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

@ -9,6 +9,12 @@
namespace DFHack
{
enum WeatherType
{
CLEAR,
RAINING,
SNOWING
};
class DFContextShared;
class DFHACK_EXPORT World : public Module
{
@ -23,6 +29,8 @@ namespace DFHack
uint32_t ReadCurrentYear();
uint32_t ReadCurrentMonth();
uint32_t ReadCurrentDay();
uint8_t ReadCurrentWeather();
void SetCurrentWeather(uint8_t weather);
private:
struct Private;

@ -49,6 +49,7 @@ struct World::Private
bool Started;
uint32_t year_offset;
uint32_t tick_offset;
uint32_t weather_offset;
DFContextShared *d;
Process * owner;
};
@ -63,6 +64,7 @@ World::World(DFContextShared * _d)
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" );
d->weather_offset = OG_World->getAddress( "current_weather" );
d->Inited = d->Started = true;
}
@ -114,3 +116,16 @@ uint32_t World::ReadCurrentDay()
{
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);
}

@ -100,6 +100,28 @@ int World_ReadCurrentDay(DFHackObject* world, uint32_t* day)
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
}
#endif