mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-16 00:12:51 +00:00
Merge branch 'auto_timetables-sx' into jgrpp
This commit is contained in:
commit
365f1c237f
@ -96,6 +96,7 @@ static void ChangeTimetable(Vehicle *v, VehicleOrderID order_number, uint16 val,
|
||||
* - p1 = (bit 0-19) - Vehicle with the orders to change.
|
||||
* - p1 = (bit 20-27) - Order index to modify.
|
||||
* - p1 = (bit 28-29) - Timetable data to change (@see ModifyTimetableFlags)
|
||||
* - p1 = (bit 30) - 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.
|
||||
* 0 to clear times, UINT16_MAX to clear speed limit.
|
||||
@ -119,16 +120,20 @@ CommandCost CmdChangeTimetable(TileIndex tile, DoCommandFlag flags, uint32 p1, u
|
||||
ModifyTimetableFlags mtf = Extract<ModifyTimetableFlags, 28, 2>(p1);
|
||||
if (mtf >= MTF_END) return CMD_ERROR;
|
||||
|
||||
bool clear_field = GB(p1, 30, 1) == 1;
|
||||
|
||||
int wait_time = order->GetWaitTime();
|
||||
int travel_time = order->GetTravelTime();
|
||||
int max_speed = order->GetMaxSpeed();
|
||||
switch (mtf) {
|
||||
case MTF_WAIT_TIME:
|
||||
wait_time = GB(p2, 0, 16);
|
||||
if (clear_field) assert(wait_time == 0);
|
||||
break;
|
||||
|
||||
case MTF_TRAVEL_TIME:
|
||||
travel_time = GB(p2, 0, 16);
|
||||
if (clear_field) assert(travel_time == 0);
|
||||
break;
|
||||
|
||||
case MTF_TRAVEL_SPEED:
|
||||
@ -163,15 +168,15 @@ CommandCost CmdChangeTimetable(TileIndex tile, DoCommandFlag flags, uint32 p1, u
|
||||
switch (mtf) {
|
||||
case MTF_WAIT_TIME:
|
||||
/* Set time if changing the value or confirming an estimated time as timetabled. */
|
||||
if (wait_time != order->GetWaitTime() || (wait_time > 0 && !order->IsWaitTimetabled())) {
|
||||
ChangeTimetable(v, order_number, wait_time, MTF_WAIT_TIME, wait_time > 0);
|
||||
if (wait_time != order->GetWaitTime() || (clear_field == order->IsWaitTimetabled())) {
|
||||
ChangeTimetable(v, order_number, wait_time, MTF_WAIT_TIME, !clear_field);
|
||||
}
|
||||
break;
|
||||
|
||||
case MTF_TRAVEL_TIME:
|
||||
/* Set time if changing the value or confirming an estimated time as timetabled. */
|
||||
if (travel_time != order->GetTravelTime() || (travel_time > 0 && !order->IsTravelTimetabled())) {
|
||||
ChangeTimetable(v, order_number, travel_time, MTF_TRAVEL_TIME, travel_time > 0);
|
||||
if (travel_time != order->GetTravelTime() || (clear_field == order->IsTravelTimetabled())) {
|
||||
ChangeTimetable(v, order_number, travel_time, MTF_TRAVEL_TIME, !clear_field);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -445,6 +450,27 @@ CommandCost CmdAutomateTimetable(TileIndex index, DoCommandFlag flags, uint32 p1
|
||||
return CommandCost();
|
||||
}
|
||||
|
||||
static inline bool IsOrderUsableForSeparation(const Order *order)
|
||||
{
|
||||
if (order->IsType(OT_CONDITIONAL)) {
|
||||
// Auto separation is unlikely to useful work at all if one of these is present, so give up
|
||||
return false;
|
||||
}
|
||||
|
||||
if (order->GetWaitTime() == 0 && order->IsType(OT_GOTO_STATION)) {
|
||||
// non-station orders are permitted to have 0 wait times
|
||||
return false;
|
||||
}
|
||||
|
||||
if (order->GetTravelTime() == 0 && !order->IsTravelTimetabled()) {
|
||||
// 0 travel times are permitted, if explicitly timetabled
|
||||
// this is useful for depot service orders
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int TimeToFinishOrder(Vehicle *v, int n)
|
||||
{
|
||||
int left;
|
||||
@ -452,8 +478,8 @@ int TimeToFinishOrder(Vehicle *v, int n)
|
||||
int wait_time = order->GetWaitTime();
|
||||
int travel_time = order->GetTravelTime();
|
||||
assert(order != NULL);
|
||||
if (!IsOrderUsableForSeparation(order)) return -1;
|
||||
if ((v->cur_real_order_index == n) && (v->last_station_visited == order->GetDestination())) {
|
||||
if (wait_time == 0) return -1;
|
||||
if (v->current_loading_time > 0) {
|
||||
left = wait_time - v->current_order_time;
|
||||
} else {
|
||||
@ -463,7 +489,6 @@ int TimeToFinishOrder(Vehicle *v, int n)
|
||||
} else {
|
||||
left = travel_time;
|
||||
if (v->cur_real_order_index == n) left -= v->current_order_time;
|
||||
if (travel_time == 0 || wait_time == 0) return -1;
|
||||
if (left < 0) left = 0;
|
||||
left +=wait_time;
|
||||
}
|
||||
@ -490,10 +515,8 @@ int SeparationBetween(Vehicle *v1, Vehicle *v2)
|
||||
if (time < 0) {
|
||||
for (n = 0; n < v1->GetNumOrders(); n++) {
|
||||
Order *order = v1->GetOrder(n);
|
||||
int wait_time = order->GetWaitTime();
|
||||
int travel_time = order->GetTravelTime();
|
||||
if (travel_time == 0 || wait_time == 0) return -1;
|
||||
time += travel_time + wait_time;
|
||||
if (!IsOrderUsableForSeparation(order)) return -1;
|
||||
time += order->GetTravelTime() + order->GetWaitTime();
|
||||
}
|
||||
}
|
||||
separation += time;
|
||||
|
@ -534,14 +534,14 @@ struct TimetableWindow : Window {
|
||||
}
|
||||
}
|
||||
|
||||
static inline uint32 PackTimetableArgs(const Vehicle *v, uint selected, bool speed)
|
||||
static inline uint32 PackTimetableArgs(const Vehicle *v, uint selected, bool speed, bool clear = false)
|
||||
{
|
||||
uint order_number = (selected + 1) / 2;
|
||||
ModifyTimetableFlags mtf = (selected % 2 == 1) ? (speed ? MTF_TRAVEL_SPEED : MTF_TRAVEL_TIME) : MTF_WAIT_TIME;
|
||||
|
||||
if (order_number >= v->GetNumOrders()) order_number = 0;
|
||||
|
||||
return v->index | (order_number << 20) | (mtf << 28);
|
||||
return v->index | (order_number << 20) | (mtf << 28) | (clear ? 1 << 30 : 0);
|
||||
}
|
||||
|
||||
virtual void OnClick(Point pt, int widget, int click_count)
|
||||
@ -623,7 +623,7 @@ struct TimetableWindow : Window {
|
||||
}
|
||||
|
||||
case WID_VT_CLEAR_TIME: { // Clear waiting time.
|
||||
uint32 p1 = PackTimetableArgs(v, this->sel_index, false);
|
||||
uint32 p1 = PackTimetableArgs(v, this->sel_index, false, true);
|
||||
DoCommandP(0, p1, 0, CMD_CHANGE_TIMETABLE | CMD_MSG(STR_ERROR_CAN_T_TIMETABLE_VEHICLE));
|
||||
break;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user