Moving camera with sub even if typing, server doesn't do impact damage to client characters, server sends cause of death in importantentityupdate if health<=0, fire sync fixes, lerping water surface in update instead of render,

This commit is contained in:
Regalis
2016-01-27 20:38:24 +02:00
parent 71faada355
commit 8cc12b6988
13 changed files with 111 additions and 45 deletions
+2 -2
View File
@@ -31,5 +31,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.3.0.1")] [assembly: AssemblyVersion("0.3.0.2")]
[assembly: AssemblyFileVersion("0.3.0.1")] [assembly: AssemblyFileVersion("0.3.0.2")]
+6 -7
View File
@@ -170,15 +170,14 @@ namespace Barotrauma
if (PlayerInput.KeyDown(Keys.D)) moveCam.X += moveSpeed; if (PlayerInput.KeyDown(Keys.D)) moveCam.X += moveSpeed;
if (PlayerInput.KeyDown(Keys.S)) moveCam.Y -= moveSpeed; if (PlayerInput.KeyDown(Keys.S)) moveCam.Y -= moveSpeed;
if (PlayerInput.KeyDown(Keys.W)) moveCam.Y += moveSpeed; if (PlayerInput.KeyDown(Keys.W)) moveCam.Y += moveSpeed;
if (Submarine.Loaded!=null && Screen.Selected == GameMain.GameScreen)
{
moveCam += FarseerPhysics.ConvertUnits.ToDisplayUnits(Submarine.Loaded.Velocity*deltaTime);
}
moveCam = moveCam * deltaTime * 60.0f;
} }
if (Submarine.Loaded!=null && Screen.Selected == GameMain.GameScreen)
{
moveCam += FarseerPhysics.ConvertUnits.ToDisplayUnits(Submarine.Loaded.Velocity*deltaTime);
}
moveCam = moveCam * deltaTime * 60.0f;
Zoom = MathHelper.Clamp(zoom + (PlayerInput.ScrollWheelSpeed / 1000.0f) * zoom, 0.1f, 2.0f); Zoom = MathHelper.Clamp(zoom + (PlayerInput.ScrollWheelSpeed / 1000.0f) * zoom, 0.1f, 2.0f);
} }
@@ -385,18 +385,20 @@ namespace Barotrauma
float impact = Vector2.Dot(avgVelocity, -normal); float impact = Vector2.Dot(avgVelocity, -normal);
if (GameMain.Server != null) impact = impact / 2.0f;
Limb l = (Limb)f1.Body.UserData; Limb l = (Limb)f1.Body.UserData;
float volume = stairs == null ? impact/5.0f : impact; float volume = stairs == null ? impact / 5.0f : impact;
volume= Math.Min(impact, 1.0f); volume = Math.Min(impact, 1.0f);
if (impact > 0.8f && l.HitSound != null && l.soundTimer <= 0.0f) l.HitSound.Play(volume, impact * 100.0f, l.WorldPosition); if (impact > 0.8f && l.HitSound != null && l.soundTimer <= 0.0f) l.HitSound.Play(volume, impact * 100.0f, l.WorldPosition);
if (impact > l.impactTolerance) if (impact > l.impactTolerance)
{ {
character.Health -= (impact - l.impactTolerance * 0.1f); if (!character.IsNetworkPlayer)
{
character.AddDamage(CauseOfDeath.Damage, impact - l.impactTolerance * 0.1f);
}
strongestImpact = Math.Max(strongestImpact, impact - l.impactTolerance); strongestImpact = Math.Max(strongestImpact, impact - l.impactTolerance);
SoundPlayer.PlayDamageSound(DamageSoundType.LimbBlunt, strongestImpact, l.body); SoundPlayer.PlayDamageSound(DamageSoundType.LimbBlunt, strongestImpact, l.body);
+32 -9
View File
@@ -89,6 +89,7 @@ namespace Barotrauma
private Character closestCharacter, selectedCharacter; private Character closestCharacter, selectedCharacter;
protected bool isDead; protected bool isDead;
private CauseOfDeath lastAttackCauseOfDeath;
private CauseOfDeath causeOfDeath; private CauseOfDeath causeOfDeath;
public readonly bool IsHumanoid; public readonly bool IsHumanoid;
@@ -230,11 +231,10 @@ namespace Barotrauma
public float Health public float Health
{ {
get { return health; } get { return health; }
set set
{ {
if (!MathUtils.IsValid(value)) return; if (!MathUtils.IsValid(value)) return;
health = MathHelper.Clamp(value, 0.0f, maxHealth); health = MathHelper.Clamp(value, 0.0f, maxHealth);
if (health <= 0.0f) Kill(CauseOfDeath.Damage);
} }
} }
@@ -968,7 +968,7 @@ namespace Barotrauma
PressureProtection -= deltaTime*100.0f; PressureProtection -= deltaTime*100.0f;
} }
health = MathHelper.Clamp(health - bleeding * deltaTime, 0.0f, maxHealth); Health -= bleeding;
if (health <= 0.0f) Kill(CauseOfDeath.Bloodloss, false); if (health <= 0.0f) Kill(CauseOfDeath.Bloodloss, false);
} }
@@ -1063,6 +1063,13 @@ namespace Barotrauma
} }
} }
public void AddDamage(CauseOfDeath causeOfDeath, float amount)
{
health = MathHelper.Clamp(health-amount, 0.0f, maxHealth);
if (amount>0.0f) lastAttackCauseOfDeath = causeOfDeath;
if (health <= 0.0f) Kill(causeOfDeath);
}
public virtual AttackResult AddDamage(IDamageable attacker, Vector2 worldPosition, Attack attack, float deltaTime, bool playSound = false) public virtual AttackResult AddDamage(IDamageable attacker, Vector2 worldPosition, Attack attack, float deltaTime, bool playSound = false)
{ {
return AddDamage(worldPosition, attack.DamageType, attack.GetDamage(deltaTime), attack.GetBleedingDamage(deltaTime), attack.Stun, playSound); return AddDamage(worldPosition, attack.DamageType, attack.GetDamage(deltaTime), attack.GetBleedingDamage(deltaTime), attack.Stun, playSound);
@@ -1091,8 +1098,11 @@ namespace Barotrauma
AttackResult attackResult = closestLimb.AddDamage(simPosition, damageType, amount, bleedingAmount, playSound); AttackResult attackResult = closestLimb.AddDamage(simPosition, damageType, amount, bleedingAmount, playSound);
health -= attackResult.Damage;
if (health <= 0.0f && damageType == DamageType.Burn) Kill(CauseOfDeath.Burn); AddDamage(damageType == DamageType.Burn ? CauseOfDeath.Burn : causeOfDeath, attackResult.Damage);
//health -= attackResult.Damage;
//if (health <= 0.0f && damageType == DamageType.Burn) Kill(CauseOfDeath.Burn);
Bleeding += attackResult.Bleeding; Bleeding += attackResult.Bleeding;
@@ -1291,9 +1301,16 @@ namespace Barotrauma
case NetworkEventType.InventoryUpdate: case NetworkEventType.InventoryUpdate:
if (inventory == null) return false; if (inventory == null) return false;
return inventory.FillNetworkData(NetworkEventType.InventoryUpdate, message, data); return inventory.FillNetworkData(NetworkEventType.InventoryUpdate, message, data);
case NetworkEventType.ImportantEntityUpdate: case NetworkEventType.ImportantEntityUpdate:
if (health>0.0f)
message.Write((byte)((health / maxHealth) * 255.0f)); {
message.Write(Math.Max((byte)((health / maxHealth) * 255.0f), (byte)1));
}
else
{
message.Write((byte)0);
message.WriteRangedInteger((int)lastAttackCauseOfDeath, 0, Enum.GetValues(typeof(CauseOfDeath)).Length);
}
if (AnimController.StunTimer<=0.0f && bleeding<=0.0f && oxygen>99.0f) if (AnimController.StunTimer<=0.0f && bleeding<=0.0f && oxygen>99.0f)
{ {
@@ -1437,7 +1454,13 @@ namespace Barotrauma
return; return;
case NetworkEventType.ImportantEntityUpdate: case NetworkEventType.ImportantEntityUpdate:
Health = (message.ReadByte() / 255.0f) * maxHealth; health = MathHelper.Clamp((message.ReadByte() / 255.0f) * maxHealth, 0.0f, maxHealth);
if (health == 0.0f)
{
causeOfDeath = (CauseOfDeath)message.ReadRangedInteger(0, Enum.GetValues(typeof(CauseOfDeath)).Length);
Kill(causeOfDeath, true);
}
bool allOk = message.ReadBoolean(); bool allOk = message.ReadBoolean();
if (allOk) return; if (allOk) return;
+1 -1
View File
@@ -269,7 +269,7 @@ namespace Barotrauma
case "heal": case "heal":
if (Character.Controlled != null) if (Character.Controlled != null)
{ {
Character.Controlled.Health = Character.Controlled.MaxHealth; Character.Controlled.AddDamage(CauseOfDeath.Damage, -Character.Controlled.MaxHealth);
Character.Controlled.Oxygen = 100.0f; Character.Controlled.Oxygen = 100.0f;
Character.Controlled.Bleeding = 0.0f; Character.Controlled.Bleeding = 0.0f;
} }
@@ -182,7 +182,7 @@ namespace Barotrauma.Items.Components
{ {
if (character.IsKeyDown(InputType.Aim)) if (character.IsKeyDown(InputType.Aim))
{ {
targetLimb.character.Health += LimbFixAmount * degreeOfSuccess; targetLimb.character.AddDamage(CauseOfDeath.Damage, LimbFixAmount * degreeOfSuccess);
//isActive = true; //isActive = true;
} }
} }
+13 -8
View File
@@ -56,6 +56,11 @@ namespace Barotrauma
} }
} }
public Hull Hull
{
get { return hull; }
}
public FireSource(Vector2 worldPosition, Hull spawningHull = null, bool networkEvent=false) public FireSource(Vector2 worldPosition, Hull spawningHull = null, bool networkEvent=false)
{ {
hull = Hull.FindHull(worldPosition, spawningHull); hull = Hull.FindHull(worldPosition, spawningHull);
@@ -193,18 +198,18 @@ namespace Barotrauma
if (hull.Volume > 0.0f) HullWaterExtinquish(deltaTime); if (hull.Volume > 0.0f) HullWaterExtinquish(deltaTime);
lightSource.Range = Math.Max(size.X, size.Y) * Rand.Range(8.0f, 10.0f)/2.0f; hull.Oxygen -= size.X * deltaTime * OxygenConsumption;
lightSource.Color = new Color(1.0f, 0.45f, 0.3f) * Rand.Range(0.8f, 1.0f);
hull.Oxygen -= size.X*deltaTime*OxygenConsumption;
position.X -= GrowSpeed * growModifier * 0.5f * deltaTime; position.X -= GrowSpeed * growModifier * 0.5f * deltaTime;
//position.Y += GrowSpeed*0.5f * deltaTime;
size.X += GrowSpeed * growModifier * deltaTime; size.X += GrowSpeed * growModifier * deltaTime;
//size.Y += GrowSpeed * deltaTime;
LimitSize(); LimitSize();
lightSource.Range = Math.Max(size.X, size.Y) * Rand.Range(8.0f, 10.0f) / 2.0f;
lightSource.Color = new Color(1.0f, 0.45f, 0.3f) * Rand.Range(0.8f, 1.0f);
lightSource.Position = position;
} }
private void OnChangeHull(Vector2 pos, Hull particleHull) private void OnChangeHull(Vector2 pos, Hull particleHull)
@@ -222,7 +227,7 @@ namespace Barotrauma
foreach (Character c in Character.CharacterList) foreach (Character c in Character.CharacterList)
{ {
if (c.AnimController.CurrentHull == null) continue; if (c.AnimController.CurrentHull == null || c.IsDead) continue;
float range = (float)Math.Sqrt(size.X) * 20.0f; float range = (float)Math.Sqrt(size.X) * 20.0f;
if (c.Position.X < position.X - range || c.Position.X > position.X + size.X + range) continue; if (c.Position.X < position.X - range || c.Position.X > position.X + size.X + range) continue;
+31 -8
View File
@@ -278,6 +278,9 @@ namespace Barotrauma
{ {
Oxygen -= OxygenDetoriationSpeed * deltaTime; Oxygen -= OxygenDetoriationSpeed * deltaTime;
surface = MathHelper.Lerp(surface, GetSurfaceY(), deltaTime * 10.0f);
if (EditWater) if (EditWater)
{ {
Vector2 position = cam.ScreenToWorld(PlayerInput.MousePosition); Vector2 position = cam.ScreenToWorld(PlayerInput.MousePosition);
@@ -432,17 +435,25 @@ namespace Barotrauma
} }
} }
private float GetSurfaceY()
{
float top = rect.Y + Submarine.DrawPosition.Y;
float bottom = top - rect.Height;
return bottom + Volume / rect.Width;
}
public void Render(GraphicsDevice graphicsDevice, Camera cam) public void Render(GraphicsDevice graphicsDevice, Camera cam)
{ {
if (renderer.PositionInBuffer > renderer.vertices.Length - 6) return; if (renderer.PositionInBuffer > renderer.vertices.Length - 6) return;
//calculate where the surface should be based on the water volume ////calculate where the surface should be based on the water volume
float top = rect.Y+Submarine.DrawPosition.Y; float top = rect.Y+Submarine.DrawPosition.Y;
float bottom = top - rect.Height; float bottom = top - rect.Height;
float surfaceY = bottom + Volume / rect.Width; //float surfaceY = bottom + Volume / rect.Width;
//interpolate the position of the rendered surface towards the "target surface" ////interpolate the position of the rendered surface towards the "target surface"
surface = surface + ((surfaceY - Submarine.DrawPosition.Y) - surface) / 10.0f; //surface = surface + ((surfaceY - Submarine.DrawPosition.Y) - surface) / 10.0f;
float drawSurface = surface + Submarine.DrawPosition.Y; float drawSurface = surface + Submarine.DrawPosition.Y;
Matrix transform = cam.Transform * Matrix.CreateOrthographic(GameMain.GraphicsWidth, GameMain.GraphicsHeight, -1, 1) * 0.5f; Matrix transform = cam.Transform * Matrix.CreateOrthographic(GameMain.GraphicsWidth, GameMain.GraphicsHeight, -1, 1) * 0.5f;
@@ -643,13 +654,17 @@ namespace Barotrauma
message.WriteRangedSingle(MathHelper.Clamp(volume/FullVolume, 0.0f, 1.5f), 0.0f, 1.5f, 6); message.WriteRangedSingle(MathHelper.Clamp(volume/FullVolume, 0.0f, 1.5f), 0.0f, 1.5f, 6);
message.Write((byte)fireSources.Count, 4); message.Write((byte)fireSources.Count, 4);
foreach (FireSource fireSource in fireSources) for (int i = 0; i < Math.Min(fireSources.Count, 16) ;i++ )
{ {
var fireSource = fireSources[i];
Vector2 normalizedPos = new Vector2( Vector2 normalizedPos = new Vector2(
(fireSource.Position.X - rect.X) / rect.Width, (fireSource.Position.X - rect.X) / rect.Width,
(fireSource.Position.Y - (rect.Y - rect.Height))/rect.Height); (fireSource.Position.Y - (rect.Y - rect.Height)) / rect.Height);
message.WriteRangedSingle(MathHelper.Clamp(normalizedPos.X, 0.0f, 1.0f), 0.0f, 1.0f, 4); message.WriteRangedSingle(MathHelper.Clamp(normalizedPos.X, 0.0f, 1.0f), 0.0f, 1.0f, 4);
message.WriteRangedSingle(MathHelper.Clamp(normalizedPos.Y, 0.0f, 1.0f), 0.0f, 1.0f, 4); message.WriteRangedSingle(MathHelper.Clamp(normalizedPos.Y, 0.0f, 1.0f), 0.0f, 1.0f, 4);
message.WriteRangedSingle(MathHelper.Clamp(fireSource.Size.X / rect.Width, 0.0f, 1.0f), 0, 1.0f, 6);
} }
return true; return true;
@@ -680,8 +695,10 @@ namespace Barotrauma
for (int i = 0; i < fireSourceCount; i++) for (int i = 0; i < fireSourceCount; i++)
{ {
Vector2 pos = Vector2.Zero; Vector2 pos = Vector2.Zero;
float size = 0.0f;
pos.X = message.ReadRangedSingle(0.0f, 1.0f, 4); pos.X = message.ReadRangedSingle(0.0f, 1.0f, 4);
pos.Y = message.ReadRangedSingle(0.0f, 1.0f, 4); pos.Y = message.ReadRangedSingle(0.0f, 1.0f, 4);
size = message.ReadRangedSingle(0.0f, 1.0f, 6);
if (!MathUtils.IsValid(pos)) continue; if (!MathUtils.IsValid(pos)) continue;
pos.X = MathHelper.Clamp(pos.X, 0.05f, 0.95f); pos.X = MathHelper.Clamp(pos.X, 0.05f, 0.95f);
@@ -694,10 +711,16 @@ namespace Barotrauma
{ {
newFireSources.Add(existingFire); newFireSources.Add(existingFire);
existingFire.Position = pos; existingFire.Position = pos;
existingFire.Size = new Vector2(
existingFire.Hull == null ? size : size*existingFire.Hull.rect.Width,
existingFire.Size.Y);
} }
else else
{ {
var newFire = new FireSource(pos, this, true); var newFire = new FireSource(pos + Submarine.Loaded.Position, this, true);
newFire.Size = new Vector2(
newFire.Hull == null ? size : size * newFire.Hull.rect.Width,
newFire.Size.Y);
//ignore if the fire wasn't added to this room (invalid position)? //ignore if the fire wasn't added to this room (invalid position)?
if (!fireSources.Contains(newFire)) continue; if (!fireSources.Contains(newFire)) continue;
+6 -1
View File
@@ -26,6 +26,8 @@ namespace Barotrauma.Lights
//what was the range of the light when HullsInRange were last updated //what was the range of the light when HullsInRange were last updated
private float prevHullUpdateRange; private float prevHullUpdateRange;
private Vector2 prevHullUpdatePosition;
private Vector2 position; private Vector2 position;
public Vector2 Position public Vector2 Position
{ {
@@ -33,9 +35,12 @@ namespace Barotrauma.Lights
set set
{ {
if (position == value) return; if (position == value) return;
position = value; position = value;
if (Vector2.Distance(prevHullUpdatePosition, position) < 5.0f) return;
UpdateHullsInRange(); UpdateHullsInRange();
prevHullUpdatePosition = position;
} }
} }
+1 -1
View File
@@ -597,7 +597,7 @@ namespace Barotrauma.Networking
{ {
if (!gameStarted) yield return CoroutineStatus.Success; if (!gameStarted) yield return CoroutineStatus.Success;
GameMain.GameSession.gameMode.End(endMessage); if (GameMain.GameSession != null) GameMain.GameSession.gameMode.End(endMessage);
//var messageBox = new GUIMessageBox("The round has ended", endMessage, 400, 300); //var messageBox = new GUIMessageBox("The round has ended", endMessage, 400, 300);
+1 -2
View File
@@ -30,8 +30,7 @@ namespace Barotrauma
renderTarget = new RenderTarget2D(graphics, GameMain.GraphicsWidth, GameMain.GraphicsHeight); renderTarget = new RenderTarget2D(graphics, GameMain.GraphicsWidth, GameMain.GraphicsHeight);
renderTargetWater = new RenderTarget2D(graphics, GameMain.GraphicsWidth, GameMain.GraphicsHeight); renderTargetWater = new RenderTarget2D(graphics, GameMain.GraphicsWidth, GameMain.GraphicsHeight);
renderTargetAir = new RenderTarget2D(graphics, GameMain.GraphicsWidth, GameMain.GraphicsHeight); renderTargetAir = new RenderTarget2D(graphics, GameMain.GraphicsWidth, GameMain.GraphicsHeight);
BackgroundCreatureManager = new BackgroundCreatureManager("Content/BackgroundSprites/BackgroundCreaturePrefabs.xml"); BackgroundCreatureManager = new BackgroundCreatureManager("Content/BackgroundSprites/BackgroundCreaturePrefabs.xml");
} }
+10
View File
@@ -1,3 +1,13 @@
---------------------------------------------------------------------------------------------------------
v0.3.0.2
---------------------------------------------------------------------------------------------------------
- fixed crashing when picking up a thermal artifact outside the sub
- fixed clients crashing if in the lobby when a round ends
- fixed crashing when attempting to join a password-protected server
- camera position is set at the position of the sub when entering spectator mode
- AI crew equips a diving suit before going outside the sub
--------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------
v0.3.0.1 v0.3.0.1
Binary file not shown.