Skip to content

Instantly share code, notes, and snippets.

@Wolfolo
Created June 10, 2017 15:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Wolfolo/227add4fe83c57b165d4e1a84576e22e to your computer and use it in GitHub Desktop.
Save Wolfolo/227add4fe83c57b165d4e1a84576e22e to your computer and use it in GitHub Desktop.
diff --git a/src/road.cpp b/src/road.cpp
index 8cb4859..7f1d27b 100644
--- a/src/road.cpp
+++ b/src/road.cpp
@@ -250,12 +250,14 @@ bool RoadTypeIdentifier::UnpackIfValid(uint32 data)
/**
* Returns the available RoadSubTypes for the provided RoadType
+ * If the given company is valid then will be returned a list of the available sub types at the current date, while passing
+ * a deity company will make all the sub types available
* @param rt the RoadType to filter
* @param c the company ID to check the roadtype against
* @param any_date whether to return only currently introduced roadtypes or also future ones
* @returns the existing RoadSubTypes
*/
-RoadSubTypes ExistingRoadSubTypesForRoadType(RoadType rt, CompanyID c, bool any_date)
+RoadSubTypes ExistingRoadSubTypesForRoadType(RoadType rt, CompanyID c)
{
/* Check only players which can actually own vehicles, editor and gamescripts are considered deities */
if (c < OWNER_END) {
@@ -276,7 +278,7 @@ RoadSubTypes ExistingRoadSubTypesForRoadType(RoadType rt, CompanyID c, bool any_
if (!HasBit(e->info.climates, _settings_game.game_creation.landscape)) continue;
/* Check whether available for all potential companies */
- if (any_date && e->company_avail != (CompanyMask)-1) continue;
+ if (e->company_avail != (CompanyMask)-1) continue;
RoadTypeIdentifier rtid = e->GetRoadType();
if (rtid.basetype != rt) continue;
@@ -285,7 +287,7 @@ RoadSubTypes ExistingRoadSubTypesForRoadType(RoadType rt, CompanyID c, bool any_
}
/* Get the date introduced roadtypes as well. */
- known_roadsubtypes = AddDateIntroducedRoadTypes(rt, known_roadsubtypes, any_date ? MAX_DAY : _date);
+ known_roadsubtypes = AddDateIntroducedRoadTypes(rt, known_roadsubtypes, MAX_DAY);
return known_roadsubtypes;
}
diff --git a/src/road.h b/src/road.h
index a5146a3..19f4774 100644
--- a/src/road.h
+++ b/src/road.h
@@ -252,7 +252,7 @@ RoadTypeIdentifier GetRoadTypeByLabel(RoadTypeLabel label, RoadType subtype, boo
void ResetRoadTypes();
void InitRoadTypes();
RoadTypeIdentifier AllocateRoadType(RoadTypeLabel label, RoadType basetype);
-RoadSubTypes ExistingRoadSubTypesForRoadType(RoadType rt, CompanyID c, bool any_date = true);
+RoadSubTypes ExistingRoadSubTypesForRoadType(RoadType rt, CompanyID c);
extern RoadTypeIdentifier _sorted_roadtypes[ROADTYPE_END][ROADSUBTYPE_END];
extern uint8 _sorted_roadtypes_size[ROADTYPE_END];
diff --git a/src/road_gui.cpp b/src/road_gui.cpp
index 07bf158..0304ac1 100644
--- a/src/road_gui.cpp
+++ b/src/road_gui.cpp
@@ -301,7 +301,7 @@ struct BuildRoadToolbarWindow : Window {
{
if (!gui_scope) return;
- bool can_build = CanBuildVehicleInfrastructure(this->roadtype_identifier, _local_company, false);
+ bool can_build = CanBuildVehicleInfrastructure(this->roadtype_identifier, _local_company);
this->SetWidgetsDisabledState(!can_build,
WID_ROT_DEPOT,
@@ -444,7 +444,7 @@ struct BuildRoadToolbarWindow : Window {
break;
case WID_ROT_DEPOT:
- if (_game_mode == GM_EDITOR || !CanBuildVehicleInfrastructure(this->roadtype_identifier, _local_company, false)) return;
+ if (_game_mode == GM_EDITOR || !CanBuildVehicleInfrastructure(this->roadtype_identifier, _local_company)) return;
if (HandlePlacePushButton(this, WID_ROT_DEPOT, GetRoadTypeInfo(roadtype_identifier)->cursor.depot, HT_RECT)) {
ShowRoadDepotPicker(this);
this->last_started_action = widget;
@@ -452,7 +452,7 @@ struct BuildRoadToolbarWindow : Window {
break;
case WID_ROT_BUS_STATION:
- if (_game_mode == GM_EDITOR || !CanBuildVehicleInfrastructure(this->roadtype_identifier, _local_company, false)) return;
+ if (_game_mode == GM_EDITOR || !CanBuildVehicleInfrastructure(this->roadtype_identifier, _local_company)) return;
if (HandlePlacePushButton(this, WID_ROT_BUS_STATION, SPR_CURSOR_BUS_STATION, HT_RECT)) {
ShowRVStationPicker(this, ROADSTOP_BUS);
this->last_started_action = widget;
@@ -460,7 +460,7 @@ struct BuildRoadToolbarWindow : Window {
break;
case WID_ROT_TRUCK_STATION:
- if (_game_mode == GM_EDITOR || !CanBuildVehicleInfrastructure(this->roadtype_identifier, _local_company, false)) return;
+ if (_game_mode == GM_EDITOR || !CanBuildVehicleInfrastructure(this->roadtype_identifier, _local_company)) return;
if (HandlePlacePushButton(this, WID_ROT_TRUCK_STATION, SPR_CURSOR_TRUCK_STATION, HT_RECT)) {
ShowRVStationPicker(this, ROADSTOP_TRUCK);
this->last_started_action = widget;
@@ -712,7 +712,7 @@ struct BuildRoadToolbarWindow : Window {
*/
static EventState RoadTramToolbarGlobalHotkeys(int hotkey, RoadTypeIdentifier last_build)
{
- if (last_build.basetype == ROADTYPE_TRAM && (_game_mode != GM_NORMAL || !CanBuildVehicleInfrastructure(last_build, _local_company, false))) return ES_NOT_HANDLED;
+ if (last_build.basetype == ROADTYPE_TRAM && (_game_mode != GM_NORMAL || !CanBuildVehicleInfrastructure(last_build, _local_company))) return ES_NOT_HANDLED;
Window *w = NULL;
switch (_game_mode) {
@@ -1285,7 +1285,7 @@ DropDownList *GetRoadTypeDropDownList(RoadTypes roadtypes, bool for_replacement,
RoadSubTypes used_roadtypes = ROADSUBTYPES_NONE;
- used_roadtypes = ExistingRoadSubTypesForRoadType(rt, c->index, false);
+ used_roadtypes = ExistingRoadSubTypesForRoadType(rt, c->index);
/* If it's not used ever, don't show it to the user. */
RoadTypeIdentifier rtid;
@@ -1318,7 +1318,7 @@ DropDownList *GetScenRoadTypeDropDownList(RoadTypes roadtypes)
for (RoadType rt = ROADTYPE_BEGIN; rt < ROADTYPE_END; rt++) {
if (!HasBit(roadtypes, rt)) continue;
- used_roadtypes = ExistingRoadSubTypesForRoadType(rt, OWNER_DEITY, true);
+ used_roadtypes = ExistingRoadSubTypesForRoadType(rt, OWNER_DEITY);
/* If it's not used ever, don't show it to the user. */
RoadTypeIdentifier rtid;
diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp
index da5d420..91a0fd2 100644
--- a/src/toolbar_gui.cpp
+++ b/src/toolbar_gui.cpp
@@ -2055,7 +2055,7 @@ struct MainToolbarWindow : Window {
this->SetWidgetDisabledState(WID_TN_STORY, StoryPage::GetNumItems() == 0);
this->SetWidgetDisabledState(WID_TN_RAILS, !CanBuildVehicleInfrastructure(VEH_TRAIN));
- this->SetWidgetDisabledState(WID_TN_TRAMS, !CanBuildVehicleInfrastructure(RoadTypeIdentifier(ROADTYPE_TRAM, ROADSUBTYPE_NORMAL), _local_company, false)); //TODO: should loop through all tramtypes
+ this->SetWidgetDisabledState(WID_TN_TRAMS, !CanBuildVehicleInfrastructure(RoadTypeIdentifier(ROADTYPE_TRAM, ROADSUBTYPE_NORMAL), _local_company)); //TODO: should loop through all tramtypes
this->SetWidgetDisabledState(WID_TN_AIR, !CanBuildVehicleInfrastructure(VEH_AIRCRAFT));
this->DrawWidgets();
@@ -2099,7 +2099,7 @@ struct MainToolbarWindow : Window {
case MTHK_ZOOM_OUT: ToolbarZoomOutClick(this); break;
case MTHK_BUILD_RAIL: if (CanBuildVehicleInfrastructure(VEH_TRAIN)) ShowBuildRailToolbar(_last_built_railtype); break;
case MTHK_BUILD_ROAD: ShowBuildRoadToolbar(_last_built_roadtype_identifier); break;
- case MTHK_BUILD_TRAM: if (CanBuildVehicleInfrastructure(_last_built_tramtype_identifier, _local_company , false)) ShowBuildRoadToolbar(_last_built_tramtype_identifier); break;
+ case MTHK_BUILD_TRAM: if (CanBuildVehicleInfrastructure(_last_built_tramtype_identifier, _local_company)) ShowBuildRoadToolbar(_last_built_tramtype_identifier); break;
case MTHK_BUILD_DOCKS: ShowBuildDocksToolbar(); break;
case MTHK_BUILD_AIRPORT: if (CanBuildVehicleInfrastructure(VEH_AIRCRAFT)) ShowBuildAirToolbar(); break;
case MTHK_BUILD_TREES: ShowBuildTreesToolbar(); break;
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index 8899a19..428bede 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -1760,12 +1760,12 @@ bool CanBuildVehicleInfrastructure(VehicleType type)
* @param any_date to check only existing vehicles or if it is possible to build them in the future
* @return true if there is any reason why you may build the infrastructure for the given roadtype
*/
-bool CanBuildVehicleInfrastructure(RoadTypeIdentifier rtid, CompanyID company, bool any_date)
+bool CanBuildVehicleInfrastructure(RoadTypeIdentifier rtid, CompanyID company)
{
if (_game_mode != GM_EDITOR && !Company::IsValidID(company)) return false;
if (!_settings_client.gui.disable_unsuitable_building) return true;
- RoadSubTypes roadsubtypes = ExistingRoadSubTypesForRoadType(rtid.basetype, company, any_date);
+ RoadSubTypes roadsubtypes = ExistingRoadSubTypesForRoadType(rtid.basetype, company);
/* Check if the filtered subtypes does have the subtype we are checking for
* and if we can build new ones */
diff --git a/src/vehicle_func.h b/src/vehicle_func.h
index 430d793..812a52c 100644
--- a/src/vehicle_func.h
+++ b/src/vehicle_func.h
@@ -72,7 +72,7 @@ UnitID GetFreeUnitNumber(VehicleType type);
void VehicleEnterDepot(Vehicle *v);
bool CanBuildVehicleInfrastructure(VehicleType type);
-bool CanBuildVehicleInfrastructure(RoadTypeIdentifier rtid, CompanyID company, bool any_date);
+bool CanBuildVehicleInfrastructure(RoadTypeIdentifier rtid, CompanyID company);
/** Position information of a vehicle after it moved */
struct GetNewVehiclePosResult {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment