-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdwarf.cpp
More file actions
78 lines (59 loc) · 1.44 KB
/
Copy pathdwarf.cpp
File metadata and controls
78 lines (59 loc) · 1.44 KB
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
#include "dwarf.h"
Dwarf::Dwarf(int r, int c, int nm, int lmbr, double radius,
std::vector< std::vector <Place> > & area, void (*set_action)(Action a, Dir dir, int r, int c) )
{
int rows = area.size();
int cols = area[0].size();
known.resize(rows);
for(int rr = 0; rr < rows; ++rr) {
known[rr].resize(cols);
for(int cc = 0; cc < cols; ++cc) {
known[rr][cc] = UNKNOWN;
if (((double)r-rr)*((double)r-rr) + ((double)c-cc)*((double)c-cc) <= radius * radius)
known[rr][cc] = area[rr][cc];
}
}
p_set_action = set_action;
location.r = r;
location.c = c;
name_value = nm;
lumber_value = lmbr;
}
int Dwarf::row() {
return location.r;
}
int Dwarf::col() {
return location.c;
}
int Dwarf::name() {
return name_value;
}
int Dwarf::lumber() {
return lumber_value;
}
Place Dwarf::look(int r, int c) {
int rows = known.size();
int cols = known[0].size();
if (r >= 0 && c >= 0 && r < rows && c < cols)
return known[r][c];
else
return UNKNOWN;
}
Place Dwarf::look(Loc loc) {
return look(loc.r, loc.c);
}
void Dwarf::start_walk(int r, int c) {
(*p_set_action)(WALK, WEST, r, c);
}
void Dwarf::start_walk(Loc loc) {
(*p_set_action)(WALK, WEST, loc.r, loc.c);
}
void Dwarf::start_chop(Dir dir) {
(*p_set_action)(CHOP, dir, 0, 0);
}
void Dwarf::start_pick(Dir dir) {
(*p_set_action)(PICK, dir, 0, 0);
}
void Dwarf::start_build(Dir dir) {
(*p_set_action)(BUILD, dir, 0, 0);
}