From e5d30a33542fd5dc9f64ca5c6eac44f14fff4d62 Mon Sep 17 00:00:00 2001 From: SamuXarick <43006711+SamuXarick@users.noreply.github.com> Date: Thu, 15 Feb 2024 21:24:11 +0000 Subject: [PATCH] Add: [Script] ScriptAirportTypeList Add function to let GS and AI create lists of airport types. --- regression/regression/main.nut | 55 +++++++++++++++++++++++ regression/regression/result.txt | 27 +++++++++-- src/script/api/CMakeLists.txt | 2 + src/script/api/ai_changelog.hpp | 3 ++ src/script/api/game_changelog.hpp | 3 ++ src/script/api/script_airporttypelist.cpp | 25 +++++++++++ src/script/api/script_airporttypelist.hpp | 25 +++++++++++ 7 files changed, 137 insertions(+), 3 deletions(-) create mode 100644 src/script/api/script_airporttypelist.cpp create mode 100644 src/script/api/script_airporttypelist.hpp diff --git a/regression/regression/main.nut b/regression/regression/main.nut index fce258a739..ce6adad278 100644 --- a/regression/regression/main.nut +++ b/regression/regression/main.nut @@ -242,6 +242,60 @@ function Regression::Airport() print(" BuildAirport(): " + AIAirport.BuildAirport(32116, 0, AIStation.STATION_JOIN_ADJACENT)); } +function Regression::AirportTypeList() +{ + local list = AIAirportTypeList(); + + print(""); + print("--AirportTypeList--"); + print(" Count(): " + list.Count()); + list.Valuate(AIAirport.IsValidAirportType); + print(" IsValidAirportType ListDump:"); + for (local i = list.Begin(); !list.IsEnd(); i = list.Next()) { + print(" " + i + " => " + list.GetValue(i)); + } + list.Valuate(AIAirport.IsAirportInformationAvailable); + print(" IsAirportInformationAvailable ListDump:"); + for (local i = list.Begin(); !list.IsEnd(); i = list.Next()) { + print(" " + i + " => " + list.GetValue(i)); + } + list.Valuate(AIAirport.GetPrice); + print(" GetPrice ListDump:"); + for (local i = list.Begin(); !list.IsEnd(); i = list.Next()) { + print(" " + i + " => " + list.GetValue(i)); + } + list.Valuate(AIAirport.GetAirportWidth); + print(" GetAirportWidth ListDump:"); + for (local i = list.Begin(); !list.IsEnd(); i = list.Next()) { + print(" " + i + " => " + list.GetValue(i)); + } + list.Valuate(AIAirport.GetAirportHeight); + print(" GetAirportHeight ListDump:"); + for (local i = list.Begin(); !list.IsEnd(); i = list.Next()) { + print(" " + i + " => " + list.GetValue(i)); + } + list.Valuate(AIAirport.GetAirportCoverageRadius); + print(" GetAirportCoverageRadius ListDump:"); + for (local i = list.Begin(); !list.IsEnd(); i = list.Next()) { + print(" " + i + " => " + list.GetValue(i)); + } + list.Valuate(AIAirport.GetMaintenanceCostFactor); + print(" GetMaintenanceCostFactor ListDump:"); + for (local i = list.Begin(); !list.IsEnd(); i = list.Next()) { + print(" " + i + " => " + list.GetValue(i)); + } + list.Valuate(AIAirport.GetMonthlyMaintenanceCost); + print(" GetMonthlyMaintenanceCost ListDump:"); + for (local i = list.Begin(); !list.IsEnd(); i = list.Next()) { + print(" " + i + " => " + list.GetValue(i)); + } + list.Valuate(AIAirport.GetAirportNumHelipads); + print(" GetAirportNumHelipads ListDump:"); + for (local i = list.Begin(); !list.IsEnd(); i = list.Next()) { + print(" " + i + " => " + list.GetValue(i)); + } +} + function Regression::Bridge() { local j = 0; @@ -1987,6 +2041,7 @@ function Regression::Start() this.Commands(); this.Airport(); + this.AirportTypeList() this.Bridge(); this.BridgeList(); this.Cargo(); diff --git a/regression/regression/result.txt b/regression/regression/result.txt index 8eedd0d71e..1c038b7b6b 100644 --- a/regression/regression/result.txt +++ b/regression/regression/result.txt @@ -883,6 +883,27 @@ ERROR: IsEnd() is invalid as Begin() is never called GetBankBalance(): 1999989626 BuildAirport(): true +--AirportTypeList-- + Count(): 1 + IsValidAirportType ListDump: + 0 => 1 + IsAirportInformationAvailable ListDump: + 0 => 1 + GetPrice ListDump: + 0 => 5400 + GetAirportWidth ListDump: + 0 => 4 + GetAirportHeight ListDump: + 0 => 3 + GetAirportCoverageRadius ListDump: + 0 => 4 + GetMaintenanceCostFactor ListDump: + 0 => 7 + GetMonthlyMaintenanceCost ListDump: + 0 => 3281 + GetAirportNumHelipads ListDump: + 0 => 0 + --Bridge-- Bridge -1 IsValidBridge(): false @@ -9748,9 +9769,9 @@ ERROR: IsEnd() is invalid as Begin() is never called --Valuate() with excessive CPU usage-- Your script made an error: excessive CPU usage in valuator function -*FUNCTION [unknown()] regression/main.nut line [2051] +*FUNCTION [unknown()] regression/main.nut line [2106] *FUNCTION [Valuate()] NATIVE line [-1] -*FUNCTION [Start()] regression/main.nut line [2052] +*FUNCTION [Start()] regression/main.nut line [2107] [id] 0 [this] TABLE @@ -9759,7 +9780,7 @@ Your script made an error: excessive CPU usage in valuator function [this] INSTANCE Your script made an error: excessive CPU usage in valuator function -*FUNCTION [Start()] regression/main.nut line [2052] +*FUNCTION [Start()] regression/main.nut line [2107] [Infinite] CLOSURE [list] INSTANCE diff --git a/src/script/api/CMakeLists.txt b/src/script/api/CMakeLists.txt index 6a8cb66d9c..ed59941491 100644 --- a/src/script/api/CMakeLists.txt +++ b/src/script/api/CMakeLists.txt @@ -146,6 +146,7 @@ add_files( script_accounting.hpp script_admin.hpp script_airport.hpp + script_airporttypelist.hpp script_asyncmode.hpp script_base.hpp script_basestation.hpp @@ -221,6 +222,7 @@ add_files( script_accounting.cpp script_admin.cpp script_airport.cpp + script_airporttypelist.cpp script_asyncmode.cpp script_base.cpp script_basestation.cpp diff --git a/src/script/api/ai_changelog.hpp b/src/script/api/ai_changelog.hpp index e6b524a857..8bc8962ae8 100644 --- a/src/script/api/ai_changelog.hpp +++ b/src/script/api/ai_changelog.hpp @@ -17,6 +17,9 @@ * * This version is not yet released. The following changes are not set in stone yet. * + * API additions: + * \li AIAirportTypeList + * * \b 14.0 * * API additions: diff --git a/src/script/api/game_changelog.hpp b/src/script/api/game_changelog.hpp index 8ebf05310c..7470c8031a 100644 --- a/src/script/api/game_changelog.hpp +++ b/src/script/api/game_changelog.hpp @@ -17,6 +17,9 @@ * * This version is not yet released. The following changes are not set in stone yet. * + * API additions: + * \li GSAirportTypeList + * * \b 14.0 * * API additions: diff --git a/src/script/api/script_airporttypelist.cpp b/src/script/api/script_airporttypelist.cpp new file mode 100644 index 0000000000..9e96c706e0 --- /dev/null +++ b/src/script/api/script_airporttypelist.cpp @@ -0,0 +1,25 @@ +/* + * 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 . + */ + +/** @file script_airporttypelist.cpp Implementation of ScriptAirportTypeList and friends. */ + +#include "../../stdafx.h" +#include "script_airporttypelist.hpp" +#include "script_error.hpp" +#include "../../newgrf_airport.h" + +#include "../../safeguards.h" + + +ScriptAirportTypeList::ScriptAirportTypeList() +{ + EnforceDeityOrCompanyModeValid_Void(); + bool is_deity = ScriptCompanyMode::IsDeity(); + for (uint8_t at = 0; at < ::NUM_AIRPORTS; at++) { + if ((is_deity && ::AirportSpec::Get(at)->enabled) || ::AirportSpec::Get(at)->IsAvailable()) this->AddItem(at); + } +} diff --git a/src/script/api/script_airporttypelist.hpp b/src/script/api/script_airporttypelist.hpp new file mode 100644 index 0000000000..1f0269ccea --- /dev/null +++ b/src/script/api/script_airporttypelist.hpp @@ -0,0 +1,25 @@ +/* + * 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 . + */ + +/** @file script_airporttypelist.hpp List all available airport types. */ + +#ifndef SCRIPT_AIRPORTTYPELIST_HPP +#define SCRIPT_AIRPORTTYPELIST_HPP + +#include "script_list.hpp" + +/** + * Creates a list of all available airport types. + * @api ai game + * @ingroup ScriptList + */ +class ScriptAirportTypeList : public ScriptList { +public: + ScriptAirportTypeList(); +}; + +#endif /* SCRIPT_AIRPORTTYPELIST_HPP */