mirror of
https://git.code.sf.net/p/quake/game-source
synced 2025-04-05 23:40:55 +00:00
split out Target implementation and kill a bunch of magic numbers
This commit is contained in:
parent
e1d70fa840
commit
27409dc710
9 changed files with 164 additions and 119 deletions
|
@ -19,6 +19,7 @@ libfrikbot_source = \
|
|||
map_dm5.qc \
|
||||
map_dm6.qc \
|
||||
chat.r \
|
||||
target.r \
|
||||
waypoint.r
|
||||
|
||||
libfrikbot_obj = $(addsuffix .o,$(basename $(libfrikbot_source)))
|
||||
|
|
|
@ -151,7 +151,7 @@ Bot has lost its target.
|
|||
|
||||
[self target_drop:targ];
|
||||
if (targ.ent.classname == "waypoint")
|
||||
targ.b_sound &= ~(ClientBitFlag (b_clientno));
|
||||
targ.b_sound &= ~b_clientflag;
|
||||
|
||||
// find a new route
|
||||
if (!success) {
|
||||
|
@ -161,17 +161,17 @@ Bot has lost its target.
|
|||
b_aiflags = 0;
|
||||
} else {
|
||||
if (targ.ent.classname == "item_artifact_invisibility")
|
||||
if (ent.items & 524288)
|
||||
if (ent.items & 524288) // IT_INVISIBILITY
|
||||
[self start_topic:3];
|
||||
|
||||
/*XXX
|
||||
if (targ.ent.flags & FL_ITEM) {
|
||||
/*XXX
|
||||
if (!targ.ent.model)
|
||||
targ.prev = NIL;
|
||||
else
|
||||
targ.prev = ent;
|
||||
*/
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
if (targ.ent.classname != "player")
|
||||
|
@ -227,12 +227,12 @@ removed.
|
|||
[self lost:targ :TRUE];
|
||||
} else if (targ.ent.teleport_time > time) {
|
||||
// try not to telefrag teammates
|
||||
keys &= 960;
|
||||
keys &= ~KEY_MOVE;
|
||||
} else if (vlen (targ.origin - ent.origin) < 128) {
|
||||
if (vlen (targ.origin - ent.origin) < 48)
|
||||
[self walkmove: ent.origin - targ.origin];
|
||||
else {
|
||||
keys &= 960;
|
||||
keys &= ~KEY_MOVE;
|
||||
[self start_topic:4];
|
||||
}
|
||||
ent.search_time = time + 5; // never time out
|
||||
|
@ -299,7 +299,7 @@ based b_aiflags.
|
|||
// wait is used by the ai to stop the bot until his search time expires / or route changes
|
||||
|
||||
if (b_aiflags & AI_WAIT)
|
||||
keys &= 960;
|
||||
keys &= ~KEY_MOVE;
|
||||
|
||||
if (b_aiflags & AI_DOORFLAG) {
|
||||
// was on a door when spawned
|
||||
|
@ -309,7 +309,7 @@ based b_aiflags.
|
|||
|
||||
if (b_aiflags & AI_DOOR_NO_OPEN) {
|
||||
if (newt.nextthink)
|
||||
keys &= 960; // wait until it closes
|
||||
keys &= ~KEY_MOVE; // wait until it closes
|
||||
else {
|
||||
[self lost:last_way :FALSE];
|
||||
}
|
||||
|
@ -361,13 +361,13 @@ based b_aiflags.
|
|||
// things, not just trains (door elevators come to mind)
|
||||
if (![ent.@this recognize_plat:FALSE]) {
|
||||
// if there is nothing there now
|
||||
keys &= 960;
|
||||
keys &= ~KEY_MOVE;
|
||||
} else {
|
||||
if ([self recognize_plat:FALSE]) {
|
||||
v = realorigin (trace_ent) + trace_ent.origin - ent.origin;
|
||||
v_z = 0;
|
||||
if (vlen (v) < 24)
|
||||
keys &= 960;
|
||||
keys &= ~KEY_MOVE;
|
||||
else {
|
||||
b_aiflags |= AI_PRECISION;
|
||||
keys = [self keysForDir:v];
|
||||
|
@ -381,7 +381,7 @@ based b_aiflags.
|
|||
v = ent.origin - realorigin (newt);
|
||||
v_z = 0;
|
||||
if (vlen (v) > 96)
|
||||
keys &= 960;
|
||||
keys &= ~KEY_MOVE;
|
||||
else
|
||||
[self walkmove:v];
|
||||
} else
|
||||
|
@ -693,14 +693,14 @@ generally making the bot look good.
|
|||
// The bot falls off ledges a lot because of "turning around"
|
||||
// so let the bot use instant turn around when not hunting a player
|
||||
if (b_skill == 3) {
|
||||
keys = keys & 63;
|
||||
keys &= ~KEY_LOOK;
|
||||
v_angle = b_angle;
|
||||
while (v_angle.x < -180)
|
||||
v_angle.x += 360;
|
||||
while (v_angle.x > 180)
|
||||
v_angle.x -= 360;
|
||||
} else if ((ent.enemy == NIL || ent.enemy.movetype == MOVETYPE_PUSH) && targets[0].classname != "player") {
|
||||
keys = keys & 63;
|
||||
keys &= ~KEY_LOOK;
|
||||
v_angle = b_angle;
|
||||
while (v_angle.x < -180)
|
||||
v_angle.x += 360;
|
||||
|
@ -710,7 +710,7 @@ generally making the bot look good.
|
|||
// skill 2 handled in bot_phys
|
||||
if (b_angle.x > 180)
|
||||
b_angle.x -= 360;
|
||||
keys = keys & 63;
|
||||
keys &= ~KEY_LOOK;
|
||||
|
||||
if (angcomp (b_angle.y, v_angle.y) > 10)
|
||||
keys = KEY_LOOKLEFT;
|
||||
|
|
|
@ -385,7 +385,7 @@ attacking an enemy.
|
|||
return;
|
||||
else if (mysz < 140)
|
||||
return;
|
||||
keys &= 960;
|
||||
keys &= ~KEY_MOVE;
|
||||
}
|
||||
}
|
||||
@end
|
||||
|
|
|
@ -88,10 +88,10 @@ this notice in its entirety.
|
|||
// afect bot movement too
|
||||
if (keys & KEY_MOVEUP) {
|
||||
if (trace_ent.velocity_z > 0)
|
||||
keys &= 960; // 960 is all view keys
|
||||
keys &= ~KEY_MOVE;
|
||||
} else if (keys & KEY_MOVEDOWN) {
|
||||
if (trace_ent.velocity_z < 0)
|
||||
keys &= 960;
|
||||
keys &= ~KEY_MOVE;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
|
@ -338,7 +338,7 @@ I have no idea how well it will work
|
|||
way.y = obs_dir.x * -1;
|
||||
}
|
||||
way_z = 0;
|
||||
keys &= 960;
|
||||
keys &= ~KEY_MOVE;
|
||||
keys |= [self keysForDir: way];
|
||||
}
|
||||
|
||||
|
@ -364,12 +364,12 @@ blah
|
|||
}
|
||||
way = realorigin(targets[0]) - ent.origin;
|
||||
if (vlen(way) < 25) {
|
||||
keys = keys & 960;
|
||||
keys &= ~KEY_MOVE;
|
||||
return;
|
||||
}
|
||||
|
||||
way = normalize (way);
|
||||
keys &= 960;
|
||||
keys &= ~KEY_MOVE;
|
||||
keys |= [self keysForDir: way];
|
||||
|
||||
[self dodge_obstruction];
|
||||
|
@ -378,10 +378,10 @@ blah
|
|||
if (b_aiflags & AI_PRECISION) {
|
||||
g = angcomp (v_angle.x, b_angle.x);
|
||||
if (fabs (g) > 10)
|
||||
keys &= 960;
|
||||
keys &= ~KEY_MOVE;
|
||||
g = angcomp (v_angle.y, b_angle.y);
|
||||
if (fabs(g) > 10)
|
||||
keys &= 960;
|
||||
keys &= ~KEY_MOVE;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -389,7 +389,7 @@ blah
|
|||
{
|
||||
// okay so it's not walkmove
|
||||
// sue me
|
||||
keys &= 960;
|
||||
keys &= ~KEY_MOVE;
|
||||
keys |= [self keysForDir: weird];
|
||||
|
||||
[self dodge_obstruction];
|
||||
|
|
|
@ -205,7 +205,7 @@ ClientFixRankings =
|
|||
btmp_bot = btmp.@this;
|
||||
if (!btmp_bot.ishuman) {
|
||||
if (players[cno])
|
||||
UpdateClient (btmp);
|
||||
[btmp_bot updateClient];
|
||||
}
|
||||
cno++;
|
||||
btmp = nextent (btmp);
|
||||
|
@ -264,29 +264,6 @@ signs on to the server.
|
|||
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||
*/
|
||||
|
||||
void (entity who)
|
||||
UpdateClient =
|
||||
{
|
||||
/* XXX
|
||||
local string bottomcolor = ftos (who.b_pants);
|
||||
local string topcolor = ftos (who.b_shirt);
|
||||
|
||||
dprint (who.netname);
|
||||
dprint ("\n");
|
||||
SV_SetPing (who, 100 * (3 - who.b_skill));
|
||||
SV_SetUserinfo (who, "\\bottomcolor\\" + bottomcolor
|
||||
+ "\\topcolor\\" + topcolor
|
||||
+ "\\team\\bot\\skin\\base\\name\\" + who.netname);
|
||||
// FIXME: do teams properly
|
||||
*/
|
||||
};
|
||||
|
||||
integer (integer clientno)
|
||||
ClientBitFlag =
|
||||
{
|
||||
return 1 << clientno;
|
||||
};
|
||||
|
||||
void(Waypoint e1, Waypoint e2, integer flag) DeveloperLightning = {};
|
||||
|
||||
// BotConnect and related functions. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||
|
@ -381,12 +358,13 @@ void () BotImpulses =
|
|||
return NIL;
|
||||
|
||||
b_clientno = cl_no + 1;
|
||||
b_clientflag = 1 << cl_no;
|
||||
|
||||
ent.colormap = (float) (cl_no + 1);
|
||||
|
||||
b_entertime = time;
|
||||
ent.team = b_pants + 1;
|
||||
UpdateClient (ent);
|
||||
[self updateClient];
|
||||
SetNewParms ();
|
||||
ishuman = 2;
|
||||
ClientConnect ();
|
||||
|
@ -473,4 +451,18 @@ void () BotImpulses =
|
|||
SV_ClientThink ();
|
||||
SV_Physics_Client ();
|
||||
}
|
||||
|
||||
-(void) updateClient
|
||||
{
|
||||
local string bottomcolor = ftos (b_pants);
|
||||
local string topcolor = ftos (b_shirt);
|
||||
|
||||
dprint (ent.netname);
|
||||
dprint ("\n");
|
||||
SV_SetPing (ent, 100 * (3 - b_skill));
|
||||
SV_SetUserinfo (ent, "\\bottomcolor\\" + bottomcolor
|
||||
+ "\\topcolor\\" + topcolor
|
||||
+ "\\team\\bot\\skin\\base\\name\\" + ent.netname);
|
||||
// FIXME: do teams properly
|
||||
}
|
||||
@end
|
||||
|
|
|
@ -46,35 +46,6 @@ this notice in its entirety.
|
|||
#include "Array.h"
|
||||
#include "List.h"
|
||||
|
||||
@static Array waypoint_array;
|
||||
@static entity waypoint_thinker;
|
||||
@static List waypoint_queue;
|
||||
@implementation Target
|
||||
|
||||
-(vector)realorigin
|
||||
{
|
||||
return realorigin (ent);
|
||||
}
|
||||
|
||||
-(integer)canSee:(Target)targ ignoring:(entity)ignore
|
||||
{
|
||||
local vector spot1, spot2;
|
||||
|
||||
spot1 = ent.origin;
|
||||
spot2 = [targ realorigin];
|
||||
|
||||
do {
|
||||
traceline (spot1, spot2, TRUE, ignore);
|
||||
spot1 = realorigin(trace_ent);
|
||||
ignore = trace_ent;
|
||||
} while ((trace_ent != world) && (trace_fraction != 1));
|
||||
if (trace_endpos == spot2)
|
||||
return TRUE;
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation Bot (Way)
|
||||
|
||||
/*
|
||||
|
@ -178,7 +149,7 @@ an object.
|
|||
local integer flag;
|
||||
local integer count, i;
|
||||
|
||||
flag = ClientBitFlag(b_clientno);
|
||||
flag = b_clientflag;
|
||||
dst = 100000;
|
||||
best = NIL;
|
||||
count = [waypoint_array count];
|
||||
|
@ -229,7 +200,7 @@ different bot.
|
|||
return;
|
||||
}
|
||||
|
||||
flag = ClientBitFlag(b_clientno);
|
||||
flag = b_clientflag;
|
||||
|
||||
while(t) {
|
||||
if (t.b_sound & flag)
|
||||
|
|
|
@ -48,6 +48,8 @@
|
|||
|
||||
-(id)queueForThink;
|
||||
@end
|
||||
@class Array;
|
||||
@extern Array waypoint_array;
|
||||
|
||||
@interface Bot: Target
|
||||
{
|
||||
|
@ -66,7 +68,7 @@
|
|||
integer wallhug;
|
||||
integer ishuman;
|
||||
float b_frags;
|
||||
integer b_clientno;
|
||||
integer b_clientno, b_clientflag;
|
||||
float b_shirt, b_pants;
|
||||
float ai_time;
|
||||
float b_sound;
|
||||
|
@ -99,6 +101,8 @@
|
|||
- (integer) postFrame;
|
||||
- (void) frame;
|
||||
- (void) disconnect;
|
||||
|
||||
- (void) updateClient;
|
||||
@end
|
||||
|
||||
@interface Bot (Misc)
|
||||
|
@ -185,50 +189,56 @@
|
|||
#define SVC_UPDATECOLORS 17
|
||||
|
||||
// used for the physics & movement AI
|
||||
#define KEY_MOVEUP 1
|
||||
#define KEY_MOVEDOWN 2
|
||||
#define KEY_MOVELEFT 4
|
||||
#define KEY_MOVERIGHT 8
|
||||
#define KEY_MOVEFORWARD 16
|
||||
#define KEY_MOVEBACK 32
|
||||
#define KEY_LOOKUP 64
|
||||
#define KEY_LOOKDOWN 128
|
||||
#define KEY_LOOKLEFT 256
|
||||
#define KEY_LOOKRIGHT 512
|
||||
#define KEY_MOVEUP 0x001
|
||||
#define KEY_MOVEDOWN 0x002
|
||||
#define KEY_MOVELEFT 0x004
|
||||
#define KEY_MOVERIGHT 0x008
|
||||
#define KEY_MOVEFORWARD 0x010
|
||||
#define KEY_MOVEBACK 0x020
|
||||
#define KEY_LOOKUP 0x040
|
||||
#define KEY_LOOKDOWN 0x080
|
||||
#define KEY_LOOKLEFT 0x100
|
||||
#define KEY_LOOKRIGHT 0x200
|
||||
|
||||
#define KEY_LOOK (KEY_LOOKRIGHT|KEY_LOOKLEFT|KEY_LOOKDOWN|KEY_LOOKUP)
|
||||
#define KEY_MOVE (KEY_MOVEBACK|KEY_MOVEFORWARD|KEY_MOVERIGHT\
|
||||
|KEY_MOVELEFT|KEY_MOVEDOWN|KEY_MOVEUP)
|
||||
|
||||
// these are aiflags for waypoints
|
||||
// some overlap to the bot
|
||||
#define AI_TELELINK_1 1 // link type
|
||||
#define AI_TELELINK_2 2 // link type
|
||||
#define AI_TELELINK_3 4 // link type
|
||||
#define AI_TELELINK_4 8 // link type
|
||||
#define AI_DOORFLAG 16 // read ahead
|
||||
#define AI_PRECISION 32 // read ahead + point
|
||||
#define AI_SURFACE 64 // point
|
||||
#define AI_BLIND 128 // read ahead + point
|
||||
#define AI_JUMP 256 // point + ignore
|
||||
#define AI_DIRECTIONAL 512 // read ahead + ignore
|
||||
#define AI_PLAT_BOTTOM 1024 // read ahead
|
||||
#define AI_RIDE_TRAIN 2048 // read ahead
|
||||
#define AI_SUPER_JUMP 4096 // point + ignore + route test
|
||||
#define AI_SNIPER 8192 // point type
|
||||
#define AI_AMBUSH 16384 // point type
|
||||
#define AI_DOOR_NO_OPEN 32768 // read ahead
|
||||
#define AI_DIFFICULT 65536 // route test
|
||||
#define AI_TRACE_TEST 131072 // route test
|
||||
#define AI_TELELINK_1 0x00001 // link type
|
||||
#define AI_TELELINK_2 0x00002 // link type
|
||||
#define AI_TELELINK_3 0x00004 // link type
|
||||
#define AI_TELELINK_4 0x00008 // link type
|
||||
#define AI_DOORFLAG 0x00010 // read ahead
|
||||
#define AI_PRECISION 0x00020 // read ahead + point
|
||||
#define AI_SURFACE 0x00040 // point
|
||||
#define AI_BLIND 0x00080 // read ahead + point
|
||||
#define AI_JUMP 0x00100 // point + ignore
|
||||
#define AI_DIRECTIONAL 0x00200 // read ahead + ignore
|
||||
#define AI_PLAT_BOTTOM 0x00400 // read ahead
|
||||
#define AI_RIDE_TRAIN 0x00800 // read ahead
|
||||
#define AI_SUPER_JUMP 0x01000 // point + ignore + route test
|
||||
#define AI_SNIPER 0x02000 // point type
|
||||
#define AI_AMBUSH 0x04000 // point type
|
||||
#define AI_DOOR_NO_OPEN 0x08000 // read ahead
|
||||
#define AI_DIFFICULT 0x10000 // route test
|
||||
#define AI_TRACE_TEST 0x20000 // route test
|
||||
|
||||
// addition masks
|
||||
#define AI_POINT_TYPES (AI_AMBUSH|AI_SNIPER|AI_SUPER_JUMP|AI_JUMP\
|
||||
|AI_BLIND|AI_SURFACE|AI_PRECISION)
|
||||
#define AI_READAHEAD_TYPES (AI_DOOR_NO_OPEN|AI_RIDE_TRAIN|AI_PLAT_BOTTOM\
|
||||
|AI_DIRECTIONAL)
|
||||
#define AI_IGNORE_TYPES (AI_SUPER_JUMP|AI_DIRECTIONAL|AI_JUMP)
|
||||
|
||||
// these are flags for bots/players (dynamic/editor flags)
|
||||
#define AI_OBSTRUCTED 1
|
||||
#define AI_HOLD_SELECT 2
|
||||
#define AI_ROUTE_FAILED 2
|
||||
#define AI_WAIT 4
|
||||
#define AI_WAIT 4
|
||||
#define AI_DANGER 8
|
||||
|
||||
// addition masks
|
||||
#define AI_POINT_TYPES 29152
|
||||
#define AI_READAHEAD_TYPES 36528
|
||||
#define AI_IGNORE_TYPES 4864
|
||||
|
||||
#define WM_UNINIT 0
|
||||
#define WM_DYNAMIC 1
|
||||
#define WM_LOADING 2
|
||||
|
@ -257,15 +267,13 @@
|
|||
@extern float coop;
|
||||
|
||||
// -------ProtoTypes------
|
||||
// external
|
||||
// external, in main code
|
||||
@extern void() ClientConnect;
|
||||
@extern void() ClientDisconnect;
|
||||
@extern void() SetNewParms;
|
||||
|
||||
// rankings
|
||||
@extern integer (entity e) ClientNumber;
|
||||
@extern integer(integer clientno) ClientBitFlag;
|
||||
@extern void(entity who) UpdateClient;
|
||||
|
||||
@extern void(vector org, vector bit1, integer bit4, integer flargs) make_way;
|
||||
|
||||
|
|
73
fbxa/target.r
Normal file
73
fbxa/target.r
Normal file
|
@ -0,0 +1,73 @@
|
|||
/***********************************************
|
||||
* *
|
||||
* FrikBot Waypoints *
|
||||
* "The better than roaming 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.
|
||||
|
||||
*/
|
||||
|
||||
#include "libfrikbot.h"
|
||||
#include "Array.h"
|
||||
#include "List.h"
|
||||
|
||||
@implementation Target
|
||||
|
||||
-(vector)realorigin
|
||||
{
|
||||
return realorigin (ent);
|
||||
}
|
||||
|
||||
-(integer)canSee:(Target)targ ignoring:(entity)ignore
|
||||
{
|
||||
local vector spot1, spot2;
|
||||
|
||||
spot1 = ent.origin;
|
||||
spot2 = [targ realorigin];
|
||||
|
||||
do {
|
||||
traceline (spot1, spot2, TRUE, ignore);
|
||||
spot1 = realorigin(trace_ent);
|
||||
ignore = trace_ent;
|
||||
} while ((trace_ent != world) && (trace_fraction != 1));
|
||||
if (trace_endpos == spot2)
|
||||
return TRUE;
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
@end
|
|
@ -46,7 +46,7 @@ this notice in its entirety.
|
|||
#include "Array.h"
|
||||
#include "List.h"
|
||||
|
||||
@static Array waypoint_array;
|
||||
Array waypoint_array;
|
||||
@static entity waypoint_thinker;
|
||||
@static List waypoint_queue;
|
||||
|
||||
|
@ -235,7 +235,7 @@ Route & path table management
|
|||
-(void)clearRouteForBot:(Bot)bot
|
||||
{
|
||||
local integer flag;
|
||||
flag = ClientBitFlag(bot.b_clientno);
|
||||
flag = bot.b_clientflag;
|
||||
b_sound &= ~flag;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue