summaryrefslogtreecommitdiff
path: root/src/script/api/script_newgrf.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/script/api/script_newgrf.cpp')
-rw-r--r--src/script/api/script_newgrf.cpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/script/api/script_newgrf.cpp b/src/script/api/script_newgrf.cpp
new file mode 100644
index 000000000..387093092
--- /dev/null
+++ b/src/script/api/script_newgrf.cpp
@@ -0,0 +1,58 @@
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+/** @file script_newgrf.cpp Implementation of ScriptNewGRF and friends. */
+
+#include "../../stdafx.h"
+#include "script_newgrf.hpp"
+#include "../../core/bitmath_func.hpp"
+#include "../../newgrf_config.h"
+#include "../../string_func.h"
+
+#include "../../safeguards.h"
+
+ScriptNewGRFList::ScriptNewGRFList()
+{
+ for (auto c = _grfconfig; c != nullptr; c = c->next) {
+ if (!HasBit(c->flags, GCF_STATIC)) {
+ this->AddItem(c->ident.grfid);
+ }
+ }
+}
+
+/* static */ bool ScriptNewGRF::IsLoaded(uint32 grfid)
+{
+ for (auto c = _grfconfig; c != nullptr; c = c->next) {
+ if (!HasBit(c->flags, GCF_STATIC) && c->ident.grfid == grfid) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+/* static */ uint32 ScriptNewGRF::GetVersion(uint32 grfid)
+{
+ for (auto c = _grfconfig; c != nullptr; c = c->next) {
+ if (!HasBit(c->flags, GCF_STATIC) && c->ident.grfid == grfid) {
+ return c->version;
+ }
+ }
+
+ return 0;
+}
+
+/* static */ char *ScriptNewGRF::GetName(uint32 grfid)
+{
+ for (auto c = _grfconfig; c != nullptr; c = c->next) {
+ if (!HasBit(c->flags, GCF_STATIC) && c->ident.grfid == grfid) {
+ return ::stredup(c->GetName());
+ }
+ }
+
+ return nullptr;
+}