Subversion Repositories eduke32

Rev

Rev 4987 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
5 Plagman 1
//-------------------------------------------------------------------------
2
/*
1652 terminx 3
Copyright (C) 2010 EDuke32 developers and contributors
5 Plagman 4
 
1652 terminx 5
This file is part of EDuke32.
5 Plagman 6
 
7
EDuke32 is free software; you can redistribute it and/or
8
modify it under the terms of the GNU General Public License version 2
9
as published by the Free Software Foundation.
10
 
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
 
15
See the GNU General Public License for more details.
16
 
17
You should have received a copy of the GNU General Public License
18
along with this program; if not, write to the Free Software
4541 hendricks2 19
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
5 Plagman 20
*/
21
//-------------------------------------------------------------------------
22
 
23
#include "duke3d.h"
2296 helixhorne 24
#include "namesdyn.h"
5 Plagman 25
#include "gamedef.h"
1677 terminx 26
#include "gameexec.h"
1950 helixhorne 27
#include "savegame.h"
2561 helixhorne 28
#include "common.h"
2726 hendricks2 29
#include "common_game.h"
5 Plagman 30
 
31
#include "osd.h"
32
 
1492 terminx 33
#ifdef _WIN32
34
#define WIN32_LEAN_AND_MEAN
35
#include <windows.h>
36
#include <shellapi.h>
37
#endif
38
 
4385 terminx 39
#define NUMKEYWORDS (int32_t)ARRAY_SIZE(keyw)
1708 helixhorne 40
 
1205 terminx 41
int32_t g_scriptVersion = 13; // 13 = 1.3D-style CON files, 14 = 1.4/1.5 style CON files
1708 helixhorne 42
uint32_t g_scriptDateVersion = 99999999;  // YYYYMMDD
3415 helixhorne 43
#if !defined LUNATIC
1708 helixhorne 44
static uint32_t g_scriptLastKeyword; // = NUMKEYWORDS-1;
5 Plagman 45
 
4385 terminx 46
#define NUMKEYWDATES (int32_t)ARRAY_SIZE(g_keywdate)
1708 helixhorne 47
// { keyw, date } means that at the date, all keywords up to keyw inclusive are available
48
static struct { uint32_t keyw; uint32_t date; } g_keywdate[] =
49
{
50
    // beginning of eduke32 svn
51
    { CON_CANSEE, 20060423 },    
52
    { CON_CANSEESPR, 20060424 },
53
    // some stuff here not representable this way
54
    { CON_FINDNEARSPRITEZVAR, 20060516 },
55
    { CON_EZSHOOT, 20060701 },
56
    { CON_EZSHOOTVAR, 20060822 },
57
    { CON_JUMP, 20060828 },
58
    { CON_QSTRLEN, 20060930 },
59
    { CON_QUAKE, 20070105 },
60
    { CON_SHOWVIEW, 20070208 },
61
    { CON_NEXTSPRITESECT, 20070819 },
62
    { CON_GETKEYNAME, 20071024 },  // keyw numbers have been
63
    { CON_SPRITENOPAL, 20071220 }, // shuffled around here
64
    { CON_HITRADIUSVAR, 20080216 },
65
    { CON_ROTATESPRITE16, 20080314 },
66
    { CON_SETARRAY, 20080401 },
67
    { CON_READARRAYFROMFILE, 20080405 },
68
    { CON_STARTTRACKVAR, 20080510 },
69
    { CON_QGETSYSSTR, 20080709 },
70
    { CON_GETTICKS, 20080711 },
71
    { CON_SETTSPR, 20080713 },
72
    { CON_CLEARMAPSTATE, 20080716 },
73
    { CON_SCRIPTSIZE, 20080720 },
74
    { CON_SETGAMENAME, 20080722 },
75
    { CON_CMENU, 20080725 },
76
    { CON_GETTIMEDATE, 20080809 },
77
    { CON_ACTIVATECHEAT, 20080810 },
78
    { CON_SETGAMEPALETTE, 20080816 },
79
    { CON_SETCFGNAME, 20080817 },
80
    { CON_IFVARVAREITHER, 20080907 },
81
    { CON_SAVENN, 20080915 },
82
    { CON_COPY, 20090219 },
83
//    { CON_INV, 20090619 },
84
    { CON_QSTRNCAT, 20090712 },
85
    { CON_STOPACTORSOUND, 20090715 },
86
    { CON_IFSERVER, 20100722 },
87
    { CON_CALCHYPOTENUSE, 20100927 },
1712 helixhorne 88
    { CON_CLIPMOVENOSLIDE, 20101009 },
1909 terminx 89
    { CON_INCLUDEDEFAULT, 20110615 },
2104 helixhorne 90
    { CON_SETACTORSOUNDPITCH, 20111102 },
2419 hendricks2 91
    { CON_ECHO, 20120304 },
2573 helixhorne 92
    { CON_SHOWVIEWUNBIASED, 20120331 },
3610 hendricks2 93
    { CON_ROTATESPRITEA, 20130324 },
3803 terminx 94
    { CON_ACTIVATE, 20130522 },
3833 hendricks2 95
    { CON_SCREENTEXT, 20130529 },
3834 hendricks2 96
    { CON_DYNAMICSOUNDREMAP, 20130530 },
3912 helixhorne 97
    { CON_SCREENSOUND, 20130628 },
4928 hendricks2 98
    { CON_SETMUSICPOSITION, 20150115 },
4987 terminx 99
    { CON_CUTSCENE, 20150117 },
100
    { CON_IFCUTSCENE, 20150117 },
1708 helixhorne 101
};
3415 helixhorne 102
#endif
1708 helixhorne 103
 
1143 terminx 104
char g_szScriptFileName[BMAX_PATH] = "(none)";  // file we're currently compiling
105
 
1205 terminx 106
int32_t g_totalLines,g_lineNumber;
5 Plagman 107
char g_szBuf[1024];
108
 
3410 helixhorne 109
#if !defined LUNATIC
3826 helixhorne 110
static char g_szCurrentBlockName[256] = "(none)", g_szLastBlockName[256] = "NULL";
111
static int32_t g_checkingIfElse, g_processingState, g_lastKeyword = -1;
112
 
3373 helixhorne 113
// The pointer to the start of the case table in a switch statement.
114
// First entry is 'default' code.
115
static intptr_t *g_caseScriptPtr=NULL;
1228 terminx 116
static intptr_t *previous_event=NULL;
1205 terminx 117
static int32_t g_numCases = 0;
118
static int32_t g_checkingSwitch = 0, g_currentEvent = -1;
3834 hendricks2 119
static int32_t g_labelsOnly = 0, g_skipKeywordCheck = 0, g_dynamicTileMapping = 0, g_dynamicSoundMapping = 0;
1205 terminx 120
static int32_t g_numBraces = 0;
5 Plagman 121
 
1857 terminx 122
static int32_t C_ParseCommand(int32_t loop);
1361 terminx 123
static int32_t C_SetScriptSize(int32_t size);
3373 helixhorne 124
#endif
874 terminx 125
 
1205 terminx 126
int32_t g_numQuoteRedefinitions = 0;
5 Plagman 127
 
3328 helixhorne 128
#ifdef LUNATIC
129
weapondata_t g_playerWeapon[MAXPLAYERS][MAX_WEAPONS];
130
#endif
5 Plagman 131
 
3826 helixhorne 132
#if !defined LUNATIC
1200 terminx 133
static intptr_t *g_parsingEventPtr=NULL;
3826 helixhorne 134
static char *textptr;
3415 helixhorne 135
#endif
5 Plagman 136
 
1205 terminx 137
int32_t g_numCompilerErrors,g_numCompilerWarnings;
432 terminx 138
 
1465 terminx 139
extern int32_t g_maxSoundPos;
140
 
1857 terminx 141
enum
335 terminx 142
{
255 terminx 143
    LABEL_ANY    = -1,
144
    LABEL_DEFINE = 1,
145
    LABEL_STATE  = 2,
146
    LABEL_ACTOR  = 4,
147
    LABEL_ACTION = 8,
148
    LABEL_AI     = 16,
149
    LABEL_MOVE   = 32,
5 Plagman 150
};
151
 
3410 helixhorne 152
#if !defined LUNATIC
1205 terminx 153
static const char *C_GetLabelType(int32_t type)
5 Plagman 154
{
1205 terminx 155
    int32_t i;
5 Plagman 156
    char x[64];
157
 
1857 terminx 158
    const char *LabelTypeText[] =
159
    {
160
        "define",
161
        "state",
162
        "actor",
163
        "action",
164
        "ai",
165
        "move"
166
    };
167
 
5 Plagman 168
    x[0] = 0;
1229 terminx 169
    for (i=0; i<6; i++)
335 terminx 170
    {
5 Plagman 171
        if (!(type & (1<<i))) continue;
172
        if (x[0]) Bstrcat(x, " or ");
1143 terminx 173
        Bstrcat(x, LabelTypeText[i]);
5 Plagman 174
    }
4491 helixhorne 175
 
176
    return Xstrdup(x);
5 Plagman 177
}
178
 
179
 
967 terminx 180
const char *keyw[] =
559 terminx 181
{
182
    "definelevelname",          // 0  defines level name
183
    "actor",                    // 1  defines an actor
184
    "addammo",                  // 2  adds ammo to a weapon
185
    "ifrnd",                    // 3  checks against a randomizer
186
    "enda",                     // 4  ends an actor definition
187
    "ifcansee",                 // 5  checks if the player can see an object
188
    "ifhitweapon",              // 6  checks if an object was hit by a weapon
189
    "action",                   // 7  defines an action if used outside a state or actor, otherwise triggers actor to perform action
190
    "ifpdistl",                 // 8  checks if player distance is less than value
191
    "ifpdistg",                 // 9  checks if player distance is more than value
192
    "else",                     // 10 used with if checks
193
    "strength",                 // 11 sets health
194
    "break",                    // 12 stops processing
195
    "shoot",                    // 13 shoots a projectile
1625 terminx 196
    "palfrom",                  // 14 used for player screen shading effect, sets p->pals
559 terminx 197
    "sound",                    // 15 plays a sound that was defined with definesound
198
    "fall",                     // 16 causes actor to fall to sector floor height
199
    "state",                    // 17 begins defining a state if used outside a state or actor, otherwise calls a state
200
    "ends",                     // 18 ends defining a state
201
    "define",                   // 19 defines a value
1203 terminx 202
    "return",                   // 20
559 terminx 203
    "ifai",                     // 21 checks if actor is currently performing a specific ai function
204
    "killit",                   // 22 kills an actor
205
    "addweapon",                // 23 adds a weapon to the closest player
206
    "ai",                       // 24 sets an ai function to be used by an actor
207
    "addphealth",               // 25 adds health to the player
208
    "ifdead",                   // 26 checks if actor is dead
209
    "ifsquished",               // 27 checks if actor has been squished
210
    "sizeto",                   // 28 gradually increases actor size until it matches parameters given
211
    "{",                        // 29 used to indicate segments of code
212
    "}",                        // 30 used to indicate segments of code
213
    "spawn",                    // 31 spawns an actor
214
    "move",                     // 32
215
    "ifwasweapon",              // 33
216
    "ifaction",                 // 34
217
    "ifactioncount",            // 35
218
    "resetactioncount",         // 36
219
    "debris",                   // 37
220
    "pstomp",                   // 38
221
    "<null>",                   // 39 was previously used to define the start of a comment block
222
    "cstat",                    // 40
223
    "ifmove",                   // 41
224
    "resetplayer",              // 42
225
    "ifonwater",                // 43
226
    "ifinwater",                // 44
227
    "ifcanshoottarget",         // 45
228
    "ifcount",                  // 46
229
    "resetcount",               // 47
230
    "addinventory",             // 48
231
    "ifactornotstayput",        // 49
232
    "hitradius",                // 50
233
    "ifp",                      // 51
234
    "count",                    // 52
235
    "ifactor",                  // 53
236
    "music",                    // 54
237
    "include",                  // 55
238
    "ifstrength",               // 56
239
    "definesound",              // 57
240
    "guts",                     // 58
241
    "ifspawnedby",              // 59
242
    "gamestartup",              // 60
243
    "wackplayer",               // 61
244
    "ifgapzl",                  // 62
245
    "ifhitspace",               // 63
246
    "ifoutside",                // 64
247
    "ifmultiplayer",            // 65
248
    "operate",                  // 66
249
    "ifinspace",                // 67
250
    "debug",                    // 68
251
    "endofgame",                // 69
252
    "ifbulletnear",             // 70
253
    "ifrespawn",                // 71
254
    "iffloordistl",             // 72
255
    "ifceilingdistl",           // 73
256
    "spritepal",                // 74
257
    "ifpinventory",             // 75
258
    "betaname",                 // 76
259
    "cactor",                   // 77
260
    "ifphealthl",               // 78
261
    "definequote",              // 79
262
    "quote",                    // 80
263
    "ifinouterspace",           // 81
264
    "ifnotmoving",              // 82
265
    "respawnhitag",             // 83
266
    "tip",                      // 84
267
    "ifspritepal",              // 85
268
    "money",                    // 86
269
    "soundonce",                // 87
270
    "addkills",                 // 88
271
    "stopsound",                // 89
272
    "ifawayfromwall",           // 90
273
    "ifcanseetarget",           // 91
274
    "globalsound",              // 92
275
    "lotsofglass",              // 93
276
    "ifgotweaponce",            // 94
277
    "getlastpal",               // 95
278
    "pkick",                    // 96
279
    "mikesnd",                  // 97
280
    "useractor",                // 98
281
    "sizeat",                   // 99
282
    "addstrength",              // 100  [#]
283
    "cstator",                  // 101
284
    "mail",                     // 102
285
    "paper",                    // 103
286
    "tossweapon",               // 104
287
    "sleeptime",                // 105
288
    "nullop",                   // 106
289
    "definevolumename",         // 107
290
    "defineskillname",          // 108
291
    "ifnosounds",               // 109
292
    "clipdist",                 // 110
2695 helixhorne 293
    "ifangdiffl",               // 111  Last Duke3D 1.5 CON command
559 terminx 294
    "gamevar",                  // 112
295
    "ifvarl",                   // 113
296
    "ifvarg",                   // 114
297
    "setvarvar",                // 115
298
    "setvar",                   // 116
299
    "addvarvar",                // 117
300
    "addvar",                   // 118
301
    "ifvarvarl",                // 119
302
    "ifvarvarg",                // 120
303
    "addlogvar",                // 121
304
    "addlog",                   // 122
305
    "onevent",                  // 123
306
    "endevent",                 // 124
307
    "ifvare",                   // 125
308
    "ifvarvare",                // 126
309
    "spgetlotag",               // 127
310
    "spgethitag",               // 128
311
    "sectgetlotag",             // 129
312
    "sectgethitag",             // 130
313
    "ifsound",                  // 131
314
    "gettexturefloor",          // 132
315
    "gettextureceiling",        // 133
316
    "inittimer",                // 134
317
    "starttrack",               // 135
318
    "randvar",                  // 136
319
    "enhanced",                 // 137
320
    "getangletotarget",         // 138
321
    "getactorangle",            // 139
322
    "setactorangle",            // 140
323
    "mulvar",                   // 141
324
    "mulvarvar",                // 142
325
    "divvar",                   // 143
326
    "divvarvar",                // 144
327
    "modvar",                   // 145
328
    "modvarvar",                // 146
329
    "andvar",                   // 147
330
    "andvarvar",                // 148
331
    "orvar",                    // 149
332
    "orvarvar",                 // 150
333
    "getplayerangle",           // 151
334
    "setplayerangle",           // 152
335
    "lockplayer",               // 153
336
    "setsector",                // 154
337
    "getsector",                // 155
338
    "setactor",                 // 156
339
    "getactor",                 // 157
340
    "setwall",                  // 158
341
    "getwall",                  // 159
342
    "findnearactor",            // 160
343
    "findnearactorvar",         // 161
344
    "setactorvar",              // 162
345
    "getactorvar",              // 163
346
    "espawn",                   // 164
347
    "getplayer",                // 165
348
    "setplayer",                // 166
349
    "sqrt",                     // 167
350
    "eventloadactor",           // 168
351
    "espawnvar",                // 169
352
    "getuserdef",               // 170
353
    "setuserdef",               // 171
354
    "subvarvar",                // 172
355
    "subvar",                   // 173
356
    "ifvarn",                   // 174
357
    "ifvarvarn",                // 175
358
    "ifvarand",                 // 176
359
    "ifvarvarand",              // 177
360
    "myos",                     // 178
361
    "myospal",                  // 179
362
    "displayrand",              // 180
363
    "sin",                      // 181
364
    "xorvarvar",                // 182
365
    "xorvar",                   // 183
366
    "randvarvar",               // 184
367
    "myosx",                    // 185
368
    "myospalx",                 // 186
369
    "gmaxammo",                 // 187
370
    "smaxammo",                 // 188
371
    "startlevel",               // 189
372
    "eshoot",                   // 190
373
    "qspawn",                   // 191
374
    "rotatesprite",             // 192
375
    "defineprojectile",         // 193
376
    "spriteshadow",             // 194
377
    "cos",                      // 195
378
    "eshootvar",                // 196
379
    "findnearactor3d",          // 197
380
    "findnearactor3dvar",       // 198
381
    "flash",                    // 199
382
    "qspawnvar",                // 200
383
    "eqspawn",                  // 201
384
    "eqspawnvar",               // 202
385
    "minitext",                 // 203
386
    "gametext",                 // 204
387
    "digitalnumber",            // 205
388
    "addweaponvar",             // 206
389
    "setprojectile",            // 207
390
    "angoff",                   // 208
391
    "updatesector",             // 209
392
    "insertspriteq",            // 210
393
    "angoffvar",                // 211
394
    "whilevarn",                // 212
395
    "switch",                   // 213
396
    "case",                     // 214
397
    "default",                  // 215
398
    "endswitch",                // 216
399
    "shootvar",                 // 217
400
    "soundvar",                 // 218
401
    "findplayer",               // 219
402
    "findotherplayer",          // 220
403
    "activatebysector",         // 221 sectnum, spriteid
404
    "operatesectors",           // 222 sectnum, spriteid
405
    "operaterespawns",          // 223 lotag
406
    "operateactivators",        // 224 lotag, player index
407
    "operatemasterswitches",    // 225 lotag
408
    "checkactivatormotion",     // 226 lotag
409
    "zshoot",                   // 227 zvar projnum
410
    "dist",                     // 228 sprite1 sprite2
411
    "ldist",                    // 229 sprite1 sprite2
412
    "shiftvarl",                // 230
413
    "shiftvarr",                // 231
414
    "spritenvg",                // 232
415
    "getangle",                 // 233
416
    "whilevarvarn",             // 234
417
    "hitscan",                  // 235
418
    "time",                     // 236
419
    "getplayervar",             // 237
420
    "setplayervar",             // 238
421
    "mulscale",                 // 239
422
    "setaspect",                // 240
423
    "ezshoot",                  // 241
424
    "spritenoshade",            // 242
425
    "movesprite",               // 243
426
    "checkavailweapon",         // 244
427
    "soundoncevar",             // 245
428
    "updatesectorz",            // 246
429
    "stopallsounds",            // 247
430
    "ssp",                      // 248
431
    "stopsoundvar",             // 249
432
    "displayrandvar",           // 250
433
    "displayrandvarvar",        // 251
434
    "checkavailinven",          // 252
435
    "globalsoundvar",           // 253
436
    "guniqhudid",               // 254
437
    "getprojectile",            // 255
438
    "getthisprojectile",        // 256
439
    "setthisprojectile",        // 257
440
    "definecheat",              // 258
441
    "cheatkeys",                // 259
442
    "userquote",                // 260
443
    "precache",                 // 261
444
    "definegamefuncname",       // 262
445
    "redefinequote",            // 263
446
    "qsprintf",                 // 264
447
    "getpname",                 // 265
448
    "qstrcat",                  // 266
449
    "qstrcpy",                  // 267
450
    "setsprite",                // 268
451
    "rotatepoint",              // 269
452
    "dragpoint",                // 270
453
    "getzrange",                // 271
454
    "changespritestat",         // 272
455
    "getceilzofslope",          // 273
456
    "getflorzofslope",          // 274
457
    "neartag",                  // 275
458
    "definegametype",           // 276
459
    "changespritesect",         // 277
460
    "spriteflags",              // 278
461
    "savegamevar",              // 279
462
    "readgamevar",              // 280
463
    "findnearsprite",           // 281
464
    "findnearspritevar",        // 282
465
    "findnearsprite3d",         // 283
466
    "findnearsprite3dvar",      // 284
467
    "dynamicremap",             // 285
468
    "setinput",                 // 286
469
    "getinput",                 // 287
955 hnt_ts 470
    "save",                     // 288
2695 helixhorne 471
    "cansee",                   // 289  Beginning EDuke32 SVN
559 terminx 472
    "canseespr",                // 290
473
    "findnearactorz",           // 291
474
    "findnearactorzvar",        // 292
475
    "findnearspritez",          // 293
476
    "findnearspritezvar",       // 294
955 hnt_ts 477
    "zshootvar",                // 295
478
    "ezshootvar",               // 296
479
    "getcurraddress",           // 297
480
    "jump",                     // 298
481
    "qstrlen",                  // 299
559 terminx 482
    "getincangle",              // 300
483
    "quake",                    // 301
484
    "showview",                 // 302
485
    "headspritestat",           // 303
486
    "prevspritestat",           // 304
487
    "nextspritestat",           // 305
488
    "headspritesect",           // 306
489
    "prevspritesect",           // 307
490
    "nextspritesect",           // 308
587 terminx 491
    "getkeyname",               // 309
492
    "qsubstr",                  // 310
493
    "gametextz",                // 311
494
    "digitalnumberz",           // 312
495
    "spritenopal",              // 313
617 terminx 496
    "hitradiusvar",             // 314
642 terminx 497
    "rotatesprite16",           // 315
676 terminx 498
    "gamearray",                // 316
499
    "setarray",                 // 317
693 terminx 500
    "resizearray",              // 318
501
    "writearraytofile",         // 319
502
    "readarrayfromfile",        // 320
955 hnt_ts 503
    "starttrackvar",            // 321
504
    "qgetsysstr",               // 322
505
    "getticks",                 // 323
856 terminx 506
    "gettspr",                  // 324
507
    "settspr",                  // 325
859 terminx 508
    "savemapstate",             // 326
509
    "loadmapstate",             // 327
510
    "clearmapstate",            // 328
874 terminx 511
    "scriptsize",               // 329
987 terminx 512
    "setgamename",              // 330
903 hnt_ts 513
    "cmenu",                    // 331
958 hnt_ts 514
    "gettimedate",              // 332
964 hnt_ts 515
    "activatecheat",            // 333
980 hnt_ts 516
    "setgamepalette",           // 334
984 terminx 517
    "setdefname",               // 335
986 terminx 518
    "setcfgname",               // 336
1060 hnt_ts 519
    "ifvaror",                  // 337
520
    "ifvarvaror",               // 338
521
    "ifvarxor",                 // 339
522
    "ifvarvarxor",              // 340
523
    "ifvareither",              // 341
524
    "ifvarvareither",           // 342
1068 terminx 525
    "getarraysize",             // 343
526
    "savenn",                   // 344
1228 terminx 527
    "copy",                     // 345
1436 terminx 528
    "<null>",                   // 346 internal inversion function
1457 terminx 529
    "sectorofwall",             // 347
530
    "qstrncat",                 // 348
1461 terminx 531
    "ifactorsound",             // 349
532
    "stopactorsound",           // 350
1673 terminx 533
    "ifclient",                 // 351
534
    "ifserver",                 // 352
1708 helixhorne 535
    "sectsetinterpolation",     // 353
536
    "sectclearinterpolation",   // 354
1857 terminx 537
    "clipmove",                 // 355
538
    "lineintersect",            // 356
539
    "rayintersect",             // 357
540
    "calchypotenuse",           // 358
541
    "clipmovenoslide",          // 359
1909 terminx 542
    "includedefault",           // 360
2104 helixhorne 543
    "setactorsoundpitch",       // 361
2419 hendricks2 544
    "echo",                     // 362
2573 helixhorne 545
    "showviewunbiased",         // 363
3610 hendricks2 546
    "rotatespritea",            // 364
3803 terminx 547
    "shadeto",                  // 365
548
    "endoflevel",               // 366
549
    "ifplayersl",               // 367
550
    "activate",                 // 368
3833 hendricks2 551
    "qstrdim",                  // 369
552
    "screentext",               // 370
3834 hendricks2 553
    "dynamicsoundremap",        // 371
3912 helixhorne 554
    "screensound",              // 372
4928 hendricks2 555
    "getmusicposition",         // 373
556
    "setmusicposition",         // 374
4977 hendricks2 557
    "undefinevolume",           // 375
558
    "undefineskill",            // 376
559
    "undefinelevel",            // 377
4987 terminx 560
    "cutscene",                 // 378
561
    "ifcutscene",               // 379
559 terminx 562
    "<null>"
563
};
3354 helixhorne 564
#endif
5 Plagman 565
 
3258 helixhorne 566
// KEEPINSYNC with enum GameEvent_t and lunatic/con_lang.lua
567
const char *EventNames[MAXEVENTS] =
2327 helixhorne 568
{
3258 helixhorne 569
    "EVENT_INIT",
570
    "EVENT_ENTERLEVEL",
571
    "EVENT_RESETWEAPONS",
572
    "EVENT_RESETINVENTORY",
573
    "EVENT_HOLSTER",
574
    "EVENT_LOOKLEFT",
575
    "EVENT_LOOKRIGHT",
576
    "EVENT_SOARUP",
577
    "EVENT_SOARDOWN",
578
    "EVENT_CROUCH",
579
    "EVENT_JUMP",
580
    "EVENT_RETURNTOCENTER",
581
    "EVENT_LOOKUP",
582
    "EVENT_LOOKDOWN",
583
    "EVENT_AIMUP",
584
    "EVENT_FIRE",
585
    "EVENT_CHANGEWEAPON",
586
    "EVENT_GETSHOTRANGE",
587
    "EVENT_GETAUTOAIMANGLE",
588
    "EVENT_GETLOADTILE",
589
    "EVENT_CHEATGETSTEROIDS",
590
    "EVENT_CHEATGETHEAT",
591
    "EVENT_CHEATGETBOOT",
592
    "EVENT_CHEATGETSHIELD",
593
    "EVENT_CHEATGETSCUBA",
594
    "EVENT_CHEATGETHOLODUKE",
595
    "EVENT_CHEATGETJETPACK",
596
    "EVENT_CHEATGETFIRSTAID",
597
    "EVENT_QUICKKICK",
598
    "EVENT_INVENTORY",
599
    "EVENT_USENIGHTVISION",
600
    "EVENT_USESTEROIDS",
601
    "EVENT_INVENTORYLEFT",
602
    "EVENT_INVENTORYRIGHT",
603
    "EVENT_HOLODUKEON",
604
    "EVENT_HOLODUKEOFF",
605
    "EVENT_USEMEDKIT",
606
    "EVENT_USEJETPACK",
607
    "EVENT_TURNAROUND",
608
    "EVENT_DISPLAYWEAPON",
609
    "EVENT_FIREWEAPON",
610
    "EVENT_SELECTWEAPON",
611
    "EVENT_MOVEFORWARD",
612
    "EVENT_MOVEBACKWARD",
613
    "EVENT_TURNLEFT",
614
    "EVENT_TURNRIGHT",
615
    "EVENT_STRAFELEFT",
616
    "EVENT_STRAFERIGHT",
617
    "EVENT_WEAPKEY1",
618
    "EVENT_WEAPKEY2",
619
    "EVENT_WEAPKEY3",
620
    "EVENT_WEAPKEY4",
621
    "EVENT_WEAPKEY5",
622
    "EVENT_WEAPKEY6",
623
    "EVENT_WEAPKEY7",
624
    "EVENT_WEAPKEY8",
625
    "EVENT_WEAPKEY9",
626
    "EVENT_WEAPKEY10",
627
    "EVENT_DRAWWEAPON",
628
    "EVENT_DISPLAYCROSSHAIR",
629
    "EVENT_DISPLAYREST",
630
    "EVENT_DISPLAYSBAR",
631
    "EVENT_RESETPLAYER",
632
    "EVENT_INCURDAMAGE",
633
    "EVENT_AIMDOWN",
634
    "EVENT_GAME",
635
    "EVENT_PREVIOUSWEAPON",
636
    "EVENT_NEXTWEAPON",
637
    "EVENT_SWIMUP",
638
    "EVENT_SWIMDOWN",
639
    "EVENT_GETMENUTILE",
640
    "EVENT_SPAWN",
641
    "EVENT_LOGO",
642
    "EVENT_EGS",
643
    "EVENT_DOFIRE",
644
    "EVENT_PRESSEDFIRE",
645
    "EVENT_USE",
646
    "EVENT_PROCESSINPUT",
647
    "EVENT_FAKEDOMOVETHINGS",
648
    "EVENT_DISPLAYROOMS",
649
    "EVENT_KILLIT",
650
    "EVENT_LOADACTOR",
651
    "EVENT_DISPLAYBONUSSCREEN",
652
    "EVENT_DISPLAYMENU",
653
    "EVENT_DISPLAYMENUREST",
654
    "EVENT_DISPLAYLOADINGSCREEN",
655
    "EVENT_ANIMATESPRITES",
656
    "EVENT_NEWGAME",
657
    "EVENT_SOUND",
658
    "EVENT_CHECKTOUCHDAMAGE",
659
    "EVENT_CHECKFLOORDAMAGE",
660
    "EVENT_LOADGAME",
661
    "EVENT_SAVEGAME",
662
    "EVENT_PREGAME",
3937 helixhorne 663
    "EVENT_CHANGEMENU",
4206 helixhorne 664
    "EVENT_DAMAGEHPLANE",
4515 hendricks2 665
    "EVENT_ACTIVATECHEAT",
4945 hendricks2 666
    "EVENT_DISPLAYINACTIVEMENU",
667
    "EVENT_DISPLAYINACTIVEMENUREST",
4987 terminx 668
    "EVENT_CUTSCENE",
3937 helixhorne 669
#ifdef LUNATIC
670
    "EVENT_ANIMATEALLSPRITES",
671
#endif
2327 helixhorne 672
};
673
 
3410 helixhorne 674
#if !defined LUNATIC
1143 terminx 675
const memberlabel_t SectorLabels[]=
559 terminx 676
{
677
    { "wallptr", SECTOR_WALLPTR, 0, 0 },
678
    { "wallnum", SECTOR_WALLNUM, 0, 0 },
679
    { "ceilingz", SECTOR_CEILINGZ, 0, 0 },
680
    { "floorz", SECTOR_FLOORZ, 0, 0 },
681
    { "ceilingstat", SECTOR_CEILINGSTAT, 0, 0 },
682
    { "floorstat", SECTOR_FLOORSTAT, 0, 0 },
683
    { "ceilingpicnum", SECTOR_CEILINGPICNUM, 0, 0 },
684
    { "ceilingslope", SECTOR_CEILINGSLOPE, 0, 0 },
685
    { "ceilingshade", SECTOR_CEILINGSHADE, 0, 0 },
686
    { "ceilingpal", SECTOR_CEILINGPAL, 0, 0 },
687
    { "ceilingxpanning", SECTOR_CEILINGXPANNING, 0, 0 },
688
    { "ceilingypanning", SECTOR_CEILINGYPANNING, 0, 0 },
689
    { "floorpicnum", SECTOR_FLOORPICNUM, 0, 0 },
690
    { "floorslope", SECTOR_FLOORSLOPE, 0, 0 },
691
    { "floorshade", SECTOR_FLOORSHADE, 0, 0 },
692
    { "floorpal", SECTOR_FLOORPAL, 0, 0 },
693
    { "floorxpanning", SECTOR_FLOORXPANNING, 0, 0 },
694
    { "floorypanning", SECTOR_FLOORYPANNING, 0, 0 },
695
    { "visibility", SECTOR_VISIBILITY, 0, 0 },
4416 helixhorne 696
    { "fogpal", SECTOR_FOGPAL, 0, 0 }, // formerly filler
697
    { "alignto", SECTOR_FOGPAL, 0, 0 }, // formerly filler
559 terminx 698
    { "lotag", SECTOR_LOTAG, 0, 0 },
699
    { "hitag", SECTOR_HITAG, 0, 0 },
700
    { "extra", SECTOR_EXTRA, 0, 0 },
2050 helixhorne 701
    { "ceilingbunch", SECTOR_CEILINGBUNCH, 0, 0 },
702
    { "floorbunch", SECTOR_FLOORBUNCH, 0, 0 },
3192 terminx 703
    { "ulotag", SECTOR_ULOTAG, 0, 0 },
704
    { "uhitag", SECTOR_UHITAG, 0, 0 },
559 terminx 705
    { "", -1, 0, 0  }     // END OF LIST
706
};
5 Plagman 707
 
1143 terminx 708
const memberlabel_t WallLabels[]=
559 terminx 709
{
710
    { "x", WALL_X, 0, 0 },
711
    { "y", WALL_Y, 0, 0 },
712
    { "point2", WALL_POINT2, 0, 0 },
713
    { "nextwall", WALL_NEXTWALL, 0, 0 },
714
    { "nextsector", WALL_NEXTSECTOR, 0, 0 },
715
    { "cstat", WALL_CSTAT, 0, 0 },
716
    { "picnum", WALL_PICNUM, 0, 0 },
717
    { "overpicnum", WALL_OVERPICNUM, 0, 0 },
718
    { "shade", WALL_SHADE, 0, 0 },
719
    { "pal", WALL_PAL, 0, 0 },
720
    { "xrepeat", WALL_XREPEAT, 0, 0 },
721
    { "yrepeat", WALL_YREPEAT, 0, 0 },
722
    { "xpanning", WALL_XPANNING, 0, 0 },
723
    { "ypanning", WALL_YPANNING, 0, 0 },
724
    { "lotag", WALL_LOTAG, 0, 0 },
725
    { "hitag", WALL_HITAG, 0, 0 },
726
    { "extra", WALL_EXTRA, 0, 0 },
3192 terminx 727
    { "ulotag", WALL_ULOTAG, 0, 0 },
728
    { "uhitag", WALL_UHITAG, 0, 0 },
559 terminx 729
    { "", -1, 0, 0  }     // END OF LIST
730
};
5 Plagman 731
 
1143 terminx 732
const memberlabel_t ActorLabels[]=
559 terminx 733
{
734
    { "x", ACTOR_X, 0, 0 },
735
    { "y", ACTOR_Y, 0, 0 },
736
    { "z", ACTOR_Z, 0, 0 },
737
    { "cstat", ACTOR_CSTAT, 0, 0 },
738
    { "picnum", ACTOR_PICNUM, 0, 0 },
739
    { "shade", ACTOR_SHADE, 0, 0 },
740
    { "pal", ACTOR_PAL, 0, 0 },
741
    { "clipdist", ACTOR_CLIPDIST, 0, 0 },
1011 terminx 742
//    { "filler", ACTOR_DETAIL, 0, 0 },
4313 helixhorne 743
    { "blend", ACTOR_DETAIL, 0, 0 },
559 terminx 744
    { "xrepeat", ACTOR_XREPEAT, 0, 0 },
745
    { "yrepeat", ACTOR_YREPEAT, 0, 0 },
746
    { "xoffset", ACTOR_XOFFSET, 0, 0 },
747
    { "yoffset", ACTOR_YOFFSET, 0, 0 },
748
    { "sectnum", ACTOR_SECTNUM, 0, 0 },
749
    { "statnum", ACTOR_STATNUM, 0, 0 },
750
    { "ang", ACTOR_ANG, 0, 0 },
751
    { "owner", ACTOR_OWNER, 0, 0 },
752
    { "xvel", ACTOR_XVEL, 0, 0 },
753
    { "yvel", ACTOR_YVEL, 0, 0 },
754
    { "zvel", ACTOR_ZVEL, 0, 0 },
755
    { "lotag", ACTOR_LOTAG, 0, 0 },
756
    { "hitag", ACTOR_HITAG, 0, 0 },
757
    { "extra", ACTOR_EXTRA, 0, 0 },
5 Plagman 758
 
1143 terminx 759
    // ActorExtra labels...
559 terminx 760
    { "htcgg", ACTOR_HTCGG, 0, 0 },
761
    { "htpicnum", ACTOR_HTPICNUM, 0, 0 },
762
    { "htang", ACTOR_HTANG, 0, 0 },
763
    { "htextra", ACTOR_HTEXTRA, 0, 0 },
764
    { "htowner", ACTOR_HTOWNER, 0, 0 },
765
    { "htmovflag", ACTOR_HTMOVFLAG, 0, 0 },
766
    { "httempang", ACTOR_HTTEMPANG, 0, 0 },
767
    { "htactorstayput", ACTOR_HTACTORSTAYPUT, 0, 0 },
768
    { "htdispicnum", ACTOR_HTDISPICNUM, 0, 0 },
769
    { "httimetosleep", ACTOR_HTTIMETOSLEEP, 0, 0 },
770
    { "htfloorz", ACTOR_HTFLOORZ, 0, 0 },
771
    { "htceilingz", ACTOR_HTCEILINGZ, 0, 0 },
772
    { "htlastvx", ACTOR_HTLASTVX, 0, 0 },
773
    { "htlastvy", ACTOR_HTLASTVY, 0, 0 },
774
    { "htbposx", ACTOR_HTBPOSX, 0, 0 },
775
    { "htbposy", ACTOR_HTBPOSY, 0, 0 },
776
    { "htbposz", ACTOR_HTBPOSZ, 0, 0 },
870 terminx 777
    { "htg_t", ACTOR_HTG_T, LABEL_HASPARM2, 10 },
5 Plagman 778
 
559 terminx 779
    // model flags
5 Plagman 780
 
559 terminx 781
    { "angoff", ACTOR_ANGOFF, 0, 0 },
782
    { "pitch", ACTOR_PITCH, 0, 0 },
783
    { "roll", ACTOR_ROLL, 0, 0 },
784
    { "mdxoff", ACTOR_MDXOFF, 0, 0 },
785
    { "mdyoff", ACTOR_MDYOFF, 0, 0 },
786
    { "mdzoff", ACTOR_MDZOFF, 0, 0 },
787
    { "mdflags", ACTOR_MDFLAGS, 0, 0 },
590 plagman 788
    { "xpanning", ACTOR_XPANNING, 0, 0 },
789
    { "ypanning", ACTOR_YPANNING, 0, 0 },
853 terminx 790
 
939 terminx 791
    { "htflags", ACTOR_HTFLAGS, 0, 0 },
792
 
1344 terminx 793
    { "alpha", ACTOR_ALPHA, 0, 0 },
1341 terminx 794
 
3192 terminx 795
    { "ulotag", ACTOR_ULOTAG, 0, 0 },
796
    { "uhitag", ACTOR_UHITAG, 0, 0 },
797
 
4146 helixhorne 798
    { "isvalid", ACTOR_ISVALID, 0, 0 },
4313 helixhorne 799
// aliases:
4448 helixhorne 800
    { "movflags", ACTOR_HITAG, 0, 0 },
4313 helixhorne 801
    { "detail", ACTOR_DETAIL, 0, 0 },  // deprecated name for 'blend'
4146 helixhorne 802
 
856 terminx 803
    { "", -1, 0, 0  }     // END OF LIST
804
};
805
 
1143 terminx 806
const memberlabel_t TsprLabels[]=
856 terminx 807
{
853 terminx 808
    // tsprite access
809
 
1007 hnt_ts 810
    { "tsprx", ACTOR_X, 0, 0 },
811
    { "tspry", ACTOR_Y, 0, 0 },
812
    { "tsprz", ACTOR_Z, 0, 0 },
813
    { "tsprcstat", ACTOR_CSTAT, 0, 0 },
814
    { "tsprpicnum", ACTOR_PICNUM, 0, 0 },
815
    { "tsprshade", ACTOR_SHADE, 0, 0 },
816
    { "tsprpal", ACTOR_PAL, 0, 0 },
817
    { "tsprclipdist", ACTOR_CLIPDIST, 0, 0 },
1011 terminx 818
//    { "tsprfiller", ACTOR_DETAIL, 0, 0 },
4313 helixhorne 819
    { "tsprblend", ACTOR_DETAIL, 0, 0 },
1007 hnt_ts 820
    { "tsprxrepeat", ACTOR_XREPEAT, 0, 0 },
821
    { "tspryrepeat", ACTOR_YREPEAT, 0, 0 },
822
    { "tsprxoffset", ACTOR_XOFFSET, 0, 0 },
823
    { "tspryoffset", ACTOR_YOFFSET, 0, 0 },
824
    { "tsprsectnum", ACTOR_SECTNUM, 0, 0 },
825
    { "tsprstatnum", ACTOR_STATNUM, 0, 0 },
826
    { "tsprang", ACTOR_ANG, 0, 0 },
827
    { "tsprowner", ACTOR_OWNER, 0, 0 },
828
#if 1
829
    { "tsprxvel", ACTOR_XVEL, 0, 0 },
830
    { "tspryvel", ACTOR_YVEL, 0, 0 },
831
    { "tsprzvel", ACTOR_ZVEL, 0, 0 },
832
    { "tsprlotag", ACTOR_LOTAG, 0, 0 },
833
    { "tsprhitag", ACTOR_HITAG, 0, 0 },
834
    { "tsprextra", ACTOR_EXTRA, 0, 0 },
835
#endif
4313 helixhorne 836
// aliases:
837
    { "tsprdetail", ACTOR_DETAIL, 0, 0 },  // deprecated name for 'tsprblend'
853 terminx 838
 
559 terminx 839
    { "", -1, 0, 0  }     // END OF LIST
840
};
5 Plagman 841
 
