Skip to content

Commit

Permalink
AI: New helper functions that check for flag and obelisk existence. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
NeonKnightOA authored Mar 18, 2024
1 parent 352eae4 commit 7dee3fd
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 40 deletions.
40 changes: 21 additions & 19 deletions code/game/ai_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -675,17 +675,21 @@ void BotMatch_DefendKeyArea(bot_state_t *bs, bot_match_t *match) {

if (!G_IsATeamGametype(gametype)) return;
// Double Domination had other rules
if (gametype == GT_DOUBLE_D) {
else if (gametype == GT_DOUBLE_D) {
// "Defend" will make bots to focus on point B.
BotMatch_TakeB(bs,match);
return;
}
// Domination has clear rules
if (gametype == GT_DOMINATION) {
else if (gametype == GT_DOMINATION) {
// Reroll to get a different DOM point.
BotSetDominationPoint(bs,-1);
BotMatch_HoldDOMPoint(bs,match);
}
}
// eCTF in AvD mode only allows defenders to defend.
else if (gametype == GT_CTF_ELIMINATION && g_elimination_ctf_oneway.integer && BotIsOnAttackingTeam(bs)) {
return;
}
//if not addressed to this bot
if (!BotAddressedToBot(bs, match)) return;
//get the match variable
Expand Down Expand Up @@ -1054,19 +1058,18 @@ void BotMatch_GetFlag(bot_state_t *bs, bot_match_t *match) {
char netname[MAX_MESSAGE_SIZE];
int client;

if (G_UsesTeamFlags(gametype) && !G_UsesTheWhiteFlag(gametype)) {
if (!ctf_redflag.areanum || !ctf_blueflag.areanum)
return;
if (!G_UsesTeamFlags(gametype) && !G_UsesTheWhiteFlag(gametype)) {
return;
}
else if (gametype == GT_1FCTF) {
if (!ctf_neutralflag.areanum || !ctf_redflag.areanum || !ctf_blueflag.areanum)
if (G_UsesTeamFlags(gametype)) {
if (!BotIsThereABlueFlag() || !BotIsThereARedFlag())
return;
}
else if (gametype == GT_POSSESSION) {
if (!ctf_neutralflag.areanum)
if (G_UsesTheWhiteFlag(gametype)) {
if (!BotIsThereANeutralFlag())
return;
}
else {
if (gametype == GT_CTF_ELIMINATION && g_elimination_ctf_oneway.integer && !BotIsOnAttackingTeam(bs)) {
return;
}
//if not addressed to this bot
Expand Down Expand Up @@ -1114,7 +1117,7 @@ void BotMatch_AttackEnemyBase(bot_state_t *bs, bot_match_t *match) {
}
else if ((G_UsesTeamFlags(gametype) && G_UsesTheWhiteFlag(gametype)) ||
gametype == GT_HARVESTER || gametype == GT_OBELISK) {
if (!redobelisk.areanum || !blueobelisk.areanum)
if (!BotIsThereARedObelisk() || !BotIsThereABlueObelisk())
return;
}
else if (gametype == GT_DOUBLE_D) {
Expand Down Expand Up @@ -1166,13 +1169,12 @@ void BotMatch_Harvest(bot_state_t *bs, bot_match_t *match) {
char netname[MAX_MESSAGE_SIZE];
int client;

if (gametype == GT_HARVESTER) {
if (!neutralobelisk.areanum || !redobelisk.areanum || !blueobelisk.areanum)
return;
}
else {
if (gametype != GT_HARVESTER) {
return;
}
if (!BotIsThereANeutralObelisk() || !BotIsThereARedObelisk() || !BotIsThereABlueObelisk()) {
return;
}
//if not addressed to this bot
if (!BotAddressedToBot(bs, match)) return;
//
Expand Down Expand Up @@ -1210,11 +1212,11 @@ void BotMatch_RushBase(bot_state_t *bs, bot_match_t *match) {
int client;

if (G_UsesTeamFlags(gametype) && !G_UsesTheWhiteFlag(gametype)) {
if (!ctf_redflag.areanum || !ctf_blueflag.areanum)
if (!BotIsThereARedFlag() || !BotIsThereABlueFlag())
return;
}
else if (gametype == GT_1FCTF || gametype == GT_HARVESTER) {
if (!redobelisk.areanum || !blueobelisk.areanum)
if (!BotIsThereARedObelisk() || !BotIsThereABlueObelisk())
return;
}
else {
Expand Down
113 changes: 97 additions & 16 deletions code/game/ai_dmq3.c
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ void BotCTFSeekGoals(bot_state_t *bs) {
}
//get the flag or defend the base
rnd = random();
if (rnd < l1 && ctf_redflag.areanum && ctf_blueflag.areanum) {
if (rnd < l1 && BotIsThereARedFlag() && BotIsThereABlueFlag()) {
bs->decisionmaker = bs->client;
bs->ordered = qfalse;
bs->ltgtype = LTG_GETFLAG;
Expand All @@ -787,7 +787,7 @@ void BotCTFSeekGoals(bot_state_t *bs) {
//get an alternative route goal towards the enemy base
BotGetAlternateRouteGoal(bs, BotOppositeTeam(bs));
BotSetTeamStatus(bs);
} else if (rnd < l2 && ctf_redflag.areanum && ctf_blueflag.areanum) {
} else if (rnd < l2 && BotIsThereARedFlag() && BotIsThereABlueFlag()) {
bs->decisionmaker = bs->client;
bs->ordered = qfalse;
//
Expand Down Expand Up @@ -1220,7 +1220,7 @@ void Bot1FCTFSeekGoals(bot_state_t *bs) {
//set the time the bot will stop getting the flag
bs->teamgoal_time = FloatTime() + CTF_GETFLAG_TIME;
BotSetTeamStatus(bs);
} else if (rnd < l2 && ctf_redflag.areanum && ctf_blueflag.areanum) {
} else if (rnd < l2 && BotIsThereARedFlag() && BotIsThereABlueFlag()) {
bs->decisionmaker = bs->client;
bs->ordered = qfalse;
//
Expand Down Expand Up @@ -1324,7 +1324,7 @@ void BotObeliskSeekGoals(bot_state_t *bs) {
}
//get the flag or defend the base
rnd = random();
if (rnd < l1 && redobelisk.areanum && blueobelisk.areanum) {
if (rnd < l1 && BotIsThereARedObelisk() && BotIsThereABlueObelisk()) {
bs->decisionmaker = bs->client;
bs->ordered = qfalse;
//
Expand All @@ -1337,7 +1337,7 @@ void BotObeliskSeekGoals(bot_state_t *bs) {
//get an alternate route goal towards the enemy base
BotGetAlternateRouteGoal(bs, BotOppositeTeam(bs));
BotSetTeamStatus(bs);
} else if (rnd < l2 && redobelisk.areanum && blueobelisk.areanum) {
} else if (rnd < l2 && BotIsThereARedObelisk() && BotIsThereABlueObelisk()) {
bs->decisionmaker = bs->client;
bs->ordered = qfalse;
//
Expand Down Expand Up @@ -1495,11 +1495,11 @@ void BotHarvesterSeekGoals(bot_state_t *bs) {
}
//
rnd = random();
if (rnd < l1 && redobelisk.areanum && blueobelisk.areanum) {
if (rnd < l1 && BotIsThereARedObelisk() && BotIsThereABlueObelisk()) {
bs->decisionmaker = bs->client;
bs->ordered = qfalse;
BotGoHarvest(bs);
} else if (rnd < l2 && redobelisk.areanum && blueobelisk.areanum) {
} else if (rnd < l2 && BotIsThereARedObelisk() && BotIsThereABlueObelisk()) {
bs->decisionmaker = bs->client;
bs->ordered = qfalse;
//
Expand Down Expand Up @@ -5699,11 +5699,11 @@ Returns true if the match has at least one control point present for Domination.
*/
qboolean BotAreThereDOMPoints(void) {
if (gametype == GT_DOMINATION) {
if (level.domination_points_count < 1) {
return qfalse;
if (level.domination_points_count >= 1) {
return qtrue;
}
}
return qtrue;
return qfalse;
}

/*
Expand All @@ -5713,10 +5713,10 @@ Returns true if the match has the A point present for Double Domination.
==================
*/
qboolean BotIsThereDDPointA(void) {
if (gametype == GT_DOUBLE_D && untrap_BotGetLevelItemGoal(-1, "Red Flag", &ctf_redflag) < 0) {
return qfalse;
if (gametype == GT_DOUBLE_D && untrap_BotGetLevelItemGoal(-1, "Red Flag", &ctf_redflag) >= 1) {
return qtrue;
}
return qtrue;
return qfalse;
}

/*
Expand All @@ -5726,9 +5726,90 @@ Returns true if the match has the B point present for Double Domination.
==================
*/
qboolean BotIsThereDDPointB(void) {
if (gametype == GT_DOUBLE_D && untrap_BotGetLevelItemGoal(-1, "Blue Flag", &ctf_blueflag) < 0) {
return qfalse;
if (gametype == GT_DOUBLE_D && untrap_BotGetLevelItemGoal(-1, "Red Flag", &ctf_blueflag) >= 1) {
return qtrue;
}
return qtrue;
return qfalse;
}

/*
==================
BotIsThereABlueFlag
Returns true if the match has a blue CTF flag present for flag-based matches.
==================
*/
qboolean BotIsThereABlueFlag(void) {
if (G_UsesTeamFlags(gametype) && ctf_blueflag.areanum) {
return qtrue;
}
return qfalse;
}

/*
==================
BotIsThereARedFlag
Returns true if the match has a red CTF flag present for flag-based matches.
==================
*/
qboolean BotIsThereARedFlag(void) {
if (G_UsesTeamFlags(gametype) && ctf_redflag.areanum) {
return qtrue;
}
return qfalse;
}

/*
==================
BotIsThereANeutralFlag
Returns true if the match has a white CTF flag present for flag-based matches.
==================
*/
qboolean BotIsThereANeutralFlag(void) {
if (G_UsesTheWhiteFlag(gametype) && ctf_neutralflag.areanum) {
return qtrue;
}
return qfalse;
}

/*
==================
BotIsThereARedObelisk
Returns true if the match has a red obelisk present for 1FCTF/Harvester/Overload matches.
==================
*/
qboolean BotIsThereARedObelisk(void) {
if ((gametype == GT_1FCTF || gametype == GT_HARVESTER ||
gametype == GT_OBELISK) && redobelisk.areanum) {
return qtrue;
}
return qfalse;
}

/*
==================
BotIsThereABlueObelisk
Returns true if the match has a blue obelisk present for 1FCTF/Harvester/Overload matches.
==================
*/
qboolean BotIsThereABlueObelisk(void) {
if ((gametype == GT_1FCTF || gametype == GT_HARVESTER ||
gametype == GT_OBELISK) && blueobelisk.areanum) {
return qtrue;
}
return qfalse;
}

/*
==================
BotIsThereANeutralObelisk
Returns true if the match has a neutral obelisk present for 1FCTF/Harvester/Possession matches.
==================
*/
qboolean BotIsThereANeutralObelisk(void) {
if ((gametype == GT_1FCTF || gametype == GT_HARVESTER ||
gametype == GT_OBELISK) && neutralobelisk.areanum) {
return qtrue;
}
return qfalse;
}

12 changes: 12 additions & 0 deletions code/game/ai_dmq3.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,18 @@ qboolean BotAreThereDOMPoints(void);
qboolean BotIsThereDDPointA(void);
// returns true if there is a B control point in the map (DD)
qboolean BotIsThereDDPointB(void);
// returns true if there is a blue CTF flag in the map (CTF/eCTF/1FCTF)
qboolean BotIsThereABlueFlag(void);
// returns true if there is a red CTF flag in the map (CTF/eCTF/1FCTF)
qboolean BotIsThereARedFlag(void);
// returns true if there is a neutral CTF flag in the map (1FCTF/Possession)
qboolean BotIsThereANeutralFlag(void);
// returns true if there is a blue obelisk in the map (1FCTF/Harvester/Overload)
qboolean BotIsThereABlueObelisk(void);
// returns true if there is a red obelisk in the map (1FCTF/Harvester/Overload)
qboolean BotIsThereARedObelisk(void);
// returns true if there is a neutral obelisk in the map (1FCTF/Harvester)
qboolean BotIsThereANeutralObelisk(void);
// returns true if the bot has a persistant powerup and a weapon
int BotHasPersistantPowerupAndWeapon(bot_state_t *bs);
//returns true if the bot wants to and goes camping
Expand Down
17 changes: 12 additions & 5 deletions code/game/ai_vcmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,18 @@ BotVoiceChat_GetFlag
*/
void BotVoiceChat_GetFlag(bot_state_t *bs, int client, int mode) {
//
if (G_UsesTeamFlags(gametype) && !G_UsesTheWhiteFlag(gametype)) {
if (!ctf_redflag.areanum || !ctf_blueflag.areanum)
if (!G_UsesTeamFlags(gametype) && !G_UsesTheWhiteFlag(gametype)) {
return;
}
if (G_UsesTeamFlags(gametype)) {
if (!BotIsThereABlueFlag() || !BotIsThereARedFlag())
return;
}
else if (gametype == GT_1FCTF) {
if (!ctf_neutralflag.areanum || !ctf_redflag.areanum || !ctf_blueflag.areanum)
if (G_UsesTheWhiteFlag(gametype)) {
if (!BotIsThereANeutralFlag())
return;
}
else {
if (gametype == GT_CTF_ELIMINATION && g_elimination_ctf_oneway.integer && !BotIsOnAttackingTeam(bs)) {
return;
}
//
Expand Down Expand Up @@ -324,6 +327,10 @@ void BotVoiceChat_Defend(bot_state_t *bs, int client, int mode) {
BotVoiceChat_HoldDOMPoint(bs,client,mode);
return;
}
// eCTF in AvD mode only allows defenders to defend.
else if (gametype == GT_CTF_ELIMINATION && g_elimination_ctf_oneway.integer && BotIsOnAttackingTeam(bs)) {
return;
}
//
bs->decisionmaker = client;
bs->ordered = qtrue;
Expand Down

0 comments on commit 7dee3fd

Please sign in to comment.