Merge remote-tracking branch 'origin/master'

develop
Alexander Gavrilov 2012-01-08 16:19:58 +04:00
commit 64a9a49ec0
12 changed files with 125 additions and 361 deletions

@ -1097,8 +1097,6 @@ MODULE_GETTER(Materials);
MODULE_GETTER(Items); MODULE_GETTER(Items);
MODULE_GETTER(Translation); MODULE_GETTER(Translation);
MODULE_GETTER(Vegetation); MODULE_GETTER(Vegetation);
MODULE_GETTER(Buildings);
MODULE_GETTER(Constructions); MODULE_GETTER(Constructions);
MODULE_GETTER(Vermin);
MODULE_GETTER(Notes); MODULE_GETTER(Notes);
MODULE_GETTER(Graphic); MODULE_GETTER(Graphic);

@ -61,9 +61,7 @@ namespace DFHack
class Items; class Items;
class Translation; class Translation;
class Vegetation; class Vegetation;
class Buildings;
class Constructions; class Constructions;
class Vermin;
class Notes; class Notes;
class VersionInfo; class VersionInfo;
class VersionInfoFactory; class VersionInfoFactory;
@ -119,12 +117,8 @@ namespace DFHack
Translation * getTranslation(); Translation * getTranslation();
/// get the vegetation module /// get the vegetation module
Vegetation * getVegetation(); Vegetation * getVegetation();
/// get the buildings module
Buildings * getBuildings();
/// get the constructions module /// get the constructions module
Constructions * getConstructions(); Constructions * getConstructions();
/// get the vermin module
Vermin * getVermin();
/// get the notes module /// get the notes module
Notes * getNotes(); Notes * getNotes();
/// get the graphic module /// get the graphic module
@ -182,9 +176,7 @@ namespace DFHack
Items * pItems; Items * pItems;
Translation * pTranslation; Translation * pTranslation;
Vegetation * pVegetation; Vegetation * pVegetation;
Buildings * pBuildings;
Constructions * pConstructions; Constructions * pConstructions;
Vermin * pVermin;
Notes * pNotes; Notes * pNotes;
Graphic * pGraphic; Graphic * pGraphic;
} s_mods; } s_mods;

@ -41,7 +41,6 @@ namespace DFHack
Module* createBuildings(); Module* createBuildings();
Module* createConstructions(); Module* createConstructions();
Module* createMaps(); Module* createMaps();
Module* createVermin();
Module* createNotes(); Module* createNotes();
Module* createGraphic(); Module* createGraphic();
} }

@ -23,61 +23,49 @@ distribution.
*/ */
#pragma once #pragma once
#ifndef CL_MOD_BUILDINGS
#define CL_MOD_BUILDINGS
/**
* \defgroup grp_buildings Building module parts - also includes zones and stockpiles
* @ingroup grp_modules
*/
#include "Export.h" #include "Export.h"
#include "Module.h"
#ifdef __cplusplus
namespace DFHack namespace DFHack
{ {
#endif namespace Simple
/** {
* Structure for holding a read DF building object namespace Buildings
* \ingroup grp_buildings {
*/ /**
struct t_building * Structure for holding a read DF building object
{ * \ingroup grp_buildings
uint32_t x1; */
uint32_t y1; struct t_building
uint32_t x2; {
uint32_t y2; uint32_t x1;
uint32_t z; uint32_t y1;
t_matglossPair material; uint32_t x2;
uint32_t type; uint32_t y2;
int32_t custom_type; uint32_t z;
void * origin; t_matglossPair material;
}; uint32_t type;
int32_t custom_type;
void * origin;
};
#ifdef __cplusplus /**
/** * The Buildings module - allows reading DF buildings
* The Buildings module - allows reading DF buildings * \ingroup grp_modules
* \ingroup grp_modules * \ingroup grp_buildings
* \ingroup grp_buildings */
*/ DFHACK_EXPORT uint32_t getNumBuildings ();
class DFHACK_EXPORT Buildings : public Module
{
public:
Buildings();
~Buildings();
bool Start(uint32_t & numBuildings);
// read one building at offset
bool Read (const uint32_t index, t_building & building);
bool Finish();
// read mapping from custom_type value to building RAW name /**
// custom_type of -1 implies ordinary building * read building by index
bool ReadCustomWorkshopTypes(std::map <uint32_t, std::string> & btypes); */
DFHACK_EXPORT bool Read (const uint32_t index, t_building & building);
private: /**
struct Private; * read mapping from custom_type value to building RAW name
Private *d; * custom_type of -1 implies ordinary building
}; */
} DFHACK_EXPORT bool ReadCustomWorkshopTypes(std::map <uint32_t, std::string> & btypes);
#endif // __cplusplus
#endif }
}
}

