2011-06-16 15:53:39 -06:00
|
|
|
/*
|
|
|
|
https://github.com/peterix/dfhack
|
2012-09-29 20:03:37 -06:00
|
|
|
Copyright (c) 2009-2012 Petr Mrázek (peterix@gmail.com)
|
2011-06-16 15:53:39 -06: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.
|
|
|
|
*/
|
|
|
|
|
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"
|
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"
|
|
|
|
|
2018-08-15 19:28:18 -06:00
|
|
|
#include "df/biome_type.h"
|
2016-08-13 19:44:01 -06:00
|
|
|
#include "df/block_flags.h"
|
|
|
|
#include "df/feature_type.h"
|
|
|
|
#include "df/flow_type.h"
|
2021-06-22 21:01:10 -06:00
|
|
|
#include "df/plant.h"
|
2012-01-19 13:11:52 -07:00
|
|
|
#include "df/tile_dig_designation.h"
|
2016-08-13 19:44:01 -06:00
|
|
|
#include "df/tile_liquid.h"
|
2012-01-19 13:11:52 -07:00
|
|
|
#include "df/tile_traffic.h"
|
2016-08-13 19:44:01 -06:00
|
|
|
#include "df/tiletype.h"
|
|
|
|
|
|
|
|
namespace df {
|
|
|
|
struct block_square_event;
|
2018-01-21 17:27:16 -07:00
|
|
|
struct block_square_event_designation_priorityst;
|
2016-08-13 19:44:01 -06:00
|
|
|
struct block_square_event_frozen_liquidst;
|
|
|
|
struct block_square_event_grassst;
|
|
|
|
struct block_square_event_item_spatterst;
|
|
|
|
struct block_square_event_material_spatterst;
|
|
|
|
struct block_square_event_mineralst;
|
|
|
|
struct block_square_event_spoorst;
|
|
|
|
struct block_square_event_world_constructionst;
|
|
|
|
struct feature_init;
|
|
|
|
struct map_block;
|
|
|
|
struct map_block_column;
|
|
|
|
struct region_map_entry;
|
|
|
|
struct world;
|
|
|
|
struct world_data;
|
|
|
|
struct world_geo_biome;
|
|
|
|
union tile_designation;
|
|
|
|
union tile_occupancy;
|
|
|
|
}
|
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];
|
|
|
|
|
2012-10-06 02:40:46 -06:00
|
|
|
/**
|
|
|
|
* Index a tile array by a 2D coordinate, clipping it to mod 16
|
|
|
|
*/
|
2018-06-18 06:49:27 -06:00
|
|
|
template<class T> inline auto index_tile(T &v, df::coord2d p)
|
|
|
|
-> typename std::add_rvalue_reference<decltype(v[0][0])>::type
|
|
|
|
{
|
2012-10-06 02:40:46 -06:00
|
|
|
return v[p.x&15][p.y&15];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a 2D coordinate is in the 0-15 range.
|
|
|
|
*/
|
|
|
|
inline bool is_valid_tile_coord(df::coord2d p) {
|
|
|
|
return (p.x & ~15) == 0 && (p.y & ~15) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-19 20:44:17 -07:00
|
|
|
/**
|
|
|
|
* 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
|
2015-02-14 20:53:06 -07:00
|
|
|
*
|
2012-01-19 20:44:17 -07:00
|
|
|
* 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
|
|
|
|
*/
|
2022-04-21 19:13:23 -06:00
|
|
|
extern DFHACK_EXPORT bool ReadFeatures(int32_t x, int32_t y, int32_t z, t_feature * local, t_feature * global);
|
|
|
|
extern DFHACK_EXPORT bool ReadFeatures(uint32_t x, uint32_t y, uint32_t z, t_feature * local, t_feature * global); // todo: deprecate me
|
2012-01-19 20:44:17 -07:00
|
|
|
/**
|
|
|
|
* 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.
|
2022-04-21 19:13:23 -06:00
|
|
|
*/
|
2012-04-11 02:01:27 -06:00
|
|
|
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
|
|
|
|
*/
|
|
|
|
|
2021-05-16 15:15:19 -06:00
|
|
|
/// get size of the map in blocks
|
2022-04-21 19:13:23 -06:00
|
|
|
extern DFHACK_EXPORT void getSize(int32_t& x, int32_t& y, int32_t& z);
|
|
|
|
extern DFHACK_EXPORT void getSize(uint32_t& x, uint32_t& y, uint32_t& z); // todo: deprecate me
|
2021-05-16 15:15:19 -06:00
|
|
|
/// get size of the map in tiles
|
2022-04-21 19:13:23 -06:00
|
|
|
extern DFHACK_EXPORT void getTileSize(int32_t& x, int32_t& y, int32_t& z);
|
|
|
|
extern DFHACK_EXPORT void getTileSize(uint32_t& x, uint32_t& y, uint32_t& z); // todo: deprecate me
|
2012-01-19 20:44:17 -07:00
|
|
|
/// get the position of the map on world map
|
|
|
|
extern DFHACK_EXPORT void getPosition(int32_t& x, int32_t& y, int32_t& z);
|
|
|
|
|
2012-09-02 04:10:58 -06:00
|
|
|
extern DFHACK_EXPORT bool isValidTilePos(int32_t x, int32_t y, int32_t z);
|
|
|
|
inline bool isValidTilePos(df::coord pos) { return isValidTilePos(pos.x, pos.y, pos.z); }
|
|
|
|
|
2017-06-10 19:54:08 -06:00
|
|
|
extern DFHACK_EXPORT bool isTileVisible(int32_t x, int32_t y, int32_t z);
|
|
|
|
inline bool isTileVisible(df::coord pos) { return isTileVisible(pos.x, pos.y, pos.z); }
|
|
|
|
|
2012-01-19 20:44:17 -07:00
|
|
|
/**
|
|
|
|
* 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-09-06 12:45:19 -06:00
|
|
|
extern DFHACK_EXPORT df::map_block * ensureTileBlock (int32_t x, int32_t y, int32_t z);
|
2012-01-19 20:44:17 -07:00
|
|
|
|
2014-07-20 05:11:20 -06:00
|
|
|
extern DFHACK_EXPORT df::map_block_column * getBlockColumn(int32_t blockx, int32_t blocky);
|
|
|
|
|
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-09-06 12:45:19 -06:00
|
|
|
inline df::map_block * ensureTileBlock (df::coord pos) { return ensureTileBlock(pos.x, pos.y, pos.z); }
|
2012-03-07 07:10:53 -07:00
|
|
|
|
2012-05-01 09:55:25 -06:00
|
|
|
extern DFHACK_EXPORT df::tiletype *getTileType(int32_t x, int32_t y, int32_t z);
|
|
|
|
extern DFHACK_EXPORT df::tile_designation *getTileDesignation(int32_t x, int32_t y, int32_t z);
|
|
|
|
extern DFHACK_EXPORT df::tile_occupancy *getTileOccupancy(int32_t x, int32_t y, int32_t z);
|
|
|
|
|
|
|
|
inline df::tiletype *getTileType(df::coord pos) {
|
|
|
|
return getTileType(pos.x, pos.y, pos.z);
|
|
|
|
}
|
|
|
|
inline df::tile_designation *getTileDesignation(df::coord pos) {
|
|
|
|
return getTileDesignation(pos.x, pos.y, pos.z);
|
|
|
|
}
|
|
|
|
inline df::tile_occupancy *getTileOccupancy(df::coord pos) {
|
|
|
|
return getTileOccupancy(pos.x, pos.y, pos.z);
|
|
|
|
}
|
|
|
|
|
2012-05-13 03:58:41 -06:00
|
|
|
/**
|
|
|
|
* Returns biome info about the specified world region.
|
|
|
|
*/
|
2012-08-27 13:03:02 -06:00
|
|
|
DFHACK_EXPORT df::region_map_entry *getRegionBiome(df::coord2d rgn_pos);
|
2012-01-19 20:44:17 -07:00
|
|
|
|
2012-05-13 03:58:41 -06:00
|
|
|
/**
|
|
|
|
* Returns biome world region coordinates for the given tile within given block.
|
|
|
|
*/
|
|
|
|
DFHACK_EXPORT df::coord2d getBlockTileBiomeRgn(df::map_block *block, df::coord2d pos);
|
|
|
|
|
|
|
|
inline df::coord2d getTileBiomeRgn(df::coord pos) {
|
|
|
|
return getBlockTileBiomeRgn(getTileBlock(pos), pos);
|
|
|
|
}
|
|
|
|
|
2012-05-12 10:12:09 -06:00
|
|
|
// Enables per-frame updates for liquid flow and/or temperature.
|
|
|
|
DFHACK_EXPORT void enableBlockUpdates(df::map_block *blk, bool flow = false, bool temperature = false);
|
|
|
|
|
2012-09-02 04:10:58 -06:00
|
|
|
DFHACK_EXPORT df::flow_info *spawnFlow(df::coord pos, df::flow_type type, int mat_type = 0, int mat_index = -1, int density = 100);
|
|
|
|
|
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,
|
2014-08-20 09:51:58 -06:00
|
|
|
std::vector<df::block_square_event_material_spatterst *>* materials = 0,
|
2012-01-19 20:44:17 -07:00
|
|
|
std::vector<df::block_square_event_grassst *>* grass = 0,
|
2014-08-20 09:51:58 -06:00
|
|
|
std::vector<df::block_square_event_world_constructionst *>* constructions = 0,
|
|
|
|
std::vector<df::block_square_event_spoorst *>* spoors = 0,
|
2018-01-21 17:27:16 -07:00
|
|
|
std::vector<df::block_square_event_item_spatterst *>* items = 0,
|
|
|
|
std::vector<df::block_square_event_designation_priorityst *>* priorities = 0
|
2012-01-19 20:44:17 -07:00
|
|
|
);
|
|
|
|
|
|
|
|
/// remove a block event from the block by address
|
2022-04-21 19:13:23 -06:00
|
|
|
extern DFHACK_EXPORT bool RemoveBlockEvent(int32_t x, int32_t y, int32_t z, df::block_square_event * which );
|
|
|
|
extern DFHACK_EXPORT bool RemoveBlockEvent(uint32_t x, uint32_t y, uint32_t z, df::block_square_event * which ); // todo: deprecate me
|
2012-04-26 08:51:39 -06:00
|
|
|
|
2013-01-05 16:09:50 -07:00
|
|
|
DFHACK_EXPORT bool canWalkBetween(df::coord pos1, df::coord pos2);
|
2012-12-19 18:30:37 -07:00
|
|
|
DFHACK_EXPORT bool canStepBetween(df::coord pos1, df::coord pos2);
|
2018-08-15 19:28:18 -06:00
|
|
|
|
2021-06-22 21:01:10 -06:00
|
|
|
/**
|
|
|
|
* Get the plant that owns the tile at the specified position
|
|
|
|
*/
|
2021-06-24 00:00:30 -06:00
|
|
|
extern DFHACK_EXPORT df::plant *getPlantAtTile(int32_t x, int32_t y, int32_t z);
|
2021-06-22 21:01:10 -06:00
|
|
|
|
2021-06-24 00:00:30 -06:00
|
|
|
inline df::plant *getPlantAtTile(df::coord pos) { return getPlantAtTile(pos.x, pos.y, pos.z); }
|
2021-06-22 21:01:10 -06:00
|
|
|
|
2018-08-15 19:28:18 -06:00
|
|
|
DFHACK_EXPORT df::enums::biome_type::biome_type GetBiomeType(int world_coord_x, int world_coord_y);
|
|
|
|
DFHACK_EXPORT df::enums::biome_type::biome_type GetBiomeTypeWithRef(int world_coord_x, int world_coord_y, int world_ref_y_coord);
|
|
|
|
|
2012-01-19 20:44:17 -07:00
|
|
|
}
|
2018-08-15 19:28:18 -06:00
|
|
|
|
|
|
|
|
2010-04-04 16:48:19 -06:00
|
|
|
}
|
2010-04-28 10:21:52 -06:00
|
|
|
#endif
|