diff options
author | Adam Borowski <kilobyte@angband.pl> | 2012-11-04 17:18:19 +0100 |
---|---|---|
committer | Adam Borowski <kilobyte@angband.pl> | 2012-11-04 17:18:19 +0100 |
commit | 2d0488338ac2a0388167c9e8b73766ae8af1e8d4 (patch) | |
tree | c92aa786daa5e2f0782de9234d70fcb0fdfaf700 /crawl-ref/source/l_dgn.cc | |
parent | 177cfa8d1158dd7c2ed8c995cf1ee706f1492f80 (diff) | |
parent | 59910180e554e796fe4a8b1f095f88dccbe0ac89 (diff) | |
download | crawl-ref-2d0488338ac2a0388167c9e8b73766ae8af1e8d4.tar.gz crawl-ref-2d0488338ac2a0388167c9e8b73766ae8af1e8d4.zip |
Merge branch 'master' into mon-pick
Merge commits instead of rerere suck, but not being able to comfortably use
the test rig sucks even more.
Diffstat (limited to 'crawl-ref/source/l_dgn.cc')
-rw-r--r-- | crawl-ref/source/l_dgn.cc | 133 |
1 files changed, 64 insertions, 69 deletions
diff --git a/crawl-ref/source/l_dgn.cc b/crawl-ref/source/l_dgn.cc index 51bbd3081a..0682ddf1b9 100644 --- a/crawl-ref/source/l_dgn.cc +++ b/crawl-ref/source/l_dgn.cc @@ -25,6 +25,7 @@ #include "state.h" #include "tiledef-dngn.h" #include "tileview.h" +#include "unwind.h" #include "view.h" static const char *VAULT_PLACEMENT_METATABLE = "crawl.vault-placement"; @@ -42,13 +43,13 @@ void dgn_reset_default_depth() lc_default_depths.clear(); } -std::string dgn_set_default_depth(const std::string &s) +string dgn_set_default_depth(const string &s) { try { lc_default_depths = depth_ranges::parse_depth_ranges(s); } - catch (const std::string &error) + catch (const string &error) { return error; } @@ -64,7 +65,7 @@ static void dgn_add_depths(depth_ranges &drs, lua_State *ls, int s, int e) { drs.add_depths(depth_ranges::parse_depth_ranges(depth)); } - catch (const std::string &error) + catch (const string &error) { luaL_error(ls, error.c_str()); } @@ -111,7 +112,7 @@ static int dgn_place(lua_State *ls) { map->place = depth_ranges::parse_depth_ranges(luaL_checkstring(ls, 2)); } - catch (const std::string &err) + catch (const string &err) { luaL_error(ls, err.c_str()); } @@ -162,13 +163,13 @@ static int dgn_tags_remove(lua_State *ls) const int top = lua_gettop(ls); for (int i = 2; i <= top; ++i) { - const std::string axee = luaL_checkstring(ls, i); + const string axee = luaL_checkstring(ls, i); while (strip_tag(map->tags, axee)); } PLUARET(string, map->tags.c_str()); } -static const std::string level_flag_names[] = +static const string level_flag_names[] = {"no_tele_control", "not_mappable", "no_magic_map", ""}; static int dgn_lflags(lua_State *ls) @@ -180,7 +181,7 @@ static int dgn_lflags(lua_State *ls) map->level_flags = map_flags::parse(level_flag_names, luaL_checkstring(ls, 2)); } - catch (const std::string &error) + catch (const string &error) { luaL_argerror(ls, 2, error.c_str()); } @@ -197,7 +198,7 @@ static int dgn_change_level_flags(lua_State *ls) flags = map_flags::parse(level_flag_names, luaL_checkstring(ls, 1)); } - catch (const std::string &error) + catch (const string &error) { luaL_argerror(ls, 2, error.c_str()); lua_pushboolean(ls, false); @@ -241,7 +242,7 @@ static int dgn_chance(lua_State *ls) static int dgn_depth_chance(lua_State *ls) { MAP(ls, 1, map); - const std::string depth(luaL_checkstring(ls, 2)); + const string depth(luaL_checkstring(ls, 2)); const bool has_priority = lua_gettop(ls) == 4; const int chance_priority = has_priority? luaL_checkint(ls, 3) : DEFAULT_CHANCE_PRIORITY; @@ -252,7 +253,7 @@ static int dgn_depth_chance(lua_State *ls) { map->_chance.add_range(depth, map_chance(chance_priority, chance)); } - catch (const std::string &error) + catch (const string &error) { luaL_error(ls, error.c_str()); } @@ -278,7 +279,7 @@ static int dgn_weight(lua_State *ls) static int dgn_depth_weight(lua_State *ls) { MAP(ls, 1, map); - const std::string depth(luaL_checkstring(ls, 2)); + const string depth(luaL_checkstring(ls, 2)); WEIGHT(ls, 3, weight); map->_weight.add_range(depth, weight); return 0; @@ -293,7 +294,7 @@ static int dgn_orient(lua_State *ls) map->orient = MAP_NONE; else { - const std::string orient = luaL_checkstring(ls, 2); + const string orient = luaL_checkstring(ls, 2); bool found = false; // Note: Empty string is intentionally mapped to MAP_NONE! for (int i = MAP_NONE; i < MAP_NUM_SECTION_TYPES; ++i) @@ -313,7 +314,7 @@ static int dgn_orient(lua_State *ls) } int dgn_map_add_transform(lua_State *ls, - std::string (map_lines::*add)(const std::string &s)) + string (map_lines::*add)(const string &s)) { MAP(ls, 1, map); if (lua_gettop(ls) == 1) @@ -325,7 +326,7 @@ int dgn_map_add_transform(lua_State *ls, luaL_error(ls, "Unexpected nil."); else { - std::string err = (map->map.*add)(luaL_checkstring(ls, i)); + string err = (map->map.*add)(luaL_checkstring(ls, i)); if (!err.empty()) luaL_error(ls, err.c_str()); } @@ -391,7 +392,7 @@ static int dgn_map(lua_State *ls) return 0; } - std::vector<std::string> &lines = map->map.get_lines(); + vector<string> &lines = map->map.get_lines(); int which_line = luaL_checkint(ls, 2); if (which_line < 0) which_line += (int) lines.size(); @@ -418,7 +419,7 @@ static int dgn_map(lua_State *ls) return 0; } - const std::string newline = luaL_checkstring(ls, 3); + const string newline = luaL_checkstring(ls, 3); if (which_line < 0) { luaL_error(ls, @@ -451,14 +452,14 @@ static int dgn_mons(lua_State *ls) if (lua_isstring(ls, 2)) { - std::string err = map->mons.add_mons(luaL_checkstring(ls, 2)); + string err = map->mons.add_mons(luaL_checkstring(ls, 2)); if (!err.empty()) luaL_error(ls, err.c_str()); return 0; } const int index = luaL_checkint(ls, 2); - std::string err = map->mons.set_mons(index, luaL_checkstring(ls, 3)); + string err = map->mons.set_mons(index, luaL_checkstring(ls, 3)); if (!err.empty()) luaL_error(ls, err.c_str()); return 0; @@ -478,14 +479,14 @@ static int dgn_item(lua_State *ls) if (lua_isstring(ls, 2)) { - std::string err = map->items.add_item(luaL_checkstring(ls, 2)); + string err = map->items.add_item(luaL_checkstring(ls, 2)); if (!err.empty()) luaL_error(ls, err.c_str()); return 0; } const int index = luaL_checkint(ls, 2); - std::string err = map->items.set_item(index, luaL_checkstring(ls, 3)); + string err = map->items.set_item(index, luaL_checkstring(ls, 3)); if (!err.empty()) luaL_error(ls, err.c_str()); return 0; @@ -501,10 +502,10 @@ static int dgn_lua_marker(lua_State *ls) } CLua &lvm(CLua::get_vm(ls)); - std::string key = lua_tostring(ls, 2); + string key = lua_tostring(ls, 2); lua_datum function(lvm, 3, false); - const std::string err = map->map.add_lua_marker(key, function); + const string err = map->map.add_lua_marker(key, function); if (!err.empty()) luaL_error(ls, err.c_str()); @@ -524,7 +525,7 @@ static int dgn_marker(lua_State *ls) if (lua_isstring(ls, 2)) { - std::string err = map->map.add_feature_marker(luaL_checkstring(ls, 2)); + string err = map->map.add_feature_marker(luaL_checkstring(ls, 2)); if (!err.empty()) luaL_error(ls, err.c_str()); } @@ -534,7 +535,7 @@ static int dgn_marker(lua_State *ls) static int dgn_kfeat(lua_State *ls) { MAP(ls, 1, map); - std::string err = map->map.add_key_feat(luaL_checkstring(ls, 2)); + string err = map->map.add_key_feat(luaL_checkstring(ls, 2)); if (!err.empty()) luaL_error(ls, err.c_str()); return 0; @@ -543,7 +544,7 @@ static int dgn_kfeat(lua_State *ls) static int dgn_kmons(lua_State *ls) { MAP(ls, 1, map); - std::string err = map->map.add_key_mons(luaL_checkstring(ls, 2)); + string err = map->map.add_key_mons(luaL_checkstring(ls, 2)); if (!err.empty()) luaL_error(ls, err.c_str()); return 0; @@ -552,7 +553,7 @@ static int dgn_kmons(lua_State *ls) static int dgn_kitem(lua_State *ls) { MAP(ls, 1, map); - std::string err = map->map.add_key_item(luaL_checkstring(ls, 2)); + string err = map->map.add_key_item(luaL_checkstring(ls, 2)); if (!err.empty()) luaL_error(ls, err.c_str()); return 0; @@ -561,7 +562,7 @@ static int dgn_kitem(lua_State *ls) static int dgn_kmask(lua_State *ls) { MAP(ls, 1, map); - std::string err = map->map.add_key_mask(luaL_checkstring(ls, 2)); + string err = map->map.add_key_mask(luaL_checkstring(ls, 2)); if (!err.empty()) luaL_error(ls, err.c_str()); return 0; @@ -597,7 +598,7 @@ static int dgn_subvault(lua_State *ls) luaL_error(ls, "Unexpected nil."); else { - std::string err = map->subvault_from_tagstring(luaL_checkstring(ls, i)); + string err = map->subvault_from_tagstring(luaL_checkstring(ls, i)); if (!err.empty()) luaL_error(ls, err.c_str()); } @@ -678,7 +679,7 @@ static int dgn_gly_point(lua_State *ls) static int dgn_gly_points(lua_State *ls) { MAP(ls, 1, map); - std::vector<coord_def> cs = map->find_glyph(*luaL_checkstring(ls, 2)); + vector<coord_def> cs = map->find_glyph(*luaL_checkstring(ls, 2)); for (int i = 0, size = cs.size(); i < size; ++i) dlua_push_coordinates(ls, cs[i]); @@ -697,7 +698,7 @@ static int dgn_original_map(lua_State *ls) static int dgn_load_des_file(lua_State *ls) { - const std::string &file = luaL_checkstring(ls, 1); + const string &file = luaL_checkstring(ls, 1); if (!file.empty()) read_map(file); return 0; @@ -714,7 +715,7 @@ static int dgn_lfloorcol(lua_State *ls) if (colour < 0 || colour == BLACK) { - std::string error; + string error; if (colour == BLACK) error = "Can't set floor to black."; @@ -745,7 +746,7 @@ static int dgn_lrockcol(lua_State *ls) if (colour < 0 || colour == BLACK) { - std::string error; + string error; if (colour == BLACK) error = "Can't set rock to black."; @@ -787,11 +788,11 @@ static int _lua_colour(lua_State *ls, int ndx, if (colour < 0 || colour == forbidden_colour) { - std::string error; + string error; if (colour == forbidden_colour) - error = std::string("Can't set floor to ") + s; + error = string("Can't set floor to ") + s; else - error = std::string("Unknown colour: '") + s + "'"; + error = string("Unknown colour: '") + s + "'"; return luaL_argerror(ls, 1, error.c_str()); } return colour; @@ -881,7 +882,7 @@ static int dgn_num_matching_markers(lua_State *ls) else val = val_ptr; - std::vector<map_marker*> markers = env.markers.get_all(key, val); + vector<map_marker*> markers = env.markers.get_all(key, val); PLUARET(number, markers.size()); } @@ -1009,7 +1010,7 @@ static int lua_dgn_set_border_fill_type(lua_State *ls) if (lua_gettop(ls) != 2) luaL_error(ls, "set_border_fill_type requires a feature."); - std::string fill_string = luaL_checkstring(ls, 2); + string fill_string = luaL_checkstring(ls, 2); dungeon_feature_type fill_type = dungeon_feature_by_name(fill_string); if (fill_type == DNGN_UNSEEN) @@ -1033,7 +1034,7 @@ static int lua_dgn_set_feature_name(lua_State *ls) if (lua_gettop(ls) != 3) luaL_error(ls, "set_feature_name takes a feature and the new name."); - std::string feat_string = luaL_checkstring(ls, 2); + string feat_string = luaL_checkstring(ls, 2); dungeon_feature_type feat_type = dungeon_feature_by_name(feat_string); if (feat_type == DNGN_UNSEEN) @@ -1049,7 +1050,7 @@ static int lua_dgn_set_feature_name(lua_State *ls) static int dgn_floor_halo(lua_State *ls) { - std::string error = ""; + string error = ""; const char *s1 = luaL_checkstring(ls, 1); const dungeon_feature_type target = dungeon_feature_by_name(s1); @@ -1181,7 +1182,7 @@ static int dgn_random_walk(lua_State *ls) return 2; } -static cloud_type dgn_cloud_name_to_type(std::string name) +static cloud_type dgn_cloud_name_to_type(string name) { lowercase(name); @@ -1197,7 +1198,7 @@ static cloud_type dgn_cloud_name_to_type(std::string name) return CLOUD_NONE; } -static kill_category dgn_kill_name_to_category(std::string name) +static kill_category dgn_kill_name_to_category(string name) { if (name.empty()) return KC_OTHER; @@ -1220,7 +1221,7 @@ static int lua_cloud_pow_rolls; static int make_a_lua_cloud(coord_def where, int garbage, int spread_rate, cloud_type ctype, const actor *agent, int colour, - std::string name, std::string tile, int excl_rad) + string name, string tile, int excl_rad) { UNUSED(garbage); @@ -1248,8 +1249,8 @@ static int dgn_apply_area_cloud(lua_State *ls) const int spread_rate = lua_isnumber(ls, 9) ? luaL_checkint(ls, 9) : -1; const int colour = lua_isstring(ls, 10) ? str_to_colour(luaL_checkstring(ls, 10)) : -1; - std::string name = lua_isstring(ls, 11) ? luaL_checkstring(ls, 11) : ""; - std::string tile = lua_isstring(ls, 12) ? luaL_checkstring(ls, 12) : ""; + string name = lua_isstring(ls, 11) ? luaL_checkstring(ls, 11) : ""; + string tile = lua_isstring(ls, 12) ? luaL_checkstring(ls, 12) : ""; const int excl_rad = lua_isnumber(ls, 13) ? luaL_checkint(ls, 13) : -1; if (!in_bounds(x, y)) @@ -1292,7 +1293,7 @@ static int dgn_apply_area_cloud(lua_State *ls) if (ctype == CLOUD_NONE) { - std::string error = "Invalid cloud type '"; + string error = "Invalid cloud type '"; error += luaL_checkstring(ls, 7); error += "'"; luaL_argerror(ls, 7, error.c_str()); @@ -1301,7 +1302,7 @@ static int dgn_apply_area_cloud(lua_State *ls) if (kc == KC_NCATEGORIES || kc != KC_OTHER) { - std::string error = "Invalid kill category '"; + string error = "Invalid kill category '"; error += kname; error += "'"; luaL_argerror(ls, 8, error.c_str()); @@ -1345,8 +1346,8 @@ static int dgn_place_cloud(lua_State *ls) const int spread_rate = lua_isnumber(ls, 6) ? luaL_checkint(ls, 6) : -1; const int colour = lua_isstring(ls, 7) ? str_to_colour(luaL_checkstring(ls, 7)) : -1; - std::string name = lua_isstring(ls, 8) ? luaL_checkstring(ls, 8) : ""; - std::string tile = lua_isstring(ls, 9) ? luaL_checkstring(ls, 9) : ""; + string name = lua_isstring(ls, 8) ? luaL_checkstring(ls, 8) : ""; + string tile = lua_isstring(ls, 9) ? luaL_checkstring(ls, 9) : ""; const int excl_rad = lua_isnumber(ls, 10) ? luaL_checkint(ls, 10) : -1; if (!in_bounds(x, y)) @@ -1359,7 +1360,7 @@ static int dgn_place_cloud(lua_State *ls) if (ctype == CLOUD_NONE) { - std::string error = "Invalid cloud type '"; + string error = "Invalid cloud type '"; error += luaL_checkstring(ls, 3); error += "'"; luaL_argerror(ls, 3, error.c_str()); @@ -1368,7 +1369,7 @@ static int dgn_place_cloud(lua_State *ls) if (kc == KC_NCATEGORIES || kc != KC_OTHER) { - std::string error = "Invalid kill category '"; + string error = "Invalid kill category '"; error += kname; error += "'"; luaL_argerror(ls, 5, error.c_str()); @@ -1434,7 +1435,7 @@ static int dgn_register_lua_marker(lua_State *ls) return 0; } -static std::auto_ptr<lua_datum> _dgn_map_safe_bounds_fn; +static unique_ptr<lua_datum> _dgn_map_safe_bounds_fn; static bool _lua_map_place_valid(const map_def &map, const coord_def &c, @@ -1589,9 +1590,7 @@ LUAFN(_dgn_place_map) env.level_vaults[env.level_vaults.size() - 1]); } else - { lua_pushnil(ls); - } return 1; } @@ -1633,8 +1632,7 @@ LUAFN(_dgn_vault_at) LUAFN(_dgn_find_marker_position_by_prop) { const char *prop = luaL_checkstring(ls, 1); - const std::string value( - lua_gettop(ls) >= 2 ? luaL_checkstring(ls, 2) : ""); + const string value(lua_gettop(ls) >= 2 ? luaL_checkstring(ls, 2) : ""); const coord_def place = find_marker_position_by_prop(prop, value); if (map_bounds(place)) dlua_push_coordinates(ls, place); @@ -1649,11 +1647,10 @@ LUAFN(_dgn_find_marker_position_by_prop) LUAFN(_dgn_find_marker_positions_by_prop) { const char *prop = luaL_checkstring(ls, 1); - const std::string value( - lua_gettop(ls) >= 2 ? luaL_checkstring(ls, 2) : ""); + const string value(lua_gettop(ls) >= 2 ? luaL_checkstring(ls, 2) : ""); const unsigned limit(lua_gettop(ls) >= 3 ? luaL_checkint(ls, 3) : 0); - const std::vector<coord_def> places = - find_marker_positions_by_prop(prop, value, limit); + const vector<coord_def> places = find_marker_positions_by_prop(prop, value, + limit); clua_gentable(ls, places, clua_pushpoint); return 1; } @@ -1667,11 +1664,9 @@ static int _push_mapmarker(lua_State *ls, map_marker *marker) LUAFN(_dgn_find_markers_by_prop) { const char *prop = luaL_checkstring(ls, 1); - const std::string value( - lua_gettop(ls) >= 2 ? luaL_checkstring(ls, 2) : ""); + const string value(lua_gettop(ls) >= 2 ? luaL_checkstring(ls, 2) : ""); const unsigned limit(lua_gettop(ls) >= 3 ? luaL_checkint(ls, 3) : 0); - const std::vector<map_marker*> places = - find_markers_by_prop(prop, value, limit); + const vector<map_marker*> places = find_markers_by_prop(prop, value, limit); clua_gentable(ls, places, _push_mapmarker); return 1; } @@ -1776,15 +1771,15 @@ LUAFN(dgn_fill_grd_area) int y2 = luaL_checkint(ls, 4); dungeon_feature_type feat = check_lua_feature(ls, 5); - x1 = std::min(std::max(x1, X_BOUND_1+1), X_BOUND_2-1); - y1 = std::min(std::max(y1, Y_BOUND_1+1), Y_BOUND_2-1); - x2 = std::min(std::max(x2, X_BOUND_1+1), X_BOUND_2-1); - y2 = std::min(std::max(y2, Y_BOUND_1+1), Y_BOUND_2-1); + x1 = min(max(x1, X_BOUND_1+1), X_BOUND_2-1); + y1 = min(max(y1, Y_BOUND_1+1), Y_BOUND_2-1); + x2 = min(max(x2, X_BOUND_1+1), X_BOUND_2-1); + y2 = min(max(y2, Y_BOUND_1+1), Y_BOUND_2-1); if (x2 < x1) - std::swap(x1, x2); + swap(x1, x2); if (y2 < y1) - std::swap(y1, y2); + swap(y1, y2); for (int y = y1; y <= y2; y++) for (int x = x1; x <= x2; x++) |