mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Use EnumBitSet for VehicleFlags. (#13793)
parent
dc343ca141
commit
8b39b23d2b
|
@ -354,8 +354,8 @@ CommandCost CmdBuildAircraft(DoCommandFlags flags, TileIndex tile, const Engine
|
|||
v->random_bits = Random();
|
||||
u->random_bits = Random();
|
||||
|
||||
v->vehicle_flags = 0;
|
||||
if (e->flags.Test(EngineFlag::ExclusivePreview)) SetBit(v->vehicle_flags, VF_BUILT_AS_PROTOTYPE);
|
||||
v->vehicle_flags = {};
|
||||
if (e->flags.Test(EngineFlag::ExclusivePreview)) v->vehicle_flags.Set(VehicleFlag::BuiltAsPrototype);
|
||||
v->SetServiceIntervalIsPercent(Company::Get(_current_company)->settings.vehicle.servint_ispercent);
|
||||
|
||||
v->InvalidateNewGRFCacheOfChain();
|
||||
|
|
|
@ -34,13 +34,13 @@ void BaseConsist::CopyConsistPropertiesFrom(const BaseConsist *src)
|
|||
this->cur_real_order_index = src->cur_real_order_index;
|
||||
this->cur_implicit_order_index = src->cur_implicit_order_index;
|
||||
|
||||
if (HasBit(src->vehicle_flags, VF_TIMETABLE_STARTED)) SetBit(this->vehicle_flags, VF_TIMETABLE_STARTED);
|
||||
if (HasBit(src->vehicle_flags, VF_AUTOFILL_TIMETABLE)) SetBit(this->vehicle_flags, VF_AUTOFILL_TIMETABLE);
|
||||
if (HasBit(src->vehicle_flags, VF_AUTOFILL_PRES_WAIT_TIME)) SetBit(this->vehicle_flags, VF_AUTOFILL_PRES_WAIT_TIME);
|
||||
if (HasBit(src->vehicle_flags, VF_SERVINT_IS_PERCENT) != HasBit(this->vehicle_flags, VF_SERVINT_IS_PERCENT)) {
|
||||
ToggleBit(this->vehicle_flags, VF_SERVINT_IS_PERCENT);
|
||||
if (src->vehicle_flags.Test(VehicleFlag::TimetableStarted)) this->vehicle_flags.Set(VehicleFlag::TimetableStarted);
|
||||
if (src->vehicle_flags.Test(VehicleFlag::AutofillTimetable)) this->vehicle_flags.Set(VehicleFlag::AutofillTimetable);
|
||||
if (src->vehicle_flags.Test(VehicleFlag::AutofillPreserveWaitTime)) this->vehicle_flags.Set(VehicleFlag::AutofillPreserveWaitTime);
|
||||
if (src->vehicle_flags.Test(VehicleFlag::ServiceIntervalIsPercent) != this->vehicle_flags.Test(VehicleFlag::ServiceIntervalIsPercent)) {
|
||||
this->vehicle_flags.Flip(VehicleFlag::ServiceIntervalIsPercent);
|
||||
}
|
||||
if (HasBit(src->vehicle_flags, VF_SERVINT_IS_CUSTOM)) SetBit(this->vehicle_flags, VF_SERVINT_IS_CUSTOM);
|
||||
if (src->vehicle_flags.Test(VehicleFlag::ServiceIntervalIsCustom)) this->vehicle_flags.Set(VehicleFlag::ServiceIntervalIsCustom);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -10,9 +10,25 @@
|
|||
#ifndef BASE_CONSIST_H
|
||||
#define BASE_CONSIST_H
|
||||
|
||||
#include "core/enum_type.hpp"
|
||||
#include "order_type.h"
|
||||
#include "timer/timer_game_tick.h"
|
||||
|
||||
/** Bit numbers in #Vehicle::vehicle_flags. */
|
||||
enum class VehicleFlag : uint8_t {
|
||||
LoadingFinished = 0, ///< Vehicle has finished loading.
|
||||
CargoUnloading = 1, ///< Vehicle is unloading cargo.
|
||||
BuiltAsPrototype = 2, ///< Vehicle is a prototype (accepted as exclusive preview).
|
||||
TimetableStarted = 3, ///< Whether the vehicle has started running on the timetable yet.
|
||||
AutofillTimetable = 4, ///< Whether the vehicle should fill in the timetable automatically.
|
||||
AutofillPreserveWaitTime = 5, ///< Whether non-destructive auto-fill should preserve waiting times
|
||||
StopLoading = 6, ///< Don't load anymore during the next load cycle.
|
||||
PathfinderLost = 7, ///< Vehicle's pathfinder is lost.
|
||||
ServiceIntervalIsCustom = 8, ///< Service interval is custom.
|
||||
ServiceIntervalIsPercent = 9, ///< Service interval is percent.
|
||||
};
|
||||
using VehicleFlags = EnumBitSet<VehicleFlag, uint16_t>;
|
||||
|
||||
/** Various front vehicle properties that are preserved when autoreplacing, using order-backup or switching front engines within a consist. */
|
||||
struct BaseConsist {
|
||||
std::string name{}; ///< Name of vehicle
|
||||
|
@ -31,7 +47,7 @@ struct BaseConsist {
|
|||
VehicleOrderID cur_real_order_index = 0; ///< The index to the current real (non-implicit) order
|
||||
VehicleOrderID cur_implicit_order_index = 0; ///< The index to the current implicit order
|
||||
|
||||
uint16_t vehicle_flags = 0; ///< Used for gradual loading and other miscellaneous things (@see VehicleFlags enum)
|
||||
VehicleFlags vehicle_flags{}; ///< Used for gradual loading and other miscellaneous things (@see VehicleFlags enum)
|
||||
|
||||
virtual ~BaseConsist() = default;
|
||||
|
||||
|
|
|
@ -1266,7 +1266,7 @@ void PrepareUnload(Vehicle *front_v)
|
|||
curr_station->loading_vehicles.push_back(front_v);
|
||||
|
||||
/* At this moment loading cannot be finished */
|
||||
ClrBit(front_v->vehicle_flags, VF_LOADING_FINISHED);
|
||||
front_v->vehicle_flags.Reset(VehicleFlag::LoadingFinished);
|
||||
|
||||
/* Start unloading at the first possible moment */
|
||||
front_v->load_unload_ticks = 1;
|
||||
|
@ -1290,7 +1290,7 @@ void PrepareUnload(Vehicle *front_v)
|
|||
front_v->current_order.GetUnloadType(), ge,
|
||||
v->cargo_type, front_v->cargo_payment,
|
||||
v->GetCargoTile());
|
||||
if (v->cargo.UnloadCount() > 0) SetBit(v->vehicle_flags, VF_CARGO_UNLOADING);
|
||||
if (v->cargo.UnloadCount() > 0) v->vehicle_flags.Set(VehicleFlag::CargoUnloading);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1642,7 +1642,7 @@ static void LoadUnloadVehicle(Vehicle *front)
|
|||
if (front->type == VEH_TRAIN && (!IsTileType(front->tile, MP_STATION) || GetStationIndex(front->tile) != st->index)) {
|
||||
/* The train reversed in the station. Take the "easy" way
|
||||
* out and let the train just leave as it always did. */
|
||||
SetBit(front->vehicle_flags, VF_LOADING_FINISHED);
|
||||
front->vehicle_flags.Set(VehicleFlag::LoadingFinished);
|
||||
front->load_unload_ticks = 1;
|
||||
return;
|
||||
}
|
||||
|
@ -1671,7 +1671,7 @@ static void LoadUnloadVehicle(Vehicle *front)
|
|||
|
||||
GoodsEntry *ge = &st->goods[v->cargo_type];
|
||||
|
||||
if (HasBit(v->vehicle_flags, VF_CARGO_UNLOADING) && (front->current_order.GetUnloadType() & OUFB_NO_UNLOAD) == 0) {
|
||||
if (v->vehicle_flags.Test(VehicleFlag::CargoUnloading) && (front->current_order.GetUnloadType() & OUFB_NO_UNLOAD) == 0) {
|
||||
uint cargo_count = v->cargo.UnloadCount();
|
||||
uint amount_unloaded = _settings_game.order.gradual_loading ? std::min(cargo_count, GetLoadAmount(v)) : cargo_count;
|
||||
bool remaining = false; // Are there cargo entities in this vehicle that can still be unloaded here?
|
||||
|
@ -1729,14 +1729,14 @@ static void LoadUnloadVehicle(Vehicle *front)
|
|||
completely_emptied = false;
|
||||
} else {
|
||||
/* We have finished unloading (cargo count == 0) */
|
||||
ClrBit(v->vehicle_flags, VF_CARGO_UNLOADING);
|
||||
v->vehicle_flags.Reset(VehicleFlag::CargoUnloading);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Do not pick up goods when we have no-load set or loading is stopped. */
|
||||
if (front->current_order.GetLoadType() & OLFB_NO_LOAD || HasBit(front->vehicle_flags, VF_STOP_LOADING)) continue;
|
||||
if (front->current_order.GetLoadType() & OLFB_NO_LOAD || front->vehicle_flags.Test(VehicleFlag::StopLoading)) continue;
|
||||
|
||||
/* This order has a refit, if this is the first vehicle part carrying cargo and the whole vehicle is empty, try refitting. */
|
||||
if (front->current_order.IsRefit() && artic_part == 1) {
|
||||
|
@ -1849,7 +1849,7 @@ static void LoadUnloadVehicle(Vehicle *front)
|
|||
|
||||
if (!anything_unloaded) delete payment;
|
||||
|
||||
ClrBit(front->vehicle_flags, VF_STOP_LOADING);
|
||||
front->vehicle_flags.Reset(VehicleFlag::StopLoading);
|
||||
if (anything_loaded || anything_unloaded) {
|
||||
if (_settings_game.order.gradual_loading) {
|
||||
/* The time it takes to load one 'slice' of cargo or passengers depends
|
||||
|
@ -1862,7 +1862,7 @@ static void LoadUnloadVehicle(Vehicle *front)
|
|||
* load and we're not supposed to wait any longer: stop loading. */
|
||||
if (!anything_unloaded && full_load_amount == 0 && reservation_left == 0 && !(front->current_order.GetLoadType() & OLFB_FULL_LOAD) &&
|
||||
front->current_order_time >= std::max(front->current_order.GetTimetabledWait() - front->lateness_counter, 0)) {
|
||||
SetBit(front->vehicle_flags, VF_STOP_LOADING);
|
||||
front->vehicle_flags.Set(VehicleFlag::StopLoading);
|
||||
}
|
||||
|
||||
UpdateLoadUnloadTicks(front, st, new_load_unload_ticks);
|
||||
|
@ -1889,7 +1889,7 @@ static void LoadUnloadVehicle(Vehicle *front)
|
|||
if (!finished_loading) LinkRefresher::Run(front, true, true);
|
||||
}
|
||||
|
||||
SB(front->vehicle_flags, VF_LOADING_FINISHED, 1, finished_loading);
|
||||
front->vehicle_flags.Set(VehicleFlag::LoadingFinished, finished_loading);
|
||||
}
|
||||
|
||||
/* Calculate the loading indicator fill percent and display
|
||||
|
|
|
@ -727,8 +727,8 @@ static uint32_t VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *objec
|
|||
if (powered && !has_power) SetBit(modflags, 6);
|
||||
if (HasBit(t->flags, VRF_TOGGLE_REVERSE)) SetBit(modflags, 8);
|
||||
}
|
||||
if (HasBit(v->vehicle_flags, VF_CARGO_UNLOADING)) SetBit(modflags, 1);
|
||||
if (HasBit(v->vehicle_flags, VF_BUILT_AS_PROTOTYPE)) SetBit(modflags, 10);
|
||||
if (v->vehicle_flags.Test(VehicleFlag::CargoUnloading)) SetBit(modflags, 1);
|
||||
if (v->vehicle_flags.Test(VehicleFlag::BuiltAsPrototype)) SetBit(modflags, 10);
|
||||
|
||||
return variable == 0xFE ? modflags : GB(modflags, 8, 8);
|
||||
}
|
||||
|
|
|
@ -312,7 +312,7 @@ CommandCost CmdBuildRoadVehicle(DoCommandFlags flags, TileIndex tile, const Engi
|
|||
v->compatible_roadtypes = rti->powered_roadtypes;
|
||||
v->gcache.cached_veh_length = VEHICLE_LENGTH;
|
||||
|
||||
if (e->flags.Test(EngineFlag::ExclusivePreview)) SetBit(v->vehicle_flags, VF_BUILT_AS_PROTOTYPE);
|
||||
if (e->flags.Test(EngineFlag::ExclusivePreview)) v->vehicle_flags.Set(VehicleFlag::BuiltAsPrototype);
|
||||
v->SetServiceIntervalIsPercent(Company::Get(_current_company)->settings.vehicle.servint_ispercent);
|
||||
|
||||
AddArticulatedParts(v);
|
||||
|
|
|
@ -1599,7 +1599,7 @@ bool AfterLoadGame()
|
|||
* loading again, even if it didn't actually load anything, so now the
|
||||
* amount that has been paid is stored. */
|
||||
for (Vehicle *v : Vehicle::Iterate()) {
|
||||
ClrBit(v->vehicle_flags, 2);
|
||||
v->vehicle_flags.Reset(VehicleFlag{2});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1654,7 +1654,7 @@ bool AfterLoadGame()
|
|||
|
||||
/* The loading finished flag is *only* set when actually completely
|
||||
* finished. Because the vehicle is loading, it is not finished. */
|
||||
ClrBit(v->vehicle_flags, VF_LOADING_FINISHED);
|
||||
v->vehicle_flags.Reset(VehicleFlag::LoadingFinished);
|
||||
}
|
||||
}
|
||||
} else if (IsSavegameVersionBefore(SLV_59)) {
|
||||
|
@ -2665,7 +2665,7 @@ bool AfterLoadGame()
|
|||
if (!HasBit(t->flags, 5)) continue;
|
||||
|
||||
ClrBit(t->flags, 5);
|
||||
SetBit(t->vehicle_flags, VF_PATHFINDER_LOST);
|
||||
t->vehicle_flags.Set(VehicleFlag::PathfinderLost);
|
||||
}
|
||||
|
||||
/* Introduced terraform/clear limits. */
|
||||
|
|
|
@ -945,7 +945,7 @@ CommandCost CmdBuildShip(DoCommandFlags flags, TileIndex tile, const Engine *e,
|
|||
v->acceleration = svi->acceleration;
|
||||
v->UpdateCache();
|
||||
|
||||
if (e->flags.Test(EngineFlag::ExclusivePreview)) SetBit(v->vehicle_flags, VF_BUILT_AS_PROTOTYPE);
|
||||
if (e->flags.Test(EngineFlag::ExclusivePreview)) v->vehicle_flags.Set(VehicleFlag::BuiltAsPrototype);
|
||||
v->SetServiceIntervalIsPercent(Company::Get(_current_company)->settings.vehicle.servint_ispercent);
|
||||
|
||||
v->InvalidateNewGRFCacheOfChain();
|
||||
|
|
|
@ -263,7 +263,7 @@ CommandCost CmdSetVehicleOnTime(DoCommandFlags flags, VehicleID veh, bool apply_
|
|||
|
||||
/* A vehicle can't be late if its timetable hasn't started.
|
||||
* If we're setting all vehicles in the group, we handle that below. */
|
||||
if (!apply_to_group && !HasBit(v->vehicle_flags, VF_TIMETABLE_STARTED)) return CommandCost(STR_ERROR_TIMETABLE_NOT_STARTED);
|
||||
if (!apply_to_group && !v->vehicle_flags.Test(VehicleFlag::TimetableStarted)) return CommandCost(STR_ERROR_TIMETABLE_NOT_STARTED);
|
||||
|
||||
CommandCost ret = CheckOwnership(v->owner);
|
||||
if (ret.Failed()) return ret;
|
||||
|
@ -273,7 +273,7 @@ CommandCost CmdSetVehicleOnTime(DoCommandFlags flags, VehicleID veh, bool apply_
|
|||
TimerGameTick::Ticks most_late = 0;
|
||||
for (Vehicle *u = v->FirstShared(); u != nullptr; u = u->NextShared()) {
|
||||
/* A vehicle can't be late if its timetable hasn't started. */
|
||||
if (!HasBit(v->vehicle_flags, VF_TIMETABLE_STARTED)) continue;
|
||||
if (!v->vehicle_flags.Test(VehicleFlag::TimetableStarted)) continue;
|
||||
|
||||
if (u->lateness_counter > most_late) {
|
||||
most_late = u->lateness_counter;
|
||||
|
@ -285,7 +285,7 @@ CommandCost CmdSetVehicleOnTime(DoCommandFlags flags, VehicleID veh, bool apply_
|
|||
if (most_late > 0) {
|
||||
for (Vehicle *u = v->FirstShared(); u != nullptr; u = u->NextShared()) {
|
||||
/* A vehicle can't be late if its timetable hasn't started. */
|
||||
if (!HasBit(v->vehicle_flags, VF_TIMETABLE_STARTED)) continue;
|
||||
if (!v->vehicle_flags.Test(VehicleFlag::TimetableStarted)) continue;
|
||||
|
||||
u->lateness_counter -= most_late;
|
||||
SetWindowDirty(WC_VEHICLE_TIMETABLE, u->index);
|
||||
|
@ -395,7 +395,7 @@ CommandCost CmdSetTimetableStart(DoCommandFlags flags, VehicleID veh_id, bool ti
|
|||
|
||||
for (Vehicle *w : vehs) {
|
||||
w->lateness_counter = 0;
|
||||
ClrBit(w->vehicle_flags, VF_TIMETABLE_STARTED);
|
||||
w->vehicle_flags.Reset(VehicleFlag::TimetableStarted);
|
||||
/* Do multiplication, then division to reduce rounding errors. */
|
||||
w->timetable_start = start_tick + (idx * total_duration / num_vehs);
|
||||
|
||||
|
@ -435,24 +435,24 @@ CommandCost CmdAutofillTimetable(DoCommandFlags flags, VehicleID veh, bool autof
|
|||
/* Start autofilling the timetable, which clears the
|
||||
* "timetable has started" bit. Times are not cleared anymore, but are
|
||||
* overwritten when the order is reached now. */
|
||||
SetBit(v->vehicle_flags, VF_AUTOFILL_TIMETABLE);
|
||||
ClrBit(v->vehicle_flags, VF_TIMETABLE_STARTED);
|
||||
v->vehicle_flags.Set(VehicleFlag::AutofillTimetable);
|
||||
v->vehicle_flags.Reset(VehicleFlag::TimetableStarted);
|
||||
|
||||
/* Overwrite waiting times only if they got longer */
|
||||
if (preserve_wait_time) SetBit(v->vehicle_flags, VF_AUTOFILL_PRES_WAIT_TIME);
|
||||
if (preserve_wait_time) v->vehicle_flags.Set(VehicleFlag::AutofillPreserveWaitTime);
|
||||
|
||||
v->timetable_start = 0;
|
||||
v->lateness_counter = 0;
|
||||
} else {
|
||||
ClrBit(v->vehicle_flags, VF_AUTOFILL_TIMETABLE);
|
||||
ClrBit(v->vehicle_flags, VF_AUTOFILL_PRES_WAIT_TIME);
|
||||
v->vehicle_flags.Reset(VehicleFlag::AutofillTimetable);
|
||||
v->vehicle_flags.Reset(VehicleFlag::AutofillPreserveWaitTime);
|
||||
}
|
||||
|
||||
for (Vehicle *v2 = v->FirstShared(); v2 != nullptr; v2 = v2->NextShared()) {
|
||||
if (v2 != v) {
|
||||
/* Stop autofilling; only one vehicle at a time can perform autofill */
|
||||
ClrBit(v2->vehicle_flags, VF_AUTOFILL_TIMETABLE);
|
||||
ClrBit(v2->vehicle_flags, VF_AUTOFILL_PRES_WAIT_TIME);
|
||||
v2->vehicle_flags.Reset(VehicleFlag::AutofillTimetable);
|
||||
v2->vehicle_flags.Reset(VehicleFlag::AutofillPreserveWaitTime);
|
||||
}
|
||||
SetWindowDirty(WC_VEHICLE_TIMETABLE, v2->index);
|
||||
}
|
||||
|
@ -491,22 +491,22 @@ void UpdateVehicleTimetable(Vehicle *v, bool travelling)
|
|||
* the vehicle last arrived at the first destination, update it to the
|
||||
* current time. Otherwise set the late counter appropriately to when
|
||||
* the vehicle should have arrived. */
|
||||
just_started = !HasBit(v->vehicle_flags, VF_TIMETABLE_STARTED);
|
||||
just_started = !v->vehicle_flags.Test(VehicleFlag::TimetableStarted);
|
||||
|
||||
if (v->timetable_start != 0) {
|
||||
v->lateness_counter = TimerGameTick::counter - v->timetable_start;
|
||||
v->timetable_start = 0;
|
||||
}
|
||||
|
||||
SetBit(v->vehicle_flags, VF_TIMETABLE_STARTED);
|
||||
v->vehicle_flags.Set(VehicleFlag::TimetableStarted);
|
||||
SetWindowDirty(WC_VEHICLE_TIMETABLE, v->index);
|
||||
}
|
||||
|
||||
if (!HasBit(v->vehicle_flags, VF_TIMETABLE_STARTED)) return;
|
||||
if (!v->vehicle_flags.Test(VehicleFlag::TimetableStarted)) return;
|
||||
|
||||
bool autofilling = HasBit(v->vehicle_flags, VF_AUTOFILL_TIMETABLE);
|
||||
bool autofilling = v->vehicle_flags.Test(VehicleFlag::AutofillTimetable);
|
||||
bool remeasure_wait_time = !real_current_order->IsWaitTimetabled() ||
|
||||
(autofilling && !HasBit(v->vehicle_flags, VF_AUTOFILL_PRES_WAIT_TIME));
|
||||
(autofilling && !v->vehicle_flags.Test(VehicleFlag::AutofillPreserveWaitTime));
|
||||
|
||||
if (travelling && remeasure_wait_time) {
|
||||
/* We just finished travelling and want to remeasure the loading time,
|
||||
|
@ -542,8 +542,8 @@ void UpdateVehicleTimetable(Vehicle *v, bool travelling)
|
|||
/* If we just started we would have returned earlier and have not reached
|
||||
* this code. So obviously, we have completed our round: So turn autofill
|
||||
* off again. */
|
||||
ClrBit(v->vehicle_flags, VF_AUTOFILL_TIMETABLE);
|
||||
ClrBit(v->vehicle_flags, VF_AUTOFILL_PRES_WAIT_TIME);
|
||||
v->vehicle_flags.Reset(VehicleFlag::AutofillTimetable);
|
||||
v->vehicle_flags.Reset(VehicleFlag::AutofillPreserveWaitTime);
|
||||
}
|
||||
|
||||
if (autofilling) return;
|
||||
|
|
|
@ -223,7 +223,7 @@ struct TimetableWindow : Window {
|
|||
*/
|
||||
static bool BuildArrivalDepartureList(const Vehicle *v, std::vector<TimetableArrivalDeparture> &table)
|
||||
{
|
||||
assert(HasBit(v->vehicle_flags, VF_TIMETABLE_STARTED));
|
||||
assert(v->vehicle_flags.Test(VehicleFlag::TimetableStarted));
|
||||
|
||||
bool travelling = (!v->current_order.IsType(OT_LOADING) || v->current_order.GetNonStopType() == ONSF_STOP_EVERYWHERE);
|
||||
TimerGameTick::Ticks start_time = -v->current_order_time;
|
||||
|
@ -391,7 +391,7 @@ struct TimetableWindow : Window {
|
|||
this->DisableWidget(WID_VT_SHARED_ORDER_LIST);
|
||||
}
|
||||
|
||||
this->SetWidgetLoweredState(WID_VT_AUTOFILL, HasBit(v->vehicle_flags, VF_AUTOFILL_TIMETABLE));
|
||||
this->SetWidgetLoweredState(WID_VT_AUTOFILL, v->vehicle_flags.Test(VehicleFlag::AutofillTimetable));
|
||||
|
||||
this->DrawWidgets();
|
||||
}
|
||||
|
@ -496,7 +496,7 @@ struct TimetableWindow : Window {
|
|||
* i.e. are only shown if we can calculate all times.
|
||||
* Excluding order lists with only one order makes some things easier. */
|
||||
TimerGameTick::Ticks total_time = v->orders != nullptr ? v->orders->GetTimetableDurationIncomplete() : 0;
|
||||
if (total_time <= 0 || v->GetNumOrders() <= 1 || !HasBit(v->vehicle_flags, VF_TIMETABLE_STARTED)) return;
|
||||
if (total_time <= 0 || v->GetNumOrders() <= 1 || !v->vehicle_flags.Test(VehicleFlag::TimetableStarted)) return;
|
||||
|
||||
std::vector<TimetableArrivalDeparture> arr_dep(v->GetNumOrders());
|
||||
const VehicleOrderID cur_order = v->cur_real_order_index % v->GetNumOrders();
|
||||
|
@ -595,7 +595,7 @@ struct TimetableWindow : Window {
|
|||
/* Other units use dates. */
|
||||
DrawString(tr, GetString(STR_TIMETABLE_STATUS_START_AT_DATE, STR_JUST_DATE_TINY, GetDateFromStartTick(v->timetable_start)));
|
||||
}
|
||||
} else if (!HasBit(v->vehicle_flags, VF_TIMETABLE_STARTED)) {
|
||||
} else if (!v->vehicle_flags.Test(VehicleFlag::TimetableStarted)) {
|
||||
/* We aren't running on a timetable yet. */
|
||||
DrawString(tr, STR_TIMETABLE_STATUS_NOT_STARTED);
|
||||
} else if (!VehicleIsAboveLatenessThreshold(abs(v->lateness_counter), false)) {
|
||||
|
@ -734,7 +734,7 @@ struct TimetableWindow : Window {
|
|||
break;
|
||||
|
||||
case WID_VT_AUTOFILL: { // Autofill the timetable.
|
||||
Command<CMD_AUTOFILL_TIMETABLE>::Post(STR_ERROR_CAN_T_TIMETABLE_VEHICLE, v->index, !HasBit(v->vehicle_flags, VF_AUTOFILL_TIMETABLE), _ctrl_pressed);
|
||||
Command<CMD_AUTOFILL_TIMETABLE>::Post(STR_ERROR_CAN_T_TIMETABLE_VEHICLE, v->index, !v->vehicle_flags.Test(VehicleFlag::AutofillTimetable), _ctrl_pressed);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -795,7 +795,7 @@ CommandCost CmdBuildRailVehicle(DoCommandFlags flags, TileIndex tile, const Engi
|
|||
v->sprite_cache.sprite_seq.Set(SPR_IMG_QUERY);
|
||||
v->random_bits = Random();
|
||||
|
||||
if (e->flags.Test(EngineFlag::ExclusivePreview)) SetBit(v->vehicle_flags, VF_BUILT_AS_PROTOTYPE);
|
||||
if (e->flags.Test(EngineFlag::ExclusivePreview)) v->vehicle_flags.Set(VehicleFlag::BuiltAsPrototype);
|
||||
v->SetServiceIntervalIsPercent(Company::Get(_current_company)->settings.vehicle.servint_ispercent);
|
||||
|
||||
v->group_id = DEFAULT_GROUP;
|
||||
|
|
|
@ -789,10 +789,10 @@ void Vehicle::HandlePathfindingResult(bool path_found)
|
|||
{
|
||||
if (path_found) {
|
||||
/* Route found, is the vehicle marked with "lost" flag? */
|
||||
if (!HasBit(this->vehicle_flags, VF_PATHFINDER_LOST)) return;
|
||||
if (!this->vehicle_flags.Test(VehicleFlag::PathfinderLost)) return;
|
||||
|
||||
/* Clear the flag as the PF's problem was solved. */
|
||||
ClrBit(this->vehicle_flags, VF_PATHFINDER_LOST);
|
||||
this->vehicle_flags.Reset(VehicleFlag::PathfinderLost);
|
||||
SetWindowWidgetDirty(WC_VEHICLE_VIEW, this->index, WID_VV_START_STOP);
|
||||
InvalidateWindowClassesData(GetWindowClassForVehicleType(this->type));
|
||||
/* Delete the news item. */
|
||||
|
@ -801,10 +801,10 @@ void Vehicle::HandlePathfindingResult(bool path_found)
|
|||
}
|
||||
|
||||
/* Were we already lost? */
|
||||
if (HasBit(this->vehicle_flags, VF_PATHFINDER_LOST)) return;
|
||||
if (this->vehicle_flags.Test(VehicleFlag::PathfinderLost)) return;
|
||||
|
||||
/* It is first time the problem occurred, set the "lost" flag. */
|
||||
SetBit(this->vehicle_flags, VF_PATHFINDER_LOST);
|
||||
this->vehicle_flags.Set(VehicleFlag::PathfinderLost);
|
||||
SetWindowWidgetDirty(WC_VEHICLE_VIEW, this->index, WID_VV_START_STOP);
|
||||
InvalidateWindowClassesData(GetWindowClassForVehicleType(this->type));
|
||||
|
||||
|
@ -1505,10 +1505,10 @@ uint8_t CalcPercentVehicleFilled(const Vehicle *front, StringID *colour)
|
|||
count += v->cargo.StoredCount();
|
||||
max += v->cargo_cap;
|
||||
if (v->cargo_cap != 0 && colour != nullptr) {
|
||||
unloading += HasBit(v->vehicle_flags, VF_CARGO_UNLOADING) ? 1 : 0;
|
||||
unloading += v->vehicle_flags.Test(VehicleFlag::CargoUnloading) ? 1 : 0;
|
||||
loading |= !order_no_load &&
|
||||
(order_full_load || st->goods[v->cargo_type].HasRating()) &&
|
||||
!HasBit(front->vehicle_flags, VF_LOADING_FINISHED) && !HasBit(front->vehicle_flags, VF_STOP_LOADING);
|
||||
!front->vehicle_flags.Test(VehicleFlag::LoadingFinished) && !front->vehicle_flags.Test(VehicleFlag::StopLoading);
|
||||
cars++;
|
||||
}
|
||||
}
|
||||
|
@ -2425,7 +2425,7 @@ void Vehicle::HandleLoading(bool mode)
|
|||
TimerGameTick::Ticks wait_time = std::max(this->current_order.GetTimetabledWait() - this->lateness_counter, 0);
|
||||
|
||||
/* Not the first call for this tick, or still loading */
|
||||
if (mode || !HasBit(this->vehicle_flags, VF_LOADING_FINISHED) || this->current_order_time < wait_time) return;
|
||||
if (mode || !this->vehicle_flags.Test(VehicleFlag::LoadingFinished) || this->current_order_time < wait_time) return;
|
||||
|
||||
this->PlayLeaveStationSound();
|
||||
|
||||
|
|
|
@ -41,20 +41,6 @@ enum class VehState : uint8_t {
|
|||
};
|
||||
using VehStates = EnumBitSet<VehState, uint8_t>;
|
||||
|
||||
/** Bit numbers in #Vehicle::vehicle_flags. */
|
||||
enum VehicleFlags : uint8_t {
|
||||
VF_LOADING_FINISHED, ///< Vehicle has finished loading.
|
||||
VF_CARGO_UNLOADING, ///< Vehicle is unloading cargo.
|
||||
VF_BUILT_AS_PROTOTYPE, ///< Vehicle is a prototype (accepted as exclusive preview).
|
||||
VF_TIMETABLE_STARTED, ///< Whether the vehicle has started running on the timetable yet.
|
||||
VF_AUTOFILL_TIMETABLE, ///< Whether the vehicle should fill in the timetable automatically.
|
||||
VF_AUTOFILL_PRES_WAIT_TIME, ///< Whether non-destructive auto-fill should preserve waiting times
|
||||
VF_STOP_LOADING, ///< Don't load anymore during the next load cycle.
|
||||
VF_PATHFINDER_LOST, ///< Vehicle's pathfinder is lost.
|
||||
VF_SERVINT_IS_CUSTOM, ///< Service interval is custom.
|
||||
VF_SERVINT_IS_PERCENT, ///< Service interval is percent.
|
||||
};
|
||||
|
||||
/** Bit numbers used to indicate which of the #NewGRFCache values are valid. */
|
||||
enum NewGRFCacheValidValues : uint8_t {
|
||||
NCVV_POSITION_CONSIST_LENGTH = 0, ///< This bit will be set if the NewGRF var 40 currently stored is valid.
|
||||
|
@ -816,13 +802,13 @@ public:
|
|||
|
||||
inline void SetServiceInterval(uint16_t interval) { this->service_interval = interval; }
|
||||
|
||||
inline bool ServiceIntervalIsCustom() const { return HasBit(this->vehicle_flags, VF_SERVINT_IS_CUSTOM); }
|
||||
inline bool ServiceIntervalIsCustom() const { return this->vehicle_flags.Test(VehicleFlag::ServiceIntervalIsCustom); }
|
||||
|
||||
inline bool ServiceIntervalIsPercent() const { return HasBit(this->vehicle_flags, VF_SERVINT_IS_PERCENT); }
|
||||
inline bool ServiceIntervalIsPercent() const { return this->vehicle_flags.Test(VehicleFlag::ServiceIntervalIsPercent); }
|
||||
|
||||
inline void SetServiceIntervalIsCustom(bool on) { AssignBit(this->vehicle_flags, VF_SERVINT_IS_CUSTOM, on); }
|
||||
inline void SetServiceIntervalIsCustom(bool on) { this->vehicle_flags.Set(VehicleFlag::ServiceIntervalIsCustom, on); }
|
||||
|
||||
inline void SetServiceIntervalIsPercent(bool on) { AssignBit(this->vehicle_flags, VF_SERVINT_IS_PERCENT, on); }
|
||||
inline void SetServiceIntervalIsPercent(bool on) { this->vehicle_flags.Set(VehicleFlag::ServiceIntervalIsPercent, on); }
|
||||
|
||||
bool HasFullLoadOrder() const;
|
||||
bool HasConditionalOrder() const;
|
||||
|
|
|
@ -1789,7 +1789,7 @@ void BaseVehicleListWindow::DrawVehicleListItems(VehicleID selected_vehicle, int
|
|||
case GB_NONE: {
|
||||
const Vehicle *v = vehgroup.GetSingleVehicle();
|
||||
|
||||
if (HasBit(v->vehicle_flags, VF_PATHFINDER_LOST)) {
|
||||
if (v->vehicle_flags.Test(VehicleFlag::PathfinderLost)) {
|
||||
DrawSprite(SPR_WARNING_SIGN, PAL_NONE, vehicle_button_x, ir.top + GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal + profit.height);
|
||||
}
|
||||
|
||||
|
@ -3149,7 +3149,7 @@ public:
|
|||
|
||||
switch (v->current_order.GetType()) {
|
||||
case OT_GOTO_STATION:
|
||||
return GetString(HasBit(v->vehicle_flags, VF_PATHFINDER_LOST) ? STR_VEHICLE_STATUS_CANNOT_REACH_STATION_VEL : STR_VEHICLE_STATUS_HEADING_FOR_STATION_VEL,
|
||||
return GetString(v->vehicle_flags.Test(VehicleFlag::PathfinderLost) ? STR_VEHICLE_STATUS_CANNOT_REACH_STATION_VEL : STR_VEHICLE_STATUS_HEADING_FOR_STATION_VEL,
|
||||
v->current_order.GetDestination(), PackVelocity(v->GetDisplaySpeed(), v->type));
|
||||
|
||||
case OT_GOTO_DEPOT: {
|
||||
|
@ -3163,14 +3163,14 @@ public:
|
|||
|
||||
auto params = MakeParameters(v->type, v->current_order.GetDestination(), PackVelocity(v->GetDisplaySpeed(), v->type));
|
||||
if (v->current_order.GetDepotActionType() & ODATFB_HALT) {
|
||||
return GetStringWithArgs(HasBit(v->vehicle_flags, VF_PATHFINDER_LOST) ? STR_VEHICLE_STATUS_CANNOT_REACH_DEPOT_VEL : STR_VEHICLE_STATUS_HEADING_FOR_DEPOT_VEL, params);
|
||||
return GetStringWithArgs(v->vehicle_flags.Test(VehicleFlag::PathfinderLost) ? STR_VEHICLE_STATUS_CANNOT_REACH_DEPOT_VEL : STR_VEHICLE_STATUS_HEADING_FOR_DEPOT_VEL, params);
|
||||
}
|
||||
|
||||
if (v->current_order.GetDepotActionType() & ODATFB_UNBUNCH) {
|
||||
return GetStringWithArgs(HasBit(v->vehicle_flags, VF_PATHFINDER_LOST) ? STR_VEHICLE_STATUS_CANNOT_REACH_DEPOT_SERVICE_VEL : STR_VEHICLE_STATUS_HEADING_FOR_DEPOT_UNBUNCH_VEL, params);
|
||||
return GetStringWithArgs(v->vehicle_flags.Test(VehicleFlag::PathfinderLost) ? STR_VEHICLE_STATUS_CANNOT_REACH_DEPOT_SERVICE_VEL : STR_VEHICLE_STATUS_HEADING_FOR_DEPOT_UNBUNCH_VEL, params);
|
||||
}
|
||||
|
||||
return GetStringWithArgs(HasBit(v->vehicle_flags, VF_PATHFINDER_LOST) ? STR_VEHICLE_STATUS_CANNOT_REACH_DEPOT_SERVICE_VEL : STR_VEHICLE_STATUS_HEADING_FOR_DEPOT_SERVICE_VEL, params);
|
||||
return GetStringWithArgs(v->vehicle_flags.Test(VehicleFlag::PathfinderLost) ? STR_VEHICLE_STATUS_CANNOT_REACH_DEPOT_SERVICE_VEL : STR_VEHICLE_STATUS_HEADING_FOR_DEPOT_SERVICE_VEL, params);
|
||||
}
|
||||
|
||||
case OT_LOADING:
|
||||
|
@ -3178,7 +3178,7 @@ public:
|
|||
|
||||
case OT_GOTO_WAYPOINT:
|
||||
assert(v->type == VEH_TRAIN || v->type == VEH_ROAD || v->type == VEH_SHIP);
|
||||
return GetString(HasBit(v->vehicle_flags, VF_PATHFINDER_LOST) ? STR_VEHICLE_STATUS_CANNOT_REACH_WAYPOINT_VEL : STR_VEHICLE_STATUS_HEADING_FOR_WAYPOINT_VEL,
|
||||
return GetString(v->vehicle_flags.Test(VehicleFlag::PathfinderLost) ? STR_VEHICLE_STATUS_CANNOT_REACH_WAYPOINT_VEL : STR_VEHICLE_STATUS_HEADING_FOR_WAYPOINT_VEL,
|
||||
v->current_order.GetDestination(),PackVelocity(v->GetDisplaySpeed(), v->type));
|
||||
|
||||
case OT_LEAVESTATION:
|
||||
|
@ -3206,7 +3206,7 @@ public:
|
|||
Rect tr = r.Shrink(WidgetDimensions::scaled.framerect);
|
||||
|
||||
const Vehicle *v = Vehicle::Get(this->window_number);
|
||||
SpriteID image = v->vehstatus.Test(VehState::Stopped) ? SPR_FLAG_VEH_STOPPED : (HasBit(v->vehicle_flags, VF_PATHFINDER_LOST)) ? SPR_WARNING_SIGN : SPR_FLAG_VEH_RUNNING;
|
||||
SpriteID image = v->vehstatus.Test(VehState::Stopped) ? SPR_FLAG_VEH_STOPPED : (v->vehicle_flags.Test(VehicleFlag::PathfinderLost)) ? SPR_WARNING_SIGN : SPR_FLAG_VEH_RUNNING;
|
||||
DrawSpriteIgnorePadding(image, PAL_NONE, tr.WithWidth(icon_width, rtl), SA_CENTER);
|
||||
|
||||
tr = tr.Indent(icon_width + WidgetDimensions::scaled.imgbtn.Horizontal(), rtl);
|
||||
|
|
Loading…
Reference in New Issue