2003-02-18 23:11:05 +00:00
|
|
|
/***********************************************
|
|
|
|
* *
|
|
|
|
* FrikBot Physics *
|
|
|
|
* The near-perfect emulation of *
|
|
|
|
* Client movement *
|
|
|
|
* *
|
|
|
|
* Special Thanks to: Asdf, Frog *
|
|
|
|
* Alan "Strider" Kivlin *
|
|
|
|
* *
|
|
|
|
* *
|
|
|
|
***********************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
This program is in the Public Domain. My crack legal
|
|
|
|
team would like to add:
|
|
|
|
|
|
|
|
RYAN "FRIKAC" SMITH IS PROVIDING THIS SOFTWARE "AS IS"
|
|
|
|
AND MAKES NO WARRANTY, EXPRESS OR IMPLIED, AS TO THE
|
|
|
|
ACCURACY, CAPABILITY, EFFICIENCY, MERCHANTABILITY, OR
|
|
|
|
FUNCTIONING OF THIS SOFTWARE AND/OR DOCUMENTATION. IN
|
|
|
|
NO EVENT WILL RYAN "FRIKAC" SMITH BE LIABLE FOR ANY
|
|
|
|
GENERAL, CONSEQUENTIAL, INDIRECT, INCIDENTAL,
|
|
|
|
EXEMPLARY, OR SPECIAL DAMAGES, EVEN IF RYAN "FRIKAC"
|
|
|
|
SMITH HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
|
|
|
DAMAGES, IRRESPECTIVE OF THE CAUSE OF SUCH DAMAGES.
|
|
|
|
|
|
|
|
You accept this software on the condition that you
|
|
|
|
indemnify and hold harmless Ryan "FrikaC" Smith from
|
|
|
|
any and all liability or damages to third parties,
|
|
|
|
including attorney fees, court costs, and other
|
|
|
|
related costs and expenses, arising out of your use
|
|
|
|
of this software irrespective of the cause of said
|
|
|
|
liability.
|
|
|
|
|
|
|
|
The export from the United States or the subsequent
|
|
|
|
reexport of this software is subject to compliance
|
|
|
|
with United States export control and munitions
|
|
|
|
control restrictions. You agree that in the event you
|
|
|
|
seek to export this software, you assume full
|
|
|
|
responsibility for obtaining all necessary export
|
|
|
|
licenses and approvals and for assuring compliance
|
|
|
|
with applicable reexport restrictions.
|
|
|
|
|
|
|
|
Any reproduction of this software must contain
|
|
|
|
this notice in its entirety.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2003-02-24 16:05:25 +00:00
|
|
|
#include "libfrikbot.h"
|
|
|
|
|
2003-02-18 23:11:05 +00:00
|
|
|
/*
|
|
|
|
=========================================
|
|
|
|
|
|
|
|
Stuff mimicking cl_input.c code
|
|
|
|
|
|
|
|
=========================================
|
|
|
|
*/
|
|
|
|
float(float key) CL_KeyState =
|
|
|
|
{
|
2003-02-21 06:01:33 +00:00
|
|
|
return ((self.keys & key) > 0) ? 1.0 : 0.0;
|
2003-02-18 23:11:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void() CL_KeyMove = // CL_BaseMove + CL_AdjustAngles
|
|
|
|
{
|
|
|
|
local float anglespeed;
|
2003-02-21 06:01:33 +00:00
|
|
|
local vector view;
|
2003-03-05 21:12:56 +00:00
|
|
|
|
2003-03-04 18:26:17 +00:00
|
|
|
if (self.keys != self.oldkeys) {
|
2003-02-18 23:11:05 +00:00
|
|
|
self.movevect = '0 0 0';
|
2003-03-08 03:20:32 +00:00
|
|
|
self.movevect_y = self.movevect_y + (350 * CL_KeyState (KEY_MOVERIGHT));
|
2003-02-18 23:11:05 +00:00
|
|
|
// 350 is the default cl_sidespeed
|
2003-03-08 03:20:32 +00:00
|
|
|
self.movevect_y = self.movevect_y - (350 * CL_KeyState (KEY_MOVELEFT));
|
2003-02-18 23:11:05 +00:00
|
|
|
// 350 is the default cl_sidespeed
|
2003-03-08 03:20:32 +00:00
|
|
|
self.movevect_x = self.movevect_x + (200 * CL_KeyState (KEY_MOVEFORWARD));
|
2003-02-18 23:11:05 +00:00
|
|
|
// 200 is the default cl_forwardspeed
|
2003-03-08 03:20:32 +00:00
|
|
|
self.movevect_x = self.movevect_x - (200 * CL_KeyState (KEY_MOVEBACK));
|
2003-02-18 23:11:05 +00:00
|
|
|
// 200 is the default cl_backspeed
|
2003-03-08 03:20:32 +00:00
|
|
|
self.movevect_z = self.movevect_z + (200 * CL_KeyState (KEY_MOVEUP));
|
2003-02-18 23:11:05 +00:00
|
|
|
// 200 is the default cl_upspeed
|
2003-03-08 03:20:32 +00:00
|
|
|
self.movevect_z = self.movevect_z - (200 * CL_KeyState (KEY_MOVEDOWN));
|
2003-02-18 23:11:05 +00:00
|
|
|
// 200 is the default cl_upspeed
|
2003-02-18 23:12:03 +00:00
|
|
|
if (!(self.b_aiflags & AI_PRECISION))
|
2003-02-18 23:11:05 +00:00
|
|
|
self.movevect = self.movevect * 2;
|
|
|
|
// 2 is the default cl_movespeedkey & bot always has +speed
|
|
|
|
}
|
|
|
|
self.oldkeys = self.keys;
|
|
|
|
|
2003-03-04 18:26:17 +00:00
|
|
|
if (self.b_skill != 2) {
|
|
|
|
// use mouse emulation
|
2003-03-08 03:20:32 +00:00
|
|
|
anglespeed = 1.5 * real_frametime;
|
2003-02-18 23:11:05 +00:00
|
|
|
// 1.5 is the default cl_anglespeedkey & bot always has +speed
|
2003-03-08 03:20:32 +00:00
|
|
|
self.v_angle_y = self.v_angle_y + anglespeed * CL_KeyState (KEY_LOOKLEFT) * 140;
|
2003-02-18 23:11:05 +00:00
|
|
|
// 140 is default cl_yawspeed
|
2003-03-08 03:20:32 +00:00
|
|
|
self.v_angle_y = self.v_angle_y - anglespeed * CL_KeyState (KEY_LOOKRIGHT) * 140;
|
2003-02-18 23:11:05 +00:00
|
|
|
// 140 is default cl_yawspeed
|
2003-03-08 03:20:32 +00:00
|
|
|
self.v_angle_x = self.v_angle_x - anglespeed * CL_KeyState (KEY_LOOKUP) * 150;
|
2003-02-18 23:11:05 +00:00
|
|
|
// 150 is default cl_pitchspeed
|
2003-03-08 03:20:32 +00:00
|
|
|
self.v_angle_x = self.v_angle_x + anglespeed * CL_KeyState (KEY_LOOKDOWN) * 150;
|
2003-02-18 23:11:05 +00:00
|
|
|
// 150 is default cl_pitchspeed
|
2003-03-04 18:26:17 +00:00
|
|
|
} else {
|
2003-03-08 03:20:32 +00:00
|
|
|
view_x = angcomp (self.b_angle_x, self.v_angle_x);
|
|
|
|
view_y = angcomp (self.b_angle_y, self.v_angle_y);
|
2003-02-21 06:01:33 +00:00
|
|
|
view_z = 0;
|
2003-03-08 03:20:32 +00:00
|
|
|
if (vlen (view) > 30) {
|
2003-02-18 23:11:05 +00:00
|
|
|
self.mouse_emu = self.mouse_emu + (view * 30);
|
|
|
|
if (vlen(self.mouse_emu) > 180)
|
2003-03-08 03:20:32 +00:00
|
|
|
self.mouse_emu = normalize (self.mouse_emu) * 180;
|
|
|
|
} else
|
2003-02-18 23:11:05 +00:00
|
|
|
self.mouse_emu = view * (1 / real_frametime);
|
2003-03-08 03:20:32 +00:00
|
|
|
self.v_angle += self.mouse_emu * real_frametime;
|
2003-02-18 23:11:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
if (self.v_angle_x > 80)
|
|
|
|
self.v_angle_x = 80;
|
|
|
|
else if (self.v_angle_x < -70)
|
|
|
|
self.v_angle_x = -70;
|
|
|
|
|
|
|
|
if (self.v_angle_z > 50)
|
|
|
|
self.v_angle_z = 50;
|
|
|
|
else if (self.v_angle_z < -50)
|
|
|
|
self.v_angle_z = -50;
|
2003-03-08 03:20:32 +00:00
|
|
|
self.v_angle_y = frik_anglemod (self.v_angle_y);
|
2003-02-18 23:11:05 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
=========================================
|
|
|
|
|
|
|
|
Stuff mimicking sv_user.c
|
|
|
|
|
|
|
|
=========================================
|
|
|
|
*/
|
|
|
|
void() SV_UserFriction =
|
|
|
|
{
|
|
|
|
local vector vel, start, stop;
|
|
|
|
local float sped, friction, newspeed;
|
|
|
|
|
2003-03-05 21:12:56 +00:00
|
|
|
vel = self.velocity;
|
2003-02-18 23:11:05 +00:00
|
|
|
vel_z =0;
|
2003-03-08 03:20:32 +00:00
|
|
|
sped = vlen (vel);
|
2003-02-18 23:11:05 +00:00
|
|
|
vel = self.velocity;
|
|
|
|
|
|
|
|
if (!sped)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// if the leading edge is over a dropoff, increase friction
|
|
|
|
|
|
|
|
start_x = stop_x = self.origin_x + vel_x / (sped * 16);
|
|
|
|
start_y = stop_y = self.origin_y + vel_y / (sped * 16);
|
|
|
|
start_z = self.origin_z + self.mins_z;
|
|
|
|
stop_z = start_z - 34;
|
|
|
|
|
2003-03-08 03:20:32 +00:00
|
|
|
traceline (start, stop, TRUE, self);
|
2003-02-18 23:11:05 +00:00
|
|
|
|
|
|
|
if (trace_fraction == 1)
|
|
|
|
friction = sv_friction * 2; // 2 is default edgefriction, removed for QW compatability
|
|
|
|
else
|
2003-03-05 21:12:56 +00:00
|
|
|
friction = sv_friction;
|
|
|
|
if (sped < sv_stopspeed)
|
2003-02-18 23:11:05 +00:00
|
|
|
newspeed = sped - real_frametime * sv_stopspeed * friction;
|
|
|
|
else
|
|
|
|
newspeed = sped - real_frametime * sped * friction;
|
|
|
|
|
|
|
|
if (newspeed < 0)
|
|
|
|
newspeed = 0;
|
|
|
|
newspeed = newspeed / sped;
|
|
|
|
|
|
|
|
self.velocity_y = vel_y * newspeed;
|
|
|
|
self.velocity_x = vel_x * newspeed;
|
|
|
|
};
|
2003-03-05 21:12:56 +00:00
|
|
|
|
2003-02-18 23:11:05 +00:00
|
|
|
void() SV_WaterJump =
|
|
|
|
{
|
2003-03-04 18:26:17 +00:00
|
|
|
if (time > self.teleport_time || !self.waterlevel) {
|
2003-03-08 03:20:32 +00:00
|
|
|
self.flags &= ~FL_WATERJUMP;
|
2003-02-18 23:11:05 +00:00
|
|
|
self.teleport_time = 0;
|
|
|
|
}
|
|
|
|
self.velocity_x = self.movedir_x;
|
|
|
|
self.velocity_y = self.movedir_y;
|
|
|
|
};
|
|
|
|
|
|
|
|
void() DropPunchAngle =
|
|
|
|
{
|
|
|
|
local float len;
|
2003-03-05 21:12:56 +00:00
|
|
|
|
2003-03-08 03:20:32 +00:00
|
|
|
len = vlen (self.punchangle);
|
|
|
|
self.punchangle = normalize (self.punchangle);
|
|
|
|
len -= 10 * real_frametime;
|
2003-02-18 23:11:05 +00:00
|
|
|
if (len < 0)
|
|
|
|
len = 0;
|
2003-03-08 03:20:32 +00:00
|
|
|
self.punchangle *= len;
|
2003-02-18 23:11:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void(vector wishvel) SV_AirAccelerate =
|
|
|
|
{
|
|
|
|
local float addspeed, wishspd, accelspeed, currentspeed;
|
|
|
|
|
2003-03-08 03:20:32 +00:00
|
|
|
wishspd = vlen (wishvel);
|
|
|
|
wishvel = normalize (wishvel);
|
2003-02-18 23:11:05 +00:00
|
|
|
if (wishspd > 30)
|
|
|
|
wishspd = 30;
|
|
|
|
currentspeed = self.velocity * wishvel;
|
|
|
|
addspeed = wishspd - currentspeed;
|
|
|
|
if (addspeed <= 0)
|
|
|
|
return;
|
|
|
|
accelspeed = 10 * sv_accelerate * wishspd * real_frametime;
|
|
|
|
if (accelspeed > addspeed)
|
|
|
|
accelspeed = addspeed;
|
|
|
|
|
2003-03-08 03:20:32 +00:00
|
|
|
self.velocity += accelspeed * wishvel;
|
2003-02-18 23:11:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void(vector wishvel) SV_Accelerate =
|
|
|
|
{
|
|
|
|
local float addspeed, wishspd, accelspeed, currentspeed;
|
|
|
|
|
2003-03-08 03:20:32 +00:00
|
|
|
wishspd = vlen (wishvel);
|
|
|
|
wishvel = normalize (wishvel);
|
2003-02-18 23:11:05 +00:00
|
|
|
|
|
|
|
currentspeed = self.velocity * wishvel;
|
|
|
|
addspeed = wishspd - currentspeed;
|
|
|
|
if (addspeed <= 0)
|
|
|
|
return;
|
|
|
|
accelspeed = sv_accelerate * wishspd * real_frametime;
|
|
|
|
if (accelspeed > addspeed)
|
|
|
|
accelspeed = addspeed;
|
|
|
|
|
2003-03-08 03:20:32 +00:00
|
|
|
self.velocity += accelspeed * wishvel;
|
2003-02-18 23:11:05 +00:00
|
|
|
};
|
2003-03-05 21:12:56 +00:00
|
|
|
|
2003-02-18 23:11:05 +00:00
|
|
|
void() SV_WaterMove =
|
|
|
|
{
|
2003-03-05 00:10:15 +00:00
|
|
|
local vector wishvel;
|
|
|
|
local float wishspeed, addspeed, cspeed, newspeed;
|
2003-03-05 21:12:56 +00:00
|
|
|
|
2003-03-08 03:20:32 +00:00
|
|
|
makevectors (self.v_angle);
|
2003-02-18 23:11:05 +00:00
|
|
|
wishvel = v_right * self.movevect_y + v_forward * self.movevect_x;
|
|
|
|
|
|
|
|
if (self.movevect == '0 0 0')
|
2003-03-08 03:20:32 +00:00
|
|
|
wishvel_z -= 60;
|
2003-02-18 23:11:05 +00:00
|
|
|
else
|
2003-03-08 03:20:32 +00:00
|
|
|
wishvel_z += self.movevect_z;
|
2003-02-18 23:11:05 +00:00
|
|
|
wishspeed = vlen(wishvel);
|
|
|
|
|
2003-03-04 18:26:17 +00:00
|
|
|
if (wishspeed > sv_maxspeed) {
|
2003-02-18 23:11:05 +00:00
|
|
|
wishvel = (sv_maxspeed / wishspeed) * wishvel;
|
|
|
|
wishspeed = sv_maxspeed;
|
|
|
|
}
|
|
|
|
wishspeed = wishspeed * 0.7;
|
2003-03-08 03:20:32 +00:00
|
|
|
cspeed = vlen (self.velocity);
|
2003-03-04 18:26:17 +00:00
|
|
|
if (cspeed) {
|
|
|
|
newspeed = cspeed - (real_frametime * cspeed * sv_friction);
|
2003-02-18 23:11:05 +00:00
|
|
|
if (newspeed < 0)
|
|
|
|
newspeed = 0;
|
2003-03-08 03:20:32 +00:00
|
|
|
self.velocity *= (newspeed / cspeed);
|
2003-02-18 23:11:05 +00:00
|
|
|
|
2003-03-04 18:26:17 +00:00
|
|
|
} else
|
2003-02-18 23:11:05 +00:00
|
|
|
newspeed = 0;
|
|
|
|
|
|
|
|
if (!wishspeed)
|
|
|
|
return;
|
|
|
|
addspeed = wishspeed - newspeed;
|
2003-03-05 00:10:15 +00:00
|
|
|
if (addspeed <= 0)
|
2003-02-18 23:11:05 +00:00
|
|
|
return;
|
|
|
|
wishvel = normalize(wishvel);
|
2003-03-05 00:10:15 +00:00
|
|
|
cspeed = sv_accelerate * wishspeed * real_frametime;
|
|
|
|
if (cspeed > addspeed)
|
|
|
|
cspeed = addspeed;
|
2003-03-08 03:20:32 +00:00
|
|
|
self.velocity += cspeed * wishvel;
|
2003-02-18 23:11:05 +00:00
|
|
|
};
|
2003-03-05 21:12:56 +00:00
|
|
|
|
2003-02-18 23:11:05 +00:00
|
|
|
void() SV_AirMove =
|
|
|
|
{
|
|
|
|
local vector wishvel, vangle;
|
|
|
|
|
|
|
|
vangle = self.v_angle;
|
|
|
|
vangle_x = vangle_z = 0;
|
2003-03-08 03:20:32 +00:00
|
|
|
makevectors (vangle);
|
2003-02-18 23:11:05 +00:00
|
|
|
if (time < self.teleport_time && (self.movevect_x < 0))
|
|
|
|
self.movevect_x = 0;
|
|
|
|
wishvel = v_right * self.movevect_y + v_forward * self.movevect_x;
|
|
|
|
|
|
|
|
|
|
|
|
if (self.movetype != MOVETYPE_WALK)
|
|
|
|
wishvel_z = self.movevect_z;
|
|
|
|
else
|
|
|
|
wishvel_z = 0;
|
2003-03-08 03:20:32 +00:00
|
|
|
if (vlen (wishvel) > sv_maxspeed)
|
|
|
|
wishvel = normalize (wishvel) * sv_maxspeed;
|
2003-02-18 23:11:05 +00:00
|
|
|
if (self.movetype == MOVETYPE_NOCLIP)
|
|
|
|
self.velocity = wishvel;
|
2003-03-04 18:26:17 +00:00
|
|
|
else if (self.flags & FL_ONGROUND) {
|
2003-03-08 03:20:32 +00:00
|
|
|
SV_UserFriction ();
|
|
|
|
SV_Accelerate (wishvel);
|
2003-03-04 18:26:17 +00:00
|
|
|
} else
|
2003-02-18 23:11:05 +00:00
|
|
|
SV_AirAccelerate (wishvel);
|
|
|
|
};
|
|
|
|
|
|
|
|
void() SV_ClientThink =
|
|
|
|
{
|
|
|
|
local vector vangle;
|
|
|
|
|
|
|
|
if (self.movetype == MOVETYPE_NONE)
|
|
|
|
return;
|
|
|
|
DropPunchAngle();
|
|
|
|
if (self.health <= 0)
|
|
|
|
return;
|
|
|
|
self.v_angle_z = 0; // V_CalcRoll removed, sucks
|
2003-03-08 03:20:32 +00:00
|
|
|
self.angles_z *= 4;
|
2003-02-18 23:11:05 +00:00
|
|
|
vangle = self.v_angle + self.punchangle;
|
2003-03-04 18:26:17 +00:00
|
|
|
if (!self.fixangle) {
|
|
|
|
self.angles_x = (vangle_x / -3);
|
2003-02-18 23:11:05 +00:00
|
|
|
self.angles_y = vangle_y;
|
2003-03-04 18:26:17 +00:00
|
|
|
} else {
|
2003-02-18 23:11:05 +00:00
|
|
|
self.v_angle = self.angles;
|
|
|
|
self.fixangle = 0;
|
|
|
|
}
|
2003-03-04 18:26:17 +00:00
|
|
|
if (self.flags & FL_WATERJUMP) {
|
2003-03-08 03:20:32 +00:00
|
|
|
SV_WaterJump ();
|
2003-02-18 23:11:05 +00:00
|
|
|
return;
|
|
|
|
}
|
2003-03-04 18:26:17 +00:00
|
|
|
if ((self.waterlevel >= 2) && (self.movetype != MOVETYPE_NOCLIP)) {
|
2003-03-08 03:20:32 +00:00
|
|
|
SV_WaterMove ();
|
2003-02-18 23:11:05 +00:00
|
|
|
return;
|
|
|
|
}
|
2003-03-08 03:20:32 +00:00
|
|
|
SV_AirMove ();
|
2003-02-18 23:11:05 +00:00
|
|
|
|
|
|
|
};
|
2003-03-05 21:12:56 +00:00
|
|
|
|
2003-02-18 23:11:05 +00:00
|
|
|
/*
|
|
|
|
=========================================
|
|
|
|
|
|
|
|
Stuff mimicking sv_phys.c
|
|
|
|
|
|
|
|
=========================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
float() SV_RunThink =
|
|
|
|
{
|
|
|
|
local float thinktime, bkuptime;
|
2003-03-05 21:12:56 +00:00
|
|
|
|
2003-02-18 23:11:05 +00:00
|
|
|
thinktime = self.nextthink;
|
|
|
|
bkuptime = time;
|
|
|
|
if (thinktime <= 0 || thinktime > (time + real_frametime))
|
|
|
|
return TRUE;
|
|
|
|
if (thinktime < time)
|
|
|
|
thinktime = time;
|
|
|
|
self.nextthink = 0;
|
|
|
|
time = thinktime;
|
2003-02-24 16:05:25 +00:00
|
|
|
other = NIL;
|
2003-03-08 03:20:32 +00:00
|
|
|
makevectors (self.v_angle); // hack
|
2003-02-18 23:11:05 +00:00
|
|
|
self.think();
|
|
|
|
time = bkuptime;
|
|
|
|
return TRUE;
|
|
|
|
};
|
|
|
|
|
|
|
|
void(float scale) SV_AddGravity =
|
|
|
|
{
|
2003-03-08 03:20:32 +00:00
|
|
|
self.velocity_z -= (scale * sv_gravity * real_frametime);
|
2003-02-18 23:11:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
float() SV_CheckWater =
|
|
|
|
{
|
|
|
|
local vector point;
|
|
|
|
local float cont;
|
|
|
|
|
|
|
|
point_x = self.origin_x;
|
|
|
|
point_y = self.origin_y;
|
|
|
|
self.waterlevel = 0;
|
|
|
|
self.watertype = CONTENT_EMPTY;
|
|
|
|
point_z = self.origin_z + self.mins_z + 1;
|
2003-03-08 03:20:32 +00:00
|
|
|
cont = pointcontents (point);
|
2003-03-04 18:26:17 +00:00
|
|
|
if (cont <= CONTENT_WATER) {
|
|
|
|
self.watertype = cont;
|
|
|
|
self.waterlevel = 1;
|
2003-02-18 23:11:05 +00:00
|
|
|
point_z = self.origin_z + (self.mins_z + self.maxs_z) * 0.5;
|
2003-03-08 03:20:32 +00:00
|
|
|
cont = pointcontents (point);
|
2003-03-04 18:26:17 +00:00
|
|
|
if (cont <= CONTENT_WATER) {
|
2003-02-18 23:11:05 +00:00
|
|
|
self.waterlevel = 2;
|
|
|
|
point_z = self.origin_z + self.view_ofs_z;
|
2003-03-08 03:20:32 +00:00
|
|
|
cont = pointcontents (point);
|
2003-02-18 23:11:05 +00:00
|
|
|
if (cont <= CONTENT_WATER)
|
|
|
|
self.waterlevel = 3;
|
|
|
|
}
|
|
|
|
}
|
2003-02-21 06:01:33 +00:00
|
|
|
return (self.waterlevel > 1) ? 1.0 : 0.0;
|
2003-02-18 23:11:05 +00:00
|
|
|
|
|
|
|
};
|
2003-03-05 21:12:56 +00:00
|
|
|
|
2003-02-18 23:11:05 +00:00
|
|
|
void() RemoveThud = // well sometimes
|
|
|
|
{
|
|
|
|
local entity oself;
|
2003-03-05 21:12:56 +00:00
|
|
|
|
2003-03-04 18:26:17 +00:00
|
|
|
if (other == NIL) {
|
|
|
|
if (self.flags & FL_ONGROUND) {
|
2003-03-08 03:20:32 +00:00
|
|
|
self.flags &= ~FL_ONGROUND;
|
2003-02-18 23:11:05 +00:00
|
|
|
}
|
2003-03-04 18:26:17 +00:00
|
|
|
} else {
|
|
|
|
if (other.solid == SOLID_BSP && (self.flags & FL_ONGROUND)) {
|
2003-02-18 23:11:05 +00:00
|
|
|
// RM: Does this break anything?
|
|
|
|
// If not, then some more thuds have been removed.
|
2003-03-08 03:20:32 +00:00
|
|
|
self.flags &= ~FL_ONGROUND;
|
2003-02-18 23:11:05 +00:00
|
|
|
}
|
|
|
|
if (other == self.owner)
|
|
|
|
return;
|
|
|
|
if (self.owner.solid == SOLID_NOT)
|
|
|
|
return;
|
|
|
|
oself = other;
|
|
|
|
other = self.owner;
|
|
|
|
self = oself;
|
|
|
|
if (self.solid == SOLID_BSP)
|
|
|
|
if (self.touch)
|
2003-03-08 03:20:32 +00:00
|
|
|
self.touch ();
|
2003-02-18 23:11:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
2003-03-05 21:12:56 +00:00
|
|
|
|
2003-02-18 23:11:05 +00:00
|
|
|
void() SV_CheckOnGround =
|
|
|
|
{
|
|
|
|
local vector org, v;
|
|
|
|
local float currentflags;
|
2003-03-05 21:12:56 +00:00
|
|
|
|
|
|
|
org = self.origin;
|
2003-02-18 23:11:05 +00:00
|
|
|
currentflags = self.flags;
|
2003-03-08 03:20:32 +00:00
|
|
|
self.flags |= FL_ONGROUND | FL_PARTIALGROUND;
|
|
|
|
walkmove (0,0); // perform C touch function
|
2003-02-18 23:11:05 +00:00
|
|
|
self.flags = currentflags | FL_ONGROUND;
|
|
|
|
if ((org_x != self.origin_x) || (org_y != self.origin_y))
|
|
|
|
org = self.origin;
|
|
|
|
else
|
|
|
|
self.origin = org;
|
|
|
|
v = org;
|
|
|
|
v_z = self.maxs_z + org_z + 1;
|
|
|
|
traceline (org, v, TRUE, self);
|
|
|
|
if ((self.waterlevel == 3) && (self.movetype == MOVETYPE_WALK))
|
2003-03-08 03:20:32 +00:00
|
|
|
self.flags &= ~FL_ONGROUND;
|
2003-02-18 23:11:05 +00:00
|
|
|
else if ((trace_plane_normal_z <= 0.7) && (trace_fraction != 1))
|
2003-03-08 03:20:32 +00:00
|
|
|
self.flags &= ~FL_ONGROUND;
|
2003-03-04 18:26:17 +00:00
|
|
|
else if (!droptofloor ())
|
2003-03-08 03:20:32 +00:00
|
|
|
self.flags &= ~FL_ONGROUND;
|
2003-02-18 23:11:05 +00:00
|
|
|
else if (org_z - self.origin_z < 2)
|
2003-03-08 03:20:32 +00:00
|
|
|
self.flags |= FL_ONGROUND;
|
2003-02-18 23:11:05 +00:00
|
|
|
else
|
2003-03-08 03:20:32 +00:00
|
|
|
self.flags &= ~FL_ONGROUND;
|
2003-02-18 23:11:05 +00:00
|
|
|
setorigin(self, org);
|
|
|
|
};
|
2003-03-05 21:12:56 +00:00
|
|
|
|
2003-02-18 23:11:05 +00:00
|
|
|
// Thanks to Alan Kivlin for this function
|
|
|
|
// modified heavily by me
|
|
|
|
float(vector dir) botCheckForStep =
|
|
|
|
{
|
|
|
|
local vector currentorigin, v;
|
|
|
|
local float currentflags, yaw, stepdistance, movedistance;
|
2003-03-05 21:12:56 +00:00
|
|
|
|
2003-02-18 23:11:05 +00:00
|
|
|
currentorigin = self.origin;
|
|
|
|
currentflags = self.flags;
|
|
|
|
self.flags = FL_ONGROUND | FL_PARTIALGROUND;
|
2003-03-08 03:20:32 +00:00
|
|
|
dir = normalize (dir);
|
2003-02-18 23:11:05 +00:00
|
|
|
dir_z = 0;
|
2003-03-08 03:20:32 +00:00
|
|
|
yaw = vectoyaw (dir);
|
|
|
|
if (walkmove (yaw, 3)) {
|
|
|
|
if (droptofloor ()) {
|
2003-02-18 23:11:05 +00:00
|
|
|
stepdistance = self.origin_z - currentorigin_z;
|
|
|
|
v = self.origin - currentorigin;
|
|
|
|
v_z = 0;
|
2003-03-08 03:20:32 +00:00
|
|
|
movedistance = vlen (v);
|
|
|
|
if ((stepdistance > 0 && stepdistance <= 16) && movedistance != 0) {
|
2003-02-18 23:11:05 +00:00
|
|
|
self.flags = currentflags | FL_PARTIALGROUND;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
self.flags = currentflags;
|
2003-03-08 03:20:32 +00:00
|
|
|
setorigin (self, currentorigin);
|
2003-02-18 23:11:05 +00:00
|
|
|
return 0;
|
|
|
|
};
|
2003-03-05 21:12:56 +00:00
|
|
|
|
2003-02-18 23:11:05 +00:00
|
|
|
// this is merely here to fix a problem with e3m5
|
|
|
|
void(vector dir) BruteForceStep =
|
|
|
|
{
|
|
|
|
local vector currentorigin;
|
2003-02-18 23:12:03 +00:00
|
|
|
local float currentflags, i = 0, len;
|
2003-02-18 23:11:05 +00:00
|
|
|
|
|
|
|
currentorigin = self.origin;
|
|
|
|
currentflags = self.flags;
|
2003-03-08 03:20:32 +00:00
|
|
|
len = vlen (dir);
|
2003-02-18 23:11:05 +00:00
|
|
|
if (len > 16)
|
2003-03-08 03:20:32 +00:00
|
|
|
dir = normalize (dir) * 16;
|
2003-02-18 23:11:05 +00:00
|
|
|
|
2003-03-08 03:20:32 +00:00
|
|
|
setorigin (self, currentorigin + dir);
|
2003-02-18 23:11:05 +00:00
|
|
|
|
2003-03-08 03:20:32 +00:00
|
|
|
while(i < 18 && !walkmove (0, 0)) {
|
2003-02-18 23:11:05 +00:00
|
|
|
self.origin_z = currentorigin_z + i;
|
2003-03-08 03:20:32 +00:00
|
|
|
i += 2;
|
2003-02-18 23:11:05 +00:00
|
|
|
}
|
|
|
|
self.flags = currentflags;
|
2003-03-08 03:20:32 +00:00
|
|
|
if (i >= 18)
|
|
|
|
setorigin (self, currentorigin);
|
2003-02-18 23:11:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void() PostPhysics =
|
|
|
|
{
|
|
|
|
local vector obstr, org;
|
2003-03-08 03:20:32 +00:00
|
|
|
local float back, dst, cflags;
|
2003-02-18 23:11:05 +00:00
|
|
|
|
|
|
|
self = self.owner;
|
|
|
|
|
2003-03-08 03:20:32 +00:00
|
|
|
self.velocity += self.phys_obj.velocity - self.phys_obj.dest1;
|
2003-03-04 18:26:17 +00:00
|
|
|
if (self.phys_obj.dest2 == self.origin) {
|
2003-03-08 03:20:32 +00:00
|
|
|
setorigin (self, self.phys_obj.origin);
|
2003-02-18 23:11:05 +00:00
|
|
|
// might've been moved during other person's physics
|
|
|
|
// (teleporters / plats)
|
|
|
|
|
2003-03-04 18:26:17 +00:00
|
|
|
if (self.movetype == MOVETYPE_WALK) {
|
2003-02-18 23:11:05 +00:00
|
|
|
|
2003-03-04 18:26:17 +00:00
|
|
|
if (self.phys_obj.dest1_x || self.phys_obj.dest1_y) {
|
|
|
|
if ((self.flags & FL_ONGROUND) || (self.waterlevel <= 2)) {
|
2003-02-18 23:11:05 +00:00
|
|
|
obstr = self.phys_obj.movedir - self.origin;
|
|
|
|
obstr_z = 0;
|
2003-03-08 03:20:32 +00:00
|
|
|
if (vlen (obstr) > 0.1) {
|
|
|
|
dst = vlen (obstr);
|
|
|
|
back = vectoyaw (obstr);
|
2003-02-18 23:11:05 +00:00
|
|
|
cflags = self.flags;
|
2003-03-08 03:20:32 +00:00
|
|
|
self.flags |= FL_PARTIALGROUND;
|
|
|
|
if (walkmove (back, dst)) {
|
2003-02-18 23:11:05 +00:00
|
|
|
self.flags = cflags;
|
|
|
|
self.phys_obj.dest1_z = 0;
|
2003-03-08 03:20:32 +00:00
|
|
|
self.velocity += self.phys_obj.dest1 - self.phys_obj.velocity;
|
2003-03-04 18:26:17 +00:00
|
|
|
} else {
|
2003-02-18 23:11:05 +00:00
|
|
|
if (dst > 1)
|
2003-03-08 03:20:32 +00:00
|
|
|
frik_obstructed (obstr, FALSE);
|
2003-02-18 23:11:05 +00:00
|
|
|
|
|
|
|
org = self.origin;
|
|
|
|
self.flags = cflags;
|
|
|
|
obstr = self.phys_obj.dest1;
|
|
|
|
obstr_x = 0;
|
2003-03-08 03:20:32 +00:00
|
|
|
if (!botCheckForStep (obstr)) {
|
2003-02-18 23:11:05 +00:00
|
|
|
obstr = self.phys_obj.dest1;
|
|
|
|
obstr_y = 0;
|
2003-03-08 03:20:32 +00:00
|
|
|
if (!botCheckForStep (obstr)) {
|
2003-02-18 23:11:05 +00:00
|
|
|
// if no steps were found, bot is really obstucted
|
2003-03-08 03:20:32 +00:00
|
|
|
BruteForceStep (self.phys_obj.dest1);
|
2003-02-18 23:11:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-08 03:20:32 +00:00
|
|
|
SV_CheckOnGround ();
|
2003-02-18 23:11:05 +00:00
|
|
|
|
2003-03-08 03:20:32 +00:00
|
|
|
PlayerPostThink ();
|
|
|
|
BotAI ();
|
2003-02-18 23:11:05 +00:00
|
|
|
self.dmg_take = self.dmg_save = 0;
|
|
|
|
|
|
|
|
};
|
2003-03-05 21:12:56 +00:00
|
|
|
|
2003-02-18 23:11:05 +00:00
|
|
|
// Avoid calling BotAI and the physics at the same time
|
|
|
|
// Can trip the runaway loop counter
|
|
|
|
void() SV_FlyMove =
|
|
|
|
{
|
|
|
|
// This is nothing like the Quake function.
|
|
|
|
|
2003-03-04 18:26:17 +00:00
|
|
|
if (self.phys_obj == NIL) {
|
2003-03-08 03:20:32 +00:00
|
|
|
self.phys_obj = find(NIL, classname, "phys_obj");
|
2003-03-04 18:26:17 +00:00
|
|
|
while (self.phys_obj.owner != self) {
|
2003-03-08 03:20:32 +00:00
|
|
|
self.phys_obj = find (self.phys_obj, classname, "phys_obj");
|
2003-03-04 18:26:17 +00:00
|
|
|
if (self.phys_obj == NIL) {
|
2003-03-08 03:20:32 +00:00
|
|
|
error ("No physics entity spawned!\nMake sure BotInit was "
|
|
|
|
"called\n");
|
2003-02-18 23:11:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-02-24 16:05:25 +00:00
|
|
|
setmodel (self.phys_obj, NIL);
|
2003-02-18 23:11:05 +00:00
|
|
|
self.phys_obj.movetype = MOVETYPE_STEP;
|
|
|
|
|
|
|
|
self.phys_obj.solid = SOLID_TRIGGER;
|
|
|
|
self.phys_obj.touch = RemoveThud;
|
2003-03-08 03:20:32 +00:00
|
|
|
setsize (self.phys_obj, self.mins, self.maxs);
|
2003-02-18 23:11:05 +00:00
|
|
|
self.phys_obj.dest2 = self.phys_obj.origin = self.origin;
|
|
|
|
self.phys_obj.watertype = 0;
|
|
|
|
self.phys_obj.movedir = self.origin + real_frametime * self.velocity;
|
|
|
|
self.phys_obj.dest1 = self.phys_obj.velocity = self.velocity;
|
2003-03-08 03:20:32 +00:00
|
|
|
self.phys_obj.velocity_z += sv_gravity * real_frametime;
|
2003-02-18 23:11:05 +00:00
|
|
|
self.phys_obj.flags = 0;
|
|
|
|
self.phys_obj.think = PostPhysics;
|
|
|
|
self.phys_obj.nextthink = time;
|
|
|
|
};
|
|
|
|
|
|
|
|
void() SV_Physics_Toss =
|
|
|
|
{
|
2003-03-08 03:20:32 +00:00
|
|
|
if (!SV_RunThink ())
|
2003-02-18 23:11:05 +00:00
|
|
|
return;
|
2003-03-04 18:26:17 +00:00
|
|
|
if (self.flags & FL_ONGROUND) {
|
2003-02-18 23:11:05 +00:00
|
|
|
self.velocity = '0 0 0';
|
2003-03-08 03:20:32 +00:00
|
|
|
BotAI ();
|
2003-02-18 23:11:05 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (self.movetype != MOVETYPE_FLY)
|
2003-03-08 03:20:32 +00:00
|
|
|
SV_AddGravity (1);
|
|
|
|
self.angles += real_frametime * self.avelocity;
|
|
|
|
SV_FlyMove ();
|
2003-02-18 23:11:05 +00:00
|
|
|
|
|
|
|
};
|
2003-03-05 21:12:56 +00:00
|
|
|
|
2003-03-08 03:20:32 +00:00
|
|
|
void ()
|
|
|
|
SV_Physics_Client =
|
2003-02-18 23:11:05 +00:00
|
|
|
{
|
2003-03-08 03:20:32 +00:00
|
|
|
PlayerPreThink ();
|
2003-03-05 21:12:56 +00:00
|
|
|
switch (self.movetype) {
|
|
|
|
case MOVETYPE_NONE:
|
2003-03-08 03:20:32 +00:00
|
|
|
if (!SV_RunThink ())
|
2003-02-18 23:11:05 +00:00
|
|
|
return;
|
2003-03-08 03:20:32 +00:00
|
|
|
PlayerPostThink ();
|
|
|
|
BotAI ();
|
2003-03-05 21:12:56 +00:00
|
|
|
break;
|
|
|
|
case MOVETYPE_WALK:
|
|
|
|
case MOVETYPE_STEP:
|
2003-03-08 03:20:32 +00:00
|
|
|
if (!SV_RunThink ())
|
2003-02-18 23:11:05 +00:00
|
|
|
return;
|
2003-03-08 03:20:32 +00:00
|
|
|
if (!(SV_CheckWater ()) && (!(self.flags & FL_WATERJUMP)))
|
|
|
|
SV_AddGravity (1);
|
|
|
|
SV_FlyMove ();
|
2003-03-05 21:12:56 +00:00
|
|
|
break;
|
|
|
|
case MOVETYPE_TOSS:
|
|
|
|
case MOVETYPE_BOUNCE:
|
2003-03-08 03:20:32 +00:00
|
|
|
SV_Physics_Toss ();
|
2003-03-05 21:12:56 +00:00
|
|
|
break;
|
|
|
|
case MOVETYPE_FLY:
|
2003-03-08 03:20:32 +00:00
|
|
|
if (!SV_RunThink ())
|
2003-02-18 23:11:05 +00:00
|
|
|
return;
|
2003-03-08 03:20:32 +00:00
|
|
|
SV_FlyMove ();
|
2003-03-05 21:12:56 +00:00
|
|
|
break;
|
|
|
|
case MOVETYPE_NOCLIP:
|
2003-03-08 03:20:32 +00:00
|
|
|
if (!SV_RunThink ())
|
2003-02-18 23:11:05 +00:00
|
|
|
return;
|
2003-03-08 03:20:32 +00:00
|
|
|
self.origin += real_frametime * self.velocity;
|
2003-02-18 23:11:05 +00:00
|
|
|
|
2003-03-08 03:20:32 +00:00
|
|
|
PlayerPostThink ();
|
|
|
|
BotAI ();
|
2003-03-05 21:12:56 +00:00
|
|
|
break;
|
|
|
|
default:
|
2003-02-18 23:11:05 +00:00
|
|
|
error ("SV_Physics_Client: Bad Movetype (BOT)");
|
2003-03-05 21:12:56 +00:00
|
|
|
break;
|
|
|
|
}
|
2003-02-18 23:11:05 +00:00
|
|
|
};
|