mirror of
https://github.com/DrBeef/Raze.git
synced 2024-11-16 01:11:28 +00:00
- removed most of the old and very messy gamevar code.
# Conflicts: # source/games/duke/src/zz_gamevars.cpp
This commit is contained in:
parent
c9bb23ee42
commit
c59928c6ff
18 changed files with 167 additions and 1037 deletions
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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];
|
||||
|
|
|
@ -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<MAXGAMEVARS;i++)
|
||||
for (i = 0; i < MAXGAMEVARS; i++)
|
||||
{
|
||||
aGameVars[i].lValue=0;
|
||||
aGameVars[i].szLabel[0]=0;
|
||||
aGameVars[i].dwFlags=0;
|
||||
aGameVars[i].plValues=NULL;
|
||||
aGameVars[i].plValue = nullptr;
|
||||
aGameVars[i].szLabel[0] = 0;
|
||||
aGameVars[i].dwFlags = 0;
|
||||
}
|
||||
iGameVarCount=0;
|
||||
iDefaultGameVarCount=0;
|
||||
return;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
// I think the best way to describe the original code here is
|
||||
// "utterly broken by design" ...
|
||||
// I hope this version is saner, there's really no need to tear down and
|
||||
// rebuild the complete set of game vars just to reset them to the defaults...
|
||||
// It makes no sense anyway for actor gamevars because the actor list is dynamic.
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
|
@ -294,15 +282,23 @@ void ResetGameVars(void)
|
|||
{
|
||||
int i;
|
||||
|
||||
FreeGameVars();
|
||||
for(i=0;i<iDefaultGameVarCount;i++)
|
||||
for(i=0;i<iGameVarCount;i++)
|
||||
{
|
||||
AddGameVar(aDefaultGameVars[i].szLabel,
|
||||
aDefaultGameVars[i].lValue,
|
||||
aDefaultGameVars[i].dwFlags | GAMEVAR_FLAG_NODEFAULT
|
||||
);
|
||||
if (!(aGameVars[i].dwFlags & GAMEVAR_FLAG_PLONG))
|
||||
{
|
||||
if (aGameVars[i].dwFlags & (GAMEVAR_FLAG_PERPLAYER | GAMEVAR_FLAG_PERACTOR))
|
||||
{
|
||||
for (auto& v : aGameVars[i].plArray)
|
||||
{
|
||||
v = aGameVars[i].defaultValue;
|
||||
}
|
||||
}
|
||||
else if (aGameVars[i].dwFlags & GAMEVAR_FLAG_PERACTOR)
|
||||
{
|
||||
aGameVars[i].lValue = aGameVars[i].defaultValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
@ -318,16 +314,12 @@ int GetGameVarID(int id, int sActor, int sPlayer)
|
|||
Printf("GetGameVarID: Invalid Game ID %d\n", id);
|
||||
return -1;
|
||||
}
|
||||
if( id == g_iThisActorID )
|
||||
{
|
||||
return sActor;
|
||||
}
|
||||
if( aGameVars[id].dwFlags & GAMEVAR_FLAG_PERPLAYER )
|
||||
{
|
||||
// for the current player
|
||||
if(sPlayer >=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<iGameVarCount;i++)
|
||||
for (int i = 0; i < iGameVarCount; i++)
|
||||
{
|
||||
if( strcmp(szGameLabel, aGameVars[i].szLabel) == 0 )
|
||||
if (strcmp(szGameLabel, aGameVars[i].szLabel) == 0)
|
||||
{
|
||||
return GetGameVarID(i, sActor, sPlayer);
|
||||
}
|
||||
|
@ -416,7 +407,6 @@ int GetGameVar(char *szGameLabel, int lDefault, short sActor, short sPlayer)
|
|||
return lDefault;
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
|
@ -432,11 +422,11 @@ int *GetGameValuePtr(char *szGameLabel)
|
|||
{
|
||||
if(aGameVars[i].dwFlags & (GAMEVAR_FLAG_PERACTOR | GAMEVAR_FLAG_PERPLAYER))
|
||||
{
|
||||
if(!aGameVars[i].plValues)
|
||||
if(!aGameVars[i].plArray.Size() == 0)
|
||||
{
|
||||
Printf("INTERNAL ERROR: NULL array !!!\n");
|
||||
}
|
||||
return aGameVars[i].plValues;
|
||||
return aGameVars[i].plArray.Data();
|
||||
}
|
||||
return &(aGameVars[i].lValue);
|
||||
}
|
||||
|
@ -445,9 +435,10 @@ int *GetGameValuePtr(char *szGameLabel)
|
|||
|
||||
}
|
||||
|
||||
#if 0
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
// Event stuff
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
|
@ -531,6 +522,7 @@ void OnEvent(int iEventID, short i,short p,long x)
|
|||
killit_flag=okillit_flag;
|
||||
insptr=oinsptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
|
@ -554,8 +546,13 @@ int *aplWeaponFireSound[MAX_WEAPONS]; // Sound made when firing (each time for a
|
|||
int *aplWeaponSound2Time[MAX_WEAPONS]; // Alternate sound time
|
||||
int *aplWeaponSound2Sound[MAX_WEAPONS]; // Alternate sound sound ID
|
||||
|
||||
|
||||
void SetSystemVarPointers();
|
||||
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"
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
|
@ -565,20 +562,17 @@ void SetSystemVarPointers();
|
|||
|
||||
void InitGameVarPointers(void)
|
||||
{
|
||||
int i,j;
|
||||
int i;
|
||||
char aszBuf[64];
|
||||
// called from game Init AND when level is loaded...
|
||||
|
||||
//AddLog("InitGameVarPointers");
|
||||
|
||||
for(i=0;i<MAX_WEAPONS;i++)
|
||||
{
|
||||
sprintf(aszBuf,"WEAPON%d_CLIP",i);
|
||||
aplWeaponClip[i]=GetGameValuePtr(aszBuf);
|
||||
if(!aplWeaponClip[i])
|
||||
{
|
||||
printf("ERROR: NULL Weapon\n");
|
||||
exit(0);
|
||||
I_FatalError("ERROR: NULL Weapon\n");
|
||||
}
|
||||
sprintf(aszBuf,"WEAPON%d_RELOAD",i);
|
||||
aplWeaponReload[i]=GetGameValuePtr(aszBuf);
|
||||
|
@ -623,10 +617,9 @@ void InitGameVarPointers(void)
|
|||
aplWeaponSound2Sound[i]=GetGameValuePtr(aszBuf);
|
||||
|
||||
}
|
||||
SetSystemVarPointers();
|
||||
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
|
@ -636,10 +629,8 @@ void InitGameVarPointers(void)
|
|||
void AddSystemVars()
|
||||
{
|
||||
// only call ONCE
|
||||
int i;
|
||||
char aszBuf[64];
|
||||
|
||||
#if 0
|
||||
/////////////////////////////
|
||||
sprintf(aszBuf,"WEAPON%d_WORKSLIKE",KNEE_WEAPON);
|
||||
AddGameVar(aszBuf, KNEE_WEAPON, GAMEVAR_FLAG_PERPLAYER | GAMEVAR_FLAG_SYSTEM);
|
||||
|
@ -1216,19 +1207,6 @@ void AddSystemVars()
|
|||
AddGameVar("ANGRANGE", 0, GAMEVAR_FLAG_SYSTEM);
|
||||
AddGameVar("AUTOAIMANGLE", 0, GAMEVAR_FLAG_SYSTEM);
|
||||
|
||||
#endif
|
||||
|
||||
SetSystemVarPointers();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
void SetSystemVarPointers()
|
||||
{
|
||||
AddGameVar("RESPAWN_MONSTERS", (intptr_t)&ud.respawn_monsters,GAMEVAR_FLAG_SYSTEM | GAMEVAR_FLAG_PLONG);
|
||||
AddGameVar("RESPAWN_ITEMS",(intptr_t)&ud.respawn_items, GAMEVAR_FLAG_SYSTEM | GAMEVAR_FLAG_PLONG);
|
||||
AddGameVar("RESPAWN_INVENTORY",(intptr_t)&ud.respawn_inventory, GAMEVAR_FLAG_SYSTEM | GAMEVAR_FLAG_PLONG);
|
||||
|
@ -1311,7 +1289,4 @@ void ResetSystemDefaults(void)
|
|||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
END_DUKE_NS
|
||||
|
|
|
@ -77,6 +77,64 @@ enum
|
|||
GAMEVAR_FLAG_PLONG = 8192, // plValue is a pointer to a long
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
NAM_GRENADE_LIFETIME = 120,
|
||||
NAM_GRENADE_LIFETIME_VAR = 30,
|
||||
};
|
||||
|
||||
extern int* aplWeaponClip[MAX_WEAPONS]; // number of items in clip
|
||||
extern int* aplWeaponReload[MAX_WEAPONS]; // delay to reload (include fire)
|
||||
extern int* aplWeaponFireDelay[MAX_WEAPONS]; // delay to fire
|
||||
extern int* aplWeaponHoldDelay[MAX_WEAPONS]; // delay after release fire button to fire (0 for none)
|
||||
extern int* aplWeaponTotalTime[MAX_WEAPONS]; // The total time the weapon is cycling before next fire.
|
||||
extern int* aplWeaponFlags[MAX_WEAPONS]; // Flags for weapon
|
||||
extern int* aplWeaponShoots[MAX_WEAPONS]; // what the weapon shoots
|
||||
extern int* aplWeaponSpawnTime[MAX_WEAPONS]; // the frame at which to spawn an item
|
||||
extern int* aplWeaponSpawn[MAX_WEAPONS]; // the item to spawn
|
||||
extern int* aplWeaponShotsPerBurst[MAX_WEAPONS]; // number of shots per 'burst' (one ammo per 'burst'
|
||||
extern int* aplWeaponWorksLike[MAX_WEAPONS]; // What original the weapon works like
|
||||
extern int* aplWeaponInitialSound[MAX_WEAPONS]; // Sound made when initialy firing. zero for no sound
|
||||
extern int* aplWeaponFireSound[MAX_WEAPONS]; // Sound made when firing (each time for automatic)
|
||||
extern int* aplWeaponSound2Time[MAX_WEAPONS]; // Alternate sound time
|
||||
extern int* aplWeaponSound2Sound[MAX_WEAPONS]; // Alternate sound sound ID
|
||||
|
||||
|
||||
enum
|
||||
{
|
||||
// 'holstering' clears the current clip
|
||||
WEAPON_FLAG_HOLSTER_CLEARS_CLIP = 1,
|
||||
// weapon 'glows' (shrinker and grower)
|
||||
WEAPON_FLAG_GLOWS = 2,
|
||||
// automatic fire (continues while 'fire' is held down
|
||||
WEAPON_FLAG_AUTOMATIC = 4,
|
||||
// during 'hold time' fire every frame
|
||||
WEAPON_FLAG_FIREEVERYOTHER = 8,
|
||||
// during 'hold time' fire every third frame.
|
||||
WEAPON_FLAG_FIREEVERYTHIRD = 16,
|
||||
// restart for automatic is 'randomized' by RND 3
|
||||
WEAPON_FLAG_RANDOMRESTART = 32,
|
||||
// uses ammo for each shot (for automatic)
|
||||
WEAPON_FLAG_AMMOPERSHOT = 64,
|
||||
// weapon is the 'bomb' trigger
|
||||
WEAPON_FLAG_BOMB_TRIGGER = 128,
|
||||
// weapon use does not cause user to become 'visible'
|
||||
WEAPON_FLAG_NOVISIBLE = 256,
|
||||
// weapon 'throws' the 'shoots' item...
|
||||
WEAPON_FLAG_THROWIT = 512,
|
||||
// check weapon availability at 'reload' time
|
||||
WEAPON_FLAG_CHECKATRELOAD = 1024,
|
||||
// player stops jumping before actual fire (like tripbomb in duke)
|
||||
WEAPON_FLAG_STANDSTILL = 2048,
|
||||
// just spawn
|
||||
WEAPON_FLAG_SPAWNTYPE1 = 0,
|
||||
// spawn like shotgun shells
|
||||
WEAPON_FLAG_SPAWNTYPE2 = 4096,
|
||||
// spawn like chaingun shells
|
||||
WEAPON_FLAG_SPAWNTYPE3 = 8192
|
||||
};
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
union
|
||||
|
@ -117,7 +175,7 @@ void AddSystemVars();
|
|||
void ResetGameVars(void);
|
||||
int GetGameVarID(int id, int sActor, int sPlayer);
|
||||
void SetGameVarID(int id, int lValue, int sActor, int sPlayer);
|
||||
int GetGameVar(char* szGameLabel, int lDefault, int sActor, int sPlayer);
|
||||
int GetGameVar(const char* szGameLabel, int lDefault, int sActor, int sPlayer);
|
||||
|
||||
void ClearGameEvents();
|
||||
bool IsGameEvent(int i);
|
||||
|
|
|
@ -1,141 +0,0 @@
|
|||
//-------------------------------------------------------------------------
|
||||
/*
|
||||
Copyright (C) 2010 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.
|
||||
*/
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
#ifndef gamevars_h_
|
||||
#define gamevars_h_
|
||||
|
||||
#include "gamedef.h"
|
||||
#include "gamevar.h"
|
||||
|
||||
BEGIN_DUKE_NS
|
||||
|
||||
// store global game definitions
|
||||
enum GamevarFlags_t
|
||||
{
|
||||
GAMEVAR_PERPLAYER = 0x00000001, // per-player variable
|
||||
GAMEVAR_PERACTOR = 0x00000002, // per-actor variable
|
||||
GAMEVAR_USER_MASK = (GAMEVAR_PERPLAYER | GAMEVAR_PERACTOR),
|
||||
GAMEVAR_RESET = 0x00000008, // INTERNAL, don't use
|
||||
GAMEVAR_DEFAULT = 0x00000100, // UNUSED, but always cleared for user-defined gamevars
|
||||
GAMEVAR_NODEFAULT = 0x00000400, // don't reset on actor spawn
|
||||
GAMEVAR_SYSTEM = 0x00000800, // cannot change mode flags...(only default value)
|
||||
GAMEVAR_READONLY = 0x00001000, // values are read-only (no setvar allowed)
|
||||
GAMEVAR_INT32PTR = 0x00002000, // plValues is a pointer to an int32_t
|
||||
GAMEVAR_INT16PTR = 0x00008000, // plValues is a pointer to a short
|
||||
|
||||
GAMEVAR_PTR_MASK = GAMEVAR_INT32PTR | GAMEVAR_INT16PTR,
|
||||
};
|
||||
|
||||
// Alignments for per-player and per-actor variables.
|
||||
#define PLAYER_VAR_ALIGNMENT (sizeof(intptr_t))
|
||||
#define ACTOR_VAR_ALIGNMENT 16
|
||||
|
||||
#define ARRAY_ALIGNMENT 16
|
||||
|
||||
#pragma pack(push,1)
|
||||
typedef struct
|
||||
{
|
||||
union {
|
||||
intptr_t global;
|
||||
intptr_t *pValues; // array of values when 'per-player', or 'per-actor'
|
||||
};
|
||||
intptr_t defaultValue;
|
||||
union
|
||||
{
|
||||
uintptr_t flags;
|
||||
uintptr_t dwFlags;
|
||||
};
|
||||
char * szLabel;
|
||||
} gamevar_t;
|
||||
#pragma pack(pop)
|
||||
|
||||
extern gamevar_t aaGameVars[MAXGAMEVARS];
|
||||
extern int32_t g_gameVarCount;
|
||||
|
||||
int __fastcall Gv_GetVar(int const gameVar, int const spriteNum, int const playerNum);
|
||||
void __fastcall Gv_SetVar(int const gameVar, int const newValue, int const spriteNum, int const playerNum);
|
||||
int __fastcall Gv_GetVar(int const gameVar);
|
||||
void __fastcall Gv_GetManyVars(int const numVars, int32_t * const outBuf);
|
||||
void __fastcall Gv_SetVar(int const gameVar, int const newValue);
|
||||
|
||||
inline void SetGameVarID(int var, int newval, int snum, int pnum)
|
||||
{
|
||||
Gv_SetVar(var, newval, snum, pnum);
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
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
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -6514,12 +6514,7 @@ static void G_Cleanup(void)
|
|||
#endif
|
||||
Xfree(apScript);
|
||||
|
||||
// Xfree(MusicPtr);
|
||||
|
||||
Gv_Clear();
|
||||
|
||||
hash_free(&h_gamevars);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
===================
|
||||
|
|
|
@ -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 "<invalid keyword>";
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<MAXPLAYERS; j++) \
|
||||
g_playerWeapon[j][Weapidx].Membname = weapondefaults[Weapidx].Membname; \
|
||||
} while (0)
|
||||
#else
|
||||
# define ADDWEAPONVAR(Weapidx, Membname) do { \
|
||||
FStringf aszBuf("WEAPON%d_" #Membname, Weapidx); \
|
||||
aszBuf.ToUpper(); \
|
||||
Gv_NewVar(aszBuf, weapondefaults[Weapidx].Membname, GAMEVAR_PERPLAYER | GAMEVAR_SYSTEM); \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
// After CON translation, get not-overridden members from weapondefaults[] back
|
||||
// into the live arrays! (That is, g_playerWeapon[][] for Lunatic, WEAPONx_*
|
||||
// gamevars on the CON side in C-CON.)
|
||||
#ifdef LUNATIC
|
||||
# define POSTADDWEAPONVAR(Weapidx, Membname) ADDWEAPONVAR(Weapidx, Membname)
|
||||
#else
|
||||
// NYI
|
||||
# define POSTADDWEAPONVAR(Weapidx, Membname) do {} while (0)
|
||||
#endif
|
||||
|
||||
// Finish a default weapon member after CON translation. If it was not
|
||||
// overridden from CON itself (see example at g_weaponOverridden[]), we set
|
||||
// both the weapondefaults[] entry (probably dead by now) and the live value.
|
||||
#define FINISH_WEAPON_DEFAULT_X(What, i, Membname) do { \
|
||||
if (!g_weaponOverridden[i].Membname) \
|
||||
{ \
|
||||
weapondefaults[i].Membname = G_StaticToDynamic##What(weapondefaults[i].Membname); \
|
||||
POSTADDWEAPONVAR(i, Membname); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define FINISH_WEAPON_DEFAULT_TILE(i, Membname) FINISH_WEAPON_DEFAULT_X(Tile, i, Membname)
|
||||
#define FINISH_WEAPON_DEFAULT_SOUND(i, Membname) FINISH_WEAPON_DEFAULT_X(Sound, i, Membname)
|
||||
|
||||
// Process the dynamic {tile,sound} mappings after CON has been translated.
|
||||
// We cannot do this before, because the dynamic maps are not yet set up then.
|
||||
void Gv_FinalizeWeaponDefaults(void)
|
||||
{
|
||||
for (int i=0; i<MAX_WEAPONS; i++)
|
||||
{
|
||||
FINISH_WEAPON_DEFAULT_TILE(i, Shoots);
|
||||
FINISH_WEAPON_DEFAULT_TILE(i, Spawn);
|
||||
|
||||
FINISH_WEAPON_DEFAULT_SOUND(i, InitialSound);
|
||||
FINISH_WEAPON_DEFAULT_SOUND(i, FireSound);
|
||||
FINISH_WEAPON_DEFAULT_SOUND(i, Sound2Sound);
|
||||
}
|
||||
}
|
||||
#undef FINISH_WEAPON_DEFAULT_SOUND
|
||||
#undef FINISH_WEAPON_DEFAULT_TILE
|
||||
#undef FINISH_WEAPON_DEFAULT_X
|
||||
#undef POSTADDWEAPONVAR
|
||||
|
||||
#if !defined LUNATIC
|
||||
static int32_t lastvisinc;
|
||||
#endif
|
||||
|
||||
static void Gv_AddSystemVars(void)
|
||||
{
|
||||
// only call ONCE
|
||||
|
||||
for (int i=0; i<MAX_WEAPONS; i++)
|
||||
{
|
||||
ADDWEAPONVAR(i, Clip);
|
||||
ADDWEAPONVAR(i, FireDelay);
|
||||
ADDWEAPONVAR(i, FireSound);
|
||||
ADDWEAPONVAR(i, Flags);
|
||||
ADDWEAPONVAR(i, FlashColor);
|
||||
ADDWEAPONVAR(i, HoldDelay);
|
||||
ADDWEAPONVAR(i, InitialSound);
|
||||
ADDWEAPONVAR(i, Reload);
|
||||
ADDWEAPONVAR(i, Shoots);
|
||||
ADDWEAPONVAR(i, ShotsPerBurst);
|
||||
ADDWEAPONVAR(i, Sound2Sound);
|
||||
ADDWEAPONVAR(i, Sound2Time);
|
||||
ADDWEAPONVAR(i, Spawn);
|
||||
ADDWEAPONVAR(i, SpawnTime);
|
||||
ADDWEAPONVAR(i, TotalTime);
|
||||
ADDWEAPONVAR(i, WorksLike);
|
||||
}
|
||||
|
||||
Gv_NewVar("GRENADE_LIFETIME", NAM_GRENADE_LIFETIME, GAMEVAR_SYSTEM | GAMEVAR_PERPLAYER);
|
||||
Gv_NewVar("GRENADE_LIFETIME_VAR", NAM_GRENADE_LIFETIME_VAR, GAMEVAR_SYSTEM | GAMEVAR_PERPLAYER);
|
||||
Gv_NewVar("STICKYBOMB_LIFETIME", NAM_GRENADE_LIFETIME, GAMEVAR_SYSTEM | GAMEVAR_PERPLAYER);
|
||||
Gv_NewVar("STICKYBOMB_LIFETIME_VAR", NAM_GRENADE_LIFETIME_VAR, GAMEVAR_SYSTEM | GAMEVAR_PERPLAYER);
|
||||
Gv_NewVar("TRIPBOMB_CONTROL", TRIPBOMB_TRIPWIRE, GAMEVAR_SYSTEM | GAMEVAR_PERPLAYER);
|
||||
|
||||
Gv_NewVar("ANGRANGE", 18, GAMEVAR_SYSTEM | GAMEVAR_PERPLAYER);
|
||||
Gv_NewVar("AUTOAIMANGLE", 0, GAMEVAR_SYSTEM | GAMEVAR_PERPLAYER);
|
||||
Gv_NewVar("COOP", (intptr_t)&ud.coop, GAMEVAR_SYSTEM | GAMEVAR_INT32PTR);
|
||||
Gv_NewVar("FFIRE", (intptr_t)&ud.ffire, GAMEVAR_SYSTEM | GAMEVAR_INT32PTR);
|
||||
Gv_NewVar("LEVEL", (intptr_t)&ud.level_number, GAMEVAR_SYSTEM | GAMEVAR_INT32PTR | GAMEVAR_READONLY);
|
||||
Gv_NewVar("MARKER", (intptr_t)&ud.marker, GAMEVAR_SYSTEM | GAMEVAR_INT32PTR);
|
||||
Gv_NewVar("MONSTERS_OFF", (intptr_t)&ud.monsters_off, GAMEVAR_SYSTEM | GAMEVAR_INT32PTR);
|
||||
Gv_NewVar("MULTIMODE", (intptr_t)&ud.multimode, GAMEVAR_SYSTEM | GAMEVAR_INT32PTR);
|
||||
Gv_NewVar("RESPAWN_INVENTORY", (intptr_t)&ud.respawn_inventory, GAMEVAR_SYSTEM | GAMEVAR_INT32PTR);
|
||||
Gv_NewVar("RESPAWN_ITEMS", (intptr_t)&ud.respawn_items, GAMEVAR_SYSTEM | GAMEVAR_INT32PTR);
|
||||
Gv_NewVar("RESPAWN_MONSTERS", (intptr_t)&ud.respawn_monsters, GAMEVAR_SYSTEM | GAMEVAR_INT32PTR);
|
||||
Gv_NewVar("RETURN", 0, GAMEVAR_SYSTEM);
|
||||
Gv_NewVar("VOLUME", (intptr_t)&ud.volume_number, GAMEVAR_SYSTEM | GAMEVAR_INT32PTR | GAMEVAR_READONLY);
|
||||
Gv_NewVar("WEAPON", 0, GAMEVAR_SYSTEM | GAMEVAR_PERPLAYER | GAMEVAR_READONLY);
|
||||
Gv_NewVar("WORKSLIKE", 0, GAMEVAR_SYSTEM | GAMEVAR_PERPLAYER | GAMEVAR_READONLY);
|
||||
Gv_NewVar("ZRANGE", 4, GAMEVAR_SYSTEM | GAMEVAR_PERPLAYER);
|
||||
}
|
||||
|
||||
#undef ADDWEAPONVAR
|
||||
|
||||
void Gv_Init(void)
|
||||
{
|
||||
#if !defined LUNATIC
|
||||
// already initialized
|
||||
if (aaGameVars[0].flags)
|
||||
return;
|
||||
#else
|
||||
static int32_t inited=0;
|
||||
if (inited)
|
||||
return;
|
||||
inited = 1;
|
||||
#endif
|
||||
|
||||
// Set up weapon defaults, g_playerWeapon[][].
|
||||
Gv_AddSystemVars();
|
||||
#if !defined LUNATIC
|
||||
Gv_InitWeaponPointers();
|
||||
#endif
|
||||
Gv_ResetSystemDefaults();
|
||||
}
|
||||
|
||||
#if !defined LUNATIC
|
||||
void Gv_InitWeaponPointers(void)
|
||||
{
|
||||
char aszBuf[64];
|
||||
// called from game Init AND when level is loaded...
|
||||
|
||||
//AddLog("Gv_InitWeaponPointers");
|
||||
|
||||
for (int i=(MAX_WEAPONS-1); i>=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
|
|
@ -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;
|
||||
|
|
|
@ -1933,10 +1933,7 @@ end_vol4a:
|
|||
pPlayer->gm = 0;
|
||||
M_ClearMenus();
|
||||
|
||||
Gv_ResetVars();
|
||||
Gv_InitWeaponPointers();
|
||||
Gv_RefreshPointers();
|
||||
Gv_ResetSystemDefaults();
|
||||
ResetGameVars();
|
||||
|
||||
//AddLog("Newgame");
|
||||
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue