Hard Light Productions Forums

Modding, Mission Design, and Coding => FS2 Open Coding - The Source Code Project (SCP) => Topic started by: arisian on August 06, 2009, 10:31:12 am

Title: changing BANK_WHEN_TURN macro to a command line flag
Post by: arisian on August 06, 2009, 10:31:12 am
Hi guys,

So first off, let me apologize for doing this on the forum rather than through Mantis, but I seem to be having the same difficulty that several others have, in that my attempts to register with Mantis do not result in me being sent a confirmation e-mail (I've tried several different usernames and e-mail accounts at this point).

To make up for this,  rather than simply requesting the feature I want, I've gone ahead and added it.  I've attached the output of 'svn diff' (run in the code/ directory), so it should be easy to use 'patch' to apply it.  It needs further testing, however; it seems to do what I expect on my system (x86_64, Gentoo Linux, nVidia openGL drivers, 3-axis joystick), but I haven't had a chance to test it on other platforms.  

The feature is essentially a migration of a #defined macro to a run-time option by using a command line flag.  The macro in question is defined (or commented out) on line 499 of code/physics/physics.cpp, and is called BANK_WHEN_TURN.  This macro controls whether applying yaw controls induces roll.  The default behavior is that a small roll is induced by yaw.  Back in the day, I didn't mind this "feature" in, eg. the early Wing Commander games, when I only had a 2 axis joystick.  Now, however, I have a 3 axis joystick, and it was annoying to me that pitch and roll controls were "pure" controls, but yaw was not.  It's possible to alter this behavior by changing the #define mentioned above, but that's a compile-time change, which is really not ideal.  Moving it to a command line flag is much friendlier, and shouldn't really affect performance at all, since it effectively just adds one extra multiply operation to an already complex algebraic formula.

This is my first time working with this codebase, but the command line parameter handling seems to be implemented in a way which makes the introduction of new flags pretty simple; I've added the new flag "-no_bank_when_turn" as a "Gameplay" modification, given it a description, and provided a link to a (currently non-extant) part of the command line reference on the wiki.  If anyone has any questions about what I've done or why, please feel free to reply to this post, or PM me.  


[attachment deleted by Tolwyn]
Title: Re: changing BANK_WHEN_TURN macro to a command line flag
Post by: General Battuta on August 06, 2009, 10:43:42 am
Should be an AI profiles flag, not command line. But good idea!
Title: Re: changing BANK_WHEN_TURN macro to a command line flag
Post by: arisian on August 06, 2009, 10:48:13 am
It's possible I'm misunderstanding what the AI Profiles flags are, since this is my first time mucking around in the SCP codebase, but my intent was to add a feature that changed the handling of *player* ships, not AI ships, which is why I made it a command line flag.  The default behavior is still what it always was, but this flag makes 3-axis joystick control more natural, particularly when yaw is mapped to the Z axis.  If I'm missing something, please let me know, and I'll try to move my fix to a more appropriate location within the code.
Title: Re: changing BANK_WHEN_TURN macro to a command line flag
Post by: Sushi on August 06, 2009, 12:53:48 pm
First off, I applaud the attitude of "I'll fix this myself!".  :yes: Welcome to HLP! Expect a beam soon from someone soon...

The only problem I see with your patch is that it affects AI behavior as well. I like the idea of making it so that the player ship NEVER banks when turning, but the AI should still do so. In fact, you can already control the amount of bank in the turn on a per-ship basis:
http://hard-light.net/wiki/index.php/Ships.tbl#.24Banking_Constant:

So, there's really two things at play here:

1. Bank-when-turn applying to all ships (player and AI). This is already handlable via ships.tbl.

2. The option to not bank when turning for player ships only. This is, I think, what you're after, and IMO a command-line option for this makes a lot of sense (it's a player preference sort of thing). The only disadvantage I see is that some modders may want to control how much banking goes into a turn differently for different ships, to give them a unique feel. A flag like this would override that behavior, and possibly upset some modders. Maybe. :) Personally, I think it's a great idea, but you need to modify it to only affect the player ship. Fix that and the patch gets a :yes: from me. :D


