1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-01-31 09:57:14 +01:00

Documented the shared miscellaneous code and made minor fixes.

This commit is contained in:
Sandu Liviu Catalin 2015-10-29 22:59:10 +02:00
parent 6f3579192a
commit dec4033208
2 changed files with 78 additions and 21 deletions

View File

@ -583,8 +583,8 @@ bool IsModelWeapon(SQInt32 id)
case 291: case 291:
case 292: case 292:
case 293: case 293:
case 294: return SQTrue; case 294: return true;
default: return SQFalse; default: return false;
} }
} }
@ -623,14 +623,14 @@ bool IsModelActuallyWeapon(SQInt32 id)
case 288: case 288:
case 289: case 289:
case 290: case 290:
case 291: return SQTrue; case 291: return true;
default: return SQFalse; default: return false;
} }
} }
bool IsModelValid(SQInt32 id) bool IsModelValid(SQInt32 id)
{ {
return (strcmp(GetModelName(id), _SC("")) != 0) ? SQTrue : SQFalse; return (strcmp(GetModelName(id), _SC("")) != 0) ? true : false;
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -1431,7 +1431,7 @@ SQInt32 GetSkinID(const SQChar * name)
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
bool IsSkinValid(SQInt32 id) bool IsSkinValid(SQInt32 id)
{ {
return (strcmp(GetSkinName(id), _SC("")) != 0) ? SQTrue : SQFalse; return (strcmp(GetSkinName(id), _SC("")) != 0) ? true : false;
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -2120,7 +2120,7 @@ SQInt32 GetAutomobileID(const SQChar * name)
bool IsAutomobileValid(SQInt32 id) bool IsAutomobileValid(SQInt32 id)
{ {
return (strcmp(GetAutomobileName(id), _SC("")) != 0) ? SQTrue : SQFalse; return (strcmp(GetAutomobileName(id), _SC("")) != 0) ? true : false;
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -2376,7 +2376,7 @@ SQInt32 GetWeaponID(const SQChar * name)
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
bool IsWeaponValid(SQInt32 id) bool IsWeaponValid(SQInt32 id)
{ {
return (strcmp(GetWeaponName(id), _SC("")) != 0) ? SQTrue : SQFalse; return (strcmp(GetWeaponName(id), _SC("")) != 0) ? true : false;
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -2389,8 +2389,8 @@ bool IsWeaponNatural(SQInt32 id)
case SQMOD_WEAPON_DROWNED: case SQMOD_WEAPON_DROWNED:
case SQMOD_WEAPON_FALL: case SQMOD_WEAPON_FALL:
case SQMOD_WEAPON_EXPLOSION2: case SQMOD_WEAPON_EXPLOSION2:
case SQMOD_WEAPON_SUICIDE: return SQTrue; case SQMOD_WEAPON_SUICIDE: return true;
default: return SQFalse; default: return false;
} }
} }

View File

@ -11,35 +11,91 @@
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
namespace SqMod { namespace SqMod {
// ------------------------------------------------------------------------------------------------ /* ------------------------------------------------------------------------------------------------
* Attempt to convert the specified key code to a name.
*/
const SQChar * GetKeyCodeName(SQInteger keycode); const SQChar * GetKeyCodeName(SQInteger keycode);
// ------------------------------------------------------------------------------------------------ /* ------------------------------------------------------------------------------------------------
* Attemp to convert the specified model identifier to a name.
*/
const SQChar * GetModelName(SQInt32 id); const SQChar * GetModelName(SQInt32 id);
/* ------------------------------------------------------------------------------------------------
* See whether the specified model identifier points to model that is used to represent weapons.
*/
bool IsModelWeapon(SQInt32 id); bool IsModelWeapon(SQInt32 id);
/* ------------------------------------------------------------------------------------------------
* See whether the specified model identifier points to model that is used to represent
* an actual weapon.
*/
bool IsModelActuallyWeapon(SQInt32 id); bool IsModelActuallyWeapon(SQInt32 id);
/* ------------------------------------------------------------------------------------------------
* See whether the specified model identifier is valid.
*/
bool IsModelValid(SQInt32 id); bool IsModelValid(SQInt32 id);
// ------------------------------------------------------------------------------------------------ /* ------------------------------------------------------------------------------------------------
* Attemp to convert the specified player skin identifier to a name.
*/
const SQChar * GetSkinName(SQInt32 id); const SQChar * GetSkinName(SQInt32 id);
/* ------------------------------------------------------------------------------------------------
* Attempt to convert the specified player skin name to an identifier.
*/
SQInt32 GetSkinID(const SQChar * name); SQInt32 GetSkinID(const SQChar * name);
/* ------------------------------------------------------------------------------------------------
* See whether the specified player skin identifier is valid.
*/
bool IsSkinValid(SQInt32 id); bool IsSkinValid(SQInt32 id);
// ------------------------------------------------------------------------------------------------ /* ------------------------------------------------------------------------------------------------
* Attemp to convert the specified vehicle model identifier to a name.
*/
const SQChar * GetAutomobileName(SQInt32 id); const SQChar * GetAutomobileName(SQInt32 id);
/* ------------------------------------------------------------------------------------------------
* Attempt to convert the specified vehicle model name to an identifier.
*/
SQInt32 GetAutomobileID(const SQChar * name); SQInt32 GetAutomobileID(const SQChar * name);
/* ------------------------------------------------------------------------------------------------
* See whether the specified vehicle model identifier is valid.
*/
bool IsAutomobileValid(SQInt32 id); bool IsAutomobileValid(SQInt32 id);
// ------------------------------------------------------------------------------------------------ /* ------------------------------------------------------------------------------------------------
* Attemp to convert the specified weapon identifier to a name.
*/
const SQChar * GetWeaponName(SQInt32 id); const SQChar * GetWeaponName(SQInt32 id);
/* ------------------------------------------------------------------------------------------------
* Attempt to convert the specified weapon name to an identifier.
*/
SQInt32 GetWeaponID(const SQChar * name); SQInt32 GetWeaponID(const SQChar * name);
/* ------------------------------------------------------------------------------------------------
* See whether the specified weapon identifier is valid.
*/
bool IsWeaponValid(SQInt32 id); 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.
*/
bool IsWeaponNatural(SQInt32 id); bool IsWeaponNatural(SQInt32 id);
// ------------------------------------------------------------------------------------------------ /* ------------------------------------------------------------------------------------------------
* Attempt to convert the weapon identifier to it's corresponding model identifier.
*/
SQInt32 WeaponToModel(SQInt32 id); SQInt32 WeaponToModel(SQInt32 id);
// ------------------------------------------------------------------------------------------------ /* ------------------------------------------------------------------------------------------------
* Helper class used to associate a tag and arbitrary data to an identifier.
*/
template < class T, unsigned N > class IdentifierStorage template < class T, unsigned N > class IdentifierStorage
{ {
public: public:
@ -57,7 +113,7 @@ protected:
protected: protected:
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* ... * Retrieve the global tag.
*/ */
static const SQChar * GlobalTag(SQUint32 id) noexcept static const SQChar * GlobalTag(SQUint32 id) noexcept
{ {
@ -65,11 +121,12 @@ protected:
{ {
return s_Globals[id].first.c_str(); return s_Globals[id].first.c_str();
} }
return _SC(""); return _SC("");
} }
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* ... * Change the global tag.
*/ */
static void GlobalTag(SQUint32 id, const SQChar * tag) noexcept static void GlobalTag(SQUint32 id, const SQChar * tag) noexcept
{ {
@ -84,7 +141,7 @@ protected:
} }
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* ... * Retrieve the global data.
*/ */
static SqObj & GlobalData(SQUint32 id) noexcept static SqObj & GlobalData(SQUint32 id) noexcept
{ {
@ -96,7 +153,7 @@ protected:
} }
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* ... * Change the global data.
*/ */
static void GlobalData(SQUint32 id, SqObj & data) noexcept static void GlobalData(SQUint32 id, SqObj & data) noexcept
{ {