author | truebrain |
Tue, 29 Apr 2008 21:34:17 +0000 | |
branch | noai |
changeset 10383 | bda80b3e9c25 |
parent 10339 | ce6cd68d9eb8 |
child 10842 | 681a3954232a |
permissions | -rw-r--r-- |
9405
df6f3b4b0038
(svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
diff
changeset
|
1 |
/* $Id$ */ |
df6f3b4b0038
(svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
diff
changeset
|
2 |
|
9833
89a64246458f
(svn r12496) [NoAI] -Documentation: give the .cpp files a nice uniform format too
truebrain
parents:
9814
diff
changeset
|
3 |
/** @file ai_industry.cpp Implementation of AIIndustry. */ |
9405
df6f3b4b0038
(svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
diff
changeset
|
4 |
|
9430
9e0a193b2bec
(svn r9234) [NoAI] -Codechange: move away from the 'much' subdirectory approach for the API implementation.
rubidium
parents:
9427
diff
changeset
|
5 |
#include "ai_industry.hpp" |
9649
bc8c06513f5b
(svn r10544) [NoAI] -Add: added AIIndustryList to list industries
truelight
parents:
9497
diff
changeset
|
6 |
#include "ai_cargo.hpp" |
9814
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9810
diff
changeset
|
7 |
#include "ai_map.hpp" |
10339
ce6cd68d9eb8
(svn r12880) [NoAI] -Add: introduces ai_types.hpp, which has all NNNId like VehicleID. This simplifies the include-mess, and avoids including tons of _type.h for just a single typedef.
truebrain
parents:
10300
diff
changeset
|
8 |
#include "../../openttd.h" |
9430
9e0a193b2bec
(svn r9234) [NoAI] -Codechange: move away from the 'much' subdirectory approach for the API implementation.
rubidium
parents:
9427
diff
changeset
|
9 |
#include "../../industry.h" |
10339
ce6cd68d9eb8
(svn r12880) [NoAI] -Add: introduces ai_types.hpp, which has all NNNId like VehicleID. This simplifies the include-mess, and avoids including tons of _type.h for just a single typedef.
truebrain
parents:
10300
diff
changeset
|
10 |
#include "../../tile_type.h" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9717
diff
changeset
|
11 |
#include "../../strings_func.h" |
10383
bda80b3e9c25
(svn r12925) [NoAI] -Add: added AIIndustry::GetAmountOfStationsAround() (Yexo)
truebrain
parents:
10339
diff
changeset
|
12 |
#include "../../station_func.h" |
9405
df6f3b4b0038
(svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
diff
changeset
|
13 |
#include "table/strings.h" |
df6f3b4b0038
(svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
diff
changeset
|
14 |
|
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
|
15 |
/* static */ IndustryID AIIndustry::GetMaxIndustryID() |
9405
df6f3b4b0038
(svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
diff
changeset
|
16 |
{ |
df6f3b4b0038
(svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
diff
changeset
|
17 |
return ::GetMaxIndustryIndex(); |
df6f3b4b0038
(svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
diff
changeset
|
18 |
} |
df6f3b4b0038
(svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
diff
changeset
|
19 |
|
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
|
20 |
/* static */ int32 AIIndustry::GetIndustryCount() |
9405
df6f3b4b0038
(svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
diff
changeset
|
21 |
{ |
df6f3b4b0038
(svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
diff
changeset
|
22 |
return ::GetNumIndustries(); |
df6f3b4b0038
(svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
diff
changeset
|
23 |
} |
df6f3b4b0038
(svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
diff
changeset
|
24 |
|
9497
f6678533ccba
(svn r9369) [NoAI] -Codechange: make some IsValidXXX() function static, so they can be used by the other classes without the need for an instance.
rubidium
parents:
9459
diff
changeset
|
25 |
/* static */ bool AIIndustry::IsValidIndustry(IndustryID industry_id) |
9405
df6f3b4b0038
(svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
diff
changeset
|
26 |
{ |
df6f3b4b0038
(svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
diff
changeset
|
27 |
return ::IsValidIndustryID(industry_id); |
df6f3b4b0038
(svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
diff
changeset
|
28 |
} |
df6f3b4b0038
(svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
diff
changeset
|
29 |
|
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
|
30 |
/* static */ char *AIIndustry::GetName(IndustryID industry_id) |
9405
df6f3b4b0038
(svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
diff
changeset
|
31 |
{ |
9736
183b38e0a480
(svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents:
9723
diff
changeset
|
32 |
if (!IsValidIndustry(industry_id)) return NULL; |
9405
df6f3b4b0038
(svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
diff
changeset
|
33 |
static const int len = 64; |
df6f3b4b0038
(svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
diff
changeset
|
34 |
char *industry_name = MallocT<char>(len); |
df6f3b4b0038
(svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
diff
changeset
|
35 |
|
9736
183b38e0a480
(svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents:
9723
diff
changeset
|
36 |
::SetDParam(0, industry_id); |
183b38e0a480
(svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents:
9723
diff
changeset
|
37 |
::GetString(industry_name, STR_INDUSTRY, &industry_name[len - 1]); |
9405
df6f3b4b0038
(svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
diff
changeset
|
38 |
|
df6f3b4b0038
(svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
diff
changeset
|
39 |
return industry_name; |
df6f3b4b0038
(svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
diff
changeset
|
40 |
} |
df6f3b4b0038
(svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
diff
changeset
|
41 |
|
9650
7e5e1a7ecbff
(svn r10545) [NoAI] -Fix: GetProduction doesn't return a tile, but a value (tnx glx)
truelight
parents:
9649
diff
changeset
|
42 |
/* static */ int32 AIIndustry::GetProduction(IndustryID industry_id, CargoID cargo_id) |
9405
df6f3b4b0038
(svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
diff
changeset
|
43 |
{ |
9736
183b38e0a480
(svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents:
9723
diff
changeset
|
44 |
if (!IsValidIndustry(industry_id)) return -1; |
9649
bc8c06513f5b
(svn r10544) [NoAI] -Add: added AIIndustryList to list industries
truelight
parents:
9497
diff
changeset
|
45 |
if (!AICargo::IsValidCargo(cargo_id)) return -1; |
bc8c06513f5b
(svn r10544) [NoAI] -Add: added AIIndustryList to list industries
truelight
parents:
9497
diff
changeset
|
46 |
|
9405
df6f3b4b0038
(svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
diff
changeset
|
47 |
const Industry *i = ::GetIndustry(industry_id); |
9736
183b38e0a480
(svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents:
9723
diff
changeset
|
48 |
const IndustrySpec *indsp = ::GetIndustrySpec(i->type); |
9649
bc8c06513f5b
(svn r10544) [NoAI] -Add: added AIIndustryList to list industries
truelight
parents:
9497
diff
changeset
|
49 |
|
9795
679ba7cd8426
(svn r12299) [NoAI] -Fix: don't assume any length of produced_cargo and accepts_cargo
truebrain
parents:
9737
diff
changeset
|
50 |
for (byte j = 0; j < lengthof(indsp->produced_cargo); j++) |
9798
28e94a3b2b06
(svn r12302) [NoAI] -Fix: GetProducing is multiplied by 8 for the GUI, so also do it for our API, to make less confusion for people (Progman)
truebrain
parents:
9795
diff
changeset
|
51 |
if (indsp->produced_cargo[j] == cargo_id) return i->production_rate[j] * 8; |
9795
679ba7cd8426
(svn r12299) [NoAI] -Fix: don't assume any length of produced_cargo and accepts_cargo
truebrain
parents:
9737
diff
changeset
|
52 |
|
9649
bc8c06513f5b
(svn r10544) [NoAI] -Add: added AIIndustryList to list industries
truelight
parents:
9497
diff
changeset
|
53 |
return -1; |
9405
df6f3b4b0038
(svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
diff
changeset
|
54 |
} |
9649
bc8c06513f5b
(svn r10544) [NoAI] -Add: added AIIndustryList to list industries
truelight
parents:
9497
diff
changeset
|
55 |
|
9710
ba44f8c1fd52
(svn r11294) [NoAI] -Add: added AIIndustry::IsCargoAccepted + Valuator (on request by Kilinich)
truelight
parents:
9650
diff
changeset
|
56 |
/* static */ bool AIIndustry::IsCargoAccepted(IndustryID industry_id, CargoID cargo_id) |
ba44f8c1fd52
(svn r11294) [NoAI] -Add: added AIIndustry::IsCargoAccepted + Valuator (on request by Kilinich)
truelight
parents:
9650
diff
changeset
|
57 |
{ |
9736
183b38e0a480
(svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents:
9723
diff
changeset
|
58 |
if (!IsValidIndustry(industry_id)) return false; |
9710
ba44f8c1fd52
(svn r11294) [NoAI] -Add: added AIIndustry::IsCargoAccepted + Valuator (on request by Kilinich)
truelight
parents:
9650
diff
changeset
|
59 |
if (!AICargo::IsValidCargo(cargo_id)) return false; |
ba44f8c1fd52
(svn r11294) [NoAI] -Add: added AIIndustry::IsCargoAccepted + Valuator (on request by Kilinich)
truelight
parents:
9650
diff
changeset
|
60 |
|
ba44f8c1fd52
(svn r11294) [NoAI] -Add: added AIIndustry::IsCargoAccepted + Valuator (on request by Kilinich)
truelight
parents:
9650
diff
changeset
|
61 |
const Industry *i = ::GetIndustry(industry_id); |
9736
183b38e0a480
(svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents:
9723
diff
changeset
|
62 |
const IndustrySpec *indsp = ::GetIndustrySpec(i->type); |
9710
ba44f8c1fd52
(svn r11294) [NoAI] -Add: added AIIndustry::IsCargoAccepted + Valuator (on request by Kilinich)
truelight
parents:
9650
diff
changeset
|
63 |
|
9795
679ba7cd8426
(svn r12299) [NoAI] -Fix: don't assume any length of produced_cargo and accepts_cargo
truebrain
parents:
9737
diff
changeset
|
64 |
for (byte j = 0; j < lengthof(indsp->accepts_cargo); j++) |
679ba7cd8426
(svn r12299) [NoAI] -Fix: don't assume any length of produced_cargo and accepts_cargo
truebrain
parents:
9737
diff
changeset
|
65 |
if (indsp->accepts_cargo[j] == cargo_id) return true; |
9710
ba44f8c1fd52
(svn r11294) [NoAI] -Add: added AIIndustry::IsCargoAccepted + Valuator (on request by Kilinich)
truelight
parents:
9650
diff
changeset
|
66 |
|
ba44f8c1fd52
(svn r11294) [NoAI] -Add: added AIIndustry::IsCargoAccepted + Valuator (on request by Kilinich)
truelight
parents:
9650
diff
changeset
|
67 |
return false; |
ba44f8c1fd52
(svn r11294) [NoAI] -Add: added AIIndustry::IsCargoAccepted + Valuator (on request by Kilinich)
truelight
parents:
9650
diff
changeset
|
68 |
} |
ba44f8c1fd52
(svn r11294) [NoAI] -Add: added AIIndustry::IsCargoAccepted + Valuator (on request by Kilinich)
truelight
parents:
9650
diff
changeset
|
69 |
|
9810
a84fc1be9e3b
(svn r12327) [NoAI] -Add: GetLastMonth(Production|Transported) (Morloth)
truebrain
parents:
9798
diff
changeset
|
70 |
/* static */ uint16 AIIndustry::GetLastMonthProduction(IndustryID industry_id, CargoID cargo_id) |
a84fc1be9e3b
(svn r12327) [NoAI] -Add: GetLastMonth(Production|Transported) (Morloth)
truebrain
parents:
9798
diff
changeset
|
71 |
{ |
a84fc1be9e3b
(svn r12327) [NoAI] -Add: GetLastMonth(Production|Transported) (Morloth)
truebrain
parents:
9798
diff
changeset
|
72 |
if (!IsValidIndustry(industry_id)) return false; |
a84fc1be9e3b
(svn r12327) [NoAI] -Add: GetLastMonth(Production|Transported) (Morloth)
truebrain
parents:
9798
diff
changeset
|
73 |
if (!AICargo::IsValidCargo(cargo_id)) return false; |
a84fc1be9e3b
(svn r12327) [NoAI] -Add: GetLastMonth(Production|Transported) (Morloth)
truebrain
parents:
9798
diff
changeset
|
74 |
|
a84fc1be9e3b
(svn r12327) [NoAI] -Add: GetLastMonth(Production|Transported) (Morloth)
truebrain
parents:
9798
diff
changeset
|
75 |
const Industry *i = ::GetIndustry(industry_id); |
a84fc1be9e3b
(svn r12327) [NoAI] -Add: GetLastMonth(Production|Transported) (Morloth)
truebrain
parents:
9798
diff
changeset
|
76 |
const IndustrySpec *indsp = ::GetIndustrySpec(i->type); |
a84fc1be9e3b
(svn r12327) [NoAI] -Add: GetLastMonth(Production|Transported) (Morloth)
truebrain
parents:
9798
diff
changeset
|
77 |
|
a84fc1be9e3b
(svn r12327) [NoAI] -Add: GetLastMonth(Production|Transported) (Morloth)
truebrain
parents:
9798
diff
changeset
|
78 |
for (byte j = 0; j < lengthof(indsp->produced_cargo); j++) |
a84fc1be9e3b
(svn r12327) [NoAI] -Add: GetLastMonth(Production|Transported) (Morloth)
truebrain
parents:
9798
diff
changeset
|
79 |
if (indsp->produced_cargo[j] == cargo_id) return i->last_month_production[j]; |
a84fc1be9e3b
(svn r12327) [NoAI] -Add: GetLastMonth(Production|Transported) (Morloth)
truebrain
parents:
9798
diff
changeset
|
80 |
|
a84fc1be9e3b
(svn r12327) [NoAI] -Add: GetLastMonth(Production|Transported) (Morloth)
truebrain
parents:
9798
diff
changeset
|
81 |
return false; |
a84fc1be9e3b
(svn r12327) [NoAI] -Add: GetLastMonth(Production|Transported) (Morloth)
truebrain
parents:
9798
diff
changeset
|
82 |
} |
a84fc1be9e3b
(svn r12327) [NoAI] -Add: GetLastMonth(Production|Transported) (Morloth)
truebrain
parents:
9798
diff
changeset
|
83 |
|
a84fc1be9e3b
(svn r12327) [NoAI] -Add: GetLastMonth(Production|Transported) (Morloth)
truebrain
parents:
9798
diff
changeset
|
84 |
/* static */ uint16 AIIndustry::GetLastMonthTransported(IndustryID industry_id, CargoID cargo_id) |
a84fc1be9e3b
(svn r12327) [NoAI] -Add: GetLastMonth(Production|Transported) (Morloth)
truebrain
parents:
9798
diff
changeset
|
85 |
{ |
a84fc1be9e3b
(svn r12327) [NoAI] -Add: GetLastMonth(Production|Transported) (Morloth)
truebrain
parents:
9798
diff
changeset
|
86 |
if (!IsValidIndustry(industry_id)) return false; |
a84fc1be9e3b
(svn r12327) [NoAI] -Add: GetLastMonth(Production|Transported) (Morloth)
truebrain
parents:
9798
diff
changeset
|
87 |
if (!AICargo::IsValidCargo(cargo_id)) return false; |
a84fc1be9e3b
(svn r12327) [NoAI] -Add: GetLastMonth(Production|Transported) (Morloth)
truebrain
parents:
9798
diff
changeset
|
88 |
|
a84fc1be9e3b
(svn r12327) [NoAI] -Add: GetLastMonth(Production|Transported) (Morloth)
truebrain
parents:
9798
diff
changeset
|
89 |
const Industry *i = ::GetIndustry(industry_id); |
a84fc1be9e3b
(svn r12327) [NoAI] -Add: GetLastMonth(Production|Transported) (Morloth)
truebrain
parents:
9798
diff
changeset
|
90 |
const IndustrySpec *indsp = ::GetIndustrySpec(i->type); |
a84fc1be9e3b
(svn r12327) [NoAI] -Add: GetLastMonth(Production|Transported) (Morloth)
truebrain
parents:
9798
diff
changeset
|
91 |
|
a84fc1be9e3b
(svn r12327) [NoAI] -Add: GetLastMonth(Production|Transported) (Morloth)
truebrain
parents:
9798
diff
changeset
|
92 |
for (byte j = 0; j < lengthof(indsp->produced_cargo); j++) |
a84fc1be9e3b
(svn r12327) [NoAI] -Add: GetLastMonth(Production|Transported) (Morloth)
truebrain
parents:
9798
diff
changeset
|
93 |
if (indsp->produced_cargo[j] == cargo_id) return i->last_month_transported[j]; |
a84fc1be9e3b
(svn r12327) [NoAI] -Add: GetLastMonth(Production|Transported) (Morloth)
truebrain
parents:
9798
diff
changeset
|
94 |
|
a84fc1be9e3b
(svn r12327) [NoAI] -Add: GetLastMonth(Production|Transported) (Morloth)
truebrain
parents:
9798
diff
changeset
|
95 |
return false; |
a84fc1be9e3b
(svn r12327) [NoAI] -Add: GetLastMonth(Production|Transported) (Morloth)
truebrain
parents:
9798
diff
changeset
|
96 |
} |
9814
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9810
diff
changeset
|
97 |
|
10383
bda80b3e9c25
(svn r12925) [NoAI] -Add: added AIIndustry::GetAmountOfStationsAround() (Yexo)
truebrain
parents:
10339
diff
changeset
|
98 |
/* static */ TileIndex AIIndustry::GetLocation(IndustryID industry_id) |
bda80b3e9c25
(svn r12925) [NoAI] -Add: added AIIndustry::GetAmountOfStationsAround() (Yexo)
truebrain
parents:
10339
diff
changeset
|
99 |
{ |
bda80b3e9c25
(svn r12925) [NoAI] -Add: added AIIndustry::GetAmountOfStationsAround() (Yexo)
truebrain
parents:
10339
diff
changeset
|
100 |
if (!IsValidIndustry(industry_id)) return INVALID_TILE; |
bda80b3e9c25
(svn r12925) [NoAI] -Add: added AIIndustry::GetAmountOfStationsAround() (Yexo)
truebrain
parents:
10339
diff
changeset
|
101 |
|
bda80b3e9c25
(svn r12925) [NoAI] -Add: added AIIndustry::GetAmountOfStationsAround() (Yexo)
truebrain
parents:
10339
diff
changeset
|
102 |
return ::GetIndustry(industry_id)->xy; |
bda80b3e9c25
(svn r12925) [NoAI] -Add: added AIIndustry::GetAmountOfStationsAround() (Yexo)
truebrain
parents:
10339
diff
changeset
|
103 |
} |
bda80b3e9c25
(svn r12925) [NoAI] -Add: added AIIndustry::GetAmountOfStationsAround() (Yexo)
truebrain
parents:
10339
diff
changeset
|
104 |
|
bda80b3e9c25
(svn r12925) [NoAI] -Add: added AIIndustry::GetAmountOfStationsAround() (Yexo)
truebrain
parents:
10339
diff
changeset
|
105 |
/* static */ int32 AIIndustry::GetAmountOfStationsAround(IndustryID industry_id) |
bda80b3e9c25
(svn r12925) [NoAI] -Add: added AIIndustry::GetAmountOfStationsAround() (Yexo)
truebrain
parents:
10339
diff
changeset
|
106 |
{ |
bda80b3e9c25
(svn r12925) [NoAI] -Add: added AIIndustry::GetAmountOfStationsAround() (Yexo)
truebrain
parents:
10339
diff
changeset
|
107 |
if (!IsValidIndustry(industry_id)) return -1; |
bda80b3e9c25
(svn r12925) [NoAI] -Add: added AIIndustry::GetAmountOfStationsAround() (Yexo)
truebrain
parents:
10339
diff
changeset
|
108 |
|
bda80b3e9c25
(svn r12925) [NoAI] -Add: added AIIndustry::GetAmountOfStationsAround() (Yexo)
truebrain
parents:
10339
diff
changeset
|
109 |
Industry *ind = ::GetIndustry(industry_id); |
bda80b3e9c25
(svn r12925) [NoAI] -Add: added AIIndustry::GetAmountOfStationsAround() (Yexo)
truebrain
parents:
10339
diff
changeset
|
110 |
return ::FindStationsAroundIndustryTile(ind->xy, ind->width, ind->height).size(); |
bda80b3e9c25
(svn r12925) [NoAI] -Add: added AIIndustry::GetAmountOfStationsAround() (Yexo)
truebrain
parents:
10339
diff
changeset
|
111 |
} |
bda80b3e9c25
(svn r12925) [NoAI] -Add: added AIIndustry::GetAmountOfStationsAround() (Yexo)
truebrain
parents:
10339
diff
changeset
|
112 |
|
9814
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9810
diff
changeset
|
113 |
/* static */ int32 AIIndustry::GetDistanceManhattanToTile(IndustryID industry_id, TileIndex tile) |
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9810
diff
changeset
|
114 |
{ |
10383
bda80b3e9c25
(svn r12925) [NoAI] -Add: added AIIndustry::GetAmountOfStationsAround() (Yexo)
truebrain
parents:
10339
diff
changeset
|
115 |
if (!IsValidIndustry(industry_id)) return -1; |
bda80b3e9c25
(svn r12925) [NoAI] -Add: added AIIndustry::GetAmountOfStationsAround() (Yexo)
truebrain
parents:
10339
diff
changeset
|
116 |
|
9814
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9810
diff
changeset
|
117 |
return AIMap::DistanceManhattan(tile, GetLocation(industry_id)); |
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9810
diff
changeset
|
118 |
} |
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9810
diff
changeset
|
119 |
|
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9810
diff
changeset
|
120 |
/* static */ int32 AIIndustry::GetDistanceSquareToTile(IndustryID industry_id, TileIndex tile) |
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9810
diff
changeset
|
121 |
{ |
10383
bda80b3e9c25
(svn r12925) [NoAI] -Add: added AIIndustry::GetAmountOfStationsAround() (Yexo)
truebrain
parents:
10339
diff
changeset
|
122 |
if (!IsValidIndustry(industry_id)) return -1; |
bda80b3e9c25
(svn r12925) [NoAI] -Add: added AIIndustry::GetAmountOfStationsAround() (Yexo)
truebrain
parents:
10339
diff
changeset
|
123 |
|
9814
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9810
diff
changeset
|
124 |
return AIMap::DistanceSquare(tile, GetLocation(industry_id)); |
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9810
diff
changeset
|
125 |
} |
10300
f947a1d7e544
(svn r12841) [NoAI] -Add: function to test whether an industry is built on water/has a heliport/dock.
rubidium
parents:
9833
diff
changeset
|
126 |
|
f947a1d7e544
(svn r12841) [NoAI] -Add: function to test whether an industry is built on water/has a heliport/dock.
rubidium
parents:
9833
diff
changeset
|
127 |
/* static */ bool AIIndustry::IsBuiltOnWater(IndustryID industry_id) |
f947a1d7e544
(svn r12841) [NoAI] -Add: function to test whether an industry is built on water/has a heliport/dock.
rubidium
parents:
9833
diff
changeset
|
128 |
{ |
f947a1d7e544
(svn r12841) [NoAI] -Add: function to test whether an industry is built on water/has a heliport/dock.
rubidium
parents:
9833
diff
changeset
|
129 |
if (!IsValidIndustry(industry_id)) return false; |
f947a1d7e544
(svn r12841) [NoAI] -Add: function to test whether an industry is built on water/has a heliport/dock.
rubidium
parents:
9833
diff
changeset
|
130 |
|
f947a1d7e544
(svn r12841) [NoAI] -Add: function to test whether an industry is built on water/has a heliport/dock.
rubidium
parents:
9833
diff
changeset
|
131 |
return (::GetIndustrySpec(::GetIndustry(industry_id)->type)->behaviour & INDUSTRYBEH_BUILT_ONWATER) != 0; |
f947a1d7e544
(svn r12841) [NoAI] -Add: function to test whether an industry is built on water/has a heliport/dock.
rubidium
parents:
9833
diff
changeset
|
132 |
} |
f947a1d7e544
(svn r12841) [NoAI] -Add: function to test whether an industry is built on water/has a heliport/dock.
rubidium
parents:
9833
diff
changeset
|
133 |
|
f947a1d7e544
(svn r12841) [NoAI] -Add: function to test whether an industry is built on water/has a heliport/dock.
rubidium
parents:
9833
diff
changeset
|
134 |
/* static */ bool AIIndustry::HasHeliportAndDock(IndustryID industry_id) |
f947a1d7e544
(svn r12841) [NoAI] -Add: function to test whether an industry is built on water/has a heliport/dock.
rubidium
parents:
9833
diff
changeset
|
135 |
{ |
f947a1d7e544
(svn r12841) [NoAI] -Add: function to test whether an industry is built on water/has a heliport/dock.
rubidium
parents:
9833
diff
changeset
|
136 |
if (!IsValidIndustry(industry_id)) return false; |
f947a1d7e544
(svn r12841) [NoAI] -Add: function to test whether an industry is built on water/has a heliport/dock.
rubidium
parents:
9833
diff
changeset
|
137 |
|
f947a1d7e544
(svn r12841) [NoAI] -Add: function to test whether an industry is built on water/has a heliport/dock.
rubidium
parents:
9833
diff
changeset
|
138 |
return (::GetIndustrySpec(::GetIndustry(industry_id)->type)->behaviour & INDUSTRYBEH_AI_AIRSHIP_ROUTES) != 0; |
f947a1d7e544
(svn r12841) [NoAI] -Add: function to test whether an industry is built on water/has a heliport/dock.
rubidium
parents:
9833
diff
changeset
|
139 |
} |
f947a1d7e544
(svn r12841) [NoAI] -Add: function to test whether an industry is built on water/has a heliport/dock.
rubidium
parents:
9833
diff
changeset
|
140 |
|
f947a1d7e544
(svn r12841) [NoAI] -Add: function to test whether an industry is built on water/has a heliport/dock.
rubidium
parents:
9833
diff
changeset
|
141 |
/* static */ TileIndex AIIndustry::GetHeliportAndDockLocation(IndustryID industry_id) |
f947a1d7e544
(svn r12841) [NoAI] -Add: function to test whether an industry is built on water/has a heliport/dock.
rubidium
parents:
9833
diff
changeset
|
142 |
{ |
f947a1d7e544
(svn r12841) [NoAI] -Add: function to test whether an industry is built on water/has a heliport/dock.
rubidium
parents:
9833
diff
changeset
|
143 |
if (!IsValidIndustry(industry_id)) return INVALID_TILE; |
f947a1d7e544
(svn r12841) [NoAI] -Add: function to test whether an industry is built on water/has a heliport/dock.
rubidium
parents:
9833
diff
changeset
|
144 |
if (!HasHeliportAndDock(industry_id)) return INVALID_TILE; |
f947a1d7e544
(svn r12841) [NoAI] -Add: function to test whether an industry is built on water/has a heliport/dock.
rubidium
parents:
9833
diff
changeset
|
145 |
|
f947a1d7e544
(svn r12841) [NoAI] -Add: function to test whether an industry is built on water/has a heliport/dock.
rubidium
parents:
9833
diff
changeset
|
146 |
return ::GetIndustry(industry_id)->xy; |
f947a1d7e544
(svn r12841) [NoAI] -Add: function to test whether an industry is built on water/has a heliport/dock.
rubidium
parents:
9833
diff
changeset
|
147 |
} |