Пример #1
0
    public static void Stockpile_UpdateAction(Furniture furniture, float deltaTime)
    {
        Inventory furnitureInventory = furniture.tile.inventory;

        if (furnitureInventory != null && furnitureInventory.stackSize >= furnitureInventory.maxStackSize)
        {
            furniture.CancelJobs();
            return;
        }

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

        if (furnitureInventory != null && furnitureInventory.stackSize == 0)
        {
            Debug.LogError("Stockpile_UpdateAction - has a zero sized stack");
            furniture.CancelJobs();
            return;
        }

        Inventory[] itemsDesired;

        if (furnitureInventory == null)
        {
            itemsDesired = Stockpile_GetItemsFromFilter();
        }
        else
        {
            Inventory desired = furnitureInventory.Clone();
            desired.maxStackSize -= desired.stackSize;
            desired.stackSize     = 0;
            itemsDesired          = new Inventory[] { desired };
        }

        Job job = new Job(
            furniture.tile,
            null,
            null,
            0f,
            itemsDesired
            );

        job.canTakeFromStockpile = false;
        job.RegisterJobWorkedCallback(Stockpile_JobWorked);
        furniture.AddJob(job);
    }
Пример #2
0
    public static void MiningDroneStation_UpdateAction(Furniture furniture, float deltaTime)
    {
        Tile spawnSpotTile = furniture.GetSpawnSpotTile();

        if (spawnSpotTile.inventory != null && spawnSpotTile.inventory.stackSize >= spawnSpotTile.inventory.maxStackSize)
        {
            if (furniture.JobCount() > 0)
            {
                furniture.CancelJobs();
            }

            return;
        }


        /*if (furniture.JobCount () > 0) {
         *      if (spawnSpotTile.inventory.stackSize >= spawnSpotTile.inventory.maxStackSize) {
         *              furniture.ClearJobs ();
         *      }
         *
         *      return;
         * }
         *
         * if (spawnSpotTile.inventory.stackSize >= spawnSpotTile.inventory.maxStackSize) {
         *      return;
         * }*/

        Tile jobSpot = furniture.GetJobSpotTile();

        if (jobSpot.inventory != null && (jobSpot.inventory.inventoryType != "Steel Plate" || jobSpot.inventory.stackSize >= jobSpot.inventory.maxStackSize))
        {
            return;
        }

        Job job = new Job(
            jobSpot,
            MiningDroneStation_JobComplete,
            null,
            1f,
            null,
            true
            );

        furniture.AddJob(job);
    }
Пример #3
0
    public static void StockpileUpdateAction(Furniture furniture, float deltaTime)
    {
        //Debug.Log("StockpileUpdateAction");

        //We need to ensure that we have a job on the queue asking for:
        //If we are empty: that any loose inventory be brought to us
        //If we have something:
        //if we are below the max stacksize: bring us stuff

        //Todo fixme: this function doesn't need to run each update
        //Only run when:
        //              --gets created
        //              --good gets delivered
        //              --good gets picked up
        //              --Ui filter of allowed items gets changed

        if (furniture.tile.inventoryTile != null && furniture.tile.inventoryTile.stackSize >= furniture.tile.inventoryTile.maxStackSize)
        {
            //we are full
            furniture.ClearJobs();
            return;
        }

        //Maybe we already have a job Queued
        if (furniture.JobCount() > 0)
        {
            //Cool, all done
            return;
        }

        //Currently not full but we don't have a job either
        //Two possibilites Some Inventory or No inventory

        //Third possiblity something is wrong
        if (furniture.tile.inventoryTile != null && furniture.tile.inventoryTile.stackSize == 0)
        {
            Debug.LogError("Stockpile has a zero-size stack. This is clearly wrong!");
            furniture.ClearJobs();
            return;
        }

        //Todo fixme: make stockpiles into multitile furniture
        //Also fix holes in stockpiles
        Inventory[] itemsDesired;

        if (furniture.tile.inventoryTile == null)
        {
            //Debug.Log("furn.tile.inventory == null");
            //We are empty -- just ask for anything
            Debug.Log("Creating job for new stack");
            itemsDesired = StockpileGetItemsFromFilter();
        }
        else
        {
            Debug.Log("Creating job for existing stack");
            //We have a stack of something but we are not full
            Inventory desiredInventory = furniture.tile.inventoryTile.Clone();
            desiredInventory.maxStackSize -= desiredInventory.stackSize;
            desiredInventory.stackSize     = 0;
            itemsDesired = new Inventory[] { desiredInventory };
        }

        Job job = new Job(furniture.tile, null, null, 0f, itemsDesired);

        //todo fixme: add stockpile priorties to take from a lower priority stockpile
        job.canTakeFromStockpile = false;
        job.RegisterJobWorkedCallback(StockpileJobWorked);
        furniture.AddJob(job);
    }
Пример #4
0
    public static void Stockpile_UpdateAction(Furniture furn, float deltaTime)
    {
        // We need to ensure that we have a job ont the queue asking:
        //  If we are empty      -> Bring any loose inventory to us
        //  If we have something -> If we are bellow max stack, bring more of it

        // TODO: This furniture doesn't need to run each update, only when:
        //                                                              -- It gets created
        //                                                              -- A good gets delivered
        //                                                              -- A good gets picked up
        //                                                              -- The UI's filter of allowed items get changed

        if (furn.tile.inventory != null && furn.tile.inventory.stackSize >= furn.tile.inventory.maxStackSize)
        {
            // We are full!
            furn.ClearJobs();
            return;
        }


        // We have already a job queued up?
        if (furn.JobCount() > 0)
        {
            return;
        }

        // Currently not full but don't have a job yet.
        // TWO possibilities: Either we have SOME inventory, or we have NONE

        // SomethingIsDeeplyWrong_Test
        if (furn.tile.inventory != null && furn.tile.inventory.stackSize == 0)
        {
            Debug.LogError("Stockpile has a zero-size stack. Clearly WRONG!");
            furn.ClearJobs();
            return;
        }

        Inventory[] itemsDesired;

        if (furn.tile.inventory == null)
        {
            // We are empty! -- Ask for aything.
            itemsDesired = Stockpile_GetItemFromFilter();
        }
        else
        {
            // We aren't empty but we don't have a job! -- Create a job.
            Inventory desInv = furn.tile.inventory.Clone();
            desInv.maxStackSize -= desInv.stackSize;
            desInv.stackSize     = 0;

            itemsDesired = new Inventory[] { desInv };
        }

        Job j = new Job(
            furn.tile,
            null,
            null,
            0,
            itemsDesired
            );

        // TODO: Add stockpile priorities.
        j.canTakeFromStockpile = false;

        j.RegisterJobWorkedCallback(Stockpile_JobWorked);
        furn.AddJob(j);
    }
Пример #5
0
    public static void Stockpile_UpdateAction(Furniture furn, float deltaTime)
    {
        //TODO: we will want to stop this running EVERY update. Lots of furniture will mean job spam!
        // Instead it will need to only run when:-
        //   -- It gets created
        //   -- A good gets delivered. (job reset)
        //   -- A good gets picked up. (job reset)
        //   -- UI "filter" gets modified.

        if (furn.tile.inventory != null && furn.tile.inventory.stackSize >= furn.tile.inventory.maxStackSize)
        {
            //we're full!
            furn.ClearJobs();
            return; //GTFO
        }

        if (furn.tile.inventory != null && furn.tile.inventory.stackSize == 0)
        {
            Debug.LogError("Stockpile:- Something went horribly wrong. the stockpile has a ZERO stacksize.");
            furn.ClearJobs();
            return; //GTFO
        }


        if (furn.JobCount() > 0)
        {
            //cool. donesies.
            return;
        }

        /*TODO: in future stockpiles, rather than being 1x1 pieces of
         * seperate furniture, we will make them single large objects
         * this would represent our first and probably only variable sized
         * furniture:-
         *  - consider holes in stockpile? maybe a station is installed in
         *    the middle.
         *  - Once we implement "mega stockpiles", then the job creation system
         *  will probably be a lot smarter. We will have requests for different
         *  objects.
         *
         *
         * Two routes from this point onwards, we have SOME/ALL Inventory.
         * or we have NO inventory.
         */
        Inventory[] itemsDesired;
        if (furn.tile.inventory == null)
        {
            Debug.Log("Stockpile:- Creating job for requesting new stack.");
            itemsDesired = Stockpile_GetItemsFromFilter();
        }
        else
        {
            Debug.Log("Stockpile:-Creating job for existing stack.");
            Inventory desInv = furn.tile.inventory.Clone();
            desInv.maxStackSize -= desInv.stackSize;
            desInv.stackSize     = 0;
            itemsDesired         = new Inventory[] { desInv };
        }


        Job j = new Job(
            furn.tile,
            null,
            null,
            0,
            itemsDesired
            );

        //TODO: add stockpile priorities, so we can take from lower priority -> higher priority stockpile.
        j.canTakeFromStockpile = false;
        j.RegisterJobWorkedCallback(Stockpile_JobWorked);
        furn.AddJob(j);
    }