forked from Mirrors/openclonk
add rule to control pump speed
parent
4c7d27ec64
commit
18424aaaa7
|
@ -0,0 +1,7 @@
|
|||
[DefCore]
|
||||
id=Rule_FastPump
|
||||
Version=8,0
|
||||
Category=C4D_StaticBack|C4D_Rule
|
||||
Width=32
|
||||
Height=32
|
||||
Offset=-16,-16
|
Binary file not shown.
After Width: | Height: | Size: 18 KiB |
|
@ -0,0 +1,81 @@
|
|||
/**
|
||||
Fast Pump
|
||||
If this rule is activate, pumps will pump with an alternative speed.
|
||||
This speed can be set in the rule.
|
||||
|
||||
@author Maikel
|
||||
*/
|
||||
|
||||
|
||||
local pump_speed = 50;
|
||||
|
||||
public func Initialize()
|
||||
{
|
||||
// Don't do anything if this is not the first rule of this type.
|
||||
if (ObjectCount(Find_ID(Rule_FastPump)) > 1)
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
public func Destruction()
|
||||
{
|
||||
// If this is not the last copy of this rule do nothing.
|
||||
if (ObjectCount(Find_ID(Rule_FastPump)) > 1)
|
||||
return;
|
||||
|
||||
// Reset the pump speed of all pumps.
|
||||
for (var pump in FindObjects(Find_ID(Pump)))
|
||||
pump.PumpSpeed = Pump.PumpSpeed;
|
||||
return;
|
||||
}
|
||||
|
||||
public func OnPumpCreation(object pump)
|
||||
{
|
||||
if (pump_speed != nil)
|
||||
pump.PumpSpeed = pump_speed;
|
||||
return;
|
||||
}
|
||||
|
||||
public func SetPumpSpeed(int speed)
|
||||
{
|
||||
pump_speed = speed ?? Pump.PumpSpeed;
|
||||
pump_speed = Max(0, pump_speed);
|
||||
// Adjust the pump speed of existing pumps.
|
||||
for (var pump in FindObjects(Find_ID(Pump)))
|
||||
pump.PumpSpeed = pump_speed;
|
||||
return;
|
||||
}
|
||||
|
||||
public func GetPumpSpeed() { return pump_speed; }
|
||||
|
||||
public func Activate(int plr)
|
||||
{
|
||||
MessageWindow(this.Description, plr);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Scenario saving.
|
||||
public func SaveScenarioObject(proplist props)
|
||||
{
|
||||
if (!inherited(props, ...)) return false;
|
||||
if (pump_speed != nil)
|
||||
props->AddCall("PumpSpeed", this, "SetPumpSpeed", pump_speed);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Editor properties.
|
||||
public func Definition(proplist def)
|
||||
{
|
||||
if (!def.EditorProps)
|
||||
def.EditorProps = {};
|
||||
def.EditorProps.pump_speed = {Name="$EditorPropPumpSpeed$", Type="int", Min = 0, Step = 10};
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/*-- Properties --*/
|
||||
|
||||
local Name = "$Name$";
|
||||
local Description = "$Description$";
|
||||
local Visibility = VIS_Editor;
|
||||
local EditorPlacementLimit = 1; // Rules are to be placed only once
|
|
@ -0,0 +1,3 @@
|
|||
Name=Schnelle Pumpe
|
||||
Description=Pumpen haben eine alternative Pump-Geschwindigkeit (meistens schneller).
|
||||
EditorPropPumpSpeed=Pump-Geschwindigkeit
|
|
@ -0,0 +1,3 @@
|
|||
Name=Fast Pump
|
||||
Description=Pumps have an alternative pumping speed (usually faster).
|
||||
EditorPropPumpSpeed=Pump speed
|
|
@ -57,6 +57,9 @@ func Initialize()
|
|||
var end = GetAnimationLength("pump");
|
||||
animation = PlayAnimation("pump", 5, Anim_Linear(GetAnimationPosition(animation), start, end, 35, ANIM_Loop));
|
||||
SetState("Wait");
|
||||
// Let the fast pump rule know it has been created.
|
||||
for (var rule in FindObjects(Find_ID(Rule_FastPump)))
|
||||
rule->~OnPumpCreation(this);
|
||||
return _inherited(...);
|
||||
}
|
||||
|
||||
|
@ -295,12 +298,6 @@ private func GetSourceObject()
|
|||
return this;
|
||||
}
|
||||
|
||||
/** Returns amount of pixels to pump per 30 frames */
|
||||
public func GetPumpSpeed()
|
||||
{
|
||||
return 50;
|
||||
}
|
||||
|
||||
/** PhaseCall of Pump: Pump the liquid from the source to the drain pipe */
|
||||
protected func Pumping()
|
||||
{
|
||||
|
@ -327,7 +324,7 @@ protected func Pumping()
|
|||
{
|
||||
// get new materials
|
||||
var source_obj = GetSourceObject();
|
||||
var mat = this->ExtractMaterialFromSource(source_obj, GetPumpSpeed() / 10);
|
||||
var mat = this->ExtractMaterialFromSource(source_obj, this.PumpSpeed / 10);
|
||||
|
||||
// no material to pump?
|
||||
if (mat)
|
||||
|
@ -747,3 +744,5 @@ local Description = "$Description$";
|
|||
local BlastIncinerate = 50;
|
||||
local HitPoints = 70;
|
||||
local Components = {Wood = 1, Metal = 3};
|
||||
// Pump speed in amount of pixels to pump per 30 frames.
|
||||
local PumpSpeed = 50;
|
||||
|
|
|
@ -19,6 +19,10 @@ protected func Initialize()
|
|||
goal.Name = "$MsgGoalName$";
|
||||
goal.Description = "$MsgGoalDescription$";
|
||||
|
||||
// Rules: make the pump faster.
|
||||
var rule = CreateObject(Rule_FastPump);
|
||||
rule->SetPumpSpeed(4 * Pump.PumpSpeed);
|
||||
|
||||
// Place objects in different sections.
|
||||
InitVillage();
|
||||
InitMines();
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
// Make the pump a bit faster.
|
||||
|
||||
#appendto Pump
|
||||
|
||||
public func GetPumpSpeed()
|
||||
{
|
||||
// Four times faster.
|
||||
return 4 * _inherited(...);
|
||||
}
|
Loading…
Reference in New Issue