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