15 |
#include "../blotchmaker/stlastar.h" |
#include "../blotchmaker/stlastar.h" |
16 |
#include "../blotchmaker/map.h" |
#include "../blotchmaker/map.h" |
17 |
|
|
18 |
const long TIMING_LOOP_DELAY =200000; |
const long TIMING_LOOP_DELAY =400000; |
19 |
|
|
20 |
|
|
21 |
// static variables: |
// static variables: |
60 |
opac = 40; |
opac = 40; |
61 |
acu = 65; |
acu = 65; |
62 |
size = 30; // aka "weight" |
size = 30; // aka "weight" |
63 |
spd = 50; |
spd = 70; |
64 |
|
|
65 |
x_pos = 0; |
x_pos = 0; |
66 |
y_pos = 0; |
y_pos = 0; |
67 |
|
|
68 |
avoid = 1; |
avoid = 1; |
69 |
engage = 0; |
engage = 1; |
70 |
|
|
71 |
// put me somewhere on the map |
// put me somewhere on the map |
72 |
// set map coords |
// set map coords |
137 |
int Pod::GetYPos(){ |
int Pod::GetYPos(){ |
138 |
return y_pos; |
return y_pos; |
139 |
} |
} |
140 |
|
|
141 |
|
int Pod::GetAvoid(){ |
142 |
|
return avoid; |
143 |
|
} |
144 |
|
|
145 |
|
int Pod::GetEngage(){ |
146 |
|
return engage; |
147 |
|
} |
148 |
|
|
149 |
|
int Pod::GetXp(){ |
150 |
|
return xp; |
151 |
|
} |
152 |
|
|
153 |
|
Mission* Pod::Misn(){ |
154 |
|
return misn; |
155 |
|
} |
156 |
// ================================== |
// ================================== |
157 |
|
|
158 |
|
|
163 |
|
|
164 |
|
|
165 |
|
|
166 |
|
// SET FUNCTIONS |
167 |
|
// ================================== |
168 |
|
void Pod::SetMission(mission_type m ) { |
169 |
|
switch(m) { |
170 |
|
case PATROL: |
171 |
|
misn = new Patrol(*this, x_pos, y_pos, 4, 0); |
172 |
|
break; |
173 |
|
default: |
174 |
|
break; |
175 |
|
} |
176 |
|
} |
177 |
|
|
178 |
|
void Pod::SetEngage(int x) { |
179 |
|
engage = x; |
180 |
|
} |
181 |
|
|
182 |
|
void Pod::SetAvoid(int x){ |
183 |
|
avoid = x; |
184 |
|
} |
185 |
|
|
186 |
|
bool Pod::Place(int x, int y) { |
187 |
|
x_pos = x; |
188 |
|
y_pos = y; |
189 |
|
bool bad = map->SetOccu(x,y,*this); |
190 |
|
if (bad) {return 0;} |
191 |
|
else {return 1;} |
192 |
|
} |
193 |
|
// ================================== |
194 |
|
|
195 |
|
|
196 |
|
|
197 |
|
|
198 |
|
|
199 |
|
|
200 |
|
|
201 |
|
|
202 |
|
|
203 |
|
|
204 |
// GENERAL POD FUNCTIONS |
// GENERAL POD FUNCTIONS |
205 |
// ================================== |
// ================================== |
206 |
// map pointer setter - used for all pods. |
// map pointer setter - used for all pods. |
232 |
bool Pod::CreatePath(int x1, int y1, int x2, int y2) { |
bool Pod::CreatePath(int x1, int y1, int x2, int y2) { |
233 |
// return 1 if path was made, 0 if path could not be found |
// return 1 if path was made, 0 if path could not be found |
234 |
|
|
235 |
int timeout = ( ( map->GetCols() * map->GetRows() ) / 2 ); |
int timeout = ( ( map->GetCols() * map->GetRows() ) / 1 ); |
236 |
|
|
237 |
// set pod pointer for all mapsearch nodes |
// set pod pointer for all mapsearch nodes |
238 |
// do this every time we search because many other pods are searching too and they all override eachother |
// do this every time we search because many other pods are searching too and they all override eachother |
275 |
path = NULL; |
path = NULL; |
276 |
return 0; |
return 0; |
277 |
} |
} |
278 |
|
|
279 |
} |
} |
280 |
|
|
281 |
|
|
284 |
|
|
285 |
bool Pod::Walk() { |
bool Pod::Walk() { |
286 |
// moves the pod across the map along the specified path until it runs out of juice. |
// moves the pod across the map along the specified path until it runs out of juice. |
287 |
|
// return zero if no path found, 1 if success |
288 |
|
|
289 |
// ERROR: got path? |
// ERROR: got path? |
290 |
|
|
309 |
if (map->GetRoadQ(is->x, is->y) <= spd_allot) { |
if (map->GetRoadQ(is->x, is->y) <= spd_allot) { |
310 |
spd_allot -= map->GetRoadQ(is->x, is->y); // subtract road cost from allotment |
spd_allot -= map->GetRoadQ(is->x, is->y); // subtract road cost from allotment |
311 |
} |
} |
312 |
else {break;} // can't afford to move anymore |
else {break; } // can't afford to move anymore |
313 |
|
|
314 |
|
// if it's occupied and we were not ready for that, STOP |
315 |
|
// this is here because the pathfinder will not figure in occupied tiles into the path |
316 |
|
// *UNLESS* it's the goal state (enemy target for instance) |
317 |
|
Pod* occupied = map->GetOccu(is->x, is->y); |
318 |
|
if (occupied != NULL) { |
319 |
|
path->FreeSolutionNodes(); |
320 |
|
path = NULL; |
321 |
|
return 1; |
322 |
|
} |
323 |
|
|
324 |
// retie all the occupation and positional markers |
// retie all the occupation and positional markers |
325 |
map->SetOccu(is->x, is->y, *this ); // move the occupation to the new tile |
map->SetOccu(is->x, is->y, *this ); // move the occupation to the new tile |
331 |
// trample road |
// trample road |
332 |
map->TrampleRoad(is->x, is->y); // TODO: maybe add trample amount depending on pod weight? |
map->TrampleRoad(is->x, is->y); // TODO: maybe add trample amount depending on pod weight? |
333 |
|
|
334 |
|
// TODO: pick up map specials |
335 |
|
|
336 |
// timing loop and shell display |
// timing loop and shell display |
337 |
clock_t s = clock(); |
clock_t s = clock(); |
338 |
while ( (clock() - s) < TIMING_LOOP_DELAY) {continue;} // NOTE: unix dependent time ticks |
while ( (clock() - s) < TIMING_LOOP_DELAY) {continue;} // NOTE: unix dependent time ticks |
360 |
|
|
361 |
}; |
}; |
362 |
|
|
363 |
return 0; // did not hit goal after all moving finished this round |
// TODO: after all done moving, we need to do some individual end-of-turn operations |
364 |
|
// ++ experience |
365 |
|
// ++ mission time <- should this be in the mission or here? sometimes we move without following the mission Exe()! |
366 |
|
|
367 |
|
|
368 |
|
return 0; // did not hit goal after all done moving this round |
369 |
} |
} |
370 |
|
|
371 |
|
|