-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.h
144 lines (108 loc) · 3.19 KB
/
action.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
#ifndef action_h
#define action_h
#include "utility.h"
#include <SDL2/SDL.h>
#include <map>
#include <vector>
#include <ctime>
#include <chrono>
/********************************************************************/
class ActionBase {
public:
ActionBase() : next_action_(nullptr) {}
virtual ~ActionBase() {}
virtual void preAction() {}
virtual bool spentTime(double time_spent) = 0;
virtual void postAction() {}
virtual void cancelAction() {}
protected:
ActionBase* next_action_ = nullptr;
bool is_valid_ = true;
};
/********************************************************************/
class Character;
//_no_action_descs = [
// tr("Looking around, just for fun..."),
// tr("Need a job"),
// tr("Gets bored"),
// tr("Dreaming")
//]
class NoAction : public ActionBase {
public:
NoAction(Character* character);
virtual bool spentTime(double time_spent) override;
protected:
Character* character_;
Position origin_;
double max_time_spent_;
};
/********************************************************************/
class MoveAction : public ActionBase {
public:
MoveAction(Character* character, std::vector<Position>& path_in_tile, int tile_size);
~MoveAction() {}
virtual bool spentTime(double time_spent) override;
virtual void postAction() override;
protected:
void create_animation_path(std::vector<Position>& path_in_tile, int tile_size);
Position get_position_in_pixel();
private:
Character* character_;
Position origin_;
std::vector<Position> path_in_pixel_;
double cur_time_;
float speed_;
float activity_percent_;
Position destination_;
bool is_finished_;
Position prev_position_;
Position next_position_;
};
/********************************************************************/
class GameBoard;
class Job;
class JobActionBase : public ActionBase {
public:
JobActionBase(GameBoard* game_board, Character* people, Job* job);
virtual ~JobActionBase();
virtual void cancelAction() override;
protected:
GameBoard* game_board_;
Character* people_;
Job* job_;
};
class BuildAction : public JobActionBase {
public:
BuildAction(GameBoard* game_board, Character* people, Job* job);
virtual ~BuildAction();
virtual void preAction() override;
virtual bool spentTime(double time_spent) override;
virtual void postAction() override;
void reset();
private:
ActionBase* action_;
};
class ExtractAction : public JobActionBase {
public:
ExtractAction(GameBoard* game_board, Character* people, Job* job);
virtual ~ExtractAction();
virtual void preAction() override;
virtual bool spentTime(double time_spent) override;
virtual void postAction() override;
private:
ActionBase* action_;
bool isValid_;
};
class CleanAction : public JobActionBase {
public:
CleanAction(GameBoard* game_board, Character* people, Job* job);
virtual ~CleanAction();
virtual void preAction() override;
virtual bool spentTime(double time_spent) override;
virtual void postAction() override;
private:
ActionBase* action_;
bool isValid_;
};
/********************************************************************/
#endif // action_h