1143 terminx 842
const memberlabel_t PlayerLabels[]=
559 terminx 843
{
844
    { "zoom", PLAYER_ZOOM, 0, 0 },
845
    { "exitx", PLAYER_EXITX, 0, 0 },
846
    { "exity", PLAYER_EXITY, 0, 0 },
870 terminx 847
    { "loogiex", PLAYER_LOOGIEX, LABEL_HASPARM2, 64 },
848
    { "loogiey", PLAYER_LOOGIEY, LABEL_HASPARM2, 64 },
559 terminx 849
    { "numloogs", PLAYER_NUMLOOGS, 0, 0 },
850
    { "loogcnt", PLAYER_LOOGCNT, 0, 0 },
851
    { "posx", PLAYER_POSX, 0, 0 },
852
    { "posy", PLAYER_POSY, 0, 0 },
853
    { "posz", PLAYER_POSZ, 0, 0 },
854
    { "horiz", PLAYER_HORIZ, 0, 0 },
855
    { "ohoriz", PLAYER_OHORIZ, 0, 0 },
856
    { "ohorizoff", PLAYER_OHORIZOFF, 0, 0 },
857
    { "invdisptime", PLAYER_INVDISPTIME, 0, 0 },
858
    { "bobposx", PLAYER_BOBPOSX, 0, 0 },
859
    { "bobposy", PLAYER_BOBPOSY, 0, 0 },
860
    { "oposx", PLAYER_OPOSX, 0, 0 },
861
    { "oposy", PLAYER_OPOSY, 0, 0 },
862
    { "oposz", PLAYER_OPOSZ, 0, 0 },
863
    { "pyoff", PLAYER_PYOFF, 0, 0 },
864
    { "opyoff", PLAYER_OPYOFF, 0, 0 },
865
    { "posxv", PLAYER_POSXV, 0, 0 },
866
    { "posyv", PLAYER_POSYV, 0, 0 },
867
    { "poszv", PLAYER_POSZV, 0, 0 },
868
    { "last_pissed_time", PLAYER_LAST_PISSED_TIME, 0, 0 },
869
    { "truefz", PLAYER_TRUEFZ, 0, 0 },
870
    { "truecz", PLAYER_TRUECZ, 0, 0 },
871
    { "player_par", PLAYER_PLAYER_PAR, 0, 0 },
872
    { "visibility", PLAYER_VISIBILITY, 0, 0 },
873
    { "bobcounter", PLAYER_BOBCOUNTER, 0, 0 },
874
    { "weapon_sway", PLAYER_WEAPON_SWAY, 0, 0 },
875
    { "pals_time", PLAYER_PALS_TIME, 0, 0 },
876
    { "randomflamex", PLAYER_RANDOMFLAMEX, 0, 0 },
877
    { "crack_time", PLAYER_CRACK_TIME, 0, 0 },
878
    { "aim_mode", PLAYER_AIM_MODE, 0, 0 },
879
    { "ang", PLAYER_ANG, 0, 0 },
880
    { "oang", PLAYER_OANG, 0, 0 },
881
    { "angvel", PLAYER_ANGVEL, 0, 0 },
882
    { "cursectnum", PLAYER_CURSECTNUM, 0, 0 },
883
    { "look_ang", PLAYER_LOOK_ANG, 0, 0 },
884
    { "last_extra", PLAYER_LAST_EXTRA, 0, 0 },
885
    { "subweapon", PLAYER_SUBWEAPON, 0, 0 },
886
    { "ammo_amount", PLAYER_AMMO_AMOUNT, LABEL_HASPARM2, MAX_WEAPONS },
887
    { "wackedbyactor", PLAYER_WACKEDBYACTOR, 0, 0 },
888
    { "frag", PLAYER_FRAG, 0, 0 },
889
    { "fraggedself", PLAYER_FRAGGEDSELF, 0, 0 },
890
    { "curr_weapon", PLAYER_CURR_WEAPON, 0, 0 },
891
    { "last_weapon", PLAYER_LAST_WEAPON, 0, 0 },
892
    { "tipincs", PLAYER_TIPINCS, 0, 0 },
893
    { "horizoff", PLAYER_HORIZOFF, 0, 0 },
894
    { "wantweaponfire", PLAYER_WANTWEAPONFIRE, 0, 0 },
895
    { "holoduke_amount", PLAYER_HOLODUKE_AMOUNT, 0, 0 },
896
    { "newowner", PLAYER_NEWOWNER, 0, 0 },
897
    { "hurt_delay", PLAYER_HURT_DELAY, 0, 0 },
898
    { "hbomb_hold_delay", PLAYER_HBOMB_HOLD_DELAY, 0, 0 },
899
    { "jumping_counter", PLAYER_JUMPING_COUNTER, 0, 0 },
900
    { "airleft", PLAYER_AIRLEFT, 0, 0 },
901
    { "knee_incs", PLAYER_KNEE_INCS, 0, 0 },
902
    { "access_incs", PLAYER_ACCESS_INCS, 0, 0 },
903
    { "fta", PLAYER_FTA, 0, 0 },
904
    { "ftq", PLAYER_FTQ, 0, 0 },
905
    { "access_wallnum", PLAYER_ACCESS_WALLNUM, 0, 0 },
906
    { "access_spritenum", PLAYER_ACCESS_SPRITENUM, 0, 0 },
907
    { "kickback_pic", PLAYER_KICKBACK_PIC, 0, 0 },
908
    { "got_access", PLAYER_GOT_ACCESS, 0, 0 },
909
    { "weapon_ang", PLAYER_WEAPON_ANG, 0, 0 },
910
    { "firstaid_amount", PLAYER_FIRSTAID_AMOUNT, 0, 0 },
911
    { "somethingonplayer", PLAYER_SOMETHINGONPLAYER, 0, 0 },
912
    { "on_crane", PLAYER_ON_CRANE, 0, 0 },
913
    { "i", PLAYER_I, 0, 0 },
914
    { "one_parallax_sectnum", PLAYER_ONE_PARALLAX_SECTNUM, 0, 0 },
915
    { "over_shoulder_on", PLAYER_OVER_SHOULDER_ON, 0, 0 },
916
    { "random_club_frame", PLAYER_RANDOM_CLUB_FRAME, 0, 0 },
917
    { "fist_incs", PLAYER_FIST_INCS, 0, 0 },
918
    { "one_eighty_count", PLAYER_ONE_EIGHTY_COUNT, 0, 0 },
919
    { "cheat_phase", PLAYER_CHEAT_PHASE, 0, 0 },
920
    { "dummyplayersprite", PLAYER_DUMMYPLAYERSPRITE, 0, 0 },
921
    { "extra_extra8", PLAYER_EXTRA_EXTRA8, 0, 0 },
922
    { "quick_kick", PLAYER_QUICK_KICK, 0, 0 },
923
    { "heat_amount", PLAYER_HEAT_AMOUNT, 0, 0 },
924
    { "actorsqu", PLAYER_ACTORSQU, 0, 0 },
925
    { "timebeforeexit", PLAYER_TIMEBEFOREEXIT, 0, 0 },
926
    { "customexitsound", PLAYER_CUSTOMEXITSOUND, 0, 0 },
1625 terminx 927
    { "weaprecs", PLAYER_WEAPRECS, LABEL_HASPARM2, MAX_WEAPONS },
559 terminx 928
    { "weapreccnt", PLAYER_WEAPRECCNT, 0, 0 },
929
    { "interface_toggle_flag", PLAYER_INTERFACE_TOGGLE_FLAG, 0, 0 },
930
    { "rotscrnang", PLAYER_ROTSCRNANG, 0, 0 },
931
    { "dead_flag", PLAYER_DEAD_FLAG, 0, 0 },
932
    { "show_empty_weapon", PLAYER_SHOW_EMPTY_WEAPON, 0, 0 },
933
    { "scuba_amount", PLAYER_SCUBA_AMOUNT, 0, 0 },
934
    { "jetpack_amount", PLAYER_JETPACK_AMOUNT, 0, 0 },
935
    { "steroids_amount", PLAYER_STEROIDS_AMOUNT, 0, 0 },
936
    { "shield_amount", PLAYER_SHIELD_AMOUNT, 0, 0 },
937
    { "holoduke_on", PLAYER_HOLODUKE_ON, 0, 0 },
938
    { "pycount", PLAYER_PYCOUNT, 0, 0 },
939
    { "weapon_pos", PLAYER_WEAPON_POS, 0, 0 },
940
    { "frag_ps", PLAYER_FRAG_PS, 0, 0 },
941
    { "transporter_hold", PLAYER_TRANSPORTER_HOLD, 0, 0 },
942
    { "last_full_weapon", PLAYER_LAST_FULL_WEAPON, 0, 0 },
943
    { "footprintshade", PLAYER_FOOTPRINTSHADE, 0, 0 },
944
    { "boot_amount", PLAYER_BOOT_AMOUNT, 0, 0 },
945
    { "scream_voice", PLAYER_SCREAM_VOICE, 0, 0 },
946
    { "gm", PLAYER_GM, 0, 0 },
947
    { "on_warping_sector", PLAYER_ON_WARPING_SECTOR, 0, 0 },
948
    { "footprintcount", PLAYER_FOOTPRINTCOUNT, 0, 0 },
949
    { "hbomb_on", PLAYER_HBOMB_ON, 0, 0 },
950
    { "jumping_toggle", PLAYER_JUMPING_TOGGLE, 0, 0 },
951
    { "rapid_fire_hold", PLAYER_RAPID_FIRE_HOLD, 0, 0 },
952
    { "on_ground", PLAYER_ON_GROUND, 0, 0 },
953
    { "name", PLAYER_NAME,  LABEL_ISSTRING, 32 },
954
    { "inven_icon", PLAYER_INVEN_ICON, 0, 0 },
955
    { "buttonpalette", PLAYER_BUTTONPALETTE, 0, 0 },
956
    { "jetpack_on", PLAYER_JETPACK_ON, 0, 0 },
957
    { "spritebridge", PLAYER_SPRITEBRIDGE, 0, 0 },
958
    { "lastrandomspot", PLAYER_LASTRANDOMSPOT, 0, 0 },
959
    { "scuba_on", PLAYER_SCUBA_ON, 0, 0 },
960
    { "footprintpal", PLAYER_FOOTPRINTPAL, 0, 0 },
961
    { "heat_on", PLAYER_HEAT_ON, 0, 0 },
962
    { "holster_weapon", PLAYER_HOLSTER_WEAPON, 0, 0 },
963
    { "falling_counter", PLAYER_FALLING_COUNTER, 0, 0 },
964
    { "gotweapon", PLAYER_GOTWEAPON, LABEL_HASPARM2, MAX_WEAPONS },
965
    { "refresh_inventory", PLAYER_REFRESH_INVENTORY, 0, 0 },
966
    { "palette", PLAYER_PALETTE, 0, 0 },
967
    { "toggle_key_flag", PLAYER_TOGGLE_KEY_FLAG, 0, 0 },
968
    { "knuckle_incs", PLAYER_KNUCKLE_INCS, 0, 0 },
969
    { "walking_snd_toggle", PLAYER_WALKING_SND_TOGGLE, 0, 0 },
970
    { "palookup", PLAYER_PALOOKUP, 0, 0 },
971
    { "hard_landing", PLAYER_HARD_LANDING, 0, 0 },
972
    { "max_secret_rooms", PLAYER_MAX_SECRET_ROOMS, 0, 0 },
973
    { "secret_rooms", PLAYER_SECRET_ROOMS, 0, 0 },
869 terminx 974
    { "pals", PLAYER_PALS, LABEL_HASPARM2, 3 },
559 terminx 975
    { "max_actors_killed", PLAYER_MAX_ACTORS_KILLED, 0, 0 },
976
    { "actors_killed", PLAYER_ACTORS_KILLED, 0, 0 },
977
    { "return_to_center", PLAYER_RETURN_TO_CENTER, 0, 0 },
978
    { "runspeed", PLAYER_RUNSPEED, 0, 0 },
979
    { "sbs", PLAYER_SBS, 0, 0 },
980
    { "reloading", PLAYER_RELOADING, 0, 0 },
981
    { "auto_aim", PLAYER_AUTO_AIM, 0, 0 },
982
    { "movement_lock", PLAYER_MOVEMENT_LOCK, 0, 0 },
983
    { "sound_pitch", PLAYER_SOUND_PITCH, 0, 0 },
984
    { "weaponswitch", PLAYER_WEAPONSWITCH, 0, 0 },
985
    { "team", PLAYER_TEAM, 0, 0 },
566 terminx 986
    { "max_player_health", PLAYER_MAX_PLAYER_HEALTH, 0, 0 },
987
    { "max_shield_amount", PLAYER_MAX_SHIELD_AMOUNT, 0, 0 },
988
    { "max_ammo_amount", PLAYER_MAX_AMMO_AMOUNT, LABEL_HASPARM2, MAX_WEAPONS },
1062 terminx 989
    { "last_quick_kick", PLAYER_LAST_QUICK_KICK, 0, 0 },
3100 hendricks2 990
    { "autostep", PLAYER_AUTOSTEP, 0, 0 },
991
    { "autostep_sbw", PLAYER_AUTOSTEP_SBW, 0, 0 },
559 terminx 992
    { "", -1, 0, 0  }     // END OF LIST
993
};
5 Plagman 994
 
1143 terminx 995
const memberlabel_t ProjectileLabels[]=
559 terminx 996
{
997
    { "workslike", PROJ_WORKSLIKE, 0, 0 },
998
    { "spawns", PROJ_SPAWNS, 0, 0 },
999
    { "sxrepeat", PROJ_SXREPEAT, 0, 0 },
1000
    { "syrepeat", PROJ_SYREPEAT, 0, 0 },
1001
    { "sound", PROJ_SOUND, 0, 0 },
1002
    { "isound", PROJ_ISOUND, 0, 0 },
1003
    { "vel", PROJ_VEL, 0, 0 },
1004
    { "extra", PROJ_EXTRA, 0, 0 },
1005
    { "decal", PROJ_DECAL, 0, 0 },
1006
    { "trail", PROJ_TRAIL, 0, 0 },
1007
    { "txrepeat", PROJ_TXREPEAT, 0, 0 },
1008
    { "tyrepeat", PROJ_TYREPEAT, 0, 0 },
1009
    { "toffset", PROJ_TOFFSET, 0, 0 },
1010
    { "tnum", PROJ_TNUM, 0, 0 },
1011
    { "drop", PROJ_DROP, 0, 0 },
1012
    { "cstat", PROJ_CSTAT, 0, 0 },
1013
    { "clipdist", PROJ_CLIPDIST, 0, 0 },
1014
    { "shade", PROJ_SHADE, 0, 0 },
1015
    { "xrepeat", PROJ_XREPEAT, 0, 0 },
1016
    { "yrepeat", PROJ_YREPEAT, 0, 0 },
1017
    { "pal", PROJ_PAL, 0, 0 },
1018
    { "extra_rand", PROJ_EXTRA_RAND, 0, 0 },
1019
    { "hitradius", PROJ_HITRADIUS, 0, 0 },
3053 terminx 1020
    { "velmult", PROJ_MOVECNT, 0, 0 },
559 terminx 1021
    { "offset", PROJ_OFFSET, 0, 0 },
1022
    { "bounces", PROJ_BOUNCES, 0, 0 },
1023
    { "bsound", PROJ_BSOUND, 0, 0 },
1024
    { "range", PROJ_RANGE, 0, 0 },
1315 terminx 1025
    { "flashcolor", PROJ_FLASH_COLOR, 0, 0 },
3866 helixhorne 1026
    { "userdata", PROJ_USERDATA, 0, 0 },
559 terminx 1027
    { "", -1, 0, 0  }     // END OF LIST
1028
};
5 Plagman 1029
 
1143 terminx 1030
const memberlabel_t UserdefsLabels[]=
559 terminx 1031
{
1032
    //        { "<null>", 1, 0, 0 },
1033
    { "god", USERDEFS_GOD, 0, 0 },
1034
    { "warp_on", USERDEFS_WARP_ON, 0, 0 },
1035
    { "cashman", USERDEFS_CASHMAN, 0, 0 },
1036
    { "eog", USERDEFS_EOG, 0, 0 },
1037
    { "showallmap", USERDEFS_SHOWALLMAP, 0, 0 },
1038
    { "show_help", USERDEFS_SHOW_HELP, 0, 0 },
1039
    { "scrollmode", USERDEFS_SCROLLMODE, 0, 0 },
1040
    { "clipping", USERDEFS_CLIPPING, 0, 0 },
1041
    { "user_name", USERDEFS_USER_NAME, LABEL_HASPARM2, MAXPLAYERS },
1042
    { "ridecule", USERDEFS_RIDECULE, LABEL_HASPARM2 | LABEL_ISSTRING, 10 },
1043
    { "savegame", USERDEFS_SAVEGAME, LABEL_HASPARM2 | LABEL_ISSTRING, 10 },
1044
    { "pwlockout", USERDEFS_PWLOCKOUT, LABEL_ISSTRING, 128 },
1045
    { "rtsname;", USERDEFS_RTSNAME,  LABEL_ISSTRING, 128 },
1046
    { "overhead_on", USERDEFS_OVERHEAD_ON, 0, 0 },
1047
    { "last_overhead", USERDEFS_LAST_OVERHEAD, 0, 0 },
1048
    { "showweapons", USERDEFS_SHOWWEAPONS, 0, 0 },
5 Plagman 1049
 
559 terminx 1050
    { "pause_on", USERDEFS_PAUSE_ON, 0, 0 },
1051
    { "from_bonus", USERDEFS_FROM_BONUS, 0, 0 },
1052
    { "camerasprite", USERDEFS_CAMERASPRITE, 0, 0 },
1053
    { "last_camsprite", USERDEFS_LAST_CAMSPRITE, 0, 0 },
1054
    { "last_level", USERDEFS_LAST_LEVEL, 0, 0 },
1055
    { "secretlevel", USERDEFS_SECRETLEVEL, 0, 0 },
4968 hendricks2 1056
    { "playerbest", USERDEFS_PLAYERBEST, 0, 0 },
5 Plagman 1057
 
559 terminx 1058
    { "const_visibility", USERDEFS_CONST_VISIBILITY, 0, 0 },
1059
    { "uw_framerate", USERDEFS_UW_FRAMERATE, 0, 0 },
1060
    { "camera_time", USERDEFS_CAMERA_TIME, 0, 0 },
1061
    { "folfvel", USERDEFS_FOLFVEL, 0, 0 },
1062
    { "folavel", USERDEFS_FOLAVEL, 0, 0 },
1063
    { "folx", USERDEFS_FOLX, 0, 0 },
1064
    { "foly", USERDEFS_FOLY, 0, 0 },
1065
    { "fola", USERDEFS_FOLA, 0, 0 },
1066
    { "reccnt", USERDEFS_RECCNT, 0, 0 },
5 Plagman 1067
 
4945 hendricks2 1068
    { "m_origin_x", USERDEFS_M_ORIGIN_X, 0, 0 },
1069
    { "m_origin_y", USERDEFS_M_ORIGIN_Y, 0, 0 },
1070
 
559 terminx 1071
    { "entered_name", USERDEFS_ENTERED_NAME, 0, 0 },
1072
    { "screen_tilting", USERDEFS_SCREEN_TILTING, 0, 0 },
1073
    { "shadows", USERDEFS_SHADOWS, 0, 0 },
1074
    { "fta_on", USERDEFS_FTA_ON, 0, 0 },
1075
    { "executions", USERDEFS_EXECUTIONS, 0, 0 },
1076
    { "auto_run", USERDEFS_AUTO_RUN, 0, 0 },
1077
    { "coords", USERDEFS_COORDS, 0, 0 },
1078
    { "tickrate", USERDEFS_TICKRATE, 0, 0 },
1079
    { "m_coop", USERDEFS_M_COOP, 0, 0 },
1080
    { "coop", USERDEFS_COOP, 0, 0 },
1081
    { "screen_size", USERDEFS_SCREEN_SIZE, 0, 0 },
1082
    { "lockout", USERDEFS_LOCKOUT, 0, 0 },
1083
    { "crosshair", USERDEFS_CROSSHAIR, 0, 0 },
4215 helixhorne 1084
//    { "wchoice[MAXPLAYERS][MAX_WEAPONS]", USERDEFS_WCHOICE, 0, 0 },
559 terminx 1085
    { "playerai", USERDEFS_PLAYERAI, 0, 0 },
1086
    { "respawn_monsters", USERDEFS_RESPAWN_MONSTERS, 0, 0 },
1087
    { "respawn_items", USERDEFS_RESPAWN_ITEMS, 0, 0 },
1088
    { "respawn_inventory", USERDEFS_RESPAWN_INVENTORY, 0, 0 },
1089
    { "recstat", USERDEFS_RECSTAT, 0, 0 },
1090
    { "monsters_off", USERDEFS_MONSTERS_OFF, 0, 0 },
1091
    { "brightness", USERDEFS_BRIGHTNESS, 0, 0 },
1092
    { "m_respawn_items", USERDEFS_M_RESPAWN_ITEMS, 0, 0 },
1093
    { "m_respawn_monsters", USERDEFS_M_RESPAWN_MONSTERS, 0, 0 },
1094
    { "m_respawn_inventory", USERDEFS_M_RESPAWN_INVENTORY, 0, 0 },
1095
    { "m_recstat", USERDEFS_M_RECSTAT, 0, 0 },
1096
    { "m_monsters_off", USERDEFS_M_MONSTERS_OFF, 0, 0 },
1097
    { "detail", USERDEFS_DETAIL, 0, 0 },
1098
    { "m_ffire", USERDEFS_M_FFIRE, 0, 0 },
1099
    { "ffire", USERDEFS_FFIRE, 0, 0 },
1100
    { "m_player_skill", USERDEFS_M_PLAYER_SKILL, 0, 0 },
1101
    { "m_level_number", USERDEFS_M_LEVEL_NUMBER, 0, 0 },
1102
    { "m_volume_number", USERDEFS_M_VOLUME_NUMBER, 0, 0 },
1103
    { "multimode", USERDEFS_MULTIMODE, 0, 0 },
1104
    { "player_skill", USERDEFS_PLAYER_SKILL, 0, 0 },
1105
    { "level_number", USERDEFS_LEVEL_NUMBER, 0, 0 },
1106
    { "volume_number", USERDEFS_VOLUME_NUMBER, 0, 0 },
1107
    { "m_marker", USERDEFS_M_MARKER, 0, 0 },
1108
    { "marker", USERDEFS_MARKER, 0, 0 },
1109
    { "mouseflip", USERDEFS_MOUSEFLIP, 0, 0 },
1110
    { "statusbarscale", USERDEFS_STATUSBARSCALE, 0, 0 },
1111
    { "drawweapon", USERDEFS_DRAWWEAPON, 0, 0 },
1112
    { "mouseaiming", USERDEFS_MOUSEAIMING, 0, 0 },
1113
    { "weaponswitch", USERDEFS_WEAPONSWITCH, 0, 0 },
1114
    { "democams", USERDEFS_DEMOCAMS, 0, 0 },
1115
    { "color", USERDEFS_COLOR, 0, 0 },
1116
    { "msgdisptime", USERDEFS_MSGDISPTIME, 0, 0 },
1117
    { "statusbarmode", USERDEFS_STATUSBARMODE, 0, 0 },
1118
    { "m_noexits", USERDEFS_M_NOEXITS, 0, 0 },
1119
    { "noexits", USERDEFS_NOEXITS, 0, 0 },
1120
    { "autovote", USERDEFS_AUTOVOTE, 0, 0 },
1121
    { "automsg", USERDEFS_AUTOMSG, 0, 0 },
1122
    { "idplayers", USERDEFS_IDPLAYERS, 0, 0 },
1123
    { "team", USERDEFS_TEAM, 0, 0 },
1124
    { "viewbob", USERDEFS_VIEWBOB, 0, 0 },
1125
    { "weaponsway", USERDEFS_WEAPONSWAY, 0, 0 },
1126
    { "angleinterpolation", USERDEFS_ANGLEINTERPOLATION, 0, 0 },
926 terminx 1127
    { "obituaries", USERDEFS_OBITUARIES, 0, 0 },
674 terminx 1128
    { "levelstats", USERDEFS_LEVELSTATS, 0, 0 },
881 terminx 1129
    { "crosshairscale", USERDEFS_CROSSHAIRSCALE, 0, 0 },
934 terminx 1130
    { "althud", USERDEFS_ALTHUD, 0, 0 },
990 terminx 1131
    { "display_bonus_screen", USERDEFS_DISPLAY_BONUS_SCREEN, 0, 0 },
1082 terminx 1132
    { "show_level_text", USERDEFS_SHOW_LEVEL_TEXT, 0, 0 },
1090 terminx 1133
    { "weaponscale", USERDEFS_WEAPONSCALE, 0, 0 },
1095 terminx 1134
    { "textscale", USERDEFS_TEXTSCALE, 0, 0 },
3071 terminx 1135
    { "runkey_mode", USERDEFS_RUNKEY_MODE, 0, 0 },
4970 hendricks2 1136
    { "musictoggle", USERDEFS_MUSICTOGGLE, 0, 0 },
559 terminx 1137
    { "", -1, 0, 0  }     // END OF LIST
1138
};
5 Plagman 1139
 
