From 8cc30baf02b57f1bcebff6b690d999e7aa1f303c Mon Sep 17 00:00:00 2001 From: Maikel de Vries Date: Wed, 18 Jan 2017 18:21:12 +0100 Subject: [PATCH] add option to gravestone rule to fade them out --- .../DefenseBoomAttack.ocd/Script.c | 4 +- .../Rules.ocd/Gravestones.ocd/Script.c | 104 +++++++++++------- 2 files changed, 70 insertions(+), 38 deletions(-) diff --git a/planet/Objects.ocd/Goals.ocd/Defense.ocd/DefenseBoomAttack.ocd/Script.c b/planet/Objects.ocd/Goals.ocd/Defense.ocd/DefenseBoomAttack.ocd/Script.c index ecb06b3bc..73d6b5361 100644 --- a/planet/Objects.ocd/Goals.ocd/Defense.ocd/DefenseBoomAttack.ocd/Script.c +++ b/planet/Objects.ocd/Goals.ocd/Defense.ocd/DefenseBoomAttack.ocd/Script.c @@ -160,7 +160,9 @@ private func DoFireworks(int killed_by) SetRider(nil); } // Notify defense goal for reward and score. - GameCallEx("OnClonkDeath", this, killed_by); + var defense = FindObject(Find_ID(Goal_Defense)); + if (defense) + defense->~OnClonkDeath(this, killed_by); Fireworks(); Explode(40); return; diff --git a/planet/Objects.ocd/Rules.ocd/Gravestones.ocd/Script.c b/planet/Objects.ocd/Rules.ocd/Gravestones.ocd/Script.c index 981a2d466..0209ca625 100644 --- a/planet/Objects.ocd/Rules.ocd/Gravestones.ocd/Script.c +++ b/planet/Objects.ocd/Rules.ocd/Gravestones.ocd/Script.c @@ -1,4 +1,12 @@ -/*-- Gravestones --*/ +/** + Gravestone Rule + Dead clonks are replaced by gravestones. + + @author Ringwaul +*/ + + +local fade_out; protected func Initialize() @@ -6,59 +14,81 @@ protected func Initialize() // Under no circumstance there may by multiple copies of this rule. if (ObjectCount(Find_ID(Rule_Gravestones)) > 1) return RemoveObject(); + fade_out = nil; return; } +public func SetFadeOut(int time) +{ + fade_out = time; + return; +} public func OnClonkDeath(object clonk) { + // Add a gravestone if the clonk died. if (!clonk->GetAlive()) - AddEffect("AddGravestone", clonk, 1, 1, this); + clonk->CreateEffect(FxAddGravestone, 100, 1, fade_out); return; } -public func FxAddGravestoneTimer(object target, proplist effect, int timer) -{ - // Wait for the death animation to be over. - if (timer >= 20) +local FxAddGravestone = new Effect +{ + Construction = func(int fade_out) { - AddEffect("IntGravestone", target, 1, nil, this); - return -1; + this.fade_out = fade_out; + }, + Timer = func(int time) + { + // Wait for the death animation to be over. + if (time >= 20) + return FX_Execute_Kill; + return FX_OK; + }, + Destruction = func(int reason) + { + // Don't do anything if the clonk has been removed. + if (reason == FX_Call_RemoveClear) + return; + // Create the grave and remove the clonk. + this.grave = Target->CreateObjectAbove(Clonk_Grave, 0, 0, Target->GetController()); + this.grave->SetInscription(Target); + if (this.fade_out > 0) + this.grave->FadeOut(this.fade_out, true); + Target->RemoveObject(); + // Smoke effect. + var particles = + { + Prototype = Particles_Dust(), + R = 200, + G = 100, + B = 50, + Size = PV_KeyFrames(0, 0, 0, 300, 40, 1000, 15) + }; + this.grave->CreateParticle("Dust", 0, 0, PV_Random(-3, 3), PV_Random(-3, 3), PV_Random(18, 1 * 36), particles, 6); } -} +}; -public func FxIntGravestoneStart(object clonk, proplist effect) +protected func Activate(int by_plr) { - effect.grave = clonk->CreateObjectAbove(Clonk_Grave, 0, 0, clonk->GetController()); - effect.grave->SetInscription(clonk); - clonk->RemoveObject(); - //smoke effect - var particles = - { - Prototype = Particles_Dust(), - R = 200, - G = 100, - B = 50, - Size = PV_KeyFrames(0, 0, 0, 300, 40, 1000, 15) - }; - effect.grave->CreateParticle("Dust", 0, 0, PV_Random(-3, 3), PV_Random(-3, 3), PV_Random(18, 1 * 36), particles, 6); -} - -public func FxIntGravestoneStop(object clonk, proplist effect, int reason) -{ - if (reason != FX_Call_RemoveClear) - { - clonk->Exit(); - effect.grave->RemoveObject(); - } -} - -protected func Activate(int iByPlayer) -{ - MessageWindow(GetProperty("Description"), iByPlayer); + MessageWindow(GetProperty("Description"), by_plr); return true; } + +/*-- Scenario Saving -- */ + +public func SaveScenarioObject(props) +{ + if (!inherited(props, ...)) return false; + if (fade_out != nil) + props->AddCall("FadeOut", this, "SetFadeOut", fade_out); + return true; +} + + +/*-- Properties --*/ + local Name = "$Name$"; local Description = "$Description$"; local Visibility = VIS_Editor;