1022 AiNew_Build_RoutePart(p, &p->ainew.path_info, DC_EXEC); |
1022 AiNew_Build_RoutePart(p, &p->ainew.path_info, DC_EXEC); |
1023 if (p->ainew.path_info.position == -2) { |
1023 if (p->ainew.path_info.position == -2) { |
1024 // This means we are done building! |
1024 // This means we are done building! |
1025 |
1025 |
1026 if (p->ainew.tbt == AI_TRUCK && !_patches.roadveh_queue) { |
1026 if (p->ainew.tbt == AI_TRUCK && !_patches.roadveh_queue) { |
1027 static const byte _roadbits_by_dir[4] = {2,1,8,4}; |
|
1028 // If they not queue, they have to go up and down to try again at a station... |
1027 // If they not queue, they have to go up and down to try again at a station... |
1029 // We don't want that, so try building some road left or right of the station |
1028 // We don't want that, so try building some road left or right of the station |
1030 int dir1, dir2, dir3; |
1029 int dir1, dir2, dir3; |
1031 TileIndex tile; |
1030 TileIndex tile; |
1032 int i, ret; |
1031 int i, ret; |
1045 dir2 = p->ainew.to_direction + 1; |
1044 dir2 = p->ainew.to_direction + 1; |
1046 if (dir2 > 3) dir2 = 0; |
1045 if (dir2 > 3) dir2 = 0; |
1047 dir3 = p->ainew.to_direction; |
1046 dir3 = p->ainew.to_direction; |
1048 } |
1047 } |
1049 |
1048 |
1050 ret = AI_DoCommand(tile, _roadbits_by_dir[dir1], 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD); |
1049 ret = AI_DoCommand(tile, DiagDirToRoadBits(ReverseDiagDir(dir1)), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD); |
1051 if (!CmdFailed(ret)) { |
1050 if (!CmdFailed(ret)) { |
1052 dir1 = TileOffsByDir(dir1); |
1051 dir1 = TileOffsByDir(dir1); |
1053 if (IsTileType(tile + dir1, MP_CLEAR) || IsTileType(tile + dir1, MP_TREES)) { |
1052 if (IsTileType(tile + dir1, MP_CLEAR) || IsTileType(tile + dir1, MP_TREES)) { |
1054 ret = AI_DoCommand(tile+dir1, AiNew_GetRoadDirection(tile, tile+dir1, tile+dir1+dir1), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD); |
1053 ret = AI_DoCommand(tile+dir1, AiNew_GetRoadDirection(tile, tile+dir1, tile+dir1+dir1), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD); |
1055 if (!CmdFailed(ret)) { |
1054 if (!CmdFailed(ret)) { |
1057 AI_DoCommand(tile+dir1+dir1, AiNew_GetRoadDirection(tile+dir1, tile+dir1+dir1, tile+dir1+dir1+dir1), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD); |
1056 AI_DoCommand(tile+dir1+dir1, AiNew_GetRoadDirection(tile+dir1, tile+dir1+dir1, tile+dir1+dir1+dir1), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD); |
1058 } |
1057 } |
1059 } |
1058 } |
1060 } |
1059 } |
1061 |
1060 |
1062 ret = AI_DoCommand(tile, _roadbits_by_dir[dir2], 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD); |
1061 ret = AI_DoCommand(tile, DiagDirToRoadBits(ReverseDiagDir(dir2)), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD); |
1063 if (!CmdFailed(ret)) { |
1062 if (!CmdFailed(ret)) { |
1064 dir2 = TileOffsByDir(dir2); |
1063 dir2 = TileOffsByDir(dir2); |
1065 if (IsTileType(tile + dir2, MP_CLEAR) || IsTileType(tile + dir2, MP_TREES)) { |
1064 if (IsTileType(tile + dir2, MP_CLEAR) || IsTileType(tile + dir2, MP_TREES)) { |
1066 ret = AI_DoCommand(tile+dir2, AiNew_GetRoadDirection(tile, tile+dir2, tile+dir2+dir2), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD); |
1065 ret = AI_DoCommand(tile+dir2, AiNew_GetRoadDirection(tile, tile+dir2, tile+dir2+dir2), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD); |
1067 if (!CmdFailed(ret)) { |
1066 if (!CmdFailed(ret)) { |
1069 AI_DoCommand(tile+dir2+dir2, AiNew_GetRoadDirection(tile+dir2, tile+dir2+dir2, tile+dir2+dir2+dir2), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD); |
1068 AI_DoCommand(tile+dir2+dir2, AiNew_GetRoadDirection(tile+dir2, tile+dir2+dir2, tile+dir2+dir2+dir2), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD); |
1070 } |
1069 } |
1071 } |
1070 } |
1072 } |
1071 } |
1073 |
1072 |
1074 ret = AI_DoCommand(tile, _roadbits_by_dir[dir3^2], 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD); |
1073 ret = AI_DoCommand(tile, DiagDirToRoadBits(dir3), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD); |
1075 if (!CmdFailed(ret)) { |
1074 if (!CmdFailed(ret)) { |
1076 dir3 = TileOffsByDir(dir3); |
1075 dir3 = TileOffsByDir(dir3); |
1077 if (IsTileType(tile + dir3, MP_CLEAR) || IsTileType(tile + dir3, MP_TREES)) { |
1076 if (IsTileType(tile + dir3, MP_CLEAR) || IsTileType(tile + dir3, MP_TREES)) { |
1078 ret = AI_DoCommand(tile+dir3, AiNew_GetRoadDirection(tile, tile+dir3, tile+dir3+dir3), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD); |
1077 ret = AI_DoCommand(tile+dir3, AiNew_GetRoadDirection(tile, tile+dir3, tile+dir3+dir3), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD); |
1079 if (!CmdFailed(ret)) { |
1078 if (!CmdFailed(ret)) { |