Skip to content

Commit

Permalink
spawn the actual classes assigned to the various actor types.
Browse files Browse the repository at this point in the history
  • Loading branch information
coelckers committed Sep 30, 2023
1 parent ab21d65 commit 3bbc3e5
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 33 deletions.
24 changes: 13 additions & 11 deletions source/games/blood/src/actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4693,7 +4693,7 @@ void MoveDude(DBloodActor* actor)
if (actor->IsPlayerActor()) pPlayer = getPlayer(actor);
if (!(actor->IsDudeActor()))
{
Printf(PRINT_HIGH, "%d: actor->IsDudeActor()", actor->GetType());
Printf(PRINT_HIGH, "%s is not a dude actor type\n", actor->GetClass()->TypeName);
return;
}

Expand Down Expand Up @@ -6129,12 +6129,12 @@ void actProcessSprites(void)
//
//---------------------------------------------------------------------------

DBloodActor* actSpawnSprite(sectortype* pSector, const DVector3& pos, int nStat, bool setextra)
DBloodActor* actSpawnSprite(sectortype* pSector, const DVector3& pos, int nStat, bool setextra, PClass* cls, int type)
{
DBloodActor* actor = InsertSprite(pSector, nStat);
DBloodActor* actor = InsertSprite(pSector, nStat, cls);
actor->spr.lotag = type; // we still need this.

SetActor(actor, pos);
actor->ChangeType(kSpriteDecoration);
if (setextra && !actor->hasX())
{
actor->addX();
Expand All @@ -6151,9 +6151,10 @@ DBloodActor* actSpawnSprite(sectortype* pSector, const DVector3& pos, int nStat,
//
//---------------------------------------------------------------------------

DBloodActor* actSpawnSprite(DBloodActor* source, int nStat)
DBloodActor* actSpawnSprite(DBloodActor* source, int nStat, PClass* cls, int type)
{
DBloodActor* actor = InsertSprite(source->sector(), nStat);
DBloodActor* actor = InsertSprite(source->sector(), nStat, cls);
actor->spr.lotag = type; // we still need this.

actor->spr.pos = source->spr.pos;
actor->vel = source->vel;
Expand All @@ -6173,7 +6174,8 @@ DBloodActor* actSpawnSprite(DBloodActor* source, int nStat)

DBloodActor* actSpawnDude(DBloodActor* source, int nType, double dist)
{
auto spawned = actSpawnSprite(source, kStatDude);
auto cls = GetSpawnType(nType);
auto spawned = actSpawnSprite(source, kStatDude, cls, nType);
if (!spawned) return nullptr;
DAngle angle = source->spr.Angles.Yaw;
int nDude = nType - kDudeBase;
Expand All @@ -6184,7 +6186,6 @@ DBloodActor* actSpawnDude(DBloodActor* source, int nType, double dist)
{
pos.XY() += angle.ToVector() * dist;
}
spawned->ChangeType(nType);
if (!VanillaMode())
spawned->spr.inittype = nType;
spawned->spr.Angles.Yaw = angle;
Expand Down Expand Up @@ -6242,7 +6243,8 @@ DBloodActor* actSpawnDude(DBloodActor* source, int nType, double dist)
DBloodActor* actSpawnThing(sectortype* pSector, const DVector3& pos, int nThingType)
{
assert(nThingType >= kThingBase && nThingType < kThingMax);
auto actor = actSpawnSprite(pSector, pos, 4, 1);
auto cls = GetSpawnType(nThingType);
auto actor = actSpawnSprite(pSector, pos, 4, 1, cls, nThingType);
int nType = nThingType - kThingBase;
actor->ChangeType(nThingType);
assert(actor->hasX());
Expand Down Expand Up @@ -6459,10 +6461,10 @@ DBloodActor* actFireMissile(DBloodActor* actor, double xyoff, double zoff, DVect
vect.XY() = gHitInfo.hitpos.XY() - actor->spr.Angles.Yaw.ToVector() * pMissileInfo->fClipDist() * 2;
}
}
auto spawned = actSpawnSprite(actor->sector(), vect, 5, 1);
auto cls = GetSpawnType(nType);
auto spawned = actSpawnSprite(actor->sector(), vect, 5, 1, cls, nType);

spawned->spr.cstat2 |= CSTAT2_SPRITE_MAPPED;
spawned->ChangeType(nType);
spawned->spr.shade = pMissileInfo->shade;
spawned->spr.pal = 0;
spawned->clipdist = pMissileInfo->fClipDist();
Expand Down
4 changes: 2 additions & 2 deletions source/games/blood/src/actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,9 @@ void actAirDrag(DBloodActor *pSprite, fixed_t drag);
void actExplodeSprite(DBloodActor *pSprite);
void actActivateGibObject(DBloodActor *actor);
void actProcessSprites(void);
DBloodActor* actSpawnSprite(sectortype* pSector, const DVector3& pos, int nStat, bool a6);
DBloodActor* actSpawnSprite(sectortype* pSector, const DVector3& pos, int nStat, bool setextra, PClass* cls = nullptr, int type = 0);
DBloodActor* actSpawnDude(DBloodActor* pSource, int nType, double dist);
DBloodActor * actSpawnSprite(DBloodActor *pSource, int nStat);
DBloodActor * actSpawnSprite(DBloodActor *pSource, int nStat, PClass* cls = nullptr, int type = 0);
DBloodActor* actSpawnThing(sectortype* pSector, const DVector3& pos, int nThingType);

DBloodActor* actFireThing(DBloodActor* actor, double xyoff, double zoff, double zvel, int thingType, double nSpeed);
Expand Down
15 changes: 7 additions & 8 deletions source/games/blood/src/aiunicult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1809,9 +1809,8 @@ void dudeLeechOperate(DBloodActor* actor, const EVENT& event)

bool doExplosion(DBloodActor* actor, int nType)
{
auto actExplosion = actSpawnSprite(actor->sector(), actor->spr.pos, kStatExplosion, true);
if (!actExplosion->hasX())
return false;
auto cls = GetSpawnType(nType);
auto actExplosion = actSpawnSprite(actor->sector(), actor->spr.pos, kStatExplosion, true, cls, nType);

int nSeq = 4; int nSnd = 304; const EXPLOSION* pExpl = &explodeInfo[nType];

Expand Down Expand Up @@ -1848,20 +1847,20 @@ bool doExplosion(DBloodActor* actor, int nType)

DBloodActor* genDudeSpawn(DBloodActor* source, DBloodActor* actor, double nDist)
{
auto spawned = actSpawnSprite(actor, kStatDude);
int nType = kDudeModernCustom;
auto cls = GetSpawnType(kDudeModernCustom);
auto spawned = actSpawnSprite(actor, kStatDude, cls, kDudeModernCustom);

auto pos = actor->spr.pos;
if (nDist > 0)
{
pos.XY() += actor->spr.Angles.Yaw.ToVector() * nDist;
}

spawned->ChangeType(nType);
spawned->spr.Angles.Yaw = actor->spr.Angles.Yaw;
SetActor(spawned, pos);
spawned->spr.cstat |= CSTAT_SPRITE_BLOCK_ALL | CSTAT_SPRITE_BLOOD_BIT1;
spawned->clipdist = dudeInfo[nType - kDudeBase].fClipdist();
auto pDudeInfo = getDudeInfo(spawned);
spawned->clipdist = pDudeInfo->fClipdist();

// inherit weapon, seq and sound settings.
spawned->xspr.data1 = source->xspr.data1;
Expand All @@ -1880,7 +1879,7 @@ DBloodActor* genDudeSpawn(DBloodActor* source, DBloodActor* actor, double nDist)
spawned->copy_clipdist(source);

// inherit custom hp settings
if (source->xspr.data4 <= 0) spawned->xspr.health = dudeInfo[nType - kDudeBase].startHealth << 4;
if (source->xspr.data4 <= 0) spawned->xspr.health = pDudeInfo->startHealth << 4;
else spawned->xspr.health = ClipRange(source->xspr.data4 << 4, 1, 65535);


Expand Down
2 changes: 1 addition & 1 deletion source/games/blood/src/blood.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ TArray<DBloodActor*> SpawnActors(BloodSpawnSpriteDef& sprites)
continue;
}
auto sprt = &sprites.sprites[i];
auto actor = InsertSprite(sprt->sectp, sprt->statnum);
auto actor = InsertSprite(sprt->sectp, sprt->statnum, GetSpawnType(sprt->lotag));
spawns[j++] = actor;
actor->time = i;
actor->initFromSprite(&sprites.sprites[i]);
Expand Down
4 changes: 3 additions & 1 deletion source/games/blood/src/bloodactor.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "coreactor.h"
#include "g_mapinfo.h"

BEGIN_BLD_NS

Expand Down Expand Up @@ -148,13 +149,14 @@ class DBloodActor : public DCoreActor
// It sucks having to do this but the game heavily depends on being able to swap out the class type and often uses this to manage actor state.
// We'll allow this only for classes that do not add their own data, though.
SetClass(newtype);
//spr.setspritetexture(GetDefaultByType(newtype)->spr.spritetexture());
}
}

// this is only temporary
void ChangeType(int newtype)
{
auto cls = GetSpawnType(newtype);
if (cls != nullptr) ChangeType(cls);
spr.lotag = newtype;
}

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 @@ -91,7 +91,7 @@ void FlareBurst(DBloodActor* actor, sectortype*) // 2
double nRadius = FixedToFloat(0x55555);
for (int i = 0; i < 8; i++)
{
auto spawnedactor = actSpawnSprite(actor, 5);
auto spawnedactor = actSpawnSprite(actor, kStatProjectile);
spawnedactor->spr.setspritetexture(aTexIds[kTexFLAREBURST]);
spawnedactor->spr.shade = -128;
spawnedactor->spr.scale = DVector2(0.5, 0.5);
Expand Down
5 changes: 3 additions & 2 deletions source/games/blood/src/db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ int gSkyCount;
//
//---------------------------------------------------------------------------

DBloodActor* InsertSprite(sectortype* pSector, int nStat)
DBloodActor* InsertSprite(sectortype* pSector, int nStat, PClass* cls)
{
auto act = static_cast<DBloodActor*>(::InsertActor(RUNTIME_CLASS(DBloodActor), pSector, nStat));
if (cls == nullptr) cls = RUNTIME_CLASS(DBloodActor);
auto act = static_cast<DBloodActor*>(::InsertActor(cls, pSector, nStat));
act->spr.cstat = CSTAT_SPRITE_YCENTER;
act->clipdist = 8;
act->spr.scale = DVector2(1, 1);
Expand Down
2 changes: 1 addition & 1 deletion source/games/blood/src/db.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ struct BloodSpawnSpriteDef : public SpawnSpriteDef
TArray<XSPRITE> xspr;
};

DBloodActor* InsertSprite(sectortype* pSector, int nStat);
DBloodActor* InsertSprite(sectortype* pSector, int nStat, PClass* cls = nullptr);
int DeleteSprite(DBloodActor* actor);

unsigned int dbReadMapCRC(const char* pPath);
Expand Down
3 changes: 2 additions & 1 deletion source/games/blood/src/fx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ DBloodActor* CFX::fxSpawnActor(FX_ID nFx, sectortype* pSector, const DVector3& p
return nullptr;
FXDATA* pFX = &gFXData[nFx];

auto actor = actSpawnSprite(pSector, pos, 1, 0);
auto cls = GetSpawnType(fxType(nFx));
auto actor = actSpawnSprite(pSector, pos, kStatFX, 0, cls, fxType(nFx));

actor->ChangeType(fxType(nFx));
actor->spr.setspritetexture(pFX->textureID());
Expand Down
9 changes: 6 additions & 3 deletions source/games/blood/src/nnexts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,13 @@ static DBloodActor* nnExtSpawnDude(DBloodActor* sourceactor, DBloodActor* origin
{
DBloodActor* pDudeActor = nullptr;

if (nType < kDudeBase || nType >= kDudeMax || (pDudeActor = actSpawnSprite(origin, kStatDude)) == NULL)
if (nType < kDudeBase || nType >= kDudeMax)
return NULL;

auto cls = GetSpawnType(nType);
pDudeActor = actSpawnSprite(origin, kStatDude, cls, nType);
if (!pDudeActor) return nullptr;

DAngle angle = origin->spr.Angles.Yaw;
auto pos = origin->spr.pos.plusZ(zadd);

Expand Down Expand Up @@ -9173,10 +9177,9 @@ void callbackUniMissileBurst(DBloodActor* actor, sectortype*) // 22

for (int i = 0; i < 8; i++)
{
auto burstactor = actSpawnSprite(actor, 5);
auto burstactor = actSpawnSprite(actor, kStatProjectile, actor->GetClass(), actor->GetType());
if (!burstactor) break;

burstactor->ChangeType(actor->GetType());
burstactor->spr.shade = actor->spr.shade;
burstactor->spr.setspritetexture(actor->spr.spritetexture());

Expand Down
5 changes: 3 additions & 2 deletions source/games/blood/src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -798,10 +798,12 @@ void playerStart(int nPlayer, int bNewLevel)
pStartZone = &gStartZone[Random(8)];
}

auto actor = actSpawnSprite(pStartZone->sector, pStartZone->pos, 6, 1);
auto cls = GetSpawnType(kDudePlayer1 + nPlayer);
auto actor = actSpawnSprite(pStartZone->sector, pStartZone->pos, kStatDude, 1, cls, kDudePlayer1 + nPlayer);
assert(actor->hasX());
pPlayer->actor = actor;
pPlayer->Angles.initialize(pPlayer->actor);

DUDEINFO* pDudeInfo = &dudeInfo[kDudePlayer1 + nPlayer - kDudeBase];
pPlayer->pDudeInfo = pDudeInfo;
playerSetRace(pPlayer, kModeHuman);
Expand All @@ -814,7 +816,6 @@ void playerStart(int nPlayer, int bNewLevel)
actor->spr.pos.Z -= bottom - actor->spr.pos.Z;
actor->spr.pal = 11 + (pPlayer->teamId & 3);
actor->spr.Angles.Yaw = pStartZone->angle;
actor->ChangeType(kDudePlayer1 + nPlayer);
actor->clipdist = pDudeInfo->fClipdist();
actor->spr.flags = 15;
actor->xspr.burnTime = 0;
Expand Down

0 comments on commit 3bbc3e5

Please sign in to comment.