forked from miki151/keeperrl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.cpp
46 lines (36 loc) · 1.02 KB
/
action.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
#include "stdafx.h"
#include "action.h"
vector<ActionId> dirActions {ActionId::MOVE, ActionId::MOVE_TO, ActionId::TRAVEL, ActionId::FIRE,
ActionId::THROW_DIR};
Action::Action() {
}
Action::Action(ActionId i) : id(i) {
CHECK(!contains(dirActions, id)) << "Id " << (int)id << " needs direction";
}
ActionId Action::getId() {
return id;
}
Action::Action(ActionId i, Vec2 dir) : id(i), direction(dir) {
CHECK(contains(dirActions, id)) << "Id " << (int)id << " doesn't have direction";
}
Vec2 Action::getDirection() {
CHECK(contains(dirActions, id)) << "Id " << (int)id << " doesn't have direction";
return direction;
}
std::ostream& operator << (std::ostream& o, Action a) {
o << (int) a.getId();
if (contains(dirActions, a.getId()))
o << " " << a.getDirection();
return o;
}
std::istream& operator >> (std::istream& in, Action& a) {
int id;
in >> id;
if (contains(dirActions, (ActionId) id)) {
Vec2 v;
in >> v;
a = Action((ActionId) id, v);
} else
a = Action((ActionId) id);
return in;
}