📄 ai_dmnet.c
字号:
//stop after 3 minutes
if (bs->teamgoal_time < FloatTime()) {
bs->ltgtype = 0;
}
BotAlternateRoute(bs, goal);
return qtrue;
}
}
#endif //CTF
#ifdef MISSIONPACK
else if (gametype == GT_1FCTF) {
if (bs->ltgtype == LTG_GETFLAG) {
//check for bot typing status message
if (bs->teammessage_time && bs->teammessage_time < FloatTime()) {
BotAI_BotInitialChat(bs, "captureflag_start", NULL);
trap_BotEnterChat(bs->cs, 0, CHAT_TEAM);
BotVoiceChatOnly(bs, -1, VOICECHAT_ONGETFLAG);
bs->teammessage_time = 0;
}
memcpy(goal, &ctf_neutralflag, sizeof(bot_goal_t));
//if touching the flag
if (trap_BotTouchingGoal(bs->origin, goal)) {
bs->ltgtype = 0;
}
//stop after 3 minutes
if (bs->teamgoal_time < FloatTime()) {
bs->ltgtype = 0;
}
return qtrue;
}
//if rushing to the base
if (bs->ltgtype == LTG_RUSHBASE) {
switch(BotTeam(bs)) {
case TEAM_RED: memcpy(goal, &ctf_blueflag, sizeof(bot_goal_t)); break;
case TEAM_BLUE: memcpy(goal, &ctf_redflag, sizeof(bot_goal_t)); break;
default: bs->ltgtype = 0; return qfalse;
}
//if not carrying the flag anymore
if (!Bot1FCTFCarryingFlag(bs)) {
bs->ltgtype = 0;
}
//quit rushing after 2 minutes
if (bs->teamgoal_time < FloatTime()) {
bs->ltgtype = 0;
}
//if touching the base flag the bot should loose the enemy flag
if (trap_BotTouchingGoal(bs->origin, goal)) {
bs->ltgtype = 0;
}
BotAlternateRoute(bs, goal);
return qtrue;
}
//attack the enemy base
if (bs->ltgtype == LTG_ATTACKENEMYBASE &&
bs->attackaway_time < FloatTime()) {
//check for bot typing status message
if (bs->teammessage_time && bs->teammessage_time < FloatTime()) {
BotAI_BotInitialChat(bs, "attackenemybase_start", NULL);
trap_BotEnterChat(bs->cs, 0, CHAT_TEAM);
BotVoiceChatOnly(bs, -1, VOICECHAT_ONOFFENSE);
bs->teammessage_time = 0;
}
switch(BotTeam(bs)) {
case TEAM_RED: memcpy(goal, &ctf_blueflag, sizeof(bot_goal_t)); break;
case TEAM_BLUE: memcpy(goal, &ctf_redflag, sizeof(bot_goal_t)); break;
default: bs->ltgtype = 0; return qfalse;
}
//quit rushing after 2 minutes
if (bs->teamgoal_time < FloatTime()) {
bs->ltgtype = 0;
}
//if touching the base flag the bot should loose the enemy flag
if (trap_BotTouchingGoal(bs->origin, goal)) {
bs->attackaway_time = FloatTime() + 2 + 5 * random();
}
return qtrue;
}
//returning flag
if (bs->ltgtype == LTG_RETURNFLAG) {
//check for bot typing status message
if (bs->teammessage_time && bs->teammessage_time < FloatTime()) {
BotAI_BotInitialChat(bs, "returnflag_start", NULL);
trap_BotEnterChat(bs->cs, 0, CHAT_TEAM);
BotVoiceChatOnly(bs, -1, VOICECHAT_ONRETURNFLAG);
bs->teammessage_time = 0;
}
//
if (bs->teamgoal_time < FloatTime()) {
bs->ltgtype = 0;
}
//just roam around
return BotGetItemLongTermGoal(bs, tfl, goal);
}
}
else if (gametype == GT_OBELISK) {
if (bs->ltgtype == LTG_ATTACKENEMYBASE &&
bs->attackaway_time < FloatTime()) {
//check for bot typing status message
if (bs->teammessage_time && bs->teammessage_time < FloatTime()) {
BotAI_BotInitialChat(bs, "attackenemybase_start", NULL);
trap_BotEnterChat(bs->cs, 0, CHAT_TEAM);
BotVoiceChatOnly(bs, -1, VOICECHAT_ONOFFENSE);
bs->teammessage_time = 0;
}
switch(BotTeam(bs)) {
case TEAM_RED: memcpy(goal, &blueobelisk, sizeof(bot_goal_t)); break;
case TEAM_BLUE: memcpy(goal, &redobelisk, sizeof(bot_goal_t)); break;
default: bs->ltgtype = 0; return qfalse;
}
//if the bot no longer wants to attack the obelisk
if (BotFeelingBad(bs) > 50) {
return BotGetItemLongTermGoal(bs, tfl, goal);
}
//if touching the obelisk
if (trap_BotTouchingGoal(bs->origin, goal)) {
bs->attackaway_time = FloatTime() + 3 + 5 * random();
}
// or very close to the obelisk
VectorSubtract(bs->origin, goal->origin, dir);
if (VectorLengthSquared(dir) < Square(60)) {
bs->attackaway_time = FloatTime() + 3 + 5 * random();
}
//quit rushing after 2 minutes
if (bs->teamgoal_time < FloatTime()) {
bs->ltgtype = 0;
}
BotAlternateRoute(bs, goal);
//just move towards the obelisk
return qtrue;
}
}
else if (gametype == GT_HARVESTER) {
//if rushing to the base
if (bs->ltgtype == LTG_RUSHBASE) {
switch(BotTeam(bs)) {
case TEAM_RED: memcpy(goal, &blueobelisk, sizeof(bot_goal_t)); break;
case TEAM_BLUE: memcpy(goal, &redobelisk, sizeof(bot_goal_t)); break;
default: BotGoHarvest(bs); return qfalse;
}
//if not carrying any cubes
if (!BotHarvesterCarryingCubes(bs)) {
BotGoHarvest(bs);
return qfalse;
}
//quit rushing after 2 minutes
if (bs->teamgoal_time < FloatTime()) {
BotGoHarvest(bs);
return qfalse;
}
//if touching the base flag the bot should loose the enemy flag
if (trap_BotTouchingGoal(bs->origin, goal)) {
BotGoHarvest(bs);
return qfalse;
}
BotAlternateRoute(bs, goal);
return qtrue;
}
//attack the enemy base
if (bs->ltgtype == LTG_ATTACKENEMYBASE &&
bs->attackaway_time < FloatTime()) {
//check for bot typing status message
if (bs->teammessage_time && bs->teammessage_time < FloatTime()) {
BotAI_BotInitialChat(bs, "attackenemybase_start", NULL);
trap_BotEnterChat(bs->cs, 0, CHAT_TEAM);
BotVoiceChatOnly(bs, -1, VOICECHAT_ONOFFENSE);
bs->teammessage_time = 0;
}
switch(BotTeam(bs)) {
case TEAM_RED: memcpy(goal, &blueobelisk, sizeof(bot_goal_t)); break;
case TEAM_BLUE: memcpy(goal, &redobelisk, sizeof(bot_goal_t)); break;
default: bs->ltgtype = 0; return qfalse;
}
//quit rushing after 2 minutes
if (bs->teamgoal_time < FloatTime()) {
bs->ltgtype = 0;
}
//if touching the base flag the bot should loose the enemy flag
if (trap_BotTouchingGoal(bs->origin, goal)) {
bs->attackaway_time = FloatTime() + 2 + 5 * random();
}
return qtrue;
}
//harvest cubes
if (bs->ltgtype == LTG_HARVEST &&
bs->harvestaway_time < FloatTime()) {
//check for bot typing status message
if (bs->teammessage_time && bs->teammessage_time < FloatTime()) {
BotAI_BotInitialChat(bs, "harvest_start", NULL);
trap_BotEnterChat(bs->cs, 0, CHAT_TEAM);
BotVoiceChatOnly(bs, -1, VOICECHAT_ONOFFENSE);
bs->teammessage_time = 0;
}
memcpy(goal, &neutralobelisk, sizeof(bot_goal_t));
//
if (bs->teamgoal_time < FloatTime()) {
bs->ltgtype = 0;
}
//
if (trap_BotTouchingGoal(bs->origin, goal)) {
bs->harvestaway_time = FloatTime() + 4 + 3 * random();
}
return qtrue;
}
}
#endif
//normal goal stuff
return BotGetItemLongTermGoal(bs, tfl, goal);
}
/*
==================
BotLongTermGoal
==================
*/
int BotLongTermGoal(bot_state_t *bs, int tfl, int retreat, bot_goal_t *goal) {
aas_entityinfo_t entinfo;
char teammate[MAX_MESSAGE_SIZE];
float squaredist;
int areanum;
vec3_t dir;
//FIXME: also have air long term goals?
//
//if the bot is leading someone and not retreating
if (bs->lead_time > 0 && !retreat) {
if (bs->lead_time < FloatTime()) {
BotAI_BotInitialChat(bs, "lead_stop", EasyClientName(bs->lead_teammate, teammate, sizeof(teammate)), NULL);
trap_BotEnterChat(bs->cs, bs->teammate, CHAT_TELL);
bs->lead_time = 0;
return BotGetLongTermGoal(bs, tfl, retreat, goal);
}
//
if (bs->leadmessage_time < 0 && -bs->leadmessage_time < FloatTime()) {
BotAI_BotInitialChat(bs, "followme", EasyClientName(bs->lead_teammate, teammate, sizeof(teammate)), NULL);
trap_BotEnterChat(bs->cs, bs->teammate, CHAT_TELL);
bs->leadmessage_time = FloatTime();
}
//get entity information of the companion
BotEntityInfo(bs->lead_teammate, &entinfo);
//
if (entinfo.valid) {
areanum = BotPointAreaNum(entinfo.origin);
if (areanum && trap_AAS_AreaReachability(areanum)) {
//update team goal
bs->lead_teamgoal.entitynum = bs->lead_teammate;
bs->lead_teamgoal.areanum = areanum;
VectorCopy(entinfo.origin, bs->lead_teamgoal.origin);
VectorSet(bs->lead_teamgoal.mins, -8, -8, -8);
VectorSet(bs->lead_teamgoal.maxs, 8, 8, 8);
}
}
//if the team mate is visible
if (BotEntityVisible(bs->entitynum, bs->eye, bs->viewangles, 360, bs->lead_teammate)) {
bs->leadvisible_time = FloatTime();
}
//if the team mate is not visible for 1 seconds
if (bs->leadvisible_time < FloatTime() - 1) {
bs->leadbackup_time = FloatTime() + 2;
}
//distance towards the team mate
VectorSubtract(bs->origin, bs->lead_teamgoal.origin, dir);
squaredist = VectorLengthSquared(dir);
//if backing up towards the team mate
if (bs->leadbackup_time > FloatTime()) {
if (bs->leadmessage_time < FloatTime() - 20) {
BotAI_BotInitialChat(bs, "followme", EasyClientName(bs->lead_teammate, teammate, sizeof(teammate)), NULL);
trap_BotEnterChat(bs->cs, bs->teammate, CHAT_TELL);
bs->leadmessage_time = FloatTime();
}
//if very close to the team mate
if (squaredist < Square(100)) {
bs->leadbackup_time = 0;
}
//the bot should go back to the team mate
memcpy(goal, &bs->lead_teamgoal, sizeof(bot_goal_t));
return qtrue;
}
else {
//if quite distant from the team mate
if (squaredist > Square(500)) {
if (bs->leadmessage_time < FloatTime() - 20) {
BotAI_BotInitialChat(bs, "followme", EasyClientName(bs->lead_teammate, teammate, sizeof(teammate)), NULL);
trap_BotEnterChat(bs->cs, bs->teammate, CHAT_TELL);
bs->leadmessage_time = FloatTime();
}
//look at the team mate
VectorSubtract(entinfo.origin, bs->origin, dir);
vectoangles(dir, bs->ideal_viewangles);
bs->ideal_viewangles[2] *= 0.5;
//just wait for the team mate
return qfalse;
}
}
}
return BotGetLongTermGoal(bs, tfl, retreat, goal);
}
/*
==================
AIEnter_Intermission
==================
*/
void AIEnter_Intermission(bot_state_t *bs, char *s) {
BotRecordNodeSwitch(bs, "intermission", "", s);
//reset the bot state
BotResetState(bs);
//check for end level chat
if (BotChat_EndLevel(bs)) {
trap_BotEnterChat(bs->cs, 0, bs->chatto);
}
bs->ainode = AINode_Intermission;
}
/*
==================
AINode_Intermission
==================
*/
int AINode_Intermission(bot_state_t *bs) {
//if the intermission ended
if (!BotIntermission(bs)) {
if (BotChat_StartLevel(bs)) {
bs->stand_time = FloatTime() + BotChatTime(bs);
}
else {
bs->stand_time = FloatTime() + 2;
}
AIEnter_Stand(bs, "intermission: chat");
}
return qtrue;
}
/*
==================
AIEnter_Observer
==================
*/
void AIEnter_Observer(bot_state_t *bs, char *s) {
BotRecordNodeSwitch(bs, "observer", "", s);
//reset the bot state
BotResetState(bs);
bs->ainode = AINode_Observer;
}
/*
==================
AINode_Observer
==================
*/
int AINode_Observer(bot_state_t *bs) {
//if the bot left observer mode
if (!BotIsObserver(bs)) {
AIEnter_Stand(bs, "observer: left observer");
}
return qtrue;
}
/*
==================
AIEnter_Stand
==================
*/
void AIEnter_Stand(bot_state_t *bs, char *s) {
BotRecordNodeSwitch(bs, "stand", "", s);
bs->standfindenemy_time = FloatTime() + 1;
bs->ainode = AINode_Stand;
}
/*
==================
AINode_Stand
==================
*/
int AINode_Stand(bot_state_t *bs) {
//if the bot's health decreased
if (bs->lastframe_health > bs->inventory[INVENTORY_HEALTH]) {
if (BotChat_HitTalking(bs)) {
bs->standfindenemy_time = FloatTime() + BotChatTime(bs) + 0.1;
bs->stand_time = FloatTime() + BotChatTime(bs) + 0.1;
}
}
if (bs->standfindenemy_time < FloatTime()) {
if (BotFindEnemy(bs, -1)) {
AIEnter_Battle_Fight(bs, "stand: found enemy");
return qfalse;
}
bs->standfindenemy_time = FloatTime() + 1;
}
// put up chat icon
trap_EA_Talk(bs->client);
// when done standing
if (bs->stand_time < FloatTime()) {
trap_BotEnterChat(bs->cs, 0, bs->chatto);
AIEnter_Seek_LTG(bs, "stand: time out");
return qfalse;
}
//
return qtrue;
}
/*
==================
AIEnter_Respawn
==================
*/
void AIEnter_Respawn(bot_state_t *bs, char *s) {
BotRecordNodeSwitch(bs, "respawn", "", s);
//reset some states
trap_BotResetMoveState(bs->ms);
trap_BotResetGoalState(bs->gs);
trap_BotResetAvoidGoals(bs->gs);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -