Loading

Paste #pzdjy2zkb

  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..8cb4859 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. +   /* Check only players which can actually own vehicles, editor and gamescripts are considered deities */
  89. +   if (c < OWNER_END) {
  90.         const Company *company = Company::GetIfValid(c);
  91.  
  92. -       return company->avail_roadtypes[rt];
  93. +       if (company != NULL) 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..12c4f73 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. @@ -1316,7 +1316,7 @@ DropDownList *GetScenRoadTypeDropDownList(RoadTypes roadtypes)
  147.     for (RoadType rt = ROADTYPE_BEGIN; rt < ROADTYPE_END; rt++) {
  148.         if (!HasBit(roadtypes, rt)) continue;
  149.  
  150. -       used_roadtypes = ExistingRoadSubTypesForRoadType(rt, INVALID_COMPANY, true);
  151. +       used_roadtypes = ExistingRoadSubTypesForRoadType(rt, OWNER_DEITY, true);
  152.  
  153.         /* If it's not used ever, don't show it to the user. */
  154.         RoadTypeIdentifier rtid;
  155. diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp
  156. index 4fe7d03..4180218 100644
  157. --- a/src/toolbar_gui.cpp
  158. +++ b/src/toolbar_gui.cpp
  159. @@ -2054,9 +2054,9 @@ struct MainToolbarWindow : Window {
  160.         this->SetWidgetDisabledState(WID_TN_GOAL, Goal::GetNumItems() == 0);
  161.         this->SetWidgetDisabledState(WID_TN_STORY, StoryPage::GetNumItems() == 0);
  162.  
  163. -       this->SetWidgetDisabledState(WID_TN_RAILS, !CanBuildVehicleInfrastructure(VEH_TRAIN, 0));
  164. -       this->SetWidgetDisabledState(WID_TN_TRAMS, !CanBuildVehicleInfrastructure(VEH_ROAD, ROADTYPE_TRAM));
  165. -       this->SetWidgetDisabledState(WID_TN_AIR, !CanBuildVehicleInfrastructure(VEH_AIRCRAFT, 0));
  166. +       this->SetWidgetDisabledState(WID_TN_RAILS, !CanBuildVehicleInfrastructure(VEH_TRAIN));
  167. +       this->SetWidgetDisabledState(WID_TN_TRAMS, !CanBuildVehicleInfrastructure(RoadTypeIdentifier(ROADTYPE_TRAM, ROADSUBTYPE_NORMAL), _local_company, false)); //TODO: should loop through all tramtypes
  168. +       this->SetWidgetDisabledState(WID_TN_AIR, !CanBuildVehicleInfrastructure(VEH_AIRCRAFT));
  169.  
  170.         this->DrawWidgets();
  171.     }
  172. @@ -2097,11 +2097,11 @@ struct MainToolbarWindow : Window {
  173.             case MTHK_AIRCRAFT_LIST: ShowVehicleListWindow(_local_company, VEH_AIRCRAFT); break;
  174.             case MTHK_ZOOM_IN: ToolbarZoomInClick(this); break;
  175.             case MTHK_ZOOM_OUT: ToolbarZoomOutClick(this); break;
  176. -           case MTHK_BUILD_RAIL: if (CanBuildVehicleInfrastructure(VEH_TRAIN, 0)) ShowBuildRailToolbar(_last_built_railtype); break;
  177. +           case MTHK_BUILD_RAIL: if (CanBuildVehicleInfrastructure(VEH_TRAIN)) ShowBuildRailToolbar(_last_built_railtype); break;
  178.             case MTHK_BUILD_ROAD: ShowBuildRoadToolbar(_last_built_roadtype_identifier); break;
  179. -           case MTHK_BUILD_TRAM: if (CanBuildVehicleInfrastructure(VEH_ROAD, ROADTYPE_TRAM)) ShowBuildRoadToolbar(_last_built_tramtype_identifier); break;
  180. +           case MTHK_BUILD_TRAM: if (CanBuildVehicleInfrastructure(_last_built_tramtype_identifier, _local_company , false)) ShowBuildRoadToolbar(_last_built_tramtype_identifier); break;
  181.             case MTHK_BUILD_DOCKS: ShowBuildDocksToolbar(); break;
  182. -           case MTHK_BUILD_AIRPORT: if (CanBuildVehicleInfrastructure(VEH_AIRCRAFT, 0)) ShowBuildAirToolbar(); break;
  183. +           case MTHK_BUILD_AIRPORT: if (CanBuildVehicleInfrastructure(VEH_AIRCRAFT)) ShowBuildAirToolbar(); break;
  184.             case MTHK_BUILD_TREES: ShowBuildTreesToolbar(); break;
  185.             case MTHK_MUSIC: ShowMusicWindow(); break;
  186.             case MTHK_AI_DEBUG: ShowAIDebugWindow(); break;
  187. diff --git a/src/vehicle.cpp b/src/vehicle.cpp
  188. index 86e3dbc..687bfc3 100644
  189. --- a/src/vehicle.cpp
  190. +++ b/src/vehicle.cpp
  191. @@ -1714,12 +1714,12 @@ UnitID GetFreeUnitNumber(VehicleType type)
  192.   * vehicle type. This to disable building stations etc. when
  193.   * you are not allowed/able to have the vehicle type yet.
  194.   * @param type the vehicle type to check this for
  195. - * @param subtype for road vehicles, either ROADTYPE_ROAD, ROADTYPE_TRAM or INVALID_ROADTYPE
  196.   * @return true if there is any reason why you may build
  197.   *         the infrastructure for the given vehicle type
  198.   */
  199. -bool CanBuildVehicleInfrastructure(VehicleType type, uint subtype)
  200. +bool CanBuildVehicleInfrastructure(VehicleType type)
  201.  {
  202. +   assert(type != VEH_ROAD);
  203.     assert(IsCompanyBuildableVehicleType(type));
  204.  
  205.     if (!Company::IsValidID(_local_company)) return false;
  206. @@ -1728,7 +1728,6 @@ bool CanBuildVehicleInfrastructure(VehicleType type, uint subtype)
  207.     UnitID max;
  208.     switch (type) {
  209.         case VEH_TRAIN:    max = _settings_game.vehicle.max_trains; break;
  210. -       case VEH_ROAD:     max = _settings_game.vehicle.max_roadveh; break;
  211.         case VEH_SHIP:     max = _settings_game.vehicle.max_ships; break;
  212.         case VEH_AIRCRAFT: max = _settings_game.vehicle.max_aircraft; break;
  213.         default: NOT_REACHED();
  214. @@ -1739,8 +1738,7 @@ bool CanBuildVehicleInfrastructure(VehicleType type, uint subtype)
  215.         /* Can we actually build the vehicle type? */
  216.         const Engine *e;
  217.         FOR_ALL_ENGINES_OF_TYPE(e, type) {
  218. -           if ((type != VEH_ROAD || subtype == INVALID_ROADTYPE || subtype == e->GetRoadType().basetype) &&
  219. -                   HasBit(e->company_avail, _local_company)) return true;
  220. +           if (HasBit(e->company_avail, _local_company)) return true;
  221.         }
  222.         return false;
  223.     }
  224. @@ -1748,14 +1746,47 @@ bool CanBuildVehicleInfrastructure(VehicleType type, uint subtype)
  225.     /* We should be able to build infrastructure when we have the actual vehicle type */
  226.     const Vehicle *v;
  227.     FOR_ALL_VEHICLES(v) {
  228. -       if (v->type == type &&
  229. -               (type != VEH_ROAD || subtype == INVALID_ROADTYPE || subtype == RoadVehicle::From(v)->rtid.basetype) &&
  230. -               v->owner == _local_company) return true;
  231. +       if (v->type == type && v->owner == _local_company) return true;
  232.     }
  233.  
  234.     return false;
  235.  }
  236.  
  237. +/**
  238. + * Check whether we can build infrastructure for the given RoadType. This to disable building stations etc. when
  239. + * you are not allowed/able to have the RoadType yet.
  240. + * @param rtid the roadtype to check this for
  241. + * @param company the company id to check this for
  242. + * @param any_date to check only existing vehicles or if it is possible to build them in the future
  243. + * @return true if there is any reason why you may build the infrastructure for the given roadtype
  244. + */
  245. +bool CanBuildVehicleInfrastructure(RoadTypeIdentifier rtid, CompanyID company, bool any_date)
  246. +{
  247. +   if (_game_mode != GM_EDITOR && !Company::IsValidID(company)) return false;
  248. +   if (!_settings_client.gui.disable_unsuitable_building) return true;
  249. +
  250. +   RoadSubTypes roadsubtypes = ExistingRoadSubTypesForRoadType(rtid.basetype, company, any_date);
  251. +
  252. +   /* Check if the filtered subtypes does have the subtype we are checking for
  253. +    * and if we can build new ones */
  254. +   if (_settings_game.vehicle.max_roadveh > 0 && HasBit(roadsubtypes, rtid.subtype)) {
  255. +       /* Can we actually build the vehicle type? */
  256. +       const Engine *e;
  257. +       FOR_ALL_ENGINES_OF_TYPE(e, VEH_ROAD) {
  258. +           if (e->GetRoadType() == rtid) return true;
  259. +       }
  260. +       return false;
  261. +   }
  262. +
  263. +   /* We should be able to build infrastructure when we have the actual vehicle type */
  264. +   const Vehicle *v;
  265. +   FOR_ALL_VEHICLES(v) {
  266. +       if (v->type == VEH_ROAD && (company == OWNER_DEITY || v->owner == company) &&
  267. +           HasBit(roadsubtypes, RoadVehicle::From(v)->rtid.subtype) && RoadVehicle::From(v)->rtid == rtid) return true;
  268. +   }
  269. +
  270. +   return false;
  271. +}
  272.  
  273.  /**
  274.   * Determines the #LiveryScheme for a vehicle.
  275. diff --git a/src/vehicle_func.h b/src/vehicle_func.h
  276. index 9d08529..430d793 100644
  277. --- a/src/vehicle_func.h
  278. +++ b/src/vehicle_func.h
  279. @@ -71,7 +71,8 @@ UnitID GetFreeUnitNumber(VehicleType type);
  280.  
  281.  void VehicleEnterDepot(Vehicle *v);
  282.  
  283. -bool CanBuildVehicleInfrastructure(VehicleType type, uint subtype);
  284. +bool CanBuildVehicleInfrastructure(VehicleType type);
  285. +bool CanBuildVehicleInfrastructure(RoadTypeIdentifier rtid, CompanyID company, bool any_date);
  286.  
  287.  /** Position information of a vehicle after it moved */
  288.  struct GetNewVehiclePosResult {

Version history

Revision # Author Created at
p5hou9kty Anonymous 26 Feb 2017, 17:00:19 UTC Diff
pquqqwb5q Anonymous 26 Feb 2017, 15:53:05 UTC Diff

Comments