Changeset - r13287:52547c48c3ba
[Not reviewed]
master
0 3 0
rubidium - 15 years ago 2009-10-18 17:47:38
rubidium@openttd.org
(svn r17806) -Codechange: split CargoPacket's 'afterload' to a separate function
3 files changed with 53 insertions and 45 deletions:
0 comments (0 inline, 0 general)
src/cargopacket.h
Show inline comments
 
@@ -117,6 +117,7 @@ public:
 

	
 
	static void InvalidateAllFrom(SourceType src_type, SourceID src);
 
	static void InvalidateAllFrom(StationID sid);
 
	static void AfterLoad();
 
};
 

	
 
/**
src/saveload/afterload.cpp
Show inline comments
 
@@ -1226,43 +1226,7 @@ bool AfterLoadGame()
 
		}
 
	}
 

	
 
	if (CheckSavegameVersion(44)) {
 
		Vehicle *v;
 
		/* If we remove a station while cargo from it is still enroute, payment calculation will assume
 
		 * 0, 0 to be the source of the cargo, resulting in very high payments usually. v->source_xy
 
		 * stores the coordinates, preserving them even if the station is removed. However, if a game is loaded
 
		 * where this situation exists, the cargo-source information is lost. in this case, we set the source
 
		 * to the current tile of the vehicle to prevent excessive profits
 
		 */
 
		FOR_ALL_VEHICLES(v) {
 
			const VehicleCargoList::List *packets = v->cargo.Packets();
 
			for (VehicleCargoList::List::const_iterator it = packets->begin(); it != packets->end(); it++) {
 
				CargoPacket *cp = *it;
 
				cp->source_xy = Station::IsValidID(cp->source) ? Station::Get(cp->source)->xy : v->tile;
 
				cp->loaded_at_xy = cp->source_xy;
 
			}
 
			v->cargo.InvalidateCache();
 
		}
 

	
 
		/* Store position of the station where the goods come from, so there
 
		 * are no very high payments when stations get removed. However, if the
 
		 * station where the goods came from is already removed, the source
 
		 * information is lost. In that case we set it to the position of this
 
		 * station */
 
		Station *st;
 
		FOR_ALL_STATIONS(st) {
 
			for (CargoID c = 0; c < NUM_CARGO; c++) {
 
				GoodsEntry *ge = &st->goods[c];
 

	
 
				const StationCargoList::List *packets = ge->cargo.Packets();
 
				for (StationCargoList::List::const_iterator it = packets->begin(); it != packets->end(); it++) {
 
					CargoPacket *cp = *it;
 
					cp->source_xy = Station::IsValidID(cp->source) ? Station::Get(cp->source)->xy : st->xy;
 
					cp->loaded_at_xy = cp->source_xy;
 
				}
 
			}
 
		}
 
	}
 
	CargoPacket::AfterLoad();
 

	
 
	if (CheckSavegameVersion(45)) {
 
		Vehicle *v;
 
@@ -1277,14 +1241,6 @@ bool AfterLoadGame()
 
		}
 
	}
 

	
 
	if (CheckSavegameVersion(120)) {
 
		/* CargoPacket's source should be either INVALID_STATION or a valid station */
 
		CargoPacket *cp;
 
		FOR_ALL_CARGOPACKETS(cp) {
 
			if (!Station::IsValidID(cp->source)) cp->source = INVALID_STATION;
 
		}
 
	}
 

	
 
	/* Buoys do now store the owner of the previous water tile, which can never
 
	 * be OWNER_NONE. So replace OWNER_NONE with OWNER_WATER. */
 
	if (CheckSavegameVersion(46)) {
src/saveload/cargopacket_sl.cpp
Show inline comments
 
@@ -11,9 +11,60 @@
 

	
 
#include "../stdafx.h"
 
#include "../cargopacket.h"
 
#include "../vehicle_base.h"
 
#include "../station_base.h"
 

	
 
#include "saveload.h"
 

	
 
/* static */ void CargoPacket::AfterLoad()
 
{
 
	if (CheckSavegameVersion(44)) {
 
		Vehicle *v;
 
		/* If we remove a station while cargo from it is still enroute, payment calculation will assume
 
			* 0, 0 to be the source of the cargo, resulting in very high payments usually. v->source_xy
 
			* stores the coordinates, preserving them even if the station is removed. However, if a game is loaded
 
			* where this situation exists, the cargo-source information is lost. in this case, we set the source
 
			* to the current tile of the vehicle to prevent excessive profits
 
			*/
 
		FOR_ALL_VEHICLES(v) {
 
			const VehicleCargoList::List *packets = v->cargo.Packets();
 
			for (VehicleCargoList::List::const_iterator it = packets->begin(); it != packets->end(); it++) {
 
				CargoPacket *cp = *it;
 
				cp->source_xy = Station::IsValidID(cp->source) ? Station::Get(cp->source)->xy : v->tile;
 
				cp->loaded_at_xy = cp->source_xy;
 
			}
 
			v->cargo.InvalidateCache();
 
		}
 

	
 
		/* Store position of the station where the goods come from, so there
 
			* are no very high payments when stations get removed. However, if the
 
			* station where the goods came from is already removed, the source
 
			* information is lost. In that case we set it to the position of this
 
			* station */
 
		Station *st;
 
		FOR_ALL_STATIONS(st) {
 
			for (CargoID c = 0; c < NUM_CARGO; c++) {
 
				GoodsEntry *ge = &st->goods[c];
 

	
 
				const StationCargoList::List *packets = ge->cargo.Packets();
 
				for (StationCargoList::List::const_iterator it = packets->begin(); it != packets->end(); it++) {
 
					CargoPacket *cp = *it;
 
					cp->source_xy = Station::IsValidID(cp->source) ? Station::Get(cp->source)->xy : st->xy;
 
					cp->loaded_at_xy = cp->source_xy;
 
				}
 
			}
 
		}
 
	}
 

	
 
	if (CheckSavegameVersion(120)) {
 
		/* CargoPacket's source should be either INVALID_STATION or a valid station */
 
		CargoPacket *cp;
 
		FOR_ALL_CARGOPACKETS(cp) {
 
			if (!Station::IsValidID(cp->source)) cp->source = INVALID_STATION;
 
		}
 
	}
 
}
 

	
 
/**
 
 * Wrapper function to get the CargoPacket's internal structure while
 
 * some of the variables itself are private.
0 comments (0 inline, 0 general)