Merge branches 'TimePath/weaponsys' and 'Mario/modpack'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / tturrets.qc
1 #include "tturrets.qh"
2 #include "_all.qh"
3
4 #include "hud.qh"
5 #include "movelib.qh"
6 #include "prandom.qh"
7 #include "teamradar.qh"
8 #include "waypointsprites.qh"
9
10 #include "../common/teams.qh"
11
12 #include "../common/movetypes/movetypes.qh"
13
14 #include "../server/tturrets/include/turrets_early.qh"
15
16 #include "../warpzonelib/anglestransform.qh"
17 #include "../warpzonelib/mathlib.qh"
18
19 .vector colormod;
20 .float cnt;
21 .float alpha;
22 .float gravity;
23
24 string tid2info_base;
25 string tid2info_head;
26 string tid2info_name;
27 vector  tid2info_min;
28 vector  tid2info_max;
29
30 void turret_tid2info(float _tid);
31 void turret_precache(float _tid);
32 float turret_is_precache[TID_LAST];
33
34 void turrets_precache()
35 {
36     turret_precache(TID_COMMON);
37 }
38
39 void turret_precache(int _tid)
40 {
41     if (!turret_is_precache[TID_COMMON])
42     {
43         precache_sound ("weapons/rocket_impact.wav");
44         precache_model ("models/turrets/base-gib1.md3");
45         precache_model ("models/turrets/base-gib2.md3");
46         precache_model ("models/turrets/base-gib3.md3");
47         precache_model ("models/turrets/base-gib4.md3");
48         precache_model ("models/turrets/head-gib1.md3");
49         precache_model ("models/turrets/head-gib2.md3");
50         precache_model ("models/turrets/head-gib3.md3");
51         precache_model ("models/turrets/head-gib4.md3");
52         precache_model ("models/turrets/base.md3");
53         precache_model ("models/turrets/rocket.md3");
54     }
55     turret_tid2info(_tid);
56     if(turret_is_precache[_tid])
57         return;
58
59     switch(_tid)
60     {
61         case TID_EWHEEL:
62             precache_model ("models/turrets/ewheel-base2.md3");
63             precache_model ("models/turrets/ewheel-gun1.md3");
64             break;
65         case TID_FLAC:
66             precache_model ("models/turrets/flac.md3");
67             break;
68         case TID_FUSION:
69             precache_model ("models/turrets/reactor.md3");
70             break;
71         case TID_HELLION:
72             precache_model ("models/turrets/hellion.md3");
73             break;
74         case TID_HK:
75             precache_model ("models/turrets/hk.md3");
76             break;
77         case TID_MACHINEGUN:
78             precache_model ("models/turrets/machinegun.md3");
79             precache_sound ("weapons/uzi_fire.wav");
80             break;
81         case TID_MLRS:
82             precache_model ("models/turrets/mlrs.md3");
83             break;
84         case TID_PHASER:
85             precache_model ("models/turrets/phaser.md3");
86             precache_model ("models/turrets/phaser_beam.md3");
87             precache_sound ("turrets/phaser.wav");
88             break;
89         case TID_PLASMA:
90             precache_model ("models/turrets/plasma.md3");
91             break;
92         case TID_PLASMA_DUAL:
93             precache_model ("models/turrets/plasmad.md3");
94             break;
95         case TID_TESLA:
96             precache_model ("models/turrets/tesla_head.md3");
97             precache_model ("models/turrets/tesla_base.md3");
98             break;
99         case TID_WALKER:
100             precache_model ("models/turrets/walker_head_minigun.md3");
101             precache_model ("models/turrets/walker_body.md3");
102             precache_sound ("weapons/uzi_fire.wav");
103             break;
104     }
105     turret_is_precache[_tid] = true;
106 }
107
108 void turret_tid2info(float _tid)
109 {
110     tid2info_base = "models/turrets/base.md3";
111     tid2info_min = '-32 -32 0';
112     tid2info_max = '32 32 64';
113
114     switch(_tid)
115     {
116         case TID_EWHEEL:
117             tid2info_base = "models/turrets/ewheel-base2.md3";
118             tid2info_head = "models/turrets/ewheel-gun1.md3";
119             tid2info_name = "eWheel";
120             break;
121         case TID_FLAC:
122             tid2info_head = "models/turrets/flac.md3";
123             tid2info_name = "Flac Cannon";
124             break;
125         case TID_FUSION:
126             tid2info_head = "models/turrets/reactor.md3";
127             tid2info_name = "Fusion Reactor";
128             tid2info_min = '-34 -34 0';
129             tid2info_max = '34 34 90';
130             break;
131         case TID_HELLION:
132             tid2info_head = "models/turrets/hellion.md3";
133             tid2info_name = "Hellion";
134             break;
135         case TID_HK:
136             tid2info_head = "models/turrets/hk.md3";
137             tid2info_name = "Hunter-Killer";
138             break;
139         case TID_MACHINEGUN:
140             tid2info_head = "models/turrets/machinegun.md3";
141             tid2info_name = "Machinegun";
142             break;
143         case TID_MLRS:
144             tid2info_head = "models/turrets/mlrs.md3";
145             tid2info_name = "MLRS";
146             break;
147         case TID_PHASER:
148             tid2info_head = "models/turrets/phaser.md3";
149             tid2info_name = "Phaser";
150             break;
151         case TID_PLASMA:
152             tid2info_head = "models/turrets/plasma.md3";
153             tid2info_name = "Plasma";
154             break;
155         case TID_PLASMA_DUAL:
156             tid2info_head = "models/turrets/plasmad.md3";
157             tid2info_name = "Dual Plasma";
158             break;
159         case TID_TESLA:
160             tid2info_base = "models/turrets/tesla_base.md3";
161             tid2info_head = "models/turrets/tesla_head.md3";
162             tid2info_name = "Tesla coil";
163             tid2info_min = '-60 -60 0';
164             tid2info_max  ='60 60 128';
165             break;
166         case TID_WALKER:
167             tid2info_base = "models/turrets/walker_body.md3";
168             tid2info_head = "models/turrets/walker_head_minigun.md3";
169             tid2info_name = "Walker";
170             tid2info_min = '-70 -70 0';
171             tid2info_max = '70 70 95';
172             break;
173     }
174 }
175
176 void turret_remove()
177 {
178     remove(self.tur_head);
179     //remove(self.enemy);
180     self.tur_head = world;
181 }
182
183 class(Turret) .vector glowmod;
184 void turret_changeteam()
185 {
186         switch(self.team - 1)
187         {
188         case NUM_TEAM_1: // Red
189             self.glowmod = '2 0 0';
190             self.teamradar_color = '1 0 0';
191             break;
192
193         case NUM_TEAM_2: // Blue
194             self.glowmod = '0 0 2';
195             self.teamradar_color = '0 0 1';
196             break;
197
198         case NUM_TEAM_3: // Yellow
199             self.glowmod = '1 1 0';
200             self.teamradar_color = '1 1 0';
201             break;
202
203         case NUM_TEAM_4: // Pink
204             self.glowmod = '1 0 1';
205             self.teamradar_color = '1 0 1';
206             break;
207         }
208
209         if(self.team)
210         self.colormap = 1024 + (self.team - 1) * 17;
211
212         self.tur_head.colormap = self.colormap;
213         self.tur_head.glowmod = self.glowmod;
214
215 }
216
217 void turret_head_draw()
218 {
219     self.drawmask = MASK_NORMAL;
220 }
221
222 void turret_draw()
223 {
224     float dt;
225
226     dt = time - self.move_time;
227     self.move_time = time;
228     if(dt <= 0)
229         return;
230
231     self.tur_head.angles += dt * self.tur_head.move_avelocity;
232
233     if (self.health < 127)
234     {
235         dt = random();
236
237         if(dt < 0.03)
238             te_spark(self.origin + '0 0 40', randomvec() * 256 + '0 0 256', 16);
239     }
240
241     if(self.health < 85)
242     if(dt < 0.01)
243         pointparticles(particleeffectnum("smoke_large"), (self.origin + (randomvec() * 80)), '0 0 0', 1);
244
245     if(self.health < 32)
246     if(dt < 0.015)
247         pointparticles(particleeffectnum("smoke_small"), (self.origin + (randomvec() * 80)), '0 0 0', 1);
248
249 }
250
251 void turret_draw2d()
252 {
253         if(self.netname == "")
254             return;
255
256         if(!autocvar_g_waypointsprite_turrets)
257                 return;
258
259     if(autocvar_cl_hidewaypoints)
260         return;
261
262         float dist = vlen(self.origin - view_origin);
263     float t = (GetPlayerColor(player_localnum) + 1);
264
265         vector o;
266         string txt;
267
268         if(autocvar_cl_vehicles_hud_tactical)
269         if(dist < 10240 && t != self.team)
270         {
271         // TODO: Vehicle tactical hud
272         o = project_3d_to_2d(self.origin + '0 0 32');
273         if(o.z < 0
274         || o.x < (vid_conwidth * waypointsprite_edgeoffset_left)
275         || o.y < (vid_conheight * waypointsprite_edgeoffset_top)
276         || o.x > (vid_conwidth - (vid_conwidth * waypointsprite_edgeoffset_right))
277         || o.y > (vid_conheight - (vid_conheight * waypointsprite_edgeoffset_bottom)))
278             return; // Dont draw wp's for turrets out of view
279         o.z = 0;
280         if(hud != HUD_NORMAL)
281         {
282             switch(hud)
283             {
284                 case HUD_SPIDERBOT:
285                 case HUD_WAKIZASHI:
286                 case HUD_RAPTOR:
287                 case HUD_BUMBLEBEE:
288                     if(self.turret_type == TID_EWHEEL || self.turret_type == TID_WALKER)
289                         txt = "gfx/vehicles/turret_moving.tga";
290                     else
291                         txt = "gfx/vehicles/turret_stationary.tga";
292
293                     vector pz = drawgetimagesize(txt) * autocvar_cl_vehicles_crosshair_size;
294                     drawpic(o - pz * 0.5, txt, pz , '1 1 1', 0.7, DRAWFLAG_NORMAL);
295                     break;
296             }
297         }
298         }
299
300         if(dist > self.maxdistance)
301         return;
302
303         string spriteimage = self.netname;
304         float a = self.alpha * autocvar_hud_panel_fg_alpha;
305         vector rgb = spritelookupcolor(spriteimage, self.teamradar_color);
306
307
308         if(self.maxdistance > waypointsprite_normdistance)
309                 a *= pow(bound(0, (self.maxdistance - dist) / (self.maxdistance - waypointsprite_normdistance), 1), waypointsprite_distancealphaexponent);
310         else if(self.maxdistance > 0)
311                 a *= pow(bound(0, (waypointsprite_fadedistance - dist) / (waypointsprite_fadedistance - waypointsprite_normdistance), 1), waypointsprite_distancealphaexponent) * (1 - waypointsprite_minalpha) + waypointsprite_minalpha;
312
313         if(rgb == '0 0 0')
314         {
315                 self.teamradar_color = '1 0 1';
316                 printf("WARNING: sprite of name %s has no color, using pink so you notice it\n", spriteimage);
317         }
318
319         txt = self.netname;
320         if(autocvar_g_waypointsprite_spam && waypointsprite_count >= autocvar_g_waypointsprite_spam)
321                 txt = _("Spam");
322         else
323                 txt = spritelookuptext(spriteimage);
324
325         if(time - floor(time) > 0.5 && t == self.team)
326         {
327                 if(self.helpme && time < self.helpme)
328                 {
329                     a *= SPRITE_HELPME_BLINK;
330                     txt = sprintf(_("%s under attack!"), txt);
331                 }
332                 else
333                         a *= spritelookupblinkvalue(spriteimage);
334         }
335
336         if(autocvar_g_waypointsprite_uppercase)
337                 txt = strtoupper(txt);
338
339         if(a > 1)
340         {
341                 rgb *= a;
342                 a = 1;
343         }
344
345         if(a <= 0)
346             return;
347
348         rgb = fixrgbexcess(rgb);
349
350         o = project_3d_to_2d(self.origin + '0 0 64');
351         if(o.z < 0
352         || o.x < (vid_conwidth * waypointsprite_edgeoffset_left)
353         || o.y < (vid_conheight * waypointsprite_edgeoffset_top)
354         || o.x > (vid_conwidth - (vid_conwidth * waypointsprite_edgeoffset_right))
355         || o.y > (vid_conheight - (vid_conheight * waypointsprite_edgeoffset_bottom)))
356             return; // Dont draw wp's for turrets out of view
357
358         o.z = 0;
359
360         float edgedistance_min, crosshairdistance;
361                 edgedistance_min = min((o.y - (vid_conheight * waypointsprite_edgeoffset_top)),
362         (o.x - (vid_conwidth * waypointsprite_edgeoffset_left)),
363         (vid_conwidth - (vid_conwidth * waypointsprite_edgeoffset_right)) - o.x,
364         (vid_conheight - (vid_conheight * waypointsprite_edgeoffset_bottom)) - o.y);
365
366         float vidscale = max(vid_conwidth / vid_width, vid_conheight / vid_height);
367
368         crosshairdistance = sqrt( pow(o.x - vid_conwidth/2, 2) + pow(o.y - vid_conheight/2, 2) );
369
370         t = waypointsprite_scale * vidscale;
371         a *= waypointsprite_alpha;
372
373         {
374                 a = a * (1 - (1 - waypointsprite_distancefadealpha) * (bound(0, dist/waypointsprite_distancefadedistance, 1)));
375                 t = t * (1 - (1 - waypointsprite_distancefadescale) * (bound(0, dist/waypointsprite_distancefadedistance, 1)));
376         }
377         if (edgedistance_min < waypointsprite_edgefadedistance) {
378                 a = a * (1 - (1 - waypointsprite_edgefadealpha) * (1 - bound(0, edgedistance_min/waypointsprite_edgefadedistance, 1)));
379                 t = t * (1 - (1 - waypointsprite_edgefadescale) * (1 - bound(0, edgedistance_min/waypointsprite_edgefadedistance, 1)));
380         }
381         if(crosshairdistance < waypointsprite_crosshairfadedistance) {
382                 a = a * (1 - (1 - waypointsprite_crosshairfadealpha) * (1 - bound(0, crosshairdistance/waypointsprite_crosshairfadedistance, 1)));
383                 t = t * (1 - (1 - waypointsprite_crosshairfadescale) * (1 - bound(0, crosshairdistance/waypointsprite_crosshairfadedistance, 1)));
384         }
385
386         o = drawspritearrow(o, M_PI, rgb, a, SPRITE_ARROW_SCALE * t);
387     o = drawspritetext(o, M_PI, (SPRITE_HEALTHBAR_WIDTH + 2 * SPRITE_HEALTHBAR_BORDER) * t, rgb, a, waypointsprite_fontsize * '1 1 0', txt);
388     drawhealthbar(
389             o,
390             0,
391             self.health / 255,
392             '0 0 0',
393             '0 0 0',
394             0.5 * SPRITE_HEALTHBAR_WIDTH * t,
395             0.5 * SPRITE_HEALTHBAR_HEIGHT * t,
396             SPRITE_HEALTHBAR_MARGIN * t + 0.5 * waypointsprite_fontsize,
397             SPRITE_HEALTHBAR_BORDER * t,
398             0,
399             rgb,
400             a * SPRITE_HEALTHBAR_BORDERALPHA,
401             rgb,
402             a * SPRITE_HEALTHBAR_HEALTHALPHA,
403             DRAWFLAG_NORMAL
404             );
405 }
406
407 void turret_walker_draw()
408 {
409     float dt;
410
411     dt = time - self.move_time;
412     self.move_time = time;
413     if(dt <= 0)
414         return;
415
416     fixedmakevectors(self.angles);
417     movelib_groundalign4point(300, 100, 0.25, 45);
418     setorigin(self, self.origin + self.velocity * dt);
419     self.tur_head.angles += dt * self.tur_head.move_avelocity;
420     self.angles_y = self.move_angles.y;
421
422     if (self.health < 127)
423     if(random() < 0.15)
424         te_spark(self.origin + '0 0 40', randomvec() * 256 + '0 0 256', 16);
425 }
426
427 void turret_ewheel_draw()
428 {
429     float dt;
430
431     dt = time - self.move_time;
432     self.move_time = time;
433     if(dt <= 0)
434         return;
435
436     fixedmakevectors(self.angles);
437     setorigin(self, self.origin + self.velocity * dt);
438     self.tur_head.angles += dt * self.tur_head.move_avelocity;
439     self.angles_y = self.move_angles.y;
440
441     if (self.health < 127)
442     if(random() < 0.05)
443         te_spark(self.origin + '0 0 40', randomvec() * 256 + '0 0 256', 16);
444 }
445
446 void turret_construct()
447 {
448     if(self.tur_head == world)
449         self.tur_head = spawn();
450
451     turret_tid2info(self.turret_type);
452     self.netname = tid2info_name;
453
454     setorigin(self, self.origin);
455     setmodel(self, tid2info_base);
456     setmodel(self.tur_head, tid2info_head);
457     setsize(self, tid2info_min, tid2info_max);
458     setsize(self.tur_head, '0 0 0', '0 0 0');
459
460     if(self.turret_type == TID_EWHEEL)
461         setattachment(self.tur_head, self, "");
462     else
463         setattachment(self.tur_head, self, "tag_head");
464
465     self.tur_head.classname     = "turret_head";
466     self.tur_head.owner         = self;
467     self.tur_head.move_movetype = MOVETYPE_NOCLIP;
468     self.move_movetype          = MOVETYPE_NOCLIP;
469     self.tur_head.angles        = self.angles;
470     self.health                 = 255;
471     self.solid                  = SOLID_BBOX;
472     self.tur_head.solid         = SOLID_NOT;
473     self.movetype               = MOVETYPE_NOCLIP;
474     self.tur_head.movetype      = MOVETYPE_NOCLIP;
475     self.draw                   = turret_draw;
476     self.entremove              = turret_remove;
477     self.drawmask               = MASK_NORMAL;
478     self.tur_head.drawmask      = MASK_NORMAL;
479     self.anim_start_time        = 0;
480     self.draw2d = turret_draw2d;
481     self.maxdistance = autocvar_g_waypointsprite_turrets_maxdist;
482     self.teamradar_color = '1 0 0';
483     self.alpha = 1;
484
485     if(self.turret_type == TID_EWHEEL || self.turret_type == TID_WALKER)
486     {
487         self.gravity            = 1;
488         self.movetype           = MOVETYPE_BOUNCE;
489         self.move_movetype      = MOVETYPE_BOUNCE;
490         self.move_origin        = self.origin;
491         self.move_time          = time;
492         switch(self.turret_type)
493         {
494             case TID_EWHEEL:
495                 self.draw               = turret_ewheel_draw;
496                 break;
497             case TID_WALKER:
498                 self.draw               = turret_walker_draw;
499                 break;
500
501         }
502     }
503 }
504
505 entity turret_gibtoss(string _model, vector _from, vector _to, vector _cmod, float _explode);
506 void turret_gibboom();
507 void turret_gib_draw()
508 {
509     Movetype_Physics_MatchTicrate(autocvar_cl_gibs_ticrate, autocvar_cl_gibs_sloppy);
510
511     self.drawmask = MASK_NORMAL;
512
513         if(self.cnt)
514         {
515             if(time >= self.nextthink)
516             {
517             turret_gibboom();
518             remove(self);
519             }
520         }
521         else
522         {
523         self.alpha = bound(0, self.nextthink - time, 1);
524         if(self.alpha < ALPHA_MIN_VISIBLE)
525             remove(self);
526         }
527 }
528
529 void turret_gibboom()
530 {
531     float i;
532
533     sound (self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTEN_NORM);
534     pointparticles(particleeffectnum("rocket_explode"), self.origin, '0 0 0', 1);
535
536     for (i = 1; i < 5; i = i + 1)
537         turret_gibtoss(strcat("models/turrets/head-gib", ftos(i), ".md3"), self.origin + '0 0 2', self.velocity + randomvec() * 700, '0 0 0', false);
538 }
539
540 entity turret_gibtoss(string _model, vector _from, vector _to, vector _cmod, float _explode)
541 {
542     entity gib;
543
544     traceline(_from, _to, MOVE_NOMONSTERS, world);
545     if(trace_startsolid)
546         return world;
547
548     gib = spawn();
549     setorigin(gib, _from);
550     setmodel(gib, _model);
551     gib.colormod    = _cmod;
552         gib.solid       = SOLID_CORPSE;
553     gib.draw        = turret_gib_draw;
554     gib.cnt         = _explode;
555     setsize(gib, '-1 -1 -1', '1 1 1');
556     if(_explode)
557     {
558         gib.nextthink = time + 0.2 * (autocvar_cl_gibs_lifetime * (1 + prandom() * 0.15));
559         gib.effects = EF_FLAME;
560     }
561     else
562         gib.nextthink = time + autocvar_cl_gibs_lifetime * (1 + prandom() * 0.15);
563
564     gib.gravity         = 1;
565         gib.move_movetype   = MOVETYPE_BOUNCE;
566         gib.move_origin     = _from;
567         setorigin(gib,        _from);
568         gib.move_velocity   = _to;
569         gib.move_avelocity  = prandomvec() * 32;
570         gib.move_time       = time;
571         gib.damageforcescale = 1;
572         gib.classname = "turret_gib";
573
574         return gib;
575 }
576
577 void turret_die()
578 {
579
580     sound (self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTEN_NORM);
581     pointparticles(particleeffectnum("rocket_explode"), self.origin, '0 0 0', 1);
582     turret_tid2info(self.turret_type);
583     if (!autocvar_cl_nogibs)
584     {
585         // Base
586         if(self.turret_type == TID_EWHEEL)
587             turret_gibtoss(tid2info_base, self.origin + '0 0 18', self.velocity + '0 0 400' + '0.1 0.1 1' * (random() * 400), '-1 -1 -1', true);
588         else if (self.turret_type == TID_WALKER)
589             turret_gibtoss(tid2info_base, self.origin + '0 0 18', self.velocity + '0 0 300' + '0.1 0.1 1' * (random() * 200), '-1 -1 -1', true);
590         else if (self.turret_type == TID_TESLA)
591             turret_gibtoss(tid2info_base, self.origin + '0 0 18', '0 0 200', '-1 -1 -1', false);
592         else
593         {
594             if (random() > 0.5)
595             {
596                 turret_gibtoss("models/turrets/base-gib2.md3", self.origin + '0 0 8', '0 0 50' + randomvec() * 150, '0 0 0', false);
597                 turret_gibtoss("models/turrets/base-gib3.md3", self.origin + '0 0 8', '0 0 50' + randomvec() * 150, '0 0 0', false);
598                 turret_gibtoss("models/turrets/base-gib4.md3", self.origin + '0 0 8', '0 0 50' + randomvec() * 150, '0 0 0', false);
599             }
600             else
601                 turret_gibtoss("models/turrets/base-gib1.md3", self.origin + '0 0 8', '0 0 0', '0 0 0', true);
602
603             entity headgib = turret_gibtoss(tid2info_head, self.origin + '0 0 32', '0 0 200' + randomvec() * 200, '-1 -1 -1', true);
604             if(headgib)
605             {
606                 headgib.angles = headgib.move_angles = self.tur_head.angles;
607                 headgib.avelocity = headgib.move_avelocity = self.tur_head.move_avelocity + randomvec() * 45;
608                 headgib.avelocity_y = headgib.move_avelocity_y = headgib.move_avelocity.y * 5;
609                 headgib.gravity = 0.5;
610             }
611         }
612     }
613
614     setmodel(self, "null");
615     setmodel(self.tur_head, "null");
616 }
617
618 void ent_turret()
619 {
620     int sf = ReadByte();
621
622         if(sf & TNSF_SETUP)
623         {
624             self.turret_type = ReadByte();
625
626             self.origin_x = ReadCoord();
627             self.origin_y = ReadCoord();
628             self.origin_z = ReadCoord();
629             setorigin(self, self.origin);
630
631             self.angles_x = ReadAngle();
632             self.angles_y = ReadAngle();
633
634             turret_precache(self.turret_type);
635             turret_construct();
636             self.colormap = 1024;
637             self.glowmod = '0 1 1';
638             self.tur_head.colormap = self.colormap;
639             self.tur_head.glowmod = self.glowmod;
640     }
641
642     if(sf & TNSF_ANG)
643     {
644         if(self.tur_head == world) // aparenly this can happpen before TNSF_SETUP. great.
645             self.tur_head = spawn();
646
647         self.tur_head.move_angles_x = ReadShort();
648         self.tur_head.move_angles_y = ReadShort();
649         //self.tur_head.angles = self.angles + self.tur_head.move_angles;
650         self.tur_head.angles = self.tur_head.move_angles;
651     }
652
653     if(sf & TNSF_AVEL)
654     {
655         if(self.tur_head == world) // aparenly this can happpen before TNSF_SETUP. great.
656             self.tur_head = spawn();
657
658         self.tur_head.move_avelocity_x = ReadShort();
659         self.tur_head.move_avelocity_y = ReadShort();
660     }
661
662     if(sf & TNSF_MOVE)
663     {
664         self.origin_x = ReadShort();
665         self.origin_y = ReadShort();
666         self.origin_z = ReadShort();
667         setorigin(self, self.origin);
668
669         self.velocity_x = ReadShort();
670         self.velocity_y = ReadShort();
671         self.velocity_z = ReadShort();
672
673         self.move_angles_y = ReadShort();
674
675         self.move_time     = time;
676         self.move_velocity = self.velocity;
677         self.move_origin   = self.origin;
678     }
679
680     if(sf & TNSF_ANIM)
681     {
682         self.frame1time = ReadCoord();
683         self.frame      = ReadByte();
684     }
685
686     if(sf & TNSF_STATUS)
687     {
688         int _tmp = ReadByte();
689         if(_tmp != self.team)
690         {
691             self.team = _tmp;
692             turret_changeteam();
693         }
694
695         _tmp = ReadByte();
696         if(_tmp == 0 && self.health != 0)
697             turret_die();
698         else if(self.health && self.health != _tmp)
699             self.helpme = servertime + 10;
700
701         self.health = _tmp;
702     }
703     //self.enemy.health = self.health / 255;
704 }