⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 entity.java

📁 MegaMek is a networked Java clone of BattleTech, a turn-based sci-fi boardgame for 2+ players. Fight
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    }    public String getWeightClassName() {        return EntityWeightClass.getClassName(getWeightClass());    }        public void setWeight(float weight) {        this.weight = weight;    }    public boolean isOmni() {        return omni;    }    public void setOmni(boolean omni) {        this.omni = omni;    }    /**     * Returns the number of locations in the entity     */    public abstract int locations();    /**     * Returns the player that "owns" this entity.     */    public Player getOwner() {        return owner;    }    public void setOwner(Player player) {        this.owner = player;        this.ownerId = player.getId();        generateDisplayName();    }    public int getOwnerId() {        return ownerId;    }    /**     * Returns true if the other entity is an enemy of this entity.  This is     * more reliable than Player.isEnemyOf since it knows that an entity will     * never be an enemy of itself.     */    public boolean isEnemyOf(Entity other) {        if ( null == owner ) {            return ( id != other.getId() && ownerId != other.ownerId );        }        return id != other.getId() && owner.isEnemyOf(other.getOwner());    }    public Pilot getCrew() {        return crew;    }    public void setCrew(Pilot crew) {        this.crew = crew;    }    public boolean isShutDown() {        return shutDown;    }    public void setShutDown(boolean shutDown) {        this.shutDown = shutDown;    }    public boolean isDoomed() {        return doomed;    }    public void setDoomed(boolean doomed) {        // Doomed entities aren't in retreat.        if ( doomed ) {            this.setRemovalCondition( IEntityRemovalConditions.REMOVE_SALVAGEABLE );        }        this.doomed = doomed;    }    public boolean isDestroyed() {        return destroyed;    }    public void setDestroyed(boolean destroyed) {        this.destroyed = destroyed;    }    // Targetable interface    public int getTargetType() { return Targetable.TYPE_ENTITY; }    public int getTargetId() { return getId(); }    public int getHeight() { return height(); }    // End Targetable interface    public boolean isDone() {        return done;    }    public void setDone(boolean done) {        this.done = done;    }    /**     * This method should <strong>only</stong> be called when needed to     * remove a dead swarmer's game turn.     */    public void setUnloaded( boolean unloaded ) {        this.unloadedThisTurn = unloaded;    }    /**     * Determine if this entity participate in the current game phase.     *     * @return  <code>true</code> if this entity is not shut down, is     *          not destroyed, has an active crew, and was not unloaded     *          from a transport this turn.  <code>false</code> otherwise.     */    public boolean isActive() {        return this.isActive(-1);    }    public boolean isActive(int turn) {        boolean isActive = !shutDown && !destroyed && getCrew().isActive() && !this.unloadedThisTurn;        if ( (turn > -1) && isActive ) {            isActive = !deployed && shouldDeploy(turn);        } else {            isActive = isActive && deployed;        }        return isActive;    }    /**     * Returns true if this entity is selectable for action.  Transported     * entities can not be selected.     */    public boolean isSelectableThisTurn() {        return !done && (conveyance == Entity.NONE) &&            !this.unloadedThisTurn && !isClearingMinefield();    }    /**     * Returns true if this entity could potentially be loaded     * (did not move from starting hex)     */    public boolean isLoadableThisTurn() {        return (delta_distance == 0) && (conveyance == Entity.NONE) &&            !this.unloadedThisTurn && !isClearingMinefield();    }    /**     * Determine if this <code>Entity</code> was unloaded previously this turn.     *     * @return  <code>true</code> if this entity was unloaded for any reason     *          during this turn.     */    public boolean isUnloadedThisTurn() {        return this.unloadedThisTurn;    }    /**     * Returns true if this entity is targetable for attacks     */    public boolean isTargetable() {        return !destroyed && !doomed && !crew.isDead() && deployed && !isOffBoard();    }    public boolean isProne() {        return prone;    }    public void setProne(boolean prone) {        this.prone = prone;        if(prone) {            hullDown = false;        }    }    public boolean isHullDown() {        return hullDown;    }    public void setHullDown(boolean down) {        hullDown = down;    }    /**     * Is this entity shut down or is the crew unconscious?     */    public boolean isImmobile() {        return shutDown || crew.isUnconscious();    }    public boolean isCharging() {        return displacementAttack instanceof ChargeAttackAction;    }    public boolean isPushing() {        return displacementAttack instanceof PushAttackAction;    }    public boolean isMakingDfa() {        return displacementAttack instanceof DfaAttackAction;    }    public boolean hasDisplacementAttack() {        return displacementAttack != null;    }    public DisplacementAttackAction getDisplacementAttack() {        return displacementAttack;    }    public void setDisplacementAttack(DisplacementAttackAction displacementAttack) {        this.displacementAttack = displacementAttack;    }    /**     * Returns true if any other entities this entity knows of are making a     * displacement attack on this entity.     */    public boolean isTargetOfDisplacementAttack() {        return findTargetedDisplacement() != null;    }    /**     * Returns any known displacement attacks (should only be one) that this     * entity is a target of.     */    public DisplacementAttackAction findTargetedDisplacement() {        for (Enumeration i = game.getEntities(); i.hasMoreElements();) {            Entity other = (Entity)i.nextElement();            if (other.hasDisplacementAttack()            && other.getDisplacementAttack().getTargetId() == id) {                return other.getDisplacementAttack();            }        }        return null;    }    public boolean isUnjammingRAC() {        return unjammingRAC;    }    public void setUnjammingRAC(boolean u) {        unjammingRAC = u;    }    public boolean isFindingClub() {        return findingClub;    }    public void setFindingClub(boolean findingClub) {        this.findingClub = findingClub;    }    /**     * Set whether or not the mech's arms are flipped to the rear     */    public void setArmsFlipped(boolean armsFlipped) {        this.armsFlipped = armsFlipped;        game.processGameEvent(new GameEntityChangeEvent(this, this));            }    /**     * Returns true if the mech's arms are flipped to the rear     */    public boolean getArmsFlipped() {        return this.armsFlipped;    }    /**     * Returns the current position of this entity on     * the board.     *     * This is not named getLocation(), since I want the word location to     * refer to hit locations on a mech or vehicle.     */    public Coords getPosition() {        return position;    }    /**     * Sets the current position of this entity on the board.     *     * @param position the new position.     */    public void setPosition(Coords position) {        this.position = position;    }    /**     * Sets the current elevation of this entity above the ground.     *     * @param elevation an <code>int</code> representing the new position.     */    public void setElevation(int elevation) {        this.elevation=elevation;    }    /**     * A helper function for fiddling with elevation.     * Takes the current hex, a hex being moved to, returns the elevation the      * Entity will be considered to be at w/r/t it's new hex.     */    public int calcElevation(IHex current, IHex next, int assumedElevation, boolean climb) {        int retVal = assumedElevation;        if ((getMovementMode() == IEntityMovementMode.SUBMARINE)                || (getMovementMode() == IEntityMovementMode.VTOL)                || (getMovementMode() == IEntityMovementMode.QUAD_SWIM && hasUMU())                || (getMovementMode() == IEntityMovementMode.BIPED_SWIM&& hasUMU())) {            retVal += current.surface();            retVal -= next.surface();        } else {            if ((getMovementMode() != IEntityMovementMode.HOVER)                    && (getMovementMode() != IEntityMovementMode.NAVAL)                    && (getMovementMode() != IEntityMovementMode.HYDROFOIL)) {                int prevWaterLevel = 0;                if (current.containsTerrain(Terrains.WATER)) {                    prevWaterLevel = current.terrainLevel(Terrains.WATER);                    if(!(current.containsTerrain(Terrains.ICE))                             || assumedElevation < 0) {                        //count water, only if the entity isn't on ice surface                        retVal += current.terrainLevel(Terrains.WATER);                                        }                }                if (next.containsTerrain(Terrains.WATER)) {                    int waterLevel = next.terrainLevel(Terrains.WATER);                    if(next.containsTerrain(Terrains.ICE)) {                        //a mech can only climb out onto ice in depth 2 or shallower water                        //mech on the surface will stay on the surface                                                if((waterLevel == 1 && prevWaterLevel == 1)                            || (prevWaterLevel <= 2 && climb)                            || assumedElevation >= 0) {                            retVal += waterLevel;                        }                    }                    retVal -= waterLevel;                }            }            if(next.containsTerrain(Terrains.BUILDING)                   || current.containsTerrain(Terrains.BUILDING)) {                int bldcur = Math.max(0, current.terrainLevel(Terrains.BLDG_ELEV));                int bldnex = Math.max(0, next.terrainLevel(Terrains.BLDG_ELEV));                if((assumedElevation == bldcur && climb && (this instanceof Mech))                        || retVal > bldnex) {                    retVal = bldnex;                }                else if(bldnex + next.surface() > bldcur + current.surface()) {                    retVal += current.surface();                    retVal -= next.surface();                }            }            if((getMovementMode() != IEntityMovementMode.NAVAL)                    && (getMovementMode() != IEntityMovementMode.HYDROFOIL)                    && (next.containsTerrain(Terrains.BRIDGE)                            || current.containsTerrain(Terrains.BRIDGE))) {                int brdnex = Math.max(-(next.depth()), next.terrainLevel(Terrains.BRIDGE_ELEV));                if(Math.abs((next.surface() + brdnex) - (current.surface() + assumedElevation))<= getMaxElevationChange()) {                    //bridge is reachable at least                    if(climb                            || Math.abs((next.surface() + retVal) - (current.surface() + assumedElevation)) > getMaxElevationChange()                            || !isElevationValid(retVal, next)) {                        //use bridge if you can't use the base terrain or if you prefer to by climb mode                        retVal = brdnex;                    }                }            }        }        return retVal;    }    public int calcElevation(IHex current, IHex next) {        return calcElevation(current,next,elevation, false);    }    /**     * Returns the elevation of this entity.     */    public int getElevation() {        if ( Entity.NONE != this.getTransportId() ) {            return game.getEntity(this.getTransportId()).getElevation();        }        if (( null == getPosition() ) && (isDeployed()))                throw new IllegalStateException                    ("Entity #" + this.getId() + " does not know its position.");        if (isOffBoard()) {            return 0;        }        return elevation;    }    public boolean canGoDown() {        return canGoDown(elevation,getPosition());    }        /**     * is it possible to go down, or are we landed/just above the water/treeline?     * assuming passed elevation.     */    public boolean canGoDown(int assumedElevation,Coords assumedPos) {        boolean inWaterOrWoods = false;        IHex hex = getGame().getBoard().getHex(assumedPos);        int altitude = assumedElevation+hex.surface();        int minAlt = hex.surface();        if(hex.containsTerrain(Terrains.WOODS) || hex.containsTerrain(Terrains.WATER) || hex.containsTerrain(Terrains.JUNGLE)) {            inWaterOrWoods=true;        }        switch(getMovementMode()) {        case IEntityMovementMode.INF_JUMP:        case IEntityMovementMode.INF_LEG:        case IEntityMovementMode.INF_MOTORIZED:            minAlt -= Math.max(0, hex.terrainLevel(Terrains.BLDG_BASEMENT));            break;        case IEntityMovementMode.VTOL:            minAlt = hex.ceiling();            if(inWaterOrWoods) {                minAlt++; //can't land here            }            break;        case IEntityMovementMode.SUBMARINE:        case IEntityMovementMode.BIPED_SWIM:        case IEntityMovementMode.QUAD_SWIM:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -