diff --git a/planet/Objects.ocd/Items.ocd/Tools.ocd/Barrel.ocd/Script.c b/planet/Objects.ocd/Items.ocd/Tools.ocd/Barrel.ocd/Script.c index 267471d03..6b89f1f7f 100644 --- a/planet/Objects.ocd/Items.ocd/Tools.ocd/Barrel.ocd/Script.c +++ b/planet/Objects.ocd/Items.ocd/Tools.ocd/Barrel.ocd/Script.c @@ -197,7 +197,7 @@ public func IsLiquidContainerForMaterial(string sznMaterial) public func CanBeStackedWith(object other) { // Does not take into account the fill level for now. - return inherited(other, ...) && (other->~GetBarrelMaterial() == this->GetBarrelMaterial()); + return inherited(other, ...) && (other->~GetLiquidType() == this->GetLiquidType()); } public func CalcValue(object in_base, int for_player) diff --git a/planet/Tests.ocf/LiquidContainer.ocs/Script.c b/planet/Tests.ocf/LiquidContainer.ocs/Script.c index 5b2ce9e79..75ec8c1fc 100644 --- a/planet/Tests.ocf/LiquidContainer.ocs/Script.c +++ b/planet/Tests.ocf/LiquidContainer.ocs/Script.c @@ -590,4 +590,61 @@ global func Test9_OnFinished() { RemoveAll(Find_Or(Find_ID(Pump), Find_ID(SteamEngine), Find_ID(Pipe))); return true; -} \ No newline at end of file +} + +global func Test10_OnStart(int plr){ return true;} +global func Test10_OnFinished(){ return; } +global func Test10_Execute() +{ + Log("Test the behaviour of barrels getting stacked"); + + var container1 = CreateObject(Barrel); + var container2 = CreateObject(Barrel); + + // can stack filled barrel with other filled barrel of the same liquid + container1->SetLiquidContainer("Water", 100); + container2->SetLiquidContainer("Water", 300); + + var passed = true; + var returned = container1->CanBeStackedWith(container2); + var test = returned == true; passed &= test; + Log("- Barrel can be stacked with other barrel that contains the same liquid: %v", test); + returned = container2->CanBeStackedWith(container1); + test = returned == true; passed &= test; + Log("- Barrel can be stacked with other barrel that contains the same liquid: %v", test); + + // cannot stack filled barrel with other empty barrel + container1->SetLiquidContainer("Water", 100); + container2->SetLiquidFillLevel(0); + + returned = container1->CanBeStackedWith(container2); + test = returned == false; passed &= test; + Log("- Filled barrel cannot be stacked with empty barrel: %v", test); + returned = container2->CanBeStackedWith(container1); + test = returned == false; passed &= test; + Log("- Empty barrel cannot be stacked with filled barrel: %v", test); + + // can stack empty barrel with other empty barrel + container1->SetLiquidFillLevel(0); + container2->SetLiquidFillLevel(0); + + returned = container1->CanBeStackedWith(container2); + test = returned == true; passed &= test; + Log("- Empty barrel can be stacked with empty barrel: %v", test); + + // cannot stack filled barrel with other filled barrel of different liquid + container1->SetLiquidContainer("Water", 100); + container2->SetLiquidContainer("Oil", 100); + + returned = container1->CanBeStackedWith(container2); + test = returned == false; passed &= test; + Log("- Liquid A barrel cannot be stacked with liquid B barrel: %v", test); + returned = container2->CanBeStackedWith(container1); + test = returned == false; passed &= test; + Log("- Liquid B barrel cannot be stacked with liquid A barrel: %v", test); + + container1->RemoveObject(); + container2->RemoveObject(); + + return passed; +}