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