Tweak lift and welder usage

This commit is contained in:
RGreenlees 2023-11-26 23:11:47 +00:00 committed by pierow
parent 39f183864c
commit af54f6816b
4 changed files with 56 additions and 6 deletions

View file

@ -58,6 +58,28 @@ bool vBBOverlaps2D(const Vector MinBBA, const Vector MaxBBA, const Vector MinBBB
&& (MinBBA.y < MaxBBB.y && MaxBBA.y > MinBBB.y));
}
Vector vClosestPointOnBB(const Vector Point, const Vector MinBB, const Vector MaxBB)
{
return Vector(clampf(Point.x, MinBB.x, MaxBB.x), clampf(Point.y, MinBB.y, MaxBB.y), clampf(Point.z, MinBB.z, MaxBB.z));
}
void vScaleBB(Vector& MinBB, Vector& MaxBB, const float Scale)
{
Vector Centre = MinBB + ((MaxBB - MinBB) * 0.5f);
float SizeX = MaxBB.x - MinBB.x;
float SizeY = MaxBB.y - MinBB.y;
float SizeZ = MaxBB.z - MinBB.z;
MinBB.x = Centre.x - (SizeX * Scale);
MinBB.y = Centre.y - (SizeY * Scale);
MinBB.z = Centre.z - (SizeZ * Scale);
MaxBB.x = Centre.x + (SizeX * Scale);
MaxBB.y = Centre.y + (SizeY * Scale);
MaxBB.z = Centre.z + (SizeZ * Scale);
}
// Returns the 3D distance of point from a line defined between lineFrom and lineTo
float vDistanceFromLine3D(const Vector lineFrom, const Vector lineTo, const Vector CheckPoint)
{

View file

@ -118,6 +118,10 @@ Vector UTIL_GetSurfaceNormal(const Vector v1, const Vector v2, const Vector v3);
bool vPointOverlaps2D(const Vector Point, const Vector MinBB, const Vector MaxBB);
bool vBBOverlaps2D(const Vector MinBBA, const Vector MaxBBA, const Vector MinBBB, const Vector MaxBBB);
Vector vClosestPointOnBB(const Vector Point, const Vector MinBB, const Vector MaxBB);
void vScaleBB(Vector& MinBB, Vector& MaxBB, const float Scale);
// WIP: Trying to get a working random unit vector in cone. Not currently used
Vector UTIL_GetRandomUnitVectorInCone(const Vector ConeDirection, const float HalfAngleRadians);
Vector random_unit_vector_within_cone(const Vector Direction, double HalfAngleRadians);

View file

@ -3546,7 +3546,19 @@ void LiftMove(AvHAIPlayer* pBot, const Vector StartPoint, const Vector EndPoint)
bool bWaitingToEmbark = (!bIsOnLift && vDist3DSq(pBot->Edict->v.origin, StartPoint) < vDist3DSq(pBot->Edict->v.origin, EndPoint)) || (bIsOnLift && !bIsLiftMoving && bIsLiftAtOrNearStart);
// Do nothing if we're on a moving lift
if (bIsLiftMoving && bIsOnLift) { return; }
if (bIsLiftMoving && bIsOnLift)
{
Vector LiftEdge = UTIL_GetClosestPointOnEntityToLocation(StartPoint, NearestLift->DoorEdict);
bool bFullyOnLift = vDist2DSq(pBot->Edict->v.origin, LiftEdge) > (sqrf(GetPlayerRadius(pBot->Player) * 1.1f));
if (!bFullyOnLift)
{
pBot->desiredMovementDir = UTIL_GetVectorNormal2D(LiftPosition - StartPoint);
}
return;
}
// if we've reached our stop, or we can directly get to the end point. Move straight there
@ -3657,7 +3669,16 @@ void LiftMove(AvHAIPlayer* pBot, const Vector StartPoint, const Vector EndPoint)
}
else
{
if (!bIsOnLift && bIsLiftAtOrNearStart)
bool bFullyOnLift = false;
if (bIsOnLift)
{
Vector LiftEdge = UTIL_GetClosestPointOnEntityToLocation(StartPoint, NearestLift->DoorEdict);
bFullyOnLift = vDist2DSq(pBot->Edict->v.origin, LiftEdge) > (sqrf(GetPlayerRadius(pBot->Player) * 1.1f) );
}
if (bIsLiftAtOrNearStart && (!bIsOnLift || !bFullyOnLift) )
{
pBot->desiredMovementDir = UTIL_GetVectorNormal2D(LiftPosition - StartPoint);
}
@ -3684,13 +3705,11 @@ void LiftMove(AvHAIPlayer* pBot, const Vector StartPoint, const Vector EndPoint)
if (!bIsOnLift)
{
pBot->desiredMovementDir = UTIL_GetVectorNormal2D(LiftPosition - pBot->Edict->v.origin);
UTIL_DrawLine(INDEXENT(1), pBot->Edict->v.origin, ButtonFloorLocation, 255, 0, 0);
return;
}
else
{
pBot->desiredMovementDir = UTIL_GetVectorNormal2D(ButtonFloorLocation - pBot->Edict->v.origin);
UTIL_DrawLine(INDEXENT(1), pBot->Edict->v.origin, ButtonFloorLocation, 255, 255, 0);
return;
}
}
@ -6925,7 +6944,7 @@ bool UTIL_IsTriggerLinkedToDoor(CBaseEntity* TriggerEntity, CBaseEntity* Door)
CBaseEntity* TargetEntity = UTIL_FindEntityByTargetname(NULL, STRING(ToggleRef->pev->target));
// Don't check this if it's targeting us (circular reference)
if (!FStrEq(STRING(TargetEntity->pev->target), STRING(TriggerEntity->pev->targetname)))
if (TargetEntity && !FStrEq(STRING(TargetEntity->pev->target), STRING(TriggerEntity->pev->targetname)))
{
if (TargetEntity && UTIL_IsTriggerLinkedToDoor(TargetEntity, Door)) { return true; }
}

View file

@ -2273,7 +2273,12 @@ void BotProgressWeldTask(AvHAIPlayer* pBot, AvHAIPlayerTask* Task)
if (IsPlayerInUseRange(pBot->Edict, Task->TaskTarget))
{
BotLookAt(pBot, UTIL_GetClosestPointOnEntityToLocation(pBot->Edict->v.origin, Task->TaskTarget));
Vector BBMin = Task->TaskTarget->v.absmin;
Vector BBMax = Task->TaskTarget->v.absmax;
vScaleBB(BBMin, BBMax, 0.75f);
BotLookAt(pBot, vClosestPointOnBB(pBot->CurrentEyePosition, BBMin, BBMax));
pBot->DesiredCombatWeapon = WEAPON_MARINE_WELDER;
if (GetBotCurrentWeapon(pBot) != WEAPON_MARINE_WELDER)