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