📄 entity.java
字号:
if (mtHeat && heat >= 48) { mod++; } return mod; } /** * Creates a new mount for this equipment and adds it in. */ public Mounted addEquipment(EquipmentType etype, int loc) throws LocationFullException { return addEquipment(etype, loc, false); } /** * Creates a new mount for this equipment and adds it in. */ public Mounted addEquipment(EquipmentType etype, int loc, boolean rearMounted) throws LocationFullException { Mounted mounted = new Mounted(this, etype); addEquipment(mounted, loc, rearMounted); return mounted; } protected void addEquipment(Mounted mounted, int loc, boolean rearMounted) throws LocationFullException { mounted.setLocation(loc, rearMounted); equipmentList.add(mounted); // add it to the proper sub-list if (mounted.getType() instanceof WeaponType) { weaponList.add(mounted); if(mounted.getType().hasFlag(WeaponType.F_ARTILLERY)) { aTracker.addWeapon(mounted); } // one-shot launchers need their single shot of ammo added. if (mounted.getType().hasFlag(WeaponType.F_ONESHOT)) { Mounted m = new Mounted(this, AmmoType.getOneshotAmmo(mounted)); m.setShotsLeft(1); mounted.setLinked(m); //Oneshot ammo will be identified by having a location // of null. Other areas in the code will rely on this. addEquipment(m, Entity.LOC_NONE, false); } } if (mounted.getType() instanceof AmmoType) { ammoList.add(mounted); } if (mounted.getType() instanceof MiscType) { miscList.add(mounted); } } public void addFailedEquipment(String s) { failedEquipmentList.addElement(s); } /** * Returns the equipment number of the specified equipment, or * -1 if equipment is not present. */ public int getEquipmentNum(Mounted mounted) { if (mounted != null) { return equipmentList.indexOf(mounted); } return -1; } /** * Returns an enumeration of all equipment */ public ArrayList<Mounted> getEquipment() { return equipmentList; } /** * Returns the equipment, specified by number */ public Mounted getEquipment(int index) { try { return equipmentList.get(index); } catch (IndexOutOfBoundsException ex) { return null; } } public EquipmentType getEquipmentType(CriticalSlot cs) { if (cs.getType() != CriticalSlot.TYPE_EQUIPMENT) return null; Mounted m = equipmentList.get(cs.getIndex()); return m.getType(); } /** * Returns an enumeration which contains the name of each * piece of equipment that failed to load. */ public Enumeration getFailedEquipment() { return failedEquipmentList.elements(); } public int getTotalAmmoOfType(EquipmentType et) { int totalShotsLeft = 0; for(Mounted amounted : getAmmo()) { if ( amounted.getType() == et && !amounted.isDumping() ) { totalShotsLeft += amounted.getShotsLeft(); } } return totalShotsLeft; } /** * Determine how much ammunition (of all munition types) remains * which is compatable with the given ammo. * * @param et - the <code>EquipmentType</code> of the ammo to be found. * This value may be <code>null</code>. * @return the <code>int</code> count of the amount of shots of all * munitions equivalent to the given ammo type. */ public int getTotalMunitionsOfType(EquipmentType et) { int totalShotsLeft = 0; for(Mounted amounted : getAmmo()) { if ( amounted.getType().equals(et) && !amounted.isDumping() ) { totalShotsLeft += amounted.getShotsLeft(); } } return totalShotsLeft; } /** * Returns the Rules.ARC that the weapon, specified by * number, fires into. */ public abstract int getWeaponArc(int wn); /** * Returns true if this weapon fires into the secondary facing arc. If * false, assume it fires into the primary. */ public abstract boolean isSecondaryArcWeapon(int weaponId); public Iterator<Mounted> getWeapons() { return weaponList.iterator(); } public ArrayList<Mounted> getWeaponList() { return weaponList; } /** * Returns the first ready weapon * * @return the index number of the first available weapon, or -1 if none are ready. */ public int getFirstWeapon() { for (Mounted mounted : getWeaponList()) { if (mounted.isReady()) { return getEquipmentNum(mounted); } } return -1; } /** * Returns the next ready weapon, starting at the specified index */ public int getNextWeapon(int start) { boolean past = false; for(Mounted mounted : getWeaponList()) { //FIXME // Logic must be inserted here to NOT always skip AMS once the // MaxTech rule for firing AMSes is implemented. if (past && (mounted != null) && (mounted.isReady()) && (!mounted.getType().hasFlag(WeaponType.F_AMS)) && ((mounted.getLinked() == null) || (mounted.getLinked().getShotsLeft()>0))) { if (mounted.getType().hasFlag(WeaponType.F_TAG) && game.getPhase()==IGame.PHASE_FIRING) { continue; } return getEquipmentNum(mounted); } if (getEquipmentNum(mounted) == start) { past = true; continue; } if (past && getEquipmentNum(mounted)==start) { return getFirstWeapon(); } } return getFirstWeapon(); } /** * Attempts to load all weapons with ammo */ public void loadAllWeapons() { for(Mounted mounted : getWeaponList()) { WeaponType wtype = (WeaponType)mounted.getType(); if (wtype.getAmmoType() != AmmoType.T_NA) { loadWeapon(mounted); } } } /** * Tries to load the specified weapon with the first available ammo */ public void loadWeapon(Mounted mounted) { for(Mounted mountedAmmo : getAmmo()) { if (loadWeapon(mounted, mountedAmmo)) break; } } /** * Tries to load the specified weapon with the first available ammo * of the same munition type as currently in use. If this fails, use first ammo. */ public void loadWeaponWithSameAmmo(Mounted mounted) { for(Mounted mountedAmmo : getAmmo()) { if (loadWeaponWithSameAmmo(mounted, mountedAmmo)) return; } //fall back to use any ammo loadWeapon(mounted); } /** * Tries to load the specified weapon with the specified ammo. * Returns true if successful, false otherwise. */ public boolean loadWeapon(Mounted mounted, Mounted mountedAmmo) { boolean success = false; WeaponType wtype = (WeaponType)mounted.getType(); AmmoType atype = (AmmoType)mountedAmmo.getType(); if (mountedAmmo.isAmmoUsable() && !wtype.hasFlag(WeaponType.F_ONESHOT) && atype.getAmmoType() == wtype.getAmmoType() && atype.getRackSize() == wtype.getRackSize()) { mounted.setLinked(mountedAmmo); success = true; } return success; } /** * Tries to load the specified weapon with the specified ammo. * Returns true if successful, false otherwise. */ public boolean loadWeaponWithSameAmmo(Mounted mounted, Mounted mountedAmmo) { AmmoType atype = (AmmoType)mountedAmmo.getType(); Mounted oldammo = mounted.getLinked(); if (oldammo != null && ((AmmoType)oldammo.getType()).getMunitionType() != atype.getMunitionType()) return false; return loadWeapon(mounted, mountedAmmo); } /** * Checks whether a weapon has been fired from the specified location this * turn */ public boolean weaponFiredFrom(int loc) { // check critical slots for used weapons for (int i = 0; i < this.getNumberOfCriticals(loc); i++) { CriticalSlot slot = getCritical(loc, i); // ignore empty & system slots if (slot == null || slot.getType() != CriticalSlot.TYPE_EQUIPMENT) { continue; } Mounted mounted = getEquipment(slot.getIndex()); if (mounted.getType() instanceof WeaponType && mounted.isUsedThisRound()) { return true; } } return false; } public ArrayList<Mounted> getAmmo() { return ammoList; } public ArrayList<Mounted> getMisc() { return miscList; } /** * Removes the first misc eq. whose name equals the specified string. Used * for removing broken tree clubs. */ public void removeMisc(String toRemove) { for(Mounted mounted:getMisc()) { if (mounted.getName().equals(toRemove)) { miscList.remove(mounted); equipmentList.remove(mounted); break; } } } public List<Mounted> getClubs() { List<Mounted> rv = new ArrayList<Mounted>(); for(Mounted m:getMisc()) { if(m.getType().hasFlag(MiscType.F_CLUB)) { rv.add(m); } } return rv; } /** * Check if the entity has an arbritrary type of misc * equipment * @param flag A MiscType.F_XXX * @param secondary A MiscType.S_XXX or -1 for don't care * @return true if at least one ready item. */ public boolean hasWorkingMisc(long flag, int secondary) { for (Mounted m : miscList) { if(m.getType() instanceof MiscType && m.isReady()) { MiscType type = (MiscType)m.getType(); if(type.hasFlag(flag) && (secondary == -1 || type.hasSubType(secondary))) return true; } } return false; } /** * Check if the entity has an arbritrary type of misc * equipment * @param flag A MiscType.F_XXX * @param secondary A MiscType.S_XXX or -1 for don't care * @param location The location to check e.g. Mech.LOC_LARM * @return true if at least one ready item. */ public boolean hasWorkingMisc(long flag, int secondary, int location) { for (Mounted m : miscList) { if(m.getType() instanceof MiscType && m.isReady() && m.getLocation() == location) { MiscType type = (MiscType)m.getType(); if(type.hasFlag(flag) && (secondary == -1 || type.hasSubType(secondary))) return true; } } return false; } /** * Returns the amount of heat that the entity can sink each * turn. */ public abstract int getHeatCapacity(); /** * Returns the amount of heat that the entity can sink each * turn, factoring in whether the entity is standing in water. */ public abstract int getHeatCapacityWithWater(); /** * Returns extra heat generated by engine crits */ public abstract int getEngineCritHeat(); /** * Returns a critical hit slot */ public CriticalSlot getCritical(int loc, int slot) { return crits[loc][slot]; } /** * Sets a critical hit slot */ public void setCritical(int loc, int slot, CriticalSlot cs) { crits[loc][slot] = cs; } /** * Adds a critical to the first available slot in the location. * * @return true if there was room for the critical */ public boolean addCritical(int loc, CriticalSlot cs) { for (int i = 0; i < getNumberOfCriticals(loc); i++) { if (getCritical(loc, i) == null) { crits[loc][i] = cs; return true; } } return false; //no slot available :( } /** * Attempts to set the given slot to the given critical. If the desired * slot is full, adds the critical to the first available slot. * * @return true if the crit was succesfully added to any slot */ public boolean addCritical(int loc, int slot, CriticalSlot cs) { if (getCritical(loc, slot) == null) { setCritical(loc, slot, cs); return true; } return addCritical(loc, cs); } /** * Removes all matching critical slots from the location */ public void remove
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -