cable cars: improve tests and script clean up

master
Maikel de Vries 2018-03-31 11:00:24 +02:00
parent c629661af2
commit 816754a3de
6 changed files with 47 additions and 26 deletions

View File

@ -146,7 +146,7 @@ public func Deactivation(int count)
/*-- Saving --*/
public func SaveScenarioObject(props)
public func SaveScenarioObject(proplist props)
{
if (!inherited(props, ...))
return false;

View File

@ -30,28 +30,28 @@ local lib_ccar_delivery;
// Overload these functions as you feel fit
// Called after the car is attached to a rail
func Engaged() {}
public func Engaged() {}
// 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
// position is a 2-value-array [x,y]
// 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
// custom_entry is a prototype for proper spacing of buttons
// 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
// Movement data like lib_ccar_direction is still nil at this moment
func OnStart() {}
public func OnStart() {}
// 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)
func OnStop(bool failed) {}
public func OnStop(bool failed) {}
/*-- Interface --*/
@ -265,7 +265,7 @@ public func EngageRail(object crossing, bool silent)
UpdateInteractionMenus(this.GetCableCarMenuEntries);
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)
@ -280,7 +280,7 @@ public func DisengageRail()
Disengaged();
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
@ -336,7 +336,7 @@ public func DestinationReached()
{
if (lib_ccar_delivery)
FinishedRequest(lib_ccar_rail);
lib_ccar_rail->OnCableCarArrival(this);
lib_ccar_rail->~OnCableCarArrival(this);
}
}
@ -344,7 +344,7 @@ public func DestinationReached()
public func DestinationFailed()
{
if (lib_ccar_rail)
lib_ccar_rail->OnCableCarStopped(this);
lib_ccar_rail->~OnCableCarStopped(this);
lib_ccar_destination = nil;
lib_ccar_direction = nil;
@ -357,7 +357,7 @@ public func DestinationFailed()
public func Destruction()
{
if (lib_ccar_rail)
lib_ccar_rail->OnCableCarDestruction(this);
lib_ccar_rail->~OnCableCarDestruction(this);
}
// Setup movement process

View File

@ -21,7 +21,7 @@ local connected_building;
// Array of all cable cars currently idling at this station
local arrived_cars;
func Initialize()
public func Initialize()
{
turn_anim = PlayAnimation("Engine", 1, Anim_Const(0), Anim_Const(1000));
arrived_cars = [];
@ -147,7 +147,7 @@ public func CombineWith(object stick_to)
}
}
/* Interaction */
/*-- Interaction --*/
// Provides an own interaction menu.
public func HasInteractionMenu() { return true; }
@ -167,7 +167,6 @@ public func GetInteractionMenus(object clonk)
Priority = 20
};
PushBack(menus, crossing_menu);
return menus;
}
@ -188,8 +187,7 @@ public func GetSettingsMenuEntries()
var menu_entries = [];
// Clickable buttons
// Clickable buttons.
var station = new custom_entry {
Priority = 1000,
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);
}
/* Settings */
/*-- Settings --*/
public func ToggleStation(bool silent)
{
@ -352,5 +350,5 @@ public func SetManual() { manual_setting = true; return true; }
local Name = "$Name$";
local BlastIncinerate = 50;
local LineAttach = [6,-9];
local LineAttach = [6, -9];
local Components = {Metal = 1, Wood = 1};

View File

@ -85,7 +85,9 @@ public func GetCableCarExtraMenuEntries(array menu_entries, proplist custom_entr
PushBack(menu_entries, { symbol = vehicle, extra_data = "Pickup", custom = to_pickup });
i++;
}
} else if (pickup && GetRailTarget()) {
}
else if (pickup && GetRailTarget())
{
// Drop the vehicle
var drop = new custom_entry {
Priority = 2000,
@ -142,7 +144,6 @@ local FxCableHoistPickup = new Effect
{
Construction = func(object hoist)
{
this.hoist = hoist;
this.vehicle_touchable = Target.Touchable;
Target.Touchable = 0;

View File

@ -2,7 +2,7 @@
Title=Cable Cars
[Definitions]
Definition2=Experimental.ocf/CableLorrys.ocs/CableCars.ocd
Definition2=Experimental.ocf\CableLorrys.ocs\CableCars.ocd
[Landscape]
NoScan=1

View File

@ -579,9 +579,13 @@ global func Test8_OnFinished()
return;
}
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 connect_chance = 20; // In percent.
var start_time = GetTime();
@ -594,18 +598,31 @@ global func Test9_OnStart(int plr)
{
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);
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("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, nr_crossings, nr_connections);
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 remove a random connection.", time_connection_removal);
Log("It took %d ms to recreate that random connection.", time_connection_recreation);
return true;
}
@ -713,6 +730,11 @@ global func IsSymmetricCableCarNetwork()
return is_symmetric;
}
global func AreDirectlyConnectedStations(object c1, object c2)
{
return !!FindObject(Find_Func("IsConnectedTo", c1), Find_Func("IsConnectedTo", c2));
}
/*-- Helper Functions --*/