Auto-convert old factions file.
And make diplomacy on by def.
This commit is contained in:
parent
2d89de5927
commit
338686bcbb
|
@ -291,16 +291,9 @@ factions.register_command("create", {
|
||||||
end
|
end
|
||||||
local factionname = args.strings[1]
|
local factionname = args.strings[1]
|
||||||
if factions.can_create_faction(factionname) then
|
if factions.can_create_faction(factionname) then
|
||||||
local listofenemies = {}
|
new_faction = factions.new_faction(factionname, nil)
|
||||||
for i in pairs(factions.factions) do
|
|
||||||
listofenemies[i] = factions.factions[i]
|
|
||||||
end
|
|
||||||
new_faction = factions.new_faction(factionname, nil)
|
|
||||||
new_faction:add_player(player, new_faction.default_leader_rank)
|
new_faction:add_player(player, new_faction.default_leader_rank)
|
||||||
for i in pairs(listofenemies) do
|
factions.start_diplomacy(factionname,new_faction)
|
||||||
new_faction:new_enemy(listofenemies[i].name)
|
|
||||||
listofenemies[i]:new_enemy(new_faction.name)
|
|
||||||
end
|
|
||||||
return true
|
return true
|
||||||
else
|
else
|
||||||
send_error(player, "Faction cannot be created.")
|
send_error(player, "Faction cannot be created.")
|
||||||
|
|
|
@ -19,7 +19,7 @@ factions_config.parcel_size = tonumber(minetest.settings:get("parcel_size")) or
|
||||||
factions_config.protection_depth_height_limit = minetest.settings:get_bool("protection_depth_height_limit") or true
|
factions_config.protection_depth_height_limit = minetest.settings:get_bool("protection_depth_height_limit") or true
|
||||||
factions_config.enable_power_per_player = minetest.settings:get_bool("power_per_playerb") or true
|
factions_config.enable_power_per_player = minetest.settings:get_bool("power_per_playerb") or true
|
||||||
factions_config.attack_parcel = minetest.settings:get_bool("attack_parcel") or false
|
factions_config.attack_parcel = minetest.settings:get_bool("attack_parcel") or false
|
||||||
factions_config.faction_diplomacy = minetest.settings:get_bool("faction_diplomacy") or false
|
factions_config.faction_diplomacy = minetest.settings:get_bool("faction_diplomacy") or true
|
||||||
factions_config.protection_style = minetest.settings:get("protection_style") or "2d"
|
factions_config.protection_style = minetest.settings:get("protection_style") or "2d"
|
||||||
--[[
|
--[[
|
||||||
factions_config.protection_max_depth = -512
|
factions_config.protection_max_depth = -512
|
||||||
|
@ -41,6 +41,6 @@ factions_config.parcel_size = 16
|
||||||
factions_config.protection_depth_height_limit = true
|
factions_config.protection_depth_height_limit = true
|
||||||
factions_config.enable_power_per_player = true
|
factions_config.enable_power_per_player = true
|
||||||
factions_config.attack_parcel = false
|
factions_config.attack_parcel = false
|
||||||
factions_config.faction_diplomacy = false
|
factions_config.faction_diplomacy = true
|
||||||
factions_config.protection_style = "2d"
|
factions_config.protection_style = "2d"
|
||||||
--]]
|
--]]
|
114
factions.lua
114
factions.lua
|
@ -109,8 +109,8 @@ end
|
||||||
|
|
||||||
|
|
||||||
--! @brief create a new empty faction
|
--! @brief create a new empty faction
|
||||||
factions.new_faction = function(name)
|
function factions.new_faction(name)
|
||||||
local faction = factions.Faction:new(nil)
|
local faction = factions.Faction:new(nil)
|
||||||
faction.name = name
|
faction.name = name
|
||||||
factions.factions[name] = faction
|
factions.factions[name] = faction
|
||||||
faction:on_create()
|
faction:on_create()
|
||||||
|
@ -122,6 +122,15 @@ factions.new_faction = function(name)
|
||||||
return faction
|
return faction
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function factions.start_diplomacy(name,faction)
|
||||||
|
for i in pairs(factions.factions) do
|
||||||
|
if i ~= name and not (faction.neutral[i] or faction.allies[i] or faction.enemies[i]) then
|
||||||
|
faction:new_enemy(factions.factions[i].name)
|
||||||
|
factions.factions[i]:new_enemy(faction.name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function factions.Faction.increase_power(self, power)
|
function factions.Faction.increase_power(self, power)
|
||||||
self.power = self.power + power
|
self.power = self.power + power
|
||||||
if self.power > self.maxpower - self.usedpower then
|
if self.power > self.maxpower - self.usedpower then
|
||||||
|
@ -175,6 +184,25 @@ function factions.Faction.decrease_usedpower(self, power)
|
||||||
updateHudPower(minetest.get_player_by_name(i),self)
|
updateHudPower(minetest.get_player_by_name(i),self)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
-- power-per-players only.
|
||||||
|
function factions.Faction.check_power(self)
|
||||||
|
if factions_config.enable_power_per_player then
|
||||||
|
for player,unused in pairs(self.players) do
|
||||||
|
local ip = factions_ip.player_ips[player]
|
||||||
|
local notsame = true
|
||||||
|
for i,k in pairs(self.players) do
|
||||||
|
local other_ip = factions_ip.player_ips[k]
|
||||||
|
if other_ip == ip then
|
||||||
|
notsame = false
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if notsame then
|
||||||
|
self:increase_maxpower(factions_config.powermax_per_player)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function factions.Faction.count_land(self)
|
function factions.Faction.count_land(self)
|
||||||
local count = 0.
|
local count = 0.
|
||||||
|
@ -785,11 +813,21 @@ end
|
||||||
--! @return true/false
|
--! @return true/false
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
function factions.load()
|
function factions.load()
|
||||||
local file,error = io.open(factions_worldid .. "/" .. "factions.conf","r")
|
local filename = "factions.conf"
|
||||||
|
local file,error = io.open(factions_worldid .. "/" .. filename,"r")
|
||||||
|
|
||||||
if file ~= nil then
|
if file ~= nil then
|
||||||
local raw_data = file:read("*a")
|
local raw_data = file:read("*a")
|
||||||
factions.factions = minetest.deserialize(raw_data)
|
factions.factions = minetest.deserialize(raw_data)
|
||||||
|
if factions.is_old_file(factions.factions) then
|
||||||
|
if factions.convert(filename) then
|
||||||
|
minetest.after(5,
|
||||||
|
function()
|
||||||
|
minetest.chat_send_all("Factions successfully converted.")
|
||||||
|
end)
|
||||||
|
factions.save()
|
||||||
|
end
|
||||||
|
end
|
||||||
for facname, faction in pairs(factions.factions) do
|
for facname, faction in pairs(factions.factions) do
|
||||||
minetest.log("action", facname..","..faction.name)
|
minetest.log("action", facname..","..faction.name)
|
||||||
for player, rank in pairs(faction.players) do
|
for player, rank in pairs(faction.players) do
|
||||||
|
@ -800,7 +838,6 @@ function factions.load()
|
||||||
factions.parcels[parcelpos] = facname
|
factions.parcels[parcelpos] = facname
|
||||||
end
|
end
|
||||||
setmetatable(faction, factions.Faction)
|
setmetatable(faction, factions.Faction)
|
||||||
-- compatiblity and later additions
|
|
||||||
if not faction.maxpower or faction.maxpower <= 0. then
|
if not faction.maxpower or faction.maxpower <= 0. then
|
||||||
faction.maxpower = faction.power
|
faction.maxpower = faction.power
|
||||||
if faction.power < 0. then
|
if faction.power < 0. then
|
||||||
|
@ -832,6 +869,36 @@ function factions.load()
|
||||||
factions_ip.load()
|
factions_ip.load()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function factions.is_old_file(oldfactions)
|
||||||
|
local tempfaction = factions.Faction:new(nil)
|
||||||
|
local pass = false
|
||||||
|
for facname, faction in pairs(oldfactions) do
|
||||||
|
for ni, nl in pairs(tempfaction) do
|
||||||
|
pass = false
|
||||||
|
for key, value in pairs(faction) do
|
||||||
|
if key == ni then
|
||||||
|
pass = true
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if not pass then
|
||||||
|
tempfaction = nil
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- Only check one faction to save time.
|
||||||
|
if not pass then
|
||||||
|
tempfaction = nil
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
tempfaction = nil
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
tempfaction = nil
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
function factions.convert(filename)
|
function factions.convert(filename)
|
||||||
local file, error = io.open(factions_worldid .. "/" .. filename, "r")
|
local file, error = io.open(factions_worldid .. "/" .. filename, "r")
|
||||||
if not file then
|
if not file then
|
||||||
|
@ -840,30 +907,21 @@ function factions.convert(filename)
|
||||||
end
|
end
|
||||||
local raw_data = file:read("*a")
|
local raw_data = file:read("*a")
|
||||||
local data = minetest.deserialize(raw_data)
|
local data = minetest.deserialize(raw_data)
|
||||||
local factionsmod = data.factionsmod
|
for facname,faction in pairs(data) do
|
||||||
local objects = data.objects
|
local newfac = factions.new_faction(facname)
|
||||||
for faction, attrs in pairs(factionsmod) do
|
for oi, ol in pairs(faction) do
|
||||||
local newfac = factions.new_faction(faction)
|
if newfac[oi] then
|
||||||
newfac:add_player(attrs.owner, "leader")
|
newfac[oi] = ol
|
||||||
for player, _ in pairs(attrs.adminlist) do
|
end
|
||||||
if not newfac.players[player] then
|
end
|
||||||
newfac:add_player(player, "moderator")
|
for player, unused in pairs(newfac.players) do
|
||||||
end
|
factions.players[player] = newfac.name
|
||||||
end
|
end
|
||||||
for player, _ in pairs(attrs.invitations) do
|
for land, unused in pairs(newfac.land) do
|
||||||
newfac:invite_player(player)
|
factions.parcels[land] = newfac.name
|
||||||
end
|
end
|
||||||
for i in ipairs(attrs.parcel) do
|
factions.start_diplomacy(facname,newfac)
|
||||||
local parcelpos = table.concat(attrs.parcel[i],",")
|
newfac:check_power()
|
||||||
newfac:claim_parcel(parcelpos)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
for player, attrs in pairs(objects) do
|
|
||||||
local facname = attrs.factionsmod
|
|
||||||
local faction = factions.factions[facname]
|
|
||||||
if faction then
|
|
||||||
faction:add_player(player)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
|
@ -40,7 +40,7 @@ power_per_playerb (Enable power-per-player) bool true
|
||||||
# Enable or disabled factions_config.attack_parcel function.
|
# Enable or disabled factions_config.attack_parcel function.
|
||||||
factions_config.attack_parcel (Enable attack parcel) bool false
|
factions_config.attack_parcel (Enable attack parcel) bool false
|
||||||
# Enable or disabled faction diplomacy.
|
# Enable or disabled faction diplomacy.
|
||||||
faction_diplomacy (Enable faction diplomacy) bool false
|
faction_diplomacy (Enable faction diplomacy) bool true
|
||||||
# Enable or disabled the max depth and height limit for a parcel
|
# Enable or disabled the max depth and height limit for a parcel
|
||||||
protection_depth_height_limit (Enable protection depth height limit) bool true
|
protection_depth_height_limit (Enable protection depth height limit) bool true
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user