* Check if an engine is buildable. * @param engine index of the engine to check. * @param type the type the engine should be. * @param company index of the company. * @return True if an engine is valid, of the specified type, and buildable by * the given company. */
| 1244 | * the given company. |
| 1245 | */ |
| 1246 | bool IsEngineBuildable(EngineID engine, VehicleType type, CompanyID company) |
| 1247 | { |
| 1248 | const Engine *e = Engine::GetIfValid(engine); |
| 1249 | |
| 1250 | /* check if it's an engine that is in the engine array */ |
| 1251 | if (e == nullptr) return false; |
| 1252 | |
| 1253 | /* check if it's an engine of specified type */ |
| 1254 | if (e->type != type) return false; |
| 1255 | |
| 1256 | /* check if it's available ... */ |
| 1257 | if (company == OWNER_DEITY) { |
| 1258 | /* ... for any company (preview does not count) */ |
| 1259 | if (!e->flags.Test(EngineFlag::Available) || e->company_avail.None()) return false; |
| 1260 | } else { |
| 1261 | /* ... for this company */ |
| 1262 | if (!e->company_avail.Test(company)) return false; |
| 1263 | } |
| 1264 | |
| 1265 | if (!e->IsEnabled()) return false; |
| 1266 | |
| 1267 | if (type == VEH_TRAIN && company != OWNER_DEITY) { |
| 1268 | /* Check if the rail type is available to this company */ |
| 1269 | const Company *c = Company::Get(company); |
| 1270 | if (!GetAllCompatibleRailTypes(e->VehInfo<RailVehicleInfo>().railtypes).Any(c->avail_railtypes)) return false; |
| 1271 | } |
| 1272 | if (type == VEH_ROAD && company != OWNER_DEITY) { |
| 1273 | /* Check if the road type is available to this company */ |
| 1274 | const Company *c = Company::Get(company); |
| 1275 | if (!GetRoadTypeInfo(e->VehInfo<RoadVehicleInfo>().roadtype)->powered_roadtypes.Any(c->avail_roadtypes)) return false; |
| 1276 | } |
| 1277 | |
| 1278 | return true; |
| 1279 | } |
| 1280 | |
| 1281 | /** |
| 1282 | * Check if an engine is refittable. |
no test coverage detected