From 69ff206590dc52efe783a00184bf19cde834632e Mon Sep 17 00:00:00 2001 From: shamoanjac Date: Tue, 9 Aug 2016 04:39:40 +0200 Subject: [PATCH] Underpowered factions' chunks can now be claimed --- chatcommands.lua | 13 +++++++------ factions.lua | 15 ++++++++++++++- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/chatcommands.lua b/chatcommands.lua index 53557bf..fa794d9 100644 --- a/chatcommands.lua +++ b/chatcommands.lua @@ -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 diff --git a/factions.lua b/factions.lua index 0807f58..020e3f2 100644 --- a/factions.lua +++ b/factions.lua @@ -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)