include "signal.gs" include "constructors.gs" class haltestelle isclass Signal { float lastStopTime=-1.0; //float minTime=60.0; int minTime=15; int klingel=1; int minLoad=0; int maxLoad=5; int minUnLoad=0; int maxUnLoad=5; public thread void dostop(Message msg); public thread void freigabe(Message msg); public thread void load(int number,Vehicle loco); public thread void unload(int number,Vehicle loco); public void Init(void) { AddHandler(me,"Object","Enter","enter"); AddHandler(me,"Object","Stopped","stop"); AddHandler(me,"Object","Leave","left"); AddHandler(me,"Freigabe","FreigabeAn","freigabe"); SetSignalState(2," "); } public void enter(Message msg) { Train train = cast msg.src; if (train.GetAutopilotMode()>1) { SetSignalState(0," "); } } public void left(Message msg) { Train train = cast msg.src; if (train) { Vehicle[] myVehicles = train.GetVehicles(); int i; for (i=0; i < myVehicles.size(); i++) //For each { PostMessage(myVehicles[i],"Haltestelle","Leaving",0.0f); } } } public void stop(Message msg) { Train train = cast msg.src; MapObject[] list; list=train.TrackSearch(true,40); int lp; for (lp=0;lp list[lp]==me) { if (train.GetAutopilotMode()>1) { dostop(msg); } else { Vehicle[] myVehicles = train.GetVehicles(); int i; for (i=0; i < myVehicles.size(); i++) //For each { PostMessage(myVehicles[i],"Haltestelle","Stopped",0.0f); } } } } } } public thread void dostop(Message msg) { Train train = cast msg.src; Vehicle[] myVehicles = train.GetVehicles(); Vehicle FirstVehicle=myVehicles[0]; float time=15.0; if (lastStopTime>=0) { float now=World.GetGameTime(); if (now0) FirstVehicle.GetMyTrain().SoundHorn(); SetSignalState(2," "); lastStopTime=World.GetGameTime(); } public thread void freigabe(Message msg) { Vehicle v=cast msg.src; unload(Math.Rand(minUnLoad,maxUnLoad),v); load(Math.Rand(minLoad,maxLoad),v); } public thread void load(int number,Vehicle loco) { if (number>0) { ProductQueue[] vehicleQueues = loco.GetQueues(); ProductQueue vQueue = vehicleQueues[0]; ProductFilter pFilter = vQueue.GetProductFilter(); Asset[] Products=pFilter.GetProducts(); Asset Product=Products[0]; Sleep(1.0f); PostMessage(loco,"Door1","Open",0.0f); Sleep(4.9f); int del=vQueue.DestroyAllProducts(); vQueue.CreateProduct(Product,number+del); PostMessage(loco,"Haltestelle","Update",0.0f); } } public thread void unload(int number,Vehicle loco) { if (number>0) { ProductQueue[] vehicleQueues = loco.GetQueues(); ProductQueue vQueue = vehicleQueues[0]; ProductFilter pFilter = vQueue.GetProductFilter(); Asset[] Products=pFilter.GetProducts(); Asset Product=Products[0]; int loaded=vQueue.CountProductMatching(null); if (loaded>0) { if ((number>1) and (loaded>1)) { PostMessage(loco,"Door2","Timer",0.0f); PostMessage(loco,"Door3","Timer",0.0f); } else { PostMessage(loco,"Door2","Timer",0.0f); } Sleep(4.0f); int del=vQueue.DestroyAllProducts(); vQueue.CreateProduct(Product,del-number); PostMessage(loco,"Haltestelle","Update",0.0f); } } } string MakeTagName(string name, Soup soup) { string tagname = name; Str.ToLower(tagname); int index = soup.GetIndexForNamedTag(tagname); if (index < 0) { int i; string tagname2; for ( i = 0; i < tagname.size(); i++ ) { if (tagname[i, i + 1] == " " ) tagname2 =tagname2 + "_"; else tagname2 = tagname2 + tagname[i, i + 1]; } int index = soup.GetIndexForNamedTag(tagname2); if (index >= 0) tagname = tagname2; } return tagname; } public void SetProperties(Soup soup) { inherited(soup); if (soup.CountTags() == 0) { minTime=15; klingel=1; minLoad=0; maxLoad=5; minUnLoad=0; maxUnLoad=5; } else { string name=GetAsset().GetName(); minTime = soup.GetNamedTagAsInt(MakeTagName(name+".minTime", soup)); klingel = soup.GetNamedTagAsInt(MakeTagName(name+".klingel", soup)); minLoad = soup.GetNamedTagAsInt(MakeTagName(name+".minLoad", soup)); maxLoad = soup.GetNamedTagAsInt(MakeTagName(name+".maxLoad", soup)); minUnLoad = soup.GetNamedTagAsInt(MakeTagName(name+".minUnLoad", soup)); maxUnLoad = soup.GetNamedTagAsInt(MakeTagName(name+".maxUnLoad", soup)); } } // // Gets the control method of this rule and saves it to a new database. // public Soup GetProperties(void) { Soup soup = inherited(); string name=GetAsset().GetName(); soup.SetNamedTag(MakeTagName(name+".minTime", soup), minTime); soup.SetNamedTag(MakeTagName(name+".klingel", soup), klingel); soup.SetNamedTag(MakeTagName(name+".minLoad", soup), minLoad); soup.SetNamedTag(MakeTagName(name+".maxLoad", soup), maxLoad); soup.SetNamedTag(MakeTagName(name+".minUnLoad", soup), minUnLoad); soup.SetNamedTag(MakeTagName(name+".maxUnLoad", soup), maxUnLoad); return soup; } // // Returns HTML code with link that allows control mode to be changed. // public string GetDescriptionHTML(void) { StringTable strTable = GetAsset().GetStringTable(); string klingelStr=" "+strTable.GetString("html_description"+(klingel+1))+" "; string pauseStr=" "+minTime+" "; string MinLoadStr=" "+minLoad+" "; string MaxLoadStr=" "+maxLoad+" "; string MinUnLoadStr=" "+minUnLoad+" "; string MaxUnLoadStr=" "+maxUnLoad+" "; return "" + strTable.GetString2("description1",MinUnLoadStr,MaxUnLoadStr)+ strTable.GetString2("description2",MinLoadStr,MaxLoadStr)+ strTable.GetString1("description3",pauseStr)+ strTable.GetString1("description4",klingelStr)+ "
"; } // // Always returns "link" - only property type used in this small rule. // string GetPropertyType(string p_propertyID) { string retstr="link"; if (p_propertyID=="minLoad") retstr="int,0,12,1"; else if (p_propertyID=="maxLoad") retstr="int,0,12,1"; else if (p_propertyID=="maxUnLoad") retstr="int,0,12,1"; else if (p_propertyID=="minUnLoad") retstr="int,0,12,1"; else if (p_propertyID=="minTime") retstr="int,20,200,5"; return retstr; } // // Acts on a link. If link is control-method, than control mode is switched. // void LinkPropertyValue(string p_propertyID) { //Interface.Log(p_propertyID); if (p_propertyID == "klingel") { klingel = (klingel + 1) % 2; } } void SetPropertyValue(string p_propertyID,int val) { if (p_propertyID=="minTime") minTime=val; else if (p_propertyID == "minLoad") minLoad=val; else if (p_propertyID == "maxLoad") maxLoad=val; else if (p_propertyID == "minUnLoad") minUnLoad=val; else if (p_propertyID == "maxUnLoad") maxUnLoad=val; } };