summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/landscape.html28
-rw-r--r--docs/landscape_grid.html2
-rw-r--r--src/newgrf_object.cpp2
-rw-r--r--src/object_base.h1
-rw-r--r--src/object_cmd.cpp23
-rw-r--r--src/object_map.h18
-rw-r--r--src/saveload/afterload.cpp36
-rw-r--r--src/saveload/object_sl.cpp3
-rw-r--r--src/saveload/saveload.cpp3
-rw-r--r--src/town_cmd.cpp2
10 files changed, 56 insertions, 62 deletions
diff --git a/docs/landscape.html b/docs/landscape.html
index cef38e03e..0a38b90e4 100644
--- a/docs/landscape.html
+++ b/docs/landscape.html
@@ -1597,34 +1597,6 @@
<li>m1 bits 4..0: <a href="#OwnershipInfo">owner</a> of the object (for lighthouses and transmitters normally <tt>10</tt>)</li>
<li>m2: index into the array of objects
<li>m3: random bits
- <li>m5: tile type:
- <table>
- <tr>
- <td nowrap valign=top><tt>00</tt>&nbsp; </td>
- <td align=left>transmitter</td>
- </tr>
-
- <tr>
- <td nowrap valign=top><tt>01</tt>&nbsp; </td>
- <td align=left>lighthouse</td>
- </tr>
-
- <tr>
- <td nowrap valign=top><tt>02</tt>&nbsp; </td>
- <td align=left>company statue
- </tr>
-
- <tr>
- <td nowrap valign=top><tt>03</tt>&nbsp; </td>
- <td align=left>company-owned land</td>
- </tr>
-
- <tr>
- <td nowrap valign=top><tt>04</tt><tt></tt>&nbsp; </td>
- <td align=left>company headquarters</td>
- </tr>
- </table>
- </li>
<li>m6 bits 7..6 : Possibility of a bridge above, in the <a href="#bridge_direction">direction specified</a></li>
<li>m6 bits 1..0 : <a href="#tropic_zone">Tropic zone definition</a></li>
<li>m7: animation counter
diff --git a/docs/landscape_grid.html b/docs/landscape_grid.html
index e2f3c1f97..b7603c72d 100644
--- a/docs/landscape_grid.html
+++ b/docs/landscape_grid.html
@@ -332,7 +332,7 @@ the array so you can quickly see what is used and what is not.
<td class="bits">XXXX XXXX XXXX XXXX</td>
<td class="bits">XXXX XXXX</td>
<td class="bits"><span class="free">OOOO OOOO</span></td>
- <td class="bits">XXXX XXXX</td>
+ <td class="bits"><span class="free">OOOO OOOO</span></td>
<td class="bits">XX<span class="free">OO OO</span>XX</td>
<td class="bits">XXXX XXXX</td>
</tr>
diff --git a/src/newgrf_object.cpp b/src/newgrf_object.cpp
index 1db4b02c6..8eaff1385 100644
--- a/src/newgrf_object.cpp
+++ b/src/newgrf_object.cpp
@@ -190,7 +190,7 @@ static uint32 GetClosestObject(TileIndex tile, ObjectType type, const Object *cu
uint32 best_dist = UINT32_MAX;
const Object *o;
FOR_ALL_OBJECTS(o) {
- if (GetObjectType(o->location.tile) != type || o == current) continue;
+ if (o->type != type || o == current) continue;
best_dist = min(best_dist, DistanceManhattan(tile, o->location.tile));
}
diff --git a/src/object_base.h b/src/object_base.h
index 8f3ddb1b4..676fc9c9c 100644
--- a/src/object_base.h
+++ b/src/object_base.h
@@ -23,6 +23,7 @@ extern ObjectPool _object_pool;
/** An object, such as transmitter, on the map. */
struct Object : ObjectPool::PoolItem<&_object_pool> {
+ ObjectType type; ///< Type of the object
Town *town; ///< Town the object is built in
TileArea location; ///< Location of the object
Date build_date; ///< Date of construction
diff --git a/src/object_cmd.cpp b/src/object_cmd.cpp
index fb7b05286..e6100c78d 100644
--- a/src/object_cmd.cpp
+++ b/src/object_cmd.cpp
@@ -52,6 +52,18 @@ uint16 Object::counts[NUM_OBJECTS];
return Object::Get(GetObjectIndex(tile));
}
+/**
+ * Gets the ObjectType of the given object tile
+ * @param t the tile to get the type from.
+ * @pre IsTileType(t, MP_OBJECT)
+ * @return the type.
+ */
+ObjectType GetObjectType(TileIndex t)
+{
+ assert(IsTileType(t, MP_OBJECT));
+ return Object::GetByTile(t)->type;
+}
+
/** Initialize/reset the objects. */
void InitializeObjects()
{
@@ -74,6 +86,7 @@ void BuildObject(ObjectType type, TileIndex tile, CompanyID owner, Town *town, u
TileArea ta(tile, GB(spec->size, HasBit(view, 0) ? 4 : 0, 4), GB(spec->size, HasBit(view, 0) ? 0 : 4, 4));
Object *o = new Object();
+ o->type = type;
o->location = ta;
o->town = town == NULL ? CalcClosestTownFromTile(tile) : town;
o->build_date = _date;
@@ -108,7 +121,7 @@ void BuildObject(ObjectType type, TileIndex tile, CompanyID owner, Town *town, u
Company::Get(owner)->infrastructure.water++;
DirtyCompanyInfrastructureWindows(owner);
}
- MakeObject(t, type, owner, o->index, wc, Random());
+ MakeObject(t, owner, o->index, wc, Random());
MarkTileDirtyByTile(t);
}
@@ -417,7 +430,7 @@ static Foundation GetFoundation_Object(TileIndex tile, Slope tileh)
*/
static void ReallyClearObjectTile(Object *o)
{
- Object::DecTypeCount(GetObjectType(o->location.tile));
+ Object::DecTypeCount(o->type);
TILE_AREA_LOOP(tile_cur, o->location) {
DeleteNewGRFInspectWindow(GSF_OBJECTS, tile_cur);
@@ -447,13 +460,13 @@ ClearedObjectArea *FindClearedObject(TileIndex tile)
static CommandCost ClearTile_Object(TileIndex tile, DoCommandFlag flags)
{
- ObjectType type = GetObjectType(tile);
- const ObjectSpec *spec = ObjectSpec::Get(type);
-
/* Get to the northern most tile. */
Object *o = Object::GetByTile(tile);
TileArea ta = o->location;
+ ObjectType type = o->type;
+ const ObjectSpec *spec = ObjectSpec::Get(type);
+
CommandCost cost(EXPENSES_CONSTRUCTION, spec->GetClearCost() * ta.w * ta.h / 5);
if (spec->flags & OBJECT_FLAG_CLEAR_INCOME) cost.MultiplyCost(-1); // They get an income!
diff --git a/src/object_map.h b/src/object_map.h
index 7af58d27c..3c185b14b 100644
--- a/src/object_map.h
+++ b/src/object_map.h
@@ -15,17 +15,7 @@
#include "water_map.h"
#include "object_type.h"
-/**
- * Gets the ObjectType of the given object tile
- * @param t the tile to get the type from.
- * @pre IsTileType(t, MP_OBJECT)
- * @return the type.
- */
-static inline ObjectType GetObjectType(TileIndex t)
-{
- assert(IsTileType(t, MP_OBJECT));
- return (ObjectType)_m[t].m5;
-}
+ObjectType GetObjectType(TileIndex t);
/**
* Check whether the object on a tile is of a specific type.
@@ -77,15 +67,13 @@ static inline byte GetObjectRandomBits(TileIndex t)
/**
* Make an Object tile.
- * @note do not use this function directly. Use one of the other Make* functions.
* @param t The tile to make and object tile.
- * @param u The object type of the tile.
* @param o The new owner of the tile.
* @param index Index to the object.
* @param wc Water class for this object.
* @param random Random data to store on the tile
*/
-static inline void MakeObject(TileIndex t, ObjectType u, Owner o, ObjectID index, WaterClass wc, byte random)
+static inline void MakeObject(TileIndex t, Owner o, ObjectID index, WaterClass wc, byte random)
{
SetTileType(t, MP_OBJECT);
SetTileOwner(t, o);
@@ -93,7 +81,7 @@ static inline void MakeObject(TileIndex t, ObjectType u, Owner o, ObjectID index
_m[t].m2 = index;
_m[t].m3 = random;
_m[t].m4 = 0;
- _m[t].m5 = u;
+ _m[t].m5 = 0;
SB(_m[t].m6, 2, 4, 0);
_me[t].m7 = 0;
}
diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp
index 4643530aa..5f56b0a08 100644
--- a/src/saveload/afterload.cpp
+++ b/src/saveload/afterload.cpp
@@ -248,6 +248,12 @@ static void InitializeWindowsAndCaches()
}
}
+ /* Count number of objects per type */
+ Object *o;
+ FOR_ALL_OBJECTS(o) {
+ Object::IncTypeCount(o->type);
+ }
+
RecomputePrices();
GroupStatistics::UpdateAfterLoad();
@@ -1444,7 +1450,7 @@ bool AfterLoadGame()
if (IsSavegameVersionBefore(52)) {
for (TileIndex t = 0; t < map_size; t++) {
- if (IsTileType(t, MP_OBJECT) && GetObjectType(t) == OBJECT_STATUE) {
+ if (IsTileType(t, MP_OBJECT) && _m[t].m5 == OBJECT_STATUE) {
_m[t].m2 = CalcClosestTownFromTile(t)->index;
}
}
@@ -1940,7 +1946,7 @@ bool AfterLoadGame()
if (!IsTileType(t, MP_OBJECT)) continue;
/* Reordering/generalisation of the object bits. */
- ObjectType type = GetObjectType(t);
+ ObjectType type = _m[t].m5;
SB(_m[t].m6, 2, 4, type == OBJECT_HQ ? GB(_m[t].m3, 2, 3) : 0);
_m[t].m3 = type == OBJECT_HQ ? GB(_m[t].m3, 1, 1) | GB(_m[t].m3, 0, 1) << 4 : 0;
@@ -1967,7 +1973,7 @@ bool AfterLoadGame()
if (offset == 0) {
/* No offset, so make the object. */
- ObjectType type = GetObjectType(t);
+ ObjectType type = _m[t].m5;
int size = type == OBJECT_HQ ? 2 : 1;
if (!Object::CanAllocateItem()) {
@@ -2200,11 +2206,6 @@ bool AfterLoadGame()
}
}
- if (IsSavegameVersionBefore(127)) {
- Station *st;
- FOR_ALL_STATIONS(st) UpdateStationAcceptance(st, false);
- }
-
if (IsSavegameVersionBefore(128)) {
const Depot *d;
FOR_ALL_DEPOTS(d) {
@@ -2814,6 +2815,25 @@ bool AfterLoadGame()
_settings_game.locale.units_height = Clamp(_old_units, 0, 2);
}
+ if (IsSavegameVersionBefore(185)) {
+ /* Move ObjectType from map to pool */
+ for (TileIndex t = 0; t < map_size; t++) {
+ if (IsTileType(t, MP_OBJECT)) {
+ Object *o = Object::GetByTile(t);
+ o->type = _m[t].m5;
+ _m[t].m5 = 0; // cleanup for next usage
+ }
+ }
+ }
+
+
+
+ /* Station acceptance is some kind of cache */
+ if (IsSavegameVersionBefore(127)) {
+ Station *st;
+ FOR_ALL_STATIONS(st) UpdateStationAcceptance(st, false);
+ }
+
/* Road stops is 'only' updating some caches */
AfterLoadRoadStops();
AfterLoadLabelMaps();
diff --git a/src/saveload/object_sl.cpp b/src/saveload/object_sl.cpp
index 037fc6b4d..4e8539793 100644
--- a/src/saveload/object_sl.cpp
+++ b/src/saveload/object_sl.cpp
@@ -24,6 +24,7 @@ static const SaveLoad _object_desc[] = {
SLE_VAR(Object, build_date, SLE_UINT32),
SLE_CONDVAR(Object, colour, SLE_UINT8, 148, SL_MAX_VERSION),
SLE_CONDVAR(Object, view, SLE_UINT8, 155, SL_MAX_VERSION),
+ SLE_CONDVAR(Object, type, SLE_UINT16, 186, SL_MAX_VERSION),
SLE_END()
};
@@ -56,8 +57,6 @@ static void Ptrs_OBJS()
if (IsSavegameVersionBefore(148) && !IsTileType(o->location.tile, MP_OBJECT)) {
/* Due to a small bug stale objects could remain. */
delete o;
- } else {
- Object::IncTypeCount(GetObjectType(o->location.tile));
}
}
}
diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp
index 8f58ea381..086dd41f3 100644
--- a/src/saveload/saveload.cpp
+++ b/src/saveload/saveload.cpp
@@ -251,8 +251,9 @@
* 183 25363
* 184 25508
* 185 25620
+ * 186 TODO
*/
-extern const uint16 SAVEGAME_VERSION = 185; ///< Current savegame version of OpenTTD.
+extern const uint16 SAVEGAME_VERSION = 186; ///< Current savegame version of OpenTTD.
SavegameType _savegame_type; ///< type of savegame we are loading
diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp
index e16ff4836..1430656a9 100644
--- a/src/town_cmd.cpp
+++ b/src/town_cmd.cpp
@@ -2635,7 +2635,7 @@ CommandCost CmdDeleteTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
} else {
Object *o = Object::GetByTile(tile);
if (o->town == t) {
- if (GetObjectType(tile) == OBJECT_STATUE) {
+ if (o->type == OBJECT_STATUE) {
/* Statue... always remove. */
try_clear = true;
} else {