diff --git a/src/game/bot/ai_class_dmbot.c b/src/game/bot/ai_class_dmbot.c index 6c437d77..cd38fccd 100644 --- a/src/game/bot/ai_class_dmbot.c +++ b/src/game/bot/ai_class_dmbot.c @@ -40,12 +40,18 @@ static gitem_t *blueflag; // BOT_DMclass_Move // DMClass is generic bot class //========================================== -void BOT_DMclass_Move(edict_t *self, usercmd_t *ucmd) +static void +BOT_DMclass_Move(edict_t *self, usercmd_t *ucmd) { int next_node_flags = 0; int current_link_type = 0; int i; + if (self->ai->next_node < 0) + { + return; + } + next_node_flags = nodes[self->ai->next_node].flags; if( AI_PlinkExists( self->ai->current_node, self->ai->next_node )) { diff --git a/src/game/bot/ai_local.h b/src/game/bot/ai_local.h index e2b0a267..1f63c67f 100644 --- a/src/game/bot/ai_local.h +++ b/src/game/bot/ai_local.h @@ -173,3 +173,7 @@ qboolean BOT_ChangeWeapon (edict_t *ent, gitem_t *item); void AI_InitAIWeapons(void); qboolean AI_IsLadder(vec3_t origin, vec3_t v_angle, vec3_t mins, vec3_t maxs, edict_t *passent); + +// A* PROPS +//=========================================== +qboolean AStar_GetPath(int origin, int goal, int movetypes, struct astarpath_s *path); diff --git a/src/game/bot/ai_navigation.c b/src/game/bot/ai_navigation.c index 520f1698..bed119c0 100644 --- a/src/game/bot/ai_navigation.c +++ b/src/game/bot/ai_navigation.c @@ -30,7 +30,6 @@ #include "../header/local.h" #include "ai_local.h" -#include "astar.h" //========================================== diff --git a/src/game/bot/astar.c b/src/game/bot/astar.c index c8c7e9ff..0e606b6f 100644 --- a/src/game/bot/astar.c +++ b/src/game/bot/astar.c @@ -49,7 +49,7 @@ typedef struct } astarnode_t; -astarnode_t astarnodes[MAX_NODES]; +static astarnode_t astarnodes[MAX_NODES]; struct astarpath_s *Apath; //========================================== @@ -76,27 +76,44 @@ static int ValidLinksMask; // //========================================== -int AStar_nodeIsInClosed( int node ) +static qboolean +AStar_nodeIsInClosed(int node) { - if( astarnodes[node].list == CLOSEDLIST ) - return 1; + if (node >= MAX_NODES || node < 0) + { + return false; + } - return 0; + if (astarnodes[node].list == CLOSEDLIST) + { + return true; + } + + return false; } -int AStar_nodeIsInOpen( int node ) +static qboolean +AStar_nodeIsInOpen(int node) { - if( astarnodes[node].list == OPENLIST ) - return 1; + if (node >= MAX_NODES || node < 0) + { + return false; + } - return 0; + if(astarnodes[node].list == OPENLIST) + { + return true; + } + + return false; } -static void AStar_InitLists (void) +static void +AStar_InitLists(void) { - int i; + size_t i; - for ( i=0; inumNodes = 0; + } alist_numNodes = 0; - memset( alist, -1, sizeof(alist));//jabot092 + memset(alist, -1, sizeof(alist));//jabot092 } static int AStar_PLinkDistance(int n1, int n2) { - int i; + size_t i; - for ( i=0; ivalue) { Com_Printf("WARNING: AStar_PutAdjacentsInOpen - Couldn't find distance between nodes\n"); } - //compare G distances and choose best parent - else if( astarnodes[addnode].G > (astarnodes[node].G + plinkDist) ) + // compare G distances and choose best parent + else if (astarnodes[addnode].G > (astarnodes[node].G + plinkDist)) { astarnodes[addnode].parent = node; astarnodes[addnode].G = astarnodes[node].G + plinkDist; } - - } else { //just put it in - + } + else + { + // just put it in int plinkDist; plinkDist = AStar_PLinkDistance( node, addnode ); - if( plinkDist == -1) + if (plinkDist == -1) { - plinkDist = AStar_PLinkDistance( addnode, node ); - if( plinkDist == -1) + plinkDist = AStar_PLinkDistance(addnode, node); + if (plinkDist == -1) + { plinkDist = 999;//jalFIXME + } if (bot_debugmonster->value) { @@ -222,8 +244,8 @@ AStar_PutAdjacentsInOpen(int node) } } - //put in global list - if( !astarnodes[addnode].list ) + // put in global list + if (!astarnodes[addnode].list) { alist[alist_numNodes] = addnode; alist_numNodes++; @@ -237,13 +259,14 @@ AStar_PutAdjacentsInOpen(int node) } } -static int AStar_FindInOpen_BestF ( void ) +static int +AStar_FindInOpen_BestF(void) { - int i; + size_t i; int bestF = -1; int best = -1; - for ( i=0; i (astarnodes[node].G + astarnodes[node].H) ) + if (bestF == -1 || bestF > (astarnodes[node].G + astarnodes[node].H)) { bestF = astarnodes[node].G + astarnodes[node].H; best = node; @@ -267,7 +290,8 @@ static int AStar_FindInOpen_BestF ( void ) return best; } -static void AStar_ListsToPath ( void ) +static void +AStar_ListsToPath(void) { int count = 0; int cur = goalNode; @@ -275,7 +299,7 @@ static void AStar_ListsToPath ( void ) Apath->numNodes = 0; pnode = Apath->nodes; - while ( cur != originNode ) + while (cur != originNode) { *pnode = cur; pnode++; @@ -283,61 +307,67 @@ static void AStar_ListsToPath ( void ) count++; } - Apath->numNodes = count-1; + Apath->numNodes = count - 1; } -static int AStar_FillLists ( void ) +static qboolean +AStar_FillLists(void) { - //put current node inside closed list - AStar_PutInClosed( currentNode ); + // put current node inside closed list + AStar_PutInClosed(currentNode); - //put adjacent nodes inside open list - AStar_PutAdjacentsInOpen( currentNode ); + // put adjacent nodes inside open list + AStar_PutAdjacentsInOpen(currentNode); - //find best adjacent and make it our current + // find best adjacent and make it our current currentNode = AStar_FindInOpen_BestF(); return (currentNode != -1); //if -1 path is bloqued } -static int AStar_ResolvePath ( int n1, int n2, int movetypes ) +static qboolean +AStar_ResolvePath(int origin, int goal, int movetypes) { + if (origin < 0 || goal < 0) + { + return false; + } + ValidLinksMask = movetypes; - if ( !ValidLinksMask ) + if (!ValidLinksMask) { ValidLinksMask = DEFAULT_MOVETYPES_MASK; } AStar_InitLists(); - originNode = n1; - goalNode = n2; - currentNode = originNode; + currentNode = originNode = origin; + goalNode = goal; - while ( !AStar_nodeIsInOpen(goalNode) ) + while (!AStar_nodeIsInOpen(goalNode)) { - if( !AStar_FillLists() ) + if(!AStar_FillLists()) { - return 0; //failed + return false; //failed } } AStar_ListsToPath(); - return 1; + return true; } -int +qboolean AStar_GetPath(int origin, int goal, int movetypes, struct astarpath_s *path) { Apath = path; if( !AStar_ResolvePath ( origin, goal, movetypes ) ) { - return 0; + return false; } path->originNode = origin; path->goalNode = goal; - return 1; + return true; } diff --git a/src/game/bot/astar.h b/src/game/bot/astar.h deleted file mode 100644 index ec45bbd5..00000000 --- a/src/game/bot/astar.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) 1997-2001 Id Software, Inc. - * Copyright (C) 2001 Steve Yeager - * Copyright (C) 2001-2004 Pat AfterMoon - * Copyright (c) ZeniMax Media Inc. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or (at - * your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - * - * -------------------------------------------------------------- - * The ACE Bot is a product of Steve Yeager, and is available from - * the ACE Bot homepage, at http://www.axionfx.com/ace. - * - * This program is a modification of the ACE Bot, and is therefore - * in NO WAY supported by Steve Yeager. - */ - -// A* PROPS -//=========================================== -int AStar_nodeIsInClosed( int node ); -int AStar_nodeIsInOpen( int node ); -int AStar_nodeIsInPath( int node ); -int AStar_ResolvePath ( int origin, int goal, int movetypes ); -//=========================================== -int AStar_GetPath( int origin, int goal, int movetypes, struct astarpath_s *path );