public static void Stockpile_UpdateAction(InstalledObject obj, float deltaTime)
    {
        if (obj.Tile.LooseObject != null && obj.Tile.LooseObject.StackSize >= obj.Tile.LooseObject.MaxStackSize)
        {
            obj.ClearJobs();
            return;
        }


        if (obj.JobCount() > 0)
        {
            return;
        }

        if (obj.Tile.LooseObject != null && obj.Tile.LooseObject.StackSize == 0)
        {
            Debug.LogError("Stockpile has a zero-size stack!");
            obj.ClearJobs();
            return;
        }

        LooseObject[] requiredItems;

        if (obj.Tile.LooseObject == null)
        {
            requiredItems = Stockpile_GetItemsFromFilter();
        }
        else
        {
            LooseObject desiredLooseObject = obj.Tile.LooseObject.Clone();
            desiredLooseObject.MaxStackSize -= desiredLooseObject.StackSize;
            desiredLooseObject.StackSize     = 0;

            requiredItems = new LooseObject[] { desiredLooseObject };
        }

        Job job = new Job(obj.Tile, null, null, 0, requiredItems);

        job.CanFetchFromStockpile = false;

        job.RegisterJobProgressedCallback(Stockpile_JobProgressed);
        obj.AddJob(job);
    }
示例#2
0
    public static void Stockpile_UpdateAction(InstalledObject _inObj, float _deltaTime)
    {
        //we need to make sure that there is always a job to bring inventory to us if we aren't empty

        //if we already have a job, return
        if (_inObj.JobCount() > 0)
        {
            return;
        }

        if (_inObj.Tile.Inventory == null)
        {
            //We are empty, ask for anything to be brought here
            Job j = new Job(_inObj.Tile, null, Stockpile_JobComplete, 0, new Inventory[1] {
                new Inventory("Steel Plate", 50, 0)
            });                                                                                                                     //need to be able to ask for any type

            _inObj.AddJob(j);
        }
    }
示例#3
0
    public static void Stockpile_UpdateAction(InstalledObject installedObject, float deltaTime)
    {
        /// Ensure that there is a job in the queue asking for either:
        ///     (if this.stockpile empty): That ANY material/items/looseObjects can be brought to us.
        ///     (if this.stockpile contains something already): If there is still room for more, bring it to this.stockpile

        // TODO: This function doesn't need to run each update.
        // Instead it only needs to run when:
        //      - It gets created
        //      - A good get delivered (at which point we reset the job)
        //      - A good gets picked up (at which point we reset the job)
        //      - The UI's filter of allowed items gets changed/updated

        // Stockpile is full
        if (installedObject.Tile.LooseObject != null && installedObject.Tile.LooseObject.StackSize >= installedObject.Tile.LooseObject.maxStackSize)
        {
            installedObject.ClearJobs();
            return;
        }

        // Maybe we already have a job queued up? In which case we're good to go
        if (installedObject.JobCount() > 0)
        {
            return;
        }

        // We're not full, but we don't have a job either
        /// Two possibilities: Either we have SOME inventory OR we have NO inventory

        // Check if there is an empty stockpile => should NOT happen
        if (installedObject.Tile.LooseObject != null && installedObject.Tile.LooseObject.StackSize == 0)
        {
            Debug.LogError("Stockpile has a 0 sized stack!");
            installedObject.ClearJobs();
            return;
        }

        // TODO: In the future stockpiles => rather than being a bunch of individual 1x1 tiles, should create one large single object.

        // Temp array of items that are required for the new job
        LooseObject[] requiredItems;

        // Stockpile is empty => ask/accept ANYTHING
        if (installedObject.Tile.LooseObject == null)
        {
            requiredItems = Stockpile_GetItemsFromFilter();
        }

        // There is already a stack that isn't full yet => add more stuff
        else
        {
            // Is there already a job => if so return
            if (installedObject.JobCount() > 0)
            {
                return;
            }

            LooseObject desiredLooseObject = installedObject.Tile.LooseObject.Clone();
            desiredLooseObject.maxStackSize -= desiredLooseObject.StackSize;
            desiredLooseObject.StackSize     = 0;

            requiredItems = new LooseObject[] { desiredLooseObject };
        }

        // Create the new job with requiredItems
        Job job = new Job(
            installedObject.Tile,
            null,
            null,
            0,
            requiredItems
            );

        // TODO: Later on, add stockpile priorities, so that we can take from a lower priority for a higher one.
        job.canTakeFromStockpile = false;

        // Register callback and add job
        job.RegisterJobProgressedCallback(Stockpile_JobProgressed);
        installedObject.AddJob(job);
    }