# HG changeset patch # User frosch # Date 2009-06-27 21:36:04 # Node ID 2375853718ac778c8224cda3a105cd424f99b097 # Parent 9cc92893e2d02223614e814a0adea23a16ae851d (svn r16679) -Codechange: Let GetCapacityOfArticulatedParts() return a CargoArray instead of a pointer to a static array. diff --git a/src/ai/api/ai_engine.cpp b/src/ai/api/ai_engine.cpp --- a/src/ai/api/ai_engine.cpp +++ b/src/ai/api/ai_engine.cpp @@ -70,7 +70,7 @@ switch (e->type) { case VEH_ROAD: case VEH_TRAIN: { - uint16 *capacities = GetCapacityOfArticulatedParts(engine_id, e->type); + CargoArray capacities = GetCapacityOfArticulatedParts(engine_id, e->type); for (CargoID c = 0; c < NUM_CARGO; c++) { if (capacities[c] == 0) continue; return capacities[c]; diff --git a/src/ai/api/ai_event_types.cpp b/src/ai/api/ai_event_types.cpp --- a/src/ai/api/ai_event_types.cpp +++ b/src/ai/api/ai_event_types.cpp @@ -35,7 +35,7 @@ int32 AIEventEnginePreview::GetCapacity( switch (e->type) { case VEH_ROAD: case VEH_TRAIN: { - uint16 *capacities = GetCapacityOfArticulatedParts(engine, e->type); + CargoArray capacities = GetCapacityOfArticulatedParts(engine, e->type); for (CargoID c = 0; c < NUM_CARGO; c++) { if (capacities[c] == 0) continue; return capacities[c]; diff --git a/src/articulated_vehicles.cpp b/src/articulated_vehicles.cpp --- a/src/articulated_vehicles.cpp +++ b/src/articulated_vehicles.cpp @@ -78,10 +78,9 @@ static inline uint32 GetAvailableVehicle return cargos; } -uint16 *GetCapacityOfArticulatedParts(EngineID engine, VehicleType type) +CargoArray GetCapacityOfArticulatedParts(EngineID engine, VehicleType type) { - static uint16 capacity[NUM_CARGO]; - memset(capacity, 0, sizeof(capacity)); + CargoArray capacity; CargoID cargo_type; uint16 cargo_capacity = GetVehicleDefaultCapacity(engine, type, &cargo_type); @@ -239,12 +238,11 @@ void CheckConsistencyOfArticulatedVehicl uint32 purchase_refit_union = GetUnionOfArticulatedRefitMasks(v->engine_type, v->type, true); uint32 purchase_refit_intersection = GetIntersectionOfArticulatedRefitMasks(v->engine_type, v->type, true); - uint16 *purchase_default_capacity = GetCapacityOfArticulatedParts(v->engine_type, v->type); + CargoArray purchase_default_capacity = GetCapacityOfArticulatedParts(v->engine_type, v->type); uint32 real_refit_union = 0; uint32 real_refit_intersection = UINT_MAX; - uint16 real_default_capacity[NUM_CARGO]; - memset(real_default_capacity, 0, sizeof(real_default_capacity)); + CargoArray real_default_capacity; do { uint32 refit_mask = GetAvailableVehicleCargoTypes(v->engine_type, v->type, true); diff --git a/src/articulated_vehicles.h b/src/articulated_vehicles.h --- a/src/articulated_vehicles.h +++ b/src/articulated_vehicles.h @@ -9,7 +9,7 @@ #include "engine_type.h" uint CountArticulatedParts(EngineID engine_type, bool purchase_window); -uint16 *GetCapacityOfArticulatedParts(EngineID engine, VehicleType type); +CargoArray GetCapacityOfArticulatedParts(EngineID engine, VehicleType type); void AddArticulatedParts(Vehicle *first, VehicleType type); uint32 GetUnionOfArticulatedRefitMasks(EngineID engine, VehicleType type, bool include_initial_cargo_type); uint32 GetIntersectionOfArticulatedRefitMasks(EngineID engine, VehicleType type, bool include_initial_cargo_type); diff --git a/src/autoreplace_cmd.cpp b/src/autoreplace_cmd.cpp --- a/src/autoreplace_cmd.cpp +++ b/src/autoreplace_cmd.cpp @@ -182,7 +182,7 @@ static CargoID GetNewCargoTypeForReplace /* 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? */ - uint16 *default_capacity = GetCapacityOfArticulatedParts(engine_type, v->type); + CargoArray default_capacity = GetCapacityOfArticulatedParts(engine_type, v->type); for (CargoID cid = 0; cid < NUM_CARGO; cid++) { if (cid != v->cargo_type && default_capacity[cid] > 0) return v->cargo_type; } @@ -198,7 +198,7 @@ static CargoID GetNewCargoTypeForReplace 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? */ - uint16 *default_capacity = GetCapacityOfArticulatedParts(engine_type, v->type); + CargoArray default_capacity = GetCapacityOfArticulatedParts(engine_type, v->type); for (CargoID cid = 0; cid < NUM_CARGO; cid++) { if (cid != cargo_type && default_capacity[cid] > 0) return cargo_type; } diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp --- a/src/build_vehicle_gui.cpp +++ b/src/build_vehicle_gui.cpp @@ -414,9 +414,9 @@ static GUIEngineList::FilterFunction * c static int DrawCargoCapacityInfo(int left, int right, int y, EngineID engine, VehicleType type, bool refittable) { - uint16 *cap = GetCapacityOfArticulatedParts(engine, type); + CargoArray cap = GetCapacityOfArticulatedParts(engine, type); - for (uint c = 0; c < NUM_CARGO; c++) { + for (CargoID c = 0; c < NUM_CARGO; c++) { if (cap[c] == 0) continue; SetDParam(0, c); diff --git a/src/engine_gui.cpp b/src/engine_gui.cpp --- a/src/engine_gui.cpp +++ b/src/engine_gui.cpp @@ -139,8 +139,8 @@ uint GetTotalCapacityOfArticulatedParts( { uint total = 0; - uint16 *cap = GetCapacityOfArticulatedParts(engine, type); - for (uint c = 0; c < NUM_CARGO; c++) { + CargoArray cap = GetCapacityOfArticulatedParts(engine, type); + for (CargoID c = 0; c < NUM_CARGO; c++) { total += cap[c]; }