# AICompany Class Reference

Class that handles all company related functions. More...

`#include <ai_company.hpp>`

Inheritance diagram for AICompany:

## Public Types
enum | CompanyID { COMPANY_FIRST = 0, COMPANY_LAST = ::MAX_COMPANIES, COMPANY_SELF = 254, COMPANY_INVALID = -1 }
| Different constants related to CompanyID. More...
enum | Gender { GENDER_MALE, GENDER_FEMALE, GENDER_INVALID = -1 }
| Possible genders for company presidents. More...
## Static Public Member Functions
static const char * | GetClassName ()
static CompanyID | ResolveCompanyID (CompanyID company)
| Resolved the given company index to the correct index for the company.
static bool | IsMine (CompanyID company)
| Check if a CompanyID is your CompanyID, to ease up checks.
static bool | SetName (const char *name)
| Set the name of your company.
static char * | GetName (CompanyID company)
| Get the name of the given company.
static bool | SetPresidentName (const char *name)
| Set the name of your president.
static char * | GetPresidentName (CompanyID company)
| Get the name of the president of the given company.
static bool | SetPresidentGender (Gender gender)
| Set the gender of the president of your company.
static Gender | GetPresidentGender (CompanyID company)
| Get the gender of the president of the given company.
static bool | SetLoanAmount (int32 loan)
| Sets the amount to loan.
static bool | SetMinimumLoanAmount (int32 loan)
| Sets the minimum amount to loan, i.e.
static Money | GetLoanAmount ()
| Gets the amount your company have loaned.
static Money | GetMaxLoanAmount ()
| Gets the maximum amount your company can loan.
static Money | GetLoanInterval ()
| Gets the interval/loan step.
static Money | GetCompanyValue (CompanyID company)
| Gets the current value of the given company.
static Money | GetBankBalance (CompanyID company)
| Gets the bank balance.
static bool | BuildCompanyHQ (TileIndex tile)
| Build your company's HQ on the given tile.
static TileIndex | GetCompanyHQ (CompanyID company)
| Return the location of a company's HQ.
static bool | SetAutoRenewStatus (bool autorenew)
| Set whether autorenew is enabled for your company.
static bool | GetAutoRenewStatus (CompanyID company)
| Return whether autorenew is enabled for a company.
static bool | SetAutoRenewMonths (int16 months)
| Set the number of months before/after max age to autorenew an engine for your company.
static int16 | GetAutoRenewMonths (CompanyID company)
| Return the number of months before/after max age to autorenew an engine for a company.
static bool | SetAutoRenewMoney (uint32 money)
| Set the minimum money needed to autorenew an engine for your company.
static uint32 | GetAutoRenewMoney (CompanyID company)
| Return the minimum money needed to autorenew an engine for a company.

## Detailed Description

Class that handles all company related functions.

Definition at line 20 of file ai_company.hpp.

## Member Enumeration Documentation

enum AICompany::CompanyID

Different constants related to CompanyID.

Enumerator:

  COMPANY_FIRST | The first available company.
  COMPANY_LAST | The last available company.
  COMPANY_SELF | Constant that gets resolved to the correct company index for your company.
  COMPANY_INVALID | An invalid company.

Definition at line 25 of file ai_company.hpp.

enum AICompany::Gender

Possible genders for company presidents.

Enumerator:

  GENDER_MALE | A male person.
  GENDER_FEMALE | A female person.
  GENDER_INVALID | An invalid gender.

Definition at line 33 of file ai_company.hpp.

## Member Function Documentation

AICompany::CompanyID AICompany::ResolveCompanyID | ( | AICompany::CompanyID | company | ) | `[static]`

Resolved the given company index to the correct index for the company.

If the company index was COMPANY_SELF it will be resolved to the index of your company. If the company with the given index does not exist it will return COMPANY_INVALID.

Parameters:

  | company | The company index to resolve.

Returns:
  The resolved company index.

Definition at line 25 of file ai_company.cpp.

References COMPANY_INVALID, and COMPANY_SELF.

Referenced by GetAutoRenewMoney(), GetAutoRenewMonths(), GetAutoRenewStatus(), GetBankBalance(), GetCompanyHQ(), GetCompanyValue(), GetName(), AITile::GetOwner(), GetPresidentGender(), GetPresidentName(), AITown::GetRating(), and IsMine().

bool AICompany::IsMine | ( | AICompany::CompanyID | company | ) | `[static]`

Check if a CompanyID is your CompanyID, to ease up checks.

Parameters:

  | company | The company index to check.

Returns:
  True if and only if this company is your CompanyID.

Definition at line 32 of file ai_company.cpp.

References COMPANY_SELF, and ResolveCompanyID().

bool AICompany::SetName | ( | const char * | name | ) | `[static]`

Set the name of your company.

Parameters:

  | name | The new name of the company.

Precondition:
  'name' must have at least one character.

  'name' must have at most 30 characters.

Exceptions:

  | AIError::ERR_NAME_IS_NOT_UNIQUE |

Returns:
  True if the name was changed.

Definition at line 37 of file ai_company.cpp.

References CMD_RENAME_COMPANY, AIObject::DoCommand(), EnforcePrecondition, EnforcePreconditionCustomError, AIError::ERR_PRECONDITION_STRING_TOO_LONG, MAX_LENGTH_COMPANY_NAME_BYTES, and StrEmpty().

char * AICompany::GetName | ( | AICompany::CompanyID | company | ) | `[static]`

Get the name of the given company.

Parameters:

  | company | The company to get the name for.

Precondition:
  ResolveCompanyID(company) != COMPANY_INVALID.

Returns:
  The name of the given company.

Definition at line 45 of file ai_company.cpp.

References COMPANY_INVALID, ResolveCompanyID(), and SetDParam().

bool AICompany::SetPresidentName | ( | const char * | name | ) | `[static]`

Set the name of your president.

Parameters:

  | name | The new name of the president.

Precondition:
  'name' must have at least one character.

Exceptions:

  | AIError::ERR_NAME_IS_NOT_UNIQUE |

Returns:
  True if the name was changed.

Definition at line 58 of file ai_company.cpp.

References CMD_RENAME_PRESIDENT, AIObject::DoCommand(), EnforcePrecondition, and StrEmpty().

char * AICompany::GetPresidentName | ( | AICompany::CompanyID | company | ) | `[static]`

Get the name of the president of the given company.

Parameters:

  | company | The company to get the president's name for.

Precondition:
  ResolveCompanyID(company) != COMPANY_INVALID.

Returns:
  The name of the president of the given company.

Definition at line 65 of file ai_company.cpp.

References COMPANY_INVALID, ResolveCompanyID(), and SetDParam().

bool AICompany::SetPresidentGender | ( | Gender | gender | ) | `[static]`

Set the gender of the president of your company.

Parameters:

  | gender | The new gender for your president.

Precondition:
  GetPresidentGender(AICompany.COMPANY_SELF) != gender.

Returns:
  True if the gender was changed.

Note:
  When succesfull a random face will be created.

Definition at line 81 of file ai_company.cpp.

References CMD_SET_COMPANY_MANAGER_FACE, COMPANY_SELF, AIObject::DoCommand(), EnforcePrecondition, ETHNICITY_BLACK, GENDER_FEMALE, GENDER_MALE, GetPresidentGender(), and RandomCompanyManagerFaceBits().

AICompany::Gender AICompany::GetPresidentGender | ( | CompanyID | company | ) | `[static]`

Get the gender of the president of the given company.

Parameters:

  | company | The company to get the presidents gender off.

Returns:
  The gender of the president.

Definition at line 93 of file ai_company.cpp.

References COMPANY_INVALID, GE_WM, GENDER_FEMALE, GENDER_INVALID, GENDER_MALE, GetCompanyManagerFaceBits(), HasBit(), and ResolveCompanyID().

Referenced by SetPresidentGender().

bool AICompany::SetLoanAmount | ( | int32 | loan | ) | `[static]`

Sets the amount to loan.

Parameters:

  | loan | The amount to loan (multiplier of GetLoanInterval()).

Precondition:
  'loan' must be non-negative.

  GetLoanInterval() must be a multiplier of 'loan'.

  'loan' must be below GetMaxLoanAmount().

  'loan' - GetLoanAmount() + GetBankBalance() must be non-negative.

Returns:
  True if the loan could be set to your requested amount.

Definition at line 133 of file ai_company.cpp.

References abs(), CMD_DECREASE_LOAN, CMD_INCREASE_LOAN, COMPANY_SELF, AIObject::DoCommand(), EnforcePrecondition, GetBankBalance(), GetLoanAmount(), GetLoanInterval(), and GetMaxLoanAmount().

Referenced by SetMinimumLoanAmount().

bool AICompany::SetMinimumLoanAmount | ( | int32 | loan | ) | `[static]`

Sets the minimum amount to loan, i.e.

the given amount of loan rounded up.

Parameters:

  | loan | The amount to loan (any positive number).

Precondition:
  'loan' must be non-negative.

  'loan' must be below GetMaxLoanAmount().

Returns:
  True if we could allocate a minimum of 'loan' loan.

Definition at line 147 of file ai_company.cpp.

References EnforcePrecondition, GetLoanAmount(), GetLoanInterval(), GetMaxLoanAmount(), and SetLoanAmount().

Money AICompany::GetLoanAmount | ( |  | ) | `[static]`

Gets the amount your company have loaned.

Returns:
  The amount loaned money.

Postcondition:
  The return value is always non-negative.

  GetLoanInterval() is always a multiplier of the return value.

Definition at line 118 of file ai_company.cpp.

Referenced by SetLoanAmount(), and SetMinimumLoanAmount().

Money AICompany::GetMaxLoanAmount | ( |  | ) | `[static]`

Gets the maximum amount your company can loan.

Returns:
  The maximum amount your company can loan.

Postcondition:
  The return value is always non-negative.

  GetLoanInterval() is always a multiplier of the return value.

Definition at line 123 of file ai_company.cpp.

Referenced by SetLoanAmount(), and SetMinimumLoanAmount().

Money AICompany::GetLoanInterval | ( |  | ) | `[static]`

