depot_gui.cpp

Go to the documentation of this file.
00001 /* $Id$ */
00002 
00003 /*
00004  * This file is part of OpenTTD.
00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
00008  */
00009 
00012 #include "stdafx.h"
00013 #include "train.h"
00014 #include "ship.h"
00015 #include "aircraft.h"
00016 #include "gui.h"
00017 #include "textbuf_gui.h"
00018 #include "viewport_func.h"
00019 #include "command_func.h"
00020 #include "depot_base.h"
00021 #include "spritecache.h"
00022 #include "strings_func.h"
00023 #include "vehicle_func.h"
00024 #include "company_func.h"
00025 #include "tilehighlight_func.h"
00026 #include "window_gui.h"
00027 #include "vehiclelist.h"
00028 #include "order_backup.h"
00029 #include "zoom_func.h"
00030 
00031 #include "widgets/depot_widget.h"
00032 
00033 #include "table/strings.h"
00034 
00035 /*
00036  * Since all depot window sizes aren't the same, we need to modify sizes a little.
00037  * It's done with the following arrays of widget indexes. Each of them tells if a widget side should be moved and in what direction.
00038  * How long they should be moved and for what window types are controlled in ShowDepotWindow()
00039  */
00040 
00042 static const NWidgetPart _nested_train_depot_widgets[] = {
00043   NWidget(NWID_HORIZONTAL),
00044     NWidget(WWT_CLOSEBOX, COLOUR_GREY),
00045     NWidget(WWT_CAPTION, COLOUR_GREY, WID_D_CAPTION), SetDataTip(STR_DEPOT_CAPTION, STR_NULL),
00046     NWidget(WWT_SHADEBOX, COLOUR_GREY),
00047     NWidget(WWT_STICKYBOX, COLOUR_GREY),
00048   EndContainer(),
00049   NWidget(NWID_HORIZONTAL),
00050     NWidget(NWID_VERTICAL),
00051       NWidget(WWT_MATRIX, COLOUR_GREY, WID_D_MATRIX), SetDataTip(0x0, STR_NULL), SetResize(1, 1), SetScrollbar(WID_D_V_SCROLL),
00052       NWidget(NWID_SELECTION, INVALID_COLOUR, WID_D_SHOW_H_SCROLL),
00053         NWidget(NWID_HSCROLLBAR, COLOUR_GREY, WID_D_H_SCROLL),
00054       EndContainer(),
00055     EndContainer(),
00056     NWidget(NWID_VERTICAL),
00057       NWidget(WWT_IMGBTN, COLOUR_GREY, WID_D_SELL), SetDataTip(0x0, STR_NULL), SetResize(0, 1), SetFill(0, 1),
00058       NWidget(NWID_SELECTION, INVALID_COLOUR, WID_D_SHOW_SELL_CHAIN),
00059         NWidget(WWT_IMGBTN, COLOUR_GREY, WID_D_SELL_CHAIN), SetDataTip(SPR_SELL_CHAIN_TRAIN, STR_DEPOT_DRAG_WHOLE_TRAIN_TO_SELL_TOOLTIP), SetResize(0, 1), SetFill(0, 1),
00060       EndContainer(),
00061       NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_D_SELL_ALL), SetDataTip(0x0, STR_NULL),
00062       NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_D_AUTOREPLACE), SetDataTip(0x0, STR_NULL),
00063     EndContainer(),
00064     NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_D_V_SCROLL),
00065   EndContainer(),
00066   NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
00067     NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_D_BUILD), SetDataTip(0x0, STR_NULL), SetFill(1, 1), SetResize(1, 0),
00068     NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_D_CLONE), SetDataTip(0x0, STR_NULL), SetFill(1, 1), SetResize(1, 0),
00069     NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_D_LOCATION), SetDataTip(STR_BUTTON_LOCATION, STR_NULL), SetFill(1, 1), SetResize(1, 0),
00070     NWidget(NWID_SELECTION, INVALID_COLOUR, WID_D_SHOW_RENAME), // rename button
00071       NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_D_RENAME), SetDataTip(STR_BUTTON_RENAME, STR_DEPOT_RENAME_TOOLTIP), SetFill(1, 1), SetResize(1, 0),
00072     EndContainer(),
00073     NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_D_VEHICLE_LIST), SetDataTip(0x0, STR_NULL), SetFill(0, 1),
00074     NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_D_STOP_ALL), SetDataTip(SPR_FLAG_VEH_STOPPED, STR_NULL), SetFill(0, 1),
00075     NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_D_START_ALL), SetDataTip(SPR_FLAG_VEH_RUNNING, STR_NULL), SetFill(0, 1),
00076     NWidget(WWT_RESIZEBOX, COLOUR_GREY),
00077   EndContainer(),
00078 };
00079 
00080 static const WindowDesc _train_depot_desc(
00081   WDP_AUTO, 362, 123,
00082   WC_VEHICLE_DEPOT, WC_NONE,
00083   WDF_UNCLICK_BUTTONS,
00084   _nested_train_depot_widgets, lengthof(_nested_train_depot_widgets)
00085 );
00086 
00087 static const WindowDesc _road_depot_desc(
00088   WDP_AUTO, 316, 97,
00089   WC_VEHICLE_DEPOT, WC_NONE,
00090   WDF_UNCLICK_BUTTONS,
00091   _nested_train_depot_widgets, lengthof(_nested_train_depot_widgets)
00092 );
00093 
00094 static const WindowDesc _ship_depot_desc(
00095   WDP_AUTO, 306, 99,
00096   WC_VEHICLE_DEPOT, WC_NONE,
00097   WDF_UNCLICK_BUTTONS,
00098   _nested_train_depot_widgets, lengthof(_nested_train_depot_widgets)
00099 );
00100 
00101 static const WindowDesc _aircraft_depot_desc(
00102   WDP_AUTO, 332, 99,
00103   WC_VEHICLE_DEPOT, WC_NONE,
00104   WDF_UNCLICK_BUTTONS,
00105   _nested_train_depot_widgets, lengthof(_nested_train_depot_widgets)
00106 );
00107 
00108 extern void DepotSortList(VehicleList *list);
00109 
00117 void CcCloneVehicle(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
00118 {
00119   if (result.Failed()) return;
00120 
00121   const Vehicle *v = Vehicle::Get(_new_vehicle_id);
00122 
00123   ShowVehicleViewWindow(v);
00124 }
00125 
00126 static void TrainDepotMoveVehicle(const Vehicle *wagon, VehicleID sel, const Vehicle *head)
00127 {
00128   const Vehicle *v = Vehicle::Get(sel);
00129 
00130   if (v == wagon) return;
00131 
00132   if (wagon == NULL) {
00133     if (head != NULL) wagon = head->Last();
00134   } else {
00135     wagon = wagon->Previous();
00136     if (wagon == NULL) return;
00137   }
00138 
00139   if (wagon == v) return;
00140 
00141   DoCommandP(v->tile, v->index | (_ctrl_pressed ? 1 : 0) << 20, wagon == NULL ? INVALID_VEHICLE : wagon->index, CMD_MOVE_RAIL_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_MOVE_VEHICLE));
00142 }
00143 
00148 static Dimension _base_block_sizes[4];
00149 
00150 static void InitBlocksizeForShipAircraft(VehicleType type)
00151 {
00152   uint max_width  = 0;
00153   uint max_height = 0;
00154 
00155   const Engine *e;
00156   FOR_ALL_ENGINES_OF_TYPE(e, type) {
00157     EngineID eid = e->index;
00158     uint x, y;
00159 
00160     switch (type) {
00161       default: NOT_REACHED();
00162       case VEH_SHIP:     GetShipSpriteSize(    eid, x, y, EIT_IN_DEPOT); break;
00163       case VEH_AIRCRAFT: GetAircraftSpriteSize(eid, x, y, EIT_IN_DEPOT); break;
00164     }
00165     if (x > max_width)  max_width  = x;
00166     if (y > max_height) max_height = y;
00167   }
00168 
00169   switch (type) {
00170     default: NOT_REACHED();
00171     case VEH_SHIP:
00172       _base_block_sizes[VEH_SHIP].width = max(76U, max_width);
00173       break;
00174     case VEH_AIRCRAFT:
00175       _base_block_sizes[VEH_AIRCRAFT].width = max(67U, max_width);
00176       break;
00177   }
00178   _base_block_sizes[type].height = max(GetVehicleHeight(type), max_height);
00179 }
00180 
00185 void InitDepotWindowBlockSizes()
00186 {
00187   _base_block_sizes[VEH_TRAIN].width = 0;
00188   _base_block_sizes[VEH_TRAIN].height = GetVehicleHeight(VEH_TRAIN);
00189 
00190   _base_block_sizes[VEH_ROAD].width = 32;
00191   _base_block_sizes[VEH_ROAD].height = GetVehicleHeight(VEH_ROAD);
00192 
00193   InitBlocksizeForShipAircraft(VEH_SHIP);
00194   InitBlocksizeForShipAircraft(VEH_AIRCRAFT);
00195 }
00196 
00197 static void DepotSellAllConfirmationCallback(Window *w, bool confirmed);
00198 const Sprite *GetAircraftSprite(EngineID engine);
00199 
00200 struct DepotWindow : Window {
00201   VehicleID sel;
00202   VehicleID vehicle_over; 
00203   VehicleType type;
00204   bool generate_list;
00205   VehicleList vehicle_list;
00206   VehicleList wagon_list;
00207   uint num_columns;       
00208   Scrollbar *hscroll;     
00209   Scrollbar *vscroll;
00210 
00211   DepotWindow(const WindowDesc *desc, TileIndex tile, VehicleType type) : Window()
00212   {
00213     assert(IsCompanyBuildableVehicleType(type)); // ensure that we make the call with a valid type
00214 
00215     this->sel = INVALID_VEHICLE;
00216     this->vehicle_over = INVALID_VEHICLE;
00217     this->generate_list = true;
00218     this->type = type;
00219     this->num_columns = 1; // for non-trains this gets set in FinishInitNested()
00220 
00221     this->CreateNestedTree(desc);
00222     this->hscroll = (this->type == VEH_TRAIN ? this->GetScrollbar(WID_D_H_SCROLL) : NULL);
00223     this->vscroll = this->GetScrollbar(WID_D_V_SCROLL);
00224     /* Don't show 'rename button' of aircraft hangar */
00225     this->GetWidget<NWidgetStacked>(WID_D_SHOW_RENAME)->SetDisplayedPlane(type == VEH_AIRCRAFT ? SZSP_NONE : 0);
00226     /* Only train depots have a horizontal scrollbar and a 'sell chain' button */
00227     this->GetWidget<NWidgetStacked>(WID_D_SHOW_H_SCROLL)->SetDisplayedPlane(type == VEH_TRAIN ? 0 : SZSP_HORIZONTAL);
00228     this->GetWidget<NWidgetStacked>(WID_D_SHOW_SELL_CHAIN)->SetDisplayedPlane(type == VEH_TRAIN ? 0 : SZSP_NONE);
00229     this->SetupWidgetData(type);
00230     this->FinishInitNested(desc, tile);
00231 
00232     this->owner = GetTileOwner(tile);
00233     OrderBackup::Reset();
00234   }
00235 
00236   ~DepotWindow()
00237   {
00238     DeleteWindowById(WC_BUILD_VEHICLE, this->window_number);
00239     OrderBackup::Reset(this->window_number);
00240   }
00241 
00249   void DrawVehicleInDepot(const Vehicle *v, int left, int right, int y) const
00250   {
00251     bool free_wagon = false;
00252     int sprite_y = y + (this->resize.step_height - GetVehicleHeight(v->type)) / 2;
00253 
00254     bool rtl = _current_text_dir == TD_RTL;
00255     int image_left  = rtl ? left  + this->count_width  : left  + this->header_width;
00256     int image_right = rtl ? right - this->header_width : right - this->count_width;
00257 
00258     switch (v->type) {
00259       case VEH_TRAIN: {
00260         const Train *u = Train::From(v);
00261         free_wagon = u->IsFreeWagon();
00262 
00263         uint x_space = free_wagon ? TRAININFO_DEFAULT_VEHICLE_WIDTH : 0;
00264         DrawTrainImage(u, image_left + (rtl ? 0 : x_space), image_right - (rtl ? x_space : 0), sprite_y - 1,
00265             this->sel, EIT_IN_DEPOT, free_wagon ? 0 : this->hscroll->GetPosition(), this->vehicle_over);
00266 
00267         /* Length of consist in tiles with 1 fractional digit (rounded up) */
00268         SetDParam(0, CeilDiv(u->gcache.cached_total_length * 10, TILE_SIZE));
00269         SetDParam(1, 1);
00270         DrawString(rtl ? left + WD_FRAMERECT_LEFT : right - this->count_width, rtl ? left + this->count_width : right - WD_FRAMERECT_RIGHT, y + (this->resize.step_height - FONT_HEIGHT_SMALL) / 2, STR_TINY_BLACK_DECIMAL, TC_FROMSTRING, SA_RIGHT); // Draw the counter
00271         break;
00272       }
00273 
00274       case VEH_ROAD:     DrawRoadVehImage( v, image_left, image_right, sprite_y, this->sel, EIT_IN_DEPOT); break;
00275       case VEH_SHIP:     DrawShipImage(    v, image_left, image_right, sprite_y, this->sel, EIT_IN_DEPOT); break;
00276       case VEH_AIRCRAFT: {
00277         const Sprite *spr = GetSprite(v->GetImage(DIR_W, EIT_IN_DEPOT), ST_NORMAL);
00278         DrawAircraftImage(v, image_left, image_right,
00279                   y + max(UnScaleByZoom(spr->height, ZOOM_LVL_GUI) + UnScaleByZoom(spr->y_offs, ZOOM_LVL_GUI) - 14, 0), // tall sprites needs an y offset
00280                   this->sel, EIT_IN_DEPOT);
00281         break;
00282       }
00283       default: NOT_REACHED();
00284     }
00285 
00286     uint diff_x, diff_y;
00287     if (v->IsGroundVehicle()) {
00288       /* Arrange unitnumber and flag horizontally */
00289       diff_x = this->flag_width + WD_FRAMERECT_LEFT;
00290       diff_y = (this->resize.step_height - this->flag_height) / 2 - 2;
00291     } else {
00292       /* Arrange unitnumber and flag vertically */
00293       diff_x = WD_FRAMERECT_LEFT;
00294       diff_y = FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL;
00295     }
00296     int text_left  = rtl ? right - this->header_width - 1 : left + diff_x;
00297     int text_right = rtl ? right - diff_x : left + this->header_width - 1;
00298 
00299     if (free_wagon) {
00300       DrawString(text_left, text_right, y + 2, STR_DEPOT_NO_ENGINE);
00301     } else {
00302       DrawSprite((v->vehstatus & VS_STOPPED) ? SPR_FLAG_VEH_STOPPED : SPR_FLAG_VEH_RUNNING, PAL_NONE, rtl ? right - this->flag_width : left + WD_FRAMERECT_LEFT, y + diff_y);
00303 
00304       SetDParam(0, v->unitnumber);
00305       DrawString(text_left, text_right, y + 2, (uint16)(v->max_age - DAYS_IN_LEAP_YEAR) >= v->age ? STR_BLACK_COMMA : STR_RED_COMMA);
00306     }
00307   }
00308 
00309   void DrawWidget(const Rect &r, int widget) const
00310   {
00311     if (widget != WID_D_MATRIX) return;
00312 
00313     bool rtl = _current_text_dir == TD_RTL;
00314 
00315     /* Set the row and number of boxes in each row based on the number of boxes drawn in the matrix */
00316     uint16 mat_data = this->GetWidget<NWidgetCore>(WID_D_MATRIX)->widget_data;
00317     uint16 rows_in_display   = GB(mat_data, MAT_ROW_START, MAT_ROW_BITS);
00318     uint16 boxes_in_each_row = GB(mat_data, MAT_COL_START, MAT_COL_BITS);
00319 
00320     uint16 num = this->vscroll->GetPosition() * boxes_in_each_row;
00321     int maxval = min(this->vehicle_list.Length(), num + (rows_in_display * boxes_in_each_row));
00322     int y;
00323     for (y = r.top + 1; num < maxval; y += this->resize.step_height) { // Draw the rows
00324       for (byte i = 0; i < boxes_in_each_row && num < maxval; i++, num++) {
00325         /* Draw all vehicles in the current row */
00326         const Vehicle *v = this->vehicle_list[num];
00327         if (boxes_in_each_row == 1) {
00328           this->DrawVehicleInDepot(v, r.left, r.right, y);
00329         } else {
00330           int x = r.left + (rtl ? (boxes_in_each_row - i - 1) : i) * this->resize.step_width;
00331           this->DrawVehicleInDepot(v, x, x + this->resize.step_width - 1, y);
00332         }
00333       }
00334     }
00335 
00336     maxval = min(this->vehicle_list.Length() + this->wagon_list.Length(), (this->vscroll->GetPosition() * boxes_in_each_row) + (rows_in_display * boxes_in_each_row));
00337 
00338     /* Draw the train wagons without an engine in front. */
00339     for (; num < maxval; num++, y += this->resize.step_height) {
00340       const Vehicle *v = this->wagon_list[num - this->vehicle_list.Length()];
00341       this->DrawVehicleInDepot(v, r.left, r.right, y);
00342     }
00343   }
00344 
00345   void SetStringParameters(int widget) const
00346   {
00347     if (widget != WID_D_CAPTION) return;
00348 
00349     /* locate the depot struct */
00350     TileIndex tile = this->window_number;
00351     SetDParam(0, this->type);
00352     SetDParam(1, (this->type == VEH_AIRCRAFT) ? GetStationIndex(tile) : GetDepotIndex(tile));
00353   }
00354 
00355   struct GetDepotVehiclePtData {
00356     const Vehicle *head;
00357     const Vehicle *wagon;
00358   };
00359 
00360   enum DepotGUIAction {
00361     MODE_ERROR,
00362     MODE_DRAG_VEHICLE,
00363     MODE_SHOW_VEHICLE,
00364     MODE_START_STOP,
00365   };
00366 
00367   DepotGUIAction GetVehicleFromDepotWndPt(int x, int y, const Vehicle **veh, GetDepotVehiclePtData *d) const
00368   {
00369     const NWidgetCore *matrix_widget = this->GetWidget<NWidgetCore>(WID_D_MATRIX);
00370     /* In case of RTL the widgets are swapped as a whole */
00371     if (_current_text_dir == TD_RTL) x = matrix_widget->current_x - x;
00372 
00373     uint xt = 0, xm = 0, ym = 0;
00374     if (this->type == VEH_TRAIN) {
00375       xm = x;
00376     } else {
00377       xt = x / this->resize.step_width;
00378       xm = x % this->resize.step_width;
00379       if (xt >= this->num_columns) return MODE_ERROR;
00380     }
00381     ym = y % this->resize.step_height;
00382 
00383     uint row = y / this->resize.step_height;
00384     if (row >= this->vscroll->GetCapacity()) return MODE_ERROR;
00385 
00386     uint boxes_in_each_row = GB(matrix_widget->widget_data, MAT_COL_START, MAT_COL_BITS);
00387     uint pos = ((row + this->vscroll->GetPosition()) * boxes_in_each_row) + xt;
00388 
00389     if (this->vehicle_list.Length() + this->wagon_list.Length() <= pos) {
00390       /* Clicking on 'line' / 'block' without a vehicle */
00391       if (this->type == VEH_TRAIN) {
00392         /* End the dragging */
00393         d->head  = NULL;
00394         d->wagon = NULL;
00395         return MODE_DRAG_VEHICLE;
00396       } else {
00397         return MODE_ERROR; // empty block, so no vehicle is selected
00398       }
00399     }
00400 
00401     bool wagon = false;
00402     if (this->vehicle_list.Length() > pos) {
00403       *veh = this->vehicle_list[pos];
00404       /* Skip vehicles that are scrolled off the list */
00405       if (this->type == VEH_TRAIN) x += this->hscroll->GetPosition();
00406     } else {
00407       pos -= this->vehicle_list.Length();
00408       *veh = this->wagon_list[pos];
00409       /* free wagons don't have an initial loco. */
00410       x -= VEHICLEINFO_FULL_VEHICLE_WIDTH;
00411       wagon = true;
00412     }
00413 
00414     const Train *v = NULL;
00415     if (this->type == VEH_TRAIN) {
00416       v = Train::From(*veh);
00417       d->head = d->wagon = v;
00418     }
00419 
00420     if (xm <= this->header_width) {
00421       switch (this->type) {
00422         case VEH_TRAIN:
00423           if (wagon) return MODE_ERROR;
00424         case VEH_ROAD:
00425           if (xm <= this->flag_width) return MODE_START_STOP;
00426           break;
00427 
00428         case VEH_SHIP:
00429         case VEH_AIRCRAFT:
00430           if (xm <= this->flag_width && ym >= (uint)(FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL)) return MODE_START_STOP;
00431           break;
00432 
00433         default: NOT_REACHED();
00434       }
00435       return MODE_SHOW_VEHICLE;
00436     }
00437 
00438     if (this->type != VEH_TRAIN) return MODE_DRAG_VEHICLE;
00439 
00440     /* Clicking on the counter */
00441     if (xm >= matrix_widget->current_x - this->count_width) return wagon ? MODE_ERROR : MODE_SHOW_VEHICLE;
00442 
00443     /* Account for the header */
00444     x -= this->header_width;
00445 
00446     /* find the vehicle in this row that was clicked */
00447     for (; v != NULL; v = v->Next()) {
00448       x -= v->GetDisplayImageWidth();
00449       if (x < 0) break;
00450     }
00451 
00452     d->wagon = (v != NULL ? v->GetFirstEnginePart() : NULL);
00453 
00454     return MODE_DRAG_VEHICLE;
00455   }
00456 
00462   void DepotClick(int x, int y)
00463   {
00464     GetDepotVehiclePtData gdvp = { NULL, NULL };
00465     const Vehicle *v = NULL;
00466     DepotGUIAction mode = this->GetVehicleFromDepotWndPt(x, y, &v, &gdvp);
00467 
00468     if (this->type == VEH_TRAIN) v = gdvp.wagon;
00469 
00470     switch (mode) {
00471       case MODE_ERROR: // invalid
00472         return;
00473 
00474       case MODE_DRAG_VEHICLE: { // start dragging of vehicle
00475         if (v != NULL && VehicleClicked(v)) return;
00476 
00477         VehicleID sel = this->sel;
00478 
00479         if (this->type == VEH_TRAIN && sel != INVALID_VEHICLE) {
00480           this->sel = INVALID_VEHICLE;
00481           TrainDepotMoveVehicle(v, sel, gdvp.head);
00482         } else if (v != NULL) {
00483           int image = v->GetImage(_current_text_dir == TD_RTL ? DIR_E : DIR_W, EIT_IN_DEPOT);
00484           SetObjectToPlaceWnd(image, GetVehiclePalette(v), HT_DRAG, this);
00485 
00486           this->sel = v->index;
00487           this->SetDirty();
00488 
00489           _cursor.short_vehicle_offset = v->IsGroundVehicle() ? 16 - v->GetGroundVehicleCache()->cached_veh_length * 2 : 0;
00490           _cursor.vehchain = _ctrl_pressed;
00491         }
00492         break;
00493       }
00494 
00495       case MODE_SHOW_VEHICLE: // show info window
00496         ShowVehicleViewWindow(v);
00497         break;
00498 
00499       case MODE_START_STOP: // click start/stop flag
00500         StartStopVehicle(v, false);
00501         break;
00502 
00503       default: NOT_REACHED();
00504     }
00505   }
00506 
00513   void SetupWidgetData(VehicleType type)
00514   {
00515     this->GetWidget<NWidgetCore>(WID_D_STOP_ALL)->tool_tip     = STR_DEPOT_MASS_STOP_DEPOT_TRAIN_TOOLTIP + type;
00516     this->GetWidget<NWidgetCore>(WID_D_START_ALL)->tool_tip    = STR_DEPOT_MASS_START_DEPOT_TRAIN_TOOLTIP + type;
00517     this->GetWidget<NWidgetCore>(WID_D_SELL)->tool_tip         = STR_DEPOT_TRAIN_SELL_TOOLTIP + type;
00518     this->GetWidget<NWidgetCore>(WID_D_SELL_ALL)->tool_tip     = STR_DEPOT_SELL_ALL_BUTTON_TRAIN_TOOLTIP + type;
00519 
00520     this->GetWidget<NWidgetCore>(WID_D_BUILD)->SetDataTip(STR_DEPOT_TRAIN_NEW_VEHICLES_BUTTON + type, STR_DEPOT_TRAIN_NEW_VEHICLES_TOOLTIP + type);
00521     this->GetWidget<NWidgetCore>(WID_D_CLONE)->SetDataTip(STR_DEPOT_CLONE_TRAIN + type, STR_DEPOT_CLONE_TRAIN_DEPOT_INFO + type);
00522 
00523     this->GetWidget<NWidgetCore>(WID_D_LOCATION)->tool_tip     = STR_DEPOT_TRAIN_LOCATION_TOOLTIP + type;
00524     this->GetWidget<NWidgetCore>(WID_D_VEHICLE_LIST)->tool_tip = STR_DEPOT_VEHICLE_ORDER_LIST_TRAIN_TOOLTIP + type;
00525     this->GetWidget<NWidgetCore>(WID_D_AUTOREPLACE)->tool_tip  = STR_DEPOT_AUTOREPLACE_TRAIN_TOOLTIP + type;
00526     this->GetWidget<NWidgetCore>(WID_D_MATRIX)->tool_tip       = STR_DEPOT_TRAIN_LIST_TOOLTIP + this->type;
00527 
00528     switch (type) {
00529       default: NOT_REACHED();
00530 
00531       case VEH_TRAIN:
00532         this->GetWidget<NWidgetCore>(WID_D_VEHICLE_LIST)->widget_data = STR_TRAIN;
00533 
00534         /* Sprites */
00535         this->GetWidget<NWidgetCore>(WID_D_SELL)->widget_data        = SPR_SELL_TRAIN;
00536         this->GetWidget<NWidgetCore>(WID_D_SELL_ALL)->widget_data    = SPR_SELL_ALL_TRAIN;
00537         this->GetWidget<NWidgetCore>(WID_D_AUTOREPLACE)->widget_data = SPR_REPLACE_TRAIN;
00538         break;
00539 
00540       case VEH_ROAD:
00541         this->GetWidget<NWidgetCore>(WID_D_VEHICLE_LIST)->widget_data = STR_LORRY;
00542 
00543         /* Sprites */
00544         this->GetWidget<NWidgetCore>(WID_D_SELL)->widget_data        = SPR_SELL_ROADVEH;
00545         this->GetWidget<NWidgetCore>(WID_D_SELL_ALL)->widget_data    = SPR_SELL_ALL_ROADVEH;
00546         this->GetWidget<NWidgetCore>(WID_D_AUTOREPLACE)->widget_data = SPR_REPLACE_ROADVEH;
00547         break;
00548 
00549       case VEH_SHIP:
00550         this->GetWidget<NWidgetCore>(WID_D_VEHICLE_LIST)->widget_data = STR_SHIP;
00551 
00552         /* Sprites */
00553         this->GetWidget<NWidgetCore>(WID_D_SELL)->widget_data        = SPR_SELL_SHIP;
00554         this->GetWidget<NWidgetCore>(WID_D_SELL_ALL)->widget_data    = SPR_SELL_ALL_SHIP;
00555         this->GetWidget<NWidgetCore>(WID_D_AUTOREPLACE)->widget_data = SPR_REPLACE_SHIP;
00556         break;
00557 
00558       case VEH_AIRCRAFT:
00559         this->GetWidget<NWidgetCore>(WID_D_VEHICLE_LIST)->widget_data = STR_PLANE;
00560 
00561         /* Sprites */
00562         this->GetWidget<NWidgetCore>(WID_D_SELL)->widget_data        = SPR_SELL_AIRCRAFT;
00563         this->GetWidget<NWidgetCore>(WID_D_SELL_ALL)->widget_data    = SPR_SELL_ALL_AIRCRAFT;
00564         this->GetWidget<NWidgetCore>(WID_D_AUTOREPLACE)->widget_data = SPR_REPLACE_AIRCRAFT;
00565         break;
00566     }
00567   }
00568 
00569   uint count_width;
00570   uint header_width;
00571   uint flag_width;
00572   uint flag_height;
00573 
00574   virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
00575   {
00576     switch (widget) {
00577       case WID_D_MATRIX: {
00578         uint min_height = 0;
00579 
00580         if (this->type == VEH_TRAIN) {
00581           SetDParam(0, 1000);
00582           SetDParam(1, 1);
00583           this->count_width = GetStringBoundingBox(STR_TINY_BLACK_DECIMAL).width + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
00584         } else {
00585           this->count_width = 0;
00586         }
00587 
00588         Dimension unumber = { GetDigitWidth() * 4, FONT_HEIGHT_NORMAL };
00589         const Sprite *spr = GetSprite(SPR_FLAG_VEH_STOPPED, ST_NORMAL);
00590         this->flag_width  = UnScaleByZoom(spr->width, ZOOM_LVL_GUI) + WD_FRAMERECT_RIGHT;
00591         this->flag_height = UnScaleByZoom(spr->height, ZOOM_LVL_GUI);
00592 
00593         if (this->type == VEH_TRAIN || this->type == VEH_ROAD) {
00594           min_height = max<uint>(unumber.height + WD_MATRIX_TOP, UnScaleByZoom(spr->height, ZOOM_LVL_GUI));
00595           this->header_width = unumber.width + this->flag_width + WD_FRAMERECT_LEFT;
00596         } else {
00597           min_height = unumber.height + UnScaleByZoom(spr->height, ZOOM_LVL_GUI) + WD_MATRIX_TOP + WD_PAR_VSEP_NORMAL + WD_MATRIX_BOTTOM;
00598           this->header_width = max<uint>(unumber.width, this->flag_width) + WD_FRAMERECT_RIGHT;
00599         }
00600         int base_width = this->count_width + this->header_width;
00601 
00602         resize->height = max(_base_block_sizes[this->type].height, min_height);
00603         if (this->type == VEH_TRAIN) {
00604           resize->width = 1;
00605           size->width = base_width + 2 * 29; // about 2 parts
00606           size->height = resize->height * 6;
00607         } else {
00608           resize->width = base_width + _base_block_sizes[this->type].width;
00609           size->width = resize->width * (this->type == VEH_ROAD ? 5 : 3);
00610           size->height = resize->height * (this->type == VEH_ROAD ? 5 : 3);
00611         }
00612         fill->width = resize->width;
00613         fill->height = resize->height;
00614         break;
00615       }
00616     }
00617   }
00618 
00624   virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
00625   {
00626     this->generate_list = true;
00627   }
00628 
00629   virtual void OnPaint()
00630   {
00631     if (this->generate_list) {
00632       /* Generate the vehicle list
00633        * It's ok to use the wagon pointers for non-trains as they will be ignored */
00634       BuildDepotVehicleList(this->type, this->window_number, &this->vehicle_list, &this->wagon_list);
00635       this->generate_list = false;
00636       DepotSortList(&this->vehicle_list);
00637     }
00638 
00639     /* determine amount of items for scroller */
00640     if (this->type == VEH_TRAIN) {
00641       uint max_width = VEHICLEINFO_FULL_VEHICLE_WIDTH;
00642       for (uint num = 0; num < this->vehicle_list.Length(); num++) {
00643         uint width = 0;
00644         for (const Train *v = Train::From(this->vehicle_list[num]); v != NULL; v = v->Next()) {
00645           width += v->GetDisplayImageWidth();
00646         }
00647         max_width = max(max_width, width);
00648       }
00649       /* Always have 1 empty row, so people can change the setting of the train */
00650       this->vscroll->SetCount(this->vehicle_list.Length() + this->wagon_list.Length() + 1);
00651       this->hscroll->SetCount(max_width);
00652     } else {
00653       this->vscroll->SetCount(CeilDiv(this->vehicle_list.Length(), this->num_columns));
00654     }
00655 
00656     /* Setup disabled buttons. */
00657     TileIndex tile = this->window_number;
00658     this->SetWidgetsDisabledState(!IsTileOwner(tile, _local_company),
00659       WID_D_STOP_ALL,
00660       WID_D_START_ALL,
00661       WID_D_SELL,
00662       WID_D_SELL_CHAIN,
00663       WID_D_SELL_ALL,
00664       WID_D_BUILD,
00665       WID_D_CLONE,
00666       WID_D_RENAME,
00667       WID_D_AUTOREPLACE,
00668       WIDGET_LIST_END);
00669 
00670     this->DrawWidgets();
00671   }
00672 
00673   virtual void OnClick(Point pt, int widget, int click_count)
00674   {
00675     switch (widget) {
00676       case WID_D_MATRIX: { // List
00677         NWidgetBase *nwi = this->GetWidget<NWidgetBase>(WID_D_MATRIX);
00678         this->DepotClick(pt.x - nwi->pos_x, pt.y - nwi->pos_y);
00679         break;
00680       }
00681 
00682       case WID_D_BUILD: // Build vehicle
00683         ResetObjectToPlace();
00684         ShowBuildVehicleWindow(this->window_number, this->type);
00685         break;
00686 
00687       case WID_D_CLONE: // Clone button
00688         this->SetWidgetDirty(WID_D_CLONE);
00689         this->ToggleWidgetLoweredState(WID_D_CLONE);
00690 
00691         if (this->IsWidgetLowered(WID_D_CLONE)) {
00692           static const CursorID clone_icons[] = {
00693             SPR_CURSOR_CLONE_TRAIN, SPR_CURSOR_CLONE_ROADVEH,
00694             SPR_CURSOR_CLONE_SHIP, SPR_CURSOR_CLONE_AIRPLANE
00695           };
00696 
00697           SetObjectToPlaceWnd(clone_icons[this->type], PAL_NONE, HT_VEHICLE, this);
00698         } else {
00699           ResetObjectToPlace();
00700         }
00701         break;
00702 
00703       case WID_D_LOCATION:
00704         if (_ctrl_pressed) {
00705           ShowExtraViewPortWindow(this->window_number);
00706         } else {
00707           ScrollMainWindowToTile(this->window_number);
00708         }
00709         break;
00710 
00711       case WID_D_RENAME: // Rename button
00712         SetDParam(0, this->type);
00713         SetDParam(1, Depot::GetByTile((TileIndex)this->window_number)->index);
00714         ShowQueryString(STR_DEPOT_NAME, STR_DEPOT_RENAME_DEPOT_CAPTION, MAX_LENGTH_DEPOT_NAME_CHARS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT | QSF_LEN_IN_CHARS);
00715         break;
00716 
00717       case WID_D_STOP_ALL:
00718       case WID_D_START_ALL: {
00719         VehicleListIdentifier vli(VL_DEPOT_LIST, this->type, this->owner);
00720         DoCommandP(this->window_number, (widget == WID_D_START_ALL ? (1 << 0) : 0), vli.Pack(), CMD_MASS_START_STOP);
00721         break;
00722       }
00723 
00724       case WID_D_SELL_ALL:
00725         /* Only open the confimation window if there are anything to sell */
00726         if (this->vehicle_list.Length() != 0 || this->wagon_list.Length() != 0) {
00727           TileIndex tile = this->window_number;
00728           byte vehtype = this->type;
00729 
00730           SetDParam(0, vehtype);
00731           SetDParam(1, (vehtype == VEH_AIRCRAFT) ? GetStationIndex(tile) : GetDepotIndex(tile));
00732           ShowQuery(
00733             STR_DEPOT_CAPTION,
00734             STR_DEPOT_SELL_CONFIRMATION_TEXT,
00735             this,
00736             DepotSellAllConfirmationCallback
00737           );
00738         }
00739         break;
00740 
00741       case WID_D_VEHICLE_LIST:
00742         ShowVehicleListWindow(GetTileOwner(this->window_number), this->type, (TileIndex)this->window_number);
00743         break;
00744 
00745       case WID_D_AUTOREPLACE:
00746         DoCommandP(this->window_number, this->type, 0, CMD_DEPOT_MASS_AUTOREPLACE);
00747         break;
00748 
00749     }
00750   }
00751 
00752   virtual void OnQueryTextFinished(char *str)
00753   {
00754     if (str == NULL) return;
00755 
00756     /* Do depot renaming */
00757     DoCommandP(0, GetDepotIndex(this->window_number), 0, CMD_RENAME_DEPOT | CMD_MSG(STR_ERROR_CAN_T_RENAME_DEPOT), NULL, str);
00758   }
00759 
00760   virtual bool OnRightClick(Point pt, int widget)
00761   {
00762     if (widget != WID_D_MATRIX) return false;
00763 
00764     GetDepotVehiclePtData gdvp = { NULL, NULL };
00765     const Vehicle *v = NULL;
00766     NWidgetBase *nwi = this->GetWidget<NWidgetBase>(WID_D_MATRIX);
00767     DepotGUIAction mode = this->GetVehicleFromDepotWndPt(pt.x - nwi->pos_x, pt.y - nwi->pos_y, &v, &gdvp);
00768 
00769     if (this->type == VEH_TRAIN) v = gdvp.wagon;
00770 
00771     if (v == NULL || mode != MODE_DRAG_VEHICLE) return false;
00772 
00773     CargoArray capacity, loaded;
00774 
00775     /* Display info for single (articulated) vehicle, or for whole chain starting with selected vehicle */
00776     bool whole_chain = (this->type == VEH_TRAIN && _ctrl_pressed);
00777 
00778     /* loop through vehicle chain and collect cargoes */
00779     uint num = 0;
00780     for (const Vehicle *w = v; w != NULL; w = w->Next()) {
00781       if (w->cargo_cap > 0 && w->cargo_type < NUM_CARGO) {
00782         capacity[w->cargo_type] += w->cargo_cap;
00783         loaded  [w->cargo_type] += w->cargo.Count();
00784       }
00785 
00786       if (w->type == VEH_TRAIN && !w->HasArticulatedPart()) {
00787         num++;
00788         if (!whole_chain) break;
00789       }
00790     }
00791 
00792     /* Build tooltipstring */
00793     static char details[1024];
00794     details[0] = '\0';
00795     char *pos = details;
00796 
00797     for (CargoID cargo_type = 0; cargo_type < NUM_CARGO; cargo_type++) {
00798       if (capacity[cargo_type] == 0) continue;
00799 
00800       SetDParam(0, cargo_type);           // {CARGO} #1
00801       SetDParam(1, loaded[cargo_type]);   // {CARGO} #2
00802       SetDParam(2, cargo_type);           // {SHORTCARGO} #1
00803       SetDParam(3, capacity[cargo_type]); // {SHORTCARGO} #2
00804       pos = GetString(pos, STR_DEPOT_VEHICLE_TOOLTIP_CARGO, lastof(details));
00805     }
00806 
00807     /* Show tooltip window */
00808     uint64 args[2];
00809     args[0] = (whole_chain ? num : v->engine_type);
00810     args[1] = (uint64)(size_t)details;
00811     GuiShowTooltips(this, whole_chain ? STR_DEPOT_VEHICLE_TOOLTIP_CHAIN : STR_DEPOT_VEHICLE_TOOLTIP, 2, args, TCC_RIGHT_CLICK);
00812 
00813     return true;
00814   }
00815 
00821   virtual bool OnVehicleSelect(const Vehicle *v)
00822   {
00823     if (DoCommandP(this->window_number, v->index, _ctrl_pressed ? 1 : 0, CMD_CLONE_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_BUY_TRAIN + v->type), CcCloneVehicle)) {
00824       ResetObjectToPlace();
00825     }
00826     return true;
00827   }
00828 
00829   virtual void OnPlaceObjectAbort()
00830   {
00831     /* abort clone */
00832     this->RaiseWidget(WID_D_CLONE);
00833     this->SetWidgetDirty(WID_D_CLONE);
00834 
00835     /* abort drag & drop */
00836     this->sel = INVALID_VEHICLE;
00837     this->vehicle_over = INVALID_VEHICLE;
00838     this->SetWidgetDirty(WID_D_MATRIX);
00839   }
00840 
00841   virtual void OnMouseDrag(Point pt, int widget)
00842   {
00843     if (this->type != VEH_TRAIN || this->sel == INVALID_VEHICLE) return;
00844 
00845     /* A rail vehicle is dragged.. */
00846     if (widget != WID_D_MATRIX) { // ..outside of the depot matrix.
00847       if (this->vehicle_over != INVALID_VEHICLE) {
00848         this->vehicle_over = INVALID_VEHICLE;
00849         this->SetWidgetDirty(WID_D_MATRIX);
00850       }
00851       return;
00852     }
00853 
00854     NWidgetBase *matrix = this->GetWidget<NWidgetBase>(widget);
00855     const Vehicle *v = NULL;
00856     GetDepotVehiclePtData gdvp = {NULL, NULL};
00857 
00858     if (this->GetVehicleFromDepotWndPt(pt.x - matrix->pos_x, pt.y - matrix->pos_y, &v, &gdvp) != MODE_DRAG_VEHICLE) return;
00859 
00860     VehicleID new_vehicle_over = INVALID_VEHICLE;
00861     if (gdvp.head != NULL) {
00862       if (gdvp.wagon == NULL && gdvp.head->Last()->index != this->sel) { // ..at the end of the train.
00863         /* NOTE: As a wagon can't be moved at the begin of a train, head index isn't used to mark a drag-and-drop
00864          * destination inside a train. This head index is then used to indicate that a wagon is inserted at
00865          * the end of the train.
00866          */
00867         new_vehicle_over = gdvp.head->index;
00868       } else if (gdvp.wagon != NULL && gdvp.head != gdvp.wagon &&
00869           gdvp.wagon->index != this->sel &&
00870           gdvp.wagon->Previous()->index != this->sel) { // ..over an existing wagon.
00871         new_vehicle_over = gdvp.wagon->index;
00872       }
00873     }
00874 
00875     if (this->vehicle_over == new_vehicle_over) return;
00876 
00877     this->vehicle_over = new_vehicle_over;
00878     this->SetWidgetDirty(widget);
00879   }
00880 
00881   virtual void OnDragDrop(Point pt, int widget)
00882   {
00883     switch (widget) {
00884       case WID_D_MATRIX: {
00885         const Vehicle *v = NULL;
00886         VehicleID sel = this->sel;
00887 
00888         this->sel = INVALID_VEHICLE;
00889         this->SetDirty();
00890 
00891         NWidgetBase *nwi = this->GetWidget<NWidgetBase>(WID_D_MATRIX);
00892         if (this->type == VEH_TRAIN) {
00893           GetDepotVehiclePtData gdvp = { NULL, NULL };
00894 
00895           if (this->GetVehicleFromDepotWndPt(pt.x - nwi->pos_x, pt.y - nwi->pos_y, &v, &gdvp) == MODE_DRAG_VEHICLE && sel != INVALID_VEHICLE) {
00896             if (gdvp.wagon != NULL && gdvp.wagon->index == sel && _ctrl_pressed) {
00897               DoCommandP(Vehicle::Get(sel)->tile, Vehicle::Get(sel)->index, true,
00898                   CMD_REVERSE_TRAIN_DIRECTION | CMD_MSG(STR_ERROR_CAN_T_REVERSE_DIRECTION_RAIL_VEHICLE));
00899             } else if (gdvp.wagon == NULL || gdvp.wagon->index != sel) {
00900               this->vehicle_over = INVALID_VEHICLE;
00901               TrainDepotMoveVehicle(gdvp.wagon, sel, gdvp.head);
00902             } else if (gdvp.head != NULL && gdvp.head->IsFrontEngine()) {
00903               ShowVehicleViewWindow(gdvp.head);
00904             }
00905           }
00906         } else if (this->GetVehicleFromDepotWndPt(pt.x - nwi->pos_x, pt.y - nwi->pos_y, &v, NULL) == MODE_DRAG_VEHICLE && v != NULL && sel == v->index) {
00907           ShowVehicleViewWindow(v);
00908         }
00909         break;
00910       }
00911 
00912       case WID_D_SELL: case WID_D_SELL_CHAIN: {
00913         if (this->IsWidgetDisabled(widget)) return;
00914         if (this->sel == INVALID_VEHICLE) return;
00915 
00916         this->HandleButtonClick(widget);
00917 
00918         const Vehicle *v = Vehicle::Get(this->sel);
00919         this->sel = INVALID_VEHICLE;
00920         this->SetDirty();
00921 
00922         int sell_cmd = (v->type == VEH_TRAIN && (widget == WID_D_SELL_CHAIN || _ctrl_pressed)) ? 1 : 0;
00923         DoCommandP(v->tile, v->index | sell_cmd << 20 | MAKE_ORDER_BACKUP_FLAG, 0, GetCmdSellVeh(v->type));
00924         break;
00925       }
00926 
00927       default:
00928         this->sel = INVALID_VEHICLE;
00929         this->SetDirty();
00930     }
00931     _cursor.vehchain = false;
00932   }
00933 
00934   virtual void OnTimeout()
00935   {
00936     if (!this->IsWidgetDisabled(WID_D_SELL)) {
00937       this->RaiseWidget(WID_D_SELL);
00938       this->SetWidgetDirty(WID_D_SELL);
00939     }
00940     if (this->nested_array[WID_D_SELL] != NULL && !this->IsWidgetDisabled(WID_D_SELL_CHAIN)) {
00941       this->RaiseWidget(WID_D_SELL_CHAIN);
00942       this->SetWidgetDirty(WID_D_SELL_CHAIN);
00943     }
00944   }
00945 
00946   virtual void OnResize()
00947   {
00948     NWidgetCore *nwi = this->GetWidget<NWidgetCore>(WID_D_MATRIX);
00949     this->vscroll->SetCapacityFromWidget(this, WID_D_MATRIX);
00950     if (this->type == VEH_TRAIN) {
00951       this->hscroll->SetCapacity(nwi->current_x - this->header_width - this->count_width);
00952       nwi->widget_data = (this->vscroll->GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
00953     } else {
00954       this->num_columns = nwi->current_x / nwi->resize_x;
00955       nwi->widget_data = (this->vscroll->GetCapacity() << MAT_ROW_START) + (this->num_columns << MAT_COL_START);
00956     }
00957   }
00958 
00959   virtual EventState OnCTRLStateChange()
00960   {
00961     if (this->sel != INVALID_VEHICLE) {
00962       _cursor.vehchain = _ctrl_pressed;
00963       this->SetWidgetDirty(WID_D_MATRIX);
00964       return ES_HANDLED;
00965     }
00966 
00967     return ES_NOT_HANDLED;
00968   }
00969 };
00970 
00971 static void DepotSellAllConfirmationCallback(Window *win, bool confirmed)
00972 {
00973   if (confirmed) {
00974     DepotWindow *w = (DepotWindow*)win;
00975     TileIndex tile = w->window_number;
00976     byte vehtype = w->type;
00977     DoCommandP(tile, vehtype, 0, CMD_DEPOT_SELL_ALL_VEHICLES);
00978   }
00979 }
00980 
00986 void ShowDepotWindow(TileIndex tile, VehicleType type)
00987 {
00988   if (BringWindowToFrontById(WC_VEHICLE_DEPOT, tile) != NULL) return;
00989 
00990   const WindowDesc *desc;
00991   switch (type) {
00992     default: NOT_REACHED();
00993     case VEH_TRAIN:    desc = &_train_depot_desc;    break;
00994     case VEH_ROAD:     desc = &_road_depot_desc;     break;
00995     case VEH_SHIP:     desc = &_ship_depot_desc;     break;
00996     case VEH_AIRCRAFT: desc = &_aircraft_depot_desc; break;
00997   }
00998 
00999   new DepotWindow(desc, tile, type);
01000 }
01001 
01006 void DeleteDepotHighlightOfVehicle(const Vehicle *v)
01007 {
01008   DepotWindow *w;
01009 
01010   /* If we haven't got any vehicles on the mouse pointer, we haven't got any highlighted in any depots either
01011    * If that is the case, we can skip looping though the windows and save time
01012    */
01013   if (_special_mouse_mode != WSM_DRAGDROP) return;
01014 
01015   w = dynamic_cast<DepotWindow*>(FindWindowById(WC_VEHICLE_DEPOT, v->tile));
01016   if (w != NULL) {
01017     if (w->sel == v->index) ResetObjectToPlace();
01018   }
01019 }