forked from Mirrors/openclonk
cable cars: let steam engine request coal when needed
parent
7178cf6a0a
commit
a70ab8b843
|
@ -39,8 +39,9 @@ public func DestinationsUpdated()
|
|||
{
|
||||
// Do nothing if set manually
|
||||
if (manual_setting) return;
|
||||
|
||||
if (GetLength(FindObjects(Find_Func("IsConnectedTo", this))) == 1)
|
||||
|
||||
var is_endpoint = GetLength(FindObjects(Find_Func("IsConnectedTo", this))) == 1;
|
||||
if (is_endpoint || connected_building)
|
||||
SetCableStation(true);
|
||||
else
|
||||
SetCableStation(false);
|
||||
|
@ -140,10 +141,12 @@ public func CombineWith(object stick_to)
|
|||
{
|
||||
if (!stick_to) return;
|
||||
|
||||
if (stick_to->~IsProducer())
|
||||
if (stick_to->~AcceptsCableStationConnection())
|
||||
{
|
||||
connected_building = stick_to;
|
||||
stick_to->ConnectCableStation(this);
|
||||
SetCableStation(true);
|
||||
CheckStationStatus();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -188,7 +191,8 @@ public func GetSettingsMenuEntries()
|
|||
var menu_entries = [];
|
||||
|
||||
// Clickable buttons.
|
||||
var station = new custom_entry {
|
||||
var station = new custom_entry
|
||||
{
|
||||
Priority = 1000,
|
||||
Tooltip = "$TooltipToggleStation$",
|
||||
OnClick = GuiAction_Call(this, "ToggleStation", false),
|
||||
|
@ -198,7 +202,8 @@ public func GetSettingsMenuEntries()
|
|||
station.image.GraphicsName = "Station";
|
||||
PushBack(menu_entries, { symbol = CableCrossing_Icons, extra_data = "Station", custom = station });
|
||||
|
||||
var drop_off = new custom_entry {
|
||||
var drop_off = new custom_entry
|
||||
{
|
||||
Priority = 1001,
|
||||
Tooltip = "$TooltipToggleDropOff$",
|
||||
OnClick = GuiAction_Call(this, "ToggleDropOff", false),
|
||||
|
|
|
@ -815,6 +815,8 @@ public func OnProductEjection(object product)
|
|||
|
||||
/*-- Cable Network --*/
|
||||
|
||||
public func AcceptsCableStationConnection() { return true; }
|
||||
|
||||
public func IsNoCableStationConnected() { return !cable_station; }
|
||||
|
||||
public func ConnectCableStation(object station)
|
||||
|
@ -847,8 +849,8 @@ public func RequestObject(id item_id, int amount)
|
|||
cable_station->AddRequest(item_id, amount);
|
||||
}
|
||||
|
||||
/*-- Storage --*/
|
||||
|
||||
/*-- Storage --*/
|
||||
|
||||
// Whether an object could enter this storage.
|
||||
public func IsCollectionAllowed(object item)
|
||||
|
|
|
@ -19,13 +19,16 @@ static const SteamEngine_produced_power = 120;
|
|||
|
||||
local fuel_amount;
|
||||
|
||||
// Possibly connected cable station
|
||||
local cable_station;
|
||||
|
||||
public func Construction()
|
||||
{
|
||||
SetAction("Default");
|
||||
return _inherited(...);
|
||||
}
|
||||
|
||||
protected func Initialize()
|
||||
public func Initialize()
|
||||
{
|
||||
fuel_amount = 0;
|
||||
AddTimer("ContentsCheck", 10);
|
||||
|
@ -37,7 +40,7 @@ public func IsHammerBuildable() { return true; }
|
|||
public func NoConstructionFlip() { return true; }
|
||||
public func IsContainer() { return true; }
|
||||
|
||||
protected func RejectCollect(id item, object obj)
|
||||
public func RejectCollect(id item, object obj)
|
||||
{
|
||||
// Accept fuel only
|
||||
if (obj->~IsFuel())
|
||||
|
@ -51,7 +54,7 @@ protected func RejectCollect(id item, object obj)
|
|||
return true;
|
||||
}
|
||||
|
||||
protected func Collection(object obj, bool put)
|
||||
public func Collection(object obj, bool put)
|
||||
{
|
||||
Sound("Objects::Clonk");
|
||||
}
|
||||
|
@ -112,17 +115,17 @@ public func OnPowerProductionStop(int amount)
|
|||
}
|
||||
|
||||
// Start call from working action.
|
||||
protected func WorkStart()
|
||||
public func WorkStart()
|
||||
{
|
||||
Sound("Structures::SteamEngine", {loop_count = 1});
|
||||
return;
|
||||
}
|
||||
|
||||
// Status?
|
||||
protected func IsWorking(){ return GetAction() == "Work";}
|
||||
public func IsWorking(){ return GetAction() == "Work";}
|
||||
|
||||
// Phase call from working action, every two frames.
|
||||
protected func Working()
|
||||
public func Working()
|
||||
{
|
||||
DoFuelAmount(-2); // Reduce the fuel amount by 1 per frame
|
||||
RefillFuel(); // Check if there is still enough fuel available.
|
||||
|
@ -133,26 +136,31 @@ protected func Working()
|
|||
SetAction("Default");
|
||||
UnregisterPowerProduction();
|
||||
}
|
||||
|
||||
// Request fuel from cable car network if there is not fuel object available.
|
||||
if (!GetFuelContents())
|
||||
RequestFuel();
|
||||
|
||||
Smoking(); // Smoke from the exhaust shaft.
|
||||
return;
|
||||
}
|
||||
|
||||
// Stop call from working action.
|
||||
protected func WorkStop()
|
||||
public func WorkStop()
|
||||
{
|
||||
// Don't kill the sound in this call, since that would interupt the sound effect.
|
||||
return;
|
||||
}
|
||||
|
||||
// Abort call from working action.
|
||||
protected func WorkAbort()
|
||||
public func WorkAbort()
|
||||
{
|
||||
// Sound can be safely stopped here since this action will always end with an abort call.
|
||||
Sound("Structures::SteamEngine", {loop_count = -1});
|
||||
return;
|
||||
}
|
||||
|
||||
func RefillFuel()
|
||||
public func RefillFuel()
|
||||
{
|
||||
// Check if there is still enough fuel available.
|
||||
var no_fuel = GetFuelAmount() <= 0;
|
||||
|
@ -167,24 +175,25 @@ func RefillFuel()
|
|||
if (fuel)
|
||||
{
|
||||
fuel_extracted = fuel->~GetFuelAmount();
|
||||
if (!fuel->~OnFuelRemoved(fuel_extracted)) fuel->RemoveObject();
|
||||
if (!fuel->~OnFuelRemoved(fuel_extracted))
|
||||
fuel->RemoveObject();
|
||||
|
||||
DoFuelAmount(fuel_extracted * 18);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func GetFuelContents()
|
||||
public func GetFuelContents()
|
||||
{
|
||||
return FindObject(Find_Container(this), Find_Func("IsFuel"));
|
||||
}
|
||||
|
||||
func DoFuelAmount(int amount)
|
||||
public func DoFuelAmount(int amount)
|
||||
{
|
||||
fuel_amount += amount;
|
||||
}
|
||||
|
||||
func Smoking()
|
||||
public func Smoking()
|
||||
{
|
||||
// Smoke from the exhaust shaft
|
||||
Smoke(-20 * GetCalcDir() + RandomX(-2, 2), -26, 10);
|
||||
|
@ -253,6 +262,25 @@ public func OnPipeConnect(object pipe, string specific_pipe_state)
|
|||
}
|
||||
|
||||
|
||||
/*-- Cable Network --*/
|
||||
|
||||
public func AcceptsCableStationConnection() { return true; }
|
||||
|
||||
public func IsNoCableStationConnected() { return !cable_station; }
|
||||
|
||||
public func ConnectCableStation(object station)
|
||||
{
|
||||
cable_station = station;
|
||||
}
|
||||
|
||||
public func RequestFuel()
|
||||
{
|
||||
// For now just request coal as it is the safest type of fuel, that is least needed by other structures.
|
||||
if (cable_station)
|
||||
cable_station->AddRequest(Coal, 1);
|
||||
}
|
||||
|
||||
|
||||
/*-- Properties --*/
|
||||
|
||||
local ActMap = {
|
||||
|
|
|
@ -57,7 +57,7 @@ protected func InitializePlayer(int plr)
|
|||
|
||||
// Add test control effect.
|
||||
var fx = AddEffect("IntTestControl", nil, 100, 2);
|
||||
fx.testnr = 1;
|
||||
fx.testnr = 9;
|
||||
fx.launched = false;
|
||||
fx.plr = plr;
|
||||
return;
|
||||
|
@ -169,6 +169,7 @@ global func Test1_OnStart(int plr)
|
|||
{
|
||||
SetWindFixed(50);
|
||||
CreateObjectAbove(WindGenerator, 90, 160, plr);
|
||||
CreateObjectAbove(Flagpole, 240, 64, plr);
|
||||
|
||||
var crossing1 = CreateObjectAbove(CableCrossing, 70, 160, plr);
|
||||
var crossing2 = CreateObjectAbove(CableCrossing, 216, 64, plr);
|
||||
|
@ -214,6 +215,7 @@ global func Test2_OnStart(int plr)
|
|||
SetWindFixed(50);
|
||||
CreateObjectAbove(WindGenerator, 90, 160, plr);
|
||||
CreateObjectAbove(WindGenerator, 440, 104, plr);
|
||||
CreateObjectAbove(Flagpole, 100, 160, plr);
|
||||
|
||||
var crossing1 = CreateObjectAbove(CableCrossing, 70, 160, plr);
|
||||
var crossing2 = CreateObjectAbove(CableCrossing, 216, 64, plr);
|
||||
|
@ -314,6 +316,7 @@ global func Test3_OnFinished()
|
|||
return;
|
||||
}
|
||||
|
||||
|
||||
global func Test4_OnStart(int plr)
|
||||
{
|
||||
SetWindFixed(50);
|
||||
|
@ -364,6 +367,7 @@ global func Test4_OnFinished()
|
|||
return;
|
||||
}
|
||||
|
||||
|
||||
global func Test5_OnStart(int plr)
|
||||
{
|
||||
SetWindFixed(50);
|
||||
|
@ -414,6 +418,7 @@ global func Test5_OnFinished()
|
|||
return;
|
||||
}
|
||||
|
||||
|
||||
global func Test6_OnStart(int plr)
|
||||
{
|
||||
SetWindFixed(80);
|
||||
|
@ -426,7 +431,12 @@ global func Test6_OnStart(int plr)
|
|||
var crossing5 = CreateObjectAbove(CableCrossing, 220, 160, plr);
|
||||
var crossing6 = CreateObjectAbove(CableCrossing, 280, 160, plr);
|
||||
var crossing7 = CreateObjectAbove(CableCrossing, 348, 104, plr);
|
||||
var crossing8 = CreateObjectAbove(CableCrossing, 476, 312, plr);
|
||||
var crossing8 = CreateObjectAbove(CableCrossing, 412, 124, plr);
|
||||
var crossing9 = CreateObjectAbove(CableCrossing, 412, 248, plr);
|
||||
var crossing10 = CreateObjectAbove(CableCrossing, 288, 248, plr);
|
||||
var crossing11 = CreateObjectAbove(CableCrossing, 254, 280, plr);
|
||||
var crossing12 = CreateObjectAbove(CableCrossing, 312, 312, plr);
|
||||
var crossing13 = CreateObjectAbove(CableCrossing, 476, 312, plr);
|
||||
|
||||
CreateCableCrossingsConnection(crossing1, crossing2);
|
||||
CreateCableCrossingsConnection(crossing2, crossing3);
|
||||
|
@ -436,6 +446,11 @@ global func Test6_OnStart(int plr)
|
|||
CreateCableCrossingsConnection(crossing6, crossing7);
|
||||
CreateCableCrossingsConnection(crossing7, crossing4);
|
||||
CreateCableCrossingsConnection(crossing7, crossing8);
|
||||
CreateCableCrossingsConnection(crossing8, crossing9);
|
||||
CreateCableCrossingsConnection(crossing9, crossing10);
|
||||
CreateCableCrossingsConnection(crossing10, crossing11);
|
||||
CreateCableCrossingsConnection(crossing11, crossing12);
|
||||
CreateCableCrossingsConnection(crossing12, crossing13);
|
||||
|
||||
var hoist, lorry;
|
||||
hoist = crossing4->CreateObject(CableHoist);
|
||||
|
@ -444,9 +459,9 @@ global func Test6_OnStart(int plr)
|
|||
hoist->PickupVehicle(lorry);
|
||||
lorry->CreateContents(Rock, 4);
|
||||
|
||||
hoist = crossing8->CreateObject(CableHoist);
|
||||
hoist->EngageRail(crossing8);
|
||||
lorry = crossing8->CreateObject(CableLorry);
|
||||
hoist = crossing13->CreateObject(CableHoist);
|
||||
hoist->EngageRail(crossing13);
|
||||
lorry = crossing13->CreateObject(CableLorry);
|
||||
hoist->PickupVehicle(lorry);
|
||||
|
||||
var foundry = CreateObjectAbove(Foundry, 110, 160, plr);
|
||||
|
@ -490,6 +505,7 @@ global func Test6_OnFinished()
|
|||
return;
|
||||
}
|
||||
|
||||
|
||||
global func Test7_OnStart(int plr)
|
||||
{
|
||||
SetWindFixed(50);
|
||||
|
@ -544,6 +560,7 @@ global func Test7_OnFinished()
|
|||
return;
|
||||
}
|
||||
|
||||
|
||||
global func Test8_OnStart(int plr)
|
||||
{
|
||||
var crossing1 = CreateObjectAbove(CableCrossing, 20, 160, plr);
|
||||
|
@ -579,7 +596,102 @@ global func Test8_OnFinished()
|
|||
return;
|
||||
}
|
||||
|
||||
|
||||
global func Test9_OnStart(int plr)
|
||||
{
|
||||
CreateObjectAbove(Flagpole, 216, 160, plr);
|
||||
CreateObjectAbove(Flagpole, 20, 312, plr);
|
||||
CreateObjectAbove(Compensator, 40, 312, plr);
|
||||
CreateObjectAbove(Compensator, 60, 312, plr);
|
||||
CreateObjectAbove(Compensator, 80, 312, plr);
|
||||
CreateObjectAbove(Compensator, 100, 312, plr);
|
||||
|
||||
var crossing1 = CreateObjectAbove(CableCrossing, 60, 160, plr);
|
||||
var crossing2 = CreateObjectAbove(CableCrossing, 216, 64, plr);
|
||||
var crossing3 = CreateObjectAbove(CableCrossing, 272, 64, plr);
|
||||
var crossing4 = CreateObjectAbove(CableCrossing, 450, 104, plr);
|
||||
var crossing5 = CreateObjectAbove(CableCrossing, 130, 160, plr);
|
||||
var crossing6 = CreateObjectAbove(CableCrossing, 280, 160, plr);
|
||||
var crossing7 = CreateObjectAbove(CableCrossing, 348, 104, plr);
|
||||
var crossing8 = CreateObjectAbove(CableCrossing, 412, 124, plr);
|
||||
var crossing9 = CreateObjectAbove(CableCrossing, 412, 248, plr);
|
||||
var crossing10 = CreateObjectAbove(CableCrossing, 288, 248, plr);
|
||||
var crossing11 = CreateObjectAbove(CableCrossing, 254, 280, plr);
|
||||
var crossing12 = CreateObjectAbove(CableCrossing, 312, 312, plr);
|
||||
var crossing13 = CreateObjectAbove(CableCrossing, 476, 312, plr);
|
||||
var crossing14 = CreateObjectAbove(CableCrossing, 440, 248, plr);
|
||||
|
||||
CreateCableCrossingsConnection(crossing1, crossing2);
|
||||
CreateCableCrossingsConnection(crossing2, crossing3);
|
||||
CreateCableCrossingsConnection(crossing3, crossing4);
|
||||
CreateCableCrossingsConnection(crossing1, crossing5);
|
||||
CreateCableCrossingsConnection(crossing5, crossing6);
|
||||
CreateCableCrossingsConnection(crossing6, crossing7);
|
||||
CreateCableCrossingsConnection(crossing7, crossing4);
|
||||
CreateCableCrossingsConnection(crossing7, crossing8);
|
||||
CreateCableCrossingsConnection(crossing8, crossing9);
|
||||
CreateCableCrossingsConnection(crossing9, crossing10);
|
||||
CreateCableCrossingsConnection(crossing10, crossing11);
|
||||
CreateCableCrossingsConnection(crossing11, crossing12);
|
||||
CreateCableCrossingsConnection(crossing12, crossing13);
|
||||
CreateCableCrossingsConnection(crossing9, crossing14);
|
||||
|
||||
var hoist, lorry;
|
||||
hoist = crossing4->CreateObject(CableHoist);
|
||||
hoist->EngageRail(crossing4);
|
||||
lorry = crossing4->CreateObject(CableLorry);
|
||||
hoist->PickupVehicle(lorry);
|
||||
|
||||
hoist = crossing13->CreateObject(CableHoist);
|
||||
hoist->EngageRail(crossing13);
|
||||
lorry = crossing13->CreateObject(CableLorry);
|
||||
hoist->PickupVehicle(lorry);
|
||||
|
||||
hoist = crossing1->CreateObject(CableHoist);
|
||||
hoist->EngageRail(crossing1);
|
||||
lorry = crossing1->CreateObject(CableLorry);
|
||||
hoist->PickupVehicle(lorry);
|
||||
|
||||
var foundry = CreateObjectAbove(Foundry, 100, 160, plr);
|
||||
foundry->AddToQueue(Metal, nil, true);
|
||||
crossing5->CombineWith(foundry);
|
||||
|
||||
var workshop = CreateObjectAbove(ToolsWorkshop, 30, 160, plr);
|
||||
crossing1->CombineWith(workshop);
|
||||
workshop->AddToQueue(Shovel, 10);
|
||||
|
||||
var chemical_lab = CreateObjectAbove(ChemicalLab, 250, 160, plr);
|
||||
crossing6->CombineWith(chemical_lab);
|
||||
chemical_lab->AddToQueue(Dynamite, 10);
|
||||
|
||||
var steam_engine = CreateObjectAbove(SteamEngine, 480, 248, plr);
|
||||
crossing14->CombineWith(steam_engine);
|
||||
steam_engine->CreateContents(Coal);
|
||||
|
||||
var sawmill = CreateObjectAbove(Sawmill, 480, 104, plr);
|
||||
sawmill->SetDir(DIR_Right);
|
||||
for (var cnt = 0; cnt < 5; cnt++)
|
||||
sawmill->CreateObjectAbove(Tree_Deciduous)->ChopDown();
|
||||
|
||||
// Log what the test is about.
|
||||
Log("Multiple producers and power supply which need resources from mines.");
|
||||
return true;
|
||||
}
|
||||
|
||||
global func Test9_Completed()
|
||||
{
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
global func Test9_OnFinished()
|
||||
{
|
||||
RemoveTestObjects();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
global func Test10_OnStart(int plr)
|
||||
{
|
||||
var wdt = LandscapeWidth();
|
||||
var hgt = LandscapeHeight();
|
||||
|
@ -626,14 +738,14 @@ global func Test9_OnStart(int plr)
|
|||
return true;
|
||||
}
|
||||
|
||||
global func Test9_Completed()
|
||||
global func Test10_Completed()
|
||||
{
|
||||
if (IsSymmetricCableCarNetwork())
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
global func Test9_OnFinished()
|
||||
global func Test10_OnFinished()
|
||||
{
|
||||
RemoveTestObjects();
|
||||
return;
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
#appendto CableHoist
|
||||
|
||||
public func Construction()
|
||||
{
|
||||
var res = _inherited(...);
|
||||
SetCableSpeed(3);
|
||||
return res;
|
||||
}
|
Loading…
Reference in New Issue