Tiles() public static method

public static Tiles ( Actor a ) : IEnumerable
a Actor
return IEnumerable
Ejemplo n.º 1
0
        public FrozenUnderFog(ActorInitializer init, FrozenUnderFogInfo info)
        {
            this.info = info;

            var map = init.World.Map;

            // Spawned actors (e.g. building husks) shouldn't be revealed
            startsRevealed = info.StartsRevealed && !init.Contains <ParentActorInit>();
            var footprintCells = FootprintUtils.Tiles(init.Self).ToList();

            footprint = footprintCells.SelectMany(c => map.ProjectedCellsCovering(c.ToMPos(map))).ToArray();
        }
Ejemplo n.º 2
0
        public void RemoveSmudges()
        {
            var smudgeLayers = self.World.WorldActor.TraitsImplementing <SmudgeLayer>();

            foreach (var smudgeLayer in smudgeLayers)
            {
                foreach (var footprintTile in FootprintUtils.Tiles(self))
                {
                    smudgeLayer.RemoveSmudge(footprintTile);
                }
            }
        }
Ejemplo n.º 3
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)));
        }
Ejemplo n.º 4
0
        public FrozenUnderFog(ActorInitializer init, FrozenUnderFogInfo info)
        {
            this.info = info;

            var map = init.World.Map;

            // Spawned actors (e.g. building husks) shouldn't be revealed
            startsRevealed = info.StartsRevealed && !init.Contains <ParentActorInit>();
            var footprintCells = FootprintUtils.Tiles(init.Self).ToList();

            footprint = footprintCells.SelectMany(c => map.ProjectedCellsCovering(c.ToMPos(map))).ToArray();
            tooltip   = Exts.Lazy(() => init.Self.TraitsImplementing <ITooltip>().FirstOrDefault());
            health    = Exts.Lazy(() => init.Self.TraitOrDefault <Health>());
        }
Ejemplo n.º 5
0
        void UpdateNeighbours(Actor self)
        {
            var footprint = FootprintUtils.Tiles(self).ToArray();
            var adjacent  = Util.ExpandFootprint(footprint, true).Except(footprint)
                            .Where(self.World.Map.Contains).ToList();

            var adjacentActorTraits = adjacent.SelectMany(self.World.ActorMap.GetActorsAt)
                                      .SelectMany(a => a.TraitsImplementing <IWallConnector>());

            foreach (var rb in adjacentActorTraits)
            {
                rb.SetDirty();
            }
        }
Ejemplo n.º 6
0
        public FrozenUnderFog(ActorInitializer init, FrozenUnderFogInfo info)
        {
            this.info = info;

            var map = init.World.Map;

            // Explore map-placed actors if the "Explore Map" option is enabled
            var exploredMap = !init.World.LobbyInfo.GlobalSettings.Shroud;

            startsRevealed = exploredMap && init.Contains <SpawnedByMapInit>() && !init.Contains <HiddenUnderFogInit>();
            var footprintCells = FootprintUtils.Tiles(init.Self).ToList();

            footprint = footprintCells.SelectMany(c => map.ProjectedCellsCovering(c.ToMPos(map))).ToArray();
        }
Ejemplo n.º 7
0
        public FrozenUnderFog(ActorInitializer init, FrozenUnderFogInfo info)
        {
            // Spawned actors (e.g. building husks) shouldn't be revealed
            startsRevealed = info.StartsRevealed && !init.Contains <ParentActorInit>();
            var footprintCells = FootprintUtils.Tiles(init.Self).ToList();

            footprint       = footprintCells.Select(cell => cell.ToMPos(init.World.Map)).ToArray();
            footprintRegion = CellRegion.BoundingRegion(init.World.Map.TileShape, footprintCells);
            tooltip         = Exts.Lazy(() => init.Self.TraitsImplementing <IToolTip>().FirstOrDefault());
            health          = Exts.Lazy(() => init.Self.TraitOrDefault <Health>());

            frozen  = new Dictionary <Player, FrozenActor>();
            visible = init.World.Players.ToDictionary(p => p, p => false);
        }
