]> 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 03cd25066b3c96c0760dd2046b271f58c1c17d85..8a90679b81a2690428328e79dd4598ccf40ce183 100644 (file)
@@ -1,19 +1,21 @@
 #ifndef IMPLEMENTATION
-REGISTER_WEAPON(
-/* WEP_##id  */ VORTEX,
-/* function  */ W_Vortex,
-/* ammotype  */ ammo_cells,
-/* impulse   */ 7,
-/* flags     */ WEP_FLAG_NORMAL | WEP_FLAG_RELOADABLE | WEP_TYPE_HITSCAN,
-/* rating    */ BOT_PICKUP_RATING_HIGH,
-/* color     */ '0.5 1 1',
-/* modelname */ "nex",
-/* simplemdl */ "foobar",
-/* crosshair */ "gfx/crosshairnex 0.65",
-/* wepimg    */ "weaponnex",
-/* refname   */ "vortex",
-/* wepname   */ _("Vortex")
-);
+CLASS(Vortex, Weapon)
+/* ammotype  */ ATTRIB(Vortex, ammo_field, .int, ammo_cells)
+/* impulse   */ ATTRIB(Vortex, impulse, int, 7)
+/* flags     */ ATTRIB(Vortex, spawnflags, int, WEP_FLAG_NORMAL | WEP_FLAG_RELOADABLE | WEP_TYPE_HITSCAN);
+/* rating    */ ATTRIB(Vortex, bot_pickupbasevalue, float, BOT_PICKUP_RATING_HIGH);
+/* color     */ ATTRIB(Vortex, wpcolor, vector, '0.5 1 1');
+/* modelname */ ATTRIB(Vortex, mdl, string, "nex");
+#ifndef MENUQC
+/* model     */ ATTRIB(Vortex, m_model, Model, MDL_VORTEX_ITEM);
+#endif
+/* crosshair */ ATTRIB(Vortex, w_crosshair, string, "gfx/crosshairnex");
+/* crosshair */ ATTRIB(Vortex, w_crosshair_size, float, 0.65);
+/* wepimg    */ ATTRIB(Vortex, model2, string, "weaponnex");
+/* refname   */ ATTRIB(Vortex, netname, string, "vortex");
+/* wepname   */ ATTRIB(Vortex, m_name, string, _("Vortex"));
+ENDCLASS(Vortex)
+REGISTER_WEAPON(VORTEX, NEW(Vortex));
 
 #define VORTEX_SETTINGS(w_cvar,w_prop) VORTEX_SETTINGS_LIST(w_cvar, w_prop, VORTEX, vortex)
 #define VORTEX_SETTINGS_LIST(w_cvar,w_prop,id,sn) \
@@ -58,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);
@@ -75,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);
 
-void W_Vortex_Attack(float issecondary)
+       //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
+
+#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;
 
@@ -103,10 +131,10 @@ void W_Vortex_Attack(float issecondary)
        mydmg *= charge;
        myforce *= charge;
 
-       W_SetupShot(self, true, 5, W_Sound("nexfire"), CH_WEAPON_A, mydmg);
+       W_SetupShot(self, true, 5, SND(NEXFIRE), CH_WEAPON_A, mydmg);
        if(charge > WEP_CVAR(vortex, charge_animlimit) && WEP_CVAR(vortex, charge_animlimit)) // if the Vortex is overcharged, we play an extra sound
        {
-               sound(self, CH_WEAPON_B, W_Sound("nexcharge"), VOL_BASE * (charge - 0.5 * WEP_CVAR(vortex, charge_animlimit)) / (1 - 0.5 * WEP_CVAR(vortex, charge_animlimit)), ATTN_NORM);
+               sound(self, CH_WEAPON_B, SND_NEXCHARGE, VOL_BASE * (charge - 0.5 * WEP_CVAR(vortex, charge_animlimit)) / (1 - 0.5 * WEP_CVAR(vortex, charge_animlimit)), ATTN_NORM);
        }
 
        yoda = 0;
@@ -126,19 +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);
 }
 
-void spawnfunc_weapon_vortex(void); // defined in t_items.qc
-
 .float vortex_chargepool_pauseregen_finished;
-bool W_Vortex(int req)
-{SELFPARAM();
-       float dt;
-       float ammo_amount;
-       switch(req)
-       {
-               case WR_AIM:
+
+               METHOD(Vortex, wr_aim, void(entity thiswep))
                {
                        if(bot_aim(1000000, 0, 1, false))
                                self.BUTTON_ATCK = true;
@@ -147,141 +168,128 @@ bool W_Vortex(int req)
                                if(WEP_CVAR(vortex, charge))
                                        self.BUTTON_ATCK2 = true;
                        }
-                       return true;
                }
-               case WR_THINK:
+               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);
-                                               dt = frametime / W_TICSPERFRAME;
+                                               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;
                }
-               case WR_INIT:
+               METHOD(Vortex, wr_init, void(entity thiswep))
                {
-                       precache_model("models/nexflash.md3");
-                       precache_model(W_Model("g_nex.md3"));
-                       precache_model(W_Model("v_nex.md3"));
-                       precache_model(W_Model("h_nex.iqm"));
-                       precache_sound(W_Sound("nexfire"));
-                       precache_sound(W_Sound("nexcharge"));
-                       precache_sound(W_Sound("nexwhoosh1"));
-                       precache_sound(W_Sound("nexwhoosh2"));
-                       precache_sound(W_Sound("nexwhoosh3"));
                        VORTEX_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP);
-                       return true;
                }
-               case WR_SETUP:
+               METHOD(Vortex, wr_setup, void(entity thiswep))
                {
                        self.vortex_lasthit = 0;
-                       return true;
                }
-               case WR_CHECKAMMO1:
+               METHOD(Vortex, wr_checkammo1, bool(entity thiswep))
                {
-                       ammo_amount = self.WEP_AMMO(VORTEX) >= WEP_CVAR_PRI(vortex, ammo);
+                       float ammo_amount = self.WEP_AMMO(VORTEX) >= WEP_CVAR_PRI(vortex, ammo);
                        ammo_amount += (autocvar_g_balance_vortex_reload_ammo && self.(weapon_load[WEP_VORTEX.m_id]) >= WEP_CVAR_PRI(vortex, ammo));
                        return ammo_amount;
                }
-               case WR_CHECKAMMO2:
+               METHOD(Vortex, wr_checkammo2, bool(entity thiswep))
                {
                        if(WEP_CVAR(vortex, secondary))
                        {
                                // don't allow charging if we don't have enough ammo
-                               ammo_amount = self.WEP_AMMO(VORTEX) >= WEP_CVAR_SEC(vortex, ammo);
+                               float ammo_amount = self.WEP_AMMO(VORTEX) >= WEP_CVAR_SEC(vortex, ammo);
                                ammo_amount += self.(weapon_load[WEP_VORTEX.m_id]) >= WEP_CVAR_SEC(vortex, ammo);
                                return ammo_amount;
                        }
@@ -290,59 +298,52 @@ bool W_Vortex(int req)
                                return false; // zoom is not a fire mode
                        }
                }
-               case WR_CONFIG:
+               METHOD(Vortex, wr_config, void(entity thiswep))
                {
                        VORTEX_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS);
-                       return true;
                }
-               case WR_RESETPLAYER:
+               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;
                }
-               case WR_RELOAD:
+               METHOD(Vortex, wr_reload, void(entity thiswep))
                {
-                       W_Reload(min(WEP_CVAR_PRI(vortex, ammo), WEP_CVAR_SEC(vortex, ammo)), W_Sound("reload"));
-                       return true;
+                       W_Reload(self, min(WEP_CVAR_PRI(vortex, ammo), WEP_CVAR_SEC(vortex, ammo)), SND(RELOAD));
                }
-               case WR_SUICIDEMESSAGE:
+               METHOD(Vortex, wr_suicidemessage, int(entity thiswep))
                {
                        return WEAPON_THINKING_WITH_PORTALS;
                }
-               case WR_KILLMESSAGE:
+               METHOD(Vortex, wr_killmessage, int(entity thiswep))
                {
                        return WEAPON_VORTEX_MURDER;
                }
-       }
-       return false;
-}
+
 #endif
 #ifdef CSQC
 float autocvar_g_balance_vortex_secondary = 0; // WEAPONTODO
-bool W_Vortex(int req)
-{SELFPARAM();
-       switch(req)
-       {
-               case WR_IMPACTEFFECT:
+
+               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, W_Sound("neximpact"), VOL_BASE, ATTN_NORM);
-
-                       return true;
+                               sound(self, CH_SHOTS, SND_NEXIMPACT, VOL_BASE, ATTN_NORM);
                }
-               case WR_INIT:
+               METHOD(Vortex, wr_init, void(entity thiswep))
                {
-                       precache_sound(W_Sound("neximpact"));
                        if(autocvar_cl_reticle && autocvar_cl_reticle_weapon)
                        {
                                precache_pic("gfx/reticle_nex");
                        }
-                       return true;
                }
-               case WR_ZOOMRETICLE:
+               METHOD(Vortex, wr_zoomreticle, bool(entity thiswep))
                {
                        if(button_zoom || zoomscript_caught || (!WEP_CVAR(vortex, secondary) && button_attack2))
                        {
@@ -355,8 +356,6 @@ bool W_Vortex(int req)
                                return false;
                        }
                }
-       }
-       return false;
-}
+
 #endif
 #endif