1 #pragma once
2 #ifndef CATA_SRC_AVATAR_H
3 #define CATA_SRC_AVATAR_H
4 
5 #include <cstddef>
6 #include <iosfwd>
7 #include <list>
8 #include <map>
9 #include <memory>
10 #include <string>
11 #include <unordered_set>
12 #include <vector>
13 
14 #include "calendar.h"
15 #include "character.h"
16 #include "coordinates.h"
17 #include "enums.h"
18 #include "game_constants.h"
19 #include "json.h"
20 #include "magic_teleporter_list.h"
21 #include "map_memory.h"
22 #include "memory_fast.h"
23 #include "player.h"
24 #include "point.h"
25 #include "type_id.h"
26 
27 class advanced_inv_area;
28 class advanced_inv_listitem;
29 class advanced_inventory_pane;
30 class faction;
31 class item;
32 class item_location;
33 class mission;
34 class monster;
35 class nc_color;
36 class npc;
37 class talker;
38 struct bionic;
39 
40 namespace catacurses
41 {
42 class window;
43 } // namespace catacurses
44 enum class character_type : int;
45 
46 namespace debug_menu
47 {
48 class mission_debug;
49 }  // namespace debug_menu
50 struct mtype;
51 struct points_left;
52 
53 // Monster visible in different directions (safe mode & compass)
54 struct monster_visible_info {
55     // New monsters visible from last update
56     std::vector<shared_ptr_fast<monster>> new_seen_mon;
57 
58     // Unique monsters (and types of monsters) visible in different directions
59     // 7 0 1    unique_types uses these indices;
60     // 6 8 2    0-7 are provide by direction_from()
61     // 5 4 3    8 is used for local monsters (for when we explain them below)
62     std::vector<npc *> unique_types[9];
63     std::vector<const mtype *> unique_mons[9];
64 
65     // If the monster visible in this direction is dangerous
66     bool dangerous[8] = {};
67 };
68 
69 class avatar : public player
70 {
71     public:
72         avatar();
73 
74         void store( JsonOut &json ) const;
75         void load( const JsonObject &data );
76         void serialize( JsonOut &json ) const override;
77         void deserialize( JsonIn &jsin ) override;
78         void serialize_map_memory( JsonOut &jsout ) const;
79         void deserialize_map_memory( JsonIn &jsin );
80 
81         // newcharacter.cpp
82         bool create( character_type type, const std::string &tempname = "" );
83         void add_profession_items();
84         void randomize( bool random_scenario, points_left &points, bool play_now = false );
85         bool load_template( const std::string &template_name, points_left &points );
86         void save_template( const std::string &name, const points_left &points );
87 
is_avatar()88         bool is_avatar() const override {
89             return true;
90         }
as_avatar()91         avatar *as_avatar() override {
92             return this;
93         }
as_avatar()94         const avatar *as_avatar() const override {
95             return this;
96         }
97 
98         void toggle_map_memory();
99         bool should_show_map_memory();
100         /** Memorizes a given tile in tiles mode; finalize_tile_memory needs to be called after it */
101         void memorize_tile( const tripoint &pos, const std::string &ter, int subtile,
102                             int rotation );
103         /** Returns last stored map tile in given location in tiles mode */
104         memorized_terrain_tile get_memorized_tile( const tripoint &p ) const;
105         /** Memorizes a given tile in curses mode; finalize_terrain_memory_curses needs to be called after it */
106         void memorize_symbol( const tripoint &pos, int symbol );
107         /** Returns last stored map tile in given location in curses mode */
108         int get_memorized_symbol( const tripoint &p ) const;
109         /** Returns the amount of tiles survivor can remember. */
110         size_t max_memorized_tiles() const;
111         void clear_memorized_tile( const tripoint &pos );
112 
113         nc_color basic_symbol_color() const override;
114         int print_info( const catacurses::window &w, int vStart, int vLines, int column ) const override;
115 
116         /** Provides the window and detailed morale data */
117         void disp_morale();
118         /** Uses morale and other factors to return the player's focus target goto value */
119         int calc_focus_equilibrium( bool ignore_pain = false ) const;
120         /** Calculates actual focus gain/loss value from focus equilibrium*/
121         int calc_focus_change() const;
122         /** Uses calc_focus_change to update the player's current focus */
123         void update_mental_focus();
124         /** Resets stats, and applies effects in an idempotent manner */
125         void reset_stats() override;
126         /** Resets all missions before saving character to template */
127         void reset_all_missions();
128 
129         std::vector<mission *> get_active_missions() const;
130         std::vector<mission *> get_completed_missions() const;
131         std::vector<mission *> get_failed_missions() const;
132         /**
133          * Returns the mission that is currently active. Returns null if mission is active.
134          */
135         mission *get_active_mission() const;
136         /**
137          * Returns the target of the active mission or @ref overmap::invalid_tripoint if there is
138          * no active mission.
139          */
140         tripoint_abs_omt get_active_mission_target() const;
141         /**
142          * Set which mission is active. The mission must be listed in @ref active_missions.
143          */
144         void set_active_mission( mission &cur_mission );
145         /**
146          * Called when a mission has been assigned to the player.
147          */
148         void on_mission_assignment( mission &new_mission );
149         /**
150          * Called when a mission has been completed or failed. Either way it's finished.
151          * Check @ref mission::has_failed to see which case it is.
152          */
153         void on_mission_finished( mission &cur_mission );
154 
155         // Dialogue and bartering--see npctalk.cpp
156         void talk_to( std::unique_ptr<talker> talk_with, bool text_only = false,
157                       bool radio_contact = false );
158 
159         /**
160          * Try to disarm the NPC. May result in fail attempt, you receiving the weapon and instantly wielding it,
161          * or the weapon falling down on the floor nearby. NPC is always getting angry with you.
162          * @param target Target NPC to disarm
163          */
164         void disarm( npc &target );
165 
166         /**
167          * Helper function for player::read.
168          *
169          * @param book Book to read
170          * @param reasons Starting with g->u, for each player/NPC who cannot read, a message will be pushed back here.
171          * @returns nullptr, if neither the player nor his followers can read to the player, otherwise the player/NPC
172          * who can read and can read the fastest
173          */
174         const player *get_book_reader( const item &book, std::vector<std::string> &reasons ) const;
175         /**
176          * Helper function for get_book_reader
177          * @warning This function assumes that the everyone is able to read
178          *
179          * @param book The book being read
180          * @param reader the player/NPC who's reading to the caller
181          * @param learner if not nullptr, assume that the caller and reader read at a pace that isn't too fast for him
182          */
183         int time_to_read( const item &book, const player &reader, const player *learner = nullptr ) const;
184         /** Handles reading effects and returns true if activity started */
185         bool read( item &it, bool continuous = false );
186         /** Completes book reading action. **/
187         void do_read( item &book );
188         /** Note that we've read a book at least once. **/
189         bool has_identified( const itype_id &item_id ) const override;
190         void identify( const item &item ) override;
191         void clear_identified();
192 
193         void wake_up();
194         // Grab furniture / vehicle
195         void grab( object_type grab_type, const tripoint &grab_point = tripoint_zero );
196         object_type get_grab_type() const;
197         /** Handles player vomiting effects */
198         void vomit();
199         void add_pain_msg( int val, const bodypart_id &bp ) const;
200         /**
201          * Try to steal an item from the NPC's inventory. May result in fail attempt, when NPC not notices you,
202          * notices your steal attempt and getting angry with you, and you successfully stealing the item.
203          * @param target Target NPC to steal from
204          */
205         void steal( npc &target );
206 
207         teleporter_list translocators;
208 
209         int get_str_base() const override;
210         int get_dex_base() const override;
211         int get_int_base() const override;
212         int get_per_base() const override;
213 
214         void upgrade_stat_prompt( const character_stat &stat_name );
215         // how many points are available to upgrade via STK
216         int free_upgrade_points() const;
217         // how much "kill xp" you have
218         int kill_xp() const;
219         void power_bionics() override;
220         void power_mutations() override;
221         /** Returns the bionic with the given invlet, or NULL if no bionic has that invlet */
222         bionic *bionic_by_invlet( int ch );
223 
224         faction *get_faction() const override;
225         // Set in npc::talk_to_you for use in further NPC interactions
226         bool dialogue_by_radio = false;
227         // Preferred aim mode - ranged.cpp aim mode defaults to this if possible
228         std::string preferred_aiming_mode;
229 
230         void set_movement_mode( const move_mode_id &mode ) override;
231 
232         // Cycles to the next move mode.
233         void cycle_move_mode();
234         // Resets to walking.
235         void reset_move_mode();
236         // Toggles running on/off.
237         void toggle_run_mode();
238         // Toggles crouching on/off.
239         void toggle_crouch_mode();
240 
241         bool wield( item_location target );
242         bool wield( item &target ) override;
243         bool wield( item &target, int obtain_cost );
244 
245         /** gets the inventory from the avatar that is interactible via advanced inventory management */
246         std::vector<advanced_inv_listitem> get_AIM_inventory( const advanced_inventory_pane &pane,
247                 advanced_inv_area &square );
248 
249         using Character::invoke_item;
250         bool invoke_item( item *, const tripoint &pt, int pre_obtain_moves ) override;
251         bool invoke_item( item * ) override;
252         bool invoke_item( item *, const std::string &, const tripoint &pt,
253                           int pre_obtain_moves = -1 ) override;
254         bool invoke_item( item *, const std::string & ) override;
255 
get_mon_visible()256         monster_visible_info &get_mon_visible() {
257             return mon_visible;
258         }
259 
260         struct daily_calories {
261             int spent = 0;
262             int gained = 0;
totaldaily_calories263             int total() const {
264                 return gained - spent;
265             }
266             std::map<float, int> activity_levels;
267 
serializedaily_calories268             void serialize( JsonOut &json ) const {
269                 json.start_object();
270 
271                 json.member( "spent", spent );
272                 json.member( "gained", gained );
273                 save_activity( json );
274 
275                 json.end_object();
276             }
deserializedaily_calories277             void deserialize( JsonIn &jsin ) {
278                 JsonObject data = jsin.get_object();
279 
280                 data.read( "spent", spent );
281                 data.read( "gained", gained );
282                 if( data.has_member( "activity" ) ) {
283                     read_activity( data );
284                 }
285             }
286 
daily_caloriesdaily_calories287             daily_calories() {
288                 activity_levels.emplace( NO_EXERCISE, 0 );
289                 activity_levels.emplace( LIGHT_EXERCISE, 0 );
290                 activity_levels.emplace( MODERATE_EXERCISE, 0 );
291                 activity_levels.emplace( BRISK_EXERCISE, 0 );
292                 activity_levels.emplace( ACTIVE_EXERCISE, 0 );
293                 activity_levels.emplace( EXTRA_EXERCISE, 0 );
294             }
295 
296             void save_activity( JsonOut &json ) const;
297             void read_activity( JsonObject &data );
298 
299         };
300         // called once a day; adds a new daily_calories to the
301         // front of the list and pops off the back if there are more than 30
302         void advance_daily_calories();
303         void add_spent_calories( int cal ) override;
304         void add_gained_calories( int cal ) override;
305         void log_activity_level( float level ) override;
306         std::string total_daily_calories_string() const;
307 
308     private:
309         map_memory player_map_memory;
310         bool show_map_memory;
311         /** Used in max_memorized_tiles to cache memory capacity. **/
312         mutable time_point current_map_memory_turn = calendar::before_time_starts;
313         mutable size_t current_map_memory_capacity = 0;
314 
315         friend class debug_menu::mission_debug;
316         /**
317          * Missions that the player has accepted and that are not finished (one
318          * way or the other).
319          */
320         std::vector<mission *> active_missions;
321         /**
322          * Missions that the player has successfully completed.
323          */
324         std::vector<mission *> completed_missions;
325         /**
326          * Missions that have failed while being assigned to the player.
327          */
328         std::vector<mission *> failed_missions;
329         /**
330          * The currently active mission, or null if no mission is currently in progress.
331          */
332         mission *active_mission;
333         /**
334          * The amount of calories spent and gained per day for the last 30 days.
335          * the back is popped off and a new one added to the front at midnight each day
336          */
337         std::list<daily_calories> calorie_diary;
338 
339         // Items the player has identified.
340         std::unordered_set<itype_id> items_identified;
341 
342         object_type grab_type;
343 
344         // these are the stat upgrades from stats through kills
345 
346         int str_upgrade = 0;
347         int dex_upgrade = 0;
348         int int_upgrade = 0;
349         int per_upgrade = 0;
350 
351         monster_visible_info mon_visible;
352 };
353 
354 avatar &get_avatar();
355 std::unique_ptr<talker> get_talker_for( avatar &me );
356 std::unique_ptr<talker> get_talker_for( avatar *me );
357 
358 struct points_left {
359     int stat_points;
360     int trait_points;
361     int skill_points;
362 
363     enum point_limit : int {
364         FREEFORM = 0,
365         ONE_POOL,
366         MULTI_POOL,
367         TRANSFER,
368     } limit;
369 
370     points_left();
371     void init_from_options();
372     // Highest amount of points to spend on stats without points going invalid
373     int stat_points_left() const;
374     int trait_points_left() const;
375     int skill_points_left() const;
376     bool is_freeform();
377     bool is_valid();
378     bool has_spare();
379     std::string to_string();
380 };
381 
382 #endif // CATA_SRC_AVATAR_H
383