From dec4033208d6758557c22e35d6768472fdad12da Mon Sep 17 00:00:00 2001 From: Sandu Liviu Catalin Date: Thu, 29 Oct 2015 22:59:10 +0200 Subject: [PATCH] Documented the shared miscellaneous code and made minor fixes. --- source/Misc/Shared.cpp | 20 +++++------ source/Misc/Shared.hpp | 79 ++++++++++++++++++++++++++++++++++++------ 2 files changed, 78 insertions(+), 21 deletions(-) diff --git a/source/Misc/Shared.cpp b/source/Misc/Shared.cpp index 37e4cb53..c2349c6f 100644 --- a/source/Misc/Shared.cpp +++ b/source/Misc/Shared.cpp @@ -583,8 +583,8 @@ bool IsModelWeapon(SQInt32 id) case 291: case 292: case 293: - case 294: return SQTrue; - default: return SQFalse; + case 294: return true; + default: return false; } } @@ -623,14 +623,14 @@ bool IsModelActuallyWeapon(SQInt32 id) case 288: case 289: case 290: - case 291: return SQTrue; - default: return SQFalse; + case 291: return true; + default: return false; } } 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) { - 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) { - 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) { - 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_FALL: case SQMOD_WEAPON_EXPLOSION2: - case SQMOD_WEAPON_SUICIDE: return SQTrue; - default: return SQFalse; + case SQMOD_WEAPON_SUICIDE: return true; + default: return false; } } diff --git a/source/Misc/Shared.hpp b/source/Misc/Shared.hpp index 025e3300..d9bc0fd2 100644 --- a/source/Misc/Shared.hpp +++ b/source/Misc/Shared.hpp @@ -11,35 +11,91 @@ // ------------------------------------------------------------------------------------------------ namespace SqMod { -// ------------------------------------------------------------------------------------------------ +/* ------------------------------------------------------------------------------------------------ + * Attempt to convert the specified key code to a name. +*/ const SQChar * GetKeyCodeName(SQInteger keycode); -// ------------------------------------------------------------------------------------------------ +/* ------------------------------------------------------------------------------------------------ + * Attemp to convert the specified model identifier to a name. +*/ const SQChar * GetModelName(SQInt32 id); + +/* ------------------------------------------------------------------------------------------------ + * See whether the specified model identifier points to model that is used to represent weapons. +*/ 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); + +/* ------------------------------------------------------------------------------------------------ + * See whether the specified model identifier is valid. +*/ bool IsModelValid(SQInt32 id); -// ------------------------------------------------------------------------------------------------ +/* ------------------------------------------------------------------------------------------------ + * Attemp to convert the specified player skin identifier to a name. +*/ const SQChar * GetSkinName(SQInt32 id); + +/* ------------------------------------------------------------------------------------------------ + * Attempt to convert the specified player skin name to an identifier. +*/ SQInt32 GetSkinID(const SQChar * name); + +/* ------------------------------------------------------------------------------------------------ + * See whether the specified player skin identifier is valid. +*/ bool IsSkinValid(SQInt32 id); -// ------------------------------------------------------------------------------------------------ +/* ------------------------------------------------------------------------------------------------ + * Attemp to convert the specified vehicle model identifier to a name. +*/ const SQChar * GetAutomobileName(SQInt32 id); + +/* ------------------------------------------------------------------------------------------------ + * Attempt to convert the specified vehicle model name to an identifier. +*/ SQInt32 GetAutomobileID(const SQChar * name); + +/* ------------------------------------------------------------------------------------------------ + * See whether the specified vehicle model identifier is valid. +*/ bool IsAutomobileValid(SQInt32 id); -// ------------------------------------------------------------------------------------------------ +/* ------------------------------------------------------------------------------------------------ + * Attemp to convert the specified weapon identifier to a name. +*/ const SQChar * GetWeaponName(SQInt32 id); + +/* ------------------------------------------------------------------------------------------------ + * Attempt to convert the specified weapon name to an identifier. +*/ SQInt32 GetWeaponID(const SQChar * name); + +/* ------------------------------------------------------------------------------------------------ + * See whether the specified weapon identifier is valid. +*/ 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); -// ------------------------------------------------------------------------------------------------ +/* ------------------------------------------------------------------------------------------------ + * Attempt to convert the weapon identifier to it's corresponding model identifier. +*/ SQInt32 WeaponToModel(SQInt32 id); -// ------------------------------------------------------------------------------------------------ +/* ------------------------------------------------------------------------------------------------ + * Helper class used to associate a tag and arbitrary data to an identifier. +*/ template < class T, unsigned N > class IdentifierStorage { public: @@ -57,7 +113,7 @@ protected: protected: /* -------------------------------------------------------------------------------------------- - * ... + * Retrieve the global tag. */ static const SQChar * GlobalTag(SQUint32 id) noexcept { @@ -65,11 +121,12 @@ protected: { return s_Globals[id].first.c_str(); } + return _SC(""); } /* -------------------------------------------------------------------------------------------- - * ... + * Change the global tag. */ static void GlobalTag(SQUint32 id, const SQChar * tag) noexcept { @@ -84,7 +141,7 @@ protected: } /* -------------------------------------------------------------------------------------------- - * ... + * Retrieve the global data. */ static SqObj & GlobalData(SQUint32 id) noexcept { @@ -96,7 +153,7 @@ protected: } /* -------------------------------------------------------------------------------------------- - * ... + * Change the global data. */ static void GlobalData(SQUint32 id, SqObj & data) noexcept {