From 56a409d9a470bfc13c02d8e4afa1a2d25c53df50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Wed, 6 Jul 2011 11:13:36 +0200 Subject: [PATCH] sync, some map data structures, commented out some dead code --- library/Core.cpp | 2 + library/include/dfhack/Module.h | 2 + library/include/dfhack/modules/Maps.h | 94 ++++++++++++++++++++++++++ library/include/dfhack/modules/World.h | 35 +++++----- library/modules/World.cpp | 8 +-- plugins/reveal.cpp | 6 +- 6 files changed, 122 insertions(+), 25 deletions(-) diff --git a/library/Core.cpp b/library/Core.cpp index 83c818db0..a52c91dec 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -189,10 +189,12 @@ void Core::Suspend() void Core::Resume() { + /* for(unsigned int i = 0 ; i < allModules.size(); i++) { allModules[i]->OnResume(); } + */ SDL_mutexV(AccessMutex); } diff --git a/library/include/dfhack/Module.h b/library/include/dfhack/Module.h index 170a68312..c583ab17c 100644 --- a/library/include/dfhack/Module.h +++ b/library/include/dfhack/Module.h @@ -40,6 +40,7 @@ namespace DFHack virtual ~Module(){}; virtual bool Start(){return true;};// default start... virtual bool Finish() = 0;// everything should have a Finish() + /* // should Context call Finish when Resume is called? virtual bool OnResume() { @@ -52,6 +53,7 @@ namespace DFHack { return false; }; + */ }; } #endif //MODULE_H_INCLUDED diff --git a/library/include/dfhack/modules/Maps.h b/library/include/dfhack/modules/Maps.h index 9ff20e0ea..74536b38e 100644 --- a/library/include/dfhack/modules/Maps.h +++ b/library/include/dfhack/modules/Maps.h @@ -33,6 +33,7 @@ distribution. #include "dfhack/Export.h" #include "dfhack/Module.h" #include "dfhack/modules/Vegetation.h" +#include /** * \defgroup grp_maps Maps module and its types @@ -518,6 +519,99 @@ namespace DFHack int32_t mystery; } mapblock40d; + // A raw DF block. + // one of the vector is the 'effects' vector. another should be item id/index vector + struct df_block + { + // FIXME: wrap the flag array! + unsigned char * flagarray; + unsigned long flagarray_slots; + // how to handle this virtual mess? + std::vector block_events; + // no idea what these are + long unk1; + long unk2; + long unk3; + // feature indexes + signed long local_feature; // local feature index, -1 = no local feature + signed long global_feature; // global feature index, -1 = no global feature + signed long mystery; // no idea. couldn't manage to catch its use in debugger. + // more mysterious numbers + long unk4; + long unk5; + long unk6; + std::vector items; // item related - probly item IDs + std::vector effects; + signed long unk7; // -1 most of the time, another index? + unsigned long unk8; // again, index? + std::vector plants; + unsigned short map_x; + unsigned short map_y; + unsigned short map_z; + unsigned short region_x; + unsigned short region_y; + unsigned short tiletype[16][16]; // weird 2-byte alignment here + t_designation designation[16][16]; + t_occupancy occupancy[16][16]; + // following is uncertain, but total length should be fixed. + unsigned char unk9[16][16]; + unsigned long pathfinding[16][16]; + unsigned short unk10[16][16]; + unsigned short unk11[16][16]; + unsigned short unk12[16][16]; + // end uncertain section + unsigned short temperature_1[16][16]; + unsigned short temperature_2[16][16]; + // no idea again. needs research... + unsigned short unk13[16][16]; + unsigned short unk14[16][16]; + unsigned char region_offset[9]; + }; + template + struct df_array + { + inline const T& operator[] (uint32_t index) + { + return array[index]; + }; + private: + T array[]; + }; + template + struct df_2darray + { + inline const df_array& operator[] (uint32_t index) + { + return array[index]; + }; + private: + df_array * array; + }; + template + struct df_3darray + { + inline const df_2darray& operator[] (uint32_t index) + { + return array[index]; + }; + private: + df_2darray * array; + }; + struct map_data + { + df_3darray map_data; + std::vector unk1; + void * unk2; + uint32_t x_size_blocks; + uint32_t y_size_blocks; + uint32_t z_size_blocks; + uint32_t x_size; + uint32_t y_size; + uint32_t z_size; + int32_t x_area_offset; + int32_t y_area_offset; + int32_t z_area_offset; + }; /** * The Maps module * \ingroup grp_modules diff --git a/library/include/dfhack/modules/World.h b/library/include/dfhack/modules/World.h index b33047662..d15a87d39 100644 --- a/library/include/dfhack/modules/World.h +++ b/library/include/dfhack/modules/World.h @@ -46,39 +46,38 @@ namespace DFHack RAINING, SNOWING }; + /** * \ingroup grp_world */ - enum ControlMode + enum GameMode { - 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 + GAMEMODE_DWARF, + GAMEMODE_ADVENTURE, + GAMEMODENUM, + GAMEMODE_NONE }; /** * \ingroup grp_world */ - enum GameMode + enum GameType { - GM_Fort = 0, - GM_Adventurer = 1, - GM_Legends = 2, - GM_Menu = 3, - GM_Arena = 4, - GM_Arena_Assumed = 5, - GM_Kittens = 6, - GM_Worldgen = 7, - GM_MAX = 7, + GAMETYPE_DWARF_MAIN, + GAMETYPE_ADVENTURE_MAIN, + GAMETYPE_VIEW_LEGENDS, + GAMETYPE_DWARF_RECLAIM, + GAMETYPE_DWARF_ARENA, + GAMETYPE_ADVENTURE_ARENA, + GAMETYPENUM, + GAMETYPE_NONE }; /** * \ingroup grp_world */ struct t_gamemodes { - ControlMode control_mode; - GameMode game_mode; + GameMode g_mode; + GameType g_type; }; class DFContextShared; /** diff --git a/library/modules/World.cpp b/library/modules/World.cpp index 55359b7c1..5c23440fc 100644 --- a/library/modules/World.cpp +++ b/library/modules/World.cpp @@ -153,8 +153,8 @@ bool World::ReadGameMode(t_gamemodes& rd) { if(d->Inited && d->StartedMode) { - rd.control_mode = (ControlMode) d->owner->readDWord( d->controlmode_offset); - rd.game_mode = (GameMode) d->owner->readDWord(d->gamemode_offset); + rd.g_mode = (GameMode) d->owner->readDWord( d->controlmode_offset); + rd.g_type = (GameType) d->owner->readDWord(d->gamemode_offset); return true; } return false; @@ -163,8 +163,8 @@ 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->gamemode_offset,wr.g_mode); + d->owner->writeDWord(d->controlmode_offset,wr.g_type); return true; } return false; diff --git a/plugins/reveal.cpp b/plugins/reveal.cpp index 20e58d146..71a2a3a10 100644 --- a/plugins/reveal.cpp +++ b/plugins/reveal.cpp @@ -50,7 +50,7 @@ DFhackCExport command_result plugin_onupdate ( Core * c ) DFHack::World *World =c->getWorld(); t_gamemodes gm; World->ReadGameMode(gm); - if(gm.game_mode == GM_Fort) + if(gm.g_mode == GAMEMODE_DWARF) { World->SetPauseState(true); } @@ -76,7 +76,7 @@ DFhackCExport command_result reveal(DFHack::Core * c, std::vector & DFHack::World *World =c->getWorld(); t_gamemodes gm; World->ReadGameMode(gm); - if(gm.game_mode != GM_Fort) + if(gm.g_mode != GAMEMODE_DWARF) { dfout << "Only in fortress mode." << std::endl; c->Resume(); @@ -141,7 +141,7 @@ DFhackCExport command_result unreveal(DFHack::Core * c, std::vector DFHack::World *World =c->getWorld(); t_gamemodes gm; World->ReadGameMode(gm); - if(gm.game_mode != GM_Fort) + if(gm.g_mode != GAMEMODE_DWARF) { dfout << "Only in fortress mode." << std::endl; c->Resume();