From 2e3a984b2018ba879730a52f8c67ac384c0d3376 Mon Sep 17 00:00:00 2001 From: Mark Date: Fri, 18 Mar 2016 06:35:44 +0100 Subject: [PATCH] Producers: Fixed objects with liquid need Liquids are handled as objects now, so that the function GetLiquidNeed() in the objects is obsolete. Adjusted the collection function accordingly. --- .../Structures.ocd/Producer.ocd/Script.c | 33 ++++++++++++++----- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/planet/Objects.ocd/Libraries.ocd/Structures.ocd/Producer.ocd/Script.c b/planet/Objects.ocd/Libraries.ocd/Structures.ocd/Producer.ocd/Script.c index 9ececa755..9fda745e1 100644 --- a/planet/Objects.ocd/Libraries.ocd/Structures.ocd/Producer.ocd/Script.c +++ b/planet/Objects.ocd/Libraries.ocd/Structures.ocd/Producer.ocd/Script.c @@ -174,7 +174,6 @@ public func OnProductHover(symbol, extra_data, desc_menu_target, menu_id) var product_id = symbol; var costs = ProductionCosts(product_id); var cost_msg = ""; - var liquid; for (var comp in costs) cost_msg = Format("%s %s {{%i}}", cost_msg, GetCostString(comp[1], CheckComponent(comp[0], comp[1])), comp[0]); if (this->~FuelNeed(product_id)) @@ -480,7 +479,6 @@ private func ProcessQueue() // These functions may be overloaded by the actual producer. private func ProductionTime(id product) { return product->~GetProductionTime(); } private func FuelNeed(id product) { return product->~GetFuelNeed(); } -private func LiquidNeed(id product) { return product->~GetLiquidNeed(); } public func PowerNeed() { return 80; } @@ -786,19 +784,38 @@ public func IsCollectionAllowed(object obj) return true; } // Liquid objects may be collected if a product needs them. - if (obj->~IsLiquid()) + if (obj->~GetLiquidType()) { for (var product in products) - if (LiquidNeed(product)) - if (LiquidNeed(product)[0] == obj->~IsLiquid()) + { + var i = 0, comp_id; + while (comp_id = GetComponent(nil, i, nil, product)) + { + if (comp_id->~GetLiquidType() == obj->~GetLiquidType()) return true; + i++; + } + } } - // Liquid containers may be collected if a product needs them. + // Liquid containers may not be collected, but we take their contents if a product needs them. if (obj->~IsLiquidContainer()) { for (var product in products) - if (LiquidNeed(product)) - return true; + { + var i = 0, comp_id; + while (comp_id = GetComponent(nil, i, nil, product)) + { + for (var liquid in FindObjects(Find_Container(obj))) + { + if (liquid->~GetLiquidType() == comp_id->~GetLiquidType()) + { + liquid->Enter(this); + } + } + i++; + } + } + return false; } return false; }