Liquid Object: Simplified transfer into liquid container.

Unfortunately, now the object is not actually transferred, but removed, and a new one is created or an existing one is filled in the liquid container. The logic could use a rework actually, because everything was more clear when the container stored things in variables.
liquid_container
Mark 2016-02-20 21:00:48 +01:00
parent 9e46d752a9
commit 7cc88bd909
3 changed files with 18 additions and 45 deletions

View File

@ -45,28 +45,20 @@ protected func RejectEntrance(object into)
func CannotEnter(object into)
{
// Enters liquid containers only
// Enters liquid containers only, will be removed anyway if the liquid object is "empty"
if (into->~IsLiquidContainer() || into->~IsLiquidPump())
{
if (!into->~LiquidContainerAccepts(IsLiquid()))
if (!GetLiquidAmount()) // the object is "empty", because it was just created
{
return true; // Cannot enter
return false;
}
for (var other_liquid in FindObjects(Find_Func("IsLiquid"), Find_Container(into)))
{
if (MergeWith(other_liquid))
{
return true; // Cannot enter
}
}
return false; // Enter this object
}
else
{
return true; // Cannot enter
var exists = this;
var transferred = into->PutLiquid(IsLiquid(), GetLiquidAmount(), this);
if (exists) DoLiquidAmount(-transferred);
}
return true; // Cannot enter
}
// Tell the interaction menu as how many objects this object should be displayed
@ -158,17 +150,6 @@ func DoLiquidAmount(int change)
UpdateLiquidObject();
}
func MergeWith(object liquid_object)
{
if (WildcardMatch(IsLiquid(), liquid_object->~IsLiquid()))
{
var transferred = liquid_object->PutLiquid(IsLiquid(), GetLiquidAmount(), this);
DoLiquidAmount(-transferred);
return true;
}
return false;
}
// -------------- Status updates
//

View File

@ -219,14 +219,3 @@ func SetLiquidContainer(string liquid_name, int amount)
SetLiquidType(liquid_name);
SetLiquidFillLevel(amount);
}
func Collection2(object item)
{
if (item->~IsLiquid() && !GetLiquidItem())
{
SetLiquidItem(item);
}
_inherited(...);
}

View File

@ -717,9 +717,9 @@ global func Test12_Execute()
liquid->Enter(container);
var passed = true;
var returned = liquid->Contained();
var test = (returned == container); passed &= test;
Log("- Liquid can enter empty barrel: %v", test);
var returned = liquid;
var test = (returned == nil); passed &= test;
Log("- Liquid can fill empty barrel: %v", test);
returned = container->GetLiquidFillLevel();
test = (100 == returned); passed &= test;
Log("- Barrel contains %d units, expected %d: %v", returned, 100, test);
@ -729,7 +729,7 @@ global func Test12_Execute()
liquid->SetLiquidAmount(100);
liquid->Enter(container);
var returned = liquid;
returned = liquid;
var test = (returned == nil); passed &= test;
Log("- Liquid can enter filled barrel, liquid got removed: %v", test);
returned = container->GetLiquidFillLevel();
@ -741,15 +741,18 @@ global func Test12_Execute()
liquid->SetLiquidAmount(200);
liquid->Enter(container);
var returned = liquid->Contained();
returned = liquid->Contained();
var test = (returned == nil); passed &= test;
Log("- Liquid cannot enter filled barrel if the capacity is exceeded: %v", test);
returned = container->GetLiquidFillLevel();
test = (300 == returned); passed &= test;
Log("- Barrel does increase fill level, up to the allowed amount, contains %d units, expected %d: %v", returned, 300, test);
returned = liquid->GetLiquidAmount();
test = (100 == returned); passed &= test;
Log("- Liquid object still contains %d units, expected %d: %v", returned, 100, test);
Log("- Resetting liquid amount to 200");
liquid->RemoveObject();
Log("- Retting liquid amount to 200");
container->SetLiquidFillLevel(200);
// cannot fill in a different liquid