summaryrefslogtreecommitdiff
path: root/src/object_cmd.cpp
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2013-10-12 16:30:42 +0000
committerfrosch <frosch@openttd.org>2013-10-12 16:30:42 +0000
commit35d7e8bca4e24bc211ed24d07fba62193d5f5f31 (patch)
tree5bd7a702966ef90ce1c815b3d73d380e6be0e628 /src/object_cmd.cpp
parent2080a8c16ff4190a8a32f6f3618323f2d3671f5c (diff)
downloadopenttd-35d7e8bca4e24bc211ed24d07fba62193d5f5f31.tar.xz
(svn r25833) -Codechange: Move ObjectType from map array into pool item.
Diffstat (limited to 'src/object_cmd.cpp')
-rw-r--r--src/object_cmd.cpp23
1 files changed, 18 insertions, 5 deletions
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!