author | truebrain |
Sun, 15 Jun 2008 22:37:35 +0000 | |
branch | noai |
changeset 10972 | 986675d19245 |
parent 10869 | 4fdb11e1b599 |
permissions | -rw-r--r-- |
9380
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
1 |
/* $Id$ */ |
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
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_town.cpp Implementation of AITown. */ |
9380
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
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_town.hpp" |
9814
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9737
diff
changeset
|
6 |
#include "ai_map.hpp" |
10840
fd5945ab9ea6
(svn r13391) [NoAI] -Add: added AITown.GetNumHouses(), AITown.GetLastMonthProduction(), AITown.GetLastMonthTransported() and AITown.GetMaxProduction()
glx
parents:
10361
diff
changeset
|
7 |
#include "ai_cargo.hpp" |
10859
4c14a8041c0a
(svn r13410) [NoAI] -Add: functions to perform town actions (advertising, bribing, building statues, etc).
rubidium
parents:
10844
diff
changeset
|
8 |
#include "ai_error.hpp" |
4c14a8041c0a
(svn r13410) [NoAI] -Add: functions to perform town actions (advertising, bribing, building statues, etc).
rubidium
parents:
10844
diff
changeset
|
9 |
#include "../../command_type.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:
10194
diff
changeset
|
10 |
#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
|
11 |
#include "../../town.h" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9582
diff
changeset
|
12 |
#include "../../strings_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9582
diff
changeset
|
13 |
#include "../../core/alloc_func.hpp" |
10859
4c14a8041c0a
(svn r13410) [NoAI] -Add: functions to perform town actions (advertising, bribing, building statues, etc).
rubidium
parents:
10844
diff
changeset
|
14 |
#include "../../player_func.h" |
9405
df6f3b4b0038
(svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
9380
diff
changeset
|
15 |
#include "table/strings.h" |
9380
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
16 |
|
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
|
17 |
/* static */ TownID AITown::GetMaxTownID() |
9380
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
18 |
{ |
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
19 |
return ::GetMaxTownIndex(); |
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
20 |
} |
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
21 |
|
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
|
22 |
/* static */ int32 AITown::GetTownCount() |
9380
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
23 |
{ |
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
24 |
return ::GetNumTowns(); |
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
25 |
} |
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
26 |
|
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
|
27 |
/* static */ bool AITown::IsValidTown(TownID town_id) |
9380
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
28 |
{ |
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
29 |
return ::IsValidTownID(town_id); |
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
30 |
} |
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
31 |
|
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
|
32 |
/* static */ char *AITown::GetName(TownID town_id) |
9380
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
33 |
{ |
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
|
34 |
if (!IsValidTown(town_id)) return NULL; |
9380
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
35 |
static const int len = 64; |
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
36 |
char *town_name = MallocT<char>(len); |
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
37 |
|
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
|
38 |
::SetDParam(0, town_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
|
39 |
::GetString(town_name, STR_TOWN, &town_name[len - 1]); |
9380
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
40 |
|
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
41 |
return town_name; |
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
42 |
} |
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
43 |
|
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
|
44 |
/* static */ int32 AITown::GetPopulation(TownID town_id) |
9380
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
45 |
{ |
10194
c9fdeb7450da
(svn r12727) [NoAI] -Fix (API CHANGE): return -1 to indicate invalidity, instead of 0 or -1, depending on the class
truebrain
parents:
9833
diff
changeset
|
46 |
if (!IsValidTown(town_id)) return -1; |
9380
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
47 |
const Town *t = ::GetTown(town_id); |
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
48 |
return t->population; |
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
49 |
} |
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
50 |
|
10844
affb2821fb9f
(svn r13395) [NoAI] -Fix [API CHANGE]: Rename AIOrder::GetNumberOfORders to AIOrder::GetOrderCount
truebrain
parents:
10840
diff
changeset
|
51 |
/* static */ int32 AITown::GetHouseCount(TownID town_id) |
10840
fd5945ab9ea6
(svn r13391) [NoAI] -Add: added AITown.GetNumHouses(), AITown.GetLastMonthProduction(), AITown.GetLastMonthTransported() and AITown.GetMaxProduction()
glx
parents:
10361
diff
changeset
|
52 |
{ |
fd5945ab9ea6
(svn r13391) [NoAI] -Add: added AITown.GetNumHouses(), AITown.GetLastMonthProduction(), AITown.GetLastMonthTransported() and AITown.GetMaxProduction()
glx
parents:
10361
diff
changeset
|
53 |
if (!IsValidTown(town_id)) return -1; |
fd5945ab9ea6
(svn r13391) [NoAI] -Add: added AITown.GetNumHouses(), AITown.GetLastMonthProduction(), AITown.GetLastMonthTransported() and AITown.GetMaxProduction()
glx
parents:
10361
diff
changeset
|
54 |
const Town *t = ::GetTown(town_id); |
fd5945ab9ea6
(svn r13391) [NoAI] -Add: added AITown.GetNumHouses(), AITown.GetLastMonthProduction(), AITown.GetLastMonthTransported() and AITown.GetMaxProduction()
glx
parents:
10361
diff
changeset
|
55 |
return t->num_houses; |
fd5945ab9ea6
(svn r13391) [NoAI] -Add: added AITown.GetNumHouses(), AITown.GetLastMonthProduction(), AITown.GetLastMonthTransported() and AITown.GetMaxProduction()
glx
parents:
10361
diff
changeset
|
56 |
} |
fd5945ab9ea6
(svn r13391) [NoAI] -Add: added AITown.GetNumHouses(), AITown.GetLastMonthProduction(), AITown.GetLastMonthTransported() and AITown.GetMaxProduction()
glx
parents:
10361
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 */ TileIndex AITown::GetLocation(TownID town_id) |
9380
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
59 |
{ |
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
|
60 |
if (!IsValidTown(town_id)) return INVALID_TILE; |
9380
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
61 |
const Town *t = ::GetTown(town_id); |
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
62 |
return t->xy; |
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
63 |
} |
9814
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9737
diff
changeset
|
64 |
|
10840
fd5945ab9ea6
(svn r13391) [NoAI] -Add: added AITown.GetNumHouses(), AITown.GetLastMonthProduction(), AITown.GetLastMonthTransported() and AITown.GetMaxProduction()
glx
parents:
10361
diff
changeset
|
65 |
/* static */ int32 AITown::GetLastMonthProduction(TownID town_id, CargoID cargo_id) |
fd5945ab9ea6
(svn r13391) [NoAI] -Add: added AITown.GetNumHouses(), AITown.GetLastMonthProduction(), AITown.GetLastMonthTransported() and AITown.GetMaxProduction()
glx
parents:
10361
diff
changeset
|
66 |
{ |
fd5945ab9ea6
(svn r13391) [NoAI] -Add: added AITown.GetNumHouses(), AITown.GetLastMonthProduction(), AITown.GetLastMonthTransported() and AITown.GetMaxProduction()
glx
parents:
10361
diff
changeset
|
67 |
if (!IsValidTown(town_id)) return -1; |
fd5945ab9ea6
(svn r13391) [NoAI] -Add: added AITown.GetNumHouses(), AITown.GetLastMonthProduction(), AITown.GetLastMonthTransported() and AITown.GetMaxProduction()
glx
parents:
10361
diff
changeset
|
68 |
if (!AICargo::IsValidCargo(cargo_id)) return -1; |
fd5945ab9ea6
(svn r13391) [NoAI] -Add: added AITown.GetNumHouses(), AITown.GetLastMonthProduction(), AITown.GetLastMonthTransported() and AITown.GetMaxProduction()
glx
parents:
10361
diff
changeset
|
69 |
|
fd5945ab9ea6
(svn r13391) [NoAI] -Add: added AITown.GetNumHouses(), AITown.GetLastMonthProduction(), AITown.GetLastMonthTransported() and AITown.GetMaxProduction()
glx
parents:
10361
diff
changeset
|
70 |
const Town *t = ::GetTown(town_id); |
fd5945ab9ea6
(svn r13391) [NoAI] -Add: added AITown.GetNumHouses(), AITown.GetLastMonthProduction(), AITown.GetLastMonthTransported() and AITown.GetMaxProduction()
glx
parents:
10361
diff
changeset
|
71 |
|
fd5945ab9ea6
(svn r13391) [NoAI] -Add: added AITown.GetNumHouses(), AITown.GetLastMonthProduction(), AITown.GetLastMonthTransported() and AITown.GetMaxProduction()
glx
parents:
10361
diff
changeset
|
72 |
switch(AICargo::GetTownEffect(cargo_id)) { |
fd5945ab9ea6
(svn r13391) [NoAI] -Add: added AITown.GetNumHouses(), AITown.GetLastMonthProduction(), AITown.GetLastMonthTransported() and AITown.GetMaxProduction()
glx
parents:
10361
diff
changeset
|
73 |
case AICargo::TE_PASSENGERS: return t->act_pass; |
fd5945ab9ea6
(svn r13391) [NoAI] -Add: added AITown.GetNumHouses(), AITown.GetLastMonthProduction(), AITown.GetLastMonthTransported() and AITown.GetMaxProduction()
glx
parents:
10361
diff
changeset
|
74 |
case AICargo::TE_MAIL: return t->act_mail; |
fd5945ab9ea6
(svn r13391) [NoAI] -Add: added AITown.GetNumHouses(), AITown.GetLastMonthProduction(), AITown.GetLastMonthTransported() and AITown.GetMaxProduction()
glx
parents:
10361
diff
changeset
|
75 |
default: return -1; |
fd5945ab9ea6
(svn r13391) [NoAI] -Add: added AITown.GetNumHouses(), AITown.GetLastMonthProduction(), AITown.GetLastMonthTransported() and AITown.GetMaxProduction()
glx
parents:
10361
diff
changeset
|
76 |
} |
fd5945ab9ea6
(svn r13391) [NoAI] -Add: added AITown.GetNumHouses(), AITown.GetLastMonthProduction(), AITown.GetLastMonthTransported() and AITown.GetMaxProduction()
glx
parents:
10361
diff
changeset
|
77 |
} |
fd5945ab9ea6
(svn r13391) [NoAI] -Add: added AITown.GetNumHouses(), AITown.GetLastMonthProduction(), AITown.GetLastMonthTransported() and AITown.GetMaxProduction()
glx
parents:
10361
diff
changeset
|
78 |
|
fd5945ab9ea6
(svn r13391) [NoAI] -Add: added AITown.GetNumHouses(), AITown.GetLastMonthProduction(), AITown.GetLastMonthTransported() and AITown.GetMaxProduction()
glx
parents:
10361
diff
changeset
|
79 |
/* static */ int32 AITown::GetLastMonthTransported(TownID town_id, CargoID cargo_id) |
fd5945ab9ea6
(svn r13391) [NoAI] -Add: added AITown.GetNumHouses(), AITown.GetLastMonthProduction(), AITown.GetLastMonthTransported() and AITown.GetMaxProduction()
glx
parents:
10361
diff
changeset
|
80 |
{ |
fd5945ab9ea6
(svn r13391) [NoAI] -Add: added AITown.GetNumHouses(), AITown.GetLastMonthProduction(), AITown.GetLastMonthTransported() and AITown.GetMaxProduction()
glx
parents:
10361
diff
changeset
|
81 |
if (!IsValidTown(town_id)) return -1; |
fd5945ab9ea6
(svn r13391) [NoAI] -Add: added AITown.GetNumHouses(), AITown.GetLastMonthProduction(), AITown.GetLastMonthTransported() and AITown.GetMaxProduction()
glx
parents:
10361
diff
changeset
|
82 |
if (!AICargo::IsValidCargo(cargo_id)) return -1; |
fd5945ab9ea6
(svn r13391) [NoAI] -Add: added AITown.GetNumHouses(), AITown.GetLastMonthProduction(), AITown.GetLastMonthTransported() and AITown.GetMaxProduction()
glx
parents:
10361
diff
changeset
|
83 |
|
fd5945ab9ea6
(svn r13391) [NoAI] -Add: added AITown.GetNumHouses(), AITown.GetLastMonthProduction(), AITown.GetLastMonthTransported() and AITown.GetMaxProduction()
glx
parents:
10361
diff
changeset
|
84 |
const Town *t = ::GetTown(town_id); |
fd5945ab9ea6
(svn r13391) [NoAI] -Add: added AITown.GetNumHouses(), AITown.GetLastMonthProduction(), AITown.GetLastMonthTransported() and AITown.GetMaxProduction()
glx
parents:
10361
diff
changeset
|
85 |
|
fd5945ab9ea6
(svn r13391) [NoAI] -Add: added AITown.GetNumHouses(), AITown.GetLastMonthProduction(), AITown.GetLastMonthTransported() and AITown.GetMaxProduction()
glx
parents:
10361
diff
changeset
|
86 |
switch(AICargo::GetTownEffect(cargo_id)) { |
fd5945ab9ea6
(svn r13391) [NoAI] -Add: added AITown.GetNumHouses(), AITown.GetLastMonthProduction(), AITown.GetLastMonthTransported() and AITown.GetMaxProduction()
glx
parents:
10361
diff
changeset
|
87 |
case AICargo::TE_PASSENGERS: return t->pct_pass_transported; |
fd5945ab9ea6
(svn r13391) [NoAI] -Add: added AITown.GetNumHouses(), AITown.GetLastMonthProduction(), AITown.GetLastMonthTransported() and AITown.GetMaxProduction()
glx
parents:
10361
diff
changeset
|
88 |
case AICargo::TE_MAIL: return t->pct_mail_transported; |
fd5945ab9ea6
(svn r13391) [NoAI] -Add: added AITown.GetNumHouses(), AITown.GetLastMonthProduction(), AITown.GetLastMonthTransported() and AITown.GetMaxProduction()
glx
parents:
10361
diff
changeset
|
89 |
default: return -1; |
fd5945ab9ea6
(svn r13391) [NoAI] -Add: added AITown.GetNumHouses(), AITown.GetLastMonthProduction(), AITown.GetLastMonthTransported() and AITown.GetMaxProduction()
glx
parents:
10361
diff
changeset
|
90 |
} |
fd5945ab9ea6
(svn r13391) [NoAI] -Add: added AITown.GetNumHouses(), AITown.GetLastMonthProduction(), AITown.GetLastMonthTransported() and AITown.GetMaxProduction()
glx
parents:
10361
diff
changeset
|
91 |
} |
fd5945ab9ea6
(svn r13391) [NoAI] -Add: added AITown.GetNumHouses(), AITown.GetLastMonthProduction(), AITown.GetLastMonthTransported() and AITown.GetMaxProduction()
glx
parents:
10361
diff
changeset
|
92 |
|
fd5945ab9ea6
(svn r13391) [NoAI] -Add: added AITown.GetNumHouses(), AITown.GetLastMonthProduction(), AITown.GetLastMonthTransported() and AITown.GetMaxProduction()
glx
parents:
10361
diff
changeset
|
93 |
/* static */ int32 AITown::GetMaxProduction(TownID town_id, CargoID cargo_id) |
fd5945ab9ea6
(svn r13391) [NoAI] -Add: added AITown.GetNumHouses(), AITown.GetLastMonthProduction(), AITown.GetLastMonthTransported() and AITown.GetMaxProduction()
glx
parents:
10361
diff
changeset
|
94 |
{ |
fd5945ab9ea6
(svn r13391) [NoAI] -Add: added AITown.GetNumHouses(), AITown.GetLastMonthProduction(), AITown.GetLastMonthTransported() and AITown.GetMaxProduction()
glx
parents:
10361
diff
changeset
|
95 |
if (!IsValidTown(town_id)) return -1; |
fd5945ab9ea6
(svn r13391) [NoAI] -Add: added AITown.GetNumHouses(), AITown.GetLastMonthProduction(), AITown.GetLastMonthTransported() and AITown.GetMaxProduction()
glx
parents:
10361
diff
changeset
|
96 |
if (!AICargo::IsValidCargo(cargo_id)) return -1; |
fd5945ab9ea6
(svn r13391) [NoAI] -Add: added AITown.GetNumHouses(), AITown.GetLastMonthProduction(), AITown.GetLastMonthTransported() and AITown.GetMaxProduction()
glx
parents:
10361
diff
changeset
|
97 |
|
fd5945ab9ea6
(svn r13391) [NoAI] -Add: added AITown.GetNumHouses(), AITown.GetLastMonthProduction(), AITown.GetLastMonthTransported() and AITown.GetMaxProduction()
glx
parents:
10361
diff
changeset
|
98 |
const Town *t = ::GetTown(town_id); |
fd5945ab9ea6
(svn r13391) [NoAI] -Add: added AITown.GetNumHouses(), AITown.GetLastMonthProduction(), AITown.GetLastMonthTransported() and AITown.GetMaxProduction()
glx
parents:
10361
diff
changeset
|
99 |
|
fd5945ab9ea6
(svn r13391) [NoAI] -Add: added AITown.GetNumHouses(), AITown.GetLastMonthProduction(), AITown.GetLastMonthTransported() and AITown.GetMaxProduction()
glx
parents:
10361
diff
changeset
|
100 |
switch(AICargo::GetTownEffect(cargo_id)) { |
fd5945ab9ea6
(svn r13391) [NoAI] -Add: added AITown.GetNumHouses(), AITown.GetLastMonthProduction(), AITown.GetLastMonthTransported() and AITown.GetMaxProduction()
glx
parents:
10361
diff
changeset
|
101 |
case AICargo::TE_PASSENGERS: return t->max_pass; |
fd5945ab9ea6
(svn r13391) [NoAI] -Add: added AITown.GetNumHouses(), AITown.GetLastMonthProduction(), AITown.GetLastMonthTransported() and AITown.GetMaxProduction()
glx
parents:
10361
diff
changeset
|
102 |
case AICargo::TE_MAIL: return t->max_mail; |
fd5945ab9ea6
(svn r13391) [NoAI] -Add: added AITown.GetNumHouses(), AITown.GetLastMonthProduction(), AITown.GetLastMonthTransported() and AITown.GetMaxProduction()
glx
parents:
10361
diff
changeset
|
103 |
default: return -1; |
fd5945ab9ea6
(svn r13391) [NoAI] -Add: added AITown.GetNumHouses(), AITown.GetLastMonthProduction(), AITown.GetLastMonthTransported() and AITown.GetMaxProduction()
glx
parents:
10361
diff
changeset
|
104 |
} |
fd5945ab9ea6
(svn r13391) [NoAI] -Add: added AITown.GetNumHouses(), AITown.GetLastMonthProduction(), AITown.GetLastMonthTransported() and AITown.GetMaxProduction()
glx
parents:
10361
diff
changeset
|
105 |
} |
fd5945ab9ea6
(svn r13391) [NoAI] -Add: added AITown.GetNumHouses(), AITown.GetLastMonthProduction(), AITown.GetLastMonthTransported() and AITown.GetMaxProduction()
glx
parents:
10361
diff
changeset
|
106 |
|
9814
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9737
diff
changeset
|
107 |
/* static */ int32 AITown::GetDistanceManhattanToTile(TownID town_id, TileIndex tile) |
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9737
diff
changeset
|
108 |
{ |
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9737
diff
changeset
|
109 |
return AIMap::DistanceManhattan(tile, GetLocation(town_id)); |
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9737
diff
changeset
|
110 |
} |
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9737
diff
changeset
|
111 |
|
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9737
diff
changeset
|
112 |
/* static */ int32 AITown::GetDistanceSquareToTile(TownID town_id, TileIndex tile) |
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9737
diff
changeset
|
113 |
{ |
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9737
diff
changeset
|
114 |
return AIMap::DistanceSquare(tile, GetLocation(town_id)); |
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9737
diff
changeset
|
115 |
} |
10360
3234cb59de55
(svn r12901) [NoAI] -Add: added AITown.IsWithinTownRadius, AIStation.IsWithinTownRadius and AITile.GetOwner (Yexo)
truebrain
parents:
10339
diff
changeset
|
116 |
|
10361
4cdffd48480f
(svn r12902) [NoAI] -Fix r12901 [API CHANGE]: renamed IsWithinTownRadius to IsWithinTownInfluence, as that reflects the meaning much better
truebrain
parents:
10360
diff
changeset
|
117 |
/* static */ bool AITown::IsWithinTownInfluence(TownID town_id, TileIndex tile) |
10360
3234cb59de55
(svn r12901) [NoAI] -Add: added AITown.IsWithinTownRadius, AIStation.IsWithinTownRadius and AITile.GetOwner (Yexo)
truebrain
parents:
10339
diff
changeset
|
118 |
{ |
10859
4c14a8041c0a
(svn r13410) [NoAI] -Add: functions to perform town actions (advertising, bribing, building statues, etc).
rubidium
parents:
10844
diff
changeset
|
119 |
if (!IsValidTown(town_id)) return false; |
4c14a8041c0a
(svn r13410) [NoAI] -Add: functions to perform town actions (advertising, bribing, building statues, etc).
rubidium
parents:
10844
diff
changeset
|
120 |
|
10360
3234cb59de55
(svn r12901) [NoAI] -Add: added AITown.IsWithinTownRadius, AIStation.IsWithinTownRadius and AITile.GetOwner (Yexo)
truebrain
parents:
10339
diff
changeset
|
121 |
const Town *t = ::GetTown(town_id); |
3234cb59de55
(svn r12901) [NoAI] -Add: added AITown.IsWithinTownRadius, AIStation.IsWithinTownRadius and AITile.GetOwner (Yexo)
truebrain
parents:
10339
diff
changeset
|
122 |
return ((uint32)GetDistanceSquareToTile(town_id, tile) <= t->squared_town_zone_radius[0]); |
3234cb59de55
(svn r12901) [NoAI] -Add: added AITown.IsWithinTownRadius, AIStation.IsWithinTownRadius and AITile.GetOwner (Yexo)
truebrain
parents:
10339
diff
changeset
|
123 |
} |
10859
4c14a8041c0a
(svn r13410) [NoAI] -Add: functions to perform town actions (advertising, bribing, building statues, etc).
rubidium
parents:
10844
diff
changeset
|
124 |
|
4c14a8041c0a
(svn r13410) [NoAI] -Add: functions to perform town actions (advertising, bribing, building statues, etc).
rubidium
parents:
10844
diff
changeset
|
125 |
/* static */ bool AITown::HasStatue(TownID town_id) |
4c14a8041c0a
(svn r13410) [NoAI] -Add: functions to perform town actions (advertising, bribing, building statues, etc).
rubidium
parents:
10844
diff
changeset
|
126 |
{ |
4c14a8041c0a
(svn r13410) [NoAI] -Add: functions to perform town actions (advertising, bribing, building statues, etc).
rubidium
parents:
10844
diff
changeset
|
127 |
if (!IsValidTown(town_id)) return false; |
4c14a8041c0a
(svn r13410) [NoAI] -Add: functions to perform town actions (advertising, bribing, building statues, etc).
rubidium
parents:
10844
diff
changeset
|
128 |
|
4c14a8041c0a
(svn r13410) [NoAI] -Add: functions to perform town actions (advertising, bribing, building statues, etc).
rubidium
parents:
10844
diff
changeset
|
129 |
return ::HasBit(::GetTown(town_id)->statues, _current_player); |
4c14a8041c0a
(svn r13410) [NoAI] -Add: functions to perform town actions (advertising, bribing, building statues, etc).
rubidium
parents:
10844
diff
changeset
|
130 |
} |
4c14a8041c0a
(svn r13410) [NoAI] -Add: functions to perform town actions (advertising, bribing, building statues, etc).
rubidium
parents:
10844
diff
changeset
|
131 |
|
4c14a8041c0a
(svn r13410) [NoAI] -Add: functions to perform town actions (advertising, bribing, building statues, etc).
rubidium
parents:
10844
diff
changeset
|
132 |
/* static */ int AITown::GetRoadReworkDuration(TownID town_id) |
4c14a8041c0a
(svn r13410) [NoAI] -Add: functions to perform town actions (advertising, bribing, building statues, etc).
rubidium
parents:
10844
diff
changeset
|
133 |
{ |
4c14a8041c0a
(svn r13410) [NoAI] -Add: functions to perform town actions (advertising, bribing, building statues, etc).
rubidium
parents:
10844
diff
changeset
|
134 |
if (!IsValidTown(town_id)) return -1; |
4c14a8041c0a
(svn r13410) [NoAI] -Add: functions to perform town actions (advertising, bribing, building statues, etc).
rubidium
parents:
10844
diff
changeset
|
135 |
|
4c14a8041c0a
(svn r13410) [NoAI] -Add: functions to perform town actions (advertising, bribing, building statues, etc).
rubidium
parents:
10844
diff
changeset
|
136 |
return ::GetTown(town_id)->road_build_months; |
4c14a8041c0a
(svn r13410) [NoAI] -Add: functions to perform town actions (advertising, bribing, building statues, etc).
rubidium
parents:
10844
diff
changeset
|
137 |
} |
4c14a8041c0a
(svn r13410) [NoAI] -Add: functions to perform town actions (advertising, bribing, building statues, etc).
rubidium
parents:
10844
diff
changeset
|
138 |
|
4c14a8041c0a
(svn r13410) [NoAI] -Add: functions to perform town actions (advertising, bribing, building statues, etc).
rubidium
parents:
10844
diff
changeset
|
139 |
/* static */ AICompany::CompanyID AITown::GetExclusiveRightsPlayer(TownID town_id) |
4c14a8041c0a
(svn r13410) [NoAI] -Add: functions to perform town actions (advertising, bribing, building statues, etc).
rubidium
parents:
10844
diff
changeset
|
140 |
{ |
4c14a8041c0a
(svn r13410) [NoAI] -Add: functions to perform town actions (advertising, bribing, building statues, etc).
rubidium
parents:
10844
diff
changeset
|
141 |
if (!IsValidTown(town_id)) return AICompany::INVALID_COMPANY; |
4c14a8041c0a
(svn r13410) [NoAI] -Add: functions to perform town actions (advertising, bribing, building statues, etc).
rubidium
parents:
10844
diff
changeset
|
142 |
|
4c14a8041c0a
(svn r13410) [NoAI] -Add: functions to perform town actions (advertising, bribing, building statues, etc).
rubidium
parents:
10844
diff
changeset
|
143 |
return (AICompany::CompanyID)(int8)::GetTown(town_id)->exclusivity; |
4c14a8041c0a
(svn r13410) [NoAI] -Add: functions to perform town actions (advertising, bribing, building statues, etc).
rubidium
parents:
10844
diff
changeset
|
144 |
} |
4c14a8041c0a
(svn r13410) [NoAI] -Add: functions to perform town actions (advertising, bribing, building statues, etc).
rubidium
parents:
10844
diff
changeset
|
145 |
|
4c14a8041c0a
(svn r13410) [NoAI] -Add: functions to perform town actions (advertising, bribing, building statues, etc).
rubidium
parents:
10844
diff
changeset
|
146 |
/* static */ int32 AITown::GetExclusiveRightsDuration(TownID town_id) |
4c14a8041c0a
(svn r13410) [NoAI] -Add: functions to perform town actions (advertising, bribing, building statues, etc).
rubidium
parents:
10844
diff
changeset
|
147 |
{ |
4c14a8041c0a
(svn r13410) [NoAI] -Add: functions to perform town actions (advertising, bribing, building statues, etc).
rubidium
parents:
10844
diff
changeset
|
148 |
if (!IsValidTown(town_id)) return -1; |
4c14a8041c0a
(svn r13410) [NoAI] -Add: functions to perform town actions (advertising, bribing, building statues, etc).
rubidium
parents:
10844
diff
changeset
|
149 |
|
4c14a8041c0a
(svn r13410) [NoAI] -Add: functions to perform town actions (advertising, bribing, building statues, etc).
rubidium
parents:
10844
diff
changeset
|
150 |
return ::GetTown(town_id)->exclusive_counter; |
4c14a8041c0a
(svn r13410) [NoAI] -Add: functions to perform town actions (advertising, bribing, building statues, etc).
rubidium
parents:
10844
diff
changeset
|
151 |
} |
4c14a8041c0a
(svn r13410) [NoAI] -Add: functions to perform town actions (advertising, bribing, building statues, etc).
rubidium
parents:
10844
diff
changeset
|
152 |
|
4c14a8041c0a
(svn r13410) [NoAI] -Add: functions to perform town actions (advertising, bribing, building statues, etc).
rubidium
parents:
10844
diff
changeset
|
153 |
extern uint GetMaskOfTownActions(int *nump, PlayerID pid, const Town *t); |
4c14a8041c0a
(svn r13410) [NoAI] -Add: functions to perform town actions (advertising, bribing, building statues, etc).
rubidium
parents:
10844
diff
changeset
|
154 |
|
10865
c4b3ddd2e9da
(svn r13416) [NoAI] -Fix: make doxygen happy again
truebrain
parents:
10859
diff
changeset
|
155 |
/* static */ bool AITown::IsActionAvailable(TownID town_id, TownAction town_action) |
10859
4c14a8041c0a
(svn r13410) [NoAI] -Add: functions to perform town actions (advertising, bribing, building statues, etc).
rubidium
parents:
10844
diff
changeset
|
156 |
{ |
4c14a8041c0a
(svn r13410) [NoAI] -Add: functions to perform town actions (advertising, bribing, building statues, etc).
rubidium
parents:
10844
diff
changeset
|
157 |
if (!IsValidTown(town_id)) return false; |
4c14a8041c0a
(svn r13410) [NoAI] -Add: functions to perform town actions (advertising, bribing, building statues, etc).
rubidium
parents:
10844
diff
changeset
|
158 |
|
10865
c4b3ddd2e9da
(svn r13416) [NoAI] -Fix: make doxygen happy again
truebrain
parents:
10859
diff
changeset
|
159 |
return HasBit(::GetMaskOfTownActions(NULL, _current_player, ::GetTown(town_id)), town_action); |
10859
4c14a8041c0a
(svn r13410) [NoAI] -Add: functions to perform town actions (advertising, bribing, building statues, etc).
rubidium
parents:
10844
diff
changeset
|
160 |
} |
4c14a8041c0a
(svn r13410) [NoAI] -Add: functions to perform town actions (advertising, bribing, building statues, etc).
rubidium
parents:
10844
diff
changeset
|
161 |
|
10865
c4b3ddd2e9da
(svn r13416) [NoAI] -Fix: make doxygen happy again
truebrain
parents:
10859
diff
changeset
|
162 |
/* static */ bool AITown::PerformTownAction(TownID town_id, TownAction town_action) |
10859
4c14a8041c0a
(svn r13410) [NoAI] -Add: functions to perform town actions (advertising, bribing, building statues, etc).
rubidium
parents:
10844
diff
changeset
|
163 |
{ |
4c14a8041c0a
(svn r13410) [NoAI] -Add: functions to perform town actions (advertising, bribing, building statues, etc).
rubidium
parents:
10844
diff
changeset
|
164 |
EnforcePrecondition(false, IsValidTown(town_id)); |
10865
c4b3ddd2e9da
(svn r13416) [NoAI] -Fix: make doxygen happy again
truebrain
parents:
10859
diff
changeset
|
165 |
EnforcePrecondition(false, IsActionAvailable(town_id, town_action)); |
10859
4c14a8041c0a
(svn r13410) [NoAI] -Add: functions to perform town actions (advertising, bribing, building statues, etc).
rubidium
parents:
10844
diff
changeset
|
166 |
|
10865
c4b3ddd2e9da
(svn r13416) [NoAI] -Fix: make doxygen happy again
truebrain
parents:
10859
diff
changeset
|
167 |
return AIObject::DoCommand(::GetTown(town_id)->xy, town_id, town_action, CMD_DO_TOWN_ACTION); |
10859
4c14a8041c0a
(svn r13410) [NoAI] -Add: functions to perform town actions (advertising, bribing, building statues, etc).
rubidium
parents:
10844
diff
changeset
|
168 |
} |
10869
4fdb11e1b599
(svn r13420) [NoAI] -Add: function to get the town rating.
rubidium
parents:
10865
diff
changeset
|
169 |
|
4fdb11e1b599
(svn r13420) [NoAI] -Add: function to get the town rating.
rubidium
parents:
10865
diff
changeset
|
170 |
/* static */ AITown::TownRating AITown::GetRating(TownID town_id, AICompany::CompanyID company_id) |
4fdb11e1b599
(svn r13420) [NoAI] -Add: function to get the town rating.
rubidium
parents:
10865
diff
changeset
|
171 |
{ |
4fdb11e1b599
(svn r13420) [NoAI] -Add: function to get the town rating.
rubidium
parents:
10865
diff
changeset
|
172 |
if (!IsValidTown(town_id)) return INVALID_TOWN_RATING; |
4fdb11e1b599
(svn r13420) [NoAI] -Add: function to get the town rating.
rubidium
parents:
10865
diff
changeset
|
173 |
AICompany::CompanyID company = AICompany::ResolveCompanyID(company_id); |
4fdb11e1b599
(svn r13420) [NoAI] -Add: function to get the town rating.
rubidium
parents:
10865
diff
changeset
|
174 |
if (company == AICompany::INVALID_COMPANY) return INVALID_TOWN_RATING; |
4fdb11e1b599
(svn r13420) [NoAI] -Add: function to get the town rating.
rubidium
parents:
10865
diff
changeset
|
175 |
|
4fdb11e1b599
(svn r13420) [NoAI] -Add: function to get the town rating.
rubidium
parents:
10865
diff
changeset
|
176 |
const Town *t = ::GetTown(town_id); |
4fdb11e1b599
(svn r13420) [NoAI] -Add: function to get the town rating.
rubidium
parents:
10865
diff
changeset
|
177 |
if (!HasBit(t->have_ratings, company)) return TOWN_RATING_NONE; |
4fdb11e1b599
(svn r13420) [NoAI] -Add: function to get the town rating.
rubidium
parents:
10865
diff
changeset
|
178 |
return max(TOWN_RATING_APPALLING, (TownRating)((t->ratings[company] / 200) + 3)); |
4fdb11e1b599
(svn r13420) [NoAI] -Add: function to get the town rating.
rubidium
parents:
10865
diff
changeset
|
179 |
} |