private void DefensiveCampaign() { DateTime beforeStart = DateTime.UtcNow; List<Point> orientations = new List<Point>(); TroopList hostileTroopsInView = this.GetHostileTroopsInView(); foreach (Troop troop in hostileTroopsInView) { orientations.Add(troop.Position); } if ((this.HasPerson() && this.HasCampaignableMilitary()) && (this.GetAllAvailableArea(false).Count != 0)) { if (hostileTroopsInView.Count > 0) { TroopList friendlyTroopsInView = this.GetFriendlyTroopsInView(); int troopSent = 0; int militaryCount = this.MilitaryCount; Troop troop2; TroopList list4 = new TroopList(); bool isBesideWater = this.IsBesideWater; foreach (Military military in this.Militaries.GetRandomList()) { if (military.IsFewScaleNeedRetreat && this.Endurance >= 30) continue; if ((isBesideWater || (military.Kind.Type != MilitaryType.水军)) && (((((this.Endurance < 30) || military.Kind.AirOffence) || (military.Scales >= 2)) && (military.Morale > 0x2d)) && ((this.Endurance < 30) || (military.InjuryQuantity < military.Kind.MinScale)))) { TroopList candidates = this.AISelectPersonIntoTroop(this, military); foreach (Troop t in candidates) { list4.Add(t); if (DateTime.UtcNow - beforeStart > new TimeSpan(0, 0, Parameters.MaxAITroopTime)) { break; } } } if (DateTime.UtcNow - beforeStart > new TimeSpan(0, 0, Parameters.MaxAITroopTime)) { break; } } if (list4.Count > 0) { list4.IsNumber = true; list4.PropertyName = "FightingForce"; list4.ReSort(); foreach (Troop troop in list4.GetList()) { if (troop.FightingForce < 10000 && troop.FightingForce < (this.TotalHostileForce * 5 - this.TotalFriendlyForce) / 25) { break; } if (troop.Army.Scales < 5 && this.Endurance > 30) { continue; } bool personAlreadyOut = false; foreach (Person p in troop.Candidates) { if (p.LocationTroop != null) { personAlreadyOut = true; break; } } if (personAlreadyOut) continue; bool militaryOut = true; foreach (Military m in this.Militaries) { if (troop.Army == m) { militaryOut = false; break; } } if (militaryOut) continue; Point? nullable = this.GetCampaignPosition(troop, orientations, troop.Army.Scales > 0); if (!nullable.HasValue) { break; } Person leader = troop.Candidates[0] as Person; PersonList candidates = this.SelectSubOfficersToTroop(troop); troop2 = this.CreateTroop(candidates, leader, troop.Army, -1, nullable.Value); troop2.WillArchitecture = this; if (this.DefensiveLegion == null) { this.CreateDefensiveLegion(); } this.DefensiveLegion.AddTroop(troop2); this.PostCreateTroop(troop2, false); this.TotalFriendlyForce += troop2.FightingForce; troopSent++; } foreach (Troop t in list4) { t.Destroy(true, false); } } } } //not enough defensive troop, call for reinforcements!! float rate = (float)Math.Max(1, (200 - this.Endurance) * 0.005 + 1); if (this.TotalFriendlyForce < this.TotalHostileForce * rate) { foreach (LinkNode i in this.AIAllLinkNodes.Values) { if (DateTime.UtcNow - beforeStart > new TimeSpan(0, 0, Parameters.MaxAITroopTime)) { return; } if (i.Level > 1) break; if (i.A.actuallyUnreachableArch.Contains(this)) { continue; } if (this.BelongedFaction == i.A.BelongedFaction && i.A.HasPerson() && i.A.BelongedSection.AIDetail.AutoRun) { int reserve; if (this.Population > 0) { reserve = (int)(i.A.getArmyReserveForOffensive(null) * Math.Pow(i.A.Population / (double)this.Population, 0.15)); } else { reserve = int.MaxValue; } TroopList supportList = new TroopList(); Troop troop2; foreach (Military military in i.A.Militaries.GetRandomList()) { if (military.IsFewScaleNeedRetreat) continue; if (military.IsTransport) continue; if (this.isArmyNavigableTo(i, military) && (military.Morale > 90) && (military.InjuryQuantity < military.Kind.MinScale)) { TroopList candidates = this.AISelectPersonIntoTroop(this, military); foreach (Troop t in candidates) { supportList.Add(t); if (DateTime.UtcNow - beforeStart > new TimeSpan(0, 0, Parameters.MaxAITroopTime)) { break; } } } if (DateTime.UtcNow - beforeStart > new TimeSpan(0, 0, Parameters.MaxAITroopTime)) { break; } } if (supportList.Count > 0) { supportList.IsNumber = true; supportList.PropertyName = "FightingForce"; supportList.ReSort(); foreach (Troop troop in supportList.GetList()) { if ((troop.FightingForce < 10000) && (troop.Army.Scales < 10)) { break; } bool personAlreadyOut = false; foreach (Person p in troop.Candidates) { if (p.LocationTroop != null) { personAlreadyOut = true; break; } } if (personAlreadyOut) continue; bool militaryOut = true; foreach (Military m in i.A.Militaries) { if (troop.Army == m) { militaryOut = false; break; } } if (militaryOut) continue; Point? nullable = i.A.GetCampaignPosition(troop, orientations, troop.Army.Scales > 0); if (!nullable.HasValue) { continue; } Person leader = troop.Candidates[0] as Person; PersonList candidates = i.A.SelectSubOfficersToTroop(troop); troop2 = i.A.CreateTroop(candidates, leader, troop.Army, -1, nullable.Value); troop2.WillArchitecture = this; if (this.DefensiveLegion == null) { this.CreateDefensiveLegion(); } this.DefensiveLegion.AddTroop(troop2); i.A.PostCreateTroop(troop2, false); this.TotalFriendlyForce += troop2.FightingForce; } foreach (Troop t in supportList) { t.Destroy(true, false); } } } } } }
private void DefensiveCampaign() { if ((this.HasPerson() && this.HasCampaignableMilitary()) && (this.GetAllAvailableArea(false).Count != 0)) { TroopList hostileTroopsInView = this.GetHostileTroopsInView(); if (hostileTroopsInView.Count > 0) { List<Point> orientations = new List<Point>(); foreach (Troop troop in hostileTroopsInView) { orientations.Add(troop.Position); } TroopList friendlyTroopsInView = this.GetFriendlyTroopsInView(); int num = 0; int militaryCount = this.MilitaryCount; while ((num < militaryCount) && (this.TotalFriendlyForce < (this.TotalHostileForce * 5))) { Troop troop2; num++; int num3 = (this.TotalHostileForce * 5) - this.TotalFriendlyForce; TroopList list4 = new TroopList(); bool isBesideWater = this.IsBesideWater; //Label_033D: foreach (Military military in this.Militaries.GetRandomList()) { if ((isBesideWater || (military.Kind.Type != MilitaryType.水军)) && (((((this.Endurance < 30) || military.Kind.AirOffence) || (military.Scales >= 2)) && (military.Morale > 0x2d)) && ((this.Endurance < 30) || (military.InjuryQuantity < military.Kind.MinScale)))) { PersonList list5; if ((military.FollowedLeader != null) && this.Persons.HasGameObject(military.FollowedLeader)) { list5 = new PersonList(); list5.Add(military.FollowedLeader); military.FollowedLeader.Selected = true; troop2 = Troop.CreateSimulateTroop(list5, military, this.Position); list4.Add(troop2); } else { if ((((military.Leader != null) && (military.LeaderExperience >= 200)) && (((military.Leader.Strength >= 80) || (military.Leader.Command >= 80)) || military.Leader.HasLeaderValidCombatTitle)) && this.Persons.HasGameObject(military.Leader)) { list5 = new PersonList(); list5.Add(military.Leader); military.Leader.Selected = true; troop2 = Troop.CreateSimulateTroop(list5, military, this.Position); list4.Add(troop2); //goto Label_033D; continue; } foreach (Person person in this.Persons) { if (!person.Selected) { list5 = new PersonList(); list5.Add(person); troop2 = Troop.CreateSimulateTroop(list5, military, this.Position); list4.Add(troop2); } } } } } if (list4.Count <= 0) { break; } list4.IsNumber = true; list4.PropertyName = "FightingForce"; list4.ReSort(); foreach (Troop troop in list4.GetList()) { if (((troop.FightingForce < 0x2710) && (troop.FightingForce < (num3 / 0x19))) && (troop.Army.Scales < 10)) { return; } Point? nullable = this.GetCampaignPosition(troop, orientations, troop.Army.Scales > 0); if (!nullable.HasValue) { return; } if (troop.Army.Kind.AirOffence && (troop.Army.Scales < 2)) { Architecture architectureByPositionNoCheck = base.Scenario.GetArchitectureByPositionNoCheck(nullable.Value); if ((architectureByPositionNoCheck == null) || (architectureByPositionNoCheck.Endurance == 0)) { continue; } } Person leader = troop.Persons[0] as Person; this.AddPersonToTroop(troop); troop2 = this.CreateTroop(troop.Persons, leader, troop.Army, -1, nullable.Value); troop2.WillArchitecture = this; if (this.DefensiveLegion == null) { this.CreateDefensiveLegion(); } this.DefensiveLegion.AddTroop(troop2); this.PostCreateTroop(troop2, false); this.TotalFriendlyForce += troop2.FightingForce; break; } if (!(this.HasCampaignableMilitary() && this.HasPerson())) { break; } } } } }
private Troop BuildOffensiveTroop(Architecture destination, LinkKind linkkind, bool offensive) { Troop troop; if (linkkind == LinkKind.None) { return null; } TroopList list = new TroopList(); this.Persons.ClearSelected(); //Label_0309: foreach (Military military in this.Militaries.GetRandomList()) { if (military.Scales < military.RetreatScale * 1.5) continue; if (military.IsTransport) continue; //never deal with transports in this function switch (linkkind) { case LinkKind.Land: { if (military.Kind.Type != MilitaryType.水军) { break; } continue; } case LinkKind.Water: { //if ((military.Kind.Type == MilitaryType.水军) || (this.ValueWater && (!offensive || ((military.Quantity >= 0x1f40) && (GameObject.Random(military.Kind.Merit) <= 0))))) if (GlobalVariables.LandArmyCanGoDownWater) { if (!offensive || (military.KindID != 28 && !military.IsTransport)) { break; } } else { if (military.Kind.Type == MilitaryType.水军) { break; } } continue; } } if ((((military.Scales > 5) && (military.Morale >= 80)) && (military.Combativity >= 80)) && (military.InjuryQuantity < military.Kind.MinScale) && (!offensive || (military.Merit > 0) )) //do not use transport teams to attack { TroopList candidates = this.AISelectPersonIntoTroop(this, military); foreach (Troop t in candidates) { list.Add(t); } } } if (list.Count > 0) { list.IsNumber = true; list.PropertyName = "SimulatingFightingForce"; list.ReSort(); foreach (Troop troop2 in list.GetList()) { bool personAlreadyOut = false; foreach (Person p in troop2.Candidates) { if (p.LocationTroop != null) { personAlreadyOut = true; break; } } bool militaryOut = true; foreach (Military m in this.Militaries) { if (troop2.Army == m) { militaryOut = false; break; } } if (personAlreadyOut) continue; if (militaryOut) continue; if (troop2.FightingForce < 10000 && offensive) { break; } Point? nullable = this.GetRandomStartingPosition(troop2); if (!nullable.HasValue) { break; } Person leader = troop2.Candidates[0] as Person; PersonList candidates = this.SelectSubOfficersToTroop(troop2); troop = this.CreateTroop(candidates, leader, troop2.Army, -1, nullable.Value); troop.WillArchitecture = destination; Legion legion = this.BelongedFaction.GetLegion(destination); if (legion == null) { legion = this.CreateOffensiveLegion(destination); } legion.AddTroop(troop); this.PostCreateTroop(troop, false); } } foreach (Troop t in list) { t.Destroy(true, false); } return null; }
private Troop BuildOffensiveTroop(Architecture destination, LinkKind linkkind, bool offensive) { Troop troop; if (linkkind == LinkKind.None) { return null; } TroopList list = new TroopList(); this.Persons.ClearSelected(); //Label_0309: foreach (Military military in this.Militaries.GetRandomList()) { switch (linkkind) { case LinkKind.Land: { if (military.Kind.Type != MilitaryType.水军) { break; } continue; } case LinkKind.Water: { if ((military.Kind.Type == MilitaryType.水军) || (this.ValueWater && (!offensive || ((military.Quantity >= 0x1f40) && (GameObject.Random(military.Kind.Merit) <= 0))))) { break; } continue; } } if ((((military.Scales >= 3) && (military.Morale >= 80)) && (military.Combativity >= 80)) && (military.InjuryQuantity < military.Kind.MinScale)) { PersonList list2; Military military2 = military; if ((linkkind == LinkKind.Water) && (military.Kind.Type != MilitaryType.水军)) { Military military3 = Military.SimCreate(base.Scenario, this, base.Scenario.GameCommonData.AllMilitaryKinds.GetMilitaryKind(0x1c)); military3.SetShelledMilitary(military); military2 = military3; } if ((military2.FollowedLeader != null) && this.Persons.HasGameObject(military2.FollowedLeader)) { list2 = new PersonList(); list2.Add(military2.FollowedLeader); military2.FollowedLeader.Selected = true; troop = Troop.CreateSimulateTroop(list2, military2, this.Position); list.Add(troop); //goto Label_0309; continue; } if ((((military2.Leader != null) && (military2.LeaderExperience >= 200)) && (((military2.Leader.Strength >= 80) || (military2.Leader.Command >= 80)) || military2.Leader.HasLeaderValidCombatTitle)) && this.Persons.HasGameObject(military2.Leader)) { list2 = new PersonList(); list2.Add(military2.Leader); military2.Leader.Selected = true; troop = Troop.CreateSimulateTroop(list2, military2, this.Position); list.Add(troop); //goto Label_0309; continue; } foreach (Person person in this.Persons) { if (!person.Selected && (person.Command >= 40)) { list2 = new PersonList(); list2.Add(person); troop = Troop.CreateSimulateTroop(list2, military2, this.Position); list.Add(troop); } } } } if (list.Count > 0) { list.IsNumber = true; list.PropertyName = "SimulatingFightingForce"; list.ReSort(); foreach (Troop troop2 in list.GetList()) { if (troop2.FightingForce < 0x2710) { break; } Point? nullable = this.GetCampaignPosition(troop2, destination.ArchitectureArea.Area, true); if (!nullable.HasValue) { break; } Person leader = troop2.Persons[0] as Person; this.AddPersonToTroop(troop2); troop = this.CreateTroop(troop2.Persons, leader, troop2.Army, -1, nullable.Value); troop.WillArchitecture = destination; Legion legion = this.BelongedFaction.GetLegion(destination); if (legion == null) { legion = this.CreateOffensiveLegion(destination); } legion.AddTroop(troop); this.PostCreateTroop(troop, false); return troop; } } return null; }