src/ai/default/default.cpp
branch0.6
changeset 10801 3ad9dfb5430d
parent 9113 4871417ad10c
equal deleted inserted replaced
10659:2d983c15a049 10801:3ad9dfb5430d
  3375 			// Do we own the airport? (Oilrigs aren't owned, though.)
  3375 			// Do we own the airport? (Oilrigs aren't owned, though.)
  3376 			if (st->owner != OWNER_NONE && st->owner != _current_player) continue;
  3376 			if (st->owner != OWNER_NONE && st->owner != _current_player) continue;
  3377 
  3377 
  3378 			AirportFTAClass::Flags flags = st->Airport()->flags;
  3378 			AirportFTAClass::Flags flags = st->Airport()->flags;
  3379 
  3379 
  3380 			if (!(flags & (_players_ai[p->index].build_kind == 1 && i == 0 ? AirportFTAClass::HELICOPTERS : AirportFTAClass::AIRPLANES))) {
  3380 			/* if airport doesn't accept our kind of plane, dismiss it */
       
  3381 			if (!(flags & (_players_ai[p->index].build_kind == 1 ? AirportFTAClass::HELICOPTERS : AirportFTAClass::AIRPLANES))) {
  3381 				continue;
  3382 				continue;
  3382 			}
  3383 			}
  3383 
  3384 
  3384 			// Dismiss airports too far away.
  3385 			// Dismiss airports too far away.
  3385 			if (DistanceMax(st->airport_tile, aib->spec_tile) > aib->rand_rng)
  3386 			if (DistanceMax(st->airport_tile, aib->spec_tile) > aib->rand_rng)
  3461 }
  3462 }
  3462 
  3463 
  3463 static int AiFindBestDefaultAirportBlock(TileIndex tile, byte cargo, byte heli, CommandCost *cost)
  3464 static int AiFindBestDefaultAirportBlock(TileIndex tile, byte cargo, byte heli, CommandCost *cost)
  3464 {
  3465 {
  3465 	const AiDefaultBlockData *p;
  3466 	const AiDefaultBlockData *p;
  3466 	uint i;
  3467 
  3467 
  3468 	bool no_small = false;
  3468 	for (i = 0; (p = _airport_default_block_data[i]) != NULL; i++) {
  3469 
  3469 		// If we are doing a helicopter service, avoid building
  3470 	if (!heli) {
  3470 		// airports where they can't land.
  3471 		/* do not build small airport if we have large available and we are not building heli route */
  3471 		if (heli && !(GetAirport(p->attr)->flags & AirportFTAClass::HELICOPTERS)) continue;
  3472 		uint valid = GetValidAirports();
       
  3473 		for (uint i = 0; (p = _airport_default_block_data[i]) != NULL; i++) {
       
  3474 			uint flags = GetAirport(p->attr)->flags;
       
  3475 			if (HasBit(valid, p->attr) && (flags & AirportFTAClass::AIRPLANES) && !(flags & AirportFTAClass::SHORT_STRIP)) {
       
  3476 				no_small = true;
       
  3477 				break;
       
  3478 			}
       
  3479 		}
       
  3480 	}
       
  3481 
       
  3482 	for (uint i = 0; (p = _airport_default_block_data[i]) != NULL; i++) {
       
  3483 		uint flags = GetAirport(p->attr)->flags;
       
  3484 		/* If we are doing a helicopter service, avoid building airports where they can't land */
       
  3485 		if (heli && !(flags & AirportFTAClass::HELICOPTERS)) continue;
       
  3486 		/* Similiar with aircraft ... */
       
  3487 		if (!heli && !(flags & AirportFTAClass::AIRPLANES)) continue;
       
  3488 		/* Do not build small airport if we prefer large */
       
  3489 		if (no_small && (flags & AirportFTAClass::SHORT_STRIP)) continue;
  3472 
  3490 
  3473 		*cost = AiDoBuildDefaultAirportBlock(tile, p, 0);
  3491 		*cost = AiDoBuildDefaultAirportBlock(tile, p, 0);
  3474 		if (CmdSucceeded(*cost) && AiCheckAirportResources(tile, p, cargo))
  3492 		if (CmdSucceeded(*cost) && AiCheckAirportResources(tile, p, cargo))
  3475 			return i;
  3493 			return i;
  3476 	}
  3494 	}