fix support for multiple liquids in liquid containers

ipv6
Maikel de Vries 2016-12-25 12:48:15 +01:00
parent 0d0a61d4b0
commit 135a7d8aff
6 changed files with 85 additions and 88 deletions

View File

@ -93,7 +93,7 @@ public func RejectStack(object item)
}
}
public func GetLiquidContainerMaxFillLevel()
public func GetLiquidContainerMaxFillLevel(liquid_name)
{
return 300;
}
@ -173,7 +173,7 @@ func FillWithLiquid()
var remaining_volume = GetLiquidContainerMaxFillLevel() - GetLiquidAmount();
var extracted = 0;
while(extracted < remaining_volume && GetMaterial(0, intake) == mat)
while (extracted < remaining_volume && GetMaterial(0, intake) == mat)
{
extracted += 1;
ExtractLiquid(0, intake);

View File

@ -1,33 +1,33 @@
/**
* Liquid
*
* Basic interface for liquids. The logic for adding and removing liquid,
* PutLiquid() and RemoveLiquid() is deliberately the same as in the
* liquid container, so that scripts can be read more easily.
*
* Author: Marky
*/
Liquid
Basic interface for liquids. The logic for adding and removing liquid,
PutLiquid() and RemoveLiquid() is deliberately the same as in the
liquid container, so that scripts can be read more easily.
@author Marky
*/
#include Library_Stackable
func IsLiquid() { return true; }
func InitialStackCount(){ return 1; }
func MaxStackCount()
public func IsLiquid() { return true; }
public func InitialStackCount(){ return 1; }
public func MaxStackCount()
{
if (this)
{
if (Contained() && Contained()->~IsLiquidContainer() && Contained()->~GetLiquidContainerMaxFillLevel() > 0)
if (Contained() && Contained()->~IsLiquidContainer() && Contained()->~GetLiquidContainerMaxFillLevel(GetID()) > 0)
{
// Stack limit is: [what is already inside the stack] + [free space in the container].
return GetLiquidAmount() + Contained()->~GetLiquidAmountRemaining();
return GetLiquidAmount() + Contained()->~GetLiquidAmountRemaining(GetID());
}
}
return Stackable_Max_Count;
}
func Construction()
public func Construction()
{
TriggerDispersion();
return _inherited(...);
@ -40,7 +40,7 @@ func Construction()
//
// naming scheme: GetLiquid[attribute], because it concerns the liquid
func GetLiquidType()
public func GetLiquidType()
{
return "undefined";
}
@ -52,20 +52,20 @@ public func GetLiquidMaterial()
return this->GetLiquidType();
}
func GetLiquidAmount()
public func GetLiquidAmount()
{
return GetStackCount();
}
// -------------- Dispersion
func Departure(object container)
public func Departure(object container)
{
TriggerDispersion();
_inherited(container, ...);
}
func TriggerDispersion()
public func TriggerDispersion()
{
var fx = GetEffect("IntLiquidDispersion", this);
if (!fx)
@ -74,7 +74,7 @@ func TriggerDispersion()
}
}
func FxIntLiquidDispersionTimer(object target, proplist fx, int timer)
public func FxIntLiquidDispersionTimer(object target, proplist fx, int timer)
{
if (!target->Contained())
{
@ -83,13 +83,13 @@ func FxIntLiquidDispersionTimer(object target, proplist fx, int timer)
return FX_Execute_Kill;
}
func Disperse(int angle, int strength)
public func Disperse(int angle, int strength)
{
// does nothing but remove the object (unless it's an infinite stack) - overload if you want special effects
if (!IsInfiniteStackCount()) RemoveObject();
}
func DisperseMaterial(string material_name, int amount, int strength, int angle, int angle_variance)
public func DisperseMaterial(string material_name, int amount, int strength, int angle, int angle_variance)
{
angle = angle ?? 0;
strength = strength ?? 30;
@ -98,7 +98,7 @@ func DisperseMaterial(string material_name, int amount, int strength, int angle,
CastPXS(material_name, amount, strength, 0, 0, angle, 30);
}
func DisperseParticles(string particle_name, int amount, int strength, int angle, int angle_variance, proplist template, int lifetime)
public func DisperseParticles(string particle_name, int amount, int strength, int angle, int angle_variance, proplist template, int lifetime)
{
angle = angle ?? 0;
strength = strength ?? 30;
@ -121,13 +121,13 @@ func DisperseParticles(string particle_name, int amount, int strength, int angle
// -------------- Status
func UpdateName()
public func UpdateName()
{
var container = Contained();
if (container && container->~IsLiquidContainer())
{
SetName(Format("%d/%d %s", GetLiquidAmount(), container->GetLiquidContainerMaxFillLevel(), GetID()->GetName()));
SetName(Format("%d/%d %s", GetLiquidAmount(), container->GetLiquidContainerMaxFillLevel(GetID()), GetID()->GetName()));
}
else
{
@ -138,7 +138,7 @@ func UpdateName()
// 1000 liquid items count as 1 mass unit
// this may have to be tuned or made object-specific?
func UpdateMass()
public func UpdateMass()
{
SetMass(GetID()->GetMass() * Max(1, GetLiquidAmount()) / 1000);
}
@ -146,7 +146,7 @@ func UpdateMass()
// 1000 liquid items count as 1 wealth unit
// this may have to be tuned or made object-specific?
func CalcValue(object in_base, int for_plr)
public func CalcValue(object in_base, int for_plr)
{
return GetID()->GetValue() * Max(1, GetLiquidAmount()) / 1000;
}
@ -166,7 +166,7 @@ Inserts liquid into the object.
@param source: Object which inserts the liquid
@return returned_amount: The inserted amount
*/
func PutLiquid(liquid_name, int amount, object source)
public func PutLiquid(liquid_name, int amount, object source)
{
amount = amount ?? 0;
@ -205,7 +205,7 @@ Extracts liquid from the object.
- returned_liquid: Material being extracted
- returned_amount: Amount being extracted
*/
func RemoveLiquid(liquid_name, int amount, object destination)
public func RemoveLiquid(liquid_name, int amount, object destination)
{
if (amount < 0)
{
@ -237,7 +237,7 @@ func RemoveLiquid(liquid_name, int amount, object destination)
and amount. Liquids with amount 0 can be created
that way.
*/
func CreateLiquid(int amount, object in_container)
public func CreateLiquid(int amount, object in_container)
{
if (GetType(this) != C4V_Def)
{

View File

@ -1,62 +1,60 @@
/**
* Liquid Container
*
* Basic interface for anything that can contain liquids.
*
* Author: Marky
*/
Liquid Container
Basic interface for anything that can contain liquids.
@author Marky
*/
func IsLiquidContainer() { return true;}
public func IsLiquidContainer() { return true; }
func GetLiquidContainerMaxFillLevel()
public func GetLiquidContainerMaxFillLevel(liquid_name)
{
return 0;
}
func IsLiquidContainerForMaterial(string liquid_name)
public func IsLiquidContainerForMaterial(string liquid_name)
{
return true;
}
func GetLiquidAmount(liquid_name)
public func GetLiquidAmount(liquid_name)
{
var amount = 0;
var type = nil;
// in case that a value was supplied, try finding the type for that
// In case that a value was supplied, try finding the type for that.
if (liquid_name != nil)
{
type = GetLiquidDef(liquid_name);
if (type == nil) FatalError(Format("No such liquid: %s", liquid_name));
if (type == nil)
FatalError(Format("GetLiquidAmount(%s): No such liquid.", liquid_name));
}
// return everything if 'nil' was passed, or a specific amount if a value was passed
// Return everything if 'nil' was passed, or a specific amount if a value was passed.
for (var liquid in GetLiquidContents())
if (liquid_name == nil || liquid->GetLiquidType() == type->GetLiquidType())
{
amount += liquid->~GetLiquidAmount();
if (liquid_name == nil || liquid->GetLiquidType() == type->GetLiquidType())
amount += liquid->~GetLiquidAmount();
}
return amount;
}
func GetLiquidAmountRemaining()
public func GetLiquidAmountRemaining(liquid_name)
{
return GetLiquidContainerMaxFillLevel() - GetLiquidAmount();
return GetLiquidContainerMaxFillLevel(liquid_name) - GetLiquidAmount(liquid_name);
}
func GetLiquidContents()
public func GetLiquidContents()
{
return FindObjects(Find_Container(this), Find_Func("IsLiquid"));
}
// -------------- Interaction
//
// Interfaces for interaction with other objects
/*-- Interaction --*/
// Returns whether this container has any of the requested liquid and returns that liquid.
// If liquid_name == nil it returns the first liquid found.
// If liquids == nil it returns the first liquid found.
public func HasLiquid(array liquids)
{
for (var liquid in GetLiquidContents())
@ -84,7 +82,7 @@ Extracts liquid from the container.
- returned_liquid: Material being extracted
- returned_amount: Amount being extracted
*/
func RemoveLiquid(liquid_name, int amount, object destination)
public func RemoveLiquid(liquid_name, int amount, object destination)
{
if (amount < 0)
{
@ -116,7 +114,7 @@ Inserts liquid into the container.
@param source: Object which inserts the liquid [optional]
@return returned_amount: The inserted amount
*/
func PutLiquid(liquid_name, int amount, object source)
public func PutLiquid(liquid_name, int amount, object source)
{
amount = amount ?? this->GetLiquidAmountRemaining();
@ -127,7 +125,7 @@ func PutLiquid(liquid_name, int amount, object source)
var type = GetLiquidDef(liquid_name);
var max = this->GetLiquidContainerMaxFillLevel();
var max = this->GetLiquidContainerMaxFillLevel(liquid_name);
var before = GetLiquidAmount(liquid_name);
if (max > 0 && before >= max) return 0;
@ -144,23 +142,17 @@ func PutLiquid(liquid_name, int amount, object source)
return after - before;
}
func AcceptsLiquid(liquid_name, int amount)
public func AcceptsLiquid(liquid_name, int amount)
{
return amount <= this->GetLiquidContainerMaxFillLevel() - GetLiquidAmount(liquid_name);
return amount <= this->GetLiquidContainerMaxFillLevel(liquid_name) - GetLiquidAmount(liquid_name);
}
private 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
{
FatalError(Format("The first parameter of GetLiquidDef() must either be a string or definition. You passed %v.", liquid_name));
}
FatalError(Format("The first parameter of GetLiquidDef() must either be a string or definition. You passed %v.", liquid_name));
return nil;
}

View File

@ -1,16 +1,15 @@
/* --- Tank ---
/**
Liquid Tank
A structure that can contain liquids. Connecting pipes to the
structure can be allowed, but this has to be implemented by the
object.
This is controlled with the callbacks
- QueryConnectPipe
- OnPipeConnect
- OnPipeDisconnect
object. This is controlled with the callbacks
- QueryConnectPipe
- OnPipeConnect
- OnPipeDisconnect
in that structure.
Author: Marky
*/
@author Marky
*/
#include Library_LiquidContainer
@ -27,7 +26,8 @@ static const LIBRARY_TANK_Menu_Action_Description = "description";
local lib_tank; // proplist for local variables
/* ---------- Callbacks ---------- */
/*-- Callbacks --*/
public func Construction()
{
@ -49,7 +49,8 @@ public func Construction()
public func IsLiquidTank() { return true; }
/* ---------- Menu Entries ---------- */
/*-- Menu Entries --*/
public func GetInteractionMenus(object clonk)
{
@ -160,7 +161,7 @@ public func OnPipeControl(symbol_or_object, string action, bool alt)
}
/* ---------- Handle connections ---------- */
/*-- Handle Connections --*/
public func GetDrainPipe() { return lib_tank.drain_pipe;}
public func GetSourcePipe() { return lib_tank.source_pipe;}
@ -185,7 +186,7 @@ public func SetNeutralPipe(object neutral_pipe)
}
/* ---------- Menu callbacks ---------- */
/*-- Menu Callbacks --*/
public func DoConnectPipe(object pipe, string specific_pipe_state)
{
@ -219,7 +220,8 @@ public func FindAvailablePipe(object container, find_state)
return nil;
}
/* ---------- Pipe callbacks ---------- */
/*-- Pipe Callbacks --*/
public func CanConnectPipe(){ return true;}
@ -231,6 +233,7 @@ public func OnPipeDisconnect(object pipe)
if (pipe == GetNeutralPipe()) SetNeutralPipe();
}
/*-- Scenario Saving --*/
public func SaveScenarioObject(props)

View File

@ -130,6 +130,13 @@ public func IsLiquidContainerForMaterial(string liquid)
return WildcardMatch("Oil", liquid) || WildcardMatch("Water", liquid) || WildcardMatch("Concrete", liquid);
}
public func GetLiquidContainerMaxFillLevel(liquid_name)
{
if (GetLiquidDef(liquid_name) == Water)
return 600;
return 300;
}
// The foundry may have one drain and one source.
public func QueryConnectPipe(object pipe)
{
@ -179,11 +186,6 @@ public func OnPipeConnect(object pipe, string specific_pipe_state)
pipe->Report("$MsgConnectedPipe$");
}
public func GetLiquidContainerMaxFillLevel()
{
return 300;
}
/*-- Properties --*/

View File

@ -192,7 +192,7 @@ public func IsLiquidContainerForMaterial(string liquid)
return WildcardMatch("Oil", liquid);
}
public func GetLiquidContainerMaxFillLevel()
public func GetLiquidContainerMaxFillLevel(liquid_name)
{
return 300;
}