Extend timetable wait/travel times from 16 to 32 bits wide

This commit is contained in:
Jonathan G Rennison
2018-10-22 18:21:30 +01:00
parent ee00a28717
commit 0e3986c39c
9 changed files with 34 additions and 28 deletions

View File

@@ -2029,7 +2029,7 @@ static void LoadUnloadVehicle(Vehicle *front)
/* We loaded less cargo than possible for all cargo types and it's not full /* We loaded less cargo than possible for all cargo types and it's not full
* load and we're not supposed to wait any longer: stop loading. */ * load and we're not supposed to wait any longer: stop loading. */
if (!anything_unloaded && full_load_amount == 0 && reservation_left == 0 && !has_full_load_order && if (!anything_unloaded && full_load_amount == 0 && reservation_left == 0 && !has_full_load_order &&
(front->current_order_time >= (uint)max(front->current_order.GetTimetabledWait() - front->lateness_counter, 0) || (front->current_order_time >= (uint)max<int>(front->current_order.GetTimetabledWait() - front->lateness_counter, 0) ||
front->current_order.GetLeaveType() == OLT_LEAVE_EARLY)) { front->current_order.GetLeaveType() == OLT_LEAVE_EARLY)) {
SetBit(front->vehicle_flags, VF_STOP_LOADING); SetBit(front->vehicle_flags, VF_STOP_LOADING);
} }

View File

@@ -62,8 +62,8 @@ private:
std::unique_ptr<OrderExtraInfo> extra; ///< Extra order info std::unique_ptr<OrderExtraInfo> extra; ///< Extra order info
uint16 wait_time; ///< How long in ticks to wait at the destination. TimetableTicks wait_time; ///< How long in ticks to wait at the destination.
uint16 travel_time; ///< How long in ticks the journey to this destination should take. TimetableTicks travel_time; ///< How long in ticks the journey to this destination should take.
uint16 max_speed; ///< How fast the vehicle may go on the way to the destination. uint16 max_speed; ///< How fast the vehicle may go on the way to the destination.
void AllocExtraInfo(); void AllocExtraInfo();
@@ -376,13 +376,13 @@ public:
inline bool IsTravelTimetabled() const { return this->IsType(OT_CONDITIONAL) ? this->travel_time > 0 : HasBit(this->flags, 7); } inline bool IsTravelTimetabled() const { return this->IsType(OT_CONDITIONAL) ? this->travel_time > 0 : HasBit(this->flags, 7); }
/** Get the time in ticks a vehicle should wait at the destination or 0 if it's not timetabled. */ /** Get the time in ticks a vehicle should wait at the destination or 0 if it's not timetabled. */
inline uint16 GetTimetabledWait() const { return this->IsWaitTimetabled() ? this->wait_time : 0; } inline TimetableTicks GetTimetabledWait() const { return this->IsWaitTimetabled() ? this->wait_time : 0; }
/** Get the time in ticks a vehicle should take to reach the destination or 0 if it's not timetabled. */ /** Get the time in ticks a vehicle should take to reach the destination or 0 if it's not timetabled. */
inline uint16 GetTimetabledTravel() const { return this->IsTravelTimetabled() ? this->travel_time : 0; } inline TimetableTicks GetTimetabledTravel() const { return this->IsTravelTimetabled() ? this->travel_time : 0; }
/** Get the time in ticks a vehicle will probably wait at the destination (timetabled or not). */ /** Get the time in ticks a vehicle will probably wait at the destination (timetabled or not). */
inline uint16 GetWaitTime() const { return this->wait_time; } inline TimetableTicks GetWaitTime() const { return this->wait_time; }
/** Get the time in ticks a vehicle will probably take to reach the destination (timetabled or not). */ /** Get the time in ticks a vehicle will probably take to reach the destination (timetabled or not). */
inline uint16 GetTravelTime() const { return this->travel_time; } inline TimetableTicks GetTravelTime() const { return this->travel_time; }
/** /**
* Get the maxmimum speed in km-ish/h a vehicle is allowed to reach on the way to the * Get the maxmimum speed in km-ish/h a vehicle is allowed to reach on the way to the
@@ -408,13 +408,13 @@ public:
* Set the time in ticks to wait at the destination. * Set the time in ticks to wait at the destination.
* @param time Time to set as wait time. * @param time Time to set as wait time.
*/ */
inline void SetWaitTime(uint16 time) { this->wait_time = time; } inline void SetWaitTime(TimetableTicks time) { this->wait_time = time; }
/** /**
* Set the time in ticks to take for travelling to the destination. * Set the time in ticks to take for travelling to the destination.
* @param time Time to set as travel time. * @param time Time to set as travel time.
*/ */
inline void SetTravelTime(uint16 time) { this->travel_time = time; } inline void SetTravelTime(TimetableTicks time) { this->travel_time = time; }
/** /**
* Set the maxmimum speed in km-ish/h a vehicle is allowed to reach on the way to the * Set the maxmimum speed in km-ish/h a vehicle is allowed to reach on the way to the

View File

@@ -18,6 +18,7 @@ typedef byte VehicleOrderID; ///< The index of an order within its current vehi
typedef uint16 OrderID; typedef uint16 OrderID;
typedef uint16 OrderListID; typedef uint16 OrderListID;
typedef uint16 DestinationID; typedef uint16 DestinationID;
typedef uint32 TimetableTicks;
/** Invalid vehicle order index (sentinel) */ /** Invalid vehicle order index (sentinel) */
static const VehicleOrderID INVALID_VEH_ORDER_ID = 0xFF; static const VehicleOrderID INVALID_VEH_ORDER_ID = 0xFF;

View File

@@ -81,7 +81,7 @@ const SlxiSubChunkInfo _sl_xv_sub_chunk_infos[] = {
{ XSLFI_SCHEDULED_DISPATCH, XSCF_NULL, 1, 1, "scheduled_dispatch", NULL, NULL, NULL }, { XSLFI_SCHEDULED_DISPATCH, XSCF_NULL, 1, 1, "scheduled_dispatch", NULL, NULL, NULL },
{ XSLFI_MORE_TOWN_GROWTH_RATES, XSCF_NULL, 1, 1, "more_town_growth_rates", NULL, NULL, NULL }, { XSLFI_MORE_TOWN_GROWTH_RATES, XSCF_NULL, 1, 1, "more_town_growth_rates", NULL, NULL, NULL },
{ XSLFI_MULTIPLE_DOCKS, XSCF_NULL, 1, 1, "multiple_docks", NULL, NULL, "DOCK" }, { XSLFI_MULTIPLE_DOCKS, XSCF_NULL, 1, 1, "multiple_docks", NULL, NULL, "DOCK" },
{ XSLFI_TIMETABLE_EXTRA, XSCF_NULL, 5, 5, "timetable_extra", NULL, NULL, "ORDX" }, { XSLFI_TIMETABLE_EXTRA, XSCF_NULL, 6, 6, "timetable_extra", NULL, NULL, "ORDX" },
{ XSLFI_TRAIN_FLAGS_EXTRA, XSCF_NULL, 1, 1, "train_flags_extra", NULL, NULL, NULL }, { XSLFI_TRAIN_FLAGS_EXTRA, XSCF_NULL, 1, 1, "train_flags_extra", NULL, NULL, NULL },
{ XSLFI_TRAIN_THROUGH_LOAD, XSCF_NULL, 2, 2, "train_through_load", NULL, NULL, NULL }, { XSLFI_TRAIN_THROUGH_LOAD, XSCF_NULL, 2, 2, "train_through_load", NULL, NULL, NULL },
{ XSLFI_ORDER_EXTRA_DATA, XSCF_NULL, 1, 1, "order_extra_data", NULL, NULL, NULL }, { XSLFI_ORDER_EXTRA_DATA, XSCF_NULL, 1, 1, "order_extra_data", NULL, NULL, NULL },

View File

@@ -112,8 +112,10 @@ const SaveLoad *GetOrderDescription()
SLE_CONDVAR(Order, refit_cargo, SLE_UINT8, 36, SL_MAX_VERSION), SLE_CONDVAR(Order, refit_cargo, SLE_UINT8, 36, SL_MAX_VERSION),
SLE_CONDNULL(1, 36, 181), // refit_subtype SLE_CONDNULL(1, 36, 181), // refit_subtype
SLE_CONDVAR_X(Order, occupancy, SLE_UINT8, 0, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_ORDER_OCCUPANCY)), SLE_CONDVAR_X(Order, occupancy, SLE_UINT8, 0, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_ORDER_OCCUPANCY)),
SLE_CONDVAR(Order, wait_time, SLE_UINT16, 67, SL_MAX_VERSION), SLE_CONDVAR_X(Order, wait_time, SLE_FILE_U16 | SLE_VAR_U32, 67, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_TIMETABLE_EXTRA, 0, 5)),
SLE_CONDVAR(Order, travel_time, SLE_UINT16, 67, SL_MAX_VERSION), SLE_CONDVAR_X(Order, wait_time, SLE_UINT32, 67, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_TIMETABLE_EXTRA, 6)),
SLE_CONDVAR_X(Order, travel_time, SLE_FILE_U16 | SLE_VAR_U32, 67, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_TIMETABLE_EXTRA, 0, 5)),
SLE_CONDVAR_X(Order, travel_time, SLE_UINT32, 67, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_TIMETABLE_EXTRA, 6)),
SLE_CONDVAR(Order, max_speed, SLE_UINT16, 172, SL_MAX_VERSION), SLE_CONDVAR(Order, max_speed, SLE_UINT16, 172, SL_MAX_VERSION),
SLE_CONDVAR_X(Order, jump_counter, SLE_INT8, 0, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_MORE_COND_ORDERS)), SLE_CONDVAR_X(Order, jump_counter, SLE_INT8, 0, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_MORE_COND_ORDERS)),

