Index: engine.h =================================================================== --- engine.h (revision 6300) +++ engine.h (working copy) @@ -204,7 +204,11 @@ static inline const AircraftVehicleInfo* AircraftVehInfo(EngineID e) { - assert(e >= AIRCRAFT_ENGINES_INDEX && e < AIRCRAFT_ENGINES_INDEX + lengthof(_aircraft_vehicle_info)); +// assert(e >= AIRCRAFT_ENGINES_INDEX && e < AIRCRAFT_ENGINES_INDEX + lengthof(_aircraft_vehicle_info)); + if (!(e >= AIRCRAFT_ENGINES_INDEX && e < AIRCRAFT_ENGINES_INDEX + lengthof(_aircraft_vehicle_info))) { + // XXX: this is a lame fix for the replace vehicle window to allow testing of build_aircraft.patch + e = AIRCRAFT_ENGINES_INDEX; + } return &_aircraft_vehicle_info[e - AIRCRAFT_ENGINES_INDEX]; } Index: vehicle_gui.c =================================================================== --- vehicle_gui.c (revision 6300) +++ vehicle_gui.c (working copy) @@ -478,7 +478,11 @@ EngineID i; sel[0] = WP(w,replaceveh_d).sel_index[0]; + // XXX: this is a lame fix for the replace vehicle window to allow testing of build_aircraft.patch + if (sel[0] == 0) sel[0] = WP(w,buildtrain_d).sel_engine; sel[1] = WP(w,replaceveh_d).sel_index[1]; + // XXX: this is a lame fix for the replace vehicle window to allow testing of build_aircraft.patch + if (sel[1] == 0) sel[1] = WP(w,buildtrain_d).sel_engine; switch (WP(w,replaceveh_d).vehicletype) { case VEH_Train: { @@ -559,8 +563,10 @@ case VEH_Aircraft: { for (i = AIRCRAFT_ENGINES_INDEX; i < AIRCRAFT_ENGINES_INDEX + NUM_AIRCRAFT_ENGINES; i++) { if (_player_num_engines[i] > 0 || EngineHasReplacementForPlayer(p, i)) { - if (sel[0] == count) selected_id[0] = i; - count++; +// if (sel[0] == count) selected_id[0] = i; +// count++; + // XXX: this is a lame fix for the replace vehicle window to allow testing of build_aircraft.patch + if (sel[0] == i) selected_id[0] = i; } } @@ -570,8 +576,10 @@ for (i = AIRCRAFT_ENGINES_INDEX; i < AIRCRAFT_ENGINES_INDEX + NUM_AIRCRAFT_ENGINES; i++) { if (HASBIT(GetEngine(i)->player_avail, _local_player) && (subtype & AIR_CTOL) == (AircraftVehInfo(i)->subtype & AIR_CTOL)) { - if (sel[1] == count2) selected_id[1] = i; - count2++; +// if (sel[1] == count2) selected_id[1] = i; +// count2++; + // XXX: this is a lame fix for the replace vehicle window to allow testing of build_aircraft.patch + if (sel[1] == i) selected_id[1] = i; } } } @@ -753,7 +761,11 @@ int y2 = 15; int sel[2]; sel[0] = WP(w,replaceveh_d).sel_index[0]; + // XXX: this is a lame fix for the replace vehicle window to allow testing of build_aircraft.patch + if (sel[0] == 0) sel[0] = WP(w,buildtrain_d).sel_engine; sel[1] = WP(w,replaceveh_d).sel_index[1]; + // XXX: this is a lame fix for the replace vehicle window to allow testing of build_aircraft.patch + if (sel[1] == 0) sel[1] = WP(w,buildtrain_d).sel_engine; { uint i; Index: aircraft_gui.c =================================================================== --- aircraft_gui.c (revision 6300) +++ aircraft_gui.c (working copy) @@ -149,9 +149,9 @@ { int x = 2; int y = 15; - int sel = WP(w,buildtrain_d).sel_index; + EngineID sel_eng = WP(w,buildtrain_d).sel_engine; + int sel_ind = WP(w,buildtrain_d).sel_index; int pos = w->vscroll.pos; - EngineID selected_id = INVALID_ENGINE; EngineID eid; for (eid = AIRCRAFT_ENGINES_INDEX; eid < AIRCRAFT_ENGINES_INDEX + NUM_AIRCRAFT_ENGINES; eid++) { @@ -162,22 +162,32 @@ avi = AircraftVehInfo(eid); if ((avi->subtype & AIR_CTOL ? HELICOPTERS_ONLY : AIRCRAFT_ONLY) == acc_planes) continue; - if (sel == 0) selected_id = eid; + if (sel_ind == 1) { // we have found the user's choice + sel_eng = eid; + } if (IS_INT_INSIDE(--pos, -w->vscroll.cap, 0)) { - DrawString(x + 62, y + 7, GetCustomEngineName(eid), sel == 0 ? 0xC : 0x10); + // drawstring highlighted if this is the user's choice + DrawString(x + 62, y + 7, GetCustomEngineName(eid), (eid == sel_eng && sel_ind < 2) ? 0xC : 0x10); DrawAircraftEngine(x + 29, y + 10, eid, GetEnginePalette(eid, _local_player)); y += 24; } - sel--; + if (sel_ind != 0) { + sel_ind--; + } } - WP(w,buildtrain_d).sel_engine = selected_id; - - if (selected_id != INVALID_ENGINE) { - DrawAircraftPurchaseInfo(2, w->widget[4].top + 1, selected_id); + if (sel_ind != 0) { // a valid option was not chosen + WP(w,buildtrain_d).sel_engine = INVALID_ENGINE; + } else { // a valid option was chosen + WP(w,buildtrain_d).sel_engine = sel_eng; + if (sel_eng != INVALID_ENGINE) { // show aircraft info if sel_eng is valid + DrawAircraftPurchaseInfo(2, w->widget[4].top + 1, sel_eng); + } } + // .sel_index == 0 usually; changes, briefly, when an aircraft is selected + WP(w,buildtrain_d).sel_index = 0; } } break; @@ -186,7 +196,8 @@ case 2: { /* listbox */ uint i = (e->click.pt.y - 14) / 24; if (i < w->vscroll.cap) { - WP(w,buildtrain_d).sel_index = i + w->vscroll.pos; + // .sel_index > 0 when an aircraft has been chosen + WP(w,buildtrain_d).sel_index = i + w->vscroll.pos + 1; SetWindowDirty(w); } } break;