diff --git a/library/Core.cpp b/library/Core.cpp index 4a3dacd25..9404fdb5b 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -1097,8 +1097,6 @@ MODULE_GETTER(Materials); MODULE_GETTER(Items); MODULE_GETTER(Translation); MODULE_GETTER(Vegetation); -MODULE_GETTER(Buildings); MODULE_GETTER(Constructions); -MODULE_GETTER(Vermin); MODULE_GETTER(Notes); MODULE_GETTER(Graphic); diff --git a/library/include/Core.h b/library/include/Core.h index a368e360d..3366b990b 100644 --- a/library/include/Core.h +++ b/library/include/Core.h @@ -61,9 +61,7 @@ namespace DFHack class Items; class Translation; class Vegetation; - class Buildings; class Constructions; - class Vermin; class Notes; class VersionInfo; class VersionInfoFactory; @@ -119,12 +117,8 @@ namespace DFHack Translation * getTranslation(); /// get the vegetation module Vegetation * getVegetation(); - /// get the buildings module - Buildings * getBuildings(); /// get the constructions module Constructions * getConstructions(); - /// get the vermin module - Vermin * getVermin(); /// get the notes module Notes * getNotes(); /// get the graphic module @@ -182,9 +176,7 @@ namespace DFHack Items * pItems; Translation * pTranslation; Vegetation * pVegetation; - Buildings * pBuildings; Constructions * pConstructions; - Vermin * pVermin; Notes * pNotes; Graphic * pGraphic; } s_mods; diff --git a/library/include/ModuleFactory.h b/library/include/ModuleFactory.h index 3677d3554..0ee5b178f 100644 --- a/library/include/ModuleFactory.h +++ b/library/include/ModuleFactory.h @@ -41,7 +41,6 @@ namespace DFHack Module* createBuildings(); Module* createConstructions(); Module* createMaps(); - Module* createVermin(); Module* createNotes(); Module* createGraphic(); } diff --git a/library/include/modules/Buildings.h b/library/include/modules/Buildings.h index 8089fd4b1..7da2ad9dc 100644 --- a/library/include/modules/Buildings.h +++ b/library/include/modules/Buildings.h @@ -23,61 +23,49 @@ distribution. */ #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 "Module.h" -#ifdef __cplusplus namespace DFHack { -#endif - /** - * Structure for holding a read DF building object - * \ingroup grp_buildings - */ - struct t_building - { - uint32_t x1; - uint32_t y1; - uint32_t x2; - uint32_t y2; - uint32_t z; - t_matglossPair material; - uint32_t type; - int32_t custom_type; - void * origin; - }; +namespace Simple +{ +namespace Buildings +{ +/** + * Structure for holding a read DF building object + * \ingroup grp_buildings + */ +struct t_building +{ + uint32_t x1; + uint32_t y1; + uint32_t x2; + uint32_t y2; + uint32_t z; + t_matglossPair material; + uint32_t type; + int32_t custom_type; + void * origin; +}; -#ifdef __cplusplus - /** - * The Buildings module - allows reading DF buildings - * \ingroup grp_modules - * \ingroup grp_buildings - */ - 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(); +/** + * The Buildings module - allows reading DF buildings + * \ingroup grp_modules + * \ingroup grp_buildings + */ +DFHACK_EXPORT uint32_t getNumBuildings (); - // read mapping from custom_type value to building RAW name - // custom_type of -1 implies ordinary building - bool ReadCustomWorkshopTypes(std::map & btypes); +/** + * read building by index + */ +DFHACK_EXPORT bool Read (const uint32_t index, t_building & building); - private: - struct Private; - Private *d; - }; -} -#endif // __cplusplus +/** + * read mapping from custom_type value to building RAW name + * custom_type of -1 implies ordinary building + */ +DFHACK_EXPORT bool ReadCustomWorkshopTypes(std::map & btypes); -#endif +} +} +} diff --git a/library/include/modules/Vermin.h b/library/include/modules/Vermin.h index 324714f5d..bcec96b51 100644 --- a/library/include/modules/Vermin.h +++ b/library/include/modules/Vermin.h @@ -1,22 +1,15 @@ #pragma once -#ifndef CL_MOD_VERMIN -#define CL_MOD_VERMIN /** * \defgroup grp_vermin Wild vermin (ants, bees, etc) - * @ingroup grp_vermin */ #include "Export.h" -#include "Module.h" - -#ifdef __cplusplus -namespace DFHack +namespace DFHack { namespace Simple { namespace Vermin { -#endif /** * Structure for holding a read DF vermin spawn point object * \ingroup grp_vermin */ - struct t_spawnPoint + struct t_vermin { void * origin; int16_t race; @@ -29,58 +22,21 @@ namespace DFHack uint32_t countdown; }; -#ifdef __cplusplus - class DFContextShared; - class SpawnPoints; - + static const uint16_t TYPE_WILD_COLONY = 0xFFFF; /** - * The Vermin module - allows reading DF vermin - * \ingroup grp_modules - * \ingroup grp_vermin + * Get number of vermin objects */ - class DFHACK_EXPORT Vermin : public Module - { - public: - Vermin(); - ~Vermin(); - - bool Finish(); - - // NOTE: caller must call delete on result when done. - SpawnPoints* getSpawnPoints(); - - private: - struct Private; - Private *d; - - 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 * p_sp; - - friend class Vermin; - }; -} -#endif // __cplusplus - -#endif + DFHACK_EXPORT uint32_t getNumVermin(); + /** + * Read from vermin object + */ + DFHACK_EXPORT bool Read (const uint32_t index, t_vermin & point); + /** + * Write into vermin object + */ + DFHACK_EXPORT bool Write (const uint32_t index, t_vermin & point); + /** + * Is vermin object a colony? + */ + DFHACK_EXPORT bool isWildColony(t_vermin & point); +} } } // end DFHack::Simple::Vermin diff --git a/library/modules/Buildings.cpp b/library/modules/Buildings.cpp index 6f2b4a3f3..2213abd35 100644 --- a/library/modules/Buildings.cpp +++ b/library/modules/Buildings.cpp @@ -38,10 +38,10 @@ using namespace std; #include "ModuleFactory.h" #include "Core.h" using namespace DFHack; +using namespace DFHack::Simple; #include "DataDefs.h" #include "df/world.h" -#include "df/world_raws.h" #include "df/building_def.h" #include "df/building.h" #include "df/building_workshopst.h" @@ -50,70 +50,19 @@ using namespace df::enums; using df::global::world; using df::building_def; -//raw -struct t_building_df40d +uint32_t Buildings::getNumBuildings() { - uint32_t vtable; - 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; + return world->buildings.all.size(); } bool Buildings::Read (const uint32_t index, t_building & building) { - if(!d->Started) - return false; + Core & c = Core::getInstance(); df::building *bld_40d = world->buildings.all[index]; // transform 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.x2 = bld_40d->x2; building.y1 = bld_40d->y1; @@ -127,19 +76,10 @@ bool Buildings::Read (const uint32_t index, t_building & building) return true; } -bool Buildings::Finish() -{ - d->Started = false; - return true; -} - bool Buildings::ReadCustomWorkshopTypes(map & btypes) { - if(!d->Inited) - return false; Core & c = Core::getInstance(); - Process * p = d->owner; vector & bld_def = world->raws.buildings.all; uint32_t size = bld_def.size(); btypes.clear(); diff --git a/library/modules/Vermin.cpp b/library/modules/Vermin.cpp index 215815eb0..31e156e22 100644 --- a/library/modules/Vermin.cpp +++ b/library/modules/Vermin.cpp @@ -37,150 +37,51 @@ using namespace std; #include "ModuleFactory.h" #include "Core.h" using namespace DFHack; +using namespace DFHack::Simple; -struct Vermin::Private -{ - void * spawn_points_vector; - uint32_t race_offset; - uint32_t type_offset; - 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 +#include "DataDefs.h" +#include "df/world.h" +#include "df/vermin.h" +using namespace df::enums; +using df::global::world; -Vermin::Vermin() +uint32_t Vermin::getNumVermin() { - Core & c = Core::getInstance(); - - 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; - } + return df::vermin::get_vector().size(); } -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; } -Vermin::~Vermin() -{ - 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 *) (v->d->spawn_points_vector); -} - -SpawnPoints::~SpawnPoints() -{ -} - -size_t SpawnPoints::size() +bool Vermin::Write (const uint32_t index, t_vermin & sp) { - if (!isValid()) - return 0; - - return p_sp->size(); -} - -bool SpawnPoints::Read (const uint32_t index, t_spawnPoint & sp) -{ - if(!isValid()) - return false; - - // 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); - + df::vermin *verm = df::vermin::find(index); + if (!verm) return false; + + verm->race = sp.race; + verm->type = sp.type; + verm->in_use = sp.in_use; + verm->countdown = sp.countdown; + verm->x = sp.x; + verm->y = sp.y; + verm->z = sp.z; return true; } -bool SpawnPoints::Write (const uint32_t index, t_spawnPoint & sp) -{ - 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) +bool Vermin::isWildColony(t_vermin & point) { return (point.type == TYPE_WILD_COLONY); } - -bool SpawnPoints::isValid() -{ - return (v != NULL && v->d->Inited && p_sp != NULL); -} diff --git a/library/xml b/library/xml index aeb25a2e8..b93b61a98 160000 --- a/library/xml +++ b/library/xml @@ -1 +1 @@ -Subproject commit aeb25a2e804aa8459f80b5d84d5cb811414d6305 +Subproject commit b93b61a988020a4aaa0103cefcee0217c37ce7b0 diff --git a/plugins/colonies.cpp b/plugins/colonies.cpp index 6b2d8a1d2..73106b966 100644 --- a/plugins/colonies.cpp +++ b/plugins/colonies.cpp @@ -9,6 +9,7 @@ using std::vector; using std::string; using namespace DFHack; +using namespace DFHack::Simple; #include DFhackCExport command_result colonies (Core * c, vector & parameters); @@ -32,10 +33,9 @@ DFhackCExport command_result plugin_shutdown ( Core * c ) return CR_OK; } -void destroyColonies(DFHack::SpawnPoints *points); -void convertColonies(DFHack::SpawnPoints *points, DFHack::Materials *Materials); -void showColonies(Core *c, DFHack::SpawnPoints *points, - DFHack::Materials *Materials); +void destroyColonies(); +void convertColonies(DFHack::Materials *Materials); +void showColonies(Core *c, DFHack::Materials *Materials); DFhackCExport command_result colonies (Core * c, vector & parameters) { @@ -71,54 +71,41 @@ DFhackCExport command_result colonies (Core * c, vector & parameters) } c->Suspend(); - Vermin * vermin = c->getVermin(); 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(); if (destroy) - destroyColonies(points); + destroyColonies(); else if (convert) - convertColonies(points, materials); + convertColonies(materials); else - showColonies(c, points, materials); - - delete points; + showColonies(c, materials); - vermin->Finish(); materials->Finish(); c->Resume(); 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++) { - DFHack::t_spawnPoint sp; - points->Read(i, sp); + Vermin::t_vermin sp; + Vermin::Read(i, sp); - if (sp.in_use && DFHack::SpawnPoints::isWildColony(sp)) + if (sp.in_use && Vermin::isWildColony(sp)) { sp.in_use = false; - points->Write(i, sp); + Vermin::Write(i, sp); } } } // Convert all colonies to honey bees. -void convertColonies(DFHack::SpawnPoints *points, DFHack::Materials *Materials) +void convertColonies(DFHack::Materials *Materials) { int bee_idx = -1; for (size_t i = 0; i < Materials->raceEx.size(); i++) @@ -134,32 +121,31 @@ void convertColonies(DFHack::SpawnPoints *points, DFHack::Materials *Materials) return; } - uint32_t numSpawnPoints = points->size(); + uint32_t numSpawnPoints = Vermin::getNumVermin(); for (uint32_t i = 0; i < numSpawnPoints; i++) { - DFHack::t_spawnPoint sp; - points->Read(i, sp); + Vermin::t_vermin sp; + Vermin::Read(i, sp); - if (sp.in_use && DFHack::SpawnPoints::isWildColony(sp)) + if (sp.in_use && Vermin::isWildColony(sp)) { sp.race = bee_idx; - points->Write(i, sp); + Vermin::Write(i, sp); } } } -void showColonies(Core *c, DFHack::SpawnPoints *points, - DFHack::Materials *Materials) +void showColonies(Core *c, DFHack::Materials *Materials) { - uint32_t numSpawnPoints = points->size(); + uint32_t numSpawnPoints = Vermin::getNumVermin(); int numColonies = 0; 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++; string race="(no race)"; diff --git a/plugins/df2mc b/plugins/df2mc index 3277c6b29..c114ec5f9 160000 --- a/plugins/df2mc +++ b/plugins/df2mc @@ -1 +1 @@ -Subproject commit 3277c6b29ddbb5d800ccb65eba27fed200236f3d +Subproject commit c114ec5f995aec69631187212254309464f82775 diff --git a/plugins/probe.cpp b/plugins/probe.cpp index a000d9e31..d70a6dbaf 100644 --- a/plugins/probe.cpp +++ b/plugins/probe.cpp @@ -135,7 +135,7 @@ DFhackCExport command_result df_probe (Core * c, vector & parameters) MapExtras::Block * b = mc.BlockAt(cursor/16); mapblock40d & block = b->raw; - if(b) + if(b && b->valid) { con.print("block addr: 0x%x\n\n", block.origin); /* @@ -285,6 +285,10 @@ DFhackCExport command_result df_probe (Core * c, vector & parameters) con << "mystery: " << block.mystery << endl; con << std::endl; } + else + { + con.printerr("No data.\n"); + } } } c->Resume(); diff --git a/plugins/stonesense b/plugins/stonesense index 545b2730e..92627e39c 160000 --- a/plugins/stonesense +++ b/plugins/stonesense @@ -1 +1 @@ -Subproject commit 545b2730ed137935643778f1b8ba115ae11c50a2 +Subproject commit 92627e39cb3502812cd5a131716d3d1da8ef625a