Beispiel #1
0
            private IEnumerable <Task> GetTasks(Order order)
            {
                yield return(new TaskLambda(game, "add handle",
                                            (work) =>
                {
                    if (activeWork != null)
                    {
                        return false;
                    }

                    activeWork = work;
                    return true;
                }));

                while (order.hauls.HasAvailableHauls(out var haul))
                {
                    foreach (var task in haul.GetHaulTasks())
                    {
                        yield return(task);
                    }
                }

                if (order.hauls.HasAllMaterials())
                {
                    // TODO: clear bench of debris
                    yield return(new TaskGoTo(game, $"Walking to {bench.def.name}.",
                                              PathCfg.Point(bench.workSpot)));

                    yield return(new TaskTimedLambda(
                                     game, order.recipe.description, MinionAnim.Idle,
                                     Tool.None, order.progress, TaskTimed.FaceArea(bench.bounds),
                                     _ => 1, // TODO: workspeed
                                     (task, amt) =>
                    {
                        if (order.amtOrdered <= 0)
                        {
                            return false;
                        }

                        order.progress = amt;
                        return true;
                    },
                                     (task) =>
                    {
                        BB.Assert(order.amtOrdered > 0);
                        order.amtOrdered -= 1;
                        order.progress = order.recipe.workAmt;
                        order.hauls.RemoveStored();
                        game.DropItems(bench.tile, order.recipe.product);
                    }));
                }

                yield return(new TaskLambda(game, "rem handle",
                                            (work) =>
                {
                    BB.Assert(activeWork == work);
                    activeWork = null;
                    return true;
                }));
            }
Beispiel #2
0
            private IEnumerable <Task> GetBuildTasks()
            {
                yield return(Capture(new TaskClaim(game,
                                                   (work) => ClaimBuild()), out var buildClaim));

                // TODO: only the builder can clear debris for
                // now to prevent jobs failing immediately after
                // all the debris is claimed
                foreach (var task in GetClearDebrisTasks())
                {
                    yield return(task);
                }

                if (!building.conDef.proto.passable)
                {
                    yield return(new TaskLambda(
                                     game, "init. build",
                                     (work) =>
                    {
                        if (!IsBlocked(work.minion))
                        {
                            building.constructionBegan = true;
                            game.RerouteMinions(area, true);
                            return true;
                        }

                        return false;
                    }));
                }
                yield return(new TaskGoTo(game, $"Building {name}.", PathCfg.Adjacent(area)));

                yield return(new TaskTimedLambda(
                                 game, $"Building {name}.",
                                 MinionAnim.Slash, Tool.Hammer, 2,
                                 TaskTimed.FaceArea(area),
                                 _ => 1, // TODO: workspeed
                                 // TODO: track work amount on building
                                 null,   //(work, workAmt) => /**/, 9
                                 (task) =>
                {
                    BB.Assert(tile.building == building);

                    task.work.Unclaim(buildClaim);
                    hauls.RemoveStored();

                    building.jobHandles.Remove(this);
                    game.ReplaceBuilding(
                        building.conDef.proto.CreateBuilding(tile, building.dir));

                    activeWorks.Remove(task.work);
                    system.RemoveJob(this);
                }));
            }
Beispiel #3
0
            protected override IEnumerable <Task> GetTasks()
            {
                string desc = $"Deconstructing {building.def.name}.";

                yield return(new TaskGoTo(game, desc, PathCfg.Adjacent(building.bounds)));

                yield return(new TaskTimedLambda(
                                 game, desc, MinionAnim.Slash, Tool.Hammer, 2,
                                 TaskTimed.FaceArea(building.bounds),
                                 _ => 1,
                                 null, // TODO: track deconstruct amt
                                 (task) =>
                {
                    BB.Assert(building.tile.building == building);
                    building.jobHandles.Remove(this);
                    game.RemoveBuilding(building);
                    game.DropItems(building.tile, buildable.GetBuildMaterials());
                }));
            }