1 /**
2  * @file
3  * @brief Player related functions.
4 **/
5 
6 
7 #pragma once
8 
9 #include <chrono>
10 #include <list>
11 #include <memory>
12 #include <vector>
13 
14 #include "actor.h"
15 #include "attribute-type.h"
16 #include "beam.h"
17 #include "bitary.h"
18 #include "book-type.h"
19 #include "caction-type.h"
20 #include "daction-type.h"
21 #include "duration-type.h"
22 #include "equipment-type.h"
23 #include "flush-reason-type.h"
24 #include "game-chapter.h"
25 #include "kill-method-type.h"
26 #include "kills.h"
27 #include "maybe-bool.h"
28 #include "mon-holy-type.h"
29 #include "mutation-type.h"
30 #include "place-info.h"
31 #include "quiver.h"
32 #include "religion-enum.h"
33 #include "skill-menu-state.h"
34 #include "species.h"
35 #include "stat-type.h"
36 #include "timed-effect-type.h"
37 #include "transformation.h"
38 #include "uncancellable-type.h"
39 #include "unique-creature-list-type.h"
40 #include "unique-item-status-type.h"
41 
42 #define ICY_ARMOUR_KEY "ozocubu's_armour_pow"
43 #define TRANSFORM_POW_KEY "transform_pow"
44 #define BARBS_MOVE_KEY "moved_with_barbs_status"
45 #define HORROR_PENALTY_KEY "horror_penalty"
46 #define POWERED_BY_DEATH_KEY "powered_by_death_strength"
47 #define WEREBLOOD_KEY "wereblood_bonus"
48 #define FORCE_MAPPABLE_KEY "force_mappable"
49 #define MANA_REGEN_AMULET_ACTIVE "mana_regen_amulet_active"
50 #define SAP_MAGIC_KEY "sap_magic_amount"
51 #define TEMP_WATERWALK_KEY "temp_waterwalk"
52 #define EMERGENCY_FLIGHT_KEY "emergency_flight"
53 #define PARALYSED_BY_KEY "paralysed_by"
54 #define PETRIFIED_BY_KEY "petrified_by"
55 #define FROZEN_RAMPARTS_KEY "frozen_ramparts_position"
56 #define PALENTONGA_CURL_KEY "palentonga_curl"
57 
58 // display/messaging breakpoints for penalties from Ru's MUT_HORROR
59 #define HORROR_LVL_EXTREME  3
60 #define HORROR_LVL_OVERWHELMING  5
61 
62 #define SEVERE_CONTAM_LEVEL 3
63 
64 /// Maximum stat value
65 static const int MAX_STAT_VALUE = 125;
66 /// The standard unit of regen; one level in artifact inscriptions
67 static const int REGEN_PIP = 100;
68 /// The standard unit of WL; one level in %/@ screens
69 static const int WL_PIP = 40;
70 /// The standard unit of stealth; one level in %/@ screens
71 static const int STEALTH_PIP = 50;
72 
73 /// The minimum aut cost for a player move (before haste)
74 static const int FASTEST_PLAYER_MOVE_SPEED = 6;
75 // relevant for swiftness, etc
76 
77 // Min delay for thrown projectiles.
78 static const int FASTEST_PLAYER_THROWING_SPEED = 7;
79 
80 class targeter;
81 class Delay;
82 
83 int player_stealth();
84 
85 enum class mutation_activity_type; // in mutation.h
86 
87 /// used for you.train[] & for rendering skill tiles (tileidx_skill)
88 enum training_status
89 {
90     TRAINING_DISABLED = 0,
91     TRAINING_ENABLED,
92     TRAINING_FOCUSED,
93     NUM_TRAINING_STATUSES,
94     // the below are only used for display purposes, not training.
95     TRAINING_MASTERED,
96     TRAINING_INACTIVE, ///< enabled but not used (in auto mode)
97 };
98 
99 // needed for assert in is_player()
100 #ifdef DEBUG_GLOBALS
101 #define you (*real_you)
102 #endif
103 extern player you;
104 
105 typedef FixedVector<int, NUM_DURATIONS> durations_t;
106 class player : public actor
107 {
108 public:
109     // ---------------
110     // Character save chunk data:
111     // None of this is really necessary, except for some complicated
112     // hacks with player_save_info. Should only be used in tags.cc or
113     // player_save_info::operator=(player).
114     // ---------------
115     string chr_species_name;
116     string chr_class_name;
117     string chr_god_name;
118 
119     // ---------------
120     // Permanent data:
121     // ---------------
122     string your_name;
123     species_type species;
124     job_type char_class;
125 
126     // This field is here even in non-WIZARD compiles, since the
127     // player might have been playing previously under wiz mode.
128     bool          wizard;            // true if player has entered wiz mode.
129     bool          explore;           // true if player has entered explore mode.
130     bool          suppress_wizard;
131     time_t        birth_time;        // start time of game
132 
133     // ----------------
134     // Long-term state:
135     // ----------------
136     int elapsed_time;        // total amount of elapsed time in the game
137     int elapsed_time_at_last_input; // used for elapsed_time delta display
138 
139     int hp;
140     int hp_max;
141     int hp_max_adj_temp;        // temporary max HP loss (draining)
142     int hp_max_adj_perm;        // base HPs from background (and permanent loss)
143 
144     int magic_points;
145     int max_magic_points;
146     int mp_max_adj;             // max MP loss (ability costs, tutorial bonus)
147 
148     FixedVector<int8_t, NUM_STATS> stat_loss;
149     FixedVector<int8_t, NUM_STATS> base_stats;
150 
151     uint8_t max_level;
152     int hit_points_regeneration;
153     int magic_points_regeneration;
154     unsigned int experience;
155     unsigned int total_experience; // 10 * amount of xp put into skills, used
156                                    // only for skill_cost_level
157     int experience_level;
158     int gold;
159     int zigs_completed, zig_max;
160 
161     FixedVector<int8_t, NUM_EQUIP> equip;
162     FixedBitVector<NUM_EQUIP> melded;
163     // Whether these are unrands that we should run the _*_world_reacts func for
164     FixedBitVector<NUM_EQUIP> unrand_reacts;
165     // True if the slot has an item that activates when worn with max hp (regen
166     // items, acrobat amulet) and max hp has been reached while wearing it;
167     // false otherwise.
168     FixedBitVector<NUM_EQUIP> activated;
169 
170     FixedArray<int, NUM_OBJECT_CLASSES, MAX_SUBTYPES> force_autopickup;
171 
172     // PC's symbol (usually @) and colour.
173     monster_type symbol;
174     transformation form;
175 
176     FixedVector< item_def, ENDOFPACK > inv;
177     FixedBitVector<NUM_RUNE_TYPES> runes;
178     int obtainable_runes; // can be != 15 in Sprint
179 
180     FixedBitVector<NUM_SPELLS> spell_library;
181     FixedBitVector<NUM_SPELLS> hidden_spells;
182     FixedVector<spell_type, MAX_KNOWN_SPELLS> spells;
183     set<spell_type> old_vehumet_gifts, vehumet_gifts;
184 
185     uint8_t spell_no;
186     game_chapter chapter;
187     bool royal_jelly_dead;
188     bool transform_uncancellable;
189     bool fishtail; // Merfolk fishtail transformation
190     bool vampire_alive;
191 
192     unsigned short pet_target;
193 
194     durations_t duration;
195     bool apply_berserk_penalty;         // Whether to apply the berserk penalty at
196     // end of the turn.
197     int berserk_penalty;                // The penalty for moving while berserk
198 
199     FixedVector<int, NUM_ATTRIBUTES> attribute;
200     FixedVector<uint8_t, quiver::NUM_LAUNCHERS> quiver; // default items for quiver
201     FixedVector<int, NUM_TIMERS> last_timer_effect;
202     FixedVector<int, NUM_TIMERS> next_timer_effect;
203 
204     bool pending_revival;
205     int lives;
206     int deaths;
207 
208     FixedVector<uint8_t, NUM_SKILLS> skills; ///< skill level
209     FixedVector<training_status, NUM_SKILLS> train; ///< see enum def
210     FixedVector<training_status, NUM_SKILLS> train_alt; ///< config of other mode
211     FixedVector<unsigned int, NUM_SKILLS>  training; ///< percentage of XP used
212     FixedBitVector<NUM_SKILLS> can_currently_train; ///< Is training this skill allowed?
213     FixedBitVector<NUM_SKILLS> should_show_skill; ///< Is this skill shown by default?
214     FixedVector<unsigned int, NUM_SKILLS> skill_points;
215     FixedVector<unsigned int, NUM_SKILLS> training_targets; ///< Training targets, scaled by 10 (so [0,270]).  0 means no target.
216     int experience_pool; ///< XP waiting to be applied.
217 
218     /// track skill points gained by crosstraining
219     FixedVector<unsigned int, NUM_SKILLS> ct_skill_points;
220     FixedVector<uint8_t, NUM_SKILLS>  skill_order;
221 
222     /// manuals
223     FixedVector<unsigned int, NUM_SKILLS>  skill_manual_points;
224 
225 
226     bool auto_training;
227     list<skill_type> exercises;     ///< recent practise events
228     list<skill_type> exercises_all; ///< also include events for disabled skills
229     set<skill_type> skills_to_hide;     ///< need to check if it should still be shown in the skill menu
230     set<skill_type> skills_to_show;    ///< we can un-hide in the skill menu
231 
232     // Skill menu states
233     skill_menu_state skill_menu_do;
234     skill_menu_state skill_menu_view;
235 
236     int  skill_cost_level;
237     int  exp_available; // xp pool, scaled by 10 from you.experience
238 
239     FixedVector<int, NUM_GODS> exp_docked;
240     FixedVector<int, NUM_GODS> exp_docked_total; // XP-based wrath
241 
242     FixedArray<uint32_t, 6, MAX_SUBTYPES> item_description;
243     FixedVector<unique_item_status_type, MAX_UNRANDARTS> unique_items;
244     unique_creature_list unique_creatures;
245 
246     KillMaster kills;
247 
248     branch_type where_are_you;
249     int depth;
250 
251     god_type religion;
252     string jiyva_second_name;       // Random second name of Jiyva
253     uint8_t piety;
254     uint8_t piety_hysteresis;       // amount of stored-up docking
255     uint8_t gift_timeout;
256     uint8_t saved_good_god_piety;   // for if you "switch" between E/Z/1 by abandoning one first
257     god_type previous_good_god;
258     FixedVector<uint8_t, NUM_GODS>  penance;
259     FixedVector<uint8_t, NUM_GODS>  worshipped;
260     FixedVector<short,   NUM_GODS>  num_current_gifts;
261     FixedVector<short,   NUM_GODS>  num_total_gifts;
262     FixedBitVector<      NUM_GODS>  one_time_ability_used;
263     FixedVector<uint8_t, NUM_GODS>  piety_max;
264 
265     FixedVector<uint8_t, NUM_MUTATIONS> mutation;
266     FixedVector<uint8_t, NUM_MUTATIONS> innate_mutation;
267     FixedVector<uint8_t, NUM_MUTATIONS> temp_mutation;
268     FixedVector<uint8_t, NUM_MUTATIONS> sacrifices;
269 
270     FixedVector<uint8_t, NUM_ABILITIES> sacrifice_piety;
271 
272     struct demon_trait
273     {
274         int           level_gained;
275         mutation_type mutation;
276     };
277 
278     vector<demon_trait> demonic_traits;
279 
280     int magic_contamination;
281 
282     FixedVector<uint32_t, NUM_WEAPONS> seen_weapon;
283     FixedVector<uint32_t, NUM_ARMOURS> seen_armour;
284     FixedBitVector<NUM_MISCELLANY>     seen_misc;
285     uint8_t                            octopus_king_rings;
286 
287     uint8_t normal_vision;        // how far the species gets to see
288     uint8_t current_vision;       // current sight radius (cells)
289 
real_time()290     int real_time() { return real_time_ms.count() / 1000; }
291     chrono::milliseconds real_time_ms;       // real time played
292     chrono::milliseconds real_time_delta;    // real time since last command
293 
294     int num_turns;            // number of turns taken
295     int exploration;          // levels explored (16.16 bit real number)
296 
297     int                       last_view_update;     // what turn was the view last updated?
298 
299     // Warning: these two are quite different.
300     //
301     // The spell table is an index to a specific spell slot (you.spells).
302     // The ability table lists the ability (ABIL_*) which prefers that letter.
303     //
304     // In other words, the spell table contains hard links and the ability
305     // table contains soft links.
306     FixedVector<int, 52>           spell_letter_table;   // ref to spell by slot
307     FixedVector<ability_type, 52>  ability_letter_table; // ref to abil by enum
308 
309     // Maps without allow_dup that have been already used.
310     set<string> uniq_map_tags;
311     set<string> uniq_map_names;
312     set<string> uniq_map_tags_abyss;
313     set<string> uniq_map_names_abyss;
314     // All maps, by level.
315     map<level_id, vector<string> > vault_list;
316 
317     PlaceInfo global_info;
318 
319     LevelXPInfo global_xp_info;
320 
321     quiver::ammo_history m_quiver_history;
322 
323     quiver::action_cycler quiver_action;
324     quiver::launcher_action_cycler launcher_action;
325 
326     // monsters mesmerising player; should be protected, but needs to be saved
327     // and restored.
328     vector<mid_t> beholders;
329 
330     // monsters causing fear to the player; see above
331     vector<mid_t> fearmongers;
332 
333     // Delayed level actions. This array is never trimmed, as usually D:1 won't
334     // be loaded again until the very end.
335     vector<daction_type> dactions;
336 
337     // Path back from portal levels.
338     vector<level_pos> level_stack;
339 
340     // The player's knowledge about item types.
341     id_arr type_ids;
342 
343     // The version the save was last played with.
344     string prev_save_version;
345 
346     // The biggest assigned monster id so far.
347     mid_t last_mid;
348 
349     // Count of various types of actions made.
350     map<pair<caction_type, int>, FixedVector<int, 27> > action_count;
351 
352     // Which branches have been noted to have been left during this game.
353     FixedBitVector<NUM_BRANCHES> branches_left;
354 
355     // For now, only control the speed of abyss morphing.
356     int abyss_speed;
357 
358     // Prompts or actions the player must answer before continuing.
359     // A stack -- back() is the first to go.
360     vector<pair<uncancellable_type, int> > uncancel;
361 
362     // A list of allies awaiting an active recall
363     vector<mid_t> recall_list;
364 
365     // Hash seed for deterministic stuff.
366     uint64_t game_seed;
367     bool fully_seeded; // true on all games started since 0.23 seeding changes
368     bool deterministic_levelgen; // true if a game was started with incremental
369                                  // or full pregen.
370 
371     // -------------------
372     // Non-saved UI state:
373     // -------------------
374     unsigned short prev_targ;
375     coord_def      prev_grd_targ;
376     // Examining spell library spells for Sif Muna's ability
377     bool           divine_exegesis;
378 
379     // Coordinates of last travel target; note that this is never used by
380     // travel itself, only by the level-map to remember the last travel target.
381     short travel_x, travel_y;
382     level_id travel_z;
383 
384     runrest running;                    // Nonzero if running/traveling.
385     bool travel_ally_pace;
386 
387     bool received_weapon_warning;
388     bool received_noskill_warning;
389     bool wizmode_teleported_into_rock;
390 
391     // This should really be unique_ptr, but that causes issues since files.cc
392     // uses the default constructor of `player`.
393     vector<shared_ptr<Delay>> delay_queue; // pending actions
394 
395     chrono::time_point<chrono::system_clock> last_keypress_time;
396 
397     bool wizard_vision;
398     map<skill_type, int8_t> skill_boost; // Skill bonuses.
399     bool digging;
400 
401     // The last spell cast by the player.
402     spell_type last_cast_spell;
403     map<int,int> last_pickup;
404     int last_unequip;
405 
406     // ---------------------------
407     // Volatile (same-turn) state:
408     // ---------------------------
409     bool turn_is_over; // player has performed a timed action
410 
411     // If true, player is headed to the Abyss.
412     bool banished;
413     string banished_by;
414     int banished_power;
415 
416     // If true, player has triggered a trap effect by exploring.
417     bool trapped;
418 
419     // Did the player trigger their spectral weapon this turn?
420     bool triggered_spectral;
421 
422     // TODO burn this API with fire
423     bool wield_change;          // redraw weapon
424     bool gear_change;           // redraw equip bar
425     bool redraw_quiver;         // redraw quiver
426     bool redraw_noise;
427 
428     bool redraw_title;
429     bool redraw_hit_points;
430     bool redraw_magic_points;
431     FixedVector<bool, NUM_STATS> redraw_stats;
432     bool redraw_experience;
433     bool redraw_armour_class;
434     bool redraw_evasion;
435     bool redraw_status_lights;
436 
437     colour_t flash_colour;
438     targeter *flash_where;
439 
440     int time_taken;
441 
442     // the loudest noise level the player has experienced in los this turn
443     int los_noise_level;
444     int los_noise_last_turn;
445 
446     // Set when the character is going to a new level, to guard against levgen
447     // failures
448     dungeon_feature_type transit_stair;
449     bool entering_level;
450 
451     int    escaped_death_cause;
452     string escaped_death_aux;
453 
454     int turn_damage;   // cumulative damage per turn
455     mid_t damage_source; // death source of last damage done to player
456     int source_damage; // cumulative damage for you.damage_source
457 
458     // When other levels are loaded (e.g. viewing), is the player on this level?
459     bool on_current_level;
460 
461     // View code clears and needs new data in places where we can't announce
462     // the portal right away; delay the announcements then.
463     int seen_portals;
464 
465     // Number of viewport refreshes.
466     unsigned int frame_no;
467 
468 
469     // ---------------------
470     // The save file itself.
471     // ---------------------
472     package *save;
473 
474 protected:
475     FixedVector<PlaceInfo, NUM_BRANCHES> branch_info;
476     map<level_id, LevelXPInfo> level_xp_info;
477 
478 public:
479     player();
480     virtual ~player();
481 
482     void init_skills();
483 
484     // Set player position without updating view geometry.
485     void set_position(const coord_def &c) override;
486     // Low-level move the player. Use this instead of changing pos directly.
487     void moveto(const coord_def &c, bool clear_net = true) override;
488     bool move_to_pos(const coord_def &c, bool clear_net = true,
489                      bool /*force*/ = false) override;
490     // Move the player during an abyss shift.
491     void shiftto(const coord_def &c);
492     bool blink_to(const coord_def& c, bool quiet = false) override;
493 
494     void set_level_visited(const level_id &level);
495     bool level_visited(const level_id &level);
496 
497     int stat(stat_type stat, bool nonneg = true) const;
498     int strength(bool nonneg = true) const;
499     int intel(bool nonneg = true) const;
500     int dex(bool nonneg = true) const;
501     int max_stat(stat_type stat, bool base = false) const;
502     int max_strength() const;
503     int max_intel() const;
504     int max_dex() const;
505 
506     bool in_water() const;
507     bool in_liquid() const;
508     bool can_swim(bool permanently = false) const;
509     bool can_water_walk() const;
510     int visible_igrd(const coord_def&) const;
511     bool is_banished() const override;
512     bool is_sufficiently_rested() const; // Up to rest_wait_percent HP and MP.
513     bool is_web_immune() const override;
514     bool cannot_speak() const;
515     bool invisible() const override;
516     bool can_see_invisible(bool calc_unid = true) const override;
517     bool innate_sinv() const;
518     bool visible_to(const actor *looker) const override;
519     bool can_see(const actor& a) const override;
520     undead_state_type undead_state(bool temp = true) const;
521     bool nightvision() const override;
522     reach_type reach_range() const override;
523     bool see_cell(const coord_def& p) const override;
524 
525     // Is c in view but behind a transparent wall?
526     bool trans_wall_blocking(const coord_def &c) const;
527 
528     bool is_icy() const override;
529     bool is_fiery() const override;
530     bool is_skeletal() const override;
531 
532     bool tengu_flight() const;
533     int heads() const override;
534 
535     bool spellcasting_unholy() const;
536 
537     // Dealing with beholders. Implemented in behold.cc.
538     void add_beholder(const monster& mon, bool axe = false);
539     bool beheld() const;
540     bool beheld_by(const monster& mon) const;
541     monster* get_beholder(const coord_def &pos) const;
542     monster* get_any_beholder() const;
543     void remove_beholder(const monster& mon);
544     void clear_beholders();
545     void update_beholders();
546     void update_beholder(const monster* mon);
547     bool possible_beholder(const monster* mon) const;
548 
549     // Dealing with fearmongers. Implemented in fearmonger.cc.
550     bool add_fearmonger(const monster* mon);
551     bool afraid() const;
552     bool afraid_of(const monster* mon) const;
553     monster* get_fearmonger(const coord_def &pos) const;
554     monster* get_any_fearmonger() const;
555     void remove_fearmonger(const monster* mon);
556     void clear_fearmongers();
557     void update_fearmongers();
558     void update_fearmonger(const monster* mon);
559 
560     bool made_nervous_by(const monster *mons);
561     bool is_nervous();
562 
563     kill_category kill_alignment() const override;
564 
565     bool has_spell(spell_type spell) const override;
566 
567     string shout_verb(bool directed = false) const;
568     int shout_volume() const;
569 
570     item_def *slot_item(equipment_type eq, bool include_melded=false) const
571         override;
572 
573     int base_ac_from(const item_def &armour, int scale = 1) const;
574 
575     int inaccuracy() const override;
576 
577     // actor
578     int mindex() const override;
579     int get_hit_dice() const override;
580     int get_experience_level() const override;
581     int get_max_xl() const;
is_player()582     bool is_player() const override
583     {
584 #ifndef DEBUG_GLOBALS
585         ASSERT(this == (actor*)&you); // there can be only one
586 #endif
587         return true;
588     }
as_monster()589     monster* as_monster() override { return nullptr; }
as_player()590     player* as_player() override { return this; }
as_monster()591     const monster* as_monster() const override { return nullptr; }
as_player()592     const player* as_player() const override { return this; }
593 
594     god_type  deity() const override;
595     bool      alive() const override;
596     bool      is_summoned(int* duration = nullptr,
597                           int* summon_type = nullptr) const override;
is_perm_summoned()598     bool      is_perm_summoned() const override { return false; };
599 
600     bool        swimming() const override;
601     bool        submerged() const override;
602     bool        floundering() const override;
603     bool        extra_balanced() const override;
604     bool        shove(const char* feat_name = "") override;
605     bool        can_pass_through_feat(dungeon_feature_type grid) const override;
606     bool        can_burrow() const override;
607     bool        is_habitable_feat(dungeon_feature_type actual_grid) const
608         override;
609     size_type   body_size(size_part_type psize = PSIZE_TORSO,
610                           bool base = false) const override;
611     brand_type  damage_brand(int which_attack = -1) override;
612     int         damage_type(int which_attack = -1) override;
613     random_var  attack_delay(const item_def *projectile = nullptr,
614                              bool rescale = true) const override;
615     int         constriction_damage(bool direct) const override;
constriction_does_damage(bool)616     bool        constriction_does_damage(bool /* direct */) const override
617                     { return true; };
618 
619     int       has_claws(bool allow_tran = true) const override;
620     bool      has_usable_claws(bool allow_tran = true) const;
621     int       has_talons(bool allow_tran = true) const;
622     bool      has_usable_talons(bool allow_tran = true) const;
623     int       has_hooves(bool allow_tran = true) const;
624     bool      has_usable_hooves(bool allow_tran = true) const;
625     int       has_fangs(bool allow_tran = true) const;
626     int       has_usable_fangs(bool allow_tran = true) const;
627     bool      has_tail(bool allow_tran = true) const;
628     bool      has_usable_offhand() const;
629     int       has_pseudopods(bool allow_tran = true) const;
630     int       has_usable_pseudopods(bool allow_tran = true) const;
631     int       has_tentacles(bool allow_tran = true) const;
632     int       has_usable_tentacles(bool allow_tran = true) const;
633 
634     // Information about player mutations. Implemented in mutation.cc
635     int       get_base_mutation_level(mutation_type mut, bool innate=true, bool temp=true, bool normal=true) const;
636     int       get_mutation_level(mutation_type mut, bool check_form=true) const;
637     int       get_mutation_level(mutation_type mut, mutation_activity_type minact) const;
638     int       get_innate_mutation_level(mutation_type mut) const;
639     int       get_temp_mutation_level(mutation_type mut) const;
640 
641     int       get_training_target(const skill_type sk) const;
642     bool      set_training_target(const skill_type sk, const double target, bool announce=false);
643     bool      set_training_target(const skill_type sk, const int target, bool announce=false);
644     void      clear_training_targets();
645 
646     bool      has_temporary_mutation(mutation_type mut) const;
647     bool      has_innate_mutation(mutation_type mut) const;
648     bool      has_mutation(mutation_type mut, bool check_form=true) const;
649 
650     int       how_mutated(bool innate=false, bool levels=false, bool temp=true) const;
651 
652     int wearing(equipment_type slot, int sub_type, bool calc_unid = true) const
653         override;
654     int wearing_ego(equipment_type slot, int type, bool calc_unid = true) const
655         override;
656     int scan_artefacts(artefact_prop_type which_property,
657                        bool calc_unid = true,
658                        vector<const item_def *> *matches = nullptr) const override;
659 
660     item_def *weapon(int which_attack = -1) const override;
661     item_def *shield() const override;
662 
663     hands_reqd_type hands_reqd(const item_def &item,
664                                bool base = false) const override;
665 
666     bool      can_wield(const item_def &item,
667                         bool ignore_curse = false,
668                         bool ignore_brand = false,
669                         bool ignore_shield = false,
670                         bool ignore_transform = false) const override;
671     bool      could_wield(const item_def &item,
672                           bool ignore_brand = false,
673                           bool ignore_transform = false,
674                           bool quiet = true) const override;
675 
676     bool wear_barding() const;
677 
678     string name(description_level_type type, bool force_visible = false,
679                 bool force_article = false) const override;
680     string pronoun(pronoun_type pro, bool force_visible = false) const override;
681     string conj_verb(const string &verb) const override;
682     string base_hand_name(bool plural, bool temp, bool *can_plural=nullptr) const;
683     string hand_name(bool plural, bool *can_plural = nullptr) const override;
684     string hands_verb(const string &plural_verb) const;
685     string hands_act(const string &plural_verb, const string &object) const;
686     string foot_name(bool plural, bool *can_plural = nullptr) const override;
687     string arm_name(bool plural, bool *can_plural = nullptr) const override;
688     int arm_count() const;
689     string unarmed_attack_name() const;
690 
691     bool fumbles_attack() override;
692     bool fights_well_unarmed(int heavy_armour_penalty) override;
693 
694     void attacking(actor *other, bool ranged = false) override;
695     bool can_go_berserk() const override;
696     bool can_go_berserk(bool intentional, bool potion = false,
697                         bool quiet = false, string *reason = nullptr,
698                         bool temp = true) const;
699     bool go_berserk(bool intentional, bool potion = false) override;
700     bool berserk() const override;
701     bool can_mutate() const override;
702     bool can_safely_mutate(bool temp = true) const override;
703     bool is_lifeless_undead(bool temp = true) const;
704     bool can_polymorph() const override;
705     bool can_bleed(bool allow_tran = true) const override;
706     bool can_drink(bool temp = true) const;
707     bool is_stationary() const override;
708     bool malmutate(const string &reason) override;
709     bool polymorph(int pow, bool allow_immobile = true) override;
710     void backlight();
711     void banish(const actor* /*agent*/, const string &who = "", const int power = 0,
712                 bool force = false) override;
713     void blink() override;
714     void teleport(bool right_now = false,
715                   bool wizard_tele = false) override;
716     void drain_stat(stat_type stat, int amount) override;
717 
718     void expose_to_element(beam_type element, int strength = 0,
719                            bool slow_cold_blood = true) override;
720     void god_conduct(conduct_type thing_done, int level) override;
721 
722     bool poison(actor *agent, int amount = 1, bool force = false) override;
723     bool sicken(int amount) override;
724     void paralyse(const actor *, int str, string source = "") override;
725     void petrify(const actor *, bool force = false) override;
726     bool fully_petrify(bool quiet = false) override;
727     void slow_down(actor *, int str) override;
728     void confuse(actor *, int strength) override;
729     void weaken(actor *attacker, int pow) override;
730     bool heal(int amount) override;
731     bool drain(const actor *, bool quiet = false, int pow = 3) override;
732     void splash_with_acid(const actor* evildoer, int acid_strength,
733                           bool allow_corrosion = true,
734                           const char* hurt_msg = nullptr) override;
735     bool corrode_equipment(const char* corrosion_source = "the acid",
736                            int degree = 1) override;
737     void sentinel_mark(bool trap = false);
738     int hurt(const actor *attacker, int amount,
739              beam_type flavour = BEAM_MISSILE,
740              kill_method_type kill_type = KILLED_BY_MONSTER,
741              string source = "",
742              string aux = "",
743              bool cleanup_dead = true,
744              bool attacker_effects = true) override;
745 
wont_attack()746     bool wont_attack() const override { return true; };
temp_attitude()747     mon_attitude_type temp_attitude() const override { return ATT_FRIENDLY; };
real_attitude()748     mon_attitude_type real_attitude() const override { return ATT_FRIENDLY; };
749 
750     monster_type mons_species(bool zombie_base = false) const override;
751 
752     mon_holy_type holiness(bool temp = true) const override;
753     bool undead_or_demonic(bool temp = true) const override;
754     bool is_holy() const override;
755     bool is_nonliving(bool temp = true) const override;
756     int how_chaotic(bool check_spells_god) const override;
757     bool is_unbreathing() const override;
758     bool is_insubstantial() const override;
759     int res_acid(bool calc_unid = true) const override;
res_damnation()760     bool res_damnation() const override { return false; };
761     int res_fire() const override;
762     int res_steam() const override;
763     int res_cold() const override;
764     int res_elec() const override;
765     int res_poison(bool temp = true) const override;
766     bool res_miasma(bool temp = true) const override;
767     int res_water_drowning() const override;
768     bool res_sticky_flame() const override;
769     int res_holy_energy() const override;
770     int res_negative_energy(bool intrinsic_only = false) const override;
771     bool res_torment() const override;
772     bool res_polar_vortex() const override;
773     bool res_petrify(bool temp = true) const override;
774     int res_constrict() const override;
775     int willpower(bool /*calc_unid*/ = true) const override;
776     bool no_tele(bool calc_unid = true, bool /*permit_id*/ = true,
777                  bool blink = false) const override;
778     string no_tele_reason(bool calc_unid = true, bool blink = false) const;
779     bool no_tele_print_reason(bool calc_unid = true, bool blink = false) const;
780     bool antimagic_susceptible() const override;
781 
782     bool res_corr(bool calc_unid = true, bool temp = true) const override;
783     bool clarity(bool calc_unid = true, bool items = true) const override;
784     bool stasis() const override;
785     bool cloud_immune(bool calc_unid = true, bool items = true) const override;
786 
787     bool airborne() const override;
788     bool permanent_flight(bool include_equip = true) const;
789     bool racial_permanent_flight() const;
790     int get_noise_perception(bool adjusted = true) const;
791     bool is_dragonkind() const override;
792 
793     bool paralysed() const override;
794     bool cannot_move() const override;
795     bool cannot_act() const override;
796     bool confused() const override;
797     bool caught() const override;
798     bool backlit(bool self_halo = true) const override;
799     bool umbra() const override;
800     int halo_radius() const override;
801     int silence_radius() const override;
802     int demon_silence_radius() const override;
803     int liquefying_radius() const override;
804     int umbra_radius() const override;
805     bool petrifying() const override;
806     bool petrified() const override;
807     bool liquefied_ground() const override;
incapacitated()808     bool incapacitated() const override
809     {
810         return actor::incapacitated() || duration[DUR_CLUMSY];
811     }
812     bool immune_to_hex(const spell_type hex) const;
813 
814     bool asleep() const override;
815     void put_to_sleep(actor *, int power = 0, bool hibernate = false) override;
816     void awaken();
817     void check_awaken(int disturbance) override;
818     int beam_resists(bolt &beam, int hurted, bool doEffects, string source)
819         override;
820     bool can_feel_fear(bool include_unknown) const override;
821 
822     bool can_throw_large_rocks() const override;
823     bool can_smell() const;
824     bool can_sleep(bool holi_only = false) const override;
825 
826     int racial_ac(bool temp) const;
827     int base_ac(int scale) const;
828     int armour_class(bool /*calc_unid*/ = true) const override;
829     int gdr_perc() const override;
830     int evasion(ev_ignore_type evit = ev_ignore::none,
831                 const actor *attacker = nullptr) const override;
832 
stat_hp()833     int stat_hp() const override     { return hp; }
stat_maxhp()834     int stat_maxhp() const override  { return hp_max; }
stealth()835     int stealth() const override     { return player_stealth(); }
836 
837     bool shielded() const override;
838     int shield_bonus() const override;
839     int shield_block_penalty() const override;
840     int shield_bypass_ability(int tohit) const override;
841     void shield_block_succeeded() override;
842     bool missile_repulsion() const override;
843 
844     // Combat-related adjusted penalty calculation methods
845     int unadjusted_body_armour_penalty() const override;
846     int adjusted_body_armour_penalty(int scale = 1) const override;
847     int adjusted_shield_penalty(int scale = 1) const override;
848     float get_shield_skill_to_offset_penalty(const item_def &item);
849     int armour_tohit_penalty(bool random_factor, int scale = 1) const override;
850     int shield_tohit_penalty(bool random_factor, int scale = 1) const override;
851 
852     bool wearing_light_armour(bool with_skill = false) const;
853     int  skill(skill_type skill, int scale = 1, bool real = false,
854                bool temp = true) const override;
855 
856     bool do_shaft() override;
857 
858     bool can_do_shaft_ability(bool quiet = false) const;
859     bool do_shaft_ability();
860 
861     bool can_potion_heal();
862     int scale_potion_healing(int healing_amount);
863 
864     void apply_location_effects(const coord_def &oldpos,
865                                 killer_type killer = KILL_NONE,
866                                 int killernum = -1) override;
867 
868     void be_agile(int pow);
869 
870     ////////////////////////////////////////////////////////////////
871 
872     PlaceInfo& get_place_info() const ; // Current place info
873     PlaceInfo& get_place_info(branch_type branch) const;
874     void clear_place_info();
875 
876     LevelXPInfo& get_level_xp_info();
877     LevelXPInfo& get_level_xp_info(const level_id &lev);
878 
879     void goto_place(const level_id &level);
880 
881     void set_place_info(PlaceInfo info);
882     // Returns copies of the PlaceInfo; modifying the vector won't
883     // modify the player object.
884     vector<PlaceInfo> get_all_place_info(bool visited_only = false,
885                                          bool dungeon_only = false) const;
886 
887     void set_level_xp_info(LevelXPInfo &xp_info);
888     vector<LevelXPInfo> get_all_xp_info(bool must_have_kills = false) const;
889 
890     bool did_escape_death() const;
891     void reset_escaped_death();
892 
893     void add_gold(int delta);
894     void del_gold(int delta);
895     void set_gold(int amount);
896 
897     void increase_duration(duration_type dur, int turns, int cap = 0,
898                            const char* msg = nullptr);
899     void set_duration(duration_type dur, int turns, int cap = 0,
900                       const char *msg = nullptr);
901 
902     bool attempt_escape(int attempts = 1);
903     int usable_tentacles() const;
904     bool has_usable_tentacle() const override;
905 
906     bool form_uses_xl() const;
907 
908     bool clear_far_engulf(bool force = false) override;
909 
910     int armour_class_with_one_sub(item_def sub) const;
911 
912     int armour_class_with_one_removal(item_def sub) const;
913 
914     int ac_changes_from_mutations() const;
915     vector<const item_def *> get_armour_items() const;
916     vector<const item_def *> get_armour_items_one_sub(const item_def& sub) const;
917     vector<const item_def *> get_armour_items_one_removal(const item_def& sub) const;
918     int base_ac_with_specific_items(int scale,
919                                     vector<const item_def *> armour_items) const;
920     int armour_class_with_specific_items(
921                                 vector<const item_def *> items) const;
922 
923 protected:
924     void _removed_beholder(bool quiet = false);
925     bool _possible_beholder(const monster* mon) const;
926 
927     void _removed_fearmonger(bool quiet = false);
928     bool _possible_fearmonger(const monster* mon) const;
929 
930 };
931 COMPILE_CHECK((int) SP_UNKNOWN_BRAND < 8*sizeof(you.seen_weapon[0]));
932 COMPILE_CHECK((int) SP_UNKNOWN_BRAND < 8*sizeof(you.seen_armour[0]));
933 
934 class monster;
935 struct item_def;
936 
937 // Helper. Use move_player_to_grid or player::apply_location_effects instead.
938 void moveto_location_effects(dungeon_feature_type old_feat,
939                              bool stepped=false, const coord_def& old_pos=coord_def());
940 
941 bool check_moveto(const coord_def& p, const string &move_verb = "step",
942                   bool physically = true);
943 bool check_moveto_terrain(const coord_def& p, const string &move_verb,
944                           const string &msg = "", bool *prompted = nullptr);
945 bool check_moveto_cloud(const coord_def& p, const string &move_verb = "step",
946                         bool *prompted = nullptr);
947 bool check_moveto_exclusions(const vector<coord_def> &areas,
948                              const string &move_verb = "step",
949                              bool *prompted = nullptr);
950 bool check_moveto_exclusion(const coord_def& p,
951                             const string &move_verb = "step",
952                             bool *prompted = nullptr);
953 bool check_moveto_trap(const coord_def& p, const string &move_verb = "step",
954         bool *prompted = nullptr);
955 
956 bool swap_check(monster* mons, coord_def &loc, bool quiet = false);
957 
958 void move_player_to_grid(const coord_def& p, bool stepped);
959 
960 bool is_map_persistent();
961 bool player_in_connected_branch();
962 bool player_in_hell(bool vestibule=false);
963 bool player_in_starting_abyss();
964 
player_in_branch(int branch)965 static inline bool player_in_branch(int branch)
966 {
967     return you.where_are_you == branch;
968 }
969 
970 bool berserk_check_wielded_weapon();
971 bool player_equip_unrand(int unrand_index, bool include_melded = false);
972 bool player_can_hear(const coord_def& p, int hear_distance = 999);
973 
974 bool player_is_shapechanged();
975 
976 void update_acrobat_status();
977 
978 bool is_effectively_light_armour(const item_def *item);
979 bool player_effectively_in_light_armour();
980 
981 int player_shield_racial_factor();
982 int player_armour_shield_spell_penalty();
983 
984 int player_movement_speed();
985 
986 int player_icemail_armour_class();
987 int player_condensation_shield_class();
988 int sanguine_armour_bonus();
989 
990 int player_wizardry(spell_type spell);
991 
992 int player_prot_life(bool calc_unid = true, bool temp = true,
993                      bool items = true);
994 
995 bool regeneration_is_inhibited();
996 int player_regen();
997 int player_mp_regen();
998 
999 int player_res_cold(bool calc_unid = true, bool temp = true,
1000                     bool items = true);
1001 int player_res_acid(bool calc_unid = true, bool items = true);
1002 
1003 bool player_kiku_res_torment();
1004 
1005 bool player_likes_water(bool permanently = false);
1006 
1007 int player_res_electricity(bool calc_unid = true, bool temp = true,
1008                            bool items = true);
1009 
1010 int player_res_fire(bool calc_unid = true, bool temp = true,
1011                     bool items = true);
1012 int player_res_sticky_flame();
1013 int player_res_steam(bool calc_unid = true, bool temp = true,
1014                      bool items = true);
1015 
1016 int player_res_poison(bool calc_unid = true, bool temp = true,
1017                       bool items = true);
1018 int player_willpower(bool calc_unid = true, bool temp = true);
1019 
1020 int player_shield_class();
1021 int player_displayed_shield_class();
1022 bool player_omnireflects();
1023 
1024 int player_spec_air();
1025 int player_spec_cold();
1026 int player_spec_conj();
1027 int player_spec_death();
1028 int player_spec_earth();
1029 int player_spec_fire();
1030 int player_spec_hex();
1031 int player_spec_poison();
1032 int player_spec_summ();
1033 
1034 int player_adjust_evoc_power(const int power, int enhancers = 0);
1035 
1036 int player_speed();
1037 
1038 int player_spell_levels();
1039 int player_total_spell_levels();
1040 
1041 int player_teleport(bool calc_unid = true);
1042 
1043 int player_monster_detect_radius();
1044 
1045 int slaying_bonus(bool ranged = false);
1046 
1047 unsigned int exp_needed(int lev, int exp_apt = -99);
1048 bool will_gain_life(int lev);
1049 
1050 bool dur_expiring(duration_type dur);
1051 void display_char_status();
1052 
1053 void forget_map(bool rot = false);
1054 
1055 int get_exp_progress();
1056 unsigned int gain_exp(unsigned int exp_gained);
1057 void apply_exp();
1058 
1059 int xp_to_level_diff(int xp, int scale=1);
1060 
1061 void level_change(bool skip_attribute_increase = false);
1062 void adjust_level(int diff, bool just_xp = false);
1063 
1064 bool is_player_same_genus(const monster_type mon);
1065 monster_type player_mons(bool transform = true);
1066 void update_player_symbol();
1067 void update_vision_range();
1068 
1069 maybe_bool you_can_wear(equipment_type eq, bool temp = false);
1070 bool player_has_feet(bool temp = true, bool include_mutations = true);
1071 
1072 bool enough_hp(int minimum, bool suppress_msg, bool abort_macros = true);
1073 bool enough_mp(int minimum, bool suppress_msg, bool abort_macros = true);
1074 
1075 void calc_hp(bool scale = false, bool set = false);
1076 void calc_mp(bool scale = false);
1077 
1078 void dec_hp(int hp_loss, bool fatal, const char *aux = nullptr);
1079 void drain_mp(int mp_loss);
1080 void pay_hp(int cost);
1081 void pay_mp(int cost);
1082 
1083 void inc_mp(int mp_gain, bool silent = false);
1084 void inc_hp(int hp_gain, bool silent = false);
1085 void refund_mp(int cost);
1086 void refund_hp(int cost);
1087 void flush_mp();
1088 void flush_hp();
1089 void finalize_mp_cost(bool addl_hp_cost = false);
1090 
1091 void drain_hp(int hp_loss);
1092 // Undrain the player's HP and return excess HP if any.
1093 int undrain_hp(int hp_recovered);
1094 int player_drained();
1095 void rot_mp(int mp_loss);
1096 
1097 void inc_max_hp(int hp_gain);
1098 void dec_max_hp(int hp_loss);
1099 
1100 void set_hp(int new_amount);
1101 
1102 int get_real_hp(bool trans, bool drained = true);
1103 int get_real_mp(bool include_items);
1104 
1105 int get_contamination_level();
1106 bool player_severe_contamination();
1107 string describe_contamination(int level);
1108 
1109 bool sanguine_armour_valid();
1110 void activate_sanguine_armour();
1111 
1112 void refresh_weapon_protection();
1113 
1114 void set_mp(int new_amount);
1115 
1116 bool player_regenerates_hp();
1117 bool player_regenerates_mp();
1118 
1119 void print_potion_heal_message();
1120 
1121 void contaminate_player(int change, bool controlled = false, bool msg = true);
1122 
1123 bool confuse_player(int amount, bool quiet = false, bool force = false);
1124 
1125 bool poison_player(int amount, string source, string source_aux = "",
1126                    bool force = false);
1127 void paralyse_player(string source, int amount = 0);
1128 void handle_player_poison(int delay);
1129 void reduce_player_poison(int amount);
1130 int get_player_poisoning();
1131 bool poison_is_lethal();
1132 int poison_survival();
1133 
1134 bool miasma_player(actor *who, string source_aux = "");
1135 
1136 bool napalm_player(int amount, string source, string source_aux = "");
1137 void dec_napalm_player(int delay);
1138 
1139 bool spell_slow_player(int pow);
1140 bool slow_player(int turns);
1141 void dec_slow_player(int delay);
1142 void dec_berserk_recovery_player(int delay);
1143 
1144 bool haste_player(int turns, bool rageext = false);
1145 void dec_haste_player(int delay);
1146 void dec_elixir_player(int delay);
1147 void dec_ambrosia_player(int delay);
1148 void dec_channel_player(int delay);
1149 void dec_frozen_ramparts(int delay);
1150 bool invis_allowed(bool quiet = false, string *fail_reason = nullptr);
1151 bool flight_allowed(bool quiet = false, string *fail_reason = nullptr);
1152 void fly_player(int pow, bool already_flying = false);
1153 void float_player();
1154 bool land_player(bool quiet = false);
1155 void player_open_door(coord_def doorpos);
1156 void player_close_door(coord_def doorpos);
1157 
1158 void player_end_berserk();
1159 
1160 void handle_player_drowning(int delay);
1161 
1162 // Determines if the given grid is dangerous for the player to enter.
1163 bool is_feat_dangerous(dungeon_feature_type feat, bool permanently = false,
1164                        bool ignore_flight = false);
1165 void enable_emergency_flight();
1166 
1167 int count_worn_ego(int which_ego);
1168 bool need_expiration_warning(duration_type dur, dungeon_feature_type feat);
1169 bool need_expiration_warning(dungeon_feature_type feat);
1170 bool need_expiration_warning(duration_type dur, coord_def p = you.pos());
1171 bool need_expiration_warning(coord_def p = you.pos());
1172 
1173 bool player_has_orb();
1174 bool player_on_orb_run();
1175