More reformatting
This commit is contained in:
@@ -46,28 +46,23 @@ public class Board {
|
||||
}
|
||||
|
||||
public static void removeAt(FLocation flocation) {
|
||||
clearOwnershipAt(flocation);
|
||||
flocationIds.remove(flocation);
|
||||
clearOwnershipAt(flocation); flocationIds.remove(flocation);
|
||||
}
|
||||
|
||||
// not to be confused with claims, ownership referring to further member-specific ownership of a claim
|
||||
public static void clearOwnershipAt(FLocation flocation) {
|
||||
Faction faction = getFactionAt(flocation);
|
||||
if (faction != null && faction.isNormal()) {
|
||||
Faction faction = getFactionAt(flocation); if (faction != null && faction.isNormal()) {
|
||||
faction.clearClaimOwnership(flocation);
|
||||
}
|
||||
}
|
||||
|
||||
public static void unclaimAll(String factionId) {
|
||||
Faction faction = Factions.i.get(factionId);
|
||||
if (faction != null && faction.isNormal()) {
|
||||
Faction faction = Factions.i.get(factionId); if (faction != null && faction.isNormal()) {
|
||||
faction.clearAllClaimOwnership();
|
||||
}
|
||||
|
||||
Iterator<Entry<FLocation, String>> iter = flocationIds.entrySet().iterator();
|
||||
while (iter.hasNext()) {
|
||||
Entry<FLocation, String> entry = iter.next();
|
||||
if (entry.getValue().equals(factionId)) {
|
||||
Iterator<Entry<FLocation, String>> iter = flocationIds.entrySet().iterator(); while (iter.hasNext()) {
|
||||
Entry<FLocation, String> entry = iter.next(); if (entry.getValue().equals(factionId)) {
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
@@ -76,20 +71,16 @@ public class Board {
|
||||
// Is this coord NOT completely surrounded by coords claimed by the same faction?
|
||||
// Simpler: Is there any nearby coord with a faction other than the faction here?
|
||||
public static boolean isBorderLocation(FLocation flocation) {
|
||||
Faction faction = getFactionAt(flocation);
|
||||
FLocation a = flocation.getRelative(1, 0);
|
||||
FLocation b = flocation.getRelative(-1, 0);
|
||||
FLocation c = flocation.getRelative(0, 1);
|
||||
Faction faction = getFactionAt(flocation); FLocation a = flocation.getRelative(1, 0);
|
||||
FLocation b = flocation.getRelative(-1, 0); FLocation c = flocation.getRelative(0, 1);
|
||||
FLocation d = flocation.getRelative(0, -1);
|
||||
return faction != getFactionAt(a) || faction != getFactionAt(b) || faction != getFactionAt(c) || faction != getFactionAt(d);
|
||||
}
|
||||
|
||||
// Is this coord connected to any coord claimed by the specified faction?
|
||||
public static boolean isConnectedLocation(FLocation flocation, Faction faction) {
|
||||
FLocation a = flocation.getRelative(1, 0);
|
||||
FLocation b = flocation.getRelative(-1, 0);
|
||||
FLocation c = flocation.getRelative(0, 1);
|
||||
FLocation d = flocation.getRelative(0, -1);
|
||||
FLocation a = flocation.getRelative(1, 0); FLocation b = flocation.getRelative(-1, 0);
|
||||
FLocation c = flocation.getRelative(0, 1); FLocation d = flocation.getRelative(0, -1);
|
||||
return faction == getFactionAt(a) || faction == getFactionAt(b) || faction == getFactionAt(c) || faction == getFactionAt(d);
|
||||
}
|
||||
|
||||
@@ -99,12 +90,9 @@ public class Board {
|
||||
//----------------------------------------------//
|
||||
|
||||
public static void clean() {
|
||||
Iterator<Entry<FLocation, String>> iter = flocationIds.entrySet().iterator();
|
||||
while (iter.hasNext()) {
|
||||
Entry<FLocation, String> entry = iter.next();
|
||||
if (!Factions.i.exists(entry.getValue())) {
|
||||
P.p.log("Board cleaner removed " + entry.getValue() + " from " + entry.getKey());
|
||||
iter.remove();
|
||||
Iterator<Entry<FLocation, String>> iter = flocationIds.entrySet().iterator(); while (iter.hasNext()) {
|
||||
Entry<FLocation, String> entry = iter.next(); if (!Factions.i.exists(entry.getValue())) {
|
||||
P.p.log("Board cleaner removed " + entry.getValue() + " from " + entry.getKey()); iter.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -114,13 +102,11 @@ public class Board {
|
||||
//----------------------------------------------//
|
||||
|
||||
public static int getFactionCoordCount(String factionId) {
|
||||
int ret = 0;
|
||||
for (String thatFactionId : flocationIds.values()) {
|
||||
int ret = 0; for (String thatFactionId : flocationIds.values()) {
|
||||
if (thatFactionId.equals(factionId)) {
|
||||
ret += 1;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
} return ret;
|
||||
}
|
||||
|
||||
public static int getFactionCoordCount(Faction faction) {
|
||||
@@ -128,16 +114,13 @@ public class Board {
|
||||
}
|
||||
|
||||
public static int getFactionCoordCountInWorld(Faction faction, String worldName) {
|
||||
String factionId = faction.getId();
|
||||
int ret = 0;
|
||||
Iterator<Entry<FLocation, String>> iter = flocationIds.entrySet().iterator();
|
||||
while (iter.hasNext()) {
|
||||
String factionId = faction.getId(); int ret = 0;
|
||||
Iterator<Entry<FLocation, String>> iter = flocationIds.entrySet().iterator(); while (iter.hasNext()) {
|
||||
Entry<FLocation, String> entry = iter.next();
|
||||
if (entry.getValue().equals(factionId) && entry.getKey().getWorldName().equals(worldName)) {
|
||||
ret += 1;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
} return ret;
|
||||
}
|
||||
|
||||
//----------------------------------------------//
|
||||
@@ -149,68 +132,47 @@ public class Board {
|
||||
* of decreasing z
|
||||
*/
|
||||
public static ArrayList<String> getMap(Faction faction, FLocation flocation, double inDegrees) {
|
||||
ArrayList<String> ret = new ArrayList<String>();
|
||||
Faction factionLoc = getFactionAt(flocation);
|
||||
ArrayList<String> ret = new ArrayList<String>(); Faction factionLoc = getFactionAt(flocation);
|
||||
ret.add(P.p.txt.titleize("(" + flocation.getCoordString() + ") " + factionLoc.getTag(faction)));
|
||||
|
||||
int halfWidth = Conf.mapWidth / 2;
|
||||
int halfHeight = Conf.mapHeight / 2;
|
||||
FLocation topLeft = flocation.getRelative(-halfWidth, -halfHeight);
|
||||
int width = halfWidth * 2 + 1;
|
||||
int halfWidth = Conf.mapWidth / 2; int halfHeight = Conf.mapHeight / 2;
|
||||
FLocation topLeft = flocation.getRelative(-halfWidth, -halfHeight); int width = halfWidth * 2 + 1;
|
||||
int height = halfHeight * 2 + 1;
|
||||
|
||||
if (Conf.showMapFactionKey) {
|
||||
height--;
|
||||
}
|
||||
|
||||
Map<String, Character> fList = new HashMap<String, Character>();
|
||||
int chrIdx = 0;
|
||||
Map<String, Character> fList = new HashMap<String, Character>(); int chrIdx = 0;
|
||||
|
||||
// For each row
|
||||
for (int dz = 0; dz < height; dz++) {
|
||||
// Draw and add that row
|
||||
String row = "";
|
||||
for (int dx = 0; dx < width; dx++) {
|
||||
String row = ""; for (int dx = 0; dx < width; dx++) {
|
||||
if (dx == halfWidth && dz == halfHeight) {
|
||||
row += ChatColor.AQUA + "+";
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
FLocation flocationHere = topLeft.getRelative(dx, dz);
|
||||
Faction factionHere = getFactionAt(flocationHere);
|
||||
Relation relation = faction.getRelationTo(factionHere);
|
||||
if (factionHere.isNone()) {
|
||||
Relation relation = faction.getRelationTo(factionHere); if (factionHere.isNone()) {
|
||||
row += ChatColor.GRAY + "-";
|
||||
}
|
||||
else if (factionHere.isSafeZone()) {
|
||||
} else if (factionHere.isSafeZone()) {
|
||||
row += Conf.colorPeaceful + "+";
|
||||
}
|
||||
else if (factionHere.isWarZone()) {
|
||||
} else if (factionHere.isWarZone()) {
|
||||
row += ChatColor.DARK_RED + "+";
|
||||
}
|
||||
else if
|
||||
(
|
||||
factionHere == faction
|
||||
||
|
||||
factionHere == factionLoc
|
||||
||
|
||||
relation.isAtLeast(Relation.ALLY)
|
||||
||
|
||||
(Conf.showNeutralFactionsOnMap && relation.equals(Relation.NEUTRAL))
|
||||
||
|
||||
(Conf.showEnemyFactionsOnMap && relation.equals(Relation.ENEMY))
|
||||
) {
|
||||
} else if (factionHere == faction ||
|
||||
factionHere == factionLoc ||
|
||||
relation.isAtLeast(Relation.ALLY) ||
|
||||
(Conf.showNeutralFactionsOnMap && relation.equals(Relation.NEUTRAL)) ||
|
||||
(Conf.showEnemyFactionsOnMap && relation.equals(Relation.ENEMY))) {
|
||||
if (!fList.containsKey(factionHere.getTag())) {
|
||||
fList.put(factionHere.getTag(), Conf.mapKeyChrs[chrIdx++]);
|
||||
}
|
||||
char tag = fList.get(factionHere.getTag());
|
||||
row += factionHere.getColorTo(faction) + "" + tag;
|
||||
}
|
||||
else {
|
||||
} char tag = fList.get(factionHere.getTag()); row += factionHere.getColorTo(faction) + "" + tag;
|
||||
} else {
|
||||
row += ChatColor.GRAY + "-";
|
||||
}
|
||||
}
|
||||
}
|
||||
ret.add(row);
|
||||
} ret.add(row);
|
||||
}
|
||||
|
||||
// Get the compass
|
||||
@@ -223,11 +185,9 @@ public class Board {
|
||||
|
||||
// Add the faction key
|
||||
if (Conf.showMapFactionKey) {
|
||||
String fRow = "";
|
||||
for (String key : fList.keySet()) {
|
||||
String fRow = ""; for (String key : fList.keySet()) {
|
||||
fRow += String.format("%s%s: %s ", ChatColor.GRAY, fList.get(key), key);
|
||||
}
|
||||
ret.add(fRow);
|
||||
} ret.add(fRow);
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -241,13 +201,10 @@ public class Board {
|
||||
public static Map<String, Map<String, String>> dumpAsSaveFormat() {
|
||||
Map<String, Map<String, String>> worldCoordIds = new HashMap<String, Map<String, String>>();
|
||||
|
||||
String worldName, coords;
|
||||
String id;
|
||||
String worldName, coords; String id;
|
||||
|
||||
for (Entry<FLocation, String> entry : flocationIds.entrySet()) {
|
||||
worldName = entry.getKey().getWorldName();
|
||||
coords = entry.getKey().getCoordString();
|
||||
id = entry.getValue();
|
||||
worldName = entry.getKey().getWorldName(); coords = entry.getKey().getCoordString(); id = entry.getValue();
|
||||
if (!worldCoordIds.containsKey(worldName)) {
|
||||
worldCoordIds.put(worldName, new TreeMap<String, String>());
|
||||
}
|
||||
@@ -261,18 +218,12 @@ public class Board {
|
||||
public static void loadFromSaveFormat(Map<String, Map<String, String>> worldCoordIds) {
|
||||
flocationIds.clear();
|
||||
|
||||
String worldName;
|
||||
String[] coords;
|
||||
int x, z;
|
||||
String factionId;
|
||||
String worldName; String[] coords; int x, z; String factionId;
|
||||
|
||||
for (Entry<String, Map<String, String>> entry : worldCoordIds.entrySet()) {
|
||||
worldName = entry.getKey();
|
||||
for (Entry<String, String> entry2 : entry.getValue().entrySet()) {
|
||||
coords = entry2.getKey().trim().split("[,\\s]+");
|
||||
x = Integer.parseInt(coords[0]);
|
||||
z = Integer.parseInt(coords[1]);
|
||||
factionId = entry2.getValue();
|
||||
worldName = entry.getKey(); for (Entry<String, String> entry2 : entry.getValue().entrySet()) {
|
||||
coords = entry2.getKey().trim().split("[,\\s]+"); x = Integer.parseInt(coords[0]);
|
||||
z = Integer.parseInt(coords[1]); factionId = entry2.getValue();
|
||||
flocationIds.put(new FLocation(worldName, x, z), factionId);
|
||||
}
|
||||
}
|
||||
@@ -284,9 +235,7 @@ public class Board {
|
||||
try {
|
||||
DiscUtil.write(file, P.p.gson.toJson(dumpAsSaveFormat()));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
P.p.log("Failed to save the board to disk.");
|
||||
return false;
|
||||
e.printStackTrace(); P.p.log("Failed to save the board to disk."); return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -296,20 +245,15 @@ public class Board {
|
||||
P.p.log("Loading board from disk");
|
||||
|
||||
if (!file.exists()) {
|
||||
P.p.log("No board to load from disk. Creating new file.");
|
||||
save();
|
||||
return true;
|
||||
P.p.log("No board to load from disk. Creating new file."); save(); return true;
|
||||
}
|
||||
|
||||
try {
|
||||
Type type = new TypeToken<Map<String, Map<String, String>>>() {
|
||||
}.getType();
|
||||
Type type = new TypeToken<Map<String, Map<String, String>>>() {}.getType();
|
||||
Map<String, Map<String, String>> worldCoordIds = P.p.gson.fromJson(DiscUtil.read(file), type);
|
||||
loadFromSaveFormat(worldCoordIds);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
P.p.log("Failed to load the board from disk.");
|
||||
return false;
|
||||
e.printStackTrace(); P.p.log("Failed to load the board from disk."); return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user