Advertisement
DarkRevenant

Autogrouper

Apr 7th, 2014
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 29.12 KB | None | 0 0
  1.     public enum WeaponGroupConfig {
  2.  
  3.         STANDARD, MISSILE, BROADSIDE, MISSILE_BROADSIDE, ALPHA_STRIKE
  4.     }
  5.  
  6.     public static final Map weaponTypeOverride;
  7.  
  8.     static {
  9.         Map weaponTypeOverrideTemp = new HashMap();
  10.  
  11.         weaponTypeOverrideTemp.put("Missile",
  12.                 createWeaponList(new String[]{
  13.                     "annihilator", "annihilatorpod", "swarmer", "pilum",
  14.                     "exigency_mmm", "exigency_mmm_f"
  15.                 }));
  16.         weaponTypeOverrideTemp.put("No Aim",
  17.                 createWeaponList(new String[]{
  18.                     "swarmer", "pilum", "exigency_mmm", "exigency_mmm_f",
  19.                     "exigency_drumlauncher"
  20.                 }));
  21.         weaponTypeOverrideTemp.put("Anti-Fighter",
  22.                 createWeaponList(new String[]{
  23.                     "swarmer", "phasecl"
  24.                 }));
  25.         weaponTypeOverrideTemp.put("Point Defense",
  26.                 createWeaponList(new String[]{
  27.                     "phasecl"
  28.                 }));
  29.         weaponTypeOverrideTemp.put("Strike",
  30.                 createWeaponList(new String[]{
  31.                     "x"
  32.                 }));
  33.         weaponTypeOverrideTemp.put("Assault",
  34.                 createWeaponList(new String[]{
  35.                     "annihilator", "annihilatorpod", "phasecl", "exigency_mmm",
  36.                     "exigency_mmm_f"
  37.                 }));
  38.         weaponTypeOverrideTemp.put("Close Support",
  39.                 createWeaponList(new String[]{
  40.                     "exigency_drumlauncher"
  41.                 }));
  42.         weaponTypeOverrideTemp.put("Fire Support",
  43.                 createWeaponList(new String[]{
  44.                     "ssp_redeemer", "pilum"
  45.                 }));
  46.         weaponTypeOverrideTemp.put("Special",
  47.                 createWeaponList(new String[]{
  48.                     "x"
  49.                 }));
  50.         weaponTypeOverrideTemp.put("Low Flux", // Cannot be autodetected
  51.                 createWeaponList(new String[]{
  52.                     "lightmg", "lightdualmg", "lightmortar", "vulcan",
  53.                     "fragbomb", "clusterbomb", "bomb", "flak",
  54.                     "heavymg", "dualflak", "mininglaser", "pdlaser",
  55.                     "taclaser", "lrpdlaser", "pdburst", "gravitonbeam",
  56.                     "heavyburst", "guardian", "ssp_tpc", "annihilator",
  57.                     "annihilatorpod", "swarmer", "phasecl", "pilum",
  58.                     "exigency_mmm", "exigency_mmm_f"
  59.                 }));
  60.         weaponTypeOverrideTemp.put("High Flux", // Cannot be autodetected
  61.                 createWeaponList(new String[]{
  62.                     "mjolnir", "miningblaster", "heavyblaster", "plasma",
  63.                     "exigency_rr", "exigency_cigenrepeater", "exipirated_rr_p"
  64.                 }));
  65.         weaponTypeOverrideTemp.put("Sustained Beam", // Cannot be autodetected
  66.                 createWeaponList(new String[]{
  67.                     "hil", "gravitonbeam", "lrpdlaser", "pdlaser",
  68.                     "mininglaser", "phasebeam", "taclaser", "exigency_repulsor_beam",
  69.                     "exigency_lightning_gun"
  70.                 }));
  71.         weaponTypeOverrideTemp.put("Limited Ammo", // Cannot be autodetected
  72.                 createWeaponList(new String[]{
  73.                     "amblaster"
  74.                 }));
  75.         weaponTypeOverrideTemp.put("Override", // Disables autodetection
  76.                 createWeaponList(new String[]{
  77.                     "ssp_redeemer", "annihilator", "annihilatorpod", "swarmer",
  78.                     "phasecl", "pilum", "exigency_mmm", "exigency_mmm_f",
  79.                     "exigency_drumlauncher"
  80.                 }));
  81.  
  82.         weaponTypeOverride = Collections.unmodifiableMap(weaponTypeOverrideTemp);
  83.     }
  84.  
  85.     private static List<String> createWeaponList(String[] variants) {
  86.         return Collections.unmodifiableList(Arrays.asList(variants));
  87.     }
  88.  
  89.     private static List<String> getWeaponList(String key) {
  90.         return (List<String>) weaponTypeOverride.get(key);
  91.     }
  92.  
  93.     public static void generateWeaponGroups(ShipVariantAPI variant, WeaponGroupConfig config) {
  94.         // Clean up the existing groups
  95.         // We go through this whole song and dance rather than just flushing and making new groups for reasons of maximum compatability
  96.         for (WeaponGroupSpec group : variant.getWeaponGroups()) {
  97.             WeaponGroupSpec clone = group.clone();
  98.             for (String slot : clone.getSlots()) {
  99.                 group.removeSlot(slot);
  100.             }
  101.         }
  102.  
  103.         // These are programmable variables passed from the WeaponGroupConfig
  104.         // This will change how the algorithm will behave
  105.         boolean splitMissiles = false;
  106.         boolean enforceSides = false;
  107.         boolean linkedStrike = false;
  108.  
  109.         if (config == WeaponGroupConfig.MISSILE) {
  110.             splitMissiles = true;
  111.         } else if (config == WeaponGroupConfig.BROADSIDE) {
  112.             enforceSides = true;
  113.         } else if (config == WeaponGroupConfig.MISSILE_BROADSIDE) {
  114.             splitMissiles = true;
  115.             enforceSides = true;
  116.         } else if (config == WeaponGroupConfig.ALPHA_STRIKE) {
  117.             linkedStrike = true;
  118.         }
  119.  
  120.         // Now we define all of the possible weapon groups that the variant can use
  121.         List<WeaponGroupSpec> groupList = new ArrayList();
  122.  
  123.         WeaponGroupSpec PDGroup = new WeaponGroupSpec();
  124.         PDGroup.setType(WeaponGroupType.LINKED);
  125.         PDGroup.setAutofireOnByDefault(true);
  126.         groupList.add(PDGroup);
  127.  
  128.         WeaponGroupSpec AFGroup = new WeaponGroupSpec();
  129.         AFGroup.setType(WeaponGroupType.LINKED);
  130.         AFGroup.setAutofireOnByDefault(true);
  131.         groupList.add(AFGroup);
  132.  
  133.         WeaponGroupSpec AssGroup = new WeaponGroupSpec();
  134.         AssGroup.setType(WeaponGroupType.LINKED);
  135.         AssGroup.setAutofireOnByDefault(false);
  136.         groupList.add(AssGroup);
  137.  
  138.         WeaponGroupSpec AssTGroup = new WeaponGroupSpec();
  139.         AssTGroup.setType(WeaponGroupType.LINKED);
  140.         AssTGroup.setAutofireOnByDefault(true);
  141.         groupList.add(AssTGroup);
  142.  
  143.         WeaponGroupSpec CSGroup = new WeaponGroupSpec();
  144.         CSGroup.setType(WeaponGroupType.LINKED);
  145.         CSGroup.setAutofireOnByDefault(false);
  146.         groupList.add(CSGroup);
  147.  
  148.         WeaponGroupSpec CSTGroup = new WeaponGroupSpec();
  149.         CSTGroup.setType(WeaponGroupType.LINKED);
  150.         CSTGroup.setAutofireOnByDefault(true);
  151.         groupList.add(CSTGroup);
  152.  
  153.         WeaponGroupSpec SupGroup = new WeaponGroupSpec();
  154.         SupGroup.setType(WeaponGroupType.LINKED);
  155.         SupGroup.setAutofireOnByDefault(true);
  156.         groupList.add(SupGroup);
  157.  
  158.         WeaponGroupSpec HvyGroup = new WeaponGroupSpec();
  159.         if (linkedStrike) {
  160.             HvyGroup.setType(WeaponGroupType.LINKED);
  161.         } else {
  162.             HvyGroup.setType(WeaponGroupType.ALTERNATING);
  163.         }
  164.         HvyGroup.setAutofireOnByDefault(false);
  165.         groupList.add(HvyGroup);
  166.  
  167.         WeaponGroupSpec HvyTGroup = new WeaponGroupSpec();
  168.         if (linkedStrike) {
  169.             HvyTGroup.setType(WeaponGroupType.LINKED);
  170.         } else {
  171.             HvyTGroup.setType(WeaponGroupType.ALTERNATING);
  172.         }
  173.         HvyTGroup.setAutofireOnByDefault(false);
  174.         groupList.add(HvyTGroup);
  175.  
  176.         WeaponGroupSpec BeaGroup = new WeaponGroupSpec();
  177.         BeaGroup.setType(WeaponGroupType.LINKED);
  178.         BeaGroup.setAutofireOnByDefault(false);
  179.         groupList.add(BeaGroup);
  180.  
  181.         WeaponGroupSpec BeaTGroup = new WeaponGroupSpec();
  182.         BeaTGroup.setType(WeaponGroupType.LINKED);
  183.         BeaTGroup.setAutofireOnByDefault(false);
  184.         groupList.add(BeaTGroup);
  185.  
  186.         WeaponGroupSpec StrGroup = new WeaponGroupSpec();
  187.         if (linkedStrike) {
  188.             StrGroup.setType(WeaponGroupType.LINKED);
  189.         } else {
  190.             StrGroup.setType(WeaponGroupType.ALTERNATING);
  191.         }
  192.         StrGroup.setAutofireOnByDefault(false);
  193.         groupList.add(StrGroup);
  194.  
  195.         WeaponGroupSpec MisGroup = new WeaponGroupSpec();
  196.         if (linkedStrike) {
  197.             MisGroup.setType(WeaponGroupType.LINKED);
  198.         } else {
  199.             MisGroup.setType(WeaponGroupType.ALTERNATING);
  200.         }
  201.         MisGroup.setAutofireOnByDefault(false);
  202.         groupList.add(MisGroup);
  203.  
  204.         WeaponGroupSpec SMisGroup = new WeaponGroupSpec();
  205.         SMisGroup.setType(WeaponGroupType.LINKED);
  206.         SMisGroup.setAutofireOnByDefault(true);
  207.         groupList.add(SMisGroup);
  208.  
  209.         WeaponGroupSpec AMisGroup = new WeaponGroupSpec();
  210.         if (linkedStrike) {
  211.             AMisGroup.setType(WeaponGroupType.LINKED);
  212.         } else {
  213.             AMisGroup.setType(WeaponGroupType.ALTERNATING);
  214.         }
  215.         AMisGroup.setAutofireOnByDefault(false);
  216.         groupList.add(AMisGroup);
  217.  
  218.         WeaponGroupSpec LGroup = new WeaponGroupSpec();
  219.         LGroup.setType(WeaponGroupType.LINKED);
  220.         LGroup.setAutofireOnByDefault(false);
  221.         groupList.add(LGroup);
  222.  
  223.         WeaponGroupSpec RGroup = new WeaponGroupSpec();
  224.         RGroup.setType(WeaponGroupType.LINKED);
  225.         RGroup.setAutofireOnByDefault(false);
  226.         groupList.add(RGroup);
  227.  
  228.         // This loops through all of the weapons and individually assigns them to initial groups
  229.         // Most weapon groupings are auto-detected based on AI hints, weapon data, and description strings
  230.         // The remaning groupings are enforced via overrides and configuration parameters
  231.         List<WeaponSlotAPI> slots = variant.getHullSpec().getAllWeaponSlotsCopy();
  232.         Collection<String> fittedSlots = variant.getFittedWeaponSlots();
  233.         for (String fittedSlot : fittedSlots) {
  234.             String weapon = variant.getWeaponId(fittedSlot);
  235.             String type = Global.getSettings().getDescription(weapon, Description.Type.WEAPON).getText2();
  236.             WeaponSlotAPI slot = null;
  237.             for (WeaponSlotAPI slott : slots) {
  238.                 if (slott.getId().equals(fittedSlot)) {
  239.                     slot = slott;
  240.                 }
  241.             }
  242.  
  243.             // These are the various weapon properties that are checked when making the groupings
  244.             boolean antiFighter = false;
  245.             boolean pointDefense = false;
  246.             boolean strike = false;
  247.             boolean noAim = false;
  248.             boolean assault = false;
  249.             boolean closeSupport = false;
  250.             boolean fireSupport = false;
  251.             boolean missile = false;
  252.             boolean lowFlux = false;
  253.             boolean highFlux = false;
  254.             boolean hardpoint = false;
  255.             boolean limitedAmmo = false;
  256.             boolean beam = false;
  257.             boolean special = false;
  258.             boolean front = false;
  259.             boolean back = false;
  260.             boolean left = false;
  261.             boolean right = false;
  262.             WeaponSize size = WeaponSize.SMALL;
  263.  
  264.             if (slot != null) {
  265.                 if (slot.isHardpoint() || slot.getArc() <= 5f) {
  266.                     hardpoint = true;
  267.                 }
  268.                 if (slot.getAngle() <= 45f && slot.getAngle() >= -45f) {
  269.                     front = true;
  270.                 } else if (slot.getAngle() >= 45f && slot.getAngle() <= 135f) {
  271.                     left = true;
  272.                 } else if (slot.getAngle() > 135f || slot.getAngle() < -135f) {
  273.                     back = true;
  274.                 } else {
  275.                     right = true;
  276.                 }
  277.                 size = slot.getSlotSize();
  278.             }
  279.             if (getWeaponList("Missile").contains(weapon)) {
  280.                 missile = true;
  281.             }
  282.             if (getWeaponList("No Aim").contains(weapon)) {
  283.                 noAim = true;
  284.             }
  285.             if (getWeaponList("Anti-Fighter").contains(weapon)) {
  286.                 antiFighter = true;
  287.             }
  288.             if (getWeaponList("Point Defense").contains(weapon)) {
  289.                 pointDefense = true;
  290.             }
  291.             if (getWeaponList("Strike").contains(weapon)) {
  292.                 strike = true;
  293.             }
  294.             if (getWeaponList("Assault").contains(weapon)) {
  295.                 assault = true;
  296.             }
  297.             if (getWeaponList("Close Support").contains(weapon)) {
  298.                 closeSupport = true;
  299.             }
  300.             if (getWeaponList("Fire Support").contains(weapon)) {
  301.                 fireSupport = true;
  302.             }
  303.             if (getWeaponList("Special").contains(weapon)) {
  304.                 special = true;
  305.             }
  306.             if (getWeaponList("Low Flux").contains(weapon)) {
  307.                 lowFlux = true;
  308.             }
  309.             if (getWeaponList("High Flux").contains(weapon)) {
  310.                 highFlux = true;
  311.             }
  312.             if (getWeaponList("Sustained Beam").contains(weapon)) {
  313.                 beam = true;
  314.             }
  315.             if (getWeaponList("Limited Ammo").contains(weapon)) {
  316.                 limitedAmmo = true;
  317.             }
  318.  
  319.             // If "Override" is set for the weapon, skip this auto-detection stuff and only use the overrides
  320.             // Weapons without "Override" set will use both auto-detected stuff and overrides
  321.             if (!getWeaponList("Override").contains(weapon)) {
  322.                 EnumSet<AIHints> hints = variant.getWeaponSpec(fittedSlot).getAIHints();
  323.                 for (AIHints hint : hints) {
  324.                     if (hint == AIHints.ANTI_FTR) {
  325.                         antiFighter = true;
  326.                     }
  327.                     if (hint == AIHints.PD || hint == AIHints.PD_ONLY) {
  328.                         pointDefense = true;
  329.                     }
  330.                     if (hint == AIHints.STRIKE) {
  331.                         strike = true;
  332.                     }
  333.                     if (hint == AIHints.DO_NOT_AIM || hint == AIHints.HEATSEEKER) {
  334.                         noAim = true;
  335.                     }
  336.                 }
  337.                 if (variant.getWeaponSpec(fittedSlot).getType() == WeaponType.MISSILE) {
  338.                     missile = true;
  339.                     lowFlux = true;
  340.                     limitedAmmo = true;
  341.                 }
  342.                 if (type.equals("Anti-Fighter")) {
  343.                     antiFighter = true;
  344.                 }
  345.                 if (type.equals("Point Defense")) {
  346.                     pointDefense = true;
  347.                 }
  348.                 if (type.equals("Strike")) {
  349.                     strike = true;
  350.                 }
  351.                 if (type.equals("Assault")) {
  352.                     assault = true;
  353.                 }
  354.                 if (type.equals("Close Support")) {
  355.                     closeSupport = true;
  356.                 }
  357.                 if (type.equals("Fire Support")) {
  358.                     fireSupport = true;
  359.                 }
  360.                 if (type.equals("Special")) {
  361.                     special = true;
  362.                 }
  363.             }
  364.  
  365.             // This is the logic for assigning weapons to general groups
  366.             // Make sure you know what you are doing before changing this stuff around
  367.             // The order of operations is important!
  368.             if (hardpoint && (highFlux || (size == WeaponSize.LARGE && (variant.getHullSize() == HullSize.FRIGATE || variant.getHullSize() == HullSize.DESTROYER || variant.getHullSize() == HullSize.DEFAULT)))) {
  369.                 if (!beam) {
  370.                     HvyGroup.addSlot(fittedSlot);
  371.                 } else {
  372.                     BeaGroup.addSlot(fittedSlot);
  373.                 }
  374.             } else if (!hardpoint && (highFlux || (size == WeaponSize.LARGE && (variant.getHullSize() == HullSize.FRIGATE || variant.getHullSize() == HullSize.DESTROYER || variant.getHullSize() == HullSize.DEFAULT)))) {
  375.                 if (!beam) {
  376.                     HvyTGroup.addSlot(fittedSlot);
  377.                 } else {
  378.                     BeaTGroup.addSlot(fittedSlot);
  379.                 }
  380.             } else if (missile && left && enforceSides && !noAim && !limitedAmmo) {
  381.                 LGroup.addSlot(fittedSlot);
  382.             } else if (missile && right && enforceSides && !noAim && !limitedAmmo) {
  383.                 RGroup.addSlot(fittedSlot);
  384.             } else if (missile && limitedAmmo && (noAim || !hardpoint) && !strike) {
  385.                 MisGroup.addSlot(fittedSlot);
  386.             } else if (missile && !limitedAmmo && !strike) {
  387.                 SMisGroup.addSlot(fittedSlot);
  388.             } else if (missile && limitedAmmo && !noAim && !strike) {
  389.                 AMisGroup.addSlot(fittedSlot);
  390.             } else if (pointDefense && !hardpoint && !limitedAmmo) {
  391.                 PDGroup.addSlot(fittedSlot);
  392.             } else if (antiFighter) {
  393.                 AFGroup.addSlot(fittedSlot);
  394.             } else if (left && (hardpoint || enforceSides) && !lowFlux) {
  395.                 LGroup.addSlot(fittedSlot);
  396.             } else if (right && (hardpoint || enforceSides) && !lowFlux) {
  397.                 RGroup.addSlot(fittedSlot);
  398.             } else if (assault && hardpoint && !lowFlux) {
  399.                 AssGroup.addSlot(fittedSlot);
  400.             } else if (assault && !hardpoint && !lowFlux) {
  401.                 AssTGroup.addSlot(fittedSlot);
  402.             } else if (closeSupport && hardpoint && !lowFlux) {
  403.                 CSGroup.addSlot(fittedSlot);
  404.             } else if (closeSupport && !hardpoint && !lowFlux) {
  405.                 CSTGroup.addSlot(fittedSlot);
  406.             } else if (strike || limitedAmmo) {
  407.                 if (!beam) {
  408.                     StrGroup.addSlot(fittedSlot);
  409.                 } else {
  410.                     if (hardpoint) {
  411.                         BeaGroup.addSlot(fittedSlot);
  412.                     } else {
  413.                         BeaTGroup.addSlot(fittedSlot);
  414.                     }
  415.                 }
  416.             } else if (fireSupport || lowFlux || special) {
  417.                 SupGroup.addSlot(fittedSlot);
  418.             } else {
  419.                 SupGroup.addSlot(fittedSlot); // This should always be at the end
  420.             }
  421.         }
  422.  
  423.         // Now we consolidate the general weapon groups into five final weapon groups
  424.         // This is only done if the number of general weapon groups is greater than 5
  425.         // If Alex ever increases the maximum number of weapon groups, this number can be changed
  426.         int groupCount = 0;
  427.         for (WeaponGroupSpec group : groupList) {
  428.             if (group.getSlots().isEmpty()) {
  429.                 groupCount++;
  430.             }
  431.         }
  432.  
  433.         // This section is the most difficult part of the algorithm and can make or break large ships like the Onslaught
  434.         // Make sure you know what you are doing when adding logic here
  435.         // Do not pass weapons into a group that may have already become null; NetBeans should warn you about this
  436.         // Order of operations is extremely important
  437.         if (!AFGroup.getSlots().isEmpty()) {
  438.             if (groupCount > 5) {
  439.                 if (!PDGroup.getSlots().isEmpty()) {
  440.                     groupCount--;
  441.                 }
  442.                 for (String toAdd : AFGroup.getSlots()) {
  443.                     PDGroup.addSlot(toAdd);
  444.                 }
  445.                 AFGroup = null;
  446.             }
  447.         } else {
  448.             AFGroup = null;
  449.         }
  450.         if (!AssGroup.getSlots().isEmpty()) {
  451.             if (groupCount > 5) {
  452.                 if (!CSGroup.getSlots().isEmpty()) {
  453.                     groupCount--;
  454.                 }
  455.                 for (String toAdd : AssGroup.getSlots()) {
  456.                     CSGroup.addSlot(toAdd);
  457.                 }
  458.                 AssGroup = null;
  459.             }
  460.         } else {
  461.             AssGroup = null;
  462.         }
  463.         if (!splitMissiles) {
  464.             if (!AMisGroup.getSlots().isEmpty()) {
  465.                 if (groupCount > 5) {
  466.                     if (!MisGroup.getSlots().isEmpty()) {
  467.                         groupCount--;
  468.                     }
  469.                     for (String toAdd : AMisGroup.getSlots()) {
  470.                         MisGroup.addSlot(toAdd);
  471.                     }
  472.                     AMisGroup = null;
  473.                 }
  474.             } else {
  475.                 AMisGroup = null;
  476.             }
  477.         }
  478.         if (!PDGroup.getSlots().isEmpty()) {
  479.             if (groupCount > 5) {
  480.                 if (!SupGroup.getSlots().isEmpty()) {
  481.                     groupCount--;
  482.                 }
  483.                 for (String toAdd : PDGroup.getSlots()) {
  484.                     SupGroup.addSlot(toAdd);
  485.                 }
  486.                 PDGroup = null;
  487.             }
  488.         } else {
  489.             PDGroup = null;
  490.         }
  491.         if (!splitMissiles) {
  492.             if (!SMisGroup.getSlots().isEmpty()) {
  493.                 if (groupCount > 5) {
  494.                     if (!AssTGroup.getSlots().isEmpty()) {
  495.                         groupCount--;
  496.                     }
  497.                     for (String toAdd : SMisGroup.getSlots()) {
  498.                         AssTGroup.addSlot(toAdd);
  499.                     }
  500.                     SMisGroup = null;
  501.                 }
  502.             } else {
  503.                 SMisGroup = null;
  504.             }
  505.         }
  506.         if (!AssTGroup.getSlots().isEmpty()) {
  507.             if (groupCount > 5) {
  508.                 if (!CSTGroup.getSlots().isEmpty()) {
  509.                     groupCount--;
  510.                 }
  511.                 for (String toAdd : AssTGroup.getSlots()) {
  512.                     CSTGroup.addSlot(toAdd);
  513.                 }
  514.                 AssTGroup = null;
  515.             }
  516.         } else {
  517.             AssTGroup = null;
  518.         }
  519.         if (!BeaTGroup.getSlots().isEmpty()) {
  520.             if (groupCount > 5) {
  521.                 if (!CSTGroup.getSlots().isEmpty()) {
  522.                     groupCount--;
  523.                 }
  524.                 for (String toAdd : BeaTGroup.getSlots()) {
  525.                     CSTGroup.addSlot(toAdd);
  526.                 }
  527.                 BeaTGroup = null;
  528.             }
  529.         } else {
  530.             BeaTGroup = null;
  531.         }
  532.         if (!BeaGroup.getSlots().isEmpty()) {
  533.             if (groupCount > 5) {
  534.                 if (!CSGroup.getSlots().isEmpty()) {
  535.                     groupCount--;
  536.                 }
  537.                 for (String toAdd : BeaGroup.getSlots()) {
  538.                     CSGroup.addSlot(toAdd);
  539.                 }
  540.                 BeaGroup = null;
  541.             }
  542.         } else {
  543.             BeaGroup = null;
  544.         }
  545.         if (!enforceSides) {
  546.             if (!LGroup.getSlots().isEmpty()) {
  547.                 if (groupCount > 5) {
  548.                     if (!RGroup.getSlots().isEmpty()) {
  549.                         groupCount--;
  550.                     }
  551.                     for (String toAdd : LGroup.getSlots()) {
  552.                         RGroup.addSlot(toAdd);
  553.                     }
  554.                     LGroup = null;
  555.                 }
  556.             } else {
  557.                 LGroup = null;
  558.             }
  559.         }
  560.         if (!CSTGroup.getSlots().isEmpty()) {
  561.             if (groupCount > 5) {
  562.                 if (!SupGroup.getSlots().isEmpty()) {
  563.                     groupCount--;
  564.                 }
  565.                 for (String toAdd : CSTGroup.getSlots()) {
  566.                     SupGroup.addSlot(toAdd);
  567.                 }
  568.                 CSTGroup = null;
  569.             }
  570.         } else {
  571.             CSTGroup = null;
  572.         }
  573.         if (!HvyTGroup.getSlots().isEmpty()) {
  574.             if (groupCount > 5) {
  575.                 if (!HvyGroup.getSlots().isEmpty()) {
  576.                     groupCount--;
  577.                 }
  578.                 for (String toAdd : HvyTGroup.getSlots()) {
  579.                     HvyGroup.addSlot(toAdd);
  580.                 }
  581.                 HvyTGroup = null;
  582.             }
  583.         } else {
  584.             HvyTGroup = null;
  585.         }
  586.         if (!HvyGroup.getSlots().isEmpty()) {
  587.             if (groupCount > 5) {
  588.                 if (!StrGroup.getSlots().isEmpty()) {
  589.                     groupCount--;
  590.                 }
  591.                 for (String toAdd : HvyGroup.getSlots()) {
  592.                     StrGroup.addSlot(toAdd);
  593.                 }
  594.                 HvyGroup = null;
  595.             }
  596.         } else {
  597.             HvyGroup = null;
  598.         }
  599.         if (splitMissiles && AMisGroup != null) {
  600.             if (!AMisGroup.getSlots().isEmpty()) {
  601.                 if (groupCount > 5) {
  602.                     if (!MisGroup.getSlots().isEmpty()) {
  603.                         groupCount--;
  604.                     }
  605.                     for (String toAdd : AMisGroup.getSlots()) {
  606.                         MisGroup.addSlot(toAdd);
  607.                     }
  608.                     AMisGroup = null;
  609.                 }
  610.             } else {
  611.                 AMisGroup = null;
  612.             }
  613.         }
  614.         if (splitMissiles && SMisGroup != null) {
  615.             if (!SMisGroup.getSlots().isEmpty()) {
  616.                 if (groupCount > 5) {
  617.                     if (!SupGroup.getSlots().isEmpty()) {
  618.                         groupCount--;
  619.                     }
  620.                     for (String toAdd : SMisGroup.getSlots()) {
  621.                         SupGroup.addSlot(toAdd);
  622.                     }
  623.                     SMisGroup = null;
  624.                 }
  625.             } else {
  626.                 SMisGroup = null;
  627.             }
  628.         }
  629.         if (enforceSides) {
  630.             if (!CSGroup.getSlots().isEmpty()) {
  631.                 if (groupCount > 5) {
  632.                     if (!SupGroup.getSlots().isEmpty()) {
  633.                         groupCount--;
  634.                     }
  635.                     for (String toAdd : CSGroup.getSlots()) {
  636.                         SupGroup.addSlot(toAdd);
  637.                     }
  638.                     CSGroup = null;
  639.                 }
  640.             } else {
  641.                 CSGroup = null;
  642.             }
  643.         } else {
  644.             if (CSGroup.getSlots().isEmpty()) {
  645.                 CSGroup = null;
  646.             }
  647.         }
  648.         if (enforceSides && LGroup != null) {
  649.             if (LGroup.getSlots().isEmpty()) {
  650.                 LGroup = null;
  651.             }
  652.         }
  653.         if (RGroup.getSlots().isEmpty()) {
  654.             RGroup = null;
  655.         }
  656.         if (StrGroup.getSlots().isEmpty()) {
  657.             StrGroup = null;
  658.         }
  659.         if (SupGroup.getSlots().isEmpty()) {
  660.             SupGroup = null;
  661.         }
  662.         if (MisGroup.getSlots().isEmpty()) {
  663.             MisGroup = null;
  664.         }
  665.  
  666.         if (variant.getWeaponGroups().size() < 5) {
  667.             for (int i = variant.getWeaponGroups().size(); i < 5; i++) {
  668.                 variant.addWeaponGroup(new WeaponGroupSpec());
  669.             }
  670.         }
  671.  
  672.         // I didn't make a loop for this because the order in which you put these functions determines their order on the ship
  673.         int currentGroup = 0;
  674.         if (HvyGroup != null) {
  675.             integrateGroup(HvyGroup, variant.getGroup(currentGroup));
  676.             currentGroup++;
  677.         }
  678.         if (HvyTGroup != null) {
  679.             integrateGroup(HvyTGroup, variant.getGroup(currentGroup));
  680.             currentGroup++;
  681.         }
  682.         if (BeaGroup != null) {
  683.             integrateGroup(BeaGroup, variant.getGroup(currentGroup));
  684.             currentGroup++;
  685.         }
  686.         if (BeaTGroup != null) {
  687.             integrateGroup(BeaTGroup, variant.getGroup(currentGroup));
  688.             currentGroup++;
  689.         }
  690.         if (LGroup != null) {
  691.             integrateGroup(LGroup, variant.getGroup(currentGroup));
  692.             currentGroup++;
  693.         }
  694.         if (RGroup != null) {
  695.             integrateGroup(RGroup, variant.getGroup(currentGroup));
  696.             currentGroup++;
  697.         }
  698.         if (AssGroup != null) {
  699.             integrateGroup(AssGroup, variant.getGroup(currentGroup));
  700.             currentGroup++;
  701.         }
  702.         if (CSGroup != null) {
  703.             integrateGroup(CSGroup, variant.getGroup(currentGroup));
  704.             currentGroup++;
  705.         }
  706.         if (AssTGroup != null) {
  707.             integrateGroup(AssTGroup, variant.getGroup(currentGroup));
  708.             currentGroup++;
  709.         }
  710.         if (CSTGroup != null) {
  711.             integrateGroup(CSTGroup, variant.getGroup(currentGroup));
  712.             currentGroup++;
  713.         }
  714.         if (StrGroup != null) {
  715.             integrateGroup(StrGroup, variant.getGroup(currentGroup));
  716.             currentGroup++;
  717.         }
  718.         if (AMisGroup != null) {
  719.             integrateGroup(AMisGroup, variant.getGroup(currentGroup));
  720.             currentGroup++;
  721.         }
  722.         if (MisGroup != null) {
  723.             integrateGroup(MisGroup, variant.getGroup(currentGroup));
  724.             currentGroup++;
  725.         }
  726.         if (SMisGroup != null) {
  727.             integrateGroup(SMisGroup, variant.getGroup(currentGroup));
  728.             currentGroup++;
  729.         }
  730.         if (SupGroup != null) {
  731.             integrateGroup(SupGroup, variant.getGroup(currentGroup));
  732.             currentGroup++;
  733.         }
  734.         if (AFGroup != null) {
  735.             integrateGroup(AFGroup, variant.getGroup(currentGroup));
  736.             currentGroup++;
  737.         }
  738.         if (PDGroup != null) {
  739.             integrateGroup(PDGroup, variant.getGroup(currentGroup));
  740.             currentGroup++;
  741.         }
  742.     }
  743.  
  744.     private static void integrateGroup(WeaponGroupSpec source, WeaponGroupSpec destination) {
  745.         for (String slot : source.getSlots()) {
  746.             destination.addSlot(slot);
  747.         }
  748.         destination.setType(source.getType());
  749.         destination.setAutofireOnByDefault(source.isAutofireOnByDefault());
  750.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement