Update CS:GO team score gamedata.
2 * vim: set ts=4 sw=4 tw=99 :
3 * =============================================================================
5 * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
6 * =============================================================================
8 * This program is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, version 3.0, as published by the
10 * Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
20 * As a special exception, AlliedModders LLC gives you permission to link the
21 * code of this program (as well as its derivative works) to "Half-Life 2," the
22 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
23 * by the Valve Corporation. You must obey the GNU General Public License in
24 * all respects for all other code used. Additionally, AlliedModders LLC grants
25 * this exception to all derivative works. AlliedModders LLC defines further
26 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
27 * or <http://www.sourcemod.net/license.php>.
35 #include "common_logic.h"
36 #include "MersenneTwister.h"
37 #include <IPluginSys.h>
38 #include <am-utility.h>
40 /****************************************
42 * FLOATING POINT NATIVE IMPLEMENTATIONS *
44 ****************************************/
47 static cell_t sm_float(IPluginContext *pCtx, const cell_t *params)
49 float val = static_cast<float>(params[1]);
54 static cell_t sm_FloatAbs(IPluginContext *pCtx, const cell_t *params)
56 float val = sp_ctof(params[1]);
57 val = (val >= 0.0f) ? val : -val;
62 static cell_t sm_FloatAdd(IPluginContext *pCtx, const cell_t *params)
64 float val = sp_ctof(params[1]) + sp_ctof(params[2]);
69 static cell_t sm_FloatSub(IPluginContext *pCtx, const cell_t *params)
71 float val = sp_ctof(params[1]) - sp_ctof(params[2]);
76 static cell_t sm_FloatMul(IPluginContext *pCtx, const cell_t *params)
78 float val = sp_ctof(params[1]) * sp_ctof(params[2]);
83 static cell_t sm_FloatDiv(IPluginContext *pCtx, const cell_t *params)
85 float val = sp_ctof(params[1]) / sp_ctof(params[2]);
90 static cell_t sm_FloatGt(IPluginContext *pCtx, const cell_t *params)
92 return !!(sp_ctof(params[1]) > sp_ctof(params[2]));
95 static cell_t sm_FloatGe(IPluginContext *pCtx, const cell_t *params)
97 return !!(sp_ctof(params[1]) >= sp_ctof(params[2]));
100 static cell_t sm_FloatLt(IPluginContext *pCtx, const cell_t *params)
102 return !!(sp_ctof(params[1]) < sp_ctof(params[2]));
105 static cell_t sm_FloatLe(IPluginContext *pCtx, const cell_t *params)
107 return !!(sp_ctof(params[1]) <= sp_ctof(params[2]));
110 static cell_t sm_FloatEq(IPluginContext *pCtx, const cell_t *params)
112 return !!(sp_ctof(params[1]) == sp_ctof(params[2]));
115 static cell_t sm_FloatNe(IPluginContext *pCtx, const cell_t *params)
117 return !!(sp_ctof(params[1]) != sp_ctof(params[2]));
120 static cell_t sm_FloatNot(IPluginContext *pCtx, const cell_t *params)
122 float val = sp_ctof(params[1]);
128 static cell_t sm_FloatCompare(IPluginContext *pCtx, const cell_t *params)
130 float val1 = sp_ctof(params[1]);
131 float val2 = sp_ctof(params[2]);
136 } else if (val1 < val2) {
143 static cell_t sm_Logarithm(IPluginContext *pCtx, const cell_t *params)
145 float val = sp_ctof(params[1]);
146 float base = sp_ctof(params[2]);
148 if ((val <= 0.0f) || (base <= 0.0f))
150 return pCtx->ThrowNativeError("Cannot evaluate the logarithm of zero or a negative number (val:%f base:%f)", val, base);
156 val = log(val) / log(base);
162 static cell_t sm_Exponential(IPluginContext *pCtx, const cell_t *params)
164 float val = sp_ctof(params[1]);
166 return sp_ftoc(exp(val));
169 static cell_t sm_Pow(IPluginContext *pCtx, const cell_t *params)
171 float base = sp_ctof(params[1]);
172 float exponent = sp_ctof(params[2]);
174 return sp_ftoc(pow(base, exponent));
177 static cell_t sm_SquareRoot(IPluginContext *pCtx, const cell_t *params)
179 float val = sp_ctof(params[1]);
183 return pCtx->ThrowNativeError("Cannot evaluate the square root of a negative number (val:%f)", val);
186 return sp_ftoc(sqrt(val));
189 static cell_t sm_RoundToNearest(IPluginContext *pCtx, const cell_t *params)
191 float val = sp_ctof(params[1]);
192 val = (float)floor(val + 0.5f);
194 return static_cast<int>(val);
197 static cell_t sm_RoundToFloor(IPluginContext *pCtx, const cell_t *params)
199 float val = sp_ctof(params[1]);
202 return static_cast<int>(val);
205 static cell_t sm_RoundToCeil(IPluginContext *pCtx, const cell_t *params)
207 float val = sp_ctof(params[1]);
210 return static_cast<int>(val);
213 static cell_t sm_RoundToZero(IPluginContext *pCtx, const cell_t *params)
215 float val = sp_ctof(params[1]);
223 return static_cast<int>(val);
226 static cell_t sm_FloatFraction(IPluginContext *pCtx, const cell_t *params)
228 float val = sp_ctof(params[1]);
229 val = val - floor(val);
234 static cell_t sm_Sine(IPluginContext *pCtx, const cell_t *params)
236 float val = sp_ctof(params[1]);
242 static cell_t sm_Cosine(IPluginContext *pCtx, const cell_t *params)
244 float val = sp_ctof(params[1]);
250 static cell_t sm_Tangent(IPluginContext *pCtx, const cell_t *params)
252 float val = sp_ctof(params[1]);
258 static cell_t sm_ArcSine(IPluginContext *pCtx, const cell_t *params)
260 float val = sp_ctof(params[1]);
266 static cell_t sm_ArcCosine(IPluginContext *pCtx, const cell_t *params)
268 float val = sp_ctof(params[1]);
274 static cell_t sm_ArcTangent(IPluginContext *pCtx, const cell_t *params)
276 float val = sp_ctof(params[1]);
282 static cell_t sm_ArcTangent2(IPluginContext *pCtx, const cell_t *params)
284 float val1 = sp_ctof(params[1]);
285 float val2 = sp_ctof(params[2]);
286 val1 = atan2(val1, val2);
288 return sp_ftoc(val1);
292 static cell_t sm_FloatRound(IPluginContext *pCtx, const cell_t *params)
294 float val = sp_ctof(params[1]);
320 val = (float)floor(val + 0.5f);
325 return static_cast<int>(val);
329 class RandomHelpers :
330 public SMGlobalClass,
331 public IPluginsListener
334 void OnSourceModAllInitialized()
336 pluginsys->AddPluginsListener(this);
339 void OnSourceModShutdown()
341 pluginsys->RemovePluginsListener(this);
344 void OnPluginDestroyed(IPlugin *plugin)
347 if (plugin->GetProperty("core.logic.mtrand", (void**)&mtrand, true))
353 MTRand *RandObjForPlugin(IPluginContext *ctx)
355 IPlugin *plugin = pluginsys->FindPluginByContext(ctx->GetContext());
357 if (!plugin->GetProperty("core.logic.mtrand", (void**)&mtrand))
359 mtrand = new MTRand();
360 plugin->SetProperty("core.logic.mtrand", mtrand);
366 static cell_t GetURandomInt(IPluginContext *ctx, const cell_t *params)
368 MTRand *randobj = s_RandHelpers.RandObjForPlugin(ctx);
369 /* Note the sign bit must be stripped off because cell_t is signed,
370 * and this guarantees a range of [0,max_int]
372 return randobj->randInt() & 0x7FFFFFFF;
375 static cell_t GetURandomFloat(IPluginContext *ctx, const cell_t *params)
377 MTRand *randobj = s_RandHelpers.RandObjForPlugin(ctx);
378 return sp_ftoc((float)randobj->rand());
381 static cell_t SetURandomSeed(IPluginContext *ctx, const cell_t *params)
383 MTRand *randobj = s_RandHelpers.RandObjForPlugin(ctx);
385 ctx->LocalToPhysAddr(params[1], &addr);
386 /* We're 32-bit only. */
387 randobj->seed((MTRand::uint32*)addr, params[2]);
391 REGISTER_NATIVES(floatnatives)
394 {"FloatMul", sm_FloatMul},
395 {"FloatDiv", sm_FloatDiv},
396 {"FloatAdd", sm_FloatAdd},
397 {"FloatSub", sm_FloatSub},
398 {"FloatFraction", sm_FloatFraction},
399 {"RoundToZero", sm_RoundToZero},
400 {"RoundToCeil", sm_RoundToCeil},
401 {"RoundToFloor", sm_RoundToFloor},
402 {"RoundToNearest", sm_RoundToNearest},
403 {"__FLOAT_GT__", sm_FloatGt},
404 {"__FLOAT_GE__", sm_FloatGe},
405 {"__FLOAT_LT__", sm_FloatLt},
406 {"__FLOAT_LE__", sm_FloatLe},
407 {"__FLOAT_EQ__", sm_FloatEq},
408 {"__FLOAT_NE__", sm_FloatNe},
409 {"__FLOAT_NOT__", sm_FloatNot},
410 {"FloatCompare", sm_FloatCompare},
411 {"SquareRoot", sm_SquareRoot},
413 {"Exponential", sm_Exponential},
414 {"Logarithm", sm_Logarithm},
416 {"Cosine", sm_Cosine},
417 {"Tangent", sm_Tangent},
418 {"FloatAbs", sm_FloatAbs},
419 {"ArcTangent", sm_ArcTangent},
420 {"ArcCosine", sm_ArcCosine},
421 {"ArcSine", sm_ArcSine},
422 {"ArcTangent2", sm_ArcTangent2},
423 {"GetURandomInt", GetURandomInt},
424 {"GetURandomFloat", GetURandomFloat},
425 {"SetURandomSeed", SetURandomSeed},