]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/mutators/mutator/overkill/sv_overkill.qc
Give W_SetupShot a deathtype parameter, fixes some ugly hacks
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mutators / mutator / overkill / sv_overkill.qc
index 9bc39781bace277a70743819d32dda4440b089ac..20216f9283d1333115be8045b3a78c395f24b17e 100644 (file)
@@ -3,49 +3,70 @@
 #include "hmg.qh"
 #include "rpc.qh"
 
-bool autocvar_g_overkill_powerups_replace;
+string autocvar_g_overkill;
 
-bool autocvar_g_overkill_filter_healthmega;
-bool autocvar_g_overkill_filter_armormedium;
-bool autocvar_g_overkill_filter_armorbig;
-bool autocvar_g_overkill_filter_armormega;
+bool autocvar_g_overkill_powerups_replace;
 
-.float ok_item;
+bool autocvar_g_overkill_itemwaypoints = true;
 
 .Weapon ok_lastwep[MAX_WEAPONSLOTS];
 
-void ok_Initialize();
-
-REGISTER_MUTATOR(ok, cvar("g_overkill") && !cvar("g_instagib") && !g_nexball && cvar_string("g_mod_balance") == "Overkill")
+REGISTER_MUTATOR(ok, expr_evaluate(autocvar_g_overkill) && !cvar("g_instagib") && !g_nexball && cvar_string("g_mod_balance") == "Overkill")
 {
        MUTATOR_ONADD
        {
-               ok_Initialize();
+               precache_all_playermodels("models/ok_player/*.dpm");
+
+               if (autocvar_g_overkill_filter_healthmega)
+               {
+                       ITEM_HealthMega.spawnflags |= ITEM_FLAG_MUTATORBLOCKED;
+               }
+               if (autocvar_g_overkill_filter_armormedium)
+               {
+                       ITEM_ArmorMedium.spawnflags |= ITEM_FLAG_MUTATORBLOCKED;
+               }
+               if (autocvar_g_overkill_filter_armorbig)
+               {
+                       ITEM_ArmorBig.spawnflags |= ITEM_FLAG_MUTATORBLOCKED;
+               }
+               if (autocvar_g_overkill_filter_armormega)
+               {
+                       ITEM_ArmorMega.spawnflags |= ITEM_FLAG_MUTATORBLOCKED;
+               }
+
+               WEP_RPC.spawnflags &= ~WEP_FLAG_MUTATORBLOCKED;
+               WEP_HMG.spawnflags &= ~WEP_FLAG_MUTATORBLOCKED;
+
+               WEP_SHOTGUN.mdl = "ok_shotgun";
+               WEP_MACHINEGUN.mdl = "ok_mg";
+               WEP_VORTEX.mdl = "ok_sniper";
        }
 
        MUTATOR_ONREMOVE
        {
+               ITEM_HealthMega.spawnflags &= ~ITEM_FLAG_MUTATORBLOCKED;
+               ITEM_ArmorMedium.spawnflags &= ~ITEM_FLAG_MUTATORBLOCKED;
+               ITEM_ArmorBig.spawnflags &= ~ITEM_FLAG_MUTATORBLOCKED;
+               ITEM_ArmorMega.spawnflags &= ~ITEM_FLAG_MUTATORBLOCKED;
+
                WEP_RPC.spawnflags |= WEP_FLAG_MUTATORBLOCKED;
                WEP_HMG.spawnflags |= WEP_FLAG_MUTATORBLOCKED;
        }
 }
 
 void W_Blaster_Attack(entity, .entity, float, float, float, float, float, float, float, float, float, float);
-spawnfunc(weapon_hmg);
-spawnfunc(weapon_rpc);
 
-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);
@@ -58,20 +79,10 @@ MUTATOR_HOOKFUNCTION(ok, PlayerDamage_Calculate, CBC_ORDER_LAST)
 
 void ok_DropItem(entity this, entity targ)
 {
-       entity e = new(droppedweapon); // hax
+       entity e = spawn();
        e.ok_item = true;
-       e.noalign = true;
-       e.pickup_anyway = true;
-       e.spawnfunc_checked = true;
-       spawnfunc_item_armor_small(e);
-       if (!wasfreed(e)) { // might have been blocked by a mutator
-        set_movetype(e, MOVETYPE_TOSS);
-        e.gravity = 1;
-        e.reset = SUB_Remove;
-        setorigin(e, this.origin + '0 0 32');
-        e.velocity = '0 0 200' + normalize(targ.origin - this.origin) * 500;
-        SUB_SetFade(e, time + 5, 1);
-       }
+       Item_InitializeLoot(e, "item_armor_small", this.origin + '0 0 32',
+               '0 0 200' + normalize(targ.origin - this.origin) * 500, 5);
 }
 
 MUTATOR_HOOKFUNCTION(ok, PlayerDies)
@@ -111,7 +122,7 @@ MUTATOR_HOOKFUNCTION(ok, ForbidThrowCurrentWeapon)
 
 MUTATOR_HOOKFUNCTION(ok, PlayerPreThink)
 {
-       if(gameover)
+       if(game_stopped)
                return;
 
        entity player = M_ARGV(0, entity);
@@ -119,27 +130,9 @@ MUTATOR_HOOKFUNCTION(ok, PlayerPreThink)
        if(IS_DEAD(player) || !IS_PLAYER(player) || STAT(FROZEN, player))
                return;
 
-       for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
-       {
-               .entity weaponentity = weaponentities[slot];
-               entity thiswep = player.(weaponentity);
-
-               if(player.ok_lastwep[slot] && player.ok_lastwep[slot] != WEP_Null)
-               {
-                       Weapon newwep = player.ok_lastwep[slot];
-                       if(player.ok_lastwep[slot] == WEP_HMG)
-                               newwep = WEP_MACHINEGUN;
-                       if(player.ok_lastwep[slot] == WEP_RPC)
-                               newwep = WEP_VORTEX;
-                       thiswep.m_switchweapon = newwep;
-                       player.ok_lastwep[slot] = WEP_Null;
-               }
-       }
-
-       if(PHYS_INPUT_BUTTON_ATCK2(player))
-       if( !forbidWeaponUse(player) || player.weapon_blocked // allow if weapon is blocked
+       if(PHYS_INPUT_BUTTON_ATCK2(player) && time >= player.jump_interval)
+       if( !forbidWeaponUse(player)
                || (round_handler_IsActive() && !round_handler_IsRoundStarted()) )
-       if(time >= player.jump_interval)
        {
                player.jump_interval = time + WEP_CVAR_PRI(blaster, refire) * W_WeaponRateFactor(player);
                makevectors(player.v_angle);
@@ -151,8 +144,6 @@ MUTATOR_HOOKFUNCTION(ok, PlayerPreThink)
                        if(player.(weaponentity).m_weapon == WEP_Null && slot != 0)
                                continue;
 
-                       Weapon oldwep = player.(weaponentity).m_weapon;
-                       player.(weaponentity).m_weapon = WEP_BLASTER;
                        W_Blaster_Attack(
                                player,
                                weaponentity,
@@ -167,80 +158,75 @@ MUTATOR_HOOKFUNCTION(ok, PlayerPreThink)
                                WEP_CVAR_SEC(vaporizer, delay),
                                WEP_CVAR_SEC(vaporizer, lifetime)
                        );
-                       player.(weaponentity).m_weapon = oldwep;
                }
        }
 
        PHYS_INPUT_BUTTON_ATCK2(player) = false;
 }
 
-MUTATOR_HOOKFUNCTION(ok, PlayerSpawn)
+MUTATOR_HOOKFUNCTION(ok, ForbidRandomStartWeapons)
+{
+       return true;
+}
+
+MUTATOR_HOOKFUNCTION(ok, PlayerWeaponSelect)
 {
        entity player = M_ARGV(0, entity);
 
-       // if player changed their weapon while dead, don't switch to their death weapon
-       if(player.impulse)
+       for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
        {
-               for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
+               .entity weaponentity = weaponentities[slot];
+               entity thiswep = player.(weaponentity);
+
+               if(player.ok_lastwep[slot] && player.ok_lastwep[slot] != WEP_Null)
                {
+                       Weapon newwep = player.ok_lastwep[slot];
+                       if(player.ok_lastwep[slot] == WEP_HMG)
+                               newwep = WEP_MACHINEGUN;
+                       if(player.ok_lastwep[slot] == WEP_RPC)
+                               newwep = WEP_VORTEX;
+                       thiswep.m_switchweapon = newwep;
                        player.ok_lastwep[slot] = WEP_Null;
                }
        }
 }
 
