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