From f4be3ef4fe741db58d27267c07879e80de70ffa4 Mon Sep 17 00:00:00 2001 From: doomchild Date: Thu, 3 Mar 2011 10:18:00 -0600 Subject: [PATCH] updated to use t_gamemodes struct in Read/WriteGameMode calls --- library/include/dfhack-c/modules/World_C.h | 3 ++- library/modules/World_C.cpp | 20 ++++++++++++++++++-- library/python/pydfhack/dftypes.py | 4 ++++ library/python/pydfhack/world.py | 13 ++++++++++++- 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/library/include/dfhack-c/modules/World_C.h b/library/include/dfhack-c/modules/World_C.h index a16068d49..ab498b40d 100644 --- a/library/include/dfhack-c/modules/World_C.h +++ b/library/include/dfhack-c/modules/World_C.h @@ -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_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 } diff --git a/library/modules/World_C.cpp b/library/modules/World_C.cpp index aa92a0359..31400d070 100644 --- a/library/modules/World_C.cpp +++ b/library/modules/World_C.cpp @@ -122,11 +122,27 @@ int World_WriteCurrentWeather(DFHackObject* world, uint8_t weather) return -1; } -int World_ReadGameMode(DFHackObject* world) +int World_ReadGameMode(DFHackObject* world, t_gamemodes* modes) { 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; diff --git a/library/python/pydfhack/dftypes.py b/library/python/pydfhack/dftypes.py index 7eae67932..d7dddd96f 100644 --- a/library/python/pydfhack/dftypes.py +++ b/library/python/pydfhack/dftypes.py @@ -415,3 +415,7 @@ def _alloc_empty_colormodifier_callback(ptr): _empty_colormodifier_functype = CFUNCTYPE(c_int, ColorModifierPtr) libdfhack.alloc_empty_colormodifier_callback = _empty_colormodifier_functype(_alloc_empty_colormodifier_callback) + +class GameModes(Structure): + _fields_ = [("control_mode", c_ubyte), + ("game_mode", c_ubyte)] diff --git a/library/python/pydfhack/world.py b/library/python/pydfhack/world.py index 29e6fd15a..59ae314a8 100644 --- a/library/python/pydfhack/world.py +++ b/library/python/pydfhack/world.py @@ -1,6 +1,9 @@ from ctypes import * +from dftypes import GameModes from util import _uintify, uint_ptr +libdfhack.World_ReadGameMode.argtypes = [ c_void_p, POINTER(GameModes) ] + class World(object): def __init__(self, ptr): self._world_ptr = ptr @@ -55,4 +58,12 @@ class World(object): return libdfhack.World_WriteCurrentWeather(self._world_ptr, c_ubyte(weather)) def read_game_mode(self): - return int(libdfhack.World_ReadGameMode(self._world_ptr)) \ No newline at end of file + 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 \ No newline at end of file