forked from cataclysmbnteam/Cataclysm-BN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.h
287 lines (252 loc) · 12 KB
/
player.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
#pragma once
#ifndef CATA_SRC_PLAYER_H
#define CATA_SRC_PLAYER_H
#include <climits>
#include <functional>
#include <list>
#include <map>
#include <memory>
#include <optional>
#include <set>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>
#include "bodypart.h"
#include "calendar.h"
#include "character.h"
#include "character_id.h"
#include "color.h"
#include "creature.h"
#include "cursesdef.h"
#include "enums.h"
#include "game_constants.h"
#include "item.h"
#include "item_location.h"
#include "pimpl.h"
#include "point.h"
#include "ret_val.h"
#include "safe_reference.h"
#include "string_id.h"
#include "type_id.h"
class basecamp;
class craft_command;
class effect;
class faction;
class inventory;
class map;
class npc;
class recipe;
struct damage_unit;
struct requirement_data;
enum class recipe_filter_flags : int;
struct itype;
static const std::string
DEFAULT_HOTKEYS( "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" );
class recipe_subset;
enum action_id : int;
class JsonIn;
class JsonObject;
class JsonOut;
class dispersion_sources;
struct bionic;
struct dealt_projectile_attack;
class profession;
struct trap;
nc_color encumb_color( int level );
enum game_message_type : int;
class vehicle;
struct item_comp;
struct tool_comp;
struct w_point;
using recipe_filter = std::function<bool( const recipe &r )>;
/** @relates ret_val */
template<>
struct ret_val<edible_rating>::default_success : public
std::integral_constant<edible_rating, edible_rating::edible> {};
/** @relates ret_val */
template<>
struct ret_val<edible_rating>::default_failure : public
std::integral_constant<edible_rating, edible_rating::inedible> {};
class player : public Character
{
public:
player();
player( const player & ) = delete;
player( player && );
~player() override;
player &operator=( const player & ) = delete;
player &operator=( player && );
bool is_player() const override {
return true;
}
player *as_player() override {
return this;
}
const player *as_player() const override {
return this;
}
bool is_npc() const override {
return false; // Overloaded for NPCs in npc.h
}
// populate variables, inventory items, and misc from json object
virtual void deserialize( JsonIn &jsin ) = 0;
// by default save all contained info
virtual void serialize( JsonOut &jsout ) const = 0;
/**
* Remove charges from a specific item (given by its item position).
* The item must exist and it must be counted by charges.
* @param position Item position of the item.
* @param quantity The number of charges to remove, must not be larger than
* the current charges of the item.
* @return An item that contains the removed charges, it's effectively a
* copy of the item with the proper charges.
*/
item reduce_charges( int position, int quantity );
/**
* Remove charges from a specific item (given by a pointer to it).
* Otherwise identical to @ref reduce_charges(int,int)
* @param it A pointer to the item, it *must* exist.
* @param quantity How many charges to remove
*/
item reduce_charges( item *it, int quantity );
// Checks crafting inventory for books providing the requested recipe.
// Then checks nearby NPCs who could provide it too.
// Returns -1 to indicate recipe not found, otherwise difficulty to learn.
int has_recipe( const recipe *r, const inventory &crafting_inv,
const std::vector<npc *> &helpers ) const;
bool has_recipe_requirements( const recipe &rec ) const;
bool studied_all_recipes( const itype &book ) const;
/** Returns all recipes that are known from the books (either in inventory or nearby). */
recipe_subset get_recipes_from_books( const inventory &crafting_inv,
recipe_filter filter = nullptr ) const;
/**
* Returns all available recipes (from books and npc companions)
* @param crafting_inv Current available items to craft
* @param helpers List of NPCs that could help with crafting.
* @param filter If set, will return only recipes that match the filter (should be much faster).
*/
recipe_subset get_available_recipes( const inventory &crafting_inv,
const std::vector<npc *> *helpers = nullptr,
recipe_filter filter = nullptr ) const;
/** For use with in progress crafts */
int available_assistant_count( const recipe &rec ) const;
/**
* Time to craft not including speed multiplier
*/
int base_time_to_craft( const recipe &rec, int batch_size = 1 ) const;
/**
* Expected time to craft a recipe, with assumption that multipliers stay constant.
*/
int expected_time_to_craft( const recipe &rec, int batch_size = 1, bool in_progress = false ) const;
std::vector<const item *> get_eligible_containers_for_crafting() const;
bool check_eligible_containers_for_crafting( const recipe &rec, int batch_size = 1 ) const;
bool can_make( const recipe *r, int batch_size = 1 ); // have components?
/**
* Returns true if the player can start crafting the recipe with the given batch size
* The player is not required to have enough tool charges to finish crafting, only to
* complete the first step (total / 20 + total % 20 charges)
*/
bool can_start_craft( const recipe *rec, recipe_filter_flags, int batch_size = 1 );
bool making_would_work( const recipe_id &id_to_make, int batch_size );
/**
* Start various types of crafts
* @param loc the location of the workbench. tripoint_zero indicates crafting from inventory.
*/
void craft( const tripoint &loc = tripoint_zero );
void recraft( const tripoint &loc = tripoint_zero );
void long_craft( const tripoint &loc = tripoint_zero );
void make_craft( const recipe_id &id, int batch_size, const tripoint &loc = tripoint_zero );
void make_all_craft( const recipe_id &id, int batch_size, const tripoint &loc = tripoint_zero );
/** consume components and create an active, in progress craft containing them */
item_location start_craft( craft_command &command, const tripoint &loc );
/**
* Calculate a value representing the success of the player at crafting the given recipe,
* taking player skill, recipe difficulty, npc helpers, and player mutations into account.
* @param making the recipe for which to calculate
* @return a value >= 0.0 with >= 1.0 representing unequivocal success
*/
double crafting_success_roll( const recipe &making ) const;
/**
* Check if the player meets the requirements to continue the in progress craft and if
* unable to continue print messages explaining the reason.
* If the craft is missing components due to messing up, prompt to consume new ones to
* allow the craft to be continued.
* @param craft the currently in progress craft
* @return if the craft can be continued
*/
bool can_continue_craft( item &craft );
/**
* Handle skill gain for player and followers during crafting
* @param craft the currently in progress craft
* @param multiplier what factor to multiply the base skill gain by. This is used to apply
* multiple steps of incremental skill gain simultaneously if needed.
*/
void craft_skill_gain( const item &craft, const int &multiplier );
const requirement_data *select_requirements(
const std::vector<const requirement_data *> &, int batch, const inventory &,
const std::function<bool( const item & )> &filter ) const;
comp_selection<item_comp>
select_item_component( const std::vector<item_comp> &components,
int batch, inventory &map_inv, bool can_cancel = false,
const std::function<bool( const item & )> &filter = return_true<item>, bool player_inv = true );
std::list<item> consume_items( const comp_selection<item_comp> &is, int batch,
const std::function<bool( const item & )> &filter = return_true<item> );
std::list<item> consume_items( map &m, const comp_selection<item_comp> &is, int batch,
const std::function<bool( const item & )> &filter = return_true<item>,
const tripoint &origin = tripoint_zero, int radius = PICKUP_RANGE );
std::list<item> consume_items( const std::vector<item_comp> &components, int batch = 1,
const std::function<bool( const item & )> &filter = return_true<item> );
/** Consume tools for the next multiplier * 5% progress of the craft */
bool craft_consume_tools( item &craft, int mulitplier, bool start_craft );
void consume_tools( const comp_selection<tool_comp> &tool, int batch );
void consume_tools( map &m, const comp_selection<tool_comp> &tool, int batch,
const tripoint &origin = tripoint_zero, int radius = PICKUP_RANGE,
basecamp *bcp = nullptr );
void consume_tools( const std::vector<tool_comp> &tools, int batch = 1,
const std::string &hotkeys = DEFAULT_HOTKEYS );
// ---------------VALUES-----------------
tripoint view_offset;
// Relative direction of a grab, add to posx, posy to get the coordinates of the grabbed thing.
tripoint grab_point;
int volume = 0;
bool random_start_location = false;
start_location_id start_location;
weak_ptr_fast<Creature> last_target;
std::optional<tripoint> last_target_pos;
// Save favorite ammo location
item_location ammo_location;
int scent = 0;
int cash = 0;
int movecounter = 0;
bool manual_examine = false;
vproto_id starting_vehicle = vproto_id::NULL_ID();
std::vector<mtype_id> starting_pets;
void make_craft_with_command( const recipe_id &id_to_make, int batch_size, bool is_long = false,
const tripoint &loc = tripoint_zero );
pimpl<craft_command> last_craft;
recipe_id lastrecipe;
int last_batch = 0;
itype_id lastconsumed; //used in crafting.cpp and construction.cpp
std::set<character_id> follower_ids;
//message related stuff
using Character::add_msg_if_player;
void add_msg_if_player( const std::string &msg ) const override;
void add_msg_if_player( const game_message_params ¶ms, const std::string &msg ) const override;
using Character::add_msg_player_or_npc;
void add_msg_player_or_npc( const std::string &player_msg,
const std::string &npc_str ) const override;
void add_msg_player_or_npc( const game_message_params ¶ms, const std::string &player_msg,
const std::string &npc_msg ) const override;
using Character::add_msg_player_or_say;
void add_msg_player_or_say( const std::string &player_msg,
const std::string &npc_speech ) const override;
void add_msg_player_or_say( const game_message_params ¶ms, const std::string &player_msg,
const std::string &npc_speech ) const override;
using Character::query_yn;
bool query_yn( const std::string &mes ) const override;
protected:
void store( JsonOut &json ) const;
void load( const JsonObject &data );
};
#endif // CATA_SRC_PLAYER_H