mirror of
https://git.code.sf.net/p/quake/game-source
synced 2025-04-07 16:21:11 +00:00
can get a bot added to the server, but the server crashes as soon as the
bot sees the player (treating entity as an object: oops)
This commit is contained in:
parent
f298e0e8e6
commit
17ca25a64a
11 changed files with 143 additions and 113 deletions
|
@ -56,7 +56,7 @@ checks to see if an entity is on the bot's stack
|
|||
|
||||
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||
*/
|
||||
-(integer)target_onstack:(entity)scot
|
||||
-(integer)target_onstack:(Target)scot
|
||||
{
|
||||
if (scot == NIL)
|
||||
return FALSE;
|
||||
|
@ -82,7 +82,7 @@ LIFO stack, this will be the bot's new target1
|
|||
|
||||
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||
*/
|
||||
-(void)target_add:(entity)e
|
||||
-(void)target_add:(Target)e
|
||||
{
|
||||
if (e == NIL)
|
||||
return;
|
||||
|
@ -109,7 +109,7 @@ is gone too.
|
|||
|
||||
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||
*/
|
||||
-(void)target_drop:(entity)e
|
||||
-(void)target_drop:(Target)e
|
||||
{
|
||||
switch ([self target_onstack:e]) {
|
||||
case 1:
|
||||
|
@ -192,12 +192,12 @@ removed.
|
|||
{
|
||||
local vector dist;
|
||||
|
||||
dist = [targ realorigin] - ent.origin;
|
||||
dist_z = 0;
|
||||
|
||||
if (targ == NIL)
|
||||
return;
|
||||
|
||||
dist = [targ realorigin] - ent.origin;
|
||||
dist_z = 0;
|
||||
|
||||
// waypoints and items are lost if you get close enough to them
|
||||
if (targ.ent.flags & FL_ITEM) {
|
||||
if (vlen (targ.ent.origin - ent.origin) < 32)
|
||||
|
@ -304,7 +304,7 @@ based b_aiflags.
|
|||
if (b_aiflags & AI_DOORFLAG) {
|
||||
// was on a door when spawned
|
||||
// if there is nothing there now
|
||||
if (![ent.@this recognize_plat:FALSE]) {
|
||||
if (![last_way recognize_plat:FALSE]) {
|
||||
newt = [self findThing: "door"]; // this is likely the door responsible (crossfingers)
|
||||
|
||||
if (b_aiflags & AI_DOOR_NO_OPEN) {
|
||||
|
@ -321,7 +321,7 @@ based b_aiflags.
|
|||
[self weapon_switch:1];
|
||||
} else {
|
||||
// target_drop (last_way);
|
||||
[self target_add:newt];
|
||||
[self target_add:newt]; //FIXME newt wrong type
|
||||
// bot_get_path (newt, TRUE);
|
||||
}
|
||||
}
|
||||
|
@ -359,7 +359,7 @@ based b_aiflags.
|
|||
// simple, but effective
|
||||
// this can probably be used for a lot of different
|
||||
// things, not just trains (door elevators come to mind)
|
||||
if (![ent.@this recognize_plat:FALSE]) {
|
||||
if (![last_way recognize_plat:FALSE]) {
|
||||
// if there is nothing there now
|
||||
keys &= ~KEY_MOVE;
|
||||
} else {
|
||||
|
@ -456,7 +456,7 @@ confused
|
|||
if (last_way) {
|
||||
if ([last_way isLinkedTo:jj] == 2) {
|
||||
// waypoints are telelinked
|
||||
tele = [self findThing:"trigger_teleport"].@this; // this is probbly the teleport responsible
|
||||
tele = [self findThing:"trigger_teleport"].@this; // this is probbly the teleport responsible FIXME shouldn't use @this here
|
||||
[self target_add:tele];
|
||||
}
|
||||
traceline (last_way.origin, jj.origin, FALSE, ent); // check for blockage
|
||||
|
@ -477,7 +477,7 @@ confused
|
|||
[self weapon_switch:1];
|
||||
} else {
|
||||
// target_drop (jj);
|
||||
[self target_add:e];
|
||||
[self target_add:e]; //FIXME e wrong type
|
||||
// bot_get_path (tele, TRUE);
|
||||
b_aiflags |= AI_BLIND; // give a bot a bone
|
||||
return;
|
||||
|
@ -628,7 +628,7 @@ the bot finds things it wants to kill/grab.
|
|||
if (best == NIL)
|
||||
return;
|
||||
if (![self target_onstack:best]) {
|
||||
[self target_add:best];
|
||||
[self target_add:best]; //FIXME best wrong type
|
||||
if (scope) {
|
||||
[self get_path:best :FALSE];
|
||||
b_aiflags |= AI_WAIT;
|
||||
|
@ -680,8 +680,8 @@ generally making the bot look good.
|
|||
view_x = view_x * -1;
|
||||
b_angle = view;
|
||||
} else if (targets[0]) {
|
||||
view = realorigin (targets[0]);
|
||||
if (targets[0].flags & FL_ITEM)
|
||||
view = [targets[0] realorigin];
|
||||
if (targets[0].ent.flags & FL_ITEM)
|
||||
view = view + '0 0 48';
|
||||
view -= (ent.origin + ent.view_ofs);
|
||||
view = vectoangles (view);
|
||||
|
@ -699,7 +699,7 @@ generally making the bot look good.
|
|||
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") {
|
||||
} else if ((ent.enemy == NIL || ent.enemy.movetype == MOVETYPE_PUSH) && targets[0].ent.classname != "player") {
|
||||
keys &= ~KEY_LOOK;
|
||||
v_angle = b_angle;
|
||||
while (v_angle.x < -180)
|
||||
|
@ -746,7 +746,8 @@ frame, the ai_time limits it's actual updating
|
|||
keys = 0;
|
||||
b_aiflags = 0;
|
||||
[Waypoint clearMyRoute:self];
|
||||
targets[0] = targets[1] = targets[2] = targets[3] = ent.enemy = NIL;
|
||||
targets[0] = targets[1] = targets[2] = targets[3] = NIL;
|
||||
ent.enemy = NIL;
|
||||
last_way = NIL;
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -42,6 +42,8 @@ this notice in its entirety.
|
|||
|
||||
#include "libfrikbot.h"
|
||||
|
||||
integer bot_fight_linker;
|
||||
|
||||
/*
|
||||
weapon_range
|
||||
|
||||
|
|
|
@ -42,6 +42,8 @@ this notice in its entirety.
|
|||
|
||||
#include "libfrikbot.h"
|
||||
|
||||
integer bot_move_linker;
|
||||
|
||||
@implementation Bot (Move)
|
||||
- (void) jump
|
||||
{
|
||||
|
@ -80,10 +82,10 @@ this notice in its entirety.
|
|||
|
||||
- (integer) recognize_plat: (integer) flag
|
||||
{
|
||||
if ((ent.classname != "waypoint") && !(ent.flags & FL_ONGROUND))
|
||||
return FALSE;
|
||||
traceline (ent.origin, ent.origin - '0 0 64', TRUE, ent);
|
||||
if (trace_ent != NIL) {
|
||||
local integer ret;
|
||||
|
||||
ret = [super recognize_plat:flag];
|
||||
if (ret) {
|
||||
if (flag) {
|
||||
// afect bot movement too
|
||||
if (keys & KEY_MOVEUP) {
|
||||
|
@ -94,9 +96,8 @@ this notice in its entirety.
|
|||
keys &= ~KEY_MOVE;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
} else
|
||||
return FALSE;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
-(integer)keysForDir: (vector) sdir
|
||||
|
@ -143,7 +144,7 @@ manuever around.
|
|||
// TODO: something
|
||||
if (b_aiflags & AI_BLIND)
|
||||
return;
|
||||
org = realorigin(targets[0]);
|
||||
org = [targets[0] realorigin];
|
||||
|
||||
if (danger) {
|
||||
b_aiflags |= AI_DANGER;
|
||||
|
@ -244,7 +245,7 @@ Also responsible for jumping gaps.
|
|||
return;
|
||||
} else {
|
||||
if (targets[0]) {
|
||||
stop = realorigin(targets[0]);
|
||||
stop = [targets[0] realorigin];
|
||||
if ((stop_z - ent.origin_z) < -32)
|
||||
return; // safe to fall
|
||||
}
|
||||
|
@ -262,7 +263,7 @@ Also responsible for jumping gaps.
|
|||
return;
|
||||
} else {
|
||||
if (targets[0]) {
|
||||
stop = realorigin(targets[0]);
|
||||
stop = [targets[0] realorigin];
|
||||
if ((stop_z - ent.origin_z) < -32)
|
||||
return; // safe to fall
|
||||
}
|
||||
|
@ -273,8 +274,8 @@ Also responsible for jumping gaps.
|
|||
|
||||
if (targets[0]) {
|
||||
// getting furter away from my target?
|
||||
test = vlen (targets[0].origin - (ang + ent.origin));
|
||||
if (test > vlen (targets[0].origin - ent.origin)) {
|
||||
test = vlen ([targets[0] origin] - (ang + ent.origin));
|
||||
if (test > vlen ([targets[0] origin] - ent.origin)) {
|
||||
if (conts < -3) {
|
||||
// bad stuff down dare
|
||||
[self obstructed: ang :TRUE];
|
||||
|
@ -288,7 +289,7 @@ Also responsible for jumping gaps.
|
|||
}
|
||||
if (hgt < -18) {
|
||||
if (targets[0]) {
|
||||
stop = realorigin (targets[0]);
|
||||
stop = [targets[0] realorigin];
|
||||
if ((stop_z - ent.origin_z) < -32)
|
||||
return; // safe to fall
|
||||
}
|
||||
|
@ -362,7 +363,7 @@ blah
|
|||
[self walkmove: v_forward];
|
||||
return;
|
||||
}
|
||||
way = realorigin(targets[0]) - ent.origin;
|
||||
way = [targets[0] realorigin] - ent.origin;
|
||||
if (vlen(way) < 25) {
|
||||
keys &= ~KEY_MOVE;
|
||||
return;
|
||||
|
|
|
@ -49,6 +49,8 @@ this notice in its entirety.
|
|||
|
||||
#include "libfrikbot.h"
|
||||
|
||||
integer bot_phys_linker;
|
||||
|
||||
float (integer keys, integer key) key_state =
|
||||
{
|
||||
return ((keys & key) != 0) ? 1.0 : 0.0;
|
||||
|
@ -106,23 +108,3 @@ float (integer keys, integer key) key_state =
|
|||
SV_UserCmd (ent, real_frametime, v_angle, movevect, buttons, impulse);
|
||||
}
|
||||
@end
|
||||
|
||||
/*
|
||||
=========================================
|
||||
|
||||
Stuff mimicking sv_user.c
|
||||
|
||||
=========================================
|
||||
*/
|
||||
|
||||
void() DropPunchAngle =
|
||||
{
|
||||
local float len;
|
||||
|
||||
len = vlen (@self.punchangle);
|
||||
@self.punchangle = normalize (@self.punchangle);
|
||||
len -= 10 * real_frametime;
|
||||
if (len < 0)
|
||||
len = 0;
|
||||
@self.punchangle *= len;
|
||||
};
|
||||
|
|
119
fbxa/bot_qw.qc
119
fbxa/bot_qw.qc
|
@ -75,6 +75,13 @@ ClientFixRankings(); // FrikBot
|
|||
|
||||
#include "libfrikbot.h"
|
||||
|
||||
integer []bot_way_ref;
|
||||
integer []bot_move_ref;
|
||||
integer []bot_phys_ref;
|
||||
integer []bot_chat_ref;
|
||||
float []stagger_think_ref;
|
||||
integer []bot_fight_ref;
|
||||
|
||||
void ()
|
||||
bot_map_load =
|
||||
{
|
||||
|
@ -134,8 +141,8 @@ void (entity e, string str) SV_SetUserinfo = #0;
|
|||
void (entity e, integer ping) SV_SetPing = #0;
|
||||
void (entity cl, float sec, vector angles, vector move, integer buttons, integer impulse) SV_UserCmd = #0;
|
||||
|
||||
void() SV_Physics_Client = #0;
|
||||
void() SV_ClientThink = #0;
|
||||
void() SV_Physics_Client = {};//#0;
|
||||
void() SV_ClientThink = {};//#0;
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
@ -216,7 +223,8 @@ ClientInRankings =
|
|||
{
|
||||
local integer cl_no = ClientNumber (@self);
|
||||
|
||||
players[cl_no] = [[Bot alloc] initWithEntity:@self];
|
||||
if (!players[cl_no])
|
||||
players[cl_no] = [[Bot alloc] initFromPlayer:@self];
|
||||
};
|
||||
|
||||
void ()
|
||||
|
@ -226,31 +234,18 @@ ClientDisconnected =
|
|||
players[cl_no] = NIL;
|
||||
};
|
||||
|
||||
/*
|
||||
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||
|
||||
BotPreFrame & BotPostFrame, used to make the
|
||||
bot easier to install
|
||||
|
||||
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||
*/
|
||||
float ()
|
||||
BotPreFrame =
|
||||
{
|
||||
return (float)[((Bot)@self.@this) preFrame];
|
||||
};
|
||||
|
||||
float ()
|
||||
BotPostFrame =
|
||||
{
|
||||
return (float)[((Bot)@self.@this) postFrame];
|
||||
};
|
||||
|
||||
// BotInit ====================================================================
|
||||
|
||||
void ()
|
||||
BotInit =
|
||||
{
|
||||
[Waypoint clearAll];
|
||||
bot_way_ref = &bot_way_linker;
|
||||
bot_move_ref = &bot_move_linker;
|
||||
bot_phys_ref = &bot_phys_linker;
|
||||
bot_chat_ref = &bot_chat_linker;
|
||||
stagger_think_ref = &stagger_think;
|
||||
bot_fight_ref = &bot_fight_linker;
|
||||
bot_map_load ();
|
||||
};
|
||||
|
||||
|
@ -343,11 +338,12 @@ void () BotImpulses =
|
|||
|
||||
b_entertime = time;
|
||||
ent.team = b_pants + 1;
|
||||
[self updateClient];
|
||||
|
||||
ent.netname = name.name;
|
||||
b_pants = name.pants;
|
||||
b_shirt = name.shirt;
|
||||
|
||||
[self updateClient];
|
||||
//b_num = I
|
||||
bot_count++;
|
||||
if (skill > 3)
|
||||
|
@ -355,7 +351,7 @@ void () BotImpulses =
|
|||
else if (skill < 0)
|
||||
skill = 0;
|
||||
b_skill = skill;
|
||||
ishuman = 2;
|
||||
ishuman = FALSE;
|
||||
|
||||
uself = @self;
|
||||
@self = ent;
|
||||
|
@ -364,6 +360,8 @@ void () BotImpulses =
|
|||
PutClientInServer ();
|
||||
@self = uself;
|
||||
|
||||
players[cl_no] = self;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
|
@ -381,13 +379,12 @@ void () BotImpulses =
|
|||
return self;
|
||||
}
|
||||
|
||||
- (integer) preFrame
|
||||
- (void) preThink
|
||||
{
|
||||
if (b_clientno == -1)
|
||||
return TRUE;
|
||||
if (ishuman)
|
||||
if (switch_wallhug)
|
||||
ClientFixRankings ();
|
||||
local entity uself;
|
||||
|
||||
if (switch_wallhug)
|
||||
ClientFixRankings ();
|
||||
if (b_frags != ent.frags) {
|
||||
if (b_frags > ent.frags) {
|
||||
if (pointcontents (ent.origin) == CONTENT_LAVA)
|
||||
|
@ -399,16 +396,21 @@ void () BotImpulses =
|
|||
b_frags = ent.frags;
|
||||
}
|
||||
[self dynamicWaypoint];
|
||||
return FALSE;
|
||||
|
||||
uself = @self;
|
||||
@self = ent;
|
||||
PlayerPreThink ();
|
||||
@self = uself;
|
||||
}
|
||||
|
||||
- (integer) postFrame
|
||||
- (void) postThink
|
||||
{
|
||||
if (b_clientno == -1)
|
||||
return TRUE;
|
||||
if (ishuman)
|
||||
BotImpulses ();
|
||||
return FALSE;
|
||||
local entity uself;
|
||||
|
||||
uself = @self;
|
||||
@self = ent;
|
||||
PlayerPostThink ();
|
||||
@self = uself;
|
||||
}
|
||||
|
||||
-(void)disconnect
|
||||
|
@ -427,24 +429,9 @@ void () BotImpulses =
|
|||
|
||||
-(void)frame
|
||||
{
|
||||
local string h;
|
||||
|
||||
h = infokey (NIL, "bot_options");
|
||||
b_options = stof (h);
|
||||
|
||||
// for the sake of speed
|
||||
sv_maxspeed = cvar ("sv_maxspeed");
|
||||
sv_gravity = cvar ("sv_gravity");
|
||||
sv_friction = cvar ("sv_friction");
|
||||
sv_accelerate = cvar ("sv_accelerate");
|
||||
sv_stopspeed = cvar ("sv_stopspeed");
|
||||
real_frametime = time - lasttime; // in QW frametime is fuxx0red
|
||||
lasttime = time;
|
||||
|
||||
[self obstacles];
|
||||
[self AI];
|
||||
[self sendMove];
|
||||
SV_ClientThink ();
|
||||
SV_Physics_Client ();
|
||||
}
|
||||
|
||||
-(void) updateClient
|
||||
|
@ -461,3 +448,27 @@ void () BotImpulses =
|
|||
// FIXME: do teams properly
|
||||
}
|
||||
@end
|
||||
|
||||
void ()
|
||||
BotFrame =
|
||||
{
|
||||
local string h;
|
||||
local integer i;
|
||||
|
||||
h = infokey (NIL, "bot_options");
|
||||
b_options = stof (h);
|
||||
|
||||
// for the sake of speed
|
||||
sv_maxspeed = cvar ("sv_maxspeed");
|
||||
sv_gravity = cvar ("sv_gravity");
|
||||
sv_friction = cvar ("sv_friction");
|
||||
sv_accelerate = cvar ("sv_accelerate");
|
||||
sv_stopspeed = cvar ("sv_stopspeed");
|
||||
real_frametime = time - lasttime; // in QW frametime is fuxx0red
|
||||
lasttime = time;
|
||||
|
||||
for (i = 0; i < 32; i++) {
|
||||
if (players[i] && !players[i].ishuman)
|
||||
[players[i] frame];
|
||||
}
|
||||
};
|
||||
|
|
|
@ -46,6 +46,8 @@ this notice in its entirety.
|
|||
#include "Array.h"
|
||||
#include "List.h"
|
||||
|
||||
integer bot_way_linker;
|
||||
|
||||
@implementation Bot (Way)
|
||||
|
||||
/*
|
||||
|
|
|
@ -42,6 +42,8 @@ this notice in its entirety.
|
|||
|
||||
#include "libfrikbot.h"
|
||||
|
||||
integer bot_chat_linker;
|
||||
|
||||
@static Bot b_originator;
|
||||
@static integer b_topic;
|
||||
/* FBX Topics
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
@extern void() BotInit;
|
||||
@extern void() BotFrame;
|
||||
@extern float () BotPreFrame;
|
||||
@extern float () BotPostFrame;
|
||||
@extern void () BotImpulses;
|
||||
@extern void() ClientInRankings;
|
||||
@extern void() ClientDisconnected;
|
||||
@extern void() ClientFixRankings;
|
||||
|
|
|
@ -13,8 +13,10 @@ typedef struct bot_data_t bot_data_t;
|
|||
{
|
||||
}
|
||||
-(vector)realorigin;
|
||||
-(vector)origin;
|
||||
-(integer)canSee:(Target)targ ignoring:(entity)ignore;
|
||||
-(void)setOrigin:(vector) org;
|
||||
-(integer)recognize_plat:(integer)flag;
|
||||
@end
|
||||
|
||||
@interface Waypoint: Target
|
||||
|
@ -92,7 +94,7 @@ typedef struct bot_data_t bot_data_t;
|
|||
integer dyn_flags, dyn_plat;
|
||||
float dyn_time;
|
||||
Waypoint temp_way, last_way, current_way;
|
||||
entity [4] targets;
|
||||
Target [4] targets;
|
||||
entity avoid;
|
||||
vector obs_dir;
|
||||
vector b_dir;
|
||||
|
@ -104,8 +106,8 @@ typedef struct bot_data_t bot_data_t;
|
|||
- (id) init;
|
||||
- (id) initWithEntity: (entity) e named:(bot_data_t [])name skill:(integer)skill;
|
||||
- (id) initFromPlayer: (entity) e;
|
||||
- (integer) preFrame;
|
||||
- (integer) postFrame;
|
||||
- (void) preThink;
|
||||
- (void) postThink;
|
||||
- (void) frame;
|
||||
- (void) disconnect;
|
||||
|
||||
|
@ -138,9 +140,9 @@ typedef struct bot_data_t bot_data_t;
|
|||
@end
|
||||
|
||||
@interface Bot (AI)
|
||||
-(integer)target_onstack:(entity)scot;
|
||||
-(void)target_add:(entity)e;
|
||||
-(void)target_drop:(entity)e;
|
||||
-(integer)target_onstack:(Target)scot;
|
||||
-(void)target_add:(Target)e;
|
||||
-(void)target_drop:(Target)e;
|
||||
-(void)lost:(Waypoint)targ :(integer)success;
|
||||
-(void)check_lost:(Waypoint)targ;
|
||||
-(void)handle_ai;
|
||||
|
@ -310,4 +312,11 @@ typedef struct bot_data_t bot_data_t;
|
|||
*/
|
||||
@extern void (entity cl, float sec, vector angles, vector move, integer buttons, integer impulse) SV_UserCmd;
|
||||
|
||||
@extern integer bot_way_linker;
|
||||
@extern integer bot_move_linker;
|
||||
@extern integer bot_phys_linker;
|
||||
@extern integer bot_chat_linker;
|
||||
@extern float stagger_think;
|
||||
@extern integer bot_fight_linker;
|
||||
|
||||
#include "defs.h"
|
||||
|
|
|
@ -53,6 +53,11 @@ this notice in its entirety.
|
|||
return realorigin (ent);
|
||||
}
|
||||
|
||||
-(vector)origin
|
||||
{
|
||||
return ent.origin;
|
||||
}
|
||||
|
||||
-(integer)canSee:(Target)targ ignoring:(entity)ignore
|
||||
{
|
||||
local vector spot1, spot2;
|
||||
|
@ -75,4 +80,14 @@ this notice in its entirety.
|
|||
{
|
||||
}
|
||||
|
||||
- (integer) recognize_plat: (integer) flag
|
||||
{
|
||||
local vector org = [self origin];
|
||||
traceline (org, org - '0 0 64', TRUE, ent);
|
||||
if (trace_ent != NIL)
|
||||
return TRUE;
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -85,6 +85,11 @@ Array waypoint_array;
|
|||
{
|
||||
origin = org;
|
||||
}
|
||||
|
||||
-(vector)origin
|
||||
{
|
||||
return origin;
|
||||
}
|
||||
/*
|
||||
entity (vector org)
|
||||
make_waypoint =
|
||||
|
@ -190,7 +195,8 @@ Waypoint Loading from file
|
|||
|
||||
+(void)clearAll
|
||||
{
|
||||
[waypoint_array free];
|
||||
if (waypoint_array)
|
||||
[waypoint_array free];
|
||||
waypoint_array = [[Array alloc] init];
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue