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.
|
|
|
|
*/
|
|
|
|
|
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"
|
|
|
|
#include "df/block_square_event_mineralst.h"
|
2012-03-13 14:40:38 -06:00
|
|
|
#include "df/construction.h"
|
2012-01-19 20:44:17 -07:00
|
|
|
using namespace DFHack;
|
2011-03-10 19:09:45 -07:00
|
|
|
namespace MapExtras
|
|
|
|
{
|
2012-01-19 20:44:17 -07:00
|
|
|
void SquashVeins (DFCoord bcoord, mapblock40d & mb, t_blockmaterials & materials)
|
2011-03-10 19:09:45 -07:00
|
|
|
{
|
|
|
|
memset(materials,-1,sizeof(materials));
|
2012-01-19 13:11:52 -07:00
|
|
|
std::vector <df::block_square_event_mineralst *> veins;
|
2012-01-19 20:44:17 -07:00
|
|
|
Maps::SortBlockEvents(bcoord.x,bcoord.y,bcoord.z,&veins);
|
2012-03-13 14:40:38 -06:00
|
|
|
for (uint32_t x = 0;x<16;x++) for (uint32_t y = 0; y< 16;y++)
|
2011-03-10 19:09:45 -07:00
|
|
|
{
|
2012-03-13 14:40:38 -06:00
|
|
|
df::tiletype tt = mb.tiletypes[x][y];
|
|
|
|
if (tileMaterial(tt) == tiletype_material::MINERAL)
|
2011-03-10 19:09:45 -07:00
|
|
|
{
|
2012-03-13 14:40:38 -06:00
|
|
|
for (size_t i = 0; i < veins.size(); i++)
|
2011-03-10 19:09:45 -07:00
|
|
|
{
|
2012-03-13 14:40:38 -06:00
|
|
|
if (veins[i]->getassignment(x,y))
|
|
|
|
materials[x][y] = veins[i]->inorganic_mat;
|
2011-03-10 19:09:45 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-13 14:40:38 -06:00
|
|
|
void SquashFrozenLiquids (DFCoord bcoord, mapblock40d & mb, tiletypes40d & frozen)
|
2011-04-10 09:01:58 -06:00
|
|
|
{
|
2012-03-13 14:40:38 -06:00
|
|
|
std::vector <df::block_square_event_frozen_liquidst *> ices;
|
|
|
|
Maps::SortBlockEvents(bcoord.x,bcoord.y,bcoord.z,NULL,&ices);
|
|
|
|
for (uint32_t x = 0; x < 16; x++) for (uint32_t y = 0; y < 16; y++)
|
2011-04-10 09:01:58 -06:00
|
|
|
{
|
2012-03-13 14:40:38 -06:00
|
|
|
df::tiletype tt = mb.tiletypes[x][y];
|
|
|
|
frozen[x][y] = tiletype::Void;
|
|
|
|
if (tileMaterial(tt) == tiletype_material::FROZEN_LIQUID)
|
2011-04-10 09:01:58 -06:00
|
|
|
{
|
2012-03-13 14:40:38 -06:00
|
|
|
for (size_t i = 0; i < ices.size(); i++)
|
2012-02-13 08:56:35 -07:00
|
|
|
{
|
2012-03-13 14:40:38 -06:00
|
|
|
df::tiletype tt2 = ices[i]->tiles[x][y];
|
|
|
|
if (tt2 != tiletype::Void)
|
|
|
|
{
|
|
|
|
frozen[x][y] = tt2;
|
|
|
|
break;
|
|
|
|
}
|
2012-02-13 08:56:35 -07:00
|
|
|
}
|
2011-04-10 09:01:58 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-13 14:40:38 -06:00
|
|
|
void SquashConstructions (DFCoord bcoord, mapblock40d & mb, tiletypes40d & constructions)
|
|
|
|
{
|
|
|
|
for (uint32_t x = 0; x < 16; x++) for (uint32_t y = 0; y < 16; y++)
|
|
|
|
{
|
|
|
|
df::tiletype tt = mb.tiletypes[x][y];
|
|
|
|
constructions[x][y] = tiletype::Void;
|
|
|
|
if (tileMaterial(tt) == tiletype_material::CONSTRUCTION)
|
|
|
|
{
|
|
|
|
DFCoord coord(bcoord.x*16 + x, bcoord.y*16 + y, bcoord.z);
|
|
|
|
df::construction *con = df::construction::find(coord);
|
|
|
|
if (con)
|
|
|
|
constructions[x][y] = con->original_tile;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SquashRocks ( std::vector< std::vector <uint16_t> > * layerassign, mapblock40d & mb, t_blockmaterials & materials)
|
|
|
|
{
|
|
|
|
// get the layer materials
|
|
|
|
for (uint32_t x = 0; x < 16; x++) for (uint32_t y = 0; y < 16; y++)
|
|
|
|
{
|
|
|
|
materials[x][y] = -1;
|
|
|
|
uint8_t test = mb.designation[x][y].bits.biome;
|
|
|
|
if ((test < sizeof(mb.biome_indices)) && (mb.biome_indices[test] < layerassign->size()))
|
|
|
|
materials[x][y] = layerassign->at(mb.biome_indices[test])[mb.designation[x][y].bits.geolayer_index];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-10 19:09:45 -07:00
|
|
|
class Block
|
|
|
|
{
|
|
|
|
public:
|
2012-03-13 14:40:38 -06:00
|
|
|
Block(DFCoord _bcoord, std::vector< std::vector <uint16_t> > * layerassign = 0)
|
2011-03-10 19:09:45 -07:00
|
|
|
{
|
|
|
|
dirty_designations = false;
|
|
|
|
dirty_tiletypes = false;
|
|
|
|
dirty_temperatures = false;
|
|
|
|
dirty_blockflags = false;
|
2011-04-27 17:36:31 -06:00
|
|
|
dirty_occupancies = false;
|
2011-03-10 19:09:45 -07:00
|
|
|
valid = false;
|
|
|
|
bcoord = _bcoord;
|
2012-01-19 20:44:17 -07:00
|
|
|
if(Maps::ReadBlock40d(bcoord.x,bcoord.y,bcoord.z,&raw))
|
2011-03-10 19:09:45 -07:00
|
|
|
{
|
2012-01-19 20:44:17 -07:00
|
|
|
Maps::ReadTemperatures(bcoord.x,bcoord.y, bcoord.z,&temp1,&temp2);
|
|
|
|
SquashVeins(bcoord,raw,veinmats);
|
2012-03-13 14:40:38 -06:00
|
|
|
SquashConstructions(bcoord, raw, contiles);
|
|
|
|
SquashFrozenLiquids(bcoord, raw, icetiles);
|
2011-04-10 09:01:58 -06:00
|
|
|
if(layerassign)
|
|
|
|
SquashRocks(layerassign,raw,basemats);
|
|
|
|
else
|
|
|
|
memset(basemats,-1,sizeof(basemats));
|
2011-03-10 19:09:45 -07:00
|
|
|
valid = true;
|
|
|
|
}
|
|
|
|
}
|
2012-01-20 03:28:00 -07:00
|
|
|
int16_t veinMaterialAt(df::coord2d p)
|
2011-03-10 19:09:45 -07:00
|
|
|
{
|
2011-04-09 22:17:11 -06:00
|
|
|
return veinmats[p.x][p.y];
|
2011-03-10 19:09:45 -07:00
|
|
|
}
|
2012-01-20 03:28:00 -07:00
|
|
|
int16_t baseMaterialAt(df::coord2d p)
|
2011-04-10 09:01:58 -06:00
|
|
|
{
|
|
|
|
return basemats[p.x][p.y];
|
|
|
|
}
|
2012-03-31 07:41:55 -06:00
|
|
|
|
|
|
|
// the clear methods are used by the floodfill in digv and digl to mark tiles which were processed
|
|
|
|
void ClearBaseMaterialAt(df::coord2d p)
|
|
|
|
{
|
|
|
|
basemats[p.x][p.y] = -1;
|
|
|
|
}
|
|
|
|
void ClearVeinMaterialAt(df::coord2d p)
|
2011-03-10 19:09:45 -07:00
|
|
|
{
|
2011-04-09 22:17:11 -06:00
|
|
|
veinmats[p.x][p.y] = -1;
|
2011-03-10 19:09:45 -07:00
|
|
|
}
|
|
|
|
|
2012-03-13 14:40:38 -06:00
|
|
|
df::tiletype BaseTileTypeAt(df::coord2d p)
|
|
|
|
{
|
|
|
|
if (contiles[p.x][p.y] != tiletype::Void)
|
|
|
|
return contiles[p.x][p.y];
|
|
|
|
else if (icetiles[p.x][p.y] != tiletype::Void)
|
|
|
|
return icetiles[p.x][p.y];
|
|
|
|
else
|
|
|
|
return raw.tiletypes[p.x][p.y];
|
|
|
|
}
|
2012-02-13 15:56:33 -07:00
|
|
|
df::tiletype TileTypeAt(df::coord2d p)
|
2011-03-10 19:09:45 -07:00
|
|
|
{
|
|
|
|
return raw.tiletypes[p.x][p.y];
|
|
|
|
}
|
2012-02-13 15:56:33 -07:00
|
|
|
bool setTiletypeAt(df::coord2d p, df::tiletype tiletype)
|
2011-03-10 19:09:45 -07:00
|
|
|
{
|
|
|
|
if(!valid) return false;
|
|
|
|
dirty_tiletypes = true;
|
|
|
|
//printf("setting block %d/%d/%d , %d %d\n",x,y,z, p.x, p.y);
|
|
|
|
raw.tiletypes[p.x][p.y] = tiletype;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-01-20 03:28:00 -07:00
|
|
|
uint16_t temperature1At(df::coord2d p)
|
2011-03-10 19:09:45 -07:00
|
|
|
{
|
|
|
|
return temp1[p.x][p.y];
|
|
|
|
}
|
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;
|
|
|
|
temp1[p.x][p.y] = temp;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-01-20 03:28:00 -07:00
|
|
|
uint16_t temperature2At(df::coord2d p)
|
2011-03-10 19:09:45 -07:00
|
|
|
{
|
|
|
|
return temp2[p.x][p.y];
|
|
|
|
}
|
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;
|
|
|
|
temp2[p.x][p.y] = temp;
|
|
|
|
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
|
|
|
{
|
|
|
|
return raw.designation[p.x][p.y];
|
|
|
|
}
|
2012-01-20 03:28:00 -07:00
|
|
|
bool setDesignationAt(df::coord2d p, df::tile_designation des)
|
2011-03-10 19:09:45 -07:00
|
|
|
{
|
|
|
|
if(!valid) return false;
|
|
|
|
dirty_designations = true;
|
|
|
|
//printf("setting block %d/%d/%d , %d %d\n",x,y,z, p.x, p.y);
|
|
|
|
raw.designation[p.x][p.y] = des;
|
2011-08-22 07:18:35 -06:00
|
|
|
if(des.bits.dig)
|
|
|
|
{
|
|
|
|
dirty_blockflags = true;
|
|
|
|
raw.blockflags.bits.designated = true;
|
|
|
|
}
|
2011-03-10 19:09:45 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-01-20 03:28:00 -07:00
|
|
|
df::tile_occupancy OccupancyAt(df::coord2d p)
|
2011-04-27 17:36:31 -06:00
|
|
|
{
|
|
|
|
return raw.occupancy[p.x][p.y];
|
|
|
|
}
|
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;
|
|
|
|
raw.occupancy[p.x][p.y] = des;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-03-13 14:40:38 -06:00
|
|
|
t_blockflags BlockFlags()
|
2011-03-10 19:09:45 -07:00
|
|
|
{
|
|
|
|
return raw.blockflags;
|
|
|
|
}
|
2012-03-13 14:40:38 -06:00
|
|
|
bool setBlockFlags(t_blockflags des)
|
2011-03-10 19:09:45 -07:00
|
|
|
{
|
|
|
|
if(!valid) return false;
|
|
|
|
dirty_blockflags = true;
|
|
|
|
//printf("setting block %d/%d/%d , %d %d\n",x,y,z, p.x, p.y);
|
|
|
|
raw.blockflags = des;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Write ()
|
|
|
|
{
|
|
|
|
if(!valid) return false;
|
|
|
|
if(dirty_designations)
|
|
|
|
{
|
2012-01-19 20:44:17 -07:00
|
|
|
Maps::WriteDesignations(bcoord.x,bcoord.y,bcoord.z, &raw.designation);
|
|
|
|
Maps::WriteDirtyBit(bcoord.x,bcoord.y,bcoord.z,true);
|
2011-03-10 19:09:45 -07:00
|
|
|
dirty_designations = false;
|
|
|
|
}
|
|
|
|
if(dirty_tiletypes)
|
|
|
|
{
|
2012-01-19 20:44:17 -07:00
|
|
|
Maps::WriteTileTypes(bcoord.x,bcoord.y,bcoord.z, &raw.tiletypes);
|
2011-03-10 19:09:45 -07:00
|
|
|
dirty_tiletypes = false;
|
|
|
|
}
|
|
|
|
if(dirty_temperatures)
|
|
|
|
{
|
2012-01-19 20:44:17 -07:00
|
|
|
Maps::WriteTemperatures(bcoord.x,bcoord.y,bcoord.z, &temp1, &temp2);
|
2011-03-10 19:09:45 -07:00
|
|
|
dirty_temperatures = false;
|
|
|
|
}
|
|
|
|
if(dirty_blockflags)
|
|
|
|
{
|
2012-01-19 20:44:17 -07:00
|
|
|
Maps::WriteBlockFlags(bcoord.x,bcoord.y,bcoord.z,raw.blockflags);
|
2011-03-10 19:09:45 -07:00
|
|
|
dirty_blockflags = false;
|
|
|
|
}
|
2011-04-27 17:36:31 -06:00
|
|
|
if(dirty_occupancies)
|
|
|
|
{
|
2012-01-19 20:44:17 -07:00
|
|
|
Maps::WriteOccupancy(bcoord.x,bcoord.y,bcoord.z,&raw.occupancy);
|
2011-04-27 17:36:31 -06:00
|
|
|
dirty_occupancies = false;
|
|
|
|
}
|
2011-03-10 19:09:45 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool valid:1;
|
|
|
|
bool dirty_designations:1;
|
|
|
|
bool dirty_tiletypes:1;
|
|
|
|
bool dirty_temperatures:1;
|
|
|
|
bool dirty_blockflags:1;
|
2011-04-27 17:36:31 -06:00
|
|
|
bool dirty_occupancies:1;
|
2012-03-13 14:40:38 -06:00
|
|
|
mapblock40d raw;
|
|
|
|
DFCoord bcoord;
|
|
|
|
t_blockmaterials veinmats;
|
|
|
|
t_blockmaterials basemats;
|
|
|
|
t_temperatures temp1;
|
|
|
|
t_temperatures temp2;
|
|
|
|
tiletypes40d contiles; // what's underneath constructions
|
|
|
|
tiletypes40d icetiles; // what's underneath ice
|
2011-03-10 19:09:45 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
class MapCache
|
|
|
|
{
|
|
|
|
public:
|
2012-01-19 20:44:17 -07:00
|
|
|
MapCache()
|
2011-03-10 19:09:45 -07:00
|
|
|
{
|
|
|
|
valid = 0;
|
2012-01-19 20:44:17 -07:00
|
|
|
Maps::getSize(x_bmax, y_bmax, z_max);
|
|
|
|
validgeo = Maps::ReadGeology( layerassign );
|
2011-03-10 19:09:45 -07:00
|
|
|
valid = true;
|
|
|
|
};
|
|
|
|
~MapCache()
|
|
|
|
{
|
2011-04-10 10:41:49 -06:00
|
|
|
trash();
|
2011-03-10 19:09:45 -07:00
|
|
|
}
|
|
|
|
bool isValid ()
|
|
|
|
{
|
|
|
|
return valid;
|
|
|
|
}
|
|
|
|
/// get the map block at a *block* coord. Block coord = tile coord / 16
|
2012-03-13 14:40:38 -06:00
|
|
|
Block * BlockAt (DFCoord blockcoord)
|
2011-03-10 19:09:45 -07:00
|
|
|
{
|
|
|
|
if(!valid)
|
|
|
|
return 0;
|
2012-03-13 14:40:38 -06:00
|
|
|
std::map <DFCoord, Block*>::iterator iter = blocks.find(blockcoord);
|
2011-03-10 19:09:45 -07:00
|
|
|
if(iter != blocks.end())
|
|
|
|
{
|
|
|
|
return (*iter).second;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-13 14:40:38 -06:00
|
|
|
if(blockcoord.x >= 0 && blockcoord.x < x_bmax &&
|
|
|
|
blockcoord.y >= 0 && blockcoord.y < y_bmax &&
|
|
|
|
blockcoord.z >= 0 && blockcoord.z < z_max)
|
2011-03-10 19:09:45 -07:00
|
|
|
{
|
2011-04-10 09:01:58 -06:00
|
|
|
Block * nblo;
|
|
|
|
if(validgeo)
|
2012-01-19 20:44:17 -07:00
|
|
|
nblo = new Block(blockcoord, &layerassign);
|
2011-04-10 09:01:58 -06:00
|
|
|
else
|
2012-01-19 20:44:17 -07:00
|
|
|
nblo = new Block(blockcoord);
|
2011-03-10 19:09:45 -07:00
|
|
|
blocks[blockcoord] = nblo;
|
|
|
|
return nblo;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2012-03-13 14:40:38 -06:00
|
|
|
df::tiletype baseTiletypeAt (DFCoord tilecoord)
|
|
|
|
{
|
|
|
|
Block * b= BlockAt(tilecoord / 16);
|
|
|
|
if(b && b->valid)
|
|
|
|
{
|
|
|
|
return b->BaseTileTypeAt(tilecoord % 16);
|
|
|
|
}
|
|
|
|
return tiletype::Void;
|
|
|
|
}
|
|
|
|
df::tiletype tiletypeAt (DFCoord tilecoord)
|
2011-03-10 19:09:45 -07:00
|
|
|
{
|
|
|
|
Block * b= BlockAt(tilecoord / 16);
|
|
|
|
if(b && b->valid)
|
|
|
|
{
|
|
|
|
return b->TileTypeAt(tilecoord % 16);
|
|
|
|
}
|
2012-02-13 15:56:33 -07:00
|
|
|
return tiletype::Void;
|
2011-03-10 19:09:45 -07:00
|
|
|
}
|
2012-03-13 14:40:38 -06:00
|
|
|
bool setTiletypeAt(DFCoord tilecoord, df::tiletype tiletype)
|
2011-03-10 19:09:45 -07:00
|
|
|
{
|
|
|
|
Block * b= BlockAt(tilecoord / 16);
|
|
|
|
if(b && b->valid)
|
|
|
|
{
|
|
|
|
b->setTiletypeAt(tilecoord % 16, tiletype);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-03-13 14:40:38 -06:00
|
|
|
uint16_t temperature1At (DFCoord tilecoord)
|
2011-03-10 19:09:45 -07:00
|
|
|
{
|
|
|
|
Block * b= BlockAt(tilecoord / 16);
|
|
|
|
if(b && b->valid)
|
|
|
|
{
|
|
|
|
return b->temperature1At(tilecoord % 16);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2012-03-13 14:40:38 -06:00
|
|
|
bool setTemp1At(DFCoord tilecoord, uint16_t temperature)
|
2011-03-10 19:09:45 -07:00
|
|
|
{
|
|
|
|
Block * b= BlockAt(tilecoord / 16);
|
|
|
|
if(b && b->valid)
|
|
|
|
{
|
|
|
|
b->setTemp1At(tilecoord % 16, temperature);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-03-13 14:40:38 -06:00
|
|
|
uint16_t temperature2At (DFCoord tilecoord)
|
2011-03-10 19:09:45 -07:00
|
|
|
{
|
|
|
|
Block * b= BlockAt(tilecoord / 16);
|
|
|
|
if(b && b->valid)
|
|
|
|
{
|
|
|
|
return b->temperature2At(tilecoord % 16);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2012-03-13 14:40:38 -06:00
|
|
|
bool setTemp2At(DFCoord tilecoord, uint16_t temperature)
|
2011-03-10 19:09:45 -07:00
|
|
|
{
|
|
|
|
Block * b= BlockAt(tilecoord / 16);
|
|
|
|
if(b && b->valid)
|
|
|
|
{
|
|
|
|
b->setTemp2At(tilecoord % 16, temperature);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-03-13 14:40:38 -06:00
|
|
|
int16_t veinMaterialAt (DFCoord tilecoord)
|
2011-03-10 19:09:45 -07:00
|
|
|
{
|
|
|
|
Block * b= BlockAt(tilecoord / 16);
|
|
|
|
if(b && b->valid)
|
|
|
|
{
|
2011-04-09 22:17:11 -06:00
|
|
|
return b->veinMaterialAt(tilecoord % 16);
|
2011-03-10 19:09:45 -07:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2012-03-13 14:40:38 -06:00
|
|
|
int16_t baseMaterialAt (DFCoord tilecoord)
|
2011-04-10 09:01:58 -06:00
|
|
|
{
|
|
|
|
Block * b= BlockAt(tilecoord / 16);
|
|
|
|
if(b && b->valid)
|
|
|
|
{
|
|
|
|
return b->baseMaterialAt(tilecoord % 16);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2012-03-31 07:41:55 -06:00
|
|
|
bool clearVeinMaterialAt (DFCoord tilecoord)
|
|
|
|
{
|
|
|
|
Block * b= BlockAt(tilecoord / 16);
|
|
|
|
if(b && b->valid)
|
|
|
|
{
|
|
|
|
b->ClearVeinMaterialAt(tilecoord % 16);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
bool clearBaseMaterialAt (DFCoord tilecoord)
|
2011-03-10 19:09:45 -07:00
|
|
|
{
|
|
|
|
Block * b= BlockAt(tilecoord / 16);
|
|
|
|
if(b && b->valid)
|
|
|
|
{
|
2012-03-31 07:41:55 -06:00
|
|
|
b->ClearBaseMaterialAt(tilecoord % 16);
|
2011-03-10 19:09:45 -07:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-03-13 14:40:38 -06:00
|
|
|
df::tile_designation designationAt (DFCoord tilecoord)
|
2011-03-10 19:09:45 -07:00
|
|
|
{
|
|
|
|
Block * b= BlockAt(tilecoord / 16);
|
|
|
|
if(b && b->valid)
|
|
|
|
{
|
|
|
|
return b->DesignationAt(tilecoord % 16);
|
|
|
|
}
|
2012-01-19 13:11:52 -07:00
|
|
|
df::tile_designation temp;
|
2011-03-10 19:09:45 -07:00
|
|
|
temp.whole = 0;
|
|
|
|
return temp;
|
|
|
|
}
|
2012-03-13 14:40:38 -06:00
|
|
|
bool setDesignationAt (DFCoord tilecoord, df::tile_designation des)
|
2011-03-10 19:09:45 -07:00
|
|
|
{
|
|
|
|
Block * b= BlockAt(tilecoord / 16);
|
|
|
|
if(b && b->valid)
|
|
|
|
{
|
|
|
|
b->setDesignationAt(tilecoord % 16, des);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-03-13 14:40:38 -06:00
|
|
|
df::tile_occupancy occupancyAt (DFCoord tilecoord)
|
2011-04-27 17:36:31 -06:00
|
|
|
{
|
|
|
|
Block * b= BlockAt(tilecoord / 16);
|
|
|
|
if(b && b->valid)
|
|
|
|
{
|
|
|
|
return b->OccupancyAt(tilecoord % 16);
|
|
|
|
}
|
2012-01-19 13:11:52 -07:00
|
|
|
df::tile_occupancy temp;
|
2011-04-27 17:36:31 -06:00
|
|
|
temp.whole = 0;
|
|
|
|
return temp;
|
|
|
|
}
|
2012-03-13 14:40:38 -06:00
|
|
|
bool setOccupancyAt (DFCoord tilecoord, df::tile_occupancy occ)
|
2011-04-27 17:36:31 -06:00
|
|
|
{
|
|
|
|
Block * b= BlockAt(tilecoord / 16);
|
|
|
|
if(b && b->valid)
|
|
|
|
{
|
|
|
|
b->setOccupancyAt(tilecoord % 16, occ);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-03-13 14:40:38 -06:00
|
|
|
bool testCoord (DFCoord tilecoord)
|
2011-03-10 19:09:45 -07:00
|
|
|
{
|
|
|
|
Block * b= BlockAt(tilecoord / 16);
|
|
|
|
if(b && b->valid)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
bool WriteAll()
|
|
|
|
{
|
2012-03-13 14:40:38 -06:00
|
|
|
std::map<DFCoord, Block *>::iterator p;
|
2011-03-10 19:09:45 -07:00
|
|
|
for(p = blocks.begin(); p != blocks.end(); p++)
|
|
|
|
{
|
|
|
|
p->second->Write();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
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();
|
|
|
|
}
|
2011-03-10 19:09:45 -07:00
|
|
|
private:
|
|
|
|
volatile bool valid;
|
2011-04-10 09:01:58 -06:00
|
|
|
volatile 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;
|
2011-07-06 04:26:18 -06:00
|
|
|
std::vector< std::vector <uint16_t> > layerassign;
|
2012-03-13 14:40:38 -06:00
|
|
|
std::map<DFCoord, Block *> blocks;
|
2011-03-10 19:09:45 -07:00
|
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|