From: <gi...@cr...> - 2011-03-31 21:00:20
|
via dd07df81c8e6820af65f8993c50ca5ae0992c87a (commit) from 3393595462a5522b334236b823b1c90f32f375ba (commit) ----------------------------------------------------------------------- commit dd07df81c8e6820af65f8993c50ca5ae0992c87a Author: Robert Burnham <bur...@gm...> Date: Thu Mar 31 15:55:22 2011 -0500 Establish handle_{{phase}} class methods Creates shell class methods in attack to serve as the classes overloaded in inheriting classes which handle each particular phase of an attack. Any given handle_{{phase}} class method returns whether or not that phase was successful. Success indicates to continue to the next phase based on the appropriate variable configuration (eg, if to_hit and !blocked, do handle_landed()). handle_phase_attempted is the only non pure-virtual method of the attack class because there are problably some initialization-related variables that we can always compute and/or set for all attacks. handle_phase_attempted will be called by the attack constructor. ----------------------------------------------------------------------- Summary of changes: crawl-ref/source/attack.cc | 9 +++++++-- crawl-ref/source/attack.h | 17 ++++++++++++++--- crawl-ref/source/melee_attack.cc | 36 ++++++++++++++++++++++++++++++++++++ crawl-ref/source/melee_attack.h | 11 ++++++++++- 4 files changed, 67 insertions(+), 6 deletions(-) diff --git a/crawl-ref/source/attack.cc b/crawl-ref/source/attack.cc index f588565..2b0d85f 100644 --- a/crawl-ref/source/attack.cc +++ b/crawl-ref/source/attack.cc @@ -26,8 +26,9 @@ ************************************************** */ attack::attack(actor *attk, actor *defn, bool allow_unarmed) - : attacker(attk), defender(defn), cancel_attack(false), did_hit(false), - needs_message(false), attacker_visible(false), defender_visible(false), + : attacker(attk), defender(defn), attack_phase(ATK_ATTEMPTED), + cancel_attack(false), did_hit(false), needs_message(false), + attacker_visible(false), defender_visible(false), attacker_invisible(false), defender_invisible(false), to_hit(0), damage_done(0), aux_damage(0), stab_attempt(false), stab_bonus(0), min_delay(0), final_attack_delay(0), unarmed_ok(allow_unarmed), @@ -44,6 +45,10 @@ attack::attack(actor *attk, actor *defn, bool allow_unarmed) // of attack actually being made (melee, ranged, etc.) } +bool attack::handle_phase_attempted() { + return true; +} + /* Returns an actor's name * * Takes into account actor visibility/invisibility and the type of description diff --git a/crawl-ref/source/attack.h b/crawl-ref/source/attack.h index ffb9d0e..621ffce 100644 --- a/crawl-ref/source/attack.h +++ b/crawl-ref/source/attack.h @@ -9,14 +9,15 @@ const int HIT_WEAK = 7; const int HIT_MED = 18; const int HIT_STRONG = 36; -enum phase +enum atk_phase { ATK_ATTEMPTED, // 0 ATK_DODGED, ATK_BLOCKED, ATK_HIT, ATK_DAMAGED, - ATK_KILLED + ATK_KILLED, + ATK_END }; class attack @@ -25,7 +26,8 @@ class attack public: // General attack properties, set on instantiation or through a normal // thread of execution - actor *attacker, *defender; + actor *attacker, *defender; + atk_phase attack_phase; bool cancel_attack; bool did_hit; @@ -108,6 +110,15 @@ public: // Private Methods protected: virtual void init_attack(); + + virtual bool handle_phase_attempted(); + virtual bool handle_phase_dodged() = 0; + virtual bool handle_phase_blocked() = 0; + virtual bool handle_phase_hit() = 0; + virtual bool handle_phase_damaged() = 0; + virtual bool handle_phase_killed() = 0; + virtual bool handle_phase_end() = 0; + virtual bool check_unrand_effects() = 0; // Methods which produce output diff --git a/crawl-ref/source/melee_attack.cc b/crawl-ref/source/melee_attack.cc index 53bbde7..97540a3 100644 --- a/crawl-ref/source/melee_attack.cc +++ b/crawl-ref/source/melee_attack.cc @@ -176,6 +176,42 @@ void melee_attack::init_attack() miscast_target = NULL; } +bool melee_attack::handle_phase_attempted() +{ + return true; +} + +bool melee_attack::handle_phase_dodged() +{ + return true; +} + +bool melee_attack::handle_phase_blocked() +{ + return true; +} + +bool melee_attack::handle_phase_hit() +{ + return true; +} + +bool melee_attack::handle_phase_damaged() +{ + return true; +} + +bool melee_attack::handle_phase_killed() +{ + return true; +} + +bool melee_attack::handle_phase_end() +{ + return true; +} + + bool melee_attack::is_banished(const actor *a) const { if (!a || a->alive()) diff --git a/crawl-ref/source/melee_attack.h b/crawl-ref/source/melee_attack.h index 1a73902..0d0ad86 100644 --- a/crawl-ref/source/melee_attack.h +++ b/crawl-ref/source/melee_attack.h @@ -71,6 +71,15 @@ public: private: void init_attack(); + + bool handle_phase_attempted(); + bool handle_phase_dodged(); + bool handle_phase_blocked(); + bool handle_phase_hit(); + bool handle_phase_damaged(); + bool handle_phase_killed(); + bool handle_phase_end(); + bool is_banished(const actor *) const; void check_autoberserk(); bool check_unrand_effects(); @@ -103,7 +112,7 @@ private: void handle_noise(const coord_def & pos); // Handle specific attack phases (mons and player) - void respond_to_attack_phase(phase); + // Added from fight.cc, were static, should be removed int _modify_blood_amount(const int damage, const int dam_type); -- Dungeon Crawl Stone Soup |