author | rubidium |
Sun, 18 Mar 2007 20:56:03 +0000 | |
branch | noai |
changeset 9462 | a4f49aab1367 |
parent 9456 | 918a92018df0 |
child 9486 | a9b5f6b8667c |
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 |
|
9436
e28503f827a5
(svn r9247) [NoAI] -Fix: some small coding-style/double inclusion issues.
rubidium
parents:
9430
diff
changeset
|
3 |
/** @file ai_company.cpp handles the functions of the AICompany class */ |
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" |
9441
03da911c8d5f
(svn r9255) [NoAI] -Add: each AI now runs in a seperate thread. The main thread is suspended if any AI thread is running, only one AI thread runs at the time.
truelight
parents:
9436
diff
changeset
|
6 |
#include "../../command.h" |
9430
9e0a193b2bec
(svn r9234) [NoAI] -Codechange: move away from the 'much' subdirectory approach for the API implementation.
rubidium
parents:
9427
diff
changeset
|
7 |
#include "../../player.h" |
9e0a193b2bec
(svn r9234) [NoAI] -Codechange: move away from the 'much' subdirectory approach for the API implementation.
rubidium
parents:
9427
diff
changeset
|
8 |
#include "../../economy.h" |
9e0a193b2bec
(svn r9234) [NoAI] -Codechange: move away from the 'much' subdirectory approach for the API implementation.
rubidium
parents:
9427
diff
changeset
|
9 |
#include "../../strings.h" |
9e0a193b2bec
(svn r9234) [NoAI] -Codechange: move away from the 'much' subdirectory approach for the API implementation.
rubidium
parents:
9427
diff
changeset
|
10 |
|
9e0a193b2bec
(svn r9234) [NoAI] -Codechange: move away from the 'much' subdirectory approach for the API implementation.
rubidium
parents:
9427
diff
changeset
|
11 |
bool AICompany::SetCompanyName(const char *name) |
9e0a193b2bec
(svn r9234) [NoAI] -Codechange: move away from the 'much' subdirectory approach for the API implementation.
rubidium
parents:
9427
diff
changeset
|
12 |
{ |
9e0a193b2bec
(svn r9234) [NoAI] -Codechange: move away from the 'much' subdirectory approach for the API implementation.
rubidium
parents:
9427
diff
changeset
|
13 |
if (name == NULL) return false; |
9e0a193b2bec
(svn r9234) [NoAI] -Codechange: move away from the 'much' subdirectory approach for the API implementation.
rubidium
parents:
9427
diff
changeset
|
14 |
|
9e0a193b2bec
(svn r9234) [NoAI] -Codechange: move away from the 'much' subdirectory approach for the API implementation.
rubidium
parents:
9427
diff
changeset
|
15 |
_cmd_text = name; |
9456
918a92018df0
(svn r9287) [NoAI] -Fix: somehow there was a left over CmdFailed, making SetCompanyName return true, always (tnx XeryusTC)
truelight
parents:
9452
diff
changeset
|
16 |
return this->DoCommand(0, 0, 0, DC_EXEC, CMD_CHANGE_PRESIDENT_NAME); |
9430
9e0a193b2bec
(svn r9234) [NoAI] -Codechange: move away from the 'much' subdirectory approach for the API implementation.
rubidium
parents:
9427
diff
changeset
|
17 |
} |
9e0a193b2bec
(svn r9234) [NoAI] -Codechange: move away from the 'much' subdirectory approach for the API implementation.
rubidium
parents:
9427
diff
changeset
|
18 |
|
9e0a193b2bec
(svn r9234) [NoAI] -Codechange: move away from the 'much' subdirectory approach for the API implementation.
rubidium
parents:
9427
diff
changeset
|
19 |
char *AICompany::GetCompanyName() |
9e0a193b2bec
(svn r9234) [NoAI] -Codechange: move away from the 'much' subdirectory approach for the API implementation.
rubidium
parents:
9427
diff
changeset
|
20 |
{ |
9e0a193b2bec
(svn r9234) [NoAI] -Codechange: move away from the 'much' subdirectory approach for the API implementation.
rubidium
parents:
9427
diff
changeset
|
21 |
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
|
22 |
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
|
23 |
GetString(company_name, GetPlayer(_current_player)->name_1, &company_name[len - 1]); |
9e0a193b2bec
(svn r9234) [NoAI] -Codechange: move away from the 'much' subdirectory approach for the API implementation.
rubidium
parents:
9427
diff
changeset
|
24 |
|
9e0a193b2bec
(svn r9234) [NoAI] -Codechange: move away from the 'much' subdirectory approach for the API implementation.
rubidium
parents:
9427
diff
changeset
|
25 |
return company_name; |
9e0a193b2bec
(svn r9234) [NoAI] -Codechange: move away from the 'much' subdirectory approach for the API implementation.
rubidium
parents:
9427
diff
changeset
|
26 |
} |
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
|
27 |
|
61379e9b2393
(svn r9161) [NoAI] -Add: functions to get/set company related information: loan, bank balance, company value and company name.
rubidium
parents:
diff
changeset
|
28 |
int32 AICompany::GetCompanyValue() |
61379e9b2393
(svn r9161) [NoAI] -Add: functions to get/set company related information: loan, bank balance, company value and company name.
rubidium
parents:
diff
changeset
|
29 |
{ |
61379e9b2393
(svn r9161) [NoAI] -Add: functions to get/set company related information: loan, bank balance, company value and company name.
rubidium
parents:
diff
changeset
|
30 |
return GetPlayer(_current_player)->cur_economy.company_value; |
61379e9b2393
(svn r9161) [NoAI] -Add: functions to get/set company related information: loan, bank balance, company value and company name.
rubidium
parents:
diff
changeset
|
31 |
} |
61379e9b2393
(svn r9161) [NoAI] -Add: functions to get/set company related information: loan, bank balance, company value and company name.
rubidium
parents:
diff
changeset
|
32 |
|
61379e9b2393
(svn r9161) [NoAI] -Add: functions to get/set company related information: loan, bank balance, company value and company name.
rubidium
parents:
diff
changeset
|
33 |
int32 AICompany::GetBankBalance() |
61379e9b2393
(svn r9161) [NoAI] -Add: functions to get/set company related information: loan, bank balance, company value and company name.
rubidium
parents:
diff
changeset
|
34 |
{ |
61379e9b2393
(svn r9161) [NoAI] -Add: functions to get/set company related information: loan, bank balance, company value and company name.
rubidium
parents:
diff
changeset
|
35 |
return GetPlayer(_current_player)->player_money; |
61379e9b2393
(svn r9161) [NoAI] -Add: functions to get/set company related information: loan, bank balance, company value and company name.
rubidium
parents:
diff
changeset
|
36 |
} |
61379e9b2393
(svn r9161) [NoAI] -Add: functions to get/set company related information: loan, bank balance, company value and company name.
rubidium
parents:
diff
changeset
|
37 |
|
61379e9b2393
(svn r9161) [NoAI] -Add: functions to get/set company related information: loan, bank balance, company value and company name.
rubidium
parents:
diff
changeset
|
38 |
int32 AICompany::GetLoanAmount() |
61379e9b2393
(svn r9161) [NoAI] -Add: functions to get/set company related information: loan, bank balance, company value and company name.
rubidium
parents:
diff
changeset
|
39 |
{ |
61379e9b2393
(svn r9161) [NoAI] -Add: functions to get/set company related information: loan, bank balance, company value and company name.
rubidium
parents:
diff
changeset
|
40 |
return GetPlayer(_current_player)->current_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
|
41 |
} |
61379e9b2393
(svn r9161) [NoAI] -Add: functions to get/set company related information: loan, bank balance, company value and company name.
rubidium
parents:
diff
changeset
|
42 |
|
61379e9b2393
(svn r9161) [NoAI] -Add: functions to get/set company related information: loan, bank balance, company value and company name.
rubidium
parents:
diff
changeset
|
43 |
int32 AICompany::GetMaxLoanAmount() |
61379e9b2393
(svn r9161) [NoAI] -Add: functions to get/set company related information: loan, bank balance, company value and company name.
rubidium
parents:
diff
changeset
|
44 |
{ |
61379e9b2393
(svn r9161) [NoAI] -Add: functions to get/set company related information: loan, bank balance, company value and company name.
rubidium
parents:
diff
changeset
|
45 |
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
|
46 |
} |
61379e9b2393
(svn r9161) [NoAI] -Add: functions to get/set company related information: loan, bank balance, company value and company name.
rubidium
parents:
diff
changeset
|
47 |
|
9376
7c12a15c945a
(svn r9164) [NoAI] -Add: function to get the value of LOAN_INTERVAL in the AIs.
rubidium
parents:
9374
diff
changeset
|
48 |
int32 AICompany::GetLoanInterval() |
7c12a15c945a
(svn r9164) [NoAI] -Add: function to get the value of LOAN_INTERVAL in the AIs.
rubidium
parents:
9374
diff
changeset
|
49 |
{ |
7c12a15c945a
(svn r9164) [NoAI] -Add: function to get the value of LOAN_INTERVAL in the AIs.
rubidium
parents:
9374
diff
changeset
|
50 |
return LOAN_INTERVAL; |
7c12a15c945a
(svn r9164) [NoAI] -Add: function to get the value of LOAN_INTERVAL in the AIs.
rubidium
parents:
9374
diff
changeset
|
51 |
} |
7c12a15c945a
(svn r9164) [NoAI] -Add: function to get the value of LOAN_INTERVAL in the AIs.
rubidium
parents:
9374
diff
changeset
|
52 |
|
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
|
53 |
bool AICompany::SetLoanAmount(int32 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
|
54 |
{ |
61379e9b2393
(svn r9161) [NoAI] -Add: functions to get/set company related information: loan, bank balance, company value and company name.
rubidium
parents:
diff
changeset
|
55 |
if (loan < 0 || |
9376
7c12a15c945a
(svn r9164) [NoAI] -Add: function to get the value of LOAN_INTERVAL in the AIs.
rubidium
parents:
9374
diff
changeset
|
56 |
(loan % this->GetLoanInterval()) != 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
|
57 |
loan > this->GetMaxLoanAmount() || |
61379e9b2393
(svn r9161) [NoAI] -Add: functions to get/set company related information: loan, bank balance, company value and company name.
rubidium
parents:
diff
changeset
|
58 |
(loan - this->GetLoanAmount() + this->GetBankBalance()) < 0) { |
61379e9b2393
(svn r9161) [NoAI] -Add: functions to get/set company related information: loan, bank balance, company value and company name.
rubidium
parents:
diff
changeset
|
59 |
return false; |
61379e9b2393
(svn r9161) [NoAI] -Add: functions to get/set company related information: loan, bank balance, company value and company name.
rubidium
parents:
diff
changeset
|
60 |
} |
61379e9b2393
(svn r9161) [NoAI] -Add: functions to get/set company related information: loan, bank balance, company value and company name.
rubidium
parents:
diff
changeset
|
61 |
|
9462
a4f49aab1367
(svn r9294) [NoAI] -Codechange: make changing the loan to 'any' amount a single command.
rubidium
parents:
9456
diff
changeset
|
62 |
if (loan == this->GetLoanAmount()) return true; |
9414
a7f7bbec08da
(svn r9212) [NoAI] -Add: added CmdFailed and CmdSucceeded in AIObject() and used it
truelight
parents:
9376
diff
changeset
|
63 |
|
9462
a4f49aab1367
(svn r9294) [NoAI] -Codechange: make changing the loan to 'any' amount a single command.
rubidium
parents:
9456
diff
changeset
|
64 |
return this->DoCommand(0, |
a4f49aab1367
(svn r9294) [NoAI] -Codechange: make changing the loan to 'any' amount a single command.
rubidium
parents:
9456
diff
changeset
|
65 |
abs(loan - this->GetLoanAmount()), 2, DC_EXEC, |
a4f49aab1367
(svn r9294) [NoAI] -Codechange: make changing the loan to 'any' amount a single command.
rubidium
parents:
9456
diff
changeset
|
66 |
(loan > this->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
|
67 |
} |