Beispiel #1
0
        public IEnumerable <Task> GetHaulTasks()
        {
            var itemClaim = query.TaskClaim(haulRemaining);

            yield return(itemClaim);

            var haulClaim = new TaskClaim(game,
                                          (work) => {
                BB.AssertNotNull(itemClaim.claim);
                ItemClaim item = itemClaim.claim;
                if (item.amt > haulRemaining)
                {
                    return(null);
                }

                amtClaimed += item.amt;
                return(new ClaimLambda(() => amtClaimed -= item.amt));
            });

            yield return(haulClaim);

            yield return(new TaskGoTo(game, taskDesc, PathCfg.Point(itemClaim.claim.pos)));

            yield return(new TaskPickupItem(itemClaim));

            yield return(new TaskGoTo(game, taskDesc, dst));

            yield return(new TaskLambda(game, "dropoff item",
                                        (work) =>
            {
                if (!work.agent.carryingItem)
                {
                    return false;
                }

                work.Unclaim(haulClaim);

                Item item = work.agent.RemoveItem();

                // Should never happen
                int haulAmt = itemClaim.claim.amt;
                if (haulAmt > haulRemaining)
                {
                    haulAmt = haulRemaining;
                }

                if (item.info.amt > haulAmt)
                {
                    game.DropItems(
                        game.Tile(work.agent.pos),
                        item.info.WithAmount(item.info.amt - haulAmt).Enumerate());
                }
                // Also should never happen
                else if (item.info.amt < haulAmt)
                {
                    haulAmt = item.info.amt;
                }

                item.Destroy();

                amtStored += haulAmt;
                return true;
            }));
        }