Code
- include "common.gs"
- include "Signal.gs"
- include "Junction.gs"
- include "gs.gs"
- class JRule {
- define int SPEED_FULL=0;
- define int SPEED_60=1;
- define int SPEED_40=2;
- define int SPEED_25=3;
- define int SPEED_0=4;
- define int SPEED_Verschub=5;
- public Junction[] junc=new Junction[0];
- public string[] njunc=new string[0];
- public int[] dir=new int[0];
- public int limit=SPEED_FULL;
- public Signal nextSignal;
- public string nextSignalName;
- public bool nextSignalScripted=false;
- public Soup GetProperties(void) {
- Soup db=Constructors.NewSoup();
- db.SetNamedTag("num.j",junc.size());
- if (junc.size()) {
- db.SetNamedTag("limit",limit);
- db.SetNamedTag("nextSignalName",nextSignalName);
- int i;
- for (i=0; i<junc.size(); i++) {
- db.SetNamedTag("junc."+i,njunc[i]);
- db.SetNamedTag("dir."+i,dir[i]);
- }
- }
- return db;
- }
- public void SetProperties(Soup db) {
- int n=db.GetNamedTagAsInt("num.j",0);
- junc=new Junction[n];
- njunc=new string[n];
- dir=new int[n];
- if (n) {
- limit=db.GetNamedTagAsInt("limit",0);
- nextSignalName=db.GetNamedTag("nextSignalName");
- int i;
- for (i=0;i<n;i++) {
- njunc[i]=db.GetNamedTag("junc."+i);
- dir[i]=db.GetNamedTagAsInt("dir."+i,3);
- }
- }
- }
- public void Setup(void) {
- int i;
- for (i=0; i<njunc.size(); i++) {
- junc[i]=cast<Junction>Router.GetGameObject(njunc[i]);
- }
- nextSignal=cast<Signal>Router.GetGameObject(nextSignalName);
- }
- };
- class SignalOBB isclass Signal {
- Soup settings;
- StringTable ST;
- Asset cervena,zluta,zelena,bila;
- JRule[] rules=new JRule[0];
- int defaultLimit;
- int nextLimit;
- int thisLimit;
- int maxSpeed=130;
- string name;
- Signal nextSignal;
- string nextSignalName;
- bool nextSignalScripted;
- Browser mb;
- define int SPEED_FULL=0;
- define int SPEED_60=1;
- define int SPEED_40=2;
- define int SPEED_25=3;
- define int SPEED_0=4;
- define int SPEED_Verschub=5;
- int[] speedlimits=new int[SPEED_Verschub+1];
- string[] names=new string[SPEED_Verschub+1];
- SignalOBB[] subscribers=new SignalOBB[0];
- void SwitchOffAllLights(void) {
- if (settings.GetNamedTagAsInt("ishome")) {
- SetFXCoronaTexture("1",null);
- SetFXCoronaTexture("2",null);
- SetFXCoronaTexture("60",null);
- SetFXCoronaTexture("61",null);
- SetFXCoronaTexture("62",null);
- SetFXCoronaTexture("63",null);
- SetFXCoronaTexture("64",null);
- }
- if (settings.GetNamedTagAsInt("speed60")) {
- SetFXCoronaTexture("3",null);
- }
- if (settings.GetNamedTagAsInt("speed40")) {
- SetFXCoronaTexture("4",null);
- }
- if (settings.GetNamedTagAsInt("isdistant")) {
- SetFXCoronaTexture("5",null);
- SetFXCoronaTexture("6",null);
- SetFXCoronaTexture("7",null);
- SetFXCoronaTexture("8",null);
- SetFXCoronaTexture("32",null);
- SetFXCoronaTexture("33",null);
- SetFXCoronaTexture("34",null);
- SetFXCoronaTexture("35",null);
- SetFXCoronaTexture("36",null);
- SetFXCoronaTexture("37",null);
- SetFXCoronaTexture("38",null);
- SetFXCoronaTexture("39",null);
- SetFXCoronaTexture("40",null);
- SetFXCoronaTexture("41",null);
- SetFXCoronaTexture("42",null);
- SetFXCoronaTexture("43",null);
- SetFXCoronaTexture("44",null);
- SetFXCoronaTexture("45",null);
- SetFXCoronaTexture("46",null);
- SetFXCoronaTexture("47",null);
- SetFXCoronaTexture("48",null);
- SetFXCoronaTexture("49",null);
- SetFXCoronaTexture("50",null);
- SetFXCoronaTexture("51",null);
- SetFXCoronaTexture("52",null);
- SetFXCoronaTexture("53",null);
- SetFXCoronaTexture("54",null);
- SetFXCoronaTexture("55",null);
- SetFXCoronaTexture("56",null);
- SetFXCoronaTexture("57",null);
- SetFXCoronaTexture("58",null);
- SetFXCoronaTexture("59",null);
- }
- if (settings.GetNamedTagAsInt("isSigTo")) {
- SetFXCoronaTexture("13",null);
- SetFXCoronaTexture("14",null);
- SetFXCoronaTexture("15",null);
- SetFXCoronaTexture("16",null);
- SetFXCoronaTexture("17",null);
- SetFXCoronaTexture("18",null);
- SetFXCoronaTexture("19",null);
- SetFXCoronaTexture("20",null);
- SetFXCoronaTexture("21",null);
- SetFXCoronaTexture("22",null);
- SetFXCoronaTexture("23",null);
- SetFXCoronaTexture("24",null);
- SetFXCoronaTexture("25",null);
- SetFXCoronaTexture("26",null);
- SetFXCoronaTexture("27",null);
- SetFXCoronaTexture("28",null);
- SetFXCoronaTexture("31",null);
- }
- }
- void NotifySubscribers(void) {
- int i;
- for(i=0;i<subscribers.size();i++) {
- PostMessage(subscribers[i],"OBBSpeedNotify",thisLimit,0);
- }
- }
- int FindRuleIndex(void) {
- int c;
- int l;
- bool hit=false;
- l=-1;
- if (rules.size()>0) {
- for (c=0; c<rules.size(); c++) {
- hit=(rules[c].junc.size()>0);
- int j;
- for (j=0; j<rules[c].junc.size(); j++) {
- if (rules[c].junc[j]) {
- hit=hit and (rules[c].junc[j].GetDirection()==rules[c].dir[j]);
- } else {
- hit=false;
- }
- }
- if (hit) {l=c;}
- }
- }
- return l;
- }
- int FindLimit(void) {
- int idx=FindRuleIndex();
- if (idx==-1) { return defaultLimit; }
- return rules[idx].limit;
- }
- Signal FindSignal(void) {
- int idx=FindRuleIndex();
- if (idx==-1) { return nextSignal; }
- return rules[idx].nextSignal;
- }
- void StateChange(Message msg) {
- if (msg.src==me) {if (thisLimit!=SPEED_Verschub) {PostMessage(me,"SignalOBB","Update",0);}}
- int idx=FindRuleIndex();
- Signal next;
- bool scripted;
- if (idx==-1) { next=nextSignal; scripted=nextSignalScripted;}
- else { next=rules[idx].nextSignal; scripted=rules[idx].nextSignalScripted; }
- if (next==msg.src) {
- if (!scripted) {
- switch (next.GetSignalState()) {
- case RED: nextLimit=SPEED_0; break;
- case YELLOW: nextLimit=SPEED_40; break;
- case GREEN: nextLimit=SPEED_FULL; break;
- default:;
- }
- if (thisLimit!=SPEED_Verschub) {PostMessage(me,"SignalOBB","Update",0);}
- }
- }
- }
- public void Update(Message msg) {
- if (msg.src==me) {
- thisLimit=FindLimit();
- if (GetSignalState()==RED and thisLimit!=SPEED_Verschub) { thisLimit=SPEED_0; }
- SwitchOffAllLights();
- if (settings.GetNamedTagAsInt("isHome")) {
- SetSignalState(AUTOMATIC,"");
- switch (thisLimit) {
- case SPEED_FULL:
- SetFXCoronaTexture("2",zelena);
- SetFXCoronaTexture("60",bila);
- SetFXCoronaTexture("61",bila);
- break;
- case SPEED_60:
- SetSpeedLimit(16.667);
- SetFXCoronaTexture("2",zelena);
- SetFXCoronaTexture("3",zelena);
- break;
- case SPEED_40:
- SetSpeedLimit(11.111);
- SetFXCoronaTexture("2",zelena);
- SetFXCoronaTexture("4",zluta);
- break;
- case SPEED_Verschub:
- SetSignalState(YELLOW,ST.GetString("fahrt.Verschub"));
- SetFXCoronaTexture("1",cervena);
- SetFXCoronaTexture("60",bila);
- SetFXCoronaTexture("62",bila);
- SetFXCoronaTexture("63",bila);
- SetFXCoronaTexture("64",cervena);
- break;
- case SPEED_0:
- SetFXCoronaTexture("1",cervena);
- break;
- default:;
- }
- if (thisLimit>=0 and thisLimit<speedlimits.size()) {
- if (thisLimit!=SPEED_0) {SetSpeedLimit(speedlimits[thisLimit]/3.6);}
- }
- NotifySubscribers();
- if (settings.GetNamedTagAsInt("isDistant")) {
- switch (thisLimit) {
- case SPEED_FULL:
- case SPEED_60:
- case SPEED_40:
- switch (nextLimit) {
- case SPEED_FULL:
- SetFXCoronaTexture("7",zelena);
- SetFXCoronaTexture("8",zelena);
- SetFXCoronaTexture("32",bila);
- SetFXCoronaTexture("33",bila);
- SetFXCoronaTexture("34",bila);
- SetFXCoronaTexture("35",bila);
- SetFXCoronaTexture("36",bila);
- SetFXCoronaTexture("37",bila);
- SetFXCoronaTexture("38",bila);
- SetFXCoronaTexture("39",bila);
- SetFXCoronaTexture("40",bila);
- SetFXCoronaTexture("41",bila);
- SetFXCoronaTexture("42",bila);
- SetFXCoronaTexture("43",bila);
- SetFXCoronaTexture("44",bila);
- break;
- case SPEED_60:
- SetFXCoronaTexture("7",zelena);
- SetFXCoronaTexture("8",zelena);
- SetFXCoronaTexture("5",zluta);
- SetFXCoronaTexture("32",bila);
- SetFXCoronaTexture("33",bila);
- SetFXCoronaTexture("34",bila);
- SetFXCoronaTexture("35",bila);
- SetFXCoronaTexture("36",bila);
- SetFXCoronaTexture("37",bila);
- SetFXCoronaTexture("38",bila);
- SetFXCoronaTexture("53",bila);
- SetFXCoronaTexture("54",bila);
- SetFXCoronaTexture("55",bila);
- SetFXCoronaTexture("56",bila);
- SetFXCoronaTexture("57",bila);
- SetFXCoronaTexture("58",bila);
- SetFXCoronaTexture("59",bila);
- break;
- case SPEED_40:
- SetFXCoronaTexture("5",zluta);
- SetFXCoronaTexture("7",zelena);
- SetFXCoronaTexture("6",zluta);
- SetFXCoronaTexture("32",bila);
- SetFXCoronaTexture("33",bila);
- SetFXCoronaTexture("34",bila);
- SetFXCoronaTexture("35",bila);
- SetFXCoronaTexture("36",bila);
- SetFXCoronaTexture("37",bila);
- SetFXCoronaTexture("38",bila);
- SetFXCoronaTexture("53",bila);
- SetFXCoronaTexture("54",bila);
- SetFXCoronaTexture("55",bila);
- SetFXCoronaTexture("56",bila);
- SetFXCoronaTexture("57",bila);
- SetFXCoronaTexture("58",bila);
- SetFXCoronaTexture("59",bila);
- break;
- case SPEED_Verschub:
- SetFXCoronaTexture("63",bila);
- case SPEED_0:
- SetFXCoronaTexture("5",zluta);
- SetFXCoronaTexture("6",zluta);
- SetFXCoronaTexture("32",bila);
- SetFXCoronaTexture("33",bila);
- SetFXCoronaTexture("34",bila);
- SetFXCoronaTexture("35",bila);
- SetFXCoronaTexture("36",bila);
- SetFXCoronaTexture("37",bila);
- SetFXCoronaTexture("38",bila);
- SetFXCoronaTexture("45",bila);
- SetFXCoronaTexture("46",bila);
- SetFXCoronaTexture("47",bila);
- SetFXCoronaTexture("48",bila);
- SetFXCoronaTexture("49",bila);
- SetFXCoronaTexture("50",bila);
- SetFXCoronaTexture("51",bila);
- SetFXCoronaTexture("52",bila);
- break;
- default:;
- }
- default:;
- }
- }
- if (settings.GetNamedTagAsInt("isSigNach")) {
- switch (thisLimit) {
- case SPEED_FULL:
- case SPEED_60:
- case SPEED_40:
- switch (nextLimit) {
- SetFXCoronaTexture("13",bila);
- SetFXCoronaTexture("14",bila);
- SetFXCoronaTexture("15",bila);
- SetFXCoronaTexture("16",bila);
- case SPEED_FULL:
- SetFXCoronaTexture("21",bila);
- SetFXCoronaTexture("22",bila);
- SetFXCoronaTexture("23",bila);
- SetFXCoronaTexture("24",bila);
- break;
- case SPEED_60:
- case SPEED_40:
- SetFXCoronaTexture("25",bila);
- SetFXCoronaTexture("26",bila);
- SetFXCoronaTexture("27",bila);
- SetFXCoronaTexture("28",bila);
- break;
- case SPEED_Verschub:
- case SPEED_0:
- SetFXCoronaTexture("17",bila);
- SetFXCoronaTexture("18",bila);
- SetFXCoronaTexture("19",bila);
- SetFXCoronaTexture("20",bila);
- break;
- default:;
- }
- default:;
- }
- }
- }
- if (settings.GetNamedTagAsInt("isDistant")) {
- if (!settings.GetNamedTagAsInt("isHome")) {
- switch (nextLimit) {
- case SPEED_FULL:
- SetFXCoronaTexture("7",zelena);
- SetFXCoronaTexture("8",zelena);
- SetFXCoronaTexture("32",bila);
- SetFXCoronaTexture("33",bila);
- SetFXCoronaTexture("34",bila);
- SetFXCoronaTexture("35",bila);
- SetFXCoronaTexture("36",bila);
- SetFXCoronaTexture("37",bila);
- SetFXCoronaTexture("38",bila);
- SetFXCoronaTexture("39",bila);
- SetFXCoronaTexture("40",bila);
- SetFXCoronaTexture("41",bila);
- SetFXCoronaTexture("42",bila);
- SetFXCoronaTexture("43",bila);
- SetFXCoronaTexture("44",bila);
- SetFXCoronaTexture("60",bila);
- SetFXCoronaTexture("61",bila);
- break;
- case SPEED_60:
- SetFXCoronaTexture("7",zelena);
- SetFXCoronaTexture("8",zelena);
- SetFXCoronaTexture("5",zluta);
- SetFXCoronaTexture("32",bila);
- SetFXCoronaTexture("33",bila);
- SetFXCoronaTexture("34",bila);
- SetFXCoronaTexture("35",bila);
- SetFXCoronaTexture("36",bila);
- SetFXCoronaTexture("37",bila);
- SetFXCoronaTexture("38",bila);
- SetFXCoronaTexture("53",bila);
- SetFXCoronaTexture("54",bila);
- SetFXCoronaTexture("55",bila);
- SetFXCoronaTexture("56",bila);
- SetFXCoronaTexture("57",bila);
- SetFXCoronaTexture("58",bila);
- SetFXCoronaTexture("59",bila);
- break;
- case SPEED_40:
- SetFXCoronaTexture("5",zluta);
- SetFXCoronaTexture("8",zelena);
- SetFXCoronaTexture("6",zluta);
- SetFXCoronaTexture("32",bila);
- SetFXCoronaTexture("33",bila);
- SetFXCoronaTexture("34",bila);
- SetFXCoronaTexture("35",bila);
- SetFXCoronaTexture("36",bila);
- SetFXCoronaTexture("37",bila);
- SetFXCoronaTexture("38",bila);
- SetFXCoronaTexture("53",bila);
- SetFXCoronaTexture("54",bila);
- SetFXCoronaTexture("55",bila);
- SetFXCoronaTexture("56",bila);
- SetFXCoronaTexture("57",bila);
- SetFXCoronaTexture("58",bila);
- SetFXCoronaTexture("59",bila);
- break;
- case SPEED_Verschub:
- SetFXCoronaTexture("63",bila);
- case SPEED_0:
- SetFXCoronaTexture("5",zluta);
- SetFXCoronaTexture("6",zluta);
- SetFXCoronaTexture("33",bila);
- SetFXCoronaTexture("34",bila);
- SetFXCoronaTexture("35",bila);
- SetFXCoronaTexture("36",bila);
- SetFXCoronaTexture("37",bila);
- SetFXCoronaTexture("38",bila);
- SetFXCoronaTexture("45",bila);
- SetFXCoronaTexture("46",bila);
- SetFXCoronaTexture("47",bila);
- SetFXCoronaTexture("48",bila);
- SetFXCoronaTexture("49",bila);
- SetFXCoronaTexture("50",bila);
- SetFXCoronaTexture("51",bila);
- SetFXCoronaTexture("52",bila);
- break;
- default:;
- }
- }
- }
- if (settings.GetNamedTagAsInt("isSigNach")) {
- if (!settings.GetNamedTagAsInt("isHome")) {
- switch (nextLimit) {
- case SPEED_FULL:
- SetFXCoronaTexture("13",bila);
- SetFXCoronaTexture("14",bila);
- SetFXCoronaTexture("15",bila);
- SetFXCoronaTexture("16",bila);
- SetFXCoronaTexture("21",bila);
- SetFXCoronaTexture("22",bila);
- SetFXCoronaTexture("23",bila);
- SetFXCoronaTexture("24",bila);
- break;
- case SPEED_60:
- case SPEED_40:
- SetFXCoronaTexture("13",bila);
- SetFXCoronaTexture("14",bila);
- SetFXCoronaTexture("15",bila);
- SetFXCoronaTexture("16",bila);
- SetFXCoronaTexture("25",bila);
- SetFXCoronaTexture("26",bila);
- SetFXCoronaTexture("27",bila);
- SetFXCoronaTexture("28",bila);
- break;
- case SPEED_Verschub:
- case SPEED_0:
- SetFXCoronaTexture("13",bila);
- SetFXCoronaTexture("14",bila);
- SetFXCoronaTexture("15",bila);
- SetFXCoronaTexture("16",bila);
- SetFXCoronaTexture("17",bila);
- SetFXCoronaTexture("18",bila);
- SetFXCoronaTexture("19",bila);
- SetFXCoronaTexture("20",bila);
- SetFXCoronaTexture("31",null);
- SetFXCoronaTexture("9",bila);
- SetFXCoronaTexture("10",bila);
- SetFXCoronaTexture("31",bila);
- break;
- default:;
- }
- }
- }
- }
- }
- void KMNotify(Message msg) {
- int idx=FindRuleIndex();
- if (idx==-1) { nextSignalScripted=true; }
- else { rules[idx].nextSignalScripted=true; }
- if (msg.src==FindSignal()) {
- if (msg.minor=="Hp0") {
- nextLimit=SPEED_0;
- } else if (msg.minor=="Hp1") {
- nextLimit=SPEED_FULL;
- } else if (msg.minor=="Hp2") {
- nextLimit=SPEED_40;
- }
- PostMessage(me,"SignalOBB","Update",0.3);
- }
- }
- void SubscribeTo(Signal sig) {
- if (cast<SignalOBB>sig) {
- PostMessage(sig,"SignalOBB","Subscribe",0);
- } else if (sig) {
- PostMessage(sig,"KMSubscribe","",0);
- }
- }
- void Setup(Message msg) {
- int i;
- for (i=0; i<rules.size(); i++) {
- rules[i].Setup();
- if (settings.GetNamedTagAsInt("isDistant")) {
- rules[i].nextSignalScripted=false;
- SubscribeTo(rules[i].nextSignal);
- }
- }
- nextSignal=cast<Signal>Router.GetGameObject(nextSignalName);
- if (settings.GetNamedTagAsInt("isDistant")) {
- nextSignalScripted=false;
- SubscribeTo(nextSignal);
- }
- thisLimit=FindLimit();
- if (name=="") {SetFXNameText("name0"," ");} else {SetFXNameText("name0",name);}
- PostMessage(me,"SignalOBB","Update",0);
- }
- void JunctionToggled(Message msg) {
- int idx=FindRuleIndex();
- bool scripted;
- Signal sig;
- if (idx==-1) { sig=nextSignal; scripted=nextSignalScripted; } else {sig=rules[idx].nextSignal; scripted=rules[idx].nextSignalScripted; }
- if (!scripted and sig!=null) {
- switch (sig.GetSignalState()) {
- case RED: nextLimit=SPEED_0; break;
- case YELLOW: nextLimit=SPEED_40; break;
- case GREEN: nextLimit=SPEED_FULL; break;
- default:;
- }
- }
- PostMessage(me,"SignalOBB","Update",0.5);
- }
- void Notify(Message msg) {
- int idx=FindRuleIndex();
- if (idx==-1) { nextSignalScripted=true; }
- else { rules[idx].nextSignalScripted=true; }
- if (FindSignal()==msg.src) {
- int limit=Str.ToInt(msg.minor);
- nextLimit=limit;
- PostMessage(me,"SignalOBB","Update",0.5);
- }
- }
- void Subscribe(Message msg) {
- int i;
- for (i=0; i<subscribers.size(); i++) {
- if (msg.src==subscribers[i]) { return; }
- }
- subscribers[subscribers.size()]=msg.src;
- PostMessage(msg.src,"OBBSpeedNotify",thisLimit,0);
- }
- string MakeProperty(string link, string text) {
- string t;
- if (text=="") {t=ST.GetString("none"); } else {t=text;}
- return HTMLWindow.MakeLink("live://property/"+link,t);
- }
- string GetRuleHTML(int r) {
- string bgcol=ST.GetString("BGCOLOR");
- string bgcol2=ST.GetString("BGCOLOR2");
- string ret=HTMLWindow.StartTable();
- int j;
- ret=ret+HTMLWindow.MakeRow(
- HTMLWindow.MakeCell(" ")+
- HTMLWindow.MakeCell(ST.GetString("junction"),bgcol)+
- HTMLWindow.MakeCell(ST.GetString("junction.left"),bgcol)+
- HTMLWindow.MakeCell(ST.GetString("junction.forward"),bgcol)+
- HTMLWindow.MakeCell(ST.GetString("junction.right"),bgcol)+
- HTMLWindow.MakeCell(MakeProperty("del-rule/"+r,ST.GetString("del")),bgcol2)
- );
- for(j=0; j<rules[r].njunc.size(); j++) {
- ret=ret+HTMLWindow.MakeRow(
- HTMLWindow.MakeCell(" ")+
- HTMLWindow.MakeCell(MakeProperty("junc/"+r+"/"+j,rules[r].njunc[j]),bgcol2)+
- HTMLWindow.MakeCell(HTMLWindow.RadioButton("live://property/dir/"+r+"/"+j+"/"+Junction.DIRECTION_LEFT,rules[r].dir[j]==Junction.DIRECTION_LEFT),bgcol2)+
- HTMLWindow.MakeCell(HTMLWindow.RadioButton("live://property/dir/"+r+"/"+j+"/"+Junction.DIRECTION_FORWARD,rules[r].dir[j]==Junction.DIRECTION_FORWARD),bgcol2)+
- HTMLWindow.MakeCell(HTMLWindow.RadioButton("live://property/dir/"+r+"/"+j+"/"+Junction.DIRECTION_RIGHT,rules[r].dir[j]==Junction.DIRECTION_RIGHT),bgcol2)+
- HTMLWindow.MakeCell(MakeProperty("del-junc/"+r+"/"+j,ST.GetString("del")),bgcol2)
- );
- }
- ret=ret+HTMLWindow.MakeRow(HTMLWindow.MakeCell(" ")+HTMLWindow.MakeCell(MakeProperty("add-junc/"+r,ST.GetString("junction.add")),bgcol2+" colspan=5"));
- if (settings.GetNamedTagAsInt("isDistant")) {
- ret=ret+HTMLWindow.MakeRow(
- HTMLWindow.MakeCell(" ")+
- HTMLWindow.MakeCell(ST.GetString("nextSignal"),bgcol+" colspan=1")+
- HTMLWindow.MakeCell(MakeProperty("rule-nextSignal/"+r,rules[r].nextSignalName),bgcol2+" colspan=4")
- );
- }
- if (settings.GetNamedTagAsInt("isSigNach")) {
- ret=ret+HTMLWindow.MakeRow(
- HTMLWindow.MakeCell(" ")+
- HTMLWindow.MakeCell(ST.GetString("signach"),bgcol+" colspan=1")+
- HTMLWindow.MakeCell(MakeProperty("rule-nextSignal/"+r,rules[r].nextSignalName),bgcol2+" colspan=4")
- );
- }
- if (settings.GetNamedTagAsInt("isHome")) {
- ret=ret+HTMLWindow.MakeRow(
- HTMLWindow.MakeCell(" ")+
- HTMLWindow.MakeCell(ST.GetString("defaultLimit"),bgcol+" colspan=1")+
- HTMLWindow.MakeCell(MakeProperty("rule-limit/"+r,ST.GetString("fahrt."+names[rules[r].limit])),bgcol2+" colspan=4")
- );
- }
- ret=ret+HTMLWindow.EndTable();
- return ret;
- }
- public string GetDescriptionHTML(void) {
- string ret="<HTML><body>";
- string bgcol=ST.GetString("BGCOLOR");
- string bgcol2=ST.GetString("BGCOLOR2");
- ret=ret+HTMLWindow.StartTable();
- if (settings.GetNamedTagAsInt("isDistant")) {
- ret=ret+HTMLWindow.MakeRow(HTMLWindow.MakeCell(ST.GetString("nextSignal"),bgcol)+HTMLWindow.MakeCell(MakeProperty("nextSignal",nextSignalName),bgcol2));
- }
- if (settings.GetNamedTagAsInt("isSigNach")) {
- ret=ret+HTMLWindow.MakeRow(HTMLWindow.MakeCell(ST.GetString("signach"),bgcol)+HTMLWindow.MakeCell(MakeProperty("nextSignal",nextSignalName),bgcol2));
- }
- if (settings.GetNamedTagAsInt("isHome")) {
- ret=ret+HTMLWindow.MakeRow(HTMLWindow.MakeCell(ST.GetString("platetext"),bgcol)+HTMLWindow.MakeCell(MakeProperty("name",name),bgcol2));
- ret=ret+HTMLWindow.MakeRow(HTMLWindow.MakeCell(ST.GetString("max.speed"),bgcol)+HTMLWindow.MakeCell(MakeProperty("maxSpeed",maxSpeed),bgcol2));
- ret=ret+HTMLWindow.MakeRow(HTMLWindow.MakeCell(ST.GetString("defaultLimit"),bgcol)+HTMLWindow.MakeCell(MakeProperty("defaultLimit",ST.GetString("fahrt."+names[defaultLimit])),bgcol2));
- }
- if (rules.size()==0) {
- ret=ret+HTMLWindow.MakeRow(HTMLWindow.MakeCell(ST.GetString("rules.none"),bgcol)+HTMLWindow.MakeCell(MakeProperty("add-rule",ST.GetString("rules.add")),bgcol2));
- } else {
- int r;
- for(r=0; r<rules.size(); r++) {
- ret=ret+HTMLWindow.MakeRow(HTMLWindow.MakeCell(GetRuleHTML(r),"colspan=2"));
- }
- ret=ret+HTMLWindow.MakeRow(HTMLWindow.MakeCell(MakeProperty("add-rule",ST.GetString("rules.add")),bgcol2+" colspan=2"));
- }
- ret=ret+HTMLWindow.EndTable();
- ret=ret+"</Body></html>";
- return ret;
- }
- public string GetPropertyType(string id) {
- string[] tok=Str.Tokens(id,"/");
- if (tok[0]=="nextSignal") { return "list,1"; }
- else if (tok[0]=="rule-nextSignal") { return "list,1"; }
- else if (tok[0]=="rule-limit") { return "list"; }
- else if (tok[0]=="defaultLimit") { return "list"; }
- else if (tok[0]=="junc") { return "list,1"; }
- else if (tok[0]=="name") { return "string,0,4"; }
- else if (tok[0]=="maxSpeed") { return "int,0,120,10"; }
- return "link";
- }
- public string[] GetPropertyElementList(string id) {
- string[] tok=Str.Tokens(id,"/");
- string[] list=new string[0];
- if (tok[0]=="nextSignal" or tok[0]=="rule-nextSignal") {
- string[] list=new string[0];
- Signal[] slist=World.GetSignalList();
- int i;
- for (i=0; i<slist.size(); i++) {
- if (slist[i].GetName()!="") {
- list[list.size()]=slist[i].GetName();
- }
- }
- return list;
- }
- if (tok[0]=="junc") {
- Junction[] jlist=World.GetJunctionList();
- string[] list=new string[0];
- int i;
- for (i=0; i<jlist.size(); i++) {
- list[i]=jlist[i].GetName();
- }
- return list;
- }
- if (tok[0]=="defaultLimit" or tok[0]=="rule-limit") {
- int i;
- if (settings.GetNamedTagAsInt("speed-1")) { list[list.size()]=ST.GetString("fahrt.-1"); }
- if (settings.GetNamedTagAsInt("speed60")) { list[list.size()]=ST.GetString("fahrt.60"); }
- if (settings.GetNamedTagAsInt("speed40")) { list[list.size()]=ST.GetString("fahrt.40"); }
- if (settings.GetNamedTagAsInt("speedVerschub")) { list[list.size()]=ST.GetString("fahrt.Verschub"); }
- if (settings.GetNamedTagAsInt("speed0")) { list[list.size()]=ST.GetString("fahrt.0"); }
- }
- return list;
- }
- public void SetPropertyValue(string id, int val) {
- string[] tok=Str.Tokens(id,"/");
- if (tok[0]=="maxSpeed") {
- maxSpeed=val;
- speedlimits[SPEED_FULL]=maxSpeed;
- }
- }
- public void SetPropertyValue(string id, string val) {
- string[] tok=Str.Tokens(id,"/");
- if (tok[0]=="defaultLimit") {
- if (val==ST.GetString("fahrt.-1")) { defaultLimit=SPEED_FULL; }
- else if (val==ST.GetString("fahrt.60")) { defaultLimit=SPEED_60; }
- else if (val==ST.GetString("fahrt.40")) { defaultLimit=SPEED_40; }
- else if (val==ST.GetString("fahrt.Verschub")) { defaultLimit=SPEED_Verschub; }
- else if (val==ST.GetString("fahrt.0")) { defaultLimit=SPEED_0; }
- PostMessage(me,"SignalOBB","Update",0);
- }
- if (tok[0]=="rule-limit") {
- int r=Str.ToInt(tok[1]);
- if (val==ST.GetString("fahrt.-1")) { rules[r].limit=SPEED_FULL; }
- else if (val==ST.GetString("fahrt.60")) { rules[r].limit=SPEED_60; }
- else if (val==ST.GetString("fahrt.40")) { rules[r].limit=SPEED_40; }
- else if (val==ST.GetString("fahrt.Verschub")) { rules[r].limit=SPEED_Verschub; }
- else if (val==ST.GetString("fahrt.0")) { rules[r].limit=SPEED_0; }
- PostMessage(me,"SignalOBB","Update",0);
- }
- if (tok[0]=="nextSignal") {
- nextSignalName=val;
- nextSignal=cast<Signal>Router.GetGameObject(val);
- nextSignalScripted=false;
- SubscribeTo(nextSignal);
- PostMessage(me,"SignalOBB","Update",0);
- }
- if (tok[0]=="rule-nextSignal") {
- int r=Str.ToInt(tok[1]);
- rules[r].nextSignalName=val;
- rules[r].nextSignal=cast<Signal>Router.GetGameObject(val);
- rules[r].nextSignalScripted=false;
- SubscribeTo(rules[r].nextSignal);
- PostMessage(me,"SignalOBB","Update",0);
- }
- if (tok[0]=="junc") {
- int r=Str.ToInt(tok[1]);
- int j=Str.ToInt(tok[2]);
- rules[r].njunc[j]=val;
- rules[r].junc[j]=cast<Junction>Router.GetGameObject(val);
- PostMessage(me,"SignalOBB","Update",0);
- }
- if (tok[0]=="name") {
- name=val;
- if (name=="") {SetFXNameText("name0"," ");} else {SetFXNameText("name0",name);}
- }
- }
- public void SetPropertyValue(string id, string val, int idx) {
- SetPropertyValue(id,val);
- }
- public void LinkPropertyValue(string id) {
- string[] tok=Str.Tokens(id,"/");
- if (tok[0]=="add-rule") {
- rules[rules.size()]=new JRule();
- }
- if (tok[0]=="add-junc") {
- int r=Str.ToInt(tok[1]);
- int n=rules[r].njunc.size();
- rules[r].njunc[n]="";
- rules[r].junc[n]=null;
- rules[r].dir[n]=Junction.DIRECTION_NONE;
- }
- if (tok[0]=="del-rule") {
- int r=Str.ToInt(tok[1]);
- rules[r,r+1]=null;
- }
- if (tok[0]=="del-junc") {
- int r=Str.ToInt(tok[1]);
- int j=Str.ToInt(tok[2]);
- rules[r].junc[j,j+1]=null;
- rules[r].njunc[j,j+1]=null;
- rules[r].dir[j,j+1]=null;
- }
- if (tok[0]=="dir") {
- int r=Str.ToInt(tok[1]);
- int j=Str.ToInt(tok[2]);
- int d=Str.ToInt(tok[3]);
- rules[r].dir[j]=d;
- }
- }
- public string GetPropertyName(string id) {
- string[] tok=Str.Tokens(id,"/");
- if (tok[0]=="nextSignal") { return ST.GetString("nextSignal"); }
- else if (tok[0]=="rule-nextSignal") { return ST.GetString("nextSignal"); }
- else if (tok[0]=="rule-limit") { return ST.GetString("defaultlimit"); }
- else if (tok[0]=="defaultLimit") { return ST.GetString("defaultlimit"); }
- else if (tok[0]=="junc") { return ST.GetString("junction"); }
- else if (tok[0]=="name") { return ST.GetString("platetext"); }
- else if (tok[0]=="maxSpeed") { return ST.GetString("max.speed"); }
- return "";
- }
- public string GetPropertyDescription(string id) {
- return "";
- }
- public Soup GetProperties(void) {
- Soup db=inherited();
- db.SetNamedTag("name",name);
- db.SetNamedTag("defaultLimit",defaultLimit);
- db.SetNamedTag("nextSignal",nextSignalName);
- db.SetNamedTag("maxSpeed",maxSpeed);
- db.SetNamedTag("rules.num",rules.size());
- int i;
- for (i=0; i<rules.size(); i++) {
- db.SetNamedSoup("rule."+i,rules[i].GetProperties());
- }
- return db;
- }
- public void SetProperties(Soup db) {
- name=db.GetNamedTag("name");
- defaultLimit=db.GetNamedTagAsInt("defaultLimit",0);
- nextSignalName=db.GetNamedTag("nextSignal");
- if (db.GetNamedTag("maxSpeed")=="") { maxSpeed=120; }
- else { maxSpeed=db.GetNamedTagAsInt("maxSpeed");}
- speedlimits[SPEED_FULL]=maxSpeed;
- int n=db.GetNamedTagAsInt("rules.num");
- rules=new JRule[n];
- int i;
- for (i=0; i<n; i++) {
- rules[i]=new JRule();
- rules[i].SetProperties(db.GetNamedSoup("rule."+i));
- }
- PostMessage(me,"SignalOBB","Setup",0);
- }
- thread void HandleMB(void) {
- Message msg;
- while (mb) {
- wait() {
- on "Browser-Closed","",msg: {
- if (msg.src==mb) { mb=null; }
- }
- }
- }
- }
- public void Init(void) {
- inherited();
- Asset self=GetAsset();
- settings=self.GetConfigSoup().GetNamedSoup("extensions");
- ST=self.GetStringTable();
- cervena=self.FindAsset("Obb-Cervena");
- zluta=self.FindAsset("Obb-Zluta");
- zelena=self.FindAsset("Obb-Zelena");
- bila=self.FindAsset("Obb-Bila");
- name="A";
- SwitchOffAllLights();
- if (zelena==null or zluta==null or cervena==null or bila==null) {
- Interface.Log("Chybí alespoň jedno koronové aktivum!");
- return;
- }
- defaultLimit=SPEED_FULL;
- maxSpeed=130;
- speedlimits[SPEED_FULL]=maxSpeed;
- speedlimits[SPEED_60]=60;
- speedlimits[SPEED_40]=40;
- speedlimits[SPEED_0]=0;
- speedlimits[SPEED_Verschub]=25;
- names[SPEED_FULL]="-1";
- names[SPEED_60]="60";
- names[SPEED_40]="40";
- names[SPEED_0]="0";
- names[SPEED_Verschub]="Verschub";
- AddHandler(me,"SignalOBB","Setup","Setup");
- AddHandler(me,"SignalOBB","Update","Update");
- AddHandler(me,"Signal","StateChanged","StateChange");
- AddHandler(me,"Junction","Toggled","JunctionToggled");
- AddHandler(me,"SignalOBB","Subscribe","Subscribe");
- AddHandler(me,"OBBSpeedNotify","","Notify");
- AddHandler(me,"MapObject","View-Details","ViewDetails");
- AddHandler(me,"KMAspectsChanged","","KMNotify");
- }
- };
I need advice on how to insert a script to set speeds of 40 and 60 km/h for the current situation. According to this script, the train sucks in the signals but does not set the speed.