Package megamek.common

Examples of megamek.common.Entity


     *             <code>Entity</code>.
     */
    public static Entity decode(ParsedXML node, IGame game) {
        String attrStr = null;
        int attrVal = 0;
        Entity entity = null;
        Vector<ParsedXML> locations = new Vector<ParsedXML>();
        ParsedXML pilotNode = null;
        ParsedXML equipNode = null;
        Enumeration<?> children = null;
        ParsedXML child = null;
        String childName;

        // Did we get a null node?
        if (null == node) {
            throw new IllegalArgumentException("The entity is null.");
        }

        // Make sure that the node is for a Entity object.
        if (!node.getName().equals("entity")) {
            throw new IllegalStateException("Not passed a entity node.");
        }

        // TODO : perform version checking.

        // Walk the entity node's children, finding bits for later parsing..
        children = node.elements();
        while (children.hasMoreElements()) {
            child = (ParsedXML) children.nextElement();
            childName = child.getName();

            // Handle null child childNames.
            if (null == childName) {

                // No-op.
            }

            // Did we find the pilot node?
            else if (childName.equals("pilot")) {

                // Save the entity's pilot for later decoding.
                pilotNode = child;

            } // End found-"entityEquipment"-node

            // Did we find the entityData node?
            else if (childName.equals("entityData")) {

                // Did we find the entity already?
                if (null != entity) {
                    throw new IllegalStateException(
                            "Found two entityData nodes for an Entity node.");
                }

                // Decode the entity data.
                entity = EntityEncoder.decodeEntityData(child, game);

            } // End found-"entityData"-node

            // Did we find the entityEquipment node?
            else if (childName.equals("entityEquipment")) {

                // Save the entity equipment for later decoding.
                equipNode = child;

            } // End found-"entityEquipment"-node

            // Did we find the location node?
            else if (childName.equals("location")) {

                // Save this location for later decoding.
                locations.addElement(child);

            } // End found-"location"-node

        } // Look at the next child.

        // Did we find the needed elements?
        if (null == entity) {
            throw new IllegalStateException(
                    "Couldn't locate the entityData for an Entity node.");
        } else if (null == pilotNode) {
            throw new IllegalStateException(
                    "Couldn't locate the pilot for an Entity node.");
        } else if (null == equipNode) {
            throw new IllegalStateException(
                    "Couldn't locate the entityEquipment for an Entity node.");
        } else if (locations.size() != entity.locations()) {
            StringBuffer msgBuf = new StringBuffer();
            msgBuf.append("Found ").append(locations.size()).append(
                    " locations for an Entity node. ").append(
                    "Was expecting to find ").append(entity.locations())
                    .append(".");
            throw new IllegalStateException(msgBuf.toString());
        }

        // Decode the entity node's chassis.
        attrStr = node.getAttribute("chassis");
        if (null == attrStr) {
            throw new IllegalStateException(
                    "Couldn't decode the chassis from an Entity node.");
        }
        entity.setChassis(attrStr);

        // Decode the entity node's model.
        attrStr = node.getAttribute("model");
        if (null == attrStr) {
            throw new IllegalStateException(
                    "Couldn't decode the model from an Entity node.");
        }
        entity.setModel(attrStr);

        // Decode the entity node's movement type.
        attrStr = node.getAttribute("typeVal");
        if (null == attrStr) {
            throw new IllegalStateException(
                    "Couldn't decode the typeVal from an Entity node.");
        }

        // Try to pull the value from the string
        try {
            attrVal = Integer.parseInt(attrStr);
        } catch (NumberFormatException exp) {
            throw new IllegalStateException("Couldn't get an integer from "
                    + attrStr);
        }
        entity.setMovementMode(attrVal);

        // Decode the entity node's year.
        attrStr = node.getAttribute("year");
        if (null == attrStr) {
            throw new IllegalStateException(
                    "Couldn't decode the year from an Entity node.");
        }

        // Try to pull the value from the string
        try {
            attrVal = Integer.parseInt(attrStr);
        } catch (NumberFormatException exp) {
            throw new IllegalStateException("Couldn't get an integer from "
                    + attrStr);
        }
        entity.setYear(attrVal);

        // Decode the entity node's techBase.
        attrStr = node.getAttribute("techBase");
        if (null == attrStr) {
            throw new IllegalStateException(
                    "Couldn't decode the techBase from an Entity node.");
        }

        // Try to pull the value from the string
        try {
            attrVal = Integer.parseInt(attrStr.substring(0, 1));
        } catch (NumberFormatException exp) {
            throw new IllegalStateException("Couldn't get an integer from "
                    + attrStr.substring(0, 1));
        }
        entity.setTechLevel(attrVal);

        // Decode the entity node's mass.
        attrStr = node.getAttribute("mass");
        if (null == attrStr) {
            throw new IllegalStateException(
                    "Couldn't decode the mass from an Entity node.");
        }

        // Try to pull the value from the string
        try {
            attrVal = Integer.parseInt(attrStr);
        } catch (NumberFormatException exp) {
            throw new IllegalStateException("Couldn't get an integer from "
                    + attrStr);
        }
        entity.setWeight(attrVal);

        // Decode the entity node's walkMp.
        attrStr = node.getAttribute("walkMp");
        if (null == attrStr) {
            throw new IllegalStateException(
                    "Couldn't decode the walkMp from an Entity node.");
        }

        // Try to pull the value from the string
        try {
            attrVal = Integer.parseInt(attrStr);
        } catch (NumberFormatException exp) {
            throw new IllegalStateException("Couldn't get an integer from "
                    + attrStr);
        }
        entity.setOriginalWalkMP(attrVal);

        // Decode the entity node's jumpMp.
        attrStr = node.getAttribute("jumpMp");
        if (null == attrStr) {
            throw new IllegalStateException(
                    "Couldn't decode the jumpMp from an Entity node.");
        }

        // Try to pull the value from the string
        try {
            attrVal = Integer.parseInt(attrStr);
        } catch (NumberFormatException exp) {
            throw new IllegalStateException("Couldn't get an integer from "
                    + attrStr);
        }
        entity.setOriginalJumpMP(attrVal);

        // Try to pull the value from the string
        try {
            attrVal = Integer.parseInt(attrStr);
        } catch (NumberFormatException exp) {
View Full Code Here


        }

        Vector<MechSummary> vMatches = new Vector<MechSummary>();
        for (MechSummary ms : m_mechsCurrent) {
            try {
                Entity entity = new MechFileParser(ms.getSourceFile(), ms
                        .getEntryName()).getEntity();
                if (isMatch(entity)) {
                    vMatches.addElement(ms);
                }
            } catch (EntityLoadingException ex) {
View Full Code Here

            if (x == -1) {
                return;
            }
            MechSummary ms = m_mechsCurrent[m_mechList.getSelectedIndex()];
            try {
                Entity e = new MechFileParser(ms.getSourceFile(), ms.getEntryName()).getEntity();
                //I need to add them to a list of entities, to eventually be processed
                listFightersSelected.add(e.getDisplayName());
                squadron.add((Aero)e);
                //fs.fighters.add(e);
            } catch (EntityLoadingException ex) {
                System.out.println("Unable to load mech: " + ms.getSourceFile() + ": " + ms.getEntryName() + ": " + ex.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                ex.printStackTrace();
View Full Code Here

                clearMechPreview();
                return;
            }
            MechSummary ms = m_mechsCurrent[selected];
            try {
                Entity entity = new MechFileParser(ms.getSourceFile(), ms
                        .getEntryName()).getEntity();
                previewMech(entity);
            } catch (EntityLoadingException ex) {
                System.out
                        .println("Unable to load mech: " + ms.getSourceFile() + ": " + ms.getEntryName() + ": " + ex.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
View Full Code Here

    /**
     * To-hit number for the specified leg to kick
     */
    public static ToHitData toHit(IGame game, int attackerId,
            Targetable target, int leg) {
        final Entity ae = game.getEntity(attackerId);
        if (ae == null) {
            return new ToHitData(TargetRoll.IMPOSSIBLE,
                    "You can't attack from a null entity!");
        }

        String impossible = PhysicalAttackAction.toHitIsImpossible(game, ae, target);
        if (impossible != null) {
            return new ToHitData(TargetRoll.IMPOSSIBLE, "impossible");
        }

        IHex attHex = game.getBoard().getHex(ae.getPosition());
        IHex targHex = game.getBoard().getHex(target.getPosition());
        final int attackerElevation = ae.getElevation() + attHex.getElevation();
        final int targetElevation = target.getElevation()
                + targHex.getElevation();
        final int targetHeight = targetElevation + target.getHeight();

        int mule = 0;
        int[] kickLegs = new int[2];
        if (ae.entityIsQuad()) {
            if (leg == KickAttackAction.LEFTMULE
                    || leg == KickAttackAction.RIGHTMULE) {
                kickLegs[0] = Mech.LOC_RLEG;
                kickLegs[1] = Mech.LOC_LLEG;
                mule = 1; // To-hit modifier
            } else {
                kickLegs[0] = Mech.LOC_RARM;
                kickLegs[1] = Mech.LOC_LARM;
            }
        } else {
            kickLegs[0] = Mech.LOC_RLEG;
            kickLegs[1] = Mech.LOC_LLEG;
        }
        final int legLoc = ((leg == KickAttackAction.RIGHTMULE) || (leg == KickAttackAction.RIGHT)) ? kickLegs[0]
                : kickLegs[1];

        ToHitData toHit;

        // arguments legal?
        // By allowing mulekicks, this gets a little more complicated :(
        if (leg != KickAttackAction.RIGHT && leg != KickAttackAction.LEFT
                && leg != KickAttackAction.RIGHTMULE
                && leg != KickAttackAction.LEFTMULE) {
            throw new IllegalArgumentException(
                    "Leg must be one of LEFT, RIGHT, LEFTMULE, or RIGHTMULE");
        }

        // non-mechs can't kick
        if (!(ae instanceof Mech)) {
            return new ToHitData(TargetRoll.IMPOSSIBLE, "Non-mechs can't kick");
        }

        // check if all legs are present & working
        if (ae.isLocationBad(Mech.LOC_LLEG) || ae.isLocationBad(Mech.LOC_LLEG)
                || (ae.entityIsQuad()
                        && (ae.isLocationBad(Mech.LOC_LARM)
                                || ae.isLocationBad(Mech.LOC_RARM)))) {
            return new ToHitData(TargetRoll.IMPOSSIBLE, "Leg missing");
        }

        // check if all hips are operational
        if (!ae.hasWorkingSystem(Mech.ACTUATOR_HIP, Mech.LOC_LLEG)
                || !ae.hasWorkingSystem(Mech.ACTUATOR_HIP, Mech.LOC_RLEG)
                || (ae.entityIsQuad()
                        && (!ae.hasWorkingSystem(Mech.ACTUATOR_HIP, Mech.LOC_LARM)
                                || !ae.hasWorkingSystem(Mech.ACTUATOR_HIP, Mech.LOC_RARM)))) {
            return new ToHitData(TargetRoll.IMPOSSIBLE, "Hip destroyed");
        }
        // check if attacker has fired leg-mounted weapons
        for (Mounted mounted : ae.getWeaponList()) {
            if (mounted.isUsedThisRound() && mounted.getLocation() == legLoc) {
                return new ToHitData(TargetRoll.IMPOSSIBLE,
                        "Weapons fired from leg this turn");
            }
        }

        // check range
        final int range = ae.getPosition().distance(target.getPosition());

        // check elevation
        if (target instanceof VTOL && ((VTOL)target).isFlying()) {
            if (targetElevation - attackerElevation != 0) {
                return new ToHitData(TargetRoll.IMPOSSIBLE, "Target elevation not in range");
            }
        } else if (attackerElevation < targetElevation
                || attackerElevation > targetHeight) {
            return new ToHitData(TargetRoll.IMPOSSIBLE,
                    "Target elevation not in range");
        }

        // check facing
        // Don't check arc for stomping infantry or tanks.
        if (0 != range
                && mule != 1
                && !Compute.isInArc(ae.getPosition(), ae.getFacing(), target
                        .getPosition(), Compute.ARC_FORWARD)) {
            return new ToHitData(TargetRoll.IMPOSSIBLE, "Target not in arc");
        }

        // check facing, part 2: Mule kick
        if (0 != range
                && mule == 1
                && !Compute.isInArc(ae.getPosition(), ae.getFacing(), target
                        .getPosition(), Compute.ARC_REAR)) {
            return new ToHitData(TargetRoll.IMPOSSIBLE, "Target not in arc");
        }

        // can't kick while prone
        if (ae.isProne()) {
            return new ToHitData(TargetRoll.IMPOSSIBLE, "Attacker is prone");
        }

        if ( ae.isHullDown() ){
            return new ToHitData(TargetRoll.IMPOSSIBLE, "Attacker is hull down");
        }


        // Attacks against adjacent buildings automatically hit.
        if (target.getTargetType() == Targetable.TYPE_BUILDING
                || target.getTargetType() == Targetable.TYPE_FUEL_TANK
                || target instanceof GunEmplacement) {
            return new ToHitData(TargetRoll.AUTOMATIC_SUCCESS,
                    "Targeting adjacent building.");
        }

        // Set the base BTH
        int base = ae.getCrew().getPiloting() - 2;

        // Start the To-Hit
        toHit = new ToHitData(base, "base");

        PhysicalAttackAction.setCommonModifiers(toHit, game, ae, target);

        // +3 modifier for kicking infantry in same hex
        // see bug 1749177
        if (target instanceof Infantry && range == 0) {
            toHit.addModifier(3, "Stomping Infantry");
        }

        // Mulekick?
        if (mule != 0) {
            toHit.addModifier(mule, "Quad Mek making a mule kick");
        }

        // damaged or missing actuators
        if (!ae.hasWorkingSystem(Mech.ACTUATOR_UPPER_LEG, legLoc)) {
            toHit.addModifier(2, "Upper leg actuator destroyed");
        }
        if (!ae.hasWorkingSystem(Mech.ACTUATOR_LOWER_LEG, legLoc)) {
            toHit.addModifier(2, "Lower leg actuator destroyed");
        }
        if (!ae.hasWorkingSystem(Mech.ACTUATOR_FOOT, legLoc)) {
            toHit.addModifier(1, "Foot actuator destroyed");
        }

        if ( ae.hasFunctionalLegAES() ) {
            toHit.addModifier(-1, "AES bonus");
        }

        // elevation
        if (attackerElevation < targetHeight) {
View Full Code Here

    /**
     * Deletes an entity owned by a certain player from the list
     */
    private void receiveEntityDelete(Packet c, int connIndex) {
        int entityId = c.getIntValue(0);
        final Entity entity = game.getEntity(entityId);

        // Only allow players to delete their *own* entities.
        if ((entity != null) && (entity.getOwner() == getPlayer(connIndex))) {

            // If we're deleting a Protomech, recalculate unit numbers.
            if (entity instanceof Protomech) {

                // How many Protomechs does the player have (include this one)?
                int numPlayerProtos = game.getSelectedEntityCount(new EntitySelector() {
                    private final int ownerId = entity.getOwnerId();

                    public boolean accept(Entity entity) {
                        if ((entity instanceof Protomech) && (ownerId == entity.getOwnerId())) {
                            return true;
                        }
                        return false;
                    }
                });

                // According to page 54 of the BMRr, Protomechs must be
                // deployed in full Points of five, unless "losses" have
                // reduced the number to less that that.
                final char oldMax = (char) (Math.ceil(numPlayerProtos / 5.0) - 1);
                char newMax = (char) (Math.ceil((numPlayerProtos - 1) / 5.0) - 1);
                char deletedUnitNum = entity.getUnitNumber();

                // Do we have to update a Protomech from the last unit?
                if ((oldMax != deletedUnitNum) && (oldMax != newMax)) {

                    // Yup. Find a Protomech from the last unit, and
                    // set it's unit number to the deleted entity.
                    Enumeration<Entity> lastUnit = game.getSelectedEntities(new EntitySelector() {
                        private final int ownerId = entity.getOwnerId();

                        private final char lastUnitNum = oldMax;

                        public boolean accept(Entity entity) {
                            if ((entity instanceof Protomech) && (ownerId == entity.getOwnerId()) && (lastUnitNum == entity.getUnitNumber())) {
                                return true;
                            }
                            return false;
                        }
                    });
                    Entity lastUnitMember = lastUnit.nextElement();
                    lastUnitMember.setUnitNumber(deletedUnitNum);
                    entityUpdate(lastUnitMember.getId());

                } // End update-unit-numbetr

            } // End added-Protomech

View Full Code Here

    /**
     * To-hit number for the specified club to hit
     */
    public static ToHitData toHit(IGame game, int attackerId,
            Targetable target, Mounted club, int aimTable) {
        final Entity ae = game.getEntity(attackerId);

        // arguments legal?
        if (ae == null || target == null) {
            throw new IllegalArgumentException("Attacker or target not valid");
        }
        if (club == null) {
            throw new IllegalArgumentException("Club is null");
        }
        if (club.getType() == null) {
            throw new IllegalArgumentException("Club type is null");
        }

        String impossible = PhysicalAttackAction.toHitIsImpossible(game, ae, target);
        if (impossible != null) {
            return new ToHitData(TargetRoll.IMPOSSIBLE, impossible);
        }

        // non-mechs can't club
        if (!(ae instanceof Mech)) {
            return new ToHitData(TargetRoll.IMPOSSIBLE, "Non-mechs can't club");
        }

        // Quads can't club
        if (ae.entityIsQuad()) {
            return new ToHitData(TargetRoll.IMPOSSIBLE, "Attacker is a quad");
        }

        if (((MiscType) club.getType())
                .hasSubType(MiscType.S_RETRACTABLE_BLADE)
                && !((Mech) ae).hasExtendedRetractableBlade()) {
            return new ToHitData(TargetRoll.IMPOSSIBLE, "Blade is Retracted.");
        }

        if ( ae.getGrappled() != Entity.NONE &&
                ae.getGrappleSide() == Entity.GRAPPLE_LEFT
                && club.getLocation() == Mech.LOC_LARM ) {
            return new ToHitData(TargetRoll.IMPOSSIBLE, "impossible");
        }

        if ( ae.getGrappled() != Entity.NONE &&
                ae.getGrappleSide() == Entity.GRAPPLE_RIGHT
                && club.getLocation() == Mech.LOC_RARM ) {
            return new ToHitData(TargetRoll.IMPOSSIBLE, "impossible");
        }


        IHex attHex = game.getBoard().getHex(ae.getPosition());
        IHex targHex = game.getBoard().getHex(target.getPosition());
        final int attackerElevation = ae.getElevation() + attHex.getElevation();
        final int attackerHeight = attackerElevation + ae.height();
        final int targetElevation = target.getElevation()
                + targHex.getElevation();
        final int targetHeight = targetElevation + target.getHeight();
        final boolean bothArms = (club.getType().hasFlag(MiscType.F_CLUB)
                && ((MiscType) club.getType()).hasSubType(MiscType.S_CLUB));
        final boolean hasClaws = (((BipedMech) ae).hasClaw(Mech.LOC_RARM)
                || ((BipedMech) ae).hasClaw(Mech.LOC_LARM));
        final boolean shield = ((MiscType) club.getType()).isShield();
        boolean needsHand = true;

        if (hasClaws
                || (((MiscType) club.getType()).hasSubType(MiscType.S_FLAIL))
                || (((MiscType) club.getType()).hasSubType(MiscType.S_WRECKING_BALL))
                || (((MiscType) club.getType()).hasSubType(MiscType.S_LANCE))
                || (((MiscType) club.getType()).hasSubType(MiscType.S_BUZZSAW))
                || (((MiscType) club.getType()).hasSubType(MiscType.S_DUAL_SAW))) {
            needsHand = false;
        }

        ToHitData toHit;

        if (bothArms) {
            // check if both arms are present & operational
            if (ae.isLocationBad(Mech.LOC_RARM)
                    || ae.isLocationBad(Mech.LOC_LARM)) {
                return new ToHitData(TargetRoll.IMPOSSIBLE, "Arm missing");
            }
            // check if attacker has fired arm-mounted weapons
            if (ae.weaponFiredFrom(Mech.LOC_RARM)
                    || ae.weaponFiredFrom(Mech.LOC_LARM)) {
                return new ToHitData(TargetRoll.IMPOSSIBLE,
                        "Weapons fired from arm this turn");
            }
            // need shoulder and hand actuators
            if (!ae.hasWorkingSystem(Mech.ACTUATOR_SHOULDER, Mech.LOC_RARM)
                    || !ae.hasWorkingSystem(Mech.ACTUATOR_SHOULDER,
                            Mech.LOC_LARM)) {
                return new ToHitData(TargetRoll.IMPOSSIBLE,
                        "Shoulder actuator destroyed");
            }
            if ((!ae.hasWorkingSystem(Mech.ACTUATOR_HAND, Mech.LOC_RARM) || !ae
                    .hasWorkingSystem(Mech.ACTUATOR_HAND, Mech.LOC_LARM))
                    && needsHand) {
                return new ToHitData(TargetRoll.IMPOSSIBLE,
                        "Hand actuator destroyed");
            }
        } else if (shield) {
            if (!ae.hasPassiveShield(club.getLocation())) {
                return new ToHitData(TargetRoll.IMPOSSIBLE,
                        "Shield not in passive mode");
            }
        } else if (((MiscType) club.getType()).hasSubType(MiscType.S_FLAIL)) {
            if (!ae.hasWorkingSystem(Mech.ACTUATOR_UPPER_ARM, club
                    .getLocation())) {
                return new ToHitData(TargetRoll.IMPOSSIBLE,
                        "Upper actuator destroyed");
            }
            if (!ae.hasWorkingSystem(Mech.ACTUATOR_LOWER_ARM, club
                    .getLocation())) {
                return new ToHitData(TargetRoll.IMPOSSIBLE,
                        "Lower actuator destroyed");
            }
        } else {
            // check if arm is present
            if (ae.isLocationBad(club.getLocation())) {
                return new ToHitData(TargetRoll.IMPOSSIBLE, "Arm missing");
            }
            // check if attacker has fired arm-mounted weapons
            if (ae.weaponFiredFrom(club.getLocation())) {
                return new ToHitData(TargetRoll.IMPOSSIBLE,
                        "Weapons fired from arm this turn");
            }
            // need shoulder and hand actuators
            if (!ae
                    .hasWorkingSystem(Mech.ACTUATOR_SHOULDER, club
                            .getLocation())) {
                return new ToHitData(TargetRoll.IMPOSSIBLE,
                        "Shoulder actuator destroyed");
            }
            if (!ae.hasWorkingSystem(Mech.ACTUATOR_HAND, club.getLocation())
                    && needsHand) {
                return new ToHitData(TargetRoll.IMPOSSIBLE,
                        "Hand actuator destroyed");
            }
        }

        // club must not be damaged
        if (!shield
                && ae.getBadCriticals(CriticalSlot.TYPE_EQUIPMENT, ae
                        .getEquipmentNum(club), club.getLocation()) > 0) {
            return new ToHitData(TargetRoll.IMPOSSIBLE, "Club is damaged");
        }

        // check elevation (target must be within one level, except for VTOL)
        if (target instanceof VTOL && ((VTOL)target).isFlying()) {
            if (targetElevation - attackerElevation > 3 || targetElevation - attackerElevation < 0) {
                return new ToHitData(TargetRoll.IMPOSSIBLE, "Target elevation not in range");
            }
        } else if (targetHeight < attackerElevation
                || targetElevation > attackerHeight) {
            return new ToHitData(TargetRoll.IMPOSSIBLE,
                    "Target elevation not in range");
        }

        // check facing
        int clubArc = bothArms ? Compute.ARC_FORWARD
                : (club.getLocation() == Mech.LOC_LARM ? Compute.ARC_LEFTARM
                        : Compute.ARC_RIGHTARM);
        if (!Compute.isInArc(ae.getPosition(), ae.getSecondaryFacing(), target
                .getPosition(), clubArc)) {
            return new ToHitData(TargetRoll.IMPOSSIBLE, "Target not in arc");
        }

        // can't club while prone
        if (ae.isProne()) {
            return new ToHitData(TargetRoll.IMPOSSIBLE, "Attacker is prone");
        }

        // Attacks against adjacent buildings automatically hit.
        if (target.getTargetType() == Targetable.TYPE_BUILDING
                || target.getTargetType() == Targetable.TYPE_FUEL_TANK
                || target instanceof GunEmplacement) {
            return new ToHitData(TargetRoll.AUTOMATIC_SUCCESS,
                    "Targeting adjacent building.");
        }

        // Set the base BTH
        int base = ae.getCrew().getPiloting();

        // Various versions of physical weapons have different base bonuses and
        // penalties.
        if (((MiscType) club.getType()).hasSubType(MiscType.S_PILE_DRIVER)) {
            base += 2;
        } else if (((MiscType) club.getType()).hasSubType(MiscType.S_BACKHOE)
                || ((MiscType) club.getType()).hasSubType(MiscType.S_ROCK_CUTTER)
                || ((MiscType) club.getType()).hasSubType(MiscType.S_WRECKING_BALL)
                || ((MiscType) club.getType()).hasSubType(MiscType.S_LANCE)
                || ((MiscType) club.getType()).hasSubType(MiscType.S_FLAIL)
                || ((MiscType) club.getType()).hasSubType(MiscType.S_MACE)
                || ((MiscType) club.getType()).hasSubType(MiscType.S_MACE_THB)) {
            base += 1;
        } else if (((MiscType) club.getType()).hasSubType(MiscType.S_CHAINSAW)
                || ((MiscType) club.getType()).hasSubType(MiscType.S_DUAL_SAW)) {
            base += 0;
        } else if (((MiscType) club.getType()).hasSubType(MiscType.S_HATCHET)
                || ((MiscType) club.getType()).hasSubType(MiscType.S_MINING_DRILL)) {
            base -= 1;
        } else if (((MiscType) club.getType()).hasSubType(MiscType.S_COMBINE)
                || ((MiscType) club.getType()).hasSubType(MiscType.S_RETRACTABLE_BLADE)
                || ((MiscType) club.getType()).hasSubType(MiscType.S_SWORD)
                || ((MiscType) club.getType()).hasSubType(MiscType.S_CHAIN_WHIP)
                || ((MiscType) club.getType()).hasSubType(MiscType.S_SHIELD_SMALL)
                || ((MiscType) club.getType()).isVibroblade()) {
            base -= 2;
        } else if (((MiscType) club.getType()).hasSubType(MiscType.S_SHIELD_MEDIUM)) {
            base -= 3;
        } else if (((MiscType) club.getType()).hasSubType(MiscType.S_SHIELD_LARGE)) {
            base -= 4;
        } else {
            base -= 1;
        }

        toHit = new ToHitData(base, "base");

        PhysicalAttackAction.setCommonModifiers(toHit, game, ae, target);

        // damaged or missing actuators
        if (bothArms) {
            if (!ae.hasWorkingSystem(Mech.ACTUATOR_UPPER_ARM, Mech.LOC_RARM)) {
                toHit.addModifier(2, "Upper arm actuator destroyed");
            }
            if (!ae.hasWorkingSystem(Mech.ACTUATOR_UPPER_ARM, Mech.LOC_LARM)) {
                toHit.addModifier(2, "Upper arm actuator destroyed");
            }
            if (!ae.hasWorkingSystem(Mech.ACTUATOR_LOWER_ARM, Mech.LOC_RARM)) {
                toHit.addModifier(2, "Lower arm actuator missing or destroyed");
            }
            if (!ae.hasWorkingSystem(Mech.ACTUATOR_LOWER_ARM, Mech.LOC_LARM)) {
                toHit.addModifier(2, "Lower arm actuator missing or destroyed");
            }
            if (hasClaws) {
                toHit.addModifier(2, "Mek has claws");
            }
            if ( ae.hasFunctionalArmAES(Mech.LOC_RARM) && ae.hasFunctionalArmAES(Mech.LOC_LARM) ) {
                toHit.addModifier(-1,"AES modifer");
            }
        } else {
            if (!ae.hasWorkingSystem(Mech.ACTUATOR_UPPER_ARM, club
                    .getLocation())) {
                toHit.addModifier(2, "Upper arm actuator destroyed");
                if ((((MiscType) club.getType()).hasSubType(MiscType.S_LANCE))) {
                    return new ToHitData(TargetRoll.IMPOSSIBLE,
                            "Unable to use lance with upper arm actuator missing or destroyed");
                }
            }
            if (!ae.hasWorkingSystem(Mech.ACTUATOR_LOWER_ARM, club
                    .getLocation())) {
                toHit.addModifier(2, "Lower arm actuator missing or destroyed");
                if ((((MiscType) club.getType()).hasSubType(MiscType.S_LANCE))) {
                    return new ToHitData(TargetRoll.IMPOSSIBLE,
                            "Unable to use lance with lower arm actuator missing or destroyed");
                }
            }
            // Rules state +2 bth if your using a club with claws.
            if (hasClaws) {
                toHit.addModifier(2, "Mek has claws");
            }
            if ((((MiscType) club.getType()).hasSubType(MiscType.S_LANCE))
                    && (!ae.hasWorkingSystem(Mech.ACTUATOR_LOWER_ARM, club
                            .getLocation()) || !ae.hasWorkingSystem(
                            Mech.ACTUATOR_UPPER_ARM, club.getLocation()))) {
            }
            if ( ae.hasFunctionalArmAES(club.getLocation()) ) {
                toHit.addModifier(-1,"AES modifer");
            }
        }

        // elevation
View Full Code Here

        // Set proper RNG
        Compute.setRNG(game.getOptions().intOption("rng_type"));

        if (changed > 0) {
            for (Enumeration<Entity> entities = game.getEntities(); entities.hasMoreElements(); ){
                Entity en = entities.nextElement();
                en.setGameOptions();
            }
            entityAllUpdate();
            return true;
        }
        return false;
View Full Code Here

    /**
     * Creates a packet containing a single entity, for update
     */
    private Packet createEntityPacket(int entityId, Vector<UnitLocation> movePath) {
        final Entity entity = game.getEntity(entityId);
        final Object[] data = new Object[3];
        data[0] = new Integer(entityId);
        data[1] = entity;
        data[2] = movePath;
        return new Packet(Packet.COMMAND_ENTITY_UPDATE, data);
View Full Code Here

        /**
         * Adds a weapon to this attack
         */
        public void addWeapon(WeaponAttackAction attack) {
            final Entity entity = game.getEntity(attack.getEntityId());
            final WeaponType wtype = (WeaponType) entity.getEquipment(attack.getWeaponId())
                    .getType();
            final String roll = attack.toHit(game).getValueAsString();
            final String table = attack.toHit(game).getTableDesc();
            weaponDescs.add(wtype.getName()
                    + Messages.getString("BoardView1.needs") + roll + " " + table); //$NON-NLS-1$
View Full Code Here

TOP

Related Classes of megamek.common.Entity

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.