]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/hud/crosshair.qc
Small cleanup
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud / crosshair.qc
1 #include "crosshair.qh"
2
3 #include <client/draw.qh>
4 #include <client/hud/panel/scoreboard.qh>
5 #include <client/view.qh>
6 #include <common/deathtypes/all.qh>
7 #include <common/ent_cs.qh>
8 #include <common/mapobjects/trigger/viewloc.qh>
9 #include <common/minigames/cl_minigames.qh>
10 #include <common/minigames/cl_minigames_hud.qh>
11 #include <common/mutators/mutator/overkill/oknex.qh>
12 #include <common/vehicles/all.qh>
13 #include <common/viewloc.qh>
14 #include <common/wepent.qh>
15 #include <lib/csqcmodel/cl_player.qh>
16 #include <lib/warpzone/common.qh>
17
18 float pickup_crosshair_time, pickup_crosshair_size;
19 float hitindication_crosshair_size;
20 float use_vortex_chargepool;
21
22 float reticle_type;
23
24 vector wcross_origin;
25 float wcross_scale_prev, wcross_alpha_prev;
26 vector wcross_color_prev;
27 float wcross_scale_goal_prev, wcross_alpha_goal_prev;
28 vector wcross_color_goal_prev;
29 float wcross_changedonetime;
30
31 string wcross_name_goal_prev, wcross_name_goal_prev_prev;
32 float wcross_resolution_goal_prev, wcross_resolution_goal_prev_prev;
33 float wcross_name_changestarttime, wcross_name_changedonetime;
34 float wcross_name_alpha_goal_prev, wcross_name_alpha_goal_prev_prev;
35
36 float wcross_ring_prev;
37
38 entity trueaim;
39 entity trueaim_rifle;
40
41 const float SHOTTYPE_HITTEAM = 1;
42 const float SHOTTYPE_HITOBSTRUCTION = 2;
43 const float SHOTTYPE_HITWORLD = 3;
44 const float SHOTTYPE_HITENEMY = 4;
45
46 void TrueAim_Init()
47 {
48         (trueaim = new_pure(trueaim)).dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_CORPSE;
49         (trueaim_rifle = new_pure(trueaim_rifle)).dphitcontentsmask = DPCONTENTS_BODY | DPCONTENTS_CORPSE;
50 }
51
52 float EnemyHitCheck()
53 {
54         float t, n;
55         wcross_origin = project_3d_to_2d(trace_endpos);
56         wcross_origin.z = 0;
57         if(trace_ent)
58                 n = trace_ent.entnum;
59         else
60                 n = trace_networkentity;
61         if(n < 1)
62                 return SHOTTYPE_HITWORLD;
63         if(n > maxclients)
64                 return SHOTTYPE_HITWORLD;
65         t = entcs_GetTeam(n - 1);
66         if(teamplay && t == myteam)
67                 return SHOTTYPE_HITTEAM;
68         if(t == NUM_SPECTATOR)
69                 return SHOTTYPE_HITWORLD;
70         return SHOTTYPE_HITENEMY;
71 }
72
73 float TrueAimCheck(entity wepent)
74 {
75         if(wepent.activeweapon.spawnflags & WEP_FLAG_NOTRUEAIM)
76                 return SHOTTYPE_HITWORLD;
77
78         float nudge = 1; // added to traceline target and subtracted from result TOOD(divVerent): do we still need this? Doesn't the engine do this now for us?
79         vector vecs, trueaimpoint, w_shotorg;
80         vector mi, ma, dv;
81         float shottype;
82         entity ta;
83         float mv;
84
85         mi = ma = '0 0 0';
86         ta = trueaim;
87         mv = MOVE_NOMONSTERS;
88
89         switch(wepent.activeweapon) // WEAPONTODO
90         {
91                 case WEP_VORTEX:
92                 case WEP_OVERKILL_NEX:
93                 case WEP_VAPORIZER:
94                         mv = MOVE_NORMAL;
95                         break;
96                 case WEP_RIFLE:
97                         ta = trueaim_rifle;
98                         mv = MOVE_NORMAL;
99                         if(zoomscript_caught)
100                         {
101                                 tracebox(view_origin, '0 0 0', '0 0 0', view_origin + view_forward * max_shot_distance, mv, ta);
102                                 return EnemyHitCheck();
103                         }
104                         break;
105                 case WEP_DEVASTATOR: // projectile has a size!
106                         mi = '-3 -3 -3';
107                         ma = '3 3 3';
108                         break;
109                 case WEP_FIREBALL: // projectile has a size!
110                         mi = '-16 -16 -16';
111                         ma = '16 16 16';
112                         break;
113                 case WEP_SEEKER: // projectile has a size!
114                         mi = '-2 -2 -2';
115                         ma = '2 2 2';
116                         break;
117                 case WEP_ELECTRO: // projectile has a size!
118                         mi = '0 0 -3';
119                         ma = '0 0 -3';
120                         break;
121         }
122
123         vector traceorigin = entcs_receiver(player_localentnum - 1).origin + (eZ * STAT(VIEWHEIGHT));
124
125         vecs = decompressShotOrigin(STAT(SHOTORG));
126
127         traceline(traceorigin, traceorigin + view_forward * max_shot_distance, mv, ta);
128         trueaimpoint = trace_endpos;
129         // move trueaimpoint a little bit forward to make the final tracebox reliable
130         // since it sometimes doesn't reach a teammate by a hair
131         trueaimpoint += view_forward;
132
133         if(vdist((trueaimpoint - traceorigin), <, g_trueaim_minrange))
134                 trueaimpoint = traceorigin + view_forward * g_trueaim_minrange;
135
136         if(vecs.x > 0)
137                 vecs.y = -vecs.y;
138         else
139                 vecs = '0 0 0';
140
141         dv = view_right * vecs.y + view_up * vecs.z;
142         w_shotorg = traceorigin + dv;
143
144         // now move the vecs forward as much as requested if possible
145         tracebox(w_shotorg, mi, ma, w_shotorg + view_forward * (vecs.x + nudge), MOVE_NORMAL, ta); // FIXME this MOVE_NORMAL part will misbehave a little in csqc
146         w_shotorg = trace_endpos - view_forward * nudge;
147
148         tracebox(w_shotorg, mi, ma, trueaimpoint, MOVE_NORMAL, ta);
149         shottype = EnemyHitCheck();
150         if(shottype != SHOTTYPE_HITWORLD)
151                 return shottype;
152
153 #if 0
154         // FIXME WHY DOES THIS NOT WORK FOR THE ROCKET LAUNCHER?
155         // or rather, I know why, but see no fix
156         if(vlen(trace_endpos - trueaimpoint) > vlen(ma) + vlen(mi) + 1)
157                 // yes, this is an ugly hack... but it seems good enough to find out whether the test hits the same place as the initial trace
158                 return SHOTTYPE_HITOBSTRUCTION;
159 #endif
160
161         return SHOTTYPE_HITWORLD;
162 }
163
164 void HUD_Crosshair_Vehicle(entity this)
165 {
166         if(hud != HUD_BUMBLEBEE_GUN)
167         {
168                 Vehicle info = REGISTRY_GET(Vehicles, hud);
169                 info.vr_crosshair(info, this);
170         }
171 }
172
173 vector crosshair_getcolor(entity this, float health_stat)
174 {
175         static float rainbow_last_flicker;
176         static vector rainbow_prev_color;
177         vector wcross_color = '0 0 0';
178         switch(autocvar_crosshair_color_special)
179         {
180                 case 1: // weapon color
181                 {
182                         if(this != WEP_Null && hud == HUD_NORMAL)
183                         {
184                                 wcross_color = this.wpcolor;
185                                 break;
186                         }
187                         else { goto normalcolor; }
188                 }
189
190                 case 2: // color based on health and armor
191                 {
192                         vector v = healtharmor_maxdamage(health_stat, STAT(ARMOR), armorblockpercent, DEATH_WEAPON.m_id);
193                         float health_and_armor = floor(v.x + 1);
194                         wcross_color = HUD_Get_Num_Color(health_and_armor, 200, false);
195                         break;
196                 }
197
198                 case 3: // rainbow/random color
199                 {
200                         if(time >= rainbow_last_flicker)
201                         {
202                                 rainbow_prev_color = randomvec() * autocvar_crosshair_color_special_rainbow_brightness;
203                                 rainbow_last_flicker = time + autocvar_crosshair_color_special_rainbow_delay;
204                         }
205                         wcross_color = rainbow_prev_color;
206                         break;
207                 }
208 LABEL(normalcolor)
209                 default: { wcross_color = stov(autocvar_crosshair_color); break; }
210         }
211
212         return wcross_color;
213 }
214
215 .entity tag_entity;
216 void HUD_Crosshair_ApplyPlayerAlpha(float new_alpha)
217 {
218         csqcplayer.alpha = new_alpha;
219         FOREACH_ENTITY_CLASS("ENT_CLIENT_MODEL", it.tag_entity == csqcplayer,
220         {
221                 it.alpha = new_alpha;
222         });
223 }
224
225 void HUD_Crosshair(entity this)
226 {
227         // reset player's alpha here upon death since forced scoreboard prevents running the crosshair_chase code
228         if(autocvar_chase_active > 0 && autocvar_crosshair_chase && STAT(HEALTH) <= 0 && csqcplayer)
229                 csqcplayer.alpha = csqcplayer.m_alpha;
230
231         if (autocvar_chase_active > 0 && (autocvar_chase_front || autocvar_cl_lockview))
232         {
233                 if (csqcplayer.alpha != csqcplayer.m_alpha)
234                         HUD_Crosshair_ApplyPlayerAlpha(csqcplayer.m_alpha);
235                 return;
236         }
237
238         float f, i, j;
239         vector v;
240         if(!scoreboard_active && !camera_active && intermission != 2 && !STAT(GAME_STOPPED) && !autocvar_cl_lockview
241                 && spectatee_status != -1 && (!csqcplayer.viewloc || (!spectatee_status && (csqcplayer.viewloc.spawnflags & VIEWLOC_FREEAIM))) && !MUTATOR_CALLHOOK(DrawCrosshair)
242                 && !HUD_MinigameMenu_IsOpened())
243         {
244                 if (!autocvar_crosshair_enabled) // main toggle for crosshair rendering
245                         return;
246
247                 if (spectatee_status > 0 && STAT(CAMERA_SPECTATOR) == 2)
248                         return;
249
250                 if (hud != HUD_NORMAL)
251                 {
252                         HUD_Crosshair_Vehicle(this);
253                         return;
254                 }
255
256                 string wcross_style;
257                 float wcross_alpha, wcross_resolution;
258                 wcross_style = autocvar_crosshair;
259                 if (csqcplayer.viewloc && (csqcplayer.viewloc.spawnflags & VIEWLOC_FREEAIM) && autocvar_crosshair_2d != "")
260                         wcross_style = autocvar_crosshair_2d;
261                 if (wcross_style == "0")
262                         return;
263                 wcross_resolution = autocvar_crosshair_size;
264                 if (wcross_resolution == 0)
265                         return;
266                 wcross_alpha = autocvar_crosshair_alpha;
267                 if (wcross_alpha == 0)
268                         return;
269
270                 // TrueAim check
271                 float shottype;
272
273                 static int crosshair_chase_state = 0;
274
275                 // wcross_origin = '0.5 0 0' * vid_conwidth + '0 0.5 0' * vid_conheight;
276                 if(csqcplayer.viewloc && (csqcplayer.viewloc.spawnflags & VIEWLOC_FREEAIM))
277                         wcross_origin = viewloc_mousepos;
278                 else if(autocvar_chase_active > 0 && autocvar_crosshair_chase)
279                 {
280                         vector player_org = ((csqcplayer) ? csqcplayer.origin + csqcplayer.view_ofs : view_origin);
281                         float my_alpha = (!csqcplayer.m_alpha) ? 1 : csqcplayer.m_alpha;
282                         float chase_playeralpha = bound(0.001, autocvar_crosshair_chase_playeralpha, 1);
283                         if(csqcplayer && chase_playeralpha < 1 && my_alpha > chase_playeralpha)
284                         {
285                                 crosshair_chase_state = 2;
286                                 bool hit = false;
287                                 if (pointinsidebox(view_origin, csqcplayer.absmin, csqcplayer.absmax))
288                                         hit = true;
289                                 else
290                                 {
291                                         WarpZone_TraceLine(view_origin, view_origin + max_shot_distance * view_forward, MOVE_NORMAL, NULL);
292                                         if(trace_ent == csqcplayer)
293                                                 hit = true;
294                                 }
295                                 float prev_alpha = csqcplayer.alpha;
296                                 float new_alpha;
297                                 if(hit)
298                                         new_alpha = max(csqcplayer.alpha - frametime * 5, chase_playeralpha);
299                                 else
300                                         new_alpha = min(csqcplayer.alpha + frametime * 5, my_alpha);
301
302                                 if (new_alpha != prev_alpha)
303                                         HUD_Crosshair_ApplyPlayerAlpha(new_alpha);
304                         }
305                         traceline(player_org, player_org + max_shot_distance * view_forward, MOVE_WORLDONLY, NULL);
306                         wcross_origin = project_3d_to_2d(trace_endpos);
307                 }
308                 else
309                         wcross_origin = project_3d_to_2d(view_origin + max_shot_distance * view_forward);
310                 wcross_origin.z = 0;
311                 if (crosshair_chase_state == 2) // enabled (this frame)
312                         crosshair_chase_state = 1;
313                 else if (crosshair_chase_state == 1) // turned off in the previous frame
314                 {
315                         // reset player alpha only in this frame
316                         if (csqcplayer)
317                                 HUD_Crosshair_ApplyPlayerAlpha(csqcplayer.m_alpha);
318                         crosshair_chase_state = 0; // turned off and alpha reset
319                 }
320
321                 if(autocvar_crosshair_hittest)
322                 {
323                         vector wcross_oldorigin;
324                         entity thiswep = viewmodels[0]; // TODO: unhardcode
325                         wcross_oldorigin = wcross_origin;
326                         shottype = TrueAimCheck(thiswep);
327                         if(shottype == SHOTTYPE_HITWORLD)
328                         {
329                                 v = wcross_origin - wcross_oldorigin;
330                                 v.x /= vid_conwidth;
331                                 v.y /= vid_conheight;
332                                 if(vdist(v, >, 0.01))
333                                         shottype = SHOTTYPE_HITOBSTRUCTION;
334                         }
335                         if(!autocvar_crosshair_hittest_showimpact)
336                                 wcross_origin = wcross_oldorigin;
337                 }
338                 else
339                         shottype = SHOTTYPE_HITWORLD;
340
341                 vector wcross_color = '0 0 0', wcross_size = '0 0 0';
342                 string wcross_name = "";
343                 float wcross_scale, wcross_blur;
344
345                 entity e = WEP_Null;
346                 if(autocvar_crosshair_per_weapon || (autocvar_crosshair_color_special == 1))
347                 {
348                         entity wepent = viewmodels[0]; // TODO: unhardcode
349                         e = wepent.switchingweapon;
350                         if(e)
351                         {
352                                 if(autocvar_crosshair_per_weapon)
353                                 {
354                                         // WEAPONTODO: access these through some general settings (with non-balance config settings)
355                                         //wcross_resolution *= cvar(strcat("crosshair_", wcross_wep, "_size"));
356                                         //if (wcross_resolution == 0)
357                                                 //return;
358
359                                         //wcross_style = cvar_string(strcat("crosshair_", wcross_wep));
360                                         wcross_resolution *= e.w_crosshair_size;
361                                         wcross_name = e.w_crosshair;
362                                 }
363                         }
364                 }
365
366                 if(wcross_name == "")
367                         wcross_name = strcat("gfx/crosshair", wcross_style);
368
369                 // MAIN CROSSHAIR COLOR DECISION
370                 wcross_color = crosshair_getcolor(e, STAT(HEALTH));
371
372                 if(autocvar_crosshair_effect_scalefade)
373                 {
374                         wcross_scale = wcross_resolution;
375                         wcross_resolution = 1;
376                 }
377                 else
378                 {
379                         wcross_scale = 1;
380                 }
381
382                 if(autocvar_crosshair_pickup)
383                 {
384                         float stat_pickup_time = STAT(LAST_PICKUP);
385
386                         if(pickup_crosshair_time < stat_pickup_time)
387                         {
388                                 if(time - stat_pickup_time < 5) // don't trigger the animation if it's too old
389                                         pickup_crosshair_size = 1;
390
391                                 pickup_crosshair_time = stat_pickup_time;
392                         }
393
394                         if(pickup_crosshair_size > 0)
395                                 pickup_crosshair_size -= autocvar_crosshair_pickup_speed * frametime;
396                         else
397                                 pickup_crosshair_size = 0;
398
399                         wcross_scale += sin(pickup_crosshair_size) * autocvar_crosshair_pickup;
400                 }
401
402                 // todo: make crosshair hit indication dependent on damage dealt
403                 if(autocvar_crosshair_hitindication)
404                 {
405                         vector col = ((autocvar_crosshair_color_special == 1) ? stov(autocvar_crosshair_hitindication_per_weapon_color) : stov(autocvar_crosshair_hitindication_color));
406
407                         if(unaccounted_damage)
408                         {
409                                 hitindication_crosshair_size = 1;
410                         }
411
412                         if(hitindication_crosshair_size > 0)
413                                 hitindication_crosshair_size -= autocvar_crosshair_hitindication_speed * frametime;
414                         else
415                                 hitindication_crosshair_size = 0;
416
417                         wcross_scale += sin(hitindication_crosshair_size) * autocvar_crosshair_hitindication;
418                         wcross_color.x += sin(hitindication_crosshair_size) * col.x;
419                         wcross_color.y += sin(hitindication_crosshair_size) * col.y;
420                         wcross_color.z += sin(hitindication_crosshair_size) * col.z;
421                 }
422
423                 // no effects needed for targeting enemies, this can't possibly span all valid targets!
424                 // just show for teammates to give a sign that they're an invalid target
425                 //if(shottype == SHOTTYPE_HITENEMY)
426                         //wcross_scale *= autocvar_crosshair_hittest; // is not queried if hittest is 0
427                 if(shottype == SHOTTYPE_HITTEAM)
428                         wcross_scale /= autocvar_crosshair_hittest; // is not queried if hittest is 0
429
430                 f = fabs(autocvar_crosshair_effect_time);
431                 if(wcross_scale != wcross_scale_goal_prev || wcross_alpha != wcross_alpha_goal_prev || wcross_color != wcross_color_goal_prev)
432                 {
433                         wcross_changedonetime = time + f;
434                 }
435                 if(wcross_name != wcross_name_goal_prev || wcross_resolution != wcross_resolution_goal_prev)
436                 {
437                         wcross_name_changestarttime = time;
438                         wcross_name_changedonetime = time + f;
439                         if(wcross_name_goal_prev_prev)
440                                 strunzone(wcross_name_goal_prev_prev);
441                         wcross_name_goal_prev_prev = wcross_name_goal_prev;
442                         wcross_name_goal_prev = strzone(wcross_name);
443                         wcross_name_alpha_goal_prev_prev = wcross_name_alpha_goal_prev;
444                         wcross_resolution_goal_prev_prev = wcross_resolution_goal_prev;
445                         wcross_resolution_goal_prev = wcross_resolution;
446                 }
447
448                 wcross_scale_goal_prev = wcross_scale;
449                 wcross_alpha_goal_prev = wcross_alpha;
450                 wcross_color_goal_prev = wcross_color;
451
452                 if((shottype == SHOTTYPE_HITTEAM && autocvar_crosshair_hittest_blur_teammate)
453                         || (shottype == SHOTTYPE_HITOBSTRUCTION && autocvar_crosshair_hittest_blur_wall && !autocvar_chase_active))
454                 {
455                         wcross_blur = 1;
456                         wcross_alpha *= 0.75;
457                 }
458                 else
459                         wcross_blur = 0;
460                 // *_prev is at time-frametime
461                 // * is at wcross_changedonetime+f
462                 // what do we have at time?
463                 if(time < wcross_changedonetime)
464                 {
465                         f = frametime / (wcross_changedonetime - time + frametime);
466                         wcross_scale = f * wcross_scale + (1 - f) * wcross_scale_prev;
467                         wcross_alpha = f * wcross_alpha + (1 - f) * wcross_alpha_prev;
468                         wcross_color = f * wcross_color + (1 - f) * wcross_color_prev;
469                 }
470
471                 wcross_scale_prev = wcross_scale;
472                 wcross_alpha_prev = wcross_alpha;
473                 wcross_color_prev = wcross_color;
474
475                 MUTATOR_CALLHOOK(UpdateCrosshair);
476
477                 wcross_scale *= 1 - autocvar__menu_alpha;
478                 wcross_alpha *= 1 - autocvar__menu_alpha;
479                 wcross_size = draw_getimagesize(wcross_name) * wcross_scale;
480
481                 if(wcross_scale >= 0.001 && wcross_alpha >= 0.001)
482                 {
483                         // crosshair rings for weapon stats
484                         if (autocvar_crosshair_ring || autocvar_crosshair_ring_reload)
485                         {
486                                 // declarations and stats
487                                 float ring_value = 0, ring_scale = 0, ring_alpha = 0, ring_inner_value = 0, ring_inner_alpha = 0;
488                                 string ring_image = string_null, ring_inner_image = string_null;
489                                 vector ring_rgb = '0 0 0', ring_inner_rgb = '0 0 0';
490
491                                 ring_scale = autocvar_crosshair_ring_size;
492
493                                 entity wepent = viewmodels[0]; // TODO: unhardcode
494
495                                 int weapon_clipload = wepent.clip_load;
496                                 int weapon_clipsize = wepent.clip_size;
497
498                                 float arc_heat = wepent.arc_heat_percent;
499
500                                 if(vortex_charge_movingavg == 0) // this should only happen if we have just loaded up the game
501                                         vortex_charge_movingavg = wepent.vortex_charge;
502
503                                 float charge = 0;
504                                 float chargepool = 0;
505                                 bool ring_vortex_enabled = false;
506                                 if (autocvar_crosshair_ring && autocvar_crosshair_ring_vortex)
507                                 {
508                                         if (wepent.activeweapon == WEP_VORTEX)
509                                         {
510                                                 charge = wepent.vortex_charge;
511                                                 chargepool = wepent.vortex_chargepool_ammo;
512                                         }
513                                         else if (wepent.activeweapon == WEP_OVERKILL_NEX)
514                                         {
515                                                 charge = wepent.oknex_charge;
516                                                 chargepool = wepent.oknex_chargepool_ammo;
517                                         }
518                                         if (charge)
519                                                 ring_vortex_enabled = true;
520                                 }
521
522                                 if (ring_vortex_enabled)
523                                 {
524                                         if (chargepool || use_vortex_chargepool) {
525                                                 use_vortex_chargepool = 1;
526                                                 ring_inner_value = chargepool;
527                                         } else {
528                                                 float rate = autocvar_crosshair_ring_vortex_currentcharge_movingavg_rate;
529                                                 vortex_charge_movingavg = (1 - rate) * vortex_charge_movingavg + rate * charge;
530                                                 ring_inner_value = bound(0, autocvar_crosshair_ring_vortex_currentcharge_scale * (charge - vortex_charge_movingavg), 1);
531                                         }
532
533                                         ring_inner_alpha = autocvar_crosshair_ring_vortex_inner_alpha;
534                                         ring_inner_rgb = vec3(autocvar_crosshair_ring_vortex_inner_color_red, autocvar_crosshair_ring_vortex_inner_color_green, autocvar_crosshair_ring_vortex_inner_color_blue);
535                                         ring_inner_image = "gfx/crosshair_ring_inner";
536
537                                         // draw the outer ring to show the current charge of the weapon
538                                         ring_value = charge;
539                                         ring_alpha = autocvar_crosshair_ring_vortex_alpha;
540                                         ring_rgb = wcross_color;
541                                         ring_image = "gfx/crosshair_ring_nexgun";
542                                 }
543                                 else if (autocvar_crosshair_ring && wepent.activeweapon == WEP_MINE_LAYER && WEP_CVAR(minelayer, limit) && autocvar_crosshair_ring_minelayer)
544                                 {
545                                         ring_value = bound(0, wepent.minelayer_mines / WEP_CVAR(minelayer, limit), 1);
546                                         ring_alpha = autocvar_crosshair_ring_minelayer_alpha;
547                                         ring_rgb = wcross_color;
548                                         ring_image = "gfx/crosshair_ring";
549                                 }
550                                 else if (wepent.activeweapon == WEP_HAGAR && wepent.hagar_load && autocvar_crosshair_ring_hagar)
551                                 {
552                                         ring_value = bound(0, wepent.hagar_load / WEP_CVAR_SEC(hagar, load_max), 1);
553                                         ring_alpha = autocvar_crosshair_ring_hagar_alpha;
554                                         ring_rgb = wcross_color;
555                                         ring_image = "gfx/crosshair_ring";
556                                 }
557                                 else if(autocvar_crosshair_ring_reload && weapon_clipsize) // forces there to be only an ammo ring
558                                 {
559                                         ring_value = bound(0, weapon_clipload / weapon_clipsize, 1);
560                                         ring_scale = autocvar_crosshair_ring_reload_size;
561                                         ring_alpha = autocvar_crosshair_ring_reload_alpha;
562                                         ring_rgb = wcross_color;
563
564                                         // Note: This is to stop Taoki from complaining that the image doesn't match all potential balances.
565                                         // if a new image for another weapon is added, add the code (and its respective file/value) here
566                                         if ((wepent.activeweapon == WEP_RIFLE) && (weapon_clipsize == 80))
567                                                 ring_image = "gfx/crosshair_ring_rifle";
568                                         else
569                                                 ring_image = "gfx/crosshair_ring";
570                                 }
571                                 else if ( autocvar_crosshair_ring && autocvar_crosshair_ring_arc && arc_heat && wepent.activeweapon == WEP_ARC )
572                                 {
573                                         ring_value = arc_heat;
574                                         ring_alpha = (1-arc_heat)*autocvar_crosshair_ring_arc_cold_alpha +
575                                                 arc_heat*autocvar_crosshair_ring_arc_hot_alpha;
576                                         ring_rgb = (1-arc_heat)*wcross_color + arc_heat*autocvar_crosshair_ring_arc_hot_color;
577                                         ring_image = "gfx/crosshair_ring";
578                                 }
579
580                                 // if in weapon switch animation, fade ring out/in
581                                 if(autocvar_crosshair_effect_time > 0)
582                                 {
583                                         f = (time - wcross_name_changestarttime) / autocvar_crosshair_effect_time;
584                                         if (f >= 1)
585                                         {
586                                                 wcross_ring_prev = ((ring_image) ? true : false);
587                                         }
588
589                                         if(wcross_ring_prev)
590                                         {
591                                                 if(f < 1)
592                                                         ring_alpha *= fabs(1 - bound(0, f, 1));
593                                         }
594                                         else
595                                         {
596                                                 if(f < 1)
597                                                         ring_alpha *= bound(0, f, 1);
598                                         }
599                                 }
600
601                                 if (autocvar_crosshair_ring_inner && ring_inner_value) // lets draw a ring inside a ring so you can ring while you ring
602                                         DrawCircleClippedPic(wcross_origin, wcross_size.x * wcross_resolution * ring_scale, ring_inner_image, ring_inner_value, ring_inner_rgb, wcross_alpha * ring_inner_alpha, DRAWFLAG_ADDITIVE);
603
604                                 if (ring_value)
605                                         DrawCircleClippedPic(wcross_origin, wcross_size.x * wcross_resolution * ring_scale, ring_image, ring_value, ring_rgb, wcross_alpha * ring_alpha, DRAWFLAG_ADDITIVE);
606                         }
607
608 #define CROSSHAIR_DO_BLUR(M,sz,wcross_name,wcross_alpha) \
609                         MACRO_BEGIN \
610                                 vector scaled_sz = sz * wcross_size; \
611                                 if(wcross_blur > 0) \
612                                 { \
613                                         for(i = -2; i <= 2; ++i) \
614                                         for(j = -2; j <= 2; ++j) \
615                                         M(i,j,sz,scaled_sz,wcross_name,wcross_alpha*0.04); \
616                                 } \
617                                 else \
618                                 { \
619                                         M(0,0,sz,scaled_sz,wcross_name,wcross_alpha); \
620                                 } \
621                         MACRO_END
622
623 #define CROSSHAIR_DRAW_SINGLE(i,j,sz,scaled_sz,wcross_name,wcross_alpha) \
624                         drawpic(wcross_origin - ('0.5 0 0' * (scaled_sz.x + i * wcross_blur) + '0 0.5 0' * (scaled_sz.y + j * wcross_blur)), wcross_name, scaled_sz, wcross_color, wcross_alpha, DRAWFLAG_NORMAL)
625
626 #define CROSSHAIR_DRAW(sz,wcross_name,wcross_alpha) \
627                         CROSSHAIR_DO_BLUR(CROSSHAIR_DRAW_SINGLE,sz,wcross_name,wcross_alpha)
628
629                         if(time < wcross_name_changedonetime && wcross_name != wcross_name_goal_prev_prev && wcross_name_goal_prev_prev)
630                         {
631                                 f = (wcross_name_changedonetime - time) / (wcross_name_changedonetime - wcross_name_changestarttime);
632                                 wcross_size = draw_getimagesize(wcross_name_goal_prev_prev) * wcross_scale;
633                                 CROSSHAIR_DRAW(wcross_resolution_goal_prev_prev, wcross_name_goal_prev_prev, wcross_alpha * f * wcross_name_alpha_goal_prev_prev);
634                                 f = 1 - f;
635                         }
636                         else
637                         {
638                                 f = 1;
639                         }
640                         wcross_name_alpha_goal_prev = f;
641
642                         wcross_size = draw_getimagesize(wcross_name) * wcross_scale;
643                         CROSSHAIR_DRAW(wcross_resolution, wcross_name, wcross_alpha * f);
644
645                         if(autocvar_crosshair_dot)
646                         {
647                                 vector wcross_color_old;
648                                 wcross_color_old = wcross_color;
649
650                                 if((autocvar_crosshair_dot_color_custom) && (autocvar_crosshair_dot_color != "0"))
651                                         wcross_color = stov(autocvar_crosshair_dot_color);
652
653                                 CROSSHAIR_DRAW(wcross_resolution * autocvar_crosshair_dot_size, "gfx/crosshairdot", f * autocvar_crosshair_dot_alpha);
654                                 // FIXME why don't we use wcross_alpha here?
655                                 wcross_color = wcross_color_old;
656                         }
657                 }
658         }
659         else
660         {
661                 wcross_scale_prev = 0;
662                 wcross_alpha_prev = 0;
663                 wcross_scale_goal_prev = 0;
664                 wcross_alpha_goal_prev = 0;
665                 wcross_changedonetime = 0;
666                 strfree(wcross_name_goal_prev);
667                 strfree(wcross_name_goal_prev_prev);
668                 wcross_name_changestarttime = 0;
669                 wcross_name_changedonetime = 0;
670                 wcross_name_alpha_goal_prev = 0;
671                 wcross_name_alpha_goal_prev_prev = 0;
672                 wcross_resolution_goal_prev = 0;
673                 wcross_resolution_goal_prev_prev = 0;
674         }
675 }
676
677 void DrawReticle(entity this)
678 {
679         if(!autocvar_cl_reticle || MUTATOR_CALLHOOK(DrawReticle))
680         {
681                 reticle_type = 0;
682                 return;
683         }
684
685         float is_dead = (STAT(HEALTH) <= 0);
686         string reticle_image = string_null;
687         bool wep_zoomed = false;
688         for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
689         {
690                 entity wepe = viewmodels[slot];
691                 Weapon wep = wepe.activeweapon;
692                 if(wep != WEP_Null && wep.wr_zoom)
693                 {
694                         bool do_zoom = wep.wr_zoom(wep, NULL);
695                         if(!reticle_image && wep.w_reticle && wep.w_reticle != "")
696                                 reticle_image = wep.w_reticle;
697                         wep_zoomed += do_zoom;
698                 }
699         }
700         // Draw the aiming reticle for weapons that use it
701         // reticle_type is changed to the item we are zooming / aiming with, to decide which reticle to use
702         // It must be a persisted float for fading out to work properly (you let go of the zoom button for
703         // the view to go back to normal, so reticle_type would become 0 as we fade out)
704         if(spectatee_status || is_dead || hud != HUD_NORMAL || this.viewloc)
705         {
706                 // no zoom reticle while dead
707                 reticle_type = 0;
708         }
709         else if(wep_zoomed && autocvar_cl_reticle_weapon)
710         {
711                 if(reticle_image) { reticle_type = 2; }
712                 else { reticle_type = 0; }
713         }
714         else if(button_zoom || zoomscript_caught)
715         {
716                 // normal zoom
717                 reticle_type = 1;
718         }
719
720         if(reticle_type)
721         {
722                 vector reticle_pos = '0 0 0', reticle_size = '0 0 0';
723                 if(autocvar_cl_reticle_stretch)
724                 {
725                         reticle_size.x = vid_conwidth;
726                         reticle_size.y = vid_conheight;
727                         reticle_pos.x = 0;
728                         reticle_pos.y = 0;
729                 }
730                 else
731                 {
732                         reticle_size.x = max(vid_conwidth, vid_conheight);
733                         reticle_size.y = max(vid_conwidth, vid_conheight);
734                         reticle_pos.x = (vid_conwidth - reticle_size.x) / 2;
735                         reticle_pos.y = (vid_conheight - reticle_size.y) / 2;
736                 }
737
738                 float f = (zoomscript_caught) ? 1 : current_zoomfraction;
739
740                 if(f)
741                 {
742                         switch(reticle_type)
743                         {
744                                 case 1: drawpic(reticle_pos, "gfx/reticle_normal", reticle_size, '1 1 1', f * autocvar_cl_reticle_normal_alpha, DRAWFLAG_NORMAL); break;
745                                 case 2: if(reticle_image) drawpic(reticle_pos, reticle_image, reticle_size, '1 1 1', f * autocvar_cl_reticle_weapon_alpha, DRAWFLAG_NORMAL); break;
746                         }
747                 }
748         }
749 }