equal
deleted
inserted
replaced
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 |
786 // To place the depot, we walk through the route, and if we find a lovely spot (MP_CLEAR, MP_TREES), we place it there.. |
786 // To place the depot, we walk through the route, and if we find a lovely spot (MP_CLEAR, MP_TREES), we place it there.. |
787 // Simple, easy, works! |
787 // Simple, easy, works! |
788 // To make the depot stand in the middle of the route, we start from the center.. |
788 // To make the depot stand in the middle of the route, we start from the center.. |
789 // But first we walk through the route see if we can find a depot that is ours |
789 // But first we walk through the route see if we can find a depot that is ours |
790 // this keeps things nice ;) |
790 // this keeps things nice ;) |
791 int g, i, r; |
791 int g, i; |
|
792 CommandCost r; |
792 DiagDirection j; |
793 DiagDirection j; |
793 TileIndex tile; |
794 TileIndex tile; |
794 assert(p->ainew.state == AI_STATE_FIND_DEPOT); |
795 assert(p->ainew.state == AI_STATE_FIND_DEPOT); |
795 |
796 |
796 p->ainew.depot_tile = 0; |
797 p->ainew.depot_tile = 0; |
982 |
983 |
983 |
984 |
984 // Build the stations |
985 // Build the stations |
985 static void AiNew_State_BuildStation(Player *p) |
986 static void AiNew_State_BuildStation(Player *p) |
986 { |
987 { |
987 int res = 0; |
988 CommandCost res = 0; |
988 assert(p->ainew.state == AI_STATE_BUILD_STATION); |
989 assert(p->ainew.state == AI_STATE_BUILD_STATION); |
989 if (p->ainew.temp == 0) { |
990 if (p->ainew.temp == 0) { |
990 if (!IsTileType(p->ainew.from_tile, MP_STATION)) |
991 if (!IsTileType(p->ainew.from_tile, MP_STATION)) |
991 res = AiNew_Build_Station(p, p->ainew.tbt, p->ainew.from_tile, 0, 0, p->ainew.from_direction, DC_EXEC); |
992 res = AiNew_Build_Station(p, p->ainew.tbt, p->ainew.from_tile, 0, 0, p->ainew.from_direction, DC_EXEC); |
992 } else { |
993 } else { |
1035 if (p->ainew.tbt == AI_TRUCK && !_patches.roadveh_queue) { |
1036 if (p->ainew.tbt == AI_TRUCK && !_patches.roadveh_queue) { |
1036 // If they not queue, they have to go up and down to try again at a station... |
1037 // If they not queue, they have to go up and down to try again at a station... |
1037 // We don't want that, so try building some road left or right of the station |
1038 // We don't want that, so try building some road left or right of the station |
1038 int dir1, dir2, dir3; |
1039 int dir1, dir2, dir3; |
1039 TileIndex tile; |
1040 TileIndex tile; |
1040 int i, ret; |
1041 CommandCost ret; |
1041 for (i=0;i<2;i++) { |
1042 for (int i = 0; i < 2; i++) { |
1042 if (i == 0) { |
1043 if (i == 0) { |
1043 tile = p->ainew.from_tile + TileOffsByDiagDir(p->ainew.from_direction); |
1044 tile = p->ainew.from_tile + TileOffsByDiagDir(p->ainew.from_direction); |
1044 dir1 = p->ainew.from_direction - 1; |
1045 dir1 = p->ainew.from_direction - 1; |
1045 if (dir1 < 0) dir1 = 3; |
1046 if (dir1 < 0) dir1 = 3; |
1046 dir2 = p->ainew.from_direction + 1; |
1047 dir2 = p->ainew.from_direction + 1; |
1100 |
1101 |
1101 |
1102 |
1102 // Builds the depot |
1103 // Builds the depot |
1103 static void AiNew_State_BuildDepot(Player *p) |
1104 static void AiNew_State_BuildDepot(Player *p) |
1104 { |
1105 { |
1105 int res = 0; |
1106 CommandCost res = 0; |
1106 assert(p->ainew.state == AI_STATE_BUILD_DEPOT); |
1107 assert(p->ainew.state == AI_STATE_BUILD_DEPOT); |
1107 |
1108 |
1108 if (IsTileType(p->ainew.depot_tile, MP_STREET) && GetRoadTileType(p->ainew.depot_tile) == ROAD_TILE_DEPOT) { |
1109 if (IsTileType(p->ainew.depot_tile, MP_STREET) && GetRoadTileType(p->ainew.depot_tile) == ROAD_TILE_DEPOT) { |
1109 if (IsTileOwner(p->ainew.depot_tile, _current_player)) { |
1110 if (IsTileOwner(p->ainew.depot_tile, _current_player)) { |
1110 // The depot is already built |
1111 // The depot is already built |
1135 |
1136 |
1136 |
1137 |
1137 // Build vehicles |
1138 // Build vehicles |
1138 static void AiNew_State_BuildVehicle(Player *p) |
1139 static void AiNew_State_BuildVehicle(Player *p) |
1139 { |
1140 { |
1140 int res; |
1141 CommandCost res; |
1141 assert(p->ainew.state == AI_STATE_BUILD_VEHICLE); |
1142 assert(p->ainew.state == AI_STATE_BUILD_VEHICLE); |
1142 |
1143 |
1143 // Check if we need to build a vehicle |
1144 // Check if we need to build a vehicle |
1144 if (p->ainew.amount_veh == 0) { |
1145 if (p->ainew.amount_veh == 0) { |
1145 // Nope, we are done! |
1146 // Nope, we are done! |
1275 return; |
1276 return; |
1276 } |
1277 } |
1277 |
1278 |
1278 if (!AiNew_SetSpecialVehicleFlag(p, v, AI_VEHICLEFLAG_SELL)) return; |
1279 if (!AiNew_SetSpecialVehicleFlag(p, v, AI_VEHICLEFLAG_SELL)) return; |
1279 { |
1280 { |
1280 int ret = 0; |
1281 CommandCost ret = 0; |
1281 if (v->type == VEH_ROAD) |
1282 if (v->type == VEH_ROAD) |
1282 ret = AI_DoCommand(0, v->index, 0, DC_EXEC, CMD_SEND_ROADVEH_TO_DEPOT); |
1283 ret = AI_DoCommand(0, v->index, 0, DC_EXEC, CMD_SEND_ROADVEH_TO_DEPOT); |
1283 // This means we can not find a depot :s |
1284 // This means we can not find a depot :s |
1284 // if (CmdFailed(ret)) |
1285 // if (CmdFailed(ret)) |
1285 } |
1286 } |