extensions/sdktools/CellRecipientFilter.h
author Phong Dang <teame06@gmail.com>
Wed Aug 01 07:29:40 2007 +0000 (2007-08-01)
changeset 1241 2e8046793bc9
parent 1233 e9cfc03b9bb8
child 1330 ab94316bb52b
permissions -rw-r--r--
Added check to make sure player are alive to perform sm_slap, sm_burn, sm_slay.
     1 /**
     2  * vim: set ts=4 :
     3  * ================================================================
     4  * SourceMod SDKTools Extension
     5  * Copyright (C) 2004-2007 AlliedModders LLC.  All rights reserved.
     6  * ================================================================
     7  *
     8  * This program is free software; you can redistribute it and/or 
     9  * modify it under the terms of the GNU General Public License, 
    10  * version 3.0, as published by the Free Software Foundation.
    11  * 
    12  * This program is distributed in the hope that it will be useful,
    13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    15  * GNU General Public License for more details.
    16  *
    17  * You should have received a copy of the GNU General Public License
    18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    19  *
    20  * As a special exception, AlliedModders LLC gives you permission to 
    21  * link the code of this program (as well as its derivative works) to 
    22  * "Half-Life 2," the "Source Engine," the "SourcePawn JIT," and any 
    23  * Game MODs that run on software by the Valve Corporation.  You must 
    24  * obey the GNU General Public License in all respects for all other 
    25  * code used. Additionally, AlliedModders LLC grants this exception 
    26  * to all derivative works. AlliedModders LLC defines further 
    27  * exceptions, found in LICENSE.txt (as of this writing, version 
    28  * JULY-31-2007), or <http://www.sourcemod.net/license.php>.
    29  *
    30  * Version: $Id$
    31  */
    32 
    33 #ifndef _INCLUDE_SOURCEMOD_CELLRECIPIENTFILTER_H_
    34 #define _INCLUDE_SOURCEMOD_CELLRECIPIENTFILTER_H_
    35 
    36 #include <irecipientfilter.h>
    37 #include <sp_vm_types.h>
    38 
    39 class CellRecipientFilter : public IRecipientFilter
    40 {
    41 public:
    42 	CellRecipientFilter() : m_IsReliable(false), m_IsInitMessage(false), m_Size(0) {}
    43 	~CellRecipientFilter() {}
    44 public: //IRecipientFilter
    45 	bool IsReliable() const;
    46 	bool IsInitMessage() const;
    47 	int GetRecipientCount() const;
    48 	int GetRecipientIndex(int slot) const;
    49 public:
    50 	void Initialize(cell_t *ptr, size_t count);
    51 	void SetToReliable(bool isreliable);
    52 	void SetToInit(bool isinitmsg);
    53 	void Reset();
    54 private:
    55 	cell_t m_Players[255];
    56 	bool m_IsReliable;
    57 	bool m_IsInitMessage;
    58 	size_t m_Size;
    59 };
    60 
    61 inline void CellRecipientFilter::Reset()
    62 {
    63 	m_IsReliable = false;
    64 	m_IsInitMessage = false;
    65 	m_Size = 0;
    66 }
    67 
    68 inline bool CellRecipientFilter::IsReliable() const
    69 {
    70 	return m_IsReliable;
    71 }
    72 
    73 inline bool CellRecipientFilter::IsInitMessage() const
    74 {
    75 	return m_IsInitMessage;
    76 }
    77 
    78 inline int CellRecipientFilter::GetRecipientCount() const
    79 {
    80 	return m_Size;
    81 }
    82 
    83 inline int CellRecipientFilter::GetRecipientIndex(int slot) const
    84 {
    85 	if ((slot < 0) || (slot >= GetRecipientCount()))
    86 	{
    87 		return -1;
    88 	}
    89 	return static_cast<int>(m_Players[slot]);
    90 }
    91 
    92 inline void CellRecipientFilter::SetToInit(bool isinitmsg)
    93 {
    94 	m_IsInitMessage = isinitmsg;
    95 }
    96 
    97 inline void CellRecipientFilter::SetToReliable(bool isreliable)
    98 {
    99 	m_IsReliable = isreliable;
   100 }
   101 
   102 inline void CellRecipientFilter::Initialize(cell_t *ptr, size_t count)
   103 {
   104 	memcpy(m_Players, ptr, count * sizeof(cell_t));
   105 	m_Size = count;
   106 }
   107 
   108 #endif //_INCLUDE_SOURCEMOD_CELLRECIPIENTFILTER_H_