Examples of Targetable


Examples of megamek.common.Targetable

     */
    private Targetable chooseTarget(Coords pos) {
        final Entity ce = ce();

        // Assume that we have *no* choice.
        Targetable choice = null;

        // Get the available choices.
        Enumeration<Entity> choices = client.game.getEntities(pos);

        // Convert the choices into a List of targets.
View Full Code Here

Examples of megamek.common.Targetable

        if (aaa.turnsTilHit > 0) {
            aaa.turnsTilHit--;
            return true;
        }
        final Vector<Integer> spottersBefore = aaa.getSpotterIds();
        final Targetable target = aaa.getTarget(game);
        final Coords targetPos = target.getPosition();
        final int playerId = aaa.getPlayerId();
        boolean isFlak = target instanceof VTOL;
        Entity bestSpotter = null;
        Entity ae = game.getEntity(aaa.getEntityId());
        if (ae == null) {
            ae = game.getOutOfGameEntity(aaa.getEntityId());
        }
        //TODO: Fix null pointer exception
        if(ae == null) {
            System.err.println("Artillery Entity is null!");
            return true;
        }
        Mounted ammo = ae.getEquipment(aaa.getAmmoId());
        final AmmoType atype = ammo == null ? null : (AmmoType) ammo.getType();
        // Are there any valid spotters?
        if ((null != spottersBefore) && !isFlak) {
            // fetch possible spotters now
            Enumeration<Entity> spottersAfter = game
                    .getSelectedEntities(new EntitySelector() {
                        public int player = playerId;

                        public Targetable targ = target;

                        public boolean accept(Entity entity) {
                            Integer id = new Integer(entity.getId());
                            if ((player == entity.getOwnerId())
                                    && spottersBefore.contains(id)
                                    && !(LosEffects.calculateLos(game, entity
                                            .getId(), targ)).isBlocked()
                                    && entity.isActive()
                                    && !entity.isINarcedWith(INarcPod.HAYWIRE)) {
                                return true;
                            }
                            return false;
                        }
                    });

            // Out of any valid spotters, pick the best.
            while (spottersAfter.hasMoreElements()) {
                Entity ent = spottersAfter.nextElement();
                if ((bestSpotter == null)
                        || (ent.crew.getGunnery() < bestSpotter.crew
                                .getGunnery())) {
                    bestSpotter = ent;
                }
            }

        } // End have-valid-spotters

        // If at least one valid spotter, then get the benefits thereof.
        if (null != bestSpotter) {
            int mod = (bestSpotter.crew.getGunnery() - 4) / 2;
            toHit.addModifier(mod, "Spotting modifier");
        }

        // Is the attacker still alive and we're not shooting FLAK?
        // then adjust the target
        Entity artyAttacker = aaa.getEntity(game);
        if ((null != artyAttacker) && !isFlak) {

            // Get the arty weapon.
            Mounted weapon = artyAttacker.getEquipment(aaa.getWeaponId());

            // If the shot hit the target hex, then all subsequent
            // fire will hit the hex automatically.
            if (roll >= toHit.getValue()) {
                artyAttacker.aTracker.setModifier(weapon,
                        TargetRoll.AUTOMATIC_SUCCESS, targetPos);

                game.getBoard().addSpecialHexDisplay(targetPos,
                        new SpecialHexDisplay(
                                SpecialHexDisplay.Type.ARTILLERY_AUTOHIT,
                                game.getRoundCount(),
                                game.getPlayer(aaa.getPlayerId()).getName(),
                                "Artilery AutoHit. Better text later.",
                                false
                        )
                 );
            }
            // If the shot missed, but was adjusted by a
            // spotter, future shots are more likely to hit.
            else if (null != bestSpotter) {
                artyAttacker.aTracker.setModifier(weapon, artyAttacker.aTracker
                        .getModifier(weapon, targetPos) - 1, targetPos);

                game.getBoard().addSpecialHexDisplay(targetPos,
                        new SpecialHexDisplay(
                            SpecialHexDisplay.Type.ARTILLERY_ADJUSTED,
                            game.getRoundCount(),
                            game.getPlayer(aaa.getPlayerId()).getName(),
                            "Artilery toHit Adjusted. Better text later.",
                            false
                        )
                );
            }

        } // End artyAttacker-alive

        // Report weapon attack and its to-hit value.
        r = new Report(3120);
        r.indent();
        r.newlines = 0;
        r.subject = subjectId;
        if (wtype != null) {
            r.add(wtype.getName());
        } else {
            r.add("Error: From Nowhwere");
        }

        r.add(target.getDisplayName(), true);
        vPhaseReport.addElement(r);
        if (toHit.getValue() == TargetRoll.IMPOSSIBLE) {
            r = new Report(3135);
            r.subject = subjectId;
            r.add(toHit.getDesc());
            vPhaseReport.addElement(r);
            return false;
        } else if (toHit.getValue() == TargetRoll.AUTOMATIC_FAIL) {
            r = new Report(3140);
            r.newlines = 0;
            r.subject = subjectId;
            r.add(toHit.getDesc());
            vPhaseReport.addElement(r);
        } else if (toHit.getValue() == TargetRoll.AUTOMATIC_SUCCESS) {
            r = new Report(3145);
            r.newlines = 0;
            r.subject = subjectId;
            r.add(toHit.getDesc());
            vPhaseReport.addElement(r);
        } else {
            // roll to hit
            r = new Report(3150);
            r.newlines = 0;
            r.subject = subjectId;
            r.add(toHit.getValue());
            vPhaseReport.addElement(r);
        }

        // dice have been rolled, thanks
        r = new Report(3155);
        r.newlines = 0;
        r.subject = subjectId;
        r.add(roll);
        vPhaseReport.addElement(r);

        if (!isFlak) {
            game.getBoard().addSpecialHexDisplay(
                    targetPos,
                    new SpecialHexDisplay(SpecialHexDisplay.Type.ARTILLERY_TARGET,
                            game.getRoundCount(),
                            game.getPlayer(aaa.getPlayerId()).getName(),
                            "Artilery Target. Better text later.",
                            false
                    )
            );
        }

        // do we hit?
        bMissed = roll < toHit.getValue();
        // Set Margin of Success/Failure.
        toHit.setMoS(roll-Math.max(2,toHit.getValue()));

        // Do this stuff first, because some weapon's miss report reference the
        // amount of shots fired and stuff.
        if (!handledAmmoAndReport) {
            addHeat();
        }
        Coords coords = target.getPosition();
        if (!bMissed) {
            if (!isFlak) {
                r = new Report(3190);
            } else {
                r = new Report(3191);
            }
            r.subject = subjectId;
            r.add(coords.getBoardNum());
            vPhaseReport.addElement(r);

            game.getBoard().addSpecialHexDisplay(targetPos,
                    new SpecialHexDisplay(SpecialHexDisplay.Type.ARTILLERY_HIT,
                            game.getRoundCount(),
                            "Artilery Hit. Better text later."));

        } else {
            // direct fire artillery only scatters by one d6
            // we do this here to avoid duplicating handle()
            // in the ArtilleryWeaponDirectFireHandler
            if (phase == IGame.Phase.PHASE_FIRING) {
                coords = Compute.scatterDirectArty(coords);
            } else {
                coords = Compute.scatter(coords, Math.abs(toHit.getMoS()));
            }
            if (game.getBoard().contains(coords)) {
                // misses and scatters to another hex
                if (!isFlak) {
                    r = new Report(3195);
                    game.getBoard().addSpecialHexDisplay(
                        coords,
                        new SpecialHexDisplay(
                                SpecialHexDisplay.Type.ARTILLERY_HIT,
                                game.getRoundCount(),
                                "Artilery Scatered Here. Better text later."
                        )
                    );
                } else {
                    r = new Report(3192);
                }
                r.subject = subjectId;
                r.add(coords.getBoardNum());
                vPhaseReport.addElement(r);
            } else {
                // misses and scatters off-board
                if (isFlak) {
                    r = new Report(3193);
                } else {
                    r = new Report(3200);
                }
                r.subject = subjectId;
                vPhaseReport.addElement(r);
                return !bMissed;
            }
        }

        if (atype.getMunitionType() == AmmoType.M_FLARE) {
            int radius;
            if (atype.getAmmoType() == AmmoType.T_ARROW_IV) {
                radius = 4;
            } else if (atype.getAmmoType() == AmmoType.T_LONG_TOM) {
                radius = 3;
            } else if (atype.getAmmoType() == AmmoType.T_SNIPER) {
                radius = 2;
            } else {
                radius = 1;
            }
            server.deliverArtilleryFlare(coords, radius);
            return false;
        }
        if (atype.getMunitionType() == AmmoType.M_DAVY_CROCKETT_M) {
            // The appropriate term here is "Bwahahahahaha..."
            server.doNuclearExplosion(coords, 1, vPhaseReport);
            return false;
        }
        if (atype.getMunitionType() == AmmoType.M_FASCAM) {
            server.deliverFASCAMMinefield(coords, ae.getOwner().getId(), atype.getRackSize(), ae.getId());
            return false;
        }
        if (atype.getMunitionType() == AmmoType.M_INFERNO_IV) {
            server.deliverArtilleryInferno(coords, artyAttacker, subjectId, vPhaseReport);
            return false;
        }
        if (atype.getMunitionType() == AmmoType.M_VIBRABOMB_IV) {
            server.deliverThunderVibraMinefield(coords, ae.getOwner().getId(),
                    atype.getRackSize(), waa.getOtherAttackInfo(), ae.getId());
            return false;
        }
        if (atype.getMunitionType() == AmmoType.M_SMOKE) {
            server.deliverArtillerySmoke(coords, vPhaseReport);
            return false;
        }
        int altitude = 0;
        if (isFlak) {
            altitude = ((VTOL) target).getElevation();
        }

        //check to see if this is a mine clearing attack
        //According to the RAW you have to hit the right hex to hit even if the scatter hex has minefields
        boolean mineClear = target.getTargetType() == Targetable.TYPE_MINEFIELD_CLEAR;
        if (mineClear && game.containsMinefield(coords)
                && !isFlak && !bMissed) {
            r = new Report(3255);
            r.indent(1);
            r.subject = subjectId;
View Full Code Here

Examples of megamek.common.Targetable

     * @param game - the <code>IGame</code> object containing all entities.
     * @return the <code>ToHitData</code> containing the target roll.
     */
    public ToHitData toHit(IGame game) {
        final Entity ae = getEntity(game);
        final Targetable target = getTarget(game);
        // arguments legal?
        if (ae == null || target == null) {
            throw new IllegalArgumentException("Attacker or target not valid");
        }

        Entity te = null;
        if (target.getTargetType() == Targetable.TYPE_ENTITY) {
            te = (Entity) target;
        }
       
        if (!game.getOptions().booleanOption("friendly_fire")) {
            // a friendly unit can never be the target of a direct attack.
            if (target.getTargetType() == Targetable.TYPE_ENTITY
                    && (((Entity)target).getOwnerId() == ae.getOwnerId()
                            || (((Entity)target).getOwner().getTeam() != Player.TEAM_NONE
                                    && ae.getOwner().getTeam() != Player.TEAM_NONE
                                    && ae.getOwner().getTeam() == ((Entity)target).getOwner().getTeam())))
                return new ToHitData(TargetRoll.IMPOSSIBLE, "A friendly unit can never be the target of a direct attack.");
        }

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

        // Mech must be prone.
        if (!ae.isProne()) {
            return new ToHitData(TargetRoll.IMPOSSIBLE,
                    "Only prone mechs can thrash at infantry");
        }

        // Can't thrash against non-infantry
        if (te == null || !(te instanceof Infantry)) {
            return new ToHitData(TargetRoll.IMPOSSIBLE,
                    "Can only thrash at infantry");
        }

        // Can't thrash against swarming infantry.
        else if (Entity.NONE != te.getSwarmTargetId()) {
            return new ToHitData(TargetRoll.IMPOSSIBLE,
                    "Can't thrash at swarming infantry");
        }

        // Check range.
        if (target.getPosition() == null
                || ae.getPosition().distance(target.getPosition()) > 0) {
            return new ToHitData(TargetRoll.IMPOSSIBLE,
                    "Target not in same hex");
        }

        if (target.getElevation() != ae.getElevation()) {
            return new ToHitData(TargetRoll.IMPOSSIBLE,
                    "Target not at same elevation");
        }

        // Check terrain.
        IHex hex = game.getBoard().getHex(ae.getPosition());
        if (hex.containsTerrain(Terrains.WOODS)
                || hex.containsTerrain(Terrains.JUNGLE)
                || hex.containsTerrain(Terrains.ROUGH)
                || hex.containsTerrain(Terrains.RUBBLE)
                || hex.containsTerrain(Terrains.FUEL_TANK)
                || hex.containsTerrain(Terrains.BUILDING)) {
            return new ToHitData(TargetRoll.IMPOSSIBLE,
                    "Not a clear or pavement hex.");
        }

        // Can't target woods or a building with a thrash attack.
        if (target.getTargetType() == Targetable.TYPE_BUILDING
                || target.getTargetType() == Targetable.TYPE_BLDG_IGNITE
                || target.getTargetType() == Targetable.TYPE_FUEL_TANK
                || target.getTargetType() == Targetable.TYPE_FUEL_TANK_IGNITE
                || target.getTargetType() == Targetable.TYPE_HEX_CLEAR
                || target.getTargetType() == Targetable.TYPE_HEX_IGNITE) {
            return new ToHitData(TargetRoll.IMPOSSIBLE, "Invalid attack");
        }

        // The Mech can't have fired a weapon this round.
        for (int loop = 0; loop < ae.locations(); loop++) {
View Full Code Here

Examples of megamek.common.Targetable

     */
    public synchronized void addAttack(AttackAction aa) {
        // do not make a sprite unless we're aware of both entities
        // this is not a great solution but better than a crash
        Entity ae = game.getEntity(aa.getEntityId());
        Targetable t = game.getTarget(aa.getTargetType(), aa.getTargetId());
        if ((ae == null) || (t == null) || (t.getTargetType() == Targetable.TYPE_INARC_POD)
                || (t.getPosition() == null) || (ae.getPosition() == null)) {
            return;
        }

        repaint(100);
        for (AttackSprite sprite : attackSprites) {
View Full Code Here

Examples of megamek.common.Targetable

    /**
     * Draw a line to represent an attack
     */
    private void paintAttack(Graphics g, AttackAction attack) {
        Entity source = m_game.getEntity(attack.getEntityId());
        Targetable target = m_game.getTarget(attack.getTargetType(), attack
                .getTargetId());
        // sanity check...
        if (null == source || null == target) {
            return;
        }

        if (attack.getTargetType() == Targetable.TYPE_INARC_POD) {
            // iNarc pods don't have a position, so lets scrap this idea, shall
            // we?
            return;
        }
        if (attack instanceof WeaponAttackAction) {
            WeaponAttackAction waa = (WeaponAttackAction) attack;
            if ((attack.getTargetType() == Targetable.TYPE_HEX_ARTILLERY)
                    && waa.getEntity(m_game).getOwner().getId() != m_client
                            .getLocalPlayer().getId()) {
                return;
            }
        }
        Color oldColor = g.getColor();

        int[] xPoints = new int[4];
        int[] yPoints = new int[4];

        xPoints[0] = source.getPosition().x
                * (hexSide[zoom] + hexSideBySin30[zoom]) + leftMargin
                + (int) 1.5 * hexSide[zoom] - 2;
        yPoints[0] = (2 * source.getPosition().y + 1 + source.getPosition().x % 2)
                * hexSideByCos30[zoom] + topMargin;
        xPoints[1] = target.getPosition().x
                * (hexSide[zoom] + hexSideBySin30[zoom]) + leftMargin
                + (int) 1.5 * hexSide[zoom] - 2;
        yPoints[1] = (2 * target.getPosition().y + 1 + target.getPosition().x % 2)
                * hexSideByCos30[zoom] + topMargin;
        xPoints[2] = xPoints[1] + 2;
        xPoints[3] = xPoints[0] + 2;
        if ((source.getPosition().x > target.getPosition().x && source
                .getPosition().y < target.getPosition().y)
                || (source.getPosition().x < target.getPosition().x && source
                        .getPosition().y > target.getPosition().y)) {
            yPoints[3] = yPoints[0] + 2;
            yPoints[2] = yPoints[1] + 2;
        } else {
            yPoints[3] = yPoints[0] - 2;
            yPoints[2] = yPoints[1] - 2;
        }
        g.setColor(PlayerColors.getColor(source.getOwner().getColorIndex()));
        g.fillPolygon(xPoints, yPoints, 4);
        g.setColor(Color.black);
        g.drawPolygon(xPoints, yPoints, 4);

        // if this is mutual fire, draw a half-and-half line
        for (Enumeration<EntityAction> iter = m_game.getActions(); iter
                .hasMoreElements();) {
            EntityAction action = iter.nextElement();
            if (action instanceof AttackAction) {
                AttackAction otherAttack = (AttackAction) action;
                if (attack.getEntityId() == otherAttack.getTargetId()
                        && otherAttack.getEntityId() == attack.getTargetId()) {
                    // attackTarget _must_ be an entity since it's shooting back
                    // (?)
                    Entity attackTarget = m_game.getEntity(otherAttack
                            .getEntityId());
                    g.setColor(PlayerColors.getColor(attackTarget.getOwner()
                            .getColorIndex()));

                    xPoints[0] = xPoints[3];
                    yPoints[0] = yPoints[3];
                    xPoints[1] = xPoints[2];
                    yPoints[1] = yPoints[2];
                    xPoints[2] = xPoints[1] + 2;
                    xPoints[3] = xPoints[0] + 2;
                    if ((source.getPosition().x > target.getPosition().x && source
                            .getPosition().y < target.getPosition().y)
                            || (source.getPosition().x < target.getPosition().x && source
                                    .getPosition().y > target.getPosition().y)) {
                        yPoints[3] = yPoints[0] + 2;
                        yPoints[2] = yPoints[1] + 2;
                    } else {
                        yPoints[3] = yPoints[0] - 2;
                        yPoints[2] = yPoints[1] - 2;
View Full Code Here

Examples of megamek.common.Targetable

    /**
     * Draw a line to represent an attack
     */
    private void paintAttack(Graphics g, AttackAction attack) {
        Entity source = m_game.getEntity(attack.getEntityId());
        Targetable target = m_game.getTarget(attack.getTargetType(), attack
                .getTargetId());
        // sanity check...
        if (null == source || null == target) {
            return;
        }

        if (attack.getTargetType() == Targetable.TYPE_INARC_POD) {
            // iNarc pods don't have a position, so lets scrap this idea, shall
            // we?
            return;
        }
        if (attack instanceof WeaponAttackAction) {
            WeaponAttackAction waa = (WeaponAttackAction) attack;
            if ((attack.getTargetType() == Targetable.TYPE_HEX_ARTILLERY)
                    && waa.getEntity(m_game).getOwner().getId() != m_client
                            .getLocalPlayer().getId()) {
                return;
            }
        }
        Color oldColor = g.getColor();

        int[] xPoints = new int[4];
        int[] yPoints = new int[4];

        xPoints[0] = source.getPosition().x
                * (hexSide[zoom] + hexSideBySin30[zoom]) + leftMargin
                + (int) 1.5 * hexSide[zoom] - 2;
        yPoints[0] = (2 * source.getPosition().y + 1 + source.getPosition().x % 2)
                * hexSideByCos30[zoom] + topMargin;
        xPoints[1] = target.getPosition().x
                * (hexSide[zoom] + hexSideBySin30[zoom]) + leftMargin
                + (int) 1.5 * hexSide[zoom] - 2;
        yPoints[1] = (2 * target.getPosition().y + 1 + target.getPosition().x % 2)
                * hexSideByCos30[zoom] + topMargin;
        xPoints[2] = xPoints[1] + 2;
        xPoints[3] = xPoints[0] + 2;
        if ((source.getPosition().x > target.getPosition().x && source
                .getPosition().y < target.getPosition().y)
                || (source.getPosition().x < target.getPosition().x && source
                        .getPosition().y > target.getPosition().y)) {
            yPoints[3] = yPoints[0] + 2;
            yPoints[2] = yPoints[1] + 2;
        } else {
            yPoints[3] = yPoints[0] - 2;
            yPoints[2] = yPoints[1] - 2;
        }
        g.setColor(PlayerColors.getColor(source.getOwner().getColorIndex()));
        g.fillPolygon(xPoints, yPoints, 4);
        g.setColor(Color.black);
        g.drawPolygon(xPoints, yPoints, 4);

        // if this is mutual fire, draw a half-and-half line
        for (Enumeration<EntityAction> iter = m_game.getActions(); iter
                .hasMoreElements();) {
            EntityAction action = iter.nextElement();
            if (action instanceof AttackAction) {
                AttackAction otherAttack = (AttackAction) action;
                if (attack.getEntityId() == otherAttack.getTargetId()
                        && otherAttack.getEntityId() == attack.getTargetId()) {
                    // attackTarget _must_ be an entity since it's shooting back
                    // (?)
                    Entity attackTarget = m_game.getEntity(otherAttack
                            .getEntityId());
                    g.setColor(PlayerColors.getColor(attackTarget.getOwner()
                            .getColorIndex()));

                    xPoints[0] = xPoints[3];
                    yPoints[0] = yPoints[3];
                    xPoints[1] = xPoints[2];
                    yPoints[1] = yPoints[2];
                    xPoints[2] = xPoints[1] + 2;
                    xPoints[3] = xPoints[0] + 2;
                    if ((source.getPosition().x > target.getPosition().x && source
                            .getPosition().y < target.getPosition().y)
                            || (source.getPosition().x < target.getPosition().x && source
                                    .getPosition().y > target.getPosition().y)) {
                        yPoints[3] = yPoints[0] + 2;
                        yPoints[2] = yPoints[1] + 2;
                    } else {
                        yPoints[3] = yPoints[0] - 2;
                        yPoints[2] = yPoints[1] - 2;
View Full Code Here

Examples of megamek.common.Targetable

        if (isIgnoringEvents()) {
            return;
        }

        if (client.isMyTurn() && (b.getCoords() != null) && (ce() != null)) {
            final Targetable targ = chooseTarget(b.getCoords());
            if (targ != null) {
                target(targ);
            } else {
                target(null);
            }
View Full Code Here

Examples of megamek.common.Targetable

     *            - the <code>Coords</code> containing targets.
     */
    private Targetable chooseTarget(Coords pos) {

        // Assume that we have *no* choice.
        Targetable choice = null;

        // Get the available choices.
        Enumeration<Entity> choices = client.game.getEntities(pos);

        // Convert the choices into a List of targets.
View Full Code Here

Examples of megamek.common.Targetable

        if (isIgnoringEvents()) {
            return;
        }

        if (client.isMyTurn() && (b.getCoords() != null) && (ce() != null)) {
            final Targetable targ = chooseTarget(b.getCoords());
            if (targ != null) {
                target(targ);
            } else {
                target(null);
            }
View Full Code Here

Examples of megamek.common.Targetable

     * @param pos - the <code>Coords</code> containing targets.
     */
    private Targetable chooseTarget(Coords pos) {

        // Assume that we have *no* choice.
        Targetable choice = null;

        // Get the available choices.
        Enumeration<Entity> choices = client.game.getEntities(pos);

        // Convert the choices into a List of targets.
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.