1 #include "movetypes.qh"
4 void set_movetype(entity this, int mt)
6 this.move_movetype = mt;
7 if (mt == MOVETYPE_PHYSICS) {
8 this.move_qcphysics = false;
9 } else if (autocvar_sv_qcphysics == 2) {
10 this.move_qcphysics = true;
12 if(!IL_CONTAINS(g_moveables, this))
13 IL_PUSH(g_moveables, this); // add it to the moveable entities list (even if it doesn't move!) logic: if an object never sets its movetype, we assume it never does anything notable
14 this.movetype = (this.move_qcphysics) ? MOVETYPE_QCENTITY : mt;
17 void set_movetype(entity this, int mt)
19 this.move_movetype = mt;
23 bool _Movetype_NudgeOutOfSolid_PivotIsKnownGood(entity this, vector pivot) // SV_NudgeOutOfSolid_PivotIsKnownGood
25 vector stuckorigin = this.origin;
26 vector goodmins = pivot, goodmaxs = pivot;
27 for(int bump = 0; bump < 6; bump++)
29 int coord = 2 - (bump >> 1);
32 for(int subbump = 0; ; ++subbump)
34 vector testorigin = stuckorigin;
40 case 0: testorigin.x += this.maxs_x - goodmaxs.x; break;
41 case 1: testorigin.y += this.maxs_y - goodmaxs.y; break;
42 case 2: testorigin.z += this.maxs_z - goodmaxs.z; break;
50 case 0: testorigin.x += this.mins_x - goodmins.x; break;
51 case 1: testorigin.y += this.mins_y - goodmins.y; break;
52 case 2: testorigin.z += this.mins_z - goodmins.z; break;
56 tracebox(stuckorigin, goodmins, goodmaxs, testorigin, MOVE_NOMONSTERS, this);
57 if(trace_startsolid && trace_ent.solid == SOLID_BSP) // NOTE: this checks for bmodelstartsolid in the engine
59 // BAD BAD, can't fix that
63 if(trace_fraction >= 1)
68 // BAD BAD, can't fix that
72 // we hit something... let's move out of it
73 vector move = trace_endpos - testorigin;
74 float nudge = (trace_plane_normal * move) + 0.03125; // FIXME cvar this constant
75 stuckorigin = stuckorigin + nudge * trace_plane_normal;
83 case 0: goodmaxs.x = this.maxs_x; break;
84 case 1: goodmaxs.y = this.maxs_y; break;
85 case 2: goodmaxs.z = this.maxs_z; break;
93 case 0: goodmins.x = this.mins_x; break;
94 case 1: goodmins.y = this.mins_y; break;
95 case 2: goodmins.z = this.mins_z; break;
101 this.origin = stuckorigin;
106 void _Movetype_WallFriction(entity this, vector stepnormal) // SV_WallFriction
110 makevectors(this.v_angle);
111 d = (stepnormal * v_forward) + 0.5;
115 i = (stepnormal * this.velocity);
116 into = i * stepnormal;
117 side = this.velocity - into;
118 this.velocity_x = side.x * (1 * d);
119 this.velocity_y = side.y * (1 * d);
123 vector planes[MAX_CLIP_PLANES];
124 int _Movetype_FlyMove(entity this, float dt, bool applygravity, bool applystepnormal, float stepheight) // SV_FlyMove
126 move_stepnormal = '0 0 0';
132 int i, j, numplanes = 0;
133 float time_left = dt, grav = 0;
135 vector primal_velocity, original_velocity;
136 vector restore_velocity = this.velocity;
138 for(i = 0; i < MAX_CLIP_PLANES; ++i)
143 this.move_didgravity = 1;
144 grav = dt * (this.gravity ? this.gravity : 1) * PHYS_GRAVITY(this);
146 if(!GAMEPLAYFIX_NOGRAVITYONGROUND || !IS_ONGROUND(this))
148 if(GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
149 this.velocity_z -= grav * 0.5;
151 this.velocity_z -= grav;
155 original_velocity = primal_velocity = this.velocity;
157 for(int bumpcount = 0;bumpcount < MAX_CLIP_PLANES;bumpcount++)
159 if(this.velocity == '0 0 0')
162 push = this.velocity * time_left;
163 if(!_Movetype_PushEntity(this, push, true, false))
165 // we got teleported by a touch function
166 // let's abort the move
171 // this code is used by MOVETYPE_WALK and MOVETYPE_STEP and SV_UnstickEntity
172 // abort move if we're stuck in the world (and didn't make it out)
173 if(trace_startsolid && trace_allsolid)
175 this.velocity = restore_velocity;
179 if(trace_fraction == 1)
182 float my_trace_fraction = trace_fraction;
183 vector my_trace_plane_normal = trace_plane_normal;
185 if(trace_plane_normal.z)
187 if(trace_plane_normal.z > 0.7)
194 //dprint("_Movetype_FlyMove: !trace_ent\n");
199 this.groundentity = trace_ent;
204 // step - handle it immediately
205 vector org = this.origin;
206 vector steppush = '0 0 1' * stepheight;
208 if(!_Movetype_PushEntity(this, steppush, true, false))
213 if(!_Movetype_PushEntity(this, push, true, false))
218 float trace2_fraction = trace_fraction;
219 steppush = vec3(0, 0, org.z - this.origin_z);
220 if(!_Movetype_PushEntity(this, steppush, true, false))
226 // accept the new position if it made some progress...
227 if(fabs(this.origin_x - org.x) >= 0.03125 || fabs(this.origin_y - org.y) >= 0.03125)
229 trace_endpos = this.origin;
230 time_left *= 1 - trace2_fraction;
239 // step - return it to caller
241 // save the trace for player extrafriction
243 move_stepnormal = trace_plane_normal;
246 if(my_trace_fraction >= 0.001)
248 // actually covered some distance
249 original_velocity = this.velocity;
253 time_left *= 1 - my_trace_fraction;
255 // clipped to another plane
256 if(numplanes >= MAX_CLIP_PLANES)
258 // this shouldn't really happen
259 this.velocity = '0 0 0';
264 planes[numplanes] = my_trace_plane_normal;
267 // modify original_velocity so it parallels all of the clip planes
268 vector new_velocity = '0 0 0';
269 for (i = 0;i < numplanes;i++)
271 new_velocity = _Movetype_ClipVelocity(original_velocity, planes[i], 1);
272 for (j = 0;j < numplanes;j++)
277 if((new_velocity * planes[j]) < 0)
287 // go along this plane
288 this.velocity = new_velocity;
292 // go along the crease
295 this.velocity = '0 0 0';
299 vector dir = cross(planes[0], planes[1]);
300 // LordHavoc: thanks to taniwha of QuakeForge for pointing out this fix for slowed falling in corners
301 float ilength = sqrt((dir * dir));
303 ilength = 1.0 / ilength;
307 float d = (dir * this.velocity);
308 this.velocity = dir * d;
311 // if current velocity is against the original velocity,
312 // stop dead to avoid tiny occilations in sloping corners
313 if((this.velocity * primal_velocity) <= 0)
315 this.velocity = '0 0 0';
320 // LordHavoc: this came from QW and allows you to get out of water more easily
321 if(GAMEPLAYFIX_EASIERWATERJUMP(this) && (this.flags & FL_WATERJUMP) && !(blockedflag & 8))
322 this.velocity = primal_velocity;
324 if(PHYS_WALLCLIP(this) && this.pm_time && !(this.flags & FL_WATERJUMP) && !(blockedflag & 8))
325 this.velocity = primal_velocity;
329 if(!GAMEPLAYFIX_NOGRAVITYONGROUND || !IS_ONGROUND(this))
331 if(GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
332 this.velocity_z -= grav * 0.5f;
339 void _Movetype_CheckVelocity(entity this) // SV_CheckVelocity
341 // if(vlen(this.velocity) < 0.0001)
342 // this.velocity = '0 0 0';
345 bool _Movetype_CheckWater(entity this) // SV_CheckWater
347 vector point = this.origin;
348 point.z += this.mins.z + 1;
350 int nativecontents = pointcontents(point);
351 if(this.watertype && this.watertype != nativecontents)
353 // dprintf("_Movetype_CheckWater(): Original: '%d', New: '%d'\n", this.watertype, nativecontents);
354 if(this.contentstransition)
355 this.contentstransition(this.watertype, nativecontents);
358 this.waterlevel = WATERLEVEL_NONE;
359 this.watertype = CONTENT_EMPTY;
361 int supercontents = Mod_Q1BSP_SuperContentsFromNativeContents(nativecontents);
362 if(supercontents & DPCONTENTS_LIQUIDSMASK)
364 this.watertype = nativecontents;
365 this.waterlevel = WATERLEVEL_WETFEET;
366 point.z = this.origin.z + (this.mins.z + this.maxs.z) * 0.5;
367 if(Mod_Q1BSP_SuperContentsFromNativeContents(pointcontents(point)) & DPCONTENTS_LIQUIDSMASK)
369 this.waterlevel = WATERLEVEL_SWIMMING;
370 point.z = this.origin.z + this.view_ofs.z;
371 if(Mod_Q1BSP_SuperContentsFromNativeContents(pointcontents(point)) & DPCONTENTS_LIQUIDSMASK)
372 this.waterlevel = WATERLEVEL_SUBMERGED;
376 return this.waterlevel > 1;
379 void _Movetype_CheckWaterTransition(entity ent) // SV_CheckWaterTransition
381 int contents = pointcontents(ent.origin);
386 if(!GAMEPLAYFIX_WATERTRANSITION(ent))
388 ent.watertype = contents;
393 else if(ent.watertype != contents)
395 // dprintf("_Movetype_CheckWaterTransition(): Origin: %s, Direct: '%d', Original: '%d', New: '%d'\n", vtos(ent.origin), pointcontents(ent.origin), ent.watertype, contents);
396 if(ent.contentstransition)
397 ent.contentstransition(ent.watertype, contents);
400 if(contents <= CONTENT_WATER)
402 ent.watertype = contents;
407 ent.watertype = CONTENT_EMPTY;
408 ent.waterlevel = (GAMEPLAYFIX_WATERTRANSITION(ent) ? 0 : contents);
412 void _Movetype_Impact(entity this, entity oth) // SV_Impact
417 // due to a lack of pointers in QC, we must save the trace values and restore them for other functions
418 bool save_trace_allsolid = trace_allsolid;
419 bool save_trace_startsolid = trace_startsolid;
420 float save_trace_fraction = trace_fraction;
421 bool save_trace_inwater = trace_inwater;
422 bool save_trace_inopen = trace_inopen;
423 vector save_trace_endpos = trace_endpos;
424 vector save_trace_plane_normal = trace_plane_normal;
425 float save_trace_plane_dist = trace_plane_dist;
426 entity save_trace_ent = trace_ent;
427 int save_trace_dpstartcontents = trace_dpstartcontents;
428 int save_trace_dphitcontents = trace_dphitcontents;
429 int save_trace_dphitq3surfaceflags = trace_dphitq3surfaceflags;
430 string save_trace_dphittexturename = trace_dphittexturename;
432 if(this.solid != SOLID_NOT && gettouch(this))
433 gettouch(this)(this, oth);
435 if(oth.solid != SOLID_NOT && gettouch(oth))
436 gettouch(oth)(oth, this);
438 trace_allsolid = save_trace_allsolid;
439 trace_startsolid = save_trace_startsolid;
440 trace_fraction = save_trace_fraction;
441 trace_inwater = save_trace_inwater;
442 trace_inopen = save_trace_inopen;
443 trace_endpos = save_trace_endpos;
444 trace_plane_normal = save_trace_plane_normal;
445 trace_plane_dist = save_trace_plane_dist;
446 trace_ent = save_trace_ent;
447 trace_dpstartcontents = save_trace_dpstartcontents;
448 trace_dphitcontents = save_trace_dphitcontents;
449 trace_dphitq3surfaceflags = save_trace_dphitq3surfaceflags;
450 trace_dphittexturename = save_trace_dphittexturename;
453 void _Movetype_LinkEdict_TouchAreaGrid(entity this) // SV_LinkEdict_TouchAreaGrid
455 if(this.solid == SOLID_NOT)
458 // due to a lack of pointers in QC, we must save the trace values and restore them for other functions
459 bool save_trace_allsolid = trace_allsolid;
460 bool save_trace_startsolid = trace_startsolid;
461 float save_trace_fraction = trace_fraction;
462 bool save_trace_inwater = trace_inwater;
463 bool save_trace_inopen = trace_inopen;
464 vector save_trace_endpos = trace_endpos;
465 vector save_trace_plane_normal = trace_plane_normal;
466 float save_trace_plane_dist = trace_plane_dist;
467 entity save_trace_ent = trace_ent;
468 int save_trace_dpstartcontents = trace_dpstartcontents;
469 int save_trace_dphitcontents = trace_dphitcontents;
470 int save_trace_dphitq3surfaceflags = trace_dphitq3surfaceflags;
471 string save_trace_dphittexturename = trace_dphittexturename;
473 FOREACH_ENTITY_RADIUS_ORDERED(0.5 * (this.absmin + this.absmax), 0.5 * vlen(this.absmax - this.absmin), true, {
474 if (it.solid == SOLID_TRIGGER && it != this)
475 if (it.move_nomonsters != MOVE_NOMONSTERS && it.move_nomonsters != MOVE_WORLDONLY)
476 if (gettouch(it) && boxesoverlap(it.absmin, it.absmax, this.absmin, this.absmax))
478 trace_allsolid = false;
479 trace_startsolid = false;
481 trace_inwater = false;
483 trace_endpos = it.origin;
484 trace_plane_normal = '0 0 1';
485 trace_plane_dist = 0;
487 trace_dpstartcontents = 0;
488 trace_dphitcontents = 0;
489 trace_dphitq3surfaceflags = 0;
490 trace_dphittexturename = string_null;
492 gettouch(it)(it, this);
496 trace_allsolid = save_trace_allsolid;
497 trace_startsolid = save_trace_startsolid;
498 trace_fraction = save_trace_fraction;
499 trace_inwater = save_trace_inwater;
500 trace_inopen = save_trace_inopen;
501 trace_endpos = save_trace_endpos;
502 trace_plane_normal = save_trace_plane_normal;
503 trace_plane_dist = save_trace_plane_dist;
504 trace_ent = save_trace_ent;
505 trace_dpstartcontents = save_trace_dpstartcontents;
506 trace_dphitcontents = save_trace_dphitcontents;
507 trace_dphitq3surfaceflags = save_trace_dphitq3surfaceflags;
508 trace_dphittexturename = save_trace_dphittexturename;
511 bool autocvar__movetype_debug = false;
512 void _Movetype_LinkEdict(entity this, bool touch_triggers) // SV_LinkEdict
514 if(autocvar__movetype_debug)
517 if(this.solid == SOLID_BSP)
519 // TODO set the absolute bbox
531 if(this.flags & FL_ITEM)
547 setorigin(this, this.origin); // calls SV_LinkEdict
549 // NOTE: CSQC's version of setorigin doesn't expand
550 this.absmin -= '1 1 1';
551 this.absmax += '1 1 1';
556 _Movetype_LinkEdict_TouchAreaGrid(this);
559 int _Movetype_ContentsMask(entity this) // SV_GenericHitSuperContentsMask
563 if(this.dphitcontentsmask)
564 return this.dphitcontentsmask;
565 else if(this.solid == SOLID_SLIDEBOX)
567 if(this.flags & FL_MONSTER)
568 return DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_MONSTERCLIP;
570 return DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP;
572 else if(this.solid == SOLID_CORPSE)
573 return DPCONTENTS_SOLID | DPCONTENTS_BODY;
574 else if(this.solid == SOLID_TRIGGER)
575 return DPCONTENTS_SOLID | DPCONTENTS_BODY;
577 return DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_CORPSE;
580 return DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_CORPSE;
583 entity _Movetype_TestEntityPosition_ent;
584 bool _Movetype_TestEntityPosition(vector ofs) // SV_TestEntityPosition
586 entity this = _Movetype_TestEntityPosition_ent;
587 vector org = this.origin + ofs;
589 //int cont = this.dphitcontentsmask;
590 //this.dphitcontentsmask = DPCONTENTS_SOLID;
591 tracebox(org, this.mins, this.maxs, this.origin, ((this.move_movetype == MOVETYPE_FLY_WORLDONLY) ? MOVE_WORLDONLY : MOVE_NOMONSTERS), this);
592 //this.dphitcontentsmask = cont;
593 if(trace_dpstartcontents & _Movetype_ContentsMask(this))
596 if(vlen2(trace_endpos - this.origin) >= 0.0001)
598 tracebox(trace_endpos, this.mins, this.maxs, trace_endpos, MOVE_NOMONSTERS, this);
599 if(!trace_startsolid)
600 this.origin = trace_endpos;
605 bool _Movetype_TestEntityPosition_Offset(int offset)
607 // NOTE: expects _Movetype_TestEntityPosition_ent to be set to the correct entity
608 // returns true if stuck
610 // start at 2, since the first position has already been checked
611 for(int j = 2; j <= offset; ++j)
613 if(!_Movetype_TestEntityPosition('0 0 -1' * j))
615 if(!_Movetype_TestEntityPosition('0 0 1' * j))
622 int _Movetype_UnstickEntity(entity this) // SV_UnstickEntity
624 _Movetype_TestEntityPosition_ent = this;
625 if (!_Movetype_TestEntityPosition(' 0 0 0')) {
628 #define X(v) if (_Movetype_TestEntityPosition(v))
629 X('0 0 -1') X(' 0 0 1')
630 X('-1 0 0') X(' 1 0 0')
631 X(' 0 -1 0') X(' 0 1 0')
632 X('-1 -1 0') X(' 1 -1 0')
633 X('-1 1 0') X(' 1 1 0')
636 if(_Movetype_TestEntityPosition_Offset(rint((this.maxs.z - this.mins.z) * 0.36)))
638 LOG_DEBUGF("Can't unstick an entity (edict: %d, classname: %s, origin: %s)",
639 etof(this), this.classname, vtos(this.origin));
640 return UNSTICK_STUCK;
643 LOG_DEBUGF("Sucessfully unstuck an entity (edict: %d, classname: %s, origin: %s)",
644 etof(this), this.classname, vtos(this.origin));
645 _Movetype_LinkEdict(this, false);
646 return UNSTICK_FIXED;
649 void _Movetype_CheckStuck(entity this) // SV_CheckStuck
651 int unstick = _Movetype_UnstickEntity(this); // sets test position entity
655 this.oldorigin = this.origin;
658 break; // already sorted
660 vector offset = this.oldorigin - this.origin;
661 if(!_Movetype_TestEntityPosition(offset))
662 _Movetype_LinkEdict(this, false);
663 // couldn't unstick, should we warn about this?
668 vector _Movetype_ClipVelocity(vector vel, vector norm, float f) // ClipVelocity
670 vel -= ((vel * norm) * norm) * f;
672 if(vel.x > -0.1 && vel.x < 0.1) vel.x = 0;
673 if(vel.y > -0.1 && vel.y < 0.1) vel.y = 0;
674 if(vel.z > -0.1 && vel.z < 0.1) vel.z = 0;
679 void _Movetype_PushEntityTrace(entity this, vector push)
681 vector end = this.origin + push;
683 if(this.move_nomonsters)
684 type = max(0, this.move_nomonsters);
685 else if(this.move_movetype == MOVETYPE_FLYMISSILE)
687 else if(this.move_movetype == MOVETYPE_FLY_WORLDONLY)
688 type = MOVE_WORLDONLY;
689 else if(this.solid == SOLID_TRIGGER || this.solid == SOLID_NOT)
690 type = MOVE_NOMONSTERS;
694 tracebox(this.origin, this.mins, this.maxs, end, type, this);
697 bool _Movetype_PushEntity(entity this, vector push, bool failonstartsolid, bool dolink) // SV_PushEntity
699 _Movetype_PushEntityTrace(this, push);
701 // NOTE: this is a workaround for the QC's lack of a worldstartsolid trace parameter
702 if(trace_startsolid && failonstartsolid)
704 int oldtype = this.move_nomonsters;
705 this.move_nomonsters = MOVE_WORLDONLY;
706 _Movetype_PushEntityTrace(this, push);
707 this.move_nomonsters = oldtype;
712 this.origin = trace_endpos;
714 vector last_origin = this.origin;
716 _Movetype_LinkEdict(this, dolink);
718 if((this.solid >= SOLID_TRIGGER && trace_fraction < 1 && (!IS_ONGROUND(this) || this.groundentity != trace_ent)))
719 _Movetype_Impact(this, trace_ent);
721 return (this.origin == last_origin); // false if teleported by touch
724 void _Movetype_Physics_Frame(entity this, float movedt)
726 this.move_didgravity = -1;
727 switch (this.move_movetype)
730 case MOVETYPE_FAKEPUSH:
731 _Movetype_Physics_Push(this, movedt);
735 case MOVETYPE_FOLLOW:
736 _Movetype_Physics_Follow(this);
738 case MOVETYPE_NOCLIP:
739 _Movetype_CheckWater(this);
740 this.origin = this.origin + movedt * this.velocity;
741 this.angles = this.angles + movedt * this.avelocity;
742 _Movetype_LinkEdict(this, false);
745 _Movetype_Physics_Step(this, movedt);
748 _Movetype_Physics_Walk(this, movedt);
751 case MOVETYPE_BOUNCE:
752 case MOVETYPE_BOUNCEMISSILE:
753 case MOVETYPE_FLYMISSILE:
755 case MOVETYPE_FLY_WORLDONLY:
756 _Movetype_Physics_Toss(this, movedt);
758 case MOVETYPE_PHYSICS:
763 void _Movetype_Physics_ClientFrame(entity this, float movedt)
765 this.move_didgravity = -1;
766 switch (this.move_movetype)
769 case MOVETYPE_FAKEPUSH:
770 LOG_DEBUG("Physics: Lacking QuakeC support for Push movetype, FIX ME by using engine physics!");
774 case MOVETYPE_FOLLOW:
775 _Movetype_Physics_Follow(this);
777 case MOVETYPE_NOCLIP:
778 _Movetype_CheckWater(this);
779 this.origin = this.origin + movedt * this.velocity;
780 this.angles = this.angles + movedt * this.avelocity;
783 if (GAMEPLAYFIX_UNSTICKPLAYERS(this) == 2)
784 _Movetype_CheckStuck(this);
785 _Movetype_Physics_Step(this, movedt);
789 case MOVETYPE_FLY_WORLDONLY:
790 if (movedt > 0 && GAMEPLAYFIX_UNSTICKPLAYERS(this) == 2)
791 _Movetype_CheckStuck(this);
792 _Movetype_Physics_Walk(this, movedt);
795 case MOVETYPE_BOUNCE:
796 case MOVETYPE_BOUNCEMISSILE:
797 case MOVETYPE_FLYMISSILE:
798 if (GAMEPLAYFIX_UNSTICKPLAYERS(this) == 2)
799 _Movetype_CheckStuck(this);
800 _Movetype_Physics_Toss(this, movedt);
802 case MOVETYPE_PHYSICS:
806 //_Movetype_CheckVelocity(this);
808 _Movetype_LinkEdict(this, true);
810 //_Movetype_CheckVelocity(this);
813 void Movetype_Physics_NoMatchTicrate(entity this, float movedt, bool isclient) // to be run every move frame
815 bool didmove = (this.move_time != 0);
816 this.move_time = time;
819 _Movetype_Physics_ClientFrame(this, movedt);
822 // this doesn't apply to clients, and only applies to unmatched entities
823 // don't run think/move on newly spawned projectiles as it messes up
824 // movement interpolation and rocket trails, and is inconsistent with
825 // respect to entities spawned in the same frame
826 // (if an ent spawns a higher numbered ent, it moves in the same frame,
827 // but if it spawns a lower numbered ent, it doesn't - this never moves
828 // ents in the first frame regardless)
829 if(!didmove && GAMEPLAYFIX_DELAYPROJECTILES(this) > 0)
831 _Movetype_Physics_Frame(this, movedt);
836 setorigin(this, this.origin);
839 void Movetype_Physics_NoMatchServer(entity this) // optimized
841 float movedt = time - this.move_time;
842 this.move_time = time;
844 _Movetype_Physics_Frame(this, movedt);
848 setorigin(this, this.origin);
851 void Movetype_Physics_MatchServer(entity this, bool sloppy)
853 Movetype_Physics_MatchTicrate(this, TICRATE, sloppy);
858 .vector tic_velocity;
860 .vector tic_avelocity;
864 .vector tic_saved_origin;
865 .vector tic_saved_velocity;
866 .int tic_saved_flags;
867 .vector tic_saved_avelocity;
868 .vector tic_saved_angles;
869 void Movetype_Physics_MatchTicrate(entity this, float tr, bool sloppy) // SV_Physics_Entity
871 // this hack exists to contain the physics feature
872 // (so entities can place themselves in the world and not need to update .tic_* themselves)
874 if(this.(s) != this.tic_saved_##s) \
875 this.tic_##s = this.(s)
884 this.flags = this.tic_flags;
885 this.velocity = this.tic_velocity;
886 setorigin(this, this.tic_origin);
887 this.avelocity = this.tic_avelocity;
888 this.angles = this.tic_angles;
892 Movetype_Physics_NoMatchServer(this);
894 this.tic_saved_flags = this.tic_flags = this.flags;
895 this.tic_saved_velocity = this.tic_velocity = this.velocity;
896 this.tic_saved_origin = this.tic_origin = this.origin;
897 this.tic_saved_avelocity = this.tic_avelocity = this.avelocity;
898 this.tic_saved_angles = this.tic_angles = this.angles;
902 float dt = time - this.move_time;
904 int n = bound(0, floor(dt / tr), 32); // limit the number of frames to 32 (CL_MAX_USERCMDS, using DP_SMALLMEMORY value for consideration of QC's limitations)
906 this.move_time += n * tr;
908 if(!this.move_didgravity)
909 this.move_didgravity = ((this.move_movetype == MOVETYPE_BOUNCE || this.move_movetype == MOVETYPE_TOSS) && !(this.tic_flags & FL_ONGROUND));
911 for (int j = 0; j < n; ++j)
913 _Movetype_Physics_Frame(this, tr);
918 // update the physics fields
919 this.tic_origin = this.origin;
920 this.tic_velocity = this.velocity;
921 this.tic_avelocity = this.avelocity;
922 this.tic_angles = this.angles;
923 this.tic_flags = this.flags;
925 // restore their actual values
926 this.flags = this.tic_saved_flags;
927 this.velocity = this.tic_saved_velocity;
928 setorigin(this, this.tic_saved_origin);
929 //this.avelocity = this.tic_saved_avelocity;
930 this.angles = this.tic_saved_angles;
932 this.avelocity = this.tic_avelocity;
934 if(dt > 0 && this.move_movetype != MOVETYPE_NONE && !(this.tic_flags & FL_ONGROUND))
936 // now continue the move from move_time to time
937 this.velocity = this.tic_velocity;
939 if(this.move_didgravity > 0)
941 this.velocity_z -= (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE ? 0.5 : 1)
943 * ((this.gravity) ? this.gravity : 1)
944 * PHYS_GRAVITY(this);
947 this.angles = this.tic_angles + dt * this.avelocity;
949 if(sloppy || this.move_movetype == MOVETYPE_NOCLIP)
951 setorigin(this, this.tic_origin + dt * this.velocity);
955 setorigin(this, this.tic_origin);
956 _Movetype_PushEntityTrace(this, dt * this.velocity);
957 if(!trace_startsolid)
958 setorigin(this, trace_endpos);
960 setorigin(this, this.tic_saved_origin);
963 if(this.move_didgravity > 0 && GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
964 this.velocity_z -= 0.5 * dt * ((this.gravity) ? this.gravity : 1) * PHYS_GRAVITY(this);
968 this.velocity = this.tic_velocity;
969 this.angles = this.tic_angles;
970 setorigin(this, this.tic_origin);
973 this.flags = this.tic_flags;
975 this.tic_saved_flags = this.flags;
976 this.tic_saved_velocity = this.velocity;
977 this.tic_saved_origin = this.origin;
978 this.tic_saved_avelocity = this.avelocity;
979 this.tic_saved_angles = this.angles;