author | glx |
Sun, 15 Jun 2008 22:56:43 +0000 | |
branch | noai |
changeset 10973 | 8577bc56132c |
parent 10856 | c7b29152d594 |
permissions | -rw-r--r-- |
9374
61379e9b2393
(svn r9161) [NoAI] -Add: functions to get/set company related information: loan, bank balance, company value and company name.
rubidium
parents:
diff
changeset
|
1 |
/* $Id$ */ |
61379e9b2393
(svn r9161) [NoAI] -Add: functions to get/set company related information: loan, bank balance, company value and company name.
rubidium
parents:
diff
changeset
|
2 |
|
9833
89a64246458f
(svn r12496) [NoAI] -Documentation: give the .cpp files a nice uniform format too
truebrain
parents:
9808
diff
changeset
|
3 |
/** @file ai_company.cpp Implementation of AICompany. */ |
9374
61379e9b2393
(svn r9161) [NoAI] -Add: functions to get/set company related information: loan, bank balance, company value and company name.
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_company.hpp" |
9865
f241472f09dc
(svn r12555) [NoAI] -Add: support for GetLastError for AICompany.
rubidium
parents:
9833
diff
changeset
|
6 |
#include "ai_error.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:
10291
diff
changeset
|
7 |
#include "../../openttd.h" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9701
diff
changeset
|
8 |
#include "../../command_func.h" |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
9 |
#include "../../player_func.h" |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
10 |
#include "../../player_base.h" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9701
diff
changeset
|
11 |
#include "../../economy_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9701
diff
changeset
|
12 |
#include "../../strings_func.h" |
9808
0b40f556e051
(svn r12318) [NoAI] -Add: added AICompany::(Build|Get)CompanyHQ (college of Morloth)
truebrain
parents:
9737
diff
changeset
|
13 |
#include "../../tile_map.h" |
9629 | 14 |
#include "../../variables.h" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9701
diff
changeset
|
15 |
#include "../../core/alloc_func.hpp" |
9865
f241472f09dc
(svn r12555) [NoAI] -Add: support for GetLastError for AICompany.
rubidium
parents:
9833
diff
changeset
|
16 |
#include "../../string_func.h" |
9629 | 17 |
#include "table/strings.h" |
9430
9e0a193b2bec
(svn r9234) [NoAI] -Codechange: move away from the 'much' subdirectory approach for the API implementation.
rubidium
parents:
9427
diff
changeset
|
18 |
|
10855
90904faa1890
(svn r13406) [NoAI] -Change [API CHANGE]: renamed CompanyIndex to CompanyID and AICompany::ResolveCompanyIndex() to AICompany::ResolveCompanyID(), to be more consistant with the rest of the API
truebrain
parents:
10339
diff
changeset
|
19 |
/* static */ AICompany::CompanyID AICompany::ResolveCompanyID(AICompany::CompanyID company) |
9668
6fe3d2cb9655
(svn r10582) [NoAI] -Codechange: allow getting the president and company names of other companies as well as their company value and bank balance.
rubidium
parents:
9629
diff
changeset
|
20 |
{ |
10855
90904faa1890
(svn r13406) [NoAI] -Change [API CHANGE]: renamed CompanyIndex to CompanyID and AICompany::ResolveCompanyIndex() to AICompany::ResolveCompanyID(), to be more consistant with the rest of the API
truebrain
parents:
10339
diff
changeset
|
21 |
if (company == MY_COMPANY) return (CompanyID)((byte)_current_player); |
9668
6fe3d2cb9655
(svn r10582) [NoAI] -Codechange: allow getting the president and company names of other companies as well as their company value and bank balance.
rubidium
parents:
9629
diff
changeset
|
22 |
|
9736
183b38e0a480
(svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents:
9724
diff
changeset
|
23 |
return (::IsValidPlayer((PlayerID)company) && ::GetPlayer((PlayerID)company)->is_active) ? company : INVALID_COMPANY; |
9668
6fe3d2cb9655
(svn r10582) [NoAI] -Codechange: allow getting the president and company names of other companies as well as their company value and bank balance.
rubidium
parents:
9629
diff
changeset
|
24 |
} |
6fe3d2cb9655
(svn r10582) [NoAI] -Codechange: allow getting the president and company names of other companies as well as their company value and bank balance.
rubidium
parents:
9629
diff
changeset
|
25 |
|
10856
c7b29152d594
(svn r13407) [NoAI] -Add: added AICompany::IsMine() to ease up owner-checks (no, not the ones to cash in money)
truebrain
parents:
10855
diff
changeset
|
26 |
/* static */ bool AICompany::IsMine(AICompany::CompanyID company) |
c7b29152d594
(svn r13407) [NoAI] -Add: added AICompany::IsMine() to ease up owner-checks (no, not the ones to cash in money)
truebrain
parents:
10855
diff
changeset
|
27 |
{ |
c7b29152d594
(svn r13407) [NoAI] -Add: added AICompany::IsMine() to ease up owner-checks (no, not the ones to cash in money)
truebrain
parents:
10855
diff
changeset
|
28 |
return ResolveCompanyID(company) == ResolveCompanyID(MY_COMPANY); |
c7b29152d594
(svn r13407) [NoAI] -Add: added AICompany::IsMine() to ease up owner-checks (no, not the ones to cash in money)
truebrain
parents:
10855
diff
changeset
|
29 |
} |
c7b29152d594
(svn r13407) [NoAI] -Add: added AICompany::IsMine() to ease up owner-checks (no, not the ones to cash in money)
truebrain
parents:
10855
diff
changeset
|
30 |
|
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
|
31 |
/* static */ bool AICompany::SetCompanyName(const char *name) |
9430
9e0a193b2bec
(svn r9234) [NoAI] -Codechange: move away from the 'much' subdirectory approach for the API implementation.
rubidium
parents:
9427
diff
changeset
|
32 |
{ |
9868
3998f2e73dda
(svn r12590) [NoAI] -Add: EnforcePrecondition macro to make code much better readable.
rubidium
parents:
9865
diff
changeset
|
33 |
EnforcePrecondition(false, !::StrEmpty(name)); |
9430
9e0a193b2bec
(svn r9234) [NoAI] -Codechange: move away from the 'much' subdirectory approach for the API implementation.
rubidium
parents:
9427
diff
changeset
|
34 |
|
9e0a193b2bec
(svn r9234) [NoAI] -Codechange: move away from the 'much' subdirectory approach for the API implementation.
rubidium
parents:
9427
diff
changeset
|
35 |
_cmd_text = name; |
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
|
36 |
return AIObject::DoCommand(0, 0, 0, CMD_CHANGE_COMPANY_NAME); |
9430
9e0a193b2bec
(svn r9234) [NoAI] -Codechange: move away from the 'much' subdirectory approach for the API implementation.
rubidium
parents:
9427
diff
changeset
|
37 |
} |
9e0a193b2bec
(svn r9234) [NoAI] -Codechange: move away from the 'much' subdirectory approach for the API implementation.
rubidium
parents:
9427
diff
changeset
|
38 |
|
10855
90904faa1890
(svn r13406) [NoAI] -Change [API CHANGE]: renamed CompanyIndex to CompanyID and AICompany::ResolveCompanyIndex() to AICompany::ResolveCompanyID(), to be more consistant with the rest of the API
truebrain
parents:
10339
diff
changeset
|
39 |
/* static */ char *AICompany::GetCompanyName(AICompany::CompanyID company) |
9430
9e0a193b2bec
(svn r9234) [NoAI] -Codechange: move away from the 'much' subdirectory approach for the API implementation.
rubidium
parents:
9427
diff
changeset
|
40 |
{ |
10855
90904faa1890
(svn r13406) [NoAI] -Change [API CHANGE]: renamed CompanyIndex to CompanyID and AICompany::ResolveCompanyIndex() to AICompany::ResolveCompanyID(), to be more consistant with the rest of the API
truebrain
parents:
10339
diff
changeset
|
41 |
company = ResolveCompanyID(company); |
9696
4384ed3de1f0
(svn r10937) [NoAI] -Add: added AIStation::GetName on request by Nickman
truelight
parents:
9668
diff
changeset
|
42 |
if (company == INVALID_COMPANY) return NULL; |
9668
6fe3d2cb9655
(svn r10582) [NoAI] -Codechange: allow getting the president and company names of other companies as well as their company value and bank balance.
rubidium
parents:
9629
diff
changeset
|
43 |
|
9430
9e0a193b2bec
(svn r9234) [NoAI] -Codechange: move away from the 'much' subdirectory approach for the API implementation.
rubidium
parents:
9427
diff
changeset
|
44 |
static const int len = 64; |
9e0a193b2bec
(svn r9234) [NoAI] -Codechange: move away from the 'much' subdirectory approach for the API implementation.
rubidium
parents:
9427
diff
changeset
|
45 |
char *company_name = MallocT<char>(len); |
9e0a193b2bec
(svn r9234) [NoAI] -Codechange: move away from the 'much' subdirectory approach for the API implementation.
rubidium
parents:
9427
diff
changeset
|
46 |
|
9736
183b38e0a480
(svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents:
9724
diff
changeset
|
47 |
::SetDParam(0, GetPlayer((PlayerID)company)->index); |
183b38e0a480
(svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents:
9724
diff
changeset
|
48 |
::GetString(company_name, STR_COMPANY_NAME, &company_name[len - 1]); |
9430
9e0a193b2bec
(svn r9234) [NoAI] -Codechange: move away from the 'much' subdirectory approach for the API implementation.
rubidium
parents:
9427
diff
changeset
|
49 |
return company_name; |
9e0a193b2bec
(svn r9234) [NoAI] -Codechange: move away from the 'much' subdirectory approach for the API implementation.
rubidium
parents:
9427
diff
changeset
|
50 |
} |
9374
61379e9b2393
(svn r9161) [NoAI] -Add: functions to get/set company related information: loan, bank balance, company value and company name.
rubidium
parents:
diff
changeset
|
51 |
|
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
|
52 |
/* static */ bool AICompany::SetPresidentName(const char *name) |
9575
a4b6bbfa6c96
(svn r9591) [NoAI] -Fix: SetCompanyName() in fact set the president name (Zuu)
truelight
parents:
9486
diff
changeset
|
53 |
{ |
9868
3998f2e73dda
(svn r12590) [NoAI] -Add: EnforcePrecondition macro to make code much better readable.
rubidium
parents:
9865
diff
changeset
|
54 |
EnforcePrecondition(false, !::StrEmpty(name)); |
9575
a4b6bbfa6c96
(svn r9591) [NoAI] -Fix: SetCompanyName() in fact set the president name (Zuu)
truelight
parents:
9486
diff
changeset
|
55 |
|
a4b6bbfa6c96
(svn r9591) [NoAI] -Fix: SetCompanyName() in fact set the president name (Zuu)
truelight
parents:
9486
diff
changeset
|
56 |
_cmd_text = name; |
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
|
57 |
return AIObject::DoCommand(0, 0, 0, CMD_CHANGE_PRESIDENT_NAME); |
9575
a4b6bbfa6c96
(svn r9591) [NoAI] -Fix: SetCompanyName() in fact set the president name (Zuu)
truelight
parents:
9486
diff
changeset
|
58 |
} |
a4b6bbfa6c96
(svn r9591) [NoAI] -Fix: SetCompanyName() in fact set the president name (Zuu)
truelight
parents:
9486
diff
changeset
|
59 |
|
10855
90904faa1890
(svn r13406) [NoAI] -Change [API CHANGE]: renamed CompanyIndex to CompanyID and AICompany::ResolveCompanyIndex() to AICompany::ResolveCompanyID(), to be more consistant with the rest of the API
truebrain
parents:
10339
diff
changeset
|
60 |
/* static */ char *AICompany::GetPresidentName(AICompany::CompanyID company) |
9575
a4b6bbfa6c96
(svn r9591) [NoAI] -Fix: SetCompanyName() in fact set the president name (Zuu)
truelight
parents:
9486
diff
changeset
|
61 |
{ |
10855
90904faa1890
(svn r13406) [NoAI] -Change [API CHANGE]: renamed CompanyIndex to CompanyID and AICompany::ResolveCompanyIndex() to AICompany::ResolveCompanyID(), to be more consistant with the rest of the API
truebrain
parents:
10339
diff
changeset
|
62 |
company = ResolveCompanyID(company); |
9668
6fe3d2cb9655
(svn r10582) [NoAI] -Codechange: allow getting the president and company names of other companies as well as their company value and bank balance.
rubidium
parents:
9629
diff
changeset
|
63 |
|
9575
a4b6bbfa6c96
(svn r9591) [NoAI] -Fix: SetCompanyName() in fact set the president name (Zuu)
truelight
parents:
9486
diff
changeset
|
64 |
static const int len = 64; |
a4b6bbfa6c96
(svn r9591) [NoAI] -Fix: SetCompanyName() in fact set the president name (Zuu)
truelight
parents:
9486
diff
changeset
|
65 |
char *president_name = MallocT<char>(len); |
9668
6fe3d2cb9655
(svn r10582) [NoAI] -Codechange: allow getting the president and company names of other companies as well as their company value and bank balance.
rubidium
parents:
9629
diff
changeset
|
66 |
if (company != INVALID_COMPANY) { |
9736
183b38e0a480
(svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents:
9724
diff
changeset
|
67 |
::SetDParam(0, GetPlayer((PlayerID)company)->index); |
183b38e0a480
(svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents:
9724
diff
changeset
|
68 |
::GetString(president_name, STR_PLAYER_NAME, &president_name[len - 1]); |
9668
6fe3d2cb9655
(svn r10582) [NoAI] -Codechange: allow getting the president and company names of other companies as well as their company value and bank balance.
rubidium
parents:
9629
diff
changeset
|
69 |
} else { |
6fe3d2cb9655
(svn r10582) [NoAI] -Codechange: allow getting the president and company names of other companies as well as their company value and bank balance.
rubidium
parents:
9629
diff
changeset
|
70 |
*president_name = '\0'; |
6fe3d2cb9655
(svn r10582) [NoAI] -Codechange: allow getting the president and company names of other companies as well as their company value and bank balance.
rubidium
parents:
9629
diff
changeset
|
71 |
} |
9575
a4b6bbfa6c96
(svn r9591) [NoAI] -Fix: SetCompanyName() in fact set the president name (Zuu)
truelight
parents:
9486
diff
changeset
|
72 |
|
a4b6bbfa6c96
(svn r9591) [NoAI] -Fix: SetCompanyName() in fact set the president name (Zuu)
truelight
parents:
9486
diff
changeset
|
73 |
return president_name; |
a4b6bbfa6c96
(svn r9591) [NoAI] -Fix: SetCompanyName() in fact set the president name (Zuu)
truelight
parents:
9486
diff
changeset
|
74 |
} |
a4b6bbfa6c96
(svn r9591) [NoAI] -Fix: SetCompanyName() in fact set the president name (Zuu)
truelight
parents:
9486
diff
changeset
|
75 |
|
10855
90904faa1890
(svn r13406) [NoAI] -Change [API CHANGE]: renamed CompanyIndex to CompanyID and AICompany::ResolveCompanyIndex() to AICompany::ResolveCompanyID(), to be more consistant with the rest of the API
truebrain
parents:
10339
diff
changeset
|
76 |
/* static */ Money AICompany::GetCompanyValue(AICompany::CompanyID company) |
9374
61379e9b2393
(svn r9161) [NoAI] -Add: functions to get/set company related information: loan, bank balance, company value and company name.
rubidium
parents:
diff
changeset
|
77 |
{ |
10855
90904faa1890
(svn r13406) [NoAI] -Change [API CHANGE]: renamed CompanyIndex to CompanyID and AICompany::ResolveCompanyIndex() to AICompany::ResolveCompanyID(), to be more consistant with the rest of the API
truebrain
parents:
10339
diff
changeset
|
78 |
company = ResolveCompanyID(company); |
10194
c9fdeb7450da
(svn r12727) [NoAI] -Fix (API CHANGE): return -1 to indicate invalidity, instead of 0 or -1, depending on the class
truebrain
parents:
9868
diff
changeset
|
79 |
if (company == INVALID_COMPANY) return -1; |
9668
6fe3d2cb9655
(svn r10582) [NoAI] -Codechange: allow getting the president and company names of other companies as well as their company value and bank balance.
rubidium
parents:
9629
diff
changeset
|
80 |
|
9736
183b38e0a480
(svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents:
9724
diff
changeset
|
81 |
return ::GetPlayer((PlayerID)company)->cur_economy.company_value; |
9374
61379e9b2393
(svn r9161) [NoAI] -Add: functions to get/set company related information: loan, bank balance, company value and company name.
rubidium
parents:
diff
changeset
|
82 |
} |
61379e9b2393
(svn r9161) [NoAI] -Add: functions to get/set company related information: loan, bank balance, company value and company name.
rubidium
parents:
diff
changeset
|
83 |
|
10855
90904faa1890
(svn r13406) [NoAI] -Change [API CHANGE]: renamed CompanyIndex to CompanyID and AICompany::ResolveCompanyIndex() to AICompany::ResolveCompanyID(), to be more consistant with the rest of the API
truebrain
parents:
10339
diff
changeset
|
84 |
/* static */ Money AICompany::GetBankBalance(AICompany::CompanyID company) |
9374
61379e9b2393
(svn r9161) [NoAI] -Add: functions to get/set company related information: loan, bank balance, company value and company name.
rubidium
parents:
diff
changeset
|
85 |
{ |
10855
90904faa1890
(svn r13406) [NoAI] -Change [API CHANGE]: renamed CompanyIndex to CompanyID and AICompany::ResolveCompanyIndex() to AICompany::ResolveCompanyID(), to be more consistant with the rest of the API
truebrain
parents:
10339
diff
changeset
|
86 |
company = ResolveCompanyID(company); |
10194
c9fdeb7450da
(svn r12727) [NoAI] -Fix (API CHANGE): return -1 to indicate invalidity, instead of 0 or -1, depending on the class
truebrain
parents:
9868
diff
changeset
|
87 |
if (company == INVALID_COMPANY) return -1; |
9668
6fe3d2cb9655
(svn r10582) [NoAI] -Codechange: allow getting the president and company names of other companies as well as their company value and bank balance.
rubidium
parents:
9629
diff
changeset
|
88 |
|
10196
aecabd927420
(svn r12728) [NoAI] -Codechange: always let functions return Money when they return something that can be quantified as money.
rubidium
parents:
10194
diff
changeset
|
89 |
return ::GetPlayer((PlayerID)company)->player_money; |
9374
61379e9b2393
(svn r9161) [NoAI] -Add: functions to get/set company related information: loan, bank balance, company value and company name.
rubidium
parents:
diff
changeset
|
90 |
} |
61379e9b2393
(svn r9161) [NoAI] -Add: functions to get/set company related information: loan, bank balance, company value and company name.
rubidium
parents:
diff
changeset
|
91 |
|
10196
aecabd927420
(svn r12728) [NoAI] -Codechange: always let functions return Money when they return something that can be quantified as money.
rubidium
parents:
10194
diff
changeset
|
92 |
/* static */ Money AICompany::GetLoanAmount() |
9374
61379e9b2393
(svn r9161) [NoAI] -Add: functions to get/set company related information: loan, bank balance, company value and company name.
rubidium
parents:
diff
changeset
|
93 |
{ |
9736
183b38e0a480
(svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents:
9724
diff
changeset
|
94 |
return ::GetPlayer(_current_player)->current_loan; |
9374
61379e9b2393
(svn r9161) [NoAI] -Add: functions to get/set company related information: loan, bank balance, company value and company name.
rubidium
parents:
diff
changeset
|
95 |
} |
61379e9b2393
(svn r9161) [NoAI] -Add: functions to get/set company related information: loan, bank balance, company value and company name.
rubidium
parents:
diff
changeset
|
96 |
|
10196
aecabd927420
(svn r12728) [NoAI] -Codechange: always let functions return Money when they return something that can be quantified as money.
rubidium
parents:
10194
diff
changeset
|
97 |
/* static */ Money AICompany::GetMaxLoanAmount() |
9374
61379e9b2393
(svn r9161) [NoAI] -Add: functions to get/set company related information: loan, bank balance, company value and company name.
rubidium
parents:
diff
changeset
|
98 |
{ |
61379e9b2393
(svn r9161) [NoAI] -Add: functions to get/set company related information: loan, bank balance, company value and company name.
rubidium
parents:
diff
changeset
|
99 |
return _economy.max_loan; |
61379e9b2393
(svn r9161) [NoAI] -Add: functions to get/set company related information: loan, bank balance, company value and company name.
rubidium
parents:
diff
changeset
|
100 |
} |
61379e9b2393
(svn r9161) [NoAI] -Add: functions to get/set company related information: loan, bank balance, company value and company name.
rubidium
parents:
diff
changeset
|
101 |
|
10196
aecabd927420
(svn r12728) [NoAI] -Codechange: always let functions return Money when they return something that can be quantified as money.
rubidium
parents:
10194
diff
changeset
|
102 |
/* static */ Money AICompany::GetLoanInterval() |
9376
7c12a15c945a
(svn r9164) [NoAI] -Add: function to get the value of LOAN_INTERVAL in the AIs.
rubidium
parents:
9374
diff
changeset
|
103 |
{ |
7c12a15c945a
(svn r9164) [NoAI] -Add: function to get the value of LOAN_INTERVAL in the AIs.
rubidium
parents:
9374
diff
changeset
|
104 |
return LOAN_INTERVAL; |
7c12a15c945a
(svn r9164) [NoAI] -Add: function to get the value of LOAN_INTERVAL in the AIs.
rubidium
parents:
9374
diff
changeset
|
105 |
} |
7c12a15c945a
(svn r9164) [NoAI] -Add: function to get the value of LOAN_INTERVAL in the AIs.
rubidium
parents:
9374
diff
changeset
|
106 |
|
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
|
107 |
/* static */ bool AICompany::SetLoanAmount(int32 loan) |
9374
61379e9b2393
(svn r9161) [NoAI] -Add: functions to get/set company related information: loan, bank balance, company value and company name.
rubidium
parents:
diff
changeset
|
108 |
{ |
9868
3998f2e73dda
(svn r12590) [NoAI] -Add: EnforcePrecondition macro to make code much better readable.
rubidium
parents:
9865
diff
changeset
|
109 |
EnforcePrecondition(false, loan >= 0); |
3998f2e73dda
(svn r12590) [NoAI] -Add: EnforcePrecondition macro to make code much better readable.
rubidium
parents:
9865
diff
changeset
|
110 |
EnforcePrecondition(false, (loan % GetLoanInterval()) == 0); |
3998f2e73dda
(svn r12590) [NoAI] -Add: EnforcePrecondition macro to make code much better readable.
rubidium
parents:
9865
diff
changeset
|
111 |
EnforcePrecondition(false, loan <= GetMaxLoanAmount()); |
3998f2e73dda
(svn r12590) [NoAI] -Add: EnforcePrecondition macro to make code much better readable.
rubidium
parents:
9865
diff
changeset
|
112 |
EnforcePrecondition(false, (loan - GetLoanAmount() + GetBankBalance(MY_COMPANY)) >= 0); |
9374
61379e9b2393
(svn r9161) [NoAI] -Add: functions to get/set company related information: loan, bank balance, company value and company name.
rubidium
parents:
diff
changeset
|
113 |
|
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
|
114 |
if (loan == GetLoanAmount()) return true; |
9414
a7f7bbec08da
(svn r9212) [NoAI] -Add: added CmdFailed and CmdSucceeded in AIObject() and used it
truelight
parents:
9376
diff
changeset
|
115 |
|
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
|
116 |
return AIObject::DoCommand(0, |
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
|
117 |
abs(loan - GetLoanAmount()), 2, |
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
|
118 |
(loan > GetLoanAmount()) ? CMD_INCREASE_LOAN : CMD_DECREASE_LOAN); |
9374
61379e9b2393
(svn r9161) [NoAI] -Add: functions to get/set company related information: loan, bank balance, company value and company name.
rubidium
parents:
diff
changeset
|
119 |
} |
9668
6fe3d2cb9655
(svn r10582) [NoAI] -Codechange: allow getting the president and company names of other companies as well as their company value and bank balance.
rubidium
parents:
9629
diff
changeset
|
120 |
|
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
|
121 |
/* static */ bool AICompany::SetMinimumLoanAmount(int32 loan) |
9668
6fe3d2cb9655
(svn r10582) [NoAI] -Codechange: allow getting the president and company names of other companies as well as their company value and bank balance.
rubidium
parents:
9629
diff
changeset
|
122 |
{ |
9868
3998f2e73dda
(svn r12590) [NoAI] -Add: EnforcePrecondition macro to make code much better readable.
rubidium
parents:
9865
diff
changeset
|
123 |
EnforcePrecondition(false, loan >= 0); |
9668
6fe3d2cb9655
(svn r10582) [NoAI] -Codechange: allow getting the president and company names of other companies as well as their company value and bank balance.
rubidium
parents:
9629
diff
changeset
|
124 |
|
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
|
125 |
int32 over_interval = loan % GetLoanInterval(); |
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
|
126 |
if (over_interval != 0) loan += GetLoanInterval() - over_interval; |
9668
6fe3d2cb9655
(svn r10582) [NoAI] -Codechange: allow getting the president and company names of other companies as well as their company value and bank balance.
rubidium
parents:
9629
diff
changeset
|
127 |
|
9868
3998f2e73dda
(svn r12590) [NoAI] -Add: EnforcePrecondition macro to make code much better readable.
rubidium
parents:
9865
diff
changeset
|
128 |
EnforcePrecondition(false, loan <= GetMaxLoanAmount()); |
9668
6fe3d2cb9655
(svn r10582) [NoAI] -Codechange: allow getting the president and company names of other companies as well as their company value and bank balance.
rubidium
parents:
9629
diff
changeset
|
129 |
|
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
|
130 |
SetLoanAmount(loan); |
9668
6fe3d2cb9655
(svn r10582) [NoAI] -Codechange: allow getting the president and company names of other companies as well as their company value and bank balance.
rubidium
parents:
9629
diff
changeset
|
131 |
|
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
|
132 |
return GetLoanAmount() == loan; |
9668
6fe3d2cb9655
(svn r10582) [NoAI] -Codechange: allow getting the president and company names of other companies as well as their company value and bank balance.
rubidium
parents:
9629
diff
changeset
|
133 |
} |
9808
0b40f556e051
(svn r12318) [NoAI] -Add: added AICompany::(Build|Get)CompanyHQ (college of Morloth)
truebrain
parents:
9737
diff
changeset
|
134 |
|
0b40f556e051
(svn r12318) [NoAI] -Add: added AICompany::(Build|Get)CompanyHQ (college of Morloth)
truebrain
parents:
9737
diff
changeset
|
135 |
/* static */ bool AICompany::BuildCompanyHQ(TileIndex tile) |
0b40f556e051
(svn r12318) [NoAI] -Add: added AICompany::(Build|Get)CompanyHQ (college of Morloth)
truebrain
parents:
9737
diff
changeset
|
136 |
{ |
9868
3998f2e73dda
(svn r12590) [NoAI] -Add: EnforcePrecondition macro to make code much better readable.
rubidium
parents:
9865
diff
changeset
|
137 |
EnforcePrecondition(false, ::IsValidTile(tile)); |
9808
0b40f556e051
(svn r12318) [NoAI] -Add: added AICompany::(Build|Get)CompanyHQ (college of Morloth)
truebrain
parents:
9737
diff
changeset
|
138 |
|
0b40f556e051
(svn r12318) [NoAI] -Add: added AICompany::(Build|Get)CompanyHQ (college of Morloth)
truebrain
parents:
9737
diff
changeset
|
139 |
return AIObject::DoCommand(tile, 0, 0, CMD_BUILD_COMPANY_HQ); |
0b40f556e051
(svn r12318) [NoAI] -Add: added AICompany::(Build|Get)CompanyHQ (college of Morloth)
truebrain
parents:
9737
diff
changeset
|
140 |
} |
0b40f556e051
(svn r12318) [NoAI] -Add: added AICompany::(Build|Get)CompanyHQ (college of Morloth)
truebrain
parents:
9737
diff
changeset
|
141 |
|
10855
90904faa1890
(svn r13406) [NoAI] -Change [API CHANGE]: renamed CompanyIndex to CompanyID and AICompany::ResolveCompanyIndex() to AICompany::ResolveCompanyID(), to be more consistant with the rest of the API
truebrain
parents:
10339
diff
changeset
|
142 |
/* static */ TileIndex AICompany::GetCompanyHQ(CompanyID company) |
9808
0b40f556e051
(svn r12318) [NoAI] -Add: added AICompany::(Build|Get)CompanyHQ (college of Morloth)
truebrain
parents:
9737
diff
changeset
|
143 |
{ |
10855
90904faa1890
(svn r13406) [NoAI] -Change [API CHANGE]: renamed CompanyIndex to CompanyID and AICompany::ResolveCompanyIndex() to AICompany::ResolveCompanyID(), to be more consistant with the rest of the API
truebrain
parents:
10339
diff
changeset
|
144 |
company = ResolveCompanyID(company); |
9808
0b40f556e051
(svn r12318) [NoAI] -Add: added AICompany::(Build|Get)CompanyHQ (college of Morloth)
truebrain
parents:
9737
diff
changeset
|
145 |
if (company == INVALID_COMPANY) return INVALID_TILE; |
0b40f556e051
(svn r12318) [NoAI] -Add: added AICompany::(Build|Get)CompanyHQ (college of Morloth)
truebrain
parents:
9737
diff
changeset
|
146 |
|
0b40f556e051
(svn r12318) [NoAI] -Add: added AICompany::(Build|Get)CompanyHQ (college of Morloth)
truebrain
parents:
9737
diff
changeset
|
147 |
TileIndex loc = ::GetPlayer((PlayerID)company)->location_of_house; |
0b40f556e051
(svn r12318) [NoAI] -Add: added AICompany::(Build|Get)CompanyHQ (college of Morloth)
truebrain
parents:
9737
diff
changeset
|
148 |
return (loc == 0) ? INVALID_TILE : loc; |
0b40f556e051
(svn r12318) [NoAI] -Add: added AICompany::(Build|Get)CompanyHQ (college of Morloth)
truebrain
parents:
9737
diff
changeset
|
149 |
} |
10291
11cb78922367
(svn r12823) [NoAI] -Add: added AICompany::(G|S)etAutoRenew(Status|Months|Money)
glx
parents:
10196
diff
changeset
|
150 |
|
11cb78922367
(svn r12823) [NoAI] -Add: added AICompany::(G|S)etAutoRenew(Status|Months|Money)
glx
parents:
10196
diff
changeset
|
151 |
/* static */ bool AICompany::SetAutoRenewStatus(bool autorenew) |
11cb78922367
(svn r12823) [NoAI] -Add: added AICompany::(G|S)etAutoRenew(Status|Months|Money)
glx
parents:
10196
diff
changeset
|
152 |
{ |
11cb78922367
(svn r12823) [NoAI] -Add: added AICompany::(G|S)etAutoRenew(Status|Months|Money)
glx
parents:
10196
diff
changeset
|
153 |
return AIObject::DoCommand(0, 0, autorenew ? 1 : 0, CMD_SET_AUTOREPLACE); |
11cb78922367
(svn r12823) [NoAI] -Add: added AICompany::(G|S)etAutoRenew(Status|Months|Money)
glx
parents:
10196
diff
changeset
|
154 |
} |
11cb78922367
(svn r12823) [NoAI] -Add: added AICompany::(G|S)etAutoRenew(Status|Months|Money)
glx
parents:
10196
diff
changeset
|
155 |
|
10855
90904faa1890
(svn r13406) [NoAI] -Change [API CHANGE]: renamed CompanyIndex to CompanyID and AICompany::ResolveCompanyIndex() to AICompany::ResolveCompanyID(), to be more consistant with the rest of the API
truebrain
parents:
10339
diff
changeset
|
156 |
/* static */ bool AICompany::GetAutoRenewStatus(CompanyID company) |
10291
11cb78922367
(svn r12823) [NoAI] -Add: added AICompany::(G|S)etAutoRenew(Status|Months|Money)
glx
parents:
10196
diff
changeset
|
157 |
{ |
10855
90904faa1890
(svn r13406) [NoAI] -Change [API CHANGE]: renamed CompanyIndex to CompanyID and AICompany::ResolveCompanyIndex() to AICompany::ResolveCompanyID(), to be more consistant with the rest of the API
truebrain
parents:
10339
diff
changeset
|
158 |
company = ResolveCompanyID(company); |
10291
11cb78922367
(svn r12823) [NoAI] -Add: added AICompany::(G|S)etAutoRenew(Status|Months|Money)
glx
parents:
10196
diff
changeset
|
159 |
if (company == INVALID_COMPANY) return false; |
11cb78922367
(svn r12823) [NoAI] -Add: added AICompany::(G|S)etAutoRenew(Status|Months|Money)
glx
parents:
10196
diff
changeset
|
160 |
|
11cb78922367
(svn r12823) [NoAI] -Add: added AICompany::(G|S)etAutoRenew(Status|Months|Money)
glx
parents:
10196
diff
changeset
|
161 |
return ::GetPlayer((PlayerID)company)->engine_renew; |
11cb78922367
(svn r12823) [NoAI] -Add: added AICompany::(G|S)etAutoRenew(Status|Months|Money)
glx
parents:
10196
diff
changeset
|
162 |
} |
11cb78922367
(svn r12823) [NoAI] -Add: added AICompany::(G|S)etAutoRenew(Status|Months|Money)
glx
parents:
10196
diff
changeset
|
163 |
|
11cb78922367
(svn r12823) [NoAI] -Add: added AICompany::(G|S)etAutoRenew(Status|Months|Money)
glx
parents:
10196
diff
changeset
|
164 |
/* static */ bool AICompany::SetAutoRenewMonths(int16 months) |
11cb78922367
(svn r12823) [NoAI] -Add: added AICompany::(G|S)etAutoRenew(Status|Months|Money)
glx
parents:
10196
diff
changeset
|
165 |
{ |
11cb78922367
(svn r12823) [NoAI] -Add: added AICompany::(G|S)etAutoRenew(Status|Months|Money)
glx
parents:
10196
diff
changeset
|
166 |
return AIObject::DoCommand(0, 1, months, CMD_SET_AUTOREPLACE); |
11cb78922367
(svn r12823) [NoAI] -Add: added AICompany::(G|S)etAutoRenew(Status|Months|Money)
glx
parents:
10196
diff
changeset
|
167 |
} |
11cb78922367
(svn r12823) [NoAI] -Add: added AICompany::(G|S)etAutoRenew(Status|Months|Money)
glx
parents:
10196
diff
changeset
|
168 |
|
10855
90904faa1890
(svn r13406) [NoAI] -Change [API CHANGE]: renamed CompanyIndex to CompanyID and AICompany::ResolveCompanyIndex() to AICompany::ResolveCompanyID(), to be more consistant with the rest of the API
truebrain
parents:
10339
diff
changeset
|
169 |
/* static */ int16 AICompany::GetAutoRenewMonths(CompanyID company) |
10291
11cb78922367
(svn r12823) [NoAI] -Add: added AICompany::(G|S)etAutoRenew(Status|Months|Money)
glx
parents:
10196
diff
changeset
|
170 |
{ |
10855
90904faa1890
(svn r13406) [NoAI] -Change [API CHANGE]: renamed CompanyIndex to CompanyID and AICompany::ResolveCompanyIndex() to AICompany::ResolveCompanyID(), to be more consistant with the rest of the API
truebrain
parents:
10339
diff
changeset
|
171 |
company = ResolveCompanyID(company); |
10291
11cb78922367
(svn r12823) [NoAI] -Add: added AICompany::(G|S)etAutoRenew(Status|Months|Money)
glx
parents:
10196
diff
changeset
|
172 |
if (company == INVALID_COMPANY) return 0; |
11cb78922367
(svn r12823) [NoAI] -Add: added AICompany::(G|S)etAutoRenew(Status|Months|Money)
glx
parents:
10196
diff
changeset
|
173 |
|
11cb78922367
(svn r12823) [NoAI] -Add: added AICompany::(G|S)etAutoRenew(Status|Months|Money)
glx
parents:
10196
diff
changeset
|
174 |
return ::GetPlayer((PlayerID)company)->engine_renew_months; |
11cb78922367
(svn r12823) [NoAI] -Add: added AICompany::(G|S)etAutoRenew(Status|Months|Money)
glx
parents:
10196
diff
changeset
|
175 |
} |
11cb78922367
(svn r12823) [NoAI] -Add: added AICompany::(G|S)etAutoRenew(Status|Months|Money)
glx
parents:
10196
diff
changeset
|
176 |
|
11cb78922367
(svn r12823) [NoAI] -Add: added AICompany::(G|S)etAutoRenew(Status|Months|Money)
glx
parents:
10196
diff
changeset
|
177 |
/* static */ bool AICompany::SetAutoRenewMoney(uint32 money) |
11cb78922367
(svn r12823) [NoAI] -Add: added AICompany::(G|S)etAutoRenew(Status|Months|Money)
glx
parents:
10196
diff
changeset
|
178 |
{ |
11cb78922367
(svn r12823) [NoAI] -Add: added AICompany::(G|S)etAutoRenew(Status|Months|Money)
glx
parents:
10196
diff
changeset
|
179 |
return AIObject::DoCommand(0, 2, money, CMD_SET_AUTOREPLACE); |
11cb78922367
(svn r12823) [NoAI] -Add: added AICompany::(G|S)etAutoRenew(Status|Months|Money)
glx
parents:
10196
diff
changeset
|
180 |
} |
11cb78922367
(svn r12823) [NoAI] -Add: added AICompany::(G|S)etAutoRenew(Status|Months|Money)
glx
parents:
10196
diff
changeset
|
181 |
|
10855
90904faa1890
(svn r13406) [NoAI] -Change [API CHANGE]: renamed CompanyIndex to CompanyID and AICompany::ResolveCompanyIndex() to AICompany::ResolveCompanyID(), to be more consistant with the rest of the API
truebrain
parents:
10339
diff
changeset
|
182 |
/* static */ uint32 AICompany::GetAutoRenewMoney(CompanyID company) |
10291
11cb78922367
(svn r12823) [NoAI] -Add: added AICompany::(G|S)etAutoRenew(Status|Months|Money)
glx
parents:
10196
diff
changeset
|
183 |
{ |
10855
90904faa1890
(svn r13406) [NoAI] -Change [API CHANGE]: renamed CompanyIndex to CompanyID and AICompany::ResolveCompanyIndex() to AICompany::ResolveCompanyID(), to be more consistant with the rest of the API
truebrain
parents:
10339
diff
changeset
|
184 |
company = ResolveCompanyID(company); |
10291
11cb78922367
(svn r12823) [NoAI] -Add: added AICompany::(G|S)etAutoRenew(Status|Months|Money)
glx
parents:
10196
diff
changeset
|
185 |
if (company == INVALID_COMPANY) return 0; |
11cb78922367
(svn r12823) [NoAI] -Add: added AICompany::(G|S)etAutoRenew(Status|Months|Money)
glx
parents:
10196
diff
changeset
|
186 |
|
11cb78922367
(svn r12823) [NoAI] -Add: added AICompany::(G|S)etAutoRenew(Status|Months|Money)
glx
parents:
10196
diff
changeset
|
187 |
return ::GetPlayer((PlayerID)company)->engine_renew_money; |
11cb78922367
(svn r12823) [NoAI] -Add: added AICompany::(G|S)etAutoRenew(Status|Months|Money)
glx
parents:
10196
diff
changeset
|
188 |
} |