Changeset - r24020:a5211d49b99f
[Not reviewed]
master
0 4 0
Charles Pigott - 5 years ago 2020-01-03 14:11:33
charlespigott@googlemail.com
Fix: When loading old timetabled saves, also reset cached timetable duration
4 files changed with 26 insertions and 6 deletions:
0 comments (0 inline, 0 general)
src/order_base.h
Show inline comments
 
@@ -278,12 +278,14 @@ public:
 

	
 
	/** Destructor. Invalidates OrderList for re-usage by the pool. */
 
	~OrderList() {}
 

	
 
	void Initialize(Order *chain, Vehicle *v);
 

	
 
	void RecalculateTimetableDuration();
 

	
 
	/**
 
	 * Get the first order of the order chain.
 
	 * @return the first order of the chain.
 
	 */
 
	inline Order *GetFirstOrder() const { return this->first; }
 

	
src/order_cmd.cpp
Show inline comments
 
@@ -293,30 +293,42 @@ void OrderList::Initialize(Order *chain,
 
	this->first_shared = v;
 

	
 
	this->num_orders = 0;
 
	this->num_manual_orders = 0;
 
	this->num_vehicles = 1;
 
	this->timetable_duration = 0;
 
	this->total_duration = 0;
 

	
 
	for (Order *o = this->first; o != nullptr; o = o->next) {
 
		++this->num_orders;
 
		if (!o->IsType(OT_IMPLICIT)) ++this->num_manual_orders;
 
		this->timetable_duration += o->GetTimetabledWait() + o->GetTimetabledTravel();
 
		this->total_duration += o->GetWaitTime() + o->GetTravelTime();
 
	}
 

	
 
	this->RecalculateTimetableDuration();
 

	
 
	for (Vehicle *u = this->first_shared->PreviousShared(); u != nullptr; u = u->PreviousShared()) {
 
		++this->num_vehicles;
 
		this->first_shared = u;
 
	}
 

	
 
	for (const Vehicle *u = v->NextShared(); u != nullptr; u = u->NextShared()) ++this->num_vehicles;
 
}
 

	
 
/**
 
 * Recomputes Timetable duration.
 
 * Split out into a separate function so it can be used by afterload.
 
 */
 
void OrderList::RecalculateTimetableDuration()
 
{
 
	this->timetable_duration = 0;
 
	for (Order *o = this->first; o != nullptr; o = o->next) {
 
		this->timetable_duration += o->GetTimetabledWait() + o->GetTimetabledTravel();
 
	}
 
}
 

	
 
/**
 
 * Free a complete order chain.
 
 * @param keep_orderlist If this is true only delete the orders, otherwise also delete the OrderList.
 
 * @note do not use on "current_order" vehicle orders!
 
 */
 
void OrderList::FreeChain(bool keep_orderlist)
 
{
src/saveload/afterload.cpp
Show inline comments
 
@@ -2960,12 +2960,22 @@ bool AfterLoadGame()
 
				}
 
				cur_skip--;
 
			}
 
		}
 
	}
 

	
 
	if (IsSavegameVersionBefore(SLV_190)) {
 
		for (Order *order : Order::Iterate()) {
 
			order->SetTravelTimetabled(order->GetTravelTime() > 0);
 
			order->SetWaitTimetabled(order->GetWaitTime() > 0);
 
		}
 
		for (OrderList *orderlist : OrderList::Iterate()) {
 
			orderlist->RecalculateTimetableDuration();
 
		}
 
	}
 

	
 
	/*
 
	 * Only keep order-backups for network clients (and when replaying).
 
	 * If we are a network server or not networking, then we just loaded a previously
 
	 * saved-by-server savegame. There are no clients with a backup, so clear it.
 
	 * Furthermore before savegame version SLV_192 the actual content was always corrupt.
 
	 */
src/saveload/order_sl.cpp
Show inline comments
 
@@ -179,16 +179,12 @@ static void Load_ORDR()
 
	} else {
 
		int index;
 

	
 
		while ((index = SlIterateArray()) != -1) {
 
			Order *order = new (index) Order();
 
			SlObject(order, GetOrderDescription());
 
			if (IsSavegameVersionBefore(SLV_190)) {
 
				order->SetTravelTimetabled(order->GetTravelTime() > 0);
 
				order->SetWaitTimetabled(order->GetWaitTime() > 0);
 
			}
 
		}
 
	}
 
}
 

	
 
static void Ptrs_ORDR()
 
{
0 comments (0 inline, 0 general)