diff --git a/src/cargopacket.cpp b/src/cargopacket.cpp index 9b96be62eb..22d0acd139 100644 --- a/src/cargopacket.cpp +++ b/src/cargopacket.cpp @@ -658,6 +658,7 @@ uint VehicleCargoList::Unload(uint max_move, StationCargoList *dest, CargoPaymen uint VehicleCargoList::Truncate(uint max_move) { max_move = min(this->count, max_move); + if (max_move > this->ActionCount(MTA_KEEP)) this->KeepAll(); this->PopCargo(CargoRemoval(this, max_move)); return max_move; } diff --git a/src/lang/english.txt b/src/lang/english.txt index 38de89c6eb..07df9f1474 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -1265,6 +1265,9 @@ STR_CONFIG_SETTING_INFRASTRUCTURE_MAINTENANCE_HELPTEXT :When enabled, i STR_CONFIG_SETTING_SHIP_COLLISION_AVOIDANCE :Ships avoid collisions: {STRING2} STR_CONFIG_SETTING_SHIP_COLLISION_AVOIDANCE_HELPTEXT :When enabled, ships try to avoid passing through each other. Requires 90° turns to be forbidden. +STR_CONFIG_SETTING_NO_TRAIN_CRASH_OTHER_COMPANY :Trains from different companies may not crash into each other: {STRING2} +STR_CONFIG_SETTING_NO_TRAIN_CRASH_OTHER_COMPANY_HELPTEXT :This setting is primarily to prevent untrusted players deliberately causing crashes involving other companies' trains in multi-player rail infrastructure sharing games. + STR_CONFIG_SETTING_NEVER_EXPIRE_AIRPORTS :Airports never expire: {STRING2} STR_CONFIG_SETTING_NEVER_EXPIRE_AIRPORTS_HELPTEXT :Enabling this setting makes each airport type stay available forever after its introduction diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index 06bf155e7e..9224f25415 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -1724,6 +1724,7 @@ static SettingsContainer &GetSettingsTree() disasters->Add(new SettingEntry("difficulty.vehicle_breakdowns")); disasters->Add(new SettingEntry("vehicle.improved_breakdowns")); disasters->Add(new SettingEntry("vehicle.plane_crashes")); + disasters->Add(new SettingEntry("vehicle.no_train_crash_other_company")); } SettingsPage *genworld = main->Add(new SettingsPage(STR_CONFIG_SETTING_GENWORLD)); diff --git a/src/settings_type.h b/src/settings_type.h index 0c0601b7b3..8998fc9639 100644 --- a/src/settings_type.h +++ b/src/settings_type.h @@ -514,6 +514,7 @@ struct VehicleSettings { bool pay_for_repair; ///< pay for repairing vehicle uint8 repair_cost; ///< cost of repairing vehicle bool ship_collision_avoidance; ///< ships try to avoid colliding with each other + bool no_train_crash_other_company; ///< trains cannot crash with trains from other companies }; /** Settings related to the economy. */ diff --git a/src/table/settings.ini b/src/table/settings.ini index cfea2be15c..e5cce4feb2 100644 --- a/src/table/settings.ini +++ b/src/table/settings.ini @@ -1289,6 +1289,15 @@ strhelp = STR_CONFIG_SETTING_SHIP_COLLISION_AVOIDANCE_HELPTEXT patxname = ""ship_collision_avoidance.vehicle.ship_collision_avoidance"" cat = SC_BASIC +[SDT_BOOL] +base = GameSettings +var = vehicle.no_train_crash_other_company +def = false +str = STR_CONFIG_SETTING_NO_TRAIN_CRASH_OTHER_COMPANY +strhelp = STR_CONFIG_SETTING_NO_TRAIN_CRASH_OTHER_COMPANY_HELPTEXT +extver = SlXvFeatureTest(XSLFTO_AND, XSLFI_INFRA_SHARING) +patxname = ""infra_sharing.vehicle.no_train_crash_other_company"" + ; station.join_stations [SDT_NULL] length = 1 diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 211cfe6519..09024c7508 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -3298,6 +3298,11 @@ static Vehicle *FindTrainCollideEnum(Vehicle *v, void *data) /* not a train or in depot */ if (v->type != VEH_TRAIN || Train::From(v)->track == TRACK_BIT_DEPOT) return NULL; + if (_settings_game.vehicle.no_train_crash_other_company) { + /* do not crash into trains of another company. */ + if (v->owner != tcc->v->owner) return NULL; + } + /* get first vehicle now to make most usual checks faster */ Train *coll = Train::From(v)->First();