-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMap.cpp
71 lines (63 loc) · 1.66 KB
/
Map.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
#include <cmath>
#include "mapgen/Map.hpp"
Map::~Map(){};
float Map::getRegionDistance(Region *r, Region *r2) {
Point p = r->site;
Point p2 = r2->site;
double distancex = (p2->x - p->x);
double distancey = (p2->y - p->y);
float d = std::sqrt(distancex * distancex + distancey * distancey);
if (r->megaCluster->isLand) {
float hd = (r->getHeight(r->site) - r2->getHeight(r2->site));
if (hd < 0) {
d += 1000 * std::abs(hd);
if (r2->city != nullptr && d >= 500) {
d -= 500;
}
}
if (r2->hasRiver) {
d *= 0.6f;
}
if (r2->state != r->state) {
d *= 1.2f;
}
if (r2->biom == biom::FORREST && r2->biom == biom::RAIN_FORREST) {
d *= 1.1f;
}
if (r2->hasRoad) {
d *= 0.2f;
}
} else {
d *= 0.8f;
}
return d;
}
float Map::LeastCostEstimate(void *stateStart, void *stateEnd) {
return getRegionDistance((Region *)stateStart, (Region *)stateEnd);
};
void Map::AdjacentCost(void *state,
MP_VECTOR<micropather::StateCost> *neighbors) {
auto r = ((Region *)state);
for (auto n : r->neighbors) {
if (n->biom == biom::LAKE) {
continue;
}
if (r->megaCluster->isLand) {
if (!n->megaCluster->isLand) {
if (r->city == nullptr || r->city->type != PORT) {
continue;
}
}
} else {
if (n->megaCluster->isLand) {
if (n->city == nullptr || n->city->type != PORT) {
continue;
}
}
}
micropather::StateCost nodeCost = {
(void *)n, getRegionDistance((Region *)state, (Region *)n)};
neighbors->push_back(nodeCost);
}
};
void Map::PrintStateInfo(void *state){};