~ubuntu-branches/debian/squeeze/openttd/squeeze

« back to all changes in this revision

Viewing changes to src/ai/api/ai_airport.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jordi Mallach, Matthijs Kooijman, Jordi Mallach
  • Date: 2009-04-15 18:22:10 UTC
  • mfrom: (1.1.6 upstream) (2.1.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090415182210-22ktb8kdbp2tf3bm
[ Matthijs Kooijman ]
* New upstream release.
* Remove Debian specific desktop file, upstream provides one now. 
* Add debian/watch file.

[ Jordi Mallach ]
* Bump Standards-Version to 3.8.1, with no changes required.
* Move to debhelper compat 7. Bump Build-Depends accordingly.
* Use dh_prep.
* Add "set -e" to config script.
* Remove a few extra doc files that get installed by upstream Makefile.
* Add more complete copyright information.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: ai_airport.cpp 15489 2009-02-14 21:16:21Z yexo $ */
 
2
 
 
3
/** @file ai_airport.cpp Implementation of AIAirport. */
 
4
 
 
5
#include "ai_airport.hpp"
 
6
#include "ai_station.hpp"
 
7
#include "../../station_map.h"
 
8
#include "../../company_func.h"
 
9
#include "../../command_type.h"
 
10
#include "../../town.h"
 
11
 
 
12
/* static */ bool AIAirport::IsValidAirportType(AirportType type)
 
13
{
 
14
        return type >= AT_SMALL && type <= AT_HELISTATION && HasBit(::GetValidAirports(), type);
 
15
}
 
16
 
 
17
/* static */ bool AIAirport::IsHangarTile(TileIndex tile)
 
18
{
 
19
        if (!::IsValidTile(tile)) return false;
 
20
 
 
21
        return ::IsTileType(tile, MP_STATION) && ::IsHangar(tile);
 
22
}
 
23
 
 
24
/* static */ bool AIAirport::IsAirportTile(TileIndex tile)
 
25
{
 
26
        if (!::IsValidTile(tile)) return false;
 
27
 
 
28
        return ::IsTileType(tile, MP_STATION) && ::IsAirport(tile);
 
29
}
 
30
 
 
31
/* static */ int32 AIAirport::GetAirportWidth(AirportType type)
 
32
{
 
33
        if (!IsValidAirportType(type)) return -1;
 
34
 
 
35
        return ::GetAirport(type)->size_x;
 
36
}
 
37
 
 
38
/* static */ int32 AIAirport::GetAirportHeight(AirportType type)
 
39
{
 
40
        if (!IsValidAirportType(type)) return -1;
 
41
 
 
42
        return ::GetAirport(type)->size_y;
 
43
}
 
44
 
 
45
/* static */ int32 AIAirport::GetAirportCoverageRadius(AirportType type)
 
46
{
 
47
        if (!IsValidAirportType(type)) return -1;
 
48
 
 
49
        return _settings_game.station.modified_catchment ? ::GetAirport(type)->catchment : (uint)CA_UNMODIFIED;
 
50
}
 
51
 
 
52
/* static */ bool AIAirport::BuildAirport(TileIndex tile, AirportType type, StationID station_id)
 
53
{
 
54
        EnforcePrecondition(false, ::IsValidTile(tile));
 
55
        EnforcePrecondition(false, IsValidAirportType(type));
 
56
        EnforcePrecondition(false, station_id == AIStation::STATION_NEW || station_id == AIStation::STATION_JOIN_ADJACENT || AIStation::IsValidStation(station_id));
 
57
 
 
58
        uint p2 = station_id == AIStation::STATION_JOIN_ADJACENT ? 0 : 1;
 
59
        p2 |= (AIStation::IsValidStation(station_id) ? station_id : INVALID_STATION) << 16;
 
60
        return AIObject::DoCommand(tile, type, p2, CMD_BUILD_AIRPORT);
 
61
}
 
62
 
 
63
/* static */ bool AIAirport::RemoveAirport(TileIndex tile)
 
64
{
 
65
        EnforcePrecondition(false, ::IsValidTile(tile))
 
66
        EnforcePrecondition(false, IsAirportTile(tile) || IsHangarTile(tile));
 
67
 
 
68
        return AIObject::DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR);
 
69
}
 
70
 
 
71
/* static */ int32 AIAirport::GetNumHangars(TileIndex tile)
 
72
{
 
73
        if (!::IsValidTile(tile)) return -1;
 
74
        if (!::IsTileType(tile, MP_STATION)) return -1;
 
75
 
 
76
        const Station *st = ::GetStationByTile(tile);
 
77
        if (st->owner != _current_company) return -1;
 
78
        if ((st->facilities & FACIL_AIRPORT) == 0) return -1;
 
79
 
 
80
        return st->Airport()->nof_depots;
 
81
}
 
82
 
 
83
/* static */ TileIndex AIAirport::GetHangarOfAirport(TileIndex tile)
 
84
{
 
85
        if (!::IsValidTile(tile)) return INVALID_TILE;
 
86
        if (!::IsTileType(tile, MP_STATION)) return INVALID_TILE;
 
87
        if (GetNumHangars(tile) < 1) return INVALID_TILE;
 
88
 
 
89
        const Station *st = ::GetStationByTile(tile);
 
90
        if (st->owner != _current_company) return INVALID_TILE;
 
91
        if ((st->facilities & FACIL_AIRPORT) == 0) return INVALID_TILE;
 
92
 
 
93
        return ::ToTileIndexDiff(st->Airport()->airport_depots[0]) + st->airport_tile;
 
94
}
 
95
 
 
96
/* static */ AIAirport::AirportType AIAirport::GetAirportType(TileIndex tile)
 
97
{
 
98
        if (!AITile::IsStationTile(tile)) return AT_INVALID;
 
99
 
 
100
        StationID station_id = ::GetStationIndex(tile);
 
101
 
 
102
        if (!AIStation::HasStationType(station_id, AIStation::STATION_AIRPORT)) return AT_INVALID;
 
103
 
 
104
        return (AirportType)::GetStation(station_id)->airport_type;
 
105
}
 
106
 
 
107
 
 
108
/* static */ int AIAirport::GetNoiseLevelIncrease(TileIndex tile, AirportType type)
 
109
{
 
110
        extern Town *AirportGetNearestTown(const AirportFTAClass *afc, TileIndex airport_tile);
 
111
        extern uint8 GetAirportNoiseLevelForTown(const AirportFTAClass *afc, TileIndex town_tile, TileIndex tile);
 
112
 
 
113
        if (!::IsValidTile(tile)) return -1;
 
114
        if (!IsValidAirportType(type)) return -1;
 
115
 
 
116
        if (_settings_game.economy.station_noise_level) {
 
117
                const AirportFTAClass *afc = ::GetAirport(type);
 
118
                const Town *t = AirportGetNearestTown(afc, tile);
 
119
                return GetAirportNoiseLevelForTown(afc, t->xy, tile);
 
120
        }
 
121
 
 
122
        return 1;
 
123
}
 
124
 
 
125
/* static */ TownID AIAirport::GetNearestTown(TileIndex tile, AirportType type)
 
126
{
 
127
        extern Town *AirportGetNearestTown(const AirportFTAClass *afc, TileIndex airport_tile);
 
128
 
 
129
        if (!::IsValidTile(tile)) return INVALID_TOWN;
 
130
        if (!IsValidAirportType(type)) return INVALID_TOWN;
 
131
 
 
132
        return AirportGetNearestTown(GetAirport(type), tile)->index;
 
133
}