📄 infantry.java
字号:
/* * MegaMek - Copyright (C) 2000-2002 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. */package megamek.common;import java.io.Serializable;import java.util.Vector;/** * This class represents the lowest of the low, the ground pounders, * the city rats, the PBI (Poor Bloody Infantry). * <p/> * PLEASE NOTE!!! This class just represents unarmored infantry platoons * as described by CitiTech (c) 1986. I've never seen the rules for * powered armor, "anti-mech" troops, or Immortals. * * @author Suvarov454@sourceforge.net (James A. Damour ) * @version $revision:$ *//* * PLEASE NOTE!!! My programming style is to put constants first in * tests so the compiler catches my "= for ==" errors. */public class Infantry extends Entity implements Serializable{ // Private attributes and helper functions. /** * The number of men originally in this platoon. */ private int menStarting = 0; /** * The number of men alive in this platoon at the beginning of the phase, * before it begins to take damage. */ private int menShooting = 0; /** * The number of men left alive in this platoon. */ private int men = 0; /** * The kind of weapons used by this platoon. */ private long weapons = 0; /** * The amount of damage the platoon can do if it hits. */ private int[] damage = new int[INF_PLT_MAX_MEN + 1]; /* * Infantry have no critical slot limitations or locations. */ private static final int[] NUM_OF_SLOTS = {0}; private static final String[] LOCATION_ABBRS= { "Men" }; private static final String[] LOCATION_NAMES= { "Men" }; /** * Identify this platoon as anti-mek trained. */ private boolean antiMek = false; protected int runMP = 1; public int turnsLayingExplosives = -1; public static final int DUG_IN_NONE = 0; public static final int DUG_IN_WORKING = 1; //no protection, can't attack public static final int DUG_IN_COMPLETE = 2; //protected, restricted arc public static final int DUG_IN_FORTIFYING1 = 3; //no protection, can't attack public static final int DUG_IN_FORTIFYING2 = 4; //no protection, can't attack private int dugIn = DUG_IN_NONE; /** * Set up the damage array for this platoon for the given weapon type. * * @param weapon - the type of weapon used by this platoon. * @exception IllegalArgumentException if a bad weapon * type is passed. */ private void setDamage( long weapon ) { int man; int points; // MGs and Flamers have wierd damage profiles. double men_per_point; // The platoon does no damage when its out of men. this.damage[0] = 0; // The various weapons require different amounts of // men to cause additional points of damage. if (weapon == INF_RIFLE || weapon == INF_LRM) men_per_point = 4.0; else if (weapon == INF_MG || weapon == INF_FLAMER) men_per_point = 3.0; else if (weapon == INF_LASER || weapon == INF_SRM) men_per_point = 2.0; else throw new IllegalArgumentException( "Unknown infantry weapon: " + weapon ); // Loop through the men in the platoon, and assign damage based // upon the number of men it takes to do a point of damage. for ( man = 1, points = 1; man <= INF_PLT_MAX_MEN; man++, points++ ) { // Round all fractions up. this.damage[man] = (int) Math.ceil( points / men_per_point ); // MGs and Flamers do something wierd for the first point of damage if ( 1 == man && ( INF_MG == weapon || INF_FLAMER == weapon ) ) { points--; } } // Handle the next man in the platoon. // MGs and Flamers do something wierd for the last point of damage if ( INF_MG == weapon || INF_FLAMER == weapon ) { this.damage[INF_PLT_MAX_MEN] = (int) Math.ceil( INF_PLT_MAX_MEN / men_per_point ); } } // End private void setDamage( int ) throws Exception // Public and Protected constants, constructors, and methods. /** * The maximum number of men in an infantry platoon. */ public static final int INF_PLT_MAX_MEN = 28; /** * The maximum number of men in an infantry platoon. */ public static final int INF_PLT_JUMP_MAX_MEN = 21; /** * The maximum number of men in an infantry platoon. */ public static final int INF_PLT_CLAN_MAX_MEN = 25; /* * The kinds of weapons available to the PBI. * * By incredible luck, the AmmoType and WeaponType constants * do not overlap for these six weapons. */ public static final int INF_UNKNOWN = -1;// T_NA public static final int INF_RIFLE = 1; // T_AC public static final int INF_MG = 3; // T_MG public static final int INF_FLAMER = 2; // F_FLAMER public static final int INF_LASER = 4; // F_LASER public static final int INF_SRM = 9; // T_SRM public static final int INF_LRM = 7; // T_LRM /** * The location for infantry equipment. */ public static final int LOC_INFANTRY = 0; /** * The internal names of the anti-Mek attacks. */ public static final String LEG_ATTACK = "LegAttack"; public static final String SWARM_MEK = "SwarmMek"; public static final String STOP_SWARM = "StopSwarm"; public String[] getLocationAbbrs() { return LOCATION_ABBRS; } public String[] getLocationNames() { return LOCATION_NAMES; } /** * Returns the number of locations in this platoon (i.e. one). */ public int locations() { return 1; } /** * Generate a new, blank, infantry platoon. * Hopefully, we'll be loaded from somewhere. */ public Infantry() { // Instantiate the superclass. super(); // Create a "dead" leg rifle platoon. this.menStarting = 0; this.menShooting = 0; this.men = 0; this.weapons = INF_RIFLE; setMovementMode(IEntityMovementMode.INF_LEG); // Populate the damage array. this.setDamage(this.weapons); // Determine the number of MPs. this.setOriginalWalkMP(1); // Clear the weapon type to be set later. this.weapons = INF_UNKNOWN; } /** * Infantry can face freely (except when dug in) */ public boolean canChangeSecondaryFacing() { return (dugIn == DUG_IN_NONE); } /** * Infantry can face freely */ public boolean isValidSecondaryFacing( int dir ) { return true; } /** * Infantry can face freely */ public int clipSecondaryFacing( int dir ) { return dir; } /** * Infantry have no piloting skill (set to 5 for BV purposes) */ public void setCrew(Pilot p) { super.setCrew(p); this.getCrew().setPiloting(5); } /** * Return this Infantry's run MP. */ public int getRunMP(boolean gravity) { if (gravity) return applyGravityEffectsOnMP(this.getOriginalRunMP()); return this.getOriginalRunMP(); } /** * Infantry don't have MASC */ public int getRunMPwithoutMASC(boolean gravity) { return getRunMP(gravity); } /** * Get this infantry's orignal Run MP */ protected int getOriginalRunMP() { return this.runMP; } /** * Infantry can not enter water. */ public boolean isHexProhibited( IHex hex ) { if(hex.containsTerrain(Terrains.IMPASSABLE)) return true; if(hex.containsTerrain(Terrains.MAGMA)) return true; return (hex.terrainLevel(Terrains.WATER) > 0 && !hex.containsTerrain(Terrains.ICE)); } /** * Returns the name of the type of movement used. * This is Infantry-specific. */ public String getMovementString(int mtype) { switch(mtype) { case IEntityMovementType.MOVE_NONE : return "None"; case IEntityMovementType.MOVE_WALK : case IEntityMovementType.MOVE_RUN : switch (this.getMovementMode()) { case IEntityMovementMode.INF_LEG: return "Walked"; case IEntityMovementMode.INF_MOTORIZED: return "Biked"; case IEntityMovementMode.INF_JUMP: default : return "Unknown!"; } case IEntityMovementType.MOVE_VTOL_WALK: case IEntityMovementType.MOVE_VTOL_RUN: return "Flew"; case IEntityMovementType.MOVE_JUMP : return "Jumped"; default : return "Unknown!"; } } /** * Returns the abbreviation of the type of movement used. * This is Infantry-specific. */ public String getMovementAbbr(int mtype) { switch(mtype) { case IEntityMovementType.MOVE_NONE : return "N"; case IEntityMovementType.MOVE_WALK : return "W"; case IEntityMovementType.MOVE_RUN : switch (this.getMovementMode()) { case IEntityMovementMode.INF_LEG: return "R"; case IEntityMovementMode.INF_MOTORIZED: return "B"; default : return "?"; } case IEntityMovementType.MOVE_JUMP : return "J"; default : return "?"; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -