Underpowered factions' chunks can now be claimed

This commit is contained in:
shamoanjac 2016-08-09 04:39:40 +02:00
parent b41f7bda72
commit 69ff206590
2 changed files with 21 additions and 7 deletions

View File

@ -160,16 +160,17 @@ factions.register_command ("claim", {
faction_permissions = {"claim"},
description = "Claim the plot of land you're on.",
on_success = function(player, faction, pos, chunkpos, args)
local chunk = factions.chunks[chunkpos]
if not chunk and faction:can_claim_chunk(chunkpos) then
local can_claim = faction:can_claim_chunk(chunkpos)
if can_claim then
minetest.chat_send_player(player, "Claming chunk "..chunkpos)
faction:claim_chunk(chunkpos)
return true
elseif not faction:can_claim_chunk(chunkpos) then
send_error(player, "Chunk cannot be claimed.")
return false
else
if chunk == faction.name then
local chunk = factions.chunks[chunkpos]
if not chunk then
send_error(player, "You faction cannot claim any (more) chunk(s).")
return false
elseif chunk == faction.name then
send_error(player, "This chunk already belongs to your faction.")
return false
else

View File

@ -105,13 +105,26 @@ function factions.Faction.remove_player(self, player)
end
function factions.Faction.can_claim_chunk(self, chunkpos)
if factions.chunks[chunkpos] or self.power < factions.power_per_chunk then
local fac = factions.chunks[chunkpos]
if fac then
if factions.factions[fac].power < 0. and self.power >= factions.power_per_chunk then
return true
else
return false
end
elseif self.power < factions.power_per_chunk then
return false
end
return true
end
function factions.Faction.claim_chunk(self, chunkpos)
-- check if claiming over other faction's territory
local otherfac = factions.chunks[chunkpos]
if otherfac then
local faction = factions.factions[otherfac]
faction:unclaim_chunk(chunkpos)
end
factions.chunks[chunkpos] = self.name
self.land[chunkpos] = true
self:decrease_power(factions.power_per_chunk)