public virtual void CheckObjectiveInProgress(bool forceStop = false) { for (int i = this.Missions.Count - 1; i >= 0; i--) { AICommanderMission aicommanderMission = this.Missions[i]; if (aicommanderMission.IsActive) { switch (aicommanderMission.Completion) { case AICommanderMission.AICommanderMissionCompletion.Initializing: if (forceStop) { this.CancelMission(this.Missions[i]); } break; case AICommanderMission.AICommanderMissionCompletion.Success: this.CancelMission(this.Missions[i]); break; case AICommanderMission.AICommanderMissionCompletion.Fail: this.CancelMission(this.Missions[i]); break; case AICommanderMission.AICommanderMissionCompletion.Interrupted: this.CancelMission(this.Missions[i]); break; } } } }
public virtual void ReadXml(XmlReader reader) { int num = reader.ReadVersionAttribute(); if (num >= 5) { this.InternalGUID = reader.GetAttribute <ulong>("InternalGUID"); } if (this.InternalGUID == GameEntityGUID.Zero) { this.InternalGUID = AIScheduler.Services.GetService <IAIEntityGUIDAIHelper>().GenerateAIEntityGUID(); } this.ForceArmyGUID = reader.GetAttribute <ulong>("ForceArmyGUID", 0UL); reader.ReadStartElement(); try { if (reader.IsStartElement("MissionList") && reader.IsEmptyElement()) { reader.Skip(); } else { reader.ReadStartElement("MissionList"); while (reader.IsStartElement()) { string attribute = reader.GetAttribute("AssemblyQualifiedName"); if (!string.IsNullOrEmpty(attribute)) { Type type = Type.GetType(attribute); AICommanderMission aicommanderMission = (AICommanderMission)Activator.CreateInstance(type); aicommanderMission.Initialize(this); reader.ReadElementSerializable <AICommanderMission>(ref aicommanderMission); this.Missions.Add(aicommanderMission); Diagnostics.Assert(AIScheduler.Services != null); ITickableRepositoryAIHelper service = AIScheduler.Services.GetService <ITickableRepositoryAIHelper>(); Diagnostics.Assert(service != null); service.Register(aicommanderMission); } else { reader.Skip(); } } reader.ReadEndElement("MissionList"); } } catch (Exception ex) { Diagnostics.LogError("Fail to load the mission: {0}", new object[] { ex.ToString() }); reader.Skip(); } }
public override float GetPriority(AICommanderMission mission) { if (base.Missions.Count > 0) { int num = base.Missions.FindIndex((AICommanderMission match) => match == mission); if (num >= 0 && base.Missions[num].AIDataArmyGUID.IsValid) { return(0.8f); } } return(base.GlobalPriority * base.LocalPriority); }
protected virtual AICommanderMission GenerateMission(AICommanderMissionDefinition missionDefinition, params object[] parameters) { if (!string.IsNullOrEmpty(missionDefinition.Type.ToString())) { Type type = Type.GetType(missionDefinition.Type.ToString()); AICommanderMission aicommanderMission = (AICommanderMission)Activator.CreateInstance(type); aicommanderMission.Initialize(this); aicommanderMission.SetParameters(missionDefinition, parameters); aicommanderMission.Load(); return(aicommanderMission); } return(null); }
public bool MayUseShift(AICommanderMission mission) { if (mission == null) { return(false); } if (StaticString.IsNullOrEmpty(mission.SeasonToSwitchTo)) { return(false); } Season currentSeason = this.seasonService.GetCurrentSeason(); return(currentSeason != null && currentSeason.SeasonDefinition.SeasonType != mission.SeasonToSwitchTo); }
protected AICommanderMission PopulationFirstMissionFromCategory(Tags tags, params object[] parameters) { IDatabase <AICommanderMissionDefinition> database = Databases.GetDatabase <AICommanderMissionDefinition>(false); Diagnostics.Assert(database != null); foreach (AICommanderMissionDefinition aicommanderMissionDefinition in database) { if (aicommanderMissionDefinition.Category.Contains(tags)) { AICommanderMission aicommanderMission = this.GenerateMission(aicommanderMissionDefinition, parameters); if (aicommanderMission != null) { this.Missions.Add(aicommanderMission); return(aicommanderMission); } } } return(null); }
public bool AssignCommanderMission(AICommanderMission commanderMissionOwner) { if (this.CommanderMission != null) { Diagnostics.LogWarning(string.Format("LOCKING: {0} tries to recruit Army assigned to {1}", commanderMissionOwner.ToString(), this.CommanderMission.ToString())); return(false); } this.CommanderMission = commanderMissionOwner; if (this.ArmyMission != null) { this.UnassignArmyMission(); } IAIDataRepositoryAIHelper service = AIScheduler.Services.GetService <IAIDataRepositoryAIHelper>(); if (this.Army != null) { for (int i = 0; i < this.Army.StandardUnits.Count; i++) { AIData_Unit aidata_Unit; if (service.TryGetAIData <AIData_Unit>(this.Army.StandardUnits[i].GUID, out aidata_Unit)) { if (aidata_Unit.IsUnitLocked()) { if (!aidata_Unit.IsUnitLockedByMe(commanderMissionOwner.InternalGUID) && Amplitude.Unity.Framework.Application.Preferences.EnableModdingTools) { Diagnostics.LogWarning(string.Format("{3} {4} LOCKING: Error when assigning commander mission {0} Guid {1}, current infroamtion {2}", new object[] { commanderMissionOwner.GetType().ToString(), commanderMissionOwner.InternalGUID, aidata_Unit.GetLockingStateString(), this.Army.Empire, this.Army.LocalizedName })); } aidata_Unit.ClearLock(); } aidata_Unit.TryLockUnit(commanderMissionOwner.InternalGUID, commanderMissionOwner.GetType().ToString(), AIData_Unit.AIDataReservationExtraTag.GenericCommander, commanderMissionOwner.Commander.GetPriority(commanderMissionOwner)); } } } return(true); }
private void VerifyAndUpdateRecruitementLocks() { IAIDataRepositoryAIHelper service = AIScheduler.Services.GetService <IAIDataRepositoryAIHelper>(); DepartmentOfDefense agency = this.Empire.GetAgency <DepartmentOfDefense>(); for (int i = 0; i < agency.Armies.Count; i++) { AIData_Unit aidata_Unit; for (int j = 0; j < agency.Armies[i].StandardUnits.Count; j++) { if (service.TryGetAIData <AIData_Unit>(agency.Armies[i].StandardUnits[j].GUID, out aidata_Unit) && aidata_Unit.IsUnitLocked()) { if (aidata_Unit.IsUnitLockedByMe(base.InternalGUID)) { aidata_Unit.TryUnLockUnit(base.InternalGUID); } else { AICommanderMission commanderMissionWithGUID = base.AIEntity.GetCommanderMissionWithGUID(aidata_Unit.ReservingGUID); if (commanderMissionWithGUID == null) { aidata_Unit.ClearLock(); } else { aidata_Unit.ReservationPriority = commanderMissionWithGUID.Commander.GetPriority(commanderMissionWithGUID); } } } } if (agency.Armies[i].Hero != null && service.TryGetAIData <AIData_Unit>(agency.Armies[i].Hero.GUID, out aidata_Unit) && aidata_Unit.IsUnitLocked()) { aidata_Unit.ClearLock(); } } }
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++; } }
private void PopulateRuinorBesiegingCityMission(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) { if (num2 < num) { if (!aicommanderMission.AIDataArmyGUID.IsValid) { num3++; } } else if (num2 >= num + 2) { this.CancelMission(aicommanderMission); goto IL_1CD; } num2++; } IL_1CD :; } Tags tags = new Tags(); if (this.POIAccessible(POI)) { tags.AddTag(base.Category.ToString()); tags.AddTag("Ruin"); for (int k = num2; k < num; k++) { base.PopulationFirstMissionFromCategory(tags, new object[] { this.RegionTarget, base.SubObjectiveGuid }); } return; } if (this.region.City != null && this.region.City.Empire.Index != base.Empire.Index && this.departmentOfForeignAffairs.IsAtWarWith(this.region.City.Empire)) { for (int l = base.Missions.Count - 1; l >= 0; l--) { AICommanderMission_VictoryRuin aicommanderMission_VictoryRuin = base.Missions[l] as AICommanderMission_VictoryRuin; if (aicommanderMission_VictoryRuin != null) { this.CancelMission(aicommanderMission_VictoryRuin); } } tags.AddTag("War"); tags.AddTag("BesiegeCity"); for (int m = num2; m < num; m++) { base.PopulationFirstMissionFromCategory(tags, new object[] { this.region.City }); } } }
public override float GetPriority(AICommanderMission mission) { return(0.3f); }
public override void PopulateMission() { if (this.IsMissionFinished()) { return; } Region region = this.worldPositionningService.GetRegion(base.RegionIndex); Tags tags = new Tags(); tags.AddTag(base.Category.ToString()); if (this.CurrentWarStep == AICommander_WarWithObjective.WarSteps.GoingToFrontier) { DepartmentOfForeignAffairs agency = base.Empire.GetAgency <DepartmentOfForeignAffairs>(); Diagnostics.Assert(agency != null); DiplomaticRelation diplomaticRelation = agency.DiplomaticRelations[region.City.Empire.Index]; if (diplomaticRelation != null && diplomaticRelation.State.Name == DiplomaticRelationState.Names.War) { this.CurrentWarStep = AICommander_WarWithObjective.WarSteps.BeSiegingCity; AICommanderMission aicommanderMission = base.Missions.Find((AICommanderMission match) => match is AICommanderMission_FrontierHarass); if (aicommanderMission != null) { this.CancelMission(aicommanderMission); } } } if (this.NeedPrivateersHarrasementMission && this.CurrentWarStep == AICommander_WarWithObjective.WarSteps.GoingToFrontier) { int num = base.Missions.Count((AICommanderMission match) => match is AICommanderMission_PrivateersHarass); if (num < 6) { tags.AddTag("PrivateersHarass"); for (int i = num; i < 6; i++) { base.PopulationFirstMissionFromCategory(tags, new object[] { region.City }); } tags.RemoveTag("PrivateersHarass"); } } else { AICommanderMission aicommanderMission2 = base.Missions.Find((AICommanderMission match) => match is AICommanderMission_PrivateersHarass); if (aicommanderMission2 != null) { this.CancelMission(aicommanderMission2); } } AICommander_WarWithObjective.WarSteps currentWarStep = this.CurrentWarStep; if (currentWarStep != AICommander_WarWithObjective.WarSteps.GoingToFrontier) { if (currentWarStep != AICommander_WarWithObjective.WarSteps.BeSiegingCity) { Diagnostics.LogError(string.Format("[AICommander_WarWithObjective] Unknow war step", this.CurrentWarStep.ToString())); return; } this.PopulateBesiegingCityMission(tags, region); if (region.City.Camp != null) { this.PopulateAttackCampMission(tags, region); return; } List <AICommanderMission> list = base.Missions.FindAll((AICommanderMission match) => match is AICommanderMission_AttackCampDefault); if (list.Count > 0) { for (int j = 0; j < list.Count; j++) { this.CancelMission(list[j]); } return; } } else if (!base.Missions.Exists((AICommanderMission match) => match is AICommanderMission_FrontierHarass)) { tags.AddTag("FrontierHarass"); base.PopulationFirstMissionFromCategory(tags, new object[] { region }); } }
public override void RefreshMission() { base.RefreshMission(); if (this.IsMissionFinished()) { return; } this.NeedPrivateersHarrasementMission = false; MajorEmpire majorEmpire = base.Empire as MajorEmpire; if (majorEmpire != null) { Region region2 = this.worldPositionningService.GetRegion(base.RegionIndex); DepartmentOfForeignAffairs agency = base.Empire.GetAgency <DepartmentOfForeignAffairs>(); Diagnostics.Assert(agency != null); DiplomaticRelation diplomaticRelation = agency.DiplomaticRelations[region2.City.Empire.Index]; if (diplomaticRelation != null && diplomaticRelation.State.Name == DiplomaticRelationState.Names.War) { this.NeedPrivateersHarrasementMission = false; } else { this.NeedPrivateersHarrasementMission = (majorEmpire.SimulationObject.Tags.Contains(AILayer_War.TagNoWarTrait) && this.departmentOfScience.CanCreatePrivateers()); } } if (base.Missions.Count != 0) { Region region = this.worldPositionningService.GetRegion(base.RegionIndex); switch (this.CurrentWarStep) { case AICommander_WarWithObjective.WarSteps.GoingToFrontier: { DepartmentOfForeignAffairs agency2 = base.Empire.GetAgency <DepartmentOfForeignAffairs>(); Diagnostics.Assert(agency2 != null); DiplomaticRelation diplomaticRelation2 = agency2.DiplomaticRelations[region.City.Empire.Index]; if (diplomaticRelation2.State == null) { Diagnostics.LogError("[AICommander_WarWithObjective] DiplomaticRelation is null"); return; } AICommanderMission_FrontierHarass aicommanderMission_FrontierHarass = base.Missions.Find((AICommanderMission match) => match is AICommanderMission_FrontierHarass) as AICommanderMission_FrontierHarass; if (aicommanderMission_FrontierHarass != null && aicommanderMission_FrontierHarass.Completion != AICommanderMission.AICommanderMissionCompletion.Fail && aicommanderMission_FrontierHarass.Completion != AICommanderMission.AICommanderMissionCompletion.Interrupted && aicommanderMission_FrontierHarass.Completion != AICommanderMission.AICommanderMissionCompletion.Cancelled && aicommanderMission_FrontierHarass.ArrivedToDestination()) { if (diplomaticRelation2.State.Name == DiplomaticRelationState.Names.War) { if (this.aiDataRepository.GetAIData <AIData_Army>(aicommanderMission_FrontierHarass.AIDataArmyGUID) == null) { aicommanderMission_FrontierHarass.Interrupt(); } else { base.ForceArmyGUID = aicommanderMission_FrontierHarass.AIDataArmyGUID; this.CurrentWarStep = AICommander_WarWithObjective.WarSteps.BeSiegingCity; this.CancelMission(aicommanderMission_FrontierHarass); } } else { WantedDiplomaticRelationStateMessage wantedDiplomaticRelationStateMessage = base.AIPlayer.Blackboard.FindFirst <WantedDiplomaticRelationStateMessage>(BlackboardLayerID.Empire, (WantedDiplomaticRelationStateMessage message) => message.OpponentEmpireIndex == region.City.Empire.Index); if (wantedDiplomaticRelationStateMessage == null) { Diagnostics.LogWarning("[AICommander_WarWithObjective] No WantedDiplomaticRelationStateMessage found"); } else if (wantedDiplomaticRelationStateMessage.WantedDiplomaticRelationStateName == DiplomaticRelationState.Names.War) { wantedDiplomaticRelationStateMessage.CurrentWarStatusType = AILayer_War.WarStatusType.Ready; } } } break; } case AICommander_WarWithObjective.WarSteps.BeSiegingCity: this.BesiegeCityProcessor(region); break; case AICommander_WarWithObjective.WarSteps.AttackingCity: { AICommanderMission aicommanderMission = base.Missions.Find((AICommanderMission match) => match is AICommanderMission_AttackCityDefault); if (aicommanderMission != null) { base.ForceArmyGUID = aicommanderMission.AIDataArmyGUID; this.CancelMission(aicommanderMission); } this.CurrentWarStep = AICommander_WarWithObjective.WarSteps.BeSiegingCity; break; } default: Diagnostics.LogError(string.Format("[AICommander_WarWithObjective] Unknow war step", this.CurrentWarStep.ToString())); break; } } this.PopulateMission(); this.EvaluateMission(); base.PromoteMission(); }
protected virtual void CancelMission(AICommanderMission mission) { this.Missions.Remove(mission); mission.Release(); }
public virtual float GetPillageModifier(AICommanderMission mission) { return(1f); }
public abstract float GetPriority(AICommanderMission mission);