diff options
author | Jude Brown <bookofjude@users.sourceforge.net> | 2009-10-21 15:47:19 +1000 |
---|---|---|
committer | Adam Borowski <kilobyte@angband.pl> | 2009-10-21 13:56:37 +0200 |
commit | 2c835d08acebcbdf28db5dbe6c9afcff318e7919 (patch) | |
tree | 0064538c97eff64ba19e7f7e1a40d1c3f3bfa44a /crawl-ref/source/mapdef.cc | |
parent | 17151da3549aeb8b8d70b2e913c6114f40b82f33 (diff) | |
download | crawl-ref-2c835d08acebcbdf28db5dbe6c9afcff318e7919.tar.gz crawl-ref-2c835d08acebcbdf28db5dbe6c9afcff318e7919.zip |
KPROP: assign feature properties in Lua vaults: FPROP_BLOODY, etc.
Diffstat (limited to 'crawl-ref/source/mapdef.cc')
-rw-r--r-- | crawl-ref/source/mapdef.cc | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/crawl-ref/source/mapdef.cc b/crawl-ref/source/mapdef.cc index dc3db2c3e4..2761d1762d 100644 --- a/crawl-ref/source/mapdef.cc +++ b/crawl-ref/source/mapdef.cc @@ -466,6 +466,11 @@ void map_lines::apply_grid_overlay(const coord_def &c) const int colour = (*overlay)(x, y).colour; if (colour) dgn_set_grid_colour_at(gc, colour); + + const int property = (*overlay)(x, y).property; + if (property >= FPROP_BLOODY) + // Over-ride whatever property is already there. + env.map(gc).property |= property; #ifdef USE_TILE const int floor = (*overlay)(x, y).floortile; if (floor) @@ -636,6 +641,42 @@ std::string map_lines::add_colour(const std::string &sub) return (""); } +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) + return false; + + push_back(map_weighted_fprop(fprop, weight)); + return true; +} + +std::string map_lines::add_fproperty(const std::string &sub) +{ + std::string s = trimmed_string(sub); + + if (s.empty()) + return (""); + + int sep = 0; + std::string key; + std::string substitute; + + std::string err = mapdef_split_key_item(sub, &key, &sep, &substitute); + if (!err.empty()) + return (err); + + map_fprop_list fprops; + err = parse_weighted_str<map_fprop_list>(substitute, fprops); + if (!err.empty()) + return (err); + + fprop_spec spec(key[0], sep == ':', fprops); + overlay_fprops(spec); + + return (""); +} + std::string map_lines::add_subst(const std::string &sub) { std::string s = trimmed_string(sub); @@ -886,6 +927,22 @@ void map_lines::overlay_colours(colour_spec &spec) } } +void map_lines::overlay_fprops(fprop_spec &spec) +{ + if (!overlay.get()) + overlay.reset(new overlay_matrix(width(), height())); + + for (int y = 0, ysize = lines.size(); y < ysize; ++y) + { + std::string::size_type pos = 0; + while ((pos = lines[y].find(spec.key, pos)) != std::string::npos) + { + (*overlay)(pos, y).property |= spec.get_property(); + ++pos; + } + } +} + #ifdef USE_TILE void map_lines::overlay_tiles(tile_spec &spec) { @@ -3154,6 +3211,24 @@ int colour_spec::get_colour() } ////////////////////////////////////////////////////////////////////////// +// fprop_spec + +int fprop_spec::get_property() +{ + if (fixed_prop != FPROP_NONE) + return (fixed_prop); + + int 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)) + chosen = fprops[i].first; + if (fix) + fixed_prop = chosen; + return (chosen); +} + +////////////////////////////////////////////////////////////////////////// // map_marker_spec std::string map_marker_spec::apply_transform(map_lines &map) |