/
h_main.c
602 lines (512 loc) · 15.9 KB
/
h_main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
/**\file
*\section License
* License: GPL
* Online License Link: http://www.gnu.org/licenses/gpl.html
*
*\author Copyright © 2003-2010 Jaakko Keränen <jaakko.keranen@iki.fi>
*\author Copyright © 2005-2010 Daniel Swanson <danij@dengine.net>
*\author Copyright © 2006 Jamie Jones <yagisan@dengine.net>
*\author Copyright © 1993-1996 by id Software, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
/**
* h_main.c: Game initialization - jHeretic specific.
*/
// HEADER FILES ------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include "jheretic.h"
#include "m_argv.h"
#include "hu_stuff.h"
#include "hu_menu.h"
#include "hu_msg.h"
#include "hu_log.h"
#include "hu_lib.h"
#include "p_saveg.h"
#include "d_net.h"
#include "p_mapspec.h"
#include "p_switch.h"
#include "am_map.h"
#include "p_inventory.h"
#include "p_player.h"
// MACROS ------------------------------------------------------------------
#define MAXWADFILES 20
// MAPDIR should be defined as the directory that holds development maps
// for the -wart # # command
#define MAPDIR "\\data\\"
// TYPES -------------------------------------------------------------------
// EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
// PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
// EXTERNAL DATA DECLARATIONS ----------------------------------------------
// PUBLIC DATA DEFINITIONS -------------------------------------------------
int verbose;
boolean devParm; // checkparm of -devparm
boolean noMonstersParm; // checkparm of -nomonsters
boolean respawnParm; // checkparm of -respawn
boolean turboParm; // checkparm of -turbo
boolean fastParm; // checkparm of -fast
float turboMul; // multiplier for turbo
skillmode_t startSkill;
int startEpisode;
int startMap;
boolean autoStart;
gamemode_t gameMode;
int gameModeBits;
// This is returned in D_Get(DD_GAME_MODE), max 16 chars.
char gameModeString[17];
boolean monsterInfight;
// Default font colours.
const float defFontRGB[] = { .425f, .986f, .378f };
const float defFontRGB2[] = { 1.0f, 1.0f, 1.0f };
const float defFontRGB3[] = { 1, .65f, .275f };
char *borderLumps[] = {
"FLAT513", // background
"bordt", // top
"bordr", // right
"bordb", // bottom
"bordl", // left
"bordtl", // top left
"bordtr", // top right
"bordbr", // bottom right
"bordbl" // bottom left
};
char *wadFiles[MAXWADFILES] = {
"heretic.wad",
"texture1.lmp",
"texture2.lmp",
"pnames.lmp"
};
char *baseDefault = "heretic.cfg";
char exrnWADs[80];
char exrnWADs2[80];
// PRIVATE DATA DEFINITIONS ------------------------------------------------
static boolean devMap;
// CODE --------------------------------------------------------------------
/**
* Attempt to change the current game mode. Can only be done when not
* actually in a level.
*
* \todo Doesn't actually do anything yet other than set the game mode
* global vars.
*
* @param mode The game mode to change to.
*
* @return @c true, if we changed game modes successfully.
*/
boolean G_SetGameMode(gamemode_t mode)
{
gameMode = mode;
if(G_GetGameState() == GS_MAP)
return false;
switch(mode)
{
case shareware: // shareware, E1, M9
gameModeBits = GM_SHAREWARE;
break;
case registered: // registered episodes
gameModeBits = GM_REGISTERED;
break;
case extended: // episodes 4 and 5 present
gameModeBits = GM_EXTENDED;
break;
case indetermined: // Well, no IWAD found.
gameModeBits = GM_INDETERMINED;
break;
default:
Con_Error("G_SetGameMode: Unknown gamemode %i", mode);
}
return true;
}
static void addFile(char *file)
{
int numWADFiles;
char *new;
for(numWADFiles = 0; wadFiles[numWADFiles]; numWADFiles++);
new = malloc(strlen(file) + 1);
strcpy(new, file);
if(strlen(exrnWADs) + strlen(file) < 78)
{
if(strlen(exrnWADs))
{
strcat(exrnWADs, ", ");
}
else
{
strcpy(exrnWADs, "External Wadfiles: ");
}
strcat(exrnWADs, file);
}
else if(strlen(exrnWADs2) + strlen(file) < 79)
{
if(strlen(exrnWADs2))
{
strcat(exrnWADs2, ", ");
}
else
{
strcpy(exrnWADs2, " ");
strcat(exrnWADs, ",");
}
strcat(exrnWADs2, file);
}
wadFiles[numWADFiles] = new;
}
/**
* Check which known IWADs are found. The purpose of this routine is to
* find out which IWADs the user lets us to know about, but we don't
* decide which one gets loaded or even see if the WADs are actually
* there. The default location for IWADs is Data\GAMENAMETEXT\.
*/
void G_DetectIWADs(void)
{
// Add a couple of probable locations for Heretic.wad.
DD_AddIWAD("}data\\"GAMENAMETEXT"\\heretic.wad");
DD_AddIWAD("}data\\heretic.wad");
DD_AddIWAD("}heretic.wad");
DD_AddIWAD("heretic.wad");
}
/**
* gamemode, gamemission and the gameModeString are set.
*/
void G_IdentifyVersion(void)
{
// The game mode string is used in netgames.
strcpy(gameModeString, "heretic");
if(!P_MapExists(1, 0) == -1)
{ // Can't find episode 2 maps, must be the shareware WAD
strcpy(gameModeString, "heretic-share");
}
else if(W_CheckNumForName("EXTENDED") != -1)
{
// Found extended lump, must be the extended WAD
strcpy(gameModeString, "heretic-ext");
}
}
/**
* Pre Engine Initialization routine.
* All game-specific actions that should take place at this time go here.
*/
void G_PreInit(void)
{
int i;
G_SetGameMode(indetermined);
// Config defaults. The real settings are read from the .cfg files
// but these will be used no such files are found.
memset(&cfg, 0, sizeof(cfg));
cfg.playerMoveSpeed = 1;
cfg.dclickUse = false;
cfg.povLookAround = true;
cfg.statusbarScale = 1;
cfg.screenBlocks = cfg.setBlocks = 10;
cfg.fiNoStretch = false;
cfg.echoMsg = true;
cfg.lookSpeed = 3;
cfg.turnSpeed = 1;
cfg.usePatchReplacement = 2; // Use built-in replacements if available.
cfg.menuScale = .9f;
cfg.menuGlitter = 0;
cfg.menuShadow = 0;
cfg.menuNoStretch = false;
//cfg.menuQuitSound = true;
cfg.flashColor[0] = .7f;
cfg.flashColor[1] = .9f;
cfg.flashColor[2] = 1;
cfg.flashSpeed = 4;
cfg.turningSkull = false;
cfg.hudShown[HUD_AMMO] = true;
cfg.hudShown[HUD_ARMOR] = true;
cfg.hudShown[HUD_KEYS] = true;
cfg.hudShown[HUD_HEALTH] = true;
cfg.hudShown[HUD_CURRENTITEM] = true;
cfg.hudShown[HUD_LOG] = true;
for(i = 0; i < NUMHUDUNHIDEEVENTS; ++i) // when the hud/statusbar unhides.
cfg.hudUnHide[i] = 1;
cfg.hudScale = .7f;
cfg.hudWideOffset = 1;
cfg.hudColor[0] = .325f;
cfg.hudColor[1] = .686f;
cfg.hudColor[2] = .278f;
cfg.hudColor[3] = 1;
cfg.hudIconAlpha = 1;
cfg.xhairSize = .5f;
cfg.xhairVitality = false;
cfg.xhairColor[0] = 1;
cfg.xhairColor[1] = 1;
cfg.xhairColor[2] = 1;
cfg.xhairColor[3] = 1;
cfg.filterStrength = .8f;
//cfg.snd_3D = false;
//cfg.snd_ReverbFactor = 100;
cfg.moveCheckZ = true;
cfg.jumpPower = 9;
cfg.airborneMovement = 1;
cfg.weaponAutoSwitch = 1; // IF BETTER
cfg.noWeaponAutoSwitchIfFiring = false;
cfg.ammoAutoSwitch = 0; // never
cfg.slidingCorpses = false;
cfg.fastMonsters = false;
cfg.secretMsg = true;
cfg.netJumping = true;
cfg.netEpisode = 0;
cfg.netMap = 1;
cfg.netSkill = SM_MEDIUM;
cfg.netColor = 4; // Use the default color by default.
cfg.netMobDamageModifier = 1;
cfg.netMobHealthModifier = 1;
cfg.netGravity = -1; // use map default
cfg.plrViewHeight = DEFAULT_PLAYER_VIEWHEIGHT;
cfg.mapTitle = true;
cfg.hideIWADAuthor = true;
cfg.menuColor[0] = defFontRGB[0]; // use the default colour by default.
cfg.menuColor[1] = defFontRGB[1];
cfg.menuColor[2] = defFontRGB[2];
cfg.menuColor2[0] = defFontRGB2[0]; // use the default colour by default.
cfg.menuColor2[1] = defFontRGB2[1];
cfg.menuColor2[2] = defFontRGB2[2];
cfg.menuSlam = true;
cfg.menuHotkeys = true;
cfg.askQuickSaveLoad = true;
cfg.monstersStuckInDoors = false;
cfg.avoidDropoffs = true;
cfg.moveBlock = false;
cfg.fallOff = true;
cfg.fixFloorFire = false;
cfg.fixPlaneScrollMaterialsEastOnly = true;
cfg.statusbarOpacity = 1;
cfg.statusbarCounterAlpha = 1;
cfg.automapCustomColors = 0; // Never.
cfg.automapL0[0] = .455f; // Unseen areas
cfg.automapL0[1] = .482f;
cfg.automapL0[2] = .439f;
cfg.automapL1[0] = .294f; // onesided lines
cfg.automapL1[1] = .196f;
cfg.automapL1[2] = .063f;
cfg.automapL2[0] = .184f; // floor height change lines
cfg.automapL2[1] = .094f;
cfg.automapL2[2] = .002f;
cfg.automapL3[0] = .592f; // ceiling change lines
cfg.automapL3[1] = .388f;
cfg.automapL3[2] = .231f;
cfg.automapMobj[0] = 1.f;
cfg.automapMobj[1] = 1.f;
cfg.automapMobj[2] = 1.f;
cfg.automapBack[0] = 1.0f;
cfg.automapBack[1] = 1.0f;
cfg.automapBack[2] = 1.0f;
cfg.automapOpacity = 1.0f;
cfg.automapLineAlpha = 1.0f;
cfg.automapShowDoors = true;
cfg.automapDoorGlow = 8;
cfg.automapHudDisplay = 2;
cfg.automapRotate = true;
cfg.automapBabyKeys = true;
cfg.automapZoomSpeed = .1f;
cfg.automapPanSpeed = .5f;
cfg.automapPanResetOnOpen = true;
cfg.automapOpenSeconds = AUTOMAP_OPEN_SECONDS;
cfg.counterCheatScale = .7f;
cfg.msgCount = 4;
cfg.msgScale = .8f;
cfg.msgUptime = 5;
cfg.msgAlign = 1; // Center.
cfg.msgBlink = 5;
cfg.msgColor[0] = defFontRGB2[0];
cfg.msgColor[1] = defFontRGB2[1];
cfg.msgColor[2] = defFontRGB2[2];
cfg.inventoryTimer = 5;
cfg.inventoryWrap = false;
cfg.inventoryUseNext = false;
cfg.inventoryUseImmediate = false;
cfg.inventorySlotMaxVis = 7;
cfg.inventorySlotShowEmpty = true;
cfg.inventorySelectMode = 0; // Cursor select.
cfg.chatBeep = 1;
//cfg.killMessages = true;
cfg.bobView = 1;
cfg.bobWeapon = 1;
cfg.bobWeaponLower = true;
cfg.cameraNoClip = true;
cfg.respawnMonstersNightmare = false;
cfg.weaponOrder[0] = WT_SEVENTH; // mace \ beak
cfg.weaponOrder[1] = WT_SIXTH; // phoenixrod \ beak
cfg.weaponOrder[2] = WT_FIFTH; // skullrod \ beak
cfg.weaponOrder[3] = WT_FOURTH; // blaster \ beak
cfg.weaponOrder[4] = WT_THIRD; // crossbow \ beak
cfg.weaponOrder[5] = WT_SECOND; // goldwand \ beak
cfg.weaponOrder[6] = WT_EIGHTH; // gauntlets \ beak
cfg.weaponOrder[7] = WT_FIRST; // staff \ beak
cfg.weaponCycleSequential = true;
cfg.menuEffects = 0;
cfg.hudFog = 5;
cfg.ringFilter = 1;
cfg.tomeCounter = 10;
cfg.tomeSound = 3;
// Shareware WAD has different border background
if(!P_MapExists(1, 0))
borderLumps[0] = "FLOOR04";
// Do the common pre init routine;
G_CommonPreInit();
}
/**
* Post Engine Initialization routine.
* All game-specific actions that should take place at this time go here.
*/
void G_PostInit(void)
{
int e, m, p;
filename_t file;
if(!P_MapExists(1, 0))
// Can't find episode 2 maps, must be the shareware WAD.
G_SetGameMode(shareware);
else if(W_CheckNumForName("EXTENDED") != -1)
// Found extended lump, must be the extended WAD.
G_SetGameMode(extended);
else
G_SetGameMode(registered);
// Common post init routine.
G_CommonPostInit();
// Initialize weapon info using definitions.
P_InitWeaponInfo();
// Print a game mode banner with rulers.
Con_FPrintf(CBLF_RULER | CBLF_WHITE | CBLF_CENTER,
gameMode == shareware? "Heretic Shareware Startup\n" :
gameMode == registered? "Heretic Registered Startup\n" :
gameMode == extended? "Heretic: Shadow of the Serpent Riders Startup\n" :
"Public Heretic\n");
Con_FPrintf(CBLF_RULER, "");
// Game parameters.
monsterInfight = GetDefInt("AI|Infight", 0);
// Defaults for skill, episode and map.
startSkill = SM_MEDIUM;
startEpisode = 0;
startMap = 0;
autoStart = false;
// Game mode specific settings.
/* None */
// Command line options.
noMonstersParm = ArgCheck("-nomonsters");
respawnParm = ArgCheck("-respawn");
devParm = ArgCheck("-devparm");
if(ArgCheck("-deathmatch"))
{
cfg.netDeathmatch = true;
}
p = ArgCheck("-skill");
if(p && p < myargc - 1)
{
startSkill = Argv(p + 1)[0] - '1';
autoStart = true;
}
p = ArgCheck("-episode");
if(p && p < myargc - 1)
{
startEpisode = Argv(p + 1)[0] - '1';
startMap = 0;
autoStart = true;
}
p = ArgCheck("-warp");
if(p && p < myargc - 2)
{
startEpisode = Argv(p + 1)[0] - '1';
startMap = Argv(p + 2)[0] - '1';
autoStart = true;
}
// turbo option.
p = ArgCheck("-turbo");
turboMul = 1.0f;
if(p)
{
int scale = 200;
turboParm = true;
if(p < myargc - 1)
scale = atoi(Argv(p + 1));
if(scale < 10)
scale = 10;
if(scale > 400)
scale = 400;
Con_Message("turbo scale: %i%%\n", scale);
turboMul = scale / 100.f;
}
// -DEVMAP <episode> <map>
// Adds a map wad from the development directory to the wad list,
// and sets the start episode and the start map.
devMap = false;
p = ArgCheck("-devmap");
if(p && p < myargc - 2)
{
e = Argv(p + 1)[0] - 1;
m = Argv(p + 2)[0] - 1;
sprintf(file, MAPDIR "E%cM%c.wad", e+1, m+1);
addFile(file);
printf("DEVMAP: Episode %c, Map %c.\n", e+1, m+1);
startEpisode = e;
startMap = m;
autoStart = true;
devMap = true;
}
// Are we autostarting?
if(autoStart)
{
Con_Message("Warp to Episode %d, Map %d, Skill %d\n", startEpisode+1,
startMap+1, startSkill + 1);
}
// Load a saved game?
p = ArgCheck("-loadgame");
if(p && p < myargc - 1)
{
SV_GetSaveGameFileName(file, Argv(p + 1)[0] - '0', FILENAME_T_MAXLEN);
G_LoadGame(file);
}
// Check valid episode and map
if(!devMap && (autoStart || IS_NETGAME) && !P_MapExists(startEpisode, startMap))
{
startEpisode = 0;
startMap = 0;
}
if(G_GetGameAction() != GA_LOADGAME)
{
if(autoStart || IS_NETGAME)
{
G_DeferedInitNew(startSkill, startEpisode, startMap);
}
else
{
G_StartTitle(); // Start up intro loop.
}
}
}
void G_Shutdown(void)
{
Hu_MsgShutdown();
Hu_UnloadData();
Hu_LogShutdown();
P_DestroyIterList(spechit);
P_DestroyIterList(linespecials);
P_DestroyLineTagLists();
P_DestroySectorTagLists();
P_ShutdownInventory();
AM_Shutdown();
R_ShutdownVectorGraphics();
P_FreeWeaponSlots();
GUI_Shutdown();
}
void G_EndFrame(void)
{
// Nothing to do.
}