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