forked from Mirrors/openclonk
Refactoring: Renamed Set/GetLiquidName to Set/GetLiquidType
parent
9a8c3f4fea
commit
6f557520e8
|
@ -31,7 +31,7 @@ private func Hit()
|
|||
if (!LiquidContainerIsEmpty())
|
||||
{
|
||||
if (GBackLiquid(0, this->GetBarrelIntakeY())
|
||||
&& GetMaterial(0, this->GetBarrelIntakeY()) != GetLiquidName())
|
||||
&& GetMaterial(0, this->GetBarrelIntakeY()) != GetLiquidType())
|
||||
return;
|
||||
|
||||
EmptyBarrel(GetR());
|
||||
|
@ -115,16 +115,16 @@ private func UpdateLiquidContainer()
|
|||
else
|
||||
{
|
||||
var liquid_name, color;
|
||||
var material = Material(GetLiquidName());
|
||||
var material = Material(GetLiquidType());
|
||||
if (material >= 0)
|
||||
{
|
||||
var liquid_name = Translate(Format("Material%s", GetLiquidName()));
|
||||
var liquid_name = Translate(Format("Material%s", GetLiquidType()));
|
||||
var tex = GetMaterialVal("TextureOverlay", "Material", material);
|
||||
color = GetAverageTextureColor(tex);
|
||||
}
|
||||
else
|
||||
{
|
||||
liquid_name = GetLiquidName();
|
||||
liquid_name = GetLiquidType();
|
||||
color = RGB(0, 0, 0);
|
||||
}
|
||||
SetColor(color);
|
||||
|
@ -210,7 +210,7 @@ public func CalcValue(object in_base, int for_player)
|
|||
var val = GetDefValue();
|
||||
if (!LiquidContainerIsEmpty())
|
||||
{
|
||||
val += GetValueOf(GetLiquidName()) * GetLiquidFillLevel() / GetLiquidContainerMaxFillLevel();
|
||||
val += GetValueOf(GetLiquidType()) * GetLiquidFillLevel() / GetLiquidContainerMaxFillLevel();
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ public func LiquidOutput(string sznMaterial, int inMaxAmount, object pnPump, obj
|
|||
var ptBarrel = FindObject(Find_Container(this), Find_Func("IsBarrel"), Find_Func("IsLiquidContainerForMaterial", sznMaterial), Find_Not(Find_Func("LiquidContainerIsEmpty")));
|
||||
var sztMaterial="";
|
||||
if (ptBarrel)
|
||||
sztMaterial = ptBarrel->GetLiquidName();
|
||||
sztMaterial = ptBarrel->GetLiquidType();
|
||||
//Nothing to pump
|
||||
if (sztMaterial == "")
|
||||
return ["", 0];
|
||||
|
|
|
@ -47,7 +47,7 @@ func LiquidContainerIsFull()
|
|||
func LiquidContainerAccepts(string liquid_name)
|
||||
{
|
||||
return IsLiquidContainerForMaterial(liquid_name)
|
||||
&& (LiquidContainerIsEmpty() || GetLiquidName() == liquid_name);
|
||||
&& (LiquidContainerIsEmpty() || GetLiquidType() == liquid_name);
|
||||
}
|
||||
|
||||
// -------------- Getters
|
||||
|
@ -57,7 +57,7 @@ func LiquidContainerAccepts(string liquid_name)
|
|||
//
|
||||
// naming scheme: GetLiquid[attribute], because it concerns the liquid
|
||||
|
||||
func GetLiquidName()
|
||||
func GetLiquidType()
|
||||
{
|
||||
//if (LiquidContainerIsEmpty())
|
||||
// return nil; // TODO: was "", this was inconsistent throughout the barrel
|
||||
|
@ -76,7 +76,7 @@ func GetLiquidFillLevel()
|
|||
//
|
||||
// naming scheme: SetLiquid[attribute], because it concerns the liquid
|
||||
|
||||
func SetLiquidName(string liquid_name)
|
||||
func SetLiquidType(string liquid_name)
|
||||
{
|
||||
lib_liquid_container.liquid = liquid_name;
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ func ChangeLiquidFillLevel(int amount)
|
|||
// Empty the liquid container
|
||||
if (LiquidContainerIsEmpty())
|
||||
{
|
||||
SetLiquidName(nil);
|
||||
SetLiquidType(nil);
|
||||
}
|
||||
|
||||
this->UpdateLiquidContainer();
|
||||
|
@ -122,15 +122,15 @@ func RemoveLiquid(string liquid_name, int amount, object destination)
|
|||
}
|
||||
|
||||
// default parameters if nothing is provided: the current material and level
|
||||
liquid_name = liquid_name ?? GetLiquidName();
|
||||
liquid_name = liquid_name ?? GetLiquidType();
|
||||
amount = amount ?? GetLiquidFillLevel();
|
||||
|
||||
//Wrong material?
|
||||
if (!WildcardMatch(GetLiquidName(), liquid_name))
|
||||
if (!WildcardMatch(GetLiquidType(), liquid_name))
|
||||
amount = 0;
|
||||
amount = Min(amount, GetLiquidFillLevel());
|
||||
ChangeLiquidFillLevel(-amount);
|
||||
return [GetLiquidName(), amount];
|
||||
return [GetLiquidType(), amount];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -149,7 +149,7 @@ func PutLiquid(string liquid_name, int amount, object source)
|
|||
|
||||
if (LiquidContainerAccepts(liquid_name))
|
||||
{
|
||||
SetLiquidName(liquid_name);
|
||||
SetLiquidType(liquid_name);
|
||||
amount = BoundBy(GetLiquidContainerMaxFillLevel() - GetLiquidFillLevel(), 0, amount);
|
||||
ChangeLiquidFillLevel(+amount);
|
||||
return amount;
|
||||
|
@ -175,15 +175,15 @@ func Construction()
|
|||
func SaveScenarioObject(props)
|
||||
{
|
||||
if (!inherited(props, ...)) return false;
|
||||
if (GetLiquidName())
|
||||
props->AddCall("Fill", this, "SetLiquidContainer", Format("%v", GetLiquidName()), GetLiquidFillLevel());
|
||||
if (GetLiquidType())
|
||||
props->AddCall("Fill", this, "SetLiquidContainer", Format("%v", GetLiquidType()), GetLiquidFillLevel());
|
||||
return true;
|
||||
}
|
||||
|
||||
// set the current state, without sanity checks
|
||||
func SetLiquidContainer(string liquid_name, int amount)
|
||||
{
|
||||
SetLiquidName(liquid_name);
|
||||
SetLiquidType(liquid_name);
|
||||
SetLiquidFillLevel(amount);
|
||||
}
|
||||
|
||||
|
|
|
@ -605,7 +605,7 @@ public func CheckLiquids(id product, bool remove)
|
|||
var need = liq_need[1];
|
||||
// Find liquid containers in this producer.
|
||||
for (var liq_container in FindObjects(Find_Container(this), Find_Func("IsLiquidContainer")))
|
||||
if (liq_container->~GetLiquidName() == liquid)
|
||||
if (liq_container->~GetLiquidType() == liquid)
|
||||
liquid_amount += liq_container->~GetLiquidFillLevel();
|
||||
// Find objects that "are" liquid (e.g. ice)
|
||||
for (var liq_object in FindObjects(Find_Container(this), Find_Func("IsLiquid")))
|
||||
|
|
|
@ -176,7 +176,7 @@ global func Test3_OnStart(int plr){ return true;}
|
|||
global func Test3_OnFinish(){ return; }
|
||||
global func Test3_Execute()
|
||||
{
|
||||
Log("Test the behaviour of GetLiquidName and SetLiquidName");
|
||||
Log("Test the behaviour of GetLiquidType and SetLiquidType");
|
||||
|
||||
var container = CreateObject(Barrel);
|
||||
var passed = true;
|
||||
|
@ -184,8 +184,8 @@ global func Test3_Execute()
|
|||
|
||||
for (var value in test_data)
|
||||
{
|
||||
container->SetLiquidName(value);
|
||||
var returned = container->GetLiquidName();
|
||||
container->SetLiquidType(value);
|
||||
var returned = container->GetLiquidType();
|
||||
var test = (value == returned); passed &= test;
|
||||
Log("- Container returns %s if liquid name is set to %s, values should be equal", returned, value);
|
||||
}
|
||||
|
@ -268,7 +268,7 @@ global func Test6_Execute()
|
|||
|
||||
// fill level
|
||||
|
||||
//container->SetLiquidName("Water");
|
||||
//container->SetLiquidType("Water");
|
||||
container->SetLiquidFillLevel(0);
|
||||
test = container->LiquidContainerAccepts("Water"); passed &= test;
|
||||
Log("- Container returns 'true' if liquid fill level is 0% and material is ok: %v", test);
|
||||
|
@ -286,21 +286,21 @@ global func Test6_Execute()
|
|||
|
||||
// material
|
||||
Log("Setting container to be filled with a material");
|
||||
container->SetLiquidName("Lava");
|
||||
Log("- Fill material is %s", container->GetLiquidName());
|
||||
container->SetLiquidType("Lava");
|
||||
Log("- Fill material is %s", container->GetLiquidType());
|
||||
|
||||
container->SetLiquidFillLevel(0);
|
||||
container->SetLiquidName("Lava");
|
||||
container->SetLiquidType("Lava");
|
||||
test = container->LiquidContainerAccepts("Water"); passed &= test;
|
||||
Log("- Container returns 'true' if filled with material and liquid fill level is 0% and other material is ok: %v", test);
|
||||
|
||||
container->SetLiquidFillLevel(container->GetLiquidContainerMaxFillLevel() / 2);
|
||||
container->SetLiquidName("Lava");
|
||||
container->SetLiquidType("Lava");
|
||||
test = !container->LiquidContainerAccepts("Water"); passed &= test;
|
||||
Log("- Container returns 'false' if filled with material and liquid fill level is 50% and other material is ok: %v", test);
|
||||
|
||||
container->SetLiquidFillLevel(container->GetLiquidContainerMaxFillLevel() / 2);
|
||||
container->SetLiquidName("Water");
|
||||
container->SetLiquidType("Water");
|
||||
test = container->LiquidContainerAccepts("Water"); passed &= test;
|
||||
// Log("-- Debug: %v", container->IsLiquidContainerForMaterial("Lava"));
|
||||
// Log("-- Debug: %v", container->LiquidContainerIsEmpty());
|
||||
|
@ -324,15 +324,15 @@ global func Test7_Execute()
|
|||
var test = (container->PutLiquid("Lava", 1, nil) == 0);
|
||||
passed &= test;
|
||||
Log("- Container returns '0' when inserting 1 pixel of incompatible material: %v", test);
|
||||
test = container->GetLiquidName() == nil; passed &= test;
|
||||
Log("- Container returns 'nil' for material name: %v, %v", test, container->GetLiquidName());
|
||||
test = container->GetLiquidType() == nil; passed &= test;
|
||||
Log("- Container returns 'nil' for material name: %v, %v", test, container->GetLiquidType());
|
||||
test = container->GetLiquidFillLevel() == 0; passed &= test;
|
||||
Log("- Container returns '0' for fill level: %v", test);
|
||||
|
||||
// compatible material
|
||||
test = (container->PutLiquid("Water", 1, nil) == 1);
|
||||
Log("- Container returns '1' when inserting 1 pixel of compatible material: %v", test);
|
||||
test = container->GetLiquidName() == "Water"; passed &= test;
|
||||
test = container->GetLiquidType() == "Water"; passed &= test;
|
||||
Log("- Container returns the liquid name when inserting 1 pixel of compatible material: %v", test);
|
||||
test = container->GetLiquidFillLevel() == 1; passed &= test;
|
||||
Log("- Container returns the fill level when inserting 1 pixel of compatible material: %v", test);
|
||||
|
|
Loading…
Reference in New Issue