Merge branch 'master' into new-netcode

Conflicts:
	Subsurface/Properties/AssemblyInfo.cs
	Subsurface/Source/Items/Components/DockingPort.cs
	Subsurface/Source/Items/Components/Signal/Wire.cs
	Subsurface/Source/Items/Item.cs
This commit is contained in:
Regalis
2016-12-29 22:18:27 +02:00
134 changed files with 1799 additions and 683 deletions
+9 -1
View File
@@ -57,7 +57,15 @@ namespace Barotrauma
}
else
{
PlaySound((aiController == null) ? AIController.AiState.None : aiController.State);
switch (aiController.State)
{
case AIController.AiState.Attack:
PlaySound(CharacterSound.SoundType.Attack);
break;
default:
PlaySound(CharacterSound.SoundType.Idle);
break;
}
soundTimer = soundInterval;
}
@@ -205,15 +205,15 @@ namespace Barotrauma
if (Limbs[i].SteerForce <= 0.0f) continue;
Vector2 pullPos = Limbs[i].pullJoint == null ? Limbs[i].SimPosition : Limbs[i].pullJoint.WorldAnchorA;
Limbs[i].body.ApplyForce(movement * Limbs[i].SteerForce * Limbs[i].Mass, pullPos);
Limbs[i].body.ApplyForce(movement * Limbs[i].SteerForce * Limbs[i].Mass, pullPos);
if (Limbs[i] == MainLimb) continue;
/*if (Limbs[i] == MainLimb) continue;
float dist = (MainLimb.SimPosition - Limbs[i].SimPosition).Length();
Vector2 limbPos = MainLimb.SimPosition - Vector2.Normalize(movement) * dist;
Limbs[i].body.ApplyForce(((limbPos - Limbs[i].SimPosition) * 3.0f - Limbs[i].LinearVelocity * 3.0f) * Limbs[i].Mass);
Limbs[i].body.ApplyForce(((limbPos - Limbs[i].SimPosition) * 3.0f - Limbs[i].LinearVelocity * 3.0f) * Limbs[i].Mass);*/
}
Collider.LinearVelocity = Vector2.Lerp(Collider.LinearVelocity, movement, 0.5f);
@@ -173,12 +173,10 @@ namespace Barotrauma
levitatingCollider = false;
UpdateClimbing();
break;
case Animation.UsingConstruction:
UpdateStanding();
break;
case Animation.CPR:
UpdateCPR(deltaTime);
break;
case Animation.UsingConstruction:
default:
if (character.SelectedCharacter != null) DragCharacter(character.SelectedCharacter);
@@ -260,9 +258,9 @@ namespace Barotrauma
float slowdownAmount = 0.0f;
if (currentHull != null)
{
//full slowdown (1.0f) when water is up to the torso
//full slowdown (1.5f) when water is up to the torso
surfaceY = ConvertUnits.ToSimUnits(currentHull.Surface);
slowdownAmount = MathHelper.Clamp((surfaceY - colliderPos.Y) / torsoPosition, 0.0f, 1.0f);
slowdownAmount = MathHelper.Clamp((surfaceY - colliderPos.Y) / torsoPosition, 0.0f, 1.0f) * 1.5f;
}
float maxSpeed = Math.Max(TargetMovement.Length() - slowdownAmount, 1.0f);
@@ -272,7 +270,7 @@ namespace Barotrauma
float walkPosX = (float)Math.Cos(walkPos);
float walkPosY = (float)Math.Sin(walkPos);
float runningModifier = (float)Math.Max(Math.Min(Math.Abs(TargetMovement.X), 3.0f) / 1.5f, 1.0);
Vector2 stepSize = new Vector2(
this.stepSize.X * walkPosX * runningModifier,
this.stepSize.Y * walkPosY * runningModifier * runningModifier);
@@ -567,7 +565,7 @@ namespace Barotrauma
rotation = MathHelper.ToDegrees(rotation);
if (rotation < 0.0f) rotation += 360;
if (!character.IsRemotePlayer && !aiming)
if (!character.IsRemotePlayer && !aiming && Anim != Animation.UsingConstruction)
{
if (rotation > 20 && rotation < 170)
TargetDir = Direction.Left;
@@ -751,9 +749,9 @@ namespace Barotrauma
ladderSimPos += character.SelectedConstruction.Submarine.SimPosition - currentHull.Submarine.SimPosition;
}
MoveLimb(head, new Vector2(ladderSimPos.X - 0.27f * Dir, Collider.SimPosition.Y + 0.7f - colliderHeightFromFloor), 10.5f);
MoveLimb(torso, new Vector2(ladderSimPos.X - 0.27f * Dir, Collider.SimPosition.Y + 0.5f - colliderHeightFromFloor), 10.5f);
MoveLimb(waist, new Vector2(ladderSimPos.X - 0.35f * Dir, Collider.SimPosition.Y + 0.4f - colliderHeightFromFloor), 10.5f);
MoveLimb(head, new Vector2(ladderSimPos.X - 0.27f * Dir, Collider.SimPosition.Y + 0.9f - colliderHeightFromFloor), 10.5f);
MoveLimb(torso, new Vector2(ladderSimPos.X - 0.27f * Dir, Collider.SimPosition.Y + 0.7f - colliderHeightFromFloor), 10.5f);
MoveLimb(waist, new Vector2(ladderSimPos.X - 0.35f * Dir, Collider.SimPosition.Y + 0.6f - colliderHeightFromFloor), 10.5f);
Collider.MoveToPos(new Vector2(ladderSimPos.X - 0.2f * Dir, Collider.SimPosition.Y), 10.5f);
@@ -761,9 +759,9 @@ namespace Barotrauma
Vector2 handPos = new Vector2(
ladderSimPos.X,
Collider.SimPosition.Y + 0.6f + movement.Y * 0.1f - ladderSimPos.Y);
Collider.SimPosition.Y + 0.8f + movement.Y * 0.1f - ladderSimPos.Y);
handPos.Y = Math.Min(-0.5f, handPos.Y) - colliderHeightFromFloor;
handPos.Y = Math.Min(-0.2f, handPos.Y) - colliderHeightFromFloor;
MoveLimb(leftHand,
new Vector2(handPos.X,
@@ -780,7 +778,7 @@ namespace Barotrauma
Vector2 footPos = new Vector2(
handPos.X - Dir * 0.05f,
Collider.SimPosition.Y + 0.7f - colliderHeightFromFloor - stepHeight * 2.7f - ladderSimPos.Y - 0.7f);
Collider.SimPosition.Y + 0.9f - colliderHeightFromFloor - stepHeight * 2.7f - ladderSimPos.Y - 0.7f);
//if (movement.Y < 0) footPos.Y += 0.05f;
@@ -372,7 +372,8 @@ namespace Barotrauma
foreach (Limb limb in Limbs)
{
limb.sprite.Depth = startDepth + limb.sprite.Depth * 0.0001f;
if (limb.sprite != null)
limb.sprite.Depth = startDepth + limb.sprite.Depth * 0.0001f;
}
Limb torso = GetLimb(LimbType.Torso);
@@ -638,27 +639,31 @@ namespace Barotrauma
}
for (int i = 0; i < Limbs.Length; i++)
foreach (Limb limb in Limbs)
{
if (Limbs[i] == null) continue;
if (limb == null) continue;
Vector2 spriteOrigin = Limbs[i].sprite.Origin;
spriteOrigin.X = Limbs[i].sprite.SourceRect.Width - spriteOrigin.X;
Limbs[i].sprite.Origin = spriteOrigin;
Limbs[i].Dir = Dir;
if (Limbs[i].LightSource != null)
if (limb.sprite != null)
{
Limbs[i].LightSource.SpriteEffect = (dir == Direction.Left) ? SpriteEffects.FlipHorizontally : SpriteEffects.None;
Vector2 spriteOrigin = limb.sprite.Origin;
spriteOrigin.X = limb.sprite.SourceRect.Width - spriteOrigin.X;
limb.sprite.Origin = spriteOrigin;
}
if (Limbs[i].pullJoint == null) continue;
limb.Dir = Dir;
Limbs[i].pullJoint.LocalAnchorA =
new Vector2(
-Limbs[i].pullJoint.LocalAnchorA.X,
Limbs[i].pullJoint.LocalAnchorA.Y);
if (limb.LightSource != null)
{
limb.LightSource.FlipX();
}
if (limb.pullJoint != null)
{
limb.pullJoint.LocalAnchorA =
new Vector2(
-limb.pullJoint.LocalAnchorA.X,
limb.pullJoint.LocalAnchorA.Y);
}
}
}
@@ -864,6 +869,7 @@ namespace Barotrauma
{
//limb isn't in any room -> it's in the water
limb.inWater = true;
if (limb.type == LimbType.Head) headInWater = true;
}
else if (limbHull.Volume > 0.0f && Submarine.RectContains(limbHull.Rect, limb.Position))
{
+25 -46
View File
@@ -144,10 +144,7 @@ namespace Barotrauma
private float bleeding;
private Sound[] sounds;
private float[] soundRange;
//which AIstate each sound is for
private AIController.AiState[] soundStates;
private List<CharacterSound> sounds;
private float attackCoolDown;
@@ -603,28 +600,13 @@ namespace Barotrauma
soundInterval = ToolBox.GetAttributeFloat(doc.Root, "soundinterval", 10.0f);
var soundElements = doc.Root.Elements("sound").ToList();
if (soundElements.Any())
sounds = new List<CharacterSound>();
foreach (XElement soundElement in soundElements)
{
sounds = new Sound[soundElements.Count];
soundStates = new AIController.AiState[soundElements.Count];
soundRange = new float[soundElements.Count];
int i = 0;
foreach (XElement soundElement in soundElements)
{
sounds[i] = Sound.Load(soundElement.Attribute("file").Value);
soundRange[i] = ToolBox.GetAttributeFloat(soundElement, "range", 1000.0f);
if (soundElement.Attribute("state") == null)
{
soundStates[i] = AIController.AiState.None;
}
else
{
soundStates[i] = (AIController.AiState)Enum.Parse(
typeof(AIController.AiState), soundElement.Attribute("state").Value, true);
}
i++;
}
sounds.Add(new CharacterSound(soundElement));
}
if (file == humanConfigFile)
{
@@ -1536,8 +1518,14 @@ namespace Barotrauma
private void UpdateOxygen(float deltaTime)
{
float prevOxygen = oxygen;
Oxygen += deltaTime * (oxygenAvailable < 30.0f ? -5.0f : 10.0f);
if (prevOxygen > 0.0f && Oxygen <= 0.0f && controlled == this)
{
SoundPlayer.PlaySound("drown");
}
PressureProtection -= deltaTime * 100.0f;
float hullAvailableOxygen = 0.0f;
@@ -1678,6 +1666,8 @@ namespace Barotrauma
/// </summary>
public HUDProgressBar UpdateHUDProgressBar(object linkedObject, Vector2 worldPosition, float progress, Color emptyColor, Color fullColor)
{
if (controlled != this) return null;
HUDProgressBar progressBar = null;
if (!hudProgressBars.TryGetValue(linkedObject, out progressBar))
{
@@ -1692,24 +1682,15 @@ namespace Barotrauma
return progressBar;
}
public void PlaySound(AIController.AiState state)
public void PlaySound(CharacterSound.SoundType soundType)
{
if (sounds == null || !sounds.Any()) return;
var matchingSoundStates = soundStates.Where(x => x == state).ToList();
if (sounds == null || sounds.Count == 0) return;
int selectedSound = Rand.Int(matchingSoundStates.Count);
var matchingSounds = sounds.FindAll(s => s.Type == soundType);
if (matchingSounds.Count == 0) return;
int n = 0;
for (int i = 0; i < sounds.Length; i++)
{
if (soundStates[i] != state) continue;
if (n == selectedSound && sounds[i]!=null)
{
sounds[i].Play(1.0f, soundRange[i], AnimController.Limbs[0].WorldPosition);
return;
}
n++;
}
var selectedSound = matchingSounds[Rand.Int(matchingSounds.Count)];
selectedSound.Sound.Play(1.0f, selectedSound.Range, AnimController.WorldPosition);
}
public virtual void AddDamage(CauseOfDeath causeOfDeath, float amount, IDamageable attacker)
@@ -1810,7 +1791,7 @@ namespace Barotrauma
// limb.Damage = 100.0f;
}
SoundPlayer.PlayDamageSound(DamageSoundType.Implode, 50.0f, AnimController.Collider);
SoundPlayer.PlaySound("implode", 1.0f, 150.0f, WorldPosition);
for (int i = 0; i < 10; i++)
{
@@ -1861,11 +1842,9 @@ namespace Barotrauma
GameServer.Log(Name+" has died (Cause of death: "+causeOfDeath+")", Color.Red);
if (OnDeath != null) OnDeath(this, causeOfDeath);
//CoroutineManager.StartCoroutine(DeathAnim(GameMain.GameScreen.Cam));
//health = 0.0f;
PlaySound(CharacterSound.SoundType.Die);
isDead = true;
this.causeOfDeath = causeOfDeath;
AnimController.movement = Vector2.Zero;
@@ -1876,7 +1855,7 @@ namespace Barotrauma
if (selectedItems[i] != null) selectedItems[i].Drop(this);
}
if (aiTarget!=null)
if (aiTarget != null)
{
aiTarget.Remove();
aiTarget = null;
@@ -138,6 +138,7 @@ namespace Barotrauma
{
if (character.Inventory != null && !character.LockHands && character.Stun >= -0.1f)
{
character.Inventory.DrawOffset = Vector2.Zero;
character.Inventory.DrawOwn(spriteBatch);
}
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace Barotrauma
{
class CharacterSound
{
public enum SoundType
{
Idle, Attack, Die
}
public readonly Sound Sound;
public readonly SoundType Type;
public readonly float Range;
public CharacterSound(XElement element)
{
Sound = Sound.Load(element.Attribute("file").Value);
Range = ToolBox.GetAttributeFloat(element, "range", 1000.0f);
Enum.TryParse<SoundType>(ToolBox.GetAttributeString(element, "state", "Idle"), true, out Type);
}
}
}
+19 -13
View File
@@ -423,7 +423,6 @@ namespace Barotrauma
if (LightSource != null)
{
LightSource.ParentSub = body.Submarine;
LightSource.Position = Position;
}
if (!character.IsDead) damage = Math.Max(0.0f, damage-deltaTime*0.1f);
@@ -504,6 +503,12 @@ namespace Barotrauma
body.UpdateDrawPosition();
}
if (LightSource != null)
{
LightSource.Position = body.DrawPosition;
LightSource.Rotation = body.DrawRotation;
}
foreach (WearableSprite wearable in wearingItems)
{
SpriteEffects spriteEffect = (dir == Direction.Right) ? SpriteEffects.None : SpriteEffects.FlipHorizontally;
@@ -528,36 +533,37 @@ namespace Barotrauma
-body.DrawRotation,
scale, spriteEffect, depth);
}
if (damage>0.0f && damagedSprite!=null && !hideLimb)
if (damage > 0.0f && damagedSprite != null && !hideLimb)
{
SpriteEffects spriteEffect = (dir == Direction.Right) ? SpriteEffects.None : SpriteEffects.FlipHorizontally;
float depth = sprite.Depth - 0.0000015f;
damagedSprite.Draw(spriteBatch,
new Vector2(body.DrawPosition.X, -body.DrawPosition.Y),
color*Math.Min(damage/50.0f,1.0f), sprite.Origin,
color * Math.Min(damage / 50.0f, 1.0f), sprite.Origin,
-body.DrawRotation,
1.0f, spriteEffect, depth);
}
if (!GameMain.DebugDraw) return;
if (pullJoint!=null)
if (pullJoint != null)
{
Vector2 pos = ConvertUnits.ToDisplayUnits(pullJoint.WorldAnchorB);
GUI.DrawRectangle(spriteBatch, new Rectangle((int)pos.X, (int)-pos.Y, 5, 5), Color.Red, true);
}
}
}
public void Remove()
{
sprite.Remove();
sprite = null;
if (sprite != null)
{
sprite.Remove();
sprite = null;
}
if (LightSource != null)
{