From 2b57a4f1f092a17b223223019ad31cb980f4212e Mon Sep 17 00:00:00 2001 From: terencehill Date: Sat, 10 Sep 2016 22:54:27 +0200 Subject: [PATCH] Add a mutator hook for customizing the eventchase effect; onslaught now makes use of it when a generator explodes --- qcsrc/client/autocvars.qh | 2 - qcsrc/client/mutators/events.qh | 9 ++++ qcsrc/client/view.qc | 31 ++++++------- .../gamemodes/gamemode/onslaught/onslaught.qc | 45 +++++++++++++++++++ 4 files changed, 70 insertions(+), 17 deletions(-) diff --git a/qcsrc/client/autocvars.qh b/qcsrc/client/autocvars.qh index 9cbbcb5f7..8e2c722e8 100644 --- a/qcsrc/client/autocvars.qh +++ b/qcsrc/client/autocvars.qh @@ -412,8 +412,6 @@ float autocvar_cl_hitsound_max_pitch = 1.5; float autocvar_cl_hitsound_nom_damage = 25; float autocvar_cl_hitsound_antispam_time; int autocvar_cl_eventchase_death = 1; -vector autocvar_cl_eventchase_generator_viewoffset = '0 0 80'; -float autocvar_cl_eventchase_generator_distance = 400; float autocvar_cl_eventchase_distance = 140; float autocvar_cl_eventchase_speed = 1.3; vector autocvar_cl_eventchase_maxs = '12 12 8'; diff --git a/qcsrc/client/mutators/events.qh b/qcsrc/client/mutators/events.qh index a852fdbe4..1792183f1 100644 --- a/qcsrc/client/mutators/events.qh +++ b/qcsrc/client/mutators/events.qh @@ -88,6 +88,15 @@ MUTATOR_HOOKABLE(GetModelParams, EV_GetModelParams); /**/ MUTATOR_HOOKABLE(WantEventchase, EV_WantEventchase); +/** allow customizing 3rd person mode effect */ +#define EV_CustomizeEventchase(i, o) \ + /** entity id */ i(entity, MUTATOR_ARGV_0_entity) \ + /* current_view_origin_override */ o(vector, MUTATOR_ARGV_0_vector) \ + /* view_offset_override */ o(vector, MUTATOR_ARGV_1_vector) \ + /* chase_distance_override */ o(float, MUTATOR_ARGV_0_float) \ + /**/ +MUTATOR_HOOKABLE(CustomizeEventchase, EV_CustomizeEventchase); + #define EV_AnnouncerOption(i, o) \ /** announcer string */ i(string, MUTATOR_ARGV_0_string) \ /** announcer string */ o(string, MUTATOR_ARGV_0_string) \ diff --git a/qcsrc/client/view.qc b/qcsrc/client/view.qc index e5f8b6a58..3134a24ed 100644 --- a/qcsrc/client/view.qc +++ b/qcsrc/client/view.qc @@ -1490,8 +1490,6 @@ void CSQC_UpdateView(entity this, float w, float h) cvar_set("chase_active", "0"); float vehicle_chase = (hud != HUD_NORMAL && (autocvar_cl_eventchase_vehicle || spectatee_status > 0)); - float ons_roundlost = (gametype == MAPINFO_TYPE_ONSLAUGHT && STAT(ROUNDLOST)); - entity gen = NULL; float vehicle_viewdist = 0; vector vehicle_viewofs = '0 0 0'; @@ -1506,18 +1504,18 @@ void CSQC_UpdateView(entity this, float w, float h) } } - if(ons_roundlost) // TODO: move this junk to a client mutator for onslaught (possible using the WantEventchase hook) + if(WantEventchase(this)) { - IL_EACH(g_onsgenerators, it.health <= 0, + vector current_view_origin_override = '0 0 0'; + vector view_offset_override = '0 0 0'; + float chase_distance_override = 0; + bool custom_eventchase = MUTATOR_CALLHOOK(CustomizeEventchase, this); + if(custom_eventchase) { - gen = it; - break; - }); - if(!gen) - ons_roundlost = false; // don't enforce the 3rd person camera if there is no dead generator to show - } - if(WantEventchase(this) || (!autocvar_cl_orthoview && ons_roundlost)) - { + current_view_origin_override = M_ARGV(0, vector); + view_offset_override = M_ARGV(1, vector); + chase_distance_override = M_ARGV(0, float); + } eventchase_running = true; entity local_player = ((csqcplayer) ? csqcplayer : CSQCModel_server2csqc(player_localentnum - 1)); @@ -1526,7 +1524,8 @@ void CSQC_UpdateView(entity this, float w, float h) // make special vector since we can't use view_origin (It is one frame old as of this code, it gets set later with the results this code makes.) vector current_view_origin = (csqcplayer ? csqcplayer.origin : pmove_org); - if(ons_roundlost) { current_view_origin = gen.origin; } + if (custom_eventchase) + current_view_origin = current_view_origin_override; // detect maximum viewoffset and use it vector view_offset = autocvar_cl_eventchase_viewoffset; @@ -1537,7 +1536,8 @@ void CSQC_UpdateView(entity this, float w, float h) else view_offset = autocvar_cl_eventchase_vehicle_viewoffset; } - if(ons_roundlost) { view_offset = autocvar_cl_eventchase_generator_viewoffset; } + if (custom_eventchase) + view_offset = view_offset_override; if(view_offset) { @@ -1560,7 +1560,8 @@ void CSQC_UpdateView(entity this, float w, float h) else chase_distance = autocvar_cl_eventchase_vehicle_distance; } - if(ons_roundlost) { chase_distance = autocvar_cl_eventchase_generator_distance; } + if (custom_eventchase) + chase_distance = chase_distance_override; if(autocvar_cl_eventchase_speed && eventchase_current_distance < chase_distance) eventchase_current_distance += autocvar_cl_eventchase_speed * (chase_distance - eventchase_current_distance) * frametime; // slow down the further we get diff --git a/qcsrc/common/gamemodes/gamemode/onslaught/onslaught.qc b/qcsrc/common/gamemodes/gamemode/onslaught/onslaught.qc index 36926b754..a30dd7d07 100644 --- a/qcsrc/common/gamemodes/gamemode/onslaught/onslaught.qc +++ b/qcsrc/common/gamemodes/gamemode/onslaught/onslaught.qc @@ -1 +1,46 @@ #include "onslaught.qh" + +#ifdef CSQC + +REGISTER_MUTATOR(cl_ons, true); + +float ons_roundlost; +vector generator_origin; +vector autocvar_cl_eventchase_generator_viewoffset = '0 0 80'; +float autocvar_cl_eventchase_generator_distance = 400; +MUTATOR_HOOKFUNCTION(cl_ons, WantEventchase) +{ + ons_roundlost = STAT(ROUNDLOST); + entity gen = NULL; + if(ons_roundlost) + { + IL_EACH(g_onsgenerators, it.health <= 0, + { + gen = it; + break; + }); + if(!gen) + ons_roundlost = false; // don't enforce the 3rd person camera if there is no dead generator to show + } + + if(ons_roundlost) + { + generator_origin = gen.origin; + return true; + } + return false; +} + +MUTATOR_HOOKFUNCTION(cl_ons, CustomizeEventchase) +{ + if(ons_roundlost) + { + M_ARGV(0, vector) = generator_origin; + M_ARGV(1, vector) = autocvar_cl_eventchase_generator_viewoffset; + M_ARGV(0, float) = autocvar_cl_eventchase_generator_distance; + return true; + } + return false; +} + +#endif -- 2.39.2