2010-05-12 07:27:51 -06:00
|
|
|
/*
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2010-05-16 02:25:50 -06:00
|
|
|
/*
|
|
|
|
FIXME: Japa said that he had to do this with the time stuff he got from here
|
|
|
|
Investigate.
|
|
|
|
|
|
|
|
currentYear = Wold->ReadCurrentYear();
|
|
|
|
currentTick = Wold->ReadCurrentTick();
|
|
|
|
currentMonth = (currentTick+9)/33600;
|
|
|
|
currentDay = ((currentTick+9)%33600)/1200;
|
|
|
|
currentHour = ((currentTick+9)-(((currentMonth*28)+currentDay)*1200))/50;
|
|
|
|
currentTickRel = (currentTick+9)-(((((currentMonth*28)+currentDay)*24)+currentHour)*50);
|
|
|
|
*/
|
|
|
|
|
2010-05-26 04:24:45 -06:00
|
|
|
#include "Internal.h"
|
|
|
|
#include "ContextShared.h"
|
2010-05-26 00:42:09 -06:00
|
|
|
#include "dfhack/modules/World.h"
|
2010-05-25 22:48:23 -06:00
|
|
|
#include "dfhack/DFProcess.h"
|
2010-08-20 06:10:05 -06:00
|
|
|
#include "dfhack/VersionInfo.h"
|
2010-05-25 22:48:23 -06:00
|
|
|
#include "dfhack/DFTypes.h"
|
2010-05-12 07:27:51 -06:00
|
|
|
|
|
|
|
using namespace DFHack;
|
|
|
|
|
|
|
|
struct World::Private
|
|
|
|
{
|
|
|
|
bool Inited;
|
|
|
|
bool Started;
|
|
|
|
uint32_t year_offset;
|
|
|
|
uint32_t tick_offset;
|
2010-05-26 04:24:45 -06:00
|
|
|
DFContextShared *d;
|
2010-05-12 07:27:51 -06:00
|
|
|
Process * owner;
|
|
|
|
};
|
|
|
|
|
2010-05-26 04:24:45 -06:00
|
|
|
World::World(DFContextShared * _d)
|
2010-05-12 07:27:51 -06:00
|
|
|
{
|
2010-08-20 06:10:05 -06:00
|
|
|
|
2010-05-12 07:27:51 -06:00
|
|
|
d = new Private;
|
|
|
|
d->d = _d;
|
|
|
|
d->owner = _d->p;
|
2010-08-20 06:10:05 -06:00
|
|
|
|
2010-08-29 16:08:17 -06:00
|
|
|
OffsetGroup * OG_World = d->d->offset_descriptor->getGroup("World");
|
|
|
|
d->year_offset = OG_World->getAddress( "current_year" );
|
|
|
|
d->tick_offset = OG_World->getAddress( "current_tick" );
|
2010-05-12 07:27:51 -06:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2010-08-20 06:10:05 -06:00
|
|
|
// FIX'D according to this:
|
2010-06-05 16:56:09 -06:00
|
|
|
/*
|
|
|
|
World::ReadCurrentMonth and World::ReadCurrentDay
|
|
|
|
« Sent to: peterix on: June 04, 2010, 04:44:30 »
|
|
|
|
« You have forwarded or responded to this message. »
|
|
|
|
ReplyQuoteRemove
|
|
|
|
Shouldn't these be /28 and %28 instead of 24? There're 28 days in a DF month.
|
|
|
|
Using 28 and doing the calculation on the value stored at the memory location
|
|
|
|
specified by memory.xml gets me the current month/date.
|
|
|
|
*/
|
2010-05-12 07:27:51 -06:00
|
|
|
uint32_t World::ReadCurrentMonth()
|
|
|
|
{
|
2010-06-05 16:56:09 -06:00
|
|
|
return this->ReadCurrentTick() / 1200 / 28;
|
2010-05-12 07:27:51 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t World::ReadCurrentDay()
|
|
|
|
{
|
2010-06-05 16:56:09 -06:00
|
|
|
return ((this->ReadCurrentTick() / 1200) % 28) + 1;
|
2010-05-12 07:27:51 -06:00
|
|
|
}
|