From 7cab36931b74bf99d3c6ee704a7ebf3b54d7a976 Mon Sep 17 00:00:00 2001 From: Jude Brown Date: Sun, 17 Jan 2010 16:29:09 +1000 Subject: Convert fprop instances in mapdef.* to unsigned long. (greensnark) fprop lists, and fprop_spec, now use unsigned long instead of int. This matches env.pgrid, and means that there won't be size issues in future when we end up with more feature properties. --- crawl-ref/source/l_dgn.cc | 8 ++------ crawl-ref/source/mapdef.cc | 15 +++++++++++---- crawl-ref/source/mapdef.h | 6 +++--- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/crawl-ref/source/l_dgn.cc b/crawl-ref/source/l_dgn.cc index ff439d5d64..739069e4e4 100644 --- a/crawl-ref/source/l_dgn.cc +++ b/crawl-ref/source/l_dgn.cc @@ -916,7 +916,7 @@ static int dgn_fprop_changed(lua_State *ls) if (lua_isnumber(ls, 3)) prop = static_cast(luaL_checkint(ls, 3)); else if (lua_isstring(ls, 3)) - prop = static_cast(str_to_fprop(lua_tostring(ls, 3))); + prop = str_to_fprop(lua_tostring(ls, 3)); coord_def pos = coord_def(luaL_checkint(ls, 1), luaL_checkint(ls, 2)); @@ -948,18 +948,14 @@ static int dgn_fprop_at (lua_State *ls) if (lua_isnumber(ls, 3)) prop = static_cast(luaL_checkint(ls, 3)); else if (lua_isstring(ls, 3)) - prop = static_cast(str_to_fprop(lua_tostring(ls, 3))); + prop = str_to_fprop(lua_tostring(ls, 3)); coord_def pos = coord_def(luaL_checkint(ls, 1), luaL_checkint(ls, 2)); if (in_bounds(pos) && prop != FPROP_NONE) - { lua_pushboolean(ls, testbits(env.pgrid(pos), prop)); - } else - { lua_pushboolean(ls, false); - } return (1); } diff --git a/crawl-ref/source/mapdef.cc b/crawl-ref/source/mapdef.cc index 8f6f2fa02d..02b15e0eac 100644 --- a/crawl-ref/source/mapdef.cc +++ b/crawl-ref/source/mapdef.cc @@ -693,9 +693,16 @@ std::string map_lines::add_colour(const std::string &sub) bool map_fprop_list::parse(const std::string &fp, int weight) { - const int fprop = fp == "none" ? FPROP_NONE : str_to_fprop(fp); - if (fprop == -1) + unsigned long fprop; + + if (fp == "nothing") + fprop = FPROP_NONE; + else if (fp.empty()) + return (false); + else if (str_to_fprop(fp) == FPROP_NONE) return false; + else + fprop = str_to_fprop(fp); push_back(map_weighted_fprop(fprop, weight)); return true; @@ -4289,12 +4296,12 @@ int colour_spec::get_colour() ////////////////////////////////////////////////////////////////////////// // fprop_spec -int fprop_spec::get_property() +unsigned long fprop_spec::get_property() { if (fixed_prop != FPROP_NONE) return (fixed_prop); - int chosen = FPROP_NONE; + unsigned long chosen = FPROP_NONE; int cweight = 0; for (int i = 0, size = fprops.size(); i < size; ++i) if (x_chance_in_y(fprops[i].second, cweight += fprops[i].second)) diff --git a/crawl-ref/source/mapdef.h b/crawl-ref/source/mapdef.h index 354109e8a1..a8a237650c 100644 --- a/crawl-ref/source/mapdef.h +++ b/crawl-ref/source/mapdef.h @@ -155,7 +155,7 @@ public: map_colour_list colours; }; -typedef std::pair map_weighted_fprop; +typedef std::pair map_weighted_fprop; class map_fprop_list : public std::vector { public: @@ -169,12 +169,12 @@ public: { } - int get_property(); + unsigned long get_property(); public: std::string key; bool fix; - int fixed_prop; + unsigned long fixed_prop; map_fprop_list fprops; }; -- cgit v1.2.3