]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/weapons/common.qc
(Untested) Merge branch 'master' into Mario/overkill
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / weapons / common.qc
1
2 void W_GiveWeapon (entity e, float wep)
3 {
4         entity oldself;
5
6         if (!wep)
7                 return;
8
9         e.weapons |= WepSet_FromWeapon(wep);
10
11         oldself = self;
12         self = e;
13
14         if(IS_PLAYER(other))
15                 { Send_Notification(NOTIF_ONE, other, MSG_MULTI, ITEM_WEAPON_GOT, wep); }
16
17         self = oldself;
18 }
19
20 void W_PlayStrengthSound(entity player) // void W_PlayStrengthSound
21 {
22         if((player.items & IT_STRENGTH)
23                 && ((time > player.prevstrengthsound + autocvar_sv_strengthsound_antispam_time) // prevent insane sound spam
24                 || (time > player.prevstrengthsoundattempt + autocvar_sv_strengthsound_antispam_refire_threshold)))
25                 {
26                         sound(player, CH_TRIGGER, "weapons/strength_fire.wav", VOL_BASE, ATTEN_NORM);
27                         player.prevstrengthsound = time;
28                 }
29                 player.prevstrengthsoundattempt = time;
30 }
31
32 float W_CheckProjectileDamage(entity inflictor, entity projowner, float deathtype, float exception)
33 {
34         float is_from_contents = (deathtype == DEATH_SLIME || deathtype == DEATH_LAVA);
35         float is_from_owner = (inflictor == projowner);
36         float is_from_exception = (exception != -1);
37         
38         //dprint(strcat("W_CheckProjectileDamage: from_contents ", ftos(is_from_contents), " : from_owner ", ftos(is_from_owner), " : exception ", strcat(ftos(is_from_exception), " (", ftos(exception), "). \n")));
39
40         if(autocvar_g_projectiles_damage <= -2)
41         {
42                 return FALSE; // no damage to projectiles at all, not even with the exceptions
43         }
44         else if(autocvar_g_projectiles_damage == -1)
45         {
46                 if(is_from_exception)
47                         return (exception); // if exception is detected, allow it to override
48                 else
49                         return FALSE; // otherwise, no other damage is allowed
50         }
51         else if(autocvar_g_projectiles_damage == 0)
52         {
53                 if(is_from_exception)
54                         return (exception); // if exception is detected, allow it to override
55                 else if(!is_from_contents)
56                         return FALSE; // otherwise, only allow damage from contents
57         }       
58         else if(autocvar_g_projectiles_damage == 1)
59         {
60                 if(is_from_exception)
61                         return (exception); // if exception is detected, allow it to override
62                 else if(!(is_from_contents || is_from_owner))
63                         return FALSE; // otherwise, only allow self damage and damage from contents
64         }
65         else if(autocvar_g_projectiles_damage == 2) // allow any damage, but override for exceptions
66         {
67                 if(is_from_exception)
68                         return (exception); // if exception is detected, allow it to override
69         }
70
71         return TRUE; // if none of these return, then allow damage anyway.
72 }
73
74 void W_PrepareExplosionByDamage(entity attacker, void() explode)
75 {
76         self.takedamage = DAMAGE_NO;
77         self.event_damage = func_null;
78         
79         if(IS_CLIENT(attacker) && !autocvar_g_projectiles_keep_owner)
80         {
81                 self.owner = attacker;
82                 self.realowner = attacker;
83         }
84         
85         // do not explode NOW but in the NEXT FRAME!
86         // because recursive calls to RadiusDamage are not allowed
87         self.nextthink = time;
88         self.think = explode;
89 }