public void ComputeFarestPositionInList(WorldPosition[] listOfPosition, WorldPosition origin, PathfindingMovementCapacity pathfindingCapacity, out WorldPosition final) { WorldPosition worldPosition = WorldPosition.Invalid; if (listOfPosition.Length > 0) { IGameService service = Services.GetService <IGameService>(); Diagnostics.Assert(service != null); IWorldPositionningService service2 = service.Game.Services.GetService <IWorldPositionningService>(); Diagnostics.Assert(service2 != null); IPathfindingService service3 = service.Game.Services.GetService <IPathfindingService>(); float num = 0f; for (int i = 0; i < listOfPosition.Length; i++) { if (service3.IsTilePassable(listOfPosition[i], pathfindingCapacity, (PathfindingFlags)0) && service3.IsTileStopable(listOfPosition[i], pathfindingCapacity, (PathfindingFlags)0)) { float num2 = (float)service2.GetDistance(listOfPosition[i], origin); if (num2 > num) { worldPosition = listOfPosition[i]; num = num2; } } } } final = worldPosition; }
public static bool AreaIsSave(WorldPosition pos, int size, DepartmentOfForeignAffairs departmentOfForeignAffairs, out float rangescore, out float incomingMP, bool NavalOnly = false) { incomingMP = 0f; rangescore = 0f; if (size < 1) { return(true); } List <global::Empire> list = new List <global::Empire>(Array.FindAll <global::Empire>((Services.GetService <IGameService>().Game as global::Game).Empires, (global::Empire match) => match is MajorEmpire && departmentOfForeignAffairs.IsAtWarWith(match))); if (list.Count < 1) { return(true); } bool result = true; IWorldPositionningService service = Services.GetService <IGameService>().Game.Services.GetService <IWorldPositionningService>(); foreach (global::Empire empire in list) { List <IGarrison> list2 = new List <IGarrison>(); DepartmentOfDefense agency = empire.GetAgency <DepartmentOfDefense>(); DepartmentOfTheInterior agency2 = empire.GetAgency <DepartmentOfTheInterior>(); if (!NavalOnly) { list2.AddRange(agency.Armies.ToList <Army>().FindAll((Army match) => !match.IsSeafaring && !match.IsSettler).Cast <IGarrison>()); list2.AddRange(agency2.Cities.Cast <IGarrison>()); list2.AddRange(agency2.Camps.Cast <IGarrison>()); list2.AddRange(agency2.ConvertedVillages.Cast <IGarrison>()); } if (NavalOnly) { list2.AddRange(agency.Armies.ToList <Army>().FindAll((Army match) => match.IsNaval && !match.IsSettler).Cast <IGarrison>()); list2.AddRange(agency2.OccupiedFortresses.Cast <IGarrison>()); } foreach (IGarrison garrison in list2) { if (garrison.UnitsCount > 0 && garrison is IWorldPositionable) { float num = (float)service.GetDistance((garrison as IWorldPositionable).WorldPosition, pos); if (num <= (float)size) { incomingMP += garrison.GetPropertyValue(SimulationProperties.MilitaryPower); result = false; float num2 = 1f - num / (float)size; if (num2 > rangescore) { rangescore = num2; } } } } } return(result); }
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 bool IsPositionInRange(WorldPosition origin, WorldPosition destination, int range) { IGameService service = Services.GetService <IGameService>(); Diagnostics.Assert(service != null); IWorldPositionningService service2 = service.Game.Services.GetService <IWorldPositionningService>(); Diagnostics.Assert(service2 != null); int distance = service2.GetDistance(origin, destination); return(distance <= range); }
public static bool IsDetourWorthCheckingFast(IWorldPositionningService worldPositionningService, Army army, WorldPosition opportunityPosition, WorldPosition mainTargetPosition, out int numberOfTurnsTillMainTarget, out int numberOfTurnsAfterDetour) { int distance = worldPositionningService.GetDistance(army.WorldPosition, opportunityPosition); int distance2 = worldPositionningService.GetDistance(army.WorldPosition, mainTargetPosition); numberOfTurnsTillMainTarget = 0; numberOfTurnsAfterDetour = 0; if (distance2 < distance) { return(false); } int distance3 = worldPositionningService.GetDistance(opportunityPosition, mainTargetPosition); float propertyValue = army.GetPropertyValue(SimulationProperties.MaximumMovement); numberOfTurnsTillMainTarget = (int)((float)distance2 / propertyValue); if (distance < 2) { numberOfTurnsAfterDetour = numberOfTurnsTillMainTarget; return(true); } numberOfTurnsAfterDetour = (int)((float)(distance + distance3) / propertyValue); return(true); }
public static WorldPosition GetValidKaijuPosition(Region targetRegion, bool randomFallback = false) { IGameService service = Services.GetService <IGameService>(); IWorldPositionningService service3 = service.Game.Services.GetService <IWorldPositionningService>(); KaijuCouncil.attractivenessMap = (KaijuCouncil.world.Atlas.GetMap(WorldAtlas.Maps.KaijuAttractiveness) as GridMap <bool>); WorldPosition[] array = (from position in targetRegion.WorldPositions where KaijuCouncil.IsPositionValidForSettleKaiju(position, null) select position).ToArray <WorldPosition>(); WorldPosition result = WorldPosition.Invalid; if (array.Length != 0) { result = array[KaijuCouncil.random.Next(0, array.Length)]; if (!ELCPUtilities.UseELCPSymbiosisBuffs) { goto IL_185; } List <WorldPosition> list = array.ToList <WorldPosition>().Randomize(KaijuCouncil.random); List <PointOfInterest> list2 = targetRegion.PointOfInterests.ToList <PointOfInterest>().FindAll((PointOfInterest PointOfInterest) => PointOfInterest.Type == ELCPUtilities.QuestLocation); if (list2 == null || list2.Count <= 0) { goto IL_185; } using (List <WorldPosition> .Enumerator enumerator = list.GetEnumerator()) { while (enumerator.MoveNext()) { WorldPosition position = enumerator.Current; if (list2.Any((PointOfInterest poi) => service3.GetDistance(poi.WorldPosition, position) == 1)) { result = position; break; } } goto IL_185; } } if (randomFallback) { Diagnostics.LogError("Could not find suitable position in starting region!... Picking a random one..."); result = targetRegion.WorldPositions[KaijuCouncil.random.Next(0, targetRegion.WorldPositions.Length)]; } IL_185: if (!result.IsValid) { Diagnostics.LogError("Could not find a valid kaiju position!"); } return(result); }
public static bool AreaIsSave(WorldPosition pos, int size, DepartmentOfForeignAffairs departmentOfForeignAffairs, bool NavalOnly = false, bool ignoreColdwar = false) { if (size < 1) { return(true); } List <global::Empire> list = new List <global::Empire>(); if (ignoreColdwar) { list.AddRange(Array.FindAll <global::Empire>((Services.GetService <IGameService>().Game as global::Game).Empires, (global::Empire match) => match is MajorEmpire && departmentOfForeignAffairs.IsAtWarWith(match))); } else { list.AddRange(Array.FindAll <global::Empire>((Services.GetService <IGameService>().Game as global::Game).Empires, (global::Empire match) => match is MajorEmpire && !departmentOfForeignAffairs.IsFriend(match))); } if (list.Count == 0) { return(true); } IWorldPositionningService service = Services.GetService <IGameService>().Game.Services.GetService <IWorldPositionningService>(); foreach (global::Empire empire in list) { List <IGarrison> list2 = new List <IGarrison>(); DepartmentOfDefense agency = empire.GetAgency <DepartmentOfDefense>(); DepartmentOfTheInterior agency2 = empire.GetAgency <DepartmentOfTheInterior>(); if (!NavalOnly) { list2.AddRange(agency.Armies.ToList <Army>().FindAll((Army match) => !match.IsSeafaring && !match.IsSettler).Cast <IGarrison>()); list2.AddRange(agency2.Cities.Cast <IGarrison>()); list2.AddRange(agency2.Camps.Cast <IGarrison>()); list2.AddRange(agency2.ConvertedVillages.Cast <IGarrison>()); } if (NavalOnly) { list2.AddRange(agency.Armies.ToList <Army>().FindAll((Army match) => match.IsNaval && !match.IsSettler).Cast <IGarrison>()); list2.AddRange(agency2.OccupiedFortresses.Cast <IGarrison>()); } foreach (IGarrison garrison in list2) { if (garrison.UnitsCount > 0 && garrison is IWorldPositionable && service.GetDistance((garrison as IWorldPositionable).WorldPosition, pos) <= size) { return(false); } } } return(true); }
private District GetClosestDistrictToAttackCity(City city, GridMap <District> districtsMap, Army army, IPathfindingService pathfindingService, IWorldPositionningService worldPositionningService) { float num = 2.14748365E+09f; District district = null; for (int i = 0; i < city.Districts.Count; i++) { if (city.Districts[i].Type == DistrictType.Exploitation && this.CanIAttackTheCityFromTheDistrict(city.Districts[i], districtsMap, army, pathfindingService, worldPositionningService)) { int distance = worldPositionningService.GetDistance(army.WorldPosition, city.Districts[i].WorldPosition); if ((float)distance < num) { num = (float)distance; district = city.Districts[i]; } } } if (district != null) { return(district); } return(city.Districts[0]); }
public override NavyTaskEvaluation ComputeFitness(BaseNavyArmy navyGarrison) { IWorldPositionningService service = Services.GetService <IGameService>().Game.Services.GetService <IWorldPositionningService>(); NavyTaskEvaluation navyTaskEvaluation = new NavyTaskEvaluation(); navyTaskEvaluation.Fitness = new HeuristicValue(0f); navyTaskEvaluation.Task = this; if (navyGarrison.Role == BaseNavyArmy.ArmyRole.Land || navyGarrison.Role == BaseNavyArmy.ArmyRole.Convoi) { navyTaskEvaluation.Fitness.Value = -1f; navyTaskEvaluation.Fitness.Log("Role is not valid for the task. Role={0}.", new object[] { navyGarrison.Role.ToString() }); } else { float enemyPower = this.GetEnemyPower(); float propertyValue = navyGarrison.Garrison.GetPropertyValue(SimulationProperties.MilitaryPower); navyTaskEvaluation.Fitness.Add(base.ComputePowerFitness(enemyPower, propertyValue), "MilitaryPower", new object[0]); if (navyTaskEvaluation.Fitness > 0f) { float value = navyTaskEvaluation.Fitness.Value; float numberOfTurnToReach = (float)service.GetDistance(navyGarrison.Garrison.WorldPosition, this.FortressPosition) / navyGarrison.GetMaximumMovement(); navyTaskEvaluation.Fitness.Multiply(base.ComputeDistanceFitness(numberOfTurnToReach, navyGarrison.Role), "Distance", new object[0]); if (navyGarrison.Role == BaseNavyArmy.ArmyRole.Forteress) { navyTaskEvaluation.Fitness.Boost(-0.2f, "Fortress...", new object[0]); } if (navyGarrison.Garrison.GetPropertyValue(SimulationProperties.ActionPointsSpent) > 0f) { navyTaskEvaluation.Fitness.Boost(-0.2f, "No more action point...", new object[0]); } } } return(navyTaskEvaluation); }
protected override State Execute(AIBehaviorTree aiBehaviorTree, params object[] parameters) { if (this.ticket != null) { if (!this.orderExecuted) { return(State.Running); } if (this.ticket.PostOrderResponse == PostOrderResponse.PreprocessHasFailed) { this.orderExecuted = false; this.ticket = null; aiBehaviorTree.ErrorCode = 1; return(State.Failure); } this.orderExecuted = false; this.ticket = null; return(State.Success); } else { Army army; if (base.GetArmyUnlessLocked(aiBehaviorTree, "$Army", out army) != AIArmyMission.AIArmyMissionErrorCode.None) { return(State.Failure); } float propertyValue = army.GetPropertyValue(SimulationProperties.MaximumNumberOfActionPoints); float propertyValue2 = army.GetPropertyValue(SimulationProperties.ActionPointsSpent); if (propertyValue <= propertyValue2) { aiBehaviorTree.ErrorCode = 33; return(State.Failure); } if (!aiBehaviorTree.Variables.ContainsKey(this.TargetVarName)) { aiBehaviorTree.LogError("${0} not set", new object[] { this.TargetVarName }); return(State.Failure); } IGameEntity target = aiBehaviorTree.Variables[this.TargetVarName] as IGameEntity; if (!(target is IWorldPositionable)) { return(State.Failure); } IGameService service = Services.GetService <IGameService>(); Diagnostics.Assert(service != null); if (!service.Game.Services.GetService <IGameEntityRepositoryService>().Contains(target.GUID)) { return(State.Success); } IWorldPositionningService service2 = service.Game.Services.GetService <IWorldPositionningService>(); IEnumerable <Encounter> service3 = service.Game.Services.GetService <IEncounterRepositoryService>(); if (service3 != null && service3.Any((Encounter encounter) => encounter.IsGarrisonInEncounter(army.GUID, false) || encounter.IsGarrisonInEncounter(target.GUID, false))) { return(State.Running); } IGarrison garrison; if (target is Kaiju) { Kaiju kaiju = target as Kaiju; garrison = kaiju.GetActiveTroops(); if (kaiju.IsStunned()) { return(State.Failure); } } else { if (target is KaijuArmy) { KaijuArmy kaijuArmy = target as KaijuArmy; if (kaijuArmy != null && kaijuArmy.Kaiju.IsStunned()) { return(State.Failure); } } else if (target is KaijuGarrison) { KaijuGarrison kaijuGarrison = target as KaijuGarrison; if (kaijuGarrison != null && kaijuGarrison.Kaiju.IsStunned()) { return(State.Failure); } } garrison = (target as IGarrison); if (garrison == null) { return(State.Failure); } } if ((army.Empire is MinorEmpire || army.Empire is NavalEmpire) && garrison.Hero != null && garrison.Hero.IsSkillUnlocked("HeroSkillLeaderMap07")) { return(State.Failure); } if (garrison.Empire.Index == aiBehaviorTree.AICommander.Empire.Index) { return(State.Failure); } this.orderExecuted = false; GameEntityGUID guid = target.GUID; if (target is City) { Diagnostics.Assert(AIScheduler.Services != null); IEntityInfoAIHelper service4 = AIScheduler.Services.GetService <IEntityInfoAIHelper>(); Diagnostics.Assert(service4 != null); City city = target as City; if (city.BesiegingEmpire != null && city.BesiegingEmpire != aiBehaviorTree.AICommander.Empire) { return(State.Failure); } District districtToAttackFrom = service4.GetDistrictToAttackFrom(army, city); if (districtToAttackFrom == null) { aiBehaviorTree.ErrorCode = 12; return(State.Failure); } guid = districtToAttackFrom.GUID; } else if (target is Camp) { Camp camp = target as Camp; IWorldPositionable worldPositionable = target as IWorldPositionable; if (worldPositionable == null) { return(State.Failure); } if (service2.GetDistance(army.WorldPosition, worldPositionable.WorldPosition) != 1) { aiBehaviorTree.ErrorCode = 12; return(State.Failure); } guid = camp.GUID; } else if (target is Fortress) { guid = target.GUID; } else { Village village = target as Village; if (village != null && (village.HasBeenPacified || (village.HasBeenConverted && village.Converter == aiBehaviorTree.AICommander.Empire) || village.HasBeenInfected)) { return(State.Failure); } Diagnostics.Assert(AIScheduler.Services != null); IWorldPositionable worldPositionable2 = target as IWorldPositionable; if (worldPositionable2 == null) { return(State.Failure); } District district = service2.GetDistrict(worldPositionable2.WorldPosition); if (district != null && District.IsACityTile(district) && district.City.Empire == garrison.Empire) { worldPositionable2 = district; guid = district.GUID; } if (service2.GetDistance(army.WorldPosition, worldPositionable2.WorldPosition) != 1) { aiBehaviorTree.ErrorCode = 12; return(State.Failure); } } OrderAttack order = new OrderAttack(army.Empire.Index, army.GUID, guid); aiBehaviorTree.AICommander.Empire.PlayerControllers.AI.PostOrder(order, out this.ticket, new EventHandler <TicketRaisedEventArgs>(this.Order_TicketRaised)); return(State.Running); } }
protected override State Execute(AIBehaviorTree aiBehaviorTree, params object[] parameters) { if (this.TypeOfDiplomaticRelation == "VillageQuest" && (!(aiBehaviorTree.AICommander.Empire is MajorEmpire) || !aiBehaviorTree.AICommander.Empire.GetAgency <DepartmentOfScience>().CanParley())) { return(State.Failure); } if (this.DiplomacyLayer == null && aiBehaviorTree.AICommander.Empire is MajorEmpire) { AIEntity_Empire entity = aiBehaviorTree.AICommander.AIPlayer.GetEntity <AIEntity_Empire>(); this.DiplomacyLayer = entity.GetLayer <AILayer_Diplomacy>(); } IGameService service = Services.GetService <IGameService>(); Diagnostics.Assert(service != null); Army army; if (base.GetArmyUnlessLocked(aiBehaviorTree, "$Army", out army) > AIArmyMission.AIArmyMissionErrorCode.None) { return(State.Failure); } if (!aiBehaviorTree.Variables.ContainsKey(this.TargetListVarName)) { return(State.Failure); } List <IWorldPositionable> list = aiBehaviorTree.Variables[this.TargetListVarName] as List <IWorldPositionable>; if (list == null || list.Count == 0) { aiBehaviorTree.ErrorCode = 10; return(State.Failure); } List <IWorldPositionable> list2 = null; if (this.TypeOfTarget == AIBehaviorTreeNode_Decorator_SelectTarget.TargetType.Army) { list2 = list.FindAll((IWorldPositionable match) => match is Army); } else if (this.TypeOfTarget == AIBehaviorTreeNode_Decorator_SelectTarget.TargetType.Ruin) { list2 = this.Execute_GetRuins(aiBehaviorTree, army, service, list); } else if (this.TypeOfTarget == AIBehaviorTreeNode_Decorator_SelectTarget.TargetType.Village) { list2 = this.Execute_GetVillages(aiBehaviorTree, army, service, list); } else if (this.TypeOfTarget > AIBehaviorTreeNode_Decorator_SelectTarget.TargetType.Village && this.TypeOfTarget < AIBehaviorTreeNode_Decorator_SelectTarget.TargetType.VolcanoformerDevice) { list2 = this.Execute_GetKaijus(aiBehaviorTree, army, service, list); } else if (this.TypeOfTarget == AIBehaviorTreeNode_Decorator_SelectTarget.TargetType.VolcanoformerDevice) { list2 = this.Execute_GetVolcanoformers(aiBehaviorTree, army, service, list); } else if (this.TypeOfTarget == AIBehaviorTreeNode_Decorator_SelectTarget.TargetType.Fortress) { list2 = this.Execute_GetFortresses(aiBehaviorTree, army, service, list); } else if (this.TypeOfTarget == AIBehaviorTreeNode_Decorator_SelectTarget.TargetType.Any) { list2 = new List <IWorldPositionable>(list); } if (army.Empire is MinorEmpire || army.Empire is NavalEmpire) { for (int i = list2.Count - 1; i >= 0; i--) { Garrison garrison = list2[i] as Garrison; if (garrison != null && garrison.Hero != null && garrison.Hero.IsSkillUnlocked("HeroSkillLeaderMap07")) { list2.RemoveAt(i); } } } IGameEntityRepositoryService service2 = service.Game.Services.GetService <IGameEntityRepositoryService>(); IWorldPositionningService service3 = service.Game.Services.GetService <IWorldPositionningService>(); bool flag = false; if (this.TypeOfDiplomaticRelation == "VillageQuest") { flag = true; } if (!string.IsNullOrEmpty(this.TypeOfDiplomaticRelationVariableName) && aiBehaviorTree.Variables.ContainsKey(this.TypeOfDiplomaticRelationVariableName)) { this.TypeOfDiplomaticRelation = (aiBehaviorTree.Variables[this.TypeOfDiplomaticRelationVariableName] as string); } DepartmentOfForeignAffairs departmentOfForeignAffairs = null; bool canAttack = false; if (this.TypeOfDiplomaticRelation == "Enemy") { departmentOfForeignAffairs = aiBehaviorTree.AICommander.Empire.GetAgency <DepartmentOfForeignAffairs>(); canAttack = true; } else if (this.TypeOfDiplomaticRelation == "DangerForMe") { departmentOfForeignAffairs = aiBehaviorTree.AICommander.Empire.GetAgency <DepartmentOfForeignAffairs>(); canAttack = false; } for (int j = list2.Count - 1; j >= 0; j--) { if (!AIBehaviorTreeNode_Decorator_SelectTarget.ValidateTarget(army, list2[j] as IGameEntity, departmentOfForeignAffairs, canAttack, service2, service3)) { list2.RemoveAt(j); } else if (list2[j] is IGarrison && departmentOfForeignAffairs != null && this.DiplomacyLayer != null && (list2[j] as IGarrison).Empire is MajorEmpire && this.DiplomacyLayer.GetPeaceWish((list2[j] as IGarrison).Empire.Index)) { if (!(list2[j] is Army) || !(list2[j] as Army).IsPrivateers) { list2.RemoveAt(j); } } else if (flag && list2[j] is Village && !this.ValidQuestVillage(list2[j] as Village, army)) { list2.RemoveAt(j); } } IWorldPositionningService worldPositionService = service.Game.Services.GetService <IWorldPositionningService>(); if (list2 != null && list2.Count != 0) { bool flag2; if (this.TypeOfTarget == AIBehaviorTreeNode_Decorator_SelectTarget.TargetType.Ruin || this.TypeOfTarget == AIBehaviorTreeNode_Decorator_SelectTarget.TargetType.Fortress) { flag2 = army.SimulationObject.Tags.Contains("MovementCapacitySail"); } else { flag2 = army.HasSeafaringUnits(); } Diagnostics.Assert(worldPositionService != null); if (!flag2) { list2.RemoveAll((IWorldPositionable element) => worldPositionService.IsWaterTile(element.WorldPosition)); } if (army.IsSeafaring) { list2.RemoveAll((IWorldPositionable element) => !worldPositionService.IsWaterTile(element.WorldPosition)); list2.RemoveAll((IWorldPositionable element) => worldPositionService.IsFrozenWaterTile(element.WorldPosition)); } } if (list2 != null && list2.Count != 0) { if (list2.Count > 1) { list2.Sort((IWorldPositionable left, IWorldPositionable right) => worldPositionService.GetDistance(left.WorldPosition, army.WorldPosition).CompareTo(worldPositionService.GetDistance(right.WorldPosition, army.WorldPosition))); } if (aiBehaviorTree.Variables.ContainsKey(this.Output_TargetVarName)) { aiBehaviorTree.Variables[this.Output_TargetVarName] = list2[0]; } else { aiBehaviorTree.Variables.Add(this.Output_TargetVarName, list2[0]); } } else if (aiBehaviorTree.Variables.ContainsKey(this.Output_TargetVarName)) { aiBehaviorTree.Variables.Remove(this.Output_TargetVarName); } State result; if (this.Inverted) { if (list2 != null && list2.Count != 0) { result = State.Failure; } else { result = State.Success; } } else if (list2 != null && list2.Count != 0) { result = State.Success; } else { aiBehaviorTree.ErrorCode = 10; result = State.Failure; } return(result); }
public override State CheckCondition(QuestBehaviour questBehaviour, GameEvent gameEvent, params object[] parameters) { if (this.Location != WorldPosition.Invalid) { IGameService service = Services.GetService <IGameService>(); Diagnostics.Assert(service != null); if (service.Game as global::Game == null) { return(State.Failure); } IWorldPositionningService service2 = service.Game.Services.GetService <IWorldPositionningService>(); global::Empire empire; if (gameEvent != null) { empire = (gameEvent.Empire as global::Empire); } else { empire = questBehaviour.Initiator; } DepartmentOfDefense agency = empire.GetAgency <DepartmentOfDefense>(); if (this.CheckAllArmies) { for (int i = 0; i < agency.Armies.Count; i++) { WorldPosition worldPosition = agency.Armies[i].WorldPosition; int distance = service2.GetDistance(this.Location, worldPosition); int regionIndex = (int)service2.GetRegionIndex(worldPosition); bool flag = service2.IsWaterTile(worldPosition) || service2.IsOceanTile(worldPosition); if (distance == -1) { return(State.Failure); } if (distance <= this.Distance && (this.RegionIndex == -1 || regionIndex == this.RegionIndex) && (!this.ExcludeWaterTile || !flag)) { return(State.Success); } } } else { Army army = agency.GetArmy(this.ArmyGuid); if (army == null) { return(State.Failure); } int distance2 = service2.GetDistance(this.Location, army.WorldPosition); int regionIndex2 = (int)service2.GetRegionIndex(army.WorldPosition); bool flag2 = service2.IsWaterTile(army.WorldPosition) || service2.IsOceanTile(army.WorldPosition); if (distance2 == -1) { return(State.Failure); } if (distance2 <= this.Distance && (this.RegionIndex == -1 || regionIndex2 == this.RegionIndex) && (!this.ExcludeWaterTile || !flag2)) { return(State.Success); } } } return(State.Failure); }
public static bool HasSaveAttackableTargetsNearby(Garrison Attacker, int size, DepartmentOfForeignAffairs departmentOfForeignAffairs, out List <IGarrison> Targets, bool NavalOnly = false) { IIntelligenceAIHelper service = AIScheduler.Services.GetService <IIntelligenceAIHelper>(); IVisibilityService service2 = Services.GetService <IGameService>().Game.Services.GetService <IVisibilityService>(); Targets = new List <IGarrison>(); if (size < 1 || Attacker == null || !(Attacker is IWorldPositionable)) { return(false); } List <global::Empire> list = new List <global::Empire>(Array.FindAll <global::Empire>((Services.GetService <IGameService>().Game as global::Game).Empires, (global::Empire match) => match is MajorEmpire && departmentOfForeignAffairs.IsAtWarWith(match))); if (list.Count < 1) { return(false); } bool result = true; IWorldPositionningService service3 = Services.GetService <IGameService>().Game.Services.GetService <IWorldPositionningService>(); foreach (global::Empire empire in list) { List <Garrison> list2 = new List <Garrison>(); DepartmentOfDefense agency = empire.GetAgency <DepartmentOfDefense>(); DepartmentOfTheInterior agency2 = empire.GetAgency <DepartmentOfTheInterior>(); if (!NavalOnly) { list2.AddRange(agency.Armies.ToList <Army>().FindAll((Army match) => !match.IsSeafaring && !match.IsSettler).Cast <Garrison>()); list2.AddRange(agency2.Cities.Cast <Garrison>()); list2.AddRange(agency2.Camps.Cast <Garrison>()); list2.AddRange(agency2.ConvertedVillages.Cast <Garrison>()); } if (NavalOnly) { list2.AddRange(agency.Armies.ToList <Army>().FindAll((Army match) => match.IsNaval && !match.IsSettler).Cast <Garrison>()); list2.AddRange(agency2.OccupiedFortresses.Cast <Garrison>()); } foreach (Garrison garrison in list2) { if (garrison.UnitsCount > 0 && garrison is IWorldPositionable && (float)service3.GetDistance((garrison as IWorldPositionable).WorldPosition, (Attacker as IWorldPositionable).WorldPosition) <= (float)size && departmentOfForeignAffairs.CanAttack(garrison) && (!garrison.SimulationObject.Tags.Contains(Army.TagCamouflaged) || service2.IsWorldPositionDetectedFor((garrison as IWorldPositionable).WorldPosition, Attacker.Empire)) && service2.IsWorldPositionVisibleFor((garrison as IWorldPositionable).WorldPosition, Attacker.Empire)) { float num = 0f; float num2 = 0f; if (!NavalOnly) { service.EstimateMPInBattleground(Attacker, garrison, ref num, ref num2); } else { num += Attacker.GetPropertyValue(SimulationProperties.MilitaryPower); num2 += garrison.GetPropertyValue(SimulationProperties.MilitaryPower); if (Attacker is Army && (Attacker as Army).IsSeafaring && garrison is Army && !(garrison as Army).IsSeafaring) { num2 *= 0.2f; } } if (num > num2 * 1.5f) { Targets.Add(garrison); } else { result = false; } } } } if (Targets.Count == 0) { result = false; } return(result); }
protected override State Execute(AIBehaviorTree aiBehaviorTree, params object[] parameters) { Army army; if (base.GetArmyUnlessLocked(aiBehaviorTree, "$Army", out army) != AIArmyMission.AIArmyMissionErrorCode.None) { return(State.Failure); } if (!aiBehaviorTree.Variables.ContainsKey(this.TargetVarName)) { aiBehaviorTree.LogError("$Target not set {0}/{1}", new object[] { army.Empire, army.LocalizedName }); return(State.Failure); } IWorldPositionable worldPositionable = aiBehaviorTree.Variables[this.TargetVarName] as IWorldPositionable; if (worldPositionable == null) { aiBehaviorTree.ErrorCode = 10; return(State.Failure); } IGameService service = Services.GetService <IGameService>(); Diagnostics.Assert(service != null); IWorldPositionningService service2 = service.Game.Services.GetService <IWorldPositionningService>(); Diagnostics.Assert(service2 != null); IPathfindingService service3 = service.Game.Services.GetService <IPathfindingService>(); Diagnostics.Assert(service3 != null); WorldPosition worldPosition; if (worldPositionable is City) { City city = worldPositionable as City; if (army.Empire != city.Empire) { worldPosition = this.NewDistrictToAttackCity(army, city); } else { District nearestDistrictToReinforce = this.GetNearestDistrictToReinforce(army, city); if (nearestDistrictToReinforce == null) { aiBehaviorTree.ErrorCode = 2; return(State.Failure); } worldPosition = nearestDistrictToReinforce.WorldPosition; } } else if (worldPositionable is Fortress) { Fortress fortress = worldPositionable as Fortress; WorldPosition worldPosition2 = worldPositionable.WorldPosition; int num = service2.GetDistance(army.WorldPosition, worldPosition2); foreach (PointOfInterest pointOfInterest in fortress.Facilities) { int distance = service2.GetDistance(army.WorldPosition, pointOfInterest.WorldPosition); if (distance < num) { num = distance; worldPosition2 = pointOfInterest.WorldPosition; } } worldPosition = this.GetValidTileToAttack(service3, service2, worldPosition2, army); } else if (worldPositionable is Camp) { worldPosition = this.GetValidTileToAttack(service3, service2, worldPositionable.WorldPosition, army); } else if (worldPositionable is Village) { worldPosition = this.GetValidTileToAttack(service3, service2, worldPositionable.WorldPosition, army); } else if (worldPositionable is OrbSpawnInfo) { worldPosition = worldPositionable.WorldPosition; } else if (worldPositionable is MapBoostSpawnInfo) { worldPosition = worldPositionable.WorldPosition; } else if (worldPositionable is PointOfInterest) { worldPosition = this.GetValidTileToAttack(service3, service2, worldPositionable.WorldPosition, army); } else if (worldPositionable is Kaiju) { worldPosition = this.GetValidTileToAttack(service3, service2, worldPositionable.WorldPosition, army); if (!worldPosition.IsValid && this.AllowBackupPosition) { worldPosition = worldPositionable.WorldPosition; } } else if (worldPositionable is Army) { worldPosition = this.GetValidTileToAttack(service3, service2, worldPositionable.WorldPosition, army); if (!worldPosition.IsValid && this.AllowBackupPosition) { worldPosition = worldPositionable.WorldPosition; } } else if (service2.IsWaterTile(army.WorldPosition) != service2.IsWaterTile(worldPositionable.WorldPosition)) { worldPosition = this.GetValidTileToAttack(service3, service2, worldPositionable.WorldPosition, army); } else { worldPosition = worldPositionable.WorldPosition; } if (worldPosition == WorldPosition.Invalid) { aiBehaviorTree.ErrorCode = 11; return(State.Failure); } if (aiBehaviorTree.Variables.ContainsKey(this.Output_DestinationVarName)) { aiBehaviorTree.Variables[this.Output_DestinationVarName] = worldPosition; } else { aiBehaviorTree.Variables.Add(this.Output_DestinationVarName, worldPosition); } return(State.Success); }