Submarine saving fixes, impact damage in sub-sub collisions, submarine ambient sounds
This commit is contained in:
@@ -1438,6 +1438,8 @@ namespace Barotrauma
|
||||
|
||||
element.Add(new XAttribute("name", prefab.Name),
|
||||
new XAttribute("ID", ID));
|
||||
|
||||
System.Diagnostics.Debug.Assert(Submarine != null);
|
||||
|
||||
if (ResizeHorizontal || ResizeVertical)
|
||||
{
|
||||
|
||||
@@ -13,20 +13,20 @@ namespace Barotrauma
|
||||
spawnQueue = new Queue<Pair<ItemPrefab, object>>();
|
||||
}
|
||||
|
||||
public void QueueItem(ItemPrefab itemPrefab, Vector2 position, bool isNetworkMessage = false)
|
||||
{
|
||||
if (!isNetworkMessage && GameMain.Client!=null)
|
||||
{
|
||||
//clients aren't allowed to spawn new items unless the server says so
|
||||
return;
|
||||
}
|
||||
//public void QueueItem(ItemPrefab itemPrefab, Vector2 position, bool isNetworkMessage = false)
|
||||
//{
|
||||
// if (!isNetworkMessage && GameMain.Client!=null)
|
||||
// {
|
||||
// //clients aren't allowed to spawn new items unless the server says so
|
||||
// return;
|
||||
// }
|
||||
|
||||
var itemInfo = new Pair<ItemPrefab, object>();
|
||||
itemInfo.First = itemPrefab;
|
||||
itemInfo.Second = position;
|
||||
// var itemInfo = new Pair<ItemPrefab, object>();
|
||||
// itemInfo.First = itemPrefab;
|
||||
// itemInfo.Second = position;
|
||||
|
||||
spawnQueue.Enqueue(itemInfo);
|
||||
}
|
||||
// spawnQueue.Enqueue(itemInfo);
|
||||
//}
|
||||
|
||||
public void QueueItem(ItemPrefab itemPrefab, Inventory inventory, bool isNetworkMessage = false)
|
||||
{
|
||||
@@ -54,16 +54,17 @@ namespace Barotrauma
|
||||
{
|
||||
var itemInfo = spawnQueue.Dequeue();
|
||||
|
||||
if (itemInfo.Second is Vector2)
|
||||
{
|
||||
//todo: take multiple subs into account
|
||||
Vector2 position = (Vector2)itemInfo.Second - Submarine.MainSub.HiddenSubPosition;
|
||||
//if (itemInfo.Second is Vector2)
|
||||
//{
|
||||
// //todo: take multiple subs into account
|
||||
// Vector2 position = (Vector2)itemInfo.Second - Submarine.MainSub.HiddenSubPosition;
|
||||
|
||||
items.Add(new Item(itemInfo.First, position, null));
|
||||
inventories.Add(null);
|
||||
// items.Add(new Item(itemInfo.First, position, null));
|
||||
// inventories.Add(null);
|
||||
|
||||
}
|
||||
else if (itemInfo.Second is Inventory)
|
||||
//}
|
||||
//else
|
||||
if (itemInfo.Second is Inventory)
|
||||
{
|
||||
var item = new Item(itemInfo.First, Vector2.Zero, null);
|
||||
|
||||
|
||||
@@ -526,7 +526,7 @@ namespace Barotrauma
|
||||
|
||||
foreach (MapEntity e in MapEntity.mapEntityList)
|
||||
{
|
||||
if (e.MoveWithLevel) continue;
|
||||
if (e.MoveWithLevel ||e.Submarine != this) continue;
|
||||
e.Save(doc);
|
||||
}
|
||||
|
||||
@@ -548,17 +548,15 @@ namespace Barotrauma
|
||||
|
||||
public static bool SaveCurrent(string filePath)
|
||||
{
|
||||
if (!loaded.Any())
|
||||
if (Submarine.MainSub == null)
|
||||
{
|
||||
loaded.Add(new Submarine(filePath));
|
||||
Submarine.MainSub = new Submarine(filePath);
|
||||
// return;
|
||||
}
|
||||
|
||||
System.Diagnostics.Debug.Assert(loaded.Count==1);
|
||||
Submarine.MainSub.filePath = filePath;
|
||||
|
||||
loaded.First().filePath = filePath;
|
||||
|
||||
return loaded.First().SaveAs(filePath);
|
||||
return Submarine.MainSub.SaveAs(filePath);
|
||||
}
|
||||
|
||||
public void CheckForErrors()
|
||||
|
||||
@@ -415,12 +415,9 @@ namespace Barotrauma
|
||||
|
||||
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 limb = f2.Body.UserData as Limb;
|
||||
if (limb == null) return true;
|
||||
|
||||
bool collision = HandleLimbCollision(contact, limb);
|
||||
|
||||
@@ -436,12 +433,32 @@ namespace Barotrauma
|
||||
return collision;
|
||||
}
|
||||
|
||||
var collisionNormal = Vector2.Normalize(ConvertUnits.ToDisplayUnits(body.Position) - cell.Center);
|
||||
VoronoiCell cell = f2.Body.UserData as VoronoiCell;
|
||||
if (cell != null)
|
||||
{
|
||||
var collisionNormal = Vector2.Normalize(ConvertUnits.ToDisplayUnits(body.Position) - cell.Center);
|
||||
|
||||
float wallImpact = Vector2.Dot(Velocity, -collisionNormal);
|
||||
float wallImpact = Vector2.Dot(Velocity, -collisionNormal);
|
||||
|
||||
ApplyImpact(wallImpact, -collisionNormal, contact);
|
||||
ApplyImpact(wallImpact, -collisionNormal, contact);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Submarine sub = f2.Body.UserData as Submarine;
|
||||
if (sub != null)
|
||||
{
|
||||
Debug.Assert(sub != submarine);
|
||||
|
||||
Vector2 normal;
|
||||
FixedArray2<Vector2> points;
|
||||
contact.GetWorldManifold(out normal, out points);
|
||||
|
||||
ApplyImpact(Vector2.Dot(Velocity - sub.Velocity, normal) / 2.0f, normal, contact);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -364,9 +364,9 @@ namespace Barotrauma.Networking
|
||||
if (!(c is AICharacter) || c.IsDead) continue;
|
||||
|
||||
//todo: take multiple subs into account
|
||||
Vector2 diff = c.WorldPosition - Submarine.MainSub.WorldPosition;
|
||||
//Vector2 diff = c.WorldPosition - Submarine.MainSub.WorldPosition;
|
||||
|
||||
if (FarseerPhysics.ConvertUnits.ToSimUnits(diff.Length()) > NetConfig.CharacterIgnoreDistance) continue;
|
||||
//if (FarseerPhysics.ConvertUnits.ToSimUnits(diff.Length()) > NetConfig.CharacterIgnoreDistance) continue;
|
||||
|
||||
new NetworkEvent(NetworkEventType.EntityUpdate, c.ID, false);
|
||||
}
|
||||
@@ -405,9 +405,9 @@ namespace Barotrauma.Networking
|
||||
if (c is AICharacter)
|
||||
{
|
||||
//todo: take multiple subs into account
|
||||
Vector2 diff = c.WorldPosition - Submarine.MainSub.WorldPosition;
|
||||
//Vector2 diff = c.WorldPosition - Submarine.MainSub.WorldPosition;
|
||||
|
||||
if (FarseerPhysics.ConvertUnits.ToSimUnits(diff.Length()) > NetConfig.CharacterIgnoreDistance) continue;
|
||||
//if (FarseerPhysics.ConvertUnits.ToSimUnits(diff.Length()) > NetConfig.CharacterIgnoreDistance) continue;
|
||||
}
|
||||
|
||||
new NetworkEvent(NetworkEventType.ImportantEntityUpdate, c.ID, false);
|
||||
|
||||
@@ -239,11 +239,11 @@ namespace Barotrauma
|
||||
}
|
||||
else
|
||||
{
|
||||
cam.Position = Submarine.MainSub.HiddenSubPosition;
|
||||
cam.Position = Vector2.Zero;
|
||||
nameBox.Text = "";
|
||||
descriptionBox.Text = "";
|
||||
|
||||
Submarine.MainSub = new Submarine("", "", false);
|
||||
Submarine.MainSub = new Submarine(Path.Combine(Submarine.SavePath, "Unnamed.sub"), "", false);
|
||||
}
|
||||
|
||||
nameBox.Deselect();
|
||||
|
||||
@@ -183,7 +183,7 @@ namespace Barotrauma
|
||||
startDrone = null;
|
||||
}
|
||||
|
||||
//todo: ambient sounds for multiple subs
|
||||
//stop submarine ambient sounds if no sub is loaded
|
||||
if (Submarine.MainSub == null)
|
||||
{
|
||||
for (int i = 0; i < waterAmbienceIndexes.Length; i++)
|
||||
@@ -213,17 +213,31 @@ namespace Barotrauma
|
||||
}
|
||||
|
||||
//how fast the sub is moving, scaled to 0.0 -> 1.0
|
||||
float movementFactor = 0.0f;
|
||||
if (Submarine.MainSub != null)
|
||||
{
|
||||
movementFactor = (Submarine.MainSub.Velocity == Vector2.Zero) ? 0.0f : Submarine.MainSub.Velocity.Length() / 5.0f;
|
||||
float movementSoundVolume = 0.0f;
|
||||
|
||||
foreach (Submarine sub in Submarine.Loaded)
|
||||
{
|
||||
float movementFactor = (sub.Velocity == Vector2.Zero) ? 0.0f : sub.Velocity.Length() / 5.0f;
|
||||
movementFactor = MathHelper.Clamp(movementFactor, 0.0f, 1.0f);
|
||||
|
||||
if (Character.Controlled==null || Character.Controlled.Submarine != sub)
|
||||
{
|
||||
float dist = Vector2.Distance(GameMain.GameScreen.Cam.WorldViewCenter, sub.WorldPosition);
|
||||
movementFactor = movementFactor / Math.Max(dist / 1000.0f, 1.0f);
|
||||
}
|
||||
|
||||
movementSoundVolume = Math.Max(movementSoundVolume, movementFactor);
|
||||
}
|
||||
|
||||
//if (Submarine.MainSub != null)
|
||||
//{
|
||||
// movementFactor = (Submarine.MainSub.Velocity == Vector2.Zero) ? 0.0f : Submarine.MainSub.Velocity.Length() / 5.0f;
|
||||
// movementFactor = MathHelper.Clamp(movementFactor, 0.0f, 1.0f);
|
||||
//}
|
||||
|
||||
SoundManager.LowPassHFGain = lowpassHFGain;
|
||||
waterAmbienceIndexes[0] = waterAmbiences[0].Loop(waterAmbienceIndexes[0], ambienceVolume * (1.0f-movementFactor));
|
||||
waterAmbienceIndexes[1] = waterAmbiences[1].Loop(waterAmbienceIndexes[1], ambienceVolume * movementFactor);
|
||||
waterAmbienceIndexes[0] = waterAmbiences[0].Loop(waterAmbienceIndexes[0], ambienceVolume * (1.0f - movementSoundVolume));
|
||||
waterAmbienceIndexes[1] = waterAmbiences[1].Loop(waterAmbienceIndexes[1], ambienceVolume * movementSoundVolume);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user