public static bool IsRegionValidForExploration(global::Empire empire, int regionIndex) { Diagnostics.Assert(AIScheduler.Services != null); IWorldAtlasAIHelper service = AIScheduler.Services.GetService <IWorldAtlasAIHelper>(); Diagnostics.Assert(service != null); if (empire != null) { DepartmentOfForeignAffairs agency = empire.GetAgency <DepartmentOfForeignAffairs>(); if (agency != null && !agency.CanMoveOn(regionIndex, false)) { return(false); } } DepartmentOfTheInterior agency2 = empire.GetAgency <DepartmentOfTheInterior>(); if (agency2 != null) { bool flag = false; for (int i = 0; i < agency2.Cities.Count; i++) { if (agency2.Cities[i].Region.ContinentID == service.Regions[regionIndex].ContinentID) { flag = true; break; } } if (agency2.Cities.Count == 0) { flag = true; } if (!flag) { DepartmentOfCreepingNodes agency3 = empire.GetAgency <DepartmentOfCreepingNodes>(); if (agency3 != null) { using (List <CreepingNode> .Enumerator enumerator = agency3.Nodes.GetEnumerator()) { while (enumerator.MoveNext()) { if (!enumerator.Current.IsUnderConstruction && AILayer_Exploration.IsTravelAllowedInNode(empire, enumerator.Current) && enumerator.Current.Region.ContinentID == service.Regions[regionIndex].ContinentID) { flag = true; break; } } } } } if (!flag) { return(false); } } return(!service.IsRegionExplored(empire.Index, regionIndex, 0.95f)); }
protected override void RefreshObjectives(StaticString context, StaticString pass) { base.RefreshObjectives(context, pass); Diagnostics.Assert(Services.GetService <IGameService>() != null); base.GatherObjectives(AICommanderMissionDefinition.AICommanderCategory.Exploration.ToString(), ref this.globalObjectiveMessages); this.regionToExplore.Clear(); if (!this.TrySelectRegionToExplore(base.AIEntity.Empire, ref this.regionToExplore) && this.departmentOfTheInterior.Cities.Count == 0) { int num = -9; for (int i = 0; i < this.departmentOfDefense.Armies.Count; i++) { if (this.departmentOfDefense.Armies[i].StandardUnits != null) { if (this.departmentOfDefense.Armies[i].StandardUnits.ToList <Unit>().Exists((Unit U) => !U.IsSettler)) { Region region = this.worldPositionningService.GetRegion(this.departmentOfDefense.Armies[i].WorldPosition); num = ((num < 0) ? region.ContinentID : num); this.regionToExplore.AddOnce(region); for (int j = 0; j < region.Borders.Length; j++) { Region region2 = this.worldPositionningService.World.Regions[region.Borders[j].NeighbourRegionIndex]; if (region2.IsLand && region2.City == null && region2.ContinentID == num) { this.regionToExplore.AddOnce(region2); } } } } } } base.ValidateMessages(ref this.globalObjectiveMessages); int index; int index2; for (index = 0; index < this.regionToExplore.Count; index = index2 + 1) { if (AILayer_Exploration.IsRegionValidForExploration(base.AIEntity.Empire, this.regionToExplore[index].Index) && this.globalObjectiveMessages.Find((GlobalObjectiveMessage match) => match.RegionIndex == this.regionToExplore[index].Index) == null) { GlobalObjectiveMessage item = base.GenerateObjective(this.regionToExplore[index].Index); this.globalObjectiveMessages.Add(item); } index2 = index; } this.ComputeObjectivePriority(); }
protected override bool TryComputeArmyMissionParameter() { if (this.ticket != null) { if (this.ticket.Raised) { this.ticket = null; } return(false); } if (base.AIDataArmyGUID.IsValid && this.TargetCity != null && this.TargetCity.Empire == base.Commander.Empire && this.aiDataRepository.GetAIData <AIData_City>(this.TargetCity.GUID) != null) { AIData_Army aidata = this.aiDataRepository.GetAIData <AIData_Army>(base.AIDataArmyGUID); if (aidata != null) { List <object> list = new List <object>(); list.Add(this.TargetCity); if (this.TargetCity.MaximumUnitSlot > this.TargetCity.CurrentUnitSlot + aidata.Army.CurrentUnitSlot) { return(base.TryCreateArmyMission("DefendCity_Bail", list)); } if (aidata.Army.CurrentUnitSlot > 1) { GameEntityGUID[] array = new GameEntityGUID[1]; for (int i = 0; i < aidata.Army.StandardUnits.Count; i++) { if (aidata.Army.StandardUnits[i].IsSettler && aidata.Army.StandardUnits[i].GetPropertyValue(SimulationProperties.Movement) > 0f) { array[0] = aidata.Army.StandardUnits[i].GUID; break; } } WorldPosition neighbourFirstAvailablePositionForArmyCreation = DepartmentOfDefense.GetNeighbourFirstAvailablePositionForArmyCreation(aidata.Army); if (neighbourFirstAvailablePositionForArmyCreation.IsValid && array[0].IsValid) { OrderTransferGarrisonToNewArmy order = new OrderTransferGarrisonToNewArmy(base.Commander.Empire.Index, base.AIDataArmyGUID, array, neighbourFirstAvailablePositionForArmyCreation, null, false, true, true); base.Commander.Empire.PlayerControllers.AI.PostOrder(order, out this.ticket, null); } return(false); } return(base.TryCreateArmyMission("ReachTarget", list)); } } Diagnostics.Assert(AIScheduler.Services != null); IIntelligenceAIHelper service = AIScheduler.Services.GetService <IIntelligenceAIHelper>(); Diagnostics.Assert(service != null); List <Region> list2 = new List <Region>(); if (service.TryGetListOfRegionToExplore(base.Commander.Empire, 0.95f, ref list2)) { foreach (Region region in list2) { if (AILayer_Exploration.IsRegionValidForExploration(base.Commander.Empire, region)) { return(base.TryCreateArmyMission("ExploreAt", new List <object> { region.Index })); } } return(false); } return(false); }
private bool IsKaijuValidForObjective(Kaiju kaiju) { bool flag = false; if (kaiju == null) { return(flag); } int regionIndex = (int)this.worldPositionningService.GetRegionIndex(kaiju.WorldPosition); if (!this.departmentOfForeignAffairs.CanMoveOn(regionIndex, false)) { return(false); } if (kaiju.MajorEmpire != null) { if (!this.departmentOfForeignAffairs.CanAttack(kaiju.GetActiveTroops())) { return(false); } if (kaiju.OnArmyMode()) { District district = this.worldPositionningService.GetDistrict(kaiju.WorldPosition); if (district != null && District.IsACityTile(district)) { return(false); } } if (this.departmentOfForeignAffairs.IsInWarWithSomeone()) { flag = !this.departmentOfForeignAffairs.IsAtWarWith(kaiju.MajorEmpire); } else { flag = this.departmentOfForeignAffairs.IsFriend(kaiju.MajorEmpire); } } if (!flag && kaiju.Empire.Index != base.AIEntity.Empire.Index && this.departmentOfTheInterior.Cities.Count > 0) { if (this.departmentOfCreepingNodes != null) { Region region = this.worldPositionningService.GetRegion(kaiju.WorldPosition); foreach (CreepingNode creepingNode in this.departmentOfCreepingNodes.Nodes) { if (!creepingNode.IsUnderConstruction && AILayer_Exploration.IsTravelAllowedInNode(base.AIEntity.Empire, creepingNode) && creepingNode.Region.Index == region.Index) { return(true); } } } foreach (Army army in this.departmentOfDefense.Armies) { if (!army.IsSeafaring) { if (this.pathfindingService.FindPath(army, this.departmentOfTheInterior.Cities[0].WorldPosition, kaiju.WorldPosition, PathfindingManager.RequestMode.Default, null, PathfindingFlags.IgnoreArmies | PathfindingFlags.IgnoreFogOfWar | PathfindingFlags.IgnoreSieges | PathfindingFlags.IgnoreKaijuGarrisons, null) == null) { return(false); } return(true); } } return(false); } return(false); }
private void RefreshMessagePriority(GlobalObjectiveMessage objectiveMessage) { objectiveMessage.GlobalPriority = base.GlobalPriority; objectiveMessage.LocalPriority = new HeuristicValue(0.35f); List <int> list = new List <int>(); if (!DepartmentOfTheInterior.CanNeverDeclareWar(base.AIEntity.Empire) || this.departmentOfForeignAffairs.IsInWarWithSomeone()) { foreach (AICommander aicommander in this.aILayer_ArmyManagement.AICommanders) { AICommander_WarWithObjective aicommander_WarWithObjective = aicommander as AICommander_WarWithObjective; if (aicommander_WarWithObjective != null) { Region region = this.worldPositionningService.GetRegion(aicommander_WarWithObjective.RegionIndex); if (region.Owner != null && region.Owner.Index != base.AIEntity.Empire.Index) { list.Add(region.Owner.Index); } } } } if (list.Count == 0) { objectiveMessage.LocalPriority.Boost(0.4f, "NoWarBoost", new object[0]); } Region region2 = this.worldPositionningService.GetRegion(objectiveMessage.RegionIndex); if (region2.Kaiju != null && region2.Kaiju.IsTamed() && list.Contains(region2.Kaiju.OwnerEmpireIndex) && this.departmentOfForeignAffairs.IsAtWarWith(region2.Kaiju.MajorEmpire)) { objectiveMessage.LocalPriority.Boost(0.2f, "At war boost", new object[0]); } if (region2 != null && region2.Kaiju != null && this.departmentOfTheInterior.Cities.Count > 0) { int num = int.MaxValue; foreach (City city in this.departmentOfTheInterior.Cities) { int distance = this.worldPositionningService.GetDistance(city.WorldPosition, region2.Kaiju.WorldPosition); if (distance < num) { num = distance; } } if (this.departmentOfCreepingNodes != null) { foreach (CreepingNode creepingNode in this.departmentOfCreepingNodes.Nodes) { if (creepingNode.Region.Index == region2.Index && !creepingNode.IsUnderConstruction && AILayer_Exploration.IsTravelAllowedInNode(base.AIEntity.Empire, creepingNode)) { int distance2 = this.worldPositionningService.GetDistance(creepingNode.WorldPosition, region2.Kaiju.WorldPosition); if (distance2 < num) { num = distance2; } } } } num = Mathf.Max(30 - num, 0); objectiveMessage.LocalPriority.Boost((float)num / 60f, "Close distance boost", new object[0]); } if (list.Count > 0 && !this.departmentOfForeignAffairs.IsInWarWithSomeone() && this.aiLayerStrategy.WantWarWithSomeone() && region2.Kaiju != null && region2.Kaiju.IsTamed() && (region2.Owner == null || region2.Owner.Index != base.AIEntity.Empire.Index) && !list.Contains(region2.Kaiju.OwnerEmpireIndex)) { objectiveMessage.LocalPriority.Boost(-0.6f, "Not our target!", new object[0]); } objectiveMessage.TimeOut = 1; }
public static bool IsRegionValidForExploration(global::Empire empire, Region region) { return(AILayer_Exploration.IsRegionValidForExploration(empire, region.Index)); }
protected override bool IsObjectiveValid(StaticString objectiveType, int regionIndex, bool checkLocalPriority = false) { return(this.regionToExplore.Contains(this.worldAtlasAIHelper.Regions[regionIndex]) && AILayer_Exploration.IsRegionValidForExploration(base.AIEntity.Empire, regionIndex)); }
public void ComputeConnectedRegion(global::Empire empire, ref List <int> connectedRegion, Func <Region, bool> match = null) { DepartmentOfCreepingNodes agency = empire.GetAgency <DepartmentOfCreepingNodes>(); DepartmentOfTheInterior agency2 = empire.GetAgency <DepartmentOfTheInterior>(); DepartmentOfForeignAffairs agency3 = empire.GetAgency <DepartmentOfForeignAffairs>(); Diagnostics.Assert(agency2 != null); bool flag = false; for (int i = 0; i < agency2.Cities.Count; i++) { Region region = agency2.Cities[i].Region; if (match == null || match(region)) { connectedRegion.Add(region.Index); } for (int j = 0; j < region.Borders.Length; j++) { Region region2 = this.world.Regions[region.Borders[j].NeighbourRegionIndex]; if (region2.IsOcean) { flag = true; } if ((region2.City == null || region2.City.Empire != empire) && !connectedRegion.Contains(region2.Index) && (match == null || match(region2))) { connectedRegion.Add(region2.Index); } } } if (agency != null && agency3 != null) { foreach (CreepingNode creepingNode in agency.Nodes) { if (!creepingNode.IsUnderConstruction && AILayer_Exploration.IsTravelAllowedInNode(empire, creepingNode) && agency3.CanMoveOn((int)this.worldPositionningService.GetRegionIndex(creepingNode.WorldPosition), false) && !connectedRegion.Contains(creepingNode.Region.Index) && (match == null || match(creepingNode.Region))) { connectedRegion.Add(creepingNode.Region.Index); } } } if (flag) { for (int k = 0; k < this.world.Continents.Length; k++) { Continent continent = this.world.Continents[k]; if (!continent.IsOcean && !continent.IsWasteland) { bool flag2 = false; for (int l = 0; l < agency2.Cities.Count; l++) { if (agency2.Cities[l].Region.ContinentID == continent.ID) { flag2 = true; break; } } if (!flag2) { for (int m = 0; m < continent.CostalRegionList.Length; m++) { Region region3 = this.world.Regions[continent.CostalRegionList[m]]; if (!connectedRegion.Contains(region3.Index) && (match == null || match(region3))) { connectedRegion.Add(region3.Index); } } } } } } }