include "locomotive.gs" include "browser.gs" include "MeshObject.gs" include "vehicle.gs" include "sessionvariables.gs" class taurus isclass Locomotive { thread void VehicleControl(); Library sharedLib; SessionVariables sessionv; bool watchfulnessLever; float watchfulnessOnDist; float watchfulnessSoundDist; int watchfulnessModeDist; bool deadMan; bool changeSignalState; bool lastctsState; bool derailtrain; bool checklastcar; define int S_NONE = 0; define int S_PC1 = 1; define int S_PC2 = 2; define int S_PC3 = 5; define int S_PC5 = 3; define int S_TB1 = 4; Asset biale; Asset czerwone; Asset skp; Asset mech,pom,mechs,poms; string bgcol="bgcolor=#808080"; string bgcol2="bgcolor=#B0B0B0"; int osw=1; int osw2; int drivertype=0; int pantos=0; int vdb_left = 100; int vdb_right = 450; int vdb_top = 100; int vdb_bottom = 500; int koncowki=0; int vrozkl = 0; bool pc2; bool bln_physics=false; bool bresopt; bool da1,db1,na,nb,ne; bool sec_driver; bool sitting=true; Train t; Browser viever; StringTable ST; Vehicle t_name; //--------------------------------------------------------------- void EmergencyBreakAndWait(Train breaktrain) { int i; // breaktrain.SetAutopilotMode(Train.CONTROL_SCRIPT); // breaktrain.SetHandBrake(true); // breaktrain.SetTrainBrakes(Train.TRAIN_BRAKE_EMERGENCY); // breaktrain.SetManualThrottle(0); SetEngineSetting("throttle",0); breaktrain.SetTrainBrakes(Train.TRAIN_BRAKE_EMERGENCY); Sleep(40); breaktrain.SetAutopilotMode(Train.CONTROL_AUTOMANUAL); } thread void Watchfulness(void) { Train breaktrain; int ebjlenght = 200; float velocity; while (1) { if (deadMan) { watchfulnessLever = false; while(!watchfulnessLever and deadMan) { velocity = Math.Abs(GetVelocity()); watchfulnessOnDist = watchfulnessOnDist + velocity; if (changeSignalState or velocity <= 4.17 or watchfulnessOnDist > watchfulnessModeDist) break; Sleep(1); } if (!watchfulnessLever and velocity > 4.17) { SetMeshAnimationFrame("ebj_invi", 0); SetMeshAnimationSpeed("ebj_invi", 1); SetMeshAnimationState("ebj_invi",true); Sleep(0.8); SetMeshAnimationSpeed("ebj_invi", 0); breaktrain = me.GetMyTrain(); while (!watchfulnessLever and deadMan) { if ((watchfulnessSoundDist = watchfulnessSoundDist + (Math.Abs(GetVelocity()) / 2)) > ebjlenght) break; if (breaktrain.GetAutopilotMode() == Train.CONTROL_AUTOPILOT) { Sleep(Math.Rand(0,2)); break; } Sleep(0.5); } if (watchfulnessSoundDist > ebjlenght) EmergencyBreakAndWait(breaktrain); SetMeshAnimationSpeed("ebj_invi", 1); watchfulnessSoundDist = 0; watchfulnessOnDist = 0; } else if (watchfulnessModeDist == 1550) watchfulnessOnDist = 0; changeSignalState = false; } if (velocity <= 4.17 or !deadMan) Sleep(5); } } int GetCTSHUDState() { return Str.ToInt(sharedLib.LibraryCall("GetCTSAnalogHUDState", null, null )); } void SetDeadmanMode(int ctsstate) { if (lastctsState != ctsstate) changeSignalState = true; switch (ctsstate) { case -1:watchfulnessModeDist = 1550; // White break; case 1: watchfulnessModeDist = 1550; // Green break; case 2: watchfulnessModeDist = 200; // 80 break; case 3: watchfulnessModeDist = 200; // 40 break; case 4: watchfulnessModeDist = 200; // Yellow break; case 5: watchfulnessModeDist = 200; // Red changeSignalState = false; break; case 6: watchfulnessModeDist = 1550; // White break; case 7: watchfulnessModeDist = 1550; // White break; case 8: watchfulnessModeDist = 1550; // 120 break; default: watchfulnessModeDist = 1550; // Default } lastctsState = ctsstate; } thread void VehicleControl(void) { int i; Message msg; while(1) wait() { on "Vehicle", "Derailed", msg: { if(msg.src == me) derailtrain = true; continue; } on "Vehicle", "Coupled", msg: { checklastcar = true; continue; } on "Vehicle", "Decoupled", msg: { checklastcar = true; continue; } on "World", "ModuleInit": { checklastcar = true; continue; } on "HoTTSignalRule", "CTSUpdateState": { SetDeadmanMode(GetCTSHUDState()); } on "CTSWFN", "ClearAlert": { Interface.Print("Space"); watchfulnessLever = true; continue; } on "CTSWFN", "On": { deadMan = true; } on "CTSWFN", "Off": { deadMan = false; } } } //--------------------------------------------------------------- void SetMech (void) { if(sitting) { switch (drivertype) { case 0: // mech automatycznie bool facing=GetDirectionRelativeToTrain(); if (facing) { SetFXAttachment("mech_a",mechs); SetFXAttachment("mech_b",null); if (sec_driver) { SetFXAttachment("pom_a",poms); SetFXAttachment("pom_b",null); } else { SetFXAttachment("pom_a",null); SetFXAttachment("pom_b",null); } } else { SetFXAttachment("mech_a",null); SetFXAttachment("mech_b",mechs); if (sec_driver) { SetFXAttachment("pom_a",null); SetFXAttachment("pom_b",poms); } else { SetFXAttachment("pom_a",null); SetFXAttachment("pom_b",null); } } break; case 1: // mech w kab. A SetFXAttachment("mech_a",mechs); SetFXAttachment("mech_b",null); if (sec_driver) { SetFXAttachment("pom_a",poms); SetFXAttachment("pom_b",null); } else { SetFXAttachment("pom_a",null); SetFXAttachment("pom_b",null); } break; case 2: // mech w kab. B SetFXAttachment("mech_a",null); SetFXAttachment("mech_b",mechs); if (sec_driver) { SetFXAttachment("pom_a",null); SetFXAttachment("pom_b",poms); } else { SetFXAttachment("pom_a",null); SetFXAttachment("pom_b",null); } break; case 3: // brak mech SetFXAttachment("mech_a",null); SetFXAttachment("mech_b",null); SetFXAttachment("pom_a",null); SetFXAttachment("pom_b",null); break; default: break; } } else { switch (drivertype) { case 0: // mech automatycznie bool facing=GetDirectionRelativeToTrain(); if (facing) { SetFXAttachment("mech_a",mech); SetFXAttachment("mech_b",null); if (sec_driver) { SetFXAttachment("pom_a",pom); SetFXAttachment("pom_b",null); } else { SetFXAttachment("pom_a",null); SetFXAttachment("pom_b",null); } } else { SetFXAttachment("mech_a",null); SetFXAttachment("mech_b",mech); if (sec_driver) { SetFXAttachment("pom_a",null); SetFXAttachment("pom_b",pom); } else { SetFXAttachment("pom_a",null); SetFXAttachment("pom_b",null); } } break; case 1: // mech w kab. A SetFXAttachment("mech_a",mech); SetFXAttachment("mech_b",null); if (sec_driver) { SetFXAttachment("pom_a",pom); SetFXAttachment("pom_b",null); } else { SetFXAttachment("pom_a",null); SetFXAttachment("pom_b",null); } break; case 2: // mech w kab. B SetFXAttachment("mech_a",null); SetFXAttachment("mech_b",mech); if (sec_driver) { SetFXAttachment("pom_a",null); SetFXAttachment("pom_b",pom); } else { SetFXAttachment("pom_a",null); SetFXAttachment("pom_b",null); } break; case 3: // brak mech SetFXAttachment("mech_a",null); SetFXAttachment("mech_b",null); SetFXAttachment("pom_a",null); SetFXAttachment("pom_b",null); break; default: break; } } } // --------------------------------------------------------------- void SetPhysics(bool bln_physics) { if(GetMyTrain()) { GetMyTrain().EnablePhysics(!bln_physics); if (bln_physics) { StopMeshAnimation("fan1"); StopMeshAnimation("fan2"); StopMeshAnimation("fan3"); } else { StartMeshAnimationLoop("fan1"); StartMeshAnimationLoop("fan2"); StartMeshAnimationLoop("fan3"); } } } // --------------------------------------------------------------- void SetDoors (void) { if (db1) { SetMeshAnimationFrame("drzwi0",30.0,2.0); } else { SetMeshAnimationFrame("drzwi0",0.0,2.0); } if (da1) { SetMeshAnimationFrame("drzwi1",30.0,2.0); } else { SetMeshAnimationFrame("drzwi1",0.0,2.0); } } // --------------------------------------------------------------- void SetLamps(int position, bool facing) { switch(position) { case S_NONE: SetFXCoronaTexture("ppb",null); //corona_white front, pb0 SetFXCoronaTexture("plb",null); //corona_white front, pb1 SetFXCoronaTexture("psb",null); //corona_white front, pb2 SetFXCoronaTexture("ppc",null); //corona_red, pc0 SetFXCoronaTexture("plc",null); //corona_red, pc1 SetFXCoronaTexture("tpb",null); //corona_white back, tb0 SetFXCoronaTexture("tlb",null); //corona_white back, tb1 SetFXCoronaTexture("tsb",null); //corona_white back, tb3 SetFXCoronaTexture("tpc",null); //corona_red SetFXCoronaTexture("tlc",null); //corona_red SetFXAttachment ("pl1",null); //tarcsa elöl SetFXAttachment ("pp1",null); //tarcsa elöl SetFXAttachment ("tl1",null); //tarcsa hatul SetFXAttachment ("tp1",null); //tarcsa hatul SetMeshVisible("white_dim1",false,0.0); SetMeshVisible("white_dim0",false,0.0); SetMeshVisible("red_lights1",false,0.0); SetMeshVisible("red_lights0",false,0.0); SetMeshVisible("white_full1",false,0.0); SetMeshVisible("white_full0",false,0.0); GetMyTrain().SetHeadlightState(false); break; case S_PC1: if (facing) { SetFXCoronaTexture("ppb",biale); SetFXCoronaTexture("plb",biale); SetFXCoronaTexture("psb",biale); SetFXCoronaTexture("tpb",null); SetFXCoronaTexture("tlb",null); SetFXCoronaTexture("tsb",null); SetFXAttachment ("pl1",null); SetFXAttachment ("pp1",null); SetMeshVisible("red_lights1",false,0.0); SetMeshVisible("red_lights0",false,0.0); SetMeshVisible("white_full1",true,0.0); SetMeshVisible("white_full0",false,0.0); SetMeshVisible("white_dim1",false,0.0); SetMeshVisible("white_dim0",false,0.0); } else { SetFXCoronaTexture("ppb",null); SetFXCoronaTexture("plb",null); SetFXCoronaTexture("psb",null); SetFXCoronaTexture("tpb",biale); SetFXCoronaTexture("tlb",biale); SetFXCoronaTexture("tsb",biale); SetFXAttachment ("tl1",null); SetFXAttachment ("tp1",null); SetMeshVisible("red_lights1",false,0.0); SetMeshVisible("red_lights0",false,0.0); SetMeshVisible("white_full1",false,0.0); SetMeshVisible("white_full0",true,0.0); SetMeshVisible("white_dim1",false,0.0); SetMeshVisible("white_dim0",false,0.0); } break; case S_PC2: if (facing) { SetFXCoronaTexture("ppb",biale); SetFXCoronaTexture("plb",null); SetFXCoronaTexture("psb",null); SetFXCoronaTexture("tpb",biale); SetFXCoronaTexture("tlb",null); SetFXCoronaTexture("tsb",null); SetFXCoronaTexture("ppc",null); SetFXCoronaTexture("plc",null); SetFXAttachment ("pl1",null); SetFXAttachment ("pp1",null); SetMeshVisible("red_lights1",false,0.0); SetMeshVisible("red_lights0",false,0.0); } else { SetFXCoronaTexture("tpb",biale); SetFXCoronaTexture("tlb",null); SetFXCoronaTexture("tsb",null); SetFXCoronaTexture("tpb",biale); SetFXCoronaTexture("tlb",null); SetFXCoronaTexture("tsb",null); SetFXCoronaTexture("tpc",null); SetFXCoronaTexture("tlc",null); SetFXAttachment ("tl1",null); SetFXAttachment ("tp1",null); SetMeshVisible("red_lights1",false,0.0); SetMeshVisible("red_lights0",false,0.0); } break; //-------------------------- case S_PC3: if (facing) { SetFXCoronaTexture("ppb",null); SetFXCoronaTexture("plb",null); SetFXCoronaTexture("psb",null); SetFXCoronaTexture("ppc",null); SetFXCoronaTexture("plc",null); SetFXCoronaTexture("tpb",null); SetFXCoronaTexture("tlb",null); SetFXCoronaTexture("tsb",null); SetMeshVisible("white_dim1",true,0.0); SetMeshVisible("white_dim0",false,0.0); SetMeshVisible("red_lights1",false,0.0); SetMeshVisible("red_lights0",false,0.0); //true SetMeshVisible("white_full1",false,0.0); SetMeshVisible("white_full0",false,0.0); } else { SetFXCoronaTexture("ppb",null); SetFXCoronaTexture("plb",null); SetFXCoronaTexture("psb",null); SetFXCoronaTexture("ppc",czerwone); SetFXCoronaTexture("plc",czerwone); SetFXCoronaTexture("tpb",null); SetFXCoronaTexture("tlb",null); SetFXCoronaTexture("tsb",null); SetMeshVisible("white_dim1",false,0.0); SetMeshVisible("white_dim0",true,0.0); SetMeshVisible("red_lights1",false,0.0); //true SetMeshVisible("red_lights0",false,0.0); SetMeshVisible("white_full1",false,0.0); SetMeshVisible("white_full0",false,0.0); } break; //-------------------------- case S_PC5: if (facing) { SetFXCoronaTexture("ppc",null); SetFXCoronaTexture("plc",null); SetMeshVisible("red_lights1",false,0.0); SetMeshVisible("red_lights0",false,0.0); if (koncowki==1) { SetFXAttachment ("tl1",skp); SetFXAttachment ("tp1",skp); SetMeshVisible("red_lights0",false,0.0); } else { SetFXCoronaTexture("tpc",czerwone); SetFXCoronaTexture("tlc",czerwone); SetMeshVisible("red_lights0",true,0.0); } } else { if (koncowki==1) { SetFXAttachment ("pl1",skp); SetFXAttachment ("pp1",skp); SetMeshVisible("red_lights1",false,0.0); } else { SetFXCoronaTexture("ppc",czerwone); SetFXCoronaTexture("plc",czerwone); SetMeshVisible("red_lights1",true,0.0); } SetFXCoronaTexture("tpc",null); SetFXCoronaTexture("tlc",null); SetMeshVisible("red_lights0",false,0.0); } break; //-------------------------- case S_TB1: SetFXAttachment ("pl1",null); SetFXAttachment ("pp1",null); SetFXAttachment ("tl1",null); SetFXAttachment ("tp1",null); SetMeshVisible("white_dim1",false,0.0); SetMeshVisible("white_dim0",false,0.0); SetMeshVisible("red_lights1",false,0.0); SetMeshVisible("red_lights0",false,0.0); SetMeshVisible("white_full1",false,0.0); SetMeshVisible("white_full0",false,0.0); if (facing) { SetFXCoronaTexture("ppb",biale); SetFXCoronaTexture("plb",null); SetFXCoronaTexture("psb",null); SetFXCoronaTexture("ppc",null); SetFXCoronaTexture("plc",null); SetFXCoronaTexture("tpb",null); SetFXCoronaTexture("tlb",biale); SetFXCoronaTexture("tsb",null); SetFXCoronaTexture("tpc",null); SetFXCoronaTexture("tlc",null); } else { SetFXCoronaTexture("ppb",null); SetFXCoronaTexture("plb",biale); SetFXCoronaTexture("psb",null); SetFXCoronaTexture("ppc",null); SetFXCoronaTexture("plc",null); SetFXCoronaTexture("tpb",biale); SetFXCoronaTexture("tlb",null); SetFXCoronaTexture("tsb",null); SetFXCoronaTexture("tpc",null); SetFXCoronaTexture("tlc",null); } break; default: break; } } // --------------------------------------------------------------- void LampySprawdz(void) { int int_prio = 2; if(GetMyTrain()) { SetLamps(S_NONE,GetDirectionRelativeToTrain()); Vehicle[] veh_wagons = GetMyTrain().GetVehicles(); int_prio = GetMyTrain().GetTrainPriorityNumber(); if (osw != 1) { if (pc2) { if (veh_wagons.size() == 1) { SetLamps(S_PC2,GetDirectionRelativeToTrain()); } else if (veh_wagons[0] == me) SetLamps(S_PC2,GetDirectionRelativeToTrain()); else if (veh_wagons[veh_wagons.size()-1] == me) SetLamps(S_PC5,GetDirectionRelativeToTrain()); GetMyTrain().SetHeadlightState(false); } else { if (int_prio == 3) SetLamps(S_TB1,GetDirectionRelativeToTrain()); else { if (veh_wagons[0] == me) SetLamps(S_PC1,GetDirectionRelativeToTrain()); if (veh_wagons[veh_wagons.size()-1] == me) SetLamps(S_PC5,GetDirectionRelativeToTrain()); if (osw == 3) { GetMyTrain().SetHeadlightState(true); if (veh_wagons[0] == me) SetLamps(S_PC3,GetDirectionRelativeToTrain()); } } } } } } // --------------------------------------------------------------- void SetPant (void) { float fra=GetMeshAnimationFrameCount("odbpra"); float frb=GetMeshAnimationFrameCount("odbprb");; //if(GetMyTrain()) //{ //Vehicle[] veh_wagons = GetMyTrain().GetVehicles(); switch (pantos) { case 0: // zmiana automatycznie bool facing=GetDirectionRelativeToTrain(); if (facing) { SetMeshAnimationFrame("odbpra",0.0,4.0); SetMeshAnimationFrame("odbprb",frb,4.0); } else { SetMeshAnimationFrame("odbpra",fra,4.0); SetMeshAnimationFrame("odbprb",0.0,4.0); } break; case 1: // tyl w gore SetMeshAnimationFrame("odbpra",0.0,4.0); SetMeshAnimationFrame("odbprb",frb,4.0); break; case 2: // przod w gore SetMeshAnimationFrame("odbpra",fra,4.0); SetMeshAnimationFrame("odbprb",0.0,4.0); break; case 3: // oba w gore SetMeshAnimationFrame("odbpra",fra,4.0); SetMeshAnimationFrame("odbprb",frb,4.0); break; case 4: // oba w dol SetMeshAnimationFrame("odbpra",0.0,4.0); SetMeshAnimationFrame("odbprb",0.0,4.0); break; default: break; } //} } // --------------------------------------------------------------- public string GetCabDescr(void) { string ret = ""; ret=ret+HTMLWindow.StartTable(" width=100%"); ret=ret+HTMLWindow.MakeRow(HTMLWindow.MakeCell(HTMLWindow.MakeFontColorBlack(ST.GetString("door")),bgcol2+" colspan=2")); ret=ret+HTMLWindow.MakeRow(HTMLWindow.MakeCell(HTMLWindow.MakeFontColorBlack(ST.GetString("cab_a")),bgcol)+HTMLWindow.MakeCell(HTMLWindow.CheckBox("live://property/da1",da1),bgcol)); ret=ret+HTMLWindow.MakeRow(HTMLWindow.MakeCell(HTMLWindow.MakeFontColorBlack(ST.GetString("cab_b")),bgcol)+HTMLWindow.MakeCell(HTMLWindow.CheckBox("live://property/db1",db1),bgcol)); ret=ret+HTMLWindow.EndTable(); return ret; } // --------------------------------------------------------------- public string GetDescriptionHTML(void) { string ret = inherited(); ret=ret+HTMLWindow.StartTable(); ret=ret+HTMLWindow.MakeRow(""); ret=ret+HTMLWindow.MakeRow(HTMLWindow.MakeCell(HTMLWindow.MakeFontColorBlack(ST.GetString("swiatla") + HTMLWindow.MakeLink("live://property/losw",ST.GetString("s"+osw))),bgcol)); ret=ret+HTMLWindow.MakeRow(HTMLWindow.MakeCell(HTMLWindow.MakeFontColorBlack(ST.GetString("pc2"))+HTMLWindow.CheckBox("live://property/lpc2",pc2),bgcol2)); ret=ret+HTMLWindow.MakeRow(HTMLWindow.MakeCell(HTMLWindow.MakeFontColorBlack(ST.GetString("lampy"))+HTMLWindow.CheckBox("live://property/lkonc0",koncowki==0),bgcol2)); ret=ret+HTMLWindow.MakeRow(HTMLWindow.MakeCell(HTMLWindow.MakeFontColorBlack(ST.GetString("tarczki"))+HTMLWindow.CheckBox("live://property/lkonc1",koncowki==1),bgcol)); ret=ret+HTMLWindow.MakeRow(HTMLWindow.MakeCell(GetCabDescr())); ret=ret+HTMLWindow.MakeRow(HTMLWindow.MakeCell(HTMLWindow.MakeFontColorBlack(ST.GetString("driver") + HTMLWindow.MakeLink("live://property/lmech",ST.GetString("cab_"+drivertype))),bgcol2)); ret=ret+HTMLWindow.MakeRow(HTMLWindow.MakeCell(HTMLWindow.MakeFontColorBlack(ST.GetString("secdriver"))+HTMLWindow.CheckBox("live://property/lsecond",sec_driver),bgcol)); ret=ret+HTMLWindow.MakeRow(HTMLWindow.MakeCell(HTMLWindow.MakeFontColorBlack(ST.GetString("sitting"))+HTMLWindow.CheckBox("live://property/lsit",sitting),bgcol2)); ret=ret+HTMLWindow.MakeRow(HTMLWindow.MakeCell(HTMLWindow.MakeFontColorBlack(ST.GetString("pantos") + HTMLWindow.MakeLink("live://property/lpant",ST.GetString("pant"+pantos))),bgcol)); ret=ret+HTMLWindow.MakeRow(HTMLWindow.MakeCell(HTMLWindow.MakeFontColorBlack(ST.GetString("st_physics"))+HTMLWindow.CheckBox("live://property/lphysics",bln_physics),bgcol2)); ret=ret+HTMLWindow.MakeRow(HTMLWindow.MakeCell(HTMLWindow.MakeFontColorBlack(ST.GetString("resopt"))+HTMLWindow.CheckBox("live://property/lresopt",bresopt),bgcol)); ret=ret+HTMLWindow.EndTable(); ret=ret+""; return ret; } // --------------------------------------------------------------- public void LinkPropertyValue(string lk) { string[] stan=Str.Tokens(lk,"/"); if (stan[0]=="priority-number") { GetMyTrain().SetTrainPriorityNumber((GetMyTrain().GetTrainPriorityNumber() % 3) + 1); LampySprawdz(); } else if (stan[0]=="losw") { osw = osw + 1; if(osw == 4) osw = 1; LampySprawdz(); } else if (stan[0]=="lkonc0") { koncowki = 0; LampySprawdz(); } else if (stan[0]=="lkonc1") { koncowki = 1; LampySprawdz(); } else if (stan[0]=="lmech") { drivertype = drivertype + 1; if(drivertype == 4) drivertype = 0; SetMech(); } else if (stan[0]=="lpant") { pantos = pantos + 1; if(pantos == 5) pantos = 0; SetPant(); } else if (stan[0]== "lsecond") { sec_driver=!sec_driver; SetMech(); } else if (stan[0]== "lsit") { sitting=!sitting; SetMech(); } else if (stan[0]=="lpc2") { pc2 =! pc2; LampySprawdz(); } else if (stan[0]== "lphysics") { bln_physics=!bln_physics; SetPhysics(bln_physics); } else if (stan[0]== "da1") { da1=!da1; SetDoors(); } else if (stan[0]== "db1") { db1=!db1; SetDoors(); } else if (stan[0]== "lresopt") { bresopt=!bresopt; } else { inherited(lk); } } // --------------------------------------------------------------- public Soup GetProperties(void) { Soup db=inherited(); db.SetNamedTag("losw",osw); db.SetNamedTag("lpc2",pc2); db.SetNamedTag("lkonc",koncowki); db.SetNamedTag("bln_physics",bln_physics); db.SetNamedTag("bresopt",bresopt); db.SetNamedTag("da1",da1); db.SetNamedTag("db1",db1); db.SetNamedTag("drivertype",drivertype); db.SetNamedTag("sec_driver",sec_driver); db.SetNamedTag("pantos",pantos); db.SetNamedTag("sitting",sitting); return db; } // --------------------------------------------------------------- public void SetProperties(Soup db) { inherited(db); osw=db.GetNamedTagAsInt("losw",1); pc2=db.GetNamedTagAsInt("lpc2"); koncowki=db.GetNamedTagAsInt("lkonc",0); bln_physics = db.GetNamedTagAsInt("bln_physics"); bresopt= db.GetNamedTagAsInt("bresopt"); da1= db.GetNamedTagAsInt("da1"); db1= db.GetNamedTagAsInt("db1"); drivertype=db.GetNamedTagAsInt("drivertype",0); sec_driver= db.GetNamedTagAsInt("sec_driver"); pantos= db.GetNamedTagAsInt("pantos",4); SetPhysics(bln_physics); sitting= db.GetNamedTagAsInt("sitting",1); LampySprawdz(); SetDoors(); SetMech(); SetPant(); } // --------------------------------------------------------------- string ViewMyDetails(void) { string ret = ""; Train trn_t = GetMyTrain(); Vehicle[] veh_vehicles = trn_t.GetVehicles(); DriverCharacter dch_driver = trn_t.GetActiveDriver(); string str_prio = (string)trn_t.GetTrainPriorityNumber(); string str_mykuidstr = GetAsset().GetKUID().GetHTMLString(); string str_myname = BrowserInterface.Quote(GetLocalisedName()); string str_trainname = BrowserInterface.Quote(trn_t.GetTrainDisplayName()); string stvrozkl = vrozkl; float flt_totalmass = 0.0; int i; for (i = 0; i < veh_vehicles.size(); i++) { flt_totalmass = flt_totalmass + veh_vehicles[i].GetMass(); } string str_massstr = strTable.GetString("mass") + ((string)(int)(flt_totalmass / 1000) + " t"); ret=ret+HTMLWindow.StartTable(); if (dch_driver) { string str_driverimgkuid = dch_driver.GetAsset().GetKUID().GetHTMLString(); ret=ret+HTMLWindow.MakeRow(HTMLWindow.MakeCell(HTMLWindow.MakeImage(str_driverimgkuid,true,32,32)+HTMLWindow.MakeBold(HTMLWindow.MakeFontSizeMedium(HTMLWindow.MakeFontColorBlack(str_trainname))),bgcol)); } else { ret=ret+HTMLWindow.MakeRow(HTMLWindow.MakeCell(HTMLWindow.MakeBold(HTMLWindow.MakeFontSizeMedium(HTMLWindow.MakeFontColorBlack(str_trainname))),bgcol2));} ret=ret+HTMLWindow.MakeRow(HTMLWindow.MakeCell(HTMLWindow.MakeBold(HTMLWindow.MakeFontSizeMedium(HTMLWindow.MakeFontColorBlack(strTable.GetString1("vehicle_view_details1", str_massstr)))),bgcol)); ret=ret+HTMLWindow.MakeRow(HTMLWindow.MakeCell(HTMLWindow.MakeFontColorBlack(strTable.GetString("interface-train-view-details-priority") + HTMLWindow.MakeLink("live://property/priority-number",str_prio)),bgcol2)); ret=ret+HTMLWindow.MakeRow(""); ret=ret+HTMLWindow.EndTable(); ret=ret+HTMLWindow.StartTable("bgcolor=#000000D0 cellpadding=0 cellspacing=0 border=0"); ret=ret+HTMLWindow.MakeRow(HTMLWindow.MakeCell("","width=100%"),"height=1"); ret=ret+HTMLWindow.EndTable(); ret=ret+HTMLWindow.StartTable(); ret=ret+HTMLWindow.MakeRow(""); ret=ret+HTMLWindow.MakeRow(HTMLWindow.MakeCell(HTMLWindow.MakeImage(str_mykuidstr,true,64,32)+HTMLWindow.MakeCell("","width=10")+HTMLWindow.MakeCell(HTMLWindow.MakeBold(HTMLWindow.MakeFontColorBlack(str_myname))))); ret=ret+HTMLWindow.MakeRow(HTMLWindow.MakeCell(HTMLWindow.MakeFontColorBlack(ST.GetString("swiatla") + HTMLWindow.MakeLink("live://property/losw",ST.GetString("s"+osw))),bgcol)); ret=ret+HTMLWindow.MakeRow(HTMLWindow.MakeCell(GetCabDescr(),"width=100%")); ret=ret+HTMLWindow.MakeRow(HTMLWindow.MakeCell(HTMLWindow.MakeFontColorBlack(ST.GetString("pc2"))+HTMLWindow.CheckBox("live://property/lpc2",pc2),bgcol)); ret=ret+HTMLWindow.MakeRow(HTMLWindow.MakeCell(HTMLWindow.MakeFontColorBlack(ST.GetString("lampy"))+HTMLWindow.CheckBox("live://property/lkonc0",koncowki==0),bgcol2)); ret=ret+HTMLWindow.MakeRow(HTMLWindow.MakeCell(HTMLWindow.MakeFontColorBlack(ST.GetString("tarczki"))+HTMLWindow.CheckBox("live://property/lkonc1",koncowki==1),bgcol)); ret=ret+HTMLWindow.MakeRow(HTMLWindow.MakeCell(HTMLWindow.MakeFontColorBlack(ST.GetString("driver") + HTMLWindow.MakeLink("live://property/lmech",ST.GetString("cab_"+drivertype))),bgcol2)); ret=ret+HTMLWindow.MakeRow(HTMLWindow.MakeCell(HTMLWindow.MakeFontColorBlack(ST.GetString("secdriver"))+HTMLWindow.CheckBox("live://property/lsecond",sec_driver),bgcol)); ret=ret+HTMLWindow.MakeRow(HTMLWindow.MakeCell(HTMLWindow.MakeFontColorBlack(ST.GetString("sitting"))+HTMLWindow.CheckBox("live://property/lsit",sitting),bgcol2)); ret=ret+HTMLWindow.MakeRow(HTMLWindow.MakeCell(HTMLWindow.MakeFontColorBlack(ST.GetString("pantos") + HTMLWindow.MakeLink("live://property/lpant",ST.GetString("pant"+pantos))),bgcol)); ret=ret+HTMLWindow.MakeRow(HTMLWindow.MakeCell(HTMLWindow.MakeFontColorBlack(ST.GetString("st_physics"))+HTMLWindow.CheckBox("live://property/lphysics",bln_physics),bgcol2)); ret=ret+HTMLWindow.MakeRow(HTMLWindow.MakeCell(HTMLWindow.MakeFontColorBlack(ST.GetString("limit")+" ")+HTMLWindow.MakeFontColorBlack(HTMLWindow.MakeLink("live://property/llimit",stvrozkl)),bgcol)); if(bresopt) ret=ret+HTMLWindow.MakeRow(HTMLWindow.MakeCell(HTMLWindow.MakeFontColorBlack(HTMLWindow.MakeLink("live://property/lreset",ST.GetString("reset"))),bgcol2)); ret=ret+HTMLWindow.EndTable(); ret=ret+HTMLWindow.StartTable(); int int_state = trn_t.GetScheduleState(); if (int_state != Train.SS_NONE) { string str_schstate = trn_t.GetScheduleStateString(); ret = ret + HTMLWindow.MakeRow(HTMLWindow.MakeCell(HTMLWindow.MakeItalic(HTMLWindow.MakeFontColorBlack(BrowserInterface.Quote(str_schstate))))); } ret=ret+HTMLWindow.EndTable(); ret=ret+""; return ret; } // --------------------------------------------------------------- string GetPropertyType(string pID) { string[] str_token = Str.Tokens(pID,"/"); if(str_token[0] == "losw") { return "link"; } if(str_token[0] == "lpc2") { return "link"; } if(str_token[0] == "lphysics") { return "link"; } if(str_token[0] == "lreset") { return "link"; } if(str_token[0] == "lresopt") { return "link"; } if(str_token[0] == "lkonc0") { return "link"; } if(str_token[0] == "lkonc1") { return "link"; } if(str_token[0] == "da1") { return "link"; } if(str_token[0] == "db1") { return "link"; } if(str_token[0] == "lmech") { return "link"; } if(str_token[0] == "lsecond") { return "link"; } if(str_token[0] == "lsit") { return "link"; } if(str_token[0] == "lpant") { return "link"; } return inherited(pID); } // --------------------------------------------------------------- void BrowserClose(Message msg) { if (msg.src == viever) { viever = null; } } // --------------------------------------------------------------- void BrowserClick(Message msg) { if (msg.src == viever) { string propCmd = msg.minor[16, ]; if (propCmd == "priority-number") { GetMyTrain().SetTrainPriorityNumber((GetMyTrain().GetTrainPriorityNumber() % 3) + 1); } else if(propCmd == "losw") { osw = osw + 1; if(osw == 4) osw = 1; } else if(propCmd == "lpc2") { pc2 =! pc2; } else if(propCmd == "lkonc0") { koncowki =0; } else if(propCmd == "lkonc1") { koncowki =1; } else if(propCmd == "lreset") { if(me.GetMyTrain() != t) { AddHandler(me.GetMyTrain(),"Train","","Controls"); t = me.GetMyTrain(); Interface.Print("reset"); } } else if(propCmd == "lphysics") { bln_physics=!bln_physics; SetPhysics(bln_physics); } else if (propCmd== "da1") { da1=!da1; SetDoors(); } else if (propCmd=="lmech") { drivertype = drivertype + 1; if(drivertype == 4) drivertype = 0; SetMech(); } else if (propCmd=="lpant") { pantos = pantos + 1; if(pantos == 5) pantos = 0; SetPant(); } else if (propCmd== "lsecond") { sec_driver=!sec_driver; SetMech(); } else if (propCmd== "lsit") { sitting=!sitting; SetMech(); } else if (propCmd== "db1") { db1=!db1; SetDoors(); } else if(propCmd == "llimit") { vrozkl = vrozkl + 10; if(vrozkl == 110) vrozkl = 0; t = me.GetMyTrain(); t.SetAdvisoryLimit(vrozkl/3.6); } LampySprawdz(); ViewDetails(msg); } } // --------------------------------------------------------------- void ViewDetails(Message msg) { if (viever) { vdb_left = viever.GetWindowLeft(); vdb_top = viever.GetWindowTop(); vdb_right = viever.GetWindowRight(); vdb_bottom = viever.GetWindowBottom(); } else { viever = Constructors.NewBrowser(); } viever.SetWindowRect(vdb_left, vdb_top, vdb_right, vdb_bottom); viever.LoadHTMLString(ViewMyDetails()); } // --------------------------------------------------------------- void QMCAuto(Message msg) { if(msg.minor == "000") { LampySprawdz(); SetDoors(); } else if(msg.minor == "100") { osw = 1; LampySprawdz(); } else if(msg.minor == "101") { osw = 2; LampySprawdz(); } else if(msg.minor == "102") { osw = 3; LampySprawdz(); } else if(msg.minor == "103") { pc2 = true; LampySprawdz(); } else if(msg.minor == "104") { pc2 = false; LampySprawdz(); } else if(msg.minor == "507") { if(GetDirectionRelativeToTrain()) { da1 = true; } else { db1 = true; } SetDoors(); } else if(msg.minor == "506") { da1 = false; db1 = false; SetDoors(); } else if(msg.minor == "001") { if(me.GetMyTrain() != t) { AddHandler(me.GetMyTrain(),"Train","","Controls"); t = me.GetMyTrain(); Interface.Print("reset"); } } else if(msg.minor == "003") { bln_physics=true; SetPhysics(bln_physics); } else if(msg.minor == "002") { bln_physics=false; SetPhysics(bln_physics); } } // --------------------------------------------------------------- void Szybkosc1 (Message msg) { float vogra; t = me.GetMyTrain(); vogra = t.GetAdvisoryLimit(); if(vogra != vrozkl/3.6) t.SetAdvisoryLimit(vrozkl/3.6); } void Controls(Message msg) { if(msg.major == "World" and msg.minor == "ModuleInit") { AddHandler(me.GetMyTrain(),"Train","","Controls"); AddHandler(me,"QMC","","QMCAuto"); if (bln_physics) SetPhysics(bln_physics); t = me.GetMyTrain(); AddHandler(me.GetMyTrain(),"Train","Over advisory speed limit","Szybkosc1"); AddHandler(me.GetMyTrain(),"Train","Over speed limit" ,"Szybkosc1"); AddHandler(me.GetMyTrain(),"Trigger","Enter" ,"Szybkosc1"); AddHandler(me.GetMyTrain(),"Trigger","Leave" ,"Szybkosc1"); } else if(msg.src == me.GetMyTrain()) { if(msg.minor == "NotifyHeadlights") { if(GetMyTrain().GetHeadlightState()) { if(GetMyTrain().GetTrainPriorityNumber() == 3) GetMyTrain().SetTrainPriorityNumber(2); osw2=osw; osw=3; pc2=false; } else { osw=osw2; pc2=false; } LampySprawdz(); } else if(msg.minor == "StartedMoving" or msg.minor == "Deleted" or msg.minor == "TurnAround" ) { LampySprawdz(); SetMech(); SetPant(); } } else { } } // --------------------------------------------------------------- public void Init(void) { inherited(); if (!GetMyTrain()) return; sessionv = castWorld.GetLibrary(me.GetAsset().LookupKUIDTable("SessionV")); //Manual mode sharedLib = World.GetLibrary(me.GetAsset().LookupKUIDTable("SharedLib")); if (sharedLib) SetDeadmanMode(GetCTSHUDState()); else watchfulnessModeDist = 1550; VehicleControl(); Watchfulness(); ST = GetAsset().GetStringTable(); biale = GetAsset().FindAsset("corona-white"); czerwone = GetAsset().FindAsset("corona-red"); mech=GetAsset().FindAsset("mechanik"); pom=GetAsset().FindAsset("pomocnik"); mechs=GetAsset().FindAsset("mechaniks"); poms=GetAsset().FindAsset("pomocniks"); skp=GetAsset().FindAsset("skp"); PostMessage(me,"pfx","-0-1-2",1); osw=1; LampySprawdz(); AddHandler(me,"Browser-URL","","BrowserClick"); AddHandler(me,"Browser-Closed","","BrowserClose"); AddHandler(me,"World","","Controls"); SetMech(); //SetPant(); Train train = me.GetMyTrain(); // Yes our train could change after the init but // AddHandler(me,"Train","NotifyPantographs","PantoHandler"); // at that point the panto is most likely up already // me.Sniff(train, "Train", "StartedMoving", true); AddHandler(me, "Train", "StartedMoving", "AiCheck"); } thread void CalcPantz(Train train) { if (pantos < 4) { pantos++; train.SetPantographState(1); } else { // otherwise if its 4 the next position must be 0 pantos = 0; train.SetPantographState(0); } SetPant(); } void AiCheck(Message msg) { Train train = GetMyTrain(); if (msg.src == train) { int trainmode = train.GetAutopilotMode(); if(trainmode > 1) { pantos = 1; SetPant(); } } } void PantoHandler(Message msg) { Train train = GetMyTrain(); if (msg.src == train) { CalcPantz(train); } } };