]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/weapons/weapon/vaporizer.qc
micro-optimization chore: in for-loops change all post-{in,de}crements to pre-{in...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / weapon / vaporizer.qc
index 2a0dd7cef856978c8c6a0aae3de812ff64f89cd7..4066efc4e00d0d346bc662f2088829ec7228972c 100644 (file)
@@ -1,6 +1,8 @@
 #include "vaporizer.qh"
 
+#ifdef GAMEQC
 REGISTER_NET_TEMP(TE_CSQC_VAPORBEAMPARTICLE)
+#endif
 
 #if defined(SVQC)
 void SendCSQCVaporizerBeamParticle(entity player, int hit) {
@@ -148,7 +150,15 @@ void W_Vaporizer_Attack(Weapon thiswep, entity actor, .entity weaponentity)
        W_DecreaseAmmo(thiswep, actor, ((autocvar_g_instagib) ? 1 : WEP_CVAR_PRI(vaporizer, ammo)), weaponentity);
 }
 
-void W_RocketMinsta_Laser_Explode (entity this, entity directhitentity)
+void W_RocketMinsta_Laser_Damage(entity this, entity directhitentity)
+{
+       int laser_count = max(1, this.rm_laser_count);
+       float laser_force = autocvar_g_rm_laser_force / laser_count;
+       float laser_damage = autocvar_g_rm_laser_damage / laser_count;
+       RadiusDamage(this, this.realowner, laser_damage, laser_damage, autocvar_g_rm_laser_radius, NULL, NULL, laser_force, this.projectiledeathtype, this.weaponentity_fld, directhitentity);
+}
+
+void W_RocketMinsta_Laser_Explode(entity this, entity directhitentity)
 {
        if(directhitentity.takedamage == DAMAGE_AIM)
                if(IS_PLAYER(directhitentity))
@@ -159,7 +169,7 @@ void W_RocketMinsta_Laser_Explode (entity this, entity directhitentity)
 
        this.event_damage = func_null;
        this.takedamage = DAMAGE_NO;
-       RadiusDamage (this, this.realowner, this.rm_damage, this.rm_edmg, autocvar_g_rm_laser_radius, NULL, NULL, this.rm_force, this.projectiledeathtype, this.weaponentity_fld, directhitentity);
+       W_RocketMinsta_Laser_Damage(this, directhitentity);
        delete(this);
 }
 
@@ -172,122 +182,74 @@ void W_RocketMinsta_Laser_Touch(entity this, entity toucher)
 {
        PROJECTILE_TOUCH(this, toucher);
        //W_RocketMinsta_Laser_Explode ();
-       RadiusDamage(this, this.realowner, this.rm_damage, this.rm_edmg, autocvar_g_rm_laser_radius, NULL, NULL, this.rm_force, this.projectiledeathtype, this.weaponentity_fld, toucher);
+       W_RocketMinsta_Laser_Damage(this, toucher);
        delete(this);
 }
 
-void W_RocketMinsta_Attack2(entity actor, .entity weaponentity)
+// mode 0 fires many projectiles
+// mode 1 fires 1 projectile
+void W_RocketMinsta_Attack(entity actor, .entity weaponentity, int mode)
 {
        makevectors(actor.v_angle);
 
        entity proj;
-       float counter = 0;
-       float total = autocvar_g_rm_laser_count;
-       float spread = autocvar_g_rm_laser_spread;
-       float rndspread = autocvar_g_rm_laser_spread_random;
-
-       W_SetupShot_ProjectileSize (actor, weaponentity, '0 0 -3', '0 0 -3', false, 2, SND_CRYLINK_FIRE, CH_WEAPON_A, autocvar_g_rm_laser_damage, WEP_ELECTRO.m_id);
+       int laser_count = max(1, autocvar_g_rm_laser_count);
+       int total = (mode == 0) ? laser_count : 1;
+       Sound snd = (mode == 0) ? SND_CRYLINK_FIRE : SND_ELECTRO_FIRE2;
+       W_SetupShot_ProjectileSize(actor, weaponentity, '0 0 -3', '0 0 -3', false, 2, snd, CH_WEAPON_A, autocvar_g_rm_laser_damage, WEP_ELECTRO.m_id);
 
        // uses electro effects
        W_MuzzleFlash(WEP_ELECTRO, actor, weaponentity, w_shotorg, w_shotdir);
 
-    while(counter < total)
+       for (int counter = 0; counter < total; ++counter)
        {
-        proj = new(plasma_prim);
-        proj.owner = proj.realowner = actor;
-        proj.bot_dodge = true;
-        proj.bot_dodgerating = autocvar_g_rm_laser_damage;
-        proj.use = W_RocketMinsta_Laser_Explode_use;
-        setthink(proj, adaptor_think2use_hittype_splash);
-        proj.nextthink = time + autocvar_g_rm_laser_lifetime;
-        PROJECTILE_MAKETRIGGER(proj);
-        proj.projectiledeathtype = WEP_ELECTRO.m_id;
-        proj.weaponentity_fld = weaponentity;
-        setorigin(proj, w_shotorg);
-
-               proj.rm_force = autocvar_g_rm_laser_force / total;
-               proj.rm_damage = autocvar_g_rm_laser_damage / total;
-               proj.rm_edmg = proj.rm_damage;
-
-        //W_SetupProjectileVelocity(proj, autocvar_g_rm_laser_speed, spread * (rndspread ? random() : 1) * autocvar_g_rm_laser_speed);
-
-        set_movetype(proj, MOVETYPE_BOUNCEMISSILE);
-        //W_SETUPPROJECTILEVELOCITY(proj, g_balance_minstanex_laser);
-               proj.velocity = (w_shotdir + (((counter + 0.5) / total) * 2 - 1) * v_right * (spread * (rndspread ? random() : 1))) * cvar("g_rm_laser_speed");
-               proj.velocity_z = proj.velocity_z + cvar("g_rm_laser_zspread") * (random() - 0.5);
+               proj = new(plasma_prim);
+               proj.owner = proj.realowner = actor;
+               proj.bot_dodge = true;
+               proj.bot_dodgerating = autocvar_g_rm_laser_damage;
+               proj.use = W_RocketMinsta_Laser_Explode_use;
+               setthink(proj, adaptor_think2use_hittype_splash);
+               proj.nextthink = time + autocvar_g_rm_laser_lifetime;
+               PROJECTILE_MAKETRIGGER(proj);
+               proj.projectiledeathtype = WEP_ELECTRO.m_id;
+               proj.weaponentity_fld = weaponentity;
+               setorigin(proj, w_shotorg);
+
+               proj.rm_laser_count = total;
+
+               //W_SetupProjectileVelocity(proj, autocvar_g_rm_laser_speed, spread * (rndspread ? random() : 1) * autocvar_g_rm_laser_speed);
+
+               set_movetype(proj, MOVETYPE_BOUNCEMISSILE);
+               if (mode == 0)
+               {
+                       float spread = autocvar_g_rm_laser_spread * (autocvar_g_rm_laser_spread_random ? random() : 1);
+                       //W_SETUPPROJECTILEVELOCITY(proj, g_balance_minstanex_laser);
+                       proj.velocity = (w_shotdir + (((counter + 0.5) / total) * 2 - 1) * v_right * spread) * cvar("g_rm_laser_speed");
+                       proj.velocity.z += cvar("g_rm_laser_zspread") * (random() - 0.5);
+               }
+               else
+                       proj.velocity = w_shotdir * autocvar_g_rm_laser_speed;
                proj.velocity = W_CalculateProjectileVelocity(actor, actor.velocity, proj.velocity, true);
-        proj.angles = vectoangles(proj.velocity);
-        settouch(proj, W_RocketMinsta_Laser_Touch);
-        setsize(proj, '0 0 -3', '0 0 -3');
-        proj.flags = FL_PROJECTILE;
-        IL_PUSH(g_projectiles, proj);
-        IL_PUSH(g_bot_dodge, proj);
-        proj.missile_flags = MIF_SPLASH;
-
-        CSQCProjectile(proj, true, PROJECTILE_ROCKETMINSTA_LASER, true);
-
-        MUTATOR_CALLHOOK(EditProjectile, actor, proj);
-        counter++;
-    }
-}
+               proj.angles = vectoangles(proj.velocity);
+               settouch(proj, W_RocketMinsta_Laser_Touch);
+               setsize(proj, '0 0 -3', '0 0 -3');
+               proj.flags = FL_PROJECTILE;
+               IL_PUSH(g_projectiles, proj);
+               IL_PUSH(g_bot_dodge, proj);
+               proj.missile_flags = MIF_SPLASH;
 
-void W_RocketMinsta_Attack3 (entity actor, .entity weaponentity)
-{
-       makevectors(actor.v_angle);
+               CSQCProjectile(proj, true, PROJECTILE_ROCKETMINSTA_LASER, true);
 
-       entity proj;
-       float counter = 0;
-       float total = 1;
-
-       W_SetupShot_ProjectileSize (actor, weaponentity, '0 0 -3', '0 0 -3', false, 2, SND_ELECTRO_FIRE2, CH_WEAPON_A, autocvar_g_rm_laser_damage, WEP_ELECTRO.m_id);
-
-       // uses electro effects
-       W_MuzzleFlash(WEP_ELECTRO, actor, weaponentity, w_shotorg, w_shotdir);
-
-    while(counter < total)
-       {
-        proj = new(plasma_prim);
-        proj.owner = proj.realowner = actor;
-        proj.bot_dodge = true;
-        proj.bot_dodgerating = autocvar_g_rm_laser_damage;
-        proj.use = W_RocketMinsta_Laser_Explode_use;
-        setthink(proj, adaptor_think2use_hittype_splash);
-        proj.nextthink = time + autocvar_g_rm_laser_lifetime;
-        PROJECTILE_MAKETRIGGER(proj);
-        proj.projectiledeathtype = WEP_ELECTRO.m_id;
-        proj.weaponentity_fld = weaponentity;
-        setorigin(proj, w_shotorg);
-
-               proj.rm_force = autocvar_g_rm_laser_force / total;
-               proj.rm_damage = autocvar_g_rm_laser_damage / total;
-               proj.rm_edmg = proj.rm_damage;
-
-        //W_SetupProjectileVelocity(proj, autocvar_g_rm_laser_speed, spread * (rndspread ? random() : 1) * autocvar_g_rm_laser_speed);
-
-        set_movetype(proj, MOVETYPE_BOUNCEMISSILE);
-               proj.velocity = w_shotdir * autocvar_g_rm_laser_speed;
-               proj.velocity = W_CalculateProjectileVelocity(actor, actor.velocity, proj.velocity, true);
-        proj.angles = vectoangles(proj.velocity);
-        settouch(proj, W_RocketMinsta_Laser_Touch);
-        setsize(proj, '0 0 -3', '0 0 -3');
-        proj.flags = FL_PROJECTILE;
-        IL_PUSH(g_projectiles, proj);
-        IL_PUSH(g_bot_dodge, proj);
-        proj.missile_flags = MIF_SPLASH;
-
-        CSQCProjectile(proj, true, PROJECTILE_ROCKETMINSTA_LASER, true);
-
-        MUTATOR_CALLHOOK(EditProjectile, actor, proj);
-        counter++;
-    }
+               MUTATOR_CALLHOOK(EditProjectile, actor, proj);
+       }
 }
 
 METHOD(Vaporizer, wr_aim, void(entity thiswep, entity actor, .entity weaponentity))
 {
     if((actor.items & IT_UNLIMITED_AMMO) || GetResource(actor, thiswep.ammo_type) > 0)
-        PHYS_INPUT_BUTTON_ATCK(actor) = bot_aim(actor, weaponentity, 1000000, 0, 1, false);
+        PHYS_INPUT_BUTTON_ATCK(actor) = bot_aim(actor, weaponentity, 1000000, 0, 1, false, true);
     else
-        PHYS_INPUT_BUTTON_ATCK2(actor) = bot_aim(actor, weaponentity, WEP_CVAR_SEC(vaporizer, speed), 0, WEP_CVAR_SEC(vaporizer, lifetime), false); // WEAPONTODO: replace with proper vaporizer cvars
+        PHYS_INPUT_BUTTON_ATCK2(actor) = bot_aim(actor, weaponentity, WEP_CVAR_SEC(vaporizer, speed), 0, WEP_CVAR_SEC(vaporizer, lifetime), false, true); // WEAPONTODO: replace with proper vaporizer cvars
 }
 METHOD(Vaporizer, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
 {
@@ -295,8 +257,12 @@ METHOD(Vaporizer, wr_think, void(entity thiswep, entity actor, .entity weaponent
     // if the laser uses load, we also consider its ammo for reloading
     if(WEP_CVAR(vaporizer, reload_ammo) && WEP_CVAR_SEC(vaporizer, ammo) && actor.(weaponentity).clip_load < min(vaporizer_ammo, WEP_CVAR_SEC(vaporizer, ammo))) { // forced reload
         thiswep.wr_reload(thiswep, actor, weaponentity);
+        actor.(weaponentity).hagar_load = false; // rocket minsta exclusive var
+        return;
     } else if(WEP_CVAR(vaporizer, reload_ammo) && actor.(weaponentity).clip_load < vaporizer_ammo) { // forced reload
         thiswep.wr_reload(thiswep, actor, weaponentity);
+        actor.(weaponentity).hagar_load = false; // rocket minsta exclusive var
+        return;
     }
     if((fire & 1) && (GetResource(actor, RES_CELLS) || !autocvar_g_rm) && !weaponLocked(actor))
     {
@@ -311,20 +277,21 @@ METHOD(Vaporizer, wr_think, void(entity thiswep, entity actor, .entity weaponent
         if((autocvar_g_rm && autocvar_g_rm_laser) || autocvar_g_rm_laser == 2)
         {
             bool rapid = autocvar_g_rm_laser_rapid;
-            if(actor.(weaponentity).jump_interval <= time && !actor.(weaponentity).held_down)
+            //hagar_load was previously named held_down
+            if(actor.(weaponentity).jump_interval <= time && !actor.(weaponentity).hagar_load)
             {
                 if(rapid)
-                    actor.(weaponentity).held_down = true;
+                    actor.(weaponentity).hagar_load = true;
                 actor.(weaponentity).jump_interval = time + autocvar_g_rm_laser_refire;
                 actor.(weaponentity).jump_interval2 = time + autocvar_g_rm_laser_rapid_delay;
                 impressive_hits = 0;
-                W_RocketMinsta_Attack2(actor, weaponentity);
+                W_RocketMinsta_Attack(actor, weaponentity, 0);
             }
-            else if(rapid && actor.(weaponentity).jump_interval2 <= time && actor.(weaponentity).held_down)
+            else if(rapid && actor.(weaponentity).jump_interval2 <= time && actor.(weaponentity).hagar_load)
             {
                 actor.(weaponentity).jump_interval2 = time + autocvar_g_rm_laser_rapid_refire;
                 impressive_hits = 0;
-                W_RocketMinsta_Attack3(actor, weaponentity);
+                W_RocketMinsta_Attack(actor, weaponentity, 1);
                 //weapon_thinkf(actor, WFRAME_FIRE2, autocvar_g_rm_laser_rapid_animtime, w_ready);
             }
         }
@@ -337,14 +304,15 @@ METHOD(Vaporizer, wr_think, void(entity thiswep, entity actor, .entity weaponent
             if(WEP_CVAR_SEC(vaporizer, ammo))
                 W_DecreaseAmmo(thiswep, actor, WEP_CVAR_SEC(vaporizer, ammo), weaponentity);
 
-            BLASTER_SECONDARY_ATTACK(vaporizer, actor, weaponentity);
+            makevectors(actor.v_angle);
+            W_Blaster_Attack(actor, weaponentity, WEP_BLASTER.m_id | HITTYPE_SECONDARY);
 
             // now do normal refire
             weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(vaporizer, animtime), w_ready);
         }
     }
     else
-        actor.(weaponentity).held_down = false;
+        actor.(weaponentity).hagar_load = false;
 }
 METHOD(Vaporizer, wr_setup, void(entity thiswep, entity actor, .entity weaponentity))
 {
@@ -394,7 +362,7 @@ METHOD(Vaporizer, wr_killmessage, Notification(entity thiswep))
 
 METHOD(Vaporizer, wr_impacteffect, void(entity thiswep, entity actor))
 {
-    vector org2 = w_org + w_backoff * 6;
+    vector org2 = w_org + w_backoff * 2;
     if(w_deathtype & HITTYPE_SECONDARY)
     {
         pointparticles(EFFECT_BLASTER_IMPACT, org2, w_backoff * 1000, 1);