Gets the interval/loan step.

Returns:
  The loan step.

Postcondition:
  Return value is always positive.

Definition at line 128 of file ai_company.cpp.

References LOAN_INTERVAL.

Referenced by SetLoanAmount(), and SetMinimumLoanAmount().

Money AICompany::GetCompanyValue | ( | AICompany::CompanyID | company | ) | `[static]`

Gets the current value of the given company.

Parameters:

  | company | The company to get the company value of.

Precondition:
  ResolveCompanyID(company) != COMPANY_INVALID.

Returns:
  The current value of the given company.

Definition at line 102 of file ai_company.cpp.

References COMPANY_INVALID, and ResolveCompanyID().

Money AICompany::GetBankBalance | ( | AICompany::CompanyID | company | ) | `[static]`

Gets the bank balance.

In other words, the amount of money the given company can spent.

Parameters:

  | company | The company to get the bank balance of.

Precondition:
  ResolveCompanyID(company) != COMPANY_INVALID.

Returns:
  The actual bank balance.

Definition at line 110 of file ai_company.cpp.

References COMPANY_INVALID, and ResolveCompanyID().

Referenced by SetLoanAmount().

bool AICompany::BuildCompanyHQ | ( | TileIndex | tile | ) | `[static]`

Build your company's HQ on the given tile.

Parameters:

  | tile | The tile to build your HQ on, this tile is the most nothern tile of your HQ.

Precondition:
  AIMap::IsValidTile(tile).

Exceptions:

  | AIError::ERR_AREA_NOT_CLEAR |
  | AIError::ERR_FLAT_LAND_REQUIRED |

Returns:
  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.

Definition at line 161 of file ai_company.cpp.

References CMD_BUILD_COMPANY_HQ, AIObject::DoCommand(), EnforcePrecondition, and IsValidTile().

TileIndex AICompany::GetCompanyHQ | ( | CompanyID | company | ) | `[static]`

Return the location of a company's HQ.

Parameters:

  | company | The company the get the HQ of.

Precondition:
  ResolveCompanyID(company) != COMPANY_INVALID.

Returns:
  The tile of the company's HQ, this tile is the most nothern tile of that HQ, or AIMap::TILE_INVALID if there is no HQ yet.

Definition at line 168 of file ai_company.cpp.

References COMPANY_INVALID, INVALID_TILE, and ResolveCompanyID().

bool AICompany::SetAutoRenewStatus | ( | bool | autorenew | ) | `[static]`

Set whether autorenew is enabled for your company.

Parameters:

  | autorenew | The new autorenew status.

Returns:
  True if autorenew status has been modified.

Definition at line 177 of file ai_company.cpp.

References CMD_CHANGE_COMPANY_SETTING, AIObject::DoCommand(), and GetCompanySettingIndex().

bool AICompany::GetAutoRenewStatus | ( | CompanyID | company | ) | `[static]`

Return whether autorenew is enabled for a company.

Parameters:

  | company | The company to get the autorenew status of.

Precondition:
  ResolveCompanyID(company) != COMPANY_INVALID.

Returns:
  True if autorenew is enabled.

Definition at line 182 of file ai_company.cpp.

References COMPANY_INVALID, and ResolveCompanyID().

bool AICompany::SetAutoRenewMonths | ( | int16 | months | ) | `[static]`

Set the number of months before/after max age to autorenew an engine for your company.

Parameters:

  | months | The new months between autorenew.

Returns:
  True if autorenew months has been modified.

Definition at line 190 of file ai_company.cpp.

References CMD_CHANGE_COMPANY_SETTING, AIObject::DoCommand(), and GetCompanySettingIndex().

int16 AICompany::GetAutoRenewMonths | ( | CompanyID | company | ) | `[static]`

Return the number of months before/after max age to autorenew an engine for a company.

Parameters:

  | company | The company to get the autorenew months of.

Precondition:
  ResolveCompanyID(company) != COMPANY_INVALID.

Returns:
  The months before/after max age of engine.

Definition at line 195 of file ai_company.cpp.

References COMPANY_INVALID, and ResolveCompanyID().

bool AICompany::SetAutoRenewMoney | ( | uint32 | money | ) | `[static]`

Set the minimum money needed to autorenew an engine for your company.

Parameters:

  | money | The new minimum required money for autorenew to work.

Returns:
  True if autorenew money has been modified.

Definition at line 203 of file ai_company.cpp.

References CMD_CHANGE_COMPANY_SETTING, AIObject::DoCommand(), and GetCompanySettingIndex().

uint32 AICompany::GetAutoRenewMoney | ( | CompanyID | company | ) | `[static]`

Return the minimum money needed to autorenew an engine for a company.

Parameters:

  | company | The company to get the autorenew money of.

Precondition:
  ResolveCompanyID(company) != COMPANY_INVALID.

Returns:
  The minimum required money for autorenew to work.

Definition at line 208 of file ai_company.cpp.

References COMPANY_INVALID, and ResolveCompanyID().

The documentation for this class was generated from the following files:

- src/ai/api/ai_company.hpp
- src/ai/api/ai_company.cpp