- do not use literal tile numbers for initializing WW2GI's weapon gamevars.

Instead use the type numbers of the items to be spawned so it is derived from configurable data.
This commit is contained in:
Christoph Oelckers 2023-01-01 12:48:01 +01:00
parent 312b649d93
commit 83eb4852f7
6 changed files with 27 additions and 20 deletions

View file

@ -351,7 +351,7 @@ void FMapInfoParser::ParseSpawnClasses()
if (actor != 0 && num >= 0)
{
// todo: check for proper base class
spawnMap.Insert(num, { actor, basetex, brokentex, sound, int8_t(fullbright), int8_t(clipdist), int16_t(flags) });
insertSpawnType(num, { actor, basetex, brokentex, sound, int8_t(fullbright), int8_t(clipdist), int16_t(flags) });
}
}
}

View file

@ -38,6 +38,7 @@
#include "vectors.h"
#include "sc_man.h"
#include "file_zip.h"
#include "actorinfo.h"
struct SpawnRec
{
@ -60,6 +61,12 @@ inline PClassActor* GetSpawnType(int spawnnum)
return nullptr;
}
inline void insertSpawnType(int typenum, const SpawnRec& entry)
{
spawnMap.Insert(typenum, entry);
if (!entry.basetex.isValid()) entry.cls->ActorInfo()->TypeNum = typenum;
}
struct BreakWallRec
{
FTextureID brokentex;

View file

@ -444,10 +444,10 @@ void GameInterface::FinalizeSetup()
}
else if (info == nullptr || !info->basetex.isValid())
{
// No unique actor exists here. Since we need one, create a new class here, directly derived from DDukeActor.
// No unique actor class exists here. Since we need one, create a new class here, directly derived from DDukeActor.
auto newcls = (PClassActor*)RUNTIME_CLASS(DDukeActor)->CreateDerivedClass(FStringf("NewConActor%d", i), RUNTIME_CLASS(DDukeActor)->Size);
newcls->InitializeDefaults();
spawnMap.Insert(i, { newcls, FNullTextureID(), FNullTextureID(), NO_SOUND, int8_t(0), int8_t(0), int16_t(0x8000) });
insertSpawnType(i, { newcls, FNullTextureID(), FNullTextureID(), NO_SOUND, int8_t(0), int8_t(0), int16_t(0x8000) });
cls = newcls;
GetDefaultByType(newcls)->spr.setspritetexture(tileGetTextureID(i)); // make it show the right pic.
}

View file

@ -1212,7 +1212,7 @@ int ConCompiler::parsecommand()
transnum(LABEL_DEFINE);
lnum = popscriptvalue();
gs.actorinfo[lnum].scriptaddress = parsing_actor; // TRANSITIONAL should only store an index
gs.actorinfo[lnum].scriptaddress = parsing_actor;
if (tw == concmd_useractor)
{
gs.actorinfo[lnum].enemyflags |= EDukeFlags1::FromInt(1);
@ -3206,7 +3206,7 @@ void loadcons()
gs.displayflags = DUKE3D_NO_WIDESCREEN_PINNING;
ScriptCode.Clear();
ScriptCode.Resize(1); // We cannot use 0 as a valid index.
labels.Clear();
SortCommands();

View file

@ -643,7 +643,7 @@ void AddSystemVars()
AddGameVar(aszBuf, WEAPON_FLAG_NOVISIBLE | WEAPON_FLAG_AUTOMATIC | WEAPON_FLAG_RANDOMRESTART, GAMEVAR_FLAG_PERPLAYER | GAMEVAR_FLAG_SYSTEM);
sprintf(aszBuf, "WEAPON%d_SHOOTS", KNEE_WEAPON);
AddGameVar(aszBuf, DTILE_KNEE, GAMEVAR_FLAG_PERPLAYER | GAMEVAR_FLAG_SYSTEM);
AddGameVar(aszBuf, DukeMeleeAttackClass->ActorInfo()->TypeNum, GAMEVAR_FLAG_PERPLAYER | GAMEVAR_FLAG_SYSTEM);
sprintf(aszBuf, "WEAPON%d_SPAWNTIME", KNEE_WEAPON);
AddGameVar(aszBuf, 0, GAMEVAR_FLAG_PERPLAYER | GAMEVAR_FLAG_SYSTEM);
@ -690,13 +690,13 @@ void AddSystemVars()
AddGameVar(aszBuf, WEAPON_FLAG_AUTOMATIC | WEAPON_FLAG_HOLSTER_CLEARS_CLIP, GAMEVAR_FLAG_PERPLAYER | GAMEVAR_FLAG_SYSTEM);
sprintf(aszBuf, "WEAPON%d_SHOOTS", PISTOL_WEAPON);
AddGameVar(aszBuf, DTILE_SHOTSPARK1, GAMEVAR_FLAG_PERPLAYER | GAMEVAR_FLAG_SYSTEM);
AddGameVar(aszBuf, DukeShotSparkClass->ActorInfo()->TypeNum, GAMEVAR_FLAG_PERPLAYER | GAMEVAR_FLAG_SYSTEM);
sprintf(aszBuf, "WEAPON%d_SPAWNTIME", PISTOL_WEAPON);
AddGameVar(aszBuf, 2, GAMEVAR_FLAG_PERPLAYER | GAMEVAR_FLAG_SYSTEM);
sprintf(aszBuf, "WEAPON%d_SPAWN", PISTOL_WEAPON);
AddGameVar(aszBuf, DTILE_SHELL, GAMEVAR_FLAG_PERPLAYER | GAMEVAR_FLAG_SYSTEM);
AddGameVar(aszBuf, DukeShellClass->ActorInfo()->TypeNum, GAMEVAR_FLAG_PERPLAYER | GAMEVAR_FLAG_SYSTEM);
sprintf(aszBuf, "WEAPON%d_SHOTSPERBURST", PISTOL_WEAPON);
AddGameVar(aszBuf, 0, GAMEVAR_FLAG_PERPLAYER | GAMEVAR_FLAG_SYSTEM);
@ -736,13 +736,13 @@ void AddSystemVars()
AddGameVar(aszBuf, WEAPON_FLAG_CHECKATRELOAD, GAMEVAR_FLAG_PERPLAYER | GAMEVAR_FLAG_SYSTEM);
sprintf(aszBuf, "WEAPON%d_SHOOTS", SHOTGUN_WEAPON);
AddGameVar(aszBuf, DTILE_SHOTGUN, GAMEVAR_FLAG_PERPLAYER | GAMEVAR_FLAG_SYSTEM);
AddGameVar(aszBuf, DukeShotgunShotClass->ActorInfo()->TypeNum, GAMEVAR_FLAG_PERPLAYER | GAMEVAR_FLAG_SYSTEM);
sprintf(aszBuf, "WEAPON%d_SPAWNTIME", SHOTGUN_WEAPON);
AddGameVar(aszBuf, 24, GAMEVAR_FLAG_PERPLAYER | GAMEVAR_FLAG_SYSTEM);
sprintf(aszBuf, "WEAPON%d_SPAWN", SHOTGUN_WEAPON);
AddGameVar(aszBuf, DTILE_SHOTGUNSHELL, GAMEVAR_FLAG_PERPLAYER | GAMEVAR_FLAG_SYSTEM);
AddGameVar(aszBuf, DukeShotgunShellClass->ActorInfo()->TypeNum, GAMEVAR_FLAG_PERPLAYER | GAMEVAR_FLAG_SYSTEM);
sprintf(aszBuf, "WEAPON%d_SHOTSPERBURST", SHOTGUN_WEAPON);
AddGameVar(aszBuf, 7, GAMEVAR_FLAG_PERPLAYER | GAMEVAR_FLAG_SYSTEM);
@ -784,13 +784,13 @@ void AddSystemVars()
sprintf(aszBuf, "WEAPON%d_SHOOTS", CHAINGUN_WEAPON);
AddGameVar(aszBuf, DTILE_CHAINGUN, GAMEVAR_FLAG_PERPLAYER | GAMEVAR_FLAG_SYSTEM);
AddGameVar(aszBuf, DukeChaingunShotClass->ActorInfo()->TypeNum, GAMEVAR_FLAG_PERPLAYER | GAMEVAR_FLAG_SYSTEM);
sprintf(aszBuf, "WEAPON%d_SPAWNTIME", CHAINGUN_WEAPON);
AddGameVar(aszBuf, 0, GAMEVAR_FLAG_PERPLAYER | GAMEVAR_FLAG_SYSTEM);
sprintf(aszBuf, "WEAPON%d_SPAWN", CHAINGUN_WEAPON);
AddGameVar(aszBuf, DTILE_SHELL, GAMEVAR_FLAG_PERPLAYER | GAMEVAR_FLAG_SYSTEM);
AddGameVar(aszBuf, DukeShellClass->ActorInfo()->TypeNum, GAMEVAR_FLAG_PERPLAYER | GAMEVAR_FLAG_SYSTEM);
sprintf(aszBuf, "WEAPON%d_SHOTSPERBURST", CHAINGUN_WEAPON);
AddGameVar(aszBuf, 0, GAMEVAR_FLAG_PERPLAYER | GAMEVAR_FLAG_SYSTEM);
@ -830,7 +830,7 @@ void AddSystemVars()
AddGameVar(aszBuf, 0, GAMEVAR_FLAG_PERPLAYER | GAMEVAR_FLAG_SYSTEM);
sprintf(aszBuf, "WEAPON%d_SHOOTS", RPG_WEAPON);
AddGameVar(aszBuf, DTILE_RPG, GAMEVAR_FLAG_PERPLAYER | GAMEVAR_FLAG_SYSTEM);
AddGameVar(aszBuf, DukeRPGClass->ActorInfo()->TypeNum, GAMEVAR_FLAG_PERPLAYER | GAMEVAR_FLAG_SYSTEM);
sprintf(aszBuf, "WEAPON%d_SPAWNTIME", RPG_WEAPON);
AddGameVar(aszBuf, 0, GAMEVAR_FLAG_PERPLAYER | GAMEVAR_FLAG_SYSTEM);
@ -876,7 +876,7 @@ void AddSystemVars()
AddGameVar(aszBuf, WEAPON_FLAG_THROWIT, GAMEVAR_FLAG_PERPLAYER | GAMEVAR_FLAG_SYSTEM);
sprintf(aszBuf, "WEAPON%d_SHOOTS", HANDBOMB_WEAPON);
AddGameVar(aszBuf, DTILE_HEAVYHBOMB, GAMEVAR_FLAG_PERPLAYER | GAMEVAR_FLAG_SYSTEM);
AddGameVar(aszBuf, DukePipeBombClass->ActorInfo()->TypeNum, GAMEVAR_FLAG_PERPLAYER | GAMEVAR_FLAG_SYSTEM);
sprintf(aszBuf, "WEAPON%d_SPAWNTIME", HANDBOMB_WEAPON);
AddGameVar(aszBuf, 0, GAMEVAR_FLAG_PERPLAYER | GAMEVAR_FLAG_SYSTEM);
@ -924,7 +924,7 @@ void AddSystemVars()
AddGameVar(aszBuf, WEAPON_FLAG_GLOWS, GAMEVAR_FLAG_PERPLAYER | GAMEVAR_FLAG_SYSTEM);
sprintf(aszBuf, "WEAPON%d_SHOOTS", SHRINKER_WEAPON);
AddGameVar(aszBuf, DTILE_SHRINKER, GAMEVAR_FLAG_PERPLAYER | GAMEVAR_FLAG_SYSTEM);
AddGameVar(aszBuf, DukeShrinkerClass->ActorInfo()->TypeNum, GAMEVAR_FLAG_PERPLAYER | GAMEVAR_FLAG_SYSTEM);
sprintf(aszBuf, "WEAPON%d_SPAWNTIME", SHRINKER_WEAPON);
AddGameVar(aszBuf, 0, GAMEVAR_FLAG_PERPLAYER | GAMEVAR_FLAG_SYSTEM);
@ -970,7 +970,7 @@ void AddSystemVars()
AddGameVar(aszBuf, WEAPON_FLAG_FIREEVERYOTHER, GAMEVAR_FLAG_PERPLAYER | GAMEVAR_FLAG_SYSTEM);
sprintf(aszBuf, "WEAPON%d_SHOOTS", DEVISTATOR_WEAPON);
AddGameVar(aszBuf, DTILE_RPG, GAMEVAR_FLAG_PERPLAYER | GAMEVAR_FLAG_SYSTEM);
AddGameVar(aszBuf, DukeRPGClass->ActorInfo()->TypeNum, GAMEVAR_FLAG_PERPLAYER | GAMEVAR_FLAG_SYSTEM);
sprintf(aszBuf, "WEAPON%d_SPAWNTIME", DEVISTATOR_WEAPON);
AddGameVar(aszBuf, 0, GAMEVAR_FLAG_PERPLAYER | GAMEVAR_FLAG_SYSTEM);
@ -1016,7 +1016,7 @@ void AddSystemVars()
AddGameVar(aszBuf, WEAPON_FLAG_STANDSTILL, GAMEVAR_FLAG_PERPLAYER | GAMEVAR_FLAG_SYSTEM);
sprintf(aszBuf, "WEAPON%d_SHOOTS", TRIPBOMB_WEAPON);
AddGameVar(aszBuf, DTILE_HANDHOLDINGLASER0, GAMEVAR_FLAG_PERPLAYER | GAMEVAR_FLAG_SYSTEM);
AddGameVar(aszBuf, DukeHandHoldingLaserClass->ActorInfo()->TypeNum, GAMEVAR_FLAG_PERPLAYER | GAMEVAR_FLAG_SYSTEM);
sprintf(aszBuf, "WEAPON%d_SPAWNTIME", TRIPBOMB_WEAPON);
AddGameVar(aszBuf, 0, GAMEVAR_FLAG_PERPLAYER | GAMEVAR_FLAG_SYSTEM);
@ -1062,7 +1062,7 @@ void AddSystemVars()
AddGameVar(aszBuf, WEAPON_FLAG_FIREEVERYOTHER, GAMEVAR_FLAG_PERPLAYER | GAMEVAR_FLAG_SYSTEM);
sprintf(aszBuf, "WEAPON%d_SHOOTS", FREEZE_WEAPON);
AddGameVar(aszBuf, DTILE_FREEZEBLAST, GAMEVAR_FLAG_PERPLAYER | GAMEVAR_FLAG_SYSTEM);
AddGameVar(aszBuf, DukeFreezeBlastClass->ActorInfo()->TypeNum, GAMEVAR_FLAG_PERPLAYER | GAMEVAR_FLAG_SYSTEM);
sprintf(aszBuf, "WEAPON%d_SPAWNTIME", FREEZE_WEAPON);
AddGameVar(aszBuf, 0, GAMEVAR_FLAG_PERPLAYER | GAMEVAR_FLAG_SYSTEM);
@ -1157,7 +1157,7 @@ void AddSystemVars()
AddGameVar(aszBuf, WEAPON_FLAG_GLOWS, GAMEVAR_FLAG_PERPLAYER | GAMEVAR_FLAG_SYSTEM);
sprintf(aszBuf, "WEAPON%d_SHOOTS", GROW_WEAPON);
AddGameVar(aszBuf, DTILE_GROWSPARK, GAMEVAR_FLAG_PERPLAYER | GAMEVAR_FLAG_SYSTEM);
AddGameVar(aszBuf, DukeGrowSparkClass->ActorInfo()->TypeNum, GAMEVAR_FLAG_PERPLAYER | GAMEVAR_FLAG_SYSTEM);
sprintf(aszBuf, "WEAPON%d_SPAWNTIME", GROW_WEAPON);
AddGameVar(aszBuf, 0, GAMEVAR_FLAG_PERPLAYER | GAMEVAR_FLAG_SYSTEM);

View file

@ -282,7 +282,7 @@ inline void processinputvel(int snum)
inline const ActorInfo* DDukeActor::conInfo() const
{
auto tn = static_cast<PClassActor*>(GetClass())->ActorInfo()->TypeNum;
return tn < 0 ? nullptr : &gs.actorinfo[tn];
return tn < 0 || gs.actorinfo[tn].scriptaddress == 0 ? nullptr : &gs.actorinfo[tn];
}
inline bool DDukeActor::isPlayer() const