Subversion Repositories eduke32

Rev

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