Scheduled dispatch: Simplify schedule copying
This commit is contained in:
@@ -730,6 +730,7 @@ public:
|
||||
*/
|
||||
inline const std::vector<uint32> &GetScheduledDispatch() const { return this->scheduled_dispatch; }
|
||||
|
||||
void SetScheduledDispatch(std::vector<uint32> dispatch_list);
|
||||
void AddScheduledDispatch(uint32 offset);
|
||||
void RemoveScheduledDispatch(uint32 offset);
|
||||
void UpdateScheduledDispatch();
|
||||
@@ -758,6 +759,18 @@ public:
|
||||
this->scheduled_dispatch_start_full_date_fract = start_full_date_fract;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the scheduled dispatch start date part
|
||||
* @return scheduled dispatch start date part
|
||||
*/
|
||||
inline Date GetScheduledDispatchStartDatePart() const { return this->scheduled_dispatch_start_date; }
|
||||
|
||||
/**
|
||||
* Get the scheduled dispatch start date fract part
|
||||
* @return scheduled dispatch start date fract part
|
||||
*/
|
||||
inline uint16 GetScheduledDispatchStartDateFractPart() const { return this->scheduled_dispatch_start_full_date_fract; }
|
||||
|
||||
/**
|
||||
* Get the scheduled dispatch start date, in absolute scaled tick
|
||||
* @return scheduled dispatch start date
|
||||
|
@@ -2133,17 +2133,10 @@ CommandCost CmdCloneOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
|
||||
if (src->orders.list != nullptr) {
|
||||
dst->orders.list->SetScheduledDispatchDuration(src->orders.list->GetScheduledDispatchDuration());
|
||||
dst->orders.list->SetScheduledDispatchDelay(src->orders.list->GetScheduledDispatchDelay());
|
||||
for (const auto& slot : src->orders.list->GetScheduledDispatch()) {
|
||||
dst->orders.list->AddScheduledDispatch(slot);
|
||||
}
|
||||
|
||||
Date start_date;
|
||||
uint16 start_full_date_fract;
|
||||
SchdispatchConvertToFullDateFract(
|
||||
src->orders.list->GetScheduledDispatchStartTick(),
|
||||
&start_date, &start_full_date_fract);
|
||||
dst->orders.list->SetScheduledDispatchStartDate(start_date, start_full_date_fract);
|
||||
/* Don't copy last dispatch, leave it at 0 (default) */
|
||||
dst->orders.list->SetScheduledDispatchStartDate(src->orders.list->GetScheduledDispatchStartDatePart(),
|
||||
src->orders.list->GetScheduledDispatchStartDateFractPart());
|
||||
dst->orders.list->SetScheduledDispatchLastDispatch(0);
|
||||
dst->orders.list->SetScheduledDispatch(src->orders.list->GetScheduledDispatch());
|
||||
}
|
||||
|
||||
/* Set automation bit if target has it. */
|
||||
|
@@ -266,6 +266,17 @@ CommandCost CmdScheduledDispatchResetLastDispatch(TileIndex tile, DoCommandFlag
|
||||
return CommandCost();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set scheduled dispatch slot list.
|
||||
* @param dispatch_list The offset time list, must be correctly sorted.
|
||||
*/
|
||||
void OrderList::SetScheduledDispatch(std::vector<uint32> dispatch_list)
|
||||
{
|
||||
this->scheduled_dispatch = std::move(dispatch_list);
|
||||
assert(std::is_sorted(this->scheduled_dispatch.begin(), this->scheduled_dispatch.end()));
|
||||
this->UpdateScheduledDispatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add new scheduled dispatch slot at offsets time.
|
||||
* @param offset The offset time to add.
|
||||
@@ -329,7 +340,7 @@ void OrderList::UpdateScheduledDispatch()
|
||||
void OrderList::ResetScheduledDispatch()
|
||||
{
|
||||
uint32 windex = this->first_shared->index;
|
||||
|
||||
|
||||
Date start_date;
|
||||
uint16 start_full_date_fract;
|
||||
uint32 duration;
|
||||
@@ -350,7 +361,7 @@ void OrderList::ResetScheduledDispatch()
|
||||
start_full_date_fract = 0;
|
||||
duration = 365*DAY_TICKS;
|
||||
}
|
||||
|
||||
|
||||
DoCommandP(0, windex, duration, CMD_SCHEDULED_DISPATCH_SET_DURATION | CMD_MSG(STR_ERROR_CAN_T_TIMETABLE_VEHICLE));
|
||||
|
||||
uint32 p1 = 0, p2 = 0;
|
||||
|
Reference in New Issue
Block a user