-
Notifications
You must be signed in to change notification settings - Fork 1
/
mb_hud.cpp
198 lines (158 loc) · 5.27 KB
/
mb_hud.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
///////////////////////////////////////////////////////////////////////////////////////////////
//
// -- GNU -- open source
// Please read and agree to the mb_gnu_license.txt file
// (the file is located in the marine_bot source folder)
// before editing or distributing this source code.
// This source code is free for use under the rules of the GNU General Public License.
// For more information goto:: http://www.gnu.org/licenses/
//
// credits to - valve, botman.
//
// Marine Bot - code by Frank McNeil, Kota@, Mav, Shrike.
//
// (http://marinebot.xf.cz)
//
//
// mb_hud.cpp
//
////////////////////////////////////////////////////////////////////////////////////////////////
#if defined(WIN32)
#pragma warning(disable: 4005 91)
#endif
#include "defines.h"
#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "bot.h"
#include "bot_manager.h"
extern edict_t *listenserver_edict;
static unsigned short FixedUnsigned16( float value, float scale )
{
int output = value * scale;
if ( output < 0 )
output = 0;
if ( output > 0xFFFF )
output = 0xFFFF;
return static_cast<unsigned short>(output);
}
static short FixedSigned16( float value, float scale )
{
int output = value * scale;
if ( output > 32767 )
output = 32767;
if ( output < -32768 )
output = -32768;
return static_cast<short>(output);
}
/*
* creates a HUD text message
* the maximal length of the text is 512 chars because of engine limitation
*/
void FullCustHudMessage(edict_t* pEntity, const char* msg_name, int channel, int pos_x, int pos_y, int gfx,
const Vector color1, const Vector color2, int brightness, float fade_in, float fade_out, float duration)
{
MESSAGE_BEGIN(MSG_ONE, SVC_TEMPENTITY, nullptr, pEntity);
WRITE_BYTE( TE_TEXTMESSAGE);
WRITE_BYTE( channel & 0xFF ); // channel ???
WRITE_SHORT( FixedSigned16( pos_x, -1<<13 ) ); // x coord on the screen
WRITE_SHORT( FixedSigned16( pos_y, -1<<13 ) ); // y coord on the screen
WRITE_BYTE(gfx); // 0 no effect // 1 flashing // 2 fade over effect
WRITE_BYTE(color1.x); //r // all to 255 is white // all to 0 is transparent
WRITE_BYTE(color1.y); //g
WRITE_BYTE(color1.z); //b
WRITE_BYTE(brightness); //opacity/brightness
WRITE_BYTE(color2.x); //r
WRITE_BYTE(color2.y); //g
WRITE_BYTE(color2.z); //b
WRITE_BYTE(brightness);
WRITE_SHORT( FixedUnsigned16( fade_in, 1<<8 ) ); // fade in time
WRITE_SHORT( FixedUnsigned16( fade_out, 1<<8 ) ); // fade out time
WRITE_SHORT( FixedUnsigned16( duration, 1<<8 ) ); // hold time
if (gfx == 2)
WRITE_SHORT( FixedUnsigned16( 4, 1<<8 ) ); // Red over lay after 4 seconds (only in gfx mode 2)
WRITE_STRING(msg_name);
MESSAGE_END();
}
/*
* displays plain HUD message for given time
* gfx may only be 0 or 1
*/
void StdHudMessage(edict_t *pEntity, const char *msg_name, int gfx, int time)
{
// to prevent crashing HL due to overloading the engine
if (internals.GetHUDMessageTime() > gpGlobals->time)
return;
edict_t *pEdict;
if ((gfx == 0 ) || ((gfx < 0 || gfx > 1)))
gfx = 0;
if ((time == 0 ) || ((time < 1 || time > 10)))
time = 4;
if (pEntity == nullptr)
pEdict = listenserver_edict;
else
pEdict = pEntity;
// shade of red
const Vector color = Vector(200, 60, 40);
FullCustHudMessage(pEdict, msg_name, 2, 0, 0, gfx, color, color, 200, 0.03, 0.1, time);
}
/*
* sends the plain HUD message to all real clients (ie. not to bots)
*/
void StdHudMessageToAll(const char *msg_name, int gfx, int time)
{
for (int i = 0; i < MAX_CLIENTS; i++)
{
if ((clients[i].pEntity != nullptr) && (clients[i].IsHuman()))
{
StdHudMessage(clients[i].pEntity, msg_name, gfx, time);
}
}
}
/*
* displays a HUD message where user can specify also color of the message
*/
void CustHudMessage(edict_t *pEntity, const char *msg_name, const Vector color1, const Vector color2, int gfx, int time)
{
if (internals.GetHUDMessageTime() < gpGlobals->time)
FullCustHudMessage(pEntity, msg_name, 3, 1, 0, gfx, color1, color2, 200, 0.03, 1.0, time);
}
/*
* sends the custom HUD message to all real clients (ie. not to bots)
*/
void CustHudMessageToAll(const char *msg_name, const Vector color1, const Vector color2, int gfx, int time)
{
for (int i = 0; i < MAX_CLIENTS; i++)
{
if ((clients[i].pEntity != nullptr) && (clients[i].IsHuman()))
{
CustHudMessage(clients[i].pEntity, msg_name, color1, color2, gfx, time);
}
}
}
/*
* displays a transparent HUD message at top left corner for 5 seconds
*/
void DisplayMsg(edict_t *pEntity, const char *msg)
{
if (internals.GetHUDMessageTime() > gpGlobals->time)
return;
// to prevent overloading HL engine, crashed if this message is used alot
// so just don't allow to print this message every frame
internals.SetHUDMessageTime(gpGlobals->time + 0.5f);
// we're using just one color for this message
const Vector color = Vector(0, 255, 20);
// displays the message
FullCustHudMessage(pEntity, msg, 3, 0, 0, 0, color, color, 200, 0.03, 0.03, 5.0);
}
/*
* displays a transparent HUD message by the top of the screen for given time
*/
void CustDisplayMsg(edict_t *pEntity, const char *msg, int x_pos, float time)
{
if (internals.GetHUDMessageTime() > gpGlobals->time)
return;
internals.SetHUDMessageTime(gpGlobals->time + 0.5f);
const Vector color = Vector(0, 255, 20);
FullCustHudMessage(pEntity, msg, 3, x_pos, 0, 0, color, color, 200, 0.03, 0.03, time);
}