+void SV_Physics_Entity (prvm_edict_t *ent, qboolean runmove)
+{
+ int i = ent - prog->edicts;
+ if (i >= 1 && i <= svs.maxclients)
+ {
+ // apply the latest accepted move to the entity fields
+ SV_ApplyClientMove();
+ // make sure the velocity is sane (not a NaN)
+ SV_CheckVelocity(ent);
+ // LordHavoc: QuakeC replacement for SV_ClientThink (player movement)
+ if (SV_PlayerPhysicsQC)
+ {
+ prog->globals.server->time = sv.time;
+ prog->globals.server->self = PRVM_EDICT_TO_PROG(ent);
+ PRVM_ExecuteProgram ((func_t)(SV_PlayerPhysicsQC - prog->functions), "QC function SV_PlayerPhysics is missing");
+ }
+ else
+ SV_ClientThink ();
+ // make sure the velocity is sane (not a NaN)
+ SV_CheckVelocity(ent);
+ // LordHavoc: a hack to ensure that the (rather silly) id1 quakec
+ // player_run/player_stand1 does not horribly malfunction if the
+ // velocity becomes a number that is both == 0 and != 0
+ // (sounds to me like NaN but to be absolutely safe...)
+ if (DotProduct(ent->fields.server->velocity, ent->fields.server->velocity) < 0.0001)
+ VectorClear(ent->fields.server->velocity);
+ // call standard client pre-think
+ prog->globals.server->time = sv.time;
+ prog->globals.server->self = PRVM_EDICT_TO_PROG(ent);
+ PRVM_ExecuteProgram (prog->globals.server->PlayerPreThink, "QC function PlayerPreThink is missing");
+ SV_CheckVelocity (ent);
+ }
+
+ // LordHavoc: merged client and normal entity physics
+ switch ((int) ent->fields.server->movetype)
+ {
+ case MOVETYPE_PUSH:
+ case MOVETYPE_FAKEPUSH:
+ SV_Physics_Pusher (ent);
+ break;
+ case MOVETYPE_NONE:
+ // LordHavoc: manually inlined the thinktime check here because MOVETYPE_NONE is used on so many objects
+ if (ent->fields.server->nextthink > 0 && ent->fields.server->nextthink <= sv.time + sv.frametime)
+ SV_RunThink (ent);
+ break;
+ case MOVETYPE_FOLLOW:
+ SV_Physics_Follow (ent);
+ break;
+ case MOVETYPE_NOCLIP:
+ if (SV_RunThink(ent))
+ {
+ SV_CheckWater(ent);
+ VectorMA(ent->fields.server->origin, sv.frametime, ent->fields.server->velocity, ent->fields.server->origin);
+ VectorMA(ent->fields.server->angles, sv.frametime, ent->fields.server->avelocity, ent->fields.server->angles);
+ }
+ // relink normal entities here, players always get relinked so don't relink twice
+ if (!(i > 0 && i <= svs.maxclients))
+ SV_LinkEdict(ent, false);
+ break;
+ case MOVETYPE_STEP:
+ SV_Physics_Step (ent);
+ break;
+ case MOVETYPE_WALK:
+ if (SV_RunThink (ent))
+ {
+ if (!SV_CheckWater (ent) && ! ((int)ent->fields.server->flags & FL_WATERJUMP) )
+ SV_AddGravity (ent);
+ SV_CheckStuck (ent);
+ SV_WalkMove (ent);
+ // relink normal entities here, players always get relinked so don't relink twice
+ if (!(i > 0 && i <= svs.maxclients))
+ SV_LinkEdict (ent, true);
+ }
+ break;
+ case MOVETYPE_TOSS:
+ case MOVETYPE_BOUNCE:
+ case MOVETYPE_BOUNCEMISSILE:
+ case MOVETYPE_FLYMISSILE:
+ // regular thinking
+ if (SV_RunThink (ent) && runmove)
+ SV_Physics_Toss (ent);
+ break;
+ case MOVETYPE_FLY:
+ if (SV_RunThink (ent) && runmove)
+ {
+ if (i > 0 && i <= svs.maxclients)
+ {
+ SV_CheckWater (ent);
+ SV_WalkMove (ent);
+ }
+ else
+ SV_Physics_Toss (ent);
+ }
+ break;
+ default:
+ Host_Error ("SV_Physics: bad movetype %i", (int)ent->fields.server->movetype);
+ break;
+ }
+
+ if (i >= 1 && i <= svs.maxclients)
+ {
+ SV_CheckVelocity (ent);
+
+ // call standard player post-think
+ SV_LinkEdict (ent, true);
+
+ SV_CheckVelocity (ent);
+
+ prog->globals.server->time = sv.time;
+ prog->globals.server->self = PRVM_EDICT_TO_PROG(ent);
+ PRVM_ExecuteProgram (prog->globals.server->PlayerPostThink, "QC function PlayerPostThink is missing");
+ }
+}
+
+