diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3bb97fb --- /dev/null +++ b/.gitignore @@ -0,0 +1,115 @@ +# Build Folders +bin/ +obj/ + +# Rider Specific +.idea/ +*.sln.iml + +# Visual Studio Code Specific +.vscode/ + +# Visual Studio Specific +.vs/ + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# Mono Auto Generated Files +mono_crash.* + +# Windows image file caches +Thumbs.db +ehthumbs.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# macOS files +.DS_Store +.AppleDouble +.LSOverride + +# UNIX files +.Trashes +.nfs* + +# Certificate files +*.pfx +*.p12 + +# Azure Pipelines +.azuredevops/ + +# Node.js folders +node_modules/ + +# JetBrains Rider config files +.idea/ + +# Microsoft Azure Web App +.project + +# Windows Installer files +*.cab +*.msi +*.msm +*.msp + +# VS Code specific settings +.vscode/ + +# Rider specific settings +.idea/ + +# Logs +*.log + +# Environment variables +.env + +# .NET user secrets +secrets.json + +# Local history for Visual Studio Code +.history/ + +# Coverage Reports +coverage/ +*.coverage +*.coveragexml +*.log + +# Crash and other diagnostic reports +*.crash +*.diagsession +*.dmp +*.hl +*.dmp +*.lst +*.mdmp + +# Docker files +docker-compose.override.yml + +# Resharper files +_ReSharper.Caches/ + +# Temporary folders +tmp/ +temp/ + +# Other general exclusions +*.lock +*.swp +*.bak +*.orig +*.rej +*~ diff --git a/Source/RimWar/Options/Controller.cs b/Source/RimWar/Options/Controller.cs index 4e4ee01..c985a80 100644 --- a/Source/RimWar/Options/Controller.cs +++ b/Source/RimWar/Options/Controller.cs @@ -300,7 +300,7 @@ public override void DoSettingsWindowContents(Rect canvas) TooltipHandler.TipRegion(rowRect6, "RW_eventFrequencyInfo".Translate()); num++; Rect rowRect4 = UIHelper.GetRowRect(rowRect6, rowHeight, num); - Settings.Instance.settlementScanRangeDivider = Mathf.RoundToInt(Widgets.HorizontalSlider(rowRect4, Settings.Instance.settlementScanRangeDivider, 200, 20, false, "RW_scanRange".Translate() + " " + Mathf.RoundToInt(1000 / Settings.Instance.settlementScanRangeDivider), "Close", "Far", 1f)); + Settings.Instance.settlementScanRangeDivider = Mathf.RoundToInt(Widgets.HorizontalSlider(rowRect4, Settings.Instance.settlementScanRangeDivider, 20, 200, false, "RW_scanRange".Translate() + " " + Mathf.RoundToInt(1000 / Settings.Instance.settlementScanRangeDivider), "Far", "Close", 1f)); TooltipHandler.TipRegion(rowRect4, "RW_scanRangeInfo".Translate()); num++; Rect rowRect3 = UIHelper.GetRowRect(rowRect4, rowHeight, num); diff --git a/Source/RimWar/Planet/RimWarSettlementComp.cs b/Source/RimWar/Planet/RimWarSettlementComp.cs index cdc032c..a0153d4 100644 --- a/Source/RimWar/Planet/RimWarSettlementComp.cs +++ b/Source/RimWar/Planet/RimWarSettlementComp.cs @@ -9,6 +9,7 @@ using RimWar; using RimWorld; using RimWorld.Planet; +using System.Threading; //using FactionColonies; namespace RimWar.Planet @@ -282,28 +283,38 @@ public int ReinforcementPoints private List settlementsInRange; private List tmpSettlementsInRange; + private Mutex tmpSettlementsMutex; + private Mutex rangeSettlementsMutex; public List OtherSettlementsInRange { get { if (this.settlementsInRange == null) { + this.rangeSettlementsMutex.WaitOne(); this.settlementsInRange = new List(); this.settlementsInRange.Clear(); + this.rangeSettlementsMutex.ReleaseMutex(); } - if(tmpSettlementsInRange == null) + if (tmpSettlementsInRange == null) { + this.tmpSettlementsMutex.WaitOne(); tmpSettlementsInRange = new List(); tmpSettlementsInRange.Clear(); + this.tmpSettlementsMutex.ReleaseMutex(); } + this.rangeSettlementsMutex.WaitOne(); settlementsInRange.Clear(); + this.rangeSettlementsMutex.ReleaseMutex(); AddTmpSettlementsToMain(); //settlementsInRange.AddRange(tmpSettlementsInRange); if (this.settlementsInRange.Count == 0 || this.nextSettlementScan <= Find.TickManager.TicksGame) { if (Options.Settings.Instance.threadingEnabled) { + this.tmpSettlementsMutex.WaitOne(); tmpSettlementsInRange.Clear(); + this.tmpSettlementsMutex.ReleaseMutex(); Options.SettingsRef settingsRef = new Options.SettingsRef(); this.nextSettlementScan = Find.TickManager.TicksGame + settingsRef.settlementScanDelay; WorldComponent_PowerTracker.tasker.Register(() => @@ -322,7 +333,9 @@ public List OtherSettlementsInRange } else { + this.tmpSettlementsMutex.WaitOne(); tmpSettlementsInRange.Clear(); + this.tmpSettlementsMutex.ReleaseMutex(); Options.SettingsRef settingsRef = new Options.SettingsRef(); List scanSettlements = WorldUtility.GetRimWorldSettlementsInRange(this.parent.Tile, SettlementScanRange); if (scanSettlements != null && scanSettlements.Count > 0) @@ -331,7 +344,9 @@ public List OtherSettlementsInRange { if (scanSettlements[i] != this.parent) { + this.tmpSettlementsMutex.WaitOne(); tmpSettlementsInRange.Add(scanSettlements[i]); + this.tmpSettlementsMutex.ReleaseMutex(); } } } @@ -348,6 +363,7 @@ public List OtherSettlementsInRange private void AddTmpSettlementsToMain() { + this.rangeSettlementsMutex.WaitOne(); try { foreach (Settlement s in tmpSettlementsInRange) @@ -359,10 +375,12 @@ private void AddTmpSettlementsToMain() } } catch { } + this.rangeSettlementsMutex.ReleaseMutex(); } private void AddSettlementsToTmp(List scanSettlements) { + this.tmpSettlementsMutex.WaitOne(); for (int i = 0; i < scanSettlements.Count; i++) { if (scanSettlements[i] != this.parent) @@ -370,6 +388,7 @@ private void AddSettlementsToTmp(List scanSettlement tmpSettlementsInRange.Add(scanSettlements[i]); } } + this.tmpSettlementsMutex.ReleaseMutex(); } public List NearbyHostileSettlements @@ -377,7 +396,9 @@ public List NearbyHostileSettlements get { List tmpSettlements = new List(); + this.tmpSettlementsMutex.WaitOne(); tmpSettlements.Clear(); + this.tmpSettlementsMutex.ReleaseMutex(); if (OtherSettlementsInRange != null && OtherSettlementsInRange.Count > 0) { try @@ -387,7 +408,9 @@ public List NearbyHostileSettlements RimWarSettlementComp rwsc = OtherSettlementsInRange[i].GetComponent(); if (OtherSettlementsInRange[i] != null && rwsc != null && rwsc.RimWarPoints > 0 && OtherSettlementsInRange[i].Faction != null && OtherSettlementsInRange[i].Faction.HostileTo(this.parent.Faction)) { + this.tmpSettlementsMutex.WaitOne(); tmpSettlements.Add(OtherSettlementsInRange[i]); + this.tmpSettlementsMutex.ReleaseMutex(); } } } @@ -405,6 +428,7 @@ public List PlayerSettlementsInRange get { List tmpPlayerSettlements = new List(); + this.tmpSettlementsMutex.WaitOne(); tmpPlayerSettlements.Clear(); foreach(Settlement s in NearbyHostileSettlements) { @@ -413,6 +437,7 @@ public List PlayerSettlementsInRange tmpPlayerSettlements.Add(s); } } + this.tmpSettlementsMutex.ReleaseMutex(); return tmpPlayerSettlements; } } @@ -441,7 +466,9 @@ public List NearbyFriendlySettlements get { List tmpSettlements = new List(); + this.tmpSettlementsMutex.WaitOne(); tmpSettlements.Clear(); + this.tmpSettlementsMutex.ReleaseMutex(); if (OtherSettlementsInRange != null && OtherSettlementsInRange.Count > 0) { try @@ -451,8 +478,10 @@ public List NearbyFriendlySettlements RimWarSettlementComp rwsc = OtherSettlementsInRange[i].GetComponent(); if (OtherSettlementsInRange[i] != null && rwsc != null && rwsc.RimWarPoints > 0 && !OtherSettlementsInRange[i].Faction.HostileTo(this.parent.Faction)) { + this.tmpSettlementsMutex.WaitOne(); //Log.Message(OtherSettlementsInRange[i].Label); tmpSettlements.Add(OtherSettlementsInRange[i]); + this.tmpSettlementsMutex.ReleaseMutex(); } } } @@ -468,6 +497,7 @@ public List NearbyFriendlySettlements public List NearbyFriendlySettlementsWithinRange(float range) { List tmpSettlements = new List(); + this.tmpSettlementsMutex.WaitOne(); tmpSettlements.Clear(); List allSettlements = Find.WorldObjects.Settlements; if(allSettlements != null && allSettlements.Count > 0) @@ -482,6 +512,7 @@ public List NearbyFriendlySettlements } } } + this.tmpSettlementsMutex.ReleaseMutex(); return tmpSettlements; } @@ -490,6 +521,8 @@ public override void Initialize(WorldObjectCompProperties props) base.Initialize(props); this.settlementsInRange = new List(); this.settlementsInRange.Clear(); + this.tmpSettlementsMutex = new Mutex(); + this.rangeSettlementsMutex = new Mutex(); } public override void CompTick() @@ -894,4 +927,4 @@ public override void PostDrawExtraSelectionOverlays() //} } -} \ No newline at end of file +} diff --git a/Source/RimWar/Planet/WorldComponent_PowerTracker.cs b/Source/RimWar/Planet/WorldComponent_PowerTracker.cs index 7552199..b2e21a6 100644 --- a/Source/RimWar/Planet/WorldComponent_PowerTracker.cs +++ b/Source/RimWar/Planet/WorldComponent_PowerTracker.cs @@ -280,7 +280,7 @@ public override void WorldComponentTick() rwsComp.RimWarPoints += Rand.Range(10, 100); this.globalActions++; } - bool requestedReinforcement = false; + //bool requestedReinforcement = false; if (rwsComp.ShouldRequestReinforcements && rwsComp.CanReinforce) { List reinforcementSettlements = rwsComp.NearbyFriendlySettlementsWithinRange(50); @@ -360,7 +360,7 @@ public override void WorldComponentTick() else { this.creationAttempts++; - } + } } } } @@ -1137,7 +1137,8 @@ private void AttemptWarbandActionAgainstTownOnMainThread(RimWarData rwd, RimWorl if (rwsComp.RimWarPoints * .85f >= pts || ignoreRestrictions) { WorldUtility.CreateWarband(pts, rwd, parentSettlement, parentSettlement.Tile, targetTown, WorldObjectDefOf.Settlement); - rwsComp.RimWarPoints = rwsComp.RimWarPoints - WorldUtility.RelativePowerCostAdjustment(pts, rwd); + // This costs around 150-200ms for this adjustment + //rwsComp.RimWarPoints -= WorldUtility.RelativePowerCostAdjustment(pts, rwd); if (targetTown.Faction == Faction.OfPlayer) { rwsComp.PlayerHeat = 0; @@ -1148,7 +1149,8 @@ private void AttemptWarbandActionAgainstTownOnMainThread(RimWarData rwd, RimWorl else if (rwsComp.RimWarPoints * .75f >= pts || ignoreRestrictions) { WorldUtility.CreateWarband(pts, rwd, parentSettlement, parentSettlement.Tile, targetTown, WorldObjectDefOf.Settlement); - rwsComp.RimWarPoints = rwsComp.RimWarPoints - WorldUtility.RelativePowerCostAdjustment(pts, rwd); + // This costs around 150-200ms for this adjustment + //rwsComp.RimWarPoints -= WorldUtility.RelativePowerCostAdjustment(pts, rwd); if (targetTown.Faction == Faction.OfPlayer) { rwsComp.PlayerHeat = 0; @@ -1239,7 +1241,8 @@ public void AttemptWarbandActionAgainstTown_UnThreaded(RimWarData rwd, RimWorld. if (rwsComp.RimWarPoints * .85f >= pts || ignoreRestrictions) { WorldUtility.CreateWarband(pts, rwd, parentSettlement, parentSettlement.Tile, targetTown, WorldObjectDefOf.Settlement); - rwsComp.RimWarPoints = rwsComp.RimWarPoints - WorldUtility.RelativePowerCostAdjustment(pts, rwd); + // This costs around 150-200ms for this adjustment + //rwsComp.RimWarPoints -= WorldUtility.RelativePowerCostAdjustment(pts, rwd); if (targetTown.Faction == Faction.OfPlayer) { rwsComp.PlayerHeat = 0; @@ -1255,7 +1258,8 @@ public void AttemptWarbandActionAgainstTown_UnThreaded(RimWarData rwd, RimWorld. else if (rwsComp.RimWarPoints * .75f >= pts || ignoreRestrictions) { WorldUtility.CreateWarband(pts, rwd, parentSettlement, parentSettlement.Tile, targetTown, WorldObjectDefOf.Settlement); - rwsComp.RimWarPoints = rwsComp.RimWarPoints - WorldUtility.RelativePowerCostAdjustment(pts, rwd); + // This costs around 150-200ms for this adjustment + //rwsComp.RimWarPoints -= WorldUtility.RelativePowerCostAdjustment(pts, rwd); if (targetTown.Faction == Faction.OfPlayer) { rwsComp.PlayerHeat = 0; @@ -1279,7 +1283,7 @@ public void AttemptWarbandActionAgainstTown_UnThreaded(RimWarData rwd, RimWorld. public void AttemptWarbandActionAgainstTown(RimWarData rwd, RimWorld.Planet.Settlement parentSettlement, RimWarSettlementComp rwsComp, bool forcePlayer = false, bool ignoreRestrictions = false) { - if (Options.Settings.Instance.threadingEnabled) + if (false) //Options.Settings.Instance.threadingEnabled) { if (rwd != null && rwsComp != null) { @@ -1405,7 +1409,8 @@ public void AttemptLaunchedWarbandAgainstTownOnMainThread(RimWarData rwd, RimWor if (rwsComp.RimWarPoints * .8f >= pts || ignoreRestrictions) { WorldUtility.CreateLaunchedWarband(pts, rwd, parentSettlement, parentSettlement.Tile, targetTown, WorldObjectDefOf.Settlement); - rwsComp.RimWarPoints = rwsComp.RimWarPoints - WorldUtility.RelativePowerCostAdjustment(pts, rwd); + // This costs around 150-200ms for this adjustment + //rwsComp.RimWarPoints -= WorldUtility.RelativePowerCostAdjustment(pts, rwd); if (targetTown.Faction == Faction.OfPlayer) { rwsComp.PlayerHeat = 0; @@ -1422,7 +1427,8 @@ public void AttemptLaunchedWarbandAgainstTownOnMainThread(RimWarData rwd, RimWor { //Log.Message("launching warband from " + rwsComp.RimWorld_Settlement.Name); WorldUtility.CreateLaunchedWarband(pts, rwd, parentSettlement, parentSettlement.Tile, targetTown, WorldObjectDefOf.Settlement); - rwsComp.RimWarPoints = rwsComp.RimWarPoints - WorldUtility.RelativePowerCostAdjustment(pts, rwd); + // This costs around 150-200ms for this adjustment + //rwsComp.RimWarPoints -= WorldUtility.RelativePowerCostAdjustment(pts, rwd); if (targetTown.Faction == Faction.OfPlayer) { rwsComp.PlayerHeat = 0; @@ -1507,7 +1513,8 @@ public void AttemptLaunchedWarbandAgainstTown_UnThreaded(RimWarData rwd, RimWorl if (rwsComp.RimWarPoints * .8f >= pts || ignoreRestrictions) { WorldUtility.CreateLaunchedWarband(pts, rwd, parentSettlement, parentSettlement.Tile, targetTown, WorldObjectDefOf.Settlement); - rwsComp.RimWarPoints = rwsComp.RimWarPoints - WorldUtility.RelativePowerCostAdjustment(pts, rwd); + // This costs around 150-200ms for this adjustment + //rwsComp.RimWarPoints -= WorldUtility.RelativePowerCostAdjustment(pts, rwd); if (targetTown.Faction == Faction.OfPlayer) { rwsComp.PlayerHeat = 0; @@ -1524,7 +1531,8 @@ public void AttemptLaunchedWarbandAgainstTown_UnThreaded(RimWarData rwd, RimWorl { //Log.Message("launching warband from " + rwsComp.RimWorld_Settlement.Name); WorldUtility.CreateLaunchedWarband(pts, rwd, parentSettlement, parentSettlement.Tile, targetTown, WorldObjectDefOf.Settlement); - rwsComp.RimWarPoints = rwsComp.RimWarPoints - WorldUtility.RelativePowerCostAdjustment(pts, rwd); + // This costs around 150-200ms for this adjustment + //rwsComp.RimWarPoints -= WorldUtility.RelativePowerCostAdjustment(pts, rwd); if (targetTown.Faction == Faction.OfPlayer) { rwsComp.PlayerHeat = 0; @@ -1542,7 +1550,7 @@ public void AttemptLaunchedWarbandAgainstTown_UnThreaded(RimWarData rwd, RimWorl public void AttemptLaunchedWarbandAgainstTown(RimWarData rwd, RimWorld.Planet.Settlement parentSettlement, RimWarSettlementComp rwsComp, bool forcePlayer = false, bool ignoreRestrictions = false) { - if (Options.Settings.Instance.threadingEnabled) + if (false) //Options.Settings.Instance.threadingEnabled) { if (rwsComp.RimWarPoints >= 1000 || ignoreRestrictions) { @@ -1605,7 +1613,8 @@ private void AttemptScoutOnMainThread(RimWarData rwd, RimWorld.Planet.Settlement Caravan playerCaravan = wo as Caravan; int pts = WorldUtility.CalculateScoutMissionPoints(rwd, Mathf.RoundToInt(playerCaravan.PlayerWealthForStoryteller / 200)); WorldUtility.CreateScout(pts, rwd, parentSettlement, parentSettlement.Tile, wo, WorldObjectDefOf.Caravan); - rwsComp.RimWarPoints = rwsComp.RimWarPoints - WorldUtility.RelativePowerCostAdjustment(pts, rwd); + // This costs around 150-200ms for this adjustment + //rwsComp.RimWarPoints -= WorldUtility.RelativePowerCostAdjustment(pts, rwd); rwsComp.PlayerHeat = 0; minimumHeatForPlayerAction += GetHeatForAction(RimWarAction.ScoutingParty); } @@ -1618,7 +1627,8 @@ private void AttemptScoutOnMainThread(RimWarData rwd, RimWorld.Planet.Settlement pts = Mathf.RoundToInt(pts * 1.2f); } WorldUtility.CreateScout(pts, rwd, parentSettlement, parentSettlement.Tile, wo, RimWarDefOf.RW_WarObject); - rwsComp.RimWarPoints = rwsComp.RimWarPoints - WorldUtility.RelativePowerCostAdjustment(pts, rwd); + // This costs around 150-200ms for this adjustment + //rwsComp.RimWarPoints -= WorldUtility.RelativePowerCostAdjustment(pts, rwd); if (wo.Faction == Faction.OfPlayer || WorldUtility.IsVassalFaction(wo.Faction)) { rwsComp.PlayerHeat = 0; @@ -1634,7 +1644,8 @@ private void AttemptScoutOnMainThread(RimWarData rwd, RimWorld.Planet.Settlement pts = Mathf.RoundToInt(pts * 1.2f); } WorldUtility.CreateScout(pts, rwd, parentSettlement, parentSettlement.Tile, wo, WorldObjectDefOf.Settlement); - rwsComp.RimWarPoints = rwsComp.RimWarPoints - WorldUtility.RelativePowerCostAdjustment(pts, rwd); + // This costs around 150-200ms for this adjustment + //rwsComp.RimWarPoints -= WorldUtility.RelativePowerCostAdjustment(pts, rwd); if (wo.Faction == Faction.OfPlayer) { rwsComp.PlayerHeat = 0; @@ -1841,10 +1852,10 @@ public void AttemptScoutMission_UnThreaded(RimWarData rwd, RimWorld.Planet.Settl Caravan playerCaravan = wo as Caravan; int pts = WorldUtility.CalculateScoutMissionPoints(rwd, Mathf.RoundToInt(playerCaravan.PlayerWealthForStoryteller / 200)); WorldUtility.CreateScout(pts, rwd, parentSettlement, parentSettlement.Tile, wo, WorldObjectDefOf.Caravan); - rwsComp.RimWarPoints = rwsComp.RimWarPoints - WorldUtility.RelativePowerCostAdjustment(pts, rwd); + // This costs around 150-200ms for this adjustment + //rwsComp.RimWarPoints -= WorldUtility.RelativePowerCostAdjustment(pts, rwd); rwsComp.PlayerHeat = 0; minimumHeatForPlayerAction += GetHeatForAction(RimWarAction.ScoutingParty); - } else if (wo is WarObject) { @@ -1855,7 +1866,8 @@ public void AttemptScoutMission_UnThreaded(RimWarData rwd, RimWorld.Planet.Settl pts = Mathf.RoundToInt(pts * 1.2f); } WorldUtility.CreateScout(pts, rwd, parentSettlement, parentSettlement.Tile, wo, RimWarDefOf.RW_WarObject); - rwsComp.RimWarPoints = rwsComp.RimWarPoints - WorldUtility.RelativePowerCostAdjustment(pts, rwd); + // This costs around 150-200ms for this adjustment + //rwsComp.RimWarPoints -= WorldUtility.RelativePowerCostAdjustment(pts, rwd); if (wo.Faction == Faction.OfPlayer || WorldUtility.IsVassalFaction(wo.Faction)) { rwsComp.PlayerHeat = 0; @@ -1871,7 +1883,8 @@ public void AttemptScoutMission_UnThreaded(RimWarData rwd, RimWorld.Planet.Settl pts = Mathf.RoundToInt(pts * 1.2f); } WorldUtility.CreateScout(pts, rwd, parentSettlement, parentSettlement.Tile, wo, WorldObjectDefOf.Settlement); - rwsComp.RimWarPoints = rwsComp.RimWarPoints - WorldUtility.RelativePowerCostAdjustment(pts, rwd); + // This costs around 150-200ms for this adjustment + //rwsComp.RimWarPoints -= WorldUtility.RelativePowerCostAdjustment(pts, rwd); if (wo.Faction == Faction.OfPlayer) { rwsComp.PlayerHeat = 0; @@ -1889,7 +1902,7 @@ public void AttemptScoutMission_UnThreaded(RimWarData rwd, RimWorld.Planet.Settl public void AttemptScoutMission(RimWarData rwd, RimWorld.Planet.Settlement parentSettlement, RimWarSettlementComp rwsComp, bool forcePlayerTown = false, bool forcePlayerCaravan = false, bool ignoreRestrictions = false) { - if (Options.Settings.Instance.threadingEnabled) + if (false) //Options.Settings.Instance.threadingEnabled) { if (rwd != null && rwsComp != null) { @@ -2001,7 +2014,8 @@ private void AttemptSettlerOnMainThread(RimWarData rwd, RimWorld.Planet.Settleme { int pts = Mathf.RoundToInt(Rand.Range(.4f, .6f) * 500); WorldUtility.CreateSettler(pts, rwd, parentSettlement, parentSettlement.Tile, destinationTile, null); - rwsComp.RimWarPoints = rwsComp.RimWarPoints - WorldUtility.RelativePowerCostAdjustment(pts, rwd); + // This costs around 150-200ms for this adjustment + //rwsComp.RimWarPoints -= WorldUtility.RelativePowerCostAdjustment(pts, rwd); } } @@ -2066,7 +2080,8 @@ public void AttemptSettler_UnThreaded(RimWarData rwd, RimWorld.Planet.Settlement { int pts = Mathf.RoundToInt(Rand.Range(.4f, .6f) * 500); WorldUtility.CreateSettler(pts, rwd, parentSettlement, parentSettlement.Tile, destinationTile, null); - rwsComp.RimWarPoints = rwsComp.RimWarPoints - WorldUtility.RelativePowerCostAdjustment(pts, rwd); + // This costs around 150-200ms for this adjustment + //rwsComp.RimWarPoints -= WorldUtility.RelativePowerCostAdjustment(pts, rwd); } } @@ -2180,7 +2195,8 @@ public void AttemptTradeMissionOnMainThread(RimWarData rwd, RimWorld.Planet.Sett if (maxPts >= pts || ignoreRestrictions) { Trader tdr = WorldUtility.CreateTrader(pts, rwd, parentSettlement, parentSettlement.Tile, targetTown, WorldObjectDefOf.Settlement); - rwsComp.RimWarPoints = rwsComp.RimWarPoints - WorldUtility.RelativePowerCostAdjustment(pts, rwd); + // This costs around 150-200ms for this adjustment + //rwsComp.RimWarPoints -= WorldUtility.RelativePowerCostAdjustment(pts, rwd); if (targetTown.Faction == Faction.OfPlayer) { rwsComp.PlayerHeat = 0; @@ -2254,7 +2270,8 @@ public void AttemptTradeMission_UnThreaded(RimWarData rwd, RimWorld.Planet.Settl if (maxPts >= pts || ignoreRestrictions) { Trader tdr = WorldUtility.CreateTrader(pts, rwd, parentSettlement, parentSettlement.Tile, targetTown, WorldObjectDefOf.Settlement); - rwsComp.RimWarPoints = rwsComp.RimWarPoints - WorldUtility.RelativePowerCostAdjustment(pts, rwd); + // This costs around 150-200ms for this adjustment + //rwsComp.RimWarPoints -= WorldUtility.RelativePowerCostAdjustment(pts, rwd); if (targetTown.Faction == Faction.OfPlayer) { rwsComp.PlayerHeat = 0; @@ -2374,7 +2391,8 @@ private void AttemptDiplomatMissionOnMainThread(RimWarData rwd, RimWorld.Planet. { //Log.Message("sending warband from " + rwsComp.RimWorld_Settlement.Name); WorldUtility.CreateDiplomat(pts, rwd, parentSettlement, parentSettlement.Tile, targetTown, WorldObjectDefOf.Settlement); - rwsComp.RimWarPoints = rwsComp.RimWarPoints - WorldUtility.RelativePowerCostAdjustment(pts, rwd); + // This costs around 150-200ms for this adjustment + //rwsComp.RimWarPoints -= WorldUtility.RelativePowerCostAdjustment(pts, rwd); if (targetTown.Faction == Faction.OfPlayer) { rwsComp.PlayerHeat = 0; @@ -2424,7 +2442,8 @@ public void AttemptDiplomatMission_UnThreaded(RimWarData rwd, RimWorld.Planet.Se { //Log.Message("sending warband from " + rwsComp.RimWorld_Settlement.Name); WorldUtility.CreateDiplomat(pts, rwd, parentSettlement, parentSettlement.Tile, targetTown, WorldObjectDefOf.Settlement); - rwsComp.RimWarPoints = rwsComp.RimWarPoints - WorldUtility.RelativePowerCostAdjustment(pts, rwd); + // This costs around 150-200ms for this adjustment + //rwsComp.RimWarPoints -= WorldUtility.RelativePowerCostAdjustment(pts, rwd); if (targetTown.Faction == Faction.OfPlayer) { rwsComp.PlayerHeat = 0; @@ -2503,7 +2522,8 @@ public void AttemptReinforcement(RimWarData rwd, RimWorld.Planet.Settlement pare { int pts = Mathf.RoundToInt(.4f * rwsComp.RimWarPoints); Trader tdr = WorldUtility.CreateTrader(pts, rwd, parentSettlement, parentSettlement.Tile, targetTown, WorldObjectDefOf.Settlement); - rwsComp.RimWarPoints = rwsComp.RimWarPoints - WorldUtility.RelativePowerCostAdjustment(pts, rwd); + // This costs around 150-200ms for this adjustment + //rwsComp.RimWarPoints -= WorldUtility.RelativePowerCostAdjustment(pts, rwd); rwsComp.bonusGrowthCount += Mathf.RoundToInt((float)pts / 10f); } } diff --git a/Source/RimWar/Planet/WorldUtility.cs b/Source/RimWar/Planet/WorldUtility.cs index 6e21114..0557d36 100644 --- a/Source/RimWar/Planet/WorldUtility.cs +++ b/Source/RimWar/Planet/WorldUtility.cs @@ -8,6 +8,7 @@ using Verse; using UnityEngine; using HarmonyLib; +using Verse.Noise; namespace RimWar.Planet { @@ -18,6 +19,10 @@ public class WorldUtility private static List tmpPawns = new List(); private static WorldComponent_PowerTracker wcpt = null; + + // Do not scan literally everything, put some arbitrary limit + private const int maxObjectsPerScan = 20; + public static WorldComponent_PowerTracker Get_WCPT() { if (wcpt == null) @@ -1374,7 +1379,6 @@ public static List GetRimWarObjectsAt(PlanetTile tile) public static List GetWorldObjectsInRange(PlanetTile from, float range) { - List tmpObjects = null; //List tmpObjects = Find.WorldObjects.AllWorldObjects; if (WorldObjectsHolder == null) @@ -1399,6 +1403,10 @@ public static List GetWorldObjectsInRange(PlanetTile from, float ra for (int i = 0; i < worldObjects.Count; i++) { PlanetTile to = worldObjects[i].Tile; + + if (objectsInRange.Count >= maxObjectsPerScan) + break; + if (from == to) { objectsInRange.Add(worldObjects[i]); diff --git a/Source/RimWar/RimWar.csproj b/Source/RimWar/RimWar.csproj index 50fceae..7461693 100644 --- a/Source/RimWar/RimWar.csproj +++ b/Source/RimWar/RimWar.csproj @@ -48,11 +48,11 @@ False - ..\..\..\..\..\..\workshop\content\294100\818773962\v1.5\Assemblies\HugsLib.dll + ..\..\..\..\..\..\workshop\content\294100\818773962\v1.6\Assemblies\HugsLib.dll False - ..\..\..\..\..\..\workshop\content\294100\1775170117\1.5\Assemblies\RimCities.dll + ..\..\..\..\..\..\workshop\content\294100\1775170117\1.6\Assemblies\RimCities.dll False diff --git a/Source/RimWar/Utility/IncidentWorker_WarObjectRaid.cs b/Source/RimWar/Utility/IncidentWorker_WarObjectRaid.cs index 8287069..a0bb568 100644 --- a/Source/RimWar/Utility/IncidentWorker_WarObjectRaid.cs +++ b/Source/RimWar/Utility/IncidentWorker_WarObjectRaid.cs @@ -64,7 +64,7 @@ protected override bool TryExecuteWorker(IncidentParms parms) List list = parms.raidStrategy.Worker.SpawnThreats(parms); if (list == null) { - list = PawnGroupMakerUtility.GeneratePawns(IncidentParmsUtility.GetDefaultPawnGroupMakerParms(combat, parms)).ToList(); + list = PawnGroupMakerUtility.GeneratePawns(IncidentParmsUtility.GetDefaultPawnGroupMakerParms(combat, parms, true)).ToList(); if (list.Count == 0) { Log.Error("Got no pawns spawning raid from parms " + parms); diff --git a/Source/RimWar/obj/Debug/.NETFramework,Version=v4.7.2.AssemblyAttributes.cs b/Source/RimWar/obj/Debug/.NETFramework,Version=v4.7.2.AssemblyAttributes.cs deleted file mode 100644 index 3871b18..0000000 --- a/Source/RimWar/obj/Debug/.NETFramework,Version=v4.7.2.AssemblyAttributes.cs +++ /dev/null @@ -1,4 +0,0 @@ -// -using System; -using System.Reflection; -[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] diff --git a/Source/RimWar/obj/Debug/CoreCompileInputs.cache b/Source/RimWar/obj/Debug/CoreCompileInputs.cache deleted file mode 100644 index 71f9d51..0000000 --- a/Source/RimWar/obj/Debug/CoreCompileInputs.cache +++ /dev/null @@ -1 +0,0 @@ -b44666eeadc09eacd2995d582e305fd3c5cb7cae diff --git a/Source/RimWar/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache b/Source/RimWar/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache deleted file mode 100644 index cca6bfa..0000000 Binary files a/Source/RimWar/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache and /dev/null differ diff --git a/Source/RimWar/obj/Debug/RimWar.csproj.CopyComplete b/Source/RimWar/obj/Debug/RimWar.csproj.CopyComplete deleted file mode 100644 index e69de29..0000000 diff --git a/Source/RimWar/obj/Debug/RimWar.csproj.CoreCompileInputs.cache b/Source/RimWar/obj/Debug/RimWar.csproj.CoreCompileInputs.cache deleted file mode 100644 index 18dd465..0000000 --- a/Source/RimWar/obj/Debug/RimWar.csproj.CoreCompileInputs.cache +++ /dev/null @@ -1 +0,0 @@ -7aced023c5d48501864e60fa3f7d19d21b27e226 diff --git a/Source/RimWar/obj/Debug/RimWar.csproj.FileListAbsolute.txt b/Source/RimWar/obj/Debug/RimWar.csproj.FileListAbsolute.txt deleted file mode 100644 index bb35773..0000000 --- a/Source/RimWar/obj/Debug/RimWar.csproj.FileListAbsolute.txt +++ /dev/null @@ -1,28 +0,0 @@ -E:/Programs/Steam/steamapps/common/RimWorld/Mods/RimWar/Assemblies/RimWar.dll -E:/Programs/Steam/steamapps/common/RimWorld/Mods/RimWar/Source/RimWar/obj/Debug/RimWar.dll -C:/Program Files (x86)/Steam/steamapps/common/RimWorld/Mods/RimWar/Source/RimWar/obj/Debug/RimWar.csproj.CoreCompileInputs.cache -C:/Program Files (x86)/Steam/steamapps/common/RimWorld/Mods/RimWar/Source/RimWar/obj/Debug/RimWar.dll -C:/Program Files (x86)/Steam/steamapps/common/RimWorld/Mods/RimWar/Assemblies/RimWar.dll -C:/Program Files (x86)/Steam/steamapps/common/RimWorld/Mods/RimWar/Source/RimWar/obj/Debug/RimWar.csproj.CopyComplete -C:/Program Files (x86)/Steam/steamapps/common/RimWorld/Mods/RimWar/Source/RimWar/obj/Debug/RimWar.csprojAssemblyReference.cache -E:/Programs/Steam/steamapps/common/RimWorld/Mods/RimWar/Source/RimWar/obj/Debug/RimWar.csproj.CoreCompileInputs.cache -E:/Programs/Steam/steamapps/common/RimWorld/Mods/RimWar/Source/RimWar/obj/Debug/RimWar.csprojAssemblyReference.cache -/Users/karimbatbouta/Library/Application Support/Steam/steamapps/common/RimWorld/RimWorldMac.app/Mods/RimWar/Assemblies/RimWar.dll -/Users/karimbatbouta/Library/Application Support/Steam/steamapps/common/RimWorld/RimWorldMac.app/Mods/RimWar/Source/RimWar/obj/Debug/RimWar.csproj.CoreCompileInputs.cache -/Users/karimbatbouta/Library/Application Support/Steam/steamapps/common/RimWorld/RimWorldMac.app/Mods/RimWar/Source/RimWar/obj/Debug/RimWar.dll -E:\Programs\Steam\steamapps\common\RimWorld\Mods\RimWar - Threaded\Source\RimWar\obj\Debug\RimWar.csprojAssemblyReference.cache -E:\Programs\Steam\steamapps\common\RimWorld\Mods\RimWar - Threaded\Source\RimWar\obj\Debug\RimWar.csproj.CoreCompileInputs.cache -E:\Programs\Steam\steamapps\common\RimWorld\Mods\RimWar - Threaded\Source\RimWar\obj\Debug\RimWar.dll -E:\Programs\Steam\steamapps\common\RimWorld\Mods\RimWar - Threaded\Assemblies\RimWar.dll -E:\Programs\Steam\steamapps\common\RimWorld\Mods\RimWar---Threaded\Assemblies\RimWar.dll -E:\Programs\Steam\steamapps\common\RimWorld\Mods\RimWar---Threaded\Source\RimWar\obj\Debug\RimWar.csproj.CoreCompileInputs.cache -E:\Programs\Steam\steamapps\common\RimWorld\Mods\RimWar---Threaded\Source\RimWar\obj\Debug\RimWar.dll -C:\Program Files (x86)\Steam\steamapps\common\RimWorld\Mods\RimWar---Threaded\Source\RimWar\obj\Debug\RimWar.csproj.CoreCompileInputs.cache -C:\Program Files (x86)\Steam\steamapps\common\RimWorld\Mods\RimWar---Threaded\Source\RimWar\obj\Debug\RimWar.dll -C:\Program Files (x86)\Steam\steamapps\common\RimWorld\Mods\RimWar---Threaded\v1.3\Assemblies\RimWar.dll -C:\Program Files (x86)\Steam\steamapps\common\RimWorld\Mods\RimWar---Threaded\Source\RimWar\obj\Debug\RimWar.csprojAssemblyReference.cache -E:\Programs\Steam\steamapps\common\RimWorld\Mods\RimWar---Threaded\v1.3\Assemblies\RimWar.dll -E:\Programs\Steam\steamapps\common\RimWorld\Mods\RimWar---Threaded\v1.4\Assemblies\RimWar.dll -E:\Programs\Steam\steamapps\common\RimWorld\Mods\RimWar---Threaded\v1.5\Assemblies\RimWar.dll -E:\Programs\Steam\steamapps\common\RimWorld\Mods\RimWar---Threaded\v1.6\Assemblies\RimWar.dll -E:\Programs\Steam\steamapps\common\RimWorld\Mods\RimWar---Threaded\Source\RimWar\obj\Debug\RimWar.csprojAssemblyReference.cache diff --git a/Source/RimWar/obj/Debug/RimWar.csprojAssemblyReference.cache b/Source/RimWar/obj/Debug/RimWar.csprojAssemblyReference.cache deleted file mode 100644 index 9baf91b..0000000 Binary files a/Source/RimWar/obj/Debug/RimWar.csprojAssemblyReference.cache and /dev/null differ diff --git a/Source/RimWar/obj/Debug/RimWar.dll b/Source/RimWar/obj/Debug/RimWar.dll deleted file mode 100644 index b8060fe..0000000 Binary files a/Source/RimWar/obj/Debug/RimWar.dll and /dev/null differ diff --git a/Source/RimWar/obj/Debug/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs b/Source/RimWar/obj/Debug/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs deleted file mode 100644 index e69de29..0000000 diff --git a/Source/RimWar/obj/Debug/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs b/Source/RimWar/obj/Debug/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs deleted file mode 100644 index e69de29..0000000 diff --git a/Source/RimWar/obj/Debug/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs b/Source/RimWar/obj/Debug/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs deleted file mode 100644 index e69de29..0000000