From 3f2ee5080dbbeffab6ce30f9cc712d2f4fc3de67 Mon Sep 17 00:00:00 2001 From: Mark Date: Tue, 25 Dec 2018 16:53:47 +0100 Subject: [PATCH] Limit liquid input to the maximum available amount --- .../LiquidContainer.ocd/Script.c | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/planet/Objects.ocd/Libraries.ocd/LiquidControl.ocd/LiquidContainer.ocd/Script.c b/planet/Objects.ocd/Libraries.ocd/LiquidControl.ocd/LiquidContainer.ocd/Script.c index cc38b0e55..68d1456d8 100644 --- a/planet/Objects.ocd/Libraries.ocd/LiquidControl.ocd/LiquidContainer.ocd/Script.c +++ b/planet/Objects.ocd/Libraries.ocd/LiquidControl.ocd/LiquidContainer.ocd/Script.c @@ -116,24 +116,26 @@ Inserts liquid into the container. */ public func PutLiquid(liquid_name, int amount, object source) { - amount = amount ?? this->GetLiquidAmountRemaining(); - + amount = amount ?? this->GetLiquidAmountRemaining(liquid_name); if (amount < 0) { FatalError(Format("You can insert positive amounts of liquid only, got %d", amount)); } var type = GetLiquidDef(liquid_name); - + + // Do nothing? var max = this->GetLiquidContainerMaxFillLevel(liquid_name); var before = GetLiquidAmount(liquid_name); if (max > 0 && before >= max) return 0; + // Limit to the actual maximum + amount = Min(amount, max); if (type) { var liquid = type->~CreateLiquid(amount); if (liquid) Collect(liquid, true); - // the check is necessary here, because the liquid may get removed if the barrel already + // The check is necessary here, because the liquid may get removed if the barrel already // has a stack inside if (liquid && !(liquid->Contained())) liquid->RemoveObject(); } @@ -149,12 +151,20 @@ public func AcceptsLiquid(liquid_name, int amount) return IsLiquidContainerForMaterial(liquid_type) && amount <= this->GetLiquidContainerMaxFillLevel(liquid_name) - GetLiquidAmount(liquid_name); } -private func GetLiquidDef(liquid_name) +func GetLiquidDef(liquid_name) { if (GetType(liquid_name) == C4V_String) + { return GetDefinition(liquid_name); + } else if (GetType(liquid_name) == C4V_Def) + { return liquid_name; + } + else if (GetType(liquid_name) == C4V_C4Object) + { + return liquid_name->GetID(); + } FatalError(Format("The first parameter of GetLiquidDef() must either be a string or definition. You passed %v.", liquid_name)); return nil; } \ No newline at end of file