Skip to content

Commit

Permalink
New helper function for AI: BotTeamControlsPoint(), which returns tru…
Browse files Browse the repository at this point in the history
…e if the bot's team controls a DD/DOM point. (#197)
  • Loading branch information
NeonKnightOA authored Mar 15, 2024
1 parent 9aa117d commit 6acc658
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 42 deletions.
3 changes: 1 addition & 2 deletions code/game/ai_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -521,8 +521,7 @@ void BotSetDominationPoint(bot_state_t *bs, int controlPoint) {
}
// Search for points our team don't own.
for (i=1;i<level.domination_points_count;i++) {
if ((BotTeam(bs) == TEAM_RED && level.pointStatusDom[i] != TEAM_RED) ||
(BotTeam(bs) == TEAM_BLUE && level.pointStatusDom[i] != TEAM_BLUE)) {
if (!BotTeamControlsPoint(bs,level.pointStatusDom[i])) {
allTaken = qfalse;
bs->currentPoint = i;
break;
Expand Down
47 changes: 26 additions & 21 deletions code/game/ai_dmq3.c
Original file line number Diff line number Diff line change
Expand Up @@ -435,24 +435,16 @@ void BotSetTeamStatus(bot_state_t *bs) {
teamtask = TEAMTASK_OFFENSE;
break;
case LTG_HOLDPOINTA:
if ((BotTeam(bs) == TEAM_BLUE && level.pointStatusA != TEAM_BLUE) ||
(BotTeam(bs) == TEAM_RED && level.pointStatusA != TEAM_RED))
teamtask = TEAMTASK_OFFENSE;
else if ((BotTeam(bs) == TEAM_BLUE && level.pointStatusA == TEAM_BLUE) ||
(BotTeam(bs) == TEAM_RED && level.pointStatusA == TEAM_RED))
if (BotTeamControlsPoint(bs,level.pointStatusA))
teamtask = TEAMTASK_DEFENSE;
else
teamtask = TEAMTASK_PATROL;
else
teamtask = TEAMTASK_OFFENSE;
break;
case LTG_HOLDPOINTB:
if ((BotTeam(bs) == TEAM_BLUE && level.pointStatusB != TEAM_BLUE) ||
(BotTeam(bs) == TEAM_RED && level.pointStatusB != TEAM_RED))
teamtask = TEAMTASK_OFFENSE;
else if ((BotTeam(bs) == TEAM_BLUE && level.pointStatusB == TEAM_BLUE) ||
(BotTeam(bs) == TEAM_RED && level.pointStatusB == TEAM_RED))
if (BotTeamControlsPoint(bs,level.pointStatusB))
teamtask = TEAMTASK_DEFENSE;
else
teamtask = TEAMTASK_PATROL;
else
teamtask = TEAMTASK_OFFENSE;
break;
case LTG_HOLDDOMPOINT:
// If the bot has an invalid CP, reroll.
Expand All @@ -461,15 +453,10 @@ void BotSetTeamStatus(bot_state_t *bs) {
BotGetDominationPoint(bs) < level.domination_points_count)) {
BotSetDominationPoint(bs,-1);
}
if ((BotTeam(bs) == TEAM_BLUE && level.pointStatusDom[BotGetDominationPoint(bs)] == TEAM_BLUE) ||
(BotTeam(bs) == TEAM_RED && level.pointStatusDom[BotGetDominationPoint(bs)] == TEAM_RED))
if (BotTeamControlsPoint(bs,level.pointStatusDom[BotGetDominationPoint(bs)]))
teamtask = TEAMTASK_DEFENSE;
else if ((BotTeam(bs) == TEAM_BLUE && level.pointStatusDom[BotGetDominationPoint(bs)] != TEAM_BLUE) ||
(BotTeam(bs) == TEAM_RED && level.pointStatusDom[BotGetDominationPoint(bs)] != TEAM_RED))
else
teamtask = TEAMTASK_OFFENSE;
else {
teamtask = TEAMTASK_PATROL;
}
break;
default:
teamtask = TEAMTASK_PATROL;
Expand Down Expand Up @@ -5683,3 +5670,21 @@ int BotCanAndWantsToUseTheGrapple(bot_state_t *bs) {
// Else they'll be happy to use it
return qtrue;
}

/*
==================
BotTeamControlsPoint
Returns true if the bot's team controls the Domination/DD point.
==================
*/
qboolean BotTeamControlsPoint(bot_state_t *bs,int point) {
// It's true if the bot is in the blue team and the point belongs to the blue team.
if(BotTeam(bs) == TEAM_BLUE && point == TEAM_BLUE) {
return qtrue;
}
// It's true if the bot is in the red team and the point belongs to the red team.
if(BotTeam(bs) == TEAM_RED && point == TEAM_RED) {
return qtrue;
}
return qfalse;
}
2 changes: 2 additions & 0 deletions code/game/ai_dmq3.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ int BotWantsToHelp(bot_state_t *bs);
int BotCanAndWantsToRocketJump(bot_state_t *bs);
// returns true if the bot has the Grappling Hook and wants to use it
int BotCanAndWantsToUseTheGrapple(bot_state_t *bs);
// returns true if the bot's team owns a control point (DD/DOM)
qboolean BotTeamControlsPoint(bot_state_t *bs,int point);
// 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
23 changes: 11 additions & 12 deletions code/game/ai_team.c
Original file line number Diff line number Diff line change
Expand Up @@ -2509,22 +2509,21 @@ BotDDorders
==================
*/
void BotDDorders(bot_state_t *bs) {
if ((BotTeam(bs) == TEAM_RED && level.pointStatusA == TEAM_RED &&
level.pointStatusB != TEAM_RED) || (BotTeam(bs) == TEAM_BLUE &&
level.pointStatusA == TEAM_BLUE && level.pointStatusB != TEAM_BLUE)) {
// If only the control point A is taken...
if (BotTeamControlsPoint(bs,level.pointStatusA) &&
!BotTeamControlsPoint(bs,level.pointStatusB)) {
BotDDorders_PointATaken(bs);
}
else if ((BotTeam(bs) == TEAM_RED && level.pointStatusA != TEAM_RED &&
level.pointStatusB == TEAM_RED) || (BotTeam(bs) == TEAM_BLUE &&
level.pointStatusA != TEAM_BLUE && level.pointStatusB == TEAM_BLUE)) {
// If only the control point B is taken...
else if (!BotTeamControlsPoint(bs,level.pointStatusA) &&
BotTeamControlsPoint(bs,level.pointStatusB)) {
BotDDorders_PointBTaken(bs);
}
else if ((BotTeam(bs) == TEAM_RED && level.pointStatusA != TEAM_RED &&
level.pointStatusB != TEAM_RED) || (BotTeam(bs) != TEAM_BLUE &&
level.pointStatusA != TEAM_BLUE && level.pointStatusB != TEAM_BLUE) ||
(BotTeam(bs) == TEAM_RED && level.pointStatusA == TEAM_RED &&
level.pointStatusB == TEAM_RED) || (BotTeam(bs) == TEAM_BLUE &&
level.pointStatusA == TEAM_BLUE && level.pointStatusB == TEAM_BLUE)) {
// If both control points (or none) are taken...
else if ((BotTeamControlsPoint(bs,level.pointStatusA) &&
BotTeamControlsPoint(bs,level.pointStatusB)) ||
(!BotTeamControlsPoint(bs,level.pointStatusA) &&
!BotTeamControlsPoint(bs,level.pointStatusB))) {
BotDDorders_BothPointsTaken(bs);
}
}
Expand Down
11 changes: 4 additions & 7 deletions code/game/ai_vcmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,19 +298,16 @@ void BotVoiceChat_Defend(bot_state_t *bs, int client, int mode) {
}
else if (gametype == GT_DOUBLE_D) {
// If the point A is under control, defend it.
if ((BotTeam(bs) == TEAM_RED && level.pointStatusA == TEAM_RED) ||
(BotTeam(bs) == TEAM_BLUE && level.pointStatusA == TEAM_BLUE)) {
if (BotTeamControlsPoint(bs,level.pointStatusA)) {
BotVoiceChat_HoldPointA(bs,client,mode);
}
// If the point B is under control, defend it.
else if ((BotTeam(bs) == TEAM_RED && level.pointStatusB == TEAM_RED) ||
(BotTeam(bs) == TEAM_BLUE && level.pointStatusB == TEAM_BLUE)) {
else if (BotTeamControlsPoint(bs,level.pointStatusB)) {
BotVoiceChat_HoldPointB(bs,client,mode);
}
// If both points are under control, pick one and defend it.
else if ((BotTeam(bs) == TEAM_RED && level.pointStatusA == TEAM_RED &&
level.pointStatusB == TEAM_RED) || (BotTeam(bs) == TEAM_BLUE &&
level.pointStatusA == TEAM_BLUE && level.pointStatusB == TEAM_BLUE)) {
else if (BotTeamControlsPoint(bs,level.pointStatusA) &&
BotTeamControlsPoint(bs,level.pointStatusB)) {
if (rand() % 10 > 5)
BotVoiceChat_HoldPointA(bs,client,mode);
else
Expand Down

0 comments on commit 6acc658

Please sign in to comment.