Hard Light Productions Forums

Modding, Mission Design, and Coding => The FRED Workshop => Topic started by: killface on May 12, 2009, 12:51:04 am

Title: remove-goal
Post by: killface on May 12, 2009, 12:51:04 am

Does the remove-goal sexp work?  Every time I try it, it does not seem to have an effect.  Then again perhaps it's the way I'm using it.  Basically, I want Beta wing to engage Red wing, but only when Red wing is ~10,000 m from its capital ship.  So I have it set up that once Red wing is 10,000+ from home, add goal to Beta to chase Red.  Once Red wing is destroyed OR the distance between Red and cap ship is under 10,000, remove that goal.  But it doesn't work.  Beta wing maintains its chase-Red goal and just sits still until the next wave of Red ships arrives and crosses the 10,000 meter threshold.  What gives?

killface
Title: Re: remove-goal
Post by: General Battuta on May 12, 2009, 12:57:14 am
As a workaround, try using clear-goals and then readding the goals you want it to perform now.
Title: Re: remove-goal
Post by: killface on May 12, 2009, 01:09:18 am
I should have mentioned...I did try using clear-goals, that was actually my plan to begin with.  But as these are every-time sexps (because there will be multiple waves of red wing), using clear-goals then add-goal just makes Beta wing fly in tiny circles, confused, as their goals get repeatedly voided out and re-added.

EDIT
Additionally, I tried having Red Wing protected until they get 10,000 meters from the cap ship, but this doesn't work either, because the unprotect-ship sexp only lets you select individual ships, not wings.  Which sucks, because there's many waves of Red wing to be had...
Title: Re: remove-goal
Post by: FUBAR-BDHR on May 12, 2009, 01:31:18 am
Try stay near ship 50 on the cap and attack red 75 as initial orders or when the cap arrives.

Also every-time should not be used in a case like this.  A repeating when would be fine and may solve the problem.  So something more advanced would be

when
--num-ships-in-battle
--->0
--->red
--clear goals
--->beta
-->add-goal
---->ai-stay-near
-----><cap>
---->89
repeat 999999 delay 1

when
--num-ships-in-battle
---> > 0
--->red
--clear goals
--->beta
-->add-goal
---->ai-chase
----->red
---->89
repeat 999999 delay 1



Title: Re: remove-goal
Post by: Rodo on May 12, 2009, 06:36:53 am
You can also try making two sexps, one for the times when RED is far away from the cap ship like

when (repeat 99999)
 >
  distance
    -RED
    -CAP SHIP
  XXXXXX
clear goals
 Alpha
add goal
 Alpha
 protect Cap ship (so it stays near it)

and another for when the wing is close enought


when (repeat 99999)
 <
  distance
    -RED
    -CAP SHIP
  XXXXXX
clear goals
 Alpha
add goal
 Alpha
 IA-chase RED


Title: Re: remove-goal
Post by: killface on May 12, 2009, 10:20:26 am

#1, it's not that Beta needs to stay near the cap ship...it's that they need to WAIT until Red is far enough away from the ENEMY cap ship before approaching, because the enemy cap ship has flak guns that will tear them up.

#2, I did try the repeating when, with the exact same effect. 

#3, Every time I involve a clear-goals sexp, the ships just wobble in space as their goals get repeatedly voided and added.  It's like they suffer from repetitive short-term memory loss.  "Let's go attack the-!....wait, what were we doing?...Oh yeah, let's get the bast-...wait, what now?"
Title: Re: remove-goal
Post by: karajorma on May 12, 2009, 10:56:40 am
Code: [Select]
// Goober5000
void sexp_remove_goal(int n)
{
}

Well it's pretty obvious why this SEXP doesn't work. :p
Title: Re: remove-goal
Post by: portej05 on May 12, 2009, 11:06:00 am
Is this as simple as the converse of sexp_add_goal?

i.e.
Code: [Select]
int num, sindex;
char *name;

Assert ( n >= 0 );
name = CTEXT(n);
sindex = CDR(n);

// first, look for ship name -- if found, then add ship goal.  else look for wing name -- if
// found, add wing goal
if ( (num = ship_name_lookup(name, 1)) != -1 )
ai_remove_ship_goal( sindex, AIG_TYPE_EVENT_SHIP, &(Ai_info[Ships[num].ai_index]) );

or is there more to it?

