Subversion Repositories eduke32

Rev

Rev 5045 | 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",
5045 hendricks2 674
    "EVENT_DISPLAYLEVELSTATS",
5046 hendricks2 675
    "EVENT_DISPLAYCAMERAOSD",
3937 helixhorne 676
#ifdef LUNATIC
677
    "EVENT_ANIMATEALLSPRITES",
678
#endif
2327 helixhorne 679
};
680
 
3410 helixhorne 681
#if !defined LUNATIC
1143 terminx 682
const memberlabel_t SectorLabels[]=
559 terminx 683
{
684
    { "wallptr", SECTOR_WALLPTR, 0, 0 },
685
    { "wallnum", SECTOR_WALLNUM, 0, 0 },
686
    { "ceilingz", SECTOR_CEILINGZ, 0, 0 },
687
    { "floorz", SECTOR_FLOORZ, 0, 0 },
688
    { "ceilingstat", SECTOR_CEILINGSTAT, 0, 0 },
689
    { "floorstat", SECTOR_FLOORSTAT, 0, 0 },
690
    { "ceilingpicnum", SECTOR_CEILINGPICNUM, 0, 0 },
691
    { "ceilingslope", SECTOR_CEILINGSLOPE, 0, 0 },
692
    { "ceilingshade", SECTOR_CEILINGSHADE, 0, 0 },
693
    { "ceilingpal", SECTOR_CEILINGPAL, 0, 0 },
694
    { "ceilingxpanning", SECTOR_CEILINGXPANNING, 0, 0 },
695
    { "ceilingypanning", SECTOR_CEILINGYPANNING, 0, 0 },
696
    { "floorpicnum", SECTOR_FLOORPICNUM, 0, 0 },
697
    { "floorslope", SECTOR_FLOORSLOPE, 0, 0 },
698
    { "floorshade", SECTOR_FLOORSHADE, 0, 0 },
699
    { "floorpal", SECTOR_FLOORPAL, 0, 0 },
700
    { "floorxpanning", SECTOR_FLOORXPANNING, 0, 0 },
701
    { "floorypanning", SECTOR_FLOORYPANNING, 0, 0 },
702
    { "visibility", SECTOR_VISIBILITY, 0, 0 },
4416 helixhorne 703
    { "fogpal", SECTOR_FOGPAL, 0, 0 }, // formerly filler
704
    { "alignto", SECTOR_FOGPAL, 0, 0 }, // formerly filler
559 terminx 705
    { "lotag", SECTOR_LOTAG, 0, 0 },
706
    { "hitag", SECTOR_HITAG, 0, 0 },
707
    { "extra", SECTOR_EXTRA, 0, 0 },
2050 helixhorne 708
    { "ceilingbunch", SECTOR_CEILINGBUNCH, 0, 0 },
709
    { "floorbunch", SECTOR_FLOORBUNCH, 0, 0 },
3192 terminx 710
    { "ulotag", SECTOR_ULOTAG, 0, 0 },
711
    { "uhitag", SECTOR_UHITAG, 0, 0 },
559 terminx 712
    { "", -1, 0, 0  }     // END OF LIST
713
};
5 Plagman 714
 
1143 terminx 715
const memberlabel_t WallLabels[]=
559 terminx 716
{
717
    { "x", WALL_X, 0, 0 },
718
    { "y", WALL_Y, 0, 0 },
719
    { "point2", WALL_POINT2, 0, 0 },
720
    { "nextwall", WALL_NEXTWALL, 0, 0 },
721
    { "nextsector", WALL_NEXTSECTOR, 0, 0 },
722
    { "cstat", WALL_CSTAT, 0, 0 },
723
    { "picnum", WALL_PICNUM, 0, 0 },
724
    { "overpicnum", WALL_OVERPICNUM, 0, 0 },
725
    { "shade", WALL_SHADE, 0, 0 },
726
    { "pal", WALL_PAL, 0, 0 },
727
    { "xrepeat", WALL_XREPEAT, 0, 0 },
728
    { "yrepeat", WALL_YREPEAT, 0, 0 },
729
    { "xpanning", WALL_XPANNING, 0, 0 },
730
    { "ypanning", WALL_YPANNING, 0, 0 },
731
    { "lotag", WALL_LOTAG, 0, 0 },
732
    { "hitag", WALL_HITAG, 0, 0 },
733
    { "extra", WALL_EXTRA, 0, 0 },
3192 terminx 734
    { "ulotag", WALL_ULOTAG, 0, 0 },
735
    { "uhitag", WALL_UHITAG, 0, 0 },
559 terminx 736
    { "", -1, 0, 0  }     // END OF LIST
737
};
5 Plagman 738
 
1143 terminx 739
const memberlabel_t ActorLabels[]=
559 terminx 740
{
741
    { "x", ACTOR_X, 0, 0 },
742
    { "y", ACTOR_Y, 0, 0 },
743
    { "z", ACTOR_Z, 0, 0 },
744
    { "cstat", ACTOR_CSTAT, 0, 0 },
745
    { "picnum", ACTOR_PICNUM, 0, 0 },
746
    { "shade", ACTOR_SHADE, 0, 0 },
747
    { "pal", ACTOR_PAL, 0, 0 },
748
    { "clipdist", ACTOR_CLIPDIST, 0, 0 },
1011 terminx 749
//    { "filler", ACTOR_DETAIL, 0, 0 },
4313 helixhorne 750
    { "blend", ACTOR_DETAIL, 0, 0 },
559 terminx 751
    { "xrepeat", ACTOR_XREPEAT, 0, 0 },
752
    { "yrepeat", ACTOR_YREPEAT, 0, 0 },
753
    { "xoffset", ACTOR_XOFFSET, 0, 0 },
754
    { "yoffset", ACTOR_YOFFSET, 0, 0 },
755
    { "sectnum", ACTOR_SECTNUM, 0, 0 },
756
    { "statnum", ACTOR_STATNUM, 0, 0 },
757
    { "ang", ACTOR_ANG, 0, 0 },
758
    { "owner", ACTOR_OWNER, 0, 0 },
759
    { "xvel", ACTOR_XVEL, 0, 0 },
760
    { "yvel", ACTOR_YVEL, 0, 0 },
761
    { "zvel", ACTOR_ZVEL, 0, 0 },
762
    { "lotag", ACTOR_LOTAG, 0, 0 },
763
    { "hitag", ACTOR_HITAG, 0, 0 },
764
    { "extra", ACTOR_EXTRA, 0, 0 },
5 Plagman 765
 
1143 terminx 766
    // ActorExtra labels...
559 terminx 767
    { "htcgg", ACTOR_HTCGG, 0, 0 },
768
    { "htpicnum", ACTOR_HTPICNUM, 0, 0 },
769
    { "htang", ACTOR_HTANG, 0, 0 },
770
    { "htextra", ACTOR_HTEXTRA, 0, 0 },
771
    { "htowner", ACTOR_HTOWNER, 0, 0 },
772
    { "htmovflag", ACTOR_HTMOVFLAG, 0, 0 },
773
    { "httempang", ACTOR_HTTEMPANG, 0, 0 },
774
    { "htactorstayput", ACTOR_HTACTORSTAYPUT, 0, 0 },
775
    { "htdispicnum", ACTOR_HTDISPICNUM, 0, 0 },
776
    { "httimetosleep", ACTOR_HTTIMETOSLEEP, 0, 0 },
777
    { "htfloorz", ACTOR_HTFLOORZ, 0, 0 },
778
    { "htceilingz", ACTOR_HTCEILINGZ, 0, 0 },
779
    { "htlastvx", ACTOR_HTLASTVX, 0, 0 },
780
    { "htlastvy", ACTOR_HTLASTVY, 0, 0 },
781
    { "htbposx", ACTOR_HTBPOSX, 0, 0 },
782
    { "htbposy", ACTOR_HTBPOSY, 0, 0 },
783
    { "htbposz", ACTOR_HTBPOSZ, 0, 0 },
870 terminx 784
    { "htg_t", ACTOR_HTG_T, LABEL_HASPARM2, 10 },
5 Plagman 785
 
559 terminx 786
    // model flags
5 Plagman 787
 
559 terminx 788
    { "angoff", ACTOR_ANGOFF, 0, 0 },
789
    { "pitch", ACTOR_PITCH, 0, 0 },
790
    { "roll", ACTOR_ROLL, 0, 0 },
791
    { "mdxoff", ACTOR_MDXOFF, 0, 0 },
792
    { "mdyoff", ACTOR_MDYOFF, 0, 0 },
793
    { "mdzoff", ACTOR_MDZOFF, 0, 0 },
794
    { "mdflags", ACTOR_MDFLAGS, 0, 0 },
590 plagman 795
    { "xpanning", ACTOR_XPANNING, 0, 0 },
796
    { "ypanning", ACTOR_YPANNING, 0, 0 },
853 terminx 797
 
939 terminx 798
    { "htflags", ACTOR_HTFLAGS, 0, 0 },
799
 
1344 terminx 800
    { "alpha", ACTOR_ALPHA, 0, 0 },
1341 terminx 801
 
3192 terminx 802
    { "ulotag", ACTOR_ULOTAG, 0, 0 },
803
    { "uhitag", ACTOR_UHITAG, 0, 0 },
804
 
4146 helixhorne 805
    { "isvalid", ACTOR_ISVALID, 0, 0 },
4313 helixhorne 806
// aliases:
4448 helixhorne 807
    { "movflags", ACTOR_HITAG, 0, 0 },
4313 helixhorne 808
    { "detail", ACTOR_DETAIL, 0, 0 },  // deprecated name for 'blend'
4146 helixhorne 809
 
856 terminx 810
    { "", -1, 0, 0  }     // END OF LIST
811
};
812
 
1143 terminx 813
const memberlabel_t TsprLabels[]=
856 terminx 814
{
853 terminx 815
    // tsprite access
816
 
1007 hnt_ts 817
    { "tsprx", ACTOR_X, 0, 0 },
818
    { "tspry", ACTOR_Y, 0, 0 },
819
    { "tsprz", ACTOR_Z, 0, 0 },
820
    { "tsprcstat", ACTOR_CSTAT, 0, 0 },
821
    { "tsprpicnum", ACTOR_PICNUM, 0, 0 },
822
    { "tsprshade", ACTOR_SHADE, 0, 0 },
823
    { "tsprpal", ACTOR_PAL, 0, 0 },
824
    { "tsprclipdist", ACTOR_CLIPDIST, 0, 0 },
1011 terminx 825
//    { "tsprfiller", ACTOR_DETAIL, 0, 0 },
4313 helixhorne 826
    { "tsprblend", ACTOR_DETAIL, 0, 0 },
1007 hnt_ts 827
    { "tsprxrepeat", ACTOR_XREPEAT, 0, 0 },
828
    { "tspryrepeat", ACTOR_YREPEAT, 0, 0 },
829
    { "tsprxoffset", ACTOR_XOFFSET, 0, 0 },
830
    { "tspryoffset", ACTOR_YOFFSET, 0, 0 },
831
    { "tsprsectnum", ACTOR_SECTNUM, 0, 0 },
832
    { "tsprstatnum", ACTOR_STATNUM, 0, 0 },
833
    { "tsprang", ACTOR_ANG, 0, 0 },
834
    { "tsprowner", ACTOR_OWNER, 0, 0 },
835
#if 1
836
    { "tsprxvel", ACTOR_XVEL, 0, 0 },
837
    { "tspryvel", ACTOR_YVEL, 0, 0 },
838
    { "tsprzvel", ACTOR_ZVEL, 0, 0 },
839
    { "tsprlotag", ACTOR_LOTAG, 0, 0 },
840
    { "tsprhitag", ACTOR_HITAG, 0, 0 },
841
    { "tsprextra", ACTOR_EXTRA, 0, 0 },
842
#endif
4313 helixhorne 843
// aliases:
844
    { "tsprdetail", ACTOR_DETAIL, 0, 0 },  // deprecated name for 'tsprblend'
853 terminx 845
 
559 terminx 846
    { "", -1, 0, 0  }     // END OF LIST
847
};
5 Plagman 848
 
1143 terminx 849
const memberlabel_t PlayerLabels[]=
559 terminx 850
{
851
    { "zoom", PLAYER_ZOOM, 0, 0 },
852
    { "exitx", PLAYER_EXITX, 0, 0 },
853
    { "exity", PLAYER_EXITY, 0, 0 },
870 terminx 854
    { "loogiex", PLAYER_LOOGIEX, LABEL_HASPARM2, 64 },
855
    { "loogiey", PLAYER_LOOGIEY, LABEL_HASPARM2, 64 },
559 terminx 856
    { "numloogs", PLAYER_NUMLOOGS, 0, 0 },
857
    { "loogcnt", PLAYER_LOOGCNT, 0, 0 },
858
    { "posx", PLAYER_POSX, 0, 0 },
859
    { "posy", PLAYER_POSY, 0, 0 },
860
    { "posz", PLAYER_POSZ, 0, 0 },
861
    { "horiz", PLAYER_HORIZ, 0, 0 },
862
    { "ohoriz", PLAYER_OHORIZ, 0, 0 },
863
    { "ohorizoff", PLAYER_OHORIZOFF, 0, 0 },
864
    { "invdisptime", PLAYER_INVDISPTIME, 0, 0 },
865
    { "bobposx", PLAYER_BOBPOSX, 0, 0 },
866
    { "bobposy", PLAYER_BOBPOSY, 0, 0 },
867
    { "oposx", PLAYER_OPOSX, 0, 0 },
868
    { "oposy", PLAYER_OPOSY, 0, 0 },
869
    { "oposz", PLAYER_OPOSZ, 0, 0 },
870
    { "pyoff", PLAYER_PYOFF, 0, 0 },
871
    { "opyoff", PLAYER_OPYOFF, 0, 0 },
872
    { "posxv", PLAYER_POSXV, 0, 0 },
873
    { "posyv", PLAYER_POSYV, 0, 0 },
874
    { "poszv", PLAYER_POSZV, 0, 0 },
875
    { "last_pissed_time", PLAYER_LAST_PISSED_TIME, 0, 0 },
876
    { "truefz", PLAYER_TRUEFZ, 0, 0 },
877
    { "truecz", PLAYER_TRUECZ, 0, 0 },
878
    { "player_par", PLAYER_PLAYER_PAR, 0, 0 },
879
    { "visibility", PLAYER_VISIBILITY, 0, 0 },
880
    { "bobcounter", PLAYER_BOBCOUNTER, 0, 0 },
881
    { "weapon_sway", PLAYER_WEAPON_SWAY, 0, 0 },
882
    { "pals_time", PLAYER_PALS_TIME, 0, 0 },
883
    { "randomflamex", PLAYER_RANDOMFLAMEX, 0, 0 },
884
    { "crack_time", PLAYER_CRACK_TIME, 0, 0 },
885
    { "aim_mode", PLAYER_AIM_MODE, 0, 0 },
886
    { "ang", PLAYER_ANG, 0, 0 },
887
    { "oang", PLAYER_OANG, 0, 0 },
888
    { "angvel", PLAYER_ANGVEL, 0, 0 },
889
    { "cursectnum", PLAYER_CURSECTNUM, 0, 0 },
890
    { "look_ang", PLAYER_LOOK_ANG, 0, 0 },
891
    { "last_extra", PLAYER_LAST_EXTRA, 0, 0 },
892
    { "subweapon", PLAYER_SUBWEAPON, 0, 0 },
893
    { "ammo_amount", PLAYER_AMMO_AMOUNT, LABEL_HASPARM2, MAX_WEAPONS },
894
    { "wackedbyactor", PLAYER_WACKEDBYACTOR, 0, 0 },
895
    { "frag", PLAYER_FRAG, 0, 0 },
896
    { "fraggedself", PLAYER_FRAGGEDSELF, 0, 0 },
897
    { "curr_weapon", PLAYER_CURR_WEAPON, 0, 0 },
898
    { "last_weapon", PLAYER_LAST_WEAPON, 0, 0 },
899
    { "tipincs", PLAYER_TIPINCS, 0, 0 },
900
    { "horizoff", PLAYER_HORIZOFF, 0, 0 },
901
    { "wantweaponfire", PLAYER_WANTWEAPONFIRE, 0, 0 },
902
    { "holoduke_amount", PLAYER_HOLODUKE_AMOUNT, 0, 0 },
903
    { "newowner", PLAYER_NEWOWNER, 0, 0 },
904
    { "hurt_delay", PLAYER_HURT_DELAY, 0, 0 },
905
    { "hbomb_hold_delay", PLAYER_HBOMB_HOLD_DELAY, 0, 0 },
906
    { "jumping_counter", PLAYER_JUMPING_COUNTER, 0, 0 },
907
    { "airleft", PLAYER_AIRLEFT, 0, 0 },
908
    { "knee_incs", PLAYER_KNEE_INCS, 0, 0 },
909
    { "access_incs", PLAYER_ACCESS_INCS, 0, 0 },
910
    { "fta", PLAYER_FTA, 0, 0 },
911
    { "ftq", PLAYER_FTQ, 0, 0 },
912
    { "access_wallnum", PLAYER_ACCESS_WALLNUM, 0, 0 },
913
    { "access_spritenum", PLAYER_ACCESS_SPRITENUM, 0, 0 },
914
    { "kickback_pic", PLAYER_KICKBACK_PIC, 0, 0 },
915
    { "got_access", PLAYER_GOT_ACCESS, 0, 0 },
916
    { "weapon_ang", PLAYER_WEAPON_ANG, 0, 0 },
917
    { "firstaid_amount", PLAYER_FIRSTAID_AMOUNT, 0, 0 },
918
    { "somethingonplayer", PLAYER_SOMETHINGONPLAYER, 0, 0 },
919
    { "on_crane", PLAYER_ON_CRANE, 0, 0 },
920
    { "i", PLAYER_I, 0, 0 },
921
    { "one_parallax_sectnum", PLAYER_ONE_PARALLAX_SECTNUM, 0, 0 },
922
    { "over_shoulder_on", PLAYER_OVER_SHOULDER_ON, 0, 0 },
923
    { "random_club_frame", PLAYER_RANDOM_CLUB_FRAME, 0, 0 },
924
    { "fist_incs", PLAYER_FIST_INCS, 0, 0 },
925
    { "one_eighty_count", PLAYER_ONE_EIGHTY_COUNT, 0, 0 },
926
    { "cheat_phase", PLAYER_CHEAT_PHASE, 0, 0 },
927
    { "dummyplayersprite", PLAYER_DUMMYPLAYERSPRITE, 0, 0 },
928
    { "extra_extra8", PLAYER_EXTRA_EXTRA8, 0, 0 },
929
    { "quick_kick", PLAYER_QUICK_KICK, 0, 0 },
930
    { "heat_amount", PLAYER_HEAT_AMOUNT, 0, 0 },
931
    { "actorsqu", PLAYER_ACTORSQU, 0, 0 },
932
    { "timebeforeexit", PLAYER_TIMEBEFOREEXIT, 0, 0 },
933
    { "customexitsound", PLAYER_CUSTOMEXITSOUND, 0, 0 },
1625 terminx 934
    { "weaprecs", PLAYER_WEAPRECS, LABEL_HASPARM2, MAX_WEAPONS },
559 terminx 935
    { "weapreccnt", PLAYER_WEAPRECCNT, 0, 0 },
936
    { "interface_toggle_flag", PLAYER_INTERFACE_TOGGLE_FLAG, 0, 0 },
937
    { "rotscrnang", PLAYER_ROTSCRNANG, 0, 0 },
938
    { "dead_flag", PLAYER_DEAD_FLAG, 0, 0 },
939
    { "show_empty_weapon", PLAYER_SHOW_EMPTY_WEAPON, 0, 0 },
940
    { "scuba_amount", PLAYER_SCUBA_AMOUNT, 0, 0 },
941
    { "jetpack_amount", PLAYER_JETPACK_AMOUNT, 0, 0 },
942
    { "steroids_amount", PLAYER_STEROIDS_AMOUNT, 0, 0 },
943
    { "shield_amount", PLAYER_SHIELD_AMOUNT, 0, 0 },
944
    { "holoduke_on", PLAYER_HOLODUKE_ON, 0, 0 },
945
    { "pycount", PLAYER_PYCOUNT, 0, 0 },
946
    { "weapon_pos", PLAYER_WEAPON_POS, 0, 0 },
947
    { "frag_ps", PLAYER_FRAG_PS, 0, 0 },
948
    { "transporter_hold", PLAYER_TRANSPORTER_HOLD, 0, 0 },
949
    { "last_full_weapon", PLAYER_LAST_FULL_WEAPON, 0, 0 },
950
    { "footprintshade", PLAYER_FOOTPRINTSHADE, 0, 0 },
951
    { "boot_amount", PLAYER_BOOT_AMOUNT, 0, 0 },
952
    { "scream_voice", PLAYER_SCREAM_VOICE, 0, 0 },
953
    { "gm", PLAYER_GM, 0, 0 },
954
    { "on_warping_sector", PLAYER_ON_WARPING_SECTOR, 0, 0 },
955
    { "footprintcount", PLAYER_FOOTPRINTCOUNT, 0, 0 },
956
    { "hbomb_on", PLAYER_HBOMB_ON, 0, 0 },
957
    { "jumping_toggle", PLAYER_JUMPING_TOGGLE, 0, 0 },
958
    { "rapid_fire_hold", PLAYER_RAPID_FIRE_HOLD, 0, 0 },
959
    { "on_ground", PLAYER_ON_GROUND, 0, 0 },
960
    { "name", PLAYER_NAME,  LABEL_ISSTRING, 32 },
961
    { "inven_icon", PLAYER_INVEN_ICON, 0, 0 },
962
    { "buttonpalette", PLAYER_BUTTONPALETTE, 0, 0 },
963
    { "jetpack_on", PLAYER_JETPACK_ON, 0, 0 },
964
    { "spritebridge", PLAYER_SPRITEBRIDGE, 0, 0 },
965
    { "lastrandomspot", PLAYER_LASTRANDOMSPOT, 0, 0 },
966
    { "scuba_on", PLAYER_SCUBA_ON, 0, 0 },
967
    { "footprintpal", PLAYER_FOOTPRINTPAL, 0, 0 },
968
    { "heat_on", PLAYER_HEAT_ON, 0, 0 },
969
    { "holster_weapon", PLAYER_HOLSTER_WEAPON, 0, 0 },
970
    { "falling_counter", PLAYER_FALLING_COUNTER, 0, 0 },
971
    { "gotweapon", PLAYER_GOTWEAPON, LABEL_HASPARM2, MAX_WEAPONS },
972
    { "refresh_inventory", PLAYER_REFRESH_INVENTORY, 0, 0 },
973
    { "palette", PLAYER_PALETTE, 0, 0 },
974
    { "toggle_key_flag", PLAYER_TOGGLE_KEY_FLAG, 0, 0 },
975
    { "knuckle_incs", PLAYER_KNUCKLE_INCS, 0, 0 },
976
    { "walking_snd_toggle", PLAYER_WALKING_SND_TOGGLE, 0, 0 },
977
    { "palookup", PLAYER_PALOOKUP, 0, 0 },
978
    { "hard_landing", PLAYER_HARD_LANDING, 0, 0 },
979
    { "max_secret_rooms", PLAYER_MAX_SECRET_ROOMS, 0, 0 },
980
    { "secret_rooms", PLAYER_SECRET_ROOMS, 0, 0 },
869 terminx 981
    { "pals", PLAYER_PALS, LABEL_HASPARM2, 3 },
559 terminx 982
    { "max_actors_killed", PLAYER_MAX_ACTORS_KILLED, 0, 0 },
983
    { "actors_killed", PLAYER_ACTORS_KILLED, 0, 0 },
984
    { "return_to_center", PLAYER_RETURN_TO_CENTER, 0, 0 },
985
    { "runspeed", PLAYER_RUNSPEED, 0, 0 },
986
    { "sbs", PLAYER_SBS, 0, 0 },
987
    { "reloading", PLAYER_RELOADING, 0, 0 },
988
    { "auto_aim", PLAYER_AUTO_AIM, 0, 0 },
989
    { "movement_lock", PLAYER_MOVEMENT_LOCK, 0, 0 },
990
    { "sound_pitch", PLAYER_SOUND_PITCH, 0, 0 },
991
    { "weaponswitch", PLAYER_WEAPONSWITCH, 0, 0 },
992
    { "team", PLAYER_TEAM, 0, 0 },
566 terminx 993
    { "max_player_health", PLAYER_MAX_PLAYER_HEALTH, 0, 0 },
994
    { "max_shield_amount", PLAYER_MAX_SHIELD_AMOUNT, 0, 0 },
995
    { "max_ammo_amount", PLAYER_MAX_AMMO_AMOUNT, LABEL_HASPARM2, MAX_WEAPONS },
1062 terminx 996
    { "last_quick_kick", PLAYER_LAST_QUICK_KICK, 0, 0 },
3100 hendricks2 997
    { "autostep", PLAYER_AUTOSTEP, 0, 0 },
998
    { "autostep_sbw", PLAYER_AUTOSTEP_SBW, 0, 0 },
559 terminx 999
    { "", -1, 0, 0  }     // END OF LIST
1000
};
5 Plagman 1001
 
