From 3d3e51489c98233021e4308020b83ec6d003d85e Mon Sep 17 00:00:00 2001 From: Sven Eberhardt Date: Sun, 5 Mar 2017 11:45:04 -0500 Subject: [PATCH] Add user action on enemy spawn --- planet/Objects.ocd/Helpers.ocd/EnemySpawn.ocd/Script.c | 8 ++++++++ .../Helpers.ocd/EnemySpawn.ocd/StringTblDE.txt | 4 +++- .../Helpers.ocd/EnemySpawn.ocd/StringTblUS.txt | 2 ++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/planet/Objects.ocd/Helpers.ocd/EnemySpawn.ocd/Script.c b/planet/Objects.ocd/Helpers.ocd/EnemySpawn.ocd/Script.c index 47cd46c7e..81941643f 100644 --- a/planet/Objects.ocd/Helpers.ocd/EnemySpawn.ocd/Script.c +++ b/planet/Objects.ocd/Helpers.ocd/EnemySpawn.ocd/Script.c @@ -22,6 +22,7 @@ local attack_path = nil; // Optional: Array of points along which the spawned en local auto_activate = false; // If true, the object is activated on the first player join local max_concurrent_enemies = SPAWNCOUNT_INFINITE; // May be set to a smaller value to limit the amount of enemies spawned in parallel. Only works with spawn_delay>0. local has_been_activated; // Set to true after first activation. Not saved in scenario. +local spawn_action; // UserAction excuted on each spawned enemy local spawned_count; // Number of enemies already spawned in current wave local spawned_enemies; // Array of spawned enemies. Automatically cleared when clonks die. @@ -198,17 +199,23 @@ private func Spawn() // Do spawn var enemies = (enemy_def.SpawnCallTarget ?? GetID())->Call(spawn_function, spawn_pos, enemy, enemy_def, use_attack_path, this); // Keep track of enemies. Could be returned as a single enemy or as an array + var first_enemy; if (GetType(enemies) == C4V_Array) { for (var obj in enemies) { TrackSpawnedEnemy(obj); } + first_enemy = enemies[0]; } else { TrackSpawnedEnemy(enemies); + first_enemy = enemies; } + // Perform spawn action + if (first_enemy) UserAction->EvaluateAction(spawn_action, this, first_enemy); + if (!this) return; } // Keep track of count if (++spawned_count == spawn_count) @@ -523,6 +530,7 @@ public func Definition(def) { Name="$Unlimited$", Value=SPAWNCOUNT_INFINITE }, { Name="$FixedNumber$", Value=1, Type=C4V_Int, Delegate={ Type="int", Min=1, Set="SetMaxConcurrentEnemies", SetRoot=true } } ] }; + def.EditorProps.spawn_action = new UserAction.Prop { Name="$SpawnAction$", EditorHelp="$SpawnActionHelp$" }; AddEnemyDef("Clonk", { SpawnType=Clonk, SpawnFunction=def.SpawnClonk, GetInfoString=GetAIClonkInfoString }, def->GetAIClonkDefaultPropValues(), def->GetAIClonkEditorProps()); } diff --git a/planet/Objects.ocd/Helpers.ocd/EnemySpawn.ocd/StringTblDE.txt b/planet/Objects.ocd/Helpers.ocd/EnemySpawn.ocd/StringTblDE.txt index 499b1c625..d65c1352a 100644 --- a/planet/Objects.ocd/Helpers.ocd/EnemySpawn.ocd/StringTblDE.txt +++ b/planet/Objects.ocd/Helpers.ocd/EnemySpawn.ocd/StringTblDE.txt @@ -63,4 +63,6 @@ AllEnemiesKilledHelp=Wahr wenn alle Gegner aus einem oder mehreren aktivierten G AttackSpeed=Angriffsgeschwindigkeit AttackSpeedHelp=Nur Fernkampfwaffen: Anpassung der Schuss- und Nachladegeschwindigkeit in Prozent des Standardwertes. Grosse Werte bedeuten schnelleres Schiessen und Nachladen. Shield=Schild -ShieldHelp=Ob der Gegnerclonk einen Schild zur Abwehr von Angriffen traegt. \ No newline at end of file +ShieldHelp=Ob der Gegnerclonk einen Schild zur Abwehr von Angriffen traegt. +SpawnAction=Aktion bei Spawn +SpawnActionHelp=Aktion, die mit jedem Gegnerspawn ausgefuehrt wird (zum Beispiel fuer grafische Effekte). diff --git a/planet/Objects.ocd/Helpers.ocd/EnemySpawn.ocd/StringTblUS.txt b/planet/Objects.ocd/Helpers.ocd/EnemySpawn.ocd/StringTblUS.txt index 92bba4cd5..0424b2b08 100644 --- a/planet/Objects.ocd/Helpers.ocd/EnemySpawn.ocd/StringTblUS.txt +++ b/planet/Objects.ocd/Helpers.ocd/EnemySpawn.ocd/StringTblUS.txt @@ -64,3 +64,5 @@ AttackSpeed=Attack speed AttackSpeedHelp=Ranged weapons only: Adjustment of shoot and reload speed in percent of the default value. Large values mean faster shooting and reloading. Shield=Shield ShieldHelp=Whether the enemy clonk carries a shield to deflect attacks. +SpawnAction=Action on spawn +SpawnActionHelp=Action to be executed for each spawned enemy. Can be used e.g. for graphical effects.