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.
|
|
|
|
*/
|
|
|
|
|
2011-04-10 05:12:28 -06:00
|
|
|
#pragma once
|
2011-03-10 19:09:45 -07:00
|
|
|
#ifndef MAPEXTRAS_H
|
|
|
|
#define MAPEXTRAS_H
|
|
|
|
|
2011-12-31 04:48:42 -07:00
|
|
|
#include "modules/Maps.h"
|
|
|
|
#include "TileTypes.h"
|
2011-06-15 09:35:47 -06:00
|
|
|
#include <stdint.h>
|
2011-03-10 19:09:45 -07:00
|
|
|
#include <cstring>
|
2012-01-19 13:11:52 -07:00
|
|
|
#include "df/map_block.h"
|
2014-07-20 05:11:20 -06:00
|
|
|
#include "df/map_block_column.h"
|
2012-04-19 09:17:07 -06:00
|
|
|
#include "df/tile_bitmask.h"
|
2012-01-19 13:11:52 -07:00
|
|
|
#include "df/block_square_event_mineralst.h"
|
2012-03-13 14:40:38 -06:00
|
|
|
#include "df/construction.h"
|
2012-04-10 10:19:41 -06:00
|
|
|
#include "df/item.h"
|
2013-10-04 07:04:42 -06:00
|
|
|
#include "df/inclusion_type.h"
|
2012-04-10 08:21:19 -06:00
|
|
|
|
2018-06-18 06:53:13 -06:00
|
|
|
#include <bitset>
|
|
|
|
|
2012-04-19 09:17:07 -06:00
|
|
|
namespace df {
|
|
|
|
struct world_region_details;
|
|
|
|
}
|
|
|
|
|
2011-03-10 19:09:45 -07:00
|
|
|
namespace MapExtras
|
|
|
|
{
|
|
|
|
|
2016-10-15 12:53:10 -06:00
|
|
|
using namespace DFHack;
|
|
|
|
|
2012-04-10 08:21:19 -06:00
|
|
|
class DFHACK_EXPORT MapCache;
|
2011-04-10 09:01:58 -06:00
|
|
|
|
2012-04-19 09:17:07 -06:00
|
|
|
class Block;
|
|
|
|
|
2013-10-03 07:54:28 -06:00
|
|
|
struct BiomeInfo {
|
|
|
|
// Determined by the 4-bit index in the designation bitfield
|
2018-06-22 06:51:03 -06:00
|
|
|
static constexpr unsigned MAX_LAYERS = 16;
|
2013-10-03 07:54:28 -06:00
|
|
|
|
|
|
|
df::coord2d pos;
|
|
|
|
int default_soil, default_stone, lava_stone;
|
|
|
|
int geo_index;
|
|
|
|
df::region_map_entry *biome;
|
|
|
|
df::world_geo_biome *geobiome;
|
|
|
|
df::world_region_details *details;
|
|
|
|
int16_t layer_stone[MAX_LAYERS];
|
|
|
|
};
|
|
|
|
|
2013-10-04 07:04:42 -06:00
|
|
|
typedef uint8_t t_veintype[16][16];
|
2013-10-05 10:07:21 -06:00
|
|
|
typedef df::tiletype t_tilearr[16][16];
|
2013-10-04 07:04:42 -06:00
|
|
|
|
2012-04-19 09:17:07 -06:00
|
|
|
class BlockInfo
|
|
|
|
{
|
|
|
|
Block *mblock;
|
|
|
|
MapCache *parent;
|
|
|
|
df::map_block *block;
|
2015-02-14 20:53:06 -07:00
|
|
|
df::map_block_column *column; //for plants
|
2012-04-19 09:17:07 -06:00
|
|
|
|
|
|
|
public:
|
2013-10-03 07:54:28 -06:00
|
|
|
enum GroundType {
|
|
|
|
G_UNKNOWN = 0, G_STONE, G_SOIL
|
|
|
|
};
|
|
|
|
static GroundType getGroundType(int material);
|
|
|
|
|
2013-10-04 07:04:42 -06:00
|
|
|
typedef df::block_square_event_mineralst::T_flags DFVeinFlags;
|
|
|
|
|
|
|
|
t_veintype veintype;
|
2012-04-19 09:17:07 -06:00
|
|
|
t_blockmaterials veinmats;
|
|
|
|
t_blockmaterials grass;
|
|
|
|
std::map<df::coord,df::plant*> plants;
|
|
|
|
|
|
|
|
df::feature_init *global_feature;
|
|
|
|
df::feature_init *local_feature;
|
|
|
|
|
|
|
|
BlockInfo()
|
|
|
|
: mblock(NULL), parent(NULL), block(NULL),
|
|
|
|
global_feature(NULL), local_feature(NULL) {}
|
|
|
|
|
|
|
|
void prepare(Block *mblock);
|
|
|
|
|
|
|
|
t_matpair getBaseMaterial(df::tiletype tt, df::coord2d pos);
|
|
|
|
|
2013-10-04 07:04:42 -06:00
|
|
|
static df::inclusion_type getVeinType(DFVeinFlags &flags);
|
|
|
|
static void setVeinType(DFVeinFlags &flags, df::inclusion_type type);
|
|
|
|
|
|
|
|
static void SquashVeins(df::map_block *mb, t_blockmaterials & materials, t_veintype &veintype);
|
2012-04-19 09:17:07 -06:00
|
|
|
static void SquashFrozenLiquids (df::map_block *mb, tiletypes40d & frozen);
|
|
|
|
static void SquashRocks (df::map_block *mb, t_blockmaterials & materials,
|
|
|
|
std::vector< std::vector <int16_t> > * layerassign);
|
|
|
|
static void SquashGrass(df::map_block *mb, t_blockmaterials &materials);
|
|
|
|
};
|
|
|
|
|
2012-04-10 08:21:19 -06:00
|
|
|
class DFHACK_EXPORT Block
|
2012-03-13 14:40:38 -06:00
|
|
|
{
|
2012-04-10 08:21:19 -06:00
|
|
|
public:
|
|
|
|
Block(MapCache *parent, DFCoord _bcoord);
|
2012-04-10 10:19:41 -06:00
|
|
|
~Block();
|
2012-03-13 14:40:38 -06:00
|
|
|
|
2012-05-12 10:12:09 -06:00
|
|
|
DFCoord getCoord() { return bcoord; }
|
|
|
|
|
|
|
|
void enableBlockUpdates(bool flow = false, bool temp = false) {
|
|
|
|
Maps::enableBlockUpdates(block, flow, temp);
|
|
|
|
}
|
|
|
|
|
2012-04-10 08:21:19 -06:00
|
|
|
/*
|
|
|
|
* All coordinates are taken mod 16.
|
|
|
|
*/
|
|
|
|
|
2013-10-04 07:04:42 -06:00
|
|
|
/// Arbitrary tag field for flood fills etc.
|
2012-04-10 08:21:19 -06:00
|
|
|
int16_t &tag(df::coord2d p) {
|
2012-04-19 09:17:07 -06:00
|
|
|
if (!tags) init_tags();
|
2018-06-18 06:49:27 -06:00
|
|
|
return index_tile(tags, p);
|
2011-03-10 19:09:45 -07:00
|
|
|
}
|
2012-04-10 08:21:19 -06:00
|
|
|
|
2013-10-04 07:04:42 -06:00
|
|
|
/// Base layer tile type (i.e. layer stone, veins, feature stone)
|
2012-04-19 09:17:07 -06:00
|
|
|
df::tiletype baseTiletypeAt(df::coord2d p)
|
|
|
|
{
|
|
|
|
if (!tiles) init_tiles();
|
2018-06-18 06:49:27 -06:00
|
|
|
return index_tile(tiles->base_tiles,p);
|
2012-04-19 09:17:07 -06:00
|
|
|
}
|
2013-10-04 07:04:42 -06:00
|
|
|
/// Base layer material (i.e. layer stone, veins, feature stone)
|
2012-04-19 09:17:07 -06:00
|
|
|
t_matpair baseMaterialAt(df::coord2d p)
|
|
|
|
{
|
|
|
|
if (!basemats) init_tiles(true);
|
|
|
|
return t_matpair(
|
2018-06-18 06:49:27 -06:00
|
|
|
index_tile(basemats->mat_type,p),
|
|
|
|
index_tile(basemats->mat_index,p)
|
2012-04-19 09:17:07 -06:00
|
|
|
);
|
|
|
|
}
|
2013-10-04 07:04:42 -06:00
|
|
|
/// Check if the base layer tile is a vein
|
2012-04-19 09:17:07 -06:00
|
|
|
bool isVeinAt(df::coord2d p)
|
|
|
|
{
|
|
|
|
using namespace df::enums::tiletype_material;
|
|
|
|
auto tm = tileMaterial(baseTiletypeAt(p));
|
|
|
|
return tm == MINERAL;
|
|
|
|
}
|
2013-10-04 07:04:42 -06:00
|
|
|
/// Check if the base layer tile is layer stone or soil
|
2012-04-19 09:17:07 -06:00
|
|
|
bool isLayerAt(df::coord2d p)
|
|
|
|
{
|
|
|
|
using namespace df::enums::tiletype_material;
|
|
|
|
auto tm = tileMaterial(baseTiletypeAt(p));
|
|
|
|
return tm == STONE || tm == SOIL;
|
|
|
|
}
|
|
|
|
|
2013-10-04 07:04:42 -06:00
|
|
|
/// Vein material at pos (even if there is no vein tile), or -1 if none
|
2012-01-20 03:28:00 -07:00
|
|
|
int16_t veinMaterialAt(df::coord2d p)
|
2011-03-10 19:09:45 -07:00
|
|
|
{
|
2013-10-04 07:04:42 -06:00
|
|
|
if (!basemats) init_tiles(true);
|
2018-06-18 06:49:27 -06:00
|
|
|
return index_tile(basemats->veinmat,p);
|
2013-10-04 07:04:42 -06:00
|
|
|
}
|
|
|
|
/// Vein type at pos (even if there is no vein tile)
|
|
|
|
df::inclusion_type veinTypeAt(df::coord2d p)
|
|
|
|
{
|
|
|
|
if (!basemats) init_tiles(true);
|
2018-06-18 06:49:27 -06:00
|
|
|
return (df::inclusion_type)index_tile(basemats->veintype,p);
|
2011-03-10 19:09:45 -07:00
|
|
|
}
|
2013-10-03 07:54:28 -06:00
|
|
|
|
2013-10-04 07:04:42 -06:00
|
|
|
/** Sets the vein material at the specified tile position.
|
|
|
|
* Use -1 to clear the tile from all veins. Does not update tile types.
|
|
|
|
* Returns false in case of some error, e.g. non-stone mat.
|
|
|
|
*/
|
2013-10-05 10:07:21 -06:00
|
|
|
bool setVeinMaterialAt(df::coord2d p, int16_t mat, df::inclusion_type type = df::enums::inclusion_type::CLUSTER);
|
2013-10-04 07:04:42 -06:00
|
|
|
|
2013-10-03 07:54:28 -06:00
|
|
|
/// Geological layer soil or stone material at pos
|
|
|
|
int16_t layerMaterialAt(df::coord2d p) {
|
|
|
|
return biomeInfoAt(p).layer_stone[layerIndexAt(p)];
|
2011-03-10 19:09:45 -07:00
|
|
|
}
|
|
|
|
|
2013-10-03 07:54:28 -06:00
|
|
|
/// Biome-specific lava stone at pos
|
|
|
|
int16_t lavaStoneAt(df::coord2d p) { return biomeInfoAt(p).lava_stone; }
|
|
|
|
|
2013-10-05 10:07:21 -06:00
|
|
|
/**
|
|
|
|
* Sets the stone tile and material at specified position, automatically
|
|
|
|
* choosing between layer, lava or vein stone.
|
|
|
|
* The force_type flags ensures the correct inclusion type, even forcing
|
|
|
|
* a vein format if necessary. If kill_veins is true and the chosen mode
|
|
|
|
* isn't vein, it will clear any old veins from the tile.
|
|
|
|
*/
|
|
|
|
bool setStoneAt(df::coord2d p, df::tiletype tile, int16_t mat, df::inclusion_type type = df::enums::inclusion_type::CLUSTER, bool force_type = false, bool kill_veins = false);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the tile at the position to SOIL material. The actual material
|
|
|
|
* is completely determined by geological layers and cannot be set.
|
|
|
|
*/
|
|
|
|
bool setSoilAt(df::coord2d p, df::tiletype tile, bool kill_veins = false);
|
|
|
|
|
2013-10-04 07:04:42 -06:00
|
|
|
/// Static layer tile (i.e. base + constructions)
|
2012-04-19 09:17:07 -06:00
|
|
|
df::tiletype staticTiletypeAt(df::coord2d p)
|
2012-03-13 14:40:38 -06:00
|
|
|
{
|
2012-04-19 09:17:07 -06:00
|
|
|
if (!tiles) init_tiles();
|
|
|
|
if (tiles->con_info)
|
2018-06-18 06:49:27 -06:00
|
|
|
return index_tile(tiles->con_info->tiles,p);
|
2012-04-19 09:17:07 -06:00
|
|
|
return baseTiletypeAt(p);
|
2012-03-13 14:40:38 -06:00
|
|
|
}
|
2013-10-04 07:04:42 -06:00
|
|
|
/// Static layer material (i.e. base + constructions)
|
2012-04-19 09:17:07 -06:00
|
|
|
t_matpair staticMaterialAt(df::coord2d p)
|
2011-03-10 19:09:45 -07:00
|
|
|
{
|
2012-04-19 09:17:07 -06:00
|
|
|
if (!basemats) init_tiles(true);
|
|
|
|
if (tiles->con_info)
|
|
|
|
return t_matpair(
|
2018-06-18 06:49:27 -06:00
|
|
|
index_tile(tiles->con_info->mat_type,p),
|
|
|
|
index_tile(tiles->con_info->mat_index,p)
|
2012-04-19 09:17:07 -06:00
|
|
|
);
|
|
|
|
return baseMaterialAt(p);
|
2011-03-10 19:09:45 -07:00
|
|
|
}
|
2012-04-19 09:17:07 -06:00
|
|
|
bool hasConstructionAt(df::coord2d p)
|
2011-03-10 19:09:45 -07:00
|
|
|
{
|
2012-04-19 09:17:07 -06:00
|
|
|
if (!tiles) init_tiles();
|
|
|
|
return tiles->con_info &&
|
|
|
|
tiles->con_info->constructed.getassignment(p);
|
2011-03-10 19:09:45 -07:00
|
|
|
}
|
|
|
|
|
2012-04-19 09:17:07 -06:00
|
|
|
df::tiletype tiletypeAt(df::coord2d p)
|
|
|
|
{
|
|
|
|
if (!block) return tiletype::Void;
|
|
|
|
if (tiles)
|
2018-06-18 06:49:27 -06:00
|
|
|
return index_tile(tiles->raw_tiles,p);
|
|
|
|
return index_tile(block->tiletype,p);
|
2012-04-19 09:17:07 -06:00
|
|
|
}
|
|
|
|
bool setTiletypeAt(df::coord2d, df::tiletype tt, bool force = false);
|
|
|
|
|
2012-01-20 03:28:00 -07:00
|
|
|
uint16_t temperature1At(df::coord2d p)
|
2011-03-10 19:09:45 -07:00
|
|
|
{
|
2018-06-18 06:49:27 -06:00
|
|
|
return index_tile(temp1,p);
|
2011-03-10 19:09:45 -07:00
|
|
|
}
|
2012-01-20 03:28:00 -07:00
|
|
|
bool setTemp1At(df::coord2d p, uint16_t temp)
|
2011-03-10 19:09:45 -07:00
|
|
|
{
|
|
|
|
if(!valid) return false;
|
|
|
|
dirty_temperatures = true;
|
2018-06-18 06:49:27 -06:00
|
|
|
index_tile(temp1,p) = temp;
|
2011-03-10 19:09:45 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-01-20 03:28:00 -07:00
|
|
|
uint16_t temperature2At(df::coord2d p)
|
2011-03-10 19:09:45 -07:00
|
|
|
{
|
2018-06-18 06:49:27 -06:00
|
|
|
return index_tile(temp2,p);
|
2011-03-10 19:09:45 -07:00
|
|
|
}
|
2012-01-20 03:28:00 -07:00
|
|
|
bool setTemp2At(df::coord2d p, uint16_t temp)
|
2011-03-10 19:09:45 -07:00
|
|
|
{
|
|
|
|
if(!valid) return false;
|
|
|
|
dirty_temperatures = true;
|
2018-06-18 06:49:27 -06:00
|
|
|
index_tile(temp2,p) = temp;
|
2011-03-10 19:09:45 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-01-20 03:28:00 -07:00
|
|
|
df::tile_designation DesignationAt(df::coord2d p)
|
2011-03-10 19:09:45 -07:00
|
|
|
{
|
2018-06-18 06:49:27 -06:00
|
|
|
return index_tile(designation,p);
|
2011-03-10 19:09:45 -07:00
|
|
|
}
|
2022-10-19 17:47:54 -06:00
|
|
|
bool setDesignationAt(df::coord2d p, df::tile_designation des, int32_t priority = 0)
|
2011-03-10 19:09:45 -07:00
|
|
|
{
|
|
|
|
if(!valid) return false;
|
|
|
|
dirty_designations = true;
|
2018-06-18 06:53:13 -06:00
|
|
|
designated_tiles[(p.x&15) + (p.y&15)*16] = true;
|
2011-03-10 19:09:45 -07:00
|
|
|
//printf("setting block %d/%d/%d , %d %d\n",x,y,z, p.x, p.y);
|
2018-06-18 06:49:27 -06:00
|
|
|
index_tile(designation,p) = des;
|
2018-06-18 06:53:13 -06:00
|
|
|
if((des.bits.dig || des.bits.smooth) && block) {
|
2012-05-12 10:12:09 -06:00
|
|
|
block->flags.bits.designated = true;
|
2022-10-19 17:47:54 -06:00
|
|
|
// if priority is not specified, keep the existing priority if it
|
|
|
|
// is set. otherwise default to 4000.
|
|
|
|
if (priority <= 0)
|
|
|
|
priority = priorityAt(p);
|
|
|
|
if (priority <= 0)
|
|
|
|
priority = 4000;
|
2018-06-18 06:53:13 -06:00
|
|
|
setPriorityAt(p, priority);
|
|
|
|
}
|
2011-03-10 19:09:45 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-01-21 17:27:16 -07:00
|
|
|
int32_t priorityAt(df::coord2d p);
|
|
|
|
bool setPriorityAt(df::coord2d p, int32_t priority);
|
|
|
|
|
2012-01-20 03:28:00 -07:00
|
|
|
df::tile_occupancy OccupancyAt(df::coord2d p)
|
2011-04-27 17:36:31 -06:00
|
|
|
{
|
2018-06-18 06:49:27 -06:00
|
|
|
return index_tile(occupancy,p);
|
2011-04-27 17:36:31 -06:00
|
|
|
}
|
2012-01-20 03:28:00 -07:00
|
|
|
bool setOccupancyAt(df::coord2d p, df::tile_occupancy des)
|
2011-04-27 17:36:31 -06:00
|
|
|
{
|
|
|
|
if(!valid) return false;
|
|
|
|
dirty_occupancies = true;
|
2018-06-18 06:49:27 -06:00
|
|
|
index_tile(occupancy,p) = des;
|
2011-04-27 17:36:31 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-10-11 09:23:32 -06:00
|
|
|
bool getFlagAt(df::coord2d p, df::tile_designation::Mask mask) {
|
2018-06-18 06:49:27 -06:00
|
|
|
return (index_tile(designation,p).whole & mask) != 0;
|
2013-10-11 09:23:32 -06:00
|
|
|
}
|
|
|
|
bool getFlagAt(df::coord2d p, df::tile_occupancy::Mask mask) {
|
2018-06-18 06:49:27 -06:00
|
|
|
return (index_tile(occupancy,p).whole & mask) != 0;
|
2013-10-11 09:23:32 -06:00
|
|
|
}
|
|
|
|
bool setFlagAt(df::coord2d p, df::tile_designation::Mask mask, bool set);
|
|
|
|
bool setFlagAt(df::coord2d p, df::tile_occupancy::Mask mask, bool set);
|
|
|
|
|
2012-04-10 10:19:41 -06:00
|
|
|
int itemCountAt(df::coord2d p)
|
|
|
|
{
|
|
|
|
if (!item_counts) init_item_counts();
|
2018-06-18 06:49:27 -06:00
|
|
|
return index_tile(item_counts,p);
|
2012-04-10 10:19:41 -06:00
|
|
|
}
|
|
|
|
|
2012-03-13 14:40:38 -06:00
|
|
|
t_blockflags BlockFlags()
|
2011-03-10 19:09:45 -07:00
|
|
|
{
|
2012-05-12 10:12:09 -06:00
|
|
|
return block ? block->flags : t_blockflags();
|
2011-03-10 19:09:45 -07:00
|
|
|
}
|
|
|
|
|
2012-04-10 08:21:19 -06:00
|
|
|
bool Write();
|
2013-10-03 06:50:00 -06:00
|
|
|
bool isDirty();
|
2012-04-10 08:21:19 -06:00
|
|
|
|
2013-10-03 07:54:28 -06:00
|
|
|
int biomeIndexAt(df::coord2d p);
|
|
|
|
int layerIndexAt(df::coord2d p) {
|
2018-06-18 06:49:27 -06:00
|
|
|
return index_tile(designation,p).bits.geolayer_index;
|
2013-10-03 07:54:28 -06:00
|
|
|
}
|
|
|
|
|
2012-04-11 02:01:27 -06:00
|
|
|
df::coord2d biomeRegionAt(df::coord2d p);
|
2013-10-03 07:54:28 -06:00
|
|
|
const BiomeInfo &biomeInfoAt(df::coord2d p);
|
|
|
|
int16_t GeoIndexAt(df::coord2d p) { return biomeInfoAt(p).geo_index; }
|
2012-04-10 08:21:19 -06:00
|
|
|
|
|
|
|
bool GetGlobalFeature(t_feature *out);
|
|
|
|
bool GetLocalFeature(t_feature *out);
|
|
|
|
|
|
|
|
bool is_valid() { return valid; }
|
|
|
|
df::map_block *getRaw() { return block; }
|
|
|
|
|
2012-09-06 12:45:19 -06:00
|
|
|
bool Allocate();
|
|
|
|
|
2012-04-19 09:17:07 -06:00
|
|
|
MapCache *getParent() { return parent; }
|
|
|
|
|
2012-04-10 08:21:19 -06:00
|
|
|
private:
|
|
|
|
friend class MapCache;
|
2012-04-19 13:02:30 -06:00
|
|
|
friend class BlockInfo;
|
2012-04-10 08:21:19 -06:00
|
|
|
|
|
|
|
MapCache *parent;
|
|
|
|
df::map_block *block;
|
|
|
|
|
2012-09-06 12:45:19 -06:00
|
|
|
void init();
|
|
|
|
|
2018-06-18 06:53:13 -06:00
|
|
|
bool valid:1;
|
2011-03-10 19:09:45 -07:00
|
|
|
bool dirty_designations:1;
|
2012-04-19 09:17:07 -06:00
|
|
|
bool dirty_tiles:1;
|
2013-10-04 07:04:42 -06:00
|
|
|
bool dirty_veins:1;
|
2011-03-10 19:09:45 -07:00
|
|
|
bool dirty_temperatures:1;
|
2011-04-27 17:36:31 -06:00
|
|
|
bool dirty_occupancies:1;
|
2012-04-10 08:21:19 -06:00
|
|
|
|
2018-06-18 06:53:13 -06:00
|
|
|
std::bitset<16*16> designated_tiles;
|
|
|
|
|
2012-03-13 14:40:38 -06:00
|
|
|
DFCoord bcoord;
|
2012-04-10 08:21:19 -06:00
|
|
|
|
2012-04-19 09:17:07 -06:00
|
|
|
// Custom tags for floodfill
|
|
|
|
typedef int16_t T_tags[16];
|
|
|
|
T_tags *tags;
|
|
|
|
void init_tags();
|
2012-04-10 08:21:19 -06:00
|
|
|
|
2012-04-19 09:17:07 -06:00
|
|
|
// On-ground item count info
|
2012-04-10 10:19:41 -06:00
|
|
|
typedef int T_item_counts[16];
|
|
|
|
T_item_counts *item_counts;
|
|
|
|
void init_item_counts();
|
|
|
|
|
|
|
|
bool addItemOnGround(df::item *item);
|
|
|
|
bool removeItemOnGround(df::item *item);
|
|
|
|
|
2013-10-05 10:07:21 -06:00
|
|
|
struct IceInfo {
|
|
|
|
df::tile_bitmask frozen;
|
|
|
|
df::tile_bitmask dirty;
|
|
|
|
};
|
2012-04-19 09:17:07 -06:00
|
|
|
struct ConInfo {
|
|
|
|
df::tile_bitmask constructed;
|
2013-10-05 10:07:21 -06:00
|
|
|
df::tile_bitmask dirty;
|
|
|
|
t_tilearr tiles;
|
2012-11-16 14:35:34 -07:00
|
|
|
t_blockmaterials mat_type;
|
|
|
|
t_blockmaterials mat_index;
|
2012-04-19 09:17:07 -06:00
|
|
|
};
|
|
|
|
struct TileInfo {
|
|
|
|
df::tile_bitmask dirty_raw;
|
2013-10-05 10:07:21 -06:00
|
|
|
t_tilearr raw_tiles;
|
2012-04-19 09:17:07 -06:00
|
|
|
|
2013-10-05 10:07:21 -06:00
|
|
|
IceInfo *ice_info;
|
2012-04-19 09:17:07 -06:00
|
|
|
ConInfo *con_info;
|
|
|
|
|
2013-10-05 10:07:21 -06:00
|
|
|
t_tilearr base_tiles;
|
2012-04-19 09:17:07 -06:00
|
|
|
|
|
|
|
TileInfo();
|
|
|
|
~TileInfo();
|
|
|
|
|
2013-10-05 10:07:21 -06:00
|
|
|
void init_iceinfo();
|
2012-04-19 09:17:07 -06:00
|
|
|
void init_coninfo();
|
2013-10-05 10:07:21 -06:00
|
|
|
|
|
|
|
void set_base_tile(df::coord2d pos, df::tiletype tile);
|
2012-04-19 09:17:07 -06:00
|
|
|
};
|
|
|
|
struct BasematInfo {
|
2012-11-16 14:35:34 -07:00
|
|
|
t_blockmaterials mat_type;
|
|
|
|
t_blockmaterials mat_index;
|
2013-10-04 07:04:42 -06:00
|
|
|
|
|
|
|
df::tile_bitmask vein_dirty;
|
|
|
|
t_veintype veintype;
|
|
|
|
t_blockmaterials veinmat;
|
2012-04-19 09:17:07 -06:00
|
|
|
|
|
|
|
BasematInfo();
|
2013-10-05 10:07:21 -06:00
|
|
|
|
|
|
|
void set_base_mat(TileInfo *tiles, df::coord2d pos, int16_t type, int16_t idx);
|
2012-04-19 09:17:07 -06:00
|
|
|
};
|
|
|
|
TileInfo *tiles;
|
|
|
|
BasematInfo *basemats;
|
|
|
|
void init_tiles(bool basemat = false);
|
|
|
|
void ParseTiles(TileInfo *tiles);
|
2013-10-04 07:04:42 -06:00
|
|
|
void WriteTiles(TileInfo*);
|
2012-04-19 09:17:07 -06:00
|
|
|
void ParseBasemats(TileInfo *tiles, BasematInfo *bmats);
|
2013-10-04 07:04:42 -06:00
|
|
|
void WriteVeins(TileInfo *tiles, BasematInfo *bmats);
|
2012-04-19 09:17:07 -06:00
|
|
|
|
2012-04-10 08:21:19 -06:00
|
|
|
designations40d designation;
|
|
|
|
occupancies40d occupancy;
|
|
|
|
|
2012-03-13 14:40:38 -06:00
|
|
|
t_temperatures temp1;
|
|
|
|
t_temperatures temp2;
|
2011-03-10 19:09:45 -07:00
|
|
|
};
|
|
|
|
|
2012-04-10 08:21:19 -06:00
|
|
|
class DFHACK_EXPORT MapCache
|
2011-03-10 19:09:45 -07:00
|
|
|
{
|
|
|
|
public:
|
2012-04-19 09:17:07 -06:00
|
|
|
MapCache();
|
2011-03-10 19:09:45 -07:00
|
|
|
~MapCache()
|
|
|
|
{
|
2011-04-10 10:41:49 -06:00
|
|
|
trash();
|
2011-03-10 19:09:45 -07:00
|
|
|
}
|
|
|
|
bool isValid ()
|
|
|
|
{
|
|
|
|
return valid;
|
|
|
|
}
|
2012-04-10 08:21:19 -06:00
|
|
|
|
2011-03-10 19:09:45 -07:00
|
|
|
/// get the map block at a *block* coord. Block coord = tile coord / 16
|
2012-04-10 08:21:19 -06:00
|
|
|
Block *BlockAt(DFCoord blockcoord);
|
|
|
|
/// get the map block at a tile coord.
|
|
|
|
Block *BlockAtTile(DFCoord coord) {
|
|
|
|
return BlockAt(df::coord(coord.x>>4,coord.y>>4,coord.z));
|
2011-03-10 19:09:45 -07:00
|
|
|
}
|
2012-04-10 08:21:19 -06:00
|
|
|
|
2012-09-06 12:45:19 -06:00
|
|
|
bool ensureBlockAt(df::coord coord)
|
|
|
|
{
|
|
|
|
Block *b = BlockAtTile(coord);
|
|
|
|
return b ? b->Allocate() : false;
|
|
|
|
}
|
|
|
|
|
2013-10-03 06:50:00 -06:00
|
|
|
/// delete the block from memory
|
|
|
|
void discardBlock(Block *block);
|
|
|
|
|
2012-03-13 14:40:38 -06:00
|
|
|
df::tiletype baseTiletypeAt (DFCoord tilecoord)
|
|
|
|
{
|
2012-04-19 09:17:07 -06:00
|
|
|
Block *b = BlockAtTile(tilecoord);
|
|
|
|
return b ? b->baseTiletypeAt(tilecoord) : tiletype::Void;
|
|
|
|
}
|
|
|
|
t_matpair baseMaterialAt (DFCoord tilecoord)
|
|
|
|
{
|
|
|
|
Block *b = BlockAtTile(tilecoord);
|
|
|
|
return b ? b->baseMaterialAt(tilecoord) : t_matpair();
|
|
|
|
}
|
|
|
|
int16_t veinMaterialAt (DFCoord tilecoord)
|
|
|
|
{
|
|
|
|
Block *b = BlockAtTile(tilecoord);
|
|
|
|
return b ? b->veinMaterialAt(tilecoord) : -1;
|
|
|
|
}
|
|
|
|
int16_t layerMaterialAt (DFCoord tilecoord)
|
|
|
|
{
|
|
|
|
Block *b = BlockAtTile(tilecoord);
|
|
|
|
return b ? b->layerMaterialAt(tilecoord) : -1;
|
|
|
|
}
|
|
|
|
bool isVeinAt (DFCoord tilecoord)
|
|
|
|
{
|
|
|
|
Block *b = BlockAtTile(tilecoord);
|
|
|
|
return b && b->isVeinAt(tilecoord);
|
2012-03-13 14:40:38 -06:00
|
|
|
}
|
2012-04-19 09:17:07 -06:00
|
|
|
bool isLayerAt (DFCoord tilecoord)
|
|
|
|
{
|
|
|
|
Block *b = BlockAtTile(tilecoord);
|
|
|
|
return b && b->isLayerAt(tilecoord);
|
|
|
|
}
|
|
|
|
|
|
|
|
df::tiletype staticTiletypeAt (DFCoord tilecoord)
|
|
|
|
{
|
|
|
|
Block *b = BlockAtTile(tilecoord);
|
|
|
|
return b ? b->staticTiletypeAt(tilecoord) : tiletype::Void;
|
|
|
|
}
|
|
|
|
t_matpair staticMaterialAt (DFCoord tilecoord)
|
|
|
|
{
|
|
|
|
Block *b = BlockAtTile(tilecoord);
|
|
|
|
return b ? b->staticMaterialAt(tilecoord) : t_matpair();
|
|
|
|
}
|
|
|
|
bool hasConstructionAt (DFCoord tilecoord)
|
|
|
|
{
|
|
|
|
Block *b = BlockAtTile(tilecoord);
|
|
|
|
return b && b->hasConstructionAt(tilecoord);
|
|
|
|
}
|
|
|
|
|
2012-03-13 14:40:38 -06:00
|
|
|
df::tiletype tiletypeAt (DFCoord tilecoord)
|
2011-03-10 19:09:45 -07:00
|
|
|
{
|
2012-04-19 09:17:07 -06:00
|
|
|
Block *b = BlockAtTile(tilecoord);
|
|
|
|
return b ? b->tiletypeAt(tilecoord) : tiletype::Void;
|
2011-03-10 19:09:45 -07:00
|
|
|
}
|
2012-04-19 09:17:07 -06:00
|
|
|
bool setTiletypeAt (DFCoord tilecoord, df::tiletype tt, bool force = false)
|
2011-03-10 19:09:45 -07:00
|
|
|
{
|
2012-04-19 09:17:07 -06:00
|
|
|
Block *b = BlockAtTile(tilecoord);
|
|
|
|
return b && b->setTiletypeAt(tilecoord, tt, force);
|
2011-03-10 19:09:45 -07:00
|
|
|
}
|
|
|
|
|
2012-03-13 14:40:38 -06:00
|
|
|
uint16_t temperature1At (DFCoord tilecoord)
|
2011-03-10 19:09:45 -07:00
|
|
|
{
|
2012-04-10 08:21:19 -06:00
|
|
|
Block * b= BlockAtTile(tilecoord);
|
|
|
|
return b ? b->temperature1At(tilecoord) : 0;
|
2011-03-10 19:09:45 -07:00
|
|
|
}
|
2012-03-13 14:40:38 -06:00
|
|
|
bool setTemp1At(DFCoord tilecoord, uint16_t temperature)
|
2011-03-10 19:09:45 -07:00
|
|
|
{
|
2012-04-10 08:21:19 -06:00
|
|
|
if (Block * b= BlockAtTile(tilecoord))
|
|
|
|
return b->setTemp1At(tilecoord, temperature);
|
2011-03-10 19:09:45 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-03-13 14:40:38 -06:00
|
|
|
uint16_t temperature2At (DFCoord tilecoord)
|
2011-03-10 19:09:45 -07:00
|
|
|
{
|
2012-04-10 08:21:19 -06:00
|
|
|
Block * b= BlockAtTile(tilecoord);
|
|
|
|
return b ? b->temperature2At(tilecoord) : 0;
|
2011-03-10 19:09:45 -07:00
|
|
|
}
|
2012-03-13 14:40:38 -06:00
|
|
|
bool setTemp2At(DFCoord tilecoord, uint16_t temperature)
|
2011-03-10 19:09:45 -07:00
|
|
|
{
|
2012-04-10 08:21:19 -06:00
|
|
|
if (Block * b= BlockAtTile(tilecoord))
|
|
|
|
return b->setTemp2At(tilecoord, temperature);
|
2011-03-10 19:09:45 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-04-10 08:21:19 -06:00
|
|
|
int16_t tagAt(DFCoord tilecoord)
|
2012-03-31 07:41:55 -06:00
|
|
|
{
|
2012-04-10 08:21:19 -06:00
|
|
|
Block * b= BlockAtTile(tilecoord);
|
|
|
|
return b ? b->tag(tilecoord) : 0;
|
2012-03-31 07:41:55 -06:00
|
|
|
}
|
2012-04-10 08:21:19 -06:00
|
|
|
void setTagAt(DFCoord tilecoord, int16_t val)
|
2011-03-10 19:09:45 -07:00
|
|
|
{
|
2012-04-10 08:21:19 -06:00
|
|
|
Block * b= BlockAtTile(tilecoord);
|
|
|
|
if (b) b->tag(tilecoord) = val;
|
2011-03-10 19:09:45 -07:00
|
|
|
}
|
2012-04-19 09:17:07 -06:00
|
|
|
void resetTags();
|
2012-04-10 08:21:19 -06:00
|
|
|
|
2012-03-13 14:40:38 -06:00
|
|
|
df::tile_designation designationAt (DFCoord tilecoord)
|
2011-03-10 19:09:45 -07:00
|
|
|
{
|
2012-04-10 08:21:19 -06:00
|
|
|
Block * b= BlockAtTile(tilecoord);
|
2016-12-09 11:41:14 -07:00
|
|
|
return b ? b->DesignationAt(tilecoord) : df::tile_designation();
|
2011-03-10 19:09:45 -07:00
|
|
|
}
|
2022-10-19 17:47:54 -06:00
|
|
|
// if priority is 0, it is kept unchanged if previously set, otherwise 4000
|
|
|
|
bool setDesignationAt (DFCoord tilecoord, df::tile_designation des, int32_t priority = 0)
|
2011-03-10 19:09:45 -07:00
|
|
|
{
|
2018-01-21 17:27:16 -07:00
|
|
|
if (Block *b = BlockAtTile(tilecoord))
|
|
|
|
{
|
2018-06-18 06:53:13 -06:00
|
|
|
if (!b->setDesignationAt(tilecoord, des, priority))
|
2018-01-21 17:27:16 -07:00
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
2011-03-10 19:09:45 -07:00
|
|
|
return false;
|
|
|
|
}
|
2012-04-10 08:21:19 -06:00
|
|
|
|
2018-01-21 17:27:16 -07:00
|
|
|
int32_t priorityAt (DFCoord tilecoord)
|
|
|
|
{
|
|
|
|
Block *b = BlockAtTile(tilecoord);
|
|
|
|
return b ? b->priorityAt(tilecoord) : -1;
|
|
|
|
}
|
|
|
|
bool setPriorityAt (DFCoord tilecoord, int32_t priority)
|
|
|
|
{
|
|
|
|
Block *b = BlockAtTile(tilecoord);
|
|
|
|
return b ? b->setPriorityAt(tilecoord, priority) : false;
|
|
|
|
}
|
|
|
|
|
2012-03-13 14:40:38 -06:00
|
|
|
df::tile_occupancy occupancyAt (DFCoord tilecoord)
|
2011-04-27 17:36:31 -06:00
|
|
|
{
|
2012-04-10 08:21:19 -06:00
|
|
|
Block * b= BlockAtTile(tilecoord);
|
2016-12-09 11:41:14 -07:00
|
|
|
return b ? b->OccupancyAt(tilecoord) : df::tile_occupancy();
|
2011-04-27 17:36:31 -06:00
|
|
|
}
|
2012-03-13 14:40:38 -06:00
|
|
|
bool setOccupancyAt (DFCoord tilecoord, df::tile_occupancy occ)
|
2011-04-27 17:36:31 -06:00
|
|
|
{
|
2012-04-10 08:21:19 -06:00
|
|
|
if (Block * b= BlockAtTile(tilecoord))
|
|
|
|
return b->setOccupancyAt(tilecoord, occ);
|
2011-04-27 17:36:31 -06:00
|
|
|
return false;
|
|
|
|
}
|
2012-04-10 08:21:19 -06:00
|
|
|
|
2012-03-13 14:40:38 -06:00
|
|
|
bool testCoord (DFCoord tilecoord)
|
2011-03-10 19:09:45 -07:00
|
|
|
{
|
2012-04-10 08:21:19 -06:00
|
|
|
Block * b= BlockAtTile(tilecoord);
|
|
|
|
return (b && b->valid);
|
2011-03-10 19:09:45 -07:00
|
|
|
}
|
2012-04-10 08:21:19 -06:00
|
|
|
|
2012-04-10 10:19:41 -06:00
|
|
|
bool addItemOnGround(df::item *item) {
|
|
|
|
Block * b= BlockAtTile(item->pos);
|
|
|
|
return b ? b->addItemOnGround(item) : false;
|
|
|
|
}
|
|
|
|
bool removeItemOnGround(df::item *item) {
|
|
|
|
Block * b= BlockAtTile(item->pos);
|
|
|
|
return b ? b->removeItemOnGround(item) : false;
|
|
|
|
}
|
|
|
|
|
2018-06-18 06:53:13 -06:00
|
|
|
bool WriteAll();
|
|
|
|
|
2011-04-10 10:41:49 -06:00
|
|
|
void trash()
|
|
|
|
{
|
2012-03-13 14:40:38 -06:00
|
|
|
std::map<DFCoord, Block *>::iterator p;
|
2011-04-10 10:41:49 -06:00
|
|
|
for(p = blocks.begin(); p != blocks.end(); p++)
|
|
|
|
{
|
|
|
|
delete p->second;
|
|
|
|
}
|
|
|
|
blocks.clear();
|
|
|
|
}
|
2012-04-10 08:21:19 -06:00
|
|
|
|
|
|
|
uint32_t maxBlockX() { return x_bmax; }
|
|
|
|
uint32_t maxBlockY() { return y_bmax; }
|
|
|
|
uint32_t maxTileX() { return x_tmax; }
|
|
|
|
uint32_t maxTileY() { return y_tmax; }
|
|
|
|
uint32_t maxZ() { return z_max; }
|
|
|
|
|
2013-10-03 07:54:28 -06:00
|
|
|
size_t getBiomeCount() { return biomes.size(); }
|
|
|
|
const BiomeInfo &getBiomeByIndex(unsigned idx) {
|
|
|
|
return (idx < biomes.size()) ? biomes[idx] : biome_stub;
|
|
|
|
}
|
|
|
|
|
2012-04-10 08:21:19 -06:00
|
|
|
private:
|
|
|
|
friend class Block;
|
2012-04-19 09:17:07 -06:00
|
|
|
friend class BlockInfo;
|
2012-04-10 08:21:19 -06:00
|
|
|
|
2013-10-03 07:54:28 -06:00
|
|
|
static const BiomeInfo biome_stub;
|
|
|
|
|
2012-04-10 08:21:19 -06:00
|
|
|
bool valid;
|
|
|
|
bool validgeo;
|
2011-03-10 19:09:45 -07:00
|
|
|
uint32_t x_bmax;
|
|
|
|
uint32_t y_bmax;
|
|
|
|
uint32_t x_tmax;
|
|
|
|
uint32_t y_tmax;
|
|
|
|
uint32_t z_max;
|
2013-10-03 07:54:28 -06:00
|
|
|
std::vector<BiomeInfo> biomes;
|
2012-04-19 09:17:07 -06:00
|
|
|
std::map<df::coord2d, df::world_region_details*> region_details;
|
2012-03-13 14:40:38 -06:00
|
|
|
std::map<DFCoord, Block *> blocks;
|
2011-03-10 19:09:45 -07:00
|
|
|
};
|
|
|
|
}
|
2016-10-15 12:53:10 -06:00
|
|
|
#endif
|