Alternate way to read vegetation using a vector in map blocks. 31.19 only for now.

develop
Petr Mrázek 2011-02-27 13:59:45 +01:00
parent 4a62b2db71
commit 254aec1787
5 changed files with 93 additions and 21 deletions

@ -730,6 +730,7 @@
<Address name="world_size_y"/>
<Group name="block" description="The map block structure.">
<Offset name="vein_vector" description="Mineral veins, objects holding tile types under ice, etc..."/>
<Offset name="vegetation_vector" description="All the plants in this block, including farm plats."/>
<Offset name="type" description="16x16 x 2B tile type values"/>
<Offset name="designation" description="16x16 * 4B designation fields"/>
<Offset name="occupancy" description="16x16 * 4B occupancy fields" />
@ -1961,6 +1962,7 @@
<Offset name="vein_vector" value="0x8" />
<Offset name="feature_global" value="0x28" />
<Offset name="feature_local" value="0x24" />
<Offset name="vegetation_vector" value="0x60" />
<Offset name="type" value="0x7a" />
<Offset name="designation" value="0x27c" />
<Offset name="occupancy" value="0x67c" />

@ -7,6 +7,8 @@
#include "dfhack/DFExport.h"
#include "dfhack/DFModule.h"
#include "Vegetation.h"
namespace DFHack
{
/***************************************************************************
@ -431,7 +433,8 @@ namespace DFHack
std::vector<t_spattervein>* splatter = 0,
std::vector<t_grassvein>* grass = 0
);
/// read all plants in this block
bool ReadVegetation(uint32_t x, uint32_t y, uint32_t z, std::vector<t_tree>* plants);
private:
struct Private;
Private *d;

@ -59,6 +59,7 @@ struct Maps::Private
bool Started;
bool hasGeology;
bool hasFeatures;
bool hasVeggies;
// map between feature address and the read object
map <uint32_t, t_feature> local_feature_store;
@ -76,7 +77,7 @@ Maps::Maps(DFContextShared* _d)
DFHack::VersionInfo * mem = p->getDescriptor();
Server::Maps::maps_offsets &off = d->offsets;
d->hasFeatures = d->hasGeology = true;
d->hasFeatures = d->hasGeology = d->hasVeggies = true;
// get the offsets once here
OffsetGroup *OG_Maps = mem->getGroup("Maps");
@ -127,6 +128,16 @@ Maps::Maps(DFContextShared* _d)
{
d->hasFeatures = false;
}
try
{
OffsetGroup * OG_Veg = d->d->offset_descriptor->getGroup("Vegetation");
off.vegvector = OG_MapBlock->getOffset ("vegetation_vector");
off.tree_desc_offset = OG_Veg->getOffset ("tree_desc_offset");
}
catch(Error::AllMemdef &)
{
d->hasVeggies = false;
}
}
d->OG_vector = mem->getGroup("vector");
@ -901,3 +912,25 @@ bool Maps::ReadGlobalFeatures( std::vector <t_feature> & features)
return true;
}
bool Maps::ReadVegetation(uint32_t x, uint32_t y, uint32_t z, std::vector<t_tree>* plants)
{
if(!d->hasVeggies || !d->Started)
return false;
uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z];
if(!addr)
return false;
t_tree shrubbery;
plants->clear();
Server::Maps::maps_offsets & off = d->offsets;
DfVector<uint32_t> vegptrs(d->owner, addr + off.vegvector);
for(int i = 0; i < vegptrs.size(); i++)
{
d->owner->read (vegptrs[i] + off.tree_desc_offset, sizeof (t_tree), (uint8_t *) &shrubbery);
shrubbery.address = vegptrs[i];
plants->push_back(shrubbery);
}
if(plants->empty()) return false;
return true;
}

@ -34,7 +34,7 @@ namespace DFHack
namespace Maps
{
// increment on every change
#define MAPS_VERSION 4
#define MAPS_VERSION 5
typedef struct
{
uint32_t map_offset;// = d->offset_descriptor->getAddress ("map_data");
@ -49,6 +49,7 @@ typedef struct
uint32_t occupancy_offset;// = d->offset_descriptor->getOffset ("occupancy");
uint32_t biome_stuffs;// = d->offset_descriptor->getOffset ("biome_stuffs");
uint32_t veinvector;// = d->offset_descriptor->getOffset ("v_vein");
uint32_t vegvector;
uint32_t temperature1_offset;
uint32_t temperature2_offset;
uint32_t global_feature_offset;
@ -73,6 +74,11 @@ typedef struct
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");
/*
* Vegetation
*/
uint32_t tree_desc_offset;
} maps_offsets;
typedef struct

@ -12,6 +12,29 @@ using namespace std;
#define DFHACK_WANT_MISCUTILS
#include <DFHack.h>
void print_tree( DFHack::Context * DF , DFHack::t_tree & tree)
{
DFHack::Materials * mat = DF->getMaterials();
printf("%d:%d = ",tree.type,tree.material);
if(tree.type == 1 || tree.type == 3)
{
cout << "near-water ";
}
cout << mat->organic[tree.material].id << " ";
if(tree.type == 0 || tree.type == 1)
{
cout << "tree";
}
if(tree.type == 2 || tree.type == 3)
{
cout << "shrub";
}
cout << endl;
printf("Address: 0x%x\n", tree.address);
hexdump(DF,tree.address,13);
}
int main (int numargs, const char ** args)
{
uint32_t addr;
@ -40,6 +63,7 @@ int main (int numargs, const char ** args)
DFHack::VersionInfo* mem = DF->getMemoryInfo();
DFHack::Position * pos = DF->getPosition();
DFHack::Vegetation * v = DF->getVegetation();
DFHack::Maps * mps = DF->getMaps();
DFHack::Materials * mat = DF->getMaterials();
mat->ReadOrganicMaterials();
@ -59,31 +83,35 @@ int main (int numargs, const char ** args)
}
}
else
{
// new method, gets the vector of trees in a block. can show farm plants
if(mps->Start())
{
vector<DFHack::t_tree> alltrees;
if(mps->ReadVegetation(x/16,y/16,z,&alltrees))
{
for(int i = 0 ; i < alltrees.size(); i++)
{
DFHack::t_tree & tree = alltrees[i];
// you could take the tree coords from the struct and % them with 16 for use in loops over the whole block
if(tree.x == x && tree.y == y && tree.z == z)
{
cout << "----==== Tree at "<< x << "/" << y << "/" << z << " ====----" << endl;
print_tree(DF, tree);
break;
}
}
}
}
// old method, gets the tree from the global vegetation vector. can't show farm plants
for(uint32_t i =0; i < numVegs; i++)
{
DFHack::t_tree tree;
v->Read(i,tree);
if(tree.x == x && tree.y == y && tree.z == z)
{
printf("%d:%d = ",tree.type,tree.material);
if(tree.type == 1 || tree.type == 3)
{
cout << "near-water ";
}
cout << mat->organic[tree.material].id << " ";
if(tree.type == 0 || tree.type == 1)
{
cout << "tree";
}
if(tree.type == 2 || tree.type == 3)
{
cout << "shrub";
}
cout << endl;
printf("Address: 0x%x\n", tree.address);
hexdump(DF,tree.address,13);
cout << "----==== Tree at "<< x << "/" << y << "/" << z << " ====----" << endl;
print_tree(DF, tree);
break;
}
}