2006-04-13 20:47:06 +00:00
//-------------------------------------------------------------------------
/*
2016-02-02 00:21:24 +00:00
Copyright ( C ) 2016 EDuke32 developers and contributors
2006-04-13 20:47:06 +00:00
2010-05-25 10:56:00 +00:00
This file is part of EDuke32 .
2006-04-13 20:47:06 +00:00
EDuke32 is free software ; you can redistribute it and / or
modify it under the terms of the GNU General Public License version 2
as published by the Free Software Foundation .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE .
See the GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program ; if not , write to the Free Software
2014-07-20 08:55:56 +00:00
Foundation , Inc . , 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 , USA .
2006-04-13 20:47:06 +00:00
*/
//-------------------------------------------------------------------------
2018-12-15 01:37:13 +00:00
# include "gamedef.h"
2018-11-18 18:09:48 +00:00
# include "cheats.h"
# include "common.h"
# include "common_game.h"
# include "crc32.h"
2018-12-15 01:37:13 +00:00
# include "debugbreak.h"
2006-04-13 20:47:06 +00:00
# include "duke3d.h"
2010-08-02 08:13:51 +00:00
# include "gameexec.h"
2018-11-18 18:09:48 +00:00
# include "namesdyn.h"
2006-04-13 20:47:06 +00:00
# include "osd.h"
2018-11-18 18:09:48 +00:00
# include "savegame.h"
2006-04-13 20:47:06 +00:00
2018-12-15 01:36:48 +00:00
# define LINE_NUMBER (g_lineNumber << 12)
2009-01-09 09:29:17 +00:00
int32_t g_scriptVersion = 13 ; // 13 = 1.3D-style CON files, 14 = 1.4/1.5 style CON files
2006-04-13 20:47:06 +00:00
2016-08-27 01:42:01 +00:00
char g_scriptFileName [ BMAX_PATH ] = " (none) " ; // file we're currently compiling
2008-11-20 14:06:36 +00:00
2018-12-15 01:36:42 +00:00
int32_t g_totalLines ;
int32_t g_lineNumber ;
2018-08-09 16:06:49 +00:00
uint32_t g_scriptcrc ;
2006-04-13 20:47:06 +00:00
char g_szBuf [ 1024 ] ;
2013-01-19 18:29:00 +00:00
# if !defined LUNATIC
2018-12-15 01:36:42 +00:00
static char * textptr ;
static char g_szCurrentBlockName [ 64 ] = " (none) " ;
static char g_szLastBlockName [ 64 ] = " NULL " ;
static bool g_checkingCase ;
static bool g_dynamicSoundMapping ;
static bool g_dynamicTileMapping ;
static bool g_labelsOnly ;
static bool g_processingState ;
static bool g_skipBranch ;
static int g_checkingIfElse ;
static int g_checkingSwitch ;
static int g_lastKeyword = - 1 ;
static int g_numBraces ;
static int g_numCases ;
static intptr_t apScriptGameEventEnd [ MAXEVENTS ] ;
static intptr_t g_scriptActorOffset ;
static intptr_t g_scriptEventBreakOffset ;
static intptr_t g_scriptEventChainOffset ;
static intptr_t g_scriptEventOffset ;
2013-05-30 18:10:49 +00:00
2013-01-05 13:09:19 +00:00
// The pointer to the start of the case table in a switch statement.
// First entry is 'default' code.
2018-12-15 01:36:42 +00:00
static intptr_t * g_caseTablePtr ;
2006-04-13 20:47:06 +00:00
2018-11-18 18:10:21 +00:00
static bool C_ParseCommand ( bool loop ) ;
static void C_SetScriptSize ( int32_t newsize ) ;
2013-01-05 13:09:19 +00:00
# endif
2008-07-20 03:29:00 +00:00
2018-12-15 01:36:42 +00:00
int32_t g_errorCnt ;
int32_t g_warningCnt ;
int32_t g_numXStrings ;
2006-04-13 20:47:06 +00:00
2012-12-28 17:18:16 +00:00
# ifdef LUNATIC
weapondata_t g_playerWeapon [ MAXPLAYERS ] [ MAX_WEAPONS ] ;
# endif
2006-04-13 20:47:06 +00:00
2013-01-19 18:29:00 +00:00
# if !defined LUNATIC
2018-11-18 18:10:21 +00:00
static char * C_GetLabelType ( int const type )
2006-04-13 20:47:06 +00:00
{
2018-11-18 18:10:21 +00:00
static tokenmap_t const LabelType [ ] =
2011-04-07 01:16:29 +00:00
{
2018-11-18 18:10:21 +00:00
{ " action " , LABEL_ACTION } ,
{ " actor " , LABEL_ACTOR } ,
{ " ai " , LABEL_AI } ,
{ " define " , LABEL_DEFINE } ,
{ " event " , LABEL_EVENT } ,
{ " move " , LABEL_MOVE } ,
{ " state " , LABEL_STATE } ,
2011-04-07 01:16:29 +00:00
} ;
2018-11-18 18:10:21 +00:00
char x [ 64 ] = { } ;
for ( auto & label : LabelType )
2006-11-15 01:16:55 +00:00
{
2018-11-18 18:10:21 +00:00
if ( ( type & label . val ) ! = label . val )
continue ;
2006-04-13 20:47:06 +00:00
if ( x [ 0 ] ) Bstrcat ( x , " or " ) ;
2018-11-18 18:10:21 +00:00
Bstrcat ( x , label . token ) ;
if ( type = = label . val )
break ;
2006-04-13 20:47:06 +00:00
}
2014-05-30 00:02:19 +00:00
return Xstrdup ( x ) ;
2006-04-13 20:47:06 +00:00
}
2017-10-16 03:32:30 +00:00
2018-11-18 18:14:26 +00:00
static hashtable_t h_keywords = { CON_END > > 1 , NULL } ;
static hashtable_t h_iter = { ITER_END > > 1 , NULL } ;
static hashtable_t * const tables [ ] = {
& h_arrays ,
& h_gamevars ,
& h_iter ,
& h_keywords ,
& h_labels ,
} ;
static hashtable_t * const tables_free [ ] = {
& h_iter ,
& h_keywords ,
& h_labels ,
} ;
2017-10-16 03:32:34 +00:00
static tokenmap_t const vm_keywords [ ] =
2017-10-16 03:32:30 +00:00
{
{ " action " , CON_ACTION } ,
{ " activate " , CON_ACTIVATE } ,
{ " activatebysector " , CON_ACTIVATEBYSECTOR } ,
{ " activatecheat " , CON_ACTIVATECHEAT } ,
{ " actor " , CON_ACTOR } ,
2017-11-29 07:28:58 +00:00
{ " actorsound " , CON_ACTORSOUND } ,
2017-10-16 03:32:30 +00:00
{ " addammo " , CON_ADDAMMO } ,
{ " addinventory " , CON_ADDINVENTORY } ,
{ " addkills " , CON_ADDKILLS } ,
2018-12-15 01:37:49 +00:00
{ " addlog " , CON_ADDLOGVAR } ,
2017-10-16 03:32:30 +00:00
{ " addlogvar " , CON_ADDLOGVAR } ,
{ " addphealth " , CON_ADDPHEALTH } ,
{ " addstrength " , CON_ADDSTRENGTH } ,
{ " addvar " , CON_ADDVAR } ,
{ " addvarvar " , CON_ADDVARVAR } ,
{ " addweapon " , CON_ADDWEAPON } ,
2018-12-15 01:37:49 +00:00
{ " addweaponvar " , CON_ADDWEAPON } ,
2017-10-16 03:32:30 +00:00
{ " ai " , CON_AI } ,
{ " andvar " , CON_ANDVAR } ,
{ " andvarvar " , CON_ANDVARVAR } ,
{ " angoff " , CON_ANGOFF } ,
2018-12-15 01:37:49 +00:00
{ " angoffvar " , CON_ANGOFF } ,
2017-10-16 03:32:30 +00:00
{ " appendevent " , CON_APPENDEVENT } ,
{ " betaname " , CON_BETANAME } ,
{ " break " , CON_BREAK } ,
{ " cactor " , CON_CACTOR } ,
{ " calchypotenuse " , CON_CALCHYPOTENUSE } ,
{ " cansee " , CON_CANSEE } ,
{ " canseespr " , CON_CANSEESPR } ,
{ " case " , CON_CASE } ,
{ " changespritesect " , CON_CHANGESPRITESECT } ,
{ " changespritestat " , CON_CHANGESPRITESTAT } ,
{ " cheatkeys " , CON_CHEATKEYS } ,
{ " checkactivatormotion " , CON_CHECKACTIVATORMOTION } ,
{ " checkavailinven " , CON_CHECKAVAILINVEN } ,
{ " checkavailweapon " , CON_CHECKAVAILWEAPON } ,
{ " clamp " , CON_CLAMP } ,
{ " clearmapstate " , CON_CLEARMAPSTATE } ,
{ " clipdist " , CON_CLIPDIST } ,
{ " clipmove " , CON_CLIPMOVE } ,
{ " clipmovenoslide " , CON_CLIPMOVENOSLIDE } ,
{ " cmenu " , CON_CMENU } ,
{ " copy " , CON_COPY } ,
{ " cos " , CON_COS } ,
{ " count " , CON_COUNT } ,
{ " cstat " , CON_CSTAT } ,
{ " cstator " , CON_CSTATOR } ,
2018-03-17 03:26:10 +00:00
{ " damageeventtile " , CON_DAMAGEEVENTTILE } ,
{ " damageeventtilerange " , CON_DAMAGEEVENTTILERANGE } ,
2017-10-16 03:32:30 +00:00
{ " debris " , CON_DEBRIS } ,
{ " debug " , CON_DEBUG } ,
{ " default " , CON_DEFAULT } ,
{ " define " , CON_DEFINE } ,
{ " definecheat " , CON_DEFINECHEAT } ,
{ " definegamefuncname " , CON_DEFINEGAMEFUNCNAME } ,
{ " definegametype " , CON_DEFINEGAMETYPE } ,
{ " definelevelname " , CON_DEFINELEVELNAME } ,
{ " defineprojectile " , CON_DEFINEPROJECTILE } ,
{ " definequote " , CON_DEFINEQUOTE } ,
{ " defineskillname " , CON_DEFINESKILLNAME } ,
{ " definesound " , CON_DEFINESOUND } ,
{ " definevolumeflags " , CON_DEFINEVOLUMEFLAGS } ,
{ " definevolumename " , CON_DEFINEVOLUMENAME } ,
{ " defstate " , CON_DEFSTATE } ,
{ " digitalnumber " , CON_DIGITALNUMBER } ,
{ " digitalnumberz " , CON_DIGITALNUMBERZ } ,
{ " displayrand " , CON_DISPLAYRAND } ,
{ " displayrandvar " , CON_DISPLAYRANDVAR } ,
{ " displayrandvarvar " , CON_DISPLAYRANDVARVAR } ,
{ " dist " , CON_DIST } ,
2018-01-29 02:14:04 +00:00
{ " divr " , CON_DIVR } ,
{ " divrd " , CON_DIVVARVAR } , // div round toward zero -- alias until proven otherwise
{ " divru " , CON_DIVRU } ,
2017-10-16 03:32:30 +00:00
{ " divscale " , CON_DIVSCALE } ,
{ " divvar " , CON_DIVVAR } ,
{ " divvarvar " , CON_DIVVARVAR } ,
{ " dragpoint " , CON_DRAGPOINT } ,
{ " drawline256 " , CON_DRAWLINE256 } ,
{ " drawlinergb " , CON_DRAWLINERGB } ,
{ " dynamicremap " , CON_DYNAMICREMAP } ,
{ " dynamicsoundremap " , CON_DYNAMICSOUNDREMAP } ,
{ " echo " , CON_ECHO } ,
{ " else " , CON_ELSE } ,
{ " enda " , CON_ENDA } ,
{ " endevent " , CON_ENDEVENT } ,
{ " endofgame " , CON_ENDOFGAME } ,
{ " endoflevel " , CON_ENDOFLEVEL } ,
{ " ends " , CON_ENDS } ,
{ " endswitch " , CON_ENDSWITCH } ,
{ " enhanced " , CON_ENHANCED } ,
2018-12-15 01:37:49 +00:00
{ " eqspawnvar " , CON_EQSPAWN } ,
{ " eshootvar " , CON_ESHOOT } ,
{ " espawnvar " , CON_ESPAWN } ,
2017-10-16 03:32:30 +00:00
{ " eventloadactor " , CON_EVENTLOADACTOR } ,
2018-12-15 01:37:49 +00:00
{ " ezshootvar " , CON_EZSHOOT } ,
2017-10-16 03:32:30 +00:00
{ " fall " , CON_FALL } ,
2018-12-15 01:37:49 +00:00
{ " findnearactor3dvar " , CON_FINDNEARACTOR3D } ,
{ " findnearactorvar " , CON_FINDNEARACTOR } ,
{ " findnearactorzvar " , CON_FINDNEARACTORZ } ,
{ " findnearsprite3dvar " , CON_FINDNEARSPRITE3D } ,
{ " findnearspritevar " , CON_FINDNEARSPRITE } ,
{ " findnearspritezvar " , CON_FINDNEARSPRITEZ } ,
2017-10-16 03:32:30 +00:00
{ " findotherplayer " , CON_FINDOTHERPLAYER } ,
{ " findplayer " , CON_FINDPLAYER } ,
{ " flash " , CON_FLASH } ,
{ " for " , CON_FOR } ,
{ " gamearray " , CON_GAMEARRAY } ,
{ " gamestartup " , CON_GAMESTARTUP } ,
{ " gametext " , CON_GAMETEXT } ,
{ " gametextz " , CON_GAMETEXTZ } ,
{ " gamevar " , CON_GAMEVAR } ,
{ " getactor " , CON_GETACTOR } ,
{ " getactorangle " , CON_GETACTORANGLE } ,
{ " getactorvar " , CON_GETACTORVAR } ,
{ " getangle " , CON_GETANGLE } ,
{ " getangletotarget " , CON_GETANGLETOTARGET } ,
{ " getarraysize " , CON_GETARRAYSIZE } ,
{ " getceilzofslope " , CON_GETCEILZOFSLOPE } ,
{ " getclosestcol " , CON_GETCLOSESTCOL } ,
{ " getcurraddress " , CON_GETCURRADDRESS } ,
{ " getflorzofslope " , CON_GETFLORZOFSLOPE } ,
{ " getincangle " , CON_GETINCANGLE } ,
{ " getinput " , CON_GETINPUT } ,
{ " getkeyname " , CON_GETKEYNAME } ,
{ " getlastpal " , CON_GETLASTPAL } ,
{ " getmusicposition " , CON_GETMUSICPOSITION } ,
{ " getplayer " , CON_GETPLAYER } ,
{ " getplayerangle " , CON_GETPLAYERANGLE } ,
{ " getplayervar " , CON_GETPLAYERVAR } ,
{ " getpname " , CON_GETPNAME } ,
{ " getprojectile " , CON_GETPROJECTILE } ,
{ " getsector " , CON_GETSECTOR } ,
{ " gettextureceiling " , CON_GETTEXTURECEILING } ,
{ " gettexturefloor " , CON_GETTEXTUREFLOOR } ,
{ " getthisprojectile " , CON_GETTHISPROJECTILE } ,
{ " getticks " , CON_GETTICKS } ,
2018-03-15 01:19:27 +00:00
{ " gettiledata " , CON_GETTILEDATA } , // OldMP compat.
2017-10-16 03:32:30 +00:00
{ " gettimedate " , CON_GETTIMEDATE } ,
{ " gettspr " , CON_GETTSPR } ,
{ " getuserdef " , CON_GETUSERDEF } ,
{ " getwall " , CON_GETWALL } ,
{ " getzrange " , CON_GETZRANGE } ,
{ " globalsound " , CON_GLOBALSOUND } ,
2018-12-15 01:37:49 +00:00
{ " globalsoundvar " , CON_GLOBALSOUND } ,
2017-10-16 03:32:30 +00:00
{ " gmaxammo " , CON_GMAXAMMO } ,
{ " guniqhudid " , CON_GUNIQHUDID } ,
{ " guts " , CON_GUTS } ,
{ " headspritesect " , CON_HEADSPRITESECT } ,
{ " headspritestat " , CON_HEADSPRITESTAT } ,
{ " hitradius " , CON_HITRADIUS } ,
2018-12-15 01:37:49 +00:00
{ " hitradiusvar " , CON_HITRADIUS } ,
2017-10-16 03:32:30 +00:00
{ " hitscan " , CON_HITSCAN } ,
{ " ifaction " , CON_IFACTION } ,
{ " ifactioncount " , CON_IFACTIONCOUNT } ,
{ " ifactor " , CON_IFACTOR } ,
{ " ifactornotstayput " , CON_IFACTORNOTSTAYPUT } ,
{ " ifactorsound " , CON_IFACTORSOUND } ,
{ " ifai " , CON_IFAI } ,
{ " ifangdiffl " , CON_IFANGDIFFL } ,
{ " ifawayfromwall " , CON_IFAWAYFROMWALL } ,
{ " ifbulletnear " , CON_IFBULLETNEAR } ,
{ " ifcansee " , CON_IFCANSEE } ,
{ " ifcanseetarget " , CON_IFCANSEETARGET } ,
{ " ifcanshoottarget " , CON_IFCANSHOOTTARGET } ,
{ " ifceilingdistl " , CON_IFCEILINGDISTL } ,
{ " ifclient " , CON_IFCLIENT } ,
{ " ifcount " , CON_IFCOUNT } ,
{ " ifcutscene " , CON_IFCUTSCENE } ,
{ " ifdead " , CON_IFDEAD } ,
{ " iffloordistl " , CON_IFFLOORDISTL } ,
{ " ifgapzl " , CON_IFGAPZL } ,
{ " ifgotweaponce " , CON_IFGOTWEAPONCE } ,
{ " ifhitspace " , CON_IFHITSPACE } ,
{ " ifhitweapon " , CON_IFHITWEAPON } ,
{ " ifinouterspace " , CON_IFINOUTERSPACE } ,
{ " ifinspace " , CON_IFINSPACE } ,
{ " ifinwater " , CON_IFINWATER } ,
{ " ifmove " , CON_IFMOVE } ,
{ " ifmultiplayer " , CON_IFMULTIPLAYER } ,
{ " ifnosounds " , CON_IFNOSOUNDS } ,
{ " ifnotmoving " , CON_IFNOTMOVING } ,
{ " ifonwater " , CON_IFONWATER } ,
{ " ifoutside " , CON_IFOUTSIDE } ,
{ " ifp " , CON_IFP } ,
{ " ifpdistg " , CON_IFPDISTG } ,
{ " ifpdistl " , CON_IFPDISTL } ,
{ " ifphealthl " , CON_IFPHEALTHL } ,
{ " ifpinventory " , CON_IFPINVENTORY } ,
{ " ifplaybackon " , CON_IFPLAYBACKON } ,
{ " ifplayersl " , CON_IFPLAYERSL } ,
{ " ifrespawn " , CON_IFRESPAWN } ,
{ " ifrnd " , CON_IFRND } ,
{ " ifserver " , CON_IFSERVER } ,
{ " ifsound " , CON_IFSOUND } ,
{ " ifspawnedby " , CON_IFSPAWNEDBY } ,
{ " ifspritepal " , CON_IFSPRITEPAL } ,
{ " ifsquished " , CON_IFSQUISHED } ,
{ " ifstrength " , CON_IFSTRENGTH } ,
2018-01-31 05:23:48 +00:00
{ " ifvara " , CON_IFVARA } ,
{ " ifvarae " , CON_IFVARAE } ,
2017-10-16 03:32:30 +00:00
{ " ifvarand " , CON_IFVARAND } ,
2018-01-31 05:23:48 +00:00
{ " ifvarb " , CON_IFVARB } ,
{ " ifvarbe " , CON_IFVARBE } ,
2017-10-16 03:32:30 +00:00
{ " ifvarboth " , CON_IFVARBOTH } ,
{ " ifvare " , CON_IFVARE } ,
{ " ifvareither " , CON_IFVAREITHER } ,
{ " ifvarg " , CON_IFVARG } ,
{ " ifvarge " , CON_IFVARGE } ,
{ " ifvarl " , CON_IFVARL } ,
{ " ifvarle " , CON_IFVARLE } ,
{ " ifvarn " , CON_IFVARN } ,
{ " ifvaror " , CON_IFVAROR } ,
2018-01-31 05:23:48 +00:00
{ " ifvarvara " , CON_IFVARVARA } ,
{ " ifvarvarae " , CON_IFVARVARAE } ,
2017-10-16 03:32:30 +00:00
{ " ifvarvarand " , CON_IFVARVARAND } ,
2018-01-31 05:23:48 +00:00
{ " ifvarvarb " , CON_IFVARVARB } ,
{ " ifvarvarbe " , CON_IFVARVARBE } ,
2017-10-16 03:32:30 +00:00
{ " ifvarvarboth " , CON_IFVARVARBOTH } ,
{ " ifvarvare " , CON_IFVARVARE } ,
{ " ifvarvareither " , CON_IFVARVAREITHER } ,
{ " ifvarvarg " , CON_IFVARVARG } ,
{ " ifvarvarge " , CON_IFVARVARGE } ,
{ " ifvarvarl " , CON_IFVARVARL } ,
{ " ifvarvarle " , CON_IFVARVARLE } ,
{ " ifvarvarn " , CON_IFVARVARN } ,
{ " ifvarvaror " , CON_IFVARVAROR } ,
{ " ifvarvarxor " , CON_IFVARVARXOR } ,
{ " ifvarxor " , CON_IFVARXOR } ,
{ " ifwasweapon " , CON_IFWASWEAPON } ,
{ " include " , CON_INCLUDE } ,
{ " includedefault " , CON_INCLUDEDEFAULT } ,
{ " inittimer " , CON_INITTIMER } ,
{ " insertspriteq " , CON_INSERTSPRITEQ } ,
{ " inv " , CON_INV } ,
{ " jump " , CON_JUMP } ,
{ " killit " , CON_KILLIT } ,
{ " klabs " , CON_KLABS } ,
{ " ldist " , CON_LDIST } ,
{ " lineintersect " , CON_LINEINTERSECT } ,
{ " loadmapstate " , CON_LOADMAPSTATE } ,
{ " lockplayer " , CON_LOCKPLAYER } ,
{ " lotsofglass " , CON_LOTSOFGLASS } ,
{ " mail " , CON_MAIL } ,
{ " mikesnd " , CON_MIKESND } ,
{ " minitext " , CON_MINITEXT } ,
{ " modvar " , CON_MODVAR } ,
{ " modvarvar " , CON_MODVARVAR } ,
{ " money " , CON_MONEY } ,
{ " move " , CON_MOVE } ,
{ " movesector " , CON_MOVESECTOR } ,
{ " movesprite " , CON_MOVESPRITE } ,
{ " mulscale " , CON_MULSCALE } ,
{ " mulvar " , CON_MULVAR } ,
{ " mulvarvar " , CON_MULVARVAR } ,
{ " music " , CON_MUSIC } ,
{ " myos " , CON_MYOS } ,
{ " myospal " , CON_MYOSPAL } ,
{ " myospalx " , CON_MYOSPALX } ,
{ " myosx " , CON_MYOSX } ,
{ " neartag " , CON_NEARTAG } ,
{ " nextsectorneighborz " , CON_NEXTSECTORNEIGHBORZ } ,
{ " nextspritesect " , CON_NEXTSPRITESECT } ,
{ " nextspritestat " , CON_NEXTSPRITESTAT } ,
{ " nullop " , CON_NULLOP } ,
{ " onevent " , CON_ONEVENT } ,
{ " operate " , CON_OPERATE } ,
{ " operateactivators " , CON_OPERATEACTIVATORS } ,
{ " operatemasterswitches " , CON_OPERATEMASTERSWITCHES } ,
{ " operaterespawns " , CON_OPERATERESPAWNS } ,
{ " operatesectors " , CON_OPERATESECTORS } ,
{ " orvar " , CON_ORVAR } ,
{ " orvarvar " , CON_ORVARVAR } ,
{ " palfrom " , CON_PALFROM } ,
{ " paper " , CON_PAPER } ,
{ " pkick " , CON_PKICK } ,
{ " precache " , CON_PRECACHE } ,
{ " prevspritesect " , CON_PREVSPRITESECT } ,
{ " prevspritestat " , CON_PREVSPRITESTAT } ,
2018-01-29 11:14:04 +00:00
{ " preloadtrackslotforswap " , CON_PRELOADTRACKSLOTFORSWAP } ,
2017-10-16 03:32:30 +00:00
{ " pstomp " , CON_PSTOMP } ,
{ " qgetsysstr " , CON_QGETSYSSTR } ,
2018-12-15 01:37:49 +00:00
{ " qspawnvar " , CON_QSPAWN } ,
2017-10-16 03:32:30 +00:00
{ " qsprintf " , CON_QSPRINTF } ,
{ " qstrcat " , CON_QSTRCAT } ,
2018-01-29 02:13:55 +00:00
{ " qstrcmp " , CON_QSTRCMP } ,
2017-10-16 03:32:30 +00:00
{ " qstrcpy " , CON_QSTRCPY } ,
{ " qstrdim " , CON_QSTRDIM } ,
{ " qstrlen " , CON_QSTRLEN } ,
{ " qstrncat " , CON_QSTRNCAT } ,
{ " qsubstr " , CON_QSUBSTR } ,
{ " quake " , CON_QUAKE } ,
{ " quote " , CON_QUOTE } ,
{ " randvar " , CON_RANDVAR } ,
{ " randvarvar " , CON_RANDVARVAR } ,
{ " rayintersect " , CON_RAYINTERSECT } ,
{ " readarrayfromfile " , CON_READARRAYFROMFILE } ,
{ " readgamevar " , CON_READGAMEVAR } ,
{ " redefinequote " , CON_REDEFINEQUOTE } ,
{ " resetactioncount " , CON_RESETACTIONCOUNT } ,
{ " resetcount " , CON_RESETCOUNT } ,
{ " resetplayer " , CON_RESETPLAYER } ,
{ " resetplayerflags " , CON_RESETPLAYERFLAGS } ,
{ " resizearray " , CON_RESIZEARRAY } ,
{ " respawnhitag " , CON_RESPAWNHITAG } ,
{ " return " , CON_RETURN } ,
{ " rotatepoint " , CON_ROTATEPOINT } ,
{ " rotatesprite " , CON_ROTATESPRITE } ,
{ " rotatesprite16 " , CON_ROTATESPRITE16 } ,
{ " rotatespritea " , CON_ROTATESPRITEA } ,
{ " save " , CON_SAVE } ,
{ " savegamevar " , CON_SAVEGAMEVAR } ,
{ " savemapstate " , CON_SAVEMAPSTATE } ,
{ " savenn " , CON_SAVENN } ,
{ " scalevar " , CON_SCALEVAR } ,
2017-11-29 07:29:14 +00:00
{ " screenpal " , CON_SCREENPAL } ,
2017-10-16 03:32:30 +00:00
{ " screensound " , CON_SCREENSOUND } ,
{ " screentext " , CON_SCREENTEXT } ,
{ " scriptsize " , CON_SCRIPTSIZE } ,
{ " sectclearinterpolation " , CON_SECTCLEARINTERPOLATION } ,
{ " sectgethitag " , CON_SECTGETHITAG } ,
{ " sectgetlotag " , CON_SECTGETLOTAG } ,
{ " sectorofwall " , CON_SECTOROFWALL } ,
{ " sectsetinterpolation " , CON_SECTSETINTERPOLATION } ,
{ " setactor " , CON_SETACTOR } ,
{ " setactorangle " , CON_SETACTORANGLE } ,
{ " setactorsoundpitch " , CON_SETACTORSOUNDPITCH } ,
{ " setactorvar " , CON_SETACTORVAR } ,
{ " setarray " , CON_SETARRAY } ,
{ " setaspect " , CON_SETASPECT } ,
{ " setcfgname " , CON_SETCFGNAME } ,
{ " setdefname " , CON_SETDEFNAME } ,
{ " setgamename " , CON_SETGAMENAME } ,
{ " setgamepalette " , CON_SETGAMEPALETTE } ,
{ " setinput " , CON_SETINPUT } ,
{ " setmusicposition " , CON_SETMUSICPOSITION } ,
{ " setplayer " , CON_SETPLAYER } ,
{ " setplayerangle " , CON_SETPLAYERANGLE } ,
{ " setplayervar " , CON_SETPLAYERVAR } ,
{ " setprojectile " , CON_SETPROJECTILE } ,
{ " setsector " , CON_SETSECTOR } ,
{ " setsprite " , CON_SETSPRITE } ,
{ " setthisprojectile " , CON_SETTHISPROJECTILE } ,
2018-03-15 01:19:27 +00:00
{ " settiledata " , CON_SETTILEDATA } ,
2017-10-16 03:32:30 +00:00
{ " settspr " , CON_SETTSPR } ,
{ " setuserdef " , CON_SETUSERDEF } ,
{ " setvar " , CON_SETVAR } ,
{ " setvarvar " , CON_SETVARVAR } ,
{ " setwall " , CON_SETWALL } ,
{ " shadeto " , CON_SHADETO } ,
{ " shiftvarl " , CON_SHIFTVARL } ,
{ " shiftvarr " , CON_SHIFTVARR } ,
{ " shiftvarvarl " , CON_SHIFTVARVARL } ,
{ " shiftvarvarr " , CON_SHIFTVARVARR } ,
2018-12-15 01:37:49 +00:00
{ " shootvar " , CON_SHOOT } ,
2017-10-16 03:32:30 +00:00
{ " showview " , CON_SHOWVIEW } ,
{ " showviewunbiased " , CON_SHOWVIEWUNBIASED } ,
2018-03-07 12:02:03 +00:00
{ " showviewq16 " , CON_SHOWVIEWQ16 } ,
{ " showviewq16unbiased " , CON_SHOWVIEWQ16UNBIASED } ,
2017-10-16 03:32:30 +00:00
{ " sin " , CON_SIN } ,
{ " sizeat " , CON_SIZEAT } ,
{ " sizeto " , CON_SIZETO } ,
{ " sleeptime " , CON_SLEEPTIME } ,
{ " smaxammo " , CON_SMAXAMMO } ,
{ " sound " , CON_SOUND } ,
{ " soundonce " , CON_SOUNDONCE } ,
2018-12-15 01:37:49 +00:00
{ " soundoncevar " , CON_SOUNDONCE } ,
{ " soundvar " , CON_SOUND } ,
2017-10-16 03:32:30 +00:00
{ " spawn " , CON_SPAWN } ,
2018-04-11 03:33:59 +00:00
{ " spawnceilingglass " , CON_SPAWNCEILINGGLASS } ,
{ " spawnwallstainedglass " , CON_SPAWNWALLSTAINEDGLASS } ,
{ " spawnwallglass " , CON_SPAWNWALLGLASS } ,
2017-10-16 03:32:30 +00:00
{ " spgethitag " , CON_SPGETHITAG } ,
{ " spgetlotag " , CON_SPGETLOTAG } ,
{ " spriteflags " , CON_SPRITEFLAGS } ,
{ " spritenopal " , CON_SPRITENOPAL } ,
{ " spritenoshade " , CON_SPRITENOSHADE } ,
{ " spritenvg " , CON_SPRITENVG } ,
{ " spritepal " , CON_SPRITEPAL } ,
{ " spriteshadow " , CON_SPRITESHADOW } ,
{ " sqrt " , CON_SQRT } ,
{ " ssp " , CON_SSP } ,
{ " startcutscene " , CON_STARTCUTSCENE } ,
{ " startlevel " , CON_STARTLEVEL } ,
2017-11-29 07:29:11 +00:00
{ " startscreen " , CON_STARTSCREEN } ,
2017-10-16 03:32:30 +00:00
{ " starttrack " , CON_STARTTRACK } ,
{ " starttrackslot " , CON_STARTTRACKSLOT } ,
2018-12-15 01:37:49 +00:00
{ " starttrackvar " , CON_STARTTRACK } ,
2017-10-16 03:32:30 +00:00
{ " state " , CON_STATE } ,
{ " stopactorsound " , CON_STOPACTORSOUND } ,
{ " stopallmusic " , CON_STOPALLMUSIC } ,
{ " stopallsounds " , CON_STOPALLSOUNDS } ,
{ " stopsound " , CON_STOPSOUND } ,
2018-12-15 01:37:49 +00:00
{ " stopsoundvar " , CON_STOPSOUND } ,
2017-10-16 03:32:30 +00:00
{ " strength " , CON_STRENGTH } ,
{ " subvar " , CON_SUBVAR } ,
{ " subvarvar " , CON_SUBVARVAR } ,
{ " switch " , CON_SWITCH } ,
2018-05-23 05:58:21 +00:00
{ " swaparrays " , CON_SWAPARRAYS } ,
2018-01-29 11:14:04 +00:00
{ " swaptrackslot " , CON_SWAPTRACKSLOT } ,
2017-10-16 03:32:30 +00:00
{ " time " , CON_TIME } ,
{ " tip " , CON_TIP } ,
{ " tossweapon " , CON_TOSSWEAPON } ,
2018-02-20 11:55:20 +00:00
{ " undefinecheat " , CON_UNDEFINECHEAT } ,
2017-10-16 03:32:30 +00:00
{ " undefinegamefunc " , CON_UNDEFINEGAMEFUNC } ,
{ " undefinelevel " , CON_UNDEFINELEVEL } ,
{ " undefineskill " , CON_UNDEFINESKILL } ,
{ " undefinevolume " , CON_UNDEFINEVOLUME } ,
{ " updatesector " , CON_UPDATESECTOR } ,
{ " updatesectorz " , CON_UPDATESECTORZ } ,
{ " useractor " , CON_USERACTOR } ,
{ " userquote " , CON_USERQUOTE } ,
{ " wackplayer " , CON_WACKPLAYER } ,
{ " whilevarl " , CON_WHILEVARL } ,
{ " whilevarn " , CON_WHILEVARN } ,
{ " whilevarvarl " , CON_WHILEVARVARL } ,
{ " whilevarvarn " , CON_WHILEVARVARN } ,
{ " writearraytofile " , CON_WRITEARRAYTOFILE } ,
{ " xorvar " , CON_XORVAR } ,
{ " xorvarvar " , CON_XORVARVAR } ,
2018-12-15 01:37:49 +00:00
{ " zshootvar " , CON_ZSHOOT } ,
2017-10-16 03:32:30 +00:00
{ " { " , CON_LEFTBRACE } ,
{ " } " , CON_RIGHTBRACE } ,
{ " #define " , CON_DEFINE } ,
{ " #include " , CON_INCLUDE } ,
{ " al " , CON_ADDLOGVAR } ,
{ " var " , CON_GAMEVAR } ,
{ " array " , CON_GAMEARRAY } ,
{ " shiftl " , CON_SHIFTVARVARL } ,
{ " shiftr " , CON_SHIFTVARVARR } ,
{ " rand " , CON_RANDVARVAR } ,
{ " set " , CON_SETVARVAR } ,
{ " add " , CON_ADDVARVAR } ,
{ " sub " , CON_SUBVARVAR } ,
{ " mul " , CON_MULVARVAR } ,
{ " div " , CON_DIVVARVAR } ,
{ " mod " , CON_MODVARVAR } ,
{ " and " , CON_ANDVARVAR } ,
{ " or " , CON_ORVARVAR } ,
{ " xor " , CON_XORVARVAR } ,
2018-01-31 05:23:48 +00:00
{ " ifa " , CON_IFVARVARA } ,
{ " ifae " , CON_IFVARVARAE } ,
{ " ifb " , CON_IFVARVARB } ,
{ " ifbe " , CON_IFVARVARBE } ,
2017-10-16 03:32:30 +00:00
{ " ifl " , CON_IFVARVARL } ,
{ " ifle " , CON_IFVARVARLE } ,
{ " ifg " , CON_IFVARVARG } ,
{ " ifge " , CON_IFVARVARGE } ,
{ " ife " , CON_IFVARVARE } ,
{ " ifn " , CON_IFVARVARN } ,
{ " ifand " , CON_IFVARVARAND } ,
{ " ifor " , CON_IFVARVAROR } ,
{ " ifxor " , CON_IFVARVARXOR } ,
{ " ifeither " , CON_IFVARVAREITHER } ,
{ " ifboth " , CON_IFVARVARBOTH } ,
{ " whilen " , CON_WHILEVARVARN } ,
{ " whilel " , CON_WHILEVARVARL } ,
{ " abs " , CON_KLABS } ,
{ " getp " , CON_GETPLAYER } ,
{ " getpv " , CON_GETPLAYERVAR } ,
{ " gets " , CON_GETSECTOR } ,
{ " geta " , CON_GETACTOR } ,
{ " getav " , CON_GETACTORVAR } ,
{ " getw " , CON_GETWALL } ,
{ " getu " , CON_GETUSERDEF } ,
{ " geti " , CON_GETINPUT } ,
{ " setp " , CON_SETPLAYER } ,
{ " setpv " , CON_SETPLAYERVAR } ,
{ " sets " , CON_SETSECTOR } ,
{ " seta " , CON_SETACTOR } ,
{ " setav " , CON_SETACTORVAR } ,
{ " setw " , CON_SETWALL } ,
{ " setu " , CON_SETUSERDEF } ,
{ " seti " , CON_SETINPUT } ,
{ " string " , CON_DEFINEQUOTE } ,
{ " print " , CON_QUOTE } ,
{ " dc " , CON_DEFINECHEAT } ,
2018-02-20 11:55:20 +00:00
{ " udc " , CON_UNDEFINECHEAT } ,
2017-10-16 03:32:30 +00:00
{ " ck " , CON_CHEATKEYS } ,
{ " qputs " , CON_REDEFINEQUOTE } ,
2018-12-15 01:37:49 +00:00
{ " espawn " , CON_ESPAWN } ,
{ " qspawn " , CON_QSPAWN } ,
{ " eqspawn " , CON_EQSPAWN } ,
2017-10-16 03:32:30 +00:00
2018-12-15 01:37:49 +00:00
{ " eshoot " , CON_ESHOOT } ,
{ " zshoot " , CON_ZSHOOT } ,
{ " ezshoot " , CON_EZSHOOT } ,
{ " shoot " , CON_SHOOT } ,
2017-10-16 03:32:30 +00:00
2018-12-15 01:37:49 +00:00
{ " findnearactor " , CON_FINDNEARACTOR } ,
{ " findnearactor3d " , CON_FINDNEARACTOR3D } ,
{ " findnearactorz " , CON_FINDNEARACTORZ } ,
2017-10-16 03:32:30 +00:00
2018-12-15 01:37:49 +00:00
{ " findnearsprite " , CON_FINDNEARSPRITE } ,
{ " findnearsprite3d " , CON_FINDNEARSPRITE3D } ,
{ " findnearspritez " , CON_FINDNEARSPRITEZ } ,
2017-10-16 03:32:30 +00:00
} ;
2018-12-15 01:37:13 +00:00
static const vec2_t varvartable [ ] =
{
{ CON_IFVARVARA , CON_IFVARA } ,
{ CON_IFVARVARAE , CON_IFVARAE } ,
{ CON_IFVARVARAND , CON_IFVARAND } ,
{ CON_IFVARVARB , CON_IFVARB } ,
{ CON_IFVARVARBE , CON_IFVARBE } ,
{ CON_IFVARVARBOTH , CON_IFVARBOTH } ,
{ CON_IFVARVARE , CON_IFVARE } ,
{ CON_IFVARVAREITHER , CON_IFVAREITHER } ,
{ CON_IFVARVARG , CON_IFVARG } ,
{ CON_IFVARVARGE , CON_IFVARGE } ,
{ CON_IFVARVARL , CON_IFVARL } ,
{ CON_IFVARVARLE , CON_IFVARLE } ,
{ CON_IFVARVARN , CON_IFVARN } ,
{ CON_IFVARVAROR , CON_IFVAROR } ,
{ CON_IFVARVARXOR , CON_IFVARXOR } ,
{ CON_ADDVARVAR , CON_ADDVAR } ,
{ CON_ANDVARVAR , CON_ANDVAR } ,
{ CON_DISPLAYRANDVARVAR , CON_DISPLAYRANDVAR } ,
{ CON_DIVVARVAR , CON_DIVVAR } ,
{ CON_MODVARVAR , CON_MODVAR } ,
{ CON_MULVARVAR , CON_MULVAR } ,
{ CON_ORVARVAR , CON_ORVAR } ,
{ CON_RANDVARVAR , CON_RANDVAR } ,
{ CON_SETVARVAR , CON_SETVAR } ,
{ CON_SHIFTVARVARL , CON_SHIFTVARL } ,
{ CON_SHIFTVARVARR , CON_SHIFTVARR } ,
{ CON_SUBVARVAR , CON_SUBVAR } ,
{ CON_WHILEVARVARL , CON_WHILEVARL } ,
{ CON_WHILEVARVARN , CON_WHILEVARN } ,
{ CON_XORVARVAR , CON_XORVAR } ,
} ;
2018-12-15 01:38:00 +00:00
static const vec2_t globalvartable [ ] =
{
2018-12-15 01:38:16 +00:00
{ CON_IFVARA , CON_IFVARA_GLOBAL } ,
{ CON_IFVARAE , CON_IFVARAE_GLOBAL } ,
{ CON_IFVARAND , CON_IFVARAND_GLOBAL } ,
{ CON_IFVARB , CON_IFVARB_GLOBAL } ,
{ CON_IFVARBE , CON_IFVARBE_GLOBAL } ,
{ CON_IFVARBOTH , CON_IFVARBOTH_GLOBAL } ,
{ CON_IFVARE , CON_IFVARE_GLOBAL } ,
{ CON_IFVAREITHER , CON_IFVAREITHER_GLOBAL } ,
{ CON_IFVARG , CON_IFVARG_GLOBAL } ,
{ CON_IFVARGE , CON_IFVARGE_GLOBAL } ,
{ CON_IFVARL , CON_IFVARL_GLOBAL } ,
{ CON_IFVARLE , CON_IFVARLE_GLOBAL } ,
{ CON_IFVARN , CON_IFVARN_GLOBAL } ,
{ CON_IFVAROR , CON_IFVAROR_GLOBAL } ,
{ CON_IFVARXOR , CON_IFVARXOR_GLOBAL } ,
{ CON_WHILEVARL , CON_WHILEVARL_GLOBAL } ,
{ CON_WHILEVARN , CON_WHILEVARN_GLOBAL } ,
{ CON_ADDVAR , CON_ADDVAR_GLOBAL } ,
{ CON_ANDVAR , CON_ANDVAR_GLOBAL } ,
{ CON_DIVVAR , CON_DIVVAR_GLOBAL } ,
{ CON_MODVAR , CON_MODVAR_GLOBAL } ,
{ CON_MULVAR , CON_MULVAR_GLOBAL } ,
{ CON_ORVAR , CON_ORVAR_GLOBAL } ,
{ CON_RANDVAR , CON_RANDVAR_GLOBAL } ,
{ CON_SETVAR , CON_SETVAR_GLOBAL } ,
{ CON_SHIFTVARL , CON_SHIFTVARL_GLOBAL } ,
{ CON_SHIFTVARR , CON_SHIFTVARR_GLOBAL } ,
{ CON_SUBVAR , CON_SUBVAR_GLOBAL } ,
{ CON_XORVAR , CON_XORVAR_GLOBAL } ,
} ;
static const vec2_t playervartable [ ] =
{
{ CON_IFVARA , CON_IFVARA_PLAYER } ,
{ CON_IFVARAE , CON_IFVARAE_PLAYER } ,
{ CON_IFVARAND , CON_IFVARAND_PLAYER } ,
{ CON_IFVARB , CON_IFVARB_PLAYER } ,
{ CON_IFVARBE , CON_IFVARBE_PLAYER } ,
{ CON_IFVARBOTH , CON_IFVARBOTH_PLAYER } ,
{ CON_IFVARE , CON_IFVARE_PLAYER } ,
{ CON_IFVAREITHER , CON_IFVAREITHER_PLAYER } ,
{ CON_IFVARG , CON_IFVARG_PLAYER } ,
{ CON_IFVARGE , CON_IFVARGE_PLAYER } ,
{ CON_IFVARL , CON_IFVARL_PLAYER } ,
{ CON_IFVARLE , CON_IFVARLE_PLAYER } ,
{ CON_IFVARN , CON_IFVARN_PLAYER } ,
{ CON_IFVAROR , CON_IFVAROR_PLAYER } ,
{ CON_IFVARXOR , CON_IFVARXOR_PLAYER } ,
{ CON_WHILEVARL , CON_WHILEVARL_PLAYER } ,
{ CON_WHILEVARN , CON_WHILEVARN_PLAYER } ,
{ CON_ADDVAR , CON_ADDVAR_PLAYER } ,
{ CON_ANDVAR , CON_ANDVAR_PLAYER } ,
{ CON_DIVVAR , CON_DIVVAR_PLAYER } ,
{ CON_MODVAR , CON_MODVAR_PLAYER } ,
{ CON_MULVAR , CON_MULVAR_PLAYER } ,
{ CON_ORVAR , CON_ORVAR_PLAYER } ,
{ CON_RANDVAR , CON_RANDVAR_PLAYER } ,
{ CON_SETVAR , CON_SETVAR_PLAYER } ,
{ CON_SHIFTVARL , CON_SHIFTVARL_PLAYER } ,
{ CON_SHIFTVARR , CON_SHIFTVARR_PLAYER } ,
{ CON_SUBVAR , CON_SUBVAR_PLAYER } ,
{ CON_XORVAR , CON_XORVAR_PLAYER } ,
} ;
static const vec2_t actorvartable [ ] =
{
{ CON_IFVARA , CON_IFVARA_ACTOR } ,
{ CON_IFVARAE , CON_IFVARAE_ACTOR } ,
{ CON_IFVARAND , CON_IFVARAND_ACTOR } ,
{ CON_IFVARB , CON_IFVARB_ACTOR } ,
{ CON_IFVARBE , CON_IFVARBE_ACTOR } ,
{ CON_IFVARBOTH , CON_IFVARBOTH_ACTOR } ,
{ CON_IFVARE , CON_IFVARE_ACTOR } ,
{ CON_IFVAREITHER , CON_IFVAREITHER_ACTOR } ,
{ CON_IFVARG , CON_IFVARG_ACTOR } ,
{ CON_IFVARGE , CON_IFVARGE_ACTOR } ,
{ CON_IFVARL , CON_IFVARL_ACTOR } ,
{ CON_IFVARLE , CON_IFVARLE_ACTOR } ,
{ CON_IFVARN , CON_IFVARN_ACTOR } ,
{ CON_IFVAROR , CON_IFVAROR_ACTOR } ,
{ CON_IFVARXOR , CON_IFVARXOR_ACTOR } ,
{ CON_WHILEVARL , CON_WHILEVARL_ACTOR } ,
{ CON_WHILEVARN , CON_WHILEVARN_ACTOR } ,
{ CON_ADDVAR , CON_ADDVAR_ACTOR } ,
{ CON_ANDVAR , CON_ANDVAR_ACTOR } ,
{ CON_DIVVAR , CON_DIVVAR_ACTOR } ,
{ CON_MODVAR , CON_MODVAR_ACTOR } ,
{ CON_MULVAR , CON_MULVAR_ACTOR } ,
{ CON_ORVAR , CON_ORVAR_ACTOR } ,
{ CON_RANDVAR , CON_RANDVAR_ACTOR } ,
{ CON_SETVAR , CON_SETVAR_ACTOR } ,
{ CON_SHIFTVARL , CON_SHIFTVARL_ACTOR } ,
{ CON_SHIFTVARR , CON_SHIFTVARR_ACTOR } ,
{ CON_SUBVAR , CON_SUBVAR_ACTOR } ,
{ CON_XORVAR , CON_XORVAR_ACTOR } ,
2018-12-15 01:38:00 +00:00
} ;
2018-12-15 01:37:13 +00:00
static inthashtable_t h_varvar = { NULL , INTHASH_SIZE ( ARRAY_SIZE ( varvartable ) ) } ;
2018-12-15 01:38:00 +00:00
static inthashtable_t h_globalvar = { NULL , INTHASH_SIZE ( ARRAY_SIZE ( globalvartable ) ) } ;
2018-12-15 01:38:16 +00:00
static inthashtable_t h_playervar = { NULL , INTHASH_SIZE ( ARRAY_SIZE ( playervartable ) ) } ;
static inthashtable_t h_actorvar = { NULL , INTHASH_SIZE ( ARRAY_SIZE ( actorvartable ) ) } ;
2018-12-15 01:38:00 +00:00
static inthashtable_t * const inttables [ ] = {
& h_varvar ,
& h_globalvar ,
2018-12-15 01:38:16 +00:00
& h_playervar ,
& h_actorvar ,
2018-12-15 01:38:00 +00:00
} ;
2018-12-15 01:37:13 +00:00
2018-11-18 18:14:26 +00:00
const tokenmap_t iter_tokens [ ] =
{
2018-12-15 01:37:39 +00:00
{ " allsprites " , ITER_ALLSPRITES } ,
{ " allspritesbystat " , ITER_ALLSPRITESBYSTAT } ,
{ " allspritesbysect " , ITER_ALLSPRITESBYSECT } ,
{ " allsectors " , ITER_ALLSECTORS } ,
{ " allwalls " , ITER_ALLWALLS } ,
{ " activelights " , ITER_ACTIVELIGHTS } ,
{ " drawnsprites " , ITER_DRAWNSPRITES } ,
{ " spritesofsector " , ITER_SPRITESOFSECTOR } ,
{ " spritesofstatus " , ITER_SPRITESOFSTATUS } ,
{ " loopofwall " , ITER_LOOPOFWALL } ,
{ " wallsofsector " , ITER_WALLSOFSECTOR } ,
{ " range " , ITER_RANGE } ,
2018-11-18 18:14:26 +00:00
// vvv alternatives go here vvv
2018-12-15 01:37:39 +00:00
{ " lights " , ITER_ACTIVELIGHTS } ,
{ " sprofsec " , ITER_SPRITESOFSECTOR } ,
{ " sprofstat " , ITER_SPRITESOFSTATUS } ,
{ " walofsec " , ITER_WALLSOFSECTOR } ,
2018-11-18 18:14:26 +00:00
} ;
2017-10-16 03:32:30 +00:00
char const * VM_GetKeywordForID ( int32_t id )
{
// could be better but this is only called for diagnostics, ayy lmao
for ( tokenmap_t const & keyword : vm_keywords )
if ( keyword . val = = id )
return keyword . token ;
2018-12-15 01:38:16 +00:00
return " <unknown> " ;
2017-10-16 03:32:30 +00:00
}
2013-01-01 15:24:18 +00:00
# endif
2007-02-08 04:19:39 +00:00
2012-12-09 13:24:36 +00:00
// KEEPINSYNC with enum GameEvent_t and lunatic/con_lang.lua
const char * EventNames [ MAXEVENTS ] =
2012-02-09 22:44:26 +00:00
{
2012-12-09 13:24:36 +00:00
" EVENT_INIT " ,
" EVENT_ENTERLEVEL " ,
" EVENT_RESETWEAPONS " ,
" EVENT_RESETINVENTORY " ,
" EVENT_HOLSTER " ,
" EVENT_LOOKLEFT " ,
" EVENT_LOOKRIGHT " ,
" EVENT_SOARUP " ,
" EVENT_SOARDOWN " ,
" EVENT_CROUCH " ,
" EVENT_JUMP " ,
" EVENT_RETURNTOCENTER " ,
" EVENT_LOOKUP " ,
" EVENT_LOOKDOWN " ,
" EVENT_AIMUP " ,
" EVENT_FIRE " ,
" EVENT_CHANGEWEAPON " ,
" EVENT_GETSHOTRANGE " ,
" EVENT_GETAUTOAIMANGLE " ,
" EVENT_GETLOADTILE " ,
" EVENT_CHEATGETSTEROIDS " ,
" EVENT_CHEATGETHEAT " ,
" EVENT_CHEATGETBOOT " ,
" EVENT_CHEATGETSHIELD " ,
" EVENT_CHEATGETSCUBA " ,
" EVENT_CHEATGETHOLODUKE " ,
" EVENT_CHEATGETJETPACK " ,
" EVENT_CHEATGETFIRSTAID " ,
" EVENT_QUICKKICK " ,
" EVENT_INVENTORY " ,
" EVENT_USENIGHTVISION " ,
" EVENT_USESTEROIDS " ,
" EVENT_INVENTORYLEFT " ,
" EVENT_INVENTORYRIGHT " ,
" EVENT_HOLODUKEON " ,
" EVENT_HOLODUKEOFF " ,
" EVENT_USEMEDKIT " ,
" EVENT_USEJETPACK " ,
" EVENT_TURNAROUND " ,
" EVENT_DISPLAYWEAPON " ,
" EVENT_FIREWEAPON " ,
" EVENT_SELECTWEAPON " ,
" EVENT_MOVEFORWARD " ,
" EVENT_MOVEBACKWARD " ,
" EVENT_TURNLEFT " ,
" EVENT_TURNRIGHT " ,
" EVENT_STRAFELEFT " ,
" EVENT_STRAFERIGHT " ,
" EVENT_WEAPKEY1 " ,
" EVENT_WEAPKEY2 " ,
" EVENT_WEAPKEY3 " ,
" EVENT_WEAPKEY4 " ,
" EVENT_WEAPKEY5 " ,
" EVENT_WEAPKEY6 " ,
" EVENT_WEAPKEY7 " ,
" EVENT_WEAPKEY8 " ,
" EVENT_WEAPKEY9 " ,
" EVENT_WEAPKEY10 " ,
" EVENT_DRAWWEAPON " ,
" EVENT_DISPLAYCROSSHAIR " ,
" EVENT_DISPLAYREST " ,
" EVENT_DISPLAYSBAR " ,
" EVENT_RESETPLAYER " ,
" EVENT_INCURDAMAGE " ,
" EVENT_AIMDOWN " ,
" EVENT_GAME " ,
" EVENT_PREVIOUSWEAPON " ,
" EVENT_NEXTWEAPON " ,
" EVENT_SWIMUP " ,
" EVENT_SWIMDOWN " ,
" EVENT_GETMENUTILE " ,
" EVENT_SPAWN " ,
" EVENT_LOGO " ,
" EVENT_EGS " ,
" EVENT_DOFIRE " ,
" EVENT_PRESSEDFIRE " ,
" EVENT_USE " ,
" EVENT_PROCESSINPUT " ,
" EVENT_FAKEDOMOVETHINGS " ,
" EVENT_DISPLAYROOMS " ,
" EVENT_KILLIT " ,
" EVENT_LOADACTOR " ,
" EVENT_DISPLAYBONUSSCREEN " ,
" EVENT_DISPLAYMENU " ,
" EVENT_DISPLAYMENUREST " ,
" EVENT_DISPLAYLOADINGSCREEN " ,
" EVENT_ANIMATESPRITES " ,
" EVENT_NEWGAME " ,
" EVENT_SOUND " ,
" EVENT_CHECKTOUCHDAMAGE " ,
" EVENT_CHECKFLOORDAMAGE " ,
" EVENT_LOADGAME " ,
" EVENT_SAVEGAME " ,
" EVENT_PREGAME " ,
2013-07-07 20:59:10 +00:00
" EVENT_CHANGEMENU " ,
2013-12-20 18:31:33 +00:00
" EVENT_DAMAGEHPLANE " ,
2014-06-16 23:16:55 +00:00
" EVENT_ACTIVATECHEAT " ,
2015-01-25 12:16:58 +00:00
" EVENT_DISPLAYINACTIVEMENU " ,
" EVENT_DISPLAYINACTIVEMENUREST " ,
2015-02-11 05:22:07 +00:00
" EVENT_CUTSCENE " ,
2015-02-11 07:08:27 +00:00
" EVENT_DISPLAYCURSOR " ,
2015-03-08 07:57:47 +00:00
" EVENT_DISPLAYLEVELSTATS " ,
2015-03-08 07:58:06 +00:00
" EVENT_DISPLAYCAMERAOSD " ,
2015-03-08 07:58:24 +00:00
" EVENT_DISPLAYROOMSCAMERA " ,
" EVENT_DISPLAYSTART " ,
2015-03-27 12:29:05 +00:00
" EVENT_WORLD " ,
" EVENT_PREWORLD " ,
" EVENT_PRELEVEL " ,
2015-03-30 05:57:30 +00:00
" EVENT_DISPLAYSPIT " ,
" EVENT_DISPLAYFIST " ,
" EVENT_DISPLAYKNEE " ,
" EVENT_DISPLAYKNUCKLES " ,
" EVENT_DISPLAYSCUBA " ,
" EVENT_DISPLAYTIP " ,
" EVENT_DISPLAYACCESS " ,
2016-01-21 19:35:22 +00:00
" EVENT_MOVESECTOR " ,
2016-01-21 19:35:25 +00:00
" EVENT_MOVEEFFECTORS " ,
2017-06-24 09:20:50 +00:00
" EVENT_DISPLAYOVERHEADMAPTEXT " ,
2017-06-24 09:21:07 +00:00
" EVENT_PRELOADGAME " ,
" EVENT_POSTSAVEGAME " ,
2017-11-29 07:29:04 +00:00
" EVENT_PRECUTSCENE " ,
2017-11-29 07:29:07 +00:00
" EVENT_SKIPCUTSCENE " ,
2017-11-29 07:29:11 +00:00
" EVENT_SCREEN " ,
2017-11-29 07:29:23 +00:00
" EVENT_DISPLAYROOMSEND " ,
" EVENT_DISPLAYEND " ,
2017-11-29 07:29:37 +00:00
" EVENT_OPENMENUSOUND " ,
2017-11-29 07:29:40 +00:00
" EVENT_RECOGSOUND " ,
2017-11-29 07:29:44 +00:00
" EVENT_UPDATESCREENAREA " ,
" EVENT_DISPLAYBORDER " ,
2017-12-12 05:13:46 +00:00
" EVENT_SETDEFAULTS " ,
2018-01-26 04:34:38 +00:00
" EVENT_MAINMENUSCREEN " ,
" EVENT_NEWGAMESCREEN " ,
" EVENT_ENDLEVELSCREEN " ,
" EVENT_EXITGAMESCREEN " ,
" EVENT_EXITPROGRAMSCREEN " ,
2018-01-26 04:35:23 +00:00
" EVENT_ALTWEAPON " ,
2018-01-28 04:31:04 +00:00
" EVENT_DISPLAYOVERHEADMAPPLAYER " ,
2018-01-29 02:14:16 +00:00
" EVENT_MENUCURSORLEFT " ,
" EVENT_MENUCURSORRIGHT " ,
" EVENT_MENUCURSORSHADE " ,
" EVENT_MENUSHADESELECTED " ,
2018-01-29 11:14:08 +00:00
" EVENT_PLAYLEVELMUSICSLOT " ,
" EVENT_CONTINUELEVELMUSICSLOT " ,
2018-03-01 13:46:52 +00:00
" EVENT_DISPLAYPOINTER " ,
2018-03-08 03:54:54 +00:00
" EVENT_LASTWEAPON " ,
2018-03-17 03:26:10 +00:00
" EVENT_DAMAGESPRITE " ,
" EVENT_POSTDAMAGESPRITE " ,
" EVENT_DAMAGEWALL " ,
" EVENT_DAMAGEFLOOR " ,
" EVENT_DAMAGECEILING " ,
2019-01-22 17:56:34 +00:00
" EVENT_DISPLAYROOMSCAMERATILE " ,
2013-07-07 20:59:10 +00:00
# ifdef LUNATIC
" EVENT_ANIMATEALLSPRITES " ,
# endif
2012-02-09 22:44:26 +00:00
} ;
2008-09-12 02:07:44 +00:00
char * bitptr ; // pointer to bitmap of which bytecode positions contain pointers
2018-11-18 18:14:20 +00:00
2016-01-11 05:05:05 +00:00
# define BITPTR_SET(x) (bitptr[(x)>>3] |= (1<<((x)&7)))
# define BITPTR_CLEAR(x) (bitptr[(x)>>3] &= ~(1<<((x)&7)))
# define BITPTR_IS_POINTER(x) (bitptr[(x)>>3] & (1<<((x) &7)))
2008-08-16 10:54:10 +00:00
2013-01-20 21:17:06 +00:00
# if !defined LUNATIC
2018-11-18 18:14:43 +00:00
hashtable_t h_arrays = { MAXGAMEARRAYS > > 1 , NULL } ;
hashtable_t h_gamevars = { MAXGAMEVARS > > 1 , NULL } ;
hashtable_t h_labels = { 11264 > > 1 , NULL } ;
2013-01-01 15:24:18 +00:00
2009-05-22 23:49:25 +00:00
// "magic" number for { and }, overrides line number in compiled code for later detection
2009-01-05 14:43:12 +00:00
# define IFELSE_MAGIC 31337
2009-01-04 22:22:33 +00:00
2018-11-18 18:10:21 +00:00
static void C_SetScriptSize ( int32_t newsize )
2008-07-20 03:29:00 +00:00
{
2018-11-18 18:14:38 +00:00
for ( int i = 0 ; i < g_scriptSize - 1 ; + + i )
2008-07-20 03:29:00 +00:00
{
2016-01-11 05:05:05 +00:00
if ( BITPTR_IS_POINTER ( i ) )
2008-07-20 03:29:00 +00:00
{
2018-11-18 18:14:38 +00:00
if ( EDUKE32_PREDICT_FALSE ( apScript [ i ] < ( intptr_t ) apScript | | apScript [ i ] > = ( intptr_t ) g_scriptPtr ) )
2011-03-04 08:50:58 +00:00
{
2016-08-27 01:42:01 +00:00
g_errorCnt + + ;
2017-06-05 10:05:12 +00:00
buildprint ( " Internal compiler error at " , i , " (0x " , hex ( i ) , " ) \n " ) ;
2016-08-27 01:40:35 +00:00
VM_ScriptInfo ( & apScript [ i ] , 16 ) ;
2011-03-04 08:50:58 +00:00
}
2018-11-18 18:10:21 +00:00
else
2018-12-15 01:36:27 +00:00
apScript [ i ] - = ( intptr_t ) apScript ;
2008-07-20 03:29:00 +00:00
}
}
2016-08-27 01:40:35 +00:00
G_Util_PtrToIdx2 ( & g_tile [ 0 ] . execPtr , MAXTILES , sizeof ( tiledata_t ) , apScript , P2I_FWD_NON0 ) ;
G_Util_PtrToIdx2 ( & g_tile [ 0 ] . loadPtr , MAXTILES , sizeof ( tiledata_t ) , apScript , P2I_FWD_NON0 ) ;
2008-07-20 03:29:00 +00:00
2018-11-18 18:10:21 +00:00
auto newscript = ( intptr_t * ) Xrealloc ( apScript , newsize * sizeof ( intptr_t ) ) ;
2018-11-18 18:14:38 +00:00
bitptr = ( char * ) Xrealloc ( bitptr , ( ( ( newsize + 7 ) > > 3 ) + 1 ) * sizeof ( uint8_t ) ) ;
2008-08-25 10:27:18 +00:00
2018-11-18 18:14:38 +00:00
if ( newsize > g_scriptSize )
Bmemset ( & newscript [ g_scriptSize ] , 0 , ( newsize - g_scriptSize ) * sizeof ( intptr_t ) ) ;
2018-11-18 18:10:21 +00:00
2016-08-27 01:40:35 +00:00
if ( apScript ! = newscript )
2009-05-22 23:49:25 +00:00
{
2018-11-18 18:14:38 +00:00
buildprint ( " Relocated compiled code from 0x " , hex ( ( intptr_t ) apScript ) , " to 0x " , hex ( ( intptr_t ) newscript ) , " \n " ) ;
g_scriptPtr = g_scriptPtr - apScript + newscript ;
apScript = newscript ;
2009-05-22 23:49:25 +00:00
}
2018-11-18 18:14:38 +00:00
int const smallestSize = min ( g_scriptSize , newsize ) ;
2018-11-18 18:10:21 +00:00
2018-11-18 18:14:38 +00:00
for ( int i = 0 ; i < smallestSize - 1 ; + + i )
2018-11-18 18:10:21 +00:00
{
if ( BITPTR_IS_POINTER ( i ) )
2018-12-15 01:36:27 +00:00
apScript [ i ] + = ( intptr_t ) apScript ;
2018-11-18 18:10:21 +00:00
}
2008-07-20 03:29:00 +00:00
2018-11-18 18:14:38 +00:00
g_scriptSize = newsize ;
2016-08-27 01:40:35 +00:00
G_Util_PtrToIdx2 ( & g_tile [ 0 ] . execPtr , MAXTILES , sizeof ( tiledata_t ) , apScript , P2I_BACK_NON0 ) ;
G_Util_PtrToIdx2 ( & g_tile [ 0 ] . loadPtr , MAXTILES , sizeof ( tiledata_t ) , apScript , P2I_BACK_NON0 ) ;
2008-07-20 03:29:00 +00:00
}
2018-11-18 18:10:21 +00:00
static inline bool ispecial ( const char c )
2010-01-23 22:12:02 +00:00
{
2016-01-21 19:35:16 +00:00
return ( c = = ' ' | | c = = 0x0d | | c = = ' ( ' | | c = = ' ) ' | |
c = = ' , ' | | c = = ' ; ' | | ( c = = 0x0a /*&& ++g_lineNumber*/ ) ) ;
2010-01-23 22:12:02 +00:00
}
2009-11-20 03:54:40 +00:00
2018-11-18 18:14:43 +00:00
static inline void scriptSkipLine ( void )
2015-03-25 06:28:09 +00:00
{
while ( * textptr ! = 0x0a & & * textptr ! = 0x0d & & * textptr ! = 0 )
textptr + + ;
}
2018-11-18 18:14:43 +00:00
static inline void scriptSkipSpaces ( void )
2015-03-25 06:28:09 +00:00
{
while ( * textptr = = ' ' | | * textptr = = ' \t ' )
textptr + + ;
}
2009-11-20 03:54:40 +00:00
2018-11-18 18:10:21 +00:00
static void C_SkipComments ( void )
2006-04-13 20:47:06 +00:00
{
2008-08-28 11:35:35 +00:00
do
2006-04-13 20:47:06 +00:00
{
2009-11-18 01:17:56 +00:00
switch ( * textptr )
2006-11-15 01:16:55 +00:00
{
2009-11-18 01:17:56 +00:00
case ' \n ' :
2008-11-20 14:06:36 +00:00
g_lineNumber + + ;
2017-07-18 20:53:41 +00:00
fallthrough__ ;
2009-11-18 01:17:56 +00:00
case ' ' :
case ' \t ' :
case ' \r ' :
2010-07-03 08:53:57 +00:00
case 0x1a :
2006-04-13 20:47:06 +00:00
textptr + + ;
2009-11-18 01:17:56 +00:00
break ;
case ' / ' :
switch ( textptr [ 1 ] )
2006-04-13 20:47:06 +00:00
{
2009-11-18 01:17:56 +00:00
case ' / ' : // C++ style comment
2018-12-15 01:38:05 +00:00
if ( g_scriptDebug > 1 & & ! g_errorCnt & & ! g_warningCnt )
2016-08-27 01:42:01 +00:00
initprintf ( " %s:%d: debug: got comment. \n " , g_scriptFileName , g_lineNumber ) ;
2018-11-18 18:14:43 +00:00
scriptSkipLine ( ) ;
2010-07-03 08:53:57 +00:00
continue ;
2009-11-18 01:17:56 +00:00
case ' * ' : // beginning of a C style comment
2018-12-15 01:38:05 +00:00
if ( g_scriptDebug > 1 & & ! g_errorCnt & & ! g_warningCnt )
2016-08-27 01:42:01 +00:00
initprintf ( " %s:%d: debug: got start of comment block. \n " , g_scriptFileName , g_lineNumber ) ;
2009-11-18 01:17:56 +00:00
do
{
if ( * textptr = = ' \n ' )
g_lineNumber + + ;
textptr + + ;
}
while ( * textptr & & ( textptr [ 0 ] ! = ' * ' | | textptr [ 1 ] ! = ' / ' ) ) ;
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_FALSE ( ! * textptr ) )
2009-11-18 01:17:56 +00:00
{
2016-08-27 01:42:01 +00:00
if ( ! ( g_errorCnt | | g_warningCnt ) & & g_scriptDebug )
initprintf ( " %s:%d: debug: EOF in comment! \n " , g_scriptFileName , g_lineNumber ) ;
2009-11-18 01:17:56 +00:00
C_ReportError ( - 1 ) ;
2016-08-27 01:42:01 +00:00
initprintf ( " %s:%d: error: found `/*' with no `*/'. \n " , g_scriptFileName , g_lineNumber ) ;
2018-12-15 01:36:42 +00:00
g_scriptActorOffset = g_numBraces = g_processingState = 0 ;
2016-08-27 01:42:01 +00:00
g_errorCnt + + ;
2010-07-03 08:53:57 +00:00
continue ;
2009-11-18 01:17:56 +00:00
}
2018-12-15 01:38:05 +00:00
if ( g_scriptDebug > 1 & & ! g_errorCnt & & ! g_warningCnt )
2016-08-27 01:42:01 +00:00
initprintf ( " %s:%d: debug: got end of comment block. \n " , g_scriptFileName , g_lineNumber ) ;
2009-11-18 01:17:56 +00:00
textptr + = 2 ;
2010-07-03 08:53:57 +00:00
continue ;
2016-01-21 19:35:03 +00:00
default :
C_ReportError ( - 1 ) ;
2016-08-27 01:42:01 +00:00
initprintf ( " %s:%d: error: malformed comment. \n " , g_scriptFileName , g_lineNumber ) ;
2018-11-18 18:14:43 +00:00
scriptSkipLine ( ) ;
2016-08-27 01:42:01 +00:00
g_errorCnt + + ;
2016-01-21 19:35:03 +00:00
continue ;
2006-04-13 20:47:06 +00:00
}
2016-12-26 06:02:06 +00:00
break ;
2009-11-18 01:17:56 +00:00
default :
2009-11-20 03:54:40 +00:00
if ( ispecial ( * textptr ) )
{
textptr + + ;
2010-07-03 08:53:57 +00:00
continue ;
2009-11-20 03:54:40 +00:00
}
2017-07-18 20:53:41 +00:00
fallthrough__ ;
2009-11-20 03:54:40 +00:00
case 0 : // EOF
2018-11-18 18:10:21 +00:00
return ;
2006-04-13 20:47:06 +00:00
}
2008-09-01 21:59:53 +00:00
}
2009-11-18 01:17:56 +00:00
while ( 1 ) ;
2006-04-13 20:47:06 +00:00
}
2018-11-18 18:14:26 +00:00
static inline int GetDefID ( char const * label ) { return hash_find ( & h_gamevars , label ) ; }
static inline int GetADefID ( char const * label ) { return hash_find ( & h_arrays , label ) ; }
2018-11-18 18:11:09 +00:00
# define LAST_LABEL (label+(g_labelCnt<<6))
2018-11-18 18:10:21 +00:00
static inline bool isaltok ( const char c )
2006-04-13 20:47:06 +00:00
{
2016-01-21 19:35:16 +00:00
return ( isalnum ( c ) | | c = = ' { ' | | c = = ' } ' | | c = = ' / ' | | c = = ' \\ ' | | c = = ' * ' | | c = = ' - ' | | c = = ' _ ' | |
c = = ' . ' ) ;
2006-04-13 20:47:06 +00:00
}
2018-11-18 18:10:21 +00:00
static inline bool C_IsLabelChar ( const char c , int32_t const i )
2014-05-18 09:55:41 +00:00
{
2018-11-18 18:14:54 +00:00
return ( isalnum ( c ) | | c = = ' _ ' | | c = = ' * ' | | c = = ' ? ' | | ( i > 0 & & ( c = = ' + ' | | c = = ' - ' ) ) ) ;
2014-05-18 09:55:41 +00:00
}
2016-01-21 19:35:16 +00:00
static inline int32_t C_GetLabelNameID ( const memberlabel_t * pLabel , hashtable_t const * const table , const char * psz )
2006-04-13 20:47:06 +00:00
{
// find the label psz in the table pLabel.
// returns the ID for the label, or -1
2018-11-18 18:10:21 +00:00
int const l = hash_findcase ( table , psz ) ;
2011-04-07 01:16:29 +00:00
return ( l > = 0 ) ? pLabel [ l ] . lId : - 1 ;
2006-04-13 20:47:06 +00:00
}
2016-01-21 19:35:16 +00:00
static inline int32_t C_GetLabelNameOffset ( hashtable_t const * const table , const char * psz )
2006-04-13 20:47:06 +00:00
{
// find the label psz in the table pLabel.
// returns the offset in the array for the label, or -1
2016-01-21 19:35:16 +00:00
return hash_findcase ( table , psz ) ;
2006-04-13 20:47:06 +00:00
}
2008-11-20 14:06:36 +00:00
static void C_GetNextLabelName ( void )
2006-04-13 20:47:06 +00:00
{
2011-04-07 01:16:29 +00:00
int32_t i = 0 ;
2006-04-13 20:47:06 +00:00
2008-11-20 14:06:36 +00:00
C_SkipComments ( ) ;
2006-04-13 20:47:06 +00:00
2014-05-18 09:55:41 +00:00
// while (ispecial(*textptr) == 0 && *textptr!='['&& *textptr!=']' && *textptr!='\t' && *textptr!='\n' && *textptr!='\r')
while ( C_IsLabelChar ( * textptr , i ) )
2018-12-15 01:36:32 +00:00
{
if ( i < ( 1 < < 6 ) - 1 )
label [ ( g_labelCnt < < 6 ) + ( i + + ) ] = * textptr ;
textptr + + ;
}
2016-01-21 19:35:16 +00:00
2016-08-27 01:42:01 +00:00
label [ ( g_labelCnt < < 6 ) + i ] = 0 ;
2011-04-07 01:16:29 +00:00
2016-08-27 01:42:01 +00:00
if ( ! ( g_errorCnt | g_warningCnt ) & & g_scriptDebug > 1 )
2018-11-18 18:11:09 +00:00
initprintf ( " %s:%d: debug: label `%s'. \n " , g_scriptFileName , g_lineNumber , LAST_LABEL ) ;
2006-04-13 20:47:06 +00:00
}
2018-11-18 18:14:20 +00:00
static inline void scriptWriteValue ( int32_t const value )
{
BITPTR_CLEAR ( g_scriptPtr - apScript ) ;
* g_scriptPtr + + = value ;
}
// addresses passed to these functions must be within the block of memory pointed to by apScript
static inline void scriptWriteAtOffset ( int32_t const value , intptr_t * const addr )
{
BITPTR_CLEAR ( addr - apScript ) ;
* ( addr ) = value ;
}
static inline void scriptWritePointer ( intptr_t const value , intptr_t * const addr )
{
BITPTR_SET ( addr - apScript ) ;
* ( addr ) = value ;
}
2018-05-23 05:58:17 +00:00
static int32_t C_GetNextGameArrayName ( void )
{
C_GetNextLabelName ( ) ;
2018-11-18 18:11:09 +00:00
int32_t const i = GetADefID ( LAST_LABEL ) ;
2018-05-23 05:58:17 +00:00
if ( EDUKE32_PREDICT_FALSE ( i < 0 ) )
{
g_errorCnt + + ;
C_ReportError ( ERROR_NOTAGAMEARRAY ) ;
return - 1 ;
}
2018-11-18 18:14:20 +00:00
scriptWriteValue ( i ) ;
2018-05-23 05:58:17 +00:00
return i ;
}
2018-11-18 18:14:43 +00:00
static int C_GetKeyword ( void )
2006-04-13 20:47:06 +00:00
{
2008-11-20 14:06:36 +00:00
C_SkipComments ( ) ;
2006-04-13 20:47:06 +00:00
2018-11-18 18:14:43 +00:00
char * temptextptr = textptr ;
2006-04-13 20:47:06 +00:00
2011-04-07 01:16:29 +00:00
if ( * temptextptr = = 0 ) // EOF
return - 2 ;
2006-11-14 21:35:50 +00:00
while ( isaltok ( * temptextptr ) = = 0 )
2006-04-13 20:47:06 +00:00
{
temptextptr + + ;
2006-11-14 21:35:50 +00:00
if ( * temptextptr = = 0 )
2006-04-13 20:47:06 +00:00
return 0 ;
}
2018-11-18 18:14:43 +00:00
int i = 0 ;
2006-11-14 21:35:50 +00:00
while ( isaltok ( * temptextptr ) )
2008-08-26 08:39:45 +00:00
tempbuf [ i + + ] = * ( temptextptr + + ) ;
2006-04-13 20:47:06 +00:00
tempbuf [ i ] = 0 ;
2011-04-07 01:16:29 +00:00
2010-05-02 23:27:30 +00:00
return hash_find ( & h_keywords , tempbuf ) ;
2006-04-13 20:47:06 +00:00
}
2018-11-18 18:14:43 +00:00
static int C_GetNextKeyword ( void ) //Returns its code #
2006-04-13 20:47:06 +00:00
{
2008-11-20 14:06:36 +00:00
C_SkipComments ( ) ;
2006-04-13 20:47:06 +00:00
2009-11-18 01:17:56 +00:00
if ( * textptr = = 0 ) // EOF
2011-04-07 01:16:29 +00:00
return - 2 ;
2006-04-13 20:47:06 +00:00
2018-11-18 18:14:43 +00:00
int l = 0 ;
2006-11-14 21:35:50 +00:00
while ( isaltok ( * ( textptr + l ) ) )
2006-04-13 20:47:06 +00:00
{
tempbuf [ l ] = textptr [ l ] ;
l + + ;
}
tempbuf [ l ] = 0 ;
2018-11-18 18:14:43 +00:00
int i ;
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_TRUE ( ( i = hash_find ( & h_keywords , tempbuf ) ) > = 0 ) )
2006-04-13 20:47:06 +00:00
{
2009-01-04 22:22:33 +00:00
if ( i = = CON_LEFTBRACE | | i = = CON_RIGHTBRACE | | i = = CON_NULLOP )
2018-12-15 01:36:42 +00:00
scriptWriteValue ( i | ( IFELSE_MAGIC < < 12 ) ) ;
2018-12-15 01:36:48 +00:00
else scriptWriteValue ( i | LINE_NUMBER ) ;
2009-05-28 02:55:46 +00:00
2008-08-25 00:49:12 +00:00
textptr + = l ;
2016-08-27 01:42:01 +00:00
if ( ! ( g_errorCnt | | g_warningCnt ) & & g_scriptDebug )
2017-10-16 03:32:34 +00:00
initprintf ( " %s:%d: debug: keyword `%s'. \n " , g_scriptFileName , g_lineNumber , tempbuf ) ;
2008-08-25 00:49:12 +00:00
return i ;
2006-04-13 20:47:06 +00:00
}
textptr + = l ;
2016-08-27 01:42:01 +00:00
g_errorCnt + + ;
2006-04-13 20:47:06 +00:00
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_FALSE ( ( tempbuf [ 0 ] = = ' { ' | | tempbuf [ 0 ] = = ' } ' ) & & tempbuf [ 1 ] ! = 0 ) )
2006-04-13 20:47:06 +00:00
{
2008-11-20 14:06:36 +00:00
C_ReportError ( - 1 ) ;
2016-08-27 01:42:01 +00:00
initprintf ( " %s:%d: error: expected whitespace between `%c' and `%s'. \n " , g_scriptFileName , g_lineNumber , tempbuf [ 0 ] , tempbuf + 1 ) ;
2006-04-13 20:47:06 +00:00
}
2008-11-20 14:06:36 +00:00
else C_ReportError ( ERROR_EXPECTEDKEYWORD ) ;
2011-04-07 01:16:29 +00:00
2006-04-13 20:47:06 +00:00
return - 1 ;
}
2012-02-29 15:27:40 +00:00
static int32_t parse_decimal_number ( void ) // (textptr)
{
// decimal constants -- this is finicky business
int64_t num = strtoll ( textptr , NULL , 10 ) ; // assume long long to be int64_t
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_TRUE ( num > = INT32_MIN & & num < = INT32_MAX ) )
2012-02-29 15:27:40 +00:00
{
// all OK
}
2014-10-25 03:36:34 +00:00
else if ( EDUKE32_PREDICT_FALSE ( num > INT32_MAX & & num < = UINT32_MAX ) )
2012-02-29 15:27:40 +00:00
{
// Number interpreted as uint32, but packed as int32 (on 32-bit archs)
// (CON code in the wild exists that does this). Note that such conversion
// is implementation-defined (C99 6.3.1.3) but GCC does the 'expected' thing.
2012-06-06 22:03:35 +00:00
#if 0
2012-02-29 15:27:40 +00:00
initprintf ( " %s:%d: warning: number greater than INT32_MAX converted to a negative one. \n " ,
g_szScriptFileName , g_lineNumber ) ;
g_numCompilerWarnings + + ;
2012-06-06 22:03:35 +00:00
# endif
2012-02-29 15:27:40 +00:00
}
else
{
// out of range, this is arguably worse
initprintf ( " %s:%d: warning: number out of the range of a 32-bit integer encountered. \n " ,
2016-08-27 01:42:01 +00:00
g_scriptFileName , g_lineNumber ) ;
g_warningCnt + + ;
2012-02-29 15:27:40 +00:00
}
return ( int32_t ) num ;
}
2012-06-10 18:56:27 +00:00
static int32_t parse_hex_constant ( const char * hexnum )
{
2018-10-25 23:29:20 +00:00
uint64_t x ;
2012-06-10 18:56:27 +00:00
sscanf ( hexnum , " % " PRIx64 " " , & x ) ;
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_FALSE ( x > UINT32_MAX ) )
2012-06-10 18:56:27 +00:00
{
2017-06-05 10:05:12 +00:00
initprintf ( g_scriptFileName , " : " , g_lineNumber , " : warning: number 0x " , hex ( x ) , " truncated to 32 bits. \n " ) ;
2016-08-27 01:42:01 +00:00
g_warningCnt + + ;
2012-06-10 18:56:27 +00:00
}
return x ;
}
2009-01-09 09:29:17 +00:00
static void C_GetNextVarType ( int32_t type )
2006-04-13 20:47:06 +00:00
{
2018-11-18 18:10:57 +00:00
int32_t id = 0 ;
int32_t flags = 0 ;
auto varptr = g_scriptPtr ;
2006-04-13 20:47:06 +00:00
2008-11-20 14:06:36 +00:00
C_SkipComments ( ) ;
2010-03-03 01:37:27 +00:00
2008-11-20 14:06:36 +00:00
if ( ! type & & ! g_labelsOnly & & ( isdigit ( * textptr ) | | ( ( * textptr = = ' - ' ) & & ( isdigit ( * ( textptr + 1 ) ) ) ) ) )
2006-04-13 20:47:06 +00:00
{
2018-11-18 18:14:20 +00:00
scriptWriteValue ( GV_FLAG_CONSTANT ) ;
2012-02-29 15:27:40 +00:00
if ( tolower ( textptr [ 1 ] ) = = ' x ' ) // hex constants
2018-11-18 18:14:20 +00:00
scriptWriteValue ( parse_hex_constant ( textptr + 2 ) ) ;
2008-02-18 08:10:54 +00:00
else
2018-11-18 18:14:20 +00:00
scriptWriteValue ( parse_decimal_number ( ) ) ;
2012-02-29 15:27:40 +00:00
2016-08-27 01:42:01 +00:00
if ( ! ( g_errorCnt | | g_warningCnt ) & & g_scriptDebug )
2018-12-15 01:36:42 +00:00
initprintf ( " %s:%d: debug: constant %ld in place of gamevar. \n " , g_scriptFileName , g_lineNumber , ( long ) ( g_scriptPtr [ - 1 ] ) ) ;
2009-01-16 06:11:25 +00:00
# if 1
while ( ! ispecial ( * textptr ) & & * textptr ! = ' ] ' ) textptr + + ;
# else
2008-11-20 14:06:36 +00:00
C_GetNextLabelName ( ) ;
2009-01-16 06:11:25 +00:00
# endif
2006-04-13 20:47:06 +00:00
return ;
}
2016-05-04 08:26:08 +00:00
else if ( * textptr = = ' - ' /* && !isdigit(*(textptr+1))*/ )
2006-04-13 20:47:06 +00:00
{
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_FALSE ( type ) )
2006-04-13 20:47:06 +00:00
{
2016-08-27 01:42:01 +00:00
g_errorCnt + + ;
2008-11-20 14:06:36 +00:00
C_ReportError ( ERROR_SYNTAXERROR ) ;
C_GetNextLabelName ( ) ;
2006-04-13 20:47:06 +00:00
return ;
}
2010-03-03 01:37:27 +00:00
2016-08-27 01:42:01 +00:00
if ( ! ( g_errorCnt | | g_warningCnt ) & & g_scriptDebug )
initprintf ( " %s:%d: debug: flagging gamevar as negative. \n " , g_scriptFileName , g_lineNumber ) ; //,Batol(textptr));
2014-10-25 03:36:34 +00:00
2018-11-18 18:10:57 +00:00
flags = GV_FLAG_NEGATIVE ;
2010-03-03 01:37:27 +00:00
textptr + + ;
2006-04-13 20:47:06 +00:00
}
2012-02-29 15:27:40 +00:00
2008-11-20 14:06:36 +00:00
C_GetNextLabelName ( ) ;
2008-04-01 02:50:44 +00:00
2018-11-18 18:11:09 +00:00
if ( EDUKE32_PREDICT_FALSE ( hash_find ( & h_keywords , LAST_LABEL ) > = 0 ) )
2008-08-25 00:49:12 +00:00
{
2016-08-27 01:42:01 +00:00
g_errorCnt + + ;
2008-11-20 14:06:36 +00:00
C_ReportError ( ERROR_ISAKEYWORD ) ;
2008-08-25 00:49:12 +00:00
return ;
}
2008-04-01 02:50:44 +00:00
2018-11-18 18:10:57 +00:00
C_SkipComments ( ) ;
2018-11-18 18:14:54 +00:00
if ( * textptr = = ' [ ' | | * textptr = = ' . ' ) //read of array as a gamevar
2008-04-01 02:50:44 +00:00
{
2018-11-18 18:10:57 +00:00
flags | = GV_FLAG_ARRAY ;
2018-11-18 18:14:54 +00:00
if ( * textptr ! = ' . ' ) textptr + + ;
2018-11-18 18:11:09 +00:00
id = GetADefID ( LAST_LABEL ) ;
2018-11-18 18:10:57 +00:00
if ( id < 0 )
2008-04-01 02:50:44 +00:00
{
2018-11-18 18:11:09 +00:00
id = GetDefID ( LAST_LABEL ) ;
2018-11-18 18:10:57 +00:00
if ( ( unsigned ) ( id - g_structVarIDs ) > = NUMQUICKSTRUCTS )
id = - 1 ;
2009-01-07 14:05:13 +00:00
2018-11-18 18:10:57 +00:00
if ( EDUKE32_PREDICT_FALSE ( id < 0 ) )
2009-01-07 14:05:13 +00:00
{
2016-08-27 01:42:01 +00:00
g_errorCnt + + ;
2009-01-07 14:05:13 +00:00
C_ReportError ( ERROR_NOTAGAMEARRAY ) ;
return ;
}
2018-11-18 18:10:57 +00:00
flags & = ~ GV_FLAG_ARRAY ; // not an array
flags | = GV_FLAG_STRUCT ;
2008-04-01 02:50:44 +00:00
}
2018-11-18 18:14:20 +00:00
scriptWriteValue ( id | flags ) ;
2015-03-25 06:27:57 +00:00
2018-11-18 18:10:57 +00:00
if ( ( flags & GV_FLAG_STRUCT ) & & id - g_structVarIDs = = STRUCT_USERDEF )
2015-03-25 06:27:57 +00:00
{
// userdef doesn't really have an array index
2018-11-18 18:14:54 +00:00
while ( * textptr ! = ' . ' )
2015-03-25 06:27:57 +00:00
{
2018-11-18 18:10:57 +00:00
if ( * textptr = = 0xa | | * textptr = = 0 )
2015-03-25 06:27:57 +00:00
break ;
textptr + + ;
}
2015-09-24 06:31:52 +00:00
2018-11-18 18:14:20 +00:00
scriptWriteValue ( 0 ) ; // help out the VM by inserting a dummy index
2015-03-25 06:27:57 +00:00
}
else
{
2018-12-15 01:36:37 +00:00
// allow "[]" or "." but not "[."
if ( * textptr = = ' ] ' | | ( * textptr = = ' . ' & & textptr [ - 1 ] ! = ' [ ' ) )
2016-01-07 03:29:59 +00:00
{
2018-11-18 18:14:20 +00:00
scriptWriteValue ( g_thisActorVarID ) ;
2016-01-07 03:29:59 +00:00
}
2016-01-03 20:07:11 +00:00
else
C_GetNextVarType ( 0 ) ;
2015-03-25 06:27:57 +00:00
C_SkipComments ( ) ;
}
2008-04-27 06:54:28 +00:00
2018-11-18 18:14:54 +00:00
if ( EDUKE32_PREDICT_FALSE ( * textptr ! = ' ] ' & & * textptr ! = ' . ' ) )
2008-04-01 02:50:44 +00:00
{
2016-08-27 01:42:01 +00:00
g_errorCnt + + ;
2008-11-20 14:06:36 +00:00
C_ReportError ( ERROR_GAMEARRAYBNC ) ;
2008-04-01 02:50:44 +00:00
return ;
}
2018-11-18 18:14:54 +00:00
if ( * textptr ! = ' . ' ) textptr + + ;
2009-01-16 06:11:25 +00:00
//writing arrays in this way is not supported because it would require too many changes to other code
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_FALSE ( type ) )
2008-04-01 02:50:44 +00:00
{
2016-08-27 01:42:01 +00:00
g_errorCnt + + ;
2008-11-20 14:06:36 +00:00
C_ReportError ( ERROR_INVALIDARRAYWRITE ) ;
2008-04-01 02:50:44 +00:00
return ;
}
2009-01-07 14:05:13 +00:00
2018-11-18 18:10:57 +00:00
if ( flags & GV_FLAG_STRUCT )
2009-01-07 14:05:13 +00:00
{
while ( * textptr ! = ' . ' )
{
2018-12-15 01:36:42 +00:00
if ( * textptr = = 0xa | | ! * textptr )
2009-01-07 14:05:13 +00:00
break ;
textptr + + ;
}
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_FALSE ( * textptr ! = ' . ' ) )
2009-01-07 14:05:13 +00:00
{
2016-08-27 01:42:01 +00:00
g_errorCnt + + ;
2009-01-07 14:05:13 +00:00
C_ReportError ( ERROR_SYNTAXERROR ) ;
return ;
}
textptr + + ;
/// now pointing at 'xxx'
C_GetNextLabelName ( ) ;
2012-03-26 05:05:57 +00:00
/*initprintf("found xxx label of \"%s\"\n", label+(g_numLabels<<6));*/
2009-01-07 14:05:13 +00:00
2018-10-07 05:22:55 +00:00
int32_t labelNum = - 1 ;
2018-11-18 18:10:57 +00:00
switch ( id - g_structVarIDs )
2015-03-25 06:27:42 +00:00
{
2018-11-18 18:14:05 +00:00
case STRUCT_SPRITE : labelNum = C_GetLabelNameOffset ( & h_actor , Bstrtolower ( LAST_LABEL ) ) ; break ;
case STRUCT_SECTOR : labelNum = C_GetLabelNameOffset ( & h_sector , Bstrtolower ( LAST_LABEL ) ) ; break ;
case STRUCT_WALL : labelNum = C_GetLabelNameOffset ( & h_wall , Bstrtolower ( LAST_LABEL ) ) ; break ;
case STRUCT_PLAYER : labelNum = C_GetLabelNameOffset ( & h_player , Bstrtolower ( LAST_LABEL ) ) ; break ;
case STRUCT_TSPR : labelNum = C_GetLabelNameOffset ( & h_tsprite , Bstrtolower ( LAST_LABEL ) ) ; break ;
case STRUCT_PROJECTILE :
case STRUCT_THISPROJECTILE : labelNum = C_GetLabelNameOffset ( & h_projectile , Bstrtolower ( LAST_LABEL ) ) ; break ;
case STRUCT_USERDEF : labelNum = C_GetLabelNameOffset ( & h_userdef , Bstrtolower ( LAST_LABEL ) ) ; break ;
case STRUCT_INPUT : labelNum = C_GetLabelNameOffset ( & h_input , Bstrtolower ( LAST_LABEL ) ) ; break ;
case STRUCT_TILEDATA : labelNum = C_GetLabelNameOffset ( & h_tiledata , Bstrtolower ( LAST_LABEL ) ) ; break ;
case STRUCT_PALDATA : labelNum = C_GetLabelNameOffset ( & h_paldata , Bstrtolower ( LAST_LABEL ) ) ; break ;
case STRUCT_ACTORVAR :
case STRUCT_PLAYERVAR : labelNum = GetDefID ( LAST_LABEL ) ; break ;
2019-01-30 09:36:52 +00:00
}
2018-11-18 18:14:05 +00:00
2019-01-30 09:36:52 +00:00
if ( labelNum = = - 1 )
{
g_errorCnt + + ;
C_ReportError ( ERROR_NOTAMEMBER ) ;
return ;
2009-01-07 14:05:13 +00:00
}
2018-11-18 18:10:57 +00:00
switch ( id - g_structVarIDs )
2009-01-07 14:05:13 +00:00
{
2015-03-25 06:27:42 +00:00
case STRUCT_SPRITE :
2018-11-18 18:11:04 +00:00
{
auto const & label = ActorLabels [ labelNum ] ;
2018-11-18 18:14:20 +00:00
scriptWriteValue ( label . lId ) ;
2018-11-18 18:11:04 +00:00
Bassert ( ( * varptr & ( MAXGAMEVARS - 1 ) ) = = g_structVarIDs + STRUCT_SPRITE ) ;
if ( label . flags & LABEL_HASPARM2 )
C_GetNextVarType ( 0 ) ;
else if ( label . offset ! = - 1 & & ( label . flags & LABEL_READFUNC ) = = 0 )
{
if ( labelNum > = ACTOR_SPRITEEXT_BEGIN )
* varptr = ( * varptr & ~ ( MAXGAMEVARS - 1 ) ) + g_structVarIDs + STRUCT_SPRITEEXT_INTERNAL__ ;
else if ( labelNum > = ACTOR_STRUCT_BEGIN )
* varptr = ( * varptr & ~ ( MAXGAMEVARS - 1 ) ) + g_structVarIDs + STRUCT_ACTOR_INTERNAL__ ;
else
* varptr = ( * varptr & ~ ( MAXGAMEVARS - 1 ) ) + g_structVarIDs + STRUCT_SPRITE_INTERNAL__ ;
}
}
2009-01-07 14:05:13 +00:00
2015-03-25 06:27:42 +00:00
break ;
case STRUCT_SECTOR :
2018-11-18 18:14:20 +00:00
scriptWriteValue ( SectorLabels [ labelNum ] . lId ) ;
2015-03-25 06:27:42 +00:00
break ;
case STRUCT_WALL :
2018-11-18 18:14:20 +00:00
scriptWriteValue ( WallLabels [ labelNum ] . lId ) ;
2015-03-25 06:27:42 +00:00
break ;
case STRUCT_PLAYER :
2018-11-18 18:14:20 +00:00
scriptWriteValue ( PlayerLabels [ labelNum ] . lId ) ;
2009-01-07 14:05:13 +00:00
2016-08-27 01:40:35 +00:00
if ( PlayerLabels [ labelNum ] . flags & LABEL_HASPARM2 )
2009-01-07 14:05:13 +00:00
C_GetNextVarType ( 0 ) ;
2015-03-25 06:27:42 +00:00
break ;
case STRUCT_ACTORVAR :
2015-03-25 06:27:57 +00:00
case STRUCT_PLAYERVAR :
2018-11-18 18:14:20 +00:00
scriptWriteValue ( labelNum ) ;
2015-03-25 06:27:42 +00:00
break ;
2015-03-25 06:27:57 +00:00
case STRUCT_TSPR :
2018-11-18 18:14:20 +00:00
scriptWriteValue ( TsprLabels [ labelNum ] . lId ) ;
2015-03-25 06:27:57 +00:00
break ;
case STRUCT_PROJECTILE :
case STRUCT_THISPROJECTILE :
2018-11-18 18:14:20 +00:00
scriptWriteValue ( ProjectileLabels [ labelNum ] . lId ) ;
2015-03-25 06:27:57 +00:00
break ;
case STRUCT_USERDEF :
2018-11-18 18:14:20 +00:00
scriptWriteValue ( UserdefsLabels [ labelNum ] . lId ) ;
2018-02-26 20:19:55 +00:00
if ( UserdefsLabels [ labelNum ] . flags & LABEL_HASPARM2 )
C_GetNextVarType ( 0 ) ;
2015-03-25 06:27:57 +00:00
break ;
case STRUCT_INPUT :
2018-11-18 18:14:20 +00:00
scriptWriteValue ( InputLabels [ labelNum ] . lId ) ;
2015-03-25 06:27:57 +00:00
break ;
2015-03-30 05:56:37 +00:00
case STRUCT_TILEDATA :
2018-11-18 18:14:20 +00:00
scriptWriteValue ( TileDataLabels [ labelNum ] . lId ) ;
2015-03-30 05:56:37 +00:00
break ;
case STRUCT_PALDATA :
2018-11-18 18:14:20 +00:00
scriptWriteValue ( PalDataLabels [ labelNum ] . lId ) ;
2015-03-30 05:56:37 +00:00
break ;
2015-03-25 06:27:42 +00:00
}
2009-01-07 14:05:13 +00:00
}
2008-04-01 02:50:44 +00:00
return ;
}
2018-11-18 18:14:54 +00:00
2018-11-18 18:11:09 +00:00
id = GetDefID ( LAST_LABEL ) ;
2018-11-18 18:10:57 +00:00
if ( id < 0 ) //gamevar not found
2006-04-13 20:47:06 +00:00
{
2018-11-18 18:14:43 +00:00
if ( EDUKE32_PREDICT_TRUE ( ! type & & ! g_labelsOnly ) )
2006-04-13 20:47:06 +00:00
{
2008-04-01 02:50:44 +00:00
//try looking for a define instead
2018-11-18 18:11:09 +00:00
Bstrcpy ( tempbuf , LAST_LABEL ) ;
2018-11-18 18:10:57 +00:00
id = hash_find ( & h_labels , tempbuf ) ;
if ( EDUKE32_PREDICT_TRUE ( id > = 0 & & labeltype [ id ] & LABEL_DEFINE ) )
2006-04-13 20:47:06 +00:00
{
2018-11-18 18:10:57 +00:00
if ( ! ( g_errorCnt | | g_warningCnt ) & & g_scriptDebug )
initprintf ( " %s:%d: debug: label `%s' in place of gamevar. \n " , g_scriptFileName , g_lineNumber , label + ( id < < 6 ) ) ;
2018-11-18 18:14:20 +00:00
scriptWriteValue ( GV_FLAG_CONSTANT ) ;
scriptWriteValue ( labelcode [ id ] ) ;
2018-11-18 18:10:57 +00:00
return ;
2006-04-13 20:47:06 +00:00
}
}
2018-11-18 18:10:57 +00:00
2016-08-27 01:42:01 +00:00
g_errorCnt + + ;
2008-11-20 14:06:36 +00:00
C_ReportError ( ERROR_NOTAGAMEVAR ) ;
2006-12-23 02:38:47 +00:00
return ;
2006-04-13 20:47:06 +00:00
}
2018-11-18 18:10:57 +00:00
if ( EDUKE32_PREDICT_FALSE ( type = = GAMEVAR_READONLY & & aGameVars [ id ] . flags & GAMEVAR_READONLY ) )
2006-04-13 20:47:06 +00:00
{
2016-08-27 01:42:01 +00:00
g_errorCnt + + ;
2008-11-20 14:06:36 +00:00
C_ReportError ( ERROR_VARREADONLY ) ;
2006-04-13 20:47:06 +00:00
return ;
}
2018-11-18 18:10:57 +00:00
else if ( EDUKE32_PREDICT_FALSE ( aGameVars [ id ] . flags & type ) )
2006-04-13 20:47:06 +00:00
{
2016-08-27 01:42:01 +00:00
g_errorCnt + + ;
2008-11-20 14:06:36 +00:00
C_ReportError ( ERROR_VARTYPEMISMATCH ) ;
2006-04-13 20:47:06 +00:00
return ;
}
2011-04-07 01:16:29 +00:00
2018-12-15 01:38:05 +00:00
if ( g_scriptDebug > 1 & & ! g_errorCnt & & ! g_warningCnt )
2018-11-18 18:11:09 +00:00
initprintf ( " %s:%d: debug: gamevar `%s'. \n " , g_scriptFileName , g_lineNumber , LAST_LABEL ) ;
2008-04-27 06:54:28 +00:00
2018-11-18 18:14:20 +00:00
scriptWriteValue ( id | flags ) ;
2006-04-13 20:47:06 +00:00
}
2009-01-10 07:38:50 +00:00
# define C_GetNextVar() C_GetNextVarType(0)
2006-04-13 20:47:06 +00:00
2018-11-18 18:14:43 +00:00
static FORCE_INLINE void C_GetManyVarsType ( int32_t type , int num )
2006-04-13 20:47:06 +00:00
{
2018-11-18 18:14:43 +00:00
for ( ; num > 0 ; - - num )
2008-11-20 14:06:36 +00:00
C_GetNextVarType ( type ) ;
2006-04-13 20:47:06 +00:00
}
2009-01-10 07:38:50 +00:00
# define C_GetManyVars(num) C_GetManyVarsType(0,num)
2006-04-13 20:47:06 +00:00
2012-06-17 19:45:46 +00:00
// returns:
// -1 on EOF or wrong type or error
// 0 if literal value
// LABEL_* (>0) if that type and matched
//
// *g_scriptPtr will contain the value OR 0 if wrong type or error
2009-01-09 09:29:17 +00:00
static int32_t C_GetNextValue ( int32_t type )
2006-04-13 20:47:06 +00:00
{
2008-11-20 14:06:36 +00:00
C_SkipComments ( ) ;
2006-04-13 20:47:06 +00:00
2009-11-18 01:17:56 +00:00
if ( * textptr = = 0 ) // EOF
return - 1 ;
2006-04-13 20:47:06 +00:00
2016-01-03 20:07:24 +00:00
int32_t l = 0 ;
2006-11-14 21:35:50 +00:00
while ( isaltok ( * ( textptr + l ) ) )
2006-04-13 20:47:06 +00:00
{
tempbuf [ l ] = textptr [ l ] ;
l + + ;
}
tempbuf [ l ] = 0 ;
2018-10-07 05:22:51 +00:00
if ( EDUKE32_PREDICT_FALSE ( hash_find ( & h_keywords , tempbuf /*label+(g_numLabels<<6)*/ ) > = 0 ) )
2008-08-25 00:49:12 +00:00
{
2016-08-27 01:42:01 +00:00
g_errorCnt + + ;
2008-11-20 14:06:36 +00:00
C_ReportError ( ERROR_ISAKEYWORD ) ;
2008-08-25 00:49:12 +00:00
textptr + = l ;
}
2006-04-28 04:14:45 +00:00
2016-01-03 20:07:24 +00:00
int32_t i = hash_find ( & h_labels , tempbuf ) ;
2008-08-25 00:49:12 +00:00
if ( i > = 0 )
2006-04-13 20:47:06 +00:00
{
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_TRUE ( labeltype [ i ] & type ) )
2008-08-25 00:49:12 +00:00
{
2018-12-15 01:38:05 +00:00
if ( g_scriptDebug > 1 & & ! g_errorCnt & & ! g_warningCnt )
2006-04-13 20:47:06 +00:00
{
2016-01-11 05:05:38 +00:00
char * gl = C_GetLabelType ( labeltype [ i ] ) ;
2016-08-27 01:42:01 +00:00
initprintf ( " %s:%d: debug: %s label `%s'. \n " , g_scriptFileName , g_lineNumber , gl , label + ( i < < 6 ) ) ;
2008-08-25 00:49:12 +00:00
Bfree ( gl ) ;
2006-04-13 20:47:06 +00:00
}
2012-03-11 17:37:50 +00:00
2018-11-18 18:14:20 +00:00
scriptWriteValue ( labelcode [ i ] ) ;
2012-03-11 17:37:50 +00:00
2006-04-13 20:47:06 +00:00
textptr + = l ;
2008-08-25 00:49:12 +00:00
return labeltype [ i ] ;
2006-04-13 20:47:06 +00:00
}
2014-10-25 03:36:34 +00:00
2018-11-18 18:14:20 +00:00
scriptWriteValue ( 0 ) ;
2008-08-25 00:49:12 +00:00
textptr + = l ;
2018-11-18 18:14:43 +00:00
char * const el = C_GetLabelType ( type ) ;
char * const gl = C_GetLabelType ( labeltype [ i ] ) ;
2008-11-20 14:06:36 +00:00
C_ReportError ( - 1 ) ;
2016-08-27 01:42:01 +00:00
initprintf ( " %s:%d: warning: expected %s, found %s. \n " , g_scriptFileName , g_lineNumber , el , gl ) ;
g_warningCnt + + ;
2008-08-25 00:49:12 +00:00
Bfree ( el ) ;
Bfree ( gl ) ;
return - 1 ; // valid label name, but wrong type
2006-04-13 20:47:06 +00:00
}
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_FALSE ( isdigit ( * textptr ) = = 0 & & * textptr ! = ' - ' ) )
2006-04-13 20:47:06 +00:00
{
2008-11-20 14:06:36 +00:00
C_ReportError ( ERROR_PARAMUNDEFINED ) ;
2016-08-27 01:42:01 +00:00
g_errorCnt + + ;
2018-11-18 18:14:20 +00:00
scriptWriteValue ( 0 ) ;
2006-04-13 20:47:06 +00:00
textptr + = l ;
2017-05-17 21:55:01 +00:00
if ( ! l ) textptr + + ;
2006-04-13 20:47:06 +00:00
return - 1 ; // error!
}
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_FALSE ( isdigit ( * textptr ) & & g_labelsOnly ) )
2006-04-13 20:47:06 +00:00
{
2008-11-20 14:06:36 +00:00
C_ReportError ( WARNING_LABELSONLY ) ;
2016-08-27 01:42:01 +00:00
g_warningCnt + + ;
2006-04-13 20:47:06 +00:00
}
2008-12-21 22:46:55 +00:00
i = l - 1 ;
do
{
2009-01-13 04:40:56 +00:00
// FIXME: check for 0-9 A-F for hex
2009-01-02 01:03:41 +00:00
if ( textptr [ 0 ] = = ' 0 ' & & textptr [ 1 ] = = ' x ' ) break ; // kill the warning for hex
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_FALSE ( ! isdigit ( textptr [ i - - ] ) ) )
2008-12-21 22:46:55 +00:00
{
C_ReportError ( - 1 ) ;
2016-08-27 01:42:01 +00:00
initprintf ( " %s:%d: warning: invalid character `%c' in definition! \n " , g_scriptFileName , g_lineNumber , textptr [ i + 1 ] ) ;
g_warningCnt + + ;
2008-12-21 22:46:55 +00:00
break ;
}
}
while ( i > 0 ) ;
2016-10-23 19:47:33 +00:00
if ( textptr [ 0 ] = = ' 0 ' & & tolower ( textptr [ 1 ] ) = = ' x ' )
2018-11-18 18:14:20 +00:00
scriptWriteValue ( parse_hex_constant ( textptr + 2 ) ) ;
2008-02-18 08:10:54 +00:00
else
2018-11-18 18:14:20 +00:00
scriptWriteValue ( parse_decimal_number ( ) ) ;
2012-02-29 15:27:40 +00:00
2018-12-15 01:38:05 +00:00
if ( g_scriptDebug > 1 & & ! g_errorCnt & & ! g_warningCnt )
2018-12-15 01:36:27 +00:00
initprintf ( " %s:%d: debug: constant %ld. \n " , g_scriptFileName , g_lineNumber , ( long ) g_scriptPtr [ - 1 ] ) ;
2006-04-13 20:47:06 +00:00
textptr + = l ;
return 0 ; // literal value
}
2018-11-18 18:14:26 +00:00
static int C_GetStructureIndexes ( bool const labelsonly , hashtable_t const * const table )
2016-01-03 20:07:11 +00:00
{
2016-01-21 19:35:14 +00:00
C_SkipComments ( ) ;
2016-01-03 20:07:11 +00:00
2018-11-18 18:14:54 +00:00
if ( EDUKE32_PREDICT_FALSE ( * textptr ! = ' [ ' & & * textptr ! = ' . ' ) )
2016-01-21 19:35:14 +00:00
{
2016-08-27 01:42:01 +00:00
g_errorCnt + + ;
2016-01-21 19:35:14 +00:00
C_ReportError ( ERROR_SYNTAXERROR ) ;
return - 1 ;
}
2016-01-03 20:07:11 +00:00
2018-11-18 18:14:54 +00:00
if ( * textptr ! = ' . ' ) textptr + + ;
2016-01-03 20:07:11 +00:00
C_SkipComments ( ) ;
2018-11-18 18:14:54 +00:00
if ( * textptr = = ' ] ' | | * textptr = = ' . ' )
2016-01-07 03:29:59 +00:00
{
2018-11-18 18:14:20 +00:00
scriptWriteValue ( g_thisActorVarID ) ;
2016-01-07 03:29:59 +00:00
}
2016-01-03 20:07:11 +00:00
else
{
g_labelsOnly = labelsonly ;
C_GetNextVar ( ) ;
g_labelsOnly = 0 ;
}
2018-11-18 18:14:54 +00:00
if ( * textptr ! = ' . ' ) textptr + + ;
2016-01-03 20:07:11 +00:00
2016-01-21 19:35:14 +00:00
C_SkipComments ( ) ;
2016-01-03 20:07:11 +00:00
2016-01-21 19:35:14 +00:00
// now get name of .xxx
if ( EDUKE32_PREDICT_FALSE ( * textptr + + ! = ' . ' ) )
2016-01-03 20:07:11 +00:00
{
2016-08-27 01:42:01 +00:00
g_errorCnt + + ;
2016-01-03 20:07:11 +00:00
C_ReportError ( ERROR_SYNTAXERROR ) ;
return - 1 ;
}
if ( ! table )
return 0 ;
// .xxx
C_GetNextLabelName ( ) ;
2018-11-18 18:14:43 +00:00
int const labelNum = C_GetLabelNameOffset ( table , Bstrtolower ( LAST_LABEL ) ) ;
2016-01-03 20:07:11 +00:00
2016-08-27 01:40:35 +00:00
if ( EDUKE32_PREDICT_FALSE ( labelNum = = - 1 ) )
2016-01-03 20:07:11 +00:00
{
2016-08-27 01:42:01 +00:00
g_errorCnt + + ;
2016-01-03 20:07:11 +00:00
C_ReportError ( ERROR_NOTAMEMBER ) ;
return - 1 ;
}
2016-08-27 01:40:35 +00:00
return labelNum ;
2016-01-03 20:07:11 +00:00
}
2019-02-28 07:21:33 +00:00
# ifdef CURRENTLY_UNUSED
2018-11-18 18:14:43 +00:00
static FORCE_INLINE bool C_IntPow2 ( int32_t const v )
2009-06-19 01:10:10 +00:00
{
2009-06-24 08:20:10 +00:00
return ( ( v ! = 0 ) & & ( v & ( v - 1 ) ) = = 0 ) ;
2009-06-19 01:10:10 +00:00
}
2016-01-03 20:07:24 +00:00
static inline uint32_t C_Pow2IntLogBase2 ( int32_t const v )
2009-06-19 01:10:10 +00:00
{
2018-11-18 18:14:43 +00:00
static constexpr uint32_t b [ ] = { 0xAAAAAAAA , 0xCCCCCCCC , 0xF0F0F0F0 , 0xFF00FF00 , 0xFFFF0000 } ;
2016-01-03 20:07:24 +00:00
2017-06-05 10:05:29 +00:00
uint32_t r = ( v & b [ 0 ] ) ! = 0 ;
2009-06-24 08:20:10 +00:00
2018-11-18 18:14:43 +00:00
for ( int i = 0 ; i < ARRAY_SSIZE ( b ) ; + + i )
2009-06-24 08:20:10 +00:00
r | = ( ( v & b [ i ] ) ! = 0 ) < < i ;
return r ;
2009-06-19 01:10:10 +00:00
}
2019-02-28 07:21:33 +00:00
# endif
2009-06-19 01:10:10 +00:00
2018-11-18 18:14:43 +00:00
static bool C_CheckMalformedBranch ( intptr_t lastScriptPtr )
2009-06-18 05:57:10 +00:00
{
switch ( C_GetKeyword ( ) )
{
case CON_RIGHTBRACE :
case CON_ENDA :
case CON_ENDEVENT :
case CON_ENDS :
2009-06-19 01:10:10 +00:00
case CON_ELSE :
2018-12-15 01:36:27 +00:00
g_scriptPtr = lastScriptPtr + apScript ;
2018-12-15 01:36:42 +00:00
g_skipBranch = true ;
2009-06-18 05:57:10 +00:00
C_ReportError ( - 1 ) ;
2016-08-27 01:42:01 +00:00
g_warningCnt + + ;
initprintf ( " %s:%d: warning: malformed `%s' branch \n " , g_scriptFileName , g_lineNumber ,
2017-10-16 03:32:34 +00:00
VM_GetKeywordForID ( * ( g_scriptPtr ) & VM_INSTMASK ) ) ;
2018-11-18 18:14:43 +00:00
return true ;
2009-06-18 05:57:10 +00:00
}
2018-11-18 18:14:43 +00:00
return false ;
2009-06-18 05:57:10 +00:00
}
2018-11-18 18:14:43 +00:00
static bool C_CheckEmptyBranch ( int tw , intptr_t lastScriptPtr )
2009-01-04 22:22:33 +00:00
{
2011-12-04 18:10:06 +00:00
// ifrnd and the others actually do something when the condition is executed
2017-10-16 03:32:34 +00:00
if ( ( Bstrncmp ( VM_GetKeywordForID ( tw ) , " if " , 2 ) & & tw ! = CON_ELSE ) | |
2011-12-04 18:10:06 +00:00
tw = = CON_IFRND | | tw = = CON_IFHITWEAPON | | tw = = CON_IFCANSEE | | tw = = CON_IFCANSEETARGET | |
tw = = CON_IFPDISTL | | tw = = CON_IFPDISTG | | tw = = CON_IFGOTWEAPONCE )
2009-01-04 22:22:33 +00:00
{
2018-12-15 01:36:42 +00:00
g_skipBranch = false ;
2018-11-18 18:14:43 +00:00
return false ;
2009-01-04 22:22:33 +00:00
}
2016-01-11 05:05:10 +00:00
if ( ( * ( g_scriptPtr ) & VM_INSTMASK ) ! = CON_NULLOP | | * ( g_scriptPtr ) > > 12 ! = IFELSE_MAGIC )
2018-12-15 01:36:42 +00:00
g_skipBranch = false ;
2009-01-04 22:22:33 +00:00
2018-12-15 01:36:42 +00:00
if ( EDUKE32_PREDICT_FALSE ( g_skipBranch ) )
2009-01-04 22:22:33 +00:00
{
2009-01-05 14:43:12 +00:00
C_ReportError ( - 1 ) ;
2016-08-27 01:42:01 +00:00
g_warningCnt + + ;
2018-12-15 01:36:27 +00:00
g_scriptPtr = lastScriptPtr + apScript ;
2016-08-27 01:42:01 +00:00
initprintf ( " %s:%d: warning: empty `%s' branch \n " , g_scriptFileName , g_lineNumber ,
2017-10-16 03:32:34 +00:00
VM_GetKeywordForID ( * ( g_scriptPtr ) & VM_INSTMASK ) ) ;
2018-12-15 01:36:42 +00:00
scriptWriteAtOffset ( CON_NULLOP | ( IFELSE_MAGIC < < 12 ) , g_scriptPtr ) ;
2018-11-18 18:14:43 +00:00
return true ;
2009-01-04 22:22:33 +00:00
}
2018-11-18 18:14:43 +00:00
return false ;
2009-01-04 22:22:33 +00:00
}
2018-11-18 18:14:43 +00:00
static int C_CountCaseStatements ( )
2006-04-13 20:47:06 +00:00
{
2018-12-15 01:36:42 +00:00
char * const temptextptr = textptr ;
int const backupLineNumber = g_lineNumber ;
int const backupNumCases = g_numCases ;
intptr_t const casePtrOffset = g_caseTablePtr - apScript ;
intptr_t const scriptPtrOffset = g_scriptPtr - apScript ;
2018-11-18 18:14:43 +00:00
g_numCases = 0 ;
2018-12-15 01:36:42 +00:00
g_caseTablePtr = NULL ;
2011-05-20 02:34:41 +00:00
C_ParseCommand ( 1 ) ;
2018-11-18 18:14:43 +00:00
2008-11-20 14:06:36 +00:00
// since we processed the endswitch, we need to re-increment g_checkingSwitch
g_checkingSwitch + + ;
2006-04-13 20:47:06 +00:00
2018-11-18 18:14:43 +00:00
int const numCases = g_numCases ;
2006-04-13 20:47:06 +00:00
2018-12-15 01:36:42 +00:00
textptr = temptextptr ;
g_lineNumber = backupLineNumber ;
g_numCases = backupNumCases ;
g_caseTablePtr = apScript + casePtrOffset ;
g_scriptPtr = apScript + scriptPtrOffset ;
2006-04-13 20:47:06 +00:00
2018-11-18 18:14:43 +00:00
return numCases ;
2006-04-13 20:47:06 +00:00
}
2011-07-21 22:39:29 +00:00
static void C_Include ( const char * confile )
{
2018-11-18 18:10:21 +00:00
int32_t const fp = kopen4loadfrommod ( confile , g_loadFromGroupOnly ) ;
2011-07-21 22:39:29 +00:00
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_FALSE ( fp < 0 ) )
2011-07-21 22:39:29 +00:00
{
2016-08-27 01:42:01 +00:00
g_errorCnt + + ;
initprintf ( " %s:%d: error: could not find file `%s'. \n " , g_scriptFileName , g_lineNumber , confile ) ;
2011-07-21 22:39:29 +00:00
return ;
}
2018-11-18 18:10:21 +00:00
int32_t const len = kfilelength ( fp ) ;
char * mptr = ( char * ) Xmalloc ( len + 1 ) ;
2011-07-21 22:39:29 +00:00
2018-11-18 18:10:21 +00:00
initprintf ( " Including: %s (%d bytes) \n " , confile , len ) ;
2016-01-03 20:07:24 +00:00
2018-11-18 18:10:21 +00:00
kread ( fp , mptr , len ) ;
2011-07-21 22:39:29 +00:00
kclose ( fp ) ;
2018-11-18 18:10:21 +00:00
mptr [ len ] = 0 ;
g_scriptcrc = Bcrc32 ( mptr , len , g_scriptcrc ) ;
2011-07-21 22:39:29 +00:00
if ( * textptr = = ' " ' ) // skip past the closing quote if it's there so we don't screw up the next line
textptr + + ;
2016-01-03 20:07:24 +00:00
2018-11-18 18:10:21 +00:00
char * const origtptr = textptr ;
char parentScriptFileName [ BMAX_PATH ] ;
2011-07-21 22:39:29 +00:00
2016-08-27 01:42:01 +00:00
Bstrcpy ( parentScriptFileName , g_scriptFileName ) ;
Bstrcpy ( g_scriptFileName , confile ) ;
2016-01-03 20:07:24 +00:00
2018-11-18 18:10:21 +00:00
int const temp_ScriptLineNumber = g_lineNumber ;
2011-07-21 22:39:29 +00:00
g_lineNumber = 1 ;
2016-01-03 20:07:24 +00:00
2018-11-18 18:10:21 +00:00
int const temp_ifelse_check = g_checkingIfElse ;
2011-07-21 22:39:29 +00:00
g_checkingIfElse = 0 ;
textptr = mptr ;
C_SkipComments ( ) ;
C_ParseCommand ( 1 ) ;
2016-08-27 01:42:01 +00:00
Bstrcpy ( g_scriptFileName , parentScriptFileName ) ;
2016-01-03 20:07:24 +00:00
2011-07-21 22:39:29 +00:00
g_totalLines + = g_lineNumber ;
g_lineNumber = temp_ScriptLineNumber ;
g_checkingIfElse = temp_ifelse_check ;
textptr = origtptr ;
Bfree ( mptr ) ;
}
2013-01-19 18:29:00 +00:00
# endif // !defined LUNATIC
2011-07-21 22:39:29 +00:00
2012-05-28 18:15:26 +00:00
# ifdef _WIN32
static void check_filename_case ( const char * fn )
{
int32_t fp ;
if ( ( fp = kopen4loadfrommod ( fn , g_loadFromGroupOnly ) ) > = 0 )
kclose ( fp ) ;
}
# else
static void check_filename_case ( const char * fn ) { UNREFERENCED_PARAMETER ( fn ) ; }
# endif
2012-12-29 15:21:24 +00:00
void G_DoGameStartup ( const int32_t * params )
{
2018-11-18 18:10:10 +00:00
auto & p0 = * g_player [ 0 ] . ps ;
2016-08-27 01:42:01 +00:00
int j = 0 ;
2013-05-23 18:28:04 +00:00
2018-11-18 18:10:10 +00:00
ud . const_visibility = params [ j + + ] ;
g_impactDamage = params [ j + + ] ;
p0 . max_shield_amount = params [ j ] ;
p0 . max_player_health = params [ j ] ;
g_maxPlayerHealth = params [ j + + ] ;
g_startArmorAmount = params [ j + + ] ;
g_actorRespawnTime = params [ j + + ] ;
g_itemRespawnTime = ( g_scriptVersion > = 11 ) ? params [ j + + ] : g_actorRespawnTime ;
2013-05-23 18:28:04 +00:00
if ( g_scriptVersion > = 11 )
g_playerFriction = params [ j + + ] ;
2016-10-14 07:40:38 +00:00
if ( g_scriptVersion > = 14 )
2013-05-23 18:28:04 +00:00
g_spriteGravity = params [ j + + ] ;
if ( g_scriptVersion > = 11 )
{
2016-08-27 01:42:01 +00:00
g_rpgRadius = params [ j + + ] ;
g_pipebombRadius = params [ j + + ] ;
g_shrinkerRadius = params [ j + + ] ;
g_tripbombRadius = params [ j + + ] ;
g_morterRadius = params [ j + + ] ;
g_bouncemineRadius = params [ j + + ] ;
g_seenineRadius = params [ j + + ] ;
2013-05-23 18:28:04 +00:00
}
2018-11-18 18:10:10 +00:00
p0 . max_ammo_amount [ PISTOL_WEAPON ] = params [ j + + ] ;
p0 . max_ammo_amount [ SHOTGUN_WEAPON ] = params [ j + + ] ;
p0 . max_ammo_amount [ CHAINGUN_WEAPON ] = params [ j + + ] ;
p0 . max_ammo_amount [ RPG_WEAPON ] = params [ j + + ] ;
p0 . max_ammo_amount [ HANDBOMB_WEAPON ] = params [ j + + ] ;
p0 . max_ammo_amount [ SHRINKER_WEAPON ] = params [ j + + ] ;
p0 . max_ammo_amount [ DEVISTATOR_WEAPON ] = params [ j + + ] ;
p0 . max_ammo_amount [ TRIPBOMB_WEAPON ] = params [ j + + ] ;
2013-05-23 18:28:04 +00:00
if ( g_scriptVersion > = 13 )
2012-12-29 15:21:24 +00:00
{
2018-11-18 18:10:10 +00:00
p0 . max_ammo_amount [ FREEZE_WEAPON ] = params [ j + + ] ;
2013-05-23 18:28:04 +00:00
2016-10-14 07:40:38 +00:00
if ( g_scriptVersion > = 14 )
2018-11-18 18:10:10 +00:00
p0 . max_ammo_amount [ GROW_WEAPON ] = params [ j + + ] ;
2013-05-23 18:28:04 +00:00
2016-08-27 01:42:01 +00:00
g_damageCameras = params [ j + + ] ;
g_numFreezeBounces = params [ j + + ] ;
2013-05-23 18:28:04 +00:00
g_freezerSelfDamage = params [ j + + ] ;
2016-10-14 07:40:38 +00:00
if ( g_scriptVersion > = 14 )
2013-05-23 18:28:04 +00:00
{
2018-11-18 18:10:10 +00:00
g_deleteQueueSize = clamp ( params [ j + + ] , 0 , ARRAY_SSIZE ( SpriteDeletionQueue ) ) ;
2013-05-23 18:28:04 +00:00
g_tripbombLaserMode = params [ j + + ] ;
}
2012-12-29 15:21:24 +00:00
}
}
2016-08-27 01:42:01 +00:00
void C_DefineMusic ( int volumeNum , int levelNum , const char * fileName )
2014-09-07 18:10:12 +00:00
{
2016-08-27 01:42:01 +00:00
Bassert ( ( unsigned ) volumeNum < MAXVOLUMES + 1 ) ;
Bassert ( ( unsigned ) levelNum < MAXLEVELS ) ;
2014-09-07 18:10:12 +00:00
2016-08-27 01:42:01 +00:00
map_t * const pMapInfo = & g_mapInfo [ ( MAXLEVELS * volumeNum ) + levelNum ] ;
2014-09-07 18:10:12 +00:00
2016-08-27 01:42:01 +00:00
Bfree ( pMapInfo - > musicfn ) ;
pMapInfo - > musicfn = dup_filename ( fileName ) ;
check_filename_case ( pMapInfo - > musicfn ) ;
2014-09-07 18:10:12 +00:00
}
2013-01-01 15:24:22 +00:00
# ifdef LUNATIC
void C_DefineSound ( int32_t sndidx , const char * fn , int32_t args [ 5 ] )
{
Bassert ( ( unsigned ) sndidx < MAXSOUNDS ) ;
{
sound_t * const snd = & g_sounds [ sndidx ] ;
Bfree ( snd - > filename ) ;
snd - > filename = dup_filename ( fn ) ;
check_filename_case ( snd - > filename ) ;
snd - > ps = args [ 0 ] ;
snd - > pe = args [ 1 ] ;
snd - > pr = args [ 2 ] ;
2013-09-21 13:38:07 +00:00
snd - > m = args [ 3 ] & ~ SF_ONEINST_INTERNAL ;
if ( args [ 3 ] & SF_LOOP )
snd - > m | = SF_ONEINST_INTERNAL ;
2013-01-01 15:24:22 +00:00
snd - > vo = args [ 4 ] ;
2018-04-02 22:00:11 +00:00
if ( sndidx > g_highestSoundIdx )
g_highestSoundIdx = sndidx ;
2013-01-01 15:24:22 +00:00
}
}
2013-01-01 15:24:28 +00:00
void C_DefineQuote ( int32_t qnum , const char * qstr )
{
C_AllocQuote ( qnum ) ;
2016-08-27 01:40:35 +00:00
Bstrncpyz ( apStrings [ qnum ] , qstr , MAXQUOTELEN ) ;
2013-01-01 15:24:28 +00:00
}
2013-01-05 13:09:19 +00:00
void C_DefineVolumeName ( int32_t vol , const char * name )
{
Bassert ( ( unsigned ) vol < MAXVOLUMES ) ;
2016-08-27 01:42:01 +00:00
Bstrncpyz ( g_volumeNames [ vol ] , name , sizeof ( g_volumeNames [ vol ] ) ) ;
g_volumeCnt = vol + 1 ;
2013-01-05 13:09:19 +00:00
}
2013-01-05 13:09:31 +00:00
void C_DefineSkillName ( int32_t skill , const char * name )
{
Bassert ( ( unsigned ) skill < MAXSKILLS ) ;
2016-08-27 01:42:01 +00:00
Bstrncpyz ( g_skillNames [ skill ] , name , sizeof ( g_skillNames [ skill ] ) ) ;
g_skillCnt = max ( g_skillCnt , skill + 1 ) ; // TODO: bring in line with C-CON?
2013-01-05 13:09:31 +00:00
}
2013-01-05 13:09:19 +00:00
void C_DefineLevelName ( int32_t vol , int32_t lev , const char * fn ,
int32_t partime , int32_t designertime ,
const char * levelname )
{
Bassert ( ( unsigned ) vol < MAXVOLUMES ) ;
Bassert ( ( unsigned ) lev < MAXLEVELS ) ;
{
2016-08-27 01:42:01 +00:00
map_t * const map = & g_mapInfo [ ( MAXLEVELS * vol ) + lev ] ;
2013-01-05 13:09:19 +00:00
Bfree ( map - > filename ) ;
map - > filename = dup_filename ( fn ) ;
// TODO: truncate to 32 chars?
Bfree ( map - > name ) ;
2014-05-30 00:02:19 +00:00
map - > name = Xstrdup ( levelname ) ;
2013-01-05 13:09:19 +00:00
map - > partime = REALGAMETICSPERSEC * partime ;
map - > designertime = REALGAMETICSPERSEC * designertime ;
}
}
2013-02-24 16:05:22 +00:00
void C_DefineGameFuncName ( int32_t idx , const char * name )
{
2013-05-30 18:10:49 +00:00
assert ( ( unsigned ) idx < NUMGAMEFUNCTIONS ) ;
2013-02-24 16:05:22 +00:00
Bstrncpyz ( gamefunctions [ idx ] , name , MAXGAMEFUNCLEN ) ;
2013-02-28 17:30:04 +00:00
hash_add ( & h_gamefuncs , gamefunctions [ idx ] , idx , 0 ) ;
2013-02-24 16:05:22 +00:00
}
2013-05-30 18:10:49 +00:00
void C_DefineGameType ( int32_t idx , int32_t flags , const char * name )
{
Bassert ( ( unsigned ) idx < MAXGAMETYPES ) ;
2016-08-27 01:42:01 +00:00
g_gametypeFlags [ idx ] = flags ;
Bstrncpyz ( g_gametypeNames [ idx ] , name , sizeof ( g_gametypeNames [ idx ] ) ) ;
g_gametypeCnt = idx + 1 ;
2013-05-30 18:10:49 +00:00
}
2013-01-01 15:24:22 +00:00
# endif
2015-02-22 22:15:20 +00:00
void C_DefineVolumeFlags ( int32_t vol , int32_t flags )
{
Bassert ( ( unsigned ) vol < MAXVOLUMES ) ;
2016-08-27 01:42:01 +00:00
g_volumeFlags [ vol ] = flags ;
2015-02-22 22:15:20 +00:00
}
2015-02-09 05:50:33 +00:00
void C_UndefineVolume ( int32_t vol )
{
Bassert ( ( unsigned ) vol < MAXVOLUMES ) ;
2016-08-27 01:41:21 +00:00
for ( bssize_t i = 0 ; i < MAXLEVELS ; i + + )
2015-02-22 22:14:54 +00:00
C_UndefineLevel ( vol , i ) ;
2016-08-27 01:42:01 +00:00
g_volumeNames [ vol ] [ 0 ] = ' \0 ' ;
2015-02-09 05:50:33 +00:00
2016-08-27 01:42:01 +00:00
g_volumeCnt = 0 ;
2016-08-27 01:41:21 +00:00
for ( bssize_t i = MAXVOLUMES - 1 ; i > = 0 ; i - - )
2015-02-09 05:50:33 +00:00
{
2016-08-27 01:42:01 +00:00
if ( g_volumeNames [ i ] [ 0 ] )
2015-02-09 05:50:33 +00:00
{
2016-08-27 01:42:01 +00:00
g_volumeCnt = i + 1 ;
2015-02-09 05:50:33 +00:00
break ;
}
}
}
void C_UndefineSkill ( int32_t skill )
{
Bassert ( ( unsigned ) skill < MAXSKILLS ) ;
2016-08-27 01:42:01 +00:00
g_skillNames [ skill ] [ 0 ] = ' \0 ' ;
2015-02-09 05:50:33 +00:00
2016-08-27 01:42:01 +00:00
g_skillCnt = 0 ;
2016-08-27 01:41:21 +00:00
for ( bssize_t i = MAXSKILLS - 1 ; i > = 0 ; i - - )
2015-02-09 05:50:33 +00:00
{
2016-08-27 01:42:01 +00:00
if ( g_skillNames [ i ] [ 0 ] )
2015-02-09 05:50:33 +00:00
{
2016-08-27 01:42:01 +00:00
g_skillCnt = i + 1 ;
2015-02-09 05:50:33 +00:00
break ;
}
}
}
void C_UndefineLevel ( int32_t vol , int32_t lev )
{
Bassert ( ( unsigned ) vol < MAXVOLUMES ) ;
Bassert ( ( unsigned ) lev < MAXLEVELS ) ;
2016-08-27 01:42:01 +00:00
map_t * const map = & g_mapInfo [ ( MAXLEVELS * vol ) + lev ] ;
2015-02-09 05:50:33 +00:00
2016-01-03 20:07:24 +00:00
DO_FREE_AND_NULL ( map - > filename ) ;
DO_FREE_AND_NULL ( map - > name ) ;
map - > partime = 0 ;
map - > designertime = 0 ;
2015-02-09 05:50:33 +00:00
}
2013-04-05 17:53:18 +00:00
LUNATIC_EXTERN int32_t C_SetDefName ( const char * name )
2013-02-24 16:05:22 +00:00
{
clearDefNamePtr ( ) ;
g_defNamePtr = dup_filename ( name ) ;
if ( g_defNamePtr )
initprintf ( " Using DEF file: %s. \n " , g_defNamePtr ) ;
return ( g_defNamePtr = = NULL ) ;
}
2015-03-24 00:40:55 +00:00
defaultprojectile_t DefaultProjectile ;
EDUKE32_STATIC_ASSERT ( sizeof ( projectile_t ) = = sizeof ( DefaultProjectile ) ) ;
2015-05-16 11:56:49 +00:00
void C_AllocProjectile ( int32_t j )
{
2018-09-01 19:36:05 +00:00
g_tile [ j ] . proj = ( projectile_t * ) Xrealloc ( g_tile [ j ] . proj , 2 * sizeof ( projectile_t ) ) ;
2015-05-16 11:56:49 +00:00
g_tile [ j ] . defproj = g_tile [ j ] . proj + 1 ;
}
void C_FreeProjectile ( int32_t j )
{
2015-09-23 17:55:31 +00:00
DO_FREE_AND_NULL ( g_tile [ j ] . proj ) ;
g_tile [ j ] . defproj = NULL ;
2015-05-16 11:56:49 +00:00
}
2013-04-05 17:53:18 +00:00
LUNATIC_EXTERN void C_DefineProjectile ( int32_t j , int32_t what , int32_t val )
2013-02-07 21:01:03 +00:00
{
2015-03-24 00:40:55 +00:00
if ( g_tile [ j ] . proj = = NULL )
{
2015-05-16 11:56:49 +00:00
C_AllocProjectile ( j ) ;
* g_tile [ j ] . proj = DefaultProjectile ;
2015-03-24 00:40:55 +00:00
}
projectile_t * const proj = g_tile [ j ] . proj ;
2013-02-07 21:01:03 +00:00
switch ( what )
{
2018-11-18 18:10:15 +00:00
case PROJ_WORKSLIKE : proj - > workslike = val ; break ;
case PROJ_SPAWNS : proj - > spawns = val ; break ;
case PROJ_SXREPEAT : proj - > sxrepeat = val ; break ;
case PROJ_SYREPEAT : proj - > syrepeat = val ; break ;
case PROJ_SOUND : proj - > sound = val ; break ;
case PROJ_ISOUND : proj - > isound = val ; break ;
case PROJ_VEL : proj - > vel = val ; break ;
case PROJ_EXTRA : proj - > extra = val ; break ;
case PROJ_DECAL : proj - > decal = val ; break ;
case PROJ_TRAIL : proj - > trail = val ; break ;
case PROJ_TXREPEAT : proj - > txrepeat = val ; break ;
case PROJ_TYREPEAT : proj - > tyrepeat = val ; break ;
case PROJ_TOFFSET : proj - > toffset = val ; break ;
case PROJ_TNUM : proj - > tnum = val ; break ;
case PROJ_DROP : proj - > drop = val ; break ;
case PROJ_CSTAT : proj - > cstat = val ; break ;
case PROJ_CLIPDIST : proj - > clipdist = val ; break ;
case PROJ_SHADE : proj - > shade = val ; break ;
case PROJ_XREPEAT : proj - > xrepeat = val ; break ;
case PROJ_YREPEAT : proj - > yrepeat = val ; break ;
case PROJ_PAL : proj - > pal = val ; break ;
case PROJ_EXTRA_RAND : proj - > extra_rand = val ; break ;
case PROJ_HITRADIUS : proj - > hitradius = val ; break ;
case PROJ_MOVECNT : proj - > movecnt = val ; break ;
case PROJ_OFFSET : proj - > offset = val ; break ;
case PROJ_BOUNCES : proj - > bounces = val ; break ;
case PROJ_BSOUND : proj - > bsound = val ; break ;
case PROJ_RANGE : proj - > range = val ; break ;
case PROJ_FLASH_COLOR : proj - > flashcolor = val ; break ;
case PROJ_USERDATA : proj - > userdata = val ; break ;
default : break ;
2013-02-07 21:01:03 +00:00
}
2015-03-24 00:40:55 +00:00
* g_tile [ j ] . defproj = * proj ;
2014-02-22 19:38:52 +00:00
g_tile [ j ] . flags | = SFLAG_PROJECTILE ;
2013-02-07 21:01:03 +00:00
}
2013-01-01 15:24:25 +00:00
int32_t C_AllocQuote ( int32_t qnum )
{
2014-03-22 17:02:21 +00:00
Bassert ( ( unsigned ) qnum < MAXQUOTES ) ;
2016-08-27 01:40:35 +00:00
if ( apStrings [ qnum ] = = NULL )
2013-01-01 15:24:25 +00:00
{
2016-08-27 01:40:35 +00:00
apStrings [ qnum ] = ( char * ) Xcalloc ( MAXQUOTELEN , sizeof ( uint8_t ) ) ;
2013-01-01 15:24:25 +00:00
return 1 ;
}
return 0 ;
}
2016-01-12 10:31:19 +00:00
# ifndef EDUKE32_TOUCH_DEVICES
2015-03-23 06:28:40 +00:00
static void C_ReplaceQuoteSubstring ( const size_t q , char const * const query , char const * const replacement )
{
size_t querylength = Bstrlen ( query ) ;
2016-08-27 01:41:21 +00:00
for ( bssize_t i = MAXQUOTELEN - querylength - 2 ; i > = 0 ; i - - )
2016-08-27 01:40:35 +00:00
if ( Bstrncmp ( & apStrings [ q ] [ i ] , query , querylength ) = = 0 )
2015-03-23 06:28:40 +00:00
{
Bmemset ( tempbuf , 0 , sizeof ( tempbuf ) ) ;
2016-08-27 01:40:35 +00:00
Bstrncpy ( tempbuf , apStrings [ q ] , i ) ;
2015-03-23 06:28:40 +00:00
Bstrcat ( tempbuf , replacement ) ;
2016-08-27 01:40:35 +00:00
Bstrcat ( tempbuf , & apStrings [ q ] [ i + querylength ] ) ;
Bstrncpy ( apStrings [ q ] , tempbuf , MAXQUOTELEN - 1 ) ;
2015-03-23 06:28:40 +00:00
i = MAXQUOTELEN - querylength - 2 ;
}
}
2016-01-12 10:31:19 +00:00
# endif
2015-03-23 06:28:40 +00:00
2013-01-01 15:24:25 +00:00
void C_InitQuotes ( void )
{
2018-11-18 18:14:26 +00:00
for ( int i = 0 ; i < 128 ; i + + ) C_AllocQuote ( i ) ;
2013-01-01 15:24:25 +00:00
2015-02-11 05:22:41 +00:00
# ifdef EDUKE32_TOUCH_DEVICES
2016-08-27 01:40:35 +00:00
apStrings [ QUOTE_DEAD ] = 0 ;
2015-01-11 04:56:10 +00:00
# else
2018-02-10 22:58:38 +00:00
char const * const OpenGameFunc = gamefunctions [ gamefunc_Open ] ;
2018-01-30 16:02:20 +00:00
C_ReplaceQuoteSubstring ( QUOTE_DEAD , " SPACE " , OpenGameFunc ) ;
C_ReplaceQuoteSubstring ( QUOTE_DEAD , " OPEN " , OpenGameFunc ) ;
C_ReplaceQuoteSubstring ( QUOTE_DEAD , " USE " , OpenGameFunc ) ;
2015-01-11 04:56:10 +00:00
# endif
2013-01-01 15:24:25 +00:00
// most of these are based on Blood, obviously
2015-01-11 04:56:10 +00:00
const char * PlayerObituaries [ ] =
2013-01-01 15:24:25 +00:00
{
2015-01-11 04:56:10 +00:00
" ^02%s^02 beat %s^02 like a cur " ,
" ^02%s^02 broke %s " ,
" ^02%s^02 body bagged %s " ,
" ^02%s^02 boned %s^02 like a fish " ,
" ^02%s^02 castrated %s " ,
" ^02%s^02 creamed %s " ,
" ^02%s^02 crushed %s " ,
" ^02%s^02 destroyed %s " ,
" ^02%s^02 diced %s " ,
" ^02%s^02 disemboweled %s " ,
" ^02%s^02 erased %s " ,
" ^02%s^02 eviscerated %s " ,
" ^02%s^02 flailed %s " ,
" ^02%s^02 flattened %s " ,
" ^02%s^02 gave AnAl MaDnEsS to %s " ,
" ^02%s^02 gave %s^02 Anal Justice " ,
" ^02%s^02 hosed %s " ,
" ^02%s^02 hurt %s^02 real bad " ,
" ^02%s^02 killed %s " ,
" ^02%s^02 made dog meat out of %s " ,
" ^02%s^02 made mincemeat out of %s " ,
" ^02%s^02 manhandled %s " ,
" ^02%s^02 massacred %s " ,
" ^02%s^02 mutilated %s " ,
" ^02%s^02 murdered %s " ,
" ^02%s^02 neutered %s " ,
" ^02%s^02 punted %s " ,
" ^02%s^02 reamed %s " ,
" ^02%s^02 ripped %s^02 a new orifice " ,
" ^02%s^02 rocked %s " ,
" ^02%s^02 sent %s^02 to hell " ,
" ^02%s^02 shredded %s " ,
" ^02%s^02 slashed %s " ,
" ^02%s^02 slaughtered %s " ,
" ^02%s^02 sliced %s " ,
" ^02%s^02 smacked %s around " ,
" ^02%s^02 smashed %s " ,
" ^02%s^02 snuffed %s " ,
" ^02%s^02 sodomized %s " ,
" ^02%s^02 splattered %s " ,
" ^02%s^02 sprayed %s " ,
" ^02%s^02 squashed %s " ,
" ^02%s^02 throttled %s " ,
" ^02%s^02 toasted %s " ,
" ^02%s^02 vented %s " ,
" ^02%s^02 ventilated %s " ,
" ^02%s^02 wasted %s " ,
" ^02%s^02 wrecked %s " ,
} ;
2013-01-01 15:24:25 +00:00
2015-01-11 04:56:10 +00:00
const char * PlayerSelfObituaries [ ] =
{
" ^02%s^02 is excrement " ,
" ^02%s^02 is hamburger " ,
" ^02%s^02 suffered scrotum separation " ,
" ^02%s^02 volunteered for population control " ,
" ^02%s^02 has suicided " ,
" ^02%s^02 bled out " ,
} ;
EDUKE32_STATIC_ASSERT ( OBITQUOTEINDEX + ARRAY_SIZE ( PlayerObituaries ) - 1 < MAXQUOTES ) ;
EDUKE32_STATIC_ASSERT ( SUICIDEQUOTEINDEX + ARRAY_SIZE ( PlayerSelfObituaries ) - 1 < MAXQUOTES ) ;
g_numObituaries = ARRAY_SIZE ( PlayerObituaries ) ;
2016-08-27 01:41:21 +00:00
for ( bssize_t i = g_numObituaries - 1 ; i > = 0 ; i - - )
2015-01-11 04:56:10 +00:00
{
if ( C_AllocQuote ( i + OBITQUOTEINDEX ) )
2016-08-27 01:40:35 +00:00
Bstrcpy ( apStrings [ i + OBITQUOTEINDEX ] , PlayerObituaries [ i ] ) ;
2015-01-11 04:56:10 +00:00
}
g_numSelfObituaries = ARRAY_SIZE ( PlayerSelfObituaries ) ;
2016-08-27 01:41:21 +00:00
for ( bssize_t i = g_numSelfObituaries - 1 ; i > = 0 ; i - - )
2015-01-11 04:56:10 +00:00
{
if ( C_AllocQuote ( i + SUICIDEQUOTEINDEX ) )
2016-08-27 01:40:35 +00:00
Bstrcpy ( apStrings [ i + SUICIDEQUOTEINDEX ] , PlayerSelfObituaries [ i ] ) ;
2013-01-01 15:24:25 +00:00
}
}
2013-11-08 18:08:45 +00:00
LUNATIC_EXTERN void C_SetCfgName ( const char * cfgname )
{
2017-07-05 05:37:52 +00:00
if ( Bstrcmp ( g_setupFileName , cfgname ) = = 0 ) // no need to do anything if name is the same
return ;
2016-08-27 01:42:01 +00:00
if ( Bstrcmp ( g_setupFileName , SETUPFILENAME ) ! = 0 ) // set to something else via -cfg
2013-11-08 18:08:45 +00:00
return ;
2018-11-18 18:13:02 +00:00
ud_setup_t const config = ud . setup ;
# ifdef POLYMER
int const renderMode = glrendmode ;
# endif
struct Bstat st ;
2013-11-08 18:08:45 +00:00
if ( Bstat ( g_modDir , & st ) < 0 )
{
if ( errno = = ENOENT ) // path doesn't exist
{
if ( Bmkdir ( g_modDir , S_IRWXU ) < 0 )
{
2018-11-18 18:13:02 +00:00
OSD_Printf ( " Failed to create directory \" %s \" ! \n " , g_modDir ) ;
2013-11-08 18:08:45 +00:00
return ;
}
}
else
{
// another type of failure
return ;
}
}
else if ( ( st . st_mode & S_IFDIR ) ! = S_IFDIR )
{
// directory isn't a directory
return ;
}
2013-11-08 18:08:47 +00:00
// XXX: Back up 'cfgname' as it may be the global 'tempbuf'.
2018-11-18 18:13:02 +00:00
char * temp = Xstrdup ( cfgname ) ;
2013-11-08 18:08:45 +00:00
CONFIG_WriteSetup ( 1 ) ;
2013-11-08 18:08:47 +00:00
2013-11-08 18:08:45 +00:00
if ( g_modDir [ 0 ] ! = ' / ' )
2016-08-27 01:42:01 +00:00
Bsnprintf ( g_setupFileName , sizeof ( g_setupFileName ) , " %s/%s " , g_modDir , temp ) ;
2013-11-08 18:08:47 +00:00
else
2016-08-27 01:42:01 +00:00
Bstrncpyz ( g_setupFileName , temp , sizeof ( g_setupFileName ) ) ;
2013-11-08 18:08:45 +00:00
2018-11-18 18:13:02 +00:00
DO_FREE_AND_NULL ( temp ) ;
2016-08-27 01:42:01 +00:00
initprintf ( " Using config file \" %s \" . \n " , g_setupFileName ) ;
2013-11-08 18:08:45 +00:00
CONFIG_ReadSetup ( ) ;
2018-11-18 18:13:02 +00:00
ud . setup = config ;
# ifdef POLYMER
glrendmode = renderMode ;
2013-11-08 18:08:45 +00:00
# endif
}
2013-01-19 18:29:00 +00:00
# if !defined LUNATIC
2016-01-21 19:35:19 +00:00
static inline void C_BitOrNextValue ( int32_t * valptr )
2014-12-26 17:29:57 +00:00
{
C_GetNextValue ( LABEL_DEFINE ) ;
g_scriptPtr - - ;
* valptr | = * g_scriptPtr ;
}
2016-01-21 19:35:19 +00:00
static inline void C_FinishBitOr ( int32_t value )
2014-12-26 17:29:57 +00:00
{
2018-11-18 18:14:20 +00:00
scriptWriteValue ( value ) ;
2014-12-26 17:29:57 +00:00
}
2015-03-27 12:28:45 +00:00
static void C_FillEventBreakStackWithJump ( intptr_t * breakPtr , intptr_t destination )
{
while ( breakPtr )
{
2016-08-27 01:40:35 +00:00
breakPtr = apScript + ( intptr_t ) breakPtr ;
2015-03-27 12:28:45 +00:00
intptr_t const tempPtr = * breakPtr ;
2018-11-18 18:14:20 +00:00
scriptWriteAtOffset ( destination , breakPtr ) ;
2016-01-08 01:33:01 +00:00
breakPtr = ( intptr_t * ) tempPtr ;
2015-03-27 12:28:45 +00:00
}
}
2018-12-15 01:38:05 +00:00
static void scriptUpdateOpcodeForVariableType ( intptr_t * ins )
{
int opcode = - 1 ;
if ( ins [ 1 ] < MAXGAMEVARS )
{
switch ( aGameVars [ ins [ 1 ] & ( MAXGAMEVARS - 1 ) ] . flags & ( GAMEVAR_USER_MASK | GAMEVAR_PTR_MASK ) )
{
case 0 :
opcode = inthash_find ( & h_globalvar , * ins & VM_INSTMASK ) ;
break ;
/*
case GAMEVAR_PERACTOR :
opcode = inthash_find ( & h_actorvar , * ins & VM_INSTMASK ) ;
break ;
case GAMEVAR_PERPLAYER :
opcode = inthash_find ( & h_playervar , * ins & VM_INSTMASK ) ;
break ;
*/
}
}
if ( opcode ! = - 1 )
{
if ( g_scriptDebug > 1 & & ! g_errorCnt & & ! g_warningCnt )
{
initprintf ( " %s:%d: %s -> %s for var %s \n " , g_scriptFileName , g_lineNumber ,
VM_GetKeywordForID ( * ins & VM_INSTMASK ) , VM_GetKeywordForID ( opcode ) , aGameVars [ ins [ 1 ] & ( MAXGAMEVARS - 1 ) ] . szLabel ) ;
}
scriptWriteAtOffset ( opcode | LINE_NUMBER , ins ) ;
}
}
2018-11-18 18:10:21 +00:00
static bool C_ParseCommand ( bool loop )
2006-04-13 20:47:06 +00:00
{
2016-01-03 20:07:24 +00:00
int32_t i , j = 0 , k = 0 , tw ;
2006-04-13 20:47:06 +00:00
2011-04-07 01:16:29 +00:00
do
2007-08-29 05:29:37 +00:00
{
2018-11-18 18:10:21 +00:00
if ( EDUKE32_PREDICT_FALSE ( g_errorCnt > 63 | | ( * textptr = = ' \0 ' ) | | ( * ( textptr + 1 ) = = ' \0 ' ) ) )
2011-04-07 01:16:29 +00:00
return 1 ;
2006-09-19 23:02:33 +00:00
2018-12-15 01:36:42 +00:00
if ( ( g_scriptPtr - apScript ) > ( g_scriptSize - 4096 ) & & g_caseTablePtr = = NULL )
2018-11-18 18:14:15 +00:00
C_SetScriptSize ( g_scriptSize < < 1 ) ;
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_FALSE ( g_scriptDebug ) )
2011-04-07 01:16:29 +00:00
C_ReportError ( - 1 ) ;
2006-04-13 20:47:06 +00:00
2018-11-18 18:10:21 +00:00
int const otw = g_lastKeyword ;
C_SkipComments ( ) ;
2006-04-13 20:47:06 +00:00
2011-04-07 01:16:29 +00:00
switch ( ( g_lastKeyword = tw = C_GetNextKeyword ( ) ) )
2006-11-16 03:02:42 +00:00
{
2011-04-07 01:16:29 +00:00
default :
case - 1 :
case - 2 :
return 1 ; //End
2015-09-24 06:31:44 +00:00
case CON_DEFSTATE :
2018-12-15 01:36:42 +00:00
if ( EDUKE32_PREDICT_FALSE ( g_processingState | | g_scriptActorOffset ) )
2015-09-24 06:31:44 +00:00
{
C_ReportError ( ERROR_FOUNDWITHIN ) ;
2016-08-27 01:42:01 +00:00
g_errorCnt + + ;
2015-09-24 06:31:44 +00:00
continue ;
}
goto DO_DEFSTATE ;
2011-04-07 01:16:29 +00:00
case CON_STATE :
2018-12-15 01:36:42 +00:00
if ( ! g_scriptActorOffset & & g_processingState = = 0 )
2011-04-07 01:16:29 +00:00
{
2015-09-24 06:31:44 +00:00
DO_DEFSTATE :
2011-04-07 01:16:29 +00:00
C_GetNextLabelName ( ) ;
g_scriptPtr - - ;
2016-08-27 01:42:01 +00:00
labelcode [ g_labelCnt ] = g_scriptPtr - apScript ;
labeltype [ g_labelCnt ] = LABEL_STATE ;
2006-11-15 01:16:55 +00:00
2011-04-07 01:16:29 +00:00
g_processingState = 1 ;
2018-11-18 18:11:09 +00:00
Bsprintf ( g_szCurrentBlockName , " %s " , LAST_LABEL ) ;
2006-11-15 01:16:55 +00:00
2018-11-18 18:11:09 +00:00
if ( EDUKE32_PREDICT_FALSE ( hash_find ( & h_keywords , LAST_LABEL ) > = 0 ) )
2011-04-07 01:16:29 +00:00
{
2016-08-27 01:42:01 +00:00
g_errorCnt + + ;
2011-04-07 01:16:29 +00:00
C_ReportError ( ERROR_ISAKEYWORD ) ;
continue ;
}
2006-11-15 01:16:55 +00:00
2018-11-18 18:11:09 +00:00
if ( EDUKE32_PREDICT_FALSE ( hash_find ( & h_gamevars , LAST_LABEL ) > = 0 ) )
2011-04-07 01:16:29 +00:00
{
2016-08-27 01:42:01 +00:00
g_warningCnt + + ;
2011-04-07 01:16:29 +00:00
C_ReportError ( WARNING_NAMEMATCHESVAR ) ;
}
2008-08-23 07:32:15 +00:00
2018-11-18 18:11:09 +00:00
hash_add ( & h_labels , LAST_LABEL , g_labelCnt , 0 ) ;
2016-08-27 01:42:01 +00:00
g_labelCnt + + ;
2011-04-07 01:16:29 +00:00
continue ;
}
2008-08-23 07:32:15 +00:00
2011-04-07 01:16:29 +00:00
C_GetNextLabelName ( ) ;
2018-11-18 18:11:09 +00:00
if ( EDUKE32_PREDICT_FALSE ( ( j = hash_find ( & h_labels , LAST_LABEL ) ) < 0 ) )
2008-08-25 00:49:12 +00:00
{
2008-11-20 14:06:36 +00:00
C_ReportError ( - 1 ) ;
2018-11-18 18:11:09 +00:00
initprintf ( " %s:%d: error: state `%s' not found. \n " , g_scriptFileName , g_lineNumber , LAST_LABEL ) ;
2016-08-27 01:42:01 +00:00
g_errorCnt + + ;
2014-10-25 03:36:34 +00:00
g_scriptPtr + + ;
continue ;
}
if ( EDUKE32_PREDICT_FALSE ( ( labeltype [ j ] & LABEL_STATE ) ! = LABEL_STATE ) )
{
char * gl = ( char * ) C_GetLabelType ( labeltype [ j ] ) ;
C_ReportError ( - 1 ) ;
2016-08-27 01:42:01 +00:00
initprintf ( " %s:%d: warning: expected state, found %s. \n " , g_scriptFileName , g_lineNumber , gl ) ;
g_warningCnt + + ;
2014-10-25 03:36:34 +00:00
Bfree ( gl ) ;
2018-12-15 01:36:27 +00:00
scriptWriteAtOffset ( CON_NULLOP , & g_scriptPtr [ - 1 ] ) ; // get rid of the state, leaving a nullop to satisfy if conditions
2014-10-25 03:36:34 +00:00
continue ; // valid label name, but wrong type
2006-04-13 20:47:06 +00:00
}
2014-10-25 03:36:34 +00:00
2018-12-15 01:38:05 +00:00
if ( g_scriptDebug > 1 & & ! g_errorCnt & & ! g_warningCnt )
2016-08-27 01:42:01 +00:00
initprintf ( " %s:%d: debug: state label `%s'. \n " , g_scriptFileName , g_lineNumber , label + ( j < < 6 ) ) ;
2014-10-25 03:36:34 +00:00
// 'state' type labels are always script addresses, as far as I can see
2018-11-18 18:14:20 +00:00
scriptWritePointer ( ( intptr_t ) ( apScript + labelcode [ j ] ) , g_scriptPtr + + ) ;
2011-04-07 01:16:29 +00:00
continue ;
case CON_ENDS :
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_FALSE ( g_processingState = = 0 ) )
2006-04-13 20:47:06 +00:00
{
2011-04-07 01:16:29 +00:00
C_ReportError ( - 1 ) ;
2016-08-27 01:42:01 +00:00
initprintf ( " %s:%d: error: found `ends' without open `state'. \n " , g_scriptFileName , g_lineNumber ) ;
g_errorCnt + + ;
2006-04-13 20:47:06 +00:00
}
2014-10-25 03:36:34 +00:00
2018-11-18 18:10:21 +00:00
if ( EDUKE32_PREDICT_FALSE ( g_numBraces > 0 ) )
{
2018-11-18 18:10:32 +00:00
C_ReportError ( ERROR_NOTTOPLEVEL ) ;
2018-11-18 18:10:21 +00:00
g_errorCnt + + ;
}
2011-04-07 01:16:29 +00:00
2018-11-18 18:10:21 +00:00
if ( EDUKE32_PREDICT_FALSE ( g_checkingSwitch > 0 ) )
{
C_ReportError ( ERROR_NOENDSWITCH ) ;
g_errorCnt + + ;
2006-04-13 20:47:06 +00:00
2018-11-18 18:10:21 +00:00
g_checkingSwitch = 0 ; // can't be checking anymore...
2006-11-15 01:16:55 +00:00
}
2018-11-18 18:10:21 +00:00
g_processingState = 0 ;
Bsprintf ( g_szCurrentBlockName , " (none) " ) ;
2011-04-07 01:16:29 +00:00
continue ;
2006-11-16 03:02:42 +00:00
2011-04-07 01:16:29 +00:00
case CON_GETPROJECTILE :
2018-11-18 18:10:21 +00:00
case CON_GETTHISPROJECTILE :
case CON_SETPROJECTILE :
case CON_SETTHISPROJECTILE :
2011-04-07 01:16:29 +00:00
{
2018-11-18 18:10:21 +00:00
int const labelNum = C_GetStructureIndexes ( tw = = CON_SETTHISPROJECTILE | | tw = = CON_GETTHISPROJECTILE , & h_projectile ) ;
2006-11-16 03:02:42 +00:00
2016-08-27 01:40:35 +00:00
if ( labelNum = = - 1 )
2011-04-07 01:16:29 +00:00
continue ;
2006-04-13 20:47:06 +00:00
2018-11-18 18:14:20 +00:00
scriptWriteValue ( ProjectileLabels [ labelNum ] . lId ) ;
2006-04-13 20:47:06 +00:00
2011-04-07 01:16:29 +00:00
switch ( tw )
{
case CON_SETPROJECTILE :
case CON_SETTHISPROJECTILE :
C_GetNextVar ( ) ;
break ;
default :
C_GetNextVarType ( GAMEVAR_READONLY ) ;
break ;
}
2011-05-20 02:34:41 +00:00
continue ;
2011-04-07 01:16:29 +00:00
}
2006-11-16 03:02:42 +00:00
2011-04-07 01:16:29 +00:00
case CON_GAMEVAR :
Syntax changes for gamevar and gamearray declarations:
Gamevar: default value and flags are now optional. A var declared without a value will default to 0 and a var declared without flags will default to global. Multiple flags can now be stacked one after another in a var declaration, and the most useful ones (GAMEVAR_PERPLAYER, GAMEVAR_PERACTOR, GAMEVAR_NODEFAULT, and GAMEVAR_NORESET) are now pre-defined tokens for easy use.
Gamearray: flags field now allows stacking of multiple flags as described above. Arrays can now be defined with specific data types, including int16_t, uint8_t, and a new bit-packed boolean data type. The tokens GAMEARRAY_RESTORE, GAMEARRAY_INT16, GAMEARRAY_UINT8, and GAMEARRAY_BOOLEAN are pre-defined for use of this feature.
This is all still pretty experimental.
git-svn-id: https://svn.eduke32.com/eduke32@6356 1a8010ca-5511-0410-912e-c29ae57300e0
2017-07-11 04:02:52 +00:00
{
2011-04-07 01:16:29 +00:00
// syntax: gamevar <var1> <initial value> <flags>
// defines var1 and sets initial value.
// flags are used to define usage
// (see top of this files for flags)
2006-04-13 20:47:06 +00:00
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_FALSE ( isdigit ( * textptr ) | | ( * textptr = = ' - ' ) ) )
2011-04-07 01:16:29 +00:00
{
2016-08-27 01:42:01 +00:00
g_errorCnt + + ;
2011-04-07 01:16:29 +00:00
C_ReportError ( ERROR_SYNTAXERROR ) ;
2018-12-15 01:36:42 +00:00
scriptSkipLine ( ) ;
2011-04-07 01:16:29 +00:00
continue ;
}
2006-11-16 03:02:42 +00:00
Syntax changes for gamevar and gamearray declarations:
Gamevar: default value and flags are now optional. A var declared without a value will default to 0 and a var declared without flags will default to global. Multiple flags can now be stacked one after another in a var declaration, and the most useful ones (GAMEVAR_PERPLAYER, GAMEVAR_PERACTOR, GAMEVAR_NODEFAULT, and GAMEVAR_NORESET) are now pre-defined tokens for easy use.
Gamearray: flags field now allows stacking of multiple flags as described above. Arrays can now be defined with specific data types, including int16_t, uint8_t, and a new bit-packed boolean data type. The tokens GAMEARRAY_RESTORE, GAMEARRAY_INT16, GAMEARRAY_UINT8, and GAMEARRAY_BOOLEAN are pre-defined for use of this feature.
This is all still pretty experimental.
git-svn-id: https://svn.eduke32.com/eduke32@6356 1a8010ca-5511-0410-912e-c29ae57300e0
2017-07-11 04:02:52 +00:00
g_scriptPtr - - ;
2008-11-20 14:06:36 +00:00
C_GetNextLabelName ( ) ;
2006-04-13 20:47:06 +00:00
2018-11-18 18:11:09 +00:00
if ( EDUKE32_PREDICT_FALSE ( hash_find ( & h_keywords , LAST_LABEL ) > = 0 ) )
2008-09-01 07:15:16 +00:00
{
2016-08-27 01:42:01 +00:00
g_warningCnt + + ;
Adds the following keywords from M32script into CON: shiftvarvarl, shiftvarvarr, ifvarvarle, ifvarvarge, ifvarvarboth, whilevarl, and whilevarvarl.
This also adds the shorthand versions of some commands, like "set" for "setvarvar", "add" for "addvarvar", "ife" for "ifvarvare", etc. There are about 30 of these. Because some of these names may already be used in some projects as variable names, this revision also includes a somewhat large change in variable naming rules: gamevars may now have the same names as CON keywords, with the caveat that the masked keyword is no longer accessible. This results in a warning at compile time but should ensure nobody's project ever stops compiling due to the introduction of new keywords.
git-svn-id: https://svn.eduke32.com/eduke32@5499 1a8010ca-5511-0410-912e-c29ae57300e0
2016-01-02 01:56:20 +00:00
C_ReportError ( WARNING_VARMASKSKEYWORD ) ;
2018-11-18 18:11:09 +00:00
hash_delete ( & h_keywords , LAST_LABEL ) ;
2008-09-01 07:15:16 +00:00
}
2006-11-16 03:02:42 +00:00
Syntax changes for gamevar and gamearray declarations:
Gamevar: default value and flags are now optional. A var declared without a value will default to 0 and a var declared without flags will default to global. Multiple flags can now be stacked one after another in a var declaration, and the most useful ones (GAMEVAR_PERPLAYER, GAMEVAR_PERACTOR, GAMEVAR_NODEFAULT, and GAMEVAR_NORESET) are now pre-defined tokens for easy use.
Gamearray: flags field now allows stacking of multiple flags as described above. Arrays can now be defined with specific data types, including int16_t, uint8_t, and a new bit-packed boolean data type. The tokens GAMEARRAY_RESTORE, GAMEARRAY_INT16, GAMEARRAY_UINT8, and GAMEARRAY_BOOLEAN are pre-defined for use of this feature.
This is all still pretty experimental.
git-svn-id: https://svn.eduke32.com/eduke32@6356 1a8010ca-5511-0410-912e-c29ae57300e0
2017-07-11 04:02:52 +00:00
int32_t defaultValue = 0 ;
int32_t varFlags = 0 ;
2016-01-03 20:07:27 +00:00
Syntax changes for gamevar and gamearray declarations:
Gamevar: default value and flags are now optional. A var declared without a value will default to 0 and a var declared without flags will default to global. Multiple flags can now be stacked one after another in a var declaration, and the most useful ones (GAMEVAR_PERPLAYER, GAMEVAR_PERACTOR, GAMEVAR_NODEFAULT, and GAMEVAR_NORESET) are now pre-defined tokens for easy use.
Gamearray: flags field now allows stacking of multiple flags as described above. Arrays can now be defined with specific data types, including int16_t, uint8_t, and a new bit-packed boolean data type. The tokens GAMEARRAY_RESTORE, GAMEARRAY_INT16, GAMEARRAY_UINT8, and GAMEARRAY_BOOLEAN are pre-defined for use of this feature.
This is all still pretty experimental.
git-svn-id: https://svn.eduke32.com/eduke32@6356 1a8010ca-5511-0410-912e-c29ae57300e0
2017-07-11 04:02:52 +00:00
if ( C_GetKeyword ( ) = = - 1 )
2006-11-16 03:02:42 +00:00
{
Syntax changes for gamevar and gamearray declarations:
Gamevar: default value and flags are now optional. A var declared without a value will default to 0 and a var declared without flags will default to global. Multiple flags can now be stacked one after another in a var declaration, and the most useful ones (GAMEVAR_PERPLAYER, GAMEVAR_PERACTOR, GAMEVAR_NODEFAULT, and GAMEVAR_NORESET) are now pre-defined tokens for easy use.
Gamearray: flags field now allows stacking of multiple flags as described above. Arrays can now be defined with specific data types, including int16_t, uint8_t, and a new bit-packed boolean data type. The tokens GAMEARRAY_RESTORE, GAMEARRAY_INT16, GAMEARRAY_UINT8, and GAMEARRAY_BOOLEAN are pre-defined for use of this feature.
This is all still pretty experimental.
git-svn-id: https://svn.eduke32.com/eduke32@6356 1a8010ca-5511-0410-912e-c29ae57300e0
2017-07-11 04:02:52 +00:00
C_GetNextValue ( LABEL_DEFINE ) ; // get initial value
defaultValue = * ( - - g_scriptPtr ) ;
j = 0 ;
while ( C_GetKeyword ( ) = = - 1 )
C_BitOrNextValue ( & j ) ;
C_FinishBitOr ( j ) ;
varFlags = * ( - - g_scriptPtr ) ;
if ( EDUKE32_PREDICT_FALSE ( ( * ( g_scriptPtr ) & GAMEVAR_USER_MASK ) = = ( GAMEVAR_PERPLAYER | GAMEVAR_PERACTOR ) ) )
{
g_warningCnt + + ;
varFlags ^ = GAMEVAR_PERPLAYER ;
C_ReportError ( WARNING_BADGAMEVAR ) ;
}
2006-11-16 03:02:42 +00:00
}
2016-01-03 20:07:27 +00:00
2018-11-18 18:11:09 +00:00
Gv_NewVar ( LAST_LABEL , defaultValue , varFlags ) ;
2011-04-07 01:16:29 +00:00
continue ;
Syntax changes for gamevar and gamearray declarations:
Gamevar: default value and flags are now optional. A var declared without a value will default to 0 and a var declared without flags will default to global. Multiple flags can now be stacked one after another in a var declaration, and the most useful ones (GAMEVAR_PERPLAYER, GAMEVAR_PERACTOR, GAMEVAR_NODEFAULT, and GAMEVAR_NORESET) are now pre-defined tokens for easy use.
Gamearray: flags field now allows stacking of multiple flags as described above. Arrays can now be defined with specific data types, including int16_t, uint8_t, and a new bit-packed boolean data type. The tokens GAMEARRAY_RESTORE, GAMEARRAY_INT16, GAMEARRAY_UINT8, and GAMEARRAY_BOOLEAN are pre-defined for use of this feature.
This is all still pretty experimental.
git-svn-id: https://svn.eduke32.com/eduke32@6356 1a8010ca-5511-0410-912e-c29ae57300e0
2017-07-11 04:02:52 +00:00
}
2006-04-13 20:47:06 +00:00
2011-04-07 01:16:29 +00:00
case CON_GAMEARRAY :
2016-09-10 05:21:01 +00:00
{
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_FALSE ( isdigit ( * textptr ) | | ( * textptr = = ' - ' ) ) )
2006-11-16 03:02:42 +00:00
{
2016-08-27 01:42:01 +00:00
g_errorCnt + + ;
2011-04-07 01:16:29 +00:00
C_ReportError ( ERROR_SYNTAXERROR ) ;
2018-12-15 01:36:42 +00:00
scriptSkipLine ( ) ;
2011-04-07 01:16:29 +00:00
continue ;
2006-11-16 03:02:42 +00:00
}
2008-11-20 14:06:36 +00:00
C_GetNextLabelName ( ) ;
2006-04-13 20:47:06 +00:00
2018-11-18 18:11:09 +00:00
if ( EDUKE32_PREDICT_FALSE ( hash_find ( & h_keywords , LAST_LABEL ) > = 0 ) )
2008-08-25 00:49:12 +00:00
{
2016-08-27 01:42:01 +00:00
g_warningCnt + + ;
Adds the following keywords from M32script into CON: shiftvarvarl, shiftvarvarr, ifvarvarle, ifvarvarge, ifvarvarboth, whilevarl, and whilevarvarl.
This also adds the shorthand versions of some commands, like "set" for "setvarvar", "add" for "addvarvar", "ife" for "ifvarvare", etc. There are about 30 of these. Because some of these names may already be used in some projects as variable names, this revision also includes a somewhat large change in variable naming rules: gamevars may now have the same names as CON keywords, with the caveat that the masked keyword is no longer accessible. This results in a warning at compile time but should ensure nobody's project ever stops compiling due to the introduction of new keywords.
git-svn-id: https://svn.eduke32.com/eduke32@5499 1a8010ca-5511-0410-912e-c29ae57300e0
2016-01-02 01:56:20 +00:00
C_ReportError ( WARNING_ARRAYMASKSKEYWORD ) ;
2018-11-18 18:11:09 +00:00
hash_delete ( & h_keywords , LAST_LABEL ) ;
2008-08-25 00:49:12 +00:00
}
2006-04-13 20:47:06 +00:00
2018-11-18 18:11:09 +00:00
i = hash_find ( & h_gamevars , LAST_LABEL ) ;
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_FALSE ( i > = 0 ) )
2008-08-23 07:32:15 +00:00
{
2016-08-27 01:42:01 +00:00
g_warningCnt + + ;
2008-11-20 14:06:36 +00:00
C_ReportError ( WARNING_NAMEMATCHESVAR ) ;
2008-08-23 07:32:15 +00:00
}
2011-04-07 01:16:29 +00:00
C_GetNextValue ( LABEL_DEFINE ) ;
2016-09-10 05:21:01 +00:00
2018-11-18 18:11:09 +00:00
char const * const arrayName = LAST_LABEL ;
2017-07-15 21:56:21 +00:00
int32_t arrayFlags = 0 ;
2016-09-10 05:21:01 +00:00
Syntax changes for gamevar and gamearray declarations:
Gamevar: default value and flags are now optional. A var declared without a value will default to 0 and a var declared without flags will default to global. Multiple flags can now be stacked one after another in a var declaration, and the most useful ones (GAMEVAR_PERPLAYER, GAMEVAR_PERACTOR, GAMEVAR_NODEFAULT, and GAMEVAR_NORESET) are now pre-defined tokens for easy use.
Gamearray: flags field now allows stacking of multiple flags as described above. Arrays can now be defined with specific data types, including int16_t, uint8_t, and a new bit-packed boolean data type. The tokens GAMEARRAY_RESTORE, GAMEARRAY_INT16, GAMEARRAY_UINT8, and GAMEARRAY_BOOLEAN are pre-defined for use of this feature.
This is all still pretty experimental.
git-svn-id: https://svn.eduke32.com/eduke32@6356 1a8010ca-5511-0410-912e-c29ae57300e0
2017-07-11 04:02:52 +00:00
while ( C_GetKeyword ( ) = = - 1 )
C_BitOrNextValue ( & arrayFlags ) ;
C_FinishBitOr ( arrayFlags ) ;
2018-12-15 01:36:27 +00:00
arrayFlags = g_scriptPtr [ - 1 ] ;
Syntax changes for gamevar and gamearray declarations:
Gamevar: default value and flags are now optional. A var declared without a value will default to 0 and a var declared without flags will default to global. Multiple flags can now be stacked one after another in a var declaration, and the most useful ones (GAMEVAR_PERPLAYER, GAMEVAR_PERACTOR, GAMEVAR_NODEFAULT, and GAMEVAR_NORESET) are now pre-defined tokens for easy use.
Gamearray: flags field now allows stacking of multiple flags as described above. Arrays can now be defined with specific data types, including int16_t, uint8_t, and a new bit-packed boolean data type. The tokens GAMEARRAY_RESTORE, GAMEARRAY_INT16, GAMEARRAY_UINT8, and GAMEARRAY_BOOLEAN are pre-defined for use of this feature.
This is all still pretty experimental.
git-svn-id: https://svn.eduke32.com/eduke32@6356 1a8010ca-5511-0410-912e-c29ae57300e0
2017-07-11 04:02:52 +00:00
g_scriptPtr - - ;
2016-09-10 05:21:01 +00:00
2018-12-15 01:36:27 +00:00
Gv_NewArray ( arrayName , NULL , g_scriptPtr [ - 1 ] , arrayFlags ) ;
2011-04-07 01:16:29 +00:00
g_scriptPtr - = 2 ; // no need to save in script...
continue ;
2016-09-10 05:21:01 +00:00
}
2011-04-07 01:16:29 +00:00
case CON_DEFINE :
2006-04-13 20:47:06 +00:00
{
2011-04-07 01:16:29 +00:00
C_GetNextLabelName ( ) ;
2018-11-18 18:11:09 +00:00
if ( EDUKE32_PREDICT_FALSE ( hash_find ( & h_keywords , LAST_LABEL ) > = 0 ) )
2011-04-07 01:16:29 +00:00
{
2016-08-27 01:42:01 +00:00
g_errorCnt + + ;
2011-04-07 01:16:29 +00:00
C_ReportError ( ERROR_ISAKEYWORD ) ;
continue ;
}
2018-11-18 18:11:09 +00:00
i = hash_find ( & h_gamevars , LAST_LABEL ) ;
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_FALSE ( i > = 0 ) )
2011-04-07 01:16:29 +00:00
{
2016-08-27 01:42:01 +00:00
g_warningCnt + + ;
2011-04-07 01:16:29 +00:00
C_ReportError ( WARNING_NAMEMATCHESVAR ) ;
}
2012-06-10 18:56:27 +00:00
C_GetNextValue ( LABEL_DEFINE ) ;
2018-11-18 18:11:09 +00:00
i = hash_find ( & h_labels , LAST_LABEL ) ;
2011-04-07 01:16:29 +00:00
if ( i > = 0 )
{
2012-06-10 18:56:27 +00:00
// if (i >= g_numDefaultLabels)
2018-12-15 01:36:27 +00:00
if ( EDUKE32_PREDICT_FALSE ( labelcode [ i ] ! = g_scriptPtr [ - 1 ] ) )
2011-04-07 01:16:29 +00:00
{
2016-08-27 01:42:01 +00:00
g_warningCnt + + ;
initprintf ( " %s:%d: warning: ignored redefinition of `%s' to %d (old: %d). \n " , g_scriptFileName ,
2018-12-15 01:36:27 +00:00
g_lineNumber , LAST_LABEL , ( int32_t ) ( g_scriptPtr [ - 1 ] ) , labelcode [ i ] ) ;
2012-06-10 18:56:27 +00:00
}
2011-04-07 01:16:29 +00:00
}
2012-06-10 18:56:27 +00:00
else
2011-04-07 01:16:29 +00:00
{
2018-11-18 18:11:09 +00:00
hash_add ( & h_labels , LAST_LABEL , g_labelCnt , 0 ) ;
2016-08-27 01:42:01 +00:00
labeltype [ g_labelCnt ] = LABEL_DEFINE ;
2018-12-15 01:36:27 +00:00
labelcode [ g_labelCnt + + ] = g_scriptPtr [ - 1 ] ;
if ( g_scriptPtr [ - 1 ] > = 0 & & g_scriptPtr [ - 1 ] < MAXTILES & & g_dynamicTileMapping )
G_ProcessDynamicTileMapping ( label + ( ( g_labelCnt - 1 ) < < 6 ) , g_scriptPtr [ - 1 ] ) ;
2011-04-07 01:16:29 +00:00
}
g_scriptPtr - = 2 ;
continue ;
2006-04-13 20:47:06 +00:00
}
2009-05-28 02:55:46 +00:00
2011-04-07 01:16:29 +00:00
case CON_PALFROM :
for ( j = 3 ; j > = 0 ; j - - )
2006-04-13 20:47:06 +00:00
{
2011-04-07 01:16:29 +00:00
if ( C_GetKeyword ( ) = = - 1 )
C_GetNextValue ( LABEL_DEFINE ) ;
else break ;
2006-04-13 20:47:06 +00:00
}
2009-05-28 02:55:46 +00:00
2011-04-07 01:16:29 +00:00
while ( j > - 1 )
2006-04-13 20:47:06 +00:00
{
2018-11-18 18:14:20 +00:00
scriptWriteValue ( 0 ) ;
2011-04-07 01:16:29 +00:00
j - - ;
2006-04-13 20:47:06 +00:00
}
2011-04-07 01:16:29 +00:00
continue ;
2006-11-16 03:02:42 +00:00
2011-04-07 01:16:29 +00:00
case CON_MOVE :
2018-12-15 01:36:42 +00:00
if ( g_scriptActorOffset | | g_processingState )
2006-11-16 03:02:42 +00:00
{
2018-12-15 01:36:27 +00:00
if ( EDUKE32_PREDICT_FALSE ( ( C_GetNextValue ( LABEL_MOVE | LABEL_DEFINE ) = = 0 ) & & ( g_scriptPtr [ - 1 ] ! = 0 ) & & ( g_scriptPtr [ - 1 ] ! = 1 ) ) )
2006-04-13 20:47:06 +00:00
{
2011-04-07 01:16:29 +00:00
C_ReportError ( - 1 ) ;
2018-12-15 01:36:27 +00:00
scriptWriteAtOffset ( 0 , & g_scriptPtr [ - 1 ] ) ;
2016-08-27 01:42:01 +00:00
initprintf ( " %s:%d: warning: expected a move, found a constant. \n " , g_scriptFileName , g_lineNumber ) ;
g_warningCnt + + ;
2006-04-13 20:47:06 +00:00
}
2006-12-12 07:25:01 +00:00
2011-04-07 01:16:29 +00:00
j = 0 ;
while ( C_GetKeyword ( ) = = - 1 )
2014-12-26 17:29:57 +00:00
C_BitOrNextValue ( & j ) ;
2006-12-05 21:22:19 +00:00
2014-12-26 17:29:57 +00:00
C_FinishBitOr ( j ) ;
2006-04-13 20:47:06 +00:00
}
2011-04-07 01:16:29 +00:00
else
2006-04-13 20:47:06 +00:00
{
2011-04-07 01:16:29 +00:00
g_scriptPtr - - ;
C_GetNextLabelName ( ) ;
// Check to see it's already defined
2006-12-04 22:05:30 +00:00
2018-11-18 18:11:09 +00:00
if ( EDUKE32_PREDICT_FALSE ( hash_find ( & h_keywords , LAST_LABEL ) > = 0 ) )
2006-11-15 01:16:55 +00:00
{
2016-08-27 01:42:01 +00:00
g_errorCnt + + ;
2011-04-07 01:16:29 +00:00
C_ReportError ( ERROR_ISAKEYWORD ) ;
continue ;
2006-04-13 20:47:06 +00:00
}
2018-11-18 18:11:09 +00:00
if ( EDUKE32_PREDICT_FALSE ( hash_find ( & h_gamevars , LAST_LABEL ) > = 0 ) )
2011-04-07 01:16:29 +00:00
{
2016-08-27 01:42:01 +00:00
g_warningCnt + + ;
2011-04-07 01:16:29 +00:00
C_ReportError ( WARNING_NAMEMATCHESVAR ) ;
}
2009-11-18 01:17:56 +00:00
2018-11-18 18:11:09 +00:00
if ( EDUKE32_PREDICT_FALSE ( ( i = hash_find ( & h_labels , LAST_LABEL ) ) > = 0 ) )
2011-04-07 01:16:29 +00:00
{
2016-08-27 01:42:01 +00:00
g_warningCnt + + ;
2018-11-18 18:11:09 +00:00
initprintf ( " %s:%d: warning: duplicate move `%s' ignored. \n " , g_scriptFileName , g_lineNumber , LAST_LABEL ) ;
2011-04-07 01:16:29 +00:00
}
2012-05-25 18:39:22 +00:00
else
2011-04-07 01:16:29 +00:00
{
2018-11-18 18:11:09 +00:00
hash_add ( & h_labels , LAST_LABEL , g_labelCnt , 0 ) ;
2016-08-27 01:42:01 +00:00
labeltype [ g_labelCnt ] = LABEL_MOVE ;
labelcode [ g_labelCnt + + ] = g_scriptPtr - apScript ;
2011-04-07 01:16:29 +00:00
}
2006-08-17 23:07:43 +00:00
2011-04-07 01:16:29 +00:00
for ( j = 1 ; j > = 0 ; j - - )
{
if ( C_GetKeyword ( ) ! = - 1 ) break ;
C_GetNextValue ( LABEL_DEFINE ) ;
}
2006-04-13 20:47:06 +00:00
2011-04-07 01:16:29 +00:00
for ( k = j ; k > = 0 ; k - - )
{
2018-11-18 18:14:20 +00:00
scriptWriteValue ( 0 ) ;
2011-04-07 01:16:29 +00:00
}
2006-04-13 20:47:06 +00:00
}
2011-04-07 01:16:29 +00:00
continue ;
2006-11-15 01:16:55 +00:00
2011-04-07 01:16:29 +00:00
case CON_MUSIC :
2006-04-13 20:47:06 +00:00
{
2011-04-07 01:16:29 +00:00
// NOTE: this doesn't get stored in the PCode...
2006-04-13 20:47:06 +00:00
2011-04-07 01:16:29 +00:00
// music 1 stalker.mid dethtoll.mid streets.mid watrwld1.mid snake1.mid
// thecall.mid ahgeez.mid dethtoll.mid streets.mid watrwld1.mid snake1.mid
g_scriptPtr - - ;
C_GetNextValue ( LABEL_DEFINE ) ; // Volume Number (0/4)
g_scriptPtr - - ;
2006-04-13 20:47:06 +00:00
2014-09-07 18:10:14 +00:00
k = * g_scriptPtr - 1 ; // 0-based volume number. -1 or MAXVOLUMES: "special"
if ( k = = - 1 )
k = MAXVOLUMES ;
2009-11-18 01:17:56 +00:00
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_FALSE ( ( unsigned ) k > = MAXVOLUMES + 1 ) ) // if it's not background or special music
2011-04-07 01:16:29 +00:00
{
2016-08-27 01:42:01 +00:00
g_errorCnt + + ;
2014-09-07 18:10:14 +00:00
C_ReportError ( - 1 ) ;
initprintf ( " %s:%d: error: volume number must be between 0 and MAXVOLUMES+1=%d. \n " ,
2016-08-27 01:42:01 +00:00
g_scriptFileName , g_lineNumber , MAXVOLUMES + 1 ) ;
2014-10-25 03:36:34 +00:00
continue ;
2011-04-07 01:16:29 +00:00
}
2014-09-07 18:10:14 +00:00
2014-10-25 03:36:34 +00:00
i = 0 ;
// get the file name...
while ( C_GetKeyword ( ) = = - 1 )
{
C_SkipComments ( ) ;
j = 0 ;
tempbuf [ j ] = ' / ' ;
while ( isaltok ( * ( textptr + j ) ) )
{
tempbuf [ j + 1 ] = textptr [ j ] ;
j + + ;
}
tempbuf [ j + 1 ] = ' \0 ' ;
C_DefineMusic ( k , i , tempbuf ) ;
textptr + = j ;
if ( i > = MAXLEVELS )
break ;
i + + ;
}
2008-09-01 07:15:16 +00:00
}
2011-04-07 01:16:29 +00:00
continue ;
case CON_INCLUDE :
2008-11-20 14:06:36 +00:00
g_scriptPtr - - ;
2006-11-15 01:16:55 +00:00
2011-04-07 01:16:29 +00:00
C_SkipComments ( ) ;
2006-11-15 01:16:55 +00:00
2011-04-07 01:16:29 +00:00
j = 0 ;
while ( isaltok ( * textptr ) )
2008-08-23 07:32:15 +00:00
{
2011-04-07 01:16:29 +00:00
tempbuf [ j ] = * ( textptr + + ) ;
j + + ;
2008-08-23 07:32:15 +00:00
}
2011-04-07 01:16:29 +00:00
tempbuf [ j ] = ' \0 ' ;
2008-08-23 07:32:15 +00:00
2011-07-21 22:39:29 +00:00
C_Include ( tempbuf ) ;
Patch from Hendricks266 and whatever changes happened to be in my tree. I hope they work ;)
"The most noticeable change is the addition of the "includedefault" CON and DEF command, which will attempt to include eduke.con (or nam.con, or ww2gi.con), then game.con, or duke3d.def, or nam.def, or ww2gi.def. This is useful for TCs like my add-ons, where for my pseudo-mutators I currently say "include EDUKE.CON", but I also have to juggle this terrible order of paths, so that I can have an EDUKE.CON file in my HRP which says "include GAME.CON" to allow the mainline game to actually run, but also allow DukePlus to load its EDUKE.CON file (since it uses that and not an -x switch), and also allow any custom EDUKE.CON files in the root to be used."
git-svn-id: https://svn.eduke32.com/eduke32@1909 1a8010ca-5511-0410-912e-c29ae57300e0
2011-06-19 00:11:52 +00:00
continue ;
case CON_INCLUDEDEFAULT :
C_SkipComments ( ) ;
2012-06-03 16:09:33 +00:00
C_Include ( G_DefaultConFile ( ) ) ;
2011-04-07 01:16:29 +00:00
continue ;
case CON_AI :
2018-12-15 01:36:42 +00:00
if ( g_scriptActorOffset | | g_processingState )
2011-04-07 01:16:29 +00:00
{
C_GetNextValue ( LABEL_AI ) ;
}
else
{
g_scriptPtr - - ;
C_GetNextLabelName ( ) ;
2018-11-18 18:11:09 +00:00
if ( EDUKE32_PREDICT_FALSE ( hash_find ( & h_keywords , LAST_LABEL ) > = 0 ) )
2011-04-07 01:16:29 +00:00
{
2016-08-27 01:42:01 +00:00
g_errorCnt + + ;
2011-04-07 01:16:29 +00:00
C_ReportError ( ERROR_ISAKEYWORD ) ;
continue ;
}
2018-11-18 18:11:09 +00:00
i = hash_find ( & h_gamevars , LAST_LABEL ) ;
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_FALSE ( i > = 0 ) )
2011-04-07 01:16:29 +00:00
{
2016-08-27 01:42:01 +00:00
g_warningCnt + + ;
2011-04-07 01:16:29 +00:00
C_ReportError ( WARNING_NAMEMATCHESVAR ) ;
}
2018-11-18 18:11:09 +00:00
i = hash_find ( & h_labels , LAST_LABEL ) ;
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_FALSE ( i > = 0 ) )
2011-04-07 01:16:29 +00:00
{
2016-08-27 01:42:01 +00:00
g_warningCnt + + ;
2018-11-18 18:11:09 +00:00
initprintf ( " %s:%d: warning: duplicate ai `%s' ignored. \n " , g_scriptFileName , g_lineNumber , LAST_LABEL ) ;
2011-04-07 01:16:29 +00:00
}
2012-05-25 18:39:22 +00:00
else
2011-04-07 01:16:29 +00:00
{
2016-08-27 01:42:01 +00:00
labeltype [ g_labelCnt ] = LABEL_AI ;
2018-11-18 18:11:09 +00:00
hash_add ( & h_labels , LAST_LABEL , g_labelCnt , 0 ) ;
2016-08-27 01:42:01 +00:00
labelcode [ g_labelCnt + + ] = g_scriptPtr - apScript ;
2011-04-07 01:16:29 +00:00
}
for ( j = 0 ; j < 3 ; j + + )
{
if ( C_GetKeyword ( ) ! = - 1 ) break ;
if ( j = = 1 )
C_GetNextValue ( LABEL_ACTION ) ;
else if ( j = = 2 )
2006-11-15 01:16:55 +00:00
{
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_FALSE ( ( C_GetNextValue ( LABEL_MOVE | LABEL_DEFINE ) = = 0 ) & &
2018-12-15 01:36:27 +00:00
( g_scriptPtr [ - 1 ] ! = 0 ) & & ( g_scriptPtr [ - 1 ] ! = 1 ) ) )
2011-04-07 01:16:29 +00:00
{
C_ReportError ( - 1 ) ;
2018-12-15 01:36:27 +00:00
scriptWriteAtOffset ( 0 , & g_scriptPtr [ - 1 ] ) ;
2016-08-27 01:42:01 +00:00
initprintf ( " %s:%d: warning: expected a move, found a constant. \n " , g_scriptFileName , g_lineNumber ) ;
g_warningCnt + + ;
2011-04-07 01:16:29 +00:00
}
2014-12-26 17:29:57 +00:00
2011-04-07 01:16:29 +00:00
k = 0 ;
while ( C_GetKeyword ( ) = = - 1 )
2014-12-26 17:29:57 +00:00
C_BitOrNextValue ( & k ) ;
C_FinishBitOr ( k ) ;
2011-05-20 02:34:41 +00:00
j = 666 ;
break ;
2006-11-15 01:16:55 +00:00
}
2011-04-07 01:16:29 +00:00
}
2011-05-20 02:34:41 +00:00
if ( j = = 666 )
continue ;
2011-04-07 01:16:29 +00:00
for ( k = j ; k < 3 ; k + + )
{
2018-11-18 18:14:20 +00:00
scriptWriteValue ( 0 ) ;
2006-11-15 01:16:55 +00:00
}
}
2011-04-07 01:16:29 +00:00
continue ;
case CON_ACTION :
2018-12-15 01:36:42 +00:00
if ( g_scriptActorOffset | | g_processingState )
2006-11-15 01:16:55 +00:00
{
2011-04-07 01:16:29 +00:00
C_GetNextValue ( LABEL_ACTION ) ;
2006-11-15 01:16:55 +00:00
}
2011-04-07 01:16:29 +00:00
else
2008-09-01 07:15:16 +00:00
{
2011-04-07 01:16:29 +00:00
g_scriptPtr - - ;
C_GetNextLabelName ( ) ;
// Check to see it's already defined
2018-11-18 18:11:09 +00:00
if ( EDUKE32_PREDICT_FALSE ( hash_find ( & h_keywords , LAST_LABEL ) > = 0 ) )
2011-04-07 01:16:29 +00:00
{
2016-08-27 01:42:01 +00:00
g_errorCnt + + ;
2011-04-07 01:16:29 +00:00
C_ReportError ( ERROR_ISAKEYWORD ) ;
continue ;
}
2018-11-18 18:11:09 +00:00
i = hash_find ( & h_gamevars , LAST_LABEL ) ;
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_FALSE ( i > = 0 ) )
2011-04-07 01:16:29 +00:00
{
2016-08-27 01:42:01 +00:00
g_warningCnt + + ;
2011-04-07 01:16:29 +00:00
C_ReportError ( WARNING_NAMEMATCHESVAR ) ;
}
2018-11-18 18:11:09 +00:00
i = hash_find ( & h_labels , LAST_LABEL ) ;
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_FALSE ( i > = 0 ) )
2011-04-07 01:16:29 +00:00
{
2016-08-27 01:42:01 +00:00
g_warningCnt + + ;
2018-11-18 18:11:09 +00:00
initprintf ( " %s:%d: warning: duplicate action `%s' ignored. \n " , g_scriptFileName , g_lineNumber , LAST_LABEL ) ;
2011-04-07 01:16:29 +00:00
}
2012-05-25 18:39:22 +00:00
else
2011-04-07 01:16:29 +00:00
{
2016-08-27 01:42:01 +00:00
labeltype [ g_labelCnt ] = LABEL_ACTION ;
labelcode [ g_labelCnt ] = g_scriptPtr - apScript ;
2018-11-18 18:11:09 +00:00
hash_add ( & h_labels , LAST_LABEL , g_labelCnt , 0 ) ;
2016-08-27 01:42:01 +00:00
g_labelCnt + + ;
2011-04-07 01:16:29 +00:00
}
2016-09-06 02:15:23 +00:00
for ( j = ACTION_PARAM_COUNT - 1 ; j > = 0 ; j - - )
2011-04-07 01:16:29 +00:00
{
if ( C_GetKeyword ( ) ! = - 1 ) break ;
C_GetNextValue ( LABEL_DEFINE ) ;
}
for ( k = j ; k > = 0 ; k - - )
{
2018-11-18 18:14:20 +00:00
scriptWriteValue ( 0 ) ;
2011-04-07 01:16:29 +00:00
}
2008-09-01 07:15:16 +00:00
}
2011-04-07 01:16:29 +00:00
continue ;
2006-04-13 20:47:06 +00:00
2011-04-07 01:16:29 +00:00
case CON_ACTOR :
case CON_USERACTOR :
case CON_EVENTLOADACTOR :
2018-12-15 01:36:42 +00:00
if ( EDUKE32_PREDICT_FALSE ( g_processingState | | g_scriptActorOffset ) )
2008-08-25 00:49:12 +00:00
{
2011-04-07 01:16:29 +00:00
C_ReportError ( ERROR_FOUNDWITHIN ) ;
2016-08-27 01:42:01 +00:00
g_errorCnt + + ;
2008-08-25 00:49:12 +00:00
}
2008-08-23 07:32:15 +00:00
2011-04-07 01:16:29 +00:00
g_numBraces = 0 ;
g_scriptPtr - - ;
2018-12-15 01:36:42 +00:00
g_scriptActorOffset = g_scriptPtr - apScript ;
2008-08-23 07:32:15 +00:00
2011-04-07 01:16:29 +00:00
if ( tw = = CON_USERACTOR )
2008-08-25 00:49:12 +00:00
{
2011-04-07 01:16:29 +00:00
C_GetNextValue ( LABEL_DEFINE ) ;
g_scriptPtr - - ;
2008-08-25 00:49:12 +00:00
}
2006-11-16 03:02:42 +00:00
2012-04-07 20:09:44 +00:00
// save the actor name w/o consuming it
2011-04-07 01:16:29 +00:00
C_SkipComments ( ) ;
j = 0 ;
while ( isaltok ( * ( textptr + j ) ) )
2006-11-16 03:02:42 +00:00
{
2011-04-07 01:16:29 +00:00
g_szCurrentBlockName [ j ] = textptr [ j ] ;
j + + ;
2006-11-15 01:16:55 +00:00
}
2011-04-07 01:16:29 +00:00
g_szCurrentBlockName [ j ] = 0 ;
2006-04-13 20:47:06 +00:00
2018-03-08 02:39:21 +00:00
j = hash_find ( & h_labels , g_szCurrentBlockName ) ;
if ( j ! = - 1 )
labeltype [ j ] | = LABEL_ACTOR ;
2011-04-07 01:16:29 +00:00
if ( tw = = CON_USERACTOR )
2006-11-15 01:16:55 +00:00
{
2011-07-20 22:08:05 +00:00
j = * g_scriptPtr ;
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_FALSE ( j > 6 | | ( j & 3 ) = = 3 ) )
2011-07-20 22:08:05 +00:00
{
C_ReportError ( - 1 ) ;
initprintf ( " %s:%d: warning: invalid useractor type. Must be 0, 1, 2 "
2012-04-07 20:09:44 +00:00
" (notenemy, enemy, enemystayput) or have 4 added ( \" doesn't move \" ). \n " ,
2016-08-27 01:42:01 +00:00
g_scriptFileName , g_lineNumber ) ;
g_warningCnt + + ;
2011-07-20 22:08:05 +00:00
j = 0 ;
}
2006-11-15 01:16:55 +00:00
}
2006-11-16 03:02:42 +00:00
2018-03-08 02:39:21 +00:00
C_GetNextValue ( LABEL_ACTOR ) ;
2011-03-04 08:50:58 +00:00
g_scriptPtr - - ;
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_FALSE ( ( unsigned ) * g_scriptPtr > = MAXTILES ) )
2012-05-13 16:05:34 +00:00
{
C_ReportError ( ERROR_EXCEEDSMAXTILES ) ;
2016-08-27 01:42:01 +00:00
g_errorCnt + + ;
2012-05-13 16:05:34 +00:00
continue ;
}
2011-04-07 01:16:29 +00:00
if ( tw = = CON_EVENTLOADACTOR )
{
2018-12-15 01:36:42 +00:00
g_tile [ * g_scriptPtr ] . loadPtr = apScript + g_scriptActorOffset ;
2011-07-20 22:08:05 +00:00
g_checkingIfElse = 0 ;
continue ;
2011-04-07 01:16:29 +00:00
}
2011-03-04 08:50:58 +00:00
2018-12-15 01:36:42 +00:00
g_tile [ * g_scriptPtr ] . execPtr = apScript + g_scriptActorOffset ;
2006-11-16 03:02:42 +00:00
2011-04-07 01:16:29 +00:00
if ( tw = = CON_USERACTOR )
2012-10-30 15:54:35 +00:00
{
2018-11-18 18:10:39 +00:00
if ( j & 1 ) g_tile [ * g_scriptPtr ] . flags | = SFLAG_BADGUY ;
if ( j & 2 ) g_tile [ * g_scriptPtr ] . flags | = ( SFLAG_BADGUY | SFLAG_BADGUYSTAYPUT ) ;
if ( j & 4 ) g_tile [ * g_scriptPtr ] . flags | = SFLAG_ROTFIXED ;
2012-10-30 15:54:35 +00:00
}
2011-03-04 08:50:58 +00:00
2011-04-07 01:16:29 +00:00
for ( j = 0 ; j < 4 ; j + + )
2006-11-15 01:16:55 +00:00
{
2018-12-15 01:36:42 +00:00
scriptWriteAtOffset ( 0 , apScript + g_scriptActorOffset + j ) ;
2011-04-07 01:16:29 +00:00
if ( j = = 3 )
2006-11-15 01:16:55 +00:00
{
2011-04-07 01:16:29 +00:00
j = 0 ;
while ( C_GetKeyword ( ) = = - 1 )
2014-12-26 17:29:57 +00:00
C_BitOrNextValue ( & j ) ;
C_FinishBitOr ( j ) ;
2006-11-15 01:16:55 +00:00
break ;
}
2011-04-07 01:16:29 +00:00
else
2006-11-15 01:16:55 +00:00
{
2011-04-07 01:16:29 +00:00
if ( C_GetKeyword ( ) ! = - 1 )
2006-11-15 01:16:55 +00:00
{
2011-04-07 01:16:29 +00:00
for ( i = 4 - j ; i ; i - - )
{
2018-11-18 18:14:20 +00:00
scriptWriteValue ( 0 ) ;
2011-04-07 01:16:29 +00:00
}
break ;
2006-11-15 01:16:55 +00:00
}
2011-04-07 01:16:29 +00:00
switch ( j )
{
case 0 :
C_GetNextValue ( LABEL_DEFINE ) ;
break ;
case 1 :
C_GetNextValue ( LABEL_ACTION ) ;
break ;
case 2 :
2011-12-21 18:41:55 +00:00
// XXX: LABEL_MOVE|LABEL_DEFINE, what is this shit? compatibility?
2014-10-25 03:36:34 +00:00
// yep, it sure is :(
2018-12-15 01:36:27 +00:00
if ( EDUKE32_PREDICT_FALSE ( ( C_GetNextValue ( LABEL_MOVE | LABEL_DEFINE ) = = 0 ) & & ( g_scriptPtr [ - 1 ] ! = 0 ) & & ( g_scriptPtr [ - 1 ] ! = 1 ) ) )
2011-04-07 01:16:29 +00:00
{
C_ReportError ( - 1 ) ;
2018-12-15 01:36:27 +00:00
scriptWriteAtOffset ( 0 , & g_scriptPtr [ - 1 ] ) ;
2016-08-27 01:42:01 +00:00
initprintf ( " %s:%d: warning: expected a move, found a constant. \n " , g_scriptFileName , g_lineNumber ) ;
g_warningCnt + + ;
2011-04-07 01:16:29 +00:00
}
break ;
}
2018-11-18 18:14:20 +00:00
2018-12-15 01:36:27 +00:00
if ( g_scriptPtr [ - 1 ] > = ( intptr_t ) apScript & & g_scriptPtr [ - 1 ] < ( intptr_t ) & apScript [ g_scriptSize ] )
2018-12-15 01:36:42 +00:00
scriptWritePointer ( g_scriptPtr [ - 1 ] , apScript + g_scriptActorOffset + j ) ;
2018-11-18 18:14:20 +00:00
else
2018-12-15 01:36:42 +00:00
scriptWriteAtOffset ( g_scriptPtr [ - 1 ] , apScript + g_scriptActorOffset + j ) ;
2006-11-15 01:16:55 +00:00
}
}
2011-04-07 01:16:29 +00:00
g_checkingIfElse = 0 ;
continue ;
2006-11-13 23:12:47 +00:00
2011-04-07 01:16:29 +00:00
case CON_ONEVENT :
2015-03-25 21:31:11 +00:00
case CON_APPENDEVENT :
2018-12-15 01:36:42 +00:00
if ( EDUKE32_PREDICT_FALSE ( g_processingState | | g_scriptActorOffset ) )
2011-04-07 01:16:29 +00:00
{
C_ReportError ( ERROR_FOUNDWITHIN ) ;
2016-08-27 01:42:01 +00:00
g_errorCnt + + ;
2011-04-07 01:16:29 +00:00
}
2006-04-13 20:47:06 +00:00
2011-04-07 01:16:29 +00:00
g_numBraces = 0 ;
g_scriptPtr - - ;
2018-12-15 01:36:42 +00:00
g_scriptEventOffset = g_scriptActorOffset = g_scriptPtr - apScript ;
2006-04-13 20:47:06 +00:00
2011-04-07 01:16:29 +00:00
C_SkipComments ( ) ;
j = 0 ;
while ( isaltok ( * ( textptr + j ) ) )
{
g_szCurrentBlockName [ j ] = textptr [ j ] ;
j + + ;
}
g_szCurrentBlockName [ j ] = 0 ;
// g_labelsOnly = 1;
2018-03-08 02:39:21 +00:00
C_GetNextValue ( LABEL_EVENT ) ;
2011-04-07 01:16:29 +00:00
g_labelsOnly = 0 ;
g_scriptPtr - - ;
j = * g_scriptPtr ; // type of event
g_currentEvent = j ;
//Bsprintf(g_szBuf,"Adding Event for %d at %lX",j, g_parsingEventPtr);
//AddLog(g_szBuf);
2017-11-29 07:28:54 +00:00
if ( EDUKE32_PREDICT_FALSE ( ( unsigned ) j > MAXEVENTS - 1 ) )
2011-04-07 01:16:29 +00:00
{
2016-08-27 01:42:01 +00:00
initprintf ( " %s:%d: error: invalid event ID. \n " , g_scriptFileName , g_lineNumber ) ;
g_errorCnt + + ;
2011-04-07 01:16:29 +00:00
continue ;
}
// if event has already been declared then store previous script location
2016-08-27 01:40:35 +00:00
if ( ! apScriptEvents [ j ] )
2011-04-07 01:16:29 +00:00
{
2018-12-15 01:36:42 +00:00
apScriptEvents [ j ] = g_scriptEventOffset ;
2015-03-25 21:31:11 +00:00
}
else if ( tw = = CON_ONEVENT )
{
2018-12-15 01:36:42 +00:00
g_scriptEventChainOffset = apScriptEvents [ j ] ;
apScriptEvents [ j ] = g_scriptEventOffset ;
2015-03-25 21:31:11 +00:00
}
else // if (tw == CON_APPENDEVENT)
{
2018-11-18 18:14:20 +00:00
auto previous_event_end = apScript + apScriptGameEventEnd [ j ] ;
2018-12-15 01:36:48 +00:00
scriptWriteAtOffset ( CON_JUMP | LINE_NUMBER , previous_event_end + + ) ;
2018-11-18 18:14:20 +00:00
scriptWriteAtOffset ( GV_FLAG_CONSTANT , previous_event_end + + ) ;
2018-12-15 01:36:42 +00:00
C_FillEventBreakStackWithJump ( ( intptr_t * ) * previous_event_end , g_scriptEventOffset ) ;
scriptWriteAtOffset ( g_scriptEventOffset , previous_event_end + + ) ;
2011-04-07 01:16:29 +00:00
}
2006-04-13 20:47:06 +00:00
2011-04-07 01:16:29 +00:00
g_checkingIfElse = 0 ;
2006-04-13 20:47:06 +00:00
2011-04-07 01:16:29 +00:00
continue ;
2006-04-13 20:47:06 +00:00
2011-04-07 01:16:29 +00:00
case CON_QSPRINTF :
C_GetManyVars ( 2 ) ;
2006-04-13 20:47:06 +00:00
2011-04-07 01:16:29 +00:00
j = 0 ;
2009-07-12 01:55:34 +00:00
2011-04-07 01:16:29 +00:00
while ( C_GetKeyword ( ) = = - 1 & & j < 32 )
C_GetNextVar ( ) , j + + ;
2009-07-12 01:55:34 +00:00
2018-12-15 01:36:48 +00:00
scriptWriteValue ( CON_NULLOP | LINE_NUMBER ) ;
2011-04-07 01:16:29 +00:00
continue ;
2006-04-13 20:47:06 +00:00
2015-01-17 00:27:19 +00:00
case CON_CSTAT :
C_GetNextValue ( LABEL_DEFINE ) ;
2018-12-15 01:36:27 +00:00
if ( EDUKE32_PREDICT_FALSE ( g_scriptPtr [ - 1 ] = = 32767 ) )
2015-01-17 00:27:19 +00:00
{
2018-12-15 01:36:27 +00:00
g_scriptPtr [ - 1 ] = 32768 ;
2015-01-17 00:27:19 +00:00
C_ReportError ( - 1 ) ;
2016-08-27 01:42:01 +00:00
initprintf ( " %s:%d: warning: tried to set cstat 32767, using 32768 instead. \n " , g_scriptFileName , g_lineNumber ) ;
g_warningCnt + + ;
2015-01-17 00:27:19 +00:00
}
2018-12-15 01:36:27 +00:00
else if ( EDUKE32_PREDICT_FALSE ( ( g_scriptPtr [ - 1 ] & 48 ) = = 48 ) )
2015-01-17 00:27:19 +00:00
{
2018-12-15 01:36:27 +00:00
i = g_scriptPtr [ - 1 ] ;
g_scriptPtr [ - 1 ] ^ = 48 ;
2015-01-17 00:27:19 +00:00
C_ReportError ( - 1 ) ;
2018-12-15 01:36:27 +00:00
initprintf ( " %s:%d: warning: tried to set cstat %d, using %d instead. \n " , g_scriptFileName , g_lineNumber , i , ( int32_t ) ( g_scriptPtr [ - 1 ] ) ) ;
2016-08-27 01:42:01 +00:00
g_warningCnt + + ;
2015-01-17 00:27:19 +00:00
}
continue ;
2017-11-29 07:29:14 +00:00
case CON_SCREENPAL :
C_GetManyVars ( 4 ) ;
continue ;
2018-12-15 01:37:49 +00:00
case CON_HITRADIUS :
2017-06-24 09:21:03 +00:00
case CON_DRAWLINE256 :
2015-01-17 00:27:19 +00:00
C_GetManyVars ( 5 ) ;
continue ;
2017-06-24 09:21:03 +00:00
case CON_DRAWLINERGB :
C_GetManyVars ( 6 ) ;
continue ;
2015-01-17 00:27:19 +00:00
case CON_ADDAMMO :
2018-11-18 18:10:15 +00:00
case CON_ADDINVENTORY :
2015-01-17 00:27:19 +00:00
case CON_DEBRIS :
case CON_GUTS :
2018-11-18 18:10:15 +00:00
case CON_SIZEAT :
case CON_SIZETO :
2015-01-17 00:27:19 +00:00
C_GetNextValue ( LABEL_DEFINE ) ;
2017-07-18 20:53:41 +00:00
fallthrough__ ;
2018-11-18 18:10:15 +00:00
case CON_ADDKILLS :
2011-04-07 01:16:29 +00:00
case CON_ADDPHEALTH :
2018-11-18 18:10:15 +00:00
case CON_ADDSTRENGTH :
case CON_CACTOR :
case CON_CLIPDIST :
2011-04-07 01:16:29 +00:00
case CON_COUNT :
2018-11-18 18:10:15 +00:00
case CON_CSTATOR :
case CON_DEBUG :
2011-04-07 01:16:29 +00:00
case CON_ENDOFGAME :
2013-05-23 18:28:04 +00:00
case CON_ENDOFLEVEL :
2018-11-18 18:10:15 +00:00
case CON_LOTSOFGLASS :
2011-04-07 01:16:29 +00:00
case CON_MAIL :
2018-11-18 18:10:15 +00:00
case CON_MONEY :
2011-04-07 01:16:29 +00:00
case CON_PAPER :
2018-11-18 18:10:15 +00:00
case CON_SAVE :
case CON_SAVENN :
case CON_SLEEPTIME :
case CON_SPAWN :
case CON_SPRITEPAL :
case CON_STRENGTH :
2011-04-07 01:16:29 +00:00
C_GetNextValue ( LABEL_DEFINE ) ;
2011-05-20 02:34:41 +00:00
continue ;
2009-06-18 05:57:10 +00:00
2018-12-15 01:38:43 +00:00
case CON_QUOTE :
C_GetNextValue ( LABEL_DEFINE ) ;
if ( EDUKE32_PREDICT_FALSE ( ( ( unsigned ) g_scriptPtr [ - 1 ] > = MAXQUOTES ) | | apStrings [ g_scriptPtr [ - 1 ] ] = = NULL ) )
{
g_errorCnt + + ;
C_ReportError ( - 1 ) ;
initprintf ( " %s:%d: error: invalid quote \n " , g_scriptFileName , g_lineNumber ) ;
}
continue ;
2011-04-07 01:16:29 +00:00
case CON_ELSE :
2014-10-25 03:36:34 +00:00
{
2015-05-26 00:48:17 +00:00
if ( EDUKE32_PREDICT_FALSE ( ! g_checkingIfElse ) )
{
g_scriptPtr - - ;
2018-11-18 18:14:43 +00:00
auto const tempscrptr = g_scriptPtr ;
2016-08-27 01:42:01 +00:00
g_warningCnt + + ;
2015-05-26 00:48:17 +00:00
C_ReportError ( - 1 ) ;
2014-10-25 03:36:34 +00:00
2018-12-15 01:38:43 +00:00
initprintf ( " %s:%d: warning: found `else' with no `if' \n " , g_scriptFileName , g_lineNumber ) ;
2014-10-25 03:36:34 +00:00
2015-05-26 00:48:17 +00:00
if ( C_GetKeyword ( ) = = CON_LEFTBRACE )
{
C_GetNextKeyword ( ) ;
g_numBraces + + ;
2014-10-25 03:36:34 +00:00
2015-05-26 00:48:17 +00:00
C_ParseCommand ( 1 ) ;
}
else C_ParseCommand ( 0 ) ;
2014-10-25 03:36:34 +00:00
2015-05-26 00:48:17 +00:00
g_scriptPtr = tempscrptr ;
2014-10-25 03:36:34 +00:00
2015-05-26 00:48:17 +00:00
continue ;
}
2014-10-25 03:36:34 +00:00
2018-12-15 01:36:27 +00:00
intptr_t const lastScriptPtr = & g_scriptPtr [ - 1 ] - apScript ;
2009-06-18 05:57:10 +00:00
2018-12-15 01:36:42 +00:00
g_skipBranch = false ;
2011-04-07 01:16:29 +00:00
g_checkingIfElse - - ;
2009-01-04 22:22:33 +00:00
2011-04-07 01:16:29 +00:00
if ( C_CheckMalformedBranch ( lastScriptPtr ) )
continue ;
2009-01-04 22:22:33 +00:00
2016-08-27 01:40:35 +00:00
intptr_t const offset = ( unsigned ) ( g_scriptPtr - apScript ) ;
2015-05-26 00:48:17 +00:00
2011-04-07 01:16:29 +00:00
g_scriptPtr + + ; //Leave a spot for the fail location
2015-05-26 00:48:17 +00:00
2011-04-07 01:16:29 +00:00
C_ParseCommand ( 0 ) ;
2009-01-05 14:43:12 +00:00
2011-04-07 01:16:29 +00:00
if ( C_CheckEmptyBranch ( tw , lastScriptPtr ) )
continue ;
2009-01-05 14:43:12 +00:00
2018-11-18 18:14:43 +00:00
auto const tempscrptr = ( intptr_t * ) apScript + offset ;
2018-11-18 18:14:20 +00:00
scriptWritePointer ( ( intptr_t ) g_scriptPtr , tempscrptr ) ;
2015-05-26 00:48:17 +00:00
continue ;
2011-04-07 01:16:29 +00:00
}
2006-11-15 01:16:55 +00:00
2011-04-07 01:16:29 +00:00
case CON_SETSECTOR :
case CON_GETSECTOR :
{
2018-11-18 18:14:43 +00:00
int const labelNum = C_GetStructureIndexes ( 1 , & h_sector ) ;
2006-11-15 01:16:55 +00:00
2016-08-27 01:40:35 +00:00
if ( labelNum = = - 1 )
2011-04-07 01:16:29 +00:00
continue ;
2006-11-15 01:16:55 +00:00
2018-11-18 18:14:20 +00:00
scriptWriteValue ( SectorLabels [ labelNum ] . lId ) ;
2006-11-15 01:16:55 +00:00
2016-01-03 20:07:24 +00:00
C_GetNextVarType ( ( tw = = CON_GETSECTOR ) ? GAMEVAR_READONLY : 0 ) ;
2011-05-20 02:34:41 +00:00
continue ;
2011-04-07 01:16:29 +00:00
}
2006-11-16 03:02:42 +00:00
2018-12-15 01:37:49 +00:00
case CON_FINDNEARACTOR3D :
case CON_FINDNEARACTOR :
case CON_FINDNEARACTORZ :
case CON_FINDNEARSPRITE3D :
case CON_FINDNEARSPRITE :
case CON_FINDNEARSPRITEZ :
2011-04-07 01:16:29 +00:00
{
C_GetNextValue ( LABEL_DEFINE ) ; // get <type>
2006-11-16 03:02:42 +00:00
2011-04-07 01:16:29 +00:00
// get the ID of the DEF
C_GetNextVar ( ) ;
switch ( tw )
{
2018-12-15 01:37:49 +00:00
case CON_FINDNEARACTORZ :
case CON_FINDNEARSPRITEZ :
2011-04-07 01:16:29 +00:00
C_GetNextVar ( ) ;
default :
break ;
}
// target var
// get the ID of the DEF
C_GetNextVarType ( GAMEVAR_READONLY ) ;
2011-05-20 02:34:41 +00:00
continue ;
2011-04-07 01:16:29 +00:00
}
2006-11-16 03:02:42 +00:00
2011-04-07 01:16:29 +00:00
case CON_SETWALL :
case CON_GETWALL :
{
2018-11-18 18:14:43 +00:00
int const labelNum = C_GetStructureIndexes ( 1 , & h_wall ) ;
2006-04-13 20:47:06 +00:00
2016-08-27 01:40:35 +00:00
if ( labelNum = = - 1 )
2011-04-07 01:16:29 +00:00
continue ;
2006-04-13 20:47:06 +00:00
2018-11-18 18:14:20 +00:00
scriptWriteValue ( WallLabels [ labelNum ] . lId ) ;
2006-04-13 20:47:06 +00:00
2016-01-03 20:07:24 +00:00
C_GetNextVarType ( ( tw = = CON_GETWALL ) ? GAMEVAR_READONLY : 0 ) ;
2011-05-20 02:34:41 +00:00
continue ;
2011-04-07 01:16:29 +00:00
}
2006-04-13 20:47:06 +00:00
2011-04-07 01:16:29 +00:00
case CON_SETPLAYER :
case CON_GETPLAYER :
{
2018-11-18 18:14:43 +00:00
int const labelNum = C_GetStructureIndexes ( 1 , & h_player ) ;
2006-04-13 20:47:06 +00:00
2016-08-27 01:40:35 +00:00
if ( labelNum = = - 1 )
2011-04-07 01:16:29 +00:00
continue ;
2006-04-13 20:47:06 +00:00
2018-11-18 18:14:20 +00:00
scriptWriteValue ( PlayerLabels [ labelNum ] . lId ) ;
2006-04-13 20:47:06 +00:00
2016-08-27 01:40:35 +00:00
if ( PlayerLabels [ labelNum ] . flags & LABEL_HASPARM2 )
2011-04-07 01:16:29 +00:00
C_GetNextVar ( ) ;
2016-01-03 20:07:24 +00:00
C_GetNextVarType ( ( tw = = CON_GETPLAYER ) ? GAMEVAR_READONLY : 0 ) ;
2011-05-20 02:34:41 +00:00
continue ;
2011-04-07 01:16:29 +00:00
}
2006-11-16 03:02:42 +00:00
2011-04-07 01:16:29 +00:00
case CON_SETINPUT :
case CON_GETINPUT :
{
2018-11-18 18:14:43 +00:00
int const labelNum = C_GetStructureIndexes ( 1 , & h_input ) ;
2006-04-13 20:47:06 +00:00
2016-08-27 01:40:35 +00:00
if ( labelNum = = - 1 )
2011-04-07 01:16:29 +00:00
continue ;
2006-11-16 03:02:42 +00:00
2018-11-18 18:14:20 +00:00
scriptWriteValue ( InputLabels [ labelNum ] . lId ) ;
2006-11-16 03:02:42 +00:00
2016-01-03 20:07:24 +00:00
C_GetNextVarType ( tw = = CON_GETINPUT ? GAMEVAR_READONLY : 0 ) ;
2011-05-20 02:34:41 +00:00
continue ;
2011-04-07 01:16:29 +00:00
}
2006-11-15 01:16:55 +00:00
2018-03-15 01:19:27 +00:00
case CON_SETTILEDATA :
case CON_GETTILEDATA :
{
2018-11-18 18:14:43 +00:00
int const labelNum = C_GetStructureIndexes ( 0 , & h_tiledata ) ;
2018-03-15 01:19:27 +00:00
if ( labelNum = = - 1 )
continue ;
2018-11-18 18:14:20 +00:00
scriptWriteValue ( TileDataLabels [ labelNum ] . lId ) ;
2018-03-15 01:19:27 +00:00
C_GetNextVarType ( ( tw = = CON_GETTILEDATA ) ? GAMEVAR_READONLY : 0 ) ;
continue ;
}
2011-04-07 01:16:29 +00:00
case CON_SETUSERDEF :
case CON_GETUSERDEF :
{
// now get name of .xxx
while ( * textptr ! = ' . ' )
{
2016-01-03 20:07:11 +00:00
if ( * textptr = = 0xa | | ! * textptr )
2011-04-07 01:16:29 +00:00
break ;
2006-11-16 03:02:42 +00:00
2011-04-07 01:16:29 +00:00
textptr + + ;
}
2016-01-03 20:07:11 +00:00
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_FALSE ( * textptr ! = ' . ' ) )
2011-04-07 01:16:29 +00:00
{
2016-08-27 01:42:01 +00:00
g_errorCnt + + ;
2011-04-07 01:16:29 +00:00
C_ReportError ( ERROR_SYNTAXERROR ) ;
continue ;
}
textptr + + ;
C_GetNextLabelName ( ) ;
2006-11-16 03:02:42 +00:00
2018-11-18 18:14:43 +00:00
int const labelNum = C_GetLabelNameID ( UserdefsLabels , & h_userdef , Bstrtolower ( LAST_LABEL ) ) ;
2006-11-13 23:12:47 +00:00
2016-08-27 01:40:35 +00:00
if ( EDUKE32_PREDICT_FALSE ( labelNum = = - 1 ) )
2011-04-07 01:16:29 +00:00
{
2016-08-27 01:42:01 +00:00
g_errorCnt + + ;
2016-01-02 01:56:25 +00:00
C_ReportError ( ERROR_NOTAMEMBER ) ;
2011-04-07 01:16:29 +00:00
continue ;
}
2018-11-18 18:14:20 +00:00
scriptWriteValue ( labelNum ) ;
2006-11-15 01:16:55 +00:00
2018-02-26 20:19:55 +00:00
if ( UserdefsLabels [ labelNum ] . flags & LABEL_HASPARM2 )
C_GetNextVar ( ) ;
2016-01-03 20:07:24 +00:00
C_GetNextVarType ( ( tw = = CON_GETUSERDEF ) ? GAMEVAR_READONLY : 0 ) ;
2011-05-20 02:34:41 +00:00
continue ;
2008-06-05 02:29:18 +00:00
}
2006-04-13 20:47:06 +00:00
2011-04-07 01:16:29 +00:00
case CON_SETACTOR :
2018-11-18 18:11:04 +00:00
{
2018-12-15 01:36:27 +00:00
intptr_t * const ins = & g_scriptPtr [ - 1 ] ;
2018-11-18 18:11:04 +00:00
int const labelNum = C_GetStructureIndexes ( 1 , & h_actor ) ;
if ( labelNum = = - 1 )
continue ;
Bassert ( ( * ins & VM_INSTMASK ) = = CON_SETACTOR ) ;
auto const & label = ActorLabels [ labelNum ] ;
if ( label . offset ! = - 1 & & ( label . flags & ( LABEL_WRITEFUNC | LABEL_HASPARM2 ) ) = = 0 )
{
if ( labelNum > = ACTOR_SPRITEEXT_BEGIN )
* ins = CON_SETSPRITEEXT ;
else if ( labelNum > = ACTOR_STRUCT_BEGIN )
* ins = CON_SETACTORSTRUCT ;
else
* ins = CON_SETSPRITESTRUCT ;
}
2018-11-18 18:14:20 +00:00
scriptWriteValue ( label . lId ) ;
2018-11-18 18:11:04 +00:00
if ( label . flags & LABEL_HASPARM2 )
C_GetNextVar ( ) ;
C_GetNextVar ( ) ;
continue ;
}
2011-04-07 01:16:29 +00:00
case CON_GETACTOR :
{
2018-12-15 01:36:27 +00:00
intptr_t * const ins = & g_scriptPtr [ - 1 ] ;
2018-11-18 18:11:04 +00:00
int const labelNum = C_GetStructureIndexes ( 1 , & h_actor ) ;
2006-11-13 23:12:47 +00:00
2016-08-27 01:40:35 +00:00
if ( labelNum = = - 1 )
2011-04-07 01:16:29 +00:00
continue ;
2018-11-18 18:11:04 +00:00
Bassert ( ( * ins & VM_INSTMASK ) = = CON_GETACTOR ) ;
auto const & label = ActorLabels [ labelNum ] ;
if ( label . offset ! = - 1 & & ( label . flags & ( LABEL_READFUNC | LABEL_HASPARM2 ) ) = = 0 )
{
if ( labelNum > = ACTOR_SPRITEEXT_BEGIN )
* ins = CON_GETSPRITEEXT ;
else if ( labelNum > = ACTOR_STRUCT_BEGIN )
* ins = CON_GETACTORSTRUCT ;
else
* ins = CON_GETSPRITESTRUCT ;
}
2018-11-18 18:14:20 +00:00
scriptWriteValue ( label . lId ) ;
2011-04-07 01:16:29 +00:00
2018-11-18 18:11:04 +00:00
if ( label . flags & LABEL_HASPARM2 )
2011-04-07 01:16:29 +00:00
C_GetNextVar ( ) ;
2018-11-18 18:11:04 +00:00
C_GetNextVarType ( GAMEVAR_READONLY ) ;
2011-05-20 02:34:41 +00:00
continue ;
2011-04-07 01:16:29 +00:00
}
2008-07-13 07:10:47 +00:00
2011-04-07 01:16:29 +00:00
case CON_GETTSPR :
case CON_SETTSPR :
{
2013-05-28 19:52:45 +00:00
#if 0
2014-10-25 03:36:34 +00:00
if ( unlikely ( g_currentEvent ! = EVENT_ANIMATESPRITES ) )
2011-04-07 01:16:29 +00:00
{
C_ReportError ( - 1 ) ;
initprintf ( " %s:%d: warning: found `%s' outside of EVENT_ANIMATESPRITES \n " , g_szScriptFileName , g_lineNumber , tempbuf ) ;
g_numCompilerWarnings + + ;
}
2013-05-28 19:52:45 +00:00
# endif
2018-11-18 18:14:43 +00:00
int const labelNum = C_GetStructureIndexes ( 1 , & h_tsprite ) ;
2008-07-13 07:10:47 +00:00
2016-08-27 01:40:35 +00:00
if ( labelNum = = - 1 )
2011-04-07 01:16:29 +00:00
continue ;
2009-07-15 01:26:38 +00:00
2018-11-18 18:14:20 +00:00
scriptWriteValue ( TsprLabels [ labelNum ] . lId ) ;
2009-07-12 01:55:34 +00:00
2016-01-03 20:07:24 +00:00
C_GetNextVarType ( ( tw = = CON_GETTSPR ) ? GAMEVAR_READONLY : 0 ) ;
2011-05-20 02:34:41 +00:00
continue ;
2011-04-07 01:16:29 +00:00
}
2006-04-13 20:47:06 +00:00
2015-01-17 00:27:19 +00:00
case CON_COS :
2018-11-18 18:10:15 +00:00
case CON_DIVR :
case CON_DIVRU :
case CON_HEADSPRITESECT :
2015-01-17 00:27:19 +00:00
case CON_HEADSPRITESTAT :
2018-11-18 18:10:15 +00:00
case CON_NEXTSPRITESECT :
2015-01-17 00:27:19 +00:00
case CON_NEXTSPRITESTAT :
case CON_PREVSPRITESECT :
2018-11-18 18:10:15 +00:00
case CON_PREVSPRITESTAT :
case CON_QSTRLEN :
2011-04-07 01:16:29 +00:00
case CON_SECTOROFWALL :
2018-11-18 18:10:15 +00:00
case CON_SIN :
2011-04-07 01:16:29 +00:00
C_GetNextVarType ( GAMEVAR_READONLY ) ;
2017-07-18 20:53:41 +00:00
fallthrough__ ;
2018-11-18 18:10:15 +00:00
case CON_ACTIVATECHEAT :
2015-01-17 00:27:19 +00:00
case CON_ADDLOGVAR :
2018-12-15 01:37:49 +00:00
case CON_ANGOFF :
2018-11-18 18:10:15 +00:00
case CON_CHECKACTIVATORMOTION :
case CON_CHECKAVAILINVEN :
case CON_CHECKAVAILWEAPON :
case CON_CLEARMAPSTATE :
case CON_CMENU :
case CON_ECHO :
2018-12-15 01:37:49 +00:00
case CON_EQSPAWN :
case CON_ESHOOT :
case CON_ESPAWN :
case CON_GLOBALSOUND :
2018-11-18 18:10:15 +00:00
case CON_GUNIQHUDID :
2011-04-07 01:16:29 +00:00
case CON_INITTIMER :
2018-11-18 18:10:15 +00:00
case CON_JUMP :
2011-04-07 01:16:29 +00:00
case CON_LOCKPLAYER :
2018-11-18 18:10:15 +00:00
case CON_MOVESECTOR :
case CON_OPERATEMASTERSWITCHES :
case CON_OPERATERESPAWNS :
2018-12-15 01:37:49 +00:00
case CON_QSPAWN :
2011-04-07 01:16:29 +00:00
case CON_QUAKE :
2018-11-18 18:10:15 +00:00
case CON_RESETPLAYERFLAGS :
2011-04-07 01:16:29 +00:00
case CON_SAVEGAMEVAR :
2018-11-18 18:10:15 +00:00
case CON_SCREENSOUND :
2015-01-17 00:27:19 +00:00
case CON_SECTCLEARINTERPOLATION :
2018-11-18 18:10:15 +00:00
case CON_SECTSETINTERPOLATION :
2015-01-17 00:27:19 +00:00
case CON_SETACTORANGLE :
2018-11-18 18:10:15 +00:00
case CON_SETGAMEPALETTE :
2015-01-17 00:28:49 +00:00
case CON_SETMUSICPOSITION :
2018-11-18 18:10:15 +00:00
case CON_SETPLAYERANGLE :
2018-12-15 01:37:49 +00:00
case CON_SHOOT :
case CON_SOUNDONCE :
case CON_SOUND :
2015-02-22 22:14:39 +00:00
case CON_STARTCUTSCENE :
2018-12-15 01:37:49 +00:00
case CON_STARTTRACK :
case CON_STOPSOUND :
2018-11-18 18:10:15 +00:00
case CON_TIME :
case CON_USERQUOTE :
2011-04-07 01:16:29 +00:00
C_GetNextVar ( ) ;
continue ;
2015-01-17 00:27:19 +00:00
case CON_SQRT :
C_GetNextVar ( ) ;
2017-07-18 20:53:41 +00:00
fallthrough__ ;
2015-01-17 00:27:19 +00:00
case CON_DISPLAYRAND :
2018-11-18 18:10:15 +00:00
case CON_FINDOTHERPLAYER :
case CON_FINDPLAYER :
2015-01-17 00:27:19 +00:00
case CON_GETACTORANGLE :
2018-11-18 18:10:15 +00:00
case CON_GETANGLETOTARGET :
2015-01-17 00:27:19 +00:00
case CON_GETCURRADDRESS :
2015-01-17 00:28:49 +00:00
case CON_GETMUSICPOSITION :
2018-11-18 18:10:15 +00:00
case CON_GETPLAYERANGLE :
case CON_GETTICKS :
2016-01-02 01:56:29 +00:00
case CON_INV :
2018-11-18 18:10:15 +00:00
case CON_KLABS :
case CON_READGAMEVAR :
2013-02-25 15:31:05 +00:00
C_GetNextVarType ( GAMEVAR_READONLY ) ;
continue ;
2009-06-19 01:10:10 +00:00
2018-11-18 18:10:15 +00:00
case CON_CALCHYPOTENUSE :
2016-05-13 22:15:37 +00:00
case CON_CLAMP :
2017-06-24 09:20:54 +00:00
case CON_GETCLOSESTCOL :
2016-05-13 22:15:37 +00:00
C_GetNextVarType ( GAMEVAR_READONLY ) ;
2017-08-01 09:48:55 +00:00
fallthrough__ ;
2018-11-18 18:10:15 +00:00
case CON_ACTORSOUND :
2017-08-01 09:48:55 +00:00
case CON_CHANGESPRITESECT :
2018-11-18 18:10:15 +00:00
case CON_CHANGESPRITESTAT :
2018-12-15 01:37:49 +00:00
case CON_EZSHOOT :
2017-08-01 09:48:55 +00:00
case CON_GETPNAME :
2018-11-18 18:10:15 +00:00
case CON_PRELOADTRACKSLOTFORSWAP :
case CON_QGETSYSSTR :
2017-08-01 09:48:55 +00:00
case CON_QSTRCAT :
case CON_QSTRCPY :
2018-11-18 18:10:15 +00:00
case CON_SPAWNCEILINGGLASS :
2018-04-11 03:33:59 +00:00
case CON_SPAWNWALLGLASS :
case CON_SPAWNWALLSTAINEDGLASS :
2018-11-18 18:10:15 +00:00
case CON_STARTLEVEL :
case CON_STARTTRACKSLOT :
case CON_STOPACTORSOUND :
case CON_SWAPTRACKSLOT :
2018-12-15 01:37:49 +00:00
case CON_ZSHOOT :
2016-05-13 22:15:37 +00:00
C_GetManyVars ( 2 ) ;
continue ;
2011-04-07 01:16:29 +00:00
case CON_ENHANCED :
2009-06-24 08:20:10 +00:00
g_scriptPtr - - ;
2011-04-07 01:16:29 +00:00
C_GetNextValue ( LABEL_DEFINE ) ;
g_scriptPtr - - ;
2016-01-21 19:35:30 +00:00
if ( EDUKE32_PREDICT_FALSE ( * g_scriptPtr > BYTEVERSION_EDUKE32 ) )
2011-04-07 01:16:29 +00:00
{
2016-08-27 01:42:01 +00:00
g_warningCnt + + ;
initprintf ( " %s:%d: warning: need build %d, found build %d \n " , g_scriptFileName , g_lineNumber , k , BYTEVERSION_EDUKE32 ) ;
2011-04-07 01:16:29 +00:00
}
2011-05-20 02:34:41 +00:00
continue ;
2009-06-19 01:10:10 +00:00
2011-04-07 01:16:29 +00:00
case CON_DYNAMICREMAP :
g_scriptPtr - - ;
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_FALSE ( g_dynamicTileMapping ) )
2011-04-07 01:16:29 +00:00
{
2016-08-27 01:42:01 +00:00
initprintf ( " %s:%d: warning: duplicate dynamicremap statement \n " , g_scriptFileName , g_lineNumber ) ;
g_warningCnt + + ;
2011-04-07 01:16:29 +00:00
}
2012-01-28 14:38:54 +00:00
# ifdef DYNTILEREMAP_ENABLE
2017-06-23 03:58:26 +00:00
# ifdef DEBUGGINGAIDS
else
initprintf ( " Using dynamic tile remapping \n " ) ;
# endif
2013-03-17 18:11:38 +00:00
g_dynamicTileMapping = 1 ;
2012-01-28 14:38:54 +00:00
# else
2017-06-23 03:58:26 +00:00
else
2012-01-28 15:16:14 +00:00
{
2016-08-27 01:42:01 +00:00
initprintf ( " %s:%d: warning: dynamic tile remapping is disabled in this build \n " , g_scriptFileName , g_lineNumber ) ;
g_warningCnt + + ;
2012-01-28 15:16:14 +00:00
}
2012-01-28 14:38:54 +00:00
# endif
2011-05-20 02:34:41 +00:00
continue ;
2011-04-07 01:16:29 +00:00
2013-06-01 06:55:30 +00:00
case CON_DYNAMICSOUNDREMAP :
g_scriptPtr - - ;
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_FALSE ( g_dynamicSoundMapping ) )
2013-06-01 06:55:30 +00:00
{
2016-08-27 01:42:01 +00:00
initprintf ( " %s:%d: warning: duplicate dynamicsoundremap statement \n " , g_scriptFileName , g_lineNumber ) ;
g_warningCnt + + ;
2013-06-01 06:55:30 +00:00
}
else
# ifdef DYNSOUNDREMAP_ENABLE
2018-12-15 01:36:42 +00:00
# ifdef DEBUGGINGAIDS
2013-06-01 06:55:30 +00:00
initprintf ( " Using dynamic sound remapping \n " ) ;
2018-12-15 01:36:42 +00:00
# endif
2013-06-01 06:55:30 +00:00
g_dynamicSoundMapping = 1 ;
# else
{
2016-08-27 01:42:01 +00:00
initprintf ( " %s:%d: warning: dynamic sound remapping is disabled in this build \n " , g_scriptFileName , g_lineNumber ) ;
g_warningCnt + + ;
2013-06-01 06:55:30 +00:00
}
# endif
continue ;
2011-04-07 01:16:29 +00:00
case CON_ADDVAR :
2018-11-18 18:10:15 +00:00
case CON_ANDVAR :
2011-04-07 01:16:29 +00:00
case CON_DISPLAYRANDVAR :
case CON_DIVVAR :
case CON_MODVAR :
2018-11-18 18:10:15 +00:00
case CON_MULVAR :
2011-04-07 01:16:29 +00:00
case CON_ORVAR :
2018-11-18 18:10:15 +00:00
case CON_RANDVAR :
case CON_SETVAR :
2011-04-07 01:16:29 +00:00
case CON_SHIFTVARL :
case CON_SHIFTVARR :
2018-11-18 18:10:15 +00:00
case CON_SUBVAR :
case CON_XORVAR :
2018-12-15 01:38:00 +00:00
setvar :
{
auto ins = & g_scriptPtr [ - 1 ] ;
2009-06-24 08:20:10 +00:00
2018-12-15 01:38:00 +00:00
C_GetNextVarType ( GAMEVAR_READONLY ) ;
C_GetNextValue ( LABEL_DEFINE ) ;
2018-12-15 01:38:38 +00:00
// replace divides and multiplies by 0 with an error asking if the user is stupid
if ( ins [ 2 ] = = 0 & & ( tw = = CON_MODVAR | | tw = = CON_MULVAR | | tw = = CON_DIVVAR ) )
{
g_errorCnt + + ;
C_ReportError ( - 1 ) ;
initprintf ( " %s:%d: error: divide or multiply by zero! What are you doing? \n " , g_scriptFileName , g_lineNumber ) ;
continue ;
}
else if ( tw = = CON_DIVVAR | | tw = = CON_MULVAR )
2009-06-24 08:20:10 +00:00
{
2018-12-15 01:38:22 +00:00
auto const i = ins [ 2 ] ;
// replace multiplies or divides by 1 with nullop
if ( i = = 1 )
2018-12-15 01:38:00 +00:00
{
2018-12-15 01:38:22 +00:00
int constexpr const opcode = CON_NULLOP ;
2009-06-19 01:10:10 +00:00
2018-12-15 01:38:22 +00:00
if ( ! g_errorCnt & & ! g_warningCnt & & g_scriptDebug > 1 )
2018-12-15 01:38:05 +00:00
{
initprintf ( " %s:%d: %s -> %s \n " , g_scriptFileName , g_lineNumber ,
VM_GetKeywordForID ( tw ) , VM_GetKeywordForID ( opcode ) ) ;
}
scriptWriteAtOffset ( opcode | LINE_NUMBER , ins ) ;
g_scriptPtr = & ins [ 1 ] ;
}
// replace multiplies or divides by -1 with inversion
else if ( i = = - 1 )
{
int constexpr const opcode = CON_INV ;
if ( g_scriptDebug > 1 & & ! g_errorCnt & & ! g_warningCnt )
2018-12-15 01:38:00 +00:00
{
initprintf ( " %s:%d: %s -> %s \n " , g_scriptFileName , g_lineNumber ,
VM_GetKeywordForID ( tw ) , VM_GetKeywordForID ( opcode ) ) ;
}
2009-08-28 23:08:00 +00:00
2018-12-15 01:38:00 +00:00
scriptWriteAtOffset ( opcode | LINE_NUMBER , ins ) ;
g_scriptPtr - - ;
}
2018-12-15 01:38:22 +00:00
}
2018-12-15 01:38:16 +00:00
// replace instructions with special versions for specific var types
scriptUpdateOpcodeForVariableType ( ins ) ;
2018-12-15 01:38:00 +00:00
continue ;
}
2009-02-19 09:39:19 +00:00
2018-12-15 01:38:00 +00:00
case CON_ADDVARVAR :
case CON_ANDVARVAR :
case CON_DISPLAYRANDVARVAR :
case CON_DIVVARVAR :
case CON_MODVARVAR :
case CON_MULVARVAR :
case CON_ORVARVAR :
case CON_RANDVARVAR :
case CON_SETVARVAR :
case CON_SHIFTVARVARL :
case CON_SHIFTVARVARR :
case CON_SUBVARVAR :
case CON_XORVARVAR :
{
setvarvar :
auto ins = & g_scriptPtr [ - 1 ] ;
auto tptr = textptr ;
2018-12-15 01:39:08 +00:00
int const lnum = g_lineNumber ;
2018-12-15 01:38:00 +00:00
C_GetNextVarType ( GAMEVAR_READONLY ) ;
C_GetNextVar ( ) ;
int const opcode = inthash_find ( & h_varvar , * ins & VM_INSTMASK ) ;
if ( ins [ 2 ] = = GV_FLAG_CONSTANT & & opcode ! = - 1 )
{
2018-12-15 01:38:05 +00:00
if ( g_scriptDebug > 1 & & ! g_errorCnt & & ! g_warningCnt )
2018-12-15 01:38:00 +00:00
{
initprintf ( " %s:%d: %s -> %s \n " , g_scriptFileName , g_lineNumber ,
VM_GetKeywordForID ( * ins & VM_INSTMASK ) , VM_GetKeywordForID ( opcode ) ) ;
}
tw = opcode ;
scriptWriteAtOffset ( opcode | LINE_NUMBER , ins ) ;
g_scriptPtr = & ins [ 1 ] ;
textptr = tptr ;
2018-12-15 01:39:08 +00:00
g_lineNumber = lnum ;
2018-12-15 01:38:00 +00:00
goto setvar ;
}
continue ;
}
case CON_GETACTORVAR :
case CON_GETPLAYERVAR :
case CON_SETACTORVAR :
case CON_SETPLAYERVAR :
{
// syntax [gs]etactorvar[<var>].<varx> <VAR>
// gets the value of the per-actor variable varx into VAR
if ( C_GetStructureIndexes ( 1 , NULL ) = = - 1 )
continue ;
if ( g_scriptPtr [ - 1 ] = = g_thisActorVarID ) // convert to "setvarvar"
{
g_scriptPtr - - ;
g_scriptPtr [ - 1 ] = CON_SETVARVAR ;
if ( tw = = CON_SETACTORVAR | | tw = = CON_SETPLAYERVAR )
{
tw = inthash_find ( & h_varvar , tw ) ;
goto setvarvar ;
}
else
{
g_scriptPtr + + ;
C_GetNextVar ( ) ;
g_scriptPtr - = 2 ;
2011-04-07 01:16:29 +00:00
C_GetNextVarType ( GAMEVAR_READONLY ) ;
2018-12-15 01:38:00 +00:00
g_scriptPtr + + ;
2011-04-07 01:16:29 +00:00
}
2018-12-15 01:38:00 +00:00
continue ;
2011-04-07 01:16:29 +00:00
}
2018-12-15 01:38:00 +00:00
/// now pointing at 'xxx'
C_GetNextLabelName ( ) ;
if ( EDUKE32_PREDICT_FALSE ( hash_find ( & h_keywords , LAST_LABEL ) > = 0 ) )
{
g_errorCnt + + ;
C_ReportError ( ERROR_ISAKEYWORD ) ;
continue ;
}
i = GetDefID ( LAST_LABEL ) ;
if ( EDUKE32_PREDICT_FALSE ( i < 0 ) )
{
g_errorCnt + + ;
C_ReportError ( ERROR_NOTAGAMEVAR ) ;
continue ;
}
if ( EDUKE32_PREDICT_FALSE ( aGameVars [ i ] . flags & GAMEVAR_READONLY ) )
{
g_errorCnt + + ;
C_ReportError ( ERROR_VARREADONLY ) ;
continue ;
}
switch ( tw )
{
case CON_SETACTORVAR :
if ( EDUKE32_PREDICT_FALSE ( ! ( aGameVars [ i ] . flags & GAMEVAR_PERACTOR ) ) )
{
g_errorCnt + + ;
C_ReportError ( - 1 ) ;
initprintf ( " %s:%d: error: variable `%s' is not per-actor. \n " , g_scriptFileName , g_lineNumber , LAST_LABEL ) ;
continue ;
}
break ;
case CON_SETPLAYERVAR :
if ( EDUKE32_PREDICT_FALSE ( ! ( aGameVars [ i ] . flags & GAMEVAR_PERPLAYER ) ) )
{
g_errorCnt + + ;
C_ReportError ( - 1 ) ;
initprintf ( " %s:%d: error: variable `%s' is not per-player. \n " , g_scriptFileName , g_lineNumber , LAST_LABEL ) ;
continue ;
}
break ;
}
scriptWriteValue ( i ) ; // the ID of the DEF (offset into array...)
switch ( tw )
{
case CON_GETACTORVAR :
case CON_GETPLAYERVAR :
C_GetNextVarType ( GAMEVAR_READONLY ) ;
break ;
default :
C_GetNextVar ( ) ;
break ;
}
continue ;
2011-04-07 01:16:29 +00:00
}
2015-01-17 00:27:19 +00:00
2011-04-07 01:16:29 +00:00
case CON_WRITEARRAYTOFILE :
case CON_READARRAYFROMFILE :
2018-05-23 05:58:17 +00:00
i = C_GetNextGameArrayName ( ) ;
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_FALSE ( i < 0 ) )
2011-04-07 01:16:29 +00:00
return 1 ;
2014-10-25 03:36:34 +00:00
2011-04-07 01:16:29 +00:00
C_GetNextValue ( LABEL_DEFINE ) ;
continue ;
2015-01-17 00:27:19 +00:00
2011-04-07 01:16:29 +00:00
case CON_COPY :
2018-05-23 05:58:17 +00:00
i = C_GetNextGameArrayName ( ) ;
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_FALSE ( i < 0 ) )
2011-04-07 01:16:29 +00:00
return 1 ;
2018-05-23 05:58:17 +00:00
C_SkipComments ( ) ;
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_FALSE ( * textptr ! = ' [ ' ) )
2011-04-07 01:16:29 +00:00
{
2016-08-27 01:42:01 +00:00
g_errorCnt + + ;
2011-04-07 01:16:29 +00:00
C_ReportError ( ERROR_GAMEARRAYBNO ) ;
return 1 ;
}
textptr + + ;
2008-11-20 14:06:36 +00:00
C_GetNextVar ( ) ;
2018-05-23 05:58:17 +00:00
C_SkipComments ( ) ;
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_FALSE ( * textptr ! = ' ] ' ) )
2011-04-07 01:16:29 +00:00
{
2016-08-27 01:42:01 +00:00
g_errorCnt + + ;
2011-04-07 01:16:29 +00:00
C_ReportError ( ERROR_GAMEARRAYBNC ) ;
return 1 ;
}
textptr + + ;
2017-07-18 20:53:41 +00:00
fallthrough__ ;
2011-04-07 01:16:29 +00:00
case CON_SETARRAY :
2018-05-23 05:58:17 +00:00
i = C_GetNextGameArrayName ( ) ;
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_FALSE ( i < 0 ) )
return 1 ;
2016-08-27 01:40:35 +00:00
if ( EDUKE32_PREDICT_FALSE ( aGameArrays [ i ] . flags & GAMEARRAY_READONLY ) )
2011-04-07 01:16:29 +00:00
{
2014-10-25 03:36:34 +00:00
C_ReportError ( ERROR_ARRAYREADONLY ) ;
2016-08-27 01:42:01 +00:00
g_errorCnt + + ;
2011-04-07 01:16:29 +00:00
return 1 ;
}
2018-05-23 05:58:17 +00:00
C_SkipComments ( ) ;
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_FALSE ( * textptr ! = ' [ ' ) )
2011-04-07 01:16:29 +00:00
{
2016-08-27 01:42:01 +00:00
g_errorCnt + + ;
2011-04-07 01:16:29 +00:00
C_ReportError ( ERROR_GAMEARRAYBNO ) ;
return 1 ;
}
textptr + + ;
C_GetNextVar ( ) ;
2018-05-23 05:58:17 +00:00
C_SkipComments ( ) ;
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_FALSE ( * textptr ! = ' ] ' ) )
2011-04-07 01:16:29 +00:00
{
2016-08-27 01:42:01 +00:00
g_errorCnt + + ;
2011-04-07 01:16:29 +00:00
C_ReportError ( ERROR_GAMEARRAYBNC ) ;
return 1 ;
}
textptr + + ;
C_GetNextVar ( ) ;
continue ;
2015-01-17 00:27:19 +00:00
2011-04-07 01:16:29 +00:00
case CON_GETARRAYSIZE :
2018-05-23 05:58:17 +00:00
i = C_GetNextGameArrayName ( ) ;
if ( EDUKE32_PREDICT_FALSE ( i < 0 ) )
return 1 ;
C_SkipComments ( ) ;
C_GetNextVarType ( GAMEVAR_READONLY ) ;
continue ;
2011-04-07 01:16:29 +00:00
case CON_RESIZEARRAY :
2018-05-23 05:58:17 +00:00
i = C_GetNextGameArrayName ( ) ;
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_FALSE ( i < 0 ) )
2011-04-07 01:16:29 +00:00
return 1 ;
2006-04-13 20:47:06 +00:00
2018-05-23 05:58:17 +00:00
if ( aGameArrays [ i ] . flags & ( GAMEARRAY_READONLY | GAMEARRAY_SYSTEM ) )
2014-10-25 03:36:34 +00:00
{
2018-05-23 05:58:21 +00:00
g_errorCnt + + ;
2014-10-25 03:36:34 +00:00
C_ReportError ( - 1 ) ;
2018-11-18 18:11:09 +00:00
initprintf ( " %s:%d: error: can't resize system array `%s'. \n " , g_scriptFileName , g_lineNumber , LAST_LABEL ) ;
2014-10-25 03:36:34 +00:00
return 1 ;
}
2011-04-07 01:16:29 +00:00
C_SkipComments ( ) ;
2018-05-23 05:58:17 +00:00
C_GetNextVarType ( 0 ) ;
2011-04-07 01:16:29 +00:00
continue ;
2018-05-23 05:58:21 +00:00
case CON_SWAPARRAYS :
i = C_GetNextGameArrayName ( ) ;
if ( EDUKE32_PREDICT_FALSE ( i < 0 ) )
return 1 ;
if ( aGameArrays [ i ] . flags & ( GAMEARRAY_READONLY | GAMEARRAY_SYSTEM | GAMEARRAY_VARSIZE ) )
{
g_errorCnt + + ;
C_ReportError ( - 1 ) ;
2018-11-18 18:11:09 +00:00
initprintf ( " %s:%d: error: can't swap system array `%s'. \n " , g_scriptFileName , g_lineNumber , LAST_LABEL ) ;
2018-05-23 05:58:21 +00:00
return 1 ;
}
C_SkipComments ( ) ;
tw = C_GetNextGameArrayName ( ) ;
if ( EDUKE32_PREDICT_FALSE ( tw < 0 ) )
return 1 ;
if ( aGameArrays [ tw ] . flags & ( GAMEARRAY_READONLY | GAMEARRAY_SYSTEM | GAMEARRAY_VARSIZE ) )
{
g_errorCnt + + ;
C_ReportError ( - 1 ) ;
2018-11-18 18:11:09 +00:00
initprintf ( " %s:%d: error: can't swap system array `%s'. \n " , g_scriptFileName , g_lineNumber , LAST_LABEL ) ;
2018-05-23 05:58:21 +00:00
return 1 ;
}
if ( ( aGameArrays [ i ] . flags & GAMEARRAY_STORAGE_MASK ) ! = ( aGameArrays [ tw ] . flags & GAMEARRAY_STORAGE_MASK ) )
{
g_errorCnt + + ;
C_ReportError ( - 1 ) ;
initprintf ( " %s:%d: error: can't swap arrays of different storage classes. \n " , g_scriptFileName , g_lineNumber ) ;
return 1 ;
}
continue ;
2011-04-07 01:16:29 +00:00
case CON_ACTIVATEBYSECTOR :
2018-12-15 01:37:49 +00:00
case CON_ADDWEAPON :
2006-04-16 03:42:36 +00:00
case CON_DIST :
2018-11-18 18:10:15 +00:00
case CON_DIVSCALE :
2011-04-07 01:16:29 +00:00
case CON_GETANGLE :
2018-11-18 18:10:15 +00:00
case CON_GETINCANGLE :
case CON_GMAXAMMO :
case CON_LDIST :
2006-04-16 03:42:36 +00:00
case CON_MULSCALE :
2018-11-18 18:10:15 +00:00
case CON_OPERATEACTIVATORS :
case CON_OPERATESECTORS :
2016-10-20 06:26:10 +00:00
case CON_SCALEVAR :
2011-04-07 01:16:29 +00:00
case CON_SETASPECT :
2018-11-18 18:10:15 +00:00
case CON_SMAXAMMO :
case CON_SSP :
2011-04-07 01:16:29 +00:00
// get the ID of the DEF
switch ( tw )
{
case CON_DIST :
2018-11-18 18:10:15 +00:00
case CON_DIVSCALE :
2011-04-07 01:16:29 +00:00
case CON_GETANGLE :
case CON_GETINCANGLE :
2018-11-18 18:10:15 +00:00
case CON_LDIST :
2012-04-22 19:11:01 +00:00
case CON_MULSCALE :
2016-10-20 06:26:10 +00:00
case CON_SCALEVAR :
2011-04-07 01:16:29 +00:00
C_GetNextVarType ( GAMEVAR_READONLY ) ;
break ;
default :
C_GetNextVar ( ) ;
break ;
}
2006-04-13 20:47:06 +00:00
2011-04-07 01:16:29 +00:00
// get the ID of the DEF
if ( tw = = CON_GMAXAMMO )
C_GetNextVarType ( GAMEVAR_READONLY ) ;
else C_GetNextVar ( ) ;
2006-11-13 23:12:47 +00:00
2011-04-07 01:16:29 +00:00
switch ( tw )
{
case CON_DIST :
case CON_GETANGLE :
case CON_GETINCANGLE :
2018-11-18 18:10:15 +00:00
case CON_LDIST :
2011-04-07 01:16:29 +00:00
C_GetNextVar ( ) ;
break ;
2016-10-20 06:26:10 +00:00
case CON_DIVSCALE :
2018-11-18 18:10:15 +00:00
case CON_MULSCALE :
2016-10-20 06:26:10 +00:00
case CON_SCALEVAR :
2011-04-07 01:16:29 +00:00
C_GetManyVars ( 2 ) ;
break ;
}
continue ;
2006-11-16 03:02:42 +00:00
2011-04-07 01:16:29 +00:00
case CON_FLASH :
case CON_SAVEMAPSTATE :
case CON_LOADMAPSTATE :
2011-08-03 17:22:46 +00:00
if ( tw ! = CON_FLASH )
{
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_FALSE ( g_currentEvent = = EVENT_ANIMATESPRITES ) )
2011-08-03 17:22:46 +00:00
{
initprintf ( " %s:%d: warning: found `%s' inside EVENT_ANIMATESPRITES \n " ,
2016-08-27 01:42:01 +00:00
g_scriptFileName , g_lineNumber , tempbuf ) ;
g_warningCnt + + ;
2011-08-03 17:22:46 +00:00
}
}
2011-04-07 01:16:29 +00:00
continue ;
2006-11-16 03:02:42 +00:00
2013-05-23 18:28:04 +00:00
case CON_ACTIVATE :
2018-12-15 01:39:08 +00:00
g_scriptPtr [ - 1 ] = CON_OPERATEACTIVATORS | LINE_NUMBER ;
2013-05-23 18:28:04 +00:00
C_GetNextValue ( LABEL_DEFINE ) ;
2018-11-18 18:14:20 +00:00
scriptWriteValue ( 0 ) ;
2013-05-23 18:28:04 +00:00
continue ;
2011-04-07 01:16:29 +00:00
case CON_GETFLORZOFSLOPE :
case CON_GETCEILZOFSLOPE :
2017-08-01 09:48:55 +00:00
case CON_UPDATESECTORZ :
2011-04-07 01:16:29 +00:00
C_GetManyVars ( 3 ) ;
C_GetNextVarType ( GAMEVAR_READONLY ) ;
continue ;
2006-11-13 23:12:47 +00:00
2011-04-07 01:16:29 +00:00
case CON_DEFINEPROJECTILE :
{
int32_t y , z ;
2006-11-13 23:12:47 +00:00
2018-12-15 01:36:42 +00:00
if ( EDUKE32_PREDICT_FALSE ( g_processingState | | g_scriptActorOffset ) )
2011-04-07 01:16:29 +00:00
{
C_ReportError ( ERROR_FOUNDWITHIN ) ;
2016-08-27 01:42:01 +00:00
g_errorCnt + + ;
2011-04-07 01:16:29 +00:00
}
2006-11-13 23:12:47 +00:00
2011-04-07 01:16:29 +00:00
g_scriptPtr - - ;
2006-04-13 20:47:06 +00:00
2011-04-07 01:16:29 +00:00
C_GetNextValue ( LABEL_DEFINE ) ;
2018-12-15 01:36:27 +00:00
j = g_scriptPtr [ - 1 ] ;
2018-12-15 01:39:14 +00:00
g_scriptPtr - - ;
2006-11-16 03:02:42 +00:00
2011-04-07 01:16:29 +00:00
C_GetNextValue ( LABEL_DEFINE ) ;
2018-12-15 01:36:27 +00:00
y = g_scriptPtr [ - 1 ] ;
2018-12-15 01:39:14 +00:00
g_scriptPtr - - ;
2011-04-07 01:16:29 +00:00
C_GetNextValue ( LABEL_DEFINE ) ;
2018-12-15 01:36:27 +00:00
z = g_scriptPtr [ - 1 ] ;
2018-12-15 01:39:14 +00:00
g_scriptPtr - - ;
2006-04-13 20:47:06 +00:00
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_FALSE ( ( unsigned ) j > = MAXTILES ) )
2012-05-13 16:05:34 +00:00
{
C_ReportError ( ERROR_EXCEEDSMAXTILES ) ;
2016-08-27 01:42:01 +00:00
g_errorCnt + + ;
2012-05-13 16:05:34 +00:00
continue ;
}
2013-02-07 21:01:03 +00:00
C_DefineProjectile ( j , y , z ) ;
2011-04-07 01:16:29 +00:00
continue ;
}
2006-04-13 20:47:06 +00:00
2018-03-17 03:26:10 +00:00
case CON_DAMAGEEVENTTILE :
{
2018-12-15 01:36:42 +00:00
if ( EDUKE32_PREDICT_FALSE ( g_processingState | | g_scriptActorOffset ) )
2018-03-17 03:26:10 +00:00
{
C_ReportError ( ERROR_FOUNDWITHIN ) ;
g_errorCnt + + ;
}
g_scriptPtr - - ;
C_GetNextValue ( LABEL_DEFINE ) ;
2018-12-15 01:36:27 +00:00
j = g_scriptPtr [ - 1 ] ;
2018-12-15 01:39:14 +00:00
g_scriptPtr - - ;
2018-03-17 03:26:10 +00:00
if ( EDUKE32_PREDICT_FALSE ( ( unsigned ) j > = MAXTILES ) )
{
C_ReportError ( ERROR_EXCEEDSMAXTILES ) ;
g_errorCnt + + ;
continue ;
}
g_tile [ j ] . flags | = SFLAG_DAMAGEEVENT ;
continue ;
}
case CON_DAMAGEEVENTTILERANGE :
{
2018-12-15 01:36:42 +00:00
if ( EDUKE32_PREDICT_FALSE ( g_processingState | | g_scriptActorOffset ) )
2018-03-17 03:26:10 +00:00
{
C_ReportError ( ERROR_FOUNDWITHIN ) ;
g_errorCnt + + ;
}
g_scriptPtr - - ;
C_GetNextValue ( LABEL_DEFINE ) ;
2018-12-15 01:36:27 +00:00
i = g_scriptPtr [ - 1 ] ;
2018-12-15 01:39:14 +00:00
g_scriptPtr - - ;
2018-03-17 03:26:10 +00:00
C_GetNextValue ( LABEL_DEFINE ) ;
2018-12-15 01:36:27 +00:00
j = g_scriptPtr [ - 1 ] ;
2018-12-15 01:39:14 +00:00
g_scriptPtr - - ;
2018-03-17 03:26:10 +00:00
if ( EDUKE32_PREDICT_FALSE ( ( unsigned ) i > = MAXTILES | | ( unsigned ) j > = MAXTILES ) )
{
C_ReportError ( ERROR_EXCEEDSMAXTILES ) ;
g_errorCnt + + ;
continue ;
}
for ( tiledata_t * t = g_tile + i , * t_end = g_tile + j ; t < = t_end ; + + t )
t - > flags | = SFLAG_DAMAGEEVENT ;
continue ;
}
2011-04-07 01:16:29 +00:00
case CON_SPRITEFLAGS :
2018-12-15 01:36:42 +00:00
if ( ! g_scriptActorOffset & & g_processingState = = 0 )
2011-04-07 01:16:29 +00:00
{
g_scriptPtr - - ;
2018-12-15 01:39:14 +00:00
auto tmpscrptr = g_scriptPtr ;
2006-04-13 20:47:06 +00:00
2011-04-07 01:16:29 +00:00
C_GetNextValue ( LABEL_DEFINE ) ;
2018-12-15 01:39:14 +00:00
j = g_scriptPtr [ - 1 ] ;
2006-11-13 23:12:47 +00:00
2014-12-26 17:29:58 +00:00
int32_t flags = 0 ;
do
C_BitOrNextValue ( & flags ) ;
while ( C_GetKeyword ( ) = = - 1 ) ;
2012-05-13 16:05:34 +00:00
2018-12-15 01:39:14 +00:00
g_scriptPtr = tmpscrptr ;
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_FALSE ( ( unsigned ) j > = MAXTILES ) )
2011-04-07 01:16:29 +00:00
{
C_ReportError ( ERROR_EXCEEDSMAXTILES ) ;
2016-08-27 01:42:01 +00:00
g_errorCnt + + ;
2012-05-13 16:05:34 +00:00
continue ;
2011-04-07 01:16:29 +00:00
}
2006-11-13 23:12:47 +00:00
2014-12-26 17:29:58 +00:00
g_tile [ j ] . flags = flags ;
2011-04-07 01:16:29 +00:00
}
2018-12-15 01:39:14 +00:00
else C_GetNextVar ( ) ;
2011-04-07 01:16:29 +00:00
continue ;
2006-04-13 20:47:06 +00:00
2006-11-13 23:12:47 +00:00
case CON_PRECACHE :
2018-11-18 18:10:15 +00:00
case CON_SPRITENOPAL :
case CON_SPRITENOSHADE :
case CON_SPRITENVG :
case CON_SPRITESHADOW :
2018-12-15 01:36:42 +00:00
if ( EDUKE32_PREDICT_FALSE ( g_processingState | | g_scriptActorOffset ) )
2011-04-07 01:16:29 +00:00
{
C_ReportError ( ERROR_FOUNDWITHIN ) ;
2016-08-27 01:42:01 +00:00
g_errorCnt + + ;
2018-12-15 01:39:08 +00:00
scriptSkipLine ( ) ;
continue ;
2011-04-07 01:16:29 +00:00
}
g_scriptPtr - - ;
2008-11-20 14:06:36 +00:00
C_GetNextValue ( LABEL_DEFINE ) ;
g_scriptPtr - - ;
2011-04-07 01:16:29 +00:00
j = * g_scriptPtr ;
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_FALSE ( ( unsigned ) j > = MAXTILES ) )
2006-04-13 20:47:06 +00:00
{
2008-11-20 14:06:36 +00:00
C_ReportError ( ERROR_EXCEEDSMAXTILES ) ;
2016-08-27 01:42:01 +00:00
g_errorCnt + + ;
2018-12-15 01:39:08 +00:00
scriptSkipLine ( ) ;
2012-05-13 16:05:34 +00:00
continue ;
2006-04-13 20:47:06 +00:00
}
2011-04-07 01:16:29 +00:00
switch ( tw )
{
case CON_SPRITESHADOW :
2014-02-22 19:38:52 +00:00
g_tile [ * g_scriptPtr ] . flags | = SFLAG_SHADOW ;
2011-04-07 01:16:29 +00:00
break ;
case CON_SPRITENVG :
2014-02-22 19:38:52 +00:00
g_tile [ * g_scriptPtr ] . flags | = SFLAG_NVG ;
2011-04-07 01:16:29 +00:00
break ;
case CON_SPRITENOSHADE :
2014-02-22 19:38:52 +00:00
g_tile [ * g_scriptPtr ] . flags | = SFLAG_NOSHADE ;
2011-04-07 01:16:29 +00:00
break ;
case CON_SPRITENOPAL :
2014-02-22 19:38:52 +00:00
g_tile [ * g_scriptPtr ] . flags | = SFLAG_NOPAL ;
2011-04-07 01:16:29 +00:00
break ;
case CON_PRECACHE :
C_GetNextValue ( LABEL_DEFINE ) ;
g_scriptPtr - - ;
i = * g_scriptPtr ;
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_FALSE ( ( unsigned ) i > = MAXTILES ) )
2011-04-07 01:16:29 +00:00
{
C_ReportError ( ERROR_EXCEEDSMAXTILES ) ;
2016-08-27 01:42:01 +00:00
g_errorCnt + + ;
2018-12-15 01:39:08 +00:00
scriptSkipLine ( ) ;
continue ;
2011-04-07 01:16:29 +00:00
}
2012-11-15 14:28:00 +00:00
g_tile [ j ] . cacherange = i ;
2011-04-07 01:16:29 +00:00
C_GetNextValue ( LABEL_DEFINE ) ;
g_scriptPtr - - ;
2012-11-15 14:28:00 +00:00
if ( * g_scriptPtr )
2014-02-22 19:38:52 +00:00
g_tile [ j ] . flags | = SFLAG_CACHE ;
2012-11-15 14:28:00 +00:00
2011-04-07 01:16:29 +00:00
break ;
}
continue ;
2009-01-04 22:22:33 +00:00
2011-04-07 01:16:29 +00:00
case CON_IFACTORSOUND :
2018-01-31 05:23:48 +00:00
case CON_IFVARVARA :
case CON_IFVARVARAE :
2018-11-18 18:10:15 +00:00
case CON_IFVARVARAND :
case CON_IFVARVARB :
2018-01-31 05:23:48 +00:00
case CON_IFVARVARBE :
Adds the following keywords from M32script into CON: shiftvarvarl, shiftvarvarr, ifvarvarle, ifvarvarge, ifvarvarboth, whilevarl, and whilevarvarl.
This also adds the shorthand versions of some commands, like "set" for "setvarvar", "add" for "addvarvar", "ife" for "ifvarvare", etc. There are about 30 of these. Because some of these names may already be used in some projects as variable names, this revision also includes a somewhat large change in variable naming rules: gamevars may now have the same names as CON keywords, with the caveat that the masked keyword is no longer accessible. This results in a warning at compile time but should ensure nobody's project ever stops compiling due to the introduction of new keywords.
git-svn-id: https://svn.eduke32.com/eduke32@5499 1a8010ca-5511-0410-912e-c29ae57300e0
2016-01-02 01:56:20 +00:00
case CON_IFVARVARBOTH :
2018-11-18 18:10:15 +00:00
case CON_IFVARVARE :
case CON_IFVARVAREITHER :
case CON_IFVARVARG :
case CON_IFVARVARGE :
case CON_IFVARVARL :
case CON_IFVARVARLE :
2011-04-07 01:16:29 +00:00
case CON_IFVARVARN :
case CON_IFVARVAROR :
case CON_IFVARVARXOR :
Adds the following keywords from M32script into CON: shiftvarvarl, shiftvarvarr, ifvarvarle, ifvarvarge, ifvarvarboth, whilevarl, and whilevarvarl.
This also adds the shorthand versions of some commands, like "set" for "setvarvar", "add" for "addvarvar", "ife" for "ifvarvare", etc. There are about 30 of these. Because some of these names may already be used in some projects as variable names, this revision also includes a somewhat large change in variable naming rules: gamevars may now have the same names as CON keywords, with the caveat that the masked keyword is no longer accessible. This results in a warning at compile time but should ensure nobody's project ever stops compiling due to the introduction of new keywords.
git-svn-id: https://svn.eduke32.com/eduke32@5499 1a8010ca-5511-0410-912e-c29ae57300e0
2016-01-02 01:56:20 +00:00
case CON_WHILEVARVARL :
2018-11-18 18:10:15 +00:00
case CON_WHILEVARVARN :
2011-04-07 01:16:29 +00:00
{
2018-12-15 01:37:13 +00:00
auto const ins = & g_scriptPtr [ - 1 ] ;
auto const lastScriptPtr = & g_scriptPtr [ - 1 ] - apScript ;
auto const lasttextptr = textptr ;
2018-12-15 01:39:08 +00:00
int const lnum = g_lineNumber ;
2007-08-29 04:01:21 +00:00
2018-12-15 01:36:42 +00:00
g_skipBranch = false ;
2009-06-18 05:57:10 +00:00
2018-12-15 01:37:13 +00:00
C_GetNextVar ( ) ;
auto const var = g_scriptPtr ;
C_GetNextVar ( ) ;
if ( * var = = GV_FLAG_CONSTANT )
{
int const opcode = inthash_find ( & h_varvar , tw ) ;
if ( opcode ! = - 1 )
{
2018-12-15 01:38:05 +00:00
if ( g_scriptDebug > 1 & & ! g_errorCnt & & ! g_warningCnt )
2018-12-15 01:37:13 +00:00
{
initprintf ( " %s:%d: replacing %s with %s \n " , g_scriptFileName , g_lineNumber ,
VM_GetKeywordForID ( * ins & VM_INSTMASK ) , VM_GetKeywordForID ( opcode ) ) ;
}
scriptWriteAtOffset ( opcode | LINE_NUMBER , ins ) ;
tw = opcode ;
g_scriptPtr = & ins [ 1 ] ;
textptr = lasttextptr ;
2018-12-15 01:39:08 +00:00
g_lineNumber = lnum ;
2018-12-15 01:38:16 +00:00
goto ifvar ;
2018-12-15 01:37:13 +00:00
}
}
2009-06-18 05:57:10 +00:00
2011-04-07 01:16:29 +00:00
if ( C_CheckMalformedBranch ( lastScriptPtr ) )
continue ;
2006-04-13 20:47:06 +00:00
2018-12-15 01:37:13 +00:00
auto const offset = g_scriptPtr - apScript ;
2011-04-07 01:16:29 +00:00
g_scriptPtr + + ; // Leave a spot for the fail location
2006-04-13 20:47:06 +00:00
2011-04-07 01:16:29 +00:00
C_ParseCommand ( 0 ) ;
2009-01-04 22:22:33 +00:00
2011-04-07 01:16:29 +00:00
if ( C_CheckEmptyBranch ( tw , lastScriptPtr ) )
continue ;
2006-04-13 20:47:06 +00:00
2018-12-15 01:37:13 +00:00
auto const tempscrptr = apScript + offset ;
2018-11-18 18:14:20 +00:00
scriptWritePointer ( ( intptr_t ) g_scriptPtr , tempscrptr ) ;
2009-01-05 14:43:12 +00:00
2018-12-15 01:37:08 +00:00
if ( tw ! = CON_WHILEVARVARN & & tw ! = CON_WHILEVARVARL )
2011-04-07 01:16:29 +00:00
{
j = C_GetKeyword ( ) ;
2006-04-13 20:47:06 +00:00
2011-04-07 01:16:29 +00:00
if ( j = = CON_ELSE | | j = = CON_LEFTBRACE )
g_checkingIfElse + + ;
}
continue ;
}
2006-04-13 20:47:06 +00:00
2018-01-31 05:23:48 +00:00
case CON_IFVARA :
case CON_IFVARAE :
2018-11-18 18:10:15 +00:00
case CON_IFVARAND :
2018-01-31 05:23:48 +00:00
case CON_IFVARB :
case CON_IFVARBE :
2018-11-18 18:10:15 +00:00
case CON_IFVARBOTH :
2011-04-07 01:16:29 +00:00
case CON_IFVARE :
2018-11-18 18:10:15 +00:00
case CON_IFVAREITHER :
case CON_IFVARG :
case CON_IFVARGE :
case CON_IFVARL :
case CON_IFVARLE :
2011-04-07 01:16:29 +00:00
case CON_IFVARN :
case CON_IFVAROR :
case CON_IFVARXOR :
Adds the following keywords from M32script into CON: shiftvarvarl, shiftvarvarr, ifvarvarle, ifvarvarge, ifvarvarboth, whilevarl, and whilevarvarl.
This also adds the shorthand versions of some commands, like "set" for "setvarvar", "add" for "addvarvar", "ife" for "ifvarvare", etc. There are about 30 of these. Because some of these names may already be used in some projects as variable names, this revision also includes a somewhat large change in variable naming rules: gamevars may now have the same names as CON keywords, with the caveat that the masked keyword is no longer accessible. This results in a warning at compile time but should ensure nobody's project ever stops compiling due to the introduction of new keywords.
git-svn-id: https://svn.eduke32.com/eduke32@5499 1a8010ca-5511-0410-912e-c29ae57300e0
2016-01-02 01:56:20 +00:00
case CON_WHILEVARL :
2018-11-18 18:10:15 +00:00
case CON_WHILEVARN :
2011-04-07 01:16:29 +00:00
{
2018-12-15 01:38:16 +00:00
ifvar :
2018-12-15 01:38:00 +00:00
auto const ins = & g_scriptPtr [ - 1 ] ;
2018-12-15 01:37:13 +00:00
auto const lastScriptPtr = & g_scriptPtr [ - 1 ] - apScript ;
2006-04-13 20:47:06 +00:00
2018-12-15 01:36:42 +00:00
g_skipBranch = false ;
2018-12-15 01:37:13 +00:00
2011-04-07 01:16:29 +00:00
C_GetNextVar ( ) ;
2018-12-15 01:37:13 +00:00
C_GetNextValue ( LABEL_DEFINE ) ;
2009-06-18 05:57:10 +00:00
2011-04-07 01:16:29 +00:00
if ( C_CheckMalformedBranch ( lastScriptPtr ) )
continue ;
2006-04-13 20:47:06 +00:00
2018-12-15 01:38:16 +00:00
scriptUpdateOpcodeForVariableType ( ins ) ;
2018-12-15 01:38:00 +00:00
2018-12-15 01:37:13 +00:00
auto const offset = g_scriptPtr - apScript ;
2011-04-07 01:16:29 +00:00
g_scriptPtr + + ; //Leave a spot for the fail location
2006-04-13 20:47:06 +00:00
2011-04-07 01:16:29 +00:00
C_ParseCommand ( 0 ) ;
2009-01-04 22:22:33 +00:00
2011-04-07 01:16:29 +00:00
if ( C_CheckEmptyBranch ( tw , lastScriptPtr ) )
continue ;
2006-04-13 20:47:06 +00:00
2018-12-15 01:37:13 +00:00
auto const tempscrptr = apScript + offset ;
2018-11-18 18:14:20 +00:00
scriptWritePointer ( ( intptr_t ) g_scriptPtr , tempscrptr ) ;
2009-01-05 14:43:12 +00:00
Adds the following keywords from M32script into CON: shiftvarvarl, shiftvarvarr, ifvarvarle, ifvarvarge, ifvarvarboth, whilevarl, and whilevarvarl.
This also adds the shorthand versions of some commands, like "set" for "setvarvar", "add" for "addvarvar", "ife" for "ifvarvare", etc. There are about 30 of these. Because some of these names may already be used in some projects as variable names, this revision also includes a somewhat large change in variable naming rules: gamevars may now have the same names as CON keywords, with the caveat that the masked keyword is no longer accessible. This results in a warning at compile time but should ensure nobody's project ever stops compiling due to the introduction of new keywords.
git-svn-id: https://svn.eduke32.com/eduke32@5499 1a8010ca-5511-0410-912e-c29ae57300e0
2016-01-02 01:56:20 +00:00
if ( tw ! = CON_WHILEVARN & & tw ! = CON_WHILEVARL )
2011-04-07 01:16:29 +00:00
{
j = C_GetKeyword ( ) ;
2009-01-05 14:43:12 +00:00
2011-04-07 01:16:29 +00:00
if ( j = = CON_ELSE | | j = = CON_LEFTBRACE )
g_checkingIfElse + + ;
}
2006-11-15 01:16:55 +00:00
2011-04-07 01:16:29 +00:00
continue ;
}
2006-11-15 01:16:55 +00:00
2016-02-02 00:21:24 +00:00
case CON_FOR : // special-purpose iteration
{
C_GetNextVarType ( GAMEVAR_READONLY ) ;
C_GetNextLabelName ( ) ;
2018-11-18 18:11:09 +00:00
int const iterType = hash_find ( & h_iter , LAST_LABEL ) ;
2016-08-27 01:42:01 +00:00
2018-11-18 18:14:43 +00:00
if ( EDUKE32_PREDICT_FALSE ( iterType < 0 ) )
2016-02-02 00:21:24 +00:00
{
2018-11-18 18:11:09 +00:00
C_CUSTOMERROR ( " unknown iteration type `%s'. " , LAST_LABEL ) ;
2016-02-02 00:21:24 +00:00
return 1 ;
}
2018-11-18 18:14:43 +00:00
2018-11-18 18:14:20 +00:00
scriptWriteValue ( iterType ) ;
2016-02-02 00:21:24 +00:00
2016-08-27 01:42:01 +00:00
if ( iterType > = ITER_SPRITESOFSECTOR )
2016-02-02 00:21:24 +00:00
C_GetNextVar ( ) ;
2018-11-18 18:14:43 +00:00
intptr_t const offset = g_scriptPtr - apScript ;
2016-02-02 00:21:24 +00:00
g_scriptPtr + + ; //Leave a spot for the location to jump to after completion
C_ParseCommand ( 0 ) ;
2018-11-18 18:14:20 +00:00
// write relative offset
auto const tscrptr = ( intptr_t * ) apScript + offset ;
scriptWriteAtOffset ( ( g_scriptPtr - apScript ) - offset , tscrptr ) ;
2016-02-02 00:21:24 +00:00
continue ;
}
2011-04-07 01:16:29 +00:00
case CON_ROTATESPRITE16 :
case CON_ROTATESPRITE :
2018-12-15 01:36:42 +00:00
if ( EDUKE32_PREDICT_FALSE ( ! g_scriptEventOffset & & g_processingState = = 0 ) )
2011-04-07 01:16:29 +00:00
{
C_ReportError ( ERROR_EVENTONLY ) ;
2016-08-27 01:42:01 +00:00
g_errorCnt + + ;
2011-04-07 01:16:29 +00:00
}
2006-11-15 01:16:55 +00:00
2011-04-07 01:16:29 +00:00
// syntax:
// int32_t x, int32_t y, int32_t z, short a, short tilenum, int8_t shade, char orientation, x1, y1, x2, y2
// myospal adds char pal
2006-11-15 01:16:55 +00:00
2011-04-07 01:16:29 +00:00
// get the ID of the DEFs
2006-11-15 01:16:55 +00:00
2011-04-07 01:16:29 +00:00
C_GetManyVars ( 12 ) ;
2011-05-20 02:34:41 +00:00
continue ;
2006-11-16 03:02:42 +00:00
2013-03-25 04:33:03 +00:00
case CON_ROTATESPRITEA :
2018-12-15 01:36:42 +00:00
if ( EDUKE32_PREDICT_FALSE ( ! g_scriptEventOffset & & g_processingState = = 0 ) )
2013-03-25 04:33:03 +00:00
{
C_ReportError ( ERROR_EVENTONLY ) ;
2016-08-27 01:42:01 +00:00
g_errorCnt + + ;
2013-03-25 04:33:03 +00:00
}
C_GetManyVars ( 13 ) ;
continue ;
2011-04-07 01:16:29 +00:00
case CON_SHOWVIEW :
2012-03-31 11:22:00 +00:00
case CON_SHOWVIEWUNBIASED :
2018-03-07 12:02:03 +00:00
case CON_SHOWVIEWQ16 :
case CON_SHOWVIEWQ16UNBIASED :
2018-12-15 01:36:42 +00:00
if ( EDUKE32_PREDICT_FALSE ( ! g_scriptEventOffset & & g_processingState = = 0 ) )
2011-04-07 01:16:29 +00:00
{
C_ReportError ( ERROR_EVENTONLY ) ;
2016-08-27 01:42:01 +00:00
g_errorCnt + + ;
2011-04-07 01:16:29 +00:00
}
2006-11-16 03:02:42 +00:00
2011-04-07 01:16:29 +00:00
C_GetManyVars ( 10 ) ;
2011-05-20 02:34:41 +00:00
continue ;
2006-11-16 03:02:42 +00:00
2011-04-07 01:16:29 +00:00
case CON_GETZRANGE :
C_GetManyVars ( 4 ) ;
C_GetManyVarsType ( GAMEVAR_READONLY , 4 ) ;
C_GetManyVars ( 2 ) ;
2011-05-20 02:34:41 +00:00
continue ;
2007-02-08 04:19:39 +00:00
2011-04-07 01:16:29 +00:00
case CON_CLIPMOVE :
case CON_CLIPMOVENOSLIDE :
// <retvar>,<x>,<y>,z,<sectnum>, xvect,yvect,walldist,floordist,ceildist,clipmask
C_GetManyVarsType ( GAMEVAR_READONLY , 3 ) ;
2008-11-20 14:06:36 +00:00
C_GetNextVar ( ) ;
2011-04-07 01:16:29 +00:00
C_GetNextVarType ( GAMEVAR_READONLY ) ;
C_GetManyVars ( 6 ) ;
2011-05-20 02:34:41 +00:00
continue ;
2006-04-13 20:47:06 +00:00
2011-04-07 01:16:29 +00:00
case CON_LINEINTERSECT :
case CON_RAYINTERSECT :
// lineintersect x y z x y z x y x y <intx> <inty> <intz> <ret>
// rayintersect x y z vx vy vz x y x y <intx> <inty> <intz> <ret>
C_GetManyVars ( 10 ) ;
C_GetManyVarsType ( GAMEVAR_READONLY , 4 ) ;
2011-05-20 02:34:41 +00:00
continue ;
2006-04-13 20:47:06 +00:00
2011-04-07 01:16:29 +00:00
case CON_HITSCAN :
case CON_CANSEE :
2006-11-16 03:02:42 +00:00
// get the ID of the DEF
2011-04-07 01:16:29 +00:00
C_GetManyVars ( tw = = CON_CANSEE ? 8 : 7 ) ;
C_GetManyVarsType ( GAMEVAR_READONLY , tw = = CON_CANSEE ? 1 : 6 ) ;
if ( tw = = CON_HITSCAN ) C_GetNextVar ( ) ;
2011-05-20 02:34:41 +00:00
continue ;
2006-04-13 20:47:06 +00:00
2011-04-07 01:16:29 +00:00
case CON_CANSEESPR :
2017-08-01 09:48:55 +00:00
case CON_UPDATESECTOR :
2018-01-29 02:13:55 +00:00
case CON_QSTRCMP :
2011-04-07 01:16:29 +00:00
C_GetManyVars ( 2 ) ;
C_GetNextVarType ( GAMEVAR_READONLY ) ;
2011-05-20 02:34:41 +00:00
continue ;
2006-04-13 20:47:06 +00:00
2011-04-07 01:16:29 +00:00
case CON_NEARTAG :
C_GetManyVars ( 5 ) ;
C_GetManyVarsType ( GAMEVAR_READONLY , 4 ) ;
C_GetManyVars ( 2 ) ;
2011-05-20 02:34:41 +00:00
continue ;
2006-04-13 20:47:06 +00:00
2011-04-07 01:16:29 +00:00
case CON_ROTATEPOINT :
C_GetManyVars ( 5 ) ;
C_GetManyVarsType ( GAMEVAR_READONLY , 2 ) ;
2011-05-20 02:34:41 +00:00
continue ;
2006-11-15 01:16:55 +00:00
2011-04-07 01:16:29 +00:00
case CON_GETTIMEDATE :
C_GetManyVarsType ( GAMEVAR_READONLY , 8 ) ;
2011-05-20 02:34:41 +00:00
continue ;
2007-08-29 04:01:21 +00:00
2011-04-07 01:16:29 +00:00
case CON_MOVESPRITE :
2017-08-01 09:48:55 +00:00
C_GetManyVars ( 5 ) ;
C_GetNextVarType ( GAMEVAR_READONLY ) ;
2011-05-20 02:34:41 +00:00
continue ;
2006-04-13 20:47:06 +00:00
2011-04-07 01:16:29 +00:00
case CON_DIGITALNUMBER :
case CON_DIGITALNUMBERZ :
2018-11-18 18:10:15 +00:00
case CON_GAMETEXT :
case CON_GAMETEXTZ :
case CON_MINITEXT :
2013-06-01 06:55:00 +00:00
case CON_SCREENTEXT :
2018-12-15 01:36:42 +00:00
if ( EDUKE32_PREDICT_FALSE ( ! g_scriptEventOffset & & g_processingState = = 0 ) )
2011-04-07 01:16:29 +00:00
{
C_ReportError ( ERROR_EVENTONLY ) ;
2016-08-27 01:42:01 +00:00
g_errorCnt + + ;
2011-04-07 01:16:29 +00:00
}
switch ( tw )
{
2013-06-01 06:55:00 +00:00
case CON_SCREENTEXT :
C_GetManyVars ( 8 ) ;
2017-07-18 20:53:41 +00:00
fallthrough__ ;
2011-04-07 01:16:29 +00:00
case CON_GAMETEXTZ :
case CON_DIGITALNUMBERZ :
C_GetManyVars ( 1 ) ;
2017-07-18 20:53:41 +00:00
fallthrough__ ;
2011-04-07 01:16:29 +00:00
case CON_GAMETEXT :
case CON_DIGITALNUMBER :
C_GetManyVars ( 6 ) ;
2017-07-18 20:53:41 +00:00
fallthrough__ ;
2011-04-07 01:16:29 +00:00
default :
C_GetManyVars ( 5 ) ;
break ;
}
2011-05-20 02:34:41 +00:00
continue ;
2008-11-20 14:06:36 +00:00
2011-04-07 01:16:29 +00:00
case CON_MYOS :
case CON_MYOSPAL :
case CON_MYOSX :
case CON_MYOSPALX :
2018-12-15 01:36:42 +00:00
if ( EDUKE32_PREDICT_FALSE ( ! g_scriptEventOffset & & g_processingState = = 0 ) )
2011-04-07 01:16:29 +00:00
{
C_ReportError ( ERROR_EVENTONLY ) ;
2016-08-27 01:42:01 +00:00
g_errorCnt + + ;
2011-04-07 01:16:29 +00:00
}
2006-04-13 20:47:06 +00:00
2011-04-07 01:16:29 +00:00
// syntax:
// int32_t x, int32_t y, short tilenum, int8_t shade, char orientation
// myospal adds char pal
2007-08-31 06:18:56 +00:00
2011-04-07 01:16:29 +00:00
C_GetManyVars ( 5 ) ;
if ( tw = = CON_MYOSPAL | | tw = = CON_MYOSPALX )
{
// Parse: pal
2006-04-13 20:47:06 +00:00
2011-04-07 01:16:29 +00:00
// get the ID of the DEF
C_GetNextVar ( ) ;
}
2011-05-20 02:34:41 +00:00
continue ;
2006-04-13 20:47:06 +00:00
2011-04-07 01:16:29 +00:00
case CON_SWITCH :
2008-01-26 03:59:34 +00:00
{
2011-04-07 01:16:29 +00:00
g_checkingSwitch + + ; // allow nesting (if other things work)
C_GetNextVar ( ) ;
2018-11-18 18:14:15 +00:00
intptr_t const tempoffset = ( unsigned ) ( g_scriptPtr - apScript ) ;
2018-11-18 18:14:20 +00:00
scriptWriteValue ( 0 ) ; // leave spot for end location (for after processing)
scriptWriteValue ( 0 ) ; // count of case statements
2018-11-18 18:14:15 +00:00
2018-12-15 01:36:42 +00:00
auto const backupCaseScriptPtr = g_caseTablePtr ;
g_caseTablePtr = g_scriptPtr ; // the first case's pointer.
2018-11-18 18:14:15 +00:00
int const backupNumCases = g_numCases ;
2018-11-18 18:14:20 +00:00
scriptWriteValue ( 0 ) ; // leave spot for 'default' location (null if none)
2011-04-07 01:16:29 +00:00
2011-10-17 18:42:10 +00:00
// temptextptr=textptr;
2011-04-07 01:16:29 +00:00
// probably does not allow nesting...
j = C_CountCaseStatements ( ) ;
// initprintf("Done Counting Case Statements for switch %d: found %d.\n", g_checkingSwitch,j);
g_scriptPtr + = j * 2 ;
C_SkipComments ( ) ;
g_scriptPtr - = j * 2 ; // allocate buffer for the table
2018-11-18 18:14:15 +00:00
auto tempscrptr = ( intptr_t * ) ( apScript + tempoffset ) ;
2010-03-02 22:49:26 +00:00
2011-04-07 01:16:29 +00:00
//AddLog(g_szBuf);
2010-03-02 22:49:26 +00:00
2011-04-07 01:16:29 +00:00
if ( j < 0 )
{
return 1 ;
}
2006-11-16 03:02:42 +00:00
2011-04-07 01:16:29 +00:00
if ( tempscrptr )
2007-12-20 19:14:38 +00:00
{
2018-11-18 18:14:20 +00:00
// save count of cases
scriptWriteAtOffset ( j , & tempscrptr [ 1 ] ) ;
2011-04-07 01:16:29 +00:00
}
else
{
//Bsprintf(g_szBuf,"ERROR::%s %d",__FILE__,__LINE__);
//AddLog(g_szBuf);
2007-12-20 19:14:38 +00:00
}
2006-11-16 03:02:42 +00:00
2011-04-07 01:16:29 +00:00
while ( j - - )
{
// leave room for statements
2018-11-18 18:14:20 +00:00
scriptWriteValue ( 0 ) ; // value check
scriptWriteValue ( 0 ) ; // code offset
2011-04-07 01:16:29 +00:00
C_SkipComments ( ) ;
}
2010-03-02 22:49:26 +00:00
2011-04-07 01:16:29 +00:00
g_numCases = 0 ;
2011-05-20 02:34:41 +00:00
C_ParseCommand ( 1 ) ;
2016-08-27 01:40:35 +00:00
tempscrptr = ( intptr_t * ) ( apScript + tempoffset ) ;
2010-03-03 01:37:27 +00:00
2011-04-07 01:16:29 +00:00
//Bsprintf(g_szBuf,"SWITCHXX: '%.22s'",textptr);
//AddLog(g_szBuf);
// done processing switch. clean up.
if ( g_checkingSwitch < 1 )
{
// Bsprintf(g_szBuf,"ERROR::%s %d: g_checkingSwitch=%d",__FILE__,__LINE__, g_checkingSwitch);
// AddLog(g_szBuf);
}
g_numCases = 0 ;
2016-08-27 01:41:37 +00:00
2011-04-07 01:16:29 +00:00
if ( tempscrptr )
{
2016-08-27 01:41:37 +00:00
for ( i = 3 ; i < 3 + tempscrptr [ 1 ] * 2 - 2 ; i + = 2 ) // sort them
2011-04-07 01:16:29 +00:00
{
2016-08-27 01:41:37 +00:00
intptr_t t = tempscrptr [ i ] ;
2018-11-18 18:14:43 +00:00
int n = i ;
2016-08-27 01:41:37 +00:00
for ( j = i + 2 ; j < 3 + tempscrptr [ 1 ] * 2 ; j + = 2 )
{
if ( tempscrptr [ j ] < t )
2011-04-07 01:16:29 +00:00
{
2016-08-27 01:41:37 +00:00
t = tempscrptr [ j ] ;
n = j ;
2011-04-07 01:16:29 +00:00
}
2016-08-27 01:41:37 +00:00
}
if ( n ! = i )
{
2018-07-21 00:18:08 +00:00
swapptr ( & tempscrptr [ i ] , & tempscrptr [ n ] ) ;
swapptr ( & tempscrptr [ i + 1 ] , & tempscrptr [ n + 1 ] ) ;
2016-08-27 01:41:37 +00:00
}
2011-04-07 01:16:29 +00:00
}
// for (j=3;j<3+tempscrptr[1]*2;j+=2)initprintf("%5d %8x\n",tempscrptr[j],tempscrptr[j+1]);
2018-11-18 18:14:20 +00:00
// save 'end' location
2018-12-15 01:36:27 +00:00
scriptWriteAtOffset ( ( intptr_t ) g_scriptPtr - ( intptr_t ) apScript , tempscrptr ) ;
2011-04-07 01:16:29 +00:00
}
else
{
//Bsprintf(g_szBuf,"ERROR::%s %d",__FILE__,__LINE__);
//AddLog(g_szBuf);
}
2018-12-15 01:36:42 +00:00
g_caseTablePtr = backupCaseScriptPtr ;
2018-11-18 18:14:15 +00:00
g_numCases = backupNumCases ;
2011-04-07 01:16:29 +00:00
//AddLog("End of Switch statement");
}
2011-05-20 02:34:41 +00:00
continue ;
2010-03-03 01:37:27 +00:00
2011-04-07 01:16:29 +00:00
case CON_CASE :
2016-01-21 19:35:19 +00:00
case CON_DEFAULT :
2011-04-07 01:16:29 +00:00
{
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_FALSE ( g_checkingSwitch < 1 ) )
2011-04-07 01:16:29 +00:00
{
2016-08-27 01:42:01 +00:00
g_errorCnt + + ;
2011-04-07 01:16:29 +00:00
C_ReportError ( - 1 ) ;
2016-08-27 01:42:01 +00:00
initprintf ( " %s:%d: error: found `%s' statement when not in switch \n " , g_scriptFileName ,
2016-01-21 19:35:19 +00:00
g_lineNumber , tw = = CON_CASE ? " case " : " default " ) ;
2011-04-07 01:16:29 +00:00
g_scriptPtr - - ;
return 1 ;
}
2006-11-16 03:02:42 +00:00
2016-01-21 19:35:19 +00:00
intptr_t tempoffset = 0 ;
2018-10-07 05:22:46 +00:00
intptr_t * tempscrptr = g_scriptPtr ;
2016-01-21 19:35:19 +00:00
2018-12-15 01:36:42 +00:00
g_checkingCase = true ;
2011-04-07 01:16:29 +00:00
repeatcase :
2016-01-21 19:35:19 +00:00
g_scriptPtr - - ;
C_SkipComments ( ) ;
if ( tw = = CON_CASE )
{
2016-01-27 10:06:00 +00:00
g_numCases + + ;
2017-05-17 05:46:59 +00:00
C_GetNextValue ( LABEL_ANY ) ;
2016-01-21 19:35:19 +00:00
j = * ( - - g_scriptPtr ) ;
}
C_SkipComments ( ) ;
2011-04-07 01:16:29 +00:00
if ( * textptr = = ' : ' )
textptr + + ;
2006-11-16 03:02:42 +00:00
2016-01-21 19:35:19 +00:00
C_SkipComments ( ) ;
2018-12-15 01:36:42 +00:00
if ( g_caseTablePtr )
2011-04-07 01:16:29 +00:00
{
2016-01-21 19:35:19 +00:00
if ( tw = = CON_DEFAULT )
{
2018-12-15 01:36:42 +00:00
if ( EDUKE32_PREDICT_FALSE ( g_caseTablePtr [ 0 ] ! = 0 ) )
2011-04-07 01:16:29 +00:00
{
2016-01-21 19:35:19 +00:00
// duplicate default statement
2016-08-27 01:42:01 +00:00
g_errorCnt + + ;
2016-01-21 19:35:19 +00:00
C_ReportError ( - 1 ) ;
2016-08-27 01:42:01 +00:00
initprintf ( " %s:%d: error: multiple `default' statements found in switch \n " , g_scriptFileName , g_lineNumber ) ;
2011-04-07 01:16:29 +00:00
}
2018-12-15 01:36:42 +00:00
g_caseTablePtr [ 0 ] = ( intptr_t ) ( g_scriptPtr - apScript ) ; // save offset
2016-01-21 19:35:19 +00:00
}
else
{
for ( i = ( g_numCases / 2 ) - 1 ; i > = 0 ; i - - )
2018-12-15 01:36:42 +00:00
if ( EDUKE32_PREDICT_FALSE ( g_caseTablePtr [ i * 2 + 1 ] = = j ) )
2016-01-21 19:35:19 +00:00
{
2016-08-27 01:42:01 +00:00
g_warningCnt + + ;
2016-01-21 19:35:19 +00:00
C_ReportError ( WARNING_DUPLICATECASE ) ;
break ;
}
2018-12-15 01:36:42 +00:00
g_caseTablePtr [ g_numCases + + ] = j ;
g_caseTablePtr [ g_numCases ] = ( intptr_t ) ( ( intptr_t * ) g_scriptPtr - apScript ) ;
2016-01-21 19:35:19 +00:00
}
2011-04-07 01:16:29 +00:00
}
2006-04-13 20:47:06 +00:00
2016-01-21 19:35:19 +00:00
j = C_GetKeyword ( ) ;
if ( j = = CON_CASE | | j = = CON_DEFAULT )
2011-04-07 01:16:29 +00:00
{
//AddLog("Found Repeat Case");
2016-01-21 19:35:19 +00:00
C_GetNextKeyword ( ) ; // eat keyword
2016-01-27 10:06:00 +00:00
tw = j ;
2011-04-07 01:16:29 +00:00
goto repeatcase ;
}
2016-01-21 19:35:19 +00:00
2016-08-27 01:40:35 +00:00
tempoffset = ( unsigned ) ( tempscrptr - apScript ) ;
2006-04-13 20:47:06 +00:00
2011-05-20 02:34:41 +00:00
while ( C_ParseCommand ( 0 ) = = 0 )
2011-04-07 01:16:29 +00:00
{
2016-01-21 19:35:19 +00:00
j = C_GetKeyword ( ) ;
if ( j = = CON_CASE | | j = = CON_DEFAULT )
2011-04-07 01:16:29 +00:00
{
2016-01-21 19:35:19 +00:00
C_GetNextKeyword ( ) ; // eat keyword
2016-08-27 01:40:35 +00:00
tempscrptr = ( intptr_t * ) ( apScript + tempoffset ) ;
2016-01-27 10:06:00 +00:00
tw = j ;
2011-04-07 01:16:29 +00:00
goto repeatcase ;
}
}
2016-01-21 19:35:19 +00:00
2011-05-20 02:34:41 +00:00
continue ;
2011-04-07 01:16:29 +00:00
}
2009-01-04 22:22:33 +00:00
2016-01-21 19:35:19 +00:00
case CON_ENDSWITCH :
//AddLog("End Switch");
2018-12-15 01:36:42 +00:00
if ( g_caseTablePtr )
2009-01-04 22:22:33 +00:00
{
2016-01-21 19:35:19 +00:00
if ( EDUKE32_PREDICT_FALSE ( g_checkingCase ) )
{
2016-08-27 01:42:01 +00:00
g_errorCnt + + ;
2016-01-21 19:35:19 +00:00
C_ReportError ( - 1 ) ;
2016-08-27 01:42:01 +00:00
initprintf ( " %s:%d: error: found `endswitch' before `break' or `return' \n " , g_scriptFileName , g_lineNumber ) ;
2016-01-21 19:35:19 +00:00
}
2009-01-04 22:22:33 +00:00
}
2009-06-18 05:57:10 +00:00
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_FALSE ( - - g_checkingSwitch < 0 ) )
2011-04-07 01:16:29 +00:00
{
2016-08-27 01:42:01 +00:00
g_errorCnt + + ;
2011-04-07 01:16:29 +00:00
C_ReportError ( - 1 ) ;
2016-08-27 01:42:01 +00:00
initprintf ( " %s:%d: error: found `endswitch' without matching `switch' \n " , g_scriptFileName , g_lineNumber ) ;
2011-04-07 01:16:29 +00:00
}
return 1 ; // end of block
2009-01-04 22:22:33 +00:00
2015-01-17 00:27:19 +00:00
case CON_DRAGPOINT :
case CON_GETKEYNAME :
2018-11-18 18:10:15 +00:00
case CON_QSTRNCAT :
2015-01-17 00:27:19 +00:00
case CON_SETACTORSOUNDPITCH :
2011-04-07 01:16:29 +00:00
C_GetManyVars ( 3 ) ;
continue ;
2015-01-17 00:27:19 +00:00
2013-06-01 06:55:00 +00:00
case CON_QSTRDIM :
2017-08-01 09:48:55 +00:00
C_GetManyVarsType ( GAMEVAR_READONLY , 2 ) ;
2013-06-01 06:55:00 +00:00
C_GetManyVars ( 16 ) ;
continue ;
2015-01-17 00:27:19 +00:00
2011-04-07 01:16:29 +00:00
case CON_QSUBSTR :
2017-08-01 09:48:55 +00:00
case CON_SETSPRITE :
case CON_NEXTSECTORNEIGHBORZ :
2011-04-07 01:16:29 +00:00
C_GetManyVars ( 4 ) ;
continue ;
2009-01-04 22:22:33 +00:00
2018-11-18 18:10:15 +00:00
case CON_IFACTION :
2011-04-07 01:16:29 +00:00
case CON_IFACTIONCOUNT :
case CON_IFACTOR :
2018-11-18 18:10:15 +00:00
case CON_IFAI :
case CON_IFANGDIFFL :
2011-04-07 01:16:29 +00:00
case CON_IFCEILINGDISTL :
2018-11-18 18:10:15 +00:00
case CON_IFCOUNT :
case CON_IFCUTSCENE :
case CON_IFFLOORDISTL :
case CON_IFGAPZL :
2011-04-07 01:16:29 +00:00
case CON_IFGOTWEAPONCE :
case CON_IFMOVE :
case CON_IFP :
2018-11-18 18:10:15 +00:00
case CON_IFPDISTG :
case CON_IFPDISTL :
case CON_IFPHEALTHL :
2011-04-07 01:16:29 +00:00
case CON_IFPINVENTORY :
2013-05-23 18:28:04 +00:00
case CON_IFPLAYERSL :
2018-11-18 18:10:15 +00:00
case CON_IFRND :
case CON_IFSOUND :
case CON_IFSPAWNEDBY :
case CON_IFSPRITEPAL :
case CON_IFSTRENGTH :
case CON_IFWASWEAPON :
2011-04-07 01:16:29 +00:00
{
2018-12-15 01:36:27 +00:00
auto const lastScriptPtr = & g_scriptPtr [ - 1 ] - apScript ;
2009-01-05 14:43:12 +00:00
2018-12-15 01:36:42 +00:00
g_skipBranch = false ;
2009-01-05 14:43:12 +00:00
2011-04-07 01:16:29 +00:00
switch ( tw )
{
2015-02-11 05:22:07 +00:00
case CON_IFCUTSCENE :
C_GetNextVar ( ) ;
break ;
2011-04-07 01:16:29 +00:00
case CON_IFAI :
C_GetNextValue ( LABEL_AI ) ;
break ;
case CON_IFACTION :
C_GetNextValue ( LABEL_ACTION ) ;
break ;
case CON_IFMOVE :
2018-12-15 01:36:27 +00:00
if ( EDUKE32_PREDICT_FALSE ( ( C_GetNextValue ( LABEL_MOVE | LABEL_DEFINE ) = = 0 ) & & ( g_scriptPtr [ - 1 ] ! = 0 ) & & ( g_scriptPtr [ - 1 ] ! = 1 ) ) )
2011-04-07 01:16:29 +00:00
{
C_ReportError ( - 1 ) ;
2018-12-15 01:36:27 +00:00
g_scriptPtr [ - 1 ] = 0 ;
2016-08-27 01:42:01 +00:00
initprintf ( " %s:%d: warning: expected a move, found a constant. \n " , g_scriptFileName , g_lineNumber ) ;
g_warningCnt + + ;
2011-04-07 01:16:29 +00:00
}
break ;
case CON_IFPINVENTORY :
C_GetNextValue ( LABEL_DEFINE ) ;
C_GetNextValue ( LABEL_DEFINE ) ;
break ;
case CON_IFP :
j = 0 ;
do
2014-12-26 17:29:57 +00:00
C_BitOrNextValue ( & j ) ;
2011-04-07 01:16:29 +00:00
while ( C_GetKeyword ( ) = = - 1 ) ;
2014-12-26 17:29:57 +00:00
C_FinishBitOr ( j ) ;
2011-04-07 01:16:29 +00:00
break ;
case CON_IFSOUND :
case CON_IFACTORSOUND :
default :
C_GetNextValue ( LABEL_DEFINE ) ;
break ;
}
2009-01-04 22:22:33 +00:00
2011-04-07 01:16:29 +00:00
if ( C_CheckMalformedBranch ( lastScriptPtr ) )
continue ;
2009-01-04 22:22:33 +00:00
2018-11-18 18:14:43 +00:00
intptr_t const offset = ( unsigned ) ( g_scriptPtr - apScript ) ;
2006-04-13 20:47:06 +00:00
2011-04-07 01:16:29 +00:00
g_scriptPtr + + ; //Leave a spot for the fail location
2009-06-18 05:57:10 +00:00
2011-04-07 01:16:29 +00:00
C_ParseCommand ( 0 ) ;
2007-08-29 04:01:21 +00:00
2011-04-07 01:16:29 +00:00
if ( C_CheckEmptyBranch ( tw , lastScriptPtr ) )
continue ;
2006-04-13 20:47:06 +00:00
2018-11-18 18:14:43 +00:00
auto const tempscrptr = ( intptr_t * ) apScript + offset ;
2018-11-18 18:14:20 +00:00
scriptWritePointer ( ( intptr_t ) g_scriptPtr , tempscrptr ) ;
2009-01-04 22:22:33 +00:00
2011-04-07 01:16:29 +00:00
j = C_GetKeyword ( ) ;
2009-01-04 22:22:33 +00:00
2011-04-07 01:16:29 +00:00
if ( j = = CON_ELSE | | j = = CON_LEFTBRACE )
g_checkingIfElse + + ;
2006-04-13 20:47:06 +00:00
2011-04-07 01:16:29 +00:00
continue ;
}
2009-01-05 14:43:12 +00:00
2011-04-07 01:16:29 +00:00
case CON_IFACTORNOTSTAYPUT :
2018-11-18 18:10:15 +00:00
case CON_IFAWAYFROMWALL :
case CON_IFBULLETNEAR :
2011-04-07 01:16:29 +00:00
case CON_IFCANSEE :
2018-11-18 18:10:15 +00:00
case CON_IFCANSEETARGET :
2011-04-07 01:16:29 +00:00
case CON_IFCANSHOOTTARGET :
2018-11-18 18:10:15 +00:00
case CON_IFCLIENT :
case CON_IFDEAD :
2011-04-07 01:16:29 +00:00
case CON_IFHITSPACE :
2018-11-18 18:10:15 +00:00
case CON_IFHITWEAPON :
2011-04-07 01:16:29 +00:00
case CON_IFINOUTERSPACE :
2018-11-18 18:10:15 +00:00
case CON_IFINSPACE :
case CON_IFINWATER :
case CON_IFMULTIPLAYER :
2011-04-07 01:16:29 +00:00
case CON_IFNOSOUNDS :
2018-11-18 18:10:15 +00:00
case CON_IFNOTMOVING :
case CON_IFONWATER :
case CON_IFOUTSIDE :
2016-10-14 07:40:41 +00:00
case CON_IFPLAYBACKON :
2018-11-18 18:10:15 +00:00
case CON_IFRESPAWN :
case CON_IFSERVER :
case CON_IFSQUISHED :
2011-04-07 01:16:29 +00:00
{
2018-12-15 01:36:27 +00:00
auto const lastScriptPtr = & g_scriptPtr [ - 1 ] - apScript ;
2009-01-05 14:43:12 +00:00
2018-12-15 01:36:42 +00:00
g_skipBranch = false ;
2009-01-04 22:22:33 +00:00
2011-04-07 01:16:29 +00:00
if ( C_CheckMalformedBranch ( lastScriptPtr ) )
continue ;
2009-01-04 22:22:33 +00:00
2018-11-18 18:14:43 +00:00
intptr_t const offset = ( unsigned ) ( g_scriptPtr - apScript ) ;
2006-04-13 20:47:06 +00:00
2011-04-07 01:16:29 +00:00
g_scriptPtr + + ; //Leave a spot for the fail location
2009-01-04 22:22:33 +00:00
2011-04-07 01:16:29 +00:00
C_ParseCommand ( 0 ) ;
2009-01-04 22:22:33 +00:00
2011-04-07 01:16:29 +00:00
if ( C_CheckEmptyBranch ( tw , lastScriptPtr ) )
continue ;
2009-01-04 22:22:33 +00:00
2018-11-18 18:14:43 +00:00
auto const tempscrptr = ( intptr_t * ) apScript + offset ;
2018-11-18 18:14:20 +00:00
scriptWritePointer ( ( intptr_t ) g_scriptPtr , tempscrptr ) ;
2009-01-05 14:43:12 +00:00
2011-04-07 01:16:29 +00:00
j = C_GetKeyword ( ) ;
2009-01-05 14:43:12 +00:00
2011-04-07 01:16:29 +00:00
if ( j = = CON_ELSE | | j = = CON_LEFTBRACE )
g_checkingIfElse + + ;
2009-01-04 22:22:33 +00:00
2011-04-07 01:16:29 +00:00
continue ;
}
case CON_LEFTBRACE :
2018-12-15 01:36:42 +00:00
if ( EDUKE32_PREDICT_FALSE ( ! ( g_processingState | | g_scriptActorOffset | | g_scriptEventOffset ) ) )
2011-04-07 01:16:29 +00:00
{
2016-08-27 01:42:01 +00:00
g_errorCnt + + ;
2011-04-07 01:16:29 +00:00
C_ReportError ( ERROR_SYNTAXERROR ) ;
}
g_numBraces + + ;
2006-04-13 20:47:06 +00:00
2011-05-20 02:34:41 +00:00
C_ParseCommand ( 1 ) ;
2011-04-07 01:16:29 +00:00
continue ;
2009-01-05 14:43:12 +00:00
2011-04-07 01:16:29 +00:00
case CON_RIGHTBRACE :
g_numBraces - - ;
2006-04-13 20:47:06 +00:00
2018-12-15 01:36:27 +00:00
if ( ( g_scriptPtr [ - 2 ] > > 12 ) = = ( IFELSE_MAGIC ) & &
( ( g_scriptPtr [ - 2 ] & VM_INSTMASK ) = = CON_LEFTBRACE ) ) // rewrite "{ }" into "nullop"
2011-04-07 01:16:29 +00:00
{
// initprintf("%s:%d: rewriting empty braces '{ }' as 'nullop' from right\n",g_szScriptFileName,g_lineNumber);
2018-12-15 01:36:42 +00:00
g_scriptPtr [ - 2 ] = CON_NULLOP | ( IFELSE_MAGIC < < 12 ) ;
2011-04-07 01:16:29 +00:00
g_scriptPtr - = 2 ;
2006-04-13 20:47:06 +00:00
2018-12-15 01:36:27 +00:00
if ( C_GetKeyword ( ) ! = CON_ELSE & & ( g_scriptPtr [ - 2 ] & VM_INSTMASK ) ! = CON_ELSE )
2018-12-15 01:36:42 +00:00
g_skipBranch = true ;
else g_skipBranch = false ;
2008-08-16 07:53:29 +00:00
2011-04-07 01:16:29 +00:00
j = C_GetKeyword ( ) ;
2006-04-25 01:56:24 +00:00
2011-04-07 01:16:29 +00:00
if ( g_checkingIfElse & & j ! = CON_ELSE )
g_checkingIfElse - - ;
2006-04-25 01:56:24 +00:00
2011-04-07 01:16:29 +00:00
return 1 ;
}
2006-04-25 01:56:24 +00:00
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_FALSE ( g_numBraces < 0 ) )
2006-04-25 01:56:24 +00:00
{
2011-04-07 01:16:29 +00:00
if ( g_checkingSwitch )
{
C_ReportError ( ERROR_NOENDSWITCH ) ;
}
C_ReportError ( - 1 ) ;
2016-08-27 01:42:01 +00:00
initprintf ( " %s:%d: error: found more `}' than `{'. \n " , g_scriptFileName , g_lineNumber ) ;
g_errorCnt + + ;
2006-04-25 01:56:24 +00:00
}
2011-05-20 02:34:41 +00:00
2011-04-07 01:16:29 +00:00
if ( g_checkingIfElse & & j ! = CON_ELSE )
g_checkingIfElse - - ;
2006-04-25 01:56:24 +00:00
2011-04-07 01:16:29 +00:00
return 1 ;
2006-04-13 20:47:06 +00:00
2011-04-07 01:16:29 +00:00
case CON_BETANAME :
g_scriptPtr - - ;
j = 0 ;
2018-11-18 18:14:43 +00:00
scriptSkipLine ( ) ;
2011-04-07 01:16:29 +00:00
continue ;
2006-04-13 20:47:06 +00:00
2015-02-09 05:50:33 +00:00
case CON_UNDEFINELEVEL :
g_scriptPtr - - ;
C_GetNextValue ( LABEL_DEFINE ) ;
g_scriptPtr - - ;
j = * g_scriptPtr ;
C_GetNextValue ( LABEL_DEFINE ) ;
g_scriptPtr - - ;
k = * g_scriptPtr ;
if ( EDUKE32_PREDICT_FALSE ( ( unsigned ) j > MAXVOLUMES - 1 ) )
{
2016-08-27 01:42:01 +00:00
initprintf ( " %s:%d: error: volume number exceeds maximum volume count. \n " , g_scriptFileName , g_lineNumber ) ;
g_errorCnt + + ;
2018-11-18 18:14:43 +00:00
scriptSkipLine ( ) ;
2015-02-09 05:50:33 +00:00
continue ;
}
if ( EDUKE32_PREDICT_FALSE ( ( unsigned ) k > MAXLEVELS - 1 ) )
{
2016-08-27 01:42:01 +00:00
initprintf ( " %s:%d: error: level number exceeds maximum number of levels per episode. \n " , g_scriptFileName , g_lineNumber ) ;
g_errorCnt + + ;
2018-11-18 18:14:43 +00:00
scriptSkipLine ( ) ;
2015-02-09 05:50:33 +00:00
continue ;
}
C_UndefineLevel ( j , k ) ;
continue ;
case CON_UNDEFINESKILL :
g_scriptPtr - - ;
C_GetNextValue ( LABEL_DEFINE ) ;
g_scriptPtr - - ;
j = * g_scriptPtr ;
if ( EDUKE32_PREDICT_FALSE ( ( unsigned ) j > = MAXSKILLS ) )
{
initprintf ( " %s:%d: error: skill number exceeds maximum skill count %d. \n " ,
2016-08-27 01:42:01 +00:00
g_scriptFileName , g_lineNumber , MAXSKILLS ) ;
g_errorCnt + + ;
2018-11-18 18:14:43 +00:00
scriptSkipLine ( ) ;
2015-02-09 05:50:33 +00:00
continue ;
}
C_UndefineSkill ( j ) ;
continue ;
case CON_UNDEFINEVOLUME :
g_scriptPtr - - ;
C_GetNextValue ( LABEL_DEFINE ) ;
g_scriptPtr - - ;
j = * g_scriptPtr ;
if ( EDUKE32_PREDICT_FALSE ( ( unsigned ) j > MAXVOLUMES - 1 ) )
{
initprintf ( " %s:%d: error: volume number exceeds maximum volume count. \n " ,
2016-08-27 01:42:01 +00:00
g_scriptFileName , g_lineNumber ) ;
g_errorCnt + + ;
2018-11-18 18:14:43 +00:00
scriptSkipLine ( ) ;
2015-02-09 05:50:33 +00:00
continue ;
}
C_UndefineVolume ( j ) ;
continue ;
2011-04-07 01:16:29 +00:00
case CON_DEFINEVOLUMENAME :
g_scriptPtr - - ;
2006-04-13 20:47:06 +00:00
2011-04-07 01:16:29 +00:00
C_GetNextValue ( LABEL_DEFINE ) ;
g_scriptPtr - - ;
j = * g_scriptPtr ;
2015-03-25 06:28:09 +00:00
2018-11-18 18:14:43 +00:00
scriptSkipSpaces ( ) ;
2011-04-07 01:16:29 +00:00
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_FALSE ( ( unsigned ) j > MAXVOLUMES - 1 ) )
2008-06-30 09:25:06 +00:00
{
2011-04-07 01:16:29 +00:00
initprintf ( " %s:%d: error: volume number exceeds maximum volume count. \n " ,
2016-08-27 01:42:01 +00:00
g_scriptFileName , g_lineNumber ) ;
g_errorCnt + + ;
2018-11-18 18:14:43 +00:00
scriptSkipLine ( ) ;
2011-05-20 02:34:41 +00:00
continue ;
2008-06-30 09:25:06 +00:00
}
2011-04-07 01:16:29 +00:00
i = 0 ;
while ( * textptr ! = 0x0a & & * textptr ! = 0x0d & & * textptr ! = 0 )
2006-04-13 20:47:06 +00:00
{
2016-08-27 01:42:01 +00:00
g_volumeNames [ j ] [ i ] = * textptr ;
2011-04-07 01:16:29 +00:00
textptr + + , i + + ;
2016-08-27 01:42:01 +00:00
if ( EDUKE32_PREDICT_FALSE ( i > = ( signed ) sizeof ( g_volumeNames [ j ] ) - 1 ) )
2011-04-07 01:16:29 +00:00
{
initprintf ( " %s:%d: warning: truncating volume name to %d characters. \n " ,
2016-08-27 01:42:01 +00:00
g_scriptFileName , g_lineNumber , ( int32_t ) sizeof ( g_volumeNames [ j ] ) - 1 ) ;
g_warningCnt + + ;
2018-11-18 18:14:43 +00:00
scriptSkipLine ( ) ;
2011-04-07 01:16:29 +00:00
break ;
}
}
2016-08-27 01:42:01 +00:00
g_volumeCnt = j + 1 ;
g_volumeNames [ j ] [ i ] = ' \0 ' ;
2011-04-07 01:16:29 +00:00
continue ;
2015-02-22 22:15:20 +00:00
case CON_DEFINEVOLUMEFLAGS :
g_scriptPtr - - ;
C_GetNextValue ( LABEL_DEFINE ) ;
g_scriptPtr - - ;
j = * g_scriptPtr ;
C_GetNextValue ( LABEL_DEFINE ) ;
g_scriptPtr - - ;
k = * g_scriptPtr ;
if ( EDUKE32_PREDICT_FALSE ( ( unsigned ) j > MAXVOLUMES - 1 ) )
{
2016-08-27 01:42:01 +00:00
initprintf ( " %s:%d: error: volume number exceeds maximum volume count. \n " , g_scriptFileName , g_lineNumber ) ;
g_errorCnt + + ;
2018-11-18 18:14:43 +00:00
scriptSkipLine ( ) ;
2015-02-22 22:15:20 +00:00
continue ;
}
C_DefineVolumeFlags ( j , k ) ;
continue ;
2011-04-07 01:16:29 +00:00
case CON_DEFINEGAMEFUNCNAME :
g_scriptPtr - - ;
C_GetNextValue ( LABEL_DEFINE ) ;
g_scriptPtr - - ;
j = * g_scriptPtr ;
2015-03-25 06:28:09 +00:00
2018-11-18 18:14:43 +00:00
scriptSkipSpaces ( ) ;
2011-04-07 01:16:29 +00:00
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_FALSE ( ( unsigned ) j > NUMGAMEFUNCTIONS - 1 ) )
2011-04-07 01:16:29 +00:00
{
initprintf ( " %s:%d: error: function number exceeds number of game functions. \n " ,
2016-08-27 01:42:01 +00:00
g_scriptFileName , g_lineNumber ) ;
g_errorCnt + + ;
2018-11-18 18:14:43 +00:00
scriptSkipLine ( ) ;
2011-05-20 02:34:41 +00:00
continue ;
2006-04-13 20:47:06 +00:00
}
2008-12-31 09:07:49 +00:00
2011-04-07 01:16:29 +00:00
i = 0 ;
2006-04-13 20:47:06 +00:00
2019-01-23 00:21:52 +00:00
{
hash_delete ( & h_gamefuncs , gamefunctions [ j ] ) ;
char * str = Bstrtolower ( Xstrdup ( gamefunctions [ j ] ) ) ;
hash_delete ( & h_gamefuncs , str ) ;
Bfree ( str ) ;
}
2011-04-07 01:16:29 +00:00
while ( * textptr ! = 0x0a & & * textptr ! = 0x0d & & * textptr ! = 0 )
{
gamefunctions [ j ] [ i ] = * textptr ;
textptr + + , i + + ;
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_FALSE ( * textptr ! = 0x0a & & * textptr ! = 0x0d & & ispecial ( * textptr ) ) )
2011-04-07 01:16:29 +00:00
{
initprintf ( " %s:%d: warning: invalid character in function name. \n " ,
2016-08-27 01:42:01 +00:00
g_scriptFileName , g_lineNumber ) ;
g_warningCnt + + ;
2018-11-18 18:14:43 +00:00
scriptSkipLine ( ) ;
2011-04-07 01:16:29 +00:00
break ;
}
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_FALSE ( i > = MAXGAMEFUNCLEN - 1 ) )
2011-04-07 01:16:29 +00:00
{
initprintf ( " %s:%d: warning: truncating function name to %d characters. \n " ,
2016-08-27 01:42:01 +00:00
g_scriptFileName , g_lineNumber , MAXGAMEFUNCLEN ) ;
g_warningCnt + + ;
2018-11-18 18:14:43 +00:00
scriptSkipLine ( ) ;
2011-04-07 01:16:29 +00:00
break ;
}
}
gamefunctions [ j ] [ i ] = ' \0 ' ;
hash_add ( & h_gamefuncs , gamefunctions [ j ] , j , 0 ) ;
{
2014-05-30 00:02:19 +00:00
char * str = Bstrtolower ( Xstrdup ( gamefunctions [ j ] ) ) ;
2011-04-07 01:16:29 +00:00
hash_add ( & h_gamefuncs , str , j , 0 ) ;
Bfree ( str ) ;
}
2008-08-16 07:53:29 +00:00
2011-04-07 01:16:29 +00:00
continue ;
2006-04-13 20:47:06 +00:00
2017-06-17 11:42:08 +00:00
case CON_UNDEFINEGAMEFUNC :
g_scriptPtr - - ;
C_GetNextValue ( LABEL_DEFINE ) ;
g_scriptPtr - - ;
j = * g_scriptPtr ;
if ( EDUKE32_PREDICT_FALSE ( ( unsigned ) j > NUMGAMEFUNCTIONS - 1 ) )
{
initprintf ( " %s:%d: error: function number exceeds number of game functions. \n " ,
g_scriptFileName , g_lineNumber ) ;
g_errorCnt + + ;
2018-11-18 18:14:43 +00:00
scriptSkipLine ( ) ;
2017-06-17 11:42:08 +00:00
continue ;
}
2019-01-23 00:21:52 +00:00
{
hash_delete ( & h_gamefuncs , gamefunctions [ j ] ) ;
char * str = Bstrtolower ( Xstrdup ( gamefunctions [ j ] ) ) ;
hash_delete ( & h_gamefuncs , str ) ;
Bfree ( str ) ;
}
2017-06-17 11:42:08 +00:00
gamefunctions [ j ] [ 0 ] = ' \0 ' ;
continue ;
2011-04-07 01:16:29 +00:00
case CON_DEFINESKILLNAME :
g_scriptPtr - - ;
2006-04-13 20:47:06 +00:00
2011-04-07 01:16:29 +00:00
C_GetNextValue ( LABEL_DEFINE ) ;
g_scriptPtr - - ;
j = * g_scriptPtr ;
2015-03-25 06:28:09 +00:00
2018-11-18 18:14:43 +00:00
scriptSkipSpaces ( ) ;
2006-04-13 20:47:06 +00:00
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_FALSE ( ( unsigned ) j > = MAXSKILLS ) )
2006-11-15 01:16:55 +00:00
{
2012-03-25 22:00:27 +00:00
initprintf ( " %s:%d: error: skill number exceeds maximum skill count %d. \n " ,
2016-08-27 01:42:01 +00:00
g_scriptFileName , g_lineNumber , MAXSKILLS ) ;
g_errorCnt + + ;
2018-11-18 18:14:43 +00:00
scriptSkipLine ( ) ;
2011-05-20 02:34:41 +00:00
continue ;
2006-11-15 01:16:55 +00:00
}
2008-07-22 09:05:34 +00:00
2011-04-07 01:16:29 +00:00
i = 0 ;
2008-07-22 09:05:34 +00:00
2011-04-07 01:16:29 +00:00
while ( * textptr ! = 0x0a & & * textptr ! = 0x0d & & * textptr ! = 0 )
2008-07-22 09:05:34 +00:00
{
2016-08-27 01:42:01 +00:00
g_skillNames [ j ] [ i ] = * textptr ;
2011-04-07 01:16:29 +00:00
textptr + + , i + + ;
2016-08-27 01:42:01 +00:00
if ( EDUKE32_PREDICT_FALSE ( i > = ( signed ) sizeof ( g_skillNames [ j ] ) - 1 ) )
2011-04-07 01:16:29 +00:00
{
initprintf ( " %s:%d: warning: truncating skill name to %d characters. \n " ,
2016-08-27 01:42:01 +00:00
g_scriptFileName , g_lineNumber , ( int32_t ) sizeof ( g_skillNames [ j ] ) - 1 ) ;
g_warningCnt + + ;
2018-11-18 18:14:43 +00:00
scriptSkipLine ( ) ;
2011-04-07 01:16:29 +00:00
break ;
}
2008-07-22 09:05:34 +00:00
}
2012-03-25 22:00:27 +00:00
2016-08-27 01:42:01 +00:00
g_skillNames [ j ] [ i ] = ' \0 ' ;
2012-03-25 22:00:27 +00:00
for ( i = 0 ; i < MAXSKILLS ; i + + )
2016-08-27 01:42:01 +00:00
if ( g_skillNames [ i ] [ 0 ] = = 0 )
2012-03-25 22:00:27 +00:00
break ;
2016-08-27 01:42:01 +00:00
g_skillCnt = i ;
2012-03-25 22:00:27 +00:00
2011-04-07 01:16:29 +00:00
continue ;
2009-11-18 01:17:56 +00:00
2011-04-07 01:16:29 +00:00
case CON_SETGAMENAME :
{
char gamename [ 32 ] ;
g_scriptPtr - - ;
2008-08-17 09:01:31 +00:00
2011-04-07 01:16:29 +00:00
C_SkipComments ( ) ;
2009-11-18 01:17:56 +00:00
2011-04-07 01:16:29 +00:00
i = 0 ;
2009-02-02 01:49:14 +00:00
2011-04-07 01:16:29 +00:00
while ( * textptr ! = 0x0a & & * textptr ! = 0x0d & & * textptr ! = 0 )
2008-08-23 23:37:01 +00:00
{
2011-04-07 01:16:29 +00:00
gamename [ i ] = * textptr ;
textptr + + , i + + ;
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_FALSE ( i > = ( signed ) sizeof ( gamename ) - 1 ) )
2008-08-23 23:37:01 +00:00
{
2011-04-07 01:16:29 +00:00
initprintf ( " %s:%d: warning: truncating game name to %d characters. \n " ,
2016-08-27 01:42:01 +00:00
g_scriptFileName , g_lineNumber , ( int32_t ) sizeof ( gamename ) - 1 ) ;
g_warningCnt + + ;
2018-11-18 18:14:43 +00:00
scriptSkipLine ( ) ;
2011-04-07 01:16:29 +00:00
break ;
2008-08-23 23:37:01 +00:00
}
}
2011-04-07 01:16:29 +00:00
gamename [ i ] = ' \0 ' ;
2014-05-30 00:02:19 +00:00
g_gameNamePtr = Xstrdup ( gamename ) ;
2014-06-16 23:17:11 +00:00
G_UpdateAppTitle ( ) ;
2011-04-07 01:16:29 +00:00
}
continue ;
case CON_SETDEFNAME :
{
g_scriptPtr - - ;
C_SkipComments ( ) ;
j = 0 ;
while ( isaltok ( * textptr ) )
2008-08-23 23:37:01 +00:00
{
2011-04-07 01:16:29 +00:00
tempbuf [ j ] = * ( textptr + + ) ;
j + + ;
2008-08-23 23:37:01 +00:00
}
2011-04-07 01:16:29 +00:00
tempbuf [ j ] = ' \0 ' ;
Clear up handling of g_*NamePtr in the game.
The primary change is that things have been made memory-clean. Some of these
pointers may point to wildly different places during the course of the program
such as statically or dynamically allocated storage, the buffer returned by
getenv() (which must not be modified according to the docs), or an element of
argv[]. Consequently, we need to strdup, or better, dup_filename them if they
are ever to be passed to a function that modifies their pointed-to data.
Specifically:
- added statics or consts according to usage
- 3 new functions clear{Grp,Def,Script}NamePtr, only 'Def' one extern for now
- in G_CheckCommandLine, don't strip 'const'; use Bstrncpyz where appropriate
- remove multiple declarations
Also, warn if an application parameter has been ignored (not matched).
git-svn-id: https://svn.eduke32.com/eduke32@2561 1a8010ca-5511-0410-912e-c29ae57300e0
2012-03-28 19:44:00 +00:00
2013-02-24 16:05:22 +00:00
C_SetDefName ( tempbuf ) ;
2008-08-23 23:37:01 +00:00
}
2011-04-07 01:16:29 +00:00
continue ;
case CON_SETCFGNAME :
2008-08-23 23:37:01 +00:00
{
2011-04-07 01:16:29 +00:00
g_scriptPtr - - ;
C_SkipComments ( ) ;
j = 0 ;
while ( isaltok ( * textptr ) )
{
tempbuf [ j ] = * ( textptr + + ) ;
j + + ;
}
tempbuf [ j ] = ' \0 ' ;
2013-11-08 18:08:45 +00:00
C_SetCfgName ( tempbuf ) ;
2011-04-07 01:16:29 +00:00
}
continue ;
2006-11-15 01:16:55 +00:00
2011-04-07 01:16:29 +00:00
case CON_DEFINEGAMETYPE :
g_scriptPtr - - ;
C_GetNextValue ( LABEL_DEFINE ) ;
g_scriptPtr - - ;
j = * g_scriptPtr ;
2006-11-16 03:02:42 +00:00
2011-04-07 01:16:29 +00:00
C_GetNextValue ( LABEL_DEFINE ) ;
g_scriptPtr - - ;
2016-08-27 01:42:01 +00:00
g_gametypeFlags [ j ] = * g_scriptPtr ;
2006-11-16 03:02:42 +00:00
2011-04-07 01:16:29 +00:00
C_SkipComments ( ) ;
2006-11-15 01:16:55 +00:00
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_FALSE ( ( unsigned ) j > MAXGAMETYPES - 1 ) )
2006-04-13 20:47:06 +00:00
{
2016-08-27 01:42:01 +00:00
initprintf ( " %s:%d: error: gametype number exceeds maximum gametype count. \n " , g_scriptFileName , g_lineNumber ) ;
g_errorCnt + + ;
2018-11-18 18:14:43 +00:00
scriptSkipLine ( ) ;
2011-05-20 02:34:41 +00:00
continue ;
2006-04-13 20:47:06 +00:00
}
2016-08-27 01:42:01 +00:00
g_gametypeCnt = j + 1 ;
2006-11-16 03:02:42 +00:00
2011-04-07 01:16:29 +00:00
i = 0 ;
2006-11-16 03:02:42 +00:00
2011-04-07 01:16:29 +00:00
while ( * textptr ! = 0x0a & & * textptr ! = 0x0d & & * textptr ! = 0 )
{
2016-08-27 01:42:01 +00:00
g_gametypeNames [ j ] [ i ] = * textptr ;
2011-04-07 01:16:29 +00:00
textptr + + , i + + ;
2016-08-27 01:42:01 +00:00
if ( EDUKE32_PREDICT_FALSE ( i > = ( signed ) sizeof ( g_gametypeNames [ j ] ) - 1 ) )
2011-04-07 01:16:29 +00:00
{
initprintf ( " %s:%d: warning: truncating gametype name to %d characters. \n " ,
2016-08-27 01:42:01 +00:00
g_scriptFileName , g_lineNumber , ( int32_t ) sizeof ( g_gametypeNames [ j ] ) - 1 ) ;
g_warningCnt + + ;
2018-11-18 18:14:43 +00:00
scriptSkipLine ( ) ;
2011-04-07 01:16:29 +00:00
break ;
}
}
2016-08-27 01:42:01 +00:00
g_gametypeNames [ j ] [ i ] = ' \0 ' ;
2011-04-07 01:16:29 +00:00
continue ;
2006-12-04 22:05:30 +00:00
2011-04-07 01:16:29 +00:00
case CON_DEFINELEVELNAME :
g_scriptPtr - - ;
C_GetNextValue ( LABEL_DEFINE ) ;
g_scriptPtr - - ;
j = * g_scriptPtr ;
C_GetNextValue ( LABEL_DEFINE ) ;
g_scriptPtr - - ;
k = * g_scriptPtr ;
C_SkipComments ( ) ;
2006-12-12 07:25:01 +00:00
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_FALSE ( ( unsigned ) j > MAXVOLUMES - 1 ) )
2006-04-13 20:47:06 +00:00
{
2016-08-27 01:42:01 +00:00
initprintf ( " %s:%d: error: volume number exceeds maximum volume count. \n " , g_scriptFileName , g_lineNumber ) ;
g_errorCnt + + ;
2018-11-18 18:14:43 +00:00
scriptSkipLine ( ) ;
2011-05-20 02:34:41 +00:00
continue ;
2011-04-07 01:16:29 +00:00
}
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_FALSE ( ( unsigned ) k > MAXLEVELS - 1 ) )
2011-04-07 01:16:29 +00:00
{
2016-08-27 01:42:01 +00:00
initprintf ( " %s:%d: error: level number exceeds maximum number of levels per episode. \n " , g_scriptFileName , g_lineNumber ) ;
g_errorCnt + + ;
2018-11-18 18:14:43 +00:00
scriptSkipLine ( ) ;
2011-05-20 02:34:41 +00:00
continue ;
2006-04-13 20:47:06 +00:00
}
2006-12-05 21:22:19 +00:00
2011-04-07 01:16:29 +00:00
i = 0 ;
2006-04-13 20:47:06 +00:00
2011-04-07 01:16:29 +00:00
tempbuf [ i ] = ' / ' ;
2006-04-13 20:47:06 +00:00
2011-04-07 01:16:29 +00:00
while ( * textptr ! = ' ' & & * textptr ! = ' \t ' & & * textptr ! = 0x0a )
{
tempbuf [ i + 1 ] = * textptr ;
textptr + + , i + + ;
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_FALSE ( i > = BMAX_PATH ) )
2011-04-07 01:16:29 +00:00
{
2016-08-27 01:42:01 +00:00
initprintf ( " %s:%d: error: level file name exceeds limit of %d characters. \n " , g_scriptFileName , g_lineNumber , BMAX_PATH ) ;
g_errorCnt + + ;
2018-11-18 18:14:43 +00:00
scriptSkipSpaces ( ) ;
2011-04-07 01:16:29 +00:00
break ;
}
}
tempbuf [ i + 1 ] = ' \0 ' ;
2006-04-13 20:47:06 +00:00
2011-04-07 01:16:29 +00:00
Bcorrectfilename ( tempbuf , 0 ) ;
2006-04-13 20:47:06 +00:00
2016-08-27 01:42:01 +00:00
if ( g_mapInfo [ j * MAXLEVELS + k ] . filename = = NULL )
g_mapInfo [ j * MAXLEVELS + k ] . filename = ( char * ) Xcalloc ( Bstrlen ( tempbuf ) + 1 , sizeof ( uint8_t ) ) ;
else if ( ( Bstrlen ( tempbuf ) + 1 ) > sizeof ( g_mapInfo [ j * MAXLEVELS + k ] . filename ) )
g_mapInfo [ j * MAXLEVELS + k ] . filename = ( char * ) Xrealloc ( g_mapInfo [ j * MAXLEVELS + k ] . filename , ( Bstrlen ( tempbuf ) + 1 ) ) ;
2006-04-13 20:47:06 +00:00
2016-08-27 01:42:01 +00:00
Bstrcpy ( g_mapInfo [ j * MAXLEVELS + k ] . filename , tempbuf ) ;
2006-04-13 20:47:06 +00:00
2011-04-07 01:16:29 +00:00
C_SkipComments ( ) ;
2006-04-13 20:47:06 +00:00
2016-08-27 01:42:01 +00:00
g_mapInfo [ j * MAXLEVELS + k ] . partime =
2011-04-07 01:16:29 +00:00
( ( ( * ( textptr + 0 ) - ' 0 ' ) * 10 + ( * ( textptr + 1 ) - ' 0 ' ) ) * REALGAMETICSPERSEC * 60 ) +
( ( ( * ( textptr + 3 ) - ' 0 ' ) * 10 + ( * ( textptr + 4 ) - ' 0 ' ) ) * REALGAMETICSPERSEC ) ;
2006-12-05 21:22:19 +00:00
2011-04-07 01:16:29 +00:00
textptr + = 5 ;
2018-11-18 18:14:43 +00:00
scriptSkipSpaces ( ) ;
2006-12-05 21:22:19 +00:00
2013-05-23 18:28:04 +00:00
// cheap hack, 0.99 doesn't have the 3D Realms time
2013-05-25 22:50:46 +00:00
if ( * ( textptr + 2 ) = = ' : ' )
2013-05-23 18:28:04 +00:00
{
2016-08-27 01:42:01 +00:00
g_mapInfo [ j * MAXLEVELS + k ] . designertime =
2013-05-23 18:28:04 +00:00
( ( ( * ( textptr + 0 ) - ' 0 ' ) * 10 + ( * ( textptr + 1 ) - ' 0 ' ) ) * REALGAMETICSPERSEC * 60 ) +
( ( ( * ( textptr + 3 ) - ' 0 ' ) * 10 + ( * ( textptr + 4 ) - ' 0 ' ) ) * REALGAMETICSPERSEC ) ;
2006-12-05 21:22:19 +00:00
2013-05-23 18:28:04 +00:00
textptr + = 5 ;
2018-11-18 18:14:43 +00:00
scriptSkipSpaces ( ) ;
2013-05-23 18:28:04 +00:00
}
2013-05-25 22:50:46 +00:00
else if ( g_scriptVersion = = 10 ) g_scriptVersion = 9 ;
2006-12-05 21:22:19 +00:00
2011-04-07 01:16:29 +00:00
i = 0 ;
2006-12-05 21:22:19 +00:00
2011-04-07 01:16:29 +00:00
while ( * textptr ! = 0x0a & & * textptr ! = 0x0d & & * textptr ! = 0 )
{
2013-03-25 04:31:09 +00:00
tempbuf [ i ] = * textptr ;
2011-04-07 01:16:29 +00:00
textptr + + , i + + ;
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_FALSE ( i > = 32 ) )
2011-04-07 01:16:29 +00:00
{
initprintf ( " %s:%d: warning: truncating level name to %d characters. \n " ,
2016-08-27 01:42:01 +00:00
g_scriptFileName , g_lineNumber , 32 ) ;
g_warningCnt + + ;
2018-11-18 18:14:43 +00:00
scriptSkipLine ( ) ;
2011-04-07 01:16:29 +00:00
break ;
}
}
2006-04-13 20:47:06 +00:00
2011-04-07 01:16:29 +00:00
tempbuf [ i ] = ' \0 ' ;
2006-04-13 20:47:06 +00:00
2016-08-27 01:42:01 +00:00
if ( g_mapInfo [ j * MAXLEVELS + k ] . name = = NULL )
g_mapInfo [ j * MAXLEVELS + k ] . name = ( char * ) Xcalloc ( Bstrlen ( tempbuf ) + 1 , sizeof ( uint8_t ) ) ;
else if ( ( Bstrlen ( tempbuf ) + 1 ) > sizeof ( g_mapInfo [ j * MAXLEVELS + k ] . name ) )
g_mapInfo [ j * MAXLEVELS + k ] . name = ( char * ) Xrealloc ( g_mapInfo [ j * MAXLEVELS + k ] . name , ( Bstrlen ( tempbuf ) + 1 ) ) ;
2006-04-13 20:47:06 +00:00
2011-04-07 01:16:29 +00:00
/* initprintf("level name string len: %d\n",Bstrlen(tempbuf)); */
2006-04-13 20:47:06 +00:00
2016-08-27 01:42:01 +00:00
Bstrcpy ( g_mapInfo [ j * MAXLEVELS + k ] . name , tempbuf ) ;
2006-04-13 20:47:06 +00:00
2011-04-07 01:16:29 +00:00
continue ;
2011-02-25 21:50:19 +00:00
2011-04-07 01:16:29 +00:00
case CON_DEFINEQUOTE :
case CON_REDEFINEQUOTE :
if ( tw = = CON_DEFINEQUOTE )
{
g_scriptPtr - - ;
}
2006-04-24 01:54:58 +00:00
2011-04-07 01:16:29 +00:00
C_GetNextValue ( LABEL_DEFINE ) ;
2006-04-13 20:47:06 +00:00
2018-12-15 01:36:27 +00:00
k = g_scriptPtr [ - 1 ] ;
2006-04-13 20:47:06 +00:00
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_FALSE ( ( unsigned ) k > = MAXQUOTES ) )
2011-04-07 01:16:29 +00:00
{
2016-08-27 01:42:01 +00:00
initprintf ( " %s:%d: error: quote number exceeds limit of %d. \n " , g_scriptFileName , g_lineNumber , MAXQUOTES ) ;
g_errorCnt + + ;
2019-02-20 21:32:39 +00:00
scriptSkipLine ( ) ;
continue ;
2011-04-07 01:16:29 +00:00
}
2012-12-09 13:42:38 +00:00
else
2006-04-23 03:14:44 +00:00
{
2013-01-01 15:24:25 +00:00
C_AllocQuote ( k ) ;
2006-04-24 02:58:15 +00:00
}
2006-04-13 20:47:06 +00:00
if ( tw = = CON_DEFINEQUOTE )
2011-04-07 01:16:29 +00:00
g_scriptPtr - - ;
i = 0 ;
2018-11-18 18:14:43 +00:00
scriptSkipSpaces ( ) ;
2011-04-07 01:16:29 +00:00
if ( tw = = CON_REDEFINEQUOTE )
2006-04-13 20:47:06 +00:00
{
2016-08-27 01:40:35 +00:00
if ( apXStrings [ g_numXStrings ] = = NULL )
apXStrings [ g_numXStrings ] = ( char * ) Xcalloc ( MAXQUOTELEN , sizeof ( uint8_t ) ) ;
2011-04-07 01:16:29 +00:00
}
while ( * textptr ! = 0x0a & & * textptr ! = 0x0d & & * textptr ! = 0 )
{
/*
if ( * textptr = = ' % ' & & * ( textptr + 1 ) = = ' s ' )
{
initprintf ( " %s:%d: error: quote text contains string identifier. \n " , g_szScriptFileName , g_lineNumber ) ;
g_numCompilerErrors + + ;
while ( * textptr ! = 0x0a & & * textptr ! = 0x0d & & * textptr ! = 0 ) textptr + + ;
2006-11-16 03:02:42 +00:00
break ;
2011-04-07 01:16:29 +00:00
}
*/
if ( tw = = CON_DEFINEQUOTE )
2016-08-27 01:40:35 +00:00
* ( apStrings [ k ] + i ) = * textptr ;
2011-04-07 01:16:29 +00:00
else
2016-08-27 01:40:35 +00:00
* ( apXStrings [ g_numXStrings ] + i ) = * textptr ;
2011-04-07 01:16:29 +00:00
textptr + + , i + + ;
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_FALSE ( i > = MAXQUOTELEN - 1 ) )
2011-04-07 01:16:29 +00:00
{
2016-08-27 01:42:01 +00:00
initprintf ( " %s:%d: warning: truncating quote text to %d characters. \n " , g_scriptFileName , g_lineNumber , MAXQUOTELEN - 1 ) ;
g_warningCnt + + ;
2018-11-18 18:14:43 +00:00
scriptSkipLine ( ) ;
2011-04-07 01:16:29 +00:00
break ;
}
2006-04-13 20:47:06 +00:00
}
2012-12-09 13:42:38 +00:00
2011-04-07 01:16:29 +00:00
if ( tw = = CON_DEFINEQUOTE )
2012-12-09 13:42:38 +00:00
{
if ( ( unsigned ) k < MAXQUOTES )
2016-08-27 01:40:35 +00:00
* ( apStrings [ k ] + i ) = ' \0 ' ;
2012-12-09 13:42:38 +00:00
}
2011-04-07 01:16:29 +00:00
else
{
2016-08-27 01:40:35 +00:00
* ( apXStrings [ g_numXStrings ] + i ) = ' \0 ' ;
2018-11-18 18:14:20 +00:00
scriptWriteValue ( g_numXStrings + + ) ;
2011-04-07 01:16:29 +00:00
}
continue ;
2006-04-13 20:47:06 +00:00
2011-04-07 01:16:29 +00:00
case CON_CHEATKEYS :
g_scriptPtr - - ;
C_GetNextValue ( LABEL_DEFINE ) ;
2018-12-15 01:36:27 +00:00
CheatKeys [ 0 ] = g_scriptPtr [ - 1 ] ;
2011-04-07 01:16:29 +00:00
C_GetNextValue ( LABEL_DEFINE ) ;
2018-12-15 01:36:27 +00:00
CheatKeys [ 1 ] = g_scriptPtr [ - 1 ] ;
2011-04-07 01:16:29 +00:00
g_scriptPtr - = 2 ;
continue ;
2006-04-13 20:47:06 +00:00
2018-02-20 11:55:20 +00:00
case CON_UNDEFINECHEAT :
g_scriptPtr - - ;
C_GetNextValue ( LABEL_DEFINE ) ;
g_scriptPtr - - ;
j = * g_scriptPtr ;
if ( EDUKE32_PREDICT_FALSE ( ( unsigned ) j > = NUMCHEATS ) )
{
initprintf ( " %s:%d: error: cheat undefinition attempts to undefine nonexistent cheat. \n " , g_scriptFileName , g_lineNumber ) ;
g_errorCnt + + ;
2018-11-18 18:14:43 +00:00
scriptSkipLine ( ) ;
2018-02-20 11:55:20 +00:00
continue ;
}
CheatStrings [ j ] [ 0 ] = ' \0 ' ;
continue ;
2011-04-07 01:16:29 +00:00
case CON_DEFINECHEAT :
g_scriptPtr - - ;
C_GetNextValue ( LABEL_DEFINE ) ;
2018-12-15 01:36:27 +00:00
k = g_scriptPtr [ - 1 ] ;
2006-04-13 20:47:06 +00:00
2017-07-10 13:43:50 +00:00
if ( EDUKE32_PREDICT_FALSE ( ( unsigned ) k > = NUMCHEATS ) )
2006-04-13 20:47:06 +00:00
{
2016-08-27 01:42:01 +00:00
initprintf ( " %s:%d: error: cheat redefinition attempts to redefine nonexistent cheat. \n " , g_scriptFileName , g_lineNumber ) ;
g_errorCnt + + ;
2018-11-18 18:14:43 +00:00
scriptSkipLine ( ) ;
2011-05-20 02:34:41 +00:00
continue ;
2006-04-13 20:47:06 +00:00
}
2011-04-07 01:16:29 +00:00
g_scriptPtr - - ;
i = 0 ;
2018-11-18 18:14:43 +00:00
scriptSkipSpaces ( ) ;
2011-04-07 01:16:29 +00:00
while ( * textptr ! = 0x0a & & * textptr ! = 0x0d & & * textptr ! = 0 & & * textptr ! = ' ' )
{
2015-03-24 10:49:03 +00:00
CheatStrings [ k ] [ i ] = Btolower ( * textptr ) ;
2011-04-07 01:16:29 +00:00
textptr + + , i + + ;
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_FALSE ( i > = ( signed ) sizeof ( CheatStrings [ k ] ) - 1 ) )
2011-04-07 01:16:29 +00:00
{
initprintf ( " %s:%d: warning: truncating cheat string to %d characters. \n " ,
2016-08-27 01:42:01 +00:00
g_scriptFileName , g_lineNumber , ( signed ) sizeof ( CheatStrings [ k ] ) - 1 ) ;
g_warningCnt + + ;
2018-11-18 18:14:43 +00:00
scriptSkipLine ( ) ;
2011-04-07 01:16:29 +00:00
break ;
}
}
CheatStrings [ k ] [ i ] = ' \0 ' ;
continue ;
2006-04-13 20:47:06 +00:00
2011-04-07 01:16:29 +00:00
case CON_DEFINESOUND :
g_scriptPtr - - ;
C_GetNextValue ( LABEL_DEFINE ) ;
2013-06-01 06:55:30 +00:00
// Ideally we could keep the value of i from C_GetNextValue() instead of having to hash_find() again.
// This depends on tempbuf remaining in place after C_GetNextValue():
j = hash_find ( & h_labels , tempbuf ) ;
2018-12-15 01:36:27 +00:00
k = g_scriptPtr [ - 1 ] ;
2018-10-07 05:22:46 +00:00
if ( EDUKE32_PREDICT_FALSE ( ( unsigned ) k > = MAXSOUNDS - 1 ) )
2011-04-07 01:16:29 +00:00
{
2018-10-10 19:15:22 +00:00
initprintf ( " %s:%d: error: sound index exceeds limit of %d. \n " , g_scriptFileName , g_lineNumber , MAXSOUNDS - 1 ) ;
2016-08-27 01:42:01 +00:00
g_errorCnt + + ;
2018-10-10 19:15:22 +00:00
k = MAXSOUNDS - 1 ;
2011-04-07 01:16:29 +00:00
}
g_scriptPtr - - ;
i = 0 ;
C_SkipComments ( ) ;
2006-11-15 01:16:55 +00:00
2011-04-07 01:16:29 +00:00
if ( g_sounds [ k ] . filename = = NULL )
2014-05-30 00:02:19 +00:00
g_sounds [ k ] . filename = ( char * ) Xcalloc ( BMAX_PATH , sizeof ( uint8_t ) ) ;
2007-09-11 05:26:38 +00:00
2011-04-07 01:16:29 +00:00
if ( * textptr = = ' \" ' )
2009-11-20 03:54:40 +00:00
{
2011-04-07 01:16:29 +00:00
textptr + + ;
while ( * textptr & & * textptr ! = ' \" ' )
2009-11-20 03:54:40 +00:00
{
2011-04-07 01:16:29 +00:00
g_sounds [ k ] . filename [ i + + ] = * textptr + + ;
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_FALSE ( i > = BMAX_PATH - 1 ) )
2011-04-07 01:16:29 +00:00
{
2016-08-27 01:42:01 +00:00
initprintf ( " %s:%d: error: sound filename exceeds limit of %d characters. \n " , g_scriptFileName , g_lineNumber , BMAX_PATH - 1 ) ;
g_errorCnt + + ;
2011-04-07 01:16:29 +00:00
C_SkipComments ( ) ;
break ;
}
2009-11-20 03:54:40 +00:00
}
2011-04-07 01:16:29 +00:00
textptr + + ;
2009-11-20 03:54:40 +00:00
}
2011-04-07 01:16:29 +00:00
else while ( * textptr ! = ' ' & & * textptr ! = ' \t ' & & * textptr ! = ' \r ' & & * textptr ! = ' \n ' )
2006-11-15 01:16:55 +00:00
{
2010-01-23 22:12:02 +00:00
g_sounds [ k ] . filename [ i + + ] = * textptr + + ;
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_FALSE ( i > = BMAX_PATH - 1 ) )
2010-01-23 22:12:02 +00:00
{
2016-08-27 01:42:01 +00:00
initprintf ( " %s:%d: error: sound filename exceeds limit of %d characters. \n " , g_scriptFileName , g_lineNumber , BMAX_PATH - 1 ) ;
g_errorCnt + + ;
2010-01-23 22:12:02 +00:00
C_SkipComments ( ) ;
break ;
}
2006-11-15 01:16:55 +00:00
}
2011-04-07 01:16:29 +00:00
g_sounds [ k ] . filename [ i ] = ' \0 ' ;
2006-04-13 20:47:06 +00:00
2012-05-28 18:15:26 +00:00
check_filename_case ( g_sounds [ k ] . filename ) ;
2011-04-07 01:16:29 +00:00
C_GetNextValue ( LABEL_DEFINE ) ;
2018-12-15 01:36:27 +00:00
g_sounds [ k ] . ps = g_scriptPtr [ - 1 ] ;
2011-04-07 01:16:29 +00:00
C_GetNextValue ( LABEL_DEFINE ) ;
2018-12-15 01:36:27 +00:00
g_sounds [ k ] . pe = g_scriptPtr [ - 1 ] ;
2011-04-07 01:16:29 +00:00
C_GetNextValue ( LABEL_DEFINE ) ;
2018-12-15 01:36:27 +00:00
g_sounds [ k ] . pr = g_scriptPtr [ - 1 ] ;
2013-01-13 16:40:36 +00:00
2011-04-07 01:16:29 +00:00
C_GetNextValue ( LABEL_DEFINE ) ;
2018-12-15 01:36:27 +00:00
g_sounds [ k ] . m = g_scriptPtr [ - 1 ] & ~ SF_ONEINST_INTERNAL ;
if ( g_scriptPtr [ - 1 ] & SF_LOOP )
2013-09-08 20:18:56 +00:00
g_sounds [ k ] . m | = SF_ONEINST_INTERNAL ;
2013-01-13 16:40:36 +00:00
2011-04-07 01:16:29 +00:00
C_GetNextValue ( LABEL_DEFINE ) ;
2018-12-15 01:36:27 +00:00
g_sounds [ k ] . vo = g_scriptPtr [ - 1 ] ;
2011-04-07 01:16:29 +00:00
g_scriptPtr - = 5 ;
2006-04-13 20:47:06 +00:00
2018-10-25 23:32:14 +00:00
g_sounds [ k ] . volume = 1.f ;
2018-04-02 22:00:11 +00:00
if ( k > g_highestSoundIdx )
g_highestSoundIdx = k ;
2013-06-01 06:55:30 +00:00
2018-11-18 18:06:53 +00:00
if ( g_dynamicSoundMapping & & j > = 0 & & ( labeltype [ j ] & LABEL_DEFINE ) )
G_ProcessDynamicSoundMapping ( label + ( j < < 6 ) , k ) ;
2011-04-07 01:16:29 +00:00
continue ;
2006-04-13 20:47:06 +00:00
2011-04-07 01:16:29 +00:00
case CON_ENDEVENT :
2006-04-13 20:47:06 +00:00
2018-12-15 01:36:42 +00:00
if ( EDUKE32_PREDICT_FALSE ( ! g_scriptEventOffset ) )
2010-02-23 18:13:46 +00:00
{
C_ReportError ( - 1 ) ;
2016-08-27 01:42:01 +00:00
initprintf ( " %s:%d: error: found `endevent' without open `onevent'. \n " , g_scriptFileName , g_lineNumber ) ;
g_errorCnt + + ;
2011-04-07 01:16:29 +00:00
}
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_FALSE ( g_numBraces > 0 ) )
2011-04-07 01:16:29 +00:00
{
2018-11-18 18:10:32 +00:00
C_ReportError ( ERROR_NOTTOPLEVEL ) ;
2016-08-27 01:42:01 +00:00
g_errorCnt + + ;
2011-04-07 01:16:29 +00:00
}
// if event has already been declared then put a jump in instead
2018-12-15 01:36:42 +00:00
if ( g_scriptEventChainOffset )
2011-04-07 01:16:29 +00:00
{
2010-05-03 01:03:06 +00:00
g_scriptPtr - - ;
2018-12-15 01:36:48 +00:00
scriptWriteValue ( CON_JUMP | LINE_NUMBER ) ;
2018-11-18 18:14:20 +00:00
scriptWriteValue ( GV_FLAG_CONSTANT ) ;
2018-12-15 01:36:42 +00:00
scriptWriteValue ( g_scriptEventChainOffset ) ;
2018-12-15 01:36:48 +00:00
scriptWriteValue ( CON_ENDEVENT | LINE_NUMBER ) ;
2016-01-08 01:33:01 +00:00
2018-12-15 01:36:42 +00:00
C_FillEventBreakStackWithJump ( ( intptr_t * ) g_scriptEventBreakOffset , g_scriptEventChainOffset ) ;
2015-03-27 12:28:45 +00:00
2018-12-15 01:36:42 +00:00
g_scriptEventChainOffset = 0 ;
2010-02-23 18:13:46 +00:00
}
2015-03-25 21:31:11 +00:00
else
{
// pad space for the next potential appendevent
2018-12-15 01:36:27 +00:00
apScriptGameEventEnd [ g_currentEvent ] = & g_scriptPtr [ - 1 ] - apScript ;
2018-12-15 01:36:48 +00:00
scriptWriteValue ( CON_ENDEVENT | LINE_NUMBER ) ;
2018-12-15 01:36:42 +00:00
scriptWriteValue ( g_scriptEventBreakOffset ) ;
2018-12-15 01:36:48 +00:00
scriptWriteValue ( CON_ENDEVENT | LINE_NUMBER ) ;
2015-03-25 21:31:11 +00:00
}
2015-03-27 12:28:45 +00:00
2018-12-15 01:36:42 +00:00
g_scriptEventBreakOffset = g_scriptEventOffset = g_scriptActorOffset = 0 ;
2011-04-07 01:16:29 +00:00
g_currentEvent = - 1 ;
Bsprintf ( g_szCurrentBlockName , " (none) " ) ;
continue ;
2006-04-13 20:47:06 +00:00
2011-04-07 01:16:29 +00:00
case CON_ENDA :
2018-12-15 01:36:42 +00:00
if ( EDUKE32_PREDICT_FALSE ( ! g_scriptActorOffset | | g_scriptEventOffset ) )
2009-01-04 22:22:33 +00:00
{
C_ReportError ( - 1 ) ;
2016-08-27 01:42:01 +00:00
initprintf ( " %s:%d: error: found `enda' without open `actor'. \n " , g_scriptFileName , g_lineNumber ) ;
g_errorCnt + + ;
2018-12-15 01:36:42 +00:00
g_scriptEventOffset = 0 ;
2009-01-04 22:22:33 +00:00
}
2018-11-18 18:10:32 +00:00
if ( EDUKE32_PREDICT_FALSE ( g_numBraces > 0 ) )
2011-04-07 01:16:29 +00:00
{
2018-11-18 18:10:32 +00:00
C_ReportError ( ERROR_NOTTOPLEVEL ) ;
2016-08-27 01:42:01 +00:00
g_errorCnt + + ;
2011-04-07 01:16:29 +00:00
}
2018-12-15 01:36:42 +00:00
g_scriptActorOffset = 0 ;
2011-04-07 01:16:29 +00:00
Bsprintf ( g_szCurrentBlockName , " (none) " ) ;
continue ;
2006-04-13 20:47:06 +00:00
2011-04-07 01:16:29 +00:00
case CON_RETURN :
2016-01-08 01:33:05 +00:00
if ( g_checkingSwitch )
2016-01-21 19:35:19 +00:00
{
2018-12-15 01:36:42 +00:00
g_checkingCase = false ;
2016-01-08 01:33:05 +00:00
return 1 ;
2016-01-21 19:35:19 +00:00
}
2016-01-08 01:33:05 +00:00
continue ;
2011-04-07 01:16:29 +00:00
case CON_BREAK :
if ( g_checkingSwitch )
{
2014-10-25 03:36:34 +00:00
if ( EDUKE32_PREDICT_FALSE ( otw = = CON_BREAK ) )
2011-04-07 01:16:29 +00:00
{
C_ReportError ( - 1 ) ;
2016-08-27 01:42:01 +00:00
initprintf ( " %s:%d: warning: duplicate `break'. \n " , g_scriptFileName , g_lineNumber ) ;
g_warningCnt + + ;
2011-04-07 01:16:29 +00:00
g_scriptPtr - - ;
2011-05-20 02:34:41 +00:00
continue ;
2011-04-07 01:16:29 +00:00
}
2016-01-21 19:35:19 +00:00
2018-12-15 01:36:42 +00:00
g_checkingCase = false ;
2011-04-07 01:16:29 +00:00
return 1 ;
}
2018-12-15 01:36:42 +00:00
else if ( g_scriptEventOffset )
2015-03-27 12:28:45 +00:00
{
g_scriptPtr - - ;
2018-12-15 01:36:48 +00:00
scriptWriteValue ( CON_JUMP | LINE_NUMBER ) ;
2018-11-18 18:14:20 +00:00
scriptWriteValue ( GV_FLAG_CONSTANT ) ;
2018-12-15 01:36:42 +00:00
scriptWriteValue ( g_scriptEventBreakOffset ) ;
g_scriptEventBreakOffset = & g_scriptPtr [ - 1 ] - apScript ;
2015-03-27 12:28:45 +00:00
}
2011-05-20 02:34:41 +00:00
continue ;
2011-04-07 01:16:29 +00:00
case CON_SCRIPTSIZE :
g_scriptPtr - - ;
2008-11-20 14:06:36 +00:00
C_GetNextValue ( LABEL_DEFINE ) ;
2018-12-15 01:36:27 +00:00
j = g_scriptPtr [ - 1 ] ;
2008-11-20 14:06:36 +00:00
g_scriptPtr - - ;
2011-04-07 01:16:29 +00:00
C_SkipComments ( ) ;
2018-11-18 18:10:21 +00:00
C_SetScriptSize ( j ) ;
2011-05-27 21:24:01 +00:00
continue ;
2011-04-07 01:16:29 +00:00
2013-05-23 18:28:04 +00:00
case CON_SHADETO :
g_scriptPtr - - ;
C_GetNextValue ( LABEL_DEFINE ) ;
g_scriptPtr - - ;
continue ;
2011-04-07 01:16:29 +00:00
case CON_FALL :
2018-11-18 18:10:15 +00:00
case CON_GETLASTPAL :
case CON_GETTEXTURECEILING :
case CON_GETTEXTUREFLOOR :
case CON_INSERTSPRITEQ :
2011-04-07 01:16:29 +00:00
case CON_KILLIT :
2018-11-18 18:10:15 +00:00
case CON_MIKESND :
case CON_OPERATE :
case CON_PKICK :
2011-04-07 01:16:29 +00:00
case CON_PSTOMP :
2018-11-18 18:10:15 +00:00
case CON_RESETACTIONCOUNT :
2011-04-07 01:16:29 +00:00
case CON_RESETCOUNT :
2018-11-18 18:10:15 +00:00
case CON_RESETPLAYER :
2011-04-07 01:16:29 +00:00
case CON_RESPAWNHITAG :
2015-01-17 00:27:19 +00:00
case CON_SECTGETHITAG :
2018-11-18 18:10:15 +00:00
case CON_SECTGETLOTAG :
case CON_SPGETHITAG :
case CON_SPGETLOTAG :
2017-11-29 07:29:11 +00:00
case CON_STARTSCREEN :
2018-11-18 18:10:15 +00:00
case CON_STOPALLMUSIC :
case CON_STOPALLSOUNDS :
case CON_TIP :
case CON_TOSSWEAPON :
case CON_WACKPLAYER :
2015-01-17 00:27:19 +00:00
continue ;
2011-04-07 01:16:29 +00:00
case CON_NULLOP :
2015-01-17 00:27:19 +00:00
if ( EDUKE32_PREDICT_FALSE ( C_GetKeyword ( ) ! = CON_ELSE ) )
2006-11-16 03:02:42 +00:00
{
2015-01-17 00:27:19 +00:00
C_ReportError ( - 1 ) ;
2016-08-27 01:42:01 +00:00
g_warningCnt + + ;
initprintf ( " %s:%d: warning: `nullop' found without `else' \n " , g_scriptFileName , g_lineNumber ) ;
2015-01-17 00:27:19 +00:00
g_scriptPtr - - ;
2018-12-15 01:36:42 +00:00
g_skipBranch = true ;
2006-11-16 03:02:42 +00:00
}
2011-04-07 01:16:29 +00:00
continue ;
2015-01-17 00:27:19 +00:00
2011-04-07 01:16:29 +00:00
case CON_GAMESTARTUP :
2006-11-16 03:02:42 +00:00
{
2016-10-14 07:40:44 +00:00
int32_t params [ 31 ] ;
2006-04-13 20:47:06 +00:00
2011-04-07 01:16:29 +00:00
g_scriptPtr - - ;
2016-10-14 07:40:44 +00:00
for ( j = 0 ; j < 31 ; j + + )
2011-04-07 01:16:29 +00:00
{
C_GetNextValue ( LABEL_DEFINE ) ;
g_scriptPtr - - ;
params [ j ] = * g_scriptPtr ;
2006-11-15 01:16:55 +00:00
2016-10-14 07:40:44 +00:00
if ( j ! = 12 & & j ! = 21 & & j ! = 25 & & j ! = 29 ) continue ;
2011-04-07 01:16:29 +00:00
if ( C_GetKeyword ( ) ! = - 1 )
{
2013-05-23 18:28:04 +00:00
if ( j = = 12 )
g_scriptVersion = 10 ;
else if ( j = = 21 )
g_scriptVersion = 11 ;
2013-06-13 21:17:17 +00:00
else if ( j = = 25 )
g_scriptVersion = 13 ;
2016-10-14 07:40:44 +00:00
else if ( j = = 29 )
g_scriptVersion = 14 ;
2011-04-07 01:16:29 +00:00
break ;
}
else
2016-10-14 07:40:44 +00:00
g_scriptVersion = 16 ;
2011-04-07 01:16:29 +00:00
}
/*
v1 .3 d v1 .5
DEFAULTVISIBILITY DEFAULTVISIBILITY
GENERICIMPACTDAMAGE GENERICIMPACTDAMAGE
MAXPLAYERHEALTH MAXPLAYERHEALTH
STARTARMORHEALTH STARTARMORHEALTH
RESPAWNACTORTIME RESPAWNACTORTIME
RESPAWNITEMTIME RESPAWNITEMTIME
RUNNINGSPEED RUNNINGSPEED
RPGBLASTRADIUS GRAVITATIONALCONSTANT
PIPEBOMBRADIUS RPGBLASTRADIUS
SHRINKERBLASTRADIUS PIPEBOMBRADIUS
TRIPBOMBBLASTRADIUS SHRINKERBLASTRADIUS
MORTERBLASTRADIUS TRIPBOMBBLASTRADIUS
BOUNCEMINEBLASTRADIUS MORTERBLASTRADIUS
SEENINEBLASTRADIUS BOUNCEMINEBLASTRADIUS
MAXPISTOLAMMO SEENINEBLASTRADIUS
MAXSHOTGUNAMMO MAXPISTOLAMMO
MAXCHAINGUNAMMO MAXSHOTGUNAMMO
MAXRPGAMMO MAXCHAINGUNAMMO
MAXHANDBOMBAMMO MAXRPGAMMO
MAXSHRINKERAMMO MAXHANDBOMBAMMO
MAXDEVISTATORAMMO MAXSHRINKERAMMO
MAXTRIPBOMBAMMO MAXDEVISTATORAMMO
MAXFREEZEAMMO MAXTRIPBOMBAMMO
CAMERASDESTRUCTABLE MAXFREEZEAMMO
NUMFREEZEBOUNCES MAXGROWAMMO
FREEZERHURTOWNER CAMERASDESTRUCTABLE
NUMFREEZEBOUNCES
FREEZERHURTOWNER
QSIZE
TRIPBOMBLASERMODE
*/
2012-12-29 15:21:24 +00:00
G_DoGameStartup ( params ) ;
2011-04-07 01:16:29 +00:00
}
continue ;
2006-04-13 20:47:06 +00:00
}
2006-11-16 03:02:42 +00:00
}
2011-04-07 01:16:29 +00:00
while ( loop ) ;
2006-04-13 20:47:06 +00:00
return 0 ;
}
2009-01-10 07:38:50 +00:00
/* Anything added with C_AddDefinition() cannot be overwritten in the CONs */
static void C_AddDefinition ( const char * lLabel , int32_t lValue , int32_t lType )
2006-04-13 20:47:06 +00:00
{
2018-11-18 18:11:09 +00:00
Bstrcpy ( LAST_LABEL , lLabel ) ;
2016-08-27 01:42:01 +00:00
labeltype [ g_labelCnt ] = lType ;
2018-11-18 18:11:09 +00:00
hash_add ( & h_labels , LAST_LABEL , g_labelCnt , 0 ) ;
2016-08-27 01:42:01 +00:00
labelcode [ g_labelCnt + + ] = lValue ;
2006-04-13 20:47:06 +00:00
}
2012-11-25 13:18:41 +00:00
// KEEPINSYNC lunatic/con_lang.lua
2008-11-20 14:06:36 +00:00
static void C_AddDefaultDefinitions ( void )
2006-04-13 20:47:06 +00:00
{
2017-07-18 20:53:15 +00:00
for ( int i = 0 ; i < MAXEVENTS ; i + + )
2018-03-08 02:39:21 +00:00
C_AddDefinition ( EventNames [ i ] , i , LABEL_DEFINE | LABEL_EVENT ) ;
2009-01-10 07:38:50 +00:00
2018-02-16 08:33:36 +00:00
#if 0
2017-07-18 20:53:15 +00:00
for ( int i = 0 ; i < NUMGAMEFUNCTIONS ; i + + )
2012-10-16 17:05:14 +00:00
{
int32_t j ;
2017-06-17 11:41:59 +00:00
if ( gamefunctions [ i ] [ 0 ] = = ' \0 ' )
continue ;
// if (!Bstrcmp(gamefunctions[i],"Show_Console")) continue;
2012-10-16 17:05:14 +00:00
2017-06-17 11:41:59 +00:00
j = Bsprintf ( tempbuf , " GAMEFUNC_%s " , gamefunctions [ i ] ) ;
2012-10-16 17:05:14 +00:00
2017-06-17 11:41:59 +00:00
for ( ; j > = 0 ; j - - )
2012-10-16 17:05:14 +00:00
tempbuf [ j ] = Btoupper ( tempbuf [ j ] ) ;
C_AddDefinition ( tempbuf , i , LABEL_DEFINE ) ;
}
2018-02-16 08:33:36 +00:00
# endif
2012-10-16 17:05:14 +00:00
2018-11-18 18:10:15 +00:00
static tokenmap_t predefined [ ] =
{
{ " GAMEARRAY_BOOLEAN " , GAMEARRAY_BITMAP } ,
{ " GAMEARRAY_INT16 " , GAMEARRAY_INT16 } ,
{ " GAMEARRAY_INT8 " , GAMEARRAY_INT8 } ,
{ " GAMEARRAY_RESTORE " , GAMEARRAY_RESTORE } ,
{ " GAMEARRAY_UINT16 " , GAMEARRAY_UINT16 } ,
{ " GAMEARRAY_UINT8 " , GAMEARRAY_UINT8 } ,
2017-07-18 20:53:15 +00:00
2018-11-18 18:10:15 +00:00
{ " GAMEVAR_NODEFAULT " , GAMEVAR_NODEFAULT } ,
{ " GAMEVAR_NOMULTI " , GAMEVAR_NOMULTI } ,
{ " GAMEVAR_NORESET " , GAMEVAR_NORESET } ,
{ " GAMEVAR_PERACTOR " , GAMEVAR_PERACTOR } ,
{ " GAMEVAR_PERPLAYER " , GAMEVAR_PERPLAYER } ,
{ " MAX_WEAPONS " , MAX_WEAPONS } ,
{ " MAXSPRITES " , MAXSPRITES } ,
2017-07-18 20:53:15 +00:00
{ " MAXSPRITESONSCREEN " , MAXSPRITESONSCREEN } ,
2018-11-18 18:10:15 +00:00
{ " MAXSTATUS " , MAXSTATUS } ,
{ " MAXTILES " , MAXTILES } ,
{ " PROJ_BOUNCES " , PROJ_BOUNCES } ,
{ " PROJ_BSOUND " , PROJ_BSOUND } ,
{ " PROJ_CLIPDIST " , PROJ_CLIPDIST } ,
{ " PROJ_CSTAT " , PROJ_CSTAT } ,
{ " PROJ_DECAL " , PROJ_DECAL } ,
{ " PROJ_DROP " , PROJ_DROP } ,
{ " PROJ_EXTRA " , PROJ_EXTRA } ,
{ " PROJ_EXTRA_RAND " , PROJ_EXTRA_RAND } ,
2017-07-18 20:53:15 +00:00
{ " PROJ_FLASH_COLOR " , PROJ_FLASH_COLOR } ,
2018-11-18 18:10:15 +00:00
{ " PROJ_HITRADIUS " , PROJ_HITRADIUS } ,
{ " PROJ_ISOUND " , PROJ_ISOUND } ,
{ " PROJ_OFFSET " , PROJ_OFFSET } ,
{ " PROJ_PAL " , PROJ_PAL } ,
{ " PROJ_RANGE " , PROJ_RANGE } ,
{ " PROJ_SHADE " , PROJ_SHADE } ,
{ " PROJ_SOUND " , PROJ_SOUND } ,
{ " PROJ_SPAWNS " , PROJ_SPAWNS } ,
{ " PROJ_SXREPEAT " , PROJ_SXREPEAT } ,
{ " PROJ_SYREPEAT " , PROJ_SYREPEAT } ,
{ " PROJ_TNUM " , PROJ_TNUM } ,
{ " PROJ_TOFFSET " , PROJ_TOFFSET } ,
{ " PROJ_TRAIL " , PROJ_TRAIL } ,
{ " PROJ_TXREPEAT " , PROJ_TXREPEAT } ,
{ " PROJ_TYREPEAT " , PROJ_TYREPEAT } ,
{ " PROJ_USERDATA " , PROJ_USERDATA } ,
{ " PROJ_VEL " , PROJ_VEL } ,
{ " PROJ_VEL_MULT " , PROJ_MOVECNT } ,
{ " PROJ_WORKSLIKE " , PROJ_WORKSLIKE } ,
{ " PROJ_XREPEAT " , PROJ_XREPEAT } ,
{ " PROJ_YREPEAT " , PROJ_YREPEAT } ,
{ " SFLAG_BADGUY " , SFLAG_BADGUY } ,
{ " SFLAG_DAMAGEEVENT " , SFLAG_DAMAGEEVENT } ,
{ " SFLAG_GREENSLIMEFOOD " , SFLAG_GREENSLIMEFOOD } ,
{ " SFLAG_HURTSPAWNBLOOD " , SFLAG_HURTSPAWNBLOOD } ,
{ " SFLAG_NOCLIP " , SFLAG_NOCLIP } ,
{ " SFLAG_NODAMAGEPUSH " , SFLAG_NODAMAGEPUSH } ,
{ " SFLAG_NOEVENTS " , SFLAG_NOEVENTCODE } ,
{ " SFLAG_NOLIGHT " , SFLAG_NOLIGHT } ,
{ " SFLAG_NOPAL " , SFLAG_NOPAL } ,
{ " SFLAG_NOSHADE " , SFLAG_NOSHADE } ,
{ " SFLAG_NOTELEPORT " , SFLAG_NOTELEPORT } ,
{ " SFLAG_NOWATERDIP " , SFLAG_NOWATERDIP } ,
{ " SFLAG_NVG " , SFLAG_NVG } ,
{ " SFLAG_REALCLIPDIST " , SFLAG_REALCLIPDIST } ,
{ " SFLAG_SHADOW " , SFLAG_SHADOW } ,
{ " SFLAG_SMOOTHMOVE " , SFLAG_SMOOTHMOVE } ,
{ " SFLAG_USEACTIVATOR " , SFLAG_USEACTIVATOR } ,
{ " SFLAG_WAKEUPBADGUYS " , SFLAG_WAKEUPBADGUYS } ,
{ " STAT_ACTIVATOR " , STAT_ACTIVATOR } ,
{ " STAT_ACTOR " , STAT_ACTOR } ,
{ " STAT_DEFAULT " , STAT_DEFAULT } ,
{ " STAT_DUMMYPLAYER " , STAT_DUMMYPLAYER } ,
{ " STAT_EFFECTOR " , STAT_EFFECTOR } ,
{ " STAT_FALLER " , STAT_FALLER } ,
{ " STAT_FX " , STAT_FX } ,
{ " STAT_LIGHT " , STAT_LIGHT } ,
{ " STAT_LOCATOR " , STAT_LOCATOR } ,
{ " STAT_MISC " , STAT_MISC } ,
{ " STAT_PLAYER " , STAT_PLAYER } ,
{ " STAT_PROJECTILE " , STAT_PROJECTILE } ,
{ " STAT_STANDABLE " , STAT_STANDABLE } ,
{ " STAT_TRANSPORT " , STAT_TRANSPORT } ,
{ " STAT_ZOMBIEACTOR " , STAT_ZOMBIEACTOR } ,
2017-07-18 20:53:15 +00:00
2018-11-18 18:10:15 +00:00
{ " STR_BESTTIME " , STR_BESTTIME } ,
{ " STR_DESIGNERTIME " , STR_DESIGNERTIME } ,
{ " STR_GAMETYPE " , STR_GAMETYPE } ,
{ " STR_MAPFILENAME " , STR_MAPFILENAME } ,
{ " STR_MAPNAME " , STR_MAPNAME } ,
{ " STR_PARTIME " , STR_PARTIME } ,
{ " STR_PLAYERNAME " , STR_PLAYERNAME } ,
{ " STR_USERMAPFILENAME " , STR_USERMAPFILENAME } ,
{ " STR_VERSION " , STR_VERSION } ,
{ " STR_VOLUMENAME " , STR_VOLUMENAME } ,
{ " STR_YOURTIME " , STR_YOURTIME } ,
2017-07-18 20:53:15 +00:00
} ;
2018-11-18 18:10:21 +00:00
for ( auto & def : predefined )
C_AddDefinition ( def . token , def . val , LABEL_DEFINE ) ;
2016-10-09 00:15:10 +00:00
C_AddDefinition ( " NO " , 0 , LABEL_DEFINE | LABEL_ACTION | LABEL_AI | LABEL_MOVE ) ;
2006-04-13 20:47:06 +00:00
}
2013-02-07 21:00:48 +00:00
# endif
2006-04-13 20:47:06 +00:00
2013-02-07 21:00:48 +00:00
void C_InitProjectiles ( void )
2006-04-13 20:47:06 +00:00
{
2015-03-24 00:40:55 +00:00
defaultprojectile_t const Projectile =
2008-09-29 07:38:12 +00:00
{
2015-04-18 21:59:21 +00:00
// workslike, cstat, hitradius, range, flashcolor;
// spawns, sound, isound, vel, decal, trail, tnum, drop;
// offset, bounces, bsound, toffset, extra, extra_rand;
// sxrepeat, syrepeat, txrepeat, tyrepeat;
// shade, xrepeat, yrepeat, pal;
// movecnt, clipdist, filler[2], userdata;
// XXX: The default projectie seems to mimic a union of hard-coded ones.
1 , - 1 , 2048 , 0 , 0 ,
( int16_t ) SMALLSMOKE , - 1 , - 1 , 600 , ( int16_t ) BULLETHOLE , - 1 , 0 , 0 ,
448 , ( int16_t ) g_numFreezeBounces , ( int16_t ) PIPEBOMB_BOUNCE , 1 , 100 , - 1 ,
- 1 , - 1 , - 1 , - 1 ,
- 96 , 18 , 18 , 0 ,
1 , 32 , { 0 , 0 } , 0 ,
2008-09-29 07:38:12 +00:00
} ;
2015-03-24 00:40:55 +00:00
DefaultProjectile = Projectile ;
2008-09-29 07:38:12 +00:00
2018-11-18 18:10:21 +00:00
for ( auto & tile : g_tile )
2012-10-30 15:54:35 +00:00
{
2018-11-18 18:10:21 +00:00
if ( tile . proj )
* tile . proj = DefaultProjectile ;
2015-03-24 00:40:55 +00:00
2018-11-18 18:10:21 +00:00
if ( tile . defproj )
* tile . defproj = DefaultProjectile ;
2012-10-30 15:54:35 +00:00
}
2006-04-13 20:47:06 +00:00
}
2013-02-07 21:00:48 +00:00
# if !defined LUNATIC
2016-01-11 05:06:10 +00:00
static char const * C_ScriptVersionString ( int32_t version )
2013-05-23 18:28:04 +00:00
{
2018-11-18 18:11:04 +00:00
# ifdef EDUKE32_STANDALONE
UNREFERENCED_PARAMETER ( version ) ;
# else
2013-05-23 18:28:04 +00:00
switch ( version )
{
case 9 :
2016-01-11 05:05:18 +00:00
return " , v0.99 compatibility mode " ;
2013-05-23 18:28:04 +00:00
case 10 :
2016-01-11 05:05:18 +00:00
return " , v1.0 compatibility mode " ;
2013-05-23 18:28:04 +00:00
case 11 :
2016-01-11 05:05:18 +00:00
return " , v1.1 compatibility mode " ;
2013-05-23 18:28:04 +00:00
case 13 :
2016-01-11 05:05:18 +00:00
return " , v1.3D compatibility mode " ;
2013-05-23 18:28:04 +00:00
}
2018-11-18 18:10:21 +00:00
# endif
return " " ;
2013-05-23 18:28:04 +00:00
}
2016-01-21 19:35:11 +00:00
void C_PrintStats ( void )
{
2016-08-27 01:42:01 +00:00
initprintf ( " %d/%d labels, %d/%d variables, %d/%d arrays \n " , g_labelCnt ,
2016-01-21 19:35:11 +00:00
( int32_t ) min ( ( MAXSECTORS * sizeof ( sectortype ) / sizeof ( int32_t ) ) ,
MAXSPRITES * sizeof ( spritetype ) / ( 1 < < 6 ) ) ,
g_gameVarCount , MAXGAMEVARS , g_gameArrayCount , MAXGAMEARRAYS ) ;
2018-11-18 18:10:21 +00:00
int cnt = g_numXStrings ;
2016-01-21 19:35:11 +00:00
2018-11-18 18:10:21 +00:00
for ( auto & ptr : apStrings )
if ( ptr )
cnt + + ;
2016-01-21 19:35:11 +00:00
2018-11-18 18:10:21 +00:00
if ( cnt ) initprintf ( " %d strings, " , cnt ) ;
cnt = 0 ;
2016-01-21 19:35:11 +00:00
2018-11-18 18:10:21 +00:00
for ( auto & apScriptEvent : apScriptEvents )
if ( apScriptEvent )
cnt + + ;
2016-01-21 19:35:11 +00:00
2018-11-18 18:10:21 +00:00
if ( cnt ) initprintf ( " %d events, " , cnt ) ;
cnt = 0 ;
for ( auto & tile : g_tile )
if ( tile . execPtr )
cnt + + ;
2016-01-21 19:35:11 +00:00
2018-11-18 18:10:21 +00:00
if ( cnt ) initprintf ( " %d actors " , cnt ) ;
2016-01-21 19:35:11 +00:00
initprintf ( " \n " ) ;
}
2018-12-15 01:38:00 +00:00
// TODO: add some kind of mapping between the table and the struct holding the tokens
2018-11-18 18:14:26 +00:00
void scriptInitTables ( )
{
for ( auto table : tables )
hash_init ( table ) ;
2018-12-15 01:38:00 +00:00
for ( auto table : inttables )
inthash_init ( table ) ;
2018-12-15 01:37:13 +00:00
2018-11-18 18:14:26 +00:00
for ( auto & keyword : vm_keywords )
hash_add ( & h_keywords , keyword . token , keyword . val , 0 ) ;
for ( auto & iter_token : iter_tokens )
hash_add ( & h_iter , iter_token . token , iter_token . val , 0 ) ;
2018-12-15 01:37:13 +00:00
for ( auto & varvar : varvartable )
inthash_add ( & h_varvar , varvar . x , varvar . y , 0 ) ;
2018-12-15 01:38:00 +00:00
for ( auto & globalvar : globalvartable )
inthash_add ( & h_globalvar , globalvar . x , globalvar . y , 0 ) ;
2018-12-15 01:38:16 +00:00
for ( auto & playervar : playervartable )
inthash_add ( & h_playervar , playervar . x , playervar . y , 0 ) ;
for ( auto & actorvar : actorvartable )
inthash_add ( & h_actorvar , actorvar . x , actorvar . y , 0 ) ;
2018-11-18 18:14:26 +00:00
}
2016-10-09 00:15:10 +00:00
void C_Compile ( const char * fileName )
2006-04-13 20:47:06 +00:00
{
2016-08-27 01:40:35 +00:00
Bmemset ( apScriptEvents , 0 , sizeof ( apScriptEvents ) ) ;
2016-01-08 01:33:01 +00:00
Bmemset ( apScriptGameEventEnd , 0 , sizeof ( apScriptGameEventEnd ) ) ;
2006-04-13 20:47:06 +00:00
2018-11-18 18:10:21 +00:00
for ( auto & i : g_tile )
Bmemset ( & i , 0 , sizeof ( tiledata_t ) ) ;
for ( double & actorMinMs : g_actorMinMs )
actorMinMs = 1e308 ;
2012-10-31 15:03:33 +00:00
2018-11-18 18:14:26 +00:00
scriptInitTables ( ) ;
scriptInitStructTables ( ) ;
2008-11-20 14:06:36 +00:00
Gv_Init ( ) ;
C_InitProjectiles ( ) ;
2006-04-13 20:47:06 +00:00
2018-11-18 18:10:21 +00:00
int const kFile = kopen4loadfrommod ( fileName , g_loadFromGroupOnly ) ;
2016-01-11 05:05:18 +00:00
2016-10-09 00:15:10 +00:00
if ( kFile = = - 1 ) // JBF: was 0
2006-04-13 20:47:06 +00:00
{
2009-09-09 07:19:14 +00:00
if ( g_loadFromGroupOnly = = 1 | | numgroupfiles = = 0 )
2006-11-15 01:16:55 +00:00
{
2017-04-24 04:35:18 +00:00
# ifndef EDUKE32_STANDALONE
2017-06-17 11:42:20 +00:00
char const * gf = G_GrpFile ( ) ;
2016-01-03 20:07:17 +00:00
Bsprintf ( tempbuf , " Required game data was not found. A valid copy of \" %s \" or other compatible data is needed to run EDuke32. \n \n "
2018-09-01 19:35:55 +00:00
" You must copy \" %s \" to your game directory before continuing! " , gf , gf ) ;
2009-09-09 07:19:14 +00:00
G_GameExit ( tempbuf ) ;
2017-04-24 04:35:18 +00:00
# else
G_GameExit ( " " ) ;
# endif
2009-09-09 07:19:14 +00:00
}
else
{
2016-10-09 00:15:10 +00:00
Bsprintf ( tempbuf , " CON file `%s' missing. " , fileName ) ;
2009-09-09 07:19:14 +00:00
G_GameExit ( tempbuf ) ;
2008-10-01 04:38:14 +00:00
}
2006-04-13 20:47:06 +00:00
2008-11-20 14:06:36 +00:00
//g_loadFromGroupOnly = 1;
2006-04-13 20:47:06 +00:00
return ; //Not there
}
2016-10-09 00:15:10 +00:00
int const kFileLen = kfilelength ( kFile ) ;
2006-04-13 20:47:06 +00:00
2016-10-09 00:15:10 +00:00
initprintf ( " Compiling: %s (%d bytes) \n " , fileName , kFileLen ) ;
2006-04-13 20:47:06 +00:00
2018-04-12 21:02:31 +00:00
g_logFlushWindow = 0 ;
2009-06-13 21:06:45 +00:00
2018-04-12 21:02:51 +00:00
uint32_t const startcompiletime = timerGetTicks ( ) ;
2008-08-26 08:39:45 +00:00
2016-10-09 00:15:10 +00:00
char * mptr = ( char * ) Xmalloc ( kFileLen + 1 ) ;
mptr [ kFileLen ] = 0 ;
2006-04-13 20:47:06 +00:00
2018-11-18 18:10:21 +00:00
textptr = ( char * ) mptr ;
kread ( kFile , ( char * ) textptr , kFileLen ) ;
2016-10-09 00:15:10 +00:00
kclose ( kFile ) ;
2006-04-13 20:47:06 +00:00
2018-08-09 16:06:49 +00:00
g_scriptcrc = Bcrc32 ( NULL , 0 , 0L ) ;
g_scriptcrc = Bcrc32 ( textptr , kFileLen , g_scriptcrc ) ;
2016-08-27 01:40:35 +00:00
Bfree ( apScript ) ;
2008-08-16 07:53:29 +00:00
2016-10-09 00:15:10 +00:00
apScript = ( intptr_t * ) Xcalloc ( 1 , g_scriptSize * sizeof ( intptr_t ) ) ;
bitptr = ( char * ) Xcalloc ( 1 , ( ( ( g_scriptSize + 7 ) > > 3 ) + 1 ) * sizeof ( uint8_t ) ) ;
2006-04-13 20:47:06 +00:00
2018-11-18 18:10:21 +00:00
g_errorCnt = 0 ;
g_labelCnt = 0 ;
g_lineNumber = 1 ;
g_scriptPtr = apScript + 3 ; // move permits constants 0 and 1; moveptr[1] would be script[2] (reachable?)
g_totalLines = 0 ;
g_warningCnt = 0 ;
2008-11-20 14:06:36 +00:00
2016-10-09 00:15:10 +00:00
Bstrcpy ( g_scriptFileName , fileName ) ;
2008-11-20 14:06:36 +00:00
2018-11-18 18:10:21 +00:00
C_AddDefaultDefinitions ( ) ;
2011-05-20 02:34:41 +00:00
C_ParseCommand ( 1 ) ;
2006-04-13 20:47:06 +00:00
2018-02-17 22:30:39 +00:00
for ( char * m : g_scriptModules )
2011-07-21 22:39:29 +00:00
{
2018-02-17 22:30:39 +00:00
C_Include ( m ) ;
free ( m ) ;
2011-07-21 22:39:29 +00:00
}
2018-02-17 22:30:39 +00:00
g_scriptModules . clear ( ) ;
2011-07-21 22:39:29 +00:00
2018-04-12 21:02:31 +00:00
g_logFlushWindow = 1 ;
2009-01-06 06:59:18 +00:00
2016-08-27 01:42:01 +00:00
if ( g_errorCnt > 63 )
2008-11-20 14:06:36 +00:00
initprintf ( " fatal error: too many errors: Aborted \n " ) ;
2006-04-13 20:47:06 +00:00
2008-11-20 14:06:36 +00:00
//*script = (intptr_t) g_scriptPtr;
2006-04-13 20:47:06 +00:00
2015-09-23 17:55:31 +00:00
DO_FREE_AND_NULL ( mptr ) ;
2006-04-13 20:47:06 +00:00
2016-08-27 01:42:01 +00:00
if ( g_warningCnt | | g_errorCnt )
2018-11-18 18:10:21 +00:00
{
2016-08-27 01:42:01 +00:00
initprintf ( " Found %d warning(s), %d error(s). \n " , g_warningCnt , g_errorCnt ) ;
2006-04-13 20:47:06 +00:00
2018-11-18 18:10:21 +00:00
if ( g_errorCnt )
{
Bsprintf ( buf , " Error compiling CON files. " ) ;
G_GameExit ( buf ) ;
}
2006-04-13 20:47:06 +00:00
}
2016-10-09 00:15:10 +00:00
2018-10-25 23:33:40 +00:00
for ( intptr_t i : apScriptGameEventEnd )
2006-04-13 20:47:06 +00:00
{
2018-10-25 23:33:40 +00:00
if ( ! i )
2017-10-31 02:09:39 +00:00
continue ;
2018-11-18 18:10:21 +00:00
auto const eventEnd = apScript + i ;
auto breakPtr = ( intptr_t * ) * ( eventEnd + 2 ) ;
2017-10-31 02:09:39 +00:00
while ( breakPtr )
2015-03-27 12:28:45 +00:00
{
2017-10-31 02:09:39 +00:00
breakPtr = apScript + ( intptr_t ) breakPtr ;
2018-12-15 01:36:48 +00:00
scriptWriteAtOffset ( CON_ENDEVENT | LINE_NUMBER , breakPtr - 2 ) ;
2017-10-31 02:09:39 +00:00
breakPtr = ( intptr_t * ) * breakPtr ;
2015-03-27 12:28:45 +00:00
}
2016-10-09 00:15:10 +00:00
}
2015-03-27 12:28:45 +00:00
2016-10-09 00:15:10 +00:00
g_totalLines + = g_lineNumber ;
2016-01-11 05:05:18 +00:00
2016-10-09 00:15:10 +00:00
C_SetScriptSize ( g_scriptPtr - apScript + 8 ) ;
2016-01-11 05:05:18 +00:00
2018-12-15 01:36:27 +00:00
initprintf ( " Compiled %d bytes in %ums%s \n " , ( int ) ( ( intptr_t ) g_scriptPtr - ( intptr_t ) apScript ) ,
2018-11-18 18:10:21 +00:00
timerGetTicks ( ) - startcompiletime , C_ScriptVersionString ( g_scriptVersion ) ) ;
2016-01-11 05:05:18 +00:00
2018-12-15 01:39:51 +00:00
for ( auto i : tables_free )
2018-10-25 23:33:40 +00:00
hash_free ( i ) ;
2016-01-21 19:35:09 +00:00
2018-12-15 01:37:13 +00:00
inthash_free ( & h_varvar ) ;
2018-12-15 01:38:00 +00:00
inthash_free ( & h_globalvar ) ;
2018-12-15 01:38:16 +00:00
inthash_free ( & h_playervar ) ;
inthash_free ( & h_actorvar ) ;
2018-12-15 01:37:13 +00:00
2016-10-09 00:15:10 +00:00
freehashnames ( ) ;
freesoundhashnames ( ) ;
2008-08-26 08:39:45 +00:00
2016-10-09 00:15:10 +00:00
if ( g_scriptDebug )
C_PrintStats ( ) ;
2006-04-24 02:58:15 +00:00
2016-10-09 00:15:10 +00:00
C_InitQuotes ( ) ;
2006-04-13 20:47:06 +00:00
}
2018-11-18 18:14:26 +00:00
void C_ReportError ( int error )
2006-04-13 20:47:06 +00:00
{
2009-01-13 04:40:56 +00:00
if ( Bstrcmp ( g_szCurrentBlockName , g_szLastBlockName ) )
{
2018-12-15 01:36:42 +00:00
if ( g_scriptEventOffset | | g_processingState | | g_scriptActorOffset )
initprintf ( " %s: In %s `%s': \n " , g_scriptFileName , g_scriptEventOffset ? " event " : g_scriptActorOffset ? " actor " : " state " , g_szCurrentBlockName ) ;
2016-08-27 01:42:01 +00:00
else initprintf ( " %s: At top level: \n " , g_scriptFileName ) ;
2009-01-13 04:40:56 +00:00
Bstrcpy ( g_szLastBlockName , g_szCurrentBlockName ) ;
}
2018-11-18 18:14:26 +00:00
switch ( error )
2009-01-13 04:40:56 +00:00
{
2018-11-18 18:10:32 +00:00
case ERROR_NOTTOPLEVEL :
initprintf ( " %s:%d: error: `%s' not at top level within script. \n " , g_scriptFileName , g_lineNumber , tempbuf ) ;
2009-01-13 04:40:56 +00:00
break ;
case ERROR_EVENTONLY :
2016-08-27 01:42:01 +00:00
initprintf ( " %s:%d: error: keyword `%s' only available during events. \n " , g_scriptFileName , g_lineNumber , tempbuf ) ;
2009-01-13 04:40:56 +00:00
break ;
case ERROR_EXCEEDSMAXTILES :
2016-08-27 01:42:01 +00:00
initprintf ( " %s:%d: error: `%s' value exceeds MAXTILES. Maximum is %d. \n " , g_scriptFileName , g_lineNumber , tempbuf , MAXTILES - 1 ) ;
2009-01-13 04:40:56 +00:00
break ;
case ERROR_EXPECTEDKEYWORD :
2016-08-27 01:42:01 +00:00
initprintf ( " %s:%d: error: expected a keyword but found `%s'. \n " , g_scriptFileName , g_lineNumber , tempbuf ) ;
2009-01-13 04:40:56 +00:00
break ;
case ERROR_FOUNDWITHIN :
2018-12-15 01:36:42 +00:00
initprintf ( " %s:%d: error: found `%s' within %s. \n " , g_scriptFileName , g_lineNumber , tempbuf , g_scriptEventOffset ? " an event " : g_scriptActorOffset ? " an actor " : " a state " ) ;
2009-01-13 04:40:56 +00:00
break ;
case ERROR_ISAKEYWORD :
2018-11-18 18:11:09 +00:00
initprintf ( " %s:%d: error: symbol `%s' is a keyword. \n " , g_scriptFileName , g_lineNumber , LAST_LABEL ) ;
2009-01-13 04:40:56 +00:00
break ;
case ERROR_NOENDSWITCH :
2018-11-18 18:11:09 +00:00
initprintf ( " %s:%d: error: did not find `endswitch' before `%s'. \n " , g_scriptFileName , g_lineNumber , LAST_LABEL ) ;
2009-01-13 04:40:56 +00:00
break ;
case ERROR_NOTAGAMEDEF :
2018-11-18 18:11:09 +00:00
initprintf ( " %s:%d: error: symbol `%s' is not a definition. \n " , g_scriptFileName , g_lineNumber , LAST_LABEL ) ;
2009-01-13 04:40:56 +00:00
break ;
case ERROR_NOTAGAMEVAR :
2018-11-18 18:11:09 +00:00
initprintf ( " %s:%d: error: symbol `%s' is not a variable. \n " , g_scriptFileName , g_lineNumber , LAST_LABEL ) ;
2009-01-13 04:40:56 +00:00
break ;
case ERROR_NOTAGAMEARRAY :
2018-11-18 18:11:09 +00:00
initprintf ( " %s:%d: error: symbol `%s' is not an array. \n " , g_scriptFileName , g_lineNumber , LAST_LABEL ) ;
2009-01-13 04:40:56 +00:00
break ;
case ERROR_GAMEARRAYBNC :
2016-08-27 01:42:01 +00:00
initprintf ( " %s:%d: error: malformed array index: expected ], found %c \n " , g_scriptFileName , g_lineNumber , * textptr ) ;
2009-01-13 04:40:56 +00:00
break ;
case ERROR_GAMEARRAYBNO :
2016-08-27 01:42:01 +00:00
initprintf ( " %s:%d: error: malformed array index: expected [, found %c \n " , g_scriptFileName , g_lineNumber , * textptr ) ;
2009-01-13 04:40:56 +00:00
break ;
case ERROR_INVALIDARRAYWRITE :
2016-08-27 01:42:01 +00:00
initprintf ( " %s:%d: error: arrays can only be written to using `setarray'. \n " , g_scriptFileName , g_lineNumber ) ;
2009-01-13 04:40:56 +00:00
break ;
case ERROR_PARAMUNDEFINED :
2016-08-27 01:42:01 +00:00
initprintf ( " %s:%d: error: parameter `%s' is undefined. \n " , g_scriptFileName , g_lineNumber , tempbuf ) ;
2009-01-13 04:40:56 +00:00
break ;
2016-01-02 01:56:25 +00:00
case ERROR_NOTAMEMBER :
2018-11-18 18:11:09 +00:00
initprintf ( " %s:%d: error: symbol `%s' is not a valid structure member. \n " , g_scriptFileName , g_lineNumber , LAST_LABEL ) ;
2009-01-13 04:40:56 +00:00
break ;
case ERROR_SYNTAXERROR :
2016-08-27 01:42:01 +00:00
initprintf ( " %s:%d: error: syntax error. \n " , g_scriptFileName , g_lineNumber ) ;
2009-01-13 04:40:56 +00:00
break ;
case ERROR_VARREADONLY :
2018-11-18 18:11:09 +00:00
initprintf ( " %s:%d: error: variable `%s' is read-only. \n " , g_scriptFileName , g_lineNumber , LAST_LABEL ) ;
2009-01-13 04:40:56 +00:00
break ;
2012-12-13 02:33:53 +00:00
case ERROR_ARRAYREADONLY :
2018-11-18 18:11:09 +00:00
initprintf ( " %s:%d: error: array `%s' is read-only. \n " , g_scriptFileName , g_lineNumber , LAST_LABEL ) ;
2012-12-13 02:33:53 +00:00
break ;
2009-01-13 04:40:56 +00:00
case ERROR_VARTYPEMISMATCH :
2018-11-18 18:11:09 +00:00
initprintf ( " %s:%d: error: variable `%s' is of the wrong type. \n " , g_scriptFileName , g_lineNumber , LAST_LABEL ) ;
2009-01-13 04:40:56 +00:00
break ;
case WARNING_BADGAMEVAR :
2018-11-18 18:11:09 +00:00
initprintf ( " %s:%d: warning: variable `%s' should be either per-player OR per-actor, not both. \n " , g_scriptFileName , g_lineNumber , LAST_LABEL ) ;
2009-01-13 04:40:56 +00:00
break ;
case WARNING_DUPLICATECASE :
2016-08-27 01:42:01 +00:00
initprintf ( " %s:%d: warning: duplicate case ignored. \n " , g_scriptFileName , g_lineNumber ) ;
2009-01-13 04:40:56 +00:00
break ;
case WARNING_DUPLICATEDEFINITION :
2018-11-18 18:11:09 +00:00
initprintf ( " %s:%d: warning: duplicate definition `%s' ignored. \n " , g_scriptFileName , g_lineNumber , LAST_LABEL ) ;
2009-01-13 04:40:56 +00:00
break ;
case WARNING_EVENTSYNC :
2016-08-27 01:42:01 +00:00
initprintf ( " %s:%d: warning: found `%s' within a local event. \n " , g_scriptFileName , g_lineNumber , tempbuf ) ;
2009-01-13 04:40:56 +00:00
break ;
case WARNING_LABELSONLY :
2016-08-27 01:42:01 +00:00
initprintf ( " %s:%d: warning: expected a label, found a constant. \n " , g_scriptFileName , g_lineNumber ) ;
2009-01-13 04:40:56 +00:00
break ;
case WARNING_NAMEMATCHESVAR :
2018-11-18 18:11:09 +00:00
initprintf ( " %s:%d: warning: symbol `%s' already used for variable. \n " , g_scriptFileName , g_lineNumber , LAST_LABEL ) ;
2009-01-13 04:40:56 +00:00
break ;
Adds the following keywords from M32script into CON: shiftvarvarl, shiftvarvarr, ifvarvarle, ifvarvarge, ifvarvarboth, whilevarl, and whilevarvarl.
This also adds the shorthand versions of some commands, like "set" for "setvarvar", "add" for "addvarvar", "ife" for "ifvarvare", etc. There are about 30 of these. Because some of these names may already be used in some projects as variable names, this revision also includes a somewhat large change in variable naming rules: gamevars may now have the same names as CON keywords, with the caveat that the masked keyword is no longer accessible. This results in a warning at compile time but should ensure nobody's project ever stops compiling due to the introduction of new keywords.
git-svn-id: https://svn.eduke32.com/eduke32@5499 1a8010ca-5511-0410-912e-c29ae57300e0
2016-01-02 01:56:20 +00:00
case WARNING_VARMASKSKEYWORD :
2018-11-18 18:11:09 +00:00
initprintf ( " %s:%d: warning: variable `%s' masks keyword. \n " , g_scriptFileName , g_lineNumber , LAST_LABEL ) ;
Adds the following keywords from M32script into CON: shiftvarvarl, shiftvarvarr, ifvarvarle, ifvarvarge, ifvarvarboth, whilevarl, and whilevarvarl.
This also adds the shorthand versions of some commands, like "set" for "setvarvar", "add" for "addvarvar", "ife" for "ifvarvare", etc. There are about 30 of these. Because some of these names may already be used in some projects as variable names, this revision also includes a somewhat large change in variable naming rules: gamevars may now have the same names as CON keywords, with the caveat that the masked keyword is no longer accessible. This results in a warning at compile time but should ensure nobody's project ever stops compiling due to the introduction of new keywords.
git-svn-id: https://svn.eduke32.com/eduke32@5499 1a8010ca-5511-0410-912e-c29ae57300e0
2016-01-02 01:56:20 +00:00
break ;
case WARNING_ARRAYMASKSKEYWORD :
2018-11-18 18:11:09 +00:00
initprintf ( " %s:%d: warning: array `%s' masks keyword. \n " , g_scriptFileName , g_lineNumber , LAST_LABEL ) ;
Adds the following keywords from M32script into CON: shiftvarvarl, shiftvarvarr, ifvarvarle, ifvarvarge, ifvarvarboth, whilevarl, and whilevarvarl.
This also adds the shorthand versions of some commands, like "set" for "setvarvar", "add" for "addvarvar", "ife" for "ifvarvare", etc. There are about 30 of these. Because some of these names may already be used in some projects as variable names, this revision also includes a somewhat large change in variable naming rules: gamevars may now have the same names as CON keywords, with the caveat that the masked keyword is no longer accessible. This results in a warning at compile time but should ensure nobody's project ever stops compiling due to the introduction of new keywords.
git-svn-id: https://svn.eduke32.com/eduke32@5499 1a8010ca-5511-0410-912e-c29ae57300e0
2016-01-02 01:56:20 +00:00
break ;
2009-01-13 04:40:56 +00:00
}
2006-04-13 20:47:06 +00:00
}
2013-01-20 21:17:06 +00:00
# endif