640 return; |
640 return; |
641 } |
641 } |
642 |
642 |
643 if (new_tile == 0 && p->ainew.tbt == AI_BUS) { |
643 if (new_tile == 0 && p->ainew.tbt == AI_BUS) { |
644 uint x, y, i = 0; |
644 uint x, y, i = 0; |
645 int r; |
645 CommandCost r; |
646 uint best; |
646 uint best; |
647 uint accepts[NUM_CARGO]; |
647 uint accepts[NUM_CARGO]; |
648 TileIndex found_spot[AI_FINDSTATION_TILE_RANGE*AI_FINDSTATION_TILE_RANGE * 4]; |
648 TileIndex found_spot[AI_FINDSTATION_TILE_RANGE*AI_FINDSTATION_TILE_RANGE * 4]; |
649 uint found_best[AI_FINDSTATION_TILE_RANGE*AI_FINDSTATION_TILE_RANGE * 4]; |
649 uint found_best[AI_FINDSTATION_TILE_RANGE*AI_FINDSTATION_TILE_RANGE * 4]; |
650 // To find a good spot we scan a range from the center, a get the point |
650 // To find a good spot we scan a range from the center, a get the point |
651 // where we get the most cargo and where it is buildable. |
651 // where we get the most cargo and where it is buildable. |
652 // TODO: also check for station of myself and make sure we are not |
652 // TODO: also check for station of myself and make sure we are not |
653 // taking eachothers passangers away (bad result when it does not) |
653 // taking eachothers passengers away (bad result when it does not) |
654 for (x = TileX(tile) - AI_FINDSTATION_TILE_RANGE; x <= TileX(tile) + AI_FINDSTATION_TILE_RANGE; x++) { |
654 for (x = TileX(tile) - AI_FINDSTATION_TILE_RANGE; x <= TileX(tile) + AI_FINDSTATION_TILE_RANGE; x++) { |
655 for (y = TileY(tile) - AI_FINDSTATION_TILE_RANGE; y <= TileY(tile) + AI_FINDSTATION_TILE_RANGE; y++) { |
655 for (y = TileY(tile) - AI_FINDSTATION_TILE_RANGE; y <= TileY(tile) + AI_FINDSTATION_TILE_RANGE; y++) { |
656 new_tile = TileXY(x, y); |
656 new_tile = TileXY(x, y); |
657 if (IsTileType(new_tile, MP_CLEAR) || IsTileType(new_tile, MP_TREES)) { |
657 if (IsTileType(new_tile, MP_CLEAR) || IsTileType(new_tile, MP_TREES)) { |
658 // This tile we can build on! |
658 // This tile we can build on! |
1054 if (dir2 > 3) dir2 = 0; |
1055 if (dir2 > 3) dir2 = 0; |
1055 dir3 = p->ainew.to_direction; |
1056 dir3 = p->ainew.to_direction; |
1056 } |
1057 } |
1057 |
1058 |
1058 ret = AI_DoCommand(tile, DiagDirToRoadBits(ReverseDiagDir((DiagDirection)dir1)), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD); |
1059 ret = AI_DoCommand(tile, DiagDirToRoadBits(ReverseDiagDir((DiagDirection)dir1)), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD); |
1059 if (!CmdFailed(ret)) { |
1060 if (CmdSucceeded(ret)) { |
1060 dir1 = TileOffsByDiagDir(dir1); |
1061 dir1 = TileOffsByDiagDir(dir1); |
1061 if (IsTileType(tile + dir1, MP_CLEAR) || IsTileType(tile + dir1, MP_TREES)) { |
1062 if (IsTileType(tile + dir1, MP_CLEAR) || IsTileType(tile + dir1, MP_TREES)) { |
1062 ret = AI_DoCommand(tile+dir1, AiNew_GetRoadDirection(tile, tile+dir1, tile+dir1+dir1), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD); |
1063 ret = AI_DoCommand(tile+dir1, AiNew_GetRoadDirection(tile, tile+dir1, tile+dir1+dir1), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD); |
1063 if (!CmdFailed(ret)) { |
1064 if (CmdSucceeded(ret)) { |
1064 if (IsTileType(tile + dir1 + dir1, MP_CLEAR) || IsTileType(tile + dir1 + dir1, MP_TREES)) |
1065 if (IsTileType(tile + dir1 + dir1, MP_CLEAR) || IsTileType(tile + dir1 + dir1, MP_TREES)) |
1065 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); |
1066 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); |
1066 } |
1067 } |
1067 } |
1068 } |
1068 } |
1069 } |
1069 |
1070 |
1070 ret = AI_DoCommand(tile, DiagDirToRoadBits(ReverseDiagDir((DiagDirection)dir2)), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD); |
1071 ret = AI_DoCommand(tile, DiagDirToRoadBits(ReverseDiagDir((DiagDirection)dir2)), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD); |
1071 if (!CmdFailed(ret)) { |
1072 if (CmdSucceeded(ret)) { |
1072 dir2 = TileOffsByDiagDir(dir2); |
1073 dir2 = TileOffsByDiagDir(dir2); |
1073 if (IsTileType(tile + dir2, MP_CLEAR) || IsTileType(tile + dir2, MP_TREES)) { |
1074 if (IsTileType(tile + dir2, MP_CLEAR) || IsTileType(tile + dir2, MP_TREES)) { |
1074 ret = AI_DoCommand(tile+dir2, AiNew_GetRoadDirection(tile, tile+dir2, tile+dir2+dir2), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD); |
1075 ret = AI_DoCommand(tile+dir2, AiNew_GetRoadDirection(tile, tile+dir2, tile+dir2+dir2), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD); |
1075 if (!CmdFailed(ret)) { |
1076 if (CmdSucceeded(ret)) { |
1076 if (IsTileType(tile + dir2 + dir2, MP_CLEAR) || IsTileType(tile + dir2 + dir2, MP_TREES)) |
1077 if (IsTileType(tile + dir2 + dir2, MP_CLEAR) || IsTileType(tile + dir2 + dir2, MP_TREES)) |
1077 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); |
1078 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); |
1078 } |
1079 } |
1079 } |
1080 } |
1080 } |
1081 } |
1081 |
1082 |
1082 ret = AI_DoCommand(tile, DiagDirToRoadBits((DiagDirection)dir3), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD); |
1083 ret = AI_DoCommand(tile, DiagDirToRoadBits((DiagDirection)dir3), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD); |
1083 if (!CmdFailed(ret)) { |
1084 if (CmdSucceeded(ret)) { |
1084 dir3 = TileOffsByDiagDir(dir3); |
1085 dir3 = TileOffsByDiagDir(dir3); |
1085 if (IsTileType(tile + dir3, MP_CLEAR) || IsTileType(tile + dir3, MP_TREES)) { |
1086 if (IsTileType(tile + dir3, MP_CLEAR) || IsTileType(tile + dir3, MP_TREES)) { |
1086 ret = AI_DoCommand(tile+dir3, AiNew_GetRoadDirection(tile, tile+dir3, tile+dir3+dir3), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD); |
1087 ret = AI_DoCommand(tile+dir3, AiNew_GetRoadDirection(tile, tile+dir3, tile+dir3+dir3), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD); |
1087 if (!CmdFailed(ret)) { |
1088 if (CmdSucceeded(ret)) { |
1088 if (IsTileType(tile + dir3 + dir3, MP_CLEAR) || IsTileType(tile + dir3 + dir3, MP_TREES)) |
1089 if (IsTileType(tile + dir3 + dir3, MP_CLEAR) || IsTileType(tile + dir3 + dir3, MP_TREES)) |
1089 AI_DoCommand(tile+dir3+dir3, AiNew_GetRoadDirection(tile+dir3, tile+dir3+dir3, tile+dir3+dir3+dir3), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD); |
1090 AI_DoCommand(tile+dir3+dir3, AiNew_GetRoadDirection(tile+dir3, tile+dir3+dir3, tile+dir3+dir3+dir3), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD); |
1090 } |
1091 } |
1091 } |
1092 } |
1092 } |
1093 } |