-
Notifications
You must be signed in to change notification settings - Fork 22
/
GameMode.cpp
117 lines (95 loc) · 1.81 KB
/
GameMode.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include "StdAfx.h"
#include "World.h"
#include "GameMode.h"
#include "Player.h"
#include "PhysicsObj.h"
#include "ChatMsgs.h"
CGameMode::CGameMode()
{
}
CGameMode::~CGameMode()
{
}
CGameMode_Tag::CGameMode_Tag()
{
m_pSelectedPlayer = NULL;
}
CGameMode_Tag::~CGameMode_Tag()
{
UnselectPlayer();
}
const char *CGameMode_Tag::GetName()
{
return "Tag";
}
void CGameMode_Tag::Think()
{
if (!m_pSelectedPlayer)
{
// Find a player to make "it."
PlayerMap *pPlayers = g_pWorld->GetPlayers();
if (pPlayers->size() < 2)
{
return;
}
int index = RandomLong(0, pPlayers->size() - 1);
CBasePlayer *pSelected = NULL;
int i = 0;
for (auto& player : *pPlayers)
{
if (i == index)
{
pSelected = player.second;
break;
}
i++;
}
SelectPlayer(pSelected);
}
}
void CGameMode_Tag::SelectPlayer(CBasePlayer *pPlayer)
{
if (!pPlayer)
{
UnselectPlayer();
return;
}
m_pSelectedPlayer = pPlayer;
ModelInfo appearance;
appearance.dwBasePalette = 0x7E;
appearance.lPalettes.push_back(PaletteRpl(0x1705, 0, 0));
m_pSelectedPlayer->SetAppearanceOverride(&appearance);
m_pSelectedPlayer->EmitEffect(32, 1.0f);
g_pWorld->BroadcastGlobal(ServerText(csprintf("%s is it!", m_pSelectedPlayer->m_strName.c_str()), 1), PRIVATE_MSG);
}
void CGameMode_Tag::UnselectPlayer()
{
if (!m_pSelectedPlayer)
{
return;
}
m_pSelectedPlayer->SetAppearanceOverride(NULL);
}
void CGameMode_Tag::OnTargetAttacked(CPhysicsObj *pTarget, CPhysicsObj *pSource)
{
if (pSource == m_pSelectedPlayer)
{
if (pTarget->IsPlayer())
{
CBasePlayer *pTargetPlayer = (CBasePlayer *)pTarget;
UnselectPlayer();
SelectPlayer(pTargetPlayer);
}
}
}
void CGameMode_Tag::OnRemoveEntity(CPhysicsObj *pEntity)
{
if (pEntity)
{
if (pEntity == m_pSelectedPlayer)
{
UnselectPlayer();
m_pSelectedPlayer = NULL;
}
}
}