* An engine has become available for general use. * Also handle the exclusive engine preview contract. * @param e Engine generally available as of now. */
| 1077 | * @param e Engine generally available as of now. |
| 1078 | */ |
| 1079 | static void NewVehicleAvailable(Engine *e) |
| 1080 | { |
| 1081 | EngineID index = e->index; |
| 1082 | |
| 1083 | /* In case the company didn't build the vehicle during the intro period, |
| 1084 | * prevent that company from getting future intro periods for a while. */ |
| 1085 | if (e->flags.Test(EngineFlag::ExclusivePreview)) { |
| 1086 | for (Company *c : Company::Iterate()) { |
| 1087 | if (!e->company_avail.Test(c->index)) continue; |
| 1088 | |
| 1089 | /* Check the company's 'ALL_GROUP' group statistics. This only includes countable vehicles, which is fine |
| 1090 | * as those are the only engines that can be given exclusive previews. */ |
| 1091 | if (GetGroupNumEngines(c->index, ALL_GROUP, e->index) == 0) { |
| 1092 | /* The company did not build this engine during preview. */ |
| 1093 | c->block_preview = 20; |
| 1094 | } |
| 1095 | } |
| 1096 | } |
| 1097 | |
| 1098 | e->flags.Reset(EngineFlag::ExclusivePreview).Set(EngineFlag::Available); |
| 1099 | AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type); |
| 1100 | |
| 1101 | /* Now available for all companies */ |
| 1102 | e->company_avail.Set(); |
| 1103 | |
| 1104 | /* Do not introduce new rail wagons */ |
| 1105 | if (IsWagon(index)) return; |
| 1106 | |
| 1107 | if (e->type == VEH_TRAIN) { |
| 1108 | /* maybe make another rail type available */ |
| 1109 | assert(e->VehInfo<RailVehicleInfo>().railtypes != RailTypes{}); |
| 1110 | RailTypes introduced = GetAllIntroducesRailTypes(e->VehInfo<RailVehicleInfo>().railtypes); |
| 1111 | for (Company *c : Company::Iterate()) c->avail_railtypes = AddDateIntroducedRailTypes(c->avail_railtypes | introduced, TimerGameCalendar::date); |
| 1112 | } else if (e->type == VEH_ROAD) { |
| 1113 | /* maybe make another road type available */ |
| 1114 | assert(e->VehInfo<RoadVehicleInfo>().roadtype < ROADTYPE_END); |
| 1115 | for (Company *c : Company::Iterate()) c->avail_roadtypes = AddDateIntroducedRoadTypes(c->avail_roadtypes | GetRoadTypeInfo(e->VehInfo<RoadVehicleInfo>().roadtype)->introduces_roadtypes, TimerGameCalendar::date); |
| 1116 | } |
| 1117 | |
| 1118 | /* Only broadcast event if AIs are able to build this vehicle type. */ |
| 1119 | if (!IsVehicleTypeDisabled(e->type, true)) AI::BroadcastNewEvent(new ScriptEventEngineAvailable(index)); |
| 1120 | |
| 1121 | /* Only provide the "New Vehicle available" news paper entry, if engine can be built. */ |
| 1122 | if (!IsVehicleTypeDisabled(e->type, false) && !e->info.extra_flags.Test(ExtraEngineFlag::NoNews)) { |
| 1123 | AddNewsItem(GetEncodedString(STR_NEWS_NEW_VEHICLE_NOW_AVAILABLE_WITH_TYPE, |
| 1124 | GetEngineCategoryName(index), |
| 1125 | PackEngineNameDParam(index, EngineNameContext::PreviewNews)), |
| 1126 | NewsType::NewVehicles, NewsStyle::Vehicle, {}, index); |
| 1127 | } |
| 1128 | |
| 1129 | /* Update the toolbar. */ |
| 1130 | if (e->type == VEH_ROAD) InvalidateWindowData(WC_BUILD_TOOLBAR, TRANSPORT_ROAD); |
| 1131 | if (e->type == VEH_SHIP) InvalidateWindowData(WC_BUILD_TOOLBAR, TRANSPORT_WATER); |
| 1132 | if (e->type == VEH_AIRCRAFT) InvalidateWindowData(WC_BUILD_TOOLBAR, TRANSPORT_AIR); |
| 1133 | |
| 1134 | /* Close pending preview windows */ |
| 1135 | CloseWindowById(WC_ENGINE_PREVIEW, index); |
| 1136 | } |
no test coverage detected