Subversion Repositories eduke32

Rev

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

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