Added check to make sure player are alive to perform sm_slap, sm_burn, sm_slay.
3 * ================================================================
5 * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved.
6 * ================================================================
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License,
10 * version 3.0, as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * As a special exception, AlliedModders LLC gives you permission to
21 * link the code of this program (as well as its derivative works) to
22 * "Half-Life 2," the "Source Engine," the "SourcePawn JIT," and any
23 * Game MODs that run on software by the Valve Corporation. You must
24 * obey the GNU General Public License in all respects for all other
25 * code used. Additionally, AlliedModders LLC grants this exception
26 * to all derivative works. AlliedModders LLC defines further
27 * exceptions, found in LICENSE.txt (as of this writing, version
28 * JULY-31-2007), or <http://www.sourcemod.net/license.php>.
36 #include "sm_globals.h"
38 /****************************************
40 * FLOATING POINT NATIVE IMPLEMENTATIONS *
42 ****************************************/
45 static cell_t sm_float(IPluginContext *pCtx, const cell_t *params)
47 float val = static_cast<float>(params[1]);
52 static cell_t sm_FloatAbs(IPluginContext *pCtx, const cell_t *params)
54 float val = sp_ctof(params[1]);
55 val = (val >= 0.0f) ? val : -val;
60 static cell_t sm_FloatAdd(IPluginContext *pCtx, const cell_t *params)
62 float val = sp_ctof(params[1]) + sp_ctof(params[2]);
67 static cell_t sm_FloatSub(IPluginContext *pCtx, const cell_t *params)
69 float val = sp_ctof(params[1]) - sp_ctof(params[2]);
74 static cell_t sm_FloatMul(IPluginContext *pCtx, const cell_t *params)
76 float val = sp_ctof(params[1]) * sp_ctof(params[2]);
81 static cell_t sm_FloatDiv(IPluginContext *pCtx, const cell_t *params)
83 float val = sp_ctof(params[1]) / sp_ctof(params[2]);
88 static cell_t sm_FloatCompare(IPluginContext *pCtx, const cell_t *params)
90 float val1 = sp_ctof(params[1]);
91 float val2 = sp_ctof(params[2]);
96 } else if (val1 < val2) {
103 static cell_t sm_Logarithm(IPluginContext *pCtx, const cell_t *params)
105 float val = sp_ctof(params[1]);
106 float base = sp_ctof(params[2]);
108 if ((val <= 0.0f) || (base <= 0.0f))
110 return pCtx->ThrowNativeError("Cannot evaluate the logarithm of zero or a negative number (val:%f base:%f)", val, base);
116 val = log(val) / log(base);
122 static cell_t sm_Exponential(IPluginContext *pCtx, const cell_t *params)
124 float val = sp_ctof(params[1]);
126 return sp_ftoc(exp(val));
129 static cell_t sm_Pow(IPluginContext *pCtx, const cell_t *params)
131 float base = sp_ctof(params[1]);
132 float exponent = sp_ctof(params[2]);
134 return sp_ftoc(pow(base, exponent));
137 static cell_t sm_SquareRoot(IPluginContext *pCtx, const cell_t *params)
139 float val = sp_ctof(params[1]);
143 return pCtx->ThrowNativeError("Cannot evaluate the square root of a negative number (val:%f)", val);
146 return sp_ftoc(sqrt(val));
149 static cell_t sm_RoundToNearest(IPluginContext *pCtx, const cell_t *params)
151 float val = sp_ctof(params[1]);
152 val = (float)floor(val + 0.5f);
154 return static_cast<int>(val);
157 static cell_t sm_RoundToFloor(IPluginContext *pCtx, const cell_t *params)
159 float val = sp_ctof(params[1]);
162 return static_cast<int>(val);
165 static cell_t sm_RoundToCeil(IPluginContext *pCtx, const cell_t *params)
167 float val = sp_ctof(params[1]);
170 return static_cast<int>(val);
173 static cell_t sm_RoundToZero(IPluginContext *pCtx, const cell_t *params)
175 float val = sp_ctof(params[1]);
183 return static_cast<int>(val);
186 static cell_t sm_FloatFraction(IPluginContext *pCtx, const cell_t *params)
188 float val = sp_ctof(params[1]);
189 val = val - floor(val);
194 static cell_t sm_Sine(IPluginContext *pCtx, const cell_t *params)
196 float val = sp_ctof(params[1]);
202 static cell_t sm_Cosine(IPluginContext *pCtx, const cell_t *params)
204 float val = sp_ctof(params[1]);
210 static cell_t sm_Tangent(IPluginContext *pCtx, const cell_t *params)
212 float val = sp_ctof(params[1]);
218 static cell_t sm_ArcSine(IPluginContext *pCtx, const cell_t *params)
220 float val = sp_ctof(params[1]);
226 static cell_t sm_ArcCosine(IPluginContext *pCtx, const cell_t *params)
228 float val = sp_ctof(params[1]);
234 static cell_t sm_ArcTangent(IPluginContext *pCtx, const cell_t *params)
236 float val = sp_ctof(params[1]);
242 static cell_t sm_ArcTangent2(IPluginContext *pCtx, const cell_t *params)
244 float val1 = sp_ctof(params[1]);
245 float val2 = sp_ctof(params[2]);
246 val1 = atan2(val1, val2);
248 return sp_ftoc(val1);
251 static cell_t sm_FloatRound(IPluginContext *pCtx, const cell_t *params)
253 float val = sp_ctof(params[1]);
279 val = (float)floor(val + 0.5f);
284 return static_cast<int>(val);
287 REGISTER_NATIVES(floatnatives)
290 {"FloatMul", sm_FloatMul},
291 {"FloatDiv", sm_FloatDiv},
292 {"FloatAdd", sm_FloatAdd},
293 {"FloatSub", sm_FloatSub},
294 {"FloatFraction", sm_FloatFraction},
295 {"RoundToZero", sm_RoundToZero},
296 {"RoundToCeil", sm_RoundToCeil},
297 {"RoundToFloor", sm_RoundToFloor},
298 {"RoundToNearest", sm_RoundToNearest},
299 {"FloatCompare", sm_FloatCompare},
300 {"SquareRoot", sm_SquareRoot},
302 {"Exponential", sm_Exponential},
303 {"Logarithm", sm_Logarithm},
305 {"Cosine", sm_Cosine},
306 {"Tangent", sm_Tangent},
307 {"FloatAbs", sm_FloatAbs},
308 {"ArcTangent", sm_ArcTangent},
309 {"ArcCosine", sm_ArcCosine},
310 {"ArcSine", sm_ArcSine},
311 {"ArcTangent2", sm_ArcTangent2},
312 {"FloatRound", sm_FloatRound}, /* Backwards compat shim */