author | rubidium |
Sun, 03 Feb 2008 20:17:54 +0000 | |
branch | noai |
changeset 9724 | b39bc69bb2f2 |
parent 9723 | eee46cb39750 |
child 9730 | cb65df290e31 |
permissions | -rw-r--r-- |
9638
f6d169a5a45a
(svn r10529) [NoAI] -Add: added AIStation to gather information about stations directly by Id, which is used now by AIStationList
truelight
parents:
diff
changeset
|
1 |
/* $Id$ */ |
f6d169a5a45a
(svn r10529) [NoAI] -Add: added AIStation to gather information about stations directly by Id, which is used now by AIStationList
truelight
parents:
diff
changeset
|
2 |
|
f6d169a5a45a
(svn r10529) [NoAI] -Add: added AIStation to gather information about stations directly by Id, which is used now by AIStationList
truelight
parents:
diff
changeset
|
3 |
/** @file ai_station.cpp handles the functions of the AIStation class */ |
f6d169a5a45a
(svn r10529) [NoAI] -Add: added AIStation to gather information about stations directly by Id, which is used now by AIStationList
truelight
parents:
diff
changeset
|
4 |
|
f6d169a5a45a
(svn r10529) [NoAI] -Add: added AIStation to gather information about stations directly by Id, which is used now by AIStationList
truelight
parents:
diff
changeset
|
5 |
#include "ai_station.hpp" |
f6d169a5a45a
(svn r10529) [NoAI] -Add: added AIStation to gather information about stations directly by Id, which is used now by AIStationList
truelight
parents:
diff
changeset
|
6 |
#include "ai_cargo.hpp" |
9670
820b77e19bb3
(svn r10609) [NoAI] -Add: added GetAirportWidth / GetAirportHeight
truelight
parents:
9666
diff
changeset
|
7 |
#include "../../debug.h" |
9638
f6d169a5a45a
(svn r10529) [NoAI] -Add: added AIStation to gather information about stations directly by Id, which is used now by AIStationList
truelight
parents:
diff
changeset
|
8 |
#include "../../station.h" |
9666
5765eb70736d
(svn r10580) [NoAI] -Add: added GetStationID to get the StationID based on a tile
truelight
parents:
9648
diff
changeset
|
9 |
#include "../../station_map.h" |
9670
820b77e19bb3
(svn r10609) [NoAI] -Add: added GetAirportWidth / GetAirportHeight
truelight
parents:
9666
diff
changeset
|
10 |
#include "../../variables.h" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9696
diff
changeset
|
11 |
#include "../../strings_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9696
diff
changeset
|
12 |
#include "../../core/alloc_func.hpp" |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
13 |
#include "../../player_func.h" |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
14 |
#include "../../settings_type.h" |
9696
4384ed3de1f0
(svn r10937) [NoAI] -Add: added AIStation::GetName on request by Nickman
truelight
parents:
9670
diff
changeset
|
15 |
#include "table/strings.h" |
9638
f6d169a5a45a
(svn r10529) [NoAI] -Add: added AIStation to gather information about stations directly by Id, which is used now by AIStationList
truelight
parents:
diff
changeset
|
16 |
|
f6d169a5a45a
(svn r10529) [NoAI] -Add: added AIStation to gather information about stations directly by Id, which is used now by AIStationList
truelight
parents:
diff
changeset
|
17 |
/* static */ bool AIStation::IsValidStation(StationID station_id) |
f6d169a5a45a
(svn r10529) [NoAI] -Add: added AIStation to gather information about stations directly by Id, which is used now by AIStationList
truelight
parents:
diff
changeset
|
18 |
{ |
f6d169a5a45a
(svn r10529) [NoAI] -Add: added AIStation to gather information about stations directly by Id, which is used now by AIStationList
truelight
parents:
diff
changeset
|
19 |
return ::IsValidStationID(station_id) && ::GetStation(station_id)->owner == _current_player; |
f6d169a5a45a
(svn r10529) [NoAI] -Add: added AIStation to gather information about stations directly by Id, which is used now by AIStationList
truelight
parents:
diff
changeset
|
20 |
} |
f6d169a5a45a
(svn r10529) [NoAI] -Add: added AIStation to gather information about stations directly by Id, which is used now by AIStationList
truelight
parents:
diff
changeset
|
21 |
|
9666
5765eb70736d
(svn r10580) [NoAI] -Add: added GetStationID to get the StationID based on a tile
truelight
parents:
9648
diff
changeset
|
22 |
/* static */ StationID AIStation::GetStationID(TileIndex tile) |
5765eb70736d
(svn r10580) [NoAI] -Add: added GetStationID to get the StationID based on a tile
truelight
parents:
9648
diff
changeset
|
23 |
{ |
5765eb70736d
(svn r10580) [NoAI] -Add: added GetStationID to get the StationID based on a tile
truelight
parents:
9648
diff
changeset
|
24 |
if (!::IsTileType(tile, MP_STATION)) return INVALID_STATION; |
5765eb70736d
(svn r10580) [NoAI] -Add: added GetStationID to get the StationID based on a tile
truelight
parents:
9648
diff
changeset
|
25 |
return ::GetStationIndex(tile); |
5765eb70736d
(svn r10580) [NoAI] -Add: added GetStationID to get the StationID based on a tile
truelight
parents:
9648
diff
changeset
|
26 |
} |
5765eb70736d
(svn r10580) [NoAI] -Add: added GetStationID to get the StationID based on a tile
truelight
parents:
9648
diff
changeset
|
27 |
|
9696
4384ed3de1f0
(svn r10937) [NoAI] -Add: added AIStation::GetName on request by Nickman
truelight
parents:
9670
diff
changeset
|
28 |
/* static */ char *AIStation::GetName(StationID station_id) |
4384ed3de1f0
(svn r10937) [NoAI] -Add: added AIStation::GetName on request by Nickman
truelight
parents:
9670
diff
changeset
|
29 |
{ |
4384ed3de1f0
(svn r10937) [NoAI] -Add: added AIStation::GetName on request by Nickman
truelight
parents:
9670
diff
changeset
|
30 |
if (!AIStation::IsValidStation(station_id)) return NULL; |
4384ed3de1f0
(svn r10937) [NoAI] -Add: added AIStation::GetName on request by Nickman
truelight
parents:
9670
diff
changeset
|
31 |
|
4384ed3de1f0
(svn r10937) [NoAI] -Add: added AIStation::GetName on request by Nickman
truelight
parents:
9670
diff
changeset
|
32 |
static const int len = 64; |
4384ed3de1f0
(svn r10937) [NoAI] -Add: added AIStation::GetName on request by Nickman
truelight
parents:
9670
diff
changeset
|
33 |
char *station_name = MallocT<char>(len); |
4384ed3de1f0
(svn r10937) [NoAI] -Add: added AIStation::GetName on request by Nickman
truelight
parents:
9670
diff
changeset
|
34 |
|
4384ed3de1f0
(svn r10937) [NoAI] -Add: added AIStation::GetName on request by Nickman
truelight
parents:
9670
diff
changeset
|
35 |
SetDParam(0, GetStation(station_id)->index); |
4384ed3de1f0
(svn r10937) [NoAI] -Add: added AIStation::GetName on request by Nickman
truelight
parents:
9670
diff
changeset
|
36 |
GetString(station_name, STR_STATION, &station_name[len - 1]); |
4384ed3de1f0
(svn r10937) [NoAI] -Add: added AIStation::GetName on request by Nickman
truelight
parents:
9670
diff
changeset
|
37 |
return station_name; |
4384ed3de1f0
(svn r10937) [NoAI] -Add: added AIStation::GetName on request by Nickman
truelight
parents:
9670
diff
changeset
|
38 |
} |
4384ed3de1f0
(svn r10937) [NoAI] -Add: added AIStation::GetName on request by Nickman
truelight
parents:
9670
diff
changeset
|
39 |
|
9638
f6d169a5a45a
(svn r10529) [NoAI] -Add: added AIStation to gather information about stations directly by Id, which is used now by AIStationList
truelight
parents:
diff
changeset
|
40 |
/* static */ TileIndex AIStation::GetLocation(StationID station_id) |
f6d169a5a45a
(svn r10529) [NoAI] -Add: added AIStation to gather information about stations directly by Id, which is used now by AIStationList
truelight
parents:
diff
changeset
|
41 |
{ |
f6d169a5a45a
(svn r10529) [NoAI] -Add: added AIStation to gather information about stations directly by Id, which is used now by AIStationList
truelight
parents:
diff
changeset
|
42 |
if (!AIStation::IsValidStation(station_id)) return INVALID_TILE; |
f6d169a5a45a
(svn r10529) [NoAI] -Add: added AIStation to gather information about stations directly by Id, which is used now by AIStationList
truelight
parents:
diff
changeset
|
43 |
|
f6d169a5a45a
(svn r10529) [NoAI] -Add: added AIStation to gather information about stations directly by Id, which is used now by AIStationList
truelight
parents:
diff
changeset
|
44 |
return ::GetStation(station_id)->xy; |
f6d169a5a45a
(svn r10529) [NoAI] -Add: added AIStation to gather information about stations directly by Id, which is used now by AIStationList
truelight
parents:
diff
changeset
|
45 |
} |
f6d169a5a45a
(svn r10529) [NoAI] -Add: added AIStation to gather information about stations directly by Id, which is used now by AIStationList
truelight
parents:
diff
changeset
|
46 |
|
f6d169a5a45a
(svn r10529) [NoAI] -Add: added AIStation to gather information about stations directly by Id, which is used now by AIStationList
truelight
parents:
diff
changeset
|
47 |
/* static */ int32 AIStation::GetCargoWaiting(StationID station_id, CargoID cargo_id) |
f6d169a5a45a
(svn r10529) [NoAI] -Add: added AIStation to gather information about stations directly by Id, which is used now by AIStationList
truelight
parents:
diff
changeset
|
48 |
{ |
f6d169a5a45a
(svn r10529) [NoAI] -Add: added AIStation to gather information about stations directly by Id, which is used now by AIStationList
truelight
parents:
diff
changeset
|
49 |
if (!AIStation::IsValidStation(station_id)) return -1; |
f6d169a5a45a
(svn r10529) [NoAI] -Add: added AIStation to gather information about stations directly by Id, which is used now by AIStationList
truelight
parents:
diff
changeset
|
50 |
if (!AICargo::IsValidCargo(cargo_id)) return -1; |
f6d169a5a45a
(svn r10529) [NoAI] -Add: added AIStation to gather information about stations directly by Id, which is used now by AIStationList
truelight
parents:
diff
changeset
|
51 |
|
f6d169a5a45a
(svn r10529) [NoAI] -Add: added AIStation to gather information about stations directly by Id, which is used now by AIStationList
truelight
parents:
diff
changeset
|
52 |
return ::GetStation(station_id)->goods[cargo_id].cargo.Count(); |
f6d169a5a45a
(svn r10529) [NoAI] -Add: added AIStation to gather information about stations directly by Id, which is used now by AIStationList
truelight
parents:
diff
changeset
|
53 |
} |
9648
760b7b504e37
(svn r10543) [NoAI] -Add: added AIStationListCargoRating as valuator for a station list
truelight
parents:
9638
diff
changeset
|
54 |
|
760b7b504e37
(svn r10543) [NoAI] -Add: added AIStationListCargoRating as valuator for a station list
truelight
parents:
9638
diff
changeset
|
55 |
/* static */ int32 AIStation::GetCargoRating(StationID station_id, CargoID cargo_id) |
760b7b504e37
(svn r10543) [NoAI] -Add: added AIStationListCargoRating as valuator for a station list
truelight
parents:
9638
diff
changeset
|
56 |
{ |
760b7b504e37
(svn r10543) [NoAI] -Add: added AIStationListCargoRating as valuator for a station list
truelight
parents:
9638
diff
changeset
|
57 |
if (!AIStation::IsValidStation(station_id)) return -1; |
760b7b504e37
(svn r10543) [NoAI] -Add: added AIStationListCargoRating as valuator for a station list
truelight
parents:
9638
diff
changeset
|
58 |
if (!AICargo::IsValidCargo(cargo_id)) return -1; |
760b7b504e37
(svn r10543) [NoAI] -Add: added AIStationListCargoRating as valuator for a station list
truelight
parents:
9638
diff
changeset
|
59 |
|
760b7b504e37
(svn r10543) [NoAI] -Add: added AIStationListCargoRating as valuator for a station list
truelight
parents:
9638
diff
changeset
|
60 |
return ::GetStation(station_id)->goods[cargo_id].rating * 101 >> 8; |
760b7b504e37
(svn r10543) [NoAI] -Add: added AIStationListCargoRating as valuator for a station list
truelight
parents:
9638
diff
changeset
|
61 |
} |
9670
820b77e19bb3
(svn r10609) [NoAI] -Add: added GetAirportWidth / GetAirportHeight
truelight
parents:
9666
diff
changeset
|
62 |
|
820b77e19bb3
(svn r10609) [NoAI] -Add: added GetAirportWidth / GetAirportHeight
truelight
parents:
9666
diff
changeset
|
63 |
/* static */ int32 AIStation::GetCoverageRadius(AIStation::StationType type) |
820b77e19bb3
(svn r10609) [NoAI] -Add: added GetAirportWidth / GetAirportHeight
truelight
parents:
9666
diff
changeset
|
64 |
{ |
820b77e19bb3
(svn r10609) [NoAI] -Add: added GetAirportWidth / GetAirportHeight
truelight
parents:
9666
diff
changeset
|
65 |
if (type == STATION_AIRPORT) { |
820b77e19bb3
(svn r10609) [NoAI] -Add: added GetAirportWidth / GetAirportHeight
truelight
parents:
9666
diff
changeset
|
66 |
DEBUG(ai, 0, "GetCoverageRadius(): coverage radius of airports needs to be requested via AIAirport::GetAirportCoverageRadius(), as it requires AirportType"); |
820b77e19bb3
(svn r10609) [NoAI] -Add: added GetAirportWidth / GetAirportHeight
truelight
parents:
9666
diff
changeset
|
67 |
return 0; |
820b77e19bb3
(svn r10609) [NoAI] -Add: added GetAirportWidth / GetAirportHeight
truelight
parents:
9666
diff
changeset
|
68 |
} |
820b77e19bb3
(svn r10609) [NoAI] -Add: added GetAirportWidth / GetAirportHeight
truelight
parents:
9666
diff
changeset
|
69 |
if (!_patches.modified_catchment) return 3; |
820b77e19bb3
(svn r10609) [NoAI] -Add: added GetAirportWidth / GetAirportHeight
truelight
parents:
9666
diff
changeset
|
70 |
|
820b77e19bb3
(svn r10609) [NoAI] -Add: added GetAirportWidth / GetAirportHeight
truelight
parents:
9666
diff
changeset
|
71 |
switch (type) { |
820b77e19bb3
(svn r10609) [NoAI] -Add: added GetAirportWidth / GetAirportHeight
truelight
parents:
9666
diff
changeset
|
72 |
case STATION_TRAIN: return CA_TRAIN; |
820b77e19bb3
(svn r10609) [NoAI] -Add: added GetAirportWidth / GetAirportHeight
truelight
parents:
9666
diff
changeset
|
73 |
case STATION_TRUCK_STOP: return CA_TRUCK; |
820b77e19bb3
(svn r10609) [NoAI] -Add: added GetAirportWidth / GetAirportHeight
truelight
parents:
9666
diff
changeset
|
74 |
case STATION_BUS_STOP: return CA_BUS; |
820b77e19bb3
(svn r10609) [NoAI] -Add: added GetAirportWidth / GetAirportHeight
truelight
parents:
9666
diff
changeset
|
75 |
case STATION_DOCK: return CA_DOCK; |
820b77e19bb3
(svn r10609) [NoAI] -Add: added GetAirportWidth / GetAirportHeight
truelight
parents:
9666
diff
changeset
|
76 |
default: return CA_NONE; |
820b77e19bb3
(svn r10609) [NoAI] -Add: added GetAirportWidth / GetAirportHeight
truelight
parents:
9666
diff
changeset
|
77 |
} |
820b77e19bb3
(svn r10609) [NoAI] -Add: added GetAirportWidth / GetAirportHeight
truelight
parents:
9666
diff
changeset
|
78 |
} |