1 #pragma once 2 #ifndef CATA_SRC_PLAYER_H 3 #define CATA_SRC_PLAYER_H 4 5 #include <iosfwd> 6 #include <list> 7 #include <map> 8 #include <set> 9 #include <type_traits> 10 #include <utility> 11 #include <vector> 12 13 #include "character.h" 14 #include "character_id.h" 15 #include "creature.h" 16 #include "enums.h" 17 #include "game_constants.h" 18 #include "item.h" 19 #include "item_location.h" 20 #include "item_pocket.h" 21 #include "memory_fast.h" 22 #include "optional.h" 23 #include "point.h" 24 #include "ret_val.h" 25 #include "type_id.h" 26 27 class JsonIn; 28 class JsonObject; 29 class JsonOut; 30 class nc_color; 31 class profession; 32 class time_duration; 33 class time_point; 34 class vehicle; 35 36 namespace catacurses 37 { 38 class window; 39 } // namespace catacurses 40 struct damage_unit; 41 struct dealt_projectile_attack; 42 struct trap; 43 44 enum action_id : int; 45 enum game_message_type : int; 46 enum class recipe_filter_flags : int; 47 48 nc_color encumb_color( int level ); 49 50 /** @relates ret_val */ 51 template<> 52 struct ret_val<edible_rating>::default_success : public 53 std::integral_constant<edible_rating, EDIBLE> {}; 54 55 /** @relates ret_val */ 56 template<> 57 struct ret_val<edible_rating>::default_failure : public 58 std::integral_constant<edible_rating, INEDIBLE> {}; 59 60 struct stat_mod { 61 int strength = 0; 62 int dexterity = 0; 63 int intelligence = 0; 64 int perception = 0; 65 66 int speed = 0; 67 }; 68 69 struct needs_rates { 70 float thirst = 0.0f; 71 float hunger = 0.0f; 72 float fatigue = 0.0f; 73 float recovery = 0.0f; 74 float kcal = 0.0f; 75 }; 76 77 class player : public Character 78 { 79 public: 80 player(); 81 player( const player & ) = delete; 82 player( player && ); 83 ~player() override; 84 player &operator=( const player & ) = delete; 85 player &operator=( player && ); 86 87 /** Calls Character::normalize() 88 * normalizes HP and body temperature 89 */ 90 91 void normalize() override; 92 93 bool is_player() const override { 94 return true; 95 } 96 player *as_player() override { 97 return this; 98 } 99 const player *as_player() const override { 100 return this; 101 } 102 103 bool is_npc() const override { 104 return false; // Overloaded for NPCs in npc.h 105 } 106 107 // populate variables, inventory items, and misc from json object 108 virtual void deserialize( JsonIn &jsin ) = 0; 109 110 // by default save all contained info 111 virtual void serialize( JsonOut &jsout ) const = 0; 112 113 /** Handles and displays detailed character info for the '@' screen */ 114 void disp_info(); 115 116 /**Estimate effect duration based on player relevant skill*/ 117 time_duration estimate_effect_dur( const skill_id &relevant_skill, const efftype_id &effect, 118 const time_duration &error_magnitude, 119 int threshold, const Creature &target ) const; 120 121 /** Resets movement points and applies other non-idempotent changes */ 122 void process_turn() override; 123 /** Calculates the various speed bonuses we will get from mutations, etc. */ 124 void recalc_speed_bonus(); 125 126 /** Called when a player triggers a trap, returns true if they don't set it off */ 127 bool avoid_trap( const tripoint &pos, const trap &tr ) const override; 128 129 void pause(); // '.' command; pauses & resets recoil 130 131 // melee.cpp 132 133 /** Returns true if a gun misfires, jams, or has other problems, else returns false */ 134 bool handle_gun_damage( item &it ); 135 136 /** Get maximum recoil penalty due to vehicle motion */ 137 double recoil_vehicle() const; 138 139 /** Current total maximum recoil penalty from all sources */ 140 double recoil_total() const; 141 142 /** How many moves does it take to aim gun to the target accuracy. */ 143 int gun_engagement_moves( const item &gun, int target = 0, int start = MAX_RECOIL ) const; 144 145 /** 146 * Fires a gun or auxiliary gunmod (ignoring any current mode) 147 * @param target where the first shot is aimed at (may vary for later shots) 148 * @param shots maximum number of shots to fire (less may be fired in some circumstances) 149 * @return number of shots actually fired 150 */ 151 152 int fire_gun( const tripoint &target, int shots = 1 ); 153 /** 154 * Fires a gun or auxiliary gunmod (ignoring any current mode) 155 * @param target where the first shot is aimed at (may vary for later shots) 156 * @param shots maximum number of shots to fire (less may be fired in some circumstances) 157 * @param gun item to fire (which does not necessary have to be in the players possession) 158 * @return number of shots actually fired 159 */ 160 int fire_gun( const tripoint &target, int shots, item &gun ); 161 162 /** 163 * Checks both the neighborhoods of from and to for climbable surfaces, 164 * returns move cost of climbing from `from` to `to`. 165 * 0 means climbing is not possible. 166 * Return value can depend on the orientation of the terrain. 167 */ 168 int climbing_cost( const tripoint &from, const tripoint &to ) const; 169 170 // ranged.cpp 171 /** Execute a throw */ 172 dealt_projectile_attack throw_item( const tripoint &target, const item &to_throw, 173 const cata::optional<tripoint> &blind_throw_from_pos = cata::nullopt ); 174 175 /** 176 * Check if a given body part is immune to a given damage type 177 * 178 * This function checks whether a given body part cannot be damaged by a given 179 * damage_unit. Note that this refers only to reduction of hp on that part. It 180 * does not account for clothing damage, pain, status effects, etc. 181 * 182 * @param bp: Body part to perform the check on 183 * @param dam: Type of damage to check for 184 * @returns true if given damage can not reduce hp of given body part 185 */ 186 bool immune_to( const bodypart_id &bp, damage_unit dam ) const; 187 /** Modifies a pain value by player traits before passing it to Creature::mod_pain() */ 188 void mod_pain( int npain ) override; 189 /** Sets new intensity of pain an reacts to it */ 190 void set_pain( int npain ) override; 191 /** Returns perceived pain (reduced with painkillers)*/ 192 int get_perceived_pain() const override; 193 194 /** Knocks the player to a specified tile */ 195 void knock_back_to( const tripoint &to ) override; 196 197 /** Returns multiplier on fall damage at low velocity (knockback/pit/1 z-level, not 5 z-levels) */ 198 float fall_damage_mod() const override; 199 /** Deals falling/collision damage with terrain/creature at pos */ 200 int impact( int force, const tripoint &pos ) override; 201 202 /** Returns overall % of HP remaining */ 203 int hp_percentage() const override; 204 205 /** Returns list of rc items in player inventory. **/ 206 std::list<item *> get_radio_items(); 207 208 /** Siphons fuel (if available) from the specified vehicle into container or 209 * similar via @ref game::handle_liquid. May start a player activity. 210 */ 211 void siphon( vehicle &veh, const itype_id &desired_liquid ); 212 213 /** Used for eating object at a location. Removes item if all of it was consumed. 214 * @returns trinary enum NONE, SOME or ALL amount consumed. 215 */ 216 trinary consume( item_location loc, bool force = false ); 217 218 /** Used for eating a particular item that doesn't need to be in inventory. 219 * @returns trinary enum NONE, SOME or ALL (doesn't remove). 220 */ 221 trinary consume( item &target, bool force = false ); 222 223 int get_lift_assist() const; 224 225 bool list_ammo( const item &base, std::vector<item::reload_option> &ammo_list, 226 bool empty = true ) const; 227 /** 228 * Select suitable ammo with which to reload the item 229 * @param base Item to select ammo for 230 * @param prompt force display of the menu even if only one choice 231 * @param empty allow selection of empty magazines 232 */ 233 item::reload_option select_ammo( const item &base, bool prompt = false, 234 bool empty = true ) const; 235 236 /** Select ammo from the provided options */ 237 item::reload_option select_ammo( const item &base, std::vector<item::reload_option> opts ) const; 238 239 /** returns players strength adjusted by any traits that affect strength during lifting jobs */ 240 int get_lift_str() const; 241 242 /** Check player strong enough to lift an object unaided by equipment (jacks, levers etc) */ 243 template <typename T> bool can_lift( const T &obj ) const; 244 /** 245 * Check player capable of taking off an item. 246 * @param it Thing to be taken off 247 */ 248 ret_val<bool> can_takeoff( const item &it, const std::list<item> *res = nullptr ); 249 250 /** 251 * Attempt to mend an item (fix any current faults) 252 * @param obj Object to mend 253 * @param interactive if true prompts player when multiple faults, otherwise mends the first 254 */ 255 void mend_item( item_location &&obj, bool interactive = true ); 256 257 /** Wear item; returns false on fail. If interactive is false, don't alert the player or drain moves on completion. */ 258 cata::optional<std::list<item>::iterator> 259 wear( int pos, bool interactive = true ); 260 261 /** Wear item; returns false on fail. If interactive is false, don't alert the player or drain moves on completion. 262 * @param item_wear item_location of item to be worn. 263 * @param interactive Alert player and drain moves if true. 264 */ 265 cata::optional<std::list<item>::iterator> 266 wear( item_location item_wear, bool interactive = true ); 267 268 /** Takes off an item, returning false on fail. The taken off item is processed in the interact */ 269 bool takeoff( item &it, std::list<item> *res = nullptr ); 270 bool takeoff( int pos ); 271 272 /** 273 * Try to wield a contained item consuming moves proportional to weapon skill and volume. 274 * @param container Container containing the item to be wielded 275 * @param internal_item reference to contained item to wield. 276 * @param penalties Whether item volume and temporary effects (e.g. GRABBED, DOWNED) should be considered. 277 * @param base_cost Cost due to storage type. 278 */ 279 bool wield_contents( item &container, item *internal_item = nullptr, bool penalties = true, 280 int base_cost = INVENTORY_HANDLING_PENALTY ); 281 /** 282 * Stores an item inside another consuming moves proportional to weapon skill and volume 283 * @param container Container in which to store the item 284 * @param put Item to add to the container 285 * @param penalties Whether item volume and temporary effects (e.g. GRABBED, DOWNED) should be considered. 286 * @param base_cost Cost due to storage type. 287 */ 288 void store( item &container, item &put, bool penalties = true, 289 int base_cost = INVENTORY_HANDLING_PENALTY, 290 item_pocket::pocket_type pk_type = item_pocket::pocket_type::CONTAINER ); 291 /** Draws the UI and handles player input for the armor re-ordering window */ 292 void sort_armor(); 293 /** Uses a tool */ 294 void use( int inventory_position ); 295 /** Uses a tool at location */ 296 void use( item_location loc, int pre_obtain_moves = -1 ); 297 /** Uses the current wielded weapon */ 298 void use_wielded(); 299 300 /** Reassign letter. */ 301 void reassign_item( item &it, int invlet ); 302 303 /** 304 * Starts activity to remove gunmod after unloading any contained ammo. 305 * Returns true on success (activity has been started) 306 */ 307 bool gunmod_remove( item &gun, item &mod ); 308 309 /** Starts activity to install gunmod having warned user about any risk of failure or irremovable mods s*/ 310 void gunmod_add( item &gun, item &mod ); 311 312 /** @return Odds for success (pair.first) and gunmod damage (pair.second) */ 313 std::pair<int, int> gunmod_installation_odds( const item &gun, const item &mod ) const; 314 315 /** Starts activity to install toolmod */ 316 void toolmod_add( item_location tool, item_location mod ); 317 318 /** Handles sleep attempts by the player, starts ACT_TRY_SLEEP activity */ 319 void try_to_sleep( const time_duration &dur ); 320 321 //returns true if the warning is now beyond final and results in hostility. 322 bool add_faction_warning( const faction_id &id ); 323 int current_warnings_fac( const faction_id &id ); 324 bool beyond_final_warning( const faction_id &id ); 325 /** Returns the effect of pain on stats */ 326 stat_mod get_pain_penalty() const; 327 int kcal_speed_penalty() const; 328 /** Returns the penalty to speed from thirst */ 329 static int thirst_speed_penalty( int thirst ); 330 331 void on_worn_item_transform( const item &old_it, const item &new_it ); 332 333 void process_items(); 334 335 // ---------------VALUES----------------- 336 tripoint view_offset; 337 // Relative direction of a grab, add to posx, posy to get the coordinates of the grabbed thing. 338 tripoint grab_point; 339 int volume = 0; 340 const profession *prof; 341 342 bool random_start_location = true; 343 start_location_id start_location; 344 345 weak_ptr_fast<Creature> last_target; 346 cata::optional<tripoint> last_target_pos; 347 // Save favorite ammo location 348 item_location ammo_location; 349 int scent = 0; 350 int cash = 0; 351 int movecounter = 0; 352 353 bool manual_examine = false; 354 vproto_id starting_vehicle; 355 std::vector<mtype_id> starting_pets; 356 357 std::set<character_id> follower_ids; 358 void mod_stat( const std::string &stat, float modifier ) override; 359 360 void set_underwater( bool ); 361 bool is_hallucination() const override; 362 void environmental_revert_effect(); 363 364 //message related stuff 365 using Character::add_msg_if_player; 366 void add_msg_if_player( const std::string &msg ) const override; 367 void add_msg_if_player( const game_message_params ¶ms, const std::string &msg ) const override; 368 using Character::add_msg_player_or_npc; 369 void add_msg_player_or_npc( const std::string &player_msg, 370 const std::string &npc_str ) const override; 371 void add_msg_player_or_npc( const game_message_params ¶ms, const std::string &player_msg, 372 const std::string &npc_msg ) const override; 373 using Character::add_msg_player_or_say; 374 void add_msg_player_or_say( const std::string &player_msg, 375 const std::string &npc_speech ) const override; 376 void add_msg_player_or_say( const game_message_params ¶ms, const std::string &player_msg, 377 const std::string &npc_speech ) const override; 378 379 /** Search surrounding squares for traps (and maybe other things in the future). */ 380 void search_surroundings(); 381 // formats and prints encumbrance info to specified window 382 void print_encumbrance( const catacurses::window &win, int line = -1, 383 const item *selected_clothing = nullptr ) const; 384 385 using Character::query_yn; 386 bool query_yn( const std::string &mes ) const override; 387 388 protected: 389 390 void store( JsonOut &json ) const; 391 void load( const JsonObject &data ); 392 393 private: 394 395 /** warnings from a faction about bad behavior */ 396 std::map<faction_id, std::pair<int, time_point>> warning_record; 397 398 }; 399 400 extern template bool player::can_lift<item>( const item &obj ) const; 401 extern template bool player::can_lift<vehicle>( const vehicle &obj ) const; 402 403 #endif // CATA_SRC_PLAYER_H 404