- 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 int nRadialBullet;
extern int lasthitsect;
extern sectortype* lasthitsect;
extern int lasthitz;
extern int lasthitx;
extern int lasthity;
@ -285,11 +285,11 @@ void FuncObject(int, int, int, int);
void FuncTrap(int, int, int, int);
void FuncEnergyBlock(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);
void AddMovingSector(int nSector, int edx, int ebx, int ecx);
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);
int BuildArrow(DExhumedActor* nSprite, int nVal);
int BuildFireBall(DExhumedActor*, int a, int b);

View file

@ -54,7 +54,7 @@ struct Bullet
FreeListArray<Bullet, kMaxBullets> BulletList;
int lasthitz, lasthitx, lasthity;
int lasthitsect;
sectortype* lasthitsect;
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));
auto pSector = &sector[nSector];
assert(pSector != nullptr);
bulletInfo *pBulletInfo = &BulletInfo[pBullet->nType];
@ -300,9 +299,9 @@ void BackUpBullet(int *x, int *y, int nAngle)
int MoveBullet(int nBullet)
{
int hitsect = -1;
int hitwall = -1;
DExhumedActor* hitactor = nullptr;
sectortype* pHitSect = nullptr;
walltype* pHitWall = nullptr;
Bullet *pBullet = &BulletList[nBullet];
int nType = pBullet->nType;
@ -373,7 +372,7 @@ MOVEEND:
x2 = pSprite->x;
y2 = pSprite->y;
z2 = pSprite->z;
hitsect = pSprite->sectnum;
pHitSect = pSprite->sector();
#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.
@ -398,7 +397,7 @@ MOVEEND:
switch (coll.type)
{
case kHitWall:
hitwall = coll.index;
pHitWall = coll.wall();
goto HITWALL;
case 0xc000:
if (!coll.exbits)
@ -440,7 +439,7 @@ MOVEEND:
x2 = hitsprite->x;
y2 = hitsprite->y;
z2 = hitsprite->z - (GetActorHeight(hitactor) >> 1);
hitsect = hitsprite->sectnum;
pHitSect = hitsprite->sector();
}
else
{
@ -456,14 +455,14 @@ MOVEEND:
y2 = hitData.pos.y;
z2 = hitData.pos.z;
hitactor = GetActor(hitData);
hitsect = hitData.sect;
hitwall = hitData.wall;
pHitSect = hitData.sect >= 0? &sector[hitData.sect] : nullptr;
pHitWall = hitData.wall >= 0? &wall[hitData.wall] : nullptr;
}
lasthitx = x2;
lasthity = y2;
lasthitz = z2;
lasthitsect = hitsect;
lasthitsect = pHitSect;
if (hitactor)
{
@ -480,31 +479,29 @@ HITSPRITE:
}
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:
auto pWall = &wall[hitwall];
if (pWall->picnum == kEnergy1)
if (pHitWall->picnum == kEnergy1)
{
if (pWall->twoSided())
if (pHitWall->twoSided())
{
int nDamage = BulletInfo[pBullet->nType].nDamage;
if (pBullet->nDoubleDamage > 1) {
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 && hitwall < 0)
if (hitactor == nullptr && pHitWall == nullptr)
{
if ((pHitSect->pBelow != nullptr && (pHitSect->pBelow->Flag & kSectUnderwater)) || pHitSect->Depth)
{
@ -520,7 +517,7 @@ HITSPRITE:
}
else
{
if (hitwall >= 0)
if (pHitWall != nullptr)
{
BackUpBullet(&x2, &y2, pSprite->ang);
@ -542,7 +539,7 @@ HITSPRITE:
pSprite->y = y2;
pSprite->z = z2;
ChangeActorSect(pActor, hitsect);
ChangeActorSect(pActor, pHitSect);
}
if (BulletInfo[nType].nRadius)
@ -596,7 +593,7 @@ DExhumedActor* BuildBullet(DExhumedActor* pActor, int nType, int nZOffset, int n
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);
return nullptr;
}

View file

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

View file

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