/// <summary> /// Search for a job that can be performed by the specified character. Tests that the job can be reached and there is enough inventory to complete it, somewhere. /// </summary> public Job GetJob(Character character) { DebugLog("{0},{1} GetJob() (Queue size: {2})", character.GetName(), character.ID, jobQueue.Count); if (jobQueue.Count == 0) { return(null); } // This makes a large assumption that we are the only one accessing the queue right now for (int i = 0; i < jobQueue.Count; i++) { Job job = jobQueue.Values[i]; jobQueue.RemoveAt(i); // TODO: This is a simplistic version and needs to be expanded. // If we can get all material and we can walk to the tile, the job is workable. if (job.IsRequiredInventoriesAvailable() && job.tile.IsReachableFromAnyNeighbor(true)) { if (CharacterCantReachHelper(job, character)) { UnityDebugger.Debugger.LogError("JobQueue", "Character could not find a path to the job site."); ReInsertHelper(job); continue; } else if ((job.RequestedItems.Count > 0) && !job.CanGetToInventory(character)) { job.AddCharCantReach(character); // Is this a bug? Or a warning // @ Decide UnityDebugger.Debugger.LogError("JobQueue", "Character could not find a path to any inventory available."); ReInsertHelper(job); continue; } return(job); } DebugLog(" - job failed requirements, test the next."); } return(null); }