Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

be_ai_goal.c File Reference

#include "../game/q_shared.h"
#include "l_utils.h"
#include "l_libvar.h"
#include "l_memory.h"
#include "l_log.h"
#include "l_script.h"
#include "l_precomp.h"
#include "l_struct.h"
#include "aasfile.h"
#include "../game/botlib.h"
#include "../game/be_aas.h"
#include "be_aas_funcs.h"
#include "be_interface.h"
#include "be_ai_weight.h"
#include "../game/be_ai_goal.h"
#include "../game/be_ai_move.h"

Include dependency graph for be_ai_goal.c:

Include dependency graph

Go to the source code of this file.

Data Structures

struct  bot_goalstate_s
struct  campspot_s
struct  itemconfig_s
struct  iteminfo_s
struct  levelitem_s
struct  maplocation_s

Defines

#define AVOID_DEFAULT_TIME   30
#define AVOID_DROPPED_TIME   10
#define AVOID_MINIMUM_TIME   10
#define DROPPEDWEIGHT
#define ET_ITEM   2
#define IFL_NOTBOT   8
#define IFL_NOTFREE   1
#define IFL_NOTSINGLE   4
#define IFL_NOTTEAM   2
#define IFL_ROAM   16
#define ITEMINFO_OFS(x)   (int)&(((iteminfo_t *)0)->x)
#define TRAVELTIME_SCALE   0.01
#define UNDECIDEDFUZZY

Typedefs

typedef bot_goalstate_s bot_goalstate_t
typedef campspot_s campspot_t
typedef itemconfig_s itemconfig_t
typedef iteminfo_s iteminfo_t
typedef levelitem_s levelitem_t
typedef maplocation_s maplocation_t

Enumerations

enum  gametype_t {
  GT_FFA, GT_TOURNAMENT, GT_SINGLE_PLAYER, GT_TEAM,
  GT_CTF, GT_MAX_GAME_TYPE
}

Functions

void AddLevelItemToList (levelitem_t *li)
levelitem_tAllocLevelItem (void)
void BotAddToAvoidGoals (bot_goalstate_t *gs, int number, float avoidtime)
int BotAllocGoalState (int client)
float BotAvoidGoalTime (int goalstate, int number)
int BotChooseLTGItem (int goalstate, vec3_t origin, int *inventory, int travelflags)
int BotChooseNBGItem (int goalstate, vec3_t origin, int *inventory, int travelflags, bot_goal_t *ltg, float maxtime)
void BotDumpAvoidGoals (int goalstate)
void BotDumpGoalStack (int goalstate)
void BotEmptyGoalStack (int goalstate)
void BotFindEntityForLevelItem (levelitem_t *li)
void BotFreeGoalState (int handle)
void BotFreeInfoEntities (void)
void BotFreeItemWeights (int goalstate)
int BotGetLevelItemGoal (int index, char *name, bot_goal_t *goal)
int BotGetMapLocationGoal (char *name, bot_goal_t *goal)
int BotGetNextCampSpotGoal (int num, bot_goal_t *goal)
int BotGetSecondGoal (int goalstate, bot_goal_t *goal)
int BotGetTopGoal (int goalstate, bot_goal_t *goal)
void BotGoalName (int number, char *name, int size)
bot_goalstate_tBotGoalStateFromHandle (int handle)
void BotInitInfoEntities (void)
void BotInitLevelItems (void)
void BotInterbreedGoalFuzzyLogic (int parent1, int parent2, int child)
int BotItemGoalInVisButNotVisible (int viewer, vec3_t eye, vec3_t viewangles, bot_goal_t *goal)
int BotLoadItemWeights (int goalstate, char *filename)
void BotMutateGoalFuzzyLogic (int goalstate, float range)
void BotPopGoal (int goalstate)
void BotPushGoal (int goalstate, bot_goal_t *goal)
void BotRemoveFromAvoidGoals (int goalstate, int number)
void BotResetAvoidGoals (int goalstate)
void BotResetGoalState (int goalstate)
void BotSaveGoalFuzzyLogic (int goalstate, char *filename)
void BotSetAvoidGoalTime (int goalstate, int number, float avoidtime)
int BotSetupGoalAI (void)
void BotShutdownGoalAI (void)
int BotTouchingGoal (vec3_t origin, bot_goal_t *goal)
void BotUpdateEntityItems (void)
void FreeLevelItem (levelitem_t *li)
void InitLevelItemHeap (void)
int * ItemWeightIndex (weightconfig_t *iwc, itemconfig_t *ic)
itemconfig_tLoadItemConfig (char *filename)
void RemoveLevelItemFromList (levelitem_t *li)

Variables

bot_goalstate_tbotgoalstates [MAX_CLIENTS+1]
campspot_tcampspots = NULL
libvar_tdroppedweight = NULL
levelitem_tfreelevelitems = NULL
int g_gametype = 0
itemconfig_titemconfig = NULL
fielddef_t iteminfo_fields []
structdef_t iteminfo_struct
levelitem_tlevelitemheap = NULL
levelitem_tlevelitems = NULL
maplocation_tmaplocations = NULL
int numlevelitems = 0


Define Documentation

#define AVOID_DEFAULT_TIME   30
 

Definition at line 57 of file be_ai_goal.c.

#define AVOID_DROPPED_TIME   10
 

Definition at line 59 of file be_ai_goal.c.

#define AVOID_MINIMUM_TIME   10
 

Definition at line 55 of file be_ai_goal.c.

#define DROPPEDWEIGHT
 

Definition at line 53 of file be_ai_goal.c.

#define ET_ITEM   2
 

Definition at line 1007 of file be_ai_goal.c.

Referenced by Blocked_Door(), CG_AddCEntity(), CG_BuildSolidList(), CG_TouchTriggerPrediction(), G_MoverPush(), G_RunFrame(), and Svcmd_EntityList_f().

#define IFL_NOTBOT   8
 

Definition at line 66 of file be_ai_goal.c.

#define IFL_NOTFREE   1
 

Definition at line 63 of file be_ai_goal.c.

#define IFL_NOTSINGLE   4
 

Definition at line 65 of file be_ai_goal.c.

#define IFL_NOTTEAM   2
 

Definition at line 64 of file be_ai_goal.c.

#define IFL_ROAM   16
 

Definition at line 67 of file be_ai_goal.c.

#define ITEMINFO_OFS  )     (int)&(((iteminfo_t *)0)->x)
 

Definition at line 137 of file be_ai_goal.c.

#define TRAVELTIME_SCALE   0.01
 

Definition at line 61 of file be_ai_goal.c.

#define UNDECIDEDFUZZY
 

Definition at line 51 of file be_ai_goal.c.


Typedef Documentation

typedef struct bot_goalstate_s bot_goalstate_t
 

Referenced by BotAddToAvoidGoals(), BotAllocGoalState(), BotAvoidGoalTime(), BotChooseLTGItem(), BotChooseNBGItem(), BotDumpAvoidGoals(), BotDumpGoalStack(), BotEmptyGoalStack(), BotFreeItemWeights(), BotGetSecondGoal(), BotGetTopGoal(), BotGoalStateFromHandle(), BotInterbreedGoalFuzzyLogic(), BotLoadItemWeights(), BotMutateGoalFuzzyLogic(), BotPopGoal(), BotPushGoal(), BotRemoveFromAvoidGoals(), BotResetAvoidGoals(), BotResetGoalState(), BotSaveGoalFuzzyLogic(), and BotSetAvoidGoalTime().

typedef struct campspot_s campspot_t
 

Referenced by BotFreeInfoEntities(), BotGetNextCampSpotGoal(), and BotInitInfoEntities().

typedef struct itemconfig_s itemconfig_t
 

Referenced by BotChooseLTGItem(), BotChooseNBGItem(), BotFindEntityForLevelItem(), BotInitLevelItems(), BotUpdateEntityItems(), ItemWeightIndex(), and LoadItemConfig().

typedef struct iteminfo_s iteminfo_t
 

Referenced by BotChooseLTGItem(), BotChooseNBGItem(), and LoadItemConfig().

typedef struct levelitem_s levelitem_t
 

Referenced by AddLevelItemToList(), AllocLevelItem(), BotChooseLTGItem(), BotChooseNBGItem(), BotFindEntityForLevelItem(), BotGetLevelItemGoal(), BotGoalName(), BotInitLevelItems(), BotSetAvoidGoalTime(), BotUpdateEntityItems(), FreeLevelItem(), InitLevelItemHeap(), and RemoveLevelItemFromList().

typedef struct maplocation_s maplocation_t
 

Referenced by BotFreeInfoEntities(), BotGetMapLocationGoal(), and BotInitInfoEntities().


Enumeration Type Documentation

enum gametype_t
 

Enumeration values:
GT_FFA 
GT_TOURNAMENT 
GT_SINGLE_PLAYER 
GT_TEAM 
GT_CTF 
GT_MAX_GAME_TYPE 

Definition at line 92 of file be_ai_goal.c.

00092              {
00093     GT_FFA,             // free for all
00094     GT_TOURNAMENT,      // one on one tournament
00095     GT_SINGLE_PLAYER,   // single player tournament
00096 
00097     //-- team games go after this --
00098 
00099     GT_TEAM,            // team deathmatch
00100     GT_CTF,             // capture the flag
00101 #ifdef MISSIONPACK
00102     GT_1FCTF,
00103     GT_OBELISK,
00104     GT_HARVESTER,
00105 #endif
00106     GT_MAX_GAME_TYPE
00107 } gametype_t;


Function Documentation

void AddLevelItemToList levelitem_t li  ) 
 

Definition at line 426 of file be_ai_goal.c.

References levelitem_t, levelitems, levelitem_s::next, and levelitem_s::prev.

Referenced by BotInitLevelItems(), and BotUpdateEntityItems().

00427 {
00428     if (levelitems) levelitems->prev = li;
00429     li->prev = NULL;
00430     li->next = levelitems;
00431     levelitems = li;
00432 } //end of the function AddLevelItemToList

levelitem_t* AllocLevelItem void   ) 
 

Definition at line 394 of file be_ai_goal.c.

References botimport, Com_Memset(), freelevelitems, levelitem_t, levelitem_s::next, and PRT_FATAL.

Referenced by BotInitLevelItems(), and BotUpdateEntityItems().

00395 {
00396     levelitem_t *li;
00397 
00398     li = freelevelitems;
00399     if (!li)
00400     {
00401         botimport.Print(PRT_FATAL, "out of level items\n");
00402         return NULL;
00403     } //end if
00404     //
00405     freelevelitems = freelevelitems->next;
00406     Com_Memset(li, 0, sizeof(levelitem_t));
00407     return li;
00408 } //end of the function AllocLevelItem

Here is the call graph for this function:

void BotAddToAvoidGoals bot_goalstate_t gs,
int  number,
float  avoidtime
 

Definition at line 742 of file be_ai_goal.c.

References AAS_Time(), bot_goalstate_s::avoidgoals, bot_goalstate_s::avoidgoaltimes, bot_goalstate_t, and i.

Referenced by BotChooseLTGItem(), BotChooseNBGItem(), and BotSetAvoidGoalTime().

00743 {
00744     int i;
00745 
00746     for (i = 0; i < MAX_AVOIDGOALS; i++)
00747     {
00748         //if the avoid goal is already stored
00749         if (gs->avoidgoals[i] == number)
00750         {
00751             gs->avoidgoals[i] = number;
00752             gs->avoidgoaltimes[i] = AAS_Time() + avoidtime;
00753             return;
00754         } //end if
00755     } //end for
00756 
00757     for (i = 0; i < MAX_AVOIDGOALS; i++)
00758     {
00759         //if this avoid goal has expired
00760         if (gs->avoidgoaltimes[i] < AAS_Time())
00761         {
00762             gs->avoidgoals[i] = number;
00763             gs->avoidgoaltimes[i] = AAS_Time() + avoidtime;
00764             return;
00765         } //end if
00766     } //end for
00767 } //end of the function BotAddToAvoidGoals

Here is the call graph for this function:

int BotAllocGoalState int  client  ) 
 

Definition at line 1731 of file be_ai_goal.c.

References bot_goalstate_t, botgoalstates, bot_goalstate_s::client, GetClearedMemory(), and i.

01732 {
01733     int i;
01734 
01735     for (i = 1; i <= MAX_CLIENTS; i++)
01736     {
01737         if (!botgoalstates[i])
01738         {
01739             botgoalstates[i] = GetClearedMemory(sizeof(bot_goalstate_t));
01740             botgoalstates[i]->client = client;
01741             return i;
01742         } //end if
01743     } //end for
01744     return 0;
01745 } //end of the function BotAllocGoalState

Here is the call graph for this function:

float BotAvoidGoalTime int  goalstate,
int  number
 

Definition at line 797 of file be_ai_goal.c.

References AAS_Time(), bot_goalstate_s::avoidgoals, bot_goalstate_s::avoidgoaltimes, bot_goalstate_t, BotGoalStateFromHandle(), i, and number.

Referenced by BotChooseLTGItem(), and BotChooseNBGItem().

00798 {
00799     int i;
00800     bot_goalstate_t *gs;
00801 
00802     gs = BotGoalStateFromHandle(goalstate);
00803     if (!gs) return 0;
00804     //don't use the goals the bot wants to avoid
00805     for (i = 0; i < MAX_AVOIDGOALS; i++)
00806     {
00807         if (gs->avoidgoals[i] == number && gs->avoidgoaltimes[i] >= AAS_Time())
00808         {
00809             return gs->avoidgoaltimes[i] - AAS_Time();
00810         } //end if
00811     } //end for
00812     return 0;
00813 } //end of the function BotAvoidGoalTime

Here is the call graph for this function:

int BotChooseLTGItem int  goalstate,
vec3_t  origin,
int *  inventory,
int  travelflags
 

Definition at line 1284 of file be_ai_goal.c.

References AAS_AreaReachability(), AAS_AreaTravelTimeToGoalArea(), bot_goal_s::areanum, bot_goal_t, bot_goalstate_t, BotAddToAvoidGoals(), BotAvoidGoalTime(), BotGoalStateFromHandle(), BotPushGoal(), BotReachabilityArea(), bot_goalstate_s::client, Com_Memset(), droppedweight, levelitem_s::entitynum, bot_goal_s::entitynum, levelitem_s::flags, bot_goal_s::flags, FuzzyWeight(), FuzzyWeightUndecided(), g_gametype, levelitem_s::goalareanum, levelitem_s::goalorigin, itemconfig_t, itemconfig_s::iteminfo, levelitem_s::iteminfo, bot_goal_s::iteminfo, iteminfo_t, bot_goalstate_s::itemweightconfig, bot_goalstate_s::itemweightindex, bot_goalstate_s::lastreachabilityarea, levelitem_t, iteminfo_s::maxs, bot_goal_s::maxs, iteminfo_s::mins, bot_goal_s::mins, levelitem_s::next, iteminfo_s::number, levelitem_s::number, bot_goal_s::number, bot_goal_s::origin, iteminfo_s::respawntime, t, levelitem_s::timeout, libvar_s::value, VectorCopy, and levelitem_s::weight.

01285 {
01286     int areanum, t, weightnum;
01287     float weight, bestweight, avoidtime;
01288     iteminfo_t *iteminfo;
01289     itemconfig_t *ic;
01290     levelitem_t *li, *bestitem;
01291     bot_goal_t goal;
01292     bot_goalstate_t *gs;
01293 
01294     gs = BotGoalStateFromHandle(goalstate);
01295     if (!gs)
01296         return qfalse;
01297     if (!gs->itemweightconfig)
01298         return qfalse;
01299     //get the area the bot is in
01300     areanum = BotReachabilityArea(origin, gs->client);
01301     //if the bot is in solid or if the area the bot is in has no reachability links
01302     if (!areanum || !AAS_AreaReachability(areanum))
01303     {
01304         //use the last valid area the bot was in
01305         areanum = gs->lastreachabilityarea;
01306     } //end if
01307     //remember the last area with reachabilities the bot was in
01308     gs->lastreachabilityarea = areanum;
01309     //if still in solid
01310     if (!areanum)
01311         return qfalse;
01312     //the item configuration
01313     ic = itemconfig;
01314     if (!itemconfig)
01315         return qfalse;
01316     //best weight and item so far
01317     bestweight = 0;
01318     bestitem = NULL;
01319     Com_Memset(&goal, 0, sizeof(bot_goal_t));
01320     //go through the items in the level
01321     for (li = levelitems; li; li = li->next)
01322     {
01323         if (g_gametype == GT_SINGLE_PLAYER) {
01324             if (li->flags & IFL_NOTSINGLE)
01325                 continue;
01326         }
01327         else if (g_gametype >= GT_TEAM) {
01328             if (li->flags & IFL_NOTTEAM)
01329                 continue;
01330         }
01331         else {
01332             if (li->flags & IFL_NOTFREE)
01333                 continue;
01334         }
01335         if (li->flags & IFL_NOTBOT)
01336             continue;
01337         //if the item is not in a possible goal area
01338         if (!li->goalareanum)
01339             continue;
01340         //FIXME: is this a good thing? added this for items that never spawned into the game (f.i. CTF flags in obelisk)
01341         if (!li->entitynum && !(li->flags & IFL_ROAM))
01342             continue;
01343         //get the fuzzy weight function for this item
01344         iteminfo = &ic->iteminfo[li->iteminfo];
01345         weightnum = gs->itemweightindex[iteminfo->number];
01346         if (weightnum < 0)
01347             continue;
01348 
01349 #ifdef UNDECIDEDFUZZY
01350         weight = FuzzyWeightUndecided(inventory, gs->itemweightconfig, weightnum);
01351 #else
01352         weight = FuzzyWeight(inventory, gs->itemweightconfig, weightnum);
01353 #endif //UNDECIDEDFUZZY
01354 #ifdef DROPPEDWEIGHT
01355         //HACK: to make dropped items more attractive
01356         if (li->timeout)
01357             weight += droppedweight->value;
01358 #endif //DROPPEDWEIGHT
01359         //use weight scale for item_botroam
01360         if (li->flags & IFL_ROAM) weight *= li->weight;
01361         //
01362         if (weight > 0)
01363         {
01364             //get the travel time towards the goal area
01365             t = AAS_AreaTravelTimeToGoalArea(areanum, origin, li->goalareanum, travelflags);
01366             //if the goal is reachable
01367             if (t > 0)
01368             {
01369                 //if this item won't respawn before we get there
01370                 avoidtime = BotAvoidGoalTime(goalstate, li->number);
01371                 if (avoidtime - t * 0.009 > 0)
01372                     continue;
01373                 //
01374                 weight /= (float) t * TRAVELTIME_SCALE;
01375                 //
01376                 if (weight > bestweight)
01377                 {
01378                     bestweight = weight;
01379                     bestitem = li;
01380                 } //end if
01381             } //end if
01382         } //end if
01383     } //end for
01384     //if no goal item found
01385     if (!bestitem)
01386     {
01387         /*
01388         //if not in lava or slime
01389         if (!AAS_AreaLava(areanum) && !AAS_AreaSlime(areanum))
01390         {
01391             if (AAS_RandomGoalArea(areanum, travelflags, &goal.areanum, goal.origin))
01392             {
01393                 VectorSet(goal.mins, -15, -15, -15);
01394                 VectorSet(goal.maxs, 15, 15, 15);
01395                 goal.entitynum = 0;
01396                 goal.number = 0;
01397                 goal.flags = GFL_ROAM;
01398                 goal.iteminfo = 0;
01399                 //push the goal on the stack
01400                 BotPushGoal(goalstate, &goal);
01401                 //
01402 #ifdef DEBUG
01403                 botimport.Print(PRT_MESSAGE, "chosen roam goal area %d\n", goal.areanum);
01404 #endif //DEBUG
01405                 return qtrue;
01406             } //end if
01407         } //end if
01408         */
01409         return qfalse;
01410     } //end if
01411     //create a bot goal for this item
01412     iteminfo = &ic->iteminfo[bestitem->iteminfo];
01413     VectorCopy(bestitem->goalorigin, goal.origin);
01414     VectorCopy(iteminfo->mins, goal.mins);
01415     VectorCopy(iteminfo->maxs, goal.maxs);
01416     goal.areanum = bestitem->goalareanum;
01417     goal.entitynum = bestitem->entitynum;
01418     goal.number = bestitem->number;
01419     goal.flags = GFL_ITEM;
01420     if (bestitem->timeout)
01421         goal.flags |= GFL_DROPPED;
01422     if (bestitem->flags & IFL_ROAM)
01423         goal.flags |= GFL_ROAM;
01424     goal.iteminfo = bestitem->iteminfo;
01425     //if it's a dropped item
01426     if (bestitem->timeout)
01427     {
01428         avoidtime = AVOID_DROPPED_TIME;
01429     } //end if
01430     else
01431     {
01432         avoidtime = iteminfo->respawntime;
01433         if (!avoidtime)
01434             avoidtime = AVOID_DEFAULT_TIME;
01435         if (avoidtime < AVOID_MINIMUM_TIME)
01436             avoidtime = AVOID_MINIMUM_TIME;
01437     } //end else
01438     //add the chosen goal to the goals to avoid for a while
01439     BotAddToAvoidGoals(gs, bestitem->number, avoidtime);
01440     //push the goal on the stack
01441     BotPushGoal(goalstate, &goal);
01442     //
01443     return qtrue;
01444 } //end of the function BotChooseLTGItem

Here is the call graph for this function:

int BotChooseNBGItem int  goalstate,
vec3_t  origin,
int *  inventory,
int  travelflags,
bot_goal_t ltg,
float  maxtime
 

Definition at line 1451 of file be_ai_goal.c.

References AAS_AreaReachability(), AAS_AreaTravelTimeToGoalArea(), bot_goal_s::areanum, bot_goal_t, bot_goalstate_t, BotAddToAvoidGoals(), BotAvoidGoalTime(), BotGoalStateFromHandle(), BotPushGoal(), BotReachabilityArea(), bot_goalstate_s::client, Com_Memset(), droppedweight, levelitem_s::entitynum, bot_goal_s::entitynum, levelitem_s::flags, bot_goal_s::flags, FuzzyWeight(), FuzzyWeightUndecided(), g_gametype, levelitem_s::goalareanum, levelitem_s::goalorigin, itemconfig_t, itemconfig_s::iteminfo, levelitem_s::iteminfo, bot_goal_s::iteminfo, iteminfo_t, bot_goalstate_s::itemweightconfig, bot_goalstate_s::itemweightindex, bot_goalstate_s::lastreachabilityarea, levelitem_t, iteminfo_s::maxs, bot_goal_s::maxs, iteminfo_s::mins, bot_goal_s::mins, levelitem_s::next, iteminfo_s::number, levelitem_s::number, bot_goal_s::number, bot_goal_s::origin, iteminfo_s::respawntime, t, levelitem_s::timeout, libvar_s::value, VectorCopy, and levelitem_s::weight.

01453 {
01454     int areanum, t, weightnum, ltg_time;
01455     float weight, bestweight, avoidtime;
01456     iteminfo_t *iteminfo;
01457     itemconfig_t *ic;
01458     levelitem_t *li, *bestitem;
01459     bot_goal_t goal;
01460     bot_goalstate_t *gs;
01461 
01462     gs = BotGoalStateFromHandle(goalstate);
01463     if (!gs)
01464         return qfalse;
01465     if (!gs->itemweightconfig)
01466         return qfalse;
01467     //get the area the bot is in
01468     areanum = BotReachabilityArea(origin, gs->client);
01469     //if the bot is in solid or if the area the bot is in has no reachability links
01470     if (!areanum || !AAS_AreaReachability(areanum))
01471     {
01472         //use the last valid area the bot was in
01473         areanum = gs->lastreachabilityarea;
01474     } //end if
01475     //remember the last area with reachabilities the bot was in
01476     gs->lastreachabilityarea = areanum;
01477     //if still in solid
01478     if (!areanum)
01479         return qfalse;
01480     //
01481     if (ltg) ltg_time = AAS_AreaTravelTimeToGoalArea(areanum, origin, ltg->areanum, travelflags);
01482     else ltg_time = 99999;
01483     //the item configuration
01484     ic = itemconfig;
01485     if (!itemconfig)
01486         return qfalse;
01487     //best weight and item so far
01488     bestweight = 0;
01489     bestitem = NULL;
01490     Com_Memset(&goal, 0, sizeof(bot_goal_t));
01491     //go through the items in the level
01492     for (li = levelitems; li; li = li->next)
01493     {
01494         if (g_gametype == GT_SINGLE_PLAYER) {
01495             if (li->flags & IFL_NOTSINGLE)
01496                 continue;
01497         }
01498         else if (g_gametype >= GT_TEAM) {
01499             if (li->flags & IFL_NOTTEAM)
01500                 continue;
01501         }
01502         else {
01503             if (li->flags & IFL_NOTFREE)
01504                 continue;
01505         }
01506         if (li->flags & IFL_NOTBOT)
01507             continue;
01508         //if the item is in a possible goal area
01509         if (!li->goalareanum)
01510             continue;
01511         //FIXME: is this a good thing? added this for items that never spawned into the game (f.i. CTF flags in obelisk)
01512         if (!li->entitynum && !(li->flags & IFL_ROAM))
01513             continue;
01514         //get the fuzzy weight function for this item
01515         iteminfo = &ic->iteminfo[li->iteminfo];
01516         weightnum = gs->itemweightindex[iteminfo->number];
01517         if (weightnum < 0)
01518             continue;
01519         //
01520 #ifdef UNDECIDEDFUZZY
01521         weight = FuzzyWeightUndecided(inventory, gs->itemweightconfig, weightnum);
01522 #else
01523         weight = FuzzyWeight(inventory, gs->itemweightconfig, weightnum);
01524 #endif //UNDECIDEDFUZZY
01525 #ifdef DROPPEDWEIGHT
01526         //HACK: to make dropped items more attractive
01527         if (li->timeout)
01528             weight += droppedweight->value;
01529 #endif //DROPPEDWEIGHT
01530         //use weight scale for item_botroam
01531         if (li->flags & IFL_ROAM) weight *= li->weight;
01532         //
01533         if (weight > 0)
01534         {
01535             //get the travel time towards the goal area
01536             t = AAS_AreaTravelTimeToGoalArea(areanum, origin, li->goalareanum, travelflags);
01537             //if the goal is reachable
01538             if (t > 0 && t < maxtime)
01539             {
01540                 //if this item won't respawn before we get there
01541                 avoidtime = BotAvoidGoalTime(goalstate, li->number);
01542                 if (avoidtime - t * 0.009 > 0)
01543                     continue;
01544                 //
01545                 weight /= (float) t * TRAVELTIME_SCALE;
01546                 //
01547                 if (weight > bestweight)
01548                 {
01549                     t = 0;
01550                     if (ltg && !li->timeout)
01551                     {
01552                         //get the travel time from the goal to the long term goal
01553                         t = AAS_AreaTravelTimeToGoalArea(li->goalareanum, li->goalorigin, ltg->areanum, travelflags);
01554                     } //end if
01555                     //if the travel back is possible and doesn't take too long
01556                     if (t <= ltg_time)
01557                     {
01558                         bestweight = weight;
01559                         bestitem = li;
01560                     } //end if
01561                 } //end if
01562             } //end if
01563         } //end if
01564     } //end for
01565     //if no goal item found
01566     if (!bestitem)
01567         return qfalse;
01568     //create a bot goal for this item
01569     iteminfo = &ic->iteminfo[bestitem->iteminfo];
01570     VectorCopy(bestitem->goalorigin, goal.origin);
01571     VectorCopy(iteminfo->mins, goal.mins);
01572     VectorCopy(iteminfo->maxs, goal.maxs);
01573     goal.areanum = bestitem->goalareanum;
01574     goal.entitynum = bestitem->entitynum;
01575     goal.number = bestitem->number;
01576     goal.flags = GFL_ITEM;
01577     if (bestitem->timeout)
01578         goal.flags |= GFL_DROPPED;
01579     if (bestitem->flags & IFL_ROAM)
01580         goal.flags |= GFL_ROAM;
01581     goal.iteminfo = bestitem->iteminfo;
01582     //if it's a dropped item
01583     if (bestitem->timeout)
01584     {
01585         avoidtime = AVOID_DROPPED_TIME;
01586     } //end if
01587     else
01588     {
01589         avoidtime = iteminfo->respawntime;
01590         if (!avoidtime)
01591             avoidtime = AVOID_DEFAULT_TIME;
01592         if (avoidtime < AVOID_MINIMUM_TIME)
01593             avoidtime = AVOID_MINIMUM_TIME;
01594     } //end else
01595     //add the chosen goal to the goals to avoid for a while
01596     BotAddToAvoidGoals(gs, bestitem->number, avoidtime);
01597     //push the goal on the stack
01598     BotPushGoal(goalstate, &goal);
01599     //
01600     return qtrue;
01601 } //end of the function BotChooseNBGItem

Here is the call graph for this function:

void BotDumpAvoidGoals int  goalstate  ) 
 

Definition at line 718 of file be_ai_goal.c.

References AAS_Time(), bot_goalstate_s::avoidgoals, bot_goalstate_s::avoidgoaltimes, bot_goalstate_t, BotGoalName(), BotGoalStateFromHandle(), i, Log_Write(), and name.

00719 {
00720     int i;
00721     bot_goalstate_t *gs;
00722     char name[32];
00723 
00724     gs = BotGoalStateFromHandle(goalstate);
00725     if (!gs) return;
00726     for (i = 0; i < MAX_AVOIDGOALS; i++)
00727     {
00728         if (gs->avoidgoaltimes[i] >= AAS_Time())
00729         {
00730             BotGoalName(gs->avoidgoals[i], name, 32);
00731             Log_Write("avoid goal %s, number %d for %f seconds", name,
00732                 gs->avoidgoals[i], gs->avoidgoaltimes[i] - AAS_Time());
00733         } //end if
00734     } //end for
00735 } //end of the function BotDumpAvoidGoals

Here is the call graph for this function:

void BotDumpGoalStack int  goalstate  ) 
 

Definition at line 1182 of file be_ai_goal.c.

References bot_goalstate_t, BotGoalName(), BotGoalStateFromHandle(), bot_goalstate_s::goalstack, bot_goalstate_s::goalstacktop, i, Log_Write(), name, and bot_goal_s::number.

Referenced by BotPushGoal().

01183 {
01184     int i;
01185     bot_goalstate_t *gs;
01186     char name[32];
01187 
01188     gs = BotGoalStateFromHandle(goalstate);
01189     if (!gs) return;
01190     for (i = 1; i <= gs->goalstacktop; i++)
01191     {
01192         BotGoalName(gs->goalstack[i].number, name, 32);
01193         Log_Write("%d: %s", i, name);
01194     } //end for
01195 } //end of the function BotDumpGoalStack

Here is the call graph for this function:

void BotEmptyGoalStack int  goalstate  ) 
 

Definition at line 1237 of file be_ai_goal.c.

References bot_goalstate_t, BotGoalStateFromHandle(), and bot_goalstate_s::goalstacktop.

01238 {
01239     bot_goalstate_t *gs;
01240 
01241     gs = BotGoalStateFromHandle(goalstate);
01242     if (!gs) return;
01243     gs->goalstacktop = 0;
01244 } //end of the function BotEmptyGoalStack

Here is the call graph for this function:

void BotFindEntityForLevelItem levelitem_t li  ) 
 

Definition at line 965 of file be_ai_goal.c.

References AAS_EntityInfo(), aas_entityinfo_t, AAS_EntityModelindex(), AAS_NextEntity(), levelitem_s::entitynum, itemconfig_t, levelitem_s::iteminfo, itemconfig_s::iteminfo, aas_entityinfo_s::lastvisorigin, levelitem_t, iteminfo_s::modelindex, levelitem_s::origin, aas_entityinfo_s::origin, vec3_t, VectorLength(), and VectorSubtract.

00966 {
00967     int ent, modelindex;
00968     itemconfig_t *ic;
00969     aas_entityinfo_t entinfo;
00970     vec3_t dir;
00971 
00972     ic = itemconfig;
00973     if (!itemconfig) return;
00974     for (ent = AAS_NextEntity(0); ent; ent = AAS_NextEntity(ent))
00975     {
00976         //get the model index of the entity
00977         modelindex = AAS_EntityModelindex(ent);
00978         //
00979         if (!modelindex) continue;
00980         //get info about the entity
00981         AAS_EntityInfo(ent, &entinfo);
00982         //if the entity is still moving
00983         if (entinfo.origin[0] != entinfo.lastvisorigin[0] ||
00984                 entinfo.origin[1] != entinfo.lastvisorigin[1] ||
00985                 entinfo.origin[2] != entinfo.lastvisorigin[2]) continue;
00986         //
00987         if (ic->iteminfo[li->iteminfo].modelindex == modelindex)
00988         {
00989             //check if the entity is very close
00990             VectorSubtract(li->origin, entinfo.origin, dir);
00991             if (VectorLength(dir) < 30)
00992             {
00993                 //found an entity for this level item
00994                 li->entitynum = ent;
00995             } //end if
00996         } //end if
00997     } //end for
00998 } //end of the function BotFindEntityForLevelItem

Here is the call graph for this function:

void BotFreeGoalState int  handle  ) 
 

Definition at line 1752 of file be_ai_goal.c.

References BotFreeItemWeights(), botgoalstates, botimport, FreeMemory(), and PRT_FATAL.

Referenced by BotShutdownGoalAI().

01753 {
01754     if (handle <= 0 || handle > MAX_CLIENTS)
01755     {
01756         botimport.Print(PRT_FATAL, "goal state handle %d out of range\n", handle);
01757         return;
01758     } //end if
01759     if (!botgoalstates[handle])
01760     {
01761         botimport.Print(PRT_FATAL, "invalid goal state handle %d\n", handle);
01762         return;
01763     } //end if
01764     BotFreeItemWeights(handle);
01765     FreeMemory(botgoalstates[handle]);
01766     botgoalstates[handle] = NULL;
01767 } //end of the function BotFreeGoalState

Here is the call graph for this function:

void BotFreeInfoEntities void   ) 
 

Definition at line 451 of file be_ai_goal.c.

References campspot_t, campspots, FreeMemory(), maplocation_t, maplocations, campspot_s::next, and maplocation_s::next.

Referenced by BotInitInfoEntities(), and BotShutdownGoalAI().

00452 {
00453     maplocation_t *ml, *nextml;
00454     campspot_t *cs, *nextcs;
00455 
00456     for (ml = maplocations; ml; ml = nextml)
00457     {
00458         nextml = ml->next;
00459         FreeMemory(ml);
00460     } //end for
00461     maplocations = NULL;
00462     for (cs = campspots; cs; cs = nextcs)
00463     {
00464         nextcs = cs->next;
00465         FreeMemory(cs);
00466     } //end for
00467     campspots = NULL;
00468 } //end of the function BotFreeInfoEntities

Here is the call graph for this function:

void BotFreeItemWeights int  goalstate  ) 
 

Definition at line 1716 of file be_ai_goal.c.

References bot_goalstate_t, BotGoalStateFromHandle(), FreeMemory(), FreeWeightConfig(), bot_goalstate_s::itemweightconfig, and bot_goalstate_s::itemweightindex.

Referenced by BotFreeGoalState().

01717 {
01718     bot_goalstate_t *gs;
01719 
01720     gs = BotGoalStateFromHandle(goalstate);
01721     if (!gs) return;
01722     if (gs->itemweightconfig) FreeWeightConfig(gs->itemweightconfig);
01723     if (gs->itemweightindex) FreeMemory(gs->itemweightindex);
01724 } //end of the function BotFreeItemWeights

Here is the call graph for this function:

int BotGetLevelItemGoal int  index,
char *  name,
bot_goal_t goal
 

Definition at line 859 of file be_ai_goal.c.

References bot_goal_s::areanum, bot_goal_t, bot_goal_s::entitynum, levelitem_s::entitynum, levelitem_s::flags, bot_goal_s::flags, g_gametype, levelitem_s::goalareanum, levelitem_s::goalorigin, itemconfig, itemconfig_s::iteminfo, levelitem_s::iteminfo, levelitem_t, bot_goal_s::maxs, bot_goal_s::mins, name, levelitem_s::next, levelitem_s::number, bot_goal_s::number, bot_goal_s::origin, Q_stricmp(), levelitem_s::timeout, and VectorCopy.

00860 {
00861     levelitem_t *li;
00862 
00863     if (!itemconfig) return -1;
00864     li = levelitems;
00865     if (index >= 0)
00866     {
00867         for (; li; li = li->next)
00868         {
00869             if (li->number == index)
00870             {
00871                 li = li->next;
00872                 break;
00873             } //end if
00874         } //end for
00875     } //end for
00876     for (; li; li = li->next)
00877     {
00878         //
00879         if (g_gametype == GT_SINGLE_PLAYER) {
00880             if (li->flags & IFL_NOTSINGLE) continue;
00881         }
00882         else if (g_gametype >= GT_TEAM) {
00883             if (li->flags & IFL_NOTTEAM) continue;
00884         }
00885         else {
00886             if (li->flags & IFL_NOTFREE) continue;
00887         }
00888         if (li->flags & IFL_NOTBOT) continue;
00889         //
00890         if (!Q_stricmp(name, itemconfig->iteminfo[li->iteminfo].name))
00891         {
00892             goal->areanum = li->goalareanum;
00893             VectorCopy(li->goalorigin, goal->origin);
00894             goal->entitynum = li->entitynum;
00895             VectorCopy(itemconfig->iteminfo[li->iteminfo].mins, goal->mins);
00896             VectorCopy(itemconfig->iteminfo[li->iteminfo].maxs, goal->maxs);
00897             goal->number = li->number;
00898             goal->flags = GFL_ITEM;
00899             if (li->timeout) goal->flags |= GFL_DROPPED;
00900             //botimport.Print(PRT_MESSAGE, "found li %s\n", itemconfig->iteminfo[li->iteminfo].name);
00901             return li->number;
00902         } //end if
00903     } //end for
00904     return -1;
00905 } //end of the function BotGetLevelItemGoal

Here is the call graph for this function:

int BotGetMapLocationGoal char *  name,
bot_goal_t goal
 

Definition at line 912 of file be_ai_goal.c.

References bot_goal_s::areanum, maplocation_s::areanum, bot_goal_t, bot_goal_s::entitynum, maplocation_t, bot_goal_s::maxs, bot_goal_s::mins, maplocation_s::name, name, maplocation_s::next, maplocation_s::origin, bot_goal_s::origin, Q_stricmp(), vec3_t, and VectorCopy.

00913 {
00914     maplocation_t *ml;
00915     vec3_t mins = {-8, -8, -8}, maxs = {8, 8, 8};
00916 
00917     for (ml = maplocations; ml; ml = ml->next)
00918     {
00919         if (!Q_stricmp(ml->name, name))
00920         {
00921             goal->areanum = ml->areanum;
00922             VectorCopy(ml->origin, goal->origin);
00923             goal->entitynum = 0;
00924             VectorCopy(mins, goal->mins);
00925             VectorCopy(maxs, goal->maxs);
00926             return qtrue;
00927         } //end if
00928     } //end for
00929     return qfalse;
00930 } //end of the function BotGetMapLocationGoal

Here is the call graph for this function:

int BotGetNextCampSpotGoal int  num,
bot_goal_t goal
 

Definition at line 937 of file be_ai_goal.c.

References bot_goal_s::areanum, campspot_s::areanum, bot_goal_t, campspot_t, bot_goal_s::entitynum, i, bot_goal_s::maxs, bot_goal_s::mins, campspot_s::next, campspot_s::origin, bot_goal_s::origin, vec3_t, and VectorCopy.

00938 {
00939     int i;
00940     campspot_t *cs;
00941     vec3_t mins = {-8, -8, -8}, maxs = {8, 8, 8};
00942 
00943     if (num < 0) num = 0;
00944     i = num;
00945     for (cs = campspots; cs; cs = cs->next)
00946     {
00947         if (--i < 0)
00948         {
00949             goal->areanum = cs->areanum;
00950             VectorCopy(cs->origin, goal->origin);
00951             goal->entitynum = 0;
00952             VectorCopy(mins, goal->mins);
00953             VectorCopy(maxs, goal->maxs);
00954             return num+1;
00955         } //end if
00956     } //end for
00957     return 0;
00958 } //end of the function BotGetNextCampSpotGoal

int BotGetSecondGoal int  goalstate,
bot_goal_t goal
 

Definition at line 1267 of file be_ai_goal.c.

References bot_goal_t, bot_goalstate_t, BotGoalStateFromHandle(), Com_Memcpy(), bot_goalstate_s::goalstack, and bot_goalstate_s::goalstacktop.

01268 {
01269     bot_goalstate_t *gs;
01270 
01271     gs = BotGoalStateFromHandle(goalstate);
01272     if (!gs) return qfalse;
01273     if (gs->goalstacktop <= 1) return qfalse;
01274     Com_Memcpy(goal, &gs->goalstack[gs->goalstacktop-1], sizeof(bot_goal_t));
01275     return qtrue;
01276 } //end of the function BotGetSecondGoal

Here is the call graph for this function:

int BotGetTopGoal int  goalstate,
bot_goal_t goal
 

Definition at line 1251 of file be_ai_goal.c.

References bot_goal_t, bot_goalstate_t, BotGoalStateFromHandle(), Com_Memcpy(), bot_goalstate_s::goalstack, and bot_goalstate_s::goalstacktop.

01252 {
01253     bot_goalstate_t *gs;
01254 
01255     gs = BotGoalStateFromHandle(goalstate);
01256     if (!gs) return qfalse;
01257     if (!gs->goalstacktop) return qfalse;
01258     Com_Memcpy(goal, &gs->goalstack[gs->goalstacktop], sizeof(bot_goal_t));
01259     return qtrue;
01260 } //end of the function BotGetTopGoal

Here is the call graph for this function:

void BotGoalName int  number,
char *  name,
int  size
 

Definition at line 679 of file be_ai_goal.c.

References itemconfig, itemconfig_s::iteminfo, levelitem_s::iteminfo, levelitem_t, name, levelitem_s::next, levelitem_s::number, strcpy(), and strncpy().

Referenced by BotDumpAvoidGoals(), and BotDumpGoalStack().

00680 {
00681     levelitem_t *li;
00682 
00683     if (!itemconfig) return;
00684     //
00685     for (li = levelitems; li; li = li->next)
00686     {
00687         if (li->number == number)
00688         {
00689             strncpy(name, itemconfig->iteminfo[li->iteminfo].name, size-1);
00690             name[size-1] = '\0';
00691             return;
00692         } //end for
00693     } //end for
00694     strcpy(name, "");
00695     return;
00696 } //end of the function BotGoalName

Here is the call graph for this function:

bot_goalstate_t* BotGoalStateFromHandle int  handle  ) 
 

Definition at line 202 of file be_ai_goal.c.

References bot_goalstate_t, botgoalstates, botimport, and PRT_FATAL.

Referenced by BotAvoidGoalTime(), BotChooseLTGItem(), BotChooseNBGItem(), BotDumpAvoidGoals(), BotDumpGoalStack(), BotEmptyGoalStack(), BotFreeItemWeights(), BotGetSecondGoal(), BotGetTopGoal(), BotInterbreedGoalFuzzyLogic(), BotLoadItemWeights(), BotMutateGoalFuzzyLogic(), BotPopGoal(), BotPushGoal(), BotRemoveFromAvoidGoals(), BotResetAvoidGoals(), BotResetGoalState(), BotSaveGoalFuzzyLogic(), and BotSetAvoidGoalTime().

00203 {
00204     if (handle <= 0 || handle > MAX_CLIENTS)
00205     {
00206         botimport.Print(PRT_FATAL, "goal state handle %d out of range\n", handle);
00207         return NULL;
00208     } //end if
00209     if (!botgoalstates[handle])
00210     {
00211         botimport.Print(PRT_FATAL, "invalid goal state %d\n", handle);
00212         return NULL;
00213     } //end if
00214     return botgoalstates[handle];
00215 } //end of the function BotGoalStateFromHandle

void BotInitInfoEntities void   ) 
 

Definition at line 475 of file be_ai_goal.c.

References AAS_FloatForBSPEpairKey(), AAS_NextBSPEntity(), AAS_PointAreaNum(), AAS_ValueForBSPEpairKey(), AAS_VectorForBSPEpairKey(), campspot_s::areanum, maplocation_s::areanum, BotFreeInfoEntities(), botimport, campspot_t, campspots, FreeMemory(), GetClearedMemory(), maplocation_t, maplocations, MAX_EPAIRKEY, campspot_s::name, maplocation_s::name, campspot_s::next, maplocation_s::next, campspot_s::origin, maplocation_s::origin, PRT_MESSAGE, campspot_s::random, campspot_s::range, strcmp(), campspot_s::wait, and campspot_s::weight.

Referenced by BotInitLevelItems().

00476 {
00477     char classname[MAX_EPAIRKEY];
00478     maplocation_t *ml;
00479     campspot_t *cs;
00480     int ent, numlocations, numcampspots;
00481 
00482     BotFreeInfoEntities();
00483     //
00484     numlocations = 0;
00485     numcampspots = 0;
00486     for (ent = AAS_NextBSPEntity(0); ent; ent = AAS_NextBSPEntity(ent))
00487     {
00488         if (!AAS_ValueForBSPEpairKey(ent, "classname", classname, MAX_EPAIRKEY)) continue;
00489 
00490         //map locations
00491         if (!strcmp(classname, "target_location"))
00492         {
00493             ml = (maplocation_t *) GetClearedMemory(sizeof(maplocation_t));
00494             AAS_VectorForBSPEpairKey(ent, "origin", ml->origin);
00495             AAS_ValueForBSPEpairKey(ent, "message", ml->name, sizeof(ml->name));
00496             ml->areanum = AAS_PointAreaNum(ml->origin);
00497             ml->next = maplocations;
00498             maplocations = ml;
00499             numlocations++;
00500         } //end if
00501         //camp spots
00502         else if (!strcmp(classname, "info_camp"))
00503         {
00504             cs = (campspot_t *) GetClearedMemory(sizeof(campspot_t));
00505             AAS_VectorForBSPEpairKey(ent, "origin", cs->origin);
00506             //cs->origin[2] += 16;
00507             AAS_ValueForBSPEpairKey(ent, "message", cs->name, sizeof(cs->name));
00508             AAS_FloatForBSPEpairKey(ent, "range", &cs->range);
00509             AAS_FloatForBSPEpairKey(ent, "weight", &cs->weight);
00510             AAS_FloatForBSPEpairKey(ent, "wait", &cs->wait);
00511             AAS_FloatForBSPEpairKey(ent, "random", &cs->random);
00512             cs->areanum = AAS_PointAreaNum(cs->origin);
00513             if (!cs->areanum)
00514             {
00515                 botimport.Print(PRT_MESSAGE, "camp spot at %1.1f %1.1f %1.1f in solid\n", cs->origin[0], cs->origin[1], cs->origin[2]);
00516                 FreeMemory(cs);
00517                 continue;
00518             } //end if
00519             cs->next = campspots;
00520             campspots = cs;
00521             //AAS_DrawPermanentCross(cs->origin, 4, LINECOLOR_YELLOW);
00522             numcampspots++;
00523         } //end else if
00524     } //end for
00525     if (bot_developer)
00526     {
00527         botimport.Print(PRT_MESSAGE, "%d map locations\n", numlocations);
00528         botimport.Print(PRT_MESSAGE, "%d camp spots\n", numcampspots);
00529     } //end if
00530 } //end of the function BotInitInfoEntities

Here is the call graph for this function:

void BotInitLevelItems void   ) 
 

Definition at line 537 of file be_ai_goal.c.

References AAS_BestReachableArea(), AAS_BestReachableFromJumpPadArea(), AAS_DropToFloor(), AAS_FloatForBSPEpairKey(), AAS_IntForBSPEpairKey(), AAS_Loaded(), AAS_NextBSPEntity(), AAS_PointContents(), AAS_Trace(), AAS_ValueForBSPEpairKey(), AAS_VectorForBSPEpairKey(), AddLevelItemToList(), AllocLevelItem(), botimport, BotInitInfoEntities(), bsp_trace_t, iteminfo_s::classname, CONTENTS_PLAYERCLIP, CONTENTS_SOLID, levelitem_s::entitynum, levelitem_s::flags, bsp_trace_s::fraction, levelitem_s::goalareanum, levelitem_s::goalorigin, i, InitLevelItemHeap(), itemconfig_t, itemconfig_s::iteminfo, levelitem_s::iteminfo, levelitem_t, levelitems, Log_Write(), MAX_EPAIRKEY, iteminfo_s::maxs, iteminfo_s::mins, iteminfo_s::modelindex, levelitem_s::number, itemconfig_s::numiteminfo, numlevelitems, levelitem_s::origin, PRT_ERROR, PRT_MESSAGE, strcmp(), levelitem_s::timeout, value, vec3_t, VectorCopy, and levelitem_s::weight.

Referenced by Export_BotLibLoadMap().

00538 {
00539     int i, spawnflags, value;
00540     char classname[MAX_EPAIRKEY];
00541     vec3_t origin, end;
00542     int ent, goalareanum;
00543     itemconfig_t *ic;
00544     levelitem_t *li;
00545     bsp_trace_t trace;
00546 
00547     //initialize the map locations and camp spots
00548     BotInitInfoEntities();
00549 
00550     //initialize the level item heap
00551     InitLevelItemHeap();
00552     levelitems = NULL;
00553     numlevelitems = 0;
00554     //
00555     ic = itemconfig;
00556     if (!ic) return;
00557 
00558     //if there's no AAS file loaded
00559     if (!AAS_Loaded()) return;
00560 
00561     //update the modelindexes of the item info
00562     for (i = 0; i < ic->numiteminfo; i++)
00563     {
00564         //ic->iteminfo[i].modelindex = AAS_IndexFromModel(ic->iteminfo[i].model);
00565         if (!ic->iteminfo[i].modelindex)
00566         {
00567             Log_Write("item %s has modelindex 0", ic->iteminfo[i].classname);
00568         } //end if
00569     } //end for
00570 
00571     for (ent = AAS_NextBSPEntity(0); ent; ent = AAS_NextBSPEntity(ent))
00572     {
00573         if (!AAS_ValueForBSPEpairKey(ent, "classname", classname, MAX_EPAIRKEY)) continue;
00574         //
00575         spawnflags = 0;
00576         AAS_IntForBSPEpairKey(ent, "spawnflags", &spawnflags);
00577         //
00578         for (i = 0; i < ic->numiteminfo; i++)
00579         {
00580             if (!strcmp(classname, ic->iteminfo[i].classname)) break;
00581         } //end for
00582         if (i >= ic->numiteminfo)
00583         {
00584             Log_Write("entity %s unknown item\r\n", classname);
00585             continue;
00586         } //end if
00587         //get the origin of the item
00588         if (!AAS_VectorForBSPEpairKey(ent, "origin", origin))
00589         {
00590             botimport.Print(PRT_ERROR, "item %s without origin\n", classname);
00591             continue;
00592         } //end else
00593         //
00594         goalareanum = 0;
00595         //if it is a floating item
00596         if (spawnflags & 1)
00597         {
00598             //if the item is not floating in water
00599             if (!(AAS_PointContents(origin) & CONTENTS_WATER))
00600             {
00601                 VectorCopy(origin, end);
00602                 end[2] -= 32;
00603                 trace = AAS_Trace(origin, ic->iteminfo[i].mins, ic->iteminfo[i].maxs, end, -1, CONTENTS_SOLID|CONTENTS_PLAYERCLIP);
00604                 //if the item not near the ground
00605                 if (trace.fraction >= 1)
00606                 {
00607                     //if the item is not reachable from a jumppad
00608                     goalareanum = AAS_BestReachableFromJumpPadArea(origin, ic->iteminfo[i].mins, ic->iteminfo[i].maxs);
00609                     Log_Write("item %s reachable from jumppad area %d\r\n", ic->iteminfo[i].classname, goalareanum);
00610                     //botimport.Print(PRT_MESSAGE, "item %s reachable from jumppad area %d\r\n", ic->iteminfo[i].classname, goalareanum);
00611                     if (!goalareanum) continue;
00612                 } //end if
00613             } //end if
00614         } //end if
00615 
00616         li = AllocLevelItem();
00617         if (!li) return;
00618         //
00619         li->number = ++numlevelitems;
00620         li->timeout = 0;
00621         li->entitynum = 0;
00622         //
00623         li->flags = 0;
00624         AAS_IntForBSPEpairKey(ent, "notfree", &value);
00625         if (value) li->flags |= IFL_NOTFREE;
00626         AAS_IntForBSPEpairKey(ent, "notteam", &value);
00627         if (value) li->flags |= IFL_NOTTEAM;
00628         AAS_IntForBSPEpairKey(ent, "notsingle", &value);
00629         if (value) li->flags |= IFL_NOTSINGLE;
00630         AAS_IntForBSPEpairKey(ent, "notbot", &value);
00631         if (value) li->flags |= IFL_NOTBOT;
00632         if (!strcmp(classname, "item_botroam"))
00633         {
00634             li->flags |= IFL_ROAM;
00635             AAS_FloatForBSPEpairKey(ent, "weight", &li->weight);
00636         } //end if
00637         //if not a stationary item
00638         if (!(spawnflags & 1))
00639         {
00640             if (!AAS_DropToFloor(origin, ic->iteminfo[i].mins, ic->iteminfo[i].maxs))
00641             {
00642                 botimport.Print(PRT_MESSAGE, "%s in solid at (%1.1f %1.1f %1.1f)\n",
00643                                                 classname, origin[0], origin[1], origin[2]);
00644             } //end if
00645         } //end if
00646         //item info of the level item
00647         li->iteminfo = i;
00648         //origin of the item
00649         VectorCopy(origin, li->origin);
00650         //
00651         if (goalareanum)
00652         {
00653             li->goalareanum = goalareanum;
00654             VectorCopy(origin, li->goalorigin);
00655         } //end if
00656         else
00657         {
00658             //get the item goal area and goal origin
00659             li->goalareanum = AAS_BestReachableArea(origin,
00660                             ic->iteminfo[i].mins, ic->iteminfo[i].maxs,
00661                             li->goalorigin);
00662             if (!li->goalareanum)
00663             {
00664                 botimport.Print(PRT_MESSAGE, "%s not reachable for bots at (%1.1f %1.1f %1.1f)\n",
00665                                                 classname, origin[0], origin[1], origin[2]);
00666             } //end if
00667         } //end else
00668         //
00669         AddLevelItemToList(li);
00670     } //end for
00671     botimport.Print(PRT_MESSAGE, "found %d level items\n", numlevelitems);
00672 } //end of the function BotInitLevelItems

Here is the call graph for this function:

void BotInterbreedGoalFuzzyLogic int  parent1,
int  parent2,
int  child
 

Definition at line 222 of file be_ai_goal.c.

References bot_goalstate_t, BotGoalStateFromHandle(), c, InterbreedWeightConfigs(), bot_goalstate_s::itemweightconfig, and p2.

00223 {
00224     bot_goalstate_t *p1, *p2, *c;
00225 
00226     p1 = BotGoalStateFromHandle(parent1);
00227     p2 = BotGoalStateFromHandle(parent2);
00228     c = BotGoalStateFromHandle(child);
00229 
00230     InterbreedWeightConfigs(p1->itemweightconfig, p2->itemweightconfig,
00231                                     c->itemweightconfig);
00232 } //end of the function BotInterbreedingGoalFuzzyLogic

Here is the call graph for this function:

int BotItemGoalInVisButNotVisible int  viewer,
vec3_t  eye,
vec3_t  viewangles,
bot_goal_t goal
 

Definition at line 1637 of file be_ai_goal.c.

References AAS_EntityInfo(), aas_entityinfo_t, AAS_Time(), AAS_Trace(), bot_goal_t, bsp_trace_t, CONTENTS_SOLID, bot_goal_s::entitynum, bot_goal_s::flags, bsp_trace_s::fraction, aas_entityinfo_s::ltime, bot_goal_s::mins, NULL, bot_goal_s::origin, vec3_t, VectorAdd, and VectorScale.

01638 {
01639     aas_entityinfo_t entinfo;
01640     bsp_trace_t trace;
01641     vec3_t middle;
01642 
01643     if (!(goal->flags & GFL_ITEM)) return qfalse;
01644     //
01645     VectorAdd(goal->mins, goal->mins, middle);
01646     VectorScale(middle, 0.5, middle);
01647     VectorAdd(goal->origin, middle, middle);
01648     //
01649     trace = AAS_Trace(eye, NULL, NULL, middle, viewer, CONTENTS_SOLID);
01650     //if the goal middle point is visible
01651     if (trace.fraction >= 1)
01652     {
01653         //the goal entity number doesn't have to be valid
01654         //just assume it's valid
01655         if (goal->entitynum <= 0)
01656             return qfalse;
01657         //
01658         //if the entity data isn't valid
01659         AAS_EntityInfo(goal->entitynum, &entinfo);
01660         //NOTE: for some wacko reason entities are sometimes
01661         // not updated
01662         //if (!entinfo.valid) return qtrue;
01663         if (entinfo.ltime < AAS_Time() - 0.5)
01664             return qtrue;
01665     } //end if
01666     return qfalse;
01667 } //end of the function BotItemGoalInVisButNotVisible

Here is the call graph for this function:

int BotLoadItemWeights int  goalstate,
char *  filename
 

Definition at line 1690 of file be_ai_goal.c.

References bot_goalstate_t, BotGoalStateFromHandle(), botimport, itemconfig, bot_goalstate_s::itemweightconfig, bot_goalstate_s::itemweightindex, ItemWeightIndex(), PRT_FATAL, and ReadWeightConfig().

01691 {
01692     bot_goalstate_t *gs;
01693 
01694     gs = BotGoalStateFromHandle(goalstate);
01695     if (!gs) return BLERR_CANNOTLOADITEMWEIGHTS;
01696     //load the weight configuration
01697     gs->itemweightconfig = ReadWeightConfig(filename);
01698     if (!gs->itemweightconfig)
01699     {
01700         botimport.Print(PRT_FATAL, "couldn't load weights\n");
01701         return BLERR_CANNOTLOADITEMWEIGHTS;
01702     } //end if
01703     //if there's no item configuration
01704     if (!itemconfig) return BLERR_CANNOTLOADITEMWEIGHTS;
01705     //create the item weight index
01706     gs->itemweightindex = ItemWeightIndex(gs->itemweightconfig, itemconfig);
01707     //everything went ok
01708     return BLERR_NOERROR;
01709 } //end of the function BotLoadItemWeights

Here is the call graph for this function:

void BotMutateGoalFuzzyLogic int  goalstate,
float  range
 

Definition at line 253 of file be_ai_goal.c.

References bot_goalstate_t, BotGoalStateFromHandle(), EvolveWeightConfig(), and bot_goalstate_s::itemweightconfig.

00254 {
00255     bot_goalstate_t *gs;
00256 
00257     gs = BotGoalStateFromHandle(goalstate);
00258 
00259     EvolveWeightConfig(gs->itemweightconfig);
00260 } //end of the function BotMutateGoalFuzzyLogic

Here is the call graph for this function:

void BotPopGoal int  goalstate  ) 
 

Definition at line 1223 of file be_ai_goal.c.

References bot_goalstate_t, BotGoalStateFromHandle(), and bot_goalstate_s::goalstacktop.

01224 {
01225     bot_goalstate_t *gs;
01226 
01227     gs = BotGoalStateFromHandle(goalstate);
01228     if (!gs) return;
01229     if (gs->goalstacktop > 0) gs->goalstacktop--;
01230 } //end of the function BotPopGoal

Here is the call graph for this function:

void BotPushGoal int  goalstate,
bot_goal_t goal
 

Definition at line 1202 of file be_ai_goal.c.

References bot_goal_t, bot_goalstate_t, BotDumpGoalStack(), BotGoalStateFromHandle(), botimport, Com_Memcpy(), bot_goalstate_s::goalstack, bot_goalstate_s::goalstacktop, MAX_GOALSTACK, and PRT_ERROR.

Referenced by BotChooseLTGItem(), and BotChooseNBGItem().

01203 {
01204     bot_goalstate_t *gs;
01205 
01206     gs = BotGoalStateFromHandle(goalstate);
01207     if (!gs) return;
01208     if (gs->goalstacktop >= MAX_GOALSTACK-1)
01209     {
01210         botimport.Print(PRT_ERROR, "goal heap overflow\n");
01211         BotDumpGoalStack(goalstate);
01212         return;
01213     } //end if
01214     gs->goalstacktop++;
01215     Com_Memcpy(&gs->goalstack[gs->goalstacktop], goal, sizeof(bot_goal_t));
01216 } //end of the function BotPushGoal

Here is the call graph for this function:

void BotRemoveFromAvoidGoals int  goalstate,
int  number
 

Definition at line 774 of file be_ai_goal.c.

References AAS_Time(), bot_goalstate_s::avoidgoals, bot_goalstate_s::avoidgoaltimes, bot_goalstate_t, BotGoalStateFromHandle(), i, and number.

00775 {
00776     int i;
00777     bot_goalstate_t *gs;
00778 
00779     gs = BotGoalStateFromHandle(goalstate);
00780     if (!gs) return;
00781     //don't use the goals the bot wants to avoid
00782     for (i = 0; i < MAX_AVOIDGOALS; i++)
00783     {
00784         if (gs->avoidgoals[i] == number && gs->avoidgoaltimes[i] >= AAS_Time())
00785         {
00786             gs->avoidgoaltimes[i] = 0;
00787             return;
00788         } //end if
00789     } //end for
00790 } //end of the function BotRemoveFromAvoidGoals

Here is the call graph for this function:

void BotResetAvoidGoals int  goalstate  ) 
 

Definition at line 703 of file be_ai_goal.c.

References bot_goalstate_s::avoidgoals, bot_goalstate_s::avoidgoaltimes, bot_goalstate_t, BotGoalStateFromHandle(), Com_Memset(), and MAX_AVOIDGOALS.

Referenced by BotResetGoalState().

00704 {
00705     bot_goalstate_t *gs;
00706 
00707     gs = BotGoalStateFromHandle(goalstate);
00708     if (!gs) return;
00709     Com_Memset(gs->avoidgoals, 0, MAX_AVOIDGOALS * sizeof(int));
00710     Com_Memset(gs->avoidgoaltimes, 0, MAX_AVOIDGOALS * sizeof(float));
00711 } //end of the function BotResetAvoidGoals

Here is the call graph for this function:

void BotResetGoalState int  goalstate  ) 
 

Definition at line 1674 of file be_ai_goal.c.

References bot_goal_t, bot_goalstate_t, BotGoalStateFromHandle(), BotResetAvoidGoals(), Com_Memset(), bot_goalstate_s::goalstack, bot_goalstate_s::goalstacktop, and MAX_GOALSTACK.

01675 {
01676     bot_goalstate_t *gs;
01677 
01678     gs = BotGoalStateFromHandle(goalstate);
01679     if (!gs) return;
01680     Com_Memset(gs->goalstack, 0, MAX_GOALSTACK * sizeof(bot_goal_t));
01681     gs->goalstacktop = 0;
01682     BotResetAvoidGoals(goalstate);
01683 } //end of the function BotResetGoalState

Here is the call graph for this function:

void BotSaveGoalFuzzyLogic int  goalstate,
char *  filename
 

Definition at line 239 of file be_ai_goal.c.

References bot_goalstate_t, and BotGoalStateFromHandle().

00240 {
00241     bot_goalstate_t *gs;
00242 
00243     gs = BotGoalStateFromHandle(goalstate);
00244 
00245     //WriteWeightConfig(filename, gs->itemweightconfig);
00246 } //end of the function BotSaveGoalFuzzyLogic

Here is the call graph for this function:

void BotSetAvoidGoalTime int  goalstate,
int  number,
float  avoidtime
 

Definition at line 820 of file be_ai_goal.c.

References bot_goalstate_t, BotAddToAvoidGoals(), BotGoalStateFromHandle(), itemconfig, itemconfig_s::iteminfo, levelitem_s::iteminfo, levelitem_t, levelitem_s::next, levelitem_s::number, number, and iteminfo_s::respawntime.

00821 {
00822     bot_goalstate_t *gs;
00823     levelitem_t *li;
00824 
00825     gs = BotGoalStateFromHandle(goalstate);
00826     if (!gs)
00827         return;
00828     if (avoidtime < 0)
00829     {
00830         if (!itemconfig)
00831             return;
00832         //
00833         for (li = levelitems; li; li = li->next)
00834         {
00835             if (li->number == number)
00836             {
00837                 avoidtime = itemconfig->iteminfo[li->iteminfo].respawntime;
00838                 if (!avoidtime)
00839                     avoidtime = AVOID_DEFAULT_TIME;
00840                 if (avoidtime < AVOID_MINIMUM_TIME)
00841                     avoidtime = AVOID_MINIMUM_TIME;
00842                 BotAddToAvoidGoals(gs, number, avoidtime);
00843                 return;
00844             } //end for
00845         } //end for
00846         return;
00847     } //end if
00848     else
00849     {
00850         BotAddToAvoidGoals(gs, number, avoidtime);
00851     } //end else
00852 } //end of the function BotSetAvoidGoalTime

Here is the call graph for this function:

int BotSetupGoalAI void   ) 
 

Definition at line 1774 of file be_ai_goal.c.

References botimport, droppedweight, g_gametype, itemconfig, LibVar(), LibVarString(), LibVarValue(), LoadItemConfig(), and PRT_FATAL.

Referenced by Export_BotLibSetup().

