Beispiel #1
0
        public static bool IsCellBuildable(this World world, CPos a, BuildingInfo bi, Actor toIgnore)
        {
            if (world.WorldActor.Trait<BuildingInfluence>().GetBuildingAt(a) != null) return false;
            if (world.ActorMap.GetUnitsAt(a).Any(b => b != toIgnore)) return false;

            return world.Map.IsInMap(a) && bi.TerrainTypes.Contains(world.GetTerrainType(a));
        }
Beispiel #2
0
 public Transforms(ActorInitializer init, TransformsInfo info)
 {
     self = init.Self;
     this.info = info;
     buildingInfo = self.World.Map.Rules.Actors[info.IntoActor].Traits.GetOrDefault<BuildingInfo>();
     race = init.Contains<RaceInit>() ? init.Get<RaceInit, string>() : self.Owner.Country.Race;
 }
Beispiel #3
0
 public static bool CanPlaceBuilding(this World world, string name, BuildingInfo building, CPos topLeft, Actor toIgnore)
 {
     var res = world.WorldActor.Trait<ResourceLayer>();
     return FootprintUtils.Tiles(name, building, topLeft).All(
         t => world.Map.IsInMap(t.X, t.Y) && res.GetResource(t) == null &&
             world.IsCellBuildable(t, building, toIgnore));
 }
Beispiel #4
0
 public Building(Actor self)
 {
     this.self = self;
     Info = self.Info.Traits.Get<BuildingInfo>();
     self.CenterLocation = Game.CellSize
         * ((float2)self.Location + .5f * (float2)Info.Dimensions);
 }
Beispiel #5
0
 public static bool CanPlaceBuilding(this World world, string name, BuildingInfo building, int2 topLeft, Actor toIgnore)
 {
     var res = world.WorldActor.traits.Get<ResourceLayer>();
     return !Footprint.Tiles(name, building, topLeft).Any(
         t => !world.Map.IsInMap(t.X, t.Y) || res.GetResource(t) != null || !world.IsCellBuildable(t,
             building.WaterBound, toIgnore));
 }
        public PlaceBuildingOrderGenerator(ProductionQueue queue, string name)
        {
            var world = queue.Actor.World;
            this.queue = queue;
            placeBuildingInfo = queue.Actor.Owner.PlayerActor.Info.TraitInfo<PlaceBuildingInfo>();
            building = name;

            // Clear selection if using Left-Click Orders
            if (Game.Settings.Game.UseClassicMouseStyle)
                world.Selection.Clear();

            var map = world.Map;
            var tileset = world.Map.Tileset.ToLowerInvariant();

            var info = map.Rules.Actors[building];
            buildingInfo = info.TraitInfo<BuildingInfo>();

            var buildableInfo = info.TraitInfo<BuildableInfo>();
            var mostLikelyProducer = queue.MostLikelyProducer();
            faction = buildableInfo.ForceFaction
                ?? (mostLikelyProducer.Trait != null ? mostLikelyProducer.Trait.Faction : queue.Actor.Owner.Faction.InternalName);

            buildOk = map.Rules.Sequences.GetSequence("overlay", "build-valid-{0}".F(tileset)).GetSprite(0);
            buildBlocked = map.Rules.Sequences.GetSequence("overlay", "build-invalid").GetSprite(0);

            buildingInfluence = world.WorldActor.Trait<BuildingInfluence>();
        }
Beispiel #7
0
 public Transforms(ActorInitializer init, TransformsInfo info)
 {
     self = init.Self;
     this.info = info;
     buildingInfo = self.World.Map.Rules.Actors[info.IntoActor].TraitInfoOrDefault<BuildingInfo>();
     faction = init.Contains<FactionInit>() ? init.Get<FactionInit, string>() : self.Owner.Faction.InternalName;
 }
Beispiel #8
0
 public Building(ActorInitializer init)
 {
     this.self = init.self;
     this.topLeft = init.Get<LocationInit,int2>();
     Info = self.Info.Traits.Get<BuildingInfo>();
     self.CenterLocation = Game.CellSize
         * ((float2)topLeft + .5f * (float2)Info.Dimensions);
 }
Beispiel #9
0
		public static bool CanPlaceBuilding(this World world, string name, BuildingInfo building, CPos topLeft, Actor toIgnore)
		{
			if (building.AllowInvalidPlacement)
				return true;

			var res = world.WorldActor.Trait<ResourceLayer>();
			return FootprintUtils.Tiles(world.Map.Rules, name, building, topLeft).All(
				t => world.Map.Contains(t) && res.GetResource(t) == null &&
					world.IsCellBuildable(t, building, toIgnore));
		}
        public PlaceBuildingOrderGenerator(Actor producer, string name)
        {
            Producer = producer;
            Building = name;
            BuildingInfo = Rules.Info[Building].Traits.Get<BuildingInfo>();

            Preview = Rules.Info[Building].Traits.Get<RenderBuildingInfo>()
                                .RenderPreview(Rules.Info[Building], producer.Owner);

            buildOk = SequenceProvider.GetSequence("overlay", "build-valid").GetSprite(0);
            buildBlocked = SequenceProvider.GetSequence("overlay", "build-invalid").GetSprite(0);
        }
Beispiel #11
0
        public static IEnumerable<int2> Tiles( string name, BuildingInfo buildingInfo, int2 topLeft )
        {
            var dim = buildingInfo.Dimensions;

            var footprint = buildingInfo.Footprint.Where(x => !char.IsWhiteSpace(x));
            if (buildingInfo.Bib)
            {
                dim.Y += 1;
                footprint = footprint.Concat(new char[dim.X]);
            }

            return TilesWhere( name, dim, footprint.ToArray(), a => a != '_' ).Select( t => t + topLeft );
        }
