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

Fixes Token VBL and AI Pathing Conflict #456 #1190

Merged
merged 1 commit into from
Jan 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package net.rptools.maptool.client.ui.zone;

import java.awt.geom.Area;
import java.util.Set;
import javax.swing.SwingWorker;
import net.rptools.maptool.client.walker.ZoneWalker;
Expand All @@ -28,23 +29,26 @@ public class RenderPathWorker extends SwingWorker<Void, Void> {
CellPoint startPoint, endPoint;
private final boolean restrictMovement;
private final Set<TerrainModifierOperation> terrainModifiersIgnored;
private final Area tokenVBL;

public RenderPathWorker(
ZoneWalker walker,
CellPoint endPoint,
boolean restrictMovement,
Set<TerrainModifierOperation> terrainModifiersIgnored,
Area tokenVBL,
ZoneRenderer zoneRenderer) {
this.walker = walker;
this.endPoint = endPoint;
this.restrictMovement = restrictMovement;
this.zoneRenderer = zoneRenderer;
this.terrainModifiersIgnored = terrainModifiersIgnored;
this.tokenVBL = tokenVBL;
}

@Override
protected Void doInBackground() throws Exception {
walker.replaceLastWaypoint(endPoint, restrictMovement, terrainModifiersIgnored);
walker.replaceLastWaypoint(endPoint, restrictMovement, terrainModifiersIgnored, tokenVBL);
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4349,7 +4349,12 @@ public void setOffset(int x, int y) {

renderPathTask =
new RenderPathWorker(
walker, point, restictMovement, terrainModifiersIgnored, ZoneRenderer.this);
walker,
point,
restictMovement,
terrainModifiersIgnored,
token.getTransformedVBL(),
ZoneRenderer.this);
renderPathThreadPool.execute(renderPathTask);
} else {
if (gridlessPath.getCellPath().size() > 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package net.rptools.maptool.client.walker;

import java.awt.geom.Area;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand All @@ -32,6 +33,7 @@ public abstract class AbstractZoneWalker implements ZoneWalker {
protected final Zone zone;
protected boolean restrictMovement = false;
protected Set<TerrainModifierOperation> terrainModifiersIgnored;
protected Area tokenVBL;
protected RenderPathWorker renderPathWorker;

public AbstractZoneWalker(Zone zone) {
Expand Down Expand Up @@ -69,17 +71,20 @@ public void addWaypoints(CellPoint... points) {
}

public CellPoint replaceLastWaypoint(CellPoint point) {
return replaceLastWaypoint(point, false, Collections.singleton(TerrainModifierOperation.NONE));
return replaceLastWaypoint(
point, false, Collections.singleton(TerrainModifierOperation.NONE), null);
}

@Override
public CellPoint replaceLastWaypoint(
CellPoint point,
boolean restrictMovement,
Set<TerrainModifierOperation> terrainModifiersIgnored) {
Set<TerrainModifierOperation> terrainModifiersIgnored,
Area tokenVBL) {

this.restrictMovement = restrictMovement;
this.terrainModifiersIgnored = terrainModifiersIgnored;
this.tokenVBL = tokenVBL;

if (partialPaths.isEmpty()) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package net.rptools.maptool.client.walker;

import java.awt.geom.Area;
import java.util.Collection;
import java.util.Set;
import net.rptools.maptool.client.ui.zone.RenderPathWorker;
Expand All @@ -24,6 +25,7 @@
import net.rptools.maptool.model.TokenFootprint;

public interface ZoneWalker {

public void setWaypoints(CellPoint... points);

public void addWaypoints(CellPoint... point);
Expand All @@ -33,7 +35,8 @@ public interface ZoneWalker {
public CellPoint replaceLastWaypoint(
CellPoint point,
boolean restrictMovement,
Set<TerrainModifierOperation> terrainModifiersIgnored);
Set<TerrainModifierOperation> terrainModifiersIgnored,
Area tokenVBL);

public boolean isWaypoint(CellPoint point);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ protected List<CellPoint> calculatePath(CellPoint start, CellPoint goal) {
// Note: zoneRenderer will be null if map is not visible to players.
if (MapTool.getFrame().getCurrentZoneRenderer() != null) {
vbl = MapTool.getFrame().getCurrentZoneRenderer().getZoneView().getTopologyTree().getArea();

if (tokenVBL != null) {
vbl.subtract(tokenVBL);
}
}

if (!vbl.isEmpty()) {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/net/rptools/maptool/model/Token.java
Original file line number Diff line number Diff line change
Expand Up @@ -1376,6 +1376,10 @@ public Area getTransformedVBL() {
* @since 1.4.1.5
*/
public Area getTransformedVBL(Area areaToTransform) {
if (areaToTransform == null) {
return null;
}

Rectangle footprintBounds = getBounds(MapTool.getFrame().getCurrentZoneRenderer().getZone());
Dimension imgSize = new Dimension(getWidth(), getHeight());
SwingUtil.constrainTo(imgSize, footprintBounds.width, footprintBounds.height);
Expand Down