private void UpdateHarassingScore(global::Empire empire) { DepartmentOfTheInterior agency = empire.GetAgency <DepartmentOfTheInterior>(); if (!this.departmentOfForeignAffairs.IsEnnemy(empire)) { return; } float num = 0.5f; if (this.departmentOfForeignAffairs.IsAtWarWith(empire)) { num = 1f; } for (int i = 0; i < agency.Cities.Count; i++) { AIRegionData regionData = this.worldAtlasAIHelper.GetRegionData(base.AIEntity.Empire.Index, agency.Cities[i].Region.Index); float num2 = regionData.MinimalDistanceToMyCities / this.averageMaximumMovementPoint; float num3 = (0.5f - Mathf.Clamp01(num2 / 10f)) / 0.5f; int num4 = regionData.WatchTowerPointOfInterestCount + regionData.ResourcePointOfInterestCount; float num5 = 0f; if (num4 > 0) { num5 = (float)(regionData.BuiltWatchTower + regionData.BuiltExtractor) / (float)num4; } float num6 = 0f; float num7 = 10f; if ((float)regionData.LostByMeAtTurn > (float)this.endTurnService.Turn - num7) { num6 = 1f - (float)(this.endTurnService.Turn - regionData.LostByMeAtTurn) / num7; } float num8 = 0f; num8 = AILayer.Boost(num8, num5 * 0.2f); num8 = AILayer.Boost(num8, num6 * 0.3f); num8 = AILayer.Boost(num8, num3 * 0.5f); num8 = AILayer.Boost(num8, num * 0.5f); regionData.HarassingScore = num8; } }
protected override void RefreshObjectives(StaticString context, StaticString pass) { base.RefreshObjectives(context, pass); AILayer_Military layer = base.AIEntity.GetLayer <AILayer_Military>(); base.GlobalPriority.Reset(); AILayer_Strategy layer2 = base.AIEntity.GetLayer <AILayer_Strategy>(); base.GlobalPriority.Add(layer2.StrategicNetwork.GetAgentValue("InternalMilitary"), "Strategic network 'InternalMilitary'", new object[0]); base.GlobalPriority.Boost(-0.5f, "Avoid patrol to be high", new object[0]); base.GatherObjectives(AICommanderMissionDefinition.AICommanderCategory.Patrol.ToString(), ref this.patrolObjectives); base.ValidateMessages(ref this.patrolObjectives); if (base.AIEntity.Empire is MajorEmpire) { MajorEmpire majorEmpire = base.AIEntity.Empire as MajorEmpire; for (int i = 0; i < majorEmpire.ConvertedVillages.Count; i++) { Village village = majorEmpire.ConvertedVillages[i]; if (this.worldAtlasHelper.IsRegionExplored(base.AIEntity.Empire, village.Region, 0.95f)) { GlobalObjectiveMessage globalObjectiveMessage = this.patrolObjectives.Find((GlobalObjectiveMessage match) => match.RegionIndex == village.Region.Index); if (globalObjectiveMessage == null) { globalObjectiveMessage = base.GenerateObjective(village.Region.Index); this.patrolObjectives.Add(globalObjectiveMessage); } globalObjectiveMessage.TimeOut = 1; globalObjectiveMessage.GlobalPriority = base.GlobalPriority; HeuristicValue heuristicValue = new HeuristicValue(0f); heuristicValue.Add(layer.GetVillageUnitPriority(village, village.StandardUnits.Count), "Village unit priority", new object[0]); globalObjectiveMessage.LocalPriority = heuristicValue; } } for (int j = 0; j < majorEmpire.TamedKaijus.Count; j++) { Kaiju kaiju = majorEmpire.TamedKaijus[j]; if (kaiju.OnGarrisonMode()) { GlobalObjectiveMessage globalObjectiveMessage2 = this.patrolObjectives.Find((GlobalObjectiveMessage match) => match.RegionIndex == kaiju.Region.Index); if (globalObjectiveMessage2 == null) { globalObjectiveMessage2 = base.GenerateObjective(kaiju.Region.Index); this.patrolObjectives.Add(globalObjectiveMessage2); } globalObjectiveMessage2.TimeOut = 1; globalObjectiveMessage2.GlobalPriority = base.GlobalPriority; HeuristicValue heuristicValue2 = new HeuristicValue(0.6f); AIRegionData regionData = this.worldAtlasHelper.GetRegionData(base.AIEntity.Empire.Index, kaiju.Region.Index); if (regionData != null) { float operand = Mathf.Min(1f, 0.1f * (float)regionData.BorderWithNeutral + 0.2f * (float)regionData.BorderWithEnnemy); heuristicValue2.Boost(operand, "Border with enemy!", new object[0]); } globalObjectiveMessage2.LocalPriority = heuristicValue2; } } } for (int k = 0; k < this.departmentOfTheInterior.Cities.Count; k++) { City city = this.departmentOfTheInterior.Cities[k]; if (this.worldAtlasHelper.IsRegionExplored(base.AIEntity.Empire, city.Region, 0.8f)) { GlobalObjectiveMessage globalObjectiveMessage3 = this.patrolObjectives.Find((GlobalObjectiveMessage match) => match.RegionIndex == city.Region.Index); if (globalObjectiveMessage3 == null) { globalObjectiveMessage3 = base.GenerateObjective(city.Region.Index); this.patrolObjectives.Add(globalObjectiveMessage3); } globalObjectiveMessage3.TimeOut = 1; globalObjectiveMessage3.GlobalPriority = base.GlobalPriority; HeuristicValue heuristicValue3 = new HeuristicValue(0f); heuristicValue3.Add(AILayer_Military.GetCityDefenseLocalPriority(city, this.unitRatioBoost, 0), "City defense local priority", new object[0]); globalObjectiveMessage3.LocalPriority = heuristicValue3; } } if (base.AIEntity.Empire is MajorEmpire) { using (List <int> .Enumerator enumerator = this.questSolverLayer.QuestRegions.GetEnumerator()) { while (enumerator.MoveNext()) { int regionIndex = enumerator.Current; GlobalObjectiveMessage globalObjectiveMessage4 = this.patrolObjectives.Find((GlobalObjectiveMessage match) => match.RegionIndex == regionIndex); if (globalObjectiveMessage4 == null) { globalObjectiveMessage4 = base.GenerateObjective(regionIndex); this.patrolObjectives.Add(globalObjectiveMessage4); } if (globalObjectiveMessage4 != null) { globalObjectiveMessage4.GlobalPriority.Value = 0.85f; globalObjectiveMessage4.LocalPriority.Value = 0.85f; } } } } if (this.departmentOfForeignAffairs.IsInWarWithSomeone()) { base.GatherObjectives(AICommanderMissionDefinition.AICommanderCategory.WarPatrol.ToString(), ref this.warPatrolObjectives); base.ValidateMessages(ref this.warPatrolObjectives); if (base.AIEntity.Empire is MajorEmpire) { MajorEmpire majorEmpire2 = base.AIEntity.Empire as MajorEmpire; for (int l = 0; l < majorEmpire2.ConvertedVillages.Count; l++) { Village village = majorEmpire2.ConvertedVillages[l]; GlobalObjectiveMessage globalObjectiveMessage5 = this.warPatrolObjectives.Find((GlobalObjectiveMessage match) => match.RegionIndex == village.Region.Index); if (globalObjectiveMessage5 == null) { globalObjectiveMessage5 = base.GenerateObjective(village.Region.Index); globalObjectiveMessage5.ObjectiveType = AICommanderMissionDefinition.AICommanderCategory.WarPatrol.ToString(); this.warPatrolObjectives.Add(globalObjectiveMessage5); } globalObjectiveMessage5.TimeOut = 1; globalObjectiveMessage5.GlobalPriority = base.GlobalPriority; HeuristicValue heuristicValue4 = new HeuristicValue(0f); heuristicValue4.Add(layer.GetVillageUnitPriority(village, village.StandardUnits.Count), "Village unit priority", new object[0]); globalObjectiveMessage5.LocalPriority = heuristicValue4; } for (int m = 0; m < majorEmpire2.TamedKaijus.Count; m++) { Kaiju kaiju = majorEmpire2.TamedKaijus[m]; if (kaiju.OnGarrisonMode()) { GlobalObjectiveMessage globalObjectiveMessage6 = this.warPatrolObjectives.Find((GlobalObjectiveMessage match) => match.RegionIndex == kaiju.Region.Index); if (globalObjectiveMessage6 == null) { globalObjectiveMessage6 = base.GenerateObjective(kaiju.Region.Index); this.warPatrolObjectives.Add(globalObjectiveMessage6); } globalObjectiveMessage6.TimeOut = 1; globalObjectiveMessage6.GlobalPriority = base.GlobalPriority; HeuristicValue heuristicValue5 = new HeuristicValue(0.8f); AIRegionData regionData2 = this.worldAtlasHelper.GetRegionData(base.AIEntity.Empire.Index, kaiju.Region.Index); if (regionData2 != null) { float operand2 = Mathf.Min(1f, 0.2f * (float)regionData2.BorderWithNeutral + 0.3f * (float)regionData2.BorderWithEnnemy); heuristicValue5.Boost(operand2, "Border with enemy!", new object[0]); } globalObjectiveMessage6.LocalPriority = heuristicValue5; } } } for (int n = 0; n < this.departmentOfTheInterior.Cities.Count; n++) { City city = this.departmentOfTheInterior.Cities[n]; GlobalObjectiveMessage globalObjectiveMessage7 = this.warPatrolObjectives.Find((GlobalObjectiveMessage match) => match.RegionIndex == city.Region.Index); if (globalObjectiveMessage7 == null) { globalObjectiveMessage7 = base.GenerateObjective(city.Region.Index); globalObjectiveMessage7.ObjectiveType = AICommanderMissionDefinition.AICommanderCategory.WarPatrol.ToString(); this.warPatrolObjectives.Add(globalObjectiveMessage7); } globalObjectiveMessage7.TimeOut = 1; globalObjectiveMessage7.GlobalPriority = base.GlobalPriority; HeuristicValue heuristicValue6 = new HeuristicValue(0f); heuristicValue6.Add(AILayer_Military.GetCityDefenseLocalPriority(city, this.unitRatioBoost, 0), "City defense local priority", new object[0]); if (this.worldAtlasHelper.GetRegionData(city.Empire.Index, city.Region.Index).BorderWithEnnemy > 0) { heuristicValue6.Boost(0.2f, "Border with enemy!", new object[0]); } globalObjectiveMessage7.LocalPriority = heuristicValue6; } bool flag = false; for (int num = 0; num < this.warPatrolObjectives.Count; num++) { GlobalObjectiveMessage warPatrolObjective = this.warPatrolObjectives[num]; if (base.AIEntity.GetCommanderProcessingTheNeededGlobalObjective(warPatrolObjective.ID) == null) { GlobalObjectiveMessage globalObjectiveMessage8 = this.patrolObjectives.Find((GlobalObjectiveMessage match) => match.RegionIndex == warPatrolObjective.RegionIndex); if (globalObjectiveMessage8 != null) { AICommander commanderProcessingTheNeededGlobalObjective = base.AIEntity.GetCommanderProcessingTheNeededGlobalObjective(globalObjectiveMessage8.ID); if (commanderProcessingTheNeededGlobalObjective != null) { commanderProcessingTheNeededGlobalObjective.Release(); flag = true; } } } } if (flag) { base.AIEntity.KillAllCommanders("AICommander_Exploration"); } } }
private void UpdateResourceStatus(PointOfInterest pointOfInterest, global::Empire empire, Region region, AIRegionData regionData, DepartmentOfTheTreasury departmentOfTheTreasury) { regionData.ResourcePointOfInterestCount++; if (pointOfInterest.PointOfInterestImprovement != null) { regionData.BuiltExtractor++; } if (!DepartmentOfTheInterior.IsPointOfInterestVisible(empire, pointOfInterest)) { return; } string empty = string.Empty; bool condition = pointOfInterest.PointOfInterestDefinition.TryGetValue("ResourceName", out empty); Diagnostics.Assert(condition); ResourceDefinition.Type resourceType = departmentOfTheTreasury.GetResourceType(empty); float num = 0f; bool condition2 = departmentOfTheTreasury.TryGetNetResourceValue(empire, empty, out num, true); Diagnostics.Assert(condition2); if (num > 0f) { if (resourceType == ResourceDefinition.Type.Luxury) { regionData.ProducedLuxuryRessourcesCount++; } else if (resourceType == ResourceDefinition.Type.Strategic) { regionData.ProducedStrategicRessourcesCount++; } return; } float num2 = 0f; bool condition3 = departmentOfTheTreasury.TryGetResourceStockValue(empire, empty, out num2, true); Diagnostics.Assert(condition3); if (num2 > 0f) { if (resourceType == ResourceDefinition.Type.Luxury) { regionData.OwnedLuxuryRessourcesCount++; } else if (resourceType == ResourceDefinition.Type.Strategic) { regionData.OwnedStrategicRessourcesCount++; } return; } if (resourceType == ResourceDefinition.Type.Luxury) { regionData.NewLuxuryRessourcesCount++; } else if (resourceType == ResourceDefinition.Type.Strategic) { regionData.NewStrategicRessourcesCount++; } }
private void UpdatePacificationStatusOfRegion(global::Empire empire, Region region, AIRegionData regionData) { regionData.VillageTotalCount = 0; regionData.VillagePacifiedOrConvertedByMeCount = 0; regionData.VillageConvertedByOtherCount = 0; regionData.VillageNotPacified = 0; regionData.VillageDestroyed = 0; regionData.VillagePacifiedAndBuilt = 0; if (region.MinorEmpire != null) { BarbarianCouncil agency = region.MinorEmpire.GetAgency <BarbarianCouncil>(); if (agency != null) { regionData.VillageTotalCount = agency.Villages.Count; for (int i = 0; i < agency.Villages.Count; i++) { Village village = agency.Villages[i]; if (village.HasBeenConverted) { if (village.Converter.Index != empire.Index) { regionData.VillageConvertedByOtherCount++; regionData.VillageNotPacified++; } else { regionData.VillagePacifiedOrConvertedByMeCount++; regionData.VillagePacifiedAndBuilt++; } } else if (village.HasBeenPacified) { regionData.VillagePacifiedOrConvertedByMeCount++; if (village.PointOfInterest.PointOfInterestImprovement == null) { regionData.VillageDestroyed++; } else { regionData.VillagePacifiedAndBuilt++; } } else { regionData.VillageNotPacified++; } } } } }
private void UpdateExplorationRatioOfRegion(global::Empire empire, Region region, AIRegionData regionData) { if (empire == null) { throw new ArgumentNullException("empire"); } if (region == null) { throw new ArgumentNullException("region"); } if (region.WorldPositions.Length == 0) { regionData.ExplorationRatio = 1f; return; } int num = 0; for (int i = 0; i < region.WorldPositions.Length; i++) { if (this.visibilityService.IsWorldPositionExploredFor(region.WorldPositions[i], empire)) { num++; } } regionData.ExplorationRatio = (float)num / (float)region.WorldPositions.Length; }
private void UpdateDistanceToMyEmpireOfRegion(global::Empire empire, Region region, AIRegionData regionData) { regionData.MinimalDistanceToMyCities = 2.14748365E+09f; if (region.City != null && region.City.Empire == empire) { regionData.MinimalDistanceToMyCities = 0f; } DepartmentOfTheInterior agency = empire.GetAgency <DepartmentOfTheInterior>(); for (int i = 0; i < agency.Cities.Count; i++) { float num = (float)this.worldPositionningService.GetDistance(region.Barycenter, agency.Cities[i].WorldPosition); if (regionData.MinimalDistanceToMyCities > num) { regionData.MinimalDistanceToMyCities = num; } } }
private bool UpdateColonizationStatusOfRegion(global::Empire empire, Region region, AIRegionData regionData) { bool flag = region.City != null && region.City.Empire == empire; if (regionData.IsColonizedByMe && !flag) { regionData.LostByMeAtTurn = base.Game.Turn; } regionData.IsColonizedByMe = flag; return(flag); }
public float GetRegionExplorationRatio(int empireIndex, int regionIndex) { AIRegionData airegionData = this.regionDataByEmpires[empireIndex][regionIndex]; return(airegionData.ExplorationRatio); }
public void RefreshColonizationPreference(int empireIndex, Region region, float preference) { AIRegionData airegionData = this.regionDataByEmpires[empireIndex][region.Index]; airegionData.ColonizationPreference = preference; }
public bool IsTileTaggedAsExplored(int empireIndex, int regionIndex, WorldPosition position) { AIRegionData airegionData = this.regionDataByEmpires[empireIndex][regionIndex]; return(airegionData.TilesTaggedAsExplored.Contains(position)); }
public bool IsRegionPacified(int empireIndex, int regionIndex) { AIRegionData airegionData = this.regionDataByEmpires[empireIndex][regionIndex]; return(airegionData != null && airegionData.VillageConvertedByOtherCount + airegionData.VillagePacifiedOrConvertedByMeCount == airegionData.VillageTotalCount); }
public bool IsRegionExplored(int empireIndex, int regionIndex, float explorationRatioToReach) { AIRegionData airegionData = this.regionDataByEmpires[empireIndex][regionIndex]; return(airegionData.ExplorationRatio >= explorationRatioToReach); }
public bool IsRegionColonizedByEmpire(int regionIndex, int empireIndex) { AIRegionData airegionData = this.regionDataByEmpires[empireIndex][regionIndex]; return(airegionData.IsColonizedByMe); }
public bool IsRegionColonized(global::Empire empire, Region region) { AIRegionData airegionData = this.regionDataByEmpires[empire.Index][region.Index]; return(airegionData.IsColonizedByMe); }
public bool UpdateRegionDataPathes(AIRegionData regionData) { global::Empire empire = base.Game.Empires[regionData.EmpireIndex]; DepartmentOfScience agency = empire.GetAgency <DepartmentOfScience>(); if (empire.GetAgency <DepartmentOfTheInterior>().Cities.Count <= 0) { return(true); } Region region = this.world.Regions[regionData.RegionIndex]; PathfindingContext pathfindingContext = new PathfindingContext(GameEntityGUID.Zero, null, (!agency.HaveResearchedShipTechnology()) ? (PathfindingMovementCapacity.Ground | PathfindingMovementCapacity.FrozenWater) : (PathfindingMovementCapacity.Ground | PathfindingMovementCapacity.Water | PathfindingMovementCapacity.FrozenWater)); pathfindingContext.RefreshProperties(1f, float.PositiveInfinity, false, false, float.PositiveInfinity, float.PositiveInfinity); pathfindingContext.Greedy = true; PathfindingFlags flags = PathfindingFlags.IgnoreArmies | PathfindingFlags.IgnoreEncounterAreas | PathfindingFlags.IgnoreFogOfWar | PathfindingFlags.IgnoreZoneOfControl; regionData.NormalPath = null; foreach (AIRegionData airegionData in this.regionDataByEmpires[empire.Index]) { if (airegionData.IsColonizedByMe) { Region region2 = this.world.Regions[airegionData.RegionIndex]; PathfindingResult pathfindingResult = this.pathfindingService.FindPath(pathfindingContext, region2.City.WorldPosition, region.Barycenter, PathfindingManager.RequestMode.Default, null, flags, null); if (pathfindingResult != null && (regionData.NormalPath == null || regionData.NormalPath.CompletPathLength > pathfindingResult.CompletPathLength)) { regionData.NormalPath = pathfindingResult; } } } AISafetyData aisafetyData = this.safetyDataByEmpires[regionData.EmpireIndex]; if (regionData.NormalPath != null && aisafetyData.UnsafeRegionIndexes.Count > 0) { bool flag = false; foreach (WorldPosition position in regionData.NormalPath.GetCompletePath()) { int regionIndex = (int)this.worldPositionningService.GetRegionIndex(position); if (aisafetyData.UnsafeRegionIndexes.Contains(regionIndex)) { flag = true; break; } } if (flag) { if (!aisafetyData.UnsafeRegionIndexes.Contains(region.Index)) { regionData.SafePath = null; foreach (AIRegionData airegionData2 in this.regionDataByEmpires[empire.Index]) { if (airegionData2.IsColonizedByMe) { Region region3 = this.world.Regions[airegionData2.RegionIndex]; PathfindingResult pathfindingResult2 = this.pathfindingService.FindPath(pathfindingContext, region3.City.WorldPosition, region.Barycenter, PathfindingManager.RequestMode.Default, aisafetyData.SafePathfindingContext, flags, null); if (pathfindingResult2 != null && (regionData.SafePath == null || regionData.SafePath.CompletPathLength > pathfindingResult2.CompletPathLength)) { regionData.SafePath = pathfindingResult2; } } } } else { regionData.SafePath = null; } } else { regionData.SafePath = regionData.NormalPath; } } return(false); }
public void AddRegion(AIRegionData regionData) { this.UpdateLists(regionData); this.Regions.Add(regionData); }
public float GetRegionExplorationRatio(global::Empire empire, Region region) { AIRegionData airegionData = this.regionDataByEmpires[empire.Index][region.Index]; return(airegionData.ExplorationRatio); }