Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
sv_physical_items.qc
Go to the documentation of this file.
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
73{
74 if(!this.cnt) // not for dropped items
76 {
77 setorigin(this, this.spawn_origin);
78 this.angles = this.spawn_angles;
79 }
80}
81
82void 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
92MUTATOR_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;
124 wep.event_damage = physical_item_damage;
125
126 if(!wep.cnt)
128
129 wep.spawn_origin = wep.origin;
130 wep.spawn_angles = item.angles;
131
132 item.effects |= EF_NODRAW; // hide the original weapon
134 item.aiment = wep; // attach the original weapon
136}
#define MUTATOR_ONADD
Definition base.qh:309
#define MUTATOR_ONROLLBACK_OR_REMOVE
Definition base.qh:311
#define REGISTER_MUTATOR(...)
Definition base.qh:295
#define MUTATOR_HOOKFUNCTION(...)
Definition base.qh:335
#define MUTATOR_ONREMOVE
Definition base.qh:310
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
float cnt
Definition powerups.qc:24
vector colormod
Definition powerups.qc:21
float alpha
Definition items.qc:13
entity owner
Definition main.qh:87
#define M_ARGV(x, type)
Definition events.qh:17
const float SOLID_CORPSE
const float SOLID_NOT
float time
float nextthink
float colormap
const float EF_NODRAW
#define spawn
vector glowmod
float EF_NOMODELFLAGS
ent angles
Definition ent_cs.qc:121
solid
Definition ent_cs.qc:165
#define LOG_INFO(...)
Definition log.qh:65
#define LOG_TRACE(...)
Definition log.qh:76
float checkextension(string ext)
void set_movetype(entity this, int mt)
Definition movetypes.qc:4
const int MOVETYPE_NONE
Definition movetypes.qh:129
const int MOVETYPE_FOLLOW
Definition movetypes.qh:141
const int MOVETYPE_PHYSICS
Definition movetypes.qh:142
bool autocvar_physics_ode
Definition movetypes.qh:5
var void func_null()
#define NULL
Definition post.qh:14
#define setSendEntity(e, f)
#define setthink(e, f)
vector
Definition self.qh:92
entity entity toucher
Definition self.qh:72
#define settouch(e, f)
Definition self.qh:73
#define ITEM_TOUCH_NEEDKILL()
Definition items.qh:128
#define ITEM_DAMAGE_NEEDKILL(dt)
Definition items.qh:129
const int DAMAGE_AIM
Definition subs.qh:81
vector spawn_origin
int autocvar_g_physical_items
float autocvar_g_physical_items_damageforcescale
void physical_item_damage(entity this, entity inflictor, entity attacker, float damage, int deathtype,.entity weaponentity, vector hitloc, vector force)
vector spawn_angles
float autocvar_g_physical_items_reset
void physical_item_think(entity this)
void physical_item_touch(entity this, entity toucher)
void DropToFloor_QC_DelayedInit(entity this)
Definition world.qc:2407