Replace Lua's for loops with Utils.Do/Team.Do

Besides fitting in better with the OpenRA coding style, this also gets
rid of some weird timing-related errors I have seen when creating teams
with a larger number (6+) of members. (The script would just print
'Error: function' in Team.AddActorEventHandlers. Adding a strategically
placed print statement fixed that. Replacing the original for loop with
Team.Do did as well)
This commit is contained in:
Oliver Brakmann
2014-01-30 22:23:09 +01:00
parent b3323869cb
commit 42532efd8f

View File

@@ -12,7 +12,7 @@ Team.New = function(actors)
end
Team.AddActorEventHandlers = function(team)
for i, actor in ipairs(team.Actors) do
Team.Do(team, function(actor)
Actor.OnKilled(actor, function()
Team.InvokeHandlers(team.OnAnyKilled)
@@ -23,13 +23,11 @@ Team.AddActorEventHandlers = function(team)
Team.InvokeHandlers(team.OnAnyRemovedFromWorld)
if not Team.AnyAreInWorld(team) then Team.InvokeHandlers(team.OnAllRemovedFromWorld) end
end)
end
end)
end
Team.InvokeHandlers = function(event)
for i, handler in ipairs(event) do
handler()
end
Utils.Do(event, function(handler) handler() end)
end
Team.AllAreDead = function(team)