From df90c6be2c049ff4dbebb4ea4d75ffd9fc48db0b Mon Sep 17 00:00:00 2001 From: simon Date: Wed, 12 May 2010 15:27:51 +0200 Subject: [PATCH] New world module, sporting right now date readings --- dfhack/APIPrivate.cpp | 5 +- dfhack/CMakeLists.txt | 1 + dfhack/DFHackAPI.cpp | 24 ++++++--- dfhack/include/DFHackAPI.h | 6 ++- dfhack/include/modules/World.h | 32 ++++++++++++ dfhack/modules/World.cpp | 94 ++++++++++++++++++++++++++++++++++ dfhack/private/APIPrivate.h | 6 ++- output/Memory.xml | 10 ++-- 8 files changed, 161 insertions(+), 17 deletions(-) create mode 100644 dfhack/include/modules/World.h create mode 100644 dfhack/modules/World.cpp diff --git a/dfhack/APIPrivate.cpp b/dfhack/APIPrivate.cpp index 95da0cf04..d4cb5d7fb 100644 --- a/dfhack/APIPrivate.cpp +++ b/dfhack/APIPrivate.cpp @@ -14,6 +14,7 @@ #include "modules/Translation.h" #include "modules/Vegetation.h" #include "modules/Gui.h" +#include "modules/World.h" #include "modules/Buildings.h" #include "modules/Constructions.h" @@ -26,12 +27,13 @@ APIPrivate::APIPrivate() maps = 0; position = 0; gui = 0; + world = 0; materials = 0; translation = 0; vegetation = 0; buildings = 0; constructions = 0; - items = 0; + items = 0; } APIPrivate::~APIPrivate() @@ -45,6 +47,7 @@ APIPrivate::~APIPrivate() if(vegetation) delete vegetation; if(buildings) delete buildings; if(constructions) delete constructions; + if(world) delete world; } bool APIPrivate::InitReadNames() diff --git a/dfhack/CMakeLists.txt b/dfhack/CMakeLists.txt index 54841700e..92d74b16d 100644 --- a/dfhack/CMakeLists.txt +++ b/dfhack/CMakeLists.txt @@ -36,6 +36,7 @@ depends/tinyxml/tinyxmlparser.cpp modules/Creatures.cpp modules/Gui.cpp +modules/World.cpp modules/Items.cpp modules/Maps.cpp modules/Materials.cpp diff --git a/dfhack/DFHackAPI.cpp b/dfhack/DFHackAPI.cpp index 9aea26544..d4d22f321 100644 --- a/dfhack/DFHackAPI.cpp +++ b/dfhack/DFHackAPI.cpp @@ -40,6 +40,7 @@ distribution. #include "modules/Items.h" #include "modules/Position.h" #include "modules/Gui.h" +#include "modules/World.h" #include "modules/Creatures.h" #include "modules/Translation.h" #include "modules/Vegetation.h" @@ -139,6 +140,11 @@ bool API::Detach() delete d->gui; d->gui = 0; } + if(d->world) + { + delete d->world; + d->world = 0; + } if(d->position) { delete d->position; @@ -149,15 +155,10 @@ bool API::Detach() delete d->materials; d->materials = 0; } - if(d->items) - { - delete d->items; - d->items = 0; - } - if(d->gui) + if(d->items) { - delete d->gui; - d->gui = 0; + delete d->items; + d->items = 0; } if(d->translation) { @@ -257,6 +258,13 @@ Gui * API::getGui() return d->gui; } +World * API::getWorld() +{ + if(!d->world) + d->world = new World(d); + return d->world; +} + Position * API::getPosition() { if(!d->position) diff --git a/dfhack/include/DFHackAPI.h b/dfhack/include/DFHackAPI.h index 188f295ca..9f5d30b80 100644 --- a/dfhack/include/DFHackAPI.h +++ b/dfhack/include/DFHackAPI.h @@ -47,12 +47,13 @@ namespace DFHack class Creatures; class Position; class Gui; + class World; class Materials; class Translation; class Vegetation; class Buildings; class Constructions; - class Items; + class Items; class DFHACK_EXPORT API { @@ -98,6 +99,9 @@ namespace DFHack // get the gui module Gui * getGui(); + + // get the world module + World * getWorld(); // get the position module Position * getPosition(); diff --git a/dfhack/include/modules/World.h b/dfhack/include/modules/World.h new file mode 100644 index 000000000..6c3c12a4a --- /dev/null +++ b/dfhack/include/modules/World.h @@ -0,0 +1,32 @@ +#ifndef CL_MOD_WORLD +#define CL_MOD_WORLD + +/* +* World: all kind of stuff related to the current world state +*/ +#include "Export.h" + +namespace DFHack +{ + class APIPrivate; + class DFHACK_EXPORT World + { + public: + + World(DFHack::APIPrivate * d); + ~World(); + bool Start(); + bool Finish(); + + uint32_t ReadCurrentTick(); + uint32_t ReadCurrentYear(); + uint32_t ReadCurrentMonth(); + uint32_t ReadCurrentDay(); + + private: + struct Private; + Private *d; + }; +} +#endif + diff --git a/dfhack/modules/World.cpp b/dfhack/modules/World.cpp new file mode 100644 index 000000000..fe997da2a --- /dev/null +++ b/dfhack/modules/World.cpp @@ -0,0 +1,94 @@ +/* +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. +*/ + +#include "DFCommonInternal.h" +#include "../private/APIPrivate.h" +#include "modules/World.h" +#include "DFProcess.h" +#include "DFMemInfo.h" +#include "DFTypes.h" + +using namespace DFHack; + +struct World::Private +{ + bool Inited; + bool Started; + uint32_t year_offset; + uint32_t tick_offset; + APIPrivate *d; + Process * owner; +}; + +World::World(APIPrivate * _d) +{ + + d = new Private; + d->d = _d; + d->owner = _d->p; + + memory_info * mem = d->d->offset_descriptor; + d->year_offset = mem->getAddress( "current_year" ); + d->tick_offset = mem->getAddress( "current_tick" ); + d->Inited = d->Started = true; +} + +World::~World() +{ + delete d; +} + +bool World::Start() +{ + return true; +} + +bool World::Finish() +{ + return true; +} + +uint32_t World::ReadCurrentYear() +{ + if(d->Inited) + return(d->owner->readDWord(d->year_offset)); + return 0; +} + +uint32_t World::ReadCurrentTick() +{ + if(d->Inited) + return(d->owner->readDWord(d->tick_offset)); + return 0; +} + +uint32_t World::ReadCurrentMonth() +{ + return this->ReadCurrentTick() / 1200 / 24; +} + +uint32_t World::ReadCurrentDay() +{ + return ((this->ReadCurrentTick() / 1200) % 24) + 1; +} diff --git a/dfhack/private/APIPrivate.h b/dfhack/private/APIPrivate.h index 259730d58..12e11aa0d 100644 --- a/dfhack/private/APIPrivate.h +++ b/dfhack/private/APIPrivate.h @@ -33,10 +33,11 @@ namespace DFHack { class Materials; class Gui; + class World; class Position; class Maps; class Creatures; - class Items; + class Items; class Translation; class Buildings; class ProcessEnumerator; @@ -71,8 +72,9 @@ namespace DFHack Maps * maps; Position * position; Gui * gui; + World * world; Materials * materials; - Items * items; + Items * items; Translation * translation; Vegetation * vegetation; Buildings * buildings; diff --git a/output/Memory.xml b/output/Memory.xml index a1f900505..b6d866ddf 100755 --- a/output/Memory.xml +++ b/output/Memory.xml @@ -1132,11 +1132,6 @@ map_data_1b60_offset 0x1B9c 0x1C 0x38 - Time - ==== -
0x0e47e08
-
0x0e79f00
- Creatures =========
0x0166ecc4
@@ -1541,6 +1536,11 @@ map_data_1b60_offset 0x1B9c 0x14 0x14 (in the vtable) + Time + ==== +
0x0e47e08
+
0x0e79f00
+ .-"""-. ' \