forked from Mirrors/openclonk
Refactoring: Liquids: Removed GetLiquidID() and changed CreateLiquid()
CreateLiquid() can be called from definition context now, to create a certain amount of liquid.liquid_container
parent
1c1ea38efa
commit
52542d7977
|
@ -28,7 +28,11 @@ func MaxStackCount()
|
|||
return Stackable_Max_Count;
|
||||
}
|
||||
|
||||
|
||||
func Construction()
|
||||
{
|
||||
TriggerDispersion();
|
||||
return _inherited(...);
|
||||
}
|
||||
|
||||
// -------------- Getters
|
||||
//
|
||||
|
@ -50,13 +54,18 @@ func GetLiquidAmount()
|
|||
// -------------- Dispersion
|
||||
|
||||
func Departure(object container)
|
||||
{
|
||||
TriggerDispersion();
|
||||
_inherited(...);
|
||||
}
|
||||
|
||||
func TriggerDispersion()
|
||||
{
|
||||
var fx = GetEffect(FX_LIQUID_Dispersion, this);
|
||||
if (!fx)
|
||||
{
|
||||
AddEffect(FX_LIQUID_Dispersion, this, 1, 1, this);
|
||||
}
|
||||
_inherited(...);
|
||||
}
|
||||
|
||||
func FxIntLiquidDispersionTimer(object target, proplist fx, int timer)
|
||||
|
@ -202,31 +211,19 @@ func RemoveLiquid(string liquid_name, int amount, object destination)
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
Converts a liquid name to a definition
|
||||
that represents that liquid.
|
||||
@par liquid_name the name of the liquid
|
||||
@return the Id of the liquid object,
|
||||
or nil if no such object exists
|
||||
*/
|
||||
func GetLiquidID(string liquid_name)
|
||||
{
|
||||
if (liquid_name == "Acid") return Acid;
|
||||
if (liquid_name == "Lava") return Lava;
|
||||
if (liquid_name == "Oil") return Oil;
|
||||
if (liquid_name == "Water") return Water;
|
||||
return Library_Liquid;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Creates a liquid object with the specified name
|
||||
and amount. Liquids with amount 0 can be created
|
||||
that way.
|
||||
*/
|
||||
func CreateLiquid(string liquid_name, int amount)
|
||||
func CreateLiquid(int amount)
|
||||
{
|
||||
var item = CreateObject(GetLiquidID(liquid_name));
|
||||
if (GetType(this) != C4V_Def)
|
||||
{
|
||||
FatalError("Must be called from definition context!");
|
||||
}
|
||||
|
||||
var item = CreateObject(this);
|
||||
item->SetStackCount(amount);
|
||||
return item;
|
||||
}
|
||||
|
|
|
@ -98,13 +98,11 @@ func PutLiquid(string liquid_name, int amount, object source)
|
|||
var before = GetLiquidAmount(liquid_name);
|
||||
if (before >= this->GetLiquidContainerMaxFillLevel()) return 0;
|
||||
|
||||
var type = Library_Liquid->GetLiquidID(liquid_name);
|
||||
var liquid = CreateObject(type);
|
||||
|
||||
if (liquid)
|
||||
var type = GetDefinition(liquid_name);
|
||||
if (type)
|
||||
{
|
||||
liquid->SetStackCount(amount);
|
||||
Collect(liquid, true);
|
||||
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
|
||||
// has a stack inside
|
||||
if (liquid && !(liquid->Contained())) liquid->RemoveObject();
|
||||
|
|
|
@ -866,8 +866,8 @@ public func RejectCollect(id item_id, object item)
|
|||
// TODO
|
||||
private func ConvertToLiquid(object obj)
|
||||
{
|
||||
var liquid = Library_Liquid->CreateLiquid(obj->CanConvertToLiquidType(), obj->GetLiquidAmount());
|
||||
|
||||
var liquid = GetDefinition(obj->CanConvertToLiquidType())->CreateLiquid(obj->GetLiquidAmount());
|
||||
|
||||
if (liquid)
|
||||
{
|
||||
liquid->Enter(this);
|
||||
|
|
Loading…
Reference in New Issue