]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/mutators/mutator/overkill/okmachinegun.qc
Merged Lyberta/URS3 into Lyberta/StandaloneOverkillWeapons.
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mutators / mutator / overkill / okmachinegun.qc
index b08f506a1513ea69e2b4d523e3973fc1534bcaea..d874304432182434b9be139c905ea9a8ae2865f1 100644 (file)
@@ -131,22 +131,67 @@ METHOD(OverkillMachineGun, wr_aim, void(entity thiswep, entity actor, .entity we
 
 METHOD(OverkillMachineGun, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
 {
+       if ((WEP_CVAR_SEC(okmachinegun, refire_type) == 1) && (fire & 2) && (time >= actor.jump_interval))
+       {
+               // Secondary uses it's own refire timer if refire_type is 1.
+               actor.jump_interval = time + WEP_CVAR_SEC(okmachinegun, refire) * W_WeaponRateFactor(actor);
+               // Ugly hack to reuse the fire mode of the blaster.
+               makevectors(actor.v_angle);
+               Weapon oldwep = actor.(weaponentity).m_weapon; // we can't avoid this hack
+               actor.(weaponentity).m_weapon = WEP_BLASTER;
+               W_Blaster_Attack(
+                       actor,
+                       weaponentity,
+                       WEP_BLASTER.m_id | HITTYPE_SECONDARY,
+                       WEP_CVAR_SEC(okmachinegun, shotangle),
+                       WEP_CVAR_SEC(okmachinegun, damage),
+                       WEP_CVAR_SEC(okmachinegun, edgedamage),
+                       WEP_CVAR_SEC(okmachinegun, radius),
+                       WEP_CVAR_SEC(okmachinegun, force),
+                       WEP_CVAR_SEC(okmachinegun, speed),
+                       WEP_CVAR_SEC(okmachinegun, spread),
+                       WEP_CVAR_SEC(okmachinegun, delay),
+                       WEP_CVAR_SEC(okmachinegun, lifetime)
+               );
+               actor.(weaponentity).m_weapon = oldwep;
+               if ((actor.(weaponentity).wframe == WFRAME_IDLE) ||
+                       (actor.(weaponentity).wframe == WFRAME_FIRE2))
+               {
+                       // Set secondary fire animation.
+                       vector a = '0 0 0';
+                       actor.(weaponentity).wframe = WFRAME_FIRE2;
+                       a = actor.(weaponentity).anim_fire2;
+                       a.z *= g_weaponratefactor;
+                       FOREACH_CLIENT(true, LAMBDA(
+                               if (it == actor || (IS_SPEC(it) && it.enemy == actor))
+                               {
+                                       wframe_send(it, actor.(weaponentity), a, true);
+                               }
+                       ));
+                       animdecide_setaction(actor, ANIMACTION_SHOOT, true);
+               }
+       }
        if (WEP_CVAR(okmachinegun, reload_ammo) && actor.(weaponentity).clip_load < min(max(WEP_CVAR(okmachinegun, sustained_ammo), WEP_CVAR(okmachinegun, first_ammo)), WEP_CVAR(okmachinegun, burst_ammo)))
-       { // forced reload
+       {
+               // Forced reload
                thiswep.wr_reload(thiswep, actor, weaponentity);
+               return;
        }
-       else if (WEP_CVAR(okmachinegun, mode) == 1)
+       if (WEP_CVAR(okmachinegun, mode) == 1)
        {
                if(fire & 1) // Primary attack
-               if(weapon_prepareattack(thiswep, actor, weaponentity, false, 0))
                {
+                       if (!weapon_prepareattack(thiswep, actor, weaponentity, false, 0))
+                       {
+                               return;
+                       }
                        actor.(weaponentity).misc_bulletcounter = 0;
                        W_OverkillMachineGun_Attack_Auto(thiswep, actor, weaponentity, fire);
+                       return;
                }
-
-               if (fire & 2) // Secondary attack
+               if ((fire & 2) && (WEP_CVAR_SEC(okmachinegun, refire_type) == 0)) // Secondary attack
                {
-                       if (!weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_SEC(okmachinegun, refire)))
+                       if (!weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(okmachinegun, refire)))
                        {
                                return;
                        }
@@ -174,17 +219,20 @@ METHOD(OverkillMachineGun, wr_think, void(entity thiswep, entity actor, .entity
        }
        else
        {
-               if(fire & 1) // Primary attack
-               if(weapon_prepareattack(thiswep, actor, weaponentity, false, 0))
+               if (fire & 1) // Primary attack
                {
+                       if (!weapon_prepareattack(thiswep, actor, weaponentity, false, 0))
+                       {
+                               return;
+                       }
                        actor.(weaponentity).misc_bulletcounter = 1;
                        W_OverkillMachineGun_Attack(WEP_OVERKILL_MACHINEGUN, WEP_OVERKILL_MACHINEGUN.m_id, actor, weaponentity); // sets attack_finished
                        weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR(okmachinegun, sustained_refire), W_OverkillMachineGun_Attack_Frame);
+                       return;
                }
-
-               if (fire & 2) // Secondary attack
+               if ((fire & 2) && (WEP_CVAR_SEC(okmachinegun, refire_type) == 0)) // Secondary attack
                {
-                       if (!weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_SEC(okmachinegun, refire)))
+                       if (!weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(okmachinegun, refire)))
                        {
                                return;
                        }
@@ -215,17 +263,24 @@ METHOD(OverkillMachineGun, wr_think, void(entity thiswep, entity actor, .entity
 METHOD(OverkillMachineGun, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity))
 {
        float ammo_amount;
-       if(WEP_CVAR(okmachinegun, mode) == 1)
-               ammo_amount = actor.(thiswep.ammo_field) >= WEP_CVAR(okmachinegun, sustained_ammo);
+       if (WEP_CVAR(okmachinegun, mode) == 1)
+       {
+               ammo_amount = GetResourceAmount(actor, thiswep.ammo_type) >= WEP_CVAR(okmachinegun, sustained_ammo);
+       }
        else
-               ammo_amount = actor.(thiswep.ammo_field) >= WEP_CVAR(okmachinegun, first_ammo);
-
-       if(WEP_CVAR(okmachinegun, reload_ammo))
        {
-               if(WEP_CVAR(okmachinegun, mode) == 1)
+               ammo_amount = GetResourceAmount(actor, thiswep.ammo_type) >= WEP_CVAR(okmachinegun, first_ammo);
+       }
+       if (WEP_CVAR(okmachinegun, reload_ammo))
+       {
+               if (WEP_CVAR(okmachinegun, mode) == 1)
+               {
                        ammo_amount += actor.(weaponentity).(weapon_load[WEP_OVERKILL_MACHINEGUN.m_id]) >= WEP_CVAR(okmachinegun, sustained_ammo);
+               }
                else
+               {
                        ammo_amount += actor.(weaponentity).(weapon_load[WEP_OVERKILL_MACHINEGUN.m_id]) >= WEP_CVAR(okmachinegun, first_ammo);
+               }
        }
        return ammo_amount;
 }
@@ -233,17 +288,24 @@ METHOD(OverkillMachineGun, wr_checkammo1, bool(entity thiswep, entity actor, .en
 METHOD(OverkillMachineGun, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
 {
        float ammo_amount;
-       if(WEP_CVAR(okmachinegun, mode) == 1)
-               ammo_amount = actor.(thiswep.ammo_field) >= WEP_CVAR(okmachinegun, burst_ammo);
+       if (WEP_CVAR(okmachinegun, mode) == 1)
+       {
+               ammo_amount = GetResourceAmount(actor, thiswep.ammo_type) >= WEP_CVAR(okmachinegun, burst_ammo);
+       }
        else
-               ammo_amount = actor.(thiswep.ammo_field) >= WEP_CVAR(okmachinegun, first_ammo);
-
-       if(WEP_CVAR(okmachinegun, reload_ammo))
        {
-               if(WEP_CVAR(okmachinegun, mode) == 1)
+               ammo_amount = GetResourceAmount(actor, thiswep.ammo_type) >= WEP_CVAR(okmachinegun, first_ammo);
+       }
+       if (WEP_CVAR(okmachinegun, reload_ammo))
+       {
+               if (WEP_CVAR(okmachinegun, mode) == 1)
+               {
                        ammo_amount += actor.(weaponentity).(weapon_load[WEP_OVERKILL_MACHINEGUN.m_id]) >= WEP_CVAR(okmachinegun, burst_ammo);
+               }
                else
+               {
                        ammo_amount += actor.(weaponentity).(weapon_load[WEP_OVERKILL_MACHINEGUN.m_id]) >= WEP_CVAR(okmachinegun, first_ammo);
+               }
        }
        return ammo_amount;
 }