public void GetTerrainDamage(WorldPosition worldPosition, out float totalDamageAbsolute, out float totalDamagePercentMax, out float totalDamagePercentCurrent)
    {
        totalDamageAbsolute       = 0f;
        totalDamagePercentMax     = 0f;
        totalDamagePercentCurrent = 0f;
        GridMap <District> map   = this.World.Atlas.GetMap(WorldAtlas.Maps.Districts) as GridMap <District>;
        District           value = map.GetValue(worldPosition);

        if (value != null && value.Type != DistrictType.Exploitation)
        {
            return;
        }
        byte         terrainType            = this.GetTerrainType(worldPosition);
        StaticString terrainTypeMappingName = this.GetTerrainTypeMappingName(terrainType);

        if (!StaticString.IsNullOrEmpty(terrainTypeMappingName))
        {
            IDatabase <TerrainTypeMapping> database           = Databases.GetDatabase <TerrainTypeMapping>(false);
            TerrainTypeMapping             terrainTypeMapping = null;
            if (database.TryGetValue(terrainTypeMappingName, out terrainTypeMapping) && terrainTypeMapping != null)
            {
                for (int i = 0; i < terrainTypeMapping.Layers.Length; i++)
                {
                    if (terrainTypeMapping.Layers[i].Type.Equals("Damage") && terrainTypeMapping.Layers[i].Name.Equals("OnEnter"))
                    {
                        for (int j = 0; j < terrainTypeMapping.Layers[i].Samples.Length; j++)
                        {
                            int   weight = terrainTypeMapping.Layers[i].Samples[j].Weight;
                            float num    = float.Parse(terrainTypeMapping.Layers[i].Samples[j].Value);
                            if (weight == 0)
                            {
                                totalDamageAbsolute += num;
                            }
                            else if (weight == 1)
                            {
                                totalDamagePercentMax += num;
                            }
                            else if (weight == 2)
                            {
                                totalDamagePercentCurrent += num;
                            }
                        }
                    }
                }
            }
        }
    }
Example #2
0
    private bool IsAreaVolcanoformed(WorldPosition areaCenter)
    {
        World       world       = base.Game.World;
        WorldCircle worldCircle = new WorldCircle(areaCenter, 1);

        WorldPosition[]      worldPositions = worldCircle.GetWorldPositions(this.WorldPositionningService.World.WorldParameters);
        List <WorldPosition> list           = new List <WorldPosition>(worldPositions);

        for (int i = list.Count - 1; i >= 0; i--)
        {
            TerrainTypeMapping terrainTypeMapping = null;
            if (world.TryGetTerraformMapping(worldPositions[i], out terrainTypeMapping))
            {
                return(false);
            }
        }
        return(true);
    }
    protected override IEnumerator OnShow(params object[] parameters)
    {
        IPlayerControllerRepositoryService playerControllerRepositoryService = base.Game.Services.GetService <IPlayerControllerRepositoryService>();

        this.ResetPropertyValues();
        WorldPosition worldPosition = (WorldPosition)this.context;

        this.stringBuilder.Length = 0;
        if (worldPosition.IsValid)
        {
            World                world             = ((global::Game)base.GameService.Game).World;
            WorldCircle          worldCircle       = new WorldCircle(worldPosition, 1);
            WorldPosition[]      worldPositions    = worldCircle.GetWorldPositions(this.worldPositionningService.World.WorldParameters);
            List <WorldPosition> filteredPositions = new List <WorldPosition>(worldPositions);
            for (int positionIndex = filteredPositions.Count - 1; positionIndex >= 0; positionIndex--)
            {
                TerrainTypeMapping terrainTypeMapping = null;
                if (!world.TryGetTerraformMapping(worldPositions[positionIndex], out terrainTypeMapping))
                {
                    filteredPositions.RemoveAt(positionIndex);
                }
            }
            for (int index = 0; index < filteredPositions.Count; index++)
            {
                this.FillWorldPositionEffects(playerControllerRepositoryService.ActivePlayerController.Empire, filteredPositions[index], false);
            }
            this.FillOutputString(ref this.stringBuilder);
            this.OldResult.Text = this.stringBuilder.ToString();
            this.ResetPropertyValues();
            this.stringBuilder.Length = 0;
            for (int index2 = 0; index2 < filteredPositions.Count; index2++)
            {
                this.FillWorldPositionEffects(playerControllerRepositoryService.ActivePlayerController.Empire, filteredPositions[index2], true);
            }
            this.FillOutputString(ref this.stringBuilder);
            this.NewResult.Text = this.stringBuilder.ToString();
            this.OldResultNotAffected.Visible = (filteredPositions.Count == 0);
            this.NewResultNotAffected.Visible = (filteredPositions.Count == 0);
        }
        yield return(base.OnShow(parameters));

        yield break;
    }
    public bool IsConstructible(WorldPosition position, int bits = 0)
    {
        byte         terrainType            = this.GetTerrainType(position);
        StaticString terrainTypeMappingName = this.GetTerrainTypeMappingName(terrainType);

        if (!StaticString.IsNullOrEmpty(terrainTypeMappingName))
        {
            TerrainTypeMapping terrainTypeMapping = null;
            if (this.terrainTypeMappingDatabase != null && this.terrainTypeMappingDatabase.TryGetValue(terrainTypeMappingName, out terrainTypeMapping) && terrainTypeMapping.Layers != null && terrainTypeMapping.Layers.Length > 0)
            {
                for (int i = 0; i < terrainTypeMapping.Layers.Length; i++)
                {
                    if (terrainTypeMapping.Layers[i].Type == WorldPositionning.LayerTypeConstruction && terrainTypeMapping.Layers[i].Name == WorldPositionning.LayerNameNotConstructible)
                    {
                        return(false);
                    }
                }
            }
        }
        GridMap <bool> gridMap = this.World.Atlas.GetMap(WorldAtlas.Maps.Ridges) as GridMap <bool>;

        return((gridMap == null || !gridMap.GetValue(position)) && !this.PillarService.IsPositionOccupiedByAPillar(position));
    }
    public bool IsExploitable(WorldPosition position, int bits = 0)
    {
        byte         terrainType            = this.GetTerrainType(position);
        StaticString terrainTypeMappingName = this.GetTerrainTypeMappingName(terrainType);

        if (!StaticString.IsNullOrEmpty(terrainTypeMappingName))
        {
            TerrainTypeMapping terrainTypeMapping = null;
            if (this.terrainTypeMappingDatabase != null && this.terrainTypeMappingDatabase.TryGetValue(terrainTypeMappingName, out terrainTypeMapping) && terrainTypeMapping.Layers != null && terrainTypeMapping.Layers.Length > 0)
            {
                for (int i = 0; i < terrainTypeMapping.Layers.Length; i++)
                {
                    if (terrainTypeMapping.Layers[i].Type == WorldPositionning.LayerTypeConstruction && terrainTypeMapping.Layers[i].Name == WorldPositionning.LayerNameNotExploitable)
                    {
                        return(false);
                    }
                }
            }
        }
        GridMap <bool> gridMap = this.World.Atlas.GetMap(WorldAtlas.Maps.Ridges) as GridMap <bool>;

        if (gridMap != null && gridMap.GetValue(position))
        {
            return(false);
        }
        Region region = this.GetRegion(position);

        if (region != null && region.PointOfInterests != null)
        {
            int j = 0;
            while (j < region.PointOfInterests.Length)
            {
                PointOfInterest pointOfInterest = region.PointOfInterests[j];
                if (pointOfInterest.WorldPosition != position)
                {
                    j++;
                }
                else
                {
                    Diagnostics.Assert(pointOfInterest != null);
                    Diagnostics.Assert(pointOfInterest.PointOfInterestDefinition != null);
                    Diagnostics.Assert(pointOfInterest.PointOfInterestDefinition.PointOfInterestTemplate != null);
                    if (WorldPositionning.NonConvertedVillagesArentExploitable && pointOfInterest.Type == "Village")
                    {
                        if (!pointOfInterest.SimulationObject.Tags.Contains(BarbarianCouncil.VillageStatusConverted) && pointOfInterest.CreepingNodeGUID == GameEntityGUID.Zero)
                        {
                            return(false);
                        }
                        IGameEntity gameEntity;
                        if (pointOfInterest.CreepingNodeGUID != GameEntityGUID.Zero && this.GameEntityRepositoryService.TryGetValue(pointOfInterest.CreepingNodeGUID, out gameEntity))
                        {
                            CreepingNode creepingNode = gameEntity as CreepingNode;
                            if (creepingNode.IsUnderConstruction)
                            {
                                return(false);
                            }
                        }
                    }
                    string text;
                    if (pointOfInterest.PointOfInterestDefinition.PointOfInterestTemplate.Properties != null && pointOfInterest.PointOfInterestDefinition.PointOfInterestTemplate.Properties.TryGetValue(WorldPositionning.PreventsDistrictTypeExploitationConstruction, out text))
                    {
                        return(false);
                    }
                    break;
                }
            }
        }
        return(true);
    }