]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/vehicles/network.qc
Merge branch 'master' into terencehill/physics_panel_updates
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / vehicles / network.qc
1 #ifdef VEHICLES_CSQC
2 // SendFlags
3 float VSF_SETUP       = 1;          /// Send vehicle type etc
4 float VSF_ORIGIN      = 2;          /// Send location
5 float VSF_MOVEMENT    = 4;          /// Send movement update (and angles)
6 float VSF_AVEL        = 8;          /// Send Angular velocity
7 float VSF_STATS       = 16;         /// Send ammo, health etc
8 float VSF_EXTRA       = 32;         /// Send additional data (turret rotations etc). Handeld per vehicle type.
9 float VSF_ANIMINFO    = 64;         /// Animation info
10 float VSF_FULL_UPDATE = 16777215;    /// Send everything
11
12 float VSX_FAR   = 1;
13 float VSX_OWNER = 2;
14 float VSX_GUN1  = 4;
15 float VSX_GUN2  = 8;
16
17 #ifdef SVQC
18 #define VSX_FARDISTANCE 2000
19 float send_vehile(entity to, float sf)
20 {
21         float dist, xf;
22
23     var void WriteFunc(float, float);
24
25     dist = vlen(self.origin - to.origin);
26     if(to == self.owner)
27         xf |= VSX_OWNER;
28     else if(dist > VSX_FARDISTANCE)
29         xf |= VSX_FAR;
30
31         // Always send a movement and origin to owner
32         if(to == self.owner)
33             sf |= VSF_ORIGIN | VSF_MOVEMENT;
34
35         WriteByte(MSG_ENTITY, ENT_CLIENT_VEHICLE);
36
37         // We need to know client-side what was sent
38         WriteByte(MSG_ENTITY, sf);
39         WriteByte(MSG_ENTITY, xf);
40
41         if(sf & VSF_SETUP)
42         {
43         WriteByte(MSG_ENTITY,  self.hud);        //vehicle type = hud
44         WriteByte(MSG_ENTITY,  self.team);
45         WriteShort(MSG_ENTITY, self.colormap);
46         WriteShort(MSG_ENTITY, self.vehicle_flags);
47         }
48
49     if(sf & VSF_ORIGIN)
50     {
51         WriteFunc = ((xf & VSX_FAR) ? WriteShort : WriteCoord);
52         WriteFunc(MSG_ENTITY, self.origin_x);
53         WriteFunc(MSG_ENTITY, self.origin_y);
54         WriteFunc(MSG_ENTITY, self.origin_z);
55     }
56
57     if(sf & VSF_MOVEMENT)
58     {
59         WriteFunc = ((xf & VSX_FAR) ? WriteShort : WriteCoord);
60         WriteFunc(MSG_ENTITY, self.velocity_x);
61         WriteFunc(MSG_ENTITY, self.velocity_y);
62         WriteFunc(MSG_ENTITY, self.velocity_z);
63
64         WriteFunc = ((xf & VSX_FAR) ? WriteShort : WriteAngle);
65         WriteFunc(MSG_ENTITY, self.angles_x);
66         WriteFunc(MSG_ENTITY, self.angles_y);
67         WriteFunc(MSG_ENTITY, self.angles_z);
68     }
69
70     if(sf & VSF_AVEL)
71     {
72         WriteFunc = ((xf & VSX_FAR) ? WriteShort : WriteCoord);
73         WriteFunc(MSG_ENTITY, self.avelocity_x);
74         WriteFunc(MSG_ENTITY, self.avelocity_y);
75         WriteFunc(MSG_ENTITY, self.avelocity_z);
76     }
77
78     if(sf & VSF_STATS)
79     {
80         WriteByte(MSG_ENTITY, self.vehicle_health);
81         if(xf & VSX_OWNER)
82         {
83             WriteByte(MSG_ENTITY, self.vehicle_shield);
84             WriteByte(MSG_ENTITY, self.vehicle_energy);
85
86             WriteByte(MSG_ENTITY, self.vehicle_ammo1);
87             WriteByte(MSG_ENTITY, self.vehicle_reload1);
88
89             WriteByte(MSG_ENTITY, self.vehicle_ammo2);
90             WriteByte(MSG_ENTITY, self.vehicle_reload2);
91
92         }
93     }
94
95     if(sf & VSF_EXTRA)
96         self.vehile_send_exta(to, sf);
97
98     return TRUE;
99 }
100
101 void net_link_vehile()
102 {
103     self.SendFlags = 0xFFFFFF;
104     Net_LinkEntity(self, FALSE, 0, send_vehile);
105 }
106 #endif // SVQC
107
108 #ifdef CSQC
109 void vehicle_spiderbot_assemble()
110 {
111
112 }
113
114 void vehicle_raptor_assemble()
115 {
116
117 }
118
119 void vehicle_bumblebee_assemble()
120 {
121
122 }
123
124 .float lastupdate;
125 void read_vehicle(float bIsNew)
126 {
127     float sf, xf;
128     var float ReadFunc();
129
130     sf = ReadByte();
131     xf = ReadByte();
132
133     if(xf & VSX_OWNER)
134         vehicle = self;
135
136         if(sf & VSF_SETUP)
137         {
138         self.vehicle_hud   = ReadByte();
139         self.team          = ReadByte();
140         self.colormap      = ReadShort();
141         self.vehicle_flags = ReadShort();
142
143         switch(self.vehicle_hud)
144         {
145             case HUD_WAKIZASHI:
146                 vehicle_racer_assemble();
147                 break;
148             case HUD_SPIDERBOT:
149                 vehicle_spiderbot_assemble();
150                 break;
151             case HUD_RAPTOR:
152                 vehicle_raptor_assemble();
153                 break;
154             case HUD_BUMBLEBEE:
155                 vehicle_bumblebee_assemble();
156                 break;
157             default:
158                 break;
159         }
160         }
161
162         if(self.vehicle_hud == HUD_WAKIZASHI && xf & VSX_OWNER)
163         {
164
165         vehicle_hudmodel.owner  = self;
166         }
167
168     //if(xf & VSX_FAR)
169     //    dprint("Client vehicle faaar set\n");
170
171     if(sf & VSF_ORIGIN)
172     {
173         ReadFunc = ((xf & VSX_FAR) ? ReadShort : ReadCoord);
174         self.origin_x = ReadFunc();
175         self.origin_y = ReadFunc();
176         self.origin_z = ReadFunc();
177
178         setorigin(self, self.origin);
179         //self.lastupdate = time;
180     }
181
182     if(sf & VSF_MOVEMENT)
183     {
184         ReadFunc = ((xf & VSX_FAR) ? ReadShort : ReadCoord);
185         self.velocity_x  = ReadFunc();
186         self.velocity_y  = ReadFunc();
187         self.velocity_z  = ReadFunc();
188
189         ReadFunc = ((sf & VSX_FAR) ? ReadShort : ReadAngle);
190         self.angles_x = ReadFunc();
191         self.angles_y = ReadFunc();
192         self.angles_z = ReadFunc();
193
194         //self.lastupdate = time;
195         // self.move_velocity  = self.velocity;
196         // self.move_angles    = self.angles;
197     }
198
199     if(sf & VSF_AVEL)
200     {
201         ReadFunc = ((xf & VSX_FAR) ? ReadShort : ReadCoord);
202         self.avelocity_x = ReadFunc();
203         self.avelocity_y = ReadFunc();
204         self.avelocity_z = ReadFunc();
205
206         // self.move_avelocity  = self.avelocity;
207     }
208
209     if(sf & VSF_STATS)
210     {
211         self.vehicle_health = ReadByte();
212         if(xf & VSX_OWNER)
213         {
214             self.vehicle_shield  = ReadByte();
215             self.vehicle_energy  = ReadByte();
216             self.vehicle_ammo1   = ReadByte();
217             self.vehicle_reload1 = ReadByte();
218             self.vehicle_ammo2   = ReadByte();
219             self.vehicle_reload2 = ReadByte();
220         }
221     }
222
223     if(sf & VSF_EXTRA)
224         self.vehile_read_exta(sf);
225
226 }
227
228 #endif // CSQC
229 #else
230 #ifdef CSQC
231 .float lastupdate;
232 void read_vehicle(float bIsNew)
233 {
234
235 }
236 #endif
237 #endif // VEHICLES_CSQC