Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Implementation for an AI order to chase ship types #6620

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

LuytenKy
Copy link
Contributor

@LuytenKy LuytenKy commented Mar 6, 2025

First draft pull request for #6271.

This PR introduces the draft for the AI order logic that allows the FreeSpace AI to target ship type, (fighter, bomber, cruiser, etc.) rather than being limited to a class, wing, or individual ship.

if (stricmp(purge_goal->target_name, Ship_types[ship_type].name) != 0)
continue;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the blank line here

if ( purge_ai_mode == AI_GOAL_CHASE_SHIP_CLASS ) {
// if the target of the purge goal is the same class of ship we are concerned about, then we have a match;
// if it is not, then we can continue (see standard ship check below)
if ( stricmp(purge_goal->target_name, Ship_info[Ships[ship_index].ship_info_index].name) != 0 )
continue;
}
else if (purge_ai_mode == AI_GOAL_CHASE_SHIP_TYPE) {
// Get the ship type of the ship we're concerned about
ship_type = Ship_info[Ships[ship_index].ship_info_index].class_type;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of declaring ship_type at the top of the function, declare it here, at the beginning of the line where it is used.

@@ -1688,6 +1711,19 @@ ai_achievability ai_mission_goal_achievable( int objnum, ai_goal *aigp )
return ai_achievability::NOT_KNOWN;
}

if (aigp->ai_mode == AI_GOAL_CHASE_SHIP_TYPE) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a comment above this line: // and similarly for chasing all ships of a certain ship type

Comment on lines +1719 to +1720
int class_type = Ship_info[Ships[type_objp->instance].ship_info_index].class_type;
if ((type_objp->type == OBJ_SHIP) && class_type >= 0 &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not possible to get the class_type if the object is not a ship. So, you'll need to separate the if() condition. Check for OBJ_SHIP first, then get the class type, then check the class type.

break;
}

case AI_GOAL_CHASE_SHIP_TYPE:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a comment above this line: // similarly for chase-ship-type

@@ -1008,6 +1031,7 @@ void ShipGoalsDlg::update_item(int item, int multi)
case AI_GOAL_STAY_NEAR_SHIP:
case AI_GOAL_STAY_STILL:
case AI_GOAL_CHASE_SHIP_CLASS:
case AI_GOAL_CHASE_SHIP_TYPE:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Farther down this file, around line 1159, there is a case TYPE_SHIP_CLASS: that needs a corresponding case TYPE_SHIP_TYPE:

} else {
aip->target_objnum = -1;
aip->target_signature = -1;
return -1;
}
}


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This blank line can be removed

if (timestamp_elapsed(aip->choose_enemy_timestamp)) {
aip->choose_enemy_timestamp = timestamp(get_enemy_timestamp());
if (aip->target_objnum != -1) {
int target_objnum = aip->target_objnum;
int target_objnum = aip->target_objnum;
ship* target_shipp = &Ships[Objects[target_objnum].instance];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change this to:

ship* target_shipp = (Objects[target_objnum].type == OBJ_SHIP) ? &Ships[Objects[target_objnum].instance] : nullptr;

Because not every target is necessarily a ship. This was a bug in Volition's code too :-/

return target_objnum;
// This could cause attack on ship on fringe on nebula to stop if attackee moves out of nebula range. (BAD)
if (Objects[target_objnum].signature == aip->target_signature) {
if (iff_matches_mask(target_shipp->team, enemy_team_mask)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change this to

if (target_shipp && iff_matches_mask(target_shipp->team, enemy_team_mask)) {

because with my above review comment, it will be possible for target_shipp to be nullptr


return get_nearest_objnum(objnum, enemy_team_mask, aip->enemy_wing, range, max_attackers, ship_info_index);

return get_nearest_objnum(objnum, enemy_team_mask,aip->enemy_wing, range, max_attackers, ship_info_index, class_type);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

put back the space between enemy_team_mask, and aip->enemy_wing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants