Hard Light Productions Forums

Modding, Mission Design, and Coding => FS2 Open Coding - The Source Code Project (SCP) => Topic started by: AndrewofDoom on June 24, 2012, 01:25:09 pm

Title: [Request]: Subsystem flag for turrets to fire ON TARGET CENTER
Post by: AndrewofDoom on June 24, 2012, 01:25:09 pm
I've been having issues in my wonderful endeavor to bring a side scroller in FSO: the AI will try to shoot somewhere where the player can't even go.

To demonstrate my problem, Here's a video. (http://www.youtube.com/watch?v=ErNSQPhls7E) in here all the turrets and their firing points points are positioned at the same x coordinate as the player. If I sit still, I die like I so rightly should, but if I start moving around a lot, the AI starts trying to aim in places where I have no velocity (the x direction). I'm proposing a flag that will always have the AI aim for its target's center. You'd think the "fire on target" flag would do it, bit it seems it doesn't at all.

It would be really nice to have so I don't have to resort to absurd workarounds like having a huge $Detonation Radius flag.
Title: Re: [Request]: Subsystem flag for turrets to fire ON TARGET CENTER
Post by: headdie on June 24, 2012, 01:54:07 pm
Its an issue with 2d missions where the AI doesn't register that it can only operate in 2 dimensions which causes much weirdness.
Title: Re: [Request]: Subsystem flag for turrets to fire ON TARGET CENTER
Post by: Goober5000 on June 25, 2012, 12:02:31 am
As is so often the case, in this thread we have someone requesting something that has nothing to do with his actual problem. :p

The real issue here is that the 2d mission feature was implemented using an utter hack, and there is hardly any support for it in the actual code.  In fact, the only part of the 2d code that does anything meaningful is this, from object.cpp:


Code: [Select]
//2D MODE
//THIS IS A FREAKIN' HACK
//Do not let ship change position on Y axis
if(The_mission.flags & MISSION_FLAG_2D_MISSION)
{
angles old_angles, new_angles;
objp->pos.xyz.y = objp->last_pos.xyz.y;
vm_extract_angles_matrix(&old_angles, &objp->last_orient);
vm_extract_angles_matrix(&new_angles, &objp->orient);
new_angles.p = old_angles.p;
new_angles.b = old_angles.b;
//new_angles.h = old_angles.h;
vm_angles_2_matrix(&objp->orient, &new_angles);

//Phys stuff hack
new_angles.h = old_angles.h;
vm_angles_2_matrix(&objp->phys_info.last_rotmat, &new_angles);
objp->phys_info.vel.xyz.y = 0.0f;
objp->phys_info.desired_rotvel.xyz.x = 0;
objp->phys_info.desired_rotvel.xyz.z = 0;
objp->phys_info.desired_vel.xyz.y = 0.0f;
}

There isn't actually anything wrong with the AI here.  What is really going on is that the ship is moving along a certain vector, and the turrets are targeting a point where the ship is going to go.  But the ship never actually gets there, because the object movement code yanks it back to the origin of the Y axis.  In effect, it dodges out of the way of the weapon.

The proper way to fix the problem is to not yank the ship back to the origin of the Y axis after it moves, but rather to prevent it from moving along the Y axis in the first place.  This would involve editing the physics code to prevent any Y axis movement, instead of editing the object code to erase the Y axis movement after the fact.

I would recommend contacting the original author of the 2D mission feature and asking him if he would be able to fix this.


EDIT: see below
Title: Re: [Request]: Subsystem flag for turrets to fire ON TARGET CENTER
Post by: AndrewofDoom on June 25, 2012, 12:10:07 am
Problem is that I'm not even using that silly flag because it is a top down perspective. I want a side scroller, so I made a script that does just that (http://pastebin.com/XxLYCk2x), and implements a lot of additional features for this mod such as actual scrolling.
Title: Re: [Request]: Subsystem flag for turrets to fire ON TARGET CENTER
Post by: Goober5000 on June 25, 2012, 12:30:58 am
Well, that is fairly pertinent information that you should have included in your first post. :doubt:

The core point still stands, though.  We need to be sure that this is actually an AI problem before diving into the morass of AI code to implement a new flag.
Title: Re: [Request]: Subsystem flag for turrets to fire ON TARGET CENTER
Post by: Bobboau on June 25, 2012, 02:59:48 am
so how does your script work exactly? are you just clipping position and rotation? if so try doing the same to velocity and acceleration.
Title: Re: [Request]: Subsystem flag for turrets to fire ON TARGET CENTER
Post by: AndrewofDoom on June 25, 2012, 07:20:21 pm
so how does your script work exactly? are you just clipping position and rotation? if so try doing the same to velocity and acceleration.

Basically I set up a camera a little outside which then I add boundaries at fixed points. If the player moves tries to move outside these boundries, his position is forced to just a little before the boundary. The camera, and anything "slaved" to the scrolling system, moves at a rate of a user defined rate for one, two, and/or three axes times ba.getFrameTime (To keep consistency of the scrolling regardless of hardware. since there are those poor people who don't have monster rig that can run FSO at 60 FPS after all, I don't want them to get a different experience). By move I mean their position is forced to move at that rate every frame.

Weapons are unhindered by the system, unless they are the player's or targeting the player, in which case any and all of those projectiles are automatically "slaved" into the scrolling system as well to prevent this from happening (http://www.youtube.com/watch?v=SeXAxeZXFzE). Adding on to that, any of the projectiles fired by the player or targeting the player (Though I may need to add an exemption list to this seeing as those Deimoses in the video I just pointed to spend all their time outside of the boundaries) are immediately killed.

But anyway, I tried the same setup, except with a different camera angle. This is what I got.... (http://www.youtube.com/watch?v=O1v3B2i6_ag) It's very strange why that's happening.

Here's the script. (http://pastebin.com/N8n4m3wd)
Title: Re: [Request]: Subsystem flag for turrets to fire ON TARGET CENTER
Post by: Commander Zane on June 25, 2012, 07:33:15 pm
But anyway, I tried the same setup, except with a different camera angle. This is what I got.... (http://www.youtube.com/watch?v=O1v3B2i6_ag) It's very strange why that's happening.
Must be for Masochist difficulty. ;)
Title: Re: [Request]: Subsystem flag for turrets to fire ON TARGET CENTER
Post by: AndrewofDoom on June 25, 2012, 08:17:04 pm
But anyway, I tried the same setup, except with a different camera angle. This is what I got.... (http://www.youtube.com/watch?v=O1v3B2i6_ag) It's very strange why that's happening.
Must be for Masochist difficulty. ;)

I would call it "Valathil" difficult. :p

It seems after removing the $Detonation Radius attribute on the weapons, I get this (http://www.youtube.com/watch?v=RI3BMaBqzYk). I can sit around forever with no fear of being hit.

Turns out the perp may not be the AI, but rather collision detection is more likely.
Title: Re: [Request]: Subsystem flag for turrets to fire ON TARGET CENTER
Post by: AndrewofDoom on June 27, 2012, 12:40:02 am
After countless hours of working with SCP coders, I think we found the center of it all. (http://scp.indiegames.us/mantis/view.php?id=2673)

Kudos to Valathil for finding the bug.
Title: Re: [Request]: Subsystem flag for turrets to fire ON TARGET CENTER
Post by: Goober5000 on June 27, 2012, 12:44:22 am
High kudos. :yes:  Valathil gets a gold star.  And maybe a custom title, except he said he likes his current one.
Title: Re: [Request]: Subsystem flag for turrets to fire ON TARGET CENTER
Post by: jr2 on June 27, 2012, 03:57:39 am
After countless hours of working with SCP coders, I think we found the center of it all. (http://scp.indiegames.us/mantis/view.php?id=2673)

Kudos to Valathil for finding the bug.

Spoiler:
When the weapon being fired is slower than the ship's max velocity that the collision pair is being tested on, the collision pair is culled.

Nice.  :eek2:
Title: Re: [Request]: Subsystem flag for turrets to fire ON TARGET CENTER
Post by: pecenipicek on June 27, 2012, 04:00:34 am
After countless hours of working with SCP coders, I think we found the center of it all. (http://scp.indiegames.us/mantis/view.php?id=2673)

Kudos to Valathil for finding the bug.
is it just me or does it mean that blob turrets might get a bit more deadly now? :p
Title: Re: [Request]: Subsystem flag for turrets to fire ON TARGET CENTER
Post by: Spoon on June 27, 2012, 06:50:50 am
Leave it to mister wizard to find and destroy these kind of bugs  :yes:
Title: Re: [Request]: Subsystem flag for turrets to fire ON TARGET CENTER
Post by: Goober5000 on June 27, 2012, 02:16:20 pm
is it just me or does it mean that blob turrets might get a bit more deadly now? :p
Quite possibly.  This is one of the things that will need to be reviewed.
Title: Re: [Request]: Subsystem flag for turrets to fire ON TARGET CENTER
Post by: Spoon on June 27, 2012, 02:35:33 pm
The slow Terran huge turret has a velocity of 175. As far as I can think of, there is no retail fighter that can reach that speed.
Title: Re: [Request]: Subsystem flag for turrets to fire ON TARGET CENTER
Post by: jr2 on June 27, 2012, 02:45:40 pm
Ugh.  Sometimes I wonder if it wouldn't be more simple to fix all teh things! the way the realistically should have been had :v: managed to work all of the kinks out before release, then re-balance FS for the new bug-free code, and then maintain compatibility with the bug-free retail source that now doesn't implicitly rely on bugs in the original code.  If FS had been more popular, you might have had this anyways in the form of a v1.3, 1.4, 1.5, (Descent 3 had 1.4 official, 1.5 unofficial) etc patch that fixed the code and fixed the balance issues caused by their fixing the code.   Of course, then again, that might be really hard. 

But would it be worth it?  :nervous:
Title: Re: [Request]: Subsystem flag for turrets to fire ON TARGET CENTER
Post by: mjn.mixael on June 27, 2012, 08:29:41 pm
Ugh.  Sometimes I wonder if it wouldn't be more simple to fix all teh things! the way the realistically should have been had :v: managed to work all of the kinks out before release, then re-balance FS for the new bug-free code, and then maintain compatibility with the bug-free retail source that now doesn't implicitly rely on bugs in the original code.  If FS had been more popular, you might have had this anyways in the form of a v1.3, 1.4, 1.5, (Descent 3 had 1.4 official, 1.5 unofficial) etc patch that fixed the code and fixed the balance issues caused by their fixing the code.   Of course, then again, that might be really hard. 

But would it be worth it?  :nervous:

No, not worth it. Also it's totally unnecessary because...

The slow Terran huge turret has a velocity of 175. As far as I can think of, there is no retail fighter that can reach that speed.
Title: Re: [Request]: Subsystem flag for turrets to fire ON TARGET CENTER
Post by: Goober5000 on June 27, 2012, 10:17:20 pm
The slow Terran huge turret has a velocity of 175. As far as I can think of, there is no retail fighter that can reach that speed.

The Shivan Megafunk turret has a velocity of 120.  The PVF Horus has an Aburn Max Vel of 170.

So this will depend on whether the algorithm deals with actual speed or potential speed.  We may need to tie this to a mod.tbl setting.
Title: Re: [Request]: Subsystem flag for turrets to fire ON TARGET CENTER
Post by: Spoon on June 28, 2012, 06:19:01 am
I've tested it. A cain with nothing but megafunk turrets and a Horus.
Every shot was a solid hit. At max engine power the Horus reaches 'only' 110. Going the max AB speed of 170, each bolt I could run into would not phase through. They all hit.

Fun fact, a single megafunk shot to the hull of the Horus will instantgib it, the Horus is in fact made of paper. Especially fun when the game decides that its time to ignore the shield collision again and just let the shot pass through the shield, right onto the hull.
Title: Re: [Request]: Subsystem flag for turrets to fire ON TARGET CENTER
Post by: Dragon on June 28, 2012, 06:52:38 am
Seems like it's calculated either off normal max speed or max overclock speed. So, patching this shouldn't be an issue in retail (and most mods, in fact).
Title: Re: [Request]: Subsystem flag for turrets to fire ON TARGET CENTER
Post by: Goober5000 on June 28, 2012, 04:04:50 pm
What did you test, Spoon?  The fix, or one of the builds before the fix?
Title: Re: [Request]: Subsystem flag for turrets to fire ON TARGET CENTER
Post by: Spoon on June 28, 2012, 05:18:58 pm
I dont have any builds that contain the fix for this.
Also, testiing it with a build that contained the fix would make my effort kinda moot, wouldnt it?
Title: Re: [Request]: Subsystem flag for turrets to fire ON TARGET CENTER
Post by: Goober5000 on June 28, 2012, 08:23:16 pm
That's why I asked. :)

EDIT: So this is good news; this means no mod.tbl setting is required.  (And it also means that this can go into 3.6.14.)  I just need to check one final thing with Valathil and then we can commit it.
Title: Re: [Request]: Subsystem flag for turrets to fire ON TARGET CENTER
Post by: Spoon on June 29, 2012, 06:16:00 am
Cool  :yes:
Title: Re: [Request]: Subsystem flag for turrets to fire ON TARGET CENTER
Post by: Droid803 on June 29, 2012, 12:18:05 pm
This does break one of the missions in DE.
Ironically using the same ship/weapons as in that video...

DAMMIT ANDREW. :P
Title: Re: [Request]: Subsystem flag for turrets to fire ON TARGET CENTER
Post by: AndrewofDoom on June 29, 2012, 06:34:08 pm
You most make an update Droid.
Title: Re: [Request]: Subsystem flag for turrets to fire ON TARGET CENTER
Post by: Dragon on June 29, 2012, 06:47:46 pm
Well, it could use a few tweaks.
Title: Re: [Request]: Subsystem flag for turrets to fire ON TARGET CENTER
Post by: Goober5000 on June 29, 2012, 10:07:19 pm
This does break one of the missions in DE.
Hmm?
Title: Re: [Request]: Subsystem flag for turrets to fire ON TARGET CENTER
Post by: Droid803 on July 01, 2012, 03:49:23 pm
Just a balance thing, easy to fix.
Don't worry about it.
Title: Re: [Request]: Subsystem flag for turrets to fire ON TARGET CENTER
Post by: Goober5000 on July 01, 2012, 07:38:17 pm
What breaks, though?  I need to know if it would affect other mods.
Title: Re: [Request]: Subsystem flag for turrets to fire ON TARGET CENTER
Post by: Droid803 on July 01, 2012, 09:43:59 pm
Its just that the weapons thrown at the player were balanced around the fact that most of them weren't hitting because they were too slow, so their damage is way too high. I didn't know that they weren't hitting, so I just thought that they didn't do enough damage...

Shouldn't be a problem for any other mod. :P

It was just me being dumb and not noticing that the projectiles were passing harmlessly through instead of doing insufficient damage, and I guess all the testers assumed that it was by design (they were basically just distractions).
Title: Re: [Request]: Subsystem flag for turrets to fire ON TARGET CENTER
Post by: Goober5000 on July 02, 2012, 02:14:24 am
Gotcha.
Title: Re: [Request]: Subsystem flag for turrets to fire ON TARGET CENTER
Post by: Dragon on July 02, 2012, 04:32:14 am
Note, it's likely that testers didn't notice. Nobody complained, and I didn't notice it too, so I'd asume no one was aware of this bug.
Title: Re: [Request]: Subsystem flag for turrets to fire ON TARGET CENTER
Post by: assasing123 on July 03, 2012, 11:37:41 am
i can tell i certainly was not aware of this bug, tho it explains a LOT! of the behavior i was having where some photon torpedos being used as primaries sometimes never did damage and sometimes would insta gib a cruiser