EDIT: I just read your last post, making me feel pretty silly. :) Clearly your intention is player-only, but I was reading the patch and it doesn't seem to have that restriction... I'll look again more closely.

EDIT2: OK, this looks like it WILL apply to all ships (it's NOT exclusive to the player). physics_read_flying_controls is called by AI as well. So just fix it so that it only turns off bank when dealing with the player ship.
Title: Re: changing BANK_WHEN_TURN macro to a command line flag
Post by: arisian on August 06, 2009, 01:55:56 pm
It looks like you're right, the way I've done it will apply to all ships.  Again, I'm not that familiar with the codebase; I'll take another crack at it later this evening.  If anyone has pointers about easy ways to distinguish player ships from non-player ships, or other ideas about where the best place to implement this change would be, I'd be happy to hear about it; otherwise, I'll just poke around until I find something.
Title: Re: changing BANK_WHEN_TURN macro to a command line flag
Post by: Sushi on August 06, 2009, 01:59:57 pm
It looks like you're right, the way I've done it will apply to all ships.  Again, I'm not that familiar with the codebase; I'll take another crack at it later this evening.  If anyone has pointers about easy ways to distinguish player ships from non-player ships, or other ideas about where the best place to implement this change would be, I'd be happy to hear about it; otherwise, I'll just poke around until I find something.

OF_PLAYER_SHIP is probably the flag you're looking for. Search through the codebase to see how it's used, I'm sure you can figure it out. :D
Title: Re: changing BANK_WHEN_TURN macro to a command line flag
Post by: chief1983 on August 06, 2009, 03:09:55 pm
If it were done via ai_profiles then a simple mod could be set up to work essentially with retail or any other mod.  Then it wouldn't be usable during validated multi matches without breaking validation, which should be the case, since it changes the playing ground for some players.
Title: Re: changing BANK_WHEN_TURN macro to a command line flag
Post by: arisian on August 06, 2009, 07:45:10 pm
Okay, I've made another patch that moves the changes into playercontrol.cpp, where it should only affect player ships not under AI control.  As before, it seems to work for me, though I make no claim to have tested extensively yet.  I'm still not sure I understand the ai_profiles thing people are talking about; ai_profiles.cpp doesn't seem to have any references to the banking constant.  Any further feedback would be welcome.

[attachment deleted by Tolwyn]
Title: Re: changing BANK_WHEN_TURN macro to a command line flag
Post by: chief1983 on August 06, 2009, 07:49:48 pm
It has nothing to do with it _yet_, we're trying to say it shouldn't be a command line option, but a new flag enabled in the ai_profiles table.  That table controls various changes in the engine to the retail behavior.  Really it would be ideal if a mod could allow it to be one or the other or force it to be set a certain way.
Title: Re: changing BANK_WHEN_TURN macro to a command line flag
Post by: General Battuta on August 06, 2009, 08:07:10 pm
Exactly.
Title: Re: changing BANK_WHEN_TURN macro to a command line flag
Post by: arisian on August 06, 2009, 09:46:25 pm
Ahh, I see what you're saying now.  What I've done so far satisfies my personal desires (as a casual single-player gamer), but if you think it'll be a problem for multiplayer or for modding, I'll just hold onto the patches for my personal use.

I think I now understand what you mean about ai_profiles.  I guess I need to learn more about actual mods; I'm perfectly comfortable with C++ code, but I've never actually looked at a FSO mod, I'm just a casual player.  Where would I look for the .tbl files with AI parameters in them?  I assume they're hidden inside the .vp archives or something, since there don't seem to be any standard files with that extension.  Are there tools for opening those things under Linux?  All the modding tools I've found so seem to be Win32 only...

I was able to make the changes I wanted with a small number of relatively minor changes by opting for "simple and not likely to break everything" over "best possible way of doing it if I was starting from scratch".  If you think that the "right" way of doing this is a more major project, I should probably step back and let someone who's more familiar with the codebase handle it.
Title: Re: changing BANK_WHEN_TURN macro to a command line flag
Post by: The E on August 06, 2009, 10:07:11 pm
To open .vps under Linux, there's maja, which is Java based. Any of the other tools should work under wine. Get them here: http://www.freespacemods.net/download.php?list.51
Title: Re: changing BANK_WHEN_TURN macro to a command line flag
Post by: Aardwolf on August 06, 2009, 10:18:40 pm
:welcome:

Also, your username looks similar to someone I know, and the fact that you're apparently also on linux has piqued my curiosity... you wouldn't happen to be Patrick Drummond, would you?
Title: Re: changing BANK_WHEN_TURN macro to a command line flag
Post by: Sushi on August 07, 2009, 10:25:52 am
I think I now understand what you mean about ai_profiles.  I guess I need to learn more about actual mods; I'm perfectly comfortable with C++ code, but I've never actually looked at a FSO mod, I'm just a casual player.  Where would I look for the .tbl files with AI parameters in them? 

Correct, they're in VP files under data/tables. Check out mods like Blue Planet: I'm pretty sure they have a custom AI_Profiles tbl file (and it's an awesome mod totally worth playing anyway).

If you do decide to make this work as an AI_Profiles flag (which isn't too hard) then there are ways to make a minimod that you can use alone or in combination with any other mod. Basically, you would make the code change so that it is triggered via AI_Profiles, then create something like arisian-aip.tbm with the change, stick it in a custom mod folder, then add that mod to the secondarylist (in mod.ini) of any other mods you happen to play. If you're interested, I & others will be happy to walk you through it.

I was able to make the changes I wanted with a small number of relatively minor changes by opting for "simple and not likely to break everything" over "best possible way of doing it if I was starting from scratch".  If you think that the "right" way of doing this is a more major project, I should probably step back and let someone who's more familiar with the codebase handle it.

No, your attitude is fine. :) Simple and nonbreaking is good, and this is a minor change that IMO doesn't need a huge project. Don't be shy about suggesting/contributing ideas and code, though! It's a good idea, and IMO still worth doing. Just learn how AI_Profiles work and move the option from the command-line to AI Profiles, and I think we're probably good.

Also, feel free to hang out on the SCP's IRC channel: #scp on irc.esper.net. Faster feedback! :)
Title: Re: changing BANK_WHEN_TURN macro to a command line flag
Post by: arisian on August 07, 2009, 06:08:26 pm
Okay, thanks for the advice.  I'll open up the .vp files and take a crack at implementing this in ai_profiles, though it may take me a few days to get back around to this project.  I'll post a patch for ai_profiles when I'm done.
Title: Re: changing BANK_WHEN_TURN macro to a command line flag
Post by: arisian on August 11, 2009, 03:51:41 pm
So, I've added some code that I *think* should work in ai_profiles, but I don't have any examples of a mod that actually uses an ai_profiles.tbl (blue planet doesn't seem to).  Anyone know of any mods that actually use ai_profiles.tbl so I can make sure I didn't break things?

Oh, and @Aardwolf, no, my name is Ben Mitchell (www.cs.jhu.edu/~ben).  The name 'arisian' is a reference to a classic space opera (http://en.wikipedia.org/wiki/Lensman_series).
Title: Re: changing BANK_WHEN_TURN macro to a command line flag
Post by: Sushi on August 11, 2009, 04:01:36 pm
So, I've added some code that I *think* should work in ai_profiles, but I don't have any examples of a mod that actually uses an ai_profiles.tbl (blue planet doesn't seem to).  Anyone know of any mods that actually use ai_profiles.tbl so I can make sure I didn't break things?

Oh, and @Aardwolf, no, my name is Ben Mitchell (www.cs.jhu.edu/~ben).  The name 'arisian' is a reference to a classic space opera (http://en.wikipedia.org/wiki/Lensman_series).

Blue Planet does in fact use ai_profiles.tbl, but it's hidden inside the VP. :) You'll need one of the various tools for opening VP files to get to it (I use qvp). I probably should have mentioned that sooner. :D Once you find it and extract it, just put it in freespace2/blueplanet/data/tables and edit away. This works because any files NOT in a VP archive will override the ones that are.
Title: Re: changing BANK_WHEN_TURN macro to a command line flag
Post by: arisian on August 11, 2009, 04:31:40 pm
Hmm, it doesn't seem to be in the copy of the blueplanet.vp that I have; I had figured out where it should be, it's just not there in the version of the .vp file that I have.  Maybe I need to find a newer version of the mod...if you have a link to the version you're using, I'd appreciate it.
Title: Re: changing BANK_WHEN_TURN macro to a command line flag
Post by: The E on August 11, 2009, 04:36:01 pm
Blue Planet forum.
BP 3.6.10 thread.
Title: Re: changing BANK_WHEN_TURN macro to a command line flag
Post by: Sushi on August 12, 2009, 11:58:39 am
Link (http://www.hard-light.net/forums/index.php/topic,61406.0.html) (this IS the internet :p)
Title: Re: changing BANK_WHEN_TURN macro to a command line flag
Post by: arisian on August 24, 2009, 04:12:03 pm
Hi guys, sorry about the delay, but I got busy with the stuff I actually get payed for...anyway, I've got a patch here that implements the banking multiplier in ai_profiles.  The trouble with this is (as it took me some time to figure out), most missions have the string "$AI Profile: FS2 RETAIL" in them somewhere.  The presence of that statement effectively means that no custom ai profiles will ever be used, because you can't modify the FS2 RETAIL profile with an ai_profiles.tbl, and any other profile you put stuff in will just get ignored.  This is true even of the Blueplanet mod missions; while they did, in fact, create a custom ai_profiles.tbl with a "BP" profile, and set "BP" as the default profile, every single  mission file then has "$AI Profile: FS2 RETAIL" in it, so the custom ai_profiles.tbl never actually affects anything.  By going in and editing the mission files to use the "BP" profile, and then adding the "$Delta Bank Multiplier" line to ai_profiles.tbl, you can get the behavior I originally wanted.

So, what I've done in this patch will allow mod builders to play with the banking multiplier, if they know what they're doing.  But so far as I can see, there's no way to have a custom ai_profiles.tbl in a tacked-on personal "mini-mod" to disable banking, because everything uses the "FS2 RETAIL" profile anyway.  I suppose we could modify things to ignore the "$AI Profile" statement in missions and always use the "default" profile, but that would make it impossible to have mission-specific profiles.  Alternatively, since I suspect that FRED is automatically generating the $AI Profile: FS2 RETAIL" statement, someone could modify FRED to not do that.  In the mean time, however, I don't see a way to use the ai_profiles patch I've made as a way to let me actually alter the behavior of anything without unpacking and editing all the mission files in a mod (which I should *not* have to do).

Again, there's a lot of code here that I'm not real familiar with, so if there's something obvious I'm missing, I'd appreciate it if someone would let me know.  Otherwise, it looks like you need to hand-edit mission files for ai_profiles.tbl to actually do anything.



[attachment deleted by Tolwyn]
Title: Re: changing BANK_WHEN_TURN macro to a command line flag
Post by: chief1983 on August 24, 2009, 04:35:26 pm
I thought you could modify the FS2 Retail entry with a +nocreate command or whatever.
Title: Re: changing BANK_WHEN_TURN macro to a command line flag
Post by: Sushi on August 24, 2009, 06:17:27 pm
You can. Arisian, meet the .tbm (modular table) file.  (http://www.hard-light.net/wiki/index.php/Tbm):D

You can create a .tbm "min-mod" that will affect FS2_RETAIL.

I'll have a look at your code a bit later.
Title: Re: changing BANK_WHEN_TURN macro to a command line flag
Post by: arisian on August 24, 2009, 10:17:23 pm
Aha, yes, I missed the "modular extensible" tables.  Thanks for the link!  Now the code patch from my last post does exactly what I want, when used in conjunction with an XXX-aip.tbm that modifies the "FS2 RETAIL" profile to have "$Delta Bank Multiplier: 0, 0, 0, 0, 0".  No need to modify mission files, or anything else.  Thanks for the help guys; sorry it took me so long to see what you were all getting at.  Whenever you get around to looking at the code patch, let me know whether you think this version looks good or if you have other suggestions.
Title: Re: changing BANK_WHEN_TURN macro to a command line flag
Post by: General Battuta on August 25, 2009, 09:34:17 am
I think you misunderstand something, arisian. It's easy to set a custom AI profile in FRED - this is how one alters the string in question, without any direct editing of mission files. BP's custom AI profile, for instance, hasn't yet been implemented just because it wasn't thoroughly tested.

Furthermore, there is no 'they' in BP; it was just Darius at the time.
Title: Re: changing BANK_WHEN_TURN macro to a command line flag
Post by: chief1983 on August 25, 2009, 09:47:12 am
No the point was we were trying to explain that you can use a tbm file to modify the ai_profile that retail missions use without ever opening the mission files in FRED or notepad, I think.
Title: Re: changing BANK_WHEN_TURN macro to a command line flag
Post by: Sushi on August 25, 2009, 10:40:07 am
Alright, I took another look. The biggest problem is that this seems to affect all ships again, not just the player. Since the point of this (I thought :)) was to make it so that the player has the option of not banking when turning, this is bad.

Also, I recommend using a binary AI Profiles flag instead of a float-list. Just have something like "$Player Bank When Turn: YES/NO" modeled after the other binary AI profiles flags. I think that better suits your purpose, although a float-list can obviously do the job too. :)
Title: Re: changing BANK_WHEN_TURN macro to a command line flag
Post by: arisian on August 25, 2009, 11:49:25 am
Yes, if you modify the FS2 RETAIL profile it does affect all ships; I'd initially thought that you could have a different profile for the player, but I haven't yet found a way to do that easily (doesn't mean it can't be done, so if anyone knows of a way, let me know).  I could go back to explicitly checking whether the ship belongs to a player, but that would mean you could *never* apply the changes to AI controlled ships, which it seemed like might be something someone might want to do someday.  The reason I chose a float list was that it allowed more than just a binary on/off; it's actually a multiplier, so you can scale the banking up or down by using numbers greater or less than 1 if you want, allowing finer grain control.  Again, I thought that someone might someday find that useful; if you think it's unlikely, I'll make it a binary flag instead.
Title: Re: changing BANK_WHEN_TURN macro to a command line flag
Post by: Sushi on August 25, 2009, 12:25:34 pm
I could go back to explicitly checking whether the ship belongs to a player, but that would mean you could *never* apply the changes to AI controlled ships, which it seemed like might be something someone might want to do someday. 

There's already a ships.tbl entry that allows the banking factor to be adjusted on a per-ship basis. So there IS a way to do that, if you want to. :) If someone wants to make a mod with high-bank ships or no-bank ships (or any combination) they already can. What we can't do right now is change the auto-bank just for the player, basically as a concession to player flight styles.

The reason I chose a float list was that it allowed more than just a binary on/off; it's actually a multiplier, so you can scale the banking up or down by using numbers greater or less than 1 if you want, allowing finer grain control.  Again, I thought that someone might someday find that useful; if you think it's unlikely, I'll make it a binary flag instead.

Fair enough, and I guess some players may want to just reduce (or even amplify!) the banking constant for them. I don't think it makes sense to have a different value for each difficulty level though (at least not if the flag only affects the player). It would probably be better to read just a single float value (using stuff_float).