From d58d41e960b0a96180b8f7b12971b0243326da72 Mon Sep 17 00:00:00 2001 From: Maikel de Vries Date: Sat, 5 Sep 2015 23:21:25 +0200 Subject: [PATCH] clean up balloon script Was trying to solve bugs, but they are located in other scripts --- .../Balloon.ocd/BalloonDeployed.ocd/Script.c | 183 ++++++++++-------- .../Items.ocd/Tools.ocd/Balloon.ocd/Script.c | 59 +++--- 2 files changed, 136 insertions(+), 106 deletions(-) diff --git a/planet/Objects.ocd/Items.ocd/Tools.ocd/Balloon.ocd/BalloonDeployed.ocd/Script.c b/planet/Objects.ocd/Items.ocd/Tools.ocd/Balloon.ocd/BalloonDeployed.ocd/Script.c index e0734880a..76bd51bbf 100644 --- a/planet/Objects.ocd/Items.ocd/Tools.ocd/Balloon.ocd/BalloonDeployed.ocd/Script.c +++ b/planet/Objects.ocd/Items.ocd/Tools.ocd/Balloon.ocd/BalloonDeployed.ocd/Script.c @@ -1,28 +1,42 @@ -/*-- Balloon - Deployed --*/ +/** + Deployed Balloon + Helper object for the balloon. +*/ local rider; local parent; -local idir; protected func Initialize() { - idir = 0; SetAction("Inflate"); SetComDir(COMD_None); - AddEffect("Float",this,1,1,this); + // Control direction determines the horizontal movement of the balloon. + var effect = AddEffect("ControlFloat", this, 100, 1, this); + effect.control_dir = 0; - //Special Effects + // Create some air particles on inflation. CreateParticle("Air", PV_Random(-1, 1), PV_Random(15, 17), PV_Random(-3, 3), PV_Random(0, 2), 18, Particles_Air(), 20); + return; +} + +public func SetRider(object clonk) +{ + rider = clonk; +} + +public func SetParent(object balloon) +{ + parent = balloon; } private func Deflate() { - if(GetAction() != "Deflate") + if (GetAction() != "Deflate") { SetAction("Deflate"); SetComDir(COMD_None); } - Schedule(this,"Pack()",20); //EndCall doesn't work. >:( + //Schedule(this, "Pack()", 20); //EndCall doesn't work. >:( } private func DeflateEffect() @@ -33,45 +47,78 @@ private func DeflateEffect() private func Pack() { - RemoveEffect("NoDrop",parent); + RemoveEffect("NoDrop", parent); rider->SetAction("Jump"); - rider->SetSpeed(GetXDir(),GetYDir()); + rider->SetSpeed(GetXDir(), GetYDir()); rider->SetComDir(COMD_Down); RemoveObject(); } -func ControlLeft() + +/*-- Controls --*/ + +public func ControlLeft() { - idir = -1; + var effect = GetEffect("ControlFloat", this); + if (effect) + effect.control_dir = -1; return true; } -func ControlRight() +public func ControlRight() { - idir = 1; + var effect = GetEffect("ControlFloat", this); + if (effect) + effect.control_dir = 1; return true; } -func ControlStop() +public func ControlStop() { - idir = 0; + var effect = GetEffect("ControlFloat", this); + if (effect) + effect.control_dir = 0; return true; } -func ControlJump() +public func ControlJump() { Deflate(); + return true; } - -public func IsProjectileTarget(target,shooter) +public func FxControlFloatTimer(object target, proplist effect, int time) { - return 1; + var speed = 7; + if (GetYDir() > speed) SetYDir(GetYDir() - 1); + if (GetYDir() < speed) SetYDir(GetYDir() + 1); + if (GetXDir() > speed * 3) SetXDir(GetXDir() - 1); + if (GetXDir() < -speed * 3) SetXDir(GetXDir() + 1); + + // Forward the control direction into movement. + SetXDir(GetXDir() + effect.control_dir); + + // Has a bottom vertex hit? Is the balloon stuck in material? Then deflate. + if (GetContact(-1) & CNAT_Bottom || Stuck()) + { + Deflate(); + return FX_Execute_Kill; + } + if (GBackSolid(0, 50) || GBackLiquid(0, 50)) + { + Deflate(); + return FX_OK; + } +} + +public func IsProjectileTarget() +{ + return true; } public func OnProjectileHit() { - //Pop! + // Pop the balloon and tumble the rider. CreateParticle("Air", 0, -10, PV_Random(-10, 10), PV_Random(-10, 10), 10, Particles_Air(), 30); Sound("BalloonPop"); if (rider) @@ -83,69 +130,47 @@ public func OnProjectileHit() RemoveObject(); } -private func FxFloatTimer(object target, effect, int time) -{ - var speed = 7; - if(GetYDir() > speed) SetYDir(GetYDir() - 1); - if(GetYDir() < speed) SetYDir(GetYDir() + 1); - if(GetXDir() > speed * 3) SetXDir(GetXDir()-1); - if(GetXDir() < -speed * 3) SetXDir(GetXDir()+1); - - //Control - SetXDir(GetXDir() + idir); - //Message(Format("%d",idir)); - - if(GetContact(-1) & CNAT_Bottom || Stuck()) //Has a bottom vertex hit? Is the balloon stuck in material? Then deflate. - { - Deflate(); - return -1; - } - if(GBackSolid(0,50) || GBackLiquid(0,50)) - { - Deflate(); - return 1; - } -} - // Could store and restore the deployed balloon, but all the // dependencies to be set when recreating this mid-animation // will probably cause more upwards incompatibilities than benefit -func SaveScenarioObject() { return false; } +public func SaveScenarioObject() { return false; } + + +/*-- Properties --*/ local ActMap = { - -Float = { - Prototype = Action, - Name = "Float", - Procedure = DFA_FLOAT, - Directions = 1, - Length = 144, - Delay = 1, - NextAction = "Float", - Animation = "Fly", -}, - -Inflate = { - Prototype = Action, - Name = "Inflate", - Procedure = DFA_FLOAT, - Directions = 1, - Length = 20, - Delay = 1, - NextAction = "Float", - Animation = "Inflate", -}, - -Deflate = { - Prototype = Action, - Name = "Deflate", - Procedure = DFA_FLOAT, - Directions = 1, - Length = 20, - Delay = 1, - PhaseCall = "DeflateEffect", - EndCall = "Pack", - Animation = "Deflate", -}, + Float = { + Prototype = Action, + Name = "Float", + Procedure = DFA_FLOAT, + Directions = 1, + Length = 144, + Delay = 1, + NextAction = "Float", + Animation = "Fly", + }, + Inflate = { + Prototype = Action, + Name = "Inflate", + Procedure = DFA_FLOAT, + Directions = 1, + Length = 20, + Delay = 1, + NextAction = "Float", + Animation = "Inflate", + }, + Deflate = { + Prototype = Action, + Name = "Deflate", + Procedure = DFA_FLOAT, + Directions = 1, + Length = 20, + Delay = 1, + PhaseCall = "DeflateEffect", + EndCall = "Pack", + AbortCall = "Pack", + NextAction = "Idle", + Animation = "Deflate", + }, }; local Name = "$Name$"; diff --git a/planet/Objects.ocd/Items.ocd/Tools.ocd/Balloon.ocd/Script.c b/planet/Objects.ocd/Items.ocd/Tools.ocd/Balloon.ocd/Script.c index 80eae660b..4ebbe735e 100644 --- a/planet/Objects.ocd/Items.ocd/Tools.ocd/Balloon.ocd/Script.c +++ b/planet/Objects.ocd/Items.ocd/Tools.ocd/Balloon.ocd/Script.c @@ -1,53 +1,58 @@ -/*-- Balloon --*/ +/** + Balloon + Inflatable balloon which acts like a parachute. +*/ -local user; public func RejectUse(object clonk) { // Disallow if directly above ground or water or if the Clonk is already holding onto something. - return GBackSemiSolid(0,15) || clonk->GetActionTarget() != nil; + return GBackSemiSolid(0, 15) || clonk->GetActionTarget() != nil; } -func ControlUseStart(object clonk, int ix, int iy) +public func ControlUseStart(object clonk) { - var balloon = CreateObjectAbove(BalloonDeployed,0,5); - balloon->SetSpeed(clonk->GetXDir(),clonk->GetYDir()); + // Create the balloon and set its speed and rider. + var balloon = CreateObjectAbove(BalloonDeployed, 0, 5); + balloon->SetSpeed(clonk->GetXDir(), clonk->GetYDir()); + balloon->SetRider(clonk); + balloon->SetParent(this); - //sound + // Sound. Sound("BalloonInflate"); - //Lots of object pointers - user = clonk; - clonk->SetAction("Ride",balloon); - balloon["rider"] = clonk; - balloon["parent"] = this; + // Make the clonk ride the balloon. + clonk->SetAction("Ride", balloon); - //make sure clonk is not diving - var side = "R"; - if(Random(2)) side = "L"; - user->PlayAnimation(Format("Jump.%s",side), 5, Anim_Linear(user->GetAnimationLength("Jump.L"), 0, - user->GetAnimationLength("Jump.L"), 36, ANIM_Hold), Anim_Linear(0, 0, 1000, 5, ANIM_Remove)); + // Make sure clonk is not diving. + var side = ["L", "R"][Random(2)]; + clonk->PlayAnimation(Format("Jump.%s", side), 5, Anim_Linear(clonk->GetAnimationLength("Jump.L"), 0, clonk->GetAnimationLength("Jump.L"), 36, ANIM_Hold), Anim_Linear(0, 0, 1000, 5, ANIM_Remove)); - AddEffect("NoDrop",this,1,1,this); - return 1; + // Ensure the balloon is not dropped or thrown. + var effect = AddEffect("NoDrop", this, 1, 1, this); + effect.user = clonk; + return true; } -func FxNoDropTimer(object target, effect, int timer) +// Replace me by a callback which blocks departure. +public func FxNoDropTimer(object target, proplist effect, int timer) { - if(target->Contained() != user) - { - target->Enter(user); - } + if (target->Contained() != effect.user) + target->Enter(effect.user); + return FX_OK; } -func Hit() +public func Hit() { Sound("GeneralHit?"); } -func IsInventorProduct() { return true; } +public func IsInventorProduct() { return true; } -local Collectible = 1; + +/*-- Properties --*/ + +local Collectible = true; local Name = "$Name$"; local Description = "$Description$"; local UsageHelp = "$UsageHelp$";