2011-07-25 02:14:58 -06:00
|
|
|
#include <iostream>
|
|
|
|
using namespace std;
|
|
|
|
|
2011-12-31 04:48:42 -07:00
|
|
|
#include "Core.h"
|
2012-01-15 13:54:14 -07:00
|
|
|
#include "Console.h"
|
|
|
|
#include "Export.h"
|
|
|
|
#include "PluginManager.h"
|
2011-07-25 02:14:58 -06:00
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
2012-01-15 13:54:14 -07:00
|
|
|
#include "modules/World.h"
|
2011-07-25 02:14:58 -06:00
|
|
|
#include <stdlib.h>
|
|
|
|
using namespace DFHack;
|
2012-06-16 04:42:56 -06:00
|
|
|
using namespace df::enums;
|
2011-07-25 02:14:58 -06:00
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
command_result mode (color_ostream &out, vector <string> & parameters);
|
2011-07-25 02:14:58 -06:00
|
|
|
|
2012-02-21 10:19:17 -07:00
|
|
|
DFHACK_PLUGIN("mode");
|
2011-07-25 02:14:58 -06:00
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands)
|
2011-07-25 02:14:58 -06:00
|
|
|
{
|
2012-01-28 05:03:56 -07:00
|
|
|
commands.push_back(PluginCommand(
|
2022-07-28 03:50:37 -06:00
|
|
|
"mode",
|
|
|
|
"View, change and track game mode.",
|
|
|
|
mode,
|
|
|
|
true));
|
2011-07-25 02:14:58 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
DFhackCExport command_result plugin_shutdown ( color_ostream &out )
|
2011-07-25 02:14:58 -06:00
|
|
|
{
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void printCurrentModes(t_gamemodes gm, Console & con)
|
|
|
|
{
|
|
|
|
con << "Current game type:\t" << gm.g_type << " (";
|
|
|
|
switch(gm.g_type)
|
|
|
|
{
|
2012-06-16 04:42:56 -06:00
|
|
|
case game_type::DWARF_MAIN:
|
2011-07-25 02:14:58 -06:00
|
|
|
con << "Fortress)" << endl;
|
|
|
|
break;
|
2012-06-16 04:42:56 -06:00
|
|
|
case game_type::ADVENTURE_MAIN:
|
2011-07-25 02:14:58 -06:00
|
|
|
con << "Adventurer)" << endl;
|
|
|
|
break;
|
2012-06-16 04:42:56 -06:00
|
|
|
case game_type::VIEW_LEGENDS:
|
2011-07-25 02:14:58 -06:00
|
|
|
con << "Legends)" << endl;
|
|
|
|
break;
|
2012-06-16 04:42:56 -06:00
|
|
|
case game_type::DWARF_RECLAIM:
|
2011-07-25 02:14:58 -06:00
|
|
|
con << "Reclaim)" << endl;
|
|
|
|
break;
|
2012-06-16 04:42:56 -06:00
|
|
|
case game_type::DWARF_ARENA:
|
2011-07-25 02:14:58 -06:00
|
|
|
con << "Arena)" << endl;
|
|
|
|
break;
|
2012-06-16 04:42:56 -06:00
|
|
|
case game_type::ADVENTURE_ARENA:
|
2011-07-25 02:14:58 -06:00
|
|
|
con << "Arena - control creature)" << endl;
|
|
|
|
break;
|
2012-06-16 04:42:56 -06:00
|
|
|
case game_type::num:
|
2011-07-25 02:14:58 -06:00
|
|
|
con << "INVALID)" << endl;
|
|
|
|
break;
|
2012-06-16 04:42:56 -06:00
|
|
|
case game_type::NONE:
|
2011-07-25 02:14:58 -06:00
|
|
|
con << "NONE)" << endl;
|
|
|
|
break;
|
2012-02-22 14:46:12 -07:00
|
|
|
default:
|
|
|
|
con << "!!UNKNOWN!!)" << endl;
|
|
|
|
break;
|
2011-07-25 02:14:58 -06:00
|
|
|
}
|
|
|
|
con << "Current game mode:\t" << gm.g_mode << " (";
|
|
|
|
switch (gm.g_mode)
|
|
|
|
{
|
2012-06-16 04:42:56 -06:00
|
|
|
case game_mode::DWARF:
|
2011-07-25 02:14:58 -06:00
|
|
|
con << "Dwarf)" << endl;
|
|
|
|
break;
|
2012-06-16 04:42:56 -06:00
|
|
|
case game_mode::ADVENTURE:
|
2011-07-25 02:14:58 -06:00
|
|
|
con << "Adventure)" << endl;
|
|
|
|
break;
|
2012-06-16 04:42:56 -06:00
|
|
|
case game_mode::num:
|
2011-07-25 02:14:58 -06:00
|
|
|
con << "INVALID)" << endl;
|
|
|
|
break;
|
2012-06-16 04:42:56 -06:00
|
|
|
case game_mode::NONE:
|
2011-07-25 02:14:58 -06:00
|
|
|
con << "NONE)" << endl;
|
|
|
|
break;
|
2012-02-22 14:46:12 -07:00
|
|
|
default:
|
|
|
|
con << "!!UNKNOWN!!)" << endl;
|
|
|
|
break;
|
2011-07-25 02:14:58 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
command_result mode (color_ostream &out_, vector <string> & parameters)
|
2011-07-25 02:14:58 -06:00
|
|
|
{
|
2012-03-29 12:18:14 -06:00
|
|
|
if(!out_.is_console())
|
|
|
|
return CR_FAILURE;
|
2012-03-10 04:55:42 -07:00
|
|
|
Console &out = static_cast<Console&>(out_);
|
|
|
|
|
2011-07-25 02:14:58 -06:00
|
|
|
string command = "";
|
|
|
|
bool set = false;
|
2012-02-22 14:46:12 -07:00
|
|
|
bool abuse = false;
|
2018-06-21 07:57:36 -06:00
|
|
|
int rv = 0;
|
2011-07-25 02:14:58 -06:00
|
|
|
t_gamemodes gm;
|
2012-02-22 14:46:12 -07:00
|
|
|
for(auto iter = parameters.begin(); iter != parameters.end(); iter++)
|
2011-07-25 02:14:58 -06:00
|
|
|
{
|
2012-02-22 14:46:12 -07:00
|
|
|
if((*iter) == "set")
|
2011-07-25 02:14:58 -06:00
|
|
|
{
|
|
|
|
set = true;
|
|
|
|
}
|
2012-02-22 14:46:12 -07:00
|
|
|
else if((*iter) == "abuse")
|
|
|
|
{
|
|
|
|
set = abuse = true;
|
|
|
|
}
|
2011-07-25 02:14:58 -06:00
|
|
|
else
|
2012-01-28 05:03:56 -07:00
|
|
|
return CR_WRONG_USAGE;
|
2011-07-25 02:14:58 -06:00
|
|
|
}
|
2012-03-10 04:55:42 -07:00
|
|
|
|
|
|
|
{
|
|
|
|
CoreSuspender suspend;
|
2012-10-06 03:46:20 -06:00
|
|
|
World::ReadGameMode(gm);
|
2012-03-10 04:55:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
printCurrentModes(gm, out);
|
|
|
|
|
2011-07-25 02:14:58 -06:00
|
|
|
if(set)
|
|
|
|
{
|
2012-02-22 14:46:12 -07:00
|
|
|
if(!abuse)
|
2011-07-25 02:14:58 -06:00
|
|
|
{
|
2012-06-16 04:42:56 -06:00
|
|
|
if( gm.g_mode == game_mode::NONE || gm.g_type == game_type::VIEW_LEGENDS)
|
2012-02-22 14:46:12 -07:00
|
|
|
{
|
2012-03-10 04:55:42 -07:00
|
|
|
out.printerr("It is not safe to set modes in menus.\n");
|
2012-02-22 14:46:12 -07:00
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
2012-03-10 04:55:42 -07:00
|
|
|
out << "\nPossible choices:" << endl
|
2012-02-22 14:46:12 -07:00
|
|
|
<< "0 = Fortress Mode" << endl
|
|
|
|
<< "1 = Adventurer Mode" << endl
|
|
|
|
<< "2 = Arena Mode" << endl
|
|
|
|
<< "3 = Arena, controlling creature" << endl
|
|
|
|
<< "4 = Reclaim Fortress Mode" << endl
|
|
|
|
<< "c = cancel/do nothing" << endl;
|
|
|
|
uint32_t select=99;
|
2011-07-25 02:14:58 -06:00
|
|
|
|
2012-02-22 14:46:12 -07:00
|
|
|
string selected;
|
|
|
|
input_again:
|
|
|
|
CommandHistory hist;
|
2018-07-04 06:21:25 -06:00
|
|
|
while((rv = out.lineedit("Enter new mode: ",selected, hist))
|
|
|
|
== Console::RETRY);
|
|
|
|
if(rv <= Console::FAILURE || selected == "c")
|
|
|
|
return rv == Console::FAILURE ? CR_FAILURE : CR_OK;
|
2012-02-22 14:46:12 -07:00
|
|
|
const char * start = selected.c_str();
|
|
|
|
char * end = 0;
|
|
|
|
select = strtol(start, &end, 10);
|
|
|
|
if(!end || end==start || select > 4)
|
|
|
|
{
|
2012-03-10 04:55:42 -07:00
|
|
|
out.printerr("This is not a valid selection.\n");
|
2012-02-22 14:46:12 -07:00
|
|
|
goto input_again;
|
|
|
|
}
|
|
|
|
switch(select)
|
|
|
|
{
|
|
|
|
case 0:
|
2012-06-16 04:42:56 -06:00
|
|
|
gm.g_mode = game_mode::DWARF;
|
|
|
|
gm.g_type = game_type::DWARF_MAIN;
|
2012-02-22 14:46:12 -07:00
|
|
|
break;
|
|
|
|
case 1:
|
2012-06-16 04:42:56 -06:00
|
|
|
gm.g_mode = game_mode::ADVENTURE;
|
|
|
|
gm.g_type = game_type::ADVENTURE_MAIN;
|
2012-02-22 14:46:12 -07:00
|
|
|
break;
|
|
|
|
case 2:
|
2012-06-16 04:42:56 -06:00
|
|
|
gm.g_mode = game_mode::DWARF;
|
|
|
|
gm.g_type = game_type::DWARF_ARENA;
|
2012-02-22 14:46:12 -07:00
|
|
|
break;
|
|
|
|
case 3:
|
2012-06-16 04:42:56 -06:00
|
|
|
gm.g_mode = game_mode::ADVENTURE;
|
|
|
|
gm.g_type = game_type::ADVENTURE_ARENA;
|
2012-02-22 14:46:12 -07:00
|
|
|
break;
|
|
|
|
case 4:
|
2012-06-16 04:42:56 -06:00
|
|
|
gm.g_mode = game_mode::DWARF;
|
|
|
|
gm.g_type = game_type::DWARF_RECLAIM;
|
2012-02-22 14:46:12 -07:00
|
|
|
break;
|
|
|
|
}
|
2011-07-25 02:14:58 -06:00
|
|
|
}
|
2012-02-22 14:46:12 -07:00
|
|
|
else
|
2011-07-25 02:14:58 -06:00
|
|
|
{
|
2012-02-22 14:46:12 -07:00
|
|
|
CommandHistory hist;
|
|
|
|
string selected;
|
2018-07-04 06:21:25 -06:00
|
|
|
while ((rv = out.lineedit("Enter new game mode number (c for exit): ",selected, hist))
|
|
|
|
== Console::RETRY);
|
|
|
|
if(rv <= Console::FAILURE || selected == "c")
|
|
|
|
return rv == Console::FAILURE ? CR_FAILURE : CR_OK;
|
2012-02-22 14:46:12 -07:00
|
|
|
const char * start = selected.c_str();
|
|
|
|
gm.g_mode = (GameMode) strtol(start, 0, 10);
|
2018-07-04 06:21:25 -06:00
|
|
|
while((rv = out.lineedit("Enter new game type number (c for exit): ",selected, hist))
|
|
|
|
== Console::RETRY);
|
|
|
|
if(rv <= Console::FAILURE || selected == "c")
|
|
|
|
return rv == Console::FAILURE ? CR_FAILURE : CR_OK;
|
2012-02-22 14:46:12 -07:00
|
|
|
start = selected.c_str();
|
|
|
|
gm.g_type = (GameType) strtol(start, 0, 10);
|
2011-07-25 02:14:58 -06:00
|
|
|
}
|
2012-03-10 04:55:42 -07:00
|
|
|
|
|
|
|
{
|
|
|
|
CoreSuspender suspend;
|
2012-10-06 03:46:20 -06:00
|
|
|
World::WriteGameMode(gm);
|
2012-03-10 04:55:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
out << endl;
|
2011-07-25 02:14:58 -06:00
|
|
|
}
|
|
|
|
return CR_OK;
|
2012-01-15 13:54:14 -07:00
|
|
|
}
|