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

pull/73/head
Jonathan G Rennison 6 years ago
parent ee00a28717
commit 0e3986c39c

@ -2029,7 +2029,7 @@ static void LoadUnloadVehicle(Vehicle *front)
/* 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. */
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)) {
SetBit(front->vehicle_flags, VF_STOP_LOADING);
}

@ -62,9 +62,9 @@ private:
std::unique_ptr<OrderExtraInfo> extra; ///< Extra order info
uint16 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.
uint16 max_speed; ///< How fast the vehicle may go on the way to the destination.
TimetableTicks wait_time; ///< How long in ticks to wait at the destination.
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.
void AllocExtraInfo();
void DeAllocExtraInfo();
@ -376,13 +376,13 @@ public:
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. */
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. */
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). */
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). */
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
@ -408,13 +408,13 @@ public:
* Set the time in ticks to wait at the destination.
* @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.
* @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

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

@ -81,7 +81,7 @@ const SlxiSubChunkInfo _sl_xv_sub_chunk_infos[] = {
{ 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_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_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 },

@ -112,8 +112,10 @@ const SaveLoad *GetOrderDescription()
SLE_CONDVAR(Order, refit_cargo, SLE_UINT8, 36, SL_MAX_VERSION),
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(Order, wait_time, SLE_UINT16, 67, SL_MAX_VERSION),
SLE_CONDVAR(Order, travel_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_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_X(Order, jump_counter, SLE_INT8, 0, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_MORE_COND_ORDERS)),

@ -665,8 +665,10 @@ const SaveLoad *GetVehicleDescription(VehicleType vt)
SLE_CONDNULL(1, 36, 181), // refit_subtype
/* Timetable in current order */
SLE_CONDVAR(Vehicle, current_order.wait_time, SLE_UINT16, 67, SL_MAX_VERSION),
SLE_CONDVAR(Vehicle, current_order.travel_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_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, 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)),

@ -36,7 +36,7 @@
* @param timetabled If the new value is explicitly timetabled.
* @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);
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 31) - 0 to set timetable wait/travel time, 1 to clear it
* @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.
* @param text unused
* @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;
int wait_time = order->GetWaitTime();
int travel_time = order->GetTravelTime();
TimetableTicks wait_time = order->GetWaitTime();
TimetableTicks travel_time = order->GetTravelTime();
int max_speed = order->GetMaxSpeed();
bool wait_fixed = order->IsWaitFixed();
bool travel_fixed = order->IsTravelFixed();
OrderLeaveType leave_type = order->GetLeaveType();
switch (mtf) {
case MTF_WAIT_TIME:
wait_time = GB(p2, 0, 16);
wait_time = p2;
if (clear_field) assert(wait_time == 0);
break;
case MTF_TRAVEL_TIME:
travel_time = GB(p2, 0, 16);
travel_time = p2;
if (clear_field) assert(travel_time == 0);
break;
@ -180,15 +180,15 @@ CommandCost CmdChangeTimetable(TileIndex tile, DoCommandFlag flags, uint32 p1, u
break;
case MTF_SET_WAIT_FIXED:
wait_fixed = GB(p2, 0, 16) != 0;
wait_fixed = p2 != 0;
break;
case MTF_SET_TRAVEL_FIXED:
travel_fixed = GB(p2, 0, 16) != 0;
travel_fixed = p2 != 0;
break;
case MTF_SET_LEAVE_TYPE:
leave_type = (OrderLeaveType)GB(p2, 0, 16);
leave_type = (OrderLeaveType)p2;
if (leave_type >= OLT_END) return CMD_ERROR;
break;

@ -917,14 +917,15 @@ struct TimetableWindow : Window {
uint32 p1 = PackTimetableArgs(v, this->sel_index, this->query_is_speed_query);
uint64 val = StrEmpty(str) ? 0 : strtoul(str, NULL, 10);
uint32 p2;
if (this->query_is_speed_query) {
val = ConvertDisplaySpeedToKmhishSpeed(val);
p2 = minu(val, UINT16_MAX);
} else {
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));
break;
}

@ -2951,7 +2951,7 @@ void Vehicle::HandleLoading(bool mode)
{
switch (this->current_order.GetType()) {
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 */
if (!HasBit(this->vehicle_flags, VF_LOADING_FINISHED)) {
@ -2998,7 +2998,7 @@ void Vehicle::HandleWaiting(bool stop_waiting)
{
switch (this->current_order.GetType()) {
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. */
if (!stop_waiting && this->current_order_time < wait_time && this->current_order.GetLeaveType() != OLT_LEAVE_EARLY) {
return;

Loading…
Cancel
Save