From 64a18389b7d067443f5cade09dc6c9efca043868 Mon Sep 17 00:00:00 2001 From: Oliver Brakmann Date: Wed, 12 Mar 2014 22:34:48 +0100 Subject: [PATCH] Allow for incremental team assembly --- mods/common/lua/team.lua | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/mods/common/lua/team.lua b/mods/common/lua/team.lua index f0f9da15c8..909b430137 100644 --- a/mods/common/lua/team.lua +++ b/mods/common/lua/team.lua @@ -7,22 +7,24 @@ Team.New = function(actors) team.OnAnyKilled = { } team.OnAllRemovedFromWorld = { } team.OnAnyRemovedFromWorld = { } - Team.AddActorEventHandlers(team) + Team.Do(team, function(actor) Team.AddActorEventHandlers(team, actor) end) return team end -Team.AddActorEventHandlers = function(team) - Team.Do(team, function(actor) +Team.Add = function(team, actor) + table.insert(team.Actors, actor) + Team.AddActorEventHandlers(team, actor) +end - Actor.OnKilled(actor, function() - Team.InvokeHandlers(team.OnAnyKilled) - if Team.AllAreDead(team) then Team.InvokeHandlers(team.OnAllKilled) end - end) +Team.AddActorEventHandlers = function(team, actor) + Actor.OnKilled(actor, function() + Team.InvokeHandlers(team.OnAnyKilled) + if Team.AllAreDead(team) then Team.InvokeHandlers(team.OnAllKilled) end + end) - Actor.OnRemovedFromWorld(actor, function() - Team.InvokeHandlers(team.OnAnyRemovedFromWorld) - if not Team.AnyAreInWorld(team) then Team.InvokeHandlers(team.OnAllRemovedFromWorld) end - end) + Actor.OnRemovedFromWorld(actor, function() + Team.InvokeHandlers(team.OnAnyRemovedFromWorld) + if not Team.AnyAreInWorld(team) then Team.InvokeHandlers(team.OnAllRemovedFromWorld) end end) end