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; }
|
inline const std::vector<uint32> &GetScheduledDispatch() const { return this->scheduled_dispatch; }
|
||||||
|
|
||||||
|
void SetScheduledDispatch(std::vector<uint32> dispatch_list);
|
||||||
void AddScheduledDispatch(uint32 offset);
|
void AddScheduledDispatch(uint32 offset);
|
||||||
void RemoveScheduledDispatch(uint32 offset);
|
void RemoveScheduledDispatch(uint32 offset);
|
||||||
void UpdateScheduledDispatch();
|
void UpdateScheduledDispatch();
|
||||||
@@ -758,6 +759,18 @@ public:
|
|||||||
this->scheduled_dispatch_start_full_date_fract = start_full_date_fract;
|
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
|
* Get the scheduled dispatch start date, in absolute scaled tick
|
||||||
* @return scheduled dispatch start date
|
* @return scheduled dispatch start date
|
||||||
|
@@ -2133,17 +2133,10 @@ CommandCost CmdCloneOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
|
|||||||
if (src->orders.list != nullptr) {
|
if (src->orders.list != nullptr) {
|
||||||
dst->orders.list->SetScheduledDispatchDuration(src->orders.list->GetScheduledDispatchDuration());
|
dst->orders.list->SetScheduledDispatchDuration(src->orders.list->GetScheduledDispatchDuration());
|
||||||
dst->orders.list->SetScheduledDispatchDelay(src->orders.list->GetScheduledDispatchDelay());
|
dst->orders.list->SetScheduledDispatchDelay(src->orders.list->GetScheduledDispatchDelay());
|
||||||
for (const auto& slot : src->orders.list->GetScheduledDispatch()) {
|
dst->orders.list->SetScheduledDispatchStartDate(src->orders.list->GetScheduledDispatchStartDatePart(),
|
||||||
dst->orders.list->AddScheduledDispatch(slot);
|
src->orders.list->GetScheduledDispatchStartDateFractPart());
|
||||||
}
|
dst->orders.list->SetScheduledDispatchLastDispatch(0);
|
||||||
|
dst->orders.list->SetScheduledDispatch(src->orders.list->GetScheduledDispatch());
|
||||||
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) */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set automation bit if target has it. */
|
/* Set automation bit if target has it. */
|
||||||
|
@@ -266,6 +266,17 @@ CommandCost CmdScheduledDispatchResetLastDispatch(TileIndex tile, DoCommandFlag
|
|||||||
return CommandCost();
|
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.
|
* Add new scheduled dispatch slot at offsets time.
|
||||||
* @param offset The offset time to add.
|
* @param offset The offset time to add.
|
||||||
@@ -329,7 +340,7 @@ void OrderList::UpdateScheduledDispatch()
|
|||||||
void OrderList::ResetScheduledDispatch()
|
void OrderList::ResetScheduledDispatch()
|
||||||
{
|
{
|
||||||
uint32 windex = this->first_shared->index;
|
uint32 windex = this->first_shared->index;
|
||||||
|
|
||||||
Date start_date;
|
Date start_date;
|
||||||
uint16 start_full_date_fract;
|
uint16 start_full_date_fract;
|
||||||
uint32 duration;
|
uint32 duration;
|
||||||
@@ -350,7 +361,7 @@ void OrderList::ResetScheduledDispatch()
|
|||||||
start_full_date_fract = 0;
|
start_full_date_fract = 0;
|
||||||
duration = 365*DAY_TICKS;
|
duration = 365*DAY_TICKS;
|
||||||
}
|
}
|
||||||
|
|
||||||
DoCommandP(0, windex, duration, CMD_SCHEDULED_DISPATCH_SET_DURATION | CMD_MSG(STR_ERROR_CAN_T_TIMETABLE_VEHICLE));
|
DoCommandP(0, windex, duration, CMD_SCHEDULED_DISPATCH_SET_DURATION | CMD_MSG(STR_ERROR_CAN_T_TIMETABLE_VEHICLE));
|
||||||
|
|
||||||
uint32 p1 = 0, p2 = 0;
|
uint32 p1 = 0, p2 = 0;
|
||||||
|
Reference in New Issue
Block a user