1 #pragma once 2 3 #include <functional> 4 #include <vector> 5 6 #include "actor.h" 7 #include "beh-type.h" 8 #include "enchant-type.h" 9 #include "kill-method-type.h" 10 #include "mon-ench.h" 11 #include "mon-poly.h" 12 #include "montravel-target-type.h" 13 #include "potion-type.h" 14 #include "seen-context-type.h" 15 #include "spl-util.h" 16 #include "xp-tracking-type.h" 17 18 using std::vector; 19 20 const int KRAKEN_TENTACLE_RANGE = 3; 21 #define TIDE_CALL_TURN "tide-call-turn" 22 23 #define MAX_DAMAGE_COUNTER 10000 24 #define ZOMBIE_BASE_AC_KEY "zombie_base_ac" 25 #define ZOMBIE_BASE_EV_KEY "zombie_base_ev" 26 #define MON_SPEED_KEY "speed" 27 #define CUSTOM_SPELLS_KEY "custom_spells" 28 #define SEEN_SPELLS_KEY "seen_spells" 29 #define KNOWN_MAX_HP_KEY "known_max_hp" 30 #define VAULT_HD_KEY "vault_hd" 31 32 #define FAKE_BLINK_KEY "fake_blink" 33 #define CEREBOV_DISARMED_KEY "cerebov_disarmed" 34 35 /// has a given hound already used up its howl? 36 #define DOOM_HOUND_HOWLED_KEY "doom_hound_howled" 37 38 #define DROPPER_MID_KEY "dropper_mid" 39 40 #define MAP_KEY "map" 41 42 typedef map<enchant_type, mon_enchant> mon_enchant_list; 43 44 struct monsterentry; 45 46 class monster : public actor 47 { 48 public: 49 monster(); 50 monster(const monster& other); 51 ~monster(); 52 53 monster& operator = (const monster& other); 54 void reset(); 55 56 public: 57 // Possibly some of these should be moved into the hash table 58 string mname; 59 60 int hit_points; 61 int max_hit_points; 62 int speed; 63 int speed_increment; 64 65 coord_def target; 66 coord_def firing_pos; 67 coord_def patrol_point; 68 mutable montravel_target_type travel_target; 69 vector<coord_def> travel_path; 70 FixedVector<short, NUM_MONSTER_SLOTS> inv; 71 monster_spells spells; 72 mon_attitude_type attitude; 73 beh_type behaviour; 74 unsigned short foe; 75 int8_t ench_countdown; 76 mon_enchant_list enchantments; 77 FixedBitVector<NUM_ENCHANTMENTS> ench_cache; 78 monster_flags_t flags; // bitfield of boolean flags 79 xp_tracking_type xp_tracking; 80 81 unsigned int experience; 82 monster_type base_monster; // zombie base monster, draconian colour 83 union 84 { 85 // These must all be the same size! 86 unsigned int number; ///< General purpose number variable 87 int blob_size; ///< num of slimes/masses in this one 88 int num_heads; ///< Hydra-like head number 89 int ballisto_activity; ///< How active is this ballistomycete? 90 int spore_cooldown; ///< Can this make ballistos (if 0) 91 int mangrove_pests; ///< num of animals in shambling mangrove 92 int prism_charge; ///< Turns this prism has existed 93 int battlecharge; ///< Charges of battlesphere 94 int move_spurt; ///< Sixfirhy/jiangshi/kraken black magic 95 int steps_remaining; ///< Foxfire remaining moves 96 mid_t tentacle_connect;///< mid of monster this tentacle is 97 // connected to: for segments, this is the 98 // tentacle; for tentacles, the head. 99 }; 100 int colour; 101 mid_t summoner; 102 103 int foe_memory; // how long to 'remember' foe x,y 104 // once they go out of sight. 105 106 god_type god; // What god the monster worships, if 107 // any. 108 109 unique_ptr<ghost_demon> ghost; // Ghost information. 110 111 seen_context_type seen_context; // Non-standard context for 112 // activity_interrupt::see_monster 113 114 int damage_friendly; // Damage taken, x2 you, x1 pets, x0 else. 115 int damage_total; 116 117 uint32_t client_id; // for ID of monster_info between turns 118 static uint32_t last_client_id; 119 120 bool went_unseen_this_turn; 121 coord_def unseen_pos; 122 123 public: 124 void set_new_monster_id(); 125 126 uint32_t get_client_id() const; 127 void reset_client_id(); 128 void ensure_has_client_id(); 129 130 void set_hit_dice(int new_hd); 131 132 mon_attitude_type temp_attitude() const override; real_attitude()133 mon_attitude_type real_attitude() const override { return attitude; } 134 135 // Returns true if the monster is named with a proper name, or is 136 // a player ghost. 137 bool is_named() const; 138 139 // Does this monster have a base name, i.e. is base_name() != name(). 140 // See base_name() for details. 141 bool has_base_name() const; 142 143 const monsterentry *find_monsterentry() const; 144 145 void init_experience(); 146 147 void mark_summoned(int longevity, bool mark_items_summoned, 148 int summon_type = 0, bool abj = true); 149 bool is_summoned(int* duration = nullptr, int* summon_type = nullptr) const 150 override; 151 bool is_perm_summoned() const override; 152 bool has_action_energy() const; 153 void check_redraw(const coord_def &oldpos, bool clear_tiles = true) const; 154 void apply_location_effects(const coord_def &oldpos, 155 killer_type killer = KILL_NONE, 156 int killernum = -1) override; 157 void self_destruct() override; 158 159 void set_position(const coord_def &c) override; 160 void moveto(const coord_def& c, bool clear_net = true) override; 161 bool move_to_pos(const coord_def &newpos, bool clear_net = true, 162 bool force = false) override; 163 bool swap_with(monster* other); 164 bool blink_to(const coord_def& c, bool quiet = false) override; 165 bool blink_to(const coord_def& c, bool quiet, bool jump); 166 kill_category kill_alignment() const override; 167 168 int foe_distance() const; 169 bool needs_berserk(bool check_spells = true, bool ignore_distance = false) const; 170 171 // Has a hydra-like variable number of attacks based on num_heads. 172 bool has_hydra_multi_attack() const; 173 int heads() const override; 174 bool has_multitargeting() const; 175 176 // Has the 'priest' flag. 177 bool is_priest() const; 178 179 // Has the 'fighter' flag. 180 bool is_fighter() const; 181 182 // Has the 'archer' flag. 183 bool is_archer() const; 184 185 // Is an actual wizard-type spellcaster (it can be silenced, Trog 186 // will dislike it, etc.). 187 bool is_actual_spellcaster() const; 188 189 // Has ENCH_SHAPESHIFTER or ENCH_GLOWING_SHAPESHIFTER. 190 bool is_shapeshifter() const; 191 192 #ifdef DEBUG_ENCH_CACHE_DIAGNOSTICS 193 bool has_ench(enchant_type ench) const; // same but validated 194 #else has_ench(enchant_type ench)195 bool has_ench(enchant_type ench) const { return ench_cache[ench]; } 196 #endif 197 bool has_ench(enchant_type ench, enchant_type ench2) const; 198 mon_enchant get_ench(enchant_type ench, 199 enchant_type ench2 = ENCH_NONE) const; 200 bool add_ench(const mon_enchant &); 201 void update_ench(const mon_enchant &); 202 bool del_ench(enchant_type ench, bool quiet = false, bool effect = true); 203 bool lose_ench_duration(const mon_enchant &e, int levels); 204 bool lose_ench_levels(const mon_enchant &e, int lev, bool infinite = false); 205 void lose_energy(energy_use_type et, int div = 1, int mult = 1) override; 206 void gain_energy(energy_use_type et, int div = 1, int mult = 1) override; 207 208 void scale_hp(int num, int den); 209 bool gain_exp(int exp, int max_levels_to_gain = 2); 210 211 void react_to_damage(const actor *oppressor, int damage, beam_type flavour); 212 213 void apply_enchantments(); 214 215 bool can_drink() const; 216 bool can_drink_potion(potion_type ptype) const; 217 bool should_drink_potion(potion_type ptype) const; 218 bool drink_potion_effect(potion_type pot_eff, bool card = false); 219 220 bool can_evoke_jewellery(jewellery_type jtype) const; 221 bool should_evoke_jewellery(jewellery_type jtype) const; 222 bool evoke_jewellery_effect(jewellery_type jtype); 223 224 void timeout_enchantments(int levels); 225 226 bool is_travelling() const; 227 bool is_patrolling() const; 228 bool needs_abyss_transit() const; 229 void set_transit(const level_id &destination); 230 bool is_trap_safe(const coord_def& where, bool just_check = false) const; 231 bool is_location_safe(const coord_def &place); 232 bool find_place_to_live(bool near_player = false); 233 bool find_home_near_place(const coord_def &c); 234 bool find_home_near_player(); 235 bool find_home_anywhere(); 236 237 // The map that placed this monster. 238 bool has_originating_map() const; 239 string originating_map() const; 240 void set_originating_map(const string &); 241 242 void set_ghost(const ghost_demon &ghost); 243 void ghost_init(bool need_pos = true); 244 void ghost_demon_init(); 245 void uglything_init(bool only_mutate = false); 246 void uglything_mutate(colour_t force_colour = COLOUR_UNDEF); 247 void destroy_inventory(); 248 void load_ghost_spells(); 249 brand_type ghost_brand() const; 250 bool has_ghost_brand() const; 251 252 actor *get_foe() const; 253 254 // actor interface 255 int mindex() const override; 256 int get_hit_dice() const override; 257 int get_experience_level() const override; 258 god_type deity() const override; 259 bool alive() const override; defined()260 bool defined() const { return alive(); } 261 bool swimming() const override; 262 263 bool submerged() const override; 264 bool can_drown() const; 265 bool floundering_at(const coord_def p) const; 266 bool floundering() const override; 267 bool extra_balanced_at(const coord_def p) const; 268 bool extra_balanced() const override; 269 bool can_pass_through_feat(dungeon_feature_type grid) const override; 270 bool can_burrow() const override; 271 bool is_habitable_feat(dungeon_feature_type actual_grid) const override; 272 bool shove(const char* name = "") override; 273 274 size_type body_size(size_part_type psize = PSIZE_TORSO, 275 bool base = false) const override; 276 brand_type damage_brand(int which_attack = -1) override; 277 int damage_type(int which_attack = -1) override; 278 random_var attack_delay(const item_def *projectile = nullptr, 279 bool rescale = true) const override; 280 int has_claws(bool allow_tran = true) const override; 281 282 int wearing(equipment_type slot, int type, bool calc_unid = true) const 283 override; 284 int wearing_ego(equipment_type slot, int type, bool calc_unid = true) const 285 override; 286 int scan_artefacts(artefact_prop_type which_property, 287 bool calc_unid = true, 288 vector<const item_def *> *_unused_matches = nullptr) const 289 override; 290 291 item_def *slot_item(equipment_type eq, bool include_melded=false) const 292 override; 293 item_def *mslot_item(mon_inv_type sl) const; 294 item_def *weapon(int which_attack = -1) const override; 295 item_def *launcher() const; 296 item_def *melee_weapon() const; 297 item_def *missiles() const; 298 item_def *shield() const override; 299 item_def *get_defining_object() const; 300 301 hands_reqd_type hands_reqd(const item_def &item, 302 bool base = false) const override; 303 304 bool can_wield(const item_def &item, 305 bool ignore_curse = false, 306 bool ignore_brand = false, 307 bool ignore_shield = false, 308 bool ignore_transform = false) const override; 309 bool could_wield(const item_def &item, 310 bool ignore_brand = false, 311 bool ignore_transform = false, 312 bool quiet = true) const override; 313 314 void wield_melee_weapon(maybe_bool msg = MB_MAYBE); 315 void swap_weapons(maybe_bool msg = MB_MAYBE); 316 bool pickup_item(item_def &item, bool msg, bool force); 317 bool drop_item(mon_inv_type eslot, bool msg); 318 bool unequip(item_def &item, bool msg, bool force = false); 319 void steal_item_from_player(); 320 item_def* take_item(int steal_what, mon_inv_type mslot, 321 bool is_stolen = false); 322 item_def* disarm(); 323 324 bool can_use_missile(const item_def &item) const; 325 bool likes_wand(const item_def &item) const; 326 327 string name(description_level_type type, bool force_visible = false, 328 bool force_article = false) const override; 329 330 // Base name of the monster, bypassing any mname setting. For an orc priest 331 // named Arbolt, name() will return "Arbolt", but base_name() will return 332 // "orc priest". 333 string base_name(description_level_type type, 334 bool force_visible = false) const; 335 // Full name of the monster. For an orc priest named Arbolt, full_name() 336 // will return "Arbolt the orc priest". 337 string full_name(description_level_type type) const; 338 string pronoun(pronoun_type pro, bool force_visible = false) const override; 339 bool pronoun_plurality(bool force_visible = false) const; 340 string conj_verb(const string &verb) const override; 341 string hand_name(bool plural, bool *can_plural = nullptr) const override; 342 string foot_name(bool plural, bool *can_plural = nullptr) const override; 343 string arm_name(bool plural, bool *can_plural = nullptr) const override; 344 345 bool fumbles_attack() override; 346 347 int skill(skill_type skill, int scale = 1, bool real = false, 348 bool temp = true) const override; 349 350 void attacking(actor *other, bool ranged) override; 351 bool can_go_frenzy(bool check_sleep = true) const; 352 bool can_go_berserk() const override; 353 bool go_berserk(bool intentional, bool potion = false) override; 354 bool go_frenzy(actor *source); 355 bool berserk() const override; 356 bool berserk_or_insane() const; 357 bool can_mutate() const override; 358 bool can_safely_mutate(bool temp = true) const override; 359 bool can_polymorph() const override; 360 bool can_bleed(bool allow_tran = true) const override; 361 bool is_stationary() const override; 362 bool malmutate(const string &/*reason*/) override; 363 void corrupt(); 364 bool polymorph(int pow, bool allow_immobile = true) override; 365 bool polymorph(poly_power_type power = PPT_SAME); 366 void banish(const actor *agent, const string &who = "", const int power = 0, 367 bool force = false) override; 368 void expose_to_element(beam_type element, int strength = 0, 369 bool slow_cold_blood = true) override; 370 371 monster_type mons_species(bool zombie_base = false) const override; 372 373 mon_holy_type holiness(bool /*temp*/ = true) const override; 374 bool undead_or_demonic(bool /*temp*/ = true) const override; 375 bool is_holy() const override; 376 bool is_nonliving(bool /*temp*/ = true) const override; 377 int how_unclean(bool check_god = true) const; 378 int known_chaos(bool check_spells_god = false) const; 379 int how_chaotic(bool check_spells_god = false) const override; 380 bool is_unbreathing() const override; 381 bool is_insubstantial() const override; 382 bool res_damnation() const override; 383 int res_fire() const override; 384 int res_steam() const override; 385 int res_cold() const override; 386 int res_elec() const override; 387 int res_poison(bool temp = true) const override; 388 bool res_miasma(bool /*temp*/ = true) const override; 389 int res_water_drowning() const override; 390 bool res_sticky_flame() const override; 391 int res_holy_energy() const override; 392 int res_negative_energy(bool intrinsic_only = false) const override; 393 bool res_torment() const override; 394 int res_acid(bool calc_unid = true) const override; 395 bool res_polar_vortex() const override; 396 bool res_petrify(bool /*temp*/ = true) const override; 397 int res_constrict() const override; 398 int willpower(bool calc_unid = true) const override; 399 bool no_tele(bool calc_unid = true, bool permit_id = true, 400 bool blink = false) const override; 401 bool res_corr(bool calc_unid = true, bool temp = true) const override; 402 bool antimagic_susceptible() const override; 403 404 bool stasis() const override; 405 bool cloud_immune(bool calc_unid = true, bool items = true) const override; 406 407 bool airborne() const override; 408 bool is_banished() const override; 409 bool is_web_immune() const override; 410 bool invisible() const override; 411 bool can_see_invisible(bool calc_unid = true) const override; 412 bool visible_to(const actor *looker) const override; 413 bool near_foe() const; 414 reach_type reach_range() const override; 415 bool nightvision() const override; 416 417 bool is_icy() const override; 418 bool is_fiery() const override; 419 bool is_skeletal() const override; 420 bool is_spiny() const; 421 bool paralysed() const override; 422 bool cannot_move() const override; 423 bool cannot_act() const override; 424 bool confused() const override; 425 bool confused_by_you() const; 426 bool caught() const override; 427 bool asleep() const override; 428 bool backlit(bool self_halo = true) const override; 429 bool umbra() const override; 430 int halo_radius() const override; 431 int silence_radius() const override; 432 int demon_silence_radius() const override; 433 int liquefying_radius() const override; 434 int umbra_radius() const override; 435 bool petrified() const override; 436 bool petrifying() const override; 437 bool liquefied_ground() const override; 438 int natural_regen_rate() const; 439 int off_level_regen_rate() const; 440 bool can_feel_fear(bool include_unknown) const override; 441 442 bool friendly() const; 443 bool neutral() const; 444 bool good_neutral() const; 445 bool strict_neutral() const; 446 bool wont_attack() const override; 447 bool pacified() const; 448 449 bool has_spells() const; 450 bool has_spell(spell_type spell) const override; 451 mon_spell_slot_flags spell_slot_flags(spell_type spell) const; 452 bool has_unclean_spell() const; 453 bool has_chaotic_spell() const; 454 455 bool has_attack_flavour(int flavour) const; 456 bool has_damage_type(int dam_type); 457 int constriction_damage(bool direct) const override; 458 bool constriction_does_damage(bool direct) const override; 459 460 bool can_throw_large_rocks() const override; 461 bool can_speak(); 462 bool is_silenced() const; 463 464 int base_armour_class() const; 465 int armour_class(bool calc_unid = true) const override; gdr_perc()466 int gdr_perc() const override { return 0; } 467 int base_evasion() const; 468 int evasion(ev_ignore_type evit = ev_ignore::none, 469 const actor* /*attacker*/ = nullptr) const override; 470 471 bool poison(actor *agent, int amount = 1, bool force = false) override; 472 bool sicken(int strength) override; 473 void paralyse(const actor *, int str, string source = "") override; 474 void petrify(const actor *, bool force = false) override; 475 bool fully_petrify(bool quiet = false) override; 476 void slow_down(actor *, int str) override; 477 void confuse(actor *, int strength) override; 478 bool drain(const actor *, bool quiet = false, int pow = 3) override; 479 void splash_with_acid(const actor* evildoer, int /*acid_strength*/ = -1, 480 bool /*allow_corrosion*/ = true, 481 const char* /*hurt_msg*/ = nullptr) override; 482 bool corrode_equipment(const char* corrosion_source = "the acid", 483 int degree = 1) override; 484 int hurt(const actor *attacker, int amount, 485 beam_type flavour = BEAM_MISSILE, 486 kill_method_type kill_type = KILLED_BY_MONSTER, 487 string source = "", 488 string aux = "", 489 bool cleanup_dead = true, 490 bool attacker_effects = true) override; 491 bool heal(int amount) override; 492 void blame_damage(const actor *attacker, int amount); 493 void blink() override; 494 void teleport(bool right_now = false, 495 bool wizard_tele = false) override; 496 bool shift(coord_def p = coord_def(0, 0)); 497 void suicide(int hp_target = -1); 498 499 void put_to_sleep(actor *attacker, int power = 0, bool hibernate = false) 500 override; 501 void weaken(actor *attacker, int pow) override; 502 void check_awaken(int disturbance) override; 503 int beam_resists(bolt &beam, int hurted, bool doEffects, string source = "") 504 override; 505 stat_hp()506 int stat_hp() const override { return hit_points; } stat_maxhp()507 int stat_maxhp() const override { return max_hit_points; } stealth()508 int stealth() const override { return 0; } 509 510 511 bool shielded() const override; 512 int shield_bonus() const override; 513 int shield_block_penalty() const override; 514 void shield_block_succeeded() override; 515 int shield_bypass_ability(int tohit) const override; 516 bool missile_repulsion() const override; 517 518 // Combat-related class methods unadjusted_body_armour_penalty()519 int unadjusted_body_armour_penalty() const override { return 0; } adjusted_body_armour_penalty(int)520 int adjusted_body_armour_penalty(int) const override { return 0; } adjusted_shield_penalty(int)521 int adjusted_shield_penalty(int) const override { return 0; } armour_tohit_penalty(bool,int)522 int armour_tohit_penalty(bool, int) const override { return 0; } shield_tohit_penalty(bool,int)523 int shield_tohit_penalty(bool, int) const override { return 0; } 524 is_player()525 bool is_player() const override { return false; } as_monster()526 monster* as_monster() override { return this; } as_player()527 player* as_player() override { return nullptr; } as_monster()528 const monster* as_monster() const override { return this; } as_player()529 const player* as_player() const override { return nullptr; } 530 531 // Hacks, with a capital H. 532 void check_speed(); 533 void upgrade_type(monster_type after, bool adjust_hd, bool adjust_hp); 534 535 string describe_enchantments() const; 536 537 int action_energy(energy_use_type et) const; 538 539 bool do_shaft() override; 540 bool has_spell_of_type(spschool discipline) const; 541 542 void bind_melee_flags(); 543 void bind_spell_flags(); 544 void calc_speed(); 545 bool attempt_escape(int attempts = 1); 546 void struggle_against_net(); 547 void catch_breath(); 548 bool has_usable_tentacle() const override; 549 550 bool is_child_tentacle() const; 551 bool is_child_tentacle_of(const monster* mons) const; 552 bool is_child_monster() const; 553 bool is_parent_monster_of(const monster* mons) const; 554 bool is_child_tentacle_segment() const; 555 556 bool is_illusion() const; 557 bool is_divine_companion() const; 558 bool is_dragonkind() const override; 559 int dragon_level() const override; 560 bool is_jumpy() const; 561 562 int spell_hd(spell_type spell = SPELL_NO_SPELL) const; 563 void remove_summons(bool check_attitude = false); 564 565 bool clear_far_engulf(bool force = false) override; 566 bool search_slots(function<bool (const mon_spell_slot &)> func) const; 567 568 bool has_facet(int facet) const; 569 bool angered_by_attacks() const; 570 571 private: 572 int hit_dice; 573 574 private: 575 bool pickup(item_def &item, mon_inv_type slot, bool msg); 576 void pickup_message(const item_def &item); 577 bool pickup_wand(item_def &item, bool msg, bool force = false); 578 bool pickup_scroll(item_def &item, bool msg); 579 bool pickup_potion(item_def &item, bool msg, bool force = false); 580 bool pickup_gold(item_def &item, bool msg); 581 bool pickup_launcher(item_def &launcher, bool msg, bool force = false); 582 bool pickup_melee_weapon(item_def &item, bool msg); 583 bool pickup_weapon(item_def &item, bool msg, bool force); 584 bool pickup_armour(item_def &item, bool msg, bool force); 585 bool pickup_jewellery(item_def &item, bool msg, bool force); 586 bool pickup_misc(item_def &item, bool msg, bool force); 587 bool pickup_missile(item_def &item, bool msg, bool force); 588 589 void equip_message(item_def &item); 590 void equip_weapon_message(item_def &item); 591 void equip_armour_message(item_def &item); 592 void equip_jewellery_message(item_def &item); 593 void unequip_weapon(item_def &item, bool msg); 594 void unequip_armour(item_def &item, bool msg); 595 void unequip_jewellery(item_def &item, bool msg); 596 597 void init_with(const monster& mons); 598 599 bool level_up(); 600 bool level_up_change(); 601 int armour_bonus(const item_def &item, bool calc_unid = true) const; 602 603 void id_if_worn(mon_inv_type mslot, object_class_type base_type, 604 int sub_type) const; 605 606 bool decay_enchantment(enchant_type en, bool decay_degree = true); 607 608 bool wants_weapon(const item_def &item) const; 609 bool wants_armour(const item_def &item) const; 610 bool wants_jewellery(const item_def &item) const; 611 void lose_pickup_energy(); 612 bool check_set_valid_home(const coord_def &place, 613 coord_def &chosen, 614 int &nvalid) const; 615 bool search_spells(function<bool (spell_type)> func) const; 616 bool is_cloud_safe(const coord_def &place) const; 617 618 void add_enchantment_effect(const mon_enchant &me, bool quiet = false); 619 void remove_enchantment_effect(const mon_enchant &me, bool quiet = false); 620 void apply_enchantment(const mon_enchant &me); 621 }; 622