Пример #1
0
        public ResourceLayer(Actor self)
        {
            world             = self.World;
            buildingInfluence = self.Trait <BuildingInfluence>();

            Content = new CellLayer <ResourceLayerContents>(world.Map);
        }
        public PlaceBuildingOrderGenerator(ProductionQueue queue, string name)
        {
            producer = queue.Actor;
            placeBuildingInfo = producer.Owner.PlayerActor.Info.Traits.Get<PlaceBuildingInfo>();
            building = name;

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

            var map = producer.World.Map;
            var tileset = producer.World.TileSet.Id.ToLowerInvariant();

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

            var buildableInfo = info.Traits.Get<BuildableInfo>();
            var mostLikelyProducer = queue.MostLikelyProducer();
            race = buildableInfo.ForceRace ?? (mostLikelyProducer.Trait != null ? mostLikelyProducer.Trait.Race : producer.Owner.Faction.InternalName);

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

            buildingInfluence = producer.World.WorldActor.Trait<BuildingInfluence>();
        }
Пример #3
0
        public ResourceLayer(Actor self)
        {
            world             = self.World;
            buildingInfluence = self.Trait <BuildingInfluence>();

            Content       = new CellLayer <CellContents>(world.Map);
            RenderContent = new CellLayer <CellContents>(world.Map);

            RenderContent.CellEntryChanged += UpdateSpriteLayers;
        }
Пример #4
0
 public ResourceLayer(Actor self, ResourceLayerInfo info)
 {
     this.info            = info;
     world                = self.World;
     Map                  = world.Map;
     BuildingInfluence    = self.Trait <BuildingInfluence>();
     Content              = new CellLayer <ResourceLayerContents>(Map);
     ResourceTypesByIndex = info.ResourceTypes.ToDictionary(
         kv => kv.Value.ResourceIndex,
         kv => kv.Key);
 }
Пример #5
0
        public ResourceLayer(Actor self)
        {
            world             = self.World;
            buildingInfluence = self.Trait <BuildingInfluence>();

            Content       = new CellLayer <CellContents>(world.Map);
            RenderContent = new CellLayer <CellContents>(world.Map);

            // этот метод обновл¤ет TerrainSpriteLayer, через данное событие.
            //RenderContent.CellEntryChanged += SubmitCellToVertexBuffer;
        }
Пример #6
0
        public Building(ActorInitializer init, BuildingInfo info)
        {
            self      = init.Self;
            topLeft   = init.Get <LocationInit, CPos>();
            Info      = info;
            influence = self.World.WorldActor.Trait <BuildingInfluence>();

            occupiedCells = Info.UnpathableTiles(TopLeft)
                            .Select(c => Pair.New(c, SubCell.FullCell)).ToArray();

            targetableCells = Info.FootprintTiles(TopLeft, FootprintCellType.Occupied)
                              .Select(c => Pair.New(c, SubCell.FullCell)).ToArray();

            CenterPosition = init.World.Map.CenterOfCell(topLeft) + Info.CenterOffset(init.World);
        }
Пример #7
0
        public void WorldLoaded(World w, WorldRenderer wr)
        {
            this.world = w;

            buildingInfluence = world.WorldActor.Trait <BuildingInfluence>();

            content = new CellLayer <CellContents>(w.Map);
            render  = new CellLayer <CellContents>(w.Map);
            dirty   = new List <CPos>();

            var resources = w.WorldActor.TraitsImplementing <ResourceType>()
                            .ToDictionary(r => r.Info.ResourceType, r => r);

            foreach (var cell in w.Map.Cells)
            {
                ResourceType t;
                if (!resources.TryGetValue(w.Map.MapResources.Value[cell].Type, out t))
                {
                    continue;
                }

                if (!AllowResourceAt(t, cell))
                {
                    continue;
                }

                content[cell] = CreateResourceCell(t, cell);
            }

            // Set initial density based on the number of neighboring resources
            foreach (var cell in w.Map.Cells)
            {
                var type = content[cell].Type;
                if (type != null)
                {
                    // Adjacent includes the current cell, so is always >= 1
                    var adjacent = GetAdjacentCellsWith(type, cell);
                    var density  = int2.Lerp(0, type.Info.MaxDensity, adjacent, 9);
                    var temp     = content[cell];
                    temp.Density = Math.Max(density, 1);

                    render[cell] = content[cell] = temp;
                    UpdateRenderedSprite(cell);
                }
            }
        }