Update content vectors to numerics (#17759)

This commit is contained in:
metalgearsloth
2023-07-08 14:08:32 +10:00
committed by GitHub
parent 15772478c9
commit 68480af109
383 changed files with 978 additions and 575 deletions

View File

@@ -1,3 +1,4 @@
using System.Numerics;
using Content.Server.NPC.Components;
using Content.Server.NPC.Events;
using Content.Shared.CombatMode;
@@ -37,7 +38,7 @@ public sealed partial class NPCCombatSystem
var idealDistance = weapon.Range * 1.5f;
var obstacleDirection = pointB - args.WorldPosition;
var obstacleDistance = obstacleDirection.Length;
var obstacleDistance = obstacleDirection.Length();
if (obstacleDistance > idealDistance || obstacleDistance == 0f)
{
@@ -47,7 +48,7 @@ public sealed partial class NPCCombatSystem
args.Steering.CanSeek = false;
obstacleDirection = args.OffsetRotation.RotateVec(obstacleDirection);
var norm = obstacleDirection.Normalized;
var norm = obstacleDirection.Normalized();
var weight = (obstacleDistance <= args.AgentRadius
? 1f
@@ -163,7 +164,7 @@ public sealed partial class NPCCombatSystem
if (_random.Prob(component.MissChance) &&
physicsQuery.TryGetComponent(component.Target, out var targetPhysics) &&
targetPhysics.LinearVelocity.LengthSquared != 0f)
targetPhysics.LinearVelocity.LengthSquared() != 0f)
{
_melee.AttemptLightAttackMiss(uid, component.Weapon, weapon, targetXform.Coordinates.Offset(_random.NextVector2(0.5f)));
}

View File

@@ -1,3 +1,4 @@
using System.Numerics;
using Content.Server.NPC.Components;
using Content.Shared.CombatMode;
using Content.Shared.Interaction;
@@ -90,7 +91,7 @@ public sealed partial class NPCCombatSystem
var (targetPos, targetRot) = _transform.GetWorldPositionRotation(targetXform, xformQuery);
// We'll work out the projected spot of the target and shoot there instead of where they are.
var distance = (targetPos - worldPos).Length;
var distance = (targetPos - worldPos).Length();
var oldInLos = comp.TargetInLOS;
// TODO: Should be doing these raycasts in parallel

View File

@@ -1,4 +1,5 @@
using System.Linq;
using System.Numerics;
using Content.Server.Examine;
using Content.Server.NPC.Components;
using Content.Server.NPC.Pathfinding;
@@ -113,7 +114,7 @@ public sealed partial class NPCSteeringSystem
var direction = targetMap.Position - ourMap.Position;
// Are we in range
if (direction.Length <= arrivalDistance)
if (direction.Length() <= arrivalDistance)
{
// Node needs some kind of special handling like access or smashing.
if (steering.CurrentPath.TryPeek(out var node) && !node.Data.IsFreeSpace)
@@ -126,7 +127,7 @@ public sealed partial class NPCSteeringSystem
lock (_obstacles)
{
// We're still coming to a stop so wait for the do_after.
if (body.LinearVelocity.LengthSquared > 0.01f)
if (body.LinearVelocity.LengthSquared() > 0.01f)
{
return true;
}
@@ -231,21 +232,21 @@ public sealed partial class NPCSteeringSystem
return false;
}
var input = direction.Normalized;
var input = direction.Normalized();
var tickMovement = moveSpeed * frameTime;
// We have the input in world terms but need to convert it back to what movercontroller is doing.
input = offsetRot.RotateVec(input);
var norm = input.Normalized;
var weight = MapValue(direction.Length, tickMovement * 0.5f, tickMovement * 0.75f);
var norm = input.Normalized();
var weight = MapValue(direction.Length(), tickMovement * 0.5f, tickMovement * 0.75f);
ApplySeek(interest, norm, weight);
// Prefer our current direction
if (weight > 0f && body.LinearVelocity.LengthSquared > 0f)
if (weight > 0f && body.LinearVelocity.LengthSquared() > 0f)
{
const float sameDirectionWeight = 0.1f;
norm = body.LinearVelocity.Normalized;
norm = body.LinearVelocity.Normalized();
ApplySeek(interest, norm, sameDirectionWeight);
}
@@ -310,7 +311,7 @@ public sealed partial class NPCSteeringSystem
// Then don't consider pruning.
var goal = nodes.Last().Coordinates.ToMap(EntityManager, _transform);
var canPrune =
_interaction.InRangeUnobstructed(mapCoordinates, goal, (goal.Position - mapCoordinates.Position).Length + 0.1f, mask);
_interaction.InRangeUnobstructed(mapCoordinates, goal, (goal.Position - mapCoordinates.Position).Length() + 0.1f, mask);
while (nodes.TryPeek(out var node))
{
@@ -424,7 +425,7 @@ public sealed partial class NPCSteeringSystem
continue;
obstacleDirection = offsetRot.RotateVec(obstacleDirection);
var norm = obstacleDirection.Normalized;
var norm = obstacleDirection.Normalized();
for (var i = 0; i < InterestDirections; i++)
{
@@ -506,7 +507,7 @@ public sealed partial class NPCSteeringSystem
}
obstacleDirection = offsetRot.RotateVec(obstacleDirection);
var norm = obstacleDirection.Normalized;
var norm = obstacleDirection.Normalized();
weight *= 0.25f;
for (var i = 0; i < InterestDirections; i++)

View File

@@ -1,4 +1,5 @@
using System.Linq;
using System.Numerics;
using System.Threading;
using System.Threading.Tasks;
using Content.Server.Administration.Managers;