Changeset - r17772:ce3cc7016cdc
[Not reviewed]
projects/openttd_vs100.vcxproj
Show inline comments
 
@@ -737,12 +737,13 @@
 
    <ClCompile Include="..\src\saveload\saveload.cpp" />
 
    <ClInclude Include="..\src\saveload\saveload.h" />
 
    <ClInclude Include="..\src\saveload\saveload_filter.h" />
 
    <ClInclude Include="..\src\saveload\saveload_internal.h" />
 
    <ClCompile Include="..\src\saveload\signs_sl.cpp" />
 
    <ClCompile Include="..\src\saveload\station_sl.cpp" />
 
    <ClCompile Include="..\src\saveload\storage_sl.cpp" />
 
    <ClCompile Include="..\src\saveload\strings_sl.cpp" />
 
    <ClCompile Include="..\src\saveload\subsidy_sl.cpp" />
 
    <ClCompile Include="..\src\saveload\town_sl.cpp" />
 
    <ClCompile Include="..\src\saveload\vehicle_sl.cpp" />
 
    <ClCompile Include="..\src\saveload\waypoint_sl.cpp" />
 
    <ClInclude Include="..\src\table\airport_defaults.h" />
projects/openttd_vs100.vcxproj.filters
Show inline comments
 
@@ -1437,12 +1437,15 @@
 
    <ClCompile Include="..\src\saveload\signs_sl.cpp">
 
      <Filter>Save/Load handlers</Filter>
 
    </ClCompile>
 
    <ClCompile Include="..\src\saveload\station_sl.cpp">
 
      <Filter>Save/Load handlers</Filter>
 
    </ClCompile>
 
    <ClCompile Include="..\src\saveload\storage_sl.cpp">
 
      <Filter>Save/Load handlers</Filter>
 
    </ClCompile>
 
    <ClCompile Include="..\src\saveload\strings_sl.cpp">
 
      <Filter>Save/Load handlers</Filter>
 
    </ClCompile>
 
    <ClCompile Include="..\src\saveload\subsidy_sl.cpp">
 
      <Filter>Save/Load handlers</Filter>
 
    </ClCompile>
projects/openttd_vs80.vcproj
Show inline comments
 
@@ -2252,12 +2252,16 @@
 
			</File>
 
			<File
 
				RelativePath=".\..\src\saveload\station_sl.cpp"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\saveload\storage_sl.cpp"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\saveload\strings_sl.cpp"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\saveload\subsidy_sl.cpp"
 
				>
projects/openttd_vs90.vcproj
Show inline comments
 
@@ -2249,12 +2249,16 @@
 
			</File>
 
			<File
 
				RelativePath=".\..\src\saveload\station_sl.cpp"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\saveload\storage_sl.cpp"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\saveload\strings_sl.cpp"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\saveload\subsidy_sl.cpp"
 
				>
source.list
Show inline comments
 
@@ -495,12 +495,13 @@ saveload/order_sl.cpp
 
saveload/saveload.cpp
 
saveload/saveload.h
 
saveload/saveload_filter.h
 
saveload/saveload_internal.h
 
saveload/signs_sl.cpp
 
saveload/station_sl.cpp
 
saveload/storage_sl.cpp
 
saveload/strings_sl.cpp
 
saveload/subsidy_sl.cpp
 
saveload/town_sl.cpp
 
saveload/vehicle_sl.cpp
 
saveload/waypoint_sl.cpp
 

	
src/industry.h
Show inline comments
 
@@ -35,14 +35,12 @@ enum ProductionLevels {
 
};
 

	
 
/**
 
 * Defines the internal data of a functional industry.
 
 */
 
struct Industry : IndustryPool::PoolItem<&_industry_pool> {
 
	typedef PersistentStorageArray<int32, 16> PersistentStorage;
 

	
 
	TileArea location;                  ///< Location of the industry
 
	Town *town;                         ///< Nearest town
 
	CargoID produced_cargo[2];          ///< 2 production cargo slots
 
	uint16 produced_cargo_waiting[2];   ///< amount of cargo produced per cargo
 
	uint16 incoming_cargo_waiting[3];   ///< incoming cargo waiting to be processed
 
	byte production_rate[2];            ///< production rate for each cargo
 
@@ -69,13 +67,13 @@ struct Industry : IndustryPool::PoolItem
 
	Date last_cargo_accepted_at;        ///< Last day cargo was accepted by this industry
 
	byte selected_layout;               ///< Which tile layout was used when creating the industry
 

	
 
	byte random_triggers;               ///< Triggers for the random
 
	uint16 random;                      ///< Random value used for randomisation of all kinds of things
 

	
 
	PersistentStorage psa;              ///< Persistent storage for NewGRF industries.
 
	PersistentStorage *psa;             ///< Persistent storage for NewGRF industries.
 

	
 
	Industry(TileIndex tile = INVALID_TILE) : location(tile, 0, 0) {}
 
	~Industry();
 

	
 
	void RecomputeProductionMultipliers();
 

	
src/industry_cmd.cpp
Show inline comments
 
@@ -164,12 +164,15 @@ Industry::~Industry()
 
		}
 
	}
 

	
 
	/* don't let any disaster vehicle target invalid industry */
 
	ReleaseDisastersTargetingIndustry(this->index);
 

	
 
	/* Clear the persistent storage. */
 
	delete this->psa;
 

	
 
	DecIndustryTypeCount(this->type);
 

	
 
	DeleteIndustryNews(this->index);
 
	DeleteWindowById(WC_INDUSTRY_VIEW, this->index);
 
	DeleteNewGRFInspectWindow(GSF_INDUSTRIES, this->index);
 

	
src/newgrf_airport.cpp
Show inline comments
 
@@ -146,13 +146,13 @@ uint32 AirportGetVariable(const Resolver
 
		*available = false;
 
		return UINT_MAX;
 
	}
 

	
 
	switch (variable) {
 
		/* Get a variable from the persistent storage */
 
		case 0x7C: return st->airport.psa.GetValue(parameter);
 
		case 0x7C: return (st->airport.psa != NULL) ? st->airport.psa->GetValue(parameter) : 0;
 

	
 
		case 0xF0: return st->facilities;
 
		case 0xFA: return Clamp(st->build_date - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 65535);
 
	}
 

	
 
	return st->GetNewGRFVariable(object, variable, parameter, available);
 
@@ -191,13 +191,23 @@ static void AirportSetTriggers(const Res
 
 * @param value Value to store.
 
 */
 
void AirportStorePSA(ResolverObject *object, uint pos, int32 value)
 
{
 
	Station *st = object->u.airport.st;
 
	if (object->scope != VSG_SCOPE_SELF || st == NULL) return;
 
	st->airport.psa.StoreValue(pos, value);
 

	
 
	if (st->airport.psa == NULL) {
 
		/* There is no need to create a storage if the value is zero. */
 
		if (value == 0) return;
 

	
 
		/* Create storage on first modification. */
 
		uint32 grfid = (object->grffile != NULL) ? object->grffile->grfid : 0;
 
		assert(PersistentStorage::CanAllocateItem());
 
		st->airport.psa = new PersistentStorage(grfid);
 
	}
 
	st->airport.psa->StoreValue(pos, value);
 
}
 

	
 
static void NewAirportResolver(ResolverObject *res, TileIndex tile, Station *st, byte airport_id, byte layout)
 
{
 
	res->GetRandomBits = AirportGetRandomBits;
 
	res->GetTriggers   = AirportGetTriggers;
src/newgrf_debug_gui.cpp
Show inline comments
 
@@ -155,24 +155,24 @@ public:
 
		this->Resolve(&ro, index);
 
		return ro.GetVariable(&ro, var, param, avail);
 
	}
 

	
 
	/**
 
	 * Allows to know the size of the persistent storage.
 
	 * @param index Unused.
 
	 * @param index Index of the item.
 
	 * @param grfid Unused.
 
	 * @return Size of the persistent storage in indices.
 
	 */
 
	virtual uint GetPSASize(uint index, uint32 grfid) const
 
	{
 
		return 0;
 
	}
 

	
 
	/**
 
	 * Gets the first position of the array containing the persistent storage.
 
	 * @param index Unused.
 
	 * @param index Index of the item.
 
	 * @param grfid Unused.
 
	 * @return Pointer to the first position of the storage array or NULL if not present.
 
	 */
 
	virtual int32 *GetPSAFirstPosition(uint index, uint32 grfid) const
 
	{
 
		return NULL;
 
@@ -365,17 +365,17 @@ struct NewGRFInspectWindow : Window {
 
				} else {
 
					this->DrawString(r, i++, "  %02x: %08x (%s)", niv->var, value, niv->name);
 
				}
 
			}
 
		}
 

	
 
		uint psa_size = nih->GetPSASize(0, 0);
 
		if (psa_size != 0) {
 
		uint psa_size = nih->GetPSASize(index, 0);
 
		int32 *psa = nih->GetPSAFirstPosition(index, 0);
 
		if (psa_size != 0 && psa != NULL) {
 
			this->DrawString(r, i++, "Persistent storage:");
 
			assert(psa_size % 4 == 0);
 
			int32 *psa = nih->GetPSAFirstPosition(0, 0);
 
			for (uint j = 0; j < psa_size; j += 4, psa += 4) {
 
				this->DrawString(r, i++, "  %i: %i %i %i %i", j, psa[0], psa[1], psa[2], psa[3]);
 
			}
 
		}
 

	
 
		if (nif->properties != NULL) {
src/newgrf_industries.cpp
Show inline comments
 
@@ -280,13 +280,13 @@ uint32 IndustryGetVariable(const Resolve
 
				town_filter = HasBit(reg, 8);
 
			}
 
			return GetCountAndDistanceOfClosestInstance(parameter, layout_filter, town_filter, industry);
 
		}
 

	
 
		/* Get a variable from the persistent storage */
 
		case 0x7C: return industry->psa.GetValue(parameter);
 
		case 0x7C: return (industry->psa != NULL) ? industry->psa->GetValue(parameter) : 0;
 

	
 
		/* Industry structure access*/
 
		case 0x80: return industry->location.tile;
 
		case 0x81: return GB(industry->location.tile, 8, 8);
 
		/* Pointer to the town the industry is associated with */
 
		case 0x82: return industry->town->index;
 
@@ -383,13 +383,25 @@ static void IndustrySetTriggers(const Re
 
 * @param value Value to store.
 
 */
 
void IndustryStorePSA(ResolverObject *object, uint pos, int32 value)
 
{
 
	Industry *ind = object->u.industry.ind;
 
	if (object->scope != VSG_SCOPE_SELF || ind->index == INVALID_INDUSTRY) return;
 
	ind->psa.StoreValue(pos, value);
 

	
 
	if (ind->psa == NULL) {
 
		/* There is no need to create a storage if the value is zero. */
 
		if (value == 0) return;
 

	
 
		/* Create storage on first modification. */
 
		const IndustrySpec *indsp = GetIndustrySpec(ind->type);
 
		uint32 grfid = (indsp->grf_prop.grffile != NULL) ? indsp->grf_prop.grffile->grfid : 0;
 
		assert(PersistentStorage::CanAllocateItem());
 
		ind->psa = new PersistentStorage(grfid);
 
	}
 

	
 
	ind->psa->StoreValue(pos, value);
 
}
 

	
 
static void NewIndustryResolver(ResolverObject *res, TileIndex tile, Industry *indus, IndustryType type)
 
{
 
	res->GetRandomBits = IndustryGetRandomBits;
 
	res->GetTriggers   = IndustryGetTriggers;
src/newgrf_industrytiles.cpp
Show inline comments
 
@@ -155,13 +155,25 @@ static void IndustryTileSetTriggers(cons
 
 * @param value Value to store.
 
 */
 
void IndustryTileStorePSA(ResolverObject *object, uint pos, int32 value)
 
{
 
	Industry *ind = object->u.industry.ind;
 
	if (object->scope != VSG_SCOPE_PARENT || ind->index == INVALID_INDUSTRY) return;
 
	ind->psa.StoreValue(pos, value);
 

	
 
	if (ind->psa == NULL) {
 
		/* There is no need to create a storage if the value is zero. */
 
		if (value == 0) return;
 

	
 
		/* Create storage on first modification. */
 
		const IndustrySpec *indsp = GetIndustrySpec(ind->type);
 
		uint32 grfid = (indsp->grf_prop.grffile != NULL) ? indsp->grf_prop.grffile->grfid : 0;
 
		assert(PersistentStorage::CanAllocateItem());
 
		ind->psa = new PersistentStorage(grfid);
 
	}
 

	
 
	ind->psa->StoreValue(pos, value);
 
}
 

	
 
static void NewIndustryTileResolver(ResolverObject *res, IndustryGfx gfx, TileIndex tile, Industry *indus)
 
{
 
	res->GetRandomBits = IndustryTileGetRandomBits;
 
	res->GetTriggers   = IndustryTileGetTriggers;
src/newgrf_storage.cpp
Show inline comments
 
@@ -8,14 +8,18 @@
 
 */
 

	
 
/** @file newgrf_storage.cpp Functionality related to the temporary and persistent storage arrays for NewGRFs. */
 

	
 
#include "stdafx.h"
 
#include "newgrf_storage.h"
 
#include "core/pool_func.hpp"
 
#include <set>
 

	
 
PersistentStoragePool _persistent_storage_pool("PersistentStorage");
 
INSTANTIATE_POOL_METHODS(PersistentStorage)
 

	
 
/** The changed storage arrays */
 
static std::set<BaseStorageArray*> _changed_storage_arrays;
 

	
 
/**
 
 * Remove references to use.
 
 */
src/newgrf_storage.h
Show inline comments
 
@@ -10,12 +10,13 @@
 
/** @file newgrf_storage.h Functionality related to the temporary and persistent storage arrays for NewGRFs. */
 

	
 
#ifndef NEWGRF_STORAGE_H
 
#define NEWGRF_STORAGE_H
 

	
 
#include "core/alloc_func.hpp"
 
#include "core/pool_type.hpp"
 

	
 
/**
 
 * Base class for all NewGRF storage arrays. Nothing fancy, only here
 
 * so we have a generalised class to use.
 
 */
 
struct BaseStorageArray
 
@@ -175,7 +176,43 @@ struct TemporaryStorageArray : BaseStora
 
	}
 
};
 

	
 
void AddChangedStorage(BaseStorageArray *storage);
 
void ClearStorageChanges(bool keep_changes);
 

	
 

	
 
typedef PersistentStorageArray<int32, 16> OldPersistentStorage;
 

	
 
typedef uint32 PersistentStorageID;
 

	
 
struct PersistentStorage;
 
typedef Pool<PersistentStorage, PersistentStorageID, 1, 0xFF000> PersistentStoragePool;
 

	
 
extern PersistentStoragePool _persistent_storage_pool;
 

	
 
/**
 
 * Class for pooled persistent storage of data.
 
 * On ClearChanges that data is always zero-ed.
 
 */
 
struct PersistentStorage : PersistentStorageArray<int32, 16>, PersistentStoragePool::PoolItem<&_persistent_storage_pool> {
 
	uint32 grfid; ///< GRFID associated to this persistent storage. A value of zero means "default".
 

	
 
	/** We don't want GCC to zero our struct! It already is zeroed and has an index! */
 
	PersistentStorage(const uint32 new_grfid) : grfid(new_grfid)
 
	{
 
		this->prev_storage = NULL;
 
		memset(this->storage, 0, sizeof(this->storage));
 
	}
 

	
 
	/** Free the memory used by the persistent storage. */
 
	~PersistentStorage()
 
	{
 
		free(this->prev_storage);
 
	}
 
};
 

	
 
assert_compile(cpp_lengthof(OldPersistentStorage, storage) == cpp_lengthof(PersistentStorage, storage));
 

	
 
#define FOR_ALL_STORAGES_FROM(var, start) FOR_ALL_ITEMS_FROM(PersistentStorage, storage_index, var, start)
 
#define FOR_ALL_STORAGES(var) FOR_ALL_STORAGES_FROM(var, 0)
 

	
 
#endif /* NEWGRF_STORAGE_H */
src/saveload/afterload.cpp
Show inline comments
 
@@ -2592,12 +2592,64 @@ bool AfterLoadGame()
 
		 * since a new option (minimal at position 1) has been added */
 
		if (_settings_game.difficulty.industry_density > 0) {
 
			_settings_game.difficulty.industry_density++;
 
		}
 
	}
 

	
 
	if (IsSavegameVersionBefore(161)) {
 
		/* Before savegame version 161, persistent storages were not stored in a pool. */
 

	
 
		if (!IsSavegameVersionBefore(76)) {
 
			Industry *ind;
 
			FOR_ALL_INDUSTRIES(ind) {
 
				assert(ind->psa != NULL);
 

	
 
				/* Check if the old storage was empty. */
 
				bool is_empty = true;
 
				for (uint i = 0; i < sizeof(ind->psa->storage); i++) {
 
					if (ind->psa->GetValue(i) != 0) {
 
						is_empty = false;
 
						break;
 
					}
 
				}
 

	
 
				if (!is_empty) {
 
					ind->psa->grfid = _industry_mngr.GetGRFID(ind->type);
 
				} else {
 
					delete ind->psa;
 
					ind->psa = NULL;
 
				}
 
			}
 
		}
 

	
 
		if (!IsSavegameVersionBefore(145)) {
 
			Station *st;
 
			FOR_ALL_STATIONS(st) {
 
				if (!st->facilities & FACIL_AIRPORT) continue;
 
				assert(st->airport.psa != NULL);
 

	
 
				/* Check if the old storage was empty. */
 
				bool is_empty = true;
 
				for (uint i = 0; i < sizeof(st->airport.psa->storage); i++) {
 
					if (st->airport.psa->GetValue(i) != 0) {
 
						is_empty = false;
 
						break;
 
					}
 
				}
 

	
 
				if (!is_empty) {
 
					st->airport.psa->grfid = _airport_mngr.GetGRFID(st->airport.type);
 
				} else {
 
					delete st->airport.psa;
 
					st->airport.psa = NULL;
 

	
 
				}
 
			}
 
		}
 
	}
 

	
 
	/* Road stops is 'only' updating some caches */
 
	AfterLoadRoadStops();
 
	AfterLoadLabelMaps();
 

	
 
	GamelogPrintDebug(1);
 

	
src/saveload/industry_sl.cpp
Show inline comments
 
@@ -8,16 +8,19 @@
 
 */
 

	
 
/** @file industry_sl.cpp Code handling saving and loading of industries */
 

	
 
#include "../stdafx.h"
 
#include "../industry.h"
 
#include "../newgrf.h"
 

	
 
#include "saveload.h"
 
#include "newgrf_sl.h"
 

	
 
static OldPersistentStorage _old_ind_persistent_storage;
 

	
 
static const SaveLoad _industry_desc[] = {
 
	SLE_CONDVAR(Industry, location.tile,              SLE_FILE_U16 | SLE_VAR_U32,  0, 5),
 
	SLE_CONDVAR(Industry, location.tile,              SLE_UINT32,                  6, SL_MAX_VERSION),
 
	    SLE_VAR(Industry, location.w,                 SLE_FILE_U8 | SLE_VAR_U16),
 
	    SLE_VAR(Industry, location.h,                 SLE_FILE_U8 | SLE_VAR_U16),
 
	    SLE_REF(Industry, town,                       REF_TOWN),
 
@@ -47,13 +50,14 @@ static const SaveLoad _industry_desc[] =
 
	SLE_CONDVAR(Industry, founder,                    SLE_UINT8,                 70, SL_MAX_VERSION),
 
	SLE_CONDVAR(Industry, construction_date,          SLE_INT32,                 70, SL_MAX_VERSION),
 
	SLE_CONDVAR(Industry, construction_type,          SLE_UINT8,                 70, SL_MAX_VERSION),
 
	SLE_CONDVAR(Industry, last_cargo_accepted_at,     SLE_INT32,                 70, SL_MAX_VERSION),
 
	SLE_CONDVAR(Industry, selected_layout,            SLE_UINT8,                 73, SL_MAX_VERSION),
 

	
 
	SLE_CONDARR(Industry, psa.storage,                SLE_UINT32, 16,            76, SL_MAX_VERSION),
 
	SLEG_CONDARR(_old_ind_persistent_storage.storage, SLE_UINT32, 16,            76, 160),
 
	SLE_CONDREF(Industry, psa,                        REF_STORAGE,              161, SL_MAX_VERSION),
 

	
 
	SLE_CONDVAR(Industry, random_triggers,            SLE_UINT8,                 82, SL_MAX_VERSION),
 
	SLE_CONDVAR(Industry, random,                     SLE_UINT16,                82, SL_MAX_VERSION),
 

	
 
	SLE_CONDNULL(32, 2, 143), // old reserved space
 

	
 
@@ -87,12 +91,20 @@ static void Load_INDY()
 

	
 
	Industry::ResetIndustryCounts();
 

	
 
	while ((index = SlIterateArray()) != -1) {
 
		Industry *i = new (index) Industry();
 
		SlObject(i, _industry_desc);
 

	
 
		/* Before savegame version 161, persistent storages were not stored in a pool. */
 
		if (IsSavegameVersionBefore(161) && !IsSavegameVersionBefore(76)) {
 
			/* Store the old persistent storage. The GRFID will be added later. */
 
			assert(PersistentStorage::CanAllocateItem());
 
			i->psa = new PersistentStorage(0);
 
			memcpy(i->psa->storage, _old_ind_persistent_storage.storage, sizeof(i->psa->storage));
 
		}
 
		Industry::IncIndustryTypeCount(i->type);
 
	}
 
}
 

	
 
static void Load_IIDS()
 
{
src/saveload/saveload.cpp
Show inline comments
 
@@ -222,14 +222,15 @@
 
 *  155   21453
 
 *  156   21728
 
 *  157   21862
 
 *  158   21933
 
 *  159   21962
 
 *  160   21974
 
 *  161   22567
 
 */
 
extern const uint16 SAVEGAME_VERSION = 160; ///< Current savegame version of OpenTTD.
 
extern const uint16 SAVEGAME_VERSION = 161; ///< Current savegame version of OpenTTD.
 

	
 
SavegameType _savegame_type; ///< type of savegame we are loading
 

	
 
uint32 _ttdp_version;     ///< version of TTDP savegame (if applicable)
 
uint16 _sl_version;       ///< the major savegame version identifier
 
byte   _sl_minor_version; ///< the minor savegame version, DO NOT USE!
 
@@ -401,12 +402,13 @@ extern const ChunkHandler _newgrf_chunk_
 
extern const ChunkHandler _group_chunk_handlers[];
 
extern const ChunkHandler _cargopacket_chunk_handlers[];
 
extern const ChunkHandler _autoreplace_chunk_handlers[];
 
extern const ChunkHandler _labelmaps_chunk_handlers[];
 
extern const ChunkHandler _airport_chunk_handlers[];
 
extern const ChunkHandler _object_chunk_handlers[];
 
extern const ChunkHandler _persistent_storage_chunk_handlers[];
 

	
 
/** Array of all chunks in a savegame, \c NULL terminated. */
 
static const ChunkHandler * const _chunk_handlers[] = {
 
	_gamelog_chunk_handlers,
 
	_map_chunk_handlers,
 
	_misc_chunk_handlers,
 
@@ -431,12 +433,13 @@ static const ChunkHandler * const _chunk
 
	_group_chunk_handlers,
 
	_cargopacket_chunk_handlers,
 
	_autoreplace_chunk_handlers,
 
	_labelmaps_chunk_handlers,
 
	_airport_chunk_handlers,
 
	_object_chunk_handlers,
 
	_persistent_storage_chunk_handlers,
 
	NULL,
 
};
 

	
 
/**
 
 * Iterate over all chunk handlers.
 
 * @param ch the chunk handler iterator
 
@@ -1170,15 +1173,16 @@ static size_t ReferenceToInt(const void 
 
		case REF_VEHICLE_OLD: // Old vehicles we save as new onces
 
		case REF_VEHICLE:   return ((const  Vehicle*)obj)->index + 1;
 
		case REF_STATION:   return ((const  Station*)obj)->index + 1;
 
		case REF_TOWN:      return ((const     Town*)obj)->index + 1;
 
		case REF_ORDER:     return ((const    Order*)obj)->index + 1;
 
		case REF_ROADSTOPS: return ((const RoadStop*)obj)->index + 1;
 
		case REF_ENGINE_RENEWS: return ((const EngineRenew*)obj)->index + 1;
 
		case REF_CARGO_PACKET:  return ((const CargoPacket*)obj)->index + 1;
 
		case REF_ORDERLIST:     return ((const   OrderList*)obj)->index + 1;
 
		case REF_ENGINE_RENEWS: return ((const       EngineRenew*)obj)->index + 1;
 
		case REF_CARGO_PACKET:  return ((const       CargoPacket*)obj)->index + 1;
 
		case REF_ORDERLIST:     return ((const         OrderList*)obj)->index + 1;
 
		case REF_STORAGE:       return ((const PersistentStorage*)obj)->index + 1;
 
		default: NOT_REACHED();
 
	}
 
}
 

	
 
/**
 
 * Pointers cannot be loaded from a savegame, so this function
 
@@ -1242,12 +1246,16 @@ static void *IntToReference(size_t index
 
			SlErrorCorrupt("Referencing invalid EngineRenew");
 

	
 
		case REF_CARGO_PACKET:
 
			if (CargoPacket::IsValidID(index)) return CargoPacket::Get(index);
 
			SlErrorCorrupt("Referencing invalid CargoPacket");
 

	
 
		case REF_STORAGE:
 
			if (PersistentStorage::IsValidID(index)) return PersistentStorage::Get(index);
 
			SlErrorCorrupt("Referencing invalid PersistentStorage");
 

	
 
		default: NOT_REACHED();
 
	}
 
}
 

	
 
/**
 
 * Return the size in bytes of a list
src/saveload/saveload.h
Show inline comments
 
@@ -85,12 +85,13 @@ enum SLRefType {
 
	REF_TOWN          = 3, ///< Load/save a reference to a town.
 
	REF_VEHICLE_OLD   = 4, ///< Load/save an old-style reference to a vehicle (for pre-4.4 savegames).
 
	REF_ROADSTOPS     = 5, ///< Load/save a reference to a bus/truck stop.
 
	REF_ENGINE_RENEWS = 6, ///< Load/save a reference to an engine renewal (autoreplace).
 
	REF_CARGO_PACKET  = 7, ///< Load/save a reference to a cargo packet.
 
	REF_ORDERLIST     = 8, ///< Load/save a reference to an orderlist.
 
	REF_STORAGE       = 9, ///< Load/save a reference to a persistent storage.
 
};
 

	
 
/** Highest possible savegame version. */
 
#define SL_MAX_VERSION 255
 

	
 
/** Flags of a chunk. */
src/saveload/station_sl.cpp
Show inline comments
 
@@ -12,12 +12,13 @@
 
#include "../stdafx.h"
 
#include "../station_base.h"
 
#include "../waypoint_base.h"
 
#include "../roadstop_base.h"
 
#include "../vehicle_base.h"
 
#include "../newgrf_station.h"
 
#include "../newgrf.h"
 

	
 
#include "saveload.h"
 
#include "table/strings.h"
 

	
 
/**
 
 * Update the buoy orders to be waypoint orders.
 
@@ -341,12 +342,14 @@ static const SaveLoad _base_station_desc
 
	      SLE_VAR(BaseStation, waiting_triggers,       SLE_UINT8),
 
	      SLE_VAR(BaseStation, num_specs,              SLE_UINT8),
 

	
 
	      SLE_END()
 
};
 

	
 
static OldPersistentStorage _old_st_persistent_storage;
 

	
 
static const SaveLoad _station_desc[] = {
 
	SLE_WRITEBYTE(Station, facilities,                 FACIL_NONE),
 
	SLE_ST_INCLUDE(),
 

	
 
	      SLE_VAR(Station, train_station.tile,         SLE_UINT32),
 
	      SLE_VAR(Station, train_station.w,            SLE_FILE_U8 | SLE_VAR_U16),
 
@@ -359,13 +362,14 @@ static const SaveLoad _station_desc[] = 
 
	  SLE_CONDVAR(Station, airport.w,                  SLE_FILE_U8 | SLE_VAR_U16, 140, SL_MAX_VERSION),
 
	  SLE_CONDVAR(Station, airport.h,                  SLE_FILE_U8 | SLE_VAR_U16, 140, SL_MAX_VERSION),
 
	      SLE_VAR(Station, airport.type,               SLE_UINT8),
 
	  SLE_CONDVAR(Station, airport.layout,             SLE_UINT8,                 145, SL_MAX_VERSION),
 
	      SLE_VAR(Station, airport.flags,              SLE_UINT64),
 
	  SLE_CONDVAR(Station, airport.rotation,           SLE_UINT8,                 145, SL_MAX_VERSION),
 
	  SLE_CONDARR(Station, airport.psa.storage,        SLE_UINT32, 16,            145, SL_MAX_VERSION),
 
	 SLEG_CONDARR(_old_st_persistent_storage.storage,  SLE_UINT32, 16,            145, 160),
 
	  SLE_CONDREF(Station, airport.psa,                REF_STORAGE,               161, SL_MAX_VERSION),
 

	
 
	      SLE_VAR(Station, indtype,                    SLE_UINT8),
 

	
 
	      SLE_VAR(Station, time_since_load,            SLE_UINT8),
 
	      SLE_VAR(Station, time_since_unload,          SLE_UINT8),
 
	      SLE_VAR(Station, last_vehicle_type,          SLE_UINT8),
 
@@ -434,12 +438,21 @@ static void Load_STNN()
 

	
 
		BaseStation *bst = waypoint ? (BaseStation *)new (index) Waypoint() : new (index) Station();
 
		SlObject(bst, waypoint ? _waypoint_desc : _station_desc);
 

	
 
		if (!waypoint) {
 
			Station *st = Station::From(bst);
 

	
 
			/* Before savegame version 161, persistent storages were not stored in a pool. */
 
			if (IsSavegameVersionBefore(161) && !IsSavegameVersionBefore(145) && st->facilities & FACIL_AIRPORT) {
 
				/* Store the old persistent storage. The GRFID will be added later. */
 
				assert(PersistentStorage::CanAllocateItem());
 
				st->airport.psa = new PersistentStorage(0);
 
				memcpy(st->airport.psa->storage, _old_st_persistent_storage.storage, sizeof(st->airport.psa->storage));
 
			}
 

	
 
			for (CargoID i = 0; i < NUM_CARGO; i++) {
 
				SlObject(&st->goods[i], GetGoodsDesc());
 
			}
 
		}
 

	
 
		if (bst->num_specs != 0) {
src/saveload/storage_sl.cpp
Show inline comments
 
new file 100644
 
/* $Id$ */
 

	
 
/*
 
 * This file is part of OpenTTD.
 
 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
 
 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
/** @file persistent_storage_sl.cpp Code handling saving and loading of persistent storages. */
 

	
 
#include "../stdafx.h"
 
#include "../newgrf_storage.h"
 
#include "saveload.h"
 

	
 
/** Description of the data to save and load in #PersistentStorage. */
 
static const SaveLoad _storage_desc[] = {
 
	 SLE_CONDVAR(PersistentStorage, grfid,    SLE_UINT32,                  6, SL_MAX_VERSION),
 
	 SLE_CONDARR(PersistentStorage, storage,  SLE_UINT32, 16,            161, SL_MAX_VERSION),
 
	 SLE_END()
 
};
 

	
 
/** Load persistent storage data. */
 
static void Load_PSAC()
 
{
 
	int index;
 

	
 
	while ((index = SlIterateArray()) != -1) {
 
		assert(PersistentStorage::CanAllocateItem());
 
		PersistentStorage *ps = new (index) PersistentStorage(0);
 
		SlObject(ps, _storage_desc);
 
	}
 
}
 

	
 
/** Save persistent storage data. */
 
static void Save_PSAC()
 
{
 
	PersistentStorage *ps;
 

	
 
	/* Write the industries */
 
	FOR_ALL_STORAGES(ps) {
 
		SlSetArrayIndex(ps->index);
 
		SlObject(ps, _storage_desc);
 
	}
 
}
 

	
 
/** Chunk handler for persistent storages. */
 
extern const ChunkHandler _persistent_storage_chunk_handlers[] = {
 
	{ 'PSAC', Save_PSAC, Load_PSAC, NULL, NULL, CH_ARRAY | CH_LAST},
 
};
src/station.cpp
Show inline comments
 
@@ -93,12 +93,16 @@ Station::~Station()
 
		/* Forget about this station if this station is removed */
 
		if (v->last_station_visited == this->index) {
 
			v->last_station_visited = INVALID_STATION;
 
		}
 
	}
 

	
 
	/* Clear the persistent storage. */
 
	delete this->airport.psa;
 

	
 

	
 
	InvalidateWindowData(WC_STATION_LIST, this->owner, 0);
 

	
 
	DeleteWindowById(WC_STATION_VIEW, index);
 

	
 
	/* Now delete all orders that go to the station */
 
	RemoveOrderFromAllVehicles(OT_GOTO_STATION, this->index);
src/station_base.h
Show inline comments
 
@@ -53,21 +53,20 @@ struct GoodsEntry {
 
	byte amount_fract;      ///< Fractional part of the amount in the cargo list
 
	StationCargoList cargo; ///< The cargo packets of cargo waiting in this station
 
};
 

	
 
/** All airport-related information. Only valid if tile != INVALID_TILE. */
 
struct Airport : public TileArea {
 
	typedef PersistentStorageArray<int32, 16> PersistentStorage;
 

	
 
	Airport() : TileArea(INVALID_TILE, 0, 0) {}
 

	
 
	uint64 flags;       ///< stores which blocks on the airport are taken. was 16 bit earlier on, then 32
 
	byte type;          ///< Type of this airport, @see AirportTypes.
 
	byte layout;        ///< Airport layout number.
 
	Direction rotation; ///< How this airport is rotated.
 
	PersistentStorage psa; ///< Persistent storage for NewGRF airports
 

	
 
	PersistentStorage *psa; ///< Persistent storage for NewGRF airports.
 

	
 
	/**
 
	 * Get the AirportSpec that from the airport type of this airport. If there
 
	 * is no airport (\c tile == INVALID_TILE) then return the dummy AirportSpec.
 
	 * @return The AirportSpec for this airport.
 
	 */
src/station_cmd.cpp
Show inline comments
 
@@ -2188,13 +2188,12 @@ CommandCost CmdBuildAirport(TileIndex ti
 

	
 
		st->AddFacility(FACIL_AIRPORT, tile);
 
		st->airport.type = airport_type;
 
		st->airport.layout = layout;
 
		st->airport.flags = 0;
 
		st->airport.rotation = rotation;
 
		st->airport.psa.ResetToZero();
 

	
 
		st->rect.BeforeAddRect(tile, w, h, StationRect::ADD_TRY);
 

	
 
		it = as->table[layout];
 
		do {
 
			TileIndex cur_tile = tile + ToTileIndexDiff(it->ti);
 
@@ -2268,12 +2267,15 @@ static CommandCost RemoveAirport(TileInd
 
			DoClearSquare(tile_cur);
 
			DeleteNewGRFInspectWindow(GSF_AIRPORTTILES, tile_cur);
 
		}
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		/* Clear the persistent storage. */
 
		delete st->airport.psa;
 

	
 
		const AirportSpec *as = st->airport.GetSpec();
 
		for (uint i = 0; i < st->airport.GetNumHangars(); ++i) {
 
			DeleteWindowById(
 
				WC_VEHICLE_DEPOT, st->airport.GetHangarTile(i)
 
			);
 
		}
 
@@ -2285,13 +2287,12 @@ static CommandCost RemoveAirport(TileInd
 
		nearest->noise_reached -= GetAirportNoiseLevelForTown(as, nearest->xy, tile);
 

	
 
		st->rect.AfterRemoveRect(st, st->airport);
 

	
 
		st->airport.Clear();
 
		st->facilities &= ~FACIL_AIRPORT;
 
		st->airport.psa.ResetToZero();
 

	
 
		SetWindowWidgetDirty(WC_STATION_VIEW, st->index, SVW_PLANES);
 

	
 
		if (_settings_game.economy.station_noise_level) {
 
			SetWindowDirty(WC_TOWN_VIEW, st->town->index);
 
		}
src/table/newgrf_debug_data.h
Show inline comments
 
@@ -288,18 +288,19 @@ class NIHIndustry : public NIHelper {
 
	bool IsInspectable(uint index) const                 { return GetIndustrySpec(Industry::Get(index)->type)->grf_prop.grffile != NULL; }
 
	uint GetParent(uint index) const                     { return GetInspectWindowNumber(GSF_FAKE_TOWNS, Industry::Get(index)->town->index); }
 
	const void *GetInstance(uint index)const             { return Industry::Get(index); }
 
	const void *GetSpec(uint index) const                { return GetIndustrySpec(Industry::Get(index)->type); }
 
	void SetStringParameters(uint index) const           { this->SetSimpleStringParameters(STR_INDUSTRY_NAME, index); }
 
	void Resolve(ResolverObject *ro, uint32 index) const { extern void GetIndustryResolver(ResolverObject *ro, uint index); GetIndustryResolver(ro, index); }
 
	uint GetPSASize(uint index, uint32 grfid) const      { return cpp_lengthof(Industry, psa.storage); }
 
	uint GetPSASize(uint index, uint32 grfid) const      { return cpp_lengthof(PersistentStorage, storage); }
 

	
 
	int32 *GetPSAFirstPosition(uint index, uint32 grfid) const
 
	{
 
		const void *base = this->GetInstance(index);
 
		return (int32*)((byte*)base + cpp_offsetof(Industry, psa.storage));
 
		Industry *i = (Industry *)this->GetInstance(index);
 
		if (i->psa == NULL) return NULL;
 
		return (int32 *)(&i->psa->storage);
 
	}
 
};
 

	
 
static const NIFeature _nif_industry = {
 
	_nip_industries,
 
	_nic_industries,
0 comments (0 inline, 0 general)