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 "company_type.h"
00016 #include "core/pool_type.hpp"
00017 #include "road_type.h"
00018 #include "rail_type.h"
00019 #include "date_type.h"
00020 #include "engine_type.h"
00021 #include "livery.h"
00022 #include "autoreplace_type.h"
00023 #include "economy_type.h"
00024 #include "tile_type.h"
00025 #include "settings_type.h"
00026 
00027 struct CompanyEconomyEntry {
00028   Money income;
00029   Money expenses;
00030   int32 delivered_cargo;
00031   int32 performance_history; 
00032   Money company_value;
00033 };
00034 
00035 typedef Pool<Company, CompanyByte, 1, MAX_COMPANIES> CompanyPool;
00036 extern CompanyPool _company_pool;
00037 
00038 
00039 struct Company : CompanyPool::PoolItem<&_company_pool> {
00040   Company(uint16 name_1 = 0, bool is_ai = false);
00041   ~Company();
00042 
00043   uint32 name_2;
00044   uint16 name_1;
00045   char *name;
00046 
00047   uint16 president_name_1;
00048   uint32 president_name_2;
00049   char *president_name;
00050 
00051   CompanyManagerFace face;
00052 
00053   Money money;
00054   byte money_fraction;
00055   Money current_loan;
00056 
00057   byte colour;
00058   Livery livery[LS_END];
00059   RailTypes avail_railtypes;
00060   RoadTypes avail_roadtypes;
00061   byte block_preview;
00062 
00063   uint32 cargo_types; 
00064 
00065   TileIndex location_of_HQ; 
00066   TileIndex last_build_coordinate;
00067 
00068   OwnerByte share_owners[4];
00069 
00070   Year inaugurated_year;
00071   byte num_valid_stat_ent;
00072 
00073   byte quarters_of_bankruptcy;
00074   CompanyMask bankrupt_asked; 
00075   int16 bankrupt_timeout;
00076   Money bankrupt_value;
00077 
00078   bool is_ai;
00079 
00080   class AIInstance *ai_instance;
00081   class AIInfo *ai_info;
00082 
00083   Money yearly_expenses[3][EXPENSES_END];
00084   CompanyEconomyEntry cur_economy;
00085   CompanyEconomyEntry old_economy[MAX_HISTORY_MONTHS];
00086   EngineRenewList engine_renew_list; 
00087   CompanySettings settings;          
00088   uint16 *num_engines; 
00089 
00090   static FORCEINLINE bool IsValidAiID(size_t index)
00091   {
00092     const Company *c = Company::GetIfValid(index);
00093     return c != NULL && c->is_ai;
00094   }
00095 
00096   static FORCEINLINE bool IsValidHumanID(size_t index)
00097   {
00098     const Company *c = Company::GetIfValid(index);
00099     return c != NULL && !c->is_ai;
00100   }
00101 
00102   static FORCEINLINE bool IsHumanID(size_t index)
00103   {
00104     return !Company::Get(index)->is_ai;
00105   }
00106 
00107   static void PostDestructor(size_t index);
00108 };
00109 
00110 #define FOR_ALL_COMPANIES_FROM(var, start) FOR_ALL_ITEMS_FROM(Company, company_index, var, start)
00111 #define FOR_ALL_COMPANIES(var) FOR_ALL_COMPANIES_FROM(var, 0)
00112 
00113 Money CalculateCompanyValue(const Company *c);
00114 
00115 extern uint _next_competitor_start;
00116 extern uint _cur_company_tick_index;
00117 
00118 #endif /* COMPANY_BASE_H */

Generated on Wed Dec 30 20:40:01 2009 for OpenTTD by  doxygen 1.5.6