From c59928c6ffec9a7626f908dba64f837c82e6c26a Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 13 May 2020 19:11:08 +0200 Subject: [PATCH] - removed most of the old and very messy gamevar code. # Conflicts: # source/games/duke/src/zz_gamevars.cpp --- source/games/duke/src/duke3d_ed.h | 2 +- source/games/duke/src/events_defs.h | 0 source/games/duke/src/gamedef.cpp | 15 +- source/games/duke/src/gamedef.h | 11 - source/games/duke/src/gamevar.cpp | 131 ++--- source/games/duke/src/gamevar.h | 60 ++- source/games/duke/src/gamevars.h | 141 ------ source/games/duke/src/global.h | 1 - source/games/duke/src/player.h | 31 +- source/games/duke/src/sector.h | 3 +- source/games/duke/src/zz_game.cpp | 7 +- source/games/duke/src/zz_gamedef.cpp | 45 -- source/games/duke/src/zz_gameexec.cpp | 34 +- source/games/duke/src/zz_gamevars.cpp | 683 -------------------------- source/games/duke/src/zz_player.cpp | 27 +- source/games/duke/src/zz_premap.cpp | 5 +- source/games/duke/src/zz_savegame.cpp | 6 +- source/games/duke/src/zz_sbar.cpp | 2 +- 18 files changed, 167 insertions(+), 1037 deletions(-) delete mode 100644 source/games/duke/src/events_defs.h delete mode 100644 source/games/duke/src/gamevars.h delete mode 100644 source/games/duke/src/zz_gamevars.cpp diff --git a/source/games/duke/src/duke3d_ed.h b/source/games/duke/src/duke3d_ed.h index c1d2de7f5..5b52361c4 100644 --- a/source/games/duke/src/duke3d_ed.h +++ b/source/games/duke/src/duke3d_ed.h @@ -114,7 +114,7 @@ END_DUKE_NS #include "gamedef.h" #include "gamedefs.h" #include "gameexec.h" -#include "gamevars.h" +#include "gamevar.h" #include "global.h" #include "inv.h" #include "macros.h" diff --git a/source/games/duke/src/events_defs.h b/source/games/duke/src/events_defs.h deleted file mode 100644 index e69de29bb..000000000 diff --git a/source/games/duke/src/gamedef.cpp b/source/games/duke/src/gamedef.cpp index 156d8019a..7cc317707 100644 --- a/source/games/duke/src/gamedef.cpp +++ b/source/games/duke/src/gamedef.cpp @@ -1161,7 +1161,7 @@ int parsecommand() ReportError(ERROR_NOTAGAMEDEF); return 0; } - if (aaGameVars[i].dwFlags & GAMEVAR_FLAG_READONLY) + if (aGameVars[i].dwFlags & GAMEVAR_FLAG_READONLY) { errorcount++; ReportError(ERROR_VARREADONLY); @@ -1191,7 +1191,7 @@ int parsecommand() ReportError(ERROR_NOTAGAMEDEF); return 0; } - if (aaGameVars[i].dwFlags & GAMEVAR_FLAG_READONLY) + if (aGameVars[i].dwFlags & GAMEVAR_FLAG_READONLY) { errorcount++; ReportError(ERROR_VARREADONLY); @@ -1712,14 +1712,14 @@ void loadcons(const char* filenam) { labelcnt = 0; + SortCommands(); + #if 0 ClearGameEvents(); +#endif ClearGameVars(); AddSystemVars(); - InitGameVarPointers(); - ResetSystemDefaults(); -#endif //memset(actorscrptr, 0, MAXSPRITES); @@ -1751,6 +1751,11 @@ void loadcons(const char* filenam) MAXGAMEVARS ); } + + // These can only be retrieved AFTER loading the scripts. + InitGameVarPointers(); + ResetSystemDefaults(); + } END_DUKE_NS diff --git a/source/games/duke/src/gamedef.h b/source/games/duke/src/gamedef.h index 95d216a88..e6180fe7f 100644 --- a/source/games/duke/src/gamedef.h +++ b/source/games/duke/src/gamedef.h @@ -43,17 +43,6 @@ BEGIN_DUKE_NS extern intptr_t const * insptr; extern void VM_ScriptInfo(intptr_t const *ptr, int range); -extern hashtable_t h_gamevars; - -extern int32_t g_aimAngleVarID; // var ID of "AUTOAIMANGLE" -extern int32_t g_angRangeVarID; // var ID of "ANGRANGE" -extern int32_t g_returnVarID; // var ID of "RETURN" -extern int32_t g_weaponVarID; // var ID of "WEAPON" -extern int32_t g_worksLikeVarID; // var ID of "WORKSLIKE" -extern int32_t g_zRangeVarID; // var ID of "ZRANGE" -#define g_iWeaponVarID g_weaponVarID -#define g_iWorksLikeVarID g_worksLikeVarID - extern intptr_t apScriptGameEvent[EVENT_NUMEVENTS]; extern char g_scriptFileName[BMAX_PATH]; diff --git a/source/games/duke/src/gamevar.cpp b/source/games/duke/src/gamevar.cpp index bbfa1d1ed..4429eda14 100644 --- a/source/games/duke/src/gamevar.cpp +++ b/source/games/duke/src/gamevar.cpp @@ -40,6 +40,9 @@ source as it is released. #include "mmulti.h" #include "gamevar.h" +// This currently only works for Duke and related games +#include "names.h" + BEGIN_DUKE_NS @@ -49,21 +52,10 @@ int iGameVarCount; extern int errorcount, warningcount, line_count; #if 0 -extern int total_lines, line_number, labelcnt, warning, error; intptr_t *actorLoadEventScrptr[MAXTILES]; intptr_t *apScriptGameEvent[MAXGAMEEVENTS]; -int g_iReturnVarID=-1; // var ID of "RETURN" -int g_iWeaponVarID=-1; // var ID of "WEAPON" -int g_iWorksLikeVarID=-1; // var ID of "WORKSLIKE" -int g_iZRangeVarID=-1; // var ID of "ZRANGE" -int g_iAngRangeVarID=-1; // var ID of "ANGRANGE" -int g_iAimAngleVarID=-1; // var ID of "AUTOAIMANGLE" -int g_iAtWithVarID=-1; // var ID of "AtWith" - - - // global crap for event management int g_i,g_p; int g_x; @@ -194,7 +186,6 @@ bool AddGameVar(const char *pszLabel, intptr_t lValue, unsigned dwFlags) } -#if 0 //--------------------------------------------------------------------------- // // @@ -250,12 +241,8 @@ void FreeGameVars(void) aGameVars[i].lValue=0; aGameVars[i].szLabel[0]=0; aGameVars[i].dwFlags=0; - if(aGameVars[i].plValues) - { - free(aGameVars[i].plValues); - } } - aGameVars[i].plValues=NULL; + aGameVars[i].plValue=NULL; } iGameVarCount=0; return; @@ -272,21 +259,22 @@ void ClearGameVars(void) // only call this function ONCE (at game init)... int i; - for(i=0;i=0 && sPlayer < MAXPLAYERS) { - return aGameVars[id].plValues[sPlayer]; + return aGameVars[id].plArray[sPlayer]; } else { @@ -339,7 +331,7 @@ int GetGameVarID(int id, int sActor, int sPlayer) // for the current actor if(sActor >= 0 && sActor <=MAXSPRITES) { - return aGameVars[id].plValues[sActor]; + return aGameVars[id].plArray[sActor]; } else { @@ -348,12 +340,12 @@ int GetGameVarID(int id, int sActor, int sPlayer) } else if( aGameVars[id].dwFlags & GAMEVAR_FLAG_PLONG ) { - if( !aGameVars[id].plValues) + if( !aGameVars[id].plValue) { Printf("GetGameVarID NULL PlValues for PLONG Var=%s\n",aGameVars[id].szLabel); } - return *aGameVars[id].plValues; + return *aGameVars[id].plValue; } else { @@ -378,17 +370,17 @@ void SetGameVarID(int id, int lValue, int sActor, int sPlayer) if( aGameVars[id].dwFlags & GAMEVAR_FLAG_PERPLAYER ) { // for the current player - aGameVars[id].plValues[sPlayer]=lValue; + aGameVars[id].plArray[sPlayer]=lValue; } else if( aGameVars[id].dwFlags & GAMEVAR_FLAG_PERACTOR ) { // for the current actor - aGameVars[id].plValues[sActor]=lValue; + aGameVars[id].plArray[sActor]=lValue; } else if( aGameVars[id].dwFlags & GAMEVAR_FLAG_PLONG ) { // set the value at pointer - *aGameVars[id].plValues=lValue; + *aGameVars[id].plValue=lValue; } else { @@ -403,12 +395,11 @@ void SetGameVarID(int id, int lValue, int sActor, int sPlayer) // //--------------------------------------------------------------------------- -int GetGameVar(char *szGameLabel, int lDefault, short sActor, short sPlayer) +int GetGameVar(const char *szGameLabel, int lDefault, int sActor, int sPlayer) { - int i; - for(i=0;i -static FORCE_INLINE void Gv_FillWithVars(T & rv) -{ - EDUKE32_STATIC_ASSERT(sizeof(T) % sizeof(int32_t) == 0); - EDUKE32_STATIC_ASSERT(sizeof(T) > sizeof(int32_t)); - Gv_GetManyVars(sizeof(T)/sizeof(int32_t), (int32_t *)&rv); -} - -int Gv_GetVarByLabel(const char *szGameLabel,int defaultValue,int spriteNum,int playerNum); -inline int GetGameVar(const char* szGameLabel, int defaultValue, int spriteNum, int playerNum) -{ - return Gv_GetVarByLabel(szGameLabel, defaultValue, spriteNum, playerNum); -} -void Gv_NewVar(const char *pszLabel,intptr_t lValue,uint32_t dwFlags); - -int GetDefID(const char* label); - -void Gv_DumpValues(void); -void Gv_InitWeaponPointers(void); -void Gv_RefreshPointers(void); -void Gv_ResetVars(void); -int Gv_ReadSave(FileReader &kFile); -void Gv_WriteSave(FileWriter &fil); -void Gv_Clear(void); - -void Gv_ResetSystemDefaults(void); -void Gv_Init(void); -void Gv_FinalizeWeaponDefaults(void); - -#define VM_GAMEVAR_OPERATOR(func, operator) \ - static FORCE_INLINE ATTRIBUTE((flatten)) void __fastcall func(int const id, int32_t const operand) \ - { \ - auto &var = aaGameVars[id]; \ - \ - switch (var.flags & (GAMEVAR_USER_MASK | GAMEVAR_PTR_MASK)) \ - { \ - default: \ - var.global operator operand; \ - break; \ - case GAMEVAR_PERPLAYER: \ - var.pValues[vm.playerNum & (MAXPLAYERS-1)] operator operand; \ - break; \ - case GAMEVAR_PERACTOR: \ - var.pValues[vm.spriteNum & (MAXSPRITES-1)] operator operand; \ - break; \ - case GAMEVAR_INT32PTR: *(int32_t *)var.pValues operator(int32_t) operand; break; \ - } \ - } - -VM_GAMEVAR_OPERATOR(Gv_AddVar, +=) -VM_GAMEVAR_OPERATOR(Gv_SubVar, -=) - -#undef VM_GAMEVAR_OPERATOR - -END_DUKE_NS -#endif diff --git a/source/games/duke/src/global.h b/source/games/duke/src/global.h index b5db2dfd6..4b4b91ccc 100644 --- a/source/games/duke/src/global.h +++ b/source/games/duke/src/global.h @@ -30,7 +30,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "quotes.h" #include "sector.h" #include "sounds.h" -#include "gamevars.h" BEGIN_DUKE_NS diff --git a/source/games/duke/src/player.h b/source/games/duke/src/player.h index 004154984..3af02e688 100644 --- a/source/games/duke/src/player.h +++ b/source/games/duke/src/player.h @@ -35,9 +35,6 @@ extern int32_t g_mostConcurrentPlayers; #define MOVEFIFOSIZ 256 -#define NAM_GRENADE_LIFETIME 120 -#define NAM_GRENADE_LIFETIME_VAR 30 - #define HORIZ_MIN -99 #define HORIZ_MAX 299 #define AUTO_AIM_ANGLE 48 @@ -45,11 +42,15 @@ extern int32_t g_mostConcurrentPlayers; #define PHEIGHT_RR (40<<8); extern int32_t PHEIGHT; -#define TRIPBOMB_TRIPWIRE 0x00000001 -#define TRIPBOMB_TIMER 0x00000002 +enum +{ + PIPEBOMB_REMOTE = 0x00000001, + PIPEBOMB_TIMER = 0x00000002, + TRIPBOMB_TRIPWIRE = 1, + TRIPBOMB_TIMER = 2 +}; + -#define PIPEBOMB_REMOTE 0x00000001 -#define PIPEBOMB_TIMER 0x00000002 #define WEAPON_POS_LOWER -9 #define WEAPON_POS_RAISE 10 @@ -331,22 +332,6 @@ typedef struct extern weapondata_t g_playerWeapon[MAXPLAYERS][MAX_WEAPONS]; #else # define PWEAPON(Player, Weapon, Wmember) (aplWeapon ## Wmember [Weapon][Player]) -extern intptr_t *aplWeaponClip[MAX_WEAPONS]; // number of items in clip -extern intptr_t *aplWeaponReload[MAX_WEAPONS]; // delay to reload (include fire) -extern intptr_t *aplWeaponFireDelay[MAX_WEAPONS]; // delay to fire -extern intptr_t *aplWeaponHoldDelay[MAX_WEAPONS]; // delay after release fire button to fire (0 for none) -extern intptr_t *aplWeaponTotalTime[MAX_WEAPONS]; // The total time the weapon is cycling before next fire. -extern intptr_t *aplWeaponFlags[MAX_WEAPONS]; // Flags for weapon -extern intptr_t *aplWeaponShoots[MAX_WEAPONS]; // what the weapon shoots -extern intptr_t *aplWeaponSpawnTime[MAX_WEAPONS]; // the frame at which to spawn an item -extern intptr_t *aplWeaponSpawn[MAX_WEAPONS]; // the item to spawn -extern intptr_t *aplWeaponShotsPerBurst[MAX_WEAPONS]; // number of shots per 'burst' (one ammo per 'burst' -extern intptr_t *aplWeaponWorksLike[MAX_WEAPONS]; // What original the weapon works like -extern intptr_t *aplWeaponInitialSound[MAX_WEAPONS]; // Sound made when initialy firing. zero for no sound -extern intptr_t *aplWeaponFireSound[MAX_WEAPONS]; // Sound made when firing (each time for automatic) -extern intptr_t *aplWeaponSound2Time[MAX_WEAPONS]; // Alternate sound time -extern intptr_t *aplWeaponSound2Sound[MAX_WEAPONS]; // Alternate sound sound ID -extern intptr_t *aplWeaponFlashColor[MAX_WEAPONS]; // Color for polymer muzzle flash #endif // KEEPINSYNC lunatic/_defs_game.lua diff --git a/source/games/duke/src/sector.h b/source/games/duke/src/sector.h index 8369c3cf9..66bb8b425 100644 --- a/source/games/duke/src/sector.h +++ b/source/games/duke/src/sector.h @@ -24,7 +24,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #define sector_h_ #include "actors.h" // actor_t -#include "gamevars.h" +#include "gamedef.h" +#include "gamevar.h" #include "macros.h" #include "namesdyn.h" // for G_GetForcefieldPicnum() #include "player.h" // playerspawn_t diff --git a/source/games/duke/src/zz_game.cpp b/source/games/duke/src/zz_game.cpp index 715814b81..189a4f710 100644 --- a/source/games/duke/src/zz_game.cpp +++ b/source/games/duke/src/zz_game.cpp @@ -6514,12 +6514,7 @@ static void G_Cleanup(void) #endif Xfree(apScript); -// Xfree(MusicPtr); - - Gv_Clear(); - - hash_free(&h_gamevars); - } +} /* =================== diff --git a/source/games/duke/src/zz_gamedef.cpp b/source/games/duke/src/zz_gamedef.cpp index c2b7ac05a..aac02826c 100644 --- a/source/games/duke/src/zz_gamedef.cpp +++ b/source/games/duke/src/zz_gamedef.cpp @@ -43,16 +43,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. BEGIN_DUKE_NS - -void SortCommands(); -int getkeyword(const char* text); -void skiptoendofline(); -void skipwhitespace(); -void skipblockcomment(); -bool skipcomments(); -int findlabel(const char* text); - - #define LINE_NUMBER (line_number << 12) int32_t g_scriptVersion = 14; // 13 = 1.3D-style CON files, 14 = 1.4/1.5 style CON files @@ -62,44 +52,12 @@ char g_scriptFileName[BMAX_PATH] = "(none)"; // file we're currently compiling int32_t g_totalLines; char g_szBuf[1024]; -static char g_szCurrentBlockName[256] = "(none)", g_szLastBlockName[256] = "NULL"; -static int32_t g_lastKeyword = -1; -extern int checking_ifelse; -extern int parsing_state; - -// The pointer to the start of the case table in a switch statement. -// First entry is 'default' code. -static intptr_t *g_caseScriptPtr; -static int32_t g_labelsOnly = 0; -extern int num_squigilly_brackets; - -int32_t C_ParseCommand(int32_t loop); -static int32_t C_SetScriptSize(int32_t size); - - - char const * VM_GetKeywordForID(int32_t id) { // do not really need this for now... return ""; } -hashtable_t h_gamevars = { MAXGAMEVARS >> 1, NULL }; - -static hashtable_t * const tables[] = { - &h_gamevars -}; - -void C_InitHashes() -{ - SortCommands(); - for (auto table : tables) - hash_init(table); -} - -int GetDefID(char const *label) { return hash_find(&h_gamevars, label); } - - void loadcons(const char* filenam); void C_Compile(const char *fileName) @@ -112,9 +70,6 @@ void C_Compile(const char *fileName) g_actorMinMs[i] = 1e308; } - C_InitHashes(); - Gv_Init(); - apScript = (intptr_t *)Xcalloc(1, g_scriptSize * sizeof(intptr_t)); loadcons(fileName); } diff --git a/source/games/duke/src/zz_gameexec.cpp b/source/games/duke/src/zz_gameexec.cpp index fc586a98f..959c67252 100644 --- a/source/games/duke/src/zz_gameexec.cpp +++ b/source/games/duke/src/zz_gameexec.cpp @@ -122,7 +122,7 @@ static FORCE_INLINE int32_t VM_EventInlineInternal__(int const eventNum, int con g_player[playerNum&(MAXPLAYERS-1)].ps, &actor[spriteNum&(MAXSPRITES-1)] }; - auto &globalReturn = aaGameVars[g_returnVarID].global; + auto &globalReturn = aGameVars[g_returnVarID].lValue; struct { @@ -2660,13 +2660,13 @@ GAMEEXEC_STATIC void VM_Execute(native_t loop) case concmd_ifvarg: insptr++; - tw = Gv_GetVar(*insptr++); + tw = GetGameVarID(*insptr++, vm.spriteNum, vm.playerNum); VM_CONDITIONAL(tw > *insptr); continue; case concmd_ifvarl: insptr++; - tw = Gv_GetVar(*insptr++); + tw = GetGameVarID(*insptr++, vm.spriteNum, vm.playerNum); VM_CONDITIONAL(tw < *insptr); continue; @@ -2674,43 +2674,39 @@ GAMEEXEC_STATIC void VM_Execute(native_t loop) insptr++; { tw = *insptr++; - int const nValue = Gv_GetVar(*insptr++); - - if ((aaGameVars[tw].flags & (GAMEVAR_USER_MASK | GAMEVAR_PTR_MASK)) == 0) - aaGameVars[tw].global = nValue; - else - Gv_SetVar(tw, nValue); + int const nValue = GetGameVarID(*insptr++, vm.spriteNum, vm.playerNum); + SetGameVarID(tw, nValue, vm.spriteNum, vm.playerNum); } continue; case concmd_setvar: - Gv_SetVar(insptr[1], insptr[2]); + SetGameVarID(insptr[1], insptr[2], vm.spriteNum, vm.playerNum); insptr += 3; continue; case concmd_addvarvar: insptr++; tw = *insptr++; - Gv_AddVar(tw, Gv_GetVar(*insptr++)); + SetGameVarID(tw, GetGameVarID(tw, vm.spriteNum, vm.playerNum) + GetGameVarID(*insptr++, vm.spriteNum, vm.playerNum), vm.spriteNum, vm.playerNum); continue; case concmd_addvar: - Gv_AddVar(insptr[1], insptr[2]); + SetGameVarID(insptr[1], GetGameVarID(insptr[1], vm.spriteNum, vm.playerNum) + insptr[2], vm.spriteNum, vm.playerNum); insptr += 3; continue; case concmd_ifvarvarl: insptr++; - tw = Gv_GetVar(*insptr++); - tw = (tw < Gv_GetVar(*insptr++)); + tw = GetGameVarID(*insptr++, vm.spriteNum, vm.playerNum); + tw = (tw < GetGameVarID(*insptr++, vm.spriteNum, vm.playerNum)); insptr--; VM_CONDITIONAL(tw); continue; case concmd_ifvarvarg: insptr++; - tw = Gv_GetVar(*insptr++); - tw = (tw > Gv_GetVar(*insptr++)); + tw = GetGameVarID(*insptr++, vm.spriteNum, vm.playerNum); + tw = (tw > GetGameVarID(*insptr++, vm.spriteNum, vm.playerNum)); insptr--; VM_CONDITIONAL(tw); continue; @@ -2721,14 +2717,14 @@ GAMEEXEC_STATIC void VM_Execute(native_t loop) case concmd_ifvare: insptr++; - tw = Gv_GetVar(*insptr++); + tw = GetGameVarID(*insptr++, vm.spriteNum, vm.playerNum); VM_CONDITIONAL(tw == *insptr); continue; case concmd_ifvarvare: insptr++; - tw = Gv_GetVar(*insptr++); - tw = (tw == Gv_GetVar(*insptr++)); + tw = GetGameVarID(*insptr++, vm.spriteNum, vm.playerNum); + tw = (tw == GetGameVarID(*insptr++, vm.spriteNum, vm.playerNum)); insptr--; VM_CONDITIONAL(tw); continue; diff --git a/source/games/duke/src/zz_gamevars.cpp b/source/games/duke/src/zz_gamevars.cpp deleted file mode 100644 index 179716b6e..000000000 --- a/source/games/duke/src/zz_gamevars.cpp +++ /dev/null @@ -1,683 +0,0 @@ -//------------------------------------------------------------------------- -/* -Copyright (C) 2016 EDuke32 developers and contributors - -This file is part of EDuke32. - -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 -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ -//------------------------------------------------------------------------- - -#include "ns.h" // Must come before everything else! - -#include "duke3d.h" -#include "menus.h" -#include "savegame.h" -#include "namesdyn.h" -#include "gamevars.h" - -//#include "vfs.h" - -BEGIN_DUKE_NS - -#define gamevars_c_ - -gamevar_t aaGameVars[MAXGAMEVARS]; -int32_t g_gameVarCount = 0; - -// pointers to weapon gamevar data -intptr_t *aplWeaponClip[MAX_WEAPONS]; // number of items in magazine -intptr_t *aplWeaponFireDelay[MAX_WEAPONS]; // delay to fire -intptr_t *aplWeaponFireSound[MAX_WEAPONS]; // Sound made when firing (each time for automatic) -intptr_t *aplWeaponFlags[MAX_WEAPONS]; // Flags for weapon -intptr_t *aplWeaponFlashColor[MAX_WEAPONS]; // Muzzle flash color -intptr_t *aplWeaponHoldDelay[MAX_WEAPONS]; // delay after release fire button to fire (0 for none) -intptr_t *aplWeaponInitialSound[MAX_WEAPONS]; // Sound made when weapon starts firing. zero for no sound -intptr_t *aplWeaponReload[MAX_WEAPONS]; // delay to reload (include fire) -intptr_t *aplWeaponShoots[MAX_WEAPONS]; // what the weapon shoots -intptr_t *aplWeaponShotsPerBurst[MAX_WEAPONS]; // number of shots per 'burst' (one ammo per 'burst') -intptr_t *aplWeaponSound2Sound[MAX_WEAPONS]; // Alternate sound sound ID -intptr_t *aplWeaponSound2Time[MAX_WEAPONS]; // Alternate sound time -intptr_t *aplWeaponSpawn[MAX_WEAPONS]; // the item to spawn -intptr_t *aplWeaponSpawnTime[MAX_WEAPONS]; // the frame at which to spawn an item -intptr_t *aplWeaponTotalTime[MAX_WEAPONS]; // The total time the weapon is cycling before next fire. -intptr_t *aplWeaponWorksLike[MAX_WEAPONS]; // What original the weapon works like - - -// Frees the memory for the *values* of game variables and arrays. Resets their -// counts to zero. Call this function as many times as needed. -// -// Returns: old g_gameVarCount | (g_gameArrayCount<<16). -int Gv_Free(void) -{ - for (auto &gameVar : aaGameVars) - { - if (gameVar.flags & GAMEVAR_USER_MASK) - ALIGNED_FREE_AND_NULL(gameVar.pValues); - gameVar.flags |= GAMEVAR_RESET; - } - - EDUKE32_STATIC_ASSERT(MAXGAMEVARS < 32768); - int const varCount = g_gameVarCount; - g_gameVarCount = 0; - - hash_init(&h_gamevars); - - return varCount; -} - -// Calls Gv_Free() and in addition frees the labels of all game variables and -// arrays. -// Only call this function at exit -void Gv_Clear(void) -{ - Gv_Free(); - - // Now, only do work that Gv_Free() hasn't done. - for (auto & gameVar : aaGameVars) - DO_FREE_AND_NULL(gameVar.szLabel); -} - -// Note that this entire function is totally architecture dependent and needs to be fixed (which won't be easy...) -int Gv_ReadSave(FileReader &kFile) -{ - return -7; -} - -// Note that this entire function is totally architecture dependent and needs to be fixed (which won't be easy...) -void Gv_WriteSave(FileWriter &fil) -{ -} - -void Gv_DumpValues(void) -{ -} - -// XXX: This function is very strange. -void Gv_ResetVars(void) /* this is called during a new game and nowhere else */ -{ - Gv_Free(); - - for (auto &aGameVar : aaGameVars) - { - if (aGameVar.szLabel != NULL) - Gv_NewVar(aGameVar.szLabel, (aGameVar.flags & GAMEVAR_NODEFAULT) ? aGameVar.global : aGameVar.defaultValue, aGameVar.flags); - } -} - -void Gv_NewVar(const char *pszLabel, intptr_t lValue, uint32_t dwFlags) -{ - int gV = hash_find(&h_gamevars,pszLabel); - - if (gV >= 0 && !(aaGameVars[gV].flags & GAMEVAR_RESET)) - { - // found it... - if (EDUKE32_PREDICT_FALSE(aaGameVars[gV].flags & (GAMEVAR_PTR_MASK))) - { - ReportError(-1); - Printf("%s:%d: warning: cannot redefine internal gamevar `%s'.\n",g_scriptFileName,line_number,label+(labelcnt<<6)); - return; - } - else if (EDUKE32_PREDICT_FALSE(!(aaGameVars[gV].flags & GAMEVAR_SYSTEM))) - { - // it's a duplicate in error - warningcount++; - ReportError(WARNING_DUPLICATEDEFINITION); - return; - } - } - - if (gV == -1) - gV = g_gameVarCount; - - // If it's a user gamevar... - if ((aaGameVars[gV].flags & GAMEVAR_SYSTEM) == 0) - { - // Allocate and set its label - if (aaGameVars[gV].szLabel == NULL) - aaGameVars[gV].szLabel = (char *)Xcalloc(MAXVARLABEL,sizeof(uint8_t)); - - if (aaGameVars[gV].szLabel != pszLabel) - Bstrcpy(aaGameVars[gV].szLabel,pszLabel); - - // and the flags - aaGameVars[gV].flags=dwFlags; - - // only free if per-{actor,player} - if (aaGameVars[gV].flags & GAMEVAR_USER_MASK) - ALIGNED_FREE_AND_NULL(aaGameVars[gV].pValues); - } - - // if existing is system, they only get to change default value.... - aaGameVars[gV].defaultValue = lValue; - aaGameVars[gV].flags &= ~GAMEVAR_RESET; - - if (gV == g_gameVarCount) - { - // we're adding a new one. - hash_add(&h_gamevars, aaGameVars[gV].szLabel, g_gameVarCount++, 0); - } - - // Set initial values. (Or, override values for system gamevars.) - if (aaGameVars[gV].flags & GAMEVAR_PERPLAYER) - { - if (!aaGameVars[gV].pValues) - { - aaGameVars[gV].pValues = (intptr_t *) Xaligned_alloc(PLAYER_VAR_ALIGNMENT, MAXPLAYERS * sizeof(intptr_t)); - Bmemset(aaGameVars[gV].pValues, 0, MAXPLAYERS * sizeof(intptr_t)); - } - for (bssize_t j=MAXPLAYERS-1; j>=0; --j) - aaGameVars[gV].pValues[j]=lValue; - } - else if (aaGameVars[gV].flags & GAMEVAR_PERACTOR) - { - if (!aaGameVars[gV].pValues) - { - aaGameVars[gV].pValues = (intptr_t *) Xaligned_alloc(ACTOR_VAR_ALIGNMENT, MAXSPRITES * sizeof(intptr_t)); - Bmemset(aaGameVars[gV].pValues, 0, MAXSPRITES * sizeof(intptr_t)); - } - for (bssize_t j=MAXSPRITES-1; j>=0; --j) - aaGameVars[gV].pValues[j]=lValue; - } - else aaGameVars[gV].global = lValue; -} - -static int Gv_GetVarIndex(const char *szGameLabel) -{ - int const gameVar = hash_find(&h_gamevars,szGameLabel); - - if (EDUKE32_PREDICT_FALSE((unsigned)gameVar >= MAXGAMEVARS)) - { - Printf(TEXTCOLOR_RED "Gv_GetVarIndex(): INTERNAL ERROR: couldn't find gamevar %s!\n", szGameLabel); - return 0; - } - - return gameVar; -} - -static FORCE_INLINE int __fastcall getvar__(int const gameVar, int const spriteNum, int const playerNum) -{ - auto const &var = aaGameVars[gameVar & (MAXGAMEVARS-1)]; - - int returnValue = 0; - int const varFlags = var.flags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK); - - if (!varFlags) returnValue = var.global; - else if (varFlags == GAMEVAR_PERACTOR) - returnValue = var.pValues[spriteNum & (MAXSPRITES-1)]; - else if (varFlags == GAMEVAR_PERPLAYER) - returnValue = var.pValues[playerNum & (MAXPLAYERS-1)]; - else switch (varFlags & GAMEVAR_PTR_MASK) - { - case GAMEVAR_INT32PTR: returnValue = *(int32_t *)var.global; break; - case GAMEVAR_INT16PTR: returnValue = *(int16_t *)var.global; break; - } - - return returnValue; -} - -int __fastcall Gv_GetVar(int const gameVar, int const spriteNum, int const playerNum) { return getvar__(gameVar, spriteNum, playerNum); } -int __fastcall Gv_GetVar(int const gameVar) { return getvar__(gameVar, vm.spriteNum, vm.playerNum); } - -void __fastcall Gv_GetManyVars(int const numVars, int32_t * const outBuf) -{ - for (native_t j = 0; j < numVars; ++j) - outBuf[j] = getvar__(*insptr++, vm.spriteNum, vm.playerNum); -} - -static FORCE_INLINE void __fastcall setvar__(int const gameVar, int const newValue, int const spriteNum, int const playerNum) -{ - gamevar_t &var = aaGameVars[gameVar]; - int const varFlags = var.flags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK); - - if (!varFlags) var.global=newValue; - else if (varFlags == GAMEVAR_PERACTOR) - var.pValues[spriteNum & (MAXSPRITES-1)] = newValue; - else if (varFlags == GAMEVAR_PERPLAYER) - var.pValues[playerNum & (MAXPLAYERS-1)] = newValue; - else switch (varFlags & GAMEVAR_PTR_MASK) - { - case GAMEVAR_INT32PTR: *((int32_t *)var.global) = (int32_t)newValue; break; - case GAMEVAR_INT16PTR: *((int16_t *)var.global) = (int16_t)newValue; break; - } - return; -} - -void __fastcall Gv_SetVar(int const gameVar, int const newValue) { setvar__(gameVar, newValue, vm.spriteNum, vm.playerNum); } -void __fastcall Gv_SetVar(int const gameVar, int const newValue, int const spriteNum, int const playerNum) -{ - setvar__(gameVar, newValue, spriteNum, playerNum); -} - -int Gv_GetVarByLabel(const char *szGameLabel, int const defaultValue, int const spriteNum, int const playerNum) -{ - int const gameVar = hash_find(&h_gamevars, szGameLabel); - return EDUKE32_PREDICT_TRUE(gameVar >= 0) ? Gv_GetVar(gameVar, spriteNum, playerNum) : defaultValue; -} - -static intptr_t *Gv_GetVarDataPtr(const char *szGameLabel) -{ - int const gameVar = hash_find(&h_gamevars, szGameLabel); - - if (EDUKE32_PREDICT_FALSE((unsigned)gameVar >= MAXGAMEVARS)) - return NULL; - - gamevar_t &var = aaGameVars[gameVar]; - - if (var.flags & (GAMEVAR_USER_MASK | GAMEVAR_PTR_MASK)) - return var.pValues; - - return &(var.global); -} - -void Gv_ResetSystemDefaults(void) -{ - // call many times... - char aszBuf[64]; - - for (int weaponNum = 0; weaponNum < MAX_WEAPONS; ++weaponNum) - { - for (int playerNum = 0; playerNum < MAXPLAYERS; ++playerNum) - { - Bsprintf(aszBuf, "WEAPON%d_CLIP", weaponNum); - aplWeaponClip[weaponNum][playerNum] = Gv_GetVarByLabel(aszBuf, 0, -1, playerNum); - Bsprintf(aszBuf, "WEAPON%d_RELOAD", weaponNum); - aplWeaponReload[weaponNum][playerNum] = Gv_GetVarByLabel(aszBuf, 0, -1, playerNum); - Bsprintf(aszBuf, "WEAPON%d_FIREDELAY", weaponNum); - aplWeaponFireDelay[weaponNum][playerNum] = Gv_GetVarByLabel(aszBuf, 0, -1, playerNum); - Bsprintf(aszBuf, "WEAPON%d_TOTALTIME", weaponNum); - aplWeaponTotalTime[weaponNum][playerNum] = Gv_GetVarByLabel(aszBuf, 0, -1, playerNum); - Bsprintf(aszBuf, "WEAPON%d_HOLDDELAY", weaponNum); - aplWeaponHoldDelay[weaponNum][playerNum] = Gv_GetVarByLabel(aszBuf, 0, -1, playerNum); - Bsprintf(aszBuf, "WEAPON%d_FLAGS", weaponNum); - aplWeaponFlags[weaponNum][playerNum] = Gv_GetVarByLabel(aszBuf, 0, -1, playerNum); - Bsprintf(aszBuf, "WEAPON%d_SHOOTS", weaponNum); - aplWeaponShoots[weaponNum][playerNum] = Gv_GetVarByLabel(aszBuf, 0, -1, playerNum); - if ((unsigned)aplWeaponShoots[weaponNum][playerNum] >= MAXTILES) - aplWeaponShoots[weaponNum][playerNum] = 0; - Bsprintf(aszBuf, "WEAPON%d_SPAWNTIME", weaponNum); - aplWeaponSpawnTime[weaponNum][playerNum] = Gv_GetVarByLabel(aszBuf, 0, -1, playerNum); - Bsprintf(aszBuf, "WEAPON%d_SPAWN", weaponNum); - aplWeaponSpawn[weaponNum][playerNum] = Gv_GetVarByLabel(aszBuf, 0, -1, playerNum); - Bsprintf(aszBuf, "WEAPON%d_SHOTSPERBURST", weaponNum); - aplWeaponShotsPerBurst[weaponNum][playerNum] = Gv_GetVarByLabel(aszBuf, 0, -1, playerNum); - Bsprintf(aszBuf, "WEAPON%d_WORKSLIKE", weaponNum); - aplWeaponWorksLike[weaponNum][playerNum] = Gv_GetVarByLabel(aszBuf, 0, -1, playerNum); - Bsprintf(aszBuf, "WEAPON%d_INITIALSOUND", weaponNum); - aplWeaponInitialSound[weaponNum][playerNum] = Gv_GetVarByLabel(aszBuf, 0, -1, playerNum); - Bsprintf(aszBuf, "WEAPON%d_FIRESOUND", weaponNum); - aplWeaponFireSound[weaponNum][playerNum] = Gv_GetVarByLabel(aszBuf, 0, -1, playerNum); - Bsprintf(aszBuf, "WEAPON%d_SOUND2TIME", weaponNum); - aplWeaponSound2Time[weaponNum][playerNum] = Gv_GetVarByLabel(aszBuf, 0, -1, playerNum); - Bsprintf(aszBuf, "WEAPON%d_SOUND2SOUND", weaponNum); - aplWeaponSound2Sound[weaponNum][playerNum] = Gv_GetVarByLabel(aszBuf, 0, -1, playerNum); - Bsprintf(aszBuf, "WEAPON%d_FLASHCOLOR", weaponNum); - aplWeaponFlashColor[weaponNum][playerNum] = Gv_GetVarByLabel(aszBuf, 0, -1, playerNum); - } - } - - g_aimAngleVarID = Gv_GetVarIndex("AUTOAIMANGLE"); - g_angRangeVarID = Gv_GetVarIndex("ANGRANGE"); - g_returnVarID = Gv_GetVarIndex("RETURN"); - g_weaponVarID = Gv_GetVarIndex("WEAPON"); - g_worksLikeVarID = Gv_GetVarIndex("WORKSLIKE"); - g_zRangeVarID = Gv_GetVarIndex("ZRANGE"); - -} - -// Will set members that were overridden at CON translation time to 1. -// For example, if -// gamevar WEAPON1_SHOOTS 2200 GAMEVAR_PERPLAYER -// was specified at file scope, g_weaponOverridden[1].Shoots will be 1. -weapondata_t g_weaponOverridden[MAX_WEAPONS]; - -static weapondata_t weapondefaults[MAX_WEAPONS] = { - /* - WorksLike, Clip, Reload, FireDelay, TotalTime, HoldDelay, - Flags, - Shoots, SpawnTime, Spawn, ShotsPerBurst, InitialSound, FireSound, Sound2Time, Sound2Sound, - FlashColor - */ - { - KNEE_WEAPON__STATIC, 0, 30, 7, 14, 14, - WEAPON_RANDOMRESTART | WEAPON_AUTOMATIC, - KNEE__STATIC, 0, 0, 0, 0, 0, 0, - 0 - }, - - { - PISTOL_WEAPON, 20, 50, 2, 5, 0, - WEAPON_AUTOMATIC | WEAPON_HOLSTER_CLEARS_CLIP, - SHOTSPARK1__STATIC, 2, SHELL__STATIC, 0, 0, PISTOL_FIRE__STATIC, 0, 0, - 255+(95<<8) - }, - - { - SHOTGUN_WEAPON__STATIC, 0, 13, 4, 31, 0, - WEAPON_CHECKATRELOAD, - SHOTGUN__STATIC, 24, SHOTGUNSHELL__STATIC, 7, 0, SHOTGUN_FIRE__STATIC, 15, SHOTGUN_COCK__STATIC, - 255+(95<<8) - }, - - { - CHAINGUN_WEAPON__STATIC, 0, 30, 1, 12, 10, - WEAPON_AUTOMATIC | WEAPON_FIREEVERYTHIRD | WEAPON_AMMOPERSHOT, - CHAINGUN__STATIC, 0, SHELL__STATIC, 0, 0, CHAINGUN_FIRE__STATIC, 0, 0, - 255+(95<<8) - }, - - { - RPG_WEAPON__STATIC, 0, 30, 4, 20, 0, - 0, - RPG__STATIC, 0, 0, 0, 0, 0, 0, 0, - 255+(95<<8) - }, - - { - HANDBOMB_WEAPON__STATIC, 0, 30, 6, 19, 12, - WEAPON_THROWIT, - HEAVYHBOMB__STATIC, 0, 0, 0, 0, 0, 0, - 0 - }, - - { - SHRINKER_WEAPON__STATIC, 0, 0, 10, 30, 0, - WEAPON_GLOWS, - SHRINKER__STATIC, 0, 0, 0, SHRINKER_FIRE__STATIC, 0, 0, 0, - 176+(252<<8)+(120<<16) - }, - - { - DEVISTATOR_WEAPON__STATIC, 0, 30, 2, 5, 5, - WEAPON_FIREEVERYOTHER, - RPG__STATIC, 0, 0, 2, CAT_FIRE__STATIC, 0, 0, 0, - 255+(95<<8) - }, - - { - TRIPBOMB_WEAPON__STATIC, 0, 30, 3, 16, 0, - WEAPON_STANDSTILL, - HANDHOLDINGLASER__STATIC, 0, 0, 0, 0, 0, 0, - 0 - }, - - { - FREEZE_WEAPON__STATIC, 0, 0, 3, 5, 0, - WEAPON_FIREEVERYOTHER, - FREEZEBLAST__STATIC, 0, 0, 0, CAT_FIRE__STATIC, CAT_FIRE__STATIC, 0, 0, - 72+(88<<8)+(140<<16) - }, - - { - HANDREMOTE_WEAPON__STATIC, 0, 30, 2, 10, 0, - WEAPON_BOMB_TRIGGER | WEAPON_NOVISIBLE, - 0, 0, 0, 0, 0, 0, 0, - 0 - }, - - { - GROW_WEAPON__STATIC, 0, 0, 3, 30, 0, - WEAPON_GLOWS, - GROWSPARK__STATIC, 0, 0, 0, EXPANDERSHOOT__STATIC, EXPANDERSHOOT__STATIC, 0, 0, - 216+(52<<8)+(20<<16) - }, -}; - -// KEEPINSYNC with what is contained above -// XXX: ugly -static int32_t G_StaticToDynamicTile(int32_t const tile) -{ - switch (tile) - { -#ifndef EDUKE32_STANDALONE - case CHAINGUN__STATIC: return TILE_CHAINGUN; - case FREEZEBLAST__STATIC: return TILE_FREEZEBLAST; - case GROWSPARK__STATIC: return TILE_GROWSPARK; - case HANDHOLDINGLASER__STATIC: return TILE_HANDHOLDINGLASER; - case HEAVYHBOMB__STATIC: return TILE_HEAVYHBOMB; - case KNEE__STATIC: return TILE_KNEE; - case RPG__STATIC: return TILE_RPG; - case SHELL__STATIC: return TILE_SHELL; - case SHOTGUNSHELL__STATIC: return TILE_SHOTGUNSHELL; - case SHOTGUN__STATIC: return TILE_SHOTGUN; - case SHOTSPARK1__STATIC: return TILE_SHOTSPARK1; - case SHRINKER__STATIC: return TILE_SHRINKER; -#endif - default: return tile; - } -} - -static int32_t G_StaticToDynamicSound(int32_t const sound) -{ - switch (sound) - { -#ifndef EDUKE32_STANDALONE - case CAT_FIRE__STATIC: return CAT_FIRE; - case CHAINGUN_FIRE__STATIC: return CHAINGUN_FIRE; - case EJECT_CLIP__STATIC: return EJECT_CLIP; - case EXPANDERSHOOT__STATIC: return EXPANDERSHOOT; - case INSERT_CLIP__STATIC: return INSERT_CLIP; - case PISTOL_FIRE__STATIC: return PISTOL_FIRE; - case SELECT_WEAPON__STATIC: return SELECT_WEAPON; - case SHOTGUN_FIRE__STATIC: return SHOTGUN_FIRE; - case SHOTGUN_COCK__STATIC: return SHOTGUN_COCK; - case SHRINKER_FIRE__STATIC: return SHRINKER_FIRE; -#endif - default: return sound; - } -} - -// Initialize WEAPONx_* gamevars. Since for Lunatic, they reside on the C side, -// they're set directly. In C-CON, a new CON variable is defined together with -// its initial value. -#ifdef LUNATIC -# define ADDWEAPONVAR(Weapidx, Membname) do { \ - int32_t j; \ - for (j=0; j=0; i--) - { - Bsprintf(aszBuf, "WEAPON%d_CLIP", i); - aplWeaponClip[i] = Gv_GetVarDataPtr(aszBuf); - - if (!aplWeaponClip[i]) - { - I_Error("ERROR: NULL weapon! WTF?! %s\n", aszBuf); - } - - Bsprintf(aszBuf, "WEAPON%d_RELOAD", i); - aplWeaponReload[i] = Gv_GetVarDataPtr(aszBuf); - Bsprintf(aszBuf, "WEAPON%d_FIREDELAY", i); - aplWeaponFireDelay[i] = Gv_GetVarDataPtr(aszBuf); - Bsprintf(aszBuf, "WEAPON%d_TOTALTIME", i); - aplWeaponTotalTime[i] = Gv_GetVarDataPtr(aszBuf); - Bsprintf(aszBuf, "WEAPON%d_HOLDDELAY", i); - aplWeaponHoldDelay[i] = Gv_GetVarDataPtr(aszBuf); - Bsprintf(aszBuf, "WEAPON%d_FLAGS", i); - aplWeaponFlags[i] = Gv_GetVarDataPtr(aszBuf); - Bsprintf(aszBuf, "WEAPON%d_SHOOTS", i); - aplWeaponShoots[i] = Gv_GetVarDataPtr(aszBuf); - Bsprintf(aszBuf, "WEAPON%d_SPAWNTIME", i); - aplWeaponSpawnTime[i] = Gv_GetVarDataPtr(aszBuf); - Bsprintf(aszBuf, "WEAPON%d_SPAWN", i); - aplWeaponSpawn[i] = Gv_GetVarDataPtr(aszBuf); - Bsprintf(aszBuf, "WEAPON%d_SHOTSPERBURST", i); - aplWeaponShotsPerBurst[i] = Gv_GetVarDataPtr(aszBuf); - Bsprintf(aszBuf, "WEAPON%d_WORKSLIKE", i); - aplWeaponWorksLike[i] = Gv_GetVarDataPtr(aszBuf); - Bsprintf(aszBuf, "WEAPON%d_INITIALSOUND", i); - aplWeaponInitialSound[i] = Gv_GetVarDataPtr(aszBuf); - Bsprintf(aszBuf, "WEAPON%d_FIRESOUND", i); - aplWeaponFireSound[i] = Gv_GetVarDataPtr(aszBuf); - Bsprintf(aszBuf, "WEAPON%d_SOUND2TIME", i); - aplWeaponSound2Time[i] = Gv_GetVarDataPtr(aszBuf); - Bsprintf(aszBuf, "WEAPON%d_SOUND2SOUND", i); - aplWeaponSound2Sound[i] = Gv_GetVarDataPtr(aszBuf); - Bsprintf(aszBuf, "WEAPON%d_FLASHCOLOR", i); - aplWeaponFlashColor[i] = Gv_GetVarDataPtr(aszBuf); - } -} - -void Gv_RefreshPointers(void) -{ - aaGameVars[Gv_GetVarIndex("COOP")].global = (intptr_t)&ud.coop; - aaGameVars[Gv_GetVarIndex("FFIRE")].global = (intptr_t)&ud.ffire; - aaGameVars[Gv_GetVarIndex("LEVEL")].global = (intptr_t)&ud.level_number; - aaGameVars[Gv_GetVarIndex("MARKER")].global = (intptr_t)&ud.marker; - aaGameVars[Gv_GetVarIndex("MONSTERS_OFF")].global = (intptr_t)&ud.monsters_off; - aaGameVars[Gv_GetVarIndex("MULTIMODE")].global = (intptr_t)&ud.multimode; - aaGameVars[Gv_GetVarIndex("RESPAWN_INVENTORY")].global = (intptr_t)&ud.respawn_inventory; - aaGameVars[Gv_GetVarIndex("RESPAWN_ITEMS")].global = (intptr_t)&ud.respawn_items; - aaGameVars[Gv_GetVarIndex("RESPAWN_MONSTERS")].global = (intptr_t)&ud.respawn_monsters; - aaGameVars[Gv_GetVarIndex("VOLUME")].global = (intptr_t)&ud.volume_number; -} -#endif - -END_DUKE_NS diff --git a/source/games/duke/src/zz_player.cpp b/source/games/duke/src/zz_player.cpp index 1f00b0474..9a5e1b7c9 100644 --- a/source/games/duke/src/zz_player.cpp +++ b/source/games/duke/src/zz_player.cpp @@ -24,6 +24,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "duke3d.h" #include "demo.h" #include "d_event.h" +#include "gamevar.h" BEGIN_DUKE_NS @@ -308,11 +309,11 @@ static int GetAutoAimAng(int spriteNum, int playerNum, int projecTile, int zAdju Bassert((unsigned)playerNum < MAXPLAYERS); - Gv_SetVar(g_aimAngleVarID, (g_player[playerNum].ps->auto_aim == 3 && (!RRRA || projecTile != TILE_RPG2)) ? AUTO_AIM_ANGLE<<1 : AUTO_AIM_ANGLE, spriteNum, playerNum); + SetGameVarID(g_iAimAngleVarID, (g_player[playerNum].ps->auto_aim == 3 && (!RRRA || projecTile != TILE_RPG2)) ? AUTO_AIM_ANGLE<<1 : AUTO_AIM_ANGLE, spriteNum, playerNum); VM_OnEvent(EVENT_GETAUTOAIMANGLE, spriteNum, playerNum); - int aimang = Gv_GetVar(g_aimAngleVarID, spriteNum, playerNum); + int aimang = GetGameVarID(g_iAimAngleVarID, spriteNum, playerNum); if (aimang > 0) returnSprite = A_FindTargetSprite(&sprite[spriteNum], aimang, projecTile); @@ -371,13 +372,13 @@ static void P_PreFireHitscan(int spriteNum, int playerNum, int projecTile, vec3_ DukePlayer_t *const pPlayer = g_player[playerNum].ps; - Gv_SetVar(g_angRangeVarID, angRange, spriteNum, playerNum); - Gv_SetVar(g_zRangeVarID, zRange, spriteNum, playerNum); + SetGameVarID(g_iAngRangeVarID, angRange, spriteNum, playerNum); + SetGameVarID(g_iZRangeVarID, zRange, spriteNum, playerNum); VM_OnEvent(EVENT_GETSHOTRANGE, spriteNum, playerNum); - angRange = Gv_GetVar(g_angRangeVarID, spriteNum, playerNum); - zRange = Gv_GetVar(g_zRangeVarID, spriteNum, playerNum); + angRange = GetGameVarID(g_iAngRangeVarID, spriteNum, playerNum); + zRange = GetGameVarID(g_iZRangeVarID, spriteNum, playerNum); if (accurateAim) { @@ -1278,14 +1279,14 @@ growspark_rr: if (placeMine == 1) { - int const tripBombMode = Gv_GetVarByLabel("TRIPBOMB_CONTROL", TRIPBOMB_TRIPWIRE, -1, -1); + int const tripBombMode = GetGameVar("TRIPBOMB_CONTROL", TRIPBOMB_TRIPWIRE, -1, -1); int const spawnedSprite = A_InsertSprite(hitData.sect, hitData.pos.x, hitData.pos.y, hitData.pos.z, TILE_TRIPBOMB, -16, 4, 5, shootAng, 0, 0, spriteNum, 6); if (tripBombMode & TRIPBOMB_TIMER) { - int32_t lLifetime = Gv_GetVarByLabel("STICKYBOMB_LIFETIME", NAM_GRENADE_LIFETIME, -1, playerNum); + int32_t lLifetime = GetGameVar("STICKYBOMB_LIFETIME", NAM_GRENADE_LIFETIME, -1, playerNum); int32_t lLifetimeVar - = Gv_GetVarByLabel("STICKYBOMB_LIFETIME_VAR", NAM_GRENADE_LIFETIME_VAR, -1, playerNum); + = GetGameVar("STICKYBOMB_LIFETIME_VAR", NAM_GRENADE_LIFETIME_VAR, -1, playerNum); // set timer. blows up when at zero.... sprite[spawnedSprite].extra = lLifetime + mulscale14(krand2(), lLifetimeVar) - lLifetimeVar; } @@ -1648,8 +1649,8 @@ void P_SetWeaponGamevars(int playerNum, const DukePlayer_t * const pPlayer) { if (!WW2GI) return; - Gv_SetVar(g_weaponVarID, pPlayer->curr_weapon, pPlayer->i, playerNum); - Gv_SetVar(g_worksLikeVarID, + SetGameVarID(g_iWeaponVarID, pPlayer->curr_weapon, pPlayer->i, playerNum); + SetGameVarID(g_iWorksLikeVarID, ((unsigned)pPlayer->curr_weapon < MAX_WEAPONS) ? PWEAPON(playerNum, pPlayer->curr_weapon, WorksLike) : -1, pPlayer->i, playerNum); } @@ -5878,8 +5879,8 @@ static void P_ProcessWeapon(int playerNum) pPlayer->pos.z,PWEAPON(playerNum, pPlayer->curr_weapon, Shoots),-16,9,9, fix16_to_int(pPlayer->q16ang),(pipeBombFwdVel+(pPlayer->hbomb_hold_delay<<5)),pipeBombZvel,pPlayer->i,1); - int pipeLifeTime = Gv_GetVarByLabel("GRENADE_LIFETIME", NAM_GRENADE_LIFETIME, -1, playerNum); - int pipeLifeVariance = Gv_GetVarByLabel("GRENADE_LIFETIME_VAR", NAM_GRENADE_LIFETIME_VAR, -1, playerNum); + int pipeLifeTime = GetGameVar("GRENADE_LIFETIME", NAM_GRENADE_LIFETIME, -1, playerNum); + int pipeLifeVariance = GetGameVar("GRENADE_LIFETIME_VAR", NAM_GRENADE_LIFETIME_VAR, -1, playerNum); sprite[pipeSpriteNum].extra = pipeLifeTime + mulscale14(krand2(), pipeLifeVariance) - pipeLifeVariance; diff --git a/source/games/duke/src/zz_premap.cpp b/source/games/duke/src/zz_premap.cpp index f776bf7fb..7ba60c124 100644 --- a/source/games/duke/src/zz_premap.cpp +++ b/source/games/duke/src/zz_premap.cpp @@ -1933,10 +1933,7 @@ end_vol4a: pPlayer->gm = 0; M_ClearMenus(); - Gv_ResetVars(); - Gv_InitWeaponPointers(); - Gv_RefreshPointers(); - Gv_ResetSystemDefaults(); + ResetGameVars(); //AddLog("Newgame"); diff --git a/source/games/duke/src/zz_savegame.cpp b/source/games/duke/src/zz_savegame.cpp index aadc18b5d..b011d3b53 100644 --- a/source/games/duke/src/zz_savegame.cpp +++ b/source/games/duke/src/zz_savegame.cpp @@ -1331,7 +1331,7 @@ static uint8_t *dosaveplayer2(FileWriter *fil, uint8_t *mem) PRINTSIZE("script"); mem=writespecdata(svgm_anmisc, fil, mem); // animates, quotes & misc. PRINTSIZE("animisc"); - Gv_WriteSave(*fil); // gamevars + //Gv_WriteSave(*fil); // gamevars mem=writespecdata((const dataspec_t *)svgm_vars, 0, mem); PRINTSIZE("vars"); @@ -1354,9 +1354,7 @@ static int32_t doloadplayer2(FileReader &fil, uint8_t **memptr) if (readspecdata(svgm_anmisc, &fil, &mem)) return -6; PRINTSIZE("animisc"); - int i; - - if ((i = Gv_ReadSave(fil))) return i; + //if ((i = Gv_ReadSave(fil))) return i; if (mem) { diff --git a/source/games/duke/src/zz_sbar.cpp b/source/games/duke/src/zz_sbar.cpp index a8f5fdc8a..29e03e8ca 100644 --- a/source/games/duke/src/zz_sbar.cpp +++ b/source/games/duke/src/zz_sbar.cpp @@ -153,7 +153,7 @@ static int32_t G_GetInvOn(const DukePlayer_t* p) static int32_t GetMoraleOrShield(DukePlayer_t *p, int32_t snum) { // WW2GI - int lAmount = Gv_GetVarByLabel("PLR_MORALE", -1, p->i, snum); + int lAmount = GetGameVar("PLR_MORALE", -1, p->i, snum); if (lAmount == -1) lAmount = p->inv_amount[GET_SHIELD]; return lAmount; }