From d4e1b1ba484f077e2fcbc885744adf8260f8d485 Mon Sep 17 00:00:00 2001 From: clemty Date: Thu, 24 Sep 2015 21:03:36 +0200 Subject: [PATCH] reduce use of Map.Topleft and Map.Bottomright as requested in #8549 --- mods/cnc/maps/gdi01/gdi01.lua | 15 ++++++---- mods/cnc/maps/nod02a/nod02a.lua | 23 ++++++--------- mods/cnc/maps/nod02b/nod02b.lua | 23 ++++++--------- mods/cnc/maps/nod05/nod05.lua | 6 ++-- mods/ra/maps/allies-03a/allies03a.lua | 2 +- mods/ra/maps/allies-03a/map.yaml | 40 +++++++++++++-------------- 6 files changed, 49 insertions(+), 60 deletions(-) diff --git a/mods/cnc/maps/gdi01/gdi01.lua b/mods/cnc/maps/gdi01/gdi01.lua index 490e72f695..1855f7489c 100644 --- a/mods/cnc/maps/gdi01/gdi01.lua +++ b/mods/cnc/maps/gdi01/gdi01.lua @@ -2,6 +2,7 @@ MCVReinforcements = { "mcv" } InfantryReinforcements = { "e1", "e1", "e1" } VehicleReinforcements = { "jeep" } NodPatrol = { "e1", "e1" } +GDIBaseBuildings = { "pyle", "fact", "nuke" } SendNodPatrol = function() Reinforcements.Reinforce(enemy, NodPatrol, { nod0.Location, nod1.Location }, 15, function(soldier) @@ -48,12 +49,16 @@ Reinforce = function(units) ReinforceWithLandingCraft(units, lstStart.Location, lstEnd.Location, reinforcementsTarget.Location) end -CheckForBase = function() - baseBuildings = Map.ActorsInBox(Map.TopLeft, Map.BottomRight, function(actor) - return actor.Type == "fact" or actor.Type == "pyle" or actor.Type == "nuke" +CheckForBase = function(player) + local buildings = 0 + + Utils.Do(GDIBaseBuildings, function(name) + if #player.GetActorsByType(name) > 0 then + buildings = buildings + 1 + end end) - return #baseBuildings >= 3 + return buildings == #GDIBaseBuildings end WorldLoaded = function() @@ -102,7 +107,7 @@ Tick = function() player.MarkFailedObjective(secureAreaObjective) end - if DateTime.GameTime % DateTime.Seconds(1) == 0 and not player.IsObjectiveCompleted(beachheadObjective) and CheckForBase() then + if DateTime.GameTime % DateTime.Seconds(1) == 0 and not player.IsObjectiveCompleted(beachheadObjective) and CheckForBase(player) then player.MarkCompletedObjective(beachheadObjective) end end diff --git a/mods/cnc/maps/nod02a/nod02a.lua b/mods/cnc/maps/nod02a/nod02a.lua index 7a22835809..805b647bef 100644 --- a/mods/cnc/maps/nod02a/nod02a.lua +++ b/mods/cnc/maps/nod02a/nod02a.lua @@ -53,23 +53,16 @@ OnAnyDamaged = function(actors, func) end) end -CheckForBase = function(player, buildings) - local checked = { } - local baseBuildings = Map.ActorsInBox(Map.TopLeft, Map.BottomRight, function(actor) - if actor.Owner ~= Nod or Utils.Any(checked, function(bldng) return bldng.Type == actor.Type end) then - return false - end +CheckForBase = function(player) + local buildings = 0 - local found = false - for i = 1, #buildings, 1 do - if actor.Type == buildings[i] then - found = true - checked[#checked + 1] = actor - end + Utils.Do(NodBaseBuildings, function(name) + if #player.GetActorsByType(name) > 0 then + buildings = buildings + 1 end - return found end) - return #baseBuildings >= 3 + + return buildings == #NodBaseBuildings end DfndTriggerFunction = function() @@ -231,7 +224,7 @@ Tick = function() end end - if DateTime.GameTime % DateTime.Seconds(1) == 0 and not Nod.IsObjectiveCompleted(NodObjective1) and CheckForBase(Nod, NodBaseBuildings) then + if DateTime.GameTime % DateTime.Seconds(1) == 0 and not Nod.IsObjectiveCompleted(NodObjective1) and CheckForBase(Nod) then Nod.MarkCompletedObjective(NodObjective1) end diff --git a/mods/cnc/maps/nod02b/nod02b.lua b/mods/cnc/maps/nod02b/nod02b.lua index 3fdbb968d3..72bb026ecb 100644 --- a/mods/cnc/maps/nod02b/nod02b.lua +++ b/mods/cnc/maps/nod02b/nod02b.lua @@ -149,7 +149,7 @@ Tick = function() Nod.MarkCompletedObjective(NodObjective2) end - if DateTime.GameTime % DateTime.Seconds(1) == 0 and not Nod.IsObjectiveCompleted(NodObjective1) and CheckForBase(Nod, NodBaseBuildings) then + if DateTime.GameTime % DateTime.Seconds(1) == 0 and not Nod.IsObjectiveCompleted(NodObjective1) and CheckForBase(Nod) then Nod.MarkCompletedObjective(NodObjective1) end @@ -158,23 +158,16 @@ Tick = function() end end -CheckForBase = function(player, buildings) - local checked = { } - local baseBuildings = Map.ActorsInBox(Map.TopLeft, Map.BottomRight, function(actor) - if actor.Owner ~= Nod or Utils.Any(checked, function(bldng) return bldng.Type == actor.Type end) then - return false - end +CheckForBase = function(player) + local buildings = 0 - local found = false - for i = 1, #buildings, 1 do - if actor.Type == buildings[i] then - found = true - checked[#checked + 1] = actor - end + Utils.Do(NodBaseBuildings, function(name) + if #player.GetActorsByType(name) > 0 then + buildings = buildings + 1 end - return found end) - return #baseBuildings >= 3 + + return buildings == #NodBaseBuildings end OnAnyDamaged = function(actors, func) diff --git a/mods/cnc/maps/nod05/nod05.lua b/mods/cnc/maps/nod05/nod05.lua index e00b5701ef..1d49ce6b8e 100644 --- a/mods/cnc/maps/nod05/nod05.lua +++ b/mods/cnc/maps/nod05/nod05.lua @@ -270,10 +270,8 @@ IdleHunt = function(unit) end CheckForSams = function(player) - local baseBuildings = Map.ActorsInBox(Map.TopLeft, Map.BottomRight, function(actor) - return actor.Owner == Nod and actor.Type == 'sam' end) - - return #baseBuildings >= 3 + local sams = Nod.GetActorsByType("sam") + return #sams >= 3 end checkProduction = function(player) diff --git a/mods/ra/maps/allies-03a/allies03a.lua b/mods/ra/maps/allies-03a/allies03a.lua index fa9edad3e9..b4603ad71a 100644 --- a/mods/ra/maps/allies-03a/allies03a.lua +++ b/mods/ra/maps/allies-03a/allies03a.lua @@ -245,7 +245,7 @@ InitTriggers = function() player.MarkCompletedObjective(FreePrisoners) end) - local oilPumps = Map.ActorsInBox(Map.TopLeft, Map.BottomRight, function(self) return self.Type == "v19" end) + local oilPumps = ussr.GetActorsByType("v19") Trigger.OnAllKilled(oilPumps, function() player.MarkCompletedObjective(KillUSSR) diff --git a/mods/ra/maps/allies-03a/map.yaml b/mods/ra/maps/allies-03a/map.yaml index 3c64747407..830f3ffcc7 100644 --- a/mods/ra/maps/allies-03a/map.yaml +++ b/mods/ra/maps/allies-03a/map.yaml @@ -439,16 +439,16 @@ Actors: Owner: USSR Actor127: v19 Location: 70,56 - Owner: Neutral + Owner: USSR Actor128: v19 Location: 70,54 - Owner: Neutral + Owner: USSR Actor129: v19 Location: 72,54 - Owner: Neutral + Owner: USSR Actor130: v19 Location: 74,54 - Owner: Neutral + Owner: USSR Actor131: brl3 Location: 84,65 Owner: USSR @@ -457,7 +457,7 @@ Actors: Owner: USSR Actor133: v19 Location: 83,65 - Owner: Neutral + Owner: USSR Actor134: barl Location: 78,70 Owner: USSR @@ -487,16 +487,16 @@ Actors: Owner: USSR Actor142: v19 Location: 87,66 - Owner: Neutral + Owner: USSR Actor143: v19 Location: 85,68 - Owner: Neutral + Owner: USSR Actor144: v19 Location: 82,66 - Owner: Neutral + Owner: USSR Actor145: v19 Location: 85,63 - Owner: Neutral + Owner: USSR Actor146: v04 Location: 54,52 Owner: Neutral @@ -523,10 +523,10 @@ Actors: Owner: USSR Actor154: v19 Location: 59,61 - Owner: Neutral + Owner: USSR Actor155: v19 Location: 57,61 - Owner: Neutral + Owner: USSR Actor156: brl3 Location: 58,61 Owner: USSR @@ -559,7 +559,7 @@ Actors: Owner: USSR Actor170: v19 Location: 54,68 - Owner: Neutral + Owner: USSR Actor179: brl3 Location: 77,66 Owner: USSR @@ -631,7 +631,7 @@ Actors: Owner: USSR Actor202: v19 Location: 101,48 - Owner: Neutral + Owner: USSR Actor203: brl3 Location: 96,50 Owner: USSR @@ -652,13 +652,13 @@ Actors: Owner: USSR Actor209: v19 Location: 102,67 - Owner: Neutral + Owner: USSR Actor210: v19 Location: 101,69 - Owner: Neutral + Owner: USSR Actor211: v19 Location: 100,71 - Owner: Neutral + Owner: USSR Actor212: brl3 Location: 102,66 Owner: USSR @@ -718,7 +718,7 @@ Actors: Owner: USSR Actor232: v19 Location: 91,68 - Owner: Neutral + Owner: USSR Actor233: brl3 Location: 91,69 Owner: USSR @@ -727,13 +727,13 @@ Actors: Owner: USSR Actor234: v19 Location: 84,51 - Owner: Neutral + Owner: USSR Actor235: v19 Location: 87,51 - Owner: Neutral + Owner: USSR Actor236: v19 Location: 86,52 - Owner: Neutral + Owner: USSR Actor237: brl3 Location: 84,52 Owner: USSR