Xonotic
sv_physical_items.qc File Reference
+ Include dependency graph for sv_physical_items.qc:

Go to the source code of this file.

Functions

 MUTATOR_HOOKFUNCTION (physical_items, Item_Spawn)
 
void physical_item_damage (entity this, entity inflictor, entity attacker, float damage, int deathtype,.entity weaponentity, vector hitloc, vector force)
 
void physical_item_think (entity this)
 
void physical_item_touch (entity this, entity toucher)
 
 REGISTER_MUTATOR (physical_items, autocvar_g_physical_items)
 

Variables

int autocvar_g_physical_items
 
float autocvar_g_physical_items_damageforcescale
 
float autocvar_g_physical_items_reset
 
vector spawn_angles
 
vector spawn_origin
 

Function Documentation

◆ MUTATOR_HOOKFUNCTION()

MUTATOR_HOOKFUNCTION ( physical_items  ,
Item_Spawn   
)

Definition at line 92 of file sv_physical_items.qc.

References autocvar_g_physical_items, autocvar_g_physical_items_damageforcescale, DAMAGE_AIM, droptofloor, EF_NODRAW, EF_NOMODELFLAGS, entity(), func_null(), M_ARGV, MOVETYPE_FOLLOW, MOVETYPE_PHYSICS, NULL, physical_item_damage(), physical_item_think(), physical_item_touch(), set_movetype(), setorigin(), setSendEntity, setthink, SOLID_CORPSE, spawn(), and time.

93 {
94  entity item = M_ARGV(0, entity);
95 
96  if(item.owner == NULL && autocvar_g_physical_items <= 1)
97  return;
98  if (item.spawnflags & 1) // floating item
99  return;
100 
101  // The actual item can't be physical and trigger at the same time, so make it invisible and use a second entity for physics.
102  // Ugly hack, but unless SOLID_TRIGGER is gotten to work with MOVETYPE_PHYSICS in the engine it can't be fixed.
103  entity wep = spawn();
104  _setmodel(wep, item.model);
105  setsize(wep, item.mins, item.maxs);
106  setorigin(wep, item.origin);
107  wep.angles = item.angles;
108  wep.velocity = item.velocity;
109 
110  wep.owner = item;
111  wep.solid = SOLID_CORPSE;
113  wep.takedamage = DAMAGE_AIM;
114  wep.effects |= EF_NOMODELFLAGS; // disable the spinning
115  wep.colormap = item.owner.colormap;
116  wep.glowmod = item.owner.glowmod;
117  wep.damageforcescale = autocvar_g_physical_items_damageforcescale;
118  wep.dphitcontentsmask = item.dphitcontentsmask;
119  wep.cnt = (item.owner != NULL);
120 
122  wep.nextthink = time;
123  settouch(wep, physical_item_touch);
124  wep.event_damage = physical_item_damage;
125 
126  if(!wep.cnt)
127  {
128  // fix the spawn origin
129  setorigin(wep, wep.origin + '0 0 1');
130  droptofloor(wep);
131  }
132 
133  wep.spawn_origin = wep.origin;
134  wep.spawn_angles = item.angles;
135 
136  item.effects |= EF_NODRAW; // hide the original weapon
138  item.aiment = wep; // attach the original weapon
139  setSendEntity(item, func_null);
140 }
const float MOVETYPE_PHYSICS
entity() spawn
float DAMAGE_AIM
Definition: progsdefs.qc:284
#define droptofloor
Definition: pre.qh:5
const float EF_NODRAW
Definition: csprogsdefs.qc:305
int autocvar_g_physical_items
float EF_NOMODELFLAGS
#define setSendEntity(e, f)
Definition: self.qh:97
#define NULL
Definition: post.qh:17
#define M_ARGV(x, type)
Definition: events.qh:17
void physical_item_think(entity this)
float MOVETYPE_FOLLOW
float autocvar_g_physical_items_damageforcescale
setorigin(ent, v)
#define setthink(e, f)
void physical_item_touch(entity this, entity toucher)
void physical_item_damage(entity this, entity inflictor, entity attacker, float damage, int deathtype,.entity weaponentity, vector hitloc, vector force)
float time
Definition: csprogsdefs.qc:16
void set_movetype(entity this, int mt)
var void func_null()
const float SOLID_CORPSE
Definition: csprogsdefs.qc:249
+ Here is the call graph for this function:

◆ physical_item_damage()

void physical_item_damage ( entity  this,
entity  inflictor,
entity  attacker,
float  damage,
int  deathtype,
.entity  weaponentity,
vector  hitloc,
vector  force 
)

Definition at line 82 of file sv_physical_items.qc.

References angles, cnt, ITEM_DAMAGE_NEEDKILL, setorigin(), spawn_angles, and spawn_origin.

Referenced by MUTATOR_HOOKFUNCTION().

83 {
84  if(!this.cnt) // not for dropped items
85  if(ITEM_DAMAGE_NEEDKILL(deathtype))
86  {
87  setorigin(this, this.spawn_origin);
88  this.angles = this.spawn_angles;
89  }
90 }
vector spawn_origin
vector spawn_angles
float cnt
Definition: powerups.qc:24
#define ITEM_DAMAGE_NEEDKILL(dt)
Definition: items.qh:130
setorigin(ent, v)
vector angles
Definition: csprogsdefs.qc:104
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ physical_item_think()

