2010-04-02 19:52:46 -06:00
|
|
|
/*
|
|
|
|
www.sourceforge.net/projects/dfhack
|
|
|
|
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
|
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied
|
|
|
|
warranty. In no event will the authors be held liable for any
|
|
|
|
damages arising from the use of this software.
|
|
|
|
|
|
|
|
Permission is granted to anyone to use this software for any
|
|
|
|
purpose, including commercial applications, and to alter it and
|
|
|
|
redistribute it freely, subject to the following restrictions:
|
|
|
|
|
|
|
|
1. The origin of this software must not be misrepresented; you must
|
|
|
|
not claim that you wrote the original software. If you use this
|
|
|
|
software in a product, an acknowledgment in the product documentation
|
|
|
|
would be appreciated but is not required.
|
|
|
|
|
|
|
|
2. Altered source versions must be plainly marked as such, and
|
|
|
|
must not be misrepresented as being the original software.
|
|
|
|
|
|
|
|
3. This notice may not be removed or altered from any source
|
|
|
|
distribution.
|
|
|
|
*/
|
|
|
|
|
2010-05-26 04:24:45 -06:00
|
|
|
#include "Internal.h"
|
2010-04-04 16:48:19 -06:00
|
|
|
#include <shms.h>
|
|
|
|
#include <mod-core.h>
|
|
|
|
#include <mod-maps.h>
|
2010-05-26 04:24:45 -06:00
|
|
|
#include "ContextShared.h"
|
2010-05-26 00:42:09 -06:00
|
|
|
#include "dfhack/modules/Maps.h"
|
2010-05-25 22:48:23 -06:00
|
|
|
#include "dfhack/DFError.h"
|
2010-08-20 06:10:05 -06:00
|
|
|
#include "dfhack/VersionInfo.h"
|
2010-05-25 22:48:23 -06:00
|
|
|
#include "dfhack/DFProcess.h"
|
|
|
|
#include "dfhack/DFVector.h"
|
2010-04-02 19:52:46 -06:00
|
|
|
|
2010-04-04 16:48:19 -06:00
|
|
|
#define SHMMAPSHDR ((Server::Maps::shm_maps_hdr *)d->d->shm_start)
|
|
|
|
#define SHMCMD(num) ((shm_cmd *)d->d->shm_start)[num]->pingpong
|
|
|
|
#define SHMHDR ((shm_core_hdr *)d->d->shm_start)
|
|
|
|
#define SHMDATA(type) ((type *)(d->d->shm_start + SHM_HEADER))
|
2010-06-16 22:46:20 -06:00
|
|
|
#define MAPS_GUARD if(!d->Started) throw DFHack::Error::ModuleNotInitialized();
|
2010-04-02 19:52:46 -06:00
|
|
|
using namespace DFHack;
|
|
|
|
|
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 * block;
|
|
|
|
uint32_t x_block_count, y_block_count, z_block_count;
|
|
|
|
uint32_t regionX, regionY, regionZ;
|
|
|
|
uint32_t worldSizeX, worldSizeY;
|
2010-04-02 19:52:46 -06:00
|
|
|
|
2010-04-04 16:48:19 -06:00
|
|
|
uint32_t maps_module;
|
|
|
|
Server::Maps::maps_offsets offsets;
|
2010-06-24 23:11:26 -06:00
|
|
|
|
2010-05-26 04:24:45 -06:00
|
|
|
DFContextShared *d;
|
2010-04-18 13:30:02 -06:00
|
|
|
Process * owner;
|
2010-08-28 07:43:53 -06:00
|
|
|
OffsetGroup *OG_local_features;
|
|
|
|
OffsetGroup *OG_global_features;
|
|
|
|
OffsetGroup *OG_vector;
|
2010-04-04 16:48:19 -06:00
|
|
|
bool Inited;
|
|
|
|
bool Started;
|
2011-02-14 16:45:37 -07:00
|
|
|
bool hasGeology;
|
|
|
|
bool hasFeatures;
|
2010-06-24 23:11:26 -06:00
|
|
|
|
2010-04-23 17:15:15 -06:00
|
|
|
// map between feature address and the read object
|
|
|
|
map <uint32_t, t_feature> local_feature_store;
|
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
|
|
|
};
|
|
|
|
|
2010-05-26 04:24:45 -06:00
|
|
|
Maps::Maps(DFContextShared* _d)
|
2010-04-04 16:48:19 -06:00
|
|
|
{
|
|
|
|
d = new Private;
|
|
|
|
d->d = _d;
|
2010-04-18 13:30:02 -06:00
|
|
|
Process *p = d->owner = _d->p;
|
2010-04-04 16:48:19 -06:00
|
|
|
d->Inited = d->Started = false;
|
2010-09-03 23:43:39 -06:00
|
|
|
d->block = NULL;
|
2010-06-24 23:11:26 -06:00
|
|
|
|
2010-08-20 06:10:05 -06:00
|
|
|
DFHack::VersionInfo * mem = p->getDescriptor();
|
2010-04-04 16:48:19 -06:00
|
|
|
Server::Maps::maps_offsets &off = d->offsets;
|
2011-02-14 16:45:37 -07:00
|
|
|
d->hasFeatures = d->hasGeology = 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");
|
2010-08-29 16:08:17 -06:00
|
|
|
{
|
|
|
|
off.map_offset = OG_Maps->getAddress ("map_data");
|
|
|
|
off.x_count_offset = OG_Maps->getAddress ("x_count_block");
|
|
|
|
off.y_count_offset = OG_Maps->getAddress ("y_count_block");
|
|
|
|
off.z_count_offset = OG_Maps->getAddress ("z_count_block");
|
|
|
|
off.region_x_offset = OG_Maps->getAddress ("region_x");
|
|
|
|
off.region_y_offset = OG_Maps->getAddress ("region_y");
|
|
|
|
off.region_z_offset = OG_Maps->getAddress ("region_z");
|
|
|
|
off.world_size_x = OG_Maps->getAddress ("world_size_x");
|
|
|
|
off.world_size_y = OG_Maps->getAddress ("world_size_y");
|
|
|
|
OffsetGroup *OG_MapBlock = OG_Maps->getGroup("block");
|
|
|
|
{
|
|
|
|
off.tile_type_offset = OG_MapBlock->getOffset ("type");
|
|
|
|
off.designation_offset = OG_MapBlock->getOffset ("designation");
|
|
|
|
off.occupancy_offset = OG_MapBlock->getOffset("occupancy");
|
|
|
|
off.biome_stuffs = OG_MapBlock->getOffset ("biome_stuffs");
|
|
|
|
off.veinvector = OG_MapBlock->getOffset ("vein_vector");
|
|
|
|
off.local_feature_offset = OG_MapBlock->getOffset ("feature_local");
|
|
|
|
off.global_feature_offset = OG_MapBlock->getOffset ("feature_global");
|
|
|
|
off.temperature1_offset = OG_MapBlock->getOffset ("temperature1");
|
|
|
|
off.temperature2_offset = OG_MapBlock->getOffset ("temperature2");
|
|
|
|
}
|
2011-02-14 16:45:37 -07:00
|
|
|
try
|
|
|
|
{
|
|
|
|
OffsetGroup *OG_Geology = OG_Maps->getGroup("geology");
|
|
|
|
{
|
|
|
|
off.world_regions = OG_Geology->getAddress ("ptr2_region_array");
|
|
|
|
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.world_geoblocks_vector = OG_Geology->getAddress ("geoblock_vector");
|
|
|
|
off.type_inside_geolayer = OG_Geology->getOffset ("type_inside_geolayer");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(Error::AllMemdef &)
|
|
|
|
{
|
|
|
|
d->hasGeology = false;
|
|
|
|
}
|
|
|
|
try
|
|
|
|
{
|
|
|
|
d->OG_global_features = OG_Maps->getGroup("features")->getGroup("global");
|
|
|
|
d->OG_local_features = OG_Maps->getGroup("features")->getGroup("local");
|
|
|
|
}
|
|
|
|
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);
|
2010-04-04 16:48:19 -06:00
|
|
|
|
|
|
|
// upload offsets to SHM server if possible
|
|
|
|
d->maps_module = 0;
|
2010-04-18 13:30:02 -06:00
|
|
|
if(p->getModuleIndex("Maps2010",1,d->maps_module))
|
2010-04-02 19:52:46 -06:00
|
|
|
{
|
|
|
|
// supply the module with offsets so it can work with them
|
2010-04-04 16:48:19 -06:00
|
|
|
Server::Maps::maps_offsets *off2 = SHMDATA(Server::Maps::maps_offsets);
|
|
|
|
memcpy(off2, &(d->offsets), sizeof(Server::Maps::maps_offsets));
|
2010-04-02 19:52:46 -06:00
|
|
|
full_barrier
|
2010-04-04 16:48:19 -06:00
|
|
|
const uint32_t cmd = Server::Maps::MAP_INIT + (d->maps_module << 16);
|
2010-04-18 13:30:02 -06:00
|
|
|
p->SetAndWait(cmd);
|
2010-04-02 19:52:46 -06:00
|
|
|
}
|
2010-04-04 16:48:19 -06:00
|
|
|
d->Inited = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Maps::~Maps()
|
|
|
|
{
|
|
|
|
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;
|
2010-04-04 16:48:19 -06:00
|
|
|
Server::Maps::maps_offsets &off = d->offsets;
|
2010-06-24 23:11:26 -06:00
|
|
|
|
2010-04-02 19:52:46 -06:00
|
|
|
// get the map pointer
|
2010-04-18 13:30:02 -06:00
|
|
|
uint32_t x_array_loc = p->readDWord (off.map_offset);
|
2010-04-02 19:52:46 -06:00
|
|
|
if (!x_array_loc)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2010-06-24 23:11:26 -06:00
|
|
|
|
2010-04-02 19:52:46 -06:00
|
|
|
// get the size
|
|
|
|
uint32_t mx, my, mz;
|
2010-04-18 13:30:02 -06:00
|
|
|
mx = d->x_block_count = p->readDWord (off.x_count_offset);
|
|
|
|
my = d->y_block_count = p->readDWord (off.y_count_offset);
|
|
|
|
mz = d->z_block_count = p->readDWord (off.z_count_offset);
|
2010-04-02 19:52:46 -06:00
|
|
|
|
|
|
|
// test for wrong map dimensions
|
|
|
|
if (mx == 0 || mx > 48 || my == 0 || my > 48 || mz == 0)
|
|
|
|
{
|
|
|
|
throw Error::BadMapDimensions(mx, my);
|
|
|
|
//return false;
|
|
|
|
}
|
|
|
|
|
2010-04-23 17:15:15 -06:00
|
|
|
// read position of the region inside DF world
|
|
|
|
p->readDWord (off.region_x_offset, d->regionX);
|
|
|
|
p->readDWord (off.region_y_offset, d->regionY);
|
|
|
|
p->readDWord (off.region_z_offset, d->regionZ);
|
|
|
|
|
2010-04-02 19:52:46 -06:00
|
|
|
// alloc array for pointers to all blocks
|
|
|
|
d->block = new uint32_t[mx*my*mz];
|
|
|
|
uint32_t *temp_x = new uint32_t[mx];
|
|
|
|
uint32_t *temp_y = new uint32_t[my];
|
|
|
|
|
2010-04-18 13:30:02 -06:00
|
|
|
p->read (x_array_loc, mx * sizeof (uint32_t), (uint8_t *) temp_x);
|
2010-04-02 19:52:46 -06:00
|
|
|
for (uint32_t x = 0; x < mx; x++)
|
|
|
|
{
|
2010-04-18 13:30:02 -06:00
|
|
|
p->read (temp_x[x], my * sizeof (uint32_t), (uint8_t *) temp_y);
|
2010-04-02 19:52:46 -06:00
|
|
|
// y -> map column
|
|
|
|
for (uint32_t y = 0; y < my; y++)
|
|
|
|
{
|
2010-04-18 13:30:02 -06:00
|
|
|
p->read (temp_y[y],
|
2010-04-02 19:52:46 -06:00
|
|
|
mz * sizeof (uint32_t),
|
|
|
|
(uint8_t *) (d->block + x*my*mz + y*mz));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
delete [] temp_x;
|
|
|
|
delete [] temp_y;
|
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
|
2010-04-11 16:48:25 -06:00
|
|
|
x = d->x_block_count;
|
|
|
|
y = d->y_block_count;
|
|
|
|
z = d->z_block_count;
|
|
|
|
}
|
|
|
|
|
2010-04-23 17:50:04 -06:00
|
|
|
// invalidates local and global features!
|
2010-04-04 16:48:19 -06:00
|
|
|
bool Maps::Finish()
|
2010-04-02 19:52:46 -06:00
|
|
|
{
|
2010-04-23 17:50:04 -06:00
|
|
|
d->local_feature_store.clear();
|
2010-04-02 19:52:46 -06:00
|
|
|
if (d->block != NULL)
|
|
|
|
{
|
|
|
|
delete [] d->block;
|
|
|
|
d->block = NULL;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-04-11 16:48:25 -06:00
|
|
|
/*
|
|
|
|
* Block reading
|
|
|
|
*/
|
|
|
|
|
2010-04-04 16:48:19 -06:00
|
|
|
bool Maps::isValidBlock (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
|
2010-04-02 19:52:46 -06:00
|
|
|
if ( x >= d->x_block_count || y >= d->y_block_count || z >= d->z_block_count)
|
|
|
|
return false;
|
|
|
|
return d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z] != 0;
|
|
|
|
}
|
|
|
|
|
2010-04-04 16:48:19 -06:00
|
|
|
uint32_t Maps::getBlockPtr (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
|
2010-04-02 19:52:46 -06:00
|
|
|
if ( x >= d->x_block_count || y >= d->y_block_count || z >= d->z_block_count)
|
|
|
|
return 0;
|
|
|
|
return d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z];
|
|
|
|
}
|
|
|
|
|
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;
|
2010-04-04 16:48:19 -06:00
|
|
|
if(d->d->shm_start && d->maps_module) // ACCELERATE!
|
2010-04-02 19:52:46 -06:00
|
|
|
{
|
|
|
|
SHMMAPSHDR->x = x;
|
|
|
|
SHMMAPSHDR->y = y;
|
|
|
|
SHMMAPSHDR->z = z;
|
2010-04-04 16:48:19 -06:00
|
|
|
volatile uint32_t cmd = Server::Maps::MAP_READ_BLOCK_BY_COORDS + (d->maps_module << 16);
|
2010-04-18 13:30:02 -06:00
|
|
|
if(!p->SetAndWait(cmd))
|
2010-04-02 19:52:46 -06:00
|
|
|
return false;
|
|
|
|
memcpy(buffer,SHMDATA(mapblock40d),sizeof(mapblock40d));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else // plain old block read
|
|
|
|
{
|
|
|
|
uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z];
|
|
|
|
if (addr)
|
|
|
|
{
|
2010-04-18 13:30:02 -06:00
|
|
|
p->read (addr + d->offsets.tile_type_offset, sizeof (buffer->tiletypes), (uint8_t *) buffer->tiletypes);
|
|
|
|
p->read (addr + d->offsets.designation_offset, sizeof (buffer->designation), (uint8_t *) buffer->designation);
|
|
|
|
p->read (addr + d->offsets.occupancy_offset, sizeof (buffer->occupancy), (uint8_t *) buffer->occupancy);
|
|
|
|
p->read (addr + d->offsets.biome_stuffs, sizeof (biome_indices40d), (uint8_t *) buffer->biome_indices);
|
2010-04-23 17:15:15 -06:00
|
|
|
p->readWord(addr + d->offsets.global_feature_offset, (uint16_t&) buffer->global_feature);
|
|
|
|
p->readWord(addr + d->offsets.local_feature_offset, (uint16_t&)buffer->local_feature);
|
2010-04-02 19:52:46 -06:00
|
|
|
buffer->origin = addr;
|
2010-04-18 13:30:02 -06:00
|
|
|
uint32_t addr_of_struct = p->readDWord(addr);
|
|
|
|
buffer->blockflags.whole = p->readDWord(addr_of_struct);
|
2010-04-02 19:52:46 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
2010-04-02 19:52:46 -06:00
|
|
|
uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z];
|
|
|
|
if (addr)
|
|
|
|
{
|
2010-04-18 13:30:02 -06:00
|
|
|
d->owner->read (addr + d->offsets.tile_type_offset, sizeof (tiletypes40d), (uint8_t *) buffer);
|
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
|
2010-04-11 16:48:25 -06:00
|
|
|
uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z];
|
|
|
|
if (addr)
|
|
|
|
{
|
2010-04-18 13:30:02 -06:00
|
|
|
d->owner->write (addr + d->offsets.tile_type_offset, sizeof (tiletypes40d), (uint8_t *) buffer);
|
2010-04-11 16:48:25 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2010-06-24 23:11:26 -06:00
|
|
|
* Dirty bit
|
|
|
|
*/
|
2010-04-11 16:48:25 -06:00
|
|
|
|
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
|
2010-04-02 19:52:46 -06:00
|
|
|
uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z];
|
|
|
|
if(addr)
|
|
|
|
{
|
2010-04-18 13:30:02 -06:00
|
|
|
Process * p = d->owner;
|
|
|
|
uint32_t addr_of_struct = p->readDWord(addr);
|
|
|
|
dirtybit = p->readDWord(addr_of_struct) & 1;
|
2010-04-02 19:52:46 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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
|
2010-04-02 19:52:46 -06:00
|
|
|
uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z];
|
|
|
|
if (addr)
|
|
|
|
{
|
2010-04-18 13:30:02 -06:00
|
|
|
Process * p = d->owner;
|
|
|
|
uint32_t addr_of_struct = p->readDWord(addr);
|
|
|
|
uint32_t dirtydword = p->readDWord(addr_of_struct);
|
2010-04-02 19:52:46 -06:00
|
|
|
dirtydword &= 0xFFFFFFFE;
|
|
|
|
dirtydword |= (uint32_t) dirtybit;
|
2010-04-18 13:30:02 -06:00
|
|
|
p->writeDWord (addr_of_struct, dirtydword);
|
2010-04-02 19:52:46 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-06-24 23:11:26 -06:00
|
|
|
/*
|
|
|
|
* Block flags
|
|
|
|
*/
|
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
|
2010-04-02 19:52:46 -06:00
|
|
|
uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z];
|
|
|
|
if(addr)
|
|
|
|
{
|
2010-04-18 13:30:02 -06:00
|
|
|
Process * p = d->owner;
|
|
|
|
uint32_t addr_of_struct = p->readDWord(addr);
|
|
|
|
blockflags.whole = p->readDWord(addr_of_struct);
|
2010-04-02 19:52:46 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
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
|
2010-04-02 19:52:46 -06:00
|
|
|
uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z];
|
|
|
|
if (addr)
|
|
|
|
{
|
2010-04-18 13:30:02 -06:00
|
|
|
Process * p = d->owner;
|
|
|
|
uint32_t addr_of_struct = p->readDWord(addr);
|
|
|
|
p->writeDWord (addr_of_struct, blockflags.whole);
|
2010-04-02 19:52:46 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
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
|
2010-04-02 19:52:46 -06:00
|
|
|
uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z];
|
|
|
|
if (addr)
|
|
|
|
{
|
2010-04-18 13:30:02 -06:00
|
|
|
d->owner->read (addr + d->offsets.designation_offset, sizeof (designations40d), (uint8_t *) buffer);
|
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
|
2010-04-02 19:52:46 -06:00
|
|
|
uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z];
|
|
|
|
if (addr)
|
|
|
|
{
|
2010-04-18 13:30:02 -06:00
|
|
|
d->owner->write (addr + d->offsets.designation_offset, sizeof (designations40d), (uint8_t *) buffer);
|
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
|
2010-04-02 19:52:46 -06:00
|
|
|
uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z];
|
|
|
|
if (addr)
|
|
|
|
{
|
2010-04-18 13:30:02 -06:00
|
|
|
d->owner->read (addr + d->offsets.occupancy_offset, sizeof (occupancies40d), (uint8_t *) buffer);
|
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
|
2010-04-11 16:48:25 -06:00
|
|
|
uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z];
|
|
|
|
if (addr)
|
|
|
|
{
|
2010-04-18 13:30:02 -06:00
|
|
|
d->owner->write (addr + d->offsets.occupancy_offset, sizeof (tiletypes40d), (uint8_t *) buffer);
|
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
|
2010-04-17 07:30:25 -06:00
|
|
|
uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z];
|
|
|
|
if (addr)
|
|
|
|
{
|
|
|
|
if(temp1)
|
2010-04-18 13:30:02 -06:00
|
|
|
d->owner->read (addr + d->offsets.temperature1_offset, sizeof (t_temperatures), (uint8_t *) temp1);
|
2010-04-17 07:30:25 -06:00
|
|
|
if(temp2)
|
2010-04-18 13:30:02 -06:00
|
|
|
d->owner->read (addr + d->offsets.temperature2_offset, sizeof (t_temperatures), (uint8_t *) temp2);
|
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
|
2010-04-17 07:30:25 -06:00
|
|
|
uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z];
|
|
|
|
if (addr)
|
|
|
|
{
|
|
|
|
if(temp1)
|
2010-04-18 13:30:02 -06:00
|
|
|
d->owner->write (addr + d->offsets.temperature1_offset, sizeof (t_temperatures), (uint8_t *) temp1);
|
2010-04-17 07:30:25 -06:00
|
|
|
if(temp2)
|
2010-04-18 13:30:02 -06:00
|
|
|
d->owner->write (addr + d->offsets.temperature2_offset, sizeof (t_temperatures), (uint8_t *) temp2);
|
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
|
2010-04-02 19:52:46 -06:00
|
|
|
uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z];
|
|
|
|
if (addr)
|
|
|
|
{
|
2010-04-18 13:30:02 -06:00
|
|
|
d->owner->read (addr + d->offsets.biome_stuffs, sizeof (biome_indices40d), (uint8_t *) buffer);
|
2010-04-02 19:52:46 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2010-04-04 21:29:46 -06:00
|
|
|
|
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
|
2010-04-26 10:12:00 -06:00
|
|
|
uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z];
|
|
|
|
if (addr)
|
|
|
|
{
|
|
|
|
Process * p = d->owner;
|
|
|
|
p->readWord(addr + d->offsets.global_feature_offset, (uint16_t&) global);
|
|
|
|
p->readWord(addr + d->offsets.local_feature_offset, (uint16_t&)local);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Maps::WriteLocalFeature(uint32_t x, uint32_t y, uint32_t z, int16_t local)
|
|
|
|
{
|
2010-06-16 22:46:20 -06:00
|
|
|
MAPS_GUARD
|
2010-04-26 10:12:00 -06:00
|
|
|
uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z];
|
|
|
|
if (addr)
|
|
|
|
{
|
|
|
|
Process * p = d->owner;
|
|
|
|
p->writeWord(addr + d->offsets.local_feature_offset, (uint16_t&)local);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Maps::WriteGlobalFeature(uint32_t x, uint32_t y, uint32_t z, int16_t global)
|
|
|
|
{
|
2010-06-16 22:46:20 -06:00
|
|
|
MAPS_GUARD
|
2010-04-26 10:12:00 -06:00
|
|
|
uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z];
|
|
|
|
if (addr)
|
|
|
|
{
|
|
|
|
Process * p = d->owner;
|
|
|
|
p->writeWord(addr + d->offsets.global_feature_offset, (uint16_t&)global);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-04-11 16:48:25 -06:00
|
|
|
/*
|
|
|
|
* Block events
|
2010-08-20 06:10:05 -06:00
|
|
|
*/
|
2011-02-16 17:54:45 -07:00
|
|
|
bool Maps::ReadVeins(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)
|
2010-04-02 19:52:46 -06:00
|
|
|
{
|
2010-06-16 22:46:20 -06:00
|
|
|
MAPS_GUARD
|
2010-04-10 18:08:21 -06:00
|
|
|
t_vein v;
|
|
|
|
t_frozenliquidvein fv;
|
|
|
|
t_spattervein sv;
|
2011-02-16 17:54:45 -07:00
|
|
|
t_grassvein gv;
|
2010-04-18 13:30:02 -06:00
|
|
|
Process* p = d->owner;
|
2010-08-20 06:10:05 -06:00
|
|
|
|
2010-04-02 19:52:46 -06:00
|
|
|
uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z];
|
2010-04-10 18:08:21 -06:00
|
|
|
if(veins) veins->clear();
|
|
|
|
if(ices) ices->clear();
|
|
|
|
if(splatter) splatter->clear();
|
2011-02-16 17:54:45 -07:00
|
|
|
if(grass) splatter->clear();
|
2010-08-20 06:10:05 -06:00
|
|
|
|
2010-04-04 16:48:19 -06:00
|
|
|
Server::Maps::maps_offsets &off = d->offsets;
|
2010-04-10 18:08:21 -06:00
|
|
|
if (addr)
|
2010-04-02 19:52:46 -06:00
|
|
|
{
|
|
|
|
// veins are stored as a vector of pointers to veins
|
|
|
|
/*pointer is 4 bytes! we work with a 32bit program here, no matter what architecture we compile khazad for*/
|
2010-04-18 13:30:02 -06:00
|
|
|
DfVector <uint32_t> p_veins (p, addr + off.veinvector);
|
2010-04-18 06:56:09 -06:00
|
|
|
uint32_t size = p_veins.size();
|
2010-04-02 19:52:46 -06:00
|
|
|
// read all veins
|
|
|
|
for (uint32_t i = 0; i < size;i++)
|
|
|
|
{
|
|
|
|
// read the vein pointer from the vector
|
2010-04-18 06:56:09 -06:00
|
|
|
uint32_t temp = p_veins[i];
|
2010-04-18 13:30:02 -06:00
|
|
|
uint32_t type = p->readDWord(temp);
|
2010-04-02 19:52:46 -06:00
|
|
|
try_again:
|
2010-04-10 18:08:21 -06:00
|
|
|
if(veins && type == off.vein_mineral_vptr)
|
2010-04-02 19:52:46 -06:00
|
|
|
{
|
|
|
|
// read the vein data (dereference pointer)
|
2010-04-18 13:30:02 -06:00
|
|
|
p->read (temp, sizeof(t_vein), (uint8_t *) &v);
|
2010-04-02 19:52:46 -06:00
|
|
|
v.address_of = temp;
|
|
|
|
// store it in the vector
|
2010-04-10 18:08:21 -06:00
|
|
|
veins->push_back (v);
|
2010-04-02 19:52:46 -06:00
|
|
|
}
|
2010-04-10 18:08:21 -06:00
|
|
|
else if(ices && type == off.vein_ice_vptr)
|
2010-04-02 19:52:46 -06:00
|
|
|
{
|
|
|
|
// read the ice vein data (dereference pointer)
|
2010-04-18 13:30:02 -06:00
|
|
|
p->read (temp, sizeof(t_frozenliquidvein), (uint8_t *) &fv);
|
2010-04-07 14:28:05 -06:00
|
|
|
fv.address_of = temp;
|
2010-04-02 19:52:46 -06:00
|
|
|
// store it in the vector
|
2010-04-10 18:08:21 -06:00
|
|
|
ices->push_back (fv);
|
2010-04-02 19:52:46 -06:00
|
|
|
}
|
2010-04-10 18:08:21 -06:00
|
|
|
else if(splatter && type == off.vein_spatter_vptr)
|
2010-04-07 14:28:05 -06:00
|
|
|
{
|
|
|
|
// read the splatter vein data (dereference pointer)
|
2010-04-18 13:30:02 -06:00
|
|
|
p->read (temp, sizeof(t_spattervein), (uint8_t *) &sv);
|
2010-04-07 14:28:05 -06:00
|
|
|
sv.address_of = temp;
|
|
|
|
// store it in the vector
|
2010-04-10 18:08:21 -06:00
|
|
|
splatter->push_back (sv);
|
2010-04-07 14:28:05 -06:00
|
|
|
}
|
2011-02-16 17:54:45 -07:00
|
|
|
else if(grass && type == off.vein_grass_vptr)
|
|
|
|
{
|
|
|
|
// read the splatter vein data (dereference pointer)
|
|
|
|
p->read (temp, sizeof(t_grassvein), (uint8_t *) &gv);
|
|
|
|
gv.address_of = temp;
|
|
|
|
// store it in the vector
|
|
|
|
grass->push_back (gv);
|
|
|
|
}
|
2010-04-10 18:08:21 -06:00
|
|
|
else
|
2010-04-02 19:52:46 -06:00
|
|
|
{
|
2010-04-18 13:30:02 -06:00
|
|
|
string cname = p->readClassName(type);
|
2010-04-11 05:03:00 -06:00
|
|
|
if(ices && cname == "block_square_event_frozen_liquidst")
|
2010-04-10 18:08:21 -06:00
|
|
|
{
|
|
|
|
off.vein_ice_vptr = type;
|
|
|
|
goto try_again;
|
|
|
|
}
|
2010-04-11 05:03:00 -06:00
|
|
|
else if(veins && cname == "block_square_event_mineralst")
|
2010-04-10 18:08:21 -06:00
|
|
|
{
|
|
|
|
off.vein_mineral_vptr = type;
|
|
|
|
goto try_again;
|
|
|
|
}
|
2010-04-11 05:03:00 -06:00
|
|
|
else if(splatter && cname == "block_square_event_material_spatterst")
|
2010-04-10 18:08:21 -06:00
|
|
|
{
|
|
|
|
off.vein_spatter_vptr = type;
|
|
|
|
goto try_again;
|
|
|
|
}
|
2011-02-16 17:54:45 -07:00
|
|
|
else if(grass && cname=="block_square_event_grassst")
|
|
|
|
{
|
|
|
|
off.vein_grass_vptr = type;
|
|
|
|
goto try_again;
|
|
|
|
}
|
2010-04-11 05:03:00 -06:00
|
|
|
#ifdef DEBUG
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cerr << "unknown vein " << cname << endl;
|
|
|
|
}
|
|
|
|
#endif
|
2010-04-10 18:08:21 -06:00
|
|
|
// or it was something we don't care about
|
2010-04-07 14:28:05 -06:00
|
|
|
}
|
2010-04-02 19:52:46 -06:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2010-04-04 21:29:46 -06:00
|
|
|
__int16 __userpurge GetGeologicalRegion<ax>(__int16 block_X<cx>, int X<ebx>, __int16 block_Y<di>, int block_addr<esi>, int Y)
|
|
|
|
{
|
|
|
|
char bio_off; // al@1
|
|
|
|
int tile_designation; // ecx@1
|
|
|
|
__int64 corrected_x; // qax@1
|
|
|
|
__int64 corrected_y; // qax@1
|
|
|
|
int difY; // eax@9
|
|
|
|
int difX; // edx@9
|
|
|
|
signed __int64 bio_off_2; // qax@9
|
|
|
|
signed __int64 bio_off_2_; // qtt@9
|
|
|
|
__int16 result; // ax@23
|
|
|
|
|
|
|
|
corrected_x = reg_off_x + (block_X + (signed int)*(_WORD *)(block_addr + 0x90)) / 48;
|
|
|
|
*(_WORD *)X = ((BYTE4(corrected_x) & 0xF) + (_DWORD)corrected_x) >> 4;
|
|
|
|
corrected_y = reg_off_y + (block_Y + (signed int)*(_WORD *)(block_addr + 0x92)) / 48;
|
|
|
|
*(_WORD *)Y = ((BYTE4(corrected_y) & 0xF) + (_DWORD)corrected_y) >> 4;
|
|
|
|
tile_designation = *(_DWORD *)(block_addr + 4 * (block_Y + 16 * block_X) + 0x29C);
|
|
|
|
bio_off = 0;
|
|
|
|
if ( tile_designation & 0x20000 )
|
|
|
|
bio_off = 1;
|
|
|
|
if ( tile_designation & 0x40000 )
|
|
|
|
bio_off |= 2u;
|
|
|
|
if ( tile_designation & 0x80000 )
|
|
|
|
bio_off |= 4u;
|
|
|
|
if ( tile_designation & 0x100000 )
|
|
|
|
bio_off |= 8u;
|
|
|
|
bio_off_2 = *(_BYTE *)(bio_off + block_addr + 0x1D9C);
|
|
|
|
bio_off_2_ = bio_off_2;
|
|
|
|
difY = bio_off_2 / 3;
|
|
|
|
difX = bio_off_2_ % 3;
|
|
|
|
if ( !difX )
|
|
|
|
--*(_WORD *)X;
|
|
|
|
if ( difX == 2 )
|
|
|
|
++*(_WORD *)X;
|
|
|
|
if ( !difY )
|
|
|
|
--*(_WORD *)Y;
|
|
|
|
if ( difY == 2 )
|
|
|
|
++*(_WORD *)Y;
|
|
|
|
if ( *(_WORD *)X < 0 )
|
|
|
|
*(_WORD *)X = 0;
|
|
|
|
if ( *(_WORD *)Y < 0 )
|
|
|
|
*(_WORD *)Y = 0;
|
|
|
|
if ( *(_WORD *)X >= (_WORD)World_size )
|
|
|
|
*(_WORD *)X = World_size - 1;
|
|
|
|
result = HIWORD(World_size);
|
|
|
|
if ( *(_WORD *)Y >= HIWORD(World_size) )
|
|
|
|
{
|
|
|
|
result = HIWORD(World_size) - 1;
|
|
|
|
*(_WORD *)Y = HIWORD(World_size) - 1;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
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;
|
2010-04-23 17:15:15 -06:00
|
|
|
Server::Maps::maps_offsets &off = d->offsets;
|
2010-04-02 19:52:46 -06:00
|
|
|
// get world size
|
2010-04-23 17:15:15 -06:00
|
|
|
p->readWord (off.world_size_x, worldSizeX);
|
|
|
|
p->readWord (off.world_size_y, worldSizeY);
|
2010-04-02 19:52:46 -06:00
|
|
|
|
|
|
|
// get pointer to first part of 2d array of regions
|
2010-04-23 17:15:15 -06:00
|
|
|
uint32_t regions = p->readDWord (off.world_regions);
|
2010-04-02 19:52:46 -06:00
|
|
|
|
|
|
|
// read the geoblock vector
|
2010-04-23 17:15:15 -06:00
|
|
|
DfVector <uint32_t> geoblocks (d->d->p, off.world_geoblocks_vector);
|
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
|
2010-04-23 17:15:15 -06:00
|
|
|
int bioRX = d->regionX / 16 + (i % 3) - 1;
|
2010-04-02 19:52:46 -06:00
|
|
|
if (bioRX < 0) bioRX = 0;
|
|
|
|
if (bioRX >= worldSizeX) bioRX = worldSizeX - 1;
|
2010-04-23 17:15:15 -06:00
|
|
|
int bioRY = d->regionY / 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
|
2010-04-23 17:15:15 -06:00
|
|
|
DfVector <uint32_t> geolayers (p, 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
|
|
|
|
|
|
|
bool Maps::ReadLocalFeatures( std::map <planecoord, std::vector<t_feature *> > & local_features )
|
|
|
|
{
|
2010-06-16 22:46:20 -06:00
|
|
|
MAPS_GUARD
|
2011-02-14 16:45:37 -07:00
|
|
|
if(!d->hasFeatures) return false;
|
2010-04-25 12:52:57 -06:00
|
|
|
// can't be used without a map!
|
|
|
|
if(!d->block)
|
|
|
|
return false;
|
2010-06-24 23:11:26 -06:00
|
|
|
|
2010-04-23 17:50:04 -06:00
|
|
|
Process * p = d->owner;
|
|
|
|
// deref pointer to the humongo-structure
|
2010-08-28 07:43:53 -06:00
|
|
|
uint32_t base = p->readDWord(d->OG_local_features->getAddress("start_ptr"));
|
2010-04-26 16:17:53 -06:00
|
|
|
if(!base)
|
|
|
|
return false;
|
2010-08-28 07:43:53 -06:00
|
|
|
const uint32_t sizeof_vec = d->OG_vector->getHexValue("sizeof");
|
2010-04-23 17:50:04 -06:00
|
|
|
const uint32_t sizeof_elem = 16;
|
|
|
|
const uint32_t offset_elem = 4;
|
2010-08-28 07:43:53 -06:00
|
|
|
const uint32_t main_mat_offset = d->OG_local_features->getOffset("material"); // 0x30
|
|
|
|
const uint32_t sub_mat_offset = d->OG_local_features->getOffset("submaterial"); // 0x34
|
2010-06-24 23:11:26 -06:00
|
|
|
|
2010-04-23 17:50:04 -06:00
|
|
|
local_features.clear();
|
2010-06-24 23:11:26 -06:00
|
|
|
|
2010-04-24 08:36:41 -06:00
|
|
|
for(uint32_t blockX = 0; blockX < d->x_block_count; blockX ++)
|
|
|
|
for(uint32_t blockY = 0; blockY < d->x_block_count; blockY ++)
|
2010-04-23 17:50:04 -06:00
|
|
|
{
|
2010-06-24 23:11:26 -06:00
|
|
|
// region X coord (48x48 tiles)
|
|
|
|
uint16_t region_x_local = ( (blockX / 3) + d->regionX ) / 16;
|
|
|
|
// region Y coord (48x48 tiles)
|
2010-04-25 12:52:57 -06:00
|
|
|
uint64_t region_y_local = ( (blockY / 3) + d->regionY ) / 16;
|
2010-06-24 23:11:26 -06:00
|
|
|
|
2010-04-23 17:50:04 -06:00
|
|
|
// this is just a few pointers to arrays of 16B (4 DWORD) structs
|
2010-06-24 23:11:26 -06:00
|
|
|
uint32_t array_elem = p->readDWord(base + (region_x_local / 16) * 4);
|
|
|
|
|
2010-04-23 17:50:04 -06:00
|
|
|
// 16B structs, second DWORD of the struct is a pointer
|
2010-08-20 06:10:05 -06:00
|
|
|
uint32_t wtf = p->readDWord(array_elem + ( sizeof_elem * ( (uint32_t)region_y_local/16)) + offset_elem);
|
2010-04-23 17:50:04 -06:00
|
|
|
if(wtf)
|
|
|
|
{
|
|
|
|
// wtf + sizeof(vector<ptr>) * crap;
|
2010-06-24 23:11:26 -06:00
|
|
|
uint32_t feat_vector = wtf + sizeof_vec * (16 * (region_x_local % 16) + (region_y_local % 16));
|
2010-04-23 17:50:04 -06:00
|
|
|
DfVector<uint32_t> p_features(p, feat_vector);
|
2010-04-24 08:36:41 -06:00
|
|
|
uint32_t size = p_features.size();
|
2010-04-23 17:50:04 -06:00
|
|
|
planecoord pc;
|
|
|
|
pc.dim.x = blockX;
|
|
|
|
pc.dim.y = blockY;
|
|
|
|
std::vector<t_feature *> tempvec;
|
2010-04-24 08:36:41 -06:00
|
|
|
for(uint32_t i = 0; i < size; i++)
|
2010-04-23 17:50:04 -06:00
|
|
|
{
|
|
|
|
uint32_t cur_ptr = p_features[i];
|
2010-06-24 23:11:26 -06:00
|
|
|
|
2010-04-23 17:50:04 -06:00
|
|
|
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
|
|
|
|
{
|
|
|
|
// create, add to store
|
|
|
|
t_feature tftemp;
|
|
|
|
tftemp.discovered = false; //= p->readDWord(cur_ptr + 4);
|
|
|
|
tftemp.origin = cur_ptr;
|
|
|
|
string name = p->readClassName(p->readDWord( cur_ptr ));
|
|
|
|
if(name == "feature_init_deep_special_tubest")
|
|
|
|
{
|
|
|
|
tftemp.main_material = p->readWord( cur_ptr + main_mat_offset );
|
|
|
|
tftemp.sub_material = p->readDWord( cur_ptr + sub_mat_offset );
|
|
|
|
tftemp.type = feature_Adamantine_Tube;
|
|
|
|
}
|
2010-04-27 15:48:25 -06:00
|
|
|
else if(name == "feature_init_deep_surface_portalst")
|
|
|
|
{
|
|
|
|
tftemp.main_material = p->readWord( cur_ptr + main_mat_offset );
|
|
|
|
tftemp.sub_material = p->readDWord( cur_ptr + sub_mat_offset );
|
|
|
|
tftemp.type = feature_Hell_Temple;
|
|
|
|
}
|
2010-04-23 17:50:04 -06:00
|
|
|
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]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
local_features[pc] = tempvec;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Maps::ReadGlobalFeatures( std::vector <t_feature> & features)
|
|
|
|
{
|
2010-06-16 22:46:20 -06:00
|
|
|
MAPS_GUARD
|
2011-02-16 17:18:27 -07:00
|
|
|
if(!d->hasFeatures) return false;
|
2010-04-25 12:52:57 -06:00
|
|
|
// can't be used without a map!
|
|
|
|
if(!d->block)
|
|
|
|
return false;
|
2010-06-24 23:11:26 -06:00
|
|
|
|
2010-04-23 17:50:04 -06:00
|
|
|
Process * p = d->owner;
|
2010-06-24 23:11:26 -06:00
|
|
|
|
2010-08-28 07:43:53 -06:00
|
|
|
const uint32_t global_feature_vector = d->OG_global_features->getAddress("vector");
|
|
|
|
const uint32_t global_feature_funcptr = d->OG_global_features->getOffset("funcptr");
|
|
|
|
const uint32_t main_mat_offset = d->OG_global_features->getOffset("material"); // 0x34
|
|
|
|
const uint32_t sub_mat_offset = d->OG_global_features->getOffset("submaterial"); // 0x38
|
2010-04-23 17:50:04 -06:00
|
|
|
DfVector<uint32_t> p_features (p,global_feature_vector);
|
2010-06-24 23:11:26 -06:00
|
|
|
|
2010-04-23 17:50:04 -06:00
|
|
|
features.clear();
|
2010-04-24 08:36:41 -06:00
|
|
|
uint32_t size = p_features.size();
|
2010-04-23 17:50:04 -06:00
|
|
|
features.reserve(size);
|
2010-04-24 08:36:41 -06:00
|
|
|
for(uint32_t i = 0; i < size; i++)
|
2010-04-23 17:50:04 -06:00
|
|
|
{
|
|
|
|
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;
|
2010-06-24 23:11:26 -06:00
|
|
|
|
2010-04-23 17:50:04 -06:00
|
|
|
// FIXME: use the memory_info cache mechanisms
|
|
|
|
string name = p->readClassName(p->readDWord( feat_ptr));
|
|
|
|
if(name == "feature_init_underworld_from_layerst")
|
|
|
|
{
|
|
|
|
temp.main_material = p->readWord( feat_ptr + main_mat_offset );
|
|
|
|
temp.sub_material = p->readDWord( feat_ptr + sub_mat_offset );
|
|
|
|
temp.type = feature_Underworld;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
temp.main_material = -1;
|
|
|
|
temp.sub_material = -1;
|
|
|
|
temp.type = feature_Other;
|
|
|
|
}
|
|
|
|
features.push_back(temp);
|
|
|
|
}
|
|
|
|
return true;
|
2010-05-01 18:38:18 -06:00
|
|
|
}
|
|
|
|
|