]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/weapons/w_arc.qc
Working on cleaning up weapon spawn functions
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / w_arc.qc
index 4612da7643389f2c66f329eee88c9cb0ab5d5b2a..ab06a8a92327d9348cb25488cd0da6e5c94adf85 100644 (file)
@@ -1,33 +1,49 @@
 #ifdef REGISTER_WEAPON
 REGISTER_WEAPON(
-/* WEP_##id  */ LIGHTNING,
-/* function  */ w_lightning,
+/* WEP_##id  */ ARC,
+/* function  */ w_arc,
 /* ammotype  */ IT_CELLS,
 /* impulse   */ 5,
-/* flags     */ WEP_FLAG_NORMAL | WEP_TYPE_SPLASH,
-/* rating    */ BOT_PICKUP_RATING_MID,
-/* model     */ "lightning",
-/* shortname */ "lightning",
-/* fullname  */ _("Lightning")
+/* flags     */ WEP_FLAG_NORMAL,
+/* rating    */ BOT_PICKUP_RATING_HIGH,
+/* model     */ "arc",
+/* shortname */ "arc",
+/* fullname  */ _("Arc")
 );
 
-#ifdef SVQC
-void LightningInit();
-vector lightning_shotorigin[4];
+#define ARC_SETTINGS(weapon) \
+       WEP_ADD_CVAR(weapon, MO_BOTH, ammo) \
+       WEP_ADD_CVAR(weapon, MO_PRI,  animtime) \
+       WEP_ADD_CVAR(weapon, MO_PRI,  damage) \
+       WEP_ADD_CVAR(weapon, MO_PRI,  falloff_halflifedist) \
+       WEP_ADD_CVAR(weapon, MO_PRI,  falloff_maxdist) \
+       WEP_ADD_CVAR(weapon, MO_PRI,  falloff_mindist) \
+       WEP_ADD_CVAR(weapon, MO_PRI,  force) \
+       WEP_ADD_CVAR(weapon, MO_PRI,  range) \
+       WEP_ADD_CVAR(weapon, MO_PRI,  refire) \
+       WEP_ADD_PROP(weapon, reloading_ammo, reload_ammo) \
+       WEP_ADD_PROP(weapon, reloading_time, reload_time) \
+       WEP_ADD_PROP(weapon, switchdelay_raise, switchdelay_raise) \
+       WEP_ADD_PROP(weapon, switchdelay_drop, switchdelay_drop)
+
+#ifndef MENUQC
+vector arc_shotorigin[4];
 #endif
-#else
 #ifdef SVQC
-
-// Declarations ========================= 
+ARC_SETTINGS(arc)
+void ArcInit();
 .vector hook_start, hook_end; // used for beam
-.entity lightning_beam; // used for beam
+.entity arc_beam; // used for beam
 .float BUTTON_ATCK_prev; // for better animation control
 .float lg_fire_prev; // for better animation control
+#endif
+#else
+#ifdef SVQC
+void spawnfunc_weapon_arc() { weapon_defaultspawnfunc(WEP_ARC); }
 
-// Lightning functions ========================= 
-float W_Lightning_Beam_Send(entity to, float sf)
+float W_Arc_Beam_Send(entity to, float sf)
 {
-       WriteByte(MSG_ENTITY, ENT_CLIENT_LIGHTNING_BEAM);
+       WriteByte(MSG_ENTITY, ENT_CLIENT_ARC_BEAM);
        sf = sf & 0x7F;
        if(sound_allowed(MSG_BROADCAST, self.owner))
                sf |= 0x80;
@@ -35,7 +51,7 @@ float W_Lightning_Beam_Send(entity to, float sf)
        if(sf & 1)
        {
                WriteByte(MSG_ENTITY, num_for_edict(self.owner));
-               WriteCoord(MSG_ENTITY, autocvar_g_balance_lightning_primary_range);
+               WriteCoord(MSG_ENTITY, WEP_CVAR_PRI(arc, range));
        }
        if(sf & 2)
        {
@@ -52,18 +68,18 @@ float W_Lightning_Beam_Send(entity to, float sf)
        return TRUE;
 }
 
-void W_Lightning_Beam_Think()
+void W_Arc_Beam_Think()
 {
        self.owner.lg_fire_prev = time;
-       if (self != self.owner.lightning_beam)
+       if (self != self.owner.arc_beam)
        {
                remove(self);
                return;
        }
        if (self.owner.weaponentity.state != WS_INUSE || (self.owner.ammo_cells <= 0 && !(self.owner.items & IT_UNLIMITED_WEAPON_AMMO)) || self.owner.deadflag != DEAD_NO || !self.owner.BUTTON_ATCK || self.owner.freezetag_frozen)
        {
-               if(self == self.owner.lightning_beam)
-                       self.owner.lightning_beam = world;
+               if(self == self.owner.arc_beam)
+                       self.owner.arc_beam = world;
                remove(self);
                return;
        }
@@ -76,27 +92,27 @@ void W_Lightning_Beam_Think()
        dt = frametime;
        if not(self.owner.items & IT_UNLIMITED_WEAPON_AMMO)
        {
-               if(autocvar_g_balance_lightning_primary_ammo)
+               if(WEP_CVAR_PRI(arc, ammo))
                {
-                       dt = min(dt, self.owner.ammo_cells / autocvar_g_balance_lightning_primary_ammo);
-                       self.owner.ammo_cells = max(0, self.owner.ammo_cells - autocvar_g_balance_lightning_primary_ammo * frametime);
+                       dt = min(dt, self.owner.ammo_cells / WEP_CVAR_PRI(arc, ammo));
+                       self.owner.ammo_cells = max(0, self.owner.ammo_cells - WEP_CVAR_PRI(arc, ammo) * frametime);
                }
        }
 
-       W_SetupShot_Range(self.owner, TRUE, 0, "", 0, autocvar_g_balance_lightning_primary_damage * dt, autocvar_g_balance_lightning_primary_range);
+       W_SetupShot_Range(self.owner, TRUE, 0, "", 0, WEP_CVAR_PRI(arc, damage) * dt, WEP_CVAR_PRI(arc, range));
        WarpZone_traceline_antilag(self.owner, w_shotorg, w_shotend, MOVE_NORMAL, self.owner, ANTILAG_LATENCY(self.owner));
 
        // apply the damage
        if(trace_ent)
        {
                vector force;
-               force = w_shotdir * autocvar_g_balance_lightning_primary_force;
+               force = w_shotdir * WEP_CVAR_PRI(arc, force);
 
-               f = ExponentialFalloff(autocvar_g_balance_lightning_primary_falloff_mindist, autocvar_g_balance_lightning_primary_falloff_maxdist, autocvar_g_balance_lightning_primary_falloff_halflifedist, vlen(WarpZone_UnTransformOrigin(WarpZone_trace_transform, trace_endpos) - w_shotorg));
+               f = ExponentialFalloff(WEP_CVAR_PRI(arc, falloff_mindist), WEP_CVAR_PRI(arc, falloff_maxdist), WEP_CVAR_PRI(arc, falloff_halflifedist), vlen(WarpZone_UnTransformOrigin(WarpZone_trace_transform, trace_endpos) - w_shotorg));
 
                if(accuracy_isgooddamage(self.owner, trace_ent))
-                       accuracy_add(self.owner, WEP_LIGHTNING, 0, autocvar_g_balance_lightning_primary_damage * dt * f);
-               Damage (trace_ent, self.owner, self.owner, autocvar_g_balance_lightning_primary_damage * dt * f, WEP_LIGHTNING, trace_endpos, force * dt);
+                       accuracy_add(self.owner, WEP_ARC, 0, WEP_CVAR_PRI(arc, damage) * dt * f);
+               Damage (trace_ent, self.owner, self.owner, WEP_CVAR_PRI(arc, damage) * dt * f, WEP_ARC, trace_endpos, force * dt);
        }
 
        // draw effect
@@ -113,7 +129,7 @@ void W_Lightning_Beam_Think()
 }
 
 // Attack functions ========================= 
-void W_Lightning_Attack1 (void)
+void W_Arc_Attack1 (void)
 {
        // only play fire sound if 0.5 sec has passed since player let go the fire button
        if(time - self.lg_fire_prev > 0.5)
@@ -121,16 +137,16 @@ void W_Lightning_Attack1 (void)
 
        entity beam, oldself;
 
-       self.lightning_beam = beam = spawn();
-       beam.classname = "W_Lightning_Beam";
+       self.arc_beam = beam = spawn();
+       beam.classname = "W_Arc_Beam";
        beam.solid = SOLID_NOT;
-       beam.think = W_Lightning_Beam_Think;
+       beam.think = W_Arc_Beam_Think;
        beam.owner = self;
        beam.movetype = MOVETYPE_NONE;
        beam.shot_spread = 1;
        beam.bot_dodge = TRUE;
-       beam.bot_dodgerating = autocvar_g_balance_lightning_primary_damage;
-       Net_LinkEntity(beam, FALSE, 0, W_Lightning_Beam_Send);
+       beam.bot_dodgerating = WEP_CVAR_PRI(arc, damage);
+       Net_LinkEntity(beam, FALSE, 0, W_Arc_Beam_Send);
 
        oldself = self;
        self = beam;
@@ -138,163 +154,184 @@ void W_Lightning_Attack1 (void)
        self = oldself;
 }
 
-float w_lightning(float req)
+float w_arc(float req)
 {
-       if (req == WR_AIM)
+       switch(req)
        {
-               self.BUTTON_ATCK = bot_aim(1000000, 0, 0.001, FALSE);
-               /*
-               self.BUTTON_ATCK=FALSE;
-               self.BUTTON_ATCK2=FALSE;
-               if(vlen(self.origin-self.enemy.origin) > 1000)
-                       self.bot_aim_whichfiretype = 0;
-               if(self.bot_aim_whichfiretype == 0)
+               case WR_AIM:
                {
-                       float shoot;
+                       self.BUTTON_ATCK = bot_aim(1000000, 0, 0.001, FALSE);
+                       /*
+                       self.BUTTON_ATCK=FALSE;
+                       self.BUTTON_ATCK2=FALSE;
+                       if(vlen(self.origin-self.enemy.origin) > 1000)
+                               self.bot_aim_whichfiretype = 0;
+                       if(self.bot_aim_whichfiretype == 0)
+                       {
+                               float shoot;
 
-                       if(autocvar_g_balance_lightning_primary_speed)
-                               shoot = bot_aim(autocvar_g_balance_lightning_primary_speed, 0, autocvar_g_balance_lightning_primary_lifetime, FALSE);
-                       else
-                               shoot = bot_aim(1000000, 0, 0.001, FALSE);
+                               if(autocvar_g_balance_arc_primary_speed)
+                                       shoot = bot_aim(autocvar_g_balance_arc_primary_speed, 0, autocvar_g_balance_arc_primary_lifetime, FALSE);
+                               else
+                                       shoot = bot_aim(1000000, 0, 0.001, FALSE);
 
-                       if(shoot)
+                               if(shoot)
+                               {
+                                       self.BUTTON_ATCK = TRUE;
+                                       if(random() < 0.01) self.bot_aim_whichfiretype = 1;
+                               }
+                       }
+                       else // todo
                        {
-                               self.BUTTON_ATCK = TRUE;
-                               if(random() < 0.01) self.bot_aim_whichfiretype = 1;
+                               //if(bot_aim(autocvar_g_balance_arc_secondary_speed, autocvar_g_balance_grenadelauncher_secondary_speed_up, autocvar_g_balance_arc_secondary_lifetime, TRUE))
+                               //{
+                               //      self.BUTTON_ATCK2 = TRUE;
+                               //      if(random() < 0.03) self.bot_aim_whichfiretype = 0;
+                               //}
                        }
+                       */
+                       
+                       return TRUE;
                }
-               else // todo
+               case WR_THINK:
                {
-                       //if(bot_aim(autocvar_g_balance_lightning_secondary_speed, autocvar_g_balance_grenadelauncher_secondary_speed_up, autocvar_g_balance_lightning_secondary_lifetime, TRUE))
-                       //{
-                       //      self.BUTTON_ATCK2 = TRUE;
-                       //      if(random() < 0.03) self.bot_aim_whichfiretype = 0;
-                       //}
-               }
-               */
-       }
-       else if (req == WR_THINK)
-       {
-               if (self.BUTTON_ATCK)
-               {
-                       if(self.BUTTON_ATCK_prev) // TODO: Find another way to implement this!
-                               /*if(self.animstate_startframe == self.anim_shoot_x && self.animstate_numframes == self.anim_shoot_y)
-                                       weapon_thinkf(WFRAME_DONTCHANGE, autocvar_g_balance_lightning_primary_animtime, w_ready);
-                               else*/
-                                       weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_lightning_primary_animtime, w_ready);
-                       
-                       if (weapon_prepareattack(0, 0))
+                       if (self.BUTTON_ATCK)
                        {
-                               if ((!self.lightning_beam) || wasfreed(self.lightning_beam))
-                                       W_Lightning_Attack1();
+                               if(self.BUTTON_ATCK_prev) // TODO: Find another way to implement this!
+                                       /*if(self.animstate_startframe == self.anim_shoot_x && self.animstate_numframes == self.anim_shoot_y)
+                                               weapon_thinkf(WFRAME_DONTCHANGE, autocvar_g_balance_arc_primary_animtime, w_ready);
+                                       else*/
+                                               weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(arc, animtime), w_ready);
                                
-                               if(!self.BUTTON_ATCK_prev)
+                               if (weapon_prepareattack(0, 0))
                                {
-                                       weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_lightning_primary_animtime, w_ready);
-                                       self.BUTTON_ATCK_prev = 1;
+                                       if ((!self.arc_beam) || wasfreed(self.arc_beam))
+                                               W_Arc_Attack1();
+                                       
+                                       if(!self.BUTTON_ATCK_prev)
+                                       {
+                                               weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(arc, animtime), w_ready);
+                                               self.BUTTON_ATCK_prev = 1;
+                                       }
                                }
-                       }
-               } 
-               else // todo
-               {
-                       if (self.BUTTON_ATCK_prev != 0)
+                       } 
+                       else // todo
                        {
-                               weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_lightning_primary_animtime, w_ready);
-                               ATTACK_FINISHED(self) = time + autocvar_g_balance_lightning_primary_refire * W_WeaponRateFactor();
+                               if (self.BUTTON_ATCK_prev != 0)
+                               {
+                                       weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(arc, animtime), w_ready);
+                                       ATTACK_FINISHED(self) = time + WEP_CVAR_PRI(arc, refire) * W_WeaponRateFactor();
+                               }
+                               self.BUTTON_ATCK_prev = 0;
                        }
-                       self.BUTTON_ATCK_prev = 0;
-               }
 
-               //if (self.BUTTON_ATCK2)
-                       //if (weapon_prepareattack(1, autocvar_g_balance_lightning_secondary_refire))
-                       //{
-                       //      W_Lightning_Attack2();
-                       //      self.lightning_count = autocvar_g_balance_lightning_secondary_count;
-                       //      weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_lightning_secondary_animtime, w_lightning_checkattack);
-                       //      self.lightning_secondarytime = time + autocvar_g_balance_lightning_secondary_refire2 * W_WeaponRateFactor();
-                       //}
-       }
-       else if (req == WR_PRECACHE)
-       {
-               precache_model ("models/weapons/g_lightning.md3");
-               precache_model ("models/weapons/v_lightning.md3");
-               precache_model ("models/weapons/h_lightning.iqm");
-               //precache_sound ("weapons/lightning_bounce.wav");
-               precache_sound ("weapons/lightning_fire.wav");
-               precache_sound ("weapons/lightning_fire2.wav");
-               precache_sound ("weapons/lightning_impact.wav");
-               //precache_sound ("weapons/lightning_impact_combo.wav");
-               //precache_sound ("weapons/W_Lightning_Beam_fire.wav");
-       }
-       else if (req == WR_SETUP)
-               weapon_setup(WEP_LIGHTNING);
-       else if (req == WR_CHECKAMMO1)
-       {
-               return !autocvar_g_balance_lightning_primary_ammo || (self.ammo_cells > 0);
-       }
-       else if (req == WR_CHECKAMMO2)
-               return self.ammo_cells >= autocvar_g_balance_lightning_secondary_ammo;
-       else if (req == WR_KILLMESSAGE)
-       {
-               if(w_deathtype & HITTYPE_SECONDARY)
+                       //if (self.BUTTON_ATCK2)
+                               //if (weapon_prepareattack(1, autocvar_g_balance_arc_secondary_refire))
+                               //{
+                               //      W_Arc_Attack2();
+                               //      self.arc_count = autocvar_g_balance_arc_secondary_count;
+                               //      weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_arc_secondary_animtime, w_arc_checkattack);
+                               //      self.arc_secondarytime = time + autocvar_g_balance_arc_secondary_refire2 * W_WeaponRateFactor();
+                               //}
+                               
+                       return TRUE;
+               }
+               case WR_PRECACHE:
+               {
+                       precache_model ("models/weapons/g_arc.md3");
+                       precache_model ("models/weapons/v_arc.md3");
+                       precache_model ("models/weapons/h_arc.iqm");
+                       //precache_sound ("weapons/arc_bounce.wav");
+                       precache_sound ("weapons/arc_fire.wav");
+                       precache_sound ("weapons/arc_fire2.wav");
+                       precache_sound ("weapons/arc_impact.wav");
+                       //precache_sound ("weapons/arc_impact_combo.wav");
+                       //precache_sound ("weapons/W_Arc_Beam_fire.wav");
+                       return TRUE;
+               }
+               case WR_SETUP:
+               {
+                       weapon_setup(WEP_ARC);
+                       return TRUE;
+               }
+               case WR_CHECKAMMO1:
+               {
+                       return !WEP_CVAR_PRI(arc, ammo) || (self.ammo_cells > 0);
+               }
+               case WR_CHECKAMMO2:
                {
-                       return WEAPON_ELECTRO_MURDER_ORBS;
+                       return self.ammo_cells >= WEP_CVAR_SEC(arc, ammo);
                }
-               else
+               case WR_KILLMESSAGE:
                {
-                       if(w_deathtype & HITTYPE_BOUNCE)
-                               return WEAPON_ELECTRO_MURDER_COMBO;
+                       if(w_deathtype & HITTYPE_SECONDARY)
+                       {
+                               return WEAPON_ELECTRO_MURDER_ORBS;
+                       }
                        else
-                               return WEAPON_ELECTRO_MURDER_BOLT;
+                       {
+                               if(w_deathtype & HITTYPE_BOUNCE)
+                                       return WEAPON_ELECTRO_MURDER_COMBO;
+                               else
+                                       return WEAPON_ELECTRO_MURDER_BOLT;
+                       }
+               }
+               case WR_RESETPLAYER:
+               {
+                       //self.arc_secondarytime = time;
+                       return TRUE;
                }
-       }
-       else if (req == WR_RESETPLAYER)
-       {
-               //self.lightning_secondarytime = time;
        }
        return TRUE;
-};
-
-void LightningInit()
-{
-       weapon_action(WEP_LIGHTNING, WR_PRECACHE);
-       lightning_shotorigin[0] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_LIGHTNING), FALSE, FALSE, 1);
-       lightning_shotorigin[1] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_LIGHTNING), FALSE, FALSE, 2);
-       lightning_shotorigin[2] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_LIGHTNING), FALSE, FALSE, 3);
-       lightning_shotorigin[3] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_LIGHTNING), FALSE, FALSE, 4);
 }
 
-void spawnfunc_weapon_lightning (void) // should this really be here?
+void ArcInit()
 {
-       weapon_defaultspawnfunc(WEP_LIGHTNING);
+       weapon_action(WEP_ARC, WR_PRECACHE);
+       arc_shotorigin[0] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 1);
+       arc_shotorigin[1] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 2);
+       arc_shotorigin[2] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 3);
+       arc_shotorigin[3] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 4);
+
+       #define WEP_ADD_CVAR(weapon,mode,name) /*nothing*/
+       #define WEP_ADD_PROP(weapon,prop,name) get_weaponinfo(WEP_ARC).##prop = autocvar_g_balance_##weapon##_##name;
+       ARC_SETTINGS(arc)
+       #undef WEP_ADD_CVAR
+       #undef WEP_ADD_PROP
 }
 #endif
 #ifdef CSQC
-float w_lightning(float req)
+float w_arc(float req)
 {
-       if(req == WR_IMPACTEFFECT)
+       switch(req)
        {
-               vector org2;
-               org2 = w_org + w_backoff * 6;
-               
-               if(w_deathtype & HITTYPE_SECONDARY)
+               case WR_IMPACTEFFECT:
                {
-                       pointparticles(particleeffectnum("lightning_ballexplode"), org2, '0 0 0', 1);
-                       if(!w_issilent)
-                               sound(self, CH_SHOTS, "weapons/lightning_impact.wav", VOL_BASE, ATTN_NORM);
+                       vector org2;
+                       org2 = w_org + w_backoff * 6;
+                       
+                       if(w_deathtype & HITTYPE_SECONDARY)
+                       {
+                               pointparticles(particleeffectnum("arc_ballexplode"), org2, '0 0 0', 1);
+                               if(!w_issilent)
+                                       sound(self, CH_SHOTS, "weapons/arc_impact.wav", VOL_BASE, ATTN_NORM);
+                       }
+                       else
+                       {
+                               pointparticles(particleeffectnum("arc_impact"), org2, '0 0 0', 1);
+                               if(!w_issilent)
+                                       sound(self, CH_SHOTS, "weapons/arc_impact.wav", VOL_BASE, ATTN_NORM);
+                       }
+                       
+                       return TRUE;
                }
-               else
+               case WR_PRECACHE:
                {
-                       pointparticles(particleeffectnum("lightning_impact"), org2, '0 0 0', 1);
-                       if(!w_issilent)
-                               sound(self, CH_SHOTS, "weapons/lightning_impact.wav", VOL_BASE, ATTN_NORM);
+                       precache_sound("weapons/arc_impact.wav");
+                       precache_sound("weapons/arc_impact_combo.wav");
+                       return TRUE;
                }
        }
-       else if(req == WR_PRECACHE)
-       {
-               precache_sound("weapons/lightning_impact.wav");
-               precache_sound("weapons/lightning_impact_combo.wav");
-       }
        return TRUE;
 }
 #endif