// Update is called once per frame void Update() { while (readyMilitias > 0) { GameObject t = GameController.Instance.FindClosest("Enemy", pos2d, currentTargetList, 4); if (t == null) { break; } currentTargetList.Add(t); Militia m = SpawnMilitia(); m.SetTarget(t); } if (assignedSoldier == null && assignedWorker == null) { GameObject t = GameController.Instance.FindClosestAvailableWorker(pos2d); if (t != null) { assignedWorker = t.GetComponent <Worker> (); assignedWorker.SetTarget(gameObject); } } }
public void NotifyDestroyed(Militia militia) { militias.Remove(militia); if (readyMilitias + militias.Count < 3) { InvokeRepeating("ReadyMilitia", 25, 25); } }
Militia SpawnMilitia() { if (readyMilitias > 0) { Militia s = GameObject.Instantiate(militiaTemplate, transform.position, Quaternion.identity); militias.Add(s); s.SetMilitaryHub(this); readyMilitias--; return(s); } return(null); }
public static List <Pile> TheFirstGame(bool two) { return(new List <Pile> { new Pile(Cellar.Get(), 10), new Pile(Moat.Get(), 10), new Pile(Village.Get(), 10), new Pile(Woodcutter.Get(), 10), new Pile(Workshop.Get(), 10), new Pile(Militia.Get(), 10), new Pile(Remodel.Get(), 10), new Pile(Smithy.Get(), 10), new Pile(Market.Get(), 10), new Pile(Mine.Get(), 10), }.Concat(VictoryAndTreasures(two)).ToList()); }
private static void CreateSplitMilitias(MobileParty original, TroopRoster party1, TroopRoster party2, TroopRoster prisoners1, TroopRoster prisoners2, ItemRoster inventory1, ItemRoster inventory2) { try { var militia1 = new Militia(original, party1, prisoners1); var militia2 = new Militia(original, party2, prisoners2); Mod.Log($"{militia1.MobileParty.MapFaction.Name} <- Split -> {militia2.MobileParty.MapFaction.Name}"); Traverse.Create(militia1.MobileParty.Party).Property("ItemRoster").SetValue(inventory1); Traverse.Create(militia2.MobileParty.Party).Property("ItemRoster").SetValue(inventory2); militia1.MobileParty.Party.Visuals.SetMapIconAsDirty(); militia2.MobileParty.Party.Visuals.SetMapIconAsDirty(); Trash(original); } catch (Exception ex) { Mod.Log(ex); } }
internal static void CityProduction(City city) { if (city == null || city.Size == 0 || city.Tile == null) { return; } Player player = Game.GetPlayer(city.Owner); IProduction production = null; // Create 2 defensive units per city if (player.HasAdvance <LaborUnion>()) { if (city.Tile.Units.Count(x => x is MechInf) < 2) { production = new MechInf(); } } else if (player.HasAdvance <Conscription>()) { if (city.Tile.Units.Count(x => x is Riflemen) < 2) { production = new Riflemen(); } } else if (player.HasAdvance <Gunpowder>()) { if (city.Tile.Units.Count(x => x is Musketeers) < 2) { production = new Musketeers(); } } else if (player.HasAdvance <BronzeWorking>()) { if (city.Tile.Units.Count(x => x is Phalanx) < 2) { production = new Phalanx(); } } else { if (city.Tile.Units.Count(x => x is Militia) < 2) { production = new Militia(); } } // Create city improvements if (production == null) { if (!city.HasBuilding <Barracks>()) { production = new Barracks(); } else if (player.HasAdvance <Pottery>() && !city.HasBuilding <Granary>()) { production = new Granary(); } else if (player.HasAdvance <CeremonialBurial>() && !city.HasBuilding <Temple>()) { production = new Temple(); } else if (player.HasAdvance <Masonry>() && !city.HasBuilding <CityWalls>()) { production = new CityWalls(); } } // Create Settlers if (production == null) { if (city.Size > 3 && !city.Units.Any(x => x is Settlers) && player.Cities.Length < 10) { production = new Settlers(); } } // Create some other unit if (production == null) { if (city.Units.Length < 4) { if (player.Government is Republic || player.Government is Democratic) { if (player.HasAdvance <Writing>()) { production = new Diplomat(); } } else { if (player.HasAdvance <Automobile>()) { production = new Armor(); } else if (player.HasAdvance <Metallurgy>()) { production = new Cannon(); } else if (player.HasAdvance <Chivalry>()) { production = new Knights(); } else if (player.HasAdvance <TheWheel>()) { production = new Chariot(); } else if (player.HasAdvance <HorsebackRiding>()) { production = new Cavalry(); } else if (player.HasAdvance <IronWorking>()) { production = new Legion(); } } } else { if (player.HasAdvance <Trade>()) { production = new Caravan(); } } } // Set random production if (production == null) { IProduction[] items = city.AvailableProduction.ToArray(); production = items[Common.Random.Next(items.Length)]; } city.SetProduction(production); }
private static void Postfix() { Mod.Log("MapScreen.OnInitialize"); //Mod.Log("Clans:"); //Clan.All.Do(x => Mod.Log($"Name: {x.Name} MapFaction: {x.MapFaction} Culture: {x.Culture}")); //Mod.Log("Bandit Clans:"); //Clan.BanditFactions.Do(x => Mod.Log($"Name: {x.Name} MapFaction: {x.MapFaction} Culture: {x.Culture}")); HeroCreatorCopy.VeteransRespect = PerkObject.All.First(x => x.StringId == "LeadershipVeteransRespect"); HeroCreatorCopy.Leadership = SkillObject.All.First(x => x.StringId == "Leadership"); EquipmentItems.Clear(); PopulateItems(); Recruits = CharacterObject.All.Where(x => x.Level == 11 && x.Occupation == Occupation.Soldier && !x.StringId.StartsWith("regular_fighter") && !x.StringId.StartsWith("veteran_borrowed_troop") && !x.StringId.EndsWith("_tier_1") && !x.StringId.Contains("_militia_") && !x.StringId.Equals("sturgian_warrior_son") && !x.StringId.Equals("khuzait_noble_son") && !x.StringId.Equals("imperial_vigla_recruit") && !x.StringId.Equals("battanian_highborn_youth") && !x.StringId.Equals("vlandian_squire") && !x.StringId.Equals("aserai_youth") && !x.StringId.Equals("poacher")); // used for armour foreach (ItemObject.ItemTypeEnum value in Enum.GetValues(typeof(ItemObject.ItemTypeEnum))) { ItemTypes[value] = Items.FindAll(x => x.Type == value && x.Value >= 1000 && x.Value <= Globals.Settings.MaxItemValue * Variance).ToList(); } // front-load BanditEquipment.Clear(); for (var i = 0; i < 500; i++) { BanditEquipment.Add(BuildViableEquipmentSet()); } PartyMilitiaMap.Clear(); Hideouts = Settlement.FindAll(x => x.IsHideout()).ToList(); var militias = MobileParty.All.Where(x => x != null && x.StringId.StartsWith("Bandit_Militia")).ToList(); for (var i = 0; i < militias.Count; i++) { var militia = militias[i]; if (militia.LeaderHero == null) { Mod.Log("Leaderless militia found and removed."); Trash(militia); } else { var recreatedMilitia = new Militia(militia); PartyMilitiaMap.Add(recreatedMilitia.MobileParty, recreatedMilitia); } } Mod.Log($"Militias: {militias.Count} (registered {PartyMilitiaMap.Count})"); // 1.5.8 is dropping the militia settlements at some point, I haven't figured out where ReHome(); DailyCalculations(); // have to patch it late because of its static constructor (type initialization exception) Mod.harmony.Patch( AccessTools.Method(typeof(EncounterGameMenuBehavior), "game_menu_encounter_on_init"), new HarmonyMethod(AccessTools.Method(typeof(Helper), nameof(FixMapEventFuckery)))); }
private static IUnit CreateUnit(UnitType type, int x, int y) { IUnit unit; switch (type) { case UnitType.Settlers: unit = new Settlers(); break; case UnitType.Militia: unit = new Militia(); break; case UnitType.Phalanx: unit = new Phalanx(); break; case UnitType.Legion: unit = new Legion(); break; case UnitType.Musketeers: unit = new Musketeers(); break; case UnitType.Riflemen: unit = new Riflemen(); break; case UnitType.Cavalry: unit = new Cavalry(); break; case UnitType.Knights: unit = new Knights(); break; case UnitType.Catapult: unit = new Catapult(); break; case UnitType.Cannon: unit = new Cannon(); break; case UnitType.Chariot: unit = new Chariot(); break; case UnitType.Armor: unit = new Armor(); break; case UnitType.MechInf: unit = new MechInf(); break; case UnitType.Artillery: unit = new Artillery(); break; case UnitType.Fighter: unit = new Fighter(); break; case UnitType.Bomber: unit = new Bomber(); break; case UnitType.Trireme: unit = new Trireme(); break; case UnitType.Sail: unit = new Sail(); break; case UnitType.Frigate: unit = new Frigate(); break; case UnitType.Ironclad: unit = new Ironclad(); break; case UnitType.Cruiser: unit = new Cruiser(); break; case UnitType.Battleship: unit = new Battleship(); break; case UnitType.Submarine: unit = new Submarine(); break; case UnitType.Carrier: unit = new Carrier(); break; case UnitType.Transport: unit = new Transport(); break; case UnitType.Nuclear: unit = new Nuclear(); break; case UnitType.Diplomat: unit = new Diplomat(); break; case UnitType.Caravan: unit = new Caravan(); break; default: return(null); } unit.X = x; unit.Y = y; unit.MovesLeft = unit.Move; return(unit); }
private static void Postfix() { Mod.Log("MapScreen.OnInitialize"); MinSplitSize = Globals.Settings.MinPartySize * 2; EquipmentItems.Clear(); PopulateItems(); // 1.7 changed CreateHeroAtOccupation to only fish from this: NotableAndWandererTemplates // this has no effect on 1.6.5 since the property doesn't exist var characterObjects = CharacterObject.All.Where(x => x.Occupation is Occupation.Bandit && x.Name.Contains("Boss")).ToList().GetReadOnlyList(); foreach (var clan in Clan.BanditFactions) { Traverse.Create(clan.Culture).Property <IReadOnlyList <CharacterObject> >("NotableAndWandererTemplates").Value = characterObjects; } var filter = new List <string> { "regular_fighter", "veteran_borrowed_troop", }; Recruits = CharacterObject.All.Where(c => c.Level == 11 && c.Occupation == Occupation.Soldier && !filter.Contains(c.StringId) && !c.StringId.EndsWith("_tier_1")); // used for armour foreach (ItemObject.ItemTypeEnum value in Enum.GetValues(typeof(ItemObject.ItemTypeEnum))) { ItemTypes[value] = Items.All.Where(x => x.Type == value && x.Value >= 1000 && x.Value <= Globals.Settings.MaxItemValue).ToList(); } // front-load BanditEquipment.Clear(); for (var i = 0; i < 1000; i++) { BanditEquipment.Add(BuildViableEquipmentSet()); } PartyMilitiaMap.Clear(); Hideouts = Settlement.FindAll(x => x.IsHideout).ToList(); // considers leaderless militias var militias = MobileParty.All.Where(m => m.LeaderHero is not null && m.StringId.StartsWith("Bandit_Militia")).ToList(); for (var i = 0; i < militias.Count; i++) { var militia = militias[i]; var recreatedMilitia = new Militia(militia); SetMilitiaPatrol(recreatedMilitia.MobileParty); PartyMilitiaMap.Add(recreatedMilitia.MobileParty, recreatedMilitia); } DoPowerCalculations(true); FlushMilitiaCharacterObjects(); // 1.6 is dropping the militia settlements at some point, I haven't figured out where ReHome(); Mod.Log($"Militias: {militias.Count} (registered {PartyMilitiaMap.Count})"); RunLateManualPatches(); }
public override void ReadXml(XmlReader reader) { int num = reader.ReadVersionAttribute(); this.guid = reader.GetAttribute <ulong>("GUID"); this.userDefinedName = reader.GetAttribute("UserDefinedString"); this.TurnWhenToProceedWithRazing = reader.GetAttribute <int>("TurnWhenToProceedWithRazing"); this.ShouldRazeRegionBuildingWithSelf = reader.GetAttribute <bool>("ShouldRazeRegionBuildingWithSelf"); this.ShouldInjureSpyOnRaze = reader.GetAttribute <bool>("ShouldInjureSpyOnRaze"); this.AdministrationSpeciality = reader.GetAttribute <string>("AdministrationSpeciality"); AICityState aicityState; if (!StaticString.IsNullOrEmpty(this.AdministrationSpeciality) && (!Databases.GetDatabase <AICityState>(false).TryGetValue(this.AdministrationSpeciality, out aicityState) || !aicityState.IsGuiCompliant)) { this.AdministrationSpeciality = StaticString.Empty; } base.ReadXml(reader); int attribute = reader.GetAttribute <int>("Count"); reader.ReadStartElement("Districts"); this.districts.Clear(); for (int i = 0; i < attribute; i++) { District district = new District(reader.GetAttribute <ulong>("GUID")); reader.ReadElementSerializable <District>(ref district); if (district != null) { this.AddDistrict(district); } } reader.ReadEndElement("Districts"); if (num >= 2) { if (reader.IsNullElement()) { reader.Skip(); } else { Militia militia = new Militia(reader.GetAttribute <ulong>("GUID")); militia.Empire = this.Empire; reader.ReadElementSerializable <Militia>(ref militia); this.Militia = militia; if (this.Militia != null) { base.AddChild(this.Militia); } } } int attribute2 = reader.GetAttribute <int>("Count"); reader.ReadStartElement("Improvements"); this.cityImprovements.Clear(); for (int j = 0; j < attribute2; j++) { CityImprovement cityImprovement = new CityImprovement(reader.GetAttribute <ulong>("GUID")); reader.ReadElementSerializable <CityImprovement>(ref cityImprovement); if (cityImprovement != null) { this.AddCityImprovement(cityImprovement, false); } } reader.ReadEndElement("Improvements"); this.WorldPosition = reader.ReadElementSerializable <WorldPosition>(); if (num >= 2 && this.Militia != null) { this.Militia.WorldPosition = this.WorldPosition; } if (reader.IsStartElement("BesiegingEmpireIndex")) { int num2 = reader.ReadElementString <int>("BesiegingEmpireIndex"); this.BesiegingEmpireIndex = num2; } if (num >= 3) { if (reader.IsNullElement()) { reader.Skip(); } else { CadastralMap cadastralMap = new CadastralMap(); reader.ReadElementSerializable <CadastralMap>(ref cadastralMap); this.CadastralMap = cadastralMap; } } if (num >= 4) { this.TradeRoutes.Clear(); int attribute3 = reader.GetAttribute <int>("Count"); reader.ReadStartElement("TradeRoutes"); for (int k = 0; k < attribute3; k++) { TradeRoute item = new TradeRoute(); reader.ReadElementSerializable <TradeRoute>(ref item); this.TradeRoutes.Add(item); } base.SetPropertyBaseValue(SimulationProperties.IntermediateTradeRoutesCount, 0f); base.SetPropertyBaseValue(SimulationProperties.IntermediateTradeRoutesDistance, 0f); base.SetPropertyBaseValue(SimulationProperties.IntermediateTradeRoutesGain, 0f); reader.ReadEndElement("TradeRoutes"); } if (num >= 5) { int attribute4 = reader.GetAttribute <int>("Count"); if (this.Ownership.Length < attribute4) { this.Ownership = new float[attribute4]; } reader.ReadStartElement("Ownerships"); for (int l = 0; l < attribute4; l++) { this.Ownership[l] = reader.ReadElementString <float>("Ownership"); } reader.ReadEndElement("Ownerships"); } if (num >= 6) { this.DryDockPosition = reader.ReadElementSerializable <WorldPosition>(); } if (num >= 7) { Camp camp = new Camp(reader.GetAttribute <ulong>(Camp.SerializableNames.CampGUID)) { Empire = this.Empire }; reader.ReadElementSerializable <Camp>(ref camp); if (camp != null) { for (int m = 0; m < camp.Districts.Count; m++) { camp.Districts[m].City = this; base.AddChild(camp.Districts[m]); camp.Districts[m].Refresh(false); } this.Camp = camp; } } if (num >= 8) { this.lastNonInfectedOwnerIndex = reader.ReadElementString <int>("LastNonInfectedOwnerIndex"); } }
public void ReturnToBase(Militia militia) { militias.Remove(militia); readyMilitias++; }
// BASE static PresetGames() { games.Add(Games.AllCards1stEdition, new List <Card> { Adventurer.Get(), Bureaucrat.Get(), Cellar.Get(), CouncilRoom.Get(), Feast.Get(), Festival.Get(), Gardens.Get(), Chancellor.Get(), Chapel.Get(), Laboratory.Get(), Library.Get(), Market.Get(), Militia.Get(), Mine.Get(), Moat.Get(), Moneylender.Get(), Remodel.Get(), Smithy.Get(), Spy.Get(), Thief.Get(), ThroneRoom.Get(), Village.Get(), Witch.Get(), Woodcutter.Get(), Workshop.Get(), }); games.Add(Games.FirstGame, new List <Card> { Cellar.Get(), Moat.Get(), Village.Get(), Woodcutter.Get(), Workshop.Get(), Militia.Get(), Remodel.Get(), Smithy.Get(), Market.Get(), Mine.Get(), }); games.Add(Games.BigMoney, new List <Card> { Adventurer.Get(), Bureaucrat.Get(), Chancellor.Get(), Chapel.Get(), Feast.Get(), Laboratory.Get(), Market.Get(), Mine.Get(), Moneylender.Get(), ThroneRoom.Get(), }); games.Add(Games.Interaction, new List <Card> { Bureaucrat.Get(), Chancellor.Get(), CouncilRoom.Get(), Festival.Get(), Library.Get(), Militia.Get(), Moat.Get(), Spy.Get(), Thief.Get(), Village.Get() }); games.Add(Games.SizeDistortion, new List <Card> { Cellar.Get(), Chapel.Get(), Feast.Get(), Gardens.Get(), Laboratory.Get(), Thief.Get(), Village.Get(), Witch.Get(), Woodcutter.Get(), Workshop.Get(), }); games.Add(Games.VillageSquare, new List <Card> { Bureaucrat.Get(), Cellar.Get(), Festival.Get(), Library.Get(), Market.Get(), Remodel.Get(), Smithy.Get(), ThroneRoom.Get(), Village.Get(), Woodcutter.Get(), }); games.Add(Games.ThrashHeap, new List <Card> { Chapel.Get(), Village.Get(), Workshop.Get(), Woodcutter.Get(), Feast.Get(), Moneylender.Get(), Remodel.Get(), Mine.Get(), Festival.Get(), Market.Get(), }); }
/// <summary> /// Creates a new card based on how many cards have already been made. /// </summary> /// <param name="card"> /// The name of the card to be created. /// </param> /// <returns> /// The new created card. /// </returns> public static Card CreateCard(CardName card) { Contract.Requires(card != CardName.Backside & card != CardName.Empty); Contract.Ensures(Contract.Result<Card>().Name == card); Card c; switch (card) { case CardName.Copper: c = new Copper(); break; case CardName.Silver: c = new Silver(); break; case CardName.Gold: c = new Gold(); break; case CardName.Curse: c = new Curse(); break; case CardName.Estate: c = new Estate(); break; case CardName.Duchy: c = new Duchy(); break; case CardName.Province: c = new Province(); break; case CardName.Gardens: c = new Gardens(); break; case CardName.Cellar: c = new Cellar(); break; case CardName.Chapel: c = new Chapel(); break; case CardName.Chancellor: c = new Chancellor(); break; case CardName.Village: c = new Village(); break; case CardName.Woodcutter: c = new Woodcutter(); break; case CardName.Workshop: c = new Workshop(); break; case CardName.Feast: c = new Feast(); break; case CardName.Moneylender: c = new Moneylender(); break; case CardName.Remodel: c = new Remodel(); break; case CardName.Smithy: c = new Smithy(); break; case CardName.ThroneRoom: c = new ThroneRoom(); break; case CardName.CouncilRoom: c = new CouncilRoom(); break; case CardName.Festival: c = new Festival(); break; case CardName.Laboratory: c = new Laboratory(); break; case CardName.Library: c = new Library(); break; case CardName.Market: c = new Market(); break; case CardName.Mine: c = new Mine(); break; case CardName.Adventurer: c = new Adventurer(); break; case CardName.Bureaucrat: c = new Bureaucrat(); break; case CardName.Militia: c = new Militia(); break; case CardName.Spy: c = new Spy(); break; case CardName.Thief: c = new Thief(); break; case CardName.Witch: c = new Witch(); break; case CardName.Moat: c = new Moat(); break; default: throw new NotImplementedException("Tried to create a card that was not implemented when CardFactory was last updated."); } c.Initialize(card, CardsMade[card]); CardsMade[card] += 1; createdCards.Add(c, true); return c; }
// main merge method private static void Postfix() { if (Campaign.Current.TimeControlMode == CampaignTimeControlMode.Stop || Campaign.Current.TimeControlMode == CampaignTimeControlMode.UnstoppableFastForwardForPartyWaitTime || Campaign.Current.TimeControlMode == CampaignTimeControlMode.FastForwardStop || Campaign.Current.TimeControlMode == CampaignTimeControlMode.StoppableFastForward) { return; } if (Campaign.CurrentTime - lastChecked < 1f) { return; } lastChecked = Campaign.CurrentTime; var hideouts = Settlement.All.Where(s => s.IsHideout).ToList(); var parties = MobileParty.All.Where(m => m.Party.IsMobile && m.CurrentSettlement is null && !m.IsUsedByAQuest() && m.IsBandit && m.MemberRoster.TotalManCount >= Globals.Settings.MinPartySizeToConsiderMerge) .ToListQ(); for (var index = 0; index < parties.Count; index++) { //T.Restart(); var mobileParty = parties[index]; if (hideouts.AnyQ(s => s.Position2D.Distance(mobileParty.Position2D) < MinDistanceFromHideout)) { continue; } if (mobileParty.IsTooBusyToMerge()) { continue; } var nearbyParties = MobileParty.FindPartiesAroundPosition(mobileParty.Position2D, FindRadius) .Intersect(parties) .Except(new[] { mobileParty }) .ToListQ(); if (!nearbyParties.Any()) { continue; } if (mobileParty.ToString().Contains("manhunter")) // Calradia Expanded Kingdoms { continue; } CampaignTime?lastChangeDate = null; if (mobileParty.IsBM()) { lastChangeDate = PartyMilitiaMap[mobileParty].LastMergedOrSplitDate; } if (CampaignTime.Now < lastChangeDate + CampaignTime.Hours(Globals.Settings.CooldownHours)) { continue; } var targetParty = nearbyParties.Where(m => IsAvailableBanditParty(m) && m.MemberRoster.TotalManCount + mobileParty.MemberRoster.TotalManCount >= Globals.Settings.MinPartySize) .ToListQ().GetRandomElement()?.Party; //Mod.Log($">T targetParty {T.ElapsedTicks / 10000F:F3}ms."); // "nobody" is a valid answer if (targetParty is null) { continue; } CampaignTime?targetLastChangeDate = null; if (targetParty.MobileParty.IsBM()) { targetLastChangeDate = PartyMilitiaMap[targetParty.MobileParty].LastMergedOrSplitDate; } if (CampaignTime.Now < targetLastChangeDate + CampaignTime.Hours(Globals.Settings.CooldownHours)) { continue; } var militiaTotalCount = mobileParty.MemberRoster.TotalManCount + targetParty.MemberRoster.TotalManCount; if (MilitiaPowerPercent > Globals.Settings.GlobalPowerPercent || militiaTotalCount < Globals.Settings.MinPartySize || militiaTotalCount > CalculatedMaxPartySize || NumMountedTroops(mobileParty.MemberRoster) + NumMountedTroops(targetParty.MemberRoster) > militiaTotalCount / 2) { continue; } //Mod.Log($"==> counted {T.ElapsedTicks / 10000F:F3}ms."); if (mobileParty != targetParty.MobileParty.MoveTargetParty && Campaign.Current.Models.MapDistanceModel.GetDistance(targetParty.MobileParty, mobileParty) > MergeDistance) { //Mod.Log($"{mobileParty} seeking > {targetParty.MobileParty}"); mobileParty.SetMoveEscortParty(targetParty.MobileParty); //Mod.Log($"SetNavigationModeParty ==> {T.ElapsedTicks / 10000F:F3}ms"); if (targetParty.MobileParty.MoveTargetParty != mobileParty) { //Mod.Log($"{targetParty.MobileParty} seeking back > {mobileParty}"); targetParty.MobileParty.SetMoveEscortParty(mobileParty); //Mod.Log($"SetNavigationModeTargetParty ==> {T.ElapsedTicks / 10000F:F3}ms"); } continue; } //Mod.Log($"==> found settlement {T.ElapsedTicks / 10000F:F3}ms."); // create a new party merged from the two var rosters = MergeRosters(mobileParty, targetParty); var militia = new Militia(mobileParty.Position2D, rosters[0], rosters[1]); // teleport new militias near the player if (Globals.Settings.TestingMode) { // in case a prisoner var party = Hero.MainHero.PartyBelongedTo ?? Hero.MainHero.PartyBelongedToAsPrisoner.MobileParty; militia.MobileParty.Position2D = party.Position2D; } militia.MobileParty.Party.Visuals.SetMapIconAsDirty(); try { // can throw if Clan is null Trash(mobileParty); Trash(targetParty.MobileParty); } catch (Exception ex) { Mod.Log(ex); } DoPowerCalculations(); //Mod.Log($"==> Finished all work: {T.ElapsedTicks / 10000F:F3}ms."); } //Mod.Log($"Looped ==> {T.ElapsedTicks / 10000F:F3}ms"); }
private static void Postfix() { try { if (Campaign.Current.TimeControlMode == CampaignTimeControlMode.Stop || Campaign.Current.TimeControlMode == CampaignTimeControlMode.UnstoppableFastForwardForPartyWaitTime || Campaign.Current.TimeControlMode == CampaignTimeControlMode.FastForwardStop || Campaign.Current.TimeControlMode == CampaignTimeControlMode.StoppableFastForward || GlobalMilitiaPower > CalculatedGlobalPowerLimit) { return; } var parties = MobileParty.All.Where(x => x.Party.IsMobile && x.CurrentSettlement == null && !x.IsCurrentlyUsedByAQuest && x.IsBandit).ToList(); //T.Restart(); for (var index = 0; index < parties.Count; index++) { var mobileParty = parties[index]; if (mobileParty.MoveTargetParty != null && mobileParty.MoveTargetParty.IsBandit || // Calradia Expanded Kingdoms mobileParty.ToString().Contains("manhunter") || mobileParty.IsTooBusyToMerge()) { continue; } CampaignTime?lastChangeDate = null; if (PartyMilitiaMap.ContainsKey(mobileParty)) { lastChangeDate = PartyMilitiaMap[mobileParty].LastMergedOrSplitDate; } if (CampaignTime.Now < lastChangeDate + CampaignTime.Hours(Globals.Settings.CooldownHours)) { continue; } var targetParty = MobileParty.FindPartiesAroundPosition(mobileParty.Position2D, FindRadius, x => x != mobileParty && IsValidParty(x) && x.MemberRoster.TotalManCount + mobileParty.MemberRoster.TotalManCount >= Globals.Settings.MinPartySize) .ToList().GetRandomElement()?.Party; // "nobody" is a valid answer if (targetParty == null) { continue; } CampaignTime?targetLastChangeDate = null; if (PartyMilitiaMap.ContainsKey(targetParty.MobileParty)) { targetLastChangeDate = PartyMilitiaMap[mobileParty].LastMergedOrSplitDate; } if (CampaignTime.Now < targetLastChangeDate + CampaignTime.Hours(Globals.Settings.CooldownHours)) { continue; } var militiaTotalCount = mobileParty.MemberRoster.TotalManCount + targetParty.MemberRoster.TotalManCount; if (militiaTotalCount < Globals.Settings.MinPartySize || militiaTotalCount > CalculatedMaxPartySize || mobileParty.Party.TotalStrength > CalculatedMaxPartyStrength || NumMountedTroops(mobileParty.MemberRoster) + NumMountedTroops(targetParty.MemberRoster) > militiaTotalCount / 2) { continue; } if (Campaign.Current.Models.MapDistanceModel.GetDistance(targetParty.MobileParty, mobileParty) > MergeDistance) { Mod.Log($"{mobileParty} seeking > {targetParty.MobileParty}"); mobileParty.SetMoveEscortParty(targetParty.MobileParty); //Mod.Log($"SetNavigationModeParty ==> {T.ElapsedTicks / 10000F:F3}ms"); if (targetParty.MobileParty.MoveTargetParty != mobileParty) { Mod.Log($"{targetParty.MobileParty} seeking back > {mobileParty}"); targetParty.MobileParty.SetMoveEscortParty(mobileParty); //Mod.Log($"SetNavigationModeTargetParty ==> {T.ElapsedTicks / 10000F:F3}ms"); } continue; } if (Settlement.FindSettlementsAroundPosition(mobileParty.Position2D, MinDistanceFromHideout, x => x.IsHideout()).Any()) { continue; } // create a new party merged from the two var rosters = MergeRosters(mobileParty, targetParty); var militia = new Militia(mobileParty, rosters[0], rosters[1]); militia.MobileParty.SetMovePatrolAroundPoint(militia.MobileParty.Position2D); // teleport new militias near the player if (TestingMode) { // in case a prisoner var party = Hero.MainHero.PartyBelongedTo ?? Hero.MainHero.PartyBelongedToAsPrisoner.MobileParty; militia.MobileParty.Position2D = party.Position2D; } militia.MobileParty.Party.Visuals.SetMapIconAsDirty(); Trash(mobileParty); Trash(targetParty.MobileParty); //Mod.Log($">>> Finished all work: {T.ElapsedTicks / 10000F:F3}ms."); } //Mod.Log($"Looped ==> {T.ElapsedTicks / 10000F:F3}ms"); } catch (Exception ex) { Mod.Log(ex); } }