Exemplo n.º 1
0
            private IEnumerable <Task> GetClearDebrisTasks()
            {
                const string desc = "Hauling debris from build site.";

                while (HasDebris())
                {
                    foreach (var pos in building.bounds.allPositionsWithin)
                    {
                        var tile = game.Tile(pos);
                        if (tile.hasItems)
                        {
                            yield return(Capture(game.ClaimItem(tile), out var claim));

                            yield return(new TaskGoTo(game, desc, PathCfg.Point(pos)));

                            yield return(new TaskPickupItem(claim));

                            yield return(new TaskGoTo(game, desc,
                                                      new PathCfg(
                                                          pt => !area.Contains(pt) && !game.Tile(pt).hasItems,
                                                          pt => Vec2.Distance(pt, area.center))));

                            yield return(new TaskLambda(game, "drop item",
                                                        (work) =>
                            {
                                BB.Assert(work.agent.carryingItem);
                                Item item = work.agent.RemoveItem();
                                game.DropItems(
                                    game.Tile(work.agent.pos),
                                    item.info.Enumerate());
                                item.Destroy();
                                return true;
                            }));
                        }
                    }
                }
            }
Exemplo n.º 2
0
 // TODO: make Item ItemVis or something, no one should really be
 // holding onto these
 public void K_DropItem(Tile tile, Item item)
 {
     item.Destroy();
     DropItems(tile, item.info.Enumerate());
 }
Exemplo n.º 3
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;
            }));
        }