📄 ai_team.c
字号:
BotSayTeamOrder(bs, teammates[1]);
BotSayVoiceTeamOrder(bs, teammates[1], VOICECHAT_GETFLAG);
//
ClientName(teammates[2], name, sizeof(name));
BotAI_BotInitialChat(bs, "cmd_getflag", name, NULL);
BotSayTeamOrder(bs, teammates[2]);
BotSayVoiceTeamOrder(bs, teammates[2], VOICECHAT_GETFLAG);
break;
}
default:
{
defenders = (int) (float) numteammates * 0.4 + 0.5;
if (defenders > 4) defenders = 4;
attackers = (int) (float) numteammates * 0.5 + 0.5;
if (attackers > 5) attackers = 5;
for (i = 0; i < defenders; i++) {
//
ClientName(teammates[i], name, sizeof(name));
BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
BotSayTeamOrder(bs, teammates[i]);
BotSayVoiceTeamOrder(bs, teammates[i], VOICECHAT_DEFEND);
}
for (i = 0; i < attackers; i++) {
//
ClientName(teammates[numteammates - i - 1], name, sizeof(name));
BotAI_BotInitialChat(bs, "cmd_getflag", name, NULL);
BotSayTeamOrder(bs, teammates[numteammates - i - 1]);
BotSayVoiceTeamOrder(bs, teammates[numteammates - i - 1], VOICECHAT_GETFLAG);
}
//
break;
}
}
}
}
/*
==================
BotCTFOrders
==================
*/
void BotCTFOrders(bot_state_t *bs) {
int flagstatus;
//
if (BotTeam(bs) == TEAM_RED) flagstatus = bs->redflagstatus * 2 + bs->blueflagstatus;
else flagstatus = bs->blueflagstatus * 2 + bs->redflagstatus;
//
switch(flagstatus) {
case 0: BotCTFOrders_BothFlagsAtBase(bs); break;
case 1: BotCTFOrders_EnemyFlagNotAtBase(bs); break;
case 2: BotCTFOrders_FlagNotAtBase(bs); break;
case 3: BotCTFOrders_BothFlagsNotAtBase(bs); break;
}
}
/*
==================
BotCreateGroup
==================
*/
void BotCreateGroup(bot_state_t *bs, int *teammates, int groupsize) {
char name[MAX_NETNAME], leadername[MAX_NETNAME];
int i;
// the others in the group will follow the teammates[0]
ClientName(teammates[0], leadername, sizeof(leadername));
for (i = 1; i < groupsize; i++)
{
ClientName(teammates[i], name, sizeof(name));
if (teammates[0] == bs->client) {
BotAI_BotInitialChat(bs, "cmd_accompanyme", name, NULL);
}
else {
BotAI_BotInitialChat(bs, "cmd_accompany", name, leadername, NULL);
}
BotSayTeamOrderAlways(bs, teammates[i]);
}
}
/*
==================
BotTeamOrders
FIXME: defend key areas?
==================
*/
void BotTeamOrders(bot_state_t *bs) {
int teammates[MAX_CLIENTS];
int numteammates, i;
char buf[MAX_INFO_STRING];
static int maxclients;
if (!maxclients)
maxclients = trap_Cvar_VariableIntegerValue("sv_maxclients");
numteammates = 0;
for (i = 0; i < maxclients && i < MAX_CLIENTS; i++) {
trap_GetConfigstring(CS_PLAYERS+i, buf, sizeof(buf));
//if no config string or no name
if (!strlen(buf) || !strlen(Info_ValueForKey(buf, "n"))) continue;
//skip spectators
if (atoi(Info_ValueForKey(buf, "t")) == TEAM_SPECTATOR) continue;
//
if (BotSameTeam(bs, i)) {
teammates[numteammates] = i;
numteammates++;
}
}
//
switch(numteammates) {
case 1: break;
case 2:
{
//nothing special
break;
}
case 3:
{
//have one follow another and one free roaming
BotCreateGroup(bs, teammates, 2);
break;
}
case 4:
{
BotCreateGroup(bs, teammates, 2); //a group of 2
BotCreateGroup(bs, &teammates[2], 2); //a group of 2
break;
}
case 5:
{
BotCreateGroup(bs, teammates, 2); //a group of 2
BotCreateGroup(bs, &teammates[2], 3); //a group of 3
break;
}
default:
{
if (numteammates <= 10) {
for (i = 0; i < numteammates / 2; i++) {
BotCreateGroup(bs, &teammates[i*2], 2); //groups of 2
}
}
break;
}
}
}
#ifdef MISSIONPACK
/*
==================
Bot1FCTFOrders_FlagAtCenter
X% defend the base, Y% get the flag
==================
*/
void Bot1FCTFOrders_FlagAtCenter(bot_state_t *bs) {
int numteammates, defenders, attackers, i;
int teammates[MAX_CLIENTS];
char name[MAX_NETNAME];
//sort team mates by travel time to base
numteammates = BotSortTeamMatesByBaseTravelTime(bs, teammates, sizeof(teammates));
//sort team mates by CTF preference
BotSortTeamMatesByTaskPreference(bs, teammates, numteammates);
//passive strategy
if (!(bs->ctfstrategy & CTFS_AGRESSIVE)) {
//different orders based on the number of team mates
switch(numteammates) {
case 1: break;
case 2:
{
//the one closest to the base will defend the base
ClientName(teammates[0], name, sizeof(name));
BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
BotSayTeamOrder(bs, teammates[0]);
BotSayVoiceTeamOrder(bs, teammates[0], VOICECHAT_DEFEND);
//the other will get the flag
ClientName(teammates[1], name, sizeof(name));
BotAI_BotInitialChat(bs, "cmd_getflag", name, NULL);
BotSayTeamOrder(bs, teammates[1]);
BotSayVoiceTeamOrder(bs, teammates[1], VOICECHAT_GETFLAG);
break;
}
case 3:
{
//the one closest to the base will defend the base
ClientName(teammates[0], name, sizeof(name));
BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
BotSayTeamOrder(bs, teammates[0]);
BotSayVoiceTeamOrder(bs, teammates[0], VOICECHAT_DEFEND);
//the second one closest to the base will defend the base
ClientName(teammates[1], name, sizeof(name));
BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
BotSayTeamOrder(bs, teammates[1]);
BotSayVoiceTeamOrder(bs, teammates[0], VOICECHAT_DEFEND);
//the other will get the flag
ClientName(teammates[2], name, sizeof(name));
BotAI_BotInitialChat(bs, "cmd_getflag", name, NULL);
BotSayTeamOrder(bs, teammates[2]);
BotSayVoiceTeamOrder(bs, teammates[2], VOICECHAT_GETFLAG);
break;
}
default:
{
//50% defend the base
defenders = (int) (float) numteammates * 0.5 + 0.5;
if (defenders > 5) defenders = 5;
//40% get the flag
attackers = (int) (float) numteammates * 0.4 + 0.5;
if (attackers > 4) attackers = 4;
for (i = 0; i < defenders; i++) {
//
ClientName(teammates[i], name, sizeof(name));
BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
BotSayTeamOrder(bs, teammates[i]);
BotSayVoiceTeamOrder(bs, teammates[i], VOICECHAT_DEFEND);
}
for (i = 0; i < attackers; i++) {
//
ClientName(teammates[numteammates - i - 1], name, sizeof(name));
BotAI_BotInitialChat(bs, "cmd_getflag", name, NULL);
BotSayTeamOrder(bs, teammates[numteammates - i - 1]);
BotSayVoiceTeamOrder(bs, teammates[numteammates - i - 1], VOICECHAT_GETFLAG);
}
//
break;
}
}
}
else { //agressive
//different orders based on the number of team mates
switch(numteammates) {
case 1: break;
case 2:
{
//the one closest to the base will defend the base
ClientName(teammates[0], name, sizeof(name));
BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
BotSayTeamOrder(bs, teammates[0]);
BotSayVoiceTeamOrder(bs, teammates[0], VOICECHAT_DEFEND);
//the other will get the flag
ClientName(teammates[1], name, sizeof(name));
BotAI_BotInitialChat(bs, "cmd_getflag", name, NULL);
BotSayTeamOrder(bs, teammates[1]);
BotSayVoiceTeamOrder(bs, teammates[1], VOICECHAT_GETFLAG);
break;
}
case 3:
{
//the one closest to the base will defend the base
ClientName(teammates[0], name, sizeof(name));
BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
BotSayTeamOrder(bs, teammates[0]);
BotSayVoiceTeamOrder(bs, teammates[0], VOICECHAT_DEFEND);
//the others should go for the enemy flag
ClientName(teammates[1], name, sizeof(name));
BotAI_BotInitialChat(bs, "cmd_getflag", name, NULL);
BotSayTeamOrder(bs, teammates[1]);
BotSayVoiceTeamOrder(bs, teammates[1], VOICECHAT_GETFLAG);
//
ClientName(teammates[2], name, sizeof(name));
BotAI_BotInitialChat(bs, "cmd_getflag", name, NULL);
BotSayTeamOrder(bs, teammates[2]);
BotSayVoiceTeamOrder(bs, teammates[2], VOICECHAT_GETFLAG);
break;
}
default:
{
//30% defend the base
defenders = (int) (float) numteammates * 0.3 + 0.5;
if (defenders > 3) defenders = 3;
//60% get the flag
attackers = (int) (float) numteammates * 0.6 + 0.5;
if (attackers > 6) attackers = 6;
for (i = 0; i < defenders; i++) {
//
ClientName(teammates[i], name, sizeof(name));
BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
BotSayTeamOrder(bs, teammates[i]);
BotSayVoiceTeamOrder(bs, teammates[i], VOICECHAT_DEFEND);
}
for (i = 0; i < attackers; i++) {
//
ClientName(teammates[numteammates - i - 1], name, sizeof(name));
BotAI_BotInitialChat(bs, "cmd_getflag", name, NULL);
BotSayTeamOrder(bs, teammates[numteammates - i - 1]);
BotSayVoiceTeamOrder(bs, teammates[numteammates - i - 1], VOICECHAT_GETFLAG);
}
//
break;
}
}
}
}
/*
==================
Bot1FCTFOrders_TeamHasFlag
X% towards neutral flag, Y% go towards enemy base and accompany flag carrier if visible
==================
*/
void Bot1FCTFOrders_TeamHasFlag(bot_state_t *bs) {
int numteammates, defenders, attackers, i, other;
int teammates[MAX_CLIENTS];
char name[MAX_NETNAME], carriername[MAX_NETNAME];
//sort team mates by travel time to base
numteammates = BotSortTeamMatesByBaseTravelTime(bs, teammates, sizeof(teammates));
//sort team mates by CTF preference
BotSortTeamMatesByTaskPreference(bs, teammates, numteammates);
//passive strategy
if (!(bs->ctfstrategy & CTFS_AGRESSIVE)) {
//different orders based on the number of team mates
switch(numteammates) {
case 1: break;
case 2:
{
//tell the one not carrying the flag to attack the enemy base
if (teammates[0] == bs->flagcarrier) other = teammates[1];
else other = teammates[0];
ClientName(other, name, sizeof(name));
BotAI_BotInitialChat(bs, "cmd_attackenemybase", name, NULL);
BotSayTeamOrder(bs, other);
BotSayVoiceTeamOrder(bs, other, VOICECHAT_OFFENSE);
break;
}
case 3:
{
//tell the one closest to the base not carrying the flag to defend the base
if (teammates[0] != bs->flagcarrier) other = teammates[0];
else other = teammates[1];
ClientName(other, name, sizeof(name));
BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
BotSayTeamOrder(bs, other);
BotSayVoiceTeamOrder(bs, other, VOICECHAT_DEFEND);
//tell the one furthest from the base not carrying the flag to accompany the flag carrier
if (teammates[2] != bs->flagcarrier) other = teammates[2];
else other = teammates[1];
ClientName(other, name, sizeof(name));
if ( bs->flagcarrier != -1 ) {
ClientName(bs->flagcarrier, carriername, sizeof(carriername));
if (bs->flagcarrier == bs->client) {
BotAI_BotInitialChat(bs, "cmd_accompanyme", name, NULL);
BotSayVoiceTeamOrder(bs, other, VOICECHAT_FOLLOWME);
}
else {
BotAI_BotInitialChat(bs, "cmd_accompany", name, carriername, NULL);
BotSayVoiceTeamOrder(bs, other, VOICECHAT_FOLLOWFLAGCARRIER);
}
}
else {
//
BotAI_BotInitialChat(bs, "cmd_getflag", name, NULL);
BotSayVoiceTeamOrder(bs, other, VOICECHAT_GETFLAG);
}
BotSayTeamOrder(bs, other);
break;
}
default:
{
//30% will defend the base
defenders = (int) (float) numteammates * 0.3 + 0.5;
if (defenders > 3) defenders = 3;
//70% accompanies the flag carrier
attackers = (int) (float) numteammates * 0.7 + 0.5;
if (attackers > 7) attackers = 7;
for (i = 0; i < defenders; i++) {
//
if (teammates[i] == bs->flagcarrier) {
continue;
}
ClientName(teammates[i], name, sizeof(name));
BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
BotSayTeamOrder(bs, teammates[i]);
BotSayVoiceTeamOrder(bs, teammates[i], VOICECHAT_DEFEND);
}
if (bs->flagcarrier != -1) {
ClientName(bs->flagcarrier, carriername, sizeof(carriername));
for (i = 0; i < attackers; i++) {
//
if (teammates[numteammates - i - 1] == bs->flagcarrier) {
continue;
}
//
ClientName(teammates[numteammates - i - 1], name, sizeof(name));
if (bs->flagcarrier == bs->client) {
BotAI_BotInitialChat(bs, "cmd_accompanyme", name, NULL);
BotSayVoiceTeamOrder(bs, teammates[numteammates - i - 1], VOICECHAT_FOLLOWME);
}
else {
BotAI_BotInitialChat(bs, "cmd_accompany", name, carriername, NULL);
BotSayVoiceTeamOrder(bs, teammates[numteammates - i - 1], VOICECHAT_FOLLOWFLAGCARRIER);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -