Hard Light Productions Forums

Modding, Mission Design, and Coding => FS2 Open Coding - The Source Code Project (SCP) => Topic started by: mjn.mixael on June 03, 2011, 01:00:05 am

Title: [Sexp Request] ai-scan-object
Post by: mjn.mixael on June 03, 2011, 01:00:05 am
I'd like to see an ai-scan-cargo sexp. Basically forcing the ai to fly within the scanning distance of the cargo/ship and stay there for the allotted scan time. Now I know you can fake this with waypoints and other trickery for cargo containers.. but what I have in mind would be useful for simulating wingmen scanning freighters and transports

Quote from: irc
<@MjnMixael> I'd like to see an ai-scan-cargo sexp. Basically forcing the ai to fly within the scanning distance of the cargo/ship and stay there for the allotted scan time. Now I know you can fake this with waypoints and other trickery for cargo containers.. but what I have in mind would be usefull for simulating wingmen scanning freighters and transports

<@Zacam-Away> Hmmm. Why simulate? Why not actually have it update the stack? Friendlies share data, so if a wingman "scans" something, that info should then become available to you as well without having you needing to scan it as well.

<@MjnMixael> well, yeah that could go with it

<@Zacam-Away> Unlike "Place of Chariots" where the cargo is "unscannable" (a hack cheat) it could start as "unscanned" or "unknown" and then actually dynamically update it's status whenever any-of "scans" it.

<@MjnMixael> aye, that would be quite useful, IMO

<@Zacam-Away> So, it would combine elements of "fly to" "within distance of" "play-dead" and a data list update to change the value of the $cargo element for the object it has "scanned"

<@MjnMixael> would "play-dead" work well with moving targets to be scanned?

<@Zacam-Away> Well, if the target is moving, then it would be ai-chase (with "no attack" orders if it's a neutral/hostile object)

<@MjnMixael> ah, yes, that's exactly the sexp I would like to see

<@Zacam-Away> So the question is, will it be "ai-scan-cargo" or "ai-scan-object"

<@Zacam-Away> I've never written a sexp though, but from what I gather of the existing sexp stacks, it should be possible to put the right combination of existing sexps into a container sexp called "ai-scan-object", the only factor there would then be if aicode needs any updating to handle the request which might be slightly more tricky.

Thoughts?
Title: Re: [Sexp Request] ai-scan-object
Post by: SypheDMar on June 03, 2011, 01:47:49 am
It'd be very useful to do this without any making a mess. I kinda wish there was a C-1-1-[scan Cargo] to tag along with this, too.
Title: Re: [Sexp Request] ai-scan-object
Post by: General Battuta on June 03, 2011, 09:01:52 am
Mjn, you know I think you're awesome, but I can't help but feel this is a lot of work for relatively little gain.
Title: Re: [Sexp Request] ai-scan-object
Post by: mjn.mixael on June 03, 2011, 09:20:41 am
Mjn, you know I think you're awesome, but I can't help but feel this is a lot of work for relatively little gain.

Oh I dunno. I can think of a crapton of uses for this kinda of thing. Regardless, I'd like to hear that from a coder familiar with the sexp system.

TBH, I'm surprised this kinda thing doesn't exist yet because it seems like a pretty simple way to make your wingmen feel more like -actual- wingmen... Seriously, wth do I have to do all the scanning of major vessels? There's FOUR of us, YOU do it. I'm tired of scanning, it's not fun! I'd rather blow stuff up while you do the boring job.
Title: Re: [Sexp Request] ai-scan-object
Post by: Black Wolf on June 03, 2011, 10:25:53 am
In most situations (though I'll grant not quite all) you can fake this acceptably by givig the AI attack orders and then locking their primaries and secondaries. Then update the cargo with sexps.
Title: Re: [Sexp Request] ai-scan-object
Post by: Angelus on June 03, 2011, 10:48:26 am
I support this request.
While you can do that with a bunch of SEXPs and Ai orders, it'd be easier to have one.
Title: Re: [Sexp Request] ai-scan-object
Post by: mjn.mixael on June 03, 2011, 10:51:07 am
In most situations (though I'll grant not quite all) you can fake this acceptably by givig the AI attack orders and then locking their primaries and secondaries. Then update the cargo with sexps.

You can get close, however the ai pretty much never flys within the scanning distance.. just close enough to shoot at it.
Title: Re: [Sexp Request] ai-scan-object
Post by: Colonol Dekker on June 03, 2011, 11:12:02 am
I support this as a SEXP request and a potential new Comms order :D
Title: Re: [Sexp Request] ai-scan-object
Post by: Goober5000 on June 03, 2011, 11:13:22 am
Here's the problem: what you think you're asking for isn't actually what you're asking for. :)  The sexp system is very simple, and it is quite easy to add a new sexp to both FSO and FRED.  Having the sexp do what you want, though, is another matter entirely.

The component pieces of this task are all already written, save one.  We have the following:

1) ai-waypoints-once
2) ai-play-dead / ai-stand-still
3) [a delay for X seconds]
4) set-cargo-scanned

Thus, it is perfectly possible to simulate an AI-controlled fighter scanning a cargo container, and in fact people have; it was done in TVWP's Unification War and a few other campaigns.

The missing link is the artificial intelligence for the fighter: the AI goal that will make it fly a certain route, without waypoints; face the cargo; avoid colliding with the cargo; sit still for a period of time regardless of whether it comes under fire; and then resume its previous goal.  And the AI system is famously difficult to work with.

This is the problem with a naive interpretation of the sexp system; it's easy to miss the fact that a sexp actually has to do something under the hood.  I think the worst sexp suggestion ever was when someone, in complete seriousness, asked for a sexp to enable multiple ship docking.  (This was still back when ships could only dock with one other ship.  For context, when I coded that feature, it involved re-implementing the entire docking section of the code and took two weeks of intensive programming, followed by a year of bugfixing.)
Title: Re: [Sexp Request] ai-scan-object
Post by: mjn.mixael on June 03, 2011, 11:16:35 am
Goober, your suggestion works except for moving targets. Didn't you read my post?
Title: Re: [Sexp Request] ai-scan-object
Post by: headdie on June 03, 2011, 11:25:36 am
waypoints and cap-speed
Title: Re: [Sexp Request] ai-scan-object
Post by: Angelus on June 03, 2011, 11:34:50 am
waypoints and cap-speed

The number of Waypoints is limited, and if you have alternate routes for the transports, you running out of waypoints very quickly.
Title: Re: [Sexp Request] ai-scan-object
Post by: headdie on June 03, 2011, 11:53:52 am
Shouldn't be too difficult to set up the waypaths so the fighter uses the transpot's waypoints and use the cap speed when the fighter hits the required distance, I am presuming the scanning will be part of a set piece, either way you will know when you want the set of scannings to start, when you want them to end and how long you want each scan to last.  Using guardian? sexp will stop the AI dynamic targeting the scanning fighter thus resetting the waypaths. 

I am not saying it is as simple as using a dedicated AI order but with a little mission planning you can overcome most difficulties using existing SEXPs and avoid any that cant be solved.
Title: Re: [Sexp Request] ai-scan-object
Post by: mjn.mixael on June 03, 2011, 12:08:27 pm
This is the most frustrating...

That system is still pretty ding-dang limited. Not to mention the idea of a mod getting C-1-1-[scan] ability is pretty stinkin exciting.

But whatever, there's been enough negative posts in this thread that it'll likely get ignored from here on out. Looks like I'm going to be seriously reading that sexp tutorial The_E posted...
Title: Re: [Sexp Request] ai-scan-object
Post by: Goober5000 on June 03, 2011, 04:26:28 pm
Goober, your suggestion works except for moving targets. Didn't you read my post?
Yes, I did.  I didn't catch the part about freighters and transports, but that doesn't make a material difference.  Just do what headdie recommended: have the fighter approach from the back and use the same waypoint the freighter/transport is using, and match the speed using cap-waypoint-speed.  I don't think AI fighters aren't affected by engine wash like players are, so you should be able to get close.


But whatever, there's been enough negative posts in this thread that it'll likely get ignored from here on out.
Excuse me, what?  The posts in this thread have been pretty positive, even if mostly misinformed.  And we're not ignoring the problem, we're telling you how to solve it using existing tools.

This problem is going to be difficult however you solve it.  But the difficulty of solving it using sexps and waypoints is significantly less than the difficulty of solving it by designing a new AI goal.

Writing the actual sexp is not the obstacle here.  In fact I could write you the ai-scan-object sexp itself in about 15 minutes; it just wouldn't do anything.  The meat of the problem is the AI.
Title: Re: [Sexp Request] ai-scan-object
Post by: Dragon on June 04, 2011, 05:58:48 am
Actually, AI is damaged by engine wash, it just doesn't care about it.
Title: Re: [Sexp Request] ai-scan-object
Post by: G0atmaster on June 04, 2011, 09:13:11 pm
Personally, this would solve one of the biggest gripes i've had about this game from the beginning. From a player's perspective, the fact that only Alpha 1 had the capability of scanning anything always ruined the game's immersion for me.  If you guys can do this, could you also conceivably write a 'Scan My Target' comm order option?
Title: Re: [Sexp Request] ai-scan-object
Post by: Trivial Psychic on June 04, 2011, 09:26:03 pm
Personally, this would solve one of the biggest gripes I've had about this game from the beginning. From a player's perspective, the fact that only Alpha 1 had the capability of scanning anything always ruined the game's immersion for me.  If you guys can do this, could you also conceivably write a 'Scan My Target' comm order option?

Writing the actual sexp is not the obstacle here.  In fact I could write you the ai-scan-object sexp itself in about 15 minutes; it just wouldn't do anything.  The meat of the problem is the AI.
Title: Re: [Sexp Request] ai-scan-object
Post by: jr2 on June 06, 2011, 12:43:21 pm
Is it possible to write a simple new AI that scans objects and takes minimal evasive manoevers (possibly rip some from the regular AI)?   If so, just switch control to the scanning AI and then back again after scan is complete.  Although it's probably way more complicated than that, I imagine...
Title: Re: [Sexp Request] ai-scan-object
Post by: General Battuta on June 06, 2011, 12:45:15 pm
Is it possible to write a simple new AI that scans objects and takes minimal evasive manoevers (possibly rip some from the regular AI)?   If so, just switch control to the scanning AI and then back again after scan is complete.  Although it's probably way more complicated than that, I imagine...

Anything with the AI code is really annoyingly complex.
Title: Re: [Sexp Request] ai-scan-object
Post by: Goober5000 on June 06, 2011, 10:31:01 pm
I should clarify my comments to emphasize that creating a new ai goal isn't impossible, just - as Battuta said - annoyingly complex.  There are a lot of things to keep track of, you'd be blazing a trail where few non-(http://www.hard-light.net/forums/Smileys/HLP/v.gif) coders have ventured before, and you'd run a risk of breaking something in the process.

But it's definitely solvable, especially if you broke the goal into several sub-problems to be solved one-at-a-time.  One way you could approach it is by essentially duplicating the "approach" part of the ai-chase code.  Instead of transitioning into the "attack" or "shoot" sub-goal, you'd just maintain a certain distance until the scan time elapsed.  The AI automatically breaks off an attack if it receives a certain amount of damage, so you could copy that logic without changes (albeit maybe adjusting for importance, since scanning something is less important than attacking a critical target).  But you'd also have to make sure the scan timestamp is reset if the fighter falls too far behind or moves outside of the "view cone" while it's in the middle of scanning.  And if the fighter "loses scan lock", you may find that it crashes around wildly before reacquiring it.
Title: Re: [Sexp Request] ai-scan-object
Post by: General Battuta on June 06, 2011, 10:39:31 pm
Mjn, you know I think you're awesome, but I can't help but feel this is a lot of work for relatively little gain.

Oh I dunno. I can think of a crapton of uses for this kinda of thing. Regardless, I'd like to hear that from a coder familiar with the sexp system.

I should clarify my comments to emphasize that creating a new ai goal isn't impossible, just - as Battuta said - annoyingly complex.  There are a lot of things to keep track of, you'd be blazing a trail where few non-(http://www.hard-light.net/forums/Smileys/HLP/v.gif) coders have ventured before, and you'd run a risk of breaking something in the process.

But it's definitely solvable, especially if you broke the goal into several sub-problems to be solved one-at-a-time.  One way you could approach it is by essentially duplicating the "approach" part of the ai-chase code.  Instead of transitioning into the "attack" or "shoot" sub-goal, you'd just maintain a certain distance until the scan time elapsed.  The AI automatically breaks off an attack if it receives a certain amount of damage, so you could copy that logic without changes (albeit maybe adjusting for importance, since scanning something is less important than attacking a critical target).  But you'd also have to make sure the scan timestamp is reset if the fighter falls too far behind or moves outside of the "view cone" while it's in the middle of scanning.  And if the fighter "loses scan lock", you may find that it crashes around wildly before reacquiring it.

Well there, you've got it!