summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-09-10 14:33:07 +0000
committerrubidium <rubidium@openttd.org>2009-09-10 14:33:07 +0000
commit55ddce8da2b6993fa1228a8935526d40fc44de46 (patch)
tree02f1f3836fd9c76b19b741a772d0efb29c528d7b
parentbb94724a092750794e8c2ad1a6537fac6b902b9e (diff)
downloadopenttd-55ddce8da2b6993fa1228a8935526d40fc44de46.tar.xz
(svn r17493) -Codechange: store the depot index on the map
-rw-r--r--docs/landscape.html3
-rw-r--r--docs/landscape_grid.html6
-rw-r--r--src/depot_map.h13
-rw-r--r--src/rail_cmd.cpp6
-rw-r--r--src/rail_map.h5
-rw-r--r--src/road_cmd.cpp2
-rw-r--r--src/road_map.h5
-rw-r--r--src/saveload/afterload.cpp9
-rw-r--r--src/town_cmd.cpp2
-rw-r--r--src/water_cmd.cpp4
-rw-r--r--src/water_map.h5
11 files changed, 45 insertions, 15 deletions
diff --git a/docs/landscape.html b/docs/landscape.html
index c6847e0c7..0c54acee6 100644
--- a/docs/landscape.html
+++ b/docs/landscape.html
@@ -454,6 +454,7 @@
</li>
<li>m5 bit 7 set, bit 6 set: railway depot
<ul>
+ <li>m2: Depot index</li>
<li>m5 bits 1..0: exit towards
<table>
<tr>
@@ -609,6 +610,7 @@
<li>m5 bit 7 set, bit 6 clear: road depot
<ul>
<li>m1: <a href="#OwnershipInfo">owner</a> of the depot</li>
+ <li>m2: Depot index</li>
<li>m5 bits 3..0: exit towards:
<table>
<tr>
@@ -952,6 +954,7 @@
<td>
<ul>
<li>m1: <a href="#OwnershipInfo">owner</a> (for sea, rivers, and coasts normally <tt>11</tt>)</li>
+ <li>m2: Depot index (for depots only)</li>
<li>m3 bits 1..0 : Water class (sea, canal or river)
<li>m4: Random data for canal or river tiles</li>
<li>m5: tile type:
diff --git a/docs/landscape_grid.html b/docs/landscape_grid.html
index ac2671005..604f14669 100644
--- a/docs/landscape_grid.html
+++ b/docs/landscape_grid.html
@@ -112,7 +112,7 @@ the array so you can quickly see what is used and what is not.
<td class="caption">depot</td>
<td class="bits">-inherit-</td>
<td class="bits">-inherit-</td>
- <td class="bits"><span class="free">OOOO OOOO OOOO OOOO</span></td>
+ <td class="bits">XXXX XXXX XXXX XXXX</td>
<td class="bits"><span class="free">OOOO</span> <span class="option">~~</span>XX</td>
<td class="bits"><span class="free">OOOO</span> XXXX</td>
<td class="bits">XX<span class="free">O</span>X <span class="free">O</span>XXX</td>
@@ -146,7 +146,7 @@ the array so you can quickly see what is used and what is not.
<td class="caption">road depot</td>
<td class="bits">-inherit-</td>
<td class="bits">-inherit-</td>
- <td class="bits">-inherit-</td>
+ <td class="bits">XXXX XXXX XXXX XXXX</td>
<td class="bits"><span class="free">OOOO OOOO</span></td>
<td class="bits"><span class="free">OOOO OOOO</span></td>
<td class="bits">XX<span class="free">OO OO</span>XX</td>
@@ -282,7 +282,7 @@ the array so you can quickly see what is used and what is not.
<td class="caption">shipdepot</td>
<td class="bits">-inherit-</td>
<td class="bits">-inherit-</td>
- <td class="bits"><span class="free">OOOO OOOO OOOO OOOO</span></td>
+ <td class="bits">XXXX XXXX XXXX XXXX</td>
<td class="bits"><span class="free">OOOO OO</span>XX</td>
<td class="bits"><span class="free">OOOO OOOO</span></td>
<td class="bits">-inherit-</td>
diff --git a/src/depot_map.h b/src/depot_map.h
index 4f34da34a..ecf2960e1 100644
--- a/src/depot_map.h
+++ b/src/depot_map.h
@@ -45,4 +45,17 @@ static inline bool IsDepotTile(TileIndex tile)
return IsRailDepotTile(tile) || IsRoadDepotTile(tile) || IsShipDepotTile(tile) || IsHangarTile(tile);
}
+/**
+ * Get the index of which depot is attached to the tile.
+ * @param t the tile
+ * @pre IsRailDepotTile(t) || IsRoadDepotTile(t) || IsShipDepotTile(t)
+ * @return DepotID
+ */
+static inline DepotID GetDepotIndex(TileIndex t)
+{
+ /* Hangars don't have a Depot class, thus store no DepotID. */
+ assert(IsRailDepotTile(t) || IsRoadDepotTile(t) || IsShipDepotTile(t));
+ return _m[t].m2;
+}
+
#endif /* DEPOT_MAP_H */
diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp
index 6b875f843..c2633bcf7 100644
--- a/src/rail_cmd.cpp
+++ b/src/rail_cmd.cpp
@@ -789,11 +789,11 @@ CommandCost CmdBuildTrainDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, u
if (flags & DC_EXEC) {
Depot *d = new Depot(tile);
- MakeRailDepot(tile, _current_company, dir, (RailType)p1);
- MarkTileDirtyByTile(tile);
-
d->town_index = ClosestTownFromTile(tile, UINT_MAX)->index;
+ MakeRailDepot(tile, _current_company, d->index, dir, (RailType)p1);
+ MarkTileDirtyByTile(tile);
+
AddSideToSignalBuffer(tile, INVALID_DIAGDIR, _current_company);
YapfNotifyTrackLayoutChange(tile, DiagDirToDiagTrack(dir));
}
diff --git a/src/rail_map.h b/src/rail_map.h
index f8a74d0eb..b3fc68d90 100644
--- a/src/rail_map.h
+++ b/src/rail_map.h
@@ -13,6 +13,7 @@
#define RAIL_MAP_H
#include "rail_type.h"
+#include "depot_type.h"
#include "signal_func.h"
#include "direction_func.h"
#include "track_func.h"
@@ -551,11 +552,11 @@ static inline void MakeRailNormal(TileIndex t, Owner o, TrackBits b, RailType r)
}
-static inline void MakeRailDepot(TileIndex t, Owner o, DiagDirection d, RailType r)
+static inline void MakeRailDepot(TileIndex t, Owner o, DepotID did, DiagDirection d, RailType r)
{
SetTileType(t, MP_RAILWAY);
SetTileOwner(t, o);
- _m[t].m2 = 0;
+ _m[t].m2 = did;
_m[t].m3 = r;
_m[t].m4 = 0;
_m[t].m5 = RAIL_TILE_DEPOT << 6 | d;
diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp
index 05e1ef571..9f5787044 100644
--- a/src/road_cmd.cpp
+++ b/src/road_cmd.cpp
@@ -882,7 +882,7 @@ CommandCost CmdBuildRoadDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, ui
Depot *dep = new Depot(tile);
dep->town_index = ClosestTownFromTile(tile, UINT_MAX)->index;
- MakeRoadDepot(tile, _current_company, dir, rt);
+ MakeRoadDepot(tile, _current_company, dep->index, dir, rt);
MarkTileDirtyByTile(tile);
}
return cost.AddCost(_price.build_road_depot);
diff --git a/src/road_map.h b/src/road_map.h
index 04e87f1b9..b43e056ff 100644
--- a/src/road_map.h
+++ b/src/road_map.h
@@ -13,6 +13,7 @@
#define ROAD_MAP_H
#include "track_func.h"
+#include "depot_type.h"
#include "rail_type.h"
#include "town_type.h"
#include "road_func.h"
@@ -407,11 +408,11 @@ static inline void MakeRoadCrossing(TileIndex t, Owner road, Owner tram, Owner r
}
-static inline void MakeRoadDepot(TileIndex t, Owner owner, DiagDirection dir, RoadType rt)
+static inline void MakeRoadDepot(TileIndex t, Owner owner, DepotID did, DiagDirection dir, RoadType rt)
{
SetTileType(t, MP_ROAD);
SetTileOwner(t, owner);
- _m[t].m2 = 0;
+ _m[t].m2 = did;
_m[t].m3 = 0;
_m[t].m4 = 0;
_m[t].m5 = ROAD_TILE_DEPOT << 6 | dir;
diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp
index 4a122d005..b1d2625d5 100644
--- a/src/saveload/afterload.cpp
+++ b/src/saveload/afterload.cpp
@@ -13,6 +13,7 @@
#include "../void_map.h"
#include "../signs_base.h"
#include "../roadstop_base.h"
+#include "../depot_base.h"
#include "../window_func.h"
#include "../fios.h"
#include "../train.h"
@@ -1951,6 +1952,14 @@ bool AfterLoadGame()
FOR_ALL_STATIONS(st) UpdateStationAcceptance(st, false);
}
+ if (CheckSavegameVersion(128)) {
+ const Depot *d;
+ FOR_ALL_DEPOTS(d) {
+ _m[d->xy].m2 = d->index;
+ if (IsTileType(d->xy, MP_WATER)) _m[GetOtherShipDepotTile(d->xy)].m2 = d->index;
+ }
+ }
+
AfterLoadLabelMaps();
GamelogPrintDebug(1);
diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp
index 921a592b6..8a9a366f9 100644
--- a/src/town_cmd.cpp
+++ b/src/town_cmd.cpp
@@ -2730,6 +2730,8 @@ Town *ClosestTownFromTile(TileIndex tile, uint threshold)
{
switch (GetTileType(tile)) {
case MP_ROAD:
+ if (IsRoadDepot(tile)) return CalcClosestTownFromTile(tile, threshold);
+
if (!HasTownOwnedRoad(tile)) {
TownID tid = GetTownIndex(tile);
diff --git a/src/water_cmd.cpp b/src/water_cmd.cpp
index f3f60c52c..a756024f2 100644
--- a/src/water_cmd.cpp
+++ b/src/water_cmd.cpp
@@ -141,8 +141,8 @@ CommandCost CmdBuildShipDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, ui
Depot *depot = new Depot(tile);
depot->town_index = ClosestTownFromTile(tile, UINT_MAX)->index;
- MakeShipDepot(tile, _current_company, DEPOT_NORTH, axis, wc1);
- MakeShipDepot(tile2, _current_company, DEPOT_SOUTH, axis, wc2);
+ MakeShipDepot(tile, _current_company, depot->index, DEPOT_NORTH, axis, wc1);
+ MakeShipDepot(tile2, _current_company, depot->index, DEPOT_SOUTH, axis, wc2);
MarkTileDirtyByTile(tile);
MarkTileDirtyByTile(tile2);
}
diff --git a/src/water_map.h b/src/water_map.h
index 474593284..7210c90ca 100644
--- a/src/water_map.h
+++ b/src/water_map.h
@@ -13,6 +13,7 @@
#define WATER_MAP_H
#include "core/math_func.hpp"
+#include "depot_type.h"
enum WaterTileType {
WATER_TILE_CLEAR,
@@ -196,11 +197,11 @@ static inline void MakeCanal(TileIndex t, Owner o, uint8 random_bits)
_me[t].m7 = 0;
}
-static inline void MakeShipDepot(TileIndex t, Owner o, DepotPart base, Axis a, WaterClass original_water_class)
+static inline void MakeShipDepot(TileIndex t, Owner o, DepotID did, DepotPart base, Axis a, WaterClass original_water_class)
{
SetTileType(t, MP_WATER);
SetTileOwner(t, o);
- _m[t].m2 = 0;
+ _m[t].m2 = did;
_m[t].m3 = original_water_class;
_m[t].m4 = 0;
_m[t].m5 = base + a * 2;