#189 - Fix Sengoku and other scenarios with fewer than 10 spaceship parts not being openable.
1 files changed, 35 insertions(+), 21 deletions(-)

M src/main/java/com/civfanatics/civ3/biqFile/IO.java
M src/main/java/com/civfanatics/civ3/biqFile/IO.java +35 -21
@@ 379,19 379,19 @@ public class IO
                 if (logger.isInfoEnabled())
                     logger.info("About to go into the various input processors; has been " + upToNow/1000000 + " milliseconds.");
                 inputBLDG(ins[0]);
-                logger.info("BLDG Bytes read: " + dataInputted + "; input bytes read = " + ins[0].numBytesRead);
+                logger.debug("BLDG Bytes read: " + dataInputted + "; input bytes read = " + ins[0].numBytesRead);
                 inputCTZN(ins[0]);
-                logger.info("CTZN Bytes read: " + dataInputted + "; input bytes read = " + ins[0].numBytesRead);
+                logger.debug("CTZN Bytes read: " + dataInputted + "; input bytes read = " + ins[0].numBytesRead);
                 inputCULT(ins[0]);
-                logger.info("CULT Bytes read: " + dataInputted + "; input bytes read = " + ins[0].numBytesRead);
+                logger.debug("CULT Bytes read: " + dataInputted + "; input bytes read = " + ins[0].numBytesRead);
                 inputDIFF(ins[0]);
-                logger.info("DIFF Bytes read: " + dataInputted + "; input bytes read = " + ins[0].numBytesRead);
+                logger.debug("DIFF Bytes read: " + dataInputted + "; input bytes read = " + ins[0].numBytesRead);
                 inputERAS(ins[0]);
-                logger.info("ERAS Bytes read: " + dataInputted + "; input bytes read = " + ins[0].numBytesRead);
+                logger.debug("ERAS Bytes read: " + dataInputted + "; input bytes read = " + ins[0].numBytesRead);
                 inputESPN(ins[0]);
-                logger.info("ESPN Bytes read: " + dataInputted + "; input bytes read = " + ins[0].numBytesRead);
+                logger.debug("ESPN Bytes read: " + dataInputted + "; input bytes read = " + ins[0].numBytesRead);
                 inputEXPR(ins[0]);
-                logger.info("EXPR Bytes read: " + dataInputted + "; input bytes read = " + ins[0].numBytesRead);
+                logger.debug("EXPR Bytes read: " + dataInputted + "; input bytes read = " + ins[0].numBytesRead);
                 if (fromSAV) {
                     //FLAV does not ALWAYS follow EXPR when embedded
                     ins[0].mark(4);

          
@@ 407,19 407,19 @@ public class IO
                     }
                 }
                 inputGOOD(ins[0]);
-                logger.info("GOOD Bytes read: " + dataInputted + "; input bytes read = " + ins[0].numBytesRead);
+                logger.debug("GOOD Bytes read: " + dataInputted + "; input bytes read = " + ins[0].numBytesRead);
                 inputGOVT(ins[0]);
-                logger.info("GOVT Bytes read: " + dataInputted + "; input bytes read = " + ins[0].numBytesRead);
+                logger.debug("GOVT Bytes read: " + dataInputted + "; input bytes read = " + ins[0].numBytesRead);
                 inputRULE(ins[0]);
-                logger.info("RULE Bytes read: " + dataInputted + "; input bytes read = " + ins[0].numBytesRead);
+                logger.debug("RULE Bytes read: " + dataInputted + "; input bytes read = " + ins[0].numBytesRead);
                 inputPRTO(ins[0]);
-                logger.info("PRTO Bytes read: " + dataInputted + "; input bytes read = " + ins[0].numBytesRead);
+                logger.debug("PRTO Bytes read: " + dataInputted + "; input bytes read = " + ins[0].numBytesRead);
                 inputRACE(ins[0]);
-                logger.info("RACE Bytes read: " + dataInputted + "; input bytes read = " + ins[0].numBytesRead);
+                logger.debug("RACE Bytes read: " + dataInputted + "; input bytes read = " + ins[0].numBytesRead);
                 inputTECH(ins[0]);
-                logger.info("TECH Bytes read: " + dataInputted + "; input bytes read = " + ins[0].numBytesRead);
+                logger.debug("TECH Bytes read: " + dataInputted + "; input bytes read = " + ins[0].numBytesRead);
                 inputTFRM(ins[0]);
-                logger.info("TFRM Bytes read: " + dataInputted + "; input bytes read = " + ins[0].numBytesRead);
+                logger.debug("TFRM Bytes read: " + dataInputted + "; input bytes read = " + ins[0].numBytesRead);
                 if (convertToConquests == 1)
                 {
                     TRFM airfield = new TRFM(this);

          
@@ 480,9 480,9 @@ public class IO
                     }
                 }
                 inputTERR(ins[0]);
-                logger.info("TERR Bytes read: " + dataInputted + "; input bytes read = " + ins[0].numBytesRead);
+                logger.debug("TERR Bytes read: " + dataInputted + "; input bytes read = " + ins[0].numBytesRead);
                 inputWSIZ(ins[0]);
-                logger.info("WSIZ Bytes read: " + dataInputted + "; input bytes read = " + ins[0].numBytesRead);
+                logger.debug("WSIZ Bytes read: " + dataInputted + "; input bytes read = " + ins[0].numBytesRead);
                 if (version == civ3Version.CONQUESTS && !fromSAV)
                 {
                     inputFLAV(ins[0]);

          
@@ 1704,10 1704,17 @@ public class IO
             dataInputted += 4;
             //logger.info(integer);
             numRules = integer;
-
+            
             for (int i = 0; i < numRules; i++)
             {
                 rule.add(new RULE(this));
+                //Standard length:
+                // 64 * 6 culture levels  = 384
+                // 4 * 10 spaceship parts =  40
+                // 296 other bytes        = 296
+                // 720 total              = 720
+                //N.B. This doesn't include the 4 bytes for dataLength
+                int adjustmentFromStandardLength = 0;
                 int ruleLength = in.readInt();
                 dataInputted += 4;
                 //Begin fix for 1.00 issue

          
@@ 1725,6 1732,7 @@ public class IO
                 rule.get(i).setMetropolisName(new String(inputThirtyTwo, currentCharset));
                 int numSpaceshipParts = in.readInt();
                 dataInputted += 4;
+                adjustmentFromStandardLength += (numSpaceshipParts - 10) * 4;
                 //Obsolete - now calculated automatically
                 //rule.get(i).setNumSpaceshipParts(integer);
                 //input number of each part required

          
@@ 1859,6 1867,7 @@ public class IO
                 //Obsolete - now calculated automatically
                 //rule.get(i).setNumCulturalLevels(integer);
                 //input name of each cultural level
+                adjustmentFromStandardLength += (numCultureLevelNames - 6) * 64;
                 for (int j = 0; j < numCultureLevelNames; j++)
                 {
                     in.read(inputSixtyFour, 0, 64);

          
@@ 1874,7 1883,10 @@ public class IO
                 rule.get(i).setBorderExpansionMultiplier(integer);
                 //Early versions of Vanilla did not have the last 5 fields
                 //in RULE.
-                if (ruleLength > 692) {
+                //Combined with PTW/Conquests additions, these add up to 28
+                //bytes fewer than the 720 standard, which then must be adjusted
+                //if spaceship parts/culture level name lengths are non-standard
+                if (ruleLength > (692 + adjustmentFromStandardLength)) {
                     integer = in.readInt();
                     dataInputted += 4;
                     rule.get(i).setBorderFactor(integer);

          
@@ 1908,10 1920,12 @@ public class IO
                     }
                 }
                 else if (convertToConquests > 0) {
-                    if (ruleLength < 712) {
+                    //712 is the "standard" length of latest-version Vanilla BICs
+                    //The last 8 will be added by the two conversion calls
+                    if (ruleLength < (712 + adjustmentFromStandardLength)) {
                         //Add data length for the fields added in later versions
                         //of Vanilla.
-                        rule.get(i).setDataLength(712);
+                        rule.get(i).setDataLength(712 + adjustmentFromStandardLength);
                     }
                     rule.get(i).convertToPTWFromVanilla();
                     rule.get(i).convertToConquestsFromPTW();

          
@@ 2552,7 2566,7 @@ public class IO
                 dataInputted += 4;
                 terrain.get(i).setNumTotalResources(integer);
                 int bytesOfAllowedResourceDataToInput = (integer + 7) / 8;
-                logger.info("Inputting " + bytesOfAllowedResourceDataToInput + " bytes of data on allowed resources.");
+                logger.trace("Inputting " + bytesOfAllowedResourceDataToInput + " bytes of data on allowed resources.");
                 for (int j = 0; j < bytesOfAllowedResourceDataToInput; j++)
                 {
                     inputByte = in.readByte();