cssdm_ctrl.cpp
author Ruben Gonzalez <drifter01620@gmail.com>
Wed Oct 01 11:50:24 2014 -0400 (2014-10-01)
changeset 193 277c856152b0
parent 21 158fd55fde91
permissions -rw-r--r--
Update linix CS:GO gamedata
     1 /**
     2  * vim: set ts=4 :
     3  * ===============================================================
     4  * CS:S DM, Copyright (C) 2004-2007 AlliedModders LLC. 
     5  * By David "BAILOPAN" Anderson
     6  * All rights reserved.
     7  * ===============================================================
     8  *
     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.
    13  * 
    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.
    18  * 
    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,
    22  * MA 02110-1301 USA
    23  * 
    24  * Version: $Id$
    25  */
    26 
    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"
    32 #include "cssdm_events.h"
    33 
    34 extern ConVar cssdm_enabled;
    35 extern ConVar cssdm_ffa_enabled;
    36 extern bool g_IsLoadedOkay;
    37 
    38 bool g_IsRunning = false;
    39 bool g_IsMapStarted = false;
    40 bool g_HasConfigRan = false;
    41 
    42 void DM_StartEverything()
    43 {
    44 	if (!g_IsMapStarted || g_HasConfigRan)
    45 	{
    46 		return;
    47 	}
    48 
    49 	g_HasConfigRan = true;
    50 
    51 	/* If we're not running but we should be, start up now.
    52 	 * g_IsRunning should never be true here.
    53 	 */
    54 	if (!g_IsRunning && cssdm_enabled.GetInt() == 1)
    55 	{
    56 		/* We should be enabled! */
    57 		DM_Enable();
    58 	}
    59 }
    60 
    61 void OnLevelInitialized()
    62 {
    63 	if (!g_IsLoadedOkay)
    64 	{
    65 		return;
    66 	}
    67 
    68 	g_IsMapStarted = true;
    69 	engine->ServerCommand("exec cssdm/cssdm.cfg\n");
    70 
    71 	char map_cmd[128];
    72 	snprintf(map_cmd, sizeof(map_cmd), "exec cssdm/maps/%s.cssdm.cfg\n", STRING(gpGlobals->mapname));
    73 	engine->ServerCommand(map_cmd);
    74 	
    75 	engine->ServerCommand("cssdm internal 1\n");
    76 }
    77 
    78 void OnLevelEnd()
    79 {
    80 	/* We fully disable CS:S DM when the map ends.
    81 	 * This is so our DM_Enable call is properly paired, but
    82 	 * also so CGameRules hooks get flushed.
    83 	 */
    84 	DM_ClearRagdollTimers();
    85 	if (g_IsRunning)
    86 	{
    87 		DM_Disable();
    88 	}
    89 
    90 	g_IsMapStarted = false;
    91 	g_HasConfigRan = false;
    92 }
    93 
    94 bool DM_Disable()
    95 {
    96 	if (!g_IsLoadedOkay || !g_IsRunning)
    97 	{
    98 		return false;
    99 	}
   100 
   101 	g_IsRunning = false;
   102 
   103 	/* If FFA is enabled, we must unpatch it. */
   104 	if (DM_FFA_IsPatched())
   105 	{
   106 		DM_Unpatch_FFA();
   107 	}
   108 
   109 	DM_OnShutdown();
   110 
   111 	return true;
   112 }
   113 
   114 bool DM_Enable()
   115 {
   116 	if (!g_IsLoadedOkay || g_IsRunning || !g_IsMapStarted || !g_HasConfigRan)
   117 	{
   118 		return false;
   119 	}
   120 
   121 	g_IsRunning = true;
   122 
   123 	DM_OnStartup();
   124 
   125 	/* If FFA should be enabled, patch it. */
   126 	if (cssdm_ffa_enabled.GetInt() != 0
   127 		&& DM_FFA_IsPrepared()
   128 		&& !DM_FFA_IsPatched())
   129 	{
   130 		DM_Patch_FFA();
   131 	}
   132 
   133 	return true;
   134 }
   135 
   136 CON_COMMAND(cssdm, "CS:S DM console menu")
   137 {
   138 	int argc = args.ArgC();
   139 	if (argc < 2)
   140 	{
   141 		/* :TODO: display menu */
   142 		return;
   143 	}
   144 
   145 	const char *arg = args.Arg(1);
   146 	if (strcmp(arg, "internal") == 0)
   147 	{
   148 		if (argc < 3)
   149 		{
   150 			return;
   151 		}
   152 		int num = atoi(args.Arg(2));
   153 		if (num == 1)
   154 		{
   155 			DM_StartEverything();
   156 		}
   157 	}
   158 }