changeset 13221:4a355fe42b41 draft

(svn r17728) -Cleanup: Remove some more unneeded/unused parameters.
author frosch <frosch@openttd.org>
date Tue, 06 Oct 2009 19:52:38 +0000
parents d8ddc1b1e866
children ccca102feab4
files src/ai/api/ai_engine.cpp src/ai/api/ai_event_types.cpp src/articulated_vehicles.cpp src/articulated_vehicles.h src/autoreplace_cmd.cpp src/build_vehicle_gui.cpp src/engine_func.h src/engine_gui.cpp src/vehicle_gui.cpp
diffstat 9 files changed, 48 insertions(+), 47 deletions(-) [+]
line wrap: on
line diff
--- a/src/ai/api/ai_engine.cpp
+++ b/src/ai/api/ai_engine.cpp
@@ -75,7 +75,7 @@
 	switch (e->type) {
 		case VEH_ROAD:
 		case VEH_TRAIN: {
-			CargoArray capacities = GetCapacityOfArticulatedParts(engine_id, e->type);
+			CargoArray capacities = GetCapacityOfArticulatedParts(engine_id);
 			for (CargoID c = 0; c < NUM_CARGO; c++) {
 				if (capacities[c] == 0) continue;
 				return capacities[c];
--- a/src/ai/api/ai_event_types.cpp
+++ b/src/ai/api/ai_event_types.cpp
@@ -41,7 +41,7 @@
 	switch (e->type) {
 		case VEH_ROAD:
 		case VEH_TRAIN: {
-			CargoArray capacities = GetCapacityOfArticulatedParts(this->engine, e->type);
+			CargoArray capacities = GetCapacityOfArticulatedParts(this->engine);
 			for (CargoID c = 0; c < NUM_CARGO; c++) {
 				if (capacities[c] == 0) continue;
 				return capacities[c];
--- a/src/articulated_vehicles.cpp
+++ b/src/articulated_vehicles.cpp
@@ -81,23 +81,24 @@
 	return cargos;
 }
 
-CargoArray GetCapacityOfArticulatedParts(EngineID engine, VehicleType type)
+CargoArray GetCapacityOfArticulatedParts(EngineID engine)
 {
 	CargoArray capacity;
+	const Engine *e = Engine::Get(engine);
 
 	CargoID cargo_type;
 	uint16 cargo_capacity = GetVehicleDefaultCapacity(engine, &cargo_type);
 	if (cargo_type < NUM_CARGO) capacity[cargo_type] = cargo_capacity;
 
-	if (type != VEH_TRAIN && type != VEH_ROAD) return capacity;
+	if (e->type != VEH_TRAIN && e->type != VEH_ROAD) return capacity;
 
-	if (!HasBit(EngInfo(engine)->callback_mask, CBM_VEHICLE_ARTIC_ENGINE)) return capacity;
+	if (!HasBit(e->info.callback_mask, CBM_VEHICLE_ARTIC_ENGINE)) return capacity;
 
 	for (uint i = 1; i < MAX_ARTICULATED_PARTS; i++) {
 		uint16 callback = GetVehicleCallback(CBID_VEHICLE_ARTIC_ENGINE, i, 0, engine, NULL);
 		if (callback == CALLBACK_FAILED || GB(callback, 0, 8) == 0xFF) break;
 
-		EngineID artic_engine = GetNewEngineID(GetEngineGRF(engine), type, GB(callback, 0, 7));
+		EngineID artic_engine = GetNewEngineID(GetEngineGRF(engine), e->type, GB(callback, 0, 7));
 
 		cargo_capacity = GetVehicleDefaultCapacity(artic_engine, &cargo_type);
 		if (cargo_type < NUM_CARGO) capacity[cargo_type] += cargo_capacity;
@@ -134,23 +135,23 @@
 /**
  * Ors the refit_masks of all articulated parts.
  * @param engine the first part
- * @param type the vehicle type
  * @param include_initial_cargo_type if true the default cargo type of the vehicle is included; if false only the refit_mask
  * @return bit mask of CargoIDs which are a refit option for at least one articulated part
  */
-uint32 GetUnionOfArticulatedRefitMasks(EngineID engine, VehicleType type, bool include_initial_cargo_type)
+uint32 GetUnionOfArticulatedRefitMasks(EngineID engine, bool include_initial_cargo_type)
 {
+	const Engine *e = Engine::Get(engine);
 	uint32 cargos = GetAvailableVehicleCargoTypes(engine, include_initial_cargo_type);
 
-	if (type != VEH_TRAIN && type != VEH_ROAD) return cargos;
+	if (e->type != VEH_TRAIN && e->type != VEH_ROAD) return cargos;
 
-	if (!HasBit(EngInfo(engine)->callback_mask, CBM_VEHICLE_ARTIC_ENGINE)) return cargos;
+	if (!HasBit(e->info.callback_mask, CBM_VEHICLE_ARTIC_ENGINE)) return cargos;
 
 	for (uint i = 1; i < MAX_ARTICULATED_PARTS; i++) {
 		uint16 callback = GetVehicleCallback(CBID_VEHICLE_ARTIC_ENGINE, i, 0, engine, NULL);
 		if (callback == CALLBACK_FAILED || GB(callback, 0, 8) == 0xFF) break;
 
-		EngineID artic_engine = GetNewEngineID(GetEngineGRF(engine), type, GB(callback, 0, 7));
+		EngineID artic_engine = GetNewEngineID(GetEngineGRF(engine), e->type, GB(callback, 0, 7));
 		cargos |= GetAvailableVehicleCargoTypes(artic_engine, include_initial_cargo_type);
 	}
 
@@ -160,26 +161,26 @@
 /**
  * Ands the refit_masks of all articulated parts.
  * @param engine the first part
- * @param type the vehicle type
  * @param include_initial_cargo_type if true the default cargo type of the vehicle is included; if false only the refit_mask
  * @return bit mask of CargoIDs which are a refit option for every articulated part (with default capacity > 0)
  */
-uint32 GetIntersectionOfArticulatedRefitMasks(EngineID engine, VehicleType type, bool include_initial_cargo_type)
+uint32 GetIntersectionOfArticulatedRefitMasks(EngineID engine, bool include_initial_cargo_type)
 {
+	const Engine *e = Engine::Get(engine);
 	uint32 cargos = UINT32_MAX;
 
 	uint32 veh_cargos = GetAvailableVehicleCargoTypes(engine, include_initial_cargo_type);
 	if (veh_cargos != 0) cargos &= veh_cargos;
 
-	if (type != VEH_TRAIN && type != VEH_ROAD) return cargos;
+	if (e->type != VEH_TRAIN && e->type != VEH_ROAD) return cargos;
 
-	if (!HasBit(EngInfo(engine)->callback_mask, CBM_VEHICLE_ARTIC_ENGINE)) return cargos;
+	if (!HasBit(e->info.callback_mask, CBM_VEHICLE_ARTIC_ENGINE)) return cargos;
 
 	for (uint i = 1; i < MAX_ARTICULATED_PARTS; i++) {
 		uint16 callback = GetVehicleCallback(CBID_VEHICLE_ARTIC_ENGINE, i, 0, engine, NULL);
 		if (callback == CALLBACK_FAILED || GB(callback, 0, 8) == 0xFF) break;
 
-		EngineID artic_engine = GetNewEngineID(GetEngineGRF(engine), type, GB(callback, 0, 7));
+		EngineID artic_engine = GetNewEngineID(GetEngineGRF(engine), e->type, GB(callback, 0, 7));
 		veh_cargos = GetAvailableVehicleCargoTypes(artic_engine, include_initial_cargo_type);
 		if (veh_cargos != 0) cargos &= veh_cargos;
 	}
@@ -239,9 +240,9 @@
 {
 	const Engine *engine = Engine::Get(v->engine_type);
 
-	uint32 purchase_refit_union = GetUnionOfArticulatedRefitMasks(v->engine_type, v->type, true);
-	uint32 purchase_refit_intersection = GetIntersectionOfArticulatedRefitMasks(v->engine_type, v->type, true);
-	CargoArray purchase_default_capacity = GetCapacityOfArticulatedParts(v->engine_type, v->type);
+	uint32 purchase_refit_union = GetUnionOfArticulatedRefitMasks(v->engine_type, true);
+	uint32 purchase_refit_intersection = GetIntersectionOfArticulatedRefitMasks(v->engine_type, true);
+	CargoArray purchase_default_capacity = GetCapacityOfArticulatedParts(v->engine_type);
 
 	uint32 real_refit_union = 0;
 	uint32 real_refit_intersection = UINT_MAX;
--- a/src/articulated_vehicles.h
+++ b/src/articulated_vehicles.h
@@ -16,10 +16,10 @@
 #include "engine_type.h"
 
 uint CountArticulatedParts(EngineID engine_type, bool purchase_window);
-CargoArray GetCapacityOfArticulatedParts(EngineID engine, VehicleType type);
+CargoArray GetCapacityOfArticulatedParts(EngineID engine);
 void AddArticulatedParts(Vehicle *first);
-uint32 GetUnionOfArticulatedRefitMasks(EngineID engine, VehicleType type, bool include_initial_cargo_type);
-uint32 GetIntersectionOfArticulatedRefitMasks(EngineID engine, VehicleType type, bool include_initial_cargo_type);
+uint32 GetUnionOfArticulatedRefitMasks(EngineID engine, bool include_initial_cargo_type);
+uint32 GetIntersectionOfArticulatedRefitMasks(EngineID engine, bool include_initial_cargo_type);
 bool IsArticulatedVehicleCarryingDifferentCargos(const Vehicle *v, CargoID *cargo_type);
 bool IsArticulatedVehicleRefittable(EngineID engine);
 void CheckConsistencyOfArticulatedVehicle(const Vehicle *v);
--- a/src/autoreplace_cmd.cpp
+++ b/src/autoreplace_cmd.cpp
@@ -33,10 +33,10 @@
  * @param type the type of the engines
  * @return true if they can both carry the same type of cargo (or at least one of them got no capacity at all)
  */
-static bool EnginesGotCargoInCommon(EngineID engine_a, EngineID engine_b, VehicleType type)
+static bool EnginesHaveCargoInCommon(EngineID engine_a, EngineID engine_b)
 {
-	uint32 available_cargos_a = GetUnionOfArticulatedRefitMasks(engine_a, type, true);
-	uint32 available_cargos_b = GetUnionOfArticulatedRefitMasks(engine_b, type, true);
+	uint32 available_cargos_a = GetUnionOfArticulatedRefitMasks(engine_a, true);
+	uint32 available_cargos_b = GetUnionOfArticulatedRefitMasks(engine_b, true);
 	return (available_cargos_a == 0 || available_cargos_b == 0 || (available_cargos_a & available_cargos_b) != 0);
 }
 
@@ -87,7 +87,7 @@
 	}
 
 	/* the engines needs to be able to carry the same cargo */
-	return EnginesGotCargoInCommon(from, to, type);
+	return EnginesHaveCargoInCommon(from, to);
 }
 
 /** Transfer cargo from a single (articulated )old vehicle to the new vehicle chain
@@ -138,8 +138,8 @@
 	const Order *o;
 	const Vehicle *u;
 
-	uint32 union_refit_mask_a = GetUnionOfArticulatedRefitMasks(v->engine_type, v->type, false);
-	uint32 union_refit_mask_b = GetUnionOfArticulatedRefitMasks(engine_type, v->type, false);
+	uint32 union_refit_mask_a = GetUnionOfArticulatedRefitMasks(v->engine_type, false);
+	uint32 union_refit_mask_b = GetUnionOfArticulatedRefitMasks(engine_type, false);
 
 	if (v->type == VEH_TRAIN) {
 		u = v->First();
@@ -171,11 +171,11 @@
 {
 	CargoID cargo_type;
 
-	if (GetUnionOfArticulatedRefitMasks(engine_type, v->type, true) == 0) return CT_NO_REFIT; // Don't try to refit an engine with no cargo capacity
+	if (GetUnionOfArticulatedRefitMasks(engine_type, true) == 0) return CT_NO_REFIT; // Don't try to refit an engine with no cargo capacity
 
 	if (IsArticulatedVehicleCarryingDifferentCargos(v, &cargo_type)) return CT_INVALID; // We cannot refit to mixed cargos in an automated way
 
-	uint32 available_cargo_types = GetIntersectionOfArticulatedRefitMasks(engine_type, v->type, true);
+	uint32 available_cargo_types = GetIntersectionOfArticulatedRefitMasks(engine_type, true);
 
 	if (cargo_type == CT_INVALID) {
 		if (v->type != VEH_TRAIN) return CT_NO_REFIT; // If the vehicle does not carry anything at all, every replacement is fine.
@@ -190,7 +190,7 @@
 			/* Now we found a cargo type being carried on the train and we will see if it is possible to carry to this one */
 			if (HasBit(available_cargo_types, v->cargo_type)) {
 				/* Do we have to refit the vehicle, or is it already carrying the right cargo? */
-				CargoArray default_capacity = GetCapacityOfArticulatedParts(engine_type, v->type);
+				CargoArray default_capacity = GetCapacityOfArticulatedParts(engine_type);
 				for (CargoID cid = 0; cid < NUM_CARGO; cid++) {
 					if (cid != v->cargo_type && default_capacity[cid] > 0) return v->cargo_type;
 				}
@@ -206,7 +206,7 @@
 		if (part_of_chain && !VerifyAutoreplaceRefitForOrders(v, engine_type)) return CT_INVALID; // Some refit orders lose their effect
 
 		/* Do we have to refit the vehicle, or is it already carrying the right cargo? */
-		CargoArray default_capacity = GetCapacityOfArticulatedParts(engine_type, v->type);
+		CargoArray default_capacity = GetCapacityOfArticulatedParts(engine_type);
 		for (CargoID cid = 0; cid < NUM_CARGO; cid++) {
 			if (cid != cargo_type && default_capacity[cid] > 0) return cargo_type;
 		}
--- a/src/build_vehicle_gui.cpp
+++ b/src/build_vehicle_gui.cpp
@@ -239,8 +239,8 @@
 	const RailVehicleInfo *rvi_a = RailVehInfo(*a);
 	const RailVehicleInfo *rvi_b = RailVehInfo(*b);
 
-	int va = GetTotalCapacityOfArticulatedParts(*a, VEH_TRAIN) * (rvi_a->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1);
-	int vb = GetTotalCapacityOfArticulatedParts(*b, VEH_TRAIN) * (rvi_b->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1);
+	int va = GetTotalCapacityOfArticulatedParts(*a) * (rvi_a->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1);
+	int vb = GetTotalCapacityOfArticulatedParts(*b) * (rvi_b->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1);
 	int r = va - vb;
 
 	/* Use EngineID to sort instead since we want consistent sorting */
@@ -262,8 +262,8 @@
 /* Road vehicle sorting functions */
 static int CDECL RoadVehEngineCapacitySorter(const EngineID *a, const EngineID *b)
 {
-	int va = GetTotalCapacityOfArticulatedParts(*a, VEH_ROAD);
-	int vb = GetTotalCapacityOfArticulatedParts(*b, VEH_ROAD);
+	int va = GetTotalCapacityOfArticulatedParts(*a);
+	int vb = GetTotalCapacityOfArticulatedParts(*b);
 	int r = va - vb;
 
 	/* Use EngineID to sort instead since we want consistent sorting */
@@ -406,7 +406,7 @@
 static bool CDECL CargoFilter(const EngineID *eid, const CargoID cid)
 {
 	if (cid == CF_ANY) return true;
-	uint32 refit_mask = GetUnionOfArticulatedRefitMasks(*eid, Engine::Get(*eid)->type, true);
+	uint32 refit_mask = GetUnionOfArticulatedRefitMasks(*eid, true);
 	return (cid == CF_NONE ? refit_mask == 0 : HasBit(refit_mask, cid));
 }
 
@@ -414,9 +414,9 @@
 	&CargoFilter,
 };
 
-static int DrawCargoCapacityInfo(int left, int right, int y, EngineID engine, VehicleType type, bool refittable)
+static int DrawCargoCapacityInfo(int left, int right, int y, EngineID engine, bool refittable)
 {
-	CargoArray cap = GetCapacityOfArticulatedParts(engine, type);
+	CargoArray cap = GetCapacityOfArticulatedParts(engine);
 
 	for (CargoID c = 0; c < NUM_CARGO; c++) {
 		if (cap[c] == 0) continue;
@@ -640,7 +640,7 @@
 			}
 
 			/* Cargo type + capacity, or N/A */
-			int new_y = DrawCargoCapacityInfo(left, right, y, engine_number, VEH_TRAIN, refittable);
+			int new_y = DrawCargoCapacityInfo(left, right, y, engine_number, refittable);
 
 			if (new_y == y) {
 				SetDParam(0, CT_INVALID);
@@ -656,7 +656,7 @@
 			y = DrawRoadVehPurchaseInfo(left, right, y, engine_number);
 
 			/* Cargo type + capacity, or N/A */
-			int new_y = DrawCargoCapacityInfo(left, right, y, engine_number, VEH_ROAD, refittable);
+			int new_y = DrawCargoCapacityInfo(left, right, y, engine_number, refittable);
 
 			if (new_y == y) {
 				SetDParam(0, CT_INVALID);
--- a/src/engine_func.h
+++ b/src/engine_func.h
@@ -32,6 +32,6 @@
 void SetYearEngineAgingStops();
 void StartupOneEngine(Engine *e, Date aging_date);
 
-uint GetTotalCapacityOfArticulatedParts(EngineID engine, VehicleType type);
+uint GetTotalCapacityOfArticulatedParts(EngineID engine);
 
 #endif /* ENGINE_H */
--- a/src/engine_gui.cpp
+++ b/src/engine_gui.cpp
@@ -122,11 +122,11 @@
 	AllocateWindowDescFront<EnginePreviewWindow>(&_engine_preview_desc, engine);
 }
 
-uint GetTotalCapacityOfArticulatedParts(EngineID engine, VehicleType type)
+uint GetTotalCapacityOfArticulatedParts(EngineID engine)
 {
 	uint total = 0;
 
-	CargoArray cap = GetCapacityOfArticulatedParts(engine, type);
+	CargoArray cap = GetCapacityOfArticulatedParts(engine);
 	for (CargoID c = 0; c < NUM_CARGO; c++) {
 		total += cap[c];
 	}
@@ -143,7 +143,7 @@
 
 	SetDParam(4, e->GetRunningCost());
 
-	uint capacity = GetTotalCapacityOfArticulatedParts(e->index, VEH_TRAIN);
+	uint capacity = GetTotalCapacityOfArticulatedParts(e->index);
 	if (capacity != 0) {
 		SetDParam(5, e->GetDefaultCargoType());
 		SetDParam(6, capacity);
@@ -180,7 +180,7 @@
 {
 	SetDParam(0, e->GetCost());
 	SetDParam(1, e->GetDisplayMaxSpeed());
-	uint capacity = GetTotalCapacityOfArticulatedParts(e->index, VEH_ROAD);
+	uint capacity = GetTotalCapacityOfArticulatedParts(e->index);
 	if (capacity != 0) {
 		SetDParam(2, e->GetDefaultCargoType());
 		SetDParam(3, capacity);
--- a/src/vehicle_gui.cpp
+++ b/src/vehicle_gui.cpp
@@ -447,7 +447,7 @@
 uint ShowRefitOptionsList(int left, int right, int y, EngineID engine)
 {
 	/* List of cargo types of this engine */
-	uint32 cmask = GetUnionOfArticulatedRefitMasks(engine, Engine::Get(engine)->type, false);
+	uint32 cmask = GetUnionOfArticulatedRefitMasks(engine, false);
 	/* List of cargo types available in this climate */
 	uint32 lmask = _cargo_mask;
 	char string[512];