From f1b1ce2cc39eda30e6ca161bfd1c79f61dba648d Mon Sep 17 00:00:00 2001 From: helixhorned Date: Fri, 28 Dec 2012 17:18:12 +0000 Subject: [PATCH] Replace wall of dup'd code in Gv_AddSystemVars with something more readable. Specifically, have a weapondata_t type mimicking the aplWeapon* arrays. Keep a list weapondefaults[] which undergoes some static->dynamic tweaks and then makes its way to the WEAPONx_XXX per-player gamevars. git-svn-id: https://svn.eduke32.com/eduke32@3327 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/source/gamedef.h | 24 ++ polymer/eduke32/source/gamevars.c | 640 ++++++++---------------------- 2 files changed, 184 insertions(+), 480 deletions(-) diff --git a/polymer/eduke32/source/gamedef.h b/polymer/eduke32/source/gamedef.h index db39c0c97..88a4f7e40 100644 --- a/polymer/eduke32/source/gamedef.h +++ b/polymer/eduke32/source/gamedef.h @@ -78,6 +78,30 @@ extern char g_szBuf[1024]; extern intptr_t *g_scriptPtr; +typedef struct +{ + // NOTE: the member names must be identical to aplWeapon* suffixes. + int32_t WorksLike; // What the original works like + int32_t Clip; // number of items in magazine + int32_t Reload; // delay to reload (include fire) + int32_t FireDelay; // delay to fire + int32_t TotalTime; // The total time the weapon is cycling before next fire. + int32_t HoldDelay; // delay after release fire button to fire (0 for none) + int32_t Flags; // Flags for weapon + int32_t Shoots; // what the weapon shoots + int32_t SpawnTime; // the frame at which to spawn an item + int32_t Spawn; // the item to spawn + int32_t ShotsPerBurst; // number of shots per 'burst' (one ammo per 'burst') + int32_t InitialSound; // Sound made when weapon starts firing. zero for no sound + int32_t FireSound; // Sound made when firing (each time for automatic) + int32_t Sound2Time; // Alternate sound time + int32_t Sound2Sound; // Alternate sound sound ID + int32_t ReloadSound1; // Sound of magazine being removed + int32_t ReloadSound2; // Sound of magazine being inserted + int32_t SelectSound; // Sound of weapon being selected + int32_t FlashColor; // Muzzle flash color +} weapondata_t; + typedef struct { const char *name; diff --git a/polymer/eduke32/source/gamevars.c b/polymer/eduke32/source/gamevars.c index 3989e33d0..3e7a6ba0a 100644 --- a/polymer/eduke32/source/gamevars.c +++ b/polymer/eduke32/source/gamevars.c @@ -484,8 +484,6 @@ int32_t Gv_NewVar(const char *pszLabel, intptr_t lValue, uint32_t dwFlags) // found it... if (aGameVars[i].dwFlags & (GAMEVAR_PTR_MASK)) { - // warning++; - // initprintf("%s:%d: warning: Internal gamevar \"%s\" cannot be redefined.\n",g_szScriptFileName,g_lineNumber,label+(g_numLabels<<6)); C_ReportError(-1); initprintf("%s:%d: warning: cannot redefine internal gamevar `%s'.\n",g_szScriptFileName,g_lineNumber,label+(g_numLabels<<6)); return 0; @@ -1072,492 +1070,174 @@ void Gv_ResetSystemDefaults(void) //AddLog("EOF:ResetWeaponDefaults"); } +static weapondata_t weapondefaults[MAX_WEAPONS] = { + /* + WorksLike, Clip, Reload, FireDelay, TotalTime, HoldDelay, + Flags, + Shoots, SpawnTime, Spawn, ShotsPerBurst, InitialSound, FireSound, Sound2Time, Sound2Sound, + ReloadSound1, ReloadSound2, SelectSound, FlashColor + */ + + { + KNEE_WEAPON, 0, 0, 7, 14, 0, + WEAPON_NOVISIBLE | WEAPON_RANDOMRESTART | WEAPON_AUTOMATIC, + KNEE__STATIC, 0, 0, 0, 0, 0, 0, + 0, EJECT_CLIP, INSERT_CLIP, 0, 0 + }, + + { + PISTOL_WEAPON, /*NAM?20:*/12, /*NAM?50:*/27, 2, 5, 0, + /*NAM?WEAPON_HOLSTER_CLEARS_CLIP:*/0 | WEAPON_RELOAD_TIMING, + SHOTSPARK1__STATIC, 2, SHELL__STATIC, 0, 0, PISTOL_FIRE, 0, 0, + EJECT_CLIP, INSERT_CLIP, INSERT_CLIP, 255+(95<<8) + }, + + { + SHOTGUN_WEAPON, 0, 13, 4, 30, 0, + WEAPON_CHECKATRELOAD, + SHOTGUN__STATIC, 24, SHOTGUNSHELL__STATIC, 7, 0, SHOTGUN_FIRE, 15, SHOTGUN_COCK, + EJECT_CLIP, INSERT_CLIP, SHOTGUN_COCK, 255+(95<<8) + }, + + { + CHAINGUN_WEAPON, 0, 0, 3, 12, 3, + WEAPON_AUTOMATIC | WEAPON_FIREEVERYTHIRD | WEAPON_AMMOPERSHOT | WEAPON_SPAWNTYPE3 | WEAPON_RESET, + CHAINGUN__STATIC, 1, SHELL__STATIC, 0, 0, CHAINGUN_FIRE, 0, 0, + EJECT_CLIP, INSERT_CLIP, SELECT_WEAPON, 255+(95<<8) + }, + + { + RPG_WEAPON, 0, 0, 4, 20, 0, + 0, + RPG__STATIC, 0, 0, 0, 0, 0, 0, 0, + EJECT_CLIP, INSERT_CLIP, SELECT_WEAPON, 255+(95<<8) + }, + + { + HANDBOMB_WEAPON, 0, 30, 6, 19, 12, + WEAPON_THROWIT, + HEAVYHBOMB__STATIC, 0, 0, 0, 0, 0, 0, + 0, EJECT_CLIP, INSERT_CLIP, 0, 0 + }, + + { + SHRINKER_WEAPON, 0, 0, 10, /*NAM?30:*/12, 0, + WEAPON_GLOWS, + SHRINKER__STATIC, 0, 0, 0, SHRINKER_FIRE, 0, 0, 0, + EJECT_CLIP, INSERT_CLIP, SELECT_WEAPON, 128+(255<<8)+(128<<16) + }, + + { + DEVISTATOR_WEAPON, 0, 0, 3, 6, 5, + WEAPON_FIREEVERYOTHER | WEAPON_AMMOPERSHOT, + RPG__STATIC, 0, 0, 2, CAT_FIRE, 0, 0, 0, + EJECT_CLIP, INSERT_CLIP, SELECT_WEAPON, 255+(95<<8) + }, + + { + TRIPBOMB_WEAPON, 0, 16, 3, 16, 7, + WEAPON_NOVISIBLE | WEAPON_STANDSTILL | WEAPON_CHECKATRELOAD, + HANDHOLDINGLASER__STATIC, 0, 0, 0, 0, 0, 0, + 0, EJECT_CLIP, INSERT_CLIP, 0, 0 + }, + + { + FREEZE_WEAPON, 0, 0, 3, 5, 0, + WEAPON_RESET, + FREEZEBLAST__STATIC, 0, 0, 0, CAT_FIRE, CAT_FIRE, 0, 0, + EJECT_CLIP, INSERT_CLIP, SELECT_WEAPON, 128+(128<<8)+(255<<16) + }, + + { + HANDREMOTE_WEAPON, 0, 10, 2, 10, 0, + WEAPON_BOMB_TRIGGER | WEAPON_NOVISIBLE, + 0, 0, 0, 0, 0, 0, 0, + 0, EJECT_CLIP, INSERT_CLIP, 0, 0 + }, + + { + GROW_WEAPON, 0, 0, 3, /*NAM?30:*/5, 0, + WEAPON_GLOWS, + GROWSPARK__STATIC, /*NAM?2:*/0, /*NAM?SHELL:*/0, 0, 0, /*NAM?0:*/EXPANDERSHOOT, 0, 0, + EJECT_CLIP, INSERT_CLIP, SELECT_WEAPON, 255+(95<<8) + }, +}; + +// KEEPINSYNC with what is contained above +// XXX: ugly +static int32_t G_StaticToDynamicTile(int32_t tile) +{ + switch (tile) + { + case CHAINGUN__STATIC: return CHAINGUN; + case FREEZEBLAST__STATIC: return FREEZEBLAST; + case GROWSPARK__STATIC: return GROWSPARK; + case HANDHOLDINGLASER__STATIC: return HANDHOLDINGLASER; + case HEAVYHBOMB__STATIC: return HEAVYHBOMB; + case KNEE__STATIC: return KNEE; + case RPG__STATIC: return RPG; + case SHELL__STATIC: return SHELL; + case SHOTGUNSHELL__STATIC: return SHOTGUNSHELL; + case SHOTGUN__STATIC: return SHOTGUN; + case SHOTSPARK1__STATIC: return SHOTSPARK1; + case SHRINKER__STATIC: return SHRINKER; + default: return tile; + } +} + +#define ADDWEAPONVAR(Weapidx, Membname) do { \ + Bsprintf(aszBuf, "WEAPON%d_" #Membname, Weapidx); \ + Bstrupr(aszBuf); \ + Gv_NewVar(aszBuf, weapondefaults[Weapidx].Membname, GAMEVAR_PERPLAYER | GAMEVAR_SYSTEM); \ +} while (0) + static void Gv_AddSystemVars(void) { // only call ONCE char aszBuf[64]; + int32_t i; + + if (NAM) + { + weapondefaults[PISTOL_WEAPON].Clip = 20; + weapondefaults[PISTOL_WEAPON].Reload = 50; + weapondefaults[PISTOL_WEAPON].Flags = WEAPON_HOLSTER_CLEARS_CLIP; + + weapondefaults[SHRINKER_WEAPON].TotalTime = 30; + + weapondefaults[GROW_WEAPON].TotalTime = 30; + weapondefaults[GROW_WEAPON].SpawnTime = 2; + weapondefaults[GROW_WEAPON].Spawn = SHELL; + weapondefaults[GROW_WEAPON].FireSound = 0; + } //AddLog("Gv_AddSystemVars"); - Bsprintf(aszBuf,"WEAPON%d_WORKSLIKE",KNEE_WEAPON); - Gv_NewVar(aszBuf, KNEE_WEAPON, GAMEVAR_PERPLAYER | GAMEVAR_SYSTEM); - Bsprintf(aszBuf,"WEAPON%d_CLIP",KNEE_WEAPON); - Gv_NewVar(aszBuf, 0, GAMEVAR_PERPLAYER | GAMEVAR_SYSTEM); - Bsprintf(aszBuf,"WEAPON%d_RELOAD",KNEE_WEAPON); - Gv_NewVar(aszBuf, 0, GAMEVAR_PERPLAYER | GAMEVAR_SYSTEM); - Bsprintf(aszBuf,"WEAPON%d_FIREDELAY",KNEE_WEAPON); - Gv_NewVar(aszBuf, 7, GAMEVAR_PERPLAYER | GAMEVAR_SYSTEM); - Bsprintf(aszBuf,"WEAPON%d_TOTALTIME",KNEE_WEAPON); - Gv_NewVar(aszBuf, 14, GAMEVAR_PERPLAYER | GAMEVAR_SYSTEM); - Bsprintf(aszBuf,"WEAPON%d_HOLDDELAY",KNEE_WEAPON); - Gv_NewVar(aszBuf, 0, GAMEVAR_PERPLAYER | GAMEVAR_SYSTEM); - Bsprintf(aszBuf,"WEAPON%d_FLAGS",KNEE_WEAPON); - Gv_NewVar(aszBuf, WEAPON_NOVISIBLE | WEAPON_RANDOMRESTART | WEAPON_AUTOMATIC, GAMEVAR_PERPLAYER | GAMEVAR_SYSTEM); - Bsprintf(aszBuf,"WEAPON%d_SHOOTS",KNEE_WEAPON); - Gv_NewVar(aszBuf, KNEE, GAMEVAR_PERPLAYER | GAMEVAR_SYSTEM); - Bsprintf(aszBuf,"WEAPON%d_SPAWNTIME",KNEE_WEAPON); - Gv_NewVar(aszBuf, 0, GAMEVAR_PERPLAYER | GAMEVAR_SYSTEM); - Bsprintf(aszBuf,"WEAPON%d_SPAWN",KNEE_WEAPON); - Gv_NewVar(aszBuf, 0, GAMEVAR_PERPLAYER | GAMEVAR_SYSTEM); - Bsprintf(aszBuf,"WEAPON%d_SHOTSPERBURST",KNEE_WEAPON); - Gv_NewVar(aszBuf, 0, GAMEVAR_PERPLAYER | GAMEVAR_SYSTEM); - Bsprintf(aszBuf,"WEAPON%d_INITIALSOUND",KNEE_WEAPON); - Gv_NewVar(aszBuf, 0, GAMEVAR_PERPLAYER | GAMEVAR_SYSTEM); - Bsprintf(aszBuf,"WEAPON%d_FIRESOUND",KNEE_WEAPON); - Gv_NewVar(aszBuf, 0, GAMEVAR_PERPLAYER | GAMEVAR_SYSTEM); - Bsprintf(aszBuf,"WEAPON%d_SOUND2TIME",KNEE_WEAPON); - Gv_NewVar(aszBuf, 0, GAMEVAR_PERPLAYER | GAMEVAR_SYSTEM); - Bsprintf(aszBuf,"WEAPON%d_SOUND2SOUND",KNEE_WEAPON); - Gv_NewVar(aszBuf, 0, GAMEVAR_PERPLAYER | GAMEVAR_SYSTEM); - Bsprintf(aszBuf,"WEAPON%d_RELOADSOUND1",KNEE_WEAPON); - Gv_NewVar(aszBuf, EJECT_CLIP, GAMEVAR_PERPLAYER | GAMEVAR_SYSTEM); - Bsprintf(aszBuf,"WEAPON%d_RELOADSOUND2",KNEE_WEAPON); - Gv_NewVar(aszBuf, INSERT_CLIP, GAMEVAR_PERPLAYER | GAMEVAR_SYSTEM); - Bsprintf(aszBuf,"WEAPON%d_SELECTSOUND",KNEE_WEAPON); - Gv_NewVar(aszBuf, 0, GAMEVAR_PERPLAYER | GAMEVAR_SYSTEM); - Bsprintf(aszBuf,"WEAPON%d_FLASHCOLOR",KNEE_WEAPON); - Gv_NewVar(aszBuf, 0, GAMEVAR_PERPLAYER | GAMEVAR_SYSTEM); + for (i=0; i