2011-06-16 15:53:39 -06:00
|
|
|
/*
|
|
|
|
https://github.com/peterix/dfhack
|
|
|
|
Copyright (c) 2009-2011 Petr Mrázek (peterix@gmail.com)
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2010-04-06 05:05:54 -06:00
|
|
|
/*******************************************************************************
|
|
|
|
M A P S
|
|
|
|
Read and write DF's map
|
|
|
|
*******************************************************************************/
|
2011-04-10 05:12:28 -06:00
|
|
|
#pragma once
|
2010-04-04 16:48:19 -06:00
|
|
|
#ifndef CL_MOD_MAPS
|
|
|
|
#define CL_MOD_MAPS
|
|
|
|
|
2011-12-31 04:48:42 -07:00
|
|
|
#include "Export.h"
|
|
|
|
#include "Module.h"
|
|
|
|
#include "modules/Vegetation.h"
|
2011-07-06 03:13:36 -06:00
|
|
|
#include <vector>
|
2011-12-31 04:48:42 -07:00
|
|
|
#include "BitArray.h"
|
2012-01-19 13:11:52 -07:00
|
|
|
#include "modules/Materials.h"
|
|
|
|
|
|
|
|
#include "df/world.h"
|
2012-04-11 09:42:05 -06:00
|
|
|
#include "df/world_data.h"
|
2012-01-19 13:11:52 -07:00
|
|
|
#include "df/map_block.h"
|
|
|
|
#include "df/block_square_event.h"
|
|
|
|
#include "df/block_square_event_mineralst.h"
|
|
|
|
#include "df/block_square_event_frozen_liquidst.h"
|
|
|
|
#include "df/block_square_event_world_constructionst.h"
|
|
|
|
#include "df/block_square_event_material_spatterst.h"
|
|
|
|
#include "df/block_square_event_grassst.h"
|
|
|
|
#include "df/tile_liquid.h"
|
|
|
|
#include "df/tile_dig_designation.h"
|
|
|
|
#include "df/tile_traffic.h"
|
2012-04-11 09:42:05 -06:00
|
|
|
#include "df/feature_init.h"
|
2011-03-18 04:09:26 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \defgroup grp_maps Maps module and its types
|
|
|
|
* @ingroup grp_modules
|
|
|
|
*/
|
|
|
|
|
2012-04-11 09:42:05 -06:00
|
|
|
namespace df
|
|
|
|
{
|
|
|
|
struct burrow;
|
|
|
|
struct world_data;
|
|
|
|
struct block_burrow;
|
|
|
|
}
|
|
|
|
|
2010-04-04 16:48:19 -06:00
|
|
|
namespace DFHack
|
|
|
|
{
|
2012-01-19 20:44:17 -07:00
|
|
|
/***************************************************************************
|
|
|
|
T Y P E S
|
|
|
|
***************************************************************************/
|
|
|
|
/**
|
|
|
|
* Function for translating feature index to its name
|
|
|
|
* \ingroup grp_maps
|
|
|
|
*/
|
|
|
|
extern DFHACK_EXPORT const char * sa_feature(df::feature_type index);
|
|
|
|
|
2012-01-20 03:28:00 -07:00
|
|
|
typedef df::coord DFCoord;
|
2012-01-19 20:44:17 -07:00
|
|
|
typedef DFCoord planecoord;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A local or global map feature
|
|
|
|
* \ingroup grp_maps
|
|
|
|
*/
|
|
|
|
struct t_feature
|
|
|
|
{
|
|
|
|
df::feature_type type;
|
|
|
|
/// main material type - decides between stuff like bodily fluids, inorganics, vomit, amber, etc.
|
|
|
|
int16_t main_material;
|
|
|
|
/// generally some index to a vector of material types.
|
|
|
|
int32_t sub_material;
|
|
|
|
/// placeholder
|
|
|
|
bool discovered;
|
|
|
|
/// this is NOT part of the DF feature, but an address of the feature as seen by DFhack.
|
2012-01-28 13:12:41 -07:00
|
|
|
df::feature_init * origin;
|
2012-01-19 20:44:17 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \ingroup grp_maps
|
|
|
|
*/
|
|
|
|
enum BiomeOffset
|
|
|
|
{
|
|
|
|
eNorthWest,
|
|
|
|
eNorth,
|
|
|
|
eNorthEast,
|
|
|
|
eWest,
|
|
|
|
eHere,
|
|
|
|
eEast,
|
|
|
|
eSouthWest,
|
|
|
|
eSouth,
|
|
|
|
eSouthEast,
|
|
|
|
eBiomeCount
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* map block flags wrapper
|
|
|
|
* \ingroup grp_maps
|
|
|
|
*/
|
2012-04-10 08:21:19 -06:00
|
|
|
typedef df::block_flags t_blockflags;
|
2012-01-19 20:44:17 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 16x16 array of tile types
|
|
|
|
* \ingroup grp_maps
|
|
|
|
*/
|
2012-02-13 15:56:33 -07:00
|
|
|
typedef df::tiletype tiletypes40d [16][16];
|
2012-01-19 20:44:17 -07:00
|
|
|
/**
|
|
|
|
* 16x16 array used for squashed block materials
|
|
|
|
* \ingroup grp_maps
|
|
|
|
*/
|
|
|
|
typedef int16_t t_blockmaterials [16][16];
|
|
|
|
/**
|
|
|
|
* 16x16 array of designation flags
|
|
|
|
* \ingroup grp_maps
|
|
|
|
*/
|
2012-01-26 21:54:26 -07:00
|
|
|
typedef df::tile_designation t_designation;
|
2012-01-28 12:54:59 -07:00
|
|
|
typedef t_designation designations40d [16][16];
|
2012-01-19 20:44:17 -07:00
|
|
|
/**
|
|
|
|
* 16x16 array of occupancy flags
|
|
|
|
* \ingroup grp_maps
|
|
|
|
*/
|
2012-01-26 21:54:26 -07:00
|
|
|
typedef df::tile_occupancy t_occupancy;
|
2012-01-28 12:54:59 -07:00
|
|
|
typedef t_occupancy occupancies40d [16][16];
|
2012-01-19 20:44:17 -07:00
|
|
|
/**
|
|
|
|
* array of 16 biome indexes valid for the block
|
|
|
|
* \ingroup grp_maps
|
|
|
|
*/
|
|
|
|
typedef uint8_t biome_indices40d [9];
|
|
|
|
/**
|
|
|
|
* 16x16 array of temperatures
|
|
|
|
* \ingroup grp_maps
|
|
|
|
*/
|
|
|
|
typedef uint16_t t_temperatures [16][16];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Maps module
|
|
|
|
* \ingroup grp_modules
|
|
|
|
* \ingroup grp_maps
|
|
|
|
*/
|
|
|
|
namespace Maps
|
|
|
|
{
|
|
|
|
|
|
|
|
extern DFHACK_EXPORT bool IsValid();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Method for reading the geological surrounding of the currently loaded region.
|
|
|
|
* assign is a reference to an array of nine vectors of unsigned words that are to be filled with the data
|
|
|
|
* array is indexed by the BiomeOffset enum
|
|
|
|
*
|
|
|
|
* I omitted resolving the layer matgloss in this API, because it would
|
|
|
|
* introduce overhead by calling some method for each tile. You have to do it
|
|
|
|
* yourself.
|
|
|
|
*
|
|
|
|
* First get the stuff from ReadGeology and then for each block get the RegionOffsets.
|
|
|
|
* For each tile get the real region from RegionOffsets and cross-reference it with
|
|
|
|
* the geology stuff (region -- array of vectors, depth -- vector).
|
|
|
|
* I'm thinking about turning that Geology stuff into a two-dimensional array
|
|
|
|
* with static size.
|
|
|
|
*
|
|
|
|
* this is the algorithm for applying matgloss:
|
|
|
|
* @code
|
|
|
|
|
|
|
|
void DfMap::applyGeoMatgloss(Block * b)
|
|
|
|
{
|
|
|
|
// load layer matgloss
|
|
|
|
for(int x_b = 0; x_b < BLOCK_SIZE; x_b++)
|
|
|
|
{
|
|
|
|
for(int y_b = 0; y_b < BLOCK_SIZE; y_b++)
|
|
|
|
{
|
|
|
|
int geolayer = b->designation[x_b][y_b].bits.geolayer_index;
|
|
|
|
int biome = b->designation[x_b][y_b].bits.biome;
|
|
|
|
b->material[x_b][y_b].type = Mat_Stone;
|
|
|
|
b->material[x_b][y_b].index = v_geology[b->RegionOffsets[biome]][geolayer];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
* @endcode
|
|
|
|
*/
|
2012-04-10 08:21:19 -06:00
|
|
|
extern DFHACK_EXPORT bool ReadGeology(std::vector<std::vector<int16_t> > *layer_mats,
|
2012-04-11 02:01:27 -06:00
|
|
|
std::vector<df::coord2d> *geoidx);
|
2012-01-19 20:44:17 -07:00
|
|
|
/**
|
|
|
|
* Get pointers to features of a block
|
|
|
|
*/
|
|
|
|
extern DFHACK_EXPORT bool ReadFeatures(uint32_t x, uint32_t y, uint32_t z, t_feature * local, t_feature * global);
|
|
|
|
/**
|
|
|
|
* Get pointers to features of an already read block
|
|
|
|
*/
|
2012-04-10 08:21:19 -06:00
|
|
|
extern DFHACK_EXPORT bool ReadFeatures(df::map_block * block,t_feature * local, t_feature * global);
|
2012-01-19 20:44:17 -07:00
|
|
|
|
2012-04-11 02:01:27 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a pointer to a specific global feature directly.
|
|
|
|
*/
|
|
|
|
DFHACK_EXPORT df::feature_init *getGlobalInitFeature(int32_t index);
|
|
|
|
/**
|
|
|
|
* Get a pointer to a specific local feature directly. rgn_coord is in the world region grid.
|
|
|
|
*/
|
|
|
|
DFHACK_EXPORT df::feature_init *getLocalInitFeature(df::coord2d rgn_coord, int32_t index);
|
|
|
|
|
2012-01-19 20:44:17 -07:00
|
|
|
/**
|
|
|
|
* Read a specific global or local feature directly
|
|
|
|
*/
|
|
|
|
extern DFHACK_EXPORT bool GetGlobalFeature(t_feature &feature, int32_t index);
|
2012-04-11 02:01:27 -06:00
|
|
|
//extern DFHACK_EXPORT bool GetLocalFeature(t_feature &feature, df::coord2d rgn_coord, int32_t index);
|
|
|
|
|
2012-01-19 20:44:17 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* BLOCK DATA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/// get size of the map in tiles
|
|
|
|
extern DFHACK_EXPORT void getSize(uint32_t& x, uint32_t& y, uint32_t& z);
|
|
|
|
/// get the position of the map on world map
|
|
|
|
extern DFHACK_EXPORT void getPosition(int32_t& x, int32_t& y, int32_t& z);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the map block or NULL if block is not valid
|
|
|
|
*/
|
|
|
|
extern DFHACK_EXPORT df::map_block * getBlock (int32_t blockx, int32_t blocky, int32_t blockz);
|
2012-04-11 02:01:27 -06:00
|
|
|
extern DFHACK_EXPORT df::map_block * getTileBlock (int32_t x, int32_t y, int32_t z);
|
2012-01-19 20:44:17 -07:00
|
|
|
|
2012-03-07 07:10:53 -07:00
|
|
|
inline df::map_block * getBlock (df::coord pos) { return getBlock(pos.x, pos.y, pos.z); }
|
2012-04-11 02:01:27 -06:00
|
|
|
inline df::map_block * getTileBlock (df::coord pos) { return getTileBlock(pos.x, pos.y, pos.z); }
|
2012-03-07 07:10:53 -07:00
|
|
|
|
2012-04-11 02:01:27 -06:00
|
|
|
DFHACK_EXPORT df::world_data::T_region_map *getRegionBiome(df::coord2d rgn_pos);
|
2012-01-19 20:44:17 -07:00
|
|
|
|
|
|
|
/// sorts the block event vector into multiple vectors by type
|
|
|
|
/// mineral veins, what's under ice, blood smears and mud
|
2012-04-10 08:21:19 -06:00
|
|
|
extern DFHACK_EXPORT bool SortBlockEvents(df::map_block *block,
|
2012-01-19 20:44:17 -07:00
|
|
|
std::vector<df::block_square_event_mineralst *>* veins,
|
|
|
|
std::vector<df::block_square_event_frozen_liquidst *>* ices = 0,
|
|
|
|
std::vector<df::block_square_event_material_spatterst *>* splatter = 0,
|
|
|
|
std::vector<df::block_square_event_grassst *>* grass = 0,
|
|
|
|
std::vector<df::block_square_event_world_constructionst *>* constructions = 0
|
|
|
|
);
|
|
|
|
|
|
|
|
/// remove a block event from the block by address
|
|
|
|
extern DFHACK_EXPORT bool RemoveBlockEvent(uint32_t x, uint32_t y, uint32_t z, df::block_square_event * which );
|
|
|
|
|
2012-04-11 09:42:05 -06:00
|
|
|
/*
|
|
|
|
* BURROWS
|
|
|
|
*/
|
|
|
|
|
|
|
|
DFHACK_EXPORT df::burrow *findBurrowByName(std::string name);
|
|
|
|
|
2012-04-13 11:41:42 -06:00
|
|
|
DFHACK_EXPORT void listBurrowBlocks(std::vector<df::map_block*> *pvec, df::burrow *burrow);
|
2012-04-14 04:12:59 -06:00
|
|
|
DFHACK_EXPORT void clearBurrowTiles(df::burrow *burrow);
|
2012-04-11 09:42:05 -06:00
|
|
|
|
2012-04-13 11:41:42 -06:00
|
|
|
DFHACK_EXPORT df::block_burrow *getBlockBurrowMask(df::burrow *burrow, df::map_block *block, bool create = false);
|
2012-04-14 04:12:59 -06:00
|
|
|
DFHACK_EXPORT bool deleteBlockBurrowMask(df::burrow *burrow, df::map_block *block, df::block_burrow *mask);
|
|
|
|
|
|
|
|
inline bool deleteBlockBurrowMask(df::burrow *burrow, df::map_block *block)
|
|
|
|
{
|
|
|
|
return deleteBlockBurrowMask(burrow, block, getBlockBurrowMask(burrow, block));
|
|
|
|
}
|
|
|
|
|
2012-04-11 09:42:05 -06:00
|
|
|
|
2012-04-13 11:41:42 -06:00
|
|
|
DFHACK_EXPORT bool isBlockBurrowTile(df::burrow *burrow, df::map_block *block, df::coord2d tile);
|
|
|
|
DFHACK_EXPORT bool setBlockBurrowTile(df::burrow *burrow, df::map_block *block, df::coord2d tile, bool enable);
|
2012-04-11 09:42:05 -06:00
|
|
|
|
|
|
|
inline bool isBurrowTile(df::burrow *burrow, df::coord tile) {
|
|
|
|
return isBlockBurrowTile(burrow, getTileBlock(tile), tile);
|
|
|
|
}
|
|
|
|
inline bool setBurrowTile(df::burrow *burrow, df::coord tile, bool enable) {
|
|
|
|
return setBlockBurrowTile(burrow, getTileBlock(tile), tile, enable);
|
|
|
|
}
|
|
|
|
|
2012-01-19 20:44:17 -07:00
|
|
|
}
|
2010-04-04 16:48:19 -06:00
|
|
|
}
|
2010-04-28 10:21:52 -06:00
|
|
|
#endif
|