2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2008-09-30 20:39:50 +00:00
|
|
|
/** @file company_base.h Definition of stuff that is very close to a company, like the company struct itself. */
|
2007-03-21 17:42:43 +00:00
|
|
|
|
2008-09-30 20:39:50 +00:00
|
|
|
#ifndef COMPANY_BASE_H
|
|
|
|
#define COMPANY_BASE_H
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-05-22 15:39:22 +00:00
|
|
|
#include "core/pool_type.hpp"
|
2008-01-09 21:05:03 +00:00
|
|
|
#include "road_type.h"
|
|
|
|
#include "rail_type.h"
|
2006-09-15 12:27:00 +00:00
|
|
|
#include "livery.h"
|
2008-01-07 09:19:53 +00:00
|
|
|
#include "autoreplace_type.h"
|
2008-01-09 21:27:39 +00:00
|
|
|
#include "economy_type.h"
|
|
|
|
#include "tile_type.h"
|
2009-05-15 23:55:06 +00:00
|
|
|
#include "settings_type.h"
|
2011-10-03 17:22:56 +00:00
|
|
|
#include "group.h"
|
2004-08-20 09:32:32 +00:00
|
|
|
|
2008-09-30 20:39:50 +00:00
|
|
|
struct CompanyEconomyEntry {
|
2007-06-18 21:44:47 +00:00
|
|
|
Money income;
|
|
|
|
Money expenses;
|
2004-08-09 17:04:08 +00:00
|
|
|
int32 delivered_cargo;
|
2008-09-30 20:39:50 +00:00
|
|
|
int32 performance_history; ///< company score (scale 0-1000)
|
2007-06-18 22:49:55 +00:00
|
|
|
Money company_value;
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-05-22 15:13:50 +00:00
|
|
|
typedef Pool<Company, CompanyByte, 1, MAX_COMPANIES> CompanyPool;
|
|
|
|
extern CompanyPool _company_pool;
|
2008-07-18 16:40:29 +00:00
|
|
|
|
2009-05-22 15:13:50 +00:00
|
|
|
|
2010-06-13 14:15:11 +00:00
|
|
|
/** Statically loadable part of Company pool item */
|
|
|
|
struct CompanyProperties {
|
2010-08-02 20:37:32 +00:00
|
|
|
uint32 name_2; ///< Parameter of #name_1.
|
2010-08-02 20:47:27 +00:00
|
|
|
uint16 name_1; ///< Name of the company if the user did not change it.
|
2010-08-02 20:37:32 +00:00
|
|
|
char *name; ///< Name of the company if the user changed it.
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2010-08-02 20:47:27 +00:00
|
|
|
uint16 president_name_1; ///< Name of the president if the user did not change it.
|
2010-08-02 20:37:32 +00:00
|
|
|
uint32 president_name_2; ///< Parameter of #president_name_1
|
|
|
|
char *president_name; ///< Name of the president if the user changed it.
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2010-08-02 20:32:39 +00:00
|
|
|
CompanyManagerFace face; ///< Face description of the president.
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2010-08-02 20:37:32 +00:00
|
|
|
Money money; ///< Money owned by the company.
|
2010-08-02 20:47:27 +00:00
|
|
|
byte money_fraction; ///< Fraction of money of the company, too small to represent in #money.
|
2010-08-02 20:32:39 +00:00
|
|
|
Money current_loan; ///< Amount of money borrowed from the bank.
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2010-08-02 20:32:39 +00:00
|
|
|
byte colour; ///< Company colour.
|
2010-06-13 14:15:11 +00:00
|
|
|
|
2010-08-02 20:32:39 +00:00
|
|
|
RailTypes avail_railtypes; ///< Rail types available to the company.
|
2010-06-13 14:15:11 +00:00
|
|
|
|
2011-02-14 19:52:26 +00:00
|
|
|
byte block_preview; ///< Number of quarters that the company is not allowed to get new exclusive engine previews (see CompaniesGenStatistics).
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2010-08-02 20:47:27 +00:00
|
|
|
uint32 cargo_types; ///< Which cargo types were transported the last year.
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2010-08-02 20:47:27 +00:00
|
|
|
TileIndex location_of_HQ; ///< Northern tile of HQ; #INVALID_TILE when there is none.
|
2010-08-02 20:32:39 +00:00
|
|
|
TileIndex last_build_coordinate; ///< Coordinate of the last build thing by this company.
|
2004-08-31 16:12:52 +00:00
|
|
|
|
2010-08-02 20:37:32 +00:00
|
|
|
OwnerByte share_owners[4]; ///< Owners of the 4 shares of the company. #INVALID_OWNER if nobody has bought them yet.
|
2004-08-31 16:12:52 +00:00
|
|
|
|
2010-08-02 20:37:32 +00:00
|
|
|
Year inaugurated_year; ///< Year of starting the company.
|
2004-08-31 16:12:52 +00:00
|
|
|
|
2010-08-02 20:32:39 +00:00
|
|
|
byte quarters_of_bankruptcy; ///< Number of quarters (a quarter is 3 months) that the company has a negative balance.
|
2010-08-02 20:37:32 +00:00
|
|
|
CompanyMask bankrupt_asked; ///< which companies were asked about buying it?
|
2010-08-02 20:32:39 +00:00
|
|
|
int16 bankrupt_timeout; ///< If bigger than \c 0, amount of time to wait for an answer on an offer to buy this company.
|
2007-06-18 21:44:47 +00:00
|
|
|
Money bankrupt_value;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2011-01-04 22:50:09 +00:00
|
|
|
uint32 terraform_limit; ///< Amount of tileheights we can (still) terraform (times 65536).
|
|
|
|
uint32 clear_limit; ///< Amount of tiles we can (still) clear (times 65536).
|
|
|
|
|
2010-08-02 20:47:27 +00:00
|
|
|
/**
|
|
|
|
* If \c true, the company is (also) controlled by the computer (a NoAI program).
|
|
|
|
* @note It is possible that the user is also participating in such a company.
|
|
|
|
*/
|
|
|
|
bool is_ai;
|
2009-01-12 17:11:45 +00:00
|
|
|
|
2011-05-19 21:03:23 +00:00
|
|
|
Money yearly_expenses[3][EXPENSES_END]; ///< Expenses of the company for the last three years, in every #Expenses category.
|
|
|
|
CompanyEconomyEntry cur_economy; ///< Economic data of the company of this quarter.
|
|
|
|
CompanyEconomyEntry old_economy[MAX_HISTORY_QUARTERS]; ///< Economic data of the company of the last #MAX_HISTORY_QUARTERS quarters.
|
|
|
|
byte num_valid_stat_ent; ///< Number of valid statistical entries in #old_economy.
|
2010-06-13 14:15:11 +00:00
|
|
|
|
|
|
|
CompanyProperties() : name(NULL), president_name(NULL) {}
|
|
|
|
|
|
|
|
~CompanyProperties()
|
|
|
|
{
|
|
|
|
free(this->name);
|
|
|
|
free(this->president_name);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Company : CompanyPool::PoolItem<&_company_pool>, CompanyProperties {
|
|
|
|
Company(uint16 name_1 = 0, bool is_ai = false);
|
|
|
|
~Company();
|
|
|
|
|
|
|
|
Livery livery[LS_END];
|
2010-08-02 20:32:39 +00:00
|
|
|
RoadTypes avail_roadtypes; ///< Road types available to this company.
|
2010-06-13 14:15:11 +00:00
|
|
|
|
|
|
|
class AIInstance *ai_instance;
|
|
|
|
class AIInfo *ai_info;
|
|
|
|
|
2010-08-02 20:32:39 +00:00
|
|
|
EngineRenewList engine_renew_list; ///< Engine renewals of this company.
|
2009-05-15 23:55:06 +00:00
|
|
|
CompanySettings settings; ///< settings specific for each company
|
2011-10-03 17:23:41 +00:00
|
|
|
GroupStatistics group_all[VEH_COMPANY_END]; ///< NOSAVE: Statistics for the ALL_GROUP group.
|
2011-10-03 17:22:56 +00:00
|
|
|
GroupStatistics group_default[VEH_COMPANY_END]; ///< NOSAVE: Statistics for the DEFAULT_GROUP group.
|
2009-06-10 22:05:01 +00:00
|
|
|
|
2010-08-01 17:45:53 +00:00
|
|
|
/**
|
|
|
|
* Is this company a valid company, controlled by the computer (a NoAI program)?
|
|
|
|
* @param index Index in the pool.
|
|
|
|
* @return \c true if it is a valid, computer controlled company, else \c false.
|
|
|
|
*/
|
2009-06-10 22:05:01 +00:00
|
|
|
static FORCEINLINE bool IsValidAiID(size_t index)
|
|
|
|
{
|
2009-06-23 12:11:35 +00:00
|
|
|
const Company *c = Company::GetIfValid(index);
|
2009-06-10 22:05:01 +00:00
|
|
|
return c != NULL && c->is_ai;
|
|
|
|
}
|
|
|
|
|
2010-08-01 17:45:53 +00:00
|
|
|
/**
|
2010-08-02 20:47:27 +00:00
|
|
|
* Is this company a valid company, not controlled by a NoAI program?
|
2010-08-01 17:45:53 +00:00
|
|
|
* @param index Index in the pool.
|
|
|
|
* @return \c true if it is a valid, human controlled company, else \c false.
|
|
|
|
* @note If you know that \a index refers to a valid company, you can use #IsHumanID() instead.
|
|
|
|
*/
|
2009-06-10 22:05:01 +00:00
|
|
|
static FORCEINLINE bool IsValidHumanID(size_t index)
|
|
|
|
{
|
2009-06-23 12:11:35 +00:00
|
|
|
const Company *c = Company::GetIfValid(index);
|
2009-06-10 22:05:01 +00:00
|
|
|
return c != NULL && !c->is_ai;
|
|
|
|
}
|
2009-06-23 12:11:35 +00:00
|
|
|
|
2010-08-01 17:45:53 +00:00
|
|
|
/**
|
2010-08-02 20:47:27 +00:00
|
|
|
* Is this company a company not controlled by a NoAI program?
|
2010-08-01 17:45:53 +00:00
|
|
|
* @param index Index in the pool.
|
|
|
|
* @return \c true if it is a human controlled company, else \c false.
|
|
|
|
* @pre \a index must be a valid CompanyID.
|
|
|
|
* @note If you don't know whether \a index refers to a valid company, you should use #IsValidHumanID() instead.
|
|
|
|
*/
|
2009-06-23 12:11:35 +00:00
|
|
|
static FORCEINLINE bool IsHumanID(size_t index)
|
|
|
|
{
|
|
|
|
return !Company::Get(index)->is_ai;
|
|
|
|
}
|
2009-09-08 12:27:27 +00:00
|
|
|
|
|
|
|
static void PostDestructor(size_t index);
|
2009-05-17 01:00:56 +00:00
|
|
|
};
|
2008-07-18 16:40:29 +00:00
|
|
|
|
2009-05-22 14:23:36 +00:00
|
|
|
#define FOR_ALL_COMPANIES_FROM(var, start) FOR_ALL_ITEMS_FROM(Company, company_index, var, start)
|
|
|
|
#define FOR_ALL_COMPANIES(var) FOR_ALL_COMPANIES_FROM(var, 0)
|
2008-07-18 16:40:29 +00:00
|
|
|
|
2010-01-24 11:05:26 +00:00
|
|
|
Money CalculateCompanyValue(const Company *c, bool including_loan = true);
|
2006-09-15 12:27:00 +00:00
|
|
|
|
2009-02-25 21:45:14 +00:00
|
|
|
extern uint _next_competitor_start;
|
|
|
|
extern uint _cur_company_tick_index;
|
|
|
|
|
2008-09-30 20:39:50 +00:00
|
|
|
#endif /* COMPANY_BASE_H */
|