src/unmovable_cmd.cpp
branchnoai
changeset 9723 eee46cb39750
parent 9722 ebf0ece7d8f6
child 9724 b39bc69bb2f2
--- a/src/unmovable_cmd.cpp	Fri Nov 23 16:59:30 2007 +0000
+++ b/src/unmovable_cmd.cpp	Wed Jan 09 18:11:12 2008 +0000
@@ -6,16 +6,13 @@
 #include "openttd.h"
 #include "table/strings.h"
 #include "table/sprites.h"
-#include "functions.h"
+#include "tile_cmd.h"
 #include "landscape.h"
-#include "map.h"
-#include "tile.h"
-#include "command.h"
-#include "viewport.h"
+#include "command_func.h"
+#include "viewport_func.h"
 #include "player.h"
 #include "gui.h"
 #include "station.h"
-#include "economy.h"
 #include "town.h"
 #include "sprite.h"
 #include "bridge_map.h"
@@ -26,6 +23,9 @@
 #include "bridge.h"
 #include "autoslope.h"
 #include "transparency.h"
+#include "functions.h"
+#include "window_func.h"
+#include "vehicle_func.h"
 
 /** Destroy a HQ.
  * During normal gameplay you can only implicitely destroy a HQ when you are
@@ -38,8 +38,6 @@
 {
 	Player* p = GetPlayer(pid);
 
-	SET_EXPENSES_TYPE(EXPENSES_PROPERTY);
-
 	if (flags & DC_EXEC) {
 		TileIndex t = p->location_of_house;
 
@@ -52,7 +50,7 @@
 	}
 
 	/* cost of relocating company is 1% of company value */
-	return CommandCost(CalculateCompanyValue(p) / 100);
+	return CommandCost(EXPENSES_PROPERTY, CalculateCompanyValue(p) / 100);
 }
 
 void UpdateCompanyHQ(Player *p, uint score)
@@ -87,9 +85,7 @@
 CommandCost CmdBuildCompanyHQ(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 {
 	Player *p = GetPlayer(_current_player);
-	CommandCost cost;
-
-	SET_EXPENSES_TYPE(EXPENSES_PROPERTY);
+	CommandCost cost(EXPENSES_PROPERTY);
 
 	cost = CheckFlatLandBelow(tile, 2, 2, flags, 0, NULL);
 	if (CmdFailed(cost)) return cost;
@@ -112,6 +108,54 @@
 	return cost;
 }
 
+/** Purchase a land area. Actually you only purchase one tile, so
+ * the name is a bit confusing ;p
+ * @param tile the tile the player is purchasing
+ * @param flags for this command type
+ * @param p1 unused
+ * @param p2 unused
+ * @return error of cost of operation
+ */
+CommandCost CmdPurchaseLandArea(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
+{
+	CommandCost cost(EXPENSES_CONSTRUCTION);
+
+	if (IsOwnedLandTile(tile) && IsTileOwner(tile, _current_player)) {
+		return_cmd_error(STR_5807_YOU_ALREADY_OWN_IT);
+	}
+
+	cost = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
+	if (CmdFailed(cost)) return CMD_ERROR;
+
+	if (flags & DC_EXEC) {
+		MakeOwnedLand(tile, _current_player);
+		MarkTileDirtyByTile(tile);
+	}
+
+	return cost.AddCost(_price.clear_roughland * 10);
+}
+
+/** Sell a land area. Actually you only sell one tile, so
+ * the name is a bit confusing ;p
+ * @param tile the tile the player is selling
+ * @param flags for this command type
+ * @param p1 unused
+ * @param p2 unused
+ * @return error or cost of operation
+ */
+CommandCost CmdSellLandArea(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
+{
+	if (!IsOwnedLandTile(tile)) return CMD_ERROR;
+	if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER) return CMD_ERROR;
+
+
+	if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
+
+	if (flags & DC_EXEC) DoClearSquare(tile);
+
+	return CommandCost(EXPENSES_CONSTRUCTION,- _price.clear_roughland * 2);
+}
+
 static Foundation GetFoundation_Unmovable(TileIndex tile, Slope tileh);
 
 static void DrawTile_Unmovable(TileInfo *ti)
@@ -411,7 +455,7 @@
 	if (IsOwnedLand(tile) && CheckTileOwnership(tile)) return CommandCost();
 
 	if (AutoslopeEnabled() && (IsStatue(tile) || IsCompanyHQ(tile))) {
-		if (!IsSteepSlope(tileh_new) && (z_new + GetSlopeMaxZ(tileh_new) == GetTileMaxZ(tile))) return _price.terraform;
+		if (!IsSteepSlope(tileh_new) && (z_new + GetSlopeMaxZ(tileh_new) == GetTileMaxZ(tile))) return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
 	}
 
 	return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);