mirror of
https://github.com/ZDoom/Raze.git
synced 2025-03-13 04:24:39 +00:00
- floatified most of aiPatrolSearchTargets
This commit is contained in:
parent
769565997f
commit
b7afaf3ed5
1 changed files with 44 additions and 47 deletions
|
@ -36,8 +36,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
BEGIN_BLD_NS
|
BEGIN_BLD_NS
|
||||||
|
|
||||||
inline int mulscale8(int a, int b) { return MulScale(a, b, 8); }
|
|
||||||
|
|
||||||
bool gAllowTrueRandom = false;
|
bool gAllowTrueRandom = false;
|
||||||
bool gEventRedirectsUsed = false;
|
bool gEventRedirectsUsed = false;
|
||||||
|
|
||||||
|
@ -8388,10 +8386,10 @@ bool readyForCrit(DBloodActor* hunter, DBloodActor* victim)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
auto dvect = victim->spr.pos.XY() - hunter->spr.pos.XY();
|
auto dvect = victim->spr.pos.XY() - hunter->spr.pos.XY();
|
||||||
if (approxDist(dvect) >= (7000 / ClipLow(gGameOptions.nDifficulty >> 1, 1)))
|
if (dvect.Length() >= (437.5 / max(gGameOptions.nDifficulty >> 1, 1)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return abs(getincangle(victim->int_ang(), getangle(dvect))) <= kAng45;
|
return absangle(victim->spr.angle, VecToAngle(dvect)) <= DAngle45;
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
@ -8414,7 +8412,7 @@ DBloodActor* aiPatrolSearchTargets(DBloodActor* actor)
|
||||||
patrolBonkles[i].max = ClipLow((gGameOptions.nDifficulty + 1) >> 1, 1);
|
patrolBonkles[i].max = ClipLow((gGameOptions.nDifficulty + 1) >> 1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int i, j, f, mod, x, y, z, dx, dy, nDist, eyeAboveZ, sndCnt = 0, seeDist, hearDist, feelDist, seeChance, hearChance;
|
int i, j, mod, sndCnt = 0, seeChance, hearChance;
|
||||||
bool stealth = (actor->xspr.unused1 & kDudeFlagStealth);
|
bool stealth = (actor->xspr.unused1 & kDudeFlagStealth);
|
||||||
bool blind = (actor->xspr.dudeGuard);
|
bool blind = (actor->xspr.dudeGuard);
|
||||||
bool deaf = (actor->xspr.dudeDeaf);
|
bool deaf = (actor->xspr.dudeDeaf);
|
||||||
|
@ -8432,20 +8430,22 @@ DBloodActor* aiPatrolSearchTargets(DBloodActor* actor)
|
||||||
|
|
||||||
newtarget = nullptr;
|
newtarget = nullptr;
|
||||||
seeChance = hearChance = 0x0000;
|
seeChance = hearChance = 0x0000;
|
||||||
x = plActor->int_pos().X, y = plActor->int_pos().Y, z = plActor->int_pos().Z,
|
auto pos = plActor->spr.pos;
|
||||||
dx = x - actor->int_pos().X, dy = y - actor->int_pos().Y;
|
auto dv = pos.XY() - actor->spr.pos.XY();
|
||||||
nDist = approxDist(dx, dy);
|
double nDistf = dv.Length();
|
||||||
seeDist = (stealth) ? pDudeInfo->seeDist / 3 : pDudeInfo->seeDist >> 1;
|
double seeDistf = (stealth) ? pDudeInfo->SeeDist() / 3 : pDudeInfo->SeeDist() / 4;
|
||||||
hearDist = pDudeInfo->hearDist; feelDist = hearDist >> 1;
|
double hearDistf = pDudeInfo->Heardist();
|
||||||
|
double feelDistf = hearDistf / 2;
|
||||||
|
|
||||||
// TO-DO: is there any dudes that sees this patrol dude and sees target?
|
// TO-DO: is there any dudes that sees this patrol dude and sees target?
|
||||||
|
|
||||||
|
|
||||||
if (nDist <= seeDist)
|
if (nDistf <= seeDistf)
|
||||||
{
|
{
|
||||||
eyeAboveZ = (pDudeInfo->eyeHeight * actor->spr.yrepeat) << 2;
|
double scratch;
|
||||||
if (nDist < seeDist >> 3) GetActorExtents(pPlayer->actor, &z, &j); //use ztop of the target sprite
|
double eyeAboveZ = (pDudeInfo->eyeHeight * actor->spr.yrepeat) * REPEAT_SCALE;
|
||||||
if (!cansee(x, y, z, plActor->sector(), actor->int_pos().X, actor->int_pos().Y, actor->int_pos().Z - eyeAboveZ, actor->sector()))
|
if (nDistf < seeDistf / 8) GetActorExtents(pPlayer->actor, &pos.Z, &scratch); //use ztop of the target sprite
|
||||||
|
if (!cansee(pos, plActor->sector(), actor->spr.pos - eyeAboveZ, actor->sector()))
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -8465,14 +8465,13 @@ DBloodActor* aiPatrolSearchTargets(DBloodActor* actor)
|
||||||
|
|
||||||
soundEngine->EnumerateChannels([&](FSoundChan* chan)
|
soundEngine->EnumerateChannels([&](FSoundChan* chan)
|
||||||
{
|
{
|
||||||
int sndx = 0, sndy = 0;
|
DVector2 sndv;
|
||||||
sectortype* searchsect = nullptr;
|
sectortype* searchsect = nullptr;
|
||||||
if (chan->SourceType == SOURCE_Actor)
|
if (chan->SourceType == SOURCE_Actor)
|
||||||
{
|
{
|
||||||
auto emitterActor = (DBloodActor*)chan->Source;
|
auto emitterActor = (DBloodActor*)chan->Source;
|
||||||
if (emitterActor == nullptr) return false; // not a valid source.
|
if (emitterActor == nullptr) return false; // not a valid source.
|
||||||
sndx = emitterActor->int_pos().X;
|
sndv = emitterActor->spr.pos.XY();
|
||||||
sndy = emitterActor->int_pos().Y;
|
|
||||||
|
|
||||||
// sound attached to the sprite
|
// sound attached to the sprite
|
||||||
if (pPlayer->actor != emitterActor && emitterActor->GetOwner() != actor)
|
if (pPlayer->actor != emitterActor && emitterActor->GetOwner() != actor)
|
||||||
|
@ -8485,13 +8484,13 @@ DBloodActor* aiPatrolSearchTargets(DBloodActor* actor)
|
||||||
else if (chan->SourceType == SOURCE_Unattached)
|
else if (chan->SourceType == SOURCE_Unattached)
|
||||||
{
|
{
|
||||||
if (chan->UserData < 0 || !validSectorIndex(chan->UserData)) return false; // not a vaild sector sound.
|
if (chan->UserData < 0 || !validSectorIndex(chan->UserData)) return false; // not a vaild sector sound.
|
||||||
sndx = int(chan->Point[0] * 16);
|
sndv.X = chan->Point[0];
|
||||||
sndy = int(chan->Point[1] * -16);
|
sndv.Y = -chan->Point[1];
|
||||||
searchsect = §or[chan->UserData];
|
searchsect = §or[chan->UserData];
|
||||||
}
|
}
|
||||||
if (searchsect == nullptr) return false;
|
if (searchsect == nullptr) return false;
|
||||||
int nDist = approxDist(sndx - actor->int_pos().X, sndy - actor->int_pos().Y);
|
double nsDist = (sndv - actor->spr.pos.XY()).Length();
|
||||||
if (nDist > hearDist) return false;
|
if (nsDist > hearDistf) return false;
|
||||||
|
|
||||||
|
|
||||||
int sndnum = chan->OrgID;
|
int sndnum = chan->OrgID;
|
||||||
|
@ -8518,9 +8517,9 @@ DBloodActor* aiPatrolSearchTargets(DBloodActor* actor)
|
||||||
}
|
}
|
||||||
if (!found) return false;
|
if (!found) return false;
|
||||||
|
|
||||||
f = ClipLow((hearDist - nDist) / 8, 0);
|
int f = max(int((hearDistf - nsDist) * 16), 0);
|
||||||
int sndvol = int(chan->Volume * (80.f / 0.8f));
|
int sndvol = int(chan->Volume * (80.f / 0.8f));
|
||||||
hearChance += mulscale8(sndvol, f) + Random(gGameOptions.nDifficulty);
|
hearChance += sndvol * f + Random(gGameOptions.nDifficulty);
|
||||||
return (hearChance >= kMaxPatrolSpotValue);
|
return (hearChance >= kMaxPatrolSpotValue);
|
||||||
});
|
});
|
||||||
/*
|
/*
|
||||||
|
@ -8544,58 +8543,56 @@ DBloodActor* aiPatrolSearchTargets(DBloodActor* actor)
|
||||||
case kModeHumanShrink:
|
case kModeHumanShrink:
|
||||||
if (pPlayer->lifeMode == kModeHumanShrink)
|
if (pPlayer->lifeMode == kModeHumanShrink)
|
||||||
{
|
{
|
||||||
seeDist -= mulscale8(164, seeDist);
|
seeDistf *= 92. / 256;
|
||||||
feelDist -= mulscale8(164, feelDist);
|
feelDistf *= 92. / 256;
|
||||||
}
|
}
|
||||||
if (pPlayer->posture == kPostureCrouch)
|
if (pPlayer->posture == kPostureCrouch)
|
||||||
{
|
{
|
||||||
seeDist -= mulscale8(64, seeDist);
|
seeDistf *= 0.75;
|
||||||
feelDist -= mulscale8(128, feelDist);
|
feelDistf *= 0.5;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case kModeHumanGrown:
|
case kModeHumanGrown:
|
||||||
if (pPlayer->posture != kPostureCrouch)
|
if (pPlayer->posture != kPostureCrouch)
|
||||||
{
|
{
|
||||||
seeDist += mulscale8(72, seeDist);
|
seeDistf *= 328. / 256;
|
||||||
feelDist += mulscale8(64, feelDist);
|
feelDistf *= 320. / 256;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
seeDist += mulscale8(48, seeDist);
|
seeDistf *= 304. / 256;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool itCanHear = false; bool itCanSee = false;
|
bool itCanHear = false;
|
||||||
feelDist = ClipLow(feelDist, 0);
|
bool itCanSee = false;
|
||||||
seeDist = ClipLow(seeDist, 0);
|
feelDistf = max(feelDistf, 0.);
|
||||||
|
seeDistf = max(seeDistf, 0.);
|
||||||
|
|
||||||
if (hearDist)
|
if (hearDistf)
|
||||||
{
|
{
|
||||||
DBloodActor* act = pPlayer->actor;
|
DBloodActor* act = pPlayer->actor;
|
||||||
itCanHear = (!deaf && (nDist < hearDist || hearChance > 0));
|
itCanHear = (!deaf && (nDistf < hearDistf || hearChance > 0));
|
||||||
if (act && itCanHear && nDist < feelDist && (act->vel.X != 0 || act->vel.Y != 0 || act->int_vel().Z))
|
if (act && itCanHear && nDistf < feelDistf && (!act->vel.isZero()))
|
||||||
hearChance += ClipLow(mulscale8(1, ClipLow(((feelDist - nDist) + (abs(act->int_vel().X) + abs(act->int_vel().Y) + abs(act->int_vel().Z))) >> 6, 0)), 0);
|
hearChance += (int)max(((feelDistf - nDistf) + act->vel.Sum() * 64, 0.) / 256, 0.);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (seeDist)
|
if (seeDistf)
|
||||||
{
|
{
|
||||||
int periphery = ClipLow(pDudeInfo->periphery, kAng60);
|
DAngle periphery = max(pDudeInfo->Periphery(), DAngle60);
|
||||||
int nDeltaAngle = abs(getincangle(actor->int_ang(), getangle(dx, dy)));
|
DAngle nDeltaAngle = absangle(actor->spr.angle, VecToAngle(dv));
|
||||||
if ((itCanSee = (!blind && nDist < seeDist && nDeltaAngle < periphery)) == true)
|
if ((itCanSee = (!blind && nDistf < seeDistf && nDeltaAngle < periphery)) == true)
|
||||||
{
|
{
|
||||||
int base = 100 + ((20 * gGameOptions.nDifficulty) - (nDeltaAngle / 5));
|
int base = 100 + ((20 * gGameOptions.nDifficulty) - (nDeltaAngle.Buildang() / 5));
|
||||||
//seeChance = base - MulScale(ClipRange(5 - gGameOptions.nDifficulty, 1, 4), nDist >> 1, 16);
|
//seeChance = base - MulScale(ClipRange(5 - gGameOptions.nDifficulty, 1, 4), nDist >> 1, 16);
|
||||||
//scale(0x40000, a6, dist2);
|
//scale(0x40000, a6, dist2);
|
||||||
int d = nDist >> 2;
|
int d = int(nDistf * 4);
|
||||||
int m = DivScale(d, 0x2000, 8);
|
int m = DivScale(d, 0x2000, 8);
|
||||||
int t = MulScale(d, m, 8);
|
int t = MulScale(d, m, 8);
|
||||||
//int n = mulscale8(nDeltaAngle >> 2, 64);
|
|
||||||
seeChance = ClipRange(DivScale(base, t, 8), 0, kMaxPatrolSpotValue >> 1);
|
seeChance = ClipRange(DivScale(base, t, 8), 0, kMaxPatrolSpotValue >> 1);
|
||||||
//seeChance = scale(0x1000, base, t);
|
|
||||||
//viewSetSystemMessage("SEE CHANCE: %d, BASE %d, DIST %d, T %d", seeChance, base, nDist, t);
|
|
||||||
//itCanSee = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue