2010-04-02 19:52:46 -06: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>
|
|
|
|
#include <cassert>
|
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"
|
|
|
|
#include "Vector.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
|
|
|
|
2010-06-16 22:46:20 -06:00
|
|
|
#define MAPS_GUARD if(!d->Started) throw DFHack::Error::ModuleNotInitialized();
|
2011-03-18 01:53:59 -06:00
|
|
|
|
2010-04-02 19:52:46 -06:00
|
|
|
using namespace DFHack;
|
|
|
|
|
2011-06-17 07:02:43 -06:00
|
|
|
Module* DFHack::createMaps()
|
2011-03-18 01:53:59 -06:00
|
|
|
{
|
2011-06-17 07:02:43 -06:00
|
|
|
return new Maps();
|
2011-03-18 01:53:59 -06:00
|
|
|
}
|
|
|
|
|
2011-03-18 04:09:26 -06:00
|
|
|
const char * DFHack::sa_feature(e_feature index)
|
2011-03-01 15:29:27 -07:00
|
|
|
{
|
2011-03-03 09:50:17 -07:00
|
|
|
switch(index)
|
|
|
|
{
|
2011-03-18 04:09:26 -06:00
|
|
|
case feature_Other:
|
2011-03-03 09:50:17 -07:00
|
|
|
return "Other";
|
2011-03-18 04:09:26 -06:00
|
|
|
case feature_Adamantine_Tube:
|
2011-03-03 09:50:17 -07:00
|
|
|
return "Adamantine Tube";
|
2011-03-18 04:09:26 -06:00
|
|
|
case feature_Underworld:
|
2011-03-03 09:50:17 -07:00
|
|
|
return "Underworld";
|
2011-03-18 04:09:26 -06:00
|
|
|
case feature_Hell_Temple:
|
2011-03-03 09:50:17 -07:00
|
|
|
return "Hell Temple";
|
|
|
|
default:
|
|
|
|
return "Unknown/Error";
|
|
|
|
}
|
2011-03-01 15:29:27 -07:00
|
|
|
};
|
|
|
|
|
2010-04-04 16:48:19 -06:00
|
|
|
struct Maps::Private
|
2010-04-02 19:52:46 -06:00
|
|
|
{
|
2010-04-04 16:48:19 -06:00
|
|
|
uint32_t worldSizeX, worldSizeY;
|
2010-04-02 19:52:46 -06:00
|
|
|
|
2010-04-04 16:48:19 -06:00
|
|
|
uint32_t maps_module;
|
2011-03-18 10:58:48 -06:00
|
|
|
struct t_offsets
|
|
|
|
{
|
2011-07-06 23:00:36 -06:00
|
|
|
// FIXME: those need a rework really. Why did Toady use virtual inheritance for such vastly different types anyway?
|
|
|
|
void * vein_mineral_vptr;
|
|
|
|
void * vein_ice_vptr;
|
|
|
|
void * vein_spatter_vptr;
|
|
|
|
void * vein_grass_vptr;
|
|
|
|
void * vein_worldconstruction_vptr;
|
2011-03-18 10:58:48 -06:00
|
|
|
/*
|
|
|
|
GEOLOGY
|
|
|
|
*/
|
|
|
|
uint32_t world_regions;// mem->getAddress ("ptr2_region_array");
|
|
|
|
uint32_t region_size;// = minfo->getHexValue ("region_size");
|
|
|
|
uint32_t region_geo_index_offset;// = minfo->getOffset ("region_geo_index_off");
|
|
|
|
uint32_t world_geoblocks_vector;// = minfo->getOffset ("geoblock_vector");
|
|
|
|
uint32_t world_size_x;// = minfo->getOffset ("world_size_x");
|
|
|
|
uint32_t world_size_y;// = minfo->getOffset ("world_size_y");
|
|
|
|
uint32_t geolayer_geoblock_offset;// = minfo->getOffset ("geolayer_geoblock_offset");
|
|
|
|
uint32_t type_inside_geolayer;// = mem->getOffset ("type_inside_geolayer");
|
|
|
|
|
|
|
|
/*
|
|
|
|
FEATURES
|
|
|
|
*/
|
2011-07-06 23:00:36 -06:00
|
|
|
// FIXME: replace with a struct pointer, eventually. needs to be mapped out first
|
2011-03-18 10:58:48 -06:00
|
|
|
uint32_t world_data;
|
2011-07-06 23:00:36 -06:00
|
|
|
uint32_t local_f_start; // offset from world_data
|
|
|
|
// FIXME: replace by virtual function call
|
2011-03-18 10:58:48 -06:00
|
|
|
uint32_t local_material;
|
2011-07-06 23:00:36 -06:00
|
|
|
// FIXME: replace by virtual function call
|
2011-03-18 10:58:48 -06:00
|
|
|
uint32_t local_submaterial;
|
2011-07-06 23:00:36 -06:00
|
|
|
uint32_t global_vector; // offset from world_data
|
2011-03-18 10:58:48 -06:00
|
|
|
uint32_t global_funcptr;
|
2011-07-06 23:00:36 -06:00
|
|
|
// FIXME: replace by virtual function call
|
2011-03-18 10:58:48 -06:00
|
|
|
uint32_t global_material;
|
2011-07-06 23:00:36 -06:00
|
|
|
// FIXME: replace by virtual function call
|
2011-03-18 10:58:48 -06:00
|
|
|
uint32_t global_submaterial;
|
|
|
|
} offsets;
|
2010-06-24 23:11:26 -06:00
|
|
|
|
2010-04-18 13:30:02 -06:00
|
|
|
Process * owner;
|
2010-08-28 07:43:53 -06:00
|
|
|
OffsetGroup *OG_vector;
|
2010-04-04 16:48:19 -06:00
|
|
|
bool Inited;
|
2011-03-23 21:00:23 -06:00
|
|
|
bool FeaturesStarted;
|
2010-04-04 16:48:19 -06:00
|
|
|
bool Started;
|
2011-02-14 16:45:37 -07:00
|
|
|
bool hasGeology;
|
|
|
|
bool hasFeatures;
|
2011-02-27 05:59:45 -07:00
|
|
|
bool hasVeggies;
|
2010-06-24 23:11:26 -06:00
|
|
|
|
2011-03-02 14:43:46 -07:00
|
|
|
set <uint32_t> unknown_veins;
|
|
|
|
|
2010-04-23 17:15:15 -06:00
|
|
|
// map between feature address and the read object
|
|
|
|
map <uint32_t, t_feature> local_feature_store;
|
2011-03-23 21:00:23 -06:00
|
|
|
map <DFCoord, vector <t_feature *> > m_local_feature;
|
|
|
|
vector <t_feature> v_global_feature;
|
2010-06-24 23:11:26 -06:00
|
|
|
|
2010-04-04 21:29:46 -06:00
|
|
|
vector<uint16_t> v_geology[eBiomeCount];
|
2010-04-04 16:48:19 -06:00
|
|
|
};
|
|
|
|
|
2011-06-17 07:02:43 -06:00
|
|
|
Maps::Maps()
|
2010-04-04 16:48:19 -06:00
|
|
|
{
|
2011-06-17 07:02:43 -06:00
|
|
|
Core & c = Core::getInstance();
|
2010-04-04 16:48:19 -06:00
|
|
|
d = new Private;
|
2011-06-17 07:02:43 -06:00
|
|
|
Process *p = d->owner = c.p;
|
2011-03-23 21:00:23 -06:00
|
|
|
d->Inited = d->FeaturesStarted = d->Started = false;
|
2010-06-24 23:11:26 -06:00
|
|
|
|
2011-06-17 07:02:43 -06:00
|
|
|
DFHack::VersionInfo * mem = c.vinfo;
|
2011-03-18 10:58:48 -06:00
|
|
|
Private::t_offsets &off = d->offsets;
|
2011-02-27 05:59:45 -07:00
|
|
|
d->hasFeatures = d->hasGeology = d->hasVeggies = true;
|
2010-06-24 23:11:26 -06:00
|
|
|
|
2010-04-02 19:52:46 -06:00
|
|
|
// get the offsets once here
|
2010-08-28 07:43:53 -06:00
|
|
|
OffsetGroup *OG_Maps = mem->getGroup("Maps");
|
2011-06-13 13:11:02 -06:00
|
|
|
off.world_data = OG_Maps->getAddress("world_data");
|
2010-08-29 16:08:17 -06:00
|
|
|
{
|
2011-07-06 23:00:36 -06:00
|
|
|
mdata = (map_data *) OG_Maps->getAddress ("map_data");
|
2011-06-13 13:11:02 -06:00
|
|
|
off.world_size_x = OG_Maps->getOffset ("world_size_x_from_wdata");
|
|
|
|
off.world_size_y = OG_Maps->getOffset ("world_size_y_from_wdata");
|
2011-02-14 16:45:37 -07:00
|
|
|
try
|
|
|
|
{
|
|
|
|
OffsetGroup *OG_Geology = OG_Maps->getGroup("geology");
|
2011-06-13 13:11:02 -06:00
|
|
|
off.world_regions = OG_Geology->getOffset ("ptr2_region_array_from_wdata");
|
|
|
|
off.world_geoblocks_vector = OG_Geology->getOffset ("geoblock_vector_from_wdata");
|
2011-03-06 12:27:40 -07:00
|
|
|
off.region_size = OG_Geology->getHexValue ("region_size");
|
|
|
|
off.region_geo_index_offset = OG_Geology->getOffset ("region_geo_index_off");
|
|
|
|
off.geolayer_geoblock_offset = OG_Geology->getOffset ("geolayer_geoblock_offset");
|
|
|
|
off.type_inside_geolayer = OG_Geology->getOffset ("type_inside_geolayer");
|
2011-02-14 16:45:37 -07:00
|
|
|
}
|
|
|
|
catch(Error::AllMemdef &)
|
|
|
|
{
|
|
|
|
d->hasGeology = false;
|
|
|
|
}
|
2011-03-06 12:27:40 -07:00
|
|
|
OffsetGroup *OG_global_features = OG_Maps->getGroup("features")->getGroup("global");
|
|
|
|
OffsetGroup *OG_local_features = OG_Maps->getGroup("features")->getGroup("local");
|
2011-02-14 16:45:37 -07:00
|
|
|
try
|
|
|
|
{
|
2011-06-13 13:11:02 -06:00
|
|
|
off.local_f_start = OG_local_features->getOffset("start_ptr_from_wdata");
|
|
|
|
off.global_vector = OG_global_features->getOffset("vector_from_wdata");
|
2011-03-06 12:27:40 -07:00
|
|
|
off.local_material = OG_local_features->getOffset("material");
|
|
|
|
off.local_submaterial = OG_local_features->getOffset("submaterial");
|
|
|
|
|
|
|
|
off.global_funcptr = OG_global_features->getOffset("funcptr");
|
|
|
|
off.global_material = OG_global_features->getOffset("material");
|
|
|
|
off.global_submaterial = OG_global_features->getOffset("submaterial");
|
2011-02-14 16:45:37 -07:00
|
|
|
}
|
|
|
|
catch(Error::AllMemdef &)
|
2010-08-29 16:08:17 -06:00
|
|
|
{
|
2011-02-14 16:45:37 -07:00
|
|
|
d->hasFeatures = false;
|
2010-08-29 16:08:17 -06:00
|
|
|
}
|
|
|
|
}
|
2010-08-28 07:43:53 -06:00
|
|
|
d->OG_vector = mem->getGroup("vector");
|
|
|
|
|
|
|
|
// these can (will) fail and will be found when looking at the actual veins later
|
2010-04-02 19:52:46 -06:00
|
|
|
// basically a cache
|
2010-04-04 16:48:19 -06:00
|
|
|
off.vein_ice_vptr = 0;
|
|
|
|
mem->resolveClassnameToVPtr("block_square_event_frozen_liquid", off.vein_ice_vptr);
|
|
|
|
off.vein_mineral_vptr = 0;
|
|
|
|
mem->resolveClassnameToVPtr("block_square_event_mineral",off.vein_mineral_vptr);
|
2011-02-16 17:54:45 -07:00
|
|
|
off.vein_spatter_vptr = 0;
|
|
|
|
mem->resolveClassnameToVPtr("block_square_event_material_spatterst",off.vein_spatter_vptr);
|
|
|
|
off.vein_grass_vptr = 0;
|
|
|
|
mem->resolveClassnameToVPtr("block_square_event_grassst",off.vein_grass_vptr);
|
2011-02-27 12:43:44 -07:00
|
|
|
off.vein_worldconstruction_vptr = 0;
|
|
|
|
mem->resolveClassnameToVPtr("block_square_event_world_constructionst",off.vein_worldconstruction_vptr);
|
2010-04-04 16:48:19 -06:00
|
|
|
d->Inited = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Maps::~Maps()
|
|
|
|
{
|
2011-03-23 21:20:34 -06:00
|
|
|
if(d->FeaturesStarted)
|
|
|
|
StopFeatures();
|
2010-04-04 16:48:19 -06:00
|
|
|
if(d->Started)
|
|
|
|
Finish();
|
2010-08-13 17:25:18 -06:00
|
|
|
delete d;
|
2010-04-04 16:48:19 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/*-----------------------------------*
|
|
|
|
* Init the mapblock pointer array *
|
|
|
|
*-----------------------------------*/
|
|
|
|
bool Maps::Start()
|
|
|
|
{
|
|
|
|
if(!d->Inited)
|
|
|
|
return false;
|
|
|
|
if(d->Started)
|
|
|
|
Finish();
|
2010-06-24 23:11:26 -06:00
|
|
|
|
2010-04-18 13:30:02 -06:00
|
|
|
Process *p = d->owner;
|
2011-03-18 10:58:48 -06:00
|
|
|
Private::t_offsets &off = d->offsets;
|
2010-06-24 23:11:26 -06:00
|
|
|
|
2011-07-06 23:00:36 -06:00
|
|
|
// is there a map?
|
|
|
|
//uint32_t x_array_loc = p->readDWord (off.map_offset);
|
|
|
|
if (!mdata->map)
|
2010-04-02 19:52:46 -06:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2010-06-24 23:11:26 -06:00
|
|
|
|
2010-04-02 19:52:46 -06:00
|
|
|
// get the size
|
2011-07-06 23:00:36 -06:00
|
|
|
uint32_t & mx = mdata->x_size_blocks;
|
|
|
|
uint32_t & my = mdata->y_size_blocks;
|
|
|
|
uint32_t & mz = mdata->z_size_blocks;
|
2010-04-02 19:52:46 -06:00
|
|
|
|
|
|
|
// test for wrong map dimensions
|
|
|
|
if (mx == 0 || mx > 48 || my == 0 || my > 48 || mz == 0)
|
|
|
|
{
|
2011-07-06 23:00:36 -06:00
|
|
|
cerr << hex << &mx << " " << &my << " " << &mz << endl;
|
2011-07-20 12:58:19 -06:00
|
|
|
cerr << dec << mx << " "<< my << " "<< mz << endl;
|
|
|
|
return false;
|
2010-04-02 19:52:46 -06:00
|
|
|
}
|
|
|
|
|
2010-04-25 12:52:57 -06:00
|
|
|
d->Started = true;
|
2010-04-02 19:52:46 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-04-11 16:48:25 -06:00
|
|
|
// getter for map size
|
|
|
|
void Maps::getSize (uint32_t& x, uint32_t& y, uint32_t& z)
|
|
|
|
{
|
2010-06-16 22:46:20 -06:00
|
|
|
MAPS_GUARD
|
2011-07-06 23:00:36 -06:00
|
|
|
x = mdata->x_size_blocks;
|
|
|
|
y = mdata->y_size_blocks;
|
|
|
|
z = mdata->z_size_blocks;
|
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)
|
|
|
|
{
|
|
|
|
MAPS_GUARD
|
2011-07-06 23:00:36 -06:00
|
|
|
x = mdata->x_area_offset;
|
|
|
|
y = mdata->y_area_offset;
|
|
|
|
z = mdata->z_area_offset;
|
2011-03-23 23:13:21 -06:00
|
|
|
}
|
|
|
|
|
2010-04-04 16:48:19 -06:00
|
|
|
bool Maps::Finish()
|
2010-04-02 19:52:46 -06:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-04-11 16:48:25 -06:00
|
|
|
/*
|
|
|
|
* Block reading
|
|
|
|
*/
|
|
|
|
|
2011-07-07 01:49:58 -06:00
|
|
|
df_block* Maps::getBlock (uint32_t x, uint32_t y, uint32_t z)
|
2010-04-02 19:52:46 -06:00
|
|
|
{
|
2010-06-16 22:46:20 -06:00
|
|
|
MAPS_GUARD
|
2011-07-06 23:00:36 -06:00
|
|
|
if(x >= mdata->x_size_blocks || y >= mdata->y_size_blocks || z >= mdata->z_size_blocks)
|
2010-04-02 19:52:46 -06:00
|
|
|
return 0;
|
2011-07-06 23:00:36 -06:00
|
|
|
return mdata->map[x][y][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
|
|
|
{
|
2010-06-16 22:46:20 -06:00
|
|
|
MAPS_GUARD
|
2010-04-18 13:30:02 -06:00
|
|
|
Process *p = d->owner;
|
2011-07-07 01:49:58 -06:00
|
|
|
df_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;
|
|
|
|
buffer->mystery = block->mystery;
|
|
|
|
// FIXME: not 64-bit safe
|
|
|
|
buffer->origin = (uint32_t) █
|
|
|
|
//uint32_t addr_of_struct = p->readDWord(addr);
|
2011-07-30 08:47:49 -06:00
|
|
|
// FIXME: maybe truncates
|
|
|
|
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
|
|
|
{
|
2010-06-16 22:46:20 -06:00
|
|
|
MAPS_GUARD
|
2011-07-07 01:49:58 -06:00
|
|
|
df_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)
|
|
|
|
{
|
2010-06-16 22:46:20 -06:00
|
|
|
MAPS_GUARD
|
2011-07-07 01:49:58 -06:00
|
|
|
df_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
|
|
|
{
|
2010-06-16 22:46:20 -06:00
|
|
|
MAPS_GUARD
|
2011-07-07 01:49:58 -06:00
|
|
|
df_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-31 19:31:52 -06:00
|
|
|
dirtybit = block->flags.is_set(BLOCK_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
|
|
|
{
|
2010-06-16 22:46:20 -06:00
|
|
|
MAPS_GUARD
|
2011-07-07 01:49:58 -06:00
|
|
|
df_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-31 19:31:52 -06:00
|
|
|
block->flags.set(BLOCK_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
|
|
|
{
|
2010-06-16 22:46:20 -06:00
|
|
|
MAPS_GUARD
|
2011-07-07 01:49:58 -06:00
|
|
|
df_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
|
|
|
{
|
2010-06-16 22:46:20 -06:00
|
|
|
MAPS_GUARD
|
2011-07-07 01:49:58 -06:00
|
|
|
df_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
|
|
|
{
|
2010-06-16 22:46:20 -06:00
|
|
|
MAPS_GUARD
|
2011-07-07 01:49:58 -06:00
|
|
|
df_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
|
|
|
{
|
2010-06-16 22:46:20 -06:00
|
|
|
MAPS_GUARD
|
2011-07-07 01:49:58 -06:00
|
|
|
df_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
|
|
|
{
|
2010-06-16 22:46:20 -06:00
|
|
|
MAPS_GUARD
|
2011-07-07 01:49:58 -06:00
|
|
|
df_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)
|
|
|
|
{
|
2010-06-16 22:46:20 -06:00
|
|
|
MAPS_GUARD
|
2011-07-07 01:49:58 -06:00
|
|
|
df_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)
|
|
|
|
{
|
2010-06-16 22:46:20 -06:00
|
|
|
MAPS_GUARD
|
2011-07-07 01:49:58 -06:00
|
|
|
df_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)
|
|
|
|
{
|
2010-06-16 22:46:20 -06:00
|
|
|
MAPS_GUARD
|
2011-07-07 01:49:58 -06:00
|
|
|
df_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
|
|
|
{
|
2010-06-16 22:46:20 -06:00
|
|
|
MAPS_GUARD
|
2011-07-07 01:49:58 -06:00
|
|
|
df_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;
|
|
|
|
}
|
2011-03-23 21:20:34 -06:00
|
|
|
bool Maps::StopFeatures()
|
|
|
|
{
|
|
|
|
if(d->FeaturesStarted)
|
|
|
|
{
|
|
|
|
d->local_feature_store.clear();
|
|
|
|
d->v_global_feature.clear();
|
|
|
|
d->m_local_feature.clear();
|
|
|
|
d->FeaturesStarted = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2010-04-04 21:29:46 -06:00
|
|
|
|
2011-03-23 21:00:23 -06:00
|
|
|
bool Maps::StartFeatures()
|
|
|
|
{
|
|
|
|
MAPS_GUARD
|
|
|
|
if(d->FeaturesStarted) return true;
|
|
|
|
if(!d->hasFeatures) return false;
|
|
|
|
// can't be used without a map!
|
2011-07-06 23:00:36 -06:00
|
|
|
if(!mdata->map)
|
2011-03-23 21:00:23 -06:00
|
|
|
return false;
|
|
|
|
|
|
|
|
Process * p = d->owner;
|
|
|
|
Private::t_offsets &off = d->offsets;
|
|
|
|
uint32_t base = 0;
|
|
|
|
uint32_t global_feature_vector = 0;
|
|
|
|
|
2011-06-13 13:11:02 -06:00
|
|
|
uint32_t world = p->readDWord(off.world_data);
|
|
|
|
if(!world) return false;
|
|
|
|
base = p->readDWord(world + off.local_f_start);
|
|
|
|
global_feature_vector = p->readDWord(off.world_data) + off.global_vector;
|
2011-03-23 21:00:23 -06:00
|
|
|
|
|
|
|
// deref pointer to the humongo-structure
|
|
|
|
if(!base)
|
|
|
|
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
|
2011-03-23 21:00:23 -06:00
|
|
|
const uint32_t sizeof_vec = d->OG_vector->getHexValue("sizeof");
|
|
|
|
const uint32_t sizeof_elem = 16;
|
|
|
|
const uint32_t offset_elem = 4;
|
|
|
|
const uint32_t loc_main_mat_offset = off.local_material;
|
|
|
|
const uint32_t loc_sub_mat_offset = off.local_submaterial;
|
2011-05-07 01:07:28 -06:00
|
|
|
const uint32_t sizeof_16vec = 16* sizeof_vec;
|
2011-03-23 21:00:23 -06:00
|
|
|
|
2011-07-06 23:00:36 -06:00
|
|
|
for(uint32_t blockX = 0; blockX < mdata->x_size_blocks; blockX ++)
|
|
|
|
for(uint32_t blockY = 0; blockY < mdata->y_size_blocks; blockY ++)
|
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
|
2011-07-06 23:00:36 -06:00
|
|
|
uint32_t region_x = ( (blockX / 3) + mdata->x_area_offset ) / 16;
|
2011-05-07 01:07:28 -06:00
|
|
|
// region Y coord - whole regions
|
2011-07-06 23:00:36 -06:00
|
|
|
uint32_t region_y = ( (blockY / 3) + mdata->y_area_offset ) / 16;
|
2011-05-07 01:07:28 -06:00
|
|
|
uint32_t bigregion_x = region_x / 16;
|
|
|
|
uint32_t bigregion_y = region_y / 16;
|
|
|
|
uint32_t sub_x = region_x % 16;
|
|
|
|
uint32_t sub_y = region_y % 16;
|
|
|
|
// megaregions = 16x16 squares of regions = 256x256 squares of embark squares
|
|
|
|
|
|
|
|
// base = pointer to local feature structure (inside world data struct)
|
|
|
|
// bigregion is 16x16 regions. for each bigregion in X dimension:
|
|
|
|
uint32_t mega_column = p->readDWord(base + bigregion_x * 4);
|
2011-03-23 21:00:23 -06:00
|
|
|
|
|
|
|
// 16B structs, second DWORD of the struct is a pointer
|
2011-05-07 01:07:28 -06:00
|
|
|
uint32_t loc_f_array16x16 = p->readDWord(mega_column + offset_elem + (sizeof_elem * bigregion_y));
|
2011-03-24 10:41:34 -06:00
|
|
|
if(loc_f_array16x16)
|
2011-03-23 21:00:23 -06:00
|
|
|
{
|
2011-05-07 01:07:28 -06:00
|
|
|
uint32_t feat_vector = loc_f_array16x16 + sizeof_16vec * sub_x + sizeof_vec * sub_y;
|
2011-06-12 17:14:10 -06:00
|
|
|
DfVector<uint32_t> p_features(feat_vector);
|
2011-03-23 21:00:23 -06:00
|
|
|
uint32_t size = p_features.size();
|
|
|
|
DFCoord pc(blockX,blockY);
|
|
|
|
std::vector<t_feature *> tempvec;
|
|
|
|
for(uint32_t i = 0; i < size; i++)
|
|
|
|
{
|
|
|
|
uint32_t cur_ptr = p_features[i];
|
|
|
|
|
|
|
|
map <uint32_t, t_feature>::iterator it;
|
|
|
|
it = d->local_feature_store.find(cur_ptr);
|
|
|
|
// do we already have the feature?
|
|
|
|
if(it != d->local_feature_store.end())
|
|
|
|
{
|
|
|
|
// push pointer to existing feature
|
|
|
|
tempvec.push_back(&((*it).second));
|
|
|
|
}
|
|
|
|
// no?
|
|
|
|
else
|
|
|
|
{
|
2011-05-07 12:23:31 -06:00
|
|
|
//FIXME: replace with accessors
|
2011-03-23 21:00:23 -06:00
|
|
|
// create, add to store
|
|
|
|
t_feature tftemp;
|
|
|
|
tftemp.discovered = false; //= p->readDWord(cur_ptr + 4);
|
|
|
|
tftemp.origin = cur_ptr;
|
2011-07-06 23:00:36 -06:00
|
|
|
string name = p->readClassName((void *)p->readDWord( cur_ptr ));
|
2011-03-23 21:00:23 -06:00
|
|
|
if(name == "feature_init_deep_special_tubest")
|
|
|
|
{
|
|
|
|
tftemp.main_material = p->readWord( cur_ptr + loc_main_mat_offset );
|
|
|
|
tftemp.sub_material = p->readDWord( cur_ptr + loc_sub_mat_offset );
|
|
|
|
tftemp.type = feature_Adamantine_Tube;
|
|
|
|
}
|
|
|
|
else if(name == "feature_init_deep_surface_portalst")
|
|
|
|
{
|
|
|
|
tftemp.main_material = p->readWord( cur_ptr + loc_main_mat_offset );
|
|
|
|
tftemp.sub_material = p->readDWord( cur_ptr + loc_sub_mat_offset );
|
|
|
|
tftemp.type = feature_Hell_Temple;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tftemp.main_material = -1;
|
|
|
|
tftemp.sub_material = -1;
|
|
|
|
tftemp.type = feature_Other;
|
|
|
|
}
|
|
|
|
d->local_feature_store[cur_ptr] = tftemp;
|
|
|
|
// push pointer
|
|
|
|
tempvec.push_back(&(d->local_feature_store[cur_ptr]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
d->m_local_feature[pc] = tempvec;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// deref pointer to the humongo-structure
|
|
|
|
const uint32_t global_feature_funcptr = off.global_funcptr;
|
|
|
|
const uint32_t glob_main_mat_offset = off.global_material;
|
|
|
|
const uint32_t glob_sub_mat_offset = off.global_submaterial;
|
2011-06-12 17:14:10 -06:00
|
|
|
DfVector<uint32_t> p_features (global_feature_vector);
|
2011-03-23 21:00:23 -06:00
|
|
|
|
|
|
|
d->v_global_feature.clear();
|
|
|
|
uint32_t size = p_features.size();
|
|
|
|
d->v_global_feature.reserve(size);
|
|
|
|
for(uint32_t i = 0; i < size; i++)
|
|
|
|
{
|
|
|
|
t_feature temp;
|
|
|
|
uint32_t feat_ptr = p->readDWord(p_features[i] + global_feature_funcptr );
|
|
|
|
temp.origin = feat_ptr;
|
|
|
|
//temp.discovered = p->readDWord( feat_ptr + 4 ); // maybe, placeholder
|
|
|
|
temp.discovered = false;
|
|
|
|
|
|
|
|
// FIXME: use the memory_info cache mechanisms
|
2011-07-06 23:00:36 -06:00
|
|
|
string name = p->readClassName((void *)p->readDWord( feat_ptr));
|
2011-03-23 21:00:23 -06:00
|
|
|
if(name == "feature_init_underworld_from_layerst")
|
|
|
|
{
|
|
|
|
temp.main_material = p->readWord( feat_ptr + glob_main_mat_offset );
|
|
|
|
temp.sub_material = p->readDWord( feat_ptr + glob_sub_mat_offset );
|
|
|
|
temp.type = feature_Underworld;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
temp.main_material = -1;
|
|
|
|
temp.sub_material = -1;
|
|
|
|
temp.type = feature_Other;
|
|
|
|
}
|
|
|
|
d->v_global_feature.push_back(temp);
|
|
|
|
}
|
|
|
|
d->FeaturesStarted = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
t_feature * Maps::GetGlobalFeature(int16_t index)
|
|
|
|
{
|
|
|
|
if(!d->FeaturesStarted) return 0;
|
2011-05-15 14:24:40 -06:00
|
|
|
if(index < 0 || uint16_t(index) >= d->v_global_feature.size())
|
2011-03-23 21:00:23 -06:00
|
|
|
return 0;
|
|
|
|
return &(d->v_global_feature[index]);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector <t_feature *> * Maps::GetLocalFeatures(DFCoord coord)
|
|
|
|
{
|
|
|
|
if(!d->FeaturesStarted) return 0;
|
|
|
|
coord.z = 0; // just making sure
|
|
|
|
map <DFCoord, std::vector <t_feature* > >::iterator iter = d->m_local_feature.find(coord);
|
|
|
|
if(iter != d->m_local_feature.end())
|
|
|
|
{
|
|
|
|
return &((*iter).second);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-04-26 10:12:00 -06:00
|
|
|
bool Maps::ReadFeatures(uint32_t x, uint32_t y, uint32_t z, int16_t & local, int16_t & global)
|
|
|
|
{
|
2010-06-16 22:46:20 -06:00
|
|
|
MAPS_GUARD
|
2011-07-07 01:49:58 -06:00
|
|
|
df_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;
|
|
|
|
}
|
|
|
|
|
2011-05-12 21:00:29 -06:00
|
|
|
bool Maps::WriteFeatures(uint32_t x, uint32_t y, uint32_t z, const int16_t & local, const int16_t & global)
|
|
|
|
{
|
|
|
|
MAPS_GUARD
|
2011-07-07 01:49:58 -06:00
|
|
|
df_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;
|
|
|
|
}
|
|
|
|
|
2011-03-23 21:00:23 -06:00
|
|
|
bool Maps::ReadFeatures(uint32_t x, uint32_t y, uint32_t z, t_feature ** local, t_feature ** global)
|
|
|
|
{
|
|
|
|
if(!d->FeaturesStarted) return false;
|
|
|
|
int16_t loc, glob;
|
2011-03-23 21:39:38 -06:00
|
|
|
if(!ReadFeatures(x,y,z,loc,glob)) return false;
|
|
|
|
|
|
|
|
if(global && glob != -1)
|
|
|
|
*global = &(d->v_global_feature[glob]);
|
|
|
|
else if (global)
|
|
|
|
*global = 0;
|
|
|
|
|
|
|
|
if(local && loc != -1)
|
2011-03-23 21:00:23 -06:00
|
|
|
{
|
2011-03-23 21:39:38 -06:00
|
|
|
DFCoord foo(x,y,0);
|
|
|
|
map <DFCoord, std::vector <t_feature* > >::iterator iter = d->m_local_feature.find(foo);
|
|
|
|
if(iter != d->m_local_feature.end())
|
2011-03-23 21:00:23 -06:00
|
|
|
{
|
2011-03-23 21:39:38 -06:00
|
|
|
*local = ((*iter).second)[loc];
|
2011-03-23 21:00:23 -06:00
|
|
|
}
|
2011-03-23 21:39:38 -06:00
|
|
|
else *local = 0;
|
2011-03-23 21:00:23 -06:00
|
|
|
}
|
2011-03-23 21:39:38 -06:00
|
|
|
else if(local)
|
|
|
|
*local = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Maps::ReadFeatures(mapblock40d * block, t_feature ** local, t_feature ** global)
|
|
|
|
{
|
|
|
|
if(!block) return false;
|
|
|
|
if(!d->FeaturesStarted) return false;
|
|
|
|
DFCoord c = block->position;
|
|
|
|
c.z = 0;
|
2011-05-07 01:07:28 -06:00
|
|
|
*global = 0;
|
|
|
|
*local = 0;
|
|
|
|
if(block->global_feature != -1)
|
2011-03-23 21:39:38 -06:00
|
|
|
*global = &(d->v_global_feature[block->global_feature]);
|
|
|
|
if(local && block->local_feature != -1)
|
|
|
|
{
|
|
|
|
map <DFCoord, std::vector <t_feature* > >::iterator iter = d->m_local_feature.find(c);
|
|
|
|
if(iter != d->m_local_feature.end())
|
|
|
|
{
|
|
|
|
*local = ((*iter).second)[block->local_feature];
|
|
|
|
}
|
|
|
|
else *local = 0;
|
|
|
|
}
|
|
|
|
return true;
|
2011-03-23 21:00:23 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Maps::SetBlockLocalFeature(uint32_t x, uint32_t y, uint32_t z, int16_t local)
|
2010-04-26 10:12:00 -06:00
|
|
|
{
|
2010-06-16 22:46:20 -06:00
|
|
|
MAPS_GUARD
|
2011-07-07 01:49:58 -06:00
|
|
|
df_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;
|
|
|
|
}
|
|
|
|
|
2011-03-23 21:00:23 -06:00
|
|
|
bool Maps::SetBlockGlobalFeature(uint32_t x, uint32_t y, uint32_t z, int16_t global)
|
2010-04-26 10:12:00 -06:00
|
|
|
{
|
2010-06-16 22:46:20 -06:00
|
|
|
MAPS_GUARD
|
2011-07-07 01:49:58 -06:00
|
|
|
df_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
|
|
|
*/
|
2011-07-07 01:49:58 -06:00
|
|
|
bool Maps::SortBlockEvents(uint32_t x, uint32_t y, uint32_t z, vector <t_vein *>* veins, vector <t_frozenliquidvein *>* ices, vector <t_spattervein *> *splatter, vector <t_grassvein *> *grass, vector <t_worldconstruction *> *constructions)
|
2010-04-02 19:52:46 -06:00
|
|
|
{
|
2010-06-16 22:46:20 -06:00
|
|
|
MAPS_GUARD
|
2010-04-18 13:30:02 -06:00
|
|
|
Process* p = d->owner;
|
2010-08-20 06:10:05 -06:00
|
|
|
|
2011-07-07 01:49:58 -06:00
|
|
|
df_block * block = getBlock(x,y,z);
|
2010-04-10 18:08:21 -06:00
|
|
|
if(veins) veins->clear();
|
|
|
|
if(ices) ices->clear();
|
|
|
|
if(splatter) splatter->clear();
|
2011-07-13 20:05:27 -06:00
|
|
|
if(grass) grass->clear();
|
2011-02-27 12:43:44 -07:00
|
|
|
if(constructions) constructions->clear();
|
2010-08-20 06:10:05 -06:00
|
|
|
|
2011-03-18 10:58:48 -06:00
|
|
|
Private::t_offsets &off = d->offsets;
|
2011-07-06 23:00:36 -06:00
|
|
|
if (!block)
|
|
|
|
return false;
|
|
|
|
uint32_t size = block->block_events.size();
|
2011-03-02 14:43:46 -07:00
|
|
|
// read all veins
|
|
|
|
for (uint32_t i = 0; i < size;i++)
|
2010-04-02 19:52:46 -06:00
|
|
|
{
|
2011-03-10 19:09:45 -07:00
|
|
|
retry:
|
2011-03-02 14:43:46 -07:00
|
|
|
// read the vein pointer from the vector
|
2011-07-06 23:00:36 -06:00
|
|
|
t_virtual * temp = block->block_events[i];
|
|
|
|
void * type = temp->vptr;
|
|
|
|
if(type == (void *) off.vein_mineral_vptr)
|
2011-03-02 14:43:46 -07:00
|
|
|
{
|
2011-03-24 23:40:33 -06:00
|
|
|
if(!veins) continue;
|
2011-03-02 14:43:46 -07:00
|
|
|
// store it in the vector
|
2011-07-06 23:00:36 -06:00
|
|
|
veins->push_back ((t_vein *) temp);
|
2011-03-02 14:43:46 -07:00
|
|
|
}
|
2011-07-06 23:00:36 -06:00
|
|
|
else if(type == (void *) off.vein_ice_vptr)
|
2010-04-02 19:52:46 -06:00
|
|
|
{
|
2011-03-24 23:40:33 -06:00
|
|
|
if(!ices) continue;
|
2011-07-06 23:00:36 -06:00
|
|
|
ices->push_back ((t_frozenliquidvein *) temp);
|
2011-03-02 14:43:46 -07:00
|
|
|
}
|
2011-07-06 23:00:36 -06:00
|
|
|
else if(type == (void *) off.vein_spatter_vptr)
|
2011-03-02 14:43:46 -07:00
|
|
|
{
|
2011-03-24 23:40:33 -06:00
|
|
|
if(!splatter) continue;
|
2011-07-06 23:00:36 -06:00
|
|
|
splatter->push_back ( (t_spattervein *)temp);
|
2011-03-02 14:43:46 -07:00
|
|
|
}
|
2011-07-06 23:00:36 -06:00
|
|
|
else if(type == (void *) off.vein_grass_vptr)
|
2011-03-02 14:43:46 -07:00
|
|
|
{
|
2011-03-24 23:40:33 -06:00
|
|
|
if(!grass) continue;
|
2011-07-06 23:00:36 -06:00
|
|
|
grass->push_back ((t_grassvein *) temp);
|
2011-03-02 14:43:46 -07:00
|
|
|
}
|
2011-07-06 23:00:36 -06:00
|
|
|
else if(type == (void *) off.vein_worldconstruction_vptr)
|
2011-03-02 14:43:46 -07:00
|
|
|
{
|
2011-03-24 23:40:33 -06:00
|
|
|
if(!constructions) continue;
|
2011-07-06 23:00:36 -06:00
|
|
|
constructions->push_back ((t_worldconstruction *) temp);
|
2011-03-02 14:43:46 -07:00
|
|
|
}
|
2011-03-24 23:40:33 -06:00
|
|
|
// previously unseen type of vein
|
2011-03-02 14:43:46 -07:00
|
|
|
else
|
|
|
|
{
|
|
|
|
string cname = p->readClassName(type);
|
2011-07-20 02:41:13 -06:00
|
|
|
//string cname = typeid(*(blockevent *)temp).name();
|
|
|
|
//Core::getInstance().con.printerr("%s\n",cname.c_str());
|
2011-03-10 19:09:45 -07:00
|
|
|
if(!off.vein_ice_vptr && cname == "block_square_event_frozen_liquidst")
|
2010-04-02 19:52:46 -06:00
|
|
|
{
|
2011-03-02 14:43:46 -07:00
|
|
|
off.vein_ice_vptr = type;
|
2011-07-21 18:44:36 -06:00
|
|
|
//Core::getInstance().con.printerr("%s %x\n",cname.c_str(), type);
|
2011-03-10 19:09:45 -07:00
|
|
|
goto retry;
|
2010-04-02 19:52:46 -06:00
|
|
|
}
|
2011-03-10 19:09:45 -07:00
|
|
|
else if(!off.vein_mineral_vptr &&cname == "block_square_event_mineralst")
|
2010-04-02 19:52:46 -06:00
|
|
|
{
|
2011-03-02 14:43:46 -07:00
|
|
|
off.vein_mineral_vptr = type;
|
2011-07-21 18:44:36 -06:00
|
|
|
//Core::getInstance().con.printerr("%s %x\n",cname.c_str(), type);
|
2011-03-10 19:09:45 -07:00
|
|
|
goto retry;
|
2010-04-02 19:52:46 -06:00
|
|
|
}
|
2011-03-10 19:09:45 -07:00
|
|
|
else if(!off.vein_spatter_vptr && cname == "block_square_event_material_spatterst")
|
2010-04-07 14:28:05 -06:00
|
|
|
{
|
2011-03-02 14:43:46 -07:00
|
|
|
off.vein_spatter_vptr = type;
|
2011-07-21 18:44:36 -06:00
|
|
|
//Core::getInstance().con.printerr("%s %x\n",cname.c_str(), type);
|
2011-03-10 19:09:45 -07:00
|
|
|
goto retry;
|
2010-04-07 14:28:05 -06:00
|
|
|
}
|
2011-03-10 19:09:45 -07:00
|
|
|
else if(!off.vein_grass_vptr && cname=="block_square_event_grassst")
|
2011-02-16 17:54:45 -07:00
|
|
|
{
|
2011-03-02 14:43:46 -07:00
|
|
|
off.vein_grass_vptr = type;
|
2011-07-21 18:44:36 -06:00
|
|
|
//Core::getInstance().con.printerr("%s %x\n",cname.c_str(), type);
|
2011-03-10 19:09:45 -07:00
|
|
|
goto retry;
|
2011-02-16 17:54:45 -07:00
|
|
|
}
|
2011-03-10 19:09:45 -07:00
|
|
|
else if(!off.vein_worldconstruction_vptr && cname=="block_square_event_world_constructionst")
|
2011-02-27 12:43:44 -07:00
|
|
|
{
|
2011-03-02 14:43:46 -07:00
|
|
|
off.vein_worldconstruction_vptr = type;
|
2011-07-21 18:44:36 -06:00
|
|
|
//Core::getInstance().con.printerr("%s %x\n",cname.c_str(), type);
|
2011-03-10 19:09:45 -07:00
|
|
|
goto retry;
|
2011-02-27 12:43:44 -07:00
|
|
|
}
|
2011-03-10 19:09:45 -07:00
|
|
|
#ifdef DEBUG
|
2011-03-02 14:43:46 -07:00
|
|
|
else // this is something we've never seen before
|
2010-04-02 19:52:46 -06:00
|
|
|
{
|
2011-03-02 14:43:46 -07:00
|
|
|
if(!d->unknown_veins.count(type))
|
2010-04-11 05:03:00 -06:00
|
|
|
{
|
2011-02-27 12:43:44 -07:00
|
|
|
cerr << "unknown vein " << cname << hex << " 0x" << temp << " block: 0x" << addr << dec << endl;
|
2011-03-02 14:43:46 -07:00
|
|
|
d->unknown_veins.insert(type);
|
2010-04-11 05:03:00 -06:00
|
|
|
}
|
2010-04-07 14:28:05 -06:00
|
|
|
}
|
2011-03-10 19:09:45 -07:00
|
|
|
#endif
|
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
|
|
|
}
|
|
|
|
|
2011-07-07 01:49:58 -06:00
|
|
|
bool Maps::RemoveBlockEvent(uint32_t x, uint32_t y, uint32_t z, t_virtual * which)
|
2011-07-18 13:55:41 -06:00
|
|
|
{
|
2011-07-07 01:49:58 -06:00
|
|
|
MAPS_GUARD
|
2011-07-18 13:55:41 -06:00
|
|
|
Process* p = d->owner;
|
|
|
|
|
2011-07-07 01:49:58 -06:00
|
|
|
df_block * block = getBlock(x,y,z);
|
|
|
|
if(block)
|
|
|
|
{
|
|
|
|
for(int i = 0; i < block->block_events.size();i++)
|
|
|
|
{
|
|
|
|
if (block->block_events[i] == which)
|
|
|
|
{
|
|
|
|
free(which);
|
|
|
|
block->block_events.erase(block->block_events.begin() + i);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2010-04-04 21:29:46 -06:00
|
|
|
}
|
|
|
|
|
2010-04-11 16:48:25 -06: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
|
|
|
{
|
2010-06-16 22:46:20 -06:00
|
|
|
MAPS_GUARD
|
2011-02-14 16:45:37 -07:00
|
|
|
if(!d->hasGeology) return false;
|
2010-04-18 13:30:02 -06:00
|
|
|
Process *p = d->owner;
|
2010-04-02 19:52:46 -06:00
|
|
|
// get needed addresses and offsets. Now this is what I call crazy.
|
|
|
|
uint16_t worldSizeX, worldSizeY;
|
2011-03-06 12:27:40 -07:00
|
|
|
uint32_t regions, geoblocks_vector_addr;
|
2011-03-18 10:58:48 -06:00
|
|
|
Private::t_offsets &off = d->offsets;
|
2010-04-02 19:52:46 -06:00
|
|
|
// get world size
|
2011-06-13 13:11:02 -06:00
|
|
|
uint32_t world = p->readDWord(off.world_data);
|
|
|
|
p->readWord (world + off.world_size_x, worldSizeX);
|
|
|
|
p->readWord (world + off.world_size_y, worldSizeY);
|
|
|
|
regions = p->readDWord ( world + off.world_regions); // ptr2_region_array
|
|
|
|
geoblocks_vector_addr = world + off.world_geoblocks_vector;
|
2010-04-02 19:52:46 -06:00
|
|
|
|
|
|
|
// read the geoblock vector
|
2011-06-12 17:14:10 -06:00
|
|
|
DfVector <uint32_t> geoblocks (geoblocks_vector_addr);
|
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
|
2011-07-06 23:00:36 -06:00
|
|
|
int bioRX = mdata->x_area_offset / 16 + ((i % 3) - 1);
|
2010-04-02 19:52:46 -06:00
|
|
|
if (bioRX < 0) bioRX = 0;
|
|
|
|
if (bioRX >= worldSizeX) bioRX = worldSizeX - 1;
|
2011-07-06 23:00:36 -06:00
|
|
|
int bioRY = mdata->y_area_offset / 16 + ((i / 3) - 1);
|
2010-04-02 19:52:46 -06:00
|
|
|
if (bioRY < 0) bioRY = 0;
|
|
|
|
if (bioRY >= worldSizeY) bioRY = worldSizeY - 1;
|
|
|
|
|
2010-04-04 21:53:38 -06:00
|
|
|
/// regions are a 2d array. consists of pointers to arrays of regions
|
|
|
|
/// regions are of region_size size
|
2010-04-02 19:52:46 -06:00
|
|
|
// get pointer to column of regions
|
|
|
|
uint32_t geoX;
|
2010-04-18 13:30:02 -06:00
|
|
|
p->readDWord (regions + bioRX*4, geoX);
|
2010-04-02 19:52:46 -06:00
|
|
|
|
|
|
|
// get index into geoblock vector
|
|
|
|
uint16_t geoindex;
|
2010-04-23 17:15:15 -06:00
|
|
|
p->readWord (geoX + bioRY*off.region_size + off.region_geo_index_offset, geoindex);
|
2010-04-02 19:52:46 -06:00
|
|
|
|
2010-04-04 21:53:38 -06:00
|
|
|
/// geology blocks are assigned to regions from a vector
|
2010-04-02 19:52:46 -06:00
|
|
|
// get the geoblock from the geoblock vector using the geoindex
|
|
|
|
// read the matgloss pointer from the vector into temp
|
2010-04-18 06:56:09 -06:00
|
|
|
uint32_t geoblock_off = geoblocks[geoindex];
|
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
|
2011-06-12 17:14:10 -06:00
|
|
|
DfVector <uint32_t> geolayers (geoblock_off + off.geolayer_geoblock_offset); // let's hope
|
2010-04-02 19:52:46 -06:00
|
|
|
// make sure we don't load crap
|
2010-04-18 06:56:09 -06:00
|
|
|
assert (geolayers.size() > 0 && geolayers.size() <= 16);
|
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
|
2010-04-18 06:56:09 -06:00
|
|
|
d->v_geology[i].reserve (geolayers.size());
|
2010-04-02 19:52:46 -06:00
|
|
|
// finally, read the layer matgloss
|
2010-04-18 06:56:09 -06:00
|
|
|
for (uint32_t j = 0;j < geolayers.size();j++)
|
2010-04-02 19:52:46 -06:00
|
|
|
{
|
|
|
|
// read pointer to a layer
|
2010-04-18 06:56:09 -06:00
|
|
|
uint32_t geol_offset = geolayers[j];
|
2010-04-02 19:52:46 -06:00
|
|
|
// read word at pointer + 2, store in our geology vectors
|
2010-04-23 17:15:15 -06:00
|
|
|
d->v_geology[i].push_back (p->readWord (geol_offset + off.type_inside_geolayer));
|
2010-04-02 19:52:46 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
assign.clear();
|
|
|
|
assign.reserve (eBiomeCount);
|
|
|
|
for (int i = 0; i < eBiomeCount;i++)
|
|
|
|
{
|
|
|
|
assign.push_back (d->v_geology[i]);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2010-04-23 17:50:04 -06:00
|
|
|
|
2011-03-10 19:09:45 -07:00
|
|
|
bool Maps::ReadLocalFeatures( std::map <DFCoord, std::vector<t_feature *> > & local_features )
|
2010-04-23 17:50:04 -06:00
|
|
|
{
|
2011-03-23 21:20:34 -06:00
|
|
|
StopFeatures();
|
|
|
|
StartFeatures();
|
2011-03-23 21:00:23 -06:00
|
|
|
if(d->FeaturesStarted)
|
2010-04-23 17:50:04 -06:00
|
|
|
{
|
2011-03-23 21:00:23 -06:00
|
|
|
local_features = d->m_local_feature;
|
|
|
|
return true;
|
2010-04-23 17:50:04 -06:00
|
|
|
}
|
2011-03-23 21:00:23 -06:00
|
|
|
return false;
|
2010-04-23 17:50:04 -06:00
|
|
|
}
|
|
|
|
|
2011-06-13 13:11:02 -06:00
|
|
|
bool Maps::ReadGlobalFeatures( std::vector <t_feature> & features )
|
2010-04-23 17:50:04 -06:00
|
|
|
{
|
2011-03-23 21:20:34 -06:00
|
|
|
StopFeatures();
|
|
|
|
StartFeatures();
|
2011-03-23 21:00:23 -06:00
|
|
|
if(d->FeaturesStarted)
|
2011-03-06 12:27:40 -07:00
|
|
|
{
|
2011-03-23 21:00:23 -06:00
|
|
|
features = d->v_global_feature;
|
|
|
|
return true;
|
2010-04-23 17:50:04 -06:00
|
|
|
}
|
2011-03-23 21:00:23 -06:00
|
|
|
return false;
|
2010-05-01 18:38:18 -06:00
|
|
|
}
|
|
|
|
|
2011-06-13 13:11:02 -06: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
|
|
|
{
|
|
|
|
if(!d->hasVeggies || !d->Started)
|
|
|
|
return false;
|
2011-07-07 01:49:58 -06:00
|
|
|
df_block * block = getBlock(x,y,z);
|
2011-07-06 23:00:36 -06:00
|
|
|
if(!block)
|
2011-02-27 05:59:45 -07:00
|
|
|
return false;
|
2011-03-18 10:58:48 -06:00
|
|
|
Private::t_offsets &off = d->offsets;
|
2011-07-06 23:00:36 -06:00
|
|
|
plants = &block->plants;
|
2011-02-27 05:59:45 -07:00
|
|
|
return true;
|
2011-03-01 15:29:27 -07:00
|
|
|
}
|