Limb collisions can damage hull again, new UI for steering, sonar & reactor, fabricators can require more than one of each ingredient, timer for character imploding, AICharacter position syncing changes, watcher, commands can also be given to controlled character

This commit is contained in:
Regalis
2016-01-13 22:19:01 +02:00
parent 5513637fe5
commit eb20af622d
23 changed files with 400 additions and 204 deletions
@@ -159,18 +159,11 @@ namespace Barotrauma
characterButton.UserData = character;
characterButton.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f);
if (character == Character.Controlled)
{
characterButton.CanBeSelected = false;
characterButton.Color = Color.LightGray * 0.3f;
}
else
{
characterButton.Color = Color.Black * 0.5f;
characterButton.HoverColor = Color.LightGray * 0.5f;
characterButton.SelectedColor = Color.Gold * 0.5f;
characterButton.OutlineColor = Color.LightGray * 0.8f;
}
characterButton.Color = Character.Controlled == character ? Color.Gold * 0.3f : Color.Black * 0.5f;
characterButton.HoverColor = Color.LightGray * 0.5f;
characterButton.SelectedColor = Color.Gold * 0.5f;
characterButton.OutlineColor = Color.LightGray * 0.8f;
string name = character.Info.Name;
if (character.Info.Job != null) name += '\n' + "(" + character.Info.Job.Name + ")";
@@ -16,6 +16,8 @@ namespace Barotrauma
private const float UpdateTargetsInterval = 5.0f;
private const float RaycastInterval = 1.0f;
private bool attackWhenProvoked;
//the preference to attack a specific type of target (-1.0 - 1.0)
//0.0 = doesn't attack targets of the type
@@ -84,6 +86,8 @@ namespace Barotrauma
sight = ToolBox.GetAttributeFloat(aiElement, "sight", 0.0f);
hearing = ToolBox.GetAttributeFloat(aiElement, "hearing", 0.0f);
attackWhenProvoked = ToolBox.GetAttributeBool(aiElement, "attackwhenprovoked", false);
steeringManager = new SteeringManager(this);
state = AiState.None;
@@ -286,6 +290,12 @@ namespace Barotrauma
updateTargetsTimer = Math.Min(updateTargetsTimer, 0.1f);
coolDownTimer *= 0.1f;
if (amount > 1.0f && attackWhenProvoked)
{
attackHumans = 100.0f;
attackRooms = 100.0f;
}
if (attacker==null || attacker.AiTarget==null) return;
AITargetMemory targetMemory = FindTargetMemory(attacker.AiTarget);
targetMemory.Priority += amount;
@@ -508,11 +518,13 @@ namespace Barotrauma
message.Write(wallAttack);
if (wallAttack)
{
message.WriteRangedSingle(MathHelper.Clamp(wallAttackPos.X, -50.0f, 50.0f), -50.0f, 50.0f, 10);
message.WriteRangedSingle(MathHelper.Clamp(wallAttackPos.Y, -50.0f, 50.0f), -50.0f, 50.0f, 10);
}
//if (wallAttack)
//{
// Vector2 relativeWallAttackPos = wallAttackPos - Submarine.Loaded.SimPosition;
// message.WriteRangedSingle(MathHelper.Clamp(relativeWallAttackPos.X, -50.0f, 50.0f), -50.0f, 50.0f, 10);
// message.WriteRangedSingle(MathHelper.Clamp(relativeWallAttackPos.Y, -50.0f, 50.0f), -50.0f, 50.0f, 10);
//}
//message.Write(Velocity.X);
//message.Write(Velocity.Y);
@@ -542,14 +554,16 @@ namespace Barotrauma
newState = (AiState)(message.ReadByte());
bool wallAttack = message.ReadBoolean();
//bool wallAttack = message.ReadBoolean();
if (wallAttack)
{
newWallAttackPos = new Vector2(
message.ReadRangedSingle(-50.0f, 50.0f, 10),
message.ReadRangedSingle(-50.0f, 50.0f, 10));
}
//if (wallAttack)
//{
// newWallAttackPos = new Vector2(
// message.ReadRangedSingle(-50.0f, 50.0f, 10),
// message.ReadRangedSingle(-50.0f, 50.0f, 10));
// newWallAttackPos += Submarine.Loaded.SimPosition;
//}
//newVelocity = new Vector2(message.ReadFloat(), message.ReadFloat());
@@ -565,7 +579,7 @@ namespace Barotrauma
catch { return; }
wallAttackPos = newWallAttackPos;
//wallAttackPos = newWallAttackPos;
steeringManager.WanderAngle = wanderAngle;
//this.updateTargetsTimer = updateTargetsTimer;
+21 -4
View File
@@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FarseerPhysics;
namespace Barotrauma
{
@@ -108,7 +109,9 @@ namespace Barotrauma
message.Write(AnimController.TargetDir == Direction.Right);
message.WriteRangedSingle(MathHelper.Clamp(AnimController.TargetMovement.X, -1.0f, 1.0f), -1.0f, 1.0f, 8);
message.WriteRangedSingle(MathHelper.Clamp(AnimController.TargetMovement.X, -1.0f, 1.0f), -1.0f, 1.0f, 8);
message.Write(Submarine != null);
message.Write(AnimController.RefLimb.SimPosition.X);
message.Write(AnimController.RefLimb.SimPosition.Y);
@@ -177,6 +180,8 @@ namespace Barotrauma
if (sendingTime <= LastNetworkUpdate) return;
bool inSub = false;
Vector2 pos = Vector2.Zero, vel = Vector2.Zero;
try
@@ -185,6 +190,8 @@ namespace Barotrauma
targetMovement.X = message.ReadRangedSingle(-1.0f, 1.0f, 8);
targetMovement.Y = message.ReadRangedSingle(-1.0f, 1.0f, 8);
inSub = message.ReadBoolean();
pos.X = message.ReadFloat();
pos.Y = message.ReadFloat();
@@ -199,9 +206,19 @@ namespace Barotrauma
AnimController.TargetDir = (targetDir) ? Direction.Right : Direction.Left;
AnimController.TargetMovement = targetMovement;
AnimController.RefLimb.body.TargetPosition = pos;
AnimController.RefLimb.body.TargetVelocity = vel;
AnimController.TargetMovement = AnimController.EstimateCurrPosition(pos, (float)(NetTime.Now) - sendingTime);
if (inSub)
{
Hull newHull = Hull.FindHull(ConvertUnits.ToDisplayUnits(pos), AnimController.CurrentHull, false);
if (newHull != null)
{
AnimController.CurrentHull = newHull;
Submarine = newHull.Submarine;
}
}
LastNetworkUpdate = sendingTime;
return;
@@ -88,11 +88,11 @@ namespace Barotrauma
if (flip)
{
//targetDir = (movement.X > 0.0f) ? Direction.Right : Direction.Left;
if (movement.X > 0.1f && movement.X > Math.Abs(movement.Y)*0.5f)
if (targetMovement.X > 0.1f && targetMovement.X > Math.Abs(targetMovement.Y) * 0.5f)
{
TargetDir = Direction.Right;
}
else if (movement.X < -0.1f && movement.X < -Math.Abs(movement.Y)*0.5f)
else if (targetMovement.X < -0.1f && targetMovement.X < -Math.Abs(targetMovement.Y) * 0.5f)
{
TargetDir = Direction.Left;
}
@@ -191,7 +191,7 @@ namespace Barotrauma
for (int i = 0; i < Limbs.Count(); i++)
{
if (steerForce!=Vector2.Zero)
if (steerForce != Vector2.Zero)
Limbs[i].body.ApplyForce(steerForce * Limbs[i].SteerForce * Limbs[i].Mass);
if (Limbs[i].type != LimbType.Torso) continue;
@@ -369,7 +369,7 @@ namespace Barotrauma
}
}
}
void UpdateDying(float deltaTime)
{
Limb head = GetLimb(LimbType.Head);
@@ -403,20 +403,29 @@ namespace Barotrauma
}
}
public override Vector2 EstimateCurrPosition(Vector2 prevPosition, float timePassed)
{
timePassed = MathHelper.Clamp(timePassed, 0.0f, 1.0f);
Vector2 currPosition = prevPosition + targetMovement * timePassed;
return currPosition;
}
private void Mirror()
{
float leftX = Limbs[0].SimPosition.X, rightX = Limbs[0].SimPosition.X;
for (int i = 1; i < Limbs.Count(); i++ )
{
if (Limbs[i].SimPosition.X < leftX)
{
leftX = Limbs[i].SimPosition.X;
}
else if (Limbs[i].SimPosition.X > rightX)
{
rightX = Limbs[i].SimPosition.X;
}
}
//float leftX = Limbs[0].SimPosition.X, rightX = Limbs[0].SimPosition.X;
//for (int i = 1; i < Limbs.Count(); i++ )
//{
// if (Limbs[i].SimPosition.X < leftX)
// {
// leftX = Limbs[i].SimPosition.X;
// }
// else if (Limbs[i].SimPosition.X > rightX)
// {
// rightX = Limbs[i].SimPosition.X;
// }
//}
float midX = GetCenterOfMass().X;
@@ -424,7 +433,7 @@ namespace Barotrauma
{
Vector2 newPos = new Vector2(midX - (l.SimPosition.X - midX), l.SimPosition.Y);
if (Submarine.CheckVisibility(l.SimPosition, newPos)!=null)
if (Submarine.CheckVisibility(l.SimPosition, newPos) != null)
{
Vector2 diff = newPos - l.SimPosition;
@@ -38,7 +38,7 @@ namespace Barotrauma
//the movement speed of the ragdoll
public Vector2 movement;
//the target speed towards which movement is interpolated
private Vector2 targetMovement;
protected Vector2 targetMovement;
//a movement vector that overrides targetmovement if trying to steer
//a Character to the position sent by server in multiplayer mode
@@ -782,15 +782,24 @@ namespace Barotrauma
{
if (inWater)
{
//foreach (Limb limb in Limbs)
//{
// //if (limb.body.TargetPosition == Vector2.Zero) continue;
// limb.body.SetTransform(limb.SimPosition + Vector2.Normalize(diff) * 0.1f, limb.Rotation);
//}
correctionMovement =
Vector2.Lerp(targetMovement, Vector2.Normalize(diff) * MathHelper.Clamp(dist * 8.0f, 0.1f, 8.0f), 0.2f);
if (character is AICharacter)
{
correctionMovement =
Vector2.Lerp(targetMovement, Vector2.Normalize(diff) * MathHelper.Clamp(dist * 8.0f, 0.1f, 8.0f), 0.5f);
}
else
{
foreach (Limb limb in Limbs)
{
//if (limb.body.TargetPosition == Vector2.Zero) continue;
limb.body.SetTransform(limb.SimPosition + Vector2.Normalize(diff) * 0.1f, limb.Rotation);
}
}
}
else
{
@@ -809,7 +818,7 @@ namespace Barotrauma
SetPosition(refLimb.body.TargetPosition);
if (character is AICharacter) SetRotation(refLimb.body.TargetRotation);
//if (character is AICharacter) SetRotation(refLimb.body.TargetRotation);
//foreach (Limb limb in Limbs)
//{
+41 -5
View File
@@ -32,10 +32,23 @@ namespace Barotrauma
set { controlled = value; }
}
private bool enabled;
public bool Enabled
{
get;
set;
get
{
return enabled;
}
set
{
enabled = value;
foreach (Limb limb in AnimController.Limbs)
{
limb.body.Enabled = enabled;
}
}
}
public readonly bool IsNetworkPlayer;
@@ -239,6 +252,13 @@ namespace Barotrauma
}
}
public float PressureTimer
{
get;
private set;
}
public float SpeedMultiplier
{
get;
@@ -652,6 +672,9 @@ namespace Barotrauma
private Item FindClosestItem(Vector2 mouseSimPos)
{
Limb torso = AnimController.GetLimb(LimbType.Torso);
if (torso == null) return null;
Vector2 pos = (torso.body.TargetPosition != Vector2.Zero) ? torso.body.TargetPosition : torso.SimPosition;
return Item.FindPickable(pos, selectedConstruction == null ? mouseSimPos : selectedConstruction.SimPosition, AnimController.CurrentHull, selectedItems);
@@ -885,8 +908,19 @@ namespace Barotrauma
if (!protectedFromPressure &&
(AnimController.CurrentHull == null || AnimController.CurrentHull.LethalPressure >= 100.0f))
{
Implode();
return;
PressureTimer += ((AnimController.CurrentHull == null) ?
100.0f : AnimController.CurrentHull.LethalPressure) * deltaTime;
if (PressureTimer >= 100.0f)
{
Implode();
return;
}
}
else
{
PressureTimer = 0.0f;
}
}
@@ -1503,10 +1537,12 @@ namespace Barotrauma
else
{
cursorPosition = Position + new Vector2(1000.0f, 0.0f) * dir;
AnimController.TargetDir = dir < 0 ? Direction.Left : Direction.Right;
}
AnimController.RefLimb.body.TargetPosition =
AnimController.EstimateCurrPosition(pos, (float)(NetTime.Now + message.SenderConnection.RemoteTimeOffset) - sendingTime);
AnimController.EstimateCurrPosition(pos, (float)(NetTime.Now) - sendingTime);
LastNetworkUpdate = sendingTime;
+1 -6
View File
@@ -14,8 +14,6 @@ namespace Barotrauma
private static GUIProgressBar drowningBar, healthBar;
private static float pressureTimer;
public static void TakeDamage()
{
healthBar.Flash();
@@ -29,9 +27,6 @@ namespace Barotrauma
if (character.Oxygen < 10.0f) drowningBar.Flash();
}
if (healthBar != null) healthBar.Update(deltaTime);
pressureTimer += ((character.AnimController.CurrentHull == null) ?
100.0f : character.AnimController.CurrentHull.LethalPressure)*deltaTime;
}
public static void Draw(SpriteBatch spriteBatch, Character character, Camera cam)
@@ -134,7 +129,7 @@ namespace Barotrauma
if (pressureFactor>0.0f)
{
float indicatorAlpha = ((float)Math.Sin(pressureTimer * 0.1f) + 1.0f) * 0.5f;
float indicatorAlpha = ((float)Math.Sin(character.PressureTimer * 0.1f) + 1.0f) * 0.5f;
indicatorAlpha = MathHelper.Clamp(indicatorAlpha, 0.1f, pressureFactor/100.0f);