diff options
-rw-r--r-- | crawl-ref/source/enum.h | 12 | ||||
-rw-r--r-- | crawl-ref/source/externs.h | 13 | ||||
-rw-r--r-- | crawl-ref/source/fight.cc | 29 | ||||
-rw-r--r-- | crawl-ref/source/mon-util.cc | 46 | ||||
-rw-r--r-- | crawl-ref/source/mon-util.h | 2 | ||||
-rw-r--r-- | crawl-ref/source/monstuff.cc | 39 | ||||
-rw-r--r-- | crawl-ref/source/mstuff2.cc | 5 |
7 files changed, 89 insertions, 57 deletions
diff --git a/crawl-ref/source/enum.h b/crawl-ref/source/enum.h index 81671b0cce..77e327e4eb 100644 --- a/crawl-ref/source/enum.h +++ b/crawl-ref/source/enum.h @@ -1099,6 +1099,18 @@ enum enchant_retval ERV_INCREASED }; +enum energy_use_type +{ + EUT_MOVE, + EUT_SWIM, + EUT_ATTACK, + EUT_MISSILE, + EUT_SPELL, + EUT_SPECIAL, + EUT_ITEM, + EUT_PICKUP +}; + enum equipment_type { EQ_NONE = -1, diff --git a/crawl-ref/source/externs.h b/crawl-ref/source/externs.h index b787849353..f3d0959fe3 100644 --- a/crawl-ref/source/externs.h +++ b/crawl-ref/source/externs.h @@ -103,6 +103,12 @@ public: virtual void make_hungry(int nutrition, bool silent = true) { } + + // Need not be implemented for the player - player action costs + // are explicitly calculated. + virtual void lose_energy(energy_use_type) + { + } virtual std::string name(description_level_type type) const = 0; virtual std::string pronoun(pronoun_type which_pronoun) const = 0; @@ -960,6 +966,8 @@ private: typedef std::map<enchant_type, mon_enchant> mon_enchant_list; +struct monsterentry; + class monsters : public actor { public: @@ -1027,6 +1035,7 @@ public: bool del_ench(enchant_type ench, bool quiet = false); bool lose_ench_duration(const mon_enchant &e, int levels); bool lose_ench_levels(const mon_enchant &e, int lev); + void lose_energy(energy_use_type et); void scale_hp(int num, int den); void gain_exp(int xp); @@ -1178,6 +1187,7 @@ public: std::string describe_enchantments() const; + int action_energy(energy_use_type et) const; static int base_speed(int mcls); bool do_shaft(); @@ -1204,7 +1214,8 @@ private: bool check_set_valid_home(const coord_def &place, coord_def &chosen, int &nvalid) const; - bool has_spell_of_type(unsigned) const; + bool has_spell_of_type(unsigned) const; + const monsterentry *find_monsterentry() const; }; struct cloud_struct diff --git a/crawl-ref/source/fight.cc b/crawl-ref/source/fight.cc index 77e572b386..df3bf61b6a 100644 --- a/crawl-ref/source/fight.cc +++ b/crawl-ref/source/fight.cc @@ -478,13 +478,9 @@ bool melee_attack::attack() // Xom thinks fumbles are funny... if (attacker->fumbles_attack()) { - if (attacker->atype() == ACT_MONSTER) - { - // Make sure the monster uses up some energy, even though - // it didn't actually attack. - monsterentry *entry = get_monster_data(atk->type); - atk->speed_increment -= entry->energy_usage.attack; - } + // Make sure the monster uses up some energy, even though + // it didn't actually attack. + attacker->lose_energy(EUT_ATTACK); // ... and thinks fumbling when trying to hit yourself is just // hilarious. @@ -532,8 +528,7 @@ bool melee_attack::attack() { // Make sure the monster uses up some energy, even though // it didn't actually land a blow. - monsterentry *entry = get_monster_data(atk->type); - atk->speed_increment -= entry->energy_usage.attack; + attacker->lose_energy(EUT_ATTACK); if (!mons_near(def)) simple_monster_message(atk, " hits something"); @@ -3459,13 +3454,10 @@ void melee_attack::mons_perform_attack_rounds() const mon_attack_def attk = mons_attack_spec(atk, attack_number); if (attk.type == AT_NONE) { + // Make sure the monster uses up some energy, even + // though it didn't actually attack. if (attack_number == 0) - { - // Make sure the monster uses up some energy, even - // though it didn't actually attack. - monsterentry *entry = get_monster_data(atk->type); - atk->speed_increment -= entry->energy_usage.attack; - } + atk->lose_energy(EUT_ATTACK); break; } @@ -3661,13 +3653,10 @@ bool you_attack(int monster_attacked, bool unarmed_attacks) static void mons_lose_attack_energy(monsters *attacker, int wpn_speed, int which_attack) { - monsterentry *entry = get_monster_data(attacker->type); - char atk_speed = entry->energy_usage.attack; - // Initial attack causes energy to be used for all attacks. No // additional energy is used for unarmed attacks. if (which_attack == 0) - attacker->speed_increment -= atk_speed; + attacker->lose_energy(EUT_ATTACK); // Monsters lose additional energy only for the first two weapon // attacks; subsequent hits are free. @@ -3677,12 +3666,12 @@ static void mons_lose_attack_energy(monsters *attacker, int wpn_speed, // speed adjustment for weapon using monsters if (wpn_speed > 0) { + const int atk_speed = attacker->action_energy(EUT_ATTACK); // only get one third penalty/bonus for second weapons. if (which_attack > 0) wpn_speed = div_rand_round( (2 * atk_speed + wpn_speed), 3 ); int delta = div_rand_round( (wpn_speed - 10 + (atk_speed - 10)), 2 ); - if (delta > 0) attacker->speed_increment -= delta; } diff --git a/crawl-ref/source/mon-util.cc b/crawl-ref/source/mon-util.cc index e7b6d93c4f..1eba1d7e4e 100644 --- a/crawl-ref/source/mon-util.cc +++ b/crawl-ref/source/mon-util.cc @@ -2929,11 +2929,12 @@ bool monsters::unequip(item_def &item, int slot, int near, bool force) void monsters::lose_pickup_energy() { - monsterentry* entry = get_monster_data(type); - int delta = speed * entry->energy_usage.pickup_percent / 100; - - if (speed_increment > 25 && delta < speed_increment) - speed_increment -= delta; + if (const monsterentry* entry = find_monsterentry()) + { + const int delta = speed * entry->energy_usage.pickup_percent / 100; + if (speed_increment > 25 && delta < speed_increment) + speed_increment -= delta; + } } void monsters::pickup_message(const item_def &item, int near) @@ -3348,8 +3349,8 @@ void monsters::swap_weapons(int near) // Monsters can swap weapons really fast. :-) if ((weap || alt) && speed_increment >= 2) { - monsterentry *entry = get_monster_data(type); - speed_increment -= div_rand_round(entry->energy_usage.attack, 5); + if (const monsterentry *entry = find_monsterentry()) + speed_increment -= div_rand_round(entry->energy_usage.attack, 5); } } @@ -5092,6 +5093,37 @@ void monsters::check_awaken(int) // XXX } +const monsterentry *monsters::find_monsterentry() const +{ + return (type == -1 || type == MONS_PROGRAM_BUG) ? NULL + : get_monster_data(type); +} + +int monsters::action_energy(energy_use_type et) const +{ + if (const monsterentry *me = find_monsterentry()) + { + const mon_energy_usage &mu = me->energy_usage; + switch (et) + { + case EUT_MOVE: return mu.move; + case EUT_SWIM: return mu.swim; + case EUT_MISSILE: return mu.missile; + case EUT_ITEM: return mu.item; + case EUT_SPECIAL: return mu.special; + case EUT_SPELL: return mu.spell; + case EUT_ATTACK: return mu.attack; + case EUT_PICKUP: return mu.pickup_percent; + } + } + return 10; +} + +void monsters::lose_energy(energy_use_type et) +{ + speed_increment -= action_energy(et); +} + ///////////////////////////////////////////////////////////////////////// // mon_enchant diff --git a/crawl-ref/source/mon-util.h b/crawl-ref/source/mon-util.h index 0556f23817..4835b1783d 100644 --- a/crawl-ref/source/mon-util.h +++ b/crawl-ref/source/mon-util.h @@ -261,7 +261,7 @@ struct mon_energy_usage // Percent of monster->speed used when picking up an item; defaults // to 100% - char pickup_percent; + char pickup_percent; }; struct monsterentry diff --git a/crawl-ref/source/monstuff.cc b/crawl-ref/source/monstuff.cc index cd71198007..8f23cf1e8e 100644 --- a/crawl-ref/source/monstuff.cc +++ b/crawl-ref/source/monstuff.cc @@ -2841,10 +2841,7 @@ static bool handle_special_ability(monsters *monster, bolt & beem) } if (used) - { - monsterentry *entry = get_monster_data(monster->type); - monster->speed_increment -= entry->energy_usage.special; - } + monster->lose_energy(EUT_SPECIAL); return (used); } // end handle_special_ability() @@ -2948,8 +2945,7 @@ static bool handle_potion(monsters *monster, bolt & beem) if (ident != ID_UNKNOWN_TYPE && was_visible) set_ident_type(OBJ_POTIONS, potion_type, ident); - monsterentry *entry = get_monster_data(monster->type); - monster->speed_increment -= entry->energy_usage.item; + monster->lose_energy(EUT_ITEM); } return (imbibed); @@ -3092,8 +3088,7 @@ static bool handle_scroll(monsters *monster) if (ident != ID_UNKNOWN_TYPE && was_visible) set_ident_type(OBJ_SCROLLS, scroll_type, ident); - monsterentry *entry = get_monster_data(monster->type); - monster->speed_increment -= entry->energy_usage.item; + monster->lose_energy(EUT_ITEM); } return read; @@ -3264,8 +3259,7 @@ static bool handle_wand(monsters *monster, bolt &beem) wand.plus2++; } - monsterentry *entry = get_monster_data(monster->type); - monster->speed_increment -= entry->energy_usage.item; + monster->lose_energy(EUT_ITEM); return (true); } @@ -3787,8 +3781,7 @@ static bool handle_spell( monsters *monster, bolt & beem ) simple_monster_message(monster, " blinks!"); monster_blink(monster); - monsterentry *entry = get_monster_data(monster->type); - monster->speed_increment -= entry->energy_usage.spell; + monster->lose_energy(EUT_SPELL); } else return (false); @@ -3798,8 +3791,7 @@ static bool handle_spell( monsters *monster, bolt & beem ) mons_cast(monster, beem, spell_cast); mmov_x = 0; mmov_y = 0; - monsterentry *entry = get_monster_data(monster->type); - monster->speed_increment -= entry->energy_usage.spell; + monster->lose_energy(EUT_SPELL); } } // end "if mons_class_flag(monster->type, M_SPELLCASTER) ... @@ -4025,15 +4017,11 @@ static void monster_regenerate(monsters *monster) static void swim_or_move_energy(monsters *mon) { - monsterentry *entry = get_monster_data(mon->type); - dungeon_feature_type feat = grd[mon->x][mon->y]; - if (feat >= DNGN_LAVA && feat <= DNGN_SHALLOW_WATER - && !mon->airborne()) - { - mon->speed_increment -= entry->energy_usage.swim; - } - else - mon->speed_increment -= entry->energy_usage.move; + const dungeon_feature_type feat = grd[mon->x][mon->y]; + // FIXME: Replace check with mons_is_swimming()? + mon->lose_energy( + feat >= DNGN_LAVA && feat <= DNGN_SHALLOW_WATER + && !mon->airborne() ? EUT_SWIM : EUT_MOVE ); } #if DEBUG @@ -4119,6 +4107,8 @@ static void handle_monster_move(int i, monsters *monster) monster->check_speed(); monsterentry* entry = get_monster_data(monster->type); + if (!entry) + return; int old_energy = INT_MAX; int non_move_energy = std::min(entry->energy_usage.move, @@ -5087,8 +5077,7 @@ static void mons_open_door(monsters* monster, const coord_def &pos) } } - monsterentry *entry = get_monster_data(monster->type); - monster->speed_increment -= entry->energy_usage.move; + monster->lose_energy(EUT_MOVE); } // Check whether a monster can move to given square (described by its relative diff --git a/crawl-ref/source/mstuff2.cc b/crawl-ref/source/mstuff2.cc index 5a5edaac3b..12de2729d2 100644 --- a/crawl-ref/source/mstuff2.cc +++ b/crawl-ref/source/mstuff2.cc @@ -1107,9 +1107,8 @@ bool mons_throw(struct monsters *monster, struct bolt &pbolt, int hand_used) const bool skilled = mons_class_flag(monster->type, M_FIGHTER); - const monsterentry *entry = get_monster_data(monster->type); - const int throw_energy = entry->energy_usage.missile; - monster->speed_increment -= throw_energy; + monster->lose_energy(EUT_MISSILE); + const int throw_energy = monster->action_energy(EUT_MISSILE); // Dropping item copy, since the launched item might be different. item_def item = mitm[hand_used]; |