From 4ea301d9910996cd3ef97a56b3cba86fd95685bb Mon Sep 17 00:00:00 2001 From: dshaligram Date: Mon, 5 Feb 2007 12:05:42 +0000 Subject: [1632567] Greedy explore now tries to do the Right Thing with mimics. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@915 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/beam.cc | 2 +- crawl-ref/source/describe.cc | 4 ++++ crawl-ref/source/enum.h | 8 +++++--- crawl-ref/source/fight.cc | 11 ++++++++++ crawl-ref/source/mon-util.cc | 10 +++++++++ crawl-ref/source/mon-util.h | 2 ++ crawl-ref/source/monstuff.cc | 13 ++++++------ crawl-ref/source/mstuff2.cc | 15 ++++++++++++-- crawl-ref/source/stuff.h | 2 +- crawl-ref/source/tags.cc | 2 +- crawl-ref/source/travel.cc | 49 ++++++++++++++++++++++++++++++++++++++++---- crawl-ref/source/view.cc | 4 ++-- 12 files changed, 102 insertions(+), 20 deletions(-) (limited to 'crawl-ref') diff --git a/crawl-ref/source/beam.cc b/crawl-ref/source/beam.cc index 00f8aaea03..87953d540f 100644 --- a/crawl-ref/source/beam.cc +++ b/crawl-ref/source/beam.cc @@ -2241,7 +2241,7 @@ bool check_line_of_sight( int sx, int sy, int tx, int ty ) and changes its appearance - the appearance change is in monster_teleport in mstuff2. */ -void mimic_alert(struct monsters *mimic) +void mimic_alert(monsters *mimic) { if (mons_has_ench( mimic, ENCH_TP_I, ENCH_TP_IV )) return; diff --git a/crawl-ref/source/describe.cc b/crawl-ref/source/describe.cc index bbe50df91e..fbcda03e74 100644 --- a/crawl-ref/source/describe.cc +++ b/crawl-ref/source/describe.cc @@ -4572,6 +4572,10 @@ void describe_monsters(int class_described, unsigned char which_mons) description = ptr_monam( &(menv[ which_mons ]), DESC_CAP_A ); description += "$$"; + // Now that the player has examined it, he knows it's a mimic. + if (mons_is_mimic(menv[which_mons].type)) + menv[which_mons].flags |= MF_KNOWN_MIMIC; + switch (class_described) { // (missing) case 423 - MONS_ANOTHER_LAVA_THING ??? 15jan2000 {dlb} diff --git a/crawl-ref/source/enum.h b/crawl-ref/source/enum.h index 456626204f..15fb845e5c 100644 --- a/crawl-ref/source/enum.h +++ b/crawl-ref/source/enum.h @@ -2306,8 +2306,7 @@ enum mon_flight_type FLY_LEVITATION // doesn't require physical effort }; -// Note: These are currently stored in chars!!! -// Need to fix struct monsters and the savefile if you want more. +// These are now saved in an unsigned long in the monsters struct. enum monster_flag_type { MF_CREATED_FRIENDLY = 0x01, // no benefit from killing @@ -2318,7 +2317,10 @@ enum monster_flag_type MF_INTERESTING = 0x20, // Player finds monster interesting MF_SEEN = 0x40, // Player already seen monster - MF_DIVINE_PROTECTION = 0x80 // Monster has divine protection. + MF_DIVINE_PROTECTION = 0x80, // Monster has divine protection. + + MF_KNOWN_MIMIC = 0x100 // Mimic that has taken a swing at the PC, + // or that the player has inspected with ? }; enum mon_dam_level_type diff --git a/crawl-ref/source/fight.cc b/crawl-ref/source/fight.cc index 9b609f8d95..6f2f3ad4e7 100644 --- a/crawl-ref/source/fight.cc +++ b/crawl-ref/source/fight.cc @@ -2045,6 +2045,10 @@ void monster_attack(int monster_attacking) if (mons_has_ench( attacker, ENCH_SUBMERGED )) return; + // If a mimic is attacking the player, it is thereafter known. + if (mons_is_mimic(attacker->type)) + attacker->flags |= MF_KNOWN_MIMIC; + if (you.duration[DUR_REPEL_UNDEAD] && mons_holiness( attacker ) == MH_UNDEAD && !check_mons_resist_magic( attacker, you.piety )) @@ -3130,6 +3134,13 @@ bool monsters_fight(int monster_attacking, int monster_attacked) if (mons_near(attacker) && mons_near(defender)) sees = true; + // Any objects seen in combat are thereafter known mimics. + if (mons_is_mimic(attacker->type) && mons_near(attacker)) + attacker->flags |= MF_KNOWN_MIMIC; + + if (mons_is_mimic(defender->type) && mons_near(defender)) + defender->flags |= MF_KNOWN_MIMIC; + // now disturb defender, regardless behaviour_event(defender, ME_WHACK, monster_attacking); diff --git a/crawl-ref/source/mon-util.cc b/crawl-ref/source/mon-util.cc index 2e6e3b1930..d0fb486907 100644 --- a/crawl-ref/source/mon-util.cc +++ b/crawl-ref/source/mon-util.cc @@ -1664,6 +1664,16 @@ bool mons_is_batty(const monsters *m) return testbits(m->flags, MF_BATTY); } +bool mons_was_seen(const monsters *m) +{ + return testbits(m->flags, MF_SEEN); +} + +bool mons_is_known_mimic(const monsters *m) +{ + return mons_is_mimic(m->type) && testbits(m->flags, MF_KNOWN_MIMIC); +} + bool mons_looks_stabbable(const monsters *m) { // Make sure oklob plants are never highlighted. That'll defeat the diff --git a/crawl-ref/source/mon-util.h b/crawl-ref/source/mon-util.h index 1f3d9b352c..7bec117412 100644 --- a/crawl-ref/source/mon-util.h +++ b/crawl-ref/source/mon-util.h @@ -402,6 +402,8 @@ bool mons_is_confused(const monsters *m); bool mons_is_fleeing(const monsters *m); bool mons_is_sleeping(const monsters *m); bool mons_is_batty(const monsters *m); +bool mons_was_seen(const monsters *m); +bool mons_is_known_mimic(const monsters *m); bool mons_is_evil( const monsters *mon ); bool mons_is_unholy( const monsters *mon ); bool mons_has_lifeforce( const monsters *mon ); diff --git a/crawl-ref/source/monstuff.cc b/crawl-ref/source/monstuff.cc index a3620b3c70..e6f9f17a24 100644 --- a/crawl-ref/source/monstuff.cc +++ b/crawl-ref/source/monstuff.cc @@ -77,7 +77,7 @@ static bool immobile_monster[MAX_MONSTERS]; // This function creates an artificial item to represent a mimic's appearance. // Eventually, mimics could be redone to be more like Dancing wepaons... // there'd only be one type and it would look like the item it carries. -- bwr -void get_mimic_item( const struct monsters *mimic, item_def &item ) +void get_mimic_item( const monsters *mimic, item_def &item ) { ASSERT( mimic != NULL && mons_is_mimic( mimic->type ) ); @@ -1769,7 +1769,7 @@ bool simple_monster_message(struct monsters *monster, const char *event, { char buff[INFO_SIZE]; - if (mons_near( monster ) + if (mons_near( monster ) && (channel == MSGCH_MONSTER_SPELL || player_monster_visible(monster))) { snprintf( buff, sizeof(buff), "%s%s", @@ -5337,7 +5337,7 @@ static int map_wand_to_mspell(int wand_type) return (mzap); } -void seen_monster(struct monsters *monster) +void seen_monster(monsters *monster) { if ( monster->flags & MF_SEEN ) return; @@ -5345,9 +5345,10 @@ void seen_monster(struct monsters *monster) // First time we've seen this particular monster monster->flags |= MF_SEEN; - if ( MONST_INTERESTING(monster) && - monster->type != MONS_PANDEMONIUM_DEMON && - monster->type != MONS_PLAYER_GHOST ) + if ( !mons_is_mimic(monster->type) + && MONST_INTERESTING(monster) + && monster->type != MONS_PANDEMONIUM_DEMON + && monster->type != MONS_PLAYER_GHOST ) { take_note( Note(NOTE_SEEN_MONSTER, monster->type, 0, diff --git a/crawl-ref/source/mstuff2.cc b/crawl-ref/source/mstuff2.cc index 30509d8ead..92e14fe6cb 100644 --- a/crawl-ref/source/mstuff2.cc +++ b/crawl-ref/source/mstuff2.cc @@ -824,7 +824,8 @@ void monster_teleport(struct monsters *monster, bool instan, bool silent) monster->colour = get_mimic_colour( monster ); } - if (!silent) + const bool now_visible = mons_near(monster); + if (!silent && now_visible) { if (was_seen) simple_monster_message(monster, " reappears nearby!"); @@ -832,8 +833,18 @@ void monster_teleport(struct monsters *monster, bool instan, bool silent) simple_monster_message(monster, " appears out of thin air!"); } - if (player_monster_visible(monster) && mons_near(monster)) + if (player_monster_visible(monster) && now_visible) seen_monster(monster); + + // Teleporting mimics change form - if they reappear out of LOS, they are + // no longer known. + if (mons_is_mimic(monster->type)) + { + if (now_visible) + monster->flags |= MF_KNOWN_MIMIC; + else + monster->flags &= ~MF_KNOWN_MIMIC; + } } // end monster_teleport() void setup_dragon(struct monsters *monster, struct bolt &pbolt) diff --git a/crawl-ref/source/stuff.h b/crawl-ref/source/stuff.h index c0bb7ab30c..401d6a746b 100644 --- a/crawl-ref/source/stuff.h +++ b/crawl-ref/source/stuff.h @@ -102,7 +102,7 @@ int letter_to_index(int the_letter); int near_stairs(int px, int py, int max_dist, unsigned char &stair_gfx); -inline bool testbits(unsigned int flags, unsigned int test) +inline bool testbits(unsigned long flags, unsigned long test) { return ((flags & test) == test); } diff --git a/crawl-ref/source/tags.cc b/crawl-ref/source/tags.cc index 88982c10af..b24b85d2d7 100644 --- a/crawl-ref/source/tags.cc +++ b/crawl-ref/source/tags.cc @@ -815,7 +815,7 @@ static void tag_construct_you_items(struct tagHeader &th) marshallShort(th,you.inv[i].plus2); marshallShort(th, you.inv[i].orig_place); marshallShort(th, you.inv[i].orig_monnum); - marshallString(th, you.inv[i].inscription.c_str(), 80); + marshallString(th, you.inv[i].inscription.c_str(), 80); } // item descrip for each type & subtype diff --git a/crawl-ref/source/travel.cc b/crawl-ref/source/travel.cc index 38bff25688..57cc5d0d60 100644 --- a/crawl-ref/source/travel.cc +++ b/crawl-ref/source/travel.cc @@ -21,6 +21,7 @@ #include "items.h" #include "misc.h" #include "mon-util.h" +#include "monstuff.h" #include "overmap.h" #include "player.h" #include "stash.h" @@ -102,6 +103,8 @@ static int find_transtravel_square(const level_pos &pos, bool verbose = true); static bool loadlev_populate_stair_distances(const level_pos &target); static void populate_stair_distances(const level_pos &target); +static bool is_greed_inducing_square(const LevelStashes *ls, + const coord_def &c); bool is_player_mapped(int grid_x, int grid_y) { @@ -694,8 +697,24 @@ inline static void check_interesting_square(int x, int y, { const coord_def pos(x + 1, y + 1); - if (ES_item && igrd(pos) != NON_ITEM) - ed.found_item( pos, mitm[ igrd(pos) ] ); + if (ES_item) + { + if (mgrd(pos) != NON_MONSTER) + { + const monsters *mons = &menv[ mgrd(pos) ]; + if (mons_is_mimic(mons->type) + && !mons_is_known_mimic(mons)) + { + item_def item; + get_mimic_item(mons, item); + + ed.found_item(pos, item); + } + } + + if (igrd(pos) != NON_ITEM) + ed.found_item( pos, mitm[ igrd(pos) ] ); + } ed.found_feature( pos, grd(pos) ); } @@ -1091,9 +1110,31 @@ travel_pathfind::travel_pathfind() { } +static bool is_greed_inducing_square(const LevelStashes *ls, const coord_def &c) +{ + if (ls && ls->needs_visit(c.x, c.y)) + return (true); + + const int m_ind = mgrd(c); + if (m_ind != NON_MONSTER) + { + const monsters *mons = &menv[ m_ind ]; + if (mons_is_mimic(mons->type) + && mons_was_seen(mons) + && !mons_is_known_mimic(mons)) + { + item_def mimic_item; + get_mimic_item(mons, mimic_item); + if (item_needs_autopickup(mimic_item)) + return (true); + } + } + return (false); +} + bool travel_pathfind::is_greed_inducing_square(const coord_def &c) const { - return (ls && ls->needs_visit(c.x, c.y)); + return ::is_greed_inducing_square(ls, c); } void travel_pathfind::set_src_dst(const coord_def &src, const coord_def &dst) @@ -3421,7 +3462,7 @@ void explore_discoveries::found_item(const coord_def &pos, const item_def &i) if (!current_level) current_level = stashes.find_current_level(); - if (current_level && current_level->needs_visit(pos.x, pos.y)) + if (current_level && is_greed_inducing_square(current_level, pos)) return; } diff --git a/crawl-ref/source/view.cc b/crawl-ref/source/view.cc index a23c710cbd..afc0c56bb1 100644 --- a/crawl-ref/source/view.cc +++ b/crawl-ref/source/view.cc @@ -667,10 +667,10 @@ void fire_monster_alerts() if (player_monster_visible( monster ) && !mons_is_submerged( monster ) && !mons_friendly( monster ) - && !mons_is_mimic( monster->type ) && !mons_class_flag( monster->type, M_NO_EXP_GAIN )) { - interrupt_activity( AI_SEE_MONSTER, monster ); + if (!mons_is_mimic( monster->type )) + interrupt_activity( AI_SEE_MONSTER, monster ); seen_monster( monster ); } } -- cgit v1.2.3-54-g00ecf