forked from APGRoboCop/foxbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew util.cpp
2321 lines (1837 loc) · 51.7 KB
/
new 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
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/***
*
* Copyright (c) 1999, 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 "util.h"
#include "cbase.h"
#include "saverestore.h"
#include <time.h>
#include "shake.h"
#include "decals.h"
#include "player.h"
#include "weapons.h"
#include "gamerules.h"
//my incluse
#include "engine.h"
#include "bot.h"
#include "bot_func.h"
extern int mod_id;
extern bot_t bots[32];
extern edict_t *pent_info_ctfdetect;
extern char team_names[MAX_TEAMS][MAX_TEAMNAME_LENGTH];
extern int num_teams;
//int gmsgHUDNotify = 0;
//int gmsgTextMsg = 0;
//int gmsgSayText = 0;
//int gmsgShowMenu = 0;
float UTIL_WeaponTimeBase( void )
{
#if defined( CLIENT_WEAPONS )
return 0.0;
#else
return gpGlobals->time;
#endif
}
static unsigned int glSeed = 0;
unsigned int seed_table[ 256 ] =
{
28985, 27138, 26457, 9451, 17764, 10909, 28790, 8716, 6361, 4853, 17798, 21977, 19643, 20662, 10834, 20103,
27067, 28634, 18623, 25849, 8576, 26234, 23887, 18228, 32587, 4836, 3306, 1811, 3035, 24559, 18399, 315,
26766, 907, 24102, 12370, 9674, 2972, 10472, 16492, 22683, 11529, 27968, 30406, 13213, 2319, 23620, 16823,
10013, 23772, 21567, 1251, 19579, 20313, 18241, 30130, 8402, 20807, 27354, 7169, 21211, 17293, 5410, 19223,
10255, 22480, 27388, 9946, 15628, 24389, 17308, 2370, 9530, 31683, 25927, 23567, 11694, 26397, 32602, 15031,
18255, 17582, 1422, 28835, 23607, 12597, 20602, 10138, 5212, 1252, 10074, 23166, 19823, 31667, 5902, 24630,
18948, 14330, 14950, 8939, 23540, 21311, 22428, 22391, 3583, 29004, 30498, 18714, 4278, 2437, 22430, 3439,
28313, 23161, 25396, 13471, 19324, 15287, 2563, 18901, 13103, 16867, 9714, 14322, 15197, 26889, 19372, 26241,
31925, 14640, 11497, 8941, 10056, 6451, 28656, 10737, 13874, 17356, 8281, 25937, 1661, 4850, 7448, 12744,
21826, 5477, 10167, 16705, 26897, 8839, 30947, 27978, 27283, 24685, 32298, 3525, 12398, 28726, 9475, 10208,
617, 13467, 22287, 2376, 6097, 26312, 2974, 9114, 21787, 28010, 4725, 15387, 3274, 10762, 31695, 17320,
18324, 12441, 16801, 27376, 22464, 7500, 5666, 18144, 15314, 31914, 31627, 6495, 5226, 31203, 2331, 4668,
12650, 18275, 351, 7268, 31319, 30119, 7600, 2905, 13826, 11343, 13053, 15583, 30055, 31093, 5067, 761,
9685, 11070, 21369, 27155, 3663, 26542, 20169, 12161, 15411, 30401, 7580, 31784, 8985, 29367, 20989, 14203,
29694, 21167, 10337, 1706, 28578, 887, 3373, 19477, 14382, 675, 7033, 15111, 26138, 12252, 30996, 21409,
25678, 18555, 13256, 23316, 22407, 16727, 991, 9236, 5373, 29402, 6117, 15241, 27715, 19291, 19888, 19847
};
unsigned int U_Random( void )
{
glSeed *= 69069;
glSeed += seed_table[ glSeed & 0xff ];
return ( ++glSeed & 0x0fffffff );
}
void U_Srand( unsigned int seed )
{
glSeed = seed_table[ seed & 0xff ];
}
/*
=====================
UTIL_SharedRandomLong
=====================
*/
int UTIL_SharedRandomLong( unsigned int seed, int low, int high )
{
unsigned int range;
U_Srand( (int)seed + low + high );
range = high - low + 1;
if( !(range - 1) )
{
return low;
}
else
{
int offset;
int rnum;
rnum = U_Random();
offset = rnum % range;
return (low + offset);
}
}
/*
=====================
UTIL_SharedRandomFloat
=====================
*/
float UTIL_SharedRandomFloat( unsigned int seed, float low, float high )
{
//
unsigned int range;
U_Srand( (int)seed + *(int *)&low + *(int *)&high );
U_Random();
U_Random();
range = high - low;
if( !range )
{
return low;
}
else
{
int tensixrand;
float offset;
tensixrand = U_Random() & 65535;
offset = (float)tensixrand / 65536.0;
return (low + offset * range );
}
}
void UTIL_ParametricRocket( entvars_t *pev, Vector vecOrigin, Vector vecAngles, edict_t *owner )
{
pev->startpos = vecOrigin;
// Trace out line to end pos
TraceResult tr;
UTIL_MakeVectors( vecAngles );
UTIL_TraceLine( pev->startpos, pev->startpos + gpGlobals->v_forward * 8192, ignore_monsters, owner, &tr);
pev->endpos = tr.vecEndPos;
// Now compute how long it will take based on current velocity
Vector vecTravel = pev->endpos - pev->startpos;
float travelTime = 0.0;
if( pev->velocity.Length() > 0 )
{
travelTime = vecTravel.Length() / pev->velocity.Length();
}
pev->starttime = gpGlobals->time;
pev->impacttime = gpGlobals->time + travelTime;
}
int g_groupmask = 0;
int g_groupop = 0;
// Normal overrides
void UTIL_SetGroupTrace( int groupmask, int op )
{
g_groupmask = groupmask;
g_groupop = op;
ENGINE_SETGROUPMASK( g_groupmask, g_groupop );
}
void UTIL_UnsetGroupTrace( void )
{
g_groupmask = 0;
g_groupop = 0;
ENGINE_SETGROUPMASK( 0, 0 );
}
// Smart version, it'll clean itself up when it pops off stack
UTIL_GroupTrace::UTIL_GroupTrace( int groupmask, int op )
{
m_oldgroupmask = g_groupmask;
m_oldgroupop = g_groupop;
g_groupmask = groupmask;
g_groupop = op;
ENGINE_SETGROUPMASK( g_groupmask, g_groupop );
}
UTIL_GroupTrace::~UTIL_GroupTrace( void )
{
g_groupmask = m_oldgroupmask;
g_groupop = m_oldgroupop;
ENGINE_SETGROUPMASK( g_groupmask, g_groupop );
}
#define ENTVARS_COUNT (sizeof(gEntvarsDescription)/sizeof(gEntvarsDescription[0]))
#ifdef DEBUG
edict_t *DBG_EntOfVars( const entvars_t *pev )
{
if(pev->pContainingEntity != NULL)
return pev->pContainingEntity;
ALERT(at_console, "entvars_t pContainingEntity is NULL, calling into engine");
edict_t* pent = (*g_engfuncs.pfnFindEntityByVars)((entvars_t*)pev);
if(pent == NULL)
ALERT(at_console, "DAMN! Even the engine couldn't FindEntityByVars!");
((entvars_t *)pev)->pContainingEntity = pent;
return pent;
}
#endif //DEBUG
#ifdef DEBUG
void
DBG_AssertFunction(
BOOL fExpr,
const char* szExpr,
const char* szFile,
int szLine,
const char* szMessage)
{
if(fExpr)
return;
char szOut[512];
if(szMessage != NULL)
sprintf(szOut, "ASSERT FAILED:\n %s \n(%s@%d)\n%s", szExpr, szFile, szLine, szMessage);
else
sprintf(szOut, "ASSERT FAILED:\n %s \n(%s@%d)", szExpr, szFile, szLine);
ALERT(at_console, szOut);
}
#endif // DEBUG
/*BOOL UTIL_GetNextBestWeapon( CBasePlayer *pPlayer, CBasePlayerItem *pCurrentWeapon )
{
return g_pGameRules->GetNextBestWeapon( pPlayer, pCurrentWeapon );
}*/
// ripped this out of the engine
float UTIL_AngleMod(float a)
{
if(a < 0)
{
a = a + 360 * ((int)(a / 360) + 1);
}
else if(a >= 360)
{
a = a - 360 * ((int)(a / 360));
}
// a = (360.0/65536) * ((int)(a*(65536/360.0)) & 65535);
return a;
}
float UTIL_AngleDiff( float destAngle, float srcAngle )
{
float delta;
delta = destAngle - srcAngle;
if( destAngle > srcAngle )
{
if( delta >= 180 )
delta -= 360;
}
else
{
if( delta <= -180 )
delta += 360;
}
return delta;
}
// float UTIL_MoveToOrigin( edict_t *pent, const Vector vecGoal, float flDist, int iMoveType )
void UTIL_MoveToOrigin( edict_t *pent, const Vector &vecGoal, float flDist, int iMoveType )
{
float rgfl[3];
vecGoal.CopyToArray(rgfl);
// return MOVE_TO_ORIGIN ( pent, rgfl, flDist, iMoveType );
MOVE_TO_ORIGIN ( pent, rgfl, flDist, iMoveType );
}
int UTIL_EntitiesInBox( CBaseEntity **pList, int listMax, const Vector &mins, const Vector &maxs, int flagMask )
{
edict_t *pEdict = g_engfuncs.pfnPEntityOfEntIndex( 1 );
CBaseEntity *pEntity;
int count;
count = 0;
if( !pEdict )
return count;
for( int i = 1; i < gpGlobals->maxEntities; i++, pEdict++ )
{
if( pEdict->free ) // Not in use
continue;
if( flagMask && !(pEdict->v.flags & flagMask) ) // Does it meet the criteria?
continue;
if( mins.x > pEdict->v.absmax.x ||
mins.y > pEdict->v.absmax.y ||
mins.z > pEdict->v.absmax.z ||
maxs.x < pEdict->v.absmin.x ||
maxs.y < pEdict->v.absmin.y ||
maxs.z < pEdict->v.absmin.z )
continue;
pEntity = CBaseEntity::Instance(pEdict);
if( !pEntity )
continue;
pList[ count ] = pEntity;
count++;
if( count >= listMax )
return count;
}
return count;
}
int UTIL_MonstersInSphere( CBaseEntity **pList, int listMax,
const Vector ¢er, float radius )
{
edict_t *pEdict = g_engfuncs.pfnPEntityOfEntIndex( 1 );
CBaseEntity *pEntity;
int count;
float distance, delta;
count = 0;
float radiusSquared = radius * radius;
if( !pEdict )
return count;
for( int i = 1; i < gpGlobals->maxEntities; i++, pEdict++ )
{
if( pEdict->free ) // Not in use
continue;
if( !(pEdict->v.flags & (FL_CLIENT|FL_MONSTER)) ) // Not a client/monster ?
continue;
// Use origin for X & Y since they are centered for all monsters
// Now X
delta = center.x - pEdict->v.origin.x;//(pEdict->v.absmin.x + pEdict->v.absmax.x)*0.5;
delta *= delta;
if( delta > radiusSquared )
continue;
distance = delta;
// Now Y
delta = center.y - pEdict->v.origin.y;//(pEdict->v.absmin.y + pEdict->v.absmax.y)*0.5;
delta *= delta;
distance += delta;
if( distance > radiusSquared )
continue;
// Now Z
delta = center.z - (pEdict->v.absmin.z + pEdict->v.absmax.z)*0.5;
delta *= delta;
distance += delta;
if( distance > radiusSquared )
continue;
pEntity = CBaseEntity::Instance(pEdict);
if( !pEntity )
continue;
pList[ count ] = pEntity;
count++;
if( count >= listMax )
return count;
}
return count;
}
CBaseEntity *UTIL_FindEntityInSphere( CBaseEntity *pStartEntity,
const Vector &vecCenter, float flRadius )
{
edict_t *pentEntity = NULL;
if(pStartEntity != NULL)
pentEntity = pStartEntity->edict();
pentEntity = FIND_ENTITY_IN_SPHERE( pentEntity, vecCenter, flRadius);
if(!FNullEnt(pentEntity))
return CBaseEntity::Instance(pentEntity);
return NULL;
}
CBaseEntity *UTIL_FindEntityByString( CBaseEntity *pStartEntity,
const char *szKeyword, const char *szValue )
{
edict_t *pentEntity = NULL;
if(pStartEntity != NULL)
pentEntity = pStartEntity->edict();
pentEntity = FIND_ENTITY_BY_STRING( pentEntity, szKeyword, szValue );
if(!FNullEnt(pentEntity))
return CBaseEntity::Instance(pentEntity);
return NULL;
}
CBaseEntity *UTIL_FindEntityByClassname( CBaseEntity *pStartEntity, const char *szName )
{
return UTIL_FindEntityByString( pStartEntity, "classname", szName );
}
CBaseEntity *UTIL_FindEntityByTargetname( CBaseEntity *pStartEntity, const char *szName )
{
return UTIL_FindEntityByString( pStartEntity, "targetname", szName );
}
CBaseEntity *UTIL_FindEntityGeneric( const char *szWhatever, Vector &vecSrc, float flRadius )
{
CBaseEntity *pEntity = NULL;
pEntity = UTIL_FindEntityByTargetname( NULL, szWhatever );
if(pEntity)
return pEntity;
CBaseEntity *pSearch = NULL;
float flMaxDist2 = flRadius * flRadius;
while((pSearch = UTIL_FindEntityByClassname( pSearch, szWhatever )) != NULL)
{
float flDist2 = (pSearch->pev->origin - vecSrc).Length();
flDist2 = flDist2 * flDist2;
if(flMaxDist2 > flDist2)
{
pEntity = pSearch;
flMaxDist2 = flDist2;
}
}
return pEntity;
}
// returns a CBaseEntity pointer to a player by index. Only returns if the player is spawned and connected
// otherwise returns NULL
// Index is 1 based
CBaseEntity *UTIL_PlayerByIndex( int playerIndex )
{
CBaseEntity *pPlayer = NULL;
if( playerIndex > 0
&& playerIndex <= gpGlobals->maxClients )
{
edict_t *pPlayerEdict = INDEXENT( playerIndex );
if( pPlayerEdict && !pPlayerEdict->free )
{
pPlayer = CBaseEntity::Instance( pPlayerEdict );
}
}
return pPlayer;
}
// This function counts the number of clients currently in the game.
// It's basically a minor variant of the one posted by Leon Hartwig
// in the HLCoders list, and should(in theory) be able to cope with players
// who have only partially joined the server.
int UTIL_CountClientsInGame(void)
{
int total = 0;
for(int index = 1; index <= gpGlobals->maxClients; index++)
{
CBaseEntity *pPlayer = UTIL_PlayerByIndex(index);
// is this a valid connected player?
if(pPlayer == NULL
|| FNullEnt(pPlayer->pev)
|| FStrEq(STRING(pPlayer->pev->netname), ""))
continue;
total++;
}
return total;
}
void UTIL_MakeAimVectors( const Vector &vecAngles )
{
float rgflVec[3];
vecAngles.CopyToArray(rgflVec);
rgflVec[0] = -rgflVec[0];
MAKE_VECTORS(rgflVec);
}
#define SWAP(a,b,temp) ((temp)=(a),(a)=(b),(b)=(temp))
void UTIL_MakeInvVectors( const Vector &vec, globalvars_t *pgv )
{
MAKE_VECTORS(vec);
float tmp;
pgv->v_right = pgv->v_right * -1;
SWAP(pgv->v_forward.y, pgv->v_right.x, tmp);
SWAP(pgv->v_forward.z, pgv->v_up.x, tmp);
SWAP(pgv->v_right.z, pgv->v_up.y, tmp);
}
/*void UTIL_EmitAmbientSound( edict_t *entity, const Vector &vecOrigin, const char *samp, float vol, float attenuation, int fFlags, int pitch )
{
float rgfl[3];
vecOrigin.CopyToArray(rgfl);
if(samp && *samp == '!')
{
char name[32];
if(SENTENCEG_Lookup(samp, name) >= 0)
EMIT_AMBIENT_SOUND(entity, rgfl, name, vol, attenuation, fFlags, pitch);
}
else
EMIT_AMBIENT_SOUND(entity, rgfl, samp, vol, attenuation, fFlags, pitch);
}*/
static unsigned short FixedUnsigned16( float value, float scale )
{
int output;
output = value * scale;
if( output < 0 )
output = 0;
if( output > 0xFFFF )
output = 0xFFFF;
return (unsigned short)output;
}
static short FixedSigned16( float value, float scale )
{
int output;
output = value * scale;
if( output > 32767 )
output = 32767;
if( output < -32768 )
output = -32768;
return (short)output;
}
// Shake the screen of all clients within radius
// radius == 0, shake all clients
// UNDONE: Allow caller to shake clients not ONGROUND?
// UNDONE: Fix falloff model (disabled)?
// UNDONE: Affect user controls?
/*void UTIL_ScreenShake( const Vector ¢er, float amplitude, float frequency, float duration, float radius )
{
int i;
float localAmplitude;
ScreenShake shake;
shake.duration = FixedUnsigned16( duration, 1<<12 ); // 4.12 fixed
shake.frequency = FixedUnsigned16( frequency, 1<<8 ); // 8.8 fixed
for( i = 1; i <= gpGlobals->maxClients; i++ )
{
CBaseEntity *pPlayer = UTIL_PlayerByIndex( i );
if( !pPlayer || !(pPlayer->pev->flags & FL_ONGROUND) ) // Don't shake if not onground
continue;
localAmplitude = 0;
if( radius <= 0 )
localAmplitude = amplitude;
else
{
Vector delta = center - pPlayer->pev->origin;
float distance = delta.Length();
// Had to get rid of this falloff - it didn't work well
if( distance < radius )
localAmplitude = amplitude;//radius - distance;
}
if( localAmplitude )
{
shake.amplitude = FixedUnsigned16( localAmplitude, 1<<12 ); // 4.12 fixed
MESSAGE_BEGIN( MSG_ONE, gmsgShake, NULL, pPlayer->edict() ); // use the magic #1 for "one client"
WRITE_SHORT( shake.amplitude ); // shake amount
WRITE_SHORT( shake.duration ); // shake lasts this long
WRITE_SHORT( shake.frequency ); // shake noise frequency
MESSAGE_END();
}
}
}
void UTIL_ScreenShakeAll( const Vector ¢er, float amplitude, float frequency, float duration )
{
UTIL_ScreenShake( center, amplitude, frequency, duration, 0 );
}*/
void UTIL_ScreenFadeBuild( ScreenFade &fade, const Vector &color, float fadeTime, float fadeHold, int alpha, int flags )
{
fade.duration = FixedUnsigned16( fadeTime, 1<<12 ); // 4.12 fixed
fade.holdTime = FixedUnsigned16( fadeHold, 1<<12 ); // 4.12 fixed
fade.r = (int)color.x;
fade.g = (int)color.y;
fade.b = (int)color.z;
fade.a = alpha;
fade.fadeFlags = flags;
}
/*void UTIL_ScreenFadeWrite( const ScreenFade &fade, CBaseEntity *pEntity )
{
if( !pEntity || !pEntity->IsNetClient() )
return;
MESSAGE_BEGIN( MSG_ONE, gmsgFade, NULL, pEntity->edict() ); // use the magic #1 for "one client"
WRITE_SHORT( fade.duration ); // fade lasts this long
WRITE_SHORT( fade.holdTime ); // fade lasts this long
WRITE_SHORT( fade.fadeFlags ); // fade type (in / out)
WRITE_BYTE( fade.r ); // fade red
WRITE_BYTE( fade.g ); // fade green
WRITE_BYTE( fade.b ); // fade blue
WRITE_BYTE( fade.a ); // fade blue
MESSAGE_END();
}
void UTIL_ScreenFadeAll( const Vector &color, float fadeTime, float fadeHold, int alpha, int flags )
{
int i;
ScreenFade fade;
UTIL_ScreenFadeBuild( fade, color, fadeTime, fadeHold, alpha, flags );
for( i = 1; i <= gpGlobals->maxClients; i++ )
{
CBaseEntity *pPlayer = UTIL_PlayerByIndex( i );
UTIL_ScreenFadeWrite( fade, pPlayer );
}
}
void UTIL_ScreenFade( CBaseEntity *pEntity, const Vector &color, float fadeTime, float fadeHold, int alpha, int flags )
{
ScreenFade fade;
UTIL_ScreenFadeBuild( fade, color, fadeTime, fadeHold, alpha, flags );
UTIL_ScreenFadeWrite( fade, pEntity );
}*/
extern int UTIL_HudMessageAll( const hudtextparms_t &textparms, const char *pMessage )
{
int i;
for( i = 1; i <= gpGlobals->maxClients; i++ )
{
CBaseEntity *pPlayer = UTIL_PlayerByIndex( i );
if( pPlayer )
UTIL_HudMessage( pPlayer, textparms, pMessage );
}
}
extern int gmsgTextMsg, gmsgSayText;
void UTIL_ClientPrintAll( int msg_dest, const char *msg_name, const char *param1, const char *param2, const char *param3, const char *param4 )
{
MESSAGE_BEGIN( MSG_ALL, gmsgTextMsg );
WRITE_BYTE( msg_dest );
WRITE_STRING( msg_name );
if( param1 )
WRITE_STRING( param1 );
if( param2 )
WRITE_STRING( param2 );
if( param3 )
WRITE_STRING( param3 );
if( param4 )
WRITE_STRING( param4 );
MESSAGE_END();
}
void ClientPrint( entvars_t *client, int msg_dest, const char *msg_name, const char *param1, const char *param2, const char *param3, const char *param4 )
{
MESSAGE_BEGIN( MSG_ONE, gmsgTextMsg, NULL, client );
WRITE_BYTE( msg_dest );
WRITE_STRING( msg_name );
if( param1 )
WRITE_STRING( param1 );
if( param2 )
WRITE_STRING( param2 );
if( param3 )
WRITE_STRING( param3 );
if( param4 )
WRITE_STRING( param4 );
MESSAGE_END();
}
void UTIL_SayText( const char *pText, CBaseEntity *pEntity )
{
if( !pEntity->IsNetClient() )
return;
MESSAGE_BEGIN( MSG_ONE, gmsgSayText, NULL, pEntity->edict() );
WRITE_BYTE( pEntity->entindex() );
WRITE_STRING( pText );
MESSAGE_END();
}
void UTIL_SayTextAll( const char *pText, CBaseEntity *pEntity )
{
MESSAGE_BEGIN( MSG_ALL, gmsgSayText, NULL );
WRITE_BYTE( pEntity->entindex() );
WRITE_STRING( pText );
MESSAGE_END();
}
char *UTIL_dtos1( int d )
{
static char buf[8];
sprintf( buf, "%d", d );
return buf;
}
char *UTIL_dtos2( int d )
{
static char buf[8];
sprintf( buf, "%d", d );
return buf;
}
char *UTIL_dtos3( int d )
{
static char buf[8];
sprintf( buf, "%d", d );
return buf;
}
char *UTIL_dtos4( int d )
{
static char buf[8];
sprintf( buf, "%d", d );
return buf;
}
/*void UTIL_ShowMessage( const char *pString, CBaseEntity *pEntity )
{
if( !pEntity || !pEntity->IsNetClient() )
return;
MESSAGE_BEGIN( MSG_ONE, gmsgHudText, NULL, pEntity->edict() );
WRITE_STRING( pString );
MESSAGE_END();
}
void UTIL_ShowMessageAll( const char *pString )
{
int i;
// loop through all players
for( i = 1; i <= gpGlobals->maxClients; i++ )
{
CBaseEntity *pPlayer = UTIL_PlayerByIndex( i );
if( pPlayer )
UTIL_ShowMessage( pString, pPlayer );
}
}*/
void UTIL_TraceHull( const Vector &vecStart, const Vector &vecEnd, IGNORE_MONSTERS igmon, int hullNumber, edict_t *pentIgnore, TraceResult *ptr )
{
TRACE_HULL( vecStart, vecEnd, (igmon == ignore_monsters ? TRUE : FALSE), hullNumber, pentIgnore, ptr );
}
void UTIL_TraceModel( const Vector &vecStart, const Vector &vecEnd, int hullNumber, edict_t *pentModel, TraceResult *ptr )
{
g_engfuncs.pfnTraceModel( vecStart, vecEnd, hullNumber, pentModel, ptr );
}
TraceResult UTIL_GetGlobalTrace( )
{
TraceResult tr;
tr.fAllSolid = gpGlobals->trace_allsolid;
tr.fStartSolid = gpGlobals->trace_startsolid;
tr.fInOpen = gpGlobals->trace_inopen;
tr.fInWater = gpGlobals->trace_inwater;
tr.flFraction = gpGlobals->trace_fraction;
tr.flPlaneDist = gpGlobals->trace_plane_dist;
tr.pHit = gpGlobals->trace_ent;
tr.vecEndPos = gpGlobals->trace_endpos;
tr.vecPlaneNormal = gpGlobals->trace_plane_normal;
tr.iHitgroup = gpGlobals->trace_hitgroup;
return tr;
}
float UTIL_VecToYaw( const Vector &vec )
{
return VEC_TO_YAW(vec);
}
void UTIL_ParticleEffect( const Vector &vecOrigin, const Vector &vecDirection, ULONG ulColor, ULONG ulCount )
{
PARTICLE_EFFECT( vecOrigin, vecDirection, (float)ulColor, (float)ulCount );
}
float UTIL_Approach( float target, float value, float speed )
{
float delta = target - value;
if( delta > speed )
value += speed;
else if( delta < -speed )
value -= speed;
else
value = target;
return value;
}
float UTIL_ApproachAngle( float target, float value, float speed )
{
target = UTIL_AngleMod( target );
value = UTIL_AngleMod( target );
float delta = target - value;
// Speed is assumed to be positive
if( speed < 0 )
speed = -speed;
if( delta < -180 )
delta += 360;
else if( delta > 180 )
delta -= 360;
if( delta > speed )
value += speed;
else if( delta < -speed )
value -= speed;
else
value = target;
return value;
}
float UTIL_AngleDistance( float next, float cur )
{
float delta = next - cur;
if( delta < -180 )
delta += 360;
else if( delta > 180 )
delta -= 360;
return delta;
}
float UTIL_SplineFraction( float value, float scale )
{
value = scale * value;
float valueSquared = value * value;
// Nice little ease-in, ease-out spline-like curve
return 3 * valueSquared - 2 * valueSquared * value;
}
Vector UTIL_GetAimVector( edict_t *pent, float flSpeed )
{
Vector tmp;
GET_AIM_VECTOR(pent, flSpeed, tmp);
return tmp;
}
int UTIL_IsMasterTriggered(string_t sMaster, CBaseEntity *pActivator)
{
if(sMaster)
{
edict_t *pentTarget = FIND_ENTITY_BY_TARGETNAME(NULL, STRING(sMaster));
if( !FNullEnt(pentTarget) )
{
CBaseEntity *pMaster = CBaseEntity::Instance(pentTarget);
if( pMaster && (pMaster->ObjectCaps() & FCAP_MASTER) )
return pMaster->IsTriggered( pActivator );
}
ALERT(at_console, "Master was null or not a master!\n");
}
// if this isn't a master entity, just say yes.
return 1;
}
BOOL UTIL_ShouldShowBlood( int color )
{
if( color != DONT_BLEED )
{
if( color == BLOOD_COLOR_RED )
{
if( CVAR_GET_FLOAT("violence_hblood") != 0 )
return TRUE;
}
else
{
if( CVAR_GET_FLOAT("violence_ablood") != 0 )
return TRUE;
}
}
return FALSE;
}
void UTIL_BloodStream( const Vector &origin, const Vector &direction, int color, int amount )
{
if( !UTIL_ShouldShowBlood( color ) )
return;
if( g_Language == LANGUAGE_GERMAN && color == BLOOD_COLOR_RED )
color = 0;
MESSAGE_BEGIN( MSG_PVS, SVC_TEMPENTITY, origin );
WRITE_BYTE( TE_BLOODSTREAM );