more accurate submarine body generation, multiplayer fixes, saving takes HiddenSubPosition into account, fire coordinate fixes, editscreen fixes, checking item triggers in AIObjectiveGoto, netlobbyscreen sync fixes, re-enabled level start/end positions, water edit fixed

This commit is contained in:
Regalis
2015-12-17 18:26:40 +02:00
parent 859be53d28
commit af470eab2e
53 changed files with 1065 additions and 427 deletions

View File

@@ -15,7 +15,7 @@ namespace Barotrauma
{
class SubmarineBody
{
public const float DamageDepth = -10000.0f;
public const float DamageDepth = -30000.0f;
const float PressureDamageMultiplier = 0.001f;
//structure damage = impact * damageMultiplier
@@ -115,7 +115,27 @@ namespace Barotrauma
foreach (Hull hull in Hull.hullList)
{
FixtureFactory.AttachRectangle(ConvertUnits.ToSimUnits(hull.Rect.Width), ConvertUnits.ToSimUnits(hull.Rect.Height), 5.0f, hull.SimPosition, body, this);
Rectangle rect = hull.Rect;
foreach (Structure wall in Structure.WallList)
{
if (!Submarine.RectsOverlap(wall.Rect, hull.Rect)) continue;
Rectangle wallRect = wall.IsHorizontal ?
new Rectangle(hull.Rect.X, wall.Rect.Y, hull.Rect.Width, wall.Rect.Height) :
new Rectangle(wall.Rect.X, hull.Rect.Y, wall.Rect.Width, hull.Rect.Height);
rect = Rectangle.Union(
new Rectangle(wallRect.X, wallRect.Y-wallRect.Height, wallRect.Width, wallRect.Height),
new Rectangle(rect.X, rect.Y - rect.Height, rect.Width, rect.Height));
rect.Y = rect.Y + rect.Height;
}
FixtureFactory.AttachRectangle(
ConvertUnits.ToSimUnits(rect.Width),
ConvertUnits.ToSimUnits(rect.Height),
5.0f,
ConvertUnits.ToSimUnits(new Vector2(rect.X + rect.Width/2, rect.Y - rect.Height/2)),
body, this);
}
body.BodyType = BodyType.Dynamic;
@@ -189,36 +209,26 @@ namespace Barotrauma
}
public void Update(float deltaTime)
{
if (Position!=Vector2.Zero)
{
if (targetPosition != Vector2.Zero && targetPosition != Position)
{
//!!!!!!!!!!!!!!!!
//UpdateColliding();
float dist = Vector2.Distance(targetPosition, Position);
if (dist > 1000.0f)
{
body.SetTransform(ConvertUnits.ToSimUnits(targetPosition), 0.0f);
targetPosition = Vector2.Zero;
}
else if (dist > 50.0f)
{
body.SetTransform((ConvertUnits.ToSimUnits(targetPosition) - body.Position) * 0.01f, 0.0f);
}
}
else
{
targetPosition = Vector2.Zero;
}
//Vector2 translateAmount = speed * deltaTime;
//translateAmount += ConvertUnits.ToDisplayUnits(Position) * collisionRigidness;
//if (targetPosition != Vector2.Zero && targetPosition != Position)
//{
// float dist = Vector2.Distance(targetPosition, Position);
// if (dist>1000.0f)
// {
// sub.SetPosition(targetPosition);
// targetPosition = Vector2.Zero;
// }
// else if (dist>50.0f)
// {
// translateAmount += (targetPosition - Position) * 0.01f;
// }
//}
//else
//{
// targetPosition = Vector2.Zero;
//}
//sub.Translate(translateAmount);
//-------------------------
@@ -236,13 +246,8 @@ namespace Barotrauma
ApplyForce(totalForce);
//UpdateDepthDamage(deltaTime);
UpdateDepthDamage(deltaTime);
//hullBodies[0].body.LinearVelocity = -hullBodies[0].body.Position;
//hullBody.SetTransform(Vector2.Zero , 0.0f);
//body.SetTransform(Vector2.Zero, 0.0f);// .LinearVelocity = -body.Position / (float)Physics.step;
//body.LinearVelocity = Vector2.Zero;
}
private Vector2 CalculateBuoyancy()
@@ -311,80 +316,15 @@ namespace Barotrauma
GameMain.GameScreen.Cam.Shake = depth * PressureDamageMultiplier * 0.1f;
damagePos += submarine.Position + Submarine.HiddenSubPosition;
Explosion.RangedStructureDamage(damagePos, depth * PressureDamageMultiplier * 50.0f, depth * PressureDamageMultiplier);
//SoundPlayer.PlayDamageSound(DamageSoundType.StructureBlunt, Rand.Range(0.0f, 100.0f), damagePos, 5000.0f);
depthDamageTimer = 10.0f;
}
//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)
{
VoronoiCell cell = f2.Body.UserData as VoronoiCell;
if (cell == null)
@@ -396,7 +336,9 @@ namespace Barotrauma
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)
if (Submarine.PickBody(
points[0] - limb.LinearVelocity * ((float)Physics.step) - ConvertUnits.ToSimUnits(submarine.Position) - submarine.Velocity * ((float)Physics.step) + normal2,
points[0] - ConvertUnits.ToSimUnits(submarine.Position) - normal2, null, Physics.CollisionWall) != null)
{
return true;
@@ -441,7 +383,7 @@ namespace Barotrauma
{
if (c.AnimController.CurrentHull == null) continue;
if (impact > 2.0f) c.AnimController.StunTimer = (impact - 2.0f) * 0.1f;
if (impact > 2.0f) c.StartStun((impact - 2.0f) * 0.1f);
foreach (Limb limb in c.AnimController.Limbs)
{