2003-02-18 23:11:05 +00:00
|
|
|
/***********************************************
|
|
|
|
* *
|
|
|
|
* FrikBot General AI *
|
|
|
|
* "The I'd rather be playing Quake 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-07-23 06:35:39 +00:00
|
|
|
@implementation Bot (AI)
|
2003-02-18 23:11:05 +00:00
|
|
|
/*
|
|
|
|
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
|
|
|
|
|
|
|
target_onstack
|
|
|
|
|
|
|
|
checks to see if an entity is on the bot's stack
|
|
|
|
|
|
|
|
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
|
|
|
*/
|
|
|
|
float(entity scot) target_onstack =
|
|
|
|
{
|
2003-02-24 16:05:25 +00:00
|
|
|
if (scot == NIL)
|
2003-02-18 23:11:05 +00:00
|
|
|
return FALSE;
|
|
|
|
else if (self.target1 == scot)
|
|
|
|
return 1;
|
|
|
|
else if (self.target2 == scot)
|
|
|
|
return 2;
|
|
|
|
else if (self.target3 == scot)
|
|
|
|
return 3;
|
|
|
|
else if (self.target4 == scot)
|
|
|
|
return 4;
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
|
|
|
|
|
|
|
target_add
|
|
|
|
|
|
|
|
adds a new entity to the stack, since it's a
|
|
|
|
LIFO stack, this will be the bot's new target1
|
|
|
|
|
|
|
|
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
|
|
|
*/
|
|
|
|
void(entity ent) target_add =
|
|
|
|
{
|
2003-02-24 16:05:25 +00:00
|
|
|
if (ent == NIL)
|
2003-02-18 23:11:05 +00:00
|
|
|
return;
|
2003-03-08 03:20:32 +00:00
|
|
|
if (target_onstack (ent))
|
2003-02-18 23:11:05 +00:00
|
|
|
return;
|
2003-03-08 03:20:32 +00:00
|
|
|
|
2003-02-18 23:11:05 +00:00
|
|
|
self.target4 = self.target3;
|
|
|
|
self.target3 = self.target2;
|
|
|
|
self.target2 = self.target1;
|
|
|
|
self.target1 = ent;
|
|
|
|
self.search_time = time + 5;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
|
|
|
|
|
|
|
target_drop
|
|
|
|
|
|
|
|
Removes an entity from the bot's target stack.
|
|
|
|
The stack will empty everything up to the object
|
|
|
|
So if you have target2 item_health, target1
|
|
|
|
waypoint, and you drop the health, the waypoint
|
|
|
|
is gone too.
|
|
|
|
|
|
|
|
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
|
|
|
*/
|
|
|
|
void(entity ent) target_drop =
|
|
|
|
{
|
2003-03-08 03:20:32 +00:00
|
|
|
switch (target_onstack (ent)) {
|
|
|
|
case 1:
|
2003-02-18 23:11:05 +00:00
|
|
|
self.target1 = self.target2;
|
|
|
|
self.target2 = self.target3;
|
|
|
|
self.target3 = self.target4;
|
2003-02-24 16:05:25 +00:00
|
|
|
self.target4 = NIL;
|
2003-03-08 03:20:32 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2003-02-18 23:11:05 +00:00
|
|
|
self.target1 = self.target3;
|
|
|
|
self.target2 = self.target4;
|
2003-02-24 16:05:25 +00:00
|
|
|
self.target3 = self.target4 = NIL;
|
2003-03-08 03:20:32 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
2003-02-18 23:11:05 +00:00
|
|
|
self.target1 = self.target4;
|
2003-02-24 16:05:25 +00:00
|
|
|
self.target2 = self.target3 = self.target4 = NIL;
|
2003-03-08 03:20:32 +00:00
|
|
|
break;
|
|
|
|
case 4:
|
2003-02-24 16:05:25 +00:00
|
|
|
self.target1 = self.target2 = self.target3 = self.target4 = NIL;
|
2003-03-08 03:20:32 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2003-02-18 23:11:05 +00:00
|
|
|
self.search_time = time + 5;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
|
|
|
|
|
|
|
bot_lost
|
|
|
|
|
|
|
|
Bot has lost its target.
|
|
|
|
|
|
|
|
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
|
|
|
*/
|
|
|
|
void(entity targ, float success) bot_lost =
|
|
|
|
{
|
|
|
|
if (!targ)
|
|
|
|
return;
|
|
|
|
|
|
|
|
target_drop(targ);
|
|
|
|
if (targ.classname == "waypoint")
|
2003-03-08 03:20:32 +00:00
|
|
|
targ.b_sound &= ~(ClientBitFlag (self.b_clientno));
|
2003-02-18 23:11:05 +00:00
|
|
|
|
|
|
|
// find a new route
|
2003-03-04 18:26:17 +00:00
|
|
|
if (!success) {
|
2003-02-24 16:05:25 +00:00
|
|
|
self.target1 = self.target2 = self.target3 = self.target4 = NIL;
|
2003-03-08 03:20:32 +00:00
|
|
|
self.last_way = FindWayPoint (self.current_way);
|
|
|
|
ClearMyRoute ();
|
2003-02-18 23:11:05 +00:00
|
|
|
self.b_aiflags = 0;
|
2003-03-04 18:26:17 +00:00
|
|
|
} else {
|
2003-02-18 23:11:05 +00:00
|
|
|
if (targ.classname == "item_artifact_invisibility")
|
|
|
|
if (self.items & 524288)
|
2003-03-08 03:20:32 +00:00
|
|
|
bot_start_topic (3);
|
2003-02-18 23:11:05 +00:00
|
|
|
|
2003-03-04 18:26:17 +00:00
|
|
|
if (targ.flags & FL_ITEM) {
|
|
|
|
if (!targ.model)
|
|
|
|
targ._last = NIL;
|
|
|
|
else
|
|
|
|
targ._last = self;
|
2003-02-18 23:11:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (targ.classname != "player")
|
|
|
|
targ.search_time = time + 5;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
|
|
|
|
|
|
|
bot_check_lost
|
|
|
|
|
|
|
|
decide if my most immediate target should be
|
|
|
|
removed.
|
|
|
|
|
|
|
|
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
|
|
|
*/
|
|
|
|
void(entity targ) bot_check_lost =
|
|
|
|
{
|
|
|
|
local vector dist;
|
2003-03-08 03:20:32 +00:00
|
|
|
|
|
|
|
dist = realorigin (targ) - self.origin;
|
2003-02-18 23:11:05 +00:00
|
|
|
dist_z = 0;
|
2003-03-08 03:20:32 +00:00
|
|
|
|
2003-02-24 16:05:25 +00:00
|
|
|
if (targ == NIL)
|
2003-02-18 23:11:05 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// waypoints and items are lost if you get close enough to them
|
2003-03-08 03:20:32 +00:00
|
|
|
if (targ.flags & FL_ITEM) {
|
|
|
|
if (vlen (targ.origin - self.origin) < 32)
|
|
|
|
bot_lost (targ, TRUE);
|
2003-02-24 16:05:25 +00:00
|
|
|
else if (!targ.model)
|
2003-03-08 03:20:32 +00:00
|
|
|
bot_lost (targ, TRUE);
|
2003-03-04 18:26:17 +00:00
|
|
|
} else if (targ.classname == "waypoint") {
|
|
|
|
if (!(self.b_aiflags & (AI_SNIPER | AI_AMBUSH))) {
|
|
|
|
if (self.b_aiflags & AI_RIDE_TRAIN) {
|
2003-03-08 03:20:32 +00:00
|
|
|
if (vlen (targ.origin - self.origin) < 48)
|
|
|
|
bot_lost (targ, TRUE);
|
2003-03-04 18:26:17 +00:00
|
|
|
} else if (self.b_aiflags & AI_PRECISION) {
|
2003-03-08 03:20:32 +00:00
|
|
|
if (vlen (targ.origin - self.origin) < 24)
|
|
|
|
bot_lost (targ, TRUE);
|
|
|
|
} else if (vlen (targ.origin - self.origin) < 32)
|
|
|
|
bot_lost (targ, TRUE);
|
2003-02-18 23:11:05 +00:00
|
|
|
}
|
2003-03-04 18:26:17 +00:00
|
|
|
} else if (targ.classname == "temp_waypoint") {
|
2003-03-08 03:20:32 +00:00
|
|
|
if (vlen (targ.origin - self.origin) < 32)
|
|
|
|
bot_lost (targ, TRUE);
|
2003-03-04 18:26:17 +00:00
|
|
|
} else if (targ.classname == "player") {
|
2003-02-18 23:11:05 +00:00
|
|
|
if (targ.health <= 0)
|
2003-03-08 03:20:32 +00:00
|
|
|
bot_lost (targ, TRUE);
|
2003-03-04 18:26:17 +00:00
|
|
|
else if ((coop) || (teamplay && targ.team == self.team)) {
|
|
|
|
if (targ.target1.classname == "player") {
|
2003-02-18 23:11:05 +00:00
|
|
|
if (!targ.target1.ishuman)
|
2003-03-08 03:20:32 +00:00
|
|
|
bot_lost (targ, TRUE);
|
2003-03-04 18:26:17 +00:00
|
|
|
} else if (targ.teleport_time > time) {
|
2003-02-18 23:11:05 +00:00
|
|
|
// try not to telefrag teammates
|
2003-03-08 03:20:32 +00:00
|
|
|
self.keys &= 960;
|
|
|
|
} else if (vlen (targ.origin - self.origin) < 128) {
|
|
|
|
if (vlen (targ.origin - self.origin) < 48)
|
|
|
|
frik_walkmove (self.origin - targ.origin);
|
2003-03-04 18:26:17 +00:00
|
|
|
else {
|
2003-03-08 03:20:32 +00:00
|
|
|
self.keys &= 960;
|
|
|
|
bot_start_topic (4);
|
2003-02-18 23:11:05 +00:00
|
|
|
}
|
|
|
|
self.search_time = time + 5; // never time out
|
2003-03-04 18:26:17 +00:00
|
|
|
} else if (!fisible(targ))
|
2003-03-08 03:20:32 +00:00
|
|
|
bot_lost (targ, FALSE);
|
2003-03-04 18:26:17 +00:00
|
|
|
} else if (waypoint_mode > WM_LOADED) {
|
2003-03-08 03:20:32 +00:00
|
|
|
if (vlen (targ.origin - self.origin) < 128) {
|
|
|
|
bot_lost (targ, TRUE);
|
2003-02-18 23:11:05 +00:00
|
|
|
}
|
|
|
|
}
|
2003-03-04 18:26:17 +00:00
|
|
|
} else if (targ.classname == "func_button") {
|
|
|
|
// buttons are lost of their frame changes
|
|
|
|
if (targ.frame) {
|
2003-03-08 03:20:32 +00:00
|
|
|
bot_lost (targ, TRUE);
|
2003-02-18 23:11:05 +00:00
|
|
|
if (self.enemy == targ)
|
2003-02-24 16:05:25 +00:00
|
|
|
self.enemy = NIL;
|
2003-03-08 03:20:32 +00:00
|
|
|
// if (self.target1)
|
|
|
|
// bot_get_path (self.target1, TRUE);
|
2003-02-18 23:11:05 +00:00
|
|
|
}
|
2003-03-04 18:26:17 +00:00
|
|
|
} else if ((targ.movetype == MOVETYPE_NONE) && (targ.solid == SOLID_TRIGGER)) {
|
|
|
|
// trigger_multiple style triggers are lost if their thinktime changes
|
|
|
|
if (targ.nextthink >= time) {
|
2003-03-08 03:20:32 +00:00
|
|
|
bot_lost (targ, TRUE);
|
|
|
|
// if (self.target1)
|
|
|
|
// bot_get_path (self.target1, TRUE);
|
2003-02-18 23:11:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// lose any target way above the bot's head
|
|
|
|
// FIXME: if the bot can fly in your mod..
|
2003-03-04 18:26:17 +00:00
|
|
|
if ((targ.origin_z - self.origin_z) > 64) {
|
2003-02-18 23:11:05 +00:00
|
|
|
dist = targ.origin - self.origin;
|
|
|
|
dist_z = 0;
|
2003-03-08 03:20:32 +00:00
|
|
|
if (vlen (dist) < 32)
|
2003-02-18 23:11:05 +00:00
|
|
|
if (self.flags & FL_ONGROUND)
|
2003-03-08 03:20:32 +00:00
|
|
|
if (!frik_recognize_plat (FALSE))
|
|
|
|
bot_lost (targ, FALSE);
|
2003-03-04 18:26:17 +00:00
|
|
|
} else if (targ.classname == "train") {
|
2003-03-08 03:20:32 +00:00
|
|
|
if (frik_recognize_plat (FALSE))
|
|
|
|
bot_lost (targ, TRUE);
|
2003-02-18 23:11:05 +00:00
|
|
|
}
|
|
|
|
// targets are lost if the bot's search time has expired
|
|
|
|
if (time > self.search_time)
|
2003-03-08 03:20:32 +00:00
|
|
|
bot_lost (targ, FALSE);
|
2003-02-18 23:11:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
|
|
|
|
|
|
|
bot_handle_ai
|
|
|
|
|
|
|
|
This is a 0.10 addition. Handles any action
|
|
|
|
based b_aiflags.
|
|
|
|
|
|
|
|
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
|
|
|
*/
|
|
|
|
void() bot_handle_ai =
|
|
|
|
{
|
|
|
|
local entity newt;
|
|
|
|
local vector v;
|
|
|
|
|
|
|
|
// handle ai flags -- note, not all aiflags are handled
|
|
|
|
// here, just those that perform some sort of action
|
|
|
|
|
|
|
|
// wait is used by the ai to stop the bot until his search time expires / or route changes
|
|
|
|
|
|
|
|
if (self.b_aiflags & AI_WAIT)
|
2003-03-08 03:20:32 +00:00
|
|
|
self.keys &= 960;
|
2003-02-18 23:11:05 +00:00
|
|
|
|
2003-03-04 18:48:44 +00:00
|
|
|
if (self.b_aiflags & AI_DOORFLAG) {
|
|
|
|
// was on a door when spawned
|
2003-02-18 23:11:05 +00:00
|
|
|
b_temp3 = self;
|
|
|
|
self = self.last_way;
|
2003-03-04 18:26:17 +00:00
|
|
|
// if there is nothing there now
|
2003-03-08 03:20:32 +00:00
|
|
|
if (!frik_recognize_plat (FALSE)) {
|
|
|
|
newt = FindThing ("door"); // this is likely the door responsible (crossfingers)
|
2003-02-18 23:11:05 +00:00
|
|
|
self = b_temp3;
|
|
|
|
|
2003-03-04 18:26:17 +00:00
|
|
|
if (self.b_aiflags & AI_DOOR_NO_OPEN) {
|
2003-02-18 23:11:05 +00:00
|
|
|
if (newt.nextthink)
|
2003-03-08 03:20:32 +00:00
|
|
|
self.keys &= 960; // wait until it closes
|
2003-03-04 18:26:17 +00:00
|
|
|
else {
|
2003-03-08 03:20:32 +00:00
|
|
|
bot_lost (self.last_way, FALSE);
|
2003-02-18 23:11:05 +00:00
|
|
|
}
|
2003-03-04 18:26:17 +00:00
|
|
|
} else {
|
|
|
|
if (newt.targetname) {
|
2003-03-08 03:20:32 +00:00
|
|
|
newt = find (NIL, target, newt.targetname);
|
2003-03-04 18:26:17 +00:00
|
|
|
if (newt.health > 0) {
|
2003-02-18 23:11:05 +00:00
|
|
|
self.enemy = newt;
|
2003-03-08 03:20:32 +00:00
|
|
|
bot_weapon_switch (1);
|
2003-03-04 18:26:17 +00:00
|
|
|
} else {
|
2003-03-08 03:20:32 +00:00
|
|
|
// target_drop (self.last_way);
|
|
|
|
target_add (newt);
|
|
|
|
// bot_get_path (newt, TRUE);
|
2003-02-18 23:11:05 +00:00
|
|
|
}
|
|
|
|
}
|
2003-03-08 03:20:32 +00:00
|
|
|
self.b_aiflags &= ~AI_DOORFLAG;
|
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
|
|
|
self = b_temp3;
|
|
|
|
}
|
|
|
|
|
2003-03-04 18:26:17 +00:00
|
|
|
if (self.b_aiflags & AI_JUMP) {
|
|
|
|
if (self.flags & FL_ONGROUND) {
|
2003-03-08 03:20:32 +00:00
|
|
|
bot_jump ();
|
|
|
|
self.b_aiflags &= ~AI_JUMP;
|
2003-02-18 23:11:05 +00:00
|
|
|
}
|
2003-03-04 18:26:17 +00:00
|
|
|
} else if (self.b_aiflags & AI_SUPER_JUMP) {
|
2003-02-18 23:11:05 +00:00
|
|
|
if (self.weapon != 32)
|
|
|
|
self.impulse = 7;
|
2003-03-04 18:26:17 +00:00
|
|
|
else if (self.flags & FL_ONGROUND) {
|
2003-03-08 03:20:32 +00:00
|
|
|
self.b_aiflags &= ~AI_SUPER_JUMP;
|
|
|
|
if (bot_can_rj (self)) {
|
|
|
|
bot_jump ();
|
2003-02-18 23:11:05 +00:00
|
|
|
self.v_angle_x = self.b_angle_x = 80;
|
|
|
|
self.button0 = TRUE;
|
2003-03-04 18:26:17 +00:00
|
|
|
} else
|
2003-03-08 03:20:32 +00:00
|
|
|
bot_lost (self.target1, FALSE);
|
2003-02-18 23:11:05 +00:00
|
|
|
}
|
|
|
|
}
|
2003-03-04 18:26:17 +00:00
|
|
|
if (self.b_aiflags & AI_SURFACE) {
|
|
|
|
if (self.waterlevel > 2) {
|
2003-02-18 23:11:05 +00:00
|
|
|
self.keys = KEY_MOVEUP;
|
|
|
|
self.button2 = TRUE; // swim!
|
2003-03-04 18:26:17 +00:00
|
|
|
} else
|
2003-03-08 03:20:32 +00:00
|
|
|
self.b_aiflags &= ~AI_SURFACE;
|
2003-02-18 23:11:05 +00:00
|
|
|
}
|
2003-03-04 18:26:17 +00:00
|
|
|
if (self.b_aiflags & AI_RIDE_TRAIN) {
|
2003-02-18 23:11:05 +00:00
|
|
|
// simple, but effective
|
|
|
|
// this can probably be used for a lot of different
|
|
|
|
// things, not just trains (door elevators come to mind)
|
|
|
|
b_temp3 = self;
|
|
|
|
self = self.last_way;
|
2003-03-08 03:20:32 +00:00
|
|
|
|
2003-03-04 18:26:17 +00:00
|
|
|
if (!frik_recognize_plat(FALSE)) {
|
|
|
|
// if there is nothing there now
|
2003-02-18 23:11:05 +00:00
|
|
|
self = b_temp3;
|
2003-03-08 03:20:32 +00:00
|
|
|
self.keys &= 960;
|
2003-03-04 18:26:17 +00:00
|
|
|
} else {
|
2003-02-18 23:11:05 +00:00
|
|
|
self = b_temp3;
|
2003-03-08 03:20:32 +00:00
|
|
|
if (frik_recognize_plat (FALSE)) {
|
|
|
|
v = realorigin (trace_ent) + trace_ent.origin - self.origin;
|
2003-02-18 23:11:05 +00:00
|
|
|
v_z = 0;
|
2003-03-08 03:20:32 +00:00
|
|
|
if (vlen (v) < 24)
|
|
|
|
self.keys &= 960;
|
2003-03-04 18:26:17 +00:00
|
|
|
else {
|
2003-03-08 03:20:32 +00:00
|
|
|
self.b_aiflags |= AI_PRECISION;
|
|
|
|
self.keys = frik_KeysForDir (v);
|
2003-02-18 23:11:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-03-04 18:26:17 +00:00
|
|
|
if (self.b_aiflags & AI_PLAT_BOTTOM) {
|
2003-03-08 03:20:32 +00:00
|
|
|
newt = FindThing ("plat");
|
2003-03-04 18:26:17 +00:00
|
|
|
if (newt.state != 1) {
|
2003-03-08 03:20:32 +00:00
|
|
|
v = self.origin - realorigin (newt);
|
2003-02-18 23:11:05 +00:00
|
|
|
v_z = 0;
|
2003-03-08 03:20:32 +00:00
|
|
|
if (vlen (v) > 96)
|
|
|
|
self.keys &= 960;
|
2003-02-18 23:11:05 +00:00
|
|
|
else
|
2003-03-08 03:20:32 +00:00
|
|
|
frik_walkmove (v);
|
2003-03-04 18:26:17 +00:00
|
|
|
} else
|
2003-03-08 03:20:32 +00:00
|
|
|
self.b_aiflags &= ~AI_PLAT_BOTTOM;
|
2003-02-18 23:11:05 +00:00
|
|
|
}
|
2003-03-04 18:26:17 +00:00
|
|
|
if (self.b_aiflags & AI_DIRECTIONAL) {
|
2003-03-08 03:20:32 +00:00
|
|
|
if ((normalize (self.last_way.origin - self.origin) * self.b_dir) > 0.4) {
|
|
|
|
self.b_aiflags &= ~AI_DIRECTIONAL;
|
|
|
|
bot_lost (self.target1, TRUE);
|
2003-02-18 23:11:05 +00:00
|
|
|
}
|
|
|
|
}
|
2003-03-04 18:26:17 +00:00
|
|
|
if (self.b_aiflags & AI_SNIPER) {
|
2003-03-08 03:20:32 +00:00
|
|
|
self.b_aiflags |= AI_WAIT | AI_PRECISION | AI_SNIPER;
|
2003-02-18 23:11:05 +00:00
|
|
|
// FIXME: Add a switch to wep command
|
|
|
|
// FIXME: increase delay?
|
|
|
|
}
|
2003-03-04 18:26:17 +00:00
|
|
|
if (self.b_aiflags & AI_AMBUSH) {
|
2003-03-08 03:20:32 +00:00
|
|
|
self.b_aiflags |= AI_WAIT | AI_AMBUSH;
|
2003-02-18 23:11:05 +00:00
|
|
|
// FIXME: Add a switch to wep command
|
|
|
|
// FIXME: increase delay?
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
|
|
|
|
|
|
|
bot_path
|
|
|
|
|
|
|
|
Bot will follow a route generated by the
|
|
|
|
begin_route set of functions in bot_way.qc.
|
|
|
|
This code, while it works pretty well, can get
|
|
|
|
confused
|
|
|
|
|
|
|
|
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
|
|
|
*/
|
|
|
|
|
|
|
|
void() bot_path =
|
|
|
|
{
|
|
|
|
|
|
|
|
local entity jj, tele;
|
|
|
|
|
2003-03-08 03:20:32 +00:00
|
|
|
bot_check_lost (self.target1);
|
2003-03-04 18:26:17 +00:00
|
|
|
if (!self.target1) {
|
2003-02-18 23:11:05 +00:00
|
|
|
self.keys=0;
|
|
|
|
return;
|
|
|
|
}
|
2003-03-08 03:20:32 +00:00
|
|
|
if (target_onstack (self.last_way))
|
2003-02-18 23:11:05 +00:00
|
|
|
return; // old waypoint still being hunted
|
|
|
|
|
2003-03-08 03:20:32 +00:00
|
|
|
jj = FindRoute (self.last_way);
|
2003-03-04 18:26:17 +00:00
|
|
|
if (!jj) {
|
2003-02-18 23:11:05 +00:00
|
|
|
// this is an ugly hack
|
2003-03-04 18:26:17 +00:00
|
|
|
if (self.target1.current_way != self.last_way) {
|
2003-02-18 23:11:05 +00:00
|
|
|
if (self.target1.classname != "temp_waypoint")
|
|
|
|
if (self.target1.classname != "player")
|
2003-03-08 03:20:32 +00:00
|
|
|
bot_lost (self.target1, FALSE);
|
2003-02-18 23:11:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// update the bot's special ai features
|
|
|
|
|
|
|
|
// Readahed types are AI conditions to perform while heading to a waypoint
|
|
|
|
// point types are AI flags that should be executed once reaching a waypoint
|
|
|
|
|
|
|
|
self.b_aiflags = (jj.b_aiflags & AI_READAHEAD_TYPES) | (self.last_way.b_aiflags & AI_POINT_TYPES);
|
2003-03-08 03:20:32 +00:00
|
|
|
target_add (jj);
|
2003-03-04 18:26:17 +00:00
|
|
|
if (self.last_way) {
|
2003-03-08 03:20:32 +00:00
|
|
|
if (CheckLinked (self.last_way, jj) == 2) {
|
2003-03-04 18:48:44 +00:00
|
|
|
// waypoints are telelinked
|
2003-03-08 03:20:32 +00:00
|
|
|
tele = FindThing ("trigger_teleport"); // this is probbly the teleport responsible
|
|
|
|
target_add (tele);
|
2003-02-18 23:11:05 +00:00
|
|
|
}
|
2003-03-08 03:20:32 +00:00
|
|
|
traceline (self.last_way.origin, jj.origin, FALSE, self); // check for blockage
|
2003-03-04 18:26:17 +00:00
|
|
|
if (trace_fraction != 1) {
|
|
|
|
if (trace_ent.classname == "door" && !(self.b_aiflags & AI_DOOR_NO_OPEN)) {
|
|
|
|
// a door blocks the way
|
2003-02-18 23:11:05 +00:00
|
|
|
// linked doors fix
|
|
|
|
if (trace_ent.owner)
|
|
|
|
trace_ent = trace_ent.owner;
|
2003-03-04 18:26:17 +00:00
|
|
|
if ((trace_ent.health > 0) && (self.enemy == NIL)) {
|
2003-02-18 23:11:05 +00:00
|
|
|
self.enemy = trace_ent;
|
2003-03-08 03:20:32 +00:00
|
|
|
bot_weapon_switch (1);
|
2003-02-18 23:11:05 +00:00
|
|
|
self.b_aiflags = self.b_aiflags | AI_BLIND; // nick knack paddy hack
|
2003-03-04 18:26:17 +00:00
|
|
|
} else if (trace_ent.targetname) {
|
2003-03-08 03:20:32 +00:00
|
|
|
tele = find (NIL, target, trace_ent.targetname);
|
2003-03-04 18:26:17 +00:00
|
|
|
if (tele.health > 0) {
|
2003-02-18 23:11:05 +00:00
|
|
|
self.enemy = tele;
|
2003-03-08 03:20:32 +00:00
|
|
|
bot_weapon_switch (1);
|
2003-03-04 18:26:17 +00:00
|
|
|
} else {
|
2003-03-08 03:20:32 +00:00
|
|
|
// target_drop (jj);
|
|
|
|
target_add (tele);
|
|
|
|
// bot_get_path (tele, TRUE);
|
|
|
|
self.b_aiflags |= AI_BLIND; // give a bot a bone
|
2003-02-18 23:11:05 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2003-03-04 18:26:17 +00:00
|
|
|
} else if (trace_ent.classname == "func_wall") {
|
2003-02-18 23:11:05 +00:00
|
|
|
// give up
|
2003-03-08 03:20:32 +00:00
|
|
|
bot_lost (self.target1, FALSE);
|
2003-02-18 23:11:05 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// this is used for AI_DRIECTIONAL
|
2003-03-08 03:20:32 +00:00
|
|
|
self.b_dir = normalize (jj.origin - self.last_way.origin);
|
2003-02-18 23:11:05 +00:00
|
|
|
|
|
|
|
self.last_way = jj;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
|
|
|
|
|
|
|
Bot Priority Look. What a stupid name. This is where
|
|
|
|
the bot finds things it wants to kill/grab.
|
|
|
|
|
|
|
|
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
|
|
|
*/
|
|
|
|
// priority scale
|
|
|
|
// 0 - 10 virtually ignore
|
|
|
|
// 10 - 30 normal item range
|
|
|
|
// 30 - 50 bot will consider this a target worth changing course for
|
|
|
|
// 50 - 90 bot will hunt these as vital items
|
|
|
|
|
|
|
|
// *!* Make sure you add code to bot_check_lost to remove the target *!*
|
|
|
|
|
|
|
|
float(entity thing) priority_for_thing =
|
|
|
|
{
|
|
|
|
local float thisp;
|
2003-03-08 03:20:32 +00:00
|
|
|
|
2003-02-18 23:11:05 +00:00
|
|
|
thisp = 0;
|
|
|
|
// This is the most executed function in the bot. Careful what you do here.
|
2003-03-04 18:26:17 +00:00
|
|
|
if ((thing.flags & FL_ITEM) && thing.model && thing.search_time < time) {
|
2003-02-18 23:11:05 +00:00
|
|
|
// ugly hack
|
2003-03-08 03:20:32 +00:00
|
|
|
if (thing._last != self)
|
|
|
|
thisp = 20;
|
2003-02-18 23:11:05 +00:00
|
|
|
if (thing.classname == "item_artifact_super_damage")
|
|
|
|
thisp = 65;
|
|
|
|
else if (thing.classname == "item_artifact_invulnerability")
|
|
|
|
thisp = 65;
|
2003-03-04 18:26:17 +00:00
|
|
|
else if (thing.classname == "item_health") {
|
2003-02-18 23:11:05 +00:00
|
|
|
if (thing.spawnflags & 2)
|
|
|
|
thisp = 55;
|
|
|
|
if (self.health < 40)
|
|
|
|
thisp = thisp + 50;
|
2003-03-04 18:26:17 +00:00
|
|
|
} else if (thing.model == "progs/armor.mdl") {
|
|
|
|
if (self.armorvalue < 200) {
|
2003-02-18 23:11:05 +00:00
|
|
|
if (thing.skin == 2)
|
|
|
|
thisp = 60;
|
|
|
|
else if (self.armorvalue < 100)
|
|
|
|
thisp = thisp + 25;
|
|
|
|
}
|
2003-03-04 18:26:17 +00:00
|
|
|
} else if (thing.classname == "weapon_supershotgun") {
|
2003-02-18 23:11:05 +00:00
|
|
|
if (!(self.items & 2)) // IT_SUPER_SHOTGUN
|
|
|
|
thisp = 25;
|
2003-03-04 18:26:17 +00:00
|
|
|
} else if (thing.classname == "weapon_nailgun") {
|
2003-02-18 23:11:05 +00:00
|
|
|
if (!(self.items & 4)) // IT_NAILGUN
|
|
|
|
thisp = 30;
|
2003-03-04 18:26:17 +00:00
|
|
|
} else if (thing.classname == "weapon_supernailgun") {
|
2003-02-18 23:11:05 +00:00
|
|
|
if (!(self.items & 8)) // IT_SUPER_NAILGUN
|
|
|
|
thisp = 35;
|
2003-03-04 18:26:17 +00:00
|
|
|
} else if (thing.classname == "weapon_grenadelauncher") {
|
2003-02-18 23:11:05 +00:00
|
|
|
if (!(self.items & 16)) // IT_GRENADE_LAUNCHER
|
|
|
|
thisp = 45;
|
2003-03-04 18:26:17 +00:00
|
|
|
} else if (thing.classname == "weapon_rocketlauncher") {
|
2003-02-18 23:11:05 +00:00
|
|
|
if (!(self.items & 32)) // IT_ROCKET_LAUNCHER
|
|
|
|
thisp = 60;
|
2003-03-04 18:26:17 +00:00
|
|
|
} else if (thing.classname == "weapon_lightning") {
|
2003-02-18 23:11:05 +00:00
|
|
|
if (!(self.items & 64)) // IT_LIGHTNING
|
|
|
|
thisp = 50;
|
|
|
|
}
|
2003-03-04 18:26:17 +00:00
|
|
|
} else if ((thing.flags & FL_MONSTER) && thing.health > 0)
|
2003-02-18 23:11:05 +00:00
|
|
|
thisp = 45;
|
2003-03-04 18:26:17 +00:00
|
|
|
else if (thing.classname == "player") {
|
|
|
|
if (thing.health > 0) {
|
2003-02-18 23:11:05 +00:00
|
|
|
if (thing == self)
|
|
|
|
return 0;
|
2003-03-04 18:26:17 +00:00
|
|
|
else {
|
2003-02-18 23:11:05 +00:00
|
|
|
if (thing.items & IT_INVISIBILITY) //FIXME
|
|
|
|
thisp = 2;
|
2003-03-04 18:26:17 +00:00
|
|
|
else if (coop) {
|
2003-02-18 23:11:05 +00:00
|
|
|
thisp = 100;
|
|
|
|
if (thing.target1.classname == "player")
|
|
|
|
if (!thing.target1.ishuman)
|
|
|
|
return 0;
|
2003-03-04 18:26:17 +00:00
|
|
|
} else if (teamplay && thing.team == self.team) {
|
2003-02-18 23:11:05 +00:00
|
|
|
thisp = 100;
|
|
|
|
if (thing.target1.classname == "player")
|
|
|
|
return 0;
|
2003-03-04 18:26:17 +00:00
|
|
|
} else
|
|
|
|
thisp = 30;
|
2003-02-18 23:11:05 +00:00
|
|
|
}
|
|
|
|
}
|
2003-03-04 18:26:17 +00:00
|
|
|
} else if (thing.classname == "waypoint") {
|
2003-02-18 23:11:05 +00:00
|
|
|
if (thing.b_aiflags & AI_SNIPER)
|
|
|
|
thisp = 30;
|
|
|
|
else if (thing.b_aiflags & AI_AMBUSH)
|
|
|
|
thisp = 30;
|
|
|
|
}
|
2003-03-08 03:20:32 +00:00
|
|
|
if (pointcontents (thing.origin) < -3)
|
2003-02-18 23:11:05 +00:00
|
|
|
return 0;
|
2003-03-04 18:26:17 +00:00
|
|
|
if (thisp) {
|
|
|
|
if (thing.current_way) {
|
2003-02-18 23:11:05 +00:00
|
|
|
// check to see if it's unreachable
|
|
|
|
if (thing.current_way.items == -1)
|
|
|
|
return 0;
|
|
|
|
else
|
2003-03-08 03:20:32 +00:00
|
|
|
thisp += (13000 - thing.current_way.items) * 0.05;
|
2003-02-18 23:11:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return thisp;
|
|
|
|
};
|
|
|
|
|
|
|
|
void(float scope) bot_look_for_crap =
|
|
|
|
{
|
2003-02-24 16:05:25 +00:00
|
|
|
local entity foe, best = NIL;
|
2003-02-18 23:11:05 +00:00
|
|
|
local float thatp, bestp, dist;
|
|
|
|
|
|
|
|
if (scope == 1)
|
2003-03-08 03:20:32 +00:00
|
|
|
foe = findradius (self.origin, 13000);
|
2003-02-18 23:11:05 +00:00
|
|
|
else
|
2003-03-08 03:20:32 +00:00
|
|
|
foe = findradius (self.origin, 500);
|
2003-02-18 23:11:05 +00:00
|
|
|
|
|
|
|
bestp = 1;
|
2003-03-08 03:20:32 +00:00
|
|
|
while (foe) {
|
|
|
|
thatp = priority_for_thing (foe);
|
2003-02-18 23:11:05 +00:00
|
|
|
if (thatp)
|
|
|
|
if (!scope)
|
2003-03-08 03:20:32 +00:00
|
|
|
if (!sisible (foe))
|
2003-02-18 23:11:05 +00:00
|
|
|
thatp = 0;
|
2003-03-04 18:26:17 +00:00
|
|
|
if (thatp > bestp) {
|
2003-02-18 23:11:05 +00:00
|
|
|
bestp = thatp;
|
|
|
|
best = foe;
|
2003-03-08 03:20:32 +00:00
|
|
|
dist = vlen (self.origin - foe.origin);
|
2003-02-18 23:11:05 +00:00
|
|
|
}
|
|
|
|
foe = foe.chain;
|
|
|
|
}
|
2003-02-24 16:05:25 +00:00
|
|
|
if (best == NIL)
|
2003-02-18 23:11:05 +00:00
|
|
|
return;
|
2003-03-08 03:20:32 +00:00
|
|
|
if (!target_onstack (best)) {
|
|
|
|
target_add (best);
|
2003-03-04 18:26:17 +00:00
|
|
|
if (scope) {
|
2003-03-08 03:20:32 +00:00
|
|
|
bot_get_path (best, FALSE);
|
|
|
|
self.b_aiflags |= AI_WAIT;
|
2003-02-18 23:11:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
|
|
|
|
|
|
|
bot_angle_set
|
|
|
|
|
|
|
|
Sets the bots look keys & b_angle to point at
|
|
|
|
the target - used for fighting and just
|
|
|
|
generally making the bot look good.
|
|
|
|
|
|
|
|
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
|
|
|
*/
|
|
|
|
void() bot_angle_set =
|
|
|
|
{
|
|
|
|
local float h;
|
|
|
|
local vector view;
|
|
|
|
|
2003-03-04 18:26:17 +00:00
|
|
|
if (self.enemy) {
|
2003-02-18 23:11:05 +00:00
|
|
|
if (self.enemy.items & 524288)
|
2003-03-08 03:20:32 +00:00
|
|
|
if (random () > 0.2)
|
2003-02-18 23:11:05 +00:00
|
|
|
return;
|
|
|
|
if (self.missile_speed == 0)
|
|
|
|
self.missile_speed = 10000;
|
2003-03-04 18:26:17 +00:00
|
|
|
if (self.enemy.solid == SOLID_BSP) {
|
2003-02-18 23:11:05 +00:00
|
|
|
view = (((self.enemy.absmin + self.enemy.absmax) * 0.5) - self.origin);
|
2003-03-04 18:26:17 +00:00
|
|
|
} else {
|
2003-03-08 03:20:32 +00:00
|
|
|
h = vlen (self.enemy.origin - self.origin) / self.missile_speed;
|
2003-02-18 23:11:05 +00:00
|
|
|
if (self.enemy.flags & FL_ONGROUND)
|
|
|
|
view = self.enemy.velocity * h;
|
|
|
|
else
|
|
|
|
view = (self.enemy.velocity - (sv_gravity * '0 0 1') * h) * h;
|
|
|
|
view = self.enemy.origin + view;
|
|
|
|
// FIXME: ?
|
2003-03-08 03:20:32 +00:00
|
|
|
traceline (self.enemy.origin, view, FALSE, self);
|
2003-02-18 23:11:05 +00:00
|
|
|
view = trace_endpos;
|
|
|
|
|
|
|
|
if (self.weapon == 32)
|
|
|
|
view = view - '0 0 22';
|
|
|
|
|
2003-03-08 03:20:32 +00:00
|
|
|
view = normalize (view - self.origin);
|
2003-02-18 23:11:05 +00:00
|
|
|
}
|
2003-03-08 03:20:32 +00:00
|
|
|
view = vectoangles (view);
|
2003-02-18 23:11:05 +00:00
|
|
|
view_x = view_x * -1;
|
|
|
|
self.b_angle = view;
|
2003-03-04 18:26:17 +00:00
|
|
|
} else if (self.target1) {
|
2003-03-08 03:20:32 +00:00
|
|
|
view = realorigin (self.target1);
|
2003-02-18 23:11:05 +00:00
|
|
|
if (self.target1.flags & FL_ITEM)
|
|
|
|
view = view + '0 0 48';
|
2003-03-08 03:20:32 +00:00
|
|
|
view -= (self.origin + self.view_ofs);
|
|
|
|
view = vectoangles (view);
|
|
|
|
view_x *= -1;
|
2003-02-18 23:11:05 +00:00
|
|
|
self.b_angle = view;
|
2003-03-04 18:26:17 +00:00
|
|
|
} else
|
2003-02-18 23:11:05 +00:00
|
|
|
self.b_angle_x = 0;
|
|
|
|
// HACK HACK HACK HACK
|
|
|
|
// The bot falls off ledges a lot because of "turning around"
|
|
|
|
// so let the bot use instant turn around when not hunting a player
|
2003-03-04 18:26:17 +00:00
|
|
|
if (self.b_skill == 3) {
|
2003-02-18 23:11:05 +00:00
|
|
|
self.keys = self.keys & 63;
|
|
|
|
self.v_angle = self.b_angle;
|
|
|
|
while (self.v_angle_x < -180)
|
2003-03-08 03:20:32 +00:00
|
|
|
self.v_angle_x += 360;
|
2003-02-18 23:11:05 +00:00
|
|
|
while (self.v_angle_x > 180)
|
2003-03-08 03:20:32 +00:00
|
|
|
self.v_angle_x -= 360;
|
2003-03-04 18:26:17 +00:00
|
|
|
} else if ((self.enemy == NIL || self.enemy.movetype == MOVETYPE_PUSH) && self.target1.classname != "player") {
|
2003-02-18 23:11:05 +00:00
|
|
|
self.keys = self.keys & 63;
|
|
|
|
self.v_angle = self.b_angle;
|
|
|
|
while (self.v_angle_x < -180)
|
2003-03-08 03:20:32 +00:00
|
|
|
self.v_angle_x += 360;
|
2003-02-18 23:11:05 +00:00
|
|
|
while (self.v_angle_x > 180)
|
2003-03-08 03:20:32 +00:00
|
|
|
self.v_angle_x -= 360;
|
2003-03-04 18:26:17 +00:00
|
|
|
} else if (self.b_skill < 2) {
|
|
|
|
// skill 2 handled in bot_phys
|
2003-02-18 23:11:05 +00:00
|
|
|
if (self.b_angle_x > 180)
|
2003-03-08 03:20:32 +00:00
|
|
|
self.b_angle_x -= 360;
|
2003-02-18 23:11:05 +00:00
|
|
|
self.keys = self.keys & 63;
|
|
|
|
|
2003-03-08 03:20:32 +00:00
|
|
|
if (angcomp (self.b_angle_y, self.v_angle_y) > 10)
|
|
|
|
self.keys = KEY_LOOKLEFT;
|
2003-02-18 23:11:05 +00:00
|
|
|
else if (angcomp(self.b_angle_y, self.v_angle_y) < -10)
|
2003-03-08 03:20:32 +00:00
|
|
|
self.keys |= KEY_LOOKRIGHT;
|
2003-02-18 23:11:05 +00:00
|
|
|
if (angcomp(self.b_angle_x, self.v_angle_x) < -10)
|
2003-03-08 03:20:32 +00:00
|
|
|
self.keys |= KEY_LOOKUP;
|
|
|
|
else if (angcomp (self.b_angle_x, self.v_angle_x) > 10)
|
|
|
|
self.keys |= KEY_LOOKDOWN;
|
2003-02-18 23:11:05 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
|
|
|
|
|
|
|
BotAI
|
|
|
|
|
|
|
|
This is the main ai loop. Though called every
|
|
|
|
frame, the ai_time limits it's actual updating
|
|
|
|
|
|
|
|
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
|
|
|
*/
|
|
|
|
float stagger_think;
|
|
|
|
|
|
|
|
void() BotAI =
|
|
|
|
{
|
|
|
|
// am I dead? Fire randomly until I respawn
|
|
|
|
// health < 1 is used because fractional healths show up as 0 on normal player
|
|
|
|
// status bars, and the mod probably already compensated for that
|
|
|
|
|
2003-03-04 18:26:17 +00:00
|
|
|
if (self.health < 1) {
|
2003-03-08 03:20:32 +00:00
|
|
|
self.button0 = floor (random() * 2);
|
2003-02-18 23:11:05 +00:00
|
|
|
self.button2 = 0;
|
|
|
|
self.keys = 0;
|
|
|
|
self.b_aiflags = 0;
|
2003-03-08 03:20:32 +00:00
|
|
|
ClearMyRoute ();
|
2003-02-24 16:05:25 +00:00
|
|
|
self.target1 = self.target2 = self.target3 = self.target4 = self.enemy = NIL;
|
|
|
|
self.last_way = NIL;
|
2003-02-18 23:11:05 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// stagger the bot's AI out so they all don't think at the same time, causing game
|
|
|
|
// 'spikes'
|
2003-03-04 18:26:17 +00:00
|
|
|
if (self.b_skill < 2) {
|
2003-02-18 23:11:05 +00:00
|
|
|
if (self.ai_time > time)
|
|
|
|
return;
|
|
|
|
|
|
|
|
self.ai_time = time + 0.05;
|
2003-03-04 18:26:17 +00:00
|
|
|
if (bot_count > 0) {
|
2003-02-18 23:11:05 +00:00
|
|
|
if ((time - stagger_think) < (0.1 / bot_count))
|
2003-03-08 03:20:32 +00:00
|
|
|
self.ai_time += 0.1 / (2 * bot_count);
|
2003-03-04 18:26:17 +00:00
|
|
|
} else
|
2003-02-18 23:11:05 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (self.view_ofs == '0 0 0')
|
2003-03-08 03:20:32 +00:00
|
|
|
bot_start_topic (7);
|
2003-02-18 23:11:05 +00:00
|
|
|
stagger_think = time;
|
|
|
|
|
|
|
|
// shut the bot's buttons off, various functions will turn them on by AI end
|
|
|
|
self.button2 = 0;
|
|
|
|
self.button0 = 0;
|
|
|
|
|
|
|
|
// target1 is like goalentity in normal Quake monster AI.
|
|
|
|
// it's the bot's most immediate target
|
2003-03-04 18:26:17 +00:00
|
|
|
if (route_table == self) {
|
|
|
|
if (busy_waypoints <= 0) {
|
2003-02-18 23:11:05 +00:00
|
|
|
if (waypoint_mode < WM_EDITOR)
|
|
|
|
bot_look_for_crap(TRUE);
|
|
|
|
}
|
|
|
|
self.b_aiflags = 0;
|
|
|
|
self.keys = 0;
|
2003-03-04 18:26:17 +00:00
|
|
|
} else if (self.target1) {
|
2003-03-08 03:20:32 +00:00
|
|
|
frik_movetogoal ();
|
|
|
|
bot_path ();
|
2003-03-04 18:26:17 +00:00
|
|
|
} else {
|
|
|
|
if (waypoint_mode < WM_EDITOR) {
|
2003-03-08 03:20:32 +00:00
|
|
|
if (self.route_failed) {
|
2003-03-04 18:26:17 +00:00
|
|
|
frik_bot_roam();
|
|
|
|
self.route_failed = 0;
|
2003-03-08 03:20:32 +00:00
|
|
|
} else if (!begin_route()) {
|
|
|
|
bot_look_for_crap (FALSE);
|
2003-03-04 18:26:17 +00:00
|
|
|
}
|
2003-02-18 23:11:05 +00:00
|
|
|
self.keys = 0;
|
2003-03-04 18:26:17 +00:00
|
|
|
} else {
|
2003-02-18 23:11:05 +00:00
|
|
|
self.b_aiflags = AI_WAIT;
|
|
|
|
self.keys = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// bot_angle_set points the bot at it's goal (self.enemy or target1)
|
2003-03-08 03:20:32 +00:00
|
|
|
bot_angle_set ();
|
2003-02-18 23:11:05 +00:00
|
|
|
|
2003-03-08 03:20:32 +00:00
|
|
|
// fight my enemy. Enemy is probably a field QC coders will most likely
|
|
|
|
// use a lot for their own needs, since it's unused on a normal player
|
2003-02-18 23:11:05 +00:00
|
|
|
// FIXME
|
|
|
|
if (self.enemy)
|
2003-03-08 03:20:32 +00:00
|
|
|
bot_fight_style ();
|
|
|
|
else if (random () < 0.2)
|
|
|
|
if (random () < 0.2)
|
|
|
|
bot_weapon_switch (-1);
|
|
|
|
bot_dodge_stuff ();
|
2003-02-18 23:11:05 +00:00
|
|
|
|
|
|
|
// checks to see if bot needs to start going up for air
|
2003-03-04 18:26:17 +00:00
|
|
|
if (self.waterlevel > 2) {
|
|
|
|
if (time > (self.air_finished - 2)) {
|
2003-02-18 23:11:05 +00:00
|
|
|
traceline (self.origin, self.origin + '0 0 6800', TRUE, self);
|
2003-03-08 03:20:32 +00:00
|
|
|
if (trace_inopen) {
|
2003-02-18 23:11:05 +00:00
|
|
|
self.keys = KEY_MOVEUP;
|
|
|
|
self.button2 = TRUE; // swim!
|
|
|
|
return; // skip ai flags for now - this is life or death
|
|
|
|
}
|
|
|
|
}
|
2003-03-04 18:26:17 +00:00
|
|
|
}
|
2003-02-18 23:11:05 +00:00
|
|
|
|
|
|
|
// b_aiflags handling
|
|
|
|
if (self.b_aiflags)
|
2003-03-08 03:20:32 +00:00
|
|
|
bot_handle_ai ();
|
2003-02-18 23:11:05 +00:00
|
|
|
else
|
2003-03-08 03:20:32 +00:00
|
|
|
bot_chat (); // don't want chat to screw him up if he's rjing or something
|
2003-02-18 23:11:05 +00:00
|
|
|
};
|
2003-07-23 06:35:39 +00:00
|
|
|
|
|
|
|
@end
|