2010-11-17 12:50:50 -07:00
|
|
|
/*
|
2011-06-16 15:53:39 -06:00
|
|
|
https://github.com/peterix/dfhack
|
|
|
|
Copyright (c) 2009-2011 Petr Mrázek (peterix@gmail.com)
|
2010-11-17 12:50:50 -07:00
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied
|
|
|
|
warranty. In no event will the authors be held liable for any
|
|
|
|
damages arising from the use of this software.
|
|
|
|
|
|
|
|
Permission is granted to anyone to use this software for any
|
|
|
|
purpose, including commercial applications, and to alter it and
|
|
|
|
redistribute it freely, subject to the following restrictions:
|
|
|
|
|
|
|
|
1. The origin of this software must not be misrepresented; you must
|
|
|
|
not claim that you wrote the original software. If you use this
|
|
|
|
software in a product, an acknowledgment in the product documentation
|
|
|
|
would be appreciated but is not required.
|
|
|
|
|
|
|
|
2. Altered source versions must be plainly marked as such, and
|
|
|
|
must not be misrepresented as being the original software.
|
|
|
|
|
|
|
|
3. This notice may not be removed or altered from any source
|
|
|
|
distribution.
|
|
|
|
*/
|
|
|
|
|
2011-04-10 05:12:28 -06:00
|
|
|
#pragma once
|
|
|
|
|
2010-11-17 12:50:50 -07:00
|
|
|
#ifndef TILETYPES_H_INCLUDED
|
|
|
|
#define TILETYPES_H_INCLUDED
|
|
|
|
|
2011-12-31 04:48:42 -07:00
|
|
|
#include "Pragma.h"
|
|
|
|
#include "Export.h"
|
2010-11-17 12:50:50 -07:00
|
|
|
|
|
|
|
namespace DFHack
|
|
|
|
{
|
|
|
|
|
|
|
|
// tile class -- determines the general shape of the tile
|
|
|
|
// enum and lookup table for string names created using X macros
|
2011-04-17 05:06:19 -06:00
|
|
|
#define TILESHAPE_MACRO \
|
2011-04-28 15:00:52 -06:00
|
|
|
X(EMPTY, "") \
|
|
|
|
X(WALL, "") \
|
|
|
|
X(PILLAR, "") \
|
|
|
|
X(BROOK_BED, "mineable, water-passable rock on the bottom of brook") \
|
|
|
|
X(FORTIFICATION, "") \
|
|
|
|
X(STAIR_UP, "") \
|
|
|
|
X(STAIR_DOWN, "") \
|
|
|
|
X(STAIR_UPDOWN, "") \
|
|
|
|
X(RAMP, "ramps have no direction" ) \
|
|
|
|
X(RAMP_TOP, "used for pathing?" ) \
|
|
|
|
X(FLOOR, "") \
|
|
|
|
X(BROOK_TOP, "water-passable floor on top of BROOK_BED tiles") \
|
2012-01-26 09:38:18 -07:00
|
|
|
X(RIVER_BED, "It's a riverbed. Basically a floor that doesn't get muddy.") \
|
2011-04-28 15:00:52 -06:00
|
|
|
X(POOL, "A pool. Gathers water while it's raining.'") \
|
|
|
|
X(TREE_DEAD, "") \
|
|
|
|
X(TREE_OK, "") \
|
|
|
|
X(SAPLING_DEAD, "") \
|
|
|
|
X(SAPLING_OK, "") \
|
|
|
|
X(SHRUB_DEAD, "") \
|
|
|
|
X(SHRUB_OK, "") \
|
|
|
|
X(BOULDER, "") \
|
|
|
|
X(PEBBLES, "") \
|
|
|
|
X(ENDLESS_PIT, "a fake endless pit")
|
2011-04-17 05:06:19 -06:00
|
|
|
//end TILESHAPE_MACRO
|
2010-11-17 12:50:50 -07:00
|
|
|
|
|
|
|
//define tile class enum
|
|
|
|
#define X(name,comment) name,
|
2011-04-17 05:06:19 -06:00
|
|
|
enum TileShape {
|
|
|
|
tileshape_invalid=-1,
|
|
|
|
TILESHAPE_MACRO
|
|
|
|
tileshape_count,
|
2010-11-17 12:50:50 -07:00
|
|
|
};
|
|
|
|
#undef X
|
|
|
|
|
2011-04-17 05:06:19 -06:00
|
|
|
DFHACK_EXPORT extern const char *TileShapeString[];
|
2010-11-17 12:50:50 -07:00
|
|
|
|
|
|
|
#define TILEMATERIAL_MACRO \
|
|
|
|
X(AIR, "empty" ) \
|
|
|
|
X(SOIL, "ordinary soil. material depends on geology" ) \
|
|
|
|
X(STONE, "ordinary layer stone. material depends on geology" ) \
|
|
|
|
X(FEATSTONE, "map special stone. used for things like hell, the hell temple or adamantine tubes. material depends on local/global special" ) \
|
2012-01-26 09:38:18 -07:00
|
|
|
X(OBSIDIAN, "lava stone created by mixing magma and water" ) \
|
2010-11-17 12:50:50 -07:00
|
|
|
X(VEIN, "vein stone. material depends on mineral veins present" ) \
|
|
|
|
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" ) \
|
2012-01-26 09:38:18 -07:00
|
|
|
X(GRASS, "light grass (has 4 variants)" ) \
|
|
|
|
X(GRASS2, "dark grass (has 4 variants)" ) \
|
2010-11-17 12:50:50 -07:00
|
|
|
X(GRASS_DEAD, "dead grass (has 4 variants)" ) \
|
|
|
|
X(GRASS_DRY, "dry grass (has 4 variants)" ) \
|
2012-01-26 09:38:18 -07:00
|
|
|
X(DRIFTWOOD, "driftwood. normally shows up on beaches" ) \
|
2010-11-17 12:50:50 -07:00
|
|
|
X(HFS, "the stuff demon pits are made of - this makes them different from ordinary pits." ) \
|
|
|
|
X(MAGMA, "material for semi-molten rock and 'magma flow' tiles" ) \
|
|
|
|
X(CAMPFIRE, "human armies make them when they siege. The original tile may be lost?" ) \
|
|
|
|
X(FIRE, "burning grass" ) \
|
|
|
|
X(ASHES, "what remains from a FIRE" ) \
|
|
|
|
X(CONSTRUCTED,"tile material depends on the construction present" ) \
|
|
|
|
X(CYAN_GLOW, "the glowy stuff that disappears from the demon temple when you take the sword." )
|
|
|
|
//end TILEMATERIAL_MACRO
|
|
|
|
|
|
|
|
// material enum
|
|
|
|
#define X(name,comment) name,
|
|
|
|
enum TileMaterial {
|
|
|
|
tilematerial_invalid=-1,
|
|
|
|
TILEMATERIAL_MACRO
|
|
|
|
tilematerial_count,
|
|
|
|
};
|
|
|
|
#undef X
|
|
|
|
|
|
|
|
|
2010-11-18 18:40:38 -07:00
|
|
|
DFHACK_EXPORT extern const char *TileMaterialString[];
|
2010-11-17 12:50:50 -07:00
|
|
|
|
|
|
|
// Special specials of the tile.
|
|
|
|
// Not the best way to do this, but compatible with existing code.
|
|
|
|
// When the TileType class gets created, everything should be re-thought.
|
|
|
|
#define TILESPECIAL_MACRO \
|
|
|
|
X(NORMAL, "Default for all type, nothing present" ) \
|
2012-01-26 09:38:18 -07:00
|
|
|
X(RIVER_SOURCE, "River Source, when it exists on a map" ) \
|
|
|
|
X(WATERFALL, "Waterfall from Nowhere, used by cave rivers back in 40d" ) \
|
|
|
|
X(CRACKED, "Partially (75%) mined walls" ) \
|
|
|
|
X(DAMAGED, "Partially (50%) mined walls" ) \
|
|
|
|
X(WORN, "Partially (25%) mined walls" ) \
|
2010-11-17 12:50:50 -07:00
|
|
|
X(SMOOTH, "Walls and floors." )
|
|
|
|
//end TILESPECIAL_MACRO
|
|
|
|
|
|
|
|
//special enum
|
|
|
|
#define X(name,comment) TILE_##name,
|
|
|
|
enum TileSpecial {
|
|
|
|
tilespecial_invalid=-1,
|
|
|
|
TILESPECIAL_MACRO
|
|
|
|
tilespecial_count,
|
|
|
|
};
|
|
|
|
#undef X
|
|
|
|
|
2010-11-18 18:40:38 -07:00
|
|
|
DFHACK_EXPORT extern const char *TileSpecialString[];
|
2010-11-17 12:50:50 -07:00
|
|
|
|
|
|
|
// variants are used for tiles, where there are multiple variants of the same - like grass floors
|
|
|
|
enum TileVariant
|
|
|
|
{
|
|
|
|
tilevariant_invalid=-1,
|
|
|
|
VAR_1, //Yes, the value of VAR_1 is 0. It's legacy. Deal with it.
|
|
|
|
VAR_2,
|
|
|
|
VAR_3,
|
|
|
|
VAR_4,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//Mainly walls and rivers
|
|
|
|
//Byte values are used because walls can have either 1 or 2 in any given direction.
|
|
|
|
const int TileDirectionCount = 4;
|
|
|
|
union TileDirection
|
|
|
|
{
|
|
|
|
uint32_t whole;
|
|
|
|
unsigned char b[TileDirectionCount];
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
//Maybe should add 'up' and 'down' for Z-levels?
|
|
|
|
unsigned char north,south,west,east;
|
|
|
|
};
|
|
|
|
|
|
|
|
inline TileDirection()
|
|
|
|
{
|
|
|
|
whole = 0;
|
|
|
|
}
|
|
|
|
TileDirection( uint32_t whole_bits)
|
|
|
|
{
|
|
|
|
whole = whole_bits;
|
|
|
|
}
|
|
|
|
TileDirection( unsigned char North, unsigned char South, unsigned char West, unsigned char East )
|
|
|
|
{
|
|
|
|
north=North; south=South; east=East; west=West;
|
|
|
|
}
|
|
|
|
TileDirection( const char *dir )
|
|
|
|
{
|
|
|
|
//This one just made for fun.
|
|
|
|
//Supports N S E W
|
|
|
|
const char *p = dir;
|
|
|
|
unsigned char *l=0;
|
|
|
|
north=south=east=west=0;
|
|
|
|
if(!dir) return;
|
|
|
|
|
|
|
|
for( ;*p;++p)
|
|
|
|
{
|
|
|
|
switch(*p)
|
|
|
|
{
|
|
|
|
case 'N': //North / Up
|
|
|
|
case 'n':
|
|
|
|
++north; l=&north; break;
|
|
|
|
case 'S': //South / Down
|
|
|
|
case 's':
|
|
|
|
++south; l=&south; break;
|
|
|
|
case 'E': //East / Right
|
|
|
|
case 'e':
|
|
|
|
++east; l=&east; break;
|
|
|
|
case 'W': //West / Left
|
|
|
|
case 'w':
|
|
|
|
++west; l=&west; break;
|
|
|
|
case '-':
|
|
|
|
case ' ':
|
|
|
|
//Explicitly ensure dash and space are ignored.
|
|
|
|
//Other characters/symbols may be assigned in the future.
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if( l && '0' <= *p && '9' >= *p )
|
|
|
|
*l += *p - '0';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//may be useful for some situations
|
|
|
|
inline uint32_t sum() const
|
|
|
|
{
|
|
|
|
return 0L + north + south + east + west;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Gives a string that represents the direction.
|
|
|
|
//This is a static string, overwritten with every call!
|
|
|
|
//Support values > 2 even though they should never happen.
|
|
|
|
//Copy string if it will be used.
|
|
|
|
inline char * getStr() const
|
|
|
|
{
|
|
|
|
static char str[16];
|
|
|
|
//type punning trick
|
|
|
|
*( (uint64_t *)str ) = *( (uint64_t *)"--------" );
|
|
|
|
str[8]=0;
|
|
|
|
#define DIRECTION(x,i,c) \
|
|
|
|
if(x){ \
|
|
|
|
str[i]=c; \
|
|
|
|
if(1==x) ; \
|
|
|
|
else if(2==x) str[i+1]=c; \
|
|
|
|
else str[i+1]='0'+x; \
|
|
|
|
}
|
|
|
|
|
|
|
|
DIRECTION(north,0,'N')
|
|
|
|
DIRECTION(south,2,'S')
|
|
|
|
DIRECTION(west,4,'W')
|
|
|
|
DIRECTION(east,6,'E')
|
|
|
|
#undef DIRECTION
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
struct TileRow
|
|
|
|
{
|
|
|
|
const char * name;
|
2011-04-17 05:06:19 -06:00
|
|
|
TileShape shape;
|
2011-04-17 03:37:36 -06:00
|
|
|
TileMaterial material;
|
|
|
|
TileVariant variant;
|
|
|
|
TileSpecial special;
|
|
|
|
TileDirection direction;
|
2010-11-17 12:50:50 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#define TILE_TYPE_ARRAY_LENGTH 520
|
|
|
|
|
2011-04-17 05:06:19 -06:00
|
|
|
extern DFHACK_EXPORT const TileRow tileTypeTable[];
|
2010-11-17 12:50:50 -07:00
|
|
|
|
2011-03-10 19:09:45 -07:00
|
|
|
// tile is missing a floor
|
|
|
|
inline
|
2012-01-26 09:38:18 -07:00
|
|
|
bool LowPassable(int16_t tiletype)
|
2011-03-10 19:09:45 -07:00
|
|
|
{
|
2011-04-17 03:37:36 -06:00
|
|
|
switch(DFHack::tileTypeTable[tiletype].shape)
|
2011-03-10 19:09:45 -07:00
|
|
|
{
|
|
|
|
case DFHack::EMPTY:
|
|
|
|
case DFHack::STAIR_DOWN:
|
|
|
|
case DFHack::STAIR_UPDOWN:
|
|
|
|
case DFHack::RAMP_TOP:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// tile is missing a roof
|
|
|
|
inline
|
2012-01-26 09:38:18 -07:00
|
|
|
bool HighPassable(int16_t tiletype)
|
2011-03-10 19:09:45 -07:00
|
|
|
{
|
2011-04-17 03:37:36 -06:00
|
|
|
switch(DFHack::tileTypeTable[tiletype].shape)
|
2011-03-10 19:09:45 -07:00
|
|
|
{
|
|
|
|
case DFHack::EMPTY:
|
|
|
|
case DFHack::STAIR_DOWN:
|
|
|
|
case DFHack::STAIR_UPDOWN:
|
|
|
|
case DFHack::STAIR_UP:
|
|
|
|
case DFHack::RAMP:
|
|
|
|
case DFHack::RAMP_TOP:
|
|
|
|
case DFHack::FLOOR:
|
|
|
|
case DFHack::SAPLING_DEAD:
|
|
|
|
case DFHack::SAPLING_OK:
|
|
|
|
case DFHack::SHRUB_DEAD:
|
|
|
|
case DFHack::SHRUB_OK:
|
|
|
|
case DFHack::BOULDER:
|
|
|
|
case DFHack::PEBBLES:
|
2011-04-28 15:00:52 -06:00
|
|
|
case DFHack::RIVER_BED:
|
|
|
|
case DFHack::POOL:
|
|
|
|
case DFHack::ENDLESS_PIT:
|
|
|
|
case DFHack::BROOK_TOP:
|
2011-03-10 19:09:45 -07:00
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
inline
|
2012-01-26 09:38:18 -07:00
|
|
|
bool FlowPassable(int16_t tiletype)
|
2011-03-10 19:09:45 -07:00
|
|
|
{
|
2011-04-17 05:06:19 -06:00
|
|
|
TileShape tc = tileTypeTable[tiletype].shape;
|
2011-03-10 19:09:45 -07:00
|
|
|
return tc != WALL && tc != PILLAR && tc != TREE_DEAD && tc != TREE_OK;
|
|
|
|
};
|
2010-11-17 12:50:50 -07:00
|
|
|
|
|
|
|
inline
|
2012-01-26 09:38:18 -07:00
|
|
|
bool isWallTerrain(int16_t tiletype)
|
2011-04-17 05:06:19 -06:00
|
|
|
{
|
|
|
|
return tileTypeTable[tiletype].shape >= WALL && tileTypeTable[tiletype].shape <= FORTIFICATION ;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
2012-01-26 09:38:18 -07:00
|
|
|
bool isFloorTerrain(int16_t tiletype)
|
2011-04-17 05:06:19 -06:00
|
|
|
{
|
|
|
|
return tileTypeTable[tiletype].shape >= FLOOR && tileTypeTable[tiletype].shape <= PEBBLES;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
2012-01-26 09:38:18 -07:00
|
|
|
bool isRampTerrain(int16_t tiletype)
|
2011-04-17 05:06:19 -06:00
|
|
|
{
|
|
|
|
return tileTypeTable[tiletype].shape == RAMP;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
2012-01-26 09:38:18 -07:00
|
|
|
bool isStairTerrain(int16_t tiletype)
|
2011-04-17 05:06:19 -06:00
|
|
|
{
|
|
|
|
return tileTypeTable[tiletype].shape >= STAIR_UP && tileTypeTable[tiletype].shape <= STAIR_UPDOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
2012-01-26 09:38:18 -07:00
|
|
|
bool isOpenTerrain(int16_t tiletype)
|
2011-04-17 05:06:19 -06:00
|
|
|
{
|
|
|
|
return tileTypeTable[tiletype].shape == EMPTY;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
2012-01-26 09:38:18 -07:00
|
|
|
const char * tileName(int16_t tiletype)
|
2010-11-17 12:50:50 -07:00
|
|
|
{
|
2011-04-17 05:06:19 -06:00
|
|
|
return tileTypeTable[tiletype].name;
|
2010-11-17 12:50:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
2012-01-26 09:38:18 -07:00
|
|
|
TileShape tileShape(int16_t tiletype)
|
2010-11-17 12:50:50 -07:00
|
|
|
{
|
2011-04-17 05:06:19 -06:00
|
|
|
return tileTypeTable[tiletype].shape;
|
2010-11-17 12:50:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
2012-01-26 09:38:18 -07:00
|
|
|
TileSpecial tileSpecial(int16_t tiletype)
|
2010-11-17 12:50:50 -07:00
|
|
|
{
|
2011-04-17 05:06:19 -06:00
|
|
|
return tileTypeTable[tiletype].special;
|
2010-11-17 12:50:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
2012-01-26 09:38:18 -07:00
|
|
|
TileVariant tileVariant(int16_t tiletype)
|
2010-11-17 12:50:50 -07:00
|
|
|
{
|
2011-04-17 05:06:19 -06:00
|
|
|
return tileTypeTable[tiletype].variant;
|
2010-11-17 12:50:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
2012-01-26 09:38:18 -07:00
|
|
|
TileMaterial tileMaterial(int16_t tiletype)
|
2010-11-17 12:50:50 -07:00
|
|
|
{
|
2011-04-17 05:06:19 -06:00
|
|
|
return tileTypeTable[tiletype].material;
|
2010-11-17 12:50:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
2012-01-26 09:38:18 -07:00
|
|
|
TileDirection tileDirection(int16_t tiletype)
|
2010-11-17 12:50:50 -07:00
|
|
|
{
|
2011-04-17 05:06:19 -06:00
|
|
|
return tileTypeTable[tiletype].direction;
|
2010-11-17 12:50:50 -07:00
|
|
|
}
|
|
|
|
|
2011-04-17 05:13:23 -06:00
|
|
|
/// Safely access the tile type array.
|
2010-11-17 12:50:50 -07:00
|
|
|
inline const
|
2012-01-26 09:38:18 -07:00
|
|
|
TileRow * getTileRow(int16_t tiletype)
|
2010-11-17 12:50:50 -07:00
|
|
|
{
|
2011-04-17 05:06:19 -06:00
|
|
|
if( tiletype<0 || tiletype>=TILE_TYPE_ARRAY_LENGTH ) return 0;
|
|
|
|
return ( const TileRow * ) &tileTypeTable[tiletype];
|
2010-11-17 12:50:50 -07:00
|
|
|
}
|
|
|
|
|
2011-04-17 05:06:19 -06:00
|
|
|
/**
|
|
|
|
* zilpin: Find the first tile entry which matches the given search criteria.
|
|
|
|
* All parameters are optional.
|
|
|
|
* To omit, use the 'invalid' enum for that type (e.g. tileclass_invalid, tilematerial_invalid, etc)
|
|
|
|
* For tile directions, pass NULL to omit.
|
|
|
|
* @return matching index in tileTypeTable, or -1 if none found.
|
|
|
|
*/
|
2010-11-17 12:50:50 -07:00
|
|
|
inline
|
2012-01-26 09:38:18 -07:00
|
|
|
int16_t findTileType( const TileShape tshape, const TileMaterial tmat, const TileVariant tvar, const TileSpecial tspecial, const TileDirection tdir )
|
2010-11-17 12:50:50 -07:00
|
|
|
{
|
2012-01-26 09:38:18 -07:00
|
|
|
int16_t tt;
|
2011-11-25 10:54:50 -07:00
|
|
|
for(tt=0;tt<TILE_TYPE_ARRAY_LENGTH; ++tt)
|
|
|
|
{
|
|
|
|
if( tshape>-1 && tshape != tileTypeTable[tt].shape ) continue;
|
|
|
|
if( tmat>-1 && tmat != tileTypeTable[tt].material ) continue;
|
|
|
|
if( tvar>-1 && tvar != tileTypeTable[tt].variant ) continue;
|
|
|
|
if( tspecial>-1 && tspecial != tileTypeTable[tt].special ) continue;
|
|
|
|
if( tdir.whole && tdir.whole != tileTypeTable[tt].direction.whole ) continue;
|
2010-11-17 12:50:50 -07:00
|
|
|
//Match!
|
|
|
|
return tt;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-04-17 05:06:19 -06:00
|
|
|
/**
|
|
|
|
* zilpin: Find a tile type similar to the one given, but with a different class.
|
|
|
|
* Useful for tile-editing operations.
|
|
|
|
* If no match found, returns the sourceType
|
|
|
|
*
|
|
|
|
* @todo Definitely needs improvement for wall directions, etc.
|
|
|
|
*/
|
2012-01-26 09:38:18 -07:00
|
|
|
DFHACK_EXPORT int16_t findSimilarTileType( const int16_t sourceTileType, const TileShape tshape );
|
2010-11-17 12:50:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif // TILETYPES_H_INCLUDED
|