1
|
|
|
/* |
2
|
|
|
* This file is part of ArakneLangLoader. |
3
|
|
|
* |
4
|
|
|
* ArakneLangLoader is free software: you can redistribute it and/or modify |
5
|
|
|
* it under the terms of the GNU Lesser General Public License as published by |
6
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
7
|
|
|
* (at your option) any later version. |
8
|
|
|
* |
9
|
|
|
* ArakneLangLoader is distributed in the hope that it will be useful, |
10
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
11
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12
|
|
|
* GNU Lesser General Public License for more details. |
13
|
|
|
* |
14
|
|
|
* You should have received a copy of the GNU Lesser General Public License |
15
|
|
|
* along with ArakneLangLoader. If not, see <https://www.gnu.org/licenses/>. |
16
|
|
|
* |
17
|
|
|
* Copyright (c) 2020 Vincent Quatrevieux |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
package fr.arakne.swflangloader.lang.maps; |
21
|
|
|
|
22
|
|
|
import java.util.Objects; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Positions and extra information for a single game map |
26
|
|
|
* |
27
|
|
|
* Note: The coordinates are not unique |
28
|
|
|
*/ |
29
|
1 |
|
final public class MapPosition { |
30
|
|
|
private int id; |
31
|
|
|
private MapsFile maps; |
32
|
|
|
|
33
|
|
|
/* final */ private int x; |
34
|
|
|
/* final */ private int y; |
35
|
|
|
/* final */ private int sa; |
36
|
|
|
/* final */ private int ep; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @return The map id. Unique on the maps file |
40
|
|
|
*/ |
41
|
|
|
public int id() { |
42
|
1 |
|
return id; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* The X coordinate |
47
|
|
|
* Lower value for north, and higher for south |
48
|
|
|
* |
49
|
|
|
* @return The coordinate value |
50
|
|
|
*/ |
51
|
|
|
public int x() { |
52
|
1 |
|
return x; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* The Y coordinate |
57
|
|
|
* Lower value for west, higher value for east |
58
|
|
|
* |
59
|
|
|
* @return The coordinate value |
60
|
|
|
*/ |
61
|
|
|
public int y() { |
62
|
1 |
|
return y; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return The sub area id |
67
|
|
|
*/ |
68
|
|
|
public int subAreaId() { |
69
|
1 |
|
return sa; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return The sub area instance |
74
|
|
|
*/ |
75
|
|
|
public MapSubArea subArea() { |
76
|
1 |
|
return maps.subArea(sa); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @return The ep value |
81
|
|
|
*/ |
82
|
|
|
public int ep() { |
83
|
1 |
|
return ep; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Compute manhattan distance between the two maps positions |
88
|
|
|
* |
89
|
|
|
* @param other The other map position |
90
|
|
|
* |
91
|
|
|
* @return The distance |
92
|
|
|
*/ |
93
|
|
|
public int distance(MapPosition other) { |
94
|
1 |
|
return Math.abs(x - other.x) + Math.abs(y - other.y); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
@Override |
98
|
|
|
public boolean equals(Object o) { |
99
|
1 |
|
if (this == o) return true; |
100
|
1 |
|
if (o == null || getClass() != o.getClass()) return false; |
101
|
1 |
|
MapPosition position = (MapPosition) o; |
102
|
1 |
|
return id == position.id; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
@Override |
106
|
|
|
public int hashCode() { |
107
|
1 |
|
return Objects.hash(id); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
@Override |
111
|
|
|
public String toString() { |
112
|
1 |
|
return "MapPosition{" + id + |
113
|
|
|
", x=" + x + |
114
|
|
|
", y=" + y + |
115
|
1 |
|
", sa=" + subArea().name() + " (" + sa + ")" + |
116
|
|
|
'}'; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
void setId(int id) { |
120
|
1 |
|
this.id = id; |
121
|
1 |
|
} |
122
|
|
|
|
123
|
|
|
void setMaps(MapsFile maps) { |
124
|
1 |
|
this.maps = maps; |
125
|
1 |
|
} |
126
|
|
|
} |
127
|
|
|
|