コード例 #1
0
ファイル: SystemDeconstruct.cs プロジェクト: sjschaff/rimlite
 public JobDeconstruct(SystemDeconstruct orders, IBuilding building)
     : base(orders, building, $"Deconstruct {building.def.name}.")
 {
     BB.AssertNotNull(building);
     buildable = (IBuildable)building.prototype;
     BB.Assert(buildable != null);
 }
コード例 #2
0
ファイル: SystemMine.cs プロジェクト: sjschaff/rimlite
 public JobMine(SystemMine system, IBuilding building)
     : base(system, building, $"Mine {building.def.name}.") // TODO: tool type
 {
     BB.AssertNotNull(building);
     mineable = (IMineable)building;
     BB.AssertNotNull(mineable);
 }
コード例 #3
0
        private static T TryInstantiate <T>(string failName, Type type, params object[] args)
            where T : class
        {
            // TODO: use reflection to check first so we dont have to deal with exceptions
            try
            {
                return((T)Activator.CreateInstance(type, args));
            } catch (MissingMethodException)
            {
                string ctor = $"{type.Name}(";
                if (args.Length > 0)
                {
                    ctor += args[0].GetType().Name;
                }
                for (int i = 1; i < args.Length; ++i)
                {
                    ctor += ", " + args[i].GetType().Name;
                }
                ctor += ")";
                BB.LogWarning($"Failed to instatiate {failName} '{type.FullName}': " +
                              $"missing constructor {ctor}");
            }

            return(null);
        }
コード例 #4
0
ファイル: Work.cs プロジェクト: sjschaff/rimlite
 public void Unclaim(IClaim claim)
 {
     BB.AssertNotNull(claim);
     BB.Assert(claims.Contains(claim));
     claim.Unclaim();
     claims.Remove(claim);
 }
コード例 #5
0
ファイル: SystemMine.cs プロジェクト: sjschaff/rimlite
            protected override IEnumerable <Task> GetTasks()
            {
                string desc = $"{DescForTool(mineable.tool)} {mineable.def.name}.";

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

                yield return(new TaskTimedLambda(
                                 game, desc, MinionAnim.Slash,
                                 mineable.tool, mineable.mineAmt,
                                 TaskTimed.FacePt(tile.pos),
                                 _ => 1,
                                 (task, workAmt) =>
                {
                    BB.Assert(task.work == activeWork);
                    mineable.mineAmt -= workAmt;
                    return true;
                },
                                 (task) =>
                {
                    BB.Assert(task.work == activeWork);
                    BB.Assert(mineable.mineAmt <= 0);

                    mineable.jobHandles.Remove(this);
                    game.RemoveBuilding(mineable);
                    game.DropItems(tile, mineable.GetMinedMaterials());
                }
                                 ));
            }
コード例 #6
0
ファイル: Misc.cs プロジェクト: sjschaff/rimlite
 private Ray(Vec2 start, Vec2 ray)
 {
     BB.Assert(ray.sqrMagnitude > 0);
     this.start = start;
     this.mag   = ray.magnitude;
     this.dir   = ray / mag;
 }
コード例 #7
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;
                }));
            }
コード例 #8
0
        private Sprite GetSprite(Map map, Vec2I pos, Vec2I subTile, int frame)
        {
            BB.Assert(frame < def.spriteFrames.Length);

            TerrainDef lambdaDef = def; // C# is dumb

            Tiling.TileType ttype = Tiling.GetTileType(pos, subTile, p => IsSame(map, p, lambdaDef));

            // TODO: Kludge for water arrangement in atlas
            if (def == K_waterDef)
            {
                switch (ttype)
                {
                case Tiling.TileType.ConcaveBL: ttype = Tiling.TileType.ConcaveTR; break;

                case Tiling.TileType.ConcaveTR: ttype = Tiling.TileType.ConcaveBL; break;

                case Tiling.TileType.ConcaveBR: ttype = Tiling.TileType.ConcaveTL; break;

                case Tiling.TileType.ConcaveTL: ttype = Tiling.TileType.ConcaveBR; break;
                }
            }

            var spritePos = def.spriteFrames[frame] + Tiling.SpriteOffset(ttype);

            return(atlas.GetSprite(spritePos, Vec2I.one));
        }
