# HG changeset patch # User peter1138 # Date 1199745510 0 # Node ID e94985a62bc6fcef440b39b10f874c23b1028c33 # Parent 740d81be2083a515f9f46b2568181ce0ed71b7b6 (svn r11781) -Codechange: variable scope and initialization 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 @@ -743,7 +743,7 @@ /* Figure out what train EngineIDs to put in the list */ static void GenerateBuildTrainList(Window *w) { - EngineID eid, sel_id; + EngineID sel_id = INVALID_ENGINE; int num_engines = 0; int num_wagons = 0; buildvehicle_d *bv = &WP(w, buildvehicle_d); @@ -756,7 +756,7 @@ * Also check to see if the previously selected engine is still available, * and if not, reset selection to INVALID_ENGINE. This could be the case * when engines become obsolete and are removed */ - for (sel_id = INVALID_ENGINE, eid = 0; eid < NUM_TRAIN_ENGINES; eid++) { + for (EngineID eid = 0; eid < NUM_TRAIN_ENGINES; eid++) { const RailVehicleInfo *rvi = RailVehInfo(eid); if (bv->filter.railtype != RAILTYPE_END && !HasPowerOnRail(rvi->railtype, bv->filter.railtype)) continue; @@ -789,14 +789,12 @@ /* Figure out what road vehicle EngineIDs to put in the list */ static void GenerateBuildRoadVehList(Window *w) { - EngineID eid, sel_id; + EngineID sel_id = INVALID_ENGINE; buildvehicle_d *bv = &WP(w, buildvehicle_d); EngList_RemoveAll(&bv->eng_list); - sel_id = INVALID_ENGINE; - - for (eid = ROAD_ENGINES_INDEX; eid < ROAD_ENGINES_INDEX + NUM_ROAD_ENGINES; eid++) { + for (EngineID eid = ROAD_ENGINES_INDEX; eid < ROAD_ENGINES_INDEX + NUM_ROAD_ENGINES; eid++) { if (!IsEngineBuildable(eid, VEH_ROAD, _local_player)) continue; if (!HasBit(bv->filter.roadtypes, HasBit(EngInfo(eid)->misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD)) continue; EngList_Add(&bv->eng_list, eid); @@ -809,14 +807,12 @@ /* Figure out what ship EngineIDs to put in the list */ static void GenerateBuildShipList(Window *w) { - EngineID eid, sel_id; + EngineID sel_id = INVALID_ENGINE; buildvehicle_d *bv = &WP(w, buildvehicle_d); EngList_RemoveAll(&bv->eng_list); - sel_id = INVALID_ENGINE; - - for (eid = SHIP_ENGINES_INDEX; eid < SHIP_ENGINES_INDEX + NUM_SHIP_ENGINES; eid++) { + for (EngineID eid = SHIP_ENGINES_INDEX; eid < SHIP_ENGINES_INDEX + NUM_SHIP_ENGINES; eid++) { if (!IsEngineBuildable(eid, VEH_SHIP, _local_player)) continue; EngList_Add(&bv->eng_list, eid); @@ -828,7 +824,7 @@ /* Figure out what aircraft EngineIDs to put in the list */ static void GenerateBuildAircraftList(Window *w) { - EngineID eid, sel_id; + EngineID sel_id = INVALID_ENGINE; buildvehicle_d *bv = &WP(w, buildvehicle_d); EngList_RemoveAll(&bv->eng_list); @@ -837,8 +833,7 @@ * Also check to see if the previously selected plane is still available, * and if not, reset selection to INVALID_ENGINE. This could be the case * when planes become obsolete and are removed */ - sel_id = INVALID_ENGINE; - for (eid = AIRCRAFT_ENGINES_INDEX; eid < AIRCRAFT_ENGINES_INDEX + NUM_AIRCRAFT_ENGINES; eid++) { + for (EngineID eid = AIRCRAFT_ENGINES_INDEX; eid < AIRCRAFT_ENGINES_INDEX + NUM_AIRCRAFT_ENGINES; eid++) { if (!IsEngineBuildable(eid, VEH_AIRCRAFT, _local_player)) continue; /* First VEH_END window_numbers are fake to allow a window open for all different types at once */ if (w->window_number > VEH_END && !CanAircraftUseStation(eid, w->window_number)) continue;