Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d0a8c2e

Browse files
committed
Move TileTypes to XML, part 1 - a bunch of stuff is now broken
1 parent 9f43d61 commit d0a8c2e

17 files changed

Lines changed: 270 additions & 1069 deletions

library/TileTypes.cpp

Lines changed: 75 additions & 723 deletions
Large diffs are not rendered by default.

library/include/TileTypes.h

Lines changed: 63 additions & 209 deletions
Original file line numberDiff line numberDiff line change
@@ -29,118 +29,11 @@ distribution.
2929

3030
#include "Pragma.h"
3131
#include "Export.h"
32+
#include "DataDefs.h"
33+
#include "df/tiletype.h"
3234

3335
namespace DFHack
3436
{
35-
36-
// tile class -- determines the general shape of the tile
37-
// enum and lookup table for string names created using X macros
38-
#define TILESHAPE_MACRO \
39-
X(EMPTY, "") \
40-
X(WALL, "") \
41-
X(PILLAR, "") \
42-
X(BROOK_BED, "mineable, water-passable rock on the bottom of brook") \
43-
X(FORTIFICATION, "") \
44-
X(STAIR_UP, "") \
45-
X(STAIR_DOWN, "") \
46-
X(STAIR_UPDOWN, "") \
47-
X(RAMP, "ramps have no direction" ) \
48-
X(RAMP_TOP, "used for pathing?" ) \
49-
X(FLOOR, "") \
50-
X(BROOK_TOP, "water-passable floor on top of BROOK_BED tiles") \
51-
X(RIVER_BED, "It's a riverbed. Basically a floor that doesn't get muddy.") \
52-
X(POOL, "A pool. Gathers water while it's raining.'") \
53-
X(TREE_DEAD, "") \
54-
X(TREE_OK, "") \
55-
X(SAPLING_DEAD, "") \
56-
X(SAPLING_OK, "") \
57-
X(SHRUB_DEAD, "") \
58-
X(SHRUB_OK, "") \
59-
X(BOULDER, "") \
60-
X(PEBBLES, "") \
61-
X(ENDLESS_PIT, "a fake endless pit")
62-
//end TILESHAPE_MACRO
63-
64-
//define tile class enum
65-
#define X(name,comment) name,
66-
enum TileShape {
67-
tileshape_invalid=-1,
68-
TILESHAPE_MACRO
69-
tileshape_count,
70-
};
71-
#undef X
72-
73-
DFHACK_EXPORT extern const char *TileShapeString[];
74-
75-
#define TILEMATERIAL_MACRO \
76-
X(AIR, "empty" ) \
77-
X(SOIL, "ordinary soil. material depends on geology" ) \
78-
X(STONE, "ordinary layer stone. material depends on geology" ) \
79-
X(FEATSTONE, "map special stone. used for things like hell, the hell temple or adamantine tubes. material depends on local/global special" ) \
80-
X(OBSIDIAN, "lava stone created by mixing magma and water" ) \
81-
X(VEIN, "vein stone. material depends on mineral veins present" ) \
82-
X(ICE, "frozen water... not much to say. you can determine what was on the tile before it froze by looking into the 'ice vein' objects" ) \
83-
X(GRASS, "light grass (has 4 variants)" ) \
84-
X(GRASS2, "dark grass (has 4 variants)" ) \
85-
X(GRASS_DEAD, "dead grass (has 4 variants)" ) \
86-
X(GRASS_DRY, "dry grass (has 4 variants)" ) \
87-
X(DRIFTWOOD, "driftwood. normally shows up on beaches" ) \
88-
X(HFS, "the stuff demon pits are made of - this makes them different from ordinary pits." ) \
89-
X(MAGMA, "material for semi-molten rock and 'magma flow' tiles" ) \
90-
X(CAMPFIRE, "human armies make them when they siege. The original tile may be lost?" ) \
91-
X(FIRE, "burning grass" ) \
92-
X(ASHES, "what remains from a FIRE" ) \
93-
X(CONSTRUCTED,"tile material depends on the construction present" ) \
94-
X(CYAN_GLOW, "the glowy stuff that disappears from the demon temple when you take the sword." )
95-
//end TILEMATERIAL_MACRO
96-
97-
// material enum
98-
#define X(name,comment) name,
99-
enum TileMaterial {
100-
tilematerial_invalid=-1,
101-
TILEMATERIAL_MACRO
102-
tilematerial_count,
103-
};
104-
#undef X
105-
106-
107-
DFHACK_EXPORT extern const char *TileMaterialString[];
108-
109-
// Special specials of the tile.
110-
// Not the best way to do this, but compatible with existing code.
111-
// When the TileType class gets created, everything should be re-thought.
112-
#define TILESPECIAL_MACRO \
113-
X(NORMAL, "Default for all type, nothing present" ) \
114-
X(RIVER_SOURCE, "River Source, when it exists on a map" ) \
115-
X(WATERFALL, "Waterfall from Nowhere, used by cave rivers back in 40d" ) \
116-
X(CRACKED, "Partially (75%) mined walls" ) \
117-
X(DAMAGED, "Partially (50%) mined walls" ) \
118-
X(WORN, "Partially (25%) mined walls" ) \
119-
X(SMOOTH, "Walls and floors." )
120-
//end TILESPECIAL_MACRO
121-
122-
//special enum
123-
#define X(name,comment) TILE_##name,
124-
enum TileSpecial {
125-
tilespecial_invalid=-1,
126-
TILESPECIAL_MACRO
127-
tilespecial_count,
128-
};
129-
#undef X
130-
131-
DFHACK_EXPORT extern const char *TileSpecialString[];
132-
133-
// variants are used for tiles, where there are multiple variants of the same - like grass floors
134-
enum TileVariant
135-
{
136-
tilevariant_invalid=-1,
137-
VAR_1, //Yes, the value of VAR_1 is 0. It's legacy. Deal with it.
138-
VAR_2,
139-
VAR_3,
140-
VAR_4,
141-
};
142-
143-
14437
//Mainly walls and rivers
14538
//Byte values are used because walls can have either 1 or 2 in any given direction.
14639
const int TileDirectionCount = 4;
@@ -162,6 +55,18 @@ namespace DFHack
16255
{
16356
whole = whole_bits;
16457
}
58+
bool operator== (const TileDirection &other) const
59+
{
60+
return whole == other.whole;
61+
}
62+
bool operator!= (const TileDirection &other) const
63+
{
64+
return whole != other.whole;
65+
}
66+
operator bool() const
67+
{
68+
return whole != 0;
69+
}
16570
TileDirection( unsigned char North, unsigned char South, unsigned char West, unsigned char East )
16671
{
16772
north=North; south=South; east=East; west=West;
@@ -235,172 +140,117 @@ namespace DFHack
235140
#undef DIRECTION
236141
return str;
237142
}
238-
239-
240-
};
241-
242-
struct TileRow
243-
{
244-
const char * name;
245-
TileShape shape;
246-
TileMaterial material;
247-
TileVariant variant;
248-
TileSpecial special;
249-
TileDirection direction;
250143
};
251144

252-
#define TILE_TYPE_ARRAY_LENGTH 520
253-
254-
extern DFHACK_EXPORT const TileRow tileTypeTable[];
145+
using namespace df::enums;
255146

256147
// tile is missing a floor
257148
inline
258-
bool LowPassable(int16_t tiletype)
149+
bool LowPassable(df::tiletype tiletype)
259150
{
260-
switch(DFHack::tileTypeTable[tiletype].shape)
261-
{
262-
case DFHack::EMPTY:
263-
case DFHack::STAIR_DOWN:
264-
case DFHack::STAIR_UPDOWN:
265-
case DFHack::RAMP_TOP:
266-
return true;
267-
default:
268-
return false;
269-
}
270-
};
151+
return tiletype_shape::get_passable_low(tiletype::get_shape(tiletype));
152+
}
271153

272154
// tile is missing a roof
273155
inline
274-
bool HighPassable(int16_t tiletype)
275-
{
276-
switch(DFHack::tileTypeTable[tiletype].shape)
277-
{
278-
case DFHack::EMPTY:
279-
case DFHack::STAIR_DOWN:
280-
case DFHack::STAIR_UPDOWN:
281-
case DFHack::STAIR_UP:
282-
case DFHack::RAMP:
283-
case DFHack::RAMP_TOP:
284-
case DFHack::FLOOR:
285-
case DFHack::SAPLING_DEAD:
286-
case DFHack::SAPLING_OK:
287-
case DFHack::SHRUB_DEAD:
288-
case DFHack::SHRUB_OK:
289-
case DFHack::BOULDER:
290-
case DFHack::PEBBLES:
291-
case DFHack::RIVER_BED:
292-
case DFHack::POOL:
293-
case DFHack::ENDLESS_PIT:
294-
case DFHack::BROOK_TOP:
295-
return true;
296-
default:
297-
return false;
298-
}
299-
};
300-
301-
inline
302-
bool FlowPassable(int16_t tiletype)
156+
bool HighPassable(df::tiletype tiletype)
303157
{
304-
TileShape tc = tileTypeTable[tiletype].shape;
305-
return tc != WALL && tc != PILLAR && tc != TREE_DEAD && tc != TREE_OK;
306-
};
158+
return tiletype_shape::get_passable_flow(tiletype::get_shape(tiletype));
159+
}
307160

308161
inline
309-
bool isWallTerrain(int16_t tiletype)
162+
bool FlowPassable(df::tiletype tiletype)
310163
{
311-
return tileTypeTable[tiletype].shape >= WALL && tileTypeTable[tiletype].shape <= FORTIFICATION ;
164+
return tiletype_shape::get_passable_high(tiletype::get_shape(tiletype));
312165
}
313166

314167
inline
315-
bool isFloorTerrain(int16_t tiletype)
168+
bool isWallTerrain(df::tiletype tiletype)
316169
{
317-
return tileTypeTable[tiletype].shape >= FLOOR && tileTypeTable[tiletype].shape <= PEBBLES;
170+
return tiletype_shape::get_basic_shape(tiletype::get_shape(tiletype)) == tiletype_shape_basic::Wall;
318171
}
319172

320173
inline
321-
bool isRampTerrain(int16_t tiletype)
174+
bool isFloorTerrain(df::tiletype tiletype)
322175
{
323-
return tileTypeTable[tiletype].shape == RAMP;
176+
return tiletype_shape::get_basic_shape(tiletype::get_shape(tiletype)) == tiletype_shape_basic::Floor;
324177
}
325178

326179
inline
327-
bool isStairTerrain(int16_t tiletype)
180+
bool isRampTerrain(df::tiletype tiletype)
328181
{
329-
return tileTypeTable[tiletype].shape >= STAIR_UP && tileTypeTable[tiletype].shape <= STAIR_UPDOWN;
182+
return tiletype_shape::get_basic_shape(tiletype::get_shape(tiletype)) == tiletype_shape_basic::Ramp;
330183
}
331184

332185
inline
333-
bool isOpenTerrain(int16_t tiletype)
186+
bool isOpenTerrain(df::tiletype tiletype)
334187
{
335-
return tileTypeTable[tiletype].shape == EMPTY;
188+
return tiletype_shape::get_basic_shape(tiletype::get_shape(tiletype)) == tiletype_shape_basic::Open;
336189
}
337190

338191
inline
339-
const char * tileName(int16_t tiletype)
192+
bool isStairTerrain(df::tiletype tiletype)
340193
{
341-
return tileTypeTable[tiletype].name;
194+
return tiletype_shape::get_basic_shape(tiletype::get_shape(tiletype)) == tiletype_shape_basic::Stair;
342195
}
343196

344197
inline
345-
TileShape tileShape(int16_t tiletype)
198+
const char * tileName(df::tiletype tiletype)
346199
{
347-
return tileTypeTable[tiletype].shape;
200+
return tiletype::get_caption(tiletype);
348201
}
349202

350203
inline
351-
TileSpecial tileSpecial(int16_t tiletype)
204+
df::tiletype_shape tileShape(df::tiletype tiletype)
352205
{
353-
return tileTypeTable[tiletype].special;
206+
return tiletype::get_shape(tiletype);
354207
}
355208

356209
inline
357-
TileVariant tileVariant(int16_t tiletype)
210+
df::tiletype_special tileSpecial(df::tiletype tiletype)
358211
{
359-
return tileTypeTable[tiletype].variant;
212+
return tiletype::get_special(tiletype);
360213
}
361214

362215
inline
363-
TileMaterial tileMaterial(int16_t tiletype)
216+
df::tiletype_variant tileVariant(df::tiletype tiletype)
364217
{
365-
return tileTypeTable[tiletype].material;
218+
return tiletype::get_variant(tiletype);
366219
}
367220

368221
inline
369-
TileDirection tileDirection(int16_t tiletype)
222+
df::tiletype_material tileMaterial(df::tiletype tiletype)
370223
{
371-
return tileTypeTable[tiletype].direction;
224+
return tiletype::get_material(tiletype);
372225
}
373226

374-
/// Safely access the tile type array.
375-
inline const
376-
TileRow * getTileRow(int16_t tiletype)
227+
inline
228+
TileDirection tileDirection(df::tiletype tiletype)
377229
{
378-
if( tiletype<0 || tiletype>=TILE_TYPE_ARRAY_LENGTH ) return 0;
379-
return ( const TileRow * ) &tileTypeTable[tiletype];
230+
return TileDirection(tiletype::get_direction(tiletype));
380231
}
381232

382233
/**
383234
* zilpin: Find the first tile entry which matches the given search criteria.
384235
* All parameters are optional.
385236
* To omit, use the 'invalid' enum for that type (e.g. tileclass_invalid, tilematerial_invalid, etc)
386237
* For tile directions, pass NULL to omit.
387-
* @return matching index in tileTypeTable, or -1 if none found.
238+
* @return matching index in tileTypeTable, or 0 if none found.
388239
*/
389240
inline
390-
int16_t findTileType( const TileShape tshape, const TileMaterial tmat, const TileVariant tvar, const TileSpecial tspecial, const TileDirection tdir )
241+
df::tiletype findTileType( const df::tiletype_shape tshape, const df::tiletype_material tmat, const df::tiletype_variant tvar, const df::tiletype_special tspecial, const TileDirection tdir )
391242
{
392-
int16_t tt;
393-
for(tt=0;tt<TILE_TYPE_ARRAY_LENGTH; ++tt)
243+
FOR_ENUM_ITEMS(tiletype, tt)
394244
{
395-
if( tshape>-1 && tshape != tileTypeTable[tt].shape ) continue;
396-
if( tmat>-1 && tmat != tileTypeTable[tt].material ) continue;
397-
if( tvar>-1 && tvar != tileTypeTable[tt].variant ) continue;
398-
if( tspecial>-1 && tspecial != tileTypeTable[tt].special ) continue;
399-
if( tdir.whole && tdir.whole != tileTypeTable[tt].direction.whole ) continue;
400-
//Match!
245+
if (tshape != tiletype_shape::NONE && tshape != tileShape(tt)) continue;
246+
if (tmat != tiletype_material::NONE && tmat != tileMaterial(tt)) continue;
247+
if (tvar != tiletype_variant::NONE && tvar != tileVariant(tt)) continue;
248+
if (tspecial != tiletype_special::NONE && tspecial != tileSpecial(tt)) continue;
249+
if (tdir && tdir != tileDirection(tt)) continue;
250+
// Match!
401251
return tt;
402252
}
403-
return -1;
253+
return tiletype::Void;
404254
}
405255

406256
/**
@@ -410,9 +260,13 @@ namespace DFHack
410260
*
411261
* @todo Definitely needs improvement for wall directions, etc.
412262
*/
413-
DFHACK_EXPORT int16_t findSimilarTileType( const int16_t sourceTileType, const TileShape tshape );
414-
}
415-
263+
DFHACK_EXPORT df::tiletype findSimilarTileType( const df::tiletype sourceTileType, const df::tiletype_shape tshape );
416264

265+
/**
266+
* Finds a random variant of the selected tile
267+
* If there are no variants, returns the same tile
268+
*/
269+
DFHACK_EXPORT df::tiletype findRandomVariant(const df::tiletype tile);
270+
}
417271

418272
#endif // TILETYPES_H_INCLUDED

0 commit comments

Comments
 (0)