Game/Control mode improvements. Use dfposition to check them.

develop
Petr Mrázek 2011-03-01 22:18:26 +01:00
parent fa220531b7
commit 267bc1d446
4 changed files with 73 additions and 8 deletions

@ -908,6 +908,8 @@
<Address name="current_year" description="Current year" />
<Address name="current_weather" description="5x5 array of bytes for surrounding biomes. For each: 0=clear, 1=raining, 2=snowing." />
<Address name="game_mode" description="Current game mode" />
<Address name="control_mode" description="Current control mode" />
<Address name="control_mode_copy" description="Copy of the control mode in DF memory" />
</Group>
</Offsets>
</Base>
@ -2034,7 +2036,9 @@
<Address name="current_tick" value="0xe2e180" /> maybe
<Address name="current_year" value="0xf0d268" />
<Address name="current_weather" value="0x15027A0" />
<Address name="game_mode" value="0xb4a814" />
<Address name="control_mode" value="0xb4a814" />
<Address name="game_mode" value="0xb4a818" />
<Address name="control_mode_copy" value="0xe2e2a2" />
fortress = 0, adventure = 1, arena = 0, menu and legends = 3 0xb4a814
Game mode: 0xb4a818 . fortress = 0, adventure = 1, arena = 4
0xe2e2a2 seems to be a copy of the first one

@ -6,6 +6,7 @@
*/
#include "dfhack/DFExport.h"
#include "dfhack/DFModule.h"
#include <ostream>
namespace DFHack
{
@ -15,11 +16,27 @@ namespace DFHack
RAINING,
SNOWING
};
enum ControlMode
{
CM_Managing = 0,
CM_DirectControl = 1,
CM_Kittens = 2, // not sure yet, but I think it will involve kittens
CM_Menu = 3,
CM_MAX = 3
};
enum GameMode
{
GM_Fort = 0,
GM_Adventurer = 1,
GM_Kittens = 2, // not sure yet, but I think it will involve kittens
GM_Menu = 3,
GM_Arena = 4,
GM_MAX
};
struct t_gamemodes
{
ControlMode control_mode;
GameMode game_mode;
};
class DFContextShared;
class DFHACK_EXPORT World : public Module
@ -37,7 +54,8 @@ namespace DFHack
uint32_t ReadCurrentDay();
uint8_t ReadCurrentWeather();
void SetCurrentWeather(uint8_t weather);
int32_t ReadGameMode();
bool ReadGameMode(t_gamemodes& rd);
bool WriteGameMode(const t_gamemodes & wr); // this is very dangerous
private:
struct Private;
Private *d;

@ -54,6 +54,8 @@ struct World::Private
uint32_t tick_offset;
uint32_t weather_offset;
uint32_t gamemode_offset;
uint32_t controlmode_offset;
uint32_t controlmodecopy_offset;
DFContextShared *d;
Process * owner;
};
@ -83,6 +85,8 @@ World::World(DFContextShared * _d)
try
{
d->gamemode_offset = OG_World->getAddress( "game_mode" );
d->controlmode_offset = OG_World->getAddress( "control_mode" );
d->controlmodecopy_offset = OG_World->getAddress( "control_mode" );
d->StartedMode = true;
}
catch(Error::All &){};
@ -118,13 +122,27 @@ uint32_t World::ReadCurrentTick()
return 0;
}
int32_t World::ReadGameMode()
bool World::ReadGameMode(t_gamemodes& rd)
{
if(d->Inited && d->StartedMode)
return d->owner->readDWord(d->gamemode_offset);
return -1;
{
rd.control_mode = (ControlMode) d->owner->readDWord( d->controlmode_offset);
rd.game_mode = (GameMode) d->owner->readDWord(d->gamemode_offset);
return true;
}
return false;
}
bool World::WriteGameMode(const t_gamemodes & wr)
{
if(d->Inited && d->StartedMode)
{
d->owner->writeDWord(d->gamemode_offset,wr.game_mode);
d->owner->writeDWord(d->controlmode_offset,wr.control_mode);
d->owner->writeDWord(d->controlmodecopy_offset,wr.control_mode);
return true;
}
return false;
}
// FIX'D according to this:
/*

@ -8,6 +8,30 @@ using namespace std;
#include <DFHack.h>
std::ostream &operator<<(std::ostream &stream, DFHack::t_gamemodes funzies)
{
char * gm[]=
{
"Fort",
"Adventurer",
"Kittens!",
"Menus",
"Arena",
};
char * cm[]=
{
"Managing",
"Direct Control",
"Kittens!",
"Menus"
};
if(funzies.game_mode <= DFHack::GM_MAX && funzies.control_mode <= DFHack::CM_MAX)
stream << "Game mode: " << gm[funzies.game_mode] << ", Control mode: " << cm[funzies.control_mode];
else
stream << "Game mode is too funky: (" << funzies.game_mode << "," << funzies.control_mode << ")";
return stream;
}
int main (int argc, char** argv)
{
bool quiet = false;
@ -39,9 +63,10 @@ int main (int argc, char** argv)
#endif
return 1;
}
if(World)
DFHack::t_gamemodes gmm;
if(World->ReadGameMode(gmm))
{
cout << "Game mode " << World->ReadGameMode() << endl;
cout << gmm << endl;
}
if (Position)
{