]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Fix #2201 "ForbidWeaponUse mutator hook can leave the player holding a weapon they... 644/head
authorterencehill <piuntn@gmail.com>
Wed, 10 Apr 2019 14:54:55 +0000 (16:54 +0200)
committerterencehill <piuntn@gmail.com>
Wed, 10 Apr 2019 14:54:55 +0000 (16:54 +0200)
18 files changed:
qcsrc/common/mutators/mutator/campcheck/sv_campcheck.qc
qcsrc/common/mutators/mutator/nades/nades.qc
qcsrc/common/mutators/mutator/overkill/sv_overkill.qc
qcsrc/common/mutators/mutator/spawn_near_teammate/sv_spawn_near_teammate.qc
qcsrc/common/vehicles/sv_vehicles.qc
qcsrc/common/vehicles/vehicle/bumblebee.qc
qcsrc/common/vehicles/vehicle/racer.qc
qcsrc/common/vehicles/vehicle/raptor.qc
qcsrc/common/vehicles/vehicle/spiderbot.qc
qcsrc/common/vehicles/vehicle/spiderbot_weapons.qc
qcsrc/common/weapons/weapon/hagar.qc
qcsrc/common/weapons/weapon/vaporizer.qc
qcsrc/server/g_hook.qc
qcsrc/server/impulse.qc
qcsrc/server/mutators/events.qh
qcsrc/server/weapons/selection.qc
qcsrc/server/weapons/weaponsystem.qc
qcsrc/server/weapons/weaponsystem.qh

index e56d044669b353aa346bde74cb4c829565c40e1d..97e63161d54a062a771fd8129a9884ebff34cd52 100644 (file)
@@ -45,7 +45,7 @@ MUTATOR_HOOKFUNCTION(campcheck, PlayerPreThink)
        if(!STAT(FROZEN, player))
        if(!PHYS_INPUT_BUTTON_CHAT(player))
        if(IS_REAL_CLIENT(player)) // bots may camp, but that's no reason to constantly kill them
-       if(!forbidWeaponUse(player))
+       if(!weaponLocked(player))
        {
                // calculate player movement (in 2 dimensions only, so jumping on one spot doesn't count as movement)
                vector dist = vec2(player.campcheck_prevorigin - player.origin);
index 6924947f05c0c821b5558648ef471c42fda5be4b..b6c4578d59fc6d32f265506ffb577f5da587a2d8 100644 (file)
@@ -1161,7 +1161,7 @@ bool CanThrowNade(entity this)
        if (!autocvar_g_nades)
                return false; // allow turning them off mid match
 
-       if(forbidWeaponUse(this))
+       if (weaponLocked(this))
                return false;
 
        if (!IS_PLAYER(this))
index c8e4398b0d7c502e845cecfa5b0547f7fceb7eb4..15a2fc2e0c972427c1270223e0f40ad178609b81 100644 (file)
@@ -143,7 +143,7 @@ MUTATOR_HOOKFUNCTION(ok, PlayerPreThink)
        {
                return;
        }
-       if (!PHYS_INPUT_BUTTON_ATCK2(player) || forbidWeaponUse(player) ||
+       if (!PHYS_INPUT_BUTTON_ATCK2(player) || weaponLocked(player) ||
                !(round_handler_IsActive() && !round_handler_IsRoundStarted()))
        {
                return;
index b747ce74922b7c19de988bf88b07492532b31665..73435841d87c296f1119c3078b1f4c0833ba02d8 100644 (file)
@@ -95,7 +95,7 @@ MUTATOR_HOOKFUNCTION(spawn_near_teammate, PlayerSpawn)
                        if (IS_DEAD(it)) continue;
                        if (time < it.msnt_timer) continue;
                        if (time < it.spawnshieldtime) continue;
-                       if (forbidWeaponUse(it)) continue;
+                       if (weaponLocked(it)) continue;
                        if (it == player) continue;
 
                        tested++; // i consider a teammate to be available when he passes the checks above
index 9a85e11455210ff3e14723792e638b8780bbcb2e..c8e47dabc20ea7efdb3b55b6c71ac86fbe49453d 100644 (file)
@@ -924,7 +924,7 @@ void vehicles_touch(entity this, entity toucher)
        // Vehicle currently in use
        if(this.owner)
        {
-               if(!forbidWeaponUse(this.owner))
+               if(!weaponLocked(this.owner))
                if(toucher != NULL)
                if((this.origin_z + this.maxs_z) > (toucher.origin_z))
                if(vehicles_crushable(toucher))
index a83b0928f347851f7fb1b9b11921d2ad02b92306..2bd81f12d2c7a0165f06b892251d4b29ab879de1 100644 (file)
@@ -157,7 +157,7 @@ bool bumblebee_gunner_frame(entity this, float dt)
                                                  autocvar_g_vehicle_bumblebee_cannon_pitchlimit_down * -1, autocvar_g_vehicle_bumblebee_cannon_pitchlimit_up,
                                                  _out * -1,  _in,  autocvar_g_vehicle_bumblebee_cannon_turnspeed, dt);
 
-       if(!forbidWeaponUse(this))
+       if(!weaponLocked(this))
        if(PHYS_INPUT_BUTTON_ATCK(this))
                if(time > gun.attack_finished_single[0])
                        if(gun.vehicle_energy >= autocvar_g_vehicle_bumblebee_cannon_cost)
@@ -531,7 +531,7 @@ bool bumblebee_pilot_frame(entity this, float dt)
                                          autocvar_g_vehicle_bumblebee_raygun_pitchlimit_down * -1,  autocvar_g_vehicle_bumblebee_raygun_pitchlimit_up,
                                          autocvar_g_vehicle_bumblebee_raygun_turnlimit_sides * -1,  autocvar_g_vehicle_bumblebee_raygun_turnlimit_sides,  autocvar_g_vehicle_bumblebee_raygun_turnspeed, dt);
 
-       if(!forbidWeaponUse(this))
+       if(!weaponLocked(this))
        if((PHYS_INPUT_BUTTON_ATCK(this) || PHYS_INPUT_BUTTON_ATCK2(this)) && (vehic.vehicle_energy > autocvar_g_vehicle_bumblebee_raygun_dps * PHYS_INPUT_FRAMETIME || autocvar_g_vehicle_bumblebee_raygun == 0))
        {
                vehic.gun3.enemy.realowner = this;
index 109eab0ca2dc1edfac58daf0741d402a22da02b7..eb9d6623a698848a507037c4bcb43aeadc5eee16 100644 (file)
@@ -287,7 +287,7 @@ bool racer_frame(entity this, float dt)
 
        Weapon wep1 = WEP_RACER;
        .entity weaponentity = weaponentities[0]; // TODO: unhardcode
-       if (!forbidWeaponUse(player))
+       if (!weaponLocked(player))
        if (PHYS_INPUT_BUTTON_ATCK(player))
        if (wep1.wr_checkammo1(wep1, vehic, weaponentity))
        {
@@ -327,7 +327,7 @@ bool racer_frame(entity this, float dt)
                }
        }
 
-       if(!forbidWeaponUse(player))
+       if(!weaponLocked(player))
        if(time > vehic.delay)
        if(PHYS_INPUT_BUTTON_ATCK2(player))
        {
index b672d348b48e0c0064605cb601315c0e9b971153..6e91441685d49cde764aec948312a38365aa172e 100644 (file)
@@ -358,7 +358,7 @@ bool raptor_frame(entity this, float dt)
 
        Weapon wep1 = WEP_RAPTOR;
        .entity weaponentity = weaponentities[0];
-       if(!forbidWeaponUse(this))
+       if(!weaponLocked(this))
        if(PHYS_INPUT_BUTTON_ATCK(this))
        if (wep1.wr_checkammo1(wep1, vehic, weaponentity))
        {
@@ -375,7 +375,7 @@ bool raptor_frame(entity this, float dt)
                vehicles_regen(vehic, vehic.cnt, vehicle_energy, autocvar_g_vehicle_raptor_energy, autocvar_g_vehicle_raptor_energy_regen_pause, autocvar_g_vehicle_raptor_energy_regen, dt, false);
 
        Weapon wep2a = WEP_RAPTOR_BOMB;
-       if(!forbidWeaponUse(this))
+       if(!weaponLocked(this))
        if(STAT(VEHICLESTAT_W2MODE, vehic) == RSM_BOMB)
        {
                if(time > vehic.lip + autocvar_g_vehicle_raptor_bombs_refire)
index 3f023729f2a69bfd640378a99d765deee6ade4c7..36f6cb2f8b81f712de78d70d0ad8aa4e27eba7dc 100644 (file)
@@ -246,7 +246,7 @@ bool spiderbot_frame(entity this, float dt)
        vehic.angles_x = bound(-autocvar_g_vehicle_spiderbot_tiltlimit, vehic.angles_x, autocvar_g_vehicle_spiderbot_tiltlimit);
        vehic.angles_z = bound(-autocvar_g_vehicle_spiderbot_tiltlimit, vehic.angles_z, autocvar_g_vehicle_spiderbot_tiltlimit);
 
-       if(!forbidWeaponUse(this))
+       if(!weaponLocked(this))
        if(PHYS_INPUT_BUTTON_ATCK(this))
        {
                vehic.cnt = time;
index a18d0321356f0bb4311abbf12997a9f2681296fa..4b48eeccead4f0c082452d988dc8ab9f79586704 100644 (file)
@@ -175,7 +175,7 @@ void spiderbot_rocket_do(entity this)
     if(!PHYS_INPUT_BUTTON_ATCK2(this.owner))
         return;
 
-    if(forbidWeaponUse(this.owner))
+    if(weaponLocked(this.owner))
         return;
 
     v = gettaginfo(this.tur_head,gettagindex(this.tur_head,"tag_fire"));
index 20c588715a5a13d6ebf496964cd8bff7c4b3e682..51699bf0cdc560a981cf7cb5d9abdcec4998585c 100644 (file)
@@ -257,7 +257,7 @@ void W_Hagar_Attack2_Load(Weapon thiswep, entity actor, .entity weaponentity)
        // loadable hagar secondary attack, must always run each frame
        if(time < game_starttime || time < actor.race_penalty || timeout_status == TIMEOUT_ACTIVE)
                return;
-       if (round_handler_IsActive() && !round_handler_IsRoundStarted())
+       if (weaponUseForbidden(actor))
                return;
 
        bool loaded = actor.(weaponentity).hagar_load >= WEP_CVAR_SEC(hagar, load_max);
index 2e76827d799380035b7c4a959f545f6e7e5b8d82..dbf24c7964d94ff229b30ac068d4a0d315a251ba 100644 (file)
@@ -295,7 +295,7 @@ METHOD(Vaporizer, wr_think, void(entity thiswep, entity actor, .entity weaponent
     } else if(WEP_CVAR(vaporizer, reload_ammo) && actor.(weaponentity).clip_load < vaporizer_ammo) { // forced reload
         thiswep.wr_reload(thiswep, actor, weaponentity);
     }
-    if((fire & 1) && (GetResource(actor, RES_CELLS) || !autocvar_g_rm) && !forbidWeaponUse(actor))
+    if((fire & 1) && (GetResource(actor, RES_CELLS) || !autocvar_g_rm) && !weaponLocked(actor))
     {
         if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(vaporizer, refire)))
         {
index ffb19f17a1041e0048bf12b9b3e7beeb31920539..453cfc1e70d3664d1725e795c685c36c1e00cb69 100644 (file)
@@ -360,7 +360,7 @@ void GrapplingHook_Damage(entity this, entity inflictor, entity attacker, float
 
 void FireGrapplingHook(entity actor, .entity weaponentity)
 {
-       if(forbidWeaponUse(actor)) return;
+       if(weaponLocked(actor)) return;
        if(actor.vehicle) return;
 
        // TODO: offhand hook shoots from eye
index 9b1e38e8e376c381f096b3c6c0f07527a30d5682..2320eb830ef50db38913df89c96a724ce801080d 100644 (file)
@@ -334,7 +334,7 @@ IMPULSE(weapon_reload)
 {
        if (this.vehicle) return;
        if (IS_DEAD(this)) return;
-       if (forbidWeaponUse(this)) return;
+       if (weaponLocked(this)) return;
        entity actor = this;
        for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
        {
index ff8928c98ee3499b93bec94be03c5f4fecf660e9..f0237b27ee8b8d55d588fe6386d49deb803d7090 100644 (file)
@@ -1083,15 +1083,23 @@ MUTATOR_HOOKABLE(Player_ChangeTeamKill, EV_Player_ChangeTeamKill);
        /** id */       i(float, MUTATOR_ARGV_0_float) \
        /** status */   i(float, MUTATOR_ARGV_1_float) \
        /** data */     i(string, MUTATOR_ARGV_2_string) \
-    /**/
+       /**/
 MUTATOR_HOOKABLE(URI_GetCallback, EV_URI_GetCallback);
 
+/**
+ * return true to lock weapon (can't be used nor changed) for a player
+ */
+#define EV_LockWeapon(i, o) \
+       /** player */ i(entity, MUTATOR_ARGV_0_entity) \
+       /**/
+MUTATOR_HOOKABLE(LockWeapon, EV_LockWeapon);
+
 /**
  * return true to prevent weapon use for a player
  */
- #define EV_ForbidWeaponUse(i, o) \
-    /** player */ i(entity, MUTATOR_ARGV_0_entity) \
-    /**/
+#define EV_ForbidWeaponUse(i, o) \
+       /** player */ i(entity, MUTATOR_ARGV_0_entity) \
+       /**/
 MUTATOR_HOOKABLE(ForbidWeaponUse, EV_ForbidWeaponUse);
 
 /** called when creating a clone of the player (usually for corpses that stay after the player has re-spawned) */
index ea5bd22551cec73cc63b9578665b9be0dd8bf25f..7f9c6ad0d76c379481cb3613fe3b322b0d7ecdff 100644 (file)
@@ -281,7 +281,7 @@ bool W_SwitchWeapon(entity this, Weapon w, .entity weaponentity)
                        return false;
                }
        }
-       else if(!forbidWeaponUse(this) && CS(this).cvar_cl_weapon_switch_reload)
+       else if(!weaponLocked(this) && CS(this).cvar_cl_weapon_switch_reload)
        {
                entity actor = this;
                w.wr_reload(w, actor, weaponentity);
index e7ab90c39eb2441408dcb86027b8de34e7c377d1..b75881127a219008f56faaad9d086817d922ab4c 100644 (file)
@@ -435,13 +435,20 @@ void weapon_thinkf(entity actor, .entity weaponentity, WFRAME fr, float t, void(
        }
 }
 
-bool forbidWeaponUse(entity player)
+bool weaponUseForbidden(entity player)
+{
+       if (round_handler_IsActive() && !round_handler_IsRoundStarted()) return true;
+       if (MUTATOR_CALLHOOK(ForbidWeaponUse, player)) return true;
+       return false;
+}
+
+bool weaponLocked(entity player)
 {
        if (time < game_starttime && !sv_ready_restart_after_countdown) return true;
        if (player.player_blocked) return true;
        if (game_stopped) return true;
        if (STAT(FROZEN, player)) return true;
-       if (MUTATOR_CALLHOOK(ForbidWeaponUse, player)) return true;
+       if (MUTATOR_CALLHOOK(LockWeapon, player)) return true;
        return false;
 }
 
@@ -459,10 +466,10 @@ void W_WeaponFrame(Player actor, .entity weaponentity)
        int button_atck = PHYS_INPUT_BUTTON_ATCK(actor);
        int button_atck2 = PHYS_INPUT_BUTTON_ATCK2(actor);
 
-       if (round_handler_IsActive() && !round_handler_IsRoundStarted())
+       if (weaponUseForbidden(actor))
                button_atck = button_atck2 = 0; // forbid primary and secondary fire, switching is allowed
 
-       if (forbidWeaponUse(actor))
+       if (weaponLocked(actor))
        {
                if (this.state != WS_CLEAR)
                {
@@ -591,7 +598,7 @@ void W_WeaponFrame(Player actor, .entity weaponentity)
                bool block_weapon = false;
                {
                        bool key_pressed = PHYS_INPUT_BUTTON_HOOK(actor) && !actor.vehicle;
-                       if (round_handler_IsActive() && !round_handler_IsRoundStarted())
+                       if (weaponUseForbidden(actor))
                                key_pressed = false;
 
                        Weapon off = actor.offhand;
index c53b150944425aa1d96fcc84e3ecc239454091f7..91879feb2a9a95548eb6008c500498bc79a07a09 100644 (file)
@@ -12,7 +12,8 @@ void CL_SpawnWeaponentity(entity e, .entity weaponentity);
 
 vector CL_Weapon_GetShotOrg(float wpn);
 
-bool forbidWeaponUse(entity player);
+bool weaponUseForbidden(entity player);
+bool weaponLocked(entity player);
 
 void W_AttachToShotorg(entity actor, .entity weaponentity, entity flash, vector offset);