View File

@@ -665,8 +665,10 @@ const SaveLoad *GetVehicleDescription(VehicleType vt)
SLE_CONDNULL(1, 36, 181), // refit_subtype SLE_CONDNULL(1, 36, 181), // refit_subtype
/* Timetable in current order */ /* Timetable in current order */
SLE_CONDVAR(Vehicle, current_order.wait_time, SLE_UINT16, 67, SL_MAX_VERSION), SLE_CONDVAR_X(Vehicle, current_order.wait_time, SLE_FILE_U16 | SLE_VAR_U32, 67, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_TIMETABLE_EXTRA, 0, 5)),
SLE_CONDVAR(Vehicle, current_order.travel_time, SLE_UINT16, 67, SL_MAX_VERSION), SLE_CONDVAR_X(Vehicle, current_order.wait_time, SLE_UINT32, 67, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_TIMETABLE_EXTRA, 6)),
SLE_CONDVAR_X(Vehicle, current_order.travel_time, SLE_FILE_U16 | SLE_VAR_U32, 67, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_TIMETABLE_EXTRA, 0, 5)),
SLE_CONDVAR_X(Vehicle, current_order.travel_time, SLE_UINT32, 67, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_TIMETABLE_EXTRA, 6)),
SLE_CONDVAR(Vehicle, current_order.max_speed, SLE_UINT16, 174, SL_MAX_VERSION), SLE_CONDVAR(Vehicle, current_order.max_speed, SLE_UINT16, 174, SL_MAX_VERSION),
SLE_CONDVAR(Vehicle, timetable_start, SLE_INT32, 129, SL_MAX_VERSION), SLE_CONDVAR(Vehicle, timetable_start, SLE_INT32, 129, SL_MAX_VERSION),
SLE_CONDVAR_X(Vehicle, timetable_start_subticks, SLE_UINT16, 0, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_TIMETABLES_START_TICKS, 2)), SLE_CONDVAR_X(Vehicle, timetable_start_subticks, SLE_UINT16, 0, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_TIMETABLES_START_TICKS, 2)),

View File

@@ -36,7 +36,7 @@
* @param timetabled If the new value is explicitly timetabled. * @param timetabled If the new value is explicitly timetabled.
* @param ignore_lock If the change should be applied even if the value is locked. * @param ignore_lock If the change should be applied even if the value is locked.
*/ */
static void ChangeTimetable(Vehicle *v, VehicleOrderID order_number, uint16 val, ModifyTimetableFlags mtf, bool timetabled, bool ignore_lock = false) static void ChangeTimetable(Vehicle *v, VehicleOrderID order_number, uint32 val, ModifyTimetableFlags mtf, bool timetabled, bool ignore_lock = false)
{ {
Order *order = v->GetOrder(order_number); Order *order = v->GetOrder(order_number);
int total_delta = 0; int total_delta = 0;
@@ -133,7 +133,7 @@ static void ChangeTimetable(Vehicle *v, VehicleOrderID order_number, uint16 val,
* - p1 = (bit 28-30) - Timetable data to change (@see ModifyTimetableFlags) * - p1 = (bit 28-30) - Timetable data to change (@see ModifyTimetableFlags)
* - p1 = (bit 31) - 0 to set timetable wait/travel time, 1 to clear it * - p1 = (bit 31) - 0 to set timetable wait/travel time, 1 to clear it
* @param p2 The amount of time to wait. * @param p2 The amount of time to wait.
* - p2 = (bit 0-15) - The data to modify as specified by p1 bits 28-29. * - p2 = - The data to modify as specified by p1 bits 28-30.
* 0 to clear times, UINT16_MAX to clear speed limit. * 0 to clear times, UINT16_MAX to clear speed limit.
* @param text unused * @param text unused
* @return the cost of this operation or an error * @return the cost of this operation or an error
@@ -157,20 +157,20 @@ CommandCost CmdChangeTimetable(TileIndex tile, DoCommandFlag flags, uint32 p1, u
bool clear_field = GB(p1, 31, 1) == 1; bool clear_field = GB(p1, 31, 1) == 1;
int wait_time = order->GetWaitTime(); TimetableTicks wait_time = order->GetWaitTime();
int travel_time = order->GetTravelTime(); TimetableTicks travel_time = order->GetTravelTime();
int max_speed = order->GetMaxSpeed(); int max_speed = order->GetMaxSpeed();
bool wait_fixed = order->IsWaitFixed(); bool wait_fixed = order->IsWaitFixed();
bool travel_fixed = order->IsTravelFixed(); bool travel_fixed = order->IsTravelFixed();
OrderLeaveType leave_type = order->GetLeaveType(); OrderLeaveType leave_type = order->GetLeaveType();
switch (mtf) { switch (mtf) {
case MTF_WAIT_TIME: case MTF_WAIT_TIME:
wait_time = GB(p2, 0, 16); wait_time = p2;
if (clear_field) assert(wait_time == 0); if (clear_field) assert(wait_time == 0);
break; break;
case MTF_TRAVEL_TIME: case MTF_TRAVEL_TIME:
travel_time = GB(p2, 0, 16); travel_time = p2;
if (clear_field) assert(travel_time == 0); if (clear_field) assert(travel_time == 0);
break; break;
@@ -180,15 +180,15 @@ CommandCost CmdChangeTimetable(TileIndex tile, DoCommandFlag flags, uint32 p1, u
break; break;
case MTF_SET_WAIT_FIXED: case MTF_SET_WAIT_FIXED:
wait_fixed = GB(p2, 0, 16) != 0; wait_fixed = p2 != 0;
break; break;
case MTF_SET_TRAVEL_FIXED: case MTF_SET_TRAVEL_FIXED:
travel_fixed = GB(p2, 0, 16) != 0; travel_fixed = p2 != 0;
break; break;
case MTF_SET_LEAVE_TYPE: case MTF_SET_LEAVE_TYPE:
leave_type = (OrderLeaveType)GB(p2, 0, 16); leave_type = (OrderLeaveType)p2;
if (leave_type >= OLT_END) return CMD_ERROR; if (leave_type >= OLT_END) return CMD_ERROR;
break; break;

View File

@@ -917,14 +917,15 @@ struct TimetableWindow : Window {
uint32 p1 = PackTimetableArgs(v, this->sel_index, this->query_is_speed_query); uint32 p1 = PackTimetableArgs(v, this->sel_index, this->query_is_speed_query);
uint64 val = StrEmpty(str) ? 0 : strtoul(str, NULL, 10); uint64 val = StrEmpty(str) ? 0 : strtoul(str, NULL, 10);
uint32 p2;
if (this->query_is_speed_query) { if (this->query_is_speed_query) {
val = ConvertDisplaySpeedToKmhishSpeed(val); val = ConvertDisplaySpeedToKmhishSpeed(val);
p2 = minu(val, UINT16_MAX);
} else { } else {
if (!_settings_client.gui.timetable_in_ticks) val *= DATE_UNIT_SIZE; if (!_settings_client.gui.timetable_in_ticks) val *= DATE_UNIT_SIZE;
p2 = val;
} }
uint32 p2 = minu(val, UINT16_MAX);
DoCommandP(0, p1, p2, (this->change_timetable_all ? CMD_BULK_CHANGE_TIMETABLE : CMD_CHANGE_TIMETABLE) | CMD_MSG(STR_ERROR_CAN_T_TIMETABLE_VEHICLE)); DoCommandP(0, p1, p2, (this->change_timetable_all ? CMD_BULK_CHANGE_TIMETABLE : CMD_CHANGE_TIMETABLE) | CMD_MSG(STR_ERROR_CAN_T_TIMETABLE_VEHICLE));
break; break;
} }

View File

@@ -2951,7 +2951,7 @@ void Vehicle::HandleLoading(bool mode)
{ {
switch (this->current_order.GetType()) { switch (this->current_order.GetType()) {
case OT_LOADING: { case OT_LOADING: {
uint wait_time = max(this->current_order.GetTimetabledWait() - this->lateness_counter, 0); TimetableTicks wait_time = max<int>(this->current_order.GetTimetabledWait() - this->lateness_counter, 0);
/* Save time just loading took since that is what goes into the timetable */ /* Save time just loading took since that is what goes into the timetable */
if (!HasBit(this->vehicle_flags, VF_LOADING_FINISHED)) { if (!HasBit(this->vehicle_flags, VF_LOADING_FINISHED)) {
@@ -2998,7 +2998,7 @@ void Vehicle::HandleWaiting(bool stop_waiting)
{ {
switch (this->current_order.GetType()) { switch (this->current_order.GetType()) {
case OT_WAITING: { case OT_WAITING: {
uint wait_time = max(this->current_order.GetTimetabledWait() - this->lateness_counter, 0); uint wait_time = max<int>(this->current_order.GetTimetabledWait() - this->lateness_counter, 0);
/* Vehicles holds on until waiting Timetabled time expires. */ /* Vehicles holds on until waiting Timetabled time expires. */
if (!stop_waiting && this->current_order_time < wait_time && this->current_order.GetLeaveType() != OLT_LEAVE_EARLY) { if (!stop_waiting && this->current_order_time < wait_time && this->current_order.GetLeaveType() != OLT_LEAVE_EARLY) {
return; return;