MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / CalendarEnginesMonthlyLoop

Function CalendarEnginesMonthlyLoop

src/engine.cpp:1139–1184  ·  view source on GitHub ↗

Monthly update of the availability, reliability, and preview offers of the engines. */

Source from the content-addressed store, hash-verified

1137
1138/** Monthly update of the availability, reliability, and preview offers of the engines. */
1139void CalendarEnginesMonthlyLoop()
1140{
1141 if (TimerGameCalendar::year < _year_engine_aging_stops) {
1142 bool refresh = false;
1143 for (Engine *e : Engine::Iterate()) {
1144 /* Age the vehicle */
1145 if (e->flags.Test(EngineFlag::Available) && e->age != INT32_MAX) {
1146 e->age++;
1147 CalcEngineReliability(e, true);
1148 refresh = true;
1149 }
1150
1151 /* Do not introduce invalid engines */
1152 if (!e->IsEnabled()) continue;
1153
1154 if (!e->flags.Test(EngineFlag::Available) && TimerGameCalendar::date >= (e->intro_date + CalendarTime::DAYS_IN_YEAR)) {
1155 /* Introduce it to all companies */
1156 NewVehicleAvailable(e);
1157 } else if (!e->flags.Any({EngineFlag::Available, EngineFlag::ExclusivePreview}) && TimerGameCalendar::date >= e->intro_date) {
1158 /* Introduction date has passed...
1159 * Check if it is allowed to build this vehicle type at all
1160 * based on the current game settings. If not, it does not
1161 * make sense to show the preview dialog to any company. */
1162 if (IsVehicleTypeDisabled(e->type, false)) continue;
1163
1164 /* Do not introduce new rail wagons */
1165 if (IsWagon(e->index)) continue;
1166
1167 /* Engine has no preview */
1168 if (e->info.extra_flags.Test(ExtraEngineFlag::NoPreview)) continue;
1169
1170 /* Show preview dialog to one of the companies. */
1171 e->flags.Set(EngineFlag::ExclusivePreview);
1172 e->preview_company = CompanyID::Invalid();
1173 e->preview_asked = CompanyMask{};
1174 }
1175 }
1176
1177 InvalidateWindowClassesData(WC_BUILD_VEHICLE); // rebuild the purchase list (esp. when sorted by reliability)
1178
1179 if (refresh) {
1180 SetWindowClassesDirty(WC_BUILD_VEHICLE);
1181 SetWindowClassesDirty(WC_REPLACE_VEHICLE);
1182 }
1183 }
1184}
1185
1186static const IntervalTimer<TimerGameCalendar> _calendar_engines_monthly({TimerGameCalendar::MONTH, TimerGameCalendar::Priority::ENGINE}, [](auto)
1187{

Callers 2

ClickChangeDateCheatFunction · 0.85
engine.cppFile · 0.85

Calls 11

CalcEngineReliabilityFunction · 0.85
NewVehicleAvailableFunction · 0.85
IsVehicleTypeDisabledFunction · 0.85
IsWagonFunction · 0.85
InvalidFunction · 0.85
SetWindowClassesDirtyFunction · 0.85
TestMethod · 0.80
AnyMethod · 0.80
IsEnabledMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected