diff --git a/source/games/sw/src/ai.cpp b/source/games/sw/src/ai.cpp index 0c8553088..6c702e0b4 100644 --- a/source/games/sw/src/ai.cpp +++ b/source/games/sw/src/ai.cpp @@ -291,7 +291,7 @@ bool CanSeePlayer(DSWActor* actor) //if (FAF_Sector(sp->sectnum)) // return(true); - if (u->tgt_sp() && FAFcansee(sp->x, sp->y, look_height, sp->sectnum, u->targetActor->s().x, u->targetActor->s().y, SPRITEp_UPPER(u->tgt_sp()), u->targetActor->s().sectnum)) + if (u->targetActor && FAFcansee(sp->x, sp->y, look_height, sp->sectnum, u->targetActor->s().x, u->targetActor->s().y, ActorUpper(u->targetActor), u->targetActor->s().sectnum)) return true; else return false; @@ -312,7 +312,8 @@ int CanHitPlayer(DSWActor* actor) zhs = sp->z - DIV2(SPRITEp_SIZE_Z(sp)); - auto hp = u->tgt_sp(); + + auto hp = &u->targetActor->s(); // get angle to target ang = getangle(hp->x - sp->x, hp->y - sp->y); @@ -345,7 +346,7 @@ int CanHitPlayer(DSWActor* actor) if (hitinfo.sect < 0) return false; - if (hitinfo.sprite == u->tgt_sp() - sprite) + if (hitinfo.sprite == u->targetActor->GetSpriteIndex()) return true; ////DSPRINTF(ds,"CanHit %s",ret ? "true" : "false"); @@ -494,7 +495,7 @@ GetPlayerSpriteNum(short SpriteNum) { pp = &Player[pnum]; - if (pp->SpriteP == u->tgt_sp()) + if (pp->Actor() == u->targetActor) { return pp->PlayerSprite; } @@ -596,7 +597,7 @@ DECISION GenericFlaming[] = every time through the loop. This would be too slow. It is only called when the actor needs to know what to do next such as running into something or being targeted. It makes decisions based on the distance and viewablity of its target - (u->tgt_sp()). When it figures out the situatation with its target it calls + (u->targetActor). When it figures out the situatation with its target it calls ChooseAction which does a random table lookup to decide what action to initialize. Once this action is initialized it will be called until it can't figure out what to do anymore and then this routine is called again. @@ -647,16 +648,6 @@ DoActorActionDecide(short SpriteNum) // !AIC KEY - If aware of player - var is changed in SpriteControl if (TEST(u->Flags, SPR_ACTIVE)) { - // CODE BELOW = CRAP, DON'T USE IT OR IT MAKES ACTORS NOT ANIMATE SOMETIMES!!!!! - // If target was actor, retarget to player it actor died - // or just randomly give the target actor a break - //if ((User[u->tgt_sp()-sprite] && - // User[u->tgt_sp()-sprite]->Health <= 0) || RandomRange(1000) > 950) - // { - // DoActorPickClosePlayer(actor); - // InitActorReposition(SpriteNum); - // return(action); - // } // Try to operate stuff DoActorOperate(SpriteNum); @@ -1220,7 +1211,7 @@ FindTrackToPlayer(USERp u) //MONO_PRINT("FindTrackToPlayer\n"); - zdiff = SPRITEp_UPPER(u->tgt_sp()) - (sp->z - SPRITEp_SIZE_Z(sp) + Z(8)); + zdiff = ActorUpper(u->targetActor) - (sp->z - SPRITEp_SIZE_Z(sp) + Z(8)); if (labs(zdiff) <= Z(20)) { diff --git a/source/games/sw/src/game.h b/source/games/sw/src/game.h index 9b8d7acdb..22fb08ebe 100644 --- a/source/games/sw/src/game.h +++ b/source/games/sw/src/game.h @@ -2247,6 +2247,22 @@ SPRITEp USER::tgt_sp() return targetActor == nullptr? nullptr : &targetActor->s(); } +inline int ActorUpper(DSWActor* actor) +{ + return SPRITEp_UPPER(&actor->s()); +} + +inline int ActorLower(DSWActor* actor) +{ + return SPRITEp_LOWER(&actor->s()); +} + +inline int ActorMid(DSWActor* actor) +{ + return SPRITEp_MID(&actor->s()); +} + + END_SW_NS #endif diff --git a/source/games/sw/src/miscactr.cpp b/source/games/sw/src/miscactr.cpp index 2681541ce..33c76b205 100644 --- a/source/games/sw/src/miscactr.cpp +++ b/source/games/sw/src/miscactr.cpp @@ -157,7 +157,7 @@ int DoToiletGirl(DSWActor* actor) bool ICanSee = false; DoActorPickClosePlayer(actor); - ICanSee = FAFcansee(sp->x,sp->y,SPRITEp_MID(sp),sp->sectnum,u->targetActor->s().x,u->targetActor->s().y,SPRITEp_MID(u->tgt_sp()),u->targetActor->s().sectnum); + ICanSee = FAFcansee(sp->x,sp->y,SPRITEp_MID(sp),sp->sectnum,u->targetActor->s().x,u->targetActor->s().y,ActorMid(u->targetActor),u->targetActor->s().sectnum); if (u->FlagOwner != 1) { @@ -400,7 +400,7 @@ int DoWashGirl(DSWActor* actor) bool ICanSee = false; DoActorPickClosePlayer(actor); - ICanSee = FAFcansee(sp->x,sp->y,SPRITEp_MID(sp),sp->sectnum,u->targetActor->s().x,u->targetActor->s().y,SPRITEp_MID(u->tgt_sp()),u->targetActor->s().sectnum); + ICanSee = FAFcansee(sp->x,sp->y,SPRITEp_MID(sp),sp->sectnum,u->targetActor->s().x,u->targetActor->s().y,ActorMid(u->targetActor),u->targetActor->s().sectnum); if (RandomRange(1000) > 980 && u->ShellNum <= 0) { @@ -1280,7 +1280,7 @@ int DoCarGirl(DSWActor* actor) bool ICanSee = false; DoActorPickClosePlayer(actor); - ICanSee = FAFcansee(sp->x,sp->y,SPRITEp_MID(sp),sp->sectnum,u->targetActor->s().x,u->targetActor->s().y,SPRITEp_MID(u->tgt_sp()),u->targetActor->s().sectnum); + ICanSee = FAFcansee(sp->x,sp->y,SPRITEp_MID(sp),sp->sectnum,u->targetActor->s().x,u->targetActor->s().y,ActorMid(u->targetActor),u->targetActor->s().sectnum); if (u->FlagOwner == 1) { @@ -1502,7 +1502,7 @@ int DoMechanicGirl(DSWActor* actor) bool ICanSee = false; DoActorPickClosePlayer(actor); - ICanSee = FAFcansee(sp->x,sp->y,SPRITEp_MID(sp),sp->sectnum,u->targetActor->s().x,u->targetActor->s().y,SPRITEp_MID(u->tgt_sp()),u->targetActor->s().sectnum); + ICanSee = FAFcansee(sp->x,sp->y,SPRITEp_MID(sp),sp->sectnum,u->targetActor->s().x,u->targetActor->s().y,ActorMid(u->targetActor),u->targetActor->s().sectnum); if (u->FlagOwner == 1) { @@ -1725,7 +1725,7 @@ int DoSailorGirl(DSWActor* actor) bool ICanSee = false; DoActorPickClosePlayer(actor); - ICanSee = FAFcansee(sp->x,sp->y,SPRITEp_MID(sp),sp->sectnum,u->targetActor->s().x,u->targetActor->s().y,SPRITEp_MID(u->tgt_sp()),u->targetActor->s().sectnum); + ICanSee = FAFcansee(sp->x,sp->y,SPRITEp_MID(sp),sp->sectnum,u->targetActor->s().x,u->targetActor->s().y,ActorMid(u->targetActor),u->targetActor->s().sectnum); if (u->FlagOwner == 1) { @@ -1940,7 +1940,7 @@ int DoPruneGirl(DSWActor* actor) bool ICanSee = false; DoActorPickClosePlayer(actor); - ICanSee = FAFcansee(sp->x,sp->y,SPRITEp_MID(sp),sp->sectnum,u->targetActor->s().x,u->targetActor->s().y,SPRITEp_MID(u->tgt_sp()),u->targetActor->s().sectnum); + ICanSee = FAFcansee(sp->x,sp->y,SPRITEp_MID(sp),sp->sectnum,u->targetActor->s().x,u->targetActor->s().y,ActorMid(u->targetActor),u->targetActor->s().sectnum); if (u->FlagOwner == 1) { diff --git a/source/games/sw/src/track.cpp b/source/games/sw/src/track.cpp index d1f7e87d5..fb8470dbf 100644 --- a/source/games/sw/src/track.cpp +++ b/source/games/sw/src/track.cpp @@ -2949,7 +2949,7 @@ DoAutoTurretObject(SECTOR_OBJECTp sop) shootp = &sprite[sop->sp_num[i]]; if (!FAFcansee(shootp->x, shootp->y, shootp->z-Z(4), shootp->sectnum, - u->targetActor->s().x, u->targetActor->s().y, SPRITEp_UPPER(u->tgt_sp()), u->targetActor->s().sectnum)) + u->targetActor->s().x, u->targetActor->s().y, ActorUpper(u->targetActor), u->targetActor->s().sectnum)) { return; } diff --git a/source/games/sw/src/weapon.cpp b/source/games/sw/src/weapon.cpp index 35bec96b2..a0d1ceece 100644 --- a/source/games/sw/src/weapon.cpp +++ b/source/games/sw/src/weapon.cpp @@ -12920,7 +12920,7 @@ InitLavaThrow(DSWActor* actor) dist = Distance(wp->x, wp->y, u->targetActor->s().x, u->targetActor->s().y); if (dist != 0) - wu->zchange = wp->zvel = (wp->xvel * (SPRITEp_UPPER(u->tgt_sp()) - wp->z)) / dist; + wu->zchange = wp->zvel = (wp->xvel * (ActorUpper(u->targetActor) - wp->z)) / dist; return w; } @@ -13246,7 +13246,7 @@ InitEnemyNapalm(DSWActor* actor) dist = Distance(wp->x, wp->y, u->targetActor->s().x, u->targetActor->s().y); if (dist != 0) - wp->zvel = (wp->xvel * (SPRITEp_UPPER(u->tgt_sp()) - wp->z)) / dist; + wp->zvel = (wp->xvel * (ActorUpper(u->targetActor) - wp->z)) / dist; wu->xchange = MOVEx(wp->xvel, wp->ang); wu->ychange = MOVEy(wp->xvel, wp->ang); @@ -13355,7 +13355,7 @@ InitEnemyMirv(DSWActor* actor) dist = Distance(wp->x, wp->y, u->targetActor->s().x, u->targetActor->s().y); if (dist != 0) - wu->zchange = wp->zvel = (wp->xvel * (SPRITEp_UPPER(u->tgt_sp()) - wp->z)) / dist; + wu->zchange = wp->zvel = (wp->xvel * (ActorUpper(u->targetActor) - wp->z)) / dist; return 0; } @@ -13815,7 +13815,7 @@ InitSumoNapalm(short SpriteNum) dist = Distance(wp->x, wp->y, u->targetActor->s().x, u->targetActor->s().y); if (dist != 0) - wp->zvel = (wp->xvel * (SPRITEp_UPPER(u->tgt_sp()) - wp->z)) / dist; + wp->zvel = (wp->xvel * (ActorUpper(u->targetActor) - wp->z)) / dist; wu->xchange = MOVEx(wp->xvel, wp->ang); wu->ychange = MOVEy(wp->xvel, wp->ang); @@ -13951,7 +13951,7 @@ InitMiniSumoClap(short SpriteNum) { if (SpriteOverlapZ(SpriteNum, short(u->tgt_sp() - sprite), Z(20))) { - if (FAFcansee(u->targetActor->s().x,u->targetActor->s().y,SPRITEp_MID(u->tgt_sp()),u->targetActor->s().sectnum,sp->x,sp->y,SPRITEp_MID(sp),sp->sectnum)) + if (FAFcansee(u->targetActor->s().x,u->targetActor->s().y,ActorMid(u->targetActor),u->targetActor->s().sectnum,sp->x,sp->y,SPRITEp_MID(sp),sp->sectnum)) { PlaySound(DIGI_CGTHIGHBONE, sp, v3df_follow|v3df_dontpan); DoDamage(short(u->tgt_sp() - sprite), SpriteNum); @@ -13960,7 +13960,7 @@ InitMiniSumoClap(short SpriteNum) } else if (dist < CLOSE_RANGE_DIST_FUDGE(u->tgt_sp(), sp, reach)) { - if (FAFcansee(u->targetActor->s().x,u->targetActor->s().y,SPRITEp_MID(u->tgt_sp()),u->targetActor->s().sectnum,sp->x,sp->y,SPRITEp_MID(sp),sp->sectnum)) + if (FAFcansee(u->targetActor->s().x,u->targetActor->s().y,ActorMid(u->targetActor),u->targetActor->s().sectnum,sp->x,sp->y,SPRITEp_MID(sp),sp->sectnum)) { PlaySound(DIGI_30MMEXPLODE, sp, v3df_none); SpawnFireballFlames(SpriteNum, short(u->tgt_sp() - sprite)); @@ -16072,7 +16072,7 @@ InitSerpSpell(DSWActor* actor) // find the distance to the target (player) dist = Distance(np->x, np->y, u->targetActor->s().x, u->targetActor->s().y); if (dist != 0) - np->zvel = (np->xvel * (SPRITEp_UPPER(u->tgt_sp()) - np->z)) / dist; + np->zvel = (np->xvel * (ActorUpper(u->targetActor) - np->z)) / dist; np->ang = NORM_ANGLE(np->ang + delta_ang[i]); @@ -16192,7 +16192,7 @@ InitSerpMonstSpell(DSWActor* actor) // find the distance to the target (player) dist = Distance(np->x, np->y, u->targetActor->s().x, u->targetActor->s().y); if (dist != 0) - np->zvel = (np->xvel * (SPRITEp_UPPER(u->tgt_sp()) - np->z)) / dist; + np->zvel = (np->xvel * (ActorUpper(u->targetActor) - np->z)) / dist; np->ang = NORM_ANGLE(np->ang + delta_ang[i]); @@ -16288,7 +16288,7 @@ InitEnemyRocket(DSWActor* actor) dist = Distance(wp->x, wp->y, u->targetActor->s().x, u->targetActor->s().y); if (dist != 0) - wu->zchange = wp->zvel = (wp->xvel * (SPRITEp_UPPER(u->tgt_sp()) - wp->z)) / dist; + wu->zchange = wp->zvel = (wp->xvel * (ActorUpper(u->targetActor) - wp->z)) / dist; return w; } @@ -16383,7 +16383,7 @@ InitEnemyRail(DSWActor* actor) dist = Distance(wp->x, wp->y, u->targetActor->s().x, u->targetActor->s().y); if (dist != 0) - wu->zchange = wp->zvel = (wp->xvel * (SPRITEp_UPPER(u->tgt_sp()) - wp->z)) / dist; + wu->zchange = wp->zvel = (wp->xvel * (ActorUpper(u->targetActor) - wp->z)) / dist; return w; } @@ -16473,7 +16473,7 @@ InitZillaRocket(DSWActor* actor) dist = Distance(wp->x, wp->y, u->targetActor->s().x, u->targetActor->s().y); if (dist != 0) - wu->zchange = wp->zvel = (wp->xvel * (SPRITEp_UPPER(u->tgt_sp()) - wp->z)) / dist; + wu->zchange = wp->zvel = (wp->xvel * (ActorUpper(u->targetActor) - wp->z)) / dist; } return w; @@ -16521,7 +16521,7 @@ InitEnemyStar(DSWActor* actor) dist = Distance(wp->x, wp->y, u->targetActor->s().x, u->targetActor->s().y); if (dist != 0) - wu->zchange = wp->zvel = (wp->xvel * (SPRITEp_UPPER(u->tgt_sp()) - wp->z)) / dist; + wu->zchange = wp->zvel = (wp->xvel * (ActorUpper(u->targetActor) - wp->z)) / dist; // // Star Power Up Code @@ -16617,7 +16617,7 @@ InitEnemyCrossbow(DSWActor* actor) dist = Distance(wp->x, wp->y, u->targetActor->s().x, u->targetActor->s().y); if (dist != 0) - wu->zchange = wp->zvel = (wp->xvel * (SPRITEp_UPPER(u->tgt_sp()) - wp->z)) / dist; + wu->zchange = wp->zvel = (wp->xvel * (ActorUpper(u->targetActor) - wp->z)) / dist; // // Star Power Up Code @@ -16706,7 +16706,7 @@ InitSkelSpell(DSWActor* actor) dist = Distance(nx, ny, u->targetActor->s().x, u->targetActor->s().y); if (dist != 0) - wp->zvel = (wp->xvel * (SPRITEp_UPPER(u->tgt_sp()) - nz)) / dist; + wp->zvel = (wp->xvel * (ActorUpper(u->targetActor) - nz)) / dist; wu->xchange = MOVEx(wp->xvel, wp->ang); wu->ychange = MOVEy(wp->xvel, wp->ang); @@ -16771,7 +16771,7 @@ InitCoolgFire(DSWActor* actor) if (dist != 0) // (velocity * difference between the target and the throwing star) / // distance - wp->zvel = (wp->xvel * (SPRITEp_UPPER(u->tgt_sp()) - nz)) / dist; + wp->zvel = (wp->xvel * (ActorUpper(u->targetActor) - nz)) / dist; wu->xchange = MOVEx(wp->xvel, wp->ang); wu->ychange = MOVEy(wp->xvel, wp->ang); @@ -17058,7 +17058,7 @@ InitSpearTrap(short SpriteNum) //int dist = Distance(wp->x, wp->y, u->targetActor->s().x, u->targetActor->s().y); //if (dist != 0) - //wu->zchange = wp->zvel = (wp->xvel * (SPRITEp_UPPER(u->tgt_sp()) - wp->z)) / dist; + //wu->zchange = wp->zvel = (wp->xvel * (ActorUpper(u->targetActor) - wp->z)) / dist; PlaySound(DIGI_STAR, sp, v3df_none); return w;