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 c543faa0dd..2dcafac4d1 100644 --- a/src/blitter/32bpp_anim.cpp +++ b/src/blitter/32bpp_anim.cpp @@ -461,7 +461,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/cargo_type.h b/src/cargo_type.h index 402e81c1b2..1eca0edff6 100644 --- a/src/cargo_type.h +++ b/src/cargo_type.h @@ -63,16 +63,16 @@ 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; +static const CargoTypes ALL_CARGOTYPES = (CargoTypes)UINT64_MAX; /** Class for storing amounts of cargo */ struct CargoArray { diff --git a/src/company_base.h b/src/company_base.h index 5283ee764d..339a4179c9 100644 --- a/src/company_base.h +++ b/src/company_base.h @@ -98,7 +98,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() { 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 2cfed84e35..dcb69c20d1 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -728,9 +728,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/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/house.h b/src/house.h index 17aee20c7f..69928311f8 100644 --- a/src/house.h +++ b/src/house.h @@ -146,6 +146,6 @@ static inline HouseID GetTranslatedHouseID(HouseID hid) StringID GetHouseName(HouseID house, TileIndex tile = INVALID_TILE); void DrawHouseImage(HouseID house_id, int left, int top, int right, int bottom); void AddProducedHouseCargo(HouseID house_id, TileIndex tile, CargoArray &produced); -void AddAcceptedHouseCargo(HouseID house_id, TileIndex tile, CargoArray &acceptance, uint32 *always_accepted = NULL); +void AddAcceptedHouseCargo(HouseID house_id, TileIndex tile, CargoArray &acceptance, CargoTypes *always_accepted = NULL); #endif /* HOUSE_H */ diff --git a/src/landscape.cpp b/src/landscape.cpp index f632821fe2..921de6f153 100644 --- a/src/landscape.cpp +++ b/src/landscape.cpp @@ -1089,8 +1089,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/lang/croatian.txt b/src/lang/croatian.txt index 8d2bd41749..5f86c85323 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 @@ -2382,6 +2382,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 diff --git a/src/lang/french.txt b/src/lang/french.txt index 93998105de..24bdd02e42 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 @@ -2287,6 +2287,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é diff --git a/src/lang/italian.txt b/src/lang/italian.txt index 8a2ad95be9..7d542ab889 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 @@ -2312,6 +2312,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 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 da15fbbebd..bc49388f61 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/newgrf_house.h b/src/newgrf_house.h index 799f6ec39a..f54246be10 100644 --- a/src/newgrf_house.h +++ b/src/newgrf_house.h @@ -122,7 +122,7 @@ void AnimateNewHouseConstruction(TileIndex tile); uint16 GetHouseCallback(CallbackID callback, uint32 param1, uint32 param2, HouseID house_id, Town *town = NULL, TileIndex tile = INVALID_TILE, bool not_yet_constructed = false, uint8 initial_random_bits = 0, CargoTypes watched_cargo_triggers = 0); -void WatchedCargoCallback(TileIndex tile, uint32 trigger_cargoes); +void WatchedCargoCallback(TileIndex tile, CargoTypes trigger_cargoes); bool HouseAllowsConstruction(HouseID house_id, TileIndex tile, Town *t, byte random_bits); bool CanDeleteHouse(TileIndex tile); 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/order_base.h b/src/order_base.h index 90b9f1af75..620c927168 100644 --- a/src/order_base.h +++ b/src/order_base.h @@ -273,11 +273,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); } @@ -463,10 +463,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) {} }; @@ -477,7 +477,7 @@ private: public: CargoStationIDStackSet() - : first(~0, INVALID_STATION) {} + : first(ALL_CARGOTYPES, INVALID_STATION) {} const StationIDStack& Get(CargoID cargo) const { @@ -491,21 +491,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) { @@ -598,8 +598,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 1cb902e248..c68067b166 100644 --- a/src/order_cmd.cpp +++ b/src/order_cmd.cpp @@ -353,13 +353,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); } } @@ -466,7 +466,7 @@ VehicleOrderID OrderList::GetIndexOfOrder(const Order *order) 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); @@ -512,14 +512,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/order_gui.cpp b/src/order_gui.cpp index d98556a7cc..6934224bd6 100644 --- a/src/order_gui.cpp +++ b/src/order_gui.cpp @@ -1068,8 +1068,6 @@ private: Scrollbar *vscroll; bool can_do_refit; ///< Vehicle chain can be refitted in depot. bool can_do_autorefit; ///< Vehicle chain can be auto-refitted. - StringID cargo_names_list[NUM_CARGO + 1]; - uint32 cargo_bitmask; int query_text_widget; ///< widget which most recently called ShowQueryString /** @@ -1437,18 +1435,6 @@ public: size->width = WD_FRAMERECT_LEFT + GetStringBoundingBox(STR_ORDERS_OCCUPANCY_PERCENT).width + 10 + WD_FRAMERECT_RIGHT; break; } - - - /* Create cargo bitmask */ - assert_compile(NUM_CARGO <= 32); - for (CargoID c = 0; c < NUM_CARGO; c++) { - if (CargoSpec::Get(c)->IsValid()) { - this->cargo_names_list[c] = CargoSpec::Get(c)->name; - SetBit(this->cargo_bitmask, c); - } - } - this->cargo_bitmask = ~this->cargo_bitmask; - this->cargo_names_list[NUM_CARGO] = INVALID_STRING_ID; } /** @@ -1676,7 +1662,11 @@ public: bool is_slot_occupancy = (ocv == OCV_SLOT_OCCUPANCY); if (is_cargo) { - this->GetWidget(WID_O_COND_CARGO)->widget_data = cargo_names_list[(order == NULL) ? 0 : order->GetConditionValue()]; + if (order == NULL || !CargoSpec::Get(order->GetConditionValue())->IsValid()) { + this->GetWidget(WID_O_COND_CARGO)->widget_data = STR_NEWGRF_INVALID_CARGO; + } else { + this->GetWidget(WID_O_COND_CARGO)->widget_data = CargoSpec::Get(order->GetConditionValue())->name; + } this->GetWidget(WID_O_SEL_COND_VALUE)->SetDisplayedPlane(DP_COND_VALUE_CARGO); } else if (is_slot_occupancy) { TraceRestrictSlotID slot_id = (order != nullptr && TraceRestrictSlot::IsValidID(order->GetXData()) ? order->GetXData() : INVALID_TRACE_RESTRICT_SLOT_ID); @@ -2034,7 +2024,16 @@ public: case WID_O_COND_CARGO: { uint value = this->vehicle->GetOrder(this->OrderGetSel())->GetConditionValue(); - ShowDropDownMenu(this, cargo_names_list, value, WID_O_COND_CARGO, 0, cargo_bitmask); + DropDownList *list = new DropDownList(); + for (size_t i = 0; i < _sorted_standard_cargo_specs_size; ++i) { + const CargoSpec *cs = _sorted_cargo_specs[i]; + *list->Append() = new DropDownListStringItem(cs->name, cs->Index(), false); + } + if (list->Length() == 0) { + delete list; + return; + } + ShowDropDownList(this, list, value, WID_O_COND_CARGO, 0); break; } diff --git a/src/pathfinder/follow_track.hpp b/src/pathfinder/follow_track.hpp index 1dee7ff6ec..4f901d6ed3 100644 --- a/src/pathfinder/follow_track.hpp +++ b/src/pathfinder/follow_track.hpp @@ -74,7 +74,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 */ @@ -228,8 +229,6 @@ protected: m_is_station = true; } else if (IsRoadTT() && IsRoadStopTile(m_new_tile)) { m_is_station = true; - } else { - m_is_station = false; } } @@ -242,7 +241,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 18c3b8a10b..c97a4172f2 100644 --- a/src/pathfinder/npf/npf.cpp +++ b/src/pathfinder/npf/npf.cpp @@ -814,7 +814,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)) { @@ -907,7 +907,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; @@ -931,7 +931,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 27bd3a1975..b14e9efefb 100644 --- a/src/pathfinder/opf/opf_ship.cpp +++ b/src/pathfinder/opf/opf_ship.cpp @@ -193,9 +193,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) { @@ -205,13 +210,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 (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 } /* And if we would not reverse? */ @@ -219,6 +226,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_costrail.hpp b/src/pathfinder/yapf/yapf_costrail.hpp index bd439b037c..939d6afbe7 100644 --- a/src/pathfinder/yapf/yapf_costrail.hpp +++ b/src/pathfinder/yapf/yapf_costrail.hpp @@ -105,7 +105,7 @@ public: assert(IsValidTrackdir(td2)); int cost = 0; if (TrackFollower::Allow90degTurns() - && ((TrackdirToTrackdirBits(td2) & (TrackdirBits)TrackdirCrossesTrackdirs(td1)) != 0)) { + && HasTrackdir(TrackdirCrossesTrackdirs(td1), td2)) { /* 90-deg curve penalty */ cost += Yapf().PfGetSettings().rail_curve90_penalty; } else if (td2 != NextTrackdir(td1)) { @@ -418,7 +418,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 03519b059f..1d1833fbfd 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) && HasTrackdir(m_destTrackdirs, td); } /** diff --git a/src/pathfinder/yapf/yapf_road.cpp b/src/pathfinder/yapf/yapf_road.cpp index 72de255d08..d86de74292 100644 --- a/src/pathfinder/yapf/yapf_road.cpp +++ b/src/pathfinder/yapf/yapf_road.cpp @@ -197,8 +197,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) @@ -273,7 +272,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); } /** @@ -433,7 +432,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; @@ -516,7 +515,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 71b19adbf9..e124189f9d 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/pbs.cpp b/src/pbs.cpp index f83cd78b7b..87cfc6c159 100644 --- a/src/pbs.cpp +++ b/src/pbs.cpp @@ -100,7 +100,7 @@ bool TryReserveRailTrackdir(TileIndex tile, Trackdir td, bool trigger_stations) */ 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 */ @@ -187,7 +187,7 @@ void UnreserveRailTrackdir(TileIndex tile, Trackdir td) */ 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)) { diff --git a/src/rev.cpp.in b/src/rev.cpp.in index cb34b04295..89c95e2b49 100644 --- a/src/rev.cpp.in +++ b/src/rev.cpp.in @@ -70,13 +70,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__ /** diff --git a/src/saveload/company_sl.cpp b/src/saveload/company_sl.cpp index 7749017181..7c673334bd 100644 --- a/src/saveload/company_sl.cpp +++ b/src/saveload/company_sl.cpp @@ -355,7 +355,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() @@ -511,7 +512,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 */ diff --git a/src/saveload/economy_sl.cpp b/src/saveload/economy_sl.cpp index 0bc5ff4bd2..d1235f0d36 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/extended_ver_sl.cpp b/src/saveload/extended_ver_sl.cpp index 5345389bb6..4ee13e9457 100644 --- a/src/saveload/extended_ver_sl.cpp +++ b/src/saveload/extended_ver_sl.cpp @@ -72,7 +72,7 @@ const SlxiSubChunkInfo _sl_xv_sub_chunk_infos[] = { { XSLFI_LINKGRAPH_DAY_SCALE, XSCF_NULL, 1, 1, "linkgraph_day_scale", NULL, NULL, NULL }, { XSLFI_TEMPLATE_REPLACEMENT, XSCF_NULL, 4, 4, "template_replacement", NULL, NULL, "TRPL,TMPL" }, { XSLFI_MORE_RAIL_TYPES, XSCF_NULL, 1, 1, "more_rail_types", NULL, NULL, NULL }, - { 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_EXTENDED_GAMELOG, XSCF_NULL, 1, 1, "extended_gamelog", NULL, NULL, NULL }, { XSLFI_STATION_CATCHMENT_INC, XSCF_NULL, 1, 1, "station_catchment_inc", NULL, NULL, NULL }, { XSLFI_CUSTOM_BRIDGE_HEADS, XSCF_NULL, 1, 1, "custom_bridge_heads", NULL, NULL, NULL }, diff --git a/src/saveload/order_sl.cpp b/src/saveload/order_sl.cpp index 23ffe6725a..6e9aef4a6c 100644 --- a/src/saveload/order_sl.cpp +++ b/src/saveload/order_sl.cpp @@ -202,9 +202,10 @@ 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_CONDVAR_X(OrderExtraInfo, xflags, SLE_UINT8, 0, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_TIMETABLE_EXTRA)), - SLE_CONDVAR_X(OrderExtraInfo, xdata, SLE_UINT32, 0, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_ORDER_EXTRA_DATA)), + 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_CONDVAR_X(OrderExtraInfo, xflags, SLE_UINT8, 0, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_TIMETABLE_EXTRA)), + SLE_CONDVAR_X(OrderExtraInfo, xdata, SLE_UINT32, 0, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_ORDER_EXTRA_DATA)), SLE_END() }; diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp index 7aad41704a..b27b49888b 100644 --- a/src/saveload/saveload.cpp +++ b/src/saveload/saveload.cpp @@ -275,8 +275,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. const uint16 SAVEGAME_VERSION_EXT = 0x8000; ///< Savegame extension indicator mask SavegameType _savegame_type; ///< type of savegame we are loading diff --git a/src/saveload/saveload.h b/src/saveload/saveload.h index e306aab8ce..77019ebd2c 100644 --- a/src/saveload/saveload.h +++ b/src/saveload/saveload.h @@ -573,7 +573,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/saveload/station_sl.cpp b/src/saveload/station_sl.cpp index 6fee7d5809..f0759d313f 100644 --- a/src/saveload/station_sl.cpp +++ b/src/saveload/station_sl.cpp @@ -351,6 +351,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(); @@ -359,7 +360,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()); @@ -400,10 +400,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()); @@ -467,7 +468,8 @@ static const SaveLoad _station_desc[] = { SLEG_CONDVAR_X(_old_last_vehicle_type, SLE_UINT8, 0, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_ST_LAST_VEH_TYPE, 0, 0)), SLE_VAR(Station, had_vehicle_of_type, SLE_UINT8), SLE_VEC(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() }; @@ -555,6 +557,7 @@ static void Load_STNN() { _num_flows = 0; + const uint num_cargo = IsSavegameVersionBefore(199) ? 32 : NUM_CARGO; ReadBuffer *buffer = ReadBuffer::GetCurrent(); int index; @@ -575,7 +578,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; @@ -624,9 +627,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 e83a28831d..a2c56d444f 100644 --- a/src/saveload/town_sl.cpp +++ b/src/saveload/town_sl.cpp @@ -193,7 +193,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), @@ -288,12 +289,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); } if (SlXvIsFeaturePresent(XSLFI_SPRINGPP)) { diff --git a/src/strings.cpp b/src/strings.cpp index 5ab89b8ab2..b41a57f3e3 100644 --- a/src/strings.cpp +++ b/src/strings.cpp @@ -1342,7 +1342,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; diff --git a/src/table/settings.h.preamble b/src/table/settings.h.preamble index 8e53410de6..9adc7e79fa 100644 --- a/src/table/settings.h.preamble +++ b/src/table/settings.h.preamble @@ -77,7 +77,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, extver, patxname) #define SDTG_STR(name, type, flags, guiflags, var, def, str, strhelp, strval, proc, from, to, cat, extver, patxname)\ - 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, extver, patxname) + 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, extver, patxname) #define SDTG_OMANY(name, type, flags, guiflags, var, def, max, full, str, strhelp, strval, proc, from, to, cat, extver, patxname)\ SDTG_GENERAL(name, SDT_ONEOFMANY, SL_VAR, type, flags, guiflags, var, 0, def, 0, max, 0, full, str, strhelp, strval, proc, from, to, cat, extver, patxname) @@ -108,7 +108,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, extver, patxname) #define SDT_STR(base, var, type, flags, guiflags, def, str, strhelp, strval, proc, from, to, cat, extver, patxname)\ - 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, extver, patxname) + 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, extver, patxname) #define SDT_CHR(base, var, flags, guiflags, def, str, strhelp, strval, proc, from, to, cat, extver, patxname)\ 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, extver, patxname) @@ -133,7 +133,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, extver, patxname) #define SDTC_STR(var, type, flags, guiflags, def, str, strhelp, strval, proc, from, to, cat, extver, patxname)\ - 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, extver, patxname) + 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, extver, patxname) #define SDTC_OMANY(var, type, flags, guiflags, def, max, full, str, strhelp, strval, proc, from, to, cat, extver, patxname)\ 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, extver, patxname) diff --git a/src/town_gui.cpp b/src/town_gui.cpp index 381aeb1d23..46acb72db8 100644 --- a/src/town_gui.cpp +++ b/src/town_gui.cpp @@ -1548,7 +1548,7 @@ public: static char buff[DRAW_STRING_BUFFER] = ""; char *str = buff; CargoArray cargo; - uint32 dummy = 0; + CargoTypes dummy = 0; AddAcceptedHouseCargo(this->display_house, INVALID_TILE, cargo, &dummy); for (uint i = 0; i < NUM_CARGO; i++) { if (cargo[i] == 0) continue; diff --git a/src/track_func.h b/src/track_func.h index aa5336447a..ce38d54be8 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 trackdir < TRACKDIR_END && ((1 << trackdir & TRACKDIR_BIT_MASK) != 0); + return trackdir < TRACKDIR_END && ((1 << trackdir & TRACKDIR_BIT_MASK) != TRACKDIR_BIT_NONE); } /** @@ -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. * diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 107fdd1454..3cb30f6787 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -2721,12 +2721,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); @@ -2761,11 +2761,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); @@ -2778,7 +2778,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 a2f37abbd1..bfc28db4a3 100644 --- a/src/vehicle_base.h +++ b/src/vehicle_base.h @@ -349,7 +349,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); 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); }