-
Notifications
You must be signed in to change notification settings - Fork 483
/
Copy pathmode.cpp
196 lines (182 loc) · 5.63 KB
/
mode.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#include <iostream>
using namespace std;
#include "Console.h"
#include "Export.h"
#include "PluginManager.h"
#include <vector>
#include <string>
#include "modules/World.h"
#include <stdlib.h>
using namespace DFHack;
using namespace df::enums;
command_result mode (color_ostream &out, vector <string> & parameters);
DFHACK_PLUGIN("mode");
DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands)
{
commands.push_back(PluginCommand(
"mode",
"View, change and track game mode.",
mode,
true));
return CR_OK;
}
DFhackCExport command_result plugin_shutdown ( color_ostream &out )
{
return CR_OK;
}
void printCurrentModes(t_gamemodes gm, Console & con)
{
con << "Current game type:\t" << gm.g_type << " (";
switch(gm.g_type)
{
case game_type::DWARF_MAIN:
con << "Fortress)" << endl;
break;
case game_type::ADVENTURE_MAIN:
con << "Adventurer)" << endl;
break;
case game_type::VIEW_LEGENDS:
con << "Legends)" << endl;
break;
case game_type::DWARF_RECLAIM:
con << "Reclaim)" << endl;
break;
case game_type::DWARF_ARENA:
con << "Arena)" << endl;
break;
case game_type::ADVENTURE_ARENA:
con << "Arena - control creature)" << endl;
break;
case game_type::num:
con << "INVALID)" << endl;
break;
case game_type::NONE:
con << "NONE)" << endl;
break;
default:
con << "!!UNKNOWN!!)" << endl;
break;
}
con << "Current game mode:\t" << gm.g_mode << " (";
switch (gm.g_mode)
{
case game_mode::DWARF:
con << "Dwarf)" << endl;
break;
case game_mode::ADVENTURE:
con << "Adventure)" << endl;
break;
case game_mode::num:
con << "INVALID)" << endl;
break;
case game_mode::NONE:
con << "NONE)" << endl;
break;
default:
con << "!!UNKNOWN!!)" << endl;
break;
}
}
command_result mode (color_ostream &out_, vector <string> & parameters)
{
if(!out_.is_console())
return CR_FAILURE;
Console &out = static_cast<Console&>(out_);
string command = "";
bool set = false;
bool abuse = false;
int rv = 0;
t_gamemodes gm;
for(auto iter = parameters.begin(); iter != parameters.end(); iter++)
{
if((*iter) == "set")
{
set = true;
}
else if((*iter) == "abuse")
{
set = abuse = true;
}
else
return CR_WRONG_USAGE;
}
World::ReadGameMode(gm);
printCurrentModes(gm, out);
if(set)
{
if(!abuse)
{
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");
return CR_FAILURE;
}
out << "\nPossible choices:" << endl
<< "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;
string selected;
input_again:
CommandHistory hist;
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;
const char * start = selected.c_str();
char * end = 0;
select = strtol(start, &end, 10);
if(!end || end==start || select > 4)
{
out.printerr("This is not a valid selection.\n");
goto input_again;
}
switch(select)
{
case 0:
gm.g_mode = game_mode::DWARF;
gm.g_type = game_type::DWARF_MAIN;
break;
case 1:
gm.g_mode = game_mode::ADVENTURE;
gm.g_type = game_type::ADVENTURE_MAIN;
break;
case 2:
gm.g_mode = game_mode::DWARF;
gm.g_type = game_type::DWARF_ARENA;
break;
case 3:
gm.g_mode = game_mode::ADVENTURE;
gm.g_type = game_type::ADVENTURE_ARENA;
break;
case 4:
gm.g_mode = game_mode::DWARF;
gm.g_type = game_type::DWARF_RECLAIM;
break;
}
}
else
{
CommandHistory hist;
string selected;
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;
const char * start = selected.c_str();
gm.g_mode = (GameMode) strtol(start, 0, 10);
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;
start = selected.c_str();
gm.g_type = (GameType) strtol(start, 0, 10);
}
World::WriteGameMode(gm);
out << endl;
}
return CR_OK;
}