2 REGISTER_MUTATOR(physical_items, cvar("g_physical_items"))
4 // check if we have a physics engine
7 if (!(autocvar_physics_ode && checkextension("DP_PHYSICS_ODE")))
9 LOG_TRACE("Warning: Physical items are enabled but no physics engine can be used. Reverting to old items.\n");
14 MUTATOR_ONROLLBACK_OR_REMOVE
16 // nothing to roll back
21 LOG_INFO("This cannot be removed at runtime\n");
28 .vector spawn_origin, spawn_angles;
30 void physical_item_think()
32 self.nextthink = time;
34 self.alpha = self.owner.alpha; // apply fading and ghosting
36 if(!self.cnt) // map item, not dropped
38 // copy ghost item properties
39 self.colormap = self.owner.colormap;
40 self.colormod = self.owner.colormod;
41 self.glowmod = self.owner.glowmod;
43 // if the item is not spawned, make sure the invisible / ghost item returns to its origin and stays there
44 if(autocvar_g_physical_items_reset)
46 if(self.owner.wait > time) // awaiting respawn
48 setorigin(self, self.spawn_origin);
49 self.angles = self.spawn_angles;
50 self.solid = SOLID_NOT;
52 self.movetype = MOVETYPE_NONE;
57 self.solid = SOLID_CORPSE;
58 self.movetype = MOVETYPE_PHYSICS;
63 if(!self.owner.modelindex)
64 remove(self); // the real item is gone, remove this
67 void physical_item_touch()
69 if(!self.cnt) // not for dropped items
70 if (ITEM_TOUCH_NEEDKILL())
72 setorigin(self, self.spawn_origin);
73 self.angles = self.spawn_angles;
77 void physical_item_damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
79 if(!self.cnt) // not for dropped items
80 if(ITEM_DAMAGE_NEEDKILL(deathtype))
82 setorigin(self, self.spawn_origin);
83 self.angles = self.spawn_angles;
87 MUTATOR_HOOKFUNCTION(physical_items, Item_Spawn)
89 if(self.owner == world && autocvar_g_physical_items <= 1)
91 if (self.spawnflags & 1) // floating item
94 // The actual item can't be physical and trigger at the same time, so make it invisible and use a second entity for physics.
95 // Ugly hack, but unless SOLID_TRIGGER is gotten to work with MOVETYPE_PHYSICS in the engine it can't be fixed.
98 _setmodel(wep, self.model);
99 setsize(wep, self.mins, self.maxs);
100 setorigin(wep, self.origin);
101 wep.angles = self.angles;
102 wep.velocity = self.velocity;
105 wep.solid = SOLID_CORPSE;
106 wep.movetype = MOVETYPE_PHYSICS;
107 wep.takedamage = DAMAGE_AIM;
108 wep.effects |= EF_NOMODELFLAGS; // disable the spinning
109 wep.colormap = self.owner.colormap;
110 wep.glowmod = self.owner.glowmod;
111 wep.damageforcescale = autocvar_g_physical_items_damageforcescale;
112 wep.dphitcontentsmask = self.dphitcontentsmask;
113 wep.cnt = (self.owner != world);
115 wep.think = physical_item_think;
116 wep.nextthink = time;
117 wep.touch = physical_item_touch;
118 wep.event_damage = physical_item_damage;
122 // fix the spawn origin
123 setorigin(wep, wep.origin + '0 0 1');
126 WITH(entity, self, wep, builtin_droptofloor());
129 wep.spawn_origin = wep.origin;
130 wep.spawn_angles = self.angles;
132 self.effects |= EF_NODRAW; // hide the original weapon
133 self.movetype = MOVETYPE_FOLLOW;
134 self.aiment = wep; // attach the original weapon
135 self.SendEntity = func_null;