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