Debian Codegraph @

prboom2/src/m_cheat.c

raw
1 /* Emacs style mode select -*- C -*-
2 *-----------------------------------------------------------------------------
3 *
4 *
5 * PrBoom: a Doom port merged with LxDoom and LSDLDoom
6 * based on BOOM, a modified and improved DOOM engine
7 * Copyright (C) 1999 by
8 * id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman
9 * Copyright (C) 1999-2002 by
10 * Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze
11 * Copyright 2005, 2006 by
12 * Florian Schulze, Colin Phipps, Neil Stevens, Andrey Budko
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27 * 02111-1307, USA.
28 *
29 * DESCRIPTION:
30 * Cheat sequence checking.
31 *
32 *-----------------------------------------------------------------------------*/
33
34 #include "doomstat.h"
35 #include "am_map.h"
36 #include "g_game.h"
37 #include "r_data.h"
38 #include "p_inter.h"
39 #include "p_tick.h"
40 #include "m_cheat.h"
41 #include "s_sound.h"
42 #include "s_advsound.h"
43 #include "sounds.h"
44 #include "dstrings.h"
45 #include "r_main.h"
46 #include "p_map.h"
47 #include "d_deh.h" // Ty 03/27/98 - externalized strings
48 /* cph 2006/07/23 - needs direct access to thinkercap */
49 #include "p_tick.h"
50 #include "w_wad.h"
51 #include "p_setup.h"
52 #include "p_user.h"
53 #include "lprintf.h"
54
55 #include "heretic/def.h"
56 #include "heretic/sb_bar.h"
57
58 #include "dsda.h"
59 #include "dsda/configuration.h"
60 #include "dsda/excmd.h"
61 #include "dsda/exhud.h"
62 #include "dsda/features.h"
63 #include "dsda/input.h"
64 #include "dsda/map_format.h"
65 #include "dsda/mapinfo.h"
66 #include "dsda/messenger.h"
67 #include "dsda/settings.h"
68 #include "dsda/skill_info.h"
69
70 #define plyr (players+consoleplayer) /* the console player */
71
72 //-----------------------------------------------------------------------------
73 //
74 // CHEAT SEQUENCE PACKAGE
75 //
76 //-----------------------------------------------------------------------------
77
78 static void cheat_mus(char buf[3]);
79 static void cheat_choppers();
80 static void cheat_god();
81 static void cheat_fa();
82 static void cheat_k();
83 static void cheat_kfa();
84 static void cheat_noclip();
85 static void cheat_pw(int pw);
86 static void cheat_behold();
87 static void cheat_clev0();
88 static void cheat_clev(char buf[3]);
89 static void cheat_mypos();
90 static void cheat_rate();
91 static void cheat_comp0();
92 static void cheat_comp(char buf[3]);
93 static void cheat_skill0();
94 static void cheat_skill(char buf[1]);
95 static void cheat_friction();
96 static void cheat_pushers();
97 static void cheat_massacre();
98 static void cheat_ddt();
99 static void cheat_reveal_secret();
100 static void cheat_reveal_kill();
101 static void cheat_reveal_item();
102 static void cheat_hom();
103 static void cheat_fast();
104 static void cheat_tntkey();
105 static void cheat_tntkeyx();
106 static void cheat_tntkeyxx(int key);
107 static void cheat_tntweap();
108 static void cheat_tntweapx(char buf[3]);
109 static void cheat_tntammo();
110 static void cheat_tntammox(char buf[1]);
111 static void cheat_smart();
112 static void cheat_pitch();
113 static void cheat_megaarmour();
114 static void cheat_health();
115 static void cheat_notarget();
116 static void cheat_freeze();
117 static void cheat_fly();
118
119 // heretic
120 static void cheat_reset_health();
121 static void cheat_tome();
122 static void cheat_chicken();
123 static void cheat_artifact(char buf[3]);
124
125 // hexen
126 static void cheat_inventory();
127 static void cheat_puzzle();
128 static void cheat_class(char buf[2]);
129 static void cheat_init();
130 static void cheat_script(char buf[3]);
131
132 //-----------------------------------------------------------------------------
133 //
134 // List of cheat codes, functions, and special argument indicators.
135 //
136 // The first argument is the cheat code.
137 //
138 // The second argument is its DEH name, or NULL if it's not supported by -deh.
139 //
140 // The third argument is a combination of the bitmasks,
141 // which excludes the cheat during certain modes of play.
142 //
143 // The fourth argument is the handler function.
144 //
145 // The fifth argument is passed to the handler function if it's non-negative;
146 // if negative, then its negative indicates the number of extra characters
147 // expected after the cheat code, which are passed to the handler function
148 // via a pointer to a buffer (after folding any letters to lowercase).
149 //
150 //-----------------------------------------------------------------------------
151
152 cheatseq_t cheat[] = {
153 CHEAT("idmus", "Change music", cht_always, cheat_mus, -2, false),
154 CHEAT("idchoppers", "Chainsaw", not_demo, cheat_choppers, 0, false),
155 CHEAT("iddqd", "God mode", not_classic_demo, cheat_god, 0, false),
156 CHEAT("idkfa", "Ammo & Keys", not_demo, cheat_kfa, 0, false),
157 CHEAT("idfa", "Ammo", not_demo, cheat_fa, 0, false),
158 CHEAT("idspispopd", "No Clipping 1", not_classic_demo, cheat_noclip, 0, false),
159 CHEAT("idclip", "No Clipping 2", not_classic_demo, cheat_noclip, 0, false),
160 CHEAT("idbeholdh", "Invincibility", not_demo, cheat_health, 0, false),
161 CHEAT("idbeholdm", "Invincibility", not_demo, cheat_megaarmour, 0, false),
162 CHEAT("idbeholdv", "Invincibility", not_demo, cheat_pw, pw_invulnerability, false),
163 CHEAT("idbeholds", "Berserk", not_demo, cheat_pw, pw_strength, false),
164 CHEAT("idbeholdi", "Invisibility", not_demo, cheat_pw, pw_invisibility, false),
165 CHEAT("idbeholdr", "Radiation Suit", not_demo, cheat_pw, pw_ironfeet, false),
166 CHEAT("idbeholda", "Auto-map", cht_always, cheat_pw, pw_allmap, false),
167 CHEAT("idbeholdl", "Lite-Amp Goggles", cht_always, cheat_pw, pw_infrared, false),
168 CHEAT("idbehold", "BEHOLD menu", cht_always, cheat_behold, 0, false),
169 CHEAT("idclev", "Level Warp", not_demo | not_menu, cheat_clev, -2, false),
170 CHEAT("idclev", "Level Warp", not_demo | not_menu, cheat_clev0, 0, false),
171 CHEAT("idmypos", NULL, cht_always, cheat_mypos, 0, false),
172 CHEAT("idrate", "Frame rate", cht_always, cheat_rate, 0, false),
173 // phares
174 CHEAT("tntcomp", NULL, not_demo, cheat_comp, -2, false),
175 CHEAT("tntcomp", NULL, not_demo, cheat_comp0, 0, false),
176 CHEAT("skill", NULL, not_demo, cheat_skill, -1, false),
177 CHEAT("skill", NULL, not_demo, cheat_skill0, 0, false),
178 // jff 2/01/98 kill all monsters
179 CHEAT("tntem", NULL, not_demo, cheat_massacre, 0, false),
180 // killough 2/07/98: moved from am_map.c
181 CHEAT("iddt", "Map cheat", cht_always, cheat_ddt, 0, true),
182 CHEAT("iddst", NULL, cht_always, cheat_reveal_secret, 0, true),
183 CHEAT("iddkt", NULL, cht_always, cheat_reveal_kill, 0, true),
184 CHEAT("iddit", NULL, cht_always, cheat_reveal_item, 0, true),
185 // killough 2/07/98: HOM autodetector
186 CHEAT("tnthom", NULL, cht_always, cheat_hom, 0, false),
187 // killough 2/16/98: generalized key cheats
188 CHEAT("tntkey", NULL, not_demo, cheat_tntkey, 0, false),
189 CHEAT("tntkeyr", NULL, not_demo, cheat_tntkeyx, 0, false),
190 CHEAT("tntkeyy", NULL, not_demo, cheat_tntkeyx, 0, false),
191 CHEAT("tntkeyb", NULL, not_demo, cheat_tntkeyx, 0, false),
192 CHEAT("tntkeyrc", NULL, not_demo, cheat_tntkeyxx, it_redcard, false),
193 CHEAT("tntkeyyc", NULL, not_demo, cheat_tntkeyxx, it_yellowcard, false),
194 CHEAT("tntkeybc", NULL, not_demo, cheat_tntkeyxx, it_bluecard, false),
195 CHEAT("tntkeyrs", NULL, not_demo, cheat_tntkeyxx, it_redskull, false),
196 CHEAT("tntkeyys", NULL, not_demo, cheat_tntkeyxx, it_yellowskull, false),
197 // killough 2/16/98: end generalized keys
198 CHEAT("tntkeybs", NULL, not_demo, cheat_tntkeyxx, it_blueskull, false),
199 // Ty 04/11/98 - Added TNTKA
200 CHEAT("tntka", NULL, not_demo, cheat_k, 0, false),
201 // killough 2/16/98: generalized weapon cheats
202 CHEAT("tntweap", NULL, not_demo, cheat_tntweap, 0, false),
203 CHEAT("tntweap", NULL, not_demo, cheat_tntweapx, -1, false),
204 CHEAT("tntammo", NULL, not_demo, cheat_tntammo, 0, false),
205 // killough 2/16/98: end generalized weapons
206 CHEAT("tntammo", NULL, not_demo, cheat_tntammox, -1, false),
207 // killough 2/21/98: smart monster toggle
208 CHEAT("tntsmart", NULL, not_demo, cheat_smart, 0, false),
209 // killough 2/21/98: pitched sound toggle
210 CHEAT("tntpitch", NULL, cht_always, cheat_pitch, 0, false),
211 // killough 2/21/98: reduce RSI injury by adding simpler alias sequences:
212 // killough 2/21/98: same as tntammo
213 CHEAT("tntamo", NULL, not_demo, cheat_tntammo, 0, false),
214 // killough 2/21/98: same as tntammo
215 CHEAT("tntamo", NULL, not_demo, cheat_tntammox, -1, false),
216 // killough 3/6/98: -fast toggle
217 CHEAT("tntfast", NULL, not_demo, cheat_fast, 0, false),
218 // phares 3/10/98: toggle variable friction effects
219 CHEAT("tntice", NULL, not_demo, cheat_friction, 0, false),
220 // phares 3/10/98: toggle pushers
221 CHEAT("tntpush", NULL, not_demo, cheat_pushers, 0, false),
222
223 // [RH] Monsters don't target
224 CHEAT("notarget", NULL, not_demo, cheat_notarget, 0, false),
225 // fly mode is active
226 CHEAT("fly", NULL, not_demo, cheat_fly, 0, false),
227
228 // heretic
229 CHEAT("quicken", NULL, not_classic_demo, cheat_god, 0, false),
230 CHEAT("ponce", NULL, not_demo, cheat_reset_health, 0, false),
231 CHEAT("kitty", NULL, not_classic_demo, cheat_noclip, 0, false),
232 CHEAT("massacre", NULL, not_demo, cheat_massacre, 0, false),
233 CHEAT("rambo", NULL, not_demo, cheat_fa, 0, false),
234 CHEAT("skel", NULL, not_demo, cheat_k, 0, false),
235 CHEAT("gimme", NULL, not_demo, cheat_artifact, -2, false),
236 CHEAT("shazam", NULL, not_demo, cheat_tome, 0, false),
237 CHEAT("engage", NULL, not_demo | not_menu, cheat_clev, -2, false),
238 CHEAT("ravmap", NULL, cht_always, cheat_ddt, 0, true),
239 CHEAT("cockadoodledoo", NULL, not_demo, cheat_chicken, 0, false),
240
241 // hexen
242 CHEAT("satan", NULL, not_classic_demo, cheat_god, 0, false),
243 CHEAT("clubmed", NULL, not_demo, cheat_reset_health, 0, false),
244 CHEAT("butcher", NULL, not_demo, cheat_massacre, 0, false),
245 CHEAT("nra", NULL, not_demo, cheat_fa, 0, false),
246 CHEAT("indiana", NULL, not_demo, cheat_inventory, 0, false),
247 CHEAT("locksmith", NULL, not_demo, cheat_k, 0, false),
248 CHEAT("sherlock", NULL, not_demo, cheat_puzzle, 0, false),
249 CHEAT("casper", NULL, not_classic_demo, cheat_noclip, 0, false),
250 CHEAT("shadowcaster", NULL, not_demo, cheat_class, -1, false),
251 CHEAT("visit", NULL, not_demo | not_menu, cheat_clev, -2, false),
252 CHEAT("init", NULL, not_demo, cheat_init, 0, false),
253 CHEAT("puke", NULL, not_demo, cheat_script, -2, false),
254 CHEAT("mapsco", NULL, cht_always, cheat_ddt, 0, true),
255 CHEAT("deliverance", NULL, not_demo, cheat_chicken, 0, false),
256
257 // end-of-list marker
258 {NULL}
259 };
260
261 //-----------------------------------------------------------------------------
262
263 static void cheat_mus(char buf[3])
264 {
265 int musnum, muslump;
266 int epsd, map;
267 char *mapname;
268
269 //jff 3/20/98 note: this cheat allowed in netgame/demorecord
270
271 //jff 3/17/98 avoid musnum being negative and crashing
272 if (!isdigit(buf[0]) || !isdigit(buf[1]))
273 return;
274
275 if (gamemode == commercial)
276 {
277 epsd = 1; //jff was 0, but espd is 1-based
278 map = (buf[0] - '0') * 10 + buf[1] - '0';
279 }
280 else
281 {
282 epsd = buf[0] - '0';
283 map = buf[1] - '0';
284 }
285
286 idmusnum = -1;
287 dsda_MapMusic(&musnum, &muslump, epsd, map);
288 idmusnum = musnum; //jff 3/17/98 remember idmus number for restore
289
290 mapname = VANILLA_MAP_LUMP_NAME(epsd,map);
291
292 if (W_LumpNameExists(mapname))
293 {
294 doom_printf("%s: %s", s_STSTR_MUS, mapname);
295
296 if (muslump != -1)
297 {
298 S_ChangeMusInfoMusic(muslump, true);
299 }
300 else if (musnum != -1)
301 {
302 S_ChangeMusic(musnum, 1);
303 }
304 }
305 else
306 {
307 dsda_AddMessage(s_STSTR_NOMUS);
308 }
309 }
310
311 // 'choppers' invulnerability & chainsaw
312 static void cheat_choppers()
313 {
314 plyr->weaponowned[wp_chainsaw] = true;
315 plyr->powers[pw_invulnerability] = true;
316 dsda_AddMessage(s_STSTR_CHOPPERS);
317 }
318
319 void M_CheatGod(void)
320 {
321 // dead players are first respawned at the current position
322 if (plyr->playerstate == PST_DEAD)
323 {
324 signed int an;
325 mapthing_t mt = {0};
326
327 P_MapStart();
328 mt.x = plyr->mo->x;
329 mt.y = plyr->mo->y;
330 mt.angle = (plyr->mo->angle + ANG45/2)*(uint64_t)45/ANG45;
331 mt.type = consoleplayer + 1;
332 mt.options = 1; // arbitrary non-zero value
333 P_SpawnPlayer(consoleplayer, &mt);
334
335 // spawn a teleport fog
336 an = plyr->mo->angle >> ANGLETOFINESHIFT;
337 P_SpawnMobj(plyr->mo->x + 20*finecosine[an],
338 plyr->mo->y + 20*finesine[an],
339 plyr->mo->z + g_telefog_height,
340 g_mt_tfog);
341 S_StartMobjSound(plyr->mo, g_sfx_revive);
342 P_MapEnd();
343 }
344
345 plyr->cheats ^= CF_GODMODE;
346 if (plyr->cheats & CF_GODMODE)
347 {
348 if (plyr->mo)
349 plyr->mo->health = god_health; // Ty 03/09/98 - deh
350
351 plyr->health = god_health;
352 dsda_AddMessage(s_STSTR_DQDON);
353 }
354 else
355 dsda_AddMessage(s_STSTR_DQDOFF);
356
357 if (raven) SB_Start();
358 }
359
360 static void cheat_god()
361 { // 'dqd' cheat for toggleable god mode
362 if (demorecording)
363 {
364 dsda_QueueExCmdGod();
365 return;
366 }
367
368 M_CheatGod();
369 }
370
371 // CPhipps - new health and armour cheat codes
372 static void cheat_health()
373 {
374 if (!(plyr->cheats & CF_GODMODE)) {
375 if (plyr->mo)
376 plyr->mo->health = mega_health;
377 plyr->health = mega_health;
378 dsda_AddMessage(s_STSTR_BEHOLDX);
379 }
380 }
381
382 static void cheat_megaarmour()
383 {
384 plyr->armorpoints[ARMOR_ARMOR] = idfa_armor; // Ty 03/09/98 - deh
385 plyr->armortype = idfa_armor_class; // Ty 03/09/98 - deh
386 dsda_AddMessage(s_STSTR_BEHOLDX);
387 }
388
389 static void cheat_fa()
390 {
391 int i;
392
393 if (hexen)
394 {
395 for (i = 0; i < NUMARMOR; i++)
396 {
397 plyr->armorpoints[i] = pclass[plyr->pclass].armor_increment[i];
398 }
399 for (i = 0; i < HEXEN_NUMWEAPONS; i++)
400 {
401 plyr->weaponowned[i] = true;
402 }
403 for (i = 0; i < NUMMANA; i++)
404 {
405 plyr->ammo[i] = MAX_MANA;
406 }
407 }
408 else
409 {
410 if (!plyr->backpack)
411 {
412 for (i=0 ; i<NUMAMMO ; i++)
413 plyr->maxammo[i] *= 2;
414 plyr->backpack = true;
415 }
416
417 plyr->armorpoints[ARMOR_ARMOR] = idfa_armor; // Ty 03/09/98 - deh
418 plyr->armortype = idfa_armor_class; // Ty 03/09/98 - deh
419
420 // You can't own weapons that aren't in the game // phares 02/27/98
421 for (i=0;i<NUMWEAPONS;i++)
422 if (!(((i == wp_plasma || i == wp_bfg) && gamemode == shareware) ||
423 (i == wp_supershotgun && gamemode != commercial)))
424 plyr->weaponowned[i] = true;
425
426 for (i=0;i<NUMAMMO;i++)
427 if (i!=am_cell || gamemode!=shareware)
428 plyr->ammo[i] = plyr->maxammo[i];
429
430 dsda_AddMessage(s_STSTR_FAADDED);
431 }
432 }
433
434 static void cheat_k()
435 {
436 int i;
437 for (i=0;i<NUMCARDS;i++)
438 if (!plyr->cards[i]) // only print message if at least one key added
439 { // however, caller may overwrite message anyway
440 plyr->cards[i] = true;
441 dsda_AddMessage("Keys Added");
442 }
443
444 // heretic - reset status bar
445 SB_Start();
446 }
447
448 static void cheat_kfa()
449 {
450 cheat_k();
451 cheat_fa();
452 dsda_AddMessage(s_STSTR_KFAADDED);
453 }
454
455 void M_CheatNoClip(void)
456 {
457 dsda_AddMessage((plyr->cheats ^= CF_NOCLIP) & CF_NOCLIP ? s_STSTR_NCON : s_STSTR_NCOFF);
458 }
459
460 static void cheat_noclip()
461 {
462 if (demorecording)
463 {
464 dsda_QueueExCmdNoClip();
465 return;
466 }
467
468 M_CheatNoClip();
469 }
470
471 // 'behold?' power-up cheats (modified for infinite duration -- killough)
472 static void cheat_pw(int pw)
473 {
474 if (pw == pw_allmap)
475 dsda_TrackFeature(uf_automap);
476
477 if (pw == pw_infrared)
478 dsda_TrackFeature(uf_liteamp);
479
480 if (plyr->powers[pw])
481 plyr->powers[pw] = pw!=pw_strength && pw!=pw_allmap; // killough
482 else
483 {
484 P_GivePower(plyr, pw);
485 if (pw != pw_strength)
486 plyr->powers[pw] = -1; // infinite duration -- killough
487 }
488 dsda_AddMessage(s_STSTR_BEHOLDX);
489 }
490
491 // 'behold' power-up menu
492 static void cheat_behold()
493 {
494 dsda_AddMessage(s_STSTR_BEHOLD);
495 }
496
497 // check 'clev' change-level cheat
498 static void cheat_clev0()
499 {
500 int epsd, map;
501 char *cur, *next;
502 cur = Z_Strdup(VANILLA_MAP_LUMP_NAME(gameepisode, gamemap));
503
504 dsda_NextMap(&epsd, &map);
505 next = VANILLA_MAP_LUMP_NAME(epsd, map);
506
507 if (W_LumpNameExists(next))
508 doom_printf("Current: %s, next: %s", cur, next);
509 else
510 doom_printf("Current: %s", cur);
511
512 Z_Free(cur);
513 }
514
515 // 'clev' change-level cheat
516 static void cheat_clev(char buf[3])
517 {
518 int epsd, map;
519
520 if (gamemode == commercial)
521 {
522 epsd = 1; //jff was 0, but espd is 1-based
523 map = (buf[0] - '0') * 10 + buf[1] - '0';
524 }
525 else
526 {
527 epsd = buf[0] - '0';
528 map = buf[1] - '0';
529 }
530
531 if (dsda_ResolveCLEV(&epsd, &map))
532 {
533 dsda_AddMessage(s_STSTR_CLEV);
534
535 G_DeferedInitNew(gameskill, epsd, map);
536 }
537 }
538
539 // 'mypos' for player position
540 static void cheat_mypos()
541 {
542 dsda_ToggleConfig(dsda_config_coordinate_display, false);
543 }
544
545 // cph - cheat to toggle frame rate/rendering stats display
546 static void cheat_rate()
547 {
548 dsda_ToggleRenderStats();
549 }
550
551 // check compatibility cheat
552 static void cheat_comp0()
553 {
554 if (raven)
555 return doom_printf("Cheat disabled for %s", heretic ? "Heretic" : "Hexen");
556
557 doom_printf("Complevel: %i - %s", compatibility_level, comp_lev_str[compatibility_level]);
558 }
559
560 // compatibility cheat
561 static void cheat_comp(char buf[3])
562 {
563 int compinput = (buf[0] - '0') * 10 + buf[1] - '0';
564
565 if (raven) return;
566
567 if (compinput < 0 ||
568 compinput >= MAX_COMPATIBILITY_LEVEL ||
569 (compinput > 17 && compinput < 21))
570 {
571 return; //doom_printf("Invalid complevel");
572 }
573 else
574 {
575 compatibility_level = compinput;
576 G_Compatibility(); // this is missing options checking
577 doom_printf("New Complevel: %i - %s", compatibility_level, comp_lev_str[compatibility_level]);
578 }
579 }
580
581 // Get skill strings
582 static const char* dsda_skill_str(void)
583 {
584 if (hexen)
585 {
586 if (PlayerClass[consoleplayer] == PCLASS_FIGHTER)
587 return hexen_skill_fighter[gameskill];
588 else if (PlayerClass[consoleplayer] == PCLASS_CLERIC)
589 return hexen_skill_cleric[gameskill];
590 else if (PlayerClass[consoleplayer] == PCLASS_MAGE)
591 return hexen_skill_mage[gameskill];
592 }
593
594 return skill_infos[gameskill].name;
595 }
596
597 // Check skill cheat
598 static void cheat_skill0()
599 {
600 if (!tc_game)
601 doom_printf("Skill: %i - %s", gameskill + 1, dsda_skill_str());
602 else
603 doom_printf("Skill: %i", gameskill + 1);
604 }
605
606 // Skill cheat
607 static void cheat_skill(char buf[1])
608 {
609 int skill = buf[0] - '0';
610
611 if (skill >= 1 && skill <= num_skills)
612 {
613 gameskill = skill - 1;
614
615 if (!tc_game)
616 doom_printf("Next Level Skill: %i - %s", gameskill + 1, dsda_skill_str());
617 else
618 doom_printf("Next Level Skill: %i", gameskill + 1);
619
620 dsda_UpdateGameSkill(gameskill);
621 }
622 }
623
624 // variable friction cheat
625 static void cheat_friction()
626 {
627 dsda_AddMessage((variable_friction = !variable_friction) ? "Variable Friction enabled" :
628 "Variable Friction disabled");
629 }
630
631
632 // Pusher cheat
633 // phares 3/10/98
634 static void cheat_pushers()
635 {
636 dsda_AddMessage((allow_pushers = !allow_pushers) ? "Pushers enabled" : "Pushers disabled");
637 }
638
639 static void cheat_massacre() // jff 2/01/98 kill all monsters
640 {
641 // jff 02/01/98 'em' cheat - kill all monsters
642 // partially taken from Chi's .46 port
643 //
644 // killough 2/7/98: cleaned up code and changed to use dprintf;
645 // fixed lost soul bug (LSs left behind when PEs are killed)
646
647 int killcount=0;
648 thinker_t *currentthinker = NULL;
649 extern void A_PainDie(mobj_t *);
650
651 // killough 7/20/98: kill friendly monsters only if no others to kill
652 uint64_t mask = MF_FRIEND;
653 P_MapStart();
654 do
655 while ((currentthinker = P_NextThinker(currentthinker,th_all)) != NULL)
656 if (currentthinker->function == P_MobjThinker &&
657 !(((mobj_t *) currentthinker)->flags & mask) && // killough 7/20/98
658 (((mobj_t *) currentthinker)->flags & MF_COUNTKILL ||
659 ((mobj_t *) currentthinker)->type == MT_SKULL))
660 { // killough 3/6/98: kill even if PE is dead
661 if (((mobj_t *) currentthinker)->health > 0)
662 {
663 killcount++;
664 P_DamageMobj((mobj_t *)currentthinker, NULL, NULL, 10000);
665 }
666 if (((mobj_t *) currentthinker)->type == MT_PAIN)
667 {
668 A_PainDie((mobj_t *) currentthinker); // killough 2/8/98
669 P_SetMobjState ((mobj_t *) currentthinker, S_PAIN_DIE6);
670 }
671 }
672 while (!killcount && mask ? mask=0, 1 : 0); // killough 7/20/98
673 P_MapEnd();
674 // killough 3/22/98: make more intelligent about plural
675 // Ty 03/27/98 - string(s) *not* externalized
676 doom_printf("%d Monster%s Killed", killcount, killcount==1 ? "" : "s");
677 }
678
679 void M_CheatIDDT(void)
680 {
681 extern int dsda_reveal_map;
682
683 dsda_TrackFeature(uf_iddt);
684
685 dsda_reveal_map = (dsda_reveal_map+1) % 3;
686 }
687
688 // killough 2/7/98: move iddt cheat from am_map.c to here
689 // killough 3/26/98: emulate Doom better
690 static void cheat_ddt()
691 {
692 if (automap_input)
693 M_CheatIDDT();
694 }
695
696 static void cheat_reveal_secret()
697 {
698 static int last_secret = -1;
699
700 if (automap_input)
701 {
702 int i, start_i;
703
704 dsda_TrackFeature(uf_iddt);
705
706 i = last_secret + 1;
707 if (i >= numsectors)
708 i = 0;
709 start_i = i;
710
711 do
712 {
713 sector_t *sec = &sectors[i];
714
715 if (P_IsSecret(sec))
716 {
717 dsda_UpdateIntConfig(dsda_config_automap_follow, false, true);
718
719 // This is probably not necessary
720 if (sec->lines && sec->lines[0] && sec->lines[0]->v1)
721 {
722 AM_SetMapCenter(sec->lines[0]->v1->x, sec->lines[0]->v1->y);
723 last_secret = i;
724 break;
725 }
726 }
727
728 i++;
729 if (i >= numsectors)
730 i = 0;
731 } while (i != start_i);
732 }
733 }
734
735 static void cheat_cycle_mobj(mobj_t **last_mobj, int *last_count, int flags, int alive)
736 {
737 extern int init_thinkers_count;
738 thinker_t *th, *start_th;
739
740 // If the thinkers have been wiped, addresses are invalid
741 if (*last_count != init_thinkers_count)
742 {
743 *last_count = init_thinkers_count;
744 *last_mobj = NULL;
745 }
746
747 if (*last_mobj)
748 th = &(*last_mobj)->thinker;
749 else
750 th = &thinkercap;
751
752 start_th = th;
753
754 do
755 {
756 th = th->next;
757 if (th->function == P_MobjThinker)
758 {
759 mobj_t *mobj;
760
761 mobj = (mobj_t *) th;
762
763 if ((!alive || mobj->health > 0) && mobj->flags & flags)
764 {
765 dsda_UpdateIntConfig(dsda_config_automap_follow, false, true);
766 AM_SetMapCenter(mobj->x, mobj->y);
767 P_SetTarget(last_mobj, mobj);
768 break;
769 }
770 }
771 } while (th != start_th);
772 }
773
774 static void cheat_reveal_kill()
775 {
776 if (automap_input)
777 {
778 static int last_count;
779 static mobj_t *last_mobj;
780
781 dsda_TrackFeature(uf_iddt);
782
783 cheat_cycle_mobj(&last_mobj, &last_count, MF_COUNTKILL, true);
784 }
785 }
786
787 static void cheat_reveal_item()
788 {
789 if (automap_input)
790 {
791 static int last_count;
792 static mobj_t *last_mobj;
793
794 dsda_TrackFeature(uf_iddt);
795
796 cheat_cycle_mobj(&last_mobj, &last_count, MF_COUNTITEM, false);
797 }
798 }
799
800 // killough 2/7/98: HOM autodetection
801 static void cheat_hom()
802 {
803 dsda_AddMessage(dsda_ToggleConfig(dsda_config_flashing_hom, true) ? "HOM Detection On"
804 : "HOM Detection Off");
805 }
806
807 // killough 3/6/98: -fast parameter toggle
808 static void cheat_fast()
809 {
810 dsda_AddMessage((fastparm = !fastparm) ? "Fast Monsters On" : "Fast Monsters Off");
811 dsda_RefreshGameSkill(); // refresh fast monsters
812 }
813
814 // killough 2/16/98: keycard/skullkey cheat functions
815 static void cheat_tntkey()
816 {
817 dsda_AddMessage("Red, Yellow, Blue");
818 }
819
820 static void cheat_tntkeyx()
821 {
822 dsda_AddMessage("Card, Skull");
823 }
824
825 static void cheat_tntkeyxx(int key)
826 {
827 dsda_AddMessage((plyr->cards[key] = !plyr->cards[key]) ? "Key Added" : "Key Removed");
828 }
829
830 // killough 2/16/98: generalized weapon cheats
831
832 static void cheat_tntweap()
833 {
834 dsda_AddMessage(gamemode == commercial ? "Weapon number 1-9" : "Weapon number 1-8");
835 }
836
837 static void cheat_tntweapx(char buf[3])
838 {
839 int w = *buf - '1';
840
841 if ((w==wp_supershotgun && gamemode!=commercial) || // killough 2/28/98
842 ((w==wp_bfg || w==wp_plasma) && gamemode==shareware))
843 return;
844
845 if (w==wp_fist) // make '1' apply beserker strength toggle
846 cheat_pw(pw_strength);
847 else
848 if (w >= 0 && w < NUMWEAPONS) {
849 if ((plyr->weaponowned[w] = !plyr->weaponowned[w]))
850 dsda_AddMessage("Weapon Added");
851 else
852 {
853 dsda_AddMessage("Weapon Removed");
854 if (w==plyr->readyweapon) // maybe switch if weapon removed
855 plyr->pendingweapon = P_SwitchWeapon(plyr);
856 }
857 }
858 }
859
860 // killough 2/16/98: generalized ammo cheats
861 static void cheat_tntammo()
862 {
863 dsda_AddMessage("Ammo 1-4, Backpack");
864 }
865
866 static void cheat_tntammox(char buf[1])
867 {
868 int a = *buf - '1';
869 if (*buf == 'b') // Ty 03/27/98 - strings *not* externalized
870 if ((plyr->backpack = !plyr->backpack))
871 {
872 dsda_AddMessage("Backpack Added");
873 for (a = 0; a < NUMAMMO; a++)
874 plyr->maxammo[a] <<= 1;
875 }
876 else
877 {
878 dsda_AddMessage("Backpack Removed");
879 for (a = 0; a < NUMAMMO; a++)
880 if (plyr->ammo[a] > (plyr->maxammo[a] >>= 1))
881 plyr->ammo[a] = plyr->maxammo[a];
882 }
883 else
884 if (a>=0 && a<NUMAMMO) // Ty 03/27/98 - *not* externalized
885 { // killough 5/5/98: switch plasma and rockets for now -- KLUDGE
886 a = a==am_cell ? am_misl : a==am_misl ? am_cell : a; // HACK
887 dsda_AddMessage((plyr->ammo[a] = !plyr->ammo[a]) ?
888 plyr->ammo[a] = plyr->maxammo[a], "Ammo Added" : "Ammo Removed");
889 }
890 }
891
892 static void cheat_smart()
893 {
894 dsda_AddMessage((monsters_remember = !monsters_remember) ?
895 "Smart Monsters Enabled" : "Smart Monsters Disabled");
896 }
897
898 static void cheat_pitch()
899 {
900 dsda_AddMessage(dsda_ToggleConfig(dsda_config_pitched_sounds, true) ? "Pitch Effects Enabled"
901 : "Pitch Effects Disabled");
902 }
903
904 static void cheat_notarget()
905 {
906 plyr->cheats ^= CF_NOTARGET;
907 if (plyr->cheats & CF_NOTARGET)
908 dsda_AddMessage("Notarget Mode ON");
909 else
910 dsda_AddMessage("Notarget Mode OFF");
911 }
912
913 static void cheat_freeze()
914 {
915 dsda_ToggleFrozenMode();
916 dsda_AddMessage(dsda_FrozenMode() ? "FREEZE ON" : "FREEZE OFF");
917 }
918
919 static void cheat_fly()
920 {
921 if (plyr->mo != NULL)
922 {
923 if (raven)
924 {
925 if (plyr->powers[pw_flight])
926 {
927 P_PlayerEndFlight(plyr);
928 plyr->powers[pw_flight] = 0;
929 dsda_AddMessage("Fly mode OFF");
930 }
931 else
932 {
933 P_GivePower(plyr, pw_flight);
934 plyr->powers[pw_flight] = INT_MAX;
935 dsda_AddMessage("Fly mode ON");
936 }
937 }
938 else
939 {
940 plyr->cheats ^= CF_FLY;
941 if (plyr->cheats & CF_FLY)
942 {
943 plyr->mo->flags |= MF_NOGRAVITY;
944 plyr->mo->flags |= MF_FLY;
945 dsda_AddMessage("Fly mode ON");
946 }
947 else
948 {
949 plyr->mo->flags &= ~MF_NOGRAVITY;
950 plyr->mo->flags &= ~MF_FLY;
951 dsda_AddMessage("Fly mode OFF");
952 }
953 }
954 }
955 }
956
957 static dboolean M_ClassicDemo(void)
958 {
959 return (demorecording || demoplayback) && !dsda_AllowCasualExCmdFeatures();
960 }
961
962 static dboolean M_CheatAllowed(int when)
963 {
964 return !dsda_StrictMode() &&
965 !(when & not_demo && (demorecording || demoplayback)) &&
966 !(when & not_classic_demo && M_ClassicDemo()) &&
967 !(when & not_menu && menuactive);
968 }
969
970 static void cht_InitCheats(void)
971 {
972 static int init = false;
973
974 if (!init)
975 {
976 cheatseq_t* cht;
977
978 init = true;
979
980 for (cht = cheat; cht->cheat; cht++)
981 {
982 cht->sequence_len = strlen(cht->cheat);
983 }
984 }
985 }
986
987 //
988 // CHEAT SEQUENCE PACKAGE
989 //
990
991 //
992 // Called in st_stuff module, which handles the input.
993 // Returns a 1 if the cheat was successful, 0 if failed.
994 //
995 static int M_FindCheats(int key)
996 {
997 int rc = 0;
998 cheatseq_t* cht;
999 char char_key;
1000
1001 cht_InitCheats();
1002
1003 char_key = (char)key;
1004
1005 for (cht = cheat; cht->cheat; cht++)
1006 {
1007 if (M_CheatAllowed(cht->when))
1008 {
1009 if (cht->chars_read < cht->sequence_len)
1010 {
1011 // still reading characters from the cheat code
1012 // and verifying. reset back to the beginning
1013 // if a key is wrong
1014
1015 if (char_key == cht->cheat[cht->chars_read])
1016 ++cht->chars_read;
1017 else if (char_key == cht->cheat[0])
1018 cht->chars_read = 1;
1019 else
1020 cht->chars_read = 0;
1021
1022 cht->param_chars_read = 0;
1023 }
1024 else if (cht->param_chars_read < -cht->arg)
1025 {
1026 // we have passed the end of the cheat sequence and are
1027 // entering parameters now
1028
1029 cht->parameter_buf[cht->param_chars_read] = char_key;
1030
1031 ++cht->param_chars_read;
1032
1033 // affirmative response
1034 rc = 1;
1035 }
1036
1037 if (cht->chars_read >= cht->sequence_len &&
1038 cht->param_chars_read >= -cht->arg)
1039 {
1040 if (cht->param_chars_read)
1041 {
1042 static char argbuf[CHEAT_ARGS_MAX + 1];
1043
1044 // process the arg buffer
1045 memcpy(argbuf, cht->parameter_buf, -cht->arg);
1046
1047 cht->func(argbuf);
1048 }
1049 else
1050 {
1051 // call cheat handler
1052 cht->func(cht->arg);
1053
1054 if (cht->repeatable)
1055 {
1056 --cht->chars_read;
1057 }
1058 }
1059
1060 if (!cht->repeatable)
1061 cht->chars_read = cht->param_chars_read = 0;
1062 rc = 1;
1063 }
1064 }
1065 }
1066
1067 return rc;
1068 }
1069
1070 typedef struct cheat_input_s {
1071 int input;
1072 const cheat_when_t when;
1073 void (*const func)();
1074 const int arg;
1075 } cheat_input_t;
1076
1077 static cheat_input_t cheat_input[] = {
1078 { dsda_input_iddqd, not_classic_demo, cheat_god, 0 },
1079 { dsda_input_idkfa, not_demo, cheat_kfa, 0 },
1080 { dsda_input_idfa, not_demo, cheat_fa, 0 },
1081 { dsda_input_idclip, not_classic_demo, cheat_noclip, 0 },
1082 { dsda_input_idbeholdh, not_demo, cheat_health, 0 },
1083 { dsda_input_idbeholdm, not_demo, cheat_megaarmour, 0 },
1084 { dsda_input_idbeholdv, not_demo, cheat_pw, pw_invulnerability },
1085 { dsda_input_idbeholds, not_demo, cheat_pw, pw_strength },
1086 { dsda_input_idbeholdi, not_demo, cheat_pw, pw_invisibility },
1087 { dsda_input_idbeholdr, not_demo, cheat_pw, pw_ironfeet },
1088 { dsda_input_idbeholda, cht_always, cheat_pw, pw_allmap },
1089 { dsda_input_idbeholdl, cht_always, cheat_pw, pw_infrared },
1090 { dsda_input_idmypos, cht_always, cheat_mypos, 0 },
1091 { dsda_input_idrate, cht_always, cheat_rate, 0 },
1092 { dsda_input_iddt, cht_always, cheat_ddt, 0 },
1093 { dsda_input_ponce, not_demo, cheat_reset_health, 0 },
1094 { dsda_input_shazam, not_demo, cheat_tome, 0 },
1095 { dsda_input_chicken, not_demo, cheat_chicken, 0 },
1096 { dsda_input_notarget, not_demo, cheat_notarget, 0 },
1097 { dsda_input_freeze, not_demo, cheat_freeze, 0 },
1098 { 0 }
1099 };
1100
1101 dboolean M_CheatResponder(event_t *ev)
1102 {
1103 cheat_input_t* cheat_i;
1104
1105 if (dsda_ProcessCheatCodes() &&
1106 ev->type == ev_keydown &&
1107 M_FindCheats(ev->data1.i))
1108 return true;
1109
1110 for (cheat_i = cheat_input; cheat_i->input; cheat_i++)
1111 {
1112 if (dsda_InputActivated(cheat_i->input))
1113 {
1114 if (M_CheatAllowed(cheat_i->when))
1115 cheat_i->func(cheat_i->arg);
1116
1117 return true;
1118 }
1119 }
1120
1121 if (M_CheatAllowed(not_demo) && dsda_InputActivated(dsda_input_avj))
1122 {
1123 plyr->mo->momz = 1000 * FRACUNIT / plyr->mo->info->mass;
1124
1125 return true;
1126 }
1127
1128 return false;
1129 }
1130
1131 dboolean M_CheatEntered(const char* element, const char* value)
1132 {
1133 cheatseq_t* cheat_i;
1134
1135 for (cheat_i = cheat; cheat_i->cheat; cheat_i++)
1136 {
1137 if (!strcmp(cheat_i->cheat, element) && M_CheatAllowed(cheat_i->when & ~not_menu))
1138 {
1139 if (cheat_i->arg >= 0)
1140 cheat_i->func(cheat_i->arg);
1141 else
1142 cheat_i->func(value);
1143 return true;
1144 }
1145 }
1146 return false;
1147 }
1148
1149 // heretic
1150
1151 #include "p_user.h"
1152
1153 static void cheat_reset_health(void)
1154 {
1155 if (heretic && plyr->chickenTics)
1156 {
1157 plyr->health = plyr->mo->health = MAXCHICKENHEALTH;
1158 }
1159 else if (hexen && plyr->morphTics)
1160 {
1161 plyr->health = plyr->mo->health = MAXMORPHHEALTH;
1162 }
1163 else
1164 {
1165 plyr->health = plyr->mo->health = MAXHEALTH;
1166 }
1167 dsda_AddMessage("FULL HEALTH");
1168 }
1169
1170 static void cheat_artifact(char buf[3])
1171 {
1172 int i;
1173 int j;
1174 int type;
1175 int count;
1176
1177 if (!heretic) return;
1178
1179 type = buf[0] - 'a' + 1;
1180 count = buf[1] - '0';
1181 if (type == 26 && count == 0)
1182 { // All artifacts
1183 for (i = arti_none + 1; i < NUMARTIFACTS; i++)
1184 {
1185 if (gamemode == shareware && (i == arti_superhealth || i == arti_teleport))
1186 {
1187 continue;
1188 }
1189 for (j = 0; j < 16; j++)
1190 {
1191 P_GiveArtifact(plyr, i, NULL);
1192 }
1193 }
1194 dsda_AddMessage("YOU GOT IT");
1195 }
1196 else if (type > arti_none && type < NUMARTIFACTS && count > 0 && count < 10)
1197 {
1198 if (gamemode == shareware && (type == arti_superhealth || type == arti_teleport))
1199 {
1200 dsda_AddMessage("BAD INPUT");
1201 return;
1202 }
1203 for (i = 0; i < count; i++)
1204 {
1205 P_GiveArtifact(plyr, type, NULL);
1206 }
1207 dsda_AddMessage("YOU GOT IT");
1208 }
1209 else
1210 {
1211 dsda_AddMessage("BAD INPUT");
1212 }
1213 }
1214
1215 static void cheat_tome(void)
1216 {
1217 if (!heretic) return;
1218
1219 if (plyr->powers[pw_weaponlevel2])
1220 {
1221 plyr->powers[pw_weaponlevel2] = 0;
1222 dsda_AddMessage("POWER OFF");
1223 }
1224 else
1225 {
1226 P_UseArtifact(plyr, arti_tomeofpower);
1227 dsda_AddMessage("POWER ON");
1228 }
1229 }
1230
1231 static void cheat_chicken(void)
1232 {
1233 if (!raven) return;
1234
1235 P_MapStart();
1236 if (heretic)
1237 {
1238 if (plyr->chickenTics)
1239 {
1240 if (P_UndoPlayerChicken(plyr))
1241 {
1242 dsda_AddMessage("CHICKEN OFF");
1243 }
1244 }
1245 else if (P_ChickenMorphPlayer(plyr))
1246 {
1247 dsda_AddMessage("CHICKEN ON");
1248 }
1249 }
1250 else
1251 {
1252 if (plyr->morphTics)
1253 {
1254 P_UndoPlayerMorph(plyr);
1255 }
1256 else
1257 {
1258 P_MorphPlayer(plyr);
1259 }
1260 dsda_AddMessage("SQUEAL!!");
1261 }
1262 P_MapEnd();
1263 }
1264
1265 // hexen
1266
1267 #include "hexen/p_acs.h"
1268
1269 static void cheat_init(void)
1270 {
1271 if (dsda_ResolveINIT())
1272 {
1273 P_SetMessage(plyr, "LEVEL WARP", true);
1274 }
1275 }
1276
1277 static void cheat_inventory(void)
1278 {
1279 int i, j;
1280 int start, end;
1281
1282 if (!raven) return;
1283
1284 if (heretic)
1285 {
1286 start = arti_none + 1;
1287 end = NUMARTIFACTS;
1288 }
1289 else
1290 {
1291 start = hexen_arti_none + 1;
1292 end = hexen_arti_firstpuzzitem;
1293 }
1294
1295 for (i = start; i < end; i++)
1296 {
1297 for (j = 0; j < g_arti_limit; j++)
1298 {
1299 P_GiveArtifact(plyr, i, NULL);
1300 }
1301 }
1302 P_SetMessage(plyr, "ALL ARTIFACTS", true);
1303 }
1304
1305 static void cheat_puzzle(void)
1306 {
1307 int i;
1308
1309 if (!hexen) return;
1310
1311 for (i = hexen_arti_firstpuzzitem; i < HEXEN_NUMARTIFACTS; i++)
1312 {
1313 P_GiveArtifact(plyr, i, NULL);
1314 }
1315 P_SetMessage(plyr, "ALL PUZZLE ITEMS", true);
1316 }
1317
1318 static void cheat_class(char buf[2])
1319 {
1320 int i;
1321 int new_class;
1322
1323 if (!hexen) return;
1324
1325 if (plyr->morphTics)
1326 { // don't change class if the player is morphed
1327 return;
1328 }
1329
1330 new_class = 1 + (buf[0] - '0');
1331 if (new_class > PCLASS_MAGE || new_class < PCLASS_FIGHTER)
1332 {
1333 P_SetMessage(plyr, "INVALID PLAYER CLASS", true);
1334 return;
1335 }
1336 plyr->pclass = new_class;
1337 for (i = 0; i < NUMARMOR; i++)
1338 {
1339 plyr->armorpoints[i] = 0;
1340 }
1341 PlayerClass[consoleplayer] = new_class;
1342 P_PostMorphWeapon(plyr, wp_first);
1343 SB_SetClassData();
1344 SB_Start();
1345 P_SetMessage(plyr, "CLASS CHANGED", true);
1346 }
1347
1348 static void cheat_script(char buf[3])
1349 {
1350 int script;
1351 byte script_args[3];
1352 int tens, ones;
1353 static char textBuffer[40];
1354
1355 if (!map_format.acs) return;
1356
1357 tens = buf[0] - '0';
1358 ones = buf[1] - '0';
1359 script = tens * 10 + ones;
1360 if (script < 1)
1361 return;
1362 if (script > 99)
1363 return;
1364 script_args[0] = script_args[1] = script_args[2] = 0;
1365
1366 if (P_StartACS(script, 0, script_args, plyr->mo, NULL, 0))
1367 {
1368 snprintf(textBuffer, sizeof(textBuffer), "RUNNING SCRIPT %.2d", script);
1369 P_SetMessage(plyr, textBuffer, true);
1370 }
1371 }