From 2742e295a32579e4ff6c6ce617b0b242114d224c Mon Sep 17 00:00:00 2001 From: "MIDDLEEAST\\evmitran" Date: Thu, 4 Aug 2022 08:41:26 -0700 Subject: [PATCH] Performance optimizations --- .../CompRemotelyControlledTurret.cs | 6 +-- .../Components/CompSkyCloudCore.cs | 10 ++--- .../Components/CompSurrogateOwner.cs | 21 ++++++----- .../Designator_AndroidToControl.cs | 6 ++- .../Designators/Designator_SurrogateToHack.cs | 3 +- .../Dialogs/Dialog_SkillUp.cs | 8 ++-- .../Harmony/Corpse_Patch.cs | 2 +- .../Harmony/PawnGenerator_Patch.cs | 2 +- .../Harmony/PawnGroupMakerUtility_Patch.cs | 5 ++- .../Harmony/TaleRecorder_Patch.cs | 2 +- .../Incidents/Incident_DeviceHacking.cs | 17 +++++---- .../Incidents/Incident_RansomWare.cs | 4 +- Source/Androids For RW1.3/Utils/CPatchs.cs | 8 ++-- Source/Androids For RW1.3/Utils/GC_ATPP.cs | 37 +++++++++---------- Source/Androids For RW1.3/Utils/Tex.cs | 4 +- Source/Androids For RW1.3/Utils/Utils.cs | 19 +++++----- 16 files changed, 77 insertions(+), 77 deletions(-) diff --git a/Source/Androids For RW1.3/Components/CompRemotelyControlledTurret.cs b/Source/Androids For RW1.3/Components/CompRemotelyControlledTurret.cs index ef3ec52..adfc157 100644 --- a/Source/Androids For RW1.3/Components/CompRemotelyControlledTurret.cs +++ b/Source/Androids For RW1.3/Components/CompRemotelyControlledTurret.cs @@ -142,12 +142,12 @@ public override IEnumerable CompGetGizmosExtra() public override string CompInspectStringExtra() { - string ret = ""; + var ret = new StringBuilder(); if(controller != null) - ret += "ATPP_RemotelyControlledBy".Translate(controller.LabelShortCap) + "\n"; + ret.AppendLine("ATPP_RemotelyControlledBy".Translate(controller.LabelShortCap)); - return ret.TrimEnd('\r', '\n') + base.CompInspectStringExtra(); + return ret.TrimEnd().Append(base.CompInspectStringExtra()).ToString(); } public override void PostDeSpawn(Map map) diff --git a/Source/Androids For RW1.3/Components/CompSkyCloudCore.cs b/Source/Androids For RW1.3/Components/CompSkyCloudCore.cs index a708ed7..fd2313a 100644 --- a/Source/Androids For RW1.3/Components/CompSkyCloudCore.cs +++ b/Source/Androids For RW1.3/Components/CompSkyCloudCore.cs @@ -323,7 +323,7 @@ public bool isOnline() public override IEnumerable CompGetGizmosExtra() { //If no minds stored - if (storedMinds.Count() == 0 || !isOnline() || !Booted()) + if (storedMinds.Count == 0 || !isOnline() || !Booted()) { yield break; } @@ -606,7 +606,7 @@ public override IEnumerable CompGetGizmosExtra() }; } - if (getNbMindsConnectedToSurrogate() != 0 || controlledTurrets.Count() != 0) + if (getNbMindsConnectedToSurrogate() != 0 || controlledTurrets.Count != 0) { yield return new Command_Action { @@ -956,7 +956,7 @@ public string getName() public float getPowerConsumed() { CompPowerTrader cpt = Utils.getCachedCPT((Building)this.parent); - return (storedMinds.Count()*Settings.powerConsumedByStoredMind) + cpt.Props.basePowerConsumption; + return (storedMinds.Count*Settings.powerConsumedByStoredMind) + cpt.Props.basePowerConsumption; } @@ -1026,10 +1026,8 @@ public void stopRemotelyControlledTurret(Pawn mind) private void disconnectAllRemotelyControlledTurrets() { - List> list = controlledTurrets.FastToList(); - for (int i = 0; i < list.Count; i++) + foreach(var e in controlledTurrets) { - KeyValuePair e = list[i]; stopRemotelyControlledTurret(e.Key); } } diff --git a/Source/Androids For RW1.3/Components/CompSurrogateOwner.cs b/Source/Androids For RW1.3/Components/CompSurrogateOwner.cs index a5c3335..c02b055 100644 --- a/Source/Androids For RW1.3/Components/CompSurrogateOwner.cs +++ b/Source/Androids For RW1.3/Components/CompSurrogateOwner.cs @@ -306,7 +306,7 @@ public override void CompTick() { sum += sr.levelInt; } - average = (int)((float)sum / (float)currentPawn.skills.skills.Count()); + average = (int)((float)sum / (float)currentPawn.skills.skills.Count); int nbp = (int)((float)((float)average / (float)20) * Rand.Range(1000, 5000)); @@ -958,7 +958,7 @@ public void disconnectControlledSurrogate(Pawn surrogate, bool externalControlle public override string CompInspectStringExtra() { - string ret = ""; + var ret = new StringBuilder(); try { if (parent.Map == null) @@ -977,7 +977,7 @@ public override string CompInspectStringExtra() { p = p = Math.Min(1.0f, (float)(Find.TickManager.TicksGame - permuteStartGT) / (float)(permuteEndingGT - permuteStartGT)); } - ret += "ATPP_PermutationPercentage".Translate(((int)(p * (float)100)).ToString()) + "\n"; + ret.AppendLine("ATPP_PermutationPercentage".Translate(((int)(p * (float)100)).ToString())); } @@ -994,7 +994,7 @@ public override string CompInspectStringExtra() { p = p = Math.Min(1.0f, (float)(Find.TickManager.TicksGame - duplicateStartGT) / (float)(duplicateEndingGT - duplicateStartGT)); } - ret += "ATPP_DuplicationPercentage".Translate(((int)(p * (float)100)).ToString()) + "\n"; + ret.AppendLine("ATPP_DuplicationPercentage".Translate(((int)(p * (float)100)).ToString())); } if (uploadToSkyCloudEndingGT != -1) @@ -1003,7 +1003,7 @@ public override string CompInspectStringExtra() float p; p = p = Math.Min(1.0f, (float)(Find.TickManager.TicksGame - uploadToSkyCloudStartGT) / (float)(uploadToSkyCloudEndingGT - uploadToSkyCloudStartGT)); - ret += "ATPP_UploadSkyCloudPercentage".Translate(((int)(p * (float)100)).ToString()) + "\n"; + ret.AppendLine("ATPP_UploadSkyCloudPercentage".Translate(((int)(p * (float)100)).ToString())); } if (downloadFromSkyCloudEndingGT != -1) @@ -1012,7 +1012,7 @@ public override string CompInspectStringExtra() float p; p = p = Math.Min(1.0f, (float)(Find.TickManager.TicksGame - downloadFromSkyCloudStartGT) / (float)(downloadFromSkyCloudEndingGT - downloadFromSkyCloudStartGT)); - ret += "ATPP_DownloadFromSkyCloudPercentage".Translate(((int)(p * (float)100)).ToString()) + "\n"; + ret.AppendLine("ATPP_DownloadFromSkyCloudPercentage".Translate(((int)(p * (float)100)).ToString())); } if (mindAbsorptionEndingGT != -1) @@ -1021,7 +1021,7 @@ public override string CompInspectStringExtra() float p; p = p = Math.Min(1.0f, (float)(Find.TickManager.TicksGame - mindAbsorptionStartGT) / (float)(mindAbsorptionEndingGT - mindAbsorptionStartGT)); - ret += "ATPP_MindAbsorptionProgress".Translate(((int)(p * (float)100)).ToString()) + "\n"; + ret.AppendLine("ATPP_MindAbsorptionProgress".Translate(((int)(p * (float)100)).ToString())); } if (controlMode && availableSX.Count > 0) @@ -1039,15 +1039,16 @@ public override string CompInspectStringExtra() } } - ret += "ATPP_RemotelyControl".Translate(lst.TrimEnd(' ', ',')) + "\n"; + ret.AppendLine("ATPP_RemotelyControl".Translate(lst.TrimEnd(' ', ','))); } - return ret.TrimEnd('\r', '\n', ' ') + base.CompInspectStringExtra(); + + return ret.TrimEnd().Append(base.CompInspectStringExtra()).ToString(); } catch(Exception e) { Log.Message("[ATPP] CompSurrogateOwner.CompInspectStringExtra "+e.Message+" "+e.StackTrace); - return ret.TrimEnd('\r', '\n', ' ') + base.CompInspectStringExtra(); + return ret.TrimEnd().Append(base.CompInspectStringExtra()).ToString(); } } diff --git a/Source/Androids For RW1.3/Designators/Designator_AndroidToControl.cs b/Source/Androids For RW1.3/Designators/Designator_AndroidToControl.cs index 5d4804f..07f8bc1 100644 --- a/Source/Androids For RW1.3/Designators/Designator_AndroidToControl.cs +++ b/Source/Androids For RW1.3/Designators/Designator_AndroidToControl.cs @@ -177,7 +177,8 @@ private bool SXInCell(IntVec3 c) List thingList = c.GetThingList(base.Map); for (int i = 0; i < thingList.Count; i++) { - if (thingList[i] is Pawn && this.CanDesignateThing(thingList[i]).Accepted) + Thing thing = thingList[i]; + if (thing is Pawn && this.CanDesignateThing(thing).Accepted) { return true; } @@ -194,7 +195,8 @@ private bool TurretInCell(IntVec3 c) List thingList = c.GetThingList(base.Map); for (int i = 0; i < thingList.Count; i++) { - if (thingList[i] != null && (thingList[i].def.thingClass == typeof(Building_Turret) || thingList[i].def.thingClass.IsSubclassOf(typeof(Building_Turret)) ) && this.CanDesignateThing(thingList[i]).Accepted) + Thing thing = thingList[i]; + if (thing != null && (thing.def.thingClass == typeof(Building_Turret) || thing.def.thingClass.IsSubclassOf(typeof(Building_Turret)) ) && this.CanDesignateThing(thing).Accepted) { return true; } diff --git a/Source/Androids For RW1.3/Designators/Designator_SurrogateToHack.cs b/Source/Androids For RW1.3/Designators/Designator_SurrogateToHack.cs index 9e5d2ee..9ccae29 100644 --- a/Source/Androids For RW1.3/Designators/Designator_SurrogateToHack.cs +++ b/Source/Androids For RW1.3/Designators/Designator_SurrogateToHack.cs @@ -293,7 +293,8 @@ private bool SXInCell(IntVec3 c) List thingList = c.GetThingList(base.Map); for (int i = 0; i < thingList.Count; i++) { - if (thingList[i] is Pawn && this.CanDesignateThing(thingList[i]).Accepted) + Thing thing = thingList[i]; + if (thing is Pawn && this.CanDesignateThing(thing).Accepted) { return true; } diff --git a/Source/Androids For RW1.3/Dialogs/Dialog_SkillUp.cs b/Source/Androids For RW1.3/Dialogs/Dialog_SkillUp.cs index 0fbe2cf..fbcdd90 100644 --- a/Source/Androids For RW1.3/Dialogs/Dialog_SkillUp.cs +++ b/Source/Androids For RW1.3/Dialogs/Dialog_SkillUp.cs @@ -8,9 +8,10 @@ namespace MOARANDROIDS { public class Dialog_SkillUp : Window { + private static List libs = new List { "Shooting".Translate(), "Melee".Translate(), "Construction".Translate(), "Mining".Translate(), "Cooking".Translate(), "Plants".Translate(), "Animals".Translate(), "Crafting".Translate(), "Artistic".Translate(), "Medicine".Translate(), "Social".Translate(), "Intellectual".Translate() }; + private static List sd = new List { SkillDefOf.Shooting, SkillDefOf.Melee, SkillDefOf.Construction, SkillDefOf.Mining, SkillDefOf.Cooking, SkillDefOf.Plants, SkillDefOf.Animals, SkillDefOf.Crafting, SkillDefOf.Artistic, SkillDefOf.Medicine, SkillDefOf.Social, SkillDefOf.Intellectual }; + Pawn android; - List libs; - List sd; List points; List passionsState; @@ -42,9 +43,6 @@ public Dialog_SkillUp(Pawn android, bool isMind=false) points = new List { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; passionsState = new List { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - libs = new List { "Shooting".Translate(), "Melee".Translate(), "Construction".Translate(), "Mining".Translate(), "Cooking".Translate(), "Plants".Translate(), "Animals".Translate(), "Crafting".Translate(), "Artistic".Translate(), "Medicine".Translate(), "Social".Translate(), "Intellectual".Translate()}; - sd = new List { SkillDefOf.Shooting, SkillDefOf.Melee, SkillDefOf.Construction, SkillDefOf.Mining, SkillDefOf.Cooking, SkillDefOf.Plants, SkillDefOf.Animals, SkillDefOf.Crafting, SkillDefOf.Artistic, SkillDefOf.Medicine, SkillDefOf.Social, SkillDefOf.Intellectual }; - int i = 0; foreach(var csd in sd) { diff --git a/Source/Androids For RW1.3/Harmony/Corpse_Patch.cs b/Source/Androids For RW1.3/Harmony/Corpse_Patch.cs index 9f20d8e..70b559d 100644 --- a/Source/Androids For RW1.3/Harmony/Corpse_Patch.cs +++ b/Source/Androids For RW1.3/Harmony/Corpse_Patch.cs @@ -29,7 +29,7 @@ public static void Listener(Pawn butcher, float efficiency, Corpse __instance, r if (cas.isSurrogate) { List res = new List(); - foreach(var r in __result.ToList()) + foreach(var r in __result) { if (r.def != null && r.def.defName != "AIPersonaCore") res.Add(r); diff --git a/Source/Androids For RW1.3/Harmony/PawnGenerator_Patch.cs b/Source/Androids For RW1.3/Harmony/PawnGenerator_Patch.cs index b63b38a..33b0b1d 100644 --- a/Source/Androids For RW1.3/Harmony/PawnGenerator_Patch.cs +++ b/Source/Androids For RW1.3/Harmony/PawnGenerator_Patch.cs @@ -82,7 +82,7 @@ public static void Listener(PawnGenerationRequest request, ref Pawn __result) if (Utils.RIMMSQOL_LOADED && Utils.lastResolveAllGraphicsHeadGraphicPath != null) { - __result.story.GetType().GetField("headGraphicPath", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(__result.story, Utils.lastResolveAllGraphicsHeadGraphicPath); + Traverse.Create(__result.story).Field("headGraphicPath").SetValue(Utils.lastResolveAllGraphicsHeadGraphicPath); Utils.lastResolveAllGraphicsHeadGraphicPath = null; } } diff --git a/Source/Androids For RW1.3/Harmony/PawnGroupMakerUtility_Patch.cs b/Source/Androids For RW1.3/Harmony/PawnGroupMakerUtility_Patch.cs index 2128c70..d30d26e 100644 --- a/Source/Androids For RW1.3/Harmony/PawnGroupMakerUtility_Patch.cs +++ b/Source/Androids For RW1.3/Harmony/PawnGroupMakerUtility_Patch.cs @@ -84,7 +84,7 @@ public static void Listener(PawnGroupMakerParms parms, bool warnOnZeroResults, r tmp.Remove(p); } - List tmpList = tmp.FastToList(); + IEnumerator tmpList = tmp.GetEnumerator(); //On va se servir des nb pawn pregénéré par la fonction patché comme controller for (int i = 0; i != nb; i++) @@ -93,7 +93,8 @@ public static void Listener(PawnGroupMakerParms parms, bool warnOnZeroResults, r //Pawn surrogate = PawnGenerator.GeneratePawn(request); PawnKindDef rpkd = null; - var tmpListElem = tmpList[i]; + tmpList.MoveNext(); + var tmpListElem = tmpList.Current; if (parms.groupKind == PawnGroupKindDefOf.Peaceful || parms.groupKind == PawnGroupKindDefOf.Trader) { diff --git a/Source/Androids For RW1.3/Harmony/TaleRecorder_Patch.cs b/Source/Androids For RW1.3/Harmony/TaleRecorder_Patch.cs index 5a798e4..9c7045a 100644 --- a/Source/Androids For RW1.3/Harmony/TaleRecorder_Patch.cs +++ b/Source/Androids For RW1.3/Harmony/TaleRecorder_Patch.cs @@ -20,7 +20,7 @@ public static bool Listener(TaleDef def, params object[] args) { Pawn p1 = null; Pawn p2 = null; - int nba = args.Count(); + int nba = args.Length; if (nba >= 2) { diff --git a/Source/Androids For RW1.3/Incidents/Incident_DeviceHacking.cs b/Source/Androids For RW1.3/Incidents/Incident_DeviceHacking.cs index d3fb0d9..a3bdb2a 100644 --- a/Source/Androids For RW1.3/Incidents/Incident_DeviceHacking.cs +++ b/Source/Androids For RW1.3/Incidents/Incident_DeviceHacking.cs @@ -8,6 +8,7 @@ using RimWorld.Planet; using UnityEngine; using Verse.Sound; +using System.Text; namespace MOARANDROIDS { @@ -24,9 +25,9 @@ protected override bool TryExecuteWorker(IncidentParms parms) if (Settings.disableSkyMindSecurityStuff) return false; - List victims; + HashSet victims; string title = ""; - string msg = ""; + var msg = new StringBuilder(); int nbConnectedClients = Utils.GCATPP.getNbThingsConnected(); HashSet cryptolockedThings = new HashSet(); int nbDevices = Utils.GCATPP.getNbDevices(); @@ -84,7 +85,7 @@ protected override bool TryExecuteWorker(IncidentParms parms) title = "ATPP_IncidentDeviceHackingVirus".Translate(); - msg = "ATPP_IncidentDeviceHackingLiteDesc".Translate(nb); + msg.Append("ATPP_IncidentDeviceHackingLiteDesc".Translate(nb)); victims = Utils.GCATPP.getRandomDevices(nb); if (victims.Count != nb) @@ -120,21 +121,21 @@ protected override bool TryExecuteWorker(IncidentParms parms) else nb = 1; - msg = "ATPP_IncidentDeviceHackingHardDesc".Translate(nb) + "\n"; + msg.AppendLine("ATPP_IncidentDeviceHackingHardDesc".Translate(nb)); switch (attackType) { case 1: title = "ATPP_IncidentDeviceHackingVirus".Translate(); - msg += "ATPP_IncidentDeviceVirusedDesc".Translate(); + msg.Append("ATPP_IncidentDeviceVirusedDesc".Translate()); break; case 2: title = "ATPP_IncidentDeviceHackingExplosiveVirus".Translate(); - msg += "ATPP_IncidentDeviceVirusedExplosiveDesc".Translate(); + msg.Append("ATPP_IncidentDeviceVirusedExplosiveDesc".Translate()); break; case 3: title = "ATPP_IncidentDeviceHackingCryptolocker".Translate(); - msg += "ATPP_IncidentDeviceCryptolockerDesc".Translate(); + msg.Append("ATPP_IncidentDeviceCryptolockerDesc".Translate()); break; } @@ -160,7 +161,7 @@ protected override bool TryExecuteWorker(IncidentParms parms) } } - Find.LetterStack.ReceiveLetter(title, msg, letter, (LookTargets) victims, null, null); + Find.LetterStack.ReceiveLetter(title, msg.ToString(), letter, new LookTargets(victims), null, null); if (attackType == 3) diff --git a/Source/Androids For RW1.3/Incidents/Incident_RansomWare.cs b/Source/Androids For RW1.3/Incidents/Incident_RansomWare.cs index 1cc9df9..bdc77a6 100644 --- a/Source/Androids For RW1.3/Incidents/Incident_RansomWare.cs +++ b/Source/Androids For RW1.3/Incidents/Incident_RansomWare.cs @@ -54,9 +54,9 @@ protected override bool TryExecuteWorker(IncidentParms parms) { List tr; if (victim.IsAndroid()) - tr = Utils.RansomAddedBadTraitsAndroid.ToList(); + tr = Utils.RansomAddedBadTraitsAndroid.FastToList(); else - tr = Utils.RansomAddedBadTraits.ToList(); + tr = Utils.RansomAddedBadTraits.FastToList(); //Purge des traits deja possédé par la victime ET incompatibles avec ceux present diff --git a/Source/Androids For RW1.3/Utils/CPatchs.cs b/Source/Androids For RW1.3/Utils/CPatchs.cs index 84e0fb4..17692c6 100644 --- a/Source/Androids For RW1.3/Utils/CPatchs.cs +++ b/Source/Androids For RW1.3/Utils/CPatchs.cs @@ -93,8 +93,8 @@ public static void PowerPP_CompLocalWirelessPowerEmitter_CompInspectStringExtra( Building build = (Building)__instance.parent; int nbConn = 0; - if (Utils.GCATPP.listerLWPNAndroid.ContainsKey(build)) - nbConn = Utils.GCATPP.listerLWPNAndroid[build].Count(); + if (Utils.GCATPP.listerLWPNAndroid.TryGetValue(build, out var list)) + nbConn = list.Count; if (__instance.parent.def.defName == "ARKPPP_LocalWirelessPortablePowerEmitter") { @@ -366,14 +366,14 @@ public static void QEE_Building_GrowerBase_get_CraftingProgressPercentPostfix(Bu string BUID = __instance.GetUniqueLoadID(); //Si plus de refgerence au pawnBeingGrown (suite a un rechargement) on essait de reresoudre ce dernier - if (Utils.GCATPP.VatGrowerLastPawnIsTX.ContainsKey(BUID) && Utils.GCATPP.VatGrowerLastPawnIsTX[BUID] && !Utils.GCATPP.VatGrowerLastPawnInProgress.ContainsKey(BUID)) + if (Utils.GCATPP.VatGrowerLastPawnIsTX.TryGetValue(BUID, out bool vatGrowerLastPawnIsTX) && vatGrowerLastPawnIsTX && !Utils.GCATPP.VatGrowerLastPawnInProgress.ContainsKey(BUID)) { Utils.GCATPP.VatGrowerLastPawnInProgress[BUID] = (Pawn)Traverse.Create(__instance).Field("pawnBeingGrown").GetValue(); } //Si le GS chargé dans le VAT est un exosquelette d'androide TX alors pas de reduction - if (Utils.GCATPP.VatGrowerLastPawnInProgress.ContainsKey(BUID) && Utils.GCATPP.VatGrowerLastPawnInProgress[BUID] != null) + if (Utils.GCATPP.VatGrowerLastPawnInProgress.TryGetValue(BUID, out Pawn vatGrowerLastPawnInProgress) && vatGrowerLastPawnInProgress != null) { CompAndroidState cas = Utils.getCachedCAS(Utils.GCATPP.VatGrowerLastPawnInProgress[BUID]); if (cas != null) diff --git a/Source/Androids For RW1.3/Utils/GC_ATPP.cs b/Source/Androids For RW1.3/Utils/GC_ATPP.cs index 8fde0dc..338c58a 100644 --- a/Source/Androids For RW1.3/Utils/GC_ATPP.cs +++ b/Source/Androids For RW1.3/Utils/GC_ATPP.cs @@ -833,7 +833,7 @@ private void removeBlacklistedAndroidsHediffs() toDel.Add(he); } - if(toDel.Count() > 0) + if(toDel.Count > 0) { foreach(var h in toDel) { @@ -1218,9 +1218,9 @@ public void checkSkyMindAutoReconnect() */ public void checkNeedRandomlyDisconnectUsers() { - if(nbSlot < connectedThing.Count()) + if(nbSlot < connectedThing.Count) { - while(nbSlot < connectedThing.Count()) + while(nbSlot < connectedThing.Count) { Thing c = connectedThing.RandomElement(); disconnectUser(c); @@ -1394,12 +1394,12 @@ public int getNbSlotAvailable() public int getNbThingsConnected() { - return connectedThing.Count(); + return connectedThing.Count; } public int getNbSkyMindUsers() { - return listerSkyMindUsers.Count(); + return listerSkyMindUsers.Count; } public int getNbSurrogateAndroids() @@ -1407,7 +1407,7 @@ public int getNbSurrogateAndroids() int ret = 0; foreach(var el in listerSurrogateAndroids) { - ret+= el.Value.Count(); + ret+= el.Value.Count; } return ret; @@ -1492,7 +1492,7 @@ public bool connectUser(Thing thing, bool broadcastEvent=true) } //Nbslot available exceeded ? ==> no Skymind connection - if(connectedThing.Count() >= nbSlot) + if(connectedThing.Count >= nbSlot) { return false; } @@ -1648,14 +1648,13 @@ public HashSet getRandomSurrogateAndroids(int nb, bool withoutVirus = true return ret; } - public List getRandomDevices(int nb, bool withoutVirus = true) + public HashSet getRandomDevices(int nb, bool withoutVirus = true) { - List ret = listerConnectedDevices.ToList(); - List tmp = ret.ToList(); + HashSet ret = listerConnectedDevices.ToHashSet(); if (withoutVirus) { - foreach (var e in tmp) + foreach (var e in listerConnectedDevices) { CompSkyMind csm = Utils.getCachedCSM(e); if (csm != null) @@ -1815,10 +1814,10 @@ public HashSet getReloadStations(Map map) public Building getFreeReloadStation(Map map, Pawn android) { //Log.Message("Nb RS en stock " + listerReloadStation.Count); - if (listerReloadStation.ContainsKey(map)) + if (listerReloadStation.TryGetValue(map, out HashSet buildings)) { //Log.Message("ICI DISPONIBLE !!!!!"); - foreach(var el in listerReloadStation[map].OrderBy((Building b) => b.Position.DistanceToSquared(android.Position))) + foreach(var el in buildings.OrderBy((Building b) => b.Position.DistanceToSquared(android.Position))) { CompPowerTrader cpt = Utils.getCachedCPT(el); if (el == null || el.Destroyed || el.IsBrokenDown() || !cpt.PowerOn || !el.Position.InAllowedArea(android)) @@ -2002,7 +2001,7 @@ public void checkRemoveAndroidFactions() public int getNbDevices() { - return listerConnectedDevices.Count(); + return listerConnectedDevices.Count; } @@ -2055,7 +2054,7 @@ public void pushSkillServer(Building build) public bool isThereSkillServers() { - return listerSkillServers.Count() != 0; + return listerSkillServers.Count != 0; } @@ -2143,12 +2142,12 @@ public HashSet getAvailableSkyCloudCores() public bool isThereSkyCloudCore() { - return (listerSkyCloudCores.Count() > 0); + return (listerSkyCloudCores.Count > 0); } public bool isThereSkyCloudCoreAbs() { - return (listerSkyCloudCoresAbs.Count() > 0); + return (listerSkyCloudCoresAbs.Count > 0); } public void pushRelayTower(Thing build, string MID) @@ -2255,7 +2254,7 @@ public bool pushLWPNAndroid(Building LWPN, Pawn android) int qtConsumed = Utils.getConsumedPowerByAndroid(android.def.defName); if (LWPN != null && !LWPN.Destroyed - && ( LWPN.def.defName == "ARKPPP_LocalWirelessPowerEmitter" || ( LWPN.def.defName == "ARKPPP_LocalWirelessPortablePowerEmitter" && listerLWPNAndroid[LWPN].Count() < Settings.maxAndroidByPortableLWPN )) + && ( LWPN.def.defName == "ARKPPP_LocalWirelessPowerEmitter" || ( LWPN.def.defName == "ARKPPP_LocalWirelessPortablePowerEmitter" && listerLWPNAndroid[LWPN].Count < Settings.maxAndroidByPortableLWPN )) && cpt.PowerOn && Utils.getCurrentAvailableEnergy(LWPN.PowerComp.PowerNet) - qtConsumed > 0) { @@ -2290,7 +2289,7 @@ public int getNbAssistingMinds() CompSkyCloudCore csc = Utils.getCachedCSC(c); //Comptabilisation que si le systeme à bouté if(csc != null && csc.Booted()) - nb +=csc.assistingMinds.Count(); + nb +=csc.assistingMinds.Count; } return nb; diff --git a/Source/Androids For RW1.3/Utils/Tex.cs b/Source/Androids For RW1.3/Utils/Tex.cs index e5cd213..37b3bea 100644 --- a/Source/Androids For RW1.3/Utils/Tex.cs +++ b/Source/Androids For RW1.3/Utils/Tex.cs @@ -125,9 +125,9 @@ public static Graphic getEyeGlowEffect(Color color, string gender, int type, int string path; Graphic res; - if (eyeGlowEffectCache.ContainsKey(key)) + if (eyeGlowEffectCache.TryGetValue(key, out Graphic graphic)) { - res = eyeGlowEffectCache[key]; + res = graphic; } else { diff --git a/Source/Androids For RW1.3/Utils/Utils.cs b/Source/Androids For RW1.3/Utils/Utils.cs index ae63143..a7e8940 100644 --- a/Source/Androids For RW1.3/Utils/Utils.cs +++ b/Source/Androids For RW1.3/Utils/Utils.cs @@ -623,12 +623,12 @@ public static Building_Bed getAvailableAndroidPodForCharging(Pawn android, bool if (!bed.Medical && (android.IsPrisoner == bed.ForPrisoners) - && !(bed.GetCurOccupant(0) != null || (bed.OwnersForReading.Count() != 0 && !bed.OwnersForReading.Contains(android))) + && !(bed.GetCurOccupant(0) != null || (bed.OwnersForReading.Count != 0 && !bed.OwnersForReading.Contains(android))) && cpt.PowerOn && el.Position.InAllowedArea(android) && android.CanReserveAndReach(el, PathEndMode.OnCell, Danger.Deadly, 1, -1, null, false)) { - float cdist = android.Position.DistanceTo(el.Position); + float cdist = android.Position.DistanceToSquared(el.Position); if (dist == -1 || cdist < dist) { @@ -998,7 +998,7 @@ public static void restoreSavedSurrogateName(Pawn surrogate) string[] tmp = cas.savedName.Split('§'); - if (tmp.Count() != 3) + if (tmp.Length != 3) return; surrogate.Name = new NameTriple(tmp[0], tmp[1], tmp[2]); @@ -1013,7 +1013,7 @@ public static string getSavedSurrogateNameNick(Pawn surrogate) string[] tmp = cas.savedName.Split('§'); - if (tmp.Count() != 3) + if (tmp.Length != 3) return ""; return tmp[1]; @@ -2203,7 +2203,7 @@ public static void ClearCachedDisabledWorkTypes(this Pawn pawn) { if (pawn != null) { - typeof(Pawn).GetField("cachedDisabledWorkTypes", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(pawn, null); + pawn.Notify_DisabledWorkTypesChanged(); } } @@ -2211,10 +2211,9 @@ public static void ClearCachedDisabledSkillRecords(this Pawn pawn) { if (pawn.skills != null && pawn.skills.skills != null) { - FieldInfo field = typeof(SkillRecord).GetField("cachedTotallyDisabled", BindingFlags.NonPublic | BindingFlags.Instance); foreach (var record in pawn.skills.skills) { - field.SetValue(record, BoolUnknown.Unknown); + record.Notify_SkillDisablesChanged(); } } } @@ -2607,7 +2606,7 @@ public static Pawn spawnCorpseCopy(Pawn pawn, bool kill=true) if (pawn.equipment != null && p.equipment != null) { - foreach (var e in pawn.equipment.AllEquipmentListForReading.ToList()) + foreach (var e in pawn.equipment.AllEquipmentListForReading.FastToList()) { try { @@ -2627,7 +2626,7 @@ public static Pawn spawnCorpseCopy(Pawn pawn, bool kill=true) p.apparel.DestroyAll(); //Log.Message("--Traitement des vetements"); - foreach (var e in pawn.apparel.WornApparel.ToList()) + foreach (var e in pawn.apparel.WornApparel.FastToList()) { pawn.apparel.Remove(e); p.apparel.Wear(e); @@ -2638,7 +2637,7 @@ public static Pawn spawnCorpseCopy(Pawn pawn, bool kill=true) p.health.hediffSet.Clear(); //Ajout des hediffs - foreach (var h in pawn.health.hediffSet.hediffs.ToList()) + foreach (var h in pawn.health.hediffSet.hediffs.FastToList()) { try {