1143 terminx 1140
const memberlabel_t InputLabels[]=
559 terminx 1141
{
1142
    { "avel", INPUT_AVEL, 0, 0 },
1143
    { "horz", INPUT_HORZ, 0, 0 },
1144
    { "fvel", INPUT_FVEL, 0, 0 },
1145
    { "svel", INPUT_SVEL, 0, 0 },
1146
    { "bits", INPUT_BITS, 0, 0 },
1147
    { "extbits", INPUT_EXTBITS, 0, 0 },
1148
    { "", -1, 0, 0  }     // END OF LIST
1149
};
5 Plagman 1150
 
3354 helixhorne 1151
#endif
1152
 
1064 terminx 1153
char *bitptr; // pointer to bitmap of which bytecode positions contain pointers
978 terminx 1154
#define BITPTR_POINTER 1
1155
 
3415 helixhorne 1156
#if !defined LUNATIC
1625 terminx 1157
hashtable_t h_gamevars    = { MAXGAMEVARS>>1, NULL };
1158
hashtable_t h_arrays      = { MAXGAMEARRAYS>>1, NULL };
1159
hashtable_t h_labels      = { 11264>>1, NULL };
3354 helixhorne 1160
 
2262 helixhorne 1161
static hashtable_t h_keywords       = { CON_END>>1, NULL };
1024 terminx 1162
 
2262 helixhorne 1163
static hashtable_t sectorH     = { SECTOR_END>>1, NULL };
1164
static hashtable_t wallH       = { WALL_END>>1, NULL };
1165
static hashtable_t userdefH    = { USERDEFS_END>>1, NULL };
1024 terminx 1166
 
2262 helixhorne 1167
static hashtable_t projectileH = { PROJ_END>>1, NULL };
1168
static hashtable_t playerH     = { PLAYER_END>>1, NULL };
1169
static hashtable_t inputH      = { INPUT_END>>1, NULL };
1170
static hashtable_t actorH      = { ACTOR_END>>1, NULL };
1171
static hashtable_t tspriteH    = { ACTOR_END>>1, NULL };
1024 terminx 1172
 
1201 terminx 1173
void C_InitHashes()
1024 terminx 1174
{
1205 terminx 1175
    int32_t i;
1024 terminx 1176
 
1625 terminx 1177
    hash_init(&h_gamevars);
1178
    hash_init(&h_arrays);
1179
    hash_init(&h_labels);
1031 hnt_ts 1180
    inithashnames();
3834 hendricks2 1181
    initsoundhashnames();
1024 terminx 1182
 
1625 terminx 1183
    hash_init(&h_keywords);
1206 terminx 1184
    hash_init(&sectorH);
1185
    hash_init(&wallH);
1186
    hash_init(&userdefH);
1187
    hash_init(&projectileH);
1188
    hash_init(&playerH);
1189
    hash_init(&inputH);
1190
    hash_init(&actorH);
1191
    hash_init(&tspriteH);
1544 terminx 1192
 
1708 helixhorne 1193
    g_scriptLastKeyword = NUMKEYWORDS-1;
1194
    // determine last CON keyword for backward compatibility with older mods
1195
    if (g_scriptDateVersion < g_keywdate[NUMKEYWDATES-1].date)
1196
    {
1197
        for (i=NUMKEYWDATES-1; i>=0; i--)
1198
        {
1199
            if (g_scriptDateVersion >= g_keywdate[i].date)
1200
            {
1201
                g_scriptLastKeyword = g_keywdate[i].keyw;
1202
                break;
1203
            }
1204
        }
1205
 
1206
        if (i<0)
1207
            g_scriptLastKeyword = g_keywdate[0].keyw-1;  // may be slightly imprecise
1208
    }
1209
 
1210
    for (i=g_scriptLastKeyword; i>=0; i--) hash_add(&h_keywords,keyw[i],i,0);
1677 terminx 1211
    for (i=0; SectorLabels[i].lId >= 0; i++) hash_add(&sectorH,SectorLabels[i].name,i,0);
1212
    for (i=0; WallLabels[i].lId >= 0; i++) hash_add(&wallH,WallLabels[i].name,i,0);
1213
    for (i=0; UserdefsLabels[i].lId >= 0; i++) hash_add(&userdefH,UserdefsLabels[i].name,i,0);
1214
    for (i=0; ProjectileLabels[i].lId >= 0; i++) hash_add(&projectileH,ProjectileLabels[i].name,i,0);
1215
    for (i=0; PlayerLabels[i].lId >= 0; i++) hash_add(&playerH,PlayerLabels[i].name,i,0);
1216
    for (i=0; InputLabels[i].lId >= 0; i++) hash_add(&inputH,InputLabels[i].name,i,0);
1217
    for (i=0; ActorLabels[i].lId >= 0; i++) hash_add(&actorH,ActorLabels[i].name,i,0);
1218
    for (i=0; TsprLabels[i].lId >= 0; i++) hash_add(&tspriteH,TsprLabels[i].name,i,0);
1024 terminx 1219
}
1025 terminx 1220
 
1390 terminx 1221
// "magic" number for { and }, overrides line number in compiled code for later detection
1201 terminx 1222
#define IFELSE_MAGIC 31337
1205 terminx 1223
static int32_t g_ifElseAborted;
1200 terminx 1224
 
1820 terminx 1225
static int32_t C_SetScriptSize(int32_t newsize)
874 terminx 1226
{
1143 terminx 1227
    intptr_t oscriptPtr = (unsigned)(g_scriptPtr-script);
1228
    intptr_t ocaseScriptPtr = (unsigned)(g_caseScriptPtr-script);
1229
    intptr_t oparsingEventPtr = (unsigned)(g_parsingEventPtr-script);
1230
    intptr_t oparsingActorPtr = (unsigned)(g_parsingActorPtr-script);
874 terminx 1231
    intptr_t *newscript;
1232
    intptr_t i, j;
1205 terminx 1233
    int32_t osize = g_scriptSize;
1820 terminx 1234
    char *scriptptrs;
1064 terminx 1235
    char *newbitptr;
2262 helixhorne 1236
 
4491 helixhorne 1237
    scriptptrs = (char *)Xcalloc(1, g_scriptSize * sizeof(uint8_t));
1820 terminx 1238
 
1229 terminx 1239
    for (i=g_scriptSize-1; i>=0; i--)
874 terminx 1240
    {
1206 terminx 1241
        if (bitptr[i>>3]&(BITPTR_POINTER<<(i&7)))
874 terminx 1242
        {
4680 terminx 1243
            if (EDUKE32_PREDICT_FALSE((intptr_t)script[i] < (intptr_t)&script[0] || (intptr_t)script[i] >= (intptr_t)&script[g_scriptSize]))
1820 terminx 1244
            {
1245
                g_numCompilerErrors++;
1909 terminx 1246
                initprintf("Internal compiler error at %" PRIdPTR " (0x%" PRIxPTR ")\n",i,i);
1820 terminx 1247
            }
1248
 
874 terminx 1249
            scriptptrs[i] = 1;
976 terminx 1250
            script[i] -= (intptr_t)&script[0];
874 terminx 1251
        }
1252
        else scriptptrs[i] = 0;
1253
    }
1254
 
3102 terminx 1255
    G_Util_PtrToIdx2(&g_tile[0].execPtr, MAXTILES, sizeof(tiledata_t), script, P2I_FWD_NON0);
1256
    G_Util_PtrToIdx2(&g_tile[0].loadPtr, MAXTILES, sizeof(tiledata_t), script, P2I_FWD_NON0);
1950 helixhorne 1257
    G_Util_PtrToIdx(apScriptGameEvent, MAXGAMEEVENTS, script, P2I_FWD_NON0);
1820 terminx 1258
 
1259
    initprintf("Resizing code buffer to %d*%d bytes\n",newsize, (int32_t)sizeof(intptr_t));
1029 terminx 1260
 
4491 helixhorne 1261
    newscript = (intptr_t *)Xrealloc(script, newsize * sizeof(intptr_t));
1262
    newbitptr = (char *)Xcalloc(1,(((newsize+7)>>3)+1) * sizeof(uint8_t));
874 terminx 1263
 
1820 terminx 1264
    if (newsize >= osize)
1029 terminx 1265
    {
1820 terminx 1266
        Bmemset(&newscript[0]+osize,0,(newsize-osize) * sizeof(uint8_t));
1229 terminx 1267
        Bmemcpy(newbitptr,bitptr,sizeof(uint8_t) *((osize+7)>>3));
1029 terminx 1268
    }
1390 terminx 1269
    else
1820 terminx 1270
        Bmemcpy(newbitptr,bitptr,sizeof(uint8_t) *((newsize+7)>>3));
1029 terminx 1271
 
1064 terminx 1272
    Bfree(bitptr);
1273
    bitptr = newbitptr;
1390 terminx 1274
    if (script != newscript)
1275
    {
3278 hendricks2 1276
        initprintf("Relocating compiled code from to 0x%" PRIxPTR " to 0x%" PRIxPTR "\n", (intptr_t)script, (intptr_t)newscript);
1390 terminx 1277
        script = newscript;
1278
    }
1279
 
1820 terminx 1280
    g_scriptSize = newsize;
1143 terminx 1281
    g_scriptPtr = (intptr_t *)(script+oscriptPtr);
976 terminx 1282
 
1544 terminx 1283
    if (g_caseScriptPtr)
1143 terminx 1284
        g_caseScriptPtr = (intptr_t *)(script+ocaseScriptPtr);
1544 terminx 1285
 
1286
    if (g_parsingEventPtr)
1143 terminx 1287
        g_parsingEventPtr = (intptr_t *)(script+oparsingEventPtr);
1544 terminx 1288
 
1289
    if (g_parsingActorPtr)
1143 terminx 1290
        g_parsingActorPtr = (intptr_t *)(script+oparsingActorPtr);
2262 helixhorne 1291
 
1820 terminx 1292
    for (i=(((newsize>=osize)?osize:newsize))-1; i>=0; i--)
1293
        if (scriptptrs[i])
1294
        {
1950 helixhorne 1295
            j = (intptr_t)script[i]+(intptr_t)&script[0];
1820 terminx 1296
            script[i] = j;
1297
        }
874 terminx 1298
 
3102 terminx 1299
    G_Util_PtrToIdx2(&g_tile[0].execPtr, MAXTILES, sizeof(tiledata_t), script, P2I_BACK_NON0);
1300
    G_Util_PtrToIdx2(&g_tile[0].loadPtr, MAXTILES, sizeof(tiledata_t), script, P2I_BACK_NON0);
1950 helixhorne 1301
    G_Util_PtrToIdx(apScriptGameEvent, MAXGAMEEVENTS, script, P2I_BACK_NON0);
874 terminx 1302
 
1303
    Bfree(scriptptrs);
1304
    return 0;
1305
}
1306
 
2640 helixhorne 1307
static int32_t ispecial(const char c)
1593 terminx 1308
{
1309
    if (c == ' ' || c == 0x0d || c == '(' || c == ')' ||
1616 helixhorne 1310
            c == ',' || c == ';' || (c == 0x0a /*&& ++g_lineNumber*/))
1593 terminx 1311
        return 1;
1545 terminx 1312
 
1593 terminx 1313
    return 0;
1314
}
1315
 
1545 terminx 1316
#define C_NextLine() while (*textptr != 0x0a && *textptr != 0x0d && *textptr != 0) textptr++
1317
 
