Xonotic
common.qc
Go to the documentation of this file.
1 #include "common.qh"
2 
3 #include <common/constants.qh>
5 #include <common/items/_mod.qh>
6 #include <common/net_linked.qh>
8 #include <common/state.qh>
9 #include <common/stats.qh>
10 #include <common/util.qh>
11 #include <common/weapons/_all.qh>
12 #include <common/wepent.qh>
13 #include <server/command/common.qh>
14 #include <server/damage.qh>
15 #include <server/hook.qh>
16 #include <server/items/items.qh>
17 #include <server/mutators/_mod.qh>
19 
20 bool W_DualWielding(entity player)
21 {
22  int held_weapons = 0;
23  for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
24  {
25  .entity weaponentity = weaponentities[slot];
26  if(player.(weaponentity) && player.(weaponentity).m_switchweapon != WEP_Null)
27  ++held_weapons;
28  }
29 
30  return held_weapons > 1;
31 }
32 
33 void W_GiveWeapon(entity e, int wep)
34 {
35  if (!wep) return;
36 
37  STAT(WEAPONS, e) |= WepSet_FromWeapon(REGISTRY_GET(Weapons, wep));
38 
39  if (IS_PLAYER(e)) {
40  Send_Notification(NOTIF_ONE, e, MSG_MULTI, ITEM_WEAPON_GOT, wep);
41  }
42 }
43 
45 {
47 }
48 
49 float W_CheckProjectileDamage(entity inflictor, entity projowner, int deathtype, float exception)
50 {
51  float is_from_contents = (deathtype == DEATH_SLIME.m_id || deathtype == DEATH_LAVA.m_id);
52  float is_from_owner = (inflictor == projowner);
53  float is_from_exception = (exception != -1);
54 
55  //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")));
56 
58  {
59  return false; // no damage to projectiles at all, not even with the exceptions
60  }
61  else if(autocvar_g_projectiles_damage == -1)
62  {
63  if(is_from_exception)
64  return (exception); // if exception is detected, allow it to override
65  else
66  return false; // otherwise, no other damage is allowed
67  }
68  else if(autocvar_g_projectiles_damage == 0)
69  {
70  if(is_from_exception)
71  return (exception); // if exception is detected, allow it to override
72  else if(!is_from_contents)
73  return false; // otherwise, only allow damage from contents
74  }
75  else if(autocvar_g_projectiles_damage == 1)
76  {
77  if(is_from_exception)
78  return (exception); // if exception is detected, allow it to override
79  else if(!(is_from_contents || is_from_owner))
80  return false; // otherwise, only allow self damage and damage from contents
81  }
82  else if(autocvar_g_projectiles_damage == 2) // allow any damage, but override for exceptions
83  {
84  if(is_from_exception)
85  return (exception); // if exception is detected, allow it to override
86  }
87 
88  return true; // if none of these return, then allow damage anyway.
89 }
90 
91 void W_PrepareExplosionByDamage(entity this, entity attacker, void(entity this) explode)
92 {
93  this.takedamage = DAMAGE_NO;
94  this.event_damage = func_null;
95 
96  MUTATOR_CALLHOOK(PrepareExplosionByDamage, this, attacker);
97 
99  {
100  this.owner = attacker;
101  this.realowner = attacker;
102  }
103 
104  // do not explode NOW but in the NEXT FRAME!
105  // because recursive calls to RadiusDamage are not allowed
106  this.nextthink = time;
107  setthink(this, explode);
108 }
109 
110 void adaptor_think2use_hittype_splash(entity this) // for timed projectile detonation
111 {
112  if(!(IS_ONGROUND(this))) // if onground, we ARE touching something, but HITTYPE_SPLASH is to be networked if the damage causing projectile is not touching ANYTHING
114  adaptor_think2use(this);
115 }
116 
117 bool SUB_NoImpactCheck(entity this, entity toucher)
118 {
119  // zero hitcontents = this is not the real impact, but either the
120  // mirror-impact of something hitting the projectile instead of the
121  // projectile hitting the something, or a touchareagrid one. Neither of
122  // these stop the projectile from moving, so...
123  if(trace_dphitcontents == 0)
124  {
125  LOG_TRACEF("A hit from a projectile happened with no hit contents! DEBUG THIS, this should never happen for projectiles! Projectile will self-destruct. (edict: %i, classname: %s, origin: %v)", this, this.classname, this.origin);
126  checkclient(this); // TODO: .health is checked in the engine with this, possibly replace with a QC function?
127  }
129  return true;
130  if (toucher == NULL && this.size != '0 0 0')
131  {
132  vector tic;
133  tic = this.velocity * sys_frametime;
134  tic = tic + normalize(tic) * vlen(this.maxs - this.mins);
135  traceline(this.origin - tic, this.origin + tic, MOVE_NORMAL, this);
136  if (trace_fraction >= 1)
137  {
138  LOG_TRACE("Odd... did not hit...?");
139  }
140  else if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
141  {
142  LOG_TRACE("Detected and prevented the sky-grapple bug.");
143  return true;
144  }
145  }
146 
147  return false;
148 }
149 
151 {
152  // owner check
153  if(toucher && toucher == this.owner)
154  return true;
155  if(SUB_NoImpactCheck(this, toucher))
156  {
157  if(this.classname == "nade")
158  return false; // no checks here
159  else if(this.classname == "grapplinghook")
160  RemoveHook(this);
161  else
162  delete(this);
163  return true;
164  }
165  if(trace_ent && trace_ent.solid > SOLID_TRIGGER)
166  UpdateCSQCProjectile(this);
167  return false;
168 }
const int HITTYPE_SPLASH
automatically set by RadiusDamage
Definition: all.qh:27
#define checkclient
Definition: pre.qh:4
bool SUB_NoImpactCheck(entity this, entity toucher)
Definition: common.qc:117
float trace_dphitq3surfaceflags
#define IS_CLIENT(v)
Definition: utils.qh:13
float W_CheckProjectileDamage(entity inflictor, entity projowner, int deathtype, float exception)
Definition: common.qc:49
float trace_dphitcontents
entity() spawn
#define REGISTRY_GET(id, i)
Definition: registry.qh:43
const float MOVE_NORMAL
Definition: csprogsdefs.qc:252
#define IS_ONGROUND(s)
Definition: movetypes.qh:16
vector maxs
Definition: csprogsdefs.qc:113
origin
Definition: ent_cs.qc:114
bool WarpZone_Projectile_Touch_ImpactFilter_Callback(entity this, entity toucher)
Definition: common.qc:150
string classname
Definition: csprogsdefs.qc:107
vector size
Definition: csprogsdefs.qc:114
bool autocvar_g_projectiles_keep_owner
Definition: common.qh:4
entity owner
Definition: main.qh:73
entity trace_ent
Definition: csprogsdefs.qc:40
float sys_frametime
Definition: common.qh:57
vector mins
Definition: csprogsdefs.qc:113
void W_PlayStrengthSound(entity player)
Definition: common.qc:44
void UpdateCSQCProjectile(entity e)
bool W_DualWielding(entity player)
Definition: common.qc:20
void W_GiveWeapon(entity e, int wep)
Definition: common.qc:33
const int MAX_WEAPONSLOTS
Definition: weapon.qh:13
void W_PrepareExplosionByDamage(entity this, entity attacker, void(entity this) explode)
Definition: common.qc:91
#define NULL
Definition: post.qh:17
#define LOG_TRACEF(...)
Definition: log.qh:82
float takedamage
Definition: progsdefs.qc:147
int autocvar_g_projectiles_damage
Definition: common.qh:3
float Q3SURFACEFLAG_NOIMPACT
float nextthink
Definition: csprogsdefs.qc:121
vector(float skel, float bonenum) _skel_get_boneabs_hidden
#define LOG_TRACE(...)
Definition: log.qh:81
const float SOLID_TRIGGER
Definition: csprogsdefs.qc:245
entity realowner
Definition: common.qh:25
#define MUTATOR_CALLHOOK(id,...)
Definition: base.qh:140
entity weaponentities[MAX_WEAPONSLOTS]
Definition: weapon.qh:14
#define setthink(e, f)
void adaptor_think2use_hittype_splash(entity this)
Definition: common.qc:110
#define WepSet_FromWeapon(it)
Definition: all.qh:38
float time
Definition: csprogsdefs.qc:16
vector velocity
Definition: csprogsdefs.qc:103
float trace_fraction
Definition: csprogsdefs.qc:36
float DAMAGE_NO
Definition: progsdefs.qc:282
#define IS_PLAYER(v)
Definition: utils.qh:9
var void func_null()
void RemoveHook(entity this)
Definition: hook.qc:96
int projectiledeathtype
Definition: common.qh:20