-
Notifications
You must be signed in to change notification settings - Fork 0
/
entity.cpp
121 lines (82 loc) · 2.42 KB
/
entity.cpp
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
#include "action.h"
#include "entity.h"
#include "map.h"
// Setup and teardown ==================
entity::entity() {
init();
}
void entity::init() {
timer_list = new vector<timer *>();
}
// Basics ====================
entityclass * entity::get_class() {
return my_class;
}
string entity::get_name() {
if (individual_name.length() > 0) {
return individual_name;
} else {
return my_class->get_name();
}
}
// Trigger effect management ===================
void entity::resolve_trigger(trigger_t trigger, argmap * args)
{
argmap * my_map = new argmap(args);
my_map->add_entity(ARG_HOLDER_ENTITY, this);
// Execute all these effects
vector<effect*> * my_effects = get_class()->get_effects(trigger);
if (my_effects != NULL) {
for(int i = 0; i < my_effects->size(); ++i) {
my_effects->at(i)->resolve(my_map);
}
}
}
// Timer management =====================
void entity::start_timers(map * my_map) {
// Create timers for timed effects in the condition's class
std::vector<timer_effect *>::iterator it = my_class->timer_effects->begin();
for (;it != get_class()->timer_effects->end(); ++it) {
argmap * newmap = new argmap();
newmap->add_entity(ARG_HOLDER_ENTITY, this);
my_map->add_timer(new timer(*it, newmap));
}
}
void entity::destroy_timers(map * my_map) {
vector<timer *>::iterator it = timer_list->begin();
for(; it != timer_list->end(); ++it) {
my_map->remove_timer(*it);
}
}
// Stat management ==================
int entity::has_stat(stats_t code) {
return get_class()->has_stat(code);
}
int entity::get_stat(stats_t code) {
return get_class()->get_stat(code);
return 0;
}
// Flag management ================
bool entity::has_flag(flags_t code) {
return get_class()->has_flag(code);
}
// State management ===============
int entity::has_state(state_t code) {
return get_class()->has_state(code);
}
entityclass * entity::get_state(state_t code) {
return get_class()->get_state(code);
return NULL;
}
bool entity::change_state(state_t code) {
entityclass * new_state = get_state(code);
if (new_state != NULL) {
my_class = new_state;
return true;
}
return false;
}
// Action management =======================
vector<action*> * entity::get_actions() {
return action::defs_for(get_class()->actions);
}