|
pred@2077
|
1 |
/** |
|
pred@2077
|
2 |
* vim: set ts=4 : |
|
pred@2077
|
3 |
* ============================================================================= |
|
pred@2077
|
4 |
* SourceMod |
|
pred@2077
|
5 |
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved. |
|
pred@2077
|
6 |
* ============================================================================= |
|
pred@2077
|
7 |
* |
|
pred@2077
|
8 |
* This program is free software; you can redistribute it and/or modify it under |
|
pred@2077
|
9 |
* the terms of the GNU General Public License, version 3.0, as published by the |
|
pred@2077
|
10 |
* Free Software Foundation. |
|
pred@2077
|
11 |
* |
|
pred@2077
|
12 |
* This program is distributed in the hope that it will be useful, but WITHOUT |
|
pred@2077
|
13 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
pred@2077
|
14 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
|
pred@2077
|
15 |
* details. |
|
pred@2077
|
16 |
* |
|
pred@2077
|
17 |
* You should have received a copy of the GNU General Public License along with |
|
pred@2077
|
18 |
* this program. If not, see <http://www.gnu.org/licenses/>. |
|
pred@2077
|
19 |
* |
|
pred@2077
|
20 |
* As a special exception, AlliedModders LLC gives you permission to link the |
|
pred@2077
|
21 |
* code of this program (as well as its derivative works) to "Half-Life 2," the |
|
pred@2077
|
22 |
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software |
|
pred@2077
|
23 |
* by the Valve Corporation. You must obey the GNU General Public License in |
|
pred@2077
|
24 |
* all respects for all other code used. Additionally, AlliedModders LLC grants |
|
pred@2077
|
25 |
* this exception to all derivative works. AlliedModders LLC defines further |
|
pred@2077
|
26 |
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), |
|
pred@2077
|
27 |
* or <http://www.sourcemod.net/license.php>. |
|
pred@2077
|
28 |
* |
|
pred@2077
|
29 |
* Version: $Id$ |
|
pred@2077
|
30 |
*/ |
|
pred@2077
|
31 |
|
|
pred@2077
|
32 |
#include "sm_globals.h" |
|
pred@2077
|
33 |
#include "NextMap.h" |
|
pred@2077
|
34 |
|
|
pred@2077
|
35 |
static cell_t sm_GetNextMap(IPluginContext *pCtx, const cell_t *params) |
|
pred@2077
|
36 |
{ |
|
pred@2077
|
37 |
const char *map = g_NextMap.GetNextMap(); |
|
pred@2077
|
38 |
|
|
pred@2077
|
39 |
if (map[0] == 0) |
|
pred@2077
|
40 |
{ |
|
pred@2077
|
41 |
return 0; |
|
pred@2077
|
42 |
} |
|
pred@2077
|
43 |
|
|
pred@2077
|
44 |
pCtx->StringToLocal(params[1], params[2], map); |
|
pred@2077
|
45 |
|
|
pred@2077
|
46 |
return 1; |
|
pred@2077
|
47 |
} |
|
pred@2077
|
48 |
|
|
pred@2077
|
49 |
static cell_t sm_SetNextMap(IPluginContext *pCtx, const cell_t *params) |
|
pred@2077
|
50 |
{ |
|
pred@2077
|
51 |
char *map; |
|
pred@2077
|
52 |
pCtx->LocalToString(params[1], &map); |
|
pred@2077
|
53 |
|
|
pred@2077
|
54 |
return g_NextMap.SetNextMap(map); |
|
pred@2077
|
55 |
} |
|
pred@2077
|
56 |
|
|
pred@2203
|
57 |
static cell_t sm_ForceChangeLevel(IPluginContext *pCtx, const cell_t *params) |
|
pred@2203
|
58 |
{ |
|
pred@2203
|
59 |
char *map; |
|
pred@2203
|
60 |
char *changeReason; |
|
pred@2203
|
61 |
|
|
pred@2203
|
62 |
pCtx->LocalToString(params[1], &map); |
|
pred@2203
|
63 |
pCtx->LocalToString(params[2], &changeReason); |
|
pred@2203
|
64 |
|
|
pred@2203
|
65 |
g_NextMap.ForceChangeLevel(map, changeReason); |
|
pred@2203
|
66 |
|
|
pred@2203
|
67 |
return 0; |
|
pred@2203
|
68 |
} |
|
pred@2203
|
69 |
|
|
pred@2203
|
70 |
static cell_t sm_GetMapHistorySize(IPluginContext *pCtx, const cell_t *params) |
|
pred@2203
|
71 |
{ |
|
pred@2203
|
72 |
return g_NextMap.m_mapHistory.size(); |
|
pred@2203
|
73 |
} |
|
pred@2203
|
74 |
|
|
pred@2203
|
75 |
static cell_t sm_GetMapHistory(IPluginContext *pCtx, const cell_t *params) |
|
pred@2203
|
76 |
{ |
|
pred@2203
|
77 |
if (params[1] < 0 || params[1] >= (int)g_NextMap.m_mapHistory.size()) |
|
pred@2203
|
78 |
{ |
|
pred@2203
|
79 |
return pCtx->ThrowNativeError("Invalid Map History Index"); |
|
pred@2203
|
80 |
} |
|
pred@2203
|
81 |
|
|
pred@2203
|
82 |
SourceHook::List<MapChangeData *>::iterator iter; |
|
pred@2203
|
83 |
iter = g_NextMap.m_mapHistory.end(); |
|
pred@2203
|
84 |
iter--; |
|
pred@2203
|
85 |
|
|
pred@2203
|
86 |
for (int i=0; i<params[1]; i++) |
|
pred@2203
|
87 |
{ |
|
pred@2203
|
88 |
iter--; |
|
pred@2203
|
89 |
} |
|
pred@2203
|
90 |
|
|
pred@2203
|
91 |
MapChangeData *data = (MapChangeData *)*iter; |
|
pred@2203
|
92 |
|
|
pred@2203
|
93 |
pCtx->StringToLocal(params[2], params[3], data->m_mapName); |
|
pred@2203
|
94 |
pCtx->StringToLocal(params[4], params[5], data->m_changeReason); |
|
pred@2203
|
95 |
|
|
pred@2203
|
96 |
cell_t *startTime; |
|
pred@2203
|
97 |
pCtx->LocalToPhysAddr(params[6], &startTime); |
|
pred@2203
|
98 |
*startTime = data->startTime; |
|
pred@2203
|
99 |
|
|
pred@2203
|
100 |
return 0; |
|
pred@2203
|
101 |
} |
|
pred@2077
|
102 |
|
|
pred@2077
|
103 |
REGISTER_NATIVES(nextmapnatives) |
|
pred@2077
|
104 |
{ |
|
pred@2203
|
105 |
{"GetNextMap", sm_GetNextMap}, |
|
pred@2203
|
106 |
{"SetNextMap", sm_SetNextMap}, |
|
pred@2203
|
107 |
{"ForceChangeLevel", sm_ForceChangeLevel}, |
|
pred@2203
|
108 |
{"GetMapHistorySize", sm_GetMapHistorySize}, |
|
pred@2203
|
109 |
{"GetMapHistory", sm_GetMapHistory}, |
|
pred@2203
|
110 |
{NULL, NULL}, |
|
pred@2077
|
111 |
}; |