station_cmd.c
branch0.5
changeset 5443 4ef33c0ddab7
parent 5442 427c81cfd6f6
child 5464 d5841259ac07
equal deleted inserted replaced
5442:427c81cfd6f6 5443:4ef33c0ddab7
   229 {
   229 {
   230 	// check around to see if there's any stations there
   230 	// check around to see if there's any stations there
   231 	BEGIN_TILE_LOOP(tile_cur, w + 2, h + 2, tile - TileDiffXY(1, 1))
   231 	BEGIN_TILE_LOOP(tile_cur, w + 2, h + 2, tile - TileDiffXY(1, 1))
   232 		if (IsTileType(tile_cur, MP_STATION)) {
   232 		if (IsTileType(tile_cur, MP_STATION)) {
   233 			StationID t = GetStationIndex(tile_cur);
   233 			StationID t = GetStationIndex(tile_cur);
   234 			{
       
   235 				Station *st = GetStation(t);
       
   236 				// you cannot take control of an oilrig!!
       
   237 				if (st->airport_type == AT_OILRIG && st->facilities == (FACIL_AIRPORT|FACIL_DOCK))
       
   238 					continue;
       
   239 			}
       
   240 
   234 
   241 			if (closest_station == INVALID_STATION) {
   235 			if (closest_station == INVALID_STATION) {
   242 				closest_station = t;
   236 				closest_station = t;
   243 			} else if (closest_station != t) {
   237 			} else if (closest_station != t) {
   244 				_error_message = STR_3006_ADJOINS_MORE_THAN_ONE_EXISTING;
   238 				_error_message = STR_3006_ADJOINS_MORE_THAN_ONE_EXISTING;
  1014 		if (st != NULL && st->facilities) st = NULL;
  1008 		if (st != NULL && st->facilities) st = NULL;
  1015 	}
  1009 	}
  1016 
  1010 
  1017 	if (st != NULL) {
  1011 	if (st != NULL) {
  1018 		// Reuse an existing station.
  1012 		// Reuse an existing station.
  1019 		if (st->owner != OWNER_NONE && st->owner != _current_player)
  1013 		if (st->owner != _current_player)
  1020 			return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION);
  1014 			return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION);
  1021 
  1015 
  1022 		if (st->train_tile != 0) {
  1016 		if (st->train_tile != 0) {
  1023 			// check if we want to expanding an already existing station?
  1017 			// check if we want to expanding an already existing station?
  1024 			if (_is_old_ai_player || !_patches.join_stations)
  1018 			if (_is_old_ai_player || !_patches.join_stations)
  1449 			GetNumRoadStopsInStation(st, RS_BUS) + GetNumRoadStopsInStation(st, RS_TRUCK) >= ROAD_STOP_LIMIT) {
  1443 			GetNumRoadStopsInStation(st, RS_BUS) + GetNumRoadStopsInStation(st, RS_TRUCK) >= ROAD_STOP_LIMIT) {
  1450 		return_cmd_error(type ? STR_3008B_TOO_MANY_TRUCK_STOPS : STR_3008A_TOO_MANY_BUS_STOPS);
  1444 		return_cmd_error(type ? STR_3008B_TOO_MANY_TRUCK_STOPS : STR_3008A_TOO_MANY_BUS_STOPS);
  1451 	}
  1445 	}
  1452 
  1446 
  1453 	if (st != NULL) {
  1447 	if (st != NULL) {
  1454 		if (st->owner != OWNER_NONE && st->owner != _current_player) {
  1448 		if (st->owner != _current_player) {
  1455 			return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION);
  1449 			return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION);
  1456 		}
  1450 		}
  1457 
  1451 
  1458 		if (!StationRect_BeforeAddTile(st, tile, RECT_MODE_TEST)) return CMD_ERROR;
  1452 		if (!StationRect_BeforeAddTile(st, tile, RECT_MODE_TEST)) return CMD_ERROR;
  1459 
  1453 
  1704 		_error_message = STR_306C_STATION_TOO_SPREAD_OUT;
  1698 		_error_message = STR_306C_STATION_TOO_SPREAD_OUT;
  1705 		return CMD_ERROR;
  1699 		return CMD_ERROR;
  1706 	}
  1700 	}
  1707 
  1701 
  1708 	if (st != NULL) {
  1702 	if (st != NULL) {
  1709 		if (st->owner != OWNER_NONE && st->owner != _current_player)
  1703 		if (st->owner != _current_player)
  1710 			return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION);
  1704 			return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION);
  1711 
  1705 
  1712 		if (!StationRect_BeforeAddRect(st, tile, w, h, RECT_MODE_TEST)) return CMD_ERROR;
  1706 		if (!StationRect_BeforeAddRect(st, tile, w, h, RECT_MODE_TEST)) return CMD_ERROR;
  1713 
  1707 
  1714 		if (st->airport_tile != 0)
  1708 		if (st->airport_tile != 0)
  1985 		st = GetClosestStationFromTile(tile, 8, _current_player);
  1979 		st = GetClosestStationFromTile(tile, 8, _current_player);
  1986 		if (st!=NULL && st->facilities) st = NULL;
  1980 		if (st!=NULL && st->facilities) st = NULL;
  1987 	}
  1981 	}
  1988 
  1982 
  1989 	if (st != NULL) {
  1983 	if (st != NULL) {
  1990 		if (st->owner != OWNER_NONE && st->owner != _current_player)
  1984 		if (st->owner != _current_player)
  1991 			return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION);
  1985 			return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION);
  1992 
  1986 
  1993 		if (!StationRect_BeforeAddRect(st, tile, _dock_w_chk[direction], _dock_h_chk[direction], RECT_MODE_TEST)) return CMD_ERROR;
  1987 		if (!StationRect_BeforeAddRect(st, tile, _dock_w_chk[direction], _dock_h_chk[direction], RECT_MODE_TEST)) return CMD_ERROR;
  1994 
  1988 
  1995 		if (st->dock_tile != 0) return_cmd_error(STR_304C_TOO_CLOSE_TO_ANOTHER_DOCK);
  1989 		if (st->dock_tile != 0) return_cmd_error(STR_304C_TOO_CLOSE_TO_ANOTHER_DOCK);