mirror of https://github.com/OpenTTD/OpenTTD.git
Codechange: Redefine some cargo-related values in terms of CargoID instead of CargoType.
Values used as special filter types are now defined as offsets from NUM_CARGO instead of confusingly reusing CARGO_NO_REFIT/CARGO_AUTO_REFIT types.
This commit is contained in:
parent
952d111b94
commit
400ae65ff2
|
@ -226,7 +226,7 @@ static int GetIncompatibleRefitOrderIdForAutoreplace(const Vehicle *v, EngineID
|
||||||
* @param engine_type The EngineID of the vehicle that is being replaced to
|
* @param engine_type The EngineID of the vehicle that is being replaced to
|
||||||
* @param part_of_chain The vehicle is part of a train
|
* @param part_of_chain The vehicle is part of a train
|
||||||
* @return The cargo type to replace to
|
* @return The cargo type to replace to
|
||||||
* CT_NO_REFIT is returned if no refit is needed
|
* CARGO_NO_REFIT is returned if no refit is needed
|
||||||
* INVALID_CARGO is returned when both old and new vehicle got cargo capacity and refitting the new one to the old one's cargo type isn't possible
|
* INVALID_CARGO is returned when both old and new vehicle got cargo capacity and refitting the new one to the old one's cargo type isn't possible
|
||||||
*/
|
*/
|
||||||
static CargoID GetNewCargoTypeForReplace(Vehicle *v, EngineID engine_type, bool part_of_chain)
|
static CargoID GetNewCargoTypeForReplace(Vehicle *v, EngineID engine_type, bool part_of_chain)
|
||||||
|
@ -234,23 +234,23 @@ static CargoID GetNewCargoTypeForReplace(Vehicle *v, EngineID engine_type, bool
|
||||||
CargoTypes available_cargo_types, union_mask;
|
CargoTypes available_cargo_types, union_mask;
|
||||||
GetArticulatedRefitMasks(engine_type, true, &union_mask, &available_cargo_types);
|
GetArticulatedRefitMasks(engine_type, true, &union_mask, &available_cargo_types);
|
||||||
|
|
||||||
if (union_mask == 0) return CT_NO_REFIT; // Don't try to refit an engine with no cargo capacity
|
if (union_mask == 0) return CARGO_NO_REFIT; // Don't try to refit an engine with no cargo capacity
|
||||||
|
|
||||||
CargoID cargo_type;
|
CargoID cargo_type;
|
||||||
CargoTypes cargo_mask = GetCargoTypesOfArticulatedVehicle(v, &cargo_type);
|
CargoTypes cargo_mask = GetCargoTypesOfArticulatedVehicle(v, &cargo_type);
|
||||||
if (!HasAtMostOneBit(cargo_mask)) {
|
if (!HasAtMostOneBit(cargo_mask)) {
|
||||||
CargoTypes new_engine_default_cargoes = GetCargoTypesOfArticulatedParts(engine_type);
|
CargoTypes new_engine_default_cargoes = GetCargoTypesOfArticulatedParts(engine_type);
|
||||||
if ((cargo_mask & new_engine_default_cargoes) == cargo_mask) {
|
if ((cargo_mask & new_engine_default_cargoes) == cargo_mask) {
|
||||||
return CT_NO_REFIT; // engine_type is already a mixed cargo type which matches the incoming vehicle by default, no refit required
|
return CARGO_NO_REFIT; // engine_type is already a mixed cargo type which matches the incoming vehicle by default, no refit required
|
||||||
}
|
}
|
||||||
|
|
||||||
return INVALID_CARGO; // We cannot refit to mixed cargoes in an automated way
|
return INVALID_CARGO; // We cannot refit to mixed cargoes in an automated way
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!IsValidCargoID(cargo_type)) {
|
if (!IsValidCargoID(cargo_type)) {
|
||||||
if (v->type != VEH_TRAIN) return CT_NO_REFIT; // If the vehicle does not carry anything at all, every replacement is fine.
|
if (v->type != VEH_TRAIN) return CARGO_NO_REFIT; // If the vehicle does not carry anything at all, every replacement is fine.
|
||||||
|
|
||||||
if (!part_of_chain) return CT_NO_REFIT;
|
if (!part_of_chain) return CARGO_NO_REFIT;
|
||||||
|
|
||||||
/* the old engine didn't have cargo capacity, but the new one does
|
/* the old engine didn't have cargo capacity, but the new one does
|
||||||
* now we will figure out what cargo the train is carrying and refit to fit this */
|
* now we will figure out what cargo the train is carrying and refit to fit this */
|
||||||
|
@ -261,7 +261,7 @@ static CargoID GetNewCargoTypeForReplace(Vehicle *v, EngineID engine_type, bool
|
||||||
if (HasBit(available_cargo_types, v->cargo_type)) return v->cargo_type;
|
if (HasBit(available_cargo_types, v->cargo_type)) return v->cargo_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
return CT_NO_REFIT; // We failed to find a cargo type on the old vehicle and we will not refit the new one
|
return CARGO_NO_REFIT; // We failed to find a cargo type on the old vehicle and we will not refit the new one
|
||||||
} else {
|
} else {
|
||||||
if (!HasBit(available_cargo_types, cargo_type)) return INVALID_CARGO; // We can't refit the vehicle to carry the cargo we want
|
if (!HasBit(available_cargo_types, cargo_type)) return INVALID_CARGO; // We can't refit the vehicle to carry the cargo we want
|
||||||
|
|
||||||
|
@ -359,7 +359,7 @@ static CommandCost BuildReplacementVehicle(Vehicle *old_veh, Vehicle **new_vehic
|
||||||
*new_vehicle = new_veh;
|
*new_vehicle = new_veh;
|
||||||
|
|
||||||
/* Refit the vehicle if needed */
|
/* Refit the vehicle if needed */
|
||||||
if (refit_cargo != CT_NO_REFIT) {
|
if (refit_cargo != CARGO_NO_REFIT) {
|
||||||
byte subtype = GetBestFittingSubType(old_veh, new_veh, refit_cargo);
|
byte subtype = GetBestFittingSubType(old_veh, new_veh, refit_cargo);
|
||||||
|
|
||||||
cost.AddCost(std::get<0>(Command<CMD_REFIT_VEHICLE>::Do(DC_EXEC, new_veh->index, refit_cargo, subtype, false, false, 0)));
|
cost.AddCost(std::get<0>(Command<CMD_REFIT_VEHICLE>::Do(DC_EXEC, new_veh->index, refit_cargo, subtype, false, false, 0)));
|
||||||
|
|
|
@ -93,16 +93,12 @@ static const NWidgetPart _nested_build_vehicle_widgets[] = {
|
||||||
EndContainer(),
|
EndContainer(),
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Special cargo filter criteria */
|
|
||||||
static const CargoID CF_ANY = CT_NO_REFIT; ///< Show all vehicles independent of carried cargo (i.e. no filtering)
|
|
||||||
static const CargoID CF_NONE = INVALID_CARGO; ///< Show only vehicles which do not carry cargo (e.g. train engines)
|
|
||||||
static const CargoID CF_ENGINES = CT_AUTO_REFIT; ///< Show only engines (for rail vehicles only)
|
|
||||||
|
|
||||||
bool _engine_sort_direction; ///< \c false = descending, \c true = ascending.
|
bool _engine_sort_direction; ///< \c false = descending, \c true = ascending.
|
||||||
byte _engine_sort_last_criteria[] = {0, 0, 0, 0}; ///< Last set sort criteria, for each vehicle type.
|
byte _engine_sort_last_criteria[] = {0, 0, 0, 0}; ///< Last set sort criteria, for each vehicle type.
|
||||||
bool _engine_sort_last_order[] = {false, false, false, false}; ///< Last set direction of the sort order, for each vehicle type.
|
bool _engine_sort_last_order[] = {false, false, false, false}; ///< Last set direction of the sort order, for each vehicle type.
|
||||||
bool _engine_sort_show_hidden_engines[] = {false, false, false, false}; ///< Last set 'show hidden engines' setting for each vehicle type.
|
bool _engine_sort_show_hidden_engines[] = {false, false, false, false}; ///< Last set 'show hidden engines' setting for each vehicle type.
|
||||||
static CargoID _engine_sort_last_cargo_criteria[] = {CF_ANY, CF_ANY, CF_ANY, CF_ANY}; ///< Last set filter criteria, for each vehicle type.
|
static CargoID _engine_sort_last_cargo_criteria[] = {CargoFilterCriteria::CF_ANY, CargoFilterCriteria::CF_ANY, CargoFilterCriteria::CF_ANY, CargoFilterCriteria::CF_ANY}; ///< Last set filter criteria, for each vehicle type.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines order of engines by engineID
|
* Determines order of engines by engineID
|
||||||
|
@ -543,13 +539,13 @@ const StringID _engine_sort_listing[][12] = {{
|
||||||
/** Filters vehicles by cargo and engine (in case of rail vehicle). */
|
/** Filters vehicles by cargo and engine (in case of rail vehicle). */
|
||||||
static bool CDECL CargoAndEngineFilter(const GUIEngineListItem *item, const CargoID cid)
|
static bool CDECL CargoAndEngineFilter(const GUIEngineListItem *item, const CargoID cid)
|
||||||
{
|
{
|
||||||
if (cid == CF_ANY) {
|
if (cid == CargoFilterCriteria::CF_ANY) {
|
||||||
return true;
|
return true;
|
||||||
} else if (cid == CF_ENGINES) {
|
} else if (cid == CargoFilterCriteria::CF_ENGINES) {
|
||||||
return Engine::Get(item->engine_id)->GetPower() != 0;
|
return Engine::Get(item->engine_id)->GetPower() != 0;
|
||||||
} else {
|
} else {
|
||||||
CargoTypes refit_mask = GetUnionOfArticulatedRefitMasks(item->engine_id, true) & _standard_cargo_mask;
|
CargoTypes refit_mask = GetUnionOfArticulatedRefitMasks(item->engine_id, true) & _standard_cargo_mask;
|
||||||
return (cid == CF_NONE ? refit_mask == 0 : HasBit(refit_mask, cid));
|
return (cid == CargoFilterCriteria::CF_NONE ? refit_mask == 0 : HasBit(refit_mask, cid));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1146,7 +1142,7 @@ struct BuildVehicleWindow : Window {
|
||||||
{
|
{
|
||||||
NWidgetCore *widget = this->GetWidget<NWidgetCore>(WID_BV_BUILD);
|
NWidgetCore *widget = this->GetWidget<NWidgetCore>(WID_BV_BUILD);
|
||||||
|
|
||||||
bool refit = this->sel_engine != INVALID_ENGINE && this->cargo_filter_criteria != CF_ANY && this->cargo_filter_criteria != CF_NONE;
|
bool refit = this->sel_engine != INVALID_ENGINE && this->cargo_filter_criteria != CargoFilterCriteria::CF_ANY && this->cargo_filter_criteria != CargoFilterCriteria::CF_NONE;
|
||||||
if (refit) refit = Engine::Get(this->sel_engine)->GetDefaultCargoType() != this->cargo_filter_criteria;
|
if (refit) refit = Engine::Get(this->sel_engine)->GetDefaultCargoType() != this->cargo_filter_criteria;
|
||||||
|
|
||||||
if (refit) {
|
if (refit) {
|
||||||
|
@ -1272,9 +1268,9 @@ struct BuildVehicleWindow : Window {
|
||||||
StringID GetCargoFilterLabel(CargoID cid) const
|
StringID GetCargoFilterLabel(CargoID cid) const
|
||||||
{
|
{
|
||||||
switch (cid) {
|
switch (cid) {
|
||||||
case CF_ANY: return STR_PURCHASE_INFO_ALL_TYPES;
|
case CargoFilterCriteria::CF_ANY: return STR_PURCHASE_INFO_ALL_TYPES;
|
||||||
case CF_ENGINES: return STR_PURCHASE_INFO_ENGINES_ONLY;
|
case CargoFilterCriteria::CF_ENGINES: return STR_PURCHASE_INFO_ENGINES_ONLY;
|
||||||
case CF_NONE: return STR_PURCHASE_INFO_NONE;
|
case CargoFilterCriteria::CF_NONE: return STR_PURCHASE_INFO_NONE;
|
||||||
default: return CargoSpec::Get(cid)->name;
|
default: return CargoSpec::Get(cid)->name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1284,16 +1280,16 @@ struct BuildVehicleWindow : Window {
|
||||||
{
|
{
|
||||||
/* Set the last cargo filter criteria. */
|
/* Set the last cargo filter criteria. */
|
||||||
this->cargo_filter_criteria = _engine_sort_last_cargo_criteria[this->vehicle_type];
|
this->cargo_filter_criteria = _engine_sort_last_cargo_criteria[this->vehicle_type];
|
||||||
if (this->cargo_filter_criteria < NUM_CARGO && !HasBit(_standard_cargo_mask, this->cargo_filter_criteria)) this->cargo_filter_criteria = CF_ANY;
|
if (this->cargo_filter_criteria < NUM_CARGO && !HasBit(_standard_cargo_mask, this->cargo_filter_criteria)) this->cargo_filter_criteria = CargoFilterCriteria::CF_ANY;
|
||||||
|
|
||||||
this->eng_list.SetFilterFuncs(_filter_funcs);
|
this->eng_list.SetFilterFuncs(_filter_funcs);
|
||||||
this->eng_list.SetFilterState(this->cargo_filter_criteria != CF_ANY);
|
this->eng_list.SetFilterState(this->cargo_filter_criteria != CargoFilterCriteria::CF_ANY);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SelectEngine(EngineID engine)
|
void SelectEngine(EngineID engine)
|
||||||
{
|
{
|
||||||
CargoID cargo = this->cargo_filter_criteria;
|
CargoID cargo = this->cargo_filter_criteria;
|
||||||
if (cargo == CF_ANY || cargo == CF_ENGINES || cargo == CF_NONE) cargo = INVALID_CARGO;
|
if (cargo == CargoFilterCriteria::CF_ANY || cargo == CargoFilterCriteria::CF_ENGINES || cargo == CargoFilterCriteria::CF_NONE) cargo = INVALID_CARGO;
|
||||||
|
|
||||||
this->sel_engine = engine;
|
this->sel_engine = engine;
|
||||||
this->SetBuyVehicleText();
|
this->SetBuyVehicleText();
|
||||||
|
@ -1567,14 +1563,14 @@ struct BuildVehicleWindow : Window {
|
||||||
DropDownList list;
|
DropDownList list;
|
||||||
|
|
||||||
/* Add item for disabling filtering. */
|
/* Add item for disabling filtering. */
|
||||||
list.push_back(std::make_unique<DropDownListStringItem>(this->GetCargoFilterLabel(CF_ANY), CF_ANY, false));
|
list.push_back(std::make_unique<DropDownListStringItem>(this->GetCargoFilterLabel(CargoFilterCriteria::CF_ANY), CargoFilterCriteria::CF_ANY, false));
|
||||||
/* Specific filters for trains. */
|
/* Specific filters for trains. */
|
||||||
if (this->vehicle_type == VEH_TRAIN) {
|
if (this->vehicle_type == VEH_TRAIN) {
|
||||||
/* Add item for locomotives only in case of trains. */
|
/* Add item for locomotives only in case of trains. */
|
||||||
list.push_back(std::make_unique<DropDownListStringItem>(this->GetCargoFilterLabel(CF_ENGINES), CF_ENGINES, false));
|
list.push_back(std::make_unique<DropDownListStringItem>(this->GetCargoFilterLabel(CargoFilterCriteria::CF_ENGINES), CargoFilterCriteria::CF_ENGINES, false));
|
||||||
/* Add item for vehicles not carrying anything, e.g. train engines.
|
/* Add item for vehicles not carrying anything, e.g. train engines.
|
||||||
* This could also be useful for eyecandy vehicles of other types, but is likely too confusing for joe, */
|
* This could also be useful for eyecandy vehicles of other types, but is likely too confusing for joe, */
|
||||||
list.push_back(std::make_unique<DropDownListStringItem>(this->GetCargoFilterLabel(CF_NONE), CF_NONE, false));
|
list.push_back(std::make_unique<DropDownListStringItem>(this->GetCargoFilterLabel(CargoFilterCriteria::CF_NONE), CargoFilterCriteria::CF_NONE, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add cargos */
|
/* Add cargos */
|
||||||
|
@ -1652,7 +1648,7 @@ struct BuildVehicleWindow : Window {
|
||||||
EngineID sel_eng = this->sel_engine;
|
EngineID sel_eng = this->sel_engine;
|
||||||
if (sel_eng != INVALID_ENGINE) {
|
if (sel_eng != INVALID_ENGINE) {
|
||||||
CargoID cargo = this->cargo_filter_criteria;
|
CargoID cargo = this->cargo_filter_criteria;
|
||||||
if (cargo == CF_ANY || cargo == CF_ENGINES || cargo == CF_NONE) cargo = INVALID_CARGO;
|
if (cargo == CargoFilterCriteria::CF_ANY || cargo == CargoFilterCriteria::CF_ENGINES || cargo == CargoFilterCriteria::CF_NONE) cargo = INVALID_CARGO;
|
||||||
if (this->vehicle_type == VEH_TRAIN && RailVehInfo(sel_eng)->railveh_type == RAILVEH_WAGON) {
|
if (this->vehicle_type == VEH_TRAIN && RailVehInfo(sel_eng)->railveh_type == RAILVEH_WAGON) {
|
||||||
Command<CMD_BUILD_VEHICLE>::Post(GetCmdBuildVehMsg(this->vehicle_type), CcBuildWagon, this->window_number, sel_eng, true, cargo, INVALID_CLIENT_ID);
|
Command<CMD_BUILD_VEHICLE>::Post(GetCmdBuildVehMsg(this->vehicle_type), CcBuildWagon, this->window_number, sel_eng, true, cargo, INVALID_CLIENT_ID);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1857,7 +1853,7 @@ struct BuildVehicleWindow : Window {
|
||||||
this->cargo_filter_criteria = index;
|
this->cargo_filter_criteria = index;
|
||||||
_engine_sort_last_cargo_criteria[this->vehicle_type] = this->cargo_filter_criteria;
|
_engine_sort_last_cargo_criteria[this->vehicle_type] = this->cargo_filter_criteria;
|
||||||
/* deactivate filter if criteria is 'Show All', activate it otherwise */
|
/* deactivate filter if criteria is 'Show All', activate it otherwise */
|
||||||
this->eng_list.SetFilterState(this->cargo_filter_criteria != CF_ANY);
|
this->eng_list.SetFilterState(this->cargo_filter_criteria != CargoFilterCriteria::CF_ANY);
|
||||||
this->eng_list.ForceRebuild();
|
this->eng_list.ForceRebuild();
|
||||||
this->SelectEngine(this->sel_engine);
|
this->SelectEngine(this->sel_engine);
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,16 +61,29 @@ enum CargoType {
|
||||||
CT_PLASTIC = 10,
|
CT_PLASTIC = 10,
|
||||||
CT_FIZZY_DRINKS = 11,
|
CT_FIZZY_DRINKS = 11,
|
||||||
|
|
||||||
NUM_ORIGINAL_CARGO = 12,
|
|
||||||
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.
|
CT_INVALID = 0xFF, ///< Invalid cargo type.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static const CargoID NUM_ORIGINAL_CARGO = 12; ///< Original number of cargo types.
|
||||||
|
static const CargoID NUM_CARGO = 64; ///< Maximum number of cargo types in a game.
|
||||||
|
|
||||||
|
/* CARGO_AUTO_REFIT and CARGO_NO_REFIT are stored in save-games for refit-orders, so should not be changed. */
|
||||||
|
static const CargoID CARGO_AUTO_REFIT = 0xFD; ///< Automatically choose cargo type when doing auto refitting.
|
||||||
|
static const CargoID CARGO_NO_REFIT = 0xFE; ///< Do not refit cargo of a vehicle (used in vehicle orders and auto-replace/auto-renew).
|
||||||
|
|
||||||
static const CargoID INVALID_CARGO = UINT8_MAX;
|
static const CargoID INVALID_CARGO = UINT8_MAX;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Special cargo filter criteria.
|
||||||
|
* These are used by user interface code only and must not be assigned to any entity. Not all values are valid for every UI filter.
|
||||||
|
*/
|
||||||
|
namespace CargoFilterCriteria {
|
||||||
|
static constexpr CargoID CF_ANY = NUM_CARGO; ///< Show all items independent of carried cargo (i.e. no filtering)
|
||||||
|
static constexpr CargoID CF_NONE = NUM_CARGO + 1; ///< Show only items which do not carry cargo (e.g. train engines)
|
||||||
|
static constexpr CargoID CF_ENGINES = NUM_CARGO + 2; ///< Show only engines (for rail vehicles only)
|
||||||
|
static constexpr CargoID CF_FREIGHT = NUM_CARGO + 3; ///< Show only vehicles which carry any freight (non-passenger) cargo
|
||||||
|
};
|
||||||
|
|
||||||
/** Test whether cargo type is not CT_INVALID */
|
/** Test whether cargo type is not CT_INVALID */
|
||||||
inline bool IsValidCargoType(CargoType t) { return t != CT_INVALID; }
|
inline bool IsValidCargoType(CargoType t) { return t != CT_INVALID; }
|
||||||
/** Test whether cargo type is not INVALID_CARGO */
|
/** Test whether cargo type is not INVALID_CARGO */
|
||||||
|
|
|
@ -1500,7 +1500,7 @@ static void HandleStationRefit(Vehicle *v, CargoArray &consist_capleft, Station
|
||||||
/* Remove old capacity from consist capacity and collect refit mask. */
|
/* Remove old capacity from consist capacity and collect refit mask. */
|
||||||
IterateVehicleParts(v_start, PrepareRefitAction(consist_capleft, refit_mask));
|
IterateVehicleParts(v_start, PrepareRefitAction(consist_capleft, refit_mask));
|
||||||
|
|
||||||
bool is_auto_refit = new_cid == CT_AUTO_REFIT;
|
bool is_auto_refit = new_cid == CARGO_AUTO_REFIT;
|
||||||
if (is_auto_refit) {
|
if (is_auto_refit) {
|
||||||
/* Get a refittable cargo type with waiting cargo for next_station or INVALID_STATION. */
|
/* Get a refittable cargo type with waiting cargo for next_station or INVALID_STATION. */
|
||||||
new_cid = v_start->cargo_type;
|
new_cid = v_start->cargo_type;
|
||||||
|
@ -1636,7 +1636,7 @@ static void LoadUnloadVehicle(Vehicle *front)
|
||||||
Station *st = Station::Get(last_visited);
|
Station *st = Station::Get(last_visited);
|
||||||
|
|
||||||
StationIDStack next_station = front->GetNextStoppingStation();
|
StationIDStack next_station = front->GetNextStoppingStation();
|
||||||
bool use_autorefit = front->current_order.IsRefit() && front->current_order.GetRefitCargo() == CT_AUTO_REFIT;
|
bool use_autorefit = front->current_order.IsRefit() && front->current_order.GetRefitCargo() == CARGO_AUTO_REFIT;
|
||||||
CargoArray consist_capleft{};
|
CargoArray consist_capleft{};
|
||||||
if (_settings_game.order.improved_load && use_autorefit ?
|
if (_settings_game.order.improved_load && use_autorefit ?
|
||||||
front->cargo_payment == nullptr : (front->current_order.GetLoadType() & OLFB_FULL_LOAD) != 0) {
|
front->cargo_payment == nullptr : (front->current_order.GetLoadType() & OLFB_FULL_LOAD) != 0) {
|
||||||
|
|
|
@ -1245,12 +1245,6 @@ static const NWidgetPart _nested_industry_directory_widgets[] = {
|
||||||
|
|
||||||
typedef GUIList<const Industry *, const CargoID &, const std::pair<CargoID, CargoID> &> GUIIndustryList;
|
typedef GUIList<const Industry *, const CargoID &, const std::pair<CargoID, CargoID> &> GUIIndustryList;
|
||||||
|
|
||||||
/** Special cargo filter criteria */
|
|
||||||
enum CargoFilterSpecialType {
|
|
||||||
CF_ANY = CT_NO_REFIT, ///< Show all industries (i.e. no filtering)
|
|
||||||
CF_NONE = INVALID_CARGO, ///< Show only industries which do not produce/accept cargo
|
|
||||||
};
|
|
||||||
|
|
||||||
/** Cargo filter functions */
|
/** Cargo filter functions */
|
||||||
/**
|
/**
|
||||||
* Check whether an industry accepts and produces a certain cargo pair.
|
* Check whether an industry accepts and produces a certain cargo pair.
|
||||||
|
@ -1266,11 +1260,11 @@ static bool CDECL CargoFilter(const Industry * const *industry, const std::pair<
|
||||||
bool accepted_cargo_matches;
|
bool accepted_cargo_matches;
|
||||||
|
|
||||||
switch (accepted_cargo) {
|
switch (accepted_cargo) {
|
||||||
case CF_ANY:
|
case CargoFilterCriteria::CF_ANY:
|
||||||
accepted_cargo_matches = true;
|
accepted_cargo_matches = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CF_NONE:
|
case CargoFilterCriteria::CF_NONE:
|
||||||
accepted_cargo_matches = !(*industry)->IsCargoAccepted();
|
accepted_cargo_matches = !(*industry)->IsCargoAccepted();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -1282,11 +1276,11 @@ static bool CDECL CargoFilter(const Industry * const *industry, const std::pair<
|
||||||
bool produced_cargo_matches;
|
bool produced_cargo_matches;
|
||||||
|
|
||||||
switch (produced_cargo) {
|
switch (produced_cargo) {
|
||||||
case CF_ANY:
|
case CargoFilterCriteria::CF_ANY:
|
||||||
produced_cargo_matches = true;
|
produced_cargo_matches = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CF_NONE:
|
case CargoFilterCriteria::CF_NONE:
|
||||||
produced_cargo_matches = !(*industry)->IsCargoProduced();
|
produced_cargo_matches = !(*industry)->IsCargoProduced();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -1344,7 +1338,7 @@ protected:
|
||||||
if (this->produced_cargo_filter_criteria != cid) {
|
if (this->produced_cargo_filter_criteria != cid) {
|
||||||
this->produced_cargo_filter_criteria = cid;
|
this->produced_cargo_filter_criteria = cid;
|
||||||
/* deactivate filter if criteria is 'Show All', activate it otherwise */
|
/* deactivate filter if criteria is 'Show All', activate it otherwise */
|
||||||
bool is_filtering_necessary = this->produced_cargo_filter_criteria != CF_ANY || this->accepted_cargo_filter_criteria != CF_ANY;
|
bool is_filtering_necessary = this->produced_cargo_filter_criteria != CargoFilterCriteria::CF_ANY || this->accepted_cargo_filter_criteria != CargoFilterCriteria::CF_ANY;
|
||||||
|
|
||||||
this->industries.SetFilterState(is_filtering_necessary);
|
this->industries.SetFilterState(is_filtering_necessary);
|
||||||
this->industries.SetFilterType(0);
|
this->industries.SetFilterType(0);
|
||||||
|
@ -1361,7 +1355,7 @@ protected:
|
||||||
if (this->accepted_cargo_filter_criteria != cid) {
|
if (this->accepted_cargo_filter_criteria != cid) {
|
||||||
this->accepted_cargo_filter_criteria = cid;
|
this->accepted_cargo_filter_criteria = cid;
|
||||||
/* deactivate filter if criteria is 'Show All', activate it otherwise */
|
/* deactivate filter if criteria is 'Show All', activate it otherwise */
|
||||||
bool is_filtering_necessary = this->produced_cargo_filter_criteria != CF_ANY || this->accepted_cargo_filter_criteria != CF_ANY;
|
bool is_filtering_necessary = this->produced_cargo_filter_criteria != CargoFilterCriteria::CF_ANY || this->accepted_cargo_filter_criteria != CargoFilterCriteria::CF_ANY;
|
||||||
|
|
||||||
this->industries.SetFilterState(is_filtering_necessary);
|
this->industries.SetFilterState(is_filtering_necessary);
|
||||||
this->industries.SetFilterType(0);
|
this->industries.SetFilterType(0);
|
||||||
|
@ -1372,8 +1366,8 @@ protected:
|
||||||
StringID GetCargoFilterLabel(CargoID cid) const
|
StringID GetCargoFilterLabel(CargoID cid) const
|
||||||
{
|
{
|
||||||
switch (cid) {
|
switch (cid) {
|
||||||
case CF_ANY: return STR_INDUSTRY_DIRECTORY_FILTER_ALL_TYPES;
|
case CargoFilterCriteria::CF_ANY: return STR_INDUSTRY_DIRECTORY_FILTER_ALL_TYPES;
|
||||||
case CF_NONE: return STR_INDUSTRY_DIRECTORY_FILTER_NONE;
|
case CargoFilterCriteria::CF_NONE: return STR_INDUSTRY_DIRECTORY_FILTER_NONE;
|
||||||
default: return CargoSpec::Get(cid)->name;
|
default: return CargoSpec::Get(cid)->name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1383,12 +1377,12 @@ protected:
|
||||||
*/
|
*/
|
||||||
void SetCargoFilterArray()
|
void SetCargoFilterArray()
|
||||||
{
|
{
|
||||||
this->produced_cargo_filter_criteria = CF_ANY;
|
this->produced_cargo_filter_criteria = CargoFilterCriteria::CF_ANY;
|
||||||
this->accepted_cargo_filter_criteria = CF_ANY;
|
this->accepted_cargo_filter_criteria = CargoFilterCriteria::CF_ANY;
|
||||||
|
|
||||||
this->industries.SetFilterFuncs(_filter_funcs);
|
this->industries.SetFilterFuncs(_filter_funcs);
|
||||||
|
|
||||||
bool is_filtering_necessary = this->produced_cargo_filter_criteria != CF_ANY || this->accepted_cargo_filter_criteria != CF_ANY;
|
bool is_filtering_necessary = this->produced_cargo_filter_criteria != CargoFilterCriteria::CF_ANY || this->accepted_cargo_filter_criteria != CargoFilterCriteria::CF_ANY;
|
||||||
|
|
||||||
this->industries.SetFilterState(is_filtering_necessary);
|
this->industries.SetFilterState(is_filtering_necessary);
|
||||||
}
|
}
|
||||||
|
@ -1462,11 +1456,11 @@ protected:
|
||||||
static int GetCargoTransportedSortValue(const Industry *i)
|
static int GetCargoTransportedSortValue(const Industry *i)
|
||||||
{
|
{
|
||||||
CargoID filter = IndustryDirectoryWindow::produced_cargo_filter;
|
CargoID filter = IndustryDirectoryWindow::produced_cargo_filter;
|
||||||
if (filter == CF_NONE) return 0;
|
if (filter == CargoFilterCriteria::CF_NONE) return 0;
|
||||||
|
|
||||||
int percentage = 0, produced_cargo_count = 0;
|
int percentage = 0, produced_cargo_count = 0;
|
||||||
for (const auto &p : i->produced) {
|
for (const auto &p : i->produced) {
|
||||||
if (filter == CF_ANY) {
|
if (filter == CargoFilterCriteria::CF_ANY) {
|
||||||
int transported = GetCargoTransportedPercentsIfValid(p);
|
int transported = GetCargoTransportedPercentsIfValid(p);
|
||||||
if (transported != -1) {
|
if (transported != -1) {
|
||||||
produced_cargo_count++;
|
produced_cargo_count++;
|
||||||
|
@ -1506,10 +1500,10 @@ protected:
|
||||||
/** Sort industries by production and name */
|
/** Sort industries by production and name */
|
||||||
static bool IndustryProductionSorter(const Industry * const &a, const Industry * const &b, const CargoID &filter)
|
static bool IndustryProductionSorter(const Industry * const &a, const Industry * const &b, const CargoID &filter)
|
||||||
{
|
{
|
||||||
if (filter == CF_NONE) return IndustryTypeSorter(a, b, filter);
|
if (filter == CargoFilterCriteria::CF_NONE) return IndustryTypeSorter(a, b, filter);
|
||||||
|
|
||||||
uint prod_a = 0, prod_b = 0;
|
uint prod_a = 0, prod_b = 0;
|
||||||
if (filter == CF_ANY) {
|
if (filter == CargoFilterCriteria::CF_ANY) {
|
||||||
for (const auto &pa : a->produced) {
|
for (const auto &pa : a->produced) {
|
||||||
if (IsValidCargoID(pa.cargo)) prod_a += pa.history[LAST_MONTH].production;
|
if (IsValidCargoID(pa.cargo)) prod_a += pa.history[LAST_MONTH].production;
|
||||||
}
|
}
|
||||||
|
@ -1585,7 +1579,7 @@ protected:
|
||||||
/* If the produced cargo filter is active then move the filtered cargo to the beginning of the list,
|
/* If the produced cargo filter is active then move the filtered cargo to the beginning of the list,
|
||||||
* because this is the one the player interested in, and that way it is not hidden in the 'n' more cargos */
|
* because this is the one the player interested in, and that way it is not hidden in the 'n' more cargos */
|
||||||
const CargoID cid = this->produced_cargo_filter_criteria;
|
const CargoID cid = this->produced_cargo_filter_criteria;
|
||||||
if (cid != CF_ANY && cid != CF_NONE) {
|
if (cid != CargoFilterCriteria::CF_ANY && cid != CargoFilterCriteria::CF_NONE) {
|
||||||
auto filtered_ci = std::find_if(cargos.begin(), cargos.end(), [cid](const CargoInfo &ci) -> bool {
|
auto filtered_ci = std::find_if(cargos.begin(), cargos.end(), [cid](const CargoInfo &ci) -> bool {
|
||||||
return ci.cargo_id == cid;
|
return ci.cargo_id == cid;
|
||||||
});
|
});
|
||||||
|
@ -1693,7 +1687,7 @@ public:
|
||||||
const CargoID acf_cid = this->accepted_cargo_filter_criteria;
|
const CargoID acf_cid = this->accepted_cargo_filter_criteria;
|
||||||
for (uint i = this->vscroll->GetPosition(); i < this->industries.size(); i++) {
|
for (uint i = this->vscroll->GetPosition(); i < this->industries.size(); i++) {
|
||||||
TextColour tc = TC_FROMSTRING;
|
TextColour tc = TC_FROMSTRING;
|
||||||
if (acf_cid != CF_ANY && acf_cid != CF_NONE) {
|
if (acf_cid != CargoFilterCriteria::CF_ANY && acf_cid != CargoFilterCriteria::CF_NONE) {
|
||||||
Industry *ind = const_cast<Industry *>(this->industries[i]);
|
Industry *ind = const_cast<Industry *>(this->industries[i]);
|
||||||
if (IndustryTemporarilyRefusesCargo(ind, acf_cid)) {
|
if (IndustryTemporarilyRefusesCargo(ind, acf_cid)) {
|
||||||
tc = TC_GREY | TC_FORCED;
|
tc = TC_GREY | TC_FORCED;
|
||||||
|
@ -1748,9 +1742,9 @@ public:
|
||||||
DropDownList list;
|
DropDownList list;
|
||||||
|
|
||||||
/* Add item for disabling filtering. */
|
/* Add item for disabling filtering. */
|
||||||
list.push_back(std::make_unique<DropDownListStringItem>(this->GetCargoFilterLabel(CF_ANY), CF_ANY, false));
|
list.push_back(std::make_unique<DropDownListStringItem>(this->GetCargoFilterLabel(CargoFilterCriteria::CF_ANY), CargoFilterCriteria::CF_ANY, false));
|
||||||
/* Add item for industries not producing anything, e.g. power plants */
|
/* Add item for industries not producing anything, e.g. power plants */
|
||||||
list.push_back(std::make_unique<DropDownListStringItem>(this->GetCargoFilterLabel(CF_NONE), CF_NONE, false));
|
list.push_back(std::make_unique<DropDownListStringItem>(this->GetCargoFilterLabel(CargoFilterCriteria::CF_NONE), CargoFilterCriteria::CF_NONE, false));
|
||||||
|
|
||||||
/* Add cargos */
|
/* Add cargos */
|
||||||
Dimension d = GetLargestCargoIconSize();
|
Dimension d = GetLargestCargoIconSize();
|
||||||
|
@ -1906,7 +1900,7 @@ const StringID IndustryDirectoryWindow::sorter_names[] = {
|
||||||
INVALID_STRING_ID
|
INVALID_STRING_ID
|
||||||
};
|
};
|
||||||
|
|
||||||
CargoID IndustryDirectoryWindow::produced_cargo_filter = CF_ANY;
|
CargoID IndustryDirectoryWindow::produced_cargo_filter = CargoFilterCriteria::CF_ANY;
|
||||||
|
|
||||||
|
|
||||||
/** Window definition of the industry directory gui */
|
/** Window definition of the industry directory gui */
|
||||||
|
|
|
@ -58,7 +58,7 @@ private:
|
||||||
public:
|
public:
|
||||||
Order *next; ///< Pointer to next order. If nullptr, end of list
|
Order *next; ///< Pointer to next order. If nullptr, end of list
|
||||||
|
|
||||||
Order() : flags(0), refit_cargo(CT_NO_REFIT), wait_time(0), travel_time(0), max_speed(UINT16_MAX) {}
|
Order() : flags(0), refit_cargo(CARGO_NO_REFIT), wait_time(0), travel_time(0), max_speed(UINT16_MAX) {}
|
||||||
~Order();
|
~Order();
|
||||||
|
|
||||||
Order(uint32_t packed);
|
Order(uint32_t packed);
|
||||||
|
@ -79,7 +79,7 @@ public:
|
||||||
void Free();
|
void Free();
|
||||||
|
|
||||||
void MakeGoToStation(StationID destination);
|
void MakeGoToStation(StationID destination);
|
||||||
void MakeGoToDepot(DepotID destination, OrderDepotTypeFlags order, OrderNonStopFlags non_stop_type = ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS, OrderDepotActionFlags action = ODATF_SERVICE_ONLY, CargoID cargo = CT_NO_REFIT);
|
void MakeGoToDepot(DepotID destination, OrderDepotTypeFlags order, OrderNonStopFlags non_stop_type = ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS, OrderDepotActionFlags action = ODATF_SERVICE_ONLY, CargoID cargo = CARGO_NO_REFIT);
|
||||||
void MakeGoToWaypoint(StationID destination);
|
void MakeGoToWaypoint(StationID destination);
|
||||||
void MakeLoading(bool ordered);
|
void MakeLoading(bool ordered);
|
||||||
void MakeLeaveStation();
|
void MakeLeaveStation();
|
||||||
|
@ -115,14 +115,14 @@ public:
|
||||||
* @pre IsType(OT_GOTO_DEPOT) || IsType(OT_GOTO_STATION)
|
* @pre IsType(OT_GOTO_DEPOT) || IsType(OT_GOTO_STATION)
|
||||||
* @return true if a refit should happen.
|
* @return true if a refit should happen.
|
||||||
*/
|
*/
|
||||||
inline bool IsRefit() const { return this->refit_cargo < NUM_CARGO || this->refit_cargo == CT_AUTO_REFIT; }
|
inline bool IsRefit() const { return this->refit_cargo < NUM_CARGO || this->refit_cargo == CARGO_AUTO_REFIT; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is this order a auto-refit order.
|
* Is this order a auto-refit order.
|
||||||
* @pre IsType(OT_GOTO_DEPOT) || IsType(OT_GOTO_STATION)
|
* @pre IsType(OT_GOTO_DEPOT) || IsType(OT_GOTO_STATION)
|
||||||
* @return true if a auto-refit should happen.
|
* @return true if a auto-refit should happen.
|
||||||
*/
|
*/
|
||||||
inline bool IsAutoRefit() const { return this->refit_cargo == CT_AUTO_REFIT; }
|
inline bool IsAutoRefit() const { return this->refit_cargo == CARGO_AUTO_REFIT; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the cargo to to refit to.
|
* Get the cargo to to refit to.
|
||||||
|
|
|
@ -237,7 +237,7 @@ Order::Order(uint32_t packed)
|
||||||
this->flags = GB(packed, 8, 8);
|
this->flags = GB(packed, 8, 8);
|
||||||
this->dest = GB(packed, 16, 16);
|
this->dest = GB(packed, 16, 16);
|
||||||
this->next = nullptr;
|
this->next = nullptr;
|
||||||
this->refit_cargo = CT_NO_REFIT;
|
this->refit_cargo = CARGO_NO_REFIT;
|
||||||
this->wait_time = 0;
|
this->wait_time = 0;
|
||||||
this->travel_time = 0;
|
this->travel_time = 0;
|
||||||
this->max_speed = UINT16_MAX;
|
this->max_speed = UINT16_MAX;
|
||||||
|
@ -719,7 +719,7 @@ CommandCost CmdInsertOrder(DoCommandFlag flags, VehicleID veh, VehicleOrderID se
|
||||||
if (ret.Failed()) return ret;
|
if (ret.Failed()) return ret;
|
||||||
|
|
||||||
/* Validate properties we don't want to have different from default as they are set by other commands. */
|
/* Validate properties we don't want to have different from default as they are set by other commands. */
|
||||||
if (new_order.GetRefitCargo() != CT_NO_REFIT || new_order.GetWaitTime() != 0 || new_order.GetTravelTime() != 0 || new_order.GetMaxSpeed() != UINT16_MAX) return CMD_ERROR;
|
if (new_order.GetRefitCargo() != CARGO_NO_REFIT || new_order.GetWaitTime() != 0 || new_order.GetTravelTime() != 0 || new_order.GetMaxSpeed() != UINT16_MAX) return CMD_ERROR;
|
||||||
|
|
||||||
/* Check if the inserted order is to the correct destination (owner, type),
|
/* Check if the inserted order is to the correct destination (owner, type),
|
||||||
* and has the correct flags if any */
|
* and has the correct flags if any */
|
||||||
|
@ -1326,7 +1326,7 @@ CommandCost CmdModifyOrder(DoCommandFlag flags, VehicleID veh, VehicleOrderID se
|
||||||
case MOF_NON_STOP:
|
case MOF_NON_STOP:
|
||||||
order->SetNonStopType((OrderNonStopFlags)data);
|
order->SetNonStopType((OrderNonStopFlags)data);
|
||||||
if (data & ONSF_NO_STOP_AT_DESTINATION_STATION) {
|
if (data & ONSF_NO_STOP_AT_DESTINATION_STATION) {
|
||||||
order->SetRefit(CT_NO_REFIT);
|
order->SetRefit(CARGO_NO_REFIT);
|
||||||
order->SetLoadType(OLF_LOAD_IF_POSSIBLE);
|
order->SetLoadType(OLF_LOAD_IF_POSSIBLE);
|
||||||
order->SetUnloadType(OUF_UNLOAD_IF_POSSIBLE);
|
order->SetUnloadType(OUF_UNLOAD_IF_POSSIBLE);
|
||||||
}
|
}
|
||||||
|
@ -1342,7 +1342,7 @@ CommandCost CmdModifyOrder(DoCommandFlag flags, VehicleID veh, VehicleOrderID se
|
||||||
|
|
||||||
case MOF_LOAD:
|
case MOF_LOAD:
|
||||||
order->SetLoadType((OrderLoadFlags)data);
|
order->SetLoadType((OrderLoadFlags)data);
|
||||||
if (data & OLFB_NO_LOAD) order->SetRefit(CT_NO_REFIT);
|
if (data & OLFB_NO_LOAD) order->SetRefit(CARGO_NO_REFIT);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MOF_DEPOT_ACTION: {
|
case MOF_DEPOT_ACTION: {
|
||||||
|
@ -1355,13 +1355,13 @@ CommandCost CmdModifyOrder(DoCommandFlag flags, VehicleID veh, VehicleOrderID se
|
||||||
case DA_SERVICE:
|
case DA_SERVICE:
|
||||||
order->SetDepotOrderType((OrderDepotTypeFlags)(order->GetDepotOrderType() | ODTFB_SERVICE));
|
order->SetDepotOrderType((OrderDepotTypeFlags)(order->GetDepotOrderType() | ODTFB_SERVICE));
|
||||||
order->SetDepotActionType((OrderDepotActionFlags)(order->GetDepotActionType() & ~ODATFB_HALT));
|
order->SetDepotActionType((OrderDepotActionFlags)(order->GetDepotActionType() & ~ODATFB_HALT));
|
||||||
order->SetRefit(CT_NO_REFIT);
|
order->SetRefit(CARGO_NO_REFIT);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DA_STOP:
|
case DA_STOP:
|
||||||
order->SetDepotOrderType((OrderDepotTypeFlags)(order->GetDepotOrderType() & ~ODTFB_SERVICE));
|
order->SetDepotOrderType((OrderDepotTypeFlags)(order->GetDepotOrderType() & ~ODTFB_SERVICE));
|
||||||
order->SetDepotActionType((OrderDepotActionFlags)(order->GetDepotActionType() | ODATFB_HALT));
|
order->SetDepotActionType((OrderDepotActionFlags)(order->GetDepotActionType() | ODATFB_HALT));
|
||||||
order->SetRefit(CT_NO_REFIT);
|
order->SetRefit(CARGO_NO_REFIT);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -1618,7 +1618,7 @@ CommandCost CmdCloneOrder(DoCommandFlag flags, CloneOptions action, VehicleID ve
|
||||||
*/
|
*/
|
||||||
CommandCost CmdOrderRefit(DoCommandFlag flags, VehicleID veh, VehicleOrderID order_number, CargoID cargo)
|
CommandCost CmdOrderRefit(DoCommandFlag flags, VehicleID veh, VehicleOrderID order_number, CargoID cargo)
|
||||||
{
|
{
|
||||||
if (cargo >= NUM_CARGO && cargo != CT_NO_REFIT && cargo != CT_AUTO_REFIT) return CMD_ERROR;
|
if (cargo >= NUM_CARGO && cargo != CARGO_NO_REFIT && cargo != CARGO_AUTO_REFIT) return CMD_ERROR;
|
||||||
|
|
||||||
const Vehicle *v = Vehicle::GetIfValid(veh);
|
const Vehicle *v = Vehicle::GetIfValid(veh);
|
||||||
if (v == nullptr || !v->IsPrimaryVehicle()) return CMD_ERROR;
|
if (v == nullptr || !v->IsPrimaryVehicle()) return CMD_ERROR;
|
||||||
|
@ -1630,7 +1630,7 @@ CommandCost CmdOrderRefit(DoCommandFlag flags, VehicleID veh, VehicleOrderID ord
|
||||||
if (order == nullptr) return CMD_ERROR;
|
if (order == nullptr) return CMD_ERROR;
|
||||||
|
|
||||||
/* Automatic refit cargo is only supported for goto station orders. */
|
/* Automatic refit cargo is only supported for goto station orders. */
|
||||||
if (cargo == CT_AUTO_REFIT && !order->IsType(OT_GOTO_STATION)) return CMD_ERROR;
|
if (cargo == CARGO_AUTO_REFIT && !order->IsType(OT_GOTO_STATION)) return CMD_ERROR;
|
||||||
|
|
||||||
if (order->GetLoadType() & OLFB_NO_LOAD) return CMD_ERROR;
|
if (order->GetLoadType() & OLFB_NO_LOAD) return CMD_ERROR;
|
||||||
|
|
||||||
|
@ -1638,7 +1638,7 @@ CommandCost CmdOrderRefit(DoCommandFlag flags, VehicleID veh, VehicleOrderID ord
|
||||||
order->SetRefit(cargo);
|
order->SetRefit(cargo);
|
||||||
|
|
||||||
/* Make the depot order an 'always go' order. */
|
/* Make the depot order an 'always go' order. */
|
||||||
if (cargo != CT_NO_REFIT && order->IsType(OT_GOTO_DEPOT)) {
|
if (cargo != CARGO_NO_REFIT && order->IsType(OT_GOTO_DEPOT)) {
|
||||||
order->SetDepotOrderType((OrderDepotTypeFlags)(order->GetDepotOrderType() & ~ODTFB_SERVICE));
|
order->SetDepotOrderType((OrderDepotTypeFlags)(order->GetDepotOrderType() & ~ODTFB_SERVICE));
|
||||||
order->SetDepotActionType((OrderDepotActionFlags)(order->GetDepotActionType() & ~ODATFB_HALT));
|
order->SetDepotActionType((OrderDepotActionFlags)(order->GetDepotActionType() & ~ODATFB_HALT));
|
||||||
}
|
}
|
||||||
|
|
|
@ -749,10 +749,10 @@ private:
|
||||||
{
|
{
|
||||||
if (_ctrl_pressed) {
|
if (_ctrl_pressed) {
|
||||||
/* Cancel refitting */
|
/* Cancel refitting */
|
||||||
Command<CMD_ORDER_REFIT>::Post(this->vehicle->tile, this->vehicle->index, this->OrderGetSel(), CT_NO_REFIT);
|
Command<CMD_ORDER_REFIT>::Post(this->vehicle->tile, this->vehicle->index, this->OrderGetSel(), CARGO_NO_REFIT);
|
||||||
} else {
|
} else {
|
||||||
if (i == 1) { // Auto-refit to available cargo type.
|
if (i == 1) { // Auto-refit to available cargo type.
|
||||||
Command<CMD_ORDER_REFIT>::Post(this->vehicle->tile, this->vehicle->index, this->OrderGetSel(), CT_AUTO_REFIT);
|
Command<CMD_ORDER_REFIT>::Post(this->vehicle->tile, this->vehicle->index, this->OrderGetSel(), CARGO_AUTO_REFIT);
|
||||||
} else {
|
} else {
|
||||||
ShowVehicleRefitWindow(this->vehicle, this->OrderGetSel(), this, auto_refit);
|
ShowVehicleRefitWindow(this->vehicle, this->OrderGetSel(), this, auto_refit);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1462,11 +1462,11 @@ bool AfterLoadGame()
|
||||||
/* Setting no refit flags to all orders in savegames from before refit in orders were added */
|
/* Setting no refit flags to all orders in savegames from before refit in orders were added */
|
||||||
if (IsSavegameVersionBefore(SLV_36)) {
|
if (IsSavegameVersionBefore(SLV_36)) {
|
||||||
for (Order *order : Order::Iterate()) {
|
for (Order *order : Order::Iterate()) {
|
||||||
order->SetRefit(CT_NO_REFIT);
|
order->SetRefit(CARGO_NO_REFIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Vehicle *v : Vehicle::Iterate()) {
|
for (Vehicle *v : Vehicle::Iterate()) {
|
||||||
v->current_order.SetRefit(CT_NO_REFIT);
|
v->current_order.SetRefit(CARGO_NO_REFIT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,8 +55,8 @@ public:
|
||||||
*/
|
*/
|
||||||
enum SpecialCargoID {
|
enum SpecialCargoID {
|
||||||
/* Note: these values represent part of the in-game CargoTypes enum */
|
/* Note: these values represent part of the in-game CargoTypes enum */
|
||||||
CT_AUTO_REFIT = ::CT_AUTO_REFIT, ///< Automatically choose cargo type when doing auto-refitting.
|
CT_AUTO_REFIT = ::CARGO_AUTO_REFIT, ///< Automatically choose cargo type when doing auto-refitting.
|
||||||
CT_NO_REFIT = ::CT_NO_REFIT, ///< Do not refit cargo of a vehicle.
|
CT_NO_REFIT = ::CARGO_NO_REFIT, ///< Do not refit cargo of a vehicle.
|
||||||
CT_INVALID = ::INVALID_CARGO, ///< An invalid cargo type.
|
CT_INVALID = ::INVALID_CARGO, ///< An invalid cargo type.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -372,11 +372,11 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
|
||||||
|
|
||||||
/* static */ CargoID ScriptOrder::GetOrderRefit(VehicleID vehicle_id, OrderPosition order_position)
|
/* static */ CargoID ScriptOrder::GetOrderRefit(VehicleID vehicle_id, OrderPosition order_position)
|
||||||
{
|
{
|
||||||
if (!IsValidVehicleOrder(vehicle_id, order_position)) return CT_NO_REFIT;
|
if (!IsValidVehicleOrder(vehicle_id, order_position)) return CARGO_NO_REFIT;
|
||||||
if (order_position != ORDER_CURRENT && !IsGotoStationOrder(vehicle_id, order_position) && !IsGotoDepotOrder(vehicle_id, order_position)) return CT_NO_REFIT;
|
if (order_position != ORDER_CURRENT && !IsGotoStationOrder(vehicle_id, order_position) && !IsGotoDepotOrder(vehicle_id, order_position)) return CARGO_NO_REFIT;
|
||||||
|
|
||||||
const Order *order = ::ResolveOrder(vehicle_id, order_position);
|
const Order *order = ::ResolveOrder(vehicle_id, order_position);
|
||||||
return order->IsRefit() ? order->GetRefitCargo() : (CargoID)CT_NO_REFIT;
|
return order->IsRefit() ? order->GetRefitCargo() : CARGO_NO_REFIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */ bool ScriptOrder::SetOrderJumpTo(VehicleID vehicle_id, OrderPosition order_position, OrderPosition jump_to)
|
/* static */ bool ScriptOrder::SetOrderJumpTo(VehicleID vehicle_id, OrderPosition order_position, OrderPosition jump_to)
|
||||||
|
@ -441,8 +441,8 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
|
||||||
{
|
{
|
||||||
EnforceCompanyModeValid(false);
|
EnforceCompanyModeValid(false);
|
||||||
EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position));
|
EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position));
|
||||||
EnforcePrecondition(false, IsGotoStationOrder(vehicle_id, order_position) || (IsGotoDepotOrder(vehicle_id, order_position) && refit_cargo != CT_AUTO_REFIT));
|
EnforcePrecondition(false, IsGotoStationOrder(vehicle_id, order_position) || (IsGotoDepotOrder(vehicle_id, order_position) && refit_cargo != CARGO_AUTO_REFIT));
|
||||||
EnforcePrecondition(false, ScriptCargo::IsValidCargo(refit_cargo) || refit_cargo == CT_AUTO_REFIT || refit_cargo == CT_NO_REFIT);
|
EnforcePrecondition(false, ScriptCargo::IsValidCargo(refit_cargo) || refit_cargo == CARGO_AUTO_REFIT || refit_cargo == CARGO_NO_REFIT);
|
||||||
|
|
||||||
return ScriptObject::Command<CMD_ORDER_REFIT>::Do(0, vehicle_id, ScriptOrderPositionToRealOrderPosition(vehicle_id, ScriptOrder::ResolveOrderPosition(vehicle_id, order_position)), refit_cargo);
|
return ScriptObject::Command<CMD_ORDER_REFIT>::Do(0, vehicle_id, ScriptOrderPositionToRealOrderPosition(vehicle_id, ScriptOrder::ResolveOrderPosition(vehicle_id, order_position)), refit_cargo);
|
||||||
}
|
}
|
||||||
|
|
|
@ -245,16 +245,16 @@ void BaseVehicleListWindow::BuildVehicleList()
|
||||||
*/
|
*/
|
||||||
static bool CargoFilterSingle(const Vehicle *v, const CargoID cid)
|
static bool CargoFilterSingle(const Vehicle *v, const CargoID cid)
|
||||||
{
|
{
|
||||||
if (cid == BaseVehicleListWindow::CF_ANY) {
|
if (cid == CargoFilterCriteria::CF_ANY) {
|
||||||
return true;
|
return true;
|
||||||
} else if (cid == BaseVehicleListWindow::CF_NONE) {
|
} else if (cid == CargoFilterCriteria::CF_NONE) {
|
||||||
for (const Vehicle *w = v; w != nullptr; w = w->Next()) {
|
for (const Vehicle *w = v; w != nullptr; w = w->Next()) {
|
||||||
if (w->cargo_cap > 0) {
|
if (w->cargo_cap > 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else if (cid == BaseVehicleListWindow::CF_FREIGHT) {
|
} else if (cid == CargoFilterCriteria::CF_FREIGHT) {
|
||||||
bool have_capacity = false;
|
bool have_capacity = false;
|
||||||
for (const Vehicle *w = v; w != nullptr; w = w->Next()) {
|
for (const Vehicle *w = v; w != nullptr; w = w->Next()) {
|
||||||
if (w->cargo_cap > 0) {
|
if (w->cargo_cap > 0) {
|
||||||
|
@ -308,7 +308,7 @@ void BaseVehicleListWindow::SetCargoFilter(CargoID cid)
|
||||||
if (this->cargo_filter_criteria != cid) {
|
if (this->cargo_filter_criteria != cid) {
|
||||||
this->cargo_filter_criteria = cid;
|
this->cargo_filter_criteria = cid;
|
||||||
/* Deactivate filter if criteria is 'Show All', activate it otherwise. */
|
/* Deactivate filter if criteria is 'Show All', activate it otherwise. */
|
||||||
this->vehgroups.SetFilterState(this->cargo_filter_criteria != CF_ANY);
|
this->vehgroups.SetFilterState(this->cargo_filter_criteria != CargoFilterCriteria::CF_ANY);
|
||||||
this->vehgroups.SetFilterType(0);
|
this->vehgroups.SetFilterType(0);
|
||||||
this->vehgroups.ForceRebuild();
|
this->vehgroups.ForceRebuild();
|
||||||
}
|
}
|
||||||
|
@ -319,9 +319,9 @@ void BaseVehicleListWindow::SetCargoFilter(CargoID cid)
|
||||||
*/
|
*/
|
||||||
void BaseVehicleListWindow::SetCargoFilterArray()
|
void BaseVehicleListWindow::SetCargoFilterArray()
|
||||||
{
|
{
|
||||||
this->cargo_filter_criteria = CF_ANY;
|
this->cargo_filter_criteria = CargoFilterCriteria::CF_ANY;
|
||||||
this->vehgroups.SetFilterFuncs(_filter_funcs);
|
this->vehgroups.SetFilterFuncs(_filter_funcs);
|
||||||
this->vehgroups.SetFilterState(this->cargo_filter_criteria != CF_ANY);
|
this->vehgroups.SetFilterState(this->cargo_filter_criteria != CargoFilterCriteria::CF_ANY);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -372,9 +372,9 @@ void BaseVehicleListWindow::OnInit()
|
||||||
StringID BaseVehicleListWindow::GetCargoFilterLabel(CargoID cid) const
|
StringID BaseVehicleListWindow::GetCargoFilterLabel(CargoID cid) const
|
||||||
{
|
{
|
||||||
switch (cid) {
|
switch (cid) {
|
||||||
case CF_ANY: return STR_CARGO_TYPE_FILTER_ALL;
|
case CargoFilterCriteria::CF_ANY: return STR_CARGO_TYPE_FILTER_ALL;
|
||||||
case CF_FREIGHT: return STR_CARGO_TYPE_FILTER_FREIGHT;
|
case CargoFilterCriteria::CF_FREIGHT: return STR_CARGO_TYPE_FILTER_FREIGHT;
|
||||||
case CF_NONE: return STR_CARGO_TYPE_FILTER_NONE;
|
case CargoFilterCriteria::CF_NONE: return STR_CARGO_TYPE_FILTER_NONE;
|
||||||
default: return CargoSpec::Get(cid)->name;
|
default: return CargoSpec::Get(cid)->name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -389,11 +389,11 @@ DropDownList BaseVehicleListWindow::BuildCargoDropDownList(bool full) const
|
||||||
DropDownList list;
|
DropDownList list;
|
||||||
|
|
||||||
/* Add item for disabling filtering. */
|
/* Add item for disabling filtering. */
|
||||||
list.push_back(std::make_unique<DropDownListStringItem>(this->GetCargoFilterLabel(CF_ANY), CF_ANY, false));
|
list.push_back(std::make_unique<DropDownListStringItem>(this->GetCargoFilterLabel(CargoFilterCriteria::CF_ANY), CargoFilterCriteria::CF_ANY, false));
|
||||||
/* Add item for freight (i.e. vehicles with cargo capacity and with no passenger capacity). */
|
/* Add item for freight (i.e. vehicles with cargo capacity and with no passenger capacity). */
|
||||||
list.push_back(std::make_unique<DropDownListStringItem>(this->GetCargoFilterLabel(CF_FREIGHT), CF_FREIGHT, false));
|
list.push_back(std::make_unique<DropDownListStringItem>(this->GetCargoFilterLabel(CargoFilterCriteria::CF_FREIGHT), CargoFilterCriteria::CF_FREIGHT, false));
|
||||||
/* Add item for vehicles not carrying anything, e.g. train engines. */
|
/* Add item for vehicles not carrying anything, e.g. train engines. */
|
||||||
list.push_back(std::make_unique<DropDownListStringItem>(this->GetCargoFilterLabel(CF_NONE), CF_NONE, false));
|
list.push_back(std::make_unique<DropDownListStringItem>(this->GetCargoFilterLabel(CargoFilterCriteria::CF_NONE), CargoFilterCriteria::CF_NONE, false));
|
||||||
|
|
||||||
/* Add cargos */
|
/* Add cargos */
|
||||||
Dimension d = GetLargestCargoIconSize();
|
Dimension d = GetLargestCargoIconSize();
|
||||||
|
|
|
@ -73,13 +73,6 @@ struct BaseVehicleListWindow : public Window {
|
||||||
GB_END,
|
GB_END,
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Special cargo filter criteria */
|
|
||||||
enum CargoFilterSpecialType {
|
|
||||||
CF_NONE = INVALID_CARGO, ///< Show only vehicles which do not carry cargo (e.g. train engines)
|
|
||||||
CF_ANY = CT_NO_REFIT, ///< Show all vehicles independent of carried cargo (i.e. no filtering)
|
|
||||||
CF_FREIGHT = CT_AUTO_REFIT, ///< Show only vehicles which carry any freight (non-passenger) cargo
|
|
||||||
};
|
|
||||||
|
|
||||||
GroupBy grouping; ///< How we want to group the list.
|
GroupBy grouping; ///< How we want to group the list.
|
||||||
VehicleList vehicles; ///< List of vehicles. This is the buffer for `vehgroups` to point into; if this is structurally modified, `vehgroups` must be rebuilt.
|
VehicleList vehicles; ///< List of vehicles. This is the buffer for `vehgroups` to point into; if this is structurally modified, `vehgroups` must be rebuilt.
|
||||||
GUIVehicleGroupList vehgroups; ///< List of (groups of) vehicles. This stores iterators of `vehicles`, and should be rebuilt if `vehicles` is structurally changed.
|
GUIVehicleGroupList vehgroups; ///< List of (groups of) vehicles. This stores iterators of `vehicles`, and should be rebuilt if `vehicles` is structurally changed.
|
||||||
|
|
Loading…
Reference in New Issue