src/ai/api/ai_company.cpp
author glx
Mon, 21 Apr 2008 20:33:03 +0000
branchnoai
changeset 10291 11cb78922367
parent 10196 aecabd927420
child 10339 ce6cd68d9eb8
permissions -rw-r--r--
(svn r12823) [NoAI] -Add: added AICompany::(G|S)etAutoRenew(Status|Months|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
     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"
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9701
diff changeset
     7
#include "../../command_func.h"
9724
b39bc69bb2f2 (svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents: 9723
diff changeset
     8
#include "../../player_func.h"
b39bc69bb2f2 (svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents: 9723
diff changeset
     9
#include "../../player_base.h"
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9701
diff changeset
    10
#include "../../economy_func.h"
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9701
diff changeset
    11
#include "../../strings_func.h"
9808
0b40f556e051 (svn r12318) [NoAI] -Add: added AICompany::(Build|Get)CompanyHQ (college of Morloth)
truebrain
parents: 9737
diff changeset
    12
#include "../../tile_map.h"
9629
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9575
diff changeset
    13
#include "../../variables.h"
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9701
diff changeset
    14
#include "../../core/alloc_func.hpp"
9865
f241472f09dc (svn r12555) [NoAI] -Add: support for GetLastError for AICompany.
rubidium
parents: 9833
diff changeset
    15
#include "../../string_func.h"
9629
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9575
diff changeset
    16
#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
    17
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
    18
/* static */ AICompany::CompanyIndex AICompany::ResolveCompanyIndex(AICompany::CompanyIndex 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
    19
{
9701
d1ac22c62f64 (svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents: 9696
diff changeset
    20
	if (company == MY_COMPANY) return (CompanyIndex)((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
    21
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
    22
	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
    23
}
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
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
    25
/* 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
    26
{
9868
3998f2e73dda (svn r12590) [NoAI] -Add: EnforcePrecondition macro to make code much better readable.
rubidium
parents: 9865
diff changeset
    27
	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
    28
9e0a193b2bec (svn r9234) [NoAI] -Codechange: move away from the 'much' subdirectory approach for the API implementation.
rubidium
parents: 9427
diff changeset
    29
	_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
    30
	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
    31
}
9e0a193b2bec (svn r9234) [NoAI] -Codechange: move away from the 'much' subdirectory approach for the API implementation.
rubidium
parents: 9427
diff changeset
    32
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
    33
/* static */ char *AICompany::GetCompanyName(AICompany::CompanyIndex company)
9430
9e0a193b2bec (svn r9234) [NoAI] -Codechange: move away from the 'much' subdirectory approach for the API implementation.
rubidium
parents: 9427
diff changeset
    34
{
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
    35
	company = ResolveCompanyIndex(company);
9696
4384ed3de1f0 (svn r10937) [NoAI] -Add: added AIStation::GetName on request by Nickman
truelight
parents: 9668
diff changeset
    36
	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
    37
9430
9e0a193b2bec (svn r9234) [NoAI] -Codechange: move away from the 'much' subdirectory approach for the API implementation.
rubidium
parents: 9427
diff changeset
    38
	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
    39
	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
    40
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
    41
	::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
    42
	::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
    43
	return company_name;
9e0a193b2bec (svn r9234) [NoAI] -Codechange: move away from the 'much' subdirectory approach for the API implementation.
rubidium
parents: 9427
diff changeset
    44
}
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
    45
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
    46
/* 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
    47
{
9868
3998f2e73dda (svn r12590) [NoAI] -Add: EnforcePrecondition macro to make code much better readable.
rubidium
parents: 9865
diff changeset
    48
	EnforcePrecondition(false, !::StrEmpty(name));
9575
a4b6bbfa6c96 (svn r9591) [NoAI] -Fix: SetCompanyName() in fact set the president name (Zuu)
truelight
parents: 9486
diff changeset
    49
a4b6bbfa6c96 (svn r9591) [NoAI] -Fix: SetCompanyName() in fact set the president name (Zuu)
truelight
parents: 9486
diff changeset
    50
	_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
    51
	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
    52
}
a4b6bbfa6c96 (svn r9591) [NoAI] -Fix: SetCompanyName() in fact set the president name (Zuu)
truelight
parents: 9486
diff changeset
    53
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
    54
/* static */ char *AICompany::GetPresidentName(AICompany::CompanyIndex company)
9575
a4b6bbfa6c96 (svn r9591) [NoAI] -Fix: SetCompanyName() in fact set the president name (Zuu)
truelight
parents: 9486
diff changeset
    55
{
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
    56
	company = ResolveCompanyIndex(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
    57
9575
a4b6bbfa6c96 (svn r9591) [NoAI] -Fix: SetCompanyName() in fact set the president name (Zuu)
truelight
parents: 9486
diff changeset
    58
	static const int len = 64;
a4b6bbfa6c96 (svn r9591) [NoAI] -Fix: SetCompanyName() in fact set the president name (Zuu)
truelight
parents: 9486
diff changeset
    59
	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
    60
	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
    61
		::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
    62
		::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
    63
	} 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
    64
		*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
    65
	}
9575
a4b6bbfa6c96 (svn r9591) [NoAI] -Fix: SetCompanyName() in fact set the president name (Zuu)
truelight
parents: 9486
diff changeset
    66
a4b6bbfa6c96 (svn r9591) [NoAI] -Fix: SetCompanyName() in fact set the president name (Zuu)
truelight
parents: 9486
diff changeset
    67
	return president_name;
a4b6bbfa6c96 (svn r9591) [NoAI] -Fix: SetCompanyName() in fact set the president name (Zuu)
truelight
parents: 9486
diff changeset
    68
}
a4b6bbfa6c96 (svn r9591) [NoAI] -Fix: SetCompanyName() in fact set the president name (Zuu)
truelight
parents: 9486
diff changeset
    69
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
    70
/* static */ Money AICompany::GetCompanyValue(AICompany::CompanyIndex 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
    71
{
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
    72
	company = ResolveCompanyIndex(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
    73
	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
    74
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
    75
	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
    76
}
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
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
    78
/* static */ Money AICompany::GetBankBalance(AICompany::CompanyIndex 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
    79
{
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
    80
	company = ResolveCompanyIndex(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
    81
	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
    82
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
    83
	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
    84
}
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
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
    86
/* 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
    87
{
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
    88
	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
    89
}
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
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
    91
/* 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
    92
{
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
	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
    94
}
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
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
    96
/* 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
    97
{
7c12a15c945a (svn r9164) [NoAI] -Add: function to get the value of LOAN_INTERVAL in the AIs.
rubidium
parents: 9374
diff changeset
    98
	return LOAN_INTERVAL;
7c12a15c945a (svn r9164) [NoAI] -Add: function to get the value of LOAN_INTERVAL in the AIs.
rubidium
parents: 9374
diff changeset
    99
}
7c12a15c945a (svn r9164) [NoAI] -Add: function to get the value of LOAN_INTERVAL in the AIs.
rubidium
parents: 9374
diff changeset
   100
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
   101
/* 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
   102
{
9868
3998f2e73dda (svn r12590) [NoAI] -Add: EnforcePrecondition macro to make code much better readable.
rubidium
parents: 9865
diff changeset
   103
	EnforcePrecondition(false, loan >= 0);
3998f2e73dda (svn r12590) [NoAI] -Add: EnforcePrecondition macro to make code much better readable.
rubidium
parents: 9865
diff changeset
   104
	EnforcePrecondition(false, (loan % GetLoanInterval()) == 0);
3998f2e73dda (svn r12590) [NoAI] -Add: EnforcePrecondition macro to make code much better readable.
rubidium
parents: 9865
diff changeset
   105
	EnforcePrecondition(false, loan <= GetMaxLoanAmount());
3998f2e73dda (svn r12590) [NoAI] -Add: EnforcePrecondition macro to make code much better readable.
rubidium
parents: 9865
diff changeset
   106
	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
   107
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
   108
	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
   109
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
   110
	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
   111
			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
   112
			(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
   113
}
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
   114
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
   115
/* 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
   116
{
9868
3998f2e73dda (svn r12590) [NoAI] -Add: EnforcePrecondition macro to make code much better readable.
rubidium
parents: 9865
diff changeset
   117
	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
   118
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
   119
	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
   120
	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
   121
9868
3998f2e73dda (svn r12590) [NoAI] -Add: EnforcePrecondition macro to make code much better readable.
rubidium
parents: 9865
diff changeset
   122
	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
   123
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
   124
	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
   125
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
   126
	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
   127
}
9808
0b40f556e051 (svn r12318) [NoAI] -Add: added AICompany::(Build|Get)CompanyHQ (college of Morloth)
truebrain
parents: 9737
diff changeset
   128
0b40f556e051 (svn r12318) [NoAI] -Add: added AICompany::(Build|Get)CompanyHQ (college of Morloth)
truebrain
parents: 9737
diff changeset
   129
/* static */ bool AICompany::BuildCompanyHQ(TileIndex tile)
0b40f556e051 (svn r12318) [NoAI] -Add: added AICompany::(Build|Get)CompanyHQ (college of Morloth)
truebrain
parents: 9737
diff changeset
   130
{
9868
3998f2e73dda (svn r12590) [NoAI] -Add: EnforcePrecondition macro to make code much better readable.
rubidium
parents: 9865
diff changeset
   131
	EnforcePrecondition(false, ::IsValidTile(tile));
9808
0b40f556e051 (svn r12318) [NoAI] -Add: added AICompany::(Build|Get)CompanyHQ (college of Morloth)
truebrain
parents: 9737
diff changeset
   132
0b40f556e051 (svn r12318) [NoAI] -Add: added AICompany::(Build|Get)CompanyHQ (college of Morloth)
truebrain
parents: 9737
diff changeset
   133
	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
   134
}
0b40f556e051 (svn r12318) [NoAI] -Add: added AICompany::(Build|Get)CompanyHQ (college of Morloth)
truebrain
parents: 9737
diff changeset
   135
0b40f556e051 (svn r12318) [NoAI] -Add: added AICompany::(Build|Get)CompanyHQ (college of Morloth)
truebrain
parents: 9737
diff changeset
   136
/* static */ TileIndex AICompany::GetCompanyHQ(CompanyIndex company)
0b40f556e051 (svn r12318) [NoAI] -Add: added AICompany::(Build|Get)CompanyHQ (college of Morloth)
truebrain
parents: 9737
diff changeset
   137
{
0b40f556e051 (svn r12318) [NoAI] -Add: added AICompany::(Build|Get)CompanyHQ (college of Morloth)
truebrain
parents: 9737
diff changeset
   138
	company = ResolveCompanyIndex(company);
0b40f556e051 (svn r12318) [NoAI] -Add: added AICompany::(Build|Get)CompanyHQ (college of Morloth)
truebrain
parents: 9737
diff changeset
   139
	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
   140
0b40f556e051 (svn r12318) [NoAI] -Add: added AICompany::(Build|Get)CompanyHQ (college of Morloth)
truebrain
parents: 9737
diff changeset
   141
	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
   142
	return (loc == 0) ? INVALID_TILE : loc;
0b40f556e051 (svn r12318) [NoAI] -Add: added AICompany::(Build|Get)CompanyHQ (college of Morloth)
truebrain
parents: 9737
diff changeset
   143
}
10291
11cb78922367 (svn r12823) [NoAI] -Add: added AICompany::(G|S)etAutoRenew(Status|Months|Money)
glx
parents: 10196
diff changeset
   144
11cb78922367 (svn r12823) [NoAI] -Add: added AICompany::(G|S)etAutoRenew(Status|Months|Money)
glx
parents: 10196
diff changeset
   145
/* static */ bool AICompany::SetAutoRenewStatus(bool autorenew)
11cb78922367 (svn r12823) [NoAI] -Add: added AICompany::(G|S)etAutoRenew(Status|Months|Money)
glx
parents: 10196
diff changeset
   146
{
11cb78922367 (svn r12823) [NoAI] -Add: added AICompany::(G|S)etAutoRenew(Status|Months|Money)
glx
parents: 10196
diff changeset
   147
	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
   148
}
11cb78922367 (svn r12823) [NoAI] -Add: added AICompany::(G|S)etAutoRenew(Status|Months|Money)
glx
parents: 10196
diff changeset
   149
11cb78922367 (svn r12823) [NoAI] -Add: added AICompany::(G|S)etAutoRenew(Status|Months|Money)
glx
parents: 10196
diff changeset
   150
/* static */ bool AICompany::GetAutoRenewStatus(CompanyIndex company)
11cb78922367 (svn r12823) [NoAI] -Add: added AICompany::(G|S)etAutoRenew(Status|Months|Money)
glx
parents: 10196
diff changeset
   151
{
11cb78922367 (svn r12823) [NoAI] -Add: added AICompany::(G|S)etAutoRenew(Status|Months|Money)
glx
parents: 10196
diff changeset
   152
	company = ResolveCompanyIndex(company);
11cb78922367 (svn r12823) [NoAI] -Add: added AICompany::(G|S)etAutoRenew(Status|Months|Money)
glx
parents: 10196
diff changeset
   153
	if (company == INVALID_COMPANY) return false;
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
	return ::GetPlayer((PlayerID)company)->engine_renew;
11cb78922367 (svn r12823) [NoAI] -Add: added AICompany::(G|S)etAutoRenew(Status|Months|Money)
glx
parents: 10196
diff changeset
   156
}
11cb78922367 (svn r12823) [NoAI] -Add: added AICompany::(G|S)etAutoRenew(Status|Months|Money)
glx
parents: 10196
diff changeset
   157
11cb78922367 (svn r12823) [NoAI] -Add: added AICompany::(G|S)etAutoRenew(Status|Months|Money)
glx
parents: 10196
diff changeset
   158
/* static */ bool AICompany::SetAutoRenewMonths(int16 months)
11cb78922367 (svn r12823) [NoAI] -Add: added AICompany::(G|S)etAutoRenew(Status|Months|Money)
glx
parents: 10196
diff changeset
   159
{
11cb78922367 (svn r12823) [NoAI] -Add: added AICompany::(G|S)etAutoRenew(Status|Months|Money)
glx
parents: 10196
diff changeset
   160
	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
   161
}
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
/* static */ int16 AICompany::GetAutoRenewMonths(CompanyIndex company)
11cb78922367 (svn r12823) [NoAI] -Add: added AICompany::(G|S)etAutoRenew(Status|Months|Money)
glx
parents: 10196
diff changeset
   164
{
11cb78922367 (svn r12823) [NoAI] -Add: added AICompany::(G|S)etAutoRenew(Status|Months|Money)
glx
parents: 10196
diff changeset
   165
	company = ResolveCompanyIndex(company);
11cb78922367 (svn r12823) [NoAI] -Add: added AICompany::(G|S)etAutoRenew(Status|Months|Money)
glx
parents: 10196
diff changeset
   166
	if (company == INVALID_COMPANY) return 0;
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
	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
   169
}
11cb78922367 (svn r12823) [NoAI] -Add: added AICompany::(G|S)etAutoRenew(Status|Months|Money)
glx
parents: 10196
diff changeset
   170
11cb78922367 (svn r12823) [NoAI] -Add: added AICompany::(G|S)etAutoRenew(Status|Months|Money)
glx
parents: 10196
diff changeset
   171
/* static */ bool AICompany::SetAutoRenewMoney(uint32 money)
11cb78922367 (svn r12823) [NoAI] -Add: added AICompany::(G|S)etAutoRenew(Status|Months|Money)
glx
parents: 10196
diff changeset
   172
{
11cb78922367 (svn r12823) [NoAI] -Add: added AICompany::(G|S)etAutoRenew(Status|Months|Money)
glx
parents: 10196
diff changeset
   173
	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
   174
}
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
/* static */ uint32 AICompany::GetAutoRenewMoney(CompanyIndex company)
11cb78922367 (svn r12823) [NoAI] -Add: added AICompany::(G|S)etAutoRenew(Status|Months|Money)
glx
parents: 10196
diff changeset
   177
{
11cb78922367 (svn r12823) [NoAI] -Add: added AICompany::(G|S)etAutoRenew(Status|Months|Money)
glx
parents: 10196
diff changeset
   178
	company = ResolveCompanyIndex(company);
11cb78922367 (svn r12823) [NoAI] -Add: added AICompany::(G|S)etAutoRenew(Status|Months|Money)
glx
parents: 10196
diff changeset
   179
	if (company == INVALID_COMPANY) return 0;
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
	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
   182
}