-
-
Notifications
You must be signed in to change notification settings - Fork 113
/
Copy pathtile_predicate.cpp
57 lines (45 loc) · 1.8 KB
/
tile_predicate.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
#include "stdafx.h"
#include "tile_predicate.h"
static bool apply(const TilePredicates::On& p, LayoutCanvas::Map* map, Vec2 v, RandomGen& r) {
return map->elems[v].contains(p.token);
}
static bool apply(const TilePredicates::Not& p, LayoutCanvas::Map* map, Vec2 v, RandomGen& r) {
return !p.predicate->apply(map, v, r);
}
static bool apply(const TilePredicates::True& p, LayoutCanvas::Map* map, Vec2 v, RandomGen& r) {
return true;
}
static bool apply(const TilePredicates::And& p, LayoutCanvas::Map* map, Vec2 v, RandomGen& r) {
for (auto& pred : p.predicates)
if (!pred.apply(map, v, r))
return false;
return true;
}
static bool apply(const TilePredicates::Or& p, LayoutCanvas::Map* map, Vec2 v, RandomGen& r) {
for (auto& pred : p.predicates)
if (pred.apply(map, v, r))
return true;
return false;
}
static bool apply(const TilePredicates::Area& p, LayoutCanvas::Map* map, Vec2 v, RandomGen& r) {
int count = 0;
for (auto pos : Rectangle::centered(v, p.radius))
if (pos.inRectangle(map->elems.getBounds()) && p.predicate->apply(map, pos, r))
++count;
return count >= p.minCount;
}
static bool apply(const TilePredicates::Translate& p, LayoutCanvas::Map* map, Vec2 v, RandomGen& r) {
return p.predicate->apply(map, v + p.offset, r);
}
static bool apply(const TilePredicates::Chance& p, LayoutCanvas::Map* map, Vec2 v, RandomGen& r) {
return r.chance(p.value);
}
static bool apply(const TilePredicates::XMod& p, LayoutCanvas::Map* map, Vec2 v, RandomGen& r) {
return v.x % p.div == p.mod;
}
static bool apply(const TilePredicates::YMod& p, LayoutCanvas::Map* map, Vec2 v, RandomGen& r) {
return v.y % p.div == p.mod;
}
bool TilePredicate::apply(LayoutCanvas::Map* map, Vec2 v, RandomGen& r) const {
return visit<bool>([&](const auto& p) { return ::apply(p, map, v, r); });
}