📄 be_ai_goal.c
字号:
{
nextml = ml->next;
FreeMemory(ml);
} //end for
maplocations = NULL;
for (cs = campspots; cs; cs = nextcs)
{
nextcs = cs->next;
FreeMemory(cs);
} //end for
campspots = NULL;
} //end of the function BotFreeInfoEntities
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void BotInitInfoEntities(void)
{
char classname[MAX_EPAIRKEY];
maplocation_t *ml;
campspot_t *cs;
int ent, numlocations, numcampspots;
BotFreeInfoEntities();
//
numlocations = 0;
numcampspots = 0;
for (ent = AAS_NextBSPEntity(0); ent; ent = AAS_NextBSPEntity(ent))
{
if (!AAS_ValueForBSPEpairKey(ent, "classname", classname, MAX_EPAIRKEY)) continue;
//map locations
if (!strcmp(classname, "target_location"))
{
ml = (maplocation_t *) GetClearedMemory(sizeof(maplocation_t));
AAS_VectorForBSPEpairKey(ent, "origin", ml->origin);
AAS_ValueForBSPEpairKey(ent, "message", ml->name, sizeof(ml->name));
ml->areanum = AAS_PointAreaNum(ml->origin);
ml->next = maplocations;
maplocations = ml;
numlocations++;
} //end if
//camp spots
else if (!strcmp(classname, "info_camp"))
{
cs = (campspot_t *) GetClearedMemory(sizeof(campspot_t));
AAS_VectorForBSPEpairKey(ent, "origin", cs->origin);
//cs->origin[2] += 16;
AAS_ValueForBSPEpairKey(ent, "message", cs->name, sizeof(cs->name));
AAS_FloatForBSPEpairKey(ent, "range", &cs->range);
AAS_FloatForBSPEpairKey(ent, "weight", &cs->weight);
AAS_FloatForBSPEpairKey(ent, "wait", &cs->wait);
AAS_FloatForBSPEpairKey(ent, "random", &cs->random);
cs->areanum = AAS_PointAreaNum(cs->origin);
if (!cs->areanum)
{
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]);
FreeMemory(cs);
continue;
} //end if
cs->next = campspots;
campspots = cs;
//AAS_DrawPermanentCross(cs->origin, 4, LINECOLOR_YELLOW);
numcampspots++;
} //end else if
} //end for
if (bot_developer)
{
botimport.Print(PRT_MESSAGE, "%d map locations\n", numlocations);
botimport.Print(PRT_MESSAGE, "%d camp spots\n", numcampspots);
} //end if
} //end of the function BotInitInfoEntities
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void BotInitLevelItems(void)
{
int i, spawnflags, value;
char classname[MAX_EPAIRKEY];
vec3_t origin, end;
int ent, goalareanum;
itemconfig_t *ic;
levelitem_t *li;
bsp_trace_t trace;
//initialize the map locations and camp spots
BotInitInfoEntities();
//initialize the level item heap
InitLevelItemHeap();
levelitems = NULL;
numlevelitems = 0;
//
ic = itemconfig;
if (!ic) return;
//if there's no AAS file loaded
if (!AAS_Loaded()) return;
//update the modelindexes of the item info
for (i = 0; i < ic->numiteminfo; i++)
{
//ic->iteminfo[i].modelindex = AAS_IndexFromModel(ic->iteminfo[i].model);
if (!ic->iteminfo[i].modelindex)
{
Log_Write("item %s has modelindex 0", ic->iteminfo[i].classname);
} //end if
} //end for
for (ent = AAS_NextBSPEntity(0); ent; ent = AAS_NextBSPEntity(ent))
{
if (!AAS_ValueForBSPEpairKey(ent, "classname", classname, MAX_EPAIRKEY)) continue;
//
spawnflags = 0;
AAS_IntForBSPEpairKey(ent, "spawnflags", &spawnflags);
//
for (i = 0; i < ic->numiteminfo; i++)
{
if (!strcmp(classname, ic->iteminfo[i].classname)) break;
} //end for
if (i >= ic->numiteminfo)
{
Log_Write("entity %s unknown item\r\n", classname);
continue;
} //end if
//get the origin of the item
if (!AAS_VectorForBSPEpairKey(ent, "origin", origin))
{
botimport.Print(PRT_ERROR, "item %s without origin\n", classname);
continue;
} //end else
//
goalareanum = 0;
//if it is a floating item
if (spawnflags & 1)
{
//if the item is not floating in water
if (!(AAS_PointContents(origin) & CONTENTS_WATER))
{
VectorCopy(origin, end);
end[2] -= 32;
trace = AAS_Trace(origin, ic->iteminfo[i].mins, ic->iteminfo[i].maxs, end, -1, CONTENTS_SOLID|CONTENTS_PLAYERCLIP);
//if the item not near the ground
if (trace.fraction >= 1)
{
//if the item is not reachable from a jumppad
goalareanum = AAS_BestReachableFromJumpPadArea(origin, ic->iteminfo[i].mins, ic->iteminfo[i].maxs);
Log_Write("item %s reachable from jumppad area %d\r\n", ic->iteminfo[i].classname, goalareanum);
//botimport.Print(PRT_MESSAGE, "item %s reachable from jumppad area %d\r\n", ic->iteminfo[i].classname, goalareanum);
if (!goalareanum) continue;
} //end if
} //end if
} //end if
li = AllocLevelItem();
if (!li) return;
//
li->number = ++numlevelitems;
li->timeout = 0;
li->entitynum = 0;
//
li->flags = 0;
AAS_IntForBSPEpairKey(ent, "notfree", &value);
if (value) li->flags |= IFL_NOTFREE;
AAS_IntForBSPEpairKey(ent, "notteam", &value);
if (value) li->flags |= IFL_NOTTEAM;
AAS_IntForBSPEpairKey(ent, "notsingle", &value);
if (value) li->flags |= IFL_NOTSINGLE;
AAS_IntForBSPEpairKey(ent, "notbot", &value);
if (value) li->flags |= IFL_NOTBOT;
if (!strcmp(classname, "item_botroam"))
{
li->flags |= IFL_ROAM;
AAS_FloatForBSPEpairKey(ent, "weight", &li->weight);
} //end if
//if not a stationary item
if (!(spawnflags & 1))
{
if (!AAS_DropToFloor(origin, ic->iteminfo[i].mins, ic->iteminfo[i].maxs))
{
botimport.Print(PRT_MESSAGE, "%s in solid at (%1.1f %1.1f %1.1f)\n",
classname, origin[0], origin[1], origin[2]);
} //end if
} //end if
//item info of the level item
li->iteminfo = i;
//origin of the item
VectorCopy(origin, li->origin);
//
if (goalareanum)
{
li->goalareanum = goalareanum;
VectorCopy(origin, li->goalorigin);
} //end if
else
{
//get the item goal area and goal origin
li->goalareanum = AAS_BestReachableArea(origin,
ic->iteminfo[i].mins, ic->iteminfo[i].maxs,
li->goalorigin);
if (!li->goalareanum)
{
botimport.Print(PRT_MESSAGE, "%s not reachable for bots at (%1.1f %1.1f %1.1f)\n",
classname, origin[0], origin[1], origin[2]);
} //end if
} //end else
//
AddLevelItemToList(li);
} //end for
botimport.Print(PRT_MESSAGE, "found %d level items\n", numlevelitems);
} //end of the function BotInitLevelItems
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void BotGoalName(int number, char *name, int size)
{
levelitem_t *li;
if (!itemconfig) return;
//
for (li = levelitems; li; li = li->next)
{
if (li->number == number)
{
strncpy(name, itemconfig->iteminfo[li->iteminfo].name, size-1);
name[size-1] = '\0';
return;
} //end for
} //end for
strcpy(name, "");
return;
} //end of the function BotGoalName
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void BotResetAvoidGoals(int goalstate)
{
bot_goalstate_t *gs;
gs = BotGoalStateFromHandle(goalstate);
if (!gs) return;
Com_Memset(gs->avoidgoals, 0, MAX_AVOIDGOALS * sizeof(int));
Com_Memset(gs->avoidgoaltimes, 0, MAX_AVOIDGOALS * sizeof(float));
} //end of the function BotResetAvoidGoals
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void BotDumpAvoidGoals(int goalstate)
{
int i;
bot_goalstate_t *gs;
char name[32];
gs = BotGoalStateFromHandle(goalstate);
if (!gs) return;
for (i = 0; i < MAX_AVOIDGOALS; i++)
{
if (gs->avoidgoaltimes[i] >= AAS_Time())
{
BotGoalName(gs->avoidgoals[i], name, 32);
Log_Write("avoid goal %s, number %d for %f seconds", name,
gs->avoidgoals[i], gs->avoidgoaltimes[i] - AAS_Time());
} //end if
} //end for
} //end of the function BotDumpAvoidGoals
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void BotAddToAvoidGoals(bot_goalstate_t *gs, int number, float avoidtime)
{
int i;
for (i = 0; i < MAX_AVOIDGOALS; i++)
{
//if the avoid goal is already stored
if (gs->avoidgoals[i] == number)
{
gs->avoidgoals[i] = number;
gs->avoidgoaltimes[i] = AAS_Time() + avoidtime;
return;
} //end if
} //end for
for (i = 0; i < MAX_AVOIDGOALS; i++)
{
//if this avoid goal has expired
if (gs->avoidgoaltimes[i] < AAS_Time())
{
gs->avoidgoals[i] = number;
gs->avoidgoaltimes[i] = AAS_Time() + avoidtime;
return;
} //end if
} //end for
} //end of the function BotAddToAvoidGoals
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void BotRemoveFromAvoidGoals(int goalstate, int number)
{
int i;
bot_goalstate_t *gs;
gs = BotGoalStateFromHandle(goalstate);
if (!gs) return;
//don't use the goals the bot wants to avoid
for (i = 0; i < MAX_AVOIDGOALS; i++)
{
if (gs->avoidgoals[i] == number && gs->avoidgoaltimes[i] >= AAS_Time())
{
gs->avoidgoaltimes[i] = 0;
return;
} //end if
} //end for
} //end of the function BotRemoveFromAvoidGoals
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
float BotAvoidGoalTime(int goalstate, int number)
{
int i;
bot_goalstate_t *gs;
gs = BotGoalStateFromHandle(goalstate);
if (!gs) return 0;
//don't use the goals the bot wants to avoid
for (i = 0; i < MAX_AVOIDGOALS; i++)
{
if (gs->avoidgoals[i] == number && gs->avoidgoaltimes[i] >= AAS_Time())
{
return gs->avoidgoaltimes[i] - AAS_Time();
} //end if
} //end for
return 0;
} //end of the function BotAvoidGoalTime
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void BotSetAvoidGoalTime(int goalstate, int number, float avoidtime)
{
bot_goalstate_t *gs;
levelitem_t *li;
gs = BotGoalStateFromHandle(goalstate);
if (!gs)
return;
if (avoidtime < 0)
{
if (!itemconfig)
return;
//
for (li = levelitems; li; li = li->next)
{
if (li->number == number)
{
avoidtime = itemconfig->iteminfo[li->iteminfo].respawntime;
if (!avoidtime)
avoidtime = AVOID_DEFAULT_TIME;
if (avoidtime < AVOID_MINIMUM_TIME)
avoidtime = AVOID_MINIMUM_TIME;
BotAddToAvoidGoals(gs, number, avoidtime);
return;
} //end for
} //end for
return;
} //end if
else
{
BotAddToAvoidGoals(gs, number, avoidtime);
} //end else
} //end of the function BotSetAvoidGoalTime
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int BotGetLevelItemGoal(int index, char *name, bot_goal_t *goal)
{
levelitem_t *li;
if (!itemconfig) return -1;
li = levelitems;
if (index >= 0)
{
for (; li; li = li->next)
{
if (li->number == index)
{
li = li->next;
break;
} //end if
} //end for
} //end for
for (; li; li = li->next)
{
//
if (g_gametype == GT_SINGLE_PLAYER) {
if (li->flags & IFL_NOTSINGLE) continue;
}
else if (g_gametype >= GT_TEAM) {
if (li->flags & IFL_NOTTEAM) continue;
}
else {
if (li->flags & IFL_NOTFREE) continue;
}
if (li->flags & IFL_NOTBOT) continue;
//
if (!Q_stricmp(name, itemconfig->iteminfo[li->iteminfo].name))
{
goal->areanum = li->goalareanum;
VectorCopy(li->goalorigin, goal->origin);
goal->entitynum = li->entitynum;
VectorCopy(itemconfig->iteminfo[li->iteminfo].mins, goal->mins);
VectorCopy(itemconfig->iteminfo[li->iteminfo].maxs, goal->maxs);
goal->number = li->number;
goal->flags = GFL_ITEM;
if (li->timeout) goal->flags |= GFL_DROPPED;
//botimport.Print(PRT_MESSAGE, "found li %s\n", itemconfig->iteminfo[li->iteminfo].name);
return li->number;
} //end if
} //end for
return -1;
} //end of the function BotGetLevelItemGoal
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int BotGetMapLocationGoal(char *name, bot_goal_t *goal)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -