-
Notifications
You must be signed in to change notification settings - Fork 55
/
GameBuildings.cpp
203 lines (179 loc) · 6.92 KB
/
GameBuildings.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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#include "common.h"
#include "WorldSegment.h"
#include "SpriteMaps.h"
#include "GameBuildings.h"
#include "BuildingConfiguration.h"
#include "ContentLoader.h"
#include "GUI.h"
#include "df/buildings_other_id.h"
using df::global::world;
//vector<BuildingConfiguration> buildingTypes;
//vector <string> v_buildingtypes;//should be empty for all buildings
/*
int TileNeighbourhoodType_simple(WorldSegment* segment, Tile* b, bool validationFuctionProc(Tile*) ){
uint32_t x,y,z;
x = b->x; y = b->y; z = b->z;
bool n = validationFuctionProc( segment->getTile( x, y-1, z, true) );
bool s = validationFuctionProc( segment->getTile( x, y+1, z, true) );
bool e = validationFuctionProc( segment->getTile( x+1, y, z, true) );
bool w = validationFuctionProc( segment->getTile( x-1, y, z, true) );
//bool nw = validationFuctionProc( segment->getTile(, x-1, y-1, z) );
//bool ne = validationFuctionProc( segment->getTile(, x+1, y-1, z) );
//bool SW = validationFuctionProc( segment->getTile(, x-1, y+1, z) );
//bool se = validationFuctionProc( segment->getTile(, x+1, y+1, z) );
if(!n && !s && !w && !e) return eSimpleSingle;
if( n && !s && !w && !e) return eSimpleN;
if(!n && !s && w && !e) return eSimpleW;
if(!n && s && !w && !e) return eSimpleS;
if(!n && !s && !w && e) return eSimpleE;
if( n && s && !w && !e) return eSimpleNnS;
if(!n && !s && w && e) return eSimpleWnE;
if( n && !s && w && !e) return eSimpleNnW;
if(!n && s && w && !e) return eSimpleSnW;
if(!n && s && !w && e) return eSimpleSnE;
if( n && !s && !w && e) return eSimpleNnE;
//....
return eSimpleSingle;
}*/
bool tileHasBridge(Tile* b)
{
if(!b) {
return 0;
}
return b->building.info.type == df::enums::building_type::Bridge;
}
dirTypes findWallCloseTo(WorldSegment* segment, Tile* b)
{
uint32_t x,y,z;
x = b->x;
y = b->y;
z = b->z;
bool n = hasWall( segment->getTileRelativeTo( x, y, z, eUp) );
bool s = hasWall( segment->getTileRelativeTo( x, y, z, eDown) );
bool w = hasWall( segment->getTileRelativeTo( x, y, z, eLeft) );
bool e = hasWall( segment->getTileRelativeTo( x, y, z, eRight) );
if(w) {
return eSimpleW;
}
if(n) {
return eSimpleN;
}
if(s) {
return eSimpleS;
}
if(e) {
return eSimpleE;
}
return eSimpleSingle;
}
void ReadBuildings(DFHack::Core& DF, vector<Buildings::t_building>* buildingHolder)
{
if(ssConfig.skipBuildings) {
return;
}
if(!buildingHolder) {
return;
}
vector<string> dummy;
Buildings::t_building tempbuilding;
df::buildings_other_id types = df::buildings_other_id::IN_PLAY;
for (int i = 0; i < world->buildings.other[types].size(); i++) {
Core & c = Core::getInstance();
df::building *bld = world->buildings.other[types][i];
tempbuilding.x1 = bld->x1;
tempbuilding.x2 = bld->x2;
tempbuilding.y1 = bld->y1;
tempbuilding.y2 = bld->y2;
tempbuilding.z = bld->z;
tempbuilding.material.index = bld->mat_index;
tempbuilding.material.type = bld->mat_type;
tempbuilding.type = bld->getType();
tempbuilding.subtype = bld->getSubtype();
tempbuilding.custom_type = bld->getCustomType();
tempbuilding.origin = bld;
buildingHolder->push_back(tempbuilding);
}
}
void MergeBuildingsToSegment(vector<Buildings::t_building>* buildings, WorldSegment* segment)
{
Buildings::t_building tempbuilding;
uint32_t numBuildings = (uint32_t)buildings->size();
for(uint32_t i=0; i < numBuildings; i++) {
tempbuilding = (*buildings)[i];
//int bheight = tempbuilding.y2 - tempbuilding.y1;
for(uint32_t yy = tempbuilding.y1; yy <= tempbuilding.y2; yy++)
for(uint32_t xx = tempbuilding.x1; xx <= tempbuilding.x2; xx++) {
Tile* b = segment->getTile( xx, yy, tempbuilding.z);
if(b) {
//want hashtable :(
// still need to test for b, because of ramp/building overlap
//handle special case where zones and stockpiles overlap buildings, and try to replace them
if(b->building.info.type != BUILDINGTYPE_NA && tempbuilding.type == df::enums::building_type::Civzone ) {
continue;
}
if(b->building.info.type != BUILDINGTYPE_NA && tempbuilding.type == df::enums::building_type::Stockpile ) {
continue;
}
b->building.index = i;
b->building.info = tempbuilding;
}
}
}
}
void loadBuildingSprites ( Tile* b)
{
bool foundTileBuildingInfo = false;
if (b == NULL) {
LogError("Null Tile skipped in loadBuildingSprites\n");
return;
}
BuildingConfiguration* generic = NULL, *specific = NULL, *custom = NULL;
for(auto iter = contentLoader->buildingConfigs.begin(); iter < contentLoader->buildingConfigs.end(); iter++) {
BuildingConfiguration & conf = *iter;
if(b->building.info.type == conf.game_type) {
generic = &conf;
if(b->building.info.subtype == conf.game_subtype) {
specific = &conf;
if(b->building.info.custom_type == conf.game_custom) {
custom = &conf;
}
}
}
}
BuildingConfiguration * final = custom?custom:(specific?specific:(generic?generic:NULL));
//check all sprites for one that matches all conditions
if (final && final->sprites != NULL && final->sprites->copyToTile(b)) {
foundTileBuildingInfo = true;
}
//add yellow box, if needed. But only if the building was not found (this way we can have blank slots in buildings)
if(b->building.sprites.size() == 0 && foundTileBuildingInfo == false) {
c_sprite unknownBuildingSprite;
unknownBuildingSprite.reset();
b->building.sprites.push_back( unknownBuildingSprite );
}
}
/*TODO: this function takes a massive amount of work, looping all buildings for every tile*/
bool TileHasSuspendedBuilding(vector<Buildings::t_building>* buildingList, Tile* b)
{
uint32_t num = (uint32_t)buildingList->size();
for(uint32_t i=0; i < num; i++) {
Buildings::t_building* building = &(*buildingList)[i];
//boundry check
if(b->z != building->z) {
continue;
}
if(b->x < building->x1 || b->x > building->x2) {
continue;
}
if(b->y < building->y1 || b->y > building->y2) {
continue;
}
if(building->type == df::enums::building_type::Bridge) {
return true;
}
if(building->type == df::enums::building_type::Civzone) {
return true;
}
}
return false;
}