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