private boolean hasFireExtinguisher() { if (myEntity.getWeaponList().size() < 1) { return false; } for (Mounted weapon : myEntity.getWeaponList()) { if (((WeaponType) weapon.getType() instanceof ISFireExtinguisher) || ((WeaponType) weapon.getType() instanceof CLFireExtinguisher)) { return true; } } return false; }
private boolean hasWeaponFlag(BigInteger weaponFlag) { if (myEntity.getWeaponList().size() < 1) { return false; } for (Mounted wpn : myEntity.getWeaponList()) { if (((WeaponType) wpn.getType()).hasFlag(weaponFlag)) { return true; } } return false; }
public boolean hasTAG() { for (Mounted m : getWeaponList()) { WeaponType equip = (WeaponType) (m.getType()); if ((equip != null) && (equip.hasFlag(WeaponType.F_TAG))) { return true; } } return false; }
private void setupRapidfireMGs() { GridBagLayout gbl = new GridBagLayout(); panRapidfireMGs.setLayout(gbl); for (Mounted m : entity.getWeaponList()) { WeaponType wtype = (WeaponType) m.getType(); if (!wtype.hasFlag(WeaponType.F_MG)) { continue; } RapidfireMGPanel rmp = new RapidfireMGPanel(m); panRapidfireMGs.add(rmp, GBC.eol()); m_vMGs.add(rmp); } }
public int getNextWeaponListIdx() { int selected = weaponList.getSelectedIndex(); // In case nothing was selected if (selected == -1) { selected = weaponList.getModel().getSize() - 1; } Mounted selectedWeap; int initialSelection = selected; boolean hasLooped = false; do { selected++; if (selected >= weaponList.getModel().getSize()) { selected = 0; } if (selected == initialSelection) { hasLooped = true; } selectedWeap = ((WeaponListModel) weaponList.getModel()) .getWeaponAt(selected); } while (!hasLooped && !entity.isWeaponValidForPhase(selectedWeap)); if ((selected >= 0) && (selected < entity.getWeaponList().size()) && !hasLooped) { return selected; } else { return -1; } }
public int getNextWeaponNum() { int selected = getNextWeaponListIdx(); if ((selected >= 0) && (selected < entity.getWeaponList().size())) { return entity.getEquipmentNum(((WeaponListModel) weaponList .getModel()).getWeaponAt(selected)); } else { return -1; } }
/** * Selects the prevous valid weapon in the weapon list. * * @return The weaponId for the selected weapon */ public int selectPrevWeapon() { int selected = getPrevWeaponListIdx(); weaponList.setSelectedIndex(selected); weaponList.ensureIndexIsVisible(selected); if ((selected >= 0) && (selected < entity.getWeaponList().size())) { return entity.getEquipmentNum(((WeaponListModel) weaponList .getModel()).getWeaponAt(selected)); } else { return -1; } }
/** * Selects the next valid weapon in the weapon list. * * @return The weaponId for the selected weapon */ public int selectNextWeapon() { int selected = getNextWeaponListIdx(); weaponList.setSelectedIndex(selected); weaponList.ensureIndexIsVisible(selected); if ((selected >= 0) && (selected < entity.getWeaponList().size())) { return entity.getEquipmentNum(((WeaponListModel) weaponList .getModel()).getWeaponAt(selected)); } else { return -1; } }
public boolean usedTag() { for (Mounted weapon : getWeaponList()) { WeaponType wtype = (WeaponType) weapon.getType(); if (weapon.isUsedThisRound() && wtype.hasFlag(WeaponType.F_TAG)) { return true; } } return false; }
/** * Worker function that creates a series of weapon ammo choice panels that allow the user to pick a particular ammo bin for an * ammo-using weapon with matching ammo. */ private void setupWeaponAmmoChoice() { GridBagLayout gbl = new GridBagLayout(); panWeaponAmmoSelector.setLayout(gbl); for(Mounted weapon : entity.getWeaponList()) { WeaponType weaponType = weapon.getType() instanceof WeaponType ? (WeaponType) weapon.getType() : null; // don't deal with bay or grouped weapons for now if(weaponType == null || weaponType.getAmmoType() == AmmoType.T_NA) { continue; } WeaponAmmoChoicePanel ammoChoicePanel = new WeaponAmmoChoicePanel(weapon); panWeaponAmmoSelector.add(ammoChoicePanel, GBC.eol()); m_vWeaponAmmoChoice.add(ammoChoicePanel); } }
/** * Selects the first valid weapon in the weapon list. * @return The weapon id of the weapon selected */ public int selectFirstWeapon() { // Entity has no weapons, return -1; if (entity.getWeaponList().size() == 0 || (entity.usesWeaponBays() && entity.getWeaponBayList().size() == 0)) { return -1; } WeaponListModel weapList = (WeaponListModel)weaponList.getModel(); for (int i = 0; i < weaponList.getModel().getSize(); i++) { Mounted selectedWeap = weapList.getWeaponAt(i); if (entity.isWeaponValidForPhase(selectedWeap)) { weaponList.setSelectedIndex(i); weaponList.ensureIndexIsVisible(i); return entity.getEquipmentNum(selectedWeap); } } // Found no valid weapon weaponList.setSelectedIndex(-1); return -1; }
private void initGUI() { //Set up the megamek QuirksPanel. for (Mounted m : entity.getWeaponList()) { h_wpnQuirks.put(entity.getEquipmentNum(m), m.getQuirks()); } qpanel = new QuirksPanel(entity, entity.getQuirks(), true, this, h_wpnQuirks); qpanel.refreshQuirks(); //Set up the display of this dialog. JScrollPane scroller = new JScrollPane(qpanel); scroller.setPreferredSize(new Dimension(300,200)); setLayout(new BorderLayout()); add(scroller, BorderLayout.CENTER); add(buildButtonPanel(), BorderLayout.SOUTH); }
@Override public void setUnit(Unit u) { super.setUnit(u); if(null != unit) { weight = 0; for (Mounted m : unit.getEntity().getWeaponList()) { WeaponType wt = (WeaponType) m.getType(); if (m.getLocation() == this.loc) { weight += wt.getTonnage(unit.getEntity()) / 10.0; } } weight = Math.ceil(weight * 2) / 2; } }
@Override public StringBuffer printWeapon(StringBuffer buff, int posLoc, int posWeight) { for (Mounted m : getEntity().getWeaponList()) { WeaponType mt = (WeaponType) m.getType(); buff.append(StringUtil.makeLength(mt.getName(), 20)); buff.append( StringUtil.makeLength(getLocationAbbr(m.getLocation()), getPrintSize() - 5 - 20)) .append(TestEntity.makeWeightString(round(mt .getTonnage(getEntity()), Ceil.KILO))).append("\n"); } return buff; }
public boolean isEligibleForTargetingPhase() { if (isAssaultDropInProgress()) { return false; } for (Mounted mounted : getWeaponList()) { WeaponType wtype = (WeaponType) mounted.getType(); if ((wtype != null) && (wtype.hasFlag(WeaponType.F_ARTILLERY))) { return true; } //Bearings-only capital missiles fire during the targeting phase if ((wtype instanceof TeleOperatedMissileBayWeapon) || (wtype instanceof CapitalMissileBayWeapon) || (wtype instanceof AR10BayWeapon)) { if (mounted.isInBearingsOnlyMode()) { return true; } } } return false; }
public StringBuffer printWeapon(StringBuffer buff, int posLoc, int posWeight) { for (Mounted m : getEntity().getWeaponList()) { WeaponType mt = (WeaponType) m.getType(); // Don't think this can happen, but ... if (m.getLocation() == Entity.LOC_NONE) { continue; } buff.append(StringUtil.makeLength(mt.getName(), 20)); buff.append( StringUtil.makeLength(getLocationAbbr(m.getLocation()), getPrintSize() - 5 - 20)) .append(TestEntity.makeWeightString(mt .getTonnage(getEntity()))).append("\n"); } return buff; }
private Entity setupGunEmplacement() { Entity testEntity = Mockito.mock(GunEmplacement.class); Mockito.when(testEntity.calculateBattleValue()).thenCallRealMethod(); Mockito.when(testEntity.calculateBattleValue(Mockito.anyBoolean(), Mockito.anyBoolean())).thenCallRealMethod(); Mockito.when(testEntity.getTotalArmor()).thenReturn(100); ArrayList<Mounted> equipment = new ArrayList<Mounted>(2); WeaponType ppcType = Mockito.mock(WeaponType.class); Mockito.when(ppcType.getBV(Mockito.any(Entity.class))).thenReturn(50.0); Mounted ppc = Mockito.mock(Mounted.class); Mockito.when(ppc.getType()).thenReturn(ppcType); Mockito.when(ppc.isDestroyed()).thenReturn(false); equipment.add(ppc); equipment.add(ppc); Mockito.when(testEntity.getEquipment()).thenReturn(equipment); Mockito.when(testEntity.getWeaponList()).thenReturn(equipment); Mockito.when(testEntity.getAmmo()).thenReturn(new ArrayList<Mounted>(0)); return testEntity; }
/** * Test to make sure that Princess will choose a FiringPlan that shots at * a MechWarrior, instead of choosing to do nothing. */ @Test public void testCalcFiringPlansAtMechwarrior() { mockTarget = Mockito.mock(MechWarrior.class); Mockito.when(mockPPCFireInfo.getProbabilityToHit()).thenReturn(0.6); Mockito.when(mockPPCFireInfo.getHeat()).thenReturn(10); Mockito.when(mockPPCFireInfo.getExpectedDamageOnHit()).thenReturn(10.0); Mockito.when(mockMLFireInfo.getProbabilityToHit()).thenReturn(0.6); Mockito.when(mockMLFireInfo.getHeat()).thenReturn(3); Mockito.when(mockMLFireInfo.getExpectedDamageOnHit()).thenReturn(5.0); Mockito.when(mockLRMFireInfo.getProbabilityToHit()).thenReturn(0.6); Mockito.when(mockLRMFireInfo.getHeat()).thenReturn(1); Mockito.when(mockLRMFireInfo.getExpectedDamageOnHit()).thenReturn(3.0); Mockito.doReturn(0.0).when(testFireControl).calcDamageAllocationUtility(Mockito.any(Targetable.class), Mockito.anyDouble()); Mockito.when(mockShooter.getPosition()).thenReturn(mockShooterCoords); Mockito.when(mockTarget.getPosition()).thenReturn(mockTargetCoords); Mockito.when(mockShooter.getWeaponList()).thenReturn(shooterWeapons); final FiringPlan plan = testFireControl.getBestFiringPlan(mockShooter, mockTarget, mockGame, testToHitThreshold); Assert.assertFalse("Expected not 0.0. Got " + plan.getUtility(), 0.00001 > Math.abs(0 - plan.getUtility())); } }
public boolean hasLinkedMGA(Mounted mounted) { for (Mounted m : getWeaponList()) { if ((m.getLocation() == mounted.getLocation()) && m.getType().hasFlag(WeaponType.F_MGA) && !(m.isDestroyed() || m.isBreached()) && m.getBayWeapons().contains(getEquipmentNum(mounted)) && m.getType().hasModes() && m.curMode().equals("Linked")) { return true; } } return false; }
public boolean isEligibleForOffboard() { // if you're charging, no shooting if (isUnjammingRAC() || isCharging() || isMakingDfa()) { return false; } // if you're offboard, no shooting if (isOffBoard() || isAssaultDropInProgress()) { return false; } for (Mounted mounted : getWeaponList()) { WeaponType wtype = (WeaponType) mounted.getType(); if ((wtype != null) && (wtype.hasFlag(WeaponType.F_TAG) && mounted.isReady())) { return true; } } return false;// only things w/ tag are }