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