protected override void ExecuteNeeds(StaticString context, StaticString pass) { base.ExecuteNeeds(context, pass); this.colossusData.Clear(); for (int i = 0; i < this.departmentOfDefense.Armies.Count; i++) { AIData_Army aidata = this.aiDataRepositoryHelper.GetAIData <AIData_Army>(this.departmentOfDefense.Armies[i].GUID); if (aidata != null && aidata.IsColossus) { this.colossusData.Add(aidata); } } int index; for (index = 0; index < this.colossusData.Count; index++) { if (!this.aiCommanders.Exists((AICommander match) => match.ForceArmyGUID == this.colossusData[index].Army.GUID)) { this.AddCommander(new AICommander_Colossus { ForceArmyGUID = this.colossusData[index].Army.GUID, Empire = base.AIEntity.Empire, AIPlayer = base.AIEntity.AIPlayer }); } } this.UpdateColossusMissions(); }
protected override bool TryGetArmyData() { if (!this.IsMissionValid()) { this.requestGarrison = null; this.Fail(); return(false); } if (this.requestGarrison == null) { this.SendGarrisonRequest(); } if (base.AIDataArmyGUID.IsValid) { AIData_Army aidata = this.aiDataRepository.GetAIData <AIData_Army>(base.AIDataArmyGUID); if (aidata != null && aidata.CommanderMission != null && aidata.CommanderMission != this) { base.AIDataArmyGUID = GameEntityGUID.Zero; } } if (this.City.BesiegingEmpire != null) { return(true); } if (base.AIDataArmyGUID.IsValid) { return(true); } if (this.State == TickableState.NeedTick) { this.State = TickableState.Optional; } return(true); }
protected override bool TryComputeArmyMissionParameter() { base.ArmyMissionParameters.Clear(); if (base.AIDataArmyGUID == GameEntityGUID.Zero) { return(false); } AIData_Army aidata = this.aiDataRepository.GetAIData <AIData_Army>(base.AIDataArmyGUID); if (aidata == null) { return(false); } if (this.colossusCommander.CurrentColossusMission == null) { return(false); } Diagnostics.Assert(aidata.Army != null); if (base.Commander.Empire != null && base.Commander.Empire is MajorEmpire && this.ailayer_War != null) { this.ailayer_War.AssignDefensiveArmyToCity(aidata.Army); } Army item = this.ChooseTheBetterArmyToSupport(); return(base.TryCreateArmyMission("RoamingArmySupport", new List <object> { item })); }
protected override bool TryComputeArmyMissionParameter() { if (this.RegionTarget == null) { base.Completion = AICommanderMission.AICommanderMissionCompletion.Fail; return(false); } base.ArmyMissionParameters.Clear(); if (base.AIDataArmyGUID == GameEntityGUID.Zero) { return(false); } AIData_Army aidata = this.aiDataRepository.GetAIData <AIData_Army>(base.AIDataArmyGUID); if (aidata == null) { base.Completion = AICommanderMission.AICommanderMissionCompletion.Fail; return(false); } Army maxHostileArmy = AILayer_Pacification.GetMaxHostileArmy(base.Commander.Empire, this.RegionTarget.Index); if (maxHostileArmy != null && aidata.Army.GetPropertyValue(SimulationProperties.MilitaryPower) > 0.8f * maxHostileArmy.GetPropertyValue(SimulationProperties.MilitaryPower)) { return(base.TryCreateArmyMission("MajorFactionAttackArmy", new List <object> { maxHostileArmy, this.RegionTarget.Index })); } return(base.TryCreateArmyMission("MajorFactionRoaming", new List <object> { this.RegionTarget.Index })); }
protected override bool TryComputeArmyMissionParameter() { base.ArmyMissionParameters.Clear(); AIData_Army aidata = this.aiDataRepository.GetAIData <AIData_Army>(base.AIDataArmyGUID); if (aidata == null || aidata.Army == null) { return(false); } if (aidata.Army.IsPrivateers) { if (base.TryCreateArmyMission("BesiegeCity", new List <object> { this.TargetCity, this.MayAttack })) { return(true); } } else if (base.TryCreateArmyMission("ConvertToPrivateers", new List <object> { this.TargetCity })) { return(true); } return(false); }
protected override bool TryComputeArmyMissionParameter() { base.ArmyMissionParameters.Clear(); if (base.AIDataArmyGUID == GameEntityGUID.Zero) { return(false); } AIData_Army aidata = this.aiDataRepository.GetAIData <AIData_Army>(base.AIDataArmyGUID); if (this.city == null || aidata == null) { base.Completion = AICommanderMission.AICommanderMissionCompletion.Fail; return(false); } List <object> list = new List <object>(); list.Add(this.city); if (this.city.BesiegingEmpireIndex >= 0) { return(base.TryCreateArmyMission("FreeCity", list)); } if (this.city.MaximumUnitSlot > this.city.CurrentUnitSlot + aidata.Army.CurrentUnitSlot) { return(base.TryCreateArmyMission("DefendCity_Bail", list)); } return(base.TryCreateArmyMission("ReachTarget", list)); }
private void TryRecruitingExplorers() { if (this.City == null) { return; } DepartmentOfDefense agency = base.Commander.Empire.GetAgency <DepartmentOfDefense>(); List <AIData_Army> list = new List <AIData_Army>(); for (int i = 0; i < agency.Armies.Count; i++) { Army army = agency.Armies[i]; if (army.StandardUnits.Count > army.MaximumUnitSlot / 4) { AIData_Army aidata = this.aiDataRepository.GetAIData <AIData_Army>(army.GUID); if (aidata != null && !aidata.IsSolitary && !aidata.Army.IsSeafaring && !aidata.Army.HasCatspaw && !(aidata.Army is KaijuArmy) && (aidata.CommanderMission == null || (aidata.CommanderMission.Commander != null && aidata.CommanderMission.Commander.Category == AICommanderMissionDefinition.AICommanderCategory.Exploration))) { list.Add(aidata); } } } if (list.Count > 0) { list.Sort((AIData_Army left, AIData_Army right) => - 1 * left.Army.GetPropertyValue(SimulationProperties.MilitaryPower).CompareTo(right.Army.GetPropertyValue(SimulationProperties.MilitaryPower))); if (list[0].CommanderMission != null) { list[0].CommanderMission.Interrupt(); } base.AIDataArmyGUID = list[0].Army.GUID; base.TryGetArmyData(); } }
protected bool TryCreateArmyMission(string missionType, List <object> missionParameter) { if (this.AIDataArmyGUID == GameEntityGUID.Zero) { return(false); } AIData_Army aidata = this.aiDataRepository.GetAIData <AIData_Army>(this.AIDataArmyGUID); if (aidata == null) { this.AIDataArmyGUID = GameEntityGUID.Zero; return(false); } AIArmyMissionDefinition value = Databases.GetDatabase <AIArmyMissionDefinition>(false).GetValue(missionType); Diagnostics.Assert(value != null); if (value == null) { return(false); } if (aidata.ArmyMission == null || aidata.ArmyMission.AIArmyMissionDefinition == null || aidata.ArmyMission.AIArmyMissionDefinition.Name != missionType) { aidata.AssignArmyMission(this.Commander, value, missionParameter.ToArray()); } else if (!aidata.ArmyMission.TrySetParameters(missionParameter.ToArray())) { aidata.AssignArmyMission(this.Commander, value, missionParameter.ToArray()); } return(true); }
private void SelectUnitToShift(AIData_Army army, float maxCost, out float cost, out GameEntityGUID[] shiftingUnitGuids) { cost = 0f; List <GameEntityGUID> list = new List <GameEntityGUID>(); DepartmentOfTheTreasury agency = army.Army.Empire.GetAgency <DepartmentOfTheTreasury>(); foreach (Unit unit in army.Army.Units) { if (this.aiDataRepositoryHelper.IsGUIDValid(unit.GUID)) { if (unit.CanShift()) { ConstructionCost unitForceShiftingCost = agency.GetUnitForceShiftingCost(unit); float value = unitForceShiftingCost.Value; if (cost + value > maxCost) { break; } cost += value; list.Add(unit.GUID); } } } shiftingUnitGuids = list.ToArray(); }
protected override void Running() { AIData_Army aidata = this.aiDataRepository.GetAIData <AIData_Army>(base.AIDataArmyGUID); if (aidata == null || aidata.ArmyMission == null || aidata.Army == null) { base.Completion = AICommanderMission.AICommanderMissionCompletion.Interrupted; return; } int num = (int)base.Commander.Empire.GetPropertyValue(SimulationProperties.ArmyUnitSlot); int count = aidata.Army.StandardUnits.Count; if (num != count) { float num2; bool flag; bool flag2; this.GetNeededArmyPower(out num2, out flag, out flag2); if (flag) { base.Completion = AICommanderMission.AICommanderMissionCompletion.Interrupted; return; } float num3 = 0f; float num4 = 0f; foreach (AICommanderMission aicommanderMission in base.Commander.Missions) { IGameEntity gameEntity = null; if (aicommanderMission.AIDataArmyGUID.IsValid && this.gameEntityRepositoryService.TryGetValue(aicommanderMission.AIDataArmyGUID, out gameEntity) && gameEntity is Army) { Army army = gameEntity as Army; if (army.GUID.IsValid) { float num5 = this.intelligenceAIHelper.EvaluateMilitaryPowerOfGarrison(base.Commander.Empire, army, 0); num3 += num5; if (army.GUID == aidata.Army.GUID) { num4 = num5; } } } } num2 *= this.personalityMPTenacity; if (num2 > num3 || ((float)count < 0.5f * (float)num && num2 > num4)) { base.Completion = AICommanderMission.AICommanderMissionCompletion.Interrupted; return; } } if (this.IsMissionCompleted()) { base.State = TickableState.NoTick; aidata.ResetArmyMission(); base.Completion = AICommanderMission.AICommanderMissionCompletion.Success; return; } base.Running(); }
private bool TransferUnits(GameEntityGUID destinationGuid) { AIData_Army aidata = this.aiDataRepository.GetAIData <AIData_Army>(base.AIDataArmyGUID); if (aidata.Army.IsInEncounter || aidata.Army.IsLocked) { Diagnostics.LogWarning("[AICommanderMission_RegroupArmyAt] Transfer source IsInEncounter or IsLocked"); return(false); } IGameEntity gameEntity; if (!this.gameEntityRepositoryService.TryGetValue(destinationGuid, out gameEntity)) { Diagnostics.LogWarning("[AICommanderMission_RegroupArmyAt] Destination Guid is not valid"); return(false); } IGarrison garrison = gameEntity as IGarrison; if (garrison == null) { Diagnostics.LogWarning("[AICommanderMission_RegroupArmyAt] Destination Guid is not a Garrison"); return(false); } if (garrison.IsInEncounter) { Diagnostics.LogWarning("[AICommanderMission_RegroupArmyAt] Transfer destination IsInEncounter"); return(false); } if (garrison is Army) { Army army = garrison as Army; if (army.IsLocked) { Diagnostics.LogWarning("[AICommanderMission_RegroupArmyAt] Transfer destination IsLocked"); return(false); } if (this.worldPositionningService.GetDistance(aidata.Army.WorldPosition, army.WorldPosition) != 1 || !this.pathfindingService.IsTransitionPassable(aidata.Army.WorldPosition, army.WorldPosition, aidata.Army, (PathfindingFlags)0, null)) { Diagnostics.LogWarning("[AICommanderMission_RegroupArmyAt] Transfer destination is not valid"); return(false); } } GameEntityGUID[] array = null; this.ClampUnitToGarrison(garrison, this.UnitGuids, out array); if (array != null && array.Length != 0) { OrderTransferUnits order = new OrderTransferUnits(base.Commander.Empire.Index, base.AIDataArmyGUID, destinationGuid, array, false); base.Commander.Empire.PlayerControllers.Server.PostOrder(order, out this.currentTicket, new EventHandler <TicketRaisedEventArgs>(this.OrderTransferUnitToArmyTicketRaised)); if (aidata.CommanderMission != this) { Diagnostics.LogWarning("LOCKING: [AICommanderMission_RegroupArmyAt] Strange desynchronization between the actual Army CommanderMission and the current CommanderMission"); } aidata.UnassignCommanderMission(); return(true); } return(false); }
protected override bool TryComputeArmyMissionParameter() { if (this.RegionTarget == null) { base.Completion = AICommanderMission.AICommanderMissionCompletion.Fail; return(false); } base.ArmyMissionParameters.Clear(); if (base.AIDataArmyGUID == GameEntityGUID.Zero) { base.Completion = AICommanderMission.AICommanderMissionCompletion.Fail; return(false); } AIData_Army aidata = this.aiDataRepository.GetAIData <AIData_Army>(base.AIDataArmyGUID); if (aidata == null || aidata.Army == null) { base.Completion = AICommanderMission.AICommanderMissionCompletion.Fail; return(false); } if (this.RegionTarget.City != null && this.departmentOfForeignAffairs.IsAtWarWith(this.RegionTarget.City.Empire)) { return(base.TryCreateArmyMission("BesiegeCity", new List <object> { this.RegionTarget.City, true })); } if (this.departmentOfScience.CanPillage() && this.departmentOfForeignAffairs.CanMoveOn(this.RegionTarget.Index, aidata.Army.IsPrivateers)) { if (base.TryCreateArmyMission("MajorFactionRoaming", new List <object> { this.RegionTarget.Index })) { return(true); } } else { List <object> list = new List <object>(); this.CalculateRegroupPositionForWaitToAttack(); if (this.targetFrontierPosition.IsValid) { list.Add(this.targetFrontierPosition); } else { list.Add(this.RegionTarget.City.WorldPosition); } if (base.TryCreateArmyMission("ScoutRegion", list)) { return(true); } } return(false); }
protected override bool TryComputeArmyMissionParameter() { if (this.RegionTarget == null) { base.Completion = AICommanderMission.AICommanderMissionCompletion.Fail; return(false); } base.ArmyMissionParameters.Clear(); if (base.AIDataArmyGUID == GameEntityGUID.Zero) { return(false); } AIData_Army aidata = this.aiDataRepository.GetAIData <AIData_Army>(base.AIDataArmyGUID); if (aidata == null) { return(false); } Diagnostics.Assert(aidata != null); Diagnostics.Assert(aidata.Army != null); List <object> list = new List <object>(); list.Add(this.RegionTarget.Index); list.Add(this.IsWarBased); if (base.Commander.Empire != null && base.Commander.Empire is MajorEmpire) { if (this.ailayer_War == null) { GameServer gameServer = (Services.GetService <ISessionService>().Session as global::Session).GameServer as GameServer; AIPlayer_MajorEmpire aiplayer_MajorEmpire; if (gameServer.AIScheduler != null && gameServer.AIScheduler.TryGetMajorEmpireAIPlayer(base.Commander.Empire as MajorEmpire, out aiplayer_MajorEmpire)) { AIEntity entity = aiplayer_MajorEmpire.GetEntity <AIEntity_Empire>(); if (entity != null) { this.ailayer_War = entity.GetLayer <AILayer_War>(); } } } if (this.ailayer_War != null) { this.ailayer_War.AssignDefensiveArmyToCity(aidata.Army); } } if (this.IsWarBased) { if (base.TryCreateArmyMission("MajorFactionWarRoaming", list)) { return(true); } } else if (base.TryCreateArmyMission("MajorFactionRoaming", list)) { return(true); } return(false); }
protected override void Running() { if (!base.AIDataArmyGUID.IsValid || this.ruinCommander == null) { base.Completion = AICommanderMission.AICommanderMissionCompletion.Success; return; } if (base.Commander.IsMissionFinished(false)) { base.Completion = AICommanderMission.AICommanderMissionCompletion.Success; return; } base.Running(); if (this.ruinCommander.PointOfInterests.Count > 0) { AIData_Army aidata = this.aiDataRepository.GetAIData <AIData_Army>(base.AIDataArmyGUID); if (aidata.ArmyMission != null && aidata.ArmyMission.Completion == AIArmyMission.AIArmyMissionCompletion.Fail && aidata.ArmyMission.ErrorCode == AIArmyMission.AIArmyMissionErrorCode.PathNotFound) { if (Amplitude.Unity.Framework.Application.Preferences.EnableModdingTools) { Diagnostics.Log("ELCP {0} {1} AICommanderMission_HuntRuin errorcode {2} target {3} {4} {5} {6}", new object[] { base.Commander.Empire, aidata.Army.LocalizedName, aidata.ArmyMission.ErrorCode, this.ruinCommander.PointOfInterests[0].WorldPosition, this.ruinCommander.PointOfInterests.Count, this.lastErrorTurn, this.errorTicks }); } if (this.lastErrorTurn != this.game.Turn) { this.lastErrorTurn = this.game.Turn; this.errorTicks = 1; } else { this.errorTicks++; if (this.errorTicks > 2) { this.ruinCommander.PointOfInterests.RemoveAt(0); this.errorTicks = 0; } } } } if (base.State == TickableState.NoTick && this.ruinCommander.PointOfInterests.Count > 0) { AIData_Army aidata2 = this.aiDataRepository.GetAIData <AIData_Army>(base.AIDataArmyGUID); if (aidata2 != null && aidata2.Army != null && aidata2.Army.GetPropertyValue(SimulationProperties.Movement) > 0.01f) { base.State = TickableState.Optional; } } }
public void SetArmyFree() { if (this.AIDataArmyGUID != GameEntityGUID.Zero) { AIData_Army aidata = this.aiDataRepository.GetAIData <AIData_Army>(this.AIDataArmyGUID); if (aidata != null && aidata.CommanderMission == this) { aidata.UnassignCommanderMission(); } this.AIDataArmyGUID = GameEntityGUID.Zero; } }
protected override bool TryGetArmyData() { if (base.TryGetArmyData()) { return(true); } if (this.requestArmy != null) { if (this.requestArmy.State == BlackboardMessage.StateValue.Message_Canceled) { this.requestArmy = null; return(false); } this.requestArmy.SetPriority(base.Commander.GetPriority(this)); if (this.requestArmy.ExecutionState == RequestUnitListMessage.RequestUnitListState.ArmyAvailable) { GameEntityGUID armyGUID = this.requestArmy.ArmyGUID; this.requestArmy.State = BlackboardMessage.StateValue.Message_Success; this.requestArmy.TimeOut = 0; this.requestArmy = null; AIData_Army aidata = this.aiDataRepository.GetAIData <AIData_Army>(armyGUID); if (aidata == null) { base.Completion = AICommanderMission.AICommanderMissionCompletion.Fail; return(false); } if (!aidata.AssignCommanderMission(this)) { base.Completion = AICommanderMission.AICommanderMissionCompletion.Fail; return(false); } base.AIDataArmyGUID = armyGUID; return(true); } else if (this.requestArmy.ExecutionState == RequestUnitListMessage.RequestUnitListState.Regrouping) { base.State = TickableState.NeedTick; } else if (this.requestArmy.ExecutionState == RequestUnitListMessage.RequestUnitListState.RegroupingPending) { base.State = TickableState.NoTick; } else if (this.requestArmy.ExecutionState == RequestUnitListMessage.RequestUnitListState.Pending) { base.State = TickableState.NoTick; } } else { this.SendArmyRequest(); } return(false); }
private void OrderTransferUnitToNewArmyTicketRaised(object sender, TicketRaisedEventArgs e) { this.createFirstArmyTicket = null; if (e.Result != PostOrderResponse.Processed) { for (int i = 0; i < this.UnitGuids.Length; i++) { IGameEntity gameEntity; if (this.gameEntityRepositoryService.TryGetValue(this.UnitGuids[i], out gameEntity)) { Unit unit = gameEntity as Unit; if (unit != null && (double)unit.GetPropertyValue(SimulationProperties.Movement) < 0.001) { base.Completion = AICommanderMission.AICommanderMissionCompletion.Fail; } return; } } base.Completion = AICommanderMission.AICommanderMissionCompletion.Initializing; return; } OrderTransferGarrisonToNewArmy orderTransferGarrisonToNewArmy = e.Order as OrderTransferGarrisonToNewArmy; AIData_Army aidata = this.aiDataRepository.GetAIData <AIData_Army>(orderTransferGarrisonToNewArmy.ArmyGuid); if (aidata != null) { aidata.UnassignArmyMission(); for (int j = 0; j < this.UnitGuids.Length; j++) { AIData_Unit aidata_Unit; this.aiDataRepository.TryGetAIData <AIData_Unit>(this.UnitGuids[j], out aidata_Unit); if (aidata_Unit == null) { Diagnostics.LogWarning("[AICommanderMission_RegroupArmyAt] no AIData for Unit {0}", new object[] { this.UnitGuids[j].ToString() }); } else { aidata_Unit.TryUnLockUnit(base.InternalGUID); } } base.AIDataArmyGUID = aidata.GameEntity.GUID; if (!aidata.AssignCommanderMission(this)) { Diagnostics.LogWarning(string.Format("LOCKING Problem in [AICommanderMission_RegroupArmyAt]", new object[0])); } } }
private bool CanTransferToNearMission() { AIData_Army aidata = this.aiDataRepository.GetAIData <AIData_Army>(base.AIDataArmyGUID); if (aidata == null || aidata.Army == null || aidata.Army.IsLocked || aidata.Army.IsInEncounter) { return(false); } foreach (AICommanderMission aicommanderMission in this.AICommanderRegroupArmies.Missions) { AICommanderMission_RegroupArmyAt aicommanderMission_RegroupArmyAt = (AICommanderMission_RegroupArmyAt)aicommanderMission; AIData_Army aidata2 = this.aiDataRepository.GetAIData <AIData_Army>(aicommanderMission_RegroupArmyAt.AIDataArmyGUID); if (aicommanderMission_RegroupArmyAt != this && aicommanderMission_RegroupArmyAt.AIDataArmyGUID.IsValid && aidata2 != null && aidata2.Army != null && !aidata2.Army.IsLocked && !aidata2.Army.IsInEncounter && aicommanderMission_RegroupArmyAt.targetTransferArmy == null && this.worldPositionningService.GetDistance(aidata.Army.WorldPosition, aidata2.Army.WorldPosition) == 1 && this.pathfindingService.IsTransitionPassable(aidata.Army.WorldPosition, aidata2.Army.WorldPosition, aidata.Army, (PathfindingFlags)0, null)) { if (aidata.Army.GetPropertyValue(SimulationProperties.Movement) <= 0f) { if (this.IsArmyBesiegingACity(aidata2.Army.GUID)) { continue; } if (aidata2.Army.GetPropertyValue(SimulationProperties.Movement) > 0f && aicommanderMission_RegroupArmyAt.TransferUnits(aidata.GameEntity.GUID)) { aicommanderMission_RegroupArmyAt.targetTransferArmy = aidata; aicommanderMission_RegroupArmyAt.Completion = AICommanderMission.AICommanderMissionCompletion.Success; int num = this.UnitGuids.Length; Array.Resize <GameEntityGUID>(ref this.UnitGuids, this.UnitGuids.Length + aicommanderMission_RegroupArmyAt.UnitGuids.Length); for (int i = 0; i < aicommanderMission_RegroupArmyAt.UnitGuids.Length; i++) { this.UnitGuids[num + i] = aicommanderMission_RegroupArmyAt.UnitGuids[i]; } } } else if (this.TransferUnits(aidata2.GameEntity.GUID)) { this.targetTransferArmy = aidata2; base.Completion = AICommanderMission.AICommanderMissionCompletion.Success; int num2 = aicommanderMission_RegroupArmyAt.UnitGuids.Length; Array.Resize <GameEntityGUID>(ref aicommanderMission_RegroupArmyAt.UnitGuids, this.UnitGuids.Length + aicommanderMission_RegroupArmyAt.UnitGuids.Length); for (int j = 0; j < this.UnitGuids.Length; j++) { aicommanderMission_RegroupArmyAt.UnitGuids[num2 + j] = this.UnitGuids[j]; } } return(true); } } return(false); }
protected override bool TryComputeArmyMissionParameter() { base.ArmyMissionParameters.Clear(); AIData_Army aidata = this.aiDataRepository.GetAIData <AIData_Army>(base.AIDataArmyGUID); if (aidata == null || aidata.Army == null) { return(false); } Camp targetCamp = this.TargetCamp; return(base.TryCreateArmyMission("AttackCamp", new List <object> { targetCamp })); }
private Army ChooseArmyToSupport() { float num = -1f; Army result = null; for (int i = 0; i < this.departmentOfDefense.Armies.Count; i++) { AIData_Army aidata = this.aiDataRepositoryHelper.GetAIData <AIData_Army>(this.departmentOfDefense.Armies[i].GUID); if (aidata != null && num < aidata.SupportScore) { num = aidata.SupportScore; result = this.departmentOfDefense.Armies[i]; } } return(result); }
protected override void Success() { base.Success(); if (this.AICommanderRegroupArmies.MissionHasAllUnits(this) && this.AICommanderRegroupArmies.RequestUnitListMessageID != 0UL) { AIData_Army aidata = this.aiDataRepository.GetAIData <AIData_Army>(base.AIDataArmyGUID); Diagnostics.Assert(aidata != null); RequestArmyMessage requestArmyMessage = base.Commander.AIPlayer.Blackboard.GetMessage(this.AICommanderRegroupArmies.RequestUnitListMessageID) as RequestArmyMessage; if (requestArmyMessage != null) { requestArmyMessage.ArmyGUID = aidata.Army.GUID; requestArmyMessage.ExecutionState = RequestUnitListMessage.RequestUnitListState.ArmyAvailable; requestArmyMessage.TimeOut = 1; if (requestArmyMessage.HeroGUID != GameEntityGUID.Zero) { OrderChangeHeroAssignment order = new OrderChangeHeroAssignment(base.Commander.Empire.Index, requestArmyMessage.HeroGUID, aidata.Army.GUID); Ticket ticket; base.Commander.Empire.PlayerControllers.Client.PostOrder(order, out ticket, null); } if (this.majorEmpireAIEntity != null && this.majorEmpireAIEntity.GetCommanderMissionBasedOnItsArmyRequestArmy(requestArmyMessage.ID) != null) { base.SetArmyFree(); this.Process(); return; } } else { RequestGarrisonMessage requestGarrisonMessage = base.Commander.AIPlayer.Blackboard.GetMessage(this.AICommanderRegroupArmies.RequestUnitListMessageID) as RequestGarrisonMessage; if (requestGarrisonMessage != null) { requestGarrisonMessage.ExecutionState = RequestUnitListMessage.RequestUnitListState.ArmyAvailable; requestGarrisonMessage.TimeOut = 1; this.TransferUnits(requestGarrisonMessage.CityGuid); } RequestGarrisonCampMessage requestGarrisonCampMessage = base.Commander.AIPlayer.Blackboard.GetMessage(this.AICommanderRegroupArmies.RequestUnitListMessageID) as RequestGarrisonCampMessage; if (requestGarrisonCampMessage != null) { requestGarrisonCampMessage.ExecutionState = RequestUnitListMessage.RequestUnitListState.ArmyAvailable; requestGarrisonCampMessage.TimeOut = 1; this.TransferUnits(requestGarrisonCampMessage.CampGuid); } } } base.SetArmyFree(); }
public bool ArrivedToDestination() { AIData_Army aidata = this.aiDataRepository.GetAIData <AIData_Army>(base.AIDataArmyGUID); if (aidata == null) { return(false); } Region region = this.worldPositionningService.GetRegion(aidata.Army.WorldPosition); if (this.RegionTarget == region) { return(true); } this.CalculateRegroupPositionForWaitToAttack(); return(!this.targetFrontierPosition.IsValid || aidata.Army.WorldPosition == this.targetFrontierPosition); }
private bool IsArmyBesiegingACity(GameEntityGUID armyGUID) { AIData_Army aidata = this.aiDataRepository.GetAIData <AIData_Army>(armyGUID); if (aidata == null) { return(false); } District district = this.worldPositionningService.GetDistrict(aidata.Army.WorldPosition); if (district == null) { return(false); } City city = district.City; return(city != null && city.Empire != aidata.Army.Empire && city.BesiegingEmpire == aidata.Army.Empire); }
public virtual void ReadXml(XmlReader reader) { if (reader.ReadVersionAttribute() >= 2) { this.InternalGUID = reader.GetAttribute <ulong>("InternalGUID"); } if (this.InternalGUID == GameEntityGUID.Zero) { this.InternalGUID = AIScheduler.Services.GetService <IAIEntityGUIDAIHelper>().GenerateAIEntityGUID(); } this.Completion = (AICommanderMission.AICommanderMissionCompletion)reader.GetAttribute <int>("Completion"); if (this.Completion == AICommanderMission.AICommanderMissionCompletion.Running) { this.Completion = AICommanderMission.AICommanderMissionCompletion.Initializing; } this.AIDataArmyGUID = new GameEntityGUID(reader.GetAttribute <ulong>("AIDataArmyGUID")); IDatabase <AICommanderMissionDefinition> database = Databases.GetDatabase <AICommanderMissionDefinition>(false); Diagnostics.Assert(database != null); StaticString staticString = reader.GetAttribute("MissionDefinition"); if (!StaticString.IsNullOrEmpty(staticString)) { this.MissionDefinition = database.GetValue(staticString); } else { this.Completion = AICommanderMission.AICommanderMissionCompletion.Fail; this.State = TickableState.NoTick; } this.IsActive = reader.GetAttribute <bool>("IsActive"); reader.ReadStartElement(); if (this.AIDataArmyGUID != GameEntityGUID.Zero) { AIData_Army aidata = this.aiDataRepository.GetAIData <AIData_Army>(this.AIDataArmyGUID); if (aidata != null) { aidata.AssignCommanderMission(this); } } }
private bool ChooseArmyToSupport() { if (this.ArmyToSupport != null && this.ArmyToSupport.GUID.IsValid && this.ArmyToSupport.Empire.Index == base.Commander.Empire.Index && (!(this.ArmyToSupport is KaijuArmy) || (this.ArmyToSupport as KaijuArmy).Kaiju.OnArmyMode())) { return(true); } this.ArmyToSupport = null; float num = 0f; float propertyValue = this.Kaiju.KaijuArmy.GetPropertyValue(SimulationProperties.MaximumMovement); for (int i = 0; i < this.departmentOfDefense.Armies.Count; i++) { AIData_Army aidata = this.aiDataRepositoryHelper.GetAIData <AIData_Army>(this.departmentOfDefense.Armies[i].GUID); if (aidata != null && aidata.Army.GUID != base.AIDataArmyGUID && aidata.SupportScore >= 0.5f) { float supportScore = aidata.SupportScore; float num2 = Mathf.Ceil((float)this.worldPositioningService.GetDistance(this.Kaiju.KaijuArmy.WorldPosition, aidata.Army.WorldPosition) / propertyValue); float num3 = supportScore * Mathf.Max(0.2f, (21f - num2) / 20f); if (num3 > num) { num = num3; this.ArmyToSupport = this.departmentOfDefense.Armies[i]; this.DistanceToSupportArmy = num2; } } } if (this.ArmyToSupport != null && this.DistanceToSupportArmy > 3f && (this.garrisonAction_MigrateKaiju.ComputeRemainingCooldownDuration(this.Kaiju.KaijuArmy) <= 1f || !this.AtWar)) { Region bestSupportRegionForKaiju = this.aILayer_KaijuManagement.GetBestSupportRegionForKaiju(this.Kaiju, this.ArmyToSupport, null); if (bestSupportRegionForKaiju != null) { float num4 = Mathf.Ceil((float)this.worldPositioningService.GetDistance(this.ArmyToSupport.WorldPosition, bestSupportRegionForKaiju.Barycenter) / propertyValue); this.GetClosestReachableNeutralRegion(this.Kaiju, (int)((this.DistanceToSupportArmy - num4) * propertyValue)); if (this.ClosestNeutralRegion != null) { this.TryToSettle = true; } } } return(this.ArmyToSupport != null); }
protected override void Running() { if (!base.AIDataArmyGUID.IsValid) { base.Completion = AICommanderMission.AICommanderMissionCompletion.Success; return; } if (base.Commander.IsMissionFinished(false)) { base.Completion = AICommanderMission.AICommanderMissionCompletion.Success; return; } AIData_Army aidata = this.aiDataRepository.GetAIData <AIData_Army>(base.AIDataArmyGUID); if (aidata == null || aidata.Army == null) { base.Completion = AICommanderMission.AICommanderMissionCompletion.Success; return; } base.Running(); }
protected virtual void Running() { AIData_Army aidata = this.aiDataRepository.GetAIData <AIData_Army>(this.AIDataArmyGUID); if (aidata == null || aidata.ArmyMission == null) { this.Completion = AICommanderMission.AICommanderMissionCompletion.Fail; return; } switch (aidata.ArmyMission.Completion) { case AIArmyMission.AIArmyMissionCompletion.Fail: { AIArmyMission.AIArmyMissionErrorCode errorCode = aidata.ArmyMission.ErrorCode; aidata.ArmyMission.Reset(); TickableState tickableState = TickableState.NoTick; this.Completion = this.GetCompletionFor(errorCode, out tickableState); this.State = tickableState; return; } case AIArmyMission.AIArmyMissionCompletion.Running: aidata.ArmyMission.Tick(); return; case AIArmyMission.AIArmyMissionCompletion.Success: { aidata.ArmyMission.Reset(); TickableState tickableState2 = TickableState.NoTick; this.Completion = this.GetCompletionWhenSuccess(aidata, out tickableState2); this.State = tickableState2; return; } default: return; } }
private float ComputeShiftPriority(AIData_Army army, Garrison target) { float num = 0f; float num2 = 0f; this.intelligenceAiHelper.EstimateMPInBattleground(army.Army, target, ref num2, ref num); float num3 = num / num2; if (num3 > 1.5f || num3 < 0.5f) { return(0f); } float propertyValue = target.Empire.GetPropertyValue(SimulationProperties.MilitaryPower); float a = num / propertyValue; float propertyValue2 = army.Army.Empire.GetPropertyValue(SimulationProperties.MilitaryPower); float b = num2 / propertyValue2; float num4 = Mathf.Max(a, b); num4 = Mathf.Clamp01(num4); float normalizedScore = 0.3f; return(AILayer.Boost(normalizedScore, num4)); }
private bool CheckArmyGuid(GameEntityGUID guid) { if (guid == GameEntityGUID.Zero) { return(false); } AIData_Army aidata = this.aiDataRepository.GetAIData <AIData_Army>(guid); if (aidata == null) { return(false); } if (aidata.Army.Empire != this.Commander.Empire) { this.ArmyLost(); return(false); } if (aidata.CommanderMission != this && !aidata.AssignCommanderMission(this)) { this.Completion = AICommanderMission.AICommanderMissionCompletion.Fail; return(false); } return(true); }
private void PopulateFinalRuinOrBesiegingCityMission(PointOfInterest POI) { float armyMaxPower = this.GetArmyMaxPower(); int num; if (this.region.City == null || this.region.City.Empire.Index == base.Empire.Index || this.departmentOfForeignAffairs.IsFriend(this.region.City.Empire)) { num = Mathf.CeilToInt(Intelligence.GetArmiesInRegion(this.region.Index).ToList <Army>().FindAll((Army x) => this.departmentOfForeignAffairs.CanAttack(x)).Sum((Army x) => x.GetPropertyValue(SimulationProperties.MilitaryPower)) * 2f / armyMaxPower); for (int i = base.Missions.Count - 1; i >= 0; i--) { AICommanderMission_BesiegeCityDefault aicommanderMission_BesiegeCityDefault = base.Missions[i] as AICommanderMission_BesiegeCityDefault; if (aicommanderMission_BesiegeCityDefault != null) { this.CancelMission(aicommanderMission_BesiegeCityDefault); } } } else { num = Mathf.CeilToInt(this.intelligenceAIHelper.EvaluateMilitaryPowerOfGarrison(base.Empire, this.region.City, 0) * 1.2f / armyMaxPower); num += Mathf.CeilToInt(Intelligence.GetArmiesInRegion(this.region.Index).ToList <Army>().FindAll((Army x) => this.departmentOfForeignAffairs.CanAttack(x)).Sum((Army x) => x.GetPropertyValue(SimulationProperties.MilitaryPower)) * 2f / armyMaxPower); } if (num == 0) { num = 1; } else if (num > 5) { num = 5; } int num2 = 0; int num3 = 0; for (int j = 0; j < base.Missions.Count; j++) { AICommanderMission aicommanderMission = base.Missions[j]; if (aicommanderMission != null && !(aicommanderMission is AICommanderMission_VictoryRuinFinal)) { if (num2 < num) { if (!aicommanderMission.AIDataArmyGUID.IsValid) { num3++; } } else if (num2 >= num + 2) { this.CancelMission(aicommanderMission); goto IL_1D6; } num2++; } IL_1D6 :; } Tags tags = new Tags(); if (this.region.City != null && this.region.City.Empire.Index != base.Empire.Index && this.departmentOfForeignAffairs.IsAtWarWith(this.region.City.Empire)) { for (int k = base.Missions.Count - 1; k >= 0; k--) { AICommanderMission_DefenseRoaming aicommanderMission_DefenseRoaming = base.Missions[k] as AICommanderMission_DefenseRoaming; if (aicommanderMission_DefenseRoaming != null) { this.CancelMission(aicommanderMission_DefenseRoaming); } } tags.AddTag("War"); tags.AddTag("BesiegeCity"); for (int l = num2; l < num; l++) { base.PopulationFirstMissionFromCategory(tags, new object[] { this.region.City }); } } else { tags.AddTag("WarPatrol"); for (int m = num2; m < num; m++) { base.PopulationFirstMissionFromCategory(tags, new object[] { this.RegionTarget, true }); } } if (!this.POIAccessible(POI)) { for (int n = base.Missions.Count - 1; n >= 0; n--) { AICommanderMission_VictoryRuinFinal aicommanderMission_VictoryRuinFinal = base.Missions[n] as AICommanderMission_VictoryRuinFinal; if (aicommanderMission_VictoryRuinFinal != null) { this.CancelMission(aicommanderMission_VictoryRuinFinal); } } return; } List <AICommanderMission> list = base.Missions.FindAll((AICommanderMission x) => x is AICommanderMission_VictoryRuinFinal); int num4 = 0; int num5 = -1; for (int num6 = list.Count - 1; num6 >= 0; num6--) { num4++; if (list[num6].AIDataArmyGUID.IsValid) { AIData_Army aidata = this.aiDataRepository.GetAIData <AIData_Army>(list[num6].AIDataArmyGUID); if (aidata != null && aidata.Army != null) { int num7 = aidata.Army.StandardUnits.Count((Unit x) => x.UnitDesign.Name.ToString().Contains(this.VictoryDesign)); if (num7 > 5) { num5 = num6; break; } if (num7 == 0) { this.CancelMission(list[num6]); } } } } if (num5 > -1) { for (int num8 = list.Count - 1; num8 >= 0; num8--) { if (num8 != num5) { this.CancelMission(list[num8]); } } return; } tags.Clear(); tags.AddTag("Final"); tags.AddTag("Ruin"); if (this.VictoryDesign == "Preacher") { tags.AddTag("Cult"); } else if (this.VictoryDesign == "MimicsUnit2") { tags.AddTag("Mykara"); } else { tags.AddTag("Settler"); } while (num4 < 6) { base.PopulationFirstMissionFromCategory(tags, new object[] { this.RegionTarget, base.SubObjectiveGuid }); num4++; } }