|
|
|
@ -505,6 +505,8 @@ string Railways::GetDestBlock(int locoflags, string blockend) {
|
|
|
|
|
|
|
|
|
|
if (blockend[0] == '+') blockend = "+:" + blockn;
|
|
|
|
|
else blockend = "-:" + blockp;
|
|
|
|
|
|
|
|
|
|
block = blockend;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
block = blockend;
|
|
|
|
@ -514,7 +516,7 @@ string Railways::GetDestBlock(int locoflags, string blockend) {
|
|
|
|
|
, (block_f & BLOCK_F_SPLIT) ? 1 : 0
|
|
|
|
|
, block.c_str());
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
return block;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -572,6 +574,7 @@ int Railways::FindWay(string org_blockstart, string org_blockend, string lockedf
|
|
|
|
|
fd_end.enterfrom = fd_start.enterfrom = -1;
|
|
|
|
|
|
|
|
|
|
if (FindReference(&fd_start.x, &fd_start.y, blockstart.substr(2, string::npos))) {
|
|
|
|
|
debug (0, "Railway::FindWay found startblock (%s).", blockstart.c_str());
|
|
|
|
|
if (Get(fd_start.x, fd_start.y).dir == 1) {
|
|
|
|
|
if (blockstart[0] == '+') fd_start.enterfrom = 0;
|
|
|
|
|
else fd_start.enterfrom = 2;
|
|
|
|
@ -591,6 +594,7 @@ int Railways::FindWay(string org_blockstart, string org_blockend, string lockedf
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (FindReference(&fd_end.x, &fd_end.y, blockend.substr(2, string::npos))) {
|
|
|
|
|
debug (0, "Railway::FindWay found endblock (%s).", blockend.c_str());
|
|
|
|
|
if (Get(fd_end.x, fd_end.y).dir == 1) {
|
|
|
|
|
if (blockend[0] == '+') fd_end.enterfrom = 0;
|
|
|
|
|
else fd_end.enterfrom = 2;
|
|
|
|
@ -636,6 +640,7 @@ int Railways::FindWay(string org_blockstart, string org_blockend, string lockedf
|
|
|
|
|
}
|
|
|
|
|
else if (fd_pos.enterfrom >= 0 && fd_end.x == fd_pos.x && fd_pos.y == fd_end.y && fd_pos.enterfrom == fd_end.enterfrom) {
|
|
|
|
|
// destination found
|
|
|
|
|
debug (0, "Railway::FindWay %s:%d found way.", __FILE__, __LINE__);
|
|
|
|
|
found = 1;
|
|
|
|
|
*next = fd_pos.way + ",b:" + blockend;
|
|
|
|
|
fd_pos.enterfrom = -1;
|
|
|
|
@ -715,6 +720,7 @@ int Railways::FindWay(string org_blockstart, string org_blockend, string lockedf
|
|
|
|
|
}
|
|
|
|
|
else if (rpos->type == RAILWAY_BLOCK) {
|
|
|
|
|
int blflags = server->blocks.GetFlags(rpos->name);
|
|
|
|
|
debug (0, "Railways::FindWay %s:%d found block: %s", __FILE__, __LINE__, rpos->name);
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// check if block is available for entering
|
|
|
|
@ -768,7 +774,7 @@ int Railways::FindWay(string org_blockstart, string org_blockend, string lockedf
|
|
|
|
|
//
|
|
|
|
|
// check if way found a block.
|
|
|
|
|
size_t npos;
|
|
|
|
|
if ((npos = next->find(",b:")) != string::npos)
|
|
|
|
|
if ((npos = next->rfind(",b:")) != string::npos)
|
|
|
|
|
*next = next->substr(0, next->find(",", npos+1));
|
|
|
|
|
else // nothing found?
|
|
|
|
|
*next = "";
|
|
|
|
@ -1098,8 +1104,6 @@ int Railways::FindRandomWay(string blockstart, string lockedfor, string *next) {
|
|
|
|
|
* try to lock or unlock the way for the loco(lockedby)
|
|
|
|
|
* Will also do the check for long trains and split blocks.
|
|
|
|
|
*/
|
|
|
|
|
#warning check for split blocks and long trains not yet finished.
|
|
|
|
|
//FIXME: check for split blocks and long trains not yet finished.
|
|
|
|
|
int Railways::LockWay (string way, string lockedby, int lockonoff) {
|
|
|
|
|
int res = 0;
|
|
|
|
|
size_t pos1, pos2;
|
|
|
|
@ -1107,10 +1111,12 @@ int Railways::LockWay (string way, string lockedby, int lockonoff) {
|
|
|
|
|
struct s_findway_data start;
|
|
|
|
|
struct s_findway_data end;
|
|
|
|
|
struct s_findway_data pos;
|
|
|
|
|
string startblock, endblock;
|
|
|
|
|
string startblock, endblock, endblock2;
|
|
|
|
|
Railway *r;
|
|
|
|
|
int finished = 0;
|
|
|
|
|
JSONParse jp;
|
|
|
|
|
int locoflags = 0;
|
|
|
|
|
int blockflags = 0;
|
|
|
|
|
|
|
|
|
|
debug (0, "* LockWay Way:'%s' for '%s' lockonoff:%d", way.c_str(), lockedby.c_str(), lockonoff);
|
|
|
|
|
|
|
|
|
@ -1118,16 +1124,25 @@ int Railways::LockWay (string way, string lockedby, int lockonoff) {
|
|
|
|
|
end.y = start.y = -1;
|
|
|
|
|
end.enterfrom = start.enterfrom = -1;
|
|
|
|
|
|
|
|
|
|
if ((pos1 = way.find("b:", 0)) == string::npos) return 0;
|
|
|
|
|
if ((pos1 = way.find("b:")) == string::npos) return 0;
|
|
|
|
|
if ((pos2 = way.find(",", pos1+1)) == string::npos) return 0;
|
|
|
|
|
startblock = way.substr (pos1+2, pos2-pos1-2);
|
|
|
|
|
|
|
|
|
|
if ((pos1 = way.find(",b:", 0)) == string::npos) return 0;
|
|
|
|
|
if ((pos1 = way.rfind(",b:")) == string::npos) return 0;
|
|
|
|
|
if ((pos2 = way.find(",", pos1+1)) == string::npos) endblock = way.substr (pos1+3, pos2);
|
|
|
|
|
else endblock = way.substr (pos1+3, pos2-pos1-3);
|
|
|
|
|
|
|
|
|
|
printf ("%s:%d LockWay Way: '%s' Startblock: '%s' Endblock: '%s'\n", __FILE__, __LINE__, way.c_str(),
|
|
|
|
|
startblock.c_str(), endblock.c_str());
|
|
|
|
|
//
|
|
|
|
|
// take care of split blocks and long trains.
|
|
|
|
|
// if the second block is not needed endblock2 will remain empty
|
|
|
|
|
locoflags = server->locomotives.GetFlags(lockedby);
|
|
|
|
|
blockflags = server->blocks.GetFlags(endblock.substr(2, string::npos));
|
|
|
|
|
if (!(locoflags & LOCO_F_SHORTTRAIN) && (blockflags & BLOCK_F_SPLIT))
|
|
|
|
|
endblock2 = server->blocks.GetSecondBlock(endblock.substr(2, string::npos));
|
|
|
|
|
else endblock2 = "";
|
|
|
|
|
debug (0, "%s:%d LockWay Way: '%s' Startblock: '%s' Endblock: '%s' Endblock2: '%s'", __FILE__, __LINE__, way.c_str(),
|
|
|
|
|
startblock.c_str(), endblock.c_str(), endblock2.c_str());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// find start position
|
|
|
|
@ -1148,8 +1163,9 @@ int Railways::LockWay (string way, string lockedby, int lockonoff) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// find end position, this needs to take care of the SPLIT blocks.
|
|
|
|
|
// if split BLOCK and LONG train check for the currect end block
|
|
|
|
|
// find end position. Long trains and Split blocks is being taken care of in
|
|
|
|
|
// the Findwaypart.
|
|
|
|
|
// when unlocking we are not unlocking the way between these blocks.
|
|
|
|
|
if (FindReference(&end.x, &end.y, endblock.substr(2,string::npos))) {
|
|
|
|
|
if (Get(end.x, end.y).dir == 1) {
|
|
|
|
|
if (endblock[0] == '+') end.enterfrom = 0;
|
|
|
|
@ -1192,7 +1208,9 @@ int Railways::LockWay (string way, string lockedby, int lockonoff) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// do lock start and endpoint... unlock only start
|
|
|
|
|
if (pos.x == end.x && pos.y == end.y && r->type == RAILWAY_BLOCK) {
|
|
|
|
|
if ((pos.x == end.x && pos.y == end.y) || (r->type == RAILWAY_BLOCK &&
|
|
|
|
|
((endblock.compare(r->name) == 0) ||
|
|
|
|
|
(endblock2.length() > 0 && endblock2.compare(r->name) == 0)))) {
|
|
|
|
|
if (lockonoff == 1) {
|
|
|
|
|
UnLock();
|
|
|
|
|
server->blocks.SetLockedby(r->name, lockedby, 1);
|
|
|
|
@ -1220,11 +1238,21 @@ int Railways::LockWay (string way, string lockedby, int lockonoff) {
|
|
|
|
|
if(network) network->ChangeListPushToAll(jp.ToString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((pos.x == end.x && pos.y == end.y) || pos.x < 0 || pos.y < 0 || pos.x >= width || pos.y >= height) {
|
|
|
|
|
if (pos.x < 0 || pos.y < 0 || pos.x >= width || pos.y >= height) {
|
|
|
|
|
server->interfaces.PowerOnOff(false);
|
|
|
|
|
debug (0, "Railway::LockWay %s:%d Error: routing out of surface [%d,%d]", __FILE__, __LINE__, pos.x, pos.y);
|
|
|
|
|
finished = 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((pos.x == end.x && pos.y == end.y) ||
|
|
|
|
|
(lockonoff == 0 &&
|
|
|
|
|
((endblock.compare(r->name) == 0) ||
|
|
|
|
|
(endblock2.length() > 0 && endblock2.compare(r->name) == 0)))) {
|
|
|
|
|
finished = 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// go to next position
|
|
|
|
|
if (r->type == RAILWAY_TURNOUT) {
|
|
|
|
|
if (curwaypos == string::npos) { // we should have a turnout
|
|
|
|
|