src/autoreplace_cmd.cpp
branchgamebalance
changeset 9913 e79cd19772dd
parent 9912 1ac8aac92385
equal deleted inserted replaced
9912:1ac8aac92385 9913:e79cd19772dd
   122  * Must be called with _current_player set to the owner of the vehicle
   122  * Must be called with _current_player set to the owner of the vehicle
   123  * @param w Vehicle to replace
   123  * @param w Vehicle to replace
   124  * @param flags is the flags to use when calling DoCommand(). Mainly DC_EXEC counts
   124  * @param flags is the flags to use when calling DoCommand(). Mainly DC_EXEC counts
   125  * @return value is cost of the replacement or CMD_ERROR
   125  * @return value is cost of the replacement or CMD_ERROR
   126  */
   126  */
   127 static int32 ReplaceVehicle(Vehicle **w, byte flags, int32 total_cost)
   127 static CommandCost ReplaceVehicle(Vehicle **w, byte flags, int32 total_cost)
   128 {
   128 {
   129 	int32 cost;
   129 	CommandCost cost;
   130 	int32 sell_value;
   130 	CommandCost sell_value;
   131 	Vehicle *old_v = *w;
   131 	Vehicle *old_v = *w;
   132 	const Player *p = GetPlayer(old_v->owner);
   132 	const Player *p = GetPlayer(old_v->owner);
   133 	EngineID new_engine_type;
   133 	EngineID new_engine_type;
   134 	const UnitID cached_unitnumber = old_v->unitnumber;
   134 	const UnitID cached_unitnumber = old_v->unitnumber;
   135 	bool new_front = false;
   135 	bool new_front = false;
   171 		return cost;
   171 		return cost;
   172 	}
   172 	}
   173 
   173 
   174 	if (replacement_cargo_type != CT_NO_REFIT) {
   174 	if (replacement_cargo_type != CT_NO_REFIT) {
   175 		/* add refit cost */
   175 		/* add refit cost */
   176 		int32 refit_cost = GetRefitCost(new_engine_type);
   176 		CommandCost refit_cost = GetRefitCost(new_engine_type);
   177 		if (old_v->type == VEH_TRAIN && IsMultiheaded(old_v)) refit_cost += refit_cost; // pay for both ends
   177 		if (old_v->type == VEH_TRAIN && IsMultiheaded(old_v)) refit_cost += refit_cost; // pay for both ends
   178 		cost += refit_cost;
   178 		cost += refit_cost;
   179 	}
   179 	}
   180 
   180 
   181 	if (flags & DC_EXEC) {
   181 	if (flags & DC_EXEC) {
   244 			vehicle_name[0] = '\0';
   244 			vehicle_name[0] = '\0';
   245 		} else {
   245 		} else {
   246 			GetName(vehicle_name, old_v->string_id & 0x7FF, lastof(vehicle_name));
   246 			GetName(vehicle_name, old_v->string_id & 0x7FF, lastof(vehicle_name));
   247 		}
   247 		}
   248 	} else { // flags & DC_EXEC not set
   248 	} else { // flags & DC_EXEC not set
   249 		int32 tmp_move = 0;
   249 		CommandCost tmp_move = 0;
   250 		if (old_v->type == VEH_TRAIN && IsFrontEngine(old_v) && old_v->next != NULL) {
   250 		if (old_v->type == VEH_TRAIN && IsFrontEngine(old_v) && old_v->next != NULL) {
   251 			/* Verify that the wagons can be placed on the engine in question.
   251 			/* Verify that the wagons can be placed on the engine in question.
   252 			 * This is done by building an engine, test if the wagons can be added and then sell the test engine. */
   252 			 * This is done by building an engine, test if the wagons can be added and then sell the test engine. */
   253 			DoCommand(old_v->tile, new_engine_type, 3, DC_EXEC, GetCmdBuildVeh(old_v));
   253 			DoCommand(old_v->tile, new_engine_type, 3, DC_EXEC, GetCmdBuildVeh(old_v));
   254 			Vehicle *temp = GetVehicle(_new_vehicle_id);
   254 			Vehicle *temp = GetVehicle(_new_vehicle_id);
   293  * if the vehicle is a train, v needs to be the front engine
   293  * if the vehicle is a train, v needs to be the front engine
   294  * @param check Checks if the replace is valid. No action is done at all
   294  * @param check Checks if the replace is valid. No action is done at all
   295  * @param display_costs If set, a cost animation is shown (only if check is false)
   295  * @param display_costs If set, a cost animation is shown (only if check is false)
   296  * @return CMD_ERROR if something went wrong. Otherwise the price of the replace
   296  * @return CMD_ERROR if something went wrong. Otherwise the price of the replace
   297  */
   297  */
   298 int32 MaybeReplaceVehicle(Vehicle *v, bool check, bool display_costs)
   298 CommandCost MaybeReplaceVehicle(Vehicle *v, bool check, bool display_costs)
   299 {
   299 {
   300 	Vehicle *w;
   300 	Vehicle *w;
   301 	const Player *p = GetPlayer(v->owner);
   301 	const Player *p = GetPlayer(v->owner);
   302 	byte flags = 0;
   302 	byte flags = 0;
   303 	int32 cost, temp_cost = 0;
   303 	CommandCost cost, temp_cost = 0;
   304 	bool stopped;
   304 	bool stopped;
   305 
   305 
   306 	/* Remember the length in case we need to trim train later on
   306 	/* Remember the length in case we need to trim train later on
   307 	 * If it's not a train, the value is unused
   307 	 * If it's not a train, the value is unused
   308 	 * round up to the length of the tiles used for the train instead of the train length instead
   308 	 * round up to the length of the tiles used for the train instead of the train length instead