I can't find the equivalent of ai_remove_wing_goal - is there one?
Title: Re: remove-goal
Post by: killface on May 12, 2009, 12:03:40 pm

Forgive me my non-coder background, kara, but are you saying that this sexp has been disabled?  If so, why?  Any ideas for what I can do to work around it?
Title: Re: remove-goal
Post by: karajorma on May 12, 2009, 12:24:20 pm
I'm not saying that it's been disabled. I'm saying it doesn't even exist! There is code to make the SEXP appear and work in FRED and for it to load in correctly in FRED and FS2. However there is no code for the SEXP itself. When game tries to run the SEXP the code to tell it what to actually do is non-existent and it just skips it.

What's even stranger is that it appears that it has always been that way. TortoiseBlame seems to suggest that Goober added the SEXP in 2006 with no actual code. Unless he was doing that to replace a buggy earlier version for compatibility reasons I'm at a loss to explain it.


@portej05 - If there is such a function in the code I could add this SEXP in about 3-4 minutes flat. If not it's probably possible to make one. But I'd like to know what happened to the body of the original function first.
Title: Re: remove-goal
Post by: Angelus on May 12, 2009, 12:30:17 pm

#1, it's not that Beta needs to stay near the cap ship...it's that they need to WAIT until Red is far enough away from the ENEMY cap ship before approaching, because the enemy cap ship has flak guns that will tear them up.

me thinks:


everytime
-->
---distance
----red
----hostile capship
----10000
---clear-goal
----Beta
---add-goal
----Beta
-----ai-chase
------red
------89


everytime
--<
---distance
----red
----hostile capship
----10000
---clear-goal
----Beta
---add-goal
----Beta
-----ai-ignore       ( alternative is to add a goal where the wing strays near a friendly cap )
------red
------89
     

FRED's not working, so i'm not 100% sure.


Every time I involve a clear-goals sexp, the ships just wobble in space as their goals get repeatedly voided and added.  It's like they suffer from repetitive short-term memory loss.  "Let's go attack the-!....wait, what were we doing?...Oh yeah, let's get the bast-...wait, what now?"


 :lol:

dementia squad is awaiting orders...
Title: Re: remove-goal
Post by: killface on May 12, 2009, 12:50:50 pm

That is EXACTLY what I tried initially...but again, clear-goals sexp + everytime conditional doesn't seem to like working.  So I can't clear the goals, I can't remove the goals, I can't protect or unprotect wings instead of individual ships...I am stuck here.
Title: Re: remove-goal
Post by: Angelus on May 12, 2009, 12:55:13 pm
That's odd, i'm using the everytime conditional a lot, never had problems with it, but i'm giving orders to single ships not wings.
Try to disband the wing ( Beta ) and give the order to each ship in the wing instead of the wing.

Do you use the 3.6.10 RC2 build?
Title: Re: remove-goal
Post by: Rodo on May 12, 2009, 02:13:56 pm
also, could you post the sexp you are using, a screenshot could help us to see what might be wrong.
Title: Re: remove-goal
Post by: killface on May 12, 2009, 03:19:18 pm
It's RC1.  Thanks for pointing me to RC2, I was on vacation while that came out, but I'm not sure if it relates to this issue.

Here's the screenshot of the SEXP, please tell me if I've got anything wrong in there.

EDIT: Again, I believe it's the repeating nature of the every-time conditional (or the when with repeats) that is causing the problem, constantly voiding out Beta wing's goals and causing the ships to stutter in space.  But I don't know of any other way to address this scenario

[attachment deleted by ninja]
Title: Re: remove-goal
Post by: karajorma on May 12, 2009, 04:22:39 pm
I'm taking a good long look at this and I simply can't see why you're using the every-time SEXP in the first place. Not only is this not one of the special circumstances when every-time is needed but more importantly this is one of the times when using every-time is hindering you more than helping.

Furthermore you're using a completely unnecessary brute force solution to the problem. As a result you're wiping and changing the orders of ships around 70 times a second. No wonder the ships are acting schizophrenically.

A little finesse should help with this.

1) Use repeating when and make it a 1 or 2 second delay between repeats. There is no need really for any less than that and you could probably justify it being longer.
2) Use a string variable to store the current orders Beta is under. In the first event set it to ATTACK_RED. In the second event use string-equals to check if the value is ATTACK_RED and if it is (along with the stuff already in the trigger) set it to ATTACK_CRUISER. Now change the first event to add the condition that the variable must equal ATTACK_CRUISER and set that to your default value for the variable.

