Skip to content

Commit

Permalink
New helper functions for AI: BotAreThereDOMPoints(), `BotIsThereDDP…
Browse files Browse the repository at this point in the history
…ointA()` and `BotIsThereDDPointB()`, return true if the control points exist in a match. (#230)
  • Loading branch information
NeonKnightOA authored Mar 18, 2024
1 parent df5973f commit 42b8dbb
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 8 deletions.
8 changes: 6 additions & 2 deletions code/game/ai_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ void BotSetDominationPoint(bot_state_t *bs, int controlPoint) {
// Domination only
if (gametype != GT_DOMINATION) return;
// If there are no points, just assign the neutral one.
if (level.domination_points_count > 1) {
if (!BotAreThereDOMPoints()) {
bs->currentPoint = 0;
return;
}
Expand Down Expand Up @@ -736,6 +736,8 @@ void BotMatch_TakeA(bot_state_t *bs, bot_match_t *match) {
int client;

if (gametype != GT_DOUBLE_D) return;
// If the A point isn't present, don't do anything.
if (!BotIsThereDDPointA()) return;
//if not addressed to this bot
if (!BotAddressedToBot(bs, match)) return;
//get the match variable
Expand Down Expand Up @@ -786,6 +788,8 @@ void BotMatch_TakeB(bot_state_t *bs, bot_match_t *match) {
int client;

if (gametype != GT_DOUBLE_D) return;
// If the B point isn't present, don't do anything.
if (!BotIsThereDDPointB()) return;
//if not addressed to this bot
if (!BotAddressedToBot(bs, match)) return;
//get the match variable
Expand Down Expand Up @@ -835,7 +839,7 @@ void BotMatch_HoldDOMPoint(bot_state_t *bs, bot_match_t *match) {
int client;

if (gametype != GT_DOMINATION) return;
if (level.domination_points_count < 1) return;
if (!BotAreThereDOMPoints()) return;
//if not addressed to this bot
if (!BotAddressedToBot(bs, match)) return;
//get the match variable
Expand Down
51 changes: 46 additions & 5 deletions code/game/ai_dmq3.c
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ void BotDomSeekGoals(bot_state_t *bs) {
// DD only
if (gametype != GT_DOMINATION) return;
// if the map has no points, just roam
if (level.domination_points_count < 1) {
if (!BotAreThereDOMPoints()) {
bs->ltgtype = LTG_PATROL;
BotSetUserInfo(bs, "teamtask", va("%d", TEAMTASK_PATROL));
BotSetTeamStatus(bs);
Expand Down Expand Up @@ -5578,13 +5578,12 @@ void BotSetupDeathmatchAI(void) {
if (untrap_BotGetLevelItemGoal(-1, "Blue Flag", &ctf_blueflag) < 0)
BotAI_Print(PRT_WARNING, "CTF without Blue Flag\n");
} else if (gametype == GT_DOUBLE_D) {
if (untrap_BotGetLevelItemGoal(-1, "Red Flag", &ctf_redflag) < 0)
if (!BotIsThereDDPointA())
BotAI_Print(PRT_WARNING, "DD without Point A\n");
if (untrap_BotGetLevelItemGoal(-1, "Blue Flag", &ctf_blueflag) < 0)
if (!BotIsThereDDPointB())
BotAI_Print(PRT_WARNING, "DD without Point B\n");
} else if (gametype == GT_DOMINATION) {
ent = untrap_BotGetLevelItemGoal(-1, "Domination point", &dom_points_bot[0]);
if (ent < 0)
if (!BotAreThereDOMPoints())
BotAI_Print(PRT_WARNING, "Domination without a single domination point\n");
else
BotSetEntityNumForGoal(&dom_points_bot[0], va("domination_point%i", 0));
Expand Down Expand Up @@ -5691,3 +5690,45 @@ qboolean BotTeamOwnsControlPoint(bot_state_t *bs,int point) {
}
return qfalse;
}

/*
==================
BotAreThereDOMPoints
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;
}
}
return qtrue;
}

/*
==================
BotIsThereDDPointA
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;
}
return qtrue;
}

/*
==================
BotIsThereDDPointB
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;
}
return qtrue;
}

6 changes: 6 additions & 0 deletions code/game/ai_dmq3.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ int BotCanAndWantsToRocketJump(bot_state_t *bs);
int BotCanAndWantsToUseTheGrapple(bot_state_t *bs);
// returns true if the bot's team owns a control point (DD/DOM)
qboolean BotTeamOwnsControlPoint(bot_state_t *bs,int point);
// returns true if there is at least one control point in the map (DOM)
qboolean BotAreThereDOMPoints(void);
// returns true if there is an A control point in the map (DD)
qboolean BotIsThereDDPointA(void);
// returns true if there is a B control point in the map (DD)
qboolean BotIsThereDDPointB(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
6 changes: 5 additions & 1 deletion code/game/ai_vcmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ BotVoiceChat_HoldPointA
void BotVoiceChat_HoldPointA(bot_state_t *bs, int client, int mode) {
//Only valid for Double Domination
if (gametype != GT_DOUBLE_D) return;
// If the A point isn't present, don't do anything.
if (!BotIsThereDDPointA()) return;

bs->decisionmaker = client;
bs->ordered = qtrue;
Expand Down Expand Up @@ -102,6 +104,8 @@ BotVoiceChat_HoldPointB
void BotVoiceChat_HoldPointB(bot_state_t *bs, int client, int mode) {
//Only valid for Double Domination
if (gametype != GT_DOUBLE_D) return;
// If the B point isn't present, don't do anything.
if (!BotIsThereDDPointB()) return;

bs->decisionmaker = client;
bs->ordered = qtrue;
Expand Down Expand Up @@ -132,7 +136,7 @@ BotVoiceChat_HoldDOMPoint
void BotVoiceChat_HoldDOMPoint(bot_state_t *bs, int client, int mode) {
//Only valid for Double Domination
if (gametype != GT_DOMINATION) return;
if (level.domination_points_count < 1) return;
if (!BotAreThereDOMPoints()) return;

bs->decisionmaker = client;
bs->ordered = qtrue;
Expand Down

0 comments on commit 42b8dbb

Please sign in to comment.