1664 }; |
1664 }; |
1665 |
1665 |
1666 /** Checks whether the vehicle may be refitted at the moment.*/ |
1666 /** Checks whether the vehicle may be refitted at the moment.*/ |
1667 static bool IsVehicleRefitable(const Vehicle *v) |
1667 static bool IsVehicleRefitable(const Vehicle *v) |
1668 { |
1668 { |
1669 /* Why is this so different for different vehicles? |
1669 if (!v->IsStoppedInDepot()) return false; |
1670 * Does maybe work one solution for all? |
1670 |
1671 */ |
1671 do { |
1672 switch (v->type) { |
1672 /* Skip this vehicle if it has no capacity */ |
1673 case VEH_TRAIN: return false; |
1673 if (v->cargo_cap == 0) continue; |
1674 case VEH_ROAD: return EngInfo(v->engine_type)->refit_mask != 0 && v->IsStoppedInDepot(); |
1674 |
1675 case VEH_SHIP: return ShipVehInfo(v->engine_type)->refittable && v->IsStoppedInDepot(); |
1675 if (IsEngineRefittable(v->engine_type)) return true; |
1676 case VEH_AIRCRAFT: return v->IsStoppedInDepot(); |
1676 } while ((v->type == VEH_TRAIN || v->type == VEH_ROAD) && (v = v->Next()) != NULL); |
1677 default: NOT_REACHED(); |
1677 |
1678 } |
1678 return false; |
1679 } |
1679 } |
1680 |
1680 |
1681 struct VehicleViewWindow : Window { |
1681 struct VehicleViewWindow : Window { |
1682 VehicleViewWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number) |
1682 VehicleViewWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number) |
1683 { |
1683 { |
1856 this->SetWidgetDisabledState(VVW_WIDGET_CLONE_VEH, !is_localcompany); |
1856 this->SetWidgetDisabledState(VVW_WIDGET_CLONE_VEH, !is_localcompany); |
1857 |
1857 |
1858 if (v->type == VEH_TRAIN) { |
1858 if (v->type == VEH_TRAIN) { |
1859 this->SetWidgetDisabledState(VVW_WIDGET_FORCE_PROCEED, !is_localcompany); |
1859 this->SetWidgetDisabledState(VVW_WIDGET_FORCE_PROCEED, !is_localcompany); |
1860 this->SetWidgetDisabledState(VVW_WIDGET_TURN_AROUND, !is_localcompany); |
1860 this->SetWidgetDisabledState(VVW_WIDGET_TURN_AROUND, !is_localcompany); |
1861 |
|
1862 /* Cargo refit button is disabled, until we know we can enable it below. */ |
|
1863 |
|
1864 if (is_localcompany) { |
|
1865 /* See if any vehicle can be refitted */ |
|
1866 for (const Vehicle *u = v; u != NULL; u = u->Next()) { |
|
1867 if (EngInfo(u->engine_type)->refit_mask != 0 || |
|
1868 (RailVehInfo(v->engine_type)->railveh_type != RAILVEH_WAGON && v->cargo_cap != 0)) { |
|
1869 this->EnableWidget(VVW_WIDGET_REFIT_VEH); |
|
1870 /* We have a refittable carriage, bail out */ |
|
1871 break; |
|
1872 } |
|
1873 } |
|
1874 } |
|
1875 } |
1861 } |
1876 |
1862 |
1877 /* draw widgets & caption */ |
1863 /* draw widgets & caption */ |
1878 SetDParam(0, v->index); |
1864 SetDParam(0, v->index); |
1879 this->DrawWidgets(); |
1865 this->DrawWidgets(); |