From c5f12523aa038145f8e3cc218674f9ebdee23015 Mon Sep 17 00:00:00 2001 From: Sven Eberhardt Date: Sun, 6 Dec 2015 21:45:06 -0500 Subject: [PATCH] Fix ruby sale goal counting gems twice (#1489). --- planet/Objects.ocd/Items.ocd/Resources.ocd/Ruby.ocd/Script.c | 4 ++-- .../Libraries.ocd/Structures.ocd/Base.ocd/Script.c | 4 +++- planet/Objects.ocd/Structures.ocd/Flagpole.ocd/Script.c | 4 +++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/planet/Objects.ocd/Items.ocd/Resources.ocd/Ruby.ocd/Script.c b/planet/Objects.ocd/Items.ocd/Resources.ocd/Ruby.ocd/Script.c index ee30501b6..ff1512f5b 100644 --- a/planet/Objects.ocd/Items.ocd/Resources.ocd/Ruby.ocd/Script.c +++ b/planet/Objects.ocd/Items.ocd/Resources.ocd/Ruby.ocd/Script.c @@ -42,12 +42,12 @@ func FxSparkleTimer(target, effect, effect_time) func IsValuable() { return true; } -func QueryOnSell() +func OnSale(int to_player, object sale_base) { // Inform goal of gem sale var goal = FindObject(Find_ID(Goal_SellGems)); if (goal) goal->OnGemSold(); - return false; // do perform selling + return true; } func Hit() diff --git a/planet/Objects.ocd/Libraries.ocd/Structures.ocd/Base.ocd/Script.c b/planet/Objects.ocd/Libraries.ocd/Structures.ocd/Base.ocd/Script.c index 3bec87bdd..1376f5f52 100644 --- a/planet/Objects.ocd/Libraries.ocd/Structures.ocd/Base.ocd/Script.c +++ b/planet/Objects.ocd/Libraries.ocd/Structures.ocd/Base.ocd/Script.c @@ -387,9 +387,11 @@ func DoSell(object pObj, int iPlr, bool bRight) break; } } + // OnSale callback to object e.g. for goal callbacks + pObj->~OnSale(iPlr, this); // And remove the object pObj->RemoveObject(); - if(bFound) return DoSell(pNewObj, iPlr, bRight); + if(bFound) return DoSell(pNewObj, iPlr, bRight); // wtf why is this recursive? will fail with too many objects return true; } diff --git a/planet/Objects.ocd/Structures.ocd/Flagpole.ocd/Script.c b/planet/Objects.ocd/Structures.ocd/Flagpole.ocd/Script.c index 41aa86c74..7eb11b1b1 100644 --- a/planet/Objects.ocd/Structures.ocd/Flagpole.ocd/Script.c +++ b/planet/Objects.ocd/Structures.ocd/Flagpole.ocd/Script.c @@ -196,8 +196,10 @@ public func Collection(object obj) if (obj->~IsValuable() && !obj->~QueryOnSell(obj->GetController())) { DoWealth(obj->GetController(), obj->GetValue()); - obj->RemoveObject(); Sound("Cash"); + // OnSale callback to object e.g. for goal updates + obj->~OnSale(obj->GetController(), this); + if (obj) obj->RemoveObject(); } return _inherited(obj, ...); }