Beispiel #1
0
    private JobQueue.Job jobProto; // TODO: Remove after adding "Tool" class.

    void Start()
    {
        cursors    = new List <GameObject>();
        cursorPool = new PrefabPool(cursorPrefab);
        cursorPool.SetParent(transform);
        cursorDrag = new IntDragger2(KeyCode.Mouse0);

        // TODO: Remove this after adding "Tool" class.
        jobProto = GameManager.Game.jobs.MakeProtoJob();
    }
Beispiel #2
0
 private void UpdateWork(float deltaTime)
 {
     // TODO: Redo the way job updating works.
     if (job.Update())
     {
         // TODO: Remove items for the job as progress goes forward.
         foreach (string itemType in job.requirements)
         {
             inventory.RemoveItemOfType(itemType);
         }
         job = null;
     }
 }
Beispiel #3
0
    public void Update(float deltaTime)
    {
        if (state == State.Idle)
        {
            // TODO: Add non-work jobs like eating, sleeping, or recreation.
            return;
        }

        if (path != null && path.Count > 0)
        {
            // If we have a path to follow, move along it.
            UpdateMovement(deltaTime);
        }
        else if (job == null)
        {
            // If we don't have a job, ask our union to find us one.
            job = union.FindJob(this);
            if (job != null)
            {
                state = HasRequiredItemsForJob() ? State.Working : State.Collecting;
            }
        }
        else if (state == State.Working)
        {
            if (!position.IsNextTo(job.position))
            {
                // If we are working and not next to the job, build a path to
                // the job.
                BuildPathNextTo(job.position);

                if (path == null)
                {
                    // TODO:    Determine if the failure to path was because the
                    //          worker is boxed in or if the job is boxed in.
                    Debug.LogError("Failed to build path to " + job.position);
                    Debug.LogError("Dropping job on the ground and idling.");
                    job   = null;
                    state = State.Idle;
                    return;
                }
            }
            else
            {
                // If we are working and are next to the job, do some work.
                UpdateWork(deltaTime);
            }
        }
        else if (state == State.Collecting)
        {
            if (HasRequiredItemsForJob())
            {
                // If we have all the items we need, change into the working state.
                state           = State.Working;
                targetContainer = null;
                path            = null;
            }
            else if (targetContainer == null)
            {
                // If we are collecting items and we do not have a container to
                // get the item from, find one.
                targetContainer = FindContainerWithJobItems();

                if (targetContainer == null)
                {
                    // TODO:    Queue a job to create the unfound item type(s)
                    //          and requeue our current job.
                    Debug.LogError("Failed to find containers with required items.");
                    Debug.LogError("Dropping job on the ground.");
                    job = null;
                    return;
                }
            }
            else if (!position.IsNextTo(targetContainer.position))
            {
                // If we are collecting items and we know where to get the items
                // but are not next to it, build a path to the container.
                BuildPathNextTo(targetContainer.position);

                if (path == null)
                {
                    // TODO:    Limit container finding to ones we can actually
                    //          get to.
                    Debug.LogError("Failed to find path to " + targetContainer.position);
                    Debug.LogError("Dropping job on the ground.");
                    job             = null;
                    targetContainer = null;
                    return;
                }
            }
            else
            {
                // If we are collecting items and are next to the item source,
                // pick up the items we need.
                UpdateCollection(deltaTime);
            }
        }
    }