added back r_speeds2, with masses of information (6 lines high), and made it print...
[xonotic/darkplaces.git] / sv_phys.c
index ffe1ce9..48af07c 100644 (file)
--- a/sv_phys.c
+++ b/sv_phys.c
@@ -270,7 +270,7 @@ int SV_FlyMove (edict_t *ent, float time, trace_t *steptrace)
 
                if (trace.allsolid)
                {       // entity is trapped in another solid
-                       VectorCopy (vec3_origin, ent->v.velocity);
+                       VectorClear(ent->v.velocity);
                        return 3;
                }
 
@@ -316,7 +316,7 @@ int SV_FlyMove (edict_t *ent, float time, trace_t *steptrace)
        // cliped to another plane
                if (numplanes >= MAX_CLIP_PLANES)
                {       // this shouldn't really happen
-                       VectorCopy (vec3_origin, ent->v.velocity);
+                       VectorClear(ent->v.velocity);
                        return 3;
                }
 
@@ -348,7 +348,7 @@ int SV_FlyMove (edict_t *ent, float time, trace_t *steptrace)
                        if (numplanes != 2)
                        {
 //                             Con_Printf ("clip velocity, numplanes == %i\n",numplanes);
-                               VectorCopy (vec3_origin, ent->v.velocity);
+                               VectorClear(ent->v.velocity);
                                return 7;
                        }
                        CrossProduct (planes[0], planes[1], dir);
@@ -362,7 +362,7 @@ int SV_FlyMove (edict_t *ent, float time, trace_t *steptrace)
 //
                if (DotProduct (ent->v.velocity, primal_velocity) <= 0)
                {
-                       VectorCopy (vec3_origin, ent->v.velocity);
+                       VectorClear(ent->v.velocity);
                        return blocked;
                }
        }
@@ -598,6 +598,24 @@ void SV_PushRotate (edict_t *pusher, float movetime)
        vec3_t          forward, right, up;
        float           savesolid;
 
+       switch ((int) pusher->v.solid)
+       {
+       // LordHavoc: valid pusher types
+       case SOLID_BSP:
+       case SOLID_BBOX:
+       case SOLID_SLIDEBOX:
+       case SOLID_CORPSE: // LordHavoc: this would be weird...
+               break;
+       // LordHavoc: no collisions
+       case SOLID_NOT:
+       case SOLID_TRIGGER:
+               VectorMA (pusher->v.angles, movetime, pusher->v.avelocity, pusher->v.angles);
+               pusher->v.ltime += movetime;
+               SV_LinkEdict (pusher, false);
+               return;
+       default:
+               Host_Error("SV_PushRotate: unrecognized solid type %f\n", pusher->v.solid);
+       }
        if (!pusher->v.avelocity[0] && !pusher->v.avelocity[1] && !pusher->v.avelocity[2])
        {
                pusher->v.ltime += movetime;
@@ -607,7 +625,7 @@ void SV_PushRotate (edict_t *pusher, float movetime)
        for (i=0 ; i<3 ; i++)
                amove[i] = pusher->v.avelocity[i] * movetime;
 
-       VectorSubtract (vec3_origin, amove, a);
+       VectorNegate (amove, a);
        AngleVectors (a, forward, right, up);
 
        VectorCopy (pusher->v.origin, pushorigin);
@@ -731,7 +749,6 @@ void SV_Physics_Pusher (edict_t *ent)
 
        oldltime = ent->v.ltime;
        
-       /*
        thinktime = ent->v.nextthink;
        if (thinktime < ent->v.ltime + host_frametime)
        {
@@ -749,23 +766,6 @@ void SV_Physics_Pusher (edict_t *ent)
                else
                        SV_PushMove (ent, movetime);    // advances ent->v.ltime if not blocked
        }
-       */
-       if (ent->v.avelocity[0] || ent->v.avelocity[1] || ent->v.avelocity[2])
-               SV_PushRotate (ent, host_frametime);
-       else
-       {
-               thinktime = ent->v.nextthink;
-               if (thinktime < ent->v.ltime + host_frametime)
-               {
-                       movetime = thinktime - ent->v.ltime;
-                       if (movetime < 0)
-                               movetime = 0;
-               }
-               else
-                       movetime = host_frametime;
-               if (movetime)
-                       SV_PushMove (ent, movetime);    // advances ent->v.ltime if not blocked
-       }
                
        if (thinktime > oldltime && thinktime <= ent->v.ltime)
        {
@@ -923,7 +923,7 @@ int SV_TryUnstick (edict_t *ent, vec3_t oldvel)
        trace_t steptrace;
        
        VectorCopy (ent->v.origin, oldorg);
-       VectorCopy (vec3_origin, dir);
+       VectorClear (dir);
 
        for (i=0 ; i<8 ; i++)
        {
@@ -959,7 +959,7 @@ int SV_TryUnstick (edict_t *ent, vec3_t oldvel)
                VectorCopy (oldorg, ent->v.origin);
        }
        
-       VectorCopy (vec3_origin, ent->v.velocity);
+       VectorClear (ent->v.velocity);
        return 7;               // still not moving
 }
 
@@ -1014,8 +1014,8 @@ void SV_WalkMove (edict_t *ent)
 //
        VectorCopy (oldorg, ent->v.origin);     // back to start pos
 
-       VectorCopy (vec3_origin, upmove);
-       VectorCopy (vec3_origin, downmove);
+       VectorClear (upmove);
+       VectorClear (downmove);
        upmove[2] = STEPSIZE;
        downmove[2] = -STEPSIZE + oldvel[2]*host_frametime;
 
@@ -1116,12 +1116,14 @@ void SV_Physics_Client (edict_t *ent, int num)
        case MOVETYPE_FLY:
                if (!SV_RunThink (ent))
                        return;
+               SV_CheckWater (ent);
                SV_FlyMove (ent, host_frametime, NULL);
                break;
                
        case MOVETYPE_NOCLIP:
                if (!SV_RunThink (ent))
                        return;
+               SV_CheckWater (ent);
                VectorMA (ent->v.origin, host_frametime, ent->v.velocity, ent->v.origin);
                break;
                
@@ -1163,19 +1165,33 @@ Entities that are "stuck" to another entity
 */
 void SV_Physics_Follow (edict_t *ent)
 {
-       vec3_t vf, vu, vr, angles;
+       vec3_t vf, vr, vu, angles;
        edict_t *e;
 // regular thinking
-       SV_RunThink (ent);
+       if (!SV_RunThink (ent))
+               return;
        // LordHavoc: implemented rotation on MOVETYPE_FOLLOW objects
        e = PROG_TO_EDICT(ent->v.aiment);
-       angles[0] = -e->v.angles[0];
-       angles[1] = e->v.angles[1];
-       angles[2] = e->v.angles[2];
-       AngleVectors (angles, vf, vr, vu);
-       VectorMA (e->v.origin, ent->v.view_ofs[0], vf, ent->v.origin);
-       VectorMA (ent->v.origin, ent->v.view_ofs[1], vr, ent->v.origin);
-       VectorMA (ent->v.origin, ent->v.view_ofs[2], vu, ent->v.origin);
+       if (e->v.angles[0] == ent->v.punchangle[0] && e->v.angles[1] == ent->v.punchangle[1] && e->v.angles[2] == ent->v.punchangle[2])
+       {
+               // quick case for no rotation
+               VectorAdd(e->v.origin, ent->v.view_ofs, ent->v.origin);
+       }
+       else
+       {
+               angles[0] = -(e->v.angles[0] - ent->v.punchangle[0]);
+               angles[1] = e->v.angles[1] - ent->v.punchangle[1];
+               angles[2] = e->v.angles[2] - ent->v.punchangle[2];
+               AngleVectors (angles, vf, vr, vu);
+               ent->v.origin[0] = ent->v.view_ofs[0] * vf[0] + ent->v.view_ofs[1] * vr[0] + ent->v.view_ofs[2] * vu[0] + e->v.origin[0];
+               ent->v.origin[1] = ent->v.view_ofs[0] * vf[1] + ent->v.view_ofs[1] * vr[1] + ent->v.view_ofs[2] * vu[1] + e->v.origin[1];
+               ent->v.origin[2] = ent->v.view_ofs[0] * vf[2] + ent->v.view_ofs[1] * vr[2] + ent->v.view_ofs[2] * vu[2] + e->v.origin[2];
+               /*
+               ent->v.origin[0] = ent->v.view_ofs[0] * vf[0] + ent->v.view_ofs[0] * vf[1] + ent->v.view_ofs[0] * vf[2] + e->v.origin[0];
+               ent->v.origin[1] = ent->v.view_ofs[1] * vr[0] + ent->v.view_ofs[1] * vr[1] + ent->v.view_ofs[1] * vr[2] + e->v.origin[1];
+               ent->v.origin[2] = ent->v.view_ofs[2] * vu[0] + ent->v.view_ofs[2] * vu[1] + ent->v.view_ofs[2] * vu[2] + e->v.origin[2];
+               */
+       }
        VectorAdd (e->v.angles, ent->v.v_angle, ent->v.angles);
 //     VectorAdd (PROG_TO_EDICT(ent->v.aiment)->v.origin, ent->v.v_angle, ent->v.origin);
        SV_LinkEdict (ent, true);
@@ -1300,8 +1316,8 @@ void SV_Physics_Toss (edict_t *ent)
                {
                        ent->v.flags = (int)ent->v.flags | FL_ONGROUND;
                        ent->v.groundentity = EDICT_TO_PROG(trace.ent);
-                       VectorCopy (vec3_origin, ent->v.velocity);
-                       VectorCopy (vec3_origin, ent->v.avelocity);
+                       VectorClear (ent->v.velocity);
+                       VectorClear (ent->v.avelocity);
                }
        }