diff --git a/ChangeLog b/ChangeLog index eee46b2..92cc33c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2023-12-30: +- fixed: FindWay will check for loops between two blocks + 2023-12-27: - split blocks do work. - fixed issues with the way finding routine diff --git a/server/locomotive.cc b/server/locomotive.cc index 9924c2e..53ad296 100644 --- a/server/locomotive.cc +++ b/server/locomotive.cc @@ -707,11 +707,14 @@ int Locomotives::AutoCheckWaySingleStep(string way, string locname, int *data) { int res = 0; size_t pos1; size_t curpos; + size_t blockpos; int state; int newdata = 0; if (*data < 0) *data = 0; + debug (0, "Locomotives::AutoCheckWaySingleStep Way:%s", way.c_str()); + curpos = 0; do { curpos = way.find (",t:", curpos+1); @@ -929,12 +932,12 @@ int Locomotives::Loco_OnRoute(Locomotive *loco) { if (Loco_SearchAndLock(loco) == 1) { loco->auto_onroute = LOCO_OR_ENTERBLOCKNEXT; debug (0, "Locomotives::Loco_OnRoute Found Way Prepare '%s'\n", loco->name); - SetSpeed(loco->name, loco->vmid); + SetSpeed(loco->name, loco->flags & LOCO_F_REVERSE ? -loco->vmin : loco->vmid); } else { loco->auto_onroute = LOCO_OR_ENTERBLOCKSTOP; debug (0, "Locomotives::Loco_OnRoute Slow Down '%s'\n", loco->name); - SetSpeed(loco->name, loco->vslow); + SetSpeed(loco->name, loco->flags & LOCO_F_REVERSE ? -loco->vslow : loco->vslow); } return 1; @@ -1064,7 +1067,6 @@ int Locomotives::Loop() { string way; Locomotive *loco = NULL; JSONParse jp; - int reverse = 1; for (lnum = 0; lnum < max; lnum++) if (locomotives[lnum].name[0] != 0) { loco = &locomotives[lnum]; @@ -1122,7 +1124,7 @@ int Locomotives::Loop() { } else { // nothing found -> try reverse - if (loco->blockassign[0] != 0 && (loco->flags & LOCO_F_CANREVERSE)) { + if (loco->blockassign[0] != 0 && loco->blockdest[0] != 0 && (loco->flags & LOCO_F_CANREVERSE)) { debug (0, "* Loco_SearchAndLock Reverse Loco %s", loco->name); if (loco->blockassign[0] == '-') loco->blockassign[0] = '+'; else if (loco->blockassign[0] == '+') loco->blockassign[0] = '-'; @@ -1143,7 +1145,7 @@ int Locomotives::Loop() { else if (loco->auto_onroute == LOCO_OR_PREPARE) { switch (Loco_PrepareWay(loco)) { case 1: - SetSpeed(loco->name, reverse * loco->vmid); + 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); jp.Clear(); @@ -1151,7 +1153,7 @@ int Locomotives::Loop() { if(network) network->ChangeListPushToAll(jp.ToString()); break; case 2: - SetSpeed(loco->name, reverse * loco->vfast); + 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); jp.Clear(); @@ -1183,7 +1185,7 @@ int Locomotives::Loop() { else if (loco->auto_onroute == LOCO_OR_ENTERBLOCKNEXT) { switch (Loco_BlockEnterNext(loco)) { case 1: - SetSpeed(loco->name, reverse * loco->vmid); + 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); jp.Clear(); @@ -1191,7 +1193,7 @@ int Locomotives::Loop() { if(network) network->ChangeListPushToAll(jp.ToString()); break; case 2: - SetSpeed(loco->name, reverse * loco->vfast); + SetSpeed(loco->name, loco->flags & LOCO_F_REVERSE ? -loco->vfast : loco->vfast); loco->auto_onroute = LOCO_OR_ONTHEWAY; debug (0, "* Locomotive LOCO_OR_ENTERBLOCKNEXT '%s' Way Prepared -> Speed: VFAST", loco->name); jp.Clear(); diff --git a/server/railway.cc b/server/railway.cc index 931aa74..c45812a 100644 --- a/server/railway.cc +++ b/server/railway.cc @@ -771,6 +771,10 @@ int Railways::FindWay(string org_blockstart, string org_blockend, string lockedf if (found == 0) *next = ""; else { + // + // do final checks: + // + // // check if way found a block. size_t npos; @@ -778,6 +782,8 @@ int Railways::FindWay(string org_blockstart, string org_blockend, string lockedf *next = next->substr(0, next->find(",", npos+1)); else // nothing found? *next = ""; + + if (!FindWayCheckIfNoDoubleTurnouts (next)) *next = ""; } UnLock(); @@ -789,6 +795,23 @@ int Railways::FindWay(string org_blockstart, string org_blockend, string lockedf }; +int Railways::FindWayCheckIfNoDoubleTurnouts (string *way) { + size_t pos1, pos2; // block positions + size_t tp1, tp2; // turnouts + + for (pos1 = 0, pos2 = way->find(",b:"); pos2 != string::npos; pos1 = pos2, pos2 = way->find(",b:", pos1+1)) { + tp1 = pos1; + for (tp1 = way->find(",t:", tp1+1); tp1 != string::npos; tp1 = way->find(",t:", tp1+1)) { + tp2 = way->find (way->substr(tp1, way->find(":", tp1+4)-tp1), tp1+1); + if (tp2 == string::npos) continue; // not found + if (tp2 < pos2) return 0; // found ... return 0 + } + } + + return 1; +} + + /* * check if the position in fwd.x|y is valid for the loco. The check will only done on * RAILWAY_BLOCK types. It will also check if the block is free. diff --git a/server/railway.h b/server/railway.h index 116dd36..09fd5ca 100644 --- a/server/railway.h +++ b/server/railway.h @@ -129,6 +129,7 @@ class Railways { int FindReference(int *x, int *y, string name); int FindWay(string blockstart, string blockend, string lockedfor, string *next); + int FindWayCheckIfNoDoubleTurnouts (string *next); int FindRandomWay(string blockstart, string lockedfor, string *next); int LockWay (string way, string lockedby, int lockonoff); int LockWay (string way, string lockedby) { return LockWay(way, lockedby, 1); };