void physical_item_think ( entity  this)

Definition at line 35 of file sv_physical_items.qc.

References alpha, angles, autocvar_g_physical_items_reset, cnt, colormap, colormod, glowmod, MOVETYPE_NONE, MOVETYPE_PHYSICS, nextthink, owner, set_movetype(), setorigin(), solid, SOLID_CORPSE, SOLID_NOT, spawn_angles, spawn_origin, and time.

Referenced by MUTATOR_HOOKFUNCTION().

36 {
37  this.nextthink = time;
38 
39  this.alpha = this.owner.alpha; // apply fading and ghosting
40 
41  if(!this.cnt) // map item, not dropped
42  {
43  // copy ghost item properties
44  this.colormap = this.owner.colormap;
45  this.colormod = this.owner.colormod;
46  this.glowmod = this.owner.glowmod;
47 
48  // if the item is not spawned, make sure the invisible / ghost item returns to its origin and stays there
50  {
51  if(this.owner.wait > time) // awaiting respawn
52  {
53  setorigin(this, this.spawn_origin);
54  this.angles = this.spawn_angles;
55  this.solid = SOLID_NOT;
56  this.alpha = -1;
58  }
59  else
60  {
61  this.alpha = 1;
62  this.solid = SOLID_CORPSE;
64  }
65  }
66  }
67 
68  if(!this.owner.modelindex)
69  delete(this); // the real item is gone, remove this
70 }
const float SOLID_NOT
Definition: csprogsdefs.qc:244
float MOVETYPE_NONE
Definition: progsdefs.qc:246
float colormap
Definition: csprogsdefs.qc:131
float alpha
Definition: items.qc:14
vector colormod
Definition: powerups.qc:21
const float MOVETYPE_PHYSICS
vector spawn_origin
vector spawn_angles
entity owner
Definition: main.qh:73
float cnt
Definition: powerups.qc:24
float nextthink
Definition: csprogsdefs.qc:121
setorigin(ent, v)
vector angles
Definition: csprogsdefs.qc:104
vector glowmod
float time
Definition: csprogsdefs.qc:16
void set_movetype(entity this, int mt)
float autocvar_g_physical_items_reset
float solid
Definition: csprogsdefs.qc:99
const float SOLID_CORPSE
Definition: csprogsdefs.qc:249
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ physical_item_touch()

void physical_item_touch ( entity  this,
entity  toucher 
)

Definition at line 72 of file sv_physical_items.qc.

References angles, cnt, ITEM_TOUCH_NEEDKILL, setorigin(), spawn_angles, and spawn_origin.

Referenced by MUTATOR_HOOKFUNCTION().

73 {
74  if(!this.cnt) // not for dropped items
75  if (ITEM_TOUCH_NEEDKILL())
76  {
77  setorigin(this, this.spawn_origin);
78  this.angles = this.spawn_angles;
79  }
80 }
vector spawn_origin
vector spawn_angles
float cnt
Definition: powerups.qc:24
#define ITEM_TOUCH_NEEDKILL()
Definition: items.qh:129
setorigin(ent, v)
vector angles
Definition: csprogsdefs.qc:104
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ REGISTER_MUTATOR()

REGISTER_MUTATOR ( physical_items  ,
autocvar_g_physical_items   
)

Definition at line 7 of file sv_physical_items.qc.

References checkextension(), LOG_INFO, LOG_TRACE, MUTATOR_ONADD, MUTATOR_ONREMOVE, and MUTATOR_ONROLLBACK_OR_REMOVE.

8 {
9  // check if we have a physics engine
11  {
12  if (!(autocvar_physics_ode && checkextension("DP_PHYSICS_ODE")))
13  {
14  LOG_TRACE("Warning: Physical items are enabled but no physics engine can be used. Reverting to old items.");
15  return -1;
16  }
17  }
18 
20  {
21  // nothing to roll back
22  }
23 
25  {
26  LOG_INFO("This cannot be removed at runtime");
27  return -1;
28  }
29 
30  return 0;
31 }
#define MUTATOR_ONROLLBACK_OR_REMOVE
Definition: base.qh:286
#define LOG_INFO(...)
Definition: log.qh:70
#define MUTATOR_ONREMOVE
Definition: base.qh:285
#define LOG_TRACE(...)
Definition: log.qh:81
#define MUTATOR_ONADD
Definition: base.qh:284
+ Here is the call graph for this function:

Variable Documentation

◆ autocvar_g_physical_items

int autocvar_g_physical_items

Definition at line 3 of file sv_physical_items.qc.

Referenced by MUTATOR_HOOKFUNCTION().

◆ autocvar_g_physical_items_damageforcescale

float autocvar_g_physical_items_damageforcescale

Definition at line 4 of file sv_physical_items.qc.

Referenced by MUTATOR_HOOKFUNCTION().

◆ autocvar_g_physical_items_reset

float autocvar_g_physical_items_reset

Definition at line 5 of file sv_physical_items.qc.

Referenced by physical_item_think().

◆ spawn_angles

vector spawn_angles

◆ spawn_origin

vector spawn_origin