From: MirceaKitsune Date: Fri, 25 Feb 2011 20:50:52 +0000 (+0200) Subject: Port blood effect from Xonotic code. When your health is under a certain amount,... X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=30d7f93ccf99d857f6cd5d6806e4c3e0b53fef1b;p=voretournament%2Fvoretournament.git Port blood effect from Xonotic code. When your health is under a certain amount, your screen will flash red and will have a blood stain on it (nothing too scary :P) --- diff --git a/data/defaultVoretournament.cfg b/data/defaultVoretournament.cfg index 0c88250b..f1202cc4 100644 --- a/data/defaultVoretournament.cfg +++ b/data/defaultVoretournament.cfg @@ -1059,6 +1059,19 @@ con_chatwidth 0.6 con_notifysize 10 con_notifyalign 0 +seta hud_damage 0.55 "an improved version of gl_polyblend for damage, draw an image instead when hurt" +seta hud_damage_gentle_alpha_multiplier 0.10 "how much to multiply alpha of flash when using the cl_gentle version, it's much more opaque than the non-gentle version" +seta hud_damage_gentle_color "1 0.7 1" "color of flash for cl_gentle version" +seta hud_damage_color "1 0 0" "color of flash" +seta hud_damage_factor 0.025 "(damage * factor) = how much to add to the alpha value" +seta hud_damage_fade_rate 0.75 "how much to subtract from the alpha value each second" +seta hud_damage_maxalpha 1.5 "how much to limit the alpha value to" +seta hud_damage_pain_threshold 0.1 "how much alpha to ignore (must be bigger than the hud_damage_factor so that e.g. rot is ignored)" +seta hud_damage_pain_threshold_lower 1.25 "how much we lower pain_threshold with when nearing 0 health (if pain_threshold gets negative then we always draw a flash at alpha = fabs(pain_threshold)" +seta hud_damage_pain_threshold_lower_health 50 "at which health we start lowering pain_threshold" +seta hud_damage_pain_threshold_pulsating_min 0.6 "minimum value when calculating the pulse: max(pulsating_min, fabs(sin(PI * time / period))" +seta hud_damage_pain_threshold_pulsating_period 0.8 "one pulse every X seconds" + seta hud_contents 1 "an improved version of gl_polyblend for liquids such as water/lava/slime, draw a filler when inside the liquid" seta hud_contents_factor 1 "factor at which to multiply the current faded value." seta hud_contents_fadeintime 0.02 "factor of time it takes for the alpha level to reach normal value when entering the liquid" diff --git a/data/qcsrc/client/Defs.qc b/data/qcsrc/client/Defs.qc index 92cd3b00..1f2edf68 100644 --- a/data/qcsrc/client/Defs.qc +++ b/data/qcsrc/client/Defs.qc @@ -156,7 +156,7 @@ float sb_showaccuracy; // float coop; // float deathmatch; -// float dmg_take; +float dmg_take; // float dmg_save; // vector dmg_origin; diff --git a/data/qcsrc/client/View.qc b/data/qcsrc/client/View.qc index 37090311..07321ed6 100644 --- a/data/qcsrc/client/View.qc +++ b/data/qcsrc/client/View.qc @@ -253,7 +253,9 @@ float camera_mode; float chase_active_old; float artwork_fade; float pickup_crosshair_time, pickup_crosshair_size; +float myhealth, myhealth_prev, myhealth_flash; float contentavgalpha, liquidalpha_prev; +vector myhealth_gentlergb; vector liquidcolor_prev; string artwork_image; string intermission_song; @@ -501,6 +503,67 @@ void CSQC_UpdateView(float w, float h) drawfill('0 0 0', '1 0 0' * vid_conwidth + '0 1 0' * vid_conheight, liquidcolor_prev, contentavgalpha * liquidalpha_prev, DRAWFLAG_NORMAL); } + if(cvar("hud_damage")) + { + float myhealth_flash_temp; + myhealth = getstati(STAT_HEALTH); + + // fade out + myhealth_flash = max(0, myhealth_flash - cvar("hud_damage_fade_rate") * frametime); + // add new damage + myhealth_flash = bound(0, myhealth_flash + dmg_take * cvar("hud_damage_factor"), cvar("hud_damage_maxalpha")); + + float pain_threshold, pain_threshold_lower, pain_threshold_lower_health; + pain_threshold = cvar("hud_damage_pain_threshold"); + pain_threshold_lower = cvar("hud_damage_pain_threshold_lower"); + pain_threshold_lower_health = cvar("hud_damage_pain_threshold_lower_health"); + + if(pain_threshold_lower && myhealth < pain_threshold_lower_health) + { + pain_threshold = pain_threshold - max(cvar("hud_damage_pain_threshold_pulsating_min"), fabs(sin(M_PI * time / cvar("hud_damage_pain_threshold_pulsating_period")))) * pain_threshold_lower * (1 - max(0, myhealth)/pain_threshold_lower_health); + } + + myhealth_flash_temp = bound(0, myhealth_flash - pain_threshold, 1); + + if(myhealth_prev < 1) + { + if(myhealth >= 1) + { + myhealth_flash = 0; // just spawned, clear the flash immediately + myhealth_flash_temp = 0; + } + else + { + myhealth_flash += cvar("hud_damage_fade_rate") * frametime; // dead + } + } + + if(spectatee_status == -1 || intermission) + { + myhealth_flash = 0; // observing, or match ended + myhealth_flash_temp = 0; + } + + myhealth_prev = myhealth; + + if(cvar("cl_gentle_damage") || cvar("cl_gentle")) + { + if(cvar("cl_gentle_damage") == 2) + { + if(myhealth_flash < pain_threshold) // only randomize when the flash is gone + { + myhealth_gentlergb = '1 0 0' * random() + '0 1 0' * random() + '0 0 1' * random(); + } + } + else + myhealth_gentlergb = stov(cvar_string("hud_damage_gentle_color")); + + drawfill('0 0 0', '1 0 0' * vid_conwidth + '0 1 0' * vid_conheight, myhealth_gentlergb, cvar("hud_damage_gentle_alpha_multiplier") * bound(0, myhealth_flash_temp, 1) * cvar("hud_damage"), DRAWFLAG_NORMAL); + } + else + drawpic('0 0 0', "gfx/blood", '1 0 0' * vid_conwidth + '0 1 0' * vid_conheight, stov(cvar_string("hud_damage_color")), bound(0, myhealth_flash_temp, 1) * cvar("hud_damage"), DRAWFLAG_NORMAL); + } + // Draw the mouse cursor // NOTE: drawpic must happen after R_RenderScene for some reason //drawpic(getmousepos(), "gfx/cursor.tga", '11 14 0', '1 1 1', 1, 0);