# HG changeset patch # User bjarni # Date 1139077507 0 # Node ID 77fa46c313c0f54a1ffa68825c4365533c78dabf # Parent 5084e1f56125356388f3b47a61eaf6a48563cb3b (svn r3535) -Feature: [autoreplace] allow autoreplacing of train wagons currently ALL available wagons are displayed in the right menu in the replace window however the replacement will only be done if the new wagon can be refitted to carry same cargo as the old one is currently carrying Since the standard vehicles do not have any valid wagon replacements, this feature can only be used when using newgrf sets diff -r 5084e1f56125 -r 77fa46c313c0 lang/english.txt --- a/lang/english.txt Sat Feb 04 15:28:30 2006 +0000 +++ b/lang/english.txt Sat Feb 04 18:25:07 2006 +0000 @@ -2769,8 +2769,13 @@ STR_REPLACE_HELP :{BLACK}This allows you to replace one engine type with another type, when trains of the original type enter a depot STR_REPLACE_REMOVE_WAGON :{BLACK}Wagon removal: {ORANGE}{SKIP}{STRING} STR_REPLACE_REMOVE_WAGON_HELP :{BLACK}Make autoreplace keep the length of a train the same by removing wagons (starting at the front), if replacing the engine would make the train longer. +STR_REPLACE_ENGINE_WAGON_SELECT :{BLACK}Replacing: {ORANGE}{SKIP}{SKIP}{STRING} +STR_REPLACE_ENGINE_WAGON_SELECT_HELP :{BLACK} EXPERIMENTAL FEATURE {}Switch between engine and wagon replacement windows.{}Wagon replacement will only be done if the new wagon can be refitted into carrying the same type of cargo as the old one. This is checked for each wagon when the actual replacement takes place. STR_ENGINE_NOT_BUILDABLE :{WHITE}Engine is not buildable +STR_ENGINES :Engines +STR_WAGONS :Wagons + STR_SHORT_DATE :{WHITE}{DATE_TINY} STR_SIGN_LIST_CAPTION :{WHITE}Sign List - {COMMA} Sign{P "" s} diff -r 5084e1f56125 -r 77fa46c313c0 train_cmd.c --- a/train_cmd.c Sat Feb 04 15:28:30 2006 +0000 +++ b/train_cmd.c Sat Feb 04 18:25:07 2006 +0000 @@ -584,6 +584,9 @@ TrainConsistChanged(GetFirstVehicleInChain(v)); InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); + if (IsLocalPlayer()) { + InvalidateWindow(WC_REPLACE_VEHICLE, VEH_Train); // updates the replace Train window + } } } diff -r 5084e1f56125 -r 77fa46c313c0 vehicle.c --- a/vehicle.c Sat Feb 04 15:28:30 2006 +0000 +++ b/vehicle.c Sat Feb 04 18:25:07 2006 +0000 @@ -1742,6 +1742,11 @@ continue; } + if (w->type == VEH_Train && IsTrainWagon(w) && !CanRefitTo(EngineReplacementForPlayer(p, w->engine_type), w->cargo_type)) { + // we can't replace this wagon since we can't refit the new one to the right cargo type + continue; + } + /* Now replace the vehicle */ temp_cost = ReplaceVehicle(&w, flags); diff -r 5084e1f56125 -r 77fa46c313c0 vehicle_gui.c --- a/vehicle_gui.c Sat Feb 04 15:28:30 2006 +0000 +++ b/vehicle_gui.c Sat Feb 04 18:25:07 2006 +0000 @@ -464,7 +464,7 @@ if (!EngineHasReplacementForPlayer(p, i) && _player_num_engines[i] == 0 && show_outdated) continue; - if (rvi->power == 0 && !show_cars) // disables display of cars (works since they do not have power) + if ((rvi->power == 0 && !show_cars) || (rvi->power != 0 && show_cars)) // show wagons or engines (works since wagons do not have power) continue; if (*sel == 0) *selected_id = i; @@ -520,7 +520,7 @@ const Engine *e = GetEngine(engine_id); const EngineInfo *info = &_engine_info[engine_id]; - if (ENGINE_AVAILABLE && RailVehInfo(engine_id)->power && e->railtype == railtype) { + if (ENGINE_AVAILABLE && ((RailVehInfo(engine_id)->power && WP(w, replaceveh_d).wagon_btnstate) || (!RailVehInfo(engine_id)->power && !WP(w, replaceveh_d).wagon_btnstate)) && e->railtype == railtype) { if (_player_num_engines[engine_id] > 0 || EngineHasReplacementForPlayer(p, engine_id)) { if (sel[0] == 0) selected_id[0] = engine_id; count++; @@ -667,9 +667,14 @@ * XXX - DO NOT EVER DO THIS EVER AGAIN! GRRR hacking in wagons as * engines to get more types.. Stays here until we have our own format * then it is exit!!! */ - train_engine_drawing_loop(&x, &y, &pos, &sel[0], &selected_id[0], railtype, w->vscroll.cap, true, false, true); // True engines - train_engine_drawing_loop(&x2, &y2, &pos2, &sel[1], &selected_id[1], railtype, w->vscroll.cap, true, false, false); // True engines - train_engine_drawing_loop(&x2, &y2, &pos2, &sel[1], &selected_id[1], railtype, w->vscroll.cap, false, false, false); // Feeble wagons + if (WP(w,replaceveh_d).wagon_btnstate) { + train_engine_drawing_loop(&x, &y, &pos, &sel[0], &selected_id[0], railtype, w->vscroll.cap, true, false, true); // True engines + train_engine_drawing_loop(&x2, &y2, &pos2, &sel[1], &selected_id[1], railtype, w->vscroll.cap, true, false, false); // True engines + train_engine_drawing_loop(&x2, &y2, &pos2, &sel[1], &selected_id[1], railtype, w->vscroll.cap, false, false, false); // Feeble wagons + } else { + train_engine_drawing_loop(&x, &y, &pos, &sel[0], &selected_id[0], railtype, w->vscroll.cap, false, true, true); + train_engine_drawing_loop(&x2, &y2, &pos2, &sel[1], &selected_id[1], railtype, w->vscroll.cap, false, true, false); + } break; } @@ -888,6 +893,9 @@ if (WP(w, replaceveh_d).vehicletype == VEH_Train) { // set on/off for renew_keep_length SetDParam(1, p->renew_keep_length ? STR_CONFIG_PATCHES_ON : STR_CONFIG_PATCHES_OFF); + + // set wagon/engine button + SetDParam(2, WP(w, replaceveh_d).wagon_btnstate ? STR_ENGINES : STR_WAGONS); } DrawWindowWidgets(w); @@ -919,7 +927,7 @@ for (i = 0 ; i < 2 ; i++) { if (i > 0) offset = 228; if (selected_id[i] != INVALID_ENGINE) { - if (!(RailVehInfo(selected_id[i])->flags & RVI_WAGON)) { + if (WP(w, replaceveh_d).wagon_btnstate) { /* it's an engine */ DrawTrainEnginePurchaseInfo(2 + offset, 15 + (14 * w->vscroll.cap), selected_id[i]); } else { @@ -970,6 +978,11 @@ byte click_side = 1; switch (e->click.widget) { + case 12: { + WP(w, replaceveh_d).wagon_btnstate = !(WP(w, replaceveh_d).wagon_btnstate); + SetWindowDirty(w); + break; + } case 14: case 15: { /* Select sorting criteria dropdown menu */ ShowDropDownMenu(w, _rail_types_list, _railtype_selected_in_replace_gui, 15, 0, ~GetPlayer(_local_player)->avail_railtypes); break; @@ -1036,7 +1049,7 @@ { WWT_SCROLL2BAR, RESIZE_BOTTOM, 14, 444, 455, 14, 125, STR_NULL, STR_0190_SCROLL_BAR_SCROLLS_LIST}, { WWT_PANEL, RESIZE_TB, 14, 228, 455, 126, 197, STR_NULL, STR_NULL}, // train specific stuff -{ WWT_PANEL, RESIZE_TB, 14, 0, 138, 198, 209, STR_NULL, STR_NULL}, +{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 138, 198, 209, STR_REPLACE_ENGINE_WAGON_SELECT, STR_REPLACE_ENGINE_WAGON_SELECT_HELP}, // widget 12 { WWT_PANEL, RESIZE_TB, 14, 139, 153, 210, 221, STR_NULL, STR_NULL}, { WWT_PANEL, RESIZE_TB, 14, 154, 277, 210, 221, STR_NULL, STR_REPLACE_HELP_RAILTYPE}, { WWT_TEXTBTN, RESIZE_TB, 14, 278, 289, 210, 221, STR_0225, STR_REPLACE_HELP_RAILTYPE}, @@ -1117,6 +1130,7 @@ w = AllocateWindowDescFront(&_replace_rail_vehicle_desc, vehicletype); w->vscroll.cap = 8; w->resize.step_height = 14; + WP(w, replaceveh_d).wagon_btnstate = true; break; case VEH_Road: w = AllocateWindowDescFront(&_replace_road_vehicle_desc, vehicletype); diff -r 5084e1f56125 -r 77fa46c313c0 window.h --- a/window.h Sat Feb 04 15:28:30 2006 +0000 +++ b/window.h Sat Feb 04 18:25:07 2006 +0000 @@ -353,6 +353,7 @@ byte sel_index[2]; EngineID sel_engine[2]; uint16 count[2]; + bool wagon_btnstate; // true means engine is selected } replaceveh_d; assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(replaceveh_d));