forked from APGRoboCop/foxbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsdk_util.cpp
100 lines (79 loc) · 2.22 KB
/
sdk_util.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// vi: set ts=4 sw=4 :
// vim: set tw=75 :
// sdk_util.cpp - utility routines from HL SDK util.cpp
// Selected portions of dlls/util.cpp from SDK 2.1.
// Functions copied from there as needed...
/***
*
* Copyright (c) 1999, 2000 Valve LLC. All rights reserved.
*
* This product contains software technology licensed from Id
* Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc.
* All Rights Reserved.
*
* Use, distribution, and modification of this source code and/or resulting
* object code is restricted to non-commercial enhancements to products from
* Valve LLC. All other use, distribution, or modification is prohibited
* without written permission from Valve LLC.
*
****/
/*
===== util.cpp ========================================================
Utility code. Really not optional after all.
*/
#include <extdll.h>
#include "sdk_util.h"
#include "cbase.h"
#include <string.h>
#include "osdep.h" // win32 v_snprintf, etc
char* UTIL_VarArgs(char* format, ...)
{
va_list argptr;
static char string[1024];
va_start(argptr, format);
#ifdef WIN32
_vsnprintf(string, 1024, format, argptr);
#else
_vsnprintf(string, 1024, format, argptr);
#endif
va_end(argptr);
return string;
}
//=========================================================
// UTIL_LogPrintf - Prints a logged message to console.
// Preceded by LOG: ( timestamp ) < message >
//=========================================================
void UTIL_LogPrintf(char* format, ...)
{
va_list argptr;
static char string[1024];
va_start(argptr, format);
#ifdef WIN32
_vsnprintf(string, 1024, format, argptr);
#else
_vsnprintf(string, 1024, format, argptr);
#endif
va_end(argptr);
// Print to server console
ALERT(at_logged, "%s", string);
}
short FixedSigned16(float value, float scale)
{
int output;
output = (int)(value * scale);
if(output > 32767)
output = 32767;
if(output < -32768)
output = -32768;
return (short)output;
}
unsigned short FixedUnsigned16(float value, float scale)
{
int output;
output = (int)(value * scale);
if(output < 0)
output = 0;
if(output > 0xFFFF)
output = 0xFFFF;
return (unsigned short)output;
}