Rename and clean up MapleFoothold

This commit is contained in:
P0nk
2021-09-09 22:20:08 +02:00
parent c0fedc8589
commit 032f111b53
4 changed files with 27 additions and 28 deletions

View File

@@ -21,19 +21,18 @@
*/ */
package server.maps; package server.maps;
import java.awt.Point; import java.awt.*;
/** /**
*
* @author Matze * @author Matze
*/ */
public class MapleFoothold implements Comparable<MapleFoothold> { public class Foothold implements Comparable<Foothold> {
private Point p1; private final Point p1;
private Point p2; private final Point p2;
private int id; private final int id;
private int next, prev; private int next, prev;
public MapleFoothold(Point p1, Point p2, int id) { public Foothold(Point p1, Point p2, int id) {
this.p1 = p1; this.p1 = p1;
this.p2 = p2; this.p2 = p2;
this.id = id; this.id = id;
@@ -57,8 +56,8 @@ public class MapleFoothold implements Comparable<MapleFoothold> {
public int getY2() { public int getY2() {
return p2.y; return p2.y;
} }
// XXX may need more precision // XXX may need more precision
public int calculateFooting(int x) { public int calculateFooting(int x) {
if (p1.y == p2.y) { if (p1.y == p2.y) {
@@ -70,8 +69,8 @@ public class MapleFoothold implements Comparable<MapleFoothold> {
} }
@Override @Override
public int compareTo(MapleFoothold o) { public int compareTo(Foothold o) {
MapleFoothold other = o; Foothold other = o;
if (p2.y < other.getY1()) { if (p2.y < other.getY1()) {
return -1; return -1;
} else if (p1.y > other.getY2()) { } else if (p1.y > other.getY2()) {

View File

@@ -35,7 +35,7 @@ public class MapleFootholdTree {
private MapleFootholdTree ne = null; private MapleFootholdTree ne = null;
private MapleFootholdTree sw = null; private MapleFootholdTree sw = null;
private MapleFootholdTree se = null; private MapleFootholdTree se = null;
private List<MapleFoothold> footholds = new LinkedList<>(); private List<Foothold> footholds = new LinkedList<>();
private Point p1; private Point p1;
private Point p2; private Point p2;
private Point center; private Point center;
@@ -57,7 +57,7 @@ public class MapleFootholdTree {
center = new Point((p2.x - p1.x) / 2, (p2.y - p1.y) / 2); center = new Point((p2.x - p1.x) / 2, (p2.y - p1.y) / 2);
} }
public void insert(MapleFoothold f) { public void insert(Foothold f) {
if (depth == 0) { if (depth == 0) {
if (f.getX1() > maxDropX) { if (f.getX1() > maxDropX) {
maxDropX = f.getX1(); maxDropX = f.getX1();
@@ -95,11 +95,11 @@ public class MapleFootholdTree {
} }
} }
private List<MapleFoothold> getRelevants(Point p) { private List<Foothold> getRelevants(Point p) {
return getRelevants(p, new LinkedList<>()); return getRelevants(p, new LinkedList<>());
} }
private List<MapleFoothold> getRelevants(Point p, List<MapleFoothold> list) { private List<Foothold> getRelevants(Point p, List<Foothold> list) {
list.addAll(footholds); list.addAll(footholds);
if (nw != null) { if (nw != null) {
if (p.x <= center.x && p.y <= center.y) { if (p.x <= center.x && p.y <= center.y) {
@@ -115,9 +115,9 @@ public class MapleFootholdTree {
return list; return list;
} }
private MapleFoothold findWallR(Point p1, Point p2) { private Foothold findWallR(Point p1, Point p2) {
MapleFoothold ret; Foothold ret;
for (MapleFoothold f : footholds) { for (Foothold f : footholds) {
if (f.isWall() && f.getX1() >= p1.x && f.getX1() <= p2.x && if (f.isWall() && f.getX1() >= p1.x && f.getX1() <= p2.x &&
f.getY1() >= p1.y && f.getY2() <= p1.y) { f.getY1() >= p1.y && f.getY2() <= p1.y) {
return f; return f;
@@ -152,23 +152,23 @@ public class MapleFootholdTree {
return null; return null;
} }
public MapleFoothold findWall(Point p1, Point p2) { public Foothold findWall(Point p1, Point p2) {
if (p1.y != p2.y) { if (p1.y != p2.y) {
throw new IllegalArgumentException(); throw new IllegalArgumentException();
} }
return findWallR(p1, p2); return findWallR(p1, p2);
} }
public MapleFoothold findBelow(Point p) { public Foothold findBelow(Point p) {
List<MapleFoothold> relevants = getRelevants(p); List<Foothold> relevants = getRelevants(p);
List<MapleFoothold> xMatches = new LinkedList<>(); List<Foothold> xMatches = new LinkedList<>();
for (MapleFoothold fh : relevants) { for (Foothold fh : relevants) {
if (fh.getX1() <= p.x && fh.getX2() >= p.x) { if (fh.getX1() <= p.x && fh.getX2() >= p.x) {
xMatches.add(fh); xMatches.add(fh);
} }
} }
Collections.sort(xMatches); Collections.sort(xMatches);
for (MapleFoothold fh : xMatches) { for (Foothold fh : xMatches) {
if (!fh.isWall()) { if (!fh.isWall()) {
if (fh.getY1() != fh.getY2()) { if (fh.getY1() != fh.getY2()) {
int calcY; int calcY;

View File

@@ -470,7 +470,7 @@ public class MapleMap {
} }
private Point calcPointBelow(Point initial) { private Point calcPointBelow(Point initial) {
MapleFoothold fh = footholds.findBelow(initial); Foothold fh = footholds.findBelow(initial);
if (fh == null) { if (fh == null) {
return null; return null;
} }

View File

@@ -187,7 +187,7 @@ public class MapleMapFactory {
map.setMapLineBoundings(bounds[0], bounds[1], bounds[2], bounds[3]); map.setMapLineBoundings(bounds[0], bounds[1], bounds[2], bounds[3]);
} }
List<MapleFoothold> allFootholds = new LinkedList<>(); List<Foothold> allFootholds = new LinkedList<>();
Point lBound = new Point(); Point lBound = new Point();
Point uBound = new Point(); Point uBound = new Point();
for (Data footRoot : mapData.getChildByPath("foothold")) { for (Data footRoot : mapData.getChildByPath("foothold")) {
@@ -197,7 +197,7 @@ public class MapleMapFactory {
int y1 = DataTool.getInt(footHold.getChildByPath("y1")); int y1 = DataTool.getInt(footHold.getChildByPath("y1"));
int x2 = DataTool.getInt(footHold.getChildByPath("x2")); int x2 = DataTool.getInt(footHold.getChildByPath("x2"));
int y2 = DataTool.getInt(footHold.getChildByPath("y2")); int y2 = DataTool.getInt(footHold.getChildByPath("y2"));
MapleFoothold fh = new MapleFoothold(new Point(x1, y1), new Point(x2, y2), Integer.parseInt(footHold.getName())); Foothold fh = new Foothold(new Point(x1, y1), new Point(x2, y2), Integer.parseInt(footHold.getName()));
fh.setPrev(DataTool.getInt(footHold.getChildByPath("prev"))); fh.setPrev(DataTool.getInt(footHold.getChildByPath("prev")));
fh.setNext(DataTool.getInt(footHold.getChildByPath("next"))); fh.setNext(DataTool.getInt(footHold.getChildByPath("next")));
if (fh.getX1() < lBound.x) { if (fh.getX1() < lBound.x) {
@@ -217,7 +217,7 @@ public class MapleMapFactory {
} }
} }
MapleFootholdTree fTree = new MapleFootholdTree(lBound, uBound); MapleFootholdTree fTree = new MapleFootholdTree(lBound, uBound);
for (MapleFoothold fh : allFootholds) { for (Foothold fh : allFootholds) {
fTree.insert(fh); fTree.insert(fh);
} }
map.setFootholds(fTree); map.setFootholds(fTree);