Package megamek.common

Examples of megamek.common.Entity


    }

    public boolean willIlluminate(IGame game, Entity who) {
        if (!isPossible(game))
            return false;
        final Entity attacker = getEntity(game);
        final Coords apos = attacker.getPosition();
        final Targetable target = getTarget(game);
        final Coords tpos = target.getPosition();

        ArrayList<Coords> in = Coords.intervening(apos, tpos); // nb includes
                                                                // attacker &
                                                                // target
        for (Coords c : in) {
            for (Enumeration<Entity> e = game.getEntities(c); e
                    .hasMoreElements();) {
                Entity en = e.nextElement();
                LosEffects los = LosEffects.calculateLos(game, getEntityId(),
                        en);
                if (los.canSee() && en.equals(who))
                    return true;
            }
        }
        return false;
    }
View Full Code Here


        sendChangedHex(c);
        // if there is water below the ice
        if (hex.terrainLevel(Terrains.WATER) > 0) {
            // drop entities on the surface into the water
            for (Enumeration<Entity> entities = game.getEntities(c); entities.hasMoreElements();) {
                Entity e = entities.nextElement();
                // If the unit is on the surface, and is no longer allowed in
                // the hex
                boolean isHoverOrWiGE = (e.getMovementMode() == IEntityMovementMode.HOVER) || (e.getMovementMode() == IEntityMovementMode.WIGE);
                if ((e.getElevation() == 0) &&
                        !(hex.containsTerrain(Terrains.BLDG_ELEV, 0)) &&
                        !(isHoverOrWiGE && (e.getRunMP() >= 0)) &&
                        (e.getMovementMode() != IEntityMovementMode.INF_UMU) && !e.hasUMU()) {
                    vPhaseReport.addAll(doEntityFallsInto(e, c, c, new PilotingRollData(TargetRoll.AUTOMATIC_FAIL)));
                }
            }
        }
        return vPhaseReport;
View Full Code Here

    public Targetable getTarget(IGame g) {
        return g.getTarget(getTargetType(), getTargetId());
    }

    public Entity getEntity(IGame g) {
        Entity e = g.getEntity(getEntityId());
        // if we have an artyattack, we might need to get an out-of-game entity
        // if it died or fled
        if (e == null) {
            e = g.getOutOfGameEntity(getEntityId());
        }
View Full Code Here

     */
    public static ToHitData nightModifiers(IGame game, Targetable target,
            AmmoType atype, Entity attacker, boolean isWeapon) {
        ToHitData toHit = null;
       
            Entity te = null;
            if (target.getTargetType() == Targetable.TYPE_ENTITY) {
                te = (Entity) target;
            }
            toHit = new ToHitData();

            int lightCond = game.getPlanetaryConditions().getLight();
            if(lightCond == PlanetaryConditions.L_DAY) {
                //not nighttime so just return
                return toHit;
            }
           
            // The base night penalty
            int night_modifier = 0;  
            night_modifier = game.getPlanetaryConditions().getLightHitPenalty(isWeapon);
            toHit.addModifier(night_modifier, game.getPlanetaryConditions().getLightCurrentName());

            boolean illuminated = false;
            if (te != null) {
                illuminated = te.isIlluminated();
                // hack for unresolved actions so client shows right BTH
                if (!illuminated) {
                    for (Enumeration<EntityAction> actions = game.getActions(); actions
                            .hasMoreElements();) {
                        EntityAction a = actions.nextElement();
                        if (a instanceof SearchlightAttackAction) {
                            SearchlightAttackAction saa = (SearchlightAttackAction) a;
                            if (saa.willIlluminate(game, te)) {
                                illuminated = true;
                                break;
                            }
                        }
                    }
                }
            }
            // Searchlights reduce the penalty to zero (or 1 for pitch-black) (except for dusk/dawn)
            int searchlightMod = Math.min(3, night_modifier);
            if(te != null && lightCond > PlanetaryConditions.L_DUSK) {
                if (te.isUsingSpotlight()) {
                    toHit.addModifier(-searchlightMod, "target using searchlight");
                    night_modifier = night_modifier - searchlightMod;
                } else if (illuminated) {
                    toHit.addModifier(-searchlightMod,"target illuminated by searchlight");
                    night_modifier = night_modifier - searchlightMod;
                }
            }
            /*
            // Ignored with EI system & implants
            else if (attacker.hasActiveEiCockpit()) {
                toHit.addModifier(-night_modifier, "EI system");
                night_modifier = 0;
            }
            */
            // So do flares
            else if (game.isPositionIlluminated(target.getPosition())) {
                toHit.addModifier(-night_modifier,
                        "target illuminated by flare");
                night_modifier = 0;
            }
            // Certain ammunitions reduce the penalty
            else if (atype != null) {
                if ((atype.getAmmoType() == AmmoType.T_AC || atype
                        .getAmmoType() == AmmoType.T_LAC)
                        && (atype.getMunitionType() == AmmoType.M_INCENDIARY_AC || atype
                                .getMunitionType() == AmmoType.M_TRACER)) {
                    toHit.addModifier(-1, "incendiary/tracer ammo");
                    night_modifier--;
                }
            }
            // Laser heatsinks
            if (night_modifier > 0 && te != null && te instanceof Mech
                    && ((Mech) te).hasLaserHeatSinks()) {
                boolean lhsused = false;
                if (te.heat > 0) {
                    toHit.addModifier(-night_modifier,
                            "target overheated with laser heatsinks");
                    night_modifier = 0;
                }
                // actions that generate heat give a -1 modifier
                else if (te.heatBuildup > 0 || te.isStealthActive()) {
                    lhsused = true;
                } else {
                    // Unfortunately, we can't just check weapons fired by the
                    // target
                    // because isUsedThisRound() is not valid if the attacker
                    // declared first.
                    // therefore, enumerate WeaponAttackActions...
                    for (Enumeration<EntityAction> actions = game.getActions(); actions
                            .hasMoreElements();) {
                        EntityAction a = actions.nextElement();
                        if (a instanceof WeaponAttackAction) {
                            WeaponAttackAction waa = (WeaponAttackAction) a;
                            if (waa.getEntityId() == te.getId()) {
                                Mounted weapon = te.getEquipment(waa
                                        .getWeaponId());
                                WeaponType wtype = (WeaponType) weapon
                                        .getType();
                                if (wtype.getHeat() != 0
                                        || weapon.isRapidfire()) {
View Full Code Here

        }
        // set entity to expected elevation
        IHex hex = game.getBoard().getHex(entity.getPosition());
        entity.setElevation(entity.elevationOccupied(hex) - hex.floor());
        // finally, check for any stacking violations
        Entity violated = Compute.stackingViolation(game, entity, entity.getPosition(), null);
        if (violated != null) {
            // handle this as accidental fall from above
            entity.setElevation(violated.getElevation() + 2);
            r = new Report(2390);
            r.subject = entity.getId();
            r.add(entity.getDisplayName(), true);
            r.add(violated.getDisplayName(), true);
            addReport(r);
            addReport(doEntityFallsInto(entity, entity.getPosition(), entity.getPosition(), psr));
        }
    }
View Full Code Here

    /**
     * resolve assault drops for all entities
     */
    void doAllAssaultDrops() {
        for (Enumeration<Entity> i = game.getEntities(); i.hasMoreElements();) {
            Entity e = i.nextElement();
            if (e.isAssaultDropInProgress()) {
                doAssaultDrop(e);
                e.setLandedAssaultDrop();
            }
        }
    }
View Full Code Here

     * Checks if a death from above attack can hit the target, including
     * movement
     */
    public static ToHitData toHit(IGame game, int attackerId,
            Targetable target, MovePath md) {
        final Entity ae = game.getEntity(attackerId);

        // Do to pretreatment of physical attacks, the target may be null.
        if (target == null) {
            return new ToHitData(TargetRoll.IMPOSSIBLE, "Target is null");
        }

        Entity te = null;
        if (target.getTargetType() == Targetable.TYPE_ENTITY) {
            te = (Entity) target;
        }
        Coords chargeSrc = ae.getPosition();
        MoveStep chargeStep = null;

        // Infantry CAN'T dfa!!!
        if (ae instanceof Infantry) {
            return new ToHitData(TargetRoll.IMPOSSIBLE, "Infantry can't D.F.A.");
        }

        if (ae.getJumpType() == Mech.JUMP_BOOSTER) {
            return new ToHitData(TargetRoll.IMPOSSIBLE,
                    "Can't D.F.A. using mechanical jump boosters.");
        }

        // let's just check this
        if (!md.contains(MovePath.STEP_DFA)) {
            return new ToHitData(TargetRoll.IMPOSSIBLE,
                    "D.F.A. action not found in movment path");
        }

        // have to jump
        if (!md.contains(MovePath.STEP_START_JUMP)) {
            return new ToHitData(TargetRoll.IMPOSSIBLE,
                    "D.F.A. must involve jumping");
        }

        // Can't target a transported entity.
        if ((te != null) && (Entity.NONE != te.getTransportId())) {
            return new ToHitData(TargetRoll.IMPOSSIBLE,
                    "Target is a passenger.");
        }

        //no evading
        if(md.contains(MovePath.STEP_EVADE)) {
            return new ToHitData(TargetRoll.IMPOSSIBLE, "No evading while charging");
        }

        // Can't target a entity conducting a swarm attack.
        if ((te != null) && (Entity.NONE != te.getSwarmTargetId())) {
            return new ToHitData(TargetRoll.IMPOSSIBLE,
                    "Target is swarming a Mek.");
        }

        // determine last valid step
        md.compile(game, ae);
        for (final Enumeration<MoveStep> i = md.getSteps(); i.hasMoreElements();) {
            final MoveStep step = i.nextElement();
            if (!step.isLegal()) {
                break;
            }
            if (step.getType() == MovePath.STEP_DFA) {
                chargeStep = step;
            } else {
                chargeSrc = step.getPosition();
            }
        }

        // need to reach target
        if ((chargeStep == null)
                || !target.getPosition().equals(chargeStep.getPosition())) {
            return new ToHitData(TargetRoll.IMPOSSIBLE,
                    "Could not reach target with movement");
        }

        // target must have moved already
        if ((te != null) && !te.isDone()) {
            return new ToHitData(TargetRoll.IMPOSSIBLE,
                    "Target must be done with movement");
        }

        return toHit(game, attackerId, target, chargeSrc);
View Full Code Here

            }

            // Walk through the entities in this position.
            Enumeration<Entity> entities = vector.elements();
            while (!collapse && entities.hasMoreElements()) {
                final Entity entity = entities.nextElement();
                final int entityElev = entity.getElevation();

                if (entityElev != bridgeEl) {
                    // Ignore entities not *inside* the building
                    if (entityElev > numFloors) {
                        continue;
                    }
                }

                if ((entity.getMovementMode() == IEntityMovementMode.HYDROFOIL) || (entity.getMovementMode() == IEntityMovementMode.NAVAL) || (entity.getMovementMode() == IEntityMovementMode.SUBMARINE) || (entity.getMovementMode() == IEntityMovementMode.INF_UMU)) {
                    continue; // under the bridge even at same level
                }

                // Add the weight of a Mek or tank to the correct floor.
                if ((entity instanceof Mech) || (entity instanceof Tank)) {
                    int load = (int) entity.getWeight();
                    int floor = entityElev;
                    if (floor == bridgeEl) {
                        floor = numLoads;
                    }

View Full Code Here

            }
        }

        // check artillery attacks
        for (ArtilleryAttackAction aaa : artilleryAttacks) {
            final Entity ae = game.getEntity(aaa.getEntityId());
            String s = null;
            if (ae != null) {
                if (aaa.getWeaponId() > -1) {
                    Mounted weap = ae.getEquipment(aaa.getWeaponId());
                    s = weap.getName();
                    if (aaa.getAmmoId() > -1) {
                        Mounted ammo = ae.getEquipment(aaa.getAmmoId());
                        s += "(" + ammo.getName() + ")";
                    }
                }
            }
            if (s == null) {
View Full Code Here

                game.getNoOfEntities());
        ArrayList<WreckSprite> newWrecks = new ArrayList<WreckSprite>();

        Enumeration<Entity> e = game.getWreckedEntities();
        while (e.hasMoreElements()) {
            Entity entity = e.nextElement();
            if (!(entity instanceof Infantry) && (entity.getPosition() != null)) {
                WreckSprite ws = new WreckSprite(entity);
                newWrecks.add(ws);
            }
        }

        clearC3Networks();
        for (Enumeration<Entity> i = game.getEntities(); i.hasMoreElements();) {
            final Entity entity = i.nextElement();
            if (entity.getPosition() == null) {
                continue;
            }

            EntitySprite sprite = new EntitySprite(entity);
            newSprites.add(sprite);
            newSpriteIds.put(new Integer(entity.getId()), sprite);

            if (entity.hasC3() || entity.hasC3i()) {
                addC3Link(entity);
            }
        }

        entitySprites = newSprites;
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.