changeset 11010:080a2d6125ed draft

(svn r15350) -Codechange: Create a spec array to hold the data definitions of unmovables objects. Note that this is the very basic spec, it will be populated a bit more, later.
author belugas <belugas@openttd.org>
date Thu, 05 Feb 2009 03:41:42 +0000
parents 8c1eace0f5bb
children fb38fb72b850
files src/table/unmovable_land.h src/unmovable.h src/unmovable_cmd.cpp
diffstat 3 files changed, 33 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/table/unmovable_land.h
+++ b/src/table/unmovable_land.h
@@ -92,3 +92,11 @@
 };
 
 #undef TILE_SPRITE_LINE
+
+static const UnmovableSpec _original_unmovable[] = {
+	{STR_5801_TRANSMITTER,          1,   1},
+	{STR_5802_LIGHTHOUSE,           1,   1},
+	{STR_2016_STATUE,               1,   1},
+	{STR_5805_COMPANY_OWNED_LAND,   10,  2},
+	{STR_5803_COMPANY_HEADQUARTERS, 1,   1},
+};
--- a/src/unmovable.h
+++ b/src/unmovable.h
@@ -5,6 +5,27 @@
 #ifndef UNMOVABLE_H
 #define UNMOVABLE_H
 
+#include "unmovable_map.h"
+#include "economy_type.h"
+#include "economy_func.h"
+
 void UpdateCompanyHQ(Company *c, uint score);
 
+struct UnmovableSpec {
+	StringID name;
+	uint8 buy_cost_multiplier;
+	uint8 sell_cost_multiplier;
+
+	Money GetRemovalCost() const { return (_price.clear_roughland * this->sell_cost_multiplier); }
+	Money GetBuildingCost() const { return (_price.clear_roughland * this->buy_cost_multiplier); }
+
+};
+
+extern const UnmovableSpec _original_unmovable[];
+
+static inline const UnmovableSpec *GetUnmovableSpec(UnmovableType type)
+{
+	return &_original_unmovable[type];
+}
+
 #endif /* UNMOVABLE_H */
--- a/src/unmovable_cmd.cpp
+++ b/src/unmovable_cmd.cpp
@@ -22,6 +22,7 @@
 #include "economy_func.h"
 #include "cheat_type.h"
 #include "landscape_type.h"
+#include "unmovable.h"
 
 #include "table/strings.h"
 #include "table/sprites.h"
@@ -132,7 +133,7 @@
 		MarkTileDirtyByTile(tile);
 	}
 
-	return cost.AddCost(_price.clear_roughland * 10);
+	return cost.AddCost(GetUnmovableSpec(UNMOVABLE_OWNED_LAND)->GetBuildingCost());
 }
 
 /** Sell a land area. Actually you only sell one tile, so
@@ -152,7 +153,7 @@
 
 	if (flags & DC_EXEC) DoClearSquare(tile);
 
-	return CommandCost(EXPENSES_CONSTRUCTION, - _price.clear_roughland * 2);
+	return CommandCost(EXPENSES_CONSTRUCTION, - GetUnmovableSpec(UNMOVABLE_OWNED_LAND)->GetRemovalCost());
 }
 
 static Foundation GetFoundation_Unmovable(TileIndex tile, Slope tileh);
@@ -300,13 +301,7 @@
 
 static void GetTileDesc_Unmovable(TileIndex tile, TileDesc *td)
 {
-	switch (GetUnmovableType(tile)) {
-		case UNMOVABLE_TRANSMITTER: td->str = STR_5801_TRANSMITTER; break;
-		case UNMOVABLE_LIGHTHOUSE:  td->str = STR_5802_LIGHTHOUSE; break;
-		case UNMOVABLE_STATUE:      td->str = STR_2016_STATUE; break;
-		case UNMOVABLE_OWNED_LAND:  td->str = STR_5805_COMPANY_OWNED_LAND; break;
-		default:                    td->str = STR_5803_COMPANY_HEADQUARTERS; break;
-	}
+	td->str = GetUnmovableSpec(GetUnmovableType(tile))->name;
 	td->owner[0] = GetTileOwner(tile);
 }