Ejemplo n.º 8
0
        void Emit(Actor self)
        {
            if (!correctFaction)
            {
                return;
            }

            var csv    = self.Info.TraitInfoOrDefault <CustomSellValueInfo>();
            var valued = self.Info.TraitInfoOrDefault <ValuedInfo>();
            var cost   = csv != null ? csv.Value : (valued != null ? valued.Cost : 0);

            var health     = self.TraitOrDefault <Health>();
            var dudesValue = info.ValuePercent * cost / 100;

            if (health != null)
            {
                if (100 * health.HP >= info.MinHpPercent * health.MaxHP)
                {
                    dudesValue = health.HP * dudesValue / health.MaxHP;
                }
                else
                {
                    dudesValue = 0;
                }
            }

            var eligibleLocations = FootprintUtils.Tiles(self).ToList();
            var actorTypes        = info.ActorTypes.Select(a => new { Name = a, Cost = self.World.Map.Rules.Actors[a].TraitInfo <ValuedInfo>().Cost }).ToList();

            while (eligibleLocations.Count > 0 && actorTypes.Any(a => a.Cost <= dudesValue))
            {
                var at  = actorTypes.Where(a => a.Cost <= dudesValue).Random(self.World.SharedRandom);
                var loc = eligibleLocations.Random(self.World.SharedRandom);

                eligibleLocations.Remove(loc);
                dudesValue -= at.Cost;

                self.World.AddFrameEndTask(w => w.CreateActor(at.Name, new TypeDictionary
                {
                    new LocationInit(loc),
                    new OwnerInit(self.Owner),
                }));
            }
        }
Ejemplo n.º 9
0
        public BuildingInfluence(World world)
        {
            map = world.Map;

            influence = new CellLayer <Actor>(map);

            world.ActorAdded += a =>
            {
                var b = a.Info.TraitInfoOrDefault <BuildingInfo>();
                if (b == null)
                {
                    return;
                }

                foreach (var u in FootprintUtils.Tiles(map.Rules, a.Info.Name, b, a.Location))
                {
                    if (influence.Contains(u) && influence[u] == null)
                    {
                        influence[u] = a;
                    }
                }
            };

            world.ActorRemoved += a =>
            {
                var b = a.Info.TraitInfoOrDefault <BuildingInfo>();
                if (b == null)
                {
                    return;
                }

                foreach (var u in FootprintUtils.Tiles(map.Rules, a.Info.Name, b, a.Location))
                {
                    if (influence.Contains(u) && influence[u] == a)
                    {
                        influence[u] = null;
                    }
                }
            };
        }
Ejemplo n.º 10
0
        public bool IsCloseEnoughToBase(World world, Player p, string buildingName, CPos topLeft)
        {
            if (p.PlayerActor.Trait <DeveloperMode>().BuildAnywhere)
            {
                return(true);
            }

            if (RequiresBaseProvider && FindBaseProvider(world, p, topLeft) == null)
            {
                return(false);
            }

            var buildingMaxBounds = Dimensions;
            var buildingTraits    = world.Map.Rules.Actors[buildingName].Traits;

            if (buildingTraits.Contains <BibInfo>() && !buildingTraits.Get <BibInfo>().HasMinibib)
            {
                buildingMaxBounds += new CVec(0, 1);
            }

            var scanStart = world.Map.Clamp(topLeft - new CVec(Adjacent, Adjacent));
            var scanEnd   = world.Map.Clamp(topLeft + buildingMaxBounds + new CVec(Adjacent, Adjacent));

            var nearnessCandidates = new List <CPos>();
            var bi = world.WorldActor.Trait <BuildingInfluence>();
            var allyBuildRadius = world.LobbyInfo.GlobalSettings.AllyBuildRadius;

            for (var y = scanStart.Y; y < scanEnd.Y; y++)
            {
                for (var x = scanStart.X; x < scanEnd.X; x++)
                {
                    var pos = new CPos(x, y);

                    var buildingAtPos = bi.GetBuildingAt(pos);

                    if (buildingAtPos == null)
                    {
                        var unitsAtPos = world.ActorMap.GetUnitsAt(pos).Where(a => a.IsInWorld &&
                                                                              (a.Owner == p || (allyBuildRadius && a.Owner.Stances[p] == Stance.Ally)) &&
                                                                              a.HasTrait <GivesBuildableArea>());

                        if (unitsAtPos.Any())
                        {
                            nearnessCandidates.Add(pos);
                        }
                    }
                    else if (buildingAtPos.IsInWorld && buildingAtPos.HasTrait <GivesBuildableArea>() &&
                             (buildingAtPos.Owner == p || (allyBuildRadius && buildingAtPos.Owner.Stances[p] == Stance.Ally)))
                    {
                        nearnessCandidates.Add(pos);
                    }
                }
            }

            var buildingTiles = FootprintUtils.Tiles(world.Map.Rules, buildingName, this, topLeft).ToList();

            return(nearnessCandidates
                   .Any(a => buildingTiles
                        .Any(b => Math.Abs(a.X - b.X) <= Adjacent &&
                             Math.Abs(a.Y - b.Y) <= Adjacent)));
        }
Ejemplo n.º 11
0
 public override void AddedToWorld(Actor self)
 {
     base.AddedToWorld(self);
     blockedPositions = FootprintUtils.Tiles(self);
 }