-
Notifications
You must be signed in to change notification settings - Fork 291
/
Copy pathactivity_actor_definitions.h
531 lines (430 loc) · 18.7 KB
/
activity_actor_definitions.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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
#pragma once
#ifndef CATA_SRC_ACTIVITY_ACTOR_DEFINITIONS_H
#define CATA_SRC_ACTIVITY_ACTOR_DEFINITIONS_H
#include "activity_actor.h"
#include "coordinates.h"
#include "item_handling_util.h"
#include "item_location.h"
#include "memory_fast.h"
#include "optional.h"
#include "pickup_token.h"
#include "point.h"
#include "type_id.h"
#include "units_energy.h"
class Creature;
class vehicle;
class aim_activity_actor : public activity_actor
{
private:
cata::optional<item> fake_weapon;
units::energy bp_cost_per_shot = 0_J;
int stamina_cost_per_shot = 0;
std::vector<tripoint> fin_trajectory;
public:
bool first_turn = true;
std::string action = "";
int aif_duration = 0; // Counts aim-and-fire duration
bool aiming_at_critter = false; // Whether aiming at critter or a tile
bool snap_to_target = false;
bool shifting_view = false;
tripoint initial_view_offset;
/** Target UI requested to abort aiming */
bool aborted = false;
/** RELOAD_AND_SHOOT weapon is kept loaded by the activity */
bool loaded_RAS_weapon = false;
/**
* Target UI requested to abort aiming and reload weapon
* Implies aborted = true
*/
bool reload_requested = false;
/**
* A friendly creature may enter line of fire during aim-and-shoot,
* and that generates a warning to proceed/abort. If player decides to
* proceed, that creature is saved in this vector to prevent the same warning
* from popping up on the following turn(s).
*/
std::vector<weak_ptr_fast<Creature>> acceptable_losses;
aim_activity_actor();
/** Aiming wielded gun */
static aim_activity_actor use_wielded();
/** Aiming fake gun provided by a bionic */
static aim_activity_actor use_bionic( const item &fake_gun, const units::energy &cost_per_shot );
/** Aiming fake gun provided by a mutation */
static aim_activity_actor use_mutation( const item &fake_gun );
activity_id get_type() const override {
return activity_id( "ACT_AIM" );
}
void start( player_activity &act, Character &who ) override;
void do_turn( player_activity &act, Character &who ) override;
void finish( player_activity &act, Character &who ) override;
void canceled( player_activity &act, Character &who ) override;
std::unique_ptr<activity_actor> clone() const override {
return std::make_unique<aim_activity_actor>( *this );
}
void serialize( JsonOut &jsout ) const override;
static std::unique_ptr<activity_actor> deserialize( JsonIn &jsin );
item *get_weapon();
void restore_view();
// Load/unload a RELOAD_AND_SHOOT weapon
bool load_RAS_weapon();
void unload_RAS_weapon();
};
class autodrive_activity_actor : public activity_actor
{
private:
vehicle *player_vehicle = nullptr;
public:
autodrive_activity_actor() = default;
activity_id get_type() const override {
return activity_id( "ACT_AUTODRIVE" );
}
void start( player_activity &act, Character & ) override;
void do_turn( player_activity &, Character & ) override;
void canceled( player_activity &, Character & ) override;
void finish( player_activity &act, Character & ) override;
std::unique_ptr<activity_actor> clone() const override {
return std::make_unique<autodrive_activity_actor>( *this );
}
void serialize( JsonOut &jsout ) const override;
static std::unique_ptr<activity_actor> deserialize( JsonIn &jsin );
};
class dig_activity_actor : public activity_actor
{
private:
int moves_total;
/** location of the dig **/
tripoint location;
std::string result_terrain;
tripoint byproducts_location;
int byproducts_count;
std::string byproducts_item_group;
/**
* Returns true if @p other and `this` are "equivalent" in the sense that
* `this` can be resumed instead of starting @p other.
*/
bool equivalent_activity( const dig_activity_actor &other ) const {
return location == other.location &&
result_terrain == other.result_terrain &&
byproducts_location == other.byproducts_location &&
byproducts_count == other.byproducts_count &&
byproducts_item_group == other.byproducts_item_group;
}
/**
* @pre @p other is a `dig_activity_actor`
*/
bool can_resume_with_internal( const activity_actor &other, const Character & ) const override {
const dig_activity_actor &d_actor = static_cast<const dig_activity_actor &>( other );
return equivalent_activity( d_actor );
}
public:
dig_activity_actor(
int dig_moves, const tripoint &dig_loc,
const std::string &resulting_ter, const tripoint &dump_loc,
int dump_spawn_count, const std::string &dump_item_group
):
moves_total( dig_moves ), location( dig_loc ),
result_terrain( resulting_ter ),
byproducts_location( dump_loc ),
byproducts_count( dump_spawn_count ),
byproducts_item_group( dump_item_group ) {}
activity_id get_type() const override {
return activity_id( "ACT_DIG" );
}
void start( player_activity &act, Character & ) override;
void do_turn( player_activity &, Character & ) override;
void finish( player_activity &act, Character &who ) override;
std::unique_ptr<activity_actor> clone() const override {
return std::make_unique<dig_activity_actor>( *this );
}
void serialize( JsonOut &jsout ) const override;
static std::unique_ptr<activity_actor> deserialize( JsonIn &jsin );
};
class dig_channel_activity_actor : public activity_actor
{
private:
int moves_total;
/** location of the dig **/
tripoint location;
std::string result_terrain;
tripoint byproducts_location;
int byproducts_count;
std::string byproducts_item_group;
/**
* Returns true if @p other and `this` are "equivalent" in the sense that
* `this` can be resumed instead of starting @p other.
*/
bool equivalent_activity( const dig_channel_activity_actor &other ) const {
return location == other.location &&
result_terrain == other.result_terrain &&
byproducts_location == other.byproducts_location &&
byproducts_count == other.byproducts_count &&
byproducts_item_group == other.byproducts_item_group;
}
/**
* @pre @p other is a `dig_activity_actor`
*/
bool can_resume_with_internal( const activity_actor &other, const Character & ) const override {
const dig_channel_activity_actor &dc_actor = static_cast<const dig_channel_activity_actor &>
( other );
return equivalent_activity( dc_actor );
}
public:
dig_channel_activity_actor(
int dig_moves, const tripoint &dig_loc,
const std::string &resulting_ter, const tripoint &dump_loc,
int dump_spawn_count, const std::string &dump_item_group
):
moves_total( dig_moves ), location( dig_loc ),
result_terrain( resulting_ter ),
byproducts_location( dump_loc ),
byproducts_count( dump_spawn_count ),
byproducts_item_group( dump_item_group ) {}
activity_id get_type() const override {
return activity_id( "ACT_DIG_CHANNEL" );
}
void start( player_activity &act, Character & ) override;
void do_turn( player_activity &, Character & ) override;
void finish( player_activity &act, Character &who ) override;
std::unique_ptr<activity_actor> clone() const override {
return std::make_unique<dig_channel_activity_actor>( *this );
}
void serialize( JsonOut &jsout ) const override;
static std::unique_ptr<activity_actor> deserialize( JsonIn &jsin );
};
class disassemble_activity_actor : public activity_actor
{
private:
std::vector<iuse_location> targets;
tripoint_abs_ms pos;
bool recursive = false;
int initial_num_targets = 0;
public:
disassemble_activity_actor() = default;
disassemble_activity_actor(
std::vector<iuse_location> &&targets,
tripoint_abs_ms pos,
bool recursive
) : targets( std::move( targets ) ), pos( pos ), recursive( recursive ) {}
~disassemble_activity_actor() = default;
activity_id get_type() const override {
return activity_id( "ACT_DISASSEMBLE" );
}
void start( player_activity &act, Character &who ) override;
void do_turn( player_activity &, Character & ) override {};
void finish( player_activity &act, Character &who ) override;
std::unique_ptr<activity_actor> clone() const override {
return std::make_unique<disassemble_activity_actor>( *this );
}
void serialize( JsonOut &jsout ) const override;
static std::unique_ptr<activity_actor> deserialize( JsonIn &jsin );
act_progress_message get_progress_message(
const player_activity &, const Character & ) const override;
bool try_start_single( player_activity &act, Character &who );
int calc_num_targets() const;
};
class drop_activity_actor : public activity_actor
{
private:
std::list<pickup::act_item> items;
bool force_ground = false;
tripoint relpos;
public:
drop_activity_actor() = default;
drop_activity_actor( Character &ch, const drop_locations &items,
bool force_ground, const tripoint &relpos );
activity_id get_type() const override {
return activity_id( "ACT_DROP" );
}
void start( player_activity &, Character & ) override;
void do_turn( player_activity &, Character &who ) override;
void finish( player_activity &, Character & ) override {};
std::unique_ptr<activity_actor> clone() const override {
return std::make_unique<drop_activity_actor>( *this );
}
void serialize( JsonOut &jsout ) const override;
static std::unique_ptr<activity_actor> deserialize( JsonIn &jsin );
};
class hacking_activity_actor : public activity_actor
{
private:
bool using_bionic = false;
public:
struct use_bionic {};
hacking_activity_actor() = default;
hacking_activity_actor( use_bionic );
activity_id get_type() const override {
return activity_id( "ACT_HACKING" );
}
void start( player_activity &act, Character &who ) override;
void do_turn( player_activity &, Character & ) override {};
void finish( player_activity &act, Character &who ) override;
std::unique_ptr<activity_actor> clone() const override {
return std::make_unique<hacking_activity_actor>( *this );
}
void serialize( JsonOut &jsout ) const override;
static std::unique_ptr<activity_actor> deserialize( JsonIn &jsin );
};
class migration_cancel_activity_actor : public activity_actor
{
public:
migration_cancel_activity_actor() = default;
activity_id get_type() const override {
return activity_id( "ACT_MIGRATION_CANCEL" );
}
void start( player_activity &, Character & ) override {};
void do_turn( player_activity &act, Character &who ) override;
void finish( player_activity &, Character & ) override {};
std::unique_ptr<activity_actor> clone() const override {
return std::make_unique<migration_cancel_activity_actor>( *this );
}
void serialize( JsonOut &jsout ) const override;
static std::unique_ptr<activity_actor> deserialize( JsonIn &jsin );
};
class move_items_activity_actor : public activity_actor
{
private:
std::vector<item_location> target_items;
std::vector<int> quantities;
bool to_vehicle;
tripoint relative_destination;
public:
move_items_activity_actor( std::vector<item_location> target_items, std::vector<int> quantities,
bool to_vehicle, tripoint relative_destination ) :
target_items( target_items ), quantities( quantities ), to_vehicle( to_vehicle ),
relative_destination( relative_destination ) {}
activity_id get_type() const override {
return activity_id( "ACT_MOVE_ITEMS" );
}
void start( player_activity &, Character & ) override {};
void do_turn( player_activity &act, Character &who ) override;
void finish( player_activity &, Character & ) override {};
std::unique_ptr<activity_actor> clone() const override {
return std::make_unique<move_items_activity_actor>( *this );
}
void serialize( JsonOut &jsout ) const override;
static std::unique_ptr<activity_actor> deserialize( JsonIn &jsin );
};
class toggle_gate_activity_actor : public activity_actor
{
private:
int moves_total;
tripoint placement;
/**
* @pre @p other is a toggle_gate_activity_actor
*/
bool can_resume_with_internal( const activity_actor &other, const Character & ) const override {
const toggle_gate_activity_actor &og_actor = static_cast<const toggle_gate_activity_actor &>
( other );
return placement == og_actor.placement;
}
public:
toggle_gate_activity_actor( int gate_moves, const tripoint &gate_placement ) :
moves_total( gate_moves ), placement( gate_placement ) {}
activity_id get_type() const override {
return activity_id( "ACT_TOGGLE_GATE" );
}
void start( player_activity &act, Character & ) override;
void do_turn( player_activity &, Character & ) override {};
void finish( player_activity &act, Character & ) override;
std::unique_ptr<activity_actor> clone() const override {
return std::make_unique<toggle_gate_activity_actor>( *this );
}
void serialize( JsonOut &jsout ) const override;
static std::unique_ptr<activity_actor> deserialize( JsonIn &jsin );
};
class pickup_activity_actor : public activity_actor
{
private:
/** Target items and the quantities thereof */
std::vector<pickup::pick_drop_selection> target_items;
/**
* Position of the character when the activity is started. This is
* stored so that we can cancel the activity if the player moves
* (e.g. if the player is in a moving vehicle). This should be null
* if not grabbing from the ground.
*/
cata::optional<tripoint> starting_pos;
public:
pickup_activity_actor( const std::vector<pickup::pick_drop_selection> &target_items,
const cata::optional<tripoint> &starting_pos )
: target_items( target_items )
, starting_pos( starting_pos ) {}
activity_id get_type() const override {
return activity_id( "ACT_PICKUP" );
}
void start( player_activity &, Character & ) override {};
void do_turn( player_activity &act, Character &who ) override;
void finish( player_activity &, Character & ) override {};
std::unique_ptr<activity_actor> clone() const override {
return std::make_unique<pickup_activity_actor>( *this );
}
void serialize( JsonOut &jsout ) const override;
static std::unique_ptr<activity_actor> deserialize( JsonIn &jsin );
};
class stash_activity_actor : public activity_actor
{
private:
std::list<pickup::act_item> items;
tripoint relpos;
public:
stash_activity_actor() = default;
stash_activity_actor( Character &ch, const drop_locations &items, const tripoint &relpos );
activity_id get_type() const override {
return activity_id( "ACT_STASH" );
}
void start( player_activity &, Character & ) override;
void do_turn( player_activity &, Character &who ) override;
void finish( player_activity &, Character & ) override {};
std::unique_ptr<activity_actor> clone() const override {
return std::make_unique<stash_activity_actor>( *this );
}
void serialize( JsonOut &jsout ) const override;
static std::unique_ptr<activity_actor> deserialize( JsonIn &jsin );
};
class throw_activity_actor : public activity_actor
{
private:
item_location target_loc;
cata::optional<tripoint> blind_throw_from_pos;
public:
throw_activity_actor() = default;
throw_activity_actor(
item_location target_loc,
cata::optional<tripoint> blind_throw_from_pos
) : target_loc( target_loc ),
blind_throw_from_pos( blind_throw_from_pos ) {}
~throw_activity_actor() = default;
activity_id get_type() const override {
return activity_id( "ACT_THROW" );
}
void start( player_activity &, Character & ) override {};
void do_turn( player_activity &act, Character &who ) override;
void finish( player_activity &, Character & ) override {};
std::unique_ptr<activity_actor> clone() const override {
return std::make_unique<throw_activity_actor>( *this );
}
void serialize( JsonOut &jsout ) const override;
static std::unique_ptr<activity_actor> deserialize( JsonIn &jsin );
};
class wash_activity_actor : public activity_actor
{
private:
iuse_locations targets;
int moves_total = 0;
public:
wash_activity_actor() = default;
wash_activity_actor( const iuse_locations &targets, int moves_total ) :
targets( targets ), moves_total( moves_total ) {};
activity_id get_type() const override {
return activity_id( "ACT_WASH" );
}
void start( player_activity &act, Character & ) override;
void do_turn( player_activity &, Character & ) override {};
void finish( player_activity &act, Character &who ) override;
std::unique_ptr<activity_actor> clone() const override {
return std::make_unique<wash_activity_actor>( *this );
}
void serialize( JsonOut &jsout ) const override;
static std::unique_ptr<activity_actor> deserialize( JsonIn &jsin );
};
#endif // CATA_SRC_ACTIVITY_ACTOR_DEFINITIONS_H