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