Skip to content

Commit

Permalink
Tore out most previous Low Alt accommodations and created new static …
Browse files Browse the repository at this point in the history
…functions
  • Loading branch information
Sleet01 committed Aug 1, 2024
1 parent d718bf2 commit 7586dde
Show file tree
Hide file tree
Showing 3 changed files with 327 additions and 106 deletions.
21 changes: 10 additions & 11 deletions megamek/src/megamek/client/ui/swing/boardview/BoardView.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@
import megamek.client.event.BoardViewListener;
import megamek.client.ui.IDisplayable;
import megamek.client.ui.Messages;
import megamek.client.ui.swing.*;
import megamek.client.ui.swing.ChatterBox2;
import megamek.client.ui.swing.ClientGUI;
import megamek.client.ui.swing.EntityChoiceDialog;
import megamek.client.ui.swing.GUIPreferences;
import megamek.client.ui.swing.tileset.TilesetManager;
import megamek.client.ui.swing.util.*;
import megamek.client.ui.swing.widget.MegamekBorder;
Expand Down Expand Up @@ -69,7 +72,8 @@
import java.util.*;
import java.util.stream.Collectors;

import static megamek.client.ui.swing.tileset.HexTileset.*;
import static megamek.client.ui.swing.tileset.HexTileset.HEX_H;
import static megamek.client.ui.swing.tileset.HexTileset.HEX_W;

/**
* Displays the board; lets the user scroll around and select points on it.
Expand Down Expand Up @@ -3578,15 +3582,10 @@ private void secondLOSHex(Coords c2, Coords c1) {
if ((ae == null) || (te == null)) {
boolean mechInFirst = GUIP.getMechInFirst();
boolean mechInSecond = GUIP.getMechInSecond();
LosEffects.AttackInfo ai = new LosEffects.AttackInfo();
ai.attackPos = c1;
ai.targetPos = c2;
ai.attackHeight = mechInFirst ? 1 : 0;
ai.targetHeight = mechInSecond ? 1 : 0;
ai.targetIsMech = mechInSecond;
ai.attackerIsMech = mechInFirst;
ai.attackAbsHeight = game.getBoard().getHex(c1).floor() + ai.attackHeight;
ai.targetAbsHeight = game.getBoard().getHex(c2).floor() + ai.targetHeight;

LosEffects.AttackInfo ai = LosEffects.prepLosAttackInfo(
game, ae, te, c1, c2, mechInFirst, mechInSecond);

le = LosEffects.calculateLos(game, ai);
message.append(Messages.getString("BoardView1.Attacker",
mechInFirst ? Messages.getString("BoardView1.Mech")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,44 +329,50 @@ private void updateRingsProperties() {
LogManager.getLogger().error("Cannot process line of sight effects with a null destination hex.");
return null;
}
LosEffects.AttackInfo ai = new LosEffects.AttackInfo();
ai.attackPos = src;
ai.targetPos = dest;

// Need to re-write this to work with Low Alt maps
// LosEffects.AttackInfo ai = new LosEffects.AttackInfo();
LosEffects.AttackInfo ai = LosEffects.prepLosAttackInfo(
this.boardView1.game, this.boardView1.getSelectedEntity(), null, src, dest,
guip.getMechInFirst(), guip.getMechInSecond()
);
//ai.attackPos = src;
//ai.targetPos = dest;
// First, we check for a selected unit and use its height. If
// there's no selected unit we use the mechInFirst GUIPref.
if (this.boardView1.getSelectedEntity() != null) {
ai.attackHeight = this.boardView1.getSelectedEntity().getHeight();
Entity ae = this.boardView1.getSelectedEntity();
// Elevation of entity above the hex surface
int elevation;
if (!boardView1.pathSprites.isEmpty()) {
// If we've got a step, get the elevation from it
int lastStepIdx = this.boardView1.pathSprites.size() - 1;
MoveStep lastMS = this.boardView1.pathSprites.get(lastStepIdx)
.getStep();
elevation = lastMS.getElevation();
elevation = (ai.lowAltitude) ? lastMS.getAltitude() : lastMS.getElevation();
} else {
// otherwise we use entity's elevation
elevation = this.boardView1.getSelectedEntity().getElevation();
// otherwise we use entity's altitude / elevation
elevation = (ai.lowAltitude) ? ae.getAltitude() : ae.getElevation();
}
ai.attackAbsHeight = srcHex.getLevel() + elevation
+ this.boardView1.getSelectedEntity().getHeight();
ai.attackAbsHeight = (ai.lowAltitude) ? elevation : srcHex.getLevel() + elevation + ae.getHeight();
} else {
ai.attackHeight = guip.getMechInFirst() ? 1 : 0;
// For hexes, getLevel is functionally the same as getAltitude()
ai.attackAbsHeight = srcHex.getLevel() + ai.attackHeight;
}
// First, we take the tallest unit in the destination hex, if no units are present we use
// the mechInSecond GUIPref.
ai.targetHeight = ai.targetAbsHeight = Integer.MIN_VALUE;
for (Entity ent : boardView1.game.getEntitiesVector(dest)) {
int trAbsheight = dstHex.getLevel() + ent.relHeight();
int trAbsheight = (ai.lowAltitude) ? ent.getAltitude() : dstHex.getLevel() + ent.relHeight();
if (trAbsheight > ai.targetAbsHeight) {
ai.targetHeight = ent.getHeight();
ai.targetAbsHeight = trAbsheight;
}
}
if ((ai.targetHeight == Integer.MIN_VALUE)
&& (ai.targetAbsHeight == Integer.MIN_VALUE)) {
ai.targetHeight = guip.getMechInSecond() ? 1 : 0;
// Current hack for more-correct shading on low-alt maps
ai.targetHeight = (ai.lowAltitude) ? 1 : (guip.getMechInSecond()) ? 1 : 0;
ai.targetAbsHeight = dstHex.getLevel() + ai.targetHeight;
}
return LosEffects.calculateLos(boardView1.game, ai);
Expand Down
Loading

0 comments on commit 7586dde

Please sign in to comment.