mirror of https://github.com/OpenTTD/OpenTTD.git
Add: [Script] Basic information about loaded NewGRFs for scripts. (#9464)
Currently, scripts use various heuristics to detect loaded NewGRFs that are inherently unreliable. The list of loaded NewGRFs is easily accessible to a human player, and thus giving scripts the same information is consistent with the current approach to not give scripts more information than a human player.
This commit is contained in:
parent
d58772ecda
commit
8706dcd9c1
|
@ -179,6 +179,7 @@ add_files(
|
|||
script_log.hpp
|
||||
script_map.hpp
|
||||
script_marine.hpp
|
||||
script_newgrf.hpp
|
||||
script_news.hpp
|
||||
script_object.hpp
|
||||
script_order.hpp
|
||||
|
@ -246,6 +247,7 @@ add_files(
|
|||
script_log.cpp
|
||||
script_map.cpp
|
||||
script_marine.cpp
|
||||
script_newgrf.cpp
|
||||
script_news.cpp
|
||||
script_object.cpp
|
||||
script_order.cpp
|
||||
|
|
|
@ -17,6 +17,10 @@
|
|||
*
|
||||
* This version is not yet released. The following changes are not set in stone yet.
|
||||
*
|
||||
* API additions:
|
||||
* \li AINewGRF
|
||||
* \li AINewGRFList
|
||||
*
|
||||
* \b 1.11.0
|
||||
*
|
||||
* API additions:
|
||||
|
|
|
@ -17,6 +17,10 @@
|
|||
*
|
||||
* This version is not yet released. The following changes are not set in stone yet.
|
||||
*
|
||||
* API additions:
|
||||
* \li GSNewGRF
|
||||
* \li GSNewGRFList
|
||||
*
|
||||
* \b 1.11.0
|
||||
*
|
||||
* API additions:
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* 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.hpp NewGRF info for scripts. */
|
||||
|
||||
#ifndef SCRIPT_NEWGRF_HPP
|
||||
#define SCRIPT_NEWGRF_HPP
|
||||
|
||||
#include "script_list.hpp"
|
||||
|
||||
/**
|
||||
* Create a list of loaded NewGRFs.
|
||||
* @api ai game
|
||||
* @ingroup ScriptList
|
||||
*/
|
||||
class ScriptNewGRFList : public ScriptList {
|
||||
public:
|
||||
ScriptNewGRFList();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Class that handles all NewGRF related functions.
|
||||
* @api ai game
|
||||
*/
|
||||
class ScriptNewGRF : public ScriptObject {
|
||||
public:
|
||||
/**
|
||||
* Check if a NewGRF with a given grfid is loaded.
|
||||
* @param grfid The grfid to check.
|
||||
* @return True if and only if a NewGRF with the given grfid is loaded in the game.
|
||||
*/
|
||||
static bool IsLoaded(uint32 grfid);
|
||||
|
||||
/**
|
||||
* Get the version of a loaded NewGRF.
|
||||
* @param grfid The NewGRF to query.
|
||||
* @pre ScriptNewGRF::IsLoaded(grfid).
|
||||
* @return Version of the NewGRF or 0 if the NewGRF specifies no version.
|
||||
*/
|
||||
static uint32 GetVersion(uint32 grfid);
|
||||
|
||||
/**
|
||||
* Get the BridgeID of a bridge at a given tile.
|
||||
* @param grfid The NewGRF to query.
|
||||
* @pre ScriptNewGRF::IsLoaded(grfid).
|
||||
* @return The name of the NewGRF or nullptr if no name is defined.
|
||||
*/
|
||||
static char *GetName(uint32 grfid);
|
||||
};
|
||||
|
||||
#endif /* SCRIPT_NEWGRF_HPP */
|
Loading…
Reference in New Issue