]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/weapons/weapon/vortex.qc
Merge branch 'master' into Mario/bulldozer
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / weapon / vortex.qc
index e9e659e0c9ed2a61b5976a64ff3a0838d9c16acb..8a90679b81a2690428328e79dd4598ccf40ce183 100644 (file)
@@ -13,7 +13,7 @@ CLASS(Vortex, Weapon)
 /* crosshair */ ATTRIB(Vortex, w_crosshair_size, float, 0.65);
 /* wepimg    */ ATTRIB(Vortex, model2, string, "weaponnex");
 /* refname   */ ATTRIB(Vortex, netname, string, "vortex");
-/* wepname   */ ATTRIB(Vortex, message, string, _("Vortex"));
+/* wepname   */ ATTRIB(Vortex, m_name, string, _("Vortex"));
 ENDCLASS(Vortex)
 REGISTER_WEAPON(VORTEX, NEW(Vortex));
 
@@ -60,15 +60,14 @@ VORTEX_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
 #endif
 #endif
 #ifdef IMPLEMENTATION
-#ifdef SVQC
-void spawnfunc_weapon_vortex(void) { weapon_defaultspawnfunc(WEP_VORTEX.m_id); }
-void spawnfunc_weapon_nex(void) { spawnfunc_weapon_vortex(); }
 
+REGISTER_NET_TEMP(TE_CSQC_VORTEXBEAMPARTICLE)
+
+#if defined(SVQC)
 void SendCSQCVortexBeamParticle(float charge) {
        vector v;
        v = WarpZone_UnTransformOrigin(WarpZone_trace_transform, trace_endpos);
-       WriteByte(MSG_BROADCAST, SVC_TEMPENTITY);
-       WriteByte(MSG_BROADCAST, TE_CSQC_VORTEXBEAMPARTICLE);
+       WriteHeader(MSG_BROADCAST, TE_CSQC_VORTEXBEAMPARTICLE);
        WriteCoord(MSG_BROADCAST, w_shotorg.x);
        WriteCoord(MSG_BROADCAST, w_shotorg.y);
        WriteCoord(MSG_BROADCAST, w_shotorg.z);
@@ -77,8 +76,35 @@ void SendCSQCVortexBeamParticle(float charge) {
        WriteCoord(MSG_BROADCAST, v.z);
        WriteByte(MSG_BROADCAST, bound(0, 255 * charge, 255));
 }
+#elif defined(CSQC)
+NET_HANDLE(TE_CSQC_VORTEXBEAMPARTICLE, bool isNew)
+{
+       vector shotorg, endpos;
+       float charge;
+       shotorg.x = ReadCoord(); shotorg.y = ReadCoord(); shotorg.z = ReadCoord();
+       endpos.x = ReadCoord(); endpos.y = ReadCoord(); endpos.z = ReadCoord();
+       charge = ReadByte() / 255.0;
+
+       pointparticles(EFFECT_VORTEX_MUZZLEFLASH, shotorg, normalize(endpos - shotorg) * 1000, 1);
+
+       //draw either the old v2.3 beam or the new beam
+       charge = sqrt(charge); // divide evenly among trail spacing and alpha
+       particles_alphamin = particles_alphamax = particles_fade = charge;
+
+       if(!MUTATOR_CALLHOOK(Particles_VortexBeam, shotorg, endpos))
+       if(autocvar_cl_particles_oldvortexbeam && (getstati(STAT_ALLOW_OLDVORTEXBEAM) || isdemo()))
+               WarpZone_TrailParticles_WithMultiplier(world, particleeffectnum(EFFECT_VORTEX_BEAM_OLD), shotorg, endpos, 1, PARTICLES_USEALPHA | PARTICLES_USEFADE);
+       else
+               WarpZone_TrailParticles_WithMultiplier(world, particleeffectnum(EFFECT_VORTEX_BEAM), shotorg, endpos, 1, PARTICLES_USEALPHA | PARTICLES_USEFADE);
+       return true;
+}
+#endif
 
-void W_Vortex_Attack(float issecondary)
+#ifdef SVQC
+spawnfunc(weapon_vortex) { weapon_defaultspawnfunc(this, WEP_VORTEX); }
+spawnfunc(weapon_nex) { spawnfunc_weapon_vortex(this); }
+
+void W_Vortex_Attack(Weapon thiswep, float issecondary)
 {SELFPARAM();
        float mydmg, myforce, mymindist, mymaxdist, myhalflife, myforcehalflife, myammo, charge;
 
@@ -128,12 +154,12 @@ void W_Vortex_Attack(float issecondary)
        //beam and muzzle flash done on client
        SendCSQCVortexBeamParticle(charge);
 
-       W_DecreaseAmmo(myammo);
+       W_DecreaseAmmo(thiswep, self, myammo);
 }
 
 .float vortex_chargepool_pauseregen_finished;
 
-               METHOD(Vortex, wr_aim, bool(entity thiswep))
+               METHOD(Vortex, wr_aim, void(entity thiswep))
                {
                        if(bot_aim(1000000, 0, 1, false))
                                self.BUTTON_ATCK = true;
@@ -142,119 +168,115 @@ void W_Vortex_Attack(float issecondary)
                                if(WEP_CVAR(vortex, charge))
                                        self.BUTTON_ATCK2 = true;
                        }
-                       return true;
                }
-               METHOD(Vortex, wr_think, bool(entity thiswep))
+               METHOD(Vortex, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
                {
-                       if(WEP_CVAR(vortex, charge) && self.vortex_charge < WEP_CVAR(vortex, charge_limit))
-                               self.vortex_charge = min(1, self.vortex_charge + WEP_CVAR(vortex, charge_rate) * frametime / W_TICSPERFRAME);
+                       if(WEP_CVAR(vortex, charge) && actor.vortex_charge < WEP_CVAR(vortex, charge_limit))
+                               actor.vortex_charge = min(1, actor.vortex_charge + WEP_CVAR(vortex, charge_rate) * frametime / W_TICSPERFRAME);
 
                        if(WEP_CVAR_SEC(vortex, chargepool))
-                               if(self.vortex_chargepool_ammo < 1)
+                               if(actor.vortex_chargepool_ammo < 1)
                                {
-                                       if(self.vortex_chargepool_pauseregen_finished < time)
-                                               self.vortex_chargepool_ammo = min(1, self.vortex_chargepool_ammo + WEP_CVAR_SEC(vortex, chargepool_regen) * frametime / W_TICSPERFRAME);
-                                       self.pauseregen_finished = max(self.pauseregen_finished, time + WEP_CVAR_SEC(vortex, chargepool_pause_regen));
+                                       if(actor.vortex_chargepool_pauseregen_finished < time)
+                                               actor.vortex_chargepool_ammo = min(1, actor.vortex_chargepool_ammo + WEP_CVAR_SEC(vortex, chargepool_regen) * frametime / W_TICSPERFRAME);
+                                       actor.pauseregen_finished = max(actor.pauseregen_finished, time + WEP_CVAR_SEC(vortex, chargepool_pause_regen));
                                }
 
-                       if(autocvar_g_balance_vortex_reload_ammo && self.clip_load < min(WEP_CVAR_PRI(vortex, ammo), WEP_CVAR_SEC(vortex, ammo))) // forced reload
-                               _WEP_ACTION(self.weapon, WR_RELOAD);
-                       else
+                       if(autocvar_g_balance_vortex_reload_ammo && actor.clip_load < min(WEP_CVAR_PRI(vortex, ammo), WEP_CVAR_SEC(vortex, ammo))) { // forced reload
+                               Weapon w = get_weaponinfo(actor.weapon);
+                               w.wr_reload(w);
+                       } else
                        {
-                               if(self.BUTTON_ATCK)
+                               if(fire & 1)
                                {
-                                       if(weapon_prepareattack(0, WEP_CVAR_PRI(vortex, refire)))
+                                       if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(vortex, refire)))
                                        {
-                                               W_Vortex_Attack(0);
-                                               weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(vortex, animtime), w_ready);
+                                               W_Vortex_Attack(thiswep, 0);
+                                               weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(vortex, animtime), w_ready);
                                        }
                                }
-                               if((WEP_CVAR(vortex, charge) && !WEP_CVAR(vortex, secondary)) ? (self.BUTTON_ZOOM | self.BUTTON_ZOOMSCRIPT) : self.BUTTON_ATCK2)
+                               if((WEP_CVAR(vortex, charge) && !WEP_CVAR(vortex, secondary)) ? (actor.BUTTON_ZOOM | actor.BUTTON_ZOOMSCRIPT) : (fire & 2))
                                {
                                        if(WEP_CVAR(vortex, charge))
                                        {
-                                               self.vortex_charge_rottime = time + WEP_CVAR(vortex, charge_rot_pause);
+                                               actor.vortex_charge_rottime = time + WEP_CVAR(vortex, charge_rot_pause);
                                                float dt = frametime / W_TICSPERFRAME;
 
-                                               if(self.vortex_charge < 1)
+                                               if(actor.vortex_charge < 1)
                                                {
                                                        if(WEP_CVAR_SEC(vortex, chargepool))
                                                        {
                                                                if(WEP_CVAR_SEC(vortex, ammo))
                                                                {
                                                                        // always deplete if secondary is held
-                                                                       self.vortex_chargepool_ammo = max(0, self.vortex_chargepool_ammo - WEP_CVAR_SEC(vortex, ammo) * dt);
+                                                                       actor.vortex_chargepool_ammo = max(0, actor.vortex_chargepool_ammo - WEP_CVAR_SEC(vortex, ammo) * dt);
 
-                                                                       dt = min(dt, (1 - self.vortex_charge) / WEP_CVAR(vortex, charge_rate));
-                                                                       self.vortex_chargepool_pauseregen_finished = time + WEP_CVAR_SEC(vortex, chargepool_pause_regen);
-                                                                       dt = min(dt, self.vortex_chargepool_ammo);
+                                                                       dt = min(dt, (1 - actor.vortex_charge) / WEP_CVAR(vortex, charge_rate));
+                                                                       actor.vortex_chargepool_pauseregen_finished = time + WEP_CVAR_SEC(vortex, chargepool_pause_regen);
+                                                                       dt = min(dt, actor.vortex_chargepool_ammo);
                                                                        dt = max(0, dt);
 
-                                                                       self.vortex_charge += dt * WEP_CVAR(vortex, charge_rate);
+                                                                       actor.vortex_charge += dt * WEP_CVAR(vortex, charge_rate);
                                                                }
                                                        }
 
                                                        else if(WEP_CVAR_SEC(vortex, ammo))
                                                        {
-                                                               if(self.BUTTON_ATCK2) // only eat ammo when the button is pressed
+                                                               if(fire & 2) // only eat ammo when the button is pressed
                                                                {
-                                                                       dt = min(dt, (1 - self.vortex_charge) / WEP_CVAR(vortex, charge_rate));
-                                                                       if(!(self.items & IT_UNLIMITED_WEAPON_AMMO))
+                                                                       dt = min(dt, (1 - actor.vortex_charge) / WEP_CVAR(vortex, charge_rate));
+                                                                       if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
                                                                        {
                                                                                // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
                                                                                if(autocvar_g_balance_vortex_reload_ammo)
                                                                                {
-                                                                                       dt = min(dt, (self.clip_load - WEP_CVAR_PRI(vortex, ammo)) / WEP_CVAR_SEC(vortex, ammo));
+                                                                                       dt = min(dt, (actor.clip_load - WEP_CVAR_PRI(vortex, ammo)) / WEP_CVAR_SEC(vortex, ammo));
                                                                                        dt = max(0, dt);
                                                                                        if(dt > 0)
                                                                                        {
-                                                                                               self.clip_load = max(WEP_CVAR_SEC(vortex, ammo), self.clip_load - WEP_CVAR_SEC(vortex, ammo) * dt);
+                                                                                               actor.clip_load = max(WEP_CVAR_SEC(vortex, ammo), actor.clip_load - WEP_CVAR_SEC(vortex, ammo) * dt);
                                                                                        }
-                                                                                       self.(weapon_load[WEP_VORTEX.m_id]) = self.clip_load;
+                                                                                       actor.(weapon_load[WEP_VORTEX.m_id]) = actor.clip_load;
                                                                                }
                                                                                else
                                                                                {
-                                                                                       dt = min(dt, (self.WEP_AMMO(VORTEX) - WEP_CVAR_PRI(vortex, ammo)) / WEP_CVAR_SEC(vortex, ammo));
+                                                                                       dt = min(dt, (actor.WEP_AMMO(VORTEX) - WEP_CVAR_PRI(vortex, ammo)) / WEP_CVAR_SEC(vortex, ammo));
                                                                                        dt = max(0, dt);
                                                                                        if(dt > 0)
                                                                                        {
-                                                                                               self.WEP_AMMO(VORTEX) = max(WEP_CVAR_SEC(vortex, ammo), self.WEP_AMMO(VORTEX) - WEP_CVAR_SEC(vortex, ammo) * dt);
+                                                                                               actor.WEP_AMMO(VORTEX) = max(WEP_CVAR_SEC(vortex, ammo), actor.WEP_AMMO(VORTEX) - WEP_CVAR_SEC(vortex, ammo) * dt);
                                                                                        }
                                                                                }
                                                                        }
-                                                                       self.vortex_charge += dt * WEP_CVAR(vortex, charge_rate);
+                                                                       actor.vortex_charge += dt * WEP_CVAR(vortex, charge_rate);
                                                                }
                                                        }
 
                                                        else
                                                        {
-                                                               dt = min(dt, (1 - self.vortex_charge) / WEP_CVAR(vortex, charge_rate));
-                                                               self.vortex_charge += dt * WEP_CVAR(vortex, charge_rate);
+                                                               dt = min(dt, (1 - actor.vortex_charge) / WEP_CVAR(vortex, charge_rate));
+                                                               actor.vortex_charge += dt * WEP_CVAR(vortex, charge_rate);
                                                        }
                                                }
                                        }
                                        else if(WEP_CVAR(vortex, secondary))
                                        {
-                                               if(weapon_prepareattack(0, WEP_CVAR_SEC(vortex, refire)))
+                                               if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_SEC(vortex, refire)))
                                                {
-                                                       W_Vortex_Attack(1);
-                                                       weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_SEC(vortex, animtime), w_ready);
+                                                       W_Vortex_Attack(thiswep, 1);
+                                                       weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_SEC(vortex, animtime), w_ready);
                                                }
                                        }
                                }
                        }
-
-                       return true;
                }
-               METHOD(Vortex, wr_init, bool(entity thiswep))
+               METHOD(Vortex, wr_init, void(entity thiswep))
                {
                        VORTEX_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP);
-                       return true;
                }
-               METHOD(Vortex, wr_setup, bool(entity thiswep))
+               METHOD(Vortex, wr_setup, void(entity thiswep))
                {
                        self.vortex_lasthit = 0;
-                       return true;
                }
                METHOD(Vortex, wr_checkammo1, bool(entity thiswep))
                {
@@ -276,26 +298,29 @@ void W_Vortex_Attack(float issecondary)
                                return false; // zoom is not a fire mode
                        }
                }
-               METHOD(Vortex, wr_config, bool(entity thiswep))
+               METHOD(Vortex, wr_config, void(entity thiswep))
                {
                        VORTEX_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS);
-                       return true;
                }
-               METHOD(Vortex, wr_resetplayer, bool(entity thiswep))
+               METHOD(Vortex, wr_resetplayer, void(entity thiswep))
                {
+                       if (WEP_CVAR(vortex, charge)) {
+                               if (WEP_CVAR_SEC(vortex, chargepool)) {
+                                       self.vortex_chargepool_ammo = 1;
+                               }
+                               self.vortex_charge = WEP_CVAR(vortex, charge_start);
+                       }
                        self.vortex_lasthit = 0;
-                       return true;
                }
-               METHOD(Vortex, wr_reload, bool(entity thiswep))
+               METHOD(Vortex, wr_reload, void(entity thiswep))
                {
-                       W_Reload(min(WEP_CVAR_PRI(vortex, ammo), WEP_CVAR_SEC(vortex, ammo)), SND(RELOAD));
-                       return true;
+                       W_Reload(self, min(WEP_CVAR_PRI(vortex, ammo), WEP_CVAR_SEC(vortex, ammo)), SND(RELOAD));
                }
-               METHOD(Vortex, wr_suicidemessage, bool(entity thiswep))
+               METHOD(Vortex, wr_suicidemessage, int(entity thiswep))
                {
                        return WEAPON_THINKING_WITH_PORTALS;
                }
-               METHOD(Vortex, wr_killmessage, bool(entity thiswep))
+               METHOD(Vortex, wr_killmessage, int(entity thiswep))
                {
                        return WEAPON_VORTEX_MURDER;
                }
@@ -304,23 +329,19 @@ void W_Vortex_Attack(float issecondary)
 #ifdef CSQC
 float autocvar_g_balance_vortex_secondary = 0; // WEAPONTODO
 
-               METHOD(Vortex, wr_impacteffect, bool(entity thiswep))
+               METHOD(Vortex, wr_impacteffect, void(entity thiswep))
                {
-                       vector org2;
-                       org2 = w_org + w_backoff * 6;
-                       pointparticles(particleeffectnum(EFFECT_VORTEX_IMPACT), org2, '0 0 0', 1);
+                       vector org2 = w_org + w_backoff * 6;
+                       pointparticles(EFFECT_VORTEX_IMPACT, org2, '0 0 0', 1);
                        if(!w_issilent)
                                sound(self, CH_SHOTS, SND_NEXIMPACT, VOL_BASE, ATTN_NORM);
-
-                       return true;
                }
-               METHOD(Vortex, wr_init, bool(entity thiswep))
+               METHOD(Vortex, wr_init, void(entity thiswep))
                {
                        if(autocvar_cl_reticle && autocvar_cl_reticle_weapon)
                        {
                                precache_pic("gfx/reticle_nex");
                        }
-                       return true;
                }
                METHOD(Vortex, wr_zoomreticle, bool(entity thiswep))
                {