Package megamek.common

Examples of megamek.common.Entity


        return retVal;
    }

    public Entity loadEntity(File f, String entityName) {
        Entity entity = null;
        try {
            entity = new MechFileParser(f, entityName).getEntity();
        } catch (megamek.common.loaders.EntityLoadingException e) {
            System.out.println("Exception: " + e.toString());
        }
View Full Code Here


        int failures = 0;
        for (int i = 0; i < ms.length; i++) {
            if (ms[i].getUnitType().equals("Mek")
                    || ms[i].getUnitType().equals("Tank")) {
                Entity entity = loadEntity(ms[i].getSourceFile(), ms[i]
                        .getEntryName());
                if (entity == null)
                    continue;
                if (!checkEntity(entity, ms[i].getSourceFile().toString(),
                        false))
View Full Code Here

                return;
            }
        }

        if (f != null) {
            Entity entity = null;
            try {
                entity = new MechFileParser(f, entityName).getEntity();
            } catch (megamek.common.loaders.EntityLoadingException e) {
                System.err.println("Exception: " + e.toString());
                System.err.println("Exception: " + e.getMessage());
View Full Code Here

     * double-blind games.
     */
    private void updateVisibilityIndicator() {
        Vector<Entity> vAllEntities = game.getEntitiesVector();
        for (int x = 0; x < vAllEntities.size(); x++) {
            Entity e = vAllEntities.elementAt(x);
            boolean previousVisibleValue = e.isVisibleToEnemy();
            boolean previousSeenValue = e.isSeenByEnemy();
            e.setVisibleToEnemy(false);
            Vector<Player> vCanSee = whoCanSee(e);
            for (int y = 0; y < vCanSee.size(); y++) {
                Player p = vCanSee.elementAt(y);
                if (e.getOwner().isEnemyOf(p) && !p.isObserver()) {
                    e.setVisibleToEnemy(true);
                    e.setSeenByEnemy(true);
                }
            }
            if ((previousVisibleValue != e.isVisibleToEnemy()) || (previousSeenValue != e.isSeenByEnemy())) {
                sendVisibilityIndicator(e);
            }
        }
    }
View Full Code Here

                // prepare and return array
                Entity[] out = new Entity[vEntities.size()];
                vEntities.copyInto(out);
                return out;
            }
            Entity e = parseEntityLine(s);

            // Damage Plan Stuff
            boolean dpCreated = false;
            DamagePlan dp = new DamagePlan(e);
            s = p.getProperty("Unit_" + sFaction + "_" + i + "_Damage");
            if (s != null) {
                int nBlocks = Integer.parseInt(s);
                m_vDamagePlans.addElement(new DamagePlan(e, nBlocks));
            }

            // Add the Specif Dammage if it exists
            s = p.getProperty("Unit_" + sFaction + "_" + i + "_DamageSpecific");
            if (s != null) {
                StringTokenizer st = new StringTokenizer(s, ",");
                while (st.hasMoreTokens()) {
                    dp.AddSpecificDammage(st.nextToken());
                }
                dpCreated = true;
            }

            // Add Crit Hits if it exists
            boolean chpCreated = false;
            s = p.getProperty("Unit_" + sFaction + "_" + i + "_CritHit");
            CritHitPlan chp = new CritHitPlan(e);
            if (s != null) {
                StringTokenizer st = new StringTokenizer(s, ",");
                while (st.hasMoreTokens()) {
                    chp.AddCritHit(st.nextToken());
                }
                chpCreated = true;
            }

            // Add Set Ammo Locations
            boolean sapCreated = false;
            s = p.getProperty("Unit_" + sFaction + "_" + i + "_SetAmmoTo");
            SetAmmoPlan sap = new SetAmmoPlan(e);
            if (s != null) {
                StringTokenizer st = new StringTokenizer(s, ",");
                while (st.hasMoreTokens()) {
                    sap.AddSetAmmoTo(st.nextToken());
                }
                sapCreated = true;
            }

            if (chpCreated)
                m_vCritHitPlans.addElement(chp);
            if (dpCreated)
                m_vDamagePlans.addElement(dp);
            if (sapCreated)
                m_vSetAmmoTo.addElement(sap);

            // Check for pilot hits
            s = p.getProperty("Unit_" + sFaction + "_" + i + "_PilotHits");
            if (null != s) {
                int hits = Integer.parseInt(s);
                if (hits > 5) {
                    hits = 0;
                }
                e.crew.setHits(hits);
            }

            // Check for unit external ids
            s = p.getProperty("Unit_" + sFaction + "_" + i + "_ExternalID");
            if (null != s) {
                e.setExternalId(Integer.parseInt(s));
            }

            // Check for advantages
            s = p.getProperty("Unit_" + sFaction + "_" + i + "_Advantages");
            if (null != s) {
                parseAdvantages(e, s);
            }

            // Check for autoeject
            s = p.getProperty("Unit_" + sFaction + "_" + i + "_AutoEject");
            if (null != s) {
                parseAutoEject(e, s);
            }

            // Check for commander
            s = p.getProperty("Unit_" + sFaction + "_" + i + "_Commander");
            if (null != s) {
                parseCommander(e, s);
            }

            // Check for deployment
            s = p
                    .getProperty("Unit_" + sFaction + "_" + i
                            + "_DeploymentRound");
            if (null != s) {
                int round = 0;

                try {
                    round = Integer.parseInt(s);
                } catch (Exception ex) {
                    throw new Exception("Bad deployment round setting (" + s
                            + ") for unit " + sFaction + ":" + i);
                }

                if (round < 0) {
                    System.out.println("Deployment round setting of '" + round
                            + "' for " + sFaction + ":" + i
                            + " will be ignored and set to 0");
                    round = 0;
                }

                if (round > 0) {
                    if (player.getStartingPos() == 0) {
                        throw new Exception(
                                "Can not combine a starting position of 'any' with delayed deployment.");
                    }

                    System.out.println(e.getDisplayName()
                            + " will be deployed before round " + round);
                    e.setDeployRound(round);
                }
            }

            vEntities.addElement(e);
        }
View Full Code Here

            MechSummary ms = MechSummaryCache.getInstance().getMech(sRef);
            if (ms == null) {
                throw new Exception("Scenario requires missing entity: " + sRef);
            }
            System.out.println("Loading " + ms.getName());
            Entity e = new MechFileParser(ms.getSourceFile(), ms.getEntryName())
                    .getEntity();
            e
                    .setCrew(new Pilot(st.nextToken(), Integer.parseInt(st
                            .nextToken()), Integer.parseInt(st.nextToken())));
            try {
                String direction = st.nextToken();
                if (direction.equalsIgnoreCase("N")) {
                    e.setFacing(0);
                } else if (direction.equalsIgnoreCase("NW")) {
                    e.setFacing(5);
                } else if (direction.equalsIgnoreCase("SW")) {
                    e.setFacing(4);
                } else if (direction.equalsIgnoreCase("S")) {
                    e.setFacing(3);
                } else if (direction.equalsIgnoreCase("SE")) {
                    e.setFacing(2);
                } else if (direction.equalsIgnoreCase("NE")) {
                    e.setFacing(1);
                }
                int x = Integer.parseInt(st.nextToken()) - 1;
                int y = Integer.parseInt(st.nextToken()) - 1;
                Coords coords = new Coords(x, y);
                e.setPosition(coords);
                e.setDeployed(true);
            } catch (NoSuchElementException ex) {
            }
            return e;
        } catch (NumberFormatException e) {
            e.printStackTrace();
            throw new Exception("Unparseable entity line: " + s);
        } catch (NoSuchElementException e) {
            e.printStackTrace();
            throw new Exception("Unparseable entity line: " + s);
        } catch (EntityLoadingException e) {
            e.printStackTrace();
            throw new Exception("Unparseable entity line: " + s
                    + "\n   Unable to load mech: " + e.getMessage());
        }
    }
View Full Code Here

                //check for quicksand that has been around at least one turn
                if(currentHex.terrainLevel(Terrains.SWAMP) == 3) {
                    //sink any units that occupy this hex
                    Enumeration<Entity> entities = game.getEntities(currentCoords);
                    while (entities.hasMoreElements()) {
                        final Entity entity = entities.nextElement();
                        if(entity.isStuck()) {
                            server.doSinkEntity(entity);
                        }
                    }
                }
                // check for any quicksand created this turn
View Full Code Here

        return StringUtil.makeLength(String.valueOf(nArmor), spaces, true);
    }

    public static void main(String[] ARGS) throws Exception {
        MechSummary ms = MechSummaryCache.getInstance().getMech(ARGS[0]);
        Entity e = new MechFileParser(ms.getSourceFile(), ms.getEntryName())
                .getEntity();
        System.out.println(format(e));
    }
View Full Code Here

        return toHit(game, attackerId, target, chargeSrc);
    }

    public ToHitData toHit(IGame game) {
        final Entity entity = game.getEntity(getEntityId());
        return toHit(game, getEntityId(), game.getTarget(getTargetType(),
                getTargetId()), entity.getPosition());
    }
View Full Code Here

            return;
        }

        // get units in hex
        for (Enumeration<Entity> impactHexHits = game.getEntities(coords); impactHexHits.hasMoreElements();) {
            Entity entity = impactHexHits.nextElement();
            int hits = damage;
            ToHitData toHit = new ToHitData();
            int cluster = 5;

            // Check: is entity excluded?
            if (entity == exclude) {
                continue;
            }

            // Check: is entity inside building?
            if ((bldg != null) && (bldgAbsorbs > 0) && (entity.getElevation() < hex.terrainLevel(Terrains.BLDG_ELEV))) {
                cluster -= bldgAbsorbs;
                if (entity instanceof Infantry) {
                    continue; // took its damage already from building damage
                } else if (cluster <= 0) {
                    // entity takes no damage
                    r = new Report(6426);
                    r.subject = subjectId;
                    r.addDesc(entity);
                    vPhaseReport.add(r);
                    continue;
                } else {
                    r = new Report(6425);
                    r.subject = subjectId;
                    r.add(bldgAbsorbs);
                    vPhaseReport.add(r);
                }
            }

            if (flak) {
                // Check: is entity not a VTOL in flight
                if (!((entity instanceof VTOL) || (entity.getMovementMode() == IEntityMovementMode.VTOL))) {
                    continue;
                }
                // Check: is entity at correct elevation?
                if (entity.getElevation() != flakElevation) {
                    continue;
                }
            } else {
                // Check: is entity a VTOL in flight?
                if ((entity instanceof VTOL) || (entity.getMovementMode() == IEntityMovementMode.VTOL)) {
                    // VTOLs take no damage from normal artillery unless landed
                    if ((entity.getElevation() != 0) && (entity.getElevation() != hex.terrainLevel(Terrains.BLDG_ELEV)) && (entity.getElevation() != hex.terrainLevel(Terrains.BRIDGE_ELEV))) {
                        continue;
                    }
                }
            }

            // Work out hit table to use
            if (attackSource != null) {
                toHit.setSideTable(entity.sideTable(attackSource));
                if ((ammo != null) && (ammo.getMunitionType() == AmmoType.M_CLUSTER) && attackSource.equals(coords)) {
                    if (entity instanceof Mech) {
                        toHit.setHitTable(ToHitData.HIT_ABOVE);
                    } else if (entity instanceof Tank) {
                        toHit.setSideTable(ToHitData.SIDE_FRONT);
                        toHit.addModifier(2, "cluster artillery hitting a Tank");
                    }
                }
            }

            // convention infantry take x2 damage from AE weapons
            if ((entity instanceof Infantry) && !(entity instanceof BattleArmor)) {
                hits *= 2;
            }

            // Entity/ammo specific damage modifiers
            if (ammo != null) {
                if (ammo.getMunitionType() == AmmoType.M_CLUSTER) {
                    if (hex.containsTerrain(Terrains.FORTIFIED) && (entity instanceof Infantry) && !(entity instanceof BattleArmor)) {
                        hits *= 2;
                    }
                } else if (ammo.getMunitionType() == AmmoType.M_FLECHETTE) {
                    // wheeled and hover tanks take movement critical
                    if ((entity instanceof Tank) && ((entity.getMovementMode() == IEntityMovementMode.WHEELED) || (entity.getMovementMode() == IEntityMovementMode.HOVER))) {
                        r = new Report(6480);
                        r.subject = entity.getId();
                        r.addDesc(entity);
                        r.add(toHit.getTableDesc());
                        r.add(0);
                        vPhaseReport.add(r);
                        vPhaseReport.addAll(vehicleMotiveDamage((Tank) entity, 0));
                        continue;
                    }
                    // only infantry and support vees with bar < 5 are affected
                    if ((entity instanceof BattleArmor) || (entity.getBARRating() > 4)) {
                        continue;
                    }
                    if (entity instanceof Infantry) {
                        hits = Compute.d6(damage);
                        hits *= 2;
                    }
                    if (entity.getBARRating() < 5) {
                        switch (ammo.getAmmoType()) {
                        case AmmoType.T_LONG_TOM:
                            // hack: check if damage is still at 4, so we're in the
                            // center hex. otherwise, do no damage
                            if (damage == 4) {
                                damage = (5 - entity.getBARRating()) * 5;
                            } else {
                                continue;
                            }
                            break;
                        case AmmoType.T_SNIPER:
                            // hack: check if damage is still at 2, so we're in the
                            // center hex. otherwise, do no damage
                            if (damage == 2) {
                                damage = (5 - entity.getBARRating()) * 3;
                            } else {
                                continue;
                            }
                            break;
                        case AmmoType.T_THUMPER:
                            // no need to check for damage, because falloff = damage for the thumper
                            damage = 5 - entity.getBARRating();
                            break;
                        }
                    }
                }
            }

            // Do the damage
            r = new Report(6480);
            r.subject = entity.getId();
            r.addDesc(entity);
            r.add(toHit.getTableDesc());
            r.add(hits);
            vPhaseReport.add(r);
            if (entity instanceof BattleArmor) {
                // BA take full damage to each trooper, ouch!
                for (int loc = 0; loc < entity.locations(); loc++) {
                    if (entity.getInternal(loc) > 0) {
                        HitData hit = new HitData(loc);
                        vPhaseReport.addAll(damageEntity(entity, hit, hits, false, DamageType.NONE, false, true, false));
                    }
                }
            } else {
                while (hits > 0) {
                    HitData hit = entity.rollHitLocation(toHit.getHitTable(), toHit.getSideTable());

                    vPhaseReport.addAll(damageEntity(entity, hit, Math.min(cluster, hits), false, DamageType.NONE, false, true, false));
                    hits -= Math.min(5, hits);
                }
            }
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.