v0.3.4.2: fixed section bodies not being restored after repairing a wall/window, fixed servers letting all clients in despite a wrong password, game version or content package

This commit is contained in:
Regalis
2016-03-05 12:50:22 +02:00
10 changed files with 45 additions and 26 deletions

View File

@@ -472,8 +472,10 @@ namespace Barotrauma
foreach (var gap in ConnectedGaps.Where(gap => gap.Open > 0))
{
var pos = gap.Position - body.Position;
var distance = MathHelper.Max(Vector2.DistanceSquared(body.Position, gap.Position)/1000,1f);
pos.Normalize();
body.body.ApplyForce((pos * gap.LerpedFlowForce) * deltaTime);
body.body.ApplyForce((pos * (gap.LerpedFlowForce/distance)) * deltaTime);
}
}

View File

@@ -259,13 +259,13 @@ namespace Barotrauma
if (prefab.CastShadow)
{
GeneateConvexHull();
GenerateConvexHull();
}
InsertToList();
}
private void GeneateConvexHull()
private void GenerateConvexHull()
{
// If not null and not empty , remove the hulls from the system
if(_convexHulls != null && _convexHulls.Any())
@@ -452,13 +452,16 @@ namespace Barotrauma
sections[sectionIndex].isHighLighted = true;
}
public bool SectionHasHole(int sectionIndex)
public bool SectionBodyDisabled(int sectionIndex)
{
if (sectionIndex < 0 || sectionIndex >= sections.Length) return false;
return (sections[sectionIndex].damage>=prefab.MaxHealth);
}
/// <summary>
/// Sections that are leaking have a gap placed on them
/// </summary>
public bool SectionIsLeaking(int sectionIndex)
{
if (sectionIndex < 0 || sectionIndex >= sections.Length) return false;
@@ -528,7 +531,7 @@ namespace Barotrauma
float damageAmount = attack.GetStructureDamage(deltaTime);
if (playSound && !SectionHasHole(i))
if (playSound && !SectionBodyDisabled(i))
{
DamageSoundType damageSoundType = (attack.DamageType == DamageType.Blunt) ? DamageSoundType.StructureBlunt : DamageSoundType.StructureSlash;
SoundPlayer.PlayDamageSound(damageSoundType, damageAmount, position);
@@ -561,7 +564,7 @@ namespace Barotrauma
sections[sectionIndex].gap.Remove();
sections[sectionIndex].gap = null;
if(CastShadow)
GeneateConvexHull();
GenerateConvexHull();
}
}
else
@@ -575,20 +578,20 @@ namespace Barotrauma
gapRect.Height += 20;
sections[sectionIndex].gap = new Gap(gapRect, !isHorizontal, Submarine);
if(CastShadow)
GeneateConvexHull();
GenerateConvexHull();
}
}
if (sections[sectionIndex].gap != null)
sections[sectionIndex].gap.Open = (float)Math.Pow(((damage / prefab.MaxHealth)-0.5)*2.0, 2.0);
bool hadHole = SectionHasHole(sectionIndex);
bool hadHole = SectionBodyDisabled(sectionIndex);
sections[sectionIndex].damage = MathHelper.Clamp(damage, 0.0f, prefab.MaxHealth);
bool hasHole = SectionHasHole(sectionIndex);
bool hasHole = SectionBodyDisabled(sectionIndex);
if (hadHole == hasHole) return;
if (hasHole) Explosion.ApplyExplosionForces(sections[sectionIndex].gap.WorldPosition, 500.0f, 5.0f, 0.0f, 0.0f);
//if (hasHole) Explosion.ApplyExplosionForces(sections[sectionIndex].gap.WorldPosition, 500.0f, 5.0f, 0.0f, 0.0f);
UpdateSections();
}
@@ -600,11 +603,18 @@ namespace Barotrauma
}
bodies.Clear();
var mergedSections = new List<WallSection>();
foreach (var section in sections)
for (int i = 0; i < sections.Count(); i++ )
{
if(section.gap == null)
var section = sections[i];
if (!SectionBodyDisabled(i))
{
mergedSections.Add(section);
if (section.gap == null || mergedSections.Count <= 0) continue;
continue;
}
if (mergedSections.Count <= 0) continue;
Rectangle mergedRect;
if (isHorizontal)
mergedRect = new Rectangle(mergedSections.Min(x => x.rect.Left), mergedSections.Max(x => x.rect.Top),

View File

@@ -374,7 +374,7 @@ namespace Barotrauma
{
if (structure.IsPlatform || structure.StairDirection != Direction.None) return -1;
int sectionIndex = structure.FindSectionIndex(ConvertUnits.ToDisplayUnits(point));
if (sectionIndex > -1 && structure.SectionHasHole(sectionIndex)) return -1;
if (sectionIndex > -1 && structure.SectionBodyDisabled(sectionIndex)) return -1;
}
if (fraction < closestFraction)