From a0de356f3d007e58152f257212ed13d8b44fdfc0 Mon Sep 17 00:00:00 2001 From: David Lawrence Ramsey Date: Sun, 1 Nov 2009 10:10:02 -0600 Subject: Move checks for a player or monster's being chaotic into another convenience function in the actor interface. --- crawl-ref/source/actor.h | 1 + crawl-ref/source/item_use.cc | 14 ++------------ crawl-ref/source/mon-util.cc | 28 +++------------------------- crawl-ref/source/mon-util.h | 3 +-- crawl-ref/source/monplace.cc | 4 ++-- crawl-ref/source/monster.cc | 22 ++++++++++++++++++++++ crawl-ref/source/monster.h | 1 + crawl-ref/source/monstuff.cc | 11 ++++++----- crawl-ref/source/player.cc | 7 ++++++- crawl-ref/source/player.h | 1 + crawl-ref/source/religion.cc | 13 ++++++++----- 11 files changed, 53 insertions(+), 52 deletions(-) (limited to 'crawl-ref') diff --git a/crawl-ref/source/actor.h b/crawl-ref/source/actor.h index b0f8157eeb..a80459a23a 100644 --- a/crawl-ref/source/actor.h +++ b/crawl-ref/source/actor.h @@ -168,6 +168,7 @@ public: virtual mon_holy_type holiness() const = 0; virtual bool is_unholy() const = 0; + virtual bool is_chaotic() const = 0; virtual int res_fire() const = 0; virtual int res_steam() const = 0; virtual int res_cold() const = 0; diff --git a/crawl-ref/source/item_use.cc b/crawl-ref/source/item_use.cc index e621b1e663..eb405b395e 100644 --- a/crawl-ref/source/item_use.cc +++ b/crawl-ref/source/item_use.cc @@ -42,9 +42,9 @@ #include "message.h" #include "misc.h" #include "mon-behv.h" +#include "mon-util.h" #include "monplace.h" #include "monstuff.h" -#include "mon-util.h" #include "notes.h" #include "ouch.h" #include "player.h" @@ -1710,17 +1710,7 @@ static bool _item_penetrates_victim(const bolt &beam, const actor *victim, static bool _silver_damages_victim(bolt &beam, actor* victim, int &dmg, std::string &dmg_msg) { - bool chaotic; - - if (victim->atype() == ACT_MONSTER) - { - monsters* mon = dynamic_cast(victim); - chaotic = mons_is_chaotic(mon); // Includes shapeshifters. - } - else - chaotic = transform_changed_physiology(); - - if (chaotic || victim->is_unholy()) + if (victim->is_unholy() || victim->is_chaotic()) { dmg *= 2; diff --git a/crawl-ref/source/mon-util.cc b/crawl-ref/source/mon-util.cc index dd7940fd58..630c80823a 100644 --- a/crawl-ref/source/mon-util.cc +++ b/crawl-ref/source/mon-util.cc @@ -546,28 +546,6 @@ bool mons_is_native_in_branch(const monsters *monster, } } -bool mons_is_chaotic(const monsters *mon) -{ - if (mon->type == MONS_UGLY_THING || mon->type == MONS_VERY_UGLY_THING) - return (true); - - if (mons_is_shapeshifter(mon)) - return (true); - - if (mon->has_spell(SPELL_POLYMORPH_OTHER)) - return (true); - - if (mon->has_attack_flavour(AF_MUTATE) - || mon->has_attack_flavour(AF_ROT) - || mon->has_attack_flavour(AF_CHAOS) - || mon->has_attack_flavour(AF_KLOWN)) - { - return (true); - } - - return (false); -} - bool mons_is_poisoner(const monsters *mon) { if (mons_corpse_effect(mon->type) == CE_POISONOUS) @@ -1722,15 +1700,15 @@ static const char *drac_colour_names[] = { "black", "mottled", "yellow", "green", "purple", "red", "white", "pale" }; -std::string draconian_colour_name(monster_type mtype) +std::string draconian_colour_name(monster_type mon_type) { COMPILE_CHECK(ARRAYSZ(drac_colour_names) == MONS_PALE_DRACONIAN - MONS_DRACONIAN, c1); - if (mtype < MONS_BLACK_DRACONIAN || mtype > MONS_PALE_DRACONIAN) + if (mon_type < MONS_BLACK_DRACONIAN || mon_type > MONS_PALE_DRACONIAN) return ("buggy"); - return (drac_colour_names[mtype - MONS_BLACK_DRACONIAN]); + return (drac_colour_names[mon_type - MONS_BLACK_DRACONIAN]); } monster_type draconian_colour_by_name(const std::string &name) diff --git a/crawl-ref/source/mon-util.h b/crawl-ref/source/mon-util.h index 3b6eb54433..439572fa2f 100644 --- a/crawl-ref/source/mon-util.h +++ b/crawl-ref/source/mon-util.h @@ -757,7 +757,6 @@ bool mons_foe_is_mons(const monsters *mons); bool mons_behaviour_perceptible(const monsters *mon); bool mons_is_native_in_branch(const monsters *monster, const branch_type branch = you.where_are_you); -bool mons_is_chaotic(const monsters *mon); bool mons_is_poisoner(const monsters *mon); bool mons_is_confused(const monsters *m, bool class_too = false); bool mons_is_caught(const monsters *m); @@ -830,7 +829,7 @@ bool monster_senior(const monsters *first, const monsters *second, monster_type draco_subspecies(const monsters *mon); unsigned char ugly_thing_random_colour(); int ugly_thing_colour_offset(const monsters *mon); -std::string draconian_colour_name(monster_type mtype); +std::string draconian_colour_name(monster_type mon_type); monster_type draconian_colour_by_name(const std::string &colour); monster_type random_monster_at_grid(const coord_def& p); diff --git a/crawl-ref/source/monplace.cc b/crawl-ref/source/monplace.cc index 8f0eed6800..76adfa699b 100644 --- a/crawl-ref/source/monplace.cc +++ b/crawl-ref/source/monplace.cc @@ -21,8 +21,8 @@ #include "message.h" #include "mon-behv.h" #include "mon-pick.h" -#include "monstuff.h" #include "mon-util.h" +#include "monstuff.h" #include "player.h" #include "random.h" #include "religion.h" @@ -2563,7 +2563,7 @@ bool player_will_anger_monster(monsters *mon, bool *holy, const bool isUnholy = (is_evil_god(you.religion) && mons_is_holy(mon)); const bool isLawful = - (you.religion == GOD_ZIN && mons_is_chaotic(mon)); + (you.religion == GOD_ZIN && mon->is_chaotic()); const bool isAntimagical = (you.religion == GOD_TROG && mons_is_magic_user(mon)); diff --git a/crawl-ref/source/monster.cc b/crawl-ref/source/monster.cc index 637fb3c078..b6fc7c0bd1 100644 --- a/crawl-ref/source/monster.cc +++ b/crawl-ref/source/monster.cc @@ -2776,6 +2776,28 @@ bool monsters::is_unholy() const return (holi == MH_UNDEAD || holi == MH_DEMONIC); } +bool monsters::is_chaotic() const +{ + if (type == MONS_UGLY_THING || type == MONS_VERY_UGLY_THING) + return (true); + + if (mons_is_shapeshifter(this)) + return (true); + + if (has_spell(SPELL_POLYMORPH_OTHER)) + return (true); + + if (has_attack_flavour(AF_MUTATE) + || has_attack_flavour(AF_ROT) + || has_attack_flavour(AF_CHAOS) + || has_attack_flavour(AF_KLOWN)) + { + return (true); + } + + return (false); +} + int monsters::res_fire() const { const mon_resist_def res = get_mons_resists(this); diff --git a/crawl-ref/source/monster.h b/crawl-ref/source/monster.h index 944a79a9a6..9c7b2fcee3 100644 --- a/crawl-ref/source/monster.h +++ b/crawl-ref/source/monster.h @@ -283,6 +283,7 @@ public: mon_holy_type holiness() const; bool is_unholy() const; + bool is_chaotic() const; int res_fire() const; int res_steam() const; int res_cold() const; diff --git a/crawl-ref/source/monstuff.cc b/crawl-ref/source/monstuff.cc index 0f01faf0e4..9f29fbe8db 100644 --- a/crawl-ref/source/monstuff.cc +++ b/crawl-ref/source/monstuff.cc @@ -49,12 +49,13 @@ static bool _wounded_damaged(monster_type mon_type); -// This function creates an artificial item to represent a mimic's appearance. -// Eventually, mimics could be redone to be more like dancing weapons... -// there'd only be one type and it would look like the item it carries. -- bwr +// This function creates an artificial item to represent a mimic's +// appearance. Eventually, mimics could be redone to be more like +// dancing weapons: there'd only be one type and it would look like the +// item it carries. - bwr void get_mimic_item( const monsters *mimic, item_def &item ) { - ASSERT( mimic != NULL && mons_is_mimic( mimic->type ) ); + ASSERT(mimic != NULL && mons_is_mimic( mimic->type)); item.base_type = OBJ_UNASSIGNED; item.sub_type = 0; @@ -1457,7 +1458,7 @@ int monster_die(monsters *monster, killer_type killer, } // Zin hates chaotic beings. - if (mons_is_chaotic(monster)) + if (monster->is_chaotic()) { did_god_conduct(DID_KILL_CHAOTIC, monster->hit_dice, true, monster); diff --git a/crawl-ref/source/player.cc b/crawl-ref/source/player.cc index 299ae43219..7bd1d6dc25 100644 --- a/crawl-ref/source/player.cc +++ b/crawl-ref/source/player.cc @@ -42,8 +42,8 @@ #include "macro.h" #include "message.h" #include "misc.h" -#include "monstuff.h" #include "mon-util.h" +#include "monstuff.h" #include "mutation.h" #include "notes.h" #include "ouch.h" @@ -6739,6 +6739,11 @@ bool player::is_unholy() const return (holi == MH_UNDEAD || holi == MH_DEMONIC); } +bool player::is_chaotic() const +{ + return (transform_changed_physiology()); +} + // Output active level of player mutation. // Might be lower than real mutation for non-"Alive" Vampires. int player_mutation_level(mutation_type mut) diff --git a/crawl-ref/source/player.h b/crawl-ref/source/player.h index 873b5cd275..b8c2c3af94 100644 --- a/crawl-ref/source/player.h +++ b/crawl-ref/source/player.h @@ -409,6 +409,7 @@ public: mon_holy_type holiness() const; bool is_unholy() const; + bool is_chaotic() const; int res_fire() const; int res_steam() const; int res_cold() const; diff --git a/crawl-ref/source/religion.cc b/crawl-ref/source/religion.cc index a1a87c7508..1e0cd81bc5 100644 --- a/crawl-ref/source/religion.cc +++ b/crawl-ref/source/religion.cc @@ -1477,7 +1477,7 @@ bool _has_jelly() bool is_good_lawful_follower(const monsters* mon) { return (mon->alive() && !mons_is_evil_or_unholy(mon) - && !mons_is_chaotic(mon) && mons_friendly(mon)); + && !mon->is_chaotic() && mons_friendly(mon)); } bool is_good_follower(const monsters* mon) @@ -5219,7 +5219,7 @@ static bool _chaotic_beings_on_level_attitude_change() { monsters *monster = &menv[i]; if (monster->alive() - && mons_is_chaotic(monster)) + && monster->is_chaotic()) { #ifdef DEBUG_DIAGNOSTICS mprf(MSGCH_DIAGNOSTICS, "Chaotic attitude changing: %s on level %d, branch %d", @@ -6811,16 +6811,19 @@ bool player_can_join_god(god_type which_god) if (you.species == SP_DEMIGOD) return (false); - if (you.is_unholy() && is_good_god(which_god)) + if (is_good_god(which_god) && you.is_unholy()) return (false); - // Feawn hates undead, but will accept demonspawn. - if (which_god == GOD_FEAWN && you.holiness() == MH_UNDEAD) + if (which_god == GOD_ZIN && you.is_chaotic()) return (false); if (which_god == GOD_BEOGH && you.species != SP_HILL_ORC) return (false); + // Feawn hates undead, but will accept demonspawn. + if (which_god == GOD_FEAWN && you.holiness() == MH_UNDEAD) + return (false); + return (true); } -- cgit v1.2.3-54-g00ecf