From f60b3d7f796840ab6d89d3a53d7c5431244aa4b7 Mon Sep 17 00:00:00 2001 From: Patric Stout Date: Sun, 9 Feb 2025 16:04:04 +0100 Subject: [PATCH] Codechange: [Script] rework how compat-scripts work and are loaded (#13504) - compat_NNN.nut files now only defines what is needed to downgrade from API NNN + 1 to NNN. - Automatically load all required compatibility files based on the API version of the script, starting with the latest. --- bin/ai/CMakeLists.txt | 1 - bin/ai/compat_0.7.nut | 142 +-------------------------------- bin/ai/compat_1.0.nut | 79 +----------------- bin/ai/compat_1.1.nut | 32 +------- bin/ai/compat_1.10.nut | 18 +---- bin/ai/compat_1.11.nut | 18 +---- bin/ai/compat_1.2.nut | 32 +------- bin/ai/compat_1.3.nut | 32 +------- bin/ai/compat_1.4.nut | 32 +------- bin/ai/compat_1.5.nut | 32 +------- bin/ai/compat_1.6.nut | 32 +------- bin/ai/compat_1.7.nut | 32 +------- bin/ai/compat_1.8.nut | 20 +---- bin/ai/compat_1.9.nut | 18 +---- bin/ai/compat_12.nut | 6 +- bin/ai/compat_13.nut | 5 +- bin/ai/compat_14.nut | 3 +- bin/ai/compat_15.nut | 6 -- bin/game/CMakeLists.txt | 1 - bin/game/compat_1.10.nut | 19 +---- bin/game/compat_1.11.nut | 17 +--- bin/game/compat_1.2.nut | 47 +---------- bin/game/compat_1.3.nut | 39 +-------- bin/game/compat_1.4.nut | 33 +------- bin/game/compat_1.5.nut | 32 +------- bin/game/compat_1.6.nut | 32 +------- bin/game/compat_1.7.nut | 32 +------- bin/game/compat_1.8.nut | 26 +----- bin/game/compat_1.9.nut | 25 +----- bin/game/compat_12.nut | 6 +- bin/game/compat_13.nut | 5 +- bin/game/compat_14.nut | 3 +- bin/game/compat_15.nut | 6 -- docs/releasing_openttd.md | 8 +- src/ai/ai_info.cpp | 3 +- src/ai/ai_info.hpp | 3 + src/ai/ai_instance.cpp | 2 +- src/game/game_info.cpp | 3 +- src/game/game_info.hpp | 3 + src/game/game_instance.cpp | 2 +- src/script/script_instance.cpp | 25 +++++- src/script/script_instance.hpp | 16 +++- 42 files changed, 78 insertions(+), 850 deletions(-) delete mode 100644 bin/ai/compat_15.nut delete mode 100644 bin/game/compat_15.nut diff --git a/bin/ai/CMakeLists.txt b/bin/ai/CMakeLists.txt index 8b54f74973..7fb23cada3 100644 --- a/bin/ai/CMakeLists.txt +++ b/bin/ai/CMakeLists.txt @@ -15,7 +15,6 @@ set(AI_COMPAT_SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/compat_12.nut ${CMAKE_CURRENT_SOURCE_DIR}/compat_13.nut ${CMAKE_CURRENT_SOURCE_DIR}/compat_14.nut - ${CMAKE_CURRENT_SOURCE_DIR}/compat_15.nut ) foreach(AI_COMPAT_SOURCE_FILE IN LISTS AI_COMPAT_SOURCE_FILES) diff --git a/bin/ai/compat_0.7.nut b/bin/ai/compat_0.7.nut index 0b2fa1f243..5f022d6709 100644 --- a/bin/ai/compat_0.7.nut +++ b/bin/ai/compat_0.7.nut @@ -5,7 +5,8 @@ * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see . */ -AILog.Info("0.7 API compatibility in effect:"); +/* This file contains code to downgrade the API from 1.0 to 0.7. */ + AILog.Info(" - AITown::GetLastMonthProduction's behaviour has slightly changed."); AILog.Info(" - AISubsidy::GetDestination returns STATION_INVALID for awarded subsidies."); AILog.Info(" - AISubsidy::GetSource returns STATION_INVALID for awarded subsidies."); @@ -256,142 +257,3 @@ class AIWaypointList extends _AIWaypointList { ::_AIWaypointList.constructor(AIWaypoint.WAYPOINT_RAIL); } } - -AIRoad._BuildRoadStation <- AIRoad.BuildRoadStation; -AIRoad.BuildRoadStation <- function(tile, front, road_veh_type, station_id) -{ - if (AIRoad.IsRoadStationTile(tile) && AICompany.IsMine(AITile.GetOwner(tile))) return false; - - return AIRoad._BuildRoadStation(tile, front, road_veh_type, station_id); -} - -AIRoad._BuildDriveThroughRoadStation <- AIRoad.BuildDriveThroughRoadStation; -AIRoad.BuildDriveThroughRoadStation <- function(tile, front, road_veh_type, station_id) -{ - if (AIRoad.IsRoadStationTile(tile) && AICompany.IsMine(AITile.GetOwner(tile))) return false; - - return AIRoad._BuildDriveThroughRoadStation(tile, front, road_veh_type, station_id); -} - -AIBridgeList.HasNext <- -AIBridgeList_Length.HasNext <- -AICargoList.HasNext <- -AICargoList_IndustryAccepting.HasNext <- -AICargoList_IndustryProducing.HasNext <- -AIDepotList.HasNext <- -AIEngineList.HasNext <- -AIGroupList.HasNext <- -AIIndustryList.HasNext <- -AIIndustryList_CargoAccepting.HasNext <- -AIIndustryList_CargoProducing.HasNext <- -AIIndustryTypeList.HasNext <- -AIList.HasNext <- -AIRailTypeList.HasNext <- -AISignList.HasNext <- -AIStationList.HasNext <- -AIStationList_Vehicle.HasNext <- -AISubsidyList.HasNext <- -AITileList.HasNext <- -AITileList_IndustryAccepting.HasNext <- -AITileList_IndustryProducing.HasNext <- -AITileList_StationType.HasNext <- -AITownList.HasNext <- -AIVehicleList.HasNext <- -AIVehicleList_DefaultGroup.HasNext <- -AIVehicleList_Group.HasNext <- -AIVehicleList_SharedOrders.HasNext <- -AIVehicleList_Station.HasNext <- -AIWaypointList.HasNext <- -AIWaypointList_Vehicle.HasNext <- -function() -{ - return !this.IsEnd(); -} - -AIIndustry._IsCargoAccepted <- AIIndustry.IsCargoAccepted; -AIIndustry.IsCargoAccepted <- function(industry_id, cargo_id) -{ - return AIIndustry._IsCargoAccepted(industry_id, cargo_id) != AIIndustry.CAS_NOT_ACCEPTED; -} - -AIAbstractList <- AIList; - -AIList.ChangeItem <- AIList.SetValue; - -AIRail.ERR_NONUNIFORM_STATIONS_DISABLED <- 0xFFFF; - -AICompany.GetCompanyValue <- function(company) -{ - return AICompany.GetQuarterlyCompanyValue(company, AICompany.CURRENT_QUARTER); -} - -AITown.GetLastMonthTransported <- AITown.GetLastMonthSupplied; - -AIEvent.AI_ET_INVALID <- AIEvent.ET_INVALID; -AIEvent.AI_ET_TEST <- AIEvent.ET_TEST; -AIEvent.AI_ET_SUBSIDY_OFFER <- AIEvent.ET_SUBSIDY_OFFER; -AIEvent.AI_ET_SUBSIDY_OFFER_EXPIRED <- AIEvent.ET_SUBSIDY_OFFER_EXPIRED; -AIEvent.AI_ET_SUBSIDY_AWARDED <- AIEvent.ET_SUBSIDY_AWARDED; -AIEvent.AI_ET_SUBSIDY_EXPIRED <- AIEvent.ET_SUBSIDY_EXPIRED; -AIEvent.AI_ET_ENGINE_PREVIEW <- AIEvent.ET_ENGINE_PREVIEW; -AIEvent.AI_ET_COMPANY_NEW <- AIEvent.ET_COMPANY_NEW; -AIEvent.AI_ET_COMPANY_IN_TROUBLE <- AIEvent.ET_COMPANY_IN_TROUBLE; -AIEvent.AI_ET_COMPANY_MERGER <- AIEvent.ET_COMPANY_MERGER; -AIEvent.AI_ET_COMPANY_BANKRUPT <- AIEvent.ET_COMPANY_BANKRUPT; -AIEvent.AI_ET_VEHICLE_CRASHED <- AIEvent.ET_VEHICLE_CRASHED; -AIEvent.AI_ET_VEHICLE_LOST <- AIEvent.ET_VEHICLE_LOST; -AIEvent.AI_ET_VEHICLE_WAITING_IN_DEPOT <- AIEvent.ET_VEHICLE_WAITING_IN_DEPOT; -AIEvent.AI_ET_VEHICLE_UNPROFITABLE <- AIEvent.ET_VEHICLE_UNPROFITABLE; -AIEvent.AI_ET_INDUSTRY_OPEN <- AIEvent.ET_INDUSTRY_OPEN; -AIEvent.AI_ET_INDUSTRY_CLOSE <- AIEvent.ET_INDUSTRY_CLOSE; -AIEvent.AI_ET_ENGINE_AVAILABLE <- AIEvent.ET_ENGINE_AVAILABLE; -AIEvent.AI_ET_STATION_FIRST_VEHICLE <- AIEvent.ET_STATION_FIRST_VEHICLE; -AIEvent.AI_ET_DISASTER_ZEPPELINER_CRASHED <- AIEvent.ET_DISASTER_ZEPPELINER_CRASHED; -AIEvent.AI_ET_DISASTER_ZEPPELINER_CLEARED <- AIEvent.ET_DISASTER_ZEPPELINER_CLEARED; -AIOrder.AIOF_NONE <- AIOrder.OF_NONE -AIOrder.AIOF_NON_STOP_INTERMEDIATE <- AIOrder.OF_NON_STOP_INTERMEDIATE -AIOrder.AIOF_NON_STOP_DESTINATION <- AIOrder.OF_NON_STOP_DESTINATION -AIOrder.AIOF_UNLOAD <- AIOrder.OF_UNLOAD -AIOrder.AIOF_TRANSFER <- AIOrder.OF_TRANSFER -AIOrder.AIOF_NO_UNLOAD <- AIOrder.OF_NO_UNLOAD -AIOrder.AIOF_FULL_LOAD <- AIOrder.OF_FULL_LOAD -AIOrder.AIOF_FULL_LOAD_ANY <- AIOrder.OF_FULL_LOAD_ANY -AIOrder.AIOF_NO_LOAD <- AIOrder.OF_NO_LOAD -AIOrder.AIOF_SERVICE_IF_NEEDED <- AIOrder.OF_SERVICE_IF_NEEDED -AIOrder.AIOF_STOP_IN_DEPOT <- AIOrder.OF_STOP_IN_DEPOT -AIOrder.AIOF_GOTO_NEAREST_DEPOT <- AIOrder.OF_GOTO_NEAREST_DEPOT -AIOrder.AIOF_NON_STOP_FLAGS <- AIOrder.OF_NON_STOP_FLAGS -AIOrder.AIOF_UNLOAD_FLAGS <- AIOrder.OF_UNLOAD_FLAGS -AIOrder.AIOF_LOAD_FLAGS <- AIOrder.OF_LOAD_FLAGS -AIOrder.AIOF_DEPOT_FLAGS <- AIOrder.OF_DEPOT_FLAGS -AIOrder.AIOF_INVALID <- AIOrder.OF_INVALID - -/* 1.9 adds a vehicle type parameter. */ -AIBridge._GetName <- AIBridge.GetName; -AIBridge.GetName <- function(bridge_id) -{ - return AIBridge._GetName(bridge_id, AIVehicle.VT_RAIL); -} - -/* 1.9 adds parent_group_id to CreateGroup function */ -AIGroup._CreateGroup <- AIGroup.CreateGroup; -AIGroup.CreateGroup <- function(vehicle_type) -{ - return AIGroup._CreateGroup(vehicle_type, AIGroup.GROUP_INVALID); -} - -/* 13 really checks RoadType against RoadType */ -AIRoad._HasRoadType <- AIRoad.HasRoadType; -AIRoad.HasRoadType <- function(tile, road_type) -{ - local list = AIRoadTypeList(AIRoad.GetRoadTramType(road_type)); - foreach (rt, _ in list) { - if (AIRoad._HasRoadType(tile, rt)) { - return true; - } - } - return false; -} - -/* 15 renames GetBridgeID */ -AIBridge.GetBridgeID <- AIBridge.GetBridgeType; diff --git a/bin/ai/compat_1.0.nut b/bin/ai/compat_1.0.nut index bf3b8334e6..f656e4cb4e 100644 --- a/bin/ai/compat_1.0.nut +++ b/bin/ai/compat_1.0.nut @@ -5,7 +5,7 @@ * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see . */ -AILog.Info("1.0 API compatibility in effect."); +/* This file contains code to downgrade the API from 1.1 to 1.0. */ AIRoad._BuildRoadStation <- AIRoad.BuildRoadStation; AIRoad.BuildRoadStation <- function(tile, front, road_veh_type, station_id) @@ -70,80 +70,3 @@ AIAbstractList <- AIList; AIList.ChangeItem <- AIList.SetValue; AIRail.ERR_NONUNIFORM_STATIONS_DISABLED <- 0xFFFF; - -AICompany.GetCompanyValue <- function(company) -{ - return AICompany.GetQuarterlyCompanyValue(company, AICompany.CURRENT_QUARTER); -} - -AITown.GetLastMonthTransported <- AITown.GetLastMonthSupplied; - -AIEvent.AI_ET_INVALID <- AIEvent.ET_INVALID; -AIEvent.AI_ET_TEST <- AIEvent.ET_TEST; -AIEvent.AI_ET_SUBSIDY_OFFER <- AIEvent.ET_SUBSIDY_OFFER; -AIEvent.AI_ET_SUBSIDY_OFFER_EXPIRED <- AIEvent.ET_SUBSIDY_OFFER_EXPIRED; -AIEvent.AI_ET_SUBSIDY_AWARDED <- AIEvent.ET_SUBSIDY_AWARDED; -AIEvent.AI_ET_SUBSIDY_EXPIRED <- AIEvent.ET_SUBSIDY_EXPIRED; -AIEvent.AI_ET_ENGINE_PREVIEW <- AIEvent.ET_ENGINE_PREVIEW; -AIEvent.AI_ET_COMPANY_NEW <- AIEvent.ET_COMPANY_NEW; -AIEvent.AI_ET_COMPANY_IN_TROUBLE <- AIEvent.ET_COMPANY_IN_TROUBLE; -AIEvent.AI_ET_COMPANY_ASK_MERGER <- AIEvent.ET_COMPANY_ASK_MERGER; -AIEvent.AI_ET_COMPANY_MERGER <- AIEvent.ET_COMPANY_MERGER; -AIEvent.AI_ET_COMPANY_BANKRUPT <- AIEvent.ET_COMPANY_BANKRUPT; -AIEvent.AI_ET_VEHICLE_CRASHED <- AIEvent.ET_VEHICLE_CRASHED; -AIEvent.AI_ET_VEHICLE_LOST <- AIEvent.ET_VEHICLE_LOST; -AIEvent.AI_ET_VEHICLE_WAITING_IN_DEPOT <- AIEvent.ET_VEHICLE_WAITING_IN_DEPOT; -AIEvent.AI_ET_VEHICLE_UNPROFITABLE <- AIEvent.ET_VEHICLE_UNPROFITABLE; -AIEvent.AI_ET_INDUSTRY_OPEN <- AIEvent.ET_INDUSTRY_OPEN; -AIEvent.AI_ET_INDUSTRY_CLOSE <- AIEvent.ET_INDUSTRY_CLOSE; -AIEvent.AI_ET_ENGINE_AVAILABLE <- AIEvent.ET_ENGINE_AVAILABLE; -AIEvent.AI_ET_STATION_FIRST_VEHICLE <- AIEvent.ET_STATION_FIRST_VEHICLE; -AIEvent.AI_ET_DISASTER_ZEPPELINER_CRASHED <- AIEvent.ET_DISASTER_ZEPPELINER_CRASHED; -AIEvent.AI_ET_DISASTER_ZEPPELINER_CLEARED <- AIEvent.ET_DISASTER_ZEPPELINER_CLEARED; -AIOrder.AIOF_NONE <- AIOrder.OF_NONE -AIOrder.AIOF_NON_STOP_INTERMEDIATE <- AIOrder.OF_NON_STOP_INTERMEDIATE -AIOrder.AIOF_NON_STOP_DESTINATION <- AIOrder.OF_NON_STOP_DESTINATION -AIOrder.AIOF_UNLOAD <- AIOrder.OF_UNLOAD -AIOrder.AIOF_TRANSFER <- AIOrder.OF_TRANSFER -AIOrder.AIOF_NO_UNLOAD <- AIOrder.OF_NO_UNLOAD -AIOrder.AIOF_FULL_LOAD <- AIOrder.OF_FULL_LOAD -AIOrder.AIOF_FULL_LOAD_ANY <- AIOrder.OF_FULL_LOAD_ANY -AIOrder.AIOF_NO_LOAD <- AIOrder.OF_NO_LOAD -AIOrder.AIOF_SERVICE_IF_NEEDED <- AIOrder.OF_SERVICE_IF_NEEDED -AIOrder.AIOF_STOP_IN_DEPOT <- AIOrder.OF_STOP_IN_DEPOT -AIOrder.AIOF_GOTO_NEAREST_DEPOT <- AIOrder.OF_GOTO_NEAREST_DEPOT -AIOrder.AIOF_NON_STOP_FLAGS <- AIOrder.OF_NON_STOP_FLAGS -AIOrder.AIOF_UNLOAD_FLAGS <- AIOrder.OF_UNLOAD_FLAGS -AIOrder.AIOF_LOAD_FLAGS <- AIOrder.OF_LOAD_FLAGS -AIOrder.AIOF_DEPOT_FLAGS <- AIOrder.OF_DEPOT_FLAGS -AIOrder.AIOF_INVALID <- AIOrder.OF_INVALID - -/* 1.9 adds a vehicle type parameter. */ -AIBridge._GetName <- AIBridge.GetName; -AIBridge.GetName <- function(bridge_id) -{ - return AIBridge._GetName(bridge_id, AIVehicle.VT_RAIL); -} - -/* 1.9 adds parent_group_id to CreateGroup function */ -AIGroup._CreateGroup <- AIGroup.CreateGroup; -AIGroup.CreateGroup <- function(vehicle_type) -{ - return AIGroup._CreateGroup(vehicle_type, AIGroup.GROUP_INVALID); -} - -/* 13 really checks RoadType against RoadType */ -AIRoad._HasRoadType <- AIRoad.HasRoadType; -AIRoad.HasRoadType <- function(tile, road_type) -{ - local list = AIRoadTypeList(AIRoad.GetRoadTramType(road_type)); - foreach (rt, _ in list) { - if (AIRoad._HasRoadType(tile, rt)) { - return true; - } - } - return false; -} - -/* 15 renames GetBridgeID */ -AIBridge.GetBridgeID <- AIBridge.GetBridgeType; diff --git a/bin/ai/compat_1.1.nut b/bin/ai/compat_1.1.nut index 456b054aba..eed756e1e3 100644 --- a/bin/ai/compat_1.1.nut +++ b/bin/ai/compat_1.1.nut @@ -5,7 +5,7 @@ * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see . */ -AILog.Info("1.1 API compatibility in effect."); +/* This file contains code to downgrade the API from 1.2 to 1.1. */ AICompany.GetCompanyValue <- function(company) { @@ -54,33 +54,3 @@ AIOrder.AIOF_UNLOAD_FLAGS <- AIOrder.OF_UNLOAD_FLAGS AIOrder.AIOF_LOAD_FLAGS <- AIOrder.OF_LOAD_FLAGS AIOrder.AIOF_DEPOT_FLAGS <- AIOrder.OF_DEPOT_FLAGS AIOrder.AIOF_INVALID <- AIOrder.OF_INVALID - -/* 1.9 adds a vehicle type parameter. */ -AIBridge._GetName <- AIBridge.GetName; -AIBridge.GetName <- function(bridge_id) -{ - return AIBridge._GetName(bridge_id, AIVehicle.VT_RAIL); -} - -/* 1.9 adds parent_group_id to CreateGroup function */ -AIGroup._CreateGroup <- AIGroup.CreateGroup; -AIGroup.CreateGroup <- function(vehicle_type) -{ - return AIGroup._CreateGroup(vehicle_type, AIGroup.GROUP_INVALID); -} - -/* 13 really checks RoadType against RoadType */ -AIRoad._HasRoadType <- AIRoad.HasRoadType; -AIRoad.HasRoadType <- function(tile, road_type) -{ - local list = AIRoadTypeList(AIRoad.GetRoadTramType(road_type)); - foreach (rt, _ in list) { - if (AIRoad._HasRoadType(tile, rt)) { - return true; - } - } - return false; -} - -/* 15 renames GetBridgeID */ -AIBridge.GetBridgeID <- AIBridge.GetBridgeType; diff --git a/bin/ai/compat_1.10.nut b/bin/ai/compat_1.10.nut index 9b82efdcb3..0a7c37c638 100644 --- a/bin/ai/compat_1.10.nut +++ b/bin/ai/compat_1.10.nut @@ -5,20 +5,4 @@ * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see . */ -AILog.Info("1.10 API compatibility in effect."); - -/* 13 really checks RoadType against RoadType */ -AIRoad._HasRoadType <- AIRoad.HasRoadType; -AIRoad.HasRoadType <- function(tile, road_type) -{ - local list = AIRoadTypeList(AIRoad.GetRoadTramType(road_type)); - foreach (rt, _ in list) { - if (AIRoad._HasRoadType(tile, rt)) { - return true; - } - } - return false; -} - -/* 15 renames GetBridgeID */ -AIBridge.GetBridgeID <- AIBridge.GetBridgeType; +/* This file contains code to downgrade the API from 1.11 to 1.10. */ diff --git a/bin/ai/compat_1.11.nut b/bin/ai/compat_1.11.nut index 1b6bc4da04..ca44c2d9fe 100644 --- a/bin/ai/compat_1.11.nut +++ b/bin/ai/compat_1.11.nut @@ -5,20 +5,4 @@ * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see . */ -AILog.Info("1.11 API compatibility in effect."); - -/* 13 really checks RoadType against RoadType */ -AIRoad._HasRoadType <- AIRoad.HasRoadType; -AIRoad.HasRoadType <- function(tile, road_type) -{ - local list = AIRoadTypeList(AIRoad.GetRoadTramType(road_type)); - foreach (rt, _ in list) { - if (AIRoad._HasRoadType(tile, rt)) { - return true; - } - } - return false; -} - -/* 15 renames GetBridgeID */ -AIBridge.GetBridgeID <- AIBridge.GetBridgeType; +/* This file contains code to downgrade the API from 12 to 1.11. */ diff --git a/bin/ai/compat_1.2.nut b/bin/ai/compat_1.2.nut index 75ffd93d66..23bf995eff 100644 --- a/bin/ai/compat_1.2.nut +++ b/bin/ai/compat_1.2.nut @@ -5,34 +5,4 @@ * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see . */ -AILog.Info("1.2 API compatibility in effect."); - -/* 1.9 adds a vehicle type parameter. */ -AIBridge._GetName <- AIBridge.GetName; -AIBridge.GetName <- function(bridge_id) -{ - return AIBridge._GetName(bridge_id, AIVehicle.VT_RAIL); -} - -/* 1.9 adds parent_group_id to CreateGroup function */ -AIGroup._CreateGroup <- AIGroup.CreateGroup; -AIGroup.CreateGroup <- function(vehicle_type) -{ - return AIGroup._CreateGroup(vehicle_type, AIGroup.GROUP_INVALID); -} - -/* 13 really checks RoadType against RoadType */ -AIRoad._HasRoadType <- AIRoad.HasRoadType; -AIRoad.HasRoadType <- function(tile, road_type) -{ - local list = AIRoadTypeList(AIRoad.GetRoadTramType(road_type)); - foreach (rt, _ in list) { - if (AIRoad._HasRoadType(tile, rt)) { - return true; - } - } - return false; -} - -/* 15 renames GetBridgeID */ -AIBridge.GetBridgeID <- AIBridge.GetBridgeType; +/* This file contains code to downgrade the API from 1.3 to 1.2. */ diff --git a/bin/ai/compat_1.3.nut b/bin/ai/compat_1.3.nut index 5bc97c2cb2..6ebdb7350c 100644 --- a/bin/ai/compat_1.3.nut +++ b/bin/ai/compat_1.3.nut @@ -5,34 +5,4 @@ * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see . */ -AILog.Info("1.3 API compatibility in effect."); - -/* 1.9 adds a vehicle type parameter. */ -AIBridge._GetName <- AIBridge.GetName; -AIBridge.GetName <- function(bridge_id) -{ - return AIBridge._GetName(bridge_id, AIVehicle.VT_RAIL); -} - -/* 1.9 adds parent_group_id to CreateGroup function */ -AIGroup._CreateGroup <- AIGroup.CreateGroup; -AIGroup.CreateGroup <- function(vehicle_type) -{ - return AIGroup._CreateGroup(vehicle_type, AIGroup.GROUP_INVALID); -} - -/* 13 really checks RoadType against RoadType */ -AIRoad._HasRoadType <- AIRoad.HasRoadType; -AIRoad.HasRoadType <- function(tile, road_type) -{ - local list = AIRoadTypeList(AIRoad.GetRoadTramType(road_type)); - foreach (rt, _ in list) { - if (AIRoad._HasRoadType(tile, rt)) { - return true; - } - } - return false; -} - -/* 15 renames GetBridgeID */ -AIBridge.GetBridgeID <- AIBridge.GetBridgeType; +/* This file contains code to downgrade the API from 1.4 to 1.3. */ diff --git a/bin/ai/compat_1.4.nut b/bin/ai/compat_1.4.nut index 5700c6bfb8..ab752521a6 100644 --- a/bin/ai/compat_1.4.nut +++ b/bin/ai/compat_1.4.nut @@ -5,34 +5,4 @@ * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see . */ -AILog.Info("1.4 API compatibility in effect."); - -/* 1.9 adds a vehicle type parameter. */ -AIBridge._GetName <- AIBridge.GetName; -AIBridge.GetName <- function(bridge_id) -{ - return AIBridge._GetName(bridge_id, AIVehicle.VT_RAIL); -} - -/* 1.9 adds parent_group_id to CreateGroup function */ -AIGroup._CreateGroup <- AIGroup.CreateGroup; -AIGroup.CreateGroup <- function(vehicle_type) -{ - return AIGroup._CreateGroup(vehicle_type, AIGroup.GROUP_INVALID); -} - -/* 13 really checks RoadType against RoadType */ -AIRoad._HasRoadType <- AIRoad.HasRoadType; -AIRoad.HasRoadType <- function(tile, road_type) -{ - local list = AIRoadTypeList(AIRoad.GetRoadTramType(road_type)); - foreach (rt, _ in list) { - if (AIRoad._HasRoadType(tile, rt)) { - return true; - } - } - return false; -} - -/* 15 renames GetBridgeID */ -AIBridge.GetBridgeID <- AIBridge.GetBridgeType; +/* This file contains code to downgrade the API from 1.5 to 1.4. */ diff --git a/bin/ai/compat_1.5.nut b/bin/ai/compat_1.5.nut index 88f4221b4e..5113c41b87 100644 --- a/bin/ai/compat_1.5.nut +++ b/bin/ai/compat_1.5.nut @@ -5,34 +5,4 @@ * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see . */ -AILog.Info("1.5 API compatibility in effect."); - -/* 1.9 adds a vehicle type parameter. */ -AIBridge._GetName <- AIBridge.GetName; -AIBridge.GetName <- function(bridge_id) -{ - return AIBridge._GetName(bridge_id, AIVehicle.VT_RAIL); -} - -/* 1.9 adds parent_group_id to CreateGroup function */ -AIGroup._CreateGroup <- AIGroup.CreateGroup; -AIGroup.CreateGroup <- function(vehicle_type) -{ - return AIGroup._CreateGroup(vehicle_type, AIGroup.GROUP_INVALID); -} - -/* 13 really checks RoadType against RoadType */ -AIRoad._HasRoadType <- AIRoad.HasRoadType; -AIRoad.HasRoadType <- function(tile, road_type) -{ - local list = AIRoadTypeList(AIRoad.GetRoadTramType(road_type)); - foreach (rt, _ in list) { - if (AIRoad._HasRoadType(tile, rt)) { - return true; - } - } - return false; -} - -/* 15 renames GetBridgeID */ -AIBridge.GetBridgeID <- AIBridge.GetBridgeType; +/* This file contains code to downgrade the API from 1.6 to 1.5. */ diff --git a/bin/ai/compat_1.6.nut b/bin/ai/compat_1.6.nut index 4ddb4c5bcb..c320c9db66 100644 --- a/bin/ai/compat_1.6.nut +++ b/bin/ai/compat_1.6.nut @@ -5,34 +5,4 @@ * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see . */ -AILog.Info("1.6 API compatibility in effect."); - -/* 1.9 adds a vehicle type parameter. */ -AIBridge._GetName <- AIBridge.GetName; -AIBridge.GetName <- function(bridge_id) -{ - return AIBridge._GetName(bridge_id, AIVehicle.VT_RAIL); -} - -/* 1.9 adds parent_group_id to CreateGroup function */ -AIGroup._CreateGroup <- AIGroup.CreateGroup; -AIGroup.CreateGroup <- function(vehicle_type) -{ - return AIGroup._CreateGroup(vehicle_type, AIGroup.GROUP_INVALID); -} - -/* 13 really checks RoadType against RoadType */ -AIRoad._HasRoadType <- AIRoad.HasRoadType; -AIRoad.HasRoadType <- function(tile, road_type) -{ - local list = AIRoadTypeList(AIRoad.GetRoadTramType(road_type)); - foreach (rt, _ in list) { - if (AIRoad._HasRoadType(tile, rt)) { - return true; - } - } - return false; -} - -/* 15 renames GetBridgeID */ -AIBridge.GetBridgeID <- AIBridge.GetBridgeType; +/* This file contains code to downgrade the API from 1.7 to 1.6. */ diff --git a/bin/ai/compat_1.7.nut b/bin/ai/compat_1.7.nut index 557f13bdc3..1e8814c5e2 100644 --- a/bin/ai/compat_1.7.nut +++ b/bin/ai/compat_1.7.nut @@ -5,34 +5,4 @@ * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see . */ -AILog.Info("1.7 API compatibility in effect."); - -/* 1.9 adds a vehicle type parameter. */ -AIBridge._GetName <- AIBridge.GetName; -AIBridge.GetName <- function(bridge_id) -{ - return AIBridge._GetName(bridge_id, AIVehicle.VT_RAIL); -} - -/* 1.9 adds parent_group_id to CreateGroup function */ -AIGroup._CreateGroup <- AIGroup.CreateGroup; -AIGroup.CreateGroup <- function(vehicle_type) -{ - return AIGroup._CreateGroup(vehicle_type, AIGroup.GROUP_INVALID); -} - -/* 13 really checks RoadType against RoadType */ -AIRoad._HasRoadType <- AIRoad.HasRoadType; -AIRoad.HasRoadType <- function(tile, road_type) -{ - local list = AIRoadTypeList(AIRoad.GetRoadTramType(road_type)); - foreach (rt, _ in list) { - if (AIRoad._HasRoadType(tile, rt)) { - return true; - } - } - return false; -} - -/* 15 renames GetBridgeID */ -AIBridge.GetBridgeID <- AIBridge.GetBridgeType; +/* This file contains code to downgrade the API from 1.8 to 1.7. */ diff --git a/bin/ai/compat_1.8.nut b/bin/ai/compat_1.8.nut index 8e99a2c0c1..eaacb0350a 100644 --- a/bin/ai/compat_1.8.nut +++ b/bin/ai/compat_1.8.nut @@ -5,34 +5,16 @@ * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see . */ -AILog.Info("1.8 API compatibility in effect."); +/* This file contains code to downgrade the API from 1.9 to 1.8. */ -/* 1.9 adds a vehicle type parameter. */ AIBridge._GetName <- AIBridge.GetName; AIBridge.GetName <- function(bridge_id) { return AIBridge._GetName(bridge_id, AIVehicle.VT_RAIL); } -/* 1.9 adds parent_group_id to CreateGroup function */ AIGroup._CreateGroup <- AIGroup.CreateGroup; AIGroup.CreateGroup <- function(vehicle_type) { return AIGroup._CreateGroup(vehicle_type, AIGroup.GROUP_INVALID); } - -/* 13 really checks RoadType against RoadType */ -AIRoad._HasRoadType <- AIRoad.HasRoadType; -AIRoad.HasRoadType <- function(tile, road_type) -{ - local list = AIRoadTypeList(AIRoad.GetRoadTramType(road_type)); - foreach (rt, _ in list) { - if (AIRoad._HasRoadType(tile, rt)) { - return true; - } - } - return false; -} - -/* 15 renames GetBridgeID */ -AIBridge.GetBridgeID <- AIBridge.GetBridgeType; diff --git a/bin/ai/compat_1.9.nut b/bin/ai/compat_1.9.nut index 8301ebb4b8..76da9d2c39 100644 --- a/bin/ai/compat_1.9.nut +++ b/bin/ai/compat_1.9.nut @@ -5,20 +5,4 @@ * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see . */ -AILog.Info("1.9 API compatibility in effect."); - -/* 13 really checks RoadType against RoadType */ -AIRoad._HasRoadType <- AIRoad.HasRoadType; -AIRoad.HasRoadType <- function(tile, road_type) -{ - local list = AIRoadTypeList(AIRoad.GetRoadTramType(road_type)); - foreach (rt, _ in list) { - if (AIRoad._HasRoadType(tile, rt)) { - return true; - } - } - return false; -} - -/* 15 renames GetBridgeID */ -AIBridge.GetBridgeID <- AIBridge.GetBridgeType; +/* This file contains code to downgrade the API from 1.10 to 1.9. */ diff --git a/bin/ai/compat_12.nut b/bin/ai/compat_12.nut index 3ac3c66cb7..67ca36c7c9 100644 --- a/bin/ai/compat_12.nut +++ b/bin/ai/compat_12.nut @@ -5,9 +5,8 @@ * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see . */ -AILog.Info("12 API compatibility in effect."); +/* This file contains code to downgrade the API from 13 to 12. */ -/* 13 really checks RoadType against RoadType */ AIRoad._HasRoadType <- AIRoad.HasRoadType; AIRoad.HasRoadType <- function(tile, road_type) { @@ -19,6 +18,3 @@ AIRoad.HasRoadType <- function(tile, road_type) } return false; } - -/* 15 renames GetBridgeID */ -AIBridge.GetBridgeID <- AIBridge.GetBridgeType; diff --git a/bin/ai/compat_13.nut b/bin/ai/compat_13.nut index 42311e8001..a5e69f706a 100644 --- a/bin/ai/compat_13.nut +++ b/bin/ai/compat_13.nut @@ -5,7 +5,4 @@ * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see . */ -AILog.Info("13 API compatibility in effect."); - -/* 15 renames GetBridgeID */ -AIBridge.GetBridgeID <- AIBridge.GetBridgeType; +/* This file contains code to downgrade the API from 14 to 13. */ diff --git a/bin/ai/compat_14.nut b/bin/ai/compat_14.nut index a303139a69..80cdb50b32 100644 --- a/bin/ai/compat_14.nut +++ b/bin/ai/compat_14.nut @@ -5,7 +5,6 @@ * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see . */ -AILog.Info("14 API compatibility in effect."); +/* This file contains code to downgrade the API from 15 to 14. */ -/* 15 renames GetBridgeID */ AIBridge.GetBridgeID <- AIBridge.GetBridgeType; diff --git a/bin/ai/compat_15.nut b/bin/ai/compat_15.nut deleted file mode 100644 index 3081fb58e8..0000000000 --- a/bin/ai/compat_15.nut +++ /dev/null @@ -1,6 +0,0 @@ -/* - * This file is part of OpenTTD. - * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. - * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see . - */ diff --git a/bin/game/CMakeLists.txt b/bin/game/CMakeLists.txt index d0b5448997..0b48e97857 100644 --- a/bin/game/CMakeLists.txt +++ b/bin/game/CMakeLists.txt @@ -12,7 +12,6 @@ set(GS_COMPAT_SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/compat_12.nut ${CMAKE_CURRENT_SOURCE_DIR}/compat_13.nut ${CMAKE_CURRENT_SOURCE_DIR}/compat_14.nut - ${CMAKE_CURRENT_SOURCE_DIR}/compat_15.nut ) foreach(GS_COMPAT_SOURCE_FILE IN LISTS GS_COMPAT_SOURCE_FILES) diff --git a/bin/game/compat_1.10.nut b/bin/game/compat_1.10.nut index 01a611075a..5381508b74 100644 --- a/bin/game/compat_1.10.nut +++ b/bin/game/compat_1.10.nut @@ -5,27 +5,10 @@ * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see . */ -GSLog.Info("1.10 API compatibility in effect."); +/* This file contains code to downgrade the API from 1.11 to 1.10. */ -/* 1.11 adds a tile parameter. */ GSCompany._ChangeBankBalance <- GSCompany.ChangeBankBalance; GSCompany.ChangeBankBalance <- function(company, delta, expenses_type) { return GSCompany._ChangeBankBalance(company, delta, expenses_type, GSMap.TILE_INVALID); } - -/* 13 really checks RoadType against RoadType */ -GSRoad._HasRoadType <- GSRoad.HasRoadType; -GSRoad.HasRoadType <- function(tile, road_type) -{ - local list = GSRoadTypeList(GSRoad.GetRoadTramType(road_type)); - foreach (rt, _ in list) { - if (GSRoad._HasRoadType(tile, rt)) { - return true; - } - } - return false; -} - -/* 15 renames GetBridgeID */ -GSBridge.GetBridgeID <- GSBridge.GetBridgeType; diff --git a/bin/game/compat_1.11.nut b/bin/game/compat_1.11.nut index 9cee3efe3b..471a2a402f 100644 --- a/bin/game/compat_1.11.nut +++ b/bin/game/compat_1.11.nut @@ -5,20 +5,5 @@ * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see . */ -GSLog.Info("1.11 API compatibility in effect."); +/* This file contains code to downgrade the API from 12 to 1.11. */ -/* 13 really checks RoadType against RoadType */ -GSRoad._HasRoadType <- GSRoad.HasRoadType; -GSRoad.HasRoadType <- function(tile, road_type) -{ - local list = GSRoadTypeList(GSRoad.GetRoadTramType(road_type)); - foreach (rt, _ in list) { - if (GSRoad._HasRoadType(tile, rt)) { - return true; - } - } - return false; -} - -/* 15 renames GetBridgeID */ -GSBridge.GetBridgeID <- GSBridge.GetBridgeType; diff --git a/bin/game/compat_1.2.nut b/bin/game/compat_1.2.nut index 662b8a8602..23bf995eff 100644 --- a/bin/game/compat_1.2.nut +++ b/bin/game/compat_1.2.nut @@ -5,49 +5,4 @@ * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see . */ -GSLog.Info("1.2 API compatibility in effect."); - -GSTown._SetGrowthRate <- GSTown.SetGrowthRate; -GSTown.SetGrowthRate <- function(town_id, days_between_town_growth) -{ - /* Growth rate 0 caused resetting the custom growth rate. While this was undocumented, it was used nevertheless (ofc). */ - if (days_between_town_growth == 0) days_between_town_growth = GSTown.TOWN_GROWTH_NORMAL; - return GSTown._SetGrowthRate(town_id, days_between_town_growth); -} - -/* 1.5 adds a game element reference to the news. */ -GSNews._Create <- GSNews.Create; -GSNews.Create <- function(type, text, company) -{ - return GSNews._Create(type, text, company, GSNews.NR_NONE, 0); -} - -/* 1.9 adds a vehicle type parameter. */ -GSBridge._GetName <- GSBridge.GetName; -GSBridge.GetName <- function(bridge_id) -{ - return GSBridge._GetName(bridge_id, GSVehicle.VT_RAIL); -} - -/* 1.11 adds a tile parameter. */ -GSCompany._ChangeBankBalance <- GSCompany.ChangeBankBalance; -GSCompany.ChangeBankBalance <- function(company, delta, expenses_type) -{ - return GSCompany._ChangeBankBalance(company, delta, expenses_type, GSMap.TILE_INVALID); -} - -/* 13 really checks RoadType against RoadType */ -GSRoad._HasRoadType <- GSRoad.HasRoadType; -GSRoad.HasRoadType <- function(tile, road_type) -{ - local list = GSRoadTypeList(GSRoad.GetRoadTramType(road_type)); - foreach (rt, _ in list) { - if (GSRoad._HasRoadType(tile, rt)) { - return true; - } - } - return false; -} - -/* 15 renames GetBridgeID */ -GSBridge.GetBridgeID <- GSBridge.GetBridgeType; +/* This file contains code to downgrade the API from 1.3 to 1.2. */ diff --git a/bin/game/compat_1.3.nut b/bin/game/compat_1.3.nut index 6dd74c008d..9d89986d5e 100644 --- a/bin/game/compat_1.3.nut +++ b/bin/game/compat_1.3.nut @@ -5,7 +5,7 @@ * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see . */ -GSLog.Info("1.3 API compatibility in effect."); +/* This file contains code to downgrade the API from 1.4 to 1.3. */ GSTown._SetGrowthRate <- GSTown.SetGrowthRate; GSTown.SetGrowthRate <- function(town_id, days_between_town_growth) @@ -14,40 +14,3 @@ GSTown.SetGrowthRate <- function(town_id, days_between_town_growth) if (days_between_town_growth == 0) days_between_town_growth = GSTown.TOWN_GROWTH_NORMAL; return GSTown._SetGrowthRate(town_id, days_between_town_growth); } - -/* 1.5 adds a game element reference to the news. */ -GSNews._Create <- GSNews.Create; -GSNews.Create <- function(type, text, company) -{ - return GSNews._Create(type, text, company, GSNews.NR_NONE, 0); -} - -/* 1.9 adds a vehicle type parameter. */ -GSBridge._GetName <- GSBridge.GetName; -GSBridge.GetName <- function(bridge_id) -{ - return GSBridge._GetName(bridge_id, GSVehicle.VT_RAIL); -} - -/* 1.11 adds a tile parameter. */ -GSCompany._ChangeBankBalance <- GSCompany.ChangeBankBalance; -GSCompany.ChangeBankBalance <- function(company, delta, expenses_type) -{ - return GSCompany._ChangeBankBalance(company, delta, expenses_type, GSMap.TILE_INVALID); -} - -/* 13 really checks RoadType against RoadType */ -GSRoad._HasRoadType <- GSRoad.HasRoadType; -GSRoad.HasRoadType <- function(tile, road_type) -{ - local list = GSRoadTypeList(GSRoad.GetRoadTramType(road_type)); - foreach (rt, _ in list) { - if (GSRoad._HasRoadType(tile, rt)) { - return true; - } - } - return false; -} - -/* 15 renames GetBridgeID */ -GSBridge.GetBridgeID <- GSBridge.GetBridgeType; diff --git a/bin/game/compat_1.4.nut b/bin/game/compat_1.4.nut index 1d53a60642..57f8ea5aea 100644 --- a/bin/game/compat_1.4.nut +++ b/bin/game/compat_1.4.nut @@ -5,41 +5,10 @@ * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see . */ -GSLog.Info("1.4 API compatibility in effect."); +/* This file contains code to downgrade the API from 1.5 to 1.4 */ -/* 1.5 adds a game element reference to the news. */ GSNews._Create <- GSNews.Create; GSNews.Create <- function(type, text, company) { return GSNews._Create(type, text, company, GSNews.NR_NONE, 0); } - -/* 1.9 adds a vehicle type parameter. */ -GSBridge._GetName <- GSBridge.GetName; -GSBridge.GetName <- function(bridge_id) -{ - return GSBridge._GetName(bridge_id, GSVehicle.VT_RAIL); -} - -/* 1.11 adds a tile parameter. */ -GSCompany._ChangeBankBalance <- GSCompany.ChangeBankBalance; -GSCompany.ChangeBankBalance <- function(company, delta, expenses_type) -{ - return GSCompany._ChangeBankBalance(company, delta, expenses_type, GSMap.TILE_INVALID); -} - -/* 13 really checks RoadType against RoadType */ -GSRoad._HasRoadType <- GSRoad.HasRoadType; -GSRoad.HasRoadType <- function(tile, road_type) -{ - local list = GSRoadTypeList(GSRoad.GetRoadTramType(road_type)); - foreach (rt, _ in list) { - if (GSRoad._HasRoadType(tile, rt)) { - return true; - } - } - return false; -} - -/* 15 renames GetBridgeID */ -GSBridge.GetBridgeID <- GSBridge.GetBridgeType; diff --git a/bin/game/compat_1.5.nut b/bin/game/compat_1.5.nut index 05fb05253b..5113c41b87 100644 --- a/bin/game/compat_1.5.nut +++ b/bin/game/compat_1.5.nut @@ -5,34 +5,4 @@ * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see . */ -GSLog.Info("1.5 API compatibility in effect."); - -/* 1.9 adds a vehicle type parameter. */ -GSBridge._GetName <- GSBridge.GetName; -GSBridge.GetName <- function(bridge_id) -{ - return GSBridge._GetName(bridge_id, GSVehicle.VT_RAIL); -} - -/* 1.11 adds a tile parameter. */ -GSCompany._ChangeBankBalance <- GSCompany.ChangeBankBalance; -GSCompany.ChangeBankBalance <- function(company, delta, expenses_type) -{ - return GSCompany._ChangeBankBalance(company, delta, expenses_type, GSMap.TILE_INVALID); -} - -/* 13 really checks RoadType against RoadType */ -GSRoad._HasRoadType <- GSRoad.HasRoadType; -GSRoad.HasRoadType <- function(tile, road_type) -{ - local list = GSRoadTypeList(GSRoad.GetRoadTramType(road_type)); - foreach (rt, _ in list) { - if (GSRoad._HasRoadType(tile, rt)) { - return true; - } - } - return false; -} - -/* 15 renames GetBridgeID */ -GSBridge.GetBridgeID <- GSBridge.GetBridgeType; +/* This file contains code to downgrade the API from 1.6 to 1.5. */ diff --git a/bin/game/compat_1.6.nut b/bin/game/compat_1.6.nut index 0ee37890d5..c320c9db66 100644 --- a/bin/game/compat_1.6.nut +++ b/bin/game/compat_1.6.nut @@ -5,34 +5,4 @@ * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see . */ -GSLog.Info("1.6 API compatibility in effect."); - -/* 1.9 adds a vehicle type parameter. */ -GSBridge._GetName <- GSBridge.GetName; -GSBridge.GetName <- function(bridge_id) -{ - return GSBridge._GetName(bridge_id, GSVehicle.VT_RAIL); -} - -/* 1.11 adds a tile parameter. */ -GSCompany._ChangeBankBalance <- GSCompany.ChangeBankBalance; -GSCompany.ChangeBankBalance <- function(company, delta, expenses_type) -{ - return GSCompany._ChangeBankBalance(company, delta, expenses_type, GSMap.TILE_INVALID); -} - -/* 13 really checks RoadType against RoadType */ -GSRoad._HasRoadType <- GSRoad.HasRoadType; -GSRoad.HasRoadType <- function(tile, road_type) -{ - local list = GSRoadTypeList(GSRoad.GetRoadTramType(road_type)); - foreach (rt, _ in list) { - if (GSRoad._HasRoadType(tile, rt)) { - return true; - } - } - return false; -} - -/* 15 renames GetBridgeID */ -GSBridge.GetBridgeID <- GSBridge.GetBridgeType; +/* This file contains code to downgrade the API from 1.7 to 1.6. */ diff --git a/bin/game/compat_1.7.nut b/bin/game/compat_1.7.nut index 33f607b7f0..1e8814c5e2 100644 --- a/bin/game/compat_1.7.nut +++ b/bin/game/compat_1.7.nut @@ -5,34 +5,4 @@ * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see . */ -GSLog.Info("1.7 API compatibility in effect."); - -/* 1.9 adds a vehicle type parameter. */ -GSBridge._GetName <- GSBridge.GetName; -GSBridge.GetName <- function(bridge_id) -{ - return GSBridge._GetName(bridge_id, GSVehicle.VT_RAIL); -} - -/* 1.11 adds a tile parameter. */ -GSCompany._ChangeBankBalance <- GSCompany.ChangeBankBalance; -GSCompany.ChangeBankBalance <- function(company, delta, expenses_type) -{ - return GSCompany._ChangeBankBalance(company, delta, expenses_type, GSMap.TILE_INVALID); -} - -/* 13 really checks RoadType against RoadType */ -GSRoad._HasRoadType <- GSRoad.HasRoadType; -GSRoad.HasRoadType <- function(tile, road_type) -{ - local list = GSRoadTypeList(GSRoad.GetRoadTramType(road_type)); - foreach (rt, _ in list) { - if (GSRoad._HasRoadType(tile, rt)) { - return true; - } - } - return false; -} - -/* 15 renames GetBridgeID */ -GSBridge.GetBridgeID <- GSBridge.GetBridgeType; +/* This file contains code to downgrade the API from 1.8 to 1.7. */ diff --git a/bin/game/compat_1.8.nut b/bin/game/compat_1.8.nut index 9723add99a..34360f4132 100644 --- a/bin/game/compat_1.8.nut +++ b/bin/game/compat_1.8.nut @@ -5,34 +5,10 @@ * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see . */ -GSLog.Info("1.8 API compatibility in effect."); +/* This file contains code to downgrade the API from 1.9 to 1.8. */ -/* 1.9 adds a vehicle type parameter. */ GSBridge._GetName <- GSBridge.GetName; GSBridge.GetName <- function(bridge_id) { return GSBridge._GetName(bridge_id, GSVehicle.VT_RAIL); } - -/* 1.11 adds a tile parameter. */ -GSCompany._ChangeBankBalance <- GSCompany.ChangeBankBalance; -GSCompany.ChangeBankBalance <- function(company, delta, expenses_type) -{ - return GSCompany._ChangeBankBalance(company, delta, expenses_type, GSMap.TILE_INVALID); -} - -/* 13 really checks RoadType against RoadType */ -GSRoad._HasRoadType <- GSRoad.HasRoadType; -GSRoad.HasRoadType <- function(tile, road_type) -{ - local list = GSRoadTypeList(GSRoad.GetRoadTramType(road_type)); - foreach (rt, _ in list) { - if (GSRoad._HasRoadType(tile, rt)) { - return true; - } - } - return false; -} - -/* 15 renames GetBridgeID */ -GSBridge.GetBridgeID <- GSBridge.GetBridgeType; diff --git a/bin/game/compat_1.9.nut b/bin/game/compat_1.9.nut index f9e3b42797..76da9d2c39 100644 --- a/bin/game/compat_1.9.nut +++ b/bin/game/compat_1.9.nut @@ -5,27 +5,4 @@ * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see . */ -GSLog.Info("1.9 API compatibility in effect."); - -/* 1.11 adds a tile parameter. */ -GSCompany._ChangeBankBalance <- GSCompany.ChangeBankBalance; -GSCompany.ChangeBankBalance <- function(company, delta, expenses_type) -{ - return GSCompany._ChangeBankBalance(company, delta, expenses_type, GSMap.TILE_INVALID); -} - -/* 13 really checks RoadType against RoadType */ -GSRoad._HasRoadType <- GSRoad.HasRoadType; -GSRoad.HasRoadType <- function(tile, road_type) -{ - local list = GSRoadTypeList(GSRoad.GetRoadTramType(road_type)); - foreach (rt, _ in list) { - if (GSRoad._HasRoadType(tile, rt)) { - return true; - } - } - return false; -} - -/* 15 renames GetBridgeID */ -GSBridge.GetBridgeID <- GSBridge.GetBridgeType; +/* This file contains code to downgrade the API from 1.10 to 1.9. */ diff --git a/bin/game/compat_12.nut b/bin/game/compat_12.nut index e2e263bd49..c9e2cb22c2 100644 --- a/bin/game/compat_12.nut +++ b/bin/game/compat_12.nut @@ -5,9 +5,8 @@ * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see . */ -GSLog.Info("12 API compatibility in effect."); +/* This file contains code to downgrade the API from 13 to 12. */ -/* 13 really checks RoadType against RoadType */ GSRoad._HasRoadType <- GSRoad.HasRoadType; GSRoad.HasRoadType <- function(tile, road_type) { @@ -19,6 +18,3 @@ GSRoad.HasRoadType <- function(tile, road_type) } return false; } - -/* 15 renames GetBridgeID */ -GSBridge.GetBridgeID <- GSBridge.GetBridgeType; diff --git a/bin/game/compat_13.nut b/bin/game/compat_13.nut index a9dc9cd87d..a5e69f706a 100644 --- a/bin/game/compat_13.nut +++ b/bin/game/compat_13.nut @@ -5,7 +5,4 @@ * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see . */ -GSLog.Info("13 API compatibility in effect."); - -/* 15 renames GetBridgeID */ -GSBridge.GetBridgeID <- GSBridge.GetBridgeType; +/* This file contains code to downgrade the API from 14 to 13. */ diff --git a/bin/game/compat_14.nut b/bin/game/compat_14.nut index 9115d8bcfa..c6c3b7b740 100644 --- a/bin/game/compat_14.nut +++ b/bin/game/compat_14.nut @@ -5,7 +5,6 @@ * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see . */ -GSLog.Info("14 API compatibility in effect."); +/* This file contains code to downgrade the API from 15 to 14. */ -/* 15 renames GetBridgeID */ GSBridge.GetBridgeID <- GSBridge.GetBridgeType; diff --git a/bin/game/compat_15.nut b/bin/game/compat_15.nut deleted file mode 100644 index 3081fb58e8..0000000000 --- a/bin/game/compat_15.nut +++ /dev/null @@ -1,6 +0,0 @@ -/* - * This file is part of OpenTTD. - * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. - * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see . - */ diff --git a/docs/releasing_openttd.md b/docs/releasing_openttd.md index d0cc591b65..b229f2c333 100644 --- a/docs/releasing_openttd.md +++ b/docs/releasing_openttd.md @@ -8,10 +8,10 @@ This guide is for OpenTTD developers/maintainers, to release a new version of Op * If this is an RC1 (first Release Candidate) build, create a new branch `release/nn` where `nn` is the major version number, then apply changes similar to [PR#9573](https://github.com/OpenTTD/OpenTTD/pull/9573). You also need to forwardport the changelog, as in [PR#10113](https://github.com/OpenTTD/OpenTTD/pull/10113). * Update the version in `CMakeLists.txt` in the master branch, heading for the next major release, e.g. from 14.0 to 15.0. - * Add a new (empty) AI compatibility script in `bin/ai/` - * Add the new version to CheckAPIVersion in `src/ai/ai_info.cpp` and `src/game/game_info.cpp` - * Add the new version to `src/script/api/ai_changelog.hpp` and `src/script/api/game_changelog.hpp` - * Update the version of regression in `bin/ai/regression/regression_info.nut` + * Add the new version to `ApiVersions` in `src/ai/ai_info.hpp` and `src/game/game_info.hpp`. + * Add the new version to `src/script/api/ai_changelog.hpp` and `src/script/api/game_changelog.hpp`. + * Update the version of regression in `bin/ai/regression/regression_info.nut`. + * Add a new (empty) AI compatibility script in `bin/ai/` and `bin/game/` for the version of the branch. * Add a note to `src/saveload/saveload.h` about which savegame version is used in the branch. * If this is a later RC or release build and the release branch already exists, you'll need to backport fixes and language from master to this branch, which were merged after the branch diverged from master. You can use these two helper scripts: https://github.com/OpenTTD/scripts/tree/main/backport diff --git a/src/ai/ai_info.cpp b/src/ai/ai_info.cpp index fccfd94871..3ca90d9499 100644 --- a/src/ai/ai_info.cpp +++ b/src/ai/ai_info.cpp @@ -24,8 +24,7 @@ */ static bool CheckAPIVersion(const std::string &api_version) { - static const std::set versions = { "0.7", "1.0", "1.1", "1.2", "1.3", "1.4", "1.5", "1.6", "1.7", "1.8", "1.9", "1.10", "1.11", "12", "13", "14", "15" }; - return versions.find(api_version) != versions.end(); + return std::ranges::find(AIInfo::ApiVersions, api_version) != AIInfo::ApiVersions.end(); } #if defined(_WIN32) diff --git a/src/ai/ai_info.hpp b/src/ai/ai_info.hpp index df8e6b65d7..baf1b9f56b 100644 --- a/src/ai/ai_info.hpp +++ b/src/ai/ai_info.hpp @@ -15,6 +15,9 @@ /** All static information from an AI like name, version, etc. */ class AIInfo : public ScriptInfo { public: + /* All valid AI API versions, in order. */ + static constexpr std::initializer_list ApiVersions{ "0.7", "1.0", "1.1", "1.2", "1.3", "1.4", "1.5", "1.6", "1.7", "1.8", "1.9", "1.10", "1.11", "12", "13", "14", "15" }; + AIInfo(); /** diff --git a/src/ai/ai_instance.cpp b/src/ai/ai_instance.cpp index db4db4b819..cb9ccd3965 100644 --- a/src/ai/ai_instance.cpp +++ b/src/ai/ai_instance.cpp @@ -54,7 +54,7 @@ void AIInstance::RegisterAPI() /* Register all classes */ SQAI_RegisterAll(this->engine); - if (!this->LoadCompatibilityScripts(this->versionAPI, AI_DIR)) this->Died(); + if (!this->LoadCompatibilityScripts(AI_DIR, AIInfo::ApiVersions)) this->Died(); } void AIInstance::Died() diff --git a/src/game/game_info.cpp b/src/game/game_info.cpp index bdc94d7399..ad2dc9c109 100644 --- a/src/game/game_info.cpp +++ b/src/game/game_info.cpp @@ -22,8 +22,7 @@ */ static bool CheckAPIVersion(const std::string &api_version) { - static const std::set versions = { "1.2", "1.3", "1.4", "1.5", "1.6", "1.7", "1.8", "1.9", "1.10", "1.11", "12", "13", "14", "15" }; - return versions.find(api_version) != versions.end(); + return std::ranges::find(GameInfo::ApiVersions, api_version) != GameInfo::ApiVersions.end(); } #if defined(_WIN32) diff --git a/src/game/game_info.hpp b/src/game/game_info.hpp index d5dd48701d..f54c9a51ce 100644 --- a/src/game/game_info.hpp +++ b/src/game/game_info.hpp @@ -15,6 +15,9 @@ /** All static information from an Game like name, version, etc. */ class GameInfo : public ScriptInfo { public: + /* All valid GameScript API versions, in order. */ + static constexpr std::initializer_list ApiVersions{ "1.2", "1.3", "1.4", "1.5", "1.6", "1.7", "1.8", "1.9", "1.10", "1.11", "12", "13", "14", "15" }; + GameInfo(); /** diff --git a/src/game/game_instance.cpp b/src/game/game_instance.cpp index 3dbbc7b056..13888f2432 100644 --- a/src/game/game_instance.cpp +++ b/src/game/game_instance.cpp @@ -50,7 +50,7 @@ void GameInstance::RegisterAPI() RegisterGameTranslation(this->engine); - if (!this->LoadCompatibilityScripts(this->versionAPI, GAME_DIR)) this->Died(); + if (!this->LoadCompatibilityScripts(GAME_DIR, GameInfo::ApiVersions)) this->Died(); } int GameInstance::GetSetting(const std::string &name) diff --git a/src/script/script_instance.cpp b/src/script/script_instance.cpp index 91a15acb6e..c8062d719a 100644 --- a/src/script/script_instance.cpp +++ b/src/script/script_instance.cpp @@ -116,9 +116,10 @@ void ScriptInstance::RegisterAPI() squirrel_register_std(this->engine); } -bool ScriptInstance::LoadCompatibilityScripts(const std::string &api_version, Subdirectory dir) +bool ScriptInstance::LoadCompatibilityScript(std::string_view api_version, Subdirectory dir) { std::string script_name = fmt::format("compat_{}.nut", api_version); + for (Searchpath sp : _valid_searchpaths) { std::string buf = FioGetDirectory(sp, dir); buf += script_name; @@ -126,12 +127,30 @@ bool ScriptInstance::LoadCompatibilityScripts(const std::string &api_version, Su if (this->engine->LoadScript(buf)) return true; - ScriptLog::Error("Failed to load API compatibility script"); + ScriptLog::Error(fmt::format("Failed to load API compatibility script for {}", api_version)); Debug(script, 0, "Error compiling / running API compatibility script: {}", buf); return false; } - ScriptLog::Warning("API compatibility script not found"); + ScriptLog::Warning(fmt::format("API compatibility script for {} not found", api_version)); + return true; +} + +bool ScriptInstance::LoadCompatibilityScripts(Subdirectory dir, std::span api_versions) +{ + /* Don't try to load compatibility scripts for the current version. */ + if (this->versionAPI == std::rbegin(api_versions)->data()) return true; + + ScriptLog::Info(fmt::format("Downgrading API to be compatible with version {}", this->versionAPI)); + + /* Downgrade the API till we are the same version as the script. The last + * entry in the list is always the current version, so skip that one. */ + for (auto it = std::rbegin(api_versions) + 1; it != std::rend(api_versions); ++it) { + if (!this->LoadCompatibilityScript(*it, dir)) return false; + + if (*it == this->versionAPI) break; + } + return true; } diff --git a/src/script/script_instance.hpp b/src/script/script_instance.hpp index d937e22484..1d772fc084 100644 --- a/src/script/script_instance.hpp +++ b/src/script/script_instance.hpp @@ -261,11 +261,11 @@ protected: /** * Load squirrel scripts to emulate an older API. - * @param api_version: API version to load scripts for - * @param dir Subdirectory to find the scripts in - * @return true iff script loading should proceed + * @param dir Subdirectory to find the scripts in. + * @param api_versions List of available versions of the script type. + * @return true iff script loading should proceed. */ - bool LoadCompatibilityScripts(const std::string &api_version, Subdirectory dir); + bool LoadCompatibilityScripts(Subdirectory dir, std::span api_versions); /** * Tell the script it died. @@ -302,6 +302,14 @@ private: */ bool CallLoad(); + /** + * Load squirrel script for a specific version to emulate an older API. + * @param api_version: API version to load scripts for. + * @param dir Subdirectory to find the scripts in. + * @return true iff script loading should proceed. + */ + bool LoadCompatibilityScript(std::string_view api_version, Subdirectory dir); + /** * Save one object (int / string / array / table) to the savegame. * @param vm The virtual machine to get all the data from.