Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
kuronekochomusuke committed Nov 18, 2023
1 parent 85cc221 commit 66b21f3
Show file tree
Hide file tree
Showing 60 changed files with 634 additions and 832 deletions.
6 changes: 2 additions & 4 deletions megamek/src/megamek/client/ui/swing/MovementDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -4209,16 +4209,14 @@ private void dumpBombs() {
// first make a control roll
PilotingRollData psr = ce().getBasePilotingRoll(overallMoveType);
Roll diceRoll = Compute.rollD6(2);
int rollValue = diceRoll.getIntValue();
String rollReport = diceRoll.getReport();
Report r = new Report(9500);
r.subject = ce().getId();
r.add(ce().getDisplayName());
r.add(psr);
r.addDataWithTooltip(rollValue, rollReport);
r.add(diceRoll);
r.newlines = 0;
r.indent(1);
if (rollValue < psr.getValue()) {
if (diceRoll.getIntValue() < psr.getValue()) {
r.choose(false);
String title = Messages.getString("MovementDisplay.DumpingBombs.title");
String body = Messages.getString("MovementDisplay.DumpFailure.message");
Expand Down
17 changes: 8 additions & 9 deletions megamek/src/megamek/common/Building.java
Original file line number Diff line number Diff line change
Expand Up @@ -433,25 +433,24 @@ public boolean rollBasement(Coords coords, Board board, Vector<Report> vPhaseRep
r.add(getName());
r.add(coords.getBoardNum());
Roll diceRoll = Compute.rollD6(2);
int rollValue = diceRoll.getIntValue();
String rollReport = diceRoll.getReport();
r.addDataWithTooltip(rollValue, rollReport);
if (rollValue == 2) {
r.add(diceRoll);

if (diceRoll.getIntValue() == 2) {
basement.put(coords, BasementType.TWO_DEEP_FEET);
hex.addTerrain(new Terrain(Terrains.BLDG_BASEMENT_TYPE, basement.get(coords).ordinal()));
} else if (rollValue == 3) {
} else if (diceRoll.getIntValue() == 3) {
basement.put(coords, BasementType.ONE_DEEP_FEET);
hex.addTerrain(new Terrain(Terrains.BLDG_BASEMENT_TYPE, basement.get(coords).ordinal()));
} else if (rollValue == 4) {
} else if (diceRoll.getIntValue() == 4) {
basement.put(coords, BasementType.ONE_DEEP_NORMAL);
hex.addTerrain(new Terrain(Terrains.BLDG_BASEMENT_TYPE, basement.get(coords).ordinal()));
} else if (rollValue == 10) {
} else if (diceRoll.getIntValue() == 10) {
basement.put(coords, BasementType.ONE_DEEP_NORMAL);
hex.addTerrain(new Terrain(Terrains.BLDG_BASEMENT_TYPE, basement.get(coords).ordinal()));
} else if (rollValue == 11) {
} else if (diceRoll.getIntValue() == 11) {
basement.put(coords, BasementType.ONE_DEEP_HEAD);
hex.addTerrain(new Terrain(Terrains.BLDG_BASEMENT_TYPE, basement.get(coords).ordinal()));
} else if (rollValue == 12) {
} else if (diceRoll.getIntValue() == 12) {
basement.put(coords, BasementType.TWO_DEEP_HEAD);
hex.addTerrain(new Terrain(Terrains.BLDG_BASEMENT_TYPE, basement.get(coords).ordinal()));
} else {
Expand Down
21 changes: 10 additions & 11 deletions megamek/src/megamek/common/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -13419,15 +13419,16 @@ private boolean doMASCOrSuperchargerFailureCheckFor(Mounted masc, Vector<Report>
HashMap<Integer, List<CriticalSlot>> vCriticals) {
if ((masc != null) && masc.curMode().equals("Armed")) {
boolean bFailure = false;
Roll discRoll = Compute.rollD6(2);
int rollValue = discRoll.getIntValue();
String rollReport = discRoll.getReport();
Roll diceRoll = Compute.rollD6(2);
int rollValue = diceRoll.getIntValue();
String rollCalc = String.valueOf(rollValue);
boolean isSupercharger = masc.getType().hasSubType(MiscType.S_SUPERCHARGER);
//WHY is this -1 here?
if (isSupercharger
&& (((this instanceof Mech) && ((Mech) this).isIndustrial())
|| (this instanceof SupportTank) || (this instanceof SupportVTOL))) {
rollValue -= 1;
rollCalc = rollValue + " [" + diceRoll.getIntValue() + " - 1]";
}

if (isSupercharger) {
Expand All @@ -13444,7 +13445,7 @@ private boolean doMASCOrSuperchargerFailureCheckFor(Mounted masc, Vector<Report>
r.subject = getId();
r.indent();
r.add(isSupercharger ? getSuperchargerTarget() : getMASCTarget());
r.addDataWithTooltip(rollValue, rollReport);
r.addDataWithTooltip(rollCalc, diceRoll.getReport());

if ((!isSupercharger && (rollValue < getMASCTarget()))
|| (isSupercharger && (rollValue < getSuperchargerTarget()))) {
Expand All @@ -13457,32 +13458,30 @@ private boolean doMASCOrSuperchargerFailureCheckFor(Mounted masc, Vector<Report>
// do the damage - engine crits
int hits = 0;
Roll diceRoll2 = Compute.rollD6(2);
int rollValue2 = diceRoll2.getIntValue();
String rollReport2 = diceRoll2.getReport();
r = new Report(6310);
r.subject = getId();
r.addDataWithTooltip(rollValue2, rollReport2);
r.add(diceRoll2);
r.newlines = 0;
vDesc.addElement(r);
if (rollValue2 <= 7) {
if (diceRoll2.getIntValue() <= 7) {
// no effect
r = new Report(6005);
r.subject = getId();
r.newlines = 0;
vDesc.addElement(r);
} else if ((rollValue2 == 8) || (rollValue2 == 9)) {
} else if ((diceRoll2.getIntValue() == 8) || (diceRoll2.getIntValue() == 9)) {
hits = 1;
r = new Report(6315);
r.subject = getId();
r.newlines = 0;
vDesc.addElement(r);
} else if ((rollValue2 ==10) || (rollValue2 == 11)) {
} else if ((diceRoll2.getIntValue() ==10) || (diceRoll2.getIntValue() == 11)) {
hits = 2;
r = new Report(6320);
r.subject = getId();
r.newlines = 0;
vDesc.addElement(r);
} else if (rollValue2 == 12) {
} else if (diceRoll2.getIntValue() == 12) {
hits = 3;
r = new Report(6325);
r.subject = getId();
Expand Down
20 changes: 7 additions & 13 deletions megamek/src/megamek/common/Mech.java
Original file line number Diff line number Diff line change
Expand Up @@ -5463,10 +5463,8 @@ public Vector<Report> doCheckEngineStallRoll(Vector<Report> vPhaseReport) {
vPhaseReport.add(Report.subjectReport(2290, getId()).indent().noNL().add(1).add(psr.getPlainDesc()));

Roll diceRoll = getCrew().rollPilotingSkill();
int rollValue = diceRoll.getIntValue();
String rollReport = diceRoll.getReport();
Report r = Report.subjectReport(2300, getId()).add(psr).addDataWithTooltip(rollValue, rollReport);
if (rollValue < psr.getValue()) {
Report r = Report.subjectReport(2300, getId()).add(psr).add(diceRoll);
if (diceRoll.getIntValue() < psr.getValue()) {
setStalled(true);
vPhaseReport.add(r.noNL().choose(false));
vPhaseReport.add(Report.subjectReport(2303, getId()));
Expand Down Expand Up @@ -5495,10 +5493,8 @@ public void checkUnstall(Vector<Report> vPhaseReport) {
vPhaseReport.add(Report.subjectReport(2290, getId()).indent().noNL().add(1).add(psr.getPlainDesc()));

Roll diceRoll = getCrew().rollPilotingSkill();
int rollValue = diceRoll.getIntValue();
String rollReport = diceRoll.getReport();
Report r = Report.subjectReport(2300, getId()).add(psr).addDataWithTooltip(rollValue, rollReport);
if (rollValue < psr.getValue()) {
Report r = Report.subjectReport(2300, getId()).add(psr).add(diceRoll);
if (diceRoll.getIntValue() < psr.getValue()) {
vPhaseReport.add(r.choose(false));
} else {
setStalled(false);
Expand Down Expand Up @@ -6253,14 +6249,12 @@ public boolean doRISCEmergencyCoolantCheckFor(Vector<Report> vDesc,
if (coolantSystem != null) {
boolean bFailure = false;
Roll diceRoll = Compute.rollD6(2);
int rollValue = diceRoll.getIntValue();
String rollReport = diceRoll.getReport();
bUsedCoolantSystem = true;
vDesc.addElement(Report.subjectReport(2365, getId()).addDesc(this).add(coolantSystem.getName()));
int requiredRoll = EMERGENCY_COOLANT_SYSTEM_FAILURE[nCoolantSystemLevel];
Report r = Report.subjectReport(2370, getId()).indent().add(requiredRoll).addDataWithTooltip(rollValue, rollReport);
Report r = Report.subjectReport(2370, getId()).indent().add(requiredRoll).add(diceRoll);

if (rollValue < requiredRoll) {
if (diceRoll.getIntValue() < requiredRoll) {
// uh oh
bFailure = true;
r.choose(false);
Expand Down Expand Up @@ -6300,7 +6294,7 @@ public boolean doRISCEmergencyCoolantCheckFor(Vector<Report> vDesc,
} else {
r.choose(true);
vDesc.addElement(r);
nCoolantSystemMOS = rollValue - EMERGENCY_COOLANT_SYSTEM_FAILURE[nCoolantSystemLevel];
nCoolantSystemMOS = diceRoll.getIntValue() - EMERGENCY_COOLANT_SYSTEM_FAILURE[nCoolantSystemLevel];
}
return bFailure;
}
Expand Down
6 changes: 2 additions & 4 deletions megamek/src/megamek/common/PhysicalResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ public class PhysicalResult implements Serializable {
public AbstractAttackAction aaa = null;
public ToHitData toHit = null;
public ToHitData toHitRight = null;
public int roll = -1;
public int rollRight = -1;
public String rollReport = "";
public String rollRightReport = "";
public Roll roll;
public Roll rollRight;
public int damage = 0;
public int damageRight = 0;
public boolean pushBackResolved = false;
Expand Down
4 changes: 4 additions & 0 deletions megamek/src/megamek/common/Report.java
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,10 @@ public Report add(TargetRoll targetRoll) {
return this;
}

public Report add(Roll diceRoll) {
return addDataWithTooltip(String.valueOf(diceRoll.getReport()), diceRoll.getReport());
}

public Report addDataWithTooltip(Integer data, String tooltip) {
return addDataWithTooltip(String.valueOf(data), tooltip);
}
Expand Down
8 changes: 4 additions & 4 deletions megamek/src/megamek/common/weapons/ACBayHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,19 @@ protected boolean doChecks(Vector<Report> vPhaseReport) {
boolean jams = false;
switch (ammoUsed) {
case 6:
if (roll <= 4) {
if (roll.getIntValue() <= 4) {
jams = true;
}
break;
case 5:
case 4:
if (roll <= 3) {
if (roll.getIntValue() <= 3) {
jams = true;
}
break;
case 3:
case 2:
if (roll <= 2) {
if (roll.getIntValue() <= 2) {
jams = true;
}
break;
Expand All @@ -84,7 +84,7 @@ protected boolean doChecks(Vector<Report> vPhaseReport) {
bayW.setJammed(true);
}
} else if (bayWType.getAmmoType() == AmmoType.T_AC_ULTRA) {
if (roll == 2 && ammoUsed == 2) {
if (roll.getIntValue() == 2 && ammoUsed == 2) {
Report r = new Report();
r.subject = subjectId;
r.messageId = 3160;
Expand Down
8 changes: 3 additions & 5 deletions megamek/src/megamek/common/weapons/ACCaselessHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,14 @@ protected boolean doChecks(Vector<Report> vPhaseReport) {
return true;
}

if ((roll <= 2) && !(ae instanceof Infantry)) {
if ((roll.getIntValue() <= 2) && !(ae instanceof Infantry)) {
Roll diceRoll = Compute.rollD6(2);
int rollValue = diceRoll.getIntValue();
String rollReport = diceRoll.getReport();

Report r = new Report(3164);
r.subject = subjectId;
r.addDataWithTooltip(rollValue, rollReport);
r.add(diceRoll);

if (rollValue >= 8) {
if (diceRoll.getIntValue() >= 8) {
// Round explodes destroying weapon
weapon.setDestroyed(true);
r.choose(false);
Expand Down
8 changes: 4 additions & 4 deletions megamek/src/megamek/common/weapons/AR10Handler.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public boolean handle(GamePhase phase, Vector<Report> vPhaseReport) {
setGlancingBlowFlags(entityTarget);

// Set Margin of Success/Failure and check for Direct Blows
toHit.setMoS(roll - Math.max(2, toHit.getValue()));
toHit.setMoS(roll.getIntValue() - Math.max(2, toHit.getValue()));
bDirect = game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_DIRECT_BLOW)
&& ((toHit.getMoS() / 3) >= 1) && (entityTarget != null);

Expand All @@ -115,7 +115,7 @@ public boolean handle(GamePhase phase, Vector<Report> vPhaseReport) {
//Only do this if the missile wasn't destroyed
if (CapMissileAMSMod > 0 && CapMissileArmor > 0) {
toHit.addModifier(CapMissileAMSMod, "Damage from Point Defenses");
if (roll < toHit.getValue()) {
if (roll.getIntValue() < toHit.getValue()) {
CapMissileMissed = true;
}
}
Expand Down Expand Up @@ -166,11 +166,11 @@ public boolean handle(GamePhase phase, Vector<Report> vPhaseReport) {
r = new Report(3155);
r.newlines = 0;
r.subject = subjectId;
r.addDataWithTooltip(roll, rollReport);
r.add(roll);
vPhaseReport.addElement(r);

// do we hit?
bMissed = roll < toHit.getValue();
bMissed = roll.getIntValue() < toHit.getValue();

//Report Glancing/Direct Blow here because of Capital Missile weirdness
if (!(amsBayEngagedCap || pdBayEngagedCap)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected void handleEntityDamage(Entity entityTarget,
waa.getAimingMode(), toHit.getCover());
hit.setGeneralDamageType(generalDamageType);
hit.setCapital(wtype.isCapital());
hit.setBoxCars(roll == 12);
hit.setBoxCars(roll.getIntValue() == 12);
hit.setCapMisCritMod(getCapMisMod());
hit.setFirstHit(firstHit);
hit.setAttackerId(getAttackerId());
Expand Down
10 changes: 4 additions & 6 deletions megamek/src/megamek/common/weapons/AmmoWeaponHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,25 +97,23 @@ protected boolean doAmmoFeedProblemCheck(Vector<Report> vPhaseReport) {
if (!weapon.hasQuirk(OptionsConstants.QUIRK_WEAP_NEG_AMMO_FEED_PROBLEMS)) {
return false;
// attack roll was a 2, may explode
} else if (roll <= 2) {
} else if (roll.getIntValue() <= 2) {
Roll diceRoll = Compute.rollD6(2);
int rollValue = diceRoll.getIntValue();
String rollReport = diceRoll.getReport();

Report r = new Report(3173);
r.subject = subjectId;
r.newlines = 0;
r.addDataWithTooltip(rollValue, rollReport);
r.add(diceRoll);
vPhaseReport.addElement(r);

if (rollValue == 12) {
if (diceRoll.getIntValue() == 12) {
// round explodes in weapon
r = new Report(3163);
r.subject = subjectId;
vPhaseReport.addElement(r);

explodeRoundInBarrel(vPhaseReport);
} else if (rollValue >= 10) {
} else if (diceRoll.getIntValue() >= 10) {
// plain old weapon jam
r = new Report(3161);
r.subject = subjectId;
Expand Down
9 changes: 4 additions & 5 deletions megamek/src/megamek/common/weapons/AreaEffectHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -259,17 +259,16 @@ public static void checkInfantryDestruction(Entity entity, int distFromCenter, E
}

Roll diceRoll = Compute.rollD6(2);
int rollValue = diceRoll.getIntValue();
String rollReport = diceRoll.getReport();
int result = rollValue + distFromCenter;
boolean destroyed = result <= rollTarget;
int rollValue = diceRoll.getIntValue() + distFromCenter;
String rollCalc = rollValue + " [" + diceRoll.getIntValue() + " + " + distFromCenter + "]";
boolean destroyed = rollValue <= rollTarget;

Report r = new Report(9987);
r.indent(1);
r.subject = attacker.getId();
r.newlines = 1;
r.add(rollTarget);
r.addDataWithTooltip(rollValue, rollReport);
r.addDataWithTooltip(rollCalc, diceRoll.getReport());
r.add(distFromCenter);
r.choose(destroyed);
vPhaseReport.addElement(r);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public boolean accept(Entity entity) {
if (!isFlak) {
// If the shot hit the target hex, then all subsequent
// fire will hit the hex automatically.
if (roll >= toHit.getValue()) {
if (roll.getIntValue() >= toHit.getValue()) {
ae.aTracker.setModifier(TargetRoll.AUTOMATIC_SUCCESS, targetPos);
} else if (null != bestSpotter) {
// If the shot missed, but was adjusted by a spotter, future shots are more likely
Expand Down Expand Up @@ -276,13 +276,13 @@ public boolean accept(Entity entity) {
r = new Report(3155);
r.newlines = 0;
r.subject = subjectId;
r.addDataWithTooltip(roll, rollReport);
r.add(roll);
vPhaseReport.addElement(r);

// do we hit?
bMissed = roll < toHit.getValue();
bMissed = roll.getIntValue() < toHit.getValue();
// Set Margin of Success/Failure.
toHit.setMoS(roll - Math.max(2, toHit.getValue()));
toHit.setMoS(roll.getIntValue() - Math.max(2, toHit.getValue()));

// Do this stuff first, because some weapon's miss report reference the
// amount of shots fired and stuff.
Expand Down
Loading

0 comments on commit 66b21f3

Please sign in to comment.