Merge branch 'NewCoordinateSystem'

Conflicts:
	Subsurface/Barotrauma.csproj
	Subsurface_Solution.v12.suo
This commit is contained in:
Regalis
2015-12-17 18:29:26 +02:00
105 changed files with 2401 additions and 1288 deletions

View File

@@ -27,6 +27,11 @@ namespace Barotrauma
set { sightRange = value; }
}
public Vector2 WorldPosition
{
get { return Entity.WorldPosition; }
}
public Vector2 SimPosition
{
get { return Entity.SimPosition; }

View File

@@ -64,6 +64,8 @@ namespace Barotrauma
public EnemyAIController(Character c, string file) : base(c)
{
if (GameMain.Client != null && GameMain.Server == null) c.Enabled = false;
targetMemories = new Dictionary<AITarget, AITargetMemory>();
XDocument doc = ToolBox.TryLoadXml(file);
@@ -167,12 +169,17 @@ namespace Barotrauma
selectedTargetMemory.Priority -= deltaTime;
Vector2 attackPosition = selectedAiTarget.SimPosition;
if (wallAttackPos != Vector2.Zero) attackPosition = wallAttackPos;
Vector2 attackSimPosition = Character.Submarine==null ? ConvertUnits.ToSimUnits(selectedAiTarget.WorldPosition) : selectedAiTarget.SimPosition;
if (wallAttackPos != Vector2.Zero && targetEntity != null)
{
attackSimPosition = wallAttackPos;
if (selectedAiTarget.Entity != null && Character.Submarine==null && selectedAiTarget.Entity.Submarine != null) attackSimPosition += ConvertUnits.ToSimUnits(selectedAiTarget.Entity.Submarine.Position);
}
if (coolDownTimer>0.0f)
{
UpdateCoolDown(attackPosition, deltaTime);
UpdateCoolDown(attackSimPosition, deltaTime);
return;
}
@@ -187,7 +194,8 @@ namespace Barotrauma
raycastTimer = RaycastInterval;
}
steeringManager.SteeringSeek(attackPosition);
steeringManager.SteeringAvoid(deltaTime, 1.0f);
steeringManager.SteeringSeek(attackSimPosition);
//check if any of the limbs is close enough to attack the target
if (attackingLimb == null)
@@ -195,7 +203,7 @@ namespace Barotrauma
foreach (Limb limb in Character.AnimController.Limbs)
{
if (limb.attack==null || limb.attack.Type == AttackType.None) continue;
if (Vector2.Distance(limb.SimPosition, attackPosition) > limb.attack.Range) continue;
if (ConvertUnits.ToDisplayUnits(Vector2.Distance(limb.SimPosition, attackSimPosition)) > limb.attack.Range) continue;
attackingLimb = limb;
break;
@@ -203,7 +211,7 @@ namespace Barotrauma
return;
}
UpdateLimbAttack(deltaTime, attackingLimb, attackPosition);
UpdateLimbAttack(deltaTime, attackingLimb, attackSimPosition);
}
@@ -230,9 +238,19 @@ namespace Barotrauma
private void GetTargetEntity()
{
targetEntity = null;
//check if there's a wall between the target and the Character
Vector2 rayStart = Character.AnimController.Limbs[0].SimPosition;
Vector2 rayStart = Character.SimPosition;
Vector2 rayEnd = selectedAiTarget.SimPosition;
if (selectedAiTarget.Entity.Submarine!=null && Character.Submarine==null)
{
rayStart -= ConvertUnits.ToSimUnits(selectedAiTarget.Entity.Submarine.Position);
}
Body closestBody = Submarine.CheckVisibility(rayStart, rayEnd);
if (Submarine.LastPickedFraction == 1.0f || closestBody == null)
@@ -245,6 +263,8 @@ namespace Barotrauma
if (wall == null)
{
wallAttackPos = Submarine.LastPickedPosition;
if (selectedAiTarget.Entity.Submarine!=null) wallAttackPos -= ConvertUnits.ToSimUnits(selectedAiTarget.Entity.Submarine.Position);
}
else
{
@@ -261,6 +281,7 @@ namespace Barotrauma
if (wall.SectionDamage(i) > sectionDamage) sectionIndex = i;
}
wallAttackPos = wall.SectionPosition(sectionIndex);
//if (wall.Submarine != null) wallAttackPos += wall.Submarine.Position;
wallAttackPos = ConvertUnits.ToSimUnits(wallAttackPos);
}
@@ -288,15 +309,8 @@ namespace Barotrauma
float dir = (limb.attack.Type == AttackType.PinchCW) ? 1.0f : -1.0f;
if (wallAttackPos != Vector2.Zero && targetEntity != null)
{
damageTarget = targetEntity as IDamageable;
}
else
{
damageTarget = selectedAiTarget.Entity as IDamageable;
}
damageTarget = (wallAttackPos != Vector2.Zero && targetEntity != null) ? targetEntity : selectedAiTarget.Entity as IDamageable;
attackTimer += deltaTime*0.05f;
if (damageTarget == null)
@@ -305,13 +319,13 @@ namespace Barotrauma
break;
}
float dist = Vector2.Distance(limb.SimPosition, damageTarget.SimPosition);
float dist = ConvertUnits.ToDisplayUnits(Vector2.Distance(limb.SimPosition, attackPosition));
if (dist < limb.attack.Range * 0.5f)
{
attackTimer += deltaTime;
limb.body.ApplyTorque(limb.Mass * 50.0f * Character.AnimController.Dir * dir);
limb.attack.DoDamage(Character, damageTarget, limb.SimPosition, deltaTime, (limb.soundTimer <= 0.0f));
limb.attack.DoDamage(Character, damageTarget, limb.WorldPosition, deltaTime, (limb.soundTimer <= 0.0f));
limb.soundTimer = Limb.SoundInterval;
}
@@ -392,9 +406,8 @@ namespace Barotrauma
}
dist = Vector2.Distance(
character.AnimController.Limbs[0].SimPosition,
target.SimPosition);
dist = ConvertUnits.ToDisplayUnits(dist);
character.WorldPosition,
target.WorldPosition);
AITargetMemory targetMemory = FindTargetMemory(target);
@@ -406,6 +419,11 @@ namespace Barotrauma
Vector2 rayStart = character.AnimController.Limbs[0].SimPosition;
Vector2 rayEnd = target.SimPosition;
if (target.Entity.Submarine != null && character.Submarine==null)
{
rayStart -= ConvertUnits.ToSimUnits(target.Entity.Submarine.Position);
}
Body closestBody = Submarine.CheckVisibility(rayStart, rayEnd);
Structure closestStructure = (closestBody == null) ? null : closestBody.UserData as Structure;
@@ -490,12 +508,12 @@ namespace Barotrauma
{
if (Character.IsDead) return;
Vector2 pos = Character.Position;
Vector2 pos = Character.WorldPosition;
pos.Y = -pos.Y;
if (selectedAiTarget!=null)
{
GUI.DrawLine(spriteBatch, pos, ConvertUnits.ToDisplayUnits(new Vector2(selectedAiTarget.SimPosition.X, -selectedAiTarget.SimPosition.Y)), Color.Red);
GUI.DrawLine(spriteBatch, pos, new Vector2(selectedAiTarget.WorldPosition.X, -selectedAiTarget.WorldPosition.Y), Color.Red);
if (wallAttackPos!=Vector2.Zero)
{

View File

@@ -28,6 +28,8 @@ namespace Barotrauma
objectiveManager = new AIObjectiveManager(c);
objectiveManager.AddObjective(new AIObjectiveFindSafety(c));
objectiveManager.AddObjective(new AIObjectiveIdle(c));
updateObjectiveTimer = Rand.Range(0.0f, UpdateObjectiveInterval);
}
public override void Update(float deltaTime)
@@ -87,7 +89,9 @@ namespace Barotrauma
{
if (selectedAiTarget != null)
{
GUI.DrawLine(spriteBatch, new Vector2(Character.Position.X, -Character.Position.Y), ConvertUnits.ToDisplayUnits(new Vector2(selectedAiTarget.SimPosition.X, -selectedAiTarget.SimPosition.Y)), Color.Red);
GUI.DrawLine(spriteBatch,
new Vector2(Character.WorldPosition.X, -Character.WorldPosition.Y),
new Vector2(selectedAiTarget.WorldPosition.X, -selectedAiTarget.WorldPosition.Y), Color.Red);
}
IndoorsSteeringManager pathSteering = steeringManager as IndoorsSteeringManager;

View File

@@ -40,6 +40,8 @@ namespace Barotrauma
this.canOpenDoors = canOpenDoors;
character = (host as AIController).Character;
findPathTimer = Rand.Range(0.0f, 1.0f);
}
public override void Update(float speed = 1)
@@ -65,9 +67,9 @@ namespace Barotrauma
if (findPathTimer > 0.0f) return Vector2.Zero;
currentTarget = target;
currentPath = pathFinder.FindPath(host.SimPosition, target);
currentPath = pathFinder.FindPath(host.SimPosition+Rand.Vector(0.2f), target);
findPathTimer = 1.0f;
findPathTimer = Rand.Range(1.0f,1.2f);
return DiffToCurrentNode();
}

View File

@@ -92,10 +92,7 @@ namespace Barotrauma
if (Vector2.Distance(character.SimPosition, enemy.SimPosition) < 3.0f)
{
character.AIController.SteeringManager.SteeringManual(deltaTime, character.SimPosition - enemy.SimPosition);
}
else
{
character.AIController.SteeringManager.SteeringManual(deltaTime, (character.SimPosition - enemy.SimPosition)*0.1f);
coolDownTimer = CoolDown;
}
}

