forked from Mirrors/openclonk
cable cars: improve tests and script clean up
parent
c629661af2
commit
816754a3de
|
@ -146,7 +146,7 @@ public func Deactivation(int count)
|
||||||
|
|
||||||
/*-- Saving --*/
|
/*-- Saving --*/
|
||||||
|
|
||||||
public func SaveScenarioObject(props)
|
public func SaveScenarioObject(proplist props)
|
||||||
{
|
{
|
||||||
if (!inherited(props, ...))
|
if (!inherited(props, ...))
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -30,28 +30,28 @@ local lib_ccar_delivery;
|
||||||
// Overload these functions as you feel fit
|
// Overload these functions as you feel fit
|
||||||
|
|
||||||
// Called after the car is attached to a rail
|
// Called after the car is attached to a rail
|
||||||
func Engaged() {}
|
public func Engaged() {}
|
||||||
|
|
||||||
// Called after the car is detached from the rail
|
// Called after the car is detached from the rail
|
||||||
func Disengaged() {}
|
public func Disengaged() {}
|
||||||
|
|
||||||
// To offset the position on the cable from the object's center
|
// To offset the position on the cable from the object's center
|
||||||
// position is a 2-value-array [x,y]
|
// position is a 2-value-array [x,y]
|
||||||
// prec is nil or a value to multiply your calculations with
|
// prec is nil or a value to multiply your calculations with
|
||||||
func GetCableOffset(array position, int prec) {}
|
public func GetCableOffset(array position, int prec) {}
|
||||||
|
|
||||||
// To add custom interaction menu entries after the regular cable car entries
|
// To add custom interaction menu entries after the regular cable car entries
|
||||||
// custom_entry is a prototype for proper spacing of buttons
|
// custom_entry is a prototype for proper spacing of buttons
|
||||||
// Use priorities > 2000 just to be sure
|
// Use priorities > 2000 just to be sure
|
||||||
func GetCableCarExtraMenuEntries(array menu_entries, proplist custom_entry, object clonk) {}
|
public func GetCableCarExtraMenuEntries(array menu_entries, proplist custom_entry, object clonk) {}
|
||||||
|
|
||||||
// Whenever movement is about to begin
|
// Whenever movement is about to begin
|
||||||
// Movement data like lib_ccar_direction is still nil at this moment
|
// Movement data like lib_ccar_direction is still nil at this moment
|
||||||
func OnStart() {}
|
public func OnStart() {}
|
||||||
|
|
||||||
// Whenever the car stops its movement
|
// Whenever the car stops its movement
|
||||||
// failed is true if the movement to a destination was cancelled (usually because the path broke in the meantime)
|
// failed is true if the movement to a destination was cancelled (usually because the path broke in the meantime)
|
||||||
func OnStop(bool failed) {}
|
public func OnStop(bool failed) {}
|
||||||
|
|
||||||
|
|
||||||
/*-- Interface --*/
|
/*-- Interface --*/
|
||||||
|
@ -265,7 +265,7 @@ public func EngageRail(object crossing, bool silent)
|
||||||
UpdateInteractionMenus(this.GetCableCarMenuEntries);
|
UpdateInteractionMenus(this.GetCableCarMenuEntries);
|
||||||
|
|
||||||
Engaged();
|
Engaged();
|
||||||
lib_ccar_rail->OnCableCarEngaged(this);
|
lib_ccar_rail->~OnCableCarEngaged(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Detach the car from its current holding point (cable or crossing, does not matter)
|
// Detach the car from its current holding point (cable or crossing, does not matter)
|
||||||
|
@ -280,7 +280,7 @@ public func DisengageRail()
|
||||||
|
|
||||||
Disengaged();
|
Disengaged();
|
||||||
if (lib_ccar_rail)
|
if (lib_ccar_rail)
|
||||||
lib_ccar_rail->OnCableCarDisengaged(this);
|
lib_ccar_rail->~OnCableCarDisengaged(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sets a target point for travelling and starts the movement process
|
// Sets a target point for travelling and starts the movement process
|
||||||
|
@ -336,7 +336,7 @@ public func DestinationReached()
|
||||||
{
|
{
|
||||||
if (lib_ccar_delivery)
|
if (lib_ccar_delivery)
|
||||||
FinishedRequest(lib_ccar_rail);
|
FinishedRequest(lib_ccar_rail);
|
||||||
lib_ccar_rail->OnCableCarArrival(this);
|
lib_ccar_rail->~OnCableCarArrival(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -344,7 +344,7 @@ public func DestinationReached()
|
||||||
public func DestinationFailed()
|
public func DestinationFailed()
|
||||||
{
|
{
|
||||||
if (lib_ccar_rail)
|
if (lib_ccar_rail)
|
||||||
lib_ccar_rail->OnCableCarStopped(this);
|
lib_ccar_rail->~OnCableCarStopped(this);
|
||||||
|
|
||||||
lib_ccar_destination = nil;
|
lib_ccar_destination = nil;
|
||||||
lib_ccar_direction = nil;
|
lib_ccar_direction = nil;
|
||||||
|
@ -357,7 +357,7 @@ public func DestinationFailed()
|
||||||
public func Destruction()
|
public func Destruction()
|
||||||
{
|
{
|
||||||
if (lib_ccar_rail)
|
if (lib_ccar_rail)
|
||||||
lib_ccar_rail->OnCableCarDestruction(this);
|
lib_ccar_rail->~OnCableCarDestruction(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup movement process
|
// Setup movement process
|
||||||
|
|
|
@ -21,7 +21,7 @@ local connected_building;
|
||||||
// Array of all cable cars currently idling at this station
|
// Array of all cable cars currently idling at this station
|
||||||
local arrived_cars;
|
local arrived_cars;
|
||||||
|
|
||||||
func Initialize()
|
public func Initialize()
|
||||||
{
|
{
|
||||||
turn_anim = PlayAnimation("Engine", 1, Anim_Const(0), Anim_Const(1000));
|
turn_anim = PlayAnimation("Engine", 1, Anim_Const(0), Anim_Const(1000));
|
||||||
arrived_cars = [];
|
arrived_cars = [];
|
||||||
|
@ -147,7 +147,7 @@ public func CombineWith(object stick_to)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Interaction */
|
/*-- Interaction --*/
|
||||||
|
|
||||||
// Provides an own interaction menu.
|
// Provides an own interaction menu.
|
||||||
public func HasInteractionMenu() { return true; }
|
public func HasInteractionMenu() { return true; }
|
||||||
|
@ -167,7 +167,6 @@ public func GetInteractionMenus(object clonk)
|
||||||
Priority = 20
|
Priority = 20
|
||||||
};
|
};
|
||||||
PushBack(menus, crossing_menu);
|
PushBack(menus, crossing_menu);
|
||||||
|
|
||||||
return menus;
|
return menus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,8 +187,7 @@ public func GetSettingsMenuEntries()
|
||||||
|
|
||||||
var menu_entries = [];
|
var menu_entries = [];
|
||||||
|
|
||||||
// Clickable buttons
|
// Clickable buttons.
|
||||||
|
|
||||||
var station = new custom_entry {
|
var station = new custom_entry {
|
||||||
Priority = 1000,
|
Priority = 1000,
|
||||||
Tooltip = "$TooltipToggleStation$",
|
Tooltip = "$TooltipToggleStation$",
|
||||||
|
@ -226,7 +224,7 @@ public func OnSettingsHover(symbol, extra_data, desc_menu_target, menu_id)
|
||||||
GuiUpdate({ Text = text }, menu_id, 1, desc_menu_target);
|
GuiUpdate({ Text = text }, menu_id, 1, desc_menu_target);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Settings */
|
/*-- Settings --*/
|
||||||
|
|
||||||
public func ToggleStation(bool silent)
|
public func ToggleStation(bool silent)
|
||||||
{
|
{
|
||||||
|
@ -352,5 +350,5 @@ public func SetManual() { manual_setting = true; return true; }
|
||||||
|
|
||||||
local Name = "$Name$";
|
local Name = "$Name$";
|
||||||
local BlastIncinerate = 50;
|
local BlastIncinerate = 50;
|
||||||
local LineAttach = [6,-9];
|
local LineAttach = [6, -9];
|
||||||
local Components = {Metal = 1, Wood = 1};
|
local Components = {Metal = 1, Wood = 1};
|
||||||
|
|
|
@ -85,7 +85,9 @@ public func GetCableCarExtraMenuEntries(array menu_entries, proplist custom_entr
|
||||||
PushBack(menu_entries, { symbol = vehicle, extra_data = "Pickup", custom = to_pickup });
|
PushBack(menu_entries, { symbol = vehicle, extra_data = "Pickup", custom = to_pickup });
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
} else if (pickup && GetRailTarget()) {
|
}
|
||||||
|
else if (pickup && GetRailTarget())
|
||||||
|
{
|
||||||
// Drop the vehicle
|
// Drop the vehicle
|
||||||
var drop = new custom_entry {
|
var drop = new custom_entry {
|
||||||
Priority = 2000,
|
Priority = 2000,
|
||||||
|
@ -142,7 +144,6 @@ local FxCableHoistPickup = new Effect
|
||||||
{
|
{
|
||||||
Construction = func(object hoist)
|
Construction = func(object hoist)
|
||||||
{
|
{
|
||||||
|
|
||||||
this.hoist = hoist;
|
this.hoist = hoist;
|
||||||
this.vehicle_touchable = Target.Touchable;
|
this.vehicle_touchable = Target.Touchable;
|
||||||
Target.Touchable = 0;
|
Target.Touchable = 0;
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
Title=Cable Cars
|
Title=Cable Cars
|
||||||
|
|
||||||
[Definitions]
|
[Definitions]
|
||||||
Definition2=Experimental.ocf/CableLorrys.ocs/CableCars.ocd
|
Definition2=Experimental.ocf\CableLorrys.ocs\CableCars.ocd
|
||||||
|
|
||||||
[Landscape]
|
[Landscape]
|
||||||
NoScan=1
|
NoScan=1
|
||||||
|
|
|
@ -579,9 +579,13 @@ global func Test8_OnFinished()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
global func Test9_OnStart(int plr)
|
global func Test9_OnStart(int plr)
|
||||||
{
|
{
|
||||||
|
var wdt = LandscapeWidth();
|
||||||
|
var hgt = LandscapeHeight();
|
||||||
|
DrawMaterialQuad("Gold", 0, 0, wdt, 0, wdt, hgt, 0, hgt, DMQ_Sky);
|
||||||
|
ClearFreeRect(0, 0, wdt, hgt);
|
||||||
|
|
||||||
var nr_crossings = RandomX(6, 12);
|
var nr_crossings = RandomX(6, 12);
|
||||||
var connect_chance = 20; // In percent.
|
var connect_chance = 20; // In percent.
|
||||||
var start_time = GetTime();
|
var start_time = GetTime();
|
||||||
|
@ -594,18 +598,31 @@ global func Test9_OnStart(int plr)
|
||||||
{
|
{
|
||||||
for (var c2 in crossings)
|
for (var c2 in crossings)
|
||||||
{
|
{
|
||||||
if (c1 != c2 && Random(100) < connect_chance)
|
if (c1 != c2 && Random(100) < connect_chance && !AreDirectlyConnectedStations(c1, c2))
|
||||||
{
|
{
|
||||||
CreateCableCrossingsConnection(c1, c2);
|
CreateCableCrossingsConnection(c1, c2);
|
||||||
nr_connections++;
|
nr_connections++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
var time_network_creation = GetTime() - start_time;
|
||||||
|
|
||||||
|
var random_cable = FindObject(Find_ID(CableLine), Sort_Random());
|
||||||
|
var c1 = random_cable->GetActionTarget(0);
|
||||||
|
var c2 = random_cable->GetActionTarget(1);
|
||||||
|
start_time = GetTime();
|
||||||
|
random_cable->RemoveObject();
|
||||||
|
var time_connection_removal = GetTime() - start_time;
|
||||||
|
|
||||||
|
start_time = GetTime();
|
||||||
|
CreateCableCrossingsConnection(c1, c2);
|
||||||
|
var time_connection_recreation = GetTime() - start_time;
|
||||||
|
|
||||||
// Log what the test is about.
|
// Log what the test is about.
|
||||||
Log("Test a random network for symmetric distance measures.");
|
Log("Test a random network for symmetric distance measures.");
|
||||||
var time = GetTime() - start_time;
|
Log("It took %d ms to create %d stations with %d connections.", time_network_creation, nr_crossings, nr_connections);
|
||||||
Log("It took %d ms to create %d stations with %d connections.", time, nr_crossings, nr_connections);
|
Log("It took %d ms to remove a random connection.", time_connection_removal);
|
||||||
|
Log("It took %d ms to recreate that random connection.", time_connection_recreation);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -713,6 +730,11 @@ global func IsSymmetricCableCarNetwork()
|
||||||
return is_symmetric;
|
return is_symmetric;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
global func AreDirectlyConnectedStations(object c1, object c2)
|
||||||
|
{
|
||||||
|
return !!FindObject(Find_Func("IsConnectedTo", c1), Find_Func("IsConnectedTo", c2));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*-- Helper Functions --*/
|
/*-- Helper Functions --*/
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue