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_headers.h"
28 #include "cssdm_config.h"
29 #include "cssdm_ctrl.h"
30 #include "cssdm_ffa.h"
31 #include "cssdm_callbacks.h"
33 extern ConVar cssdm_enabled;
34 extern ConVar cssdm_ffa_enabled;
35 extern bool g_IsLoadedOkay;
37 bool g_IsRunning = false;
38 bool g_IsMapStarted = false;
39 bool g_HasConfigRan = false;
41 void DM_StartEverything()
43 if (!g_IsMapStarted || g_HasConfigRan)
48 g_HasConfigRan = true;
50 /* If we're not running but we should be, start up now.
51 * g_IsRunning should never be true here.
53 if (!g_IsRunning && cssdm_enabled.GetInt() == 1)
55 /* We should be enabled! */
60 void OnLevelInitialized()
67 g_IsMapStarted = true;
68 engine->ServerCommand("exec cssdm/cssdm.cfg\n");
71 snprintf(map_cmd, sizeof(map_cmd), "exec cssdm/%s.cfg\n", STRING(gpGlobals->mapname));
72 engine->ServerCommand(map_cmd);
74 engine->ServerCommand("cssdm internal 1\n");
79 /* We fully disable CS:S DM when the map ends.
80 * This is so our DM_Enable call is properly paired, but
81 * also so CGameRules hooks get flushed.
88 g_IsMapStarted = false;
89 g_HasConfigRan = false;
94 if (!g_IsLoadedOkay || !g_IsRunning)
101 /* If FFA is enabled, we must unpatch it. */
102 if (DM_FFA_IsPatched())
114 if (!g_IsLoadedOkay || g_IsRunning || !g_IsMapStarted || !g_HasConfigRan)
123 /* If FFA should be enabled, patch it. */
124 if (cssdm_ffa_enabled.GetInt() != 0
125 && DM_FFA_IsPrepared()
126 && !DM_FFA_IsPatched())
134 CON_COMMAND(cssdm, "CS:S DM console menu")
136 int args = engine->Cmd_Argc();
139 /* :TODO: display menu */
143 const char *arg = engine->Cmd_Argv(1);
144 if (strcmp(arg, "internal") == 0)
150 int num = atoi(engine->Cmd_Argv(2));
153 DM_StartEverything();