See attached diff:
Notes (There's always a caveat!):
1) This will remove the first instance of a specified goal, and only the goal found using ai_mode. Probably not quite what you're after (kara - could you please check if there's a way around this - I'm not sure that there is)
2) I'm not a FREDder, and I'm not sure how to actually go about testing this (but I'm learning, slowly!)
3) This needs a _complete_ review by someone who knows the ai system better than I do
This is quite a bit more complex than I thought it would be.
The patch does the following:
1) remove-goal now calls either ai_remove_ship_goal_sexp or ai_remove_wing_goal_sexp
2) Those functions call ai_remove_ship_goal_sexp which performs the following steps
a) Parameter check
b) Map the sexp to the AI_GOAL* structure, including checking for wings in GOAL_CHASE and GOAL_GUARD (_WINGS)
c) Find the index of the goal in the aip->goals structure using ai_find_goal_index
d) Remove the goal using ai_remove_ship_goal
There's also a potential buffer overflow fixed in the called function ai_get_goal_ship_name
oh, and most importantly: ENJOY
[attachment deleted by ninja]