/
UnreachableAreaFillMapper.cpp
94 lines (79 loc) · 2.2 KB
/
UnreachableAreaFillMapper.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
#include "precompiled.h"
#include "UnreachableAreaFillMapper.h"
#include "GameMap.h"
#ifdef PROJECT_AOV
#define UNREACHABLE_OBSTACLE_HEIGHT 3.7f
#else
#define UNREACHABLE_OBSTACLE_HEIGHT 2.0f
#endif
namespace game
{
UnreachableAreaFillMapper::UnreachableAreaFillMapper(GameMap *data)
{
assert(data != NULL);
this->data = data;
this->fillmap = new unsigned char[data->getObstacleSizeX() * data->getObstacleSizeY()];
init();
}
UnreachableAreaFillMapper::~UnreachableAreaFillMapper()
{
delete [] fillmap;
}
unsigned char UnreachableAreaFillMapper::getByte(int x, int y)
{
assert(x >= 0 && y >= 0 && x < data->getObstacleSizeX() && y < data->getObstacleSizeY());
return fillmap[x + y * data->getObstacleSizeX()];
}
void UnreachableAreaFillMapper::setByte(int x, int y, unsigned char value)
{
assert(x >= 0 && y >= 0 && x < data->getObstacleSizeX() && y < data->getObstacleSizeY());
fillmap[x + y * data->getObstacleSizeX()] = value;
}
void UnreachableAreaFillMapper::init()
{
int sizex = data->getObstacleSizeX();
int sizey = data->getObstacleSizeY();
for (int y = 0; y < sizey; y++)
{
for (int x = 0; x < sizex; x++)
{
if (data->getObstacleHeight(x, y) == 0
|| data->isMovingObstacle(x, y))
{
fillmap[x + y * sizex] = UNR_VALUE_EMPTY;
}
else
{
fillmap[x + y * sizex] = UNR_VALUE_OBSTACLE;
}
}
}
}
void UnreachableAreaFillMapper::addReachablePoint(int x, int y)
{
if (x >= 0 && y >= 0 && x < data->getObstacleSizeX() && y < data->getObstacleSizeY())
{
fillmap[x + y * data->getObstacleSizeX()] = UNR_VALUE_REACHABLE;
} else {
// out of map!
assert(!"UnreachableAreaFillMapper::addReachablePoint - Coordinates out of bounds.");
}
}
void UnreachableAreaFillMapper::applyResult()
{
int sizex = data->getObstacleSizeX();
int sizey = data->getObstacleSizeY();
float heightScale = data->getScaleHeight();
for (int y = 0; y < sizey; y++)
{
for (int x = 0; x < sizex; x++)
{
if (fillmap[x + y * sizex] == UNR_VALUE_EMPTY
&& data->getObstacleHeight(x, y) == 0)
{
data->addObstacleHeight(x, y, (int)(UNREACHABLE_OBSTACLE_HEIGHT / heightScale), AREAVALUE_OBSTACLE_TERRAINOBJECT);
}
}
}
}
}