Changeset - r25876:7da167ac72e9
[Not reviewed]
master
0 2 0
Michael Lutz - 3 years ago 2021-08-10 19:09:35
michi@icosahedron.de
Fix 8706dcd9: [Script] Byte-swap grfids to match normal expectations.
2 files changed with 8 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/script/api/script_newgrf.cpp
Show inline comments
 
@@ -16,41 +16,47 @@
 
#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);
 
			this->AddItem(BSWAP32(c->ident.grfid));
 
		}
 
	}
 
}
 

	
 
/* static */ bool ScriptNewGRF::IsLoaded(uint32 grfid)
 
{
 
	grfid = BSWAP32(grfid); // Match people's expectations.
 

	
 
	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)
 
{
 
	grfid = BSWAP32(grfid); // Match people's expectations.
 

	
 
	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)
 
{
 
	grfid = BSWAP32(grfid); // Match people's expectations.
 

	
 
	for (auto c = _grfconfig; c != nullptr; c = c->next) {
 
		if (!HasBit(c->flags, GCF_STATIC) && c->ident.grfid == grfid) {
 
			return ::stredup(c->GetName());
 
		}
 
	}
 

	
src/script/api/script_newgrf.hpp
Show inline comments
 
@@ -42,13 +42,13 @@ public:
 
	 * @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.
 
	 * Get the name of a loaded NewGRF.
 
	 * @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);
 
};
0 comments (0 inline, 0 general)