Added support for reading and setting the weather.

Signed-off-by: Mike Stewart <thewonderiidot@gmail.com>
develop
thewonderidiot 2010-09-01 11:22:19 -04:00
parent b8fbc7f137
commit 988b1d8692
5 changed files with 61 additions and 9 deletions

@ -1032,6 +1032,7 @@
<Group name="World"> <Group name="World">
<Address name="current_tick" description="Current time of the year" /> <Address name="current_tick" description="Current time of the year" />
<Address name="current_year" description="Current year" /> <Address name="current_year" description="Current year" />
<Address name="current_weather" description="Single byte, 0=clear, 1=raining, 2=snowing" />
</Group> </Group>
</Offsets> </Offsets>
</Base> </Base>
@ -1595,6 +1596,9 @@
<Group name="Position"> <Group name="Position">
<Address name="screen_tiles_pointer" value="0x18313D0" /> <Address name="screen_tiles_pointer" value="0x18313D0" />
</Group> </Group>
<Group name="World">
<Address name="current_weather" value="0x14BCDEE" />
</Group>
</Offsets> </Offsets>
</Version> </Version>

@ -40,6 +40,9 @@ DFHACK_EXPORT int World_ReadCurrentYear(DFHackObject* world, uint32_t* year);
DFHACK_EXPORT int World_ReadCurrentMonth(DFHackObject* world, uint32_t* month); DFHACK_EXPORT int World_ReadCurrentMonth(DFHackObject* world, uint32_t* month);
DFHACK_EXPORT int World_ReadCurrentDay(DFHackObject* world, uint32_t* day); DFHACK_EXPORT int World_ReadCurrentDay(DFHackObject* world, uint32_t* day);
DFHACK_EXPORT int World_ReadCurrentWeather(DFHackObject* world, uint8_t* weather);
DFHACK_EXPORT int World_WriteCurrentWeather(DFHackObject* world, uint8_t weather);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

@ -9,21 +9,29 @@
namespace DFHack namespace DFHack
{ {
enum WeatherType
{
CLEAR,
RAINING,
SNOWING
};
class DFContextShared; class DFContextShared;
class DFHACK_EXPORT World : public Module class DFHACK_EXPORT World : public Module
{ {
public: public:
World(DFHack::DFContextShared * d); World(DFHack::DFContextShared * d);
~World(); ~World();
bool Start(); bool Start();
bool Finish(); bool Finish();
uint32_t ReadCurrentTick(); uint32_t ReadCurrentTick();
uint32_t ReadCurrentYear(); uint32_t ReadCurrentYear();
uint32_t ReadCurrentMonth(); uint32_t ReadCurrentMonth();
uint32_t ReadCurrentDay(); uint32_t ReadCurrentDay();
uint8_t ReadCurrentWeather();
void SetCurrentWeather(uint8_t weather);
private: private:
struct Private; struct Private;
Private *d; Private *d;

@ -49,6 +49,7 @@ struct World::Private
bool Started; bool Started;
uint32_t year_offset; uint32_t year_offset;
uint32_t tick_offset; uint32_t tick_offset;
uint32_t weather_offset;
DFContextShared *d; DFContextShared *d;
Process * owner; Process * owner;
}; };
@ -63,6 +64,7 @@ World::World(DFContextShared * _d)
OffsetGroup * OG_World = d->d->offset_descriptor->getGroup("World"); OffsetGroup * OG_World = d->d->offset_descriptor->getGroup("World");
d->year_offset = OG_World->getAddress( "current_year" ); d->year_offset = OG_World->getAddress( "current_year" );
d->tick_offset = OG_World->getAddress( "current_tick" ); d->tick_offset = OG_World->getAddress( "current_tick" );
d->weather_offset = OG_World->getAddress( "current_weather" );
d->Inited = d->Started = true; d->Inited = d->Started = true;
} }
@ -114,3 +116,16 @@ uint32_t World::ReadCurrentDay()
{ {
return ((this->ReadCurrentTick() / 1200) % 28) + 1; return ((this->ReadCurrentTick() / 1200) % 28) + 1;
} }
uint8_t World::ReadCurrentWeather()
{
if (d->Inited)
return(d->owner->readByte(d->weather_offset));
return 0;
}
void World::SetCurrentWeather(uint8_t weather)
{
if (d->Inited)
d->owner->writeByte(d->weather_offset,weather);
}

@ -39,7 +39,7 @@ int World_Start(DFHackObject* world)
else else
return 0; return 0;
} }
return -1; return -1;
} }
@ -52,7 +52,7 @@ int World_Finish(DFHackObject* world)
else else
return 0; return 0;
} }
return -1; return -1;
} }
@ -63,7 +63,7 @@ int World_ReadCurrentTick(DFHackObject* world, uint32_t* tick)
*tick = ((DFHack::World*)world)->ReadCurrentTick(); *tick = ((DFHack::World*)world)->ReadCurrentTick();
return 1; return 1;
} }
return -1; return -1;
} }
@ -74,7 +74,7 @@ int World_ReadCurrentYear(DFHackObject* world, uint32_t* year)
*year = ((DFHack::World*)world)->ReadCurrentYear(); *year = ((DFHack::World*)world)->ReadCurrentYear();
return 1; return 1;
} }
return -1; return -1;
} }
@ -85,7 +85,7 @@ int World_ReadCurrentMonth(DFHackObject* world, uint32_t* month)
*month = ((DFHack::World*)world)->ReadCurrentMonth(); *month = ((DFHack::World*)world)->ReadCurrentMonth();
return 1; return 1;
} }
return -1; return -1;
} }
@ -96,10 +96,32 @@ int World_ReadCurrentDay(DFHackObject* world, uint32_t* day)
*day = ((DFHack::World*)world)->ReadCurrentDay(); *day = ((DFHack::World*)world)->ReadCurrentDay();
return 1; return 1;
} }
return -1; return -1;
} }
int World_ReadCurrentWeather(DFHackObject* world, uint8_t* weather)
{
if(world != NULL)
{
*weather = ((DFHack::World*)world)->ReadCurrentWeather();
return 1;
}
return -1;
}
int World_WriteCurrentWeather(DFHackObject* world, uint8_t weather)
{
if (world != NULL)
{
((DFHack::World*)world)->SetCurrentWeather(weather);
return 1;
}
return -1;
}
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif