Loading

Paste #plifu4l8w

  1. Index: src/vehicle_cmd.cpp
  2. ===================================================================
  3. --- src/vehicle_cmd.cpp (revision 27675)
  4. +++ src/vehicle_cmd.cpp (working copy)
  5. @@ -606,7 +606,7 @@
  6.     bool vehicle_list_window = HasBit(p1, 1);
  7.  
  8.     VehicleListIdentifier vli;
  9. -   if (!vli.Unpack(p2)) return CMD_ERROR;
  10. +   if (!vli.UnpackIfValid(p2)) return CMD_ERROR;
  11.     if (!IsCompanyBuildableVehicleType(vli.vtype)) return CMD_ERROR;
  12.  
  13.     if (vehicle_list_window) {
  14. @@ -1001,7 +1001,7 @@
  15.     if (p1 & DEPOT_MASS_SEND) {
  16.         /* Mass goto depot requested */
  17.         VehicleListIdentifier vli;
  18. -       if (!vli.Unpack(p2)) return CMD_ERROR;
  19. +       if (!vli.UnpackIfValid(p2)) return CMD_ERROR;
  20.         return SendAllVehiclesToDepot(flags, (p1 & DEPOT_SERVICE) != 0, vli);
  21.     }
  22.  
  23. Index: src/vehicle_gui.cpp
  24. ===================================================================
  25. --- src/vehicle_gui.cpp (revision 27675)
  26. +++ src/vehicle_gui.cpp (working copy)
  27. @@ -1638,7 +1638,7 @@
  28.                 break;
  29.  
  30.             case WID_VL_MANAGE_VEHICLES_DROPDOWN: {
  31. -               DropDownList *list = this->BuildActionDropdownList(VehicleListIdentifier(this->window_number).type == VL_STANDARD, false);
  32. +               DropDownList *list = this->BuildActionDropdownList(VehicleListIdentifier::UnPack(this->window_number).type == VL_STANDARD, false);
  33.                 ShowDropDownList(this, list, 0, WID_VL_MANAGE_VEHICLES_DROPDOWN);
  34.                 break;
  35.             }
  36. Index: src/vehicle_gui_base.h
  37. ===================================================================
  38. --- src/vehicle_gui_base.h  (revision 27675)
  39. +++ src/vehicle_gui_base.h  (working copy)
  40. @@ -38,7 +38,7 @@
  41.     static const StringID vehicle_sorter_names[];
  42.     static GUIVehicleList::SortFunction * const vehicle_sorter_funcs[];
  43.  
  44. -   BaseVehicleListWindow(WindowDesc *desc, WindowNumber wno) : Window(desc), vli(wno)
  45. +   BaseVehicleListWindow(WindowDesc *desc, WindowNumber wno) : Window(desc), vli(VehicleListIdentifier::UnPack(wno))
  46.     {
  47.         this->vehicles.SetSortFuncs(this->vehicle_sorter_funcs);
  48.     }
  49. Index: src/vehiclelist.cpp
  50. ===================================================================
  51. --- src/vehiclelist.cpp (revision 27675)
  52. +++ src/vehiclelist.cpp (working copy)
  53. @@ -37,7 +37,7 @@
  54.   * @param data The data to unpack.
  55.   * @return true iff the data was valid (enough).
  56.   */
  57. -bool VehicleListIdentifier::Unpack(uint32 data)
  58. +bool VehicleListIdentifier::UnpackIfValid(uint32 data)
  59.  {
  60.     byte c        = GB(data, 28, 4);
  61.     this->company = c == 0xF ? OWNER_NONE : (CompanyID)c;
  62. @@ -52,10 +52,12 @@
  63.   * Decode a packed vehicle list identifier into a new one.
  64.   * @param data The data to unpack.
  65.   */
  66. -VehicleListIdentifier::VehicleListIdentifier(uint32 data)
  67. +/* static */ VehicleListIdentifier VehicleListIdentifier::UnPack(uint32 data)
  68.  {
  69. -   bool ret = this->Unpack(data);
  70. +   VehicleListIdentifier result;
  71. +   bool ret = result.UnpackIfValid(data);
  72.     assert(ret);
  73. +   return result;
  74.  }
  75.  
  76.  /**
  77. Index: src/vehiclelist.h
  78. ===================================================================
  79. --- src/vehiclelist.h   (revision 27675)
  80. +++ src/vehiclelist.h   (working copy)
  81. @@ -35,7 +35,8 @@
  82.     uint32 index;         ///< A vehicle list type specific index.
  83.  
  84.     uint32 Pack() const;
  85. -   bool Unpack(uint32 data);
  86. +   bool UnpackIfValid(uint32 data);
  87. +   static VehicleListIdentifier UnPack(uint32 data);
  88.  
  89.     /**
  90.      * Create a simple vehicle list.
  91. @@ -47,7 +48,7 @@
  92.     VehicleListIdentifier(VehicleListType type, VehicleType vtype, CompanyID company, uint index = 0) :
  93.         type(type), vtype(vtype), company(company), index(index) {}
  94.  
  95. -   VehicleListIdentifier(uint32 data = 0);
  96. +   VehicleListIdentifier() : type(), vtype(), company(), index() {}
  97.  };
  98.  
  99.  /** A list of vehicles. */
  100.  

Comments