Source Code Project Mantis - FSSCP
View Issue Details
0002369FSSCPtablespublic2011-01-04 10:002011-11-29 01:04
Assigned ToGoober5000 
PlatformOSOS Version
Product VersionAntipodes 8 
Target VersionFixed in Version 
Summary0002369: Setting $SBank Capacity in shp.tbm also requires $Default SBanks
DescriptionIf omitted, debug gives following error

f-shp.tbm(line 41:Error: Required token = [#End], [$Subsystem:], [$Name], or [$Template], found [$SBank Capacity: ( 40, 40 )].
TagsNo tags attached.
Attached Files

2011-01-04 10:02   
Reverse is also true, omitting $SBank Capacity when $Default SBanks it set also produces debug error.

f-shp.tbm(line 42:Error: Missing required token: [$SBank Capacity:]. Found [$Shields: 480]
2011-10-29 08:58   
(Last edited: 2011-10-29 09:00)
I've made a patch which removes $SBank Capacity's dependency on $Default Banks, so you can now include the former regardless of whether the latter is present. The reverse, however, I think seems to make sense, so in my (admittedly limited) view, I vote it should be kept as is.

This does need coder review though.

EDIT: Patch is here:

2011-10-29 23:38   
CommanderDJ - the patch looks like it'll work fine, however I'm not so keen on copy/paste of code. What about using a function to do the work of parsing "$SBank Capacity:"?

required_string("$SBank Capacity:");
else if(optional_string("$SBank Capacity:"))
2011-10-30 02:18   
(Last edited: 2011-10-30 05:40)
I went one better and removed the need for duplicate code. I've also removed the dependency both ways now, so you can have either one of $Default SBanks or $SBank Capacity without the other.

In the process I found something that would have actually prevented the previous patch from working - the code determined the number of secondary banks on a ship from its default banks. If the number of capacities didn't match up, it threw a warning.

Since the two are no longer dependent I've done it this way: if $Default SBanks is specified, the code uses that to determine the number of secondary banks. If $SBank Capacity is also specified, it double checks that the two match up as before. If Capacity is specified but not Defaults, it uses the number of Capacities as the number of banks (keep in mind any discrepancies between model and table get picked up on mission load - during game startup it only checks for mismatches within the tables). I think this should work for everyone, but if there are any other suggestions I'm happy to work on them.

EDIT: new patch is here:

2011-11-03 21:52   
The patch appears to make $Default SBanks optional when being parsed in a .tbl as well? How does FSO/FRED handle a ship that has no SBanks specfied at all?
2011-11-03 22:14   
FSO/FRED sets the defaults to the first secondary available in weapons.tbl if none are specified. I have tested it with no capacity and nothing broke, but I'm not sure exactly what it does. I'll do some more testing later today and post here with any findings.
2011-11-04 11:31   
How is this even a bug? A ship *always* needs default SBanks so that FRED knows what to assign the ship when it's created, or so that ship-create knows what to put in the missile bays.

If you're saying the TBM requires default SBanks when they were already specified in the table, then that's legitimate. But the suggested patch doesn't appear to capture all scenarios. What if, as asked on the forum, default SBanks were never specified in either the tbl or tbm? It looks like at least two arrays would go uninitialized.
2011-11-04 11:43   
Also, a while back I think I eliminated the need for a ship to have SBanks at all. TIE Fighters in FotG seem to be working fine without them. Hope it doesn't affect that adversely.
2011-11-04 21:20   
Currently Default Sbanks is an optional setting. As CommanderDJ says the game is capable of figuring out what it should use for the SBanks in that situation. If you've made Default SBanks optional then you need to make sure that nothing else screws up as a result. Which is what this fix is supposed to be doing.

The only other alternative would be to set Default SBanks back to required.
2011-11-04 23:00   
Karajorma's right. Default SBanks was optional beforehand, the game simply assigns the first secondary in weapons.tbl as the defaults if it isn't specified. I'm currently investigating what it does for capacity, but I do recall nothing breaking. I'll post here when I have more info.
2011-11-07 00:01   
If the ship doesn't have any SBanks at all, then it shouldn't have any SBank capacities either. So the TIE Fighter example doesn't seem relevant here.

If you specify Defaults but don't specify Capacities, then what capacities should be used by default? Zero?

If you specify Capacities but don't specify Defaults, that just strikes me as being lazy. You can use the first secondary listed in the table, but that's almost always the Rockeye and may not be suitable for all ships.

For those reasons it's pretty self-evident that Defaults and Capacities should always be specified together. Even if it may be possible to make them work independently, I don't think it's a good idea.

In fact, I originally thought that this patch would cause problems due to not initializing the sip->secondary_bank_weapons array in certain code branches. Fortunately, the ship_set() method initializes everything to 0, so the absence of explicit initialization here does not harm anything. Even so, a comment should probably be added explaining this.

There's also the issue that if the Capacity but not the Defaults is specified in a modular table, and the number of Capacity banks in the TBM happens to be different from the number of Default banks in the original ships.tbl, the parser will silently change the number of banks without showing a warning like it should. This is because multiple TBMs require multiple invocations of the parse_ship_values function, and the sbank_defaults_specified variable does not persist from invocation to invocation.
2011-11-28 06:00   
Sorry to bump this, but are we leaving it as is then? If so, can this ticket be closed?
2011-11-29 01:04   
Well, after further consideration, I realized that what I was actually concerned about was not having both lines specified before parsing *completed*, as opposed to not having both lines consecutively in the same file. So I instead implemented a fix where the parser was made a little more robust and a little more forgiving. It now complains if Default Banks and Bank Capacities get out of sync, but it doesn't complain if you modify them one-at-a-time in a modular table.

Fixed in r8054.

Issue History
2011-01-04 10:00FuryNew Issue
2011-01-04 10:02FuryNote Added: 0012587
2011-10-29 08:58CommanderDJNote Added: 0012909
2011-10-29 08:59CommanderDJNote Edited: 0012909
2011-10-29 09:00CommanderDJNote Edited: 0012909
2011-10-29 23:38niffiwanNote Added: 0012910
2011-10-30 02:18CommanderDJNote Added: 0012911
2011-10-30 02:19CommanderDJNote Edited: 0012911
2011-10-30 05:40CommanderDJNote Edited: 0012911
2011-11-03 21:52iss_mneurNote Added: 0012919
2011-11-03 21:52iss_mneurStatusnew => acknowledged
2011-11-03 22:14CommanderDJNote Added: 0012920
2011-11-04 11:28Goober5000Statusacknowledged => assigned
2011-11-04 11:28Goober5000Assigned To => Goober5000
2011-11-04 11:31Goober5000Note Added: 0012922
2011-11-04 11:43chief1983Note Added: 0012923
2011-11-04 21:20karajormaNote Added: 0012926
2011-11-04 23:00CommanderDJNote Added: 0012927
2011-11-07 00:01Goober5000Note Added: 0012935
2011-11-28 06:00CommanderDJNote Added: 0012985
2011-11-29 01:04Goober5000Note Added: 0012986
2011-11-29 01:04Goober5000Statusassigned => resolved
2011-11-29 01:04Goober5000Resolutionopen => fixed