-void self_spawnfunc_weapon_hmg(entity this) { spawnfunc_weapon_hmg(this); }
-void self_spawnfunc_weapon_rpc(entity this) { spawnfunc_weapon_rpc(this); }
-
-MUTATOR_HOOKFUNCTION(ok, OnEntityPreSpawn)
+bool ok_HandleItemWaypoints(entity e)
 {
-       entity ent = M_ARGV(0, entity);
+       if(!autocvar_g_overkill_itemwaypoints)
+               return false; // don't handle it
 
-       if(autocvar_g_powerups)
-       if(autocvar_g_overkill_powerups_replace)
+       switch(e.itemdef)
        {
-               if(ent.classname == "item_strength")
-               {
-                       entity wep = new(weapon_hmg);
-                       setorigin(wep, ent.origin);
-                       setmodel(wep, MDL_OK_HMG);
-                       wep.ok_item = true;
-                       wep.noalign = ent.noalign;
-                       wep.cnt = ent.cnt;
-                       wep.team = ent.team;
-                       wep.respawntime = g_pickup_respawntime_superweapon;
-                       wep.pickup_anyway = true;
-                       wep.spawnfunc_checked = true;
-                       setthink(wep, self_spawnfunc_weapon_hmg);
-                       wep.nextthink = time + 0.1;
-                       return true;
-               }
-
-               if(ent.classname == "item_invincible")
-               {
-                       entity wep = new(weapon_rpc);
-                       setorigin(wep, ent.origin);
-                       setmodel(wep, MDL_OK_RPC);
-                       wep.ok_item = true;
-                       wep.noalign = ent.noalign;
-                       wep.cnt = ent.cnt;
-                       wep.team = ent.team;
-                       wep.respawntime = g_pickup_respawntime_superweapon;
-                       wep.pickup_anyway = true;
-                       wep.spawnfunc_checked = true;
-                       setthink(wep, self_spawnfunc_weapon_rpc);
-                       wep.nextthink = time + 0.1;
-                       return true;
-               }
+               case ITEM_HealthMega: return true;
+               case ITEM_ArmorMedium: return true;
+               case ITEM_ArmorBig: return true;
+               case ITEM_ArmorMega: return true;
        }
+
+       return false;
+}
+
+MUTATOR_HOOKFUNCTION(ok, Item_RespawnCountdown)
+{
+       entity item = M_ARGV(0, entity);
+       return ok_HandleItemWaypoints(item);
+}
+
+MUTATOR_HOOKFUNCTION(ok, Item_ScheduleRespawn)
+{
+       entity item = M_ARGV(0, entity);
+       return ok_HandleItemWaypoints(item);
 }
 
 MUTATOR_HOOKFUNCTION(ok, FilterItem)
 {
        entity item = M_ARGV(0, entity);
 
-       if(item.ok_item)
+       if (item.ok_item)
+       {
                return false;
-
+       }
        switch(item.itemdef)
        {
                case ITEM_HealthMega: return autocvar_g_overkill_filter_healthmega;
@@ -248,7 +234,38 @@ MUTATOR_HOOKFUNCTION(ok, FilterItem)
                case ITEM_ArmorBig: return autocvar_g_overkill_filter_armorbig;
                case ITEM_ArmorMega: return autocvar_g_overkill_filter_armormega;
        }
-
+       if (!autocvar_g_powerups || !autocvar_g_overkill_powerups_replace)
+       {
+               return true;
+       }
+       if (item.classname == "item_strength")
+       {
+               entity wep = new(weapon_hmg);
+               setorigin(wep, item.origin);
+               wep.ok_item = true;
+               wep.noalign = Item_ShouldKeepPosition(item);
+               wep.cnt = item.cnt;
+               wep.team = item.team;
+               wep.respawntime = g_pickup_respawntime_superweapon;
+               wep.pickup_anyway = true;
+               wep.spawnfunc_checked = true;
+               Item_Initialize(wep, "weapon_hmg");
+               return true;
+       }
+       else if (item.classname == "item_shield")
+       {
+               entity wep = new(weapon_rpc);
+               setorigin(wep, item.origin);
+               wep.ok_item = true;
+               wep.noalign = Item_ShouldKeepPosition(item);
+               wep.cnt = item.cnt;
+               wep.team = item.team;
+               wep.respawntime = g_pickup_respawntime_superweapon;
+               wep.pickup_anyway = true;
+               wep.spawnfunc_checked = true;
+               Item_Initialize(wep, "weapon_rpc");
+               return true;
+       }
        return true;
 }
 
@@ -284,26 +301,3 @@ MUTATOR_HOOKFUNCTION(ok, SetModname)
        M_ARGV(0, string) = "Overkill";
        return true;
 }
-
-void ok_SetCvars()
-{
-       // hack to force overkill playermodels
-       cvar_settemp("sv_defaultcharacter", "1");
-       cvar_settemp("sv_defaultplayermodel", "models/ok_player/okrobot1.dpm models/ok_player/okrobot2.dpm models/ok_player/okrobot3.dpm models/ok_player/okrobot4.dpm models/ok_player/okmale1.dpm models/ok_player/okmale2.dpm models/ok_player/okmale3.dpm models/ok_player/okmale4.dpm");
-       cvar_settemp("sv_defaultplayermodel_red", "models/ok_player/okrobot1.dpm models/ok_player/okrobot2.dpm models/ok_player/okrobot3.dpm models/ok_player/okrobot4.dpm");
-       cvar_settemp("sv_defaultplayermodel_blue", "models/ok_player/okmale1.dpm models/ok_player/okmale2.dpm models/ok_player/okmale3.dpm models/ok_player/okmale4.dpm");
-}
-
-void ok_Initialize()
-{
-       ok_SetCvars();
-
-       precache_all_playermodels("models/ok_player/*.dpm");
-
-       WEP_RPC.spawnflags &= ~WEP_FLAG_MUTATORBLOCKED;
-       WEP_HMG.spawnflags &= ~WEP_FLAG_MUTATORBLOCKED;
-
-       WEP_SHOTGUN.mdl = "ok_shotgun";
-       WEP_MACHINEGUN.mdl = "ok_mg";
-       WEP_VORTEX.mdl = "ok_sniper";
-}