/
h_main.c
505 lines (422 loc) · 13.3 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
/**\file h_main.c
*\section License
* License: GPL
* Online License Link: http://www.gnu.org/licenses/gpl.html
*
*\author Copyright © 2003-2012 Jaakko Keränen <jaakko.keranen@iki.fi>
*\author Copyright © 2005-2012 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
*/
/**
* Game initialization - Heretic specific.
*/
// HEADER FILES ------------------------------------------------------------
#include <assert.h>
#include <string.h>
#include "jheretic.h"
#include "d_netsv.h"
#include "m_argv.h"
#include "p_map.h"
#include "p_saveg.h"
#include "am_map.h"
#include "g_defs.h"
#include "p_inventory.h"
// MACROS ------------------------------------------------------------------
// 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 fastParm; // checkparm of -fast
boolean turboParm; // checkparm of -turbo
//boolean randomClassParm; // checkparm of -randclass
float turboMul; // Multiplier for turbo.
gamemode_t gameMode;
int gameModeBits;
// Default font colours.
const float defFontRGB[] = { .425f, .986f, .378f };
const float defFontRGB2[] = { 1, .65f, .275f };
const float defFontRGB3[] = { 1.0f, 1.0f, 1.0f };
// The patches used in drawing the view border.
// Percent-encoded.
char* borderGraphics[] = {
"Flats:FLAT513", // Background.
"BORDT", // Top.
"BORDR", // Right.
"BORDB", // Bottom.
"BORDL", // Left.
"BORDTL", // Top left.
"BORDTR", // Top right.
"BORDBR", // Bottom right.
"BORDBL" // Bottom left.
};
// PRIVATE DATA DEFINITIONS ------------------------------------------------
static skillmode_t startSkill;
static uint startEpisode;
static uint startMap;
static boolean autoStart;
// CODE --------------------------------------------------------------------
/**
* Get a 32-bit integer value.
*/
int H_GetInteger(int id)
{
switch(id)
{
case DD_DMU_VERSION:
return DMUAPI_VER;
default:
break;
}
// ID not recognized, return NULL.
return 0;
}
/**
* Get a pointer to the value of a variable. Added for 64-bit support.
*/
void* H_GetVariable(int id)
{
static float bob[2];
switch(id)
{
case DD_PLUGIN_NAME:
return PLUGIN_NAMETEXT;
case DD_PLUGIN_NICENAME:
return PLUGIN_NICENAME;
case DD_PLUGIN_VERSION_SHORT:
return PLUGIN_VERSION_TEXT;
case DD_PLUGIN_VERSION_LONG:
return PLUGIN_VERSION_TEXTLONG "\n" PLUGIN_DETAILS;
case DD_PLUGIN_HOMEURL:
return PLUGIN_HOMEURL;
case DD_PLUGIN_DOCSURL:
return PLUGIN_DOCSURL;
case DD_GAME_CONFIG:
return gameConfigString;
case DD_ACTION_LINK:
return actionlinks;
case DD_XGFUNC_LINK:
return xgClasses;
case DD_PSPRITE_BOB_X:
R_GetWeaponBob(DISPLAYPLAYER, &bob[0], NULL);
return &bob[0];
case DD_PSPRITE_BOB_Y:
R_GetWeaponBob(DISPLAYPLAYER, NULL, &bob[1]);
return &bob[1];
case DD_TM_FLOOR_Z:
return (void*) &tmFloorZ;
case DD_TM_CEILING_Z:
return (void*) &tmCeilingZ;
default:
break;
}
// ID not recognized, return NULL.
return 0;
}
/**
* Pre Game Initialization routine.
* All game-specific actions that should take place at this time go here.
*/
void H_PreInit(void)
{
// 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.povLookAround = true;
cfg.statusbarScale = 1;
cfg.screenBlocks = cfg.setBlocks = 10;
cfg.echoMsg = true;
cfg.lookSpeed = 3;
cfg.turnSpeed = 1;
cfg.menuPatchReplaceMode = PRM_ALLOW_TEXT;
cfg.menuScale = .9f;
cfg.menuTextGlitter = 0;
cfg.menuShadow = 0;
//cfg.menuQuitSound = true;
cfg.menuTextFlashColor[0] = .7f;
cfg.menuTextFlashColor[1] = .9f;
cfg.menuTextFlashColor[2] = 1;
cfg.menuTextFlashSpeed = 4;
cfg.menuCursorRotate = false;
cfg.inludePatchReplaceMode = PRM_ALLOW_TEXT;
cfg.hudPatchReplaceMode = PRM_ALLOW_TEXT;
cfg.hudShown[HUD_AMMO] = true;
cfg.hudShown[HUD_ARMOR] = true;
cfg.hudShown[HUD_KEYS] = true;
cfg.hudShown[HUD_HEALTH] = true;
cfg.hudShown[HUD_READYITEM] = true;
cfg.hudShown[HUD_LOG] = true;
{ int i;
for(i = 0; i < NUMHUDUNHIDEEVENTS; ++i) // when the hud/statusbar unhides.
cfg.hudUnHide[i] = 1;
}
cfg.hudScale = .7f;
cfg.hudColor[0] = .325f;
cfg.hudColor[1] = .686f;
cfg.hudColor[2] = .278f;
cfg.hudColor[3] = 1;
cfg.hudIconAlpha = 1;
cfg.xhairAngle = 0;
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.menuTextColors[0][0] = defFontRGB[0];
cfg.menuTextColors[0][1] = defFontRGB[1];
cfg.menuTextColors[0][2] = defFontRGB[2];
cfg.menuTextColors[1][0] = defFontRGB2[0];
cfg.menuTextColors[1][1] = defFontRGB2[1];
cfg.menuTextColors[1][2] = defFontRGB2[2];
cfg.menuTextColors[2][0] = defFontRGB3[0];
cfg.menuTextColors[2][1] = defFontRGB3[1];
cfg.menuTextColors[2][2] = defFontRGB3[2];
cfg.menuTextColors[3][0] = defFontRGB3[0];
cfg.menuTextColors[3][1] = defFontRGB3[1];
cfg.menuTextColors[3][2] = defFontRGB3[2];
cfg.menuSlam = true;
cfg.menuShortcutsEnabled = true;
cfg.menuGameSaveSuggestName = true;
cfg.confirmQuickGameSave = true;
cfg.loadAutoSaveOnReborn = false;
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] = .292f; // onesided lines
cfg.automapL1[1] = .195f;
cfg.automapL1[2] = .062f;
cfg.automapL2[0] = .812f; // floor height change lines
cfg.automapL2[1] = .687f;
cfg.automapL2[2] = .519f;
cfg.automapL3[0] = .402f; // ceiling change lines
cfg.automapL3[1] = .230f;
cfg.automapL3[2] = .121f;
cfg.automapMobj[0] = .093f;
cfg.automapMobj[1] = .093f;
cfg.automapMobj[2] = .093f;
cfg.automapBack[0] = 1.0f;
cfg.automapBack[1] = 1.0f;
cfg.automapBack[2] = 1.0f;
cfg.automapOpacity = 1.0f;
cfg.automapLineAlpha = 1.0f;
cfg.automapLineWidth = 1.1f;
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.hudCheatCounterScale = .7f;
cfg.hudCheatCounterShowWithAutomap = true;
cfg.msgCount = 4;
cfg.msgScale = .8f;
cfg.msgUptime = 5;
cfg.msgAlign = 1; // Center.
cfg.msgBlink = 5;
cfg.msgColor[0] = defFontRGB3[0];
cfg.msgColor[1] = defFontRGB3[1];
cfg.msgColor[2] = defFontRGB3[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 = true;
//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.menuEffectFlags = MEF_TEXT_SHADOW;
cfg.hudFog = 5;
cfg.ringFilter = 1;
cfg.tomeCounter = 10;
cfg.tomeSound = 3;
// Use the crossfade transition by default.
Con_SetInteger("con-transition", 0);
// Do the common pre init routine;
G_CommonPreInit();
}
/**
* Post Game Initialization routine.
* All game-specific actions that should take place at this time go here.
*/
void H_PostInit(void)
{
ddstring_t* path;
Uri* uri;
int p;
/// \kludge Shareware WAD has different border background.
/// @todo Do this properly!
if(gameMode == heretic_shareware)
borderGraphics[0] = "Flats:FLOOR04";
else
borderGraphics[0] = "Flats:FLAT513";
// Common post init routine.
G_CommonPostInit();
// Initialize weapon info using definitions.
P_InitWeaponInfo();
// 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 = CommandLine_Check("-nomonsters");
respawnParm = CommandLine_Check("-respawn");
devParm = CommandLine_Check("-devparm");
if(CommandLine_Check("-deathmatch"))
{
cfg.netDeathmatch = true;
}
// turbo option.
p = CommandLine_Check("-turbo");
turboMul = 1.0f;
if(p)
{
int scale = 200;
turboParm = true;
if(p < myargc - 1)
scale = atoi(CommandLine_At(p + 1));
if(scale < 10)
scale = 10;
if(scale > 400)
scale = 400;
Con_Message("turbo scale: %i%%\n", scale);
turboMul = scale / 100.f;
}
// Load a saved game?
p = CommandLine_Check("-loadgame");
if(p && p < myargc - 1)
{
const int saveSlot = CommandLine_At(p + 1)[0] - '0';
if(G_LoadGame(saveSlot))
{
// No further initialization is to be done.
return;
}
}
p = CommandLine_Check("-skill");
if(p && p < myargc - 1)
{
startSkill = CommandLine_At(p + 1)[0] - '1';
autoStart = true;
}
p = CommandLine_Check("-episode");
if(p && p < myargc - 1)
{
startEpisode = CommandLine_At(p + 1)[0] - '1';
startMap = 0;
autoStart = true;
}
p = CommandLine_Check("-warp");
if(p && p < myargc - 2)
{
startEpisode = CommandLine_At(p + 1)[0] - '1';
startMap = CommandLine_At(p + 2)[0] - '1';
autoStart = true;
}
// Are we autostarting?
if(autoStart)
{
Con_Message("Warp to Episode %d, Map %d, Skill %d\n", startEpisode+1,
startMap+1, startSkill + 1);
}
// Validate episode and map.
uri = G_ComposeMapUri(startEpisode, startMap);
path = Uri_Compose(uri);
if((autoStart || IS_NETGAME) && !P_MapExists(Str_Text(path)))
{
startEpisode = 0;
startMap = 0;
}
Str_Delete(path);
Uri_Delete(uri);
if(autoStart || IS_NETGAME)
{
G_DeferedInitNew(startSkill, startEpisode, startMap);
}
else
{
G_StartTitle(); // Start up intro loop.
}
}
void H_Shutdown(void)
{
P_ShutdownInventory();
G_CommonShutdown();
}