//------------------------------------------------------------------------- /* Copyright (C) 1996, 2003 - 3D Realms Entertainment Copyright (C) 2000, 2003 - Matt Saettler (EDuke Enhancements) Copyright (C) 2004, 2007 - EDuke32 developers 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ //------------------------------------------------------------------------- #include "duke3d.h" #include "gamedef.h" extern int g_i,g_p; static void FreeGameVars(void) { // call this function as many times as needed. int i; // AddLog("FreeGameVars"); for (i=0;i (MAXVARLABEL-1)) { error++; ReportError(-1); initprintf("%s:%ld: error: variable name `%s' exceeds limit of %d characters.\n",compilefile,line_number,pszLabel, MAXVARLABEL); return 0; } for (i=0;i= iGameVarCount) { if (id==MAXGAMEVARS) return(*insptr++); if (!(id&(MAXGAMEVARS<<1))) { OSD_Printf("GetGameVarID(): invalid gamevar ID (%d)\n",id); return -1; } inv=1; id ^= (MAXGAMEVARS<<1); } if (aGameVars[id].dwFlags & GAMEVAR_FLAG_PERPLAYER) { // for the current player if (iPlayer >=0 && iPlayer < MAXPLAYERS) { //Bsprintf(g_szBuf,"GetGameVarID(%d, %d, %d) returns %ld\n",id,iActor,iPlayer, aGameVars[id].plValues[iPlayer]); //AddLog(g_szBuf); if (inv) return(-aGameVars[id].plValues[iPlayer]); return (aGameVars[id].plValues[iPlayer]); } if (inv) return(-aGameVars[id].lValue); return (aGameVars[id].lValue); } if (aGameVars[id].dwFlags & GAMEVAR_FLAG_PERACTOR) { // for the current actor if (iActor >= 0 && iActor <=MAXSPRITES) { if (inv) return(-aGameVars[id].plValues[iActor]); return (aGameVars[id].plValues[iActor]); } if (inv) return(-aGameVars[id].lValue); return (aGameVars[id].lValue); } if (aGameVars[id].dwFlags & GAMEVAR_FLAG_PLONG) { if (inv) return(-(*((long*)aGameVars[id].lValue))); return(*((long*)aGameVars[id].lValue)); } if (aGameVars[id].dwFlags & GAMEVAR_FLAG_PSHORT) { if (inv) return(-(*((short*)aGameVars[id].lValue))); return(*((short*)aGameVars[id].lValue)); } if (aGameVars[id].dwFlags & GAMEVAR_FLAG_PCHAR) { if (inv) return(-(*((char*)aGameVars[id].lValue))); return(*((char*)aGameVars[id].lValue)); } if (inv) return(-aGameVars[id].lValue); return (aGameVars[id].lValue); } void SetGameVarID(int id, long lValue, int iActor, int iPlayer) { if (id<0 || id >= iGameVarCount) { OSD_Printf("SetGameVarID(): tried to set invalid gamevar ID (%d) from sprite %d (%d), player %d\n",id,g_i,sprite[g_i].picnum,g_p); return; } //Bsprintf(g_szBuf,"SGVI: %d ('%s') to %ld for %d %d",id,aGameVars[id].szLabel,lValue,iActor,iPlayer); //AddLog(g_szBuf); if (aGameVars[id].dwFlags & GAMEVAR_FLAG_PERPLAYER) { if (iPlayer < 0 || iPlayer > MAXPLAYERS-1) { OSD_Printf("SetGameVarID(): invalid player (%d) for per-player gamevar %s from sprite %d (%d), player %d\n",iPlayer,aGameVars[id].szLabel,g_i,sprite[g_i].picnum,g_p); return; } // for the current player aGameVars[id].plValues[iPlayer]=lValue; return; } if ((aGameVars[id].dwFlags & GAMEVAR_FLAG_PERACTOR)) { if (iActor < 0 || iActor > MAXSPRITES-1) { OSD_Printf("SetGameVarID(): invalid sprite (%d) for per-actor gamevar %s from sprite %d (%d), player %d\n",iActor,aGameVars[id].szLabel,g_i,sprite[g_i].picnum,g_p); return; } // for the current actor aGameVars[id].plValues[iActor]=lValue; return; } if (aGameVars[id].dwFlags & GAMEVAR_FLAG_PLONG) { // set the value at pointer *((long*)aGameVars[id].lValue)=lValue; return; } if (aGameVars[id].dwFlags & GAMEVAR_FLAG_PSHORT) { // set the value at pointer *((short*)aGameVars[id].lValue)=(short)lValue; return; } if (aGameVars[id].dwFlags & GAMEVAR_FLAG_PCHAR) { // set the value at pointer *((char*)aGameVars[id].lValue)=(char)lValue; return; } aGameVars[id].lValue=lValue; } long GetGameVar(const char *szGameLabel, long lDefault, int iActor, int iPlayer) { int i=0; for (;i