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 #include "group.h"
00024 
00025 struct CompanyEconomyEntry {
00026   Money income;
00027   Money expenses;
00028   int32 delivered_cargo;
00029   int32 performance_history; 
00030   Money company_value;
00031 };
00032 
00033 struct CompanyInfrastructure {
00034   uint32 road[ROADTYPE_END]; 
00035   uint32 signal;             
00036   uint32 rail[RAILTYPE_END]; 
00037   uint32 water;              
00038   uint32 station;            
00039   uint32 airport;            
00040 };
00041 
00042 typedef Pool<Company, CompanyByte, 1, MAX_COMPANIES> CompanyPool;
00043 extern CompanyPool _company_pool;
00044 
00045 
00047 struct CompanyProperties {
00048   uint32 name_2;                   
00049   uint16 name_1;                   
00050   char *name;                      
00051 
00052   uint16 president_name_1;         
00053   uint32 president_name_2;         
00054   char *president_name;            
00055 
00056   CompanyManagerFace face;         
00057 
00058   Money money;                     
00059   byte money_fraction;             
00060   Money current_loan;              
00061 
00062   byte colour;                     
00063 
00064   RailTypes avail_railtypes;       
00065 
00066   byte block_preview;              
00067 
00068   uint32 cargo_types;              
00069 
00070   TileIndex location_of_HQ;        
00071   TileIndex last_build_coordinate; 
00072 
00073   OwnerByte share_owners[4];       
00074 
00075   Year inaugurated_year;           
00076 
00077   byte quarters_of_bankruptcy;     
00078   CompanyMask bankrupt_asked;      
00079   int16 bankrupt_timeout;          
00080   Money bankrupt_value;
00081 
00082   uint32 terraform_limit;          
00083   uint32 clear_limit;              
00084 
00089   bool is_ai;
00090 
00091   Money yearly_expenses[3][EXPENSES_END];                
00092   CompanyEconomyEntry cur_economy;                       
00093   CompanyEconomyEntry old_economy[MAX_HISTORY_QUARTERS]; 
00094   byte num_valid_stat_ent;                               
00095 
00096   CompanyProperties() : name(NULL), president_name(NULL) {}
00097 
00098   ~CompanyProperties()
00099   {
00100     free(this->name);
00101     free(this->president_name);
00102   }
00103 };
00104 
00105 struct Company : CompanyPool::PoolItem<&_company_pool>, CompanyProperties {
00106   Company(uint16 name_1 = 0, bool is_ai = false);
00107   ~Company();
00108 
00109   Livery livery[LS_END];
00110   RoadTypes avail_roadtypes;         
00111 
00112   class AIInstance *ai_instance;
00113   class AIInfo *ai_info;
00114 
00115   EngineRenewList engine_renew_list; 
00116   CompanySettings settings;          
00117   GroupStatistics group_all[VEH_COMPANY_END];      
00118   GroupStatistics group_default[VEH_COMPANY_END];  
00119 
00120   CompanyInfrastructure infrastructure; 
00121 
00127   static FORCEINLINE bool IsValidAiID(size_t index)
00128   {
00129     const Company *c = Company::GetIfValid(index);
00130     return c != NULL && c->is_ai;
00131   }
00132 
00139   static FORCEINLINE bool IsValidHumanID(size_t index)
00140   {
00141     const Company *c = Company::GetIfValid(index);
00142     return c != NULL && !c->is_ai;
00143   }
00144 
00152   static FORCEINLINE bool IsHumanID(size_t index)
00153   {
00154     return !Company::Get(index)->is_ai;
00155   }
00156 
00157   static void PostDestructor(size_t index);
00158 };
00159 
00160 #define FOR_ALL_COMPANIES_FROM(var, start) FOR_ALL_ITEMS_FROM(Company, company_index, var, start)
00161 #define FOR_ALL_COMPANIES(var) FOR_ALL_COMPANIES_FROM(var, 0)
00162 
00163 Money CalculateCompanyValue(const Company *c, bool including_loan = true);
00164 
00165 extern uint _next_competitor_start;
00166 extern uint _cur_company_tick_index;
00167 
00168 #endif /* COMPANY_BASE_H */