📄 mounted.java
字号:
/* * MegaMek - * Copyright (C) 2000,2001,2002,2003,2004,2005 Ben Mazur (bmazur@sev.org) * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation; either version 2 of the License, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. *//* * Mounted.java * * Created on April 1, 2002, 1:29 PM */package megamek.common;import java.io.Serializable;/** * This describes equipment mounted on a mech. * * @author Ben * @version */public class Mounted implements Serializable, RoundUpdated { private boolean usedThisRound = false; private boolean destroyed = false; private boolean hit = false; private boolean missing = false; private boolean jammed = false; private boolean useless = false; private boolean fired = false; //Only true for used OS stuff. private boolean rapidfire = false; //MGs in rapid-fire mode private boolean hotloaded = false; //Hotloading for ammoType private int mode; //Equipment's current state. On or Off. Sixshot or Fourshot, etc private int pendingMode = -1; // if mode changes happen at end of turn private int location; private boolean rearMounted; private Mounted linked = null; // for ammo, or artemis private Mounted linkedBy = null; // reverse link for convenience private Entity entity; // what I'm mounted on private transient EquipmentType type; private String typeName; // ammo-specific stuff. Probably should be a subclass private int shotsLeft; private boolean m_bPendingDump; private boolean m_bDumping; // handle split weapons private boolean bSplit = false; private int nFoundCrits = 0; private int secondLocation = 0; // mine type private int mineType = MINE_NONE; // vibrabomb mine setting private int vibraSetting = 20; private int phase = IGame.PHASE_UNKNOWN; public static final int MINE_NONE = -1; public static final int MINE_CONVENTIONAL = 0; public static final int MINE_VIBRABOMB = 1; public static final int MINE_COMMAND_DETONATED = 2; //New stuff for shields protected int baseDamageAbsorptionRate = 0; protected int baseDamageCapacity = 0; protected int damageTaken = 0; /** Creates new Mounted */ public Mounted(Entity entity, EquipmentType type) { this.entity = entity; this.type = type; this.typeName = type.getInternalName(); if (type instanceof AmmoType) { shotsLeft = ((AmmoType)type).getShots(); } if (type instanceof MiscType && type.hasFlag(MiscType.F_MINE)) { this.mineType = MINE_CONVENTIONAL; } if ( type instanceof MiscType && ((MiscType)type).isShield() ){ MiscType shield = (MiscType)type; baseDamageAbsorptionRate = shield.baseDamageAbsorptionRate; baseDamageCapacity = shield.baseDamageCapacity; damageTaken = shield.damageTaken; } } /** * Changing ammo loadouts allows updating AmmoTypes of existing bins. * This is the only circumstance under which this should happen. */ public void changeAmmoType(AmmoType at) { if ( !(type instanceof AmmoType)) { System.out.println("Attempted to change ammo type of non-ammo"); return; } this.type = at; this.typeName = at.getInternalName(); if (this.location == Entity.LOC_NONE) { //Oneshot launcher shotsLeft = 1; } else { //Regular launcher shotsLeft = at.getShots(); } } /** * Restores the equipment from the name */ public void restore() { if (typeName == null) typeName = type.getName(); else this.type = EquipmentType.get(typeName); if (this.type == null) { System.err.println("Mounted.restore: could not restore equipment type \"" + typeName + "\""); } } public EquipmentType getType() { return type; } /** * * @return the current mode of the equipment, or <code>null</code> * if it's not available. */ public EquipmentMode curMode() { if (mode >= 0 && mode < type.getModesCount()) return type.getMode(mode); return null; } /** * * @return the pending mode of the equipment. */ public EquipmentMode pendingMode() { if (pendingMode < 0 || pendingMode >= type.getModesCount()) { return EquipmentMode.getMode("None"); } return type.getMode(pendingMode); } /** * Switches the equipment mode to the next available. * @return new mode number, or <code>-1</code> if it's not available. */ public int switchMode() { if (type.hasModes()) { int nMode = 0; if (pendingMode > -1) { nMode = (pendingMode + 1) % type.getModesCount(); } else { nMode = (mode + 1) % type.getModesCount(); } setMode(nMode); return nMode; } return -1; } /** * Sets the equipment mode to the mode denoted by the given mode name * @param newMode the name of the desired new mode * @return new mode number on success, <code>-1<code> otherwise. */ public int setMode(String newMode) { for (int x = 0, e = type.getModesCount(); x < e; x++) { if (type.getMode(x).equals(newMode)) { setMode(x); return x; } } return -1; } /** * Sets the equipment mode to the mode denoted by the given mode number * @param newMode the number of the desired new mode */ public void setMode(int newMode) { if (type.hasModes()) { megamek.debug.Assert.assertTrue(newMode >= 0 && newMode < type.getModesCount(), "Invalid mode, mode="+newMode+", modesCount="+type.getModesCount()); if (type.hasInstantModeSwitch()) { mode = newMode; } else if (pendingMode != newMode) { pendingMode = newMode; } } } public void newRound(int roundNumber) { setUsedThisRound(false); if ((type != null) && (type.hasModes() && pendingMode != -1)) { mode = pendingMode; pendingMode = -1; } } /** * Shortcut to type.getName() */ public String getName() { return type.getName(); } public String getDesc() { StringBuffer desc; switch (getMineType()) { case 0: desc = new StringBuffer(Messages.getString("Mounted.ConventionalMine")); break; case 1: desc = new StringBuffer(Messages.getString("Mounted.VibraBombMine")); break; case 2: desc = new StringBuffer(Messages.getString("Mounted.CommandDetonatedMine")); break; case -1: default: desc = new StringBuffer(type.getDesc()); } if (destroyed) { desc.insert(0, "*"); } else if (useless) { desc.insert(0, "x "); } else if (usedThisRound) { desc.insert(0, "+"); } else if (jammed) { desc.insert(0, "j "); } else if (fired) { desc.insert(0, "x "); } if (rearMounted) { desc.append(" (R)"); } if (type instanceof AmmoType && location != Entity.LOC_NONE) { desc.append(" ("); desc.append(shotsLeft); desc.append(")"); } return desc.toString(); } public boolean isReady() { return !usedThisRound && !destroyed && !jammed && !useless; } public boolean isUsedThisRound() { return usedThisRound; } public void setUsedThisRound(boolean usedThisRound) { this.usedThisRound = usedThisRound; if (usedThisRound) { phase = entity.game.getPhase(); } else { phase = IGame.PHASE_UNKNOWN; } } public int usedInPhase () { if (usedThisRound) { return phase; } return IGame.PHASE_UNKNOWN; } public boolean isBreached() { return useless; } public void setBreached(boolean breached) { this.useless = breached; } public boolean isDestroyed() { return destroyed; } public void setDestroyed(boolean destroyed) { this.destroyed = destroyed; } public boolean isHit() { return hit; } public void setHit(boolean hit) { this.hit = hit; } public boolean isMissing() { return missing; } public void setMissing(boolean missing) { this.missing = missing; } public boolean isJammed() { return jammed; } public void setJammed(boolean j) { jammed = j; } public int getShotsLeft() { return shotsLeft; } public void setShotsLeft(int shotsLeft) { if (shotsLeft < 0) shotsLeft = 0; this.shotsLeft = shotsLeft; } /** * Returns how many shots the weapon is using */ public int howManyShots() { final WeaponType wtype = (WeaponType)this.getType(); int nShots = 1; // figure out # of shots for variable-shot weapons if (((wtype.getAmmoType() == AmmoType.T_AC_ULTRA) || (wtype.getAmmoType() == AmmoType.T_AC_ULTRA_THB)) && this.curMode().equals("Ultra")) { nShots = 2; } //sets number of shots for AC rapid mode else if ( (wtype.getAmmoType() == AmmoType.T_AC || (wtype.getAmmoType() == AmmoType.T_LAC)) && wtype.hasModes() && this.curMode().equals("Rapid")) { nShots = 2; } else if (wtype.getAmmoType() == AmmoType.T_AC_ROTARY || wtype.getInternalName().equals(BattleArmor.MINE_LAUNCHER)) { if (this.curMode().equals("2-shot")) { nShots = 2; } else if (this.curMode().equals("4-shot")) { nShots = 4;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -