Example #1
0
 public void TryDeletingHaulingJob()
 {
     if (haulJob != null)
     {
         haulJob.JobResultHandler -= HaulJobResultHandler;
         haulJob.DeleteJob();
         haulJob = null;
     }
 }
Example #2
0
    /// <summary>
    /// Attempts to put the item stack on the tile, or in the present tile addition
    /// Putting an item inside a tile addition has priority on putting it on top of the tile
    /// </summary>
    /// <param name="stack"></param>
    /// <returns></returns>
    public ItemStack AddItemStackToTile(ItemStack stack)
    {
        if (Addition != null)
        {
            // First try to put the itemstack in the tile addition if possible
            stack = Addition.AddItemStackToTileAddition(stack);

            // The stack has been fully placed inside the tile addition
            if (stack == null)
            {
                return(null);
            }

            if (!Addition.CanContainItemOnTile(stack))
            {
                // Now that the tile addition is full, can we put the stack on top?
                // if not end the execution here
                return(stack);
            }
            // Else we continue to try and put the itemstack on top of the tile
        }

        // At this point the item will end up on the floor, if the floor is full the item just gets deleted

        // If there is an itemstack, try to merge them, if the resulting itemstack (meaning some items weren't merged) is not null
        // The item stack wasn't fully added to this tile so return false
        if (ItemStack != null)
        {
            return(ItemStack.MergeStackInto(stack));
        }

        // If we haven't returned at this point the tile contained no items and no tile addition
        // Any regular tile can contain an itemstack (for now, for example if we add in a water tile this might not be possible)

        // Assign the itemstack to this tile
        ItemStack = stack;

        // we can't have items lying around. Anything that is dropped on the floor and becomes an itemstack should be queued to be stored
        // In case there is no storage available the user should be able to store the itemstacks later on with a command
        // If the stack has a location to be stored, create the job for it.
        ItemContainer c = world.storageContainers.GetContainerToStoreItemStack(ItemStack, this);

        Debug.Log("Item dropped on the floor and going to: " + c);
        if (c != null)
        {
            HaulJob job = new HaulJob(this, c.tile);
            world.Jobs.EnqueueJob(job);
            Debug.Log("Found container for dropped item and made haul job");
        }

        return(ItemStack);
    }
    private void TryHaulingItemToAnyStockpile(Item item)
    {
        if (Utils.TileAt(item.Position).Contents.StockpilePart != null || item.HasHaulJob)
        {
            return;
        }

        StockpilePart part = FindStockpilePartForItem(item);

        if (part != null)
        {
            HaulJob job = new HaulJob(item, part.position);
            part.SetHaulJob(job);
            JobSystem.GetInstance().AddJob(job);
        }
    }
Example #4
0
 protected override void OnJobDeleted(Job job)
 {
     if (pawnThatPickedUpItem != null)
     {
         // Cancelling this job should delete this job instead of cancelling it
         // We'll create the new job on our own because the pickup tile will have changed
         HaulJob updated = new HaulJob(pawnThatPickedUpItem.CurrTile, dropoff);
         pawnThatPickedUpItem.HeldItem = pawnThatPickedUpItem.CurrTile.AddItemStackToTile(pawnThatPickedUpItem.HeldItem);
         DestinationTile.world.Jobs.EnqueueJob(updated);
         job.DeleteJob();
     }
     else
     {
         // We didn't reach the destination tile so just cancel it like always
         base.OnJobDeleted(job);
     }
 }
Example #5
0
    private void RemoveItemFromTileUnderConstructionPlan()
    {
        //find closest free spot
        bool RequirementsFunction(Tile t) => (t is null) ? false : !t.Contents.HasItem;

        Tile haulToTile = SearchEngine.FindClosestTileWhere(Position, RequirementsFunction);

        if (haulToTile != null)
        {
            Job job = new HaulJob(Utils.TileAt(Position).Contents.Item, haulToTile.Position);
            _jobs.Add(job);
            JobSystem.GetInstance().AddJob(job);
            job.JobResultHandler += OnTileClearJobFinish;
        }
        else
        {
            Debug.LogError("No empty tile to move item to was found. Implement wait function to try again some time later. P: " + Position);
        }
    }
Example #6
0
 public void SetHaulJob(HaulJob job)
 {
     HasHaulJob            = true;
     job.JobResultHandler += HaulJobResultHandler;
 }
Example #7
0
 public void HaulJobResultHandler(object source, EventArgs e)
 {
     haulJob.JobResultHandler -= HaulJobResultHandler;
     haulJob = null;
 }
Example #8
0
 public void SetHaulJob(HaulJob haulJob) => this.haulJob = haulJob;