From a5b8caab9ddb354c9641749aaf05740a1c5cb357 Mon Sep 17 00:00:00 2001 From: Clonkonaut Date: Thu, 3 Apr 2014 16:54:37 +0200 Subject: [PATCH] Reworked tree splitting. Moved the logic from the axe to the tree library for better handling. Also, dual splitting with two players is effective now (hasn't been before). --- .../Items.ocd/Tools.ocd/Axe.ocd/Script.c | 12 +++---- .../Plants.ocd/Tree.ocd/Script.c | 31 +++++++++++++++++-- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/planet/Objects.ocd/Items.ocd/Tools.ocd/Axe.ocd/Script.c b/planet/Objects.ocd/Items.ocd/Tools.ocd/Axe.ocd/Script.c index 570b0c7e6..f5a4d26d2 100644 --- a/planet/Objects.ocd/Items.ocd/Tools.ocd/Axe.ocd/Script.c +++ b/planet/Objects.ocd/Items.ocd/Tools.ocd/Axe.ocd/Script.c @@ -238,13 +238,10 @@ func FxIntSplitTimer(object clonk, effect, int time) //Create the woodchip particle clonk->CreateParticle("WoodChip", x, 4, PV_Random(-12, 12), PV_Random(-13, -6), PV_Random(36 * 3, 36 * 10), Particles_WoodChip(), 10); - } - // Tree split! - if ((axe_swing_time * 12) / time == 1) - { - var wood_count = effect.tree->GetComponent(Wood) / 2; - CastObjects(Wood, wood_count, 5, AbsX(effect.tree->GetX()), AbsY(effect.tree->GetY())); - effect.tree->RemoveObject(); + + // Split tree! + effect.tree->Split(); + if (!effect.tree) return -1; } //Make sure the clonk does not move clonk->SetComDir(COMD_Stop); @@ -368,7 +365,6 @@ func FxAxeStrikeStopTimer(pTarget, effect) return 1; } - public func IsTool() { return true; } public func IsToolProduct() { return true; } diff --git a/planet/Objects.ocd/Libraries.ocd/Plants.ocd/Tree.ocd/Script.c b/planet/Objects.ocd/Libraries.ocd/Plants.ocd/Tree.ocd/Script.c index 424dab0a4..1228c89be 100644 --- a/planet/Objects.ocd/Libraries.ocd/Plants.ocd/Tree.ocd/Script.c +++ b/planet/Objects.ocd/Libraries.ocd/Plants.ocd/Tree.ocd/Script.c @@ -26,12 +26,12 @@ public func IsStanding() /** Maximum damage the tree can take before it falls. Each blow from the axe deals 10 damage. @return \c the maximum amount of damage. */ -private func MaxDamage() +func MaxDamage() { return 50; } -protected func Damage() +func Damage() { // do not grow for a few seconds var g = GetGrowthValue(); @@ -123,3 +123,30 @@ func FxTreeFallTimer(object target, proplist effect) return -1; } } + +/* Splitting */ + +local split; + +/** Amount of axe strikes needed to split the tree into its components. + @return \c the amount of strikes. +*/ +func Toughness() +{ + return 5; +} + +/** Call to add another strike to the split routine. +*/ +func Split() +{ + split++; + if (split > Toughness()) SplitDown(); +} + +/** Called when the tree is split using an axe. Default behaviour is Split2Components(); +*/ +func SplitDown() +{ + Split2Components(); +} \ No newline at end of file