]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/weapons/weapon/arc.qc
Add a new attack mode to Arc (disabled by default)
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / weapon / arc.qc
index 959e0939d3b010806028f6c9b71dcaba5e6db497..1d6a4a76cec013b552f5054d13b67c5c91bd8144 100644 (file)
@@ -17,6 +17,18 @@ CLASS(Arc, Weapon)
 
 #define X(BEGIN, P, END, class, prefix) \
        BEGIN(class) \
+               P(class, prefix, bolt, float, NONE) \
+               P(class, prefix, bolt_ammo, float, NONE) \
+        P(class, prefix, bolt_damageforcescale, float, NONE) \
+        P(class, prefix, bolt_damage, float, NONE) \
+        P(class, prefix, bolt_edgedamage, float, NONE) \
+        P(class, prefix, bolt_force, float, NONE) \
+        P(class, prefix, bolt_health, float, NONE) \
+        P(class, prefix, bolt_lifetime, float, NONE) \
+        P(class, prefix, bolt_radius, float, NONE) \
+        P(class, prefix, bolt_refire, float, NONE) \
+        P(class, prefix, bolt_speed, float, NONE) \
+        P(class, prefix, bolt_spread, float, NONE) \
                P(class, prefix, beam_ammo, float, NONE) \
         P(class, prefix, beam_animtime, float, NONE) \
         P(class, prefix, beam_botaimlifetime, float, NONE) \
@@ -217,6 +229,77 @@ void Arc_Player_SetHeat(entity player)
        //dprint("Heat: ",ftos(player.arc_heat_percent*100),"%\n");
 }
 
+void W_Arc_Bolt_Explode()
+{SELFPARAM();
+       self.event_damage = func_null;
+       RadiusDamage(self, self.realowner, WEP_CVAR(arc, bolt_damage), WEP_CVAR(arc, bolt_edgedamage), WEP_CVAR(arc, bolt_radius), world, world, WEP_CVAR(arc, bolt_force), self.projectiledeathtype, other);
+
+       remove(self);
+}
+
+void W_Arc_Bolt_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
+{
+       if(this.health <= 0)
+               return;
+
+       if(!W_CheckProjectileDamage(inflictor.realowner, this.realowner, deathtype, -1))
+               return; // g_projectiles_damage says to halt
+
+       this.health = this.health - damage;
+       this.angles = vectoangles(this.velocity);
+
+       if(this.health <= 0)
+               WITH(entity, self, this, W_PrepareExplosionByDamage(attacker, this.think));
+}
+
+void W_Arc_Bolt_Touch()
+{SELFPARAM();
+       PROJECTILE_TOUCH;
+       self.use();
+}
+
+void W_Arc_Attack_Bolt(Weapon thiswep)
+{SELFPARAM();
+       entity missile;
+
+       W_DecreaseAmmo(thiswep, self, WEP_CVAR(arc, bolt_ammo));
+
+       W_SetupShot(self, false, 2, SND(LASERGUN_FIRE), CH_WEAPON_A, WEP_CVAR(arc, bolt_damage));
+
+       Send_Effect(EFFECT_ARC_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
+
+       missile = new(missile);
+       missile.owner = missile.realowner = self;
+       missile.bot_dodge = true;
+       missile.bot_dodgerating = WEP_CVAR(arc, bolt_damage);
+
+       missile.takedamage = DAMAGE_YES;
+       missile.health = WEP_CVAR(arc, bolt_health);
+       missile.damageforcescale = WEP_CVAR(arc, bolt_damageforcescale);
+       missile.event_damage = W_Arc_Bolt_Damage;
+       missile.damagedbycontents = true;
+
+       missile.touch = W_Arc_Bolt_Touch;
+       missile.use = W_Arc_Bolt_Explode;
+       missile.think = adaptor_think2use_hittype_splash;
+       missile.nextthink = time + WEP_CVAR(arc, bolt_lifetime);
+       PROJECTILE_MAKETRIGGER(missile);
+       missile.projectiledeathtype = WEP_ARC.m_id | HITTYPE_SECONDARY;
+       setorigin(missile, w_shotorg);
+       setsize(missile, '0 0 0', '0 0 0');
+
+       missile.movetype = MOVETYPE_FLY;
+       W_SetupProjVelocity_PRE(missile, arc, bolt_);
+
+       missile.angles = vectoangles(missile.velocity);
+       missile.flags = FL_PROJECTILE;
+       missile.missile_flags = MIF_SPLASH;
+
+       CSQCProjectile(missile, true, PROJECTILE_ARC_BOLT, true);
+
+       MUTATOR_CALLHOOK(EditProjectile, self, missile);
+}
+
 void W_Arc_Beam_Think()
 {SELFPARAM();
        if(self != self.owner.arc_beam)
@@ -227,7 +310,7 @@ void W_Arc_Beam_Think()
 
 
        float burst = 0;
-       if( self.owner.BUTTON_ATCK2 || self.beam_bursting)
+       if( (self.owner.BUTTON_ATCK2 && !WEP_CVAR(arc, bolt)) || self.beam_bursting)
        {
                if(!self.beam_bursting)
                        self.beam_bursting = true;
@@ -241,11 +324,11 @@ void W_Arc_Beam_Think()
                ||
                (self.owner.(thiswep.ammo_field) <= 0 && !(self.owner.items & IT_UNLIMITED_WEAPON_AMMO))
                ||
-               self.owner.deadflag != DEAD_NO
+               IS_DEAD(self.owner)
                ||
                (!self.owner.BUTTON_ATCK && !burst )
                ||
-               self.owner.frozen
+               STAT(FROZEN, self.owner)
                ||
                self.owner.vehicle
                ||
@@ -665,8 +748,10 @@ void Arc_Smoke()
                        Arc_Player_SetHeat(actor);
                        Arc_Smoke();
 
+                       bool beam_fire2 = ((fire & 2) && !WEP_CVAR(arc, bolt));
+
                        if (time >= actor.arc_overheat)
-                       if ((fire & 1) || (fire & 2) || actor.arc_beam.beam_bursting)
+                       if ((fire & 1) || beam_fire2 || actor.arc_beam.beam_bursting)
                        {
 
                                if(actor.arc_BUTTON_ATCK_prev)
@@ -681,9 +766,9 @@ void Arc_Smoke()
 
                                if((!actor.arc_beam) || wasfreed(actor.arc_beam))
                                {
-                                       if(weapon_prepareattack(thiswep, actor, weaponentity, boolean(fire & 2), 0))
+                                       if(weapon_prepareattack(thiswep, actor, weaponentity, boolean(beam_fire2), 0))
                                        {
-                                               W_Arc_Beam(boolean(fire & 2));
+                                               W_Arc_Beam(boolean(beam_fire2));
 
                                                if(!actor.arc_BUTTON_ATCK_prev)
                                                {
@@ -695,6 +780,14 @@ void Arc_Smoke()
 
                                return;
                        }
+                       else if(fire & 2)
+                       {
+                               if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR(arc, bolt_refire)))
+                               {
+                                       W_Arc_Attack_Bolt(thiswep);
+                                       weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR(arc, bolt_refire), w_ready);
+                               }
+                       }
 
                        if(actor.arc_BUTTON_ATCK_prev)
                        {
@@ -734,12 +827,22 @@ void Arc_Smoke()
                METHOD(Arc, wr_checkammo2, bool(entity thiswep))
                {
                        SELFPARAM();
-                       return WEP_CVAR(arc, overheat_max) > 0 &&
-                               ((!WEP_CVAR(arc, burst_ammo)) || (self.(thiswep.ammo_field) > 0));
+                       if(WEP_CVAR(arc, bolt))
+                       {
+                               float ammo_amount = self.(thiswep.ammo_field) >= WEP_CVAR(arc, bolt_ammo);
+                               ammo_amount += self.(weapon_load[WEP_ARC.m_id]) >= WEP_CVAR(arc, bolt_ammo);
+                               return ammo_amount;
+                       }
+                       else
+                               return WEP_CVAR(arc, overheat_max) > 0 &&
+                                       ((!WEP_CVAR(arc, burst_ammo)) || (self.(thiswep.ammo_field) > 0));
                }
                METHOD(Arc, wr_killmessage, int(entity thiswep))
                {
-                       return WEAPON_ARC_MURDER;
+                       if(w_deathtype & HITTYPE_SECONDARY)
+                               return WEAPON_ARC_MURDER_SPRAY;
+                       else
+                               return WEAPON_ARC_MURDER;
                }
                METHOD(Arc, wr_drop, void(entity thiswep))
                {
@@ -759,6 +862,17 @@ void Arc_Smoke()
                }
 #endif
 #ifdef CSQC
+               METHOD(Arc, wr_impacteffect, void(entity thiswep))
+               {
+                       if(w_deathtype & HITTYPE_SECONDARY)
+                       {
+                               vector org2;
+                               org2 = w_org + w_backoff * 6;
+                               pointparticles(EFFECT_ARC_BOLT_EXPLODE, org2, w_backoff * 1000, 1);
+                               if(!w_issilent) { sound(self, CH_SHOTS, SND_LASERIMPACT, VOL_BASE, ATTN_NORM); }
+                       }
+               }
+
 void Draw_ArcBeam_callback(vector start, vector hit, vector end)
 {
        entity beam = Draw_ArcBeam_callback_entity;
@@ -852,13 +966,13 @@ void Reset_ArcBeam()
 
 void Draw_ArcBeam(entity this)
 {
-       float dt = time - self.move_time;
-       self.move_time = time;
+       float dt = time - this.move_time;
+       this.move_time = time;
        if(dt <= 0) { return; }
 
-       if(!self.beam_usevieworigin)
+       if(!this.beam_usevieworigin)
        {
-               InterpolateOrigin_Do(self);
+               InterpolateOrigin_Do(this);
        }
 
        // origin = beam starting origin
@@ -867,10 +981,10 @@ void Draw_ArcBeam(entity this)
 
        vector start_pos;
        vector wantdir; //= view_forward;
-       vector beamdir; //= self.beam_dir;
+       vector beamdir; //= this.beam_dir;
 
        float segments;
-       if(self.beam_usevieworigin)
+       if(this.beam_usevieworigin)
        {
                // WEAPONTODO:
                // Currently we have to replicate nearly the same method of figuring
@@ -885,99 +999,99 @@ void Draw_ArcBeam(entity this)
                vector up = v_up;
 
                // decide upon start position
-               if(self.beam_usevieworigin == 2)
+               if(this.beam_usevieworigin == 2)
                        { start_pos = warpzone_save_view_origin; }
                else
-                       { start_pos = self.origin; }
+                       { start_pos = this.origin; }
 
                // trace forward with an estimation
                WarpZone_TraceLine(
                        start_pos,
-                       start_pos + forward * self.beam_range,
+                       start_pos + forward * this.beam_range,
                        MOVE_NOMONSTERS,
-                       self
+                       this
                );
 
                // untransform in case our trace went through a warpzone
                vector end_pos = WarpZone_UnTransformOrigin(WarpZone_trace_transform, trace_endpos);
 
                // un-adjust trueaim if shotend is too close
-               if(vlen(end_pos - start_pos) < g_trueaim_minrange)
+               if(vdist(end_pos - start_pos, <, g_trueaim_minrange))
                        end_pos = start_pos + (forward * g_trueaim_minrange);
 
                // move shot origin to the actual gun muzzle origin
                vector origin_offset =
-                         right * -self.beam_shotorigin.y
-                       + up * self.beam_shotorigin.z;
+                         right * -this.beam_shotorigin.y
+                       + up * this.beam_shotorigin.z;
 
                start_pos = start_pos + origin_offset;
 
                // Move it also forward, but only as far as possible without hitting anything. Don't poke into walls!
-               traceline(start_pos, start_pos + forward * self.beam_shotorigin.x, MOVE_NORMAL, self);
+               traceline(start_pos, start_pos + forward * this.beam_shotorigin.x, MOVE_NORMAL, this);
                start_pos = trace_endpos;
 
                // calculate the aim direction now
                wantdir = normalize(end_pos - start_pos);
 
-               if(!self.beam_initialized)
+               if(!this.beam_initialized)
                {
-                       self.beam_dir = wantdir;
-                       self.beam_initialized = true;
+                       this.beam_dir = wantdir;
+                       this.beam_initialized = true;
                }
 
-               if(self.beam_dir != wantdir)
+               if(this.beam_dir != wantdir)
                {
                        // calculate how much we're going to move the end of the beam to the want position
                        // WEAPONTODO (server and client):
                        // blendfactor never actually becomes 0 in this situation, which is a problem
-                       // regarding precision... this means that self.beam_dir and w_shotdir approach
+                       // regarding precision... this means that this.beam_dir and w_shotdir approach
                        // eachother, however they never actually become the same value with this method.
                        // Perhaps we should do some form of rounding/snapping?
-                       float angle = vlen(wantdir - self.beam_dir) * RAD2DEG;
-                       if(angle && (angle > self.beam_maxangle))
+                       float angle = vlen(wantdir - this.beam_dir) * RAD2DEG;
+                       if(angle && (angle > this.beam_maxangle))
                        {
                                // if the angle is greater than maxangle, force the blendfactor to make this the maximum factor
                                float blendfactor = bound(
                                        0,
-                                       (1 - (self.beam_returnspeed * frametime)),
-                                       min(self.beam_maxangle / angle, 1)
+                                       (1 - (this.beam_returnspeed * frametime)),
+                                       min(this.beam_maxangle / angle, 1)
                                );
-                               self.beam_dir = normalize((wantdir * (1 - blendfactor)) + (self.beam_dir * blendfactor));
+                               this.beam_dir = normalize((wantdir * (1 - blendfactor)) + (this.beam_dir * blendfactor));
                        }
                        else
                        {
                                // the radius is not too far yet, no worries :D
                                float blendfactor = bound(
                                        0,
-                                       (1 - (self.beam_returnspeed * frametime)),
+                                       (1 - (this.beam_returnspeed * frametime)),
                                        1
                                );
-                               self.beam_dir = normalize((wantdir * (1 - blendfactor)) + (self.beam_dir * blendfactor));
+                               this.beam_dir = normalize((wantdir * (1 - blendfactor)) + (this.beam_dir * blendfactor));
                        }
 
                        // calculate how many segments are needed
                        float max_allowed_segments;
 
-                       if(self.beam_distancepersegment)
+                       if(this.beam_distancepersegment)
                        {
                                max_allowed_segments = min(
                                        ARC_MAX_SEGMENTS,
-                                       1 + (vlen(wantdir / self.beam_distancepersegment))
+                                       1 + (vlen(wantdir / this.beam_distancepersegment))
                                );
                        }
                        else { max_allowed_segments = ARC_MAX_SEGMENTS; }
 
-                       if(self.beam_degreespersegment)
+                       if(this.beam_degreespersegment)
                        {
                                segments = bound(
                                        1,
                                        (
                                                min(
                                                        angle,
-                                                       self.beam_maxangle
+                                                       this.beam_maxangle
                                                )
                                                /
-                                               self.beam_degreespersegment
+                                               this.beam_degreespersegment
                                        ),
                                        max_allowed_segments
                                );
@@ -987,17 +1101,17 @@ void Draw_ArcBeam(entity this)
                else { segments = 1; }
 
                // set the beam direction which the rest of the code will refer to
-               beamdir = self.beam_dir;
+               beamdir = this.beam_dir;
 
-               // finally, set self.angles to the proper direction so that muzzle attachment points in proper direction
-               self.angles = fixedvectoangles2(forward, up); // TODO(Samual): is this == warpzone_save_view_angles?
+               // finally, set this.angles to the proper direction so that muzzle attachment points in proper direction
+               this.angles = fixedvectoangles2(forward, up); // TODO(Samual): is this == warpzone_save_view_angles?
        }
        else
        {
                // set the values from the provided info from the networked entity
-               start_pos = self.origin;
-               wantdir = self.v_angle;
-               beamdir = self.angles;
+               start_pos = this.origin;
+               wantdir = this.v_angle;
+               beamdir = this.angles;
 
                if(beamdir != wantdir)
                {
@@ -1006,26 +1120,26 @@ void Draw_ArcBeam(entity this)
                        // calculate how many segments are needed
                        float max_allowed_segments;
 
-                       if(self.beam_distancepersegment)
+                       if(this.beam_distancepersegment)
                        {
                                max_allowed_segments = min(
                                        ARC_MAX_SEGMENTS,
-                                       1 + (vlen(wantdir / self.beam_distancepersegment))
+                                       1 + (vlen(wantdir / this.beam_distancepersegment))
                                );
                        }
                        else { max_allowed_segments = ARC_MAX_SEGMENTS; }
 
-                       if(self.beam_degreespersegment)
+                       if(this.beam_degreespersegment)
                        {
                                segments = bound(
                                        1,
                                        (
                                                min(
                                                        angle,
-                                                       self.beam_maxangle
+                                                       this.beam_maxangle
                                                )
                                                /
-                                               self.beam_degreespersegment
+                                               this.beam_degreespersegment
                                        ),
                                        max_allowed_segments
                                );
@@ -1035,13 +1149,13 @@ void Draw_ArcBeam(entity this)
                else { segments = 1; }
        }
 
-       setorigin(self, start_pos);
-       self.beam_muzzleentity.angles_z = random() * 360; // WEAPONTODO: use avelocity instead?
+       setorigin(this, start_pos);
+       this.beam_muzzleentity.angles_z = random() * 360; // WEAPONTODO: use avelocity instead?
 
-       vector beam_endpos = (start_pos + (beamdir * self.beam_range));
-       vector beam_controlpoint = start_pos + wantdir * (self.beam_range * (1 - self.beam_tightness));
+       vector beam_endpos = (start_pos + (beamdir * this.beam_range));
+       vector beam_controlpoint = start_pos + wantdir * (this.beam_range * (1 - this.beam_tightness));
 
-       Draw_ArcBeam_callback_entity = self;
+       Draw_ArcBeam_callback_entity = this;
        Draw_ArcBeam_callback_last_thickness = 0;
        Draw_ArcBeam_callback_last_top = start_pos;
        Draw_ArcBeam_callback_last_bottom = start_pos;
@@ -1089,49 +1203,49 @@ void Draw_ArcBeam(entity this)
        }
 
        // visual effects for startpoint and endpoint
-       if(self.beam_hiteffect)
+       if(this.beam_hiteffect)
        {
                // FIXME we really should do this on the server so it actually
                // matches gameplay. What this client side stuff is doing is no
                // more than guesswork.
                if((trace_ent || trace_fraction < 1) && !(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT))
                pointparticles(
-                       self.beam_hiteffect,
+                       this.beam_hiteffect,
                        last_origin,
                        beamdir * -1,
                        frametime * 2
                );
        }
-       if(self.beam_hitlight[0])
+       if(this.beam_hitlight[0])
        {
                adddynamiclight(
                        last_origin,
-                       self.beam_hitlight[0],
+                       this.beam_hitlight[0],
                        vec3(
-                               self.beam_hitlight[1],
-                               self.beam_hitlight[2],
-                               self.beam_hitlight[3]
+                               this.beam_hitlight[1],
+                               this.beam_hitlight[2],
+                               this.beam_hitlight[3]
                        )
                );
        }
-       if(self.beam_muzzleeffect)
+       if(this.beam_muzzleeffect)
        {
                pointparticles(
-                       self.beam_muzzleeffect,
+                       this.beam_muzzleeffect,
                        original_start_pos + wantdir * 20,
                        wantdir * 1000,
                        frametime * 0.1
                );
        }
-       if(self.beam_muzzlelight[0])
+       if(this.beam_muzzlelight[0])
        {
                adddynamiclight(
                        original_start_pos + wantdir * 20,
-                       self.beam_muzzlelight[0],
+                       this.beam_muzzlelight[0],
                        vec3(
-                               self.beam_muzzlelight[1],
-                               self.beam_muzzlelight[2],
-                               self.beam_muzzlelight[3]
+                               this.beam_muzzlelight[1],
+                               this.beam_muzzlelight[2],
+                               this.beam_muzzlelight[3]
                        )
                );
        }
@@ -1143,10 +1257,10 @@ void Draw_ArcBeam(entity this)
        Draw_ArcBeam_callback_last_bottom = '0 0 0';
 }
 
-void Remove_ArcBeam()
-{SELFPARAM();
-       remove(self.beam_muzzleentity);
-       sound(self, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, ATTEN_NORM);
+void Remove_ArcBeam(entity this)
+{
+       remove(this.beam_muzzleentity);
+       sound(this, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, ATTEN_NORM);
 }
 
 NET_HANDLE(ENT_CLIENT_ARC_BEAM, bool isnew)