# company_base.h

Go to the documentation of this file.

    00001 /* $Id$ */
    00002
    00003 /*
    00004  * This file is part of OpenTTD.
    00005  * 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.
    00006  * 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.
    00007  * 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/>.
    00008  */
    00009
    00012 #ifndef COMPANY_BASE_H
    00013 #define COMPANY_BASE_H
    00014
    00015 #include "core/pool_type.hpp"
    00016 #include "road_type.h"
    00017 #include "rail_type.h"
    00018 #include "livery.h"
    00019 #include "autoreplace_type.h"
    00020 #include "economy_type.h"
    00021 #include "tile_type.h"
    00022 #include "settings_type.h"
    00023
    00024 struct CompanyEconomyEntry {
    00025   Money income;
    00026   Money expenses;
    00027   int32 delivered_cargo;
    00028   int32 performance_history;
    00029   Money company_value;
    00030 };
    00031
    00032 typedef Pool<Company, CompanyByte, 1, MAX_COMPANIES> CompanyPool;
    00033 extern CompanyPool _company_pool;
    00034
    00035
    00037 struct CompanyProperties {
    00038   uint32 name_2;
    00039   uint16 name_1;
    00040   char *name;
    00041
    00042   uint16 president_name_1;
    00043   uint32 president_name_2;
    00044   char *president_name;
    00045
    00046   CompanyManagerFace face;
    00047
    00048   Money money;
    00049   byte money_fraction;
    00050   Money current_loan;
    00051
    00052   byte colour;
    00053
    00054   RailTypes avail_railtypes;
    00055
    00056   byte block_preview;
    00057
    00058   uint32 cargo_types;
    00059
    00060   TileIndex location_of_HQ;
    00061   TileIndex last_build_coordinate;
    00062
    00063   OwnerByte share_owners[4];
    00064
    00065   Year inaugurated_year;
    00066
    00067   byte quarters_of_bankruptcy;
    00068   CompanyMask bankrupt_asked;
    00069   int16 bankrupt_timeout;
    00070   Money bankrupt_value;
    00071
    00072   uint32 terraform_limit;
    00073   uint32 clear_limit;
    00074
    00079   bool is_ai;
    00080
    00081   Money yearly_expenses[3][EXPENSES_END];
    00082   CompanyEconomyEntry cur_economy;
    00083   CompanyEconomyEntry old_economy[MAX_HISTORY_MONTHS];
    00084   byte num_valid_stat_ent;
    00085
    00086   CompanyProperties() : name(NULL), president_name(NULL) {}
    00087
    00088   ~CompanyProperties()
    00089   {
    00090     free(this->name);
    00091     free(this->president_name);
    00092   }
    00093 };
    00094
    00095 struct Company : CompanyPool::PoolItem<&_company_pool>, CompanyProperties {
    00096   Company(uint16 name_1 = 0, bool is_ai = false);
    00097   ~Company();
    00098
    00099   Livery livery[LS_END];
    00100   RoadTypes avail_roadtypes;
    00101
    00102   class AIInstance *ai_instance;
    00103   class AIInfo *ai_info;
    00104
    00105   EngineRenewList engine_renew_list;
    00106   CompanySettings settings;
    00107   uint16 *num_engines;
    00108
    00114   static FORCEINLINE bool IsValidAiID(size_t index)
    00115   {
    00116     const Company *c = Company::GetIfValid(index);
    00117     return c != NULL && c->is_ai;
    00118   }
    00119
    00126   static FORCEINLINE bool IsValidHumanID(size_t index)
    00127   {
    00128     const Company *c = Company::GetIfValid(index);
    00129     return c != NULL && !c->is_ai;
    00130   }
    00131
    00139   static FORCEINLINE bool IsHumanID(size_t index)
    00140   {
    00141     return !Company::Get(index)->is_ai;
    00142   }
    00143
    00144   static void PostDestructor(size_t index);
    00145 };
    00146
    00147 #define FOR_ALL_COMPANIES_FROM(var, start) FOR_ALL_ITEMS_FROM(Company, company_index, var, start)
    00148 #define FOR_ALL_COMPANIES(var) FOR_ALL_COMPANIES_FROM(var, 0)
    00149
    00150 Money CalculateCompanyValue(const Company *c, bool including_loan = true);
    00151
    00152 extern uint _next_competitor_start;
    00153 extern uint _cur_company_tick_index;
    00154
    00155 #endif /* COMPANY_BASE_H */