Advertisement
DarkRevenant

Autogroup

Apr 7th, 2014
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 27.75 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.         for (WeaponGroupSpec group : variant.getWeaponGroups()) {
  95.             WeaponGroupSpec clone = group.clone();
  96.             for (String slot : clone.getSlots()) {
  97.                 group.removeSlot(slot);
  98.             }
  99.         }
  100.  
  101.         boolean splitMissiles = false;
  102.         boolean enforceSides = false;
  103.         boolean linkedStrike = false;
  104.  
  105.         List<WeaponSlotAPI> slots = variant.getHullSpec().getAllWeaponSlotsCopy();
  106.  
  107.         if (config == WeaponGroupConfig.MISSILE) {
  108.             splitMissiles = true;
  109.         } else if (config == WeaponGroupConfig.BROADSIDE) {
  110.             enforceSides = true;
  111.         } else if (config == WeaponGroupConfig.MISSILE_BROADSIDE) {
  112.             splitMissiles = true;
  113.             enforceSides = true;
  114.         } else if (config == WeaponGroupConfig.ALPHA_STRIKE) {
  115.             linkedStrike = true;
  116.         }
  117.  
  118.         WeaponGroupSpec PDGroup = new WeaponGroupSpec();
  119.         PDGroup.setType(WeaponGroupType.LINKED);
  120.         PDGroup.setAutofireOnByDefault(true);
  121.         WeaponGroupSpec AFGroup = new WeaponGroupSpec();
  122.         AFGroup.setType(WeaponGroupType.LINKED);
  123.         AFGroup.setAutofireOnByDefault(true);
  124.         WeaponGroupSpec AssGroup = new WeaponGroupSpec();
  125.         AssGroup.setType(WeaponGroupType.LINKED);
  126.         AssGroup.setAutofireOnByDefault(false);
  127.         WeaponGroupSpec AssTGroup = new WeaponGroupSpec();
  128.         AssTGroup.setType(WeaponGroupType.LINKED);
  129.         AssTGroup.setAutofireOnByDefault(true);
  130.         WeaponGroupSpec CSGroup = new WeaponGroupSpec();
  131.         CSGroup.setType(WeaponGroupType.LINKED);
  132.         CSGroup.setAutofireOnByDefault(false);
  133.         WeaponGroupSpec CSTGroup = new WeaponGroupSpec();
  134.         CSTGroup.setType(WeaponGroupType.LINKED);
  135.         CSTGroup.setAutofireOnByDefault(true);
  136.         WeaponGroupSpec SupGroup = new WeaponGroupSpec();
  137.         SupGroup.setType(WeaponGroupType.LINKED);
  138.         SupGroup.setAutofireOnByDefault(true);
  139.         WeaponGroupSpec HvyGroup = new WeaponGroupSpec();
  140.         if (linkedStrike) {
  141.             HvyGroup.setType(WeaponGroupType.LINKED);
  142.         } else {
  143.             HvyGroup.setType(WeaponGroupType.ALTERNATING);
  144.         }
  145.         HvyGroup.setAutofireOnByDefault(false);
  146.         WeaponGroupSpec HvyTGroup = new WeaponGroupSpec();
  147.         if (linkedStrike) {
  148.             HvyTGroup.setType(WeaponGroupType.LINKED);
  149.         } else {
  150.             HvyTGroup.setType(WeaponGroupType.ALTERNATING);
  151.         }
  152.         HvyTGroup.setAutofireOnByDefault(false);
  153.         WeaponGroupSpec BeaGroup = new WeaponGroupSpec();
  154.         BeaGroup.setType(WeaponGroupType.LINKED);
  155.         BeaGroup.setAutofireOnByDefault(false);
  156.         WeaponGroupSpec BeaTGroup = new WeaponGroupSpec();
  157.         BeaTGroup.setType(WeaponGroupType.LINKED);
  158.         BeaTGroup.setAutofireOnByDefault(false);
  159.         WeaponGroupSpec StrGroup = new WeaponGroupSpec();
  160.         if (linkedStrike) {
  161.             StrGroup.setType(WeaponGroupType.LINKED);
  162.         } else {
  163.             StrGroup.setType(WeaponGroupType.ALTERNATING);
  164.         }
  165.         StrGroup.setAutofireOnByDefault(false);
  166.         WeaponGroupSpec MisGroup = new WeaponGroupSpec();
  167.         if (linkedStrike) {
  168.             MisGroup.setType(WeaponGroupType.LINKED);
  169.         } else {
  170.             MisGroup.setType(WeaponGroupType.ALTERNATING);
  171.         }
  172.         MisGroup.setAutofireOnByDefault(false);
  173.         WeaponGroupSpec SMisGroup = new WeaponGroupSpec();
  174.         SMisGroup.setType(WeaponGroupType.LINKED);
  175.         SMisGroup.setAutofireOnByDefault(true);
  176.         WeaponGroupSpec AMisGroup = new WeaponGroupSpec();
  177.         if (linkedStrike) {
  178.             AMisGroup.setType(WeaponGroupType.LINKED);
  179.         } else {
  180.             AMisGroup.setType(WeaponGroupType.ALTERNATING);
  181.         }
  182.         AMisGroup.setAutofireOnByDefault(false);
  183.         WeaponGroupSpec LGroup = new WeaponGroupSpec();
  184.         LGroup.setType(WeaponGroupType.LINKED);
  185.         LGroup.setAutofireOnByDefault(false);
  186.         WeaponGroupSpec RGroup = new WeaponGroupSpec();
  187.         RGroup.setType(WeaponGroupType.LINKED);
  188.         RGroup.setAutofireOnByDefault(false);
  189.  
  190.         Collection<String> fittedSlots = variant.getFittedWeaponSlots();
  191.         for (String fittedSlot : fittedSlots) {
  192.             String weapon = variant.getWeaponId(fittedSlot);
  193.             String type = Global.getSettings().getDescription(weapon, Description.Type.WEAPON).getText2();
  194.             WeaponSlotAPI slot = null;
  195.             for (WeaponSlotAPI slott : slots) {
  196.                 if (slott.getId().equals(fittedSlot)) {
  197.                     slot = slott;
  198.                 }
  199.             }
  200.  
  201.             boolean antiFighter = false;
  202.             boolean pointDefense = false;
  203.             boolean strike = false;
  204.             boolean noAim = false;
  205.             boolean assault = false;
  206.             boolean closeSupport = false;
  207.             boolean fireSupport = false;
  208.             boolean missile = false;
  209.             boolean lowFlux = false;
  210.             boolean highFlux = false;
  211.             boolean hardpoint = false;
  212.             boolean limitedAmmo = false;
  213.             boolean beam = false;
  214.             boolean special = false;
  215.             boolean front = false;
  216.             boolean back = false;
  217.             boolean left = false;
  218.             boolean right = false;
  219.             WeaponSize size = WeaponSize.SMALL;
  220.  
  221.             if (slot != null) {
  222.                 if (slot.isHardpoint() || slot.getArc() <= 5f) {
  223.                     hardpoint = true;
  224.                 }
  225.                 if (slot.getAngle() <= 45f && slot.getAngle() >= -45f) {
  226.                     front = true;
  227.                 } else if (slot.getAngle() >= 45f && slot.getAngle() <= 135f) {
  228.                     left = true;
  229.                 } else if (slot.getAngle() > 135f || slot.getAngle() < -135f) {
  230.                     back = true;
  231.                 } else {
  232.                     right = true;
  233.                 }
  234.                 size = slot.getSlotSize();
  235.             }
  236.             if (getWeaponList("Missile").contains(weapon)) {
  237.                 missile = true;
  238.             }
  239.             if (getWeaponList("No Aim").contains(weapon)) {
  240.                 noAim = true;
  241.             }
  242.             if (getWeaponList("Anti-Fighter").contains(weapon)) {
  243.                 antiFighter = true;
  244.             }
  245.             if (getWeaponList("Point Defense").contains(weapon)) {
  246.                 pointDefense = true;
  247.             }
  248.             if (getWeaponList("Strike").contains(weapon)) {
  249.                 strike = true;
  250.             }
  251.             if (getWeaponList("Assault").contains(weapon)) {
  252.                 assault = true;
  253.             }
  254.             if (getWeaponList("Close Support").contains(weapon)) {
  255.                 closeSupport = true;
  256.             }
  257.             if (getWeaponList("Fire Support").contains(weapon)) {
  258.                 fireSupport = true;
  259.             }
  260.             if (getWeaponList("Special").contains(weapon)) {
  261.                 special = true;
  262.             }
  263.             if (getWeaponList("Low Flux").contains(weapon)) {
  264.                 lowFlux = true;
  265.             }
  266.             if (getWeaponList("High Flux").contains(weapon)) {
  267.                 highFlux = true;
  268.             }
  269.             if (getWeaponList("Sustained Beam").contains(weapon)) {
  270.                 beam = true;
  271.             }
  272.             if (getWeaponList("Limited Ammo").contains(weapon)) {
  273.                 limitedAmmo = true;
  274.             }
  275.             if (!getWeaponList("Override").contains(weapon)) {
  276.                 EnumSet<AIHints> hints = variant.getWeaponSpec(fittedSlot).getAIHints();
  277.                 for (AIHints hint : hints) {
  278.                     if (hint == AIHints.ANTI_FTR) {
  279.                         antiFighter = true;
  280.                     }
  281.                     if (hint == AIHints.PD || hint == AIHints.PD_ONLY) {
  282.                         pointDefense = true;
  283.                     }
  284.                     if (hint == AIHints.STRIKE) {
  285.                         strike = true;
  286.                     }
  287.                     if (hint == AIHints.DO_NOT_AIM || hint == AIHints.HEATSEEKER) {
  288.                         noAim = true;
  289.                     }
  290.                 }
  291.                 if (variant.getWeaponSpec(fittedSlot).getType() == WeaponType.MISSILE) {
  292.                     missile = true;
  293.                     lowFlux = true;
  294.                     limitedAmmo = true;
  295.                 }
  296.                 if (type.equals("Anti-Fighter")) {
  297.                     antiFighter = true;
  298.                 }
  299.                 if (type.equals("Point Defense")) {
  300.                     pointDefense = true;
  301.                 }
  302.                 if (type.equals("Strike")) {
  303.                     strike = true;
  304.                 }
  305.                 if (type.equals("Assault")) {
  306.                     assault = true;
  307.                 }
  308.                 if (type.equals("Close Support")) {
  309.                     closeSupport = true;
  310.                 }
  311.                 if (type.equals("Fire Support")) {
  312.                     fireSupport = true;
  313.                 }
  314.                 if (type.equals("Special")) {
  315.                     special = true;
  316.                 }
  317.             }
  318.  
  319.             if (hardpoint && (highFlux || (size == WeaponSize.LARGE && (variant.getHullSize() == HullSize.FRIGATE || variant.getHullSize() == HullSize.DESTROYER || variant.getHullSize() == HullSize.DEFAULT)))) {
  320.                 if (!beam) {
  321.                     HvyGroup.addSlot(fittedSlot);
  322.                 } else {
  323.                     BeaGroup.addSlot(fittedSlot);
  324.                 }
  325.             } else if (!hardpoint && (highFlux || (size == WeaponSize.LARGE && (variant.getHullSize() == HullSize.FRIGATE || variant.getHullSize() == HullSize.DESTROYER || variant.getHullSize() == HullSize.DEFAULT)))) {
  326.                 if (!beam) {
  327.                     HvyTGroup.addSlot(fittedSlot);
  328.                 } else {
  329.                     BeaTGroup.addSlot(fittedSlot);
  330.                 }
  331.             } else if (missile && left && enforceSides && !noAim && !limitedAmmo) {
  332.                 LGroup.addSlot(fittedSlot);
  333.             } else if (missile && right && enforceSides && !noAim && !limitedAmmo) {
  334.                 RGroup.addSlot(fittedSlot);
  335.             } else if (missile && limitedAmmo && (noAim || !hardpoint) && !strike) {
  336.                 MisGroup.addSlot(fittedSlot);
  337.             } else if (missile && !limitedAmmo && !strike) {
  338.                 SMisGroup.addSlot(fittedSlot);
  339.             } else if (missile && limitedAmmo && !noAim && !strike) {
  340.                 AMisGroup.addSlot(fittedSlot);
  341.             } else if (pointDefense && !hardpoint && !limitedAmmo) {
  342.                 PDGroup.addSlot(fittedSlot);
  343.             } else if (antiFighter) {
  344.                 AFGroup.addSlot(fittedSlot);
  345.             } else if (left && (hardpoint || enforceSides) && !lowFlux) {
  346.                 LGroup.addSlot(fittedSlot);
  347.             } else if (right && (hardpoint || enforceSides) && !lowFlux) {
  348.                 RGroup.addSlot(fittedSlot);
  349.             } else if (assault && hardpoint && !lowFlux) {
  350.                 AssGroup.addSlot(fittedSlot);
  351.             } else if (assault && !hardpoint && !lowFlux) {
  352.                 AssTGroup.addSlot(fittedSlot);
  353.             } else if (closeSupport && hardpoint && !lowFlux) {
  354.                 CSGroup.addSlot(fittedSlot);
  355.             } else if (closeSupport && !hardpoint && !lowFlux) {
  356.                 CSTGroup.addSlot(fittedSlot);
  357.             } else if (strike || limitedAmmo) {
  358.                 if (!beam) {
  359.                     StrGroup.addSlot(fittedSlot);
  360.                 } else {
  361.                     if (hardpoint) {
  362.                         BeaGroup.addSlot(fittedSlot);
  363.                     } else {
  364.                         BeaTGroup.addSlot(fittedSlot);
  365.                     }
  366.                 }
  367.             } else if (fireSupport || lowFlux || special) {
  368.                 SupGroup.addSlot(fittedSlot);
  369.             } else {
  370.                 SupGroup.addSlot(fittedSlot);
  371.             }
  372.         }
  373.  
  374.         int groupCount = 0;
  375.         if (!AssTGroup.getSlots().isEmpty()) {
  376.             groupCount++;
  377.         }
  378.         if (!CSTGroup.getSlots().isEmpty()) {
  379.             groupCount++;
  380.         }
  381.         if (!HvyTGroup.getSlots().isEmpty()) {
  382.             groupCount++;
  383.         }
  384.         if (!SMisGroup.getSlots().isEmpty()) {
  385.             groupCount++;
  386.         }
  387.         if (!AMisGroup.getSlots().isEmpty()) {
  388.             groupCount++;
  389.         }
  390.         if (!PDGroup.getSlots().isEmpty()) {
  391.             groupCount++;
  392.         }
  393.         if (!AFGroup.getSlots().isEmpty()) {
  394.             groupCount++;
  395.         }
  396.         if (!AssGroup.getSlots().isEmpty()) {
  397.             groupCount++;
  398.         }
  399.         if (!CSGroup.getSlots().isEmpty()) {
  400.             groupCount++;
  401.         }
  402.         if (!StrGroup.getSlots().isEmpty()) {
  403.             groupCount++;
  404.         }
  405.         if (!HvyGroup.getSlots().isEmpty()) {
  406.             groupCount++;
  407.         }
  408.         if (!SupGroup.getSlots().isEmpty()) {
  409.             groupCount++;
  410.         }
  411.         if (!MisGroup.getSlots().isEmpty()) {
  412.             groupCount++;
  413.         }
  414.         if (!LGroup.getSlots().isEmpty()) {
  415.             groupCount++;
  416.         }
  417.         if (!RGroup.getSlots().isEmpty()) {
  418.             groupCount++;
  419.         }
  420.         if (!BeaGroup.getSlots().isEmpty()) {
  421.             groupCount++;
  422.         }
  423.         if (!BeaTGroup.getSlots().isEmpty()) {
  424.             groupCount++;
  425.         }
  426.  
  427.         if (!AFGroup.getSlots().isEmpty()) {
  428.             if (groupCount > 5) {
  429.                 if (!PDGroup.getSlots().isEmpty()) {
  430.                     groupCount--;
  431.                 }
  432.                 for (String toAdd : AFGroup.getSlots()) {
  433.                     PDGroup.addSlot(toAdd);
  434.                 }
  435.                 AFGroup = null;
  436.             }
  437.         } else {
  438.             AFGroup = null;
  439.         }
  440.         if (!AssGroup.getSlots().isEmpty()) {
  441.             if (groupCount > 5) {
  442.                 if (!CSGroup.getSlots().isEmpty()) {
  443.                     groupCount--;
  444.                 }
  445.                 for (String toAdd : AssGroup.getSlots()) {
  446.                     CSGroup.addSlot(toAdd);
  447.                 }
  448.                 AssGroup = null;
  449.             }
  450.         } else {
  451.             AssGroup = null;
  452.         }
  453.         if (!splitMissiles) {
  454.             if (!AMisGroup.getSlots().isEmpty()) {
  455.                 if (groupCount > 5) {
  456.                     if (!MisGroup.getSlots().isEmpty()) {
  457.                         groupCount--;
  458.                     }
  459.                     for (String toAdd : AMisGroup.getSlots()) {
  460.                         MisGroup.addSlot(toAdd);
  461.                     }
  462.                     AMisGroup = null;
  463.                 }
  464.             } else {
  465.                 AMisGroup = null;
  466.             }
  467.         }
  468.         if (!PDGroup.getSlots().isEmpty()) {
  469.             if (groupCount > 5) {
  470.                 if (!SupGroup.getSlots().isEmpty()) {
  471.                     groupCount--;
  472.                 }
  473.                 for (String toAdd : PDGroup.getSlots()) {
  474.                     SupGroup.addSlot(toAdd);
  475.                 }
  476.                 PDGroup = null;
  477.             }
  478.         } else {
  479.             PDGroup = null;
  480.         }
  481.         if (!splitMissiles) {
  482.             if (!SMisGroup.getSlots().isEmpty()) {
  483.                 if (groupCount > 5) {
  484.                     if (!AssTGroup.getSlots().isEmpty()) {
  485.                         groupCount--;
  486.                     }
  487.                     for (String toAdd : SMisGroup.getSlots()) {
  488.                         AssTGroup.addSlot(toAdd);
  489.                     }
  490.                     SMisGroup = null;
  491.                 }
  492.             } else {
  493.                 SMisGroup = null;
  494.             }
  495.         }
  496.         if (!AssTGroup.getSlots().isEmpty()) {
  497.             if (groupCount > 5) {
  498.                 if (!CSTGroup.getSlots().isEmpty()) {
  499.                     groupCount--;
  500.                 }
  501.                 for (String toAdd : AssTGroup.getSlots()) {
  502.                     CSTGroup.addSlot(toAdd);
  503.                 }
  504.                 AssTGroup = null;
  505.             }
  506.         } else {
  507.             AssTGroup = null;
  508.         }
  509.         if (!BeaTGroup.getSlots().isEmpty()) {
  510.             if (groupCount > 5) {
  511.                 if (!CSTGroup.getSlots().isEmpty()) {
  512.                     groupCount--;
  513.                 }
  514.                 for (String toAdd : BeaTGroup.getSlots()) {
  515.                     CSTGroup.addSlot(toAdd);
  516.                 }
  517.                 BeaTGroup = null;
  518.             }
  519.         } else {
  520.             BeaTGroup = null;
  521.         }
  522.         if (!BeaGroup.getSlots().isEmpty()) {
  523.             if (groupCount > 5) {
  524.                 if (!CSGroup.getSlots().isEmpty()) {
  525.                     groupCount--;
  526.                 }
  527.                 for (String toAdd : BeaGroup.getSlots()) {
  528.                     CSGroup.addSlot(toAdd);
  529.                 }
  530.                 BeaGroup = null;
  531.             }
  532.         } else {
  533.             BeaGroup = null;
  534.         }
  535.         if (!enforceSides) {
  536.             if (!LGroup.getSlots().isEmpty()) {
  537.                 if (groupCount > 5) {
  538.                     if (!RGroup.getSlots().isEmpty()) {
  539.                         groupCount--;
  540.                     }
  541.                     for (String toAdd : LGroup.getSlots()) {
  542.                         RGroup.addSlot(toAdd);
  543.                     }
  544.                     LGroup = null;
  545.                 }
  546.             } else {
  547.                 LGroup = null;
  548.             }
  549.         }
  550.         if (!CSTGroup.getSlots().isEmpty()) {
  551.             if (groupCount > 5) {
  552.                 if (!SupGroup.getSlots().isEmpty()) {
  553.                     groupCount--;
  554.                 }
  555.                 for (String toAdd : CSTGroup.getSlots()) {
  556.                     SupGroup.addSlot(toAdd);
  557.                 }
  558.                 CSTGroup = null;
  559.             }
  560.         } else {
  561.             CSTGroup = null;
  562.         }
  563.         if (!HvyTGroup.getSlots().isEmpty()) {
  564.             if (groupCount > 5) {
  565.                 if (!HvyGroup.getSlots().isEmpty()) {
  566.                     groupCount--;
  567.                 }
  568.                 for (String toAdd : HvyTGroup.getSlots()) {
  569.                     HvyGroup.addSlot(toAdd);
  570.                 }
  571.                 HvyTGroup = null;
  572.             }
  573.         } else {
  574.             HvyTGroup = null;
  575.         }
  576.         if (!HvyGroup.getSlots().isEmpty()) {
  577.             if (groupCount > 5) {
  578.                 if (!StrGroup.getSlots().isEmpty()) {
  579.                     groupCount--;
  580.                 }
  581.                 for (String toAdd : HvyGroup.getSlots()) {
  582.                     StrGroup.addSlot(toAdd);
  583.                 }
  584.                 HvyGroup = null;
  585.             }
  586.         } else {
  587.             HvyGroup = null;
  588.         }
  589.         if (splitMissiles && AMisGroup != null) {
  590.             if (!AMisGroup.getSlots().isEmpty()) {
  591.                 if (groupCount > 5) {
  592.                     if (!MisGroup.getSlots().isEmpty()) {
  593.                         groupCount--;
  594.                     }
  595.                     for (String toAdd : AMisGroup.getSlots()) {
  596.                         MisGroup.addSlot(toAdd);
  597.                     }
  598.                     AMisGroup = null;
  599.                 }
  600.             } else {
  601.                 AMisGroup = null;
  602.             }
  603.         }
  604.         if (splitMissiles && SMisGroup != null) {
  605.             if (!SMisGroup.getSlots().isEmpty()) {
  606.                 if (groupCount > 5) {
  607.                     if (!SupGroup.getSlots().isEmpty()) {
  608.                         groupCount--;
  609.                     }
  610.                     for (String toAdd : SMisGroup.getSlots()) {
  611.                         SupGroup.addSlot(toAdd);
  612.                     }
  613.                     SMisGroup = null;
  614.                 }
  615.             } else {
  616.                 SMisGroup = null;
  617.             }
  618.         }
  619.         if (enforceSides) {
  620.             if (!CSGroup.getSlots().isEmpty()) {
  621.                 if (groupCount > 5) {
  622.                     if (!SupGroup.getSlots().isEmpty()) {
  623.                         groupCount--;
  624.                     }
  625.                     for (String toAdd : CSGroup.getSlots()) {
  626.                         SupGroup.addSlot(toAdd);
  627.                     }
  628.                     CSGroup = null;
  629.                 }
  630.             } else {
  631.                 CSGroup = null;
  632.             }
  633.         } else {
  634.             if (CSGroup.getSlots().isEmpty()) {
  635.                 CSGroup = null;
  636.             }
  637.         }
  638.         if (enforceSides && LGroup != null) {
  639.             if (LGroup.getSlots().isEmpty()) {
  640.                 LGroup = null;
  641.             }
  642.         }
  643.         if (RGroup.getSlots().isEmpty()) {
  644.             RGroup = null;
  645.         }
  646.         if (StrGroup.getSlots().isEmpty()) {
  647.             StrGroup = null;
  648.         }
  649.         if (SupGroup.getSlots().isEmpty()) {
  650.             SupGroup = null;
  651.         }
  652.         if (MisGroup.getSlots().isEmpty()) {
  653.             MisGroup = null;
  654.         }
  655.  
  656.         if (variant.getWeaponGroups().size() < 5) {
  657.             for (int i = variant.getWeaponGroups().size(); i < 5; i++) {
  658.                 variant.addWeaponGroup(new WeaponGroupSpec());
  659.             }
  660.         }
  661.  
  662.         int currentGroup = 0;
  663.         if (HvyGroup != null) {
  664.             integrateGroup(HvyGroup, variant.getGroup(currentGroup));
  665.             currentGroup++;
  666.         }
  667.         if (HvyTGroup != null) {
  668.             integrateGroup(HvyTGroup, variant.getGroup(currentGroup));
  669.             currentGroup++;
  670.         }
  671.         if (BeaGroup != null) {
  672.             integrateGroup(BeaGroup, variant.getGroup(currentGroup));
  673.             currentGroup++;
  674.         }
  675.         if (BeaTGroup != null) {
  676.             integrateGroup(BeaTGroup, variant.getGroup(currentGroup));
  677.             currentGroup++;
  678.         }
  679.         if (LGroup != null) {
  680.             integrateGroup(LGroup, variant.getGroup(currentGroup));
  681.             currentGroup++;
  682.         }
  683.         if (RGroup != null) {
  684.             integrateGroup(RGroup, variant.getGroup(currentGroup));
  685.             currentGroup++;
  686.         }
  687.         if (AssGroup != null) {
  688.             integrateGroup(AssGroup, variant.getGroup(currentGroup));
  689.             currentGroup++;
  690.         }
  691.         if (CSGroup != null) {
  692.             integrateGroup(CSGroup, variant.getGroup(currentGroup));
  693.             currentGroup++;
  694.         }
  695.         if (AssTGroup != null) {
  696.             integrateGroup(AssTGroup, variant.getGroup(currentGroup));
  697.             currentGroup++;
  698.         }
  699.         if (CSTGroup != null) {
  700.             integrateGroup(CSTGroup, variant.getGroup(currentGroup));
  701.             currentGroup++;
  702.         }
  703.         if (StrGroup != null) {
  704.             integrateGroup(StrGroup, variant.getGroup(currentGroup));
  705.             currentGroup++;
  706.         }
  707.         if (AMisGroup != null) {
  708.             integrateGroup(AMisGroup, variant.getGroup(currentGroup));
  709.             currentGroup++;
  710.         }
  711.         if (MisGroup != null) {
  712.             integrateGroup(MisGroup, variant.getGroup(currentGroup));
  713.             currentGroup++;
  714.         }
  715.         if (SMisGroup != null) {
  716.             integrateGroup(SMisGroup, variant.getGroup(currentGroup));
  717.             currentGroup++;
  718.         }
  719.         if (SupGroup != null) {
  720.             integrateGroup(SupGroup, variant.getGroup(currentGroup));
  721.             currentGroup++;
  722.         }
  723.         if (AFGroup != null) {
  724.             integrateGroup(AFGroup, variant.getGroup(currentGroup));
  725.             currentGroup++;
  726.         }
  727.         if (PDGroup != null) {
  728.             integrateGroup(PDGroup, variant.getGroup(currentGroup));
  729.             currentGroup++;
  730.         }
  731.     }
  732.  
  733.     private static void integrateGroup(WeaponGroupSpec source, WeaponGroupSpec destination) {
  734.         for (String slot : source.getSlots()) {
  735.             destination.addSlot(slot);
  736.         }
  737.         destination.setType(source.getType());
  738.         destination.setAutofireOnByDefault(source.isAutofireOnByDefault());
  739.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement