Hard Light Productions Forums

Modding, Mission Design, and Coding => FS2 Open Coding - The Source Code Project (SCP) => Topic started by: Mastadon on May 21, 2012, 06:29:04 am

Title: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: Mastadon on May 21, 2012, 06:29:04 am
Hi everyone.

I had a bit of inspiration today and extended the "target my attacker" key so that it cycles through all of the ships that are attacking you rather than just the closest attacker---much like the "target nearest hostile" key works. This change allows you to, for example, ignore the Aten-class cruiser hanging 500m off your starboard bow w/ a destroyed weapons subsystem and see the wing of Thoths that are 800m away and trying to gun you down.

I've attached both a patch that is good against r8811 and have also attached a demo mission to help highlight the changes I've made. This patch probably breaks the cardinal rule, but I'm not sure how to go about doing anything about it, so I'll just submit the patch as-is and let the coding community give me feedback. One thing to also note: for my extensions, I utilized a mix of OO-style programming, but I'm not sure how well that will flow with a program that is primarily written in a procedural fashion. If an SCP member could give me guidance as to how to best structure and format my code so that it causes the least amount of trouble for the SCP community, that would be appreciated.

Thanks in advance!

[attachment deleted by a ninja]
Title: Re: Patch submission: "target my attacker" now cycles through all attackers
Post by: X3N0-Life-Form on May 21, 2012, 06:45:54 am
After spending a couple minutes trying to figure out something appropriate, I believe I'm gonna go with a simple "hell yes".
So, here it is:

Hell yeah \o/ .
Title: Re: Patch submission: "target my attacker" now cycles through all attackers
Post by: niffiwan on May 21, 2012, 07:14:22 am
Umm - your patch removes a number of recent commits from trunk, perhaps from around 8800 onwards?  :D  Could you please redo your patch to just include your targeting changes?

As for the patch itself, cool idea, I'd definitely find that feature useful  :yes:
Title: Re: Patch submission: "target my attacker" now cycles through all attackers
Post by: Iss Mneur on May 21, 2012, 08:42:27 am
Well, I am going to pick it apart line by line:
- Why was the style of the comments for HugGaugeMessages::render changed from doxygen style to something else.  Why did HugGaugeTalkingHead lose it documentation?
- All directories and code files should have lowercase names.
- Style changes should be a separate patch done under its own merit.
- You are adding an empty file? (RoundRobinSelection)
- Please use doxygen style comments.
- Please be careful of unnecessary changes to the project files and if you are changing compilation options, it should also be a separate patch under its own merit (that is changes other than adding removing files).
- I have no idea what to did to the target names in Freespace2.vcxproj.
- Please document the structure esct (or move its documentation with it).
- All files should have a newline at the end.

I do not have a problem with the use of more object orientated code because in this case it doesn't really stand out, but the general rule in that regard is to just go with what is already there.
Title: Re: Patch submission: "target my attacker" now cycles through all attackers
Post by: Capt_Thunder on May 21, 2012, 08:44:11 am
Thank you. This has been needed for a long time.
Title: Re: Patch submission: "target my attacker" now cycles through all attackers
Post by: Dragon on May 21, 2012, 08:58:02 am
I agree, this would be a great change. I think it could be on by default, it doesn't break anything retail and should improve gameplay in a subtle, yet noticeable way.
Title: Re: Patch submission: "target my attacker" now cycles through all attackers
Post by: Mastadon on May 21, 2012, 02:45:06 pm
Well, I am going to pick it apart line by line:
- Why was the style of the comments for HugGaugeMessages::render changed from doxygen style to something else.  Why did HugGaugeTalkingHead lose it documentation?
- All directories and code files should have lowercase names.
- Style changes should be a separate patch done under its own merit.
- You are adding an empty file? (RoundRobinSelection)
- Please use doxygen style comments.
- Please be careful of unnecessary changes to the project files and if you are changing compilation options, it should also be a separate patch under its own merit (that is changes other than adding removing files).
- I have no idea what to did to the target names in Freespace2.vcxproj.
- Please document the structure esct (or move its documentation with it).
- All files should have a newline at the end.

I do not have a problem with the use of more object orientated code because in this case it doesn't really stand out, but the general rule in that regard is to just go with what is already there.


Thanks for the in-depth feedback Iss Mneur: it is appreciated. I will try and answer your feedback in the order in which you gave it:
  - I overlayed a mercurial repository over my working copy of fs2_open and have been mirroring changes back into the "default" branch (mercurial's equivalent to "trunk"), keeping my various patches in separate branches. What happened here is I forgot to merge the default branch into my tragetting_key_fix branch, resulting a bunch of superfluous changes when I created the svn patch. I've since corrected that oversight.
  - I've adjusted my file naming conventions to be "two_word_name" compliant.
  - I'll change the comments to doxygen-style in a later update...possibly tonight.
  - Pragmatically speaking, I did nothing of consequence to the Freespace2.vcxproj. Internally, I tacked on a "_targetting_key_fix"suffix to the FS2 open binaries generated so that I can easily keep track of my various patches and their compiled products. I've since stripped out any "changes" to the Freespace2.vcxproj.
  - I really am not sure what the esct structure does. I found it in the hudtarget.cpp file and needed to use it elsewhere, so I moved it to it's own file. I can do an svn blame on hudtarget.cpp to try and find out where the esct struct came from, but judging from the code I edited, it was probably in the original :v: codebase.


[attachment deleted by a ninja]
Title: Re: Patch submission: "target my attacker" now cycles through all attackers
Post by: The E on May 21, 2012, 02:51:59 pm
Quote
I found it in the hudtarget.cpp file and needed to use it elsewhere, so I moved it to it's own file.

Why not move it to a preexisting header file, like hud.h or pstypes.h (which is a header file defining quite a few base structs like vec3d)?
Title: Re: Patch submission: "target my attacker" now cycles through all attackers
Post by: Mastadon on May 21, 2012, 04:53:00 pm
Quote
I found it in the hudtarget.cpp file and needed to use it elsewhere, so I moved it to it's own file.

Why not move it to a preexisting header file, like hud.h or pstypes.h (which is a header file defining quite a few base structs like vec3d)?

Because at the time, I wasn't sure where to put such a struct, so I defaulted to my standard practice of declaring and / or defining one class / struct / enum per file. However, when I get to work on triaging the other issues that have been raised about this patch, I'll move the esct struct over to hudtarget.h, since the struct was originally defined in hudtarget.cpp and it would make the most sense to move it to it's associated header file, where type definitions belong.
Title: Re: Patch submission: "target my attacker" now cycles through all attackers
Post by: Goober5000 on May 21, 2012, 09:37:57 pm
Excellent work Mastadon, and your efforts are appreciated. :yes:  Keep this up and we might make you an official SCP member. ;)

I've attached both a patch that is good against r8811 and have also attached a demo mission to help highlight the changes I've made. This patch probably breaks the cardinal rule, but I'm not sure how to go about doing anything about it, so I'll just submit the patch as-is and let the coding community give me feedback. One thing to also note: for my extensions, I utilized a mix of OO-style programming, but I'm not sure how well that will flow with a program that is primarily written in a procedural fashion. If an SCP member could give me guidance as to how to best structure and format my code so that it causes the least amount of trouble for the SCP community, that would be appreciated.

In answer to your questions...

1) The cardinal rule, as you have read, is that gameplay on FSO should be the same as gameplay on FS2.  Generally this applies to things like ship/weapon balance and AI, not so much the interface.  This new behavior ought to be acceptable, as it sounds very much like the existing "target nearest hostile" key behavior.  (I'm speaking in theory as I haven't tested it yet.)

1a) When coding new features that affect balance and AI, the retail behavior is usually made a special case of the new behavior.  For example, ship-to-ship docking is now a special case of multiple ship docking.

2) The rule of thumb is the modifications and edits to existing features should be written using the same techniques and styles.  (It is jarring when an otherwise consistent bit of code has a sudden change midway through.)  But if you design a new feature, or significantly rewrite an existing feature, you can change it to your own style.

3) Commits and patches should usually focus on one thing, or one small group of closely related things.  Cramming a bunch of unrelated changes into a single commit is heavily discouraged as it introduced lots of bugs during SCP's earlier days.

4) Be cognizant of potential pitfalls for other platforms.  Mixed-case file names will trip you up on Linux.

5) What IssMneur said.
Title: Re: Patch submission: "target my attacker" now cycles through all attackers
Post by: Mastadon on May 24, 2012, 03:20:09 pm
Ok. I believe I've made all the changes Iss Mneur and Goober5000 recommended. I've attached the current version to the first post, so as to avoid confusion as to which version of the patch is the current version.
Title: Re: Patch submission: "target my attacker" now cycles through all attackers
Post by: Goober5000 on May 25, 2012, 12:13:30 am
Cool.  I think this is an excellent candidate for integration with trunk... all it needs is a code review by a SCP member.  (To be fair, we should probably also wait for the 3.6.14 release.)

Bump this (and your other patch thread) in a week or so to remind people about it. :)
Title: Re: Patch submission: "target my attacker" now cycles through all attackers
Post by: Mastadon on May 25, 2012, 12:41:50 am
Will do.  :yes:
Title: Re: Patch submission: "target my attacker" now cycles through all attackers
Post by: Iss Mneur on May 25, 2012, 01:44:27 am
The patch itself appears to be sound, just some points of style that are bothering me before I put this in trunk.

Regarding lines 187-189 of the patch.  The design of evaluate_ship_as_closest_target is a very common idiom in the FSO code base.  I also agree that it makes learning the code hard and can hide and/or introduce bugs into other code. However because the idiom is so common in the code base you do get used to it (as much of a cop out as that sounds).

Okay, now to pick on the style:

Hard wrap your lines at 80 chars (that is, use the enter key to wrap the lines).  I have a 19in monitor and some of them still run off the the screen when my diff viewer is full screen, I shudder to think what would happen in the the tiny window for code that results when debugging.

If you don't know how to set your favourite editor to at least show a line at 80 columns I am sure one of us SCPers (or google) would be able to help you.  If your favourite editor cannot show a line at 80 columns, I suggest you get a better editor.

Please fix the extraneous whitespace (and inconsistent use of whitespace) for examples:

Personally I am not a fan of littering names all over the code because it implies ownership of the code.  However, it is rather common in our code base, but it is put at the end of the comment not the beginning.

Finally, you haven't included a commit message. :D  Preferably a <60 char summary or a <60 char summary with a longer explanation after.
Title: Re: Patch submission: "target my attacker" now cycles through all attackers
Post by: Goober5000 on May 25, 2012, 10:01:38 pm
Regarding lines 187-189 of the patch.  The design of evaluate_ship_as_closest_target is a very common idiom in the FSO code base.  I also agree that it makes learning the code hard and can hide and/or introduce bugs into other code. However because the idiom is so common in the code base you do get used to it (as much of a cop out as that sounds).
I looked at lines 187-189 (by themselves, since I don't have time ATM to review the whole patch).  I agree that the design of evaluate_ship_as_closest_target is very common throughout the code and should generally be kept, but the specific issue that Mastadon raises (i.e. comparing a float to anything, even FLT_MAX) is salient.  Making the one specific change of adding a bool return type would be a good design change IMO.

Quote
Personally I am not a fan of littering names all over the code because it implies ownership of the code.  However, it is rather common in our code base, but it is put at the end of the comment not the beginning.
Personally, my reason for leaving names is not to claim ownership, but to say "this is who to yell at if something breaks". :D  However, beware the case where an unknown person rewrites the code, accidentally adds a bug, and neglects to change the name in the comment.  This has happened more than once. :shaking:
Title: Re: Patch submission: "target my attacker" now cycles through all attackers
Post by: Iss Mneur on May 25, 2012, 10:31:07 pm
However, beware the case where an unknown person rewrites the code, accidentally adds a bug, and neglects to change the name in the comment.  This has happened more than once. :shaking:
Indeed.

This is why we have svn blame or svn praise. You cannot lie to the version control system. No relying on the honour system that way.
Title: Re: Patch submission: "target my attacker" now cycles through all attackers
Post by: chief1983 on May 27, 2012, 01:37:47 pm
You _can_, however, inadvertently claim code via whitespace or typo refactoring, which is why I tend to discourage that kind of refactoring once code is in place.   Makes for a confusing history.  Get it right the first time :P
Title: Re: Patch submission: "target my attacker" now cycles through all attackers
Post by: Mastadon on May 28, 2012, 09:22:12 am
Ok, I've gone ahead and fixed the various code formatting issues and have replaced the patch w/ version 4 of the cycle attakers patch.


Here is a commit message that summarizes the changes this patch makes to the codebase, complete with a one-line summary:

"Target closest attacker" cycles through all attackers; misc code cleanup.
  -- Changed "target closest attacker" command to cycle through the other
       baddies gunning for you by pressing the "target closest attacker"
       command repeatedly.
    -- The new functionality behaves similarly to the "target closest hostile" key.
  -- Fixed bug identified where pressing the "target attacking ship" button
       targets a non-attacking-but-hostile ship (Mantis issue #2656).
    -- This is a bug also present in FSO 3.6.14 RC5.
  -- Moved the esct (or, the "Evaluate Ship as Closest Target" struct) to
       hudtarget.h, where a type declaration belongs.
  -- Moved the documenting comments for hud_target_closest() to be just above
      the function definition.
    -- Also, converted these commments to doxygen format.
Title: Re: Patch submission: "target my attacker" now cycles through all attackers
Post by: Goober5000 on May 28, 2012, 09:45:37 am
It seems as though you conflated "Target closest hostile" and "Target closest attacker" in that comment...
Title: Re: Patch submission: "target my attacker" now cycles through all attackers
Post by: Mastadon on May 28, 2012, 10:04:58 am
It seems as though you conflated "Target closest hostile" and "Target closest attacker" in that comment...

D'oh! I must have made that error when I originally wrote the local commit log entry about a week ago. In any case, I've fixed that oversight.
Title: Re: Patch submission: "target my attacker" now cycles through all attackers
Post by: Goober5000 on May 28, 2012, 03:41:31 pm
:yes:
Title: Re: Patch submission: "target my attacker" now cycles through all attackers
Post by: Mastadon on May 31, 2012, 04:34:42 pm
 :bump:
Title: Re: Patch submission: "target my attacker" now cycles through all attackers
Post by: Iss Mneur on May 31, 2012, 07:44:10 pm
Committed in revision: 8841

Mastatdon or a moderator: Please edit the post OP to contain [Committed 8841].
Title: Re: Patch submission: "target my attacker" now cycles through all attackers
Post by: Goober5000 on May 31, 2012, 09:41:56 pm
Eh, whatever happened to waiting until 3.6.14 was out? :p
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: Iss Mneur on May 31, 2012, 10:21:04 pm
Just wanted to do it before it I forgot about it.  :doubt:
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: Goober5000 on May 31, 2012, 10:50:58 pm
Oh, I certainly agree that we shouldn't forget about it... that's why I asked Mastadon to keep bumping it. :)  But don't worry, it's not a hard-and-fast rule.  We're not doing an official code freeze like we've done in the past.
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: Iss Mneur on May 31, 2012, 11:02:25 pm
We're not doing an official code freeze like we've done in the past.
Yeah, no kidding.  At the pace we are going on this RC (I know, some of that is my fault, but look we just got wxLauncher 0.9.0 out (http://www.hard-light.net/forums/index.php?topic=67950.msg1341695#msg1341695) yesterday :D), we will need to do another release right after just to get the bugs out of trunk before the pilot code goes in.
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: Goober5000 on May 31, 2012, 11:18:04 pm
Perhaps.  I'm open to ways of increasing coder participation.
Title: Re: Patch submission: "target my attacker" now cycles through all attackers
Post by: Mastadon on June 01, 2012, 01:28:46 pm
Committed in revision: 8841

Mastatdon or a moderator: Please edit the post OP to contain [Committed 8841].

Thank you for committing my patch Iss Mneur!
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: mjn.mixael on June 05, 2012, 10:48:53 am
Something with this patch has changed how Auto Target works. Auto Target used to select the nearest hostile, but now it always selects nearest hostile attacker. Which seems a bit odd given that for years I've been used to it selecting the next closest valid target for me to aim my weapons at.

I have a specific issue with this in that I've just played a mission where the nearest hostiles aren't targetting me, but the hostiles that are targetting me are still 10k out and are completely irrelevant to my current goals.
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: Goober5000 on June 05, 2012, 11:13:28 am
Mantis 2659 is tracking this:
http://scp.indiegames.us/mantis/view.php?id=2659
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: Mastadon on June 05, 2012, 02:01:25 pm
While I haven't had a chance just yet to do a more thorough code review of my modifications, I suspect that the cause of the trouble is that the hud_target_closest() function now filters out any object not attacking the player if we're looking for someone attacking a specific object, such as the player. If that is true, then one solution to the problem would be to add a default parameter to the hud_target_closest method that specifies a maximum distance to consider a target a threat. Another option would be to automatically filter out attackers that are beyond a certain distance. :v: originally wrote some commented out code that does just that by default for non-players, but the MIN_DISTANCE_TO_CONSIDER_THREAT macro they use is only set to 1500, which is just too short to be effective in FS2 with weapons such as the Prometheus S, Maxim, Tornado, and Trebuchet.


BTW, I like the new title someone bestowed upon me!  :cool:

Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: Goober5000 on June 05, 2012, 03:16:00 pm
Glad to hear it. :D
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: Sushi on June 05, 2012, 03:33:46 pm
I thought the problem was that the auto-target was emulating "target closest hostile" (i.e. target my attacker) instead of "target closest enemy." Seems like it should be straightforward to just make the auto-target call whatever code the latter uses.
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: Mastadon on June 05, 2012, 04:48:26 pm
I thought the problem was that the auto-target was emulating "target closest hostile" (i.e. target my attacker) instead of "target closest enemy." Seems like it should be straightforward to just make the auto-target call whatever code the latter uses.

Well, not quite. The problem is that the target closest attacker code now actually finds targets that are attacking you and the auto-targeting code first searches for and attempts to target any ship that is both attacking you and is targetable:

Code: [Select]
// ...
int valid_team_mask = iff_get_attackee_mask(Player_ship->team);

// try target closest ship attacking player
if ( Player_ai->target_objnum == -1 ) {
hud_target_closest(valid_team_mask, OBJ_INDEX(Player_obj), FALSE, TRUE );
}

// if none, try targeting closest hostile fighter/bomber
if ( Player_ai->target_objnum == -1 ) { //-V581
hud_target_closest(valid_team_mask, -1, FALSE, TRUE);
}

// No fighter/bombers exists, so go ahead an target the closest hostile
if ( Player_ai->target_objnum == -1 ) { //-V581
hud_target_closest(valid_team_mask, -1, FALSE);
}

// um, ok.  Try targeting asteroids that are on a collision course for an escort ship
if ( Player_ai->target_objnum == -1 ) { //-V581
asteroid_target_closest_danger();
}

In a nutshell, what will need to happen is that hud_target_closest() will need to be rewritten so that it either (1) limits targetting to objects within a certain distance or (2) returns the distance from the newly targetted object. If option 2 is taken, the call to hud_target_closest for ships attacking the player would need to be rewritten such that it doesn't make a targetting sound. That being said, I still think that option 1 would be the ideal way to go, as adding a default parameter to hud_target_closest has the lowest probability of causing additional UFOs  (Unintentional Feature Offering) in the code.
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: Sushi on June 05, 2012, 11:35:53 pm
The problem with a distance is that it is completely arbitrary. IMHO we should just have autotarget pick the closest enemy. That's basically what it did before (it may have tried to find the closest ship attacking the player, but since that code wasn't working correctly anyway, that doesn't have much of an effect).

So my suggestion is to just delete this whole if statement.

Code: [Select]
// try target closest ship attacking player
if ( Player_ai->target_objnum == -1 ) {
hud_target_closest(valid_team_mask, OBJ_INDEX(Player_obj), FALSE, TRUE );
}
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: mjn.mixael on June 06, 2012, 12:22:38 am
Yes, that's my thoughts exactly. A distance check is, as you said, totally arbitrary.
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: Mastadon on June 06, 2012, 01:49:48 am
I guess the big question is: when an event where auto-targeting kicks in (for example, your target is destroyed or warps out), would you rather (1) get the next target attacking you if they aren't too much farther away from you than the absolute closest target or (2) just get the next closet bad guy? I'll open up a poll so we can get some more concrete numbers to make a decision on.
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: mjn.mixael on June 06, 2012, 08:42:58 am
Well, retail was always just the next closest hostile target.. so that's what it needs to be. If anything you could create a game_settings.tbl flag and let mods choose between the two with the default being retail behavior.
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: karajorma on June 06, 2012, 09:01:03 am
I don't think in cases like this it needs to stay exactly the same as retail. We are allowed to improve gameplay, what we can't do is rebalance it.

I definitely don't think we need a table setting for this. Pick whichever one works best and go with that. That said, I'm leaning towards next closest not because it's retail behaviour but because I feel the behaviour of the "Auto-target hostile" and "Target hostile" should match.
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: mjn.mixael on June 06, 2012, 09:08:28 am
I actually disagree that it messes with balance. In the example of the mission I was playing, it took me much longer to find the next useful hostile target after everytime I killed a hostile ship. That precious time allowed those craft to do a noticeable amount more damage to the ship I was protecting than before.
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: karajorma on June 06, 2012, 09:32:18 am
Ah, in that case we should use the retail version for that reason too.
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: Mastadon on June 08, 2012, 05:37:50 am
Since a majority of the voters want option 2, I have gone ahead and created a patch that removes the code that attempts to auto-target ships that are attacking you first.

[attachment deleted by a ninja]
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: mjn.mixael on June 08, 2012, 09:08:03 am
Yes that works like I expected. 'H' targets nearest hostile. 'R' targets nearest attcking hostile. 'Auto Target' targets nearest hostile.
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: Sushi on June 08, 2012, 09:32:30 am
Patch looks good to me.
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: CommanderDJ on June 08, 2012, 10:17:57 am
approval++;
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: Mastadon on June 08, 2012, 10:27:09 am
Shouldn't that be ++approval;

 ;)
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: CommanderDJ on June 08, 2012, 08:29:05 pm
Shouldn't that be ++approval;

 ;)
Shouldn't that have been a question? :P

Seriously though, no one's ever really explained the difference to me. Is there a meaningful change in speed or something?
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: Sushi on June 08, 2012, 08:34:04 pm
Patch committed in r/8848. Thanks, Mastadon!
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: Iss Mneur on June 08, 2012, 08:48:07 pm
Seriously though, no one's ever really explained the difference to me. Is there a meaningful change in speed or something?
In theory a prefix operator is faster because no data was copied (if you recall, a postfix operator returns the current value and does the increment afterwords).

In practice, a compiler will catch that sort of thing even at the lowest optimization levels, especially when the postfix operator is called in a void context (ie. its not going to assign the return value to anything, this is one reason why a copy constructor or an assignment operator should not change data just copy it).
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: Mastadon on June 08, 2012, 09:18:12 pm
Shouldn't that be ++approval;

 ;)