01775 {
01776     char *filename;
01777 
01778     //check if teamplay is on
01779     g_gametype = LibVarValue("g_gametype", "0");
01780     //item configuration file
01781     filename = LibVarString("itemconfig", "items.c");
01782     //load the item configuration
01783     itemconfig = LoadItemConfig(filename);
01784     if (!itemconfig)
01785     {
01786         botimport.Print(PRT_FATAL, "couldn't load item config\n");
01787         return BLERR_CANNOTLOADITEMCONFIG;
01788     } //end if
01789     //
01790     droppedweight = LibVar("droppedweight", "1000");
01791     //everything went ok
01792     return BLERR_NOERROR;
01793 } //end of the function BotSetupGoalAI

Here is the call graph for this function:

void BotShutdownGoalAI void   ) 
 

Definition at line 1800 of file be_ai_goal.c.

References BotFreeGoalState(), BotFreeInfoEntities(), botgoalstates, freelevelitems, FreeMemory(), i, itemconfig, levelitemheap, levelitems, and numlevelitems.

Referenced by Export_BotLibShutdown().

01801 {
01802     int i;
01803 
01804     if (itemconfig) FreeMemory(itemconfig);
01805     itemconfig = NULL;
01806     if (levelitemheap) FreeMemory(levelitemheap);
01807     levelitemheap = NULL;
01808     freelevelitems = NULL;
01809     levelitems = NULL;
01810     numlevelitems = 0;
01811 
01812     BotFreeInfoEntities();
01813 
01814     for (i = 1; i <= MAX_CLIENTS; i++)
01815     {
01816         if (botgoalstates[i])
01817         {
01818             BotFreeGoalState(i);
01819         } //end if
01820     } //end for
01821 } //end of the function BotShutdownGoalAI

Here is the call graph for this function:

int BotTouchingGoal vec3_t  origin,
bot_goal_t goal
 

Definition at line 1608 of file be_ai_goal.c.

References AAS_PresenceTypeBoundingBox(), bot_goal_t, i, bot_goal_s::maxs, bot_goal_s::mins, bot_goal_s::origin, PRESENCE_NORMAL, vec3_t, VectorAdd, and VectorSubtract.

01609 {
01610     int i;
01611     vec3_t boxmins, boxmaxs;
01612     vec3_t absmins, absmaxs;
01613     vec3_t safety_maxs = {0, 0, 0}; //{4, 4, 10};
01614     vec3_t safety_mins = {0, 0, 0}; //{-4, -4, 0};
01615 
01616     AAS_PresenceTypeBoundingBox(PRESENCE_NORMAL, boxmins, boxmaxs);
01617     VectorSubtract(goal->mins, boxmaxs, absmins);
01618     VectorSubtract(goal->maxs, boxmins, absmaxs);
01619     VectorAdd(absmins, goal->origin, absmins);
01620     VectorAdd(absmaxs, goal->origin, absmaxs);
01621     //make the box a little smaller for safety
01622     VectorSubtract(absmaxs, safety_maxs, absmaxs);
01623     VectorSubtract(absmins, safety_mins, absmins);
01624 
01625     for (i = 0; i < 3; i++)
01626     {
01627         if (origin[i] < absmins[i] || origin[i] > absmaxs[i]) return qfalse;
01628     } //end for
01629     return qtrue;
01630 } //end of the function BotTouchingGoal

Here is the call graph for this function:

void BotUpdateEntityItems void   ) 
 

Definition at line 1009 of file be_ai_goal.c.

References AAS_AreaJumpPad(), AAS_BestReachableArea(), AAS_EntityInfo(), aas_entityinfo_t, AAS_EntityModelindex(), AAS_EntityType(), AAS_NextEntity(), AAS_Time(), AddLevelItemToList(), AllocLevelItem(), levelitem_s::entitynum, levelitem_s::flags, FreeLevelItem(), g_gametype, levelitem_s::goalareanum, levelitem_s::goalorigin, i, itemconfig_t, itemconfig_s::iteminfo, levelitem_s::iteminfo, aas_entityinfo_s::lastvisorigin, levelitem_t, Log_Write(), iteminfo_s::maxs, iteminfo_s::mins, iteminfo_s::modelindex, levelitem_s::next, levelitem_s::number, itemconfig_s::numiteminfo, numlevelitems, aas_entityinfo_s::origin, levelitem_s::origin, RemoveLevelItemFromList(), levelitem_s::timeout, vec3_t, VectorCopy, VectorLength(), and VectorSubtract.

01010 {
01011     int ent, i, modelindex;
01012     vec3_t dir;
01013     levelitem_t *li, *nextli;
01014     aas_entityinfo_t entinfo;
01015     itemconfig_t *ic;
01016 
01017     //timeout current entity items if necessary
01018     for (li = levelitems; li; li = nextli)
01019     {
01020         nextli = li->next;
01021         //if it is a item that will time out
01022         if (li->timeout)
01023         {
01024             //timeout the item
01025             if (li->timeout < AAS_Time())
01026             {
01027                 RemoveLevelItemFromList(li);
01028                 FreeLevelItem(li);
01029             } //end if
01030         } //end if
01031     } //end for
01032     //find new entity items
01033     ic = itemconfig;
01034     if (!itemconfig) return;
01035     //
01036     for (ent = AAS_NextEntity(0); ent; ent = AAS_NextEntity(ent))
01037     {
01038         if (AAS_EntityType(ent) != ET_ITEM) continue;
01039         //get the model index of the entity
01040         modelindex = AAS_EntityModelindex(ent);
01041         //
01042         if (!modelindex) continue;
01043         //get info about the entity
01044         AAS_EntityInfo(ent, &entinfo);
01045         //FIXME: don't do this
01046         //skip all floating items for now
01047         //if (entinfo.groundent != ENTITYNUM_WORLD) continue;
01048         //if the entity is still moving
01049         if (entinfo.origin[0] != entinfo.lastvisorigin[0] ||
01050                 entinfo.origin[1] != entinfo.lastvisorigin[1] ||
01051                 entinfo.origin[2] != entinfo.lastvisorigin[2]) continue;
01052         //check if the entity is already stored as a level item
01053         for (li = levelitems; li; li = li->next)
01054         {
01055             //if the level item is linked to an entity
01056             if (li->entitynum && li->entitynum == ent)
01057             {
01058                 //the entity is re-used if the models are different
01059                 if (ic->iteminfo[li->iteminfo].modelindex != modelindex)
01060                 {
01061                     //remove this level item
01062                     RemoveLevelItemFromList(li);
01063                     FreeLevelItem(li);
01064                     li = NULL;
01065                     break;
01066                 } //end if
01067                 else
01068                 {
01069                     if (entinfo.origin[0] != li->origin[0] ||
01070                         entinfo.origin[1] != li->origin[1] ||
01071                         entinfo.origin[2] != li->origin[2])
01072                     {
01073                         VectorCopy(entinfo.origin, li->origin);
01074                         //also update the goal area number
01075                         li->goalareanum = AAS_BestReachableArea(li->origin,
01076                                         ic->iteminfo[li->iteminfo].mins, ic->iteminfo[li->iteminfo].maxs,
01077                                         li->goalorigin);
01078                     } //end if
01079                     break;
01080                 } //end else
01081             } //end if
01082         } //end for
01083         if (li) continue;
01084         //try to link the entity to a level item
01085         for (li = levelitems; li; li = li->next)
01086         {
01087             //if this level item is already linked
01088             if (li->entitynum) continue;
01089             //
01090             if (g_gametype == GT_SINGLE_PLAYER) {
01091                 if (li->flags & IFL_NOTSINGLE) continue;
01092             }
01093             else if (g_gametype >= GT_TEAM) {
01094                 if (li->flags & IFL_NOTTEAM) continue;
01095             }
01096             else {
01097                 if (li->flags & IFL_NOTFREE) continue;
01098             }
01099             //if the model of the level item and the entity are the same
01100             if (ic->iteminfo[li->iteminfo].modelindex == modelindex)
01101             {
01102                 //check if the entity is very close
01103                 VectorSubtract(li->origin, entinfo.origin, dir);
01104                 if (VectorLength(dir) < 30)
01105                 {
01106                     //found an entity for this level item
01107                     li->entitynum = ent;
01108                     //if the origin is different
01109                     if (entinfo.origin[0] != li->origin[0] ||
01110                         entinfo.origin[1] != li->origin[1] ||
01111                         entinfo.origin[2] != li->origin[2])
01112                     {
01113                         //update the level item origin
01114                         VectorCopy(entinfo.origin, li->origin);
01115                         //also update the goal area number
01116                         li->goalareanum = AAS_BestReachableArea(li->origin,
01117                                         ic->iteminfo[li->iteminfo].mins, ic->iteminfo[li->iteminfo].maxs,
01118                                         li->goalorigin);
01119                     } //end if
01120 #ifdef DEBUG
01121                     Log_Write("linked item %s to an entity", ic->iteminfo[li->iteminfo].classname);
01122 #endif //DEBUG
01123                     break;
01124                 } //end if
01125             } //end else
01126         } //end for
01127         if (li) continue;
01128         //check if the model is from a known item
01129         for (i = 0; i < ic->numiteminfo; i++)
01130         {
01131             if (ic->iteminfo[i].modelindex == modelindex)
01132             {
01133                 break;
01134             } //end if
01135         } //end for
01136         //if the model is not from a known item
01137         if (i >= ic->numiteminfo) continue;
01138         //allocate a new level item
01139         li = AllocLevelItem();
01140         //
01141         if (!li) continue;
01142         //entity number of the level item
01143         li->entitynum = ent;
01144         //number for the level item
01145         li->number = numlevelitems + ent;
01146         //set the item info index for the level item
01147         li->iteminfo = i;
01148         //origin of the item
01149         VectorCopy(entinfo.origin, li->origin);
01150         //get the item goal area and goal origin
01151         li->goalareanum = AAS_BestReachableArea(li->origin,
01152                                     ic->iteminfo[i].mins, ic->iteminfo[i].maxs,
01153                                     li->goalorigin);
01154         //never go for items dropped into jumppads
01155         if (AAS_AreaJumpPad(li->goalareanum))
01156         {
01157             FreeLevelItem(li);
01158             continue;
01159         } //end if
01160         //time this item out after 30 seconds
01161         //dropped items disappear after 30 seconds
01162         li->timeout = AAS_Time() + 30;
01163         //add the level item to the list
01164         AddLevelItemToList(li);
01165         //botimport.Print(PRT_MESSAGE, "found new level item %s\n", ic->iteminfo[i].classname);
01166     } //end for
01167     /*
01168     for (li = levelitems; li; li = li->next)
01169     {
01170         if (!li->entitynum)
01171         {
01172             BotFindEntityForLevelItem(li);
01173         } //end if
01174     } //end for*/
01175 } //end of the function BotUpdateEntityItems

Here is the call graph for this function:

void FreeLevelItem levelitem_t li  ) 
 

Definition at line 415 of file be_ai_goal.c.

References freelevelitems, levelitem_t, and levelitem_s::next.

Referenced by BotUpdateEntityItems().

00416 {
00417     li->next = freelevelitems;
00418     freelevelitems = li;
00419 } //end of the function FreeLevelItem

void InitLevelItemHeap void   ) 
 

Definition at line 371 of file be_ai_goal.c.

References freelevelitems, FreeMemory(), GetClearedMemory(), i, levelitem_t, levelitemheap, LibVarValue(), and levelitem_s::next.

Referenced by BotInitLevelItems().

00372 {
00373     int i, max_levelitems;
00374 
00375     if (levelitemheap) FreeMemory(levelitemheap);
00376 
00377     max_levelitems = (int) LibVarValue("max_levelitems", "256");
00378     levelitemheap = (levelitem_t *) GetClearedMemory(max_levelitems * sizeof(levelitem_t));
00379 
00380     for (i = 0; i < max_levelitems-1; i++)
00381     {
00382         levelitemheap[i].next = &levelitemheap[i + 1];
00383     } //end for
00384     levelitemheap[max_levelitems-1].next = NULL;
00385     //
00386     freelevelitems = levelitemheap;
00387 } //end of the function InitLevelItemHeap

Here is the call graph for this function:

int* ItemWeightIndex weightconfig_t iwc,
itemconfig_t ic
 

Definition at line 348 of file be_ai_goal.c.

References iteminfo_s::classname, FindFuzzyWeight(), GetClearedMemory(), i, itemconfig_t, itemconfig_s::iteminfo, Log_Write(), itemconfig_s::numiteminfo, and weightconfig_t.

Referenced by BotLoadItemWeights().

00349 {
00350     int *index, i;
00351 
00352     //initialize item weight index
00353     index = (int *) GetClearedMemory(sizeof(int) * ic->numiteminfo);
00354 
00355     for (i = 0; i < ic->numiteminfo; i++)
00356     {
00357         index[i] = FindFuzzyWeight(iwc, ic->iteminfo[i].classname);
00358         if (index[i] < 0)
00359         {
00360             Log_Write("item info %d \"%s\" has no fuzzy weight\r\n", i, ic->iteminfo[i].classname);
00361         } //end if
00362     } //end for
00363     return index;
00364 } //end of the function ItemWeightIndex

Here is the call graph for this function:

itemconfig_t* LoadItemConfig char *  filename  ) 
 

Definition at line 267 of file be_ai_goal.c.

References BOTFILESBASEFOLDER, botimport, iteminfo_s::classname, Com_Memset(), FreeMemory(), FreeSource(), GetClearedHunkMemory(), itemconfig_t, itemconfig_s::iteminfo, iteminfo_struct, iteminfo_t, LibVarSet(), LibVarValue(), LoadSourceFile(), MAX_PATH, iteminfo_s::number, itemconfig_s::numiteminfo, PC_ExpectTokenType(), PC_ReadToken(), PC_SetBaseFolder(), PRT_ERROR, PRT_MESSAGE, PRT_WARNING, ReadStructure(), source, source_t, SourceError(), strcmp(), token_s::string, StripDoubleQuotes(), strncpy(), token, token_t, and TT_STRING.

Referenced by BotSetupGoalAI().

00268 {
00269     int max_iteminfo;
00270     token_t token;
00271     char path[MAX_PATH];
00272     source_t *source;
00273     itemconfig_t *ic;
00274     iteminfo_t *ii;
00275 
00276     max_iteminfo = (int) LibVarValue("max_iteminfo", "256");
00277     if (max_iteminfo < 0)
00278     {
00279         botimport.Print(PRT_ERROR, "max_iteminfo = %d\n", max_iteminfo);
00280         max_iteminfo = 256;
00281         LibVarSet( "max_iteminfo", "256" );
00282     }
00283 
00284     strncpy( path, filename, MAX_PATH );
00285     PC_SetBaseFolder(BOTFILESBASEFOLDER);
00286     source = LoadSourceFile( path );
00287     if( !source ) {
00288         botimport.Print( PRT_ERROR, "counldn't load %s\n", path );
00289         return NULL;
00290     } //end if
00291     //initialize item config
00292     ic = (itemconfig_t *) GetClearedHunkMemory(sizeof(itemconfig_t) +
00293                                                         max_iteminfo * sizeof(iteminfo_t));
00294     ic->iteminfo = (iteminfo_t *) ((char *) ic + sizeof(itemconfig_t));
00295     ic->numiteminfo = 0;
00296     //parse the item config file
00297     while(PC_ReadToken(source, &token))
00298     {
00299         if (!strcmp(token.string, "iteminfo"))
00300         {
00301             if (ic->numiteminfo >= max_iteminfo)
00302             {
00303                 SourceError(source, "more than %d item info defined\n", max_iteminfo);
00304                 FreeMemory(ic);
00305                 FreeSource(source);
00306                 return NULL;
00307             } //end if
00308             ii = &ic->iteminfo[ic->numiteminfo];
00309             Com_Memset(ii, 0, sizeof(iteminfo_t));
00310             if (!PC_ExpectTokenType(source, TT_STRING, 0, &token))
00311             {
00312                 FreeMemory(ic);
00313                 FreeMemory(source);
00314                 return NULL;
00315             } //end if
00316             StripDoubleQuotes(token.string);
00317             strncpy(ii->classname, token.string, sizeof(ii->classname)-1);
00318             if (!ReadStructure(source, &iteminfo_struct, (char *) ii))
00319             {
00320                 FreeMemory(ic);
00321                 FreeSource(source);
00322                 return NULL;
00323             } //end if
00324             ii->number = ic->numiteminfo;
00325             ic->numiteminfo++;
00326         } //end if
00327         else
00328         {
00329             SourceError(source, "unknown definition %s\n", token.string);
00330             FreeMemory(ic);
00331             FreeSource(source);
00332             return NULL;
00333         } //end else
00334     } //end while
00335     FreeSource(source);
00336     //
00337     if (!ic->numiteminfo) botimport.Print(PRT_WARNING, "no item info loaded\n");
00338     botimport.Print(PRT_MESSAGE, "loaded %s\n", path);
00339     return ic;
00340 } //end of the function LoadItemConfig

Here is the call graph for this function:

void RemoveLevelItemFromList levelitem_t li  ) 
 

Definition at line 439 of file be_ai_goal.c.

References levelitem_t, levelitems, levelitem_s::next, and levelitem_s::prev.

Referenced by BotUpdateEntityItems().

00440 {
00441     if (li->prev) li->prev->next = li->next;
00442     else levelitems = li->next;
00443     if (li->next) li->next->prev = li->prev;
00444 } //end of the function RemoveLevelItemFromList


Variable Documentation

bot_goalstate_t* botgoalstates[MAX_CLIENTS+1]
 

Definition at line 179 of file be_ai_goal.c.

Referenced by BotAllocGoalState(), BotFreeGoalState(), BotGoalStateFromHandle(), and BotShutdownGoalAI().

campspot_t* campspots = NULL
 

Definition at line 190 of file be_ai_goal.c.

Referenced by BotFreeInfoEntities(), and BotInitInfoEntities().

libvar_t* droppedweight = NULL
 

Definition at line 194 of file be_ai_goal.c.

Referenced by BotChooseLTGItem(), BotChooseNBGItem(), and BotSetupGoalAI().

levelitem_t* freelevelitems = NULL
 

Definition at line 184 of file be_ai_goal.c.

Referenced by AllocLevelItem(), BotShutdownGoalAI(), FreeLevelItem(), and InitLevelItemHeap().

int g_gametype = 0
 

Definition at line 192 of file be_ai_goal.c.

Referenced by AddScore(), ArenaServers_Event(), ArenaServers_MenuInit(), BeginIntermission(), BotChooseLTGItem(), BotChooseNBGItem(), BotDeathmatchAI(), BotGetLevelItemGoal(), BotSetupGoalAI(), BotUpdateEntityItems(), CalculateRanks(), CheckAlmostCapture(), CheckExitRules(), CheckIntermissionExit(), CheckTournament(), ClearRegisteredItems(), ClientBegin(), ClientConnect(), ClientDisconnect(), ClientEvents(), ClientSpawn(), ClientUserinfoChanged(), Cmd_Follow_f(), Cmd_FollowCycle_f(), Cmd_LevelShot_f(), Cmd_Team_f(), Cmd_VoiceTaunt_f(), ExitLevel(), FireWeapon(), G_AddBot(), G_CheckBotSpawn(), G_CheckMinimumPlayers(), G_CheckTeamItems(), G_Damage(), G_InitBots(), G_InitGame(), G_InitSessionData(), G_InitWorldSession(), G_RankRunFrame(), G_RegisterCvars(), G_Say(), G_SayTo(), G_SpawnGEntityFromSpawnVars(), G_Voice(), G_VoiceTo(), G_WriteSessionData(), LaunchItem(), LogExit(), OnSameTeam(), Pickup_Powerup(), Pickup_Team(), Pickup_Weapon(), player_die(), ScoreIsTied(), SetTeam(), Svcmd_AbortPodium_f(), Team_FragBonuses(), Team_InitGame(), Team_ResetFlags(), Team_SetFlagStatus(), Team_TouchEnemyFlag(), Team_TouchOurFlag(), TossClientItems(), Touch_Item(), and UpdateTournamentInfo().

itemconfig_t* itemconfig = NULL
 

Definition at line 181 of file be_ai_goal.c.

Referenced by BotGetLevelItemGoal(), BotGoalName(), BotLoadItemWeights(), BotSetAvoidGoalTime(), BotSetupGoalAI(), and BotShutdownGoalAI().

fielddef_t iteminfo_fields[]
 

Initial value:

{
{"name", ITEMINFO_OFS(name), FT_STRING},
{"model", ITEMINFO_OFS(model), FT_STRING},
{"modelindex", ITEMINFO_OFS(modelindex), FT_INT},
{"type", ITEMINFO_OFS(type), FT_INT},
{"index", ITEMINFO_OFS(index), FT_INT},
{"respawntime", ITEMINFO_OFS(respawntime), FT_FLOAT},
{"mins", ITEMINFO_OFS(mins), FT_FLOAT|FT_ARRAY, 3},
{"maxs", ITEMINFO_OFS(maxs), FT_FLOAT|FT_ARRAY, 3},
{0, 0, 0}
}

Definition at line 139 of file be_ai_goal.c.

structdef_t iteminfo_struct
 

Initial value:

Definition at line 152 of file be_ai_goal.c.

Referenced by LoadItemConfig().

levelitem_t* levelitemheap = NULL
 

Definition at line 183 of file be_ai_goal.c.

Referenced by BotShutdownGoalAI(), and InitLevelItemHeap().

levelitem_t* levelitems = NULL
 

Definition at line 185 of file be_ai_goal.c.

Referenced by AddLevelItemToList(), BotInitLevelItems(), BotShutdownGoalAI(), and RemoveLevelItemFromList().

maplocation_t* maplocations = NULL
 

Definition at line 188 of file be_ai_goal.c.

Referenced by BotFreeInfoEntities(), and BotInitInfoEntities().

int numlevelitems = 0
 

Definition at line 186 of file be_ai_goal.c.

Referenced by BotInitLevelItems(), BotShutdownGoalAI(), and BotUpdateEntityItems().


Generated on Thu Aug 25 12:41:36 2005 for Quake III Arena by  doxygen 1.3.9.1