Moar progress, fixed shadow/los/submarine misalignment issues

This commit is contained in:
Regalis
2015-12-09 19:29:53 +02:00
parent beecfe60ac
commit 78bccca4af
43 changed files with 396 additions and 383 deletions

View File

@@ -15,7 +15,7 @@
<!-- lower yaw -->
<limb id = "1" radius="20" height="240" impacttolerance="50.0">
<sprite texture="Content/Characters/Coelanth/coelanth.png" sourcerect="425,1,101,309" depth="0.025" origin="0.5,0.5"/>
<attack type="PinchCCW" range="200" duration="0.5" damage="200" bleedingdamage="50" structuredamage="150" damagetype="slash"/>
<attack type="PinchCCW" range="250" duration="0.5" damage="200" bleedingdamage="50" structuredamage="150" damagetype="slash"/>
</limb>
<!-- body -->

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

@@ -167,12 +167,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)
{
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 +192,7 @@ namespace Barotrauma
raycastTimer = RaycastInterval;
}
steeringManager.SteeringSeek(attackPosition);
steeringManager.SteeringSeek(attackSimPosition);
//check if any of the limbs is close enough to attack the target
if (attackingLimb == null)
@@ -195,7 +200,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 +208,7 @@ namespace Barotrauma
return;
}
UpdateLimbAttack(deltaTime, attackingLimb, attackPosition);
UpdateLimbAttack(deltaTime, attackingLimb, attackSimPosition);
}
@@ -230,9 +235,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 +260,8 @@ namespace Barotrauma
if (wall == null)
{
wallAttackPos = Submarine.LastPickedPosition;
if (selectedAiTarget.Entity.Submarine!=null) wallAttackPos -= ConvertUnits.ToSimUnits(selectedAiTarget.Entity.Submarine.Position);
}
else
{
@@ -261,6 +278,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 +306,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,12 +316,12 @@ 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.soundTimer = Limb.SoundInterval;
@@ -392,9 +403,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 +416,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 +505,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

@@ -87,7 +87,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

@@ -89,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

@@ -536,11 +536,11 @@ namespace Barotrauma
}
}
public void FindHull(bool setSubmarine = true)
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;
@@ -619,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;
@@ -633,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;
@@ -659,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);
@@ -678,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);

View File

@@ -153,15 +153,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));
}

View File

@@ -47,9 +47,10 @@ namespace Barotrauma
if (position == null)
{
if (WayPoint.WayPointList.Count>0)
var wayPoints = WayPoint.WayPointList.FindAll(wp => wp.Submarine==null);
if (wayPoints.Any())
{
WayPoint wp = WayPoint.WayPointList[Rand.Int(WayPoint.WayPointList.Count)];
WayPoint wp = wayPoints[Rand.Int(wayPoints.Count)];
pos = new Vector2(wp.Rect.X, wp.Rect.Y);
pos += Rand.Vector(200.0f);

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; }
@@ -295,7 +300,7 @@ namespace Barotrauma
public static Character Create(CharacterInfo characterInfo, WayPoint spawnPoint, bool isNetworkPlayer = false)
{
return Create(characterInfo.File, spawnPoint.SimPosition, characterInfo, isNetworkPlayer);
return Create(characterInfo.File, spawnPoint.WorldPosition, characterInfo, isNetworkPlayer);
}
@@ -393,7 +398,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);
}
@@ -443,7 +448,8 @@ namespace Barotrauma
}
}
AnimController.FindHull(false);
AnimController.FindHull(null, false);
if (AnimController.CurrentHull != null) Submarine = AnimController.CurrentHull.Submarine;
CharacterList.Add(this);
@@ -735,7 +741,7 @@ namespace Barotrauma
{
Limb head = AnimController.GetLimb(LimbType.Head);
Lights.LightManager.ViewPos = ConvertUnits.ToDisplayUnits(WorldPosition);
Lights.LightManager.ViewPos = WorldPosition;
if (!DisableControls)
{
@@ -1004,7 +1010,7 @@ namespace Barotrauma
AnimController.DebugDraw(spriteBatch);
}
Vector2 healthBarPos = new Vector2(Position.X - 50, -Position.Y - 100.0f);
Vector2 healthBarPos = new Vector2(WorldPosition.X - 50, -WorldPosition.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);
}
@@ -1102,12 +1108,12 @@ namespace Barotrauma
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)));
}

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,7 +212,7 @@ 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));

View File

