From afca7419dca1dd47ef7d202d9f0aed2247d48fae Mon Sep 17 00:00:00 2001 From: lethosor Date: Mon, 9 Mar 2015 20:08:21 -0400 Subject: [PATCH] Add gametype checks to World.cpp --- library/LuaApi.cpp | 20 ++++++++++++++++++++ library/include/modules/World.h | 5 +++++ library/modules/World.cpp | 29 +++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+) diff --git a/library/LuaApi.cpp b/library/LuaApi.cpp index 26e158368..43898954a 100644 --- a/library/LuaApi.cpp +++ b/library/LuaApi.cpp @@ -1646,6 +1646,25 @@ static const luaL_Reg dfhack_maps_funcs[] = { { NULL, NULL } }; +/****** World module ******/ + +static const LuaWrapper::FunctionReg dfhack_world_module[] = { + WRAPM(World, ReadPauseState), + WRAPM(World, SetPauseState), + WRAPM(World, ReadCurrentTick), + WRAPM(World, ReadCurrentYear), + WRAPM(World, ReadCurrentMonth), + WRAPM(World, ReadCurrentDay), + WRAPM(World, ReadCurrentWeather), + WRAPM(World, SetCurrentWeather), + WRAPM(World, ReadWorldFolder), + WRAPM(World, isFortressMode), + WRAPM(World, isAdventureMode), + WRAPM(World, isArena), + WRAPM(World, isLegends), + { NULL, NULL } +}; + /***** Burrows module *****/ static bool burrows_isAssignedBlockTile(df::burrow *burrow, df::map_block *block, int x, int y) @@ -2483,6 +2502,7 @@ void OpenDFHackApi(lua_State *state) OpenModule(state, "units", dfhack_units_module, dfhack_units_funcs); OpenModule(state, "items", dfhack_items_module, dfhack_items_funcs); OpenModule(state, "maps", dfhack_maps_module, dfhack_maps_funcs); + OpenModule(state, "world", dfhack_world_module); OpenModule(state, "burrows", dfhack_burrows_module, dfhack_burrows_funcs); OpenModule(state, "buildings", dfhack_buildings_module, dfhack_buildings_funcs); OpenModule(state, "constructions", dfhack_constructions_module); diff --git a/library/include/modules/World.h b/library/include/modules/World.h index f1fea52a1..67c4082df 100644 --- a/library/include/modules/World.h +++ b/library/include/modules/World.h @@ -157,6 +157,11 @@ namespace DFHack DFHACK_EXPORT bool WriteGameMode(const t_gamemodes & wr); // this is very dangerous DFHACK_EXPORT std::string ReadWorldFolder(); + DFHACK_EXPORT bool isFortressMode(df::game_type t = (df::game_type)-1); + DFHACK_EXPORT bool isAdventureMode(df::game_type t = (df::game_type)-1); + DFHACK_EXPORT bool isArena(df::game_type t = (df::game_type)-1); + DFHACK_EXPORT bool isLegends(df::game_type t = (df::game_type)-1); + // Store data in fake historical figure names. // This ensures that the values are stored in save games. DFHACK_EXPORT PersistentDataItem AddPersistentData(const std::string &key); diff --git a/library/modules/World.cpp b/library/modules/World.cpp index 0f54e68eb..66390da6e 100644 --- a/library/modules/World.cpp +++ b/library/modules/World.cpp @@ -152,6 +152,35 @@ string World::ReadWorldFolder() return world->cur_savegame.save_dir; } +bool World::isFortressMode(df::game_type t) +{ + if (t == -1 && df::global::gametype) + t = *df::global::gametype; + return (t == game_type::DWARF_MAIN || t == game_type::DWARF_RECLAIM || + t == game_type::DWARF_UNRETIRE); +} + +bool World::isAdventureMode(df::game_type t) +{ + if (t == -1 && df::global::gametype) + t = *df::global::gametype; + return (t == game_type::ADVENTURE_MAIN); +} + +bool World::isArena(df::game_type t) +{ + if (t == -1 && df::global::gametype) + t = *df::global::gametype; + return (t == game_type::DWARF_ARENA || t == game_type::ADVENTURE_ARENA); +} + +bool World::isLegends(df::game_type t) +{ + if (t == -1 && df::global::gametype) + t = *df::global::gametype; + return (t == game_type::VIEW_LEGENDS); +} + static PersistentDataItem dataFromHFig(df::historical_figure *hfig) { return PersistentDataItem(hfig->id, hfig->name.first_name, &hfig->name.nickname, hfig->name.words);