forked from fabiolimamp/alkaline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcshud.qc
560 lines (463 loc) · 15.1 KB
/
cshud.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
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
vector screensize;
float st_items, st_items2, st_weapons, st_activeweapon, prevweapons;
float st_boots, st_boots_finished;
float baralpha, hudalpha;
// Default sizes for HUD elements
vector HUDSIZE_24 = '24 24 0'; // Status Bar
vector HUDSIZE_16 = '16 16 0'; // Inventory/Powerups
vector HUDSIZE_1624 = '16 24 0'; // Special key background
vector HUDSIZE_816 = '8 16 0'; // Old Vertical Runes
vector HUDSIZE_168 = '16 8 0'; // Silver/Gold/Custom Keys
vector HUDSIZE_8 = '8 8 0'; // Ammo numbers
vector HUDSIZE_C8 = '8 0 0'; // Character sizes
// 8 pixel font table (index positions)
float HUDFONT_WHITE = 0; // Default index = 48-57
float HUDFONT_YELLOW = 1; // index = index - 30
float HUDFONT_RED = 2; // index = index + 128
vector HUDRGB_DEF = '1 1 1';
string number[10] = {
"gfx/xnum_0",
"gfx/xnum_1",
"gfx/xnum_2",
"gfx/xnum_3",
"gfx/xnum_4",
"gfx/xnum_5",
"gfx/xnum_6",
"gfx/xnum_7",
"gfx/xnum_8",
"gfx/xnum_9"
};
string anumber[10] = {
"gfx/xanum_0",
"gfx/xanum_1",
"gfx/xanum_2",
"gfx/xanum_3",
"gfx/xanum_4",
"gfx/xanum_5",
"gfx/xanum_6",
"gfx/xanum_7",
"gfx/xanum_8",
"gfx/xanum_9"
};
string faceid[10] = {
"face5", "face4", "face3", "face2", "face1",
"face_p5", "face_p4", "face_p3", "face_p2", "face_p1"
};
string weaponprefix[12] = {
"gfx/",
"gfx/",
"gfx/",
"gfx/",
"gfx/",
"gfx/",
"gfx/",
"gfx/",
"gfx/",
"gfx/",
"gfx/",
"gfx/"
};
string weaponname[12] = {
"axe",//"axe.lmp",
"chainsaw",//"chainsaw.lmp",
"shotgun",
"sshotgun",
"nailgun",
"snailgun",
"rlaunch",
"plaunch",//"plaunch.lmp",
"srlaunch",
"alightng",
"laser",//"laser.lmp",
"plasma"//"plasma.lmp"
};
float weaponflags[12] = {
WEAPON_AXE,
WEAPON_CHAINSAW,
WEAPON_SHOTGUN,
WEAPON_SUPER_SHOTGUN,
WEAPON_NAILGUN,
WEAPON_SUPER_NAILGUN,
WEAPON_GRENADE_LAUNCHER,
WEAPON_PROXIMITY_GUN,
WEAPON_ROCKET_LAUNCHER,
WEAPON_LIGHTNING,
WEAPON_LASER_CANNON,
WEAPON_PLASMA
};
string weaponframes[7] = {
"inv_", "inv2_", "inva1_", "inva2_", "inva3_", "inva4_", "inva5_"
};
// Total actual weapon slots
float WPN_ICONS = 12;
// Record when weapons have been added (flash mechanic)
float weapontime[WPN_ICONS];
string(float num, float fr) getWeaponName = {
return strcat(weaponprefix[num], weaponframes[fr], weaponname[num]);
}
void(float num, vector pos) Hud_DrawWeapon = {
float flash, fr;
string name;
if (st_weapons & weaponflags[num]) {
flash = (time - weapontime[num])*10;
if (flash < 10) {
// Is the flash into second phase?
if (flash < 0) flash = 0;
else if (flash >= 5) flash = flash - 5;
// flash is only 0-4 frames
fr = flash + 2;
}
else {
if (st_activeweapon == weaponflags[num])
fr = 1;
else
fr = 0;
}
name = getWeaponName(num, fr);
drawpic(pos, name, '24 16 0', '1 1 1', 1, 0);
}
}
//----------------------------------------------------------------------
// Draws small 8 pixel numbers to HUD (white/yellow/red text options)
//----------------------------------------------------------------------
void(vector pos, float value, float digit, float zerofill, float fontcol) Hud_DrawNoFont8 =
{
local string val_str;
local float disp_len, disp_no;
// Make sure value is within range
if (value < 0) value = 0;
// Check max range against max digits
else if (value > 999 && digit >= 3) value = 999;
else if (value > 99 && digit == 2) value = 99;
else if (value > 9 && digit <= 1) value = 9;
// Round number down (floor) and work out length
val_str = ftos(floor(value));
disp_len = strlen(val_str);
// Zero fill number?
if (zerofill) {
while (disp_len < digit) {
// Keep adding more zero's
val_str = strcat("0", val_str);
// Exit condition?
disp_len = strlen(val_str);
}
}
// Move to the lowest digit position first
pos_x = pos_x + (digit * HUDSIZE_8_x);
while (disp_len > 0) {
// Countdown first (digit positions = 0-2)
disp_len = disp_len - 1;
// Move backward to display a digit
pos_x = pos_x - HUDSIZE_8_x;
// Convert character to number (font table index 48-57)
disp_no = str2chr(val_str, disp_len);
if (fontcol == HUDFONT_YELLOW) disp_no = disp_no - 30;
else if (fontcol == HUDFONT_RED) disp_no = disp_no + 128;
// Draw character from ascii font table (right-justified)
drawcharacter(pos, disp_no, HUDSIZE_8, HUDRGB_DEF, hudalpha, 0);
}
};
void(vector pos, float value, float threshhold) Hud_DrawLargeValue =
{
float c;
float len;
string s;
if (value < 0)
value = 0; //hrm
if (value>999)
value = 999;
//for (len = 0; len < 3; len++) {
// drawpic(pos+ len * '24 0 0', "gfx/numbk_non", '24 24 0', '1 1 1', 1, 0);
//}
s = ftos(floor(value));
len = strlen(s);
pos_x += 24 * (3-len);
if (value <= threshhold)
{ //use alternate (red) numbers
while(len>0)
{
len--;
c = str2chr(s, len);
drawpic(pos+len * '24 0 0', anumber[c-'0'], '24 24 0', '1 1 1', 1, 0);
}
}
else
{ //use normal numbers
while(len>0)
{
len--;
c = str2chr(s, len);
drawpic(pos+len * '24 0 0', number[c-'0'], '24 24 0', '1 1 1', 1, 0);
}
}
};
void(float type, vector pos, float drawback) Hud_DrawAmmoCount =
{
string s;
float value;
float len;
float c;
value = getstati(STAT_SHELLS+type);
if (value < 0)
value = 0; //hrm
if (value>999)
value = 999;
s = ftos(floor(value));
len = strlen(s);
pos_x += 8 * (3-len);
while(len>0)
{
len--;
c = str2chr(s, len);
drawcharacter(pos+len * '8 0 0', (18-'0') + c, '8 8 0', '1 1 1', 1, 0);
}
};
//----------------------------------------------------------------------
// Change HUD face to reflect Health, Pain or Powerups
//----------------------------------------------------------------------
void(vector pos) Hud_DrawFace =
{
string face;
local float hpframe;
if (st_items & IT_TRIFECTA){
// trifecta + belt
if (st_items & IT_INVISIBILITY)
face = "gfx/face_tri2";
// trifecta only
else
face = "gfx/face_tri";
}
// belt + pentagram + quad
else if (st_items & (IT_INVISIBILITY | IT_INVULNERABILITY | IT_QUAD) == (IT_INVISIBILITY | IT_INVULNERABILITY | IT_QUAD))
face = "gfx/face_allbuttri";
// belt + pentagram
else if (st_items & (IT_INVISIBILITY | IT_INVULNERABILITY) == (IT_INVISIBILITY | IT_INVULNERABILITY))
face = "gfx/face_inv2";
// belt + quad
else if (st_items & (IT_INVISIBILITY | IT_QUAD) == (IT_INVISIBILITY | IT_QUAD))
face = "gfx/face_invisquad";
// pentagram + quad
else if (st_items & (IT_INVULNERABILITY | IT_QUAD) == (IT_INVULNERABILITY | IT_QUAD))
face = "gfx/face_inv3";
// belt only
else if (st_items & IT_INVISIBILITY)
face = "gfx/face_invis";
// quad only
else if (st_items & IT_QUAD)
face = "gfx/face_quad";
// pentagram only
else if (st_items & IT_INVULNERABILITY){
face = "gfx/face_invul2";
}
// Regular face
else {
// Work out face based on HP (100/80/60/40/20)
hpframe = floor(getstatf(STAT_HEALTH) / 20);
// Check for negative and upper (MegaHP) limits
if (hpframe < 0) hpframe = 0;
else if (hpframe > 4) hpframe = 4;
// Check for any pain/flinch updates
if (painfinishtime > time) hpframe = hpframe + 5;
// Final HP face
face = faceid[hpframe];
}
// Draw face - always 24x24 size, full rgb/alpha
drawpic(pos, face, HUDSIZE_24, HUDRGB_DEF, hudalpha, 0);
};
string(float f, float chars, string lead) FormatFloat
{
string s = ftos(f);
if (f < 10 && chars >= 3)
s = strcat(lead, lead, s);
else if (f < 10 && chars == 2)
s = strcat(lead, s);
else if (f < 100 && chars >= 3)
s = strcat(lead, s);
return s;
};
void Hud_DrawSBar(vector pos)
{
if (st_items & IT_TRIFECTA) {
drawpic(pos + '16 0 0', "gfx/sb_aarmortri", '112 24 0', '1 1 1', 1, 0);
}
else if (st_items & IT_INVULNERABILITY) {
drawpic(pos + '16 0 0', "gfx/sb_aarmor666", '112 24 0', '1 1 1', 1, 0);
}
else {
if (st_items & IT_ARMOR3)
drawpic(pos+'16 0 0', "gfx/sb_aarmor3", '24 24 0', '1 1 1', 1, 0);
else if (st_items & IT_ARMOR2)
drawpic(pos+'16 0 0', "gfx/sb_aarmor2", '24 24 0', '1 1 1', 1, 0);
else if (st_items & IT_ARMOR1)
drawpic(pos+'16 0 0', "gfx/sb_aarmor1", '24 24 0', '1 1 1', 1, 0);
drawpic(pos+'40 0 0', "gfx/numbk_armorammo", '88 24 0', '1 1 1', 1, 0);
//drawpic(pos+'40 0 0', "gfx/numbk_l1", '8 24 0', '1 1 1', 1, 0);
Hud_DrawLargeValue(pos+'48 0 0', getstatf(STAT_ARMOR), 25);
//drawpic(pos+'120 0 0', "gfx/numbk_r1", '8 24 0', '1 1 1', 1, 0);
}
Hud_DrawFace(pos+'176 0 0');
drawpic(pos+'200 0 0', "gfx/numbk_health", '88 24 0', '1 1 1', 1, 0);
//drawpic(pos+'200 0 0', "gfx/numbk_l2", '8 24 0', '1 1 1', 1, 0);
Hud_DrawLargeValue(pos+'208 0 0', getstatf(STAT_HEALTH), 25);
//drawpic(pos+'280 0 0', "gfx/numbk_r2", '8 24 0', '1 1 1', 1, 0);
if (st_items & IT_SHELLS)
drawpic(pos+'336 0 0', "gfx/sb_ashells", '24 24 0', '1 1 1', 1, 0);
else if (st_items & IT_NAILS)
drawpic(pos+'336 0 0', "gfx/sb_anails", '24 24 0', '1 1 1', 1, 0);
else if (st_items & IT_ROCKETS)
drawpic(pos+'336 0 0', "gfx/sb_arocket", '24 24 0', '1 1 1', 1, 0);
else if (st_items & IT_CELLS)
drawpic(pos+'336 0 0', "gfx/sb_cells", '24 24 0', '1 1 1', 1, 0);
drawpic(pos+'360 0 0', "gfx/numbk_armorammo", '88 24 0', '1 1 1', 1, 0);
//drawpic(pos+'360 0 0', "gfx/numbk_l1", '8 24 0', '1 1 1', 1, 0);
Hud_DrawLargeValue(pos+'368 0 0', getstatf(STAT_AMMO), 10);
//drawpic(pos+'440 0 0', "gfx/numbk_r1", '8 24 0', '1 1 1', 1, 0);
};
void Hud_DrawIBar(vector pos)
{
float i;
vector offset;
for (i = 0; i < 12; i++) {
offset = [i * 24, 8, 0];
Hud_DrawWeapon(i, pos + offset);
}
Hud_DrawAmmoCount(0, pos + '10 0 0', FALSE);
Hud_DrawAmmoCount(1, pos + '58 0 0', FALSE);
Hud_DrawAmmoCount(2, pos + '106 0 0', FALSE);
Hud_DrawAmmoCount(3, pos + '154 0 0', FALSE);
if (st_items & IT_KEY1)
drawpic(pos+'288 8 0', "gfx/sb_key1", '16 16 0', '1 1 1', 1, 0);
if (st_items & IT_KEY2)
drawpic(pos+'304 8 0', "gfx/sb_key2", '16 16 0', '1 1 1', 1, 0);
if (st_items & IT_INVISIBILITY)
drawpic(pos+'320 8 0', "gfx/sb_invis", '16 16 0', '1 1 1', 1, 0);
if (st_items & IT_INVULNERABILITY)
drawpic(pos+'336 8 0', "gfx/sb_invuln", '16 16 0', '1 1 1', 1, 0);
if (st_items & IT_SUIT)
drawpic(pos+'352 8 0', "gfx/sb_suit", '16 16 0', '1 1 1', 1, 0);
if (st_items & IT_QUAD)
drawpic(pos+'368 8 0', "gfx/sb_quad", '16 16 0', '1 1 1', 1, 0);
if (st_items & IT_TRIFECTA)
drawpic(pos+'384 8 0', "gfx/sb_trifecta", '16 16 0', '1 1 1', 1, 0);
if (st_boots)
drawpic(pos+'400 8 0', "gfx/sb_boots", '16 16 0', '1 1 1', 1, 0);
if (st_items2 & 32)
drawpic(pos+'416 8 0', "gfx/sb_sigil1", '8 16 0', '1 1 1', 1, 0);
if (st_items2 & 64)
drawpic(pos+'424 8 0', "gfx/sb_sigil2", '8 16 0', '1 1 1', 1, 0);
if (st_items2 & 128)
drawpic(pos+'432 8 0', "gfx/sb_sigil3", '8 16 0', '1 1 1', 1, 0);
if (st_items2 & 256)
drawpic(pos+'440 8 0', "gfx/sb_sigil4", '8 16 0', '1 1 1', 1, 0);
};
void(vector pos, float bx, float by, float bwidth, float bheight, float pixelspeed, string draw_str) Hud_ScrollTextBox =
{
local float str_width, str_double, str_speed;
local string wide_str;
// draw debug visual box to show area on screen
//drawfill( pos+[bx,by], [bwidth,bheight], HUDRGB_DEF, 0.1, 0);
// Find out width of string in pixels (using font 8)
str_width = stringwidth( draw_str, TRUE, HUDSIZE_8);
// String less than window width?
if (str_width < bwidth) {
// Center the map name string in the box area
str_double = (bwidth - str_width) / 2;
// Display string normally (no scrolling required)
drawstring( pos+[bx+str_double, by], draw_str, HUDSIZE_8, HUDRGB_DEF, hudalpha, 0);
}
else {
// Create double length string with boundary marker
wide_str = strcat(draw_str, " /// ", draw_str);
// Setup clip (scissor) area for exclusive drawing
drawsetcliparea( pos_x + bx, pos_y + by, bwidth, bheight);
str_double = stringwidth( wide_str, TRUE, HUDSIZE_8);
// create offset of string to make it look like its scrolling
str_speed = mod(cltime * pixelspeed, (str_double - str_width));
// draw string (with offset) inside of clip (scissor) area only
drawstring( pos+[bx - str_speed, by], wide_str, HUDSIZE_8, HUDRGB_DEF, hudalpha, 0);
// Reset clip string area to default
drawresetcliparea();
}
};
void(vector pos) Hud_DrawScoreBar_QSClock = {
local string skill_str, map_str;
local float digit, skill_no;
local float nsecs, nmins;
// Clear status bar ready for map info/scores
drawpic(pos, "gfx/alk_scorebar", [464, 24], '1 1 1', baralpha, 0);
// Level designers Map name + Skill level name
map_str = strcat(world.message, " (", mapname, ")");
Hud_ScrollTextBox(pos, 8, 4, 448, 8, 16, map_str);
// Kills
drawstring(pos+[8,12], "Kills:", HUDSIZE_8, HUDRGB_DEF, hudalpha, 0);
Hud_DrawNoFont8(pos+[56,12], getstatf(STAT_KILLEDMONSTERS), 3, FALSE, HUDFONT_WHITE);
drawstring(pos+[80,12], "/", HUDSIZE_8, HUDRGB_DEF, hudalpha, 0);
if (getstatf(STAT_TOTALMONSTERS) < 100) digit = 2;
else digit = 3;
Hud_DrawNoFont8(pos+[88,12], getstatf(STAT_TOTALMONSTERS), digit, FALSE, HUDFONT_WHITE);
// Work out time passed
//drawstring(pos+[112,12], "Time", HUDSIZE_8, HUDRGB_DEF, hudalpha, 0);
nmins = floor(time/60);
nsecs = floor(time - nmins*60);
Hud_DrawNoFont8(pos+[124,12], nmins, 3, FALSE, HUDFONT_WHITE);
drawstring(pos+[148,12], ":", HUDSIZE_8, HUDRGB_DEF, hudalpha, 0);
Hud_DrawNoFont8(pos+[160,12], nsecs, 2, TRUE, HUDFONT_WHITE);
// Secret totals
drawstring(pos+[200,12], "Secrets:", HUDSIZE_8, HUDRGB_DEF, hudalpha, 0);
Hud_DrawNoFont8(pos+[264,12], getstatf(STAT_FOUNDSECRETS), 2, FALSE, HUDFONT_WHITE);
drawstring(pos+[280,12], "/", HUDSIZE_8, HUDRGB_DEF, hudalpha, 0);
Hud_DrawNoFont8(pos+[288,12], getstatf(STAT_TOTALSECRETS), 2, FALSE, HUDFONT_WHITE);
// Map skill level
//skill_no = stof(autocvar(skill, "1"));
skill_no = cvar("skill");
if (skill_no == 0) skill_str = "Easy";
else if (skill_no == 1) skill_str = "Normal";
else if (skill_no == 2) skill_str = "Hard";
else if (skill_no == 3) skill_str = "Nightmare";
else skill_str = "Unknown";
drawstring(pos+[332, 12], strcat(skill_str, " skill"), HUDSIZE_8, HUDRGB_DEF, hudalpha, 0);
};
nonstatic void Hud_Draw(float hudtype, float scoreboard, float width, float height) {
vector pos;
float hudviewsize;
float i;
screensize_x = width;
screensize_y = height;
screensize_z = 0;
prevweapons = st_weapons;
pos_x = (screensize_x-464)/2;
pos_y = screensize_y;
//st_items = getstatbits(STAT_ITEMS, 0, 23);
st_items = getstatf(STAT_IT);
st_items2 = getstatbits(STAT_ITEMS, 23, 9);
st_weapons = getstatf(STAT_WEAPONS);
st_activeweapon = getstatf(STAT_ACTIVEWEAPON);
st_boots = getstatf(STAT_BOOTS);
st_boots_finished = getstatf(STAT_BOOTS_FINISHED);
hudviewsize = cvar("viewsize");
baralpha = cvar("scr_sbaralpha");
if (baralpha == 0) baralpha = 0.333;
// Default is 1 for everything else
hudalpha = 1;
for (i = 0; i < WPN_ICONS; i++) {
if ((st_weapons & weaponflags[i]) && !(prevweapons & weaponflags[i]))
weapontime[i] = time;
}
//if hudtype == 0 then the engine already drew it.
if (scoreboard) {
//Hud_CoopScores_SBar(pos - '0 24 0');
Hud_DrawScoreBar_QSClock(pos - '0 24 ');
}
if (hudviewsize < 110) {
drawpic(pos - '0 48 0', "gfx/alk_ibar", '464 24 0', '1 1 1', baralpha, 0);
Hud_DrawIBar(pos - '-8 48 0');
if (!scoreboard) {
drawpic(pos - '0 24 0', "gfx/alk_sbar", '464 24 0', '1 1 1', baralpha, 0);
Hud_DrawSBar(pos - '0 24 0');
}
}
else if (hudviewsize == 110 && !scoreboard) {
drawpic(pos - '0 24 0', "gfx/alk_sbar_solo", '464 24 0', '1 1 1', baralpha, 0);
Hud_DrawSBar(pos - '0 24 0');
}
};