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>
17 bool W_DualWielding(entity player)
20 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
22 .entity weaponentity = weaponentities[slot];
23 if(player.(weaponentity) && player.(weaponentity).m_switchweapon != WEP_Null)
27 return held_weapons > 1;
30 void W_GiveWeapon(entity e, int wep)
34 STAT(WEAPONS, e) |= WepSet_FromWeapon(REGISTRY_GET(Weapons, wep));
37 Send_Notification(NOTIF_ONE, e, MSG_MULTI, ITEM_WEAPON_GOT, wep);
41 void W_PlayStrengthSound(entity player)
43 entity store = IS_PLAYER(player) ? PS(player) : player; // because non-player entities can fire, but can they have items? TODO
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)))
49 sound(player, CH_TRIGGER, SND_STRENGTH_FIRE, VOL_BASE, ATTEN_NORM);
50 store.prevstrengthsound = time;
52 store.prevstrengthsoundattempt = time;
55 float W_CheckProjectileDamage(entity inflictor, entity projowner, int deathtype, float exception)
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);
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")));
63 if(autocvar_g_projectiles_damage <= -2)
65 return false; // no damage to projectiles at all, not even with the exceptions
67 else if(autocvar_g_projectiles_damage == -1)
70 return (exception); // if exception is detected, allow it to override
72 return false; // otherwise, no other damage is allowed
74 else if(autocvar_g_projectiles_damage == 0)
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
81 else if(autocvar_g_projectiles_damage == 1)
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
88 else if(autocvar_g_projectiles_damage == 2) // allow any damage, but override for exceptions
91 return (exception); // if exception is detected, allow it to override
94 return true; // if none of these return, then allow damage anyway.
97 void W_PrepareExplosionByDamage(entity this, entity attacker, void(entity this) explode)
99 this.takedamage = DAMAGE_NO;
100 this.event_damage = func_null;
102 MUTATOR_CALLHOOK(PrepareExplosionByDamage, this, attacker);
104 if(IS_CLIENT(attacker) && !autocvar_g_projectiles_keep_owner)
106 this.owner = attacker;
107 this.realowner = attacker;
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);