- aiProcessDudes and aiInitSprite done, completing the main pass over ai.cpp.

This commit is contained in:
Christoph Oelckers 2021-05-05 12:55:52 +02:00
parent 29e245dfce
commit 44b0e59127
6 changed files with 44 additions and 47 deletions

View file

@ -6519,7 +6519,7 @@ DBloodActor* actSpawnDude(DBloodActor* source, short nType, int a3, int a4)
}
#endif
aiInitSprite(pSprite2);
aiInitSprite(spawned);
return spawned;
}

View file

@ -1706,19 +1706,17 @@ void aiProcessDudes(void)
void aiInit(void)
{
int nSprite;
StatIterator it(kStatDude);
while ((nSprite = it.NextIndex()) >= 0)
BloodStatIterator it(kStatDude);
while (auto actor = it.Next())
{
aiInitSprite(&sprite[nSprite]);
aiInitSprite(actor);
}
}
void aiInitSprite(spritetype *pSprite)
void aiInitSprite(DBloodActor* actor)
{
auto actor = &bloodActors[pSprite->index];
int nXSprite = pSprite->extra;
XSPRITE *pXSprite = &xsprite[nXSprite];
auto pSprite = &actor->s();
auto pXSprite = &actor->x();
int nSector = pSprite->sectnum;
int nXSector = sector[nSector].extra;
XSECTOR* pXSector = NULL;
@ -1736,19 +1734,19 @@ void aiInitSprite(spritetype *pSprite)
int targetX = 0, targetY = 0, targetZ = 0;
// dude patrol init
if (gModernMap) {
if (gModernMap)
{
// must keep it in case of loading save
if (pXSprite->dudeFlag4 && spriRangeIsFine(pXSprite->target_i) && sprite[pXSprite->target_i].type == kMarkerPath) {
stateTimer = pXSprite->stateTimer; targetMarker = pXSprite->target_i;
targetX = pXSprite->targetX; targetY = pXSprite->targetY;
targetZ = pXSprite->targetZ;
}
}
#endif
switch (pSprite->type) {
switch (pSprite->type)
{
case kDudeCultistTommy:
case kDudeCultistShotgun:
case kDudeCultistTesla:
@ -1903,7 +1901,7 @@ void aiInitSprite(spritetype *pSprite)
aiNewState(actor, &genIdle);
break;
}
aiSetTarget_(pXSprite, 0, 0, 0);
aiSetTarget(actor, 0, 0, 0);
pXSprite->stateTimer = 0;
switch (pSprite->type)
{
@ -1952,12 +1950,13 @@ void aiInitSprite(spritetype *pSprite)
}
#ifdef NOONE_EXTENSIONS
if (gModernMap) {
if (pXSprite->dudeFlag4) {
if (gModernMap)
{
if (pXSprite->dudeFlag4)
{
// restore dude's path
if (spriRangeIsFine(targetMarker)) {
if (spriRangeIsFine(targetMarker))
{
pXSprite->target_i = targetMarker;
pXSprite->targetX = targetX;
pXSprite->targetY = targetY;
@ -1982,12 +1981,9 @@ void aiInitSprite(spritetype *pSprite)
else if (uwater) aiPatrolState(pSprite, kAiStatePatrolMoveW);
else if (pXSprite->unused1 & kDudeFlagCrouch) aiPatrolState(pSprite, kAiStatePatrolMoveC);
else aiPatrolState(pSprite, kAiStatePatrolMoveL);
}
}
#endif
}
END_BLD_NS

View file

@ -93,7 +93,7 @@ void aiThinkTarget(DBloodActor* actor);
void aiLookForTarget(DBloodActor* actor);
void aiProcessDudes(void);
void aiInit(void);
void aiInitSprite(spritetype *pSprite);
void aiInitSprite(DBloodActor* pSprite);
bool CanMove(DBloodActor* pSprite, int a2, int nAngle, int nRange);
void aiSetTarget_(XSPRITE* pXSprite, int x, int y, int z);

View file

@ -1716,7 +1716,7 @@ spritetype* genDudeSpawn(XSPRITE* pXSource, spritetype* pSprite, int nDist) {
}
gKillMgr.AddNewKill(1);
aiInitSprite(pDude);
aiInitSprite(spawned);
return pDude;
}
@ -1814,7 +1814,7 @@ void genDudeTransform(spritetype* pSprite) {
int target = pXSprite->target_i;
// re-init sprite
aiInitSprite(pSprite);
aiInitSprite(actor);
// try to restore target
if (target == -1) aiSetTarget(actor, pSprite->x, pSprite->y, pSprite->z);

View file

@ -277,7 +277,7 @@ void Respawn(int nSprite) // 9
if (getSequence(getDudeInfo(nType + kDudeBase)->seqStartID))
seqSpawn(getDudeInfo(nType + kDudeBase)->seqStartID, 3, pSprite->extra, -1);
#endif
aiInitSprite(pSprite);
aiInitSprite(actor);
pXSprite->key = 0;
} else if (pSprite->type == kThingTNTBarrel) {
pSprite->cstat |= CSTAT_SPRITE_BLOCK | CSTAT_SPRITE_BLOCK_HITSCAN;

View file

@ -331,7 +331,7 @@ spritetype* nnExtSpawnDude(XSPRITE* pXSource, spritetype* pSprite, short nType,
}
aiInitSprite(pDude);
aiInitSprite(pDudeActor);
gKillMgr.AddNewKill(1);
@ -342,7 +342,7 @@ spritetype* nnExtSpawnDude(XSPRITE* pXSource, spritetype* pSprite, short nType,
}
if ((burning || (pSource->flags & kModernTypeFlag3)) && !pXDude->dudeFlag4)
aiActivateDude(&bloodActors[pXDude->reference]);
aiActivateDude(pDudeActor);
return pDude;
}
@ -2664,6 +2664,7 @@ void usePropertiesChanger(XSPRITE* pXSource, short objType, int objIndex) {
}
void useTeleportTarget(XSPRITE* pXSource, spritetype* pSprite) {
auto actor = &bloodActors[pSprite->index];
spritetype* pSource = &sprite[pXSource->reference]; PLAYER* pPlayer = getPlayerById(pSprite->type);
XSECTOR* pXSector = (sector[pSource->sectnum].extra >= 0) ? &xsector[sector[pSource->sectnum].extra] : NULL;
bool isDude = (!pPlayer && IsDudeSprite(pSprite));
@ -2733,7 +2734,7 @@ void useTeleportTarget(XSPRITE* pXSource, spritetype* pSprite) {
int x = pXDude->targetX; int y = pXDude->targetY; int z = pXDude->targetZ;
int target = pXDude->target_i;
aiInitSprite(pSprite);
aiInitSprite(actor);
if (target >= 0) {
pXDude->targetX = x; pXDude->targetY = y; pXDude->targetZ = z;
@ -4414,7 +4415,7 @@ void aiFightActivateDudes(int rx) {
if (rxBucket[i].type != OBJ_SPRITE) continue;
spritetype* pDude = &sprite[rxBucket[i].index]; XSPRITE* pXDude = &xsprite[pDude->extra];
if (!IsDudeSprite(pDude) || pXDude->aiState->stateType != kAiStateGenIdle) continue;
aiInitSprite(pDude);
aiInitSprite(&bloodActors[pDude->index]);
}
}
@ -6826,7 +6827,7 @@ void aiPatrolStop(spritetype* pSprite, int target, bool alarm)
} else {
aiInitSprite(pSprite);
aiInitSprite(actor);
aiSetTarget_(pXSprite, pXSprite->targetX, pXSprite->targetY, pXSprite->targetZ);