diff --git a/library/Core.cpp b/library/Core.cpp index eb1f51b11..7fd2158dc 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -1,4 +1,4 @@ -/* +/* https://github.com/peterix/dfhack Copyright (c) 2009-2011 Petr Mrázek (peterix@gmail.com) @@ -1091,6 +1091,5 @@ TYPE * Core::get##TYPE() \ MODULE_GETTER(Gui); MODULE_GETTER(World); MODULE_GETTER(Materials); -MODULE_GETTER(Constructions); MODULE_GETTER(Notes); MODULE_GETTER(Graphic); diff --git a/library/include/Core.h b/library/include/Core.h index 02ef883ad..c1d9f8217 100644 --- a/library/include/Core.h +++ b/library/include/Core.h @@ -1,4 +1,4 @@ -/* +/* https://github.com/peterix/dfhack Copyright (c) 2009-2011 Petr Mrázek (peterix@gmail.com) @@ -55,7 +55,6 @@ namespace DFHack class Gui; class World; class Materials; - class Constructions; class Notes; class VersionInfo; class VersionInfoFactory; @@ -99,8 +98,6 @@ namespace DFHack World * getWorld(); /// get the materials module Materials * getMaterials(); - /// get the constructions module - Constructions * getConstructions(); /// get the notes module Notes * getNotes(); /// get the graphic module @@ -152,7 +149,6 @@ namespace DFHack Gui * pGui; World * pWorld; Materials * pMaterials; - Constructions * pConstructions; Notes * pNotes; Graphic * pGraphic; } s_mods; diff --git a/library/include/ModuleFactory.h b/library/include/ModuleFactory.h index 33b31f036..4a2f3870d 100644 --- a/library/include/ModuleFactory.h +++ b/library/include/ModuleFactory.h @@ -1,4 +1,4 @@ -/* +/* https://github.com/peterix/dfhack Copyright (c) 2009-2011 Petr Mrázek (peterix@gmail.com) @@ -34,7 +34,6 @@ namespace DFHack Module* createWorld(); Module* createMaterials(); Module* createVegetation(); - Module* createConstructions(); Module* createNotes(); Module* createGraphic(); } diff --git a/library/include/modules/Constructions.h b/library/include/modules/Constructions.h index 85c9175dc..6e836ae65 100644 --- a/library/include/modules/Constructions.h +++ b/library/include/modules/Constructions.h @@ -1,4 +1,4 @@ -/* +/* https://github.com/peterix/dfhack Copyright (c) 2009-2011 Petr Mrázek (peterix@gmail.com) @@ -26,10 +26,11 @@ distribution. #ifndef CL_MOD_CONSTRUCTIONS #define CL_MOD_CONSTRUCTIONS /* -* DF constructions -*/ + * DF constructions + */ #include "Export.h" -#include "Module.h" +#include "DataDefs.h" +#include "df/construction.h" /** * \defgroup grp_constructions Construction module parts @@ -37,64 +38,14 @@ distribution. */ namespace DFHack { - /** - * type of item the construction is made of - * \ingroup grp_constructions - */ - enum e_construction_base - { - constr_bar = 0, /*!< Bars */ - constr_block = 2, /*!< Blocks */ - constr_boulder = 4, /*!< Rough stones or boulders */ - constr_logs = 5 /*!< Wooden logs */ - }; - #pragma pack(push, 1) - /** - * structure for holding a DF construction - * \ingroup grp_constructions - */ - struct t_construction - { - //0 - uint16_t x; /*!< X coordinate */ - uint16_t y; /*!< Y coordinate */ - // 4 - uint16_t z; /*!< Z coordinate */ - uint16_t form; /*!< type of item the construction is made of */ - // 8 - uint16_t unk_8; // = -1 in many cases - uint16_t mat_type; - // C - uint32_t mat_idx; - uint16_t unk3; - // 10 - uint16_t unk4; - uint16_t unk5; - // 14 - uint32_t unk6; - - /// Address of the read object in DF memory. Added by DFHack. - t_construction * origin; - }; - #pragma pack (pop) - class DFContextShared; - /** - * The Constructions module - allows reading constructed tiles (walls, floors, stairs, etc.) - * \ingroup grp_modules - * \ingroup grp_constructions - */ - class DFHACK_EXPORT Constructions : public Module - { - public: - Constructions(); - ~Constructions(); - bool Start(uint32_t & numConstructions); - bool Read (const uint32_t index, t_construction & constr); - bool Finish(); - - private: - struct Private; - Private *d; - }; +namespace Simple +{ +namespace Constructions +{ +DFHACK_EXPORT bool isValid(); +DFHACK_EXPORT uint32_t getCount(); +DFHACK_EXPORT df::construction *getConstruction (const int32_t index); +} +} } #endif diff --git a/library/modules/Constructions.cpp b/library/modules/Constructions.cpp index 1ae5f8337..62c87424a 100644 --- a/library/modules/Constructions.cpp +++ b/library/modules/Constructions.cpp @@ -1,4 +1,4 @@ -/* +/* https://github.com/peterix/dfhack Copyright (c) 2009-2011 Petr Mrázek (peterix@gmail.com) @@ -34,64 +34,26 @@ using namespace std; #include "VersionInfo.h" #include "MemAccess.h" #include "Types.h" -#include "modules/Constructions.h" -#include "ModuleFactory.h" #include "Core.h" - +#include "modules/Constructions.h" +#include "df/world.h" using namespace DFHack; +using namespace DFHack::Simple; +using df::global::world; -struct Constructions::Private -{ - vector * p_cons; - Process * owner; - bool Inited; - bool Started; -}; - -Module* DFHack::createConstructions() +bool Constructions::isValid() { - return new Constructions(); + return (world->constructions.size() > 0); } -Constructions::Constructions() +uint32_t Constructions::getCount() { - Core & c = Core::getInstance(); - d = new Private; - d->owner = c.p; - d->Inited = d->Started = false; - VersionInfo * mem = c.vinfo; - d->p_cons = (decltype(d->p_cons)) mem->getGroup("Constructions")->getAddress ("vector"); - d->Inited = true; + return world->constructions.size(); } -Constructions::~Constructions() +df::construction *Constructions::getConstruction(const int32_t index) { - if(d->Started) - Finish(); - delete d; + if (index < 0 || index >= getCount()) + return NULL; + return world->constructions[index]; } - -bool Constructions::Start(uint32_t & numconstructions) -{ - numconstructions = d->p_cons->size(); - d->Started = true; - return true; -} - - -bool Constructions::Read (const uint32_t index, t_construction & construction) -{ - if(!d->Started) return false; - - t_construction * orig = d->p_cons->at(index); - construction = *orig; - construction.origin = orig; - return true; -} - -bool Constructions::Finish() -{ - d->Started = false; - return true; -} -