@@ -225,7 +225,7 @@ namespace Barotrauma
if (commands[1].ToLower()=="human")
{
WayPoint spawnPoint = WayPoint.GetRandom(SpawnType.Human);
Character.Controlled = Character.Create(Character.HumanConfigFile, (spawnPoint == null) ? Vector2.Zero : spawnPoint.SimPosition);
Character.Controlled = Character.Create(Character.HumanConfigFile, (spawnPoint == null) ? Vector2.Zero : spawnPoint.WorldPosition);
if (GameMain.GameSession != null)
{
SinglePlayerMode mode = GameMain.GameSession.gameMode as SinglePlayerMode;
@@ -237,7 +237,7 @@ namespace Barotrauma
else
{
WayPoint spawnPoint = WayPoint.GetRandom(SpawnType.Enemy);
Character.Create("Content/Characters/" + commands[1] + "/" + commands[1] + ".xml", (spawnPoint == null) ? Vector2.Zero : spawnPoint.SimPosition);
Character.Create("Content/Characters/" + commands[1] + "/" + commands[1] + ".xml", (spawnPoint == null) ? Vector2.Zero : spawnPoint.WorldPosition);
}
break;

View File

@@ -30,7 +30,7 @@ namespace Barotrauma
return;
}
Hull cargoRoom = Hull.FindHull(wp.Position);
Hull cargoRoom = Hull.FindHull(wp.WorldPosition);
if (cargoRoom == null)
{

View File

@@ -343,7 +343,7 @@ namespace Barotrauma
bool broken = false;
do
{
Submarine.Loaded.Speed = Vector2.Zero;
Submarine.Loaded.Velocity = Vector2.Zero;
moloch.AIController.SelectTarget(steering.Item.CurrentHull.AiTarget);
Vector2 steeringDir = windows[0].Position - moloch.Position;

View File

@@ -318,7 +318,7 @@ namespace Barotrauma.Items.Components
}
Vector2 pos = new Vector2(item.Rect.Center.X, item.Rect.Y);
if (item.Submarine != null) pos += item.Submarine.Position;
if (item.Submarine != null) pos += item.Submarine.DrawPosition;
pos.Y = -pos.Y;
spriteBatch.Draw(doorSprite.Texture, pos,

View File

@@ -24,8 +24,8 @@ namespace Barotrauma.Items.Components
[HasDefaultValue(0.0f, false)]
public float Range
{
get { return ConvertUnits.ToDisplayUnits(range); }
set { range = ConvertUnits.ToSimUnits(value); }
get { return range; }
set { range = value; }
}
[HasDefaultValue(0.0f, false)]
@@ -61,8 +61,8 @@ namespace Barotrauma.Items.Components
[HasDefaultValue("0.0,0.0", false)]
public string BarrelPos
{
get { return ToolBox.Vector2ToString(ConvertUnits.ToDisplayUnits(barrelPos)); }
set { barrelPos = ConvertUnits.ToSimUnits(ToolBox.ParseToVector2(value)); }
get { return ToolBox.Vector2ToString(barrelPos); }
set { barrelPos = ToolBox.ParseToVector2(value); }
}
public Vector2 TransformedBarrelPos
@@ -72,7 +72,7 @@ namespace Barotrauma.Items.Components
Matrix bodyTransform = Matrix.CreateRotationZ(item.body.Rotation);
Vector2 flippedPos = barrelPos;
if (item.body.Dir < 0.0f) flippedPos.X = -flippedPos.X;
return (Vector2.Transform(flippedPos, bodyTransform) + item.body.SimPosition);
return (Vector2.Transform(flippedPos, bodyTransform));
}
}
@@ -115,7 +115,6 @@ namespace Barotrauma.Items.Components
IsActive = true;
Vector2 targetPosition = item.body.SimPosition;
//targetPosition = targetPosition.X, -targetPosition.Y);
float degreeOfSuccess = DegreeOfSuccess(character)/100.0f;
@@ -126,6 +125,7 @@ namespace Barotrauma.Items.Components
return false;
}
Vector2 targetPosition = item.WorldPosition;
targetPosition += new Vector2(
(float)Math.Cos(item.body.Rotation),
(float)Math.Sin(item.body.Rotation)) * range * item.body.Dir;
@@ -137,14 +137,18 @@ namespace Barotrauma.Items.Components
ignoredBodies.Add(limb.body.FarseerBody);
}
Vector2 rayStart = item.WorldPosition + TransformedBarrelPos;
Vector2 rayEnd = targetPosition;
Body targetBody = Submarine.PickBody(
ConvertUnits.ToSimUnits(rayStart - Submarine.Loaded.Position),
ConvertUnits.ToSimUnits(rayEnd - Submarine.Loaded.Position), ignoredBodies);
Body targetBody = Submarine.PickBody(TransformedBarrelPos, targetPosition, ignoredBodies);
pickedPosition = Submarine.LastPickedPosition;
if (ExtinquishAmount > 0.0f)
{
Vector2 displayPos = ConvertUnits.ToDisplayUnits(TransformedBarrelPos + (targetPosition-TransformedBarrelPos)*Submarine.LastPickedFraction*0.9f);
Vector2 displayPos = rayStart + (rayEnd-rayStart)*Submarine.LastPickedFraction*0.9f;
Hull hull = Hull.FindHull(displayPos, item.CurrentHull);
if (hull != null) hull.Extinquish(deltaTime, ExtinquishAmount, displayPos);
}
@@ -224,7 +228,7 @@ namespace Barotrauma.Items.Components
if (!string.IsNullOrWhiteSpace(particles))
{
GameMain.ParticleManager.CreateParticle(particles, ConvertUnits.ToDisplayUnits(TransformedBarrelPos),
GameMain.ParticleManager.CreateParticle(particles, item.WorldPosition+TransformedBarrelPos,
-item.body.Rotation + ((item.body.Dir>0.0f) ? 0.0f : MathHelper.Pi), ParticleSpeed);
}

View File

@@ -74,7 +74,7 @@ namespace Barotrauma.Items.Components
for (int i = 0; i < 5; i++)
{
GameMain.ParticleManager.CreateParticle("bubbles", item.Position,
GameMain.ParticleManager.CreateParticle("bubbles", item.WorldPosition,
-currForce / 5.0f + new Vector2(Rand.Range(-100.0f, 100.0f), Rand.Range(-50f, 50f)),
0.0f, item.CurrentHull);
}

View File

@@ -103,7 +103,7 @@ namespace Barotrauma.Items.Components
private void GetHull()
{
hull1 = Hull.FindHull(item.Position, item.CurrentHull);
hull1 = Hull.FindHull(item.WorldPosition, item.CurrentHull);
}
public override void DrawHUD(SpriteBatch spriteBatch, Character character)

View File

@@ -163,7 +163,7 @@ namespace Barotrauma.Items.Components
Vector2 baseVel = Rand.Vector(300.0f);
for (int i = 0; i < 10; i++)
{
var particle = GameMain.ParticleManager.CreateParticle("spark", item.Position,
var particle = GameMain.ParticleManager.CreateParticle("spark", item.WorldPosition,
baseVel + Rand.Vector(100.0f), 0.0f, item.CurrentHull);
if (particle != null) particle.Size *= Rand.Range(0.5f, 1.0f);

View File

@@ -193,7 +193,7 @@ namespace Barotrauma.Items.Components
{
float prediction = 5.0f;
Vector2 futurePosition = Submarine.Loaded.Speed * prediction;
Vector2 futurePosition = ConvertUnits.ToDisplayUnits(Submarine.Loaded.Velocity) * prediction;
Vector2 targetSpeed = ((steeringPath.CurrentNode.Position - Submarine.Loaded.Position) - futurePosition);
targetSpeed = Vector2.Normalize(targetSpeed);

View File

@@ -67,7 +67,7 @@ namespace Barotrauma.Items.Components
Vector2 baseVel = Rand.Vector(300.0f);
for (int i = 0; i < 10; i++)
{
var particle = GameMain.ParticleManager.CreateParticle("spark", pt.item.Position,
var particle = GameMain.ParticleManager.CreateParticle("spark", pt.item.WorldPosition,
baseVel + Rand.Vector(100.0f), 0.0f, item.CurrentHull);
if (particle != null) particle.Size *= Rand.Range(0.5f, 1.0f);

View File

@@ -4,31 +4,17 @@ namespace Barotrauma.Items.Components
{
class OxygenDetector : ItemComponent
{
private Hull hull;
public OxygenDetector(Item item, XElement element)
: base (item, element)
{
hull = Hull.FindHull(item.Position);
IsActive = true;
}
public override void OnMapLoaded()
{
hull = Hull.FindHull(item.Position);
}
public override void Move(Microsoft.Xna.Framework.Vector2 amount)
{
hull = Hull.FindHull(item.Position);
}
public override void Update(float deltaTime, Camera cam)
{
if (hull == null) return;
item.SendSignal(((int)hull.OxygenPercentage).ToString(), "signal_out");
if (item.CurrentHull == null) return;
item.SendSignal(((int)item.CurrentHull.OxygenPercentage).ToString(), "signal_out");
}

View File

@@ -41,11 +41,10 @@ namespace Barotrauma.Items.Components
public override void Move(Vector2 amount)
{
//amount = FarseerPhysics.ConvertUnits.ToDisplayUnits(amount);
//for (int i = 0; i<Nodes.Count; i++)
//{
// Nodes[i] += amount;
//}
for (int i = 0; i < Nodes.Count; i++)
{
Nodes[i] += amount;
}
}
public Connection OtherConnection(Connection connection)
@@ -348,9 +347,11 @@ namespace Barotrauma.Items.Components
MapEntity.DisableSelect = true;
Nodes[(int)selectedNodeIndex] = GameMain.EditMapScreen.Cam.ScreenToWorld(PlayerInput.MousePosition);
Vector2 pos = Nodes[(int)selectedNodeIndex];
Vector2 nodeWorldPos = Nodes[(int)selectedNodeIndex];
Nodes[(int)selectedNodeIndex] = RoundNode(Nodes[(int)selectedNodeIndex], Hull.FindHull(Nodes[(int)selectedNodeIndex]));
if (item.Submarine != null) nodeWorldPos += item.Submarine.Position;
Nodes[(int)selectedNodeIndex] = RoundNode(Nodes[(int)selectedNodeIndex], Hull.FindHull(nodeWorldPos));
MapEntity.SelectEntity(item);
}
}
@@ -362,6 +363,12 @@ namespace Barotrauma.Items.Components
private void DrawSection(SpriteBatch spriteBatch, Vector2 start, Vector2 end, Color color)
{
if (item.Submarine!=null)
{
start += item.Submarine.DrawPosition;
end += item.Submarine.DrawPosition;
}
start.Y = -start.Y;
end.Y = -end.Y;

View File

@@ -81,8 +81,12 @@ namespace Barotrauma.Items.Components
public override void Draw(SpriteBatch spriteBatch, bool editing)
{
Vector2 drawPos = new Vector2(item.Rect.X, item.Rect.Y);
if (item.Submarine != null) drawPos += item.Submarine.DrawPosition;
drawPos.Y = -drawPos.Y;
barrelSprite.Draw(spriteBatch,
new Vector2(item.Rect.X, -item.Rect.Y) + barrelPos, Color.White,
drawPos + barrelPos, Color.White,
rotation + MathHelper.PiOver2, 1.0f,
SpriteEffects.None, item.Sprite.Depth+0.01f);
}

View File

@@ -378,9 +378,8 @@ namespace Barotrauma
if (ItemList != null && body != null)
{
amount = ConvertUnits.ToSimUnits(amount);
//Vector2 pos = new Vector2(rect.X + rect.Width / 2.0f, rect.Y - rect.Height / 2.0f);
body.SetTransform(body.SimPosition+amount, body.Rotation);
body.SetTransform(body.SimPosition+ConvertUnits.ToSimUnits(amount), body.Rotation);
}
foreach (ItemComponent ic in components)
{
@@ -409,7 +408,7 @@ namespace Barotrauma
public virtual Hull FindHull()
{
CurrentHull = Hull.FindHull((body == null) ? Position : ConvertUnits.ToDisplayUnits(body.SimPosition), CurrentHull);
CurrentHull = Hull.FindHull(WorldPosition, CurrentHull);
if (body!=null)
{
body.Submarine = CurrentHull == null ? null : Submarine.Loaded;

View File

@@ -10,8 +10,6 @@ namespace Barotrauma
{
class Explosion
{
private Vector2 position;
private Attack attack;
private float force;
@@ -32,58 +30,52 @@ namespace Barotrauma
shockwave = ToolBox.GetAttributeBool(element, "shockwave", true);
flames = ToolBox.GetAttributeBool(element, "flames", true);
CameraShake = ToolBox.GetAttributeFloat(element, "camerashake", attack.Range*10.0f);
CameraShake = ToolBox.GetAttributeFloat(element, "camerashake", attack.Range);
}
public void Explode()
public void Explode(Vector2 worldPosition)
{
Explode(position);
}
public void Explode(Vector2 simPosition)
{
Vector2 displayPosition = ConvertUnits.ToDisplayUnits(simPosition);
Hull hull = Hull.FindHull(displayPosition);
Hull hull = Hull.FindHull(worldPosition);
if (shockwave)
{
GameMain.ParticleManager.CreateParticle("shockwave", displayPosition,
GameMain.ParticleManager.CreateParticle("shockwave", worldPosition,
Vector2.Zero, 0.0f, hull);
}
for (int i = 0; i < attack.Range * 10; i++)
for (int i = 0; i < attack.Range * 0.1f; i++)
{
if (sparks)
{
GameMain.ParticleManager.CreateParticle("spark", displayPosition,
GameMain.ParticleManager.CreateParticle("spark", worldPosition,
Rand.Vector(Rand.Range(500.0f, 800.0f)), 0.0f, hull);
}
if (flames)
{
GameMain.ParticleManager.CreateParticle("explosionfire", displayPosition + Rand.Vector(50f),
GameMain.ParticleManager.CreateParticle("explosionfire", worldPosition + Rand.Vector(50f),
Rand.Vector(Rand.Range(50f, 100.0f)), 0.0f, hull);
}
}
float displayRange = ConvertUnits.ToDisplayUnits(attack.Range);
float displayRange = attack.Range;
if (displayRange < 0.1f) return;
light = new LightSource(displayPosition, displayRange, Color.LightYellow, hull != null ? hull.Submarine : null);
light = new LightSource(worldPosition, displayRange, Color.LightYellow, hull != null ? hull.Submarine : null);
CoroutineManager.StartCoroutine(DimLight());
float cameraDist = Vector2.Distance(GameMain.GameScreen.Cam.Position, displayPosition)/2.0f;
GameMain.GameScreen.Cam.Shake = CameraShake * Math.Max((displayRange - cameraDist)/displayRange, 0.0f);
float cameraDist = Vector2.Distance(GameMain.GameScreen.Cam.Position, worldPosition)/2.0f;
GameMain.GameScreen.Cam.Shake = CameraShake * Math.Max((displayRange - cameraDist) / displayRange, 0.0f);
if (attack.GetStructureDamage(1.0f) > 0.0f)
{
RangedStructureDamage(displayPosition, displayRange, attack.GetStructureDamage(1.0f));
RangedStructureDamage(worldPosition, displayRange, attack.GetStructureDamage(1.0f));
}
if (force == 0.0f && attack.Stun == 0.0f && attack.GetDamage(1.0f) == 0.0f) return;
foreach (Character c in Character.CharacterList)
{
float dist = Vector2.Distance(c.SimPosition, simPosition);
float dist = Vector2.Distance(c.WorldPosition, worldPosition);
if (dist > attack.Range) continue;
@@ -91,14 +83,14 @@ namespace Barotrauma
foreach (Limb limb in c.AnimController.Limbs)
{
if (limb.SimPosition == simPosition) continue;
distFactor = 1.0f - Vector2.Distance(limb.SimPosition, simPosition)/attack.Range;
if (limb.WorldPosition == worldPosition) continue;
distFactor = 1.0f - Vector2.Distance(limb.WorldPosition, worldPosition)/attack.Range;
c.AddDamage(limb.SimPosition, DamageType.None,
attack.GetDamage(1.0f) / c.AnimController.Limbs.Length * distFactor, 0.0f, attack.Stun * distFactor, false);
if (force>0.0f)
if (force > 0.0f)
{
limb.body.ApplyLinearImpulse(Vector2.Normalize(limb.SimPosition - simPosition) * distFactor * force);
limb.body.ApplyLinearImpulse(Vector2.Normalize(limb.WorldPosition - worldPosition) * distFactor * force);
}
}
}
@@ -124,7 +116,7 @@ namespace Barotrauma
yield return CoroutineStatus.Success;
}
public static void RangedStructureDamage(Vector2 displayPosition, float displayRange, float damage)
public static void RangedStructureDamage(Vector2 worldPosition, float worldRange, float damage)
{
List<Structure> structureList = new List<Structure>();
@@ -137,7 +129,7 @@ namespace Barotrauma
if (structure.HasBody &&
!structure.IsPlatform &&
Vector2.Distance(structure.Position, displayPosition) < dist * 3.0f)
Vector2.Distance(structure.WorldPosition, worldPosition) < dist * 3.0f)
{
structureList.Add(structure);
}
@@ -147,7 +139,7 @@ namespace Barotrauma
{
for (int i = 0; i < structure.SectionCount; i++)
{
float distFactor = 1.0f - (Vector2.Distance(structure.SectionPosition(i), displayPosition) / displayRange);
float distFactor = 1.0f - (Vector2.Distance(structure.SectionPosition(i, true), worldPosition) / worldRange);
if (distFactor > 0.0f) structure.AddDamage(i, damage * distFactor);
}
}

View File

@@ -39,9 +39,9 @@ namespace Barotrauma
get { return size; }
}
public FireSource(Vector2 position, Hull spawningHull = null, bool networkEvent=false)
public FireSource(Vector2 worldPosition, Hull spawningHull = null, bool networkEvent=false)
{
hull = Hull.FindHull(position, spawningHull);
hull = Hull.FindHull(worldPosition, spawningHull);
if (hull == null || (!networkEvent && GameMain.Client!=null)) return;
if (fireSoundBasic==null)
@@ -50,11 +50,11 @@ namespace Barotrauma
fireSoundLarge = Sound.Load("Content/Sounds/firelarge.ogg");
}
lightSource = new LightSource(position, 50.0f, new Color(1.0f, 0.9f, 0.6f), hull == null ? null : hull.Submarine);
lightSource = new LightSource(worldPosition, 50.0f, new Color(1.0f, 0.9f, 0.6f), hull == null ? null : hull.Submarine);
hull.AddFireSource(this, !networkEvent);
this.position = position - new Vector2(-5.0f, 5.0f);
this.position = worldPosition - new Vector2(-5.0f, 5.0f);
//this.position.Y = hull.Rect.Y - hull.Rect.Height;

View File

@@ -229,7 +229,7 @@ namespace Barotrauma
{
pos.X += Math.Sign(flowForce.X);
pos.Y = MathHelper.Clamp((higherSurface+lowerSurface)/2.0f, rect.Y - rect.Height, rect.Y);
Vector2 velocity = new Vector2(
MathHelper.Clamp(flowForce.X, -5000.0f, 5000.0f) * Rand.Range(0.5f, 0.7f),
flowForce.Y * Rand.Range(0.5f, 0.7f));

View File

@@ -270,8 +270,11 @@ namespace Barotrauma
float maxDelta = Math.Max(Math.Abs(rightDelta[i]), Math.Abs(leftDelta[i]));
if (maxDelta > Rand.Range(1.0f,10.0f))
{
Vector2 particlePos = new Vector2(rect.X + WaveWidth * i, surface + waveY[i]);
if (Submarine != null) particlePos += Submarine.Position;
GameMain.ParticleManager.CreateParticle("mist",
new Vector2(rect.X + WaveWidth * i,surface + waveY[i]),
particlePos,
new Vector2(0.0f, -50.0f), 0.0f, this);
}
@@ -473,21 +476,21 @@ namespace Barotrauma
}
//returns the water block which contains the point (or null if it isn't inside any)
public static Hull FindHull(Vector2 position, Hull guess = null)
public static Hull FindHull(Vector2 worldPosition, Hull guess = null)
{
return FindHull(position, hullList, guess);
return FindHull(worldPosition, hullList, guess);
}
public static Hull FindHull(Vector2 position, List<Hull> hulls, Hull guess = null)
public static Hull FindHull(Vector2 worldPosition, List<Hull> hulls, Hull guess = null)
{
if (guess != null && hulls.Contains(guess))
{
if (Submarine.RectContains(guess.rect, position)) return guess;
if (Submarine.RectContains(guess.WorldRect, worldPosition)) return guess;
}
foreach (Hull w in hulls)
foreach (Hull hull in hulls)
{
if (Submarine.RectContains(w.rect, position)) return w;
if (Submarine.RectContains(hull.WorldRect, worldPosition)) return hull;
}
return null;

View File

@@ -9,6 +9,11 @@ namespace Barotrauma
get;
}
Vector2 WorldPosition
{
get;
}
float Health
{
get;

View File

@@ -35,18 +35,18 @@ namespace Barotrauma
public void Draw(SpriteBatch spriteBatch)
{
Vector2 pos = Vector2.Zero;// level.EndPosition;
Vector2 pos = new Vector2(0.0f, -level.StartPosition.Y);// level.EndPosition;
//pos.Y = -pos.Y - level.Position.Y;
if (GameMain.GameScreen.Cam.WorldView.Y < -pos.Y - 512) return;
pos.X = GameMain.GameScreen.Cam.WorldView.X - 512.0f;
pos.X = GameMain.GameScreen.Cam.WorldView.X -512.0f;
//pos.X += Position.X % 512;
int width = (int)(Math.Ceiling(GameMain.GameScreen.Cam.WorldView.Width / 512.0f + 2.0f) * 512.0f);
spriteBatch.Draw(shaftTexture,
new Rectangle((int)(MathUtils.Round(pos.X, 512.0f) - Submarine.Loaded.Position.X % 512), (int)pos.Y, width, 512),
new Rectangle((int)(MathUtils.Round(pos.X, 512.0f)), (int)pos.Y, width, 512),
new Rectangle(0, 0, width, 256),
Color.White, 0.0f,
Vector2.Zero,

View File

@@ -30,7 +30,6 @@ namespace Barotrauma.Lights
private Dictionary<LightSource, CachedShadow> cachedShadows;
private Vector2[] worldVertices;
private Vector2[] vertices;
private int primitiveCount;
@@ -75,7 +74,6 @@ namespace Barotrauma.Lights
cachedShadows = new Dictionary<LightSource, CachedShadow>();
vertices = points;
worldVertices = new Vector2[vertices.Length];
primitiveCount = vertices.Length;
CalculateDimensions();
@@ -115,7 +113,6 @@ namespace Barotrauma.Lights
for (int i = 0; i < vertices.Count(); i++)
{
vertices[i] += amount;
worldVertices[i] += amount;
}
CalculateDimensions();
@@ -125,26 +122,17 @@ namespace Barotrauma.Lights
{
cachedShadows.Clear();
worldVertices = points;
vertices = points;
}
private void CalculateShadowVertices(Vector2 lightSourcePos, bool los = true)
{
for (int i = 0; i < vertices.Length; i++)
{
worldVertices[i] = vertices[i];
if (parentEntity != null && parentEntity.Submarine != null)
{
worldVertices[i] += parentEntity.Submarine.Position;
}
}
//compute facing of each edge, using N*L
for (int i = 0; i < primitiveCount; i++)
{
Vector2 firstVertex = new Vector2(worldVertices[i].X, worldVertices[i].Y);
Vector2 firstVertex = new Vector2(vertices[i].X, vertices[i].Y);
int secondIndex = (i + 1) % primitiveCount;
Vector2 secondVertex = new Vector2(worldVertices[secondIndex].X, worldVertices[secondIndex].Y);
Vector2 secondVertex = new Vector2(vertices[secondIndex].X, vertices[secondIndex].Y);
Vector2 middle = (firstVertex + secondVertex) / 2;
Vector2 L = lightSourcePos - middle;
@@ -187,7 +175,7 @@ namespace Barotrauma.Lights
int svCount = 0;
while (svCount != shadowVertexCount * 2)
{
Vector3 vertexPos = new Vector3(worldVertices[currentIndex], 0.0f);
Vector3 vertexPos = new Vector3(vertices[currentIndex], 0.0f);
//one vertex on the hull
shadowVertices[svCount] = new VertexPositionColor();
@@ -217,7 +205,7 @@ namespace Barotrauma.Lights
for (int n = 0; n < 4; n += 3)
{
Vector3 penumbraStart = new Vector3((n == 0) ? worldVertices[startingIndex] : worldVertices[endingIndex], 0.0f);
Vector3 penumbraStart = new Vector3((n == 0) ? vertices[startingIndex] : vertices[endingIndex], 0.0f);
penumbraVertices[n] = new VertexPositionTexture();
penumbraVertices[n].Position = penumbraStart;
@@ -293,6 +281,8 @@ namespace Barotrauma.Lights
{
if (!Enabled) return;
if (parentEntity != null && parentEntity.Submarine != null) lightSourcePos -= parentEntity.Submarine.Position;
CalculateShadowVertices(lightSourcePos, los);
DrawShadows(graphicsDevice, cam, transform, los);
@@ -300,7 +290,15 @@ namespace Barotrauma.Lights
private void DrawShadows(GraphicsDevice graphicsDevice, Camera cam, Matrix transform, bool los = true)
{
shadowEffect.World = transform;
Vector3 offset = Vector3.Zero;
if (parentEntity != null && parentEntity.Submarine != null)
{
offset = new Vector3(parentEntity.Submarine.DrawPosition.X, parentEntity.Submarine.DrawPosition.Y, 0.0f);
}
shadowEffect.World = Matrix.CreateTranslation(offset) * transform;
shadowEffect.CurrentTechnique.Passes[0].Apply();
graphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleStrip, shadowVertices, 0, shadowVertices.Length - 2);

View File

@@ -128,7 +128,7 @@ namespace Barotrauma.Lights
//draw the light shape
//where Alpha is 0, nothing will be written
spriteBatch.Begin(SpriteSortMode.Deferred, CustomBlendStates.MultiplyWithAlpha, null, null, null, null, Matrix.CreateTranslation(new Vector3(Submarine.Loaded.Position.X, -Submarine.Loaded.Position.Y, 0.0f)) * cam.Transform);
spriteBatch.Begin(SpriteSortMode.Deferred, CustomBlendStates.MultiplyWithAlpha, null, null, null, null, Matrix.CreateTranslation(new Vector3(Submarine.Loaded.DrawPosition.X, -Submarine.Loaded.DrawPosition.Y, 0.0f)) * cam.Transform);
light.Draw(spriteBatch);
spriteBatch.End();
}

View File

@@ -70,7 +70,12 @@ namespace Barotrauma
public virtual Rectangle Rect {
get { return rect; }
set { rect = value; }
}
}
public Rectangle WorldRect
{
get { return Submarine == null ? rect : new Rectangle((int)(Submarine.Position.X + rect.X), (int)(Submarine.Position.Y + rect.Y), rect.Width, rect.Height); }
}
public virtual Sprite Sprite
{
@@ -505,12 +510,16 @@ namespace Barotrauma
foreach (MapEntity e in mapEntityList)
{
e.OnMapLoaded();
if (e.Submarine != null) e.Move(Submarine.HiddenSubPosition);
}
//mapEntityList.Sort((x, y) =>
//{
// return x.Name.CompareTo(y.Name);
//});
mapEntityList.Sort((x, y) =>
{
return x.Name.CompareTo(y.Name);
});
}

View File

@@ -292,16 +292,16 @@ namespace Barotrauma
Color color = (isHighlighted) ? Color.Green : Color.White;
if (isSelected && editing) color = Color.Red;
Vector2 drawPos = Submarine == null ? new Vector2(rect.X, -rect.Y) : new Vector2(rect.X + Submarine.DrawPosition.X, -(rect.Y + Submarine.DrawPosition.Y));
prefab.sprite.DrawTiled(spriteBatch, drawPos, new Vector2(rect.Width, rect.Height), Vector2.Zero, color);
Vector2 drawOffset = Submarine == null ? Vector2.Zero : Submarine.DrawPosition;
prefab.sprite.DrawTiled(spriteBatch, new Vector2(rect.X + drawOffset.X, -(rect.Y + drawOffset.Y)), new Vector2(rect.Width, rect.Height), Vector2.Zero, color);
foreach (WallSection s in sections)
{
if (s.isHighLighted)
{
GUI.DrawRectangle(spriteBatch,
drawPos, new Vector2(rect.Width, rect.Height),
new Vector2(s.rect.X + drawOffset.X, -(s.rect.Y + drawOffset.Y)), new Vector2(s.rect.Width, s.rect.Height),
new Color((s.damage / prefab.MaxHealth), 1.0f - (s.damage / prefab.MaxHealth), 0.0f, 1.0f), true);
}
@@ -310,7 +310,7 @@ namespace Barotrauma
if (s.damage < 0.01f) continue;
GUI.DrawRectangle(spriteBatch,
drawPos, new Vector2(rect.Width, rect.Height),
new Vector2(s.rect.X + drawOffset.X, -(s.rect.Y + drawOffset.Y)), new Vector2(s.rect.Width, s.rect.Height),
Color.Black * (s.damage / prefab.MaxHealth), true);
}
@@ -413,13 +413,17 @@ namespace Barotrauma
return sections[sectionIndex].damage;
}
public Vector2 SectionPosition(int sectionIndex)
public Vector2 SectionPosition(int sectionIndex, bool world = false)
{
if (sectionIndex < 0 || sectionIndex >= sections.Length) return Vector2.Zero;
return new Vector2(
Vector2 sectionPos = new Vector2(
sections[sectionIndex].rect.X + sections[sectionIndex].rect.Width / 2.0f,
sections[sectionIndex].rect.Y - sections[sectionIndex].rect.Height / 2.0f);
if (world && Submarine != null) sectionPos += Submarine.Position;
return sectionPos;
}
public AttackResult AddDamage(IDamageable attacker, Vector2 position, Attack attack, float deltaTime, bool playSound = false)
@@ -427,7 +431,10 @@ namespace Barotrauma
if (Submarine.Loaded != null && Submarine.Loaded.GodMode) return new AttackResult(0.0f, 0.0f);
if (!prefab.HasBody || prefab.IsPlatform) return new AttackResult(0.0f, 0.0f);
int i = FindSectionIndex(ConvertUnits.ToDisplayUnits(position));
Vector2 transformedPos = ConvertUnits.ToDisplayUnits(position);
if (Submarine != null) transformedPos -= Submarine.Position;
int i = FindSectionIndex(transformedPos);
if (i == -1) return new AttackResult(0.0f, 0.0f);
GameMain.ParticleManager.CreateParticle("dustcloud", SectionPosition(i), 0.0f, 0.0f);

View File

@@ -25,6 +25,10 @@ namespace Barotrauma
{
public static string SavePath = "Data" + System.IO.Path.DirectorySeparatorChar + "SavedSubs";
//position of the "actual submarine" which is rendered wherever the SubmarineBody is
//should be in an unreachable place
public static readonly Vector2 HiddenSubPosition = new Vector2(0.0f, 50000.0f);
public static List<Submarine> SavedSubmarines = new List<Submarine>();
public static readonly Vector2 GridSize = new Vector2(16.0f, 16.0f);
@@ -97,7 +101,7 @@ namespace Barotrauma
public override Vector2 Position
{
get { return subBody.Position; }
get { return subBody.Position - HiddenSubPosition; }
}
public new Vector2 DrawPosition
@@ -106,13 +110,13 @@ namespace Barotrauma
private set;
}
public Vector2 Speed
public Vector2 Velocity
{
get { return subBody==null ? Vector2.Zero : subBody.Speed; }
set
get { return subBody==null ? Vector2.Zero : subBody.Velocity; }
set
{
if (subBody == null) return;
subBody.Speed = value;
subBody.Velocity = value;
}
}
@@ -185,10 +189,6 @@ namespace Barotrauma
MapEntity.mapEntityList[i].Draw(spriteBatch, editing);
}
if (Submarine.Loaded!=null)
{
Submarine.Loaded.DrawPosition = Physics.Interpolate(Submarine.Loaded.prevPosition, Submarine.Loaded.Position);
}
if (loaded == null) return;
@@ -214,6 +214,11 @@ namespace Barotrauma
}
}
public void UpdateTransform()
{
DrawPosition = Physics.Interpolate(prevPosition, Position);
}
//math/physics stuff ----------------------------------------------------
public static Vector2 MouseToWorldGrid(Camera cam)
@@ -414,8 +419,8 @@ namespace Barotrauma
message.Write(Position.X);
message.Write(Position.Y);
message.Write(Speed.X);
message.Write(Speed.Y);
message.Write(Velocity.X);
message.Write(Velocity.Y);
return true;
}
@@ -446,7 +451,7 @@ namespace Barotrauma
//newTargetPosition = newTargetPosition + newSpeed * (float)(NetTime.Now - sendingTime);
subBody.TargetPosition = newTargetPosition;
subBody.Speed = newSpeed;
subBody.Velocity = newSpeed;
lastNetworkUpdate = sendingTime;
}
@@ -611,6 +616,8 @@ namespace Barotrauma
XDocument doc = OpenDoc(filePath);
if (doc == null) return;
subBody = new SubmarineBody(this);
foreach (XElement element in doc.Root.Elements())
{
string typeName = element.Name.ToString();
@@ -643,7 +650,7 @@ namespace Barotrauma
}
subBody = new SubmarineBody(this);
subBody.SetPosition(HiddenSubPosition);
loaded = this;
@@ -694,10 +701,10 @@ namespace Barotrauma
{
if (GameMain.GameScreen.Cam != null) GameMain.GameScreen.Cam.TargetPos = Vector2.Zero;
subBody = null;
Entity.RemoveAll();
subBody = null;
PhysicsBody.list.Clear();
Ragdoll.list.Clear();

View File

@@ -35,14 +35,12 @@ namespace Barotrauma
private Body body;
private Vector2 speed;
private Vector2 targetPosition;
float mass = 10000.0f;
private Vector2? lastContactPoint;
private VoronoiCell lastContactCell;
//private Vector2? lastContactPoint;
//private VoronoiCell lastContactCell;
public Rectangle Borders
{
@@ -50,13 +48,13 @@ namespace Barotrauma
private set;
}
public Vector2 Speed
public Vector2 Velocity
{
get { return speed; }
set
get { return body.LinearVelocity; }
set
{
if (!MathUtils.IsValid(value)) return;
speed = value;
body.LinearVelocity = value;
}
}
@@ -117,15 +115,16 @@ namespace Barotrauma
body = BodyFactory.CreateCompoundPolygon(GameMain.World, triangulatedVertices, 5.0f);
body.BodyType = BodyType.Dynamic;
body.CollisionCategories = Physics.CollisionMisc;
body.CollisionCategories = Physics.CollisionMisc | Physics.CollisionWall;
body.CollidesWith = Physics.CollisionLevel | Physics.CollisionCharacter;
body.Restitution = 0.0f;
body.Restitution = Restitution;
body.Friction = Friction;
body.FixedRotation = true;
body.Mass = mass;
body.Awake = true;
body.SleepingAllowed = false;
body.IgnoreGravity = true;
body.OnCollision += OnCollision;
body.OnSeparation += OnSeparation;
body.UserData = this;
}
@@ -224,14 +223,14 @@ namespace Barotrauma
Vector2 totalForce = CalculateBuoyancy();
if (speed.LengthSquared() > 0.000001f)
if (body.LinearVelocity.LengthSquared() > 0.000001f)
{
float dragCoefficient = 0.00001f;
float speedLength = (speed == Vector2.Zero) ? 0.0f : speed.Length();
float speedLength = (body.LinearVelocity == Vector2.Zero) ? 0.0f : body.LinearVelocity.Length();
float drag = speedLength * speedLength * dragCoefficient * mass;
totalForce += -Vector2.Normalize(speed) * drag;
totalForce += -Vector2.Normalize(body.LinearVelocity) * drag;
}
ApplyForce(totalForce);
@@ -267,7 +266,7 @@ namespace Barotrauma
public void ApplyForce(Vector2 force)
{
body.ApplyForce(force/100.0f);
body.ApplyForce(force);
}
public void SetPosition(Vector2 position)
@@ -317,31 +316,121 @@ namespace Barotrauma
depthDamageTimer = 10.0f;
}
private void UpdateColliding()
//private void UpdateColliding()
//{
// return;
// if (body.Position.LengthSquared()<0.00001f) return;
// Vector2 normal = Vector2.Normalize(body.Position);
// Vector2 simSpeed = ConvertUnits.ToSimUnits(body.LinearVelocity);
// float impact = Vector2.Dot(simSpeed, -normal);
// if (impact < 0.0f) return;
// Vector2 u = Vector2.Dot(simSpeed, -normal) * normal;
// Vector2 w = (simSpeed + u);
// //speed = ConvertUnits.ToDisplayUnits(w * (1.0f - Friction) + u * Restitution);
// if (lastContactPoint == null || lastContactCell==null || impact < 3.0f) return;
// SoundPlayer.PlayDamageSound(DamageSoundType.StructureBlunt, impact * 10.0f, ConvertUnits.ToDisplayUnits((Vector2)lastContactPoint));
// GameMain.GameScreen.Cam.Shake = impact * 2.0f;
// Vector2 limbForce = -normal * impact*0.5f;
// float length = limbForce.Length();
// if (length > 10.0f) limbForce = (limbForce / length) * 10.0f;
// foreach (Character c in Character.CharacterList)
// {
// if (c.AnimController.CurrentHull == null) continue;
// if (impact > 2.0f) c.AnimController.StunTimer = (impact - 2.0f) * 0.1f;
// foreach (Limb limb in c.AnimController.Limbs)
// {
// if (c.AnimController.LowestLimb == limb) continue;
// limb.body.ApplyLinearImpulse(limb.Mass * limbForce);
// }
// }
// Explosion.RangedStructureDamage(ConvertUnits.ToDisplayUnits((Vector2)lastContactPoint), impact*50.0f, impact*DamageMultiplier);
// //Body wallBody = Submarine.PickBody(
// // (Vector2)lastContactPoint - body.Position,
// // (Vector2)lastContactPoint + body.Position * 10.0f,
// // new List<Body>() { lastContactCell.body });
// //if (wallBody == null || wallBody.UserData == null) return;
// //var damageable = wallBody.UserData as IDamageable;
// //Structure structure = wallBody.UserData as Structure;
// //if (structure == null) return;
// //int sectionIndex = structure.FindSectionIndex(ConvertUnits.ToDisplayUnits(Submarine.LastPickedPosition));
// //for (int i = sectionIndex - (int)(impact / 5.0f); i < sectionIndex + (int)(impact / 5.0f); i++)
// //{
// // structure.AddDamage(i, impact * DamageMultiplier);
// //}
//}
public bool OnCollision(Fixture f1, Fixture f2, Contact contact)
{
return;
if (body.Position.LengthSquared()<0.00001f) return;
Vector2 normal = Vector2.Normalize(body.Position);
Vector2 simSpeed = ConvertUnits.ToSimUnits(speed);
float impact = Vector2.Dot(simSpeed, -normal);
if (impact < 0.0f) return;
Vector2 u = Vector2.Dot(simSpeed, -normal) * normal;
Vector2 w = (simSpeed + u);
speed = ConvertUnits.ToDisplayUnits(w * (1.0f - Friction) + u * Restitution);
VoronoiCell cell = f2.Body.UserData as VoronoiCell;
if (lastContactPoint == null || lastContactCell==null || impact < 3.0f) return;
SoundPlayer.PlayDamageSound(DamageSoundType.StructureBlunt, impact * 10.0f, ConvertUnits.ToDisplayUnits((Vector2)lastContactPoint));
if (cell == null)
{
Limb limb = f2.Body.UserData as Limb;
if (limb!=null && limb.character.Submarine==null)
{
Vector2 normal2;
FixedArray2<Vector2> points;
contact.GetWorldManifold(out normal2, out points);
if (Submarine.PickBody(points[0] - ConvertUnits.ToSimUnits(submarine.Position) + normal2, points[0] - ConvertUnits.ToSimUnits(submarine.Position) - normal2, null, Physics.CollisionWall) != null)
{
return true;
}
var ragdoll = limb.character.AnimController;
ragdoll.FindHull();
return false;
}
return true;
}
Vector2 normal;
FarseerPhysics.Common.FixedArray2<Vector2> worldPoints;
contact.GetWorldManifold(out normal, out worldPoints);
Vector2 lastContactPoint = worldPoints[0];
float impact = Vector2.Dot(Velocity, -normal);
//Vector2 u = Vector2.Dot(Velocity, -normal) * normal;
//Vector2 w = (Velocity + u);
//speed = ConvertUnits.ToDisplayUnits(w * (1.0f - Friction) + u * Restitution);
if (impact < 3.0f) return true;
SoundPlayer.PlayDamageSound(DamageSoundType.StructureBlunt, impact * 10.0f, ConvertUnits.ToDisplayUnits(lastContactPoint));
GameMain.GameScreen.Cam.Shake = impact * 2.0f;
Vector2 limbForce = -normal * impact*0.5f;
Vector2 limbForce = -normal * impact * 0.5f;
float length = limbForce.Length();
if (length > 10.0f) limbForce = (limbForce / length) * 10.0f;
@@ -359,141 +448,10 @@ namespace Barotrauma
}
}
Explosion.RangedStructureDamage(ConvertUnits.ToDisplayUnits((Vector2)lastContactPoint), impact*50.0f, impact*DamageMultiplier);
//Body wallBody = Submarine.PickBody(
// (Vector2)lastContactPoint - body.Position,
// (Vector2)lastContactPoint + body.Position * 10.0f,
// new List<Body>() { lastContactCell.body });
//if (wallBody == null || wallBody.UserData == null) return;
//var damageable = wallBody.UserData as IDamageable;
//Structure structure = wallBody.UserData as Structure;
//if (structure == null) return;
//int sectionIndex = structure.FindSectionIndex(ConvertUnits.ToDisplayUnits(Submarine.LastPickedPosition));
//for (int i = sectionIndex - (int)(impact / 5.0f); i < sectionIndex + (int)(impact / 5.0f); i++)
//{
// structure.AddDamage(i, impact * DamageMultiplier);
//}
}
public bool OnCollision(Fixture f1, Fixture f2, Contact contact)
{
VoronoiCell cell = f2.Body.UserData as VoronoiCell;
if (cell == null)
{
Limb limb = f2.Body.UserData as Limb;
if (limb!=null && limb.character.Submarine==null)
{
Vector2 normal2;
FixedArray2<Vector2> points;
contact.GetWorldManifold(out normal2, out points);
if (Submarine.PickBody(points[0] - ConvertUnits.ToSimUnits(submarine.Position), points[0] - ConvertUnits.ToSimUnits(submarine.Position) - normal2, null, Physics.CollisionWall) != null)
{
return true;
}
return false;
//var ragdoll = limb.character.AnimController;
//ragdoll.SetPosition(ragdoll.RefLimb.Position - body.Position);
//limb.character.Submarine = submarine;
}
return true;
}
lastContactCell = cell;
Vector2 normal;
FarseerPhysics.Common.FixedArray2<Vector2> worldPoints;
contact.GetWorldManifold(out normal, out worldPoints);
lastContactPoint = worldPoints[0];
Explosion.RangedStructureDamage(ConvertUnits.ToDisplayUnits(lastContactPoint), impact * 50.0f, impact * DamageMultiplier);
return true;
//Vector2 normal = contact.Manifold.LocalNormal;
//Vector2 simSpeed = ConvertUnits.ToSimUnits(speed);
//float impact = Vector2.Dot(-simSpeed, normal);
////Vector2 u = Vector2.Dot(simSpeed, -normal) * -normal;
////Vector2 w = simSpeed - u;
//Vector2 limbForce = normal * impact;
////float length = limbForce.Length();
////if (length > 10.0f) limbForce = (limbForce / length) * 10.0f;
////foreach (Character c in Character.CharacterList)
////{
//// if (c.AnimController.CurrentHull == null) continue;
//// if (impact > 2.0f) c.AnimController.StunTimer = (impact - 2.0f) * 0.1f;
//// foreach (Limb limb in c.AnimController.Limbs)
//// {
//// if (c.AnimController.LowestLimb == limb) continue;
//// limb.body.ApplyLinearImpulse(limb.Mass * limbForce);
//// }
////}
//System.Diagnostics.Debug.WriteLine("IMPACT: " + impact + " normal: " + normal + " simspeed: " + simSpeed);
//if (impact > 1.0f)
//{
// contact.GetWorldManifold(out normal, out worldPoints);
// lastContactPoint = worldPoints[0];
// AmbientSoundManager.PlayDamageSound(DamageSoundType.StructureBlunt, impact * 10.0f, ConvertUnits.ToDisplayUnits(worldPoints[0]));
// GameMain.GameScreen.Cam.Shake = impact * 2.0f;
// //speed = ConvertUnits.ToDisplayUnits(w * 0.9f + u * 0.5f);
// //FixedArray2<Vector2> worldPoints;
// //contact.GetWorldManifold(out normal, out worldPoints);
// //if (contact.Manifold.PointCount >= 1)
// //{
// // Vector2 contactPoint = worldPoints[0];
// // Body wallBody = Submarine.PickBody(contactPoint, contactPoint + normal, new List<Body>() { cell.body });
// // if (wallBody!=null && wallBody.UserData!=null)
// // {
// // Structure s = wallBody.UserData as Structure;
// // }
// //}
// //foreach (GraphEdge ge in cell.edges)
// //{
// // Body wallBody = Submarine.PickBody(
// // ConvertUnits.ToSimUnits(ge.point1 + GameMain.GameSession.Level.Position + normal),
// // ConvertUnits.ToSimUnits(ge.point2 + GameMain.GameSession.Level.Position + normal), new List<Body>() { cell.body });
// // if (wallBody == null || wallBody.UserData == null) continue;
// // Structure structure = wallBody.UserData as Structure;
// // if (structure == null) continue;
// // structure.AddDamage(
// // structure.FindSectionIndex(ConvertUnits.ToDisplayUnits(Submarine.LastPickedPosition)), impact*50.0f);
// //}
//}
//collisionRigidness = 0.8f;
//return true;
}
public void OnSeparation(Fixture f1, Fixture f2)
{
lastContactPoint = null;
}
}
}

View File

@@ -403,7 +403,7 @@ namespace Barotrauma
public override void OnMapLoaded()
{
currentHull = Hull.FindHull(this.Position);
currentHull = Hull.FindHull(WorldPosition);
}
public override XElement Save(XDocument doc)

View File

@@ -74,7 +74,7 @@ namespace Barotrauma.Particles
spriteIndex = Rand.Int(prefab.Sprites.Count);
currentHull = Hull.FindHull(position, hullGuess);
if (currentHull == null) position = Submarine.Loaded == null ? position : position + Submarine.Loaded.Position;
//if (currentHull == null) position = Submarine.Loaded == null ? position : position + Submarine.Loaded.Position;
this.position = position;
prevPosition = position;
@@ -164,8 +164,8 @@ namespace Barotrauma.Particles
if ((prefab.DeleteOnCollision || prefab.CollidesWithWalls) && currentHull!=null)
{
Vector2 edgePos = position + prefab.CollisionRadius * Vector2.Normalize(velocity) * size.X;
if (!Submarine.RectContains(currentHull.Rect, edgePos))
if (!Submarine.RectContains(currentHull.WorldRect, edgePos))
{
if (prefab.DeleteOnCollision) return false;
@@ -174,13 +174,13 @@ namespace Barotrauma.Particles
{
if (!gap.isHorizontal)
{
if (gap.Rect.X > position.X || gap.Rect.Right < position.X) continue;
if (Math.Sign(velocity.Y) != Math.Sign(gap.Rect.Y - (currentHull.Rect.Y-currentHull.Rect.Height))) continue;
if (gap.WorldRect.X > position.X || gap.WorldRect.Right < position.X) continue;
if (Math.Sign(velocity.Y) != Math.Sign(gap.WorldRect.Y - (currentHull.WorldRect.Y - currentHull.WorldRect.Height))) continue;
}
else
{
if (gap.Rect.Y < position.Y || gap.Rect.Y - gap.Rect.Height > position.Y) continue;
if (Math.Sign(velocity.X) != Math.Sign(gap.Rect.Center.X - currentHull.Rect.Center.X)) continue;
if (gap.WorldRect.Y < position.Y || gap.WorldRect.Y - gap.WorldRect.Height > position.Y) continue;
if (Math.Sign(velocity.X) != Math.Sign(gap.WorldRect.Center.X - currentHull.WorldRect.Center.X)) continue;
}
//Rectangle enlargedRect = new Rectangle(gap.Rect.X - 10, gap.Rect.Y + 10, gap.Rect.Width + 20, gap.Rect.Height + 20);
@@ -224,27 +224,29 @@ namespace Barotrauma.Particles
}
private void OnWallCollision(Hull prevHull, Vector2 position)
{
if (position.Y < prevHull.Rect.Y - prevHull.Rect.Height)
{
Rectangle prevHullRect = prevHull.WorldRect;
if (position.Y < prevHullRect.Y - prevHullRect.Height)
{
position.Y = prevHull.Rect.Y - prevHull.Rect.Height + 1.0f;
position.Y = prevHullRect.Y - prevHullRect.Height + 1.0f;
velocity.Y = -velocity.Y;
}
else if (position.Y > prevHull.Rect.Y)
else if (position.Y > prevHullRect.Y)
{
position.Y = prevHull.Rect.Y - 1.0f;
position.Y = prevHullRect.Y - 1.0f;
velocity.X = Math.Abs(velocity.Y) * Math.Sign(velocity.X);
velocity.Y = -velocity.Y*0.1f;
}
if (position.X < prevHull.Rect.X)
if (position.X < prevHullRect.X)
{
position.X = prevHull.Rect.X + 1.0f;
position.X = prevHullRect.X + 1.0f;
velocity.X = -velocity.X;
}
else if (position.X > prevHull.Rect.X + prevHull.Rect.Width)
else if (position.X > prevHullRect.X + prevHullRect.Width)
{
position.X = prevHull.Rect.X + prevHull.Rect.Width - 1.0f;
position.X = prevHullRect.X + prevHullRect.Width - 1.0f;
velocity.X = -velocity.X;
}
@@ -265,11 +267,8 @@ namespace Barotrauma.Particles
drawSize *= ((totalLifeTime - lifeTime) / prefab.GrowTime);
}
Vector2 screenSpacePos = currentHull == null && Submarine.Loaded != null ? drawPosition - Submarine.Loaded.Position : drawPosition;
screenSpacePos.Y = -screenSpacePos.Y;
prefab.Sprites[spriteIndex].Draw(spriteBatch,
screenSpacePos,
new Vector2(drawPosition.X, -drawPosition.Y),
color * alpha,
prefab.Sprites[spriteIndex].origin, drawRotation,
drawSize, SpriteEffects.None, prefab.Sprites[spriteIndex].Depth);

View File

@@ -166,11 +166,14 @@ namespace Barotrauma
public void DrawMap(GraphicsDevice graphics, SpriteBatch spriteBatch)
{
if (Submarine.Loaded != null) Submarine.Loaded.UpdateTransform();
GameMain.LightManager.ObstructVision = Character.Controlled != null && Character.Controlled.ObstructVision;
GameMain.LightManager.UpdateLightMap(graphics, spriteBatch, cam);
GameMain.LightManager.UpdateObstructVision(graphics, spriteBatch, cam,
Character.Controlled==null ? LightManager.ViewPos : Character.Controlled.CursorPosition);
Character.Controlled==null ? LightManager.ViewPos : Character.Controlled.CursorWorldPosition);
//----------------------------------------------------------------------------------------
//1. draw the background, characters and the parts of the submarine that are behind them

View File

@@ -201,7 +201,7 @@ namespace Barotrauma
float movementFactor = 0.0f;
if (Submarine.Loaded != null)
{
movementFactor = (Submarine.Loaded.Speed == Vector2.Zero) ? 0.0f : Submarine.Loaded.Speed.Length() / 500.0f;
movementFactor = (Submarine.Loaded.Velocity == Vector2.Zero) ? 0.0f : Submarine.Loaded.Velocity.Length() / 5.0f;
movementFactor = MathHelper.Clamp(movementFactor, 0.0f, 1.0f);
}

Binary file not shown.