On second thought, don't override the intermission timer with the warmup text
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / physics / movetypes / movetypes.qc
1 #include "movetypes.qh"
2
3 #ifdef SVQC
4 void set_movetype(entity this, int mt)
5 {
6         this.move_movetype = mt;
7         if (mt == MOVETYPE_PHYSICS || mt == MOVETYPE_PUSH || mt == MOVETYPE_FAKEPUSH) {
8                 this.move_qcphysics = false;
9         }
10         this.movetype = (this.move_qcphysics) ? MOVETYPE_NONE : mt;
11 }
12 #elif defined(CSQC)
13 void set_movetype(entity this, int mt)
14 {
15         this.move_movetype = mt;
16 }
17 #endif
18
19 void _Movetype_WallFriction(entity this, vector stepnormal)  // SV_WallFriction
20 {
21         /*float d, i;
22         vector into, side;
23         makevectors(this.v_angle);
24         d = (stepnormal * v_forward) + 0.5;
25
26         if(d < 0)
27         {
28             i = (stepnormal * this.velocity);
29             into = i * stepnormal;
30             side = this.velocity - into;
31             this.velocity_x = side.x * (1 * d);
32             this.velocity_y = side.y * (1 * d);
33         }*/
34 }
35
36 vector planes[MAX_CLIP_PLANES];
37 int _Movetype_FlyMove(entity this, float dt, bool applygravity, vector stepnormal, float stepheight) // SV_FlyMove
38 {
39         int blocked = 0;
40         int i, j, numplanes = 0;
41         float time_left = dt, grav = 0;
42         vector push;
43         vector primal_velocity, original_velocity, restore_velocity;
44
45         for(i = 0; i < MAX_CLIP_PLANES; ++i)
46                 planes[i] = '0 0 0';
47
48         if(applygravity)
49         {
50                 this.move_didgravity = 1;
51                 grav = dt * (PHYS_ENTGRAVITY(this) ? PHYS_ENTGRAVITY(this) : 1) * PHYS_GRAVITY(this);
52
53                 if(!GAMEPLAYFIX_NOGRAVITYONGROUND || !IS_ONGROUND(this))
54                 {
55                         if(GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
56                                 this.velocity_z -= grav * 0.5;
57                         else
58                                 this.velocity_z -= grav;
59                 }
60         }
61
62         original_velocity = primal_velocity = restore_velocity = this.velocity;
63
64         for(int bumpcount = 0;bumpcount < MAX_CLIP_PLANES;bumpcount++)
65         {
66                 if(this.velocity == '0 0 0')
67                         break;
68
69                 push = this.velocity * time_left;
70                 _Movetype_PushEntity(this, push, true);
71                 if(trace_startsolid)
72                 {
73                         // we got teleported by a touch function
74                         // let's abort the move
75                         blocked |= 8;
76                         break;
77                 }
78
79                 // this code is used by MOVETYPE_WALK and MOVETYPE_STEP and SV_UnstickEntity
80                 // abort move if we're stuck in the world (and didn't make it out)
81                 if(trace_startsolid && trace_allsolid)
82                 {
83                         this.velocity = restore_velocity;
84                         return 3;
85                 }
86
87                 if(trace_fraction == 1)
88                         break;
89
90                 float my_trace_fraction = trace_fraction;
91                 vector my_trace_plane_normal = trace_plane_normal;
92
93                 if(trace_plane_normal.z)
94                 {
95                         if(trace_plane_normal.z > 0.7)
96                         {
97                                 // floor
98                                 blocked |= 1;
99
100                                 if(!trace_ent)
101                                 {
102                                         //dprint("_Movetype_FlyMove: !trace_ent\n");
103                                         trace_ent = NULL;
104                                 }
105
106                                 SET_ONGROUND(this);
107                                 this.groundentity = trace_ent;
108                         }
109                 }
110                 else if(stepheight)
111                 {
112                         // step - handle it immediately
113                         vector org = this.origin;
114                         vector steppush = '0 0 1' * stepheight;
115
116                         _Movetype_PushEntity(this, steppush, true);
117                         if(trace_startsolid)
118                         {
119                                 blocked |= 8;
120                                 break;
121                         }
122                         _Movetype_PushEntity(this, push, true);
123                         if(trace_startsolid)
124                         {
125                                 blocked |= 8;
126                                 break;
127                         }
128                         float trace2_fraction = trace_fraction;
129                         steppush = '0 0 1' * (org.z - this.origin_z);
130                         _Movetype_PushEntity(this, steppush, true);
131                         if(trace_startsolid)
132                         {
133                                 blocked |= 8;
134                                 break;
135                         }
136
137                         // accept the new position if it made some progress...
138                         if(fabs(this.origin_x - org.x) >= 0.03125 || fabs(this.origin_y - org.y) >= 0.03125)
139                         {
140                                 trace_endpos = this.origin;
141                                 time_left *= 1 - trace2_fraction;
142                                 numplanes = 0;
143                                 continue;
144                         }
145                         else
146                                 this.origin = org;
147                 }
148                 else
149                 {
150                         // step - return it to caller
151                         blocked |= 2;
152                         // save the trace for player extrafriction
153                         if(stepnormal)
154                                 stepnormal = trace_plane_normal;
155                 }
156
157                 if(my_trace_fraction >= 0.001)
158                 {
159                         // actually covered some distance
160                         original_velocity = this.velocity;
161                         numplanes = 0;
162                 }
163
164                 time_left *= 1 - my_trace_fraction;
165
166                 // clipped to another plane
167                 if(numplanes >= MAX_CLIP_PLANES)
168                 {
169                         // this shouldn't really happen
170                         this.velocity = '0 0 0';
171                         blocked = 3;
172                         break;
173                 }
174
175                 planes[numplanes] = my_trace_plane_normal;
176                 numplanes++;
177
178                 // modify original_velocity so it parallels all of the clip planes
179                 vector new_velocity = '0 0 0';
180                 for (i = 0;i < numplanes;i++)
181                 {
182                         new_velocity = _Movetype_ClipVelocity(original_velocity, planes[i], 1);
183                         for (j = 0;j < numplanes;j++)
184                         {
185                                 if(j != i)
186                                 {
187                                         // not ok
188                                         if((new_velocity * planes[j]) < 0)
189                                                 break;
190                                 }
191                         }
192                         if(j == numplanes)
193                                 break;
194                 }
195
196                 if(i != numplanes)
197                 {
198                         // go along this plane
199                         this.velocity = new_velocity;
200                 }
201                 else
202                 {
203                         // go along the crease
204                         if(numplanes != 2)
205                         {
206                                 this.velocity = '0 0 0';
207                                 blocked = 7;
208                                 break;
209                         }
210                         vector dir = cross(planes[0], planes[1]);
211                         // LordHavoc: thanks to taniwha of QuakeForge for pointing out this fix for slowed falling in corners
212                         float ilength = sqrt((dir * dir));
213                         if(ilength)
214                                 ilength = 1.0 / ilength;
215                         dir.x *= ilength;
216                         dir.y *= ilength;
217                         dir.z *= ilength;
218                         float d = (dir * this.velocity);
219                         this.velocity = dir * d;
220                 }
221
222                 // if current velocity is against the original velocity,
223                 // stop dead to avoid tiny occilations in sloping corners
224                 if((this.velocity * primal_velocity) <= 0)
225                 {
226                         this.velocity = '0 0 0';
227                         break;
228                 }
229         }
230
231         // LordHavoc: this came from QW and allows you to get out of water more easily
232         if(GAMEPLAYFIX_EASIERWATERJUMP(this) && (this.flags & FL_WATERJUMP) && !(blocked & 8))
233                 this.velocity = primal_velocity;
234
235         if(PHYS_WALLCLIP(this) && this.pm_time && !(this.flags & FL_WATERJUMP) && !(blocked & 8))
236                 this.velocity = primal_velocity;
237
238         if(applygravity)
239         {
240                 if(!GAMEPLAYFIX_NOGRAVITYONGROUND || !IS_ONGROUND(this))
241                 {
242                         if(GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
243                                 this.velocity_z -= grav * 0.5f;
244                 }
245         }
246
247         return blocked;
248 }
249
250 void _Movetype_CheckVelocity(entity this)  // SV_CheckVelocity
251 {
252         // if(vlen(this.velocity) < 0.0001)
253         // this.velocity = '0 0 0';
254 }
255
256 bool _Movetype_CheckWater(entity this)  // SV_CheckWater
257 {
258         vector point = this.origin;
259         point.z += this.mins.z + 1;
260
261         int nativecontents = pointcontents(point);
262         if(this.watertype && this.watertype != nativecontents)
263         {
264                 // dprintf("_Movetype_CheckWater(): Original: '%d', New: '%d'\n", this.watertype, nativecontents);
265                 if(this.contentstransition)
266                         this.contentstransition(this.watertype, nativecontents);
267         }
268
269         this.waterlevel = WATERLEVEL_NONE;
270         this.watertype = CONTENT_EMPTY;
271
272         int supercontents = Mod_Q1BSP_SuperContentsFromNativeContents(nativecontents);
273         if(supercontents & DPCONTENTS_LIQUIDSMASK)
274         {
275                 this.watertype = nativecontents;
276                 this.waterlevel = WATERLEVEL_WETFEET;
277                 point.z = this.origin.z + (this.mins.z + this.maxs.z) * 0.5;
278                 if(Mod_Q1BSP_SuperContentsFromNativeContents(pointcontents(point)) & DPCONTENTS_LIQUIDSMASK)
279                 {
280                         this.waterlevel = WATERLEVEL_SWIMMING;
281                         point.z = this.origin.z + this.view_ofs.z;
282                         if(Mod_Q1BSP_SuperContentsFromNativeContents(pointcontents(point)) & DPCONTENTS_LIQUIDSMASK)
283                                 this.waterlevel = WATERLEVEL_SUBMERGED;
284                 }
285         }
286
287         return this.waterlevel > 1;
288 }
289
290 void _Movetype_CheckWaterTransition(entity ent)  // SV_CheckWaterTransition
291 {
292         int contents = pointcontents(ent.origin);
293
294         if(!ent.watertype)
295         {
296                 // just spawned here
297                 if(!GAMEPLAYFIX_WATERTRANSITION(ent))
298                 {
299                         ent.watertype = contents;
300                         ent.waterlevel = 1;
301                         return;
302                 }
303         }
304         else if(ent.watertype != contents)
305         {
306                 // dprintf("_Movetype_CheckWaterTransition(): Origin: %s, Direct: '%d', Original: '%d', New: '%d'\n", vtos(ent.origin), pointcontents(ent.origin), ent.watertype, contents);
307                 if(ent.contentstransition)
308                         ent.contentstransition(ent.watertype, contents);
309         }
310
311         if(contents <= CONTENT_WATER)
312         {
313                 ent.watertype = contents;
314                 ent.waterlevel = 1;
315         }
316         else
317         {
318                 ent.watertype = CONTENT_EMPTY;
319                 ent.waterlevel = (GAMEPLAYFIX_WATERTRANSITION(ent) ? 0 : contents);
320         }
321 }
322
323 void _Movetype_Impact(entity this, entity oth)  // SV_Impact
324 {
325         if(gettouch(this))
326                 gettouch(this)(this, oth);
327
328         if(gettouch(oth))
329                 gettouch(oth)(oth, this);
330 }
331
332 void _Movetype_LinkEdict_TouchAreaGrid(entity this)  // SV_LinkEdict_TouchAreaGrid
333 {
334         if(this.solid == SOLID_NOT)
335                 return;
336
337     FOREACH_ENTITY_RADIUS(0.5 * (this.absmin + this.absmax), 0.5 * vlen(this.absmax - this.absmin), true, {
338                 if (it.solid == SOLID_TRIGGER && it != this)
339                 if (it.move_nomonsters != MOVE_NOMONSTERS && it.move_nomonsters != MOVE_WORLDONLY)
340                 if (gettouch(it) && boxesoverlap(it.absmin, it.absmax, this.absmin, this.absmax))
341                 {
342                         trace_allsolid = false;
343                         trace_startsolid = false;
344                         trace_fraction = 1;
345                         trace_inwater = false;
346                         trace_inopen = true;
347                         trace_endpos = it.origin;
348                         trace_plane_normal = '0 0 1';
349                         trace_plane_dist = 0;
350                         trace_ent = this;
351
352                         gettouch(it)(it, this);
353                 }
354     });
355 }
356
357 bool autocvar__movetype_debug = false;
358 void _Movetype_LinkEdict(entity this, bool touch_triggers)  // SV_LinkEdict
359 {
360         if(autocvar__movetype_debug)
361         {
362                 vector mi, ma;
363                 if(this.solid == SOLID_BSP)
364                 {
365                         // TODO set the absolute bbox
366                         mi = this.mins;
367                         ma = this.maxs;
368                 }
369                 else
370                 {
371                         mi = this.mins;
372                         ma = this.maxs;
373                 }
374                 mi += this.origin;
375                 ma += this.origin;
376
377                 if(this.flags & FL_ITEM)
378                 {
379                         mi -= '15 15 1';
380                         ma += '15 15 1';
381                 }
382                 else
383                 {
384                         mi -= '1 1 1';
385                         ma += '1 1 1';
386                 }
387
388                 this.absmin = mi;
389                 this.absmax = ma;
390         }
391         else
392         {
393                 setorigin(this, this.origin); // calls SV_LinkEdict
394         #ifdef CSQC
395                 // NOTE: CSQC's version of setorigin doesn't expand
396                 this.absmin -= '1 1 1';
397                 this.absmax += '1 1 1';
398         #endif
399         }
400
401         if(touch_triggers)
402                 _Movetype_LinkEdict_TouchAreaGrid(this);
403 }
404
405 entity _Movetype_TestEntityPosition_ent;
406 bool _Movetype_TestEntityPosition(vector ofs)  // SV_TestEntityPosition
407 {
408     entity this = _Movetype_TestEntityPosition_ent;
409 //      vector org = this.origin + ofs;
410
411         int cont = this.dphitcontentsmask;
412         this.dphitcontentsmask = DPCONTENTS_SOLID;
413         tracebox(this.origin, this.mins, this.maxs, this.origin, ((this.move_movetype == MOVETYPE_FLY_WORLDONLY) ? MOVE_WORLDONLY : MOVE_NOMONSTERS), this);
414         this.dphitcontentsmask = cont;
415
416         if(trace_startsolid)
417                 return true;
418
419         if(vdist(trace_endpos - this.origin, >, 0.0001))
420                 this.origin = trace_endpos;
421         return false;
422 }
423
424 bool _Movetype_UnstickEntity(entity this)  // SV_UnstickEntity
425 {
426     _Movetype_TestEntityPosition_ent = this;
427         if (!_Movetype_TestEntityPosition(' 0  0  0')) {
428             return true;
429         }
430         #define X(v) if (_Movetype_TestEntityPosition(v))
431         X('-1  0  0') X(' 1  0  0')
432         X(' 0 -1  0') X(' 0  1  0')
433         X('-1 -1  0') X(' 1 -1  0')
434         X('-1  1  0') X(' 1  1  0')
435         #undef X
436         {
437         #define X(i) \
438             if (_Movetype_TestEntityPosition('0 0 -1' * i)) \
439             if (_Movetype_TestEntityPosition('0 0 1' * i))
440         X(01) X(02) X(03) X(04) X(05) X(06) X(07) X(08)
441         X(09) X(10) X(11) X(12) X(13) X(14) X(15) X(16)
442         X(17)
443         #undef X
444         {
445             LOG_DEBUGF("Can't unstick an entity (edict: %d, classname: %s, origin: %s)",
446                 etof(this), this.classname, vtos(this.origin));
447             return false;
448         }
449         }
450         LOG_DEBUGF("Sucessfully unstuck an entity (edict: %d, classname: %s, origin: %s)",
451                 etof(this), this.classname, vtos(this.origin));
452         _Movetype_LinkEdict(this, true);
453         return true;
454 }
455
456 vector _Movetype_ClipVelocity(vector vel, vector norm, float f)  // SV_ClipVelocity
457 {
458         vel -= ((vel * norm) * norm) * f;
459
460         if(vel.x > -0.1 && vel.x < 0.1) vel.x = 0;
461         if(vel.y > -0.1 && vel.y < 0.1) vel.y = 0;
462         if(vel.z > -0.1 && vel.z < 0.1) vel.z = 0;
463
464         return vel;
465 }
466
467 void _Movetype_PushEntityTrace(entity this, vector push)
468 {
469         vector end = this.origin + push;
470         int type;
471         if(this.move_nomonsters)
472                 type = max(0, this.move_nomonsters);
473         else if(this.move_movetype == MOVETYPE_FLYMISSILE)
474                 type = MOVE_MISSILE;
475         else if(this.move_movetype == MOVETYPE_FLY_WORLDONLY)
476                 type = MOVE_WORLDONLY;
477         else if(this.solid == SOLID_TRIGGER || this.solid == SOLID_NOT)
478                 type = MOVE_NOMONSTERS;
479         else
480                 type = MOVE_NORMAL;
481
482         tracebox(this.origin, this.mins, this.maxs, end, type, this);
483 }
484
485 float _Movetype_PushEntity(entity this, vector push, bool failonstartsolid)  // SV_PushEntity
486 {
487         _Movetype_PushEntityTrace(this, push);
488
489         if(trace_startsolid && failonstartsolid)
490                 return trace_fraction;
491
492         this.origin = trace_endpos;
493
494         if(trace_fraction < 1)
495                 if(this.solid >= SOLID_TRIGGER && (!IS_ONGROUND(this) || (this.groundentity != trace_ent)))
496                         _Movetype_Impact(this, trace_ent);
497
498         return trace_fraction;
499 }
500
501
502 .float ltime;
503 .void() blocked;
504
505 void _Movetype_Physics_Frame(entity this, float movedt)
506 {
507         this.move_didgravity = -1;
508         switch (this.move_movetype)
509         {
510                 case MOVETYPE_PUSH:
511                 case MOVETYPE_FAKEPUSH:
512                         LOG_DEBUGF("Physics: Lacking QuakeC support for Push movetype, FIX ME by using engine physics!");
513                         break;
514                 case MOVETYPE_NONE:
515                         break;
516                 case MOVETYPE_FOLLOW:
517                         _Movetype_Physics_Follow(this);
518                         break;
519                 case MOVETYPE_NOCLIP:
520                         _Movetype_CheckWater(this);
521                         this.origin = this.origin + movedt * this.velocity;
522                         this.angles = this.angles + movedt * this.avelocity;
523                         _Movetype_LinkEdict(this, false);
524                         break;
525                 case MOVETYPE_STEP:
526                         _Movetype_Physics_Step(this, movedt);
527                         break;
528                 case MOVETYPE_WALK:
529                         _Movetype_Physics_Walk(this, movedt);
530                         break;
531                 case MOVETYPE_TOSS:
532                 case MOVETYPE_BOUNCE:
533                 case MOVETYPE_BOUNCEMISSILE:
534                 case MOVETYPE_FLYMISSILE:
535                 case MOVETYPE_FLY:
536                 case MOVETYPE_FLY_WORLDONLY:
537                         _Movetype_Physics_Toss(this, movedt);
538                         if(wasfreed(this))
539                                 return;
540                         _Movetype_LinkEdict(this, true);
541                         break;
542                 case MOVETYPE_PHYSICS:
543                         break;
544         }
545 }
546
547 void _Movetype_Physics_ClientFrame(entity this, float movedt)
548 {
549         this.move_didgravity = -1;
550         switch (this.move_movetype)
551         {
552                 case MOVETYPE_PUSH:
553                 case MOVETYPE_FAKEPUSH:
554                         LOG_DEBUGF("Physics: Lacking QuakeC support for Push movetype, FIX ME by using engine physics!");
555                         break;
556                 case MOVETYPE_NONE:
557                         break;
558                 case MOVETYPE_FOLLOW:
559                         _Movetype_Physics_Follow(this);
560                         break;
561                 case MOVETYPE_NOCLIP:
562                         _Movetype_CheckWater(this);
563                         this.origin = this.origin + movedt * this.velocity;
564                         this.angles = this.angles + movedt * this.avelocity;
565                         break;
566                 case MOVETYPE_STEP:
567                         _Movetype_Physics_Step(this, movedt);
568                         break;
569                 case MOVETYPE_WALK:
570                 case MOVETYPE_FLY:
571                 case MOVETYPE_FLY_WORLDONLY:
572                         _Movetype_Physics_Walk(this, movedt);
573                         break;
574                 case MOVETYPE_TOSS:
575                 case MOVETYPE_BOUNCE:
576                 case MOVETYPE_BOUNCEMISSILE:
577                 case MOVETYPE_FLYMISSILE:
578                         _Movetype_Physics_Toss(this, movedt);
579                         break;
580                 case MOVETYPE_PHYSICS:
581                         break;
582         }
583
584         //_Movetype_CheckVelocity(this);
585
586         _Movetype_LinkEdict(this, true);
587
588         //_Movetype_CheckVelocity(this);
589 }
590
591 void Movetype_Physics_NoMatchTicrate(entity this, float movedt, bool isclient)  // to be run every move frame
592 {
593         this.move_time = time;
594
595         if(isclient)
596                 _Movetype_Physics_ClientFrame(this, movedt);
597         else
598                 _Movetype_Physics_Frame(this, movedt);
599         if(wasfreed(this))
600                 return;
601
602         setorigin(this, this.origin);
603 }
604
605 void Movetype_Physics_NoMatchServer(entity this)  // optimized
606 {
607         float movedt = time - this.move_time;
608         this.move_time = time;
609
610         _Movetype_Physics_Frame(this, movedt);
611         if(wasfreed(this))
612                 return;
613
614         setorigin(this, this.origin);
615 }
616
617 void Movetype_Physics_MatchServer(entity this, bool sloppy)
618 {
619         Movetype_Physics_MatchTicrate(this, TICRATE, sloppy);
620 }
621
622 .vector tic_origin;
623 .vector tic_velocity;
624 .int tic_flags;
625 .vector tic_avelocity;
626 .vector tic_angles;
627
628 .vector tic_saved_origin;
629 .vector tic_saved_velocity;
630 .int tic_saved_flags;
631 .vector tic_saved_avelocity;
632 .vector tic_saved_angles;
633 void Movetype_Physics_MatchTicrate(entity this, float tr, bool sloppy)  // SV_Physics_Entity
634 {
635 #define X(s) \
636         if(this.(s) != this.tic_saved_##s) \
637                 this.tic_##s = this.(s)
638
639         X(origin);
640         X(velocity);
641         X(flags);
642         X(avelocity);
643         X(angles);
644 #undef X
645
646         if(tr <= 0)
647         {
648                 this.flags = this.tic_flags;
649                 this.velocity = this.tic_velocity;
650                 this.origin = this.tic_origin;
651                 this.avelocity = this.tic_avelocity;
652                 this.angles = this.tic_angles;
653                 Movetype_Physics_NoMatchServer(this);
654                 this.tic_origin = this.origin;
655                 this.tic_velocity = this.velocity;
656                 this.tic_avelocity = this.avelocity;
657                 this.tic_angles = this.angles;
658                 this.tic_flags = this.flags;
659
660                 this.tic_saved_flags = this.flags;
661                 this.tic_saved_velocity = this.velocity;
662                 this.tic_saved_origin = this.origin;
663                 this.tic_saved_avelocity = this.avelocity;
664                 this.tic_saved_angles = this.angles;
665                 return;
666         }
667
668         float dt = time - this.move_time;
669
670         int n = max(0, floor(dt / tr));
671         dt -= n * tr;
672         this.move_time += n * tr;
673
674         if(!this.move_didgravity)
675                 this.move_didgravity = ((this.move_movetype == MOVETYPE_BOUNCE || this.move_movetype == MOVETYPE_TOSS) && !(this.tic_flags & FL_ONGROUND));
676
677         for (int i = 0; i < n; ++i)
678         {
679                 this.flags = this.tic_flags;
680                 this.velocity = this.tic_velocity;
681                 setorigin(this, this.tic_origin);
682                 this.avelocity = this.tic_avelocity;
683                 this.angles = this.tic_angles;
684                 _Movetype_Physics_Frame(this, tr);
685                 this.tic_origin = this.origin;
686                 this.tic_velocity = this.velocity;
687                 this.tic_avelocity = this.avelocity;
688                 this.tic_angles = this.angles;
689                 this.tic_flags = this.flags;
690                 if(wasfreed(this))
691                         return;
692         }
693
694         this.avelocity = this.tic_avelocity;
695
696         if(dt > 0 && this.move_movetype != MOVETYPE_NONE && !(this.tic_flags & FL_ONGROUND))
697         {
698                 // now continue the move from move_time to time
699                 this.velocity = this.tic_velocity;
700
701                 if(this.move_didgravity > 0)
702                 {
703                         this.velocity_z -= (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE ? 0.5 : 1)
704                             * dt
705                             * (this.gravity ? this.gravity : 1)
706                             * PHYS_GRAVITY(this);
707                 }
708
709                 this.angles = this.tic_angles + dt * this.avelocity;
710
711                 if(sloppy || this.move_movetype == MOVETYPE_NOCLIP)
712                 {
713                         setorigin(this, this.tic_origin + dt * this.velocity);
714                 }
715                 else
716                 {
717                         vector oldorg = this.origin;
718                         this.origin = this.tic_origin;
719                         _Movetype_PushEntityTrace(this, dt * this.velocity);
720                         this.origin = oldorg;
721                         if(!trace_startsolid)
722                                 setorigin(this, trace_endpos);
723                 }
724
725                 if(this.move_didgravity > 0 && GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
726                         this.velocity_z -= 0.5 * dt * (this.gravity ? this.gravity : 1) * PHYS_GRAVITY(this);
727         }
728         else
729         {
730                 this.velocity = this.tic_velocity;
731                 this.angles = this.tic_angles;
732                 setorigin(this, this.tic_origin);
733         }
734
735         this.tic_saved_flags = this.flags;
736         this.tic_saved_velocity = this.velocity;
737         this.tic_saved_origin = this.origin;
738         this.tic_saved_avelocity = this.avelocity;
739         this.tic_saved_angles = this.angles;
740 }