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 time_left *= 1 - trace_fraction;
184 float my_trace_fraction = trace_fraction;
185 vector my_trace_plane_normal = trace_plane_normal;
187 if(trace_plane_normal.z)
189 if(trace_plane_normal.z > 0.7)
196 //dprint("_Movetype_FlyMove: !trace_ent\n");
201 this.groundentity = trace_ent;
206 // step - handle it immediately
207 vector org = this.origin;
208 vector steppush = '0 0 1' * stepheight;
209 push = this.velocity * time_left;
211 if(!_Movetype_PushEntity(this, steppush, true, false))
216 if(!_Movetype_PushEntity(this, push, true, false))
221 float trace2_fraction = trace_fraction;
222 steppush = vec3(0, 0, org.z - this.origin_z);
223 if(!_Movetype_PushEntity(this, steppush, true, false))
229 // accept the new position if it made some progress...
230 // previously this checked if absolute distance >= 0.03125 which made stepping up unreliable
231 if(this.origin_x - org.x || this.origin_y - org.y)
233 trace_endpos = this.origin;
234 time_left *= 1 - trace2_fraction;
243 // step - return it to caller
245 // save the trace for player extrafriction
247 move_stepnormal = trace_plane_normal;
250 if(my_trace_fraction >= 0.001)
252 // actually covered some distance
253 original_velocity = this.velocity;
257 // clipped to another plane
258 if(numplanes >= MAX_CLIP_PLANES)
260 // this shouldn't really happen
261 this.velocity = '0 0 0';
266 planes[numplanes] = my_trace_plane_normal;
269 // modify original_velocity so it parallels all of the clip planes
270 vector new_velocity = '0 0 0';
271 for (i = 0;i < numplanes;i++)
273 new_velocity = _Movetype_ClipVelocity(original_velocity, planes[i], 1);
274 for (j = 0;j < numplanes;j++)
279 if((new_velocity * planes[j]) < 0)
289 // go along this plane
290 this.velocity = new_velocity;
294 // go along the crease
297 this.velocity = '0 0 0';
301 vector dir = cross(planes[0], planes[1]);
302 // LordHavoc: thanks to taniwha of QuakeForge for pointing out this fix for slowed falling in corners
303 float ilength = sqrt((dir * dir));
305 ilength = 1.0 / ilength;
309 float d = (dir * this.velocity);
310 this.velocity = dir * d;
313 // if current velocity is against the original velocity,
314 // stop dead to avoid tiny occilations in sloping corners
315 if((this.velocity * primal_velocity) <= 0)
317 this.velocity = '0 0 0';
322 // LordHavoc: this came from QW and allows you to get out of water more easily
323 if(GAMEPLAYFIX_EASIERWATERJUMP(this) && (this.flags & FL_WATERJUMP) && !(blockedflag & 8))
324 this.velocity = primal_velocity;
326 if(PHYS_WALLCLIP(this) && this.pm_time && !(this.flags & FL_WATERJUMP) && !(blockedflag & 8))
327 this.velocity = primal_velocity;
331 if(!GAMEPLAYFIX_NOGRAVITYONGROUND || !IS_ONGROUND(this))
333 if(GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
334 this.velocity_z -= grav * 0.5f;
341 void _Movetype_CheckVelocity(entity this) // SV_CheckVelocity
343 // if(vlen(this.velocity) < 0.0001)
344 // this.velocity = '0 0 0';
347 bool _Movetype_CheckWater(entity this) // SV_CheckWater
349 vector point = this.origin;
350 point.z += this.mins.z + 1;
352 int nativecontents = pointcontents(point);
353 if(this.watertype && this.watertype != nativecontents)
355 // dprintf("_Movetype_CheckWater(): Original: '%d', New: '%d'\n", this.watertype, nativecontents);
356 if(this.contentstransition)
357 this.contentstransition(this.watertype, nativecontents);
360 this.waterlevel = WATERLEVEL_NONE;
361 this.watertype = CONTENT_EMPTY;
363 int supercontents = Mod_Q1BSP_SuperContentsFromNativeContents(nativecontents);
364 if(supercontents & DPCONTENTS_LIQUIDSMASK)
366 this.watertype = nativecontents;
367 this.waterlevel = WATERLEVEL_WETFEET;
368 point.z = this.origin.z + (this.mins.z + this.maxs.z) * 0.5;
369 if(Mod_Q1BSP_SuperContentsFromNativeContents(pointcontents(point)) & DPCONTENTS_LIQUIDSMASK)
371 this.waterlevel = WATERLEVEL_SWIMMING;
372 point.z = this.origin.z + this.view_ofs.z;
373 if(Mod_Q1BSP_SuperContentsFromNativeContents(pointcontents(point)) & DPCONTENTS_LIQUIDSMASK)
374 this.waterlevel = WATERLEVEL_SUBMERGED;
378 return this.waterlevel > 1;
381 void _Movetype_CheckWaterTransition(entity ent) // SV_CheckWaterTransition
383 int contents = pointcontents(ent.origin);
388 if(!GAMEPLAYFIX_WATERTRANSITION(ent))
390 ent.watertype = contents;
395 else if(ent.watertype != contents)
397 // dprintf("_Movetype_CheckWaterTransition(): Origin: %s, Direct: '%d', Original: '%d', New: '%d'\n", vtos(ent.origin), pointcontents(ent.origin), ent.watertype, contents);
398 if(ent.contentstransition)
399 ent.contentstransition(ent.watertype, contents);
402 if(contents <= CONTENT_WATER)
404 ent.watertype = contents;
409 ent.watertype = CONTENT_EMPTY;
410 ent.waterlevel = (GAMEPLAYFIX_WATERTRANSITION(ent) ? 0 : contents);
414 void _Movetype_Impact(entity this, entity oth) // SV_Impact
419 // due to a lack of pointers in QC, we must save the trace values and restore them for other functions
420 bool save_trace_allsolid = trace_allsolid;
421 bool save_trace_startsolid = trace_startsolid;
422 float save_trace_fraction = trace_fraction;
423 bool save_trace_inwater = trace_inwater;
424 bool save_trace_inopen = trace_inopen;
425 vector save_trace_endpos = trace_endpos;
426 vector save_trace_plane_normal = trace_plane_normal;
427 float save_trace_plane_dist = trace_plane_dist;
428 entity save_trace_ent = trace_ent;
429 int save_trace_dpstartcontents = trace_dpstartcontents;
430 int save_trace_dphitcontents = trace_dphitcontents;
431 int save_trace_dphitq3surfaceflags = trace_dphitq3surfaceflags;
432 string save_trace_dphittexturename = trace_dphittexturename;
434 if(this.solid != SOLID_NOT && gettouch(this))
435 gettouch(this)(this, oth);
437 if(oth.solid != SOLID_NOT && gettouch(oth))
438 gettouch(oth)(oth, this);
440 trace_allsolid = save_trace_allsolid;
441 trace_startsolid = save_trace_startsolid;
442 trace_fraction = save_trace_fraction;
443 trace_inwater = save_trace_inwater;
444 trace_inopen = save_trace_inopen;
445 trace_endpos = save_trace_endpos;
446 trace_plane_normal = save_trace_plane_normal;
447 trace_plane_dist = save_trace_plane_dist;
448 trace_ent = save_trace_ent;
449 trace_dpstartcontents = save_trace_dpstartcontents;
450 trace_dphitcontents = save_trace_dphitcontents;
451 trace_dphitq3surfaceflags = save_trace_dphitq3surfaceflags;
452 trace_dphittexturename = save_trace_dphittexturename;
455 void _Movetype_LinkEdict_TouchAreaGrid(entity this) // SV_LinkEdict_TouchAreaGrid
457 if(this.solid == SOLID_NOT)
460 // due to a lack of pointers in QC, we must save the trace values and restore them for other functions
461 bool save_trace_allsolid = trace_allsolid;
462 bool save_trace_startsolid = trace_startsolid;
463 float save_trace_fraction = trace_fraction;
464 bool save_trace_inwater = trace_inwater;
465 bool save_trace_inopen = trace_inopen;
466 vector save_trace_endpos = trace_endpos;
467 vector save_trace_plane_normal = trace_plane_normal;
468 float save_trace_plane_dist = trace_plane_dist;
469 entity save_trace_ent = trace_ent;
470 int save_trace_dpstartcontents = trace_dpstartcontents;
471 int save_trace_dphitcontents = trace_dphitcontents;
472 int save_trace_dphitq3surfaceflags = trace_dphitq3surfaceflags;
473 string save_trace_dphittexturename = trace_dphittexturename;
475 FOREACH_ENTITY_RADIUS_ORDERED(0.5 * (this.absmin + this.absmax), 0.5 * vlen(this.absmax - this.absmin), true, {
476 if (it.solid == SOLID_TRIGGER && it != this)
477 if (it.move_nomonsters != MOVE_NOMONSTERS && it.move_nomonsters != MOVE_WORLDONLY)
478 if (gettouch(it) && boxesoverlap(it.absmin, it.absmax, this.absmin, this.absmax))
480 trace_allsolid = false;
481 trace_startsolid = false;
483 trace_inwater = false;
485 trace_endpos = it.origin;
486 trace_plane_normal = '0 0 1';
487 trace_plane_dist = 0;
489 trace_dpstartcontents = 0;
490 trace_dphitcontents = 0;
491 trace_dphitq3surfaceflags = 0;
492 trace_dphittexturename = string_null;
494 gettouch(it)(it, this);
498 trace_allsolid = save_trace_allsolid;
499 trace_startsolid = save_trace_startsolid;
500 trace_fraction = save_trace_fraction;
501 trace_inwater = save_trace_inwater;
502 trace_inopen = save_trace_inopen;
503 trace_endpos = save_trace_endpos;
504 trace_plane_normal = save_trace_plane_normal;
505 trace_plane_dist = save_trace_plane_dist;
506 trace_ent = save_trace_ent;
507 trace_dpstartcontents = save_trace_dpstartcontents;
508 trace_dphitcontents = save_trace_dphitcontents;
509 trace_dphitq3surfaceflags = save_trace_dphitq3surfaceflags;
510 trace_dphittexturename = save_trace_dphittexturename;
513 bool autocvar__movetype_debug = false;
514 void _Movetype_LinkEdict(entity this, bool touch_triggers) // SV_LinkEdict
516 if(autocvar__movetype_debug)
519 if(this.solid == SOLID_BSP)
521 // TODO set the absolute bbox
533 if(this.flags & FL_ITEM)
549 setorigin(this, this.origin); // calls SV_LinkEdict
551 // NOTE: CSQC's version of setorigin doesn't expand
552 this.absmin -= '1 1 1';
553 this.absmax += '1 1 1';
558 _Movetype_LinkEdict_TouchAreaGrid(this);
561 int _Movetype_ContentsMask(entity this) // SV_GenericHitSuperContentsMask
565 if(this.dphitcontentsmask)
566 return this.dphitcontentsmask;
567 else if(this.solid == SOLID_SLIDEBOX)
569 if(this.flags & FL_MONSTER)
570 return DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_MONSTERCLIP;
572 return DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP;
574 else if(this.solid == SOLID_CORPSE)
575 return DPCONTENTS_SOLID | DPCONTENTS_BODY;
576 else if(this.solid == SOLID_TRIGGER)
577 return DPCONTENTS_SOLID | DPCONTENTS_BODY;
579 return DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_CORPSE;
582 return DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_CORPSE;
585 entity _Movetype_TestEntityPosition_ent;
586 bool _Movetype_TestEntityPosition(vector ofs) // SV_TestEntityPosition
588 entity this = _Movetype_TestEntityPosition_ent;
589 vector org = this.origin + ofs;
591 //int cont = this.dphitcontentsmask;
592 //this.dphitcontentsmask = DPCONTENTS_SOLID;
593 tracebox(org, this.mins, this.maxs, this.origin, ((this.move_movetype == MOVETYPE_FLY_WORLDONLY) ? MOVE_WORLDONLY : MOVE_NOMONSTERS), this);
594 //this.dphitcontentsmask = cont;
595 if(trace_dpstartcontents & _Movetype_ContentsMask(this))
598 if(vlen2(trace_endpos - this.origin) >= 0.0001)
600 tracebox(trace_endpos, this.mins, this.maxs, trace_endpos, MOVE_NOMONSTERS, this);
601 if(!trace_startsolid)
602 this.origin = trace_endpos;
607 bool _Movetype_TestEntityPosition_Offset(int offset)
609 // NOTE: expects _Movetype_TestEntityPosition_ent to be set to the correct entity
610 // returns true if stuck
612 // start at 2, since the first position has already been checked
613 for(int j = 2; j <= offset; ++j)
615 if(!_Movetype_TestEntityPosition('0 0 -1' * j))
617 if(!_Movetype_TestEntityPosition('0 0 1' * j))
624 int _Movetype_UnstickEntity(entity this) // SV_UnstickEntity
626 _Movetype_TestEntityPosition_ent = this;
627 if (!_Movetype_TestEntityPosition(' 0 0 0')) {
630 #define X(v) if (_Movetype_TestEntityPosition(v))
631 X('0 0 -1') X(' 0 0 1')
632 X('-1 0 0') X(' 1 0 0')
633 X(' 0 -1 0') X(' 0 1 0')
634 X('-1 -1 0') X(' 1 -1 0')
635 X('-1 1 0') X(' 1 1 0')
638 if(_Movetype_TestEntityPosition_Offset(rint((this.maxs.z - this.mins.z) * 0.36)))
640 LOG_DEBUGF("Can't unstick an entity (edict: %d, classname: %s, origin: %s)",
641 etof(this), this.classname, vtos(this.origin));
642 return UNSTICK_STUCK;
645 LOG_DEBUGF("Sucessfully unstuck an entity (edict: %d, classname: %s, origin: %s)",
646 etof(this), this.classname, vtos(this.origin));
647 _Movetype_LinkEdict(this, false);
648 return UNSTICK_FIXED;
651 void _Movetype_CheckStuck(entity this) // SV_CheckStuck
653 int unstick = _Movetype_UnstickEntity(this); // sets test position entity
657 this.oldorigin = this.origin;
660 break; // already sorted
662 vector offset = this.oldorigin - this.origin;
663 if(!_Movetype_TestEntityPosition(offset))
664 _Movetype_LinkEdict(this, false);
665 // couldn't unstick, should we warn about this?
670 vector _Movetype_ClipVelocity(vector vel, vector norm, float f) // ClipVelocity
672 vel -= ((vel * norm) * norm) * f;
674 if(vel.x > -0.1 && vel.x < 0.1) vel.x = 0;
675 if(vel.y > -0.1 && vel.y < 0.1) vel.y = 0;
676 if(vel.z > -0.1 && vel.z < 0.1) vel.z = 0;
681 void _Movetype_PushEntityTrace(entity this, vector push)
683 vector end = this.origin + push;
685 if(this.move_nomonsters)
686 type = max(0, this.move_nomonsters);
687 else if(this.move_movetype == MOVETYPE_FLYMISSILE)
689 else if(this.move_movetype == MOVETYPE_FLY_WORLDONLY)
690 type = MOVE_WORLDONLY;
691 else if(this.solid == SOLID_TRIGGER || this.solid == SOLID_NOT)
692 type = MOVE_NOMONSTERS;
696 tracebox(this.origin, this.mins, this.maxs, end, type, this);
699 bool _Movetype_PushEntity(entity this, vector push, bool failonstartsolid, bool dolink) // SV_PushEntity
701 _Movetype_PushEntityTrace(this, push);
703 // NOTE: this is a workaround for the QC's lack of a worldstartsolid trace parameter
704 if(trace_startsolid && failonstartsolid)
706 int oldtype = this.move_nomonsters;
707 this.move_nomonsters = MOVE_WORLDONLY;
708 _Movetype_PushEntityTrace(this, push);
709 this.move_nomonsters = oldtype;
714 this.origin = trace_endpos;
716 vector last_origin = this.origin;
718 _Movetype_LinkEdict(this, dolink);
720 if((this.solid >= SOLID_TRIGGER && trace_fraction < 1 && (!IS_ONGROUND(this) || this.groundentity != trace_ent)))
721 _Movetype_Impact(this, trace_ent);
723 return (this.origin == last_origin); // false if teleported by touch
726 void _Movetype_Physics_Frame(entity this, float movedt)
728 this.move_didgravity = -1;
729 switch (this.move_movetype)
732 case MOVETYPE_FAKEPUSH:
733 _Movetype_Physics_Push(this, movedt);
737 case MOVETYPE_FOLLOW:
738 _Movetype_Physics_Follow(this);
740 case MOVETYPE_NOCLIP:
741 _Movetype_CheckWater(this);
742 this.origin = this.origin + movedt * this.velocity;
743 this.angles = this.angles + movedt * this.avelocity;
744 _Movetype_LinkEdict(this, false);
747 _Movetype_Physics_Step(this, movedt);
750 _Movetype_Physics_Walk(this, movedt);
753 case MOVETYPE_BOUNCE:
754 case MOVETYPE_BOUNCEMISSILE:
755 case MOVETYPE_FLYMISSILE:
757 case MOVETYPE_FLY_WORLDONLY:
758 _Movetype_Physics_Toss(this, movedt);
760 case MOVETYPE_PHYSICS:
765 void _Movetype_Physics_ClientFrame(entity this, float movedt)
767 this.move_didgravity = -1;
768 switch (this.move_movetype)
771 case MOVETYPE_FAKEPUSH:
772 LOG_DEBUG("Physics: Lacking QuakeC support for Push movetype, FIX ME by using engine physics!");
776 case MOVETYPE_FOLLOW:
777 _Movetype_Physics_Follow(this);
779 case MOVETYPE_NOCLIP:
780 _Movetype_CheckWater(this);
781 this.origin = this.origin + movedt * this.velocity;
782 this.angles = this.angles + movedt * this.avelocity;
785 if (GAMEPLAYFIX_UNSTICKPLAYERS(this) == 2)
786 _Movetype_CheckStuck(this);
787 _Movetype_Physics_Step(this, movedt);
791 case MOVETYPE_FLY_WORLDONLY:
792 if (movedt > 0 && GAMEPLAYFIX_UNSTICKPLAYERS(this) == 2)
793 _Movetype_CheckStuck(this);
794 _Movetype_Physics_Walk(this, movedt);
797 case MOVETYPE_BOUNCE:
798 case MOVETYPE_BOUNCEMISSILE:
799 case MOVETYPE_FLYMISSILE:
800 if (GAMEPLAYFIX_UNSTICKPLAYERS(this) == 2)
801 _Movetype_CheckStuck(this);
802 _Movetype_Physics_Toss(this, movedt);
804 case MOVETYPE_PHYSICS:
808 //_Movetype_CheckVelocity(this);
810 _Movetype_LinkEdict(this, true);
812 //_Movetype_CheckVelocity(this);
815 void Movetype_Physics_NoMatchTicrate(entity this, float movedt, bool isclient) // to be run every move frame
817 bool didmove = (this.move_time != 0);
818 this.move_time = time;
821 _Movetype_Physics_ClientFrame(this, movedt);
824 // this doesn't apply to clients, and only applies to unmatched entities
825 // don't run think/move on newly spawned projectiles as it messes up
826 // movement interpolation and rocket trails, and is inconsistent with
827 // respect to entities spawned in the same frame
828 // (if an ent spawns a higher numbered ent, it moves in the same frame,
829 // but if it spawns a lower numbered ent, it doesn't - this never moves
830 // ents in the first frame regardless)
831 if(!didmove && GAMEPLAYFIX_DELAYPROJECTILES(this) > 0)
833 _Movetype_Physics_Frame(this, movedt);
838 setorigin(this, this.origin);
841 void Movetype_Physics_NoMatchServer(entity this) // optimized
843 float movedt = time - this.move_time;
844 this.move_time = time;
846 _Movetype_Physics_Frame(this, movedt);
850 setorigin(this, this.origin);
853 void Movetype_Physics_MatchServer(entity this, bool sloppy)
855 Movetype_Physics_MatchTicrate(this, TICRATE, sloppy);
860 .vector tic_velocity;
862 .vector tic_avelocity;
866 .vector tic_saved_origin;
867 .vector tic_saved_velocity;
868 .int tic_saved_flags;
869 .vector tic_saved_avelocity;
870 .vector tic_saved_angles;
871 void Movetype_Physics_MatchTicrate(entity this, float tr, bool sloppy) // SV_Physics_Entity
873 // this hack exists to contain the physics feature
874 // (so entities can place themselves in the world and not need to update .tic_* themselves)
876 if(this.(s) != this.tic_saved_##s) \
877 this.tic_##s = this.(s)
886 this.flags = this.tic_flags;
887 this.velocity = this.tic_velocity;
888 setorigin(this, this.tic_origin);
889 this.avelocity = this.tic_avelocity;
890 this.angles = this.tic_angles;
894 Movetype_Physics_NoMatchServer(this);
896 this.tic_saved_flags = this.tic_flags = this.flags;
897 this.tic_saved_velocity = this.tic_velocity = this.velocity;
898 this.tic_saved_origin = this.tic_origin = this.origin;
899 this.tic_saved_avelocity = this.tic_avelocity = this.avelocity;
900 this.tic_saved_angles = this.tic_angles = this.angles;
904 float dt = time - this.move_time;
906 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)
908 this.move_time += n * tr;
910 if(!this.move_didgravity)
911 this.move_didgravity = ((this.move_movetype == MOVETYPE_BOUNCE || this.move_movetype == MOVETYPE_TOSS) && !(this.tic_flags & FL_ONGROUND));
913 for (int j = 0; j < n; ++j)
915 _Movetype_Physics_Frame(this, tr);
920 // update the physics fields
921 this.tic_origin = this.origin;
922 this.tic_velocity = this.velocity;
923 this.tic_avelocity = this.avelocity;
924 this.tic_angles = this.angles;
925 this.tic_flags = this.flags;
927 // restore their actual values
928 this.flags = this.tic_saved_flags;
929 this.velocity = this.tic_saved_velocity;
930 setorigin(this, this.tic_saved_origin);
931 //this.avelocity = this.tic_saved_avelocity;
932 this.angles = this.tic_saved_angles;
934 this.avelocity = this.tic_avelocity;
936 if(dt > 0 && this.move_movetype != MOVETYPE_NONE && !(this.tic_flags & FL_ONGROUND))
938 // now continue the move from move_time to time
939 this.velocity = this.tic_velocity;
941 if(this.move_didgravity > 0)
943 this.velocity_z -= (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE ? 0.5 : 1)
945 * ((this.gravity) ? this.gravity : 1)
946 * PHYS_GRAVITY(this);
949 this.angles = this.tic_angles + dt * this.avelocity;
951 if(sloppy || this.move_movetype == MOVETYPE_NOCLIP)
953 setorigin(this, this.tic_origin + dt * this.velocity);
957 setorigin(this, this.tic_origin);
958 _Movetype_PushEntityTrace(this, dt * this.velocity);
959 if(!trace_startsolid)
960 setorigin(this, trace_endpos);
962 setorigin(this, this.tic_saved_origin);
965 if(this.move_didgravity > 0 && GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
966 this.velocity_z -= 0.5 * dt * ((this.gravity) ? this.gravity : 1) * PHYS_GRAVITY(this);
970 this.velocity = this.tic_velocity;
971 this.angles = this.tic_angles;
972 setorigin(this, this.tic_origin);
975 this.flags = this.tic_flags;
977 this.tic_saved_flags = this.flags;
978 this.tic_saved_velocity = this.velocity;
979 this.tic_saved_origin = this.origin;
980 this.tic_saved_avelocity = this.avelocity;
981 this.tic_saved_angles = this.angles;