]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/mutators/mutator_physical_weapons.qc
Properly detect if the item is dropped or not. If some mod ever happens to allow...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / mutators / mutator_physical_weapons.qc
1 .vector spawn_origin, spawn_angles;
2
3 void thrown_wep_ode_think()
4 {
5         self.nextthink = time;
6
7         self.alpha = self.owner.alpha; // apply fading and ghosting
8
9         if(!self.cnt) // map item, not dropped weapon
10         {
11                 // copy ghost item properties
12                 self.colormap = self.owner.colormap;
13                 self.colormod = self.owner.colormod;
14                 self.glowmod = self.owner.glowmod;
15
16                 // if the item is not spawned, make sure the invisible / ghost item returns to its origin and stays there
17                 if(autocvar_g_ode_items_reset)
18                 {
19                         if(self.owner.nextthink > time) // awaiting respawn
20                         {
21                                 setorigin(self, self.spawn_origin);
22                                 self.angles = self.spawn_angles;
23                                 self.solid = SOLID_NOT;
24                                 self.movetype = MOVETYPE_NONE;
25                         }
26                         else
27                         {
28                                 self.solid = SOLID_CORPSE;
29                                 self.movetype = MOVETYPE_PHYSICS;
30                         }
31                 }
32         }
33
34         if(!self.owner.modelindex)
35                 remove(self); // the real weapon is gone, remove this
36 }
37
38 void thrown_wep_ode_touch()
39 {
40         if(!self.cnt) // not for dropped items
41         if (ITEM_TOUCH_NEEDKILL())
42         {
43                 setorigin(self, self.spawn_origin);
44                 self.angles = self.spawn_angles;
45         }
46 }
47
48 MUTATOR_HOOKFUNCTION(item_spawning)
49 {
50         if(self.owner == world && autocvar_g_ode_items <= 1)
51                 return FALSE;
52         if (self.spawnflags & 1) // floating item
53                 return FALSE;
54
55         // The actual item can't be physical and trigger at the same time, so make it invisible and use a second entity for physics.
56         // Ugly hack, but unless SOLID_TRIGGER is gotten to work with MOVETYPE_PHYSICS in the engine it can't be fixed.
57         entity wep;
58         wep = spawn();
59         setmodel(wep, self.model);
60         setsize(wep, self.mins, self.maxs);
61         setorigin(wep, self.origin);
62         wep.angles = self.angles;
63         wep.velocity = self.velocity;
64
65         wep.owner = self;
66         wep.solid = SOLID_CORPSE;
67         wep.movetype = MOVETYPE_PHYSICS;
68         wep.takedamage = DAMAGE_AIM;
69         wep.effects |= EF_NOMODELFLAGS; // disable the spinning
70         wep.colormap = self.owner.colormap;
71         wep.glowmod = self.owner.glowmod;
72         wep.damageforcescale = autocvar_g_ode_items_damageforcescale;
73         wep.dphitcontentsmask = self.dphitcontentsmask;
74         wep.cnt = (self.owner != world);
75
76         wep.think = thrown_wep_ode_think;
77         wep.nextthink = time;
78         wep.touch = thrown_wep_ode_touch;
79
80         wep.spawn_origin = self.origin;
81         wep.spawn_angles = self.angles;
82
83         self.effects |= EF_NODRAW; // hide the original weapon
84         self.movetype = MOVETYPE_FOLLOW;
85         self.aiment = wep; // attach the original weapon
86
87         return FALSE;
88 }
89
90 MUTATOR_DEFINITION(mutator_physical_weapons)
91 {
92         if(!autocvar_physics_ode)
93                 return FALSE;
94
95         MUTATOR_HOOK(Item_Spawn, item_spawning, CBC_ORDER_ANY);
96
97         return FALSE;
98 }