From 7eca4a9b47e5bdf5123be6158c89be8ebeb213d6 Mon Sep 17 00:00:00 2001 From: translators Date: Mon, 25 Jun 2018 19:45:40 +0200 Subject: [PATCH 01/15] Update: Translations from eints french: 5 changes by glx --- src/lang/french.txt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/lang/french.txt b/src/lang/french.txt index 4232e43877..6a361172a9 100644 --- a/src/lang/french.txt +++ b/src/lang/french.txt @@ -882,10 +882,10 @@ STR_NEWS_EXCLUSIVE_RIGHTS_DESCRIPTION :{BIG_FONT}{BLAC # Extra view window STR_EXTRA_VIEW_PORT_TITLE :{WHITE}Vue {COMMA} -STR_EXTRA_VIEW_MOVE_VIEW_TO_MAIN :{BLACK}Copier vers la vue -STR_EXTRA_VIEW_MOVE_VIEW_TO_MAIN_TT :{BLACK}Copier l'emplacement de la vue principale vers cette vue-ci -STR_EXTRA_VIEW_MOVE_MAIN_TO_VIEW :{BLACK}Coller depuis la vue -STR_EXTRA_VIEW_MOVE_MAIN_TO_VIEW_TT :{BLACK}Coller l'emplacement de cette vue-ci vers la vue principale +STR_EXTRA_VIEW_MOVE_VIEW_TO_MAIN :{BLACK}Modifier cette vue +STR_EXTRA_VIEW_MOVE_VIEW_TO_MAIN_TT :{BLACK}Copier l'emplacement de la vue principale vers cette vue +STR_EXTRA_VIEW_MOVE_MAIN_TO_VIEW :{BLACK}Modifier la vue principale +STR_EXTRA_VIEW_MOVE_MAIN_TO_VIEW_TT :{BLACK}Copier l'emplacement de cette vue vers la vue principale # Game options window STR_GAME_OPTIONS_CAPTION :{WHITE}Options @@ -2289,6 +2289,7 @@ STR_LINKGRAPH_LEGEND_CAPTION :{BLACK}Légende STR_LINKGRAPH_LEGEND_ALL :{BLACK}Toute STR_LINKGRAPH_LEGEND_NONE :{BLACK}Aucune STR_LINKGRAPH_LEGEND_SELECT_COMPANIES :{BLACK}Choisir les compagnies à afficher +STR_LINKGRAPH_LEGEND_COMPANY_TOOLTIP :{BLACK}{STRING}{}{COMPANY} # Linkgraph legend window and linkgraph legend in smallmap STR_LINKGRAPH_LEGEND_UNUSED :{TINY_FONT}{BLACK}inutilisé From 11ab3c4ea2f6a6d29efda8c9ba2af04194621ea7 Mon Sep 17 00:00:00 2001 From: PeterN Date: Tue, 26 Jun 2018 13:32:58 +0100 Subject: [PATCH 02/15] Change: Increase cargo type limit to 64. --- src/cargo_type.h | 4 ++-- src/graph_gui.cpp | 10 +++++----- src/saveload/company_sl.cpp | 3 ++- src/saveload/economy_sl.cpp | 2 +- src/saveload/saveload.cpp | 3 ++- src/saveload/station_sl.cpp | 14 +++++++++----- src/saveload/town_sl.cpp | 6 ++++-- src/strings.cpp | 2 +- 8 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/cargo_type.h b/src/cargo_type.h index 402e81c1b2..c84f1f4902 100644 --- a/src/cargo_type.h +++ b/src/cargo_type.h @@ -63,14 +63,14 @@ enum CargoType { CT_PLASTIC = 10, CT_FIZZY_DRINKS = 11, - NUM_CARGO = 32, ///< Maximal number of cargo types in a game. + NUM_CARGO = 64, ///< Maximal number of cargo types in a game. CT_AUTO_REFIT = 0xFD, ///< Automatically choose cargo type when doing auto refitting. CT_NO_REFIT = 0xFE, ///< Do not refit cargo of a vehicle (used in vehicle orders and auto-replace/auto-new). CT_INVALID = 0xFF, ///< Invalid cargo type. }; -typedef uint32 CargoTypes; +typedef uint64 CargoTypes; static const CargoTypes ALL_CARGOTYPES = (CargoTypes)UINT32_MAX; diff --git a/src/graph_gui.cpp b/src/graph_gui.cpp index c12c6ace4d..f4334429fb 100644 --- a/src/graph_gui.cpp +++ b/src/graph_gui.cpp @@ -33,8 +33,8 @@ #include "safeguards.h" /* Bitmasks of company and cargo indices that shouldn't be drawn. */ -static uint _legend_excluded_companies; -static uint _legend_excluded_cargo; +static CompanyMask _legend_excluded_companies; +static CargoTypes _legend_excluded_cargo; /* Apparently these don't play well with enums. */ static const OverflowSafeInt64 INVALID_DATAPOINT(INT64_MAX); // Value used for a datapoint that shouldn't be drawn. @@ -166,14 +166,14 @@ struct ValuesInterval { struct BaseGraphWindow : Window { protected: - static const int GRAPH_MAX_DATASETS = 32; + static const int GRAPH_MAX_DATASETS = 64; static const int GRAPH_AXIS_LINE_COLOUR = PC_BLACK; static const int GRAPH_NUM_MONTHS = 24; ///< Number of months displayed in the graph. static const int MIN_GRAPH_NUM_LINES_Y = 9; ///< Minimal number of horizontal lines to draw. static const int MIN_GRID_PIXEL_SIZE = 20; ///< Minimum distance between graph lines. - uint excluded_data; ///< bitmask of the datasets that shouldn't be displayed. + uint64 excluded_data; ///< bitmask of the datasets that shouldn't be displayed. byte num_dataset; byte num_on_x_axis; byte num_vert_lines; @@ -561,7 +561,7 @@ public: */ void UpdateStatistics(bool initialize) { - uint excluded_companies = _legend_excluded_companies; + CompanyMask excluded_companies = _legend_excluded_companies; /* Exclude the companies which aren't valid */ for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) { diff --git a/src/saveload/company_sl.cpp b/src/saveload/company_sl.cpp index 9a90560610..07d685e92f 100644 --- a/src/saveload/company_sl.cpp +++ b/src/saveload/company_sl.cpp @@ -350,7 +350,8 @@ static const SaveLoad _company_economy_desc[] = { SLE_CONDVAR(CompanyEconomyEntry, company_value, SLE_INT64, 2, SL_MAX_VERSION), SLE_CONDVAR(CompanyEconomyEntry, delivered_cargo[NUM_CARGO - 1], SLE_INT32, 0, 169), - SLE_CONDARR(CompanyEconomyEntry, delivered_cargo, SLE_UINT32, NUM_CARGO, 170, SL_MAX_VERSION), + SLE_CONDARR(CompanyEconomyEntry, delivered_cargo, SLE_UINT32, 32, 170, 198), + SLE_CONDARR(CompanyEconomyEntry, delivered_cargo, SLE_UINT32, NUM_CARGO, 199, SL_MAX_VERSION), SLE_VAR(CompanyEconomyEntry, performance_history, SLE_INT32), SLE_END() diff --git a/src/saveload/economy_sl.cpp b/src/saveload/economy_sl.cpp index dabf120fca..0effb5b2ff 100644 --- a/src/saveload/economy_sl.cpp +++ b/src/saveload/economy_sl.cpp @@ -29,7 +29,7 @@ static void Load_PRIC() /** Cargo payment rates in pre 126 savegames */ static void Load_CAPR() { - uint num_cargo = IsSavegameVersionBefore(55) ? 12 : NUM_CARGO; + uint num_cargo = IsSavegameVersionBefore(55) ? 12 : IsSavegameVersionBefore(199) ? 32 : NUM_CARGO; int vt = IsSavegameVersionBefore(65) ? SLE_FILE_I32 : SLE_FILE_I64; SlArray(NULL, num_cargo, vt | SLE_VAR_NULL); SlArray(NULL, num_cargo, SLE_FILE_U16 | SLE_VAR_NULL); diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp index d06214e234..692f73cf2d 100644 --- a/src/saveload/saveload.cpp +++ b/src/saveload/saveload.cpp @@ -266,8 +266,9 @@ * 196 27778 1.7.x * 197 27978 1.8.x * 198 + * 199 */ -extern const uint16 SAVEGAME_VERSION = 198; ///< Current savegame version of OpenTTD. +extern const uint16 SAVEGAME_VERSION = 199; ///< Current savegame version of OpenTTD. SavegameType _savegame_type; ///< type of savegame we are loading FileToSaveLoad _file_to_saveload; ///< File to save or load in the openttd loop. diff --git a/src/saveload/station_sl.cpp b/src/saveload/station_sl.cpp index 391ba30a8e..f01123da0a 100644 --- a/src/saveload/station_sl.cpp +++ b/src/saveload/station_sl.cpp @@ -329,6 +329,7 @@ static void Load_STNS() _cargo_days = 0; _cargo_feeder_share = 0; + uint num_cargo = IsSavegameVersionBefore(55) ? 12 : IsSavegameVersionBefore(199) ? 32 : NUM_CARGO; int index; while ((index = SlIterateArray()) != -1) { Station *st = new (index) Station(); @@ -337,7 +338,6 @@ static void Load_STNS() _waiting_acceptance = 0; - uint num_cargo = IsSavegameVersionBefore(55) ? 12 : NUM_CARGO; for (CargoID i = 0; i < num_cargo; i++) { GoodsEntry *ge = &st->goods[i]; SlObject(ge, GetGoodsDesc()); @@ -377,10 +377,11 @@ static void Ptrs_STNS() /* Don't run when savegame version is higher than or equal to 123. */ if (!IsSavegameVersionBefore(123)) return; + uint num_cargo = IsSavegameVersionBefore(199) ? 32 : NUM_CARGO; Station *st; FOR_ALL_STATIONS(st) { if (!IsSavegameVersionBefore(68)) { - for (CargoID i = 0; i < NUM_CARGO; i++) { + for (CargoID i = 0; i < num_cargo; i++) { GoodsEntry *ge = &st->goods[i]; SwapPackets(ge); SlObject(ge, GetGoodsDesc()); @@ -440,7 +441,8 @@ static const SaveLoad _station_desc[] = { SLE_VAR(Station, last_vehicle_type, SLE_UINT8), SLE_VAR(Station, had_vehicle_of_type, SLE_UINT8), SLE_LST(Station, loading_vehicles, REF_VEHICLE), - SLE_CONDVAR(Station, always_accepted, SLE_UINT32, 127, SL_MAX_VERSION), + SLE_CONDVAR(Station, always_accepted, SLE_FILE_U32 | SLE_VAR_U64, 127, 198), + SLE_CONDVAR(Station, always_accepted, SLE_UINT64, 199, SL_MAX_VERSION), SLE_END() }; @@ -520,6 +522,7 @@ static void Load_STNN() { _num_flows = 0; + uint num_cargo = IsSavegameVersionBefore(199) ? 32 : NUM_CARGO; int index; while ((index = SlIterateArray()) != -1) { bool waypoint = (SlReadByte() & FACIL_WAYPOINT) != 0; @@ -538,7 +541,7 @@ static void Load_STNN() memcpy(st->airport.psa->storage, _old_st_persistent_storage.storage, sizeof(st->airport.psa->storage)); } - for (CargoID i = 0; i < NUM_CARGO; i++) { + for (CargoID i = 0; i < num_cargo; i++) { SlObject(&st->goods[i], GetGoodsDesc()); FlowSaveLoad flow; FlowStat *fs = NULL; @@ -580,9 +583,10 @@ static void Ptrs_STNN() /* Don't run when savegame version lower than 123. */ if (IsSavegameVersionBefore(123)) return; + uint num_cargo = IsSavegameVersionBefore(199) ? 32 : NUM_CARGO; Station *st; FOR_ALL_STATIONS(st) { - for (CargoID i = 0; i < NUM_CARGO; i++) { + for (CargoID i = 0; i < num_cargo; i++) { GoodsEntry *ge = &st->goods[i]; if (IsSavegameVersionBefore(183)) { SwapPackets(ge); diff --git a/src/saveload/town_sl.cpp b/src/saveload/town_sl.cpp index 41ac701650..13438d85bf 100644 --- a/src/saveload/town_sl.cpp +++ b/src/saveload/town_sl.cpp @@ -192,7 +192,8 @@ static const SaveLoad _town_desc[] = { SLE_CONDLST(Town, psa_list, REF_STORAGE, 161, SL_MAX_VERSION), - SLE_CONDVAR(Town, cargo_produced, SLE_UINT32, 166, SL_MAX_VERSION), + SLE_CONDVAR(Town, cargo_produced, SLE_FILE_U32 | SLE_VAR_U64, 166, 198), + SLE_CONDVAR(Town, cargo_produced, SLE_UINT64, 199, SL_MAX_VERSION), /* reserve extra space in savegame here. (currently 30 bytes) */ SLE_CONDNULL(30, 2, SL_MAX_VERSION), @@ -274,12 +275,13 @@ static void Save_TOWN() static void Load_TOWN() { int index; + uint num_cargo = IsSavegameVersionBefore(199) ? 32 : NUM_CARGO; while ((index = SlIterateArray()) != -1) { Town *t = new (index) Town(); SlObject(t, _town_desc); - for (CargoID i = 0; i < NUM_CARGO; i++) { + for (CargoID i = 0; i < num_cargo; i++) { SlObject(&t->supplied[i], _town_supplied_desc); } for (int i = TE_BEGIN; i < TE_END; i++) { diff --git a/src/strings.cpp b/src/strings.cpp index 3bfd88662b..b793503187 100644 --- a/src/strings.cpp +++ b/src/strings.cpp @@ -1147,7 +1147,7 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg } case SCC_CARGO_LIST: { // {CARGO_LIST} - CargoTypes cmask = args->GetInt32(SCC_CARGO_LIST); + CargoTypes cmask = args->GetInt64(SCC_CARGO_LIST); bool first = true; const CargoSpec *cs; From 6c02c1993101da6988d56165694ddd89f439dd2e Mon Sep 17 00:00:00 2001 From: translators Date: Wed, 27 Jun 2018 19:45:41 +0200 Subject: [PATCH 03/15] Update: Translations from eints italian: 3 changes by lorenzodv --- src/lang/italian.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/lang/italian.txt b/src/lang/italian.txt index 4222a34554..d245136f1d 100644 --- a/src/lang/italian.txt +++ b/src/lang/italian.txt @@ -883,9 +883,9 @@ STR_NEWS_EXCLUSIVE_RIGHTS_DESCRIPTION :{BIG_FONT}{BLAC # Extra view window STR_EXTRA_VIEW_PORT_TITLE :{WHITE}Mini visuale {COMMA} -STR_EXTRA_VIEW_MOVE_VIEW_TO_MAIN :{BLACK}Copia nella mini visuale +STR_EXTRA_VIEW_MOVE_VIEW_TO_MAIN :{BLACK}Cambia mini visuale STR_EXTRA_VIEW_MOVE_VIEW_TO_MAIN_TT :{BLACK}Copia la posizione della visuale principale in questa mini visuale -STR_EXTRA_VIEW_MOVE_MAIN_TO_VIEW :{BLACK}Copia dalla mini visuale +STR_EXTRA_VIEW_MOVE_MAIN_TO_VIEW :{BLACK}Cambia visuale principale STR_EXTRA_VIEW_MOVE_MAIN_TO_VIEW_TT :{BLACK}Copia la posizione di questa mini visuale nella visuale principale # Game options window @@ -2314,6 +2314,7 @@ STR_LINKGRAPH_LEGEND_NONE :{BLACK}Nessuno STR_LINKGRAPH_LEGEND_NONE.ms :{BLACK}Nessuno STR_LINKGRAPH_LEGEND_NONE.fs :{BLACK}Nessuna STR_LINKGRAPH_LEGEND_SELECT_COMPANIES :{BLACK}Seleziona le compagnie da mostrare +STR_LINKGRAPH_LEGEND_COMPANY_TOOLTIP :{BLACK}{STRING}{}{COMPANY} # Linkgraph legend window and linkgraph legend in smallmap STR_LINKGRAPH_LEGEND_UNUSED :{TINY_FONT}{BLACK}inutilizzata From dbfc417e65804c09cecf6e549de74a18639f6f7b Mon Sep 17 00:00:00 2001 From: Michael Lutz Date: Sun, 24 Jun 2018 20:44:37 +0200 Subject: [PATCH 04/15] Fix: [Win32] Garbage in OS window title if branch name was too long. This was caused by a missing \0-character on reaching the buffer limit. --- src/video/win32_v.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/video/win32_v.cpp b/src/video/win32_v.cpp index d1d4a4cd57..9559163c38 100644 --- a/src/video/win32_v.cpp +++ b/src/video/win32_v.cpp @@ -338,13 +338,13 @@ bool VideoDriver_Win32::MakeWindow(bool full_screen) if (_wnd.main_wnd != NULL) { if (!_window_maximize) SetWindowPos(_wnd.main_wnd, 0, 0, 0, w, h, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_NOMOVE); } else { - TCHAR Windowtitle[50]; int x = (GetSystemMetrics(SM_CXSCREEN) - w) / 2; int y = (GetSystemMetrics(SM_CYSCREEN) - h) / 2; - _sntprintf(Windowtitle, lengthof(Windowtitle), _T("OpenTTD %s"), MB_TO_WIDE(_openttd_revision)); + char window_title[64]; + seprintf(window_title, lastof(window_title), "OpenTTD %s", _openttd_revision); - _wnd.main_wnd = CreateWindow(_T("OTTD"), Windowtitle, style, x, y, w, h, 0, 0, GetModuleHandle(NULL), 0); + _wnd.main_wnd = CreateWindow(_T("OTTD"), MB_TO_WIDE(window_title), style, x, y, w, h, 0, 0, GetModuleHandle(NULL), 0); if (_wnd.main_wnd == NULL) usererror("CreateWindow failed"); ShowWindow(_wnd.main_wnd, showstyle); } From e1b9187e9b39ff2ce1982a8fbcb4f2a018662ce7 Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Sun, 20 May 2018 17:10:45 +0100 Subject: [PATCH 05/15] Codechange: Add initialisation values for all CompanyProperty attributes --- src/company_base.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/company_base.h b/src/company_base.h index b8ea09f955..1bc4b7f83c 100644 --- a/src/company_base.h +++ b/src/company_base.h @@ -96,7 +96,13 @@ struct CompanyProperties { CompanyEconomyEntry old_economy[MAX_HISTORY_QUARTERS]; ///< Economic data of the company of the last #MAX_HISTORY_QUARTERS quarters. byte num_valid_stat_ent; ///< Number of valid statistical entries in #old_economy. - CompanyProperties() : name(NULL), president_name(NULL) {} + // TODO: Change some of these member variables to use relevant INVALID_xxx constants + CompanyProperties() + : name_2(0), name_1(0), name(NULL), president_name_1(0), president_name_2(0), president_name(NULL), + face(0), money(0), money_fraction(0), current_loan(0), colour(0), block_preview(0), + location_of_HQ(0), last_build_coordinate(0), share_owners(), inaugurated_year(0), + months_of_bankruptcy(0), bankrupt_asked(0), bankrupt_timeout(0), bankrupt_value(0), + terraform_limit(0), clear_limit(0), tree_limit(0), is_ai(false) {} ~CompanyProperties() { From 5f86e1a390b4aa9510d43f97251484ca67934f1c Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Sun, 13 May 2018 18:34:57 +0100 Subject: [PATCH 06/15] Codechange: Silence -Wclass-memaccess warnings with GCC8 --- src/3rdparty/squirrel/squirrel/squtils.h | 2 +- src/3rdparty/squirrel/squirrel/sqvm.cpp | 6 ++---- src/base_media_func.h | 2 -- src/blitter/32bpp_anim.cpp | 2 +- src/core/alloc_func.hpp | 2 +- src/economy.cpp | 5 +++-- src/landscape.cpp | 3 +-- src/newgrf_object.cpp | 4 +++- src/saveload/company_sl.cpp | 1 - 9 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/3rdparty/squirrel/squirrel/squtils.h b/src/3rdparty/squirrel/squirrel/squtils.h index 28c6cbec2b..b1138dcb1a 100644 --- a/src/3rdparty/squirrel/squirrel/squtils.h +++ b/src/3rdparty/squirrel/squirrel/squtils.h @@ -90,7 +90,7 @@ public: { _vals[idx].~T(); if(idx < (_size - 1)) { - memmove(&_vals[idx], &_vals[idx+1], sizeof(T) * (_size - (size_t)idx - 1)); + memmove(static_cast(&_vals[idx]), &_vals[idx+1], sizeof(T) * (_size - (size_t)idx - 1)); } _size--; } diff --git a/src/3rdparty/squirrel/squirrel/sqvm.cpp b/src/3rdparty/squirrel/squirrel/sqvm.cpp index c66c4aca59..03ffea2303 100644 --- a/src/3rdparty/squirrel/squirrel/sqvm.cpp +++ b/src/3rdparty/squirrel/squirrel/sqvm.cpp @@ -378,8 +378,7 @@ bool SQVM::StartCall(SQClosure *closure,SQInteger target,SQInteger args,SQIntege } if (!tailcall) { - CallInfo lc; - memset(&lc, 0, sizeof(lc)); + CallInfo lc = {}; lc._generator = NULL; lc._etraps = 0; lc._prevstkbase = (SQInt32) ( stackbase - _stackbase ); @@ -1159,8 +1158,7 @@ bool SQVM::CallNative(SQNativeClosure *nclosure,SQInteger nargs,SQInteger stackb SQInteger oldtop = _top; SQInteger oldstackbase = _stackbase; _top = stackbase + nargs; - CallInfo lci; - memset(&lci, 0, sizeof(lci)); + CallInfo lci = {}; lci._closure = nclosure; lci._generator = NULL; lci._etraps = 0; diff --git a/src/base_media_func.h b/src/base_media_func.h index 2cb751fe0c..f7afca0edb 100644 --- a/src/base_media_func.h +++ b/src/base_media_func.h @@ -40,8 +40,6 @@ template bool BaseSet::FillSetDetails(IniFile *ini, const char *path, const char *full_filename, bool allow_empty_filename) { - memset(this, 0, sizeof(*this)); - IniGroup *metadata = ini->GetGroup("metadata"); IniItem *item; diff --git a/src/blitter/32bpp_anim.cpp b/src/blitter/32bpp_anim.cpp index 578d85f188..98ae22b00c 100644 --- a/src/blitter/32bpp_anim.cpp +++ b/src/blitter/32bpp_anim.cpp @@ -361,7 +361,7 @@ void Blitter_32bppAnim::CopyFromBuffer(void *video, const void *src, int width, Colour *dst_pal = dst; uint16 *anim_pal = anim_line; - memcpy(dst, usrc, width * sizeof(uint32)); + memcpy(static_cast(dst), usrc, width * sizeof(uint32)); usrc += width; dst += _screen.pitch; /* Copy back the anim-buffer */ diff --git a/src/core/alloc_func.hpp b/src/core/alloc_func.hpp index c7e17421f7..c33e733016 100644 --- a/src/core/alloc_func.hpp +++ b/src/core/alloc_func.hpp @@ -125,7 +125,7 @@ static inline T *ReallocT(T *t_ptr, size_t num_elements) /* Ensure the size does not overflow. */ CheckAllocationConstraints(num_elements); - t_ptr = (T*)realloc(t_ptr, num_elements * sizeof(T)); + t_ptr = (T*)realloc(static_cast(t_ptr), num_elements * sizeof(T)); if (t_ptr == NULL) ReallocError(num_elements * sizeof(T)); return t_ptr; } diff --git a/src/economy.cpp b/src/economy.cpp index 70b0bd8376..fae71f3e42 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -696,9 +696,10 @@ static void CompaniesGenStatistics() if (!HasBit(1 << 0 | 1 << 3 | 1 << 6 | 1 << 9, _cur_month)) return; FOR_ALL_COMPANIES(c) { - memmove(&c->old_economy[1], &c->old_economy[0], sizeof(c->old_economy) - sizeof(c->old_economy[0])); + /* Drop the oldest history off the end */ + std::copy_backward(c->old_economy, c->old_economy + MAX_HISTORY_QUARTERS - 1, c->old_economy + MAX_HISTORY_QUARTERS); c->old_economy[0] = c->cur_economy; - memset(&c->cur_economy, 0, sizeof(c->cur_economy)); + c->cur_economy = {}; if (c->num_valid_stat_ent != MAX_HISTORY_QUARTERS) c->num_valid_stat_ent++; diff --git a/src/landscape.cpp b/src/landscape.cpp index 185e84a80b..a29c97b9d7 100644 --- a/src/landscape.cpp +++ b/src/landscape.cpp @@ -1080,8 +1080,7 @@ static uint River_Hash(uint tile, uint dir) */ static void BuildRiver(TileIndex begin, TileIndex end) { - AyStar finder; - MemSetT(&finder, 0); + AyStar finder = {}; finder.CalculateG = River_CalculateG; finder.CalculateH = River_CalculateH; finder.GetNeighbours = River_GetNeighbours; diff --git a/src/newgrf_object.cpp b/src/newgrf_object.cpp index 78bbc52443..40a966a166 100644 --- a/src/newgrf_object.cpp +++ b/src/newgrf_object.cpp @@ -96,7 +96,9 @@ uint ObjectSpec::Index() const void ResetObjects() { /* Clean the pool. */ - MemSetT(_object_specs, 0, lengthof(_object_specs)); + for (uint16 i = 0; i < NUM_OBJECTS; i++) { + _object_specs[i] = {}; + } /* And add our originals. */ MemCpyT(_object_specs, _original_objects, lengthof(_original_objects)); diff --git a/src/saveload/company_sl.cpp b/src/saveload/company_sl.cpp index 07d685e92f..ce388e2141 100644 --- a/src/saveload/company_sl.cpp +++ b/src/saveload/company_sl.cpp @@ -498,7 +498,6 @@ static void Check_PLYR() int index; while ((index = SlIterateArray()) != -1) { CompanyProperties *cprops = new CompanyProperties(); - memset(cprops, 0, sizeof(*cprops)); SaveLoad_PLYR_common(NULL, cprops); /* We do not load old custom names */ From 2aacddd4123a45e386cde7445e1fa7b8cf60a222 Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Wed, 16 May 2018 21:26:41 +0100 Subject: [PATCH 07/15] Codechange: lengthof is not defined for runtime-length strings, use sizeof instead --- src/saveload/saveload.h | 2 +- src/table/settings.h.preamble | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/saveload/saveload.h b/src/saveload/saveload.h index d492558c5a..3405f3351c 100644 --- a/src/saveload/saveload.h +++ b/src/saveload/saveload.h @@ -436,7 +436,7 @@ typedef SaveLoad SaveLoadGlobVarList; * @param variable Name of the global variable. * @param type Storage of the data in memory and in the savegame. */ -#define SLEG_STR(variable, type) SLEG_CONDSTR(variable, type, lengthof(variable), 0, SL_MAX_VERSION) +#define SLEG_STR(variable, type) SLEG_CONDSTR(variable, type, sizeof(variable), 0, SL_MAX_VERSION) /** * Storage of a global list in every savegame version. diff --git a/src/table/settings.h.preamble b/src/table/settings.h.preamble index 33345bb713..f475e305bc 100644 --- a/src/table/settings.h.preamble +++ b/src/table/settings.h.preamble @@ -74,7 +74,7 @@ static size_t ConvertLandscape(const char *value); SDTG_GENERAL(name, SDT_INTLIST, SL_ARR, type, flags, guiflags, var, length, def, 0, 0, 0, NULL, str, strhelp, strval, proc, from, to, cat) #define SDTG_STR(name, type, flags, guiflags, var, def, str, strhelp, strval, proc, from, to, cat)\ - SDTG_GENERAL(name, SDT_STRING, SL_STR, type, flags, guiflags, var, lengthof(var), def, 0, 0, 0, NULL, str, strhelp, strval, proc, from, to, cat) + SDTG_GENERAL(name, SDT_STRING, SL_STR, type, flags, guiflags, var, sizeof(var), def, 0, 0, 0, NULL, str, strhelp, strval, proc, from, to, cat) #define SDTG_OMANY(name, type, flags, guiflags, var, def, max, full, str, strhelp, strval, proc, from, to, cat)\ SDTG_GENERAL(name, SDT_ONEOFMANY, SL_VAR, type, flags, guiflags, var, 0, def, 0, max, 0, full, str, strhelp, strval, proc, from, to, cat) @@ -102,7 +102,7 @@ static size_t ConvertLandscape(const char *value); SDT_GENERAL(#var, SDT_INTLIST, SL_ARR, type, flags, guiflags, base, var, lengthof(((base*)8)->var), def, 0, 0, 0, NULL, str, strhelp, strval, proc, NULL, from, to, cat) #define SDT_STR(base, var, type, flags, guiflags, def, str, strhelp, strval, proc, from, to, cat)\ - SDT_GENERAL(#var, SDT_STRING, SL_STR, type, flags, guiflags, base, var, lengthof(((base*)8)->var), def, 0, 0, 0, NULL, str, strhelp, strval, proc, NULL, from, to, cat) + SDT_GENERAL(#var, SDT_STRING, SL_STR, type, flags, guiflags, base, var, sizeof(((base*)8)->var), def, 0, 0, 0, NULL, str, strhelp, strval, proc, NULL, from, to, cat) #define SDT_CHR(base, var, flags, guiflags, def, str, strhelp, strval, proc, from, to, cat)\ SDT_GENERAL(#var, SDT_STRING, SL_VAR, SLE_CHAR, flags, guiflags, base, var, 1, def, 0, 0, 0, NULL, str, strhelp, strval, proc, NULL, from, to, cat) @@ -127,7 +127,7 @@ static size_t ConvertLandscape(const char *value); SDTG_GENERAL(#var, SDT_INTLIST, SL_ARR, type, flags, guiflags, _settings_client.var, lengthof(_settings_client.var), def, 0, 0, 0, NULL, str, strhelp, strval, proc, from, to, cat) #define SDTC_STR(var, type, flags, guiflags, def, str, strhelp, strval, proc, from, to, cat)\ - SDTG_GENERAL(#var, SDT_STRING, SL_STR, type, flags, guiflags, _settings_client.var, lengthof(_settings_client.var), def, 0, 0, 0, NULL, str, strhelp, strval, proc, from, to, cat) + SDTG_GENERAL(#var, SDT_STRING, SL_STR, type, flags, guiflags, _settings_client.var, sizeof(_settings_client.var), def, 0, 0, 0, NULL, str, strhelp, strval, proc, from, to, cat) #define SDTC_OMANY(var, type, flags, guiflags, def, max, full, str, strhelp, strval, proc, from, to, cat)\ SDTG_GENERAL(#var, SDT_ONEOFMANY, SL_VAR, type, flags, guiflags, _settings_client.var, 1, def, 0, max, 0, full, str, strhelp, strval, proc, from, to, cat) From 6a9df285d0c368df5026270d34639d396a8120bb Mon Sep 17 00:00:00 2001 From: Juanjo Date: Tue, 1 Jan 2013 12:44:50 +0100 Subject: [PATCH 08/15] Codechange: Separate an assertion. More information if assert is triggered. --- src/pathfinder/follow_track.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pathfinder/follow_track.hpp b/src/pathfinder/follow_track.hpp index d9a70b7fca..a8399cd9f6 100644 --- a/src/pathfinder/follow_track.hpp +++ b/src/pathfinder/follow_track.hpp @@ -73,7 +73,8 @@ struct CFollowTrackT inline void Init(Owner o, RailTypes railtype_override, CPerformanceTimer *pPerf) { - assert((!IsRoadTT() || m_veh != NULL) && (!IsRailTT() || railtype_override != INVALID_RAILTYPES)); + assert(!IsRoadTT() || m_veh != NULL); + assert(!IsRailTT() || railtype_override != INVALID_RAILTYPES); m_veh_owner = o; m_pPerf = pPerf; /* don't worry, all is inlined so compiler should remove unnecessary initializations */ From 85ebe20a761127bebe873389d81f31502685a98a Mon Sep 17 00:00:00 2001 From: Juanjo Date: Tue, 15 Jul 2014 19:08:00 +0200 Subject: [PATCH 09/15] Cleanup: Unnecessary assignation on FollowTileExit(): done previously on the function. --- src/pathfinder/follow_track.hpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/pathfinder/follow_track.hpp b/src/pathfinder/follow_track.hpp index a8399cd9f6..ad81d974b0 100644 --- a/src/pathfinder/follow_track.hpp +++ b/src/pathfinder/follow_track.hpp @@ -227,8 +227,6 @@ protected: m_is_station = true; } else if (IsRoadTT() && IsRoadStopTile(m_new_tile)) { m_is_station = true; - } else { - m_is_station = false; } } From 31ac11bddb71945bba57d0cefac620f455963455 Mon Sep 17 00:00:00 2001 From: J0anJosep Date: Sun, 29 Apr 2018 12:23:01 +0200 Subject: [PATCH 10/15] Codechange: Increase readability of track functions and pathfinders. --- src/pathfinder/follow_track.hpp | 2 +- src/pathfinder/npf/npf.cpp | 6 +++--- src/pathfinder/opf/opf_ship.cpp | 27 +++++++++++++++++---------- src/pathfinder/yapf/yapf_common.hpp | 3 +-- src/pathfinder/yapf/yapf_costrail.hpp | 2 +- src/pathfinder/yapf/yapf_destrail.hpp | 9 +++------ src/pathfinder/yapf/yapf_road.cpp | 3 +-- src/track_func.h | 2 +- 8 files changed, 28 insertions(+), 26 deletions(-) diff --git a/src/pathfinder/follow_track.hpp b/src/pathfinder/follow_track.hpp index ad81d974b0..70f148de38 100644 --- a/src/pathfinder/follow_track.hpp +++ b/src/pathfinder/follow_track.hpp @@ -239,7 +239,7 @@ protected: } else { m_new_td_bits = TrackStatusToTrackdirBits(GetTileTrackStatus(m_new_tile, TT(), IsRoadTT() ? RoadVehicle::From(m_veh)->compatible_roadtypes : 0)); - if (IsTram() && m_new_td_bits == 0) { + if (IsTram() && m_new_td_bits == TRACKDIR_BIT_NONE) { /* GetTileTrackStatus() returns 0 for single tram bits. * As we cannot change it there (easily) without breaking something, change it here */ switch (GetSingleTramBit(m_new_tile)) { diff --git a/src/pathfinder/npf/npf.cpp b/src/pathfinder/npf/npf.cpp index f989ff2c34..3218d8314f 100644 --- a/src/pathfinder/npf/npf.cpp +++ b/src/pathfinder/npf/npf.cpp @@ -807,7 +807,7 @@ static TrackdirBits GetDriveableTrackdirBits(TileIndex dst_tile, Trackdir src_tr { TrackdirBits trackdirbits = TrackStatusToTrackdirBits(GetTileTrackStatus(dst_tile, type, subtype)); - if (trackdirbits == 0 && type == TRANSPORT_ROAD && HasBit(subtype, ROADTYPE_TRAM)) { + if (trackdirbits == TRACKDIR_BIT_NONE && type == TRANSPORT_ROAD && HasBit(subtype, ROADTYPE_TRAM)) { /* GetTileTrackStatus() returns 0 for single tram bits. * As we cannot change it there (easily) without breaking something, change it here */ switch (GetSingleTramBit(dst_tile)) { @@ -900,7 +900,7 @@ static void NPFFollowTrack(AyStar *aystar, OpenListNode *current) trackdirbits = GetDriveableTrackdirBits(dst_tile, src_trackdir, type, subtype); - if (trackdirbits == 0) { + if (trackdirbits == TRACKDIR_BIT_NONE) { /* We cannot enter the next tile. Road vehicles can reverse, others reach dead end */ if (type != TRANSPORT_ROAD || HasBit(subtype, ROADTYPE_TRAM)) return; @@ -924,7 +924,7 @@ static void NPFFollowTrack(AyStar *aystar, OpenListNode *current) /* Enumerate possible track */ uint i = 0; - while (trackdirbits != 0) { + while (trackdirbits != TRACKDIR_BIT_NONE) { Trackdir dst_trackdir = RemoveFirstTrackdir(&trackdirbits); DEBUG(npf, 5, "Expanded into trackdir: %d, remaining trackdirs: 0x%X", dst_trackdir, trackdirbits); diff --git a/src/pathfinder/opf/opf_ship.cpp b/src/pathfinder/opf/opf_ship.cpp index 023c6a4a09..e3b7db5a6f 100644 --- a/src/pathfinder/opf/opf_ship.cpp +++ b/src/pathfinder/opf/opf_ship.cpp @@ -183,9 +183,14 @@ bad:; } /** - * returns the track to choose on the next tile, or -1 when it's better to - * reverse. The tile given is the tile we are about to enter, enterdir is the - * direction in which we are entering the tile + * Finds the best track to choose on the next tile and + * returns INVALID_TRACK when it is better to reverse. + * @param v The ship. + * @param tile The tile we are about to enter. + * @param enterdir The direction entering the tile. + * @param tracks The tracks available on new tile. + * @param[out] path_found Whether a path has been found. + * @return Best track on next tile or INVALID_TRACK when better to reverse. */ Track OPFShipChooseTrack(const Ship *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool &path_found) { @@ -195,13 +200,15 @@ Track OPFShipChooseTrack(const Ship *v, TileIndex tile, DiagDirection enterdir, Track track; /* Let's find out how far it would be if we would reverse first */ - Trackdir trackdir = v->GetVehicleTrackdir(); - TrackBits b = TrackStatusToTrackBits(GetTileTrackStatus(tile2, TRANSPORT_WATER, 0)) & DiagdirReachesTracks(ReverseDiagDir(enterdir)) & TrackdirBitsToTrackBits(TrackdirToTrackdirBits(trackdir)); + uint rev_dist = UINT_MAX; // distance if we reverse + Track cur_track = TrackdirToTrack(v->GetVehicleTrackdir()); // track on the current tile + DiagDirection rev_enterdir = ReverseDiagDir(enterdir); + TrackBits rev_tracks = TrackStatusToTrackBits(GetTileTrackStatus(tile2, TRANSPORT_WATER, 0)) & + DiagdirReachesTracks(rev_enterdir); - uint distr = UINT_MAX; // distance if we reversed - if (b != 0) { - distr = FindShipTrack(v, tile2, ReverseDiagDir(enterdir), b, tile, &track); - if (distr != UINT_MAX) distr++; // penalty for reversing + if ((rev_tracks & TrackToTrackBits(cur_track) != TRACK_BIT_NONE) { + rev_dist = FindShipTrack(v, tile2, rev_enterdir, TrackToTrackBits(cur_track), tile, &track); + if (rev_dist != UINT_MAX) rev_dist++; // penalty for reversing } /* And if we would not reverse? */ @@ -209,6 +216,6 @@ Track OPFShipChooseTrack(const Ship *v, TileIndex tile, DiagDirection enterdir, /* Due to the way this pathfinder works we cannot determine whether we're lost or not. */ path_found = true; - if (dist <= distr) return track; + if (dist <= rev_dist) return track; return INVALID_TRACK; // We could better reverse } diff --git a/src/pathfinder/yapf/yapf_common.hpp b/src/pathfinder/yapf/yapf_common.hpp index 660c231161..ac2e5b5a2d 100644 --- a/src/pathfinder/yapf/yapf_common.hpp +++ b/src/pathfinder/yapf/yapf_common.hpp @@ -142,8 +142,7 @@ public: /** Called by YAPF to detect if node ends in the desired destination */ inline bool PfDetectDestination(Node &n) { - bool bDest = (n.m_key.m_tile == m_destTile) && ((m_destTrackdirs & TrackdirToTrackdirBits(n.GetTrackdir())) != TRACKDIR_BIT_NONE); - return bDest; + return (n.m_key.m_tile == m_destTile) && ((m_destTrackdirs & TrackdirToTrackdirBits(n.GetTrackdir())) != TRACKDIR_BIT_NONE); } /** diff --git a/src/pathfinder/yapf/yapf_costrail.hpp b/src/pathfinder/yapf/yapf_costrail.hpp index ca317f09a7..5c5a7fbaf4 100644 --- a/src/pathfinder/yapf/yapf_costrail.hpp +++ b/src/pathfinder/yapf/yapf_costrail.hpp @@ -104,7 +104,7 @@ public: assert(IsValidTrackdir(td2)); int cost = 0; if (TrackFollower::Allow90degTurns() - && ((TrackdirToTrackdirBits(td2) & (TrackdirBits)TrackdirCrossesTrackdirs(td1)) != 0)) { + && ((TrackdirToTrackdirBits(td2) & TrackdirCrossesTrackdirs(td1)) != TRACKDIR_BIT_NONE)) { /* 90-deg curve penalty */ cost += Yapf().PfGetSettings().rail_curve90_penalty; } else if (td2 != NextTrackdir(td1)) { diff --git a/src/pathfinder/yapf/yapf_destrail.hpp b/src/pathfinder/yapf/yapf_destrail.hpp index 03519b059f..7b3f1c5a1a 100644 --- a/src/pathfinder/yapf/yapf_destrail.hpp +++ b/src/pathfinder/yapf/yapf_destrail.hpp @@ -166,16 +166,13 @@ public: /** Called by YAPF to detect if node ends in the desired destination */ inline bool PfDetectDestination(TileIndex tile, Trackdir td) { - bool bDest; if (m_dest_station_id != INVALID_STATION) { - bDest = HasStationTileRail(tile) + return HasStationTileRail(tile) && (GetStationIndex(tile) == m_dest_station_id) && (GetRailStationTrack(tile) == TrackdirToTrack(td)); - } else { - bDest = (tile == m_destTile) - && ((m_destTrackdirs & TrackdirToTrackdirBits(td)) != TRACKDIR_BIT_NONE); } - return bDest; + + return (tile == m_destTile) && ((m_destTrackdirs & TrackdirToTrackdirBits(td)) != TRACKDIR_BIT_NONE); } /** diff --git a/src/pathfinder/yapf/yapf_road.cpp b/src/pathfinder/yapf/yapf_road.cpp index 380b641da7..b2ec6ae234 100644 --- a/src/pathfinder/yapf/yapf_road.cpp +++ b/src/pathfinder/yapf/yapf_road.cpp @@ -185,8 +185,7 @@ public: /** Called by YAPF to detect if node ends in the desired destination */ inline bool PfDetectDestination(Node &n) { - bool bDest = IsRoadDepotTile(n.m_segment_last_tile); - return bDest; + return IsRoadDepotTile(n.m_segment_last_tile); } inline bool PfDetectDestinationTile(TileIndex tile, Trackdir trackdir) diff --git a/src/track_func.h b/src/track_func.h index 5e1585c086..c1a23ba039 100644 --- a/src/track_func.h +++ b/src/track_func.h @@ -61,7 +61,7 @@ static inline bool IsValidTrackdirForRoadVehicle(Trackdir trackdir) */ static inline bool IsValidTrackdir(Trackdir trackdir) { - return (1 << trackdir & TRACKDIR_BIT_MASK) != 0; + return (1 << trackdir & TRACKDIR_BIT_MASK) != TRACKDIR_BIT_NONE; } /** From d01c09fb73aacd1b3c204829e7c574bbde09153f Mon Sep 17 00:00:00 2001 From: J0anJosep Date: Sat, 12 May 2018 18:19:40 +0200 Subject: [PATCH 11/15] Codechange: Use HasTrack(dir) to improve code readability. --- src/pathfinder/opf/opf_ship.cpp | 2 +- src/pathfinder/yapf/yapf_common.hpp | 2 +- src/pathfinder/yapf/yapf_costrail.hpp | 4 ++-- src/pathfinder/yapf/yapf_destrail.hpp | 2 +- src/pathfinder/yapf/yapf_road.cpp | 6 +++--- src/pathfinder/yapf/yapf_ship.cpp | 2 +- src/track_func.h | 22 ++++++++++++++++++++++ 7 files changed, 31 insertions(+), 9 deletions(-) diff --git a/src/pathfinder/opf/opf_ship.cpp b/src/pathfinder/opf/opf_ship.cpp index e3b7db5a6f..1a866337c7 100644 --- a/src/pathfinder/opf/opf_ship.cpp +++ b/src/pathfinder/opf/opf_ship.cpp @@ -206,7 +206,7 @@ Track OPFShipChooseTrack(const Ship *v, TileIndex tile, DiagDirection enterdir, TrackBits rev_tracks = TrackStatusToTrackBits(GetTileTrackStatus(tile2, TRANSPORT_WATER, 0)) & DiagdirReachesTracks(rev_enterdir); - if ((rev_tracks & TrackToTrackBits(cur_track) != TRACK_BIT_NONE) { + if (HasTrack(rev_tracks, cur_track)) { rev_dist = FindShipTrack(v, tile2, rev_enterdir, TrackToTrackBits(cur_track), tile, &track); if (rev_dist != UINT_MAX) rev_dist++; // penalty for reversing } diff --git a/src/pathfinder/yapf/yapf_common.hpp b/src/pathfinder/yapf/yapf_common.hpp index ac2e5b5a2d..8ff69b3f6b 100644 --- a/src/pathfinder/yapf/yapf_common.hpp +++ b/src/pathfinder/yapf/yapf_common.hpp @@ -142,7 +142,7 @@ public: /** Called by YAPF to detect if node ends in the desired destination */ inline bool PfDetectDestination(Node &n) { - return (n.m_key.m_tile == m_destTile) && ((m_destTrackdirs & TrackdirToTrackdirBits(n.GetTrackdir())) != TRACKDIR_BIT_NONE); + return (n.m_key.m_tile == m_destTile) && HasTrackdir(m_destTrackdirs, n.GetTrackdir()); } /** diff --git a/src/pathfinder/yapf/yapf_costrail.hpp b/src/pathfinder/yapf/yapf_costrail.hpp index 5c5a7fbaf4..022b9a1678 100644 --- a/src/pathfinder/yapf/yapf_costrail.hpp +++ b/src/pathfinder/yapf/yapf_costrail.hpp @@ -104,7 +104,7 @@ public: assert(IsValidTrackdir(td2)); int cost = 0; if (TrackFollower::Allow90degTurns() - && ((TrackdirToTrackdirBits(td2) & TrackdirCrossesTrackdirs(td1)) != TRACKDIR_BIT_NONE)) { + && HasTrackdir(TrackdirCrossesTrackdirs(td1), td2)) { /* 90-deg curve penalty */ cost += Yapf().PfGetSettings().rail_curve90_penalty; } else if (td2 != NextTrackdir(td1)) { @@ -280,7 +280,7 @@ public: { assert(!n.flags_u.flags_s.m_targed_seen); assert(tf->m_new_tile == n.m_key.m_tile); - assert((TrackdirToTrackdirBits(n.m_key.m_td) & tf->m_new_td_bits) != TRACKDIR_BIT_NONE); + assert((HasTrackdir(tf->m_new_td_bits, n.m_key.m_td))); CPerfStart perf_cost(Yapf().m_perf_cost); diff --git a/src/pathfinder/yapf/yapf_destrail.hpp b/src/pathfinder/yapf/yapf_destrail.hpp index 7b3f1c5a1a..1d1833fbfd 100644 --- a/src/pathfinder/yapf/yapf_destrail.hpp +++ b/src/pathfinder/yapf/yapf_destrail.hpp @@ -172,7 +172,7 @@ public: && (GetRailStationTrack(tile) == TrackdirToTrack(td)); } - return (tile == m_destTile) && ((m_destTrackdirs & TrackdirToTrackdirBits(td)) != TRACKDIR_BIT_NONE); + return (tile == m_destTile) && HasTrackdir(m_destTrackdirs, td); } /** diff --git a/src/pathfinder/yapf/yapf_road.cpp b/src/pathfinder/yapf/yapf_road.cpp index b2ec6ae234..edc8d2a3a3 100644 --- a/src/pathfinder/yapf/yapf_road.cpp +++ b/src/pathfinder/yapf/yapf_road.cpp @@ -260,7 +260,7 @@ public: (m_non_artic || IsDriveThroughStopTile(tile)); } - return tile == m_destTile && ((m_destTrackdirs & TrackdirToTrackdirBits(trackdir)) != TRACKDIR_BIT_NONE); + return tile == m_destTile && HasTrackdir(m_destTrackdirs, trackdir); } /** @@ -420,7 +420,7 @@ public: /* set origin (tile, trackdir) */ TileIndex src_tile = v->tile; Trackdir src_td = v->GetVehicleTrackdir(); - if ((TrackStatusToTrackdirBits(GetTileTrackStatus(src_tile, TRANSPORT_ROAD, v->compatible_roadtypes)) & TrackdirToTrackdirBits(src_td)) == 0) { + if (!HasTrackdir(TrackStatusToTrackdirBits(GetTileTrackStatus(src_tile, TRANSPORT_ROAD, v->compatible_roadtypes)), src_td)) { /* sometimes the roadveh is not on the road (it resides on non-existing track) * how should we handle that situation? */ return false; @@ -503,7 +503,7 @@ FindDepotData YapfRoadVehicleFindNearestDepot(const RoadVehicle *v, int max_dist { TileIndex tile = v->tile; Trackdir trackdir = v->GetVehicleTrackdir(); - if ((TrackStatusToTrackdirBits(GetTileTrackStatus(tile, TRANSPORT_ROAD, v->compatible_roadtypes)) & TrackdirToTrackdirBits(trackdir)) == 0) { + if (!HasTrackdir(TrackStatusToTrackdirBits(GetTileTrackStatus(tile, TRANSPORT_ROAD, v->compatible_roadtypes)), trackdir)) { return FindDepotData(); } diff --git a/src/pathfinder/yapf/yapf_ship.cpp b/src/pathfinder/yapf/yapf_ship.cpp index df6cd468ce..44a5c0cfa7 100644 --- a/src/pathfinder/yapf/yapf_ship.cpp +++ b/src/pathfinder/yapf/yapf_ship.cpp @@ -65,7 +65,7 @@ public: /* use vehicle's current direction if that's possible, otherwise use first usable one. */ Trackdir veh_dir = v->GetVehicleTrackdir(); - return ((trackdirs & TrackdirToTrackdirBits(veh_dir)) != 0) ? veh_dir : (Trackdir)FindFirstBit2x64(trackdirs); + return (HasTrackdir(trackdirs, veh_dir)) ? veh_dir : (Trackdir)FindFirstBit2x64(trackdirs); } /* move back to the old tile/trackdir (where ship is coming from) */ diff --git a/src/track_func.h b/src/track_func.h index c1a23ba039..8e2056265e 100644 --- a/src/track_func.h +++ b/src/track_func.h @@ -331,6 +331,28 @@ static inline TrackdirBits TrackBitsToTrackdirBits(TrackBits bits) return (TrackdirBits)(bits * 0x101); } +/** + * Checks whether a TrackBits has a given Track. + * @param tracks The track bits. + * @param track The track to check. + */ +static inline bool HasTrack(TrackBits tracks, Track track) +{ + assert(IsValidTrack(track)); + return HasBit(tracks, track); +} + +/** + * Checks whether a TrackdirBits has a given Trackdir. + * @param trackdirs The trackdir bits. + * @param trackdir The trackdir to check. + */ +static inline bool HasTrackdir(TrackdirBits trackdirs, Trackdir trackdir) +{ + assert(IsValidTrackdir(trackdir)); + return HasBit(trackdirs, trackdir); +} + /** * Returns the present-trackdir-information of a TrackStatus. * From 4189cb85ba054d0f41ec0b64a9323e63e49f2afc Mon Sep 17 00:00:00 2001 From: J0anJosep Date: Mon, 30 Apr 2018 18:37:45 +0200 Subject: [PATCH 12/15] Codechange: Use HasTracks with TrackStatus. --- src/pbs.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pbs.cpp b/src/pbs.cpp index 133293909f..6bb35a6964 100644 --- a/src/pbs.cpp +++ b/src/pbs.cpp @@ -81,7 +81,7 @@ void SetRailStationPlatformReservation(TileIndex start, DiagDirection dir, bool */ bool TryReserveRailTrack(TileIndex tile, Track t, bool trigger_stations) { - assert((GetTileTrackStatus(tile, TRANSPORT_RAIL, 0) & TrackToTrackBits(t)) != 0); + assert(HasTrack(TrackStatusToTrackBits(GetTileTrackStatus(tile, TRANSPORT_RAIL, 0)), t)); if (_settings_client.gui.show_track_reservation) { /* show the reserved rail if needed */ @@ -142,7 +142,7 @@ bool TryReserveRailTrack(TileIndex tile, Track t, bool trigger_stations) */ void UnreserveRailTrack(TileIndex tile, Track t) { - assert((GetTileTrackStatus(tile, TRANSPORT_RAIL, 0) & TrackToTrackBits(t)) != 0); + assert(HasTrack(TrackStatusToTrackBits(GetTileTrackStatus(tile, TRANSPORT_RAIL, 0)), t)); if (_settings_client.gui.show_track_reservation) { if (IsBridgeTile(tile)) { From 6cf4d7d3ef4dd27eac482eed86a3de1504454dbe Mon Sep 17 00:00:00 2001 From: Niels Martin Hansen Date: Sun, 1 Jul 2018 12:15:00 +0200 Subject: [PATCH 13/15] Fix: Put last SVN revision back in NewGRF version number (#6843) This is necessary to be compatible with some Game Scripts that might trigger compatibility modes if the SVN revision part is wrong. Potentially some NewGRFs might also be affected. See for example [SuperLib's Helper class](https://dev.openttdcoop.org/projects/superlib/repository/entry/helper.nut#L280), containing this function: function _SuperLib_Helper::HasWorldGenBug() { local version = _SuperLib_Helper.GetOpenTTDVersion(); if (version.Major == 0 || (version.Major == 1 && version.Minor <= 3)) { return version.Revision < 25339; } else { return version.Revision < 25305; } } If this function sees a Revision value of zero, it might trigger a workaround not required, causing a regression in scripts dependent on this. The MinimalGS example, for one, will trigger this. --- src/rev.cpp.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rev.cpp.in b/src/rev.cpp.in index 6689fe6891..0f4b2a6b57 100644 --- a/src/rev.cpp.in +++ b/src/rev.cpp.in @@ -64,13 +64,13 @@ const byte _openttd_revision_modified = !!MODIFIED!!; * 24-27 minor version * 20-23 build * 19 1 if it is a release, 0 if it is not. - * 0-18 used to be the SVN revision, currently unused + * 0-18 used to be the SVN revision, now just last revision before switch to git * * The 19th bit is there so the development/betas/alpha, etc. leading to a * final release will always have a lower version number than the released * version, thus making comparisons on specific revisions easy. */ -const uint32 _openttd_newgrf_version = 1 << 28 | 9 << 24 | 0 << 20 | 0 << 19; +const uint32 _openttd_newgrf_version = 1 << 28 | 9 << 24 | 0 << 20 | 0 << 19 | 28004; #ifdef __MORPHOS__ /** From 8f278b34055814150327f8584029a18d2c0f67e7 Mon Sep 17 00:00:00 2001 From: translators Date: Sun, 1 Jul 2018 19:45:40 +0200 Subject: [PATCH 14/15] Update: Translations from eints croatian: 4 changes by VoyagerOne --- src/lang/croatian.txt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/lang/croatian.txt b/src/lang/croatian.txt index 3d55e1ce4e..10f6ca94f4 100644 --- a/src/lang/croatian.txt +++ b/src/lang/croatian.txt @@ -977,10 +977,10 @@ STR_NEWS_EXCLUSIVE_RIGHTS_DESCRIPTION :{BIG_FONT}{BLAC # Extra view window STR_EXTRA_VIEW_PORT_TITLE :{WHITE}Mini pogled {COMMA} -STR_EXTRA_VIEW_MOVE_VIEW_TO_MAIN :{BLACK}Kopiraj u mini pogled +STR_EXTRA_VIEW_MOVE_VIEW_TO_MAIN :{BLACK}Promijeni pogled STR_EXTRA_VIEW_MOVE_VIEW_TO_MAIN_TT :{BLACK}Kopiraj lokaciju globalnog pogleda u ovaj mini pogled -STR_EXTRA_VIEW_MOVE_MAIN_TO_VIEW :{BLACK}Zalijepi iz mini pogleda -STR_EXTRA_VIEW_MOVE_MAIN_TO_VIEW_TT :{BLACK}Zalijepi lokaciju ovog mini pogleda u globalni pogled +STR_EXTRA_VIEW_MOVE_MAIN_TO_VIEW :{BLACK}Promijeni glavni pogled +STR_EXTRA_VIEW_MOVE_MAIN_TO_VIEW_TT :{BLACK}Kopiraj lokaciju ovog mini pogleda u glavni pogled # Game options window STR_GAME_OPTIONS_CAPTION :{WHITE}Postavke igre @@ -2384,6 +2384,7 @@ STR_LINKGRAPH_LEGEND_CAPTION :{BLACK}Kazalo p STR_LINKGRAPH_LEGEND_ALL :{BLACK}Sve STR_LINKGRAPH_LEGEND_NONE :{BLACK}Ništa STR_LINKGRAPH_LEGEND_SELECT_COMPANIES :{BLACK}Odaberi tvrtke koje će se prikazati +STR_LINKGRAPH_LEGEND_COMPANY_TOOLTIP :{BLACK}{STRING}{}{COMPANY} # Linkgraph legend window and linkgraph legend in smallmap STR_LINKGRAPH_LEGEND_UNUSED :{TINY_FONT}{BLACK}nekorišten From 00b1fe62469ee20ce9de6818c9c075bffba6bd54 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Mon, 2 Jul 2018 19:20:59 +0100 Subject: [PATCH 15/15] Cargo type orders: Add support for 64 cargo types --- src/cargo_type.h | 2 +- src/linkgraph/refresh.cpp | 12 ++++++------ src/linkgraph/refresh.h | 6 +++--- src/order_base.h | 22 +++++++++++----------- src/order_cmd.cpp | 14 +++++++------- src/saveload/extended_ver_sl.cpp | 2 +- src/saveload/order_sl.cpp | 3 ++- src/vehicle.cpp | 14 +++++++------- src/vehicle_base.h | 2 +- 9 files changed, 39 insertions(+), 38 deletions(-) diff --git a/src/cargo_type.h b/src/cargo_type.h index c84f1f4902..1eca0edff6 100644 --- a/src/cargo_type.h +++ b/src/cargo_type.h @@ -72,7 +72,7 @@ enum CargoType { typedef uint64 CargoTypes; -static const CargoTypes ALL_CARGOTYPES = (CargoTypes)UINT32_MAX; +static const CargoTypes ALL_CARGOTYPES = (CargoTypes)UINT64_MAX; /** Class for storing amounts of cargo */ struct CargoArray { diff --git a/src/linkgraph/refresh.cpp b/src/linkgraph/refresh.cpp index c28876fca0..70850c791c 100644 --- a/src/linkgraph/refresh.cpp +++ b/src/linkgraph/refresh.cpp @@ -26,16 +26,16 @@ * @param is_full_loading If the vehicle is full loading. * @param cargo_mask Mask of cargoes to refresh */ -/* static */ void LinkRefresher::Run(Vehicle *v, bool allow_merge, bool is_full_loading, uint32 cargo_mask) +/* static */ void LinkRefresher::Run(Vehicle *v, bool allow_merge, bool is_full_loading, CargoTypes cargo_mask) { /* If there are no orders we can't predict anything.*/ if (v->orders.list == NULL) return; - uint32 have_cargo_mask = v->GetLastLoadingStationValidCargoMask(); + CargoTypes have_cargo_mask = v->GetLastLoadingStationValidCargoMask(); /* Scan orders for cargo-specific load/unload, and run LinkRefresher separately for each set of cargoes where they differ. */ while (cargo_mask != 0) { - uint32 iter_cargo_mask = cargo_mask; + CargoTypes iter_cargo_mask = cargo_mask; for (const Order *o = v->orders.list->GetFirstOrder(); o != NULL; o = o->next) { if (o->IsType(OT_GOTO_STATION) || o->IsType(OT_IMPLICIT)) { if (o->GetUnloadType() == OUFB_CARGO_TYPE_UNLOAD) { @@ -92,7 +92,7 @@ bool LinkRefresher::Hop::operator<(const Hop &other) const * @param allow_merge If the refresher is allowed to merge or extend link graphs. * @param is_full_loading If the vehicle is full loading. */ -LinkRefresher::LinkRefresher(Vehicle *vehicle, HopSet *seen_hops, bool allow_merge, bool is_full_loading, uint32 cargo_mask) : +LinkRefresher::LinkRefresher(Vehicle *vehicle, HopSet *seen_hops, bool allow_merge, bool is_full_loading, CargoTypes cargo_mask) : vehicle(vehicle), seen_hops(seen_hops), cargo(CT_INVALID), allow_merge(allow_merge), is_full_loading(is_full_loading), cargo_mask(cargo_mask) { @@ -199,7 +199,7 @@ const Order *LinkRefresher::PredictNextOrder(const Order *cur, const Order *next SetBit(flags, USE_NEXT); if (next->IsType(OT_CONDITIONAL)) { - uint32 this_cargo_mask = this->cargo_mask; + CargoTypes this_cargo_mask = this->cargo_mask; const Order *skip_to = this->vehicle->orders.list->GetNextDecisionNode( this->vehicle->orders.list->GetOrderAt(next->GetConditionSkipToOrder()), num_hops, this_cargo_mask); assert(this_cargo_mask == this->cargo_mask); @@ -215,7 +215,7 @@ const Order *LinkRefresher::PredictNextOrder(const Order *cur, const Order *next /* Reassign next with the following stop. This can be a station or a * depot.*/ - uint32 this_cargo_mask = this->cargo_mask; + CargoTypes this_cargo_mask = this->cargo_mask; next = this->vehicle->orders.list->GetNextDecisionNode( this->vehicle->orders.list->GetNext(next), num_hops++, this_cargo_mask); assert(this_cargo_mask == this->cargo_mask); diff --git a/src/linkgraph/refresh.h b/src/linkgraph/refresh.h index 0b834a3e54..f903bbb0e4 100644 --- a/src/linkgraph/refresh.h +++ b/src/linkgraph/refresh.h @@ -23,7 +23,7 @@ */ class LinkRefresher { public: - static void Run(Vehicle *v, bool allow_merge = true, bool is_full_loading = false, uint32 cargo_mask = ~0); + static void Run(Vehicle *v, bool allow_merge = true, bool is_full_loading = false, CargoTypes cargo_mask = ALL_CARGOTYPES); protected: /** @@ -89,9 +89,9 @@ protected: CargoID cargo; ///< Cargo given in last refit order. bool allow_merge; ///< If the refresher is allowed to merge or extend link graphs. bool is_full_loading; ///< If the vehicle is full loading. - uint32 cargo_mask; ///< Bit-mask of cargo IDs to refresh. + CargoTypes cargo_mask; ///< Bit-mask of cargo IDs to refresh. - LinkRefresher(Vehicle *v, HopSet *seen_hops, bool allow_merge, bool is_full_loading, uint32 cargo_mask); + LinkRefresher(Vehicle *v, HopSet *seen_hops, bool allow_merge, bool is_full_loading, CargoTypes cargo_mask); bool HandleRefit(CargoID refit_cargo); void ResetRefit(); diff --git a/src/order_base.h b/src/order_base.h index af78e0fb60..3f59a22889 100644 --- a/src/order_base.h +++ b/src/order_base.h @@ -229,11 +229,11 @@ public: return ouf; } - template uint32 FilterLoadUnloadTypeCargoMask(F filter_func, uint32 cargo_mask = ~0) + template CargoTypes FilterLoadUnloadTypeCargoMask(F filter_func, CargoTypes cargo_mask = ALL_CARGOTYPES) { if ((this->GetLoadType() == OLFB_CARGO_TYPE_LOAD) || (this->GetUnloadType() == OUFB_CARGO_TYPE_UNLOAD)) { CargoID cargo; - uint32 output_mask = cargo_mask; + CargoTypes output_mask = cargo_mask; FOR_EACH_SET_BIT(cargo, cargo_mask) { if (!filter_func(this, cargo)) ClrBit(output_mask, cargo); } @@ -395,10 +395,10 @@ void InsertOrder(Vehicle *v, Order *new_o, VehicleOrderID sel_ord); void DeleteOrder(Vehicle *v, VehicleOrderID sel_ord); struct CargoMaskedStationIDStack { - uint32 cargo_mask; + CargoTypes cargo_mask; StationIDStack station; - CargoMaskedStationIDStack(uint32 cargo_mask, StationIDStack station) + CargoMaskedStationIDStack(CargoTypes cargo_mask, StationIDStack station) : cargo_mask(cargo_mask), station(station) {} }; @@ -409,7 +409,7 @@ private: public: CargoStationIDStackSet() - : first(~0, INVALID_STATION) {} + : first(ALL_CARGOTYPES, INVALID_STATION) {} const StationIDStack& Get(CargoID cargo) const { @@ -423,21 +423,21 @@ public: void FillNextStoppingStation(const Vehicle *v, const OrderList *o, const Order *first = NULL, uint hops = 0); }; -template uint32 FilterCargoMask(F filter_func, uint32 cargo_mask = ~0) +template CargoTypes FilterCargoMask(F filter_func, CargoTypes cargo_mask = ALL_CARGOTYPES) { CargoID cargo; - uint32 output_mask = cargo_mask; + CargoTypes output_mask = cargo_mask; FOR_EACH_SET_BIT(cargo, cargo_mask) { if (!filter_func(cargo)) ClrBit(output_mask, cargo); } return output_mask; } -template T CargoMaskValueFilter(uint32 &cargo_mask, F filter_func) +template T CargoMaskValueFilter(CargoTypes &cargo_mask, F filter_func) { CargoID first_cargo_id = FindFirstBit(cargo_mask); T value = filter_func(first_cargo_id); - uint32 other_cargo_mask = cargo_mask; + CargoTypes other_cargo_mask = cargo_mask; ClrBit(other_cargo_mask, first_cargo_id); CargoID cargo; FOR_EACH_SET_BIT(cargo, other_cargo_mask) { @@ -518,8 +518,8 @@ public: */ inline VehicleOrderID GetNumManualOrders() const { return this->num_manual_orders; } - CargoMaskedStationIDStack GetNextStoppingStation(const Vehicle *v, uint32 cargo_mask, const Order *first = NULL, uint hops = 0) const; - const Order *GetNextDecisionNode(const Order *next, uint hops, uint32 &cargo_mask) const; + CargoMaskedStationIDStack GetNextStoppingStation(const Vehicle *v, CargoTypes cargo_mask, const Order *first = NULL, uint hops = 0) const; + const Order *GetNextDecisionNode(const Order *next, uint hops, CargoTypes &cargo_mask) const; void InsertOrderAt(Order *new_order, int index); void DeleteOrderAt(int index); diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp index f42a3806d3..576c0d3f74 100644 --- a/src/order_cmd.cpp +++ b/src/order_cmd.cpp @@ -309,13 +309,13 @@ void Order::DeAllocExtraInfo() void CargoStationIDStackSet::FillNextStoppingStation(const Vehicle *v, const OrderList *o, const Order *first, uint hops) { this->more.clear(); - this->first = o->GetNextStoppingStation(v, ~0, first, hops); - if (this->first.cargo_mask != (uint32) ~0) { - uint32 have_cargoes = this->first.cargo_mask; + this->first = o->GetNextStoppingStation(v, ALL_CARGOTYPES, first, hops); + if (this->first.cargo_mask != ALL_CARGOTYPES) { + CargoTypes have_cargoes = this->first.cargo_mask; do { this->more.push_back(o->GetNextStoppingStation(v, ~have_cargoes, first, hops)); have_cargoes |= this->more.back().cargo_mask; - } while (have_cargoes != (uint32) ~0); + } while (have_cargoes != ALL_CARGOTYPES); } } @@ -402,7 +402,7 @@ Order *OrderList::GetOrderAt(int index) const * \li a non-trivial conditional order * \li NULL if the vehicle won't stop anymore. */ -const Order *OrderList::GetNextDecisionNode(const Order *next, uint hops, uint32 &cargo_mask) const +const Order *OrderList::GetNextDecisionNode(const Order *next, uint hops, CargoTypes &cargo_mask) const { assert(cargo_mask != 0); @@ -448,14 +448,14 @@ const Order *OrderList::GetNextDecisionNode(const Order *next, uint hops, uint32 /** * Recursively determine the next deterministic station to stop at. * @param v The vehicle we're looking at. - * @param uint32 cargo_mask Bit-set of the cargo IDs of interest. + * @param CargoTypes cargo_mask Bit-set of the cargo IDs of interest. * @param first Order to start searching at or NULL to start at cur_implicit_order_index + 1. * @param hops Number of orders we have already looked at. * @return A CargoMaskedStationIDStack of the cargo mask the result is valid for, and the next stoppping station or INVALID_STATION. * @pre The vehicle is currently loading and v->last_station_visited is meaningful. * @note This function may draw a random number. Don't use it from the GUI. */ -CargoMaskedStationIDStack OrderList::GetNextStoppingStation(const Vehicle *v, uint32 cargo_mask, const Order *first, uint hops) const +CargoMaskedStationIDStack OrderList::GetNextStoppingStation(const Vehicle *v, CargoTypes cargo_mask, const Order *first, uint hops) const { assert(cargo_mask != 0); diff --git a/src/saveload/extended_ver_sl.cpp b/src/saveload/extended_ver_sl.cpp index a5d4170242..49446f3d44 100644 --- a/src/saveload/extended_ver_sl.cpp +++ b/src/saveload/extended_ver_sl.cpp @@ -45,7 +45,7 @@ std::vector _sl_xv_discardable_chunk_ids; ///< list of chunks static const uint32 _sl_xv_slxi_chunk_version = 0; ///< current version os SLXI chunk const SlxiSubChunkInfo _sl_xv_sub_chunk_infos[] = { - { XSLFI_CARGO_TYPE_ORDERS, XSCF_NULL, 2, 2, "cargo_type_orders", NULL, NULL, "ORDX,VEOX" }, + { XSLFI_CARGO_TYPE_ORDERS, XSCF_NULL, 3, 3, "cargo_type_orders", NULL, NULL, "ORDX,VEOX" }, { XSLFI_NULL, XSCF_NULL, 0, 0, NULL, NULL, NULL, NULL },// This is the end marker }; diff --git a/src/saveload/order_sl.cpp b/src/saveload/order_sl.cpp index 03335506ff..108a251243 100644 --- a/src/saveload/order_sl.cpp +++ b/src/saveload/order_sl.cpp @@ -197,7 +197,8 @@ static void Load_ORDR() const SaveLoad *GetOrderExtraInfoDescription() { static const SaveLoad _order_extra_info_desc[] = { - SLE_ARR(OrderExtraInfo, cargo_type_flags, SLE_UINT8, NUM_CARGO), + SLE_CONDARR_X(OrderExtraInfo, cargo_type_flags, SLE_UINT8, 32, 0, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_CARGO_TYPE_ORDERS, 1, 2)), + SLE_CONDARR_X(OrderExtraInfo, cargo_type_flags, SLE_UINT8, NUM_CARGO, 0, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_CARGO_TYPE_ORDERS, 3)), SLE_END() }; diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 2c564a65ee..cb95924e98 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -2168,12 +2168,12 @@ void Vehicle::CancelReservation(StationID next, Station *st) } } -uint32 Vehicle::GetLastLoadingStationValidCargoMask() const +CargoTypes Vehicle::GetLastLoadingStationValidCargoMask() const { if (!HasBit(this->vehicle_flags, VF_LAST_LOAD_ST_SEP)) { - return (this->last_loading_station != INVALID_STATION) ? ~0 : 0; + return (this->last_loading_station != INVALID_STATION) ? ALL_CARGOTYPES : 0; } else { - uint32 cargo_mask = 0; + CargoTypes cargo_mask = 0; for (const Vehicle *u = this; u != NULL; u = u->Next()) { if (u->cargo_type < NUM_CARGO && u->last_loading_station != INVALID_STATION) { SetBit(cargo_mask, u->cargo_type); @@ -2197,11 +2197,11 @@ void Vehicle::LeaveStation() /* Only update the timetable if the vehicle was supposed to stop here. */ if (this->current_order.GetNonStopType() != ONSF_STOP_EVERYWHERE) UpdateVehicleTimetable(this, false); - uint32 cargoes_can_load_unload = this->current_order.FilterLoadUnloadTypeCargoMask([&](const Order *o, CargoID cargo) { + CargoTypes cargoes_can_load_unload = this->current_order.FilterLoadUnloadTypeCargoMask([&](const Order *o, CargoID cargo) { return ((o->GetCargoLoadType(cargo) & OLFB_NO_LOAD) == 0) || ((o->GetCargoUnloadType(cargo) & OUFB_NO_UNLOAD) == 0); }); - uint32 has_cargo_mask = this->GetLastLoadingStationValidCargoMask(); - uint32 cargoes_can_leave_with_cargo = FilterCargoMask([&](CargoID cargo) { + CargoTypes has_cargo_mask = this->GetLastLoadingStationValidCargoMask(); + CargoTypes cargoes_can_leave_with_cargo = FilterCargoMask([&](CargoID cargo) { return this->current_order.CanLeaveWithCargo(HasBit(has_cargo_mask, cargo), cargo); }, cargoes_can_load_unload); @@ -2214,7 +2214,7 @@ void Vehicle::LeaveStation() LinkRefresher::Run(this, true, false, cargoes_can_leave_with_cargo); } - if (cargoes_can_leave_with_cargo == (uint32) ~0) { + if (cargoes_can_leave_with_cargo == ALL_CARGOTYPES) { /* can leave with all cargoes */ /* if the vehicle could load here or could stop with cargo loaded set the last loading station */ diff --git a/src/vehicle_base.h b/src/vehicle_base.h index e4fe4e6acc..3f359fe946 100644 --- a/src/vehicle_base.h +++ b/src/vehicle_base.h @@ -337,7 +337,7 @@ public: /** We want to 'destruct' the right class. */ virtual ~Vehicle(); - uint32 GetLastLoadingStationValidCargoMask() const; + CargoTypes GetLastLoadingStationValidCargoMask() const; void BeginLoading(); void CancelReservation(StationID next, Station *st);