mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r25833) -Codechange: Move ObjectType from map array into pool item.
This commit is contained in:
parent
2080a8c16f
commit
35d7e8bca4
|
@ -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>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>m2: index into the array of objects
|
||||||
<li>m3: random bits
|
<li>m3: random bits
|
||||||
<li>m5: tile type:
|
|
||||||
<table>
|
|
||||||
<tr>
|
|
||||||
<td nowrap valign=top><tt>00</tt> </td>
|
|
||||||
<td align=left>transmitter</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td nowrap valign=top><tt>01</tt> </td>
|
|
||||||
<td align=left>lighthouse</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td nowrap valign=top><tt>02</tt> </td>
|
|
||||||
<td align=left>company statue
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td nowrap valign=top><tt>03</tt> </td>
|
|
||||||
<td align=left>company-owned land</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td nowrap valign=top><tt>04</tt><tt></tt> </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 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>m6 bits 1..0 : <a href="#tropic_zone">Tropic zone definition</a></li>
|
||||||
<li>m7: animation counter
|
<li>m7: animation counter
|
||||||
|
|
|
@ -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 XXXX XXXX</td>
|
||||||
<td class="bits">XXXX XXXX</td>
|
<td class="bits">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">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">XX<span class="free">OO OO</span>XX</td>
|
||||||
<td class="bits">XXXX XXXX</td>
|
<td class="bits">XXXX XXXX</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
|
@ -190,7 +190,7 @@ static uint32 GetClosestObject(TileIndex tile, ObjectType type, const Object *cu
|
||||||
uint32 best_dist = UINT32_MAX;
|
uint32 best_dist = UINT32_MAX;
|
||||||
const Object *o;
|
const Object *o;
|
||||||
FOR_ALL_OBJECTS(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));
|
best_dist = min(best_dist, DistanceManhattan(tile, o->location.tile));
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ extern ObjectPool _object_pool;
|
||||||
|
|
||||||
/** An object, such as transmitter, on the map. */
|
/** An object, such as transmitter, on the map. */
|
||||||
struct Object : ObjectPool::PoolItem<&_object_pool> {
|
struct Object : ObjectPool::PoolItem<&_object_pool> {
|
||||||
|
ObjectType type; ///< Type of the object
|
||||||
Town *town; ///< Town the object is built in
|
Town *town; ///< Town the object is built in
|
||||||
TileArea location; ///< Location of the object
|
TileArea location; ///< Location of the object
|
||||||
Date build_date; ///< Date of construction
|
Date build_date; ///< Date of construction
|
||||||
|
|
|
@ -52,6 +52,18 @@ uint16 Object::counts[NUM_OBJECTS];
|
||||||
return Object::Get(GetObjectIndex(tile));
|
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. */
|
/** Initialize/reset the objects. */
|
||||||
void InitializeObjects()
|
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));
|
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();
|
Object *o = new Object();
|
||||||
|
o->type = type;
|
||||||
o->location = ta;
|
o->location = ta;
|
||||||
o->town = town == NULL ? CalcClosestTownFromTile(tile) : town;
|
o->town = town == NULL ? CalcClosestTownFromTile(tile) : town;
|
||||||
o->build_date = _date;
|
o->build_date = _date;
|
||||||
|
@ -108,7 +121,7 @@ void BuildObject(ObjectType type, TileIndex tile, CompanyID owner, Town *town, u
|
||||||
Company::Get(owner)->infrastructure.water++;
|
Company::Get(owner)->infrastructure.water++;
|
||||||
DirtyCompanyInfrastructureWindows(owner);
|
DirtyCompanyInfrastructureWindows(owner);
|
||||||
}
|
}
|
||||||
MakeObject(t, type, owner, o->index, wc, Random());
|
MakeObject(t, owner, o->index, wc, Random());
|
||||||
MarkTileDirtyByTile(t);
|
MarkTileDirtyByTile(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -417,7 +430,7 @@ static Foundation GetFoundation_Object(TileIndex tile, Slope tileh)
|
||||||
*/
|
*/
|
||||||
static void ReallyClearObjectTile(Object *o)
|
static void ReallyClearObjectTile(Object *o)
|
||||||
{
|
{
|
||||||
Object::DecTypeCount(GetObjectType(o->location.tile));
|
Object::DecTypeCount(o->type);
|
||||||
TILE_AREA_LOOP(tile_cur, o->location) {
|
TILE_AREA_LOOP(tile_cur, o->location) {
|
||||||
DeleteNewGRFInspectWindow(GSF_OBJECTS, tile_cur);
|
DeleteNewGRFInspectWindow(GSF_OBJECTS, tile_cur);
|
||||||
|
|
||||||
|
@ -447,13 +460,13 @@ ClearedObjectArea *FindClearedObject(TileIndex tile)
|
||||||
|
|
||||||
static CommandCost ClearTile_Object(TileIndex tile, DoCommandFlag flags)
|
static CommandCost ClearTile_Object(TileIndex tile, DoCommandFlag flags)
|
||||||
{
|
{
|
||||||
ObjectType type = GetObjectType(tile);
|
|
||||||
const ObjectSpec *spec = ObjectSpec::Get(type);
|
|
||||||
|
|
||||||
/* Get to the northern most tile. */
|
/* Get to the northern most tile. */
|
||||||
Object *o = Object::GetByTile(tile);
|
Object *o = Object::GetByTile(tile);
|
||||||
TileArea ta = o->location;
|
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);
|
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!
|
if (spec->flags & OBJECT_FLAG_CLEAR_INCOME) cost.MultiplyCost(-1); // They get an income!
|
||||||
|
|
||||||
|
|
|
@ -15,17 +15,7 @@
|
||||||
#include "water_map.h"
|
#include "water_map.h"
|
||||||
#include "object_type.h"
|
#include "object_type.h"
|
||||||
|
|
||||||
/**
|
ObjectType GetObjectType(TileIndex t);
|
||||||
* 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether the object on a tile is of a specific type.
|
* 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.
|
* 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 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 o The new owner of the tile.
|
||||||
* @param index Index to the object.
|
* @param index Index to the object.
|
||||||
* @param wc Water class for this object.
|
* @param wc Water class for this object.
|
||||||
* @param random Random data to store on the tile
|
* @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);
|
SetTileType(t, MP_OBJECT);
|
||||||
SetTileOwner(t, o);
|
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].m2 = index;
|
||||||
_m[t].m3 = random;
|
_m[t].m3 = random;
|
||||||
_m[t].m4 = 0;
|
_m[t].m4 = 0;
|
||||||
_m[t].m5 = u;
|
_m[t].m5 = 0;
|
||||||
SB(_m[t].m6, 2, 4, 0);
|
SB(_m[t].m6, 2, 4, 0);
|
||||||
_me[t].m7 = 0;
|
_me[t].m7 = 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -248,6 +248,12 @@ static void InitializeWindowsAndCaches()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Count number of objects per type */
|
||||||
|
Object *o;
|
||||||
|
FOR_ALL_OBJECTS(o) {
|
||||||
|
Object::IncTypeCount(o->type);
|
||||||
|
}
|
||||||
|
|
||||||
RecomputePrices();
|
RecomputePrices();
|
||||||
|
|
||||||
GroupStatistics::UpdateAfterLoad();
|
GroupStatistics::UpdateAfterLoad();
|
||||||
|
@ -1444,7 +1450,7 @@ bool AfterLoadGame()
|
||||||
|
|
||||||
if (IsSavegameVersionBefore(52)) {
|
if (IsSavegameVersionBefore(52)) {
|
||||||
for (TileIndex t = 0; t < map_size; t++) {
|
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;
|
_m[t].m2 = CalcClosestTownFromTile(t)->index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1940,7 +1946,7 @@ bool AfterLoadGame()
|
||||||
if (!IsTileType(t, MP_OBJECT)) continue;
|
if (!IsTileType(t, MP_OBJECT)) continue;
|
||||||
|
|
||||||
/* Reordering/generalisation of the object bits. */
|
/* 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);
|
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;
|
_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) {
|
if (offset == 0) {
|
||||||
/* No offset, so make the object. */
|
/* No offset, so make the object. */
|
||||||
ObjectType type = GetObjectType(t);
|
ObjectType type = _m[t].m5;
|
||||||
int size = type == OBJECT_HQ ? 2 : 1;
|
int size = type == OBJECT_HQ ? 2 : 1;
|
||||||
|
|
||||||
if (!Object::CanAllocateItem()) {
|
if (!Object::CanAllocateItem()) {
|
||||||
|
@ -2200,11 +2206,6 @@ bool AfterLoadGame()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsSavegameVersionBefore(127)) {
|
|
||||||
Station *st;
|
|
||||||
FOR_ALL_STATIONS(st) UpdateStationAcceptance(st, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (IsSavegameVersionBefore(128)) {
|
if (IsSavegameVersionBefore(128)) {
|
||||||
const Depot *d;
|
const Depot *d;
|
||||||
FOR_ALL_DEPOTS(d) {
|
FOR_ALL_DEPOTS(d) {
|
||||||
|
@ -2814,6 +2815,25 @@ bool AfterLoadGame()
|
||||||
_settings_game.locale.units_height = Clamp(_old_units, 0, 2);
|
_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 */
|
/* Road stops is 'only' updating some caches */
|
||||||
AfterLoadRoadStops();
|
AfterLoadRoadStops();
|
||||||
AfterLoadLabelMaps();
|
AfterLoadLabelMaps();
|
||||||
|
|
|
@ -24,6 +24,7 @@ static const SaveLoad _object_desc[] = {
|
||||||
SLE_VAR(Object, build_date, SLE_UINT32),
|
SLE_VAR(Object, build_date, SLE_UINT32),
|
||||||
SLE_CONDVAR(Object, colour, SLE_UINT8, 148, SL_MAX_VERSION),
|
SLE_CONDVAR(Object, colour, SLE_UINT8, 148, SL_MAX_VERSION),
|
||||||
SLE_CONDVAR(Object, view, SLE_UINT8, 155, 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()
|
SLE_END()
|
||||||
};
|
};
|
||||||
|
@ -56,8 +57,6 @@ static void Ptrs_OBJS()
|
||||||
if (IsSavegameVersionBefore(148) && !IsTileType(o->location.tile, MP_OBJECT)) {
|
if (IsSavegameVersionBefore(148) && !IsTileType(o->location.tile, MP_OBJECT)) {
|
||||||
/* Due to a small bug stale objects could remain. */
|
/* Due to a small bug stale objects could remain. */
|
||||||
delete o;
|
delete o;
|
||||||
} else {
|
|
||||||
Object::IncTypeCount(GetObjectType(o->location.tile));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -251,8 +251,9 @@
|
||||||
* 183 25363
|
* 183 25363
|
||||||
* 184 25508
|
* 184 25508
|
||||||
* 185 25620
|
* 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
|
SavegameType _savegame_type; ///< type of savegame we are loading
|
||||||
|
|
||||||
|
|
|
@ -2635,7 +2635,7 @@ CommandCost CmdDeleteTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
|
||||||
} else {
|
} else {
|
||||||
Object *o = Object::GetByTile(tile);
|
Object *o = Object::GetByTile(tile);
|
||||||
if (o->town == t) {
|
if (o->town == t) {
|
||||||
if (GetObjectType(tile) == OBJECT_STATUE) {
|
if (o->type == OBJECT_STATUE) {
|
||||||
/* Statue... always remove. */
|
/* Statue... always remove. */
|
||||||
try_clear = true;
|
try_clear = true;
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue