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

Adding airlocks and making normal doors leak air #166

Merged
merged 20 commits into from
Aug 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
26 changes: 25 additions & 1 deletion Assets/Scripts/Controllers/FurnitureSpriteController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void OnFurnitureCreated(Furniture furn)
furn_go.transform.SetParent(this.transform, true);

// FIXME: This hardcoding is not ideal!
if (furn.objectType == "Door")
if (furn.objectType == "Door" || furn.objectType == "Airlock")
{
// By default, the door graphic is meant for walls to the east & west
// Check to see if we actually have a wall north/south, and if so
Expand Down Expand Up @@ -152,6 +152,30 @@ public Sprite GetSpriteForFurniture(Furniture furn)
}
//Debug.Log(spriteName);
}
if (furn.objectType == "Airlock")
{
if (furn.GetParameter("openness") < 0.1f)
{
// Airlock is closed
spriteName = "Airlock";
}
else if (furn.GetParameter("openness") < 0.5f)
{
// Airlock is a bit open
spriteName = "Airlock_openness_1";
}
else if (furn.GetParameter("openness") < 0.9f)
{
// Airlock is a lot open
spriteName = "Airlock_openness_2";
}
else
{
// Airlock is a fully open
spriteName = "Airlock_openness_3";
}
//Debug.Log(spriteName);
}

/*if(furnitureSprites.ContainsKey(spriteName) == false) {
Debug.Log("furnitureSprites has no definition for: " + spriteName);
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/Models/Character.cs
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ void Update_DoMovement(float deltaTime)
// so that we don't waste a bunch of time walking towards a dead end.
// To save CPU, maybe we can only check every so often?
// Or maybe we should register a callback to the OnTileChanged event?
Debug.LogError("FIXME: A character was trying to enter an unwalkable tile.");
// Debug.LogError("FIXME: A character was trying to enter an unwalkable tile.");
NextTile = null; // our next tile is a no-go
pathAStar = null; // clearly our pathfinding info is out of date.
return;
Expand Down
33 changes: 33 additions & 0 deletions Assets/Scripts/Models/Room.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,38 @@ public void ChangeGas(string name, float amount)

}

public void EqualiseGas(Room otherRoom, float leakFactor)
{
if (otherRoom == null)
{
return;
}

List<string> gasses = this.GetGasNames().ToList();
gasses = gasses.Union(otherRoom.GetGasNames().ToList()).ToList();
foreach (string gas in gasses)
{
float pressureDifference = this.GetGasPressure(gas) - otherRoom.GetGasPressure(gas);
this.ChangeGas(gas, (-1) * pressureDifference * leakFactor);
otherRoom.ChangeGas(gas, pressureDifference * leakFactor);
}
}

public static void EqualiseGasByTile(Tile tile, float leakFactor)
{
List<Room> roomsDone = new List<Room>();
foreach (Tile t in tile.GetNeighbours())
{
if(roomsDone.Contains(t.room) == false)
{
foreach (Room r in roomsDone) {
t.room.EqualiseGas(r, leakFactor);
}
roomsDone.Add(t.room);
}
}
}

// Gets absolute gas amount in preasure(in atm) multiplyed by number of tiles
public float GetGasAmount(string name)
{
Expand Down Expand Up @@ -132,6 +164,7 @@ public string[] GetGasNames()
return atmosphericGasses.Keys.ToArray();
}


public static void DoRoomFloodFill(Tile sourceTile, bool onlyIfOutside = false)
{
// sourceFurniture is the piece of furniture that may be
Expand Down
5 changes: 5 additions & 0 deletions Assets/Scripts/Models/Tile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,11 @@ public static void ChangeTileTypeJobComplete(Job theJob)
theJob.tile.pendingBuildJob = null;
}

public void EqualiseGas(float leakFactor)
{
Room.EqualiseGasByTile(this, leakFactor);
}


// Tells us if two tiles are adjacent.
public bool IsNeighbour(Tile tile, bool diagOkay = false)
Expand Down
35 changes: 35 additions & 0 deletions Assets/StreamingAssets/Data/Furniture.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,47 @@
</DeconstructJob>

<OnUpdate FunctionName="OnUpdate_Door" />
<OnUpdate FunctionName="OnUpdate_Leak_Door" />

<IsEnterable FunctionName="IsEnterable_Door" />

<LocalizationCode>furn_door</LocalizationCode>
<UnlocalizedDescription>furn_door_desc</UnlocalizedDescription>

</Furniture>

<Furniture objectType="Airlock">
<Name>Door</Name>
<Description>An Airlock prevents air from leaving the base</Description>
<MovementCost>1</MovementCost>
<Width>1</Width>
<Height>1</Height>
<LinksToNeighbours>false</LinksToNeighbours>
<EnclosesRooms>true</EnclosesRooms>
<CanReplaceFurniture objectName="Basic Wall" />


<Params>
<Param name="openness" value="0" />
<Param name="is_opening" value="0" />
</Params>

<BuildingJob jobTime="5">
<Inventory objectType="Steel Plate" amount="10" />
</BuildingJob>

<DeconstructJob>
<Inventory objectType="Steel Plate" amount="7" />
</DeconstructJob>

<OnUpdate FunctionName="OnUpdate_Door" />
<OnUpdate FunctionName="OnUpdate_Leak_Airlock" />

<IsEnterable FunctionName="IsEnterable_Door" />

<LocalizationCode>furn_airlock</LocalizationCode>
<UnlocalizedDescription>furn_airlock_desc</UnlocalizedDescription>

</Furniture>


Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions Assets/StreamingAssets/Images/Furniture/Airlock.png.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions Assets/StreamingAssets/Images/Furniture/Airlock.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Sprites>
<Sprite name="Airlock" x="32" y="224" w="32" h="32" pixelPerUnit="32" />
<Sprite name="Airlock_openness_1" x="32" y="192" w="32" h="32" pixelPerUnit="32" />
<Sprite name="Airlock_openness_2" x="32" y="160" w="32" h="32" pixelPerUnit="32" />
<Sprite name="Airlock_openness_3" x="32" y="128" w="32" h="32" pixelPerUnit="32" />
</Sprites>
8 changes: 8 additions & 0 deletions Assets/StreamingAssets/Images/Furniture/Airlock.xml.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion Assets/StreamingAssets/LUA/Furniture.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,19 @@ function OnUpdate_Door( furniture, deltaTime )
furniture.ChangeParameter("openness", deltaTime * -4)
end


furniture.SetParameter("openness", Clamp01(furniture.GetParameter("openness")) )

furniture.UpdateOnChanged(furniture);
end

function OnUpdate_Leak_Door( furniture, deltaTime )
furniture.tile.EqualiseGas(deltaTime * 10.0 * (furniture.GetParameter("openness") + 0.1))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the 0.1 leak in normal doors be a parameter so that it'd be easy for other people creating doors to add more or less of it?

Copy link
Contributor Author

@emilkris33 emilkris33 Aug 18, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I might look at doing that tomorrow. If this PR gets merged before that I will do it as part of my next changed to the atmosphere system(Unless someone beats me to it)

end

function OnUpdate_Leak_Airlock( furniture, deltaTime )
furniture.tile.EqualiseGas(deltaTime * 10.0 * (furniture.GetParameter("openness")))
end

function IsEnterable_Door( furniture )
furniture.SetParameter("is_opening", 1)

Expand Down
4 changes: 3 additions & 1 deletion Assets/StreamingAssets/Localization/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ furn_stockpile_desc=A storage for your materials.
furn_oxygen_generator=Oxygen Generator
furn_oxygen_generator_desc=Generating oxygen for your astronauts.
furn_mining_drone_station=Mining Drone
furn_mining_drone_station_desc=Mining materials out of nothing.
furn_mining_drone_station_desc=Mining materials out of nothing.
furn_airlock=Airlock
furn_airlock_desc=An Airlock prevents air from leaving the base
4 changes: 2 additions & 2 deletions Assets/StreamingAssets/Localization/es_ES.lang.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.