* Finds out, whether given company has a given RoadType available for construction. * @param company ID of company * @param roadtypet RoadType to test * @return true if company has the requested RoadType available */
| 121 | * @return true if company has the requested RoadType available |
| 122 | */ |
| 123 | bool HasRoadTypeAvail(const CompanyID company, RoadType roadtype) |
| 124 | { |
| 125 | if (company == OWNER_DEITY || company == OWNER_TOWN || _game_mode == GM_EDITOR || _generating_world) { |
| 126 | const RoadTypeInfo *rti = GetRoadTypeInfo(roadtype); |
| 127 | if (rti->label == 0) return false; |
| 128 | |
| 129 | /* Not yet introduced at this date. */ |
| 130 | if (IsInsideMM(rti->introduction_date, 0, CalendarTime::MAX_DATE.base()) && rti->introduction_date > TimerGameCalendar::date) return false; |
| 131 | |
| 132 | /* |
| 133 | * Do not allow building hidden road types, except when a town may build it. |
| 134 | * The GS under deity mode, as well as anybody in the editor builds roads that are |
| 135 | * owned by towns. So if a town may build it, it should be buildable by them too. |
| 136 | */ |
| 137 | return !rti->flags.Test( RoadTypeFlag::Hidden) || rti->flags.Test( RoadTypeFlag::TownBuild); |
| 138 | } else { |
| 139 | const Company *c = Company::GetIfValid(company); |
| 140 | if (c == nullptr) return false; |
| 141 | RoadTypes avail = c->avail_roadtypes; |
| 142 | avail.Reset(_roadtypes_hidden_mask); |
| 143 | return avail.Test(roadtype); |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | /** |
| 148 | * Test if any buildable RoadType is available for a company. |
no test coverage detected