- fixed AICharacters being updated even if they're disabled

- enemies can spot targets from further away if they've previously spotted the target
- physics bodies are immediately moved to the correct position if they're really far (instead of lerping)
This commit is contained in:
Regalis
2016-03-13 19:24:30 +02:00
parent d713874bd6
commit 5120812adf
9 changed files with 23 additions and 20 deletions
+1 -1
View File
@@ -11,7 +11,7 @@ namespace Barotrauma
public static List<AITarget> List = new List<AITarget>();
public Entity Entity;
public readonly Entity Entity;
private float soundRange;
private float sightRange;
@@ -438,7 +438,7 @@ namespace Barotrauma
valueModifier = attackHumans;
}
else if (target.Entity!=null && attackRooms!=0.0f)
else if (target.Entity!=null && attackRooms != 0.0f)
{
//skip the target if it's the room the Character is inside of
if (character.AnimController.CurrentHull != null && character.AnimController.CurrentHull == target.Entity as Hull) continue;
@@ -450,12 +450,17 @@ namespace Barotrauma
character.WorldPosition,
target.WorldPosition);
//if the target has been within range earlier, the character will notice it more easily
//(i.e. remember where the target was)
if (targetMemories.ContainsKey(target)) dist *= 0.5f;
//ignore target if it's too far to see or hear
if (dist > target.SightRange * sight && dist > target.SoundRange * hearing) continue;
AITargetMemory targetMemory = FindTargetMemory(target);
valueModifier = valueModifier * targetMemory.Priority / dist;
//dist -= targetMemory.Priority;
if (Math.Abs(valueModifier) > Math.Abs(targetValue) && (dist < target.SightRange * sight || dist < target.SoundRange * hearing))
if (Math.Abs(valueModifier) > Math.Abs(targetValue))
{
Vector2 rayStart = character.AnimController.Limbs[0].SimPosition;
Vector2 rayEnd = target.SimPosition;
@@ -517,7 +522,7 @@ namespace Barotrauma
foreach(KeyValuePair<AITarget, AITargetMemory> memory in targetMemories)
{
memory.Value.Priority += 0.5f;
if (memory.Value.Priority == 0.0f || !AITarget.List.Contains(memory.Key)) toBeRemoved.Add(memory.Key);
if (Math.Abs(memory.Value.Priority) < 1.0f || !AITarget.List.Contains(memory.Key)) toBeRemoved.Add(memory.Key);
}
foreach (AITarget target in toBeRemoved)
@@ -33,6 +33,8 @@ namespace Barotrauma
public override void Update(Camera cam, float deltaTime)
{
if (!Enabled) return;
base.Update(cam, deltaTime);
float dist = Vector2.Distance(cam.WorldViewCenter, WorldPosition);
+3 -6
View File
@@ -417,11 +417,8 @@ namespace Barotrauma
new GUIMessageBox(commands[1], commands[2]);
break;
case "debugdraw":
//Hull.DebugDraw = !Hull.DebugDraw;
//Ragdoll.DebugDraw = !Ragdoll.DebugDraw;
GameMain.DebugDraw = !GameMain.DebugDraw;
break;
case "drawaitargets":
case "showaitargets":
AITarget.ShowAITargets = !AITarget.ShowAITargets;
@@ -429,11 +426,11 @@ namespace Barotrauma
case "sendrandomdata":
int messageCount = 1;
if (commands.Length>1) int.TryParse(commands[1], out messageCount);
if (commands.Length > 1) int.TryParse(commands[1], out messageCount);
for (int i = 0; i < messageCount; i++ )
for (int i = 0; i < messageCount; i++)
{
if (GameMain.Server!=null)
if (GameMain.Server != null)
{
GameMain.Server.SendRandomData();
}
@@ -200,7 +200,6 @@ namespace Barotrauma.Items.Components
if (limb.SimPosition == Vector2.Zero || pointDist > radius) continue;
if (pointDist > radius) continue;
if (pointDist > prevPingRadius && pointDist < pingRadius)
{
for (int i = 0; i<=limb.Mass/100.0f; i++)
+2 -2
View File
@@ -352,8 +352,8 @@ namespace Barotrauma
FireSource.UpdateAll(fireSources, deltaTime);
aiTarget.SightRange = Submarine == null ? 0.0f : Submarine.Velocity.Length() * 500.0f;
aiTarget.SoundRange -= deltaTime*1000.0f;
aiTarget.SightRange = Submarine == null ? 0.0f : Math.Max(Submarine.Velocity.Length() * 500.0f, 500.0f);
aiTarget.SoundRange -= deltaTime * 1000.0f;
float strongestFlow = 0.0f;
foreach (Gap gap in ConnectedGaps)
+1 -1
View File
@@ -307,7 +307,7 @@ namespace Barotrauma
return;
}
if (lerp)
if (lerp && Vector2.Distance(targetPosition, body.Position)<10.0f)
{
offsetFromTargetPos = targetPosition - (body.Position - offsetFromTargetPos);
prevPosition = targetPosition;