1 #include "crosshair.qh"
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>
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>
20 float pickup_crosshair_time, pickup_crosshair_size;
21 float hitindication_crosshair_size;
22 float use_vortex_chargepool;
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;
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;
38 float wcross_ring_prev;
43 const float SHOTTYPE_HITTEAM = 1;
44 const float SHOTTYPE_HITOBSTRUCTION = 2;
45 const float SHOTTYPE_HITWORLD = 3;
46 const float SHOTTYPE_HITENEMY = 4;
50 (trueaim = new_pure(trueaim)).dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_CORPSE;
51 (trueaim_rifle = new_pure(trueaim_rifle)).dphitcontentsmask = DPCONTENTS_BODY | DPCONTENTS_CORPSE;
57 wcross_origin = project_3d_to_2d(trace_endpos);
62 n = trace_networkentity;
64 return SHOTTYPE_HITWORLD;
66 return SHOTTYPE_HITWORLD;
67 t = entcs_GetTeam(n - 1);
70 return SHOTTYPE_HITTEAM;
71 if(t == NUM_SPECTATOR)
72 return SHOTTYPE_HITWORLD;
73 return SHOTTYPE_HITENEMY;
76 float TrueAimCheck(entity wepent)
78 if(wepent.activeweapon.spawnflags & WEP_FLAG_NOTRUEAIM)
79 return SHOTTYPE_HITWORLD;
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;
92 switch(wepent.activeweapon) // WEAPONTODO
95 case WEP_OVERKILL_NEX:
102 if(zoomscript_caught)
104 tracebox(view_origin, '0 0 0', '0 0 0', view_origin + view_forward * max_shot_distance, mv, ta);
105 return EnemyHitCheck();
108 case WEP_DEVASTATOR: // projectile has a size!
112 case WEP_FIREBALL: // projectile has a size!
116 case WEP_SEEKER: // projectile has a size!
120 case WEP_ELECTRO: // projectile has a size!
126 vector traceorigin = entcs_receiver(player_localentnum - 1).origin + (eZ * STAT(VIEWHEIGHT));
128 vecs = decompressShotOrigin(STAT(SHOTORG));
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;
136 if(vdist((trueaimpoint - traceorigin), <, g_trueaim_minrange))
137 trueaimpoint = traceorigin + view_forward * g_trueaim_minrange;
144 dv = view_right * vecs.y + view_up * vecs.z;
145 w_shotorg = traceorigin + dv;
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;
151 tracebox(w_shotorg, mi, ma, trueaimpoint, MOVE_NORMAL, ta);
152 shottype = EnemyHitCheck();
153 if(shottype != SHOTTYPE_HITWORLD)
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;
164 return SHOTTYPE_HITWORLD;
167 void HUD_Crosshair_Vehicle(entity this)
169 if(hud != HUD_BUMBLEBEE_GUN)
171 Vehicle info = REGISTRY_GET(Vehicles, hud);
172 info.vr_crosshair(info, this);
176 vector crosshair_getcolor(entity this, float health_stat)
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)
183 case 1: // weapon color
185 if(this != WEP_Null && hud == HUD_NORMAL)
187 wcross_color = this.wpcolor;
190 else { goto normalcolor; }
193 case 2: // color based on health and armor
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);
201 case 3: // rainbow/random color
203 if(time >= rainbow_last_flicker)
205 rainbow_prev_color = randomvec() * autocvar_crosshair_color_special_rainbow_brightness;
206 rainbow_last_flicker = time + autocvar_crosshair_color_special_rainbow_delay;
208 wcross_color = rainbow_prev_color;
212 default: { wcross_color = stov(autocvar_crosshair_color); break; }
218 void HUD_Crosshair(entity this)
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;
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())
230 if (!autocvar_crosshair_enabled) // main toggle for crosshair rendering
233 if (spectatee_status > 0 && STAT(CAMERA_SPECTATOR) == 2)
236 if (hud != HUD_NORMAL)
238 HUD_Crosshair_Vehicle(this);
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")
249 wcross_resolution = autocvar_crosshair_size;
250 if (wcross_resolution == 0)
252 wcross_alpha = autocvar_crosshair_alpha;
253 if (wcross_alpha == 0)
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)
264 vector player_org = ((csqcplayer) ? csqcplayer.origin + csqcplayer.view_ofs : view_origin);
265 if(csqcplayer && autocvar_crosshair_chase_playeralpha && autocvar_crosshair_chase_playeralpha < 1)
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);
272 csqcplayer.alpha = csqcplayer.m_alpha;
274 traceline(player_org, player_org + max_shot_distance * view_forward, MOVE_WORLDONLY, NULL);
275 wcross_origin = project_3d_to_2d(trace_endpos);
278 wcross_origin = project_3d_to_2d(view_origin + max_shot_distance * view_forward);
280 if(autocvar_crosshair_hittest)
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)
288 v = wcross_origin - wcross_oldorigin;
290 v.y /= vid_conheight;
291 if(vdist(v, >, 0.01))
292 shottype = SHOTTYPE_HITOBSTRUCTION;
294 if(!autocvar_crosshair_hittest_showimpact)
295 wcross_origin = wcross_oldorigin;
298 shottype = SHOTTYPE_HITWORLD;
300 vector wcross_color = '0 0 0', wcross_size = '0 0 0';
301 string wcross_name = "";
302 float wcross_scale, wcross_blur;
305 if(autocvar_crosshair_per_weapon || (autocvar_crosshair_color_special == 1))
307 entity wepent = viewmodels[0]; // TODO: unhardcode
308 e = wepent.switchingweapon;
311 if(autocvar_crosshair_per_weapon)
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)
318 //wcross_style = cvar_string(strcat("crosshair_", wcross_wep));
319 wcross_resolution *= e.w_crosshair_size;
320 wcross_name = e.w_crosshair;
325 if(wcross_name == "")
326 wcross_name = strcat("gfx/crosshair", wcross_style);
328 // MAIN CROSSHAIR COLOR DECISION
329 wcross_color = crosshair_getcolor(e, STAT(HEALTH));
331 if(autocvar_crosshair_effect_scalefade)
333 wcross_scale = wcross_resolution;
334 wcross_resolution = 1;
341 if(autocvar_crosshair_pickup)
343 float stat_pickup_time = STAT(LAST_PICKUP);
345 if(pickup_crosshair_time < stat_pickup_time)
347 if(time - stat_pickup_time < 5) // don't trigger the animation if it's too old
348 pickup_crosshair_size = 1;
350 pickup_crosshair_time = stat_pickup_time;
353 if(pickup_crosshair_size > 0)
354 pickup_crosshair_size -= autocvar_crosshair_pickup_speed * frametime;
356 pickup_crosshair_size = 0;
358 wcross_scale += sin(pickup_crosshair_size) * autocvar_crosshair_pickup;
361 // todo: make crosshair hit indication dependent on damage dealt
362 if(autocvar_crosshair_hitindication)
364 vector hitindication_color = ((autocvar_crosshair_color_special == 1) ? stov(autocvar_crosshair_hitindication_per_weapon_color) : stov(autocvar_crosshair_hitindication_color));
366 if(unaccounted_damage)
368 hitindication_crosshair_size = 1;
371 if(hitindication_crosshair_size > 0)
372 hitindication_crosshair_size -= autocvar_crosshair_hitindication_speed * frametime;
374 hitindication_crosshair_size = 0;
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;
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
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)
392 wcross_changedonetime = time + f;
394 if(wcross_name != wcross_name_goal_prev || wcross_resolution != wcross_resolution_goal_prev)
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;
407 wcross_scale_goal_prev = wcross_scale;
408 wcross_alpha_goal_prev = wcross_alpha;
409 wcross_color_goal_prev = wcross_color;
411 if((shottype == SHOTTYPE_HITTEAM && autocvar_crosshair_hittest_blur_teammate)
412 || (shottype == SHOTTYPE_HITOBSTRUCTION && autocvar_crosshair_hittest_blur_wall && !autocvar_chase_active))
415 wcross_alpha *= 0.75;
419 // *_prev is at time-frametime
420 // * is at wcross_changedonetime+f
421 // what do we have at time?
422 if(time < wcross_changedonetime)
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;
430 wcross_scale_prev = wcross_scale;
431 wcross_alpha_prev = wcross_alpha;
432 wcross_color_prev = wcross_color;
434 MUTATOR_CALLHOOK(UpdateCrosshair);
436 wcross_scale *= 1 - autocvar__menu_alpha;
437 wcross_alpha *= 1 - autocvar__menu_alpha;
438 wcross_size = draw_getimagesize(wcross_name) * wcross_scale;
440 if(wcross_scale >= 0.001 && wcross_alpha >= 0.001)
442 // crosshair rings for weapon stats
443 if (autocvar_crosshair_ring || autocvar_crosshair_ring_reload)
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';
450 ring_scale = autocvar_crosshair_ring_size;
452 entity wepent = viewmodels[0]; // TODO: unhardcode
454 int weapon_clipload = wepent.clip_load;
455 int weapon_clipsize = wepent.clip_size;
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;
463 if(vortex_charge_movingavg == 0) // this should only happen if we have just loaded up the game
464 vortex_charge_movingavg = vcharge;
467 if (autocvar_crosshair_ring && wepent.activeweapon == WEP_VORTEX && vcharge && autocvar_crosshair_ring_vortex) // ring around crosshair representing velocity-dependent damage for the vortex
469 if (vchargepool || use_vortex_chargepool) {
470 use_vortex_chargepool = 1;
471 ring_inner_value = vchargepool;
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);
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";
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";
487 else if (autocvar_crosshair_ring && (wepent.activeweapon == WEP_OVERKILL_NEX) && oknex_charge_ && autocvar_crosshair_ring_vortex)
489 if (oknex_chargepool_ || use_vortex_chargepool) {
490 use_vortex_chargepool = 1;
491 ring_inner_value = oknex_chargepool_;
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);
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";
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";
507 else if (autocvar_crosshair_ring && wepent.activeweapon == WEP_MINE_LAYER && WEP_CVAR(minelayer, limit) && autocvar_crosshair_ring_minelayer)
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";
514 else if (wepent.activeweapon == WEP_HAGAR && wepent.hagar_load && autocvar_crosshair_ring_hagar)
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";
521 else if(autocvar_crosshair_ring_reload && weapon_clipsize) // forces there to be only an ammo ring
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;
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";
533 ring_image = "gfx/crosshair_ring.tga";
535 else if ( autocvar_crosshair_ring && autocvar_crosshair_ring_arc && arc_heat && wepent.activeweapon == WEP_ARC )
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";
544 // if in weapon switch animation, fade ring out/in
545 if(autocvar_crosshair_effect_time > 0)
547 f = (time - wcross_name_changestarttime) / autocvar_crosshair_effect_time;
550 wcross_ring_prev = ((ring_image) ? true : false);
556 ring_alpha *= fabs(1 - bound(0, f, 1));
561 ring_alpha *= bound(0, f, 1);
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);
569 DrawCircleClippedPic(wcross_origin, wcross_size.x * wcross_resolution * ring_scale, ring_image, ring_value, ring_rgb, wcross_alpha * ring_alpha, DRAWFLAG_ADDITIVE);
572 #define CROSSHAIR_DO_BLUR(M,sz,wcross_name,wcross_alpha) \
574 vector scaled_sz = sz * wcross_size; \
575 if(wcross_blur > 0) \
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); \
583 M(0,0,sz,scaled_sz,wcross_name,wcross_alpha); \
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)
590 #define CROSSHAIR_DRAW(sz,wcross_name,wcross_alpha) \
591 CROSSHAIR_DO_BLUR(CROSSHAIR_DRAW_SINGLE,sz,wcross_name,wcross_alpha)
593 if(time < wcross_name_changedonetime && wcross_name != wcross_name_goal_prev_prev && wcross_name_goal_prev_prev)
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);
604 wcross_name_alpha_goal_prev = f;
606 wcross_size = draw_getimagesize(wcross_name) * wcross_scale;
607 CROSSHAIR_DRAW(wcross_resolution, wcross_name, wcross_alpha * f);
609 if(autocvar_crosshair_dot)
611 vector wcross_color_old;
612 wcross_color_old = wcross_color;
614 if((autocvar_crosshair_dot_color_custom) && (autocvar_crosshair_dot_color != "0"))
615 wcross_color = stov(autocvar_crosshair_dot_color);
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;
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;
641 void DrawReticle(entity this)
643 if(!autocvar_cl_reticle || MUTATOR_CALLHOOK(DrawReticle))
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)
654 entity wepe = viewmodels[slot];
655 Weapon wep = wepe.activeweapon;
656 if(wep != WEP_Null && wep.wr_zoom)
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;
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)
670 // no zoom reticle while dead
673 else if(wep_zoomed && autocvar_cl_reticle_weapon)
675 if(reticle_image) { reticle_type = 2; }
676 else { reticle_type = 0; }
678 else if(button_zoom || zoomscript_caught)
686 vector reticle_pos = '0 0 0', reticle_size = '0 0 0';
687 if(autocvar_cl_reticle_stretch)
689 reticle_size.x = vid_conwidth;
690 reticle_size.y = vid_conheight;
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;
702 float f = (zoomscript_caught) ? 1 : current_zoomfraction;
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;