From e55e12b955d739545cf587d04fcb840ef6470f13 Mon Sep 17 00:00:00 2001 From: dolorous Date: Thu, 20 Mar 2008 17:57:17 +0000 Subject: Improve the previous sanity fixes. Add a function invalid_monster_index(), and use that where applicable. Also, put the "god gift" flag back on orcish followers, since the Crusade card now handles orc conversion properly for Beoghites, and so that the index check doesn't have to be done twice for collateral kills. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@3755 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/mon-util.cc | 7 +++++++ crawl-ref/source/mon-util.h | 1 + crawl-ref/source/monstuff.cc | 21 +++++++-------------- crawl-ref/source/religion.cc | 4 +++- 4 files changed, 18 insertions(+), 15 deletions(-) (limited to 'crawl-ref/source') diff --git a/crawl-ref/source/mon-util.cc b/crawl-ref/source/mon-util.cc index 1bbdc16114..96465c7c1e 100644 --- a/crawl-ref/source/mon-util.cc +++ b/crawl-ref/source/mon-util.cc @@ -469,6 +469,13 @@ bool invalid_monster_class(int mclass) || mon_entry[mclass] == MONS_PROGRAM_BUG); } +bool invalid_monster_index(int i) +{ + return (i != ANON_FRIENDLY_MONSTER + && i >= 0 + && i < MAX_MONSTERS); +} + bool mons_is_statue(int mc) { return (mc == MONS_ORANGE_STATUE diff --git a/crawl-ref/source/mon-util.h b/crawl-ref/source/mon-util.h index 7afdf12b91..277fb85d86 100644 --- a/crawl-ref/source/mon-util.h +++ b/crawl-ref/source/mon-util.h @@ -658,6 +658,7 @@ bool mons_is_submerged( const monsters *mon ); bool invalid_monster(const monsters *mon); bool invalid_monster_class(int mclass); +bool invalid_monster_index(int i); bool monster_shover(const monsters *m); bool mons_is_paralysed(const monsters *m); diff --git a/crawl-ref/source/monstuff.cc b/crawl-ref/source/monstuff.cc index b0bf368639..b6c787ff09 100644 --- a/crawl-ref/source/monstuff.cc +++ b/crawl-ref/source/monstuff.cc @@ -466,7 +466,7 @@ static bool ely_heals_monster(monsters *monster, killer_type killer, int i) { god_type god = GOD_ELYVILON; ASSERT(you.religion != god); - + const int ely_penance = you.penance[god]; ASSERT(ely_penance > 0); @@ -477,9 +477,7 @@ static bool ely_heals_monster(monsters *monster, killer_type killer, int i) return (false); } - if (MON_KILL(killer) - && i != ANON_FRIENDLY_MONSTER - && i >= 0 && i < MAX_MONSTERS) + if (MON_KILL(killer) && !invalid_monster_index(i)) { monsters *mon = &menv[i]; if (!mons_friendly(mon) || !one_chance_in(3)) @@ -530,7 +528,7 @@ static bool monster_avoided_death(monsters *monster, killer_type killer, int i) { return (true); } - + bool convert = false; if (you.religion == GOD_BEOGH @@ -540,9 +538,7 @@ static bool monster_avoided_death(monsters *monster, killer_type killer, int i) { if (YOU_KILL(killer)) convert = true; - else if (MON_KILL(killer) - && i != ANON_FRIENDLY_MONSTER - && i >= 0 && i < MAX_MONSTERS) + else if (MON_KILL(killer) && !invalid_monster_index(i)) { monsters *mon = &menv[i]; if (is_orcish_follower(mon) && !one_chance_in(3)) @@ -728,7 +724,7 @@ void monster_die(monsters *monster, killer_type killer, int i, bool silent) case KILL_YOU_MISSILE: /* You kill by missile or beam. */ case KILL_YOU_CONF: /* You kill by confusion */ { - const bool created_friendly = + const bool created_friendly = testbits(monster->flags, MF_CREATED_FRIENDLY); const bool was_neutral = testbits(monster->flags, MF_WAS_NEUTRAL); @@ -868,14 +864,12 @@ void monster_die(monsters *monster, killer_type killer, int i, bool silent) if (attacker_holy == MH_UNDEAD) { if (targ_holy == MH_NATURAL) - notice |= + notice |= did_god_conduct(DID_LIVING_KILLED_BY_UNDEAD_SLAVE, monster->hit_dice); } else if (you.religion == GOD_VEHUMET || you.religion == GOD_MAKHLEB - || (you.religion == GOD_BEOGH - && is_orcish_follower(&menv[i])) || (!anon && testbits(menv[i].flags, MF_GOD_GIFT))) { // Yes, we are splitting undead pets from the others @@ -938,8 +932,7 @@ void monster_die(monsters *monster, killer_type killer, int i, bool silent) && mons_is_evil_or_unholy(monster) && (!player_under_penance() && random2(you.piety) >= piety_breakpoint(0)) - && i != ANON_FRIENDLY_MONSTER - && i >= 0 && i < MAX_MONSTERS) + && !invalid_monster_index(i)) { monsters *mon = &menv[i]; if (mon->alive() && mon->hit_points < mon->max_hit_points) diff --git a/crawl-ref/source/religion.cc b/crawl-ref/source/religion.cc index ae28e7cc12..c5653df1b2 100644 --- a/crawl-ref/source/religion.cc +++ b/crawl-ref/source/religion.cc @@ -3426,7 +3426,7 @@ void beogh_convert_orc(monsters *orc, bool emergency, { _print_converted_orc_speech("reaction_sight", orc, MSGCH_MONSTER_ENCHANT); - + if (!one_chance_in(3)) _print_converted_orc_speech("speech_sight", orc, MSGCH_TALK); } @@ -3438,6 +3438,8 @@ void beogh_convert_orc(monsters *orc, bool emergency, // hostile later on, it won't count as a good kill orc->flags |= MF_CREATED_FRIENDLY; + orc->flags |= MF_GOD_GIFT; + if (orc->hit_points <= 0) orc->hit_points = std::min(random_range(1, 4), orc->max_hit_points); -- cgit v1.2.3-54-g00ecf