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
@@ -15,7 +15,7 @@
<!-- lower yaw --> <!-- lower yaw -->
<limb id = "1" radius="20" height="240" impacttolerance="50.0"> <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"/> <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> </limb>
<!-- body --> <!-- body -->
@@ -27,6 +27,11 @@ namespace Barotrauma
set { sightRange = value; } set { sightRange = value; }
} }
public Vector2 WorldPosition
{
get { return Entity.WorldPosition; }
}
public Vector2 SimPosition public Vector2 SimPosition
{ {
get { return Entity.SimPosition; } get { return Entity.SimPosition; }
@@ -167,12 +167,17 @@ namespace Barotrauma
selectedTargetMemory.Priority -= deltaTime; selectedTargetMemory.Priority -= deltaTime;
Vector2 attackPosition = selectedAiTarget.SimPosition; Vector2 attackSimPosition = Character.Submarine==null ? ConvertUnits.ToSimUnits(selectedAiTarget.WorldPosition) : selectedAiTarget.SimPosition;
if (wallAttackPos != Vector2.Zero) attackPosition = wallAttackPos; 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) if (coolDownTimer>0.0f)
{ {
UpdateCoolDown(attackPosition, deltaTime); UpdateCoolDown(attackSimPosition, deltaTime);
return; return;
} }
@@ -187,7 +192,7 @@ namespace Barotrauma
raycastTimer = RaycastInterval; raycastTimer = RaycastInterval;
} }
steeringManager.SteeringSeek(attackPosition); steeringManager.SteeringSeek(attackSimPosition);
//check if any of the limbs is close enough to attack the target //check if any of the limbs is close enough to attack the target
if (attackingLimb == null) if (attackingLimb == null)
@@ -195,7 +200,7 @@ namespace Barotrauma
foreach (Limb limb in Character.AnimController.Limbs) foreach (Limb limb in Character.AnimController.Limbs)
{ {
if (limb.attack==null || limb.attack.Type == AttackType.None) continue; 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; attackingLimb = limb;
break; break;
@@ -203,7 +208,7 @@ namespace Barotrauma
return; return;
} }
UpdateLimbAttack(deltaTime, attackingLimb, attackPosition); UpdateLimbAttack(deltaTime, attackingLimb, attackSimPosition);
} }
@@ -230,9 +235,19 @@ namespace Barotrauma
private void GetTargetEntity() private void GetTargetEntity()
{ {
targetEntity = null; targetEntity = null;
//check if there's a wall between the target and the Character //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; 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); Body closestBody = Submarine.CheckVisibility(rayStart, rayEnd);
if (Submarine.LastPickedFraction == 1.0f || closestBody == null) if (Submarine.LastPickedFraction == 1.0f || closestBody == null)
@@ -245,6 +260,8 @@ namespace Barotrauma
if (wall == null) if (wall == null)
{ {
wallAttackPos = Submarine.LastPickedPosition; wallAttackPos = Submarine.LastPickedPosition;
if (selectedAiTarget.Entity.Submarine!=null) wallAttackPos -= ConvertUnits.ToSimUnits(selectedAiTarget.Entity.Submarine.Position);
} }
else else
{ {
@@ -261,6 +278,7 @@ namespace Barotrauma
if (wall.SectionDamage(i) > sectionDamage) sectionIndex = i; if (wall.SectionDamage(i) > sectionDamage) sectionIndex = i;
} }
wallAttackPos = wall.SectionPosition(sectionIndex); wallAttackPos = wall.SectionPosition(sectionIndex);
//if (wall.Submarine != null) wallAttackPos += wall.Submarine.Position;
wallAttackPos = ConvertUnits.ToSimUnits(wallAttackPos); wallAttackPos = ConvertUnits.ToSimUnits(wallAttackPos);
} }
@@ -288,14 +306,7 @@ namespace Barotrauma
float dir = (limb.attack.Type == AttackType.PinchCW) ? 1.0f : -1.0f; float dir = (limb.attack.Type == AttackType.PinchCW) ? 1.0f : -1.0f;
if (wallAttackPos != Vector2.Zero && targetEntity != null) damageTarget = (wallAttackPos != Vector2.Zero && targetEntity != null) ? targetEntity : selectedAiTarget.Entity as IDamageable;
{
damageTarget = targetEntity as IDamageable;
}
else
{
damageTarget = selectedAiTarget.Entity as IDamageable;
}
attackTimer += deltaTime*0.05f; attackTimer += deltaTime*0.05f;
@@ -305,7 +316,7 @@ namespace Barotrauma
break; 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) if (dist < limb.attack.Range * 0.5f)
{ {
attackTimer += deltaTime; attackTimer += deltaTime;
@@ -392,9 +403,8 @@ namespace Barotrauma
} }
dist = Vector2.Distance( dist = Vector2.Distance(
character.AnimController.Limbs[0].SimPosition, character.WorldPosition,
target.SimPosition); target.WorldPosition);
dist = ConvertUnits.ToDisplayUnits(dist);
AITargetMemory targetMemory = FindTargetMemory(target); AITargetMemory targetMemory = FindTargetMemory(target);
@@ -406,6 +416,11 @@ namespace Barotrauma
Vector2 rayStart = character.AnimController.Limbs[0].SimPosition; Vector2 rayStart = character.AnimController.Limbs[0].SimPosition;
Vector2 rayEnd = target.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); Body closestBody = Submarine.CheckVisibility(rayStart, rayEnd);
Structure closestStructure = (closestBody == null) ? null : closestBody.UserData as Structure; Structure closestStructure = (closestBody == null) ? null : closestBody.UserData as Structure;
@@ -490,12 +505,12 @@ namespace Barotrauma
{ {
if (Character.IsDead) return; if (Character.IsDead) return;
Vector2 pos = Character.Position; Vector2 pos = Character.WorldPosition;
pos.Y = -pos.Y; pos.Y = -pos.Y;
if (selectedAiTarget!=null) 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) if (wallAttackPos!=Vector2.Zero)
{ {
@@ -87,7 +87,9 @@ namespace Barotrauma
{ {
if (selectedAiTarget != null) 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; IndoorsSteeringManager pathSteering = steeringManager as IndoorsSteeringManager;
@@ -89,7 +89,7 @@ namespace Barotrauma
foreach (WayPoint wp in WayPoint.WayPointList) 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) foreach (string tag in wp.IdCardTags)
{ {
@@ -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( Vector2 findPos = worldPosition==null ? refLimb.WorldPosition : (Vector2)worldPosition;
ConvertUnits.ToDisplayUnits(refLimb.SimPosition),
currentHull); Hull newHull = Hull.FindHull(findPos, currentHull);
if (newHull == currentHull) return; if (newHull == currentHull) return;
@@ -619,11 +619,9 @@ namespace Barotrauma
foreach (Limb limb in Limbs) foreach (Limb limb in Limbs)
{ {
Vector2 limbPosition = ConvertUnits.ToDisplayUnits(limb.SimPosition);
//find the room which the limb is in //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 //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; bool prevInWater = limb.inWater;
limb.inWater = false; limb.inWater = false;
@@ -633,9 +631,9 @@ namespace Barotrauma
//limb isn't in any room -> it's in the water //limb isn't in any room -> it's in the water
limb.inWater = true; limb.inWater = true;
} }
else if (limbHull.Volume > 0.0f && Submarine.RectContains(limbHull.Rect, limbPosition)) else if (limbHull.Volume > 0.0f && Submarine.RectContains(limbHull.Rect, limb.Position))
{ {
if (limbPosition.Y < limbHull.Surface) if (limb.Position.Y < limbHull.Surface)
{ {
limb.inWater = true; limb.inWater = true;
@@ -659,12 +657,12 @@ namespace Barotrauma
//create a splash particle //create a splash particle
GameMain.ParticleManager.CreateParticle("watersplash", 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)), new Vector2(0.0f, Math.Abs(-limb.LinearVelocity.Y * 10.0f)),
0.0f, limbHull); 0.0f, limbHull);
GameMain.ParticleManager.CreateParticle("bubbles", 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, limb.LinearVelocity*0.001f,
0.0f, limbHull); 0.0f, limbHull);
@@ -678,7 +676,7 @@ namespace Barotrauma
float parallel = (float)Math.Abs(Math.Sin(limb.Rotation)); float parallel = (float)Math.Abs(Math.Sin(limb.Rotation));
Vector2 impulse = Vector2.Multiply(limb.LinearVelocity, -parallel * limb.Mass); Vector2 impulse = Vector2.Multiply(limb.LinearVelocity, -parallel * limb.Mass);
//limb.body.ApplyLinearImpulse(impulse); //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); limbHull.WaveVel[n] = Math.Min(impulse.Y * 1.0f, 5.0f);
StrongestImpact = ((impulse.Length() * 0.5f) - limb.impactTolerance); StrongestImpact = ((impulse.Length() * 0.5f) - limb.impactTolerance);
} }
+1 -1
View File
@@ -109,7 +109,7 @@ namespace Barotrauma
sound = Sound.Load(soundPath); 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); Duration = ToolBox.GetAttributeFloat(element, "duration", 0.0f);
@@ -153,13 +153,13 @@ namespace Barotrauma
if (velocity.X < 0.0f) rotation -= MathHelper.Pi; 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) if (depth > 0.0f)
{ {
Vector2 camOffset = drawPosition - GameMain.GameScreen.Cam.WorldViewCenter; 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), prefab.Sprite.Draw(spriteBatch, new Vector2(drawPosition.X, -drawPosition.Y), Color.Lerp(Color.White, Color.DarkBlue, (depth/MaxDepth)*0.3f),
@@ -47,9 +47,10 @@ namespace Barotrauma
if (position == null) 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 = new Vector2(wp.Rect.X, wp.Rect.Y);
pos += Rand.Vector(200.0f); pos += Rand.Vector(200.0f);
+13 -7
View File
@@ -138,6 +138,11 @@ namespace Barotrauma
} }
} }
public Vector2 CursorWorldPosition
{
get { return Submarine == null ? cursorPosition : cursorPosition + Submarine.Position; }
}
public Character ClosestCharacter public Character ClosestCharacter
{ {
get { return closestCharacter; } get { return closestCharacter; }
@@ -295,7 +300,7 @@ namespace Barotrauma
public static Character Create(CharacterInfo characterInfo, WayPoint spawnPoint, bool isNetworkPlayer = false) 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) 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); //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); CharacterList.Add(this);
@@ -735,7 +741,7 @@ namespace Barotrauma
{ {
Limb head = AnimController.GetLimb(LimbType.Head); Limb head = AnimController.GetLimb(LimbType.Head);
Lights.LightManager.ViewPos = ConvertUnits.ToDisplayUnits(WorldPosition); Lights.LightManager.ViewPos = WorldPosition;
if (!DisableControls) if (!DisableControls)
{ {
@@ -1004,7 +1010,7 @@ namespace Barotrauma
AnimController.DebugDraw(spriteBatch); 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 - 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); 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++) for (int i = 0; i < 10; i++)
{ {
Particle p = GameMain.ParticleManager.CreateParticle("waterblood", Particle p = GameMain.ParticleManager.CreateParticle("waterblood",
centerOfMass + Rand.Vector(50.0f), ConvertUnits.ToDisplayUnits(centerOfMass) + Rand.Vector(50.0f),
Vector2.Zero); Vector2.Zero);
if (p!=null) p.Size *= 2.0f; if (p!=null) p.Size *= 2.0f;
GameMain.ParticleManager.CreateParticle("bubbles", 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))); new Vector2(Rand.Range(-50f, 50f), Rand.Range(-100f,50f)));
} }
+7 -2
View File
@@ -79,6 +79,11 @@ namespace Barotrauma
get { return doesFlip; } get { return doesFlip; }
} }
public Vector2 WorldPosition
{
get { return character.Submarine == null ? Position : Position + character.Submarine.Position; }
}
public Vector2 Position public Vector2 Position
{ {
get { return ConvertUnits.ToDisplayUnits(body.SimPosition); } get { return ConvertUnits.ToDisplayUnits(body.SimPosition); }
@@ -352,13 +357,13 @@ namespace Barotrauma
if (particleVel != Vector2.Zero) particleVel = Vector2.Normalize(particleVel); if (particleVel != Vector2.Zero) particleVel = Vector2.Normalize(particleVel);
GameMain.ParticleManager.CreateParticle("blood", GameMain.ParticleManager.CreateParticle("blood",
Position, WorldPosition,
particleVel * Rand.Range(100.0f, 300.0f), 0.0f, character.AnimController.CurrentHull); particleVel * Rand.Range(100.0f, 300.0f), 0.0f, character.AnimController.CurrentHull);
} }
for (int i = 0; i < bloodAmount / 2; i++) 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; damage += Math.Max(amount,bleedingAmount) / character.MaxHealth * 100.0f;
+1 -1
View File
@@ -212,7 +212,7 @@ namespace Barotrauma
protected virtual void Apply(float deltaTime, Entity entity, List<IPropertyObject> targets) 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 (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, ConvertUnits.ToDisplayUnits(entity.SimPosition));
+2 -2
View File
@@ -225,7 +225,7 @@ namespace Barotrauma
if (commands[1].ToLower()=="human") if (commands[1].ToLower()=="human")
{ {
WayPoint spawnPoint = WayPoint.GetRandom(SpawnType.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) if (GameMain.GameSession != null)
{ {
SinglePlayerMode mode = GameMain.GameSession.gameMode as SinglePlayerMode; SinglePlayerMode mode = GameMain.GameSession.gameMode as SinglePlayerMode;
@@ -237,7 +237,7 @@ namespace Barotrauma
else else
{ {
WayPoint spawnPoint = WayPoint.GetRandom(SpawnType.Enemy); 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; break;
@@ -30,7 +30,7 @@ namespace Barotrauma
return; return;
} }
Hull cargoRoom = Hull.FindHull(wp.Position); Hull cargoRoom = Hull.FindHull(wp.WorldPosition);
if (cargoRoom == null) if (cargoRoom == null)
{ {
@@ -343,7 +343,7 @@ namespace Barotrauma
bool broken = false; bool broken = false;
do do
{ {
Submarine.Loaded.Speed = Vector2.Zero; Submarine.Loaded.Velocity = Vector2.Zero;
moloch.AIController.SelectTarget(steering.Item.CurrentHull.AiTarget); moloch.AIController.SelectTarget(steering.Item.CurrentHull.AiTarget);
Vector2 steeringDir = windows[0].Position - moloch.Position; Vector2 steeringDir = windows[0].Position - moloch.Position;
+1 -1
View File
@@ -318,7 +318,7 @@ namespace Barotrauma.Items.Components
} }
Vector2 pos = new Vector2(item.Rect.Center.X, item.Rect.Y); 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; pos.Y = -pos.Y;
spriteBatch.Draw(doorSprite.Texture, pos, spriteBatch.Draw(doorSprite.Texture, pos,
@@ -24,8 +24,8 @@ namespace Barotrauma.Items.Components
[HasDefaultValue(0.0f, false)] [HasDefaultValue(0.0f, false)]
public float Range public float Range
{ {
get { return ConvertUnits.ToDisplayUnits(range); } get { return range; }
set { range = ConvertUnits.ToSimUnits(value); } set { range = value; }
} }
[HasDefaultValue(0.0f, false)] [HasDefaultValue(0.0f, false)]
@@ -61,8 +61,8 @@ namespace Barotrauma.Items.Components
[HasDefaultValue("0.0,0.0", false)] [HasDefaultValue("0.0,0.0", false)]
public string BarrelPos public string BarrelPos
{ {
get { return ToolBox.Vector2ToString(ConvertUnits.ToDisplayUnits(barrelPos)); } get { return ToolBox.Vector2ToString(barrelPos); }
set { barrelPos = ConvertUnits.ToSimUnits(ToolBox.ParseToVector2(value)); } set { barrelPos = ToolBox.ParseToVector2(value); }
} }
public Vector2 TransformedBarrelPos public Vector2 TransformedBarrelPos
@@ -72,7 +72,7 @@ namespace Barotrauma.Items.Components
Matrix bodyTransform = Matrix.CreateRotationZ(item.body.Rotation); Matrix bodyTransform = Matrix.CreateRotationZ(item.body.Rotation);
Vector2 flippedPos = barrelPos; Vector2 flippedPos = barrelPos;
if (item.body.Dir < 0.0f) flippedPos.X = -flippedPos.X; 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; IsActive = true;
Vector2 targetPosition = item.body.SimPosition;
//targetPosition = targetPosition.X, -targetPosition.Y); //targetPosition = targetPosition.X, -targetPosition.Y);
float degreeOfSuccess = DegreeOfSuccess(character)/100.0f; float degreeOfSuccess = DegreeOfSuccess(character)/100.0f;
@@ -126,6 +125,7 @@ namespace Barotrauma.Items.Components
return false; return false;
} }
Vector2 targetPosition = item.WorldPosition;
targetPosition += new Vector2( targetPosition += new Vector2(
(float)Math.Cos(item.body.Rotation), (float)Math.Cos(item.body.Rotation),
(float)Math.Sin(item.body.Rotation)) * range * item.body.Dir; (float)Math.Sin(item.body.Rotation)) * range * item.body.Dir;
@@ -137,14 +137,18 @@ namespace Barotrauma.Items.Components
ignoredBodies.Add(limb.body.FarseerBody); 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; pickedPosition = Submarine.LastPickedPosition;
if (ExtinquishAmount > 0.0f) 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); Hull hull = Hull.FindHull(displayPos, item.CurrentHull);
if (hull != null) hull.Extinquish(deltaTime, ExtinquishAmount, displayPos); if (hull != null) hull.Extinquish(deltaTime, ExtinquishAmount, displayPos);
} }
@@ -224,7 +228,7 @@ namespace Barotrauma.Items.Components
if (!string.IsNullOrWhiteSpace(particles)) 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); -item.body.Rotation + ((item.body.Dir>0.0f) ? 0.0f : MathHelper.Pi), ParticleSpeed);
} }
@@ -74,7 +74,7 @@ namespace Barotrauma.Items.Components
for (int i = 0; i < 5; i++) 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)), -currForce / 5.0f + new Vector2(Rand.Range(-100.0f, 100.0f), Rand.Range(-50f, 50f)),
0.0f, item.CurrentHull); 0.0f, item.CurrentHull);
} }
@@ -103,7 +103,7 @@ namespace Barotrauma.Items.Components
private void GetHull() 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) public override void DrawHUD(SpriteBatch spriteBatch, Character character)
@@ -163,7 +163,7 @@ namespace Barotrauma.Items.Components
Vector2 baseVel = Rand.Vector(300.0f); Vector2 baseVel = Rand.Vector(300.0f);
for (int i = 0; i < 10; i++) 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); baseVel + Rand.Vector(100.0f), 0.0f, item.CurrentHull);
if (particle != null) particle.Size *= Rand.Range(0.5f, 1.0f); if (particle != null) particle.Size *= Rand.Range(0.5f, 1.0f);
@@ -193,7 +193,7 @@ namespace Barotrauma.Items.Components
{ {
float prediction = 5.0f; 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); Vector2 targetSpeed = ((steeringPath.CurrentNode.Position - Submarine.Loaded.Position) - futurePosition);
targetSpeed = Vector2.Normalize(targetSpeed); targetSpeed = Vector2.Normalize(targetSpeed);
@@ -67,7 +67,7 @@ namespace Barotrauma.Items.Components
Vector2 baseVel = Rand.Vector(300.0f); Vector2 baseVel = Rand.Vector(300.0f);
for (int i = 0; i < 10; i++) 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); baseVel + Rand.Vector(100.0f), 0.0f, item.CurrentHull);
if (particle != null) particle.Size *= Rand.Range(0.5f, 1.0f); if (particle != null) particle.Size *= Rand.Range(0.5f, 1.0f);
@@ -4,31 +4,17 @@ namespace Barotrauma.Items.Components
{ {
class OxygenDetector : ItemComponent class OxygenDetector : ItemComponent
{ {
private Hull hull;
public OxygenDetector(Item item, XElement element) public OxygenDetector(Item item, XElement element)
: base (item, element) : base (item, element)
{ {
hull = Hull.FindHull(item.Position);
IsActive = true; 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) public override void Update(float deltaTime, Camera cam)
{ {
if (hull == null) return; if (item.CurrentHull == null) return;
item.SendSignal(((int)hull.OxygenPercentage).ToString(), "signal_out"); item.SendSignal(((int)item.CurrentHull.OxygenPercentage).ToString(), "signal_out");
} }
@@ -41,11 +41,10 @@ namespace Barotrauma.Items.Components
public override void Move(Vector2 amount) public override void Move(Vector2 amount)
{ {
//amount = FarseerPhysics.ConvertUnits.ToDisplayUnits(amount); for (int i = 0; i < Nodes.Count; i++)
//for (int i = 0; i<Nodes.Count; i++) {
//{ Nodes[i] += amount;
// Nodes[i] += amount; }
//}
} }
public Connection OtherConnection(Connection connection) public Connection OtherConnection(Connection connection)
@@ -348,9 +347,11 @@ namespace Barotrauma.Items.Components
MapEntity.DisableSelect = true; MapEntity.DisableSelect = true;
Nodes[(int)selectedNodeIndex] = GameMain.EditMapScreen.Cam.ScreenToWorld(PlayerInput.MousePosition); 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); MapEntity.SelectEntity(item);
} }
} }
@@ -362,6 +363,12 @@ namespace Barotrauma.Items.Components
private void DrawSection(SpriteBatch spriteBatch, Vector2 start, Vector2 end, Color color) 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; start.Y = -start.Y;
end.Y = -end.Y; end.Y = -end.Y;
+5 -1
View File
@@ -81,8 +81,12 @@ namespace Barotrauma.Items.Components
public override void Draw(SpriteBatch spriteBatch, bool editing) 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, barrelSprite.Draw(spriteBatch,
new Vector2(item.Rect.X, -item.Rect.Y) + barrelPos, Color.White, drawPos + barrelPos, Color.White,
rotation + MathHelper.PiOver2, 1.0f, rotation + MathHelper.PiOver2, 1.0f,
SpriteEffects.None, item.Sprite.Depth+0.01f); SpriteEffects.None, item.Sprite.Depth+0.01f);
} }
+2 -3
View File
@@ -378,9 +378,8 @@ namespace Barotrauma
if (ItemList != null && body != null) 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); //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) foreach (ItemComponent ic in components)
{ {
@@ -409,7 +408,7 @@ namespace Barotrauma
public virtual Hull FindHull() public virtual Hull FindHull()
{ {
CurrentHull = Hull.FindHull((body == null) ? Position : ConvertUnits.ToDisplayUnits(body.SimPosition), CurrentHull); CurrentHull = Hull.FindHull(WorldPosition, CurrentHull);
if (body!=null) if (body!=null)
{ {
body.Submarine = CurrentHull == null ? null : Submarine.Loaded; body.Submarine = CurrentHull == null ? null : Submarine.Loaded;
+21 -29
View File
@@ -10,8 +10,6 @@ namespace Barotrauma
{ {
class Explosion class Explosion
{ {
private Vector2 position;
private Attack attack; private Attack attack;
private float force; private float force;
@@ -32,58 +30,52 @@ namespace Barotrauma
shockwave = ToolBox.GetAttributeBool(element, "shockwave", true); shockwave = ToolBox.GetAttributeBool(element, "shockwave", true);
flames = ToolBox.GetAttributeBool(element, "flames", 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); Hull hull = Hull.FindHull(worldPosition);
}
public void Explode(Vector2 simPosition)
{
Vector2 displayPosition = ConvertUnits.ToDisplayUnits(simPosition);
Hull hull = Hull.FindHull(displayPosition);
if (shockwave) if (shockwave)
{ {
GameMain.ParticleManager.CreateParticle("shockwave", displayPosition, GameMain.ParticleManager.CreateParticle("shockwave", worldPosition,
Vector2.Zero, 0.0f, hull); 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) if (sparks)
{ {
GameMain.ParticleManager.CreateParticle("spark", displayPosition, GameMain.ParticleManager.CreateParticle("spark", worldPosition,
Rand.Vector(Rand.Range(500.0f, 800.0f)), 0.0f, hull); Rand.Vector(Rand.Range(500.0f, 800.0f)), 0.0f, hull);
} }
if (flames) 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); 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()); CoroutineManager.StartCoroutine(DimLight());
float cameraDist = Vector2.Distance(GameMain.GameScreen.Cam.Position, displayPosition)/2.0f; float cameraDist = Vector2.Distance(GameMain.GameScreen.Cam.Position, worldPosition)/2.0f;
GameMain.GameScreen.Cam.Shake = CameraShake * Math.Max((displayRange - cameraDist)/displayRange, 0.0f); GameMain.GameScreen.Cam.Shake = CameraShake * Math.Max((displayRange - cameraDist) / displayRange, 0.0f);
if (attack.GetStructureDamage(1.0f) > 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; if (force == 0.0f && attack.Stun == 0.0f && attack.GetDamage(1.0f) == 0.0f) return;
foreach (Character c in Character.CharacterList) 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; if (dist > attack.Range) continue;
@@ -91,14 +83,14 @@ namespace Barotrauma
foreach (Limb limb in c.AnimController.Limbs) foreach (Limb limb in c.AnimController.Limbs)
{ {
if (limb.SimPosition == simPosition) continue; if (limb.WorldPosition == worldPosition) continue;
distFactor = 1.0f - Vector2.Distance(limb.SimPosition, simPosition)/attack.Range; distFactor = 1.0f - Vector2.Distance(limb.WorldPosition, worldPosition)/attack.Range;
c.AddDamage(limb.SimPosition, DamageType.None, c.AddDamage(limb.SimPosition, DamageType.None,
attack.GetDamage(1.0f) / c.AnimController.Limbs.Length * distFactor, 0.0f, attack.Stun * distFactor, false); 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; 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>(); List<Structure> structureList = new List<Structure>();
@@ -137,7 +129,7 @@ namespace Barotrauma
if (structure.HasBody && if (structure.HasBody &&
!structure.IsPlatform && !structure.IsPlatform &&
Vector2.Distance(structure.Position, displayPosition) < dist * 3.0f) Vector2.Distance(structure.WorldPosition, worldPosition) < dist * 3.0f)
{ {
structureList.Add(structure); structureList.Add(structure);
} }
@@ -147,7 +139,7 @@ namespace Barotrauma
{ {
for (int i = 0; i < structure.SectionCount; i++) 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); if (distFactor > 0.0f) structure.AddDamage(i, damage * distFactor);
} }
} }
+4 -4
View File
@@ -39,9 +39,9 @@ namespace Barotrauma
get { return size; } 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 (hull == null || (!networkEvent && GameMain.Client!=null)) return;
if (fireSoundBasic==null) if (fireSoundBasic==null)
@@ -50,11 +50,11 @@ namespace Barotrauma
fireSoundLarge = Sound.Load("Content/Sounds/firelarge.ogg"); 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); 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; //this.position.Y = hull.Rect.Y - hull.Rect.Height;
+10 -7
View File
@@ -270,8 +270,11 @@ namespace Barotrauma
float maxDelta = Math.Max(Math.Abs(rightDelta[i]), Math.Abs(leftDelta[i])); float maxDelta = Math.Max(Math.Abs(rightDelta[i]), Math.Abs(leftDelta[i]));
if (maxDelta > Rand.Range(1.0f,10.0f)) 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", GameMain.ParticleManager.CreateParticle("mist",
new Vector2(rect.X + WaveWidth * i,surface + waveY[i]), particlePos,
new Vector2(0.0f, -50.0f), 0.0f, this); 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) //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 (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; return null;
+5
View File
@@ -9,6 +9,11 @@ namespace Barotrauma
get; get;
} }
Vector2 WorldPosition
{
get;
}
float Health float Health
{ {
get; get;
@@ -35,18 +35,18 @@ namespace Barotrauma
public void Draw(SpriteBatch spriteBatch) 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; //pos.Y = -pos.Y - level.Position.Y;
if (GameMain.GameScreen.Cam.WorldView.Y < -pos.Y - 512) return; 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; //pos.X += Position.X % 512;
int width = (int)(Math.Ceiling(GameMain.GameScreen.Cam.WorldView.Width / 512.0f + 2.0f) * 512.0f); int width = (int)(Math.Ceiling(GameMain.GameScreen.Cam.WorldView.Width / 512.0f + 2.0f) * 512.0f);
spriteBatch.Draw(shaftTexture, 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), new Rectangle(0, 0, width, 256),
Color.White, 0.0f, Color.White, 0.0f,
Vector2.Zero, Vector2.Zero,
+15 -17
View File
@@ -30,7 +30,6 @@ namespace Barotrauma.Lights
private Dictionary<LightSource, CachedShadow> cachedShadows; private Dictionary<LightSource, CachedShadow> cachedShadows;
private Vector2[] worldVertices;
private Vector2[] vertices; private Vector2[] vertices;
private int primitiveCount; private int primitiveCount;
@@ -75,7 +74,6 @@ namespace Barotrauma.Lights
cachedShadows = new Dictionary<LightSource, CachedShadow>(); cachedShadows = new Dictionary<LightSource, CachedShadow>();
vertices = points; vertices = points;
worldVertices = new Vector2[vertices.Length];
primitiveCount = vertices.Length; primitiveCount = vertices.Length;
CalculateDimensions(); CalculateDimensions();
@@ -115,7 +113,6 @@ namespace Barotrauma.Lights
for (int i = 0; i < vertices.Count(); i++) for (int i = 0; i < vertices.Count(); i++)
{ {
vertices[i] += amount; vertices[i] += amount;
worldVertices[i] += amount;
} }
CalculateDimensions(); CalculateDimensions();
@@ -125,26 +122,17 @@ namespace Barotrauma.Lights
{ {
cachedShadows.Clear(); cachedShadows.Clear();
worldVertices = points;
vertices = points; vertices = points;
} }
private void CalculateShadowVertices(Vector2 lightSourcePos, bool los = true) 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 //compute facing of each edge, using N*L
for (int i = 0; i < primitiveCount; i++) 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; 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 middle = (firstVertex + secondVertex) / 2;
Vector2 L = lightSourcePos - middle; Vector2 L = lightSourcePos - middle;
@@ -187,7 +175,7 @@ namespace Barotrauma.Lights
int svCount = 0; int svCount = 0;
while (svCount != shadowVertexCount * 2) 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 //one vertex on the hull
shadowVertices[svCount] = new VertexPositionColor(); shadowVertices[svCount] = new VertexPositionColor();
@@ -217,7 +205,7 @@ namespace Barotrauma.Lights
for (int n = 0; n < 4; n += 3) 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] = new VertexPositionTexture();
penumbraVertices[n].Position = penumbraStart; penumbraVertices[n].Position = penumbraStart;
@@ -293,6 +281,8 @@ namespace Barotrauma.Lights
{ {
if (!Enabled) return; if (!Enabled) return;
if (parentEntity != null && parentEntity.Submarine != null) lightSourcePos -= parentEntity.Submarine.Position;
CalculateShadowVertices(lightSourcePos, los); CalculateShadowVertices(lightSourcePos, los);
DrawShadows(graphicsDevice, cam, transform, 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) 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(); shadowEffect.CurrentTechnique.Passes[0].Apply();
graphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleStrip, shadowVertices, 0, shadowVertices.Length - 2); graphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleStrip, shadowVertices, 0, shadowVertices.Length - 2);
+1 -1
View File
@@ -128,7 +128,7 @@ namespace Barotrauma.Lights
//draw the light shape //draw the light shape
//where Alpha is 0, nothing will be written //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); light.Draw(spriteBatch);
spriteBatch.End(); spriteBatch.End();
} }
+13 -4
View File
@@ -72,6 +72,11 @@ namespace Barotrauma
set { rect = value; } 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 public virtual Sprite Sprite
{ {
get { return null; } get { return null; }
@@ -505,12 +510,16 @@ namespace Barotrauma
foreach (MapEntity e in mapEntityList) foreach (MapEntity e in mapEntityList)
{ {
e.OnMapLoaded(); 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);
});
} }
+15 -8
View File
@@ -292,16 +292,16 @@ namespace Barotrauma
Color color = (isHighlighted) ? Color.Green : Color.White; Color color = (isHighlighted) ? Color.Green : Color.White;
if (isSelected && editing) color = Color.Red; 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)); 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);
prefab.sprite.DrawTiled(spriteBatch, drawPos, new Vector2(rect.Width, rect.Height), Vector2.Zero, color);
foreach (WallSection s in sections) foreach (WallSection s in sections)
{ {
if (s.isHighLighted) if (s.isHighLighted)
{ {
GUI.DrawRectangle(spriteBatch, 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); 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; if (s.damage < 0.01f) continue;
GUI.DrawRectangle(spriteBatch, 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); Color.Black * (s.damage / prefab.MaxHealth), true);
} }
@@ -413,13 +413,17 @@ namespace Barotrauma
return sections[sectionIndex].damage; 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; 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.X + sections[sectionIndex].rect.Width / 2.0f,
sections[sectionIndex].rect.Y - sections[sectionIndex].rect.Height / 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) 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 (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); 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); if (i == -1) return new AttackResult(0.0f, 0.0f);
GameMain.ParticleManager.CreateParticle("dustcloud", SectionPosition(i), 0.0f, 0.0f); GameMain.ParticleManager.CreateParticle("dustcloud", SectionPosition(i), 0.0f, 0.0f);
+21 -14
View File
@@ -25,6 +25,10 @@ namespace Barotrauma
{ {
public static string SavePath = "Data" + System.IO.Path.DirectorySeparatorChar + "SavedSubs"; 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 List<Submarine> SavedSubmarines = new List<Submarine>();
public static readonly Vector2 GridSize = new Vector2(16.0f, 16.0f); public static readonly Vector2 GridSize = new Vector2(16.0f, 16.0f);
@@ -97,7 +101,7 @@ namespace Barotrauma
public override Vector2 Position public override Vector2 Position
{ {
get { return subBody.Position; } get { return subBody.Position - HiddenSubPosition; }
} }
public new Vector2 DrawPosition public new Vector2 DrawPosition
@@ -106,13 +110,13 @@ namespace Barotrauma
private set; private set;
} }
public Vector2 Speed public Vector2 Velocity
{ {
get { return subBody==null ? Vector2.Zero : subBody.Speed; } get { return subBody==null ? Vector2.Zero : subBody.Velocity; }
set set
{ {
if (subBody == null) return; if (subBody == null) return;
subBody.Speed = value; subBody.Velocity = value;
} }
} }
@@ -185,10 +189,6 @@ namespace Barotrauma
MapEntity.mapEntityList[i].Draw(spriteBatch, editing); 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; if (loaded == null) return;
@@ -214,6 +214,11 @@ namespace Barotrauma
} }
} }
public void UpdateTransform()
{
DrawPosition = Physics.Interpolate(prevPosition, Position);
}
//math/physics stuff ---------------------------------------------------- //math/physics stuff ----------------------------------------------------
public static Vector2 MouseToWorldGrid(Camera cam) public static Vector2 MouseToWorldGrid(Camera cam)
@@ -414,8 +419,8 @@ namespace Barotrauma
message.Write(Position.X); message.Write(Position.X);
message.Write(Position.Y); message.Write(Position.Y);
message.Write(Speed.X); message.Write(Velocity.X);
message.Write(Speed.Y); message.Write(Velocity.Y);
return true; return true;
} }
@@ -446,7 +451,7 @@ namespace Barotrauma
//newTargetPosition = newTargetPosition + newSpeed * (float)(NetTime.Now - sendingTime); //newTargetPosition = newTargetPosition + newSpeed * (float)(NetTime.Now - sendingTime);
subBody.TargetPosition = newTargetPosition; subBody.TargetPosition = newTargetPosition;
subBody.Speed = newSpeed; subBody.Velocity = newSpeed;
lastNetworkUpdate = sendingTime; lastNetworkUpdate = sendingTime;
} }
@@ -611,6 +616,8 @@ namespace Barotrauma
XDocument doc = OpenDoc(filePath); XDocument doc = OpenDoc(filePath);
if (doc == null) return; if (doc == null) return;
subBody = new SubmarineBody(this);
foreach (XElement element in doc.Root.Elements()) foreach (XElement element in doc.Root.Elements())
{ {
string typeName = element.Name.ToString(); string typeName = element.Name.ToString();
@@ -643,7 +650,7 @@ namespace Barotrauma
} }
subBody = new SubmarineBody(this); subBody.SetPosition(HiddenSubPosition);
loaded = this; loaded = this;
@@ -694,10 +701,10 @@ namespace Barotrauma
{ {
if (GameMain.GameScreen.Cam != null) GameMain.GameScreen.Cam.TargetPos = Vector2.Zero; if (GameMain.GameScreen.Cam != null) GameMain.GameScreen.Cam.TargetPos = Vector2.Zero;
subBody = null;
Entity.RemoveAll(); Entity.RemoveAll();
subBody = null;
PhysicsBody.list.Clear(); PhysicsBody.list.Clear();
Ragdoll.list.Clear(); Ragdoll.list.Clear();
+117 -159
View File
@@ -35,14 +35,12 @@ namespace Barotrauma
private Body body; private Body body;
private Vector2 speed;
private Vector2 targetPosition; private Vector2 targetPosition;
float mass = 10000.0f; float mass = 10000.0f;
private Vector2? lastContactPoint; //private Vector2? lastContactPoint;
private VoronoiCell lastContactCell; //private VoronoiCell lastContactCell;
public Rectangle Borders public Rectangle Borders
{ {
@@ -50,13 +48,13 @@ namespace Barotrauma
private set; private set;
} }
public Vector2 Speed public Vector2 Velocity
{ {
get { return speed; } get { return body.LinearVelocity; }
set set
{ {
if (!MathUtils.IsValid(value)) return; 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 = BodyFactory.CreateCompoundPolygon(GameMain.World, triangulatedVertices, 5.0f);
body.BodyType = BodyType.Dynamic; body.BodyType = BodyType.Dynamic;
body.CollisionCategories = Physics.CollisionMisc; body.CollisionCategories = Physics.CollisionMisc | Physics.CollisionWall;
body.CollidesWith = Physics.CollisionLevel | Physics.CollisionCharacter; body.CollidesWith = Physics.CollisionLevel | Physics.CollisionCharacter;
body.Restitution = 0.0f; body.Restitution = Restitution;
body.Friction = Friction;
body.FixedRotation = true; body.FixedRotation = true;
body.Mass = mass;
body.Awake = true; body.Awake = true;
body.SleepingAllowed = false; body.SleepingAllowed = false;
body.IgnoreGravity = true; body.IgnoreGravity = true;
body.OnCollision += OnCollision; body.OnCollision += OnCollision;
body.OnSeparation += OnSeparation;
body.UserData = this; body.UserData = this;
} }
@@ -224,14 +223,14 @@ namespace Barotrauma
Vector2 totalForce = CalculateBuoyancy(); Vector2 totalForce = CalculateBuoyancy();
if (speed.LengthSquared() > 0.000001f) if (body.LinearVelocity.LengthSquared() > 0.000001f)
{ {
float dragCoefficient = 0.00001f; 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; float drag = speedLength * speedLength * dragCoefficient * mass;
totalForce += -Vector2.Normalize(speed) * drag; totalForce += -Vector2.Normalize(body.LinearVelocity) * drag;
} }
ApplyForce(totalForce); ApplyForce(totalForce);
@@ -267,7 +266,7 @@ namespace Barotrauma
public void ApplyForce(Vector2 force) public void ApplyForce(Vector2 force)
{ {
body.ApplyForce(force/100.0f); body.ApplyForce(force);
} }
public void SetPosition(Vector2 position) public void SetPosition(Vector2 position)
@@ -317,31 +316,121 @@ namespace Barotrauma
depthDamageTimer = 10.0f; 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; VoronoiCell cell = f2.Body.UserData as VoronoiCell;
Vector2 normal = Vector2.Normalize(body.Position); if (cell == null)
Vector2 simSpeed = ConvertUnits.ToSimUnits(speed); {
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);
float impact = Vector2.Dot(simSpeed, -normal); if (Submarine.PickBody(points[0] - ConvertUnits.ToSimUnits(submarine.Position) + normal2, points[0] - ConvertUnits.ToSimUnits(submarine.Position) - normal2, null, Physics.CollisionWall) != null)
{
if (impact < 0.0f) return; return true;
}
Vector2 u = Vector2.Dot(simSpeed, -normal) * normal; var ragdoll = limb.character.AnimController;
Vector2 w = (simSpeed + u); ragdoll.FindHull();
speed = ConvertUnits.ToDisplayUnits(w * (1.0f - Friction) + u * Restitution); return false;
if (lastContactPoint == null || lastContactCell==null || impact < 3.0f) return; }
SoundPlayer.PlayDamageSound(DamageSoundType.StructureBlunt, impact * 10.0f, ConvertUnits.ToDisplayUnits((Vector2)lastContactPoint)); 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; GameMain.GameScreen.Cam.Shake = impact * 2.0f;
Vector2 limbForce = -normal * impact*0.5f; Vector2 limbForce = -normal * impact * 0.5f;
float length = limbForce.Length(); float length = limbForce.Length();
if (length > 10.0f) limbForce = (limbForce / length) * 10.0f; 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); Explosion.RangedStructureDamage(ConvertUnits.ToDisplayUnits(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];
return true; 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;
}
} }
} }
+1 -1
View File
@@ -403,7 +403,7 @@ namespace Barotrauma
public override void OnMapLoaded() public override void OnMapLoaded()
{ {
currentHull = Hull.FindHull(this.Position); currentHull = Hull.FindHull(WorldPosition);
} }
public override XElement Save(XDocument doc) public override XElement Save(XDocument doc)
+17 -18
View File
@@ -74,7 +74,7 @@ namespace Barotrauma.Particles
spriteIndex = Rand.Int(prefab.Sprites.Count); spriteIndex = Rand.Int(prefab.Sprites.Count);
currentHull = Hull.FindHull(position, hullGuess); 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; this.position = position;
prevPosition = position; prevPosition = position;
@@ -165,7 +165,7 @@ namespace Barotrauma.Particles
{ {
Vector2 edgePos = position + prefab.CollisionRadius * Vector2.Normalize(velocity) * size.X; 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; if (prefab.DeleteOnCollision) return false;
@@ -174,13 +174,13 @@ namespace Barotrauma.Particles
{ {
if (!gap.isHorizontal) if (!gap.isHorizontal)
{ {
if (gap.Rect.X > position.X || gap.Rect.Right < position.X) continue; if (gap.WorldRect.X > position.X || gap.WorldRect.Right < position.X) continue;
if (Math.Sign(velocity.Y) != Math.Sign(gap.Rect.Y - (currentHull.Rect.Y-currentHull.Rect.Height))) continue; if (Math.Sign(velocity.Y) != Math.Sign(gap.WorldRect.Y - (currentHull.WorldRect.Y - currentHull.WorldRect.Height))) continue;
} }
else else
{ {
if (gap.Rect.Y < position.Y || gap.Rect.Y - gap.Rect.Height > position.Y) continue; if (gap.WorldRect.Y < position.Y || gap.WorldRect.Y - gap.WorldRect.Height > position.Y) continue;
if (Math.Sign(velocity.X) != Math.Sign(gap.Rect.Center.X - currentHull.Rect.Center.X)) 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); //Rectangle enlargedRect = new Rectangle(gap.Rect.X - 10, gap.Rect.Y + 10, gap.Rect.Width + 20, gap.Rect.Height + 20);
@@ -225,26 +225,28 @@ namespace Barotrauma.Particles
private void OnWallCollision(Hull prevHull, Vector2 position) 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; 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.X = Math.Abs(velocity.Y) * Math.Sign(velocity.X);
velocity.Y = -velocity.Y*0.1f; 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; 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; velocity.X = -velocity.X;
} }
@@ -265,11 +267,8 @@ namespace Barotrauma.Particles
drawSize *= ((totalLifeTime - lifeTime) / prefab.GrowTime); 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, prefab.Sprites[spriteIndex].Draw(spriteBatch,
screenSpacePos, new Vector2(drawPosition.X, -drawPosition.Y),
color * alpha, color * alpha,
prefab.Sprites[spriteIndex].origin, drawRotation, prefab.Sprites[spriteIndex].origin, drawRotation,
drawSize, SpriteEffects.None, prefab.Sprites[spriteIndex].Depth); drawSize, SpriteEffects.None, prefab.Sprites[spriteIndex].Depth);
+4 -1
View File
@@ -166,11 +166,14 @@ namespace Barotrauma
public void DrawMap(GraphicsDevice graphics, SpriteBatch spriteBatch) 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.ObstructVision = Character.Controlled != null && Character.Controlled.ObstructVision;
GameMain.LightManager.UpdateLightMap(graphics, spriteBatch, cam); GameMain.LightManager.UpdateLightMap(graphics, spriteBatch, cam);
GameMain.LightManager.UpdateObstructVision(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 //1. draw the background, characters and the parts of the submarine that are behind them
+1 -1
View File
@@ -201,7 +201,7 @@ namespace Barotrauma
float movementFactor = 0.0f; float movementFactor = 0.0f;
if (Submarine.Loaded != null) 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); movementFactor = MathHelper.Clamp(movementFactor, 0.0f, 1.0f);
} }
Binary file not shown.