- fixed camera "twitching" when trying to move it above the upper limit of the level

- fixed duplicate hulls/gaps being placed at docking ports when saving and loading
- fixed linkedsubmarines moving when saving and reloading if the center of the wall vertices isn't he same as the center of the sub
- moving docked submarines along with the main sub when syncing the position
- characters are killed when the client controlling them disconnects (+ cause of death: disconnected)
- fixed the description box in server lobby
This commit is contained in:
Regalis
2016-07-15 17:55:16 +03:00
parent a5111d33df
commit 03a3a156ba
14 changed files with 167 additions and 71 deletions
+2
View File
@@ -11,6 +11,7 @@
<CauseOfDeath.Suffocation>Suffocated</CauseOfDeath.Suffocation>
<CauseOfDeath.Pressure>Crushed by water pressure</CauseOfDeath.Pressure>
<CauseOfDeath.Burn>Burned to death</CauseOfDeath.Burn>
<CauseOfDeath.Disconnected>Disconnected</CauseOfDeath.Disconnected>
<Self_CauseOfDeath.Damage>You have succumbed to your injuries.</Self_CauseOfDeath.Damage>
<Self_CauseOfDeath.Bloodloss>You have bled out.</Self_CauseOfDeath.Bloodloss>
@@ -18,5 +19,6 @@
<Self_CauseOfDeath.Suffocation>You have suffocated.</Self_CauseOfDeath.Suffocation>
<Self_CauseOfDeath.Pressure>You have been crushed by water pressure.</Self_CauseOfDeath.Pressure>
<Self_CauseOfDeath.Burn>You have burned to death.</Self_CauseOfDeath.Burn>
<CauseOfDeath.Disconnected>You have been disconnected from the server.</CauseOfDeath.Disconnected>
</infotexts>
+2
View File
@@ -142,6 +142,8 @@ namespace Barotrauma
{
position.Y -= Math.Max(worldView.Y - Level.Loaded.Size.Y, 0.0f);
interpolatedPosition.Y -= Math.Max(worldView.Y - Level.Loaded.Size.Y, 0.0f);
worldView.Y = Math.Min((int)Level.Loaded.Size.Y, worldView.Y);
}
transform = Matrix.CreateTranslation(
+1 -1
View File
@@ -8,7 +8,7 @@ namespace Barotrauma
{
enum CauseOfDeath
{
Damage, Bloodloss, Pressure, Suffocation, Drowning, Burn
Damage, Bloodloss, Pressure, Suffocation, Drowning, Burn, Disconnected
}
public enum DamageType { None, Blunt, Slash, Burn }
@@ -126,6 +126,7 @@ namespace Barotrauma
}
if (reloadSub || Submarine.MainSub != submarine) submarine.Load(true);
Submarine.MainSub = submarine;
//var secondSub = new Submarine(submarine.FilePath, submarine.MD5Hash.Hash);
//secondSub.Load(false);
@@ -59,6 +59,12 @@ namespace Barotrauma.Items.Components
set;
}
public DockingPort DockingTarget
{
get { return dockingTarget; }
set { dockingTarget = value; }
}
public bool Docked
{
get
@@ -135,7 +141,8 @@ namespace Barotrauma.Items.Components
PlaySound(ActionType.OnUse, item.WorldPosition);
item.linkedTo.Add(target.item);
if (!item.linkedTo.Contains(target.item)) item.linkedTo.Add(target.item);
if (!target.item.linkedTo.Contains(item)) target.item.linkedTo.Add(item);
if (!target.item.Submarine.DockedTo.Contains(item.Submarine)) target.item.Submarine.DockedTo.Add(item.Submarine);
if (!item.Submarine.DockedTo.Contains(target.item.Submarine)) item.Submarine.DockedTo.Add(target.item.Submarine);
@@ -184,7 +191,7 @@ namespace Barotrauma.Items.Components
Vector2.UnitX * Math.Sign(dockingTarget.item.WorldPosition.X - item.WorldPosition.X) :
Vector2.UnitY * Math.Sign(dockingTarget.item.WorldPosition.Y - item.WorldPosition.Y));
offset *= DockedDistance * 0.5f;
Vector2 pos1 = item.WorldPosition + offset;
Vector2 pos2 = dockingTarget.item.WorldPosition - offset;
@@ -302,6 +309,11 @@ namespace Barotrauma.Items.Components
}
}
item.linkedTo.Add(hulls[0]);
item.linkedTo.Add(hulls[1]);
item.linkedTo.Add(gap);
foreach (Body body in bodies)
{
@@ -394,6 +406,22 @@ namespace Barotrauma.Items.Components
}
else
{
if (!docked)
{
Dock(dockingTarget);
//if (joint.BodyA.Mass < joint.BodyB.Mass)
//{
// joint.BodyA.SetTransform(joint.BodyA.Position + (joint.WorldAnchorB - joint.WorldAnchorA), 0.0f);
//}
//else
//{
// joint.BodyB.SetTransform(joint.BodyB.Position + (joint.WorldAnchorA - joint.WorldAnchorB), 0.0f);
//}
}
if (joint is DistanceJoint)
{
item.SendSignal(0, "0", "state_out");
@@ -405,7 +433,11 @@ namespace Barotrauma.Items.Components
PlaySound(ActionType.OnSecondaryUse, item.WorldPosition);
CreateJoint(true);
CreateHull();
if (!item.linkedTo.Any(e => e is Hull) && !dockingTarget.item.linkedTo.Any(e => e is Hull))
{
CreateHull();
}
}
dockingState = MathHelper.Lerp(dockingState, 0.5f, deltaTime * 10.0f);
}
@@ -459,7 +491,7 @@ namespace Barotrauma.Items.Components
drawPos,
new Rectangle(
rect.X, rect.Y + rect.Height/2 + (int)(rect.Height / 2 * (1.0f - dockingState)),
rect.Width, (int)(rect.Height / 2 * dockingState)), Color.White);
rect.Width, (int)(rect.Height / 2 * dockingState)), Color.Red);
}
else
@@ -482,11 +514,31 @@ namespace Barotrauma.Items.Components
{
if (!item.linkedTo.Any()) return;
Item linkedItem = item.linkedTo.First() as Item;
if (linkedItem == null) return;
foreach (MapEntity entity in item.linkedTo)
{
DockingPort port = linkedItem.GetComponent<DockingPort>();
if (port != null) Dock(port);
var hull = entity as Hull;
if (hull != null)
{
hull.Remove();
continue;
}
var gap = entity as Gap;
if (gap != null)
{
gap.Remove();
continue;
}
Item linkedItem = entity as Item;
if (linkedItem == null) continue;
var dockingPort = linkedItem.GetComponent<DockingPort>();
if (dockingPort != null) dockingTarget = dockingPort;
}
item.linkedTo.Clear();
}
public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item sender, float power = 0.0f)
@@ -82,8 +82,8 @@ namespace Barotrauma
{
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearWrap);
Vector2 backgroundPos = cam.Position;
//if (Level.Loaded != null) backgroundPos -= Level.Loaded.Position;
Vector2 backgroundPos = cam.WorldViewCenter;
backgroundPos.Y = -backgroundPos.Y;
backgroundPos /= 20.0f;
+10 -3
View File
@@ -79,7 +79,10 @@ namespace Barotrauma
(int)sl.wallVertices.Max(v => v.X + position.X),
(int)sl.wallVertices.Min(v => v.Y + position.Y));
sl.rect = new Rectangle(sl.rect.X, sl.rect.Y, sl.rect.Width - sl.rect.X, sl.rect.Y - sl.rect.Height);
int width = sl.rect.Width - sl.rect.X;
int height = sl.rect.Y - sl.rect.Height;
sl.rect = new Rectangle((int)position.X, (int)position.Y, 1, 1);
return sl;
}
@@ -96,7 +99,7 @@ namespace Barotrauma
Color color = (isHighlighted) ? Color.Orange : Color.Green;
if (isSelected) color = Color.Red;
Vector2 pos = new Vector2(rect.X + rect.Width/2, rect.Y - rect.Height/2);
Vector2 pos = Position;
for (int i = 0; i < wallVertices.Count; i++)
{
@@ -116,6 +119,9 @@ namespace Barotrauma
GUI.DrawLine(spriteBatch, pos + Vector2.UnitY * 50.0f, pos - Vector2.UnitY * 50.0f, color, 0.0f, 5);
GUI.DrawLine(spriteBatch, pos + Vector2.UnitX * 50.0f, pos - Vector2.UnitX * 50.0f, color, 0.0f, 5);
Rectangle drawRect = rect;
drawRect.Y = -rect.Y;
GUI.DrawRectangle(spriteBatch, drawRect, Color.Red, true);
foreach (MapEntity e in linkedTo)
{
@@ -210,6 +216,7 @@ namespace Barotrauma
GenerateWallVertices(doc.Root);
saveElement = doc.Root;
saveElement.Name = "LinkedSubmarine";
filePath = pathBox.Text;
@@ -354,7 +361,7 @@ namespace Barotrauma
if (myPort != null)
{
myPort.Dock(linkedPort);
myPort.DockingTarget = linkedPort;
}
}
}
+18 -15
View File
@@ -819,24 +819,27 @@ namespace Barotrauma
center.X -= center.X % GridSize.X;
center.Y -= center.Y % GridSize.Y;
foreach (Item item in Item.ItemList)
if (center != Vector2.Zero)
{
if (item.Submarine != this) continue;
var wire = item.GetComponent<Items.Components.Wire>();
if (wire == null) continue;
for (int i = 0; i < wire.Nodes.Count; i++)
foreach (Item item in Item.ItemList)
{
wire.Nodes[i] -= center;
}
}
if (item.Submarine != this) continue;
for (int i = 0; i < MapEntity.mapEntityList.Count; i++)
{
if (MapEntity.mapEntityList[i].Submarine != this) continue;
MapEntity.mapEntityList[i].Move(-center);
var wire = item.GetComponent<Items.Components.Wire>();
if (wire == null) continue;
for (int i = 0; i < wire.Nodes.Count; i++)
{
wire.Nodes[i] -= center;
}
}
for (int i = 0; i < MapEntity.mapEntityList.Count; i++)
{
if (MapEntity.mapEntityList[i].Submarine != this) continue;
MapEntity.mapEntityList[i].Move(-center);
}
}
}
+40 -18
View File
@@ -127,6 +127,8 @@ namespace Barotrauma
foreach (Hull hull in Hull.hullList)
{
if (hull.Submarine != submarine) continue;
Rectangle rect = hull.Rect;
FixtureFactory.AttachRectangle(
ConvertUnits.ToSimUnits(rect.Width),
@@ -190,30 +192,43 @@ namespace Barotrauma
{
float dist = Vector2.Distance((Vector2)targetPosition, Position);
if (dist > 1000.0f) //immediately snap the sub to the target position if more than 1000.0f units away
if (dist > 500.0f) //immediately snap the sub to the target position if more than 500.0f units away
{
Vector2 moveAmount = (Vector2)targetPosition - ConvertUnits.ToDisplayUnits(Body.Position);
ForceTranslate(moveAmount);
List<SubmarineBody> dockedBodies = new List<SubmarineBody>() { this };
submarine.DockedTo.ForEach(d => dockedBodies.Add(d.SubBody));
if ((Character.Controlled != null && Character.Controlled.Submarine == submarine) ||
(Character.Controlled == null && Submarine.GetClosest(GameMain.GameScreen.Cam.WorldViewCenter) == submarine))
foreach (SubmarineBody dockedBody in dockedBodies)
{
GameMain.GameScreen.Cam.UpdateTransform(false);
dockedBody.ForceTranslate(moveAmount);
if ((Character.Controlled != null && Character.Controlled.Submarine == dockedBody.submarine) ||
(Character.Controlled == null && Submarine.GetClosest(GameMain.GameScreen.Cam.WorldViewCenter) == dockedBody.submarine))
{
GameMain.GameScreen.Cam.UpdateTransform(false);
}
dockedBody.submarine.SetPrevTransform(dockedBody.submarine.Position);
dockedBody.submarine.UpdateTransform();
targetPosition = null;
dockedBody.DisplaceCharacters(moveAmount);
}
submarine.SetPrevTransform(submarine.Position);
submarine.UpdateTransform();
targetPosition = null;
DisplaceCharacters(moveAmount);
}
else if (dist > 50.0f) //lerp the position if (50 < dist < 1000)
else if (dist > 50.0f) //lerp the position if (50 < dist < 500)
{
Vector2 moveAmount = Vector2.Normalize((Vector2)targetPosition - Position);
moveAmount *= Math.Min(dist, 100.0f);
ForceTranslate(moveAmount * deltaTime);
foreach (Submarine sub in submarine.DockedTo)
{
sub.SubBody.ForceTranslate(moveAmount * deltaTime);
}
}
else
{
@@ -252,13 +267,17 @@ namespace Barotrauma
private void ForceTranslate(Vector2 amount)
{
Body.SetTransform(Body.Position + ConvertUnits.ToSimUnits(amount), 0.0f);
if (Character.Controlled != null) Character.Controlled.CursorPosition += amount;
if ((Character.Controlled != null && Character.Controlled.Submarine == submarine) ||
(Character.Controlled == null && Submarine.GetClosest(GameMain.GameScreen.Cam.WorldViewCenter) == submarine))
if (Character.Controlled != null)
{
GameMain.GameScreen.Cam.Position += amount;
if (GameMain.GameScreen.Cam.TargetPos != Vector2.Zero) GameMain.GameScreen.Cam.TargetPos += amount;
Character.Controlled.CursorPosition += amount;
if (Character.Controlled.Submarine == submarine ||
(Character.Controlled == null && Submarine.GetClosest(GameMain.GameScreen.Cam.WorldViewCenter) == submarine))
{
GameMain.GameScreen.Cam.Position += amount;
if (GameMain.GameScreen.Cam.TargetPos != Vector2.Zero) GameMain.GameScreen.Cam.TargetPos += amount;
}
}
}
@@ -317,10 +336,13 @@ namespace Barotrauma
float neutralPercentage = 0.07f;
float buoyancy = Math.Max(neutralPercentage - waterPercentage, -neutralPercentage*2.0f);
buoyancy *= Body.Mass;
Body.IgnoreGravity = true;
return new Vector2(0.0f, buoyancy*10.0f);
float buoyancy = neutralPercentage - waterPercentage;
if (buoyancy > 0.0f) buoyancy *= 2.0f;
return new Vector2(0.0f, buoyancy * Body.Mass * 10.0f);
}
public void ApplyForce(Vector2 force)
+3 -1
View File
@@ -806,7 +806,9 @@ namespace Barotrauma.Networking
}
}
if (respawnManager != null && respawnManager.CurrentState == RespawnManager.State.Waiting &&
if (respawnManager != null &&
respawnManager.CurrentState == RespawnManager.State.Waiting &&
respawnManager.CountdownStarted &&
myCharacter != null && myCharacter.IsDead)
{
GUI.DrawString(spriteBatch,
@@ -1175,8 +1175,10 @@ namespace Barotrauma.Networking
if (gameStarted && client.Character != null)
{
client.Character.ClearInputs();
client.Character.Kill(CauseOfDeath.Disconnected, true);
}
if (string.IsNullOrWhiteSpace(msg)) msg = client.name + " has left the server";
if (string.IsNullOrWhiteSpace(targetmsg)) targetmsg = "You have left the server";
+21 -12
View File
@@ -118,7 +118,11 @@ namespace Barotrauma.Networking
int characterToRespawnCount = GetClientsToRespawn().Count;
if (server.Character != null && server.Character.IsDead) characterToRespawnCount++;
CountdownStarted = characterToRespawnCount >= MinCharactersToRespawn;
bool startCountdown = characterToRespawnCount >= MinCharactersToRespawn;
if (startCountdown && !CountdownStarted) server.SendRespawnManagerMsg();
CountdownStarted = startCountdown;
if (!CountdownStarted) return;
@@ -170,17 +174,19 @@ namespace Barotrauma.Networking
|| (respawnShuttle.WorldPosition.Y + respawnShuttle.Borders.Y > Level.Loaded.StartPosition.Y - Level.ShaftHeight &&
Math.Abs(Level.Loaded.StartPosition.X - respawnShuttle.WorldPosition.X) < 1000.0f))
{
CoroutineManager.StartCoroutine(
ForceShuttleToPos(new Vector2(Level.Loaded.StartPosition.X, Level.Loaded.Size.Y + 1000.0f), 100.0f));
if (GameMain.GameSession != null && GameMain.GameSession.Map != null)
{
string msg = "The transportation shuttle has returned to " + GameMain.GameSession.Map.SelectedLocation;
server.SendChatMessage(ChatMessage.Create("", msg, ChatMessageType.Server, null), server.ConnectedClients);
}
CoroutineManager.StopCoroutines("forcepos");
CoroutineManager.StartCoroutine(
ForceShuttleToPos(new Vector2(Level.Loaded.StartPosition.X, Level.Loaded.Size.Y + 1000.0f), 100.0f), "forcepos");
//string msg = "The transportation shuttle has returned to ";
//server.SendChatMessage(ChatMessage.Create("", msg, ChatMessageType.Server, null), server.ConnectedClients);
state = State.Waiting;
respawnTimer = RespawnInterval;
server.SendRespawnManagerMsg();
}
@@ -200,8 +206,9 @@ namespace Barotrauma.Networking
server.SendChatMessage(ChatMessage.Create("", "Transportation shuttle dispatched", ChatMessageType.Server, null), server.ConnectedClients);
server.SendRespawnManagerMsg();
CoroutineManager.StartCoroutine(ForceShuttleToPos(Level.Loaded.StartPosition - Vector2.UnitY * Level.ShaftHeight, 100.0f));
CoroutineManager.StopCoroutines("forcepos");
CoroutineManager.StartCoroutine(ForceShuttleToPos(Level.Loaded.StartPosition - Vector2.UnitY * Level.ShaftHeight, 100.0f), "forcepos");
}
private IEnumerable<object> ForceShuttleToPos(Vector2 position, float speed)
@@ -255,6 +262,7 @@ namespace Barotrauma.Networking
if (i < clients.Count)
{
msg.Write((byte)clients[i].ID);
clients[i].Character = character;
}
else
{
@@ -297,7 +305,8 @@ namespace Barotrauma.Networking
client.ReadCharacterData(inc, clientId == client.ID);
}
CoroutineManager.StartCoroutine(ForceShuttleToPos(Level.Loaded.StartPosition - Vector2.UnitY * Level.ShaftHeight, 100.0f));
CoroutineManager.StopCoroutines("forcepos");
CoroutineManager.StartCoroutine(ForceShuttleToPos(Level.Loaded.StartPosition - Vector2.UnitY * Level.ShaftHeight, 100.0f), "forcepos");
break;
case State.Waiting:
CountdownStarted = true;
+2 -2
View File
@@ -342,14 +342,14 @@ namespace Barotrauma
private void DrawSubmarineIndicator(SpriteBatch spriteBatch, Submarine submarine)
{
Vector2 subDiff = submarine.WorldPosition - cam.Position;
Vector2 subDiff = submarine.WorldPosition - cam.WorldViewCenter;
if (Math.Abs(subDiff.X) > cam.WorldView.Width || Math.Abs(subDiff.Y) > cam.WorldView.Height)
{
Vector2 normalizedSubDiff = Vector2.Normalize(subDiff);
Vector2 iconPos =
cam.WorldToScreen(cam.Position) +
cam.WorldToScreen(cam.WorldViewCenter) +
new Vector2(normalizedSubDiff.X * GameMain.GraphicsWidth * 0.4f, -normalizedSubDiff.Y * GameMain.GraphicsHeight * 0.4f);
GUI.SubmarineIcon.Draw(spriteBatch, iconPos, Color.LightBlue * 0.5f);
+3 -9
View File
@@ -38,7 +38,7 @@ namespace Barotrauma
private GUITickBox autoRestartBox;
public bool IsServer;
public string ServerName, ServerMessage;
public string ServerName;
const float NetworkUpdateInterval = 1.0f;
private float networkUpdateTimer;
@@ -95,10 +95,6 @@ namespace Barotrauma
{
return ServerName;
}
public string GetServerMessage()
{
return ServerMessage;
}
public List<JobPrefab> JobPreferences
{
@@ -308,7 +304,6 @@ namespace Barotrauma
serverMessage = new GUITextBox(new Rectangle(0, 30, 360, 70), null, null, Alignment.TopLeft, Alignment.TopLeft, GUI.Style, infoFrame);
serverMessage.Wrap = true;
serverMessage.TextGetter = GetServerMessage;
serverMessage.OnTextChanged = UpdateServerMessage;
}
@@ -686,7 +681,6 @@ namespace Barotrauma
public bool UpdateServerMessage(GUITextBox textBox, string text)
{
if (GameMain.Server == null) return false;
ServerMessage = text;
valueChanged = true;
return true;
@@ -1107,7 +1101,7 @@ namespace Barotrauma
}
msg.Write(ServerName);
msg.Write(ServerMessage);
msg.Write(serverMessage.Text);
msg.WriteRangedInteger(0, 2, (int)GameMain.Server.TraitorsEnabled);
@@ -1147,7 +1141,7 @@ namespace Barotrauma
md5Hash = msg.ReadString();
ServerName = msg.ReadString();
ServerMessage = msg.ReadString();
serverMessage.Text = msg.ReadString();
traitorsEnabled = (YesNoMaybe)msg.ReadRangedInteger(0, 2);