-
Notifications
You must be signed in to change notification settings - Fork 286
/
Copy pathactivity_actor.h
133 lines (107 loc) · 4.33 KB
/
activity_actor.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
#pragma once
#ifndef CATA_SRC_ACTIVITY_ACTOR_H
#define CATA_SRC_ACTIVITY_ACTOR_H
#include <algorithm>
#include <memory>
#include <unordered_map>
#include <vector>
#include "clone_ptr.h"
#include "item_location.h"
#include "point.h"
#include "type_id.h"
class Character;
class JsonIn;
class JsonOut;
class player_activity;
class activity_actor
{
public:
virtual ~activity_actor() = default;
/**
* Should return the activity id of the corresponding activity
*/
virtual activity_id get_type() const = 0;
/**
* Called once at the start of the activity.
* This may be used to preform setup actions and/or set
* player_activity::moves_left/moves_total.
*/
virtual void start( player_activity &act, Character &who ) = 0;
/**
* Called on every turn of the activity
* It may be used to stop the activity prematurely by setting it to null.
*/
virtual void do_turn( player_activity &act, Character &who ) = 0;
/**
* Called when the activity runs out of moves, assuming that it has not
* already been set to null
*/
virtual void finish( player_activity &act, Character &who ) = 0;
/**
* Returns a deep copy of this object. Example implementation:
* \code
* class my_activity_actor {
* std::unique_ptr<activity_actor> clone() const override {
* return std::make_unique<my_activity_actor>( *this );
* }
* };
* \endcode
* The returned value should behave like the original item and must have the same type.
*/
virtual std::unique_ptr<activity_actor> clone() const = 0;
/**
* Must write any custom members of the derived class to json
* Note that a static member function for deserialization must also be created and
* added to the `activity_actor_deserializers` hashmap in activity_actor.cpp
*/
virtual void serialize( JsonOut &jsout ) const = 0;
};
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 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 );
};
namespace activity_actors
{
// defined in activity_actor.cpp
extern const std::unordered_map<activity_id, std::unique_ptr<activity_actor>( * )( JsonIn & )>
deserialize_functions;
} // namespace activity_actors
void serialize( const cata::clone_ptr<activity_actor> &actor, JsonOut &jsout );
void deserialize( cata::clone_ptr<activity_actor> &actor, JsonIn &jsin );
#endif // CATA_SRC_ACTIVITY_ACTOR_H