]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/physics/movetypes/movetypes.qc
Merge branch 'sev/lumaIcons' into 'master'
[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(applygravity)
236         {
237                 if(!GAMEPLAYFIX_NOGRAVITYONGROUND || !IS_ONGROUND(this))
238                 {
239                         if(GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
240                                 this.velocity_z -= grav * 0.5f;
241                 }
242         }
243
244         return blocked;
245 }
246
247 void _Movetype_CheckVelocity(entity this)  // SV_CheckVelocity
248 {
249         // if(vlen(this.velocity) < 0.0001)
250         // this.velocity = '0 0 0';
251 }
252
253 bool _Movetype_CheckWater(entity this)  // SV_CheckWater
254 {
255         vector point = this.origin;
256         point.z += this.mins.z + 1;
257
258         int nativecontents = pointcontents(point);
259         if(this.watertype && this.watertype != nativecontents)
260         {
261                 // dprintf("_Movetype_CheckWater(): Original: '%d', New: '%d'\n", this.watertype, nativecontents);
262                 if(this.contentstransition)
263                         this.contentstransition(this.watertype, nativecontents);
264         }
265
266         this.waterlevel = WATERLEVEL_NONE;
267         this.watertype = CONTENT_EMPTY;
268
269         int supercontents = Mod_Q1BSP_SuperContentsFromNativeContents(nativecontents);
270         if(supercontents & DPCONTENTS_LIQUIDSMASK)
271         {
272                 this.watertype = nativecontents;
273                 this.waterlevel = WATERLEVEL_WETFEET;
274                 point.z = this.origin.z + (this.mins.z + this.maxs.z) * 0.5;
275                 if(Mod_Q1BSP_SuperContentsFromNativeContents(pointcontents(point)) & DPCONTENTS_LIQUIDSMASK)
276                 {
277                         this.waterlevel = WATERLEVEL_SWIMMING;
278                         point.z = this.origin.z + this.view_ofs.z;
279                         if(Mod_Q1BSP_SuperContentsFromNativeContents(pointcontents(point)) & DPCONTENTS_LIQUIDSMASK)
280                                 this.waterlevel = WATERLEVEL_SUBMERGED;
281                 }
282         }
283
284         return this.waterlevel > 1;
285 }
286
287 void _Movetype_CheckWaterTransition(entity ent)  // SV_CheckWaterTransition
288 {
289         int contents = pointcontents(ent.origin);
290
291         if(!ent.watertype)
292         {
293                 // just spawned here
294                 if(!GAMEPLAYFIX_WATERTRANSITION(ent))
295                 {
296                         ent.watertype = contents;
297                         ent.waterlevel = 1;
298                         return;
299                 }
300         }
301         else if(ent.watertype != contents)
302         {
303                 // dprintf("_Movetype_CheckWaterTransition(): Origin: %s, Direct: '%d', Original: '%d', New: '%d'\n", vtos(ent.origin), pointcontents(ent.origin), ent.watertype, contents);
304                 if(ent.contentstransition)
305                         ent.contentstransition(ent.watertype, contents);
306         }
307
308         if(contents <= CONTENT_WATER)
309         {
310                 ent.watertype = contents;
311                 ent.waterlevel = 1;
312         }
313         else
314         {
315                 ent.watertype = CONTENT_EMPTY;
316                 ent.waterlevel = (GAMEPLAYFIX_WATERTRANSITION(ent) ? 0 : contents);
317         }
318 }
319
320 void _Movetype_Impact(entity this, entity oth)  // SV_Impact
321 {
322         if(gettouch(this))
323                 gettouch(this)(this, oth);
324
325         if(gettouch(oth))
326                 gettouch(oth)(oth, this);
327 }
328
329 void _Movetype_LinkEdict_TouchAreaGrid(entity this)  // SV_LinkEdict_TouchAreaGrid
330 {
331         if(this.solid == SOLID_NOT)
332                 return;
333
334     FOREACH_ENTITY_RADIUS(0.5 * (this.absmin + this.absmax), 0.5 * vlen(this.absmax - this.absmin), true, {
335                 if (it.solid == SOLID_TRIGGER && it != this)
336                 if (it.move_nomonsters != MOVE_NOMONSTERS && it.move_nomonsters != MOVE_WORLDONLY)
337                 if (gettouch(it) && boxesoverlap(it.absmin, it.absmax, this.absmin, this.absmax))
338                 {
339                         trace_allsolid = false;
340                         trace_startsolid = false;
341                         trace_fraction = 1;
342                         trace_inwater = false;
343                         trace_inopen = true;
344                         trace_endpos = it.origin;
345                         trace_plane_normal = '0 0 1';
346                         trace_plane_dist = 0;
347                         trace_ent = this;
348
349                         gettouch(it)(it, this);
350                 }
351     });
352 }
353
354 bool autocvar__movetype_debug = false;
355 void _Movetype_LinkEdict(entity this, bool touch_triggers)  // SV_LinkEdict
356 {
357         if(autocvar__movetype_debug)
358         {
359                 vector mi, ma;
360                 if(this.solid == SOLID_BSP)
361                 {
362                         // TODO set the absolute bbox
363                         mi = this.mins;
364                         ma = this.maxs;
365                 }
366                 else
367                 {
368                         mi = this.mins;
369                         ma = this.maxs;
370                 }
371                 mi += this.origin;
372                 ma += this.origin;
373
374                 if(this.flags & FL_ITEM)
375                 {
376                         mi -= '15 15 1';
377                         ma += '15 15 1';
378                 }
379                 else
380                 {
381                         mi -= '1 1 1';
382                         ma += '1 1 1';
383                 }
384
385                 this.absmin = mi;
386                 this.absmax = ma;
387         }
388         else
389         {
390                 setorigin(this, this.origin); // calls SV_LinkEdict
391         #ifdef CSQC
392                 // NOTE: CSQC's version of setorigin doesn't expand
393                 this.absmin -= '1 1 1';
394                 this.absmax += '1 1 1';
395         #endif
396         }
397
398         if(touch_triggers)
399                 _Movetype_LinkEdict_TouchAreaGrid(this);
400 }
401
402 entity _Movetype_TestEntityPosition_ent;
403 bool _Movetype_TestEntityPosition(vector ofs)  // SV_TestEntityPosition
404 {
405     entity this = _Movetype_TestEntityPosition_ent;
406 //      vector org = this.origin + ofs;
407
408         int cont = this.dphitcontentsmask;
409         this.dphitcontentsmask = DPCONTENTS_SOLID;
410         tracebox(this.origin, this.mins, this.maxs, this.origin, ((this.move_movetype == MOVETYPE_FLY_WORLDONLY) ? MOVE_WORLDONLY : MOVE_NOMONSTERS), this);
411         this.dphitcontentsmask = cont;
412
413         if(trace_startsolid)
414                 return true;
415
416         if(vdist(trace_endpos - this.origin, >, 0.0001))
417                 this.origin = trace_endpos;
418         return false;
419 }
420
421 bool _Movetype_UnstickEntity(entity this)  // SV_UnstickEntity
422 {
423     _Movetype_TestEntityPosition_ent = this;
424         if (!_Movetype_TestEntityPosition(' 0  0  0')) {
425             return true;
426         }
427         #define X(v) if (_Movetype_TestEntityPosition(v))
428         X('-1  0  0') X(' 1  0  0')
429         X(' 0 -1  0') X(' 0  1  0')
430         X('-1 -1  0') X(' 1 -1  0')
431         X('-1  1  0') X(' 1  1  0')
432         #undef X
433         {
434         #define X(i) \
435             if (_Movetype_TestEntityPosition('0 0 -1' * i)) \
436             if (_Movetype_TestEntityPosition('0 0 1' * i))
437         X(01) X(02) X(03) X(04) X(05) X(06) X(07) X(08)
438         X(09) X(10) X(11) X(12) X(13) X(14) X(15) X(16)
439         X(17)
440         #undef X
441         {
442             LOG_DEBUGF("Can't unstick an entity (edict: %d, classname: %s, origin: %s)",
443                 etof(this), this.classname, vtos(this.origin));
444             return false;
445         }
446         }
447         LOG_DEBUGF("Sucessfully unstuck an entity (edict: %d, classname: %s, origin: %s)",
448                 etof(this), this.classname, vtos(this.origin));
449         _Movetype_LinkEdict(this, true);
450         return true;
451 }
452
453 vector _Movetype_ClipVelocity(vector vel, vector norm, float f)  // SV_ClipVelocity
454 {
455         vel -= ((vel * norm) * norm) * f;
456
457         if(vel.x > -0.1 && vel.x < 0.1) vel.x = 0;
458         if(vel.y > -0.1 && vel.y < 0.1) vel.y = 0;
459         if(vel.z > -0.1 && vel.z < 0.1) vel.z = 0;
460
461         return vel;
462 }
463
464 void _Movetype_PushEntityTrace(entity this, vector push)
465 {
466         vector end = this.origin + push;
467         int type;
468         if(this.move_nomonsters)
469                 type = max(0, this.move_nomonsters);
470         else if(this.move_movetype == MOVETYPE_FLYMISSILE)
471                 type = MOVE_MISSILE;
472         else if(this.move_movetype == MOVETYPE_FLY_WORLDONLY)
473                 type = MOVE_WORLDONLY;
474         else if(this.solid == SOLID_TRIGGER || this.solid == SOLID_NOT)
475                 type = MOVE_NOMONSTERS;
476         else
477                 type = MOVE_NORMAL;
478
479         tracebox(this.origin, this.mins, this.maxs, end, type, this);
480 }
481
482 float _Movetype_PushEntity(entity this, vector push, bool failonstartsolid)  // SV_PushEntity
483 {
484         _Movetype_PushEntityTrace(this, push);
485
486         if(trace_startsolid && failonstartsolid)
487                 return trace_fraction;
488
489         this.origin = trace_endpos;
490
491         if(trace_fraction < 1)
492                 if(this.solid >= SOLID_TRIGGER && (!IS_ONGROUND(this) || (this.groundentity != trace_ent)))
493                         _Movetype_Impact(this, trace_ent);
494
495         return trace_fraction;
496 }
497
498
499 .float ltime;
500 .void() blocked;
501
502 void _Movetype_Physics_Frame(entity this, float movedt)
503 {
504         this.move_didgravity = -1;
505         switch (this.move_movetype)
506         {
507                 case MOVETYPE_PUSH:
508                 case MOVETYPE_FAKEPUSH:
509                         LOG_DEBUGF("Physics: Lacking QuakeC support for Push movetype, FIX ME by using engine physics!");
510                         break;
511                 case MOVETYPE_NONE:
512                         break;
513                 case MOVETYPE_FOLLOW:
514                         _Movetype_Physics_Follow(this);
515                         break;
516                 case MOVETYPE_NOCLIP:
517                         _Movetype_CheckWater(this);
518                         this.origin = this.origin + movedt * this.velocity;
519                         this.angles = this.angles + movedt * this.avelocity;
520                         _Movetype_LinkEdict(this, false);
521                         break;
522                 case MOVETYPE_STEP:
523                         _Movetype_Physics_Step(this, movedt);
524                         break;
525                 case MOVETYPE_WALK:
526                         _Movetype_Physics_Walk(this, movedt);
527                         break;
528                 case MOVETYPE_TOSS:
529                 case MOVETYPE_BOUNCE:
530                 case MOVETYPE_BOUNCEMISSILE:
531                 case MOVETYPE_FLYMISSILE:
532                 case MOVETYPE_FLY:
533                 case MOVETYPE_FLY_WORLDONLY:
534                         _Movetype_Physics_Toss(this, movedt);
535                         if(wasfreed(this))
536                                 return;
537                         _Movetype_LinkEdict(this, true);
538                         break;
539                 case MOVETYPE_PHYSICS:
540                         break;
541         }
542 }
543
544 void _Movetype_Physics_ClientFrame(entity this, float movedt)
545 {
546         this.move_didgravity = -1;
547         switch (this.move_movetype)
548         {
549                 case MOVETYPE_PUSH:
550                 case MOVETYPE_FAKEPUSH:
551                         LOG_DEBUGF("Physics: Lacking QuakeC support for Push movetype, FIX ME by using engine physics!");
552                         break;
553                 case MOVETYPE_NONE:
554                         break;
555                 case MOVETYPE_FOLLOW:
556                         _Movetype_Physics_Follow(this);
557                         break;
558                 case MOVETYPE_NOCLIP:
559                         _Movetype_CheckWater(this);
560                         this.origin = this.origin + movedt * this.velocity;
561                         this.angles = this.angles + movedt * this.avelocity;
562                         break;
563                 case MOVETYPE_STEP:
564                         _Movetype_Physics_Step(this, movedt);
565                         break;
566                 case MOVETYPE_WALK:
567                 case MOVETYPE_FLY:
568                 case MOVETYPE_FLY_WORLDONLY:
569                         _Movetype_Physics_Walk(this, movedt);
570                         break;
571                 case MOVETYPE_TOSS:
572                 case MOVETYPE_BOUNCE:
573                 case MOVETYPE_BOUNCEMISSILE:
574                 case MOVETYPE_FLYMISSILE:
575                         _Movetype_Physics_Toss(this, movedt);
576                         break;
577                 case MOVETYPE_PHYSICS:
578                         break;
579         }
580
581         //_Movetype_CheckVelocity(this);
582
583         _Movetype_LinkEdict(this, true);
584
585         //_Movetype_CheckVelocity(this);
586 }
587
588 void Movetype_Physics_NoMatchTicrate(entity this, float movedt, bool isclient)  // to be run every move frame
589 {
590         this.move_time = time;
591
592         if(isclient)
593                 _Movetype_Physics_ClientFrame(this, movedt);
594         else
595                 _Movetype_Physics_Frame(this, movedt);
596         if(wasfreed(this))
597                 return;
598
599         setorigin(this, this.origin);
600 }
601
602 void Movetype_Physics_NoMatchServer(entity this)  // optimized
603 {
604         float movedt = time - this.move_time;
605         this.move_time = time;
606
607         _Movetype_Physics_Frame(this, movedt);
608         if(wasfreed(this))
609                 return;
610
611         setorigin(this, this.origin);
612 }
613
614 void Movetype_Physics_MatchServer(entity this, bool sloppy)
615 {
616         Movetype_Physics_MatchTicrate(this, TICRATE, sloppy);
617 }
618
619 .vector tic_origin;
620 .vector tic_velocity;
621 .int tic_flags;
622 .vector tic_avelocity;
623 .vector tic_angles;
624
625 .vector tic_saved_origin;
626 .vector tic_saved_velocity;
627 .int tic_saved_flags;
628 .vector tic_saved_avelocity;
629 .vector tic_saved_angles;
630 void Movetype_Physics_MatchTicrate(entity this, float tr, bool sloppy)  // SV_Physics_Entity
631 {
632 #define X(s) \
633         if(this.(s) != this.tic_saved_##s) \
634                 this.tic_##s = this.(s)
635
636         X(origin);
637         X(velocity);
638         X(flags);
639         X(avelocity);
640         X(angles);
641 #undef X
642
643         if(tr <= 0)
644         {
645                 this.flags = this.tic_flags;
646                 this.velocity = this.tic_velocity;
647                 this.origin = this.tic_origin;
648                 this.avelocity = this.tic_avelocity;
649                 this.angles = this.tic_angles;
650                 Movetype_Physics_NoMatchServer(this);
651                 this.tic_origin = this.origin;
652                 this.tic_velocity = this.velocity;
653                 this.tic_avelocity = this.avelocity;
654                 this.tic_angles = this.angles;
655                 this.tic_flags = this.flags;
656
657                 this.tic_saved_flags = this.flags;
658                 this.tic_saved_velocity = this.velocity;
659                 this.tic_saved_origin = this.origin;
660                 this.tic_saved_avelocity = this.avelocity;
661                 this.tic_saved_angles = this.angles;
662                 return;
663         }
664
665         float dt = time - this.move_time;
666
667         int n = max(0, floor(dt / tr));
668         dt -= n * tr;
669         this.move_time += n * tr;
670
671         if(!this.move_didgravity)
672                 this.move_didgravity = ((this.move_movetype == MOVETYPE_BOUNCE || this.move_movetype == MOVETYPE_TOSS) && !(this.tic_flags & FL_ONGROUND));
673
674         for (int i = 0; i < n; ++i)
675         {
676                 this.flags = this.tic_flags;
677                 this.velocity = this.tic_velocity;
678                 setorigin(this, this.tic_origin);
679                 this.avelocity = this.tic_avelocity;
680                 this.angles = this.tic_angles;
681                 _Movetype_Physics_Frame(this, tr);
682                 this.tic_origin = this.origin;
683                 this.tic_velocity = this.velocity;
684                 this.tic_avelocity = this.avelocity;
685                 this.tic_angles = this.angles;
686                 this.tic_flags = this.flags;
687                 if(wasfreed(this))
688                         return;
689         }
690
691         this.avelocity = this.tic_avelocity;
692
693         if(dt > 0 && this.move_movetype != MOVETYPE_NONE && !(this.tic_flags & FL_ONGROUND))
694         {
695                 // now continue the move from move_time to time
696                 this.velocity = this.tic_velocity;
697
698                 if(this.move_didgravity > 0)
699                 {
700                         this.velocity_z -= (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE ? 0.5 : 1)
701                             * dt
702                             * (this.gravity ? this.gravity : 1)
703                             * PHYS_GRAVITY(this);
704                 }
705
706                 this.angles = this.tic_angles + dt * this.avelocity;
707
708                 if(sloppy || this.move_movetype == MOVETYPE_NOCLIP)
709                 {
710                         setorigin(this, this.tic_origin + dt * this.velocity);
711                 }
712                 else
713                 {
714                         vector oldorg = this.origin;
715                         this.origin = this.tic_origin;
716                         _Movetype_PushEntityTrace(this, dt * this.velocity);
717                         this.origin = oldorg;
718                         if(!trace_startsolid)
719                                 setorigin(this, trace_endpos);
720                 }
721
722                 if(this.move_didgravity > 0 && GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
723                         this.velocity_z -= 0.5 * dt * (this.gravity ? this.gravity : 1) * PHYS_GRAVITY(this);
724         }
725         else
726         {
727                 this.velocity = this.tic_velocity;
728                 this.angles = this.tic_angles;
729                 setorigin(this, this.tic_origin);
730         }
731
732         this.tic_saved_flags = this.flags;
733         this.tic_saved_velocity = this.velocity;
734         this.tic_saved_origin = this.origin;
735         this.tic_saved_avelocity = this.avelocity;
736         this.tic_saved_angles = this.angles;
737 }