Xonotic
sv_physical_items.qc
Go to the documentation of this file.
1 #include "sv_physical_items.qh"
2 
6 
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 }
32 
34 
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 }
71 
72 void physical_item_touch(entity this, entity toucher)
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 }
81 
82 void physical_item_damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, .entity weaponentity, vector hitloc, vector force)
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 }
91 
92 MUTATOR_HOOKFUNCTION(physical_items, Item_Spawn)
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 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
entity() spawn
float DAMAGE_AIM
Definition: progsdefs.qc:284
vector spawn_origin
vector spawn_angles
#define droptofloor
Definition: pre.qh:5
entity owner
Definition: main.qh:73
REGISTER_MUTATOR(physical_items, autocvar_g_physical_items)
#define MUTATOR_ONROLLBACK_OR_REMOVE
Definition: base.qh:286
const float EF_NODRAW
Definition: csprogsdefs.qc:305
float cnt
Definition: powerups.qc:24
int autocvar_g_physical_items
float EF_NOMODELFLAGS
#define setSendEntity(e, f)
Definition: self.qh:97
#define NULL
Definition: post.qh:17
#define LOG_INFO(...)
Definition: log.qh:70
#define M_ARGV(x, type)
Definition: events.qh:17
float nextthink
Definition: csprogsdefs.qc:121
vector(float skel, float bonenum) _skel_get_boneabs_hidden
#define ITEM_DAMAGE_NEEDKILL(dt)
Definition: items.qh:130
#define MUTATOR_ONREMOVE
Definition: base.qh:285
#define ITEM_TOUCH_NEEDKILL()
Definition: items.qh:129
void physical_item_think(entity this)
float MOVETYPE_FOLLOW
#define LOG_TRACE(...)
Definition: log.qh:81
float autocvar_g_physical_items_damageforcescale
setorigin(ent, v)
#define setthink(e, f)
vector angles
Definition: csprogsdefs.qc:104
MUTATOR_HOOKFUNCTION(physical_items, Item_Spawn)
void physical_item_touch(entity this, entity toucher)
vector glowmod
#define MUTATOR_ONADD
Definition: base.qh:284
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()
float autocvar_g_physical_items_reset
float solid
Definition: csprogsdefs.qc:99
const float SOLID_CORPSE
Definition: csprogsdefs.qc:249