Skip to content

Commit

Permalink
use a class pointer to store the initial type of an actor.
Browse files Browse the repository at this point in the history
This decouples it from the type numbers.
  • Loading branch information
coelckers committed Oct 10, 2023
1 parent c400a20 commit 54858fc
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 35 deletions.
9 changes: 4 additions & 5 deletions source/games/blood/src/actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1647,7 +1647,7 @@ static int actDamageDude(DBloodActor* source, DBloodActor* actor, int damage, DA
{
if (!actor->IsDudeActor())
{
Printf(PRINT_HIGH, "Bad Dude Failed: initial=%d type=%d %s\n", (int)actor->spr.inittype, (int)actor->GetType(), (int)(actor->spr.flags & kHitagRespawn) ? "RESPAWN" : "NORMAL");
Printf(PRINT_HIGH, "Bad Dude Failed: initial=%s type=%d %s\n", actor->originalType->TypeName.GetChars(), (int)actor->GetType(), (int)(actor->spr.flags & kHitagRespawn) ? "RESPAWN" : "NORMAL");
return damage >> 4;
}

Expand Down Expand Up @@ -2970,13 +2970,13 @@ void MoveDude(DBloodActor* actor)
break;
case kDudeBurningCultist:
{
const bool fixRandomCultist = !cl_bloodvanillaenemies && (actor->spr.inittype >= kDudeBase) && (actor->spr.inittype < kDudeMax) && (actor->spr.inittype != actor->GetType()) && !VanillaMode(); // fix burning cultists randomly switching types underwater
const bool fixRandomCultist = !cl_bloodvanillaenemies && actor->WasDudeActor() && actor->originalType != actor->GetClass() && !VanillaMode(); // fix burning cultists randomly switching types underwater
if (Chance(chance))
actor->ChangeType(kDudeCultistTommy);
else
actor->ChangeType(kDudeCultistShotgun);
if (fixRandomCultist) // fix burning cultists randomly switching types underwater
actor->ChangeType(actor->spr.inittype); // restore back to spawned cultist type
actor->ChangeType(actor->originalType); // restore back to spawned cultist type
actor->xspr.burnTime = 0;
evPostActor(actor, 0, AF(EnemyBubble));
sfxPlay3DSound(actor, 720, -1, 0);
Expand Down Expand Up @@ -4136,8 +4136,7 @@ DBloodActor* actSpawnDude(DBloodActor* source, int nType, double dist)
{
pos.XY() += angle.ToVector() * dist;
}
if (!VanillaMode())
spawned->spr.inittype = nType;
spawned->originalType = cls;
spawned->spr.Angles.Yaw = angle;
SetActor(spawned, pos);

Expand Down
2 changes: 2 additions & 0 deletions source/games/blood/src/actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ DBloodActor* actSpawnThing(sectortype* pSector, const DVector3& pos, int nThingT
DBloodActor* actFireThing(DBloodActor* actor, double xyoff, double zoff, double zvel, int thingType, double nSpeed);
DBloodActor* actFireMissile(DBloodActor* actor, double xyoff, double zoff, DVector3 dc, int nType);

bool IsBurningDude(DBloodActor* pSprite);
void actBurnSprite(DBloodActor* pSource, DBloodActor* pTarget, int nTime);

bool isGrown(DBloodActor* pSprite);
bool isShrunk(DBloodActor* pSprite);
bool ceilIsTooLow(DBloodActor* actor);
Expand Down
6 changes: 3 additions & 3 deletions source/games/blood/src/ai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,7 @@ int aiDamageSprite(DBloodActor* source, DBloodActor* actor, DAMAGE_TYPE nDmgType
DUDEEXTRA* pDudeExtra = &actor->dudeExtra;
pDudeExtra->teslaHit = 0;
}
const bool fixRandomCultist = !cl_bloodvanillaenemies && (actor->spr.inittype >= kDudeBase) && (actor->spr.inittype < kDudeMax) && (actor->spr.inittype != actor->GetType()) && !VanillaMode(); // fix burning cultists randomly switching types underwater
const bool fixRandomCultist = !cl_bloodvanillaenemies && actor->WasDudeActor() && actor->originalType != actor->GetClass() && !VanillaMode(); // fix burning cultists randomly switching types underwater
switch (actor->GetType())
{
case kDudeCultistTommy:
Expand Down Expand Up @@ -1045,15 +1045,15 @@ int aiDamageSprite(DBloodActor* source, DBloodActor* actor, DAMAGE_TYPE nDmgType
{
actor->ChangeType(kDudeCultistTommy);
if (fixRandomCultist) // fix burning cultists randomly switching types underwater
actor->ChangeType(actor->spr.inittype); // restore back to spawned cultist type
actor->ChangeType(actor->originalType); // restore back to spawned cultist type
actor->xspr.burnTime = 0;
aiNewState(actor, NAME_cultistSwimGoto);
}
else if (actor->xspr.medium == kMediumWater || actor->xspr.medium == kMediumGoo)
{
actor->ChangeType(kDudeCultistShotgun);
if (fixRandomCultist) // fix burning cultists randomly switching types underwater
actor->ChangeType(actor->spr.inittype); // restore back to spawned cultist type
actor->ChangeType(actor->originalType); // restore back to spawned cultist type
actor->xspr.burnTime = 0;
aiNewState(actor, NAME_cultistSwimGoto);
}
Expand Down
4 changes: 2 additions & 2 deletions source/games/blood/src/aiunicult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1947,8 +1947,8 @@ void genDudeTransform(DBloodActor* actor)
// trigger dude death before transform
trTriggerSprite(actor, kCmdOff, actor);

actor->spr.inittype = actIncarnation->GetType();
actor->ChangeType(actor->spr.inittype);
actor->originalType = actIncarnation->GetClass();
actor->ChangeType(actor->originalType);
actor->spr.flags = actIncarnation->spr.flags;
actor->spr.pal = actIncarnation->spr.pal;
actor->spr.shade = actIncarnation->spr.shade;
Expand Down
6 changes: 6 additions & 0 deletions source/games/blood/src/bloodactor.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class DBloodActor : public DCoreActor
XSPRITE xspr;
SPRITEHIT hit;
DUDEEXTRA dudeExtra;
PClass* originalType; // what this originally started as.
TObjPtr<DBloodActor*> ownerActor; // was previously stored in the sprite's owner field.

// nnext stuff. For now not exported to scripting.
Expand Down Expand Up @@ -130,6 +131,11 @@ class DBloodActor : public DCoreActor
return IsKindOf(BloodDudeBaseClass);
}

bool WasDudeActor()
{
return originalType && originalType->IsDescendantOf(BloodDudeBaseClass);
}

bool IsThingActor()
{
return IsKindOf(BloodThingBaseClass);
Expand Down
2 changes: 1 addition & 1 deletion source/games/blood/src/callback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ void Respawn(DBloodActor* actor) // 9
assert(actor->spr.intowner != kStatRespawn);
assert(actor->spr.intowner >= 0 && actor->spr.intowner < kMaxStatus);
ChangeActorStat(actor, actor->spr.intowner);
actor->ChangeType(actor->spr.inittype);
actor->ChangeType(actor->originalType);
actor->SetOwner(nullptr);
actor->spr.flags &= ~kHitagRespawn;
actor->vel.Zero();
Expand Down
1 change: 1 addition & 0 deletions source/games/blood/src/loadsave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ void DBloodActor::Serialize(FSerializer& arc)
Super::Serialize(arc);
arc
("hasx", hasx)
("spawntype", originalType)
("basepoint", basePoint);

// The rest is only relevant if the actor has an xsprite.
Expand Down
2 changes: 1 addition & 1 deletion source/games/blood/src/nnexts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5658,7 +5658,7 @@ bool modernTypeOperateSprite(DBloodActor* actor, EVENT& event)
// dude to thing morphing causing a lot of problems since it continues receiving commands after dude is dead.
// this leads to weird stuff like exploding with gargoyle gib or corpse disappearing immediately.
// let's allow only specific commands here to avoid this.
if (actor->spr.inittype < kDudeBase || actor->spr.inittype >= kDudeMax) return false;
if (!actor->WasDudeActor()) return false;
else if (event.cmd != kCmdToggle && event.cmd != kCmdOff && event.cmd != kCmdSpriteImpact) return true;
DudeToGibCallback1(actor); // set proper gib type just in case DATAs was changed from the outside.
return false;
Expand Down
1 change: 0 additions & 1 deletion source/games/blood/src/nnexts.h
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,6 @@ void callbackMakeMissileBlocking(DBloodActor* actor);
void callbackGenDudeUpdate(DBloodActor* actor);
// ------------------------------------------------------------------------- //
DBloodPlayer* getPlayerById(int id);
bool IsBurningDude(DBloodActor* pSprite);
bool IsKillableDude(DBloodActor* pSprite);
bool isActive(DBloodActor* nSprite);
int getDataFieldOfObject(EventObject& eob, int dataIndex);
Expand Down
2 changes: 1 addition & 1 deletion source/games/blood/src/seq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ void seqProcess(int nTicks)
if (actor)
{
evKillActor(actor);
if ((actor->spr.hitag & kAttrRespawn) != 0 && (actor->spr.inittype >= kDudeBase && actor->spr.inittype < kDudeMax))
if ((actor->spr.hitag & kAttrRespawn) != 0 && actor->WasDudeActor())
evPostActor(actor, gGameOptions.nMonsterRespawnTime, AF(Respawn));
else DeleteSprite(actor); // safe to not use actPostSprite here
}
Expand Down
38 changes: 17 additions & 21 deletions source/games/blood/src/triggers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ bool SetSpriteState(DBloodActor* actor, int nState, DBloodActor* initiator)
actor->xspr.busy = IntToFixed(nState);
actor->xspr.state = nState;
evKillActor(actor, initiator);
if ((actor->spr.flags & kHitagRespawn) != 0 && actor->spr.inittype >= kDudeBase && actor->spr.inittype < kDudeMax)
if ((actor->spr.flags & kHitagRespawn) != 0 && actor->WasDudeActor())
{
actor->xspr.respawnPending = 3;
evPostActor(actor, gGameOptions.nMonsterRespawnTime, AF(Respawn));
Expand Down Expand Up @@ -480,26 +480,22 @@ void OperateSprite(DBloodActor* actor, EVENT event)

break;
case kMarkerDudeSpawn:
if (gGameOptions.nMonsterSettings && actor->xspr.data1 >= kDudeBase && actor->xspr.data1 < kDudeMax)
if (gGameOptions.nMonsterSettings)
{
auto spawned = actSpawnDude(actor, actor->xspr.data1, -1);
if (spawned) {
if (AllowedKillType(spawned)) Level.addKillCount();
switch (actor->xspr.data1) {
case kDudeBurningInnocent:
case kDudeBurningCultist:
case kDudeBurningZombieAxe:
case kDudeBurningZombieButcher:
case kDudeBurningTinyCaleb:
case kDudeBurningBeast: {
spawned->xspr.health = static_cast<DBloodActor*>(GetDefaultByType(GetSpawnType(actor->xspr.data1)))->startHealth() << 4;
spawned->xspr.burnTime = 10;
spawned->SetTarget(nullptr);
aiActivateDude(spawned);
break;
default:
break;
}
auto type = GetSpawnType(actor->xspr.data1);
if (type->IsDescendantOf(BloodDudeBaseClass))
{
auto spawned = actSpawnDude(actor, actor->xspr.data1, -1);
if (spawned)
{
if (AllowedKillType(spawned)) Level.addKillCount();
if (IsBurningDude(spawned))
{
spawned->xspr.health = static_cast<DBloodActor*>(GetDefaultByType(GetSpawnType(actor->xspr.data1)))->startHealth() << 4;
spawned->xspr.burnTime = 10;
spawned->SetTarget(nullptr);
aiActivateDude(spawned);
}
}
}
}
Expand Down Expand Up @@ -2279,7 +2275,7 @@ void trInit(TArray<DBloodActor*>& actors)
for (auto actor : actors)
{
if (!actor->exists()) continue;
actor->spr.inittype = actor->GetType();
actor->originalType = actor->GetClass();
actor->basePoint = actor->spr.pos;
}
for (auto& wal : wall)
Expand Down

0 comments on commit 54858fc

Please sign in to comment.