-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcell.cpp
179 lines (161 loc) · 4.78 KB
/
cell.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
// Copyright 2015 FMAW
#include "./cell.h"
#include <vector>
bool operator <(IndexPath const &left, IndexPath const &right) {
return left.row < right.row || (left.row == right.row
&& left.col < right.col);
}
bool operator ==(IndexPath const &left, IndexPath const &right) {
return left.row == right.row && left.col == right.col;
}
Cell::Cell() {
this->background = FMAW::Background(0);
}
void Cell::setCenter(FMAW::Point newCenter) {
this->center = newCenter;
}
CellBackgroundType Cell::getBackgroundType() {
return this->backgroundType;
}
void Cell::setBackgroundType(CellBackgroundType type) {
this->backgroundType = type;
}
FMAW::Point Cell::getCenter() {
return this->center;
}
bool Cell::isOccupied() {
return this->characterInCell != nullptr;
}
Unit *Cell::getCharacter() {
return this->characterInCell;
}
Unit *Cell::setCharacter(Unit *newCharacter) {
Unit *prev = this->characterInCell;
this->characterInCell = newCharacter;
if (newCharacter != nullptr) {
newCharacter->decreaseAvailableActions();
newCharacter->setPosition(this->center);
}
return prev;
}
int Cell::movementCost() {
switch (this->backgroundType) {
case CellBGBase:
return COST_MOVE_CELL_BASE;
case CellBGBridge:
case CellBGBridgeH:
return COST_MOVE_CELL_BRIDGE;
case CellBGForest:
return COST_MOVE_CELL_FOREST;
case CellBGGrass:
return COST_MOVE_CELL_GRASS;
case CellBGMountain:
return COST_MOVE_CELL_MOUNTAIN;
case CellBGRiver:
case CellBGRiverH:
return COST_MOVE_CELL_RIVER;
case CellBGCastle:
return COST_MOVE_CELL_CASTLE;
default:
return COST_CELL_INFINITY;
}
}
int Cell::sightCost() {
switch (this->backgroundType) {
case CellBGBase:
return COST_SEE_CELL_BASE;
case CellBGBridge:
case CellBGBridgeH:
return COST_SEE_CELL_BRIDGE;
case CellBGForest:
return COST_SEE_CELL_FOREST;
case CellBGGrass:
return COST_SEE_CELL_GRASS;
case CellBGMountain:
return COST_SEE_CELL_MOUNTAIN;
case CellBGRiver:
case CellBGRiverH:
return COST_SEE_CELL_RIVER;
case CellBGCastle:
return COST_SEE_CELL_CASTLE;
default:
return COST_CELL_INFINITY;
}
}
int Cell::terrainDefense() {
switch (this->backgroundType) {
case CellBGBase:
return DEFENSE_CELL_BASE;
case CellBGBridge:
case CellBGBridgeH:
return DEFENSE_CELL_BRIDGE;
case CellBGForest:
return DEFENSE_CELL_FOREST;
case CellBGGrass:
return DEFENSE_CELL_GRASS;
case CellBGMountain:
return DEFENSE_CELL_MOUNTAIN;
case CellBGRiver:
case CellBGRiverH:
return DEFENSE_CELL_RIVER;
default:
return DEFAULT_DEFENSE;
}
}
void Cell::renderBackground() {
switch (this->backgroundType) {
case CellBGBase:
case CellBGBridge:
case CellBGBridgeH:
case CellBGForest:
case CellBGGrass:
case CellBGMountain:
case CellBGRiver:
case CellBGRiverH:
case CellBGCastle:
this->background.setScreenBaseBlock(2);
for (int i = 0; i < this->tiles.size(); ++i) {
this->background.setTile(
this->tiles[i],
FMAW::Tile(this->backgroundType).imgMemory + i);
this->background.setPalette(
this->tiles[i],
FMAW::Tile(this->backgroundType).palMemory);
}
break;
default:
break;
}
}
void Cell::renderFoggyBackground() {
switch (this->backgroundType) {
case CellBGBase:
case CellBGBridge:
case CellBGBridgeH:
case CellBGForest:
case CellBGGrass:
case CellBGMountain:
case CellBGRiver:
case CellBGRiverH:
case CellBGCastle:
this->background.setScreenBaseBlock(2);
for (int i = 0; i < this->tiles.size(); ++i) {
this->background.setTile(
this->tiles[i],
FMAW::Tile(this->backgroundType +
NUM_BACKGROUNDS).imgMemory + i);
this->background.setPalette(
this->tiles[i],
FMAW::Tile(this->backgroundType +
NUM_BACKGROUNDS).palMemory);
}
break;
default:
break;
}
}
void Cell::renderCharacter() {
if (this->characterInCell != nullptr) {
this->characterInCell->render();
}
}