Package megamek.common

Examples of megamek.common.WeaponType


                    // RACs count for a significant portion of possible damage
                    int rac_damage = 0;
                    int other_damage = 0;
                    int clearance_range = 0;
                    for (Mounted equip : min.getCEntity().entity.getWeaponList()) {
                        WeaponType test_weapon = new WeaponType();

                        test_weapon = (WeaponType) equip.getType();
                        if ((test_weapon.getAmmoType() == AmmoType.T_AC_ROTARY)
                                && (equip.isJammed() == true)) {
                            rac_damage = rac_damage + 4 * (test_weapon.getDamage());
                        } else {
                            if (equip.canFire()) {
                                other_damage += test_weapon.getDamage();
                                if (test_weapon.getMediumRange() > clearance_range) {
                                    clearance_range = test_weapon.getMediumRange();
                                }
                            }
                        }
                    }
                    // Even if the jammed RAC doesn't make up a significant
View Full Code Here


        int spin_mode = 0;
        int starg_mod;
        ArrayList<AttackOption> result = new ArrayList<AttackOption>();
        Enumeration<Entity> ents = game.getValidTargets(en).elements();
        WeaponAttackAction wep_test;
        WeaponType spinner;
        AttackOption a = null;
        AttackOption max = new AttackOption(null, null, 0, null, 1);
        while (ents.hasMoreElements()) {
            Entity e = ents.nextElement();
            CEntity enemy = centities.get(e);
            // long entry = System.currentTimeMillis();
            ToHitData th = WeaponAttackAction.toHit(game, from, e, weaponID);
            // long exit = System.currentTimeMillis();
            // if (exit != entry)
            // System.out.println("Weapon attack toHit took "+(exit-entry));
            if (th.getValue() != TargetRoll.IMPOSSIBLE && !(th.getValue() >= 13)) {
                double expectedDmg;

                wep_test = new WeaponAttackAction(from, e.getId(), weaponID);

                // If this is an Ultra or Rotary cannon, check for spin up
                spinner = (WeaponType) mw.getType();
                if ((spinner.getAmmoType() == AmmoType.T_AC_ULTRA)
                        || (spinner.getAmmoType() == AmmoType.T_AC_ULTRA_THB)
                        || (spinner.getAmmoType() == AmmoType.T_AC_ROTARY)) {
                    spin_mode = Compute.spinUpCannon(game, wep_test);
                    super.sendModeChange(from, weaponID, spin_mode);
                }

                // Ammo cycler runs each valid ammo type through the weapon
View Full Code Here

        int spin_mode = 0;
        double max = java.lang.Double.NEGATIVE_INFINITY;
        int[] results = null;
        ArrayList<ArrayList<AttackOption>> winner = null;
        int arc = 0;
        WeaponType spinner;

        if (entity_num == -1) {
            return;
        }

        do {
            Entity en = game.getEntity(entity_num);
            CEntity cen = centities.get(en);

            GAAttack test = bestAttack(cen.current, null, 3);

            if (test != null && test.getFittestChromosomesFitness() > max) {
                max = test.getFittestChromosomesFitness();
                results = test.getResultChromosome();
                arc = test.getFiringArc();
                best_entity = entity_num;
                winner = test.getAttack();
            }
            entity_num = game.getNextEntityNum(getMyTurn(), entity_num);
        } while (entity_num != first_entity && entity_num != -1);

        Vector<EntityAction> av = new Vector<EntityAction>();
        // maximum already selected (or default)
        Entity en = game.getEntity(best_entity);
        if (results != null) {
            Entity primary_target = game.getEntitiesVector().get(results[results.length - 1]);
            TreeSet<AttackOption> tm = new TreeSet<AttackOption>(new AttackOption.Sorter(centities
                    .get(primary_target)));
            for (int i = 0; i < results.length - 1; i++) {
                if (winner != null) {
                    AttackOption a = winner.get(i).get(results[i]);
                    if (a.target != null) {
                        a.target.expected_damage[a.toHit.getSideTable()] += a.value;
                        a.target.hasTakenDamage = true;
                        tm.add(a);
                    }
                }
            }
            Iterator<AttackOption> i = tm.iterator();
            while (i.hasNext()) {
                AttackOption a = i.next();

                WeaponAttackAction new_attack = new WeaponAttackAction(en.getId(), a.target
                        .getEntity().getId(), en.getEquipmentNum(a.weapon));

                if (en.getEquipment(new_attack.getWeaponId()).getLinked() != null) {
                    spinner = (WeaponType) a.weapon.getType();

                    // If this is an ultra-cannon or rotary cannon, try to spin
                    // it up

                    if ((spinner.getAmmoType() == AmmoType.T_AC_ULTRA)
                            || (spinner.getAmmoType() == AmmoType.T_AC_ULTRA_THB)
                            || (spinner.getAmmoType() == AmmoType.T_AC_ROTARY)) {
                        spin_mode = Compute.spinUpCannon(game, new_attack);
                        super.sendModeChange(en.getId(), en.getEquipmentNum(a.weapon), spin_mode);
                    }
                    Mounted cur_ammo = en.getEquipment(new_attack.getWeaponId()).getLinked();
                    new_attack.setAmmoId(en.getEquipmentNum(cur_ammo));
View Full Code Here

        // cluster of enemies in range

        av_range = 0.0;
        weapon_count = 0;
        for (Mounted mounted : getEntity(entNum).getWeaponList()) {
            WeaponType wtype = (WeaponType) mounted.getType();
            if ((wtype.getName() != "ATM 3") && (wtype.getName() != "ATM 6")
                    && (wtype.getName() != "ATM 9") && (wtype.getName() != "ATM 12")) {
                if (getEntity(entNum).getC3Master() != null) {
                    av_range += ((wtype.getLongRange()) * 1.25);
                } else {
                    av_range += wtype.getLongRange();
                }
                weapon_count++;
            }
        }
        for (Mounted mounted : getEntity(entNum).getAmmo()) {
View Full Code Here

                    // RACs count for a significant portion of possible damage
                    int rac_damage = 0;
                    int other_damage = 0;
                    int clearance_range = 0;
                    for (Mounted equip : min.getCEntity().entity.getWeaponList()) {
                        WeaponType test_weapon = new WeaponType();

                        test_weapon = (WeaponType) equip.getType();
                        if ((test_weapon.getAmmoType() == AmmoType.T_AC_ROTARY)
                                && (equip.isJammed() == true)) {
                            rac_damage = rac_damage + 4 * (test_weapon.getDamage());
                        } else {
                            if (equip.canFire()) {
                                other_damage += test_weapon.getDamage();
                                if (test_weapon.getMediumRange() > clearance_range) {
                                    clearance_range = test_weapon.getMediumRange();
                                }
                            }
                        }
                    }
                    // Even if the jammed RAC doesn't make up a significant
View Full Code Here

        if (target != null && weapon != null) {
            if (weapon.getType().getModesCount() > 0) {
                use_mode = weapon.curMode().getName();
            }
            WeaponType w = (WeaponType) weapon.getType();

            // As a primary attack. Damage is already odds-adjusted.
            primary_odds = Compute.oddsAbove(toHit.getValue()) / 100.0;
            primary_expected = this.value;

            // As a secondary attack. Raw damage is extracted, then adjusted
            // for secondary to-hit odds. Since units with active Stealth armor
            // cannot be secondary targets, chances of hitting are 0.

            if (target.getEntity().isStealthActive()) {
                odds = 0.0;
            } else {
                odds = sec_mod <= 12 ? (Compute.oddsAbove(toHit.getValue()
                        + sec_mod) / 100.0) : 0.0;
            }
            heat = w.getHeat();
            expected = this.value / primary_odds;
            expected = expected * odds;

            // Check for ammo; note that some conventional infantry and BA
            // weapons do NOT return AmmoType.T_NA

            final boolean isInfantryWeapon = w.hasFlag(WeaponType.F_INFANTRY);
            final boolean usesAmmo = (!isInfantryWeapon & w.getAmmoType() != AmmoType.T_NA);

            final Mounted ammo = usesAmmo ? weapon.getLinked() : null;
            if (usesAmmo && (ammo == null || ammo.getShotsLeft() == 0)) {
                this.value = 0.0; // should have already been caught...
                primary_expected = 0.0;
View Full Code Here

            primary = primary_target;
        }

        public int compare(AttackOption a, AttackOption a1) {
            if (a.target.getKey().intValue() == a1.target.getKey().intValue()) {
                WeaponType w = (WeaponType) a.weapon.getType();
                WeaponType w1 = (WeaponType) a1.weapon.getType();
                if (w.getDamage() == WeaponType.DAMAGE_MISSILE) {
                    if (w1.getDamage() == WeaponType.DAMAGE_MISSILE) {
                        if (a.expected > a1.expected) {
                            return -1;
                        }
                        return 1;
                    }
View Full Code Here

        // Increase average range if the unit has an active c3 link

        av_range = 0.0;
        weapon_count = 0;
        for (Mounted mounted : deployed_ent.getWeaponList()) {
            WeaponType wtype = (WeaponType) mounted.getType();
            if ((wtype.getName() != "ATM 3") && (wtype.getName() != "ATM 6")
                    && (wtype.getName() != "ATM 9")
                    && (wtype.getName() != "ATM 12")) {
                if (deployed_ent.getC3Master() != null) {
                    av_range += wtype.getLongRange() * 1.25;
                } else {
                    av_range += wtype.getLongRange();
                }
                weapon_count++;
            }
        }
        for (Mounted mounted : deployed_ent.getAmmo()) {
View Full Code Here

        }

        // TODO : update for BattleArmor.

        float fDamage = 0.0f;
        WeaponType wt = (WeaponType) weapon.getType();
        if (wt.getDamage() == WeaponType.DAMAGE_MISSILE) {
            if (weapon.getLinked() == null) {
                return 0.0f;
            }
            AmmoType at = (AmmoType) weapon.getLinked().getType();

            float fHits = 0.0f;
            if ((wt.getAmmoType() == AmmoType.T_SRM_STREAK)
                    || (wt.getAmmoType() == AmmoType.T_MRM_STREAK)
                    || (wt.getAmmoType() == AmmoType.T_LRM_STREAK)) {
                fHits = wt.getRackSize();
            } else if (wt.getRackSize() == 40 || wt.getRackSize() == 30) {
                fHits = 2.0f * expectedHitsByRackSize[wt.getRackSize() / 2];
            } else {
                fHits = expectedHitsByRackSize[wt.getRackSize()];
            }
            // adjust for previous AMS
            ArrayList<Mounted> vCounters = waa.getCounterEquipment();
            if (vCounters != null) {
                for (int x = 0; x < vCounters.size(); x++) {
                    EquipmentType type = vCounters.get(x).getType();
                    if (type instanceof WeaponType
                            && type.hasFlag(WeaponType.F_AMS)) {
                        float fAMS = 3.5f * ((WeaponType) type).getDamage();
                        fHits = Math.max(0.0f, fHits - fAMS);
                    }
                }
            }
            // damage is expected missiles * damage per missile
            fDamage = fHits * at.getDamagePerShot();
        } else {
            fDamage = wt.getDamage();
        }

        fDamage *= fChance;
        return fDamage;
    }
View Full Code Here

    }

    private String getWeapons(boolean showDetail) {
        StringBuffer sWeapons = new StringBuffer();
        for (Mounted mounted : entity.getWeaponList()) {
            WeaponType wtype = (WeaponType) mounted.getType();

            sWeapons.append(mounted.getDesc()).append("  [") //$NON-NLS-1$
                    .append(entity.getLocationAbbr(mounted.getLocation()));
            if (mounted.isSplit()) {
                sWeapons.append("/") // $NON-NLS-1$
                        .append(
                                entity.getLocationAbbr(mounted
                                        .getSecondLocation()));
            }
            sWeapons.append("]"); //$NON-NLS-1$
            if (entity.isClan()
                    && mounted.getType().getInternalName().substring(0, 2)
                            .equals("IS")) { //$NON-NLS-1$
                sWeapons.append(Messages.getString("MechView.IS")); //$NON-NLS-1$
            }
            if (!entity.isClan()
                    && mounted.getType().getInternalName().substring(0, 2)
                            .equals("CL")) { //$NON-NLS-1$
                sWeapons.append(Messages.getString("MechView.Clan")); //$NON-NLS-1$
            }
            if (wtype.hasFlag(WeaponType.F_ONESHOT)) {
                sWeapons.append(" <") //$NON-NLS-1$
                        .append(mounted.getLinked().getDesc()).append(">"); //$NON-NLS-1$
            }

            if(wtype instanceof BayWeapon) {
                //loop through weapons in bay and add up heat
                int heat = 0;
                for(int wId : mounted.getBayWeapons()) {
                    Mounted m = entity.getEquipment(wId);
                    if(null == m) {
                        continue;
                    }
                    heat = heat + ((WeaponType)m.getType()).getHeat();
                }
                sWeapons.append(" ").append(heat).append(Messages.getString("MechView.Heat")); //$NON-NLS-1$ //$NON-NLS-2$
            } else {
                sWeapons.append(" ").append(wtype.getHeat()).append(Messages.getString("MechView.Heat")); //$NON-NLS-1$ //$NON-NLS-2$
            }

            sWeapons.append("\n"); //$NON-NLS-1$

//          if this is a weapon bay, then cycle through weapons and ammo
            if((wtype instanceof BayWeapon) && showDetail) {
                for(int wId : mounted.getBayWeapons()) {
                    Mounted m = entity.getEquipment(wId);
                    if(null == m) {
                        continue;
                    }

                    WeaponType newwtype = (WeaponType)m.getType();

                    sWeapons.append("  ")
                        .append( m.getDesc() );

                    if (entity.isClan() &&
                        m.getType().getInternalName().substring(0,2).equals("IS")) { //$NON-NLS-1$
                        sWeapons.append(Messages.getString("MechView.IS")); //$NON-NLS-1$
                    }
                    if (!entity.isClan() &&
                        m.getType().getInternalName().substring(0,2).equals("CL")) { //$NON-NLS-1$
                        sWeapons.append(Messages.getString("MechView.Clan")); //$NON-NLS-1$
                    }
                    if (newwtype.hasFlag(WeaponType.F_ONESHOT)) {
                        sWeapons.append(" <") //$NON-NLS-1$
                            .append(mounted.getLinked().getDesc())
                            .append(">"); //$NON-NLS-1$
                    }
View Full Code Here

TOP

Related Classes of megamek.common.WeaponType

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.