/// <summary> /// Enqueue a job in it's designated queue /// </summary> /// <typeparam name="T">The type of the job you are enqueueing</typeparam> /// <param name="job">The job to enqueue</param> public void EnqueueJob <T>(T job) where T : Job { SpecificQueue <T> queue = SpecificQueue <T> .Instance; UnityEngine.Debug.Log("Enqueuing job of type " + job.GetType() + " for queue: " + queue.GetType()); if (activeQueuesWithKey.Keys.Contains(queue.GetDescription())) { // We are keeping track of the queue } else { // This is a job type that we don't have a queue for yet! Add it to the list of tracked job queues so the user can see it exists activeQueuesWithKey.Add(queue.GetDescription(), queue); if (JobQueueAdded != null) { JobQueueAdded(this, queue.GetDescription()); } } // The reason to do this here is because here we know the job is properly instantiated but hasn't been enqueued yet. // If a job is directly assigned to a character we don't need it to pop up on the tile. // Makes sure that the active tile is aware of it's currently active job. Unregistering is done by the tile itself. job.GetActiveTile().AddJob(job); // If the active tile is updated, the new tile should be informed job.OnJobDestinationUpdated += (j) => { j.GetActiveTile().AddJob(j); }; queue.OfferJob(job); }
public Job RequestJob(List <String> priorities) { foreach (string priority in priorities) { if (activeQueuesWithKey.ContainsKey(priority)) { SpecificQueue queue = activeQueuesWithKey[priority]; Job requestedJob = queue.RequestJob(); if (requestedJob != null) { return(requestedJob); } // No job? check for a lower priority job! } else { UnityEngine.Debug.Log("JobQueue -- A priority string was passed that we do not have a queue for, you probably edited the list instead of just reorganised it"); return(null); } } // Do not remove empty queues, this allows us to request all jobtypes that have ever been active in the world. // This is useful for setting up priorities // None of the queues had a job, the pawn is now idle return(null); }
/// <summary> /// Enqueue a job in it's designated queue, but reset the queue before enqueueing it. Only use when adding a job for the first time after deserialisation /// </summary> /// <typeparam name="T">The type of the job you are enqueueing</typeparam> /// <param name="job">The job to enqueue</param> public void EnqueueJobAndResetQueue <T>(T job) where T : Job { SpecificQueue <T> queue = SpecificQueue <T> .Instance; UnityEngine.Debug.Log("Enqueuing job of type " + job.GetType() + " and resetting queue: " + queue.GetType()); queue.HardResetQueue(); EnqueueJob(job); }