1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2024-11-08 16:57:16 +01:00
SqMod/source/Misc/Shared.hpp

178 lines
6.3 KiB
C++
Raw Normal View History

2015-09-30 02:56:11 +02:00
#ifndef _MISC_SHARED_HPP_
#define _MISC_SHARED_HPP_
// ------------------------------------------------------------------------------------------------
#include "Common.hpp"
// ------------------------------------------------------------------------------------------------
#include <array>
#include <utility>
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Attempt to convert the specified key code to a name.
*/
2015-09-30 02:56:11 +02:00
const SQChar * GetKeyCodeName(SQInteger keycode);
/* ------------------------------------------------------------------------------------------------
* Attemp to convert the specified model identifier to a name.
*/
2015-09-30 02:56:11 +02:00
const SQChar * GetModelName(SQInt32 id);
/* ------------------------------------------------------------------------------------------------
* See whether the specified model identifier points to model that is used to represent weapons.
*/
2015-09-30 02:56:11 +02:00
bool IsModelWeapon(SQInt32 id);
/* ------------------------------------------------------------------------------------------------
* See whether the specified model identifier points to model that is used to represent
* an actual weapon.
*/
2015-09-30 02:56:11 +02:00
bool IsModelActuallyWeapon(SQInt32 id);
/* ------------------------------------------------------------------------------------------------
* See whether the specified model identifier is valid.
*/
2015-09-30 02:56:11 +02:00
bool IsModelValid(SQInt32 id);
/* ------------------------------------------------------------------------------------------------
* Attemp to convert the specified player skin identifier to a name.
*/
2015-09-30 02:56:11 +02:00
const SQChar * GetSkinName(SQInt32 id);
/* ------------------------------------------------------------------------------------------------
* Attempt to convert the specified player skin name to an identifier.
*/
2015-09-30 02:56:11 +02:00
SQInt32 GetSkinID(const SQChar * name);
/* ------------------------------------------------------------------------------------------------
* See whether the specified player skin identifier is valid.
*/
2015-09-30 02:56:11 +02:00
bool IsSkinValid(SQInt32 id);
/* ------------------------------------------------------------------------------------------------
* Attemp to convert the specified vehicle model identifier to a name.
*/
2015-09-30 02:56:11 +02:00
const SQChar * GetAutomobileName(SQInt32 id);
/* ------------------------------------------------------------------------------------------------
* Attempt to convert the specified vehicle model name to an identifier.
*/
2015-09-30 02:56:11 +02:00
SQInt32 GetAutomobileID(const SQChar * name);
/* ------------------------------------------------------------------------------------------------
* See whether the specified vehicle model identifier is valid.
*/
2015-09-30 02:56:11 +02:00
bool IsAutomobileValid(SQInt32 id);
/* ------------------------------------------------------------------------------------------------
* Attemp to convert the specified weapon identifier to a name.
*/
2015-09-30 02:56:11 +02:00
const SQChar * GetWeaponName(SQInt32 id);
/* ------------------------------------------------------------------------------------------------
* Attempt to convert the specified weapon name to an identifier.
*/
2015-09-30 02:56:11 +02:00
SQInt32 GetWeaponID(const SQChar * name);
/* ------------------------------------------------------------------------------------------------
* See whether the specified weapon identifier is valid.
*/
2015-09-30 02:56:11 +02:00
bool IsWeaponValid(SQInt32 id);
/* ------------------------------------------------------------------------------------------------
* See whether the specified weapon identifier points to a weapon that may not be used by
* another player to perform a kill. Such as a player fall, drown, explosion etc.
*/
2015-09-30 02:56:11 +02:00
bool IsWeaponNatural(SQInt32 id);
/* ------------------------------------------------------------------------------------------------
* Attempt to convert the weapon identifier to it's corresponding model identifier.
*/
2015-09-30 02:56:11 +02:00
SQInt32 WeaponToModel(SQInt32 id);
/* ------------------------------------------------------------------------------------------------
* Helper class used to associate a tag and arbitrary data to an identifier.
*/
2015-09-30 02:56:11 +02:00
template < class T, unsigned N > class IdentifierStorage
{
public:
// --------------------------------------------------------------------------------------------
static constexpr SQInt32 Max = N;
protected:
// --------------------------------------------------------------------------------------------
typedef std::array< std::pair< SqTag, SqObj >, N > GlobalStorage;
// --------------------------------------------------------------------------------------------
static GlobalStorage s_Globals;
protected:
/* --------------------------------------------------------------------------------------------
* Retrieve the global tag.
2015-09-30 02:56:11 +02:00
*/
static const SQChar * GlobalTag(SQUint32 id) noexcept
{
if (id < N)
{
return s_Globals[id].first.c_str();
}
2015-09-30 02:56:11 +02:00
return _SC("");
}
/* --------------------------------------------------------------------------------------------
* Change the global tag.
2015-09-30 02:56:11 +02:00
*/
static void GlobalTag(SQUint32 id, const SQChar * tag) noexcept
{
if (id < N)
{
s_Globals[id].first.assign(tag);
}
else
{
LogErr("Attempting to set global tag for invalid automobile id: %d", id);
}
}
/* --------------------------------------------------------------------------------------------
* Retrieve the global data.
2015-09-30 02:56:11 +02:00
*/
static SqObj & GlobalData(SQUint32 id) noexcept
{
if (id < N)
{
return s_Globals[id].second;
}
return NullData();
}
/* --------------------------------------------------------------------------------------------
* Change the global data.
2015-09-30 02:56:11 +02:00
*/
static void GlobalData(SQUint32 id, SqObj & data) noexcept
{
if (id < N)
{
s_Globals[id].second = data;
}
else
{
LogErr("Attempting to set global data for invalid automobile id: %d", id);
}
}
};
// ------------------------------------------------------------------------------------------------
template < class T, unsigned N >
typename IdentifierStorage< T, N >::GlobalStorage IdentifierStorage< T, N >::s_Globals;
} // Namespace:: SqMod
#endif // _MISC_SHARED_HPP_