-
Notifications
You must be signed in to change notification settings - Fork 30
/
commands.hpp
333 lines (269 loc) · 9.09 KB
/
commands.hpp
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
command_result mapshot_cmd (color_ostream &out, std::vector <std::string> & parameters)
{
if (legacy_mode)
{
*out2 << COLOR_RED << "This command is not supported in legacy mode" << std::endl;
*out2 << COLOR_RESET;
return CR_FAILURE;
}
if (!enabled)
return CR_FAILURE;
// CoreSuspender suspend;
domapshot = 10;
return CR_OK;
}
command_result multilevel_cmd (color_ostream &out, std::vector <std::string> & parameters)
{
if (!enabled)
return CR_FAILURE;
// CoreSuspender suspend;
int pcnt = parameters.size();
if (pcnt >= 1)
{
std::string ¶m0 = parameters[0];
int newmaxlevels = maxlevels;
if (param0 == "shadowcolor" && pcnt >= 5)
{
float c[4];
bool ok = parse_float(parameters[1], c[0]) &&
parse_float(parameters[2], c[1]) &&
parse_float(parameters[3], c[2]) &&
parse_float(parameters[4], c[3]);
if (ok)
memcpy(shadowcolor, c, sizeof(shadowcolor));
else
return CR_WRONG_USAGE;
}
else if (param0 == "fogcolor" && pcnt >= 4)
{
float c[3];
bool ok = parse_float(parameters[1], c[0]) &&
parse_float(parameters[2], c[1]) &&
parse_float(parameters[3], c[2]);
if (ok)
memcpy(fogcolor, c, sizeof(fogcolor));
else
return CR_WRONG_USAGE;
}
else if (param0 == "fogdensity" && pcnt >= 2)
{
float val[3];
bool ok;
ok = parse_float(parameters[1], val[0]);
if (pcnt >= 3)
ok &= parse_float(parameters[2], val[1]);
if (pcnt >= 4)
ok &= parse_float(parameters[3], val[2]);
if (!ok)
return CR_WRONG_USAGE;
fogdensity = val[0];
if (pcnt >= 3)
fogstart = val[1];
else
fogstart = 0;
if (pcnt >= 4)
fogstep = val[2];
else
fogstep = 1;
((renderer_cool*)enabler->renderer)->needs_full_update = true;
}
else if (param0 == "more")
{
if (maxlevels < 15)
newmaxlevels = maxlevels + 1;
}
else if (param0 == "less")
{
if (maxlevels > 0)
newmaxlevels = maxlevels - 1;
}
else
{
int val;
if (parse_int(param0, val))
newmaxlevels = std::max (std::min(val, 15), 0);
else
return CR_WRONG_USAGE;
}
if (newmaxlevels && !maxlevels)
{
if (!legacy_mode)
patch_rendering(false);
((renderer_cool*)enabler->renderer)->needs_full_update = true;
}
else if (!newmaxlevels && maxlevels)
{
if (!legacy_mode)
patch_rendering(true);
multi_rendered = false;
((renderer_cool*)enabler->renderer)->needs_full_update = true;
}
maxlevels = newmaxlevels;
}
else
return CR_WRONG_USAGE;
return CR_OK;
}
command_result twbt_cmd (color_ostream &out, std::vector <std::string> & parameters)
{
if (!enabled)
return CR_FAILURE;
// CoreSuspender suspend;
int pcnt = parameters.size();
if (pcnt >= 1)
{
std::string ¶m0 = parameters[0];
if (param0 == "tilesize")
{
renderer_cool *r = (renderer_cool*) enabler->renderer;
std::string ¶m2 = parameters[1];
if (pcnt == 1)
{
*out2 << "Map tile size is " << r->gdispx << "x" << r->gdispy << std::endl;
return CR_OK;
}
if (parameters[1] == "bigger")
{
r->gdispx++;
r->gdispy++;
r->needs_reshape = true;
}
else if (parameters[1] == "smaller")
{
if (r->gdispx > 1 && r->gdispy > 1 && (r->gdimxfull < world->map.x_count || r->gdimyfull < world->map.y_count))
{
r->gdispx--;
r->gdispy--;
r->needs_reshape = true;
}
}
else if (parameters[1] == "reset")
{
r->gdispx = enabler->fullscreen ? small_map_dispx : large_map_dispx;
r->gdispy = enabler->fullscreen ? small_map_dispy : large_map_dispy;
r->needs_reshape = true;
}
else if (parameters[1][0] == '+' || parameters[1][0] == '-')
{
int delta;
if (!parse_int(parameters[1], delta))
return CR_WRONG_USAGE;
r->gdispx += delta;
r->gdispy += delta;
r->needs_reshape = true;
}
else if (pcnt >= 3)
{
int w, h;
bool ok = parse_int(parameters[1], w) &&
parse_int(parameters[2], h);
if (ok)
{
r->gdispx = w;
r->gdispy = h;
r->needs_reshape = true;
}
else
return CR_WRONG_USAGE;
}
else
return CR_WRONG_USAGE;
}
else if (param0 == "redraw_all")
{
int on;
if (!parse_int(parameters[1], on))
return CR_WRONG_USAGE;
always_full_update = (on > 0);
*out2 << "Forced redraw mode " << (always_full_update ? "enabled" : "disabled") << std::endl;
}
else if (param0 == "hide_stockpiles")
{
if (!always_full_update)
{
*out2 << COLOR_RED << "Hiding stockpiles requires \"twbt redraw_all 1\"" << std::endl;
*out2 << COLOR_RESET;
return CR_WRONG_USAGE;
}
int on;
if (!parse_int(parameters[1], on))
return CR_WRONG_USAGE;
hide_stockpiles = (on > 0);
if (hide_stockpiles)
*out2 << "Hiding stockpiles unless in [q], [p] or [k] mode" << std::endl;
else
*out2 << "Always showing stockpiles" << std::endl;
enable_building_hooks();
}
else if (param0 == "unit_transparency")
{
int on;
if (!parse_int(parameters[1], on))
return CR_WRONG_USAGE;
unit_transparency = (on > 0);
*out2 << "Unit transparency " << (unit_transparency ? "enabled" : "disabled") << std::endl;
enable_unit_hooks();
gps->force_full_display_count = 1;
((renderer_cool*)enabler->renderer)->needs_full_update = true;
}
else if (param0 == "workshop_transparency")
{
int on;
if (!parse_int(parameters[1], on))
return CR_WRONG_USAGE;
workshop_transparency = (on > 0);
*out2 << "Workshop transparency " << (workshop_transparency ? "enabled" : "disabled") << std::endl;
enable_building_hooks();
gps->force_full_display_count = 1;
((renderer_cool*)enabler->renderer)->needs_full_update = true;
}
}
return CR_OK;
}
command_result colormap_cmd (color_ostream &out, std::vector <std::string> & parameters)
{
if (!enabled)
return CR_FAILURE;
// CoreSuspender suspend;
int pcnt = parameters.size();
if (pcnt == 1)
{
std::string ¶m0 = parameters[0];
if (param0 == "reload")
{
load_colormap();
}
else
{
int cidx = color_name_to_index(param0);
if (cidx != -1)
out << param0 << " = " <<
roundf(enabler->ccolor[cidx][0] * 255) << " " <<
roundf(enabler->ccolor[cidx][1] * 255) << " " <<
roundf(enabler->ccolor[cidx][2] * 255) << std::endl;
}
gps->force_full_display_count = 1;
((renderer_cool*)enabler->renderer)->needs_full_update = true;
}
else if (pcnt == 4)
{
int cidx = color_name_to_index(parameters[0]);
if (cidx != -1)
{
float c[3];
bool ok = parse_float(parameters[1], c[0]) &&
parse_float(parameters[2], c[1]) &&
parse_float(parameters[3], c[2]);
if (ok)
{
c[0] /= 255.0f, c[1] /= 255.0f, c[2] /= 255.0f;
memcpy(enabler->ccolor[cidx], c, sizeof(enabler->ccolor[cidx]));
gps->force_full_display_count = 1;
((renderer_cool*)enabler->renderer)->needs_full_update = true;
}
else
return CR_WRONG_USAGE;
}
}
return CR_OK;
}