Petr Mrázek 2011-03-03 17:51:27 +01:00
commit f307d2c4c3
4 changed files with 36 additions and 4 deletions

@ -43,7 +43,8 @@ DFHACK_EXPORT int World_ReadCurrentDay(DFHackObject* world, uint32_t* day);
DFHACK_EXPORT int World_ReadCurrentWeather(DFHackObject* world, uint8_t* weather); DFHACK_EXPORT int World_ReadCurrentWeather(DFHackObject* world, uint8_t* weather);
DFHACK_EXPORT int World_WriteCurrentWeather(DFHackObject* world, uint8_t weather); DFHACK_EXPORT int World_WriteCurrentWeather(DFHackObject* world, uint8_t weather);
DFHACK_EXPORT int World_ReadGameMode(DFHackObject* world); DFHACK_EXPORT int World_ReadGameMode(DFHackObject* world, t_gamemodes*);
DFHACK_EXPORT int World_WriteGameMode(DFHackObject* world, t_gamemodes);
#ifdef __cplusplus #ifdef __cplusplus
} }

@ -122,11 +122,27 @@ int World_WriteCurrentWeather(DFHackObject* world, uint8_t weather)
return -1; return -1;
} }
int World_ReadGameMode(DFHackObject* world) int World_ReadGameMode(DFHackObject* world, t_gamemodes* modes)
{ {
if(world != NULL) if(world != NULL)
{ {
return ((DFHack::World*)world)->ReadGameMode(); if(((DFHack::World*)world)->ReadGameMode(*modes))
return 1;
else
return 0;
}
return -1;
}
int World_WriteGameMode(DFHackObject* world, t_gamemodes modes)
{
if(world != NULL)
{
if(((DFHack::World*)world)->WriteGameMode(modes))
return 1;
else
return 0;
} }
return -1; return -1;

@ -415,3 +415,7 @@ def _alloc_empty_colormodifier_callback(ptr):
_empty_colormodifier_functype = CFUNCTYPE(c_int, ColorModifierPtr) _empty_colormodifier_functype = CFUNCTYPE(c_int, ColorModifierPtr)
libdfhack.alloc_empty_colormodifier_callback = _empty_colormodifier_functype(_alloc_empty_colormodifier_callback) libdfhack.alloc_empty_colormodifier_callback = _empty_colormodifier_functype(_alloc_empty_colormodifier_callback)
class GameModes(Structure):
_fields_ = [("control_mode", c_ubyte),
("game_mode", c_ubyte)]

@ -1,6 +1,9 @@
from ctypes import * from ctypes import *
from dftypes import GameModes
from util import _uintify, uint_ptr from util import _uintify, uint_ptr
libdfhack.World_ReadGameMode.argtypes = [ c_void_p, POINTER(GameModes) ]
class World(object): class World(object):
def __init__(self, ptr): def __init__(self, ptr):
self._world_ptr = ptr self._world_ptr = ptr
@ -55,4 +58,12 @@ class World(object):
return libdfhack.World_WriteCurrentWeather(self._world_ptr, c_ubyte(weather)) return libdfhack.World_WriteCurrentWeather(self._world_ptr, c_ubyte(weather))
def read_game_mode(self): def read_game_mode(self):
return int(libdfhack.World_ReadGameMode(self._world_ptr)) game_modes = GameModes()
if libdfhack.World_ReadGameMode(self._world_ptr, byref(game_modes)) > 0:
return game_modes
else:
return None
def write_game_mode(self, game_mode):
return libdfhack.World_WriteGameMode(self._world_ptr, game_modes) > 0