That should drastically cut the AI flailing on its own. If it doesn't I have some other ideas. :)
Title: Re: remove-goal
Post by: killface on May 12, 2009, 04:44:42 pm

I had tried using when with repeats, with the same result.  However, hadn't tried lengthening the repeat.  That's a good call.  Implementing all of the changes you outlined created an unexpected result.  Now Beta wing just sits there with "no orders".  Very confused re: why.  Here are the SEXPs as they read now.

[attachment deleted by ninja]
Title: Re: remove-goal
Post by: karajorma on May 12, 2009, 05:15:18 pm
You probably forgot to actually give some initial order to Beta. I don't know how your mission is set up but if red wing starts out less than 10,000m from the Typhon the game will never enter either of those two events.

Swapping the default value for the Variable would probably solve this too. The default value should reflect what you want Beta to be doing right at the start.
Title: Re: remove-goal
Post by: killface on May 12, 2009, 05:52:13 pm

Alright, that seemed to work...but ultimately I think I'm just going to redesign the layout of this mission to prevent near-capship encounters, rather than do this sexp setup for the 20+ fighter wings involved.  Also, it would be sweet if remove-goal could be made to live once more (if it ever did). 

Thanks all
Title: Re: remove-goal
Post by: General Battuta on May 12, 2009, 05:54:53 pm
...20+ fighter wings?

Simultaneously?
Title: Re: remove-goal
Post by: FUBAR-BDHR on May 12, 2009, 05:56:37 pm
You could use the same 2 events and make them when-argument any-of with the wings listed. 
Title: Re: remove-goal
Post by: killface on May 12, 2009, 06:01:10 pm
But each friendly wing has a separate enemy target.  How can I cram argument lists for BOTH friendly wings and enemy ships into one event?

It's a 30 on 30 rumble with cap-ships respawning the fighters, so 15 wings maximally at any time, to be exact.  The key is to keep AI fighters from trying to engage their targets while still too close to the cap ships, in which case they get raked with flak fire and other nastiness.
Title: Re: remove-goal
Post by: General Battuta on May 12, 2009, 06:10:39 pm
So each wing only has two fighters?
Title: Re: remove-goal
Post by: killface on May 12, 2009, 06:15:18 pm

30+30=60

60/15=4

15 wings, 4 fighters apiece. 

7 friendly wings and 8 enemy just to make it a bit more challenging, so technically it's a 28 on 32 rumble  ;)
Title: Re: remove-goal
Post by: portej05 on May 12, 2009, 08:31:28 pm
kara: The ai_remove_ship_goal exists, however, I couldn't find the equivalent for orders given to a wing.
Title: Re: remove-goal
Post by: General Battuta on May 12, 2009, 08:43:07 pm

30+30=60

60/15=4

15 wings, 4 fighters apiece. 

7 friendly wings and 8 enemy just to make it a bit more challenging, so technically it's a 28 on 32 rumble  ;)

Sorry, misread your post.
Title: Re: remove-goal
Post by: karajorma on May 13, 2009, 02:01:08 am
kara: The ai_remove_ship_goal exists, however, I couldn't find the equivalent for orders given to a wing.

Yeah. I know. Goober says that he never got around to actually making the SEXP work. With the wing function missing it will take a little longer than 4-5 minutes but it should be possible.
Title: Re: remove-goal
Post by: portej05 on May 13, 2009, 02:21:37 am
kara: Shall I take a crack at this one?
Title: Re: remove-goal
Post by: karajorma on May 13, 2009, 02:35:39 am
Feel free. When you're done, post a diff (just that fix) and I'll commit it for you.
Title: Re: remove-goal
Post by: killface on May 14, 2009, 07:44:39 pm

Thanks guys
Title: Re: remove-goal
Post by: portej05 on May 15, 2009, 01:09:14 am
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]
Title: Re: remove-goal
Post by: karajorma on May 15, 2009, 01:41:18 am
Downloaded. I'll take a look at this tonight.
Title: Re: remove-goal
Post by: portej05 on May 20, 2009, 08:04:40 pm
Ignore the change to ai.cpp - I don't think there is a problem there (wasn't sure about the order of operations with the postfix operator)
Title: Re: remove-goal
Post by: karajorma on May 21, 2009, 01:37:36 am
Damn. I forgot about this. I'll look at it in a little bit. And I agree with you about the ai.h change. It is unnecessary.