]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/weapons/common.qc
Merge branch 'master' into martin-t/defaults
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / weapons / common.qc
1 #include "common.qh"
2
3 #include <common/t_items.qh>
4 #include <common/constants.qh>
5 #include <common/net_linked.qh>
6 #include <common/deathtypes/all.qh>
7 #include <common/notifications/all.qh>
8 #include <common/state.qh>
9 #include <common/util.qh>
10 #include <common/weapons/_all.qh>
11 #include <common/items/_mod.qh>
12
13 void W_GiveWeapon(entity e, int wep)
14 {
15         if (!wep) return;
16
17         e.weapons |= WepSet_FromWeapon(Weapons_from(wep));
18
19         if (IS_PLAYER(e)) {
20             Send_Notification(NOTIF_ONE, e, MSG_MULTI, ITEM_WEAPON_GOT, wep);
21     }
22 }
23
24 void W_PlayStrengthSound(entity player)
25 {
26         entity store = IS_PLAYER(player) ? PS(player) : player; // because non-player entities can fire, but can they have items? TODO
27
28         if((player.items & ITEM_Strength.m_itemid)
29                 && ((time > store.prevstrengthsound + autocvar_sv_strengthsound_antispam_time) // prevent insane sound spam
30                 || (time > store.prevstrengthsoundattempt + autocvar_sv_strengthsound_antispam_refire_threshold)))
31                 {
32                         sound(player, CH_TRIGGER, SND_STRENGTH_FIRE, VOL_BASE, ATTEN_NORM);
33                         store.prevstrengthsound = time;
34                 }
35                 store.prevstrengthsoundattempt = time;
36 }
37
38 float W_CheckProjectileDamage(entity inflictor, entity projowner, int deathtype, float exception)
39 {
40         float is_from_contents = (deathtype == DEATH_SLIME.m_id || deathtype == DEATH_LAVA.m_id);
41         float is_from_owner = (inflictor == projowner);
42         float is_from_exception = (exception != -1);
43
44         //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")));
45
46         if(autocvar_g_projectiles_damage <= -2)
47         {
48                 return false; // no damage to projectiles at all, not even with the exceptions
49         }
50         else if(autocvar_g_projectiles_damage == -1)
51         {
52                 if(is_from_exception)
53                         return (exception); // if exception is detected, allow it to override
54                 else
55                         return false; // otherwise, no other damage is allowed
56         }
57         else if(autocvar_g_projectiles_damage == 0)
58         {
59                 if(is_from_exception)
60                         return (exception); // if exception is detected, allow it to override
61                 else if(!is_from_contents)
62                         return false; // otherwise, only allow damage from contents
63         }
64         else if(autocvar_g_projectiles_damage == 1)
65         {
66                 if(is_from_exception)
67                         return (exception); // if exception is detected, allow it to override
68                 else if(!(is_from_contents || is_from_owner))
69                         return false; // otherwise, only allow self damage and damage from contents
70         }
71         else if(autocvar_g_projectiles_damage == 2) // allow any damage, but override for exceptions
72         {
73                 if(is_from_exception)
74                         return (exception); // if exception is detected, allow it to override
75         }
76
77         return true; // if none of these return, then allow damage anyway.
78 }
79
80 void W_PrepareExplosionByDamage(entity this, entity attacker, void(entity this) explode)
81 {
82         this.takedamage = DAMAGE_NO;
83         this.event_damage = func_null;
84
85         if(IS_CLIENT(attacker) && !autocvar_g_projectiles_keep_owner)
86         {
87                 this.owner = attacker;
88                 this.realowner = attacker;
89         }
90
91         MUTATOR_CALLHOOK(PrepareExplosionByDamage, this, attacker);
92
93         // do not explode NOW but in the NEXT FRAME!
94         // because recursive calls to RadiusDamage are not allowed
95         this.nextthink = time;
96         setthink(this, explode);
97 }