Changeset - r8680:3232a99af2b8
[Not reviewed]
master
0 2 0
frosch - 16 years ago 2008-03-06 10:39:26
frosch@openttd.org
(svn r12346) -Fix [FS#1748, FS#1825](r9874, r11872): Remove duplicated and inconsistent code wrt. autoreplace with rules in both vehicles' group and ALL_GROUP.
2 files changed with 5 insertions and 29 deletions:
0 comments (0 inline, 0 general)
src/autoreplace_cmd.cpp
Show inline comments
 
@@ -137,24 +137,15 @@ static CommandCost ReplaceVehicle(Vehicl
 
	const UnitID cached_unitnumber = old_v->unitnumber;
 
	bool new_front = false;
 
	Vehicle *new_v = NULL;
 
	char *vehicle_name = NULL;
 
	CargoID replacement_cargo_type;
 

	
 
	/* If the vehicle belongs to a group, check if the group is protected from the global autoreplace.
 
	 *  If not, chek if an global auto replacement is defined */
 
	new_engine_type = (IsValidGroupID(old_v->group_id) && GetGroup(old_v->group_id)->replace_protection) ?
 
			INVALID_ENGINE :
 
			EngineReplacementForPlayer(p, old_v->engine_type, ALL_GROUP);
 

	
 
	/* If we don't set new_egnine_type previously, we try to check if an autoreplacement was defined
 
	 *  for the group and the engine_type of the vehicle */
 
	if (new_engine_type == INVALID_ENGINE && !IsAllGroupID(old_v->group_id)) {
 
		new_engine_type = EngineReplacementForPlayer(p, old_v->engine_type, old_v->group_id);
 
	}
 

	
 
	/* Check if there is a autoreplacement set for the vehicle */
 
	new_engine_type = EngineReplacementForPlayer(p, old_v->engine_type, old_v->group_id);
 
	/* if not, just renew to the same type */
 
	if (new_engine_type == INVALID_ENGINE) new_engine_type = old_v->engine_type;
 

	
 
	replacement_cargo_type = GetNewCargoTypeForReplace(old_v, new_engine_type);
 

	
 
	/* check if we can't refit to the needed type, so no replace takes place to prevent the vehicle from altering cargo type */
 
	if (replacement_cargo_type == CT_INVALID) return CommandCost();
 
@@ -342,28 +333,13 @@ CommandCost MaybeReplaceVehicle(Vehicle 
 
				continue;
 
			}
 

	
 
			// check if the vehicle should be replaced
 
			if (!w->NeedsAutorenewing(p) || // replace if engine is too old
 
					w->max_age == 0) { // rail cars got a max age of 0
 
				/* If the vehicle belongs to a group, check if the group is protected from the global autoreplace.
 
				   If not, chek if an global auto remplacement is defined */
 
				if (IsValidGroupID(w->group_id)) {
 
					if (!EngineHasReplacementForPlayer(p, w->engine_type, w->group_id) && (
 
							GetGroup(w->group_id)->replace_protection ||
 
							!EngineHasReplacementForPlayer(p, w->engine_type, ALL_GROUP))) {
 
						continue;
 
					}
 
				} else if (IsDefaultGroupID(w->group_id)) {
 
					if (!EngineHasReplacementForPlayer(p, w->engine_type, DEFAULT_GROUP) &&
 
							!EngineHasReplacementForPlayer(p, w->engine_type, ALL_GROUP)) {
 
						continue;
 
					}
 
				} else if (!EngineHasReplacementForPlayer(p, w->engine_type, ALL_GROUP)) {
 
					continue;
 
				}
 
				if (!EngineHasReplacementForPlayer(p, w->engine_type, w->group_id)) continue;
 
			}
 

	
 
			/* Now replace the vehicle */
 
			temp_cost = ReplaceVehicle(&w, flags, cost.GetCost());
 

	
 
			if (CmdFailed(temp_cost)) break; // replace failed for some reason. Leave the vehicle alone
src/group.h
Show inline comments
 
@@ -9,13 +9,13 @@
 
#include "player_type.h"
 
#include "vehicle_type.h"
 
#include "engine.h"
 

	
 
enum {
 
	ALL_GROUP     = 0xFFFD,
 
	DEFAULT_GROUP = 0xFFFE,
 
	DEFAULT_GROUP = 0xFFFE, ///< ungrouped vehicles are in this group.
 
	INVALID_GROUP = 0xFFFF,
 
};
 

	
 
struct Group;
 
DECLARE_OLD_POOL(Group, Group, 5, 2047)
 

	
0 comments (0 inline, 0 general)