]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/vehicles/network.qc
33bbfeaceb0e22deeceea8df9cb7b49584f0c274
[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 and such). Handeld per vehicle type.
9 float VSF_ANIMINFO    = 64;         /// Animation info
10 float VSF_FAR         = 128;
11 float VSF_FULL_UPDATE = 16777215;    /// Send everything
12
13 #ifdef SVQC
14 #define VSF_FARDISTANCE 2000
15 float send_vehile(entity to, float sf)
16 {
17         float dist;
18     var void WriteFunc(float, float);
19     
20     dist = vlen(self.origin - to.origin);
21     if(dist > VSF_FARDISTANCE && to != self.owner)
22         sf |= VSF_FAR;
23         
24         // Always send a movement and origin to owner
25         if(to == self.owner)
26             sf |= VSF_ORIGIN | VSF_MOVEMENT;
27                 
28         WriteByte(MSG_ENTITY, ENT_CLIENT_VEHICLE);
29         
30         // We need to know client-side what was sent
31         WriteByte(MSG_ENTITY, sf);
32         
33         if(sf & VSF_SETUP)
34         {
35         WriteByte(MSG_ENTITY,   self.hud);        //vehicle type = hud
36         WriteByte(MSG_ENTITY,   self.team);
37         WriteShort(MSG_ENTITY,  self.colormap);
38         }
39     
40     if(sf & VSF_ORIGIN)
41     {        
42         WriteFunc = ((sf & VSF_FAR) ? WriteShort : WriteCoord); 
43         WriteFunc(MSG_ENTITY, self.origin_x);
44         WriteFunc(MSG_ENTITY, self.origin_y);
45         WriteFunc(MSG_ENTITY, self.origin_z);        
46     }
47     
48     if(sf & VSF_MOVEMENT)
49     {   
50         WriteFunc = ((sf & VSF_FAR) ? WriteShort : WriteCoord);
51         WriteCoord(MSG_ENTITY, self.velocity_x);
52         WriteCoord(MSG_ENTITY, self.velocity_y);
53         WriteCoord(MSG_ENTITY, self.velocity_z);
54
55         WriteFunc = ((sf & VSF_FAR) ? WriteShort : WriteAngle);
56         WriteAngle(MSG_ENTITY, self.angles_x);
57         WriteAngle(MSG_ENTITY, self.angles_y);
58         WriteAngle(MSG_ENTITY, self.angles_z);
59     }
60     
61     if(sf & VSF_AVEL)
62     {
63         WriteFunc = ((sf & VSF_FAR) ? WriteShort : WriteCoord);
64         WriteCoord(MSG_ENTITY, self.avelocity_x);
65         WriteCoord(MSG_ENTITY, self.avelocity_y);
66         WriteCoord(MSG_ENTITY, self.avelocity_z);        
67     }
68     
69     if(sf & VSF_STATS)
70     {
71         if(to == self.owner)
72         {
73             WriteByte(MSG_ENTITY, 1);
74             WriteByte(MSG_ENTITY, self.vehicle_shield);
75             WriteByte(MSG_ENTITY, self.vehicle_energy);
76             
77             WriteByte(MSG_ENTITY, self.vehicle_ammo1);
78             WriteByte(MSG_ENTITY, self.vehicle_reload1);
79             
80             WriteByte(MSG_ENTITY, self.vehicle_ammo2);
81             WriteByte(MSG_ENTITY, self.vehicle_reload2);
82             
83         }
84         else
85             WriteByte(MSG_ENTITY, 0);
86             
87         WriteByte(MSG_ENTITY, self.vehicle_health);
88     }
89     
90     if(sf & VSF_EXTRA)
91         self.vehile_send_exta(to, sf);
92     
93     return TRUE;
94 }
95
96 void net_link_vehile()
97 {    
98     self.SendFlags = 0xFFFFFF;
99     Net_LinkEntity(self, FALSE, 0, send_vehile);    
100 }
101 #endif // SVQC
102
103 #ifdef CSQC
104 void Net_ReadVehicle(float bIsNew)
105 {
106     float sf;
107     var float ReadFunc();
108     
109     if(bIsNew)
110     {
111         /*setmodel(self, "models/vehicles/wakizashi.dpm");
112         self.move_movetype = MOVETYPE_BOUNCE;        
113         self.entremove = VehicleRacerRemove;
114         setsize(self,  '-60 -60 -20', '60 60 20');        
115         self.draw = VehicleRacerDraw;
116         self.scale = 0.5;*/
117     }
118
119     sf = ReadByte();    
120         if(sf & VSF_SETUP)
121         {
122         self.vehicle_hud      = ReadByte();
123         self.team     = ReadByte();
124         self.colormap = ReadShort();
125         
126         switch(self.vehicle_hud)
127         {
128             case HUD_WAKIZASHI:
129                 break;
130             case HUD_SPIDERBOT:
131                 break;
132             case HUD_RAPTOR:
133                 break;
134             case HUD_BUMBLEBEE:
135                 break;
136             default:
137                 break;
138         }
139         }        
140     
141     if(sf & VSF_ORIGIN)
142     {    
143         ReadFunc = ((sf & VSF_FAR) ? ReadShort : ReadCoord);
144         self.origin_x       = ReadCoord();
145         self.origin_y       = ReadCoord();
146         self.origin_z       = ReadCoord();
147         self.move_origin    = self.origin;
148     }
149     
150     if(sf & VSF_MOVEMENT)
151     {    
152         ReadFunc = ((sf & VSF_FAR) ? ReadShort : ReadCoord);
153         self.velocity_x     = ReadFunc();
154         self.velocity_y     = ReadFunc();
155         self.velocity_z     = ReadFunc();
156
157         ReadFunc = ((sf & VSF_FAR) ? ReadShort : ReadAngle);
158         self.angles_x       = ReadFunc();
159         self.angles_y       = ReadFunc();
160         self.angles_z       = ReadFunc();
161         
162         self.move_velocity  = self.velocity;
163         self.move_angles    = self.angles;
164     }
165
166     if(sf & VSF_AVEL)
167     {    
168         ReadFunc = ((sf & VSF_FAR) ? ReadShort : ReadCoord);
169         self.avelocity_x     = ReadFunc();
170         self.avelocity_y     = ReadFunc();
171         self.avelocity_z     = ReadFunc();
172     }
173     
174     if(sf & VSF_EXTRA)
175         self.vehile_read_exta(sf);
176
177 }
178
179 #endif // CSQC
180
181 #endif // VEHICLES_CSQC