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