# 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 "command_type.h"
    00024 #include "table/strings.h"
    00025
    00026 struct CompanyEconomyEntry {
    00027   Money income;
    00028   Money expenses;
    00029   int32 delivered_cargo;
    00030   int32 performance_history;
    00031   Money company_value;
    00032 };
    00033
    00034 typedef Pool<Company, CompanyByte, 1, MAX_COMPANIES> CompanyPool;
    00035 extern CompanyPool _company_pool;
    00036
    00037
    00039 struct CompanyProperties {
    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
    00056   RailTypes avail_railtypes;
    00057
    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
    00069   byte quarters_of_bankruptcy;
    00070   CompanyMask bankrupt_asked;
    00071   int16 bankrupt_timeout;
    00072   Money bankrupt_value;
    00073
    00074   uint32 terraform_limit;
    00075   uint32 clear_limit;
    00076
    00081   bool is_ai;
    00082
    00083   Money yearly_expenses[3][EXPENSES_END];
    00084   CompanyEconomyEntry cur_economy;
    00085   CompanyEconomyEntry old_economy[MAX_HISTORY_QUARTERS];
    00086   byte num_valid_stat_ent;
    00087
    00088   CompanyProperties() : name(NULL), president_name(NULL) {}
    00089
    00090   ~CompanyProperties()
    00091   {
    00092     free(this->name);
    00093     free(this->president_name);
    00094   }
    00095 };
    00096
    00097 struct Company : CompanyPool::PoolItem<&_company_pool>, CompanyProperties {
    00098   Company(uint16 name_1 = 0, bool is_ai = false);
    00099   ~Company();
    00100
    00101   Livery livery[LS_END];
    00102   RoadTypes avail_roadtypes;
    00103
    00104   class AIInstance *ai_instance;
    00105   class AIInfo *ai_info;
    00106
    00107   EngineRenewList engine_renew_list;
    00108   CompanySettings settings;
    00109   uint16 *num_engines;
    00110
    00116   static FORCEINLINE bool IsValidAiID(size_t index)
    00117   {
    00118     const Company *c = Company::GetIfValid(index);
    00119     return c != NULL && c->is_ai;
    00120   }
    00121
    00128   static FORCEINLINE bool IsValidHumanID(size_t index)
    00129   {
    00130     const Company *c = Company::GetIfValid(index);
    00131     return c != NULL && !c->is_ai;
    00132   }
    00133
    00141   static FORCEINLINE bool IsHumanID(size_t index)
    00142   {
    00143     return !Company::Get(index)->is_ai;
    00144   }
    00145
    00146   static void PostDestructor(size_t index);
    00147 };
    00148
    00149 struct CompanyProfile {
    00150   char president_name[MAX_LENGTH_PRESIDENT_NAME_CHARS];
    00151   char company_name[MAX_LENGTH_COMPANY_NAME_CHARS];
    00152   CompanyManagerFace face;
    00153   Livery livery[LS_END];
    00154
    00155   StringID error_id;
    00156
    00157   CompanyProfile()
    00158   {
    00159     this->error_id = STR_NULL;
    00160   }
    00161
    00162   CompanyProfile(StringID err)
    00163   {
    00164     this->error_id = err;
    00165   }
    00166 };
    00167
    00168 CompanyProfile GetCompanyProfile (const Company&);
    00169 StringID       SetCompanyProfile (const CompanyProfile&);
    00170 StringID       CompanyLoadProfile(CompanyProfile&);
    00171 StringID       CompanySaveProfile(const CompanyProfile&);
    00172
    00173 #define FOR_ALL_COMPANIES_FROM(var, start) FOR_ALL_ITEMS_FROM(Company, company_index, var, start)
    00174 #define FOR_ALL_COMPANIES(var) FOR_ALL_COMPANIES_FROM(var, 0)
    00175
    00176 Money CalculateCompanyValue(const Company *c, bool including_loan = true);
    00177
    00178 extern uint _next_competitor_start;
    00179 extern uint _cur_company_tick_index;
    00180
    00181 #endif /* COMPANY_BASE_H */