From a5f48b90bfa5f11717385652e57aca472c8b38b7 Mon Sep 17 00:00:00 2001 From: dshaligram Date: Thu, 27 Sep 2007 10:59:19 +0000 Subject: Bumped piety cost for brothers-in-arms and greater healing. Added COLOUR: directive to maps to allow custom colouring of features by glyph, and tweaked the strawberry fields variants to use it. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@2227 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/FixAry.h | 49 ++++++++++++ crawl-ref/source/FixVec.h | 1 - crawl-ref/source/abl-show.cc | 4 +- crawl-ref/source/dat/lair.des | 4 + crawl-ref/source/dat/levdes.vim | 2 +- crawl-ref/source/dungeon.cc | 12 +-- crawl-ref/source/luadgn.cc | 8 ++ crawl-ref/source/mapdef.cc | 157 ++++++++++++++++++++++++++++++++------ crawl-ref/source/mapdef.h | 42 ++++++++-- crawl-ref/source/util/levcomp.lpp | 1 + crawl-ref/source/util/levcomp.ypp | 23 +++++- 11 files changed, 262 insertions(+), 41 deletions(-) diff --git a/crawl-ref/source/FixAry.h b/crawl-ref/source/FixAry.h index ba4b863866..4e3ab70514 100644 --- a/crawl-ref/source/FixAry.h +++ b/crawl-ref/source/FixAry.h @@ -71,5 +71,54 @@ protected: FixedVector mData; }; +template +class Matrix { +public: + Matrix(int width, int height, const Z &initial); + Matrix(int width, int height); + ~Matrix(); + + void init(const Z &initial); + Z &operator () (int x, int y) + { + return data[x + y * width]; + } + const Z &operator () (int x, int y) const + { + return data[x + y * width]; + } + +private: + Z *data; + int width, height, size; +}; + +template +Matrix::Matrix(int _width, int _height, const Z &initial) + : data(NULL), width(_width), height(_height), size(_width * _height) +{ + data = new Z [ size ]; + init(initial); +} + +template +Matrix::Matrix(int _width, int _height) + : data(NULL), width(_width), height(_height), size(_width * _height) +{ + data = new Z [ size ]; +} + +template +Matrix::~Matrix() +{ + delete [] data; +} + +template +void Matrix::init(const Z &initial) +{ + for (int i = 0; i < size; ++i) + data[i] = initial; +} #endif // FIXARY_H diff --git a/crawl-ref/source/FixVec.h b/crawl-ref/source/FixVec.h index f574f8fa1c..ca6876a5e9 100644 --- a/crawl-ref/source/FixVec.h +++ b/crawl-ref/source/FixVec.h @@ -17,7 +17,6 @@ #include "debug.h" - // ========================================================================== // class FixedVector // ========================================================================== diff --git a/crawl-ref/source/abl-show.cc b/crawl-ref/source/abl-show.cc index 14cea56b73..343e2ce842 100644 --- a/crawl-ref/source/abl-show.cc +++ b/crawl-ref/source/abl-show.cc @@ -275,7 +275,7 @@ static const ability_def Ability_List[] = { ABIL_TROG_BURN_BOOKS, "Burn Books", 0, 0, 10, 0, ABFLAG_NONE }, { ABIL_TROG_BERSERK, "Berserk", 0, 0, 200, 0, ABFLAG_NONE }, { ABIL_TROG_REGENERATION, "Trog's Hand", 0, 0, 50, 1, ABFLAG_NONE }, - { ABIL_TROG_BROTHERS_IN_ARMS, "Brothers in Arms", 0, 0, 100, 3, ABFLAG_NONE }, + { ABIL_TROG_BROTHERS_IN_ARMS, "Brothers in Arms", 0, 0, 100, 6, ABFLAG_NONE }, // Elyvilon { ABIL_ELYVILON_DESTROY_WEAPONS, "Destroy Weapons", 0, 0, 0, 0, ABFLAG_NONE }, @@ -285,7 +285,7 @@ static const ability_def Ability_List[] = ABFLAG_CONF_OK }, { ABIL_ELYVILON_HEALING, "Healing", 2, 0, 250, 2, ABFLAG_CONF_OK }, { ABIL_ELYVILON_RESTORATION, "Restoration", 3, 0, 400, 3, ABFLAG_CONF_OK }, - { ABIL_ELYVILON_GREATER_HEALING, "Greater Healing", 6, 0, 600, 4, + { ABIL_ELYVILON_GREATER_HEALING, "Greater Healing", 6, 0, 600, 5, ABFLAG_CONF_OK }, // Lugonu diff --git a/crawl-ref/source/dat/lair.des b/crawl-ref/source/dat/lair.des index 73e2379593..fa36475328 100644 --- a/crawl-ref/source/dat/lair.des +++ b/crawl-ref/source/dat/lair.des @@ -261,6 +261,7 @@ SUBST: .= d .:150 1:8 2:4 MONS: plant, butterfly ITEM: strawberry / strawberry q:1 / strawberry q:2 / strawberry q:3 / strawberry q:4 / strawberry q:5 / strawberry q:6 / strawberry q:8 CHANCE: 2 +COLOUR: . = green:20 / brown:15 / none MAP ..................... ..................... @@ -287,6 +288,7 @@ SUBST: .= d .:140 1:8 2:4 MONS: plant, butterfly ITEM: strawberry / strawberry q:1 / strawberry q:2 / strawberry q:3 / strawberry q:4 / strawberry q:5 / strawberry q:6 / strawberry q:8 CHANCE: 2 +COLOUR: . = green:20 / brown:15 / none MAP ....... ........... @@ -314,6 +316,7 @@ MONS: plant, butterfly ITEM: strawberry / strawberry q:1 / strawberry q:2 / strawberry q:3 / strawberry q:4 / strawberry q:5 / strawberry q:6 / strawberry q:8 CHANCE: 3 PLACE: Lair:3 +COLOUR: . = green:20 / brown:15 / none MAP .... ........ @@ -332,6 +335,7 @@ SUBST: .= d .:50 1:8 2:4 MONS: plant, butterfly ITEM: strawberry / strawberry q:1 / strawberry q:2 / strawberry q:3 / strawberry q:4 / strawberry q:5 / strawberry q:6 / strawberry q:8 CHANCE: 3 +COLOUR: . = green:20 / brown:15 / none MAP .. ...... diff --git a/crawl-ref/source/dat/levdes.vim b/crawl-ref/source/dat/levdes.vim index f2c2206f9f..c3e608b734 100644 --- a/crawl-ref/source/dat/levdes.vim +++ b/crawl-ref/source/dat/levdes.vim @@ -51,7 +51,7 @@ syn region desNsubst start=/^NSUBST:\s*/ end=/$/ contains=desNsubstDec,desSubstA syn region desShuffle start=/^SHUFFLE:\s*/ end=/$/ contains=desShuffleDec,desMapFrag keepend -syn keyword desDeclarator NAME: ORIENT: DEPTH: PLACE: MONS: FLAGS: default-depth: TAGS: CHANCE: WEIGHT: ITEM: KFEAT: KMONS: KITEM: +syn keyword desDeclarator NAME: ORIENT: DEPTH: PLACE: MONS: FLAGS: default-depth: TAGS: CHANCE: WEIGHT: ITEM: KFEAT: KMONS: KITEM: COLOUR: syn keyword desOrientation encompass north south east west northeast northwest southeast southwest float no_hmirror no_vmirror no_rotate entry pan no_pool_fixup no_monster_gen generate_awake mini_float no_item_gen syn match desComment "^\s*#.*$" diff --git a/crawl-ref/source/dungeon.cc b/crawl-ref/source/dungeon.cc index 95a033309c..b07dc20008 100644 --- a/crawl-ref/source/dungeon.cc +++ b/crawl-ref/source/dungeon.cc @@ -3249,23 +3249,25 @@ static bool build_minivaults(int level_number, int force_vault, continue; const dungeon_feature_type oldgrid = grd[vx][vy]; altar_count = vault_grid( place, - level_number, vx, vy, altar_count, + level_number, vx, vy, + altar_count, acq_item_class, - feat, target_connections, + feat, target_connections, num_runes ); if (!building_level) { link_items(); const dungeon_feature_type newgrid = grd[vx][vy]; grd[vx][vy] = oldgrid; - dungeon_terrain_changed(coord_def(vx, vy), newgrid, + dungeon_terrain_changed(coord_def(vx, vy), + newgrid, true, true); env.markers.remove_markers_at(coord_def(vx, vy), MAT_ANY); } } } - place.map.map.apply_markers(coord_def(v1x, v1y)); + place.map.map.apply_overlays(coord_def(v1x, v1y)); if (target_connections.empty() && place.map.has_tag("mini_float")) pick_float_exits(place, target_connections); @@ -3809,7 +3811,7 @@ static bool build_vaults(int level_number, int force_vault, int rune_subst, } } - place.map.map.apply_markers(coord_def(place.x, place.y)); + place.map.map.apply_overlays(coord_def(place.x, place.y)); register_place(place); if (gluggy == MAP_FLOAT && target_connections.empty()) diff --git a/crawl-ref/source/luadgn.cc b/crawl-ref/source/luadgn.cc index 82039db1bf..4a73aa9e36 100644 --- a/crawl-ref/source/luadgn.cc +++ b/crawl-ref/source/luadgn.cc @@ -619,6 +619,13 @@ static int dgn_nsubst(lua_State *ls) &map_lines::clear_nsubsts); } +static int dgn_colour(lua_State *ls) +{ + return dgn_map_add_transform(ls, + &map_lines::add_colour, + &map_lines::clear_colours); +} + static int dgn_subst_remove(lua_State *ls) { MAP(ls, 1, map); @@ -1210,6 +1217,7 @@ static const struct luaL_reg dgn_lib[] = { "shuffle_remove", dgn_shuffle_remove }, { "subst", dgn_subst }, { "nsubst", dgn_nsubst }, + { "colour", dgn_colour }, { "subst_remove", dgn_subst_remove }, { "map", dgn_map }, { "mons", dgn_mons }, diff --git a/crawl-ref/source/mapdef.cc b/crawl-ref/source/mapdef.cc index 28fc83fd57..36579eda2d 100644 --- a/crawl-ref/source/mapdef.cc +++ b/crawl-ref/source/mapdef.cc @@ -16,6 +16,7 @@ #include "describe.h" #include "direct.h" #include "files.h" +#include "initfile.h" #include "invent.h" #include "items.h" #include "libutil.h" @@ -52,12 +53,12 @@ const char *map_section_name(int msect) return map_section_names[msect]; } -static int find_weight(std::string &s) +static int find_weight(std::string &s, int defweight = TAG_UNFOUND) { int weight = strip_number_tag(s, "weight:"); if (weight == TAG_UNFOUND) weight = strip_number_tag(s, "w:"); - return (weight); + return (weight == TAG_UNFOUND? defweight : weight); } static std::string split_key_item(const std::string &s, @@ -304,9 +305,9 @@ map_transformer::~map_transformer() // map_lines map_lines::map_lines() - : transforms(), markers(), lines(), map_width(0), - solid_north(false), solid_east(false), solid_south(false), - solid_west(false), solid_checked(false) + : transforms(), markers(), lines(), colour_overlay(), + map_width(0), solid_north(false), solid_east(false), + solid_south(false), solid_west(false), solid_checked(false) { } @@ -343,6 +344,7 @@ void map_lines::init_from(const map_lines &map) // Transforms and markers have to be regenerated, they will not be copied. clear_transforms(); clear_markers(); + colour_overlay.reset(NULL); lines = map.lines; map_width = map.map_width; solid_north = map.solid_north; @@ -399,6 +401,26 @@ void map_lines::apply_markers(const coord_def &c) markers.clear(); } +void map_lines::apply_colours(const coord_def &c) +{ + if (!colour_overlay.get()) + return; + const Matrix &overlay = *colour_overlay; + for (int y = height() - 1; y >= 0; --y) + for (int x = width() - 1; x >= 0; --x) + { + const int colour = overlay(x, y); + if (colour) + env.grid_colours(c + coord_def(x, y)) = colour; + } +} + +void map_lines::apply_overlays(const coord_def &c) +{ + apply_markers(c); + apply_colours(c); +} + const std::vector &map_lines::get_lines() const { return (lines); @@ -476,6 +498,65 @@ std::string map_lines::parse_glyph_replacements(std::string s, return (""); } +std::string map_lines::parse_weighted_colours(const std::string &cspec, + map_colour_list &colours) const +{ + std::vector cspeclist = split_string("/", cspec); + for (int i = 0, size = cspeclist.size(); i < size; ++i) + { + std::string col = cspeclist[i]; + lowercase(col); + + int weight = find_weight(col); + + if (weight == TAG_UNFOUND) + { + // :number suffix? + std::string::size_type cpos = col.find(':'); + if (cpos != std::string::npos) + { + weight = atoi(col.substr(cpos + 1).c_str()); + if (weight <= 0) + weight = 10; + col.erase(cpos); + trim_string(col); + } + } + + const int colour = col == "none"? BLACK : str_to_colour(col, -1); + if (colour != -1) + colours.push_back(map_weighted_colour(colour, weight)); + else + return make_stringf("bad colour spec: '%s' in '%s'", + col.c_str(), cspec.c_str()); + } + return (""); +} + +std::string map_lines::add_colour(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 = split_key_item(sub, &key, &sep, &substitute); + if (!err.empty()) + return (err); + + map_colour_list colours; + err = parse_weighted_colours(substitute, colours); + if (!err.empty()) + return (err); + + transforms.push_back( new colour_spec( key[0], sep == ':', colours ) ); + return (""); +} + std::string map_lines::add_subst(const std::string &sub) { std::string s = trimmed_string(sub); @@ -631,6 +712,11 @@ void map_lines::clear_transforms(map_transformer::transform_type tt) } } +void map_lines::clear_colours() +{ + clear_transforms(map_transformer::TT_COLOUR); +} + void map_lines::clear_shuffles() { clear_transforms(map_transformer::TT_SHUFFLE); @@ -733,6 +819,22 @@ void map_lines::subst(subst_spec &spec) subst(lines[y], spec); } +void map_lines::overlay_colours(colour_spec &spec) +{ + if (!colour_overlay.get()) + colour_overlay.reset( new Matrix(width(), height(), BLACK) ); + + 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) + { + (*colour_overlay)(pos, y) = spec.get_colour(); + ++pos; + } + } +} + void map_lines::nsubst(nsubst_spec &spec) { std::vector positions; @@ -2228,11 +2330,6 @@ std::string subst_spec::apply_transform(map_lines &map) return (""); } -map_transformer *subst_spec::clone() const -{ - return new subst_spec(*this); -} - map_transformer::transform_type subst_spec::type() const { return (TT_SUBST); @@ -2283,16 +2380,40 @@ std::string nsubst_spec::apply_transform(map_lines &map) return (""); } -map_transformer *nsubst_spec::clone() const +std::string nsubst_spec::describe() const +{ + return (""); +} + +////////////////////////////////////////////////////////////////////////// +// colour_spec + +std::string colour_spec::apply_transform(map_lines &map) { - return new nsubst_spec(key, specs); + map.overlay_colours(*this); + return (""); } -std::string nsubst_spec::describe() const +std::string colour_spec::describe() const { return (""); } +int colour_spec::get_colour() +{ + if (fixed_colour != BLACK) + return (fixed_colour); + + int chosen = BLACK; + int cweight = 0; + for (int i = 0, size = colours.size(); i < size; ++i) + if (random2(cweight += colours[i].second) < colours[i].second) + chosen = colours[i].first; + if (fix) + fixed_colour = chosen; + return (chosen); +} + ////////////////////////////////////////////////////////////////////////// // shuffle_spec @@ -2302,11 +2423,6 @@ std::string shuffle_spec::apply_transform(map_lines &map) return (""); } -map_transformer *shuffle_spec::clone() const -{ - return new shuffle_spec(*this); -} - map_transformer::transform_type shuffle_spec::type() const { return (TT_SHUFFLE); @@ -2356,11 +2472,6 @@ std::string map_marker_spec::describe() const return ("unimplemented"); } -map_transformer *map_marker_spec::clone() const -{ - return new map_marker_spec(key, marker); -} - ////////////////////////////////////////////////////////////////////////// // map_flags map_flags::map_flags() diff --git a/crawl-ref/source/mapdef.h b/crawl-ref/source/mapdef.h index e3fd3e3d04..d364553a9a 100644 --- a/crawl-ref/source/mapdef.h +++ b/crawl-ref/source/mapdef.h @@ -18,6 +18,7 @@ #include "externs.h" #include "makeitem.h" #include "travel.h" +#include "FixAry.h" // [dshaligram] Maps can be mirrored; for every orientation, there must be // a suitable mirror. @@ -104,13 +105,13 @@ public: TT_SHUFFLE, TT_SUBST, TT_NSUBST, - TT_MARKER + TT_MARKER, + TT_COLOUR }; public: virtual ~map_transformer() = 0; virtual std::string apply_transform(map_lines &map) = 0; - virtual map_transformer *clone() const = 0; virtual transform_type type() const = 0; virtual std::string describe() const = 0; }; @@ -129,7 +130,6 @@ public: int value(); std::string apply_transform(map_lines &map); - map_transformer *clone() const; transform_type type() const; std::string describe() const; @@ -148,7 +148,6 @@ class nsubst_spec : public map_transformer public: nsubst_spec(int key, const std::vector &specs); std::string apply_transform(map_lines &map); - map_transformer *clone() const; transform_type type() const { return TT_NSUBST; } std::string describe() const; @@ -157,6 +156,27 @@ public: std::vector specs; }; +typedef std::pair map_weighted_colour; +typedef std::vector map_colour_list; +struct colour_spec : public map_transformer +{ +public: + colour_spec(int _key, bool _fix, const map_colour_list &clist) + : key(_key), fix(_fix), fixed_colour(BLACK), colours(clist) + { + } + std::string apply_transform(map_lines &map); + transform_type type() const { return TT_COLOUR; } + std::string describe() const; + + int get_colour(); + +public: + int key; + bool fix; + int fixed_colour; + map_colour_list colours; +}; struct shuffle_spec : public map_transformer { @@ -168,7 +188,6 @@ struct shuffle_spec : public map_transformer } std::string apply_transform(map_lines &map); - map_transformer *clone() const; transform_type type() const; std::string describe() const; bool operator == (const shuffle_spec &other) const @@ -187,7 +206,6 @@ struct map_marker_spec : public map_transformer std::string apply_transform(map_lines &map); transform_type type() const; std::string describe() const; - map_transformer *clone() const; }; class map_def; @@ -206,12 +224,14 @@ public: std::string add_nsubst(const std::string &st); std::string add_subst(const std::string &st); std::string add_shuffle(const std::string &s); + std::string add_colour(const std::string &col); void remove_shuffle(const std::string &s); void remove_subst(const std::string &s); void clear_shuffles(); void clear_substs(); void clear_nsubsts(); void clear_markers(); + void clear_colours(); std::vector find_glyph(int glyph) const; coord_def find_first_glyph(int glyph) const; @@ -241,7 +261,11 @@ public: void add_marker(map_marker *marker); std::string add_feature_marker(const std::string &desc); + void apply_markers(const coord_def &pos); + void apply_colours(const coord_def &pos); + void apply_overlays(const coord_def &pos); + const std::vector &get_lines() const; std::vector &get_lines(); std::vector get_shuffle_strings() const; @@ -266,6 +290,7 @@ private: void subst(std::string &s, subst_spec &spec); void subst(subst_spec &); void nsubst(nsubst_spec &); + void overlay_colours(colour_spec &); void check_borders(); void clear_transforms(map_transformer::transform_type); std::string shuffle(std::string s); @@ -280,16 +305,21 @@ private: subst_spec &spec); std::string parse_glyph_replacements(std::string s, glyph_replacements_t &gly); + std::string parse_weighted_colours(const std::string &cspec, + map_colour_list &colours) const; friend class subst_spec; friend class nsubst_spec; friend class shuffle_spec; friend class map_marker_spec; + friend class colour_spec; private: std::vector transforms; std::vector markers; std::vector lines; + std::auto_ptr< Matrix > colour_overlay; + int map_width; bool solid_north, solid_east, solid_south, solid_west; bool solid_checked; diff --git a/crawl-ref/source/util/levcomp.lpp b/crawl-ref/source/util/levcomp.lpp index a2044da067..ffff5860f8 100644 --- a/crawl-ref/source/util/levcomp.lpp +++ b/crawl-ref/source/util/levcomp.lpp @@ -198,6 +198,7 @@ LFLAGS: { BEGIN(ARGUMENT); return LFLAGS; } BFLAGS: { BEGIN(ARGUMENT); return BFLAGS; } SUBST: { BEGIN(ITEM_LIST); return SUBST; } NSUBST: { BEGIN(ITEM_LIST); return NSUBST; } +COLOUR: { BEGIN(ITEM_LIST); return COLOUR; } MONS: { BEGIN(MNAME); return MONS; } ITEM: { BEGIN(ITEM_LIST); return ITEM; } MARKER: { BEGIN(TOEOL); return MARKER; } diff --git a/crawl-ref/source/util/levcomp.ypp b/crawl-ref/source/util/levcomp.ypp index 74cc7ff68f..98b71047b4 100644 --- a/crawl-ref/source/util/levcomp.ypp +++ b/crawl-ref/source/util/levcomp.ypp @@ -53,7 +53,7 @@ level_range set_range(const char *s, int start, int end) %expect 2 %token DEFAULT_DEPTH SHUFFLE SUBST TAGS KFEAT KITEM KMONS KMASK -%token NAME DEPTH ORIENT PLACE CHANCE MONS ITEM MARKER +%token NAME DEPTH ORIENT PLACE CHANCE MONS ITEM MARKER COLOUR %token PRELUDE MAIN VALIDATE VETO NSUBST WELCOME LFLAGS BFLAGS %token COMMA INTEGER CHARACTER @@ -158,6 +158,7 @@ metaline : place | marker | subst | nsubst + | colour | shuffle | tags | lflags @@ -342,11 +343,27 @@ mspec_segment : STRING } ; +colour : COLOUR colour_specifiers { } + ; + +colour_specifiers : colour_specifier { } + | colour_specifiers COMMA colour_specifier { } + ; + +colour_specifier : ITEM_INFO + { + lc_map.main.add( + yylineno, + make_stringf("colour(\"%s\")", + quote_lua_string($1).c_str())); + } + ; + nsubst : NSUBST nsubst_specifiers { } ; -nsubst_specifiers : nsubst_spec - | nsubst_specifiers COMMA nsubst_spec +nsubst_specifiers : nsubst_spec { } + | nsubst_specifiers COMMA nsubst_spec { } ; nsubst_spec : ITEM_INFO -- cgit v1.2.3-54-g00ecf