src/ai/api/ai_company.hpp
author rubidium
Thu, 03 Apr 2008 23:01:54 +0000
branchnoai
changeset 9865 f241472f09dc
parent 9853 b0512cb3ceb1
child 9866 efc38e1f559a
permissions -rw-r--r--
(svn r12555) [NoAI] -Add: support for GetLastError for AICompany.
/* $Id$ */

/** @file ai_company.hpp Everything to query a company's financials and statistics or build company related buildings. */

#ifndef AI_COMPANY_HPP
#define AI_COMPANY_HPP

#include "ai_object.hpp"

/**
 * Class that handles all company related functions.
 */
class AICompany : public AIObject {
public:
	static const char *GetClassName() { return "AICompany"; }

	/** Different constants related to CompanyIndex. */
	enum CompanyIndex {
		FIRST_COMPANY   = 0, //!< The first available company.
		LAST_COMPANY    = 7, //!< The last available company.
		MY_COMPANY      = 8, //!< Constant that gets resolved to the correct company index for your company.
		INVALID_COMPANY = 9, //!< An invalid company.
	};

	/**
	 * Resolved the given company index to the correct index for the company. If
	 *  the company index was MY_COMPANY it will be resolved to the index of
	 *  your company. If the company with the given index does not exist it will
	 *  return INVALID_COMPANY.
	 * @param company The company index to resolve.
	 * @return The resolved company index.
	 */
	static CompanyIndex ResolveCompanyIndex(CompanyIndex company);

	/**
	 * Set the name of your company.
	 * @param name The new name of the company.
	 * @pre 'name' must have at least one character.
	 * @exception AIError::ERR_NAME_IS_NOT_UNIQUE
	 * @return True if the name was changed.
	 */
	static bool SetCompanyName(const char *name);

	/**
	 * Get the name of the given company.
	 * @param company The company to get the name for.
	 * @pre ResolveCompanyIndex(company) != INVALID_COMPANY
	 * @return The name of the given company.
	 */
	static char *GetCompanyName(CompanyIndex company);

	/**
	 * Set the name of your president.
	 * @param name The new name of the president.
	 * @pre 'name' must have at least one character.
	 * @exception AIError::ERR_NAME_IS_NOT_UNIQUE
	 * @return True if the name was changed.
	 */
	static bool SetPresidentName(const char *name);

	/**
	 * Get the name of the president of the given company.
	 * @param company The company to get the president's name for.
	 * @pre ResolveCompanyIndex(company) != INVALID_COMPANY
	 * @return The name of the president of the given company.
	 */
	static char *GetPresidentName(CompanyIndex company);

	/**
	 * Sets the amount to loan.
	 * @param loan The amount to loan (multiplier of GetLoanInterval()).
	 * @pre 'loan' must be non-negative.
	 * @pre GetLoanInterval() must be a multiplier of GetLoanInterval().
	 * @pre 'loan' must be below GetMaxLoanAmount().
	 * @pre 'loan' - GetLoanAmount() + GetBankBalance() must be non-negative.
	 * @return True if the loan could be set to your requested amount.
	 */
	static bool SetLoanAmount(int32 loan);

	/**
	 * Sets the minimum amount to loan, i.e. the given amount of loan rounded up.
	 * @param loan The amount to loan (any positive number).
	 * @pre 'loan' must be non-negative.
	 * @pre 'loan' must be below GetMaxLoanAmount().
	 * @return True if we could allocate a minimum of "loan" loan.
	 */
	static bool SetMinimumLoanAmount(int32 loan);

	/**
	 * Gets the amount your company have loaned.
	 * @return The amount loaned money.
	 * @post The return value is always non-negative.
	 * @post GetLoanInterval() is always a multiplier of the return value.
	 */
	static int32 GetLoanAmount();

	/**
	 * Gets the maximum amount your company can loan.
	 * @return The maximum amount your company can loan.
	 * @post The return value is always non-negative.
	 * @post GetLoanInterval() is always a multiplier of the return value.
	 */
	static int32 GetMaxLoanAmount();

	/**
	 * Gets the interval/loan step.
	 * @return The loan step.
	 * @post Return value is always positive.
	 */
	static int32 GetLoanInterval();

	/**
	 * Gets the current value of the given company.
	 * @param company The company to get the company value of.
	 * @pre ResolveCompanyIndex(company) != INVALID_COMPANY
	 * @return The current value of the given company.
	 */
	static int32 GetCompanyValue(CompanyIndex company);

	/**
	 * Gets the bank balance. In other words, the amount of money the given company can spent.
	 * @param company The company to get the bank balance of.
	 * @pre ResolveCompanyIndex(company) != INVALID_COMPANY
	 * @return The actual bank balance.
	 */
	static int32 GetBankBalance(CompanyIndex company);

	/**
	 * Build your company's HQ on the given tile.
	 * @param tile The tile to build your HQ on, this tile is the most nothern tile of your HQ.
	 * @pre AIMap::IsValidTile(tile).
	 * @exception AIError::ERR_AREA_NOT_CLEAR
	 * @return True if the HQ could be build.
	 * @note An HQ can not be removed, only by water or rebuilding; If an HQ is
	 *  build again, the old one is removed.
	 */
	static bool BuildCompanyHQ(TileIndex tile);

	/**
	 * Return the location of a company's HQ.
	 * @param company The company the get the HQ of.
	 * @pre ResolveCompanyIndex(company) != INVALID_COMPANY.
	 * @return The tile of the company's HQ, this tile is the most nothern tile of that HQ, or INVALID_TILE if there is no HQ yet.
	 */
	static TileIndex GetCompanyHQ(CompanyIndex company);
};

DECLARE_POSTFIX_INCREMENT(AICompany::CompanyIndex);

#endif /* AI_COMPANY_HPP */