Shouldn't that have been a question? :P

Seriously though, no one's ever really explained the difference to me. Is there a meaningful change in speed or something?

Like Iss Mneur said, the big logical difference in the prefix verses postfix increment operators is in what gets returned by the operator. With the prefix increment and decrement operators, the variable is incremented / decremented first and the resulting value of the variable is returned by the operator. In contrast, the postfix increment and decrement operators return the current value of the variable first, then increment the value of the variable.

In terms of performance, I've also herd that the prefix variants can be faster than their postfix counterparts, but in practice I have had a hard time proving that claim.
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: Tomo on June 11, 2012, 04:06:37 pm
There is a difference in the speed of assembly, however there's no difference in the speed of the C/C++ because all modern* compilers will optimise any difference out.

As Mastadon said, there is a difference in result though:
Code: [Select]
x = 0;
y = ++x;

x = 0;
z = x++;
After this snippet, y != z. Surprise!

I use the prefix version of increment almost exclusively.
It's primarily a style thing - if I'm using the result, I never want the value from before the increment because if I did, I'd assign it on a separate line for improved readability.

- Equally, the above snippet is fairly bad form because it may not be immediately clear what happens.

* Last decade, if not longer. You're not going to be using a compiler that doesn't.
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: Goober5000 on July 01, 2012, 01:42:14 am
:bump:

With all the discussion on what the hostiles are actually doing, I don't think anyone paid attention to the other thing Mastadon suggested, the bit where the target key could ignore the Aten with a destroyed weapon system.  Because that actually has a direct bearing on this bug (http://scp.indiegames.us/mantis/view.php?id=2154) in Mantis.  Mastadon, have you added any filtering functionality where ships with no functioning guns or turrets are not targeted?
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: Mastadon on July 01, 2012, 03:43:46 pm
I'm not sure if I have added additional filtering functionality to the effect that ships w/ no functioning guns or turrets are not targeted. If I have time, I'll take a look tomorrow...maybe late today if I have the time.


EDIT: Darn, looks like my time just got eaten up through Friday with work and church. I'll see if I can get to this Friday.
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: Swifty on August 14, 2012, 02:24:23 pm
Question about this patch. Did this patch completely remove the ability of Target Closest Attacker to target closest hostiles if there are no present attackers?

Perhaps this patch made Target Closest Attacker now work as advertised but I feel that was done at expense of the command's original functionality which was still pretty useful.

If possible, does anyone mind if I also re-add the capability for this command to target closest hostile if there are no attackers present? I mean, if you don't have any present attackers, the command doesn't really do anything now. Might as well fill the gap.
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: mjn.mixael on August 14, 2012, 02:37:13 pm
I would prefer that fix, actually.
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: Mastadon on August 14, 2012, 03:44:00 pm
Question about this patch. Did this patch completely remove the ability of Target Closest Attacker to target closest hostiles if there are no present attackers?

Perhaps this patch made Target Closest Attacker now work as advertised but I feel that was done at expense of the command's original functionality which was still pretty useful.

If possible, does anyone mind if I also re-add the capability for this command to target closest hostile if there are no attackers present? I mean, if you don't have any present attackers, the command doesn't really do anything now. Might as well fill the gap.

Actually, the target closest attacker doing nothing is a feature if nobody's actually attacking you because it tells you that nobody's attacking you. If we have the target closest attacker feature then target the next closest hostile if nobody is attacking you, you have no way of knowing whether or not the hostile targeted is either attacking you or just another potential victim.
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: Swifty on August 14, 2012, 04:35:47 pm
But the hollow attacker arrow that goes around the reticle should be information enough. I don't see why it doing nothing when you have no attackers is a feature when closest hostile can be context dependent. I'm trying to make a compromise here between original retail functionality and the current new functionality.
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: Iss Mneur on August 14, 2012, 05:26:17 pm
What is wrong with using the "Target Hostile" key when you are not being attacked?
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: Swifty on August 14, 2012, 05:29:29 pm
Because you're cycling through hostiles. That key doesn't immediately give you the closest hostile exclusively. You could already be in the middle of the list of enemy targets cycled. What's wrong with a fallback behavior that emulates the original retail functionality?
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: redsniper on August 15, 2012, 08:28:29 am
Because you're cycling through hostiles. That key doesn't immediately give you the closest hostile exclusively. You could already be in the middle of the list of enemy targets cycled. What's wrong with a fallback behavior that emulates the original retail functionality?

Wait what? Pressing H cycles through targets by distance right? Giving you the closest hostile is exactly what it does. That said, I wouldn't mind having R do the same thing when there's no attacker.
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: Dragon on August 15, 2012, 08:33:30 am
Another thing is that "R" is much closer to your fingers than "H" on a standard keyboard. Pressing it is a lot faster than "H", and it matters a lot in tense dogfights, especially if you're escorting something. I don't play multi, but I guess it matters even more against a human.
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: jr2 on August 15, 2012, 11:46:19 am
1) You can hit H with your left pointer finger if you want, really.  Try it a few times and see.

2) So, since the key that cycles through Escort ships doesn't do anything with not ships in escort list, have it cycle through all friendly capships, right?  I mean, the fact that your escort list is empty should tell you that there are no escortable ships... And since the target next turret key doesn't do anything after the turrets are destroyed, it should target the next nearest hostile capship and begin cycling those turrets, right?  The targetted ship  changing should tell you that there's no turrets left....

:nervous:

3) Now, imagine a mission where you are  not to attack a hostile unless it's attacking you.  Now this key gets all jacked up, cause it looks like they are all attacking you unless you notice the threat indicator missing.
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: Kobrar44 on August 15, 2012, 01:00:23 pm
U no get this? Retail behaviour is changed now. It is a big deal. If something is changed, it should be kept as close tor retail as possible. While having R cycle through attackers it should also cycle through hostiles as it did in retail. So that some noobs don't happily press R and discover that this function works completely different now.
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: jr2 on August 15, 2012, 01:10:28 pm
Yeah.  Well... personally, I think there's a difference in keeping compatibility with retail and treating it as some sort of holy grail to be cloned.  Yes I know that's heresy, but anyways.

One could  argue that supporting higher resolutions than retail allows users to see ships further out and affects balance.  :rolleyes:
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: Kobrar44 on August 15, 2012, 02:09:05 pm

One could  argue that supporting higher resolutions than retail allows users to see ships further out and affects balance.  :rolleyes:
That would be FoV.
Higher resolutions are feature. This is a replacement for old function which is something we should be really careful about.
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: Dragon on August 15, 2012, 02:46:10 pm
2) So, since the key that cycles through Escort ships doesn't do anything with not ships in escort list, have it cycle through all friendly capships, right?  I mean, the fact that your escort list is empty should tell you that there are no escortable ships... And since the target next turret key doesn't do anything after the turrets are destroyed, it should target the next nearest hostile capship and begin cycling those turrets, right?  The targetted ship  changing should tell you that there's no turrets left....
You're thinking in a bit wrong direction here, but the general idea is good. Turret cycling key should switch to regular subsystems when no turrets are left, that'd be more logical. For the escort, cycling through friendly capships might be a good suggestion, but I'd rather go with something more like "nearest capship". It'd be good for quick orientation. Or, it could cycle through hotkeyed formations. Overall, this might become a rarely used, but convenient feature.
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: Goober5000 on August 15, 2012, 10:35:18 pm
U no get this? Retail behaviour is changed now. It is a big deal. If something is changed, it should be kept as close tor retail as possible. While having R cycle through attackers it should also cycle through hostiles as it did in retail. So that some noobs don't happily press R and discover that this function works completely different now.

Kobrar44 has a good point, and my first inclination was to agree with him, but on the other hand, this new behavior could be considered the expected behavior.  Suppose that if you pressed the E key to select something on the escort list, and the escort list was empty.  It wouldn't make sense to target a friendly capital ship just because you might be escorting it.

