private float ComputeDestroyInterest(CreepingNode target, AIEntity_Empire entityEmpire, Army army) { float normalizedScore = 0.1f; AILayer_Diplomacy layer = entityEmpire.GetLayer <AILayer_Diplomacy>(); if (layer != null) { float num = layer.GetWantWarScore(target.Empire); float num2 = layer.GetAllyScore(target.Empire); if (num2 > 0.5f || num < 0.25f || layer.GetPeaceWish(target.Empire.Index)) { return(-1f); } num = (num - 0.25f) / 0.75f; num2 = (num2 - 0.5f) / 0.5f; float boostFactor = 0.2f * (num - num2); normalizedScore = AILayer.Boost(normalizedScore, boostFactor); } float propertyValue = army.Empire.GetPropertyValue(SimulationProperties.MilitaryPower); float num3 = target.Empire.GetPropertyValue(SimulationProperties.MilitaryPower); if (num3 == 0f) { num3 = 1f; } float num4 = propertyValue / num3; if (num4 < 1f) { return(-1f); } float boostFactor2 = Mathf.Clamp01(num4 / 2f) * 0.2f; return(AILayer.Boost(normalizedScore, boostFactor2)); }
public override void Reset() { base.Reset(); if (!base.Enable) { return; } if (this.departmentOfTheInterior == null) { Diagnostics.LogError("The agent {0} can't get the department of interior.", new object[] { base.Name }); base.Enable = false; return; } Agent[] validatedAgents = new AgentGroupPath("ResourceEvaluationAmas/CityAgentGroup").GetValidatedAgents(base.ParentGroup, "NetCityMoney"); SimulationNormalizedAgent[] array; if (validatedAgents != null) { array = Array.ConvertAll <Agent, SimulationNormalizedAgent>(validatedAgents, (Agent agent) => agent as SimulationNormalizedAgent); } else { array = new SimulationNormalizedAgent[0]; } this.netCityMoneyAgents = array; Diagnostics.Assert(this.netCityMoneyAgents != null); AIEntity_Empire entity = (base.ContextObject as AIPlayer_MajorEmpire).GetEntity <AIEntity_Empire>(); this.aILayer_Victory = entity.GetLayer <AILayer_Victory>(); }
public override void Load() { base.Load(); if (!this.TargetGUID.IsValid) { base.Completion = AICommanderMission.AICommanderMissionCompletion.Fail; return; } IGameEntity gameEntity; if (this.gameEntityRepositoryService.TryGetValue(this.TargetGUID, out gameEntity) && gameEntity is PointOfInterest) { this.POI = (gameEntity as PointOfInterest); } AIEntity_Empire entity = base.Commander.AIPlayer.GetEntity <AIEntity_Empire>(); this.QuestBTlayer = entity.GetLayer <AILayer_QuestBTController>(); if (this.POI != null) { this.village = this.POI.Region.MinorEmpire.GetAgency <BarbarianCouncil>().GetVillageAt(this.POI.WorldPosition); return; } if (gameEntity is TerraformDevice) { this.device = (gameEntity as TerraformDevice); } }
protected override bool Initialize(AIBehaviorTree aiBehaviorTree) { this.isDlcActive = true; IDownloadableContentService service = Services.GetService <IDownloadableContentService>(); if (!service.IsShared(DownloadableContent13.ReadOnlyName)) { this.isDlcActive = false; } if (!(aiBehaviorTree.AICommander.Empire is MajorEmpire)) { this.isDlcActive = false; } if (this.isDlcActive) { IGameService service2 = Services.GetService <IGameService>(); Diagnostics.Assert(service2 != null); this.gameEntityRepositoryService = service2.Game.Services.GetService <IGameEntityRepositoryService>(); this.aiDataRepositoryHelper = AIScheduler.Services.GetService <IAIDataRepositoryAIHelper>(); this.orbAIHelper = AIScheduler.Services.GetService <IOrbAIHelper>(); this.intelligenceAiHelper = AIScheduler.Services.GetService <IIntelligenceAIHelper>(); AIEntity_Empire entity = aiBehaviorTree.AICommander.AIPlayer.GetEntity <AIEntity_Empire>(); this.accountManager = entity.GetLayer <AILayer_AccountManager>(); } return(base.Initialize(aiBehaviorTree)); }
protected override bool Initialize(AIBehaviorTree aiBehaviorTree) { if (aiBehaviorTree.AICommander.Empire is MajorEmpire) { AIEntity_Empire entity = aiBehaviorTree.AICommander.AIPlayer.GetEntity <AIEntity_Empire>(); this.aILayer_Trade = entity.GetLayer <AILayer_Trade>(); } return(base.Initialize(aiBehaviorTree)); }
private float ComputePillageInterest(PointOfInterest target, AIEntity_Empire entityEmpire, Army army) { float normalizedScore = 0.1f; AILayer_Diplomacy layer = entityEmpire.GetLayer <AILayer_Diplomacy>(); if (layer != null) { if (layer.GetPeaceWish(target.Region.City.Empire.Index)) { return(-1f); } float num = layer.GetWantWarScore(target.Region.City.Empire); float num2 = layer.GetAllyScore(target.Region.City.Empire); if (num2 > 0.5f || num < 0.25f) { return(-1f); } num = (num - 0.25f) / 0.75f; num2 = (num2 - 0.5f) / 0.5f; float boostFactor = 0.2f * (num - num2); normalizedScore = AILayer.Boost(normalizedScore, boostFactor); } float propertyValue = army.Empire.GetPropertyValue(SimulationProperties.MilitaryPower); float num3 = target.Region.City.Empire.GetPropertyValue(SimulationProperties.MilitaryPower); if (num3 == 0f) { num3 = 1f; } float num4 = propertyValue / num3; if (num4 < 1f) { return(-1f); } float boostFactor2 = Mathf.Clamp01(num4 / 2f) * 0.2f; normalizedScore = AILayer.Boost(normalizedScore, boostFactor2); string a = target.Type; float boostFactor3; if (a == "ResourceDeposit") { boostFactor3 = 0.2f; } else if (a == "WatchTower") { boostFactor3 = 0.2f; } else { boostFactor3 = 0.2f; } normalizedScore = AILayer.Boost(normalizedScore, boostFactor3); return(AILayer.Boost(normalizedScore, this.ComputeInfluence(army, target) * 0.5f)); }
public override void Initialize(AICommander commander) { base.Initialize(commander); Diagnostics.Assert(AIScheduler.Services != null); this.intelligenceAiHelper = AIScheduler.Services.GetService <IIntelligenceAIHelper>(); IGameService service = Services.GetService <IGameService>(); Diagnostics.Assert(service != null); this.worldPositionningService = service.Game.Services.GetService <IWorldPositionningService>(); Diagnostics.Assert(this.worldPositionningService != null); this.pathfindingService = service.Game.Services.GetService <IPathfindingService>(); this.personalityAIHelper = AIScheduler.Services.GetService <IPersonalityAIHelper>(); this.unitInGarrisonPercent = this.personalityAIHelper.GetRegistryValue <float>(base.Commander.Empire, string.Format("{0}/{1}", AILayer_Military.RegistryPath, "UnitInGarrisonPercent"), this.unitInGarrisonPercent); this.unitInGarrisonPriorityMultiplierPerSlot = this.personalityAIHelper.GetRegistryValue <float>(base.Commander.Empire, string.Format("{0}/{1}", AILayer_Military.RegistryPath, "UnitInGarrisonPriorityMultiplierPerSlot"), this.unitInGarrisonPriorityMultiplierPerSlot); this.unitRatioBoost = this.personalityAIHelper.GetRegistryValue <float>(base.Commander.Empire, string.Format("{0}/{1}", AILayer_Military.RegistryPath, "UnitRatioBoost"), this.unitRatioBoost); AIEntity_Empire entity = commander.AIPlayer.GetEntity <AIEntity_Empire>(); this.militaryLayer = entity.GetLayer <AILayer_Military>(); this.ailayer_War = entity.GetLayer <AILayer_War>(); }
public override bool Initialize(BehaviourTree behaviourTree) { IGameService service = Services.GetService <IGameService>(); this.worldPositionningService = service.Game.Services.GetService <IWorldPositionningService>(); if ((behaviourTree as AIBehaviorTree).AICommander.Empire is MajorEmpire) { AIEntity_Empire entity = (behaviourTree as AIBehaviorTree).AICommander.AIPlayer.GetEntity <AIEntity_Empire>(); this.aILayer_Terraformation = entity.GetLayer <AILayer_Terraformation>(); } return(base.Initialize(behaviourTree)); }
public override void Load() { base.Load(); IGameService service = Services.GetService <IGameService>(); this.gameEntityRepositoryService = service.Game.Services.GetService <IGameEntityRepositoryService>(); this.departmentOfScience = base.Empire.GetAgency <DepartmentOfScience>(); this.departmentOfInternalAffairs = base.Empire.GetAgency <DepartmentOfInternalAffairs>(); AIEntity_Empire entity = base.AIPlayer.GetEntity <AIEntity_Empire>(); this.villageLayer = entity.GetLayer <AILayer_Village>(); }
protected override bool Initialize(AIBehaviorTree aiBehaviorTree) { if (aiBehaviorTree.AICommander.Empire is MajorEmpire) { AIEntity_Empire entity = aiBehaviorTree.AICommander.AIPlayer.GetEntity <AIEntity_Empire>(); this.aILayer_Trade = entity.GetLayer <AILayer_Trade>(); } ArmyAction armyAction; Databases.GetDatabase <ArmyAction>(false).TryGetValue("ArmyActionTameUnstunnedKaiju", out armyAction); this.armyAction_TameUnstunnedKaiju = (armyAction as ArmyAction_TameUnstunnedKaiju); return(base.Initialize(aiBehaviorTree)); }
public override void Load() { base.Load(); if (this.RegionTarget == null || this.RegionTarget.MinorEmpire == null) { base.Completion = AICommanderMission.AICommanderMissionCompletion.Fail; return; } this.departmentOfInternalAffairs = base.Commander.Empire.GetAgency <DepartmentOfInternalAffairs>(); this.barbarianCouncil = this.RegionTarget.MinorEmpire.GetAgency <BarbarianCouncil>(); AIEntity_Empire entity = base.Commander.AIPlayer.GetEntity <AIEntity_Empire>(); this.villageLayer = entity.GetLayer <AILayer_Village>(); this.Village = this.SelectVillage(); }
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); }
protected override State Execute(AIBehaviorTree aiBehaviorTree, params object[] parameters) { if (!this.downloadableContentService.IsShared(DownloadableContent13.ReadOnlyName)) { return(State.Failure); } Army army; if (base.GetArmyUnlessLocked(aiBehaviorTree, "$Army", out army) != AIArmyMission.AIArmyMissionErrorCode.None) { return(State.Failure); } if (!(army.Empire is MajorEmpire)) { return(State.Failure); } if (!string.IsNullOrEmpty(this.OpportunityMaximumTurnName) && aiBehaviorTree.Variables.ContainsKey(this.OpportunityMaximumTurnName)) { this.OpportunityMaximumTurn = (float)aiBehaviorTree.Variables[this.OpportunityMaximumTurnName]; } AIEntity_Empire entity = aiBehaviorTree.AICommander.AIPlayer.GetEntity <AIEntity_Empire>(); if (this.DiplomacyLayer == null && aiBehaviorTree.AICommander.Empire is MajorEmpire) { this.DiplomacyLayer = entity.GetLayer <AILayer_Diplomacy>(); } Region region = this.worldPositionningService.GetRegion(army.WorldPosition); bool flag = false; AIData_Army aidata_Army; if (this.aiDataRepositoryHelper.TryGetAIData <AIData_Army>(army.GUID, out aidata_Army)) { flag = aidata_Army.IsManta; } float num = flag ? -1000f : 0.1f; float propertyValue = army.GetPropertyValue(SimulationProperties.MaximumMovement); OrbSpawnInfo orbSpawnInfo = null; for (int i = 0; i < this.orbAIHelper.OrbSpawns.Count; i++) { OrbSpawnInfo orbSpawnInfo2 = this.orbAIHelper.OrbSpawns[i]; if (orbSpawnInfo2 != null && orbSpawnInfo2.CurrentOrbCount != 0f) { bool flag2 = this.worldPositionningService.IsWaterTile(orbSpawnInfo2.WorldPosition); if (flag || flag2 != !army.IsSeafaring) { float num2 = 0.5f; if (entity != null) { num2 = this.ComputeOrbCollectingScore(orbSpawnInfo2, entity, army); } if (num2 > 0f) { Region region2 = this.worldPositionningService.GetRegion(orbSpawnInfo2.WorldPosition); if (flag || region2.ContinentID == region.ContinentID) { float num3 = (float)this.worldPositionningService.GetDistance(army.WorldPosition, orbSpawnInfo2.WorldPosition) / propertyValue; if (num3 <= this.MaximumTurnDistance) { if (flag) { num2 = -num3 + num2 * 1E-09f; } else { float orbDistanceExponent = this.orbAIHelper.GetOrbDistanceExponent(entity.Empire); float num4 = 1f + Mathf.Pow(num3, orbDistanceExponent); num2 /= num4; } if (num2 > num) { num = num2; orbSpawnInfo = orbSpawnInfo2; } } } } } } } if (orbSpawnInfo == null) { return(State.Failure); } if (num < this.orbAIHelper.EmpireOrbNeedThreshold[army.Empire.Index] && !flag) { return(State.Failure); } if (this.OpportunityMaximumTurn >= 0f) { int num5 = 0; int num6 = 0; if (aiBehaviorTree.Variables.ContainsKey(this.OpportunityMainTargetPosition)) { WorldPosition mainTargetPosition = (WorldPosition)aiBehaviorTree.Variables[this.OpportunityMainTargetPosition]; if (!AIBehaviorTreeNode_Decorator_EvaluateOpportunity.IsDetourWorthCheckingFast(this.worldPositionningService, army, orbSpawnInfo.WorldPosition, mainTargetPosition, out num6, out num5)) { return(State.Failure); } } if ((float)(num5 - num6) > this.OpportunityMaximumTurn) { return(State.Failure); } } if (aiBehaviorTree.Variables.ContainsKey(this.Output_TargetVarName)) { aiBehaviorTree.Variables[this.Output_TargetVarName] = orbSpawnInfo; } else { aiBehaviorTree.Variables.Add(this.Output_TargetVarName, orbSpawnInfo); } return(State.Success); }