56 trace =
gi.trace(ent->s.origin, ent->mins, ent->maxs, ent->s.origin, ent, mask);
77 for (i = 0 ; i < 3 ; i++) {
96 thinktime = ent->nextthink;
104 gi.error(
"NULL ent->think");
124 if (e1->touch && e1->solid != SOLID_NOT)
125 e1->touch(e1, e2, &trace->plane, trace->surface);
127 if (e2->touch && e2->solid != SOLID_NOT)
128 e2->touch(e2, e1, NULL, NULL);
140 #define STOP_EPSILON 0.1
142 int ClipVelocity(vec3_t in, vec3_t normal, vec3_t out,
float overbounce)
154 backoff = DotProduct(in, normal) * overbounce;
156 for (i = 0 ; i < 3 ; i++) {
157 change = normal[i] * backoff;
158 out[i] = in[i] - change;
178 #define MAX_CLIP_PLANES 5
182 int bumpcount, numbumps;
187 vec3_t primal_velocity, original_velocity, new_velocity;
197 VectorCopy(ent->velocity, original_velocity);
198 VectorCopy(ent->velocity, primal_velocity);
203 ent->groundentity = NULL;
204 for (bumpcount = 0 ; bumpcount < numbumps ; bumpcount++) {
205 for (i = 0 ; i < 3 ; i++)
206 end[i] = ent->s.origin[i] + time_left * ent->velocity[i];
208 trace =
gi.trace(ent->s.origin, ent->mins, ent->maxs, end, ent, mask);
210 if (trace.allsolid) {
216 if (trace.fraction > 0) {
218 VectorCopy(trace.endpos, ent->s.origin);
219 VectorCopy(ent->velocity, original_velocity);
223 if (trace.fraction == 1)
228 if (trace.plane.normal[2] > 0.7) {
230 if (hit->solid == SOLID_BSP) {
231 ent->groundentity = hit;
232 ent->groundentity_linkcount = hit->linkcount;
235 if (!trace.plane.normal[2]) {
247 time_left -= time_left * trace.fraction;
256 VectorCopy(trace.plane.normal, planes[numplanes]);
262 for (i = 0 ; i < numplanes ; i++) {
263 ClipVelocity(original_velocity, planes[i], new_velocity, 1);
265 for (j = 0 ; j < numplanes ; j++)
266 if ((j != i) && !VectorCompare(planes[i], planes[j])) {
267 if (DotProduct(new_velocity, planes[j]) < 0)
274 if (i != numplanes) {
276 VectorCopy(new_velocity, ent->velocity);
279 if (numplanes != 2) {
284 CrossProduct(planes[0], planes[1], dir);
285 d = DotProduct(dir, ent->velocity);
286 VectorScale(dir, d, ent->velocity);
293 if (DotProduct(ent->velocity, primal_velocity) <= 0) {
336 VectorCopy(ent->s.origin, start);
337 VectorAdd(start,
push, end);
341 mask = ent->clipmask;
345 trace =
gi.trace(start, ent->mins, ent->maxs, end, ent, mask);
347 VectorCopy(trace.endpos, ent->s.origin);
350 if (trace.fraction != 1.0) {
354 if (!trace.ent->inuse && ent->inuse) {
356 VectorCopy(start, ent->s.origin);
373 #if USE_SMOOTH_DELTA_ANGLES
389 qboolean
SV_Push(edict_t *pusher, vec3_t move, vec3_t amove)
392 edict_t *check, *block;
399 for (i = 0 ; i < 3 ; i++) {
401 temp = move[i] * 8.0;
406 move[i] = 0.125 * (
int)temp;
410 for (i = 0 ; i < 3 ; i++) {
411 mins[i] = pusher->absmin[i] + move[i];
412 maxs[i] = pusher->absmax[i] + move[i];
423 #if USE_SMOOTH_DELTA_ANGLES
425 pushed_p->deltayaw = pusher->client->ps.pmove.delta_angles[YAW];
430 VectorAdd(pusher->s.origin, move, pusher->s.origin);
431 VectorAdd(pusher->s.angles, amove, pusher->s.angles);
432 gi.linkentity(pusher);
436 for (e = 1; e <
globals.num_edicts; e++, check++) {
445 if (!check->area.prev)
449 if (check->groundentity != pusher) {
451 if (check->absmin[0] >= maxs[0]
452 || check->absmin[1] >= maxs[1]
453 || check->absmin[2] >= maxs[2]
454 || check->absmax[0] <= mins[0]
455 || check->absmax[1] <= mins[1]
456 || check->absmax[2] <= mins[2])
464 if ((pusher->movetype ==
MOVETYPE_PUSH) || (check->groundentity == pusher)) {
469 #if USE_SMOOTH_DELTA_ANGLES
471 pushed_p->deltayaw = check->client->ps.pmove.delta_angles[YAW];
476 VectorAdd(check->s.origin, move, check->s.origin);
477 #if USE_SMOOTH_DELTA_ANGLES
481 check->client->ps.pmove.delta_angles[YAW] += ANGLE2SHORT(amove[YAW]);
486 VectorSubtract(check->s.origin, pusher->s.origin, org);
487 org2[0] = DotProduct(org,
forward);
488 org2[1] = -DotProduct(org,
right);
489 org2[2] = DotProduct(org,
up);
490 VectorSubtract(org2, org, move2);
491 VectorAdd(check->s.origin, move2, check->s.origin);
494 if (check->groundentity != pusher)
495 check->groundentity = NULL;
500 gi.linkentity(check);
508 VectorSubtract(check->s.origin, move, check->s.origin);
525 #if USE_SMOOTH_DELTA_ANGLES
526 if (p->
ent->client) {
527 p->
ent->client->ps.pmove.delta_angles[YAW] = p->deltayaw;
530 gi.linkentity(p->
ent);
565 for (part = ent ; part ; part = part->teamchain) {
566 if (part->velocity[0] || part->velocity[1] || part->velocity[2] ||
567 part->avelocity[0] || part->avelocity[1] || part->avelocity[2]
570 VectorScale(part->velocity,
FRAMETIME, move);
571 VectorScale(part->avelocity,
FRAMETIME, amove);
573 if (!
SV_Push(part, move, amove))
578 gi.error(
"pushed_p > &pushed[MAX_EDICTS], memory corrupted");
582 for (mv = ent ; mv ; mv = mv->teamchain) {
583 if (mv->nextthink > 0)
593 if (!
obstacle->inuse && part->inuse)
598 for (part = ent ; part ; part = part->teamchain) {
634 VectorMA(ent->s.angles,
FRAMETIME, ent->avelocity, ent->s.angles);
635 VectorMA(ent->s.origin,
FRAMETIME, ent->velocity, ent->s.origin);
674 if (ent->velocity[2] > 0)
675 ent->groundentity = NULL;
678 if (ent->groundentity)
679 if (!ent->groundentity->inuse)
680 ent->groundentity = NULL;
683 if (ent->groundentity)
686 VectorCopy(ent->s.origin, old_origin);
696 VectorMA(ent->s.angles,
FRAMETIME, ent->avelocity, ent->s.angles);
699 VectorScale(ent->velocity,
FRAMETIME, move);
704 if (trace.fraction < 1) {
710 ClipVelocity(ent->velocity, trace.plane.normal, ent->velocity, backoff);
713 if (trace.plane.normal[2] > 0.7) {
715 ent->groundentity = trace.ent;
716 ent->groundentity_linkcount = trace.ent->linkcount;
727 wasinwater = (ent->watertype & MASK_WATER);
728 ent->watertype =
gi.pointcontents(ent->s.origin);
729 isinwater = ent->watertype & MASK_WATER;
736 if (!wasinwater && isinwater)
737 gi.positioned_sound(old_origin,
g_edicts, CHAN_AUTO,
gi.soundindex(
"misc/h2ohit1.wav"), 1, 1, 0);
738 else if (wasinwater && !isinwater)
739 gi.positioned_sound(ent->s.origin,
g_edicts, CHAN_AUTO,
gi.soundindex(
"misc/h2ohit1.wav"), 1, 1, 0);
742 for (slave = ent->teamchain; slave; slave = slave->teamchain) {
743 VectorCopy(ent->s.origin, slave->s.origin);
744 gi.linkentity(slave);
770 #define sv_stopspeed 100
771 #define sv_friction 6
772 #define sv_waterfriction 1
779 VectorMA(ent->s.angles,
FRAMETIME, ent->avelocity, ent->s.angles);
781 for (n = 0; n < 3; n++) {
782 if (ent->avelocity[n] > 0) {
783 ent->avelocity[n] -= adjustment;
784 if (ent->avelocity[n] < 0)
785 ent->avelocity[n] = 0;
787 ent->avelocity[n] += adjustment;
788 if (ent->avelocity[n] > 0)
789 ent->avelocity[n] = 0;
796 qboolean wasonground;
797 qboolean hitsound = qfalse;
799 float speed, newspeed, control;
801 edict_t *groundentity;
805 if (!ent->groundentity)
808 groundentity = ent->groundentity;
815 wasonground = qfalse;
817 if (ent->avelocity[0] || ent->avelocity[1] || ent->avelocity[2])
824 if (!(ent->flags &
FL_FLY))
825 if (!((ent->flags &
FL_SWIM) && (ent->waterlevel > 2))) {
826 if (ent->velocity[2] <
sv_gravity->value * -0.1)
828 if (ent->waterlevel == 0)
833 if ((ent->flags &
FL_FLY) && (ent->velocity[2] != 0)) {
834 speed = fabs(ent->velocity[2]);
837 newspeed = speed - (
FRAMETIME * control * friction);
841 ent->velocity[2] *= newspeed;
845 if ((ent->flags &
FL_SWIM) && (ent->velocity[2] != 0)) {
846 speed = fabs(ent->velocity[2]);
852 ent->velocity[2] *= newspeed;
855 if (ent->velocity[2] || ent->velocity[1] || ent->velocity[0]) {
861 speed = sqrt(vel[0] * vel[0] + vel[1] * vel[1]);
866 newspeed = speed -
FRAMETIME * control * friction;
877 if (ent->svflags & SVF_MONSTER)
878 mask = MASK_MONSTERSOLID;
888 if (ent->groundentity)
891 gi.sound(ent, 0,
gi.soundindex(
"world/land.wav"), 1, 1, 0);
910 switch ((
int)ent->movetype) {
931 gi.error(
"SV_Physics: bad movetype %i", (
int)ent->movetype);