Sync to the change in gamemode/gametype globals.

develop
Alexander Gavrilov 2012-06-16 14:42:56 +04:00
parent dc5bef2cb8
commit db91850464
8 changed files with 54 additions and 71 deletions

@ -379,19 +379,19 @@ static command_result GetWorldInfo(color_ostream &stream,
if (!ui || !world || !Core::getInstance().isWorldLoaded()) if (!ui || !world || !Core::getInstance().isWorldLoaded())
return CR_NOT_FOUND; return CR_NOT_FOUND;
t_gamemodes mode; df::game_type gt = game_type::DWARF_MAIN;
if (!Core::getInstance().getWorld()->ReadGameMode(mode)) if (df::global::gametype)
mode.g_type = GAMETYPE_DWARF_MAIN; gt = *df::global::gametype;
out->set_save_dir(world->cur_savegame.save_dir); out->set_save_dir(world->cur_savegame.save_dir);
if (world->world_data->name.has_name) if (world->world_data->name.has_name)
describeName(out->mutable_world_name(), &world->world_data->name); describeName(out->mutable_world_name(), &world->world_data->name);
switch (mode.g_type) switch (gt)
{ {
case GAMETYPE_DWARF_MAIN: case game_type::DWARF_MAIN:
case GAMETYPE_DWARF_RECLAIM: case game_type::DWARF_RECLAIM:
out->set_mode(GetWorldInfoOut::MODE_DWARF); out->set_mode(GetWorldInfoOut::MODE_DWARF);
out->set_civ_id(ui->civ_id); out->set_civ_id(ui->civ_id);
out->set_site_id(ui->site_id); out->set_site_id(ui->site_id);
@ -399,7 +399,7 @@ static command_result GetWorldInfo(color_ostream &stream,
out->set_race_id(ui->race_id); out->set_race_id(ui->race_id);
break; break;
case GAMETYPE_ADVENTURE_MAIN: case game_type::ADVENTURE_MAIN:
out->set_mode(GetWorldInfoOut::MODE_ADVENTURE); out->set_mode(GetWorldInfoOut::MODE_ADVENTURE);
if (auto unit = vector_get(world->units.active, 0)) if (auto unit = vector_get(world->units.active, 0))
@ -423,7 +423,7 @@ static command_result GetWorldInfo(color_ostream &stream,
} }
break; break;
case GAMETYPE_VIEW_LEGENDS: case game_type::VIEW_LEGENDS:
out->set_mode(GetWorldInfoOut::MODE_LEGENDS); out->set_mode(GetWorldInfoOut::MODE_LEGENDS);
break; break;

@ -35,32 +35,15 @@ distribution.
#include "Module.h" #include "Module.h"
#include <ostream> #include <ostream>
#include "DataDefs.h"
namespace DFHack namespace DFHack
{ {
/** typedef df::game_mode GameMode;
* \ingroup grp_world typedef df::game_type GameType;
*/
enum GameMode #define GAMEMODE_ADVENTURE df::enums::game_mode::ADVENTURE
{
GAMEMODE_DWARF,
GAMEMODE_ADVENTURE,
GAMEMODENUM,
GAMEMODE_NONE
};
/**
* \ingroup grp_world
*/
enum GameType
{
GAMETYPE_DWARF_MAIN,
GAMETYPE_ADVENTURE_MAIN,
GAMETYPE_VIEW_LEGENDS,
GAMETYPE_DWARF_RECLAIM,
GAMETYPE_DWARF_ARENA,
GAMETYPE_ADVENTURE_ARENA,
GAMETYPENUM,
GAMETYPE_NONE
};
/** /**
* \ingroup grp_world * \ingroup grp_world
*/ */

@ -85,7 +85,7 @@ World::World()
if(df::global::current_weather) if(df::global::current_weather)
d->StartedWeather = true; d->StartedWeather = true;
if (df::global::game_mode && df::global::control_mode) if (df::global::gamemode && df::global::gametype)
d->StartedMode = true; d->StartedMode = true;
d->Inited = true; d->Inited = true;
@ -132,8 +132,8 @@ bool World::ReadGameMode(t_gamemodes& rd)
{ {
if(d->Inited && d->StartedMode) if(d->Inited && d->StartedMode)
{ {
rd.g_mode = (DFHack::GameMode)*df::global::control_mode; rd.g_mode = (DFHack::GameMode)*df::global::gamemode;
rd.g_type = (DFHack::GameType)*df::global::game_mode; rd.g_type = (DFHack::GameType)*df::global::gametype;
return true; return true;
} }
return false; return false;
@ -142,8 +142,8 @@ bool World::WriteGameMode(const t_gamemodes & wr)
{ {
if(d->Inited && d->StartedMode) if(d->Inited && d->StartedMode)
{ {
*df::global::control_mode = wr.g_mode; *df::global::gamemode = wr.g_mode;
*df::global::game_mode = wr.g_type; *df::global::gametype = wr.g_type;
return true; return true;
} }
return false; return false;

@ -1 +1 @@
Subproject commit c381884664c71adefbec44258a734def2c88dacc Subproject commit bc757db69514b54eb66d4d38e9cc1354d3761907

@ -101,8 +101,8 @@ DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_chan
switch (event) { switch (event) {
case SC_MAP_LOADED: case SC_MAP_LOADED:
deinit_map(out); deinit_map(out);
if (df::global::game_mode && if (df::global::gamemode &&
*df::global::game_mode == GAMEMODE_DWARF) *df::global::gamemode == game_mode::DWARF)
init_map(out); init_map(out);
break; break;
case SC_MAP_UNLOADED: case SC_MAP_UNLOADED:

@ -10,7 +10,7 @@ using namespace std;
#include "modules/World.h" #include "modules/World.h"
#include <stdlib.h> #include <stdlib.h>
using namespace DFHack; using namespace DFHack;
using namespace df::enums;
command_result mode (color_ostream &out, vector <string> & parameters); command_result mode (color_ostream &out, vector <string> & parameters);
@ -44,28 +44,28 @@ void printCurrentModes(t_gamemodes gm, Console & con)
con << "Current game type:\t" << gm.g_type << " ("; con << "Current game type:\t" << gm.g_type << " (";
switch(gm.g_type) switch(gm.g_type)
{ {
case GAMETYPE_DWARF_MAIN: case game_type::DWARF_MAIN:
con << "Fortress)" << endl; con << "Fortress)" << endl;
break; break;
case GAMETYPE_ADVENTURE_MAIN: case game_type::ADVENTURE_MAIN:
con << "Adventurer)" << endl; con << "Adventurer)" << endl;
break; break;
case GAMETYPE_VIEW_LEGENDS: case game_type::VIEW_LEGENDS:
con << "Legends)" << endl; con << "Legends)" << endl;
break; break;
case GAMETYPE_DWARF_RECLAIM: case game_type::DWARF_RECLAIM:
con << "Reclaim)" << endl; con << "Reclaim)" << endl;
break; break;
case GAMETYPE_DWARF_ARENA: case game_type::DWARF_ARENA:
con << "Arena)" << endl; con << "Arena)" << endl;
break; break;
case GAMETYPE_ADVENTURE_ARENA: case game_type::ADVENTURE_ARENA:
con << "Arena - control creature)" << endl; con << "Arena - control creature)" << endl;
break; break;
case GAMETYPENUM: case game_type::num:
con << "INVALID)" << endl; con << "INVALID)" << endl;
break; break;
case GAMETYPE_NONE: case game_type::NONE:
con << "NONE)" << endl; con << "NONE)" << endl;
break; break;
default: default:
@ -75,16 +75,16 @@ void printCurrentModes(t_gamemodes gm, Console & con)
con << "Current game mode:\t" << gm.g_mode << " ("; con << "Current game mode:\t" << gm.g_mode << " (";
switch (gm.g_mode) switch (gm.g_mode)
{ {
case GAMEMODE_DWARF: case game_mode::DWARF:
con << "Dwarf)" << endl; con << "Dwarf)" << endl;
break; break;
case GAMEMODE_ADVENTURE: case game_mode::ADVENTURE:
con << "Adventure)" << endl; con << "Adventure)" << endl;
break; break;
case GAMEMODENUM: case game_mode::num:
con << "INVALID)" << endl; con << "INVALID)" << endl;
break; break;
case GAMEMODE_NONE: case game_mode::NONE:
con << "NONE)" << endl; con << "NONE)" << endl;
break; break;
default: default:
@ -132,7 +132,7 @@ command_result mode (color_ostream &out_, vector <string> & parameters)
{ {
if(!abuse) if(!abuse)
{ {
if( gm.g_mode == GAMEMODE_NONE || gm.g_type == GAMETYPE_VIEW_LEGENDS) if( gm.g_mode == game_mode::NONE || gm.g_type == game_type::VIEW_LEGENDS)
{ {
out.printerr("It is not safe to set modes in menus.\n"); out.printerr("It is not safe to set modes in menus.\n");
return CR_FAILURE; return CR_FAILURE;
@ -163,24 +163,24 @@ command_result mode (color_ostream &out_, vector <string> & parameters)
switch(select) switch(select)
{ {
case 0: case 0:
gm.g_mode = GAMEMODE_DWARF; gm.g_mode = game_mode::DWARF;
gm.g_type = GAMETYPE_DWARF_MAIN; gm.g_type = game_type::DWARF_MAIN;
break; break;
case 1: case 1:
gm.g_mode = GAMEMODE_ADVENTURE; gm.g_mode = game_mode::ADVENTURE;
gm.g_type = GAMETYPE_ADVENTURE_MAIN; gm.g_type = game_type::ADVENTURE_MAIN;
break; break;
case 2: case 2:
gm.g_mode = GAMEMODE_DWARF; gm.g_mode = game_mode::DWARF;
gm.g_type = GAMETYPE_DWARF_ARENA; gm.g_type = game_type::DWARF_ARENA;
break; break;
case 3: case 3:
gm.g_mode = GAMEMODE_ADVENTURE; gm.g_mode = game_mode::ADVENTURE;
gm.g_type = GAMETYPE_ADVENTURE_ARENA; gm.g_type = game_type::ADVENTURE_ARENA;
break; break;
case 4: case 4:
gm.g_mode = GAMEMODE_DWARF; gm.g_mode = game_mode::DWARF;
gm.g_type = GAMETYPE_DWARF_RECLAIM; gm.g_type = game_type::DWARF_RECLAIM;
break; break;
} }
} }

@ -90,7 +90,7 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out )
World *World = Core::getInstance().getWorld(); World *World = Core::getInstance().getWorld();
t_gamemodes gm; t_gamemodes gm;
World->ReadGameMode(gm); World->ReadGameMode(gm);
if(gm.g_mode == GAMEMODE_DWARF) if(gm.g_mode == game_mode::DWARF)
{ {
// if the map is revealed and we're in fortress mode, force the game to pause. // if the map is revealed and we're in fortress mode, force the game to pause.
if(revealed == REVEALED) if(revealed == REVEALED)
@ -193,12 +193,12 @@ command_result reveal(color_ostream &out, vector<string> & params)
} }
t_gamemodes gm; t_gamemodes gm;
World->ReadGameMode(gm); World->ReadGameMode(gm);
if(gm.g_mode == GAMEMODE_ADVENTURE) if(gm.g_mode == game_mode::ADVENTURE)
{ {
revealAdventure(out); revealAdventure(out);
return CR_OK; return CR_OK;
} }
if(gm.g_mode != GAMEMODE_DWARF) if(gm.g_mode != game_mode::DWARF)
{ {
con.printerr("Only in fortress mode.\n"); con.printerr("Only in fortress mode.\n");
return CR_FAILURE; return CR_FAILURE;
@ -272,7 +272,7 @@ command_result unreveal(color_ostream &out, vector<string> & params)
} }
t_gamemodes gm; t_gamemodes gm;
World->ReadGameMode(gm); World->ReadGameMode(gm);
if(gm.g_mode != GAMEMODE_DWARF) if(gm.g_mode != game_mode::DWARF)
{ {
con.printerr("Only in fortress mode.\n"); con.printerr("Only in fortress mode.\n");
return CR_FAILURE; return CR_FAILURE;
@ -350,7 +350,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 != GAMETYPE_DWARF_MAIN && gm.g_mode != GAMEMODE_DWARF ) if(gm.g_type != game_type::DWARF_MAIN && 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;

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