-
Notifications
You must be signed in to change notification settings - Fork 0
/
console_commands.c
326 lines (258 loc) · 7.71 KB
/
console_commands.c
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "engine.h"
#include "world.h"
#include "console.h"
#include "vector3.h"
#include "player.h"
#include "ff_math.h"
void command_ver(char** tokens)
{
printf_console("RT76800\nVersion %s\n", ENGINE_VERSION);
}
void command_intro(char** tokens)
{
printf_console("----------------------------------------\n");
printf_console("Foffonso's DoomClone Engine\n");
printf_console("Codename DN F3D\n");
printf_console("Copyright Affonso Amendola, 2019-2020\n");
printf_console("Version %s\n\n", ENGINE_VERSION);
printf_console("Be Excellent to Each Other\n");
printf_console("----------------------------------------\n");
}
void command_help(char** tokens)
{
int page;
sscanf(*tokens, "%d", &page);
if(page <= 1)
{
printf_console("----------------------------------------\n");
printf_console("Command List Page 1/3\n");
printf_console("help [page]:\n");
printf_console(" shows command list's specified page\n");
printf_console("ver: shows current game version\n");
printf_console("intro: shows console intro again\n");
printf_console("sector show [sector value]:\n");
printf_console(" shows the sector's vertexes info\n");
printf_console("noclip: enables no-clip mode\n");
printf_console("----------------------------------------\n");
}
else
if(page == 2)
{
printf_console("----------------------------------------\n");
printf_console("Command List Page 2/3\n");
printf_console("vertex list: \n");
printf_console(" list all vertexes in the current level\n");
printf_console("set tint [r] [g] [b]:\n");
printf_console(" sets the tint value of the player's \n");
printf_console(" sector to the [r] [g] [b] values \n");
printf_console(" specified, from 0 to 1\n");
printf_console("set health [value]: sets health to value\n");
printf_console("----------------------------------------\n");
}
else
if(page >= 3)
{
printf_console("----------------------------------------\n");
printf_console("Command List Page 3/3\n");
printf_console("set armor [value]: sets armor to value\n");
printf_console("edit: enables edit mode\n");
printf_console("save [filename]: \n");
printf_console(" saves current edited level as filename\n");
printf_console("load [filename]: \n");
printf_console(" loads level from filename\n");
printf_console("\n");
printf_console("----------------------------------------\n");
}
}
void console_print_vertex_at(int index)
{
Vertex vert = *(Vertex*)ff_get_at_list(&world.vertexes, index);
index %= world.vertexes.size;
printf_console("%d x = %.2f, y = %.2f\n", index, vert.value.x, vert.value.y);
}
void command_vertex(char** tokens)
{
int index;
sscanf(*tokens, "%d", &index);
console_print_vertex_at(index);
}
void command_remove_vertex(char** tokens)
{
int index;
sscanf(*tokens, "%d", &index);
level_destroy_vertex(ff_get_at_list(&world.vertexes, index));
scroll_console(1);
}
void command_vertex_list(char** tokens)
{
int index;
sscanf(*tokens, "%d", &index);
for(uint32_t i = 0; i < ff_min(world.vertexes.size, 12); i++)
{
console_print_vertex_at(index);
index++;
index %= world.vertexes.size;
}
if(world.vertexes.size == 0) printf_console("No vertexes, dude.\n");
}
void command_mode(char** tokens)
{
uint32_t mode;
sscanf(*tokens, "%d", &mode);
switch(mode)
{
case MODE_EDITOR:
{
printf_console("Changing to editor mode.\n");
engine_change_mode(mode);
}
break;
case MODE_GAME:
{
printf_console("Changing to game mode.\n");
engine_change_mode(mode);
}
break;
default:
{
printf_console("Unrecognized mode.\n");
}
break;
}
}
/*
void command_sector_show(char** tokens)
{
int sector_index;
sscanf(*tokens, "%d", §or_index);
if(sector_index >= 0 && sector_index < loaded_level.s_num)
{
printf_console("\nx y is_portal neighbor_sector_id");
for(int e = 0; e < (loaded_level.sectors+sector_index)->e_num; e++)
{
EDGE current_edge;
current_edge = *(((loaded_level.sectors+sector_index)->e+e));
sprintf(buffer, "\n%u %u %u %u", current_edge.v_start, current_edge.v_end, current_edge.is_portal, current_edge.neighbor_sector_id);
printf_console(buffer);
}
}
printf_console("\n");
}
void COMMAND_vertex_list(char** tokens)
{
for(int v = 0; v < loaded_level.v_num; v++)
{
sprintf(buffer, "\n%f %f", (loaded_level.vertexes + v)->x, (loaded_level.vertexes + v)->y);
printf_console(buffer);
}
}
void COMMAND_noclip(char** tokens)
{
player->noclip = !(player->noclip);
if(player->noclip == 1)
printf_console("\nFLY YOU FOOL");
if(player->noclip == 0)
printf_console("\nYOU ARE GROUNDED");
}
void COMMAND_set(char** tokens)
{
char* variable = tokens[0];
int value;
sscanf(tokens[1], "%d", &value);
if(strcmp(variable, "health") == 0)
{
printf_console("\nSetting health to %i", value);
player->health = value;
}
if(strcmp(variable, "armor") == 0)
{
printf_console("\nSetting armor to %i");
player->armor = value;
}
}
void COMMAND_set_tint(char** tokens)
{
float r;
float g;
float b;
sscanf(tokens[0], "%f", &r);
sscanf(tokens[1], "%f", &g);
sscanf(tokens[2], "%f", &b);
player->closest_sector->tint = GFX_Tint(r, g, b);
}
void COMMAND_save_level(char** tokens)
{
char* filename = *tokens;
printf_console("\nSaving...");
FILE * new_file;
new_file = fopen(filename, "w");
sprintf(buffer, "%i\n", loaded_level.v_num);
fputs(buffer, new_file);
sprintf(buffer, "%i\n\n", loaded_level.s_num);
fputs(buffer, new_file);
for(int v = 0; v < loaded_level.v_num; v++)
{
sprintf(buffer, "%f %f\n", loaded_level.vertexes[v].x, loaded_level.vertexes[v].y);
fputs(buffer, new_file);
}
fputs("\n", new_file);
for(int s = 0; s < loaded_level.s_num; s++)
{
SECTOR * current_sector;
current_sector = loaded_level.sectors + s;
sprintf(buffer, "%u\n", current_sector->e_num);
fputs(buffer, new_file);
sprintf(buffer, "%f %f\n", current_sector->floor_height, current_sector->ceiling_height);
fputs(buffer, new_file);
EDGE * current_edge;
for(int v = 0; v < current_sector->e_num; v++)
{
current_edge = current_sector->e + v;
sprintf(buffer, "%u ", current_edge->v_start);
fputs(buffer, new_file);
}
fputs("\n", new_file);
sprintf(buffer, "%f %f %f\n", current_sector->tint.r, current_sector->tint.g, current_sector->tint.b);
fputs(buffer, new_file);
for(int v = 0; v < current_sector->e_num; v++)
{
current_edge = current_sector->e + v;
sprintf(buffer, "%u %u %u %u %f %f\n", current_edge->text_param.id,
current_edge->text_param.parallax,
current_edge->text_param.u_offset,
current_edge->text_param.v_offset,
current_edge->text_param.u_scale,
current_edge->text_param.v_scale);
fputs(buffer, new_file);
}
sprintf(buffer, "%u %u %u %u %f %f\n", current_sector->text_param_ceil.id,
current_sector->text_param_ceil.parallax,
current_sector->text_param_ceil.u_offset,
current_sector->text_param_ceil.v_offset,
current_sector->text_param_ceil.u_scale,
current_sector->text_param_ceil.v_scale);
fputs(buffer, new_file);
sprintf(buffer, "%u %u %u %u %f %f\n", current_sector->text_param_floor.id,
current_sector->text_param_floor.parallax,
current_sector->text_param_floor.u_offset,
current_sector->text_param_floor.v_offset,
current_sector->text_param_floor.u_scale,
current_sector->text_param_floor.v_scale);
fputs(buffer, new_file);
fputs("\n", new_file);
}
fclose(new_file);
printf_console("\nSaved to %s", filename);
}
void COMMAND_load_level(char** tokens)
{
level_load(*tokens);
}
void COMMAND_edit()
{
engine.edit_mode = !engine.edit_mode;
player->noclip = !player->noclip;
}*/