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