(svn r13691) -Codechange: make it easier to determine whether a command is ran in the context of autoreplace or not
authorsmatz
Wed, 09 Jul 2008 20:55:47 +0000
changeset 11133 a75c67ae67b0
parent 11125 856f16065654
child 11134 c40cabfe69a5
(svn r13691) -Codechange: make it easier to determine whether a command is ran in the context of autoreplace or not
src/aircraft_cmd.cpp
src/autoreplace_cmd.cpp
src/command_type.h
src/roadveh_cmd.cpp
src/ship_cmd.cpp
src/train_cmd.cpp
--- a/src/aircraft_cmd.cpp	Wed Jul 09 02:18:51 2008 +0000
+++ b/src/aircraft_cmd.cpp	Wed Jul 09 20:55:47 2008 +0000
@@ -261,7 +261,7 @@
  * @param tile tile of depot where aircraft is built
  * @param flags for command
  * @param p1 aircraft type being built (engine)
- * @param p2 bit 0 when set, the unitnumber will be 0, otherwise it will be a free number
+ * @param p2 unused
  * return result of operation.  Could be cost, error
  */
 CommandCost CmdBuildAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
@@ -286,7 +286,7 @@
 		return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME);
 	}
 
-	UnitID unit_num = HasBit(p2, 0) ? 0 : GetFreeUnitNumber(VEH_AIRCRAFT);
+	UnitID unit_num = (flags & DC_AUTOREPLACE) ? 0 : GetFreeUnitNumber(VEH_AIRCRAFT);
 	if (unit_num > _settings_game.vehicle.max_aircraft)
 		return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME);
 
--- a/src/autoreplace_cmd.cpp	Wed Jul 09 02:18:51 2008 +0000
+++ b/src/autoreplace_cmd.cpp	Wed Jul 09 20:55:47 2008 +0000
@@ -128,7 +128,7 @@
  * @param new_engine_type The EngineID to replace to
  * @return value is cost of the replacement or CMD_ERROR
  */
-static CommandCost ReplaceVehicle(Vehicle **w, byte flags, Money total_cost, const Player *p, EngineID new_engine_type)
+static CommandCost ReplaceVehicle(Vehicle **w, uint32 flags, Money total_cost, const Player *p, EngineID new_engine_type)
 {
 	CommandCost cost;
 	CommandCost sell_value;
@@ -151,7 +151,7 @@
 	 * We take it back if building fails or when we really sell the old engine */
 	SubtractMoneyFromPlayer(sell_value);
 
-	cost = DoCommand(old_v->tile, new_engine_type, 3, flags, GetCmdBuildVeh(old_v));
+	cost = DoCommand(old_v->tile, new_engine_type, 0, flags | DC_AUTOREPLACE, GetCmdBuildVeh(old_v));
 	if (CmdFailed(cost)) {
 		/* Take back the money we just gave the player */
 		sell_value.MultiplyCost(-1);
@@ -259,7 +259,7 @@
 			if (next_veh != NULL) {
 				/* Verify that the wagons can be placed on the engine in question.
 				 * This is done by building an engine, test if the wagons can be added and then sell the test engine. */
-				DoCommand(old_v->tile, new_engine_type, 3, DC_EXEC, GetCmdBuildVeh(old_v));
+				DoCommand(old_v->tile, new_engine_type, 0, DC_EXEC | DC_AUTOREPLACE, GetCmdBuildVeh(old_v));
 				Vehicle *temp = GetVehicle(_new_vehicle_id);
 				tmp_move = DoCommand(0, (temp->index << 16) | next_veh->index, 1, 0, CMD_MOVE_RAIL_VEHICLE);
 				DoCommand(0, temp->index, 0, DC_EXEC, GetCmdSellVeh(old_v));
--- a/src/command_type.h	Wed Jul 09 02:18:51 2008 +0000
+++ b/src/command_type.h	Wed Jul 09 20:55:47 2008 +0000
@@ -286,14 +286,15 @@
  * This enums defines some flags which can be used for the commands.
  */
 enum {
-	DC_EXEC            = 0x01, ///< execute the given command
-	DC_AUTO            = 0x02, ///< don't allow building on structures
-	DC_QUERY_COST      = 0x04, ///< query cost only,  don't build.
-	DC_NO_WATER        = 0x08, ///< don't allow building on water
-	DC_NO_RAIL_OVERLAP = 0x10, ///< don't allow overlap of rails (used in buildrail)
-	DC_AI_BUILDING     = 0x20, ///< special building rules for AI
-	DC_NO_TOWN_RATING  = 0x40, ///< town rating does not disallow you from building
-	DC_BANKRUPT        = 0x80, ///< company bankrupts, skip money check, skip vehicle on tile check in some cases
+	DC_EXEC            = 0x001, ///< execute the given command
+	DC_AUTO            = 0x002, ///< don't allow building on structures
+	DC_QUERY_COST      = 0x004, ///< query cost only,  don't build.
+	DC_NO_WATER        = 0x008, ///< don't allow building on water
+	DC_NO_RAIL_OVERLAP = 0x010, ///< don't allow overlap of rails (used in buildrail)
+	DC_AI_BUILDING     = 0x020, ///< special building rules for AI
+	DC_NO_TOWN_RATING  = 0x040, ///< town rating does not disallow you from building
+	DC_BANKRUPT        = 0x080, ///< company bankrupts, skip money check, skip vehicle on tile check in some cases
+	DC_AUTOREPLACE     = 0x100, ///< autoreplace/autorenew is in progress
 };
 
 /**
--- a/src/roadveh_cmd.cpp	Wed Jul 09 02:18:51 2008 +0000
+++ b/src/roadveh_cmd.cpp	Wed Jul 09 20:55:47 2008 +0000
@@ -170,7 +170,7 @@
  * @param tile tile of depot where road vehicle is built
  * @param flags operation to perform
  * @param p1 bus/truck type being built (engine)
- * @param p2 bit 0 when set, the unitnumber will be 0, otherwise it will be a free number
+ * @param p2 unused
  */
 CommandCost CmdBuildRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 {
@@ -204,7 +204,7 @@
 	v = vl[0];
 
 	/* find the first free roadveh id */
-	unit_num = HasBit(p2, 0) ? 0 : GetFreeUnitNumber(VEH_ROAD);
+	unit_num = (flags & DC_AUTOREPLACE) ? 0 : GetFreeUnitNumber(VEH_ROAD);
 	if (unit_num > _settings_game.vehicle.max_roadveh)
 		return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME);
 
--- a/src/ship_cmd.cpp	Wed Jul 09 02:18:51 2008 +0000
+++ b/src/ship_cmd.cpp	Wed Jul 09 20:55:47 2008 +0000
@@ -748,7 +748,7 @@
  * @param tile tile of depot where ship is built
  * @param flags type of operation
  * @param p1 ship type being built (engine)
- * @param p2 bit 0 when set, the unitnumber will be 0, otherwise it will be a free number
+ * @param p2 unused
  */
 CommandCost CmdBuildShip(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 {
@@ -766,7 +766,7 @@
 	if (!IsShipDepotTile(tile)) return CMD_ERROR;
 	if (!IsTileOwner(tile, _current_player)) return CMD_ERROR;
 
-	unit_num = HasBit(p2, 0) ? 0 : GetFreeUnitNumber(VEH_SHIP);
+	unit_num = (flags & DC_AUTOREPLACE) ? 0 : GetFreeUnitNumber(VEH_SHIP);
 
 	if (!Vehicle::AllocateList(NULL, 1) || unit_num > _settings_game.vehicle.max_ships)
 		return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME);
--- a/src/train_cmd.cpp	Wed Jul 09 02:18:51 2008 +0000
+++ b/src/train_cmd.cpp	Wed Jul 09 20:55:47 2008 +0000
@@ -685,8 +685,7 @@
  * @param tile tile of the depot where rail-vehicle is built
  * @param flags type of operation
  * @param p1 engine type id
- * @param p2 bit 0 when set, the train will get number 0, otherwise it will get a free number
- *           bit 1 prevents any free cars from being added to the train
+ * @param p2 bit 1 prevents any free cars from being added to the train
  */
 CommandCost CmdBuildRailVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 {
@@ -725,7 +724,7 @@
 
 		Vehicle *v = vl[0];
 
-		UnitID unit_num = HasBit(p2, 0) ? 0 : GetFreeUnitNumber(VEH_TRAIN);
+		UnitID unit_num = (flags & DC_AUTOREPLACE) ? 0 : GetFreeUnitNumber(VEH_TRAIN);
 		if (unit_num > _settings_game.vehicle.max_trains)
 			return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME);
 
@@ -798,7 +797,7 @@
 			TrainConsistChanged(v);
 			UpdateTrainGroupID(v);
 
-			if (!HasBit(p2, 1)) { // check if the cars should be added to the new vehicle
+			if (!HasBit(p2, 1) && !(flags & DC_AUTOREPLACE)) { // check if the cars should be added to the new vehicle
 				NormalizeTrainVehInDepot(v);
 			}