equal
deleted
inserted
replaced
5 #include "ai_cargo.hpp" |
5 #include "ai_cargo.hpp" |
6 #include "../../cargotype.h" |
6 #include "../../cargotype.h" |
7 #include "../../player.h" // For economy.h |
7 #include "../../player.h" // For economy.h |
8 #include "../../economy.h" |
8 #include "../../economy.h" |
9 |
9 |
|
10 bool AICargo::IsValidCargo(CargoID cargo_type) |
|
11 { |
|
12 return (cargo_type < NUM_CARGO && GetCargo(cargo_type)->IsValid()); |
|
13 } |
|
14 |
10 char *AICargo::GetCargoLabel(CargoID cargo_type) |
15 char *AICargo::GetCargoLabel(CargoID cargo_type) |
11 { |
16 { |
12 if (cargo_type >= NUM_CARGO) return NULL; |
17 if (!this->IsValidCargo(cargo_type)) return NULL; |
13 const CargoSpec *cargo = GetCargo(cargo_type); |
18 const CargoSpec *cargo = GetCargo(cargo_type); |
14 |
19 |
15 /* cargo->label is a uint32 packing a 4 character non-terminated string, |
20 /* cargo->label is a uint32 packing a 4 character non-terminated string, |
16 * like "PASS", "COAL", "OIL_". New ones can be defined by NewGRFs */ |
21 * like "PASS", "COAL", "OIL_". New ones can be defined by NewGRFs */ |
17 char *cargo_label = MallocT<char>(sizeof(cargo->label) + 1); |
22 char *cargo_label = MallocT<char>(sizeof(cargo->label) + 1); |
22 return cargo_label; |
27 return cargo_label; |
23 } |
28 } |
24 |
29 |
25 bool AICargo::IsFreight(CargoID cargo_type) |
30 bool AICargo::IsFreight(CargoID cargo_type) |
26 { |
31 { |
27 if (cargo_type >= NUM_CARGO) return false; |
32 if (!this->IsValidCargo(cargo_type)) return false; |
28 const CargoSpec *cargo = GetCargo(cargo_type); |
33 const CargoSpec *cargo = GetCargo(cargo_type); |
29 return cargo->is_freight; |
34 return cargo->is_freight; |
30 } |
35 } |
31 |
36 |
32 int32 AICargo::GetCargoIncome(uint32 distance, uint32 days_in_transit, CargoID cargo_type) |
37 int32 AICargo::GetCargoIncome(uint32 distance, uint32 days_in_transit, CargoID cargo_type) |
33 { |
38 { |
34 if (cargo_type >= NUM_CARGO) return 0; |
39 if (!this->IsValidCargo(cargo_type)) return 0; |
35 return GetTransportedGoodsIncome(1, distance, days_in_transit, cargo_type); |
40 return GetTransportedGoodsIncome(1, distance, days_in_transit, cargo_type); |
36 } |
41 } |