View File

@@ -57,17 +57,34 @@ namespace Barotrauma
character.AIController.SteeringManager.SteeringSeek(
target != null ? target.SimPosition : targetPos);
Vector2 currTargetPos = target != null ? target.SimPosition : targetPos;
if (Vector2.Distance(currTargetPos, character.SimPosition) < 1.0f)
{
character.AnimController.TargetDir = currTargetPos.X > character.SimPosition.X ? Direction.Right : Direction.Left;
}
}
public override bool IsCompleted()
{
if (repeat) return false;
bool completed = false;
float allowedDistance = 0.5f;
var item = target as Item;
if (item != null) allowedDistance = Math.Max(item.PickDistance,allowedDistance);
return Vector2.Distance(target != null ? target.SimPosition : targetPos, character.SimPosition) < allowedDistance;
if (item != null)
{
allowedDistance = Math.Max(item.PickDistance, allowedDistance);
if (item.IsInsideTrigger(character.WorldPosition)) completed = true;
}
completed = completed || Vector2.Distance(target != null ? target.SimPosition : targetPos, character.SimPosition) < allowedDistance;
if (completed) character.AIController.SteeringManager.SteeringManual(0.0f, -character.AIController.Steering);
return completed;
}
public override bool IsDuplicate(AIObjective otherObjective)

View File

@@ -31,6 +31,11 @@ namespace Barotrauma
var pathSteering = character.AIController.SteeringManager as IndoorsSteeringManager;
if (pathSteering==null)
{
return;
}
if (newTargetTimer <= 0.0f)
{
currentTarget = FindRandomTarget();
@@ -54,15 +59,19 @@ namespace Barotrauma
(pathSteering.CurrentPath.NextNode == null || pathSteering.CurrentPath.Unreachable)))
{
//steer away from edges of the hull
if (character.Position.X < character.AnimController.CurrentHull.Rect.X + WallAvoidDistance)
if (character.AnimController.CurrentHull!=null)
{
pathSteering.SteeringManual(deltaTime, Vector2.UnitX);
}
else if (character.Position.X > character.AnimController.CurrentHull.Rect.Right - WallAvoidDistance)
{
pathSteering.SteeringManual(deltaTime, -Vector2.UnitX);
if (character.Position.X < character.AnimController.CurrentHull.Rect.X + WallAvoidDistance)
{
pathSteering.SteeringManual(deltaTime, Vector2.UnitX*5.0f);
}
else if (character.Position.X > character.AnimController.CurrentHull.Rect.Right - WallAvoidDistance)
{
pathSteering.SteeringManual(deltaTime, -Vector2.UnitX);
}
}
character.AIController.SteeringManager.SteeringWander(1.0f);
return;
}
@@ -80,8 +89,8 @@ namespace Barotrauma
foreach (WayPoint wp in WayPoint.WayPointList)
{
if (wp.SpawnType != SpawnType.Human) continue;
if (wp.SpawnType != SpawnType.Human || wp.CurrentHull==null) continue;
foreach (string tag in wp.IdCardTags)
{
if (idCard.HasTag(tag)) return wp.CurrentHull.AiTarget;

View File

@@ -30,7 +30,7 @@ namespace Barotrauma
ItemComponent target = itemController == null ? targetItem: itemController;
if (Vector2.Distance(character.SimPosition, target.Item.SimPosition) < target.Item.PickDistance
|| target.Item.IsInsideTrigger(character.Position))
|| target.Item.IsInsideTrigger(character.WorldPosition))
{
if (character.SelectedConstruction != target.Item && target.CanBeSelected)
{

View File

@@ -218,7 +218,7 @@ namespace Barotrauma
//a node that hasn't been searched yet
if (nextNode.state==0)
{
nextNode.H = Vector2.DistanceSquared(nextNode.Position,end.Position);
nextNode.H = Vector2.Distance(nextNode.Position,end.Position);
if (GetNodePenalty != null)
{

View File

@@ -144,11 +144,14 @@ namespace Barotrauma
avoidSteering = Vector2.Normalize(Submarine.LastPickedPosition - obstaclePosition);
}
else
else if (closestBody.UserData is Item)
{
Item item = closestBody.UserData as Item;
if (item != null) avoidSteering = Vector2.Normalize(Submarine.LastPickedPosition - item.SimPosition);
avoidSteering = Vector2.Normalize(Submarine.LastPickedPosition - item.SimPosition);
}
else
{
avoidSteering = Vector2.Normalize(host.SimPosition - Submarine.LastPickedPosition);
}
}

View File

@@ -42,7 +42,7 @@ namespace Barotrauma
public AICharacter(string file, Vector2 position, CharacterInfo characterInfo = null, bool isNetworkPlayer = false)
: base(file, position, characterInfo, isNetworkPlayer)
{
if (GameMain.Client != null && GameMain.Server == null) Enabled = false;
soundInterval = Rand.Range(0.0f, soundInterval);
}
public void SetAI(AIController aiController)
@@ -94,15 +94,14 @@ namespace Barotrauma
case NetworkEventType.KillCharacter:
return true;
case NetworkEventType.ImportantEntityUpdate:
int i = 0;
//foreach (Limb limb in AnimController.Limbs)
//{
//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.WriteRangedSingle(AnimController.RefLimb.SimPosition.Y, -NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16);
message.Write(AnimController.RefLimb.SimPosition.X);
message.Write(AnimController.RefLimb.SimPosition.Y);
message.Write(AnimController.RefLimb.Rotation);
@@ -115,14 +114,23 @@ namespace Barotrauma
aiController.FillNetworkData(message);
return true;
case NetworkEventType.EntityUpdate:
if (AnimController.RefLimb.SimPosition.Length() > NetConfig.CharacterIgnoreDistance) return false;
if (Submarine == null)
{
if ((AnimController.RefLimb.SimPosition - Submarine.Loaded.SimPosition).Length() > NetConfig.CharacterIgnoreDistance) return false;
}
else
{
if (AnimController.RefLimb.SimPosition.Length() > NetConfig.CharacterIgnoreDistance) return false;
}
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(AnimController.RefLimb.SimPosition.X, -NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16);
message.WriteRangedSingle(AnimController.RefLimb.SimPosition.Y, -NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16);
message.Write(AnimController.RefLimb.SimPosition.X);
message.Write(AnimController.RefLimb.SimPosition.Y);
return true;
}
@@ -150,8 +158,8 @@ namespace Barotrauma
try
{
limbPos.X = message.ReadRangedSingle(-NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16);
limbPos.Y = message.ReadRangedSingle(-NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16);
limbPos.X = message.ReadFloat();
limbPos.Y = message.ReadFloat();
rotation = message.ReadFloat();
}
@@ -197,8 +205,8 @@ namespace Barotrauma
targetMovement.X = 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.Y = message.ReadRangedSingle(-NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16);
pos.X = message.ReadFloat();
pos.Y = message.ReadFloat();
//vel.X = message.ReadFloat();
//vel.Y = message.ReadFloat();

View File

@@ -152,7 +152,17 @@ namespace Barotrauma
public Hull CurrentHull
{
get { return currentHull;}
get { return currentHull; }
set
{
if (value == currentHull) return;
currentHull = value;
foreach (Limb limb in Limbs)
{
limb.body.Submarine = currentHull == null ? null : Submarine.Loaded;
}
}
}
public bool IgnorePlatforms
@@ -378,14 +388,14 @@ namespace Barotrauma
float volume = stairs == null ? impact/5.0f : impact;
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.body.FarseerBody);
if (impact > 0.8f && l.HitSound != null && l.soundTimer <= 0.0f) l.HitSound.Play(volume, impact * 100.0f, l.WorldPosition);
if (impact > l.impactTolerance)
{
character.Health -= (impact - l.impactTolerance * 0.1f);
strongestImpact = Math.Max(strongestImpact, impact - l.impactTolerance);
SoundPlayer.PlayDamageSound(DamageSoundType.LimbBlunt, strongestImpact, l.body.FarseerBody);
SoundPlayer.PlayDamageSound(DamageSoundType.LimbBlunt, strongestImpact, l.body);
if (Character.Controlled == character) GameMain.GameScreen.Cam.Shake = strongestImpact;
}
@@ -526,16 +536,28 @@ namespace Barotrauma
}
}
public void FindHull()
public void FindHull(Vector2? worldPosition = null, bool setSubmarine = true)
{
Hull newHull = Hull.FindHull(
ConvertUnits.ToDisplayUnits(refLimb.SimPosition),
currentHull);
Vector2 findPos = worldPosition==null ? refLimb.WorldPosition : (Vector2)worldPosition;
Hull newHull = Hull.FindHull(findPos, currentHull);
if (newHull == currentHull) return;
currentHull = newHull;
if (setSubmarine)
{
if (newHull == null && currentHull.Submarine != null)
{
SetPosition(refLimb.SimPosition + ConvertUnits.ToSimUnits(currentHull.Submarine.Position));
}
else if (currentHull == null && newHull != null && newHull.Submarine != null)
{
SetPosition(refLimb.SimPosition - ConvertUnits.ToSimUnits(newHull.Submarine.Position));
}
}
CurrentHull = newHull;
UpdateCollisionCategories();
}
@@ -597,11 +619,9 @@ namespace Barotrauma
foreach (Limb limb in Limbs)
{
Vector2 limbPosition = ConvertUnits.ToDisplayUnits(limb.SimPosition);
//find the room which the limb is in
//the room where the ragdoll is in is used as the "guess", meaning that it's checked first
Hull limbHull = Hull.FindHull(limbPosition, currentHull);
Hull limbHull = Hull.FindHull(limb.WorldPosition, currentHull);
bool prevInWater = limb.inWater;
limb.inWater = false;
@@ -611,9 +631,9 @@ namespace Barotrauma
//limb isn't in any room -> it's in the water
limb.inWater = true;
}
else if (limbHull.Volume > 0.0f && Submarine.RectContains(limbHull.Rect, limbPosition))
{
if (limbPosition.Y < limbHull.Surface)
else if (limbHull.Volume > 0.0f && Submarine.RectContains(limbHull.Rect, limb.Position))
{
if (limb.Position.Y < limbHull.Surface)
{
limb.inWater = true;
@@ -637,12 +657,12 @@ namespace Barotrauma
//create a splash particle
GameMain.ParticleManager.CreateParticle("watersplash",
new Vector2(limb.Position.X, limbHull.Surface),
new Vector2(limb.Position.X, limbHull.Surface) + limbHull.Submarine.Position,
new Vector2(0.0f, Math.Abs(-limb.LinearVelocity.Y * 10.0f)),
0.0f, limbHull);
GameMain.ParticleManager.CreateParticle("bubbles",
new Vector2(limb.Position.X, limbHull.Surface),
new Vector2(limb.Position.X, limbHull.Surface) + limbHull.Submarine.Position,
limb.LinearVelocity*0.001f,
0.0f, limbHull);
@@ -656,7 +676,7 @@ namespace Barotrauma
float parallel = (float)Math.Abs(Math.Sin(limb.Rotation));
Vector2 impulse = Vector2.Multiply(limb.LinearVelocity, -parallel * limb.Mass);
//limb.body.ApplyLinearImpulse(impulse);
int n = (int)((limbPosition.X - limbHull.Rect.X) / Hull.WaveWidth);
int n = (int)((limb.Position.X - limbHull.Rect.X) / Hull.WaveWidth);
limbHull.WaveVel[n] = Math.Min(impulse.Y * 1.0f, 5.0f);
StrongestImpact = ((impulse.Length() * 0.5f) - limb.impactTolerance);
}

View File

@@ -109,7 +109,7 @@ namespace Barotrauma
sound = Sound.Load(soundPath);
}
Range = FarseerPhysics.ConvertUnits.ToSimUnits(ToolBox.GetAttributeFloat(element, "range", 0.0f));
Range = ToolBox.GetAttributeFloat(element, "range", 0.0f);
Duration = ToolBox.GetAttributeFloat(element, "duration", 0.0f);
@@ -122,7 +122,7 @@ namespace Barotrauma
}
public AttackResult DoDamage(IDamageable attacker, IDamageable target, Vector2 position, float deltaTime, bool playSound = true)
public AttackResult DoDamage(IDamageable attacker, IDamageable target, Vector2 worldPosition, float deltaTime, bool playSound = true)
{
float damageAmount = 0.0f;
//DamageSoundType damageSoundType = DamageSoundType.None;
@@ -139,15 +139,15 @@ namespace Barotrauma
if (particleEmitterPrefab != null)
{
particleEmitterPrefab.Emit(position);
particleEmitterPrefab.Emit(worldPosition);
}
if (sound != null)
{
sound.Play(1.0f, 500.0f, position);
sound.Play(1.0f, 500.0f, worldPosition);
}
return target.AddDamage(attacker, position, this, deltaTime, playSound);
return target.AddDamage(attacker, worldPosition, this, deltaTime, playSound);
}
}

View File

@@ -9,7 +9,7 @@ using System.Xml.Linq;
namespace Barotrauma
{
class BackgroundSprite : ISteerable
class BackgroundCreature : ISteerable
{
const float MaxDepth = 100.0f;
@@ -17,7 +17,7 @@ namespace Barotrauma
public bool Enabled;
private BackgroundSpritePrefab prefab;
private BackgroundCreaturePrefab prefab;
private Vector2 position;
@@ -53,13 +53,13 @@ namespace Barotrauma
set;
}
public BackgroundSprite(BackgroundSpritePrefab prefab, Vector2 position)
public BackgroundCreature(BackgroundCreaturePrefab prefab, Vector2 position)
{
this.prefab = prefab;
this.position = position;
drawPosition = position + Level.Loaded.Position;
drawPosition = position;
steeringManager = new SteeringManager(this);
@@ -105,18 +105,6 @@ namespace Barotrauma
Vector2 midPoint = Swarm.MidPoint();
float midPointDist = Vector2.Distance(position, midPoint);
//steeringManager.SteeringSeek(midPoint + Swarm.AvgVelocity()*1000.0f, prefab.Speed*0.1f);
//float avgWanderAngle = 0.0f;
//foreach (var other in Swarm.Members)
//{
// avgWanderAngle += other.steeringManager.WanderAngle;
//}
//avgWanderAngle /= Swarm.Members.Count;
//steeringManager.WanderAngle = MathHelper.Lerp(steeringManager.WanderAngle, avgWanderAngle, 0.1f);
if (midPointDist > Swarm.MaxDistance)
{
steeringManager.SteeringSeek(midPoint, (midPointDist / Swarm.MaxDistance) * prefab.Speed);
@@ -153,15 +141,15 @@ namespace Barotrauma
if (velocity.X < 0.0f) rotation -= MathHelper.Pi;
}
if (Level.Loaded != null) drawPosition = position + Level.Loaded.Position;
drawPosition = position;// +Level.Loaded.Position;
if (depth > 0.0f)
{
Vector2 camOffset = drawPosition - GameMain.GameScreen.Cam.WorldViewCenter;
drawPosition = drawPosition - camOffset * (depth / MaxDepth) * 0.05f;
drawPosition -= camOffset * (depth / MaxDepth) * 0.05f;
}
prefab.Sprite.Draw(spriteBatch, new Vector2(drawPosition.X, -drawPosition.Y), Color.Lerp(Color.White, Color.DarkBlue, (depth/MaxDepth)*0.3f),
rotation, 1.0f - (depth / MaxDepth) * 0.2f, velocity.X > 0.0f ? SpriteEffects.None : SpriteEffects.FlipHorizontally, (depth / MaxDepth));
}
@@ -169,7 +157,7 @@ namespace Barotrauma
class Swarm
{
public List<BackgroundSprite> Members;
public List<BackgroundCreature> Members;
public readonly float MaxDistance;
@@ -179,7 +167,7 @@ namespace Barotrauma
Vector2 midPoint = Vector2.Zero;
foreach (BackgroundSprite member in Members)
foreach (BackgroundCreature member in Members)
{
midPoint += member.SimPosition;
}
@@ -195,7 +183,7 @@ namespace Barotrauma
Vector2 avgVel = Vector2.Zero;
foreach (BackgroundSprite member in Members)
foreach (BackgroundCreature member in Members)
{
avgVel += member.Velocity;
}
@@ -205,13 +193,13 @@ namespace Barotrauma
return avgVel;
}
public Swarm(List<BackgroundSprite> members, float maxDistance)
public Swarm(List<BackgroundCreature> members, float maxDistance)
{
this.Members = members;
this.MaxDistance = maxDistance;
foreach (BackgroundSprite bgSprite in members)
foreach (BackgroundCreature bgSprite in members)
{
bgSprite.Swarm = this;
}

View File

@@ -0,0 +1,125 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
namespace Barotrauma
{
class BackgroundCreatureManager
{
const int MaxSprites = 100;
const float checkActiveInterval = 1.0f;
float checkActiveTimer;
private List<BackgroundCreaturePrefab> prefabs;
private List<BackgroundCreature> activeSprites;
public BackgroundCreatureManager(string configPath)
{
activeSprites = new List<BackgroundCreature>();
prefabs = new List<BackgroundCreaturePrefab>();
XDocument doc = ToolBox.TryLoadXml(configPath);
if (doc == null || doc.Root == null) return;
foreach (XElement element in doc.Root.Elements())
{
prefabs.Add(new BackgroundCreaturePrefab(element));
}
}
public void SpawnSprites(int count, Vector2? position = null)
{
activeSprites.Clear();
if (prefabs.Count == 0) return;
count = Math.Min(count, MaxSprites);
for (int i = 0; i < count; i++ )
{
Vector2 pos = Vector2.Zero;
if (position == null)
{
var wayPoints = WayPoint.WayPointList.FindAll(wp => wp.Submarine==null);
if (wayPoints.Any())
{
WayPoint wp = wayPoints[Rand.Int(wayPoints.Count)];
pos = new Vector2(wp.Rect.X, wp.Rect.Y);
pos += Rand.Vector(200.0f);
}
else
{
pos = Rand.Vector(2000.0f);
}
}
else
{
pos = (Vector2)position;
}
var prefab = prefabs[Rand.Int(prefabs.Count)];
int amount = Rand.Range(prefab.SwarmMin, prefab.SwarmMax);
List<BackgroundCreature> swarmMembers = new List<BackgroundCreature>();
for (int n = 0; n < amount; n++)
{
var newSprite = new BackgroundCreature(prefab, pos);
activeSprites.Add(newSprite);
swarmMembers.Add(newSprite);
}
if (amount > 0)
{
new Swarm(swarmMembers, prefab.SwarmRadius);
}
}
}
public void ClearSprites()
{
activeSprites.Clear();
}
public void Update(Camera cam, float deltaTime)
{
if (checkActiveTimer<0.0f)
{
foreach (BackgroundCreature sprite in activeSprites)
{
sprite.Enabled = (Math.Abs(sprite.TransformedPosition.X - cam.WorldViewCenter.X) < 4000.0f &&
Math.Abs(sprite.TransformedPosition.Y - cam.WorldViewCenter.Y) < 4000.0f);
}
checkActiveTimer = checkActiveInterval;
}
else
{
checkActiveTimer -= deltaTime;
}
foreach (BackgroundCreature sprite in activeSprites)
{
if (!sprite.Enabled) continue;
sprite.Update(deltaTime);
}
}
public void Draw(SpriteBatch spriteBatch)
{
foreach (BackgroundCreature sprite in activeSprites)
{
if (!sprite.Enabled) continue;
sprite.Draw(spriteBatch);
}
}
}
}

View File

@@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
namespace Barotrauma
{
class BackgroundCreaturePrefab
{
public readonly Sprite Sprite;
public readonly float Speed;
public readonly float WanderAmount;
public readonly float WanderZAmount;
public readonly int SwarmMin, SwarmMax;
public readonly float SwarmRadius;
public readonly bool DisableRotation;
public BackgroundCreaturePrefab(XElement element)
{
Speed = ToolBox.GetAttributeFloat(element, "speed", 1.0f);
WanderAmount = ToolBox.GetAttributeFloat(element, "wanderamount", 0.0f);
WanderZAmount = ToolBox.GetAttributeFloat(element, "wanderzamount", 0.0f);
SwarmMin = ToolBox.GetAttributeInt(element, "swarmmin", 1);
SwarmMax = ToolBox.GetAttributeInt(element, "swarmmax", 1);
SwarmRadius = ToolBox.GetAttributeFloat(element, "swarmradius", 200.0f);
DisableRotation = ToolBox.GetAttributeBool(element, "disablerotation", false);
foreach (XElement subElement in element.Elements())
{
if (subElement.Name.ToString().ToLower() != "sprite") continue;
Sprite = new Sprite(subElement);
break;
}
}
}
}

View File

@@ -5,23 +5,30 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Voronoi2;
namespace Barotrauma
{
class BackgroundSprite
{
public readonly BackgroundSpritePrefab Prefab;
public Vector2 Position;
public BackgroundSprite(BackgroundSpritePrefab prefab, Vector2 position)
{
this.Prefab = prefab;
this.Position = position;
}
}
class BackgroundSpriteManager
{
const int MaxSprites = 100;
const float checkActiveInterval = 1.0f;
float checkActiveTimer;
private List<BackgroundSpritePrefab> prefabs;
private List<BackgroundSprite> activeSprites;
private List<BackgroundSprite> sprites;
public BackgroundSpriteManager(string configPath)
{
activeSprites = new List<BackgroundSprite>();
sprites = new List<BackgroundSprite>();
prefabs = new List<BackgroundSpritePrefab>();
XDocument doc = ToolBox.TryLoadXml(configPath);
@@ -33,92 +40,92 @@ namespace Barotrauma
}
}
public void SpawnSprites(int count, Vector2? position = null)
public void PlaceSprites(Level level, int amount)
{
activeSprites.Clear();
sprites.Clear();
if (prefabs.Count == 0) return;
count = Math.Min(count, MaxSprites);
for (int i = 0; i < count; i++ )
for (int i = 0 ; i <amount; i++)
{
Vector2 pos = Vector2.Zero;
BackgroundSpritePrefab prefab = GetRandomPrefab();
Vector2 pos = FindSpritePosition(level, prefab);
if (position == null)
{
if (WayPoint.WayPointList.Count>0)
{
WayPoint wp = WayPoint.WayPointList[Rand.Int(WayPoint.WayPointList.Count)];
pos = new Vector2(wp.Rect.X, wp.Rect.Y);
pos += Rand.Vector(200.0f);
}
else
{
pos = Rand.Vector(2000.0f);
}
}
else
{
pos = (Vector2)position;
}
var prefab = prefabs[Rand.Int(prefabs.Count)];
int amount = Rand.Range(prefab.SwarmMin, prefab.SwarmMax);
List<BackgroundSprite> swarmMembers = new List<BackgroundSprite>();
for (int n = 0; n < amount; n++)
{
var newSprite = new BackgroundSprite(prefab, pos);
activeSprites.Add(newSprite);
swarmMembers.Add(newSprite);
}
if (amount > 0)
{
new Swarm(swarmMembers, prefab.SwarmRadius);
}
sprites.Add(new BackgroundSprite(prefab, pos));
}
}
public void ClearSprites()
private Vector2 FindSpritePosition(Level level, BackgroundSpritePrefab prefab)
{
activeSprites.Clear();
Vector2 randomPos = new Vector2(Rand.Range(0.0f, level.Size.X), Rand.Range(0.0f, level.Size.Y));
var cells = level.GetCells(randomPos);
if (!cells.Any()) return Vector2.Zero;
VoronoiCell cell = cells[Rand.Int(cells.Count)];
GraphEdge bestEdge = null;
foreach (GraphEdge edge in cell.edges)
{
if (prefab.Alignment.HasFlag(Alignment.Bottom))
{
if (bestEdge == null || edge.Center.Y > bestEdge.Center.Y) bestEdge = edge;
}
else if (prefab.Alignment.HasFlag(Alignment.Top))
{
if (bestEdge == null || edge.Center.Y < bestEdge.Center.Y) bestEdge = edge;
}
else if (prefab.Alignment.HasFlag(Alignment.Left))
{
if (bestEdge == null || edge.Center.X > bestEdge.Center.X) bestEdge = edge;
}
else if (prefab.Alignment.HasFlag(Alignment.Right))
{
if (bestEdge == null || edge.Center.X < bestEdge.Center.X) bestEdge = edge;
}
}
Vector2 dir = Vector2.Normalize(bestEdge.point1 - bestEdge.point2);
Vector2 pos = bestEdge.Center;
if (prefab.Alignment.HasFlag(Alignment.Bottom))
{
pos.Y -= Math.Abs(dir.Y) * prefab.Sprite.size.X/Math.Abs(dir.X);
}
else if (prefab.Alignment.HasFlag(Alignment.Top))
{
pos.Y += Math.Abs(dir.Y) * prefab.Sprite.size.X/Math.Abs(dir.X);
}
return pos;
}
public void Update(Camera cam, float deltaTime)
public void DrawSprites(SpriteBatch spriteBatch)
{
if (checkActiveTimer<0.0f)
foreach (BackgroundSprite sprite in sprites)
{
foreach (BackgroundSprite sprite in activeSprites)
sprite.Prefab.Sprite.Draw(spriteBatch, new Vector2(sprite.Position.X, -sprite.Position.Y));
}
}
private BackgroundSpritePrefab GetRandomPrefab()
{
int totalCommonness = 0;
foreach (BackgroundSpritePrefab prefab in prefabs)
{
totalCommonness += prefab.Commonness;
}
float randomNumber = Rand.Int(totalCommonness+1);
foreach (BackgroundSpritePrefab prefab in prefabs)
{
if (randomNumber <= prefab.Commonness)
{
sprite.Enabled = (Math.Abs(sprite.TransformedPosition.X - cam.WorldViewCenter.X) < 4000.0f &&
Math.Abs(sprite.TransformedPosition.Y - cam.WorldViewCenter.Y) < 4000.0f);
return prefab;
}
checkActiveTimer = checkActiveInterval;
}
else
{
checkActiveTimer -= deltaTime;
randomNumber -= prefab.Commonness;
}
foreach (BackgroundSprite sprite in activeSprites)
{
if (!sprite.Enabled) continue;
sprite.Update(deltaTime);
}
}
public void Draw(SpriteBatch spriteBatch)
{
foreach (BackgroundSprite sprite in activeSprites)
{
if (!sprite.Enabled) continue;
sprite.Draw(spriteBatch);
}
return null;
}
}
}

View File

@@ -10,32 +10,17 @@ namespace Barotrauma
{
public readonly Sprite Sprite;
public readonly float Speed;
public readonly Alignment Alignment;
public readonly float WanderAmount;
public readonly int Commonness;
public readonly float WanderZAmount;
public readonly int SwarmMin, SwarmMax;
public readonly float SwarmRadius;
public readonly bool DisableRotation;
public BackgroundSpritePrefab(XElement element)
{
Speed = ToolBox.GetAttributeFloat(element, "speed", 1.0f);
string alignmentStr = ToolBox.GetAttributeString(element, "alignment", "BottomCenter");
WanderAmount = ToolBox.GetAttributeFloat(element, "wanderamount", 0.0f);
if (!Enum.TryParse(alignmentStr, out Alignment)) Alignment = Alignment.BottomCenter;
WanderZAmount = ToolBox.GetAttributeFloat(element, "wanderzamount", 0.0f);
SwarmMin = ToolBox.GetAttributeInt(element, "swarmmin", 1);
SwarmMax = ToolBox.GetAttributeInt(element, "swarmmax", 1);
SwarmRadius = ToolBox.GetAttributeFloat(element, "swarmradius", 200.0f);
DisableRotation = ToolBox.GetAttributeBool(element, "disablerotation", false);
Commonness = ToolBox.GetAttributeInt(element, "commonness", 1);
foreach (XElement subElement in element.Elements())
{
@@ -45,6 +30,6 @@ namespace Barotrauma
break;
}
}
}
}
}

View File

@@ -138,6 +138,11 @@ namespace Barotrauma
}
}
public Vector2 CursorWorldPosition
{
get { return Submarine == null ? cursorPosition : cursorPosition + Submarine.Position; }
}
public Character ClosestCharacter
{
get { return closestCharacter; }
@@ -273,38 +278,32 @@ namespace Barotrauma
get { return AnimController.RefLimb.SimPosition; }
}
public Vector2 Position
public override Vector2 Position
{
get { return ConvertUnits.ToDisplayUnits(AnimController.RefLimb.SimPosition); }
get { return AnimController.RefLimb.Position; }
}
static Character()
{
DeathMsg[(int)CauseOfDeath.Damage] = "succumbed to your injuries";
DeathMsg[(int)CauseOfDeath.Bloodloss] = "bled out";
DeathMsg[(int)CauseOfDeath.Drowning] = "drowned";
DeathMsg[(int)CauseOfDeath.Damage] = "succumbed to your injuries";
DeathMsg[(int)CauseOfDeath.Bloodloss] = "bled out";
DeathMsg[(int)CauseOfDeath.Drowning] = "drowned";
DeathMsg[(int)CauseOfDeath.Suffocation] = "suffocated";
DeathMsg[(int)CauseOfDeath.Pressure] = "been crushed by water pressure";
DeathMsg[(int)CauseOfDeath.Burn] = "burnt to death";
DeathMsg[(int)CauseOfDeath.Pressure] = "been crushed by water pressure";
DeathMsg[(int)CauseOfDeath.Burn] = "burnt to death";
}
public static Character Create(string file, Vector2 position)
{
return Create(file, position, null);
}
public static Character Create(CharacterInfo characterInfo, WayPoint spawnPoint, bool isNetworkPlayer = false)
public static Character Create(CharacterInfo characterInfo, Vector2 position, bool isNetworkPlayer = false, bool hasAi=true)
{
return Create(characterInfo.File, spawnPoint.SimPosition, characterInfo, isNetworkPlayer);
return Create(characterInfo.File, position, characterInfo, isNetworkPlayer, hasAi);
}
public static Character Create(CharacterInfo characterInfo, Vector2 position, bool isNetworkPlayer = false)
{
return Create(characterInfo.File, position, characterInfo, isNetworkPlayer);
}
public static Character Create(string file, Vector2 position, CharacterInfo characterInfo = null, bool isNetworkPlayer = false)
public static Character Create(string file, Vector2 position, CharacterInfo characterInfo = null, bool isNetworkPlayer = false, bool hasAi=true)
{
if (file != humanConfigFile)
{
@@ -316,24 +315,25 @@ namespace Barotrauma
}
else
{
if (isNetworkPlayer)
{
var netCharacter = new Character(file, position, characterInfo, isNetworkPlayer);
return netCharacter;
}
else
if (hasAi && !isNetworkPlayer)
{
var character = new AICharacter(file, position, characterInfo, isNetworkPlayer);
var ai = new HumanAIController(character);
character.SetAI(ai);
return character;
}
else
{
return new Character(file, position, characterInfo, isNetworkPlayer);
}
}
}
protected Character(string file, Vector2 position, CharacterInfo characterInfo = null, bool isNetworkPlayer = false)
: base(null)
{
keys = new Key[Enum.GetNames(typeof(InputType)).Length];
@@ -342,26 +342,12 @@ namespace Barotrauma
{
keys[i] = new Key(GameMain.Config.KeyBind((InputType)i));
}
//keys[(int)InputType.Select] = new Key(GameMain.Config.KeyBind(InputType.Select));
//keys[(int)InputType.ActionHeld] = new Key(true);
//keys[(int)InputType.ActionHit] = new Key(false);
//keys[(int)InputType.SecondaryHit] = new Key(false);
//keys[(int)InputType.SecondaryHeld] = new Key(true);
//keys[(int)InputType.Left] = new Key(true);
//keys[(int)InputType.Right] = new Key(true);
//keys[(int)InputType.Up] = new Key(true);
//keys[(int)InputType.Down] = new Key(true);
//keys[(int)InputType.Run] = new Key(true);
selectedItems = new Item[2];
IsNetworkPlayer = isNetworkPlayer;
oxygen = 100.0f;
//blood = 100.0f;
aiTarget = new AITarget(this);
lowPassMultiplier = 1.0f;
@@ -392,7 +378,7 @@ namespace Barotrauma
foreach (Limb limb in AnimController.Limbs)
{
limb.body.SetTransform(position+limb.SimPosition, 0.0f);
limb.body.SetTransform(ConvertUnits.ToSimUnits(position)+limb.SimPosition, 0.0f);
//limb.prevPosition = ConvertUnits.ToDisplayUnits(position);
}
@@ -442,7 +428,8 @@ namespace Barotrauma
}
}
AnimController.FindHull();
AnimController.FindHull(null);
if (AnimController.CurrentHull != null) Submarine = AnimController.CurrentHull.Submarine;
CharacterList.Add(this);
@@ -522,7 +509,7 @@ namespace Barotrauma
continue;
}
Item item = new Item(itemPrefab, Position);
Item item = new Item(itemPrefab, Position, null);
if (info.Job.EquipSpawnItem[i])
{
@@ -734,7 +721,7 @@ namespace Barotrauma
{
Limb head = AnimController.GetLimb(LimbType.Head);
Lights.LightManager.ViewPos = ConvertUnits.ToDisplayUnits(head.SimPosition);
//Lights.LightManager.ViewPos = WorldPosition;
if (!DisableControls)
{
@@ -757,8 +744,11 @@ namespace Barotrauma
cam.OffsetAmount = MathHelper.Lerp(cam.OffsetAmount, 250.0f, 0.05f);
}
cursorPosition = cam.ScreenToWorld(PlayerInput.MousePosition);
cursorPosition = cam.ScreenToWorld(PlayerInput.MousePosition);
if (AnimController.CurrentHull != null) cursorPosition -= Submarine.Loaded.Position;
Vector2 mouseSimPos = ConvertUnits.ToSimUnits(cursorPosition);
if (Vector2.Distance(AnimController.Limbs[0].SimPosition, mouseSimPos)>1.0f)
{
Body body = Submarine.PickBody(AnimController.Limbs[0].SimPosition, mouseSimPos);
@@ -876,9 +866,11 @@ namespace Barotrauma
{
if (!Enabled) return;
Submarine = AnimController.CurrentHull == null ? null : Submarine.Loaded;
obstructVisionAmount = Math.Max(obstructVisionAmount - deltaTime, 0.0f);
AnimController.SimplePhysicsEnabled = (Character.controlled != this && Vector2.Distance(cam.WorldViewCenter, Position) > 5000.0f);
AnimController.SimplePhysicsEnabled = (Character.controlled != this && Vector2.Distance(cam.WorldViewCenter, WorldPosition) > 5000.0f);
if (isDead) return;
@@ -888,7 +880,7 @@ namespace Barotrauma
if (Submarine.Loaded!=null && Level.Loaded !=null)
{
protectedFromPressure = protectedFromPressure && (Position-Level.Loaded.Position).Y > SubmarineBody.DamageDepth;
protectedFromPressure = protectedFromPressure && Position.Y > SubmarineBody.DamageDepth;
}
if (!protectedFromPressure &&
@@ -976,7 +968,7 @@ namespace Barotrauma
{
if (!Enabled) return;
Vector2 pos = ConvertUnits.ToDisplayUnits(AnimController.Limbs[0].SimPosition);
Vector2 pos = AnimController.Limbs[0].WorldPosition;
pos.Y = -pos.Y;
if (this == controlled) return;
@@ -998,7 +990,7 @@ namespace Barotrauma
AnimController.DebugDraw(spriteBatch);
}
Vector2 healthBarPos = new Vector2(Position.X - 50, -Position.Y - 100.0f);
Vector2 healthBarPos = new Vector2(DrawPosition.X - 50, -DrawPosition.Y - 100.0f);
GUI.DrawRectangle(spriteBatch, new Rectangle((int)healthBarPos.X - 2, (int)healthBarPos.Y - 2, 100 + 4, 15 + 4), Color.Black, false);
GUI.DrawRectangle(spriteBatch, new Rectangle((int)healthBarPos.X, (int)healthBarPos.Y, (int)(100.0f * (health / maxHealth)), 15), Color.Red, true);
}
@@ -1016,17 +1008,16 @@ namespace Barotrauma
if (soundStates[i] != state) continue;
if (n == selectedSound && sounds[i]!=null)
{
sounds[i].Play(1.0f, 2000.0f,
AnimController.Limbs[0].body.FarseerBody);
sounds[i].Play(1.0f, 2000.0f, AnimController.Limbs[0].WorldPosition);
return;
}
n++;
}
}
public virtual AttackResult AddDamage(IDamageable attacker, Vector2 simPosition, Attack attack, float deltaTime, bool playSound = false)
public virtual AttackResult AddDamage(IDamageable attacker, Vector2 worldPosition, Attack attack, float deltaTime, bool playSound = false)
{
return AddDamage(simPosition, 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);
}
public AttackResult AddDamage(Vector2 simPosition, DamageType damageType, float amount, float bleedingAmount, float stun, bool playSound)
@@ -1091,17 +1082,17 @@ namespace Barotrauma
// limb.Damage = 100.0f;
}
SoundPlayer.PlayDamageSound(DamageSoundType.Implode, 50.0f, AnimController.RefLimb.body.FarseerBody);
SoundPlayer.PlayDamageSound(DamageSoundType.Implode, 50.0f, AnimController.RefLimb.body);
for (int i = 0; i < 10; i++)
{
Particle p = GameMain.ParticleManager.CreateParticle("waterblood",
centerOfMass + Rand.Vector(50.0f),
ConvertUnits.ToDisplayUnits(centerOfMass) + Rand.Vector(50.0f),
Vector2.Zero);
if (p!=null) p.Size *= 2.0f;
GameMain.ParticleManager.CreateParticle("bubbles",
centerOfMass + Rand.Vector(50.0f),
ConvertUnits.ToDisplayUnits(centerOfMass) + Rand.Vector(50.0f),
new Vector2(Rand.Range(-50f, 50f), Rand.Range(-100f,50f)));
}
@@ -1256,22 +1247,6 @@ namespace Barotrauma
return inventory.FillNetworkData(NetworkEventType.InventoryUpdate, message, data);
case NetworkEventType.ImportantEntityUpdate:
//int i = 0;
//foreach (Limb limb in AnimController.Limbs)
//{
// if (limb.SimPosition.Length() > NetConfig.CharacterIgnoreDistance) return false;
// message.WriteRangedSingle(limb.body.SimPosition.X, -NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16);
// message.WriteRangedSingle(limb.body.SimPosition.Y, -NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16);
// //message.Write(limb.body.LinearVelocity.X);
// //message.Write(limb.body.LinearVelocity.Y);
// message.Write(limb.body.Rotation);
// //message.WriteRangedSingle(MathHelper.Clamp(limb.body.AngularVelocity, -10.0f, 10.0f), -10.0f, 10.0f, 8);
// i++;
//}
message.Write((byte)((health / maxHealth) * 255.0f));
if (AnimController.StunTimer<=0.0f && bleeding<=0.0f && oxygen>99.0f)
@@ -1288,10 +1263,8 @@ namespace Barotrauma
bleeding = MathHelper.Clamp(bleeding, 0.0f, 5.0f);
message.WriteRangedSingle(bleeding, 0.0f, 5.0f, 8);
}
return true;
case NetworkEventType.EntityUpdate:
message.Write(keys[(int)InputType.Use].DequeueHeld);
@@ -1324,10 +1297,14 @@ namespace Barotrauma
message.Write(AnimController.Dir > 0.0f);
}
if (AnimController.RefLimb.SimPosition.Length() > NetConfig.CharacterIgnoreDistance) return true;
message.WriteRangedSingle(AnimController.RefLimb.SimPosition.X, -NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16);
message.WriteRangedSingle(AnimController.RefLimb.SimPosition.Y, -NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16);
message.Write(Submarine != null);
//Vector2 position = Submarine == null ? SimPosition : SimPosition - Submarine.SimPosition;
//if ((AnimController.RefLimb.SimPosition - Submarine.Loaded.SimPosition).Length() > NetConfig.CharacterIgnoreDistance) return true;
message.Write(SimPosition.X);
message.Write(SimPosition.Y);
return true;
default:
@@ -1492,17 +1469,21 @@ namespace Barotrauma
#endif
return;
}
try
{
pos.X = message.ReadRangedSingle(-NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16);
pos.Y = message.ReadRangedSingle(-NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16);
}
catch
bool inSub = message.ReadBoolean();
pos.X = message.ReadFloat();
pos.Y = message.ReadFloat();
if (inSub)
{
//failed to read position, Character may be further than NetConfig.CharacterIgnoreDistance
pos = SimPosition;
}
Hull newHull = Hull.FindHull(ConvertUnits.ToDisplayUnits(pos), AnimController.CurrentHull, false);
if (newHull != null)
{
AnimController.CurrentHull = newHull;
Submarine = newHull.Submarine;
}
}
if (secondaryKeyState)
{
@@ -1514,7 +1495,8 @@ namespace Barotrauma
cursorPosition = Position + new Vector2(1000.0f, 0.0f) * dir;
}
AnimController.RefLimb.body.TargetPosition = AnimController.EstimateCurrPosition(pos, (float)(NetTime.Now + message.SenderConnection.RemoteTimeOffset) - sendingTime);
AnimController.RefLimb.body.TargetPosition =
AnimController.EstimateCurrPosition(pos, (float)(NetTime.Now + message.SenderConnection.RemoteTimeOffset) - sendingTime);
LastNetworkUpdate = sendingTime;

View File

@@ -54,7 +54,7 @@ namespace Barotrauma
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.DrawPosition + (character.ClosestCharacter.DrawPosition - character.DrawPosition) * 0.7f;
startPos = cam.WorldToScreen(startPos);
Vector2 textPos = startPos;
@@ -67,7 +67,7 @@ namespace Barotrauma
else if (character.SelectedCharacter == null && character.ClosestItem != null && character.SelectedConstruction == null)
{
Vector2 startPos = character.Position + (character.ClosestItem.Position - character.Position) * 0.7f;
Vector2 startPos = character.DrawPosition + (character.ClosestItem.DrawPosition - character.DrawPosition) * 0.7f;
startPos = cam.WorldToScreen(startPos);
Vector2 textPos = startPos;
@@ -96,10 +96,10 @@ namespace Barotrauma
{
int width = 100, height = 20;
drowningBar = new GUIProgressBar(new Rectangle(30, GameMain.GraphicsHeight - 200, width, height), Color.Blue, 1.0f);
drowningBar = new GUIProgressBar(new Rectangle(30, GameMain.GraphicsHeight - 200, width, height), Color.Blue, GUI.Style, 1.0f, Alignment.TopLeft);
new GUIImage(new Rectangle(-27, -7, 20, 20), new Rectangle(17, 0, 20, 24), statusIcons, Alignment.TopLeft, drowningBar);
healthBar = new GUIProgressBar(new Rectangle(30, GameMain.GraphicsHeight - 230, width, height), Color.Red, 1.0f);
healthBar = new GUIProgressBar(new Rectangle(30, GameMain.GraphicsHeight - 230, width, height), Color.Red, GUI.Style, 1.0f, Alignment.TopLeft);
new GUIImage(new Rectangle(-26, -7, 20, 20), new Rectangle(0, 0, 13, 24), statusIcons, Alignment.TopLeft, healthBar);
}

View File

@@ -79,6 +79,11 @@ namespace Barotrauma
get { return doesFlip; }
}
public Vector2 WorldPosition
{
get { return character.Submarine == null ? Position : Position + character.Submarine.Position; }
}
public Vector2 Position
{
get { return ConvertUnits.ToDisplayUnits(body.SimPosition); }
@@ -352,13 +357,13 @@ namespace Barotrauma
if (particleVel != Vector2.Zero) particleVel = Vector2.Normalize(particleVel);
GameMain.ParticleManager.CreateParticle("blood",
Position,
WorldPosition,
particleVel * Rand.Range(100.0f, 300.0f), 0.0f, character.AnimController.CurrentHull);
}
for (int i = 0; i < bloodAmount / 2; i++)
{
GameMain.ParticleManager.CreateParticle("waterblood", Position, Vector2.Zero, 0.0f, character.AnimController.CurrentHull);
GameMain.ParticleManager.CreateParticle("waterblood", WorldPosition, Vector2.Zero, 0.0f, character.AnimController.CurrentHull);
}
damage += Math.Max(amount,bleedingAmount) / character.MaxHealth * 100.0f;

View File

@@ -212,10 +212,10 @@ namespace Barotrauma
protected virtual void Apply(float deltaTime, Entity entity, List<IPropertyObject> targets)
{
if (explosion != null) explosion.Explode(entity.SimPosition);
if (explosion != null) explosion.Explode(entity.WorldPosition);
if (Fire) new FireSource(ConvertUnits.ToDisplayUnits(entity.SimPosition));
if (sound != null) sound.Play(1.0f, 1000.0f, ConvertUnits.ToDisplayUnits(entity.SimPosition));
if (sound != null) sound.Play(1.0f, 1000.0f, entity.WorldPosition);
for (int i = 0; i < propertyNames.Count(); i++)
{