Timetable: Implement autofill/automate for taken conditional orders.

Fix wrong timetable values being set after using skip or send to depot.
Add timetabled flag for conditional order branch taken travel time.
This commit is contained in:
Jonathan G Rennison
2017-12-18 01:26:27 +00:00
parent 102c55bc57
commit 218085c535
16 changed files with 187 additions and 34 deletions

View File

@@ -32,6 +32,7 @@ extern OrderListPool _orderlist_pool;
struct OrderExtraInfo {
uint8 cargo_type_flags[NUM_CARGO] = {}; ///< Load/unload types for each cargo type.
uint8 xflags = 0; ///< Extra flags
};
/* If you change this, keep in mind that it is saved on 3 places:
@@ -72,6 +73,17 @@ private:
if (!this->extra) this->AllocExtraInfo();
}
inline uint8 GetXFlags() const
{
return this->extra != nullptr ? this->extra->xflags : 0;
}
inline uint8 &GetXFlagsRef()
{
CheckExtraInfoAlloced();
return this->extra->xflags;
}
public:
Order *next; ///< Pointer to next order. If NULL, end of list
@@ -340,7 +352,7 @@ public:
* explicitly set (but travel_time is actually unused for conditionals). */
/** Does this order have an explicit wait time set? */
inline bool IsWaitTimetabled() const { return this->IsType(OT_CONDITIONAL) ? this->wait_time > 0 : HasBit(this->flags, 3); }
inline bool IsWaitTimetabled() const { return this->IsType(OT_CONDITIONAL) ? HasBit(this->GetXFlags(), 0) : HasBit(this->flags, 3); }
/** Does this order have an explicit travel time set? */
inline bool IsTravelTimetabled() const { return this->IsType(OT_CONDITIONAL) ? this->travel_time > 0 : HasBit(this->flags, 7); }
@@ -361,7 +373,15 @@ public:
inline uint16 GetMaxSpeed() const { return this->max_speed; }
/** Set if the wait time is explicitly timetabled (unless the order is conditional). */
inline void SetWaitTimetabled(bool timetabled) { if (!this->IsType(OT_CONDITIONAL)) SB(this->flags, 3, 1, timetabled ? 1 : 0); }
inline void SetWaitTimetabled(bool timetabled)
{
if (this->IsType(OT_CONDITIONAL)) {
SB(this->GetXFlagsRef(), 0, 1, timetabled ? 1 : 0);
} else {
SB(this->flags, 3, 1, timetabled ? 1 : 0);
}
}
/** Set if the travel time is explicitly timetabled (unless the order is conditional). */
inline void SetTravelTimetabled(bool timetabled) { if (!this->IsType(OT_CONDITIONAL)) SB(this->flags, 7, 1, timetabled ? 1 : 0); }
@@ -494,7 +514,7 @@ private:
Ticks timetable_duration; ///< NOSAVE: Total timetabled duration of the order list.
Ticks total_duration; ///< NOSAVE: Total (timetabled or not) duration of the order list.
std::vector<uint32> scheduled_dispatch; ///< Scheduled dispatch time
uint32 scheduled_dispatch_duration; ///< Scheduled dispatch duration
Date scheduled_dispatch_start_date; ///< Scheduled dispatch start date
@@ -531,6 +551,8 @@ public:
Order *GetOrderAt(int index) const;
VehicleOrderID GetIndexOfOrder(const Order *order) const;
/**
* Get the last order of the order chain.
* @return the last order of the chain.
@@ -636,7 +658,7 @@ public:
* @return first scheduled dispatch
*/
inline const std::vector<uint32> &GetScheduledDispatch() { return this->scheduled_dispatch; }
void AddScheduledDispatch(uint32 offset);
void RemoveScheduledDispatch(uint32 offset);
void UpdateScheduledDispatch();