- int i;
- vec3_t angle;
- int bits;
- eval_t *val;
- float total;
-
-// read ping time
- host_client->ping_times[host_client->num_pings % NUM_PING_TIMES] = sv.time - MSG_ReadFloat ();
- host_client->num_pings++;
- for (i=0, total = 0;i < NUM_PING_TIMES;i++)
- total += host_client->ping_times[i];
- host_client->ping = total / NUM_PING_TIMES; // can be used for prediction
- host_client->latency = 0;
- if (sv_predict.integer && (svs.maxclients > 1) && (!sv.paused)) // if paused or a local game, don't predict
- host_client->latency = host_client->ping;
- if ((val = GETEDICTFIELDVALUE(host_client->edict, eval_ping)))
- val->_float = host_client->ping * 1000.0;
-
-// read current angles
- // dpprotocol version 2
- for (i = 0;i < 3;i++)
- angle[i] = MSG_ReadFloat ();
+ int j;
+ vec3_t wishvel, wishdir, v, v_forward, v_right, v_up, start, stop;
+ float wishspeed, f, limit;
+ trace_t trace;
+
+ if (host_client->edict->fields.server->movetype == MOVETYPE_NONE)
+ return;
+
+ f = DotProduct(host_client->edict->fields.server->punchangle, host_client->edict->fields.server->punchangle);
+ if (f)
+ {
+ limit = sqrt(f);
+ f = (limit - 10 * sv.frametime);
+ f /= limit;
+ f = max(0, f);
+ VectorScale(host_client->edict->fields.server->punchangle, f, host_client->edict->fields.server->punchangle);
+ }
+
+ // if dead, behave differently
+ if (host_client->edict->fields.server->health <= 0)
+ return;
+
+ AngleVectors(host_client->edict->fields.server->v_angle, v_forward, v_right, v_up);
+ // show 1/3 the pitch angle and all the roll angle
+ f = DotProduct(host_client->edict->fields.server->velocity, v_right) * (1.0 / cl_rollspeed.value);
+ host_client->edict->fields.server->angles[2] = bound(-1, f, 1) * cl_rollangle.value * 4;
+ if (!host_client->edict->fields.server->fixangle)
+ {
+ host_client->edict->fields.server->angles[0] = (host_client->edict->fields.server->v_angle[0] + host_client->edict->fields.server->punchangle[0]) * -0.333;
+ host_client->edict->fields.server->angles[1] = host_client->edict->fields.server->v_angle[1] + host_client->edict->fields.server->punchangle[1];
+ }
+
+ if ((int)host_client->edict->fields.server->flags & FL_WATERJUMP)
+ {
+ host_client->edict->fields.server->velocity[0] = host_client->edict->fields.server->movedir[0];
+ host_client->edict->fields.server->velocity[1] = host_client->edict->fields.server->movedir[1];
+ if (sv.time > host_client->edict->fields.server->teleport_time || host_client->edict->fields.server->waterlevel == 0)
+ {
+ host_client->edict->fields.server->flags = (int)host_client->edict->fields.server->flags - ((int)host_client->edict->fields.server->flags & FL_WATERJUMP);
+ host_client->edict->fields.server->teleport_time = 0;
+ }
+ return;
+ }
+
+ // swim
+ if (host_client->edict->fields.server->waterlevel >= 2)
+ if (host_client->edict->fields.server->movetype != MOVETYPE_NOCLIP)
+ {
+ if (host_client->cmd.forwardmove == 0 && host_client->cmd.sidemove == 0 && host_client->cmd.upmove == 0)
+ {
+ // drift towards bottom
+ wishvel[0] = 0;
+ wishvel[1] = 0;
+ wishvel[2] = -60;
+ }
+ else
+ {
+ for (j = 0;j < 3;j++)
+ wishvel[j] = v_forward[j] * host_client->cmd.forwardmove + v_right[j] * host_client->cmd.sidemove;
+ wishvel[2] += host_client->cmd.upmove;
+ }
+
+ wishspeed = VectorLength(wishvel);
+ wishspeed = min(wishspeed, sv_maxspeed.value) * 0.7;
+
+ // water friction
+ f = VectorLength(host_client->edict->fields.server->velocity) * (1 - sv.frametime * sv_friction.value);
+ if (f > 0)
+ f /= VectorLength(host_client->edict->fields.server->velocity);
+ else
+ f = 0;
+ VectorScale(host_client->edict->fields.server->velocity, f, host_client->edict->fields.server->velocity);
+
+ // water acceleration
+ if (wishspeed <= f)
+ return;
+
+ f = wishspeed - f;
+ limit = sv_accelerate.value * wishspeed * sv.frametime;
+ if (f > limit)
+ f = limit;
+ limit = VectorLength(wishvel);
+ if (limit)
+ f /= limit;
+ VectorMA(host_client->edict->fields.server->velocity, f, wishvel, host_client->edict->fields.server->velocity);
+ return;
+ }
+
+ // if not flying, move horizontally only
+ if (host_client->edict->fields.server->movetype != MOVETYPE_FLY)
+ {
+ VectorClear(wishvel);
+ wishvel[1] = host_client->edict->fields.server->v_angle[1];
+ AngleVectors(wishvel, v_forward, v_right, v_up);
+ }
+
+ // hack to not let you back into teleporter
+ VectorScale(v_right, host_client->cmd.sidemove, wishvel);
+ if (sv.time >= host_client->edict->fields.server->teleport_time || host_client->cmd.forwardmove > 0)
+ VectorMA(wishvel, host_client->cmd.forwardmove, v_forward, wishvel);
+ if (host_client->edict->fields.server->movetype != MOVETYPE_WALK)
+ wishvel[2] += cmd.upmove;
+
+ VectorCopy(wishvel, wishdir);
+ VectorNormalize(wishdir);
+ wishspeed = VectorLength(wishvel);
+ if (wishspeed > sv_maxspeed.value)
+ wishspeed = sv_maxspeed.value;