Update ramps and cliffs

This commit is contained in:
Retera 2021-01-23 23:03:03 -05:00
parent 4f7368eb57
commit ec1510adcd
3 changed files with 156 additions and 27 deletions

View File

@ -594,25 +594,24 @@ public class Terrain {
}
if (!(facingDown && (j == 0)) && !(!facingDown && (j >= (this.rows - 2)))
&& !(facingLeft && (i == 0)) && !(!facingLeft && (i >= (this.columns - 2)))) {
final boolean br = ((bottomLeft.getRamp() != 0) != (bottomRight.getRamp() != 0))
&& ((topLeft.getRamp() != 0) != (topRight.getRamp() != 0))
&& !this.corners[i + (bottomRight.getRamp() != 0 ? 1 : 0)][j
+ (facingDown ? -1 : 1)].cliff;
final boolean verticalRamp = ((bottomLeft.isRamp()) != (bottomRight.isRamp()))
&& ((topLeft.isRamp()) != (topRight.isRamp()))
&& !this.corners[i][j + (facingDown ? -1 : 1)].cliff;
final boolean bo = ((bottomLeft.getRamp() != 0) != (topLeft.getRamp() != 0))
&& ((bottomRight.getRamp() != 0) != (topRight.getRamp() != 0))
&& !this.corners[i + (facingLeft ? -1 : 1)][j + (topLeft.getRamp() != 0 ? 1 : 0)].cliff;
final boolean horizontalRamp = ((bottomLeft.isRamp()) != (topLeft.isRamp()))
&& ((bottomRight.isRamp()) != (topRight.isRamp()))
&& !this.corners[i + (facingLeft ? -1 : 1)][j].cliff;
if (br || bo) {
String fileName = "" + (char) ((bottomLeft.getRamp() != 0 ? 'L' : 'A')
+ ((bottomLeft.getLayerHeight() - base) * (bottomLeft.getRamp() != 0 ? -4 : 1)))
+ (char) ((topLeft.getRamp() != 0 ? 'L' : 'A')
+ ((topLeft.getLayerHeight() - base) * (topLeft.getRamp() != 0 ? -4 : 1)))
+ (char) ((topRight.getRamp() != 0 ? 'L' : 'A')
+ ((topRight.getLayerHeight() - base) * (topRight.getRamp() != 0 ? -4 : 1)))
+ (char) ((bottomRight.getRamp() != 0 ? 'L' : 'A')
+ ((bottomRight.getLayerHeight() - base)
* (bottomRight.getRamp() != 0 ? -4 : 1)));
if (verticalRamp || horizontalRamp) {
String fileName = ""
+ (char) ((topLeft.isRamp() ? 'L' : 'A')
+ ((topLeft.getLayerHeight() - base) * (topLeft.isRamp() ? -4 : 1)))
+ (char) ((topRight.isRamp() ? 'L' : 'A')
+ ((topRight.getLayerHeight() - base) * (topRight.isRamp() ? -4 : 1)))
+ (char) ((bottomRight.isRamp() ? 'L' : 'A')
+ ((bottomRight.getLayerHeight() - base) * (bottomRight.isRamp() ? -4 : 1)))
+ (char) ((bottomLeft.isRamp() ? 'L' : 'A')
+ ((bottomLeft.getLayerHeight() - base) * (bottomLeft.isRamp() ? -4 : 1)));
final String rampModelDir = this.cliffTextures.get(bottomLeftCliffTex).rampModelDir;
fileName = "Doodads\\Terrain\\" + rampModelDir + "\\" + rampModelDir + fileName + "0.mdx";
@ -625,19 +624,20 @@ public class Terrain {
for (int ji = this.cliffs.size(); ji-- > 0;) {
final IVec3 pos = this.cliffs.get(ji);
if ((pos.x == (i + ((bo ? 1 : 0) * (facingLeft ? 0 : 1))))
&& (pos.y == (j - ((br ? 1 : 0) * (facingDown ? 1 : 0))))) {
if ((pos.x == (i + ((horizontalRamp ? 1 : 0) * (facingLeft ? -1 : 0))))
&& (pos.y == (j - ((verticalRamp ? 1 : 0) * (facingDown ? 1 : 0))))) {
this.cliffs.remove(ji);
break;
}
}
this.cliffs.add(new IVec3((i + ((bo ? 1 : 0) * (facingLeft ? 0 : 1))),
(j - ((br ? 1 : 0) * (facingDown ? 1 : 0))), this.pathToCliff.get(fileName)));
this.cliffs.add(new IVec3((i + ((horizontalRamp ? 1 : 0) * (facingLeft ? -1 : 0))),
(j - ((verticalRamp ? 1 : 0) * (facingDown ? 1 : 0))),
this.pathToCliff.get(fileName)));
bottomLeft.romp = true;
this.corners[i + ((facingLeft ? -1 : 1) * (bo ? 1 : 0))][j
+ ((facingDown ? -1 : 1) * (br ? 1 : 0))].romp = true;
this.corners[i + ((facingLeft ? -1 : 1) * (horizontalRamp ? 1 : 0))][j
+ ((facingDown ? -1 : 1) * (verticalRamp ? 1 : 0))].romp = true;
continue;
}
@ -788,8 +788,8 @@ public class Terrain {
final RenderCorner topLeft = this.corners[x + i][y + j + 1];
final RenderCorner topRight = this.corners[x + i + 1][y + j + 1];
if ((bottomLeft.getRamp() != 0) && (topLeft.getRamp() != 0) && (bottomRight.getRamp() != 0)
&& (topRight.getRamp() != 0) && (!bottomLeft.romp) && (!bottomRight.romp)
if ((bottomLeft.isRamp()) && (topLeft.isRamp()) && (bottomRight.isRamp())
&& (topRight.isRamp()) && (!bottomLeft.romp) && (!bottomRight.romp)
&& (!topLeft.romp) && (!topRight.romp)) {
break ILoop;
}
@ -825,8 +825,8 @@ public class Terrain {
final RenderCorner topLeft = this.corners[x][y + 1];
final RenderCorner topRight = this.corners[x + 1][y + 1];
return (bottomLeft.getRamp() != 0) && (topLeft.getRamp() != 0) && (bottomRight.getRamp() != 0)
&& (topRight.getRamp() != 0) && !((bottomLeft.getLayerHeight() == topRight.getLayerHeight())
return (bottomLeft.isRamp()) && (topLeft.isRamp()) && (bottomRight.isRamp()) && (topRight.isRamp())
&& !((bottomLeft.getLayerHeight() == topRight.getLayerHeight())
&& (topLeft.getLayerHeight() == bottomRight.getLayerHeight()));
}

View File

@ -0,0 +1,36 @@
package com.etheller.warsmash.desktop.util;
import java.io.IOException;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.WindowConstants;
import com.etheller.warsmash.WarsmashGdxMapGame;
import com.etheller.warsmash.datasources.DataSource;
import com.etheller.warsmash.desktop.DesktopLauncher;
import com.etheller.warsmash.parsers.w3x.War3Map;
import com.etheller.warsmash.parsers.w3x.w3e.War3MapW3e;
import com.etheller.warsmash.units.DataTable;
public class TerrainView {
public static void main(final String[] args) {
final DataTable warsmashIni = DesktopLauncher.loadWarsmashIni();
final DataSource dataSources = WarsmashGdxMapGame.parseDataSources(warsmashIni);
final War3Map war3Map = new War3Map(dataSources, warsmashIni.get("Map").getField("FilePath"));
try {
final War3MapW3e environmentFile = war3Map.readEnvironment();
final TerrainViewPanel terrainViewPanel = new TerrainViewPanel(environmentFile);
final JFrame frame = new JFrame("TerrainView");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.setContentPane(new JScrollPane(terrainViewPanel));
frame.setBounds(0, 0, 800, 600);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
catch (final IOException e) {
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,93 @@
package com.etheller.warsmash.desktop.util;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.Box;
import javax.swing.JPanel;
import com.etheller.warsmash.parsers.w3x.w3e.Corner;
import com.etheller.warsmash.parsers.w3x.w3e.War3MapW3e;
public class TerrainViewPanel extends JPanel {
private final War3MapW3e environmentFile;
private final Font baseFont;
private final Font biggerFont;
private int cliffMode = 0;
public TerrainViewPanel(final War3MapW3e environmentFile) {
this.environmentFile = environmentFile;
add(Box.createRigidArea(new Dimension(this.environmentFile.getCorners()[0].length * 32,
this.environmentFile.getCorners().length * 32)));
this.baseFont = getFont();
this.biggerFont = this.baseFont.deriveFont(24f);
addMouseListener(new MouseListener() {
@Override
public void mouseReleased(final MouseEvent e) {
}
@Override
public void mousePressed(final MouseEvent e) {
TerrainViewPanel.this.cliffMode = (TerrainViewPanel.this.cliffMode + 1) % 4;
repaint();
}
@Override
public void mouseExited(final MouseEvent e) {
}
@Override
public void mouseEntered(final MouseEvent e) {
}
@Override
public void mouseClicked(final MouseEvent e) {
}
});
}
@Override
protected void paintComponent(final Graphics g) {
super.paintComponent(g);
final Corner[][] corners = this.environmentFile.getCorners();
for (int i = 0; i < corners.length; i++) {
final int length = corners[i].length;
for (int j = 0; j < length; j++) {
int base = 0;
final int value;
switch (this.cliffMode) {
case 0:
value = corners[i][j].getRamp();
break;
case 1:
value = corners[i][j].getLayerHeight();
base = 2;
break;
case 2:
value = corners[i][j].getGroundTexture();
break;
case 3:
value = corners[i][j].getCliffTexture();
break;
default:
value = 0;
break;
}
if (value != base) {
g.setFont(this.biggerFont);
}
else {
g.setFont(this.baseFont);
}
g.drawString(value + "", j * 32, (length - i - 1) * 32);
}
}
}
}