Remove unused code.
3 * ===============================================================
4 * CS:S DM, Copyright (C) 2004-2007 AlliedModders LLC.
5 * By David "BAILOPAN" Anderson
7 * ===============================================================
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or (at
12 * your option) any later version.
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; see the file COPYING; if not, write to the
21 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
27 #include "cssdm_events.h"
28 #include "cssdm_players.h"
29 #include "cssdm_utils.h"
30 #include "cssdm_config.h"
31 #include "cssdm_headers.h"
32 #include "cssdm_callbacks.h"
33 #include "cssdm_weapons.h"
34 #include "cssdm_detours.h"
37 using namespace SourceHook;
39 bool g_InRoundRestart = false;
40 List<ITimer *> g_RagdollTimers;
42 class RagdollRemoval : public ITimedEvent
45 ResultType OnTimer(ITimer *pTimer, void *pData)
49 IDataPack *pack = (IDataPack *)pData;
51 int index = pack->ReadCell();
52 int serial = pack->ReadCell();
53 edict_t *pEdict = gamehelpers->EdictOfIndex(index);
54 if (pEdict && !pEdict->IsFree() && DM_CheckSerial(pEdict, serial))
56 CBaseEntity *pEntity = DM_GetBaseEntity(index);
59 DM_RemoveEntity(pEntity);
63 g_RagdollTimers.remove(pTimer);
68 void OnTimerEnd(ITimer *pTimer, void *pData)
70 g_pSM->FreeDataPack((IDataPack *)pData);
74 class PlayerSpawner : public ITimedEvent
77 ResultType OnTimer(ITimer *pTimer, void *pData)
85 IDataPack *pack = (IDataPack *)pData;
87 int client = pack->ReadCell();
89 dm_player_t *player = DM_GetPlayer(client);
91 /* Make sure the team is valid */
92 int team = player->pInfo->GetTeamIndex();
93 if (team != CS_TEAM_T && team != CS_TEAM_CT)
98 /* Make sure they're dead */
99 if (DM_IsPlayerAlive(client))
104 DM_RespawnPlayer(client);
109 void OnTimerEnd(ITimer *pTimer, void *pData)
111 IDataPack *pack = (IDataPack *)pData;
113 int client = pack->ReadCell();
115 dm_player_t *player = DM_GetPlayer(client);
116 if (player->respawn_timer == pTimer)
118 player->respawn_timer = NULL;
121 g_pSM->FreeDataPack((IDataPack *)pData);
125 void DM_ClearRagdollTimers()
127 List<ITimer *>::iterator iter = g_RagdollTimers.begin();
128 while (iter != g_RagdollTimers.end())
130 timersys->KillTimer((*iter));
131 iter = g_RagdollTimers.erase(iter);
135 void DM_SchedRespawn(int client)
137 dm_player_t *player = DM_GetPlayer(client);
139 if (player->respawn_timer)
141 timersys->KillTimer(player->respawn_timer);
144 IDataPack *pack = g_pSM->CreateDataPack();
145 pack->PackCell(client);
147 player->respawn_timer = timersys->CreateTimer(&s_PlayerSpawner, DM_GetRespawnWait(), pack, 0);
150 void OnClientCommand_Post(edict_t *edict, const CCommand &args)
157 const char *cmd = args.Arg(0);
159 if (strcmp(cmd, "joinclass") == 0)
161 int client = gamehelpers->IndexOfEdict(edict);
162 dm_player_t *player = DM_GetPlayer(client);
163 if (!player || !player->pEntity)
168 if (DM_IsPlayerAlive(client))
173 if (!player->will_respawn_on_class)
178 player->will_respawn_on_class = false;
181 DM_SchedRespawn(client);
185 void OnClientDropWeapons(CBaseEntity *pEntity)
189 /* Block them from having a defuse kit so they don't drop it. */
190 DM_SetDefuseKit(pEntity, false);
194 void OnClientDroppedWeapon(CBaseEntity *pEntity, CBaseEntity *pWeapon)
196 if (!g_IsRunning || !pWeapon || !DM_ShouldRemoveDrops())
203 edict_t *pEdict = gameents->BaseEntityToEdict(pWeapon);
204 if (pEdict && strcmp(pEdict->GetClassName(), "weapon_c4") == 0)
210 DM_RemoveEntity(pWeapon);
213 #define IMPLEMENT_EVENT(name) \
214 cls_event_##name g_cls_event_##name; \
215 void cls_event_##name::FireGameEvent(IGameEvent *event)
217 IMPLEMENT_EVENT(player_death)
224 int userid = event->GetInt("userid");
226 int client = playerhelpers->GetClientOfUserId(userid);
232 dm_player_t *player = DM_GetPlayer(client);
238 player->is_spawned = false;
241 unsigned int ragdollTime = DM_GetBodyStayTime();
242 if (ragdollTime <= 20 && !g_InRoundRestart)
245 CBaseEntity *ragdoll = DM_GetAndClearRagdoll(player->pEntity, serial);
246 if (ragdollTime == 0)
248 DM_RemoveEntity(ragdoll);
250 edict_t *pEdict = gameents->BaseEntityToEdict(ragdoll);
253 int index = gamehelpers->IndexOfEdict(pEdict);
254 IDataPack *pack = g_pSM->CreateDataPack();
255 pack->PackCell(index);
256 pack->PackCell(serial);
257 ITimer *timer = timersys->CreateTimer(&s_RagdollRemover, ragdollTime, pack, 0);
258 g_RagdollTimers.push_back(timer);
263 if (!DM_OnClientDeath(client))
268 DM_SchedRespawn(client);
271 IMPLEMENT_EVENT(player_team)
278 int userid = event->GetInt("userid");
279 int client = playerhelpers->GetClientOfUserId(userid);
285 dm_player_t *player = DM_GetPlayer(client);
286 if (!player || !player->pEntity)
291 if (DM_IsPlayerAlive(client) || event->GetBool("disconnect"))
296 int old_team = event->GetInt("oldteam");
297 if (old_team == CS_TEAM_T || old_team == CS_TEAM_CT)
302 int new_team = event->GetInt("team");
303 if (new_team != CS_TEAM_T && new_team != CS_TEAM_CT)
310 DM_SchedRespawn(client);
312 player->will_respawn_on_class = true;
316 IMPLEMENT_EVENT(player_spawn)
323 int userid = event->GetInt("userid");
324 int client = playerhelpers->GetClientOfUserId(userid);
330 dm_player_t *player = DM_GetPlayer(client);
331 if (!player || !player->pEntity || (player->is_spawned && !g_InRoundRestart))
336 /* This can be fired before a player gets a team! */
337 int team_idx = player->pInfo->GetTeamIndex();
338 if (team_idx != CS_TEAM_T
339 && team_idx != CS_TEAM_CT)
344 bool old_value = player->is_spawned;
345 player->is_spawned = true;
347 /* If we were waiting to respawn, cancel the timer */
348 if (player->respawn_timer && !player->pBot)
350 timersys->KillTimer(player->respawn_timer);
351 player->respawn_timer = NULL;
354 DM_OnClientSpawned(client, old_value);
357 IMPLEMENT_EVENT(server_shutdown)
359 g_IsInGlobalShutdown = true;
362 IMPLEMENT_EVENT(round_start)
364 g_InRoundRestart = false;
367 IMPLEMENT_EVENT(round_end)
369 g_InRoundRestart = true;
371 DM_ClearRagdollTimers();
373 for (int i=1; i<=gpGlobals->maxClients; i++)
375 dm_player_t *player = DM_GetPlayer(i);
376 player->is_spawned = false;
380 IMPLEMENT_EVENT(item_pickup)
382 if (!g_IsRunning || DM_AllowC4())
387 const char *weapon = event->GetString("item");
388 if (strcmp(weapon, "c4") != 0)
393 int userid = event->GetInt("userid");
394 int client = playerhelpers->GetClientOfUserId(userid);
400 dm_player_t *player = DM_GetPlayer(client);
401 if (!player || !player->pEntity)
406 CBaseEntity *pWeapon = DM_GetWeaponFromSlot(player->pEntity, (int)WeaponType_C4);
409 DM_DropWeapon(player->pEntity, pWeapon);