2003-02-18 23:11:05 +00:00
|
|
|
/***********************************************
|
|
|
|
* *
|
|
|
|
* 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.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2003-02-24 16:05:25 +00:00
|
|
|
#include "libfrikbot.h"
|
|
|
|
|
2003-07-24 18:25:46 +00:00
|
|
|
Waypoint way_foot; // Ugh. Do I need a foot for this or not?
|
2003-07-24 08:25:04 +00:00
|
|
|
|
2003-07-24 18:23:13 +00:00
|
|
|
@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
|
|
|
|
|
2003-03-08 03:20:32 +00:00
|
|
|
// Waypoint Linking code ======================================================
|
2003-02-18 23:11:05 +00:00
|
|
|
|
2003-07-24 18:25:46 +00:00
|
|
|
@implementation Waypoint
|
2003-07-24 08:25:04 +00:00
|
|
|
|
2003-07-24 18:25:46 +00:00
|
|
|
-(integer)isLinkedTo:(Waypoint)way
|
2003-02-18 23:11:05 +00:00
|
|
|
{
|
2003-07-24 08:25:04 +00:00
|
|
|
local integer i;
|
2003-03-08 03:20:32 +00:00
|
|
|
|
2003-07-24 08:25:04 +00:00
|
|
|
if (way == self || !way || !self)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
if (targets[i] == way) {
|
|
|
|
if (flags & (AI_TELELINK_1 << i))
|
|
|
|
return 2;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2003-02-18 23:11:05 +00:00
|
|
|
|
2003-07-24 18:25:46 +00:00
|
|
|
-(integer)linkWay:(Waypoint)way
|
2003-02-18 23:11:05 +00:00
|
|
|
{
|
2003-07-24 08:25:04 +00:00
|
|
|
local integer i;
|
2003-02-18 23:11:05 +00:00
|
|
|
|
2003-07-24 08:25:04 +00:00
|
|
|
if (self == way || !self || !way)
|
|
|
|
return 0;
|
|
|
|
else if ([self isLinkedTo:way])
|
|
|
|
return 0; // already linked!!!
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
if (!targets[i]) {
|
|
|
|
targets[i] = way;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2003-02-18 23:11:05 +00:00
|
|
|
|
2003-03-08 03:20:32 +00:00
|
|
|
// Link Ways part 2, used only for teleporters
|
2003-07-24 18:25:46 +00:00
|
|
|
-(integer)teleLinkWay:(Waypoint)way
|
2003-02-18 23:11:05 +00:00
|
|
|
{
|
2003-07-24 08:25:04 +00:00
|
|
|
local integer i;
|
|
|
|
|
|
|
|
if (self == way || !self || !way)
|
|
|
|
return 0;
|
|
|
|
else if ([self isLinkedTo:way])
|
|
|
|
return 0; // already linked!!!
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
if (!targets[i]) {
|
|
|
|
targets[i] = way;
|
|
|
|
flags |= AI_TELELINK_1 << i;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2003-02-18 23:11:05 +00:00
|
|
|
|
2003-07-24 18:25:46 +00:00
|
|
|
-(void)unlinkWay:(Waypoint)way
|
2003-02-18 23:11:05 +00:00
|
|
|
{
|
2003-07-24 08:25:04 +00:00
|
|
|
local integer i;
|
|
|
|
|
|
|
|
if (self == way || !self || !way)
|
2003-02-18 23:11:05 +00:00
|
|
|
return;
|
2003-07-24 08:25:04 +00:00
|
|
|
else if (![self isLinkedTo:way])
|
2003-02-18 23:11:05 +00:00
|
|
|
return;
|
|
|
|
|
2003-07-24 08:25:04 +00:00
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
if (targets[i] == way) {
|
|
|
|
flags &= ~(AI_TELELINK_1 << i);
|
|
|
|
targets[i] = NIL;
|
|
|
|
}
|
2003-02-18 23:11:05 +00:00
|
|
|
}
|
2003-07-24 08:25:04 +00:00
|
|
|
}
|
2003-02-18 23:11:05 +00:00
|
|
|
|
2003-07-24 08:25:04 +00:00
|
|
|
// Waypoint Spawning Code =====================================================
|
2003-02-18 23:11:05 +00:00
|
|
|
|
2003-07-24 08:25:04 +00:00
|
|
|
-(id)initAt:(vector)org
|
2003-02-18 23:11:05 +00:00
|
|
|
{
|
2003-07-24 08:25:04 +00:00
|
|
|
count = ++waypoints;
|
|
|
|
if (!way_head) {
|
|
|
|
way_head = self;
|
|
|
|
way_foot = self;
|
2003-03-04 18:26:17 +00:00
|
|
|
} else {
|
2003-07-24 08:25:04 +00:00
|
|
|
way_foot.next = self;
|
|
|
|
self.prev = way_foot;
|
|
|
|
way_foot = self;
|
2003-02-18 23:11:05 +00:00
|
|
|
}
|
2003-07-24 08:25:04 +00:00
|
|
|
return self;
|
|
|
|
}
|
2003-02-18 23:11:05 +00:00
|
|
|
|
2003-07-24 08:25:04 +00:00
|
|
|
-(id)initFromEntity:(entity)ent
|
|
|
|
{
|
|
|
|
[self initAt:ent.origin];
|
|
|
|
}
|
|
|
|
/*
|
2003-03-08 03:20:32 +00:00
|
|
|
entity (vector org)
|
|
|
|
make_waypoint =
|
2003-02-18 23:11:05 +00:00
|
|
|
{
|
|
|
|
local entity point;
|
2003-03-08 03:20:32 +00:00
|
|
|
|
|
|
|
point = spawn ();
|
2003-02-18 23:11:05 +00:00
|
|
|
point.classname = "waypoint";
|
2003-07-24 08:25:04 +00:00
|
|
|
|
2003-02-18 23:11:05 +00:00
|
|
|
point.search_time = time; // don't double back for me;
|
|
|
|
point.solid = SOLID_TRIGGER;
|
|
|
|
point.movetype = MOVETYPE_NONE;
|
|
|
|
point.items = -1;
|
2003-03-08 03:20:32 +00:00
|
|
|
setorigin (point, org);
|
2003-02-18 23:11:05 +00:00
|
|
|
|
2003-03-08 03:20:32 +00:00
|
|
|
setsize (point, VEC_HULL_MIN, VEC_HULL_MAX);
|
|
|
|
waypoints++;
|
2003-03-04 18:26:17 +00:00
|
|
|
if (!way_head) {
|
2003-02-18 23:11:05 +00:00
|
|
|
way_head = point;
|
|
|
|
way_foot = point;
|
2003-03-04 18:26:17 +00:00
|
|
|
} else {
|
2003-02-18 23:11:05 +00:00
|
|
|
way_foot._next = point;
|
|
|
|
point._last = way_foot;
|
|
|
|
way_foot = point;
|
|
|
|
}
|
|
|
|
|
|
|
|
point.count = waypoints;
|
|
|
|
if (waypoint_mode > WM_LOADED) // editor modes
|
2003-03-08 03:20:32 +00:00
|
|
|
setmodel (point, "progs/s_bubble.spr");
|
2003-02-18 23:11:05 +00:00
|
|
|
return point;
|
|
|
|
};
|
2003-07-24 08:25:04 +00:00
|
|
|
*/
|
2003-02-18 23:11:05 +00:00
|
|
|
|
|
|
|
/*
|
2003-07-24 08:25:04 +00:00
|
|
|
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
|
|
|
|
|
|
|
Waypoint Loading from file
|
|
|
|
|
|
|
|
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
2003-02-18 23:11:05 +00:00
|
|
|
*/
|
2003-07-24 08:25:04 +00:00
|
|
|
|
|
|
|
+(void)clearAll
|
2003-02-18 23:11:05 +00:00
|
|
|
{
|
|
|
|
|
2003-07-24 18:25:46 +00:00
|
|
|
local Waypoint t, n;
|
2003-07-24 08:25:04 +00:00
|
|
|
|
|
|
|
t = way_head;
|
|
|
|
while(t) {
|
|
|
|
n = t.next;
|
|
|
|
[t free];
|
|
|
|
t = n;
|
2003-02-18 23:11:05 +00:00
|
|
|
}
|
2003-07-24 08:25:04 +00:00
|
|
|
way_head = NIL;
|
|
|
|
way_foot = NIL;
|
|
|
|
waypoints = 0;
|
|
|
|
}
|
2003-02-18 23:11:05 +00:00
|
|
|
|
2003-07-24 18:25:46 +00:00
|
|
|
+(Waypoint)waypointForNum:(integer)num
|
2003-07-24 08:25:04 +00:00
|
|
|
{
|
2003-07-24 18:25:46 +00:00
|
|
|
local Waypoint t;
|
2003-07-24 08:25:04 +00:00
|
|
|
if (!num)
|
|
|
|
return NIL;
|
2003-02-18 23:11:05 +00:00
|
|
|
|
2003-07-24 08:25:04 +00:00
|
|
|
t = way_head;
|
|
|
|
while (t) {
|
|
|
|
if (t.count == num)
|
|
|
|
return t;
|
|
|
|
t = t.next;
|
2003-02-18 23:11:05 +00:00
|
|
|
}
|
2003-07-24 08:25:04 +00:00
|
|
|
return NIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
-(void)fix
|
|
|
|
{
|
2003-07-24 18:25:46 +00:00
|
|
|
targets[0] = [Waypoint waypointForNum:b_pants];
|
|
|
|
targets[1] = [Waypoint waypointForNum:b_skill];
|
|
|
|
targets[2] = [Waypoint waypointForNum:b_shirt];
|
|
|
|
targets[3] = [Waypoint waypointForNum:b_frags];
|
2003-07-24 08:25:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+(void) fixWaypoints
|
|
|
|
{
|
2003-07-24 18:25:46 +00:00
|
|
|
local Waypoint way;
|
2003-07-24 08:25:04 +00:00
|
|
|
|
|
|
|
for (way = way_head; way; way = way.next)
|
|
|
|
[way fix];
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
|
|
|
|
|
|
|
Route & path table management
|
|
|
|
|
|
|
|
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
|
|
|
*/
|
|
|
|
|
|
|
|
+(void)clearRouteTable
|
|
|
|
{
|
|
|
|
// cleans up route table
|
|
|
|
|
2003-07-24 18:25:46 +00:00
|
|
|
local Waypoint t;
|
2003-07-24 08:25:04 +00:00
|
|
|
t = way_head;
|
|
|
|
while (t) {
|
|
|
|
t.keys = FALSE;
|
|
|
|
t.enemy = NIL;
|
|
|
|
t.items = -1; // not in table
|
|
|
|
t = t.next;
|
2003-02-18 23:11:05 +00:00
|
|
|
}
|
2003-07-24 08:25:04 +00:00
|
|
|
}
|
2003-02-18 23:11:05 +00:00
|
|
|
|
2003-07-24 08:25:04 +00:00
|
|
|
+(void)clearMyRoute:(Bot) bot
|
|
|
|
{
|
|
|
|
local integer flag;
|
2003-07-24 18:25:46 +00:00
|
|
|
local Waypoint t;
|
2003-07-24 08:25:04 +00:00
|
|
|
|
|
|
|
flag = ClientBitFlag(bot.b_clientno);
|
|
|
|
|
|
|
|
t = way_head;
|
|
|
|
while (t) {
|
|
|
|
t.b_sound &= ~flag;
|
|
|
|
t = t.next;
|
2003-02-18 23:11:05 +00:00
|
|
|
}
|
2003-07-24 08:25:04 +00:00
|
|
|
}
|
2003-02-18 23:11:05 +00:00
|
|
|
|
2003-07-24 08:25:04 +00:00
|
|
|
/*
|
|
|
|
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
|
|
|
|
|
|
|
WaypointThink
|
|
|
|
|
|
|
|
Calculates the routes. We use thinks to avoid
|
|
|
|
tripping the runaway loop counter
|
|
|
|
|
|
|
|
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
|
|
|
*/
|
|
|
|
|
2003-07-24 18:25:46 +00:00
|
|
|
-(void)followLink:(Waypoint)e2 :(integer)b_bit
|
2003-07-24 08:25:04 +00:00
|
|
|
{
|
|
|
|
local float dist;
|
|
|
|
|
|
|
|
if (flags & b_bit)
|
|
|
|
dist = items;
|
|
|
|
else
|
|
|
|
dist = vlen(self.origin - e2.origin) + self.items;
|
|
|
|
|
|
|
|
// check if this is an RJ link
|
|
|
|
if (e2.flags & AI_SUPER_JUMP) {
|
|
|
|
if (![route_table can_rj])
|
2003-02-18 23:11:05 +00:00
|
|
|
return;
|
|
|
|
}
|
2003-07-24 08:25:04 +00:00
|
|
|
if (e2.flags & AI_DIFFICULT)
|
|
|
|
dist = dist + 1000;
|
2003-02-18 23:11:05 +00:00
|
|
|
|
2003-07-24 08:25:04 +00:00
|
|
|
dist = dist + random() * 100; // add a little chaos
|
|
|
|
|
|
|
|
if ((dist < e2.items) || (e2.items == -1)) {
|
|
|
|
if (!e2.keys)
|
|
|
|
busy_waypoints = busy_waypoints + 1;
|
|
|
|
e2.keys = TRUE;
|
|
|
|
e2.items = dist;
|
2003-07-24 18:23:13 +00:00
|
|
|
(IMP)e2.ent.think = [self methodFor: @selector (waypointThink)];
|
2003-07-24 08:25:04 +00:00
|
|
|
e2.ent.nextthink = time;
|
|
|
|
e2.enemy = self;
|
2003-02-18 23:11:05 +00:00
|
|
|
}
|
2003-07-24 08:25:04 +00:00
|
|
|
}
|
2003-02-18 23:11:05 +00:00
|
|
|
|
2003-07-24 08:25:04 +00:00
|
|
|
-(void)waypointThink
|
|
|
|
{
|
|
|
|
local integer i;
|
2003-02-18 23:11:05 +00:00
|
|
|
|
2003-07-24 08:25:04 +00:00
|
|
|
if (self.items == -1)
|
2003-02-18 23:11:05 +00:00
|
|
|
return;
|
2003-07-24 08:25:04 +00:00
|
|
|
// can you say ugly?
|
|
|
|
if (flags & AI_TRACE_TEST) {
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
if (targets[i]) {
|
|
|
|
traceline (origin, targets[i].origin, TRUE, /*self*/NIL);
|
|
|
|
if (trace_fraction == 1)
|
|
|
|
[self followLink:targets[i].origin :AI_TELELINK_1 << i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
if (targets[i]) {
|
|
|
|
[self followLink:targets[i].origin :AI_TELELINK_1 << i];
|
|
|
|
}
|
|
|
|
}
|
2003-02-18 23:11:05 +00:00
|
|
|
}
|
|
|
|
|
2003-07-24 08:25:04 +00:00
|
|
|
busy_waypoints--;
|
|
|
|
keys = FALSE;
|
|
|
|
|
|
|
|
if (busy_waypoints <= 0) {
|
|
|
|
if (direct_route) {
|
|
|
|
[route_table get_path:route_table.targets[0] :FALSE];
|
|
|
|
direct_route = FALSE;
|
|
|
|
}
|
2003-02-18 23:11:05 +00:00
|
|
|
}
|
2003-07-24 08:25:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
2003-02-18 23:11:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
|
|
|
|
2003-07-24 08:25:04 +00:00
|
|
|
BSP/QC Waypoint loading
|
2003-02-18 23:11:05 +00:00
|
|
|
|
|
|
|
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
|
|
|
*/
|
|
|
|
|
2003-07-24 08:25:04 +00:00
|
|
|
void() waypoint =
|
|
|
|
{
|
2003-07-24 18:25:46 +00:00
|
|
|
local Waypoint way = [[Waypoint alloc] initFromEntity: @self];
|
2003-07-24 08:25:04 +00:00
|
|
|
/*
|
|
|
|
self.search_time = time;
|
|
|
|
self.solid = SOLID_TRIGGER;
|
|
|
|
self.movetype = MOVETYPE_NONE;
|
|
|
|
setorigin(self, self.origin);
|
|
|
|
|
|
|
|
setsize(self, VEC_HULL_MIN, VEC_HULL_MAX);
|
|
|
|
waypoints = waypoints + 1;
|
|
|
|
if (!way_head) {
|
|
|
|
way_head = self;
|
|
|
|
way_foot = self;
|
|
|
|
} else {
|
|
|
|
way_foot._next = self;
|
|
|
|
self._last = way_foot;
|
|
|
|
way_foot = self;
|
2003-02-18 23:11:05 +00:00
|
|
|
}
|
|
|
|
|
2003-07-24 08:25:04 +00:00
|
|
|
self.count = waypoints;
|
|
|
|
waypoint_mode = WM_LOADED;
|
|
|
|
if (self.count == 1) {
|
|
|
|
self.think = FixWaypoints; // wait until all bsp loaded points are spawned
|
|
|
|
self.nextthink = time;
|
2003-02-18 23:11:05 +00:00
|
|
|
}
|
2003-07-24 08:25:04 +00:00
|
|
|
*/
|
2003-02-18 23:11:05 +00:00
|
|
|
};
|
|
|
|
|
2003-07-24 08:25:04 +00:00
|
|
|
void(vector org, vector bit1, integer bit4, integer flargs) make_way =
|
2003-02-18 23:11:05 +00:00
|
|
|
{
|
2003-07-24 18:25:46 +00:00
|
|
|
local Waypoint y = [[Waypoint alloc] initAt:org];
|
2003-07-24 08:25:04 +00:00
|
|
|
//local entity y;
|
|
|
|
//waypoint_mode = WM_LOADED;
|
|
|
|
//y = make_waypoint(org);
|
|
|
|
y.flags = flargs;
|
|
|
|
y.b_pants = (integer)bit1_x;
|
|
|
|
y.b_skill = (integer)bit1_y;
|
|
|
|
y.b_shirt = (integer)bit1_z;
|
|
|
|
y.b_frags = bit4;
|
|
|
|
/*
|
|
|
|
if (y.count == 1) {
|
|
|
|
y.think = FixWaypoints; // wait until all qc loaded points are spawned
|
|
|
|
y.nextthink = time;
|
2003-02-18 23:11:05 +00:00
|
|
|
}
|
2003-07-24 08:25:04 +00:00
|
|
|
*/
|
2003-02-18 23:11:05 +00:00
|
|
|
};
|
|
|
|
|
2003-07-24 08:25:04 +00:00
|
|
|
@implementation Bot (Way)
|
|
|
|
|
|
|
|
/*
|
|
|
|
FindWaypoint
|
|
|
|
|
|
|
|
This is used quite a bit, by many different
|
|
|
|
functions big lag causer
|
|
|
|
|
|
|
|
Finds the closest, fisible, waypoint to e
|
|
|
|
*/
|
2003-07-24 18:25:46 +00:00
|
|
|
-(Waypoint)findWaypoint:(Waypoint)start
|
2003-02-18 23:11:05 +00:00
|
|
|
{
|
2003-07-24 18:25:46 +00:00
|
|
|
local Waypoint best, t;
|
2003-07-24 08:25:04 +00:00
|
|
|
local float dst, tdst;
|
|
|
|
local vector org;
|
2003-02-18 23:11:05 +00:00
|
|
|
|
2003-07-24 08:25:04 +00:00
|
|
|
org = realorigin (ent);
|
2003-02-18 23:11:05 +00:00
|
|
|
|
2003-07-24 08:25:04 +00:00
|
|
|
t = way_head;
|
|
|
|
if (start != NIL) {
|
|
|
|
dst = vlen (start.origin - org);
|
|
|
|
best = start;
|
|
|
|
} else {
|
|
|
|
dst = 100000;
|
|
|
|
best = NIL;
|
|
|
|
}
|
|
|
|
while (t) {
|
|
|
|
// real players cut through ignore types
|
|
|
|
if (dst < 20)
|
|
|
|
return best;
|
|
|
|
if (!(t.flags & AI_IGNORE_TYPES) || ishuman) {
|
|
|
|
tdst = vlen (t.origin - org);
|
|
|
|
if (tdst < dst) {
|
|
|
|
/*XXX
|
|
|
|
if (sisible (t)) {
|
|
|
|
dst = tdst;
|
|
|
|
best = t;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
t = t.next;
|
|
|
|
}
|
|
|
|
return best;
|
|
|
|
}
|
2003-02-18 23:11:05 +00:00
|
|
|
|
2003-07-24 18:25:46 +00:00
|
|
|
-(void)deleteWaypoint:(Waypoint)what
|
2003-02-18 23:11:05 +00:00
|
|
|
{
|
2003-07-24 18:25:46 +00:00
|
|
|
local Waypoint t;
|
2003-02-18 23:11:05 +00:00
|
|
|
|
|
|
|
if (way_head == what)
|
2003-07-24 08:25:04 +00:00
|
|
|
way_head = what.next;
|
2003-02-18 23:11:05 +00:00
|
|
|
if (way_foot == what)
|
2003-07-24 08:25:04 +00:00
|
|
|
way_foot = what.prev;
|
|
|
|
if (what.prev)
|
|
|
|
what.prev.next = what.next;
|
|
|
|
if (what.next)
|
|
|
|
what.next.prev = what.prev;
|
2003-02-18 23:11:05 +00:00
|
|
|
waypoints = 0;
|
|
|
|
t = way_head;
|
2003-03-04 18:26:17 +00:00
|
|
|
while(t) {
|
2003-02-18 23:11:05 +00:00
|
|
|
t.count = waypoints = waypoints + 1;
|
2003-07-24 08:25:04 +00:00
|
|
|
if ([t isLinkedTo:what])
|
|
|
|
[t unlinkWay:what];
|
|
|
|
t = t.next;
|
2003-02-18 23:11:05 +00:00
|
|
|
}
|
|
|
|
if (self.current_way == what)
|
2003-02-24 16:05:25 +00:00
|
|
|
self.current_way = NIL;
|
2003-07-24 08:25:04 +00:00
|
|
|
[what free];
|
|
|
|
}
|
2003-02-18 23:11:05 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
|
|
|
|
|
|
|
FindRoute & FindThing used by the pathing code
|
|
|
|
in bot_ai.qc
|
|
|
|
|
|
|
|
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2003-07-24 08:25:04 +00:00
|
|
|
-(entity)findThing:(string)s
|
2003-02-18 23:11:05 +00:00
|
|
|
{
|
|
|
|
local entity t;
|
|
|
|
local float tdst, dst;
|
|
|
|
local entity best;
|
|
|
|
dst = 100000;
|
2003-02-24 16:05:25 +00:00
|
|
|
best = NIL;
|
|
|
|
t = find (NIL, classname, s);
|
2003-03-04 18:26:17 +00:00
|
|
|
while (t != NIL) {
|
2003-07-23 22:44:15 +00:00
|
|
|
tdst = vlen(((t.absmin + t.absmax) * 0.5) - ent.origin);
|
2003-03-04 18:26:17 +00:00
|
|
|
if (tdst < dst) {
|
2003-02-18 23:11:05 +00:00
|
|
|
dst = tdst;
|
|
|
|
best = t;
|
|
|
|
}
|
|
|
|
t = find(t, classname, s);
|
|
|
|
}
|
|
|
|
return best;
|
2003-07-24 08:25:04 +00:00
|
|
|
}
|
2003-02-18 23:11:05 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
|
|
|
|
|
|
|
FindRoute, this is a key function in the
|
|
|
|
pathing. The name is a bit misleading, this
|
|
|
|
code finds the closest waypoint that is part
|
|
|
|
of a route calculated by the begin_route and
|
|
|
|
end_route routines This is a definite path to
|
|
|
|
an object.
|
|
|
|
|
|
|
|
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
|
|
|
*/
|
|
|
|
|
2003-07-24 18:25:46 +00:00
|
|
|
-(Waypoint)findRoute:(Waypoint)lastone
|
2003-02-18 23:11:05 +00:00
|
|
|
{
|
|
|
|
// kinda like FindWaypoint, only of this bots route though
|
2003-07-24 18:25:46 +00:00
|
|
|
local Waypoint t, best;
|
2003-07-24 08:25:04 +00:00
|
|
|
local float dst, tdst;
|
|
|
|
local integer flag;
|
|
|
|
|
|
|
|
flag = ClientBitFlag(b_clientno);
|
2003-02-18 23:11:05 +00:00
|
|
|
t = way_head;
|
|
|
|
dst = 100000;
|
2003-02-24 16:05:25 +00:00
|
|
|
best = NIL;
|
2003-03-04 18:26:17 +00:00
|
|
|
while(t) {
|
2003-07-24 08:25:04 +00:00
|
|
|
tdst = vlen(t.origin - ent.origin);
|
2003-03-04 18:26:17 +00:00
|
|
|
if ((tdst < dst) && (t.b_sound & flag)) {
|
2003-07-24 08:25:04 +00:00
|
|
|
if ((lastone == NIL) || ([lastone isLinkedTo:t])) {
|
2003-02-18 23:11:05 +00:00
|
|
|
dst = tdst;
|
|
|
|
best = t;
|
|
|
|
}
|
|
|
|
}
|
2003-07-24 08:25:04 +00:00
|
|
|
t = t.next;
|
2003-02-18 23:11:05 +00:00
|
|
|
}
|
|
|
|
return best;
|
2003-07-24 08:25:04 +00:00
|
|
|
}
|
2003-02-18 23:11:05 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
|
|
|
|
|
|
|
Mark_path
|
|
|
|
|
|
|
|
After the route has been found, mark it with
|
|
|
|
bitflags so the table can be used for a
|
|
|
|
different bot.
|
|
|
|
|
|
|
|
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2003-07-24 08:25:04 +00:00
|
|
|
-(void)mark_path:(entity)this
|
2003-02-18 23:11:05 +00:00
|
|
|
{
|
2003-07-24 18:25:46 +00:00
|
|
|
local Waypoint t;
|
2003-07-24 08:25:04 +00:00
|
|
|
local integer flag;
|
|
|
|
local Bot bot = (Bot)this.@this;
|
2003-02-18 23:11:05 +00:00
|
|
|
|
2003-07-24 18:25:46 +00:00
|
|
|
[Waypoint clearMyRoute:self];
|
2003-02-18 23:11:05 +00:00
|
|
|
|
2003-07-24 18:25:46 +00:00
|
|
|
t = [this.@this findWaypoint:bot.current_way];
|
2003-02-18 23:11:05 +00:00
|
|
|
// FIXME
|
|
|
|
// ugh, better way to find players please!!!
|
|
|
|
if (this.classname != "player")
|
2003-07-24 08:25:04 +00:00
|
|
|
bot.current_way = t;
|
2003-02-18 23:11:05 +00:00
|
|
|
|
2003-03-04 18:26:17 +00:00
|
|
|
if (t.enemy == NIL) {
|
2003-07-24 08:25:04 +00:00
|
|
|
[self lost:this :FALSE];
|
2003-02-18 23:11:05 +00:00
|
|
|
if (waypoint_mode == WM_DYNAMIC)
|
2003-07-24 08:25:04 +00:00
|
|
|
route_failed = TRUE;
|
2003-02-18 23:11:05 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-07-24 08:25:04 +00:00
|
|
|
flag = ClientBitFlag(b_clientno);
|
2003-02-18 23:11:05 +00:00
|
|
|
|
2003-03-04 18:26:17 +00:00
|
|
|
while(t) {
|
2003-02-18 23:11:05 +00:00
|
|
|
if (t.b_sound & flag)
|
|
|
|
return;
|
2003-07-24 08:25:04 +00:00
|
|
|
if (t == last_way)
|
2003-02-18 23:11:05 +00:00
|
|
|
return;
|
2003-07-24 08:25:04 +00:00
|
|
|
t.b_sound |= flag;
|
2003-02-18 23:11:05 +00:00
|
|
|
t = t.enemy;
|
|
|
|
}
|
2003-07-24 08:25:04 +00:00
|
|
|
}
|
2003-02-18 23:11:05 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
|
|
|
|
|
|
|
begin_route and bot_get_path
|
|
|
|
|
|
|
|
PLEASE NOTE: bot_get_path replaces the old
|
|
|
|
calls to begin_route.
|
|
|
|
|
|
|
|
Routing isn't done all at once now, but in two
|
|
|
|
stages, the bot will calc a route *THEN*
|
|
|
|
choose a target, *THEN* mark a path.
|
|
|
|
|
|
|
|
Boy it's confusing.
|
|
|
|
|
|
|
|
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
|
|
|
*/
|
|
|
|
|
2003-07-24 08:25:04 +00:00
|
|
|
-(integer)begin_route
|
2003-02-18 23:11:05 +00:00
|
|
|
{
|
|
|
|
if (busy_waypoints > 0)
|
|
|
|
return FALSE;
|
|
|
|
|
2003-07-24 08:25:04 +00:00
|
|
|
if (route_table) {
|
2003-03-04 18:26:17 +00:00
|
|
|
if (!route_table.ishuman) {
|
2003-02-18 23:11:05 +00:00
|
|
|
if (route_table.b_clientno != -1)
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
route_table = self;
|
2003-07-24 18:25:46 +00:00
|
|
|
[Waypoint clearRouteTable];
|
|
|
|
last_way = [self findWaypoint:current_way];
|
2003-07-24 08:25:04 +00:00
|
|
|
|
|
|
|
if (last_way != NIL) {
|
|
|
|
last_way.items = vlen(self.last_way.origin - ent.origin);
|
|
|
|
last_way.ent.nextthink = time;
|
2003-07-24 18:23:13 +00:00
|
|
|
(IMP)last_way.ent.think = [self methodFor: @selector(waypointThink)];
|
2003-07-24 08:25:04 +00:00
|
|
|
last_way.keys = TRUE;
|
2003-02-18 23:11:05 +00:00
|
|
|
busy_waypoints = 1;
|
|
|
|
return TRUE;
|
2003-03-04 18:26:17 +00:00
|
|
|
} else {
|
2003-02-24 16:05:25 +00:00
|
|
|
route_table = NIL;
|
2003-02-18 23:11:05 +00:00
|
|
|
busy_waypoints = 0;
|
|
|
|
return FALSE;
|
|
|
|
}
|
2003-07-24 08:25:04 +00:00
|
|
|
}
|
2003-02-18 23:11:05 +00:00
|
|
|
|
2003-07-24 18:25:46 +00:00
|
|
|
-(void)get_path:(Waypoint)this :(integer)direct
|
2003-02-18 23:11:05 +00:00
|
|
|
{
|
2003-02-24 16:05:25 +00:00
|
|
|
if (this == NIL)
|
2003-02-18 23:11:05 +00:00
|
|
|
return;
|
|
|
|
|
2003-03-04 18:26:17 +00:00
|
|
|
if (route_table == self) {
|
|
|
|
if (busy_waypoints <= 0) {
|
2003-02-24 16:05:25 +00:00
|
|
|
route_table = NIL;
|
2003-07-24 08:25:04 +00:00
|
|
|
[self mark_path:this];
|
2003-02-18 23:11:05 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2003-03-04 18:26:17 +00:00
|
|
|
if (direct) {
|
2003-07-24 08:25:04 +00:00
|
|
|
if([self begin_route])
|
2003-02-18 23:11:05 +00:00
|
|
|
direct_route = TRUE;
|
|
|
|
else
|
2003-07-24 08:25:04 +00:00
|
|
|
[self lost:this :FALSE];
|
2003-02-18 23:11:05 +00:00
|
|
|
return;
|
|
|
|
}
|
2003-07-24 08:25:04 +00:00
|
|
|
}
|
2003-02-18 23:11:05 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
|
|
|
|
|
|
|
Temporary Marker code
|
|
|
|
|
|
|
|
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
|
|
|
*/
|
|
|
|
|
2003-07-24 08:25:04 +00:00
|
|
|
-(void)spawnTempWaypoint:(vector)org
|
2003-02-18 23:11:05 +00:00
|
|
|
{
|
2003-07-24 08:25:04 +00:00
|
|
|
/*XXX
|
2003-02-18 23:11:05 +00:00
|
|
|
local entity tep;
|
|
|
|
|
|
|
|
if (!self.temp_way)
|
|
|
|
self.temp_way = tep = spawn();
|
|
|
|
else
|
|
|
|
tep = self.temp_way;
|
|
|
|
|
|
|
|
tep.classname = "temp_waypoint";
|
|
|
|
tep.search_time = 0;
|
|
|
|
tep.solid = SOLID_TRIGGER;
|
|
|
|
tep.movetype = MOVETYPE_NOCLIP;
|
|
|
|
setorigin(tep, org);
|
|
|
|
target_add(tep);
|
|
|
|
setsize(tep, VEC_HULL_MIN, VEC_HULL_MAX); // FIXME: convert these to numerical
|
2003-07-24 08:25:04 +00:00
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Dynamic Waypoint spawning and linking. Not
|
|
|
|
very good all things considered.
|
|
|
|
*/
|
|
|
|
-(void)dynamicWaypoint
|
|
|
|
{
|
2003-07-24 18:25:46 +00:00
|
|
|
local Waypoint t;
|
2003-07-24 08:25:04 +00:00
|
|
|
local float dist, dynlink = 0, dynpoint = 0, editor = 0;
|
|
|
|
|
|
|
|
if (teleport_time > portal_time) {
|
|
|
|
if (!(ent.flags & FL_WATERJUMP)) {
|
|
|
|
dyn_flags = 2;
|
|
|
|
if (!ishuman) {
|
|
|
|
[self lost:targets[0] :TRUE];
|
|
|
|
ent.enemy = NIL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
portal_time = teleport_time;
|
|
|
|
}
|
|
|
|
// stacking everything on waypoint_mode might've been good for the editor,
|
|
|
|
// but it sucks to beat hell for this code.
|
|
|
|
|
|
|
|
// convert waypoint_mode to something more usable..
|
|
|
|
if (waypoint_mode > WM_LOADED) {
|
|
|
|
if (self.ishuman) {
|
|
|
|
if (waypoint_mode == WM_EDITOR_DYNLINK)
|
|
|
|
dynlink = 1;
|
|
|
|
else if (waypoint_mode == WM_EDITOR_DYNAMIC)
|
|
|
|
dynlink = dynpoint = 1;
|
|
|
|
editor = 1;
|
|
|
|
}
|
|
|
|
} else if (waypoint_mode == WM_DYNAMIC)
|
|
|
|
dynlink = dynpoint = 1;
|
|
|
|
|
|
|
|
// if there's nothing for dynamic to do..
|
|
|
|
if (!dynpoint) {
|
|
|
|
if (!editor)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// for speed sake, I won't have bots dynamic waypoint in coop
|
|
|
|
if (!self.ishuman)
|
|
|
|
if (coop)
|
|
|
|
return;
|
|
|
|
// don't waypoint in single player
|
|
|
|
if (max_clients < 2)
|
|
|
|
return;
|
|
|
|
// if you're dead
|
|
|
|
else if (ent.health <= 0) {
|
|
|
|
if (dynpoint) {
|
|
|
|
if (current_way) {
|
|
|
|
if (pointcontents(ent.origin) < -4) {
|
|
|
|
if (self.current_way.flags & AI_BLIND)
|
|
|
|
self.current_way.flags |= AI_PRECISION;
|
|
|
|
else
|
|
|
|
self.current_way.flags |= AI_BLIND;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
self.dyn_dest = '0 0 0';
|
|
|
|
self.current_way = NIL;
|
|
|
|
self.dyn_flags = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// you shouldn't be making waypoints mid air
|
|
|
|
if (dynpoint) {
|
|
|
|
if (!((ent.flags & FL_ONGROUND) || ent.waterlevel == 3)) {
|
|
|
|
if (dyn_flags != 2) {
|
|
|
|
dyn_flags = 1;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// keep from doing the rest of this every frame
|
|
|
|
if (self.dyn_time > time)
|
|
|
|
return;
|
|
|
|
self.dyn_time = time + 0.2;
|
|
|
|
|
|
|
|
// display the links for editor mode
|
|
|
|
if (editor) {
|
|
|
|
if (self.current_way) {
|
2003-07-24 18:25:46 +00:00
|
|
|
local Waypoint way = self.current_way;
|
2003-07-24 08:25:04 +00:00
|
|
|
local integer i;
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
if (way.targets[i]) {
|
|
|
|
DeveloperLightning (way, way.targets[i],
|
|
|
|
way.flags & (AI_TELELINK_1 << i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (self.b_aiflags & AI_HOLD_SELECT)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-07-24 18:25:46 +00:00
|
|
|
t = [self findWaypoint:current_way];
|
2003-07-24 08:25:04 +00:00
|
|
|
if (t) {
|
|
|
|
dist = vlen (ent.origin - t.origin);
|
|
|
|
if (dist < 192) {
|
|
|
|
if (dist < 64) {
|
|
|
|
if (t != self.current_way) {
|
|
|
|
if (dynlink) {
|
|
|
|
if (!self.dyn_flags) {
|
|
|
|
if ([t canSee:current_way ignoring:ent])
|
|
|
|
[t linkWay:current_way];
|
|
|
|
}
|
|
|
|
if (dyn_flags == 2)
|
|
|
|
[current_way teleLinkWay:t];
|
|
|
|
else if ([t canSee:current_way ignoring:ent])
|
|
|
|
[current_way linkWay:t];
|
|
|
|
}
|
|
|
|
if (editor) {
|
|
|
|
setmodel(t.ent, "progs/s_light.spr");
|
|
|
|
if (current_way)
|
|
|
|
setmodel(current_way.ent, "progs/s_bubble.spr");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
self.current_way = t;
|
|
|
|
self.dyn_flags = 0;
|
|
|
|
}
|
|
|
|
dyn_dest = ent.origin + ent.view_ofs;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ([self recognize_plat:FALSE]) {
|
|
|
|
if (vlen(trace_ent.velocity) > 0) {
|
|
|
|
if (self.dyn_plat)
|
|
|
|
return;
|
|
|
|
self.dyn_plat = TRUE;
|
|
|
|
if (!self.dyn_flags)
|
|
|
|
self.dyn_flags = 1;
|
|
|
|
//bprint("on a plat!!!!!\n");
|
|
|
|
} else
|
|
|
|
self.dyn_plat = FALSE;
|
|
|
|
} else
|
|
|
|
dyn_plat = FALSE;
|
|
|
|
|
|
|
|
if (dyn_flags == 2)
|
|
|
|
dyn_dest = ent.origin + ent.view_ofs;
|
|
|
|
else if (self.dyn_dest == '0 0 0')
|
|
|
|
dyn_dest = ent.origin + ent.view_ofs;
|
|
|
|
if (!dynpoint)
|
|
|
|
return;
|
2003-07-24 18:25:46 +00:00
|
|
|
t = [[Waypoint alloc] initAt:dyn_dest];
|
2003-07-24 08:25:04 +00:00
|
|
|
|
|
|
|
if (!dyn_flags) {
|
|
|
|
if ([t canSee:current_way ignoring:ent])
|
|
|
|
[t linkWay:current_way];
|
|
|
|
}
|
|
|
|
if (dyn_flags == 2)
|
|
|
|
[current_way teleLinkWay: t];
|
|
|
|
else if ([t canSee:current_way ignoring:ent])
|
|
|
|
[current_way linkWay:t];
|
|
|
|
|
|
|
|
if (editor) {
|
|
|
|
setmodel(t.ent, "progs/s_light.spr");
|
|
|
|
if (current_way)
|
|
|
|
setmodel(current_way.ent, "progs/s_bubble.spr");
|
|
|
|
}
|
|
|
|
current_way = t;
|
|
|
|
dyn_flags = 0;
|
|
|
|
|
|
|
|
dyn_dest = ent.origin + ent.view_ofs;
|
|
|
|
|
|
|
|
if ([self recognize_plat:FALSE]) {
|
|
|
|
if (trace_ent.classname == "door")
|
|
|
|
t.flags |= AI_DOORFLAG;
|
|
|
|
}
|
|
|
|
}
|
2003-07-24 18:23:13 +00:00
|
|
|
|
|
|
|
-(integer)canSee:(Target)targ
|
|
|
|
{
|
|
|
|
local float thruwater = 0, pc1 = 0, pc2 = 0;
|
|
|
|
local vector spot1, org;
|
|
|
|
|
|
|
|
org = [targ realorigin];
|
|
|
|
spot1 = ent.origin + ent.view_ofs;
|
|
|
|
|
|
|
|
if (targ.ent.solid == SOLID_BSP) {
|
|
|
|
traceline (spot1, org, TRUE, ent);
|
|
|
|
if (trace_ent == targ.ent)
|
|
|
|
return TRUE;
|
|
|
|
else if (trace_fraction == 1)
|
|
|
|
return TRUE;
|
|
|
|
return FALSE;
|
|
|
|
} else {
|
|
|
|
pc1 = pointcontents (org);
|
|
|
|
pc2 = pointcontents (spot1);
|
|
|
|
if (targ.ent.classname == "player")
|
|
|
|
thruwater = FALSE;
|
|
|
|
else if (pc1 == CONTENT_LAVA)
|
|
|
|
return FALSE;
|
|
|
|
else
|
|
|
|
thruwater = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pc1 < -1) {
|
|
|
|
// targ's origin is in water or other liquid
|
|
|
|
if (pc2 != pc1) {
|
|
|
|
// look for their head
|
|
|
|
traceline (spot1, org + targ.ent.mins, TRUE, ent);
|
|
|
|
// cross the water check
|
|
|
|
if (trace_inopen)
|
|
|
|
if (trace_inwater)
|
|
|
|
if (!thruwater)
|
|
|
|
return FALSE;
|
|
|
|
if (trace_ent == targ.ent)
|
|
|
|
return TRUE;
|
|
|
|
else if (trace_fraction == 1)
|
|
|
|
return TRUE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (pc2 != pc1) {
|
|
|
|
traceline (spot1, org + targ.ent.maxs, TRUE, ent);
|
|
|
|
if (trace_inopen)
|
|
|
|
if (trace_inwater)
|
|
|
|
if (!thruwater)
|
|
|
|
return FALSE;
|
|
|
|
if (trace_ent == targ.ent)
|
|
|
|
return TRUE;
|
|
|
|
else if (trace_fraction == 1)
|
|
|
|
return TRUE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
traceline (spot1, org, TRUE, ent);
|
|
|
|
if (trace_ent == targ.ent)
|
|
|
|
return TRUE;
|
|
|
|
else if (trace_fraction == 1)
|
|
|
|
return TRUE;
|
|
|
|
traceline (spot1, org + targ.ent.maxs, TRUE, ent);
|
|
|
|
if (trace_ent == targ.ent)
|
|
|
|
return TRUE;
|
|
|
|
else if (trace_fraction == 1)
|
|
|
|
return TRUE;
|
|
|
|
traceline (spot1, org + targ.ent.mins, TRUE, ent);
|
|
|
|
if (trace_ent == targ.ent)
|
|
|
|
return TRUE;
|
|
|
|
else if (trace_fraction == 1)
|
|
|
|
return TRUE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
2003-07-24 08:25:04 +00:00
|
|
|
@end
|