src/ai/api/ai_company.cpp
author truelight
Fri, 04 May 2007 22:59:59 +0000
branchnoai
changeset 9617 df9cedf12aab
parent 9575 a4b6bbfa6c96
child 9629 66dde6412125
permissions -rw-r--r--
(svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
[NoAI] -Fix: move AITileListValuators self-defined checks to AITile so we can call it per tile (instead of only via AITileList)
/* $Id$ */

/** @file ai_company.cpp handles the functions of the AICompany class */

#include "ai_company.hpp"
#include "../../command.h"
#include "../../player.h"
#include "../../economy.h"
#include "../../strings.h"

bool AICompany::SetCompanyName(const char *name)
{
	if (name == NULL) return false;

	_cmd_text = name;
	return this->DoCommand(0, 0, 0, CMD_CHANGE_COMPANY_NAME);
}

char *AICompany::GetCompanyName()
{
	static const int len = 64;
	char *company_name = MallocT<char>(len);
	GetString(company_name, GetPlayer(_current_player)->name_1, &company_name[len - 1]);

	return company_name;
}

bool AICompany::SetPresidentName(const char *name)
{
	if (name == NULL) return false;

	_cmd_text = name;
	return this->DoCommand(0, 0, 0, CMD_CHANGE_PRESIDENT_NAME);
}

char *AICompany::GetPresidentName()
{
	static const int len = 64;
	char *president_name = MallocT<char>(len);
	GetString(president_name, GetPlayer(_current_player)->president_name_1, &president_name[len - 1]);

	return president_name;
}

int32 AICompany::GetCompanyValue()
{
	return GetPlayer(_current_player)->cur_economy.company_value;
}

int32 AICompany::GetBankBalance()
{
	return GetPlayer(_current_player)->player_money;
}

int32 AICompany::GetLoanAmount()
{
	return GetPlayer(_current_player)->current_loan;
}

int32 AICompany::GetMaxLoanAmount()
{
	return _economy.max_loan;
}

int32 AICompany::GetLoanInterval()
{
	return LOAN_INTERVAL;
}

bool AICompany::SetLoanAmount(int32 loan)
{
	if (loan < 0 ||
			(loan % this->GetLoanInterval()) != 0 ||
			loan > this->GetMaxLoanAmount() ||
			(loan - this->GetLoanAmount() + this->GetBankBalance()) < 0) {
		return false;
	}

	if (loan == this->GetLoanAmount()) return true;

	return this->DoCommand(0,
			abs(loan - this->GetLoanAmount()), 2,
			(loan > this->GetLoanAmount()) ? CMD_INCREASE_LOAN : CMD_DECREASE_LOAN);
}