Skip to content

Commit

Permalink
Merge pull request #5937 from SJuliez/cowl
Browse files Browse the repository at this point in the history
Cowl quirk updates
  • Loading branch information
SJuliez authored Sep 4, 2024
2 parents 6f4b309 + 7b5389e commit 2216a78
Show file tree
Hide file tree
Showing 7 changed files with 232 additions and 255 deletions.
39 changes: 39 additions & 0 deletions megamek/data/scenarios/Test Setups/MekCowl.mms
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
MMSVersion: 2
name: Test Setup for Mek Cowls
planet: None
description: A few units on a small map to test mek cowl (quirk) functions
map: Beginner Box/16x17 Grassland 1.board

factions:
- name: Test Player

units:
- fullname: Cyclops CP-10-Z
at: [ 9, 12 ]
facing: 0
crew:
gunnery: 0

- fullname: Cyclops CP-10-Z
at: [ 9, 8 ]
facing: 3
crew:
gunnery: 0

- fullname: Cyclops CP-10-Z
at: [ 10, 8 ]
facing: 3
crew:
gunnery: 0

- fullname: Cyclops CP-10-Z
at: [ 9, 15 ]
facing: 0
crew:
gunnery: 0

- fullname: Cyclops CP-10-Z
at: [ 6, 9 ]
facing: 3
crew:
gunnery: 0
28 changes: 28 additions & 0 deletions megamek/src/megamek/common/Coords.java
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,34 @@ public static Coords nextHex(Coords current, Coords destination) {
new IdealHex(destination), directions);
}

/**
* Returns true when the given other Coords are exactly on the hex row (line) from this Coords in the given
* direction. For example, if the direction is 0 (north), returns true only for Coords that are above
* this Coords at the same x. Returns false when the other Coords are null, the other Coords are equal
* to this or the direction is outside of 0 to 5.
*
* @param direction The direction, 0 = N, 2 = SE ...
* @param other The Coords to test
* @return True when the other Coords are on the hex row from this Coords in the given direction
*/
public boolean isOnHexRow(int direction, @Nullable Coords other) {
if ((other == null) || this.equals(other)) {
return false;
}
HexLine line = new HexLine(this, direction);
if (line.judgePoint(other) != 0) {
return false;
} else {
return switch (direction) {
case 0 -> other.y < y;
case 1, 2 -> other.x > x;
case 3 -> other.y > y;
case 4, 5 -> other.x < x;
default -> false;
};
}
}

/**
* Returns a list of all adjacent coordinates (distance = 1),
* regardless of whether they're on the board or not.
Expand Down
32 changes: 15 additions & 17 deletions megamek/src/megamek/common/Mech.java
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,9 @@ public abstract class Mech extends Entity {

protected int cockpitType = COCKPIT_STANDARD;

/**
* Head armor provided by the Cowl quirk. Ignored when the unit doesn't have Cowl or quirks aren't used.
*/
private int cowlArmor = 3;

private int hasLaserHeatSinks = HAS_UNKNOWN;
Expand Down Expand Up @@ -389,34 +392,29 @@ public CrewType defaultCrewType() {
*/
public abstract boolean cannotStandUpFromHullDown();

public int getCowlArmor() {
if (hasCowl()) {
return cowlArmor;
}
return 0;
}

/**
* @return True if this Mek has the Cowl quirk and quirks are used in the present game.
*/
public boolean hasCowl() {
return hasQuirk(OptionsConstants.QUIRK_POS_COWL);
}

/**
* Damage the cowl. Returns amount of excess damage
* Damages the remaining cowl armor, if any, by the given amount. Returns the amount of excess damage
* that is left after deducting cowl armor. This method tests if the unit has Cowl and quirks are
* being used.
*
* @param amount
* @return
* @param amount The incoming damage
* @return The damage left after deducting the cowl's remaining armor, if any
*/
public int damageCowl(int amount) {
if (hasCowl()) {
if (amount < cowlArmor) {
cowlArmor -= amount;
return 0;
}
amount -= cowlArmor;
cowlArmor = 0;
int excessDamage = Math.max(amount - cowlArmor, 0);
cowlArmor = Math.max(cowlArmor - amount, 0);
return excessDamage;
} else {
return amount;
}
return amount; // No cowl - return full damage
}

/**
Expand Down
22 changes: 0 additions & 22 deletions megamek/src/megamek/common/MiscType.java
Original file line number Diff line number Diff line change
Expand Up @@ -1537,7 +1537,6 @@ public static void initializeTypes() {
EquipmentType.addType(MiscType.createCombine());
EquipmentType.addType(MiscType.createBackhoe());
EquipmentType.addType(MiscType.createPileDriver());
EquipmentType.addType(MiscType.createArmoredCowl());
EquipmentType.addType(MiscType.createNullSignatureSystem());
EquipmentType.addType(MiscType.createVoidSignatureSystem());
EquipmentType.addType(MiscType.createChameleonLightPolarizationShield());
Expand Down Expand Up @@ -8641,27 +8640,6 @@ public static MiscType createPintleTurret() {
return misc;
}

// Battle Armor Tech

public static MiscType createArmoredCowl() {
MiscType misc = new MiscType();

misc.name = "Armored Cowl";
misc.setInternalName(misc.name);
misc.tonnage = 1;
misc.criticals = 1;
misc.cost = 10000;
misc.flags = misc.flags.or(F_COWL).or(F_MECH_EQUIPMENT);
misc.bv = 10;
// Making this up based on the Strat Ops Quirk

misc.techAdvancement.setTechBase(TECH_BASE_IS);
misc.techAdvancement.setISAdvancement(DATE_NONE, DATE_NONE, 2439);
misc.techAdvancement.setTechRating(RATING_C);
misc.techAdvancement.setAvailability(new int[] { RATING_E, RATING_E, RATING_E, RATING_X });
return misc;
}

// Start BattleArmor equipment

public static MiscType createISBALightActiveProbe() {
Expand Down
24 changes: 9 additions & 15 deletions megamek/src/megamek/server/totalwarfare/TWGameManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -18242,21 +18242,15 @@ public Vector<Report> damageEntity(Entity te, HitData hit, int damage,
}

// Armored Cowl may absorb some damage from hit
if (te instanceof Mech) {
Mech me = (Mech) te;
if (me.hasCowl() && (hit.getLocation() == Mech.LOC_HEAD)
&& !throughFront) {
int damageNew = me.damageCowl(damage);
int damageDiff = damage - damageNew;
me.damageThisPhase += damageDiff;
damage = damageNew;

r = new Report(3520);
r.subject = te_n;
r.indent(3);
r.add(damageDiff);
vDesc.addElement(r);
}
if ((te instanceof Mech targetMek) && targetMek.hasCowl() && (hit.getLocation() == Mech.LOC_HEAD)
&& ((targetMek.getPosition() == null) || (ae == null)
|| !targetMek.getPosition().isOnHexRow(targetMek.getSecondaryFacing(), ae.getPosition()))) {
int excessDamage = targetMek.damageCowl(damage);
int blockedByCowl = damage - excessDamage;
r = new Report(3520).subject(te_n).indent(3).add(blockedByCowl);
vDesc.addElement(r);
targetMek.damageThisPhase += blockedByCowl;
damage = excessDamage;
}

// So might modular armor, if the location mounts any.
Expand Down
Loading

0 comments on commit 2216a78

Please sign in to comment.