Skip to content

Commit

Permalink
Show random encounter probabilities in worldmap viewer
Browse files Browse the repository at this point in the history
Shown alongside travel times when travel distances are enabled.
  • Loading branch information
Argent77 committed Sep 11, 2024
1 parent 6ba05f9 commit 6366504
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/org/infinity/resource/wmp/ViewerMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,10 @@ private void showMapDistances(int... areaIndices) {
Point ptTarget = getMapIconCoordinate(dstAreaIndex, dstDir, false);

// checking for random encounters during travels
final int randomEncounterProb =
((IsNumeric) destLink.getAttribute(AreaLink.WMP_LINK_RANDOM_ENCOUNTER_PROBABILITY)).getValue();
boolean hasRandomEncounters = false;
if (((IsNumeric) destLink.getAttribute(AreaLink.WMP_LINK_RANDOM_ENCOUNTER_PROBABILITY)).getValue() > 0) {
if (randomEncounterProb > 0) {
for (int rnd = 1; rnd < 6; rnd++) {
String rndArea = ((IsReference) destLink
.getAttribute(String.format(AreaLink.WMP_LINK_RANDOM_ENCOUNTER_AREA_FMT, rnd))).getResourceName();
Expand All @@ -449,8 +451,13 @@ private void showMapDistances(int... areaIndices) {
g.drawLine(ptOrigin.x, ptOrigin.y, ptTarget.x, ptTarget.y);

// printing travel time (in hours)
String duration = String.format("%d h",
((IsNumeric) destLink.getAttribute(AreaLink.WMP_LINK_DISTANCE_SCALE)).getValue() * 4);
final String duration;
final int distScale = ((IsNumeric) destLink.getAttribute(AreaLink.WMP_LINK_DISTANCE_SCALE)).getValue() * 4;
if (hasRandomEncounters) {
duration = String.format("%d h (%d%%)", distScale, randomEncounterProb);
} else {
duration = String.format("%d h", distScale);
}
LineMetrics lm = g.getFont().getLineMetrics(duration, g.getFontRenderContext());
Rectangle2D rectText = g.getFont().getStringBounds(duration, g.getFontRenderContext());
int textX = ptOrigin.x + ((ptTarget.x - ptOrigin.x) - rectText.getBounds().width) / 3;
Expand Down

0 comments on commit 6366504

Please sign in to comment.