From: <gi...@cr...> - 2011-08-31 11:52:13
|
via 4305f1e5298fda1f2fb4706ffe9d5e0e90ce26e3 (commit) via 0519e133364dd9f092d4e5535018236b81d97077 (commit) from 6ce96cd4f694f9cb2a823924555ff7d08fb0df5a (commit) ----------------------------------------------------------------------- commit 4305f1e5298fda1f2fb4706ffe9d5e0e90ce26e3 Author: Adam Borowski <kil...@an...> Date: Wed Aug 31 13:42:33 2011 +0200 Fix a harmful use of an uninitialized variable. If the number there would be a small positive integer, shit would happen. commit 0519e133364dd9f092d4e5535018236b81d97077 Author: Pete Hurst <pe...@do...> Date: Wed Aug 31 02:11:28 2011 +0100 Spiders sense when trapped in web ----------------------------------------------------------------------- Summary of changes: crawl-ref/source/enum.h | 6 ++ crawl-ref/source/files.cc | 4 +- crawl-ref/source/mon-data.h | 12 ++-- crawl-ref/source/mon-flags.h | 2 + crawl-ref/source/shout.cc | 196 ++++++++++++++++++++++++++++-------------- crawl-ref/source/shout.h | 3 + crawl-ref/source/traps.cc | 15 +++- 7 files changed, 161 insertions(+), 77 deletions(-) diff --git a/crawl-ref/source/enum.h b/crawl-ref/source/enum.h index 981f008..c088e11 100644 --- a/crawl-ref/source/enum.h +++ b/crawl-ref/source/enum.h @@ -2791,6 +2791,12 @@ enum score_format_type SCORE_VERBOSE, // everything (dates, times, god, etc.) }; +enum sense_type +{ + SENSE_SMELL_BLOOD, + SENSE_WEB_VIBRATION, +}; + enum shop_type // (uint8_t) env.sh_type[], item_in_shop(), in_a_shop() { SHOP_WEAPON, diff --git a/crawl-ref/source/files.cc b/crawl-ref/source/files.cc index d0e0601..4dc6d18 100644 --- a/crawl-ref/source/files.cc +++ b/crawl-ref/source/files.cc @@ -240,7 +240,7 @@ std::string get_base_filename(const std::string &filename) std::string get_cache_name(const std::string &filename) { - std::string::size_type pos = filename.rfind(FILE_SEPARATOR, pos - 1); + std::string::size_type pos = filename.rfind(FILE_SEPARATOR); while (pos != std::string::npos && filename.find("/des", pos) != pos) { pos = filename.rfind(FILE_SEPARATOR, pos - 1); @@ -248,7 +248,7 @@ std::string get_cache_name(const std::string &filename) if (pos != std::string::npos) return replace_all_of(filename.substr(pos + 5), " /\\:", "_"); #ifdef ALT_FILE_SEPARATOR - pos = filename.rfind(ALT_FILE_SEPARATOR, pos - 1); + pos = filename.rfind(ALT_FILE_SEPARATOR); while (pos != std::string::npos && filename.find("/des", pos) != pos) { pos = filename.rfind(ALT_FILE_SEPARATOR, pos - 1); diff --git a/crawl-ref/source/mon-data.h b/crawl-ref/source/mon-data.h index f361624..939ecf6 100644 --- a/crawl-ref/source/mon-data.h +++ b/crawl-ref/source/mon-data.h @@ -1920,7 +1920,7 @@ static monsterentry mondata[] = { { MONS_SPIDER, 's', CYAN, "spider", - M_NO_SKELETON, + M_NO_SKELETON | M_WEB_SENSE, MR_VUL_POISON, 250, 10, MONS_SPIDER, MONS_SPIDER, MH_NATURAL, -3, { {AT_BITE, AF_POISON_MEDIUM, 5}, AT_NO_ATK, AT_NO_ATK, AT_NO_ATK }, @@ -1932,7 +1932,7 @@ static monsterentry mondata[] = { { MONS_TARANTELLA, 's', LIGHTMAGENTA, "tarantella", - M_NO_SKELETON, + M_NO_SKELETON | M_WEB_SENSE, MR_VUL_POISON, 300, 10, MONS_SPIDER, MONS_TARANTELLA, MH_NATURAL, -3, { {AT_BITE, AF_CONFUSE, 8}, AT_NO_ATK, AT_NO_ATK, AT_NO_ATK }, @@ -1944,7 +1944,7 @@ static monsterentry mondata[] = { { MONS_JUMPING_SPIDER, 's', LIGHTBLUE, "jumping spider", - M_NO_SKELETON | M_SPELLCASTER | M_FAKE_SPELLS, + M_NO_SKELETON | M_SPELLCASTER | M_FAKE_SPELLS | M_WEB_SENSE, MR_VUL_POISON, 300, 10, MONS_SPIDER, MONS_JUMPING_SPIDER, MH_NATURAL, -3, { {AT_BITE, AF_POISON_MEDIUM, 16}, AT_NO_ATK, AT_NO_ATK, AT_NO_ATK }, @@ -1956,7 +1956,7 @@ static monsterentry mondata[] = { { MONS_WOLF_SPIDER, 's', WHITE, "wolf spider", - M_NO_SKELETON, + M_NO_SKELETON | M_WEB_SENSE, MR_VUL_POISON, 900, 10, MONS_SPIDER, MONS_WOLF_SPIDER, MH_NATURAL, -3, { {AT_BITE, AF_POISON_MEDIUM, 20}, AT_NO_ATK, AT_NO_ATK, AT_NO_ATK }, @@ -1968,7 +1968,7 @@ static monsterentry mondata[] = { { MONS_TRAPDOOR_SPIDER, 's', LIGHTCYAN, "trapdoor spider", - M_NO_SKELETON | M_SUBMERGES, + M_NO_SKELETON | M_SUBMERGES | M_WEB_SENSE, MR_VUL_POISON, 240, 10, MONS_SPIDER, MONS_TRAPDOOR_SPIDER, MH_NATURAL, -3, { {AT_BITE, AF_POISON_MEDIUM, 20}, AT_NO_ATK, AT_NO_ATK, AT_NO_ATK }, @@ -1982,7 +1982,7 @@ static monsterentry mondata[] = { { MONS_REDBACK, 's', RED, "redback", - M_NO_SKELETON, + M_NO_SKELETON | M_WEB_SENSE, MR_VUL_POISON, 130, 14, MONS_SPIDER, MONS_REDBACK, MH_NATURAL, -3, { {AT_BITE, AF_POISON_STRONG, 18}, AT_NO_ATK, AT_NO_ATK, AT_NO_ATK }, diff --git a/crawl-ref/source/mon-flags.h b/crawl-ref/source/mon-flags.h index 92fb70c..695788a 100644 --- a/crawl-ref/source/mon-flags.h +++ b/crawl-ref/source/mon-flags.h @@ -137,6 +137,8 @@ const uint64_t M_HERD = (uint64_t)1<<41; // will not flee const uint64_t M_NO_FLEE = (uint64_t)1<<42; +// can sense vibrations in web traps +const uint64_t M_WEB_SENSE = (uint64_t)1<<43; // Same for flags for actual monsters. typedef uint64_t monster_flag_type; diff --git a/crawl-ref/source/shout.cc b/crawl-ref/source/shout.cc index 0471548..7b11632 100644 --- a/crawl-ref/source/shout.cc +++ b/crawl-ref/source/shout.cc @@ -594,97 +594,161 @@ static const char* _player_vampire_smells_blood(int dist) return ""; } -void blood_smell(int strength, const coord_def& where) +static const char* _player_spider_senses_web(int dist) { - const int range = strength * strength; - dprf("blood stain at (%d, %d), range of smell = %d", - where.x, where.y, range); + if (dist < 4) + return " near-by"; - // Of the player species, only Vampires can smell blood. - if (you.species == SP_VAMPIRE) - { - // Whether they actually do so, depends on their hunger state. - int vamp_strength = strength - 2 * (you.hunger_state - 1); - if (vamp_strength > 0) - { - int vamp_range = vamp_strength * vamp_strength; + if (dist > LOS_RADIUS) + return " in the distance"; - const int player_distance = distance(you.pos(), where); + return ""; +} - if (player_distance <= vamp_range) - { - dprf("Player smells blood, pos: (%d, %d), dist = %d)", - you.pos().x, you.pos().y, player_distance); - you.check_awaken(range - player_distance); - // Don't message if you can see the square. - if (!you.see_cell(where)) - { - mprf("You smell fresh blood%s.", - _player_vampire_smells_blood(player_distance)); - } - } +void check_player_sense(sense_type sense, int range, const coord_def& where) +{ + const int player_distance = distance(you.pos(), where); + + if (player_distance <= range) + { + switch(sense) + { + case SENSE_SMELL_BLOOD: + dprf("Player smells blood, pos: (%d, %d), dist = %d)", + you.pos().x, you.pos().y, player_distance); + you.check_awaken(range - player_distance); + // Don't message if you can see the square. + if (!you.see_cell(where)) + { + mprf("You smell fresh blood%s.", + _player_vampire_smells_blood(player_distance)); + } + break; + + case SENSE_WEB_VIBRATION: + // Spider form + if (you.can_cling_to_walls()) + { + you.check_awaken(range - player_distance); + // Don't message if you can see the square. + if (!you.see_cell(where)) + { + mprf("You hear a 'twang'%s.", + _player_spider_senses_web(player_distance)); + } + } + break; } } +} +void check_monsters_sense(sense_type sense, int range, const coord_def& where) +{ circle_def c(where, range, C_CIRCLE); for (monster_iterator mi(&c); mi; ++mi) { - if (!mons_class_flag(mi->type, M_BLOOD_SCENT)) - continue; - - // Let sleeping hounds lie. - if (mi->asleep() - && mons_species(mi->type) != MONS_VAMPIRE - && mi->type != MONS_SHARK) + switch(sense) { - // 33% chance of sleeping on - // 33% of being disturbed (start BEH_WANDER) - // 33% of being alerted (start BEH_SEEK) - if (!one_chance_in(3)) + case SENSE_SMELL_BLOOD: + if (!mons_class_flag(mi->type, M_BLOOD_SCENT)) + break; + + // Let sleeping hounds lie. + if (mi->asleep() + && mons_species(mi->type) != MONS_VAMPIRE + && mi->type != MONS_SHARK) { - if (coinflip()) + // 33% chance of sleeping on + // 33% of being disturbed (start BEH_WANDER) + // 33% of being alerted (start BEH_SEEK) + if (!one_chance_in(3)) { - dprf("disturbing %s (%d, %d)", - mi->name(DESC_PLAIN).c_str(), - mi->pos().x, mi->pos().y); - behaviour_event(*mi, ME_DISTURB, MHITNOT, where); + if (coinflip()) + { + dprf("disturbing %s (%d, %d)", + mi->name(DESC_PLAIN).c_str(), + mi->pos().x, mi->pos().y); + behaviour_event(*mi, ME_DISTURB, MHITNOT, where); + } + break; } - continue; } - } - dprf("alerting %s (%d, %d)", - mi->name(DESC_PLAIN).c_str(), - mi->pos().x, mi->pos().y); - behaviour_event(*mi, ME_ALERT, MHITNOT, where); + dprf("alerting %s (%d, %d)", + mi->name(DESC_PLAIN).c_str(), + mi->pos().x, mi->pos().y); + behaviour_event(*mi, ME_ALERT, MHITNOT, where); - if (mi->type == MONS_SHARK) - { - // Sharks go into a battle frenzy if they smell blood. - monster_pathfind mp; - if (mp.init_pathfind(*mi, where)) + if (mi->type == MONS_SHARK) { - mon_enchant ench = mi->get_ench(ENCH_BATTLE_FRENZY); - const int dist = 15 - (mi->pos() - where).rdist(); - const int dur = random_range(dist, dist*2) - * speed_to_duration(mi->speed); + // Sharks go into a battle frenzy if they smell blood. + monster_pathfind mp; + if (mp.init_pathfind(*mi, where)) + { + mon_enchant ench = mi->get_ench(ENCH_BATTLE_FRENZY); + const int dist = 15 - (mi->pos() - where).rdist(); + const int dur = random_range(dist, dist*2) + * speed_to_duration(mi->speed); + + if (ench.ench != ENCH_NONE) + { + int level = ench.degree; + if (level < 4 && one_chance_in(2*level)) + ench.degree++; + ench.duration = std::max(ench.duration, dur); + mi->update_ench(ench); + } + else + { + mi->add_ench(mon_enchant(ENCH_BATTLE_FRENZY, 1, 0, dur)); + simple_monster_message(*mi, " is consumed with " + "blood-lust!"); + } + } + } + break; - if (ench.ench != ENCH_NONE) + case SENSE_WEB_VIBRATION: + if (!mons_class_flag(mi->type, M_WEB_SENSE)) + break; + if (!one_chance_in(4)) + { + if (coinflip()) { - int level = ench.degree; - if (level < 4 && one_chance_in(2*level)) - ench.degree++; - ench.duration = std::max(ench.duration, dur); - mi->update_ench(ench); + dprf("disturbing %s (%d, %d)", + mi->name(DESC_PLAIN).c_str(), + mi->pos().x, mi->pos().y); + behaviour_event(*mi, ME_DISTURB, MHITNOT, where); } else { - mi->add_ench(mon_enchant(ENCH_BATTLE_FRENZY, 1, - 0, dur)); - simple_monster_message(*mi, " is consumed with " - "blood-lust!"); + dprf("alerting %s (%d, %d)", + mi->name(DESC_PLAIN).c_str(), + mi->pos().x, mi->pos().y); + behaviour_event(*mi, ME_ALERT, MHITNOT, where); } } + break; + } + } +} + +void blood_smell(int strength, const coord_def& where) +{ + const int range = strength * strength; + dprf("blood stain at (%d, %d), range of smell = %d", + where.x, where.y, range); + + // Of the player species, only Vampires can smell blood. + if (you.species == SP_VAMPIRE) + { + // Whether they actually do so, depends on their hunger state. + int vamp_strength = strength - 2 * (you.hunger_state - 1); + if (vamp_strength > 0) + { + int vamp_range = vamp_strength * vamp_strength; + check_player_sense(SENSE_SMELL_BLOOD, vamp_range, where); } + check_monsters_sense(SENSE_SMELL_BLOOD, range, where); } } diff --git a/crawl-ref/source/shout.h b/crawl-ref/source/shout.h index 5eee4b9..fef3f06 100644 --- a/crawl-ref/source/shout.h +++ b/crawl-ref/source/shout.h @@ -11,6 +11,9 @@ bool fake_noisy(int loudness, const coord_def& where); void item_noise(const item_def& item, std::string msg, int loudness = 25); void noisy_equipment(); +void check_player_sense(sense_type sense, int range, const coord_def& where); +void check_monsters_sense(sense_type sense, int range, const coord_def& where); + void blood_smell(int strength, const coord_def& where); void handle_monster_shouts(monster* mons, bool force = false); bool check_awaken(monster* mons); diff --git a/crawl-ref/source/traps.cc b/crawl-ref/source/traps.cc index 8c91bf1..0a8dd76 100644 --- a/crawl-ref/source/traps.cc +++ b/crawl-ref/source/traps.cc @@ -869,13 +869,18 @@ void trap_def::trigger(actor& triggerer, bool flat_footed) if (random2limit(player_evasion(), 40) + (random2(you.dex()) / 3) + (trig_knows ? 3 : 0) > 12) { - mpr("You notice a web but duck past it!"); + mpr("A web is hanging here but you duck past it!"); } else { mpr("You are caught in the web!"); - if (player_caught_in_web() && player_in_a_dangerous_place()) - xom_is_stimulated(50); + + if (player_caught_in_web()) + { + check_monsters_sense(SENSE_WEB_VIBRATION, 100, you.pos()); + if (player_in_a_dangerous_place()) + xom_is_stimulated(50); + } } } } @@ -914,6 +919,10 @@ void trap_def::trigger(actor& triggerer, bool flat_footed) // If somehow already caught, make it worse. m->add_ench(ENCH_HELD); + + // Alert both monsters and player + check_monsters_sense(SENSE_WEB_VIBRATION, 100, triggerer.position); + check_player_sense(SENSE_WEB_VIBRATION, 100, triggerer.position); } } break; -- Dungeon Crawl Stone Soup |