From 7771777a1521202e6c3d4a5b50bcf878904cbc7e Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Wed, 12 Mar 2003 22:39:21 +0000 Subject: [PATCH] working on objectising frikbot :) --- fbxa/bot_phys.qc | 58 +++++++++++++++++++++++++++++++++++++++++++++++ fbxa/libfrikbot.h | 13 +++++++---- 2 files changed, 67 insertions(+), 4 deletions(-) diff --git a/fbxa/bot_phys.qc b/fbxa/bot_phys.qc index 7b1d8e9..ee587ae 100644 --- a/fbxa/bot_phys.qc +++ b/fbxa/bot_phys.qc @@ -61,6 +61,64 @@ float(float key) CL_KeyState = return ((self.keys & key) > 0) ? 1.0 : 0.0; }; +float (integer keys, integer key) key_state = +{ + return ((keys & key) != 0) ? 1.0 : 0.0; +}; + +@implementation Bot (Physics) + +-(void)sendMove +{ + local vector movevect = '0 0 0'; + local float anglespeed; + local vector view; + + if (keys != oldkeys) { + 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 + v_angle.y += anglespeed * key_state (keys, KEY_LOOKLEFT) * 140; + // 140 is default cl_yawspeed + v_angle.y -= anglespeed * key_state (keys, KEY_LOOKRIGHT) * 140; + // 140 is default cl_yawspeed + v_angle.x -= anglespeed * key_state (keys, KEY_LOOKUP) * 150; + // 150 is default cl_pitchspeed + v_angle.x += anglespeed * key_state (keys, KEY_LOOKDOWN) * 150; + // 150 is default cl_pitchspeed + } else { + view.x = angcomp (b_angle.x, v_angle.x); + view.y = angcomp (b_angle.y, 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); + v_angle += mouse_emu * real_frametime; + + + } + oldkeys = keys; + SV_UserCmd (ent, real_frametime, v_angle, movevect, buttons, impulse); +} +@end + void() CL_KeyMove = // CL_BaseMove + CL_AdjustAngles { local float anglespeed; diff --git a/fbxa/libfrikbot.h b/fbxa/libfrikbot.h index f98ce23..b0dd167 100644 --- a/fbxa/libfrikbot.h +++ b/fbxa/libfrikbot.h @@ -2,8 +2,12 @@ @interface Bot: Entity { - integer wallhug; integer keys, oldkeys; + integer buttons, impulse; + vector v_angle, b_angle; + vector mouse_emu; + + integer wallhug; integer ishuman; float b_frags; integer b_clientno; @@ -24,10 +28,7 @@ entity temp_way, last_way, current_way; entity [4] target; entity _next, _last; - vector b_angle; - vector mouse_emu; vector obs_dir; - vector movevect; vector b_dir; vector dyn_dest; vector punchangle; @@ -36,6 +37,10 @@ - (id) initWithEntity: (entity) e; @end +@interface Bot (Physics) +- (void)sendMove; +@end + #define FALSE 0 #define TRUE 1