Merge branch 'martin-t/ok_weap' into 'master'
authorMario <zacjardine@y7mail.com>
Mon, 2 Jan 2017 08:05:02 +0000 (08:05 +0000)
committerMario <zacjardine@y7mail.com>
Mon, 2 Jan 2017 08:05:02 +0000 (08:05 +0000)
overkill: take into account last weapon held when switching while dead

Closes #1728

See merge request !400

1  2 
qcsrc/common/mutators/mutator/overkill/sv_overkill.qc
qcsrc/server/mutators/events.qh

@@@ -92,17 -92,18 +92,17 @@@ float ok_CheckWeaponCharge(entity ent, 
        return (ent.ammo_charge[wep] >= cvar(sprintf("g_overkill_ammo_decharge_%s", wepent.netname)));
  }
  
 -MUTATOR_HOOKFUNCTION(ok, PlayerDamage_Calculate, CBC_ORDER_LAST)
 +MUTATOR_HOOKFUNCTION(ok, Damage_Calculate, CBC_ORDER_LAST)
  {
        entity frag_attacker = M_ARGV(1, entity);
        entity frag_target = M_ARGV(2, entity);
        float frag_deathtype = M_ARGV(3, float);
  
 -      if(IS_PLAYER(frag_attacker) && IS_PLAYER(frag_target))
 +      if(IS_PLAYER(frag_attacker) && (IS_PLAYER(frag_target) || IS_VEHICLE(frag_target) || IS_TURRET(frag_target)))
        if(DEATH_ISWEAPON(frag_deathtype, WEP_BLASTER))
        {
                if(frag_attacker != frag_target)
 -              if(frag_target.health > 0)
 -              if(STAT(FROZEN, frag_target) == 0)
 +              if(!STAT(FROZEN, frag_target))
                if(!IS_DEAD(frag_target))
                {
                        Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_SECONDARY_NODAMAGE);
@@@ -171,17 -172,6 +171,6 @@@ MUTATOR_HOOKFUNCTION(ok, PlayerPreThink
        if(IS_DEAD(player) || !IS_PLAYER(player) || STAT(FROZEN, player))
                return;
  
-       if(player.ok_lastwep)
-       {
-               Weapon newwep = Weapons_from(player.ok_lastwep);
-               if(player.ok_lastwep == WEP_HMG.m_id)
-                       newwep = WEP_MACHINEGUN;
-               if(player.ok_lastwep == WEP_RPC.m_id)
-                       newwep = WEP_VORTEX;
-               PS(player).m_switchweapon = newwep;
-               player.ok_lastwep = 0;
-       }
        ok_IncreaseCharge(player, PS(player).m_weapon.m_id);
  
        if(PHYS_INPUT_BUTTON_ATCK2(player))
@@@ -248,10 -238,22 +237,22 @@@ MUTATOR_HOOKFUNCTION(ok, PlayerSpawn
        }
        else
                player.ok_use_ammocharge = 0;
+ }
  
-       // if player changed their weapon while dead, don't switch to their death weapon
-       if(player.impulse)
+ MUTATOR_HOOKFUNCTION(ok, PlayerWeaponSelect)
+ {
+       entity player = M_ARGV(0, entity);
+       if(player.ok_lastwep)
+       {
+               Weapon newwep = Weapons_from(player.ok_lastwep);
+               if(player.ok_lastwep == WEP_HMG.m_id)
+                       newwep = WEP_MACHINEGUN;
+               if(player.ok_lastwep == WEP_RPC.m_id)
+                       newwep = WEP_VORTEX;
+               PS(player).m_switchweapon = newwep;
                player.ok_lastwep = 0;
+       }
  }
  
  void self_spawnfunc_weapon_hmg(entity this) { spawnfunc_weapon_hmg(this); }
@@@ -280,7 -282,8 +281,7 @@@ MUTATOR_HOOKFUNCTION(ok, OnEntityPreSpa
                        wep.nextthink = time + 0.1;
                        return true;
                }
 -
 -              if(ent.classname == "item_invincible")
 +              else if(ent.classname == "item_invincible")
                {
                        entity wep = new(weapon_rpc);
                        setorigin(wep, ent.origin);
@@@ -31,6 -31,12 +31,12 @@@ MUTATOR_HOOKABLE(ForbidSpawn, EV_Forbid
      /**/
  MUTATOR_HOOKABLE(PlayerSpawn, EV_PlayerSpawn);
  
+ /** called after a player's weapon is chosen so it can be overriden here */
+ #define EV_PlayerWeaponSelect(i, o) \
+       /** player spawning */ i(entity, MUTATOR_ARGV_0_entity) \
+     /**/
+ MUTATOR_HOOKABLE(PlayerWeaponSelect, EV_PlayerWeaponSelect);
  /** called in reset_map */
  #define EV_reset_map_global(i, o) \
      /**/
@@@ -351,7 -357,7 +357,7 @@@ MUTATOR_HOOKABLE(PlayerDamage_SplitHeal
   * called to adjust damage and force values which are applied to the player, used for e.g. strength damage/force multiplier
   * i'm not sure if I should change this around slightly (Naming of the entities, and also how they're done in g_damage).
   */
 -#define EV_PlayerDamage_Calculate(i, o) \
 +#define EV_Damage_Calculate(i, o) \
      /** inflictor             */ i(entity, MUTATOR_ARGV_0_entity) \
      /** attacker      */ i(entity, MUTATOR_ARGV_1_entity) \
      /** target                */ i(entity, MUTATOR_ARGV_2_entity) \
      /** force           */ i(vector, MUTATOR_ARGV_6_vector) \
      /** force                         */ o(vector, MUTATOR_ARGV_6_vector) \
      /**/
 -MUTATOR_HOOKABLE(PlayerDamage_Calculate, EV_PlayerDamage_Calculate);
 +MUTATOR_HOOKABLE(Damage_Calculate, EV_Damage_Calculate);
  
  /**
   * Called when a player is damaged