From 00a23e6c11df1f0020d1f86fb7fdba581bc4be47 Mon Sep 17 00:00:00 2001 From: RoosterDragon Date: Sat, 9 Mar 2024 09:57:12 +0000 Subject: [PATCH] Fetch actors directly in DropPodsPower. Use direct dictionary lookups, rather than iterating the entire actors dictionary. --- .../Traits/SupportPowers/DropPodsPower.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/OpenRA.Mods.Cnc/Traits/SupportPowers/DropPodsPower.cs b/OpenRA.Mods.Cnc/Traits/SupportPowers/DropPodsPower.cs index 645611e2a0..b6e25691d1 100644 --- a/OpenRA.Mods.Cnc/Traits/SupportPowers/DropPodsPower.cs +++ b/OpenRA.Mods.Cnc/Traits/SupportPowers/DropPodsPower.cs @@ -91,18 +91,22 @@ namespace OpenRA.Mods.Cnc.Traits this.info = info; unitTypes = info.UnitTypes.Select(unit => unit.ToLowerInvariant()).ToArray(); - foreach (var actorInfo in self.World.Map.Rules.Actors.Where(a => unitTypes.Contains(a.Key))) + + foreach (var unitType in unitTypes) { - var aircraftInfo = actorInfo.Value.TraitInfo(); + if (!self.World.Map.Rules.Actors.TryGetValue(unitType, out var actorInfo)) + throw new NotImplementedException("No rules definition for unit " + unitType); + + var aircraftInfo = actorInfo.TraitInfo(); var altitude = aircraftInfo.CruiseAltitude.Length; var delta = - new WVec(0, -altitude * aircraftInfo.Speed / actorInfo.Value.TraitInfo().Velocity.Length, 0) + new WVec(0, -altitude * aircraftInfo.Speed / actorInfo.TraitInfo().Velocity.Length, 0) .Rotate(WRot.FromYaw(info.PodFacing)); // PERF: Cache constant values. - getLaunchLocation[actorInfo.Key] = pos => self.World.Map.CenterOfCell(pos) - delta + new WVec(0, 0, altitude); - landableTerrainTypes[actorInfo.Key] = aircraftInfo.LandableTerrainTypes; + getLaunchLocation[unitType] = pos => self.World.Map.CenterOfCell(pos) - delta + new WVec(0, 0, altitude); + landableTerrainTypes[unitType] = aircraftInfo.LandableTerrainTypes; } }