company_base.h

Go to the documentation of this file.
00001 /* $Id: company_base.h 18908 2010-01-24 11:05:26Z rubidium $ */
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 
00036 struct Company : CompanyPool::PoolItem<&_company_pool> {
00037   Company(uint16 name_1 = 0, bool is_ai = false);
00038   ~Company();
00039 
00040   uint32 name_2;
00041   uint16 name_1;
00042   char *name;
00043 
00044   uint16 president_name_1;
00045   uint32 president_name_2;
00046   char *president_name;
00047 
00048   CompanyManagerFace face;
00049 
00050   Money money;
00051   byte money_fraction;
00052   Money current_loan;
00053 
00054   byte colour;
00055   Livery livery[LS_END];
00056   RailTypes avail_railtypes;
00057   RoadTypes avail_roadtypes;
00058   byte block_preview;
00059 
00060   uint32 cargo_types; 
00061 
00062   TileIndex location_of_HQ; 
00063   TileIndex last_build_coordinate;
00064 
00065   OwnerByte share_owners[4];
00066 
00067   Year inaugurated_year;
00068   byte num_valid_stat_ent;
00069 
00070   byte quarters_of_bankruptcy;
00071   CompanyMask bankrupt_asked; 
00072   int16 bankrupt_timeout;
00073   Money bankrupt_value;
00074 
00075   bool is_ai;
00076 
00077   class AIInstance *ai_instance;
00078   class AIInfo *ai_info;
00079 
00080   Money yearly_expenses[3][EXPENSES_END];
00081   CompanyEconomyEntry cur_economy;
00082   CompanyEconomyEntry old_economy[MAX_HISTORY_MONTHS];
00083   EngineRenewList engine_renew_list; 
00084   CompanySettings settings;          
00085   uint16 *num_engines; 
00086 
00087   static FORCEINLINE bool IsValidAiID(size_t index)
00088   {
00089     const Company *c = Company::GetIfValid(index);
00090     return c != NULL && c->is_ai;
00091   }
00092 
00093   static FORCEINLINE bool IsValidHumanID(size_t index)
00094   {
00095     const Company *c = Company::GetIfValid(index);
00096     return c != NULL && !c->is_ai;
00097   }
00098 
00099   static FORCEINLINE bool IsHumanID(size_t index)
00100   {
00101     return !Company::Get(index)->is_ai;
00102   }
00103 
00104   static void PostDestructor(size_t index);
00105 };
00106 
00107 #define FOR_ALL_COMPANIES_FROM(var, start) FOR_ALL_ITEMS_FROM(Company, company_index, var, start)
00108 #define FOR_ALL_COMPANIES(var) FOR_ALL_COMPANIES_FROM(var, 0)
00109 
00110 Money CalculateCompanyValue(const Company *c, bool including_loan = true);
00111 
00112 extern uint _next_competitor_start;
00113 extern uint _cur_company_tick_index;
00114 
00115 #endif /* COMPANY_BASE_H */

Generated on Sat Jul 31 21:37:45 2010 for OpenTTD by  doxygen 1.6.1