From 80412bdc51e88b12749d2b3fad21c34daf1af53b Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 22 Aug 2022 18:36:41 +0200 Subject: [PATCH] - cansee refactoring, part 2 --- source/games/blood/src/aicaleb.cpp | 8 ++++---- source/games/blood/src/aicerber.cpp | 8 +++++--- source/games/blood/src/aicult.cpp | 4 ++-- source/games/blood/src/aigarg.cpp | 6 ++++-- source/games/blood/src/aighost.cpp | 6 ++++-- source/games/blood/src/aigilbst.cpp | 8 ++++---- 6 files changed, 23 insertions(+), 17 deletions(-) diff --git a/source/games/blood/src/aicaleb.cpp b/source/games/blood/src/aicaleb.cpp index 3f4b55e9e..e0fe0577c 100644 --- a/source/games/blood/src/aicaleb.cpp +++ b/source/games/blood/src/aicaleb.cpp @@ -152,8 +152,8 @@ static void calebThinkChase(DBloodActor* actor) if (nDist <= pDudeInfo->seeDist) { int nDeltaAngle = ((getangle(dx, dy) + 1024 - actor->int_ang()) & 2047) - 1024; - int height = (pDudeInfo->eyeHeight * actor->spr.yrepeat) << 2; - if (cansee(target->int_pos().X, target->int_pos().Y, target->int_pos().Z, target->sector(), actor->int_pos().X, actor->int_pos().Y, actor->int_pos().Z - height, actor->sector())) + double height = (pDudeInfo->eyeHeight * actor->spr.yrepeat) * REPEAT_SCALE; + if (cansee(target->spr.pos, target->sector(), actor->spr.pos.plusZ(-height), actor->sector())) { if (nDist < pDudeInfo->seeDist && abs(nDeltaAngle) <= pDudeInfo->periphery) { @@ -250,10 +250,10 @@ static void calebThinkSwimChase(DBloodActor* actor) if (nDist <= pDudeInfo->seeDist) { int nDeltaAngle = ((getangle(dx, dy) + 1024 - actor->int_ang()) & 2047) - 1024; - int height = pDudeInfo->eyeHeight + actor->int_pos().Z; + double height = (pDudeInfo->eyeHeight * actor->spr.yrepeat) * REPEAT_SCALE; int top, bottom; GetActorExtents(actor, &top, &bottom); - if (cansee(target->int_pos().X, target->int_pos().Y, target->int_pos().Z, target->sector(), actor->int_pos().X, actor->int_pos().Y, actor->int_pos().Z - height, actor->sector())) + if (cansee(target->spr.pos, target->sector(), actor->spr.pos.plusZ(-height), actor->sector())) { if (nDist < pDudeInfo->seeDist && abs(nDeltaAngle) <= pDudeInfo->periphery) { diff --git a/source/games/blood/src/aicerber.cpp b/source/games/blood/src/aicerber.cpp index f5f0db8a2..52c64dddf 100644 --- a/source/games/blood/src/aicerber.cpp +++ b/source/games/blood/src/aicerber.cpp @@ -258,6 +258,7 @@ static void cerberusThinkTarget(DBloodActor* actor) PLAYER* pPlayer = &gPlayer[p]; if (pPlayer->actor->xspr.health == 0 || powerupCheck(pPlayer, kPwUpShadowCloak) > 0) continue; + auto ppos = pPlayer->actor->spr.pos; int x = pPlayer->actor->int_pos().X; int y = pPlayer->actor->int_pos().Y; int z = pPlayer->actor->int_pos().Z; @@ -267,7 +268,8 @@ static void cerberusThinkTarget(DBloodActor* actor) int nDist = approxDist(dx, dy); if (nDist > pDudeInfo->seeDist && nDist > pDudeInfo->hearDist) continue; - if (!cansee(x, y, z, pSector, actor->int_pos().X, actor->int_pos().Y, actor->int_pos().Z - ((pDudeInfo->eyeHeight * actor->spr.yrepeat) << 2), actor->sector())) + double height = (pDudeInfo->eyeHeight * actor->spr.yrepeat) * REPEAT_SCALE; + if (!cansee(ppos, pSector, actor->spr.pos.plusZ(-height), actor->sector())) continue; int nDeltaAngle = ((getangle(dx, dy) + 1024 - actor->int_ang()) & 2047) - 1024; if (nDist < pDudeInfo->seeDist && abs(nDeltaAngle) <= pDudeInfo->periphery) @@ -372,8 +374,8 @@ static void cerberusThinkChase(DBloodActor* actor) if (nDist <= pDudeInfo->seeDist) { int nDeltaAngle = ((getangle(dx, dy) + 1024 - actor->int_ang()) & 2047) - 1024; - int height = (pDudeInfo->eyeHeight * actor->spr.yrepeat) << 2; - if (cansee(target->int_pos().X, target->int_pos().Y, target->int_pos().Z, target->sector(), actor->int_pos().X, actor->int_pos().Y, actor->int_pos().Z - height, actor->sector())) + double height = (pDudeInfo->eyeHeight * actor->spr.yrepeat) * REPEAT_SCALE; + if (cansee(target->spr.pos, target->sector(), actor->spr.pos.plusZ(-height), actor->sector())) { if (nDist < pDudeInfo->seeDist && abs(nDeltaAngle) <= pDudeInfo->periphery) { aiSetTarget(actor, actor->GetTarget()); diff --git a/source/games/blood/src/aicult.cpp b/source/games/blood/src/aicult.cpp index cbefe74fb..00da45ecc 100644 --- a/source/games/blood/src/aicult.cpp +++ b/source/games/blood/src/aicult.cpp @@ -274,8 +274,8 @@ static void cultThinkChase(DBloodActor* actor) if (nDist > 0 && nDist <= pDudeInfo->seeDist) { int nDeltaAngle = ((getangle(dx, dy) + 1024 - actor->int_ang()) & 2047) - 1024; - int height = (pDudeInfo->eyeHeight * actor->spr.yrepeat) << 2; - if (cansee(target->int_pos().X, target->int_pos().Y, target->int_pos().Z, target->sector(), actor->int_pos().X, actor->int_pos().Y, actor->int_pos().Z - height, actor->sector())) + double height = (pDudeInfo->eyeHeight * actor->spr.yrepeat) * REPEAT_SCALE; + if (cansee(target->spr.pos, target->sector(), actor->spr.pos.plusZ(-height), actor->sector())) { if (nDist < pDudeInfo->seeDist && abs(nDeltaAngle) <= pDudeInfo->periphery) { diff --git a/source/games/blood/src/aigarg.cpp b/source/games/blood/src/aigarg.cpp index aea10ff83..75156bc58 100644 --- a/source/games/blood/src/aigarg.cpp +++ b/source/games/blood/src/aigarg.cpp @@ -218,6 +218,7 @@ static void gargThinkTarget(DBloodActor* actor) PLAYER* pPlayer = &gPlayer[p]; if (pPlayer->actor->xspr.health == 0 || powerupCheck(pPlayer, kPwUpShadowCloak) > 0) continue; + auto ppos = pPlayer->actor->spr.pos; int x = pPlayer->actor->int_pos().X; int y = pPlayer->actor->int_pos().Y; int z = pPlayer->actor->int_pos().Z; @@ -227,7 +228,8 @@ static void gargThinkTarget(DBloodActor* actor) int nDist = approxDist(dx, dy); if (nDist > pDudeInfo->seeDist && nDist > pDudeInfo->hearDist) continue; - if (!cansee(x, y, z, pSector, actor->int_pos().X, actor->int_pos().Y, actor->int_pos().Z - ((pDudeInfo->eyeHeight * actor->spr.yrepeat) << 2), actor->sector())) + double height = (pDudeInfo->eyeHeight * actor->spr.yrepeat) * REPEAT_SCALE; + if (!cansee(ppos, pSector, actor->spr.pos.plusZ(-height), actor->sector())) continue; int nDeltaAngle = ((getangle(dx, dy) + 1024 - actor->int_ang()) & 2047) - 1024; if (nDist < pDudeInfo->seeDist && abs(nDeltaAngle) <= pDudeInfo->periphery) @@ -363,7 +365,7 @@ static void gargThinkChase(DBloodActor* actor) int height2 = (pDudeInfo->eyeHeight * target->spr.yrepeat) << 2; int top, bottom; GetActorExtents(actor, &top, &bottom); - if (cansee(target->int_pos().X, target->int_pos().Y, target->int_pos().Z, target->sector(), actor->int_pos().X, actor->int_pos().Y, actor->int_pos().Z - height, actor->sector())) + if (cansee(target->spr.pos, target->sector(), actor->spr.pos.plusZ(-height * zinttoworld), actor->sector())) { if (nDist < pDudeInfo->seeDist && abs(nDeltaAngle) <= pDudeInfo->periphery) { diff --git a/source/games/blood/src/aighost.cpp b/source/games/blood/src/aighost.cpp index 27707f71e..1fb49f9d8 100644 --- a/source/games/blood/src/aighost.cpp +++ b/source/games/blood/src/aighost.cpp @@ -198,6 +198,7 @@ static void ghostThinkTarget(DBloodActor* actor) PLAYER* pPlayer = &gPlayer[p]; if (pPlayer->actor->xspr.health == 0 || powerupCheck(pPlayer, kPwUpShadowCloak) > 0) continue; + auto ppos = pPlayer->actor->spr.pos; int x = pPlayer->actor->int_pos().X; int y = pPlayer->actor->int_pos().Y; int z = pPlayer->actor->int_pos().Z; @@ -207,7 +208,8 @@ static void ghostThinkTarget(DBloodActor* actor) int nDist = approxDist(dx, dy); if (nDist > pDudeInfo->seeDist && nDist > pDudeInfo->hearDist) continue; - if (!cansee(x, y, z, pSector, actor->int_pos().X, actor->int_pos().Y, actor->int_pos().Z - ((pDudeInfo->eyeHeight * actor->spr.yrepeat) << 2), actor->sector())) + double height = (pDudeInfo->eyeHeight * actor->spr.yrepeat) * REPEAT_SCALE; + if (!cansee(ppos, pSector, actor->spr.pos.plusZ(-height), actor->sector())) continue; int nDeltaAngle = ((getangle(dx, dy) + 1024 - actor->int_ang()) & 2047) - 1024; if (nDist < pDudeInfo->seeDist && abs(nDeltaAngle) <= pDudeInfo->periphery) @@ -342,7 +344,7 @@ static void ghostThinkChase(DBloodActor* actor) int height2 = (pDudeInfo->eyeHeight * target->spr.yrepeat) << 2; int top, bottom; GetActorExtents(actor, &top, &bottom); - if (cansee(target->int_pos().X, target->int_pos().Y, target->int_pos().Z, target->sector(), actor->int_pos().X, actor->int_pos().Y, actor->int_pos().Z - height, actor->sector())) + if (cansee(target->spr.pos, target->sector(), actor->spr.pos.plusZ(-height * zinttoworld), actor->sector())) { if (nDist < pDudeInfo->seeDist && abs(nDeltaAngle) <= pDudeInfo->periphery) { diff --git a/source/games/blood/src/aigilbst.cpp b/source/games/blood/src/aigilbst.cpp index 4f01b625d..f2f890cb9 100644 --- a/source/games/blood/src/aigilbst.cpp +++ b/source/games/blood/src/aigilbst.cpp @@ -140,8 +140,8 @@ static void gillThinkChase(DBloodActor* actor) if (nDist <= pDudeInfo->seeDist) { int nDeltaAngle = ((getangle(dx, dy) + 1024 - actor->int_ang()) & 2047) - 1024; - int height = (pDudeInfo->eyeHeight * actor->spr.yrepeat) << 2; - if (cansee(target->int_pos().X, target->int_pos().Y, target->int_pos().Z, target->sector(), actor->int_pos().X, actor->int_pos().Y, actor->int_pos().Z - height, actor->sector())) + double height = (pDudeInfo->eyeHeight * actor->spr.yrepeat) * REPEAT_SCALE; + if (cansee(target->spr.pos, target->sector(), actor->spr.pos.plusZ(-height), actor->sector())) { if (nDist < pDudeInfo->seeDist && abs(nDeltaAngle) <= pDudeInfo->periphery) { @@ -237,10 +237,10 @@ static void gillThinkSwimChase(DBloodActor* actor) if (nDist <= pDudeInfo->seeDist) { int nDeltaAngle = ((getangle(dx, dy) + 1024 - actor->int_ang()) & 2047) - 1024; - int height = pDudeInfo->eyeHeight + actor->int_pos().Z; + double height = (pDudeInfo->eyeHeight * actor->spr.yrepeat) * REPEAT_SCALE; int top, bottom; GetActorExtents(actor, &top, &bottom); - if (cansee(target->int_pos().X, target->int_pos().Y, target->int_pos().Z, target->sector(), actor->int_pos().X, actor->int_pos().Y, actor->int_pos().Z - height, actor->sector())) + if (cansee(target->spr.pos, target->sector(), actor->spr.pos.plusZ(-height), actor->sector())) { if (nDist < pDudeInfo->seeDist && abs(nDeltaAngle) <= pDudeInfo->periphery) {