private void UpdateWeatherEffectAtPosition(WorldPosition worldPosition, Army army, bool apply) { WeatherDefinition weatherDefinitionAtPosition = this.GetWeatherDefinitionAtPosition(worldPosition); if (weatherDefinitionAtPosition == null) { return; } if (weatherDefinitionAtPosition.SimulationDescriptorReferences == null) { return; } if (apply) { for (int i = 0; i < weatherDefinitionAtPosition.SimulationDescriptorReferences.Length; i++) { SimulationDescriptor simulationDescriptor; if (this.simulationDescriptorsDatabase.TryGetValue(weatherDefinitionAtPosition.SimulationDescriptorReferences[i].Name, out simulationDescriptor) && !army.SimulationObject.Tags.Contains(simulationDescriptor.Name)) { army.AddDescriptor(simulationDescriptor, false); } } } else { for (int j = 0; j < weatherDefinitionAtPosition.SimulationDescriptorReferences.Length; j++) { army.RemoveDescriptorByName(weatherDefinitionAtPosition.SimulationDescriptorReferences[j].Name); } } army.Refresh(false); }
public byte GetWeatherValueAtPosition(WorldPosition worldPosition) { if (this.weatherMap == null || !worldPosition.IsValid) { return(0); } if (!this.GetMayAffectedByWeather(worldPosition)) { return(0); } byte value = this.staticWeatherMap.GetValue((int)worldPosition.Row, (int)worldPosition.Column); if (value != 0) { WeatherDefinition weatherDefinition = this.GetWeatherDefinition(value); if (this.GetTerrainCompatibilityAtPosition(weatherDefinition, worldPosition)) { return(value); } } byte b = this.weatherMap.GetValue((int)worldPosition.Row, (int)worldPosition.Column); if (b != 0) { WeatherDefinition weatherDefinition2 = this.GetWeatherDefinition(b); if (weatherDefinition2 != null && !this.GetTerrainCompatibilityAtPosition(weatherDefinition2, worldPosition)) { b = 0; } } return(b); }
public bool IsWorldPositionObstructingVision(WorldPosition observerPosition, WorldPosition tilePosition, int observerHeight, bool ignoreFog) { if (!observerPosition.IsValid || !tilePosition.IsValid) { return(true); } Diagnostics.Assert(this.elevationMap != null); if ((int)observerPosition.Row >= this.elevationMap.Height || (int)observerPosition.Column >= this.elevationMap.Width || (int)tilePosition.Row >= this.elevationMap.Height || (int)tilePosition.Column >= this.elevationMap.Width) { return(true); } sbyte b = this.elevationMap.GetValue(tilePosition); PathfindingMovementCapacity tileMovementCapacity = this.pathfindingService.GetTileMovementCapacity(observerPosition, (PathfindingFlags)0); bool flag = tileMovementCapacity == PathfindingMovementCapacity.Water || tileMovementCapacity == PathfindingMovementCapacity.FrozenWater; sbyte b2 = (!flag) ? this.elevationMap.GetValue(observerPosition) : this.waterHeightMap.GetValue(observerPosition); if (this.ridgeMap.GetValue(tilePosition)) { b = (sbyte)((int)b + (int)this.ridgeHeight); } IWorldPositionningService service = base.Game.GetService <IWorldPositionningService>(); if (service == null) { return(false); } Region region = service.GetRegion(tilePosition); if (region != null && region.IsWasteland) { b = (sbyte)((int)b + (int)this.wastelandHeight); } if ((int)b - (int)b2 > observerHeight) { return(true); } if (service.GetDistance(tilePosition, observerPosition) <= 1) { return(false); } if (this.weatherService == null) { return(false); } if (region != null && region.IsOcean && !ignoreFog) { WeatherDefinition weatherDefinitionAtPosition = this.weatherService.GetWeatherDefinitionAtPosition(tilePosition); if (weatherDefinitionAtPosition != null && weatherDefinitionAtPosition.ObstructVisibility) { return(true); } } return(false); }
public void OverridePathfindingCost(WorldPosition worldPosition, PathfindingMovementCapacity movementCapacity, ref float cost) { int weatherValueAtPosition = (int)this.GetWeatherValueAtPosition(worldPosition); if (weatherValueAtPosition == 0) { return; } WeatherDefinition weatherDefinition = null; for (int i = 0; i < this.weatherDefinitions.Length; i++) { if (this.weatherDefinitions[i].Value == weatherValueAtPosition) { weatherDefinition = this.weatherDefinitions[i]; break; } } if (weatherDefinition == null) { Diagnostics.LogError("In OverrideCostByWeatherEffectsPathfindingRule, Fail getting weather definition."); return; } PathfindingRule rule = weatherDefinition.GetRule(); if (rule == null) { return; } if ((movementCapacity & PathfindingMovementCapacity.Water) == PathfindingMovementCapacity.None) { cost = float.PositiveInfinity; } else { int currentTileHeigh = (int)this.worldPositionService.GetTerrainHeight(worldPosition); cost = rule.GetCost(movementCapacity, currentTileHeigh); } }
public bool GetTerrainCompatibilityAtPosition(WeatherDefinition weatherDefinition, WorldPosition worldPosition) { if (weatherDefinition.TerrainTypeMappings != null && weatherDefinition.TerrainTypeMappings.Length > 0) { byte terrainType = this.worldPositionService.GetTerrainType(worldPosition); StaticString terrainTypeMappingName = this.worldPositionService.GetTerrainTypeMappingName(terrainType); bool flag = false; for (int i = 0; i < weatherDefinition.TerrainTypeMappings.Length; i++) { if (terrainTypeMappingName.Equals(weatherDefinition.TerrainTypeMappings[i])) { flag = true; break; } } if (!flag) { return(false); } } return(this.pathfindingService.IsTileStopable(worldPosition, PathfindingMovementCapacity.All, (PathfindingFlags)0)); }
private void RunGenerationForWeather(WeatherDefinition weatherDefinition, int seed, string presetName) { string currentSeasonType; if (!string.IsNullOrEmpty(presetName)) { currentSeasonType = presetName; } else { currentSeasonType = this.seasonService.GetCurrentSeason().SeasonDefinition.SeasonType; } if (string.IsNullOrEmpty(currentSeasonType)) { Diagnostics.LogError("currentSeasonType can't be null or empty"); return; } WeatherDefinition.Preferences preferences = weatherDefinition.GameSettingsPreferences.First((WeatherDefinition.Preferences pref) => pref.SeasonType == currentSeasonType && pref.GameDifficulty == this.weatherDifficulty); if (preferences == null) { Diagnostics.LogWarning("No preferences were found corresponding to season type and game difficulty"); return; } float num = preferences.Threshold; WeatherDefinition.Preferences.PreferencesOverride[] overrides = preferences.Overrides; if (overrides != null && overrides.Length > 0) { string seasonIntensityName = this.seasonService.GetSeasonIntensityName(); if (!string.IsNullOrEmpty(seasonIntensityName)) { num *= this.GetWeatherThresholdMultiplier(preferences, seasonIntensityName); } } if (num > 1f || preferences.Priority <= 0f) { return; } NoiseHelper.BufferGenerationData bufferGenerationData = preferences.BufferGenerationData; NoiseHelper.ApplyRandomOffsetToBufferGenerationData(seed, ref bufferGenerationData); Vector2 mapSize = new Vector2((float)this.weatherMap.Width, (float)this.weatherMap.Height); for (int i = 0; i < this.weatherMap.Height; i++) { for (int j = 0; j < this.weatherMap.Width; j++) { Vector2 uv = new Vector2((float)j / mapSize.x, (float)i / mapSize.y); float num2 = NoiseHelper.GetNoiseCyclicMap(uv, bufferGenerationData, mapSize); if (num2 >= num) { num2 *= preferences.Priority; if (weatherDefinition.AffectedByWind) { if (num2 > this.tempData.GetValue(i, j)) { this.tempData.SetValue(i, j, num2); this.weatherMap.SetValue(i, j, (byte)weatherDefinition.Value); } } else if (num2 > this.staticTempData.GetValue(i, j)) { this.staticTempData.SetValue(i, j, num2); this.staticWeatherMap.SetValue(i, j, (byte)weatherDefinition.Value); } } } } }