So, following that line of thinking, wouldn't it make more sense to just play the "invalid keypress" error buzz, instead of targeting a hostile ship?  Because if no ship is actually attacking you, then you should know about it so that you can reprioritize your gameplay.
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: SypheDMar on August 15, 2012, 11:33:09 pm
That's what I'd like to have happened. It makes a lot of sense, especially when I can't tell if I'm being chased.
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: Mongoose on August 16, 2012, 12:45:10 am
Yeah, I'm not sure why that command would have targeted the nearest hostile in the first place.
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: Swifty on August 16, 2012, 01:59:23 am
U no get this? Retail behaviour is changed now. It is a big deal. If something is changed, it should be kept as close tor retail as possible. While having R cycle through attackers it should also cycle through hostiles as it did in retail. So that some noobs don't happily press R and discover that this function works completely different now.

Kobrar44 has a good point, and my first inclination was to agree with him, but on the other hand, this new behavior could be considered the expected behavior.  Suppose that if you pressed the E key to select something on the escort list, and the escort list was empty.  It wouldn't make sense to target a friendly capital ship just because you might be escorting it.

So, following that line of thinking, wouldn't it make more sense to just play the "invalid keypress" error buzz, instead of targeting a hostile ship?  Because if no ship is actually attacking you, then you should know about it so that you can reprioritize your gameplay.

All right, so be it then. I guess I'm just going to add a new command that targets the closest hostile so we can get that original functionality back without interfering with the correct functionality.
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: mjn.mixael on August 16, 2012, 06:53:40 am
Wait, I must be misunderstanding. We can already target the closest hostile with 'H'... what's this new command?
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: jr2 on August 16, 2012, 12:19:45 pm
Wait, I must be misunderstanding. We can already target the closest hostile with 'H'... what's this new command?

That's why I was not so happy about combining other keys into something multifunction.  Unless you're making hit so that you can play with an XBOX360 controller, then it would make sense.
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: Swifty on August 16, 2012, 02:22:25 pm
Wait, I must be misunderstanding. We can already target the closest hostile with 'H'... what's this new command?

H cycles through hostiles sorted by distance. It won't give you the closest hostile unless you're already not targetting another hostile. Pressing H will just get you a closer target, but not necessarily the closest if you're already targetting a farther hostile. Semantically the H key is "Target Closer Hostile". There is no "Target Closest Hostile" at the moment.
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: MatthTheGeek on August 16, 2012, 02:24:39 pm
Unless I'm wrong, H circles through enemies only if you repeatedly hit it. If you wait a couple of seconds H will target the closest hostile even if you had another hostile target targeted.
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: chief1983 on August 16, 2012, 02:42:17 pm
Pretty sure MatthTheGeek is right, the cycling resets to the closest hostile after a few seconds.
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: jr2 on August 16, 2012, 02:43:31 pm
What exactly is the timeout?  Or is that difficult to check?
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: Commander Zane on August 16, 2012, 02:44:52 pm
One, two seconds?
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: niffiwan on August 16, 2012, 04:43:07 pm
I think this is the reset value, so 1.5 secs...

Code: (code/hud/hudtarget.cpp) [Select]
#define TL_RESET            1500
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: Swifty on August 17, 2012, 01:25:48 am
That seems rather arcane. How would any new player know that you'd have to wait 1.5 seconds to get the closest enemy target when the command itself just says "Target Next Closest Hostile Ship"? That's about as "Xbox 360 context sensitive" as my previous suggestion. :P

In light of this, I still feel that "Target Closest Hostile" needs to be it's own key command for clarity. The 1.5 second wait seems even more hokey than having Target Closest Attacker falling back Target Closest Hostile when no attackers are present.
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: Mastadon on August 17, 2012, 05:26:06 am
That seems rather arcane. How would any new player know that you'd have to wait 1.5 seconds to get the closest enemy target when the command itself just says "Target Next Closest Hostile Ship"? That's about as "Xbox 360 context sensitive" as my previous suggestion. :P

In light of this, I still feel that "Target Closest Hostile" needs to be it's own key command for clarity. The 1.5 second wait seems even more hokey than having Target Closest Attacker falling back Target Closest Hostile when no attackers are present.


I don't think it's rather arcane at all. Rather, I believe it reflects :v:'s intent to allow players to select the closest hostile or, if they so desire, the next closest / farthest hostile if they press the key within a certain amount of time so as to indicate player intent to keep shuffling targets. I don't really see the benefit to having a specialized targeting key that just targets the closest hostile when I can just wait 1.5 seconds to get the closest hostile.

Besides, in a dogfight scenario, I usually don't care about which potential victim is actually closest as much as I do about helping him become life-long friends with one of my missiles...
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: MatthTheGeek on August 17, 2012, 05:28:39 am
That seems rather arcane. How would any new player know that you'd have to wait 1.5 seconds to get the closest enemy target when the command itself just says "Target Next Closest Hostile Ship"?
Back when I was a new player that was as instinctive to me as it gets. And until this thread, I never thought it should or even could have been otherwise.
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: redsniper on August 17, 2012, 08:21:51 am
Yeah I think I figured out the behavior of the H key pretty quickly when I first started playing FS and I never realized it was a problem for anyone until now...
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: jr2 on August 17, 2012, 08:27:10 am
I just wish there was a way to reduce the wait to, say, 0.5 or 0.7 seconds.  When desperately shooting down hordes of enemy bombers with fighters flying everywhere, 1.5 seconds is an eternity.  Although, when it's that thick, you usually don't have to worry about finding a target until you clear out the pocket of bogeys around you and are looking for the next pocket to decimate, hopefully before they manage to implant their bombs into the convoy you're escorting.
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: MatthTheGeek on August 17, 2012, 08:40:07 am
If you really want to improve the current targetting system, instead of f*cking around with the parts that work as intended and are perfectly fine for 99% players, one thing I think would really benefit to everyone would be a "Target closest bomber". Not the one we already have, but one that would ignore bombs, just cycle through bombers.
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: jr2 on August 17, 2012, 09:04:21 am
Maybe make that Alt+B?
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: MatthTheGeek on August 17, 2012, 09:10:35 am
The key is irrelevant, you can change it anyway. It could even simply be unbound by default as far as I'm concerned.
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: chief1983 on August 17, 2012, 10:14:58 am
With the new pilot code, that should be a possibility.
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: Swifty on August 17, 2012, 11:59:13 am
It looks like adding that additional key isn't going to cause problems. I'll also throw in the target closest bomber command.
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: mjn.mixael on August 17, 2012, 12:10:07 pm
I know this doesn't really belong in this topic.. but since we are talking about adding keybinds here it is anyway. (Feel free to split discussion if need be.)