1205 terminx 1318
static int32_t C_SkipComments(void)
5 Plagman 1319
{
1040 terminx 1320
    do
5 Plagman 1321
    {
1544 terminx 1322
        switch (*textptr)
335 terminx 1323
        {
1544 terminx 1324
        case '\n':
1143 terminx 1325
            g_lineNumber++;
1544 terminx 1326
        case ' ':
1327
        case '\t':
1328
        case '\r':
1665 terminx 1329
        case 0x1a:
5 Plagman 1330
            textptr++;
1544 terminx 1331
            break;
1332
        case '/':
1333
            switch (textptr[1])
5 Plagman 1334
            {
1544 terminx 1335
            case '/': // C++ style comment
1336
                if (!(g_numCompilerErrors || g_numCompilerWarnings) && g_scriptDebug > 1)
1337
                    initprintf("%s:%d: debug: got comment.\n",g_szScriptFileName,g_lineNumber);
1545 terminx 1338
                C_NextLine();
1665 terminx 1339
                continue;
1544 terminx 1340
            case '*': // beginning of a C style comment
1341
                if (!(g_numCompilerErrors || g_numCompilerWarnings) && g_scriptDebug > 1)
1342
                    initprintf("%s:%d: debug: got start of comment block.\n",g_szScriptFileName,g_lineNumber);
1343
                do
1344
                {
1345
                    if (*textptr == '\n')
1346
                        g_lineNumber++;
1347
                    textptr++;
1348
                }
1349
                while (*textptr && (textptr[0] != '*' || textptr[1] != '/'));
1350
 
4680 terminx 1351
                if (EDUKE32_PREDICT_FALSE(!*textptr))
1544 terminx 1352
                {
1353
                    if (!(g_numCompilerErrors || g_numCompilerWarnings) && g_scriptDebug)
1354
                        initprintf("%s:%d: debug: EOF in comment!\n",g_szScriptFileName,g_lineNumber);
1355
                    C_ReportError(-1);
1356
                    initprintf("%s:%d: error: found `/*' with no `*/'.\n",g_szScriptFileName,g_lineNumber);
1857 terminx 1357
                    g_parsingActorPtr = NULL; g_processingState = g_numBraces = 0;
1544 terminx 1358
                    g_numCompilerErrors++;
1665 terminx 1359
                    continue;
1544 terminx 1360
                }
1361
 
1362
                if (!(g_numCompilerErrors || g_numCompilerWarnings) && g_scriptDebug > 1)
1363
                    initprintf("%s:%d: debug: got end of comment block.\n",g_szScriptFileName,g_lineNumber);
1364
 
1365
                textptr+=2;
1665 terminx 1366
                continue;
5 Plagman 1367
            }
1665 terminx 1368
            continue;
1544 terminx 1369
 
1545 terminx 1370
        default:
1371
            if (ispecial(*textptr))
1372
            {
1373
                textptr++;
1665 terminx 1374
                continue;
1545 terminx 1375
            }
1544 terminx 1376
        case 0: // EOF
1377
            return ((g_scriptPtr-script) > (g_scriptSize-32)) ? C_SetScriptSize(g_scriptSize<<1) : 0;
5 Plagman 1378
        }
1046 terminx 1379
    }
1544 terminx 1380
    while (1);
5 Plagman 1381
}
1382
 
1625 terminx 1383
#define GetDefID(szGameLabel) hash_find(&h_gamevars,szGameLabel)
1384
#define GetADefID(szGameLabel) hash_find(&h_arrays,szGameLabel)
1189 terminx 1385
 
2640 helixhorne 1386
static int32_t isaltok(const char c)
5 Plagman 1387
{
1213 terminx 1388
    return (isalnum(c) || c == '{' || c == '}' || c == '/' || c == '\\' ||
1215 terminx 1389
            c == '*' || c == '-' || c == '_' || c == '.');
5 Plagman 1390
}
1391
 
4474 helixhorne 1392
static int32_t C_IsLabelChar(const char c, int32_t i)
1393
{
1394
    return (isalnum(c) || c=='_' || c=='*' || c=='?' ||
1395
            (i > 0 && (c=='+' || c=='-' || c=='.')));
1396
}
1397
 
1206 terminx 1398
static inline int32_t C_GetLabelNameID(const memberlabel_t *pLabel, hashtable_t *tH, const char *psz)
5 Plagman 1399
{
1400
    // find the label psz in the table pLabel.
1401
    // returns the ID for the label, or -1
1402
 
1857 terminx 1403
    int32_t l = hash_findcase(tH,psz);
1404
    return (l >= 0) ? pLabel[l].lId : -1;
5 Plagman 1405
}
1406
 
1206 terminx 1407
static inline int32_t C_GetLabelNameOffset(hashtable_t *tH, const char *psz)
5 Plagman 1408
{
1409
    // find the label psz in the table pLabel.
1410
    // returns the offset in the array for the label, or -1
1411
 
1206 terminx 1412
    return hash_findcase(tH,psz);
5 Plagman 1413
}
1414
 
1143 terminx 1415
static void C_GetNextLabelName(void)
5 Plagman 1416
{
1857 terminx 1417
    int32_t i = 0;
5 Plagman 1418
 
1143 terminx 1419
    C_SkipComments();
5 Plagman 1420
 
4474 helixhorne 1421
//    while (ispecial(*textptr) == 0 && *textptr!='['&& *textptr!=']' && *textptr!='\t' && *textptr!='\n' && *textptr!='\r')
1422
    while (C_IsLabelChar(*textptr, i))
1143 terminx 1423
        label[(g_numLabels<<6)+(i++)] = *(textptr++);
1857 terminx 1424
    label[(g_numLabels<<6)+i] = 0;
5 Plagman 1425
 
1857 terminx 1426
    if (!(g_numCompilerErrors|g_numCompilerWarnings) && g_scriptDebug > 1)
1143 terminx 1427
        initprintf("%s:%d: debug: got label `%s'.\n",g_szScriptFileName,g_lineNumber,label+(g_numLabels<<6));
5 Plagman 1428
}
1429
 
1205 terminx 1430
static int32_t C_GetKeyword(void)
5 Plagman 1431
{
1205 terminx 1432
    int32_t i;
5 Plagman 1433
    char *temptextptr;
1434
 
1143 terminx 1435
    C_SkipComments();
5 Plagman 1436
 
1437
    temptextptr = textptr;
1438
 
1857 terminx 1439
    if (*temptextptr == 0) // EOF
1440
        return -2;
1441
 
333 terminx 1442
    while (isaltok(*temptextptr) == 0)
5 Plagman 1443
    {
1444
        temptextptr++;
333 terminx 1445
        if (*temptextptr == 0)
5 Plagman 1446
            return 0;
1447
    }
1448
 
1449
    i = 0;
333 terminx 1450
    while (isaltok(*temptextptr))
1034 terminx 1451
        tempbuf[i++] = *(temptextptr++);
5 Plagman 1452
    tempbuf[i] = 0;
1857 terminx 1453
 
1625 terminx 1454
    return hash_find(&h_keywords,tempbuf);
5 Plagman 1455
}
1456
 
1205 terminx 1457
static int32_t C_GetNextKeyword(void) //Returns its code #
5 Plagman 1458
{
1205 terminx 1459
    int32_t i, l;
5 Plagman 1460
 
1143 terminx 1461
    C_SkipComments();
5 Plagman 1462
 
1544 terminx 1463
    if (*textptr == 0) // EOF
1857 terminx 1464
        return -2;
5 Plagman 1465
 
1466
    l = 0;
333 terminx 1467
    while (isaltok(*(textptr+l)))
5 Plagman 1468
    {
1469
        tempbuf[l] = textptr[l];
1470
        l++;
1471
    }
1472
    tempbuf[l] = 0;
1473
 
4680 terminx 1474
    if (EDUKE32_PREDICT_TRUE((i = hash_find(&h_keywords,tempbuf)) >= 0))
5 Plagman 1475
    {
1200 terminx 1476
        if (i == CON_LEFTBRACE || i == CON_RIGHTBRACE || i == CON_NULLOP)
1201 terminx 1477
            *g_scriptPtr = i + (IFELSE_MAGIC<<12);
1200 terminx 1478
        else *g_scriptPtr = i + (g_lineNumber<<12);
1393 terminx 1479
 
1450 terminx 1480
        bitptr[(g_scriptPtr-script)>>3] &= ~(BITPTR_POINTER<<((g_scriptPtr-script)&7));
1024 terminx 1481
        textptr += l;
1143 terminx 1482
        g_scriptPtr++;
1393 terminx 1483
 
1143 terminx 1484
        if (!(g_numCompilerErrors || g_numCompilerWarnings) && g_scriptDebug)
1485
            initprintf("%s:%d: debug: translating keyword `%s'.\n",g_szScriptFileName,g_lineNumber,keyw[i]);
1024 terminx 1486
        return i;
5 Plagman 1487
    }
1488
 
1489
    textptr += l;
1857 terminx 1490
    g_numCompilerErrors++;
5 Plagman 1491
 
4680 terminx 1492
    if (EDUKE32_PREDICT_FALSE((tempbuf[0] == '{' || tempbuf[0] == '}') && tempbuf[1] != 0))
5 Plagman 1493
    {
1143 terminx 1494
        C_ReportError(-1);
1857 terminx 1495
        initprintf("%s:%d: error: expected whitespace between `%c' and `%s'.\n",g_szScriptFileName,g_lineNumber,tempbuf[0],tempbuf+1);
5 Plagman 1496
    }
1143 terminx 1497
    else C_ReportError(ERROR_EXPECTEDKEYWORD);
1857 terminx 1498
 
5 Plagman 1499
    return -1;
1500
}
1501
 
2392 helixhorne 1502
static int32_t parse_decimal_number(void)  // (textptr)
1503
{
1504
    // decimal constants -- this is finicky business
1505
    int64_t num = strtoll(textptr, NULL, 10);  // assume long long to be int64_t
1506
 
4680 terminx 1507
    if (EDUKE32_PREDICT_TRUE(num >= INT32_MIN && num <= INT32_MAX))
2392 helixhorne 1508
    {
1509
        // all OK
1510
    }
4680 terminx 1511
    else if (EDUKE32_PREDICT_FALSE(num > INT32_MAX && num <= UINT32_MAX))
2392 helixhorne 1512
    {
1513
        // Number interpreted as uint32, but packed as int32 (on 32-bit archs)
1514
        // (CON code in the wild exists that does this).  Note that such conversion
1515
        // is implementation-defined (C99 6.3.1.3) but GCC does the 'expected' thing.
2742 helixhorne 1516
#if 0
2392 helixhorne 1517
        initprintf("%s:%d: warning: number greater than INT32_MAX converted to a negative one.\n",
1518
                   g_szScriptFileName,g_lineNumber);
1519
        g_numCompilerWarnings++;
2742 helixhorne 1520
#endif
2392 helixhorne 1521
    }
1522
    else
1523
    {
1524
        // out of range, this is arguably worse
1525
 
1526
        initprintf("%s:%d: warning: number out of the range of a 32-bit integer encountered.\n",
1527
                   g_szScriptFileName,g_lineNumber);
1528
        g_numCompilerWarnings++;
1529
    }
1530
 
1531
    return (int32_t)num;
1532
}
1533
 
2751 helixhorne 1534
static int32_t parse_hex_constant(const char *hexnum)
1535
{
1536
    int64_t x;
1537
    sscanf(hexnum, "%" PRIx64 "", &x);
1538
 
4680 terminx 1539
    if (EDUKE32_PREDICT_FALSE(x > UINT32_MAX))
2751 helixhorne 1540
    {
1541
        initprintf("%s:%d: warning: number 0x%" PRIx64 " truncated to 32 bits.\n",
1542
                   g_szScriptFileName,g_lineNumber, x);
1543
        g_numCompilerWarnings++;
1544
    }
1545
 
1546
    return x;
1547
}
1548
 
