summaryrefslogtreecommitdiff
path: root/src/newgrf_airport.cpp
diff options
context:
space:
mode:
authorterkhen <terkhen@openttd.org>2011-06-12 20:47:45 +0000
committerterkhen <terkhen@openttd.org>2011-06-12 20:47:45 +0000
commit00e5c1df18449992cc974b99c61a44d1385bf4a7 (patch)
tree7433db92049848236fe05f18b99d6f80c99442c6 /src/newgrf_airport.cpp
parent9f55abf51aac0f408e60d905fb2ac1b8a1405bb9 (diff)
downloadopenttd-00e5c1df18449992cc974b99c61a44d1385bf4a7.tar.xz
(svn r22567) -Codechange: Store persistent storages inside a pool.
Diffstat (limited to 'src/newgrf_airport.cpp')
-rw-r--r--src/newgrf_airport.cpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/newgrf_airport.cpp b/src/newgrf_airport.cpp
index 03fa9567d..0b1dd650c 100644
--- a/src/newgrf_airport.cpp
+++ b/src/newgrf_airport.cpp
@@ -149,7 +149,7 @@ uint32 AirportGetVariable(const ResolverObject *object, byte variable, byte para
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);
@@ -194,7 +194,17 @@ 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)