Merge pull request #575 from lethosor/game-type

Add gametype checks to World module
develop
Lethosor 2015-03-13 22:25:37 -04:00
commit 3639920a50
7 changed files with 62 additions and 8 deletions

@ -1647,6 +1647,25 @@ static const luaL_Reg dfhack_maps_funcs[] = {
{ NULL, NULL } { 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 *****/ /***** Burrows module *****/
static bool burrows_isAssignedBlockTile(df::burrow *burrow, df::map_block *block, int x, int y) static bool burrows_isAssignedBlockTile(df::burrow *burrow, df::map_block *block, int x, int y)
@ -2486,6 +2505,7 @@ void OpenDFHackApi(lua_State *state)
OpenModule(state, "units", dfhack_units_module, dfhack_units_funcs); OpenModule(state, "units", dfhack_units_module, dfhack_units_funcs);
OpenModule(state, "items", dfhack_items_module, dfhack_items_funcs); OpenModule(state, "items", dfhack_items_module, dfhack_items_funcs);
OpenModule(state, "maps", dfhack_maps_module, dfhack_maps_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, "burrows", dfhack_burrows_module, dfhack_burrows_funcs);
OpenModule(state, "buildings", dfhack_buildings_module, dfhack_buildings_funcs); OpenModule(state, "buildings", dfhack_buildings_module, dfhack_buildings_funcs);
OpenModule(state, "constructions", dfhack_constructions_module); OpenModule(state, "constructions", dfhack_constructions_module);

@ -157,6 +157,11 @@ namespace DFHack
DFHACK_EXPORT bool WriteGameMode(const t_gamemodes & wr); // this is very dangerous DFHACK_EXPORT bool WriteGameMode(const t_gamemodes & wr); // this is very dangerous
DFHACK_EXPORT std::string ReadWorldFolder(); 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. // Store data in fake historical figure names.
// This ensures that the values are stored in save games. // This ensures that the values are stored in save games.
DFHACK_EXPORT PersistentDataItem AddPersistentData(const std::string &key); DFHACK_EXPORT PersistentDataItem AddPersistentData(const std::string &key);

@ -152,6 +152,35 @@ string World::ReadWorldFolder()
return world->cur_savegame.save_dir; 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) static PersistentDataItem dataFromHFig(df::historical_figure *hfig)
{ {
return PersistentDataItem(hfig->id, hfig->name.first_name, &hfig->name.nickname, hfig->name.words); return PersistentDataItem(hfig->id, hfig->name.first_name, &hfig->name.nickname, hfig->name.words);

@ -10,6 +10,7 @@
#include "PluginManager.h" #include "PluginManager.h"
#include "modules/MapCache.h" #include "modules/MapCache.h"
#include "modules/Random.h" #include "modules/Random.h"
#include "modules/World.h"
#include "MiscUtils.h" #include "MiscUtils.h"
@ -1626,7 +1627,7 @@ command_result cmd_3dveins(color_ostream &con, std::vector<std::string> & parame
return CR_FAILURE; return CR_FAILURE;
} }
if (*gametype != game_type::DWARF_MAIN && *gametype != game_type::DWARF_RECLAIM) if (!World::isFortressMode())
{ {
con.printerr("Must be used in fortress mode!\n"); con.printerr("Must be used in fortress mode!\n");
return CR_FAILURE; return CR_FAILURE;

@ -11,6 +11,7 @@
#include "modules/Gui.h" #include "modules/Gui.h"
#include "modules/Items.h" #include "modules/Items.h"
#include "modules/Materials.h" #include "modules/Materials.h"
#include "modules/World.h"
#include "DataDefs.h" #include "DataDefs.h"
#include "df/game_type.h" #include "df/game_type.h"
@ -84,7 +85,7 @@ bool makeItem (df::reaction_product_itemst *prod, df::unit *unit, bool second_it
prod->produce(unit, &out_items, &in_reag, &in_items, 1, job_skill::NONE, prod->produce(unit, &out_items, &in_reag, &in_items, 1, job_skill::NONE,
df::historical_entity::find(unit->civ_id), df::historical_entity::find(unit->civ_id),
((*gametype == game_type::DWARF_MAIN) || (*gametype == game_type::DWARF_RECLAIM)) ? df::world_site::find(ui->site_id) : NULL); (World::isFortressMode()) ? df::world_site::find(ui->site_id) : NULL);
if (!out_items.size()) if (!out_items.size())
return false; return false;
// if we asked to make shoes and we got twice as many as we asked, then we're okay // if we asked to make shoes and we got twice as many as we asked, then we're okay
@ -348,7 +349,7 @@ command_result df_createitem (color_ostream &out, vector <string> & parameters)
df::unit *unit = Gui::getSelectedUnit(out, true); df::unit *unit = Gui::getSelectedUnit(out, true);
if (!unit) if (!unit)
{ {
if (*gametype == game_type::ADVENTURE_ARENA || *gametype == game_type::ADVENTURE_MAIN) if (*gametype == game_type::ADVENTURE_ARENA || World::isAdventureMode())
{ {
// Use the adventurer unit // Use the adventurer unit
unit = world->units.active[0]; unit = world->units.active[0];

@ -346,7 +346,7 @@ command_result revflood(color_ostream &out, vector<string> & params)
} }
t_gamemodes gm; t_gamemodes gm;
World::ReadGameMode(gm); World::ReadGameMode(gm);
if(gm.g_type != game_type::DWARF_MAIN && gm.g_mode != game_mode::DWARF ) if(!World::isFortressMode(gm.g_type) || gm.g_mode != game_mode::DWARF )
{ {
out.printerr("Only in proper dwarf mode.\n"); out.printerr("Only in proper dwarf mode.\n");
return CR_FAILURE; return CR_FAILURE;

@ -119,8 +119,7 @@ command_result df_seedwatch(color_ostream &out, vector<string>& parameters)
World::ReadGameMode(gm);// FIXME: check return value World::ReadGameMode(gm);// FIXME: check return value
// if game mode isn't fortress mode // if game mode isn't fortress mode
if(gm.g_mode != game_mode::DWARF || if(gm.g_mode != game_mode::DWARF || !World::isFortressMode(gm.g_type))
!(gm.g_type == game_type::DWARF_MAIN || gm.g_type == game_type::DWARF_RECLAIM))
{ {
// just print the help // just print the help
printHelp(out); printHelp(out);
@ -310,8 +309,7 @@ DFhackCExport command_result plugin_onupdate(color_ostream &out)
t_gamemodes gm; t_gamemodes gm;
World::ReadGameMode(gm);// FIXME: check return value World::ReadGameMode(gm);// FIXME: check return value
// if game mode isn't fortress mode // if game mode isn't fortress mode
if(gm.g_mode != game_mode::DWARF || if(gm.g_mode != game_mode::DWARF || !World::isFortressMode(gm.g_type))
!(gm.g_type == game_type::DWARF_MAIN || gm.g_type == game_type::DWARF_RECLAIM))
{ {
// stop running. // stop running.
running = false; running = false;