Update to 1.11.0-beta1
This commit is contained in:
@@ -62,12 +62,11 @@ const uint8 _engine_offsets[4] = {
|
||||
lengthof(_orig_rail_vehicle_info) + lengthof(_orig_road_vehicle_info) + lengthof(_orig_ship_vehicle_info),
|
||||
};
|
||||
|
||||
assert_compile(lengthof(_orig_rail_vehicle_info) + lengthof(_orig_road_vehicle_info) + lengthof(_orig_ship_vehicle_info) + lengthof(_orig_aircraft_vehicle_info) == lengthof(_orig_engine_info));
|
||||
static_assert(lengthof(_orig_rail_vehicle_info) + lengthof(_orig_road_vehicle_info) + lengthof(_orig_ship_vehicle_info) + lengthof(_orig_aircraft_vehicle_info) == lengthof(_orig_engine_info));
|
||||
|
||||
const uint EngineOverrideManager::NUM_DEFAULT_ENGINES = _engine_counts[VEH_TRAIN] + _engine_counts[VEH_ROAD] + _engine_counts[VEH_SHIP] + _engine_counts[VEH_AIRCRAFT];
|
||||
|
||||
Engine::Engine() :
|
||||
name(nullptr),
|
||||
overrides_count(0),
|
||||
overrides(nullptr)
|
||||
{
|
||||
@@ -140,7 +139,6 @@ Engine::Engine(VehicleType type, EngineID base)
|
||||
Engine::~Engine()
|
||||
{
|
||||
UnloadWagonOverrides(this);
|
||||
free(this->name);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -488,8 +486,7 @@ void EngineOverrideManager::ResetToDefaultMapping()
|
||||
this->clear();
|
||||
for (VehicleType type = VEH_TRAIN; type <= VEH_AIRCRAFT; type++) {
|
||||
for (uint internal_id = 0; internal_id < _engine_counts[type]; internal_id++) {
|
||||
/*C++17: EngineIDMapping &eid = */ this->emplace_back();
|
||||
EngineIDMapping &eid = this->back();
|
||||
EngineIDMapping &eid = this->emplace_back();
|
||||
eid.type = type;
|
||||
eid.grfid = INVALID_GRFID;
|
||||
eid.internal_id = internal_id;
|
||||
@@ -581,7 +578,7 @@ static void CalcEngineReliability(Engine *e)
|
||||
/* Check for early retirement */
|
||||
if (e->company_avail != 0 && !_settings_game.vehicle.never_expire_vehicles && e->info.base_life != 0xFF) {
|
||||
int retire_early = e->info.retire_early;
|
||||
uint retire_early_max_age = max(0, e->duration_phase_1 + e->duration_phase_2 - retire_early * 12);
|
||||
uint retire_early_max_age = std::max(0, e->duration_phase_1 + e->duration_phase_2 - retire_early * 12);
|
||||
if (retire_early != 0 && age >= retire_early_max_age) {
|
||||
/* Early retirement is enabled and we're past the date... */
|
||||
e->company_avail = 0;
|
||||
@@ -628,7 +625,7 @@ void SetYearEngineAgingStops()
|
||||
YearMonthDay ymd;
|
||||
ConvertDateToYMD(ei->base_intro + (ei->lifelength * DAYS_IN_LEAP_YEAR) / 2, &ymd);
|
||||
|
||||
_year_engine_aging_stops = max(_year_engine_aging_stops, ymd.year);
|
||||
_year_engine_aging_stops = std::max(_year_engine_aging_stops, ymd.year);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -646,9 +643,8 @@ void StartupOneEngine(Engine *e, Date aging_date)
|
||||
e->company_avail = 0;
|
||||
e->company_hidden = 0;
|
||||
|
||||
/* Don't randomise the start-date in the first two years after gamestart to ensure availability
|
||||
* of engines in early starting games.
|
||||
* Note: TTDP uses fixed 1922 */
|
||||
/* Vehicles with the same base_intro date shall be introduced at the same time.
|
||||
* Make sure they use the same randomisation of the date. */
|
||||
SavedRandomSeeds saved_seeds;
|
||||
SaveRandomSeeds(&saved_seeds);
|
||||
SetRandomSeed(_settings_game.game_creation.generation_seed ^
|
||||
@@ -657,6 +653,9 @@ void StartupOneEngine(Engine *e, Date aging_date)
|
||||
e->GetGRFID());
|
||||
uint32 r = Random();
|
||||
|
||||
/* Don't randomise the start-date in the first two years after gamestart to ensure availability
|
||||
* of engines in early starting games.
|
||||
* Note: TTDP uses fixed 1922 */
|
||||
e->intro_date = ei->base_intro <= ConvertYMDToDate(_settings_game.game_creation.starting_year + 2, 0, 1) ? ei->base_intro : (Date)GB(r, 0, 9) + ei->base_intro;
|
||||
if (e->intro_date <= _date) {
|
||||
e->age = (aging_date - e->intro_date) >> 5;
|
||||
@@ -664,19 +663,20 @@ void StartupOneEngine(Engine *e, Date aging_date)
|
||||
e->flags |= ENGINE_AVAILABLE;
|
||||
}
|
||||
|
||||
e->reliability_start = GB(r, 16, 14) + 0x7AE0;
|
||||
r = Random();
|
||||
e->reliability_max = GB(r, 0, 14) + 0xBFFF;
|
||||
e->reliability_final = GB(r, 16, 14) + 0x3FFF;
|
||||
RestoreRandomSeeds(saved_seeds);
|
||||
|
||||
r = Random();
|
||||
e->reliability_start = GB(r, 16, 14) + 0x7AE0;
|
||||
e->reliability_max = GB(r, 0, 14) + 0xBFFF;
|
||||
|
||||
r = Random();
|
||||
e->reliability_final = GB(r, 16, 14) + 0x3FFF;
|
||||
e->duration_phase_1 = GB(r, 0, 5) + 7;
|
||||
e->duration_phase_2 = GB(r, 5, 4) + ei->base_life * 12 - 96;
|
||||
e->duration_phase_3 = GB(r, 9, 7) + 120;
|
||||
|
||||
e->reliability_spd_dec = ei->decay_speed << 2;
|
||||
|
||||
RestoreRandomSeeds(saved_seeds);
|
||||
CalcEngineReliability(e);
|
||||
|
||||
/* prevent certain engines from ever appearing. */
|
||||
@@ -693,7 +693,7 @@ void StartupOneEngine(Engine *e, Date aging_date)
|
||||
void StartupEngines()
|
||||
{
|
||||
/* Aging of vehicles stops, so account for that when starting late */
|
||||
const Date aging_date = min(_date, ConvertYMDToDate(_year_engine_aging_stops, 0, 1));
|
||||
const Date aging_date = std::min(_date, ConvertYMDToDate(_year_engine_aging_stops, 0, 1));
|
||||
|
||||
for (Engine *e : Engine::Iterate()) {
|
||||
StartupOneEngine(e, aging_date);
|
||||
@@ -735,6 +735,7 @@ static void EnableEngineForCompany(EngineID eid, CompanyID company)
|
||||
InvalidateWindowData(WC_MAIN_TOOLBAR, 0);
|
||||
if (e->type == VEH_ROAD) InvalidateWindowData(WC_BUILD_TOOLBAR, TRANSPORT_ROAD);
|
||||
if (e->type == VEH_SHIP) InvalidateWindowData(WC_BUILD_TOOLBAR, TRANSPORT_WATER);
|
||||
if (e->type == VEH_AIRCRAFT) InvalidateWindowData(WC_BUILD_TOOLBAR, TRANSPORT_AIR);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1018,6 +1019,7 @@ static void NewVehicleAvailable(Engine *e)
|
||||
/* Update the toolbar. */
|
||||
if (e->type == VEH_ROAD) InvalidateWindowData(WC_BUILD_TOOLBAR, TRANSPORT_ROAD);
|
||||
if (e->type == VEH_SHIP) InvalidateWindowData(WC_BUILD_TOOLBAR, TRANSPORT_WATER);
|
||||
if (e->type == VEH_AIRCRAFT) InvalidateWindowData(WC_BUILD_TOOLBAR, TRANSPORT_AIR);
|
||||
|
||||
/* Close pending preview windows */
|
||||
DeleteWindowById(WC_ENGINE_PREVIEW, index);
|
||||
@@ -1069,7 +1071,7 @@ void EnginesMonthlyLoop()
|
||||
static bool IsUniqueEngineName(const char *name)
|
||||
{
|
||||
for (const Engine *e : Engine::Iterate()) {
|
||||
if (e->name != nullptr && strcmp(e->name, name) == 0) return false;
|
||||
if (!e->name.empty() && e->name == name) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -1097,12 +1099,10 @@ CommandCost CmdRenameEngine(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
|
||||
}
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
free(e->name);
|
||||
|
||||
if (reset) {
|
||||
e->name = nullptr;
|
||||
e->name.clear();
|
||||
} else {
|
||||
e->name = stredup(text);
|
||||
e->name = text;
|
||||
}
|
||||
|
||||
MarkWholeScreenDirty();
|
||||
@@ -1198,7 +1198,7 @@ void CheckEngines()
|
||||
if ((e->flags & ENGINE_AVAILABLE) != 0 && e->company_avail != 0) return;
|
||||
|
||||
/* Okay, try to find the earliest date. */
|
||||
min_date = min(min_date, e->info.base_intro);
|
||||
min_date = std::min(min_date, e->info.base_intro);
|
||||
}
|
||||
|
||||
if (min_date < INT32_MAX) {
|
||||
|
||||
Reference in New Issue
Block a user