diff --git a/server/block.cc b/server/block.cc index 76f9a79..c89c5a3 100644 --- a/server/block.cc +++ b/server/block.cc @@ -303,6 +303,20 @@ void Blocks::ClearLockedby(string name) { }; +int Blocks::GetFlags (string blname) { + int res = 0; + int i; + JSONParse jp; + + Lock(); + for (i = 0; i < max; i++) if (blname.compare(blocks[i].name) == 0) { + res = blocks[i].flags; + } + UnLock(); + return res; +}; + + string Blocks::GetSensorMinus (string blname) { string res = ""; int i; diff --git a/server/block.h b/server/block.h index 1d23c4f..dc3c7ed 100644 --- a/server/block.h +++ b/server/block.h @@ -58,6 +58,7 @@ class Blocks { string GetSensorMinus (string blname); string GetSensorCenter (string blname); string GetSensorPlus (string blname); + int GetFlags (string blname); int SetLockedby (string blname, string lockedby, int lock_onoff); string GetLockedby (string blname); diff --git a/server/locomotive.cc b/server/locomotive.cc index a41c546..c66bf18 100644 --- a/server/locomotive.cc +++ b/server/locomotive.cc @@ -559,7 +559,6 @@ int Locomotives::AutoCheckWaySingleStep(string way, string locname, int *data) { } - int Locomotives::Loop() { int lnum, i; string way; @@ -567,9 +566,13 @@ int Locomotives::Loop() { string block; string sensor; JSONParse jp; + int reverse = 1; for (lnum = 0; lnum < max; lnum++) if (locomotives[lnum].name[0] != 0) { loco = &locomotives[lnum]; + if (loco->flags & LOCO_F_REVERSE) reverse = -1; + else reverse = 1; + if (loco->flags & LOCO_F_AUTO) { // // only in automate do anything alone @@ -582,6 +585,9 @@ int Locomotives::Loop() { } else if (loco->auto_onroute == LOCO_OR_SEARCH) { + // + // find way, if nothing found check if we can reverse direction + // if (loco->auto_timenext.tv_sec == 0 || timer_get(&loco->auto_timenext) > LOCO_TO_TRYAGAIN) { if (server->railways.FindWay(loco->blockassign, loco->blockdest, loco->name, &way)) { size_t pos; @@ -596,15 +602,28 @@ int Locomotives::Loop() { else timer_start(&loco->auto_timenext); } } - else timer_start(&loco->auto_timenext); + else { + if (loco->blockassign[0] != 0 && (loco->flags & LOCO_F_CANREVERSE)) { + if (loco->blockassign[0] == '-') loco->blockassign[0] = '+'; + else if (loco->blockassign[0] == '+') loco->blockassign[0] = '-'; + + if (loco->flags & LOCO_F_REVERSE) loco->flags &= ~LOCO_F_REVERSE; + else loco->flags |= LOCO_F_REVERSE; + } + timer_start(&loco->auto_timenext); + } } } else if (loco->auto_onroute == LOCO_OR_PREPARE) { + block = loco->blocknext+2; + if (loco->auto_timenext.tv_sec == 0 || timer_get(&loco->auto_timenext) > LOCO_TO_TURNOUT) { if (AutoCheckWaySingleStep(loco->auto_way, loco->name, &loco->auto_data) == 1) { - if (loco->flags & LOCO_F_CARGO) SetSpeed(loco->name, loco->vmid); - else SetSpeed(loco->name, loco->vfast); + if ((loco->flags & LOCO_F_CARGO) || + (server->blocks.GetFlags(block) & BLOCK_F_SPEEDLIMIT)) + SetSpeed(loco->name, reverse * loco->vmid); + else SetSpeed(loco->name, reverse * loco->vfast); loco->auto_onroute = LOCO_OR_ONTHEWAY; } else timer_start(&loco->auto_timenext); @@ -638,7 +657,7 @@ int Locomotives::Loop() { printf ("%s:%d LOCO_OR_ONTHEWAY enter assign == dest stop\n", __FILE__, __LINE__); loco->blockdest[0] = 0; loco->auto_onroute = LOCO_OR_ENTERBLOCKSTOP; - SetSpeed(loco->name, loco->vslow); + SetSpeed(loco->name, reverse * loco->vslow); } else { // try to find new way @@ -655,17 +674,17 @@ int Locomotives::Loop() { } else { loco->auto_onroute = LOCO_OR_ENTERBLOCKSTOP; - SetSpeed(loco->name, loco->vslow); + SetSpeed(loco->name, reverse * loco->vslow); } } else { loco->auto_onroute = LOCO_OR_ENTERBLOCKSTOP; - SetSpeed(loco->name, loco->vslow); + SetSpeed(loco->name, reverse * loco->vslow); } } else { loco->auto_onroute = LOCO_OR_ENTERBLOCKSTOP; - SetSpeed(loco->name, loco->vslow); + SetSpeed(loco->name, reverse * loco->vslow); } } @@ -676,7 +695,7 @@ int Locomotives::Loop() { if (loco->auto_onroute == LOCO_OR_ONTHEWAY) { loco->auto_onroute = LOCO_OR_ENTERBLOCKSTOP; - SetSpeed(loco->name, loco->vslow); + SetSpeed(loco->name, reverse * loco->vslow); } } } @@ -734,6 +753,10 @@ int Locomotives::Loop() { timer_start(&loco->auto_timenext); } else { + if (server->blocks.GetFlags(block) & BLOCK_F_SPEEDLIMIT) { + SetSpeed(loco->name, reverse * loco->vmid); + } + loco->auto_onroute = LOCO_OR_ONTHEWAY; } }