Add buffer zone for areas between Faction claims. Adds #233.
This commit is contained in:
parent
559695d103
commit
5579005714
@ -45,6 +45,7 @@ public abstract class Board {
|
||||
// Is this coord connected to any coord claimed by the specified faction?
|
||||
public abstract boolean isConnectedLocation(FLocation flocation, Faction faction);
|
||||
|
||||
public abstract boolean hasFactionWithin(FLocation flocation, Faction faction, int radius);
|
||||
|
||||
//----------------------------------------------//
|
||||
// Cleaner. Remove orphaned foreign keys
|
||||
|
@ -104,6 +104,39 @@ public abstract class MemoryBoard extends Board {
|
||||
return faction == getFactionAt(a) || faction == getFactionAt(b) || faction == getFactionAt(c) || faction == getFactionAt(d);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if there is another faction within a given radius other than Wilderness.
|
||||
* Used for HCF feature that requires a 'buffer' between factions.
|
||||
* @param flocation - center location.
|
||||
* @param faction - faction checking for.
|
||||
* @param radius - chunk radius to check.
|
||||
* @return true if another Faction is within the radius, otherwise false.
|
||||
*/
|
||||
public boolean hasFactionWithin(FLocation flocation, Faction faction, int radius) {
|
||||
for(int i = 1; i <= radius; i++) {
|
||||
FLocation a = flocation.getRelative(i, 0);
|
||||
FLocation b = flocation.getRelative(-i, 0);
|
||||
FLocation c = flocation.getRelative(0, i);
|
||||
FLocation d = flocation.getRelative(0, -i);
|
||||
if(isDifferentFaction(a, faction) || isDifferentFaction(b, faction) || isDifferentFaction(c, faction) || isDifferentFaction(d, faction)) {
|
||||
return false; // Return if the Faction found is a different one.
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the faction at the flocation is not wilderness and different than given faction.
|
||||
* @param flocation - location to check.
|
||||
* @param faction - faction to compare.
|
||||
* @return true if not wilderness, safezone, or warzone and different faction, otherwise false.
|
||||
*/
|
||||
private boolean isDifferentFaction(FLocation flocation, Faction faction) {
|
||||
Faction other = getFactionAt(flocation);
|
||||
// Check if faction is
|
||||
return other.isNormal() && other != faction;
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------//
|
||||
// Cleaner. Remove orphaned foreign keys
|
||||
|
@ -658,6 +658,7 @@ public abstract class MemoryFPlayer implements FPlayer {
|
||||
Faction myFaction = getFaction();
|
||||
Faction currentFaction = Board.getInstance().getFactionAt(flocation);
|
||||
int ownedLand = forFaction.getLandRounded();
|
||||
int buffer = P.p.getConfig().getInt("hcf.buffer-zone", 0);
|
||||
|
||||
if (Conf.worldGuardChecking && Worldguard.checkForRegionsInChunk(location)) {
|
||||
// Checks for WorldGuard regions in the chunk attempting to be claimed
|
||||
@ -694,6 +695,8 @@ public abstract class MemoryFPlayer implements FPlayer {
|
||||
} else {
|
||||
error = P.p.txt.parse(TL.CLAIM_FACTIONCONTIGUOUS.toString());
|
||||
}
|
||||
} else if (buffer > 0 && Board.getInstance().hasFactionWithin(flocation, myFaction, buffer)) {
|
||||
error = P.p.txt.parse(TL.CLAIM_TOOCLOSETOOTHERFACTION.format(buffer));
|
||||
} else if (currentFaction.isNormal()) {
|
||||
if (myFaction.isPeaceful()) {
|
||||
error = P.p.txt.parse(TL.CLAIM_PEACEFUL.toString(), currentFaction.getTag(this));
|
||||
|
@ -537,6 +537,7 @@ public enum TL {
|
||||
CLAIM_CLAIMED("<h>%s<i> claimed land for <h>%s<i> from <h>%s<i>."),
|
||||
CLAIM_CLAIMEDLOG("%s claimed land at (%s) for the faction: %s"),
|
||||
CLAIM_OVERCLAIM_DISABLED("<i>Over claiming is disabled on this server."),
|
||||
CLAIM_TOOCLOSETOOTHERFACTION("<i>Your claim is too close to another Faction. Buffer required is %d"),
|
||||
|
||||
/**
|
||||
* More generic, or less easily categorisable translations, which may apply to more than one class
|
||||
|
@ -189,3 +189,15 @@ hcf:
|
||||
# This resets on each death but does not accumulate.
|
||||
# Set to 0 for no freeze. Time is in seconds.
|
||||
powerfreeze: 0
|
||||
|
||||
# Buffer Zone
|
||||
# Buffer Zone is an chunk area required between claims of different Factions.
|
||||
# This is default to 0 and has always been that way. Meaning Factions can have
|
||||
# claims that border each other.
|
||||
# If this is set to 3, then Factions need to have 3 chunks between their claim
|
||||
# and another Faction's claim.
|
||||
# It's recommended to keep this pretty low as the radius check could be a
|
||||
# heavy operation if set to a large number.
|
||||
# If this is set to 0, we won't even bother checking which is how Factions has
|
||||
# always been.
|
||||
buffer-zone: 0
|
Loading…
Reference in New Issue
Block a user