Subversion Repositories eduke32

Rev

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