コード例 #9
0
ファイル: Task.cs プロジェクト: sjschaff/rimlite
 public Status BeginTask(Work work)
 {
     BB.AssertNull(this.work);
     BB.AssertNotNull(work);
     BB.AssertNotNull(work.agent);
     this.work = work;
     return(OnBeginTask());
 }
コード例 #10
0
ファイル: Map.cs プロジェクト: sjschaff/rimlite
        public void ReplaceBuilding(IBuilding building)
        {
            var tile = building.tile;

            BB.Assert(tile.hasBuilding);
            BB.Assert(tile.building.bounds.Equals(building.bounds));
            SetBuilding(tile.pos, building);
        }
コード例 #11
0
ファイル: Agent.cs プロジェクト: sjschaff/rimlite
 private void ReconfigureItem()
 {
     BB.AssertNotNull(carriedItem);
     carriedItem.Configure(
         dir == Dir.Up ?
         Item.Config.PlayerBelow :
         Item.Config.PlayerAbove);
 }
コード例 #12
0
ファイル: Map.cs プロジェクト: sjschaff/rimlite
        public void RemoveItem(TileItem item)
        {
            BB.AssertNotNull(item.tile);
            var tile = Tile(item.tile.pos);

            BB.Assert(item == tile.item);
            Tile(item.tile.pos).item = null;
        }
コード例 #13
0
ファイル: ToolSelection.cs プロジェクト: sjschaff/rimlite
        public void Init(Vec2 worldPos, Vec2 scPos, IEnumerable <Minion> minions)
        {
            this.minions = minions.ToList();
            BB.Assert(this.minions.Count > 0);

            this.targetPos = worldPos.Floor();
            this.menuPos   = scPos;
            this.selection = ctrl.SelectAll(worldPos);
        }
コード例 #14
0
 public void Undraft()
 {
     BB.Assert(isDrafted);
     isDrafted = false;
     if (hasWork)
     {
         AbandonWork();
     }
 }
コード例 #15
0
 public void Draft()
 {
     BB.Assert(!isDrafted);
     isDrafted = true;
     if (hasWork)
     {
         AbandonWork();
     }
 }
コード例 #16
0
 public TaskWaitLambda(Game game, string description,
                       Func <TaskWaitLambda, float, bool> doneFn,
                       Action <TaskWaitLambda, bool> completeFn = null)
     : base(game, description)
 {
     BB.AssertNotNull(doneFn);
     this.doneFn     = doneFn;
     this.completeFn = completeFn;
 }
コード例 #17
0
ファイル: Map.cs プロジェクト: sjschaff/rimlite
        private void Init()
        {
            BB.AssertNotNull(tiles);
            BB.AssertNull(tiler);
            BB.AssertNull(nav);

            tiler = new MapTiler(this);
            nav   = new Nav(this);
        }
コード例 #18
0
        public static ItemClaim MakeClaim(Game game, TileItem item, int amt)
        {
            BB.AssertNotNull(item);
            if (!game.TryClaim(item, amt))
            {
                return(null);
            }

            return(new ItemClaim(game, item, amt));
        }
コード例 #19
0
ファイル: Work.cs プロジェクト: sjschaff/rimlite
 private void Complete()
 {
     BB.Assert(claims.Count == 0);
     if (claims.Count != 0)
     {
         BB.LogError("Task completed with claims left over, this is a bug");
     }
     ClearClaims();
     agent.WorkCompleted(this);
 }
コード例 #20
0
        private void DropItem(Tile tile, Item item)
        {
            BB.AssertNotNull(item);
            BB.Assert(!tile.hasItems);

            var tileItem = new TileItem(tile, item);

            items.AddLast(tileItem);
            map.PlaceItem(tileItem);
            NotifyItemAdded(tileItem);
        }
コード例 #21
0
        public void AddBuilding(IBuilding building)
        {
            BB.Assert(CanPlaceBuilding(building.bounds));

            var  tile     = building.tile;
            bool passable = tile.passable;

            map.AddBuilding(building);
            NotifyBuildingAdded(building);
            RerouteMinions(building.bounds, passable, tile.passable);
        }
コード例 #22
0
ファイル: Work.cs プロジェクト: sjschaff/rimlite
 public void Abandon(Agent agent)
 {
     BB.AssertNotNull(this.agent);
     BB.Assert(this.agent == agent);
     if (activeTask != null)
     {
         EndActiveTask(true);
     }
     job.AbandonWork(this);
     ClearClaims();
 }
コード例 #23
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);
                }));
            }
コード例 #24
0
            private void AddOrder(RecipeDef recipe)
            {
                BB.Assert(bench.proto.def.recipes.Contains(recipe));
                var order = new Order(recipe);

                orders.Add(order);

                var path = PathCfg.Adjacent(bench.bounds);

                order.hauls = new HaulProviders(game, bench.def.name, path,
                                                recipe.materials);
            }
コード例 #25
0
        public                     Sprite[] GetAnimationSprites(Map map, Vec2I pos, Vec2I subTile)
        {
            BB.Assert(animated);

            var sprites = new Sprite[def.spriteFrames.Length];

            for (int i = 0; i < def.spriteFrames.Length; ++i)
            {
                sprites[i] = GetSprite(map, pos, subTile, i);
            }
            return(sprites);
        }
コード例 #26
0
ファイル: Work.cs プロジェクト: sjschaff/rimlite
        public void ClaimWork(Agent agent)
        {
            BB.AssertNull(this.agent);
            BB.AssertNull(activeTask);
            this.agent = agent;
            if (agent is Minion minion)
            {
                this.minion = minion;
            }

            BB.Assert(MoveToNextTask(), "Work task failed immediately");
        }
コード例 #27
0
        public Tile FindNearestTile(Tile tileStart, Func <Tile, bool> filterFn)
        {
            BB.AssertNotNull(filterFn);
            Tile ret = null;

            FloodFill(tileStart, filterFn, tile =>
            {
                ret = tile;
                return(true);
            });

            return(ret);
        }
コード例 #28
0
ファイル: Map.cs プロジェクト: sjschaff/rimlite
        private void InitTiles(Vec2I size)
        {
            BB.AssertNull(tiles);

            this.size = size;
            tiles     = new BBTile[size.x, size.y];
            for (int x = 0; x < size.x; ++x)
            {
                for (int y = 0; y < size.y; ++y)
                {
                    tiles[x, y] = new BBTile(new Vec2I(x, y));
                }
            }
        }
コード例 #29
0
ファイル: Work.cs プロジェクト: sjschaff/rimlite
        public Work(JobHandle job, IEnumerable <Task> tasks, string D_workName)
        {
#if DEBUG
            D_uniqueID = D_nextID;
            ++D_nextID;
            this.D_workName = D_workName;
#endif
            BB.AssertNotNull(job);
            BB.AssertNotNull(tasks);

            this.job    = job;
            this.claims = new HashSet <IClaim>();
            this.tasks  = tasks.GetEnumerator();
        }
コード例 #30
0
        public void RemoveBuilding(IBuilding building)
        {
            var tile = building.tile;

            BB.Assert(tile.hasBuilding);
            BB.Assert(building.tile.building == building);

            bool passable = tile.passable;
            var  bounds   = building.bounds;

            building.CancelAllJobs();
            map.RemoveBuilding(tile);
            NotifyBuildingRemoved(building);
            RerouteMinions(bounds, passable, tile.passable);
        }