Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No longer deconstructs walls when this would cause depressurisation #701

Merged
merged 1 commit into from
Aug 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions Assets/Scripts/Controllers/BuildModeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,33 @@ public void DoBuild(Tile t)
// TODO
if (t.Furniture != null)
{
// check if this is a WALL neighbouring a pressured and pressureless environ & if so bail
if (t.Furniture.HasTypeTag("Wall"))
{
Tile[] neighbors = t.GetNeighbours(); // diagOkay??
int pressuredNeighbors = 0;
int vacuumNeighbors = 0;
foreach (Tile neighbor in neighbors)
{
if (neighbor != null && neighbor.Room != null)
{
if ((neighbor.Room == World.current.GetOutsideRoom()) || MathUtilities.IsZero(neighbor.Room.GetTotalGasPressure()))
{
vacuumNeighbors++;
}
else
{
pressuredNeighbors++;
}
}
}

if (vacuumNeighbors > 0 && pressuredNeighbors > 0)
{
Debug.Log("Someone tried to deconstruct a wall between a pressurised room and vacuum!");
return;
}
}
t.Furniture.Deconstruct();
}
else if (t.PendingBuildJob != null)
Expand Down
12 changes: 12 additions & 0 deletions Assets/Scripts/Models/Room.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,18 @@ public float GetGasPercentage(string name)
return atmosphericGasses[name] / t;
}

public float GetTotalGasPressure()
{
float t = 0;

foreach (string n in atmosphericGasses.Keys)
{
t += atmosphericGasses[n];
}

return t;
}

public string[] GetGasNames()
{
return atmosphericGasses.Keys.ToArray();
Expand Down