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

Unreachable Job Fix #1580

Merged
merged 26 commits into from
Nov 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
15e77ea
Change the name of a few things to be more clear.
Geoffrotism Oct 25, 2016
4b8cf17
Jobs now keep track of what characters can't reach them.
Geoffrotism Oct 25, 2016
7e0dad5
Deleted debugging lines.
Geoffrotism Oct 25, 2016
ba7854b
doesnt change anything BUT IT SHOULD
Geoffrotism Oct 25, 2016
ad20c21
Merge branch 'master' of https://github.com/TeamPorcupine/ProjectPorc…
Geoffrotism Oct 25, 2016
c6595d1
Resets the unreachable state for jobs when furniture is removed.
Geoffrotism Oct 25, 2016
b5e23a6
More commenting.
Geoffrotism Oct 25, 2016
adadd29
Merge branch 'master' of https://github.com/TeamPorcupine/ProjectPorc…
Geoffrotism Oct 27, 2016
8b23de0
Fixed the deletion of jobs when unreachable.
Geoffrotism Oct 27, 2016
2006541
StyleCop fixes.
Geoffrotism Oct 27, 2016
71c32a5
Commenting Corrections.
Geoffrotism Nov 1, 2016
e640dbb
Merge branch 'master' of https://github.com/TeamPorcupine/ProjectPorc…
Geoffrotism Nov 2, 2016
662429a
Merge branch 'master' of https://github.com/TeamPorcupine/ProjectPorc…
Geoffrotism Nov 2, 2016
f927c59
Refactored a name that was redundant.
Geoffrotism Nov 2, 2016
45b1843
combined two if-else statements
Geoffrotism Nov 2, 2016
e369aa2
Jobs now do not get picked up by characters if they are unable to rea…
Geoffrotism Nov 2, 2016
2b1d6e7
Jobs now get re-added to the queue when new inventory is made.
Geoffrotism Nov 2, 2016
ae12e3e
Refactored JobObjectType to Type to avoid redundancy.
Geoffrotism Nov 3, 2016
c312684
Formatting
Geoffrotism Nov 3, 2016
3b9ee68
Merge branch 'master' of https://github.com/TeamPorcupine/ProjectPorc…
Geoffrotism Nov 3, 2016
c2fe808
Bug Fixing
Geoffrotism Nov 3, 2016
7f4b838
unreachable inventory now gets properly handled.
Geoffrotism Nov 4, 2016
ebec82d
StyleCop Fixes.
Geoffrotism Nov 4, 2016
a7b06c5
Merge branch 'master' of https://github.com/TeamPorcupine/ProjectPorc…
Geoffrotism Nov 4, 2016
e6b9879
last fix
Geoffrotism Nov 4, 2016
123dc0d
Merge branch 'master' of https://github.com/TeamPorcupine/ProjectPorc…
Geoffrotism Nov 6, 2016
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
Binary file modified Assets/Plugins/Net20/Newtonsoft.Json.dll.mdb
Binary file not shown.
5 changes: 5 additions & 0 deletions Assets/Plugins/Net20/Newtonsoft.Json.dll.mdb.meta

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

21 changes: 9 additions & 12 deletions Assets/Plugins/x86_64/fmod.dll.meta

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

6 changes: 6 additions & 0 deletions Assets/Resources/Prefab.meta

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

6 changes: 3 additions & 3 deletions Assets/Scripts/Controllers/InputOutput/BuildModeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public void DoBuild(Tile tile)
Debug.ULogErrorChannel("BuildModeController", "There is no furniture job prototype for '" + furnitureType + "'");
job = new Job(tile, furnitureType, World.Current.FurnitureManager.ConstructJobCompleted, 0.1f, null, Job.JobPriority.High);
job.adjacent = true;
job.JobDescription = "job_build_" + furnitureType + "_desc";
job.Description = "job_build_" + furnitureType + "_desc";
}

Furniture furnituteToBuild = PrototypeManager.Furniture.Get(furnitureType).Clone();
Expand Down Expand Up @@ -233,15 +233,15 @@ public void DoBuild(Tile tile)
{
Debug.ULogErrorChannel("BuildModeController", "There is no furniture job prototype for '" + utilityType + "'");
job = new Job(tile, utilityType, World.Current.UtilityManager.ConstructJobCompleted, 0.1f, null, Job.JobPriority.High);
job.JobDescription = "job_build_" + utilityType + "_desc";
job.Description = "job_build_" + utilityType + "_desc";
}

job.buildablePrototype = PrototypeManager.Utility.Get(utilityType);

// Add the job to the queue or build immediately if in dev mode
if (Settings.GetSetting("DialogBoxSettings_developerModeToggle", false))
{
World.Current.UtilityManager.PlaceUtility(job.JobObjectType, job.tile);
World.Current.UtilityManager.PlaceUtility(job.Type, job.tile);
}
else
{
Expand Down
14 changes: 7 additions & 7 deletions Assets/Scripts/Controllers/Sprites/JobSpriteController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public override void RemoveAll()

protected override void OnCreated(Job job)
{
if (job.JobTileType == null && job.JobObjectType == null)
if (job.JobTileType == null && job.Type == null)
{
// This job doesn't really have an associated sprite with it, so no need to render.
return;
Expand All @@ -81,7 +81,7 @@ protected override void OnCreated(Job job)
// Add our tile/GO pair to the dictionary.
objectGameObjectMap.Add(job, job_go);

job_go.name = "JOB_" + job.JobObjectType + "_" + job.tile.X + "_" + job.tile.Y + "_" + job.tile.Z;
job_go.name = "JOB_" + job.Type + "_" + job.tile.X + "_" + job.tile.Y + "_" + job.tile.Z;
job_go.transform.SetParent(objectParent.transform, true);

SpriteRenderer sr = job_go.AddComponent<SpriteRenderer>();
Expand All @@ -94,13 +94,13 @@ protected override void OnCreated(Job job)
sr.sprite = SpriteManager.GetSprite("Tile", "Solid");
sr.color = new Color32(128, 255, 128, 192);
}
else if (job.JobDescription.Contains("deconstruct"))
else if (job.Description.Contains("deconstruct"))
{
sr.sprite = SpriteManager.GetSprite("UI", "CursorCircle");
sr.color = Color.red;
job_go.transform.position = job.tile.Vector3;
}
else if (job.JobDescription.Contains("mine"))
else if (job.Description.Contains("mine"))
{
sr.sprite = SpriteManager.GetSprite("UI", "MiningIcon");
sr.color = new Color(1, 1, 1, 0.25f);
Expand All @@ -118,13 +118,13 @@ protected override void OnCreated(Job job)
if (job.buildablePrototype.GetType().ToString() == "Furniture")
{
Furniture furnitureToBuild = (Furniture)job.buildablePrototype;
sr.sprite = fsc.GetSpriteForFurniture(job.JobObjectType);
sr.sprite = fsc.GetSpriteForFurniture(job.Type);
job_go.transform.position = job.tile.Vector3 + ImageUtils.SpritePivotOffset(sr.sprite, furnitureToBuild.Rotation);
job_go.transform.Rotate(0, 0, furnitureToBuild.Rotation);
}
else if (job.buildablePrototype.GetType().ToString() == "Utility")
{
sr.sprite = usc.GetSpriteForUtility(job.JobObjectType);
sr.sprite = usc.GetSpriteForUtility(job.Type);
job_go.transform.position = job.tile.Vector3 + ImageUtils.SpritePivotOffset(sr.sprite);
}

Expand All @@ -134,7 +134,7 @@ protected override void OnCreated(Job job)
sr.sortingLayerName = "Jobs";

// FIXME: This hardcoding is not ideal! <== Understatement
if (job.JobObjectType == "Door")
if (job.Type == "Door")
{
// 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
2 changes: 1 addition & 1 deletion Assets/Scripts/Models/Area/World.cs
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ private void TickFixedFrequency(float deltaTime)
}

/// <summary>
/// Called when a furniture is created so that we can regenerate the til graph.
/// Called when a furniture is created so that we can regenerate the tile graph.
/// </summary>
/// <param name="furniture">Furniture.</param>
private void OnFurnitureCreated(Furniture furniture)
Expand Down
4 changes: 2 additions & 2 deletions Assets/Scripts/Models/Buildable/Components/Workshop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ private void ConsumeInventories(List<KeyValuePair<Tile, int>> flaggedForTaking)
private void PlaceInventoryToWorkshopInput(Job job)
{
job.CancelJob();
foreach (Inventory heldInventory in job.HeldInventory.Values)
foreach (Inventory heldInventory in job.DeliveredItems.Values)
{
if (heldInventory.StackSize > 0)
{
Expand Down Expand Up @@ -354,7 +354,7 @@ private void HaulingJobForInputs(ProductionChain prodChain)
false,
false);

job.JobDescription = string.Format("Hauling '{0}' to '{1}'", desiredInv, ParentFurniture.Name);
job.Description = string.Format("Hauling '{0}' to '{1}'", desiredInv, ParentFurniture.Name);
job.OnJobWorked += PlaceInventoryToWorkshopInput;
ParentFurniture.Jobs.Add(job);
}
Expand Down
4 changes: 2 additions & 2 deletions Assets/Scripts/Models/Buildable/Furniture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ public void ReadXmlBuildingJob(XmlReader reader)
jobTime,
items.ToArray(),
Job.JobPriority.High);
job.JobDescription = "job_build_" + Type + "_desc";
job.Description = "job_build_" + Type + "_desc";

PrototypeManager.FurnitureConstructJob.Set(job);
}
Expand Down Expand Up @@ -838,7 +838,7 @@ public void ReadXmlDeconstructJob(XmlReader reader)
jobTime,
null,
Job.JobPriority.High);
job.JobDescription = "job_deconstruct_" + Type + "_desc";
job.Description = "job_deconstruct_" + Type + "_desc";
job.adjacent = true;

PrototypeManager.FurnitureDeconstructJob.Set(job);
Expand Down
8 changes: 6 additions & 2 deletions Assets/Scripts/Models/Buildable/FurnitureManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,11 @@ public Furniture PlaceFurniture(Furniture prototype, Tile tile, bool doRoomFlood
furnitures.Add(furniture);
furnituresVisible.Add(furniture);

// Do we need to recalculate our rooms?
// Do we need to recalculate our rooms/reachability for other jobs?
if (doRoomFloodFill && furniture.RoomEnclosure)
{
World.Current.RoomManager.DoRoomFloodFill(furniture.Tile, true);
World.Current.jobQueue.ReevaluateReachability();
}

if (Created != null)
Expand Down Expand Up @@ -160,7 +161,7 @@ public int CountWithType(string type)
}

/// <summary>
/// Reuturns a list of furniture using the given filter function.
/// Returns a list of furniture using the given filter function.
/// </summary>
/// <returns>A list of furnitures.</returns>
/// <param name="filterFunc">The filter function.</param>
Expand Down Expand Up @@ -308,5 +309,8 @@ private void OnRemoved(Furniture furniture)
{
furnituresVisible.Remove(furniture);
}

// Movement to jobs might have been opened, let's move jobs back into the queue to be re-evaluated.
World.Current.jobQueue.ReevaluateReachability();
}
}
2 changes: 1 addition & 1 deletion Assets/Scripts/Models/Buildable/TileType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ private void ReadBuildingJob(XmlReader parentReader)
false,
true)
{
JobDescription = "job_build_floor_" + this
Description = "job_build_floor_" + this
};
}
}
4 changes: 2 additions & 2 deletions Assets/Scripts/Models/Buildable/Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ public void ReadXmlBuildingJob(XmlReader reader)
jobTime,
items.ToArray(),
Job.JobPriority.High);
job.JobDescription = "job_build_" + Type + "_desc";
job.Description = "job_build_" + Type + "_desc";
PrototypeManager.UtilityConstructJob.Set(job);
}

Expand Down Expand Up @@ -691,7 +691,7 @@ private void ReadXmlDeconstructJob(XmlReader reader)
jobTime,
null,
Job.JobPriority.High);
job.JobDescription = "job_deconstruct_" + Type + "_desc";
job.Description = "job_deconstruct_" + Type + "_desc";
PrototypeManager.UtilityDeconstructJob.Set(job);
}

Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/Models/Buildable/UtilityManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public Utility PlaceUtility(Utility prototype, Tile tile, bool doRoomFloodFill =
/// <param name="job">The completed job.</param>
public void ConstructJobCompleted(Job job)
{
PlaceUtility(job.JobObjectType, job.tile);
PlaceUtility(job.Type, job.tile);

// FIXME: I don't like having to manually and explicitly set
// flags that preven conflicts. It's too easy to forget to set/clear them!
Expand Down
4 changes: 2 additions & 2 deletions Assets/Scripts/Models/Character/Character.cs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ public void Update(float deltaTime)
else
{
// TODO: Lack of job states should be more interesting. Maybe go to the pub and have a pint?
SetState(new IdleState(this));
SetState(new IdleState(this));
}
}
}
Expand Down Expand Up @@ -442,7 +442,7 @@ public string GetJobDescription()
return "job_no_job_desc";
}

return MyJob.JobDescription;
return MyJob.Description;
}

#endregion
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/Models/Character/CharacterManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
[MoonSharpUserData]
public class CharacterManager : IEnumerable<Character>
{
private List<Character> characters;
public List<Character> characters;

/// <summary>
/// Initializes a new instance of the <see cref="CharacterManager"/> class.
Expand Down
13 changes: 9 additions & 4 deletions Assets/Scripts/Models/Inventory/InventoryManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,13 @@ public bool PlaceInventory(Tile tile, Inventory inventory)
{
// The tile did not accept the inventory for whatever reason, therefore stop.
return false;

// TODO: Geoffrotism. Is this where we would hook in to handle inventory not being able to be placed in a tile.
}

CleanupInventory(inventory);

// We may also created a new stack on the tile, if the startTile was previously empty.
// We may also have to create a new stack on the tile, if the startTile was previously empty.
if (tileWasEmpty)
{
if (Inventories.ContainsKey(tile.Inventory.Type) == false)
Expand Down Expand Up @@ -152,12 +154,12 @@ public bool PlaceInventory(Job job, Character character)
}

// Check that there is a target to transfer to
if (job.HeldInventory.ContainsKey(sourceInventory.Type) == false)
if (job.DeliveredItems.ContainsKey(sourceInventory.Type) == false)
{
job.HeldInventory[sourceInventory.Type] = new Inventory(sourceInventory.Type, 0, sourceInventory.MaxStackSize);
job.DeliveredItems[sourceInventory.Type] = new Inventory(sourceInventory.Type, 0, sourceInventory.MaxStackSize);
}

Inventory targetInventory = job.HeldInventory[sourceInventory.Type];
Inventory targetInventory = job.DeliveredItems[sourceInventory.Type];
int transferAmount = Mathf.Min(targetInventory.MaxStackSize - targetInventory.StackSize, sourceInventory.StackSize);

sourceInventory.StackSize -= transferAmount;
Expand Down Expand Up @@ -367,6 +369,9 @@ private void InvokeInventoryCreated(Inventory inventory)
if (handler != null)
{
handler(inventory);

// Let the JobQueue know there is new inventory available.
World.Current.jobQueue.ReevaluateReachability();
}
}

Expand Down
Loading