Ejemplo n.º 1
0
/*
==================
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;
    }
}
Ejemplo n.º 2
0
/*
==================
BotTeamAI
==================
*/
void BotTeamAI(bot_state_t *bs) {
    int numteammates, flagstatus;
    char netname[MAX_NETNAME];

    if(!bs) return;

    //
    if (gametype != GT_TEAM && gametype != GT_CTF) return;
    //make sure we've got a valid team leader
    if (!BotValidTeamLeader(bs)) {
        //
        if (!bs->askteamleader_time && !bs->becometeamleader_time) {
            if (bs->entergame_time + 10 > trap_AAS_Time()) {
                bs->askteamleader_time = trap_AAS_Time() + 5 + random() * 10;
            }
            else {
                bs->becometeamleader_time = trap_AAS_Time() + 5 + random() * 10;
            }
        }
        if (bs->askteamleader_time && bs->askteamleader_time < trap_AAS_Time()) {
            //if asked for a team leader and no repsonse
            BotAI_BotInitialChat(bs, "whoisteamleader", NULL);
            trap_BotEnterChat(bs->cs, bs->client, CHAT_TEAM);
            bs->askteamleader_time = 0;
            bs->becometeamleader_time = trap_AAS_Time() + 15 + random() * 10;
        }
        if (bs->becometeamleader_time && bs->becometeamleader_time < trap_AAS_Time()) {
            BotAI_BotInitialChat(bs, "iamteamleader", NULL);
            trap_BotEnterChat(bs->cs, bs->client, CHAT_TEAM);
            ClientName(bs->client, netname, sizeof(netname));
            strncpy(bs->teamleader, netname, sizeof(bs->teamleader));
            bs->teamleader[sizeof(bs->teamleader)-1] = '\0';
            bs->becometeamleader_time = 0;
        }
        return;
    }
    bs->askteamleader_time = 0;
    bs->becometeamleader_time = 0;

    //return if this bot is NOT the team leader
    ClientName(bs->client, netname, sizeof(netname));
    if (Q_stricmp(netname, bs->teamleader) != 0) return;
    //
    //if the game starts OR a new player comes onto the team OR a player leaves the team
    //
    numteammates = BotNumTeamMates(bs);
    //give orders
    switch(gametype) {
    case GT_TEAM:
    {
        if (bs->numteammates != numteammates || bs->forceorders) {
            bs->teamgiveorders_time = trap_AAS_Time();
            bs->numteammates = numteammates;
            bs->forceorders = qfalse;
        }
        //if it's time to give orders
        if (bs->teamgiveorders_time < trap_AAS_Time() - 5) {
            BotTeamOrders(bs);
            //
            bs->teamgiveorders_time = 0;
        }
        break;
    }
    case GT_CTF:
    {
        //if the number of team mates changed or the flag status changed
        //or someone wants to know what to do
        if (bs->numteammates != numteammates || bs->flagstatuschanged || bs->forceorders) {
            bs->teamgiveorders_time = trap_AAS_Time();
            bs->numteammates = numteammates;
            bs->flagstatuschanged = qfalse;
            bs->forceorders = qfalse;
        }
        //if there were no flag captures the last 3 minutes
        if (bs->lastflagcapture_time < trap_AAS_Time() - 240) {
            bs->lastflagcapture_time = trap_AAS_Time();
            //randomly change the CTF strategy
            if (random() < 0.4) {
                bs->ctfstrategy ^= CTFS_PASSIVE;
                bs->teamgiveorders_time = trap_AAS_Time();
            }
        }
        //if it's time to give orders
        if (bs->teamgiveorders_time && bs->teamgiveorders_time < trap_AAS_Time() - 3) {
            //
            if (BotCTFTeam(bs) == CTF_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;
            }
            //
            bs->teamgiveorders_time = 0;
        }
        break;
    }
    }
}