Skip to content

Commit 3783cb0

Browse files
committed
fix STAY_NEAR_TARGET_ITEM
1. Allow "Stay near me" and "Stay near my target" to work even if the teams do not match 2. Allow "Stay near my target" to be issued regardless of team 3. Avoid divide-by-zero errors when running `ai_stay_near()`
1 parent 829edaa commit 3783cb0

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

code/ai/aicode.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11476,7 +11476,7 @@ void ai_stay_near()
1147611476
else if (aip->submode_parm0 != 0) {
1147711477
vec3d rand_vec, center_to_goal, center_to_objp;
1147811478
auto goal_objp = &Objects[goal_objnum];
11479-
float max_dist = aip->submode_float0;
11479+
float max_dist = std::max(aip->submode_float0, 1.0f);
1148011480

1148111481
// Figure out a goal point to fly to
1148211482
// Make not all ships pursue same point.
@@ -11507,7 +11507,7 @@ void ai_stay_near()
1150711507
else {
1150811508
vec3d rand_vec, goal_pos, vec_to_goal;
1150911509
auto goal_objp = &Objects[goal_objnum];
11510-
float max_dist = aip->submode_float0;
11510+
float max_dist = std::max(aip->submode_float0, 1.0f);
1151111511

1151211512
// Make not all ships pursue same point.
1151311513
// Calculate the seed from both shipnums so the same Pl_objp doesn't always choose the same spot

code/hud/hudsquadmsg.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,9 @@ SCP_vector<player_order> Player_orders = {
147147
};
148148

149149
const SCP_set<size_t> default_messages{ ATTACK_TARGET_ITEM , DISABLE_TARGET_ITEM , DISARM_TARGET_ITEM , PROTECT_TARGET_ITEM , IGNORE_TARGET_ITEM , FORMATION_ITEM , COVER_ME_ITEM , ENGAGE_ENEMY_ITEM , DEPART_ITEM , DISABLE_SUBSYSTEM_ITEM };
150+
// note: STAY_NEAR_TARGET_ITEM appears in both enemy and friendly sets
150151
const SCP_set<size_t> enemy_target_messages{ ATTACK_TARGET_ITEM , DISABLE_TARGET_ITEM , DISARM_TARGET_ITEM , IGNORE_TARGET_ITEM , STAY_NEAR_TARGET_ITEM , CAPTURE_TARGET_ITEM , DISABLE_SUBSYSTEM_ITEM };
151-
const SCP_set<size_t> friendly_target_messages{ PROTECT_TARGET_ITEM };
152+
const SCP_set<size_t> friendly_target_messages{ PROTECT_TARGET_ITEM , STAY_NEAR_TARGET_ITEM };
152153
const SCP_set<size_t> target_messages = []() {
153154
SCP_set<size_t> setunion;
154155
std::set_union(enemy_target_messages.cbegin(), enemy_target_messages.cend(), friendly_target_messages.cbegin(), friendly_target_messages.cend(), std::inserter(setunion, setunion.end()));
@@ -1319,11 +1320,6 @@ int hud_squadmsg_send_ship_command( int shipnum, int command, int send_message,
13191320

13201321
case STAY_NEAR_ME_ITEM:
13211322
case STAY_NEAR_TARGET_ITEM:
1322-
1323-
// cannot stay near a hostile ship(?)
1324-
if ( (command == STAY_NEAR_TARGET_ITEM) && (ship_team != target_team) )
1325-
break;
1326-
13271323
ai_mode = AI_GOAL_STAY_NEAR_SHIP;
13281324
ai_submode = -1;
13291325
message = MESSAGE_YESSIR;

0 commit comments

Comments
 (0)