- handle all x() calls in AI code.

This commit is contained in:
Christoph Oelckers 2021-12-22 20:48:11 +01:00
parent 389933fe3a
commit 723e22743e
18 changed files with 44 additions and 43 deletions

View file

@ -214,7 +214,7 @@ static void beastThinkChase(DBloodActor* actor)
DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type); DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type);
if (!actor->ValidateTarget(__FUNCTION__)) return; if (!actor->ValidateTarget(__FUNCTION__)) return;
auto target = actor->GetTarget(); auto target = actor->GetTarget();
XSPRITE* pXTarget = &actor->GetTarget()->x();
int dx = target->spr.pos.X - actor->spr.pos.X; int dx = target->spr.pos.X - actor->spr.pos.X;
int dy = target->spr.pos.Y - actor->spr.pos.Y; int dy = target->spr.pos.Y - actor->spr.pos.Y;
aiChooseDirection(actor, getangle(dx, dy)); aiChooseDirection(actor, getangle(dx, dy));
@ -222,7 +222,7 @@ static void beastThinkChase(DBloodActor* actor)
auto pSector = actor->spr.sector(); auto pSector = actor->spr.sector();
auto pXSector = pSector->hasX() ? &pSector->xs() : nullptr; auto pXSector = pSector->hasX() ? &pSector->xs() : nullptr;
if (pXTarget->health == 0) if (target->xspr.health == 0)
{ {
if (pXSector && pXSector->Underwater) if (pXSector && pXSector->Underwater)
aiNewState(actor, &beastSwimSearch); aiNewState(actor, &beastSwimSearch);
@ -253,7 +253,7 @@ static void beastThinkChase(DBloodActor* actor)
&& target->IsPlayerActor() && Chance(0x8000)) && target->IsPlayerActor() && Chance(0x8000))
{ {
int hit = HitScan(actor, actor->spr.pos.Z, dx, dy, 0, CLIPMASK1, 0); int hit = HitScan(actor, actor->spr.pos.Z, dx, dy, 0, CLIPMASK1, 0);
if (pXTarget->health > (unsigned)gPlayerTemplate[0].startHealth / 2) if (target->xspr.health > (unsigned)gPlayerTemplate[0].startHealth / 2)
{ {
switch (hit) switch (hit)
{ {
@ -355,11 +355,11 @@ static void beastThinkSwimChase(DBloodActor* actor)
DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type); DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type);
if (!actor->ValidateTarget(__FUNCTION__)) return; if (!actor->ValidateTarget(__FUNCTION__)) return;
auto target = actor->GetTarget(); auto target = actor->GetTarget();
XSPRITE* pXTarget = &actor->GetTarget()->x();
int dx = target->spr.pos.X - actor->spr.pos.X; int dx = target->spr.pos.X - actor->spr.pos.X;
int dy = target->spr.pos.Y - actor->spr.pos.Y; int dy = target->spr.pos.Y - actor->spr.pos.Y;
aiChooseDirection(actor, getangle(dx, dy)); aiChooseDirection(actor, getangle(dx, dy));
if (pXTarget->health == 0) if (target->xspr.health == 0)
{ {
aiNewState(actor, &beastSwimSearch); aiNewState(actor, &beastSwimSearch);
return; return;

View file

@ -174,11 +174,11 @@ static void eelThinkPonder(DBloodActor* actor)
assert(actor->spr.type >= kDudeBase && actor->spr.type < kDudeMax); assert(actor->spr.type >= kDudeBase && actor->spr.type < kDudeMax);
DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type); DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type);
auto target = actor->GetTarget(); auto target = actor->GetTarget();
XSPRITE* pXTarget = &actor->GetTarget()->x();
int dx = target->spr.pos.X - actor->spr.pos.X; int dx = target->spr.pos.X - actor->spr.pos.X;
int dy = target->spr.pos.Y - actor->spr.pos.Y; int dy = target->spr.pos.Y - actor->spr.pos.Y;
aiChooseDirection(actor, getangle(dx, dy)); aiChooseDirection(actor, getangle(dx, dy));
if (pXTarget->health == 0) if (target->xspr.health == 0)
{ {
aiNewState(actor, &eelSearch); aiNewState(actor, &eelSearch);
return; return;
@ -277,11 +277,11 @@ static void eelThinkChase(DBloodActor* actor)
assert(actor->spr.type >= kDudeBase && actor->spr.type < kDudeMax); assert(actor->spr.type >= kDudeBase && actor->spr.type < kDudeMax);
DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type); DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type);
auto target = actor->GetTarget(); auto target = actor->GetTarget();
XSPRITE* pXTarget = &actor->GetTarget()->x();
int dx = target->spr.pos.X - actor->spr.pos.X; int dx = target->spr.pos.X - actor->spr.pos.X;
int dy = target->spr.pos.Y - actor->spr.pos.Y; int dy = target->spr.pos.Y - actor->spr.pos.Y;
aiChooseDirection(actor, getangle(dx, dy)); aiChooseDirection(actor, getangle(dx, dy));
if (pXTarget->health == 0) if (target->xspr.health == 0)
{ {
aiNewState(actor, &eelSearch); aiNewState(actor, &eelSearch);
return; return;

View file

@ -158,11 +158,11 @@ static void burnThinkChase(DBloodActor* actor)
assert(actor->spr.type >= kDudeBase && actor->spr.type < kDudeMax); assert(actor->spr.type >= kDudeBase && actor->spr.type < kDudeMax);
DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type); DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type);
auto target = actor->GetTarget(); auto target = actor->GetTarget();
XSPRITE* pXTarget = &actor->GetTarget()->x();
int dx = target->spr.pos.X - actor->spr.pos.X; int dx = target->spr.pos.X - actor->spr.pos.X;
int dy = target->spr.pos.Y - actor->spr.pos.Y; int dy = target->spr.pos.Y - actor->spr.pos.Y;
aiChooseDirection(actor, getangle(dx, dy)); aiChooseDirection(actor, getangle(dx, dy));
if (pXTarget->health == 0) if (target->xspr.health == 0)
{ {
switch (actor->spr.type) switch (actor->spr.type)
{ {

View file

@ -127,11 +127,11 @@ static void calebThinkChase(DBloodActor* actor)
assert(actor->spr.type >= kDudeBase && actor->spr.type < kDudeMax); assert(actor->spr.type >= kDudeBase && actor->spr.type < kDudeMax);
DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type); DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type);
auto target = actor->GetTarget(); auto target = actor->GetTarget();
XSPRITE* pXTarget = &actor->GetTarget()->x();
int dx = target->spr.pos.X - actor->spr.pos.X; int dx = target->spr.pos.X - actor->spr.pos.X;
int dy = target->spr.pos.Y - actor->spr.pos.Y; int dy = target->spr.pos.Y - actor->spr.pos.Y;
aiChooseDirection(actor, getangle(dx, dy)); aiChooseDirection(actor, getangle(dx, dy));
if (pXTarget->health == 0) if (target->xspr.health == 0)
{ {
if (pXSector && pXSector->Underwater) if (pXSector && pXSector->Underwater)
aiNewState(actor, &tinycalebSwimSearch); aiNewState(actor, &tinycalebSwimSearch);
@ -235,11 +235,11 @@ static void calebThinkSwimChase(DBloodActor* actor)
assert(actor->spr.type >= kDudeBase && actor->spr.type < kDudeMax); assert(actor->spr.type >= kDudeBase && actor->spr.type < kDudeMax);
DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type); DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type);
auto target = actor->GetTarget(); auto target = actor->GetTarget();
XSPRITE* pXTarget = &actor->GetTarget()->x();
int dx = target->spr.pos.X - actor->spr.pos.X; int dx = target->spr.pos.X - actor->spr.pos.X;
int dy = target->spr.pos.Y - actor->spr.pos.Y; int dy = target->spr.pos.Y - actor->spr.pos.Y;
aiChooseDirection(actor, getangle(dx, dy)); aiChooseDirection(actor, getangle(dx, dy));
if (pXTarget->health == 0) if (target->xspr.health == 0)
{ {
aiNewState(actor, &tinycalebSwimSearch); aiNewState(actor, &tinycalebSwimSearch);
return; return;

View file

@ -343,12 +343,12 @@ static void cerberusThinkChase(DBloodActor* actor)
if (!actor->ValidateTarget(__FUNCTION__)) return; if (!actor->ValidateTarget(__FUNCTION__)) return;
auto target = actor->GetTarget(); auto target = actor->GetTarget();
XSPRITE* pXTarget = &actor->GetTarget()->x();
int dx = target->spr.pos.X - actor->spr.pos.X; int dx = target->spr.pos.X - actor->spr.pos.X;
int dy = target->spr.pos.Y - actor->spr.pos.Y; int dy = target->spr.pos.Y - actor->spr.pos.Y;
aiChooseDirection(actor, getangle(dx, dy)); aiChooseDirection(actor, getangle(dx, dy));
if (pXTarget->health == 0) { if (target->xspr.health == 0) {
switch (actor->spr.type) { switch (actor->spr.type) {
case kDudeCerberusTwoHead: case kDudeCerberusTwoHead:
aiNewState(actor, &cerberusSearch); aiNewState(actor, &cerberusSearch);

View file

@ -236,11 +236,11 @@ static void cultThinkChase(DBloodActor* actor)
assert(actor->spr.type >= kDudeBase && actor->spr.type < kDudeMax); assert(actor->spr.type >= kDudeBase && actor->spr.type < kDudeMax);
DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type); DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type);
auto target = actor->GetTarget(); auto target = actor->GetTarget();
XSPRITE* pXTarget = &actor->GetTarget()->x();
int dx = target->spr.pos.X - actor->spr.pos.X; int dx = target->spr.pos.X - actor->spr.pos.X;
int dy = target->spr.pos.Y - actor->spr.pos.Y; int dy = target->spr.pos.Y - actor->spr.pos.Y;
aiChooseDirection(actor, getangle(dx, dy)); aiChooseDirection(actor, getangle(dx, dy));
if (pXTarget->health == 0) if (target->xspr.health == 0)
{ {
switch (pXSprite->medium) switch (pXSprite->medium)
{ {

View file

@ -347,11 +347,11 @@ static void gargThinkChase(DBloodActor* actor)
} }
DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type); DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type);
auto target = actor->GetTarget(); auto target = actor->GetTarget();
XSPRITE* pXTarget = &actor->GetTarget()->x();
int dx = target->spr.pos.X - actor->spr.pos.X; int dx = target->spr.pos.X - actor->spr.pos.X;
int dy = target->spr.pos.Y - actor->spr.pos.Y; int dy = target->spr.pos.Y - actor->spr.pos.Y;
aiChooseDirection(actor, getangle(dx, dy)); aiChooseDirection(actor, getangle(dx, dy));
if (pXTarget->health == 0) if (target->xspr.health == 0)
{ {
aiNewState(actor, &gargoyleFSearch); aiNewState(actor, &gargoyleFSearch);
return; return;

View file

@ -327,11 +327,11 @@ static void ghostThinkChase(DBloodActor* actor)
} }
DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type); DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type);
auto target = actor->GetTarget(); auto target = actor->GetTarget();
XSPRITE* pXTarget = &actor->GetTarget()->x();
int dx = target->spr.pos.X - actor->spr.pos.X; int dx = target->spr.pos.X - actor->spr.pos.X;
int dy = target->spr.pos.Y - actor->spr.pos.Y; int dy = target->spr.pos.Y - actor->spr.pos.Y;
aiChooseDirection(actor, getangle(dx, dy)); aiChooseDirection(actor, getangle(dx, dy));
if (pXTarget->health == 0) if (target->xspr.health == 0)
{ {
aiNewState(actor, &ghostSearch); aiNewState(actor, &ghostSearch);
return; return;

View file

@ -89,11 +89,11 @@ static void handThinkChase(DBloodActor* actor)
DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type); DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type);
if (!actor->ValidateTarget(__FUNCTION__)) return; if (!actor->ValidateTarget(__FUNCTION__)) return;
auto target = actor->GetTarget(); auto target = actor->GetTarget();
XSPRITE* pXTarget = &actor->GetTarget()->x();
int dx = target->spr.pos.X - actor->spr.pos.X; int dx = target->spr.pos.X - actor->spr.pos.X;
int dy = target->spr.pos.Y - actor->spr.pos.Y; int dy = target->spr.pos.Y - actor->spr.pos.Y;
aiChooseDirection(actor, getangle(dx, dy)); aiChooseDirection(actor, getangle(dx, dy));
if (pXTarget->health == 0) if (target->xspr.health == 0)
{ {
aiNewState(actor, &handSearch); aiNewState(actor, &handSearch);
return; return;

View file

@ -106,11 +106,11 @@ static void houndThinkChase(DBloodActor* actor)
} }
DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type); DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type);
auto target = actor->GetTarget(); auto target = actor->GetTarget();
XSPRITE* pXTarget = &actor->GetTarget()->x();
int dx = target->spr.pos.X - actor->spr.pos.X; int dx = target->spr.pos.X - actor->spr.pos.X;
int dy = target->spr.pos.Y - actor->spr.pos.Y; int dy = target->spr.pos.Y - actor->spr.pos.Y;
aiChooseDirection(actor, getangle(dx, dy)); aiChooseDirection(actor, getangle(dx, dy));
if (pXTarget->health == 0) if (target->xspr.health == 0)
{ {
aiNewState(actor, &houndSearch); aiNewState(actor, &houndSearch);
return; return;

View file

@ -74,11 +74,11 @@ static void innocThinkChase(DBloodActor* actor)
DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type); DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type);
if (!actor->ValidateTarget(__FUNCTION__)) return; if (!actor->ValidateTarget(__FUNCTION__)) return;
auto target = actor->GetTarget(); auto target = actor->GetTarget();
XSPRITE* pXTarget = &actor->GetTarget()->x();
int dx = target->spr.pos.X - actor->spr.pos.X; int dx = target->spr.pos.X - actor->spr.pos.X;
int dy = target->spr.pos.Y - actor->spr.pos.Y; int dy = target->spr.pos.Y - actor->spr.pos.Y;
aiChooseDirection(actor, getangle(dx, dy)); aiChooseDirection(actor, getangle(dx, dy));
if (pXTarget->health == 0) if (target->xspr.health == 0)
{ {
aiNewState(actor, &innocentSearch); aiNewState(actor, &innocentSearch);
return; return;

View file

@ -182,11 +182,11 @@ static void aiPodChase(DBloodActor* actor)
} }
DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type); DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type);
auto target = actor->GetTarget(); auto target = actor->GetTarget();
XSPRITE* pXTarget = &actor->GetTarget()->x();
int dx = target->spr.pos.X - actor->spr.pos.X; int dx = target->spr.pos.X - actor->spr.pos.X;
int dy = target->spr.pos.Y - actor->spr.pos.Y; int dy = target->spr.pos.Y - actor->spr.pos.Y;
aiChooseDirection(actor, getangle(dx, dy)); aiChooseDirection(actor, getangle(dx, dy));
if (pXTarget->health == 0) { if (target->xspr.health == 0) {
switch (actor->spr.type) { switch (actor->spr.type) {
case kDudePodGreen: case kDudePodGreen:

View file

@ -84,11 +84,11 @@ static void ratThinkChase(DBloodActor* actor)
assert(actor->spr.type >= kDudeBase && actor->spr.type < kDudeMax); assert(actor->spr.type >= kDudeBase && actor->spr.type < kDudeMax);
DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type); DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type);
auto target = actor->GetTarget(); auto target = actor->GetTarget();
XSPRITE* pXTarget = &actor->GetTarget()->x();
int dx = target->spr.pos.X - actor->spr.pos.X; int dx = target->spr.pos.X - actor->spr.pos.X;
int dy = target->spr.pos.Y - actor->spr.pos.Y; int dy = target->spr.pos.Y - actor->spr.pos.Y;
aiChooseDirection(actor, getangle(dx, dy)); aiChooseDirection(actor, getangle(dx, dy));
if (pXTarget->health == 0) if (target->xspr.health == 0)
{ {
aiNewState(actor, &ratSearch); aiNewState(actor, &ratSearch);
return; return;

View file

@ -194,11 +194,11 @@ static void spidThinkChase(DBloodActor* actor)
assert(actor->spr.type >= kDudeBase && actor->spr.type < kDudeMax); assert(actor->spr.type >= kDudeBase && actor->spr.type < kDudeMax);
DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type); DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type);
auto target = actor->GetTarget(); auto target = actor->GetTarget();
XSPRITE* pXTarget = &actor->GetTarget()->x();
int dx = target->spr.pos.X - actor->spr.pos.X; int dx = target->spr.pos.X - actor->spr.pos.X;
int dy = target->spr.pos.Y - actor->spr.pos.Y; int dy = target->spr.pos.Y - actor->spr.pos.Y;
aiChooseDirection(actor, getangle(dx, dy)); aiChooseDirection(actor, getangle(dx, dy));
if (pXTarget->health == 0) if (target->xspr.health == 0)
{ {
aiNewState(actor, &spidSearch); aiNewState(actor, &spidSearch);
return; return;

View file

@ -291,11 +291,11 @@ static void sub_72934(DBloodActor* actor)
DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type); DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type);
if (!actor->ValidateTarget(__FUNCTION__)) return; if (!actor->ValidateTarget(__FUNCTION__)) return;
auto target = actor->GetTarget(); auto target = actor->GetTarget();
XSPRITE* pXTarget = &actor->GetTarget()->x();
int dx = target->spr.pos.X - actor->spr.pos.X; int dx = target->spr.pos.X - actor->spr.pos.X;
int dy = target->spr.pos.Y - actor->spr.pos.Y; int dy = target->spr.pos.Y - actor->spr.pos.Y;
aiChooseDirection(actor, getangle(dx, dy)); aiChooseDirection(actor, getangle(dx, dy));
if (pXTarget->health == 0) if (target->xspr.health == 0)
{ {
aiNewState(actor, &tchernobogSearch); aiNewState(actor, &tchernobogSearch);
return; return;

View file

@ -478,6 +478,7 @@ static void unicultThinkChase(DBloodActor* actor)
genDudeUpdate(actor); genDudeUpdate(actor);
} }
// we need to be very careful here not to screw up the condition for this check!
XSPRITE* pXTarget = !targetactor || !targetactor->IsDudeActor() || !targetactor->hasX() ? nullptr : &targetactor->x(); XSPRITE* pXTarget = !targetactor || !targetactor->IsDudeActor() || !targetactor->hasX() ? nullptr : &targetactor->x();
if (pXTarget == nullptr) // target lost if (pXTarget == nullptr) // target lost

View file

@ -115,11 +115,11 @@ static void zombaThinkChase(DBloodActor* actor)
DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type); DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type);
if (!actor->ValidateTarget(__FUNCTION__)) return; if (!actor->ValidateTarget(__FUNCTION__)) return;
auto target = actor->GetTarget(); auto target = actor->GetTarget();
XSPRITE* pXTarget = &actor->GetTarget()->x();
int dx = target->spr.pos.X - actor->spr.pos.X; int dx = target->spr.pos.X - actor->spr.pos.X;
int dy = target->spr.pos.Y - actor->spr.pos.Y; int dy = target->spr.pos.Y - actor->spr.pos.Y;
aiChooseDirection(actor, getangle(dx, dy)); aiChooseDirection(actor, getangle(dx, dy));
if (pXTarget->health == 0) if (target->xspr.health == 0)
{ {
aiNewState(actor, &zombieASearch); aiNewState(actor, &zombieASearch);
return; return;
@ -165,11 +165,11 @@ static void zombaThinkPonder(DBloodActor* actor)
DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type); DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type);
if (!actor->ValidateTarget(__FUNCTION__)) return; if (!actor->ValidateTarget(__FUNCTION__)) return;
auto target = actor->GetTarget(); auto target = actor->GetTarget();
XSPRITE* pXTarget = &actor->GetTarget()->x();
int dx = target->spr.pos.X - actor->spr.pos.X; int dx = target->spr.pos.X - actor->spr.pos.X;
int dy = target->spr.pos.Y - actor->spr.pos.Y; int dy = target->spr.pos.Y - actor->spr.pos.Y;
aiChooseDirection(actor, getangle(dx, dy)); aiChooseDirection(actor, getangle(dx, dy));
if (pXTarget->health == 0) if (target->xspr.health == 0)
{ {
aiNewState(actor, &zombieASearch); aiNewState(actor, &zombieASearch);
return; return;

View file

@ -114,11 +114,11 @@ static void zombfThinkChase(DBloodActor* actor)
DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type); DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type);
if (!actor->ValidateTarget(__FUNCTION__)) return; if (!actor->ValidateTarget(__FUNCTION__)) return;
auto target = actor->GetTarget(); auto target = actor->GetTarget();
XSPRITE* pXTarget = &actor->GetTarget()->x();
int dx = target->spr.pos.X - actor->spr.pos.X; int dx = target->spr.pos.X - actor->spr.pos.X;
int dy = target->spr.pos.Y - actor->spr.pos.Y; int dy = target->spr.pos.Y - actor->spr.pos.Y;
aiChooseDirection(actor, getangle(dx, dy)); aiChooseDirection(actor, getangle(dx, dy));
if (pXTarget->health == 0) if (target->xspr.health == 0)
{ {
aiNewState(actor, &zombieFSearch); aiNewState(actor, &zombieFSearch);
return; return;