|
|
|
@ -40,7 +40,9 @@ int Railways::UnLock() {
|
|
|
|
|
//
|
|
|
|
|
// data must be mutex looked before use
|
|
|
|
|
struct s_findway_data Railways::NextPos(struct s_findway_data pos, int dirtype) {
|
|
|
|
|
struct s_findway_data np = { x: -1, y: -1, enterfrom: -1, parma: pos.parma }; // newpos
|
|
|
|
|
struct s_findway_data np = { x: -1, y: -1, enterfrom: -1, oldx: pos.x, oldy:pos.y,
|
|
|
|
|
oldenterfrom: pos.enterfrom, parma: pos.parma,
|
|
|
|
|
way: pos.way }; // newpos
|
|
|
|
|
|
|
|
|
|
if (dirtype == 1) {
|
|
|
|
|
if (pos.enterfrom == EF_NORTH) {
|
|
|
|
@ -394,7 +396,6 @@ void Railways::ClearLockedby(string name) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int Railways::_FindReference(int *x, int *y, string name) {
|
|
|
|
|
int found = 0;
|
|
|
|
|
if (x == NULL || y == NULL) return 0;
|
|
|
|
@ -485,11 +486,16 @@ void Railways::DebugPrintFindWay(struct s_findway_map *fw) {
|
|
|
|
|
printf ("Debug Finished\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// FindWay: will be in two phases to decide where to go and how
|
|
|
|
|
// 1. check all possible ways in respect of (out of service blocks)
|
|
|
|
|
// 2.
|
|
|
|
|
// return 0 if no way found
|
|
|
|
|
int Railways::FindWay(string blockstart, string blockend, string lockedfor, string *next) {
|
|
|
|
|
// direction 0 ... RIGHT and DOWN
|
|
|
|
|
// direction 1 ... LEFT and UP
|
|
|
|
|
|
|
|
|
|
struct s_findway_data fd_pos;
|
|
|
|
|
struct s_findway_data fd_tmp;
|
|
|
|
|
struct s_findway_data fd_start;
|
|
|
|
@ -528,6 +534,7 @@ int Railways::FindWay(string blockstart, string blockend, string lockedfor, stri
|
|
|
|
|
if (blockstart[0] == '+') fd_start.enterfrom = 3;
|
|
|
|
|
else fd_start.enterfrom = 1;
|
|
|
|
|
}
|
|
|
|
|
fd_start.way = "b:" + blockstart;
|
|
|
|
|
fd_data[GetRIdx(fd_start.x, fd_start.y)].e = (1 << fd_start.enterfrom);
|
|
|
|
|
fd_data[GetRIdx(fd_start.x, fd_start.y)].score = 1;
|
|
|
|
|
fd_start.parma = 1;
|
|
|
|
@ -547,6 +554,7 @@ int Railways::FindWay(string blockstart, string blockend, string lockedfor, stri
|
|
|
|
|
if (blockend[0] == '+') fd_end.enterfrom = 3;
|
|
|
|
|
else fd_end.enterfrom = 1;
|
|
|
|
|
}
|
|
|
|
|
fd_end.way = blockend;
|
|
|
|
|
fd_data[GetRIdx(fd_end.x, fd_end.y)].e = (1 << fd_end.enterfrom);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
@ -561,7 +569,9 @@ int Railways::FindWay(string blockstart, string blockend, string lockedfor, stri
|
|
|
|
|
Lock();
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// loop through the map; if found next needs to be filled in
|
|
|
|
|
// loop through the map to find all possible ways to the destination
|
|
|
|
|
// this will be done in respect of lockedby blocks and ways.
|
|
|
|
|
//
|
|
|
|
|
while ((fd_list.size() > 0 || fd_pos.enterfrom >= 0) && found == 0) {
|
|
|
|
|
DebugPrintFindWay(fd_data);
|
|
|
|
|
if (fd_pos.enterfrom < 0) {
|
|
|
|
@ -582,13 +592,17 @@ int Railways::FindWay(string blockstart, string blockend, string lockedfor, stri
|
|
|
|
|
fd_pos.enterfrom = -1;
|
|
|
|
|
fd_pos.x = -1;
|
|
|
|
|
fd_pos.y = -1;
|
|
|
|
|
fd_pos.way = "";
|
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
printf ("%s:%d destination found fd_pos (%d,%d) fd_end (%d,%d)\n", __FILE__, __LINE__, fd_pos.x, fd_pos.y, fd_end.x, fd_end.y);
|
|
|
|
|
printf ("%s:%d destination found fd_pos (%d,%d) fd_end (%d,%d) next:%s\n", __FILE__, __LINE__, fd_pos.x, fd_pos.y, fd_end.x, fd_end.y, fd_pos.way.c_str());
|
|
|
|
|
found = 1;
|
|
|
|
|
*next = fd_pos.way + ",b:" + blockend;
|
|
|
|
|
fd_pos.enterfrom = -1;
|
|
|
|
|
fd_pos.x = -1;
|
|
|
|
|
fd_pos.y = -1;
|
|
|
|
|
fd_pos.way = "";
|
|
|
|
|
}
|
|
|
|
|
else if (fd_pos.enterfrom >= 0 && fd_start.x == fd_pos.x && fd_start.y == fd_pos.y && fd_start.enterfrom == fd_pos.enterfrom) {
|
|
|
|
|
// start found
|
|
|
|
@ -596,6 +610,7 @@ int Railways::FindWay(string blockstart, string blockend, string lockedfor, stri
|
|
|
|
|
fd_pos.enterfrom = -1;
|
|
|
|
|
fd_pos.x = -1;
|
|
|
|
|
fd_pos.y = -1;
|
|
|
|
|
fd_pos.way = "";
|
|
|
|
|
}
|
|
|
|
|
else if (fd_data[GetRIdx(fd_pos.x, fd_pos.y)].e & (1 << fd_pos.enterfrom)) {
|
|
|
|
|
// old entry found
|
|
|
|
@ -603,6 +618,7 @@ int Railways::FindWay(string blockstart, string blockend, string lockedfor, stri
|
|
|
|
|
fd_pos.enterfrom = -1;
|
|
|
|
|
fd_pos.x = -1;
|
|
|
|
|
fd_pos.y = -1;
|
|
|
|
|
fd_pos.way = "";
|
|
|
|
|
}
|
|
|
|
|
else if (fd_pos.enterfrom >= 0) {
|
|
|
|
|
rpos = &railways[GetRIdx(fd_pos.x, fd_pos.y)];
|
|
|
|
@ -611,14 +627,24 @@ int Railways::FindWay(string blockstart, string blockend, string lockedfor, stri
|
|
|
|
|
if (rpos->type == RAILWAY_NORMAL || rpos->type == RAILWAY_SENSOR) {
|
|
|
|
|
fd_pos = NextPos(fd_pos, rpos->dir);
|
|
|
|
|
fd_pos.parma++;
|
|
|
|
|
rnext = &railways[GetRIdx(fd_pos.x, fd_pos.y)];
|
|
|
|
|
if (rnext->lockedby[0] != 0) {
|
|
|
|
|
printf ("%s:%d railway is locked by %s\n", __FILE__, __LINE__, rnext->lockedby);
|
|
|
|
|
fd_pos.enterfrom = -1;
|
|
|
|
|
fd_pos.x = -1;
|
|
|
|
|
fd_pos.y = -1;
|
|
|
|
|
fd_pos.way = "";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (rpos->type == RAILWAY_TURNOUT) {
|
|
|
|
|
fd_tmp = NextPos(fd_pos, rpos->altdir);
|
|
|
|
|
fd_tmp.way += (string)",t:" + (string)rpos->name + (string)":1";
|
|
|
|
|
printf ("%s:%d turnout dir:%d altdir:%d fd_pos (%d,%d -> %d) fd_tmp (%d,%d -> %d)\n", __FILE__, __LINE__, rpos->dir, rpos->altdir, fd_pos.x, fd_pos.y, fd_pos.enterfrom, fd_tmp.x, fd_tmp.y, fd_tmp.enterfrom);
|
|
|
|
|
fd_tmp.parma++;
|
|
|
|
|
fd_tmp.parma += 10; // 10 bad point for using the turnout
|
|
|
|
|
fd_list.push_back(fd_tmp);
|
|
|
|
|
fd_pos = NextPos(fd_pos, rpos->dir);
|
|
|
|
|
fd_pos.way += (string)",t:" + (string)rpos->name + (string)":0";
|
|
|
|
|
fd_pos.parma++;
|
|
|
|
|
printf ("%s:%d turnout fd_newpos (%d,%d -> %d)\n", __FILE__, __LINE__, fd_pos.x, fd_pos.y, fd_pos.enterfrom);
|
|
|
|
|
}
|
|
|
|
@ -627,10 +653,14 @@ int Railways::FindWay(string blockstart, string blockend, string lockedfor, stri
|
|
|
|
|
int found = 0;
|
|
|
|
|
|
|
|
|
|
printf ("%s:%d connector found Reference:'%s'\n", __FILE__, __LINE__, rpos->name);
|
|
|
|
|
|
|
|
|
|
x = -1;
|
|
|
|
|
y = -1;
|
|
|
|
|
while (found == 0 && _FindReference(&x, &y, rpos->name) == 1) {
|
|
|
|
|
if (fd_pos.x != x || fd_pos.y != y) {
|
|
|
|
|
printf ("%s:%d found %d,%d\n", __FILE__, __LINE__, x, y);
|
|
|
|
|
fd_pos.oldx = fd_pos.x;
|
|
|
|
|
fd_pos.oldy = fd_pos.y;
|
|
|
|
|
fd_pos.oldenterfrom = fd_pos.enterfrom;
|
|
|
|
|
fd_pos.x = x;
|
|
|
|
|
fd_pos.y = y;
|
|
|
|
|
rpos = &railways[GetRIdx(fd_pos.x, fd_pos.y)];
|
|
|
|
@ -645,6 +675,7 @@ int Railways::FindWay(string blockstart, string blockend, string lockedfor, stri
|
|
|
|
|
fd_pos.enterfrom = -1;
|
|
|
|
|
fd_pos.x = -1;
|
|
|
|
|
fd_pos.y = -1;
|
|
|
|
|
fd_pos.way = "";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//
|
|
|
|
@ -656,12 +687,27 @@ int Railways::FindWay(string blockstart, string blockend, string lockedfor, stri
|
|
|
|
|
fd_pos.enterfrom = -1;
|
|
|
|
|
fd_pos.x = -1;
|
|
|
|
|
fd_pos.y = -1;
|
|
|
|
|
fd_pos.way = "";
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// lockedby = server->blocks.GetLockedby(rpos->name);
|
|
|
|
|
lockedby = server->blocks.GetLockedby(rpos->name);
|
|
|
|
|
if (lockedby.length() == 0) {
|
|
|
|
|
if (fd_pos.enterfrom == 0 || fd_pos.enterfrom == 3)
|
|
|
|
|
fd_pos.way += (string)",b:+:" + (string)rpos->name;
|
|
|
|
|
else fd_pos.way += (string)",b:-:" + (string)rpos->name;
|
|
|
|
|
|
|
|
|
|
fd_pos = NextPos(fd_pos, rpos->dir);
|
|
|
|
|
fd_pos.parma++;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
printf ("%s:%d block is locked by %s\n", __FILE__, __LINE__, lockedby.c_str());
|
|
|
|
|
fd_pos.enterfrom = -1;
|
|
|
|
|
fd_pos.x = -1;
|
|
|
|
|
fd_pos.y = -1;
|
|
|
|
|
fd_pos.way = "";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else { // finished
|
|
|
|
@ -669,11 +715,30 @@ int Railways::FindWay(string blockstart, string blockend, string lockedfor, stri
|
|
|
|
|
fd_pos.enterfrom = -1;
|
|
|
|
|
fd_pos.x = -1;
|
|
|
|
|
fd_pos.y = -1;
|
|
|
|
|
fd_pos.way = "";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
printf ("%s:%d fd_pos (%d,%d) enterfrom:%d\n\n", __FILE__, __LINE__, fd_pos.x, fd_pos.y, fd_pos.enterfrom);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (found == 0) *next = "";
|
|
|
|
|
else {
|
|
|
|
|
//
|
|
|
|
|
// next = "b:+blockname,t:name:0,t:name:1,b:-blockname"
|
|
|
|
|
printf ("Temp Next: %s\n", next->c_str());
|
|
|
|
|
int i;
|
|
|
|
|
i = 0;
|
|
|
|
|
size_t npos;
|
|
|
|
|
if ((npos = next->find(",b:")) != string::npos) {
|
|
|
|
|
*next = next->substr(0, next->find(",", npos+1));
|
|
|
|
|
printf ("%s:%d next: '%s' found\n", __FILE__, __LINE__, next->c_str());
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// nothing found?
|
|
|
|
|
printf ("%s:%d next: '%s' but no next block?\n", __FILE__, __LINE__, next->c_str());
|
|
|
|
|
*next = "";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
UnLock();
|
|
|
|
|
|
|
|
|
|
free (fd_data);
|
|
|
|
@ -681,3 +746,217 @@ int Railways::FindWay(string blockstart, string blockend, string lockedfor, stri
|
|
|
|
|
return found;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int Railways::LockWay (string way, string lockedby, int lockonoff) {
|
|
|
|
|
int res = 0;
|
|
|
|
|
size_t pos1, pos2;
|
|
|
|
|
size_t curwaypos;
|
|
|
|
|
struct s_findway_data start;
|
|
|
|
|
struct s_findway_data end;
|
|
|
|
|
struct s_findway_data pos;
|
|
|
|
|
string startblock, endblock;
|
|
|
|
|
Railway *r;
|
|
|
|
|
int finished = 0;
|
|
|
|
|
JSONParse jp;
|
|
|
|
|
|
|
|
|
|
debug (0, "* LockWay Way:'%s' for '%s'", way.c_str(), lockedby.c_str());
|
|
|
|
|
|
|
|
|
|
end.x = start.x = -1;
|
|
|
|
|
end.y = start.y = -1;
|
|
|
|
|
end.enterfrom = start.enterfrom = -1;
|
|
|
|
|
end.parma = start.parma = -1;
|
|
|
|
|
|
|
|
|
|
if ((pos1 = way.find("b:", 0)) == 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 ((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());
|
|
|
|
|
|
|
|
|
|
if (FindReference(&start.x, &start.y, startblock.substr(2,string::npos))) {
|
|
|
|
|
if (Get(start.x, start.y).dir == 1) {
|
|
|
|
|
if (startblock[0] == '+') start.enterfrom = 0;
|
|
|
|
|
else start.enterfrom = 2;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (startblock[0] == '+') start.enterfrom = 3;
|
|
|
|
|
else start.enterfrom = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
debug (0, "Railway::LockWay could not find start (%s).", startblock.c_str());
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
else end.enterfrom = 2;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (endblock[0] == '+') end.enterfrom = 3;
|
|
|
|
|
else end.enterfrom = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
debug (0, "Railway::FindWay could not find end (%s).", endblock.c_str());
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
printf ("%s:%d LockWay Way:'%s' start [%d,%d -> %d] to [%d,%d -> %d]\n", __FILE__, __LINE__, way.c_str(),
|
|
|
|
|
start.x, start.y, start.enterfrom, end.x, end.y, end.enterfrom);
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// lock way depending on Way
|
|
|
|
|
Lock();
|
|
|
|
|
|
|
|
|
|
pos.x = start.x;
|
|
|
|
|
pos.y = start.y;
|
|
|
|
|
pos.enterfrom = start.enterfrom;
|
|
|
|
|
curwaypos = 0; // position in string // find first turnout
|
|
|
|
|
curwaypos = way.find(",t:", curwaypos);
|
|
|
|
|
if (curwaypos != string::npos) curwaypos++;
|
|
|
|
|
|
|
|
|
|
finished = 0;
|
|
|
|
|
do {
|
|
|
|
|
r = &railways[GetRIdx(pos.x, pos.y)];
|
|
|
|
|
printf ("LockWay Position [%d,%d] Name:%s LockedBy:'%s'\n", pos.x, pos.y, r->name, r->lockedby);
|
|
|
|
|
|
|
|
|
|
// check if railway is free or locked by me
|
|
|
|
|
if (r->lockedby[0] != 0 && lockedby.compare(r->lockedby) != 0) {
|
|
|
|
|
debug (0, "LockWay: Railway currently locked by '%s'.", r->lockedby);
|
|
|
|
|
UnLock();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// do lock start and endpoint... unlock only start
|
|
|
|
|
if (pos.x == end.x && pos.y == end.y && r->type == RAILWAY_BLOCK) {
|
|
|
|
|
if (lockonoff == 1) {
|
|
|
|
|
server->blocks.SetLockedby(r->name, lockedby, 1);
|
|
|
|
|
strncpy (r->lockedby, lockedby.c_str(), REFERENCENAME_LEN);
|
|
|
|
|
jp.Clear();
|
|
|
|
|
jp.AddObject("railway",_GetJSONRailway(pos.x, pos.y));
|
|
|
|
|
if(network) network->ChangeListPushToAll(jp.ToString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (pos.x != start.x && pos.y != start.y && r->type == RAILWAY_BLOCK) {
|
|
|
|
|
server->blocks.SetLockedby(r->name, lockedby, lockonoff);
|
|
|
|
|
if (lockonoff) strncpy (r->lockedby, lockedby.c_str(), REFERENCENAME_LEN);
|
|
|
|
|
else r->lockedby[0] = 0;
|
|
|
|
|
jp.Clear();
|
|
|
|
|
jp.AddObject("railway",_GetJSONRailway(pos.x, pos.y));
|
|
|
|
|
if(network) network->ChangeListPushToAll(jp.ToString());
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (lockonoff) strncpy (r->lockedby, lockedby.c_str(), REFERENCENAME_LEN);
|
|
|
|
|
else r->lockedby[0] = 0;
|
|
|
|
|
jp.Clear();
|
|
|
|
|
jp.AddObject("railway",_GetJSONRailway(pos.x, pos.y));
|
|
|
|
|
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) {
|
|
|
|
|
finished = 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// go to next position
|
|
|
|
|
if (r->type == RAILWAY_TURNOUT) {
|
|
|
|
|
if (curwaypos == string::npos) { // we should have a turnout
|
|
|
|
|
debug (0, "LockWay turnout '%s' not on Way '%s'", r->name, way.c_str());
|
|
|
|
|
UnLock();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pos1 = way.find(":", curwaypos+2);
|
|
|
|
|
if (pos1 == string::npos) {
|
|
|
|
|
debug (0, "LockWay turnout could not find parameter 'active'" );
|
|
|
|
|
UnLock();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (way.substr(curwaypos+2, pos1-curwaypos-2).compare(r->name) != 0) {
|
|
|
|
|
debug (0, "LockWay turnout '%s' not on Way '%s' we should on '%s'", r->name, way.c_str(), way.substr(curwaypos+2, pos1-curwaypos-2).c_str());
|
|
|
|
|
UnLock();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (way[pos1+1] == '0') pos = NextPos(pos, r->dir);
|
|
|
|
|
else pos = NextPos(pos, r->altdir);
|
|
|
|
|
|
|
|
|
|
// next turnout?
|
|
|
|
|
curwaypos = way.find(",t:", curwaypos);
|
|
|
|
|
if (curwaypos != string::npos) curwaypos++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (r->type == RAILWAY_CONNECTOR) {
|
|
|
|
|
int found = 0;
|
|
|
|
|
int x, y;
|
|
|
|
|
printf ("%s:%d connector found Reference:'%s'\n", __FILE__, __LINE__, r->name);
|
|
|
|
|
x = -1;
|
|
|
|
|
y = -1;
|
|
|
|
|
while (found == 0 && _FindReference(&x, &y, r->name) == 1) {
|
|
|
|
|
if (pos.x != x || pos.y != y) {
|
|
|
|
|
printf ("%s:%d found %d,%d\n", __FILE__, __LINE__, x, y);
|
|
|
|
|
pos.oldx = pos.x;
|
|
|
|
|
pos.oldy = pos.y;
|
|
|
|
|
pos.oldenterfrom = pos.enterfrom;
|
|
|
|
|
pos.x = x;
|
|
|
|
|
pos.y = y;
|
|
|
|
|
r = &railways[GetRIdx(pos.x, pos.y)];
|
|
|
|
|
pos = NextPos(pos, r->dir);
|
|
|
|
|
pos.parma++;
|
|
|
|
|
found = 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (found == 0) {
|
|
|
|
|
debug (0, "LockWay connector '%s' did not find second end.", r->name );
|
|
|
|
|
UnLock();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (r->type == RAILWAY_BLOCK || r->type == RAILWAY_SENSOR || r->type == RAILWAY_NORMAL) {
|
|
|
|
|
pos = NextPos(pos, r->dir);
|
|
|
|
|
}
|
|
|
|
|
} while (finished == 0);
|
|
|
|
|
|
|
|
|
|
if (pos.x == end.x && pos.y == end.y) res = 1;
|
|
|
|
|
UnLock();
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int Railways::SetLockedby (int x, int y, string name, int locked) {
|
|
|
|
|
int res = 1;
|
|
|
|
|
Railway *r;
|
|
|
|
|
JSONParse jp;
|
|
|
|
|
|
|
|
|
|
if (x < 0 || y < 0 || x >= width || y >= height) return 0;
|
|
|
|
|
|
|
|
|
|
Lock();
|
|
|
|
|
r = &railways[GetRIdx(x,y)];
|
|
|
|
|
if (r->lockedby[0] != 0)
|
|
|
|
|
if (name.compare(r->lockedby) != 0) res = 0;
|
|
|
|
|
|
|
|
|
|
if (res) {
|
|
|
|
|
if (locked) strncpy (r->lockedby, name.c_str(), REFERENCENAME_LEN);
|
|
|
|
|
else r->lockedby[0] = 0;
|
|
|
|
|
|
|
|
|
|
if (railways[GetRIdx(x, y)].type != RAILWAY_NOTHING) {
|
|
|
|
|
jp.AddObject("railway", _GetJSONRailway(x, y));
|
|
|
|
|
if(network) network->ChangeListPushToAll(jp.ToString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UnLock();
|
|
|
|
|
return res;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|