What do people think of adding 2 or 3 null keybinds. Keys that are assigned to an action called 'Special Action' or something, but don't do anything by default. The idea here is to add a couple keybinds for FREDers to use so we don't have to keep stealing the mutliplayer keys all the time.
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: Spoon on August 17, 2012, 12:40:20 pm
I know this doesn't really belong in this topic.. but since we are talking about adding keybinds here it is anyway. (Feel free to split discussion if need be.)

What do people think of adding 2 or 3 null keybinds. Keys that are assigned to an action called 'Special Action' or something, but don't do anything by default. The idea here is to add a couple keybinds for FREDers to use so we don't have to keep stealing the mutliplayer keys all the time.
I support this!
Poor Alt-X is getting so abused right now...
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: Mastadon on August 17, 2012, 06:27:42 pm
If you really want to improve the current targetting system, instead of f*cking around with the parts that work as intended and are perfectly fine for 99% players, one thing I think would really benefit to everyone would be a "Target closest bomber". Not the one we already have, but one that would ignore bombs, just cycle through bombers.

I'm already working on that (http://www.hard-light.net/forums/index.php?topic=81066), I just need to stop procrastinating and finish what I started! :blah:
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: MatthTheGeek on August 18, 2012, 02:33:10 am
No, what you're doing is modifying the existing key behaviour. Which is exactly what I don't want. I haven't spent years mastering FS controls just so you could steal them away, thank you very much.

What I was asking was adding a new key so we have more options without changing the existing behaviour.
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: Mastadon on August 18, 2012, 04:02:46 am
Well, "stealing away the FS controls" as you put it is one part of the patch, but another part of the patch is adding a specific key to only cycle through enemy bombers.

On the "stealing" note, I really don't see what the big problem is. Seriously, what is so twisted and wrong about wanting to find the bomb(er) is closest to you first rather than the one that was created by the Freespace engine first? The Freespace controls as they were designed were never meant to handle the kind of bombing action you see in a number of popular mods. They are, to be perfectly blunt, broken in the case of fleet defense scenarios because there is no way to prioritize which bomb(er) gets targeted and, in a fleet defense scenario, you need to have such a prioritization to successfully find and destroy enemy bomb(ers).

Having said all of that, it might be possible to make it such that either users or mission designers can turn on the "bomb(er) prioritization" feature and have the FS engine default to the original behavior if neither the user nor the mission designer wants the feature turned on. I wonder if this could be set as a table option of some sort...
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: MatthTheGeek on August 18, 2012, 04:21:43 am
Nah, actually that works for me. I misunderstood what your patch was doing. Tis all good. Thanks for the clarification.
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: karajorma on August 18, 2012, 04:34:57 am
Please don't give us yet another pointless table entry we have to support for all of eternity!

You're right, plain and simple. The system as designed is quite clearly broken and targeting the first created bomb not only is clearly the result of a bad programming kludge it also is counter-intuitive to all the other targeting keys which work exactly as you'd fix the bomb key.
Title: Re: Patch submission: "target my attacker" now cycles through all attackers [r8841]
Post by: chief1983 on August 23, 2012, 03:41:37 pm
This thread definitely got some emotional responses from some people, and the commits here are already giving me a headache.  I've spent the better part of the day trying to sort out what code between 8841, 8842, 8843, and 8848 was actually needed to fix _just_ the bug in #2659, and what was related to this new feature.  I still can't tell for certain what does what.  Additionally, this new feature does seem to be digging into the skin of some people, as I do agree that this behavior change and its adverse side affects are modifying retail behavior (even if for the better).  But given the fact that the next release will be the new pilot code, which will allow adding all sorts of new keypresses, I'm now wondering if it would be better to back this change out entirely for the time being, and have it rewritten as a new command, instead of modifying an existing command.  As it stands, I can't even be certain that .14 is working as intended, because 8848 was the only commit backported, and I'm not sure that was the commit that was supposed to fix 2659 or not (which was filed by Mastadon before his feature patch even hit trunk).  I think everyone would be fine with it only cycling attackers, and not all hostiles, as long as the current behavior of the default R action is maintained.  Because currently, this would make it such that there is no key you could spam in the heat of battle and be _certain_ it's the closest attacker (or thing to spew missiles at).  Getting rid of that one key is bound to bother some people, so I think this is likely to be a good compromise, only made possible with the new pilot code.