]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/csqcprojectile.qc
documented joints
[divverent/nexuiz.git] / data / qcsrc / server / csqcprojectile.qc
1 .float csqcprojectile_type;
2
3 float CSQCProjectile_SendEntity(entity to, float sf)
4 {
5         // note: flag 0x20 = no trail please
6         sf = sf & 0x3F;
7
8         if(self.csqcprojectile_clientanimate)
9                 sf |= 0x80; // client animated, not interpolated
10
11         if(self.flags & FL_ONGROUND)
12                 sf |= 0x40;
13
14         WriteByte(MSG_ENTITY, ENT_CLIENT_PROJECTILE);
15         WriteByte(MSG_ENTITY, sf);
16
17         if(sf & 1)
18         {
19                 WriteCoord(MSG_ENTITY, self.origin_x);
20                 WriteCoord(MSG_ENTITY, self.origin_y);
21                 WriteCoord(MSG_ENTITY, self.origin_z);
22
23                 if(sf & 0x80)
24                 {
25                         WriteCoord(MSG_ENTITY, self.velocity_x);
26                         WriteCoord(MSG_ENTITY, self.velocity_y);
27                         WriteCoord(MSG_ENTITY, self.velocity_z);
28                         WriteCoord(MSG_ENTITY, self.gravity);
29                 }
30         }
31
32         if(sf & 2)
33                 WriteByte(MSG_ENTITY, self.csqcprojectile_type); // TODO maybe put this into sf?
34
35         return 1;
36 }
37
38 .vector csqcprojectile_oldorigin;
39 void CSQCProjectile_Check(entity e)
40 {
41         if(e.csqcprojectile_clientanimate)
42         if(e.flags & FL_ONGROUND)
43         if(e.origin != e.csqcprojectile_oldorigin)
44                 UpdateCSQCProjectile(e);
45         e.csqcprojectile_oldorigin = e.origin;
46 }
47
48 void CSQCProjectile(entity e, float clientanimate, float type, float docull)
49 {
50         Net_LinkEntity(e, docull, 0, CSQCProjectile_SendEntity);
51         
52         e.csqcprojectile_clientanimate = clientanimate;
53         
54         if(e.movetype == MOVETYPE_TOSS || e.movetype == MOVETYPE_BOUNCE)
55         {
56                 if(e.gravity == 0)
57                         e.gravity = 1;
58         }
59         else
60                 e.gravity = 0;
61
62         e.csqcprojectile_type = type;
63         if(!sound_allowed(MSG_BROADCAST, e))
64                 type |= 0x80;
65 }
66
67 void UpdateCSQCProjectile(entity e)
68 {
69         if(e.SendEntity == CSQCProjectile_SendEntity)
70         {
71                 // send new origin data
72                 e.SendFlags |= 1;
73         }
74 }
75
76 void UpdateCSQCProjectileAfterTeleport(entity e)
77 {
78         if(e.SendEntity == CSQCProjectile_SendEntity)
79         {
80                 // send new origin data and mark as teleported
81                 e.SendFlags |= 0x21;
82         }
83 }
84
85 .void(void) csqcprojectile_oldthink;
86 .float csqcprojectile_oldnextthink;
87
88 void CSQCProjectile_Update_Think()
89 {
90         UpdateCSQCProjectile(self);
91         self.think = self.csqcprojectile_oldthink;
92         self.nextthink = max(time, self.csqcprojectile_oldnextthink);
93 }
94
95 void UpdateCSQCProjectileNextFrame(entity e)
96 {
97         if(e.SendEntity == CSQCProjectile_SendEntity)
98         if(e.think != CSQCProjectile_Update_Think)
99         {
100                 e.csqcprojectile_oldthink = e.think;
101                 e.csqcprojectile_oldnextthink = e.nextthink;
102                 e.think = CSQCProjectile_Update_Think;
103                 e.nextthink = time;
104         }
105 }