diff options
author | frosch <frosch@openttd.org> | 2010-06-13 14:15:11 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2010-06-13 14:15:11 +0000 |
commit | e95518c8e9e27d2f208ba6434d3db061616d1bcd (patch) | |
tree | 0796ad27870458ef7753e6ab3548882a34d51589 /src | |
parent | 0270ca846eebab033e9595687a11c0f2000bb9a2 (diff) | |
download | openttd-e95518c8e9e27d2f208ba6434d3db061616d1bcd.tar.xz |
(svn r19979) -Codechange: Separate static loadable fields from Company into separate struct.
Diffstat (limited to 'src')
-rw-r--r-- | src/company_base.h | 33 | ||||
-rw-r--r-- | src/company_cmd.cpp | 10 | ||||
-rw-r--r-- | src/saveload/company_sl.cpp | 75 |
3 files changed, 68 insertions, 50 deletions
diff --git a/src/company_base.h b/src/company_base.h index 16fc622c1..e06bca433 100644 --- a/src/company_base.h +++ b/src/company_base.h @@ -33,10 +33,8 @@ typedef Pool<Company, CompanyByte, 1, MAX_COMPANIES> CompanyPool; extern CompanyPool _company_pool; -struct Company : CompanyPool::PoolItem<&_company_pool> { - Company(uint16 name_1 = 0, bool is_ai = false); - ~Company(); - +/** Statically loadable part of Company pool item */ +struct CompanyProperties { uint32 name_2; uint16 name_1; char *name; @@ -52,9 +50,9 @@ struct Company : CompanyPool::PoolItem<&_company_pool> { Money current_loan; byte colour; - Livery livery[LS_END]; + RailTypes avail_railtypes; - RoadTypes avail_roadtypes; + byte block_preview; uint32 cargo_types; ///< which cargo types were transported the last year @@ -74,12 +72,29 @@ struct Company : CompanyPool::PoolItem<&_company_pool> { bool is_ai; - class AIInstance *ai_instance; - class AIInfo *ai_info; - Money yearly_expenses[3][EXPENSES_END]; CompanyEconomyEntry cur_economy; CompanyEconomyEntry old_economy[MAX_HISTORY_MONTHS]; + + CompanyProperties() : name(NULL), president_name(NULL) {} + + ~CompanyProperties() + { + free(this->name); + free(this->president_name); + } +}; + +struct Company : CompanyPool::PoolItem<&_company_pool>, CompanyProperties { + Company(uint16 name_1 = 0, bool is_ai = false); + ~Company(); + + Livery livery[LS_END]; + RoadTypes avail_roadtypes; + + class AIInstance *ai_instance; + class AIInfo *ai_info; + EngineRenewList engine_renew_list; ///< Defined later CompanySettings settings; ///< settings specific for each company uint16 *num_engines; ///< caches the number of engines of each type the company owns (no need to save this) diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp index fe3dc29a4..34def7f36 100644 --- a/src/company_cmd.cpp +++ b/src/company_cmd.cpp @@ -50,19 +50,17 @@ uint _cur_company_tick_index; ///< used to generate a name for one c CompanyPool _company_pool("Company"); INSTANTIATE_POOL_METHODS(Company) -Company::Company(uint16 name_1, bool is_ai) : - name_1(name_1), - location_of_HQ(INVALID_TILE), - is_ai(is_ai) +Company::Company(uint16 name_1, bool is_ai) { + this->name_1 = name_1; + this->location_of_HQ = INVALID_TILE; + this->is_ai = is_ai; for (uint j = 0; j < 4; j++) this->share_owners[j] = COMPANY_SPECTATOR; InvalidateWindowData(WC_PERFORMANCE_DETAIL, 0, INVALID_COMPANY); } Company::~Company() { - free(this->name); - free(this->president_name); free(this->num_engines); if (CleaningPool()) return; diff --git a/src/saveload/company_sl.cpp b/src/saveload/company_sl.cpp index fd0e8aaf2..1a13fb9b5 100644 --- a/src/saveload/company_sl.cpp +++ b/src/saveload/company_sl.cpp @@ -88,56 +88,60 @@ CompanyManagerFace ConvertFromOldCompanyManagerFace(uint32 face) /* Save/load of companies */ static const SaveLoad _company_desc[] = { - SLE_VAR(Company, name_2, SLE_UINT32), - SLE_VAR(Company, name_1, SLE_STRINGID), - SLE_CONDSTR(Company, name, SLE_STR, 0, 84, SL_MAX_VERSION), + SLE_VAR(CompanyProperties, name_2, SLE_UINT32), + SLE_VAR(CompanyProperties, name_1, SLE_STRINGID), + SLE_CONDSTR(CompanyProperties, name, SLE_STR, 0, 84, SL_MAX_VERSION), - SLE_VAR(Company, president_name_1, SLE_UINT16), - SLE_VAR(Company, president_name_2, SLE_UINT32), - SLE_CONDSTR(Company, president_name, SLE_STR, 0, 84, SL_MAX_VERSION), + SLE_VAR(CompanyProperties, president_name_1, SLE_UINT16), + SLE_VAR(CompanyProperties, president_name_2, SLE_UINT32), + SLE_CONDSTR(CompanyProperties, president_name, SLE_STR, 0, 84, SL_MAX_VERSION), - SLE_VAR(Company, face, SLE_UINT32), + SLE_VAR(CompanyProperties, face, SLE_UINT32), /* money was changed to a 64 bit field in savegame version 1. */ - SLE_CONDVAR(Company, money, SLE_VAR_I64 | SLE_FILE_I32, 0, 0), - SLE_CONDVAR(Company, money, SLE_INT64, 1, SL_MAX_VERSION), + SLE_CONDVAR(CompanyProperties, money, SLE_VAR_I64 | SLE_FILE_I32, 0, 0), + SLE_CONDVAR(CompanyProperties, money, SLE_INT64, 1, SL_MAX_VERSION), - SLE_CONDVAR(Company, current_loan, SLE_VAR_I64 | SLE_FILE_I32, 0, 64), - SLE_CONDVAR(Company, current_loan, SLE_INT64, 65, SL_MAX_VERSION), + SLE_CONDVAR(CompanyProperties, current_loan, SLE_VAR_I64 | SLE_FILE_I32, 0, 64), + SLE_CONDVAR(CompanyProperties, current_loan, SLE_INT64, 65, SL_MAX_VERSION), - SLE_VAR(Company, colour, SLE_UINT8), - SLE_VAR(Company, money_fraction, SLE_UINT8), - SLE_CONDVAR(Company, avail_railtypes, SLE_UINT8, 0, 57), - SLE_VAR(Company, block_preview, SLE_UINT8), + SLE_VAR(CompanyProperties, colour, SLE_UINT8), + SLE_VAR(CompanyProperties, money_fraction, SLE_UINT8), + SLE_CONDVAR(CompanyProperties, avail_railtypes, SLE_UINT8, 0, 57), + SLE_VAR(CompanyProperties, block_preview, SLE_UINT8), - SLE_CONDVAR(Company, cargo_types, SLE_FILE_U16 | SLE_VAR_U32, 0, 93), - SLE_CONDVAR(Company, cargo_types, SLE_UINT32, 94, SL_MAX_VERSION), - SLE_CONDVAR(Company, location_of_HQ, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), - SLE_CONDVAR(Company, location_of_HQ, SLE_UINT32, 6, SL_MAX_VERSION), - SLE_CONDVAR(Company, last_build_coordinate, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), - SLE_CONDVAR(Company, last_build_coordinate, SLE_UINT32, 6, SL_MAX_VERSION), - SLE_CONDVAR(Company, inaugurated_year, SLE_FILE_U8 | SLE_VAR_I32, 0, 30), - SLE_CONDVAR(Company, inaugurated_year, SLE_INT32, 31, SL_MAX_VERSION), + SLE_CONDVAR(CompanyProperties, cargo_types, SLE_FILE_U16 | SLE_VAR_U32, 0, 93), + SLE_CONDVAR(CompanyProperties, cargo_types, SLE_UINT32, 94, SL_MAX_VERSION), + SLE_CONDVAR(CompanyProperties, location_of_HQ, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), + SLE_CONDVAR(CompanyProperties, location_of_HQ, SLE_UINT32, 6, SL_MAX_VERSION), + SLE_CONDVAR(CompanyProperties, last_build_coordinate, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), + SLE_CONDVAR(CompanyProperties, last_build_coordinate, SLE_UINT32, 6, SL_MAX_VERSION), + SLE_CONDVAR(CompanyProperties, inaugurated_year, SLE_FILE_U8 | SLE_VAR_I32, 0, 30), + SLE_CONDVAR(CompanyProperties, inaugurated_year, SLE_INT32, 31, SL_MAX_VERSION), - SLE_ARR(Company, share_owners, SLE_UINT8, 4), + SLE_ARR(CompanyProperties, share_owners, SLE_UINT8, 4), - SLE_VAR(Company, num_valid_stat_ent, SLE_UINT8), + SLE_VAR(CompanyProperties, num_valid_stat_ent, SLE_UINT8), - SLE_VAR(Company, quarters_of_bankruptcy,SLE_UINT8), - SLE_CONDVAR(Company, bankrupt_asked, SLE_FILE_U8 | SLE_VAR_U16, 0, 103), - SLE_CONDVAR(Company, bankrupt_asked, SLE_UINT16, 104, SL_MAX_VERSION), - SLE_VAR(Company, bankrupt_timeout, SLE_INT16), - SLE_CONDVAR(Company, bankrupt_value, SLE_VAR_I64 | SLE_FILE_I32, 0, 64), - SLE_CONDVAR(Company, bankrupt_value, SLE_INT64, 65, SL_MAX_VERSION), + SLE_VAR(CompanyProperties, quarters_of_bankruptcy,SLE_UINT8), + SLE_CONDVAR(CompanyProperties, bankrupt_asked, SLE_FILE_U8 | SLE_VAR_U16, 0, 103), + SLE_CONDVAR(CompanyProperties, bankrupt_asked, SLE_UINT16, 104, SL_MAX_VERSION), + SLE_VAR(CompanyProperties, bankrupt_timeout, SLE_INT16), + SLE_CONDVAR(CompanyProperties, bankrupt_value, SLE_VAR_I64 | SLE_FILE_I32, 0, 64), + SLE_CONDVAR(CompanyProperties, bankrupt_value, SLE_INT64, 65, SL_MAX_VERSION), /* yearly expenses was changed to 64-bit in savegame version 2. */ - SLE_CONDARR(Company, yearly_expenses, SLE_FILE_I32 | SLE_VAR_I64, 3 * 13, 0, 1), - SLE_CONDARR(Company, yearly_expenses, SLE_INT64, 3 * 13, 2, SL_MAX_VERSION), + SLE_CONDARR(CompanyProperties, yearly_expenses, SLE_FILE_I32 | SLE_VAR_I64, 3 * 13, 0, 1), + SLE_CONDARR(CompanyProperties, yearly_expenses, SLE_INT64, 3 * 13, 2, SL_MAX_VERSION), - SLE_CONDVAR(Company, is_ai, SLE_BOOL, 2, SL_MAX_VERSION), + SLE_CONDVAR(CompanyProperties, is_ai, SLE_BOOL, 2, SL_MAX_VERSION), SLE_CONDNULL(1, 107, 111), ///< is_noai SLE_CONDNULL(1, 4, 99), + SLE_END() +}; + +static const SaveLoad _company_settings_desc[] = { /* Engine renewal settings */ SLE_CONDNULL(512, 16, 18), SLE_CONDREF(Company, engine_renew_list, REF_ENGINE_RENEWS, 19, SL_MAX_VERSION), @@ -230,7 +234,8 @@ static void SaveLoad_PLYR(Company *c) { int i; - SlObject(c, _company_desc); + SlObject((CompanyProperties *)c, _company_desc); + SlObject(c, _company_settings_desc); /* Keep backwards compatible for savegames, so load the old AI block */ if (CheckSavegameVersion(107) && c->is_ai) { |