]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/mutators/mutator_physical_items.qc
Replace print calls with logger calls
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / mutators / mutator_physical_items.qc
1 #include "../_all.qh"
2
3 #include "mutator.qh"
4
5 .vector spawn_origin, spawn_angles;
6
7 void physical_item_think()
8 {
9         self.nextthink = time;
10
11         self.alpha = self.owner.alpha; // apply fading and ghosting
12
13         if(!self.cnt) // map item, not dropped
14         {
15                 // copy ghost item properties
16                 self.colormap = self.owner.colormap;
17                 self.colormod = self.owner.colormod;
18                 self.glowmod = self.owner.glowmod;
19
20                 // if the item is not spawned, make sure the invisible / ghost item returns to its origin and stays there
21                 if(autocvar_g_physical_items_reset)
22                 {
23                         if(self.owner.nextthink > time) // awaiting respawn
24                         {
25                                 setorigin(self, self.spawn_origin);
26                                 self.angles = self.spawn_angles;
27                                 self.solid = SOLID_NOT;
28                                 self.movetype = MOVETYPE_NONE;
29                         }
30                         else
31                         {
32                                 self.solid = SOLID_CORPSE;
33                                 self.movetype = MOVETYPE_PHYSICS;
34                         }
35                 }
36         }
37
38         if(!self.owner.modelindex)
39                 remove(self); // the real item is gone, remove this
40 }
41
42 void physical_item_touch()
43 {
44         if(!self.cnt) // not for dropped items
45         if (ITEM_TOUCH_NEEDKILL())
46         {
47                 setorigin(self, self.spawn_origin);
48                 self.angles = self.spawn_angles;
49         }
50 }
51
52 void physical_item_damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
53 {
54         if(!self.cnt) // not for dropped items
55         if(ITEM_DAMAGE_NEEDKILL(deathtype))
56         {
57                 setorigin(self, self.spawn_origin);
58                 self.angles = self.spawn_angles;
59         }
60 }
61
62 MUTATOR_HOOKFUNCTION(item_spawning)
63 {
64         if(self.owner == world && autocvar_g_physical_items <= 1)
65                 return false;
66         if (self.spawnflags & 1) // floating item
67                 return false;
68
69         // The actual item can't be physical and trigger at the same time, so make it invisible and use a second entity for physics.
70         // Ugly hack, but unless SOLID_TRIGGER is gotten to work with MOVETYPE_PHYSICS in the engine it can't be fixed.
71         entity wep;
72         wep = spawn();
73         setmodel(wep, self.model);
74         setsize(wep, self.mins, self.maxs);
75         setorigin(wep, self.origin);
76         wep.angles = self.angles;
77         wep.velocity = self.velocity;
78
79         wep.owner = self;
80         wep.solid = SOLID_CORPSE;
81         wep.movetype = MOVETYPE_PHYSICS;
82         wep.takedamage = DAMAGE_AIM;
83         wep.effects |= EF_NOMODELFLAGS; // disable the spinning
84         wep.colormap = self.owner.colormap;
85         wep.glowmod = self.owner.glowmod;
86         wep.damageforcescale = autocvar_g_physical_items_damageforcescale;
87         wep.dphitcontentsmask = self.dphitcontentsmask;
88         wep.cnt = (self.owner != world);
89
90         wep.think = physical_item_think;
91         wep.nextthink = time;
92         wep.touch = physical_item_touch;
93         wep.event_damage = physical_item_damage;
94
95         wep.spawn_origin = self.origin;
96         wep.spawn_angles = self.angles;
97
98         self.effects |= EF_NODRAW; // hide the original weapon
99         self.movetype = MOVETYPE_FOLLOW;
100         self.aiment = wep; // attach the original weapon
101
102         return false;
103 }
104
105 MUTATOR_DEFINITION(mutator_physical_items)
106 {
107         MUTATOR_HOOK(Item_Spawn, item_spawning, CBC_ORDER_ANY);
108
109         // check if we have a physics engine
110         MUTATOR_ONADD
111         {
112                 if (!(autocvar_physics_ode && checkextension("DP_PHYSICS_ODE")))
113                 {
114                         LOG_TRACE("Warning: Physical items are enabled but no physics engine can be used. Reverting to old items.\n");
115                         return -1;
116                 }
117         }
118
119         MUTATOR_ONROLLBACK_OR_REMOVE
120         {
121                 // nothing to roll back
122         }
123
124         MUTATOR_ONREMOVE
125         {
126                 LOG_INFO("This cannot be removed at runtime\n");
127                 return -1;
128         }
129
130         return 0;
131 }