forked from Bots-United/jk_botti
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot_inline_funcs.h
153 lines (120 loc) · 4.43 KB
/
bot_inline_funcs.h
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
//
// JK_Botti - be more human!
//
// bot_inline_funcs.h
//
#ifndef BOT_INLINE_FUNCS
#define BOT_INLINE_FUNCS
#include <inttypes.h>
#include <sys/time.h>
// Manual branch optimization for GCC 3.0.0 and newer
#if !defined(__GNUC__) || __GNUC__ < 3
#define likely(x) (x)
#define unlikely(x) (x)
#else
#define likely(x) __builtin_expect((long int)!!(x), true)
#define unlikely(x) __builtin_expect((long int)!!(x), false)
#endif
//
inline Vector GetGunPosition(edict_t *pEdict)
{
return (pEdict->v.origin + pEdict->v.view_ofs);
}
inline void UTIL_SelectItem(edict_t *pEdict, const char *item_name)
{
FakeClientCommand(pEdict, item_name, NULL, NULL);
}
// Overloaded to add IGNORE_GLASS
inline void UTIL_TraceLine( const Vector & vecStart, const Vector &vecEnd, IGNORE_MONSTERS igmon, IGNORE_GLASS ignoreGlass, edict_t *pentIgnore, TraceResult *ptr )
{
TRACE_LINE( vecStart, vecEnd, (igmon == ignore_monsters ? TRUE : FALSE) | (ignoreGlass?0x100:0), pentIgnore, ptr );
}
inline void UTIL_TraceLine( const Vector &vecStart, const Vector &vecEnd, IGNORE_MONSTERS igmon, edict_t *pentIgnore, TraceResult *ptr )
{
TRACE_LINE( vecStart, vecEnd, (igmon == ignore_monsters ? TRUE : FALSE), pentIgnore, ptr );
}
inline 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 );
}
inline void UTIL_TraceMove( const Vector &vecStart, const Vector &vecEnd, IGNORE_MONSTERS igmon, edict_t *pentIgnore, TraceResult *ptr )
{
TRACE_HULL( vecStart, vecEnd, (igmon == ignore_monsters ? TRUE : FALSE), point_hull, pentIgnore, ptr );
}
inline void UTIL_TraceDuck( const Vector &vecStart, const Vector &vecEnd, IGNORE_MONSTERS igmon, edict_t *pentIgnore, TraceResult *ptr )
{
TRACE_HULL( vecStart, vecEnd, (igmon == ignore_monsters ? TRUE : FALSE), head_hull, pentIgnore, ptr );
}
inline edict_t *UTIL_FindEntityInSphere( edict_t *pentStart, const Vector &vecCenter, float flRadius )
{
edict_t *pentEntity;
pentEntity = FIND_ENTITY_IN_SPHERE( pentStart, vecCenter, flRadius);
if (likely(!FNullEnt(pentEntity)))
return pentEntity;
return NULL;
}
inline edict_t *UTIL_FindEntityByString( edict_t *pentStart, const char *szKeyword, const char *szValue )
{
edict_t *pentEntity;
pentEntity = FIND_ENTITY_BY_STRING( pentStart, szKeyword, szValue );
if (likely(!FNullEnt(pentEntity)))
return pentEntity;
return NULL;
}
inline edict_t *UTIL_FindEntityByClassname( edict_t *pentStart, const char *szName )
{
return UTIL_FindEntityByString( pentStart, "classname", szName );
}
inline edict_t *UTIL_FindEntityByTarget( edict_t *pentStart, const char *szName )
{
return UTIL_FindEntityByString( pentStart, "target", szName );
}
inline edict_t *UTIL_FindEntityByTargetname( edict_t *pentStart, const char *szName )
{
return UTIL_FindEntityByString( pentStart, "targetname", szName );
}
inline double deg2rad(double deg)
{
return(deg * (M_PI / 180));
}
inline void BotFixIdealPitch(edict_t *pEdict)
{
pEdict->v.idealpitch = UTIL_WrapAngle(pEdict->v.idealpitch);
}
inline void BotFixIdealYaw(edict_t *pEdict)
{
pEdict->v.ideal_yaw = UTIL_WrapAngle(pEdict->v.ideal_yaw);
}
inline Vector UTIL_GetOrigin(edict_t *pEdict)
{
// if(strncmp(STRING(pEdict->v.classname), "func_", 5) == 0)
if(unlikely(pEdict->v.solid == SOLID_BSP))
return VecBModelOrigin(pEdict);
return pEdict->v.origin;
}
inline Vector UTIL_GetOriginWithExtent(bot_t &pBot, edict_t *pTarget)
{
return(UTIL_AdjustOriginWithExtent(pBot, UTIL_GetOrigin(pTarget), pTarget));
}
inline void UTIL_ParticleEffect( const Vector &vecOrigin, const Vector &vecDirection, ULONG ulColor, ULONG ulCount )
{
PARTICLE_EFFECT( vecOrigin, vecDirection, (float)ulColor, (float)ulCount );
}
inline qboolean FIsClassname(edict_t * pent, const char * cname)
{
return(likely(pent)?strcmp(STRING(pent->v.classname), cname)==0:FALSE);
}
inline qboolean FIsClassname(const char * cname, edict_t * pent)
{
return(FIsClassname(pent, cname));
}
inline qboolean FVisible( const Vector &vecOrigin, edict_t *pEdict, edict_t * pOrigin )
{
edict_t * pHit = NULL;
return(FVisible(vecOrigin, pEdict, &pHit) || (pOrigin != NULL && pHit == pOrigin));
}
inline qboolean FVisible( const Vector &vecOrigin, edict_t *pEdict )
{
return(FVisible(vecOrigin, pEdict, (edict_t **)NULL));
}
#endif /*BOT_INLINE_FUNCS*/