1205 terminx 1549
static void C_GetNextVarType(int32_t type)
5 Plagman 1550
{
1205 terminx 1551
    int32_t i=0,f=0;
5 Plagman 1552
 
1143 terminx 1553
    C_SkipComments();
1605 terminx 1554
 
1143 terminx 1555
    if (!type && !g_labelsOnly && (isdigit(*textptr) || ((*textptr == '-') && (isdigit(*(textptr+1))))))
5 Plagman 1556
    {
1450 terminx 1557
        bitptr[(g_scriptPtr-script)>>3] &= ~(BITPTR_POINTER<<((g_scriptPtr-script)&7));
2392 helixhorne 1558
 
1559
        *g_scriptPtr++ = MAXGAMEVARS;
1560
 
1561
        if (tolower(textptr[1])=='x')  // hex constants
2751 helixhorne 1562
            *g_scriptPtr = parse_hex_constant(textptr+2);
622 terminx 1563
        else
2392 helixhorne 1564
            *g_scriptPtr = parse_decimal_number();
1565
 
1566
        if (!(g_numCompilerErrors || g_numCompilerWarnings) && g_scriptDebug)
1567
            initprintf("%s:%d: debug: accepted constant %ld in place of gamevar.\n",
1568
                       g_szScriptFileName,g_lineNumber,(long)*g_scriptPtr);
1569
 
1450 terminx 1570
        bitptr[(g_scriptPtr-script)>>3] &= ~(BITPTR_POINTER<<((g_scriptPtr-script)&7));
1143 terminx 1571
        g_scriptPtr++;
1213 terminx 1572
#if 1
1573
        while (!ispecial(*textptr) && *textptr != ']') textptr++;
1574
#else
1143 terminx 1575
        C_GetNextLabelName();
1213 terminx 1576
#endif
5 Plagman 1577
        return;
1578
    }
1034 terminx 1579
    else if ((*textptr == '-')/* && !isdigit(*(textptr+1))*/)
5 Plagman 1580
    {
4680 terminx 1581
        if (EDUKE32_PREDICT_FALSE(type))
5 Plagman 1582
        {
1143 terminx 1583
            g_numCompilerErrors++;
1584
            C_ReportError(ERROR_SYNTAXERROR);
1585
            C_GetNextLabelName();
5 Plagman 1586
            return;
1587
        }
1605 terminx 1588
 
4680 terminx 1589
        if (!(g_numCompilerErrors || g_numCompilerWarnings) && g_scriptDebug)
1590
            initprintf("%s:%d: debug: flagging gamevar as negative.\n", g_szScriptFileName, g_lineNumber); //,Batol(textptr));
1591
        f = (MAXGAMEVARS<<1);
1592
 
1605 terminx 1593
        textptr++;
5 Plagman 1594
    }
2392 helixhorne 1595
 
1143 terminx 1596
    C_GetNextLabelName();
676 terminx 1597
 
4680 terminx 1598
    if (EDUKE32_PREDICT_FALSE(!g_skipKeywordCheck && hash_find(&h_keywords,label+(g_numLabels<<6))>=0))
1024 terminx 1599
    {
1143 terminx 1600
        g_numCompilerErrors++;
1601
        C_ReportError(ERROR_ISAKEYWORD);
1024 terminx 1602
        return;
1603
    }
676 terminx 1604
 
1143 terminx 1605
    C_SkipComments(); //skip comments and whitespace
676 terminx 1606
    if ((*textptr == '['))     //read of array as a gamevar
1607
    {
1205 terminx 1608
        int32_t lLabelID = -1;
1204 terminx 1609
 
715 terminx 1610
        f |= (MAXGAMEVARS<<2);
676 terminx 1611
        textptr++;
1143 terminx 1612
        i=GetADefID(label+(g_numLabels<<6));
715 terminx 1613
        if (i < 0)
676 terminx 1614
        {
1204 terminx 1615
            i=GetDefID(label+(g_numLabels<<6));
1213 terminx 1616
            if (i < g_iSpriteVarID || i > g_iActorVarID)
1204 terminx 1617
                i = -1;
1618
 
4680 terminx 1619
            if (EDUKE32_PREDICT_FALSE(i < 0))
1204 terminx 1620
            {
1621
                g_numCompilerErrors++;
1622
                C_ReportError(ERROR_NOTAGAMEARRAY);
1623
                return;
1624
            }
1625
            f &= ~(MAXGAMEVARS<<2); // not an array
1626
            f |= (MAXGAMEVARS<<3);
676 terminx 1627
        }
1628
 
1450 terminx 1629
        bitptr[(g_scriptPtr-script)>>3] &= ~(BITPTR_POINTER<<((g_scriptPtr-script)&7));
1143 terminx 1630
        *g_scriptPtr++=(i|f);
1631
        C_GetNextVarType(0);
1213 terminx 1632
        C_SkipComments();
715 terminx 1633
 
4680 terminx 1634
        if (EDUKE32_PREDICT_FALSE(*textptr != ']'))
676 terminx 1635
        {
1143 terminx 1636
            g_numCompilerErrors++;
1637
            C_ReportError(ERROR_GAMEARRAYBNC);
676 terminx 1638
            return;
1639
        }
1640
        textptr++;
1213 terminx 1641
 
1642
        //writing arrays in this way is not supported because it would require too many changes to other code
1643
 
4680 terminx 1644
        if (EDUKE32_PREDICT_FALSE(type))
676 terminx 1645
        {
1143 terminx 1646
            g_numCompilerErrors++;
1647
            C_ReportError(ERROR_INVALIDARRAYWRITE);
676 terminx 1648
            return;
1649
        }
1204 terminx 1650
 
1651
        if (f & (MAXGAMEVARS<<3))
1652
        {
1653
            while (*textptr != '.')
1654
            {
1655
                if (*textptr == 0xa)
1656
                    break;
1657
                if (!*textptr)
1658
                    break;
1659
 
1660
                textptr++;
1661
            }
1662
 
4680 terminx 1663
            if (EDUKE32_PREDICT_FALSE(*textptr != '.'))
1204 terminx 1664
            {
1665
                g_numCompilerErrors++;
1666
                C_ReportError(ERROR_SYNTAXERROR);
1667
                return;
1668
            }
1669
            textptr++;
1670
            /// now pointing at 'xxx'
1671
            C_GetNextLabelName();
2538 hendricks2 1672
            /*initprintf("found xxx label of \"%s\"\n",   label+(g_numLabels<<6));*/
1204 terminx 1673
 
1674
            if (i == g_iSpriteVarID)
1642 terminx 1675
                lLabelID=C_GetLabelNameOffset(&actorH,Bstrtolower(label+(g_numLabels<<6)));
1204 terminx 1676
            else if (i == g_iSectorVarID)
1642 terminx 1677
                lLabelID=C_GetLabelNameOffset(&sectorH,Bstrtolower(label+(g_numLabels<<6)));
1204 terminx 1678
            else if (i == g_iWallVarID)
1642 terminx 1679
                lLabelID=C_GetLabelNameOffset(&wallH,Bstrtolower(label+(g_numLabels<<6)));
1204 terminx 1680
            else if (i == g_iPlayerVarID)
1642 terminx 1681
                lLabelID=C_GetLabelNameOffset(&playerH,Bstrtolower(label+(g_numLabels<<6)));
1213 terminx 1682
            else if (i == g_iActorVarID)
1683
                lLabelID=GetDefID(label+(g_numLabels<<6));
1207 terminx 1684
 
1204 terminx 1685
            //printf("LabelID is %d\n",lLabelID);
4680 terminx 1686
            if (EDUKE32_PREDICT_FALSE(lLabelID == -1))
1204 terminx 1687
            {
1688
                g_numCompilerErrors++;
1689
                C_ReportError(ERROR_SYMBOLNOTRECOGNIZED);
1690
                return;
1691
            }
1692
 
1450 terminx 1693
            bitptr[(g_scriptPtr-script)>>3] &= ~(BITPTR_POINTER<<((g_scriptPtr-script)&7));
1204 terminx 1694
 
1695
            if (i == g_iSpriteVarID)
1696
            {
1697
                *g_scriptPtr++=ActorLabels[lLabelID].lId;
1698
 
1699
                //printf("member's flags are: %02Xh\n",ActorLabels[lLabelID].flags);
1700
                if (ActorLabels[lLabelID].flags & LABEL_HASPARM2)
1701
                {
1702
                    //printf("Member has PARM2\n");
1703
                    // get parm2
1704
                    // get the ID of the DEF
1705
                    C_GetNextVarType(0);
1706
                }
1707
            }
1213 terminx 1708
            else if (i == g_iSectorVarID)
1709
                *g_scriptPtr++=SectorLabels[lLabelID].lId;
1710
            else if (i == g_iWallVarID)
1711
                *g_scriptPtr++=SectorLabels[lLabelID].lId;
1204 terminx 1712
            else if (i == g_iPlayerVarID)
1713
            {
1714
                *g_scriptPtr++=PlayerLabels[lLabelID].lId;
1715
 
1716
                //printf("member's flags are: %02Xh\n",ActorLabels[lLabelID].flags);
1717
                if (PlayerLabels[lLabelID].flags & LABEL_HASPARM2)
1718
                {
1719
                    //printf("Member has PARM2\n");
1720
                    // get parm2
1721
                    // get the ID of the DEF
1722
                    C_GetNextVarType(0);
1723
                }
1724
            }
1213 terminx 1725
            else if (i == g_iActorVarID)
1726
                *g_scriptPtr++=lLabelID;
1204 terminx 1727
        }
676 terminx 1728
        return;
1729
    }
1730
//    initprintf("not an array");
1143 terminx 1731
    i=GetDefID(label+(g_numLabels<<6));
676 terminx 1732
    if (i<0)   //gamevar not found
5 Plagman 1733
    {
1143 terminx 1734
        if (!type && !g_labelsOnly)
5 Plagman 1735
        {
676 terminx 1736
            //try looking for a define instead
1143 terminx 1737
            Bstrcpy(tempbuf,label+(g_numLabels<<6));
1625 terminx 1738
            i = hash_find(&h_labels,tempbuf);
4680 terminx 1739
            if (EDUKE32_PREDICT_TRUE(i>=0))
5 Plagman 1740
            {
4680 terminx 1741
                if (EDUKE32_PREDICT_TRUE(labeltype[i] & LABEL_DEFINE))
5 Plagman 1742
                {
1143 terminx 1743
                    if (!(g_numCompilerErrors || g_numCompilerWarnings) && g_scriptDebug)
1744
                        initprintf("%s:%d: debug: accepted defined label `%s' instead of gamevar.\n",g_szScriptFileName,g_lineNumber,label+(i<<6));
1450 terminx 1745
                    bitptr[(g_scriptPtr-script)>>3] &= ~(BITPTR_POINTER<<((g_scriptPtr-script)&7));
2185 helixhorne 1746
                    *g_scriptPtr++ = MAXGAMEVARS;
1450 terminx 1747
                    bitptr[(g_scriptPtr-script)>>3] &= ~(BITPTR_POINTER<<((g_scriptPtr-script)&7));
2185 helixhorne 1748
                    *g_scriptPtr++ = labelcode[i];
5 Plagman 1749
                    return;
1750
                }
1751
            }
1143 terminx 1752
            g_numCompilerErrors++;
1753
            C_ReportError(ERROR_NOTAGAMEVAR);
5 Plagman 1754
            return;
1755
        }
1143 terminx 1756
        g_numCompilerErrors++;
1757
        C_ReportError(ERROR_NOTAGAMEVAR);
437 terminx 1758
        textptr++;
1759
        return;
676 terminx 1760
 
5 Plagman 1761
    }
4680 terminx 1762
    if (EDUKE32_PREDICT_FALSE(type == GAMEVAR_READONLY && aGameVars[i].dwFlags & GAMEVAR_READONLY))
5 Plagman 1763
    {
1143 terminx 1764
        g_numCompilerErrors++;
1765
        C_ReportError(ERROR_VARREADONLY);
5 Plagman 1766
        return;
1767
    }
4680 terminx 1768
    else if (EDUKE32_PREDICT_FALSE(aGameVars[i].dwFlags & type))
5 Plagman 1769
    {
1143 terminx 1770
        g_numCompilerErrors++;
1771
        C_ReportError(ERROR_VARTYPEMISMATCH);
5 Plagman 1772
        return;
1773
    }
1857 terminx 1774
 
1143 terminx 1775
    if (!(g_numCompilerErrors || g_numCompilerWarnings) && g_scriptDebug > 1)
1776
        initprintf("%s:%d: debug: accepted gamevar `%s'.\n",g_szScriptFileName,g_lineNumber,label+(g_numLabels<<6));
715 terminx 1777
 
1450 terminx 1778
    bitptr[(g_scriptPtr-script)>>3] &= ~(BITPTR_POINTER<<((g_scriptPtr-script)&7));
1143 terminx 1779
    *g_scriptPtr++=(i|f);
5 Plagman 1780
}
1781
 
1206 terminx 1782
#define C_GetNextVar() C_GetNextVarType(0)
5 Plagman 1783
 
1205 terminx 1784
static inline void C_GetManyVarsType(int32_t type, int32_t num)
5 Plagman 1785
{
1205 terminx 1786
    int32_t i;
1229 terminx 1787
    for (i=num-1; i>=0; i--)
1143 terminx 1788
        C_GetNextVarType(type);
5 Plagman 1789
}
1790
 
1206 terminx 1791
#define C_GetManyVars(num) C_GetManyVarsType(0,num)
5 Plagman 1792
 
2766 helixhorne 1793
// returns:
1794
//  -1 on EOF or wrong type or error
1795
//   0 if literal value
1796
//   LABEL_* (>0) if that type and matched
1797
//
1798
// *g_scriptPtr will contain the value OR 0 if wrong type or error
1205 terminx 1799
static int32_t C_GetNextValue(int32_t type)
5 Plagman 1800
{
1205 terminx 1801
    int32_t i, l;
5 Plagman 1802
 
1143 terminx 1803
    C_SkipComments();
5 Plagman 1804
 
1544 terminx 1805
    if (*textptr == 0) // EOF
1806
        return -1;
5 Plagman 1807
 
1808
    l = 0;
333 terminx 1809
    while (isaltok(*(textptr+l)))
5 Plagman 1810
    {
1811
        tempbuf[l] = textptr[l];
1812
        l++;
1813
    }
1814
    tempbuf[l] = 0;
1815
 
4680 terminx 1816
    if (EDUKE32_PREDICT_FALSE(!g_skipKeywordCheck && hash_find(&h_keywords,tempbuf /*label+(g_numLabels<<6)*/)>=0))
1024 terminx 1817
    {
1143 terminx 1818
        g_numCompilerErrors++;
1819
        C_ReportError(ERROR_ISAKEYWORD);
1024 terminx 1820
        textptr+=l;
1821
    }
121 terminx 1822
 
1625 terminx 1823
    i = hash_find(&h_labels,tempbuf);
1024 terminx 1824
    if (i>=0)
5 Plagman 1825
    {
1024 terminx 1826
        char *el,*gl;
1827
 
4680 terminx 1828
        if (EDUKE32_PREDICT_TRUE(labeltype[i] & type))
5 Plagman 1829
        {
1143 terminx 1830
            if (!(g_numCompilerErrors || g_numCompilerWarnings) && g_scriptDebug > 1)
5 Plagman 1831
            {
1143 terminx 1832
                gl = (char *)C_GetLabelType(labeltype[i]);
1833
                initprintf("%s:%d: debug: accepted %s label `%s'.\n",g_szScriptFileName,g_lineNumber,gl,label+(i<<6));
1024 terminx 1834
                Bfree(gl);
5 Plagman 1835
            }
2150 helixhorne 1836
 
2185 helixhorne 1837
            bitptr[(g_scriptPtr-script)>>3] &= ~(BITPTR_POINTER<<((g_scriptPtr-script)&7));
1838
            *(g_scriptPtr++) = labelcode[i];
2451 helixhorne 1839
 
5 Plagman 1840
            textptr += l;
1024 terminx 1841
            return labeltype[i];
5 Plagman 1842
        }
4680 terminx 1843
 
1450 terminx 1844
        bitptr[(g_scriptPtr-script)>>3] &= ~(BITPTR_POINTER<<((g_scriptPtr-script)&7));
1143 terminx 1845
        *(g_scriptPtr++) = 0;
1024 terminx 1846
        textptr += l;
1143 terminx 1847
        el = (char *)C_GetLabelType(type);
1848
        gl = (char *)C_GetLabelType(labeltype[i]);
1849
        C_ReportError(-1);
1206 terminx 1850
        initprintf("%s:%d: warning: expected %s, found %s.\n",g_szScriptFileName,g_lineNumber,el,gl);
1143 terminx 1851
        g_numCompilerWarnings++;
1024 terminx 1852
        Bfree(el);
1853
        Bfree(gl);
1854
        return -1;  // valid label name, but wrong type
5 Plagman 1855
    }
1856
 
4680 terminx 1857
    if (EDUKE32_PREDICT_FALSE(isdigit(*textptr) == 0 && *textptr != '-'))
5 Plagman 1858
    {
1143 terminx 1859
        C_ReportError(ERROR_PARAMUNDEFINED);
1860
        g_numCompilerErrors++;
1450 terminx 1861
        bitptr[(g_scriptPtr-script)>>3] &= ~(BITPTR_POINTER<<((g_scriptPtr-script)&7));
1143 terminx 1862
        *g_scriptPtr = 0;
1863
        g_scriptPtr++;
5 Plagman 1864
        textptr+=l;
1865
        return -1; // error!
1866
    }
1867
 
4680 terminx 1868
    if (EDUKE32_PREDICT_FALSE(isdigit(*textptr) && g_labelsOnly))
5 Plagman 1869
    {
1143 terminx 1870
        C_ReportError(WARNING_LABELSONLY);
1871
        g_numCompilerWarnings++;
5 Plagman 1872
    }
1189 terminx 1873
 
1874
    i = l-1;
1875
    do
1876
    {
1207 terminx 1877
        // FIXME: check for 0-9 A-F for hex
1198 terminx 1878
        if (textptr[0] == '0' && textptr[1] == 'x') break; // kill the warning for hex
4680 terminx 1879
        if (EDUKE32_PREDICT_FALSE(!isdigit(textptr[i--])))
1189 terminx 1880
        {
1881
            C_ReportError(-1);
1206 terminx 1882
            initprintf("%s:%d: warning: invalid character `%c' in definition!\n",g_szScriptFileName,g_lineNumber,textptr[i+1]);
1189 terminx 1883
            g_numCompilerWarnings++;
1884
            break;
1885
        }
1886
    }
1887
    while (i > 0);
1888
 
1450 terminx 1889
    bitptr[(g_scriptPtr-script)>>3] &= ~(BITPTR_POINTER<<((g_scriptPtr-script)&7));
1189 terminx 1890
 
1891
    if (tolower(textptr[1])=='x')
2751 helixhorne 1892
        *g_scriptPtr = parse_hex_constant(textptr+2);
622 terminx 1893
    else
2392 helixhorne 1894
        *g_scriptPtr = parse_decimal_number();
1189 terminx 1895
 
2392 helixhorne 1896
    if (!(g_numCompilerErrors || g_numCompilerWarnings) && g_scriptDebug > 1)
1897
        initprintf("%s:%d: debug: accepted constant %ld.\n",
1898
                   g_szScriptFileName,g_lineNumber,(long)*g_scriptPtr);
1899
 
1143 terminx 1900
    g_scriptPtr++;
5 Plagman 1901
 
1902
    textptr += l;
1903
 
1904
    return 0;   // literal value
1905
}
1906
 
1436 terminx 1907
static inline int32_t C_IntPow2(int32_t v)
1908
{
1440 terminx 1909
    return ((v!=0) && (v&(v-1))==0);
1436 terminx 1910
}
1911
 
1912
static inline uint32_t C_Pow2IntLogBase2(int32_t v)
1913
{
1440 terminx 1914
    static const uint32_t b[] = {0xAAAAAAAA, 0xCCCCCCCC, 0xF0F0F0F0,
1915
                                 0xFF00FF00, 0xFFFF0000
1916
                                };
1917
    register uint32_t r = (v & b[0]) != 0;
1918
    int32_t i = 4;
1919
 
1920
    for (; i > 0; i--)
1921
        r |= ((v & b[i]) != 0) << i;
1922
 
1923
    return r;
1436 terminx 1924
}
1925
 
1435 terminx 1926
static int32_t C_CheckMalformedBranch(intptr_t lastScriptPtr)
1927
{
1928
    switch (C_GetKeyword())
1929
    {
1930
    case CON_RIGHTBRACE:
1931
    case CON_ENDA:
1932
    case CON_ENDEVENT:
1933
    case CON_ENDS:
1436 terminx 1934
    case CON_ELSE:
1435 terminx 1935
        g_scriptPtr = lastScriptPtr + &script[0];
1936
        g_ifElseAborted = 1;
1937
        C_ReportError(-1);
1938
        g_numCompilerWarnings++;
1939
        initprintf("%s:%d: warning: malformed `%s' branch\n",g_szScriptFileName,g_lineNumber,
1440 terminx 1940
                   keyw[*(g_scriptPtr) & 0xFFF]);
1435 terminx 1941
        return 1;
1942
    }
1943
    return 0;
1944
}
1945
 
1205 terminx 1946
static int32_t C_CheckEmptyBranch(int32_t tw, intptr_t lastScriptPtr)
1200 terminx 1947
{
2149 helixhorne 1948
    // ifrnd and the others actually do something when the condition is executed
1202 terminx 1949
    if ((Bstrncmp(keyw[tw], "if", 2) && tw != CON_ELSE) ||
2149 helixhorne 1950
            tw == CON_IFRND || tw == CON_IFHITWEAPON || tw == CON_IFCANSEE || tw == CON_IFCANSEETARGET ||
1951
            tw == CON_IFPDISTL || tw == CON_IFPDISTG || tw == CON_IFGOTWEAPONCE)
1200 terminx 1952
    {
1953
        g_ifElseAborted = 0;
1954
        return 0;
1955
    }
1956
 
1201 terminx 1957
    if ((*(g_scriptPtr) & 0xFFF) != CON_NULLOP || *(g_scriptPtr)>>12 != IFELSE_MAGIC)
1200 terminx 1958
        g_ifElseAborted = 0;
1959
 
4680 terminx 1960
    if (EDUKE32_PREDICT_FALSE(g_ifElseAborted))
1200 terminx 1961
    {
1201 terminx 1962
        C_ReportError(-1);
1963
        g_numCompilerWarnings++;
1200 terminx 1964
        g_scriptPtr = lastScriptPtr + &script[0];
1201 terminx 1965
        initprintf("%s:%d: warning: empty `%s' branch\n",g_szScriptFileName,g_lineNumber,
1200 terminx 1966
                   keyw[*(g_scriptPtr) & 0xFFF]);
1435 terminx 1967
        *(g_scriptPtr) = (CON_NULLOP + (IFELSE_MAGIC<<12));
1200 terminx 1968
        return 1;
1969
    }
1970
    return 0;
1971
}
1972
 
1205 terminx 1973
static int32_t C_CountCaseStatements()
5 Plagman 1974
{
1205 terminx 1975
    int32_t lCount;
437 terminx 1976
    char *temptextptr = textptr;
1205 terminx 1977
    int32_t temp_ScriptLineNumber = g_lineNumber;
1143 terminx 1978
    intptr_t scriptoffset = (unsigned)(g_scriptPtr-script);
1979
    intptr_t caseoffset = (unsigned)(g_caseScriptPtr-script);
1205 terminx 1980
//    int32_t i;
5 Plagman 1981
 
1143 terminx 1982
    g_numCases=0;
1983
    g_caseScriptPtr=NULL;
5 Plagman 1984
    //Bsprintf(g_szBuf,"CSS: %.12s",textptr);
1985
    //AddLog(g_szBuf);
1891 terminx 1986
    C_ParseCommand(1);
1143 terminx 1987
    // since we processed the endswitch, we need to re-increment g_checkingSwitch
1988
    g_checkingSwitch++;
5 Plagman 1989
 
1990
    textptr=temptextptr;
1143 terminx 1991
    g_scriptPtr = (intptr_t *)(script+scriptoffset);
5 Plagman 1992
 
1143 terminx 1993
    g_lineNumber = temp_ScriptLineNumber;
5 Plagman 1994
 
1143 terminx 1995
    lCount=g_numCases;
1996
    g_numCases=0;
1997
    g_caseScriptPtr = (intptr_t *)(script+caseoffset);
1998
    g_numCases = 0;
5 Plagman 1999
    return lCount;
2000
}
2001
 
1937 hendricks2 2002
static void C_Include(const char *confile)
2003
{
2004
    int32_t temp_ScriptLineNumber;
2005
    int32_t temp_ifelse_check;
2006
    int32_t j;
2007
    char *origtptr, *mptr;
2008
    char parentScriptFileName[255];
2009
    int32_t fp;
2010
 
2011
    fp = kopen4loadfrommod(confile,g_loadFromGroupOnly);
4680 terminx 2012
    if (EDUKE32_PREDICT_FALSE(fp < 0))
1937 hendricks2 2013
    {
2014
        g_numCompilerErrors++;
2015
        initprintf("%s:%d: error: could not find file `%s'.\n",g_szScriptFileName,g_lineNumber,confile);
2016
        return;
2017
    }
2018
 
2019
    j = kfilelength(fp);
2020
 
4491 helixhorne 2021
    mptr = (char *)Xmalloc(j+1);
1937 hendricks2 2022
 
2023
    initprintf("Including: %s (%d bytes)\n",confile, j);
2024
    kread(fp, mptr, j);
2025
    kclose(fp);
2026
    mptr[j] = 0;
2027
 
2028
    if (*textptr == '"') // skip past the closing quote if it's there so we don't screw up the next line
2029
        textptr++;
2030
    origtptr = textptr;
2031
 
2032
    Bstrcpy(parentScriptFileName, g_szScriptFileName);
2033
    Bstrcpy(g_szScriptFileName, confile);
2034
    temp_ScriptLineNumber = g_lineNumber;
2035
    g_lineNumber = 1;
2036
    temp_ifelse_check = g_checkingIfElse;
2037
    g_checkingIfElse = 0;
2038
 
2039
    textptr = mptr;
2040
 
2041
    C_SkipComments();
2042
 
2043
    C_ParseCommand(1);
2044
 
2045
    Bstrcpy(g_szScriptFileName, parentScriptFileName);
2046
    g_totalLines += g_lineNumber;
2047
    g_lineNumber = temp_ScriptLineNumber;
2048
    g_checkingIfElse = temp_ifelse_check;
2049
 
2050
    textptr = origtptr;
2051
 
2052
    Bfree(mptr);
2053
}
3410 helixhorne 2054
#endif  // !defined LUNATIC
1937 hendricks2 2055
 
2704 helixhorne 2056
#ifdef _WIN32
2057
static void check_filename_case(const char *fn)
2058
{
2059
    int32_t fp;
2060
    if ((fp = kopen4loadfrommod(fn, g_loadFromGroupOnly)) >= 0)
2061
        kclose(fp);
2062
}
2063
#else
2064
static void check_filename_case(const char *fn) { UNREFERENCED_PARAMETER(fn); }
2065
#endif
2066
 
3343 helixhorne 2067
void G_DoGameStartup(const int32_t *params)
2068
{
2069
    int32_t j = 0;
2070
 
2071
    ud.const_visibility = params[j++];
2072
    g_impactDamage = params[j++];
2073
    g_maxPlayerHealth = g_player[0].ps->max_player_health = g_player[0].ps->max_shield_amount = params[j++];
2074
    g_startArmorAmount = params[j++];
2075
    g_actorRespawnTime = params[j++];
3803 terminx 2076
 
2077
    if (g_scriptVersion >= 11)
2078
        g_itemRespawnTime = params[j++];
2079
    else
2080
        g_itemRespawnTime = g_actorRespawnTime;
2081
 
2082
    if (g_scriptVersion >= 11)
2083
        g_playerFriction = params[j++];
2084
 
2085
    if (g_scriptVersion == 14)
2086
        g_spriteGravity = params[j++];
2087
 
2088
    if (g_scriptVersion >= 11)
2089
    {
2090
        g_rpgBlastRadius = params[j++];
2091
        g_pipebombBlastRadius = params[j++];
2092
        g_shrinkerBlastRadius = params[j++];
2093
        g_tripbombBlastRadius = params[j++];
2094
        g_morterBlastRadius = params[j++];
2095
        g_bouncemineBlastRadius = params[j++];
2096
        g_seenineBlastRadius = params[j++];
2097
    }
2098
 
3343 helixhorne 2099
    g_player[0].ps->max_ammo_amount[PISTOL_WEAPON] = params[j++];
2100
    g_player[0].ps->max_ammo_amount[SHOTGUN_WEAPON] = params[j++];
2101
    g_player[0].ps->max_ammo_amount[CHAINGUN_WEAPON] = params[j++];
2102
    g_player[0].ps->max_ammo_amount[RPG_WEAPON] = params[j++];
2103
    g_player[0].ps->max_ammo_amount[HANDBOMB_WEAPON] = params[j++];
2104
    g_player[0].ps->max_ammo_amount[SHRINKER_WEAPON] = params[j++];
2105
    g_player[0].ps->max_ammo_amount[DEVISTATOR_WEAPON] = params[j++];
2106
    g_player[0].ps->max_ammo_amount[TRIPBOMB_WEAPON] = params[j++];
3803 terminx 2107
 
2108
    if (g_scriptVersion >= 13)
3343 helixhorne 2109
    {
3803 terminx 2110
        g_player[0].ps->max_ammo_amount[FREEZE_WEAPON] = params[j++];
3343 helixhorne 2111
 
3803 terminx 2112
        if (g_scriptVersion == 14)
2113
            g_player[0].ps->max_ammo_amount[GROW_WEAPON] = params[j++];
2114
 
2115
        g_damageCameras = params[j++];
2116
        g_numFreezeBounces = params[j++];
2117
        g_freezerSelfDamage = params[j++];
2118
 
2119
        if (g_scriptVersion == 14)
2120
        {
2121
            g_spriteDeleteQueueSize = params[j++];
2122
            g_spriteDeleteQueueSize = clamp(g_spriteDeleteQueueSize, 0, 1024);
2123
 
2124
            g_tripbombLaserMode = params[j++];
2125
        }
3343 helixhorne 2126
    }
2127
}
2128
 
4586 helixhorne 2129
void C_DefineMusic(int32_t vol, int32_t lev, const char *fn)
2130
{
4588 helixhorne 2131
    Bassert((unsigned)vol < MAXVOLUMES+1);
2132
    Bassert((unsigned)lev < MAXLEVELS);
4586 helixhorne 2133
 
2134
    {
4588 helixhorne 2135
        map_t *const map = &MapInfo[(MAXLEVELS*vol)+lev];
4586 helixhorne 2136
 
4588 helixhorne 2137
        Bfree(map->musicfn);
2138
        map->musicfn = dup_filename(fn);
2139
        check_filename_case(map->musicfn);
4586 helixhorne 2140
    }
2141
}
2142
 
3355 helixhorne 2143
#ifdef LUNATIC
2144
void C_DefineSound(int32_t sndidx, const char *fn, int32_t args[5])
2145
{
2146
    Bassert((unsigned)sndidx < MAXSOUNDS);
2147
 
2148
    {
2149
        sound_t *const snd = &g_sounds[sndidx];
2150
 
2151
        Bfree(snd->filename);
2152
        snd->filename = dup_filename(fn);
2153
        check_filename_case(snd->filename);
2154
 
2155
        snd->ps = args[0];
2156
        snd->pe = args[1];
2157
        snd->pr = args[2];
4067 helixhorne 2158
        snd->m = args[3] & ~SF_ONEINST_INTERNAL;
2159
        if (args[3] & SF_LOOP)
2160
            snd->m |= SF_ONEINST_INTERNAL;
3355 helixhorne 2161
        snd->vo = args[4];
2162
 
2163
        if (sndidx > g_maxSoundPos)
2164
            g_maxSoundPos = sndidx;
2165
    }
2166
}
3357 helixhorne 2167
 
2168
void C_DefineQuote(int32_t qnum, const char *qstr)
2169
{
2170
    C_AllocQuote(qnum);
2171
    Bstrncpyz(ScriptQuotes[qnum], qstr, MAXQUOTELEN);
2172
}
3373 helixhorne 2173
 
2174
void C_DefineVolumeName(int32_t vol, const char *name)
2175
{
2176
    Bassert((unsigned)vol < MAXVOLUMES);
2177
    Bstrncpyz(EpisodeNames[vol], name, sizeof(EpisodeNames[vol]));
2178
    g_numVolumes = max(g_numVolumes, vol+1);
2179
}
2180
 
3375 helixhorne 2181
void C_DefineSkillName(int32_t skill, const char *name)
2182
{
2183
    Bassert((unsigned)skill < MAXSKILLS);
2184
    Bstrncpyz(SkillNames[skill], name, sizeof(SkillNames[skill]));
2185
    g_numSkills = max(g_numSkills, skill+1);
2186
}
2187
 
3373 helixhorne 2188
void C_DefineLevelName(int32_t vol, int32_t lev, const char *fn,
2189
                       int32_t partime, int32_t designertime,
2190
                       const char *levelname)
2191
{
2192
    Bassert((unsigned)vol < MAXVOLUMES);
2193
    Bassert((unsigned)lev < MAXLEVELS);
2194
 
2195
    {
2196
        map_t *const map = &MapInfo[(MAXLEVELS*vol)+lev];
2197
 
2198
        Bfree(map->filename);
2199
        map->filename = dup_filename(fn);
2200
 
2201
        // TODO: truncate to 32 chars?
2202
        Bfree(map->name);
4491 helixhorne 2203
        map->name = Xstrdup(levelname);
3373 helixhorne 2204
 
2205
        map->partime = REALGAMETICSPERSEC * partime;
2206
        map->designertime = REALGAMETICSPERSEC * designertime;
2207
    }
2208
}
3516 helixhorne 2209
 
2210
void C_DefineGameFuncName(int32_t idx, const char *name)
2211
{
3826 helixhorne 2212
    assert((unsigned)idx < NUMGAMEFUNCTIONS);
3516 helixhorne 2213
 
2214
    Bstrncpyz(gamefunctions[idx], name, MAXGAMEFUNCLEN);
2215
    Bstrncpyz(keydefaults[3*idx], name, MAXGAMEFUNCLEN);
3530 helixhorne 2216
 
2217
    hash_add(&h_gamefuncs, gamefunctions[idx], idx, 0);
3516 helixhorne 2218
}
3826 helixhorne 2219
 
2220
void C_DefineGameType(int32_t idx, int32_t flags, const char *name)
2221
{
2222
    Bassert((unsigned)idx < MAXGAMETYPES);
2223
 
2224
    GametypeFlags[idx] = flags;
2225
    Bstrncpyz(GametypeNames[idx], name, sizeof(GametypeNames[idx]));
2226
    g_numGametypes = idx+1;
2227
}
3355 helixhorne 2228
#endif
2229
 
4977 hendricks2 2230
void C_UndefineVolume(int32_t vol)
2231
{
2232
    Bassert((unsigned)vol < MAXVOLUMES);
2233
 
2234
    EpisodeNames[vol][0] = '\0';
2235
 
2236
    g_numVolumes = 0;
2237
    for (int32_t i = MAXVOLUMES-1; i >= 0; i--)
2238
    {
2239
        if (EpisodeNames[i]