public static IEnumerable<CPos> Tiles(string name, BuildingInfo buildingInfo, CPos topLeft)
        {
            var dim = (CVec)buildingInfo.Dimensions;

            var footprint = buildingInfo.Footprint.Where(x => !char.IsWhiteSpace(x));

            if (Rules.Info[ name ].Traits.Contains<BibInfo>())
            {
                dim += new CVec(0, 1);
                footprint = footprint.Concat(new char[dim.X]);
            }

            return TilesWhere( name, dim, footprint.ToArray(), a => a != '_' ).Select( t => t + topLeft );
        }
 public static IEnumerable<CPos> UnpathableTiles(string name, BuildingInfo buildingInfo, CPos position)
 {
     var footprint = buildingInfo.Footprint.Where( x => !char.IsWhiteSpace( x ) ).ToArray();
     foreach( var tile in TilesWhere( name, (CVec)buildingInfo.Dimensions, footprint, a => a == 'x' ) )
         yield return tile + position;
 }
 public static WVec CenterOffset(BuildingInfo buildingInfo)
 {
     var dim = buildingInfo.Dimensions;
     // Offset is measured relative to the center of the cell, so need to subtract an additional half cell.
     return new CVec(dim.X, dim.Y).ToWVec() / 2 - new WVec(512, 512, 0);
 }
Beispiel #4
0
        public static CVec AdjustForBuildingSize(BuildingInfo buildingInfo)
        {
            var dim = buildingInfo.Dimensions;

            return(new CVec(dim.X / 2, dim.Y > 1 ? (dim.Y + 1) / 2 : 0));
        }
 public static CVec AdjustForBuildingSize(BuildingInfo buildingInfo)
 {
     var dim = buildingInfo.Dimensions;
     return new CVec(dim.X / 2, dim.Y > 1 ? (dim.Y + 1) / 2 : 0);
 }
Beispiel #6
0
 public Bib(Actor self, BibInfo info)
 {
     this.info = info;
     rs        = self.Trait <RenderSprites>();
     bi        = self.Info.Traits.Get <BuildingInfo>();
 }
Beispiel #7
0
        public static IEnumerable <CPos> GetLineBuildCells(World world, CPos location, string name, BuildingInfo bi)
        {
            var lbi     = world.Map.Rules.Actors[name].Traits.Get <LineBuildInfo>();
            var topLeft = location;             // 1x1 assumption!

            if (world.IsCellBuildable(topLeft, bi))
            {
                yield return(topLeft);
            }

            // Start at place location, search outwards
            // TODO: First make it work, then make it nice
            var vecs = new[] { new CVec(1, 0), new CVec(0, 1), new CVec(-1, 0), new CVec(0, -1) };

            int[] dirs = { 0, 0, 0, 0 };
            for (int d = 0; d < 4; d++)
            {
                for (int i = 1; i < lbi.Range; i++)
                {
                    if (dirs[d] != 0)
                    {
                        continue;
                    }

                    var cell = topLeft + i * vecs[d];
                    if (world.IsCellBuildable(cell, bi))
                    {
                        continue;                         // Cell is empty; continue search
                    }
                    // Cell contains an actor. Is it the type we want?
                    if (world.ActorsWithTrait <LineBuildNode>().Any(a =>
                                                                    (
                                                                        a.Actor.Location == cell &&
                                                                        a.Actor.Info.Traits.Get <LineBuildNodeInfo>().Types.Intersect(lbi.NodeTypes).Any()
                                                                    )))
                    {
                        dirs[d] = i;                         // Cell contains actor of correct type
                    }
                    else
                    {
                        dirs[d] = -1;                         // Cell is blocked by another actor type
                    }
                }

                // Place intermediate-line sections
                if (dirs[d] > 0)
                {
                    for (int i = 1; i < dirs[d]; i++)
                    {
                        yield return(topLeft + i * vecs[d]);
                    }
                }
            }
        }
Beispiel #8
0
 public static bool IsCellBuildable(this World world, CPos a, BuildingInfo bi)
 {
     return(world.IsCellBuildable(a, bi, null));
 }
Beispiel #9
0
		public static WVec CenterOffset(World w, BuildingInfo buildingInfo)
		{
			var dim = buildingInfo.Dimensions;
			return (w.Map.CenterOfCell(CPos.Zero + new CVec(dim.X, dim.Y)) - w.Map.CenterOfCell(new CPos(1, 1))) / 2;
		}
Beispiel #10
0
        public static IEnumerable <int2> GetLineBuildCells(World world, int2 location, string name, BuildingInfo bi)
        {
            int range   = Rules.Info[name].Traits.Get <LineBuildInfo>().Range;
            var topLeft = location;             // 1x1 assumption!

            if (world.IsCellBuildable(topLeft, bi))
            {
                yield return(topLeft);
            }

            // Start at place location, search outwards
            // TODO: First make it work, then make it nice
            var vecs = new[] { new int2(1, 0), new int2(0, 1), new int2(-1, 0), new int2(0, -1) };

            int[] dirs = { 0, 0, 0, 0 };
            for (int d = 0; d < 4; d++)
            {
                for (int i = 1; i < range; i++)
                {
                    if (dirs[d] != 0)
                    {
                        continue;
                    }

                    int2 cell = topLeft + i * vecs[d];
                    if (world.IsCellBuildable(cell, bi))
                    {
                        continue;                         // Cell is empty; continue search
                    }
                    // Cell contains an actor. Is it the type we want?
                    if (world.ActorsWithTrait <LineBuild>().Any(a => (a.Actor.Info.Name == name && a.Actor.Location.X == cell.X && a.Actor.Location.Y == cell.Y)))
                    {
                        dirs[d] = i;                         // Cell contains actor of correct type
                    }
                    else
                    {
                        dirs[d] = -1;                         // Cell is blocked by another actor type
                    }
                }

                // Place intermediate-line sections
                if (dirs[d] > 0)
                {
                    for (int i = 1; i < dirs[d]; i++)
                    {
                        yield return(topLeft + i * vecs[d]);
                    }
                }
            }
        }