Merge branch 'cargo_type_order' into jgrpp

# Conflicts:
#	src/pathfinder/yapf/yapf_common.hpp
#	src/saveload/extended_ver_sl.cpp
#	src/saveload/order_sl.cpp
#	src/saveload/station_sl.cpp
#	src/track_func.h
This commit is contained in:
Jonathan G Rennison
2018-07-02 21:04:06 +01:00
45 changed files with 183 additions and 145 deletions

View File

@@ -90,7 +90,7 @@ public:
{ {
_vals[idx].~T(); _vals[idx].~T();
if(idx < (_size - 1)) { if(idx < (_size - 1)) {
memmove(&_vals[idx], &_vals[idx+1], sizeof(T) * (_size - (size_t)idx - 1)); memmove(static_cast<void *>(&_vals[idx]), &_vals[idx+1], sizeof(T) * (_size - (size_t)idx - 1));
} }
_size--; _size--;
} }

View File

@@ -378,8 +378,7 @@ bool SQVM::StartCall(SQClosure *closure,SQInteger target,SQInteger args,SQIntege
} }
if (!tailcall) { if (!tailcall) {
CallInfo lc; CallInfo lc = {};
memset(&lc, 0, sizeof(lc));
lc._generator = NULL; lc._generator = NULL;
lc._etraps = 0; lc._etraps = 0;
lc._prevstkbase = (SQInt32) ( stackbase - _stackbase ); lc._prevstkbase = (SQInt32) ( stackbase - _stackbase );
@@ -1159,8 +1158,7 @@ bool SQVM::CallNative(SQNativeClosure *nclosure,SQInteger nargs,SQInteger stackb
SQInteger oldtop = _top; SQInteger oldtop = _top;
SQInteger oldstackbase = _stackbase; SQInteger oldstackbase = _stackbase;
_top = stackbase + nargs; _top = stackbase + nargs;
CallInfo lci; CallInfo lci = {};
memset(&lci, 0, sizeof(lci));
lci._closure = nclosure; lci._closure = nclosure;
lci._generator = NULL; lci._generator = NULL;
lci._etraps = 0; lci._etraps = 0;

View File

@@ -40,8 +40,6 @@
template <class T, size_t Tnum_files, bool Tsearch_in_tars> template <class T, size_t Tnum_files, bool Tsearch_in_tars>
bool BaseSet<T, Tnum_files, Tsearch_in_tars>::FillSetDetails(IniFile *ini, const char *path, const char *full_filename, bool allow_empty_filename) bool BaseSet<T, Tnum_files, Tsearch_in_tars>::FillSetDetails(IniFile *ini, const char *path, const char *full_filename, bool allow_empty_filename)
{ {
memset(this, 0, sizeof(*this));
IniGroup *metadata = ini->GetGroup("metadata"); IniGroup *metadata = ini->GetGroup("metadata");
IniItem *item; IniItem *item;

View File

@@ -461,7 +461,7 @@ void Blitter_32bppAnim::CopyFromBuffer(void *video, const void *src, int width,
Colour *dst_pal = dst; Colour *dst_pal = dst;
uint16 *anim_pal = anim_line; uint16 *anim_pal = anim_line;
memcpy(dst, usrc, width * sizeof(uint32)); memcpy(static_cast<void *>(dst), usrc, width * sizeof(uint32));
usrc += width; usrc += width;
dst += _screen.pitch; dst += _screen.pitch;
/* Copy back the anim-buffer */ /* Copy back the anim-buffer */

View File

@@ -63,16 +63,16 @@ enum CargoType {
CT_PLASTIC = 10, CT_PLASTIC = 10,
CT_FIZZY_DRINKS = 11, 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_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_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. 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 */ /** Class for storing amounts of cargo */
struct CargoArray { struct CargoArray {

View File

@@ -98,7 +98,13 @@ struct CompanyProperties {
CompanyEconomyEntry old_economy[MAX_HISTORY_QUARTERS]; ///< Economic data of the company of the last #MAX_HISTORY_QUARTERS quarters. 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. 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() ~CompanyProperties()
{ {

View File

@@ -125,7 +125,7 @@ static inline T *ReallocT(T *t_ptr, size_t num_elements)
/* Ensure the size does not overflow. */ /* Ensure the size does not overflow. */
CheckAllocationConstraints<T>(num_elements); CheckAllocationConstraints<T>(num_elements);
t_ptr = (T*)realloc(t_ptr, num_elements * sizeof(T)); t_ptr = (T*)realloc(static_cast<void *>(t_ptr), num_elements * sizeof(T));
if (t_ptr == NULL) ReallocError(num_elements * sizeof(T)); if (t_ptr == NULL) ReallocError(num_elements * sizeof(T));
return t_ptr; return t_ptr;
} }

View File

@@ -728,9 +728,10 @@ static void CompaniesGenStatistics()
if (!HasBit(1 << 0 | 1 << 3 | 1 << 6 | 1 << 9, _cur_month)) return; if (!HasBit(1 << 0 | 1 << 3 | 1 << 6 | 1 << 9, _cur_month)) return;
FOR_ALL_COMPANIES(c) { 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; 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++; if (c->num_valid_stat_ent != MAX_HISTORY_QUARTERS) c->num_valid_stat_ent++;

View File

@@ -33,8 +33,8 @@
#include "safeguards.h" #include "safeguards.h"
/* Bitmasks of company and cargo indices that shouldn't be drawn. */ /* Bitmasks of company and cargo indices that shouldn't be drawn. */
static uint _legend_excluded_companies; static CompanyMask _legend_excluded_companies;
static uint _legend_excluded_cargo; static CargoTypes _legend_excluded_cargo;
/* Apparently these don't play well with enums. */ /* 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. 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 { struct BaseGraphWindow : Window {
protected: 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_AXIS_LINE_COLOUR = PC_BLACK;
static const int GRAPH_NUM_MONTHS = 24; ///< Number of months displayed in the graph. 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_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. 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_dataset;
byte num_on_x_axis; byte num_on_x_axis;
byte num_vert_lines; byte num_vert_lines;
@@ -561,7 +561,7 @@ public:
*/ */
void UpdateStatistics(bool initialize) void UpdateStatistics(bool initialize)
{ {
uint excluded_companies = _legend_excluded_companies; CompanyMask excluded_companies = _legend_excluded_companies;
/* Exclude the companies which aren't valid */ /* Exclude the companies which aren't valid */
for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) { for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {

View File

@@ -146,6 +146,6 @@ static inline HouseID GetTranslatedHouseID(HouseID hid)
StringID GetHouseName(HouseID house, TileIndex tile = INVALID_TILE); StringID GetHouseName(HouseID house, TileIndex tile = INVALID_TILE);
void DrawHouseImage(HouseID house_id, int left, int top, int right, int bottom); void DrawHouseImage(HouseID house_id, int left, int top, int right, int bottom);
void AddProducedHouseCargo(HouseID house_id, TileIndex tile, CargoArray &produced); 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 */ #endif /* HOUSE_H */

View File

@@ -1089,8 +1089,7 @@ static uint River_Hash(uint tile, uint dir)
*/ */
static void BuildRiver(TileIndex begin, TileIndex end) static void BuildRiver(TileIndex begin, TileIndex end)
{ {
AyStar finder; AyStar finder = {};
MemSetT(&finder, 0);
finder.CalculateG = River_CalculateG; finder.CalculateG = River_CalculateG;
finder.CalculateH = River_CalculateH; finder.CalculateH = River_CalculateH;
finder.GetNeighbours = River_GetNeighbours; finder.GetNeighbours = River_GetNeighbours;

View File

@@ -977,10 +977,10 @@ STR_NEWS_EXCLUSIVE_RIGHTS_DESCRIPTION :{BIG_FONT}{BLAC
# Extra view window # Extra view window
STR_EXTRA_VIEW_PORT_TITLE :{WHITE}Mini pogled {COMMA} 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_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 :{BLACK}Promijeni glavni pogled
STR_EXTRA_VIEW_MOVE_MAIN_TO_VIEW_TT :{BLACK}Zalijepi lokaciju ovog mini pogleda u globalni pogled STR_EXTRA_VIEW_MOVE_MAIN_TO_VIEW_TT :{BLACK}Kopiraj lokaciju ovog mini pogleda u glavni pogled
# Game options window # Game options window
STR_GAME_OPTIONS_CAPTION :{WHITE}Postavke igre 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_ALL :{BLACK}Sve
STR_LINKGRAPH_LEGEND_NONE :{BLACK}Ništa STR_LINKGRAPH_LEGEND_NONE :{BLACK}Ništa
STR_LINKGRAPH_LEGEND_SELECT_COMPANIES :{BLACK}Odaberi tvrtke koje će se prikazati 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 # Linkgraph legend window and linkgraph legend in smallmap
STR_LINKGRAPH_LEGEND_UNUSED :{TINY_FONT}{BLACK}nekorišten STR_LINKGRAPH_LEGEND_UNUSED :{TINY_FONT}{BLACK}nekorišten

View File

@@ -882,10 +882,10 @@ STR_NEWS_EXCLUSIVE_RIGHTS_DESCRIPTION :{BIG_FONT}{BLAC
# Extra view window # Extra view window
STR_EXTRA_VIEW_PORT_TITLE :{WHITE}Vue {COMMA} 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 :{BLACK}Modifier cette 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_VIEW_TO_MAIN_TT :{BLACK}Copier l'emplacement de la vue principale vers cette vue
STR_EXTRA_VIEW_MOVE_MAIN_TO_VIEW :{BLACK}Coller depuis la vue STR_EXTRA_VIEW_MOVE_MAIN_TO_VIEW :{BLACK}Modifier la vue principale
STR_EXTRA_VIEW_MOVE_MAIN_TO_VIEW_TT :{BLACK}Coller l'emplacement de cette vue-ci vers 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 # Game options window
STR_GAME_OPTIONS_CAPTION :{WHITE}Options 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_ALL :{BLACK}Toute
STR_LINKGRAPH_LEGEND_NONE :{BLACK}Aucune STR_LINKGRAPH_LEGEND_NONE :{BLACK}Aucune
STR_LINKGRAPH_LEGEND_SELECT_COMPANIES :{BLACK}Choisir les compagnies à afficher 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 # Linkgraph legend window and linkgraph legend in smallmap
STR_LINKGRAPH_LEGEND_UNUSED :{TINY_FONT}{BLACK}inutilisé STR_LINKGRAPH_LEGEND_UNUSED :{TINY_FONT}{BLACK}inutilisé

View File

@@ -883,9 +883,9 @@ STR_NEWS_EXCLUSIVE_RIGHTS_DESCRIPTION :{BIG_FONT}{BLAC
# Extra view window # Extra view window
STR_EXTRA_VIEW_PORT_TITLE :{WHITE}Mini visuale {COMMA} 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_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 STR_EXTRA_VIEW_MOVE_MAIN_TO_VIEW_TT :{BLACK}Copia la posizione di questa mini visuale nella visuale principale
# Game options window # Game options window
@@ -2312,6 +2312,7 @@ STR_LINKGRAPH_LEGEND_NONE :{BLACK}Nessuno
STR_LINKGRAPH_LEGEND_NONE.ms :{BLACK}Nessuno STR_LINKGRAPH_LEGEND_NONE.ms :{BLACK}Nessuno
STR_LINKGRAPH_LEGEND_NONE.fs :{BLACK}Nessuna STR_LINKGRAPH_LEGEND_NONE.fs :{BLACK}Nessuna
STR_LINKGRAPH_LEGEND_SELECT_COMPANIES :{BLACK}Seleziona le compagnie da mostrare 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 # Linkgraph legend window and linkgraph legend in smallmap
STR_LINKGRAPH_LEGEND_UNUSED :{TINY_FONT}{BLACK}inutilizzata STR_LINKGRAPH_LEGEND_UNUSED :{TINY_FONT}{BLACK}inutilizzata

View File

@@ -26,16 +26,16 @@
* @param is_full_loading If the vehicle is full loading. * @param is_full_loading If the vehicle is full loading.
* @param cargo_mask Mask of cargoes to refresh * @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 there are no orders we can't predict anything.*/
if (v->orders.list == NULL) return; 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. */ /* Scan orders for cargo-specific load/unload, and run LinkRefresher separately for each set of cargoes where they differ. */
while (cargo_mask != 0) { 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) { 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->IsType(OT_GOTO_STATION) || o->IsType(OT_IMPLICIT)) {
if (o->GetUnloadType() == OUFB_CARGO_TYPE_UNLOAD) { 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 allow_merge If the refresher is allowed to merge or extend link graphs.
* @param is_full_loading If the vehicle is full loading. * @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), vehicle(vehicle), seen_hops(seen_hops), cargo(CT_INVALID), allow_merge(allow_merge),
is_full_loading(is_full_loading), cargo_mask(cargo_mask) 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); SetBit(flags, USE_NEXT);
if (next->IsType(OT_CONDITIONAL)) { 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( const Order *skip_to = this->vehicle->orders.list->GetNextDecisionNode(
this->vehicle->orders.list->GetOrderAt(next->GetConditionSkipToOrder()), num_hops, this_cargo_mask); this->vehicle->orders.list->GetOrderAt(next->GetConditionSkipToOrder()), num_hops, this_cargo_mask);
assert(this_cargo_mask == 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 /* Reassign next with the following stop. This can be a station or a
* depot.*/ * depot.*/
uint32 this_cargo_mask = this->cargo_mask; CargoTypes this_cargo_mask = this->cargo_mask;
next = this->vehicle->orders.list->GetNextDecisionNode( next = this->vehicle->orders.list->GetNextDecisionNode(
this->vehicle->orders.list->GetNext(next), num_hops++, this_cargo_mask); this->vehicle->orders.list->GetNext(next), num_hops++, this_cargo_mask);
assert(this_cargo_mask == this->cargo_mask); assert(this_cargo_mask == this->cargo_mask);

View File

@@ -23,7 +23,7 @@
*/ */
class LinkRefresher { class LinkRefresher {
public: 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: protected:
/** /**
@@ -89,9 +89,9 @@ protected:
CargoID cargo; ///< Cargo given in last refit order. CargoID cargo; ///< Cargo given in last refit order.
bool allow_merge; ///< If the refresher is allowed to merge or extend link graphs. bool allow_merge; ///< If the refresher is allowed to merge or extend link graphs.
bool is_full_loading; ///< If the vehicle is full loading. 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); bool HandleRefit(CargoID refit_cargo);
void ResetRefit(); void ResetRefit();

View File

@@ -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, 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); 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 HouseAllowsConstruction(HouseID house_id, TileIndex tile, Town *t, byte random_bits);
bool CanDeleteHouse(TileIndex tile); bool CanDeleteHouse(TileIndex tile);

View File

@@ -96,7 +96,9 @@ uint ObjectSpec::Index() const
void ResetObjects() void ResetObjects()
{ {
/* Clean the pool. */ /* 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. */ /* And add our originals. */
MemCpyT(_object_specs, _original_objects, lengthof(_original_objects)); MemCpyT(_object_specs, _original_objects, lengthof(_original_objects));

View File

@@ -273,11 +273,11 @@ public:
return ouf; return ouf;
} }
template <typename F> uint32 FilterLoadUnloadTypeCargoMask(F filter_func, uint32 cargo_mask = ~0) template <typename F> CargoTypes FilterLoadUnloadTypeCargoMask(F filter_func, CargoTypes cargo_mask = ALL_CARGOTYPES)
{ {
if ((this->GetLoadType() == OLFB_CARGO_TYPE_LOAD) || (this->GetUnloadType() == OUFB_CARGO_TYPE_UNLOAD)) { if ((this->GetLoadType() == OLFB_CARGO_TYPE_LOAD) || (this->GetUnloadType() == OUFB_CARGO_TYPE_UNLOAD)) {
CargoID cargo; CargoID cargo;
uint32 output_mask = cargo_mask; CargoTypes output_mask = cargo_mask;
FOR_EACH_SET_BIT(cargo, cargo_mask) { FOR_EACH_SET_BIT(cargo, cargo_mask) {
if (!filter_func(this, cargo)) ClrBit(output_mask, cargo); 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); void DeleteOrder(Vehicle *v, VehicleOrderID sel_ord);
struct CargoMaskedStationIDStack { struct CargoMaskedStationIDStack {
uint32 cargo_mask; CargoTypes cargo_mask;
StationIDStack station; StationIDStack station;
CargoMaskedStationIDStack(uint32 cargo_mask, StationIDStack station) CargoMaskedStationIDStack(CargoTypes cargo_mask, StationIDStack station)
: cargo_mask(cargo_mask), station(station) {} : cargo_mask(cargo_mask), station(station) {}
}; };
@@ -477,7 +477,7 @@ private:
public: public:
CargoStationIDStackSet() CargoStationIDStackSet()
: first(~0, INVALID_STATION) {} : first(ALL_CARGOTYPES, INVALID_STATION) {}
const StationIDStack& Get(CargoID cargo) const 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); void FillNextStoppingStation(const Vehicle *v, const OrderList *o, const Order *first = NULL, uint hops = 0);
}; };
template <typename F> uint32 FilterCargoMask(F filter_func, uint32 cargo_mask = ~0) template <typename F> CargoTypes FilterCargoMask(F filter_func, CargoTypes cargo_mask = ALL_CARGOTYPES)
{ {
CargoID cargo; CargoID cargo;
uint32 output_mask = cargo_mask; CargoTypes output_mask = cargo_mask;
FOR_EACH_SET_BIT(cargo, cargo_mask) { FOR_EACH_SET_BIT(cargo, cargo_mask) {
if (!filter_func(cargo)) ClrBit(output_mask, cargo); if (!filter_func(cargo)) ClrBit(output_mask, cargo);
} }
return output_mask; return output_mask;
} }
template <typename T, typename F> T CargoMaskValueFilter(uint32 &cargo_mask, F filter_func) template <typename T, typename F> T CargoMaskValueFilter(CargoTypes &cargo_mask, F filter_func)
{ {
CargoID first_cargo_id = FindFirstBit(cargo_mask); CargoID first_cargo_id = FindFirstBit(cargo_mask);
T value = filter_func(first_cargo_id); 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); ClrBit(other_cargo_mask, first_cargo_id);
CargoID cargo; CargoID cargo;
FOR_EACH_SET_BIT(cargo, other_cargo_mask) { FOR_EACH_SET_BIT(cargo, other_cargo_mask) {
@@ -598,8 +598,8 @@ public:
*/ */
inline VehicleOrderID GetNumManualOrders() const { return this->num_manual_orders; } 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; CargoMaskedStationIDStack GetNextStoppingStation(const Vehicle *v, CargoTypes cargo_mask, const Order *first = NULL, uint hops = 0) const;
const Order *GetNextDecisionNode(const Order *next, uint hops, uint32 &cargo_mask) const; const Order *GetNextDecisionNode(const Order *next, uint hops, CargoTypes &cargo_mask) const;
void InsertOrderAt(Order *new_order, int index); void InsertOrderAt(Order *new_order, int index);
void DeleteOrderAt(int index); void DeleteOrderAt(int index);

View File

@@ -353,13 +353,13 @@ void Order::DeAllocExtraInfo()
void CargoStationIDStackSet::FillNextStoppingStation(const Vehicle *v, const OrderList *o, const Order *first, uint hops) void CargoStationIDStackSet::FillNextStoppingStation(const Vehicle *v, const OrderList *o, const Order *first, uint hops)
{ {
this->more.clear(); this->more.clear();
this->first = o->GetNextStoppingStation(v, ~0, first, hops); this->first = o->GetNextStoppingStation(v, ALL_CARGOTYPES, first, hops);
if (this->first.cargo_mask != (uint32) ~0) { if (this->first.cargo_mask != ALL_CARGOTYPES) {
uint32 have_cargoes = this->first.cargo_mask; CargoTypes have_cargoes = this->first.cargo_mask;
do { do {
this->more.push_back(o->GetNextStoppingStation(v, ~have_cargoes, first, hops)); this->more.push_back(o->GetNextStoppingStation(v, ~have_cargoes, first, hops));
have_cargoes |= this->more.back().cargo_mask; 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 a non-trivial conditional order
* \li NULL if the vehicle won't stop anymore. * \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); 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. * Recursively determine the next deterministic station to stop at.
* @param v The vehicle we're looking 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 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. * @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. * @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. * @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. * @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); assert(cargo_mask != 0);

View File

@@ -1068,8 +1068,6 @@ private:
Scrollbar *vscroll; Scrollbar *vscroll;
bool can_do_refit; ///< Vehicle chain can be refitted in depot. bool can_do_refit; ///< Vehicle chain can be refitted in depot.
bool can_do_autorefit; ///< Vehicle chain can be auto-refitted. 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 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; size->width = WD_FRAMERECT_LEFT + GetStringBoundingBox(STR_ORDERS_OCCUPANCY_PERCENT).width + 10 + WD_FRAMERECT_RIGHT;
break; 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); bool is_slot_occupancy = (ocv == OCV_SLOT_OCCUPANCY);
if (is_cargo) { if (is_cargo) {
this->GetWidget<NWidgetCore>(WID_O_COND_CARGO)->widget_data = cargo_names_list[(order == NULL) ? 0 : order->GetConditionValue()]; if (order == NULL || !CargoSpec::Get(order->GetConditionValue())->IsValid()) {
this->GetWidget<NWidgetCore>(WID_O_COND_CARGO)->widget_data = STR_NEWGRF_INVALID_CARGO;
} else {
this->GetWidget<NWidgetCore>(WID_O_COND_CARGO)->widget_data = CargoSpec::Get(order->GetConditionValue())->name;
}
this->GetWidget<NWidgetStacked>(WID_O_SEL_COND_VALUE)->SetDisplayedPlane(DP_COND_VALUE_CARGO); this->GetWidget<NWidgetStacked>(WID_O_SEL_COND_VALUE)->SetDisplayedPlane(DP_COND_VALUE_CARGO);
} else if (is_slot_occupancy) { } else if (is_slot_occupancy) {
TraceRestrictSlotID slot_id = (order != nullptr && TraceRestrictSlot::IsValidID(order->GetXData()) ? order->GetXData() : INVALID_TRACE_RESTRICT_SLOT_ID); 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: { case WID_O_COND_CARGO: {
uint value = this->vehicle->GetOrder(this->OrderGetSel())->GetConditionValue(); 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; break;
} }

View File

@@ -74,7 +74,8 @@ struct CFollowTrackT
inline void Init(Owner o, RailTypes railtype_override, CPerformanceTimer *pPerf) 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_veh_owner = o;
m_pPerf = pPerf; m_pPerf = pPerf;
/* don't worry, all is inlined so compiler should remove unnecessary initializations */ /* don't worry, all is inlined so compiler should remove unnecessary initializations */
@@ -228,8 +229,6 @@ protected:
m_is_station = true; m_is_station = true;
} else if (IsRoadTT() && IsRoadStopTile(m_new_tile)) { } else if (IsRoadTT() && IsRoadStopTile(m_new_tile)) {
m_is_station = true; m_is_station = true;
} else {
m_is_station = false;
} }
} }
@@ -242,7 +241,7 @@ protected:
} else { } else {
m_new_td_bits = TrackStatusToTrackdirBits(GetTileTrackStatus(m_new_tile, TT(), IsRoadTT() ? RoadVehicle::From(m_veh)->compatible_roadtypes : 0)); 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. /* GetTileTrackStatus() returns 0 for single tram bits.
* As we cannot change it there (easily) without breaking something, change it here */ * As we cannot change it there (easily) without breaking something, change it here */
switch (GetSingleTramBit(m_new_tile)) { switch (GetSingleTramBit(m_new_tile)) {

View File

@@ -814,7 +814,7 @@ static TrackdirBits GetDriveableTrackdirBits(TileIndex dst_tile, Trackdir src_tr
{ {
TrackdirBits trackdirbits = TrackStatusToTrackdirBits(GetTileTrackStatus(dst_tile, type, subtype)); 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. /* GetTileTrackStatus() returns 0 for single tram bits.
* As we cannot change it there (easily) without breaking something, change it here */ * As we cannot change it there (easily) without breaking something, change it here */
switch (GetSingleTramBit(dst_tile)) { switch (GetSingleTramBit(dst_tile)) {
@@ -907,7 +907,7 @@ static void NPFFollowTrack(AyStar *aystar, OpenListNode *current)
trackdirbits = GetDriveableTrackdirBits(dst_tile, src_trackdir, type, subtype); 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 */ /* We cannot enter the next tile. Road vehicles can reverse, others reach dead end */
if (type != TRANSPORT_ROAD || HasBit(subtype, ROADTYPE_TRAM)) return; if (type != TRANSPORT_ROAD || HasBit(subtype, ROADTYPE_TRAM)) return;
@@ -931,7 +931,7 @@ static void NPFFollowTrack(AyStar *aystar, OpenListNode *current)
/* Enumerate possible track */ /* Enumerate possible track */
uint i = 0; uint i = 0;
while (trackdirbits != 0) { while (trackdirbits != TRACKDIR_BIT_NONE) {
Trackdir dst_trackdir = RemoveFirstTrackdir(&trackdirbits); Trackdir dst_trackdir = RemoveFirstTrackdir(&trackdirbits);
DEBUG(npf, 5, "Expanded into trackdir: %d, remaining trackdirs: 0x%X", dst_trackdir, trackdirbits); DEBUG(npf, 5, "Expanded into trackdir: %d, remaining trackdirs: 0x%X", dst_trackdir, trackdirbits);

View File

@@ -193,9 +193,14 @@ bad:;
} }
/** /**
* returns the track to choose on the next tile, or -1 when it's better to * Finds the best track to choose on the next tile and
* reverse. The tile given is the tile we are about to enter, enterdir is the * returns INVALID_TRACK when it is better to reverse.
* direction in which we are entering the tile * @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) 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; Track track;
/* Let's find out how far it would be if we would reverse first */ /* Let's find out how far it would be if we would reverse first */
Trackdir trackdir = v->GetVehicleTrackdir(); uint rev_dist = UINT_MAX; // distance if we reverse
TrackBits b = TrackStatusToTrackBits(GetTileTrackStatus(tile2, TRANSPORT_WATER, 0)) & DiagdirReachesTracks(ReverseDiagDir(enterdir)) & TrackdirBitsToTrackBits(TrackdirToTrackdirBits(trackdir)); 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 (HasTrack(rev_tracks, cur_track)) {
if (b != 0) { rev_dist = FindShipTrack(v, tile2, rev_enterdir, TrackToTrackBits(cur_track), tile, &track);
distr = FindShipTrack(v, tile2, ReverseDiagDir(enterdir), b, tile, &track); if (rev_dist != UINT_MAX) rev_dist++; // penalty for reversing
if (distr != UINT_MAX) distr++; // penalty for reversing
} }
/* And if we would not reverse? */ /* 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. */ /* Due to the way this pathfinder works we cannot determine whether we're lost or not. */
path_found = true; path_found = true;
if (dist <= distr) return track; if (dist <= rev_dist) return track;
return INVALID_TRACK; // We could better reverse return INVALID_TRACK; // We could better reverse
} }

View File

@@ -105,7 +105,7 @@ public:
assert(IsValidTrackdir(td2)); assert(IsValidTrackdir(td2));
int cost = 0; int cost = 0;
if (TrackFollower::Allow90degTurns() if (TrackFollower::Allow90degTurns()
&& ((TrackdirToTrackdirBits(td2) & (TrackdirBits)TrackdirCrossesTrackdirs(td1)) != 0)) { && HasTrackdir(TrackdirCrossesTrackdirs(td1), td2)) {
/* 90-deg curve penalty */ /* 90-deg curve penalty */
cost += Yapf().PfGetSettings().rail_curve90_penalty; cost += Yapf().PfGetSettings().rail_curve90_penalty;
} else if (td2 != NextTrackdir(td1)) { } else if (td2 != NextTrackdir(td1)) {
@@ -418,7 +418,7 @@ public:
{ {
assert(!n.flags_u.flags_s.m_targed_seen); assert(!n.flags_u.flags_s.m_targed_seen);
assert(tf->m_new_tile == n.m_key.m_tile); 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); CPerfStart perf_cost(&Yapf().m_perf_cost);

View File

@@ -166,16 +166,13 @@ public:
/** Called by YAPF to detect if node ends in the desired destination */ /** Called by YAPF to detect if node ends in the desired destination */
inline bool PfDetectDestination(TileIndex tile, Trackdir td) inline bool PfDetectDestination(TileIndex tile, Trackdir td)
{ {
bool bDest;
if (m_dest_station_id != INVALID_STATION) { if (m_dest_station_id != INVALID_STATION) {
bDest = HasStationTileRail(tile) return HasStationTileRail(tile)
&& (GetStationIndex(tile) == m_dest_station_id) && (GetStationIndex(tile) == m_dest_station_id)
&& (GetRailStationTrack(tile) == TrackdirToTrack(td)); && (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);
} }
/** /**

View File

@@ -197,8 +197,7 @@ public:
/** Called by YAPF to detect if node ends in the desired destination */ /** Called by YAPF to detect if node ends in the desired destination */
inline bool PfDetectDestination(Node &n) inline bool PfDetectDestination(Node &n)
{ {
bool bDest = IsRoadDepotTile(n.m_segment_last_tile); return IsRoadDepotTile(n.m_segment_last_tile);
return bDest;
} }
inline bool PfDetectDestinationTile(TileIndex tile, Trackdir trackdir) inline bool PfDetectDestinationTile(TileIndex tile, Trackdir trackdir)
@@ -273,7 +272,7 @@ public:
(m_non_artic || IsDriveThroughStopTile(tile)); (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) */ /* set origin (tile, trackdir) */
TileIndex src_tile = v->tile; TileIndex src_tile = v->tile;
Trackdir src_td = v->GetVehicleTrackdir(); 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) /* sometimes the roadveh is not on the road (it resides on non-existing track)
* how should we handle that situation? */ * how should we handle that situation? */
return false; return false;
@@ -516,7 +515,7 @@ FindDepotData YapfRoadVehicleFindNearestDepot(const RoadVehicle *v, int max_dist
{ {
TileIndex tile = v->tile; TileIndex tile = v->tile;
Trackdir trackdir = v->GetVehicleTrackdir(); 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(); return FindDepotData();
} }

View File

@@ -65,7 +65,7 @@ public:
/* use vehicle's current direction if that's possible, otherwise use first usable one. */ /* use vehicle's current direction if that's possible, otherwise use first usable one. */
Trackdir veh_dir = v->GetVehicleTrackdir(); 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) */ /* move back to the old tile/trackdir (where ship is coming from) */

View File

@@ -100,7 +100,7 @@ bool TryReserveRailTrackdir(TileIndex tile, Trackdir td, bool trigger_stations)
*/ */
bool TryReserveRailTrack(TileIndex tile, Track t, 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) { if (_settings_client.gui.show_track_reservation) {
/* show the reserved rail if needed */ /* show the reserved rail if needed */
@@ -187,7 +187,7 @@ void UnreserveRailTrackdir(TileIndex tile, Trackdir td)
*/ */
void UnreserveRailTrack(TileIndex tile, Track t) 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 (_settings_client.gui.show_track_reservation) {
if (IsBridgeTile(tile)) { if (IsBridgeTile(tile)) {

View File

@@ -70,13 +70,13 @@ const byte _openttd_revision_modified = !!MODIFIED!!;
* 24-27 minor version * 24-27 minor version
* 20-23 build * 20-23 build
* 19 1 if it is a release, 0 if it is not. * 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 * 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 * final release will always have a lower version number than the released
* version, thus making comparisons on specific revisions easy. * 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__ #ifdef __MORPHOS__
/** /**

View File

@@ -355,7 +355,8 @@ static const SaveLoad _company_economy_desc[] = {
SLE_CONDVAR(CompanyEconomyEntry, company_value, SLE_INT64, 2, SL_MAX_VERSION), SLE_CONDVAR(CompanyEconomyEntry, company_value, SLE_INT64, 2, SL_MAX_VERSION),
SLE_CONDVAR(CompanyEconomyEntry, delivered_cargo[NUM_CARGO - 1], SLE_INT32, 0, 169), 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_VAR(CompanyEconomyEntry, performance_history, SLE_INT32),
SLE_END() SLE_END()
@@ -511,7 +512,6 @@ static void Check_PLYR()
int index; int index;
while ((index = SlIterateArray()) != -1) { while ((index = SlIterateArray()) != -1) {
CompanyProperties *cprops = new CompanyProperties(); CompanyProperties *cprops = new CompanyProperties();
memset(cprops, 0, sizeof(*cprops));
SaveLoad_PLYR_common(NULL, cprops); SaveLoad_PLYR_common(NULL, cprops);
/* We do not load old custom names */ /* We do not load old custom names */

View File

@@ -29,7 +29,7 @@ static void Load_PRIC()
/** Cargo payment rates in pre 126 savegames */ /** Cargo payment rates in pre 126 savegames */
static void Load_CAPR() 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; int vt = IsSavegameVersionBefore(65) ? SLE_FILE_I32 : SLE_FILE_I64;
SlArray(NULL, num_cargo, vt | SLE_VAR_NULL); SlArray(NULL, num_cargo, vt | SLE_VAR_NULL);
SlArray(NULL, num_cargo, SLE_FILE_U16 | SLE_VAR_NULL); SlArray(NULL, num_cargo, SLE_FILE_U16 | SLE_VAR_NULL);

View File

@@ -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_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_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_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_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_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 }, { XSLFI_CUSTOM_BRIDGE_HEADS, XSCF_NULL, 1, 1, "custom_bridge_heads", NULL, NULL, NULL },

View File

@@ -202,7 +202,8 @@ static void Load_ORDR()
const SaveLoad *GetOrderExtraInfoDescription() const SaveLoad *GetOrderExtraInfoDescription()
{ {
static const SaveLoad _order_extra_info_desc[] = { 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_CONDVAR_X(OrderExtraInfo, xflags, SLE_UINT8, 0, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_TIMETABLE_EXTRA)), 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_CONDVAR_X(OrderExtraInfo, xdata, SLE_UINT32, 0, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_ORDER_EXTRA_DATA)),
SLE_END() SLE_END()

View File

@@ -275,8 +275,9 @@
* 196 27778 1.7.x * 196 27778 1.7.x
* 197 27978 1.8.x * 197 27978 1.8.x
* 198 * 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 const uint16 SAVEGAME_VERSION_EXT = 0x8000; ///< Savegame extension indicator mask
SavegameType _savegame_type; ///< type of savegame we are loading SavegameType _savegame_type; ///< type of savegame we are loading

View File

@@ -573,7 +573,7 @@ typedef SaveLoad SaveLoadGlobVarList;
* @param variable Name of the global variable. * @param variable Name of the global variable.
* @param type Storage of the data in memory and in the savegame. * @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. * Storage of a global list in every savegame version.

View File

@@ -351,6 +351,7 @@ static void Load_STNS()
_cargo_days = 0; _cargo_days = 0;
_cargo_feeder_share = 0; _cargo_feeder_share = 0;
uint num_cargo = IsSavegameVersionBefore(55) ? 12 : IsSavegameVersionBefore(199) ? 32 : NUM_CARGO;
int index; int index;
while ((index = SlIterateArray()) != -1) { while ((index = SlIterateArray()) != -1) {
Station *st = new (index) Station(); Station *st = new (index) Station();
@@ -359,7 +360,6 @@ static void Load_STNS()
_waiting_acceptance = 0; _waiting_acceptance = 0;
uint num_cargo = IsSavegameVersionBefore(55) ? 12 : NUM_CARGO;
for (CargoID i = 0; i < num_cargo; i++) { for (CargoID i = 0; i < num_cargo; i++) {
GoodsEntry *ge = &st->goods[i]; GoodsEntry *ge = &st->goods[i];
SlObject(ge, GetGoodsDesc()); SlObject(ge, GetGoodsDesc());
@@ -400,10 +400,11 @@ static void Ptrs_STNS()
/* Don't run when savegame version is higher than or equal to 123. */ /* Don't run when savegame version is higher than or equal to 123. */
if (!IsSavegameVersionBefore(123)) return; if (!IsSavegameVersionBefore(123)) return;
uint num_cargo = IsSavegameVersionBefore(199) ? 32 : NUM_CARGO;
Station *st; Station *st;
FOR_ALL_STATIONS(st) { FOR_ALL_STATIONS(st) {
if (!IsSavegameVersionBefore(68)) { if (!IsSavegameVersionBefore(68)) {
for (CargoID i = 0; i < NUM_CARGO; i++) { for (CargoID i = 0; i < num_cargo; i++) {
GoodsEntry *ge = &st->goods[i]; GoodsEntry *ge = &st->goods[i];
SwapPackets(ge); SwapPackets(ge);
SlObject(ge, GetGoodsDesc()); 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)), 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_VAR(Station, had_vehicle_of_type, SLE_UINT8),
SLE_VEC(Station, loading_vehicles, REF_VEHICLE), 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() SLE_END()
}; };
@@ -555,6 +557,7 @@ static void Load_STNN()
{ {
_num_flows = 0; _num_flows = 0;
const uint num_cargo = IsSavegameVersionBefore(199) ? 32 : NUM_CARGO;
ReadBuffer *buffer = ReadBuffer::GetCurrent(); ReadBuffer *buffer = ReadBuffer::GetCurrent();
int index; 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)); 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()); SlObject(&st->goods[i], GetGoodsDesc());
FlowSaveLoad flow; FlowSaveLoad flow;
FlowStat *fs = NULL; FlowStat *fs = NULL;
@@ -624,9 +627,10 @@ static void Ptrs_STNN()
/* Don't run when savegame version lower than 123. */ /* Don't run when savegame version lower than 123. */
if (IsSavegameVersionBefore(123)) return; if (IsSavegameVersionBefore(123)) return;
uint num_cargo = IsSavegameVersionBefore(199) ? 32 : NUM_CARGO;
Station *st; Station *st;
FOR_ALL_STATIONS(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]; GoodsEntry *ge = &st->goods[i];
if (IsSavegameVersionBefore(183)) { if (IsSavegameVersionBefore(183)) {
SwapPackets(ge); SwapPackets(ge);

View File

@@ -193,7 +193,8 @@ static const SaveLoad _town_desc[] = {
SLE_CONDLST(Town, psa_list, REF_STORAGE, 161, SL_MAX_VERSION), 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) */ /* reserve extra space in savegame here. (currently 30 bytes) */
SLE_CONDNULL(30, 2, SL_MAX_VERSION), SLE_CONDNULL(30, 2, SL_MAX_VERSION),
@@ -288,12 +289,13 @@ static void Save_TOWN()
static void Load_TOWN() static void Load_TOWN()
{ {
int index; int index;
uint num_cargo = IsSavegameVersionBefore(199) ? 32 : NUM_CARGO;
while ((index = SlIterateArray()) != -1) { while ((index = SlIterateArray()) != -1) {
Town *t = new (index) Town(); Town *t = new (index) Town();
SlObject(t, _town_desc); 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); SlObject(&t->supplied[i], _town_supplied_desc);
} }
if (SlXvIsFeaturePresent(XSLFI_SPRINGPP)) { if (SlXvIsFeaturePresent(XSLFI_SPRINGPP)) {

View File

@@ -1342,7 +1342,7 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
} }
case SCC_CARGO_LIST: { // {CARGO_LIST} case SCC_CARGO_LIST: { // {CARGO_LIST}
CargoTypes cmask = args->GetInt32(SCC_CARGO_LIST); CargoTypes cmask = args->GetInt64(SCC_CARGO_LIST);
bool first = true; bool first = true;
const CargoSpec *cs; const CargoSpec *cs;

View File

@@ -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) 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)\ #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)\ #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) 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) 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)\ #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)\ #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) 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) 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)\ #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)\ #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) 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)

View File

@@ -1548,7 +1548,7 @@ public:
static char buff[DRAW_STRING_BUFFER] = ""; static char buff[DRAW_STRING_BUFFER] = "";
char *str = buff; char *str = buff;
CargoArray cargo; CargoArray cargo;
uint32 dummy = 0; CargoTypes dummy = 0;
AddAcceptedHouseCargo(this->display_house, INVALID_TILE, cargo, &dummy); AddAcceptedHouseCargo(this->display_house, INVALID_TILE, cargo, &dummy);
for (uint i = 0; i < NUM_CARGO; i++) { for (uint i = 0; i < NUM_CARGO; i++) {
if (cargo[i] == 0) continue; if (cargo[i] == 0) continue;

View File

@@ -61,7 +61,7 @@ static inline bool IsValidTrackdirForRoadVehicle(Trackdir trackdir)
*/ */
static inline bool IsValidTrackdir(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); 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. * Returns the present-trackdir-information of a TrackStatus.
* *

View File

@@ -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)) { 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 { } else {
uint32 cargo_mask = 0; CargoTypes cargo_mask = 0;
for (const Vehicle *u = this; u != NULL; u = u->Next()) { for (const Vehicle *u = this; u != NULL; u = u->Next()) {
if (u->cargo_type < NUM_CARGO && u->last_loading_station != INVALID_STATION) { if (u->cargo_type < NUM_CARGO && u->last_loading_station != INVALID_STATION) {
SetBit(cargo_mask, u->cargo_type); 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. */ /* Only update the timetable if the vehicle was supposed to stop here. */
if (this->current_order.GetNonStopType() != ONSF_STOP_EVERYWHERE) UpdateVehicleTimetable(this, false); 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); return ((o->GetCargoLoadType(cargo) & OLFB_NO_LOAD) == 0) || ((o->GetCargoUnloadType(cargo) & OUFB_NO_UNLOAD) == 0);
}); });
uint32 has_cargo_mask = this->GetLastLoadingStationValidCargoMask(); CargoTypes has_cargo_mask = this->GetLastLoadingStationValidCargoMask();
uint32 cargoes_can_leave_with_cargo = FilterCargoMask([&](CargoID cargo) { CargoTypes cargoes_can_leave_with_cargo = FilterCargoMask([&](CargoID cargo) {
return this->current_order.CanLeaveWithCargo(HasBit(has_cargo_mask, cargo), cargo); return this->current_order.CanLeaveWithCargo(HasBit(has_cargo_mask, cargo), cargo);
}, cargoes_can_load_unload); }, cargoes_can_load_unload);
@@ -2778,7 +2778,7 @@ void Vehicle::LeaveStation()
LinkRefresher::Run(this, true, false, cargoes_can_leave_with_cargo); 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 */ /* can leave with all cargoes */
/* if the vehicle could load here or could stop with cargo loaded set the last loading station */ /* if the vehicle could load here or could stop with cargo loaded set the last loading station */

View File

@@ -349,7 +349,7 @@ public:
/** We want to 'destruct' the right class. */ /** We want to 'destruct' the right class. */
virtual ~Vehicle(); virtual ~Vehicle();
uint32 GetLastLoadingStationValidCargoMask() const; CargoTypes GetLastLoadingStationValidCargoMask() const;
void BeginLoading(); void BeginLoading();
void CancelReservation(StationID next, Station *st); void CancelReservation(StationID next, Station *st);

View File

@@ -338,13 +338,13 @@ bool VideoDriver_Win32::MakeWindow(bool full_screen)
if (_wnd.main_wnd != NULL) { 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); if (!_window_maximize) SetWindowPos(_wnd.main_wnd, 0, 0, 0, w, h, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_NOMOVE);
} else { } else {
TCHAR Windowtitle[50];
int x = (GetSystemMetrics(SM_CXSCREEN) - w) / 2; int x = (GetSystemMetrics(SM_CXSCREEN) - w) / 2;
int y = (GetSystemMetrics(SM_CYSCREEN) - h) / 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"); if (_wnd.main_wnd == NULL) usererror("CreateWindow failed");
ShowWindow(_wnd.main_wnd, showstyle); ShowWindow(_wnd.main_wnd, showstyle);
} }