1143 terminx 1002
const memberlabel_t ProjectileLabels[]=
559 terminx 1003
{
1004
    { "workslike", PROJ_WORKSLIKE, 0, 0 },
1005
    { "spawns", PROJ_SPAWNS, 0, 0 },
1006
    { "sxrepeat", PROJ_SXREPEAT, 0, 0 },
1007
    { "syrepeat", PROJ_SYREPEAT, 0, 0 },
1008
    { "sound", PROJ_SOUND, 0, 0 },
1009
    { "isound", PROJ_ISOUND, 0, 0 },
1010
    { "vel", PROJ_VEL, 0, 0 },
1011
    { "extra", PROJ_EXTRA, 0, 0 },
1012
    { "decal", PROJ_DECAL, 0, 0 },
1013
    { "trail", PROJ_TRAIL, 0, 0 },
1014
    { "txrepeat", PROJ_TXREPEAT, 0, 0 },
1015
    { "tyrepeat", PROJ_TYREPEAT, 0, 0 },
1016
    { "toffset", PROJ_TOFFSET, 0, 0 },
1017
    { "tnum", PROJ_TNUM, 0, 0 },
1018
    { "drop", PROJ_DROP, 0, 0 },
1019
    { "cstat", PROJ_CSTAT, 0, 0 },
1020
    { "clipdist", PROJ_CLIPDIST, 0, 0 },
1021
    { "shade", PROJ_SHADE, 0, 0 },
1022
    { "xrepeat", PROJ_XREPEAT, 0, 0 },
1023
    { "yrepeat", PROJ_YREPEAT, 0, 0 },
1024
    { "pal", PROJ_PAL, 0, 0 },
1025
    { "extra_rand", PROJ_EXTRA_RAND, 0, 0 },
1026
    { "hitradius", PROJ_HITRADIUS, 0, 0 },
3053 terminx 1027
    { "velmult", PROJ_MOVECNT, 0, 0 },
559 terminx 1028
    { "offset", PROJ_OFFSET, 0, 0 },
1029
    { "bounces", PROJ_BOUNCES, 0, 0 },
1030
    { "bsound", PROJ_BSOUND, 0, 0 },
1031
    { "range", PROJ_RANGE, 0, 0 },
1315 terminx 1032
    { "flashcolor", PROJ_FLASH_COLOR, 0, 0 },
3866 helixhorne 1033
    { "userdata", PROJ_USERDATA, 0, 0 },
559 terminx 1034
    { "", -1, 0, 0  }     // END OF LIST
1035
};
5 Plagman 1036
 
1143 terminx 1037
const memberlabel_t UserdefsLabels[]=
559 terminx 1038
{
1039
    //        { "<null>", 1, 0, 0 },
1040
    { "god", USERDEFS_GOD, 0, 0 },
1041
    { "warp_on", USERDEFS_WARP_ON, 0, 0 },
1042
    { "cashman", USERDEFS_CASHMAN, 0, 0 },
1043
    { "eog", USERDEFS_EOG, 0, 0 },
1044
    { "showallmap", USERDEFS_SHOWALLMAP, 0, 0 },
1045
    { "show_help", USERDEFS_SHOW_HELP, 0, 0 },
1046
    { "scrollmode", USERDEFS_SCROLLMODE, 0, 0 },
1047
    { "clipping", USERDEFS_CLIPPING, 0, 0 },
1048
    { "user_name", USERDEFS_USER_NAME, LABEL_HASPARM2, MAXPLAYERS },
1049
    { "ridecule", USERDEFS_RIDECULE, LABEL_HASPARM2 | LABEL_ISSTRING, 10 },
1050
    { "savegame", USERDEFS_SAVEGAME, LABEL_HASPARM2 | LABEL_ISSTRING, 10 },
1051
    { "pwlockout", USERDEFS_PWLOCKOUT, LABEL_ISSTRING, 128 },
1052
    { "rtsname;", USERDEFS_RTSNAME,  LABEL_ISSTRING, 128 },
1053
    { "overhead_on", USERDEFS_OVERHEAD_ON, 0, 0 },
1054
    { "last_overhead", USERDEFS_LAST_OVERHEAD, 0, 0 },
1055
    { "showweapons", USERDEFS_SHOWWEAPONS, 0, 0 },
5 Plagman 1056
 
559 terminx 1057
    { "pause_on", USERDEFS_PAUSE_ON, 0, 0 },
1058
    { "from_bonus", USERDEFS_FROM_BONUS, 0, 0 },
1059
    { "camerasprite", USERDEFS_CAMERASPRITE, 0, 0 },
1060
    { "last_camsprite", USERDEFS_LAST_CAMSPRITE, 0, 0 },
1061
    { "last_level", USERDEFS_LAST_LEVEL, 0, 0 },
1062
    { "secretlevel", USERDEFS_SECRETLEVEL, 0, 0 },
4968 hendricks2 1063
    { "playerbest", USERDEFS_PLAYERBEST, 0, 0 },
5 Plagman 1064
 
559 terminx 1065
    { "const_visibility", USERDEFS_CONST_VISIBILITY, 0, 0 },
1066
    { "uw_framerate", USERDEFS_UW_FRAMERATE, 0, 0 },
1067
    { "camera_time", USERDEFS_CAMERA_TIME, 0, 0 },
1068
    { "folfvel", USERDEFS_FOLFVEL, 0, 0 },
1069
    { "folavel", USERDEFS_FOLAVEL, 0, 0 },
1070
    { "folx", USERDEFS_FOLX, 0, 0 },
1071
    { "foly", USERDEFS_FOLY, 0, 0 },
1072
    { "fola", USERDEFS_FOLA, 0, 0 },
1073
    { "reccnt", USERDEFS_RECCNT, 0, 0 },
5 Plagman 1074
 
4945 hendricks2 1075
    { "m_origin_x", USERDEFS_M_ORIGIN_X, 0, 0 },
1076
    { "m_origin_y", USERDEFS_M_ORIGIN_Y, 0, 0 },
1077
 
5043 hendricks2 1078
    { "usevoxels", USERDEFS_USEVOXELS, 0, 0 },
1079
    { "usehightile", USERDEFS_USEHIGHTILE, 0, 0 },
1080
    { "usemodels", USERDEFS_USEMODELS, 0, 0 },
1081
 
559 terminx 1082
    { "entered_name", USERDEFS_ENTERED_NAME, 0, 0 },
1083
    { "screen_tilting", USERDEFS_SCREEN_TILTING, 0, 0 },
1084
    { "shadows", USERDEFS_SHADOWS, 0, 0 },
1085
    { "fta_on", USERDEFS_FTA_ON, 0, 0 },
1086
    { "executions", USERDEFS_EXECUTIONS, 0, 0 },
1087
    { "auto_run", USERDEFS_AUTO_RUN, 0, 0 },
1088
    { "coords", USERDEFS_COORDS, 0, 0 },
1089
    { "tickrate", USERDEFS_TICKRATE, 0, 0 },
1090
    { "m_coop", USERDEFS_M_COOP, 0, 0 },
1091
    { "coop", USERDEFS_COOP, 0, 0 },
1092
    { "screen_size", USERDEFS_SCREEN_SIZE, 0, 0 },
1093
    { "lockout", USERDEFS_LOCKOUT, 0, 0 },
1094
    { "crosshair", USERDEFS_CROSSHAIR, 0, 0 },
4215 helixhorne 1095
//    { "wchoice[MAXPLAYERS][MAX_WEAPONS]", USERDEFS_WCHOICE, 0, 0 },
559 terminx 1096
    { "playerai", USERDEFS_PLAYERAI, 0, 0 },
1097
    { "respawn_monsters", USERDEFS_RESPAWN_MONSTERS, 0, 0 },
1098
    { "respawn_items", USERDEFS_RESPAWN_ITEMS, 0, 0 },
1099
    { "respawn_inventory", USERDEFS_RESPAWN_INVENTORY, 0, 0 },
1100
    { "recstat", USERDEFS_RECSTAT, 0, 0 },
1101
    { "monsters_off", USERDEFS_MONSTERS_OFF, 0, 0 },
1102
    { "brightness", USERDEFS_BRIGHTNESS, 0, 0 },
1103
    { "m_respawn_items", USERDEFS_M_RESPAWN_ITEMS, 0, 0 },
1104
    { "m_respawn_monsters", USERDEFS_M_RESPAWN_MONSTERS, 0, 0 },
1105
    { "m_respawn_inventory", USERDEFS_M_RESPAWN_INVENTORY, 0, 0 },
1106
    { "m_recstat", USERDEFS_M_RECSTAT, 0, 0 },
1107
    { "m_monsters_off", USERDEFS_M_MONSTERS_OFF, 0, 0 },
1108
    { "detail", USERDEFS_DETAIL, 0, 0 },
1109
    { "m_ffire", USERDEFS_M_FFIRE, 0, 0 },
1110
    { "ffire", USERDEFS_FFIRE, 0, 0 },
1111
    { "m_player_skill", USERDEFS_M_PLAYER_SKILL, 0, 0 },
1112
    { "m_level_number", USERDEFS_M_LEVEL_NUMBER, 0, 0 },
1113
    { "m_volume_number", USERDEFS_M_VOLUME_NUMBER, 0, 0 },
1114
    { "multimode", USERDEFS_MULTIMODE, 0, 0 },
1115
    { "player_skill", USERDEFS_PLAYER_SKILL, 0, 0 },
1116
    { "level_number", USERDEFS_LEVEL_NUMBER, 0, 0 },
1117
    { "volume_number", USERDEFS_VOLUME_NUMBER, 0, 0 },
1118
    { "m_marker", USERDEFS_M_MARKER, 0, 0 },
1119
    { "marker", USERDEFS_MARKER, 0, 0 },
1120
    { "mouseflip", USERDEFS_MOUSEFLIP, 0, 0 },
1121
    { "statusbarscale", USERDEFS_STATUSBARSCALE, 0, 0 },
1122
    { "drawweapon", USERDEFS_DRAWWEAPON, 0, 0 },
1123
    { "mouseaiming", USERDEFS_MOUSEAIMING, 0, 0 },
1124
    { "weaponswitch", USERDEFS_WEAPONSWITCH, 0, 0 },
1125
    { "democams", USERDEFS_DEMOCAMS, 0, 0 },
1126
    { "color", USERDEFS_COLOR, 0, 0 },
1127
    { "msgdisptime", USERDEFS_MSGDISPTIME, 0, 0 },
1128
    { "statusbarmode", USERDEFS_STATUSBARMODE, 0, 0 },
1129
    { "m_noexits", USERDEFS_M_NOEXITS, 0, 0 },
1130
    { "noexits", USERDEFS_NOEXITS, 0, 0 },
1131
    { "autovote", USERDEFS_AUTOVOTE, 0, 0 },
1132
    { "automsg", USERDEFS_AUTOMSG, 0, 0 },
1133
    { "idplayers", USERDEFS_IDPLAYERS, 0, 0 },
1134
    { "team", USERDEFS_TEAM, 0, 0 },
1135
    { "viewbob", USERDEFS_VIEWBOB, 0, 0 },
1136
    { "weaponsway", USERDEFS_WEAPONSWAY, 0, 0 },
1137
    { "angleinterpolation", USERDEFS_ANGLEINTERPOLATION, 0, 0 },
926 terminx 1138
    { "obituaries", USERDEFS_OBITUARIES, 0, 0 },
674 terminx 1139
    { "levelstats", USERDEFS_LEVELSTATS, 0, 0 },
881 terminx 1140
    { "crosshairscale", USERDEFS_CROSSHAIRSCALE, 0, 0 },
934 terminx 1141
    { "althud", USERDEFS_ALTHUD, 0, 0 },
990 terminx 1142
    { "display_bonus_screen", USERDEFS_DISPLAY_BONUS_SCREEN, 0, 0 },
1082 terminx 1143
    { "show_level_text", USERDEFS_SHOW_LEVEL_TEXT, 0, 0 },
1090 terminx 1144
    { "weaponscale", USERDEFS_WEAPONSCALE, 0, 0 },
1095 terminx 1145
    { "textscale", USERDEFS_TEXTSCALE, 0, 0 },
3071 terminx 1146
    { "runkey_mode", USERDEFS_RUNKEY_MODE, 0, 0 },
4970 hendricks2 1147
    { "musictoggle", USERDEFS_MUSICTOGGLE, 0, 0 },
5044 hendricks2 1148
    { "gametypeflags", USERDEFS_GAMETYPEFLAGS, 0, 0 },
1149
    { "m_gametypeflags", USERDEFS_M_GAMETYPEFLAGS, 0, 0 },
559 terminx 1150
    { "", -1, 0, 0  }     // END OF LIST
1151
};
5 Plagman 1152
 
1143 terminx 1153
const memberlabel_t InputLabels[]=
559 terminx 1154
{
1155
    { "avel", INPUT_AVEL, 0, 0 },
1156
    { "horz", INPUT_HORZ, 0, 0 },
1157
    { "fvel", INPUT_FVEL, 0, 0 },
1158
    { "svel", INPUT_SVEL, 0, 0 },
1159
    { "bits", INPUT_BITS, 0, 0 },
1160
    { "extbits", INPUT_EXTBITS, 0, 0 },
1161
    { "", -1, 0, 0  }     // END OF LIST
1162
};
5 Plagman 1163
 
3354 helixhorne 1164
#endif
1165
 
1064 terminx 1166
char *bitptr; // pointer to bitmap of which bytecode positions contain pointers
978 terminx 1167
#define BITPTR_POINTER 1
1168
 
3415 helixhorne 1169
#if !defined LUNATIC
1625 terminx 1170
hashtable_t h_gamevars    = { MAXGAMEVARS>>1, NULL };
1171
hashtable_t h_arrays      = { MAXGAMEARRAYS>>1, NULL };
1172
hashtable_t h_labels      = { 11264>>1, NULL };
3354 helixhorne 1173
 
2262 helixhorne 1174
static hashtable_t h_keywords       = { CON_END>>1, NULL };
1024 terminx 1175
 
2262 helixhorne 1176
static hashtable_t sectorH     = { SECTOR_END>>1, NULL };
1177
static hashtable_t wallH       = { WALL_END>>1, NULL };
1178
static hashtable_t userdefH    = { USERDEFS_END>>1, NULL };
1024 terminx 1179
 
2262 helixhorne 1180
static hashtable_t projectileH = { PROJ_END>>1, NULL };
1181
static hashtable_t playerH     = { PLAYER_END>>1, NULL };
1182
static hashtable_t inputH      = { INPUT_END>>1, NULL };
1183
static hashtable_t actorH      = { ACTOR_END>>1, NULL };
1184
static hashtable_t tspriteH    = { ACTOR_END>>1, NULL };
1024 terminx 1185
 
1201 terminx 1186
void C_InitHashes()
1024 terminx 1187
{
1205 terminx 1188
    int32_t i;
1024 terminx 1189
 
1625 terminx 1190
    hash_init(&h_gamevars);
1191
    hash_init(&h_arrays);
1192
    hash_init(&h_labels);
1031 hnt_ts 1193
    inithashnames();
3834 hendricks2 1194
    initsoundhashnames();
1024 terminx 1195
 
1625 terminx 1196
    hash_init(&h_keywords);
1206 terminx 1197
    hash_init(&sectorH);
1198
    hash_init(&wallH);
1199
    hash_init(&userdefH);
1200
    hash_init(&projectileH);
1201
    hash_init(&playerH);
1202
    hash_init(&inputH);
1203
    hash_init(&actorH);
1204
    hash_init(&tspriteH);
1544 terminx 1205
 
1708 helixhorne 1206
    g_scriptLastKeyword = NUMKEYWORDS-1;
1207
    // determine last CON keyword for backward compatibility with older mods
1208
    if (g_scriptDateVersion < g_keywdate[NUMKEYWDATES-1].date)
1209
    {
1210
        for (i=NUMKEYWDATES-1; i>=0; i--)
1211
        {
1212
            if (g_scriptDateVersion >= g_keywdate[i].date)
1213
            {
1214
                g_scriptLastKeyword = g_keywdate[i].keyw;
1215
                break;
1216
            }
1217
        }
1218
 
1219
        if (i<0)
1220
            g_scriptLastKeyword = g_keywdate[0].keyw-1;  // may be slightly imprecise
1221
    }
1222
 
1223
    for (i=g_scriptLastKeyword; i>=0; i--) hash_add(&h_keywords,keyw[i],i,0);
1677 terminx 1224
    for (i=0; SectorLabels[i].lId >= 0; i++) hash_add(&sectorH,SectorLabels[i].name,i,0);
1225
    for (i=0; WallLabels[i].lId >= 0; i++) hash_add(&wallH,WallLabels[i].name,i,0);
1226
    for (i=0; UserdefsLabels[i].lId >= 0; i++) hash_add(&userdefH,UserdefsLabels[i].name,i,0);
1227
    for (i=0; ProjectileLabels[i].lId >= 0; i++) hash_add(&projectileH,ProjectileLabels[i].name,i,0);
1228
    for (i=0; PlayerLabels[i].lId >= 0; i++) hash_add(&playerH,PlayerLabels[i].name,i,0);
1229
    for (i=0; InputLabels[i].lId >= 0; i++) hash_add(&inputH,InputLabels[i].name,i,0);
1230
    for (i=0; ActorLabels[i].lId >= 0; i++) hash_add(&actorH,ActorLabels[i].name,i,0);
1231
    for (i=0; TsprLabels[i].lId >= 0; i++) hash_add(&tspriteH,TsprLabels[i].name,i,0);
1024 terminx 1232
}
1025 terminx 1233
 
1390 terminx 1234
// "magic" number for { and }, overrides line number in compiled code for later detection
1201 terminx 1235
#define IFELSE_MAGIC 31337
1205 terminx 1236
static int32_t g_ifElseAborted;
1200 terminx 1237
 
1820 terminx 1238
static int32_t C_SetScriptSize(int32_t newsize)
874 terminx 1239
{
1143 terminx 1240
    intptr_t oscriptPtr = (unsigned)(g_scriptPtr-script);
1241
    intptr_t ocaseScriptPtr = (unsigned)(g_caseScriptPtr-script);
1242
    intptr_t oparsingEventPtr = (unsigned)(g_parsingEventPtr-script);
1243
    intptr_t oparsingActorPtr = (unsigned)(g_parsingActorPtr-script);
874 terminx 1244
    intptr_t *newscript;
1245
    intptr_t i, j;
1205 terminx 1246
    int32_t osize = g_scriptSize;
1820 terminx 1247
    char *scriptptrs;
1064 terminx 1248
    char *newbitptr;
2262 helixhorne 1249
 
4491 helixhorne 1250
    scriptptrs = (char *)Xcalloc(1, g_scriptSize * sizeof(uint8_t));
1820 terminx 1251
 
1229 terminx 1252
    for (i=g_scriptSize-1; i>=0; i--)
874 terminx 1253
    {
1206 terminx 1254
        if (bitptr[i>>3]&(BITPTR_POINTER<<(i&7)))
874 terminx 1255
        {
4680 terminx 1256
            if (EDUKE32_PREDICT_FALSE((intptr_t)script[i] < (intptr_t)&script[0] || (intptr_t)script[i] >= (intptr_t)&script[g_scriptSize]))
1820 terminx 1257
            {
1258
                g_numCompilerErrors++;
1909 terminx 1259
                initprintf("Internal compiler error at %" PRIdPTR " (0x%" PRIxPTR ")\n",i,i);
1820 terminx 1260
            }
1261
 
874 terminx 1262
            scriptptrs[i] = 1;
976 terminx 1263
            script[i] -= (intptr_t)&script[0];
874 terminx 1264
        }
1265
        else scriptptrs[i] = 0;
1266
    }
1267
 
3102 terminx 1268
    G_Util_PtrToIdx2(&g_tile[0].execPtr, MAXTILES, sizeof(tiledata_t), script, P2I_FWD_NON0);
1269
    G_Util_PtrToIdx2(&g_tile[0].loadPtr, MAXTILES, sizeof(tiledata_t), script, P2I_FWD_NON0);
1950 helixhorne 1270
    G_Util_PtrToIdx(apScriptGameEvent, MAXGAMEEVENTS, script, P2I_FWD_NON0);
1820 terminx 1271
 
1272
    initprintf("Resizing code buffer to %d*%d bytes\n",newsize, (int32_t)sizeof(intptr_t));
1029 terminx 1273
 
4491 helixhorne 1274
    newscript = (intptr_t *)Xrealloc(script, newsize * sizeof(intptr_t));
1275
    newbitptr = (char *)Xcalloc(1,(((newsize+7)>>3)+1) * sizeof(uint8_t));
874 terminx 1276
 
1820 terminx 1277
    if (newsize >= osize)
1029 terminx 1278
    {
1820 terminx 1279
        Bmemset(&newscript[0]+osize,0,(newsize-osize) * sizeof(uint8_t));
1229 terminx 1280
        Bmemcpy(newbitptr,bitptr,sizeof(uint8_t) *((osize+7)>>3));
1029 terminx 1281
    }
1390 terminx 1282
    else
1820 terminx 1283
        Bmemcpy(newbitptr,bitptr,sizeof(uint8_t) *((newsize+7)>>3));
1029 terminx 1284
 
1064 terminx 1285
    Bfree(bitptr);
1286
    bitptr = newbitptr;
1390 terminx 1287
    if (script != newscript)
1288
    {
3278 hendricks2 1289
        initprintf("Relocating compiled code from to 0x%" PRIxPTR " to 0x%" PRIxPTR "\n", (intptr_t)script, (intptr_t)newscript);
1390 terminx 1290
        script = newscript;
1291
    }
1292
 
1820 terminx 1293
    g_scriptSize = newsize;
1143 terminx 1294
    g_scriptPtr = (intptr_t *)(script+oscriptPtr);
976 terminx 1295
 
1544 terminx 1296
    if (g_caseScriptPtr)
1143 terminx 1297
        g_caseScriptPtr = (intptr_t *)(script+ocaseScriptPtr);
1544 terminx 1298
 
1299
    if (g_parsingEventPtr)
1143 terminx 1300
        g_parsingEventPtr = (intptr_t *)(script+oparsingEventPtr);
1544 terminx 1301
 
1302
    if (g_parsingActorPtr)
1143 terminx 1303
        g_parsingActorPtr = (intptr_t *)(script+oparsingActorPtr);
2262 helixhorne 1304
 
1820 terminx 1305
    for (i=(((newsize>=osize)?osize:newsize))-1; i>=0; i--)
1306
        if (scriptptrs[i])
1307
        {
1950 helixhorne 1308
            j = (intptr_t)script[i]+(intptr_t)&script[0];
1820 terminx 1309
            script[i] = j;
1310
        }
874 terminx 1311
 
3102 terminx 1312
    G_Util_PtrToIdx2(&g_tile[0].execPtr, MAXTILES, sizeof(tiledata_t), script, P2I_BACK_NON0);
1313
    G_Util_PtrToIdx2(&g_tile[0].loadPtr, MAXTILES, sizeof(tiledata_t), script, P2I_BACK_NON0);
1950 helixhorne 1314
    G_Util_PtrToIdx(apScriptGameEvent, MAXGAMEEVENTS, script, P2I_BACK_NON0);
874 terminx 1315
 
1316
    Bfree(scriptptrs);
1317
    return 0;
1318
}
1319
 
