Allow building multiple docks per station.

(cherry picked from commit 0110c4a35d383e0be2cbb53cbe9cbe6784abb3e9)

# Conflicts:
#	src/station_cmd.cpp
This commit is contained in:
keldorkatarn
2017-09-11 22:48:19 +02:00
committed by Jonathan G Rennison
parent d486d58d86
commit 1d3cf59d8a
26 changed files with 412 additions and 62 deletions

View File

@@ -30,6 +30,7 @@
#include "../station_base.h"
#include "../waypoint_base.h"
#include "../roadstop_base.h"
#include "../dock_base.h"
#include "../tunnelbridge_map.h"
#include "../pathfinder/yapf/yapf_cache.h"
#include "../elrail_func.h"
@@ -728,9 +729,9 @@ bool AfterLoadGame()
/* no station is determined by 'tile == INVALID_TILE' now (instead of '0') */
Station *st;
FOR_ALL_STATIONS(st) {
if (st->airport.tile == 0) st->airport.tile = INVALID_TILE;
if (st->dock_tile == 0) st->dock_tile = INVALID_TILE;
if (st->train_station.tile == 0) st->train_station.tile = INVALID_TILE;
if (st->airport.tile == 0) st->airport.tile = INVALID_TILE;
if (st->dock_station.tile == 0) st->dock_station.tile = INVALID_TILE;
if (st->train_station.tile == 0) st->train_station.tile = INVALID_TILE;
}
/* the same applies to Company::location_of_HQ */
@@ -3343,6 +3344,21 @@ bool AfterLoadGame()
FOR_ALL_STATIONS(st) UpdateStationAcceptance(st, false);
}
if (IsPatchPackSavegameVersionBefore(SL_PATCH_PACK_1_18)) {
/* Dock type has changed. */
Station *st;
FOR_ALL_STATIONS(st) {
if (st->dock_station.tile == INVALID_TILE) continue;
assert(Dock::CanAllocateItem());
if (IsOilRig(st->dock_station.tile)) {
/* Set dock station tile to dest tile instead of station. */
st->docks = new Dock(st->dock_station.tile, st->dock_station.tile + ToTileIndexDiff({1, 0}));
} else { /* A normal two-tiles dock. */
st->docks = new Dock(st->dock_station.tile, TileAddByDiagDir(st->dock_station.tile, GetDockDirection(st->dock_station.tile)));
}
}
}
// setting moved from game settings to company settings
if (SlXvIsFeaturePresent(XSLFI_ORDER_OCCUPANCY, 1, 1)) {
Company *c;

View File

@@ -728,7 +728,7 @@ static const OldChunks station_chunk[] = {
OCL_NULL( 4 ), ///< bus/lorry tile
OCL_SVAR( OC_TILE, Station, train_station.tile ),
OCL_SVAR( OC_TILE, Station, airport.tile ),
OCL_SVAR( OC_TILE, Station, dock_tile ),
OCL_SVAR( OC_TILE, Station, dock_station.tile),
OCL_SVAR( OC_FILE_U8 | OC_VAR_U16, Station, train_station.w ),
OCL_NULL( 1 ), ///< sort-index, no longer in use

View File

@@ -24,6 +24,7 @@
#include "../stdafx.h"
#include "../debug.h"
#include "../station_base.h"
#include "../dock_base.h"
#include "../thread/thread.h"
#include "../town.h"
#include "../network/network.h"
@@ -1344,6 +1345,7 @@ static size_t ReferenceToInt(const void *obj, SLRefType rt)
case REF_STORAGE: return ((const PersistentStorage*)obj)->index + 1;
case REF_LINK_GRAPH: return ((const LinkGraph*)obj)->index + 1;
case REF_LINK_GRAPH_JOB: return ((const LinkGraphJob*)obj)->index + 1;
case REF_DOCKS: return ((const Dock*)obj)->index + 1;
default: NOT_REACHED();
}
}
@@ -1409,6 +1411,10 @@ static void *IntToReference(size_t index, SLRefType rt)
if (RoadStop::IsValidID(index)) return RoadStop::Get(index);
SlErrorCorrupt("Referencing invalid RoadStop");
case REF_DOCKS:
if (Dock::IsValidID(index)) return Dock::Get(index);
SlErrorCorrupt("Referencing invalid Dock");
case REF_ENGINE_RENEWS:
if (EngineRenew::IsValidID(index)) return EngineRenew::Get(index);
SlErrorCorrupt("Referencing invalid EngineRenew");

View File

