Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #10574 -- revert the change and don't list unavailable road types to game script. #10585

Merged
merged 3 commits into from May 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/road.cpp
Expand Up @@ -112,7 +112,17 @@ bool HasRoadTypeAvail(const CompanyID company, RoadType roadtype)
{
if (company == OWNER_DEITY || company == OWNER_TOWN || _game_mode == GM_EDITOR || _generating_world) {
const RoadTypeInfo *rti = GetRoadTypeInfo(roadtype);
return rti->label != 0 && (rti->flags & ROTFB_HIDDEN) == 0;
if (rti->label == 0) return false;

/* Not yet introduced at this date. */
if (IsInsideMM(rti->introduction_date, 0, MAX_DATE) && rti->introduction_date > TimerGameCalendar::date) return false;

/*
* Do not allow building hidden road types, except when a town may build it.
* The GS under deity mode, as well as anybody in the editor builds roads that are
* owned by towns. So if a town may build it, it should be buildable by them too.
*/
return (rti->flags & ROTFB_HIDDEN) == 0 || (rti->flags & ROTFB_TOWN_BUILD) != 0;
} else {
const Company *c = Company::GetIfValid(company);
if (c == nullptr) return false;
Expand Down
4 changes: 2 additions & 2 deletions src/road.h
Expand Up @@ -39,14 +39,14 @@ enum RoadTypeFlags {
ROTF_NO_LEVEL_CROSSING, ///< Bit number for disabling level crossing
ROTF_NO_HOUSES, ///< Bit number for setting this roadtype as not house friendly
ROTF_HIDDEN, ///< Bit number for hidden from construction.
ROTF_TOWN_BUILD, ///< Bit number for allowing towns to build this roadtype. Does not override ROTF_HIDDEN.
ROTF_TOWN_BUILD, ///< Bit number for allowing towns to build this roadtype.

ROTFB_NONE = 0, ///< All flags cleared.
ROTFB_CATENARY = 1 << ROTF_CATENARY, ///< Value for drawing a catenary.
ROTFB_NO_LEVEL_CROSSING = 1 << ROTF_NO_LEVEL_CROSSING, ///< Value for disabling a level crossing.
ROTFB_NO_HOUSES = 1 << ROTF_NO_HOUSES, ///< Value for for setting this roadtype as not house friendly.
ROTFB_HIDDEN = 1 << ROTF_HIDDEN, ///< Value for hidden from construction.
ROTFB_TOWN_BUILD = 1 << ROTF_TOWN_BUILD, ///< Value for allowing towns to build this roadtype. Does not override ROTFB_HIDDEN.
ROTFB_TOWN_BUILD = 1 << ROTF_TOWN_BUILD, ///< Value for allowing towns to build this roadtype.
};
DECLARE_ENUM_AS_BIT_SET(RoadTypeFlags)

Expand Down
2 changes: 1 addition & 1 deletion src/script/api/script_roadtypelist.cpp
Expand Up @@ -18,6 +18,6 @@ ScriptRoadTypeList::ScriptRoadTypeList(ScriptRoad::RoadTramTypes rtts)
EnforceDeityOrCompanyModeValid_Void();
for (RoadType rt = ROADTYPE_BEGIN; rt != ROADTYPE_END; rt++) {
if (!HasBit(rtts, GetRoadTramType(rt))) continue;
if (ScriptCompanyMode::IsDeity() || ::HasRoadTypeAvail(ScriptObject::GetCompany(), rt)) this->AddItem(rt);
if (::HasRoadTypeAvail(ScriptObject::GetCompany(), rt)) this->AddItem(rt);
}
}