]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/weapons/w_shockwave.qc
Bring back old start weapons, and make shockwave a mutator blocked weapon
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / w_shockwave.qc
index 4528351a67b3a89e644b9617663f4cac28b426ed..60e8d8436de69a3fb3fc4a835c25a9a7f843bbea 100644 (file)
@@ -1,14 +1,18 @@
 #ifdef REGISTER_WEAPON
 REGISTER_WEAPON(
-/* WEP_##id */ SHOCKWAVE,
-/* function */ W_Shockwave,
-/* ammotype */ ammo_none,
-/* impulse  */ 2,
-/* flags    */ WEP_FLAG_NORMAL | WEP_TYPE_HITSCAN,
-/* rating   */ BOT_PICKUP_RATING_LOW,
-/* model    */ "shotgun",
-/* netname  */ "shockwave",
-/* fullname */ _("Shockwave")
+/* WEP_##id  */ SHOCKWAVE,
+/* function  */ W_Shockwave,
+/* ammotype  */ ammo_none,
+/* impulse   */ 2,
+/* flags     */ WEP_FLAG_NORMAL | WEP_TYPE_HITSCAN | WEP_FLAG_MUTATORBLOCKED,
+/* rating    */ BOT_PICKUP_RATING_LOW,
+/* color     */ '0.5 0.25 0',
+/* modelname */ "shotgun",
+/* simplemdl */ "foobar",
+/* crosshair */ "gfx/crosshairshotgun 0.7",
+/* wepimg    */ "weaponshotgun",
+/* refname   */ "shockwave",
+/* wepname   */ _("Shockwave")
 );
 
 #define SHOCKWAVE_SETTINGS(w_cvar,w_prop) SHOCKWAVE_SETTINGS_LIST(w_cvar, w_prop, SHOCKWAVE, shockwave)
@@ -60,34 +64,47 @@ REGISTER_WEAPON(
        w_prop(id, sn, float,  switchdelay_drop, switchdelay_drop) \
        w_prop(id, sn, string, weaponreplace, weaponreplace) \
        w_prop(id, sn, float,  weaponstart, weaponstart) \
-       w_prop(id, sn, float,  weaponstartoverride, weaponstartoverride)
+       w_prop(id, sn, float,  weaponstartoverride, weaponstartoverride) \
+       w_prop(id, sn, float,  weaponthrowable, weaponthrowable)
 
 #ifdef SVQC
 SHOCKWAVE_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
 #endif
+#ifdef CSQC
+void Net_ReadShockwaveParticle(void);
+.vector sw_shotorg;
+.vector sw_shotdir;
+.float sw_distance;
+.float sw_spread_max;
+.float sw_spread_min;
+.float sw_time;
+#endif
 #else
 #ifdef SVQC
-void spawnfunc_weapon_shockwave()
+void spawnfunc_weapon_shockwave(void)
 {
        //if(autocvar_sv_q3acompat_machineshockwaveswap) // WEAPONTODO
        if(autocvar_sv_q3acompat_machineshotgunswap)
        if(self.classname != "droppedweapon")
        {
-               weapon_defaultspawnfunc(WEP_UZI);
+               weapon_defaultspawnfunc(WEP_MACHINEGUN);
                return;
        }
        weapon_defaultspawnfunc(WEP_SHOCKWAVE);
 }
 
+#define MAX_SHOCKWAVE_HITS 10
+#define DEBUG_SHOCKWAVE
+
 .float swing_prev;
 .entity swing_alreadyhit;
 .float shockwave_blasttime;
-entity shockwave_hit[32];
-float shockwave_hit_damage[32];
-vector shockwave_hit_force[32];
+entity shockwave_hit[MAX_SHOCKWAVE_HITS];
+float shockwave_hit_damage[MAX_SHOCKWAVE_HITS];
+vector shockwave_hit_force[MAX_SHOCKWAVE_HITS];
 
 // MELEE ATTACK MODE
-void W_Shockwave_Melee_Think()
+void W_Shockwave_Melee_Think(void)
 {
        // declarations
        float i, f, swing, swing_factor, swing_damage, meleetime, is_player;
@@ -139,7 +156,7 @@ void W_Shockwave_Melee_Think()
                te_lightning2(world, targpos, self.realowner.origin + self.realowner.view_ofs + v_forward * 5 - v_up * 5); 
                te_customflash(targpos, 40,  2, '1 1 1');
                
-               is_player = (trace_ent.classname == "player" || trace_ent.classname == "body");
+               is_player = (trace_ent.classname == "player" || trace_ent.classname == "body" || (trace_ent.flags & FL_MONSTER));
 
                if((trace_fraction < 1) // if trace is good, apply the damage and remove self if necessary
                        && (trace_ent.takedamage == DAMAGE_AIM)  
@@ -207,7 +224,7 @@ void W_Shockwave_Melee_Think()
        }
 }
 
-void W_Shockwave_Melee()
+void W_Shockwave_Melee(void)
 {
        sound(self, CH_WEAPON_A, "weapons/shotgun_melee.wav", VOL_BASE, ATTN_NORM);
        weapon_thinkf(WFRAME_FIRE2, WEP_CVAR(shockwave, melee_animtime), w_ready);
@@ -296,10 +313,8 @@ float W_Shockwave_Attack_CheckHit(
 {
        if(!head) { return FALSE; }
        float i;
-
-       ++queue;
        
-       for(i = 1; i <= queue; ++i)
+       for(i = 0; i <= queue; ++i)
        {
                if(shockwave_hit[i] == head)
                {
@@ -315,7 +330,23 @@ float W_Shockwave_Attack_CheckHit(
        return TRUE;
 }
 
-void W_Shockwave_Attack()
+void W_Shockwave_Send(void)
+{
+       WriteByte(MSG_BROADCAST, SVC_TEMPENTITY);
+       WriteByte(MSG_BROADCAST, TE_CSQC_SHOCKWAVEPARTICLE);
+       WriteCoord(MSG_BROADCAST, w_shotorg_x);
+       WriteCoord(MSG_BROADCAST, w_shotorg_y);
+       WriteCoord(MSG_BROADCAST, w_shotorg_z);
+       WriteCoord(MSG_BROADCAST, w_shotdir_x);
+       WriteCoord(MSG_BROADCAST, w_shotdir_y);
+       WriteCoord(MSG_BROADCAST, w_shotdir_z);
+       WriteShort(MSG_BROADCAST, WEP_CVAR(shockwave, blast_distance));
+       WriteByte(MSG_BROADCAST, bound(0, WEP_CVAR(shockwave, blast_spread_max), 255));
+       WriteByte(MSG_BROADCAST, bound(0, WEP_CVAR(shockwave, blast_spread_min), 255));
+       WriteByte(MSG_BROADCAST, num_for_edict(self));
+}
+
+void W_Shockwave_Attack(void)
 {
        // declarations
        float multiplier, multiplier_from_accuracy, multiplier_from_distance;
@@ -335,7 +366,7 @@ void W_Shockwave_Attack()
        //entity transform = WarpZone_trace_transform;
 
        // do the firing effect now
-       //SendCSQCShockwaveParticle(attack_endpos); // WEAPONTODO
+       W_Shockwave_Send();
        Damage_DamageInfo(
                attack_hitpos,
                WEP_CVAR(shockwave, blast_splash_damage),
@@ -488,7 +519,7 @@ void W_Shockwave_Attack()
                                final_force_z *= WEP_CVAR(shockwave, blast_force_zscale);
 
                                // queue damage with this calculated info
-                               if(W_Shockwave_Attack_CheckHit(queue, head, final_force, final_damage)) { ++queue; }
+                               if(W_Shockwave_Attack_CheckHit(queue, head, final_force, final_damage)) { queue = min(queue + 1, MAX_SHOCKWAVE_HITS); }
 
                                #ifdef DEBUG_SHOCKWAVE
                                print(sprintf(
@@ -531,9 +562,8 @@ void W_Shockwave_Attack()
 
                        vector nearest_on_line = (w_shotorg + a * w_shotdir);
                        vector nearest_to_attacker = WarpZoneLib_NearestPointOnBox(center + head.mins, center + head.maxs, nearest_on_line);
-                       float distance_to_target = vlen(w_shotorg - nearest_to_attacker); // WEAPONTODO: use the findradius function for this
 
-                       if((distance_to_target <= WEP_CVAR(shockwave, blast_distance)) 
+                       if((vlen(head.WarpZone_findradius_dist) <= WEP_CVAR(shockwave, blast_distance)) 
                                && (W_Shockwave_Attack_IsVisible(head, nearest_on_line, w_shotorg, attack_endpos)))
                        {
                                // calculate importance of distance and accuracy for this attack
@@ -547,7 +577,7 @@ void W_Shockwave_Attack()
                                );
                                multiplier_from_distance = (1 -
                                        (distance_to_hit ?
-                                               min(1, (distance_to_target / distance_to_end))
+                                               min(1, (vlen(head.WarpZone_findradius_dist) / distance_to_end))
                                                :
                                                0
                                        )
@@ -580,7 +610,7 @@ void W_Shockwave_Attack()
                                final_force_z *= WEP_CVAR(shockwave, blast_force_zscale);
 
                                // queue damage with this calculated info
-                               if(W_Shockwave_Attack_CheckHit(queue, head, final_force, final_damage)) { ++queue; }
+                               if(W_Shockwave_Attack_CheckHit(queue, head, final_force, final_damage)) { queue = min(queue + 1, MAX_SHOCKWAVE_HITS); }
 
                                #ifdef DEBUG_SHOCKWAVE
                                print(sprintf(
@@ -600,9 +630,9 @@ void W_Shockwave_Attack()
 
        for(i = 1; i <= queue; ++i)
        {
-               head = shockwave_hit[i];
-               final_force = shockwave_hit_force[i];
-               final_damage = shockwave_hit_damage[i];
+               head = shockwave_hit[i-1];
+               final_force = shockwave_hit_force[i-1];
+               final_damage = shockwave_hit_damage[i-1];
                
                Damage(
                        head,
@@ -613,7 +643,13 @@ void W_Shockwave_Attack()
                        head.origin,
                        final_force
                );
-               
+
+               if(accuracy_isgooddamage(self.realowner, head))
+               {
+                       print("wtf\n");
+                       accuracy_add(self.realowner, WEP_SHOCKWAVE, 0, final_damage);
+               }
+
                #ifdef DEBUG_SHOCKWAVE
                print(sprintf(
                        "SHOCKWAVE by %s: damage = %f, force = %f.\n",
@@ -623,9 +659,9 @@ void W_Shockwave_Attack()
                ));
                #endif
                
-               shockwave_hit[i] = world;
-               shockwave_hit_force[i] = '0 0 0';
-               shockwave_hit_damage[i] = 0;
+               shockwave_hit[i-1] = world;
+               shockwave_hit_force[i-1] = '0 0 0';
+               shockwave_hit_damage[i-1] = 0;
        }
 }
 
@@ -678,7 +714,7 @@ float W_Shockwave(float req)
                        precache_sound("misc/itempickup.wav");
                        precache_sound("weapons/shockwave_fire.wav");
                        precache_sound("weapons/shockwave_melee.wav");
-                       SHOCKWAVE_SETTINGS(WEP_SKIPCVAR, WEP_SET_PROP)
+                       SHOCKWAVE_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP)
                        return TRUE;
                }
                case WR_CHECKAMMO1:
@@ -704,20 +740,141 @@ float W_Shockwave(float req)
                                return WEAPON_SHOCKWAVE_MURDER;
                }
        }
-       return TRUE;
+       return FALSE;
 }
 #endif
 #ifdef CSQC
+// WEAPONTODO: add client side settings for these
+#define SW_MAXALPHA 0.5
+#define SW_FADETIME 0.4
+#define SW_DISTTOMIN 200
+void Draw_Shockwave()
+{
+       // fading/removal control
+       float a = bound(0, (SW_MAXALPHA - ((time - self.sw_time) / SW_FADETIME)), SW_MAXALPHA);
+       if(a < ALPHA_MIN_VISIBLE) { remove(self); }
+
+       // WEAPONTODO: save this only once when creating the entity
+       vector sw_color = getcsqcplayercolor(self.sv_entnum); // GetTeamRGB(GetPlayerColor(self.sv_entnum));
+
+       // WEAPONTODO: trace to find what we actually hit
+       vector endpos = (self.sw_shotorg + (self.sw_shotdir * self.sw_distance));
+
+       vectorvectors(self.sw_shotdir);
+       vector right = v_right; // save this for when we do makevectors later
+       vector up = v_up; // save this for when we do makevectors later
+
+       // WEAPONTODO: combine and simplify these calculations
+       vector min_end = ((self.sw_shotorg + (self.sw_shotdir * SW_DISTTOMIN)) + (up * self.sw_spread_min));
+       vector max_end = (endpos + (up * self.sw_spread_max));
+       float spread_to_min = vlen(normalize(min_end - self.sw_shotorg) - self.sw_shotdir);
+       float spread_to_max = vlen(normalize(max_end - min_end) - self.sw_shotdir);
+
+       vector first_min_end = '0 0 0', prev_min_end = '0 0 0', new_min_end = '0 0 0';
+       vector first_max_end = '0 0 0', prev_max_end = '0 0 0', new_max_end = '0 0 0';
+       float new_max_dist, new_min_dist;
+
+       vector deviation, angle = '0 0 0';
+       float counter, divisions = 20;
+       for(counter = 0; counter < divisions; ++counter)
+       {
+               // perfect circle effect lines
+               makevectors('0 360 0' * (0.75 + (counter - 0.5) / divisions));
+               angle_y = v_forward_x;
+               angle_z = v_forward_y;
+
+               // first do the spread_to_min effect
+               deviation = angle * spread_to_min;
+               deviation = ((self.sw_shotdir + (right * deviation_y) + (up * deviation_z)));
+               new_min_dist = SW_DISTTOMIN;
+               new_min_end = (self.sw_shotorg + (deviation * new_min_dist));
+               //te_lightning2(world, new_min_end, self.sw_shotorg);
+
+               // then calculate spread_to_max effect
+               deviation = angle * spread_to_max;
+               deviation = ((self.sw_shotdir + (right * deviation_y) + (up * deviation_z)));
+               new_max_dist = vlen(new_min_end - endpos);
+               new_max_end = (new_min_end + (deviation * new_max_dist));
+               //te_lightning2(world, new_end, prev_min_end);
+               
+
+               if(counter == 0)
+               {
+                       first_min_end = new_min_end;
+                       first_max_end = new_max_end;
+               }
+
+               if(counter >= 1)
+               {
+                       // draw from shot origin to min spread radius
+                       R_BeginPolygon("", DRAWFLAG_NORMAL);
+                       R_PolygonVertex(prev_min_end, '0 0 0', sw_color, a);
+                       R_PolygonVertex(new_min_end, '0 0 0', sw_color, a);
+                       R_PolygonVertex(self.sw_shotorg, '0 0 0', sw_color, a);
+                       R_EndPolygon();
+
+                       // draw from min spread radius to max spread radius
+                       R_BeginPolygon("", DRAWFLAG_NORMAL);
+                       R_PolygonVertex(new_min_end, '0 0 0', sw_color, a);
+                       R_PolygonVertex(prev_min_end, '0 0 0', sw_color, a);
+                       R_PolygonVertex(prev_max_end, '0 0 0', sw_color, a);
+                       R_PolygonVertex(new_max_end, '0 0 0', sw_color, a);
+                       R_EndPolygon();
+               }
+
+               prev_min_end = new_min_end;
+               prev_max_end = new_max_end;
+
+               // last division only
+               if((counter + 1) == divisions)
+               {
+                       // draw from shot origin to min spread radius
+                       R_BeginPolygon("", DRAWFLAG_NORMAL);
+                       R_PolygonVertex(prev_min_end, '0 0 0', sw_color, a);
+                       R_PolygonVertex(first_min_end, '0 0 0', sw_color, a);
+                       R_PolygonVertex(self.sw_shotorg, '0 0 0', sw_color, a);
+                       R_EndPolygon();
+
+                       // draw from min spread radius to max spread radius
+                       R_BeginPolygon("", DRAWFLAG_NORMAL);
+                       R_PolygonVertex(first_min_end, '0 0 0', sw_color, a);
+                       R_PolygonVertex(prev_min_end, '0 0 0', sw_color, a);
+                       R_PolygonVertex(prev_max_end, '0 0 0', sw_color, a);
+                       R_PolygonVertex(first_max_end, '0 0 0', sw_color, a);
+                       R_EndPolygon();
+               }
+       }
+}
+
+void Net_ReadShockwaveParticle(void)
+{
+       entity shockwave;
+       shockwave = spawn();
+       shockwave.draw = Draw_Shockwave;
+       
+       shockwave.sw_shotorg_x = ReadCoord(); shockwave.sw_shotorg_y = ReadCoord(); shockwave.sw_shotorg_z = ReadCoord();
+       shockwave.sw_shotdir_x  = ReadCoord(); shockwave.sw_shotdir_y  = ReadCoord(); shockwave.sw_shotdir_z  = ReadCoord();
+
+       shockwave.sw_distance = ReadShort();
+       shockwave.sw_spread_max = ReadByte();
+       shockwave.sw_spread_min = ReadByte();
+
+       shockwave.sv_entnum = ReadByte();
+
+       shockwave.sw_time = time;
+}
+
 float W_Shockwave(float req)
 {
        switch(req)
        {
                case WR_IMPACTEFFECT:
                {
-                       vector org2;
-                       org2 = w_org + w_backoff * 2;
-                       pointparticles(particleeffectnum("shockwave_impact"), org2, w_backoff * 1000, 1);
-                       return TRUE;
+                       // handled by Net_ReadShockwaveParticle
+                       //vector org2;
+                       //org2 = w_org + w_backoff * 2;
+                       //pointparticles(particleeffectnum("laser_impact"), org2, w_backoff * 1000, 1);
+                       return FALSE;
                }
                case WR_INIT:
                {
@@ -726,8 +883,13 @@ float W_Shockwave(float req)
                        //precache_sound("weapons/ric3.wav");
                        return FALSE;
                }
+               case WR_ZOOMRETICLE:
+               {
+                       // no weapon specific image for this weapon
+                       return FALSE;
+               }
        }
-       return TRUE;
+       return FALSE;
 }
 #endif
 #endif