From 356d2e3e4b9ce53e0b205ff6fd5b35a4163a0cc5 Mon Sep 17 00:00:00 2001 From: dolorous Date: Fri, 7 Nov 2008 21:39:26 +0000 Subject: Clean up sticky flame handling. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@7409 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/acr.cc | 42 +++++------------------------------ crawl-ref/source/beam.cc | 33 ++++++++++++++-------------- crawl-ref/source/beam.h | 4 ++-- crawl-ref/source/fight.cc | 48 +++++++++++++++++++++------------------- crawl-ref/source/fight.h | 1 + crawl-ref/source/player.cc | 55 ++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 107 insertions(+), 76 deletions(-) (limited to 'crawl-ref/source') diff --git a/crawl-ref/source/acr.cc b/crawl-ref/source/acr.cc index 4c22598b33..c0790a49c0 100644 --- a/crawl-ref/source/acr.cc +++ b/crawl-ref/source/acr.cc @@ -2520,42 +2520,12 @@ static void _decrement_durations() if (_decrement_a_duration(DUR_SLEEP)) you.awake(); - // Paradox: It both lasts longer & does more damage overall if you're - // moving slower. - // Rationalisation: I guess it gets rubbed off/falls off/etc if you - // move around more. - if (you.duration[DUR_LIQUID_FLAMES] > 0) - you.duration[DUR_LIQUID_FLAMES]--; - - if (you.duration[DUR_LIQUID_FLAMES] != 0) - { - const int res_fire = player_res_fire(); - - mpr("You are covered in liquid flames!", MSGCH_WARN); - expose_player_to_element(BEAM_NAPALM, 12); - - if (res_fire > 0) - { - ouch((((random2avg(9, 2) + 1) * you.time_taken) / - (1 + (res_fire * res_fire))) / 10, NON_MONSTER, - KILLED_BY_BURNING); - } - - if (res_fire <= 0) - { - ouch(((random2avg(9, 2) + 1) * you.time_taken) / 10, 0, - KILLED_BY_BURNING); - } - - if (res_fire < 0) - { - ouch(((random2avg(9, 2) + 1) * you.time_taken) / 10, 0, - KILLED_BY_BURNING); - } - - if (you.duration[DUR_CONDENSATION_SHIELD] > 0) - remove_condensation_shield(); - } + // Sticky flame paradox: It both lasts longer and does more damage + // overall if you're moving more slowly. + // + // Rationalisation: I guess it gets rubbed off/falls off/etc. if you + // move around more. + dec_napalm_player(); if (_decrement_a_duration(DUR_ICY_ARMOUR, "Your icy armour evaporates.", diff --git a/crawl-ref/source/beam.cc b/crawl-ref/source/beam.cc index 34e0e4073d..e593c5a32c 100644 --- a/crawl-ref/source/beam.cc +++ b/crawl-ref/source/beam.cc @@ -2434,28 +2434,29 @@ bool poison_monster(monsters *monster, kill_category who, int levels, return (new_pois.degree > old_pois.degree); } -// Actually napalms the player. -void sticky_flame_player() -{ - you.duration[DUR_LIQUID_FLAMES] += random2avg(7, 3) + 1; -} - // Actually napalms a monster (with message). -void sticky_flame_monster(int mn, kill_category who, int levels) +bool napalm_monster(monsters *monster, kill_category who, int levels, + bool verbose) { - monsters *monster = &menv[mn]; - if (!monster->alive()) - return; + return (false); - if (mons_res_sticky_flame(monster)) - return; + if (mons_res_sticky_flame(monster) > 0 || levels <= 0) + return (false); + + const mon_enchant old_flame = monster->get_ench(ENCH_STICKY_FLAME); + monster->add_ench(mon_enchant(ENCH_STICKY_FLAME, levels, who)); + const mon_enchant new_flame = monster->get_ench(ENCH_STICKY_FLAME); - if (monster->add_ench(mon_enchant(ENCH_STICKY_FLAME, levels, who))) + // Actually do the napalming. The order is important here. + if (new_flame.degree > old_flame.degree) { - simple_monster_message(monster, " is covered in liquid flames!"); + if (verbose) + simple_monster_message(monster, " is covered in liquid flames!"); behaviour_event(monster, ME_WHACK, who == KC_YOU ? MHITYOU : MHITNOT); } + + return (new_flame.degree > old_flame.degree); } // Used by monsters in "planning" which spell to cast. Fires off a "tracer" @@ -3904,7 +3905,7 @@ static int _affect_player( bolt &beam, item_def *item, bool affect_items ) { if (!player_res_sticky_flame()) { - sticky_flame_player(); + napalm_player(random2avg(7, 3) + 1); was_affected = true; } } @@ -4443,7 +4444,7 @@ static int _affect_monster(bolt &beam, monsters *mon, item_def *item) if (beam.name == "sticky flame") { int levels = std::min(4, 1 + random2(hurt_final) / 2); - sticky_flame_monster(tid, _whose_kill(beam), levels); + napalm_monster(mon, _whose_kill(beam), levels); } // Handle missile effects. diff --git a/crawl-ref/source/beam.h b/crawl-ref/source/beam.h index f44b638356..9be2ada74c 100644 --- a/crawl-ref/source/beam.h +++ b/crawl-ref/source/beam.h @@ -100,8 +100,6 @@ public: actor* agent() const; }; -void sticky_flame_player(); -void sticky_flame_monster(int mn, kill_category who, int hurt_final); dice_def calc_dice( int num_dice, int max_damage ); // Test if the to-hit (attack) beats evasion (defence). @@ -131,6 +129,8 @@ bool curare_hits_monster(const bolt &beam, monsters *monster, kill_category who, int levels = 1); bool poison_monster(monsters *monster, kill_category who, int levels = 1, bool force = false, bool verbose = true); +bool napalm_monster(monsters *monster, kill_category who, int levels = 1, + bool verbose = true); void fire_tracer( const monsters *monster, struct bolt &pbolt, bool explode_only = false ); bool check_line_of_sight( const coord_def& source, const coord_def& target ); diff --git a/crawl-ref/source/fight.cc b/crawl-ref/source/fight.cc index 9e15a84cba..48a8b22f41 100644 --- a/crawl-ref/source/fight.cc +++ b/crawl-ref/source/fight.cc @@ -3506,6 +3506,31 @@ void melee_attack::mons_do_poison(const mon_attack_def &attk) } } +void melee_attack::mons_do_napalm() +{ + if (defender->res_sticky_flame() > 0) + return; + + if (one_chance_in(20) || (damage_done > 2 && one_chance_in(3))) + { + if (needs_message) + { + mprf("%s %s covered in liquid flames%s", + def_name(DESC_CAP_THE).c_str(), + defender->conj_verb("are").c_str(), + special_attack_punctuation().c_str()); + } + + if (defender->atype() == ACT_PLAYER) + napalm_player(random2avg(7, 3) + 1); + else + { + napalm_monster(def, mons_friendly(atk) ? KC_FRIENDLY : KC_OTHER, + std::min(4, 1 + random2(atk->hit_dice) / 2)); + } + } +} + void melee_attack::wasp_paralyse_defender() { // [dshaligram] Adopted 4.1.2's wasp mechanics, in slightly modified form. @@ -3787,28 +3812,7 @@ void melee_attack::mons_apply_attack_flavour(const mon_attack_def &attk) break; case AF_NAPALM: - if (defender->res_sticky_flame() > 0) - break; - - if (one_chance_in(20) || (damage_done > 2 && one_chance_in(3))) - { - if (needs_message) - { - mprf("%s %s covered in liquid flames%s", - def_name(DESC_CAP_THE).c_str(), - defender->conj_verb("are").c_str(), - special_attack_punctuation().c_str()); - } - - if (defender->atype() == ACT_PLAYER) - sticky_flame_player(); - else - { - sticky_flame_monster(monster_index(def), - mons_friendly(atk) ? KC_FRIENDLY : KC_OTHER, - std::min(4, 1 + random2(atk->hit_dice) / 2)); - } - } + mons_do_napalm(); break; } } diff --git a/crawl-ref/source/fight.h b/crawl-ref/source/fight.h index 2ab259223c..4ac3b0051d 100644 --- a/crawl-ref/source/fight.h +++ b/crawl-ref/source/fight.h @@ -218,6 +218,7 @@ private: void mons_announce_dud_hit(const mon_attack_def &attk); void mons_set_weapon(const mon_attack_def &attk); void mons_do_poison(const mon_attack_def &attk); + void mons_do_napalm(); std::string mons_defender_name(); void wasp_paralyse_defender(); diff --git a/crawl-ref/source/player.cc b/crawl-ref/source/player.cc index 8e8f8e8ae7..5ce17d6463 100644 --- a/crawl-ref/source/player.cc +++ b/crawl-ref/source/player.cc @@ -5077,6 +5077,61 @@ void reduce_poison_player(int amount) mpr("You feel a little better.", MSGCH_RECOVERY); } +bool napalm_player(int amount) +{ + if (player_res_sticky_flame() || amount <= 0) + return (false); + + const int old_value = you.duration[DUR_LIQUID_FLAMES]; + you.duration[DUR_LIQUID_FLAMES] += amount; + + if (you.duration[DUR_LIQUID_FLAMES] > 40) + you.duration[DUR_LIQUID_FLAMES] = 40; + + if (you.duration[DUR_LIQUID_FLAMES] > old_value) + mpr("You are covered in liquid flames!", MSGCH_WARN); + + return (true); +} + +void dec_napalm_player() +{ + if (you.duration[DUR_LIQUID_FLAMES] > 1) + { + you.duration[DUR_LIQUID_FLAMES]--; + + mpr("You are covered in liquid flames!", MSGCH_WARN); + + expose_player_to_element(BEAM_NAPALM, 12); + + const int res_fire = player_res_fire(); + + if (res_fire > 0) + { + ouch((((random2avg(9, 2) + 1) * you.time_taken) / + (1 + (res_fire * res_fire))) / 10, NON_MONSTER, + KILLED_BY_BURNING); + } + + if (res_fire <= 0) + { + ouch(((random2avg(9, 2) + 1) * you.time_taken) / 10, 0, + KILLED_BY_BURNING); + } + + if (res_fire < 0) + { + ouch(((random2avg(9, 2) + 1) * you.time_taken) / 10, 0, + KILLED_BY_BURNING); + } + + if (you.duration[DUR_CONDENSATION_SHIELD] > 0) + remove_condensation_shield(); + } + else if (you.duration[DUR_LIQUID_FLAMES] == 1) + you.duration[DUR_LIQUID_FLAMES] = 0; +} + bool confuse_player(int amount, bool resistable) { if (amount <= 0) -- cgit v1.2.3-54-g00ecf