Skip to content

Commit a9664ff

Browse files
Merge pull request #6752 from Goober5000/stay_near_target_fix
fix STAY_NEAR_TARGET_ITEM
2 parents b5f4942 + 939d6a5 commit a9664ff

File tree

4 files changed

+21
-18
lines changed

4 files changed

+21
-18
lines changed

code/ai/aicode.cpp

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

1149411494
// Figure out a goal point to fly to
1149511495
// Make not all ships pursue same point.
@@ -11520,7 +11520,7 @@ void ai_stay_near()
1152011520
else {
1152111521
vec3d rand_vec, goal_pos, vec_to_goal;
1152211522
auto goal_objp = &Objects[goal_objnum];
11523-
float max_dist = aip->submode_float0;
11523+
float max_dist = std::max(aip->submode_float0, 1.0f);
1152411524

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

code/ai/aigoals.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -732,12 +732,14 @@ void ai_goal_fixup_dockpoints(ai_info *aip, ai_goal *aigp)
732732
// from the mission goals (i.e. those goals which come from events) in that we don't
733733
// use sexpressions for goals from the player...so we enumerate all the parameters
734734

735-
void ai_add_goal_sub_player(ai_goal_type type, ai_goal_mode mode, int submode, const char *target_name, ai_goal *aigp, const ai_lua_parameters& lua_target )
735+
void ai_add_goal_sub_player(ai_goal_type type, ai_goal_mode mode, int submode, const char *target_name, ai_goal *aigp, int int_data, float float_data, const ai_lua_parameters& lua_target )
736736
{
737737
Assert ( (type == ai_goal_type::PLAYER_WING) || (type == ai_goal_type::PLAYER_SHIP) );
738738

739739
ai_goal_reset(aigp, true, mode, submode, type);
740740

741+
aigp->int_data = int_data;
742+
aigp->float_data = float_data;
741743
aigp->lua_ai_target = lua_target;
742744

743745
if ( mode == AI_GOAL_WARP ) {
@@ -865,14 +867,14 @@ void ai_add_ship_goal_scripting(ai_goal_mode mode, int submode, int priority, co
865867
// is issued to ship or wing (from player), mode is AI_GOAL_*. submode is the submode the
866868
// ship should go into. shipname is the object of the action. aip is the ai_info pointer
867869
// of the ship receiving the order
868-
void ai_add_ship_goal_player(ai_goal_type type, ai_goal_mode mode, int submode, const char *shipname, ai_info *aip, const ai_lua_parameters& lua_target)
870+
void ai_add_ship_goal_player(ai_goal_type type, ai_goal_mode mode, int submode, const char *shipname, ai_info *aip, int int_data, float float_data, const ai_lua_parameters& lua_target)
869871
{
870872
int empty_index;
871873
ai_goal *aigp;
872874

873875
empty_index = ai_goal_find_empty_slot( aip->goals, aip->active_goal );
874876
aigp = &aip->goals[empty_index];
875-
ai_add_goal_sub_player( type, mode, submode, shipname, aigp, lua_target );
877+
ai_add_goal_sub_player( type, mode, submode, shipname, aigp, int_data, float_data, lua_target );
876878

877879
// if the goal is to dock, then we must determine which dock points on the two ships to use.
878880
// If the target of the dock is a cargo type container, then we should use DOCK_TYPE_CARGO
@@ -886,7 +888,7 @@ void ai_add_ship_goal_player(ai_goal_type type, ai_goal_mode mode, int submode,
886888

887889
// adds a goal from the player to the given wing (which in turn will add it to the proper
888890
// ships in the wing
889-
void ai_add_wing_goal_player(ai_goal_type type, ai_goal_mode mode, int submode, const char *shipname, int wingnum, const ai_lua_parameters& lua_target)
891+
void ai_add_wing_goal_player(ai_goal_type type, ai_goal_mode mode, int submode, const char *shipname, int wingnum, int int_data, float float_data, const ai_lua_parameters& lua_target)
890892
{
891893
int i, empty_index;
892894
wing *wingp = &Wings[wingnum];
@@ -897,15 +899,15 @@ void ai_add_wing_goal_player(ai_goal_type type, ai_goal_mode mode, int submode,
897899
int num = wingp->ship_index[i];
898900
if ( num == -1 ) // ship must have been destroyed or departed
899901
continue;
900-
ai_add_ship_goal_player( type, mode, submode, shipname, &Ai_info[Ships[num].ai_index], lua_target );
902+
ai_add_ship_goal_player( type, mode, submode, shipname, &Ai_info[Ships[num].ai_index], int_data, float_data, lua_target );
901903
}
902904
}
903905

904906
// add the sexpression index into the wing's list of goal sexpressions if
905907
// there are more waves to come. We use the same method here as when adding a goal to
906908
// a ship -- find the first empty entry. If none exists, take the oldest entry and replace it.
907909
empty_index = ai_goal_find_empty_slot( wingp->ai_goals, -1 );
908-
ai_add_goal_sub_player( type, mode, submode, shipname, &wingp->ai_goals[empty_index], lua_target );
910+
ai_add_goal_sub_player( type, mode, submode, shipname, &wingp->ai_goals[empty_index], int_data, float_data, lua_target );
909911
}
910912

911913

code/ai/aigoals.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ extern int ai_remove_goal_sexp_sub( int sexp, ai_goal* aigp, bool &remove_more )
187187
extern void ai_remove_wing_goal_sexp( int sexp, wing *wingp );
188188

189189
// adds goals to ships/sings through player orders
190-
extern void ai_add_ship_goal_player(ai_goal_type type, ai_goal_mode mode, int submode, const char* shipname, ai_info* aip, const ai_lua_parameters& lua_target = { object_ship_wing_point_team(), luacpp::LuaValueList{} });
191-
extern void ai_add_wing_goal_player(ai_goal_type type, ai_goal_mode mode, int submode, const char* shipname, int wingnum, const ai_lua_parameters& lua_target = { object_ship_wing_point_team(), luacpp::LuaValueList{} });
190+
extern void ai_add_ship_goal_player(ai_goal_type type, ai_goal_mode mode, int submode, const char* shipname, ai_info* aip, int int_data = 0, float float_data = 0.0f, const ai_lua_parameters& lua_target = { object_ship_wing_point_team(), luacpp::LuaValueList{} });
191+
extern void ai_add_wing_goal_player(ai_goal_type type, ai_goal_mode mode, int submode, const char* shipname, int wingnum, int int_data = 0, float float_data = 0.0f, const ai_lua_parameters& lua_target = { object_ship_wing_point_team(), luacpp::LuaValueList{} });
192192

193193
extern void ai_remove_ship_goal( ai_info *aip, int index );
194194
extern void ai_clear_ship_goals( ai_info *aip );

code/hud/hudsquadmsg.cpp

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

150150
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 };
151+
// note: STAY_NEAR_TARGET_ITEM appears in both enemy and friendly sets
151152
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 };
152-
const SCP_set<size_t> friendly_target_messages{ PROTECT_TARGET_ITEM };
153+
const SCP_set<size_t> friendly_target_messages{ PROTECT_TARGET_ITEM , STAY_NEAR_TARGET_ITEM };
153154
const SCP_set<size_t> target_messages = []() {
154155
SCP_set<size_t> setunion;
155156
std::set_union(enemy_target_messages.cbegin(), enemy_target_messages.cend(), friendly_target_messages.cbegin(), friendly_target_messages.cend(), std::inserter(setunion, setunion.end()));
@@ -1183,6 +1184,8 @@ int hud_squadmsg_send_ship_command( int shipnum, int command, int send_message,
11831184
int ai_submode; // ...and submode needed for ship commands
11841185
ship *target = nullptr;
11851186
char *target_shipname;
1187+
int int_data = 0;
1188+
float float_data = 0.0f;
11861189
ai_lua_parameters lua_target;
11871190
int message;
11881191
int target_team, ship_team; // team id's for the ship getting message and any target the player has
@@ -1404,13 +1407,9 @@ int hud_squadmsg_send_ship_command( int shipnum, int command, int send_message,
14041407

14051408
case STAY_NEAR_ME_ITEM:
14061409
case STAY_NEAR_TARGET_ITEM:
1407-
1408-
// cannot stay near a hostile ship(?)
1409-
if ( (command == STAY_NEAR_TARGET_ITEM) && (ship_team != target_team) )
1410-
break;
1411-
14121410
ai_mode = AI_GOAL_STAY_NEAR_SHIP;
14131411
ai_submode = -1;
1412+
float_data = 300.0f; // distance from target ship
14141413
message = MESSAGE_YESSIR;
14151414
if (command == STAY_NEAR_ME_ITEM) {
14161415
target_shipname = ordering_shipp->ship_name;
@@ -1440,7 +1439,7 @@ int hud_squadmsg_send_ship_command( int shipnum, int command, int send_message,
14401439
// handle case of messaging one ship. Deal with messaging all fighters next.
14411440
if (ai_mode != AI_GOAL_NONE) {
14421441
Assert(ai_submode != -1234567);
1443-
ai_add_ship_goal_player(ai_goal_type::PLAYER_SHIP, ai_mode, ai_submode, target_shipname, &Ai_info[Ships[shipnum].ai_index], lua_target);
1442+
ai_add_ship_goal_player(ai_goal_type::PLAYER_SHIP, ai_mode, ai_submode, target_shipname, &Ai_info[Ships[shipnum].ai_index], int_data, float_data, lua_target);
14441443
if (update_history == SQUADMSG_HISTORY_ADD_ENTRY) {
14451444
hud_add_issued_order(Ships[shipnum].ship_name, command);
14461445
hud_update_last_order(target_shipname, player_num, special_index);
@@ -1480,6 +1479,8 @@ int hud_squadmsg_send_wing_command( int wingnum, int command, int send_message,
14801479
int ai_submode; // ...and submode needed for ship commands
14811480
ship *target = nullptr;
14821481
char *target_shipname;
1482+
int int_data = 0;
1483+
float float_data = 0.0f;
14831484
ai_lua_parameters lua_target;
14841485
int message_sent, message;
14851486
int target_team, wing_team; // team for the wing and the player's target
@@ -1664,7 +1665,7 @@ int hud_squadmsg_send_wing_command( int wingnum, int command, int send_message,
16641665

16651666
if (ai_mode != AI_GOAL_NONE) {
16661667
Assert(ai_submode != -1234567);
1667-
ai_add_wing_goal_player(ai_goal_type::PLAYER_WING, ai_mode, ai_submode, target_shipname, wingnum, lua_target);
1668+
ai_add_wing_goal_player(ai_goal_type::PLAYER_WING, ai_mode, ai_submode, target_shipname, wingnum, int_data, float_data, lua_target);
16681669

16691670
if (update_history == SQUADMSG_HISTORY_ADD_ENTRY) {
16701671
hud_add_issued_order(Wings[wingnum].name, command);

0 commit comments

Comments
 (0)