- Bullets and bobs.

This commit is contained in:
Christoph Oelckers 2021-11-22 23:40:53 +01:00
parent b191bca49e
commit 7713723045
5 changed files with 67 additions and 71 deletions

View file

@ -67,7 +67,7 @@ struct bulletInfo
extern bulletInfo BulletInfo[]; extern bulletInfo BulletInfo[];
extern int nRadialBullet; extern int nRadialBullet;
extern int lasthitsect; extern sectortype* lasthitsect;
extern int lasthitz; extern int lasthitz;
extern int lasthitx; extern int lasthitx;
extern int lasthity; extern int lasthity;
@ -285,11 +285,11 @@ void FuncObject(int, int, int, int);
void FuncTrap(int, int, int, int); void FuncTrap(int, int, int, int);
void FuncEnergyBlock(int, int, int, int); void FuncEnergyBlock(int, int, int, int);
void FuncSpark(int, int, int, int); void FuncSpark(int, int, int, int);
void SnapBobs(int nSectorA, int nSectorB); void SnapBobs(sectortype* nSectorA, sectortype* nSectorB);
DExhumedActor* FindWallSprites(int nSector); DExhumedActor* FindWallSprites(int nSector);
void AddMovingSector(int nSector, int edx, int ebx, int ecx); void AddMovingSector(int nSector, int edx, int ebx, int ecx);
void ProcessTrailSprite(DExhumedActor* nSprite, int nLotag, int nHitag); void ProcessTrailSprite(DExhumedActor* nSprite, int nLotag, int nHitag);
void AddSectorBob(int nSector, int nHitag, int bx); void AddSectorBob(sectortype* nSector, int nHitag, int bx);
DExhumedActor* BuildObject(DExhumedActor* nSprite, int nOjectType, int nHitag); DExhumedActor* BuildObject(DExhumedActor* nSprite, int nOjectType, int nHitag);
int BuildArrow(DExhumedActor* nSprite, int nVal); int BuildArrow(DExhumedActor* nSprite, int nVal);
int BuildFireBall(DExhumedActor*, int a, int b); int BuildFireBall(DExhumedActor*, int a, int b);

View file

@ -54,7 +54,7 @@ struct Bullet
FreeListArray<Bullet, kMaxBullets> BulletList; FreeListArray<Bullet, kMaxBullets> BulletList;
int lasthitz, lasthitx, lasthity; int lasthitz, lasthitx, lasthity;
int lasthitsect; sectortype* lasthitsect;
int nRadialBullet = 0; int nRadialBullet = 0;
@ -172,10 +172,9 @@ void IgniteSprite(DExhumedActor* pActor)
} }
} }
void BulletHitsSprite(Bullet *pBullet, DExhumedActor* pBulletActor, DExhumedActor* pHitActor, int x, int y, int z, int nSector) void BulletHitsSprite(Bullet *pBullet, DExhumedActor* pBulletActor, DExhumedActor* pHitActor, int x, int y, int z, sectortype* pSector)
{ {
assert(validSectorIndex(nSector)); assert(pSector != nullptr);
auto pSector = &sector[nSector];
bulletInfo *pBulletInfo = &BulletInfo[pBullet->nType]; bulletInfo *pBulletInfo = &BulletInfo[pBullet->nType];
@ -300,9 +299,9 @@ void BackUpBullet(int *x, int *y, int nAngle)
int MoveBullet(int nBullet) int MoveBullet(int nBullet)
{ {
int hitsect = -1;
int hitwall = -1;
DExhumedActor* hitactor = nullptr; DExhumedActor* hitactor = nullptr;
sectortype* pHitSect = nullptr;
walltype* pHitWall = nullptr;
Bullet *pBullet = &BulletList[nBullet]; Bullet *pBullet = &BulletList[nBullet];
int nType = pBullet->nType; int nType = pBullet->nType;
@ -373,7 +372,7 @@ MOVEEND:
x2 = pSprite->x; x2 = pSprite->x;
y2 = pSprite->y; y2 = pSprite->y;
z2 = pSprite->z; z2 = pSprite->z;
hitsect = pSprite->sectnum; pHitSect = pSprite->sector();
#if 0 #if 0
// Original code. This was producing some beautiful undefined behavior in the first case because the index can be anything, not just a wall. // Original code. This was producing some beautiful undefined behavior in the first case because the index can be anything, not just a wall.
@ -398,7 +397,7 @@ MOVEEND:
switch (coll.type) switch (coll.type)
{ {
case kHitWall: case kHitWall:
hitwall = coll.index; pHitWall = coll.wall();
goto HITWALL; goto HITWALL;
case 0xc000: case 0xc000:
if (!coll.exbits) if (!coll.exbits)
@ -440,7 +439,7 @@ MOVEEND:
x2 = hitsprite->x; x2 = hitsprite->x;
y2 = hitsprite->y; y2 = hitsprite->y;
z2 = hitsprite->z - (GetActorHeight(hitactor) >> 1); z2 = hitsprite->z - (GetActorHeight(hitactor) >> 1);
hitsect = hitsprite->sectnum; pHitSect = hitsprite->sector();
} }
else else
{ {
@ -456,14 +455,14 @@ MOVEEND:
y2 = hitData.pos.y; y2 = hitData.pos.y;
z2 = hitData.pos.z; z2 = hitData.pos.z;
hitactor = GetActor(hitData); hitactor = GetActor(hitData);
hitsect = hitData.sect; pHitSect = hitData.sect >= 0? &sector[hitData.sect] : nullptr;
hitwall = hitData.wall; pHitWall = hitData.wall >= 0? &wall[hitData.wall] : nullptr;
} }
lasthitx = x2; lasthitx = x2;
lasthity = y2; lasthity = y2;
lasthitz = z2; lasthitz = z2;
lasthitsect = hitsect; lasthitsect = pHitSect;
if (hitactor) if (hitactor)
{ {
@ -480,31 +479,29 @@ HITSPRITE:
} }
else else
{ {
BulletHitsSprite(pBullet, pActor->pTarget, hitactor, x2, y2, z2, hitsect); BulletHitsSprite(pBullet, pActor->pTarget, hitactor, x2, y2, z2, pHitSect);
} }
} }
else if (hitwall > -1) else if (pHitWall != nullptr)
{ {
HITWALL: HITWALL:
auto pWall = &wall[hitwall]; if (pHitWall->picnum == kEnergy1)
if (pWall->picnum == kEnergy1)
{ {
if (pWall->twoSided()) if (pHitWall->twoSided())
{ {
int nDamage = BulletInfo[pBullet->nType].nDamage; int nDamage = BulletInfo[pBullet->nType].nDamage;
if (pBullet->nDoubleDamage > 1) { if (pBullet->nDoubleDamage > 1) {
nDamage *= 2; nDamage *= 2;
} }
runlist_DamageEnemy(EnergyBlocks[pWall->nextSector()->extra], pActor, nDamage); runlist_DamageEnemy(EnergyBlocks[pHitWall->nextSector()->extra], pActor, nDamage);
} }
} }
} }
if (hitsect > -1) // NOTE: hitsect can be -1. this check wasn't in original code. TODO: demo compatiblity? if (pHitSect != nullptr) // NOTE: hitsect can be -1. this check wasn't in original code. TODO: demo compatiblity?
{ {
auto pHitSect = &sector[hitsect]; if (hitactor == nullptr && pHitWall == nullptr)
if (hitactor == nullptr && hitwall < 0)
{ {
if ((pHitSect->pBelow != nullptr && (pHitSect->pBelow->Flag & kSectUnderwater)) || pHitSect->Depth) if ((pHitSect->pBelow != nullptr && (pHitSect->pBelow->Flag & kSectUnderwater)) || pHitSect->Depth)
{ {
@ -520,7 +517,7 @@ HITSPRITE:
} }
else else
{ {
if (hitwall >= 0) if (pHitWall != nullptr)
{ {
BackUpBullet(&x2, &y2, pSprite->ang); BackUpBullet(&x2, &y2, pSprite->ang);
@ -542,7 +539,7 @@ HITSPRITE:
pSprite->y = y2; pSprite->y = y2;
pSprite->z = z2; pSprite->z = z2;
ChangeActorSect(pActor, hitsect); ChangeActorSect(pActor, pHitSect);
} }
if (BulletInfo[nType].nRadius) if (BulletInfo[nType].nRadius)
@ -596,7 +593,7 @@ DExhumedActor* BuildBullet(DExhumedActor* pActor, int nType, int nZOffset, int n
assert(pTargetSprite->sector()); assert(pTargetSprite->sector());
BulletHitsSprite(&sBullet, pActor, pTarget, pTargetSprite->x, pTargetSprite->y, pTargetSprite->z - (nHeight >> 1), pTargetSprite->sectnum); BulletHitsSprite(&sBullet, pActor, pTarget, pTargetSprite->x, pTargetSprite->y, pTargetSprite->z - (nHeight >> 1), pTargetSprite->sector());
DeleteActor(sBullet.pActor); DeleteActor(sBullet.pActor);
return nullptr; return nullptr;
} }

View file

@ -85,7 +85,7 @@ enum ECounter
}; };
extern int Counters[kNumCounters]; extern int Counters[kNumCounters];
void SnapSectors(int nSectorA, int nSectorB, int b); void SnapSectors(sectortype* nSectorA, sectortype* nSectorB, int b);
void LoadObjects(); void LoadObjects();

View file

@ -194,9 +194,9 @@ void InitNewGame()
} }
} }
void SnapSectors(int nSectorA, int nSectorB, int b) void SnapSectors(sectortype* pSectorA, sectortype* pSectorB, int b)
{ {
for(auto& wal1 : wallsofsector(nSectorA)) for(auto& wal1 : wallsofsector(pSectorA))
{ {
int bestx = 0x7FFFFFF; int bestx = 0x7FFFFFF;
int besty = bestx; int besty = bestx;
@ -206,7 +206,7 @@ void SnapSectors(int nSectorA, int nSectorB, int b)
walltype* bestwall = nullptr; walltype* bestwall = nullptr;
for(auto& wal2 : wallsofsector(nSectorB)) for(auto& wal2 : wallsofsector(pSectorB))
{ {
int thisx = x - wal2.x; int thisx = x - wal2.x;
int thisy = y - wal2.y; int thisy = y - wal2.y;
@ -225,11 +225,11 @@ void SnapSectors(int nSectorA, int nSectorB, int b)
} }
if (b) { if (b) {
sector[nSectorB].ceilingz = sector[nSectorA].floorz; pSectorB->ceilingz = pSectorA->floorz;
} }
if (sector[nSectorA].Flag & 0x1000) { if (pSectorA->Flag & 0x1000) {
SnapBobs(nSectorA, nSectorB); SnapBobs(pSectorA, pSectorB);
} }
} }
@ -556,14 +556,14 @@ void ProcessSpriteTag(DExhumedActor* pActor, int nLotag, int nHitag)
{ {
auto pSector = pSprite->sector(); auto pSector = pSprite->sector();
pSector->pBelow = &sector[nHitag]; pSector->pBelow = &sector[nHitag];
SnapSectors(sectnum(pSector), nHitag, 1); SnapSectors(pSector, pSector->pBelow, 1);
DeleteActor(pActor); DeleteActor(pActor);
return; return;
} }
case 97: case 97:
{ {
AddSectorBob(pSprite->sectnum, nHitag, 1); AddSectorBob(pSprite->sector(), nHitag, 1);
DeleteActor(pActor); DeleteActor(pActor);
return; return;
@ -585,7 +585,7 @@ void ProcessSpriteTag(DExhumedActor* pActor, int nLotag, int nHitag)
} }
case 95: case 95:
{ {
AddSectorBob(pSprite->sectnum, nHitag, 0); AddSectorBob(pSprite->sector(), nHitag, 0);
DeleteActor(pActor); DeleteActor(pActor);
return; return;

View file

@ -58,7 +58,7 @@ struct TrailPoint
struct Bob struct Bob
{ {
int nSector; sectortype* pSector;
int z; int z;
uint8_t nPhase; uint8_t nPhase;
uint8_t field_3; uint8_t field_3;
@ -204,7 +204,7 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, Bob& w, Bob* def)
{ {
if (arc.BeginObject(keyname)) if (arc.BeginObject(keyname))
{ {
arc("sector", w.nSector) arc("sector", w.pSector)
("at2", w.nPhase) ("at2", w.nPhase)
("at3", w.field_3) ("at3", w.field_3)
("z", w.z) ("z", w.z)
@ -626,13 +626,13 @@ int CheckSectorSprites(int nSector, int nVal)
} }
// done // done
void MoveSectorSprites(int nSector, int z) void MoveSectorSprites(sectortype* pSector, int z)
{ {
int newz = sector[nSector].floorz; int newz = pSector->floorz;
int oldz = newz - z; int oldz = newz - z;
int minz = min(newz, oldz); int minz = min(newz, oldz);
int maxz = max(newz, oldz); int maxz = max(newz, oldz);
ExhumedSectIterator it(nSector); ExhumedSectIterator it(pSector);
while (auto pActor = it.Next()) while (auto pActor = it.Next())
{ {
auto pSprite = &pActor->s(); auto pSprite = &pActor->s();
@ -786,7 +786,7 @@ void AIElev::Tick(RunListEvent* ev)
else else
{ {
assert(nSector == nSectorB); assert(nSector == nSectorB);
MoveSectorSprites(nSector, nVal); MoveSectorSprites(&sector[nSector], nVal);
if (nVal < 0 && CheckSectorSprites(nSector, 2)) if (nVal < 0 && CheckSectorSprites(nSector, 2))
{ {
@ -2147,46 +2147,45 @@ void DoDrips()
sBob[i].nPhase += 4; sBob[i].nPhase += 4;
int edx = bsin(sBob[i].nPhase << 3, -4); int edx = bsin(sBob[i].nPhase << 3, -4);
int nSector =sBob[i].nSector; auto pSector =sBob[i].pSector;
if (sBob[i].field_3) if (sBob[i].field_3)
{ {
sector[nSector].ceilingz = edx + sBob[i].z; pSector->ceilingz = edx + sBob[i].z;
} }
else else
{ {
int nFloorZ = sector[nSector].floorz; int nFloorZ = pSector->floorz;
sector[nSector].floorz = edx + sBob[i].z; pSector->floorz = edx + sBob[i].z;
MoveSectorSprites(nSector, sector[nSector].floorz - nFloorZ); MoveSectorSprites(pSector, pSector->floorz - nFloorZ);
} }
} }
} }
void SnapBobs(int nSectorA, int nSectorB) void SnapBobs(sectortype* pSectorA, sectortype* pSectorB)
{ {
int ecx = -1; int select1 = -1;
int ebx = ecx; int select2 = select1;
// int var_14 = nSector; int esi;
// int edi = edx;
for (unsigned i = 0; i < sBob.Size(); i++) for (unsigned i = 0; i < sBob.Size(); i++)
{ {
int esi = sBob[i].nSector; auto pSector = sBob[i].pSector;
if (esi != nSectorA) if (pSector != pSectorA)
{ {
if (nSectorB != esi) if (pSectorB != pSector)
continue; continue;
esi = ebx; esi = select2;
ecx = i; select1 = i;
} }
else else
{ {
esi = ecx; esi = select1;
ebx = i; select2 = i;
} }
if (esi != -1) { if (esi != -1) {
@ -2194,18 +2193,18 @@ void SnapBobs(int nSectorA, int nSectorB)
} }
} }
if (ecx <= -1) { if (select1 <= -1) {
return; return;
} }
if (ebx <= -1) { if (select2 <= -1) {
return; return;
} }
sBob[ecx].nPhase = sBob[ebx].nPhase; sBob[select1].nPhase = sBob[select2].nPhase;
} }
void AddSectorBob(int nSector, int nHitag, int bx) void AddSectorBob(sectortype* pSector, int nHitag, int bx)
{ {
auto nBobs = sBob.Reserve(1); auto nBobs = sBob.Reserve(1);
sBob[nBobs].field_3 = bx; sBob[nBobs].field_3 = bx;
@ -2213,20 +2212,20 @@ void AddSectorBob(int nSector, int nHitag, int bx)
int z; int z;
if (bx == 0) { if (bx == 0) {
z = sector[nSector].floorz; z = pSector->floorz;
} }
else { else {
z = sector[nSector].ceilingz; z = pSector->ceilingz;
} }
sBob[nBobs].z = z; sBob[nBobs].z = z;
sBob[nBobs].nPhase = nHitag << 4; sBob[nBobs].nPhase = nHitag << 4;
sBob[nBobs].sBobID = nHitag; sBob[nBobs].sBobID = nHitag;
sBob[nBobs].nSector = nSector; sBob[nBobs].pSector = pSector;
StartInterpolation(nSector, bx == 0 ? Interp_Sect_Floorz : Interp_Sect_Ceilingz); StartInterpolation(pSector, bx == 0 ? Interp_Sect_Floorz : Interp_Sect_Ceilingz);
sector[nSector].Flag |= 0x0010; pSector->Flag |= 0x0010;
} }
int FindTrail(int nVal) int FindTrail(int nVal)
@ -2498,7 +2497,7 @@ void PostProcess()
{ {
sMoveSect[j].pCurSector = sMoveSect[i].pSector; sMoveSect[j].pCurSector = sMoveSect[i].pSector;
SnapSectors(sectnum(sMoveSect[j].pSector), sectnum(sMoveSect[i].pSector), 0); SnapSectors(sMoveSect[j].pSector, sMoveSect[i].pSector, 0);
sMoveSect[i].pSector = nullptr; sMoveSect[i].pSector = nullptr;
} }
} }
@ -2516,7 +2515,7 @@ void PostProcess()
if (j != i) if (j != i)
{ {
if (sBob[i].field_3 != 0 && sBob[j].sBobID == bobID) { if (sBob[i].field_3 != 0 && sBob[j].sBobID == bobID) {
SnapSectors(i, j, 0); SnapSectors(sBob[i].pSector, sBob[j].pSector, 0);
} }
} }
} }