@ -1,22 +1,15 @@
#pragma once #pragma once
#ifndef CL_MOD_VERMIN
#define CL_MOD_VERMIN
/** /**
* \defgroup grp_vermin Wild vermin (ants, bees, etc) * \defgroup grp_vermin Wild vermin (ants, bees, etc)
* @ingroup grp_vermin
*/ */
#include "Export.h" #include "Export.h"
#include "Module.h" namespace DFHack { namespace Simple { namespace Vermin
#ifdef __cplusplus
namespace DFHack
{ {
#endif
/** /**
* Structure for holding a read DF vermin spawn point object * Structure for holding a read DF vermin spawn point object
* \ingroup grp_vermin * \ingroup grp_vermin
*/ */
struct t_spawnPoint struct t_vermin
{ {
void * origin; void * origin;
int16_t race; int16_t race;
@ -29,58 +22,21 @@ namespace DFHack
uint32_t countdown; uint32_t countdown;
}; };
#ifdef __cplusplus static const uint16_t TYPE_WILD_COLONY = 0xFFFF;
class DFContextShared;
class SpawnPoints;
/** /**
* The Vermin module - allows reading DF vermin * Get number of vermin objects
* \ingroup grp_modules
* \ingroup grp_vermin
*/ */
class DFHACK_EXPORT Vermin : public Module DFHACK_EXPORT uint32_t getNumVermin();
{ /**
public: * Read from vermin object
Vermin(); */
~Vermin(); DFHACK_EXPORT bool Read (const uint32_t index, t_vermin & point);
/**
bool Finish(); * Write into vermin object
*/
// NOTE: caller must call delete on result when done. DFHACK_EXPORT bool Write (const uint32_t index, t_vermin & point);
SpawnPoints* getSpawnPoints(); /**
* Is vermin object a colony?
private: */
struct Private; DFHACK_EXPORT bool isWildColony(t_vermin & point);
Private *d; } } } // end DFHack::Simple::Vermin
friend class SpawnPoints;
};
class DFHACK_EXPORT SpawnPoints
{
public:
static const uint16_t TYPE_WILD_COLONY = 0xFFFF;
protected:
SpawnPoints(Vermin * v);
public:
~SpawnPoints();
size_t size();
bool Read (const uint32_t index, t_spawnPoint & point);
bool Write (const uint32_t index, t_spawnPoint & point);
bool isValid();
static bool isWildColony(t_spawnPoint & point);
private:
Vermin* v;
std::vector <char*> * p_sp;
friend class Vermin;
};
}
#endif // __cplusplus
#endif

@ -38,10 +38,10 @@ using namespace std;
#include "ModuleFactory.h" #include "ModuleFactory.h"
#include "Core.h" #include "Core.h"
using namespace DFHack; using namespace DFHack;
using namespace DFHack::Simple;
#include "DataDefs.h" #include "DataDefs.h"
#include "df/world.h" #include "df/world.h"
#include "df/world_raws.h"
#include "df/building_def.h" #include "df/building_def.h"
#include "df/building.h" #include "df/building.h"
#include "df/building_workshopst.h" #include "df/building_workshopst.h"
@ -50,70 +50,19 @@ using namespace df::enums;
using df::global::world; using df::global::world;
using df::building_def; using df::building_def;
//raw uint32_t Buildings::getNumBuildings()
struct t_building_df40d
{ {
uint32_t vtable; return world->buildings.all.size();
uint32_t x1;
uint32_t y1;
uint32_t centerx;
uint32_t x2;
uint32_t y2;
uint32_t centery;
uint32_t z;
uint32_t height;
t_matglossPair material;
// not complete
};
struct Buildings::Private
{
Process * owner;
bool Inited;
bool Started;
int32_t custom_workshop_id;
};
Module* DFHack::createBuildings()
{
return new Buildings();
}
Buildings::Buildings()
{
Core & c = Core::getInstance();
d = new Private;
d->Started = false;
d->owner = c.p;
d->Inited = true;
c.vinfo->resolveClassnameToClassID("building_custom_workshop", d->custom_workshop_id);
}
Buildings::~Buildings()
{
if(d->Started)
Finish();
delete d;
}
bool Buildings::Start(uint32_t & numbuildings)
{
if(!d->Inited)
return false;
numbuildings = world->buildings.all.size();
d->Started = true;
return true;
} }
bool Buildings::Read (const uint32_t index, t_building & building) bool Buildings::Read (const uint32_t index, t_building & building)
{ {
if(!d->Started) Core & c = Core::getInstance();
return false;
df::building *bld_40d = world->buildings.all[index]; df::building *bld_40d = world->buildings.all[index];
// transform // transform
int32_t type = -1; int32_t type = -1;
d->owner->getDescriptor()->resolveObjectToClassID ( (char *)bld_40d, type); c.vinfo->resolveObjectToClassID ( (char *)bld_40d, type);
building.x1 = bld_40d->x1; building.x1 = bld_40d->x1;
building.x2 = bld_40d->x2; building.x2 = bld_40d->x2;
building.y1 = bld_40d->y1; building.y1 = bld_40d->y1;
@ -127,19 +76,10 @@ bool Buildings::Read (const uint32_t index, t_building & building)
return true; return true;
} }
bool Buildings::Finish()
{
d->Started = false;
return true;
}
bool Buildings::ReadCustomWorkshopTypes(map <uint32_t, string> & btypes) bool Buildings::ReadCustomWorkshopTypes(map <uint32_t, string> & btypes)
{ {
if(!d->Inited)
return false;
Core & c = Core::getInstance(); Core & c = Core::getInstance();
Process * p = d->owner;
vector <building_def *> & bld_def = world->raws.buildings.all; vector <building_def *> & bld_def = world->raws.buildings.all;
uint32_t size = bld_def.size(); uint32_t size = bld_def.size();
btypes.clear(); btypes.clear();

@ -37,150 +37,51 @@ using namespace std;
#include "ModuleFactory.h" #include "ModuleFactory.h"
#include "Core.h" #include "Core.h"
using namespace DFHack; using namespace DFHack;
using namespace DFHack::Simple;
struct Vermin::Private #include "DataDefs.h"
{ #include "df/world.h"
void * spawn_points_vector; #include "df/vermin.h"
uint32_t race_offset; using namespace df::enums;
uint32_t type_offset; using df::global::world;
uint32_t position_offset;
uint32_t in_use_offset;
uint32_t unknown_offset;
uint32_t countdown_offset;
Process * owner;
bool Inited;
bool Started;
};
Module* DFHack::createVermin()
{
return new Vermin();
}
#include <stdio.h>
Vermin::Vermin() uint32_t Vermin::getNumVermin()
{ {
Core & c = Core::getInstance(); return df::vermin::get_vector().size();
d = new Private;
d->owner = c.p;
d->Inited = d->Started = false;
VersionInfo * mem = c.vinfo;
OffsetGroup * OG_vermin = mem->getGroup("Vermin");
OffsetGroup * OG_spawn = OG_vermin->getGroup("Spawn Points");
d->Inited = true;
try
{
d->spawn_points_vector = OG_spawn->getAddress("vector");
d->race_offset = OG_spawn->getOffset("race");
d->type_offset = OG_spawn->getOffset("type");
d->position_offset = OG_spawn->getOffset("position");
d->in_use_offset = OG_spawn->getOffset("in_use");
d->unknown_offset = OG_spawn->getOffset("unknown");
d->countdown_offset = OG_spawn->getOffset("countdown");
}
catch(DFHack::Error::AllMemdef &e)
{
cerr << "Vermin not available... " << e.what() << endl;
d->Inited = false;
}
} }
bool Vermin::Finish() bool Vermin::Read (const uint32_t index, t_vermin & sp)
{ {
df::vermin *verm = df::vermin::find(index);
if (!verm) return false;
sp.origin = verm;
sp.race = verm->race;
sp.type = verm->type;
sp.in_use = verm->in_use;
sp.countdown = verm->countdown;
sp.x = verm->x;
sp.y = verm->y;
sp.z = verm->z;
return true; return true;
} }
Vermin::~Vermin() bool Vermin::Write (const uint32_t index, t_vermin & sp)
{
delete d;
}
// NOTE: caller must call delete on result when done.
SpawnPoints* Vermin::getSpawnPoints()
{
if (!d->Inited)
{
cerr << "Couldn't get spawn points: Vermin module not inited" << endl;
return NULL;
}
return new SpawnPoints(this);
}
SpawnPoints::SpawnPoints(Vermin* v_)
{
v = v_;
p_sp = NULL;
if (!v->d->Inited)
{
cerr << "Couldn't get spawn points: Vermin module not inited" << endl;
return;
}
p_sp = (vector <char*>*) (v->d->spawn_points_vector);
}
SpawnPoints::~SpawnPoints()
{
}
size_t SpawnPoints::size()
{ {
if (!isValid()) df::vermin *verm = df::vermin::find(index);
return 0; if (!verm) return false;
return p_sp->size(); verm->race = sp.race;
} verm->type = sp.type;
verm->in_use = sp.in_use;
bool SpawnPoints::Read (const uint32_t index, t_spawnPoint & sp) verm->countdown = sp.countdown;
{ verm->x = sp.x;
if(!isValid()) verm->y = sp.y;
return false; verm->z = sp.z;
// read pointer from vector at position
char * temp = p_sp->at (index);
sp.origin = temp;
sp.race = v->d->owner->readWord(temp + v->d->race_offset);
sp.type = v->d->owner->readWord(temp + v->d->type_offset);
sp.in_use = v->d->owner->readByte(temp + v->d->in_use_offset);
sp.unknown = v->d->owner->readByte(temp + v->d->unknown_offset);
sp.countdown = v->d->owner->readDWord(temp + v->d->countdown_offset);
// Three consecutive 16 bit numbers for x/y/z
v->d->owner->read(temp + v->d->position_offset, 6, (uint8_t*) &sp.x);
return true; return true;
} }
bool SpawnPoints::Write (const uint32_t index, t_spawnPoint & sp) bool Vermin::isWildColony(t_vermin & point)
{
if(!isValid())
return false;
// read pointer from vector at position
char * temp = p_sp->at (index);
v->d->owner->writeWord(temp + v->d->race_offset, sp.race);
v->d->owner->writeWord(temp + v->d->type_offset, sp.type);
v->d->owner->writeByte(temp + v->d->in_use_offset, sp.in_use);
v->d->owner->writeByte(temp + v->d->unknown_offset, sp.unknown);
v->d->owner->writeDWord(temp + v->d->countdown_offset, sp.countdown);
// Three consecutive 16 bit numbers for x/y/z
v->d->owner->write(temp + v->d->position_offset, 6, (uint8_t*) &sp.x);
return true;
}
bool SpawnPoints::isWildColony(t_spawnPoint & point)
{ {
return (point.type == TYPE_WILD_COLONY); return (point.type == TYPE_WILD_COLONY);
} }
bool SpawnPoints::isValid()
{
return (v != NULL && v->d->Inited && p_sp != NULL);
}

@ -1 +1 @@
Subproject commit aeb25a2e804aa8459f80b5d84d5cb811414d6305 Subproject commit b93b61a988020a4aaa0103cefcee0217c37ce7b0

@ -9,6 +9,7 @@
using std::vector; using std::vector;
using std::string; using std::string;
using namespace DFHack; using namespace DFHack;
using namespace DFHack::Simple;
#include <DFHack.h> #include <DFHack.h>
DFhackCExport command_result colonies (Core * c, vector <string> & parameters); DFhackCExport command_result colonies (Core * c, vector <string> & parameters);
@ -32,10 +33,9 @@ DFhackCExport command_result plugin_shutdown ( Core * c )
return CR_OK; return CR_OK;
} }
void destroyColonies(DFHack::SpawnPoints *points); void destroyColonies();
void convertColonies(DFHack::SpawnPoints *points, DFHack::Materials *Materials); void convertColonies(DFHack::Materials *Materials);
void showColonies(Core *c, DFHack::SpawnPoints *points, void showColonies(Core *c, DFHack::Materials *Materials);
DFHack::Materials *Materials);
DFhackCExport command_result colonies (Core * c, vector <string> & parameters) DFhackCExport command_result colonies (Core * c, vector <string> & parameters)
{ {
@ -71,54 +71,41 @@ DFhackCExport command_result colonies (Core * c, vector <string> & parameters)
} }
c->Suspend(); c->Suspend();
Vermin * vermin = c->getVermin();
Materials * materials = c->getMaterials(); Materials * materials = c->getMaterials();
SpawnPoints *points = vermin->getSpawnPoints();
if(!points || !points->isValid())
{
c->con.printerr("vermin not supported for this DF version\n");
c->Resume();
return CR_FAILURE;
}
materials->ReadCreatureTypesEx(); materials->ReadCreatureTypesEx();
if (destroy) if (destroy)
destroyColonies(points); destroyColonies();
else if (convert) else if (convert)
convertColonies(points, materials); convertColonies(materials);
else else
showColonies(c, points, materials); showColonies(c, materials);
delete points;
vermin->Finish();
materials->Finish(); materials->Finish();
c->Resume(); c->Resume();
return CR_OK; return CR_OK;
} }
void destroyColonies(DFHack::SpawnPoints *points) void destroyColonies()
{ {
uint32_t numSpawnPoints = points->size(); uint32_t numSpawnPoints = Vermin::getNumVermin();
for (uint32_t i = 0; i < numSpawnPoints; i++) for (uint32_t i = 0; i < numSpawnPoints; i++)
{ {
DFHack::t_spawnPoint sp; Vermin::t_vermin sp;
points->Read(i, sp); Vermin::Read(i, sp);
if (sp.in_use && DFHack::SpawnPoints::isWildColony(sp)) if (sp.in_use && Vermin::isWildColony(sp))
{ {
sp.in_use = false; sp.in_use = false;
points->Write(i, sp); Vermin::Write(i, sp);
} }
} }
} }
// Convert all colonies to honey bees. // Convert all colonies to honey bees.
void convertColonies(DFHack::SpawnPoints *points, DFHack::Materials *Materials) void convertColonies(DFHack::Materials *Materials)
{ {
int bee_idx = -1; int bee_idx = -1;
for (size_t i = 0; i < Materials->raceEx.size(); i++) for (size_t i = 0; i < Materials->raceEx.size(); i++)
@ -134,32 +121,31 @@ void convertColonies(DFHack::SpawnPoints *points, DFHack::Materials *Materials)
return; return;
} }
uint32_t numSpawnPoints = points->size(); uint32_t numSpawnPoints = Vermin::getNumVermin();
for (uint32_t i = 0; i < numSpawnPoints; i++) for (uint32_t i = 0; i < numSpawnPoints; i++)
{ {
DFHack::t_spawnPoint sp; Vermin::t_vermin sp;
points->Read(i, sp); Vermin::Read(i, sp);
if (sp.in_use && DFHack::SpawnPoints::isWildColony(sp)) if (sp.in_use && Vermin::isWildColony(sp))
{ {
sp.race = bee_idx; sp.race = bee_idx;
points->Write(i, sp); Vermin::Write(i, sp);
} }
} }
} }
void showColonies(Core *c, DFHack::SpawnPoints *points, void showColonies(Core *c, DFHack::Materials *Materials)
DFHack::Materials *Materials)
{ {
uint32_t numSpawnPoints = points->size(); uint32_t numSpawnPoints = Vermin::getNumVermin();
int numColonies = 0; int numColonies = 0;
for (uint32_t i = 0; i < numSpawnPoints; i++) for (uint32_t i = 0; i < numSpawnPoints; i++)
{ {
DFHack::t_spawnPoint sp; Vermin::t_vermin sp;
points->Read(i, sp); Vermin::Read(i, sp);
if (sp.in_use && DFHack::SpawnPoints::isWildColony(sp)) if (sp.in_use && Vermin::isWildColony(sp))
{ {
numColonies++; numColonies++;
string race="(no race)"; string race="(no race)";

@ -1 +1 @@
Subproject commit 3277c6b29ddbb5d800ccb65eba27fed200236f3d Subproject commit c114ec5f995aec69631187212254309464f82775

@ -135,7 +135,7 @@ DFhackCExport command_result df_probe (Core * c, vector <string> & parameters)
MapExtras::Block * b = mc.BlockAt(cursor/16); MapExtras::Block * b = mc.BlockAt(cursor/16);
mapblock40d & block = b->raw; mapblock40d & block = b->raw;
if(b) if(b && b->valid)
{ {
con.print("block addr: 0x%x\n\n", block.origin); con.print("block addr: 0x%x\n\n", block.origin);
/* /*
@ -285,6 +285,10 @@ DFhackCExport command_result df_probe (Core * c, vector <string> & parameters)
con << "mystery: " << block.mystery << endl; con << "mystery: " << block.mystery << endl;
con << std::endl; con << std::endl;
} }
else
{
con.printerr("No data.\n");
}
} }
} }
c->Resume(); c->Resume();

@ -1 +1 @@
Subproject commit 545b2730ed137935643778f1b8ba115ae11c50a2 Subproject commit 92627e39cb3502812cd5a131716d3d1da8ef625a