Loading

Paste #pquqqwb5q

  1. diff --git a/src/airport_gui.cpp b/src/airport_gui.cpp
  2. index 014884c..6437f23 100644
  3. --- a/src/airport_gui.cpp
  4. +++ b/src/airport_gui.cpp
  5. @@ -91,7 +91,7 @@ struct BuildAirToolbarWindow : Window {
  6.     {
  7.         if (!gui_scope) return;
  8.  
  9. -       if (!CanBuildVehicleInfrastructure(VEH_AIRCRAFT, 0)) delete this;
  10. +       if (!CanBuildVehicleInfrastructure(VEH_AIRCRAFT)) delete this;
  11.     }
  12.  
  13.     virtual void OnClick(Point pt, int widget, int click_count)
  14. @@ -159,7 +159,7 @@ struct BuildAirToolbarWindow : Window {
  15.   */
  16.  static EventState AirportToolbarGlobalHotkeys(int hotkey)
  17.  {
  18. -   if (_game_mode != GM_NORMAL || !CanBuildVehicleInfrastructure(VEH_AIRCRAFT, 0)) return ES_NOT_HANDLED;
  19. +   if (_game_mode != GM_NORMAL || !CanBuildVehicleInfrastructure(VEH_AIRCRAFT)) return ES_NOT_HANDLED;
  20.     Window *w = ShowBuildAirToolbar();
  21.     if (w == NULL) return ES_NOT_HANDLED;
  22.     return w->OnHotkey(hotkey);
  23. diff --git a/src/dock_gui.cpp b/src/dock_gui.cpp
  24. index 531fb4b..79eaa89 100644
  25. --- a/src/dock_gui.cpp
  26. +++ b/src/dock_gui.cpp
  27. @@ -117,7 +117,7 @@ struct BuildDocksToolbarWindow : Window {
  28.     {
  29.         if (!gui_scope) return;
  30.  
  31. -       bool can_build = CanBuildVehicleInfrastructure(VEH_SHIP, 0);
  32. +       bool can_build = CanBuildVehicleInfrastructure(VEH_SHIP);
  33.         this->SetWidgetsDisabledState(!can_build,
  34.             WID_DT_DEPOT,
  35.             WID_DT_STATION,
  36. @@ -145,17 +145,17 @@ struct BuildDocksToolbarWindow : Window {
  37.                 break;
  38.  
  39.             case WID_DT_DEPOT: // Build depot button
  40. -               if (!CanBuildVehicleInfrastructure(VEH_SHIP, 0)) return;
  41. +               if (!CanBuildVehicleInfrastructure(VEH_SHIP)) return;
  42.                 if (HandlePlacePushButton(this, WID_DT_DEPOT, SPR_CURSOR_SHIP_DEPOT, HT_RECT)) ShowBuildDocksDepotPicker(this);
  43.                 break;
  44.  
  45.             case WID_DT_STATION: // Build station button
  46. -               if (!CanBuildVehicleInfrastructure(VEH_SHIP, 0)) return;
  47. +               if (!CanBuildVehicleInfrastructure(VEH_SHIP)) return;
  48.                 if (HandlePlacePushButton(this, WID_DT_STATION, SPR_CURSOR_DOCK, HT_SPECIAL)) ShowBuildDockStationPicker(this);
  49.                 break;
  50.  
  51.             case WID_DT_BUOY: // Build buoy button
  52. -               if (!CanBuildVehicleInfrastructure(VEH_SHIP, 0)) return;
  53. +               if (!CanBuildVehicleInfrastructure(VEH_SHIP)) return;
  54.                 HandlePlacePushButton(this, WID_DT_BUOY, SPR_CURSOR_BUOY, HT_RECT);
  55.                 break;
  56.  
  57. diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp
  58. index 2c407b6..56e663c 100644
  59. --- a/src/rail_gui.cpp
  60. +++ b/src/rail_gui.cpp
  61. @@ -444,7 +444,7 @@ struct BuildRailToolbarWindow : Window {
  62.     {
  63.         if (!gui_scope) return;
  64.  
  65. -       if (!CanBuildVehicleInfrastructure(VEH_TRAIN, 0)) delete this;
  66. +       if (!CanBuildVehicleInfrastructure(VEH_TRAIN)) delete this;
  67.     }
  68.  
  69.     /**
  70. @@ -778,7 +778,7 @@ struct BuildRailToolbarWindow : Window {
  71.   */
  72.  static EventState RailToolbarGlobalHotkeys(int hotkey)
  73.  {
  74. -   if (_game_mode != GM_NORMAL || !CanBuildVehicleInfrastructure(VEH_TRAIN, 0)) return ES_NOT_HANDLED;
  75. +   if (_game_mode != GM_NORMAL || !CanBuildVehicleInfrastructure(VEH_TRAIN)) return ES_NOT_HANDLED;
  76.     extern RailType _last_built_railtype;
  77.     Window *w = ShowBuildRailToolbar(_last_built_railtype);
  78.     if (w == NULL) return ES_NOT_HANDLED;
  79. diff --git a/src/road.cpp b/src/road.cpp
  80. index b891bb5..c3060b8 100644
  81. --- a/src/road.cpp
  82. +++ b/src/road.cpp
  83. @@ -257,10 +257,11 @@ bool RoadTypeIdentifier::UnpackIfValid(uint32 data)
  84.   */
  85.  RoadSubTypes ExistingRoadSubTypesForRoadType(RoadType rt, CompanyID c, bool any_date)
  86.  {
  87. -   if (c != INVALID_COMPANY) {
  88. +   if (c != INVALID_OWNER) {
  89.         const Company *company = Company::GetIfValid(c);
  90.  
  91. -       return company->avail_roadtypes[rt];
  92. +       if (company != NULL)
  93. +           return company->avail_roadtypes[rt];
  94.     }
  95.  
  96.     RoadSubTypes known_roadsubtypes = ROADSUBTYPES_NONE;
  97. diff --git a/src/road_gui.cpp b/src/road_gui.cpp
  98. index 1b9a32f..04ff316 100644
  99. --- a/src/road_gui.cpp
  100. +++ b/src/road_gui.cpp
  101. @@ -300,7 +300,7 @@ struct BuildRoadToolbarWindow : Window {
  102.     {
  103.         if (!gui_scope) return;
  104.  
  105. -       bool can_build = CanBuildVehicleInfrastructure(VEH_ROAD, this->roadtype_identifier.basetype);
  106. +       bool can_build = CanBuildVehicleInfrastructure(this->roadtype_identifier, _local_company, false);
  107.  
  108.         this->SetWidgetsDisabledState(!can_build,
  109.                 WID_ROT_DEPOT,
  110. @@ -440,7 +440,7 @@ struct BuildRoadToolbarWindow : Window {
  111.                 break;
  112.  
  113.             case WID_ROT_DEPOT:
  114. -               if (_game_mode == GM_EDITOR || !CanBuildVehicleInfrastructure(VEH_ROAD, this->roadtype_identifier.basetype)) return;
  115. +               if (_game_mode == GM_EDITOR || !CanBuildVehicleInfrastructure(this->roadtype_identifier, _local_company, false)) return;
  116.                 if (HandlePlacePushButton(this, WID_ROT_DEPOT, GetRoadTypeInfo(roadtype_identifier)->cursor.depot, HT_RECT)) {
  117.                     ShowRoadDepotPicker(this);
  118.                     this->last_started_action = widget;
  119. @@ -448,7 +448,7 @@ struct BuildRoadToolbarWindow : Window {
  120.                 break;
  121.  
  122.             case WID_ROT_BUS_STATION:
  123. -               if (_game_mode == GM_EDITOR || !CanBuildVehicleInfrastructure(VEH_ROAD, this->roadtype_identifier.basetype)) return;
  124. +               if (_game_mode == GM_EDITOR || !CanBuildVehicleInfrastructure(this->roadtype_identifier, _local_company, false)) return;
  125.                 if (HandlePlacePushButton(this, WID_ROT_BUS_STATION, SPR_CURSOR_BUS_STATION, HT_RECT)) {
  126.                     ShowRVStationPicker(this, ROADSTOP_BUS);
  127.                     this->last_started_action = widget;
  128. @@ -456,7 +456,7 @@ struct BuildRoadToolbarWindow : Window {
  129.                 break;
  130.  
  131.             case WID_ROT_TRUCK_STATION:
  132. -               if (_game_mode == GM_EDITOR || !CanBuildVehicleInfrastructure(VEH_ROAD, this->roadtype_identifier.basetype)) return;
  133. +               if (_game_mode == GM_EDITOR || !CanBuildVehicleInfrastructure(this->roadtype_identifier, _local_company, false)) return;
  134.                 if (HandlePlacePushButton(this, WID_ROT_TRUCK_STATION, SPR_CURSOR_TRUCK_STATION, HT_RECT)) {
  135.                     ShowRVStationPicker(this, ROADSTOP_TRUCK);
  136.                     this->last_started_action = widget;
  137. @@ -707,7 +707,7 @@ struct BuildRoadToolbarWindow : Window {
  138.   */
  139.  static EventState RoadTramToolbarGlobalHotkeys(int hotkey, RoadTypeIdentifier last_build)
  140.  {
  141. -   if (last_build.basetype == ROADTYPE_TRAM && (_game_mode != GM_NORMAL || !CanBuildVehicleInfrastructure(VEH_ROAD, last_build.basetype))) return ES_NOT_HANDLED;
  142. +   if (last_build.basetype == ROADTYPE_TRAM && (_game_mode != GM_NORMAL || !CanBuildVehicleInfrastructure(last_build, _local_company, false))) return ES_NOT_HANDLED;
  143.  
  144.     Window *w = NULL;
  145.     switch (_game_mode) {
  146. diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp
  147. index 4fe7d03..4180218 100644
  148. --- a/src/toolbar_gui.cpp
  149. +++ b/src/toolbar_gui.cpp
  150. @@ -2054,9 +2054,9 @@ struct MainToolbarWindow : Window {
  151.         this->SetWidgetDisabledState(WID_TN_GOAL, Goal::GetNumItems() == 0);
  152.         this->SetWidgetDisabledState(WID_TN_STORY, StoryPage::GetNumItems() == 0);
  153.  
  154. -       this->SetWidgetDisabledState(WID_TN_RAILS, !CanBuildVehicleInfrastructure(VEH_TRAIN, 0));
  155. -       this->SetWidgetDisabledState(WID_TN_TRAMS, !CanBuildVehicleInfrastructure(VEH_ROAD, ROADTYPE_TRAM));
  156. -       this->SetWidgetDisabledState(WID_TN_AIR, !CanBuildVehicleInfrastructure(VEH_AIRCRAFT, 0));
  157. +       this->SetWidgetDisabledState(WID_TN_RAILS, !CanBuildVehicleInfrastructure(VEH_TRAIN));
  158. +       this->SetWidgetDisabledState(WID_TN_TRAMS, !CanBuildVehicleInfrastructure(RoadTypeIdentifier(ROADTYPE_TRAM, ROADSUBTYPE_NORMAL), _local_company, false)); //TODO: should loop through all tramtypes
  159. +       this->SetWidgetDisabledState(WID_TN_AIR, !CanBuildVehicleInfrastructure(VEH_AIRCRAFT));
  160.  
  161.         this->DrawWidgets();
  162.     }
  163. @@ -2097,11 +2097,11 @@ struct MainToolbarWindow : Window {
  164.             case MTHK_AIRCRAFT_LIST: ShowVehicleListWindow(_local_company, VEH_AIRCRAFT); break;
  165.             case MTHK_ZOOM_IN: ToolbarZoomInClick(this); break;
  166.             case MTHK_ZOOM_OUT: ToolbarZoomOutClick(this); break;
  167. -           case MTHK_BUILD_RAIL: if (CanBuildVehicleInfrastructure(VEH_TRAIN, 0)) ShowBuildRailToolbar(_last_built_railtype); break;
  168. +           case MTHK_BUILD_RAIL: if (CanBuildVehicleInfrastructure(VEH_TRAIN)) ShowBuildRailToolbar(_last_built_railtype); break;
  169.             case MTHK_BUILD_ROAD: ShowBuildRoadToolbar(_last_built_roadtype_identifier); break;
  170. -           case MTHK_BUILD_TRAM: if (CanBuildVehicleInfrastructure(VEH_ROAD, ROADTYPE_TRAM)) ShowBuildRoadToolbar(_last_built_tramtype_identifier); break;
  171. +           case MTHK_BUILD_TRAM: if (CanBuildVehicleInfrastructure(_last_built_tramtype_identifier, _local_company , false)) ShowBuildRoadToolbar(_last_built_tramtype_identifier); break;
  172.             case MTHK_BUILD_DOCKS: ShowBuildDocksToolbar(); break;
  173. -           case MTHK_BUILD_AIRPORT: if (CanBuildVehicleInfrastructure(VEH_AIRCRAFT, 0)) ShowBuildAirToolbar(); break;
  174. +           case MTHK_BUILD_AIRPORT: if (CanBuildVehicleInfrastructure(VEH_AIRCRAFT)) ShowBuildAirToolbar(); break;
  175.             case MTHK_BUILD_TREES: ShowBuildTreesToolbar(); break;
  176.             case MTHK_MUSIC: ShowMusicWindow(); break;
  177.             case MTHK_AI_DEBUG: ShowAIDebugWindow(); break;
  178. diff --git a/src/vehicle.cpp b/src/vehicle.cpp
  179. index 86e3dbc..c46e851 100644
  180. --- a/src/vehicle.cpp
  181. +++ b/src/vehicle.cpp
  182. @@ -1714,11 +1714,10 @@ UnitID GetFreeUnitNumber(VehicleType type)
  183.   * vehicle type. This to disable building stations etc. when
  184.   * you are not allowed/able to have the vehicle type yet.
  185.   * @param type the vehicle type to check this for
  186. - * @param subtype for road vehicles, either ROADTYPE_ROAD, ROADTYPE_TRAM or INVALID_ROADTYPE
  187.   * @return true if there is any reason why you may build
  188.   *         the infrastructure for the given vehicle type
  189.   */
  190. -bool CanBuildVehicleInfrastructure(VehicleType type, uint subtype)
  191. +bool CanBuildVehicleInfrastructure(VehicleType type)
  192.  {
  193.     assert(IsCompanyBuildableVehicleType(type));
  194.  
  195. @@ -1739,8 +1738,7 @@ bool CanBuildVehicleInfrastructure(VehicleType type, uint subtype)
  196.         /* Can we actually build the vehicle type? */
  197.         const Engine *e;
  198.         FOR_ALL_ENGINES_OF_TYPE(e, type) {
  199. -           if ((type != VEH_ROAD || subtype == INVALID_ROADTYPE || subtype == e->GetRoadType().basetype) &&
  200. -                   HasBit(e->company_avail, _local_company)) return true;
  201. +           if (HasBit(e->company_avail, _local_company)) return true;
  202.         }
  203.         return false;
  204.     }
  205. @@ -1748,14 +1746,51 @@ bool CanBuildVehicleInfrastructure(VehicleType type, uint subtype)
  206.     /* We should be able to build infrastructure when we have the actual vehicle type */
  207.     const Vehicle *v;
  208.     FOR_ALL_VEHICLES(v) {
  209. -       if (v->type == type &&
  210. -               (type != VEH_ROAD || subtype == INVALID_ROADTYPE || subtype == RoadVehicle::From(v)->rtid.basetype) &&
  211. -               v->owner == _local_company) return true;
  212. +       if (v->type == type && v->owner == _local_company) return true;
  213.     }
  214.  
  215.     return false;
  216.  }
  217.  
  218. +/**
  219. + * Check whether we can build infrastructure for the given
  220. + * RoadType. This to disable building stations etc. when
  221. + * you are not allowed/able to have the RoadType yet.
  222. + * @param rtid the roadtype to check this for
  223. + * @param company the company id to check this for
  224. + * @param any_date to check only existing vehicles or
  225. +          if it is possible to build them in the future
  226. + * @return true if there is any reason why you may build
  227. + *         the infrastructure for the given roadtype
  228. + */
  229. +bool CanBuildVehicleInfrastructure(RoadTypeIdentifier rtid, CompanyID company, bool any_date)
  230. +{
  231. +   if (_game_mode != GM_EDITOR && !Company::IsValidID(company)) return false;
  232. +   if (!_settings_client.gui.disable_unsuitable_building) return true;
  233. +
  234. +   RoadSubTypes roadsubtypes = ExistingRoadSubTypesForRoadType(rtid.basetype, company, any_date);
  235. +
  236. +   UnitID max = _settings_game.vehicle.max_roadveh;
  237. +
  238. +   if (max > 0) {
  239. +       /* Can we actually build the vehicle type? */
  240. +       const Engine *e;
  241. +       FOR_ALL_ENGINES_OF_TYPE(e, VEH_ROAD) {
  242. +           if (HasBit(roadsubtypes, e->GetRoadType().subtype) && e->GetRoadType().subtype == rtid.subtype) return true;
  243. +       }
  244. +       return false;
  245. +   }
  246. +
  247. +   /* We should be able to build infrastructure when we have the actual vehicle type */
  248. +   const Vehicle *v;
  249. +   FOR_ALL_VEHICLES(v) {
  250. +       if (v->type == VEH_ROAD &&
  251. +           HasBit(roadsubtypes, RoadVehicle::From(v)->rtid.subtype) && RoadVehicle::From(v)->rtid.subtype == rtid.subtype
  252. +               && (company == OWNER_NONE || v->owner == company)) return true;
  253. +   }
  254. +
  255. +   return false;
  256. +}
  257.  
  258.  /**
  259.   * Determines the #LiveryScheme for a vehicle.
  260. diff --git a/src/vehicle_func.h b/src/vehicle_func.h
  261. index 9d08529..430d793 100644
  262. --- a/src/vehicle_func.h
  263. +++ b/src/vehicle_func.h
  264. @@ -71,7 +71,8 @@ UnitID GetFreeUnitNumber(VehicleType type);
  265.  
  266.  void VehicleEnterDepot(Vehicle *v);
  267.  
  268. -bool CanBuildVehicleInfrastructure(VehicleType type, uint subtype);
  269. +bool CanBuildVehicleInfrastructure(VehicleType type);
  270. +bool CanBuildVehicleInfrastructure(RoadTypeIdentifier rtid, CompanyID company, bool any_date);
  271.  
  272.  /** Position information of a vehicle after it moved */
  273.  struct GetNewVehiclePosResult {

Comments