|
|
|
|
@ -5,6 +5,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Locomotives::Locomotives () {
|
|
|
|
|
pthread_mutex_init(&mtx, NULL);
|
|
|
|
|
changed = 0;
|
|
|
|
|
locomotives = (Locomotive*) malloc(sizeof(Locomotive)*LOCOMOTIVES_MAX);
|
|
|
|
|
memset(locomotives, 0x0, sizeof(Locomotive)*LOCOMOTIVES_MAX);
|
|
|
|
|
@ -703,7 +704,7 @@ int Locomotives::SchedulerNextStep(Locomotive *loc) {
|
|
|
|
|
// with each call only check one single step of the way, if we have to
|
|
|
|
|
// turn a turnout try to do it and return 0.
|
|
|
|
|
// if everything is set up till the destination (next) block return 1
|
|
|
|
|
// to speed things up: we only prepare ways wich we have locked already
|
|
|
|
|
// to speed things up: we only prepare ways which we have locked already
|
|
|
|
|
//
|
|
|
|
|
int Locomotives::AutoCheckWaySingleStep(string way, string locname, int *data) {
|
|
|
|
|
int res = 0;
|
|
|
|
|
@ -719,10 +720,12 @@ int Locomotives::AutoCheckWaySingleStep(string way, string locname, int *data) {
|
|
|
|
|
|
|
|
|
|
if (*data < 0) *data = 0;
|
|
|
|
|
|
|
|
|
|
debug (0, "Locomotives::AutoCheckWaySingleStep Prepare for Loco: %s Way:%s", locname.c_str(), way.c_str());
|
|
|
|
|
debug (0, "Locomotives::AutoCheckWaySingleStep Prepare for Loco: %s Way:%s data:%d", locname.c_str(), way.c_str(), *data);
|
|
|
|
|
|
|
|
|
|
curpos = 0;
|
|
|
|
|
do {
|
|
|
|
|
//
|
|
|
|
|
// read all ways from the begin with stop at "data"
|
|
|
|
|
curpos = way.find (",t:", curpos+1);
|
|
|
|
|
newdata++;
|
|
|
|
|
if (curpos != string::npos) {
|
|
|
|
|
@ -747,27 +750,33 @@ int Locomotives::AutoCheckWaySingleStep(string way, string locname, int *data) {
|
|
|
|
|
while (server->railways.FindReference(&x, &y, turnout, cnt++)) {
|
|
|
|
|
cnt++;
|
|
|
|
|
r = server->railways.RailwayGet(x, y);
|
|
|
|
|
debug (0, "Locomotives::AutoCheckWaySingleStep Loco:%s Turnout: %s LockedBy:%s", locname.c_str(), turnout.c_str(), r.lockedby);
|
|
|
|
|
debug (0, "Locomotives::AutoCheckWaySingleStep Loco:%s Turnout:%s LockedBy:%s", locname.c_str(), turnout.c_str(), r.lockedby);
|
|
|
|
|
|
|
|
|
|
if (locname.compare(r.lockedby) == 0) {
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
if (locname.compare(r.lockedby) == 0 || r.lockedby[0] == 0) {
|
|
|
|
|
if (way[pos1+1] == '0' && state != 0) {
|
|
|
|
|
debug (0, "Locomotives::AutoCheckWaySingleStep Loco:%s Turnout:%s Not Equal -> Set:0", locname.c_str(), turnout.c_str());
|
|
|
|
|
server->turnouts.Set(way.substr(curpos+3, pos1-curpos-3), 0);
|
|
|
|
|
break;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
else if (way[pos1+1] == '1' && state != 1) {
|
|
|
|
|
debug (0, "Locomotives::AutoCheckWaySingleStep Loco:%s Turnout:%s Not Equal -> Set:1", locname.c_str(), turnout.c_str());
|
|
|
|
|
server->turnouts.Set(way.substr(curpos+3, pos1-curpos-3), 1);
|
|
|
|
|
break;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
else if (newdata > *data) {
|
|
|
|
|
debug (0, "Locomotives::AutoCheckWaySingleStep Loco:%s Turnout:%s Equal Reset:%c", locname.c_str(), turnout.c_str(), way[pos1+1]);
|
|
|
|
|
if (way[pos1+1] == '0') server->turnouts.Set(way.substr(curpos+3, pos1-curpos-3), 0);
|
|
|
|
|
if (way[pos1+1] == '1') server->turnouts.Set(way.substr(curpos+3, pos1-curpos-3), 1);
|
|
|
|
|
(*data) = newdata;
|
|
|
|
|
break;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (cnt == 0) {
|
|
|
|
|
debug (0, "Locomotives::AutoCheckWaySingleStep Loco:%s Turnout:%s Reference not found", locname.c_str(), turnout.c_str());
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} while (curpos != string::npos);
|
|
|
|
|
@ -1176,7 +1185,7 @@ int Locomotives::Loop() {
|
|
|
|
|
case 1:
|
|
|
|
|
SetSpeed(loco->name, loco->flags & LOCO_F_REVERSE ? -loco->vmid : loco->vmid);
|
|
|
|
|
loco->auto_onroute = LOCO_OR_ONTHEWAY;
|
|
|
|
|
debug (0, "* Locomotive '%s' Way Prepared -> Speed: VMID", loco->name);
|
|
|
|
|
debug (0, "* %s:%d Locomotive '%s' Way Prepared -> Speed: VMID", __FILE__, __LINE__, loco->name);
|
|
|
|
|
jp.Clear();
|
|
|
|
|
jp.AddObject("locomotive",_GetJSON(lnum));
|
|
|
|
|
if(network) network->ChangeListPushToAll(jp.ToString());
|
|
|
|
|
@ -1184,7 +1193,7 @@ int Locomotives::Loop() {
|
|
|
|
|
case 2:
|
|
|
|
|
SetSpeed(loco->name, loco->flags & LOCO_F_REVERSE ? -loco->vfast : loco->vfast);
|
|
|
|
|
loco->auto_onroute = LOCO_OR_ONTHEWAY;
|
|
|
|
|
debug (0, "* Locomotive '%s' Way Prepared -> Speed: VFAST", loco->name);
|
|
|
|
|
debug (0, "* %s:%d Locomotive '%s' Way Prepared -> Speed: VFAST", __FILE__, __LINE__, loco->name);
|
|
|
|
|
jp.Clear();
|
|
|
|
|
jp.AddObject("locomotive",_GetJSON(lnum));
|
|
|
|
|
if(network) network->ChangeListPushToAll(jp.ToString());
|
|
|
|
|
@ -1216,7 +1225,7 @@ int Locomotives::Loop() {
|
|
|
|
|
case 1:
|
|
|
|
|
SetSpeed(loco->name, loco->flags & LOCO_F_REVERSE ? -loco->vmid : loco->vmid);
|
|
|
|
|
loco->auto_onroute = LOCO_OR_ONTHEWAY;
|
|
|
|
|
debug (0, "* Locomotive LOCO_OR_ENTERBLOCKNEXT '%s' Way Prepared -> Speed: VMID", loco->name);
|
|
|
|
|
debug (0, "* %s:%d Locomotive LOCO_OR_ENTERBLOCKNEXT '%s' Way Prepared -> Speed: VMID", __FILE__, __LINE__, loco->name);
|
|
|
|
|
jp.Clear();
|
|
|
|
|
jp.AddObject("locomotive",_GetJSON(lnum));
|
|
|
|
|
if(network) network->ChangeListPushToAll(jp.ToString());
|
|
|
|
|
|