@@ -81,19 +81,20 @@ struct NullStruct {
/** Type of reference (#SLE_REF, #SLE_CONDREF). */
enum SLRefType {
REF_ORDER = 0, ///< Load/save a reference to an order.
REF_VEHICLE = 1, ///< Load/save a reference to a vehicle.
REF_STATION = 2, ///< Load/save a reference to a station.
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.
REF_LINK_GRAPH = 10, ///< Load/save a reference to a link graph.
REF_LINK_GRAPH_JOB = 11, ///< Load/save a reference to a link graph job.
REF_TEMPLATE_VEHICLE = 12, ///< Load/save a reference to a template vehicle
REF_ORDER = 0, ///< Load/save a reference to an order.
REF_VEHICLE = 1, ///< Load/save a reference to a vehicle.
REF_STATION = 2, ///< Load/save a reference to a station.
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.
REF_LINK_GRAPH = 10, ///< Load/save a reference to a link graph.
REF_LINK_GRAPH_JOB = 11, ///< Load/save a reference to a link graph job.
REF_TEMPLATE_VEHICLE = 12, ///< Load/save a reference to a template vehicle
REF_DOCKS = 13, ///< Load/save a reference to a dock.
};
/** Highest possible savegame version. */

View File

@@ -13,6 +13,7 @@
#include "../station_base.h"
#include "../waypoint_base.h"
#include "../roadstop_base.h"
#include "../dock_base.h"
#include "../vehicle_base.h"
#include "../newgrf_station.h"
@@ -123,6 +124,11 @@ void AfterLoadStations()
Station *sta = Station::From(st);
for (const RoadStop *rs = sta->bus_stops; rs != NULL; rs = rs->next) sta->bus_station.Add(rs->xy);
for (const RoadStop *rs = sta->truck_stops; rs != NULL; rs = rs->next) sta->truck_station.Add(rs->xy);
for (const Dock *d = sta->docks; d != NULL; d = d->next) {
sta->dock_station.Add(d->sloped);
sta->dock_station.Add(d->flat);
}
}
StationUpdateCachedTriggers(st);
@@ -166,6 +172,14 @@ static const SaveLoad _roadstop_desc[] = {
SLE_END()
};
static const SaveLoad _dock_desc[] = {
SLE_VAR(Dock, sloped, SLE_UINT32),
SLE_VAR(Dock, flat, SLE_UINT32),
SLE_REF(Dock, next, REF_DOCKS),
SLE_END()
};
static const SaveLoad _old_station_desc[] = {
SLE_CONDVAR(Station, xy, SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
SLE_CONDVAR(Station, xy, SLE_UINT32, 6, SL_MAX_VERSION),
@@ -174,8 +188,8 @@ static const SaveLoad _old_station_desc[] = {
SLE_CONDVAR(Station, train_station.tile, SLE_UINT32, 6, SL_MAX_VERSION),
SLE_CONDVAR(Station, airport.tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
SLE_CONDVAR(Station, airport.tile, SLE_UINT32, 6, SL_MAX_VERSION),
SLE_CONDVAR(Station, dock_tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
SLE_CONDVAR(Station, dock_tile, SLE_UINT32, 6, SL_MAX_VERSION),
SLE_CONDVAR(Station, dock_station.tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
SLE_CONDVAR(Station, dock_station.tile, SLE_UINT32, 6, SL_MAX_VERSION),
SLE_REF(Station, town, REF_TOWN),
SLE_VAR(Station, train_station.w, SLE_FILE_U8 | SLE_VAR_U16),
SLE_CONDVAR(Station, train_station.h, SLE_FILE_U8 | SLE_VAR_U16, 2, SL_MAX_VERSION),
@@ -425,7 +439,8 @@ static const SaveLoad _station_desc[] = {
SLE_REF(Station, bus_stops, REF_ROADSTOPS),
SLE_REF(Station, truck_stops, REF_ROADSTOPS),
SLE_VAR(Station, dock_tile, SLE_UINT32),
SLE_CONDVAR(Station, dock_station.tile, SLE_UINT32, 0, SL_PATCH_PACK_1_18 - 1),
SLE_CONDREF(Station, docks, REF_DOCKS, SL_PATCH_PACK_1_18, SL_MAX_VERSION),
SLE_VAR(Station, airport.tile, SLE_UINT32),
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),
@@ -638,8 +653,38 @@ static void Ptrs_ROADSTOP()
}
}
static void Save_DOCK()
{
Dock *d;
FOR_ALL_DOCKS(d) {
SlSetArrayIndex(d->index);
SlObject(d, _dock_desc);
}
}
static void Load_DOCK()
{
int index;
while ((index = SlIterateArray()) != -1) {
Dock *d = new (index) Dock();
SlObject(d, _dock_desc);
}
}
static void Ptrs_DOCK()
{
Dock *d;
FOR_ALL_DOCKS(d) {
SlObject(d, _dock_desc);
}
}
extern const ChunkHandler _station_chunk_handlers[] = {
{ 'STNS', NULL, Load_STNS, Ptrs_STNS, NULL, CH_ARRAY },
{ 'STNN', Save_STNN, Load_STNN, Ptrs_STNN, NULL, CH_ARRAY },
{ 'ROAD', Save_ROADSTOP, Load_ROADSTOP, Ptrs_ROADSTOP, NULL, CH_ARRAY | CH_LAST},
{ 'ROAD', Save_ROADSTOP, Load_ROADSTOP, Ptrs_ROADSTOP, NULL, CH_ARRAY},
{ 'DOCK', Save_DOCK, Load_DOCK, Ptrs_DOCK, NULL, CH_ARRAY | CH_LAST},
};