This repository has been archived by the owner on Nov 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
utility.qc
218 lines (181 loc) · 4.52 KB
/
utility.qc
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
void(string s, string ss) dprint2 =
{ dprint(s); dprint(ss); }
void(string s, string ss, string sss) dprint3 =
{ dprint(s); dprint(ss); dprint(sss); }
void(string s, string ss, string sss, string ssss) dprint4 =
{ dprint(s); dprint(ss); dprint(sss); dprint(ssss); }
void(string s, string ss, string sss, string ssss, string sssss) dprint5 =
{ dprint(s); dprint(ss); dprint(sss); dprint(ssss); dprint(sssss); }
void(string s, string ss, string sss, string ssss, string sssss, string ssssss) dprint6 =
{ dprint(s); dprint(ss); dprint(sss); dprint(ssss); dprint(sssss); dprint(ssssss);}
void(string s, string ss, string sss, string ssss, string sssss, string ssssss, string sssssss) dprint7 =
{ dprint(s); dprint(ss); dprint(sss); dprint(ssss); dprint(sssss); dprint(ssssss); dprint(sssssss);}
void(string s, string ss, string sss, string ssss, string sssss, string ssssss, string sssssss, string ssssssss) dprint8 =
{ dprint(s); dprint(ss); dprint(sss); dprint(ssss); dprint(sssss); dprint(ssssss); dprint(sssssss); dprint(ssssssss); }
void(string s, string ss, string sss, string ssss, string sssss, string ssssss, string sssssss, string ssssssss, string sssssssss) dprint9 =
{ dprint(s); dprint(ss); dprint(sss); dprint(ssss); dprint(sssss); dprint(ssssss); dprint(sssssss); dprint(ssssssss); dprint(sssssssss); }
/**********************************
Sourced from utility.qc from smej2
**********************************/
float(float in) bprint_int =
{
in = floor(in);
if (in <= 0) return 0;
float digit;
digit = in - bprint_int(in / 10);
switch(digit) {
case 9:
bprint("9"); break;
case 8:
bprint("8"); break;
case 7:
bprint("7"); break;
case 6:
bprint("6"); break;
case 5:
bprint("5"); break;
case 4:
bprint("4"); break;
case 3:
bprint("3"); break;
case 2:
bprint("2"); break;
case 1:
bprint("1"); break;
case 0:
bprint("0"); break;
}
return in * 10;
}
float(float in, float def) defaultFl = {
if (in) return in;
else return def;
}
// shorthand for turning -1 to 0 for keyvalues for which 0 is a valid non-default selection
float(float in) zeroconvert =
{
if (in == -1) return 0;
return in;
}
float(float in, float def) zeroconvertdefault =
{
if (in == -1) return 0;
if (in == 0) return def;
return in;
}
// for measuring how large an entity is along an arbitrary vector
// FIXME: this is trash and it returns trash
float(vector v, vector s) BoundsAngleSize =
{
v_x = fabs(v_x);
v_y = fabs(v_y);
v_z = fabs(v_z);
// size is always + + + but this is in case I switch the parameters somewhere
s_x = fabs(s_x);
s_y = fabs(s_y);
s_z = fabs(s_z);
return v * s;
}
//count -4 = numclients in coop
/*void(.float fld) playercount_convert =
{
if (self.fld != -4) return;
if (!coop)
self.fld = 1;
else
self.fld = clients;
}
*/
// wonderful stuffcmd code from Honey by czg
/*
=============
stuffcmd_float
This is a horrible hack that I am ashamed of!
===============
*/
void stuffcmd_digit( entity client, float f) =
{
float d;
d = floor(f);
d = mod(d, 10);
//CLOSE YOUR EYES, HONEY! DON'T LOOK!
if(d == 0)
stuffcmd(client, "0");
else if(d == 1)
stuffcmd(client, "1");
else if(d == 2)
stuffcmd(client, "2");
else if(d == 3)
stuffcmd(client, "3");
else if(d == 4)
stuffcmd(client, "4");
else if(d == 5)
stuffcmd(client, "5");
else if(d == 6)
stuffcmd(client, "6");
else if(d == 7)
stuffcmd(client, "7");
else if(d == 8)
stuffcmd(client, "8");
else if(d == 9)
stuffcmd(client, "9");
}
void stuffcmd_int( entity client, float f, float numdigits) =
{
float tmp;
if(f == 0)
{
stuffcmd( client, "0");
return;
}
if(f < 0)
{
// Yeah sure.
stuffcmd( client, "-");
f = fabs(f);
}
if(numdigits <= 0)
{
tmp = f;
numdigits = 1;
while(tmp >= 1){
tmp = tmp / 10;
numdigits = numdigits * 10;
}
}
//I don't know what I'm thinking here...
//I need to do this to get zero-padding to work.
while( numdigits > 1 )
{
numdigits = numdigits / 10;
tmp = f / numdigits;
stuffcmd_digit( client, tmp);
}
}
void stuffcmd_float( entity client, float f) =
{
float intpart, decpart, isNegative;
isNegative = FALSE;
if(f == 0)
{
stuffcmd( client, "0");
return;
}
if(f < 0)
{
// easier this way
isNegative = TRUE;
f = fabs(f);
}
// 1: stuff the integer part.
intpart = floor(f);
if(isNegative)
stuffcmd( client, "-");
stuffcmd_int( client, intpart, 0);
// 2: stuff the decimal point.
stuffcmd( client, ".");
// 3: stuff the decimal part.
decpart = mod( f, 1);
decpart = decpart * 10000;
stuffcmd_int( client, decpart, 10000);
}