Changeset - r26979:a9bdfd2db2b5
[Not reviewed]
master
0 2 0
glx22 - 16 months ago 2023-03-04 14:52:47
glx@openttd.org
Codechange: Use SQInteger for generic numbers in script_newgrf
2 files changed with 9 insertions and 9 deletions:
0 comments (0 inline, 0 general)
src/script/api/script_newgrf.cpp
Show inline comments
 
@@ -21,41 +21,41 @@ ScriptNewGRFList::ScriptNewGRFList()
 
		if (!HasBit(c->flags, GCF_STATIC)) {
 
			this->AddItem(BSWAP32(c->ident.grfid));
 
		}
 
	}
 
}
 

	
 
/* static */ bool ScriptNewGRF::IsLoaded(uint32 grfid)
 
/* static */ bool ScriptNewGRF::IsLoaded(SQInteger grfid)
 
{
 
	grfid = BSWAP32(grfid); // Match people's expectations.
 
	grfid = BSWAP32(GB(grfid, 0, 32)); // 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)
 
/* static */ SQInteger ScriptNewGRF::GetVersion(SQInteger grfid)
 
{
 
	grfid = BSWAP32(grfid); // Match people's expectations.
 
	grfid = BSWAP32(GB(grfid, 0, 32)); // 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)
 
/* static */ char *ScriptNewGRF::GetName(SQInteger grfid)
 
{
 
	grfid = BSWAP32(grfid); // Match people's expectations.
 
	grfid = BSWAP32(GB(grfid, 0, 32)); // 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
 
@@ -31,26 +31,26 @@ 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);
 
	static bool IsLoaded(SQInteger 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);
 
	static SQInteger GetVersion(SQInteger grfid);
 

	
 
	/**
 
	 * Get the name of a loaded NewGRF.
 
	 * @param grfid The NewGRF to query.
 
	 * @pre ScriptNewGRF::IsLoaded(grfid).
 
	 * @return The name of the NewGRF or null if no name is defined.
 
	 */
 
	static char *GetName(uint32 grfid);
 
	static char *GetName(SQInteger grfid);
 
};
 

	
 
#endif /* SCRIPT_NEWGRF_HPP */
0 comments (0 inline, 0 general)