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
[email protected]
     1
/**
[email protected]
     2
 * vim: set ts=4 :
[email protected]
     3
 * ===============================================================
[email protected]
     4
 * CS:S DM, Copyright (C) 2004-2007 AlliedModders LLC. 
[email protected]
     5
 * By David "BAILOPAN" Anderson
[email protected]
     6
 * All rights reserved.
[email protected]
     7
 * ===============================================================
[email protected]
     8
 *
[email protected]
     9
 * This program is free software; you can redistribute it and/or modify
[email protected]
    10
 * it under the terms of the GNU General Public License as published by
[email protected]
    11
 * the Free Software Foundation; either version 2 of the License, or (at
[email protected]
    12
 * your option) any later version.
[email protected]
    13
 * 
[email protected]
    14
 * This program is distributed in the hope that it will be useful, but
[email protected]
    15
 * WITHOUT ANY WARRANTY; without even the implied warranty of
[email protected]
    16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
[email protected]
    17
 * General Public License for more details.
[email protected]
    18
 * 
[email protected]
    19
 * You should have received a copy of the GNU General Public License
[email protected]
    20
 * along with this program; see the file COPYING; if not, write to the
[email protected]
    21
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
[email protected]
    22
 * MA 02110-1301 USA
[email protected]
    23
 * 
[email protected]
    24
 * Version: $Id$
[email protected]
    25
 */
[email protected]
    26
[email protected]
    27
#include "cssdm_headers.h"
[email protected]
    28
#include "cssdm_config.h"
[email protected]
    29
#include "cssdm_ctrl.h"
[email protected]
    30
#include "cssdm_ffa.h"
[email protected]
    31
#include "cssdm_callbacks.h"
[email protected]
    32
#include "cssdm_events.h"
[email protected]
    33
[email protected]
    34
extern ConVar cssdm_enabled;
[email protected]
    35
extern ConVar cssdm_ffa_enabled;
[email protected]
    36
extern bool g_IsLoadedOkay;
[email protected]
    37
[email protected]
    38
bool g_IsRunning = false;
[email protected]
    39
bool g_IsMapStarted = false;
[email protected]
    40
bool g_HasConfigRan = false;
[email protected]
    41
[email protected]
    42
void DM_StartEverything()
[email protected]
    43
{
[email protected]
    44
	if (!g_IsMapStarted || g_HasConfigRan)
[email protected]
    45
	{
[email protected]
    46
		return;
[email protected]
    47
	}
[email protected]
    48
[email protected]
    49
	g_HasConfigRan = true;
[email protected]
    50
[email protected]
    51
	/* If we're not running but we should be, start up now.
[email protected]
    52
	 * g_IsRunning should never be true here.
[email protected]
    53
	 */
[email protected]
    54
	if (!g_IsRunning && cssdm_enabled.GetInt() == 1)
[email protected]
    55
	{
[email protected]
    56
		/* We should be enabled! */
[email protected]
    57
		DM_Enable();
[email protected]
    58
	}
[email protected]
    59
}
[email protected]
    60
[email protected]
    61
void OnLevelInitialized()
[email protected]
    62
{
[email protected]
    63
	if (!g_IsLoadedOkay)
[email protected]
    64
	{
[email protected]
    65
		return;
[email protected]
    66
	}
[email protected]
    67
[email protected]
    68
	g_IsMapStarted = true;
[email protected]
    69
	engine->ServerCommand("exec cssdm/cssdm.cfg\n");
[email protected]
    70
[email protected]
    71
	char map_cmd[128];
[email protected]
    72
	snprintf(map_cmd, sizeof(map_cmd), "exec cssdm/maps/%s.cssdm.cfg\n", STRING(gpGlobals->mapname));
[email protected]
    73
	engine->ServerCommand(map_cmd);
[email protected]
    74
	
[email protected]
    75
	engine->ServerCommand("cssdm internal 1\n");
[email protected]
    76
}
[email protected]
    77
[email protected]
    78
void OnLevelEnd()
[email protected]
    79
{
[email protected]
    80
	/* We fully disable CS:S DM when the map ends.
[email protected]
    81
	 * This is so our DM_Enable call is properly paired, but
[email protected]
    82
	 * also so CGameRules hooks get flushed.
[email protected]
    83
	 */
[email protected]
    84
	DM_ClearRagdollTimers();
[email protected]
    85
	if (g_IsRunning)
[email protected]
    86
	{
[email protected]
    87
		DM_Disable();
[email protected]
    88
	}
[email protected]
    89
[email protected]
    90
	g_IsMapStarted = false;
[email protected]
    91
	g_HasConfigRan = false;
[email protected]
    92
}
[email protected]
    93
[email protected]
    94
bool DM_Disable()
[email protected]
    95
{
[email protected]
    96
	if (!g_IsLoadedOkay || !g_IsRunning)
[email protected]
    97
	{
[email protected]
    98
		return false;
[email protected]
    99
	}
[email protected]
   100
[email protected]
   101
	g_IsRunning = false;
[email protected]
   102
[email protected]
   103
	/* If FFA is enabled, we must unpatch it. */
[email protected]
   104
	if (DM_FFA_IsPatched())
[email protected]
   105
	{
[email protected]
   106
		DM_Unpatch_FFA();
[email protected]
   107
	}
[email protected]
   108
[email protected]
   109
	DM_OnShutdown();
[email protected]
   110
[email protected]
   111
	return true;
[email protected]
   112
}
[email protected]
   113
[email protected]
   114
bool DM_Enable()
[email protected]
   115
{
[email protected]
   116
	if (!g_IsLoadedOkay || g_IsRunning || !g_IsMapStarted || !g_HasConfigRan)
[email protected]
   117
	{
[email protected]
   118
		return false;
[email protected]
   119
	}
[email protected]
   120
[email protected]
   121
	g_IsRunning = true;
[email protected]
   122
[email protected]
   123
	DM_OnStartup();
[email protected]
   124
[email protected]
   125
	/* If FFA should be enabled, patch it. */
[email protected]
   126
	if (cssdm_ffa_enabled.GetInt() != 0
[email protected]
   127
		&& DM_FFA_IsPrepared()
[email protected]
   128
		&& !DM_FFA_IsPatched())
[email protected]
   129
	{
[email protected]
   130
		DM_Patch_FFA();
[email protected]
   131
	}
[email protected]
   132
[email protected]
   133
	return true;
[email protected]
   134
}
[email protected]
   135
[email protected]
   136
CON_COMMAND(cssdm, "CS:S DM console menu")
[email protected]
   137
{
[email protected]
   138
	int argc = args.ArgC();
[email protected]
   139
	if (argc < 2)
[email protected]
   140
	{
[email protected]
   141
		/* :TODO: display menu */
[email protected]
   142
		return;
[email protected]
   143
	}
[email protected]
   144
[email protected]
   145
	const char *arg = args.Arg(1);
[email protected]
   146
	if (strcmp(arg, "internal") == 0)
[email protected]
   147
	{
[email protected]
   148
		if (argc < 3)
[email protected]
   149
		{
[email protected]
   150
			return;
[email protected]
   151
		}
[email protected]
   152
		int num = atoi(args.Arg(2));
[email protected]
   153
		if (num == 1)
[email protected]
   154
		{
[email protected]
   155
			DM_StartEverything();
[email protected]
   156
		}
[email protected]
   157
	}
[email protected]
   158
}