# company_base.h

Go to the documentation of this file.

    00001 /* $Id: company_base.h 15257 2009-01-24 15:31:48Z smatz $ */
    00002
    00005 #ifndef COMPANY_BASE_H
    00006 #define COMPANY_BASE_H
    00007
    00008 #include "company_type.h"
    00009 #include "oldpool.h"
    00010 #include "road_type.h"
    00011 #include "rail_type.h"
    00012 #include "date_type.h"
    00013 #include "engine_type.h"
    00014 #include "livery.h"
    00015 #include "autoreplace_type.h"
    00016 #include "economy_type.h"
    00017 #include "tile_type.h"
    00018
    00019 struct CompanyEconomyEntry {
    00020   Money income;
    00021   Money expenses;
    00022   int32 delivered_cargo;
    00023   int32 performance_history;
    00024   Money company_value;
    00025 };
    00026
    00027 /* The third parameter and the number after >> MUST be the same,
    00028  * otherwise more (or less) companies will be allowed to be
    00029  * created than what MAX_COMPANIES specifies!
    00030  */
    00031 DECLARE_OLD_POOL(Company, Company, 1, (MAX_COMPANIES + 1) >> 1)
    00032
    00033 struct Company : PoolItem<Company, CompanyByte, &_Company_pool> {
    00034   Company(uint16 name_1 = 0, bool is_ai = false);
    00035   ~Company();
    00036
    00037   uint32 name_2;
    00038   uint16 name_1;
    00039   char *name;
    00040
    00041   uint16 president_name_1;
    00042   uint32 president_name_2;
    00043   char *president_name;
    00044
    00045   CompanyManagerFace face;
    00046
    00047   Money money;
    00048   byte money_fraction;
    00049   Money current_loan;
    00050
    00051   byte colour;
    00052   Livery livery[LS_END];
    00053   RailTypes avail_railtypes;
    00054   RoadTypes avail_roadtypes;
    00055   byte block_preview;
    00056
    00057   uint32 cargo_types;
    00058
    00059   TileIndex location_of_HQ;
    00060   TileIndex last_build_coordinate;
    00061
    00062   OwnerByte share_owners[4];
    00063
    00064   Year inaugurated_year;
    00065   byte num_valid_stat_ent;
    00066
    00067   byte quarters_of_bankrupcy;
    00068   CompanyMask bankrupt_asked;
    00069   int16 bankrupt_timeout;
    00070   Money bankrupt_value;
    00071
    00072   bool is_ai;
    00073
    00074   class AIInstance *ai_instance;
    00075   class AIInfo *ai_info;
    00076
    00077   Money yearly_expenses[3][EXPENSES_END];
    00078   CompanyEconomyEntry cur_economy;
    00079   CompanyEconomyEntry old_economy[24];
    00080   EngineRenewList engine_renew_list;
    00081   bool engine_renew;
    00082   bool renew_keep_length;
    00083   int16 engine_renew_months;
    00084   uint32 engine_renew_money;
    00085   uint16 *num_engines;
    00086
    00087   inline bool IsValid() const { return this->name_1 != 0; }
    00088 };
    00089
    00090 static inline bool IsValidCompanyID(CompanyID company)
    00091 {
    00092   return company < MAX_COMPANIES && (uint)company < GetCompanyPoolSize() && GetCompany(company)->IsValid();
    00093 }
    00094
    00095 #define FOR_ALL_COMPANIES_FROM(d, start) for (d = GetCompany(start); d != NULL; d = (d->index + 1U < GetCompanyPoolSize()) ? GetCompany(d->index + 1U) : NULL) if (d->IsValid())
    00096 #define FOR_ALL_COMPANIES(d) FOR_ALL_COMPANIES_FROM(d, 0)
    00097
    00098 static inline byte ActiveCompanyCount()
    00099 {
    00100   const Company *c;
    00101   byte count = 0;
    00102
    00103   FOR_ALL_COMPANIES(c) count++;
    00104
    00105   return count;
    00106 }
    00107
    00108 Money CalculateCompanyValue(const Company *c);
    00109
    00110 #endif /* COMPANY_BASE_H */