src/ai/api/ai_airport.cpp
author rubidium
Sun, 03 Feb 2008 20:17:54 +0000
branchnoai
changeset 9724 b39bc69bb2f2
parent 9723 eee46cb39750
child 9732 f8eb3e208514
permissions -rw-r--r--
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
9654
b836eb5c521f (svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff changeset
     1
/* $Id$ */
b836eb5c521f (svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff changeset
     2
b836eb5c521f (svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff changeset
     3
#include "ai_airport.hpp"
9670
820b77e19bb3 (svn r10609) [NoAI] -Add: added GetAirportWidth / GetAirportHeight
truelight
parents: 9654
diff changeset
     4
#include "../../variables.h"
9654
b836eb5c521f (svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff changeset
     5
#include "../../station_map.h"
9724
b39bc69bb2f2 (svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents: 9723
diff changeset
     6
#include "../../player_func.h"
b39bc69bb2f2 (svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents: 9723
diff changeset
     7
#include "../../settings_type.h"
9654
b836eb5c521f (svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff changeset
     8
b836eb5c521f (svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff changeset
     9
9670
820b77e19bb3 (svn r10609) [NoAI] -Add: added GetAirportWidth / GetAirportHeight
truelight
parents: 9654
diff changeset
    10
/* static */ bool AIAirport::IsHangarTile(TileIndex tile)
9654
b836eb5c521f (svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff changeset
    11
{
b836eb5c521f (svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff changeset
    12
	/* Outside of the map */
b836eb5c521f (svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff changeset
    13
	if (tile >= ::MapSize()) return false;
b836eb5c521f (svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff changeset
    14
b836eb5c521f (svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff changeset
    15
	return ::IsTileType(tile, MP_STATION) && ::IsHangar(tile);
b836eb5c521f (svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff changeset
    16
}
b836eb5c521f (svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff changeset
    17
9670
820b77e19bb3 (svn r10609) [NoAI] -Add: added GetAirportWidth / GetAirportHeight
truelight
parents: 9654
diff changeset
    18
/* static */ bool AIAirport::IsAirportTile(TileIndex tile)
9654
b836eb5c521f (svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff changeset
    19
{
b836eb5c521f (svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff changeset
    20
	/* Outside of the map */
b836eb5c521f (svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff changeset
    21
	if (tile >= ::MapSize()) return false;
b836eb5c521f (svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff changeset
    22
b836eb5c521f (svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff changeset
    23
	return ::IsTileType(tile, MP_STATION) && ::IsAirport(tile);
b836eb5c521f (svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff changeset
    24
}
b836eb5c521f (svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff changeset
    25
9670
820b77e19bb3 (svn r10609) [NoAI] -Add: added GetAirportWidth / GetAirportHeight
truelight
parents: 9654
diff changeset
    26
/* static */ bool AIAirport::AiportAvailable(AirportType type)
9654
b836eb5c521f (svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff changeset
    27
{
9670
820b77e19bb3 (svn r10609) [NoAI] -Add: added GetAirportWidth / GetAirportHeight
truelight
parents: 9654
diff changeset
    28
	if (type > AT_HELISTATION) return 0;
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9670
diff changeset
    29
	return HasBit(::GetValidAirports(), type);
9654
b836eb5c521f (svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff changeset
    30
}
b836eb5c521f (svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff changeset
    31
9670
820b77e19bb3 (svn r10609) [NoAI] -Add: added GetAirportWidth / GetAirportHeight
truelight
parents: 9654
diff changeset
    32
/* static */ int32 AIAirport::GetAirportWidth(AirportType type)
820b77e19bb3 (svn r10609) [NoAI] -Add: added GetAirportWidth / GetAirportHeight
truelight
parents: 9654
diff changeset
    33
{
820b77e19bb3 (svn r10609) [NoAI] -Add: added GetAirportWidth / GetAirportHeight
truelight
parents: 9654
diff changeset
    34
	if (type > AT_HELISTATION) return 0;
820b77e19bb3 (svn r10609) [NoAI] -Add: added GetAirportWidth / GetAirportHeight
truelight
parents: 9654
diff changeset
    35
	return GetAirport(type)->size_x;
820b77e19bb3 (svn r10609) [NoAI] -Add: added GetAirportWidth / GetAirportHeight
truelight
parents: 9654
diff changeset
    36
}
820b77e19bb3 (svn r10609) [NoAI] -Add: added GetAirportWidth / GetAirportHeight
truelight
parents: 9654
diff changeset
    37
820b77e19bb3 (svn r10609) [NoAI] -Add: added GetAirportWidth / GetAirportHeight
truelight
parents: 9654
diff changeset
    38
/* static */ int32 AIAirport::GetAirportHeight(AirportType type)
820b77e19bb3 (svn r10609) [NoAI] -Add: added GetAirportWidth / GetAirportHeight
truelight
parents: 9654
diff changeset
    39
{
820b77e19bb3 (svn r10609) [NoAI] -Add: added GetAirportWidth / GetAirportHeight
truelight
parents: 9654
diff changeset
    40
	if (type > AT_HELISTATION) return 0;
820b77e19bb3 (svn r10609) [NoAI] -Add: added GetAirportWidth / GetAirportHeight
truelight
parents: 9654
diff changeset
    41
	return GetAirport(type)->size_y;
820b77e19bb3 (svn r10609) [NoAI] -Add: added GetAirportWidth / GetAirportHeight
truelight
parents: 9654
diff changeset
    42
}
820b77e19bb3 (svn r10609) [NoAI] -Add: added GetAirportWidth / GetAirportHeight
truelight
parents: 9654
diff changeset
    43
820b77e19bb3 (svn r10609) [NoAI] -Add: added GetAirportWidth / GetAirportHeight
truelight
parents: 9654
diff changeset
    44
/* static */ int32 AIAirport::GetAirportCoverageRadius(AirportType type)
820b77e19bb3 (svn r10609) [NoAI] -Add: added GetAirportWidth / GetAirportHeight
truelight
parents: 9654
diff changeset
    45
{
820b77e19bb3 (svn r10609) [NoAI] -Add: added GetAirportWidth / GetAirportHeight
truelight
parents: 9654
diff changeset
    46
	if (type > AT_HELISTATION) return 0;
820b77e19bb3 (svn r10609) [NoAI] -Add: added GetAirportWidth / GetAirportHeight
truelight
parents: 9654
diff changeset
    47
	return _patches.modified_catchment ? GetAirport(type)->catchment : 4;
820b77e19bb3 (svn r10609) [NoAI] -Add: added GetAirportWidth / GetAirportHeight
truelight
parents: 9654
diff changeset
    48
}
820b77e19bb3 (svn r10609) [NoAI] -Add: added GetAirportWidth / GetAirportHeight
truelight
parents: 9654
diff changeset
    49
9654
b836eb5c521f (svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff changeset
    50
bool AIAirport::BuildAirport(TileIndex tile, AirportType type)
b836eb5c521f (svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff changeset
    51
{
b836eb5c521f (svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff changeset
    52
	/* Outside of the map */
b836eb5c521f (svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff changeset
    53
	if (tile >= ::MapSize()) return false;
9670
820b77e19bb3 (svn r10609) [NoAI] -Add: added GetAirportWidth / GetAirportHeight
truelight
parents: 9654
diff changeset
    54
	if (type > AT_HELISTATION) return 0;
9654
b836eb5c521f (svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff changeset
    55
b836eb5c521f (svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff changeset
    56
	return this->DoCommand(tile, type, 0, CMD_BUILD_AIRPORT);
b836eb5c521f (svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff changeset
    57
}
b836eb5c521f (svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff changeset
    58
b836eb5c521f (svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff changeset
    59
bool AIAirport::RemoveAirport(TileIndex tile)
b836eb5c521f (svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff changeset
    60
{
b836eb5c521f (svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff changeset
    61
	/* Outside of the map */
b836eb5c521f (svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff changeset
    62
	if (tile >= ::MapSize()) return false;
b836eb5c521f (svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff changeset
    63
b836eb5c521f (svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff changeset
    64
	/* Not a airport tile */
b836eb5c521f (svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff changeset
    65
	if (!IsAirportTile(tile) && !IsHangarTile(tile)) return false;
b836eb5c521f (svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff changeset
    66
b836eb5c521f (svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff changeset
    67
	return this->DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR);
b836eb5c521f (svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff changeset
    68
}
b836eb5c521f (svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff changeset
    69
b836eb5c521f (svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff changeset
    70
TileIndex AIAirport::GetHangarOfAirport(TileIndex tile)
b836eb5c521f (svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff changeset
    71
{
b836eb5c521f (svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff changeset
    72
	if (!IsTileType(tile, MP_STATION)) return INVALID_TILE;
b836eb5c521f (svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff changeset
    73
b836eb5c521f (svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff changeset
    74
	const Station *st = GetStationByTile(tile);
b836eb5c521f (svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff changeset
    75
	if (st->owner != _current_player) return INVALID_TILE;
b836eb5c521f (svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff changeset
    76
b836eb5c521f (svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff changeset
    77
	return ToTileIndexDiff(st->Airport()->airport_depots[0]) + st->xy;
b836eb5c521f (svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff changeset
    78
}