Multiplayer fixes

This commit is contained in:
Regalis
2015-12-12 16:23:01 +02:00
parent 17e8a2171f
commit 04cfca0ede
14 changed files with 46 additions and 37 deletions
@@ -64,6 +64,8 @@ namespace Barotrauma
public EnemyAIController(Character c, string file) : base(c) public EnemyAIController(Character c, string file) : base(c)
{ {
if (GameMain.Client != null && GameMain.Server == null) c.Enabled = false;
targetMemories = new Dictionary<AITarget, AITargetMemory>(); targetMemories = new Dictionary<AITarget, AITargetMemory>();
XDocument doc = ToolBox.TryLoadXml(file); XDocument doc = ToolBox.TryLoadXml(file);
+10 -11
View File
@@ -42,7 +42,6 @@ namespace Barotrauma
public AICharacter(string file, Vector2 position, CharacterInfo characterInfo = null, bool isNetworkPlayer = false) public AICharacter(string file, Vector2 position, CharacterInfo characterInfo = null, bool isNetworkPlayer = false)
: base(file, position, characterInfo, isNetworkPlayer) : base(file, position, characterInfo, isNetworkPlayer)
{ {
if (GameMain.Client != null && GameMain.Server == null) Enabled = false;
} }
public void SetAI(AIController aiController) public void SetAI(AIController aiController)
@@ -98,10 +97,10 @@ namespace Barotrauma
//{ //{
//if (RefLimb.ignoreCollisions) continue; //if (RefLimb.ignoreCollisions) continue;
if (AnimController.RefLimb.SimPosition.Length() > NetConfig.CharacterIgnoreDistance) return false; if ((AnimController.RefLimb.SimPosition - Submarine.Loaded.SimPosition).Length() > NetConfig.CharacterIgnoreDistance) return false;
message.WriteRangedSingle(AnimController.RefLimb.SimPosition.X, -NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16); message.Write(AnimController.RefLimb.SimPosition.X);
message.WriteRangedSingle(AnimController.RefLimb.SimPosition.Y, -NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16); message.Write(AnimController.RefLimb.SimPosition.Y);
message.Write(AnimController.RefLimb.Rotation); message.Write(AnimController.RefLimb.Rotation);
@@ -114,14 +113,14 @@ namespace Barotrauma
aiController.FillNetworkData(message); aiController.FillNetworkData(message);
return true; return true;
case NetworkEventType.EntityUpdate: case NetworkEventType.EntityUpdate:
if (AnimController.RefLimb.SimPosition.Length() > NetConfig.CharacterIgnoreDistance) return false; if ((AnimController.RefLimb.SimPosition - Submarine.Loaded.SimPosition).Length() > NetConfig.CharacterIgnoreDistance) return false;
message.Write(AnimController.TargetDir == Direction.Right); 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.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.WriteRangedSingle(AnimController.RefLimb.SimPosition.X, -NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16); message.Write(AnimController.RefLimb.SimPosition.X);
message.WriteRangedSingle(AnimController.RefLimb.SimPosition.Y, -NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16); message.Write(AnimController.RefLimb.SimPosition.Y);
return true; return true;
} }
@@ -149,8 +148,8 @@ namespace Barotrauma
try try
{ {
limbPos.X = message.ReadRangedSingle(-NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16); limbPos.X = message.ReadFloat();
limbPos.Y = message.ReadRangedSingle(-NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16); limbPos.Y = message.ReadFloat();
rotation = message.ReadFloat(); rotation = message.ReadFloat();
} }
@@ -196,8 +195,8 @@ namespace Barotrauma
targetMovement.X = message.ReadRangedSingle(-1.0f, 1.0f, 8); targetMovement.X = message.ReadRangedSingle(-1.0f, 1.0f, 8);
targetMovement.Y = message.ReadRangedSingle(-1.0f, 1.0f, 8); targetMovement.Y = message.ReadRangedSingle(-1.0f, 1.0f, 8);
pos.X = message.ReadRangedSingle(-NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16); pos.X = message.ReadFloat();
pos.Y = message.ReadRangedSingle(-NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16); pos.Y = message.ReadFloat();
//vel.X = message.ReadFloat(); //vel.X = message.ReadFloat();
//vel.Y = message.ReadFloat(); //vel.Y = message.ReadFloat();
+6 -6
View File
@@ -988,7 +988,7 @@ namespace Barotrauma
{ {
if (!Enabled) return; if (!Enabled) return;
Vector2 pos = ConvertUnits.ToDisplayUnits(AnimController.Limbs[0].SimPosition); Vector2 pos = AnimController.Limbs[0].WorldPosition;
pos.Y = -pos.Y; pos.Y = -pos.Y;
if (this == controlled) return; if (this == controlled) return;
@@ -1335,10 +1335,10 @@ namespace Barotrauma
message.Write(AnimController.Dir > 0.0f); message.Write(AnimController.Dir > 0.0f);
} }
if (AnimController.RefLimb.SimPosition.Length() > NetConfig.CharacterIgnoreDistance) return true; if ((AnimController.RefLimb.SimPosition - Submarine.Loaded.SimPosition).Length() > NetConfig.CharacterIgnoreDistance) return true;
message.WriteRangedSingle(AnimController.RefLimb.SimPosition.X, -NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16); message.Write(AnimController.RefLimb.SimPosition.X);
message.WriteRangedSingle(AnimController.RefLimb.SimPosition.Y, -NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16); message.Write(AnimController.RefLimb.SimPosition.Y);
return true; return true;
default: default:
@@ -1505,8 +1505,8 @@ namespace Barotrauma
} }
try try
{ {
pos.X = message.ReadRangedSingle(-NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16); pos.X = message.ReadFloat();
pos.Y = message.ReadRangedSingle(-NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16); pos.Y = message.ReadFloat();
} }
catch catch
+1 -1
View File
@@ -54,7 +54,7 @@ namespace Barotrauma
if (character.ClosestCharacter != null && (character.ClosestCharacter.IsDead || character.ClosestCharacter.Stun > 0.0f)) if (character.ClosestCharacter != null && (character.ClosestCharacter.IsDead || character.ClosestCharacter.Stun > 0.0f))
{ {
Vector2 startPos = character.Position + (character.ClosestCharacter.Position - character.Position) * 0.7f; Vector2 startPos = character.Position + (character.ClosestCharacter.WorldPosition - character.WorldPosition) * 0.7f;
startPos = cam.WorldToScreen(startPos); startPos = cam.WorldToScreen(startPos);
Vector2 textPos = startPos; Vector2 textPos = startPos;
@@ -61,7 +61,7 @@ namespace Barotrauma.Items.Components
{ {
base.Draw(spriteBatch, editing); base.Draw(spriteBatch, editing);
textBlock.Rect = new Rectangle(item.WorldRect.X, -(item.WorldRect.Y - item.Rect.Height/2), item.Rect.Width, item.Rect.Height); textBlock.Rect = new Rectangle((int)item.DrawPosition.X - item.Rect.Width/2, -(int)(item.DrawPosition.Y + item.Rect.Height/2), item.Rect.Width, item.Rect.Height);
textBlock.Draw(spriteBatch); textBlock.Draw(spriteBatch);
} }
} }
@@ -118,7 +118,7 @@ namespace Barotrauma.Items.Components
fmj.WorldAnchorB = position; fmj.WorldAnchorB = position;
} }
item.SendSignal(ToolBox.Vector2ToString(character.CursorPosition), "position_out"); item.SendSignal(ToolBox.Vector2ToString(character.CursorWorldPosition), "position_out");
} }
public override bool Use(float deltaTime, Character activator = null) public override bool Use(float deltaTime, Character activator = null)
@@ -152,12 +152,12 @@ namespace Barotrauma.Items.Components
{ {
if (c2 == null || c2.Item==null || !c2.Item.Prefab.FocusOnSelected) continue; if (c2 == null || c2.Item==null || !c2.Item.Prefab.FocusOnSelected) continue;
Vector2 centerPos = c2.Item.Position; Vector2 centerPos = c2.Item.WorldPosition;
if (character == Character.Controlled && cam != null) if (character == Character.Controlled && cam != null)
{ {
Lights.LightManager.ViewPos = centerPos; Lights.LightManager.ViewPos = centerPos;
cam.TargetPos = c2.Item.Position; cam.TargetPos = c2.Item.WorldPosition;
} }
break; break;
@@ -50,6 +50,8 @@ namespace Barotrauma.Items.Components
public override void Update(float deltaTime, Camera cam) public override void Update(float deltaTime, Camera cam)
{ {
currPowerConsumption = powerConsumption;
base.Update(deltaTime, cam); base.Update(deltaTime, cam);
for (int i = radarBlips.Count - 1; i >= 0; i-- ) for (int i = radarBlips.Count - 1; i >= 0; i-- )
@@ -71,6 +73,8 @@ namespace Barotrauma.Items.Components
{ {
pingState = 0.0f; pingState = 0.0f;
} }
voltage = 0.0f;
} }
public override bool Use(float deltaTime, Character character = null) public override bool Use(float deltaTime, Character character = null)
@@ -262,7 +266,6 @@ namespace Barotrauma.Items.Components
prevPos = pos; prevPos = pos;
} }
voltage = 0.0f;
} }
private void DrawBlip(SpriteBatch spriteBatch, RadarBlip blip, Vector2 center, Color color, float radius) private void DrawBlip(SpriteBatch spriteBatch, RadarBlip blip, Vector2 center, Color color, float radius)
+2 -2
View File
@@ -153,7 +153,7 @@ namespace Barotrauma.Items.Components
projectile.body.ResetDynamics(); projectile.body.ResetDynamics();
projectile.body.Enabled = true; projectile.body.Enabled = true;
projectile.SetTransform(ConvertUnits.ToSimUnits(new Vector2(item.Rect.X + barrelPos.X, item.Rect.Y - barrelPos.Y)), -rotation); projectile.SetTransform(ConvertUnits.ToSimUnits(new Vector2(item.WorldRect.X + barrelPos.X, item.WorldRect.Y - barrelPos.Y)), -rotation);
projectiles[0].Use(deltaTime); projectiles[0].Use(deltaTime);
if (projectile.container != null) projectile.container.RemoveContained(projectile); if (projectile.container != null) projectile.container.RemoveContained(projectile);
@@ -301,7 +301,7 @@ namespace Barotrauma.Items.Components
case "position_in": case "position_in":
Vector2 receivedPos = ToolBox.ParseToVector2(signal, false); Vector2 receivedPos = ToolBox.ParseToVector2(signal, false);
Vector2 centerPos = new Vector2(item.Rect.X + barrelPos.X, item.Rect.Y - barrelPos.Y); Vector2 centerPos = new Vector2(item.WorldRect.X + barrelPos.X, item.WorldRect.Y - barrelPos.Y);
Vector2 offset = receivedPos - centerPos; Vector2 offset = receivedPos - centerPos;
offset.Y = -offset.Y; offset.Y = -offset.Y;
+8
View File
@@ -110,6 +110,14 @@ namespace Barotrauma
private set; private set;
} }
public override Vector2 SimPosition
{
get
{
return ConvertUnits.ToSimUnits(Position);
}
}
public Vector2 Velocity public Vector2 Velocity
{ {
get { return subBody==null ? Vector2.Zero : subBody.Velocity; } get { return subBody==null ? Vector2.Zero : subBody.Velocity; }
+1 -1
View File
@@ -402,7 +402,7 @@ namespace Barotrauma
} }
var ragdoll = limb.character.AnimController; var ragdoll = limb.character.AnimController;
ragdoll.FindHull(); ragdoll.FindHull();
return false; return false;
+4 -5
View File
@@ -3,6 +3,7 @@ using Lidgren.Network;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using System.Collections.Generic; using System.Collections.Generic;
using Barotrauma.Networking.ReliableMessages; using Barotrauma.Networking.ReliableMessages;
using FarseerPhysics;
namespace Barotrauma.Networking namespace Barotrauma.Networking
{ {
@@ -356,7 +357,7 @@ namespace Barotrauma.Networking
if (myCharacter.IsDead) if (myCharacter.IsDead)
{ {
Character.Controlled = null; Character.Controlled = null;
GameMain.GameScreen.Cam.TargetPos = Vector2.Zero; //GameMain.GameScreen.Cam.TargetPos = Vector2.Zero;
} }
else if (gameStarted) else if (gameStarted)
{ {
@@ -742,7 +743,7 @@ namespace Barotrauma.Networking
float closestDist = 0.0f; float closestDist = 0.0f;
foreach (WayPoint wp in WayPoint.WayPointList) foreach (WayPoint wp in WayPoint.WayPointList)
{ {
float dist = Vector2.Distance(wp.SimPosition, position); float dist = Vector2.Distance(wp.WorldPosition, position);
if (closestWaypoint != null && dist > closestDist) continue; if (closestWaypoint != null && dist > closestDist) continue;
closestWaypoint = wp; closestWaypoint = wp;
@@ -750,9 +751,7 @@ namespace Barotrauma.Networking
continue; continue;
} }
Character character = (closestWaypoint == null) ? Character character = Character.Create(ch, position, !isMyCharacter);
Character.Create(ch, position, !isMyCharacter) :
Character.Create(ch, closestWaypoint, !isMyCharacter);
character.ID = ID; character.ID = ID;
+2 -2
View File
@@ -1223,8 +1223,8 @@ namespace Barotrauma.Networking
message.Write((byte)character.Info.HeadSpriteId); message.Write((byte)character.Info.HeadSpriteId);
message.Write(character.SimPosition.X); message.Write(character.WorldPosition.X);
message.Write(character.SimPosition.Y); message.Write(character.WorldPosition.Y);
message.Write(character.Info.Job.Name); message.Write(character.Info.Job.Name);
} }
+2 -4
View File
@@ -18,14 +18,12 @@ namespace Barotrauma
public static float Range(float minimum, float maximum, bool local = true) public static float Range(float minimum, float maximum, bool local = true)
{ {
return (float)(local ? localRandom : syncedRandom).NextDouble() * (maximum - minimum) + minimum; return (float)(local ? localRandom : syncedRandom).NextDouble() * (maximum - minimum) + minimum;
} }
public static int Range(int minimum, int maximum, bool local = true) public static int Range(int minimum, int maximum, bool local = true)
{ {
return (local ? localRandom : syncedRandom).Next(maximum - minimum) + minimum; return (local ? localRandom : syncedRandom).Next(maximum - minimum) + minimum;
} }
public static int Int(int max = int.MaxValue, bool local = true) public static int Int(int max = int.MaxValue, bool local = true)
Binary file not shown.