2640 helixhorne 1320
static int32_t ispecial(const char c)
1593 terminx 1321
{
1322
    if (c == ' ' || c == 0x0d || c == '(' || c == ')' ||
1616 helixhorne 1323
            c == ',' || c == ';' || (c == 0x0a /*&& ++g_lineNumber*/))
1593 terminx 1324
        return 1;
1545 terminx 1325
 
1593 terminx 1326
    return 0;
1327
}
1328
 
1545 terminx 1329
#define C_NextLine() while (*textptr != 0x0a && *textptr != 0x0d && *textptr != 0) textptr++
1330
 
1205 terminx 1331
static int32_t C_SkipComments(void)
5 Plagman 1332
{
1040 terminx 1333
    do
5 Plagman 1334
    {
1544 terminx 1335
        switch (*textptr)
335 terminx 1336
        {
1544 terminx 1337
        case '\n':
1143 terminx 1338
            g_lineNumber++;
1544 terminx 1339
        case ' ':
1340
        case '\t':
1341
        case '\r':
1665 terminx 1342
        case 0x1a:
5 Plagman 1343
            textptr++;
1544 terminx 1344
            break;
1345
        case '/':
1346
            switch (textptr[1])
5 Plagman 1347
            {
1544 terminx 1348
            case '/': // C++ style comment
1349
                if (!(g_numCompilerErrors || g_numCompilerWarnings) && g_scriptDebug > 1)
1350
                    initprintf("%s:%d: debug: got comment.\n",g_szScriptFileName,g_lineNumber);
1545 terminx 1351
                C_NextLine();
1665 terminx 1352
                continue;
1544 terminx 1353
            case '*': // beginning of a C style comment
1354
                if (!(g_numCompilerErrors || g_numCompilerWarnings) && g_scriptDebug > 1)
1355
                    initprintf("%s:%d: debug: got start of comment block.\n",g_szScriptFileName,g_lineNumber);
1356
                do
1357
                {
1358
                    if (*textptr == '\n')
1359
                        g_lineNumber++;
1360
                    textptr++;
1361
                }
1362
                while (*textptr && (textptr[0] != '*' || textptr[1] != '/'));
1363
 
4680 terminx 1364
                if (EDUKE32_PREDICT_FALSE(!*textptr))
1544 terminx 1365
                {
1366
                    if (!(g_numCompilerErrors || g_numCompilerWarnings) && g_scriptDebug)
1367
                        initprintf("%s:%d: debug: EOF in comment!\n",g_szScriptFileName,g_lineNumber);
1368
                    C_ReportError(-1);
1369
                    initprintf("%s:%d: error: found `/*' with no `*/'.\n",g_szScriptFileName,g_lineNumber);
1857 terminx 1370
                    g_parsingActorPtr = NULL; g_processingState = g_numBraces = 0;
1544 terminx 1371
                    g_numCompilerErrors++;
1665 terminx 1372
                    continue;
1544 terminx 1373
                }
1374
 
1375
                if (!(g_numCompilerErrors || g_numCompilerWarnings) && g_scriptDebug > 1)
1376
                    initprintf("%s:%d: debug: got end of comment block.\n",g_szScriptFileName,g_lineNumber);
1377
 
1378
                textptr+=2;
1665 terminx 1379
                continue;
5 Plagman 1380
            }
1665 terminx 1381
            continue;
1544 terminx 1382
 
1545 terminx 1383
        default:
1384
            if (ispecial(*textptr))
1385
            {
1386
                textptr++;
1665 terminx 1387
                continue;
1545 terminx 1388
            }
1544 terminx 1389
        case 0: // EOF
1390
            return ((g_scriptPtr-script) > (g_scriptSize-32)) ? C_SetScriptSize(g_scriptSize<<1) : 0;
5 Plagman 1391
        }
1046 terminx 1392
    }
1544 terminx 1393
    while (1);
5 Plagman 1394
}
1395
 
1625 terminx 1396
#define GetDefID(szGameLabel) hash_find(&h_gamevars,szGameLabel)
1397
#define GetADefID(szGameLabel) hash_find(&h_arrays,szGameLabel)
1189 terminx 1398
 
2640 helixhorne 1399
static int32_t isaltok(const char c)
5 Plagman 1400
{
1213 terminx 1401
    return (isalnum(c) || c == '{' || c == '}' || c == '/' || c == '\\' ||
1215 terminx 1402
            c == '*' || c == '-' || c == '_' || c == '.');
5 Plagman 1403
}
1404
 
4474 helixhorne 1405
static int32_t C_IsLabelChar(const char c, int32_t i)
1406
{
1407
    return (isalnum(c) || c=='_' || c=='*' || c=='?' ||
1408
            (i > 0 && (c=='+' || c=='-' || c=='.')));
1409
}
1410
 
1206 terminx 1411
static inline int32_t C_GetLabelNameID(const memberlabel_t *pLabel, hashtable_t *tH, const char *psz)
5 Plagman 1412
{
1413
    // find the label psz in the table pLabel.
1414
    // returns the ID for the label, or -1
1415
 
1857 terminx 1416
    int32_t l = hash_findcase(tH,psz);
1417
    return (l >= 0) ? pLabel[l].lId : -1;
5 Plagman 1418
}
1419
 
1206 terminx 1420
static inline int32_t C_GetLabelNameOffset(hashtable_t *tH, const char *psz)
5 Plagman 1421
{
1422
    // find the label psz in the table pLabel.
1423
    // returns the offset in the array for the label, or -1
1424
 
1206 terminx 1425
    return hash_findcase(tH,psz);
5 Plagman 1426
}
1427
 
1143 terminx 1428
static void C_GetNextLabelName(void)
5 Plagman 1429
{
1857 terminx 1430
    int32_t i = 0;
5 Plagman 1431
 
1143 terminx 1432
    C_SkipComments();
5 Plagman 1433
 
4474 helixhorne 1434
//    while (ispecial(*textptr) == 0 && *textptr!='['&& *textptr!=']' && *textptr!='\t' && *textptr!='\n' && *textptr!='\r')
1435
    while (C_IsLabelChar(*textptr, i))
1143 terminx 1436
        label[(g_numLabels<<6)+(i++)] = *(textptr++);
1857 terminx 1437
    label[(g_numLabels<<6)+i] = 0;
5 Plagman 1438
 
1857 terminx 1439
    if (!(g_numCompilerErrors|g_numCompilerWarnings) && g_scriptDebug > 1)
1143 terminx 1440
        initprintf("%s:%d: debug: got label `%s'.\n",g_szScriptFileName,g_lineNumber,label+(g_numLabels<<6));
5 Plagman 1441
}
1442
 
1205 terminx 1443
static int32_t C_GetKeyword(void)
5 Plagman 1444
{
1205 terminx 1445
    int32_t i;
5 Plagman 1446
    char *temptextptr;
1447
 
1143 terminx 1448
    C_SkipComments();
5 Plagman 1449
 
1450
    temptextptr = textptr;
1451
 
1857 terminx 1452
    if (*temptextptr == 0) // EOF
1453
        return -2;
1454
 
333 terminx 1455
    while (isaltok(*temptextptr) == 0)
5 Plagman 1456
    {
1457
        temptextptr++;
333 terminx 1458
        if (*temptextptr == 0)
5 Plagman 1459
            return 0;
1460
    }
1461
 
1462
    i = 0;
333 terminx 1463
    while (isaltok(*temptextptr))
1034 terminx 1464
        tempbuf[i++] = *(temptextptr++);
5 Plagman 1465
    tempbuf[i] = 0;
1857 terminx 1466
 
1625 terminx 1467
    return hash_find(&h_keywords,tempbuf);
5 Plagman 1468
}
1469
 
1205 terminx 1470
static int32_t C_GetNextKeyword(void) //Returns its code #
5 Plagman 1471
{
1205 terminx 1472
    int32_t i, l;
5 Plagman 1473
 
1143 terminx 1474
    C_SkipComments();
5 Plagman 1475
 
1544 terminx 1476
    if (*textptr == 0) // EOF
1857 terminx 1477
        return -2;
5 Plagman 1478
 
1479
    l = 0;
333 terminx 1480
    while (isaltok(*(textptr+l)))
5 Plagman 1481
    {
1482
        tempbuf[l] = textptr[l];
1483
        l++;
1484
    }
1485
    tempbuf[l] = 0;
1486
 
4680 terminx 1487
    if (EDUKE32_PREDICT_TRUE((i = hash_find(&h_keywords,tempbuf)) >= 0))
5 Plagman 1488
    {
1200 terminx 1489
        if (i == CON_LEFTBRACE || i == CON_RIGHTBRACE || i == CON_NULLOP)
1201 terminx 1490
            *g_scriptPtr = i + (IFELSE_MAGIC<<12);
1200 terminx 1491
        else *g_scriptPtr = i + (g_lineNumber<<12);
1393 terminx 1492
 
1450 terminx 1493
        bitptr[(g_scriptPtr-script)>>3] &= ~(BITPTR_POINTER<<((g_scriptPtr-script)&7));
1024 terminx 1494
        textptr += l;
1143 terminx 1495
        g_scriptPtr++;
1393 terminx 1496
 
1143 terminx 1497
        if (!(g_numCompilerErrors || g_numCompilerWarnings) && g_scriptDebug)
1498
            initprintf("%s:%d: debug: translating keyword `%s'.\n",g_szScriptFileName,g_lineNumber,keyw[i]);
1024 terminx 1499
        return i;
5 Plagman 1500
    }
1501
 
1502
    textptr += l;
1857 terminx 1503
    g_numCompilerErrors++;
5 Plagman 1504
 
4680 terminx 1505
    if (EDUKE32_PREDICT_FALSE((tempbuf[0] == '{' || tempbuf[0] == '}') && tempbuf[1] != 0))
5 Plagman 1506
    {
1143 terminx 1507
        C_ReportError(-1);
1857 terminx 1508
        initprintf("%s:%d: error: expected whitespace between `%c' and `%s'.\n",g_szScriptFileName,g_lineNumber,tempbuf[0],tempbuf+1);
5 Plagman 1509
    }
1143 terminx 1510
    else C_ReportError(ERROR_EXPECTEDKEYWORD);
1857 terminx 1511
 
5 Plagman 1512
    return -1;
1513
}
1514
 
2392 helixhorne 1515
static int32_t parse_decimal_number(void)  // (textptr)
1516
{
1517
    // decimal constants -- this is finicky business
1518
    int64_t num = strtoll(textptr, NULL, 10);  // assume long long to be int64_t
1519
 
4680 terminx 1520
    if (EDUKE32_PREDICT_TRUE(num >= INT32_MIN && num <= INT32_MAX))
2392 helixhorne 1521
    {
1522
        // all OK
1523
    }
4680 terminx 1524
    else if (EDUKE32_PREDICT_FALSE(num > INT32_MAX && num <= UINT32_MAX))
2392 helixhorne 1525
    {
1526
        // Number interpreted as uint32, but packed as int32 (on 32-bit archs)
1527
        // (CON code in the wild exists that does this).  Note that such conversion
1528
        // is implementation-defined (C99 6.3.1.3) but GCC does the 'expected' thing.
2742 helixhorne 1529
#if 0
2392 helixhorne 1530
        initprintf("%s:%d: warning: number greater than INT32_MAX converted to a negative one.\n",
1531
                   g_szScriptFileName,g_lineNumber);
1532
        g_numCompilerWarnings++;
2742 helixhorne 1533
#endif
2392 helixhorne 1534
    }
1535
    else
1536
    {
1537
        // out of range, this is arguably worse
1538
 
1539
        initprintf("%s:%d: warning: number out of the range of a 32-bit integer encountered.\n",
1540
                   g_szScriptFileName,g_lineNumber);
1541
        g_numCompilerWarnings++;
1542
    }
1543
 
1544
    return (int32_t)num;
1545
}
1546
 
2751 helixhorne 1547
static int32_t parse_hex_constant(const char *hexnum)
1548
{
1549
    int64_t x;
1550
    sscanf(hexnum, "%" PRIx64 "", &x);
1551
 
4680 terminx 1552
    if (EDUKE32_PREDICT_FALSE(x > UINT32_MAX))
2751 helixhorne 1553
    {
1554
        initprintf("%s:%d: warning: number 0x%" PRIx64 " truncated to 32 bits.\n",
1555
                   g_szScriptFileName,g_lineNumber, x);
1556
        g_numCompilerWarnings++;
1557
    }
1558
 
1559
    return x;
1560
}
1561
 
1205 terminx 1562
static void C_GetNextVarType(int32_t type)
5 Plagman 1563
{
1205 terminx 1564
    int32_t i=0,f=0;
5 Plagman 1565
 
1143 terminx 1566
    C_SkipComments();
1605 terminx 1567
 
1143 terminx 1568
    if (!type && !g_labelsOnly && (isdigit(*textptr) || ((*textptr == '-') && (isdigit(*(textptr+1))))))
5 Plagman 1569
    {
1450 terminx 1570
        bitptr[(g_scriptPtr-script)>>3] &= ~(BITPTR_POINTER<<((g_scriptPtr-script)&7));
2392 helixhorne 1571
 
1572
        *g_scriptPtr++ = MAXGAMEVARS;
1573
 
1574
        if (tolower(textptr[1])=='x')  // hex constants
2751 helixhorne 1575
            *g_scriptPtr = parse_hex_constant(textptr+2);
622 terminx 1576
        else
2392 helixhorne 1577
            *g_scriptPtr = parse_decimal_number();
1578
 
1579
        if (!(g_numCompilerErrors || g_numCompilerWarnings) && g_scriptDebug)
1580
            initprintf("%s:%d: debug: accepted constant %ld in place of gamevar.\n",
1581
                       g_szScriptFileName,g_lineNumber,(long)*g_scriptPtr);
1582
 
1450 terminx 1583
        bitptr[(g_scriptPtr-script)>>3] &= ~(BITPTR_POINTER<<((g_scriptPtr-script)&7));
1143 terminx 1584
        g_scriptPtr++;
1213 terminx 1585
#if 1
1586
        while (!ispecial(*textptr) && *textptr != ']') textptr++;
1587
#else
1143 terminx 1588
        C_GetNextLabelName();
1213 terminx 1589
#endif
5 Plagman 1590
        return;
1591
    }
1034 terminx 1592
    else if ((*textptr == '-')/* && !isdigit(*(textptr+1))*/)
5 Plagman 1593
    {
4680 terminx 1594
        if (EDUKE32_PREDICT_FALSE(type))
5 Plagman 1595
        {
1143 terminx 1596
            g_numCompilerErrors++;
1597
            C_ReportError(ERROR_SYNTAXERROR);
1598
            C_GetNextLabelName();
5 Plagman 1599
            return;
1600
        }
1605 terminx 1601
 
4680 terminx 1602
        if (!(g_numCompilerErrors || g_numCompilerWarnings) && g_scriptDebug)
1603
            initprintf("%s:%d: debug: flagging gamevar as negative.\n", g_szScriptFileName, g_lineNumber); //,Batol(textptr));
1604
        f = (MAXGAMEVARS<<1);
1605
 
1605 terminx 1606
        textptr++;
5 Plagman 1607
    }
2392 helixhorne 1608
 
1143 terminx 1609
    C_GetNextLabelName();
676 terminx 1610
 
4680 terminx 1611
    if (EDUKE32_PREDICT_FALSE(!g_skipKeywordCheck && hash_find(&h_keywords,label+(g_numLabels<<6))>=0))
1024 terminx 1612
    {
1143 terminx 1613
        g_numCompilerErrors++;
1614
        C_ReportError(ERROR_ISAKEYWORD);
1024 terminx 1615
        return;
1616
    }
676 terminx 1617
 
1143 terminx 1618
    C_SkipComments(); //skip comments and whitespace
676 terminx 1619
    if ((*textptr == '['))     //read of array as a gamevar
1620
    {
1205 terminx 1621
        int32_t lLabelID = -1;
1204 terminx 1622
 
715 terminx 1623
        f |= (MAXGAMEVARS<<2);
676 terminx 1624
        textptr++;
1143 terminx 1625
        i=GetADefID(label+(g_numLabels<<6));
715 terminx 1626
        if (i < 0)
676 terminx 1627
        {
1204 terminx 1628
            i=GetDefID(label+(g_numLabels<<6));
1213 terminx 1629
            if (i < g_iSpriteVarID || i > g_iActorVarID)
1204 terminx 1630
                i = -1;
1631
 
4680 terminx 1632
            if (EDUKE32_PREDICT_FALSE(i < 0))
1204 terminx 1633
            {
1634
                g_numCompilerErrors++;
1635
                C_ReportError(ERROR_NOTAGAMEARRAY);
1636
                return;
1637
            }
1638
            f &= ~(MAXGAMEVARS<<2); // not an array
1639
            f |= (MAXGAMEVARS<<3);
676 terminx 1640
        }
1641
 
1450 terminx 1642
        bitptr[(g_scriptPtr-script)>>3] &= ~(BITPTR_POINTER<<((g_scriptPtr-script)&7));
1143 terminx 1643
        *g_scriptPtr++=(i|f);
1644
        C_GetNextVarType(0);
1213 terminx 1645
        C_SkipComments();
715 terminx 1646
 
4680 terminx 1647
        if (EDUKE32_PREDICT_FALSE(*textptr != ']'))
676 terminx 1648
        {
1143 terminx 1649
            g_numCompilerErrors++;
1650
            C_ReportError(ERROR_GAMEARRAYBNC);
676 terminx 1651
            return;
1652
        }
1653
        textptr++;
1213 terminx 1654
 
1655
        //writing arrays in this way is not supported because it would require too many changes to other code
1656
 
4680 terminx 1657
        if (EDUKE32_PREDICT_FALSE(type))
676 terminx 1658
        {
1143 terminx 1659
            g_numCompilerErrors++;
1660
            C_ReportError(ERROR_INVALIDARRAYWRITE);
676 terminx 1661
            return;
1662
        }
1204 terminx 1663
 
1664
        if (f & (MAXGAMEVARS<<3))
1665
        {
1666
            while (*textptr != '.')
1667
            {
1668
                if (*textptr == 0xa)
1669
                    break;
1670
                if (!*textptr)
1671
                    break;
1672
 
1673
                textptr++;
1674
            }
1675
 
4680 terminx 1676
            if (EDUKE32_PREDICT_FALSE(*textptr != '.'))
1204 terminx 1677
            {
1678
                g_numCompilerErrors++;
1679
                C_ReportError(ERROR_SYNTAXERROR);
1680
                return;
1681
            }
1682
            textptr++;
1683
            /// now pointing at 'xxx'
1684
            C_GetNextLabelName();
2538 hendricks2 1685
            /*initprintf("found xxx label of \"%s\"\n",   label+(g_numLabels<<6));*/
1204 terminx 1686
 
1687
            if (i == g_iSpriteVarID)
1642 terminx 1688
                lLabelID=C_GetLabelNameOffset(&actorH,Bstrtolower(label+(g_numLabels<<6)));
1204 terminx 1689
            else if (i == g_iSectorVarID)
1642 terminx 1690
                lLabelID=C_GetLabelNameOffset(&sectorH,Bstrtolower(label+(g_numLabels<<6)));
1204 terminx 1691
            else if (i == g_iWallVarID)
1642 terminx 1692
                lLabelID=C_GetLabelNameOffset(&wallH,Bstrtolower(label+(g_numLabels<<6)));
1204 terminx 1693
            else if (i == g_iPlayerVarID)
1642 terminx 1694
                lLabelID=C_GetLabelNameOffset(&playerH,Bstrtolower(label+(g_numLabels<<6)));
1213 terminx 1695
            else if (i == g_iActorVarID)
1696
                lLabelID=GetDefID(label+(g_numLabels<<6));
1207 terminx 1697
 
1204 terminx 1698
            //printf("LabelID is %d\n",lLabelID);
4680 terminx 1699
            if (EDUKE32_PREDICT_FALSE(lLabelID == -1))
1204 terminx 1700
            {
1701
                g_numCompilerErrors++;
1702
                C_ReportError(ERROR_SYMBOLNOTRECOGNIZED);
1703
                return;
1704
            }
1705
 
1450 terminx 1706
            bitptr[(g_scriptPtr-script)>>3] &= ~(BITPTR_POINTER<<((g_scriptPtr-script)&7));
1204 terminx 1707
 
1708
            if (i == g_iSpriteVarID)
1709
            {
1710
                *g_scriptPtr++=ActorLabels[lLabelID].lId;
1711
 
1712
                //printf("member's flags are: %02Xh\n",ActorLabels[lLabelID].flags);
1713
                if (ActorLabels[lLabelID].flags & LABEL_HASPARM2)
1714
                {
1715
                    //printf("Member has PARM2\n");
1716
                    // get parm2
1717
                    // get the ID of the DEF
1718
                    C_GetNextVarType(0);
1719
                }
1720
            }
1213 terminx 1721
            else if (i == g_iSectorVarID)
1722
                *g_scriptPtr++=SectorLabels[lLabelID].lId;
1723
            else if (i == g_iWallVarID)
1724
                *g_scriptPtr++=SectorLabels[lLabelID].lId;
1204 terminx 1725
            else if (i == g_iPlayerVarID)
1726
            {
1727
                *g_scriptPtr++=PlayerLabels[lLabelID].lId;
1728
 
1729
                //printf("member's flags are: %02Xh\n",ActorLabels[lLabelID].flags);
1730
                if (PlayerLabels[lLabelID].flags & LABEL_HASPARM2)
1731
                {
1732
                    //printf("Member has PARM2\n");
1733
                    // get parm2
1734
                    // get the ID of the DEF
1735
                    C_GetNextVarType(0);
1736
                }
1737
            }
1213 terminx 1738
            else if (i == g_iActorVarID)
1739
                *g_scriptPtr++=lLabelID;
1204 terminx 1740
        }
676 terminx 1741
        return;
1742
    }
1743
//    initprintf("not an array");
1143 terminx 1744
    i=GetDefID(label+(g_numLabels<<6));
676 terminx 1745
    if (i<0)   //gamevar not found
5 Plagman 1746
    {
1143 terminx 1747
        if (!type && !g_labelsOnly)
5 Plagman 1748
        {
676 terminx 1749
            //try looking for a define instead
1143 terminx 1750
            Bstrcpy(tempbuf,label+(g_numLabels<<6));
1625 terminx 1751
            i = hash_find(&h_labels,tempbuf);
4680 terminx 1752
            if (EDUKE32_PREDICT_TRUE(i>=0))
5 Plagman 1753
            {
4680 terminx 1754
                if (EDUKE32_PREDICT_TRUE(labeltype[i] & LABEL_DEFINE))
5 Plagman 1755
                {
1143 terminx 1756
                    if (!(g_numCompilerErrors || g_numCompilerWarnings) && g_scriptDebug)
1757
                        initprintf("%s:%d: debug: accepted defined label `%s' instead of gamevar.\n",g_szScriptFileName,g_lineNumber,label+(i<<6));
1450 terminx 1758
                    bitptr[(g_scriptPtr-script)>>3] &= ~(BITPTR_POINTER<<((g_scriptPtr-script)&7));
2185 helixhorne 1759
                    *g_scriptPtr++ = MAXGAMEVARS;
1450 terminx 1760
                    bitptr[(g_scriptPtr-script)>>3] &= ~(BITPTR_POINTER<<((g_scriptPtr-script)&7));
2185 helixhorne 1761
                    *g_scriptPtr++ = labelcode[i];
5 Plagman 1762
                    return;
1763
                }
1764
            }
1143 terminx 1765
            g_numCompilerErrors++;
1766
            C_ReportError(ERROR_NOTAGAMEVAR);
5 Plagman 1767
            return;
1768
        }
1143 terminx 1769
        g_numCompilerErrors++;
1770
        C_ReportError(ERROR_NOTAGAMEVAR);
437 terminx 1771
        textptr++;
1772
        return;
676 terminx 1773
 
5 Plagman 1774
    }
4680 terminx 1775
    if (EDUKE32_PREDICT_FALSE(type == GAMEVAR_READONLY && aGameVars[i].dwFlags & GAMEVAR_READONLY))
5 Plagman 1776
    {
1143 terminx 1777
        g_numCompilerErrors++;
1778
        C_ReportError(ERROR_VARREADONLY);
5 Plagman 1779
        return;
1780
    }
4680 terminx 1781
    else if (EDUKE32_PREDICT_FALSE(aGameVars[i].dwFlags & type))
5 Plagman 1782
    {
1143 terminx 1783
        g_numCompilerErrors++;
1784
        C_ReportError(ERROR_VARTYPEMISMATCH);
5 Plagman 1785
        return;
1786
    }
1857 terminx 1787
 
1143 terminx 1788
    if (!(g_numCompilerErrors || g_numCompilerWarnings) && g_scriptDebug > 1)
1789
        initprintf("%s:%d: debug: accepted gamevar `%s'.\n",g_szScriptFileName,g_lineNumber,label+(g_numLabels<<6));
715 terminx 1790
 
1450 terminx 1791
    bitptr[(g_scriptPtr-script)>>3] &= ~(BITPTR_POINTER<<((g_scriptPtr-script)&7));
1143 terminx 1792
    *g_scriptPtr++=(i|f);
5 Plagman 1793
}
1794
 
1206 terminx 1795
#define C_GetNextVar() C_GetNextVarType(0)
5 Plagman 1796
 
1205 terminx 1797
static inline void C_GetManyVarsType(int32_t type, int32_t num)
5 Plagman 1798
{
1205 terminx 1799
    int32_t i;
1229 terminx 1800
    for (i=num-1; i>=0; i--)
1143 terminx 1801
        C_GetNextVarType(type);
5 Plagman 1802
}
1803
 
1206 terminx 1804
#define C_GetManyVars(num) C_GetManyVarsType(0,num)
5 Plagman 1805
 
2766 helixhorne 1806
// returns:
1807
//  -1 on EOF or wrong type or error
1808
//   0 if literal value
1809
//   LABEL_* (>0) if that type and matched
1810
//
1811
// *g_scriptPtr will contain the value OR 0 if wrong type or error
1205 terminx 1812
static int32_t C_GetNextValue(int32_t type)
5 Plagman 1813
{
1205 terminx 1814
    int32_t i, l;
5 Plagman 1815
 
1143 terminx 1816
    C_SkipComments();
5 Plagman 1817
 
1544 terminx 1818
    if (*textptr == 0) // EOF
1819
        return -1;
5 Plagman 1820
 
1821
    l = 0;
333 terminx 1822
    while (isaltok(*(textptr+l)))
5 Plagman 1823
    {
1824
        tempbuf[l] = textptr[l];
1825
        l++;
1826
    }
1827
    tempbuf[l] = 0;
1828
 
4680 terminx 1829
    if (EDUKE32_PREDICT_FALSE(!g_skipKeywordCheck && hash_find(&h_keywords,tempbuf /*label+(g_numLabels<<6)*/)>=0))
1024 terminx 1830
    {
1143 terminx 1831
        g_numCompilerErrors++;
1832
        C_ReportError(ERROR_ISAKEYWORD);
1024 terminx 1833
        textptr+=l;
1834
    }
121 terminx 1835
 
1625 terminx 1836
    i = hash_find(&h_labels,tempbuf);
1024 terminx 1837
    if (i>=0)
5 Plagman 1838
    {
1024 terminx 1839
        char *el,*gl;
1840
 
4680 terminx 1841
        if (EDUKE32_PREDICT_TRUE(labeltype[i] & type))
5 Plagman 1842
        {
1143 terminx 1843
            if (!(g_numCompilerErrors || g_numCompilerWarnings) && g_scriptDebug > 1)
5 Plagman 1844
            {
1143 terminx 1845
                gl = (char *)C_GetLabelType(labeltype[i]);
1846
                initprintf("%s:%d: debug: accepted %s label `%s'.\n",g_szScriptFileName,g_lineNumber,gl,label+(i<<6));
1024 terminx 1847
                Bfree(gl);
5 Plagman 1848
            }
2150 helixhorne 1849
 
2185 helixhorne 1850
            bitptr[(g_scriptPtr-script)>>3] &= ~(BITPTR_POINTER<<((g_scriptPtr-script)&7));
1851
            *(g_scriptPtr++) = labelcode[i];
2451 helixhorne 1852
 
5 Plagman 1853
            textptr += l;
1024 terminx 1854
            return labeltype[i];
5 Plagman 1855
        }
4680 terminx 1856
 
1450 terminx 1857
        bitptr[(g_scriptPtr-script)>>3] &= ~(BITPTR_POINTER<<((g_scriptPtr-script)&7));
1143 terminx 1858
        *(g_scriptPtr++) = 0;
1024 terminx 1859
        textptr += l;
1143 terminx 1860
        el = (char *)C_GetLabelType(type);
1861
        gl = (char *)C_GetLabelType(labeltype[i]);
1862
        C_ReportError(-1);
1206 terminx 1863
        initprintf("%s:%d: warning: expected %s, found %s.\n",g_szScriptFileName,g_lineNumber,el,gl);
1143 terminx 1864
        g_numCompilerWarnings++;
1024 terminx 1865
        Bfree(el);
1866
        Bfree(gl);
1867
        return -1;  // valid label name, but wrong type
5 Plagman 1868
    }
1869
 
4680 terminx 1870
    if (EDUKE32_PREDICT_FALSE(isdigit(*textptr) == 0 && *textptr != '-'))
5 Plagman 1871
    {
1143 terminx 1872
        C_ReportError(ERROR_PARAMUNDEFINED);
1873
        g_numCompilerErrors++;
1450 terminx 1874
        bitptr[(g_scriptPtr-script)>>3] &= ~(BITPTR_POINTER<<((g_scriptPtr-script)&7));
1143 terminx 1875
        *g_scriptPtr = 0;
1876
        g_scriptPtr++;
5 Plagman 1877
        textptr+=l;
1878
        return -1; // error!
1879
    }
1880
 
4680 terminx 1881
    if (EDUKE32_PREDICT_FALSE(isdigit(*textptr) && g_labelsOnly))
5 Plagman 1882
    {
1143 terminx 1883
        C_ReportError(WARNING_LABELSONLY);
1884
        g_numCompilerWarnings++;
5 Plagman 1885
    }
1189 terminx 1886
 
1887
    i = l-1;
1888
    do
1889
    {
1207 terminx 1890
        // FIXME: check for 0-9 A-F for hex
1198 terminx 1891
        if (textptr[0] == '0' && textptr[1] == 'x') break; // kill the warning for hex
4680 terminx 1892
        if (EDUKE32_PREDICT_FALSE(!isdigit(textptr[i--])))
1189 terminx 1893
        {
1894
            C_ReportError(-1);
1206 terminx 1895
            initprintf("%s:%d: warning: invalid character `%c' in definition!\n",g_szScriptFileName,g_lineNumber,textptr[i+1]);
1189 terminx 1896
            g_numCompilerWarnings++;
1897
            break;
1898
        }
1899
    }
1900
    while (i > 0);
1901
 
1450 terminx 1902
    bitptr[(g_scriptPtr-script)>>3] &= ~(BITPTR_POINTER<<((g_scriptPtr-script)&7));
1189 terminx 1903
 
1904
    if (tolower(textptr[1])=='x')
2751 helixhorne 1905
        *g_scriptPtr = parse_hex_constant(textptr+2);
622 terminx 1906
    else
2392 helixhorne 1907
        *g_scriptPtr = parse_decimal_number();
1189 terminx 1908
 
2392 helixhorne 1909
    if (!(g_numCompilerErrors || g_numCompilerWarnings) && g_scriptDebug > 1)
1910
        initprintf("%s:%d: debug: accepted constant %ld.\n",
1911
                   g_szScriptFileName,g_lineNumber,(long)*g_scriptPtr);
1912
 
1143 terminx 1913
    g_scriptPtr++;
5 Plagman 1914
 
1915
    textptr += l;
1916
 
1917
    return 0;   // literal value
1918
}
1919
 
1436 terminx 1920
static inline int32_t C_IntPow2(int32_t v)
1921
{
1440 terminx 1922
    return ((v!=0) && (v&(v-1))==0);
1436 terminx 1923
}
1924
 
1925
static inline uint32_t C_Pow2IntLogBase2(int32_t v)
1926
{
1440 terminx 1927
    static const uint32_t b[] = {0xAAAAAAAA, 0xCCCCCCCC, 0xF0F0F0F0,
1928
                                 0xFF00FF00, 0xFFFF0000
1929
                                };
1930
    register uint32_t r = (v & b[0]) != 0;
1931
    int32_t i = 4;
1932
 
1933
    for (; i > 0; i--)
1934
        r |= ((v & b[i]) != 0) << i;
1935
 
1936
    return r;
1436 terminx 1937
}
1938
 
1435 terminx 1939
static int32_t C_CheckMalformedBranch(intptr_t lastScriptPtr)
1940
{
1941
    switch (C_GetKeyword())
1942
    {
1943
    case CON_RIGHTBRACE:
1944
    case CON_ENDA:
1945
    case CON_ENDEVENT:
1946
    case CON_ENDS:
1436 terminx 1947
    case CON_ELSE:
1435 terminx 1948
        g_scriptPtr = lastScriptPtr + &script[0];
1949
        g_ifElseAborted = 1;
1950
        C_ReportError(-1);
1951
        g_numCompilerWarnings++;
1952
        initprintf("%s:%d: warning: malformed `%s' branch\n",g_szScriptFileName,g_lineNumber,
1440 terminx 1953
                   keyw[*(g_scriptPtr) & 0xFFF]);
1435 terminx 1954
        return 1;
1955
    }
1956
    return 0;
1957
}
1958
 
1205 terminx 1959
static int32_t C_CheckEmptyBranch(int32_t tw, intptr_t lastScriptPtr)
1200 terminx 1960
{
2149 helixhorne 1961
    // ifrnd and the others actually do something when the condition is executed
1202 terminx 1962
    if ((Bstrncmp(keyw[tw], "if", 2) && tw != CON_ELSE) ||
2149 helixhorne 1963
            tw == CON_IFRND || tw == CON_IFHITWEAPON || tw == CON_IFCANSEE || tw == CON_IFCANSEETARGET ||
1964
            tw == CON_IFPDISTL || tw == CON_IFPDISTG || tw == CON_IFGOTWEAPONCE)
1200 terminx 1965
    {
1966
        g_ifElseAborted = 0;
1967
        return 0;
1968
    }
1969
 
1201 terminx 1970
    if ((*(g_scriptPtr) & 0xFFF) != CON_NULLOP || *(g_scriptPtr)>>12 != IFELSE_MAGIC)
1200 terminx 1971
        g_ifElseAborted = 0;
1972
 
4680 terminx 1973
    if (EDUKE32_PREDICT_FALSE(g_ifElseAborted))
1200 terminx 1974
    {
1201 terminx 1975
        C_ReportError(-1);
1976
        g_numCompilerWarnings++;
1200 terminx 1977
        g_scriptPtr = lastScriptPtr + &script[0];
1201 terminx 1978
        initprintf("%s:%d: warning: empty `%s' branch\n",g_szScriptFileName,g_lineNumber,
1200 terminx 1979
                   keyw[*(g_scriptPtr) & 0xFFF]);
1435 terminx 1980
        *(g_scriptPtr) = (CON_NULLOP + (IFELSE_MAGIC<<12));
1200 terminx 1981
        return 1;
1982
    }
1983
    return 0;
1984
}
1985
 
1205 terminx 1986
static int32_t C_CountCaseStatements()
5 Plagman 1987
{
1205 terminx 1988
    int32_t lCount;
437 terminx 1989
    char *temptextptr = textptr;
1205 terminx 1990
    int32_t temp_ScriptLineNumber = g_lineNumber;
1143 terminx 1991
    intptr_t scriptoffset = (unsigned)(g_scriptPtr-script);
1992
    intptr_t caseoffset = (unsigned)(g_caseScriptPtr-script);
1205 terminx 1993
//    int32_t i;
5 Plagman 1994
 
1143 terminx 1995
    g_numCases=0;
1996
    g_caseScriptPtr=NULL;
5 Plagman 1997
    //Bsprintf(g_szBuf,"CSS: %.12s",textptr);
1998
    //AddLog(g_szBuf);
1891 terminx 1999
    C_ParseCommand(1);
1143 terminx 2000
    // since we processed the endswitch, we need to re-increment g_checkingSwitch
2001
    g_checkingSwitch++;
5 Plagman 2002
 
2003
    textptr=temptextptr;
1143 terminx 2004
    g_scriptPtr = (intptr_t *)(script+scriptoffset);
5 Plagman 2005
 
1143 terminx 2006
    g_lineNumber = temp_ScriptLineNumber;
5 Plagman 2007
 
1143 terminx 2008
    lCount=g_numCases;
2009
    g_numCases=0;
2010
    g_caseScriptPtr = (intptr_t *)(script+caseoffset);
2011
    g_numCases = 0;
5 Plagman 2012
    return lCount;
2013
}
2014
 
1937 hendricks2 2015
static void C_Include(const char *confile)
2016
{
2017
    int32_t temp_ScriptLineNumber;
2018
    int32_t temp_ifelse_check;
2019
    int32_t j;
2020
    char *origtptr, *mptr;
2021
    char parentScriptFileName[255];
2022
    int32_t fp;
2023
 
2024
    fp = kopen4loadfrommod(confile,g_loadFromGroupOnly);
4680 terminx 2025
    if (EDUKE32_PREDICT_FALSE(fp < 0))
1937 hendricks2 2026
    {
2027
        g_numCompilerErrors++;
2028
        initprintf("%s:%d: error: could not find file `%s'.\n",g_szScriptFileName,g_lineNumber,confile);
2029
        return;
2030
    }
2031
 
2032
    j = kfilelength(fp);
2033
 
4491 helixhorne 2034
    mptr = (char *)Xmalloc(j+1);
1937 hendricks2 2035
 
2036
    initprintf("Including: %s (%d bytes)\n",confile, j);
2037
    kread(fp, mptr, j);
2038
    kclose(fp);
2039
    mptr[j] = 0;
2040
 
2041
    if (*textptr == '"') // skip past the closing quote if it's there so we don't screw up the next line
2042
        textptr++;
2043
    origtptr = textptr;
2044
 
2045
    Bstrcpy(parentScriptFileName, g_szScriptFileName);
2046
    Bstrcpy(g_szScriptFileName, confile);
2047
    temp_ScriptLineNumber = g_lineNumber;
2048
    g_lineNumber = 1;
2049
    temp_ifelse_check = g_checkingIfElse;
2050
    g_checkingIfElse = 0;
2051
 
2052
    textptr = mptr;
2053
 
2054
    C_SkipComments();
2055
 
2056
    C_ParseCommand(1);
2057
 
2058
    Bstrcpy(g_szScriptFileName, parentScriptFileName);
2059
    g_totalLines += g_lineNumber;
2060
    g_lineNumber = temp_ScriptLineNumber;
2061
    g_checkingIfElse = temp_ifelse_check;
2062
 
2063
    textptr = origtptr;
2064
 
2065
    Bfree(mptr);
2066
}
3410 helixhorne 2067
#endif  // !defined LUNATIC
1937 hendricks2 2068
 
2704 helixhorne 2069
#ifdef _WIN32
2070
static void check_filename_case(const char *fn)
2071
{
2072
    int32_t fp;
2073
    if ((fp = kopen4loadfrommod(fn, g_loadFromGroupOnly)) >= 0)
2074
        kclose(fp);
2075
}
2076
#else
2077
static void check_filename_case(const char *fn) { UNREFERENCED_PARAMETER(fn); }
2078
#endif
2079
 
3343 helixhorne 2080
void G_DoGameStartup(const int32_t *params)
2081
{
2082
    int32_t j = 0;
2083
 
2084
    ud.const_visibility = params[j++];
2085
    g_impactDamage = params[j++];
2086
    g_maxPlayerHealth = g_player[0].ps->max_player_health = g_player[0].ps->max_shield_amount = params[j++];
2087
    g_startArmorAmount = params[j++];
2088
    g_actorRespawnTime = params[j++];
3803 terminx 2089
 
2090
    if (g_scriptVersion >= 11)
2091
        g_itemRespawnTime = params[j++];
2092
    else
2093
        g_itemRespawnTime = g_actorRespawnTime;
2094
 
2095
    if (g_scriptVersion >= 11)
2096
        g_playerFriction = params[j++];
2097
 
2098
    if (g_scriptVersion == 14)
2099
        g_spriteGravity = params[j++];
2100
 
2101
    if (g_scriptVersion >= 11)
2102
    {
2103
        g_rpgBlastRadius = params[j++];
2104
        g_pipebombBlastRadius = params[j++];
2105
        g_shrinkerBlastRadius = params[j++];
2106
        g_tripbombBlastRadius = params[j++];
2107
        g_morterBlastRadius = params[j++];
2108
        g_bouncemineBlastRadius = params[j++];
2109
        g_seenineBlastRadius = params[j++];
2110
    }
2111
 
3343 helixhorne 2112
    g_player[0].ps->max_ammo_amount[PISTOL_WEAPON] = params[j++];
2113
    g_player[0].ps->max_ammo_amount[SHOTGUN_WEAPON] = params[j++];
2114
    g_player[0].ps->max_ammo_amount[CHAINGUN_WEAPON] = params[j++];
2115
    g_player[0].ps->max_ammo_amount[RPG_WEAPON] = params[j++];
2116
    g_player[0].ps->max_ammo_amount[HANDBOMB_WEAPON] = params[j++];
2117
    g_player[0].ps->max_ammo_amount[SHRINKER_WEAPON] = params[j++];
2118
    g_player[0].ps->max_ammo_amount[DEVISTATOR_WEAPON] = params[j++];
2119
    g_player[0].ps->max_ammo_amount[TRIPBOMB_WEAPON] = params[j++];
3803 terminx 2120
 
2121
    if (g_scriptVersion >= 13)
3343 helixhorne 2122
    {
3803 terminx 2123
        g_player[0].ps->max_ammo_amount[FREEZE_WEAPON] = params[j++];
3343 helixhorne 2124
 
3803 terminx 2125
        if (g_scriptVersion == 14)
2126
            g_player[0].ps->max_ammo_amount[GROW_WEAPON] = params[j++];
2127
 
2128
        g_damageCameras = params[j++];
2129
        g_numFreezeBounces = params[j++];
2130
        g_freezerSelfDamage = params[j++];
2131
 
2132
        if (g_scriptVersion == 14)
2133
        {
2134
            g_spriteDeleteQueueSize = params[j++];
2135
            g_spriteDeleteQueueSize = clamp(g_spriteDeleteQueueSize, 0, 1024);
2136
 
2137
            g_tripbombLaserMode = params[j++];
2138
        }
3343 helixhorne 2139
    }
2140
}
2141
 
4586 helixhorne 2142
void C_DefineMusic(int32_t vol, int32_t lev, const char *fn)
2143
{
4588 helixhorne 2144
    Bassert((unsigned)vol < MAXVOLUMES+1);
2145
    Bassert((unsigned)lev < MAXLEVELS);
4586 helixhorne 2146
 
2147
    {
4588 helixhorne 2148
        map_t *const map = &MapInfo[(MAXLEVELS*vol)+lev];
4586 helixhorne 2149
 
4588 helixhorne 2150
        Bfree(map->musicfn);
2151
        map->musicfn = dup_filename(fn);
2152
        check_filename_case(map->musicfn);
4586 helixhorne 2153
    }
2154
}
2155
 
3355 helixhorne 2156
#ifdef LUNATIC
2157
void C_DefineSound(int32_t sndidx, const char *fn, int32_t args[5])
2158
{
2159
    Bassert((unsigned)sndidx < MAXSOUNDS);
2160
 
2161
    {
2162
        sound_t *const snd = &g_sounds[sndidx];
2163
 
2164
        Bfree(snd->filename);
2165
        snd->filename = dup_filename(fn);
2166
        check_filename_case(snd->filename);
2167
 
2168
        snd->ps = args[0];
2169
        snd->pe = args[1];
2170
        snd->pr = args[2];
4067 helixhorne 2171
        snd->m = args[3] & ~SF_ONEINST_INTERNAL;
2172
        if (args[3] & SF_LOOP)
2173
            snd->m |= SF_ONEINST_INTERNAL;
3355 helixhorne 2174
        snd->vo = args[4];
2175
 
2176
        if (sndidx > g_maxSoundPos)
2177
            g_maxSoundPos = sndidx;
2178
    }
2179
}
3357 helixhorne 2180
 
2181
void C_DefineQuote(int32_t qnum, const char *qstr)
2182
{
2183
    C_AllocQuote(qnum);
2184
    Bstrncpyz(ScriptQuotes[qnum], qstr, MAXQUOTELEN);
2185
}
3373 helixhorne 2186
 
2187
void C_DefineVolumeName(int32_t vol, const char *name)
2188
{
2189
    Bassert((unsigned)vol < MAXVOLUMES);
2190
    Bstrncpyz(EpisodeNames[vol], name, sizeof(EpisodeNames[vol]));
2191
    g_numVolumes = max(g_numVolumes, vol+1);
2192
}
2193
 
3375 helixhorne 2194
void C_DefineSkillName(int32_t skill, const char *name)
2195
{
2196
    Bassert((unsigned)skill < MAXSKILLS);
2197
    Bstrncpyz(SkillNames[skill], name, sizeof(SkillNames[skill]));
2198
    g_numSkills = max(g_numSkills, skill+1);
2199
}
2200
 
3373 helixhorne 2201
void C_DefineLevelName(int32_t vol, int32_t lev, const char *fn,
2202
                       int32_t partime, int32_t designertime,
2203
                       const char *levelname)
2204
{
2205
    Bassert((unsigned)vol < MAXVOLUMES);
2206
    Bassert((unsigned)lev < MAXLEVELS);
2207
 
2208
    {
2209
        map_t *const map = &MapInfo[(MAXLEVELS*vol)+lev];
2210
 
2211
        Bfree(map->filename);
2212
        map->filename = dup_filename(fn);
2213
 
2214
        // TODO: truncate to 32 chars?
2215
        Bfree(map->name);
4491 helixhorne 2216
        map->name = Xstrdup(levelname);
3373 helixhorne 2217
 
2218
        map->partime = REALGAMETICSPERSEC * partime;
2219
        map->designertime = REALGAMETICSPERSEC * designertime;
2220
    }
2221
}
3516 helixhorne 2222
 
2223
void C_DefineGameFuncName(int32_t idx, const char *name)
2224
{
3826 helixhorne 2225
    assert((unsigned)idx < NUMGAMEFUNCTIONS);
3516 helixhorne 2226
 
2227
    Bstrncpyz(gamefunctions[idx], name, MAXGAMEFUNCLEN);
2228
    Bstrncpyz(keydefaults[3*idx], name, MAXGAMEFUNCLEN);
3530 helixhorne 2229
 
2230
    hash_add(&h_gamefuncs, gamefunctions[idx], idx, 0);
3516 helixhorne 2231
}
3826 helixhorne 2232
 
2233
void C_DefineGameType(int32_t idx, int32_t flags, con