Beispiel #12
0
		public static bool IsCellBuildable(this World world, CPos cell, BuildingInfo bi, Actor toIgnore = null)
		{
			if (!world.Map.Contains(cell))
				return false;

			if (world.WorldActor.Trait<BuildingInfluence>().GetBuildingAt(cell) != null)
				return false;

			if (!bi.AllowInvalidPlacement && world.ActorMap.GetActorsAt(cell).Any(a => a != toIgnore))
				return false;

			var tile = world.Map.MapTiles.Value[cell];
			var tileInfo = world.TileSet.GetTileInfo(tile);

			// TODO: This is bandaiding over bogus tilesets.
			if (tileInfo != null && tileInfo.RampType > 0)
				return false;

			return bi.TerrainTypes.Contains(world.Map.GetTerrainInfo(cell).Type);
		}
Beispiel #13
0
		public static IEnumerable<CPos> GetLineBuildCells(World world, CPos location, string name, BuildingInfo bi)
		{
			var lbi = world.Map.Rules.Actors[name].TraitInfo<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 (var d = 0; d < 4; d++)
			{
				for (var 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.TraitInfo<LineBuildNodeInfo>()
						.Types.Overlaps(lbi.NodeTypes))))
						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 (var i = 1; i < dirs[d]; i++)
						yield return topLeft + i * vecs[d];
			}
		}
Beispiel #14
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.WaterBound))
                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.WaterBound))
                        continue; // Cell is empty; continue search

                    // Cell contains an actor. Is it the type we want?
                    if (Game.world.Queries.WithTrait<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];
            }
        }
Beispiel #15
0
 public static IEnumerable<int2> UnpathableTiles( string name, BuildingInfo buildingInfo, int2 position )
 {
     var footprint = buildingInfo.Footprint.Where( x => !char.IsWhiteSpace( x ) ).ToArray();
     foreach( var tile in TilesWhere( name, buildingInfo.Dimensions, footprint, a => a == 'x' ) )
         yield return tile + position;
 }
Beispiel #16
0
 public static int2 AdjustForBuildingSize( BuildingInfo buildingInfo )
 {
     var dim = buildingInfo.Dimensions;
     return new int2( dim.X / 2, dim.Y > 1 ? ( dim.Y + 1 ) / 2 : 0 );
 }
Beispiel #17
0
 public Transforms(Actor self, TransformsInfo info)
 {
     this.self = self;
     Info = info;
     bi = Rules.Info[info.IntoActor].Traits.GetOrDefault<BuildingInfo>();
 }
Beispiel #18
0
        public void DrawBuildingGrid( World world, string name, BuildingInfo bi )
        {
            var position = Game.controller.MousePosition.ToInt2();
            var topLeft = position - Footprint.AdjustForBuildingSize( bi );

            // Linebuild for walls.
            // Assumes a 1x1 footprint; weird things will happen for other footprints
            if (Rules.Info[name].Traits.Contains<LineBuildInfo>())
            {
                foreach (var t in LineBuildUtils.GetLineBuildCells(world, topLeft, name, bi))
                    spriteRenderer.DrawSprite(world.IsCloseEnoughToBase(world.LocalPlayer, name, bi, t)
                        ? buildOk : buildBlocked, Game.CellSize * t, "terrain");
            }
            else
            {
                var res = world.WorldActor.traits.Get<ResourceLayer>();
                var isCloseEnough = world.IsCloseEnoughToBase(world.LocalPlayer, name, bi, topLeft);
                foreach (var t in Footprint.Tiles(name, bi, topLeft))
                    spriteRenderer.DrawSprite((isCloseEnough && world.IsCellBuildable(t, bi.WaterBound) && res.GetResource(t) == null)
                        ? buildOk : buildBlocked, Game.CellSize * t, "terrain");
            }

            spriteRenderer.Flush();
        }
Beispiel #19
0
		bool IsRallyPointValid(CPos x, BuildingInfo info)
		{
			return info != null && World.IsCellBuildable(x, info);
		}
Beispiel #20
0
 public Transforms(TransformsInfo info)
 {
     Info = info;
     bi = Rules.Info[info.IntoActor].Traits.GetOrDefault<BuildingInfo>();
 }
Beispiel #21
0
        public static bool IsCloseEnoughToBase(this World world, Player p, string buildingName, BuildingInfo bi, int2 topLeft)
        {
            var buildingMaxBounds = bi.Dimensions;
            if( bi.Bib )
                buildingMaxBounds.Y += 1;

            var scanStart = world.ClampToWorld( topLeft - new int2( bi.Adjacent, bi.Adjacent ) );
            var scanEnd = world.ClampToWorld( topLeft + buildingMaxBounds + new int2( bi.Adjacent, bi.Adjacent ) );

            var nearnessCandidates = new List<int2>();

            for( int y = scanStart.Y ; y < scanEnd.Y ; y++ )
            {
                for( int x = scanStart.X ; x < scanEnd.X ; x++ )
                {
                    var at = world.WorldActor.traits.Get<BuildingInfluence>().GetBuildingAt( new int2( x, y ) );
                    if( at != null && at.Owner == p && at.Info.Traits.Get<BuildingInfo>().BaseNormal)
                        nearnessCandidates.Add( new int2( x, y ) );
                }
            }
            var buildingTiles = Footprint.Tiles( buildingName, bi, topLeft ).ToList();
            return nearnessCandidates
                .Any( a => buildingTiles
                    .Any( b => Math.Abs( a.X - b.X ) <= bi.Adjacent
                            && Math.Abs( a.Y - b.Y ) <= bi.Adjacent ) );
        }
Beispiel #22
0
 public static bool IsCellBuildable(this World world, CPos a, BuildingInfo bi)
 {
     return world.IsCellBuildable(a, bi, null);
 }