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

📄 custombattlearmordialog.java

📁 MegaMek is a networked Java clone of BattleTech, a turn-based sci-fi boardgame for 2+ players. Fight
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        retVal.append("\n");        return retVal.toString();    }    private void calcCurrentWeight() {        stateCurrentWeight = 0;        // Add in the chassis weight.        stateCurrentWeight += getChassisWeight();        // Add in the weight of the unit's armor...        stateCurrentWeight += getArmorWeight();        // Add in the unit's ground movement weight...        stateCurrentWeight += getGroundMPWeight();        // Add in the unit's jump/VTOL/UMU movement weight...        stateCurrentWeight += getJumpMPWeight();        // Add in the weight of all the unit's other equipment.        stateCurrentWeight += getManipulatorWeight();        if (leftArmEquipment != null) {            Iterator tmpE = leftArmEquipment.iterator();            while (tmpE.hasNext()) {                BattleArmorEquipment tmpBAE = (BattleArmorEquipment) (tmpE.next());                stateCurrentWeight += tmpBAE.weight;            }        }        if (rightArmEquipment != null) {            Iterator tmpE = rightArmEquipment.iterator();            while (tmpE.hasNext()) {                BattleArmorEquipment tmpBAE = (BattleArmorEquipment) (tmpE.next());                stateCurrentWeight += tmpBAE.weight;            }        }        if (torsoEquipment != null) {            Iterator tmpE = torsoEquipment.iterator();            while (tmpE.hasNext()) {                BattleArmorEquipment tmpBAE = (BattleArmorEquipment) (tmpE.next());                stateCurrentWeight += tmpBAE.weight;            }        }        //FIXME        // Needs to finish updating stateCurrentWeight!    }    public boolean isValid() {        // We need to check a whole bunch of crap to make sure this is valid.        // Calculate the weight up front, just to make sure it's been calculated and updated!        calcCurrentWeight();        // We'll arbitrarily require the squad to have a name.        // No blank designations.        if ((m_tfBAName.getText() == null)                || (m_tfBAName.getText().trim().length() < 1)) {            invalidReason = "Squads must be named.";            return false;        }        // Quad chassis can't be PA(L)        if ((stateChassisType == CHASSIS_TYPE_QUAD)                && (stateWeightClass == WEIGHT_CLASS_PAL)) {            invalidReason = "PA(L) suits cannot have a quad chassis.";            return false;        }        // Make sure it's not currently overweight.        // According to the CBT folks, it's legal for it to be underweight.        if (stateCurrentWeight > stateMaxWeight) {            invalidReason = "Suit overweight.";            return false;        }        // Check to make sure the armor is valid for the tech base.        if (ARMOR_TYPE_WEIGHT[stateTechBase][stateArmorType] == 0) {            // For now, we allow selection of illegal armor types...            // And include this slightly cludgy way of detecting illegal armor/tech base pairings.            invalidReason = ARMOR_TYPE_STRINGS[stateArmorType] + " Armor not legal for chosen tech base.";            return false;        }        // Certain combinations of manipulators make it invalid.        if (((stateManipulatorTypeLeft == BattleArmor.MANIPULATOR_CARGO_LIFTER) && (stateManipulatorTypeRight != BattleArmor.MANIPULATOR_CARGO_LIFTER))                || ((stateManipulatorTypeRight == BattleArmor.MANIPULATOR_CARGO_LIFTER) && (stateManipulatorTypeLeft != BattleArmor.MANIPULATOR_CARGO_LIFTER))) {            invalidReason = "Cargo lifter manipulators must be mounted in pairs.";            return false;        }        // Certain combinations of manipulators make it invalid.        if (((stateManipulatorTypeLeft == BattleArmor.MANIPULATOR_BATTLE_MAGNET) && (stateManipulatorTypeRight != BattleArmor.MANIPULATOR_BATTLE_MAGNET))                || ((stateManipulatorTypeRight == BattleArmor.MANIPULATOR_BATTLE_MAGNET) && (stateManipulatorTypeLeft != BattleArmor.MANIPULATOR_BATTLE_MAGNET))) {            invalidReason = "Magnetic manipulators must be mounted in pairs.";            return false;        }        // Certain combinations of manipulators make it invalid.        if (((stateManipulatorTypeLeft == BattleArmor.MANIPULATOR_BASIC_MINE_CLEARANCE) && (stateManipulatorTypeRight != BattleArmor.MANIPULATOR_BASIC_MINE_CLEARANCE))                || ((stateManipulatorTypeRight == BattleArmor.MANIPULATOR_BASIC_MINE_CLEARANCE) && (stateManipulatorTypeLeft != BattleArmor.MANIPULATOR_BASIC_MINE_CLEARANCE))) {            invalidReason = "Mine clearance manipulators must be mounted in pairs.";            return false;        }        // Check to make sure none of the locations have gone over on slots.        if (stateChassisType == CHASSIS_TYPE_QUAD) {            // We're only going to be using torso stuff here.            // Quads only have one location!            if (torsoEquipment != null) {                int totalSlots = 0;                Iterator tmpE = torsoEquipment.iterator();                while (tmpE.hasNext()) {                    BattleArmorEquipment tmpBAE = (BattleArmorEquipment) (tmpE.next());                    totalSlots += tmpBAE.slots;                }                if (totalSlots > (QUAD_MAX_SLOTS[stateWeightClass] - ARMOR_TYPE_SLOTS[stateArmorType])) {                    invalidReason = "Unit is using more slots than are available.";                    return false;                }            }        } else {            // Here, we have to check all three locations individually.            int totalFreeSlots = (2 * ARM_MAX_SLOTS[stateWeightClass]) + TORSO_MAX_SLOTS[stateWeightClass];            if (leftArmEquipment != null) {                int totalSlots = 0;                Iterator tmpE = leftArmEquipment.iterator();                while (tmpE.hasNext()) {                    BattleArmorEquipment tmpBAE = (BattleArmorEquipment) (tmpE.next());                    totalSlots += tmpBAE.slots;                }                if (totalSlots > ARM_MAX_SLOTS[stateWeightClass]) {                    invalidReason = "Left Arm is using more slots than are available.";                    return false;                }                totalFreeSlots -= totalSlots;            }            if (rightArmEquipment != null) {                int totalSlots = 0;                Iterator tmpE = rightArmEquipment.iterator();                while (tmpE.hasNext()) {                    BattleArmorEquipment tmpBAE = (BattleArmorEquipment) (tmpE.next());                    totalSlots += tmpBAE.slots;                }                if (totalSlots > ARM_MAX_SLOTS[stateWeightClass]) {                    invalidReason = "Right Arm is using more slots than are available.";                    return false;                }                totalFreeSlots -= totalSlots;            }            if (torsoEquipment != null) {                int totalSlots = 0;                Iterator tmpE = torsoEquipment.iterator();                while (tmpE.hasNext()) {                    BattleArmorEquipment tmpBAE = (BattleArmorEquipment) (tmpE.next());                    totalSlots += tmpBAE.slots;                }                if (totalSlots > TORSO_MAX_SLOTS[stateWeightClass]) {                    invalidReason = "Torso is using more slots than are available.";                    return false;                }                totalFreeSlots -= totalSlots;            }            // Don't forget to include armor...            if (totalFreeSlots < ARMOR_TYPE_SLOTS[stateArmorType]) {                invalidReason = "Unit is using more total slots than are available.";                return false;            }        }        // Check to make sure no locations breach weapon limits.        // On quads, it can have a total of 4 weapons.        // On bipeds, it's one anti-'Mech + one anti-personnel or two        // anti-personnel per arm, plus two anti-'Mech and two anti-personnel        // in the torso.        if (stateChassisType == CHASSIS_TYPE_QUAD) {            // We're only going to be using torso stuff here.            // Quads only have one location!            if (torsoEquipment != null) {                int totalWeapons = 0;                Iterator tmpE = torsoEquipment.iterator();                while (tmpE.hasNext()) {                    BattleArmorEquipment tmpBAE = (BattleArmorEquipment) (tmpE.next());                    if ((tmpBAE.internalType == EQUIPMENT_TYPE_WEAPON)                            || (tmpBAE.internalType == EQUIPMENT_TYPE_WEAPON_AP))                        totalWeapons++;                }                if (totalWeapons > 4) {                    invalidReason = "Unit has more weapons than it is allowed (limit of 4).";                    return false;                }            }        } else {            if (torsoEquipment != null) {                int totalAPWeapons = 0;                int totalAMWeapons = 0;                Iterator tmpE = torsoEquipment.iterator();                while (tmpE.hasNext()) {                    BattleArmorEquipment tmpBAE = (BattleArmorEquipment) (tmpE.next());                    if (tmpBAE.internalType == EQUIPMENT_TYPE_WEAPON) {                        totalAMWeapons++;                    } else if (tmpBAE.internalType == EQUIPMENT_TYPE_WEAPON_AP) {                        totalAPWeapons++;                    }                }                if (totalAMWeapons > 2) {                    invalidReason = "Unit has more anti-'Mech weapons than it is allowed in its torso (limit of 2).";                    return false;                }                if (totalAPWeapons > 2) {                    invalidReason = "Unit has more anti-personnel weapons than it is allowed in its torso (limit of 2).";                    return false;                }            }            if (rightArmEquipment != null) {                int totalWeapons = 0;                int totalAMWeapons = 0;                Iterator tmpE = rightArmEquipment.iterator();                while (tmpE.hasNext()) {                    BattleArmorEquipment tmpBAE = (BattleArmorEquipment) (tmpE.next());                    if (tmpBAE.internalType == EQUIPMENT_TYPE_WEAPON) {                        totalWeapons++;                        totalAMWeapons++;                    } else if (tmpBAE.internalType == EQUIPMENT_TYPE_WEAPON_AP) {                        totalWeapons++;                    }                }                if (totalAMWeapons > 1) {                    invalidReason = "Unit has more anti-'Mech weapons than it is allowed in its right arm (limit of 1).";                    return false;                } else if (totalWeapons > 2) {                    invalidReason = "Unit has more weapons than it is allowed in its right arm (limit of 2).";                    return false;                }            }            if (leftArmEquipment != null) {                int totalWeapons = 0;                int totalAMWeapons = 0;                Iterator tmpE = leftArmEquipment.iterator();                while (tmpE.hasNext()) {                    BattleArmorEquipment tmpBAE = (BattleArmorEquipment) (tmpE.next());                    if (tmpBAE.internalType == EQUIPMENT_TYPE_WEAPON) {                        totalWeapons++;                        totalAMWeapons++;                    } else if (tmpBAE.internalType == EQUIPMENT_TYPE_WEAPON_AP) {                        totalWeapons++;                    }                }                if (totalAMWeapons > 1) {                    invalidReason = "Unit has more anti-'Mech weapons than it is allowed in its left arm (limit of 1).";                    return false;                } else if (totalWeapons > 2) {                    invalidReason = "Unit has more weapons than it is allowed in its left arm (limit of 2).";                    return false;                }            }        }        // If it hasn't failed on any specific point, then return true.        return true;    }    private int getChassisWeight() {        return getChassisWeight(stateWeightClass, stateTechBase);    }    private static int getChassisWeight(int weightClass, int techBase) {        if (techBase == TECH_BASE_IS) {            // Inner Sphere tech base.            switch (weightClass) {                case WEIGHT_CLASS_PAL:                    return 80;                case WEIGHT_CLASS_LIGHT:                    return 100;                case WEIGHT_CLASS_MEDIUM:                    return 175;                case WEIGHT_CLASS_HEAVY:                    return 300;                case WEIGHT_CLASS_ASSAULT:                    return 550;            }        } else {            // Clan tech base            switch (weightClass) {                case WEIGHT_CLASS_PAL:                    return 130;                case WEIGHT_CLASS_LIGHT:                    return 150;                case WEIGHT_CLASS_MEDIUM:                    return 250;                case WEIGHT_CLASS_HEAVY:                    return 400;                case WEIGHT_CLASS_ASSAULT:                    return 700;            }        }        // This is an error case...        return 0;    }    private int getArmorWeight() {        return getArmorWeight(stateTechBase, stateArmorType, stat

⌨️ 快捷键说明

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