14 #include "../../variables.h" |
14 #include "../../variables.h" |
15 #include "../../core/alloc_func.hpp" |
15 #include "../../core/alloc_func.hpp" |
16 #include "../../string_func.h" |
16 #include "../../string_func.h" |
17 #include "table/strings.h" |
17 #include "table/strings.h" |
18 |
18 |
19 /* static */ AICompany::CompanyIndex AICompany::ResolveCompanyIndex(AICompany::CompanyIndex company) |
19 /* static */ AICompany::CompanyID AICompany::ResolveCompanyID(AICompany::CompanyID company) |
20 { |
20 { |
21 if (company == MY_COMPANY) return (CompanyIndex)((byte)_current_player); |
21 if (company == MY_COMPANY) return (CompanyID)((byte)_current_player); |
22 |
22 |
23 return (::IsValidPlayer((PlayerID)company) && ::GetPlayer((PlayerID)company)->is_active) ? company : INVALID_COMPANY; |
23 return (::IsValidPlayer((PlayerID)company) && ::GetPlayer((PlayerID)company)->is_active) ? company : INVALID_COMPANY; |
24 } |
24 } |
25 |
25 |
26 /* static */ bool AICompany::SetCompanyName(const char *name) |
26 /* static */ bool AICompany::SetCompanyName(const char *name) |
29 |
29 |
30 _cmd_text = name; |
30 _cmd_text = name; |
31 return AIObject::DoCommand(0, 0, 0, CMD_CHANGE_COMPANY_NAME); |
31 return AIObject::DoCommand(0, 0, 0, CMD_CHANGE_COMPANY_NAME); |
32 } |
32 } |
33 |
33 |
34 /* static */ char *AICompany::GetCompanyName(AICompany::CompanyIndex company) |
34 /* static */ char *AICompany::GetCompanyName(AICompany::CompanyID company) |
35 { |
35 { |
36 company = ResolveCompanyIndex(company); |
36 company = ResolveCompanyID(company); |
37 if (company == INVALID_COMPANY) return NULL; |
37 if (company == INVALID_COMPANY) return NULL; |
38 |
38 |
39 static const int len = 64; |
39 static const int len = 64; |
40 char *company_name = MallocT<char>(len); |
40 char *company_name = MallocT<char>(len); |
41 |
41 |
50 |
50 |
51 _cmd_text = name; |
51 _cmd_text = name; |
52 return AIObject::DoCommand(0, 0, 0, CMD_CHANGE_PRESIDENT_NAME); |
52 return AIObject::DoCommand(0, 0, 0, CMD_CHANGE_PRESIDENT_NAME); |
53 } |
53 } |
54 |
54 |
55 /* static */ char *AICompany::GetPresidentName(AICompany::CompanyIndex company) |
55 /* static */ char *AICompany::GetPresidentName(AICompany::CompanyID company) |
56 { |
56 { |
57 company = ResolveCompanyIndex(company); |
57 company = ResolveCompanyID(company); |
58 |
58 |
59 static const int len = 64; |
59 static const int len = 64; |
60 char *president_name = MallocT<char>(len); |
60 char *president_name = MallocT<char>(len); |
61 if (company != INVALID_COMPANY) { |
61 if (company != INVALID_COMPANY) { |
62 ::SetDParam(0, GetPlayer((PlayerID)company)->index); |
62 ::SetDParam(0, GetPlayer((PlayerID)company)->index); |
66 } |
66 } |
67 |
67 |
68 return president_name; |
68 return president_name; |
69 } |
69 } |
70 |
70 |
71 /* static */ Money AICompany::GetCompanyValue(AICompany::CompanyIndex company) |
71 /* static */ Money AICompany::GetCompanyValue(AICompany::CompanyID company) |
72 { |
72 { |
73 company = ResolveCompanyIndex(company); |
73 company = ResolveCompanyID(company); |
74 if (company == INVALID_COMPANY) return -1; |
74 if (company == INVALID_COMPANY) return -1; |
75 |
75 |
76 return ::GetPlayer((PlayerID)company)->cur_economy.company_value; |
76 return ::GetPlayer((PlayerID)company)->cur_economy.company_value; |
77 } |
77 } |
78 |
78 |
79 /* static */ Money AICompany::GetBankBalance(AICompany::CompanyIndex company) |
79 /* static */ Money AICompany::GetBankBalance(AICompany::CompanyID company) |
80 { |
80 { |
81 company = ResolveCompanyIndex(company); |
81 company = ResolveCompanyID(company); |
82 if (company == INVALID_COMPANY) return -1; |
82 if (company == INVALID_COMPANY) return -1; |
83 |
83 |
84 return ::GetPlayer((PlayerID)company)->player_money; |
84 return ::GetPlayer((PlayerID)company)->player_money; |
85 } |
85 } |
86 |
86 |
132 EnforcePrecondition(false, ::IsValidTile(tile)); |
132 EnforcePrecondition(false, ::IsValidTile(tile)); |
133 |
133 |
134 return AIObject::DoCommand(tile, 0, 0, CMD_BUILD_COMPANY_HQ); |
134 return AIObject::DoCommand(tile, 0, 0, CMD_BUILD_COMPANY_HQ); |
135 } |
135 } |
136 |
136 |
137 /* static */ TileIndex AICompany::GetCompanyHQ(CompanyIndex company) |
137 /* static */ TileIndex AICompany::GetCompanyHQ(CompanyID company) |
138 { |
138 { |
139 company = ResolveCompanyIndex(company); |
139 company = ResolveCompanyID(company); |
140 if (company == INVALID_COMPANY) return INVALID_TILE; |
140 if (company == INVALID_COMPANY) return INVALID_TILE; |
141 |
141 |
142 TileIndex loc = ::GetPlayer((PlayerID)company)->location_of_house; |
142 TileIndex loc = ::GetPlayer((PlayerID)company)->location_of_house; |
143 return (loc == 0) ? INVALID_TILE : loc; |
143 return (loc == 0) ? INVALID_TILE : loc; |
144 } |
144 } |
146 /* static */ bool AICompany::SetAutoRenewStatus(bool autorenew) |
146 /* static */ bool AICompany::SetAutoRenewStatus(bool autorenew) |
147 { |
147 { |
148 return AIObject::DoCommand(0, 0, autorenew ? 1 : 0, CMD_SET_AUTOREPLACE); |
148 return AIObject::DoCommand(0, 0, autorenew ? 1 : 0, CMD_SET_AUTOREPLACE); |
149 } |
149 } |
150 |
150 |
151 /* static */ bool AICompany::GetAutoRenewStatus(CompanyIndex company) |
151 /* static */ bool AICompany::GetAutoRenewStatus(CompanyID company) |
152 { |
152 { |
153 company = ResolveCompanyIndex(company); |
153 company = ResolveCompanyID(company); |
154 if (company == INVALID_COMPANY) return false; |
154 if (company == INVALID_COMPANY) return false; |
155 |
155 |
156 return ::GetPlayer((PlayerID)company)->engine_renew; |
156 return ::GetPlayer((PlayerID)company)->engine_renew; |
157 } |
157 } |
158 |
158 |
159 /* static */ bool AICompany::SetAutoRenewMonths(int16 months) |
159 /* static */ bool AICompany::SetAutoRenewMonths(int16 months) |
160 { |
160 { |
161 return AIObject::DoCommand(0, 1, months, CMD_SET_AUTOREPLACE); |
161 return AIObject::DoCommand(0, 1, months, CMD_SET_AUTOREPLACE); |
162 } |
162 } |
163 |
163 |
164 /* static */ int16 AICompany::GetAutoRenewMonths(CompanyIndex company) |
164 /* static */ int16 AICompany::GetAutoRenewMonths(CompanyID company) |
165 { |
165 { |
166 company = ResolveCompanyIndex(company); |
166 company = ResolveCompanyID(company); |
167 if (company == INVALID_COMPANY) return 0; |
167 if (company == INVALID_COMPANY) return 0; |
168 |
168 |
169 return ::GetPlayer((PlayerID)company)->engine_renew_months; |
169 return ::GetPlayer((PlayerID)company)->engine_renew_months; |
170 } |
170 } |
171 |
171 |
172 /* static */ bool AICompany::SetAutoRenewMoney(uint32 money) |
172 /* static */ bool AICompany::SetAutoRenewMoney(uint32 money) |
173 { |
173 { |
174 return AIObject::DoCommand(0, 2, money, CMD_SET_AUTOREPLACE); |
174 return AIObject::DoCommand(0, 2, money, CMD_SET_AUTOREPLACE); |
175 } |
175 } |
176 |
176 |
177 /* static */ uint32 AICompany::GetAutoRenewMoney(CompanyIndex company) |
177 /* static */ uint32 AICompany::GetAutoRenewMoney(CompanyID company) |
178 { |
178 { |
179 company = ResolveCompanyIndex(company); |
179 company = ResolveCompanyID(company); |
180 if (company == INVALID_COMPANY) return 0; |
180 if (company == INVALID_COMPANY) return 0; |
181 |
181 |
182 return ::GetPlayer((PlayerID)company)->engine_renew_money; |
182 return ::GetPlayer((PlayerID)company)->engine_renew_money; |
183 } |
183 } |