1 #include "movetypes.qh"
4 void set_movetype(entity this, int mt)
6 this.move_movetype = mt;
7 this.move_qcphysics = (mt != MOVETYPE_PHYSICS && !use_engine_physics);
8 if(!IL_CONTAINS(g_moveables, this))
9 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
10 this.movetype = (this.move_qcphysics) ? MOVETYPE_QCENTITY : mt;
13 void set_movetype(entity this, int mt)
15 this.move_movetype = mt;
19 bool _Movetype_NudgeOutOfSolid_PivotIsKnownGood(entity this, vector pivot) // SV_NudgeOutOfSolid_PivotIsKnownGood
21 vector stuckorigin = this.origin;
22 vector goodmins = pivot, goodmaxs = pivot;
23 for(int bump = 0; bump < 6; bump++)
25 int coord = 2 - (bump >> 1);
28 for(int subbump = 0; ; ++subbump)
30 vector testorigin = stuckorigin;
36 case 0: testorigin.x += this.maxs_x - goodmaxs.x; break;
37 case 1: testorigin.y += this.maxs_y - goodmaxs.y; break;
38 case 2: testorigin.z += this.maxs_z - goodmaxs.z; break;
46 case 0: testorigin.x += this.mins_x - goodmins.x; break;
47 case 1: testorigin.y += this.mins_y - goodmins.y; break;
48 case 2: testorigin.z += this.mins_z - goodmins.z; break;
52 tracebox(stuckorigin, goodmins, goodmaxs, testorigin, MOVE_NOMONSTERS, this);
53 if(trace_startsolid && trace_ent.solid == SOLID_BSP) // NOTE: this checks for bmodelstartsolid in the engine
55 // BAD BAD, can't fix that
59 if(trace_fraction >= 1)
64 // BAD BAD, can't fix that
68 // we hit something... let's move out of it
69 vector move = trace_endpos - testorigin;
70 float nudge = (trace_plane_normal * move) + 0.03125; // FIXME cvar this constant
71 stuckorigin = stuckorigin + nudge * trace_plane_normal;
79 case 0: goodmaxs.x = this.maxs_x; break;
80 case 1: goodmaxs.y = this.maxs_y; break;
81 case 2: goodmaxs.z = this.maxs_z; break;
89 case 0: goodmins.x = this.mins_x; break;
90 case 1: goodmins.y = this.mins_y; break;
91 case 2: goodmins.z = this.mins_z; break;
97 this.origin = stuckorigin;
102 void _Movetype_WallFriction(entity this, vector stepnormal) // SV_WallFriction
106 makevectors(this.v_angle);
107 d = (stepnormal * v_forward) + 0.5;
111 i = (stepnormal * this.velocity);
112 into = i * stepnormal;
113 side = this.velocity - into;
114 this.velocity_x = side.x * (1 * d);
115 this.velocity_y = side.y * (1 * d);
119 vector planes[MAX_CLIP_PLANES];
120 int _Movetype_FlyMove(entity this, float dt, bool applygravity, bool applystepnormal, float stepheight) // SV_FlyMove
122 move_stepnormal = '0 0 0';
129 float time_left = dt, grav = 0;
131 vector primal_velocity, original_velocity;
132 vector restore_velocity = this.velocity;
134 for(int j = 0; j < MAX_CLIP_PLANES; ++j)
139 this.move_didgravity = 1;
140 grav = dt * (this.gravity ? this.gravity : 1) * PHYS_GRAVITY(this);
142 if(!GAMEPLAYFIX_NOGRAVITYONGROUND || !IS_ONGROUND(this))
144 if(GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
145 this.velocity_z -= grav * 0.5;
147 this.velocity_z -= grav;
151 original_velocity = primal_velocity = this.velocity;
153 for(int bumpcount = 0;bumpcount < MAX_CLIP_PLANES;bumpcount++)
155 if(this.velocity == '0 0 0')
158 push = this.velocity * time_left;
159 if(!_Movetype_PushEntity(this, push, false))
161 // we got teleported by a touch function
162 // let's abort the move
167 // this code is used by MOVETYPE_WALK and MOVETYPE_STEP and SV_UnstickEntity
168 // abort move if we're stuck in the world (and didn't make it out)
169 if(trace_startsolid && trace_allsolid)
171 this.velocity = restore_velocity;
175 if(trace_fraction == 1)
178 time_left *= 1 - trace_fraction;
180 float my_trace_fraction = trace_fraction;
181 vector my_trace_plane_normal = trace_plane_normal;
183 if(trace_plane_normal.z)
185 if(trace_plane_normal.z > 0.7)
192 //dprint("_Movetype_FlyMove: !trace_ent\n");
197 this.groundentity = trace_ent;
202 // step - handle it immediately
203 vector org = this.origin;
204 vector steppush = vec3(0, 0, stepheight);
205 push = this.velocity * time_left;
207 if(!_Movetype_PushEntity(this, steppush, false))
212 if(!_Movetype_PushEntity(this, push, false))
217 float trace2_fraction = trace_fraction;
218 steppush = vec3(0, 0, org.z - this.origin_z);
219 if(!_Movetype_PushEntity(this, steppush, false))
225 // accept the new position if it made some progress...
226 // previously this checked if absolute distance >= 0.03125 which made stepping up unreliable
227 if(this.origin_x - org.x || this.origin_y - org.y)
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 // clipped to another plane
254 if(numplanes >= MAX_CLIP_PLANES)
256 // this shouldn't really happen
257 this.velocity = '0 0 0';
262 planes[numplanes] = my_trace_plane_normal;
265 // modify original_velocity so it parallels all of the clip planes
266 vector new_velocity = '0 0 0';
268 for (plane = 0;plane < numplanes;plane++)
271 new_velocity = _Movetype_ClipVelocity(original_velocity, planes[plane], 1);
272 for (newplane = 0;newplane < numplanes;newplane++)
274 if(newplane != plane)
277 if((new_velocity * planes[newplane]) < 0)
281 if(newplane == numplanes)
285 if(plane != numplanes)
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 dir = normalize(dir);
302 float d = (dir * this.velocity);
303 this.velocity = dir * d;
306 // if current velocity is against the original velocity,
307 // stop dead to avoid tiny occilations in sloping corners
308 if((this.velocity * primal_velocity) <= 0)
310 this.velocity = '0 0 0';
315 // LordHavoc: this came from QW and allows you to get out of water more easily
316 if(GAMEPLAYFIX_EASIERWATERJUMP(this) && (this.flags & FL_WATERJUMP) && !(blockedflag & 8))
317 this.velocity = primal_velocity;
319 if(PHYS_WALLCLIP(this) && this.pm_time && !(this.flags & FL_WATERJUMP) && !(blockedflag & 8))
320 this.velocity = primal_velocity;
324 if(!GAMEPLAYFIX_NOGRAVITYONGROUND || !IS_ONGROUND(this))
326 if(GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
327 this.velocity_z -= grav * 0.5f;
334 void _Movetype_CheckVelocity(entity this) // SV_CheckVelocity
336 // if(vlen(this.velocity) < 0.0001)
337 // this.velocity = '0 0 0';
340 bool _Movetype_CheckWater(entity this) // SV_CheckWater
342 vector point = this.origin;
343 point.z += this.mins.z + 1;
345 int nativecontents = pointcontents(point);
346 if(this.watertype && this.watertype != nativecontents)
348 // dprintf("_Movetype_CheckWater(): Original: '%d', New: '%d'\n", this.watertype, nativecontents);
349 if(this.contentstransition)
350 this.contentstransition(this.watertype, nativecontents);
353 this.waterlevel = WATERLEVEL_NONE;
354 this.watertype = CONTENT_EMPTY;
356 int supercontents = Mod_Q1BSP_SuperContentsFromNativeContents(nativecontents);
357 if(supercontents & DPCONTENTS_LIQUIDSMASK)
359 this.watertype = nativecontents;
360 this.waterlevel = WATERLEVEL_WETFEET;
361 point.z = this.origin.z + (this.mins.z + this.maxs.z) * 0.5;
362 if(Mod_Q1BSP_SuperContentsFromNativeContents(pointcontents(point)) & DPCONTENTS_LIQUIDSMASK)
364 this.waterlevel = WATERLEVEL_SWIMMING;
365 point.z = this.origin.z + this.view_ofs.z;
366 if(Mod_Q1BSP_SuperContentsFromNativeContents(pointcontents(point)) & DPCONTENTS_LIQUIDSMASK)
367 this.waterlevel = WATERLEVEL_SUBMERGED;
371 return this.waterlevel > 1;
374 void _Movetype_CheckWaterTransition(entity ent) // SV_CheckWaterTransition
376 int contents = pointcontents(ent.origin);
381 if(!GAMEPLAYFIX_WATERTRANSITION(ent))
383 ent.watertype = contents;
388 else if(ent.watertype != contents)
390 // dprintf("_Movetype_CheckWaterTransition(): Origin: %s, Direct: '%d', Original: '%d', New: '%d'\n", vtos(ent.origin), pointcontents(ent.origin), ent.watertype, contents);
391 if(ent.contentstransition)
392 ent.contentstransition(ent.watertype, contents);
395 if(contents <= CONTENT_WATER)
397 ent.watertype = contents;
402 ent.watertype = CONTENT_EMPTY;
403 ent.waterlevel = (GAMEPLAYFIX_WATERTRANSITION(ent) ? 0 : contents);
407 void _Movetype_Impact(entity this, entity toucher) // SV_Impact
409 // due to a lack of pointers in QC, we must save the trace values and restore them for other functions
410 bool save_trace_allsolid = trace_allsolid;
411 bool save_trace_startsolid = trace_startsolid;
412 float save_trace_fraction = trace_fraction;
413 bool save_trace_inwater = trace_inwater;
414 bool save_trace_inopen = trace_inopen;
415 vector save_trace_endpos = trace_endpos;
416 vector save_trace_plane_normal = trace_plane_normal;
417 float save_trace_plane_dist = trace_plane_dist;
418 entity save_trace_ent = trace_ent;
419 int save_trace_dpstartcontents = trace_dpstartcontents;
420 int save_trace_dphitcontents = trace_dphitcontents;
421 int save_trace_dphitq3surfaceflags = trace_dphitq3surfaceflags;
422 string save_trace_dphittexturename = trace_dphittexturename;
424 if(this.solid != SOLID_NOT && gettouch(this) && !wasfreed(this) && !wasfreed(toucher))
425 gettouch(this)(this, toucher);
427 if(toucher.solid != SOLID_NOT && gettouch(toucher) && !wasfreed(this) && !wasfreed(toucher))
429 trace_endpos = toucher.origin;
430 trace_plane_normal = -trace_plane_normal;
431 trace_plane_dist = -trace_plane_dist;
433 trace_dpstartcontents = 0;
434 trace_dphitcontents = 0;
435 trace_dphitq3surfaceflags = 0;
436 trace_dphittexturename = string_null;
437 gettouch(toucher)(toucher, 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 vector emin = this.absmin, emax = this.absmax;
476 // Xonotic and Nexuiz maps assume triggers will be activated by adjacent players
477 // prior to sv_legacy_bbox_expand 0 DP always did this for SVQC and never for CSQC
478 // we also need this for zero-size bboxes because radius == 0 returns nothing
479 // see also: WarpZoneLib_ExactTrigger_Touch()
483 FOREACH_ENTITY_RADIUS_ORDERED(0.5 * (this.absmin + this.absmax), 0.5 * vlen(emin - emax), true, {
484 if (it.solid == SOLID_TRIGGER && it != this)
485 if (it.move_nomonsters != MOVE_NOMONSTERS && it.move_nomonsters != MOVE_WORLDONLY)
486 if (gettouch(it) && boxesoverlap(it.absmin, it.absmax, emin, emax))
488 trace_allsolid = false;
489 trace_startsolid = false;
491 trace_inwater = false;
493 trace_endpos = it.origin;
494 trace_plane_normal = '0 0 1';
495 trace_plane_dist = 0;
497 trace_dpstartcontents = 0;
498 trace_dphitcontents = 0;
499 trace_dphitq3surfaceflags = 0;
500 trace_dphittexturename = string_null;
502 gettouch(it)(it, this);
506 trace_allsolid = save_trace_allsolid;
507 trace_startsolid = save_trace_startsolid;
508 trace_fraction = save_trace_fraction;
509 trace_inwater = save_trace_inwater;
510 trace_inopen = save_trace_inopen;
511 trace_endpos = save_trace_endpos;
512 trace_plane_normal = save_trace_plane_normal;
513 trace_plane_dist = save_trace_plane_dist;
514 trace_ent = save_trace_ent;
515 trace_dpstartcontents = save_trace_dpstartcontents;
516 trace_dphitcontents = save_trace_dphitcontents;
517 trace_dphitq3surfaceflags = save_trace_dphitq3surfaceflags;
518 trace_dphittexturename = save_trace_dphittexturename;
521 bool autocvar__movetype_debug = false;
522 void _Movetype_LinkEdict(entity this, bool touch_triggers) // SV_LinkEdict
524 if(autocvar__movetype_debug)
526 this.absmin = this.origin + this.mins;
527 this.absmax = this.origin + this.maxs;
530 setorigin(this, this.origin); // calls SV_LinkEdict
533 _Movetype_LinkEdict_TouchAreaGrid(this);
536 int _Movetype_ContentsMask(entity this) // SV_GenericHitSuperContentsMask
540 if(this.dphitcontentsmask)
541 return this.dphitcontentsmask;
542 else if(this.solid == SOLID_SLIDEBOX)
544 if(this.flags & FL_MONSTER)
545 return DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_MONSTERCLIP;
547 return DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP;
549 else if(this.solid == SOLID_CORPSE)
550 return DPCONTENTS_SOLID | DPCONTENTS_BODY;
551 else if(this.solid == SOLID_TRIGGER)
552 return DPCONTENTS_SOLID | DPCONTENTS_BODY;
554 return DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_CORPSE;
557 return DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_CORPSE;
560 entity _Movetype_TestEntityPosition_ent;
561 bool _Movetype_TestEntityPosition(vector ofs) // SV_TestEntityPosition
563 entity this = _Movetype_TestEntityPosition_ent;
564 vector org = this.origin + ofs;
566 //int cont = this.dphitcontentsmask;
567 //this.dphitcontentsmask = DPCONTENTS_SOLID;
568 tracebox(org, this.mins, this.maxs, this.origin, ((this.move_movetype == MOVETYPE_FLY_WORLDONLY) ? MOVE_WORLDONLY : MOVE_NOMONSTERS), this);
569 //this.dphitcontentsmask = cont;
570 if(trace_dpstartcontents & _Movetype_ContentsMask(this))
573 if(vlen2(trace_endpos - this.origin) >= 0.0001)
575 tracebox(trace_endpos, this.mins, this.maxs, trace_endpos, MOVE_NOMONSTERS, this);
576 if(!trace_startsolid)
577 this.origin = trace_endpos;
582 bool _Movetype_TestEntityPosition_Offset(int offset)
584 // NOTE: expects _Movetype_TestEntityPosition_ent to be set to the correct entity
585 // returns true if stuck
587 // start at 2, since the first position has already been checked
588 for(int j = 2; j <= offset; ++j)
590 if(!_Movetype_TestEntityPosition('0 0 -1' * j))
592 if(!_Movetype_TestEntityPosition('0 0 1' * j))
599 int _Movetype_UnstickEntity(entity this) // SV_UnstickEntity
601 _Movetype_TestEntityPosition_ent = this;
602 if (!_Movetype_TestEntityPosition(' 0 0 0')) {
605 #define X(v) if (_Movetype_TestEntityPosition(v))
606 X('0 0 -1') X(' 0 0 1')
607 X('-1 0 0') X(' 1 0 0')
608 X(' 0 -1 0') X(' 0 1 0')
609 X('-1 -1 0') X(' 1 -1 0')
610 X('-1 1 0') X(' 1 1 0')
613 if(_Movetype_TestEntityPosition_Offset(rint((this.maxs.z - this.mins.z) * 0.36)))
615 LOG_DEBUGF("Can't unstick an entity (edict: %d, classname: %s, origin: %s)",
616 etof(this), this.classname, vtos(this.origin));
617 return UNSTICK_STUCK;
620 LOG_DEBUGF("Sucessfully unstuck an entity (edict: %d, classname: %s, origin: %s)",
621 etof(this), this.classname, vtos(this.origin));
622 _Movetype_LinkEdict(this, false);
623 return UNSTICK_FIXED;
626 void _Movetype_CheckStuck(entity this) // SV_CheckStuck
628 int unstick = _Movetype_UnstickEntity(this); // sets test position entity
632 this.oldorigin = this.origin;
635 break; // already sorted
637 vector offset = this.oldorigin - this.origin;
638 if(!_Movetype_TestEntityPosition(offset))
639 _Movetype_LinkEdict(this, false);
640 // couldn't unstick, should we warn about this?
645 vector _Movetype_ClipVelocity(vector vel, vector norm, float f) // ClipVelocity
647 vel -= ((vel * norm) * norm) * f;
649 if(vel.x > -0.1 && vel.x < 0.1) vel.x = 0;
650 if(vel.y > -0.1 && vel.y < 0.1) vel.y = 0;
651 if(vel.z > -0.1 && vel.z < 0.1) vel.z = 0;
656 void _Movetype_PushEntityTrace(entity this, vector push)
658 vector end = this.origin + push;
660 if(this.move_nomonsters)
661 type = max(0, this.move_nomonsters);
662 else if(this.move_movetype == MOVETYPE_FLYMISSILE)
664 else if(this.move_movetype == MOVETYPE_FLY_WORLDONLY)
665 type = MOVE_WORLDONLY;
666 else if(this.solid == SOLID_TRIGGER || this.solid == SOLID_NOT)
667 type = MOVE_NOMONSTERS;
671 tracebox(this.origin, this.mins, this.maxs, end, type, this);
674 bool _Movetype_PushEntity(entity this, vector push, bool dolink) // SV_PushEntity
676 _Movetype_PushEntityTrace(this, push);
678 // NOTE: this is a workaround for the QC's lack of a worldstartsolid trace parameter
681 int oldtype = this.move_nomonsters;
682 this.move_nomonsters = MOVE_WORLDONLY;
683 _Movetype_PushEntityTrace(this, push);
684 this.move_nomonsters = oldtype;
689 this.origin = trace_endpos;
691 vector last_origin = this.origin;
693 _Movetype_LinkEdict(this, dolink);
695 if((this.solid >= SOLID_TRIGGER && trace_fraction < 1 && (!IS_ONGROUND(this) || this.groundentity != trace_ent)))
696 _Movetype_Impact(this, trace_ent);
698 return (this.origin == last_origin); // false if teleported by touch
701 void _Movetype_Physics_Frame(entity this, float movedt)
703 this.move_didgravity = -1;
704 switch (this.move_movetype)
707 case MOVETYPE_FAKEPUSH:
708 _Movetype_Physics_Push(this, movedt);
712 case MOVETYPE_FOLLOW:
713 _Movetype_Physics_Follow(this);
715 case MOVETYPE_NOCLIP:
716 _Movetype_CheckWater(this);
717 this.origin = this.origin + movedt * this.velocity;
718 this.angles = this.angles + movedt * this.avelocity;
719 _Movetype_LinkEdict(this, false);
722 _Movetype_Physics_Step(this, movedt);
725 _Movetype_Physics_Walk(this, movedt);
728 case MOVETYPE_BOUNCE:
729 case MOVETYPE_BOUNCEMISSILE:
730 case MOVETYPE_FLYMISSILE:
732 case MOVETYPE_FLY_WORLDONLY:
733 _Movetype_Physics_Toss(this, movedt);
735 case MOVETYPE_PHYSICS:
740 void _Movetype_Physics_ClientFrame(entity this, float movedt)
742 this.move_didgravity = -1;
743 switch (this.move_movetype)
746 case MOVETYPE_FAKEPUSH:
747 LOG_DEBUG("Physics: Lacking QuakeC support for Push movetype, FIX ME by using engine physics!");
751 case MOVETYPE_FOLLOW:
752 _Movetype_Physics_Follow(this);
754 case MOVETYPE_NOCLIP:
755 _Movetype_CheckWater(this);
756 this.origin = this.origin + movedt * this.velocity;
757 this.angles = this.angles + movedt * this.avelocity;
760 _Movetype_Physics_Step(this, movedt);
764 case MOVETYPE_FLY_WORLDONLY:
765 _Movetype_Physics_Walk(this, movedt);
768 case MOVETYPE_BOUNCE:
769 case MOVETYPE_BOUNCEMISSILE:
770 case MOVETYPE_FLYMISSILE:
771 if (GAMEPLAYFIX_UNSTICKPLAYERS(this) == 2)
772 _Movetype_CheckStuck(this);
773 _Movetype_Physics_Toss(this, movedt);
775 case MOVETYPE_PHYSICS:
779 //_Movetype_CheckVelocity(this);
781 _Movetype_LinkEdict(this, true);
783 //_Movetype_CheckVelocity(this);
786 void Movetype_Physics_NoMatchTicrate(entity this, float movedt, bool isclient) // to be run every move frame
788 bool didmove = (this.move_time != 0);
789 this.move_time = time;
792 _Movetype_Physics_ClientFrame(this, movedt);
795 // this doesn't apply to clients, and only applies to unmatched entities
796 // don't run think/move on newly spawned projectiles as it messes up
797 // movement interpolation and rocket trails, and is inconsistent with
798 // respect to entities spawned in the same frame
799 // (if an ent spawns a higher numbered ent, it moves in the same frame,
800 // but if it spawns a lower numbered ent, it doesn't - this never moves
801 // ents in the first frame regardless)
802 if(!didmove && GAMEPLAYFIX_DELAYPROJECTILES(this) > 0)
804 _Movetype_Physics_Frame(this, movedt);
809 setorigin(this, this.origin);
812 void Movetype_Physics_NoMatchServer(entity this) // optimized
814 float movedt = time - this.move_time;
815 this.move_time = time;
817 _Movetype_Physics_Frame(this, movedt);
821 setorigin(this, this.origin);
824 void Movetype_Physics_MatchServer(entity this, bool sloppy)
826 Movetype_Physics_MatchTicrate(this, TICRATE, sloppy);
831 .vector tic_velocity;
833 .vector tic_avelocity;
837 .vector tic_saved_origin;
838 .vector tic_saved_velocity;
839 .int tic_saved_flags;
840 .vector tic_saved_avelocity;
841 .vector tic_saved_angles;
842 void Movetype_Physics_MatchTicrate(entity this, float tr, bool sloppy) // SV_Physics_Entity
844 // this hack exists to contain the physics feature
845 // (so entities can place themselves in the world and not need to update .tic_* themselves)
847 if(this.(s) != this.tic_saved_##s) \
848 this.tic_##s = this.(s)
857 this.flags = this.tic_flags;
858 this.velocity = this.tic_velocity;
859 setorigin(this, this.tic_origin);
860 this.avelocity = this.tic_avelocity;
861 this.angles = this.tic_angles;
865 Movetype_Physics_NoMatchServer(this);
867 this.tic_saved_flags = this.tic_flags = this.flags;
868 this.tic_saved_velocity = this.tic_velocity = this.velocity;
869 this.tic_saved_origin = this.tic_origin = this.origin;
870 this.tic_saved_avelocity = this.tic_avelocity = this.avelocity;
871 this.tic_saved_angles = this.tic_angles = this.angles;
875 float dt = time - this.move_time;
877 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)
879 this.move_time += n * tr;
881 if(!this.move_didgravity)
882 this.move_didgravity = ((this.move_movetype == MOVETYPE_BOUNCE || this.move_movetype == MOVETYPE_TOSS) && !(this.tic_flags & FL_ONGROUND));
884 for (int j = 0; j < n; ++j)
886 _Movetype_Physics_Frame(this, tr);
891 // update the physics fields
892 this.tic_origin = this.origin;
893 this.tic_velocity = this.velocity;
894 this.tic_avelocity = this.avelocity;
895 this.tic_angles = this.angles;
896 this.tic_flags = this.flags;
898 // restore their actual values
899 this.flags = this.tic_saved_flags;
900 this.velocity = this.tic_saved_velocity;
901 setorigin(this, this.tic_saved_origin);
902 //this.avelocity = this.tic_saved_avelocity;
903 this.angles = this.tic_saved_angles;
905 this.avelocity = this.tic_avelocity;
907 if(dt > 0 && this.move_movetype != MOVETYPE_NONE && !(this.tic_flags & FL_ONGROUND))
909 // now continue the move from move_time to time
910 this.velocity = this.tic_velocity;
912 if(this.move_didgravity > 0)
914 this.velocity_z -= (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE ? 0.5 : 1)
916 * ((this.gravity) ? this.gravity : 1)
917 * PHYS_GRAVITY(this);
920 this.angles = this.tic_angles + dt * this.avelocity;
922 if(sloppy || this.move_movetype == MOVETYPE_NOCLIP)
924 setorigin(this, this.tic_origin + dt * this.velocity);
928 setorigin(this, this.tic_origin);
929 _Movetype_PushEntityTrace(this, dt * this.velocity);
930 if(!trace_startsolid)
931 setorigin(this, trace_endpos);
933 setorigin(this, this.tic_saved_origin);
936 if(this.move_didgravity > 0 && GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
937 this.velocity_z -= 0.5 * dt * ((this.gravity) ? this.gravity : 1) * PHYS_GRAVITY(this);
941 this.velocity = this.tic_velocity;
942 this.angles = this.tic_angles;
943 setorigin(this, this.tic_origin);
946 this.flags = this.tic_flags;
948 this.tic_saved_flags = this.flags;
949 this.tic_saved_velocity = this.velocity;
950 this.tic_saved_origin = this.origin;
951 this.tic_saved_avelocity = this.avelocity;
952 this.tic_saved_angles = this.angles;