Skip to content

Commit 92a46c9

Browse files
Goober5000claude
andauthored
Fix SEXP references for shifted waypoints after single waypoint deletion (#7337)
When a waypoint is deleted from a list, the remaining waypoints after it shift down (e.g. Path:3 becomes Path:2). SEXP and AI goal references were properly invalidated for the deleted waypoint, but were not updated for any subsequent waypoint to reflect the new numbering. Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent bca2721 commit 92a46c9

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

fred2/management.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,9 +1306,24 @@ int common_object_delete(int obj)
13061306
invalidate_references(wp_list->get_name(), sexp_ref_type::WAYPOINT_PATH);
13071307
}
13081308

1309+
// save info needed to update shifted waypoint references after removal
1310+
int deleted_index = wpt->get_index();
1311+
char list_name[NAME_LENGTH];
1312+
strcpy_s(list_name, wp_list->get_name());
1313+
13091314
// the actual removal code has been moved to this function in waypoints.cpp
13101315
waypoint_remove(wpt);
13111316

1317+
// update SEXP and AI goal references for waypoints that shifted down
1318+
for (int wi = deleted_index; wi < (int)count - 1; wi++) {
1319+
char old_wpt_name[NAME_LENGTH];
1320+
char new_wpt_name[NAME_LENGTH];
1321+
waypoint_stuff_name(old_wpt_name, list_name, wi + 2); // old 1-based number
1322+
waypoint_stuff_name(new_wpt_name, list_name, wi + 1); // new 1-based number
1323+
update_sexp_references(old_wpt_name, new_wpt_name);
1324+
ai_update_goal_references(sexp_ref_type::WAYPOINT, old_wpt_name, new_wpt_name);
1325+
}
1326+
13121327
} else if (type == OBJ_SHIP) {
13131328
name = Ships[Objects[obj].instance].ship_name;
13141329
r = reference_handler(name, sexp_ref_type::SHIP, obj);

qtfred/src/mission/Editor.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,9 +1066,24 @@ int Editor::common_object_delete(int obj) {
10661066
invalidate_references(wp_list->get_name(), sexp_ref_type::WAYPOINT_PATH);
10671067
}
10681068

1069+
// save info needed to update shifted waypoint references after removal
1070+
int deleted_index = wpt->get_index();
1071+
char list_name[NAME_LENGTH];
1072+
strcpy_s(list_name, wp_list->get_name());
1073+
10691074
// the actual removal code has been moved to this function in waypoints.cpp
10701075
waypoint_remove(wpt);
10711076

1077+
// update SEXP and AI goal references for waypoints that shifted down
1078+
for (int wi = deleted_index; wi < (int)count - 1; wi++) {
1079+
char old_wpt_name[NAME_LENGTH];
1080+
char new_wpt_name[NAME_LENGTH];
1081+
waypoint_stuff_name(old_wpt_name, list_name, wi + 2); // old 1-based number
1082+
waypoint_stuff_name(new_wpt_name, list_name, wi + 1); // new 1-based number
1083+
update_sexp_references(old_wpt_name, new_wpt_name);
1084+
ai_update_goal_references(sexp_ref_type::WAYPOINT, old_wpt_name, new_wpt_name);
1085+
}
1086+
10721087
} else if (type == OBJ_SHIP) {
10731088
name = Ships[Objects[obj].instance].ship_name;
10741089
r = reference_handler(name, sexp_ref_type::SHIP, obj);

0 commit comments

Comments
 (0)