2003-02-18 23:11:05 +00:00
|
|
|
/***********************************************
|
|
|
|
* *
|
|
|
|
* FrikBot Movement AI *
|
|
|
|
* "The slightly better movement AI" *
|
|
|
|
* *
|
|
|
|
***********************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
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-08-18 06:30:05 +00:00
|
|
|
integer bot_move_linker;
|
|
|
|
|
2003-08-22 14:52:34 +00:00
|
|
|
float (integer keys, integer key) key_state =
|
|
|
|
{
|
|
|
|
return ((keys & key) != 0) ? 1.0 : 0.0;
|
|
|
|
};
|
|
|
|
|
2003-09-04 07:44:47 +00:00
|
|
|
void (vector start, vector mins, vector maxs, vector end, float type,
|
|
|
|
entity passent) checkmove = #98; // Wrapper around SV_Move.
|
|
|
|
|
|
|
|
|
2003-07-23 06:35:39 +00:00
|
|
|
@implementation Bot (Move)
|
2003-08-22 14:52:34 +00:00
|
|
|
|
|
|
|
-(void)sendMove
|
|
|
|
{
|
|
|
|
local vector movevect = '0 0 0';
|
|
|
|
local float anglespeed;
|
|
|
|
local vector view;
|
2003-09-04 07:44:47 +00:00
|
|
|
local vector probe, start;
|
|
|
|
local integer obstructed = 0;
|
2003-08-22 14:52:34 +00:00
|
|
|
|
|
|
|
movevect.y += (350 * key_state (keys, KEY_MOVERIGHT));
|
|
|
|
movevect.y -= (350 * key_state (keys, KEY_MOVELEFT));
|
|
|
|
|
|
|
|
movevect.x += (200 * key_state (keys, KEY_MOVEFORWARD));
|
|
|
|
movevect.x -= (200 * key_state (keys, KEY_MOVEBACK));
|
|
|
|
|
|
|
|
movevect.z += (200 * key_state (keys, KEY_MOVEUP));
|
|
|
|
movevect.z -= (200 * key_state (keys, KEY_MOVEDOWN));
|
|
|
|
|
|
|
|
if (!(b_aiflags & AI_PRECISION))
|
|
|
|
movevect *= 2;
|
|
|
|
|
|
|
|
if (b_skill != 2) {
|
|
|
|
// use mouse emulation
|
|
|
|
anglespeed = 1.5 * real_frametime;
|
|
|
|
// 1.5 is the default cl_anglespeedkey & bot always has +speed
|
|
|
|
ent.v_angle_y += anglespeed * key_state (keys, KEY_LOOKLEFT) * 140;
|
|
|
|
// 140 is default cl_yawspeed
|
|
|
|
ent.v_angle_y -= anglespeed * key_state (keys, KEY_LOOKRIGHT) * 140;
|
|
|
|
// 140 is default cl_yawspeed
|
|
|
|
ent.v_angle_x -= anglespeed * key_state (keys, KEY_LOOKUP) * 150;
|
|
|
|
// 150 is default cl_pitchspeed
|
|
|
|
ent.v_angle_x += anglespeed * key_state (keys, KEY_LOOKDOWN) * 150;
|
|
|
|
// 150 is default cl_pitchspeed
|
|
|
|
} else {
|
|
|
|
view.x = angcomp (b_angle.x, ent.v_angle_x);
|
|
|
|
view.y = angcomp (b_angle.y, ent.v_angle_y);
|
|
|
|
view.z = 0;
|
|
|
|
if (vlen (view) > 30) {
|
|
|
|
mouse_emu += (view * 30);
|
|
|
|
if (vlen(mouse_emu) > 180)
|
|
|
|
mouse_emu = normalize (mouse_emu) * 180;
|
|
|
|
} else
|
|
|
|
mouse_emu = view * (1 / real_frametime);
|
|
|
|
ent.v_angle += mouse_emu * real_frametime;
|
|
|
|
|
|
|
|
|
2003-09-04 07:44:47 +00:00
|
|
|
}
|
|
|
|
start = ent.origin;
|
|
|
|
//start.z += 16; // step offset
|
|
|
|
makevectors (ent.v_angle);
|
|
|
|
probe = v_forward * movevect.x + v_right * movevect.y + ent.velocity;
|
|
|
|
probe.z = 0;
|
|
|
|
if (probe) {
|
|
|
|
probe = normalize (probe);
|
|
|
|
probe = probe * 32 + start;
|
|
|
|
checkmove (start, ent.mins, ent.maxs, probe, 1, ent);
|
|
|
|
if (trace_fraction != 1) {
|
|
|
|
obstructed = 1;
|
|
|
|
probe = (probe - start);
|
|
|
|
if (trace_fraction)
|
|
|
|
probe *= trace_fraction;
|
|
|
|
else
|
|
|
|
probe = normalize (probe);
|
|
|
|
}
|
2003-08-22 14:52:34 +00:00
|
|
|
}
|
|
|
|
//dprint (itos (buttons) + " " + itos (impulse) + "\n");
|
2003-09-04 07:44:47 +00:00
|
|
|
//dprint (ftos (real_frametime) + "\n");
|
2003-08-22 14:52:34 +00:00
|
|
|
SV_UserCmd (ent, real_frametime, ent.v_angle, movevect, buttons, impulse);
|
|
|
|
impulse = 0;
|
2003-09-04 07:44:47 +00:00
|
|
|
if (obstructed)
|
|
|
|
[self obstructed:probe:FALSE];
|
2003-08-22 14:52:34 +00:00
|
|
|
}
|
|
|
|
|
2003-07-23 06:35:39 +00:00
|
|
|
- (void) jump
|
2003-02-18 23:11:05 +00:00
|
|
|
{
|
|
|
|
// TODO check for precision, etc.
|
2003-08-21 03:53:15 +00:00
|
|
|
buttons |= 4;
|
2003-07-23 06:35:39 +00:00
|
|
|
}
|
2003-02-18 23:11:05 +00:00
|
|
|
|
2003-08-18 16:48:53 +00:00
|
|
|
- (integer) canRJ
|
2003-02-18 23:11:05 +00:00
|
|
|
{
|
|
|
|
// this returns true of the bot can rocket/superjump/hook
|
|
|
|
// if your mod doesn't have an RL you can just return FALSE all the time
|
|
|
|
// if it has a hook or some other means for the bot to get to high places
|
|
|
|
// you can check here for that capability
|
|
|
|
|
|
|
|
// am I dumb?
|
2003-07-23 06:35:39 +00:00
|
|
|
if (b_skill == 0)
|
2003-02-18 23:11:05 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
// quad = bad
|
2003-07-31 18:36:19 +00:00
|
|
|
if (ent.items & IT_QUAD)
|
2003-02-18 23:11:05 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
// do I have rockets & RL?
|
2003-07-31 18:36:19 +00:00
|
|
|
if (!((ent.items & IT_ROCKET_LAUNCHER) && (ent.ammo_rockets > 0)))
|
2003-02-18 23:11:05 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
// do I have pent?
|
2003-07-31 18:36:19 +00:00
|
|
|
if (ent.items & IT_INVULNERABILITY)
|
2003-02-18 23:11:05 +00:00
|
|
|
return TRUE;
|
|
|
|
|
2003-07-23 06:35:39 +00:00
|
|
|
if (ent.health > 50)
|
2003-02-18 23:11:05 +00:00
|
|
|
return TRUE;
|
|
|
|
else
|
|
|
|
return FALSE;
|
2003-07-23 06:35:39 +00:00
|
|
|
}
|
2003-02-18 23:11:05 +00:00
|
|
|
|
2003-08-18 16:48:53 +00:00
|
|
|
- (integer) recognizePlat: (integer) flag
|
2003-02-18 23:11:05 +00:00
|
|
|
{
|
2003-08-18 06:30:05 +00:00
|
|
|
local integer ret;
|
|
|
|
|
2003-08-18 16:48:53 +00:00
|
|
|
ret = [super recognizePlat:flag];
|
2003-08-18 06:30:05 +00:00
|
|
|
if (ret) {
|
2003-03-04 18:26:17 +00:00
|
|
|
if (flag) {
|
|
|
|
// afect bot movement too
|
2003-07-23 06:35:39 +00:00
|
|
|
if (keys & KEY_MOVEUP) {
|
2003-02-18 23:11:05 +00:00
|
|
|
if (trace_ent.velocity_z > 0)
|
2003-07-31 16:57:01 +00:00
|
|
|
keys &= ~KEY_MOVE;
|
2003-07-23 06:35:39 +00:00
|
|
|
} else if (keys & KEY_MOVEDOWN) {
|
2003-02-18 23:11:05 +00:00
|
|
|
if (trace_ent.velocity_z < 0)
|
2003-07-31 16:57:01 +00:00
|
|
|
keys &= ~KEY_MOVE;
|
2003-02-18 23:11:05 +00:00
|
|
|
}
|
|
|
|
}
|
2003-08-18 06:30:05 +00:00
|
|
|
}
|
|
|
|
return ret;
|
2003-07-23 06:35:39 +00:00
|
|
|
}
|
2003-02-18 23:11:05 +00:00
|
|
|
|
2003-07-23 06:35:39 +00:00
|
|
|
-(integer)keysForDir: (vector) sdir
|
2003-02-18 23:11:05 +00:00
|
|
|
{
|
2003-07-23 06:35:39 +00:00
|
|
|
local integer outkeys;
|
|
|
|
local float tang;
|
2003-03-08 03:20:32 +00:00
|
|
|
local vector keydir;
|
|
|
|
|
2003-02-18 23:11:05 +00:00
|
|
|
outkeys = 0;
|
2003-03-04 18:26:17 +00:00
|
|
|
if (sdir_x || sdir_y) {
|
2003-03-08 03:20:32 +00:00
|
|
|
// Everything is tested against 60 degrees, this allows the bot to
|
|
|
|
// overlap the keys 30 degrees on each diagonal 45 degrees might look
|
|
|
|
// more realistic
|
2003-02-18 23:11:05 +00:00
|
|
|
|
2003-03-08 03:20:32 +00:00
|
|
|
keydir = vectoangles (sdir);
|
2003-07-23 06:35:39 +00:00
|
|
|
tang = angcomp (keydir_y, ent.v_angle_y);
|
2003-02-18 23:11:05 +00:00
|
|
|
if ((tang <= 150) && (tang >= 30))
|
2003-03-08 03:20:32 +00:00
|
|
|
outkeys |= KEY_MOVELEFT;
|
2003-02-18 23:11:05 +00:00
|
|
|
else if ((tang >= -150) && (tang <= -30))
|
2003-03-08 03:20:32 +00:00
|
|
|
outkeys |= KEY_MOVERIGHT;
|
2003-02-18 23:11:05 +00:00
|
|
|
if (fabs(tang) <= 60)
|
2003-03-08 03:20:32 +00:00
|
|
|
outkeys |= KEY_MOVEFORWARD;
|
2003-02-18 23:11:05 +00:00
|
|
|
else if (fabs(tang) >= 120)
|
2003-03-08 03:20:32 +00:00
|
|
|
outkeys |= KEY_MOVEBACK;
|
2003-02-18 23:11:05 +00:00
|
|
|
}
|
|
|
|
if (sdir_z > 0.7)
|
2003-03-08 03:20:32 +00:00
|
|
|
outkeys |= KEY_MOVEUP;
|
2003-02-18 23:11:05 +00:00
|
|
|
else if (sdir_z < 0.7)
|
2003-03-08 03:20:32 +00:00
|
|
|
outkeys |= KEY_MOVEDOWN;
|
2003-02-18 23:11:05 +00:00
|
|
|
return outkeys;
|
2003-07-23 06:35:39 +00:00
|
|
|
}
|
2003-02-18 23:11:05 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
frik_obstructed
|
|
|
|
|
|
|
|
Bot has hit a ledge or wall that he should
|
|
|
|
manuever around.
|
|
|
|
*/
|
2003-07-23 06:35:39 +00:00
|
|
|
-(void)obstructed: (vector) whichway : (integer) danger
|
2003-02-18 23:11:05 +00:00
|
|
|
{
|
|
|
|
local float dist;
|
2003-02-21 06:01:33 +00:00
|
|
|
local vector disway, org;
|
2003-03-08 03:20:32 +00:00
|
|
|
|
2003-02-18 23:11:05 +00:00
|
|
|
// TODO: something
|
2003-07-23 06:35:39 +00:00
|
|
|
if (b_aiflags & AI_BLIND)
|
2003-02-18 23:11:05 +00:00
|
|
|
return;
|
|
|
|
|
2003-03-04 18:26:17 +00:00
|
|
|
if (danger) {
|
2003-07-23 06:35:39 +00:00
|
|
|
b_aiflags |= AI_DANGER;
|
|
|
|
keys = [self keysForDir:'0 0 0' - whichway];
|
2003-02-18 23:11:05 +00:00
|
|
|
}
|
2003-07-23 06:35:39 +00:00
|
|
|
if (b_aiflags & AI_PRECISION)
|
2003-02-18 23:11:05 +00:00
|
|
|
return;
|
|
|
|
|
2003-09-04 07:44:47 +00:00
|
|
|
disway_z = 0;
|
2003-02-18 23:11:05 +00:00
|
|
|
|
2003-07-23 22:44:15 +00:00
|
|
|
if (targets[0]) {
|
2003-07-23 06:35:39 +00:00
|
|
|
if (b_aiflags & AI_OBSTRUCTED) {
|
|
|
|
if (!(b_aiflags & AI_DANGER)) {
|
|
|
|
b_aiflags &= ~AI_OBSTRUCTED;
|
2003-02-18 23:11:05 +00:00
|
|
|
return;
|
2003-03-04 18:26:17 +00:00
|
|
|
} else if (!danger)
|
2003-02-18 23:11:05 +00:00
|
|
|
return;
|
|
|
|
}
|
2003-09-04 07:44:47 +00:00
|
|
|
org = [targets[0] realorigin];
|
2003-07-23 06:35:39 +00:00
|
|
|
obs_dir = whichway;
|
2003-02-18 23:11:05 +00:00
|
|
|
disway_x = whichway_y * -1;
|
|
|
|
disway_y = whichway_x;
|
2003-07-23 06:35:39 +00:00
|
|
|
dist = vlen (org - (ent.origin + disway));
|
2003-02-18 23:11:05 +00:00
|
|
|
disway_x = whichway_y;
|
|
|
|
disway_y = whichway_x * -1;
|
2003-07-23 06:35:39 +00:00
|
|
|
wallhug = (vlen (org - (ent.origin + disway)) > dist);
|
|
|
|
b_aiflags |= AI_OBSTRUCTED;
|
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
|
|
|
disway_x = whichway_y * -1;
|
|
|
|
disway_y = whichway_x;
|
2003-07-23 06:35:39 +00:00
|
|
|
dist = vlen (disway - obs_dir);
|
2003-02-18 23:11:05 +00:00
|
|
|
disway_x = whichway_y;
|
|
|
|
disway_y = whichway_x * -1;
|
2003-07-23 06:35:39 +00:00
|
|
|
wallhug = (vlen (disway - obs_dir) < dist);
|
|
|
|
obs_dir = whichway;
|
2003-02-18 23:11:05 +00:00
|
|
|
|
2003-07-23 06:35:39 +00:00
|
|
|
b_aiflags |= AI_OBSTRUCTED;
|
2003-02-18 23:11:05 +00:00
|
|
|
}
|
2003-07-23 06:35:39 +00:00
|
|
|
}
|
2003-02-18 23:11:05 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
frik_obstacles
|
|
|
|
|
|
|
|
Detects small bumps the bot needs to jump over
|
|
|
|
or ledges the bot should avoid falling in.
|
|
|
|
Also responsible for jumping gaps.
|
|
|
|
*/
|
2003-07-23 06:35:39 +00:00
|
|
|
-(void)obstacles
|
2003-02-18 23:11:05 +00:00
|
|
|
{
|
|
|
|
local vector start, stop, ang;
|
|
|
|
local float test, conts, dist, hgt;
|
|
|
|
|
2003-07-23 06:35:39 +00:00
|
|
|
if (!(ent.flags & FL_ONGROUND))
|
2003-02-18 23:11:05 +00:00
|
|
|
return;
|
2003-07-23 06:35:39 +00:00
|
|
|
if (b_aiflags & AI_BLIND)
|
2003-02-18 23:11:05 +00:00
|
|
|
return;
|
|
|
|
|
2003-07-23 06:35:39 +00:00
|
|
|
ang = normalize(ent.velocity);
|
2003-02-18 23:11:05 +00:00
|
|
|
ang_z = 0;
|
2003-07-23 06:35:39 +00:00
|
|
|
start = ent.origin + ang * 32; // ahem
|
|
|
|
start_z = ent.origin_z + ent.maxs_z;
|
2003-02-18 23:11:05 +00:00
|
|
|
stop = start;
|
2003-07-23 06:35:39 +00:00
|
|
|
stop_z = ent.origin_z + ent.mins_z;
|
|
|
|
traceline (start, stop - '0 0 256', TRUE, ent);
|
2003-02-18 23:11:05 +00:00
|
|
|
if (trace_allsolid || trace_startsolid)
|
|
|
|
return;
|
|
|
|
hgt = trace_endpos_z - stop_z;
|
|
|
|
|
2003-03-04 18:26:17 +00:00
|
|
|
if (hgt > 18) {
|
2003-07-23 06:35:39 +00:00
|
|
|
[self jump];
|
2003-02-18 23:11:05 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (hgt >= 0)
|
|
|
|
return;
|
|
|
|
|
2003-03-08 03:20:32 +00:00
|
|
|
conts = pointcontents (trace_endpos + '0 0 4');
|
2003-02-18 23:11:05 +00:00
|
|
|
start = stop - '0 0 8';
|
|
|
|
stop = start + ang * 256;
|
2003-07-23 06:35:39 +00:00
|
|
|
traceline (start, stop, TRUE, ent);
|
2003-02-18 23:11:05 +00:00
|
|
|
test = vlen(trace_endpos - start);
|
|
|
|
if (test <= 20)
|
|
|
|
return; // it's a walkable gap, do nothing
|
2003-07-23 06:35:39 +00:00
|
|
|
ang_x = ent.velocity_y * -1;
|
|
|
|
ang_y = ent.velocity_x;
|
2003-03-08 03:20:32 +00:00
|
|
|
ang = normalize (ang);
|
2003-07-23 06:35:39 +00:00
|
|
|
traceline (start - (ang * 10), start + (ang * 10), TRUE, ent);
|
2003-02-18 23:11:05 +00:00
|
|
|
if ((trace_fraction != 1) || trace_startsolid)
|
|
|
|
return; // gap is only 20 wide, walkable
|
2003-07-23 06:35:39 +00:00
|
|
|
ang = ent.velocity;
|
2003-02-18 23:11:05 +00:00
|
|
|
ang_z = 0;
|
2003-03-08 03:20:32 +00:00
|
|
|
dist = ((540 / sv_gravity) * vlen (ang))/* + 32*/;
|
2003-03-04 18:26:17 +00:00
|
|
|
if (test > dist) {
|
|
|
|
// I can't make it
|
|
|
|
if (conts < -3) {
|
|
|
|
// bad stuff down dare
|
2003-07-23 06:35:39 +00:00
|
|
|
[self obstructed: ang :TRUE];
|
2003-02-18 23:11:05 +00:00
|
|
|
return;
|
2003-03-04 18:26:17 +00:00
|
|
|
} else {
|
2003-07-23 22:44:15 +00:00
|
|
|
if (targets[0]) {
|
2003-08-18 06:30:05 +00:00
|
|
|
stop = [targets[0] realorigin];
|
2003-07-23 06:35:39 +00:00
|
|
|
if ((stop_z - ent.origin_z) < -32)
|
2003-02-18 23:11:05 +00:00
|
|
|
return; // safe to fall
|
|
|
|
}
|
2003-07-23 06:35:39 +00:00
|
|
|
[self obstructed: ang :FALSE];
|
2003-02-18 23:11:05 +00:00
|
|
|
return;
|
|
|
|
}
|
2003-03-04 18:26:17 +00:00
|
|
|
} else {
|
2003-02-18 23:11:05 +00:00
|
|
|
ang = normalize(ang);
|
|
|
|
//look for a ledge
|
2003-07-23 06:35:39 +00:00
|
|
|
traceline (ent.origin, ent.origin + (ang * (test + 20)), TRUE, ent);
|
2003-03-04 18:26:17 +00:00
|
|
|
if (trace_fraction != 1) {
|
|
|
|
if (conts < -3) {
|
|
|
|
// bad stuff down dare
|
2003-07-23 06:35:39 +00:00
|
|
|
[self obstructed: ang :TRUE];
|
2003-02-18 23:11:05 +00:00
|
|
|
return;
|
2003-03-04 18:26:17 +00:00
|
|
|
} else {
|
2003-07-23 22:44:15 +00:00
|
|
|
if (targets[0]) {
|
2003-08-18 06:30:05 +00:00
|
|
|
stop = [targets[0] realorigin];
|
2003-07-23 06:35:39 +00:00
|
|
|
if ((stop_z - ent.origin_z) < -32)
|
2003-02-18 23:11:05 +00:00
|
|
|
return; // safe to fall
|
|
|
|
}
|
2003-07-23 06:35:39 +00:00
|
|
|
[self obstructed: ang :FALSE];
|
2003-02-18 23:11:05 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-07-23 22:44:15 +00:00
|
|
|
if (targets[0]) {
|
2003-02-18 23:11:05 +00:00
|
|
|
// getting furter away from my target?
|
2003-08-18 06:30:05 +00:00
|
|
|
test = vlen ([targets[0] origin] - (ang + ent.origin));
|
|
|
|
if (test > vlen ([targets[0] origin] - ent.origin)) {
|
2003-03-04 18:26:17 +00:00
|
|
|
if (conts < -3) {
|
|
|
|
// bad stuff down dare
|
2003-07-23 06:35:39 +00:00
|
|
|
[self obstructed: ang :TRUE];
|
2003-02-18 23:11:05 +00:00
|
|
|
return;
|
2003-03-04 18:26:17 +00:00
|
|
|
} else {
|
2003-07-23 06:35:39 +00:00
|
|
|
[self obstructed: ang :FALSE];
|
2003-02-18 23:11:05 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-03-04 18:26:17 +00:00
|
|
|
if (hgt < -18) {
|
2003-07-23 22:44:15 +00:00
|
|
|
if (targets[0]) {
|
2003-08-18 06:30:05 +00:00
|
|
|
stop = [targets[0] realorigin];
|
2003-07-23 06:35:39 +00:00
|
|
|
if ((stop_z - ent.origin_z) < -32)
|
2003-02-18 23:11:05 +00:00
|
|
|
return; // safe to fall
|
|
|
|
}
|
2003-07-23 06:35:39 +00:00
|
|
|
[self jump];
|
2003-02-18 23:11:05 +00:00
|
|
|
}
|
|
|
|
// go for it
|
|
|
|
|
2003-07-23 06:35:39 +00:00
|
|
|
}
|
2003-02-18 23:11:05 +00:00
|
|
|
|
|
|
|
/*
|
2003-03-08 03:20:32 +00:00
|
|
|
After frik_obstructed, the bot uses the
|
2003-02-18 23:11:05 +00:00
|
|
|
following funtion to move "around" the obstacle
|
|
|
|
|
|
|
|
I have no idea how well it will work
|
|
|
|
*/
|
2003-08-18 16:48:53 +00:00
|
|
|
-(void)dodgeObstruction
|
2003-02-18 23:11:05 +00:00
|
|
|
{
|
2003-02-21 06:01:33 +00:00
|
|
|
local vector way, org;
|
2003-02-18 23:11:05 +00:00
|
|
|
local float oflags, yaw;
|
|
|
|
|
2003-07-23 06:35:39 +00:00
|
|
|
if (!(b_aiflags & AI_OBSTRUCTED))
|
2003-02-18 23:11:05 +00:00
|
|
|
return;
|
2003-07-23 06:35:39 +00:00
|
|
|
if ((b_aiflags & (AI_BLIND | AI_PRECISION))
|
|
|
|
|| !(ent.flags & FL_ONGROUND)) {
|
|
|
|
b_aiflags &= ~AI_OBSTRUCTED;
|
2003-02-18 23:11:05 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// perform a walkmove check to see if the obs_dir is still obstructed
|
|
|
|
// walkmove is less forgiving than frik_obstacles, so I dunno
|
|
|
|
// how well this will work
|
|
|
|
|
2003-07-23 06:35:39 +00:00
|
|
|
oflags = ent.flags;
|
|
|
|
org = ent.origin;
|
2003-02-18 23:11:05 +00:00
|
|
|
|
2003-07-23 06:35:39 +00:00
|
|
|
yaw = vectoyaw (obs_dir);
|
2003-03-08 03:20:32 +00:00
|
|
|
if (walkmove (yaw, 32))
|
2003-07-23 06:35:39 +00:00
|
|
|
b_aiflags &= ~AI_OBSTRUCTED;
|
2003-03-04 18:26:17 +00:00
|
|
|
else {
|
2003-07-23 06:35:39 +00:00
|
|
|
if (b_aiflags & AI_DANGER) {
|
|
|
|
way = '0 0 0' - obs_dir;
|
|
|
|
} else if (wallhug) {
|
2003-07-24 18:23:13 +00:00
|
|
|
way.x = obs_dir.y * -1;
|
|
|
|
way.y = obs_dir.x;
|
2003-03-04 18:26:17 +00:00
|
|
|
} else {
|
2003-07-24 18:23:13 +00:00
|
|
|
way.x = obs_dir.y;
|
|
|
|
way.y = obs_dir.x * -1;
|
2003-02-18 23:11:05 +00:00
|
|
|
}
|
2003-02-21 06:01:33 +00:00
|
|
|
way_z = 0;
|
2003-07-31 16:57:01 +00:00
|
|
|
keys &= ~KEY_MOVE;
|
2003-07-23 06:35:39 +00:00
|
|
|
keys |= [self keysForDir: way];
|
2003-02-18 23:11:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// fix the bot
|
2003-07-23 06:35:39 +00:00
|
|
|
ent.origin = org;
|
|
|
|
ent.flags = oflags;
|
|
|
|
}
|
2003-02-18 23:11:05 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
movetogoal and walkmove replacements
|
|
|
|
|
|
|
|
blah
|
|
|
|
*/
|
2003-07-23 06:35:39 +00:00
|
|
|
-(void) movetogoal
|
2003-02-18 23:11:05 +00:00
|
|
|
{
|
2003-02-18 23:12:03 +00:00
|
|
|
local vector way;
|
2003-02-18 23:11:05 +00:00
|
|
|
local float g;
|
|
|
|
|
2003-07-23 22:44:15 +00:00
|
|
|
if (targets[0] == NIL) {
|
2003-08-21 20:39:04 +00:00
|
|
|
makevectors(ent.v_angle);
|
2003-07-23 06:35:39 +00:00
|
|
|
[self walkmove: v_forward];
|
2003-02-18 23:11:05 +00:00
|
|
|
return;
|
|
|
|
}
|
2003-08-18 06:30:05 +00:00
|
|
|
way = [targets[0] realorigin] - ent.origin;
|
2003-03-04 18:26:17 +00:00
|
|
|
if (vlen(way) < 25) {
|
2003-07-31 16:57:01 +00:00
|
|
|
keys &= ~KEY_MOVE;
|
2003-02-18 23:11:05 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-03-08 03:20:32 +00:00
|
|
|
way = normalize (way);
|
2003-07-31 16:57:01 +00:00
|
|
|
keys &= ~KEY_MOVE;
|
2003-07-23 06:35:39 +00:00
|
|
|
keys |= [self keysForDir: way];
|
2003-02-18 23:11:05 +00:00
|
|
|
|
2003-08-18 16:48:53 +00:00
|
|
|
[self dodgeObstruction];
|
|
|
|
[self recognizePlat: TRUE];
|
2003-02-18 23:11:05 +00:00
|
|
|
|
2003-07-23 06:35:39 +00:00
|
|
|
if (b_aiflags & AI_PRECISION) {
|
2003-08-21 20:39:04 +00:00
|
|
|
g = angcomp (ent.v_angle_x, b_angle.x);
|
2003-03-08 03:20:32 +00:00
|
|
|
if (fabs (g) > 10)
|
2003-07-31 16:57:01 +00:00
|
|
|
keys &= ~KEY_MOVE;
|
2003-08-21 20:39:04 +00:00
|
|
|
g = angcomp (ent.v_angle_y, b_angle.y);
|
2003-02-18 23:11:05 +00:00
|
|
|
if (fabs(g) > 10)
|
2003-07-31 16:57:01 +00:00
|
|
|
keys &= ~KEY_MOVE;
|
2003-02-18 23:11:05 +00:00
|
|
|
}
|
2003-07-23 06:35:39 +00:00
|
|
|
}
|
2003-02-18 23:11:05 +00:00
|
|
|
|
2003-07-23 06:35:39 +00:00
|
|
|
-(integer)walkmove: (vector) weird
|
2003-02-18 23:11:05 +00:00
|
|
|
{
|
|
|
|
// okay so it's not walkmove
|
|
|
|
// sue me
|
2003-07-31 16:57:01 +00:00
|
|
|
keys &= ~KEY_MOVE;
|
2003-07-23 06:35:39 +00:00
|
|
|
keys |= [self keysForDir: weird];
|
2003-02-18 23:11:05 +00:00
|
|
|
|
2003-08-18 16:48:53 +00:00
|
|
|
[self dodgeObstruction];
|
|
|
|
[self recognizePlat: TRUE];
|
2003-07-30 16:53:57 +00:00
|
|
|
if (b_aiflags & AI_OBSTRUCTED)
|
2003-02-18 23:11:05 +00:00
|
|
|
return FALSE;
|
|
|
|
else
|
|
|
|
return TRUE;
|
2003-07-23 06:35:39 +00:00
|
|
|
}
|
2003-02-18 23:11:05 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
|
|
|
The "hook" method of navigation. This nav
|
|
|
|
system is copyrighted 1999 by Ryan "Frika C"
|
|
|
|
Smith, keep that in mind when you steal it.
|
|
|
|
|
|
|
|
I brought this back because normal roaming
|
|
|
|
won't work - the bot gets distracted by it's
|
|
|
|
own waypoints.
|
|
|
|
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
|
|
|
*/
|
|
|
|
|
2003-07-23 06:35:39 +00:00
|
|
|
-(void)roam
|
2003-02-18 23:11:05 +00:00
|
|
|
{
|
|
|
|
local float loopcount, flag, dist;
|
2003-03-08 03:20:32 +00:00
|
|
|
local vector org, ang, org1;
|
2003-02-18 23:11:05 +00:00
|
|
|
|
|
|
|
loopcount = 26;
|
|
|
|
flag = FALSE;
|
2003-03-08 03:20:32 +00:00
|
|
|
while ((loopcount > 0) && !flag) {
|
|
|
|
loopcount--;
|
2003-07-23 06:35:39 +00:00
|
|
|
org = ent.origin + ent.view_ofs;
|
|
|
|
ang = ent.angles;
|
2003-03-08 03:20:32 +00:00
|
|
|
ang_y = frik_anglemod (ang_y - 90 + (180 * random ()));
|
2003-02-18 23:11:05 +00:00
|
|
|
ang_x = 0; // avoid upward sloping
|
2003-03-08 03:20:32 +00:00
|
|
|
makevectors (ang);
|
2003-07-23 06:35:39 +00:00
|
|
|
traceline (org, org + v_forward * 2300, TRUE, ent);
|
2003-03-04 18:26:17 +00:00
|
|
|
if (trace_fraction != 1) {
|
2003-02-18 23:11:05 +00:00
|
|
|
org1 = trace_endpos;
|
2003-03-08 03:20:32 +00:00
|
|
|
ang = normalize (trace_plane_normal);
|
2003-02-18 23:11:05 +00:00
|
|
|
ang_z = 0; // avoid upward sloping
|
2003-07-23 06:35:39 +00:00
|
|
|
traceline (org1, org1 + (ang * 2300), TRUE, ent);
|
2003-03-04 18:26:17 +00:00
|
|
|
if ((trace_fraction != 1) && (vlen(trace_endpos - org1) >= 64)) {
|
2003-02-18 23:11:05 +00:00
|
|
|
org = trace_endpos;
|
2003-07-23 06:35:39 +00:00
|
|
|
traceline (org, ent.origin + ent.view_ofs, TRUE, ent);
|
2003-03-04 18:26:17 +00:00
|
|
|
if (trace_fraction != 1) {
|
2003-03-08 03:20:32 +00:00
|
|
|
dist = vlen (org1 - org) /2;
|
2003-02-18 23:11:05 +00:00
|
|
|
org = org1 + (ang * dist);
|
2003-07-23 06:35:39 +00:00
|
|
|
traceline(org, org - '0 0 48', TRUE, ent);
|
2003-03-04 18:26:17 +00:00
|
|
|
if (trace_fraction != 1) {
|
2003-07-24 18:23:13 +00:00
|
|
|
[self spawnTempWaypoint:org];
|
2003-02-18 23:11:05 +00:00
|
|
|
flag = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-08-21 20:39:04 +00:00
|
|
|
b_angle.y = ent.v_angle_y + 10;
|
2003-07-23 06:35:39 +00:00
|
|
|
}
|
|
|
|
@end
|