src/command.cpp
branchNewGRF_ports
changeset 6872 1c4a4a609f85
parent 6871 5a9dc001e1ad
child 6877 889301acc299
--- a/src/command.cpp	Mon Dec 03 23:39:38 2007 +0000
+++ b/src/command.cpp	Tue Jan 22 21:00:30 2008 +0000
@@ -4,20 +4,28 @@
 
 #include "stdafx.h"
 #include "openttd.h"
-#include "table/strings.h"
-#include "strings.h"
-#include "functions.h"
 #include "landscape.h"
-#include "map.h"
+#include "tile_map.h"
 #include "gui.h"
-#include "command.h"
-#include "player.h"
+#include "command_func.h"
 #include "network/network.h"
 #include "variables.h"
 #include "genworld.h"
 #include "newgrf_storage.h"
+#include "strings_func.h"
+#include "gfx_func.h"
+#include "functions.h"
+#include "town.h"
+#include "date_func.h"
+#include "debug.h"
+#include "player_func.h"
+#include "player_base.h"
+#include "signal_func.h"
+
+#include "table/strings.h"
 
 const char *_cmd_text = NULL;
+StringID _error_message;
 
 /**
  * Helper macro to define the header of all command handler macros.
@@ -387,7 +395,7 @@
 	return _command_proc_table[cmd & 0xFF].flags;
 }
 
-static int _docommand_recursive;
+static int _docommand_recursive = 0;
 
 /*!
  * This function executes a given command with the parameters from the #CommandProc parameter list.
@@ -400,7 +408,7 @@
  * @param procc The command-id to execute (a value of the CMD_* enums)
  * @see CommandProc
  */
-CommandCost DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc)
+CommandCost DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint32 procc)
 {
 	CommandCost res;
 	CommandProc *proc;
@@ -419,7 +427,9 @@
 
 	/* only execute the test call if it's toplevel, or we're not execing. */
 	if (_docommand_recursive == 1 || !(flags & DC_EXEC) || (flags & DC_FORCETEST) ) {
+		SetTownRatingTestMode(true);
 		res = proc(tile, flags & ~DC_EXEC, p1, p2);
+		SetTownRatingTestMode(false);
 		if (CmdFailed(res)) {
 			res.SetGlobalErrorMessage();
 			goto error;
@@ -440,7 +450,7 @@
 	}
 
 	/* Execute the command here. All cost-relevant functions set the expenses type
-	 * themselves with "SET_EXPENSES_TYPE(...);" at the beginning of the function */
+	 * themselves to the cost object at some point */
 	res = proc(tile, flags, p1, p2);
 	if (CmdFailed(res)) {
 		res.SetGlobalErrorMessage();
@@ -539,7 +549,7 @@
 	 *  e.g.: if you demolish a whole town, the dryrun would say okay.
 	 *  but by really destroying, your rating drops and at a certain point
 	 *  it will fail. so res and res2 are different
-	 * CMD_REMOVE_ROAD: This command has special local authority
+	 * CMD_REMOVE_LONG_ROAD: This command has special local authority
 	 * restrictions which may cause the test run to fail (the previous
 	 * road fragments still stay there and the town won't let you
 	 * disconnect the road system), but the exec will succeed and this
@@ -549,9 +559,7 @@
 	 * estimate the cost of cloning a vehicle. */
 	notest =
 		(cmd & 0xFF) == CMD_CLEAR_AREA ||
-		(cmd & 0xFF) == CMD_CONVERT_RAIL ||
 		(cmd & 0xFF) == CMD_LEVEL_LAND ||
-		(cmd & 0xFF) == CMD_REMOVE_ROAD ||
 		(cmd & 0xFF) == CMD_REMOVE_LONG_ROAD ||
 		(cmd & 0xFF) == CMD_CLONE_VEHICLE;
 
@@ -581,7 +589,9 @@
 
 	if (!((cmd & CMD_NO_TEST_IF_IN_NETWORK) && _networking)) {
 		/* first test if the command can be executed. */
+		SetTownRatingTestMode(true);
 		res = proc(tile, flags, p1, p2);
+		SetTownRatingTestMode(false);
 		if (CmdFailed(res)) {
 			res.SetGlobalErrorMessage();
 			goto show_error;
@@ -609,6 +619,7 @@
 		return true;
 	}
 #endif /* ENABLE_NETWORK */
+	DebugDumpCommands("ddc:cmd:%d;%d;%d;%d;%d;%d;%d;%s\n", _date, _date_fract, (int)_current_player, tile, p1, p2, cmd, _cmd_text);
 
 	/* update last build coordinate of player. */
 	if (tile != 0 && IsValidPlayer(_current_player)) {
@@ -617,7 +628,6 @@
 
 	/* Actually try and execute the command. If no cost-type is given
 	 * use the construction one */
-	_yearly_expenses_type = EXPENSES_CONSTRUCTION;
 	res2 = proc(tile, flags | DC_EXEC, p1, p2);
 
 	/* If notest is on, it means the result of the test can be different than
@@ -633,6 +643,9 @@
 
 	SubtractMoneyFromPlayer(res2);
 
+	/* update signals if needed */
+	UpdateSignalsInBuffer();
+
 	if (IsLocalPlayer() && _game_mode != GM_EDITOR) {
 		if (res2.GetCost() != 0 && tile != 0) ShowCostOrIncomeAnimation(x, y, GetSlopeZ(x, y), res2.GetCost());
 		if (_additional_cash_required != 0) {
@@ -692,6 +705,11 @@
 	return this->cost;
 }
 
+ExpensesType CommandCost::GetExpensesType() const
+{
+	return this->expense_type;
+}
+
 void CommandCost::SetGlobalErrorMessage() const
 {
 	extern StringID _error_message;