author | truebrain |
Mon, 21 Apr 2008 20:52:54 +0000 | |
branch | noai |
changeset 10292 | 7856e972f8aa |
parent 10194 | c9fdeb7450da |
child 10513 | 33cb70ff2f5d |
permissions | -rw-r--r-- |
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 |
|
9833
89a64246458f
(svn r12496) [NoAI] -Documentation: give the .cpp files a nice uniform format too
truebrain
parents:
9820
diff
changeset
|
3 |
/** @file ai_airport.cpp Implementation of AIAirport. */ |
9820
8c116d4c6033
(svn r12423) [NoAI] -Change: bring a little more uniformness into the first few lines of the API related files (add missing /* $Id$ */ and such).
rubidium
parents:
9801
diff
changeset
|
4 |
|
9654
b836eb5c521f
(svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff
changeset
|
5 |
#include "ai_airport.hpp" |
9866
efc38e1f559a
(svn r12559) [NoAI] -Add: SetLastError support for AIAirport.
rubidium
parents:
9837
diff
changeset
|
6 |
#include "ai_error.hpp" |
9837
c9ec4f82e0d0
(svn r12503) [NoAI] -Sync: with trunk r12461:12501.
rubidium
parents:
9833
diff
changeset
|
7 |
#include "../../openttd.h" |
9670
820b77e19bb3
(svn r10609) [NoAI] -Add: added GetAirportWidth / GetAirportHeight
truelight
parents:
9654
diff
changeset
|
8 |
#include "../../variables.h" |
9654
b836eb5c521f
(svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff
changeset
|
9 |
#include "../../station_map.h" |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
10 |
#include "../../player_func.h" |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
11 |
#include "../../settings_type.h" |
9654
b836eb5c521f
(svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff
changeset
|
12 |
|
9670
820b77e19bb3
(svn r10609) [NoAI] -Add: added GetAirportWidth / GetAirportHeight
truelight
parents:
9654
diff
changeset
|
13 |
/* static */ bool AIAirport::IsHangarTile(TileIndex tile) |
9654
b836eb5c521f
(svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff
changeset
|
14 |
{ |
9801
03a3eebd7fb7
(svn r12307) [NoAI] -Codechange: as followup on r12303 (trunk), use ::IsValidTile to check if a tile is inside the map, instead of all our custom ways
truebrain
parents:
9773
diff
changeset
|
15 |
if (!::IsValidTile(tile)) return false; |
9654
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 |
return ::IsTileType(tile, MP_STATION) && ::IsHangar(tile); |
b836eb5c521f
(svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff
changeset
|
18 |
} |
b836eb5c521f
(svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff
changeset
|
19 |
|
9670
820b77e19bb3
(svn r10609) [NoAI] -Add: added GetAirportWidth / GetAirportHeight
truelight
parents:
9654
diff
changeset
|
20 |
/* static */ bool AIAirport::IsAirportTile(TileIndex tile) |
9654
b836eb5c521f
(svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff
changeset
|
21 |
{ |
9801
03a3eebd7fb7
(svn r12307) [NoAI] -Codechange: as followup on r12303 (trunk), use ::IsValidTile to check if a tile is inside the map, instead of all our custom ways
truebrain
parents:
9773
diff
changeset
|
22 |
if (!::IsValidTile(tile)) return false; |
9654
b836eb5c521f
(svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff
changeset
|
23 |
|
b836eb5c521f
(svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff
changeset
|
24 |
return ::IsTileType(tile, MP_STATION) && ::IsAirport(tile); |
b836eb5c521f
(svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff
changeset
|
25 |
} |
b836eb5c521f
(svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff
changeset
|
26 |
|
9773
d2c20cd38f18
(svn r12266) [NoAI] -Fix: [API CHANGE] minor typo in Ai*r*portAvailable (tnx yorick)
truebrain
parents:
9737
diff
changeset
|
27 |
/* static */ bool AIAirport::AirportAvailable(AirportType type) |
9654
b836eb5c521f
(svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff
changeset
|
28 |
{ |
10194
c9fdeb7450da
(svn r12727) [NoAI] -Fix (API CHANGE): return -1 to indicate invalidity, instead of 0 or -1, depending on the class
truebrain
parents:
9868
diff
changeset
|
29 |
if (type > AT_HELISTATION) return false; |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9670
diff
changeset
|
30 |
return HasBit(::GetValidAirports(), type); |
9654
b836eb5c521f
(svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff
changeset
|
31 |
} |
b836eb5c521f
(svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff
changeset
|
32 |
|
9670
820b77e19bb3
(svn r10609) [NoAI] -Add: added GetAirportWidth / GetAirportHeight
truelight
parents:
9654
diff
changeset
|
33 |
/* static */ int32 AIAirport::GetAirportWidth(AirportType type) |
820b77e19bb3
(svn r10609) [NoAI] -Add: added GetAirportWidth / GetAirportHeight
truelight
parents:
9654
diff
changeset
|
34 |
{ |
10194
c9fdeb7450da
(svn r12727) [NoAI] -Fix (API CHANGE): return -1 to indicate invalidity, instead of 0 or -1, depending on the class
truebrain
parents:
9868
diff
changeset
|
35 |
if (type > AT_HELISTATION) return -1; |
9736
183b38e0a480
(svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents:
9732
diff
changeset
|
36 |
return ::GetAirport(type)->size_x; |
9670
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 |
|
820b77e19bb3
(svn r10609) [NoAI] -Add: added GetAirportWidth / GetAirportHeight
truelight
parents:
9654
diff
changeset
|
39 |
/* static */ int32 AIAirport::GetAirportHeight(AirportType type) |
820b77e19bb3
(svn r10609) [NoAI] -Add: added GetAirportWidth / GetAirportHeight
truelight
parents:
9654
diff
changeset
|
40 |
{ |
10194
c9fdeb7450da
(svn r12727) [NoAI] -Fix (API CHANGE): return -1 to indicate invalidity, instead of 0 or -1, depending on the class
truebrain
parents:
9868
diff
changeset
|
41 |
if (type > AT_HELISTATION) return -1; |
9736
183b38e0a480
(svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents:
9732
diff
changeset
|
42 |
return ::GetAirport(type)->size_y; |
9670
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 |
|
820b77e19bb3
(svn r10609) [NoAI] -Add: added GetAirportWidth / GetAirportHeight
truelight
parents:
9654
diff
changeset
|
45 |
/* static */ int32 AIAirport::GetAirportCoverageRadius(AirportType type) |
820b77e19bb3
(svn r10609) [NoAI] -Add: added GetAirportWidth / GetAirportHeight
truelight
parents:
9654
diff
changeset
|
46 |
{ |
10194
c9fdeb7450da
(svn r12727) [NoAI] -Fix (API CHANGE): return -1 to indicate invalidity, instead of 0 or -1, depending on the class
truebrain
parents:
9868
diff
changeset
|
47 |
if (type > AT_HELISTATION) return -1; |
9736
183b38e0a480
(svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents:
9732
diff
changeset
|
48 |
return _patches.modified_catchment ? ::GetAirport(type)->catchment : (uint)CA_UNMODIFIED; |
9670
820b77e19bb3
(svn r10609) [NoAI] -Add: added GetAirportWidth / GetAirportHeight
truelight
parents:
9654
diff
changeset
|
49 |
} |
820b77e19bb3
(svn r10609) [NoAI] -Add: added GetAirportWidth / GetAirportHeight
truelight
parents:
9654
diff
changeset
|
50 |
|
9737
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
51 |
/* static */ bool AIAirport::BuildAirport(TileIndex tile, AirportType type) |
9654
b836eb5c521f
(svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff
changeset
|
52 |
{ |
9868
3998f2e73dda
(svn r12590) [NoAI] -Add: EnforcePrecondition macro to make code much better readable.
rubidium
parents:
9866
diff
changeset
|
53 |
EnforcePrecondition(false, ::IsValidTile(tile)); |
3998f2e73dda
(svn r12590) [NoAI] -Add: EnforcePrecondition macro to make code much better readable.
rubidium
parents:
9866
diff
changeset
|
54 |
EnforcePrecondition(false, type <= AT_HELISTATION); |
9737
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
55 |
return AIObject::DoCommand(tile, type, 0, CMD_BUILD_AIRPORT); |
9654
b836eb5c521f
(svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff
changeset
|
56 |
} |
b836eb5c521f
(svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff
changeset
|
57 |
|
9737
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
58 |
/* static */ bool AIAirport::RemoveAirport(TileIndex tile) |
9654
b836eb5c521f
(svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff
changeset
|
59 |
{ |
9868
3998f2e73dda
(svn r12590) [NoAI] -Add: EnforcePrecondition macro to make code much better readable.
rubidium
parents:
9866
diff
changeset
|
60 |
EnforcePrecondition(false, ::IsValidTile(tile)) |
3998f2e73dda
(svn r12590) [NoAI] -Add: EnforcePrecondition macro to make code much better readable.
rubidium
parents:
9866
diff
changeset
|
61 |
EnforcePrecondition(false, IsAirportTile(tile) || IsHangarTile(tile)); |
9737
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
62 |
return AIObject::DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR); |
9654
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 |
|
9737
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
65 |
/* static */ TileIndex AIAirport::GetHangarOfAirport(TileIndex tile) |
9654
b836eb5c521f
(svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff
changeset
|
66 |
{ |
9736
183b38e0a480
(svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents:
9732
diff
changeset
|
67 |
if (!::IsTileType(tile, MP_STATION)) return INVALID_TILE; |
9654
b836eb5c521f
(svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff
changeset
|
68 |
|
9736
183b38e0a480
(svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents:
9732
diff
changeset
|
69 |
const Station *st = ::GetStationByTile(tile); |
9654
b836eb5c521f
(svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff
changeset
|
70 |
if (st->owner != _current_player) return INVALID_TILE; |
b836eb5c521f
(svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff
changeset
|
71 |
|
9736
183b38e0a480
(svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents:
9732
diff
changeset
|
72 |
return ::ToTileIndexDiff(st->Airport()->airport_depots[0]) + st->xy; |
9654
b836eb5c521f
(svn r10556) [NoAI] -Add: added AIAirport, which can build an airport
truelight
parents:
diff
changeset
|
73 |
} |