2012-01-27 08:47:14 -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-04-02 19:52:46 -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-06-16 15:53:39 -06:00
|
|
|
|
2010-05-26 04:24:45 -06:00
|
|
|
#include "Internal.h"
|
2011-04-10 02:19:15 -06:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include <map>
|
|
|
|
#include <set>
|
2011-07-07 01:49:58 -06:00
|
|
|
#include <cstdlib>
|
2011-04-10 02:19:15 -06:00
|
|
|
using namespace std;
|
|
|
|
|
2011-12-31 04:48:42 -07:00
|
|
|
#include "modules/Maps.h"
|
|
|
|
#include "Error.h"
|
|
|
|
#include "VersionInfo.h"
|
|
|
|
#include "MemAccess.h"
|
2011-03-18 10:58:48 -06:00
|
|
|
#include "ModuleFactory.h"
|
2011-12-31 04:48:42 -07:00
|
|
|
#include "Core.h"
|
2010-04-02 19:52:46 -06:00
|
|
|
|
2012-01-19 13:11:52 -07:00
|
|
|
#include "DataDefs.h"
|
|
|
|
#include "df/world_data.h"
|
|
|
|
#include "df/world_underground_region.h"
|
2012-01-20 09:27:39 -07:00
|
|
|
#include "df/world_geo_biome.h"
|
|
|
|
#include "df/world_geo_layer.h"
|
2012-01-19 13:11:52 -07:00
|
|
|
#include "df/feature_init.h"
|
|
|
|
|
2010-04-02 19:52:46 -06:00
|
|
|
using namespace DFHack;
|
2012-01-19 20:44:17 -07:00
|
|
|
using namespace DFHack::Simple;
|
2012-01-31 09:17:27 -07:00
|
|
|
using namespace df::enums;
|
2012-01-19 20:44:17 -07:00
|
|
|
using df::global::world;
|
2011-03-18 01:53:59 -06:00
|
|
|
|
2012-01-19 13:11:52 -07:00
|
|
|
const char * DFHack::sa_feature(df::feature_type index)
|
2011-03-01 15:29:27 -07:00
|
|
|
{
|
2011-03-03 09:50:17 -07:00
|
|
|
switch(index)
|
|
|
|
{
|
2012-01-31 09:17:27 -07:00
|
|
|
case feature_type::outdoor_river:
|
2012-01-19 13:11:52 -07:00
|
|
|
return "River";
|
2012-01-31 09:17:27 -07:00
|
|
|
case feature_type::cave:
|
2012-01-19 13:11:52 -07:00
|
|
|
return "Cave";
|
2012-01-31 09:17:27 -07:00
|
|
|
case feature_type::pit:
|
2012-01-19 13:11:52 -07:00
|
|
|
return "Pit";
|
2012-01-31 09:17:27 -07:00
|
|
|
case feature_type::magma_pool:
|
2012-01-19 13:11:52 -07:00
|
|
|
return "Magma pool";
|
2012-01-31 09:17:27 -07:00
|
|
|
case feature_type::volcano:
|
2012-01-19 13:11:52 -07:00
|
|
|
return "Volcano";
|
2012-01-31 09:17:27 -07:00
|
|
|
case feature_type::deep_special_tube:
|
2012-01-19 13:11:52 -07:00
|
|
|
return "Adamantine deposit";
|
2012-01-31 09:17:27 -07:00
|
|
|
case feature_type::deep_surface_portal:
|
2012-01-19 13:11:52 -07:00
|
|
|
return "Underworld portal";
|
2012-01-31 09:17:27 -07:00
|
|
|
case feature_type::subterranean_from_layer:
|
2012-01-19 13:11:52 -07:00
|
|
|
return "Cavern";
|
2012-01-31 09:17:27 -07:00
|
|
|
case feature_type::magma_core_from_layer:
|
2012-01-19 13:11:52 -07:00
|
|
|
return "Magma sea";
|
2012-01-31 09:17:27 -07:00
|
|
|
case feature_type::feature_underworld_from_layer:
|
2012-01-19 13:11:52 -07:00
|
|
|
return "Underworld";
|
|
|
|
default:
|
|
|
|
return "Unknown/Error";
|
2011-03-03 09:50:17 -07:00
|
|
|
}
|
2011-03-01 15:29:27 -07:00
|
|
|
};
|
|
|
|
|
2012-01-19 20:44:17 -07:00
|
|
|
bool Maps::IsValid ()
|
2010-04-04 16:48:19 -06:00
|
|
|
{
|
2012-01-19 20:44:17 -07:00
|
|
|
return (world->map.block_index != NULL);
|
2010-04-04 16:48:19 -06:00
|
|
|
}
|
|
|
|
|
2010-04-11 16:48:25 -06:00
|
|
|
// getter for map size
|
|
|
|
void Maps::getSize (uint32_t& x, uint32_t& y, uint32_t& z)
|
|
|
|
{
|
2012-01-19 21:11:43 -07:00
|
|
|
if (!IsValid())
|
|
|
|
throw DFHack::Error::ModuleNotInitialized();
|
2012-01-19 13:11:52 -07:00
|
|
|
x = world->map.x_count_block;
|
|
|
|
y = world->map.y_count_block;
|
|
|
|
z = world->map.z_count_block;
|
2010-04-11 16:48:25 -06:00
|
|
|
}
|
|
|
|
|
2011-03-23 23:13:21 -06:00
|
|
|
// getter for map position
|
|
|
|
void Maps::getPosition (int32_t& x, int32_t& y, int32_t& z)
|
|
|
|
{
|
2012-01-19 21:11:43 -07:00
|
|
|
if (!IsValid())
|
|
|
|
throw DFHack::Error::ModuleNotInitialized();
|
2012-01-19 13:11:52 -07:00
|
|
|
x = world->map.region_x;
|
|
|
|
y = world->map.region_y;
|
|
|
|
z = world->map.region_z;
|
2011-03-23 23:13:21 -06:00
|
|
|
}
|
|
|
|
|
2010-04-11 16:48:25 -06:00
|
|
|
/*
|
|
|
|
* Block reading
|
|
|
|
*/
|
|
|
|
|
2012-01-19 20:44:17 -07:00
|
|
|
df::map_block *Maps::getBlock (int32_t blockx, int32_t blocky, int32_t blockz)
|
2010-04-02 19:52:46 -06:00
|
|
|
{
|
2012-01-19 21:11:43 -07:00
|
|
|
if (!IsValid())
|
|
|
|
return NULL;
|
2012-01-19 13:11:52 -07:00
|
|
|
if ((blockx < 0) || (blocky < 0) || (blockz < 0))
|
|
|
|
return NULL;
|
2012-01-19 13:57:55 -07:00
|
|
|
if ((blockx >= world->map.x_count_block) || (blocky >= world->map.y_count_block) || (blockz >= world->map.z_count_block))
|
2012-01-19 13:11:52 -07:00
|
|
|
return NULL;
|
|
|
|
return world->map.block_index[blockx][blocky][blockz];
|
|
|
|
}
|
|
|
|
|
|
|
|
df::map_block *Maps::getBlockAbs (int32_t x, int32_t y, int32_t z)
|
|
|
|
{
|
2012-01-19 21:11:43 -07:00
|
|
|
if (!IsValid())
|
|
|
|
return NULL;
|
2012-01-19 13:11:52 -07:00
|
|
|
if ((x < 0) || (y < 0) || (z < 0))
|
|
|
|
return NULL;
|
|
|
|
if ((x >= world->map.x_count) || (y >= world->map.y_count) || (z >= world->map.z_count))
|
|
|
|
return NULL;
|
|
|
|
return world->map.block_index[x >> 4][y >> 4][z];
|
2010-04-02 19:52:46 -06:00
|
|
|
}
|
|
|
|
|
2010-04-04 16:48:19 -06:00
|
|
|
bool Maps::ReadBlock40d(uint32_t x, uint32_t y, uint32_t z, mapblock40d * buffer)
|
2010-04-02 19:52:46 -06:00
|
|
|
{
|
2012-01-19 13:11:52 -07:00
|
|
|
df::map_block * block = getBlock(x,y,z);
|
2011-07-06 23:00:36 -06:00
|
|
|
if (block)
|
2010-04-02 19:52:46 -06:00
|
|
|
{
|
2011-03-23 21:39:38 -06:00
|
|
|
buffer->position = DFCoord(x,y,z);
|
2011-07-06 23:00:36 -06:00
|
|
|
memcpy(buffer->tiletypes,block->tiletype, sizeof(tiletypes40d));
|
|
|
|
memcpy(buffer->designation,block->designation, sizeof(designations40d));
|
|
|
|
memcpy(buffer->occupancy,block->occupancy, sizeof(occupancies40d));
|
|
|
|
memcpy(buffer->biome_indices,block->region_offset, sizeof(block->region_offset));
|
|
|
|
buffer->global_feature = block->global_feature;
|
|
|
|
buffer->local_feature = block->local_feature;
|
2012-01-19 13:11:52 -07:00
|
|
|
buffer->mystery = block->unk2;
|
2012-01-25 06:57:11 -07:00
|
|
|
buffer->origin = block;
|
2011-07-30 08:47:49 -06:00
|
|
|
buffer->blockflags.whole = block->flags;
|
2010-04-02 19:52:46 -06:00
|
|
|
return true;
|
|
|
|
}
|
2011-03-18 10:58:48 -06:00
|
|
|
return false;
|
2010-04-02 19:52:46 -06:00
|
|
|
}
|
|
|
|
|
2010-04-11 16:48:25 -06:00
|
|
|
/*
|
|
|
|
* Tiletypes
|
2010-06-24 23:11:26 -06:00
|
|
|
*/
|
2010-04-02 19:52:46 -06:00
|
|
|
|
2010-04-04 16:48:19 -06:00
|
|
|
bool Maps::ReadTileTypes (uint32_t x, uint32_t y, uint32_t z, tiletypes40d *buffer)
|
2010-04-02 19:52:46 -06:00
|
|
|
{
|
2012-01-19 20:44:17 -07:00
|
|
|
df::map_block *block = getBlock(x,y,z);
|
2011-07-06 23:00:36 -06:00
|
|
|
if (block)
|
2010-04-02 19:52:46 -06:00
|
|
|
{
|
2011-07-06 23:00:36 -06:00
|
|
|
memcpy(buffer, block->tiletype, sizeof(tiletypes40d));
|
2010-04-02 19:52:46 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-04-11 16:48:25 -06:00
|
|
|
bool Maps::WriteTileTypes (uint32_t x, uint32_t y, uint32_t z, tiletypes40d *buffer)
|
|
|
|
{
|
2012-01-19 20:44:17 -07:00
|
|
|
df::map_block *block = getBlock(x,y,z);
|
2011-07-06 23:00:36 -06:00
|
|
|
if (block)
|
2010-04-11 16:48:25 -06:00
|
|
|
{
|
2011-07-06 23:00:36 -06:00
|
|
|
memcpy(block->tiletype, buffer, sizeof(tiletypes40d));
|
2010-04-11 16:48:25 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2010-06-24 23:11:26 -06:00
|
|
|
* Dirty bit
|
|
|
|
*/
|
2010-04-04 16:48:19 -06:00
|
|
|
bool Maps::ReadDirtyBit(uint32_t x, uint32_t y, uint32_t z, bool &dirtybit)
|
2010-04-02 19:52:46 -06:00
|
|
|
{
|
2012-01-19 20:44:17 -07:00
|
|
|
df::map_block *block = getBlock(x,y,z);
|
2011-07-06 23:00:36 -06:00
|
|
|
if (block)
|
2010-04-02 19:52:46 -06:00
|
|
|
{
|
2012-01-31 09:17:27 -07:00
|
|
|
dirtybit = block->flags.is_set(block_flags::Designated);
|
2010-04-02 19:52:46 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2011-07-30 08:47:49 -06:00
|
|
|
|
2010-04-04 16:48:19 -06:00
|
|
|
bool Maps::WriteDirtyBit(uint32_t x, uint32_t y, uint32_t z, bool dirtybit)
|
2010-04-02 19:52:46 -06:00
|
|
|
{
|
2012-01-19 20:44:17 -07:00
|
|
|
df::map_block *block = getBlock(x,y,z);
|
2011-07-06 23:00:36 -06:00
|
|
|
if (block)
|
2010-04-02 19:52:46 -06:00
|
|
|
{
|
2012-01-31 09:17:27 -07:00
|
|
|
block->flags.set(block_flags::Designated, dirtybit);
|
2010-04-02 19:52:46 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2011-07-30 08:47:49 -06:00
|
|
|
/*
|
2010-06-24 23:11:26 -06:00
|
|
|
/*
|
|
|
|
* Block flags
|
|
|
|
*/
|
2011-07-30 08:47:49 -06:00
|
|
|
// FIXME: maybe truncates, still bullshit
|
2010-04-04 16:48:19 -06:00
|
|
|
bool Maps::ReadBlockFlags(uint32_t x, uint32_t y, uint32_t z, t_blockflags &blockflags)
|
2010-04-02 19:52:46 -06:00
|
|
|
{
|
2012-01-19 20:44:17 -07:00
|
|
|
df::map_block *block = getBlock(x,y,z);
|
2011-07-06 23:00:36 -06:00
|
|
|
if (block)
|
2010-04-02 19:52:46 -06:00
|
|
|
{
|
2011-07-30 08:47:49 -06:00
|
|
|
blockflags.whole = block->flags;
|
2010-04-02 19:52:46 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2011-07-30 08:47:49 -06:00
|
|
|
//FIXME: maybe truncated, still bullshit
|
2010-04-04 16:48:19 -06:00
|
|
|
bool Maps::WriteBlockFlags(uint32_t x, uint32_t y, uint32_t z, t_blockflags blockflags)
|
2010-04-02 19:52:46 -06:00
|
|
|
{
|
2012-01-19 20:44:17 -07:00
|
|
|
df::map_block *block = getBlock(x,y,z);
|
2011-07-06 23:00:36 -06:00
|
|
|
if (block)
|
2010-04-02 19:52:46 -06:00
|
|
|
{
|
2011-07-30 08:47:49 -06:00
|
|
|
return (block->flags = blockflags.whole);
|
2010-04-02 19:52:46 -06:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-04-11 16:48:25 -06:00
|
|
|
/*
|
|
|
|
* Designations
|
2010-06-24 23:11:26 -06:00
|
|
|
*/
|
2010-04-04 16:48:19 -06:00
|
|
|
bool Maps::ReadDesignations (uint32_t x, uint32_t y, uint32_t z, designations40d *buffer)
|
2010-04-02 19:52:46 -06:00
|
|
|
{
|
2012-01-19 20:44:17 -07:00
|
|
|
df::map_block *block = getBlock(x,y,z);
|
2011-07-06 23:00:36 -06:00
|
|
|
if (block)
|
2010-04-02 19:52:46 -06:00
|
|
|
{
|
2011-07-06 23:00:36 -06:00
|
|
|
memcpy(buffer, block->designation, sizeof(designations40d));
|
2010-04-02 19:52:46 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-04-11 16:48:25 -06:00
|
|
|
bool Maps::WriteDesignations (uint32_t x, uint32_t y, uint32_t z, designations40d *buffer)
|
2010-04-02 19:52:46 -06:00
|
|
|
{
|
2012-01-19 20:44:17 -07:00
|
|
|
df::map_block *block = getBlock(x,y,z);
|
2011-07-06 23:00:36 -06:00
|
|
|
if (block)
|
2010-04-02 19:52:46 -06:00
|
|
|
{
|
2011-07-06 23:00:36 -06:00
|
|
|
memcpy(block->designation, buffer, sizeof(designations40d));
|
2010-04-02 19:52:46 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-04-11 16:48:25 -06:00
|
|
|
/*
|
|
|
|
* Occupancies
|
2010-06-24 23:11:26 -06:00
|
|
|
*/
|
2010-04-11 16:48:25 -06:00
|
|
|
bool Maps::ReadOccupancy (uint32_t x, uint32_t y, uint32_t z, occupancies40d *buffer)
|
2010-04-02 19:52:46 -06:00
|
|
|
{
|
2012-01-19 20:44:17 -07:00
|
|
|
df::map_block *block = getBlock(x,y,z);
|
2011-07-06 23:00:36 -06:00
|
|
|
if (block)
|
2010-04-02 19:52:46 -06:00
|
|
|
{
|
2011-07-06 23:00:36 -06:00
|
|
|
memcpy(buffer, block->occupancy, sizeof(occupancies40d));
|
2010-04-02 19:52:46 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-04-11 16:48:25 -06:00
|
|
|
bool Maps::WriteOccupancy (uint32_t x, uint32_t y, uint32_t z, occupancies40d *buffer)
|
|
|
|
{
|
2012-01-19 20:44:17 -07:00
|
|
|
df::map_block *block = getBlock(x,y,z);
|
2011-07-06 23:00:36 -06:00
|
|
|
if (block)
|
2010-04-11 16:48:25 -06:00
|
|
|
{
|
2011-07-06 23:00:36 -06:00
|
|
|
memcpy(block->occupancy, buffer, sizeof(occupancies40d));
|
2010-04-11 16:48:25 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2010-04-04 21:29:46 -06:00
|
|
|
|
2010-04-17 07:30:25 -06:00
|
|
|
/*
|
|
|
|
* Temperatures
|
2010-06-24 23:11:26 -06:00
|
|
|
*/
|
2010-04-17 07:30:25 -06:00
|
|
|
bool Maps::ReadTemperatures(uint32_t x, uint32_t y, uint32_t z, t_temperatures *temp1, t_temperatures *temp2)
|
|
|
|
{
|
2012-01-19 20:44:17 -07:00
|
|
|
df::map_block *block = getBlock(x,y,z);
|
2011-07-06 23:00:36 -06:00
|
|
|
if (block)
|
2010-04-17 07:30:25 -06:00
|
|
|
{
|
|
|
|
if(temp1)
|
2011-07-06 23:00:36 -06:00
|
|
|
memcpy(temp1, block->temperature_1, sizeof(t_temperatures));
|
2010-04-17 07:30:25 -06:00
|
|
|
if(temp2)
|
2011-07-06 23:00:36 -06:00
|
|
|
memcpy(temp2, block->temperature_2, sizeof(t_temperatures));
|
2010-04-17 07:30:25 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
bool Maps::WriteTemperatures (uint32_t x, uint32_t y, uint32_t z, t_temperatures *temp1, t_temperatures *temp2)
|
|
|
|
{
|
2012-01-19 20:44:17 -07:00
|
|
|
df::map_block *block = getBlock(x,y,z);
|
2011-07-06 23:00:36 -06:00
|
|
|
if (block)
|
2010-04-17 07:30:25 -06:00
|
|
|
{
|
|
|
|
if(temp1)
|
2011-07-06 23:00:36 -06:00
|
|
|
memcpy(block->temperature_1, temp1, sizeof(t_temperatures));
|
2010-04-17 07:30:25 -06:00
|
|
|
if(temp2)
|
2011-07-06 23:00:36 -06:00
|
|
|
memcpy(block->temperature_2, temp2, sizeof(t_temperatures));
|
2010-04-17 07:30:25 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-04-11 16:48:25 -06:00
|
|
|
/*
|
|
|
|
* Region Offsets - used for layer geology
|
2010-08-20 06:10:05 -06:00
|
|
|
*/
|
2010-04-04 16:48:19 -06:00
|
|
|
bool Maps::ReadRegionOffsets (uint32_t x, uint32_t y, uint32_t z, biome_indices40d *buffer)
|
2010-04-02 19:52:46 -06:00
|
|
|
{
|
2012-01-19 20:44:17 -07:00
|
|
|
df::map_block *block = getBlock(x,y,z);
|
2011-07-06 23:00:36 -06:00
|
|
|
if (block)
|
2010-04-02 19:52:46 -06:00
|
|
|
{
|
2011-07-06 23:00:36 -06:00
|
|
|
memcpy(buffer, block->region_offset,sizeof(biome_indices40d));
|
2010-04-02 19:52:46 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2012-01-19 20:44:17 -07:00
|
|
|
|
|
|
|
bool Maps::GetGlobalFeature(t_feature &feature, int32_t index)
|
2011-03-23 21:20:34 -06:00
|
|
|
{
|
2012-01-19 20:44:17 -07:00
|
|
|
feature.type = (df::feature_type)-1;
|
2012-01-19 21:11:43 -07:00
|
|
|
if (!world->world_data)
|
|
|
|
return false;
|
2012-01-19 20:44:17 -07:00
|
|
|
|
|
|
|
if ((index < 0) || (index >= world->world_data->underground_regions.size()))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
df::feature_init *f = world->world_data->underground_regions[index]->feature_init;
|
|
|
|
|
|
|
|
feature.discovered = false;
|
|
|
|
feature.origin = f;
|
|
|
|
feature.type = f->getType();
|
|
|
|
f->getMaterial(&feature.main_material, &feature.sub_material);
|
|
|
|
return true;
|
2011-03-23 21:20:34 -06:00
|
|
|
}
|
2010-04-04 21:29:46 -06:00
|
|
|
|
2012-01-20 03:28:00 -07:00
|
|
|
bool Maps::GetLocalFeature(t_feature &feature, df::coord2d coord, int32_t index)
|
2011-03-23 21:00:23 -06:00
|
|
|
{
|
2012-01-19 20:44:17 -07:00
|
|
|
feature.type = (df::feature_type)-1;
|
2012-01-19 21:11:43 -07:00
|
|
|
if (!world->world_data)
|
|
|
|
return false;
|
2011-05-07 19:36:26 -06:00
|
|
|
|
2011-05-07 01:07:28 -06:00
|
|
|
// regionX and regionY are in embark squares!
|
|
|
|
// we convert to full region tiles
|
|
|
|
// this also works in adventure mode
|
|
|
|
// region X coord - whole regions
|
2012-01-19 20:44:17 -07:00
|
|
|
uint32_t region_x = ( (coord.x / 3) + world->map.region_x ) / 16;
|
|
|
|
// region Y coord - whole regions
|
|
|
|
uint32_t region_y = ( (coord.y / 3) + world->map.region_y ) / 16;
|
2011-03-23 21:00:23 -06:00
|
|
|
|
2012-01-19 20:44:17 -07:00
|
|
|
uint32_t bigregion_x = region_x / 16;
|
|
|
|
uint32_t bigregion_y = region_y / 16;
|
2012-01-19 13:11:52 -07:00
|
|
|
|
2012-01-19 20:44:17 -07:00
|
|
|
uint32_t sub_x = region_x % 16;
|
|
|
|
uint32_t sub_y = region_y % 16;
|
|
|
|
// megaregions = 16x16 squares of regions = 256x256 squares of embark squares
|
2011-03-23 21:00:23 -06:00
|
|
|
|
2012-01-19 20:44:17 -07:00
|
|
|
// bigregion is 16x16 regions. for each bigregion in X dimension:
|
|
|
|
if (!world->world_data->unk_204[bigregion_x][bigregion_y].features)
|
|
|
|
return false;
|
2011-03-23 21:00:23 -06:00
|
|
|
|
2012-01-19 20:44:17 -07:00
|
|
|
vector <df::feature_init *> &features = world->world_data->unk_204[bigregion_x][bigregion_y].features->feature_init[sub_x][sub_y];
|
|
|
|
if ((index < 0) || (index >= features.size()))
|
|
|
|
return false;
|
|
|
|
df::feature_init *f = features[index];
|
|
|
|
|
|
|
|
feature.discovered = false;
|
|
|
|
feature.origin = f;
|
|
|
|
feature.type = f->getType();
|
|
|
|
f->getMaterial(&feature.main_material, &feature.sub_material);
|
|
|
|
return true;
|
2011-03-23 21:00:23 -06:00
|
|
|
}
|
|
|
|
|
2012-01-19 20:44:17 -07:00
|
|
|
bool Maps::ReadFeatures(uint32_t x, uint32_t y, uint32_t z, int32_t & local, int32_t & global)
|
2010-04-26 10:12:00 -06:00
|
|
|
{
|
2012-01-19 20:44:17 -07:00
|
|
|
df::map_block *block = getBlock(x,y,z);
|
2011-07-06 23:00:36 -06:00
|
|
|
if (block)
|
2010-04-26 10:12:00 -06:00
|
|
|
{
|
2011-07-06 23:00:36 -06:00
|
|
|
local = block->local_feature;
|
|
|
|
global = block->global_feature;
|
2010-04-26 10:12:00 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-01-19 20:44:17 -07:00
|
|
|
bool Maps::WriteFeatures(uint32_t x, uint32_t y, uint32_t z, const int32_t & local, const int32_t & global)
|
2011-05-12 21:00:29 -06:00
|
|
|
{
|
2012-01-19 20:44:17 -07:00
|
|
|
df::map_block *block = getBlock(x,y,z);
|
2011-07-06 23:00:36 -06:00
|
|
|
if (block)
|
2011-05-12 21:00:29 -06:00
|
|
|
{
|
2011-07-06 23:00:36 -06:00
|
|
|
block->local_feature = local;
|
|
|
|
block->global_feature = global;
|
2011-05-12 21:00:29 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-01-19 20:44:17 -07:00
|
|
|
bool Maps::ReadFeatures(uint32_t x, uint32_t y, uint32_t z, t_feature *local, t_feature *global)
|
2011-03-23 21:00:23 -06:00
|
|
|
{
|
2012-01-19 20:44:17 -07:00
|
|
|
int32_t loc, glob;
|
|
|
|
if (!ReadFeatures(x, y, z, loc, glob))
|
|
|
|
return false;
|
2011-03-23 21:39:38 -06:00
|
|
|
|
2012-01-19 20:44:17 -07:00
|
|
|
bool result = true;
|
|
|
|
if (global)
|
|
|
|
{
|
|
|
|
if (glob != -1)
|
|
|
|
result &= GetGlobalFeature(*global, glob);
|
|
|
|
else
|
|
|
|
global->type = (df::feature_type)-1;
|
|
|
|
}
|
|
|
|
if (local)
|
2011-03-23 21:00:23 -06:00
|
|
|
{
|
2012-01-19 20:44:17 -07:00
|
|
|
if (loc != -1)
|
2011-03-23 21:00:23 -06:00
|
|
|
{
|
2012-01-20 03:28:00 -07:00
|
|
|
df::coord2d coord(x,y);
|
2012-01-19 20:44:17 -07:00
|
|
|
result &= GetLocalFeature(*local, coord, loc);
|
2011-03-23 21:00:23 -06:00
|
|
|
}
|
2012-01-19 20:44:17 -07:00
|
|
|
else
|
|
|
|
local->type = (df::feature_type)-1;
|
2011-03-23 21:00:23 -06:00
|
|
|
}
|
2012-01-19 20:44:17 -07:00
|
|
|
return result;
|
2011-03-23 21:39:38 -06:00
|
|
|
}
|
|
|
|
|
2012-01-19 20:44:17 -07:00
|
|
|
bool Maps::ReadFeatures(mapblock40d * block, t_feature * local, t_feature * global)
|
|
|
|
{
|
2012-01-19 21:11:43 -07:00
|
|
|
bool result = true;
|
2012-01-19 20:44:17 -07:00
|
|
|
if (global)
|
2011-03-23 21:39:38 -06:00
|
|
|
{
|
2012-01-19 20:44:17 -07:00
|
|
|
if (block->global_feature != -1)
|
2012-01-19 21:11:43 -07:00
|
|
|
result &= GetGlobalFeature(*global, block->global_feature);
|
2012-01-20 07:30:09 -07:00
|
|
|
else
|
|
|
|
global->type = (df::feature_type)-1;
|
2012-01-19 20:44:17 -07:00
|
|
|
}
|
|
|
|
if (local)
|
|
|
|
{
|
|
|
|
if (block->local_feature != -1)
|
2012-01-19 21:11:43 -07:00
|
|
|
result &= GetLocalFeature(*local, block->position, block->local_feature);
|
2012-01-20 07:30:09 -07:00
|
|
|
else
|
|
|
|
local->type = (df::feature_type)-1;
|
2011-03-23 21:39:38 -06:00
|
|
|
}
|
2012-01-19 21:11:43 -07:00
|
|
|
return result;
|
2011-03-23 21:00:23 -06:00
|
|
|
}
|
|
|
|
|
2012-01-19 20:44:17 -07:00
|
|
|
bool Maps::SetBlockLocalFeature(uint32_t x, uint32_t y, uint32_t z, int32_t local)
|
2010-04-26 10:12:00 -06:00
|
|
|
{
|
2012-01-19 20:44:17 -07:00
|
|
|
df::map_block *block = getBlock(x,y,z);
|
2011-07-06 23:00:36 -06:00
|
|
|
if (block)
|
2010-04-26 10:12:00 -06:00
|
|
|
{
|
2011-07-06 23:00:36 -06:00
|
|
|
block->local_feature = local;
|
2010-04-26 10:12:00 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-01-19 20:44:17 -07:00
|
|
|
bool Maps::SetBlockGlobalFeature(uint32_t x, uint32_t y, uint32_t z, int32_t global)
|
2010-04-26 10:12:00 -06:00
|
|
|
{
|
2012-01-19 20:44:17 -07:00
|
|
|
df::map_block *block = getBlock(x,y,z);
|
2011-07-06 23:00:36 -06:00
|
|
|
if (block)
|
2010-04-26 10:12:00 -06:00
|
|
|
{
|
2011-07-06 23:00:36 -06:00
|
|
|
block->global_feature = global;
|
2010-04-26 10:12:00 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-04-11 16:48:25 -06:00
|
|
|
/*
|
|
|
|
* Block events
|
2010-08-20 06:10:05 -06:00
|
|
|
*/
|
2012-01-19 13:11:52 -07:00
|
|
|
bool Maps::SortBlockEvents(uint32_t x, uint32_t y, uint32_t z,
|
|
|
|
vector <df::block_square_event_mineralst *>* veins,
|
|
|
|
vector <df::block_square_event_frozen_liquidst *>* ices,
|
|
|
|
vector <df::block_square_event_material_spatterst *> *splatter,
|
2012-01-31 09:17:27 -07:00
|
|
|
vector <df::block_square_event_grassst *> *grasses,
|
2012-01-19 13:11:52 -07:00
|
|
|
vector <df::block_square_event_world_constructionst *> *constructions)
|
2010-04-02 19:52:46 -06:00
|
|
|
{
|
2012-01-19 20:44:17 -07:00
|
|
|
if (veins)
|
|
|
|
veins->clear();
|
|
|
|
if (ices)
|
|
|
|
ices->clear();
|
|
|
|
if (splatter)
|
|
|
|
splatter->clear();
|
2012-01-31 09:17:27 -07:00
|
|
|
if (grasses)
|
|
|
|
grasses->clear();
|
2012-01-19 20:44:17 -07:00
|
|
|
if (constructions)
|
|
|
|
constructions->clear();
|
2010-08-20 06:10:05 -06:00
|
|
|
|
2012-01-19 20:44:17 -07:00
|
|
|
df::map_block * block = getBlock(x,y,z);
|
2011-07-06 23:00:36 -06:00
|
|
|
if (!block)
|
|
|
|
return false;
|
2012-01-19 20:44:17 -07:00
|
|
|
|
|
|
|
// read all events
|
2012-01-31 09:55:38 -07:00
|
|
|
for (size_t i = 0; i < block->block_events.size(); i++)
|
2010-04-02 19:52:46 -06:00
|
|
|
{
|
2012-01-19 13:11:52 -07:00
|
|
|
df::block_square_event *evt = block->block_events[i];
|
|
|
|
switch (evt->getType())
|
2011-03-02 14:43:46 -07:00
|
|
|
{
|
2012-01-31 09:17:27 -07:00
|
|
|
case block_square_event_type::mineral:
|
2012-01-19 13:11:52 -07:00
|
|
|
if (veins)
|
|
|
|
veins->push_back((df::block_square_event_mineralst *)evt);
|
|
|
|
break;
|
2012-01-31 09:17:27 -07:00
|
|
|
case block_square_event_type::frozen_liquid:
|
2012-01-19 13:11:52 -07:00
|
|
|
if (ices)
|
|
|
|
ices->push_back((df::block_square_event_frozen_liquidst *)evt);
|
|
|
|
break;
|
2012-01-31 09:17:27 -07:00
|
|
|
case block_square_event_type::material_spatter:
|
2012-01-19 13:11:52 -07:00
|
|
|
if (splatter)
|
|
|
|
splatter->push_back((df::block_square_event_material_spatterst *)evt);
|
|
|
|
break;
|
2012-01-31 09:17:27 -07:00
|
|
|
case block_square_event_type::grass:
|
|
|
|
if (grasses)
|
|
|
|
grasses->push_back((df::block_square_event_grassst *)evt);
|
2012-01-19 13:11:52 -07:00
|
|
|
break;
|
2012-01-31 09:17:27 -07:00
|
|
|
case block_square_event_type::world_construction:
|
2012-01-19 13:11:52 -07:00
|
|
|
if (constructions)
|
|
|
|
constructions->push_back((df::block_square_event_world_constructionst *)evt);
|
|
|
|
break;
|
2010-04-02 19:52:46 -06:00
|
|
|
}
|
|
|
|
}
|
2011-03-02 14:43:46 -07:00
|
|
|
return true;
|
2010-04-02 19:52:46 -06:00
|
|
|
}
|
|
|
|
|
2012-01-19 13:11:52 -07:00
|
|
|
bool Maps::RemoveBlockEvent(uint32_t x, uint32_t y, uint32_t z, df::block_square_event * which)
|
2011-07-18 13:55:41 -06:00
|
|
|
{
|
2012-01-19 13:11:52 -07:00
|
|
|
df::map_block * block = getBlock(x,y,z);
|
2012-01-19 20:44:17 -07:00
|
|
|
if (!block)
|
|
|
|
return false;
|
2012-01-31 09:55:38 -07:00
|
|
|
for (size_t i = 0; i < block->block_events.size(); i++)
|
2011-07-07 01:49:58 -06:00
|
|
|
{
|
2012-01-19 20:44:17 -07:00
|
|
|
if (block->block_events[i] == which)
|
2011-07-07 01:49:58 -06:00
|
|
|
{
|
2012-01-19 20:44:17 -07:00
|
|
|
delete which;
|
|
|
|
block->block_events.erase(block->block_events.begin() + i);
|
|
|
|
return true;
|
2011-07-07 01:49:58 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2010-04-04 21:29:46 -06:00
|
|
|
}
|
|
|
|
|
2010-04-11 16:48:25 -06:00
|
|
|
/*
|
2012-01-03 17:45:11 -07:00
|
|
|
* Layer geology
|
|
|
|
*/
|
2010-04-04 21:29:46 -06:00
|
|
|
bool Maps::ReadGeology (vector < vector <uint16_t> >& assign)
|
2010-04-02 19:52:46 -06:00
|
|
|
{
|
2012-01-19 21:11:43 -07:00
|
|
|
if (!world->world_data)
|
|
|
|
return false;
|
2010-04-02 19:52:46 -06:00
|
|
|
|
2012-01-19 20:44:17 -07:00
|
|
|
vector<uint16_t> v_geology[eBiomeCount];
|
2010-04-02 19:52:46 -06:00
|
|
|
// iterate over 8 surrounding regions + local region
|
|
|
|
for (int i = eNorthWest; i < eBiomeCount; i++)
|
|
|
|
{
|
2010-04-04 21:53:38 -06:00
|
|
|
// check against worldmap boundaries, fix if needed
|
2011-03-24 10:41:34 -06:00
|
|
|
// regionX is in embark squares
|
|
|
|
// regionX/16 is in 16x16 embark square regions
|
|
|
|
// i provides -1 .. +1 offset from the current region
|
2012-01-19 13:11:52 -07:00
|
|
|
int bioRX = world->map.region_x / 16 + ((i % 3) - 1);
|
2010-04-02 19:52:46 -06:00
|
|
|
if (bioRX < 0) bioRX = 0;
|
2012-01-19 13:11:52 -07:00
|
|
|
if (bioRX >= world->world_data->world_width) bioRX = world->world_data->world_width - 1;
|
|
|
|
int bioRY = world->map.region_y / 16 + ((i / 3) - 1);
|
2010-04-02 19:52:46 -06:00
|
|
|
if (bioRY < 0) bioRY = 0;
|
2012-01-19 13:11:52 -07:00
|
|
|
if (bioRY >= world->world_data->world_height) bioRY = world->world_data->world_height - 1;
|
2010-04-02 19:52:46 -06:00
|
|
|
|
|
|
|
// get index into geoblock vector
|
2012-01-21 06:18:53 -07:00
|
|
|
uint16_t geoindex = world->world_data->region_map[bioRX][bioRY].geo_index;
|
2010-04-02 19:52:46 -06:00
|
|
|
|
2010-04-04 21:53:38 -06:00
|
|
|
/// geology blocks have a vector of layer descriptors
|
2010-04-02 19:52:46 -06:00
|
|
|
// get the vector with pointer to layers
|
2012-01-20 09:27:39 -07:00
|
|
|
df::world_geo_biome *geo_biome = df::world_geo_biome::find(geoindex);
|
|
|
|
if (!geo_biome)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
vector <df::world_geo_layer*> &geolayers = geo_biome->layers;
|
2010-04-02 19:52:46 -06:00
|
|
|
|
2010-04-04 21:53:38 -06:00
|
|
|
/// layer descriptor has a field that determines the type of stone/soil
|
2012-01-19 20:44:17 -07:00
|
|
|
v_geology[i].reserve(geolayers.size());
|
|
|
|
|
2010-04-02 19:52:46 -06:00
|
|
|
// finally, read the layer matgloss
|
2012-01-31 09:55:38 -07:00
|
|
|
for (size_t j = 0; j < geolayers.size(); j++)
|
2012-01-20 09:27:39 -07:00
|
|
|
v_geology[i].push_back(geolayers[j]->mat_index);
|
2010-04-02 19:52:46 -06:00
|
|
|
}
|
2012-01-19 20:44:17 -07:00
|
|
|
|
2010-04-02 19:52:46 -06:00
|
|
|
assign.clear();
|
2012-01-19 20:44:17 -07:00
|
|
|
assign.reserve(eBiomeCount);
|
|
|
|
for (int i = 0; i < eBiomeCount; i++)
|
|
|
|
assign.push_back(v_geology[i]);
|
2010-04-02 19:52:46 -06:00
|
|
|
return true;
|
|
|
|
}
|
2010-04-23 17:50:04 -06:00
|
|
|
|
2012-01-21 16:54:57 -07:00
|
|
|
bool Maps::ReadVegetation(uint32_t x, uint32_t y, uint32_t z, std::vector<df::plant *>*& plants)
|
2011-02-27 05:59:45 -07:00
|
|
|
{
|
2012-01-19 20:44:17 -07:00
|
|
|
df::map_block *block = getBlock(x,y,z);
|
|
|
|
if (!block)
|
2011-02-27 05:59:45 -07:00
|
|
|
return false;
|
2012-01-19 13:11:52 -07:00
|
|
|
|
2012-01-21 16:54:57 -07:00
|
|
|
plants = &block->plants;
|
2011-02-27 05:59:45 -07:00
|
|
|
return true;
|
2011-03-01 15:29:27 -07:00
|
|
|
}
|