Debian Codegraph @

prboom2/src/g_game.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-2004 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: none
30 * The original Doom description was none, basically because this file
31 * has everything. This ties up the game logic, linking the menu and
32 * input code to the underlying game by creating & respawning players,
33 * building game tics, calling the underlying thing logic.
34 *
35 *-----------------------------------------------------------------------------
36 */
37
38 #include <stdio.h>
39 #include <stdarg.h>
40 #include <stdlib.h>
41 #ifdef _MSC_VER
42 #include <io.h>
43 #else
44 #include <unistd.h>
45 #endif
46
47 #ifdef HAVE_CONFIG_H
48 #include "config.h"
49 #endif
50
51 #include "doomstat.h"
52 #include "d_net.h"
53 #include "f_finale.h"
54 #include "i_video.h"
55 #include "m_file.h"
56 #include "m_misc.h"
57 #include "m_menu.h"
58 #include "m_cheat.h"
59 #include "m_random.h"
60 #include "p_setup.h"
61 #include "p_saveg.h"
62 #include "p_tick.h"
63 #include "p_map.h"
64 #include "d_main.h"
65 #include "wi_stuff.h"
66 #include "hu_stuff.h"
67 #include "st_stuff.h"
68 #include "am_map.h"
69 #include "w_wad.h"
70 #include "r_main.h"
71 #include "r_draw.h"
72 #include "p_map.h"
73 #include "s_sound.h"
74 #include "s_advsound.h"
75 #include "dstrings.h"
76 #include "sounds.h"
77 #include "r_data.h"
78 #include "r_sky.h"
79 #include "d_deh.h" // Ty 3/27/98 deh declarations
80 #include "p_inter.h"
81 #include "g_game.h"
82 #include "lprintf.h"
83 #include "i_main.h"
84 #include "i_system.h"
85 #include "smooth.h"
86 #include "r_fps.h"
87 #include "e6y.h"//e6y
88
89 #include "dsda.h"
90 #include "dsda/aim.h"
91 #include "dsda/args.h"
92 #include "dsda/brute_force.h"
93 #include "dsda/build.h"
94 #include "dsda/configuration.h"
95 #include "dsda/console.h"
96 #include "dsda/demo.h"
97 #include "dsda/excmd.h"
98 #include "dsda/exdemo.h"
99 #include "dsda/features.h"
100 #include "dsda/key_frame.h"
101 #include "dsda/mapinfo.h"
102 #include "dsda/messenger.h"
103 #include "dsda/save.h"
104 #include "dsda/settings.h"
105 #include "dsda/input.h"
106 #include "dsda/map_format.h"
107 #include "dsda/mapinfo.h"
108 #include "dsda/mouse.h"
109 #include "dsda/options.h"
110 #include "dsda/pause.h"
111 #include "dsda/playback.h"
112 #include "dsda/skill_info.h"
113 #include "dsda/skip.h"
114 #include "dsda/time.h"
115 #include "dsda/tracker.h"
116 #include "dsda/split_tracker.h"
117 #include "dsda/utility.h"
118
119 // Allows use of HELP2 screen for PWADs under DOOM 1
120 int pwad_help2_check;
121
122 struct
123 {
124 int type; // mobjtype_t
125 int speed[2];
126 } MonsterMissileInfo[] = {
127 { HERETIC_MT_IMPBALL, { 10, 20 } },
128 { HERETIC_MT_MUMMYFX1, { 9, 18 } },
129 { HERETIC_MT_KNIGHTAXE, { 9, 18 } },
130 { HERETIC_MT_REDAXE, { 9, 18 } },
131 { HERETIC_MT_BEASTBALL, { 12, 20 } },
132 { HERETIC_MT_WIZFX1, { 18, 24 } },
133 { HERETIC_MT_SNAKEPRO_A, { 14, 20 } },
134 { HERETIC_MT_SNAKEPRO_B, { 14, 20 } },
135 { HERETIC_MT_HEADFX1, { 13, 20 } },
136 { HERETIC_MT_HEADFX3, { 10, 18 } },
137 { HERETIC_MT_MNTRFX1, { 20, 26 } },
138 { HERETIC_MT_MNTRFX2, { 14, 20 } },
139 { HERETIC_MT_SRCRFX1, { 20, 28 } },
140 { HERETIC_MT_SOR2FX1, { 20, 28 } },
141 { -1, { -1, -1 } } // Terminator
142 };
143
144 // e6y
145 // It is signature for new savegame format with continuous numbering.
146 // Now it is not necessary to add a new level of compatibility in case
147 // of need to savegame format change from one minor version to another.
148 // The old format is still supported.
149 #define NEWFORMATSIG "\xff\xff\xff\xff"
150
151 static const byte *demobuffer; /* cph - only used for playback */
152 static int demolength; // check for overrun (missing DEMOMARKER)
153
154 gameaction_t gameaction;
155 gamestate_t gamestate;
156 dboolean in_game;
157 int gameskill;
158 int gameepisode;
159 int gamemap;
160 // CPhipps - moved *_loadgame vars here
161 static dboolean forced_loadgame = false;
162 static dboolean load_via_cmd = false;
163
164 dboolean timingdemo; // if true, exit with report on completion
165 dboolean fastdemo; // if true, run at full speed -- killough
166 dboolean nodrawers; // for comparative timing purposes
167 int starttime; // for comparative timing purposes
168 dboolean deathmatch; // only if started as net death
169 dboolean netgame; // only true if packets are broadcast
170 dboolean playeringame[MAX_MAXPLAYERS];
171 player_t players[MAX_MAXPLAYERS];
172 pclass_t PlayerClass[MAX_MAXPLAYERS];
173 int upmove;
174 int consoleplayer; // player taking events and displaying
175 int displayplayer; // view being displayed
176 int gametic;
177 int boom_basetic; /* killough 9/29/98: for demo sync */
178 int true_basetic;
179 int totalkills, totallive, totalitems, totalsecret; // for intermission
180 dboolean demorecording;
181 wbstartstruct_t wminfo; // parms for world map / intermission
182 dboolean haswolflevels = false;// jff 4/18/98 wolf levels present
183 int totalleveltimes; // CPhipps - total time for all completed levels
184 int levels_completed;
185 int longtics;
186
187 dboolean coop_spawns;
188
189 // e6y
190 // There is a new command-line switch "-shorttics".
191 // This makes it possible to practice routes and tricks
192 // (e.g. glides, where this makes a significant difference)
193 // with the same mouse behaviour as when recording,
194 // but without having to be recording every time.
195 int shorttics;
196
197 //
198 // controls (have defaults)
199 //
200
201 #define MAXPLMOVE (forwardmove[1])
202 #define SLOWTURNTICS 6
203 #define QUICKREVERSE (short)32768 // 180 degree reverse // phares
204
205 fixed_t forwardmove[2] = {0x19, 0x32};
206 fixed_t sidemove[2] = {0x18, 0x28};
207 fixed_t angleturn[3] = {640, 1280, 320}; // + slow turn
208 fixed_t flyspeed[2] = {1*256, 3*256};
209
210 static int turnheld; // for accelerative turning
211
212 // Set to -1 or +1 to switch to the previous or next weapon.
213
214 static int next_weapon = 0;
215
216 // Used for prev/next weapon keys.
217
218 static const struct
219 {
220 weapontype_t weapon;
221 weapontype_t weapon_num;
222 } weapon_order_table[] = {
223 { wp_fist, wp_fist },
224 { wp_chainsaw, wp_fist },
225 { wp_pistol, wp_pistol },
226 { wp_shotgun, wp_shotgun },
227 { wp_supershotgun, wp_shotgun },
228 { wp_chaingun, wp_chaingun },
229 { wp_missile, wp_missile },
230 { wp_plasma, wp_plasma },
231 { wp_bfg, wp_bfg }
232 };
233
234 // HERETIC_TODO: dynamically set these
235 // static const struct
236 // {
237 // weapontype_t weapon;
238 // weapontype_t weapon_num;
239 // } heretic_weapon_order_table[] = {
240 // { wp_staff, wp_staff },
241 // { wp_gauntlets, wp_staff },
242 // { wp_goldwand, wp_goldwand },
243 // { wp_crossbow, wp_crossbow },
244 // { wp_blaster, wp_blaster },
245 // { wp_skullrod, wp_skullrod },
246 // { wp_phoenixrod, wp_phoenixrod },
247 // { wp_mace, wp_mace },
248 // { wp_beak, wp_beak },
249 // };
250
251 // mouse values are used once
252 static int mousex;
253 static int mousey;
254 static int dclicktime;
255 static int dclickstate;
256 static int dclicks;
257 static int dclicktime2;
258 static int dclickstate2;
259 static int dclicks2;
260
261 static int left_analog_x;
262 static int left_analog_y;
263
264 // Game events info
265 static buttoncode_t special_event; // Event triggered by local player, to send
266 static int savegameslot; // Slot to load if gameaction == ga_loadgame
267 char savedescription[SAVEDESCLEN]; // Description to save in savegame if gameaction == ga_savegame
268
269 // heretic
270 #include "p_user.h"
271 #include "heretic/def.h"
272
273 int inventoryTics;
274 int lookheld;
275
276 static dboolean InventoryMoveLeft(void);
277 static dboolean InventoryMoveRight(void);
278 // end heretic
279
280 // hexen
281 #include "heretic/sb_bar.h"
282 #include "hexen/a_action.h"
283 #include "hexen/p_acs.h"
284 #include "hexen/sn_sonix.h"
285 #include "hexen/sv_save.h"
286
287 // Position indicator for cooperative net-play reborn
288 int RebornPosition;
289
290 leave_data_t leave_data;
291
292 void G_DoTeleportNewMap(void);
293 static void Hexen_G_DoReborn(int playernum);
294 // end hexen
295
296 typedef enum
297 {
298 carry_vertmouse,
299 carry_mousex,
300 carry_mousey,
301 NUMDOUBLECARRY
302 } double_carry_t;
303
304 static double double_carry[NUMDOUBLECARRY];
305
306 static int G_CarryDouble(double_carry_t c, double value)
307 {
308 int truncated_result;
309 double true_result;
310
311 true_result = double_carry[c] + value;
312 truncated_result = (int) true_result;
313 double_carry[c] = true_result - truncated_result;
314
315 return truncated_result;
316 }
317
318 static void G_DoSaveGame(dboolean via_cmd);
319
320 //
321 // G_BuildTiccmd
322 // Builds a ticcmd from all of the available inputs
323 // or reads it from the demo buffer.
324 // If recording a demo, write it out
325 //
326 static inline signed char fudgef(signed char b)
327 {
328 /*e6y
329 static int c;
330 if (!b || !demo_compatibility || longtics) return b;
331 if (++c & 0x1f) return b;
332 b |= 1; if (b>2) b-=2;*/
333 return b;
334 }
335
336 void G_SetSpeed(dboolean reset)
337 {
338 dsda_pclass_t *player_class;
339 static dsda_pclass_t *last_player_class = NULL;
340
341 player_class = &pclass[players[consoleplayer].pclass];
342
343 if (last_player_class == player_class && !reset)
344 return;
345
346 last_player_class = player_class;
347
348 forwardmove[0] = player_class->forwardmove[0];
349 forwardmove[1] = player_class->forwardmove[1];
350
351 if(dsda_AlwaysSR50())
352 {
353 sidemove[0] = player_class->forwardmove[0];
354 sidemove[1] = player_class->forwardmove[1];
355 }
356 else
357 {
358 sidemove[0] = player_class->sidemove[0];
359 sidemove[1] = player_class->sidemove[1];
360 }
361
362 {
363 int turbo_scale = dsda_TurboScale();
364
365 if (turbo_scale)
366 {
367 forwardmove[0] = player_class->forwardmove[0] * turbo_scale / 100;
368 forwardmove[1] = player_class->forwardmove[1] * turbo_scale / 100;
369 sidemove[0] = sidemove[0] * turbo_scale / 100;
370 sidemove[1] = sidemove[1] * turbo_scale / 100;
371
372 if (forwardmove[0] > 127)
373 forwardmove[0] = 127;
374
375 if (forwardmove[1] > 127)
376 forwardmove[1] = 127;
377
378 if (sidemove[0] > 127)
379 sidemove[0] = 127;
380
381 if (sidemove[1] > 127)
382 sidemove[1] = 127;
383 }
384 }
385 }
386
387 static dboolean WeaponSelectable(weapontype_t weapon)
388 {
389 if (heretic)
390 {
391 return weapon != wp_beak && players[consoleplayer].weaponowned[weapon];
392 }
393 else if (hexen)
394 {
395 return weapon < HEXEN_NUMWEAPONS && players[consoleplayer].weaponowned[weapon];
396 }
397
398 if (gamemode == shareware)
399 {
400 if (weapon == wp_plasma || weapon == wp_bfg)
401 return false;
402 }
403
404 // Can't select the super shotgun in Doom 1.
405 if (weapon == wp_supershotgun && gamemission == doom)
406 {
407 return false;
408 }
409
410 // Can't select a weapon if we don't own it.
411 if (!players[consoleplayer].weaponowned[weapon])
412 {
413 return false;
414 }
415
416 // Can't select the fist if we have the chainsaw, unless
417 // we also have the berserk pack.
418 if ((demo_compatibility)
419 && weapon == wp_fist
420 && players[consoleplayer].weaponowned[wp_chainsaw]
421 && !players[consoleplayer].powers[pw_strength])
422 {
423 return false;
424 }
425
426 return true;
427 }
428
429 static int G_NextWeapon(int direction)
430 {
431 weapontype_t weapon;
432 int start_i, i, arrlen;
433
434 // Find index in the table.
435 if (players[consoleplayer].pendingweapon == wp_nochange)
436 {
437 weapon = players[consoleplayer].readyweapon;
438 }
439 else
440 {
441 weapon = players[consoleplayer].pendingweapon;
442 }
443
444 arrlen = sizeof(weapon_order_table) / sizeof(*weapon_order_table);
445 for (i = 0; i < arrlen; i++)
446 {
447 if (weapon_order_table[i].weapon == weapon)
448 {
449 break;
450 }
451 }
452
453 // Switch weapon. Don't loop forever.
454 start_i = i;
455 do
456 {
457 i += direction;
458 i = (i + arrlen) % arrlen;
459 }
460 while (i != start_i && !WeaponSelectable(weapon_order_table[i].weapon));
461
462 return weapon_order_table[i].weapon_num;
463 }
464
465 static double mouse_sensitivity_horiz;
466 static double mouse_sensitivity_vert;
467 static double mouse_sensitivity_mlook;
468 static double mouse_strafe_divisor;
469
470 void G_UpdateMouseSensitivity(void)
471 {
472 double horizontal_sensitivity, fine_sensitivity;
473
474 horizontal_sensitivity = dsda_IntConfig(dsda_config_mouse_sensitivity_horiz);
475 fine_sensitivity = dsda_IntConfig(dsda_config_fine_sensitivity);
476
477 mouse_sensitivity_horiz = horizontal_sensitivity + fine_sensitivity / 100;
478 mouse_sensitivity_vert = dsda_IntConfig(dsda_config_mouse_sensitivity_vert);
479 mouse_sensitivity_mlook = dsda_IntConfig(dsda_config_mouse_sensitivity_mlook);
480 mouse_strafe_divisor = dsda_IntConfig(dsda_config_movement_mousestrafedivisor);
481 }
482
483 void G_ResetMotion(void)
484 {
485 mousex = mousey = 0;
486 left_analog_x = left_analog_y = 0;
487 }
488
489 static void G_ConvertAnalogMotion(int speed, int *forward, int *side)
490 {
491 if (left_analog_x || left_analog_y)
492 {
493 if (left_analog_x > sidemove[speed])
494 left_analog_x = sidemove[speed];
495 else if (left_analog_x < -sidemove[speed])
496 left_analog_x = -sidemove[speed];
497
498 if (left_analog_y > forwardmove[speed])
499 left_analog_y = forwardmove[speed];
500 else if (left_analog_y < -forwardmove[speed])
501 left_analog_y = -forwardmove[speed];
502
503 *forward += left_analog_y;
504 *side += left_analog_x;
505 }
506 }
507
508 void G_BuildTiccmd(ticcmd_t* cmd)
509 {
510 int strafe;
511 int bstrafe;
512 int speed;
513 int tspeed;
514 int forward;
515 int side;
516 int newweapon; // phares
517 dboolean strict_input;
518
519 dsda_pclass_t *player_class = &pclass[players[consoleplayer].pclass];
520
521 strict_input = dsda_StrictMode();
522
523 G_SetSpeed(false);
524 dsda_EvaluateSkipModeBuildTiccmd();
525
526 memset(cmd, 0, sizeof(*cmd));
527
528 if (demoplayback && demorecording)
529 {
530 G_ResetMotion();
531 return;
532 }
533
534 strafe = dsda_InputActive(dsda_input_strafe);
535 //e6y: the "RUN" key inverts the autorun state
536 speed = (dsda_InputActive(dsda_input_speed) ? !dsda_AutoRun() : dsda_AutoRun()); // phares
537
538 forward = side = 0;
539
540 // use two stage accelerative turning on the keyboard
541 if (dsda_InputActive(dsda_input_turnright) || dsda_InputActive(dsda_input_turnleft))
542 ++turnheld;
543 else
544 turnheld = 0;
545
546 if (turnheld < SLOWTURNTICS)
547 tspeed = 2; // slow turn
548 else
549 tspeed = speed;
550
551 // turn 180 degrees in one keystroke?
552 if (dsda_InputTickActivated(dsda_input_reverse))
553 {
554 if (!strafe) {
555 if (strict_input)
556 doom_printf("180 key disabled by strict mode");
557 else
558 cmd->angleturn += QUICKREVERSE;
559 }
560 }
561
562 // let movement keys cancel each other out
563
564 if (strafe)
565 {
566 if (dsda_InputActive(dsda_input_turnright))
567 side += sidemove[speed];
568 if (dsda_InputActive(dsda_input_turnleft))
569 side -= sidemove[speed];
570 }
571 else
572 {
573 if (dsda_InputActive(dsda_input_turnright))
574 cmd->angleturn -= angleturn[tspeed];
575 if (dsda_InputActive(dsda_input_turnleft))
576 cmd->angleturn += angleturn[tspeed];
577 }
578
579 if (dsda_InputActive(dsda_input_forward))
580 forward += forwardmove[speed];
581 if (dsda_InputActive(dsda_input_backward))
582 forward -= forwardmove[speed];
583 if (dsda_InputActive(dsda_input_straferight))
584 side += sidemove[speed];
585 if (dsda_InputActive(dsda_input_strafeleft))
586 side -= sidemove[speed];
587
588 if (raven)
589 {
590 int lspeed;
591 int look, arti;
592 int flyheight;
593
594 look = arti = flyheight = 0;
595
596 if (dsda_InputActive(dsda_input_lookdown) || dsda_InputActive(dsda_input_lookup))
597 {
598 ++lookheld;
599 }
600 else
601 {
602 lookheld = 0;
603 }
604 if (lookheld < SLOWTURNTICS)
605 {
606 lspeed = 1;
607 }
608 else
609 {
610 lspeed = 2;
611 }
612
613 // Look up/down/center keys
614 if (dsda_InputActive(dsda_input_lookup))
615 {
616 look = lspeed;
617 }
618 if (dsda_InputActive(dsda_input_lookdown))
619 {
620 look = -lspeed;
621 }
622
623 if (dsda_InputActive(dsda_input_lookcenter))
624 {
625 look = TOCENTER;
626 }
627
628 // Fly up/down/drop keys
629 if (dsda_InputActive(dsda_input_flyup))
630 {
631 flyheight = 5; // note that the actual flyheight will be twice this
632 }
633 if (dsda_InputActive(dsda_input_flydown))
634 {
635 flyheight = -5;
636 }
637 if (dsda_InputActive(dsda_input_flycenter))
638 {
639 flyheight = TOCENTER;
640 look = TOCENTER;
641 }
642
643 // Use artifact key
644 if (dsda_InputTickActivated(dsda_input_use_artifact))
645 {
646 if (inventory)
647 {
648 players[consoleplayer].readyArtifact = players[consoleplayer].inventory[inv_ptr].type;
649 inventory = false;
650 cmd->arti = 0;
651 }
652 else
653 {
654 cmd->arti |= players[consoleplayer].inventory[inv_ptr].type & AFLAG_MASK;
655 }
656 }
657
658 if (hexen)
659 {
660 extern int mn_SuicideConsole;
661
662 if (dsda_InputActive(dsda_input_jump))
663 {
664 cmd->arti |= AFLAG_JUMP;
665 }
666
667 if (mn_SuicideConsole)
668 {
669 cmd->arti |= AFLAG_SUICIDE;
670 mn_SuicideConsole = false;
671 }
672
673 if (!cmd->arti)
674 {
675 if (dsda_InputTickActivated(dsda_input_arti_ring))
676 {
677 cmd->arti = hexen_arti_invulnerability;
678 }
679 else if (dsda_InputTickActivated(dsda_input_arti_quartz) &&
680 players[consoleplayer].mo &&
681 players[consoleplayer].mo->health < MAXHEALTH)
682 {
683 cmd->arti = hexen_arti_health;
684 }
685 else if (dsda_InputTickActivated(dsda_input_arti_urn))
686 {
687 cmd->arti = hexen_arti_superhealth;
688 }
689 else if (dsda_InputTickActivated(dsda_input_hexen_arti_incant))
690 {
691 cmd->arti = hexen_arti_healingradius;
692 }
693 else if (dsda_InputTickActivated(dsda_input_hexen_arti_summon))
694 {
695 cmd->arti = hexen_arti_summon;
696 }
697 else if (dsda_InputTickActivated(dsda_input_arti_torch))
698 {
699 cmd->arti = hexen_arti_torch;
700 }
701 else if (dsda_InputTickActivated(dsda_input_arti_morph))
702 {
703 cmd->arti = hexen_arti_egg;
704 }
705 else if (dsda_InputTickActivated(dsda_input_arti_wings))
706 {
707 cmd->arti = hexen_arti_fly;
708 }
709 else if (dsda_InputTickActivated(dsda_input_hexen_arti_disk))
710 {
711 cmd->arti = hexen_arti_blastradius;
712 }
713 else if (dsda_InputTickActivated(dsda_input_hexen_arti_flechette))
714 {
715 cmd->arti = hexen_arti_poisonbag;
716 }
717 else if (dsda_InputTickActivated(dsda_input_hexen_arti_banishment))
718 {
719 cmd->arti = hexen_arti_teleportother;
720 }
721 else if (dsda_InputTickActivated(dsda_input_hexen_arti_boots))
722 {
723 cmd->arti = hexen_arti_speed;
724 }
725 else if (dsda_InputTickActivated(dsda_input_hexen_arti_krater))
726 {
727 cmd->arti = hexen_arti_boostmana;
728 }
729 else if (dsda_InputTickActivated(dsda_input_hexen_arti_bracers))
730 {
731 cmd->arti = hexen_arti_boostarmor;
732 }
733 else if (dsda_InputTickActivated(dsda_input_arti_chaosdevice))
734 {
735 cmd->arti = hexen_arti_teleport;
736 }
737 }
738 }
739 else
740 {
741 if (dsda_InputTickActivated(dsda_input_arti_tome) && !cmd->arti
742 && !players[consoleplayer].powers[pw_weaponlevel2])
743 {
744 cmd->arti = arti_tomeofpower;
745 }
746 else if (dsda_InputTickActivated(dsda_input_arti_quartz) && !cmd->arti &&
747 players[consoleplayer].mo &&
748 players[consoleplayer].mo->health < MAXHEALTH)
749 {
750 cmd->arti = arti_health;
751 }
752 else if (dsda_InputTickActivated(dsda_input_arti_urn) && !cmd->arti)
753 {
754 cmd->arti = arti_superhealth;
755 }
756 else if (dsda_InputTickActivated(dsda_input_arti_bomb) && !cmd->arti)
757 {
758 cmd->arti = arti_firebomb;
759 }
760 else if (dsda_InputTickActivated(dsda_input_arti_ring) && !cmd->arti)
761 {
762 cmd->arti = arti_invulnerability;
763 }
764 else if (dsda_InputTickActivated(dsda_input_arti_chaosdevice) && !cmd->arti)
765 {
766 cmd->arti = arti_teleport;
767 }
768 else if (dsda_InputTickActivated(dsda_input_arti_shadowsphere) && !cmd->arti)
769 {
770 cmd->arti = arti_invisibility;
771 }
772 else if (dsda_InputTickActivated(dsda_input_arti_wings) && !cmd->arti)
773 {
774 cmd->arti = arti_fly;
775 }
776 else if (dsda_InputTickActivated(dsda_input_arti_torch) && !cmd->arti)
777 {
778 cmd->arti = arti_torch;
779 }
780 else if (dsda_InputTickActivated(dsda_input_arti_morph) && !cmd->arti)
781 {
782 cmd->arti = arti_egg;
783 }
784 }
785
786 if (players[consoleplayer].playerstate == PST_LIVE && !dsda_FreeAim())
787 {
788 if (look < 0)
789 {
790 look += 16;
791 }
792 cmd->lookfly = look;
793 }
794 if (flyheight < 0)
795 {
796 flyheight += 16;
797 }
798 cmd->lookfly |= flyheight << 4;
799 }
800
801 if (dsda_AllowJumping())
802 {
803 if (!hexen && dsda_InputActive(dsda_input_jump))
804 {
805 dsda_QueueExCmdJump();
806 }
807 }
808
809 if (players[consoleplayer].mo && players[consoleplayer].mo->pitch && !dsda_MouseLook())
810 dsda_QueueExCmdLook(XC_LOOK_RESET);
811
812 if (dsda_FreeAim())
813 {
814 short look;
815
816 look = mlooky;
817
818 if (look)
819 {
820 if (players[consoleplayer].mo && !V_IsOpenGLMode())
821 {
822 int target_look = players[consoleplayer].mo->pitch + (look << 16);
823
824 if (target_look < (int) raven_angle_up_limit)
825 look = (raven_angle_up_limit - players[consoleplayer].mo->pitch) >> 16;
826
827 if (target_look > (int) raven_angle_down_limit)
828 look = (raven_angle_down_limit - players[consoleplayer].mo->pitch) >> 16;
829 }
830
831 dsda_QueueExCmdLook(look);
832 }
833 }
834
835 if (dsda_InputActive(dsda_input_fire))
836 cmd->buttons |= BT_ATTACK;
837
838 if (dsda_InputActive(dsda_input_use) || dsda_InputTickActivated(dsda_input_use))
839 {
840 cmd->buttons |= BT_USE;
841 // clear double clicks if hit use button
842 dclicks = 0;
843 }
844
845 {
846 extern dboolean boom_weapon_state_injection;
847 static dboolean done_autoswitch = false;
848
849 if (!players[consoleplayer].attackdown)
850 {
851 done_autoswitch = false;
852 }
853
854 // Toggle between the top 2 favorite weapons. // phares
855 // If not currently aiming one of these, switch to // phares
856 // the favorite. Only switch if you possess the weapon. // phares
857
858 // killough 3/22/98:
859 //
860 // Perform automatic weapons switch here rather than in p_pspr.c,
861 // except in demo_compatibility mode.
862 //
863 // killough 3/26/98, 4/2/98: fix autoswitch when no weapons are left
864
865 // Make Boom insert only a single weapon change command on autoswitch.
866 if (
867 (
868 !demo_compatibility &&
869 players[consoleplayer].attackdown && // killough
870 !P_CheckAmmo(&players[consoleplayer]) &&
871 (
872 (
873 (
874 dsda_SwitchWhenAmmoRunsOut() ||
875 boom_weapon_state_injection
876 ) &&
877 !done_autoswitch
878 ) || (
879 cmd->buttons & BT_ATTACK &&
880 players[consoleplayer].pendingweapon == wp_nochange
881 )
882 )
883 ) || (!hexen && dsda_InputActive(dsda_input_toggleweapon))
884 )
885 {
886 done_autoswitch = true;
887 boom_weapon_state_injection = false;
888 newweapon = P_SwitchWeapon(&players[consoleplayer]); // phares
889 }
890 else
891 { // phares 02/26/98: Added gamemode checks
892 if (next_weapon && players[consoleplayer].morphTics == 0)
893 {
894 newweapon = G_NextWeapon(next_weapon);
895 }
896 else if (hexen)
897 {
898 newweapon =
899 dsda_InputActive(dsda_input_weapon1) ? wp_first : // killough 5/2/98: reformatted
900 dsda_InputActive(dsda_input_weapon2) ? wp_second :
901 dsda_InputActive(dsda_input_weapon3) ? wp_third :
902 dsda_InputActive(dsda_input_weapon4) ? wp_fourth :
903 wp_nochange;
904 }
905 else
906 {
907 // HERETIC_TODO: fix this
908 newweapon =
909 dsda_InputTickActivated(dsda_input_weapon1) ? wp_fist : // killough 5/2/98: reformatted
910 dsda_InputTickActivated(dsda_input_weapon2) ? wp_pistol :
911 dsda_InputTickActivated(dsda_input_weapon3) ? wp_shotgun :
912 dsda_InputTickActivated(dsda_input_weapon4) ? wp_chaingun :
913 dsda_InputTickActivated(dsda_input_weapon5) ? wp_missile :
914 dsda_InputTickActivated(dsda_input_weapon6) && gamemode != shareware ? wp_plasma :
915 dsda_InputTickActivated(dsda_input_weapon7) && gamemode != shareware ? wp_bfg :
916 dsda_InputTickActivated(dsda_input_weapon8) ? wp_chainsaw :
917 (!demo_compatibility && dsda_InputTickActivated(dsda_input_weapon9) && gamemode == commercial) ? wp_supershotgun :
918 wp_nochange;
919 }
920
921 // killough 3/22/98: For network and demo consistency with the
922 // new weapons preferences, we must do the weapons switches here
923 // instead of in p_user.c. But for old demos we must do it in
924 // p_user.c according to the old rules. Therefore demo_compatibility
925 // determines where the weapons switch is made.
926
927 // killough 2/8/98:
928 // Allow user to switch to fist even if they have chainsaw.
929 // Switch to fist or chainsaw based on preferences.
930 // Switch to shotgun or SSG based on preferences.
931
932 if (!demo_compatibility)
933 {
934 const player_t *player = &players[consoleplayer];
935
936 // only select chainsaw from '1' if it's owned, it's
937 // not already in use, and the player prefers it or
938 // the fist is already in use, or the player does not
939 // have the berserker strength.
940
941 if (newweapon==wp_fist && player->weaponowned[wp_chainsaw] &&
942 player->readyweapon!=wp_chainsaw &&
943 (player->readyweapon==wp_fist ||
944 !player->powers[pw_strength] ||
945 P_WeaponPreferred(wp_chainsaw, wp_fist)))
946 newweapon = wp_chainsaw;
947
948 // Select SSG from '3' only if it's owned and the player
949 // does not have a shotgun, or if the shotgun is already
950 // in use, or if the SSG is not already in use and the
951 // player prefers it.
952
953 if (newweapon == wp_shotgun && gamemode == commercial &&
954 player->weaponowned[wp_supershotgun] &&
955 (!player->weaponowned[wp_shotgun] ||
956 player->readyweapon == wp_shotgun ||
957 (player->readyweapon != wp_supershotgun &&
958 P_WeaponPreferred(wp_supershotgun, wp_shotgun))))
959 newweapon = wp_supershotgun;
960 }
961 }
962 }
963
964 next_weapon = 0;
965
966 if (newweapon != wp_nochange && players[consoleplayer].chickenTics == 0)
967 {
968 cmd->buttons |= BT_CHANGE;
969 cmd->buttons |= newweapon<<BT_WEAPONSHIFT;
970 }
971
972 // mouse
973
974 if (dsda_IntConfig(dsda_config_mouse_doubleclick_as_use)) {//e6y
975 // forward double click
976 if (dsda_InputMouseBActive(dsda_input_forward) != dclickstate && dclicktime > 1 )
977 {
978 dclickstate = dsda_InputMouseBActive(dsda_input_forward);
979 if (dclickstate)
980 dclicks++;
981 if (dclicks == 2)
982 {
983 cmd->buttons |= BT_USE;
984 dclicks = 0;
985 }
986 else
987 dclicktime = 0;
988 }
989 else
990 if (++dclicktime > 20)
991 {
992 dclicks = 0;
993 dclickstate = 0;
994 }
995
996 // strafe double click
997 bstrafe = dsda_InputMouseBActive(dsda_input_strafe) || dsda_InputJoyBActive(dsda_input_strafe);
998 if (bstrafe != dclickstate2 && dclicktime2 > 1 )
999 {
1000 dclickstate2 = bstrafe;
1001 if (dclickstate2)
1002 dclicks2++;
1003 if (dclicks2 == 2)
1004 {
1005 cmd->buttons |= BT_USE;
1006 dclicks2 = 0;
1007 }
1008 else
1009 dclicktime2 = 0;
1010 }
1011 else
1012 if (++dclicktime2 > 20)
1013 {
1014 dclicks2 = 0;
1015 dclickstate2 = 0;
1016 }
1017 }
1018
1019 if (dsda_VertMouse())
1020 {
1021 forward += mousey;
1022 }
1023
1024 dsda_ApplyQuickstartMouseCache(&mousex);
1025
1026 if (strafe)
1027 {
1028 static double mousestrafe_carry = 0;
1029 int delta;
1030 double true_delta;
1031
1032 true_delta = mousestrafe_carry +
1033 (double) mousex / mouse_strafe_divisor;
1034
1035 delta = (int) true_delta;
1036 delta = (delta / 2) * 2;
1037 mousestrafe_carry = true_delta - delta;
1038
1039 side += delta;
1040 side = (side / 2) * 2; // only even values are possible
1041 }
1042 else
1043 cmd->angleturn -= mousex; /* mead now have enough dynamic range 2-10-00 */
1044
1045 G_ConvertAnalogMotion(speed, &forward, &side);
1046
1047 if (!walkcamera.type || menuactive) //e6y
1048 G_ResetMotion();
1049
1050 if (forward > MAXPLMOVE)
1051 forward = MAXPLMOVE;
1052 else if (forward < -MAXPLMOVE)
1053 forward = -MAXPLMOVE;
1054
1055 if (side > MAXPLMOVE)
1056 side = MAXPLMOVE;
1057 else if (side < -MAXPLMOVE)
1058 side = -MAXPLMOVE;
1059
1060 //e6y
1061 if (dsda_AlwaysSR50())
1062 {
1063 if (!speed)
1064 {
1065 if (side > player_class->forwardmove[0])
1066 side = player_class->forwardmove[0];
1067 else if (side < -player_class->forwardmove[0])
1068 side = -player_class->forwardmove[0];
1069 }
1070 else if (!dsda_IntConfig(dsda_config_movement_strafe50onturns) && !strafe && cmd->angleturn)
1071 {
1072 if (side > player_class->sidemove[1])
1073 side = player_class->sidemove[1];
1074 else if (side < -player_class->sidemove[1])
1075 side = -player_class->sidemove[1];
1076 }
1077 }
1078
1079 if (players[consoleplayer].powers[pw_speed] && !players[consoleplayer].morphTics)
1080 { // Adjust for a player with a speed artifact
1081 forward = (3 * forward) >> 1;
1082 side = (3 * side) >> 1;
1083 }
1084
1085 if (stroller) side = 0;
1086
1087 cmd->forwardmove += fudgef((signed char)forward);
1088 cmd->sidemove += side;
1089
1090 if ((demorecording && !longtics) || shorttics)
1091 {
1092 // Chocolate Doom Mouse Behaviour
1093 // Don't discard mouse delta even if value is too small to
1094 // turn the player this tic
1095 if (dsda_IntConfig(dsda_config_mouse_carrytics)) {
1096 static signed short carry = 0;
1097 signed short desired_angleturn = cmd->angleturn + carry;
1098 cmd->angleturn = (desired_angleturn + 128) & 0xff00;
1099 carry = desired_angleturn - cmd->angleturn;
1100 }
1101
1102 cmd->angleturn = (((cmd->angleturn + 128) >> 8) << 8);
1103 }
1104
1105 upmove = 0;
1106 if (dsda_InputActive(dsda_input_flyup))
1107 upmove += flyspeed[speed];
1108 if (dsda_InputActive(dsda_input_flydown))
1109 upmove -= flyspeed[speed];
1110
1111 // CPhipps - special events (game new/load/save/pause)
1112 if (special_event & BT_SPECIAL) {
1113 cmd->buttons = special_event;
1114 special_event = 0;
1115 }
1116
1117 dsda_PopExCmdQueue(cmd);
1118
1119 if (!dsda_StrictMode()) {
1120 if (leveltime == 0 && totalleveltimes == 0) {
1121 dsda_arg_t* arg;
1122
1123 arg = dsda_Arg(dsda_arg_first_input);
1124 if (arg->found) {
1125 dsda_TrackFeature(uf_buildzero);
1126
1127 cmd->forwardmove = (signed char) arg->value.v_int_array[0];
1128 cmd->sidemove = (signed char) arg->value.v_int_array[1];
1129 cmd->angleturn = (signed short) (arg->value.v_int_array[2] << 8);
1130
1131 dsda_JoinDemoCmd(cmd);
1132 }
1133 }
1134 }
1135 }
1136
1137 static void G_SetInitialHealth(player_t *p)
1138 {
1139 p->health = initial_health; // Ty 03/12/98 - use dehacked values
1140 }
1141
1142 static void G_SetInitialInventory(player_t *p)
1143 {
1144 int i;
1145
1146 if (hexen)
1147 {
1148 p->readyweapon = p->pendingweapon = wp_first;
1149 p->weaponowned[wp_first] = true;
1150 }
1151 else
1152 {
1153 p->readyweapon = p->pendingweapon = g_wp_pistol;
1154 p->weaponowned[g_wp_fist] = true;
1155 p->weaponowned[g_wp_pistol] = true;
1156 if (heretic)
1157 p->ammo[am_goldwand] = 50;
1158 else
1159 p->ammo[am_clip] = initial_bullets; // Ty 03/12/98 - use dehacked values
1160 }
1161
1162 for (i = 0; i < NUMAMMO; i++)
1163 p->maxammo[i] = maxammo[i];
1164 }
1165
1166 static void G_ResetHealth(player_t *p)
1167 {
1168 G_SetInitialHealth(p);
1169 }
1170
1171 static void G_ResetInventory(player_t *p)
1172 {
1173 memset(p->armorpoints, 0, sizeof(p->armorpoints));
1174 p->armortype = 0;
1175 memset(p->powers, 0, sizeof(p->powers));
1176 memset(p->cards, 0, sizeof(p->cards));
1177 p->backpack = false;
1178 memset(p->weaponowned, 0, sizeof(p->weaponowned));
1179 memset(p->ammo, 0, sizeof(p->ammo));
1180
1181 // readyweapon, pendingweapon, maxammo handled here
1182 G_SetInitialInventory(p);
1183 }
1184
1185 //
1186 // G_DoLoadLevel
1187 //
1188
1189 static void G_DoLoadLevel (void)
1190 {
1191 int i;
1192
1193 // Set the sky map.
1194 // First thing, we have a dummy sky texture name,
1195 // a flat. The data is in the WAD only because
1196 // we look for an actual index, instead of simply
1197 // setting one.
1198
1199 skyflatnum = R_FlatNumForName(g_skyflatname);
1200 skytexture = dsda_SkyTexture();
1201 R_SetFloorNum(&grnrock, dsda_BorderTexture());
1202
1203 // [RH] Set up details about sky rendering
1204 R_InitSkyMap ();
1205
1206 dsda_InitMessenger();
1207
1208 levelstarttic = gametic; // for time calculation
1209
1210 if (!demo_compatibility && !mbf_features) // killough 9/29/98
1211 boom_basetic = gametic;
1212
1213 if (wipegamestate == GS_LEVEL)
1214 wipegamestate = -1; // force a wipe
1215
1216 gamestate = GS_LEVEL;
1217
1218 for (i = 0; i < g_maxplayers; i++)
1219 {
1220 if (playeringame[i])
1221 {
1222 if (players[i].playerstate == PST_DEAD)
1223 players[i].playerstate = PST_REBORN;
1224 else
1225 {
1226 if (map_info.flags & MI_RESET_HEALTH)
1227 G_ResetHealth(&players[i]);
1228
1229 if (map_info.flags & MI_RESET_INVENTORY)
1230 G_ResetInventory(&players[i]);
1231 }
1232 }
1233 memset(players[i].frags, 0, sizeof(players[i].frags));
1234 }
1235
1236 // automatic pistol start when advancing from one level to the next
1237 if (pistolstart)
1238 if (allow_incompatibility)
1239 G_PlayerReborn(0);
1240
1241 // initialize the msecnode_t freelist. phares 3/25/98
1242 // any nodes in the freelist are gone by now, cleared
1243 // by Z_FreeTag() when the previous level ended or player
1244 // died.
1245 P_FreeSecNodeList();
1246
1247 if (map_format.sndseq)
1248 SN_StopAllSequences();
1249
1250 P_SetupLevel (gameepisode, gamemap, 0, gameskill);
1251 if (!demoplayback) // Don't switch views if playing a demo
1252 displayplayer = consoleplayer; // view the guy you are playing
1253 gameaction = ga_nothing;
1254
1255 // clear cmd building stuff
1256 dsda_InputFlush();
1257 G_ResetMotion();
1258 mlooky = 0;//e6y
1259 special_event = 0;
1260 dsda_ResetPauseMode();
1261 dsda_ResetExCmdQueue();
1262
1263 if (dsda_BuildMode() || dsda_StartInBuildMode())
1264 dsda_EnterBuildMode();
1265
1266 // killough 5/13/98: in case netdemo has consoleplayer other than green
1267 ST_Start();
1268 HU_Start();
1269
1270 // The border texture can change between maps, which must queue a backscreen fill
1271 {
1272 void D_MustFillBackScreen();
1273
1274 static int old_grnrock = -1;
1275
1276 if (old_grnrock != grnrock.lumpnum)
1277 {
1278 old_grnrock = grnrock.lumpnum;
1279 D_MustFillBackScreen();
1280 }
1281 }
1282
1283 // killough: make -timedemo work on multilevel demos
1284 // Move to end of function to minimize noise -- killough 2/22/98:
1285
1286 if (timingdemo)
1287 {
1288 static int first=1;
1289 if (first)
1290 {
1291 starttime = dsda_GetTickRealTime();
1292 first=0;
1293 }
1294 }
1295 }
1296
1297 //
1298 // G_Responder
1299 // Get info needed to make ticcmd_ts for the players.
1300 //
1301
1302 dboolean G_Responder (event_t* ev)
1303 {
1304 if (
1305 gamestate == GS_LEVEL && (
1306 HU_Responder(ev) ||
1307 ST_Responder(ev) ||
1308 AM_Responder(ev)
1309 )
1310 ) return true;
1311
1312 if (dsda_IntConfig(dsda_config_playback_mouse_controls) &&
1313 demoplayback && !timingdemo && dsda_InputActivated(dsda_input_fire))
1314 {
1315 int x, y;
1316
1317 dsda_GetMousePosition(&x, &y);
1318
1319 y = y * ACTUALHEIGHT / viewport_rect.h;
1320
1321 if (x && y > (ACTUALHEIGHT - ST_SCALED_HEIGHT / 6))
1322 {
1323 dsda_JumpToLogicTic(demo_tics_count * x / viewport_rect.w);
1324 return true;
1325 }
1326 }
1327
1328 // allow spy mode changes even during the demo
1329 // killough 2/22/98: even during DM demo
1330 //
1331 // killough 11/98: don't autorepeat spy mode switch
1332 if (dsda_InputActivated(dsda_input_spy) &&
1333 netgame && (demoplayback || !deathmatch) &&
1334 gamestate == GS_LEVEL)
1335 {
1336 do // spy mode
1337 if (++displayplayer >= g_maxplayers)
1338 displayplayer = 0;
1339 while (!playeringame[displayplayer] && displayplayer!=consoleplayer);
1340
1341 ST_Start(); // killough 3/7/98: switch status bar views too
1342 HU_Start();
1343 S_UpdateSounds();
1344 R_ActivateSectorInterpolations();
1345 R_SmoothPlaying_Reset(NULL);
1346 return true;
1347 }
1348
1349 // any other key pops up menu if in demos
1350 //
1351 // killough 8/2/98: enable automap in -timedemo demos
1352 //
1353 // killough 9/29/98: make any key pop up menu regardless of
1354 // which kind of demo, and allow other events during playback
1355
1356 if (gameaction == ga_nothing && (demoplayback || gamestate == GS_DEMOSCREEN))
1357 {
1358 // killough 9/29/98: allow user to pause demos during playback
1359 if (dsda_InputActivated(dsda_input_pause))
1360 {
1361 dsda_TogglePauseMode(PAUSE_PLAYBACK);
1362 if (dsda_Paused())
1363 S_PauseSound();
1364 else
1365 S_ResumeSound();
1366 return true;
1367 }
1368 }
1369
1370 if (gamestate == GS_FINALE && F_Responder(ev))
1371 return true; // finale ate the event
1372
1373 if (dsda_BuildResponder(ev))
1374 return true;
1375
1376 // If the next/previous weapon keys are pressed, set the next_weapon
1377 // variable to change weapons when the next ticcmd is generated.
1378 if (dsda_InputActivated(dsda_input_prevweapon))
1379 {
1380 next_weapon = -1;
1381 }
1382 else if (dsda_InputActivated(dsda_input_nextweapon))
1383 {
1384 next_weapon = 1;
1385 }
1386
1387 if (dsda_InputActivated(dsda_input_invleft))
1388 {
1389 return InventoryMoveLeft();
1390 }
1391 if (dsda_InputActivated(dsda_input_invright))
1392 {
1393 return InventoryMoveRight();
1394 }
1395
1396 if (dsda_InputActivated(dsda_input_pause))
1397 {
1398 special_event = BT_SPECIAL | (BT_PAUSE & BT_SPECIALMASK);
1399 return true;
1400 }
1401
1402 // Events that make it here should reach into the game logic
1403 dsda_InputTrackGameEvent(ev);
1404
1405 switch (ev->type)
1406 {
1407 case ev_keydown:
1408 return true; // eat key down events
1409
1410 case ev_mousemotion:
1411 {
1412 double value;
1413
1414 dsda_WatchMouseEvent();
1415
1416 value = mouse_sensitivity_horiz * AccelerateMouse(ev->data1.i);
1417 mousex += G_CarryDouble(carry_mousex, value);
1418 if (dsda_MouseLook())
1419 {
1420 value = mouse_sensitivity_mlook * AccelerateMouse(ev->data2.i);
1421 if (dsda_IntConfig(dsda_config_movement_mouseinvert))
1422 mlooky += G_CarryDouble(carry_mousey, value);
1423 else
1424 mlooky -= G_CarryDouble(carry_mousey, value);
1425 }
1426 else
1427 {
1428 value = mouse_sensitivity_vert * AccelerateMouse(ev->data2.i) / 8;
1429 mousey += G_CarryDouble(carry_vertmouse, value);
1430 }
1431
1432 return true; // eat events
1433 }
1434
1435 case ev_move_analog:
1436 dsda_WatchGameControllerEvent();
1437
1438 left_analog_x = ev->data1.f;
1439 left_analog_y = ev->data2.f;
1440 return true; // eat events
1441
1442 case ev_look_analog:
1443 dsda_WatchGameControllerEvent();
1444
1445 mousex += AccelerateAnalog(ev->data1.f);
1446 if (dsda_MouseLook())
1447 {
1448 if (dsda_IntConfig(dsda_config_invert_analog_look))
1449 mlooky += AccelerateAnalog(ev->data2.f);
1450 else
1451 mlooky -= AccelerateAnalog(ev->data2.f);
1452 }
1453 return true; // eat events
1454
1455 default:
1456 break;
1457 }
1458 return false;
1459 }
1460
1461 //
1462 // G_Ticker
1463 // Make ticcmd_ts for the players.
1464 //
1465
1466 void G_Ticker (void)
1467 {
1468 int i;
1469 int entry_leveltime;
1470 int pause_mask;
1471 dboolean advance_frame = false;
1472 static gamestate_t prevgamestate;
1473
1474 entry_leveltime = leveltime;
1475
1476 // CPhipps - player colour changing
1477 if (!demoplayback && mapcolor.plyr[consoleplayer] != mapcolor.me) {
1478 // Changed my multiplayer colour - Inform the whole game
1479 G_ChangedPlayerColour(consoleplayer, mapcolor.me);
1480 }
1481 P_MapStart();
1482 // do player reborns if needed
1483 for (i = 0; i < g_maxplayers; i++)
1484 if (playeringame[i] && players[i].playerstate == PST_REBORN)
1485 G_DoReborn(i);
1486 P_MapEnd();
1487
1488 // do things to change the game state
1489 while (gameaction != ga_nothing)
1490 {
1491 switch (gameaction)
1492 {
1493 case ga_loadlevel:
1494 // force players to be initialized on level reload
1495 if (!hexen)
1496 for (i = 0; i < g_maxplayers; i++)
1497 players[i].playerstate = PST_REBORN;
1498 G_DoLoadLevel();
1499 break;
1500 case ga_newgame:
1501 G_DoNewGame();
1502 break;
1503 case ga_loadgame:
1504 G_DoLoadGame();
1505 break;
1506 case ga_playdemo:
1507 G_DoPlayDemo();
1508 break;
1509 case ga_completed:
1510 G_DoCompleted();
1511 break;
1512 case ga_victory:
1513 F_StartFinale();
1514 break;
1515 case ga_worlddone:
1516 G_DoWorldDone();
1517 break;
1518 case ga_leavemap:
1519 G_DoTeleportNewMap();
1520 break;
1521 case ga_nothing:
1522 break;
1523 }
1524 }
1525
1526 dsda_EvaluateSkipModeGTicker();
1527
1528 if (!dsda_SkipMode() && gamestate == GS_LEVEL)
1529 {
1530 DO_ONCE
1531 dsda_arg_t *arg;
1532
1533 arg = dsda_Arg(dsda_arg_command);
1534 if (arg->found)
1535 dsda_InterpretConsoleCommands(arg->value.v_string, false, true);
1536 END_ONCE
1537 }
1538
1539 if (dsda_BruteForce())
1540 dsda_EvaluateBruteForce();
1541
1542 if (dsda_BuildMode())
1543 dsda_RefreshBuildMode();
1544
1545 if (dsda_AdvanceFrame())
1546 {
1547 advance_frame = true;
1548 pause_mask = dsda_MaskPause();
1549 }
1550 else if (dsda_BuildMode() &&
1551 dsda_BruteForceEnded() &&
1552 dsda_Flag(dsda_arg_quit_after_brute_force))
1553 {
1554 I_SafeExit(0);
1555 }
1556
1557 if (dsda_PausedOutsideDemo())
1558 {
1559 boom_basetic++; // For revenant tracers and RNG -- we must maintain sync
1560 true_basetic++;
1561 }
1562 else {
1563 int buf = gametic % BACKUPTICS;
1564
1565 if (!timingdemo) {
1566 dsda_UpdateAutoKeyFrames();
1567 dsda_UpdateAutoSaves();
1568
1569 if (demoplayback)
1570 dsda_UpdatePlaybackKeyFrames();
1571 }
1572
1573 if (dsda_BruteForce())
1574 {
1575 dsda_UpdateBruteForce();
1576 dsda_RemovePauseMode(PAUSE_BUILDMODE);
1577 }
1578
1579 for (i = 0; i < g_maxplayers; i++)
1580 {
1581 if (playeringame[i])
1582 {
1583 ticcmd_t *cmd = &players[i].cmd;
1584
1585 memcpy(cmd, &local_cmds[i][buf], sizeof *cmd);
1586
1587 if (dsda_BuildMode())
1588 dsda_ReadBuildCmd(cmd);
1589
1590 if (dsda_PendingJoin())
1591 dsda_JoinDemoCmd(cmd);
1592
1593 if (demoplayback)
1594 dsda_TryPlaybackOneTick(cmd);
1595
1596 if (demorecording)
1597 G_WriteDemoTiccmd(cmd);
1598 }
1599 }
1600
1601 dsda_InputFlushTick();
1602 dsda_WatchCommand();
1603
1604 // check for special buttons
1605 for (i = 0; i < g_maxplayers; i++)
1606 {
1607 if (playeringame[i])
1608 {
1609 if (players[i].cmd.buttons & BT_SPECIAL)
1610 {
1611 switch (players[i].cmd.buttons & BT_SPECIALMASK)
1612 {
1613 case BT_PAUSE:
1614 dsda_TogglePauseMode(PAUSE_COMMAND);
1615 if (dsda_Paused())
1616 S_PauseSound();
1617 else
1618 S_ResumeSound();
1619 break;
1620 }
1621 if (!raven) players[i].cmd.buttons = 0;
1622 }
1623
1624 if (dsda_AllowExCmd())
1625 {
1626 excmd_t *ex = &players[i].cmd.ex;
1627
1628 if (ex->actions & XC_SAVE)
1629 {
1630 savegameslot = ex->save_slot;
1631 G_DoSaveGame(true);
1632 }
1633
1634 if (ex->actions & XC_LOAD)
1635 {
1636 savegameslot = ex->load_slot;
1637 gameaction = ga_loadgame;
1638 forced_loadgame = true;
1639 load_via_cmd = true;
1640 R_SmoothPlaying_Reset(NULL);
1641 }
1642
1643 if (ex->actions & XC_GOD)
1644 {
1645 M_CheatGod();
1646 }
1647
1648 if (ex->actions & XC_NOCLIP)
1649 {
1650 M_CheatNoClip();
1651 }
1652
1653 if (ex->actions & XC_LOOK && ex->look != XC_LOOK_RESET && !dsda_MouseLook())
1654 {
1655 dsda_UpdateIntConfig(dsda_config_freelook, 1, false);
1656 }
1657 }
1658 }
1659 }
1660
1661 // turn inventory off after a certain amount of time
1662 if (inventory && !(--inventoryTics))
1663 {
1664 players[consoleplayer].readyArtifact =
1665 players[consoleplayer].inventory[inv_ptr].type;
1666 inventory = false;
1667 }
1668
1669 dsda_DisplayNotifications();
1670 }
1671
1672 // cph - if the gamestate changed, we may need to clean up the old gamestate
1673 if (gamestate != prevgamestate) {
1674 switch (prevgamestate) {
1675 case GS_LEVEL:
1676 break;
1677 case GS_INTERMISSION:
1678 WI_End();
1679 default:
1680 break;
1681 }
1682 prevgamestate = gamestate;
1683 }
1684
1685 // e6y
1686 // do nothing if a pause has been pressed during playback
1687 // pausing during intermission can cause desynchs without that
1688 if (dsda_PausedOutsideDemo() && gamestate != GS_LEVEL)
1689 return;
1690
1691 // do main actions
1692 switch (gamestate)
1693 {
1694 case GS_LEVEL:
1695 P_Ticker();
1696 P_WalkTicker();
1697 mlooky = 0;
1698 AM_Ticker();
1699 ST_Ticker();
1700 HU_Ticker();
1701 break;
1702
1703 case GS_INTERMISSION:
1704 WI_Ticker();
1705 break;
1706
1707 case GS_FINALE:
1708 F_Ticker();
1709 break;
1710
1711 case GS_DEMOSCREEN:
1712 D_PageTicker();
1713 break;
1714
1715 case GS_DEFAULT:
1716 break;
1717 }
1718
1719 if (leveltime == entry_leveltime)
1720 S_StopSoundLoops();
1721
1722 if (advance_frame)
1723 dsda_UnmaskPause(pause_mask);
1724 }
1725
1726 //
1727 // PLAYER STRUCTURE FUNCTIONS
1728 // also see P_SpawnPlayer in P_Things
1729 //
1730
1731 //
1732 // G_PlayerFinishLevel
1733 // Can when a player completes a level.
1734 //
1735
1736 typedef struct {
1737 int flight_carryover;
1738 dboolean set_one_artifact;
1739 int use_flight_artifact;
1740 int use_flight_count;
1741 dboolean remove_cards;
1742 } finish_level_behaviour_t;
1743
1744 static void G_FinishLevelBehaviour(finish_level_behaviour_t *flb, player_t *p)
1745 {
1746 dboolean different_cluster;
1747
1748 different_cluster = (dsda_MapCluster(gamemap) != dsda_MapCluster(leave_data.map));
1749
1750 if (hexen && !deathmatch && !different_cluster)
1751 flb->flight_carryover = p->powers[pw_flight];
1752 else
1753 flb->flight_carryover = 0;
1754
1755 flb->set_one_artifact = heretic;
1756
1757 if (heretic && !deathmatch)
1758 {
1759 flb->use_flight_artifact = arti_fly;
1760 flb->use_flight_count = 16;
1761 }
1762 else if (hexen && !deathmatch && different_cluster)
1763 {
1764 flb->use_flight_artifact = hexen_arti_fly;
1765 flb->use_flight_count = 25;
1766 }
1767 else
1768 {
1769 flb->use_flight_artifact = arti_none;
1770 flb->use_flight_count = 0;
1771 }
1772
1773 flb->remove_cards = (!hexen || different_cluster);
1774 }
1775
1776 static void G_PlayerFinishLevel(int player)
1777 {
1778 int i;
1779 player_t *p = &players[player];
1780 finish_level_behaviour_t flb;
1781
1782 G_FinishLevelBehaviour(&flb, p);
1783
1784 if (flb.set_one_artifact)
1785 {
1786 for (i = 0; i < p->inventorySlotNum; i++)
1787 {
1788 p->inventory[i].count = 1;
1789 }
1790 p->artifactCount = p->inventorySlotNum;
1791 }
1792
1793 if (flb.use_flight_artifact)
1794 {
1795 for (i = 0; i < flb.use_flight_count; i++)
1796 {
1797 if (hexen)
1798 p->powers[pw_flight] = 0;
1799
1800 P_PlayerUseArtifact(p, flb.use_flight_artifact);
1801 }
1802 }
1803
1804 if (p->chickenTics || p->morphTics)
1805 {
1806 p->readyweapon = p->mo->special1.i; // Restore weapon
1807 p->chickenTics = 0;
1808 p->morphTics = 0;
1809 }
1810
1811 p->lookdir = 0;
1812 p->rain1 = NULL;
1813 p->rain2 = NULL;
1814
1815 if (!hexen || (hexen && dsda_MapCluster(gamemap) != dsda_MapCluster(leave_data.map)))
1816 p->ravenkeys = 0;
1817
1818 memset(p->powers, 0, sizeof p->powers);
1819 if (flb.flight_carryover)
1820 p->powers[pw_flight] = flb.flight_carryover;
1821
1822 if (flb.remove_cards)
1823 memset(p->cards, 0, sizeof p->cards);
1824
1825 // TODO: need to understand the life cycle of p->mo in hexen
1826 if (hexen)
1827 p->mo->flags &= ~MF_SHADOW; // Remove invisibility
1828 else
1829 p->mo = NULL; // cph - this is zone-allocated so it's gone
1830
1831 p->extralight = 0; // cancel gun flashes
1832 p->fixedcolormap = 0; // cancel ir gogles
1833 p->damagecount = 0; // no palette changes
1834 p->bonuscount = 0;
1835 p->poisoncount = 0;
1836
1837 if (p == &players[consoleplayer])
1838 {
1839 SB_Start(); // refresh the status bar
1840 }
1841 }
1842
1843 // CPhipps - G_SetPlayerColour
1844 // Player colours stuff
1845 //
1846 // G_SetPlayerColour
1847
1848 #include "r_draw.h"
1849
1850 void G_ChangedPlayerColour(int pn, int cl)
1851 {
1852 int i;
1853
1854 if (!netgame) return;
1855
1856 mapcolor.plyr[pn] = cl;
1857
1858 // Rebuild colour translation tables accordingly
1859 R_InitTranslationTables();
1860 // Change translations on existing player mobj's
1861 for (i = 0; i < g_maxplayers; i++) {
1862 if ((gamestate == GS_LEVEL) && playeringame[i] && (players[i].mo != NULL)) {
1863 players[i].mo->flags &= ~MF_TRANSLATION;
1864 players[i].mo->flags |= ((uint64_t)playernumtotrans[i]) << MF_TRANSSHIFT;
1865 }
1866 }
1867 }
1868
1869 //
1870 // G_PlayerReborn
1871 // Called after a player dies
1872 // almost everything is cleared and initialized
1873 //
1874
1875 void G_PlayerReborn (int player)
1876 {
1877 player_t *p;
1878 int frags[MAX_MAXPLAYERS];
1879 int killcount;
1880 int itemcount;
1881 int secretcount;
1882 int maxkilldiscount; //e6y
1883 unsigned int worldTimer;
1884
1885 memcpy (frags, players[player].frags, sizeof frags);
1886 killcount = players[player].killcount;
1887 itemcount = players[player].itemcount;
1888 secretcount = players[player].secretcount;
1889 maxkilldiscount = players[player].maxkilldiscount; //e6y
1890 worldTimer = players[player].worldTimer;
1891
1892 p = &players[player];
1893
1894 // killough 3/10/98,3/21/98: preserve cheats across idclev
1895 {
1896 int cheats = p->cheats;
1897 memset (p, 0, sizeof(*p));
1898 p->cheats = cheats;
1899 }
1900
1901 memcpy(players[player].frags, frags, sizeof(players[player].frags));
1902 players[player].killcount = killcount;
1903 players[player].itemcount = itemcount;
1904 players[player].secretcount = secretcount;
1905 players[player].maxkilldiscount = maxkilldiscount; //e6y
1906 players[player].worldTimer = worldTimer;
1907 players[player].pclass = PlayerClass[player];
1908
1909 p->usedown = p->attackdown = true; // don't do anything immediately
1910 p->playerstate = PST_LIVE;
1911
1912 G_SetInitialHealth(p);
1913 G_SetInitialInventory(p);
1914
1915 p->lookdir = 0;
1916 localQuakeHappening[player] = false;
1917 if (p == &players[consoleplayer])
1918 {
1919 SB_Start(); // refresh the status bar
1920 inv_ptr = 0; // reset the inventory pointer
1921 curpos = 0;
1922 }
1923
1924 levels_completed = 0;
1925 }
1926
1927 //
1928 // G_CheckSpot
1929 // Returns false if the player cannot be respawned
1930 // at the given mapthing_t spot
1931 // because something is occupying it
1932 //
1933
1934 static dboolean G_CheckSpot(int playernum, mapthing_t *mthing)
1935 {
1936 fixed_t x,y;
1937 sector_t *sec;
1938 int i;
1939
1940 if (!players[playernum].mo)
1941 {
1942 // first spawn of level, before corpses
1943 for (i=0 ; i<playernum ; i++)
1944 if (players[i].mo->x == mthing->x && players[i].mo->y == mthing->y)
1945 return false;
1946 return true;
1947 }
1948
1949 x = mthing->x;
1950 y = mthing->y;
1951
1952 if (raven)
1953 {
1954 unsigned an;
1955 mobj_t *mo;
1956
1957 players[playernum].mo->flags2 &= ~MF2_PASSMOBJ;
1958 if (!P_CheckPosition(players[playernum].mo, x, y))
1959 {
1960 players[playernum].mo->flags2 |= MF2_PASSMOBJ;
1961 return false;
1962 }
1963 players[playernum].mo->flags2 |= MF2_PASSMOBJ;
1964
1965 // spawn a teleport fog
1966 sec = R_PointInSector(x, y);
1967 an = ((unsigned) ANG45 * (mthing->angle / 45)) >> ANGLETOFINESHIFT;
1968
1969 mo = P_SpawnMobj(x + 20 * finecosine[an], y + 20 * finesine[an],
1970 sec->floorheight + TELEFOGHEIGHT, g_mt_tfog);
1971
1972 if (players[consoleplayer].viewz != 1)
1973 S_StartMobjSound(mo, g_sfx_telept); // don't start sound on first frame
1974
1975 return true;
1976 }
1977
1978 // killough 4/2/98: fix bug where P_CheckPosition() uses a non-solid
1979 // corpse to detect collisions with other players in DM starts
1980 //
1981 // Old code:
1982 // if (!P_CheckPosition (players[playernum].mo, x, y))
1983 // return false;
1984
1985 players[playernum].mo->flags |= MF_SOLID;
1986 i = P_CheckPosition(players[playernum].mo, x, y);
1987 players[playernum].mo->flags &= ~MF_SOLID;
1988 if (!i)
1989 return false;
1990
1991 {
1992 void A_AddPlayerCorpse(mobj_t * actor);
1993
1994 A_AddPlayerCorpse(players[playernum].mo);
1995 }
1996
1997 // spawn a teleport fog
1998 sec = R_PointInSector (x,y);
1999 { // Teleport fog at respawn point
2000 fixed_t xa,ya;
2001 int an;
2002 mobj_t *mo;
2003
2004 /* BUG: an can end up negative, because mthing->angle is (signed) short.
2005 * We have to emulate original Doom's behaviour, deferencing past the start
2006 * of the array, into the previous array (finetangent) */
2007 an = ( ANG45 * ((signed)mthing->angle/45) ) >> ANGLETOFINESHIFT;
2008 xa = finecosine[an];
2009 ya = finesine[an];
2010
2011 if (compatibility_level <= finaldoom_compatibility || compatibility_level == prboom_4_compatibility)
2012 switch (an) {
2013 case -4096: xa = finetangent[2048]; // finecosine[-4096]
2014 ya = finetangent[0]; // finesine[-4096]
2015 break;
2016 case -3072: xa = finetangent[3072]; // finecosine[-3072]
2017 ya = finetangent[1024]; // finesine[-3072]
2018 break;
2019 case -2048: xa = finesine[0]; // finecosine[-2048]
2020 ya = finetangent[2048]; // finesine[-2048]
2021 break;
2022 case -1024: xa = finesine[1024]; // finecosine[-1024]
2023 ya = finetangent[3072]; // finesine[-1024]
2024 break;
2025 case 1024:
2026 case 2048:
2027 case 3072:
2028 case 4096:
2029 case 0: break; /* correct angles set above */
2030 default: I_Error("G_CheckSpot: unexpected angle %d\n",an);
2031 }
2032
2033 mo = P_SpawnMobj(x+20*xa, y+20*ya, sec->floorheight, MT_TFOG);
2034
2035 if (players[consoleplayer].viewz != 1)
2036 S_StartMobjSound(mo, sfx_telept); // don't start sound on first frame
2037 }
2038
2039 return true;
2040 }
2041
2042
2043 // G_DeathMatchSpawnPlayer
2044 // Spawns a player at one of the random death match spots
2045 // called at level load and each death
2046 //
2047 void G_DeathMatchSpawnPlayer (int playernum)
2048 {
2049 int j, selections = deathmatch_p - deathmatchstarts;
2050
2051 if (selections < g_maxplayers)
2052 I_Error("G_DeathMatchSpawnPlayer: Only %i deathmatch spots, %d required",
2053 selections, g_maxplayers);
2054
2055 for (j=0 ; j<20 ; j++)
2056 {
2057 int i = P_Random(pr_dmspawn) % selections;
2058 if (G_CheckSpot (playernum, &deathmatchstarts[i]) )
2059 {
2060 deathmatchstarts[i].type = playernum+1;
2061 P_SpawnPlayer (playernum, &deathmatchstarts[i]);
2062 return;
2063 }
2064 }
2065
2066 // no good spot, so the player will probably get stuck
2067 P_SpawnPlayer (playernum, &playerstarts[0][playernum]);
2068 }
2069
2070 //
2071 // G_DoReborn
2072 //
2073
2074 void G_DoReborn (int playernum)
2075 {
2076 dsda_WatchReborn(playernum);
2077
2078 if (hexen)
2079 return Hexen_G_DoReborn(playernum);
2080
2081 if (!netgame && !(map_info.flags & MI_ALLOW_RESPAWN) && !(skill_info.flags & SI_PLAYER_RESPAWN))
2082 gameaction = ga_loadlevel; // reload the level from scratch
2083 else
2084 { // respawn at the start
2085 int i;
2086
2087 // first dissasociate the corpse
2088 players[playernum].mo->player = NULL;
2089
2090 // spawn at random spot if in death match
2091 if (deathmatch)
2092 {
2093 G_DeathMatchSpawnPlayer (playernum);
2094 return;
2095 }
2096
2097 if (G_CheckSpot (playernum, &playerstarts[0][playernum]) )
2098 {
2099 P_SpawnPlayer (playernum, &playerstarts[0][playernum]);
2100 return;
2101 }
2102
2103 // try to spawn at one of the other players spots
2104 for (i = 0; i < g_maxplayers; i++)
2105 {
2106 if (G_CheckSpot (playernum, &playerstarts[0][i]) )
2107 {
2108 P_SpawnPlayer (playernum, &playerstarts[0][i]);
2109 return;
2110 }
2111 // he's going to be inside something. Too bad.
2112 }
2113 P_SpawnPlayer (playernum, &playerstarts[0][playernum]);
2114 }
2115 }
2116
2117 // DOOM Par Times
2118 int pars[5][10] = {
2119 {0},
2120 {0,30,75,120,90,165,180,180,30,165},
2121 {0,90,90,90,120,90,360,240,30,170},
2122 {0,90,45,90,150,90,90,165,30,135},
2123 // from Doom 3 BFG Edition
2124 {0,165,255,135,150,180,390,135,360,180}
2125 };
2126
2127 // DOOM II Par Times
2128 int cpars[34] = {
2129 30,90,120,120,90,150,120,120,270,90, // 1-10
2130 210,150,150,150,210,150,420,150,210,150, // 11-20
2131 240,150,180,150,150,300,330,420,300,180, // 21-30
2132 120,30,30,30 // 31-34
2133 };
2134
2135 dboolean secretexit;
2136
2137 void G_ExitLevel(int position)
2138 {
2139 secretexit = false;
2140 gameaction = ga_completed;
2141 dsda_UpdateLeaveData(0, position, 0, 0);
2142 }
2143
2144 // Here's for the german edition.
2145 // IF NO WOLF3D LEVELS, NO SECRET EXIT!
2146
2147 void G_SecretExitLevel(int position)
2148 {
2149 if (gamemode!=commercial || haswolflevels)
2150 secretexit = true;
2151 else
2152 secretexit = false;
2153 gameaction = ga_completed;
2154 dsda_UpdateLeaveData(0, position, 0, 0);
2155 }
2156
2157 //
2158 // G_DoCompleted
2159 //
2160
2161 void G_DoCompleted (void)
2162 {
2163 int i;
2164 int completed_behaviour;
2165
2166 R_ResetColorMap();
2167
2168 if (hexen)
2169 totalleveltimes = players[consoleplayer].worldTimer;
2170 else
2171 totalleveltimes += leveltime - leveltime % 35;
2172 ++levels_completed;
2173
2174 gameaction = ga_nothing;
2175
2176 for (i = 0; i < g_maxplayers; i++)
2177 if (playeringame[i])
2178 G_PlayerFinishLevel(i); // take away cards and stuff
2179
2180 AM_Stop(false);
2181
2182 e6y_G_DoCompleted();
2183 dsda_WatchLevelCompletion();
2184
2185 wminfo.nextep = wminfo.epsd = gameepisode -1;
2186 wminfo.last = gamemap -1;
2187
2188 dsda_UpdateLastMapInfo();
2189
2190 dsda_PrepareIntermission(&completed_behaviour);
2191
2192 if (completed_behaviour & DC_VICTORY)
2193 {
2194 gameaction = ga_victory;
2195 return;
2196 }
2197
2198 dsda_UpdateNextMapInfo();
2199 wminfo.maxkills = totalkills;
2200 wminfo.maxitems = totalitems;
2201 wminfo.maxsecret = totalsecret;
2202 wminfo.maxfrags = 0;
2203 wminfo.pnum = consoleplayer;
2204
2205 for (i = 0; i < g_maxplayers; i++)
2206 {
2207 wminfo.plyr[i].in = playeringame[i];
2208 wminfo.plyr[i].skills = players[i].killcount;
2209 wminfo.plyr[i].sitems = players[i].itemcount;
2210 wminfo.plyr[i].ssecret = players[i].secretcount;
2211 wminfo.plyr[i].stime = leveltime;
2212 memcpy (wminfo.plyr[i].frags, players[i].frags,
2213 sizeof(wminfo.plyr[i].frags));
2214 }
2215
2216 wminfo.totaltimes = totalleveltimes;
2217
2218 gamestate = GS_INTERMISSION;
2219 automap_active = false;
2220
2221 // lmpwatch.pl engine-side demo testing support
2222 // print "FINISHED: <mapname>" when the player exits the current map
2223 if (nodrawers && (demoplayback || timingdemo))
2224 lprintf(LO_INFO, "FINISHED: %s\n", dsda_MapLumpName(gameepisode, gamemap));
2225
2226 if (!(map_info.flags & MI_INTERMISSION))
2227 {
2228 G_WorldDone();
2229 }
2230 else
2231 {
2232 WI_Start (&wminfo);
2233 }
2234 }
2235
2236 //
2237 // G_WorldDone
2238 //
2239
2240 void G_WorldDone (void)
2241 {
2242 int done_behaviour;
2243
2244 gameaction = ga_worlddone;
2245
2246 if (secretexit)
2247 players[consoleplayer].didsecret = true;
2248
2249 dsda_PrepareFinale(&done_behaviour);
2250
2251 if (done_behaviour & WD_VICTORY)
2252 {
2253 if (dsda_Flag(dsda_arg_chain_episodes))
2254 {
2255 int epi, map;
2256
2257 dsda_NextMap(&epi, &map);
2258
2259 if (epi != 1 || map != 1)
2260 {
2261 int i;
2262
2263 for (i = 0; i < g_maxplayers; ++i)
2264 if (playeringame[i])
2265 players[i].playerstate = PST_DEAD;
2266
2267 wminfo.nextep = epi - 1;
2268 wminfo.next = map - 1;
2269
2270 return;
2271 }
2272 }
2273
2274 gameaction = ga_victory;
2275
2276 return;
2277 }
2278
2279 if (done_behaviour & WD_START_FINALE)
2280 {
2281 F_StartFinale();
2282
2283 return;
2284 }
2285 }
2286
2287 void G_DoWorldDone (void)
2288 {
2289 idmusnum = -1; //jff 3/17/98 allow new level's music to be loaded
2290 gamestate = GS_LEVEL;
2291 dsda_UpdateGameMap(wminfo.nextep + 1, wminfo.next + 1);
2292 G_DoLoadLevel();
2293 gameaction = ga_nothing;
2294 AM_clearMarks(); //jff 4/12/98 clear any marks on the automap
2295 dsda_EvaluateSkipModeDoWorldDone();
2296 }
2297
2298 extern dboolean setsizeneeded;
2299
2300 //CPhipps - savename variable redundant
2301
2302 /* killough 12/98:
2303 * This function returns a signature for the current wad.
2304 * It is used to distinguish between wads, for the purposes
2305 * of savegame compatibility warnings, and options lookups.
2306 */
2307
2308 static uint64_t G_UpdateSignature(uint64_t s, const char *name)
2309 {
2310 int i, lump = W_CheckNumForName(name);
2311 if (lump != LUMP_NOT_FOUND && (i = lump+10) < numlumps)
2312 do
2313 {
2314 int size = W_LumpLength(i);
2315 const byte *p = W_LumpByNum(i);
2316 while (size--)
2317 s <<= 1, s += *p++;
2318 }
2319 while (--i > lump);
2320 return s;
2321 }
2322
2323 static uint64_t G_Signature(void)
2324 {
2325 static uint64_t s = 0;
2326 static dboolean computed = false;
2327 int episode, map;
2328
2329 if (!computed) {
2330 computed = true;
2331 if (gamemode == commercial)
2332 for (map = haswolflevels ? 32 : 30; map; map--)
2333 s = G_UpdateSignature(s, dsda_MapLumpName(1, map));
2334 else
2335 for (episode = gamemode==retail ? 4 :
2336 gamemode==shareware ? 1 : 3; episode; episode--)
2337 for (map = 9; map; map--)
2338 s = G_UpdateSignature(s, dsda_MapLumpName(episode, map));
2339 }
2340 return s;
2341 }
2342
2343 //
2344 // killough 5/15/98: add forced loadgames, which allow user to override checks
2345 //
2346
2347 void G_ForcedLoadGame(void)
2348 {
2349 // CPhipps - net loadgames are always forced, so we only reach here
2350 // in single player
2351 gameaction = ga_loadgame;
2352 forced_loadgame = true;
2353 }
2354
2355 // killough 3/16/98: add slot info
2356 void G_LoadGame(int slot)
2357 {
2358 if (demorecording)
2359 {
2360 dsda_QueueExCmdLoad(slot);
2361 return;
2362 }
2363
2364 if (!demoplayback)
2365 {
2366 forced_loadgame = netgame; // CPhipps - always force load netgames
2367 }
2368 else
2369 {
2370 dsda_ClearPlaybackStream();
2371 forced_loadgame = false;
2372 // Don't stay in netgame state if loading single player save
2373 // while watching multiplayer demo
2374 netgame = false;
2375 }
2376
2377 gameaction = ga_loadgame;
2378 savegameslot = slot;
2379 load_via_cmd = false;
2380 R_SmoothPlaying_Reset(NULL); // e6y
2381 }
2382
2383 // killough 5/15/98:
2384 // Consistency Error when attempting to load savegame.
2385
2386 static void G_LoadGameErr(const char *msg)
2387 {
2388 P_FreeSaveBuffer();
2389 M_ForcedLoadGame(msg); // Print message asking for 'Y' to force
2390 }
2391
2392 const char * comp_lev_str[MAX_COMPATIBILITY_LEVEL] =
2393 { "Doom v1.2", "Doom v1.666", "Doom/Doom2 v1.9", "Ultimate Doom/Doom95", "Final Doom",
2394 "early DosDoom", "TASDoom", "\"boom compatibility\"", "boom v2.01", "boom v2.02", "lxdoom v1.3.2+",
2395 "MBF", "PrBoom 2.03beta", "PrBoom v2.1.0-2.1.1", "PrBoom v2.1.2-v2.2.6",
2396 "PrBoom v2.3.x", "PrBoom 2.4.0", "Current PrBoom", "", "", "", "MBF21" };
2397
2398 const char * hexen_skill_fighter[5] = { "SQUIRE", "KNIGHT", "WARRIOR", "BERSERKER", "TITAN" };
2399 const char * hexen_skill_cleric[5] = { "ALTAR BOY", "ACOLYTE", "PRIEST", "CARDINAL", "POPE" };
2400 const char * hexen_skill_mage[5] = { "APPRENTICE", "ENCHANTER", "SORCERER", "WARLOCK", "ARCHIMAGE" };
2401
2402 //==========================================================================
2403 //
2404 // RecalculateDrawnSubsectors
2405 //
2406 // In case the subsector data is unusable this function tries to reconstruct
2407 // if from the linedefs' ML_MAPPED info.
2408 //
2409 //==========================================================================
2410
2411 void RecalculateDrawnSubsectors(void)
2412 {
2413 int i, j;
2414
2415 for (i = 0; i < numsubsectors; i++)
2416 {
2417 subsector_t *sub = &subsectors[i];
2418 seg_t *seg = &segs[sub->firstline];
2419 for (j = 0; j < sub->numlines; j++, seg++)
2420 {
2421 if (seg->linedef && seg->linedef->flags & ML_MAPPED)
2422 {
2423 map_subsectors[i] = 1;
2424 }
2425 }
2426 }
2427
2428 gld_ResetTexturedAutomap();
2429 }
2430
2431 void G_AfterLoad(void)
2432 {
2433 extern int BorderNeedRefresh;
2434
2435 dsda_ResetTrackers();
2436
2437 R_ActivateSectorInterpolations(); //e6y
2438 R_SmoothPlaying_Reset(NULL); // e6y
2439
2440 RecalculateDrawnSubsectors();
2441
2442 if (hexen)
2443 {
2444 SB_SetClassData();
2445 }
2446
2447 if (raven)
2448 {
2449 players[consoleplayer].readyArtifact = players[consoleplayer].inventory[inv_ptr].type;
2450 }
2451
2452 if (setsizeneeded)
2453 R_ExecuteSetViewSize ();
2454
2455 BorderNeedRefresh = true;
2456 ST_Start();
2457 }
2458
2459 void G_DoLoadGame(void)
2460 {
2461 int length;
2462 // CPhipps - do savegame filename stuff here
2463 char *name; // killough 3/22/98
2464 int saveversion;
2465
2466 dsda_SetLastLoadSlot(savegameslot);
2467
2468 name = dsda_SaveGameName(savegameslot, load_via_cmd);
2469
2470 // [crispy] loaded game must always be single player.
2471 // Needed for ability to use a further game loading, as well as
2472 // cheat codes and other single player only specifics.
2473 if (!load_via_cmd)
2474 {
2475 netgame = false;
2476 deathmatch = false;
2477 }
2478
2479 gameaction = ga_nothing;
2480
2481 length = M_ReadFile(name, &savebuffer);
2482 if (length<=0)
2483 I_Error("Couldn't read file %s: %s", name, "(Unknown Error)");
2484 Z_Free(name);
2485 save_p = savebuffer + SAVESTRINGSIZE;
2486
2487 P_LOAD_X(saveversion);
2488 if (saveversion != SAVEVERSION && !forced_loadgame) {
2489 G_LoadGameErr("Unrecognised savegame version!\nAre you sure? (y/n) ");
2490 return;
2491 }
2492
2493 // CPhipps - always check savegames even when forced,
2494 // only print a warning if forced
2495 { // killough 3/16/98: check lump name checksum (independent of order)
2496 uint64_t checksum;
2497
2498 P_LOAD_X(checksum);
2499
2500 if (checksum != G_Signature() && !forced_loadgame)
2501 {
2502 char *msg = Z_Malloc(strlen((char *) save_p) + 128);
2503
2504 strcpy(msg, "Incompatible Savegame!!!\n");
2505 if (*save_p)
2506 strcat(strcat(msg, "Wads expected:\n\n"), (char *) save_p);
2507 strcat(msg, "\nAre you sure?");
2508
2509 G_LoadGameErr(msg);
2510
2511 Z_Free(msg);
2512
2513 return;
2514 }
2515 }
2516
2517 save_p += strlen((char*) save_p) + 1;
2518
2519 // dearchive all the modifications
2520 dsda_UnArchiveAll();
2521
2522 if (*save_p != 0xe6)
2523 I_Error ("G_DoLoadGame: Bad savegame");
2524
2525 G_AfterLoad();
2526
2527 P_FreeSaveBuffer();
2528 }
2529
2530 //
2531 // G_SaveGame
2532 // Called by the menu task.
2533 // Description is a 24 byte text string
2534 //
2535
2536 void G_SaveGame(int slot, const char *description)
2537 {
2538 strcpy(savedescription, description);
2539
2540 if (demorecording && dsda_AllowCasualExCmdFeatures())
2541 {
2542 dsda_QueueExCmdSave(slot);
2543 }
2544 else
2545 {
2546 savegameslot = slot;
2547 G_DoSaveGame(false);
2548 }
2549 }
2550
2551 static void G_DoSaveGame(dboolean via_cmd)
2552 {
2553 char *name;
2554 char *description;
2555 int saveversion;
2556 uint64_t checksum;
2557 const char *maplump;
2558 int time, ttime;
2559
2560 gameaction = ga_nothing; // cph - cancel savegame at top of this function,
2561 // in case later problems cause a premature exit
2562
2563 dsda_SetLastSaveSlot(savegameslot);
2564
2565 name = dsda_SaveGameName(savegameslot, via_cmd);
2566
2567 description = savedescription;
2568 saveversion = SAVEVERSION;
2569
2570 P_InitSaveBuffer();
2571
2572 P_SAVE_SIZE(description, SAVESTRINGSIZE);
2573 P_SAVE_X(saveversion);
2574
2575 /* killough 3/16/98, 12/98: store lump name checksum */
2576 checksum = G_Signature();
2577 P_SAVE_X(checksum);
2578
2579 // killough 3/16/98: store pwad filenames in savegame
2580 {
2581 // CPhipps - changed for new wadfiles handling
2582 size_t i;
2583 for (i = 0; i<numwadfiles; i++)
2584 {
2585 const char *const w = wadfiles[i].name;
2586 size_t size = strlen(w);
2587
2588 P_SAVE_SIZE(w, size);
2589 P_SAVE_BYTE('\n');
2590 }
2591 P_SAVE_BYTE(0);
2592 }
2593
2594 dsda_ArchiveAll();
2595
2596 P_SAVE_BYTE(0xe6); // consistency marker
2597
2598 doom_printf( "%s", M_WriteFile(name, savebuffer, save_p - savebuffer)
2599 ? s_GGSAVED /* Ty - externalised */
2600 : "Game save failed!"); // CPhipps - not externalised
2601
2602 /* Print some information about the save game */
2603 maplump = dsda_MapLumpName(gameepisode, gamemap);
2604 time = leveltime / TICRATE;
2605 ttime = (totalleveltimes + leveltime) / TICRATE;
2606
2607 lprintf(LO_INFO, "G_DoSaveGame: [%d] %s (%s), Skill %d, Level Time %02d:%02d:%02d, Total Time %02d:%02d:%02d\n",
2608 savegameslot + 1, maplump, W_GetLumpInfoByNum(W_GetNumForName(maplump))->wadfile->name, gameskill + 1,
2609 time/3600, (time%3600)/60, time%60, ttime/3600, (ttime%3600)/60, ttime%60);
2610
2611 P_FreeSaveBuffer();
2612
2613 savedescription[0] = 0;
2614 Z_Free(name);
2615 }
2616
2617 static int d_skill;
2618 static int d_episode;
2619 static int d_map;
2620
2621 void G_DeferedInitNew(int skill, int episode, int map)
2622 {
2623 d_skill = skill;
2624 d_episode = episode;
2625 d_map = map;
2626 gameaction = ga_newgame;
2627
2628 dsda_WatchDeferredInitNew(skill, episode, map);
2629 }
2630
2631 /* cph -
2632 * G_Compatibility
2633 *
2634 * Initialises the comp[] array based on the compatibility_level
2635 * For reference, MBF did:
2636 * for (i=0; i < COMP_TOTAL; i++)
2637 * comp[i] = compatibility;
2638 *
2639 * Instead, we have a lookup table showing at what version a fix was
2640 * introduced, and made optional (replaces comp_options_by_version)
2641 */
2642
2643 void G_Compatibility(void)
2644 {
2645 static const struct {
2646 complevel_t fix; // level at which fix/change was introduced
2647 complevel_t opt; // level at which fix/change was made optional
2648 } levels[] = {
2649 // comp_telefrag - monsters used to telefrag only on MAP30, now they do it for spawners only
2650 { mbf_compatibility, mbf_compatibility },
2651 // comp_dropoff - MBF encourages things to drop off of overhangs
2652 { mbf_compatibility, mbf_compatibility },
2653 // comp_vile - original Doom archville bugs like ghosts
2654 { boom_compatibility, mbf_compatibility },
2655 // comp_pain - original Doom limits Pain Elementals from spawning too many skulls
2656 { boom_compatibility, mbf_compatibility },
2657 // comp_skull - original Doom let skulls be spit through walls by Pain Elementals
2658 { boom_compatibility, mbf_compatibility },
2659 // comp_blazing - original Doom duplicated blazing door sound
2660 { boom_compatibility, mbf_compatibility },
2661 // e6y: "Tagged doors don't trigger special lighting" handled wrong
2662 // http://sourceforge.net/tracker/index.php?func=detail&aid=1411400&group_id=148658&atid=772943
2663 // comp_doorlight - MBF made door lighting changes more gradual
2664 { boom_compatibility, mbf_compatibility },
2665 // comp_model - improvements to the game physics
2666 { boom_compatibility, mbf_compatibility },
2667 // comp_god - fixes to God mode
2668 { boom_compatibility, mbf_compatibility },
2669 // comp_falloff - MBF encourages things to drop off of overhangs
2670 { mbf_compatibility, mbf_compatibility },
2671 // comp_floors - fixes for moving floors bugs
2672 { boom_compatibility_compatibility, mbf_compatibility },
2673 // comp_skymap
2674 { mbf_compatibility, mbf_compatibility },
2675 // comp_pursuit - MBF AI change, limited pursuit?
2676 { mbf_compatibility, mbf_compatibility },
2677 // comp_doorstuck - monsters stuck in doors fix
2678 { boom_202_compatibility, mbf_compatibility },
2679 // comp_staylift - MBF AI change, monsters try to stay on lifts
2680 { mbf_compatibility, mbf_compatibility },
2681 // comp_zombie - prevent dead players triggering stuff
2682 { lxdoom_1_compatibility, mbf_compatibility },
2683 // comp_stairs - see p_floor.c
2684 { boom_202_compatibility, mbf_compatibility },
2685 // comp_infcheat - FIXME
2686 { mbf_compatibility, mbf_compatibility },
2687 // comp_zerotags - allow zero tags in wads */
2688 { boom_compatibility, mbf_compatibility },
2689 // comp_moveblock - enables keygrab and mancubi shots going thru walls
2690 { lxdoom_1_compatibility, prboom_2_compatibility },
2691 // comp_respawn - objects which aren't on the map at game start respawn at (0,0)
2692 { prboom_2_compatibility, prboom_2_compatibility },
2693 // comp_sound - see s_sound.c
2694 { boom_compatibility_compatibility, prboom_3_compatibility },
2695 // comp_666 - emulate pre-Ultimate BossDeath behaviour
2696 { ultdoom_compatibility, prboom_4_compatibility },
2697 // comp_soul - enables lost souls bouncing (see P_ZMovement)
2698 { prboom_4_compatibility, prboom_4_compatibility },
2699 // comp_maskedanim - 2s mid textures don't animate
2700 { doom_1666_compatibility, prboom_4_compatibility },
2701 //e6y
2702 // comp_ouchface - Use Doom's buggy "Ouch" face code
2703 { prboom_1_compatibility, prboom_6_compatibility },
2704 // comp_maxhealth - Max Health in DEH applies only to potions
2705 { boom_compatibility_compatibility, prboom_6_compatibility },
2706 // comp_translucency - No predefined translucency for some things
2707 { boom_compatibility_compatibility, prboom_6_compatibility },
2708 // comp_ledgeblock - ground monsters are blocked by ledges
2709 { boom_compatibility, mbf21_compatibility },
2710 // comp_friendlyspawn - A_Spawn new mobj inherits friendliness
2711 { prboom_1_compatibility, mbf21_compatibility },
2712 // comp_voodooscroller - Voodoo dolls on slow scrollers move too slowly
2713 { mbf21_compatibility, mbf21_compatibility },
2714 // comp_reservedlineflag - ML_RESERVED clears extended flags
2715 { mbf21_compatibility, mbf21_compatibility }
2716 };
2717 unsigned int i;
2718
2719 if (sizeof(levels)/sizeof(*levels) != MBF_COMP_TOTAL)
2720 I_Error("G_Compatibility: consistency error");
2721
2722 for (i = 0; i < sizeof(levels)/sizeof(*levels); i++)
2723 if (compatibility_level < levels[i].opt)
2724 comp[i] = (compatibility_level < levels[i].fix);
2725
2726 // These options were deoptionalized in mbf21
2727 if (mbf21)
2728 {
2729 comp[comp_moveblock] = 0;
2730 comp[comp_sound] = 0;
2731 comp[comp_666] = 0;
2732 comp[comp_maskedanim] = 0;
2733 comp[comp_ouchface] = 0;
2734 comp[comp_maxhealth] = 0;
2735 comp[comp_translucency] = 0;
2736 }
2737
2738 e6y_G_Compatibility();//e6y
2739
2740 if (!mbf_features) {
2741 monster_infighting = 1;
2742 monster_backing = 0;
2743 monster_avoid_hazards = 0;
2744 monster_friction = 0;
2745 help_friends = 0;
2746
2747 dogs = 0;
2748 dog_jumping = 0;
2749
2750 monkeys = 0;
2751 }
2752 }
2753
2754 // killough 3/1/98: function to reload all the default parameter
2755 // settings before a new game begins
2756
2757 void G_ReloadDefaults(void)
2758 {
2759 const dsda_options_t* options;
2760
2761 compatibility_level = dsda_IntConfig(dsda_config_default_complevel);
2762 {
2763 int l;
2764 l = dsda_CompatibilityLevel();
2765 if (l != UNSPECIFIED_COMPLEVEL)
2766 compatibility_level = l;
2767 else
2768 dsda_MarkCompatibilityLevelUnspecified();
2769 }
2770 if (compatibility_level == -1)
2771 compatibility_level = best_compatibility;
2772
2773 // killough 3/1/98: Initialize options based on config file
2774 // (allows functions above to load different values for demos
2775 // and savegames without messing up defaults).
2776
2777 // Allows PWAD HELP2 screen for DOOM 1 wads.
2778 // there's no easy way to set it only to complevel 0-2, so
2779 // I just allowed it for complevel 3 if HELP2 is present
2780 if ((compatibility_level <= 3) && (gamemode != commercial) && (gamemode != shareware) && !raven)
2781 pwad_help2_check = W_PWADLumpNameExists("HELP2");
2782
2783 options = dsda_Options();
2784
2785 weapon_recoil = options->weapon_recoil; // weapon recoil
2786
2787 player_bobbing = 1; // whether player bobs or not
2788
2789 variable_friction = 1;
2790 allow_pushers = 1;
2791 monsters_remember = options->monsters_remember; // remember former enemies
2792
2793 monster_infighting = options->monster_infighting; // killough 7/19/98
2794
2795 dogs = netgame ? 0 : options->player_helpers; // killough 7/19/98
2796 dog_jumping = options->dog_jumping;
2797
2798 distfriend = options->friend_distance; // killough 8/8/98
2799
2800 monster_backing = options->monster_backing; // killough 9/8/98
2801
2802 monster_avoid_hazards = options->monster_avoid_hazards; // killough 9/9/98
2803
2804 monster_friction = options->monster_friction; // killough 10/98
2805
2806 help_friends = options->help_friends; // killough 9/9/98
2807
2808 monkeys = options->monkeys;
2809
2810 // jff 1/24/98 reset play mode to command line spec'd version
2811 // killough 3/1/98: moved to here
2812 respawnparm = clrespawnparm;
2813 fastparm = clfastparm;
2814 nomonsters = clnomonsters;
2815
2816 dsda_ClearPlaybackStream();
2817
2818 // killough 2/21/98:
2819 memset(playeringame + 1, 0, sizeof(*playeringame) * (MAX_MAXPLAYERS - 1));
2820
2821 consoleplayer = 0;
2822
2823 // MBF introduced configurable compatibility settings
2824 if (mbf_features)
2825 {
2826 comp[comp_telefrag] = options->comp_telefrag;
2827 comp[comp_dropoff] = options->comp_dropoff;
2828 comp[comp_vile] = options->comp_vile;
2829 comp[comp_pain] = options->comp_pain;
2830 comp[comp_skull] = options->comp_skull;
2831 comp[comp_blazing] = options->comp_blazing;
2832 comp[comp_doorlight] = options->comp_doorlight;
2833 comp[comp_model] = options->comp_model;
2834 comp[comp_god] = options->comp_god;
2835 comp[comp_falloff] = options->comp_falloff;
2836 comp[comp_floors] = options->comp_floors;
2837 comp[comp_skymap] = options->comp_skymap;
2838 comp[comp_pursuit] = options->comp_pursuit;
2839 comp[comp_doorstuck] = options->comp_doorstuck;
2840 comp[comp_staylift] = options->comp_staylift;
2841 comp[comp_zombie] = options->comp_zombie;
2842 comp[comp_stairs] = options->comp_stairs;
2843 comp[comp_infcheat] = options->comp_infcheat;
2844 comp[comp_zerotags] = options->comp_zerotags;
2845
2846 comp[comp_moveblock] = options->comp_moveblock;
2847 comp[comp_respawn] = options->comp_respawn;
2848 comp[comp_sound] = options->comp_sound;
2849 comp[comp_666] = options->comp_666;
2850 comp[comp_soul] = options->comp_soul;
2851 comp[comp_maskedanim] = options->comp_maskedanim;
2852 comp[comp_ouchface] = options->comp_ouchface;
2853 comp[comp_maxhealth] = options->comp_maxhealth;
2854 comp[comp_translucency] = options->comp_translucency;
2855 comp[comp_ledgeblock] = options->comp_ledgeblock;
2856 comp[comp_friendlyspawn] = options->comp_friendlyspawn;
2857 comp[comp_voodooscroller] = options->comp_voodooscroller;
2858 comp[comp_reservedlineflag] = options->comp_reservedlineflag;
2859 }
2860
2861 G_Compatibility();
2862
2863 // killough 3/31/98, 4/5/98: demo sync insurance
2864 demo_insurance = 0;
2865
2866 rngseed += I_GetRandomTimeSeed() + gametic; // CPhipps
2867 }
2868
2869 void G_DoNewGame (void)
2870 {
2871 int realMap = d_map;
2872 int realEpisode = d_episode;
2873
2874 // e6y: allow new level's music to be loaded
2875 idmusnum = -1;
2876
2877 G_ReloadDefaults(); // killough 3/1/98
2878 netgame = solo_net;
2879 deathmatch = false;
2880
2881 dsda_NewGameMap(&realEpisode, &realMap);
2882 dsda_ResetLeaveData();
2883
2884 G_InitNew (d_skill, realEpisode, realMap, true);
2885 gameaction = ga_nothing;
2886
2887 dsda_WatchNewGame();
2888
2889 //jff 4/26/98 wake up the status bar in case were coming out of a DM demo
2890 ST_Start();
2891 walkcamera.type=0; //e6y
2892 }
2893
2894 // killough 4/10/98: New function to fix bug which caused Doom
2895 // lockups when idclev was used in conjunction with -fast.
2896
2897 void G_RefreshFastMonsters(void)
2898 {
2899 static int fast = 0; // remembers fast state
2900 int i;
2901 int fast_pending;
2902
2903 fast_pending = !!(skill_info.flags & SI_FAST_MONSTERS);
2904
2905 if (hexen)
2906 {
2907 return;
2908 }
2909
2910 if (heretic)
2911 {
2912 for (i = 0; MonsterMissileInfo[i].type != -1; i++)
2913 {
2914 mobjinfo[MonsterMissileInfo[i].type].speed =
2915 MonsterMissileInfo[i].speed[fast_pending] << FRACBITS;
2916 }
2917
2918 return;
2919 }
2920
2921 if (fast != fast_pending) { /* only change if necessary */
2922 for (i = 0; i < num_mobj_types; ++i)
2923 if (mobjinfo[i].altspeed != NO_ALTSPEED)
2924 {
2925 int swap = mobjinfo[i].speed;
2926 mobjinfo[i].speed = mobjinfo[i].altspeed;
2927 mobjinfo[i].altspeed = swap;
2928 }
2929
2930 if ((fast = fast_pending))
2931 {
2932 for (i = 0; i < num_states; i++)
2933 if (states[i].flags & STATEF_SKILL5FAST && (states[i].tics != 1 || demo_compatibility))
2934 states[i].tics >>= 1; // don't change 1->0 since it causes cycles
2935 }
2936 else
2937 {
2938 for (i = 0; i < num_states; i++)
2939 if (states[i].flags & STATEF_SKILL5FAST)
2940 states[i].tics <<= 1;
2941 }
2942 }
2943 }
2944
2945 int G_ValidateMapName(const char *mapname, int *pEpi, int *pMap)
2946 {
2947 // Check if the given map name can be expressed as a gameepisode/gamemap pair and be reconstructed from it.
2948 char lumpname[9], mapuname[9];
2949 int epi = -1, map = -1;
2950
2951 if (strlen(mapname) > 8) return 0;
2952 strncpy(mapuname, mapname, 8);
2953 mapuname[8] = 0;
2954 M_Strupr(mapuname);
2955
2956 if (gamemode != commercial)
2957 {
2958 if (sscanf(mapuname, "E%dM%d", &epi, &map) != 2) return 0;
2959 snprintf(lumpname, sizeof(lumpname), "E%dM%d", epi, map);
2960 }
2961 else
2962 {
2963 if (sscanf(mapuname, "MAP%d", &map) != 1) return 0;
2964 snprintf(lumpname, sizeof(lumpname), "MAP%02d", map);
2965 epi = 1;
2966 }
2967 if (pEpi) *pEpi = epi;
2968 if (pMap) *pMap = map;
2969 return !strcmp(mapuname, lumpname);
2970 }
2971
2972 //
2973 // G_InitNew
2974 // Can be called by the startup code or the menu task,
2975 // consoleplayer, displayplayer, playeringame[] should be set.
2976 //
2977
2978 extern int EpiCustom;
2979
2980 void G_InitNew(int skill, int episode, int map, dboolean prepare)
2981 {
2982 int i;
2983
2984 // e6y
2985 // This variable is for correct checking for upper limit of episode.
2986 // Ultimate Doom, Final Doom and Doom95 have
2987 // "if (episode == 0) episode = 3/4" check instead of
2988 // "if (episode > 3/4) episode = 3/4"
2989 dboolean fake_episode_check =
2990 compatibility_level == ultdoom_compatibility ||
2991 compatibility_level == finaldoom_compatibility;
2992
2993 in_game = true;
2994
2995 if (prepare)
2996 dsda_PrepareInitNew();
2997
2998 if (dsda_Paused())
2999 {
3000 dsda_ResetPauseMode();
3001 S_ResumeSound();
3002 }
3003
3004 if (episode < 1)
3005 episode = 1;
3006
3007 if (!W_LumpNameExists(dsda_MapLumpName(episode, map)))
3008 {
3009 if (heretic)
3010 {
3011 if (episode > 9)
3012 episode = 9;
3013 if (map < 1)
3014 map = 1;
3015 if (map > 9)
3016 map = 9;
3017 }
3018 else if (map_format.map99)
3019 {
3020 if (map < 1)
3021 map = 1;
3022 if (map > 99)
3023 map = 99;
3024 }
3025 else
3026 {
3027 //e6y: We need to remove the fourth episode for pre-ultimate complevels.
3028 if (compatibility_level < ultdoom_compatibility && episode > 3)
3029 {
3030 episode = 3;
3031 }
3032
3033 //e6y: DosDoom has only this check
3034 if (compatibility_level == dosdoom_compatibility)
3035 {
3036 if (gamemode == shareware)
3037 episode = 1; // only start episode 1 on shareware
3038 }
3039 else
3040 if (gamemode == retail)
3041 {
3042 // e6y: Ability to play any episode with Ultimate Doom,
3043 // Final Doom or Doom95 compatibility and -warp command line switch
3044 // E5M1 from 2002ado.wad is an example.
3045 // Now you can play it with "-warp 5 1 -complevel 3".
3046 // 'Vanilla' Ultimate Doom executable also allows it.
3047 if (fake_episode_check ? episode == 0 : episode > 4)
3048 episode = 4;
3049 }
3050 else
3051 if (gamemode == shareware)
3052 {
3053 if (episode > 1)
3054 episode = 1; // only start episode 1 on shareware
3055 }
3056 else
3057 // e6y: Ability to play any episode with Ultimate Doom,
3058 // Final Doom or Doom95 compatibility and -warp command line switch
3059 if (fake_episode_check ? episode == 0 : episode > 3)
3060 episode = 3;
3061
3062 if (map < 1)
3063 map = 1;
3064 if (map > 9 && gamemode != commercial)
3065 map = 9;
3066 }
3067 }
3068
3069 {
3070 extern int dsda_startmap;
3071
3072 dsda_startmap = map;
3073 }
3074
3075 M_ClearRandom();
3076
3077 // force players to be initialized upon first level load
3078 for (i = 0; i < g_maxplayers; i++)
3079 {
3080 players[i].playerstate = PST_REBORN;
3081 players[i].worldTimer = 0;
3082 }
3083
3084 dsda_ResetPauseMode();
3085 dsda_ResetCommandHistory();
3086 automap_active = false;
3087 dsda_UpdateGameSkill(skill);
3088 dsda_UpdateGameMap(episode, map);
3089
3090 totalleveltimes = 0; // cph
3091 levels_completed = 0;
3092
3093 dsda_EvaluateSkipModeInitNew();
3094
3095 //jff 4/16/98 force marks on automap cleared every new level start
3096 AM_clearMarks();
3097
3098 dsda_InitSky();
3099
3100 G_DoLoadLevel ();
3101 }
3102
3103 //
3104 // DEMO RECORDING
3105 //
3106
3107 #define DEMOHEADER_RESPAWN 0x20
3108 #define DEMOHEADER_LONGTICS 0x10
3109 #define DEMOHEADER_NOMONSTERS 0x02
3110
3111 void G_ReadOneTick(ticcmd_t* cmd, const byte **data_p)
3112 {
3113 unsigned char at = 0; // e6y: for tasdoom demo format
3114
3115 cmd->forwardmove = (signed char)(*(*data_p)++);
3116 cmd->sidemove = (signed char)(*(*data_p)++);
3117 if (!longtics)
3118 {
3119 cmd->angleturn = ((unsigned char)(at = *(*data_p)++))<<8;
3120 }
3121 else
3122 {
3123 unsigned int lowbyte = (unsigned char)(*(*data_p)++);
3124 cmd->angleturn = (((signed int)(*(*data_p)++))<<8) + lowbyte;
3125 }
3126 cmd->buttons = (unsigned char)(*(*data_p)++);
3127
3128 if (raven)
3129 {
3130 cmd->lookfly = (unsigned char)(*(*data_p)++);
3131 cmd->arti = (unsigned char)(*(*data_p)++);
3132 }
3133
3134 // e6y: ability to play tasdoom demos directly
3135 if (compatibility_level == tasdoom_compatibility)
3136 {
3137 signed char tmp = cmd->forwardmove;
3138 cmd->forwardmove = cmd->sidemove;
3139 cmd->sidemove = (signed char)at;
3140 cmd->angleturn = ((unsigned char)cmd->buttons)<<8;
3141 cmd->buttons = (byte)tmp;
3142 }
3143
3144 dsda_ReadExCmd(cmd, data_p);
3145 }
3146
3147 /* Demo limits removed -- killough
3148 * cph - record straight to file
3149 */
3150 void G_WriteDemoTiccmd (ticcmd_t* cmd)
3151 {
3152 char buf[10];
3153 char *p = buf;
3154 const byte* data_p = (byte*)buf;
3155
3156 if (compatibility_level == tasdoom_compatibility)
3157 {
3158 *p++ = cmd->buttons;
3159 *p++ = cmd->forwardmove;
3160 *p++ = cmd->sidemove;
3161 *p++ = (cmd->angleturn+128)>>8;
3162 }
3163 else
3164 {
3165 *p++ = cmd->forwardmove;
3166 *p++ = cmd->sidemove;
3167 if (!longtics) {
3168 *p++ = (cmd->angleturn+128)>>8;
3169 } else {
3170 signed short a = cmd->angleturn;
3171 *p++ = a & 0xff;
3172 *p++ = (a >> 8) & 0xff;
3173 }
3174 *p++ = cmd->buttons;
3175
3176 if (raven)
3177 {
3178 *p++ = cmd->lookfly;
3179 *p++ = cmd->arti;
3180 }
3181 }
3182
3183 dsda_WriteExCmd(&p, cmd);
3184
3185 dsda_WriteTicToDemo(buf, p - buf);
3186
3187 G_ReadOneTick(cmd, &data_p);
3188 }
3189
3190 // These functions are used to read and write game-specific options in demos
3191 // and savegames so that demo sync is preserved and savegame restoration is
3192 // complete. Not all options (for example "compatibility"), however, should
3193 // be loaded and saved here. It is extremely important to use the same
3194 // positions as before for the variables, so if one becomes obsolete, the
3195 // byte(s) should still be skipped over or padded with 0's.
3196 // Lee Killough 3/1/98
3197
3198 byte *G_WriteOptions(byte *demo_p)
3199 {
3200 byte *target;
3201
3202 if (mbf21)
3203 {
3204 return dsda_WriteOptions21(demo_p);
3205 }
3206
3207 target = demo_p + dsda_GameOptionSize();
3208
3209 *demo_p++ = monsters_remember; // part of monster AI
3210
3211 *demo_p++ = variable_friction; // ice & mud
3212
3213 *demo_p++ = weapon_recoil; // weapon recoil
3214
3215 *demo_p++ = allow_pushers; // MT_PUSH Things
3216
3217 *demo_p++ = 0;
3218
3219 *demo_p++ = player_bobbing; // whether player bobs or not
3220
3221 // killough 3/6/98: add parameters to savegame, move around some in demos
3222 *demo_p++ = respawnparm;
3223 *demo_p++ = fastparm;
3224 *demo_p++ = nomonsters;
3225
3226 *demo_p++ = demo_insurance; // killough 3/31/98
3227
3228 // killough 3/26/98: Added rngseed. 3/31/98: moved here
3229 *demo_p++ = (byte)((rngseed >> 24) & 0xff);
3230 *demo_p++ = (byte)((rngseed >> 16) & 0xff);
3231 *demo_p++ = (byte)((rngseed >> 8) & 0xff);
3232 *demo_p++ = (byte)( rngseed & 0xff);
3233
3234 // Options new to v2.03 begin here
3235
3236 *demo_p++ = monster_infighting; // killough 7/19/98
3237
3238 *demo_p++ = dogs; // killough 7/19/98
3239
3240 *demo_p++ = 0;
3241 *demo_p++ = 0;
3242
3243 *demo_p++ = (distfriend >> 8) & 0xff; // killough 8/8/98
3244 *demo_p++ = distfriend & 0xff; // killough 8/8/98
3245
3246 *demo_p++ = monster_backing; // killough 9/8/98
3247
3248 *demo_p++ = monster_avoid_hazards; // killough 9/9/98
3249
3250 *demo_p++ = monster_friction; // killough 10/98
3251
3252 *demo_p++ = help_friends; // killough 9/9/98
3253
3254 *demo_p++ = dog_jumping;
3255
3256 *demo_p++ = monkeys;
3257
3258 { // killough 10/98: a compatibility vector now
3259 int i;
3260 for (i = 0; i < MBF_COMP_TOTAL; i++)
3261 *demo_p++ = comp[i] != 0;
3262 }
3263
3264 // unused forceOldBsp
3265 *demo_p++ = 0;
3266
3267 //----------------
3268 // Padding at end
3269 //----------------
3270 while (demo_p < target)
3271 *demo_p++ = 0;
3272
3273 if (demo_p != target)
3274 I_Error("G_WriteOptions: dsda_GameOptionSize is too small");
3275
3276 return target;
3277 }
3278
3279 /* Same, but read instead of write
3280 * cph - const byte*'s
3281 */
3282
3283 const byte *G_ReadOptions(const byte *demo_p)
3284 {
3285 const byte *target;
3286
3287 if (mbf21)
3288 {
3289 return dsda_ReadOptions21(demo_p);
3290 }
3291
3292 target = demo_p + dsda_GameOptionSize();
3293
3294 monsters_remember = *demo_p++;
3295
3296 variable_friction = *demo_p; // ice & mud
3297 demo_p++;
3298
3299 weapon_recoil = *demo_p; // weapon recoil
3300 demo_p++;
3301
3302 allow_pushers = *demo_p; // MT_PUSH Things
3303 demo_p++;
3304
3305 demo_p++;
3306
3307 player_bobbing = *demo_p; // whether player bobs or not
3308 demo_p++;
3309
3310 // killough 3/6/98: add parameters to savegame, move from demo
3311 respawnparm = *demo_p++;
3312 fastparm = *demo_p++;
3313 nomonsters = *demo_p++;
3314
3315 demo_insurance = *demo_p++; // killough 3/31/98
3316
3317 // killough 3/26/98: Added rngseed to demos; 3/31/98: moved here
3318
3319 rngseed = *demo_p++ & 0xff;
3320 rngseed <<= 8;
3321 rngseed += *demo_p++ & 0xff;
3322 rngseed <<= 8;
3323 rngseed += *demo_p++ & 0xff;
3324 rngseed <<= 8;
3325 rngseed += *demo_p++ & 0xff;
3326
3327 // Options new to v2.03
3328 if (mbf_features)
3329 {
3330 monster_infighting = *demo_p++; // killough 7/19/98
3331
3332 dogs = *demo_p++; // killough 7/19/98
3333
3334 demo_p += 2;
3335
3336 distfriend = *demo_p++ << 8; // killough 8/8/98
3337 distfriend+= *demo_p++;
3338
3339 monster_backing = *demo_p++; // killough 9/8/98
3340
3341 monster_avoid_hazards = *demo_p++; // killough 9/9/98
3342
3343 monster_friction = *demo_p++; // killough 10/98
3344
3345 help_friends = *demo_p++; // killough 9/9/98
3346
3347 dog_jumping = *demo_p++; // killough 10/98
3348
3349 monkeys = *demo_p++;
3350
3351 { // killough 10/98: a compatibility vector now
3352 int i;
3353 for (i = 0; i < MBF_COMP_TOTAL; i++)
3354 comp[i] = *demo_p++;
3355 }
3356
3357 // unused forceOldBsp
3358 demo_p++;
3359 }
3360 else /* defaults for versions <= 2.02 */
3361 {
3362 /* G_Compatibility will set these */
3363 }
3364
3365 G_Compatibility();
3366
3367 return target;
3368 }
3369
3370 void G_BeginRecording (void)
3371 {
3372 int i;
3373 byte *demostart, *demo_p;
3374 demostart = demo_p = Z_Malloc(1000);
3375 longtics = 0;
3376
3377 dsda_ResetDemoSaveSlots();
3378 dsda_ApplyDSDADemoFormat(&demo_p);
3379
3380 /* cph - 3 demo record formats supported: MBF+, BOOM, and Doom v1.9 */
3381 if (mbf_features) {
3382 { /* Write version code into demo */
3383 unsigned char v = 0;
3384 switch(compatibility_level) {
3385 case mbf_compatibility: v = 203; break; // e6y: Bug in MBF compatibility mode fixed
3386 case prboom_2_compatibility: v = 210; break;
3387 case prboom_3_compatibility: v = 211; break;
3388 case prboom_4_compatibility: v = 212; break;
3389 case prboom_5_compatibility: v = 213; break;
3390 case prboom_6_compatibility:
3391 v = 214;
3392 longtics = 1;
3393 break;
3394 case mbf21_compatibility:
3395 v = 221;
3396 longtics = 1;
3397 shorttics = !dsda_Flag(dsda_arg_longtics);
3398 break;
3399 default: I_Error("G_BeginRecording: PrBoom compatibility level unrecognised?");
3400 }
3401 *demo_p++ = v;
3402 }
3403
3404 // signature
3405 *demo_p++ = 0x1d;
3406 *demo_p++ = 'M';
3407 *demo_p++ = 'B';
3408 *demo_p++ = 'F';
3409 *demo_p++ = 0xe6;
3410 *demo_p++ = '\0';
3411
3412 if (!mbf21)
3413 {
3414 // boom compatibility mode flag, which has no meaning in mbf+
3415 *demo_p++ = 0;
3416 }
3417
3418 *demo_p++ = gameskill;
3419 *demo_p++ = gameepisode;
3420 *demo_p++ = gamemap;
3421 *demo_p++ = deathmatch;
3422 *demo_p++ = consoleplayer;
3423
3424 demo_p = G_WriteOptions(demo_p); // killough 3/1/98: Save game options
3425
3426 for (i = 0; i < g_maxplayers; i++)
3427 *demo_p++ = playeringame[i];
3428
3429 // killough 2/28/98:
3430 // We always store at least FUTURE_MAXPLAYERS bytes in demo, to
3431 // support enhancements later w/o losing demo compatibility
3432
3433 for (; i < FUTURE_MAXPLAYERS; i++)
3434 *demo_p++ = 0;
3435
3436 // FIXME } else if (compatibility_level >= boom_compatibility_compatibility) { //e6y
3437 } else if (compatibility_level > boom_compatibility_compatibility) {
3438 byte v = 0, c = 0; /* Nominally, version and compatibility bits */
3439 switch (compatibility_level) {
3440 case boom_compatibility_compatibility: v = 202, c = 1; break;
3441 case boom_201_compatibility: v = 201; c = 0; break;
3442 case boom_202_compatibility: v = 202, c = 0; break;
3443 default: I_Error("G_BeginRecording: Boom compatibility level unrecognised?");
3444 }
3445 *demo_p++ = v;
3446
3447 // signature
3448 *demo_p++ = 0x1d;
3449 *demo_p++ = 'B';
3450 *demo_p++ = 'o';
3451 *demo_p++ = 'o';
3452 *demo_p++ = 'm';
3453 *demo_p++ = 0xe6;
3454
3455 /* CPhipps - save compatibility level in demos */
3456 *demo_p++ = c;
3457
3458 *demo_p++ = gameskill;
3459 *demo_p++ = gameepisode;
3460 *demo_p++ = gamemap;
3461 *demo_p++ = deathmatch;
3462 *demo_p++ = consoleplayer;
3463
3464 demo_p = G_WriteOptions(demo_p); // killough 3/1/98: Save game options
3465
3466 for (i = 0; i < g_maxplayers; i++)
3467 *demo_p++ = playeringame[i];
3468
3469 // killough 2/28/98:
3470 // We always store at least FUTURE_MAXPLAYERS bytes in demo, to
3471 // support enhancements later w/o losing demo compatibility
3472
3473 for (; i < FUTURE_MAXPLAYERS; i++)
3474 *demo_p++ = 0;
3475 } else if (!raven) { // cph - write old v1.9 demos (might even sync)
3476 unsigned char v = 109;
3477 longtics = dsda_Flag(dsda_arg_longtics);
3478 if (longtics)
3479 {
3480 v = 111;
3481 }
3482 else
3483 {
3484 switch (compatibility_level)
3485 {
3486 case doom_1666_compatibility:
3487 v = 106;
3488 break;
3489 case tasdoom_compatibility:
3490 v = 110;
3491 break;
3492 }
3493 }
3494 *demo_p++ = v;
3495 *demo_p++ = gameskill;
3496 *demo_p++ = gameepisode;
3497 *demo_p++ = gamemap;
3498 *demo_p++ = deathmatch;
3499 *demo_p++ = respawnparm;
3500 *demo_p++ = fastparm;
3501 *demo_p++ = nomonsters;
3502 *demo_p++ = consoleplayer;
3503 for (i=0; i<4; i++) // intentionally hard-coded 4 -- killough
3504 *demo_p++ = playeringame[i];
3505 } else { // versionless raven
3506 *demo_p++ = gameskill;
3507 *demo_p++ = gameepisode;
3508 *demo_p++ = gamemap;
3509
3510 // Write special parameter bits onto player one byte.
3511 // This aligns with vvHeretic demo usage:
3512 // 0x20 = -respawn
3513 // 0x10 = -longtics
3514 // 0x02 = -nomonsters
3515 *demo_p = 1; // assume player one exists
3516 if (respawnparm)
3517 *demo_p |= DEMOHEADER_RESPAWN;
3518 if (longtics)
3519 *demo_p |= DEMOHEADER_LONGTICS;
3520 if (nomonsters)
3521 *demo_p |= DEMOHEADER_NOMONSTERS;
3522 demo_p++;
3523
3524 if (heretic)
3525 {
3526 for (i = 1; i < g_maxplayers; i++)
3527 *demo_p++ = playeringame[i];
3528 }
3529 else
3530 {
3531 *demo_p++ = PlayerClass[0] - 1;
3532 for (i = 1; i < g_maxplayers; i++)
3533 {
3534 *demo_p++ = playeringame[i];
3535 *demo_p++ = PlayerClass[i] - 1;
3536 }
3537 }
3538 }
3539
3540 dsda_EvaluateBytesPerTic();
3541
3542 dsda_WriteToDemo(demostart, demo_p - demostart);
3543 dsda_ContinueKeyFrame();
3544 dsda_ResetSplits();
3545
3546 Z_Free(demostart);
3547 }
3548
3549 //
3550 // G_PlayDemo
3551 //
3552
3553 static const char *defdemoname;
3554
3555 void G_DeferedPlayDemo (const char* name)
3556 {
3557 defdemoname = name;
3558 gameaction = ga_playdemo;
3559 }
3560
3561 static int G_GetOriginalDoomCompatLevel(int ver)
3562 {
3563 int level;
3564
3565 level = dsda_CompatibilityLevel();
3566 if (level >= 0) return level;
3567
3568 if (ver == 110) return tasdoom_compatibility;
3569 if (ver < 107) return doom_1666_compatibility;
3570 if (gamemode == retail) return ultdoom_compatibility;
3571 if (gamemission == pack_tnt || gamemission == pack_plut) return finaldoom_compatibility;
3572 return doom2_19_compatibility;
3573 }
3574
3575 //e6y: Check for overrun
3576 static dboolean CheckForOverrun(const byte *start_p, const byte *current_p, size_t maxsize, size_t size, dboolean failonerror)
3577 {
3578 size_t pos = current_p - start_p;
3579 if (pos + size > maxsize)
3580 {
3581 if (failonerror)
3582 I_Error("G_ReadDemoHeader: wrong demo header\n");
3583 else
3584 return true;
3585 }
3586 return false;
3587 }
3588
3589 const byte* G_ReadDemoHeaderEx(const byte *demo_p, size_t size, unsigned int params)
3590 {
3591 int skill;
3592 int i, episode = 1, map = 0;
3593
3594 // e6y
3595 // The local variable should be used instead of demobuffer,
3596 // because demobuffer can be uninitialized
3597 const byte *header_p = demo_p;
3598
3599 dboolean failonerror = (params&RDH_SAFE);
3600
3601 boom_basetic = gametic; // killough 9/29/98
3602 true_basetic = gametic;
3603
3604 // killough 2/22/98, 2/28/98: autodetect old demos and act accordingly.
3605 // Old demos turn on demo_compatibility => compatibility; new demos load
3606 // compatibility flag, and other flags as well, as a part of the demo.
3607
3608 //e6y: check for overrun
3609 if (CheckForOverrun(header_p, demo_p, size, 1, failonerror))
3610 return NULL;
3611
3612 dsda_DisableExCmd();
3613
3614 demover = *demo_p++;
3615 longtics = 0;
3616
3617 // defunct extended header or unknown (e.g., eternity)
3618 if (demover == 255)
3619 {
3620 demo_p = dsda_StripDemoVersion255(demo_p, header_p, size);
3621
3622 if (!demo_p)
3623 {
3624 if (failonerror)
3625 {
3626 I_Error("G_ReadDemoHeader: wrong demo header\n");
3627 }
3628 else
3629 {
3630 return NULL;
3631 }
3632 }
3633
3634 // update the start of the demo header
3635 size -= demo_p - header_p;
3636 header_p = demo_p;
3637
3638 if (CheckForOverrun(header_p, demo_p, size, 1, failonerror))
3639 return NULL;
3640
3641 demover = *demo_p++;
3642 }
3643
3644 // e6y
3645 // Handling of unrecognized demo formats
3646 // Versions up to 1.2 use a 7-byte header - first byte is a skill level.
3647 // Versions after 1.2 use a 13-byte header - first byte is a demoversion.
3648 // BOOM's demoversion starts from 200
3649 if (!((demover >= 0 && demover <= 4) ||
3650 (demover >= 104 && demover <= 111) ||
3651 (demover >= 200 && demover <= 214) ||
3652 (demover == 221)))
3653 {
3654 I_Error("G_ReadDemoHeader: Unknown demo format %d.", demover);
3655 }
3656
3657 if (demover < 200) // Autodetect old demos
3658 {
3659 if (demover >= 111) longtics = 1;
3660
3661 // killough 3/2/98: force these variables to be 0 in demo_compatibility
3662
3663 variable_friction = 0;
3664
3665 weapon_recoil = 0;
3666
3667 allow_pushers = 0;
3668
3669 monster_infighting = 1; // killough 7/19/98
3670
3671 dogs = 0; // killough 7/19/98
3672 dog_jumping = 0; // killough 10/98
3673
3674 monster_backing = 0; // killough 9/8/98
3675
3676 monster_avoid_hazards = 0; // killough 9/9/98
3677
3678 monster_friction = 0; // killough 10/98
3679 help_friends = 0; // killough 9/9/98
3680 monkeys = 0;
3681
3682 // killough 3/6/98: rearrange to fix savegame bugs (moved fastparm,
3683 // respawnparm, nomonsters flags to G_LoadOptions()/G_SaveOptions())
3684
3685 if ((skill = demover) >= 100) // For demos from versions >= 1.4
3686 {
3687 //e6y: check for overrun
3688 if (CheckForOverrun(header_p, demo_p, size, 8, failonerror))
3689 return NULL;
3690
3691 compatibility_level = G_GetOriginalDoomCompatLevel(demover);
3692 skill = *demo_p++;
3693 episode = *demo_p++;
3694 map = *demo_p++;
3695 deathmatch = *demo_p++;
3696 respawnparm = *demo_p++;
3697 fastparm = *demo_p++;
3698 nomonsters = *demo_p++;
3699 consoleplayer = *demo_p++;
3700 }
3701 else
3702 {
3703 //e6y: check for overrun
3704 if (CheckForOverrun(header_p, demo_p, size, 2, failonerror))
3705 return NULL;
3706
3707 compatibility_level = doom_12_compatibility;
3708 episode = *demo_p++;
3709 map = *demo_p++;
3710 deathmatch = respawnparm = fastparm =
3711 nomonsters = consoleplayer = 0;
3712
3713 // e6y
3714 // Ability to force -nomonsters and -respawn for playback of 1.2 demos.
3715 // Demos recorded with Doom.exe 1.2 did not contain any information
3716 // about whether these parameters had been used. In order to play them
3717 // back, you should add them to the command-line for playback.
3718 // There is no more desynch on mesh.lmp @ mesh.wad
3719 // prboom -iwad doom.wad -file mesh.wad -playdemo mesh.lmp -nomonsters
3720 // http://www.doomworld.com/idgames/index.php?id=13976
3721 respawnparm = dsda_Flag(dsda_arg_respawn);
3722 fastparm = dsda_Flag(dsda_arg_fast);
3723 nomonsters = dsda_Flag(dsda_arg_nomonsters);
3724
3725 // Read special parameter bits from player one byte.
3726 // This aligns with vvHeretic demo usage:
3727 // 0x20 = -respawn
3728 // 0x10 = -longtics
3729 // 0x02 = -nomonsters
3730 if (raven)
3731 {
3732 if (*demo_p & DEMOHEADER_RESPAWN)
3733 respawnparm = true;
3734 if (*demo_p & DEMOHEADER_LONGTICS || dsda_Flag(dsda_arg_longtics))
3735 longtics = true;
3736 if (*demo_p & DEMOHEADER_NOMONSTERS)
3737 nomonsters = true;
3738 }
3739
3740 // e6y: detection of more unsupported demo formats
3741 if (*(header_p + size - 1) == DEMOMARKER)
3742 {
3743 // file size test;
3744 // DOOM_old and HERETIC don't use maps>9;
3745 // 2 at 4,6 means playerclass=mage -> not DOOM_old or HERETIC;
3746 if ((size >= 8 && (size - 8) % 4 != 0 && !raven) ||
3747 (map > 9 && !hexen) ||
3748 (size >= 6 && (*(header_p + 4) == 2 || *(header_p + 6) == 2) && !hexen))
3749 {
3750 I_Error("Unrecognised demo format.");
3751 }
3752 }
3753
3754 }
3755 G_Compatibility();
3756 }
3757 else // new versions of demos
3758 {
3759 demo_p += 6; // skip signature;
3760 switch (demover) {
3761 case 200: /* BOOM */
3762 case 201:
3763 //e6y: check for overrun
3764 if (CheckForOverrun(header_p, demo_p, size, 1, failonerror))
3765 return NULL;
3766
3767 if (!*demo_p++)
3768 compatibility_level = boom_201_compatibility;
3769 else
3770 compatibility_level = boom_compatibility_compatibility;
3771 break;
3772 case 202:
3773 //e6y: check for overrun
3774 if (CheckForOverrun(header_p, demo_p, size, 1, failonerror))
3775 return NULL;
3776
3777 if (!*demo_p++)
3778 compatibility_level = boom_202_compatibility;
3779 else
3780 compatibility_level = boom_compatibility_compatibility;
3781 break;
3782 case 203:
3783 /* LxDoom or MBF - determine from signature
3784 * cph - load compatibility level */
3785 switch (*(header_p + 2)) {
3786 case 'B': /* LxDoom */
3787 /* cph - DEMOSYNC - LxDoom demos recorded in compatibility modes support dropped */
3788 compatibility_level = lxdoom_1_compatibility;
3789 break;
3790 case 'M':
3791 compatibility_level = mbf_compatibility;
3792 demo_p++;
3793 break;
3794 }
3795 break;
3796 case 210:
3797 compatibility_level = prboom_2_compatibility;
3798 demo_p++;
3799 break;
3800 case 211:
3801 compatibility_level = prboom_3_compatibility;
3802 demo_p++;
3803 break;
3804 case 212:
3805 compatibility_level = prboom_4_compatibility;
3806 demo_p++;
3807 break;
3808 case 213:
3809 compatibility_level = prboom_5_compatibility;
3810 demo_p++;
3811 break;
3812 case 214:
3813 compatibility_level = prboom_6_compatibility;
3814 longtics = 1;
3815 demo_p++;
3816 break;
3817 case 221:
3818 compatibility_level = mbf21_compatibility;
3819 longtics = 1;
3820 break;
3821 }
3822 //e6y: check for overrun
3823 if (CheckForOverrun(header_p, demo_p, size, 5, failonerror))
3824 return NULL;
3825
3826 skill = *demo_p++;
3827 episode = *demo_p++;
3828 map = *demo_p++;
3829 deathmatch = *demo_p++;
3830 consoleplayer = *demo_p++;
3831
3832 //e6y: check for overrun
3833 if (CheckForOverrun(header_p, demo_p, size, dsda_GameOptionSize(), failonerror))
3834 return NULL;
3835
3836 demo_p = G_ReadOptions(demo_p); // killough 3/1/98: Read game options
3837
3838 if (demover == 200) // killough 6/3/98: partially fix v2.00 demos
3839 demo_p += 256 - dsda_GameOptionSize();
3840 }
3841
3842 if (sizeof(comp_lev_str)/sizeof(comp_lev_str[0]) != MAX_COMPATIBILITY_LEVEL)
3843 I_Error("G_ReadDemoHeader: compatibility level strings incomplete");
3844
3845 for (i = 0; i < g_maxplayers; i++)
3846 playeringame[i] = 0;
3847
3848 if (demo_compatibility || demover < 200) //e6y // only 4 players can exist in old demos
3849 {
3850 if (hexen)
3851 {
3852 //e6y: check for overrun
3853 if (CheckForOverrun(header_p, demo_p, size, g_maxplayers, failonerror))
3854 return NULL;
3855
3856 for (i = 0; i < g_maxplayers; i++)
3857 {
3858 playeringame[i] = (*demo_p++) != 0;
3859 PlayerClass[i] = *demo_p++ + 1;
3860 }
3861 }
3862 else
3863 {
3864 //e6y: check for overrun
3865 if (CheckForOverrun(header_p, demo_p, size, g_maxplayers, failonerror))
3866 return NULL;
3867
3868 for (i = 0; i < g_maxplayers; i++)
3869 playeringame[i] = *demo_p++;
3870 }
3871 }
3872 else
3873 {
3874 //e6y: check for overrun
3875 if (CheckForOverrun(header_p, demo_p, size, g_maxplayers, failonerror))
3876 return NULL;
3877
3878 for (i=0 ; i < g_maxplayers; i++)
3879 playeringame[i] = *demo_p++;
3880 demo_p += FUTURE_MAXPLAYERS - g_maxplayers;
3881 }
3882
3883 {
3884 dsda_arg_t* arg;
3885
3886 arg = dsda_Arg(dsda_arg_consoleplayer);
3887 if (arg->found) {
3888 consoleplayer = arg->value.v_int;
3889
3890 if (consoleplayer >= g_maxplayers || !playeringame[consoleplayer])
3891 consoleplayer = 0;
3892 }
3893 }
3894
3895 displayplayer = consoleplayer;
3896
3897 if (playeringame[1])
3898 {
3899 netgame = true;
3900 }
3901
3902 if (!(params & RDH_SKIP_HEADER))
3903 {
3904 G_InitNew(skill, episode, map, true);
3905 demo_p = dsda_EvaluateDemoStartPoint(demo_p);
3906 }
3907
3908 for (i = 0; i < g_maxplayers; i++) // killough 4/24/98
3909 players[i].cheats = 0;
3910
3911 // e6y
3912 // additional params
3913 {
3914 const byte *p = demo_p;
3915
3916 dsda_EvaluateBytesPerTic();
3917
3918 demo_playerscount = 0;
3919 demo_tics_count = 0;
3920 strcpy(demo_len_st, "-");
3921
3922 for (i = 0; i < g_maxplayers; i++)
3923 {
3924 if (playeringame[i])
3925 {
3926 demo_playerscount++;
3927 }
3928 }
3929
3930 if (demo_playerscount > 0 && demolength > 0)
3931 {
3932 demo_tics_count = dsda_DemoTicsCount(p, demobuffer, demolength);
3933
3934 snprintf(demo_len_st, sizeof(demo_len_st), "\x1b\x35/%d:%02d",
3935 demo_tics_count / TICRATE / 60,
3936 (demo_tics_count % (60 * TICRATE)) / TICRATE);
3937 }
3938 }
3939
3940 return demo_p;
3941 }
3942
3943 void G_StartDemoPlayback(const byte *buffer, int length, int behaviour)
3944 {
3945 const byte *demo_p;
3946
3947 dsda_InitDemoPlayback();
3948 demo_p = G_ReadDemoHeaderEx(demobuffer, demolength, RDH_SAFE);
3949 dsda_AttachPlaybackStream(demo_p, demolength, behaviour);
3950
3951 dsda_InitAutoKeyFrames();
3952 dsda_InitPlaybackKeyFrames();
3953
3954 R_SmoothPlaying_Reset(NULL); // e6y
3955 }
3956
3957 static int LoadDemo(const char *name, const byte **buffer, int *length)
3958 {
3959 char basename[9];
3960 int num;
3961 int len;
3962 const byte *buf = NULL;
3963
3964 if (dsda_CopyExDemo(buffer, length))
3965 return true;
3966
3967 ExtractFileBase(name, basename);
3968 basename[8] = 0;
3969
3970 // check ns_demos namespace first, then ns_global
3971 num = W_CheckNumForName2(basename, ns_demos);
3972
3973 if (num == LUMP_NOT_FOUND)
3974 num = W_CheckNumForName(basename);
3975
3976 if (num == LUMP_NOT_FOUND)
3977 return false;
3978
3979 buf = W_LumpByNum(num);
3980 len = W_LumpLength(num);
3981
3982 if (len > 0)
3983 {
3984 if (buffer)
3985 *buffer = buf;
3986 if (length)
3987 *length = len;
3988 }
3989
3990 return (len > 0);
3991 }
3992
3993
3994 void G_DoPlayDemo(void)
3995 {
3996 if (LoadDemo(defdemoname, &demobuffer, &demolength))
3997 {
3998 G_StartDemoPlayback(demobuffer, demolength, PLAYBACK_NORMAL);
3999
4000 if (dsda_Flag(dsda_arg_track_playback))
4001 dsda_ResetSplits();
4002
4003 lprintf(LO_INFO, "Playing demo:\n Name: %s\n Compatibility: %s\n",
4004 defdemoname, comp_lev_str[compatibility_level]);
4005
4006 gameaction = ga_nothing;
4007 }
4008 else
4009 {
4010 // e6y
4011 // Do not exit if corresponding demo lump is not found.
4012 // It makes sense for Plutonia and TNT IWADs, which have no DEMO4 lump,
4013 // but DEMO4 should be in a demo cycle as real Plutonia and TNT have.
4014 //
4015 // Plutonia/Tnt executables exit with "W_GetNumForName: DEMO4 not found"
4016 // message after playing of DEMO3, because DEMO4 is not present
4017 // in the corresponding IWADs.
4018 D_StartTitle(); // Start the title screen
4019 gamestate = GS_DEMOSCREEN; // And set the game state accordingly
4020 }
4021 }
4022
4023 /* G_CheckDemoStatus
4024 *
4025 * Called after a death or level completion to allow demos to be cleaned up
4026 * Returns true if a new demo loop action will take place
4027 */
4028 dboolean G_CheckDemoStatus (void)
4029 {
4030 dsda_EvaluateSkipModeCheckDemoStatus();
4031
4032 if (demorecording)
4033 {
4034 dsda_EndDemoRecording();
4035
4036 return false; // killough
4037 }
4038
4039 if (timingdemo)
4040 {
4041 int endtime = dsda_GetTickRealTime();
4042 // killough -- added fps information and made it work for longer demos:
4043 unsigned realtics = endtime-starttime;
4044
4045 M_SaveDefaults();
4046
4047 lprintf(LO_INFO, "Timed %u gametics in %u realtics = %-.1f frames per second\n",
4048 (unsigned) gametic,realtics,
4049 (unsigned) gametic * (double) TICRATE / realtics);
4050
4051 if (dsda_IntConfig(dsda_config_demo_end_quit))
4052 I_SafeExit(0);
4053 else
4054 {
4055 timingdemo = false;
4056 dsda_ClearPlaybackStream();
4057 return false;
4058 }
4059 }
4060
4061 if (demoplayback)
4062 {
4063 if (userdemo)
4064 {
4065 if (dsda_IntConfig(dsda_config_demo_end_quit))
4066 I_SafeExit(0); // killough
4067 else
4068 {
4069 dsda_ClearPlaybackStream();
4070 return false;
4071 }
4072 }
4073
4074 G_ReloadDefaults(); // killough 3/1/98
4075 netgame = false; // killough 3/29/98
4076 deathmatch = false;
4077 D_AdvanceDemo ();
4078 return true;
4079 }
4080 return false;
4081 }
4082
4083 // killough 1/22/98: this is a "Doom printf" for messages. I've gotten
4084 // tired of using players->message=... and so I've added this dprintf.
4085 //
4086 // killough 3/6/98: Made limit static to allow z_zone functions to call
4087 // this function, without calling realloc(), which seems to cause problems.
4088
4089 #define MAX_MESSAGE_SIZE 1024
4090
4091 // CPhipps - renamed to doom_printf to avoid name collision with glibc
4092 void doom_printf(const char *s, ...)
4093 {
4094 static char msg[MAX_MESSAGE_SIZE];
4095 va_list v;
4096 va_start(v,s);
4097 vsnprintf(msg,sizeof(msg),s,v); /* print message in buffer */
4098 va_end(v);
4099
4100 dsda_AddMessage(msg);
4101 }
4102
4103 //e6y
4104 void P_WalkTicker()
4105 {
4106 int strafe;
4107 int speed;
4108 int tspeed;
4109 int turnheld;
4110 int forward;
4111 int side;
4112 int angturn;
4113
4114 if (!walkcamera.type || menuactive)
4115 return;
4116
4117 G_SetSpeed(false);
4118
4119 strafe = dsda_InputActive(dsda_input_strafe);
4120 speed = dsda_AutoRun() || dsda_InputActive(dsda_input_speed); // phares
4121
4122 forward = side = 0;
4123 angturn = 0;
4124 turnheld = 0;
4125
4126 // use two stage accelerative turning on the keyboard
4127 if (dsda_InputActive(dsda_input_turnright) || dsda_InputActive(dsda_input_turnleft))
4128 ++turnheld;
4129 else
4130 turnheld = 0;
4131
4132 if (turnheld < SLOWTURNTICS)
4133 tspeed = 0; // slow turn
4134 else
4135 tspeed = speed; // phares
4136
4137 // let movement keys cancel each other out
4138
4139 if (strafe)
4140 {
4141 if (dsda_InputActive(dsda_input_turnright))
4142 side += sidemove[speed];
4143 if (dsda_InputActive(dsda_input_turnleft))
4144 side -= sidemove[speed];
4145 }
4146 else
4147 {
4148 if (dsda_InputActive(dsda_input_turnright))
4149 angturn -= angleturn[tspeed];
4150 if (dsda_InputActive(dsda_input_turnleft))
4151 angturn += angleturn[tspeed];
4152 }
4153
4154 if (dsda_InputActive(dsda_input_forward))
4155 forward += forwardmove[speed];
4156 if (dsda_InputActive(dsda_input_backward))
4157 forward -= forwardmove[speed];
4158 if (dsda_InputActive(dsda_input_straferight))
4159 side += sidemove[speed];
4160 if (dsda_InputActive(dsda_input_strafeleft))
4161 side -= sidemove[speed];
4162
4163 if (dsda_IntConfig(dsda_config_vertmouse))
4164 forward += mousey;
4165
4166 if (strafe)
4167 side += mousex / 4; /* mead Don't want to strafe as fast as turns.*/
4168 else
4169 angturn -= mousex; /* mead now have enough dynamic range 2-10-00 */
4170
4171 G_ConvertAnalogMotion(speed, &forward, &side);
4172
4173 walkcamera.angle += ((angturn / 8) << ANGLETOFINESHIFT);
4174 if (dsda_MouseLook())
4175 {
4176 walkcamera.pitch += ((mlooky / 8) << ANGLETOFINESHIFT);
4177 CheckPitch((signed int *) &walkcamera.pitch);
4178 }
4179
4180 if (dsda_InputActive(dsda_input_fire))
4181 {
4182 walkcamera.x = players[0].mo->x;
4183 walkcamera.y = players[0].mo->y;
4184 walkcamera.angle = players[0].mo->angle;
4185 walkcamera.pitch = dsda_PlayerPitch(&players[0]);
4186 }
4187
4188 if (forward > MAXPLMOVE)
4189 forward = MAXPLMOVE;
4190 else if (forward < -MAXPLMOVE)
4191 forward = -MAXPLMOVE;
4192 if (side > MAXPLMOVE)
4193 side = MAXPLMOVE;
4194 else if (side < -MAXPLMOVE)
4195 side = -MAXPLMOVE;
4196
4197 // moving forward
4198 walkcamera.x += FixedMul ((ORIG_FRICTION / 4) * forward,
4199 finecosine[walkcamera.angle >> ANGLETOFINESHIFT]);
4200 walkcamera.y += FixedMul ((ORIG_FRICTION / 4) * forward,
4201 finesine[walkcamera.angle >> ANGLETOFINESHIFT]);
4202
4203 // strafing
4204 walkcamera.x += FixedMul ((ORIG_FRICTION / 6) * side,
4205 finecosine[(walkcamera.angle -
4206 ANG90) >> ANGLETOFINESHIFT]);
4207 walkcamera.y += FixedMul ((ORIG_FRICTION / 6) * side,
4208 finesine[(walkcamera.angle - ANG90) >> ANGLETOFINESHIFT]);
4209
4210 {
4211 sector_t *sec = R_PointInSector (walkcamera.x, walkcamera.y);
4212 walkcamera.z = sec->floorheight + 41 * FRACUNIT;
4213 }
4214
4215 G_ResetMotion();
4216 }
4217
4218 void P_ResetWalkcam(void)
4219 {
4220 if (walkcamera.type)
4221 {
4222 walkcamera.PrevX = walkcamera.x;
4223 walkcamera.PrevY = walkcamera.y;
4224 walkcamera.PrevZ = walkcamera.z;
4225 walkcamera.PrevAngle = walkcamera.angle;
4226 walkcamera.PrevPitch = walkcamera.pitch;
4227 }
4228 }
4229
4230 void P_SyncWalkcam(dboolean sync_coords, dboolean sync_sight)
4231 {
4232 if (!walkcamera.type)
4233 return;
4234
4235 if (players[displayplayer].mo)
4236 {
4237 if (sync_sight)
4238 {
4239 walkcamera.angle = players[displayplayer].mo->angle;
4240 walkcamera.pitch = dsda_PlayerPitch(&players[displayplayer]);
4241 }
4242
4243 if(sync_coords)
4244 {
4245 walkcamera.x = players[displayplayer].mo->x;
4246 walkcamera.y = players[displayplayer].mo->y;
4247 }
4248 }
4249 }
4250
4251 //e6y
4252 void G_ContinueDemo(const char *playback_name)
4253 {
4254 if (LoadDemo(playback_name, &demobuffer, &demolength))
4255 {
4256 G_StartDemoPlayback(demobuffer, demolength, PLAYBACK_JOIN_ON_END);
4257
4258 dsda_InitDemoRecording();
4259 G_BeginRecording();
4260 }
4261 }
4262
4263 // heretic
4264
4265 static dboolean InventoryMoveLeft(void)
4266 {
4267 player_t *plr;
4268
4269 plr = &players[consoleplayer];
4270
4271 if (R_FullView())
4272 {
4273 inv_ptr--;
4274 if (inv_ptr < 0)
4275 {
4276 inv_ptr = 0;
4277 }
4278 plr->readyArtifact = plr->inventory[inv_ptr].type;
4279 return true;
4280 }
4281
4282 inventoryTics = 5 * 35;
4283 if (!inventory)
4284 {
4285 inventory = true;
4286 return false;
4287 }
4288 inv_ptr--;
4289 if (inv_ptr < 0)
4290 {
4291 inv_ptr = 0;
4292 }
4293 else
4294 {
4295 curpos--;
4296 if (curpos < 0)
4297 {
4298 curpos = 0;
4299 }
4300 }
4301 return true;
4302 }
4303
4304 static dboolean InventoryMoveRight(void)
4305 {
4306 player_t *plr;
4307
4308 plr = &players[consoleplayer];
4309
4310 if (R_FullView())
4311 {
4312 inv_ptr++;
4313 if (inv_ptr >= plr->inventorySlotNum)
4314 {
4315 inv_ptr--;
4316 if (inv_ptr < 0)
4317 inv_ptr = 0;
4318 }
4319 plr->readyArtifact = plr->inventory[inv_ptr].type;
4320 return true;
4321 }
4322
4323 inventoryTics = 5 * 35;
4324 if (!inventory)
4325 {
4326 inventory = true;
4327 return false;
4328 }
4329 inv_ptr++;
4330 if (inv_ptr >= plr->inventorySlotNum)
4331 {
4332 inv_ptr--;
4333 if (inv_ptr < 0)
4334 inv_ptr = 0;
4335 }
4336 else
4337 {
4338 curpos++;
4339 if (curpos > 6)
4340 {
4341 curpos = 6;
4342 }
4343 }
4344 return true;
4345 }
4346
4347 // hexen
4348
4349 void G_Completed(int map, int position, int flags, angle_t angle)
4350 {
4351 if (hexen && gamemode == shareware && map > 4)
4352 {
4353 P_SetMessage(&players[consoleplayer], "ACCESS DENIED -- DEMO", true);
4354 S_StartVoidSound(hexen_sfx_chat);
4355 return;
4356 }
4357
4358 secretexit = false;
4359 gameaction = ga_completed;
4360 dsda_UpdateLeaveData(map, position, flags, angle);
4361 }
4362
4363 void G_DoTeleportNewMap(void)
4364 {
4365 SV_MapTeleport(leave_data.map, leave_data.position);
4366 gamestate = GS_LEVEL;
4367 gameaction = ga_nothing;
4368 RebornPosition = leave_data.position;
4369 dsda_EvaluateSkipModeDoTeleportNewMap();
4370 }
4371
4372 void Hexen_G_DoReborn(int playernum)
4373 {
4374 int i;
4375 dboolean oldWeaponowned[HEXEN_NUMWEAPONS];
4376 dboolean oldKeys[NUMCARDS];
4377 int oldPieces;
4378 dboolean foundSpot;
4379 int bestWeapon;
4380
4381 if (!netgame)
4382 {
4383 gameaction = ga_loadlevel;
4384 }
4385 else
4386 { // Net-game
4387 players[playernum].mo->player = NULL; // Dissassociate the corpse
4388
4389 if (deathmatch)
4390 { // Spawn at random spot if in death match
4391 G_DeathMatchSpawnPlayer(playernum);
4392 return;
4393 }
4394
4395 // Cooperative net-play, retain keys and weapons
4396 for (i = 0; i < NUMCARDS; ++i)
4397 oldKeys[i] = players[playernum].cards[i];
4398 oldPieces = players[playernum].pieces;
4399 for (i = 0; i < HEXEN_NUMWEAPONS; i++)
4400 {
4401 oldWeaponowned[i] = players[playernum].weaponowned[i];
4402 }
4403
4404 foundSpot = false;
4405 if (G_CheckSpot(playernum, &playerstarts[RebornPosition][playernum]))
4406 { // Appropriate player start spot is open
4407 P_SpawnPlayer(playernum, &playerstarts[RebornPosition][playernum]);
4408 foundSpot = true;
4409 }
4410 else
4411 {
4412 // Try to spawn at one of the other player start spots
4413 for (i = 0; i < g_maxplayers; i++)
4414 {
4415 if (G_CheckSpot(playernum, &playerstarts[RebornPosition][i]))
4416 { // Found an open start spot
4417
4418 // Fake as other player
4419 playerstarts[RebornPosition][i].type = playernum + 1;
4420 P_SpawnPlayer(playernum, &playerstarts[RebornPosition][i]);
4421
4422 // Restore proper player type
4423 playerstarts[RebornPosition][i].type = i + 1;
4424
4425 foundSpot = true;
4426 break;
4427 }
4428 }
4429 }
4430
4431 if (foundSpot == false)
4432 { // Player's going to be inside something
4433 P_SpawnPlayer(playernum, &playerstarts[RebornPosition][playernum]);
4434 }
4435
4436 // Restore keys and weapons
4437 for (i = 0; i < NUMCARDS; ++i)
4438 players[playernum].cards[i] = oldKeys[i];
4439 players[playernum].pieces = oldPieces;
4440 for (bestWeapon = 0, i = 0; i < HEXEN_NUMWEAPONS; i++)
4441 {
4442 if (oldWeaponowned[i])
4443 {
4444 bestWeapon = i;
4445 players[playernum].weaponowned[i] = true;
4446 }
4447 }
4448 players[playernum].ammo[MANA_1] = 25;
4449 players[playernum].ammo[MANA_2] = 25;
4450 if (bestWeapon)
4451 { // Bring up the best weapon
4452 players[playernum].pendingweapon = bestWeapon;
4453 }
4454 }
4455 }