Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add report roll tooltip #4873

Merged
merged 13 commits into from
Dec 12, 2023
6 changes: 3 additions & 3 deletions megamek/src/megamek/client/ui/swing/MovementDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -4208,15 +4208,15 @@ private void dumpBombs() {
dumpBombsDialog.getChoices();
// first make a control roll
PilotingRollData psr = ce().getBasePilotingRoll(overallMoveType);
int ctrlroll = Compute.d6(2);
Roll diceRoll = Compute.rollD6(2);
Report r = new Report(9500);
r.subject = ce().getId();
r.add(ce().getDisplayName());
r.add(psr);
r.add(ctrlroll);
r.add(diceRoll);
r.newlines = 0;
r.indent(1);
if (ctrlroll < 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: 9 additions & 8 deletions megamek/src/megamek/common/Building.java
Original file line number Diff line number Diff line change
Expand Up @@ -432,24 +432,25 @@ public boolean rollBasement(Coords coords, Board board, Vector<Report> vPhaseRep
Report r = new Report(2111, Report.PUBLIC);
r.add(getName());
r.add(coords.getBoardNum());
int basementRoll = Compute.d6(2);
r.add(basementRoll);
if (basementRoll == 2) {
Roll diceRoll = Compute.rollD6(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 (basementRoll == 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 (basementRoll == 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 (basementRoll == 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 (basementRoll == 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 (basementRoll == 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
41 changes: 23 additions & 18 deletions megamek/src/megamek/common/Compute.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,13 @@
import megamek.common.enums.BasementType;
import megamek.common.enums.IlluminationLevel;
import megamek.common.options.OptionsConstants;
import megamek.common.verifier.TestEntity;
import megamek.common.weapons.InfantryAttack;
import megamek.common.weapons.Weapon;
import megamek.common.weapons.artillery.ArtilleryCannonWeapon;
import megamek.common.weapons.bayweapons.BayWeapon;
import megamek.common.weapons.gaussrifles.HAGWeapon;
import megamek.common.weapons.infantry.InfantryWeapon;
import megamek.common.weapons.mgs.MGWeapon;
import megamek.common.weapons.mortars.MekMortarWeapon;
import megamek.server.Server;
import megamek.server.SmokeCloud;
import org.apache.logging.log4j.LogManager;
Expand Down Expand Up @@ -137,46 +135,53 @@ public class Compute {
{ 30, 10, 10, 12, 18, 18, 18, 18, 24, 24, 30, 30 },
{ 40, 12, 12, 18, 24, 24, 24, 24, 32, 32, 40, 40 } };

/**
* Wrapper to random#d6()
*/
public static int d6() {
return d6( 1);
}

/**
* Wrapper to random#d6(n)
*/
public static int d6(int dice) {
Roll roll = random.d6(dice);
if (Server.getServerInstance() != null) {
if (Server.getServerInstance().getGame().getOptions()
.booleanOption(OptionsConstants.BASE_RNG_LOG)) {
Server.getServerInstance().reportRoll(roll);
}
}
return roll.getIntValue();
return rollD6(dice).getIntValue();
}

/**
* Wrapper to random#d6(n)
*/
public static int d6(int dice, int keep) {
Roll roll = random.d6(dice, keep);
return rollD6(dice, keep).getIntValue();
}

/**
* Wrapper to random#d6(n)
*/
public static Roll rollD6(int dice) {
Roll roll = random.d6(dice);
if (Server.getServerInstance() != null) {
if (Server.getServerInstance().getGame().getOptions()
.booleanOption(OptionsConstants.BASE_RNG_LOG)) {
.booleanOption(OptionsConstants.BASE_RNG_LOG)) {
Server.getServerInstance().reportRoll(roll);
}
}
return roll.getIntValue();
return roll;
}

/**
* Wrapper to random#d6()
* Wrapper to random#d6(n)
*/
public static int d6() {
Roll roll = random.d6();
public static Roll rollD6(int dice, int keep) {
Roll roll = random.d6(dice, keep);
if (Server.getServerInstance() != null) {
if (Server.getServerInstance().getGame().getOptions()
.booleanOption(OptionsConstants.BASE_RNG_LOG)) {
.booleanOption(OptionsConstants.BASE_RNG_LOG)) {
Server.getServerInstance().reportRoll(roll);
}
}
return roll.getIntValue();
return roll;
}

/**
Expand Down
12 changes: 6 additions & 6 deletions megamek/src/megamek/common/Crew.java
Original file line number Diff line number Diff line change
Expand Up @@ -1157,20 +1157,20 @@ public void resetGameState() {
}
}

public int rollGunnerySkill() {
public Roll rollGunnerySkill() {
if (getOptions().booleanOption(OptionsConstants.PILOT_APTITUDE_GUNNERY)) {
return Compute.d6(3, 2);
return Compute.rollD6(3, 2);
}

return Compute.d6(2);
return Compute.rollD6(2);
}

public int rollPilotingSkill() {
public Roll rollPilotingSkill() {
if (getOptions().booleanOption(OptionsConstants.PILOT_APTITUDE_PILOTING)) {
return Compute.d6(3, 2);
return Compute.rollD6(3, 2);
}

return Compute.d6(2);
return Compute.rollD6(2);
}

public int getCurrentPilotIndex() {
Expand Down
33 changes: 18 additions & 15 deletions megamek/src/megamek/common/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ public abstract class Entity extends TurnOrdered implements Transporter, Targeta
private int sensorCheck;

// the roll for ghost targets
private int ghostTargetRoll;
private Roll ghostTargetRoll;
// the roll to override ghost targets
private int ghostTargetOverride;

Expand Down Expand Up @@ -6329,7 +6329,7 @@ public void newRound(int roundNumber) {
}

// ghost target roll
ghostTargetRoll = Compute.d6(2);
ghostTargetRoll = Compute.rollD6(2);
ghostTargetOverride = Compute.d6(2);

// update fatigue count
Expand Down Expand Up @@ -12132,12 +12132,12 @@ public int getDamageReductionFromModularArmor(HitData hit, int damage, Vector<Re
return damage;
}

public int getGhostTargetRoll() {
public Roll getGhostTargetRoll() {
return ghostTargetRoll;
}

public int getGhostTargetRollMoS() {
return ghostTargetRoll - (getCrew().getSensorOps() + 2);
return ghostTargetRoll.getIntValue() - (getCrew().getSensorOps() + 2);
}

public int getGhostTargetOverride() {
Expand Down Expand Up @@ -13419,13 +13419,16 @@ private boolean doMASCOrSuperchargerFailureCheckFor(Mounted masc, Vector<Report>
HashMap<Integer, List<CriticalSlot>> vCriticals) {
if ((masc != null) && masc.curMode().equals("Armed")) {
boolean bFailure = false;
int nRoll = Compute.d6(2);
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))) {
nRoll -= 1;
rollValue -= 1;
rollCalc = rollValue + " [" + diceRoll.getIntValue() + " - 1]";
}

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

if ((!isSupercharger && (nRoll < getMASCTarget()))
|| (isSupercharger && (nRoll < getSuperchargerTarget()))) {
if ((!isSupercharger && (rollValue < getMASCTarget()))
|| (isSupercharger && (rollValue < getSuperchargerTarget()))) {
// uh oh
bFailure = true;
r.choose(false);
Expand All @@ -13454,31 +13457,31 @@ private boolean doMASCOrSuperchargerFailureCheckFor(Mounted masc, Vector<Report>
if (isSupercharger) {
// do the damage - engine crits
int hits = 0;
int roll = Compute.d6(2);
Roll diceRoll2 = Compute.rollD6(2);
r = new Report(6310);
r.subject = getId();
r.add(roll);
r.add(diceRoll2);
r.newlines = 0;
vDesc.addElement(r);
if (roll <= 7) {
if (diceRoll2.getIntValue() <= 7) {
// no effect
r = new Report(6005);
r.subject = getId();
r.newlines = 0;
vDesc.addElement(r);
} else if ((roll >= 8) && (roll <= 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 ((roll >= 10) && (roll <= 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 (roll == 12) {
} else if (diceRoll2.getIntValue() == 12) {
hits = 3;
r = new Report(6325);
r.subject = getId();
Expand Down
16 changes: 8 additions & 8 deletions megamek/src/megamek/common/Mech.java
Original file line number Diff line number Diff line change
Expand Up @@ -5462,9 +5462,9 @@ public Vector<Report> doCheckEngineStallRoll(Vector<Report> vPhaseReport) {
vPhaseReport.add(Report.subjectReport(2285, getId()).add(psr.getValueAsString()).add(psr.getDesc()));
vPhaseReport.add(Report.subjectReport(2290, getId()).indent().noNL().add(1).add(psr.getPlainDesc()));

int diceRoll = getCrew().rollPilotingSkill();
Roll diceRoll = getCrew().rollPilotingSkill();
Report r = Report.subjectReport(2300, getId()).add(psr).add(diceRoll);
if (diceRoll < psr.getValue()) {
if (diceRoll.getIntValue() < psr.getValue()) {
setStalled(true);
vPhaseReport.add(r.noNL().choose(false));
vPhaseReport.add(Report.subjectReport(2303, getId()));
Expand Down Expand Up @@ -5492,9 +5492,9 @@ public void checkUnstall(Vector<Report> vPhaseReport) {
vPhaseReport.add(Report.subjectReport(2285, getId()).add(psr.getValueAsString()).add(psr.getDesc()));
vPhaseReport.add(Report.subjectReport(2290, getId()).indent().noNL().add(1).add(psr.getPlainDesc()));

int diceRoll = getCrew().rollPilotingSkill();
Roll diceRoll = getCrew().rollPilotingSkill();
Report r = Report.subjectReport(2300, getId()).add(psr).add(diceRoll);
if (diceRoll < psr.getValue()) {
if (diceRoll.getIntValue() < psr.getValue()) {
vPhaseReport.add(r.choose(false));
} else {
setStalled(false);
Expand Down Expand Up @@ -6248,13 +6248,13 @@ public boolean doRISCEmergencyCoolantCheckFor(Vector<Report> vDesc,
}
if (coolantSystem != null) {
boolean bFailure = false;
int nRoll = Compute.d6(2);
Roll diceRoll = Compute.rollD6(2);
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).add(nRoll);
Report r = Report.subjectReport(2370, getId()).indent().add(requiredRoll).add(diceRoll);

if (nRoll < requiredRoll) {
if (diceRoll.getIntValue() < requiredRoll) {
// uh oh
bFailure = true;
r.choose(false);
Expand Down Expand Up @@ -6294,7 +6294,7 @@ public boolean doRISCEmergencyCoolantCheckFor(Vector<Report> vDesc,
} else {
r.choose(true);
vDesc.addElement(r);
nCoolantSystemMOS = nRoll - EMERGENCY_COOLANT_SYSTEM_FAILURE[nCoolantSystemLevel];
nCoolantSystemMOS = diceRoll.getIntValue() - EMERGENCY_COOLANT_SYSTEM_FAILURE[nCoolantSystemLevel];
}
return bFailure;
}
Expand Down
4 changes: 2 additions & 2 deletions megamek/src/megamek/common/PhysicalResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +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 Roll roll;
public Roll rollRight;
public int damage = 0;
public int damageRight = 0;
public boolean pushBackResolved = false;
Expand Down
8 changes: 8 additions & 0 deletions megamek/src/megamek/common/Report.java
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,14 @@ public Report add(TargetRoll targetRoll) {
return this;
}

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

public Report addDataWithTooltip(Integer data, String tooltip) {
return addDataWithTooltip(String.valueOf(data), tooltip);
}

/**
* Adds a field to the report with additional data available as a tooltip
*
Expand Down
4 changes: 3 additions & 1 deletion megamek/src/megamek/common/Roll.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
*/
package megamek.common;

import java.io.Serializable;

/**
* Encapsulate all information known about a requested roll. This information
* can be logged for full statistical analysis and auditing, so hopefully people
Expand All @@ -21,7 +23,7 @@
* @author Suvarov454
* @since July 20, 2004, 4:21 PM
*/
public abstract class Roll {
public abstract class Roll implements Serializable {

/**
* Make sure that all rolls are uniquely identified.
Expand Down
1 change: 1 addition & 0 deletions megamek/src/megamek/common/util/SerializationHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public static XStream getSaveGameXStream() {
xStream.allowTypeHierarchy(megamek.common.Crew.class);
xStream.allowTypeHierarchy(megamek.common.GameTurn.class);
xStream.allowTypeHierarchy(megamek.common.ITechnology.class);
xStream.allowTypeHierarchy(megamek.common.Roll.class);
xStream.allowTypeHierarchy(megamek.common.Transporter.class);
xStream.allowTypeHierarchy(megamek.common.actions.EntityAction.class);
xStream.allowTypeHierarchy(megamek.common.icons.AbstractIcon.class);
Expand Down
Loading