Enhanced doxygen comments

This commit is contained in:
shamoanjac 2016-08-12 11:16:43 +02:00
parent be791384bd
commit 9931060c71
1 changed files with 67 additions and 7 deletions

View File

@ -4,10 +4,10 @@
-- License WTFPL -- License WTFPL
-- --
--! @file factions.lua --! @file factions.lua
--! @brief factions core file containing datastorage --! @brief factions core file
--! @copyright Sapier --! @copyright Sapier, agrecascino, shamoanjac
--! @author Sapier --! @author Sapier, agrecascino, shamoanjac
--! @date 2013-05-08 --! @date 2016-08-12
-- --
-- Contact sapier a t gmx net -- Contact sapier a t gmx net
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
@ -32,6 +32,7 @@ factions.power_per_chunk = .5
--------------------- ---------------------
--! @brief returns whether a faction can be created or not (allows for implementation of blacklists and the like) --! @brief returns whether a faction can be created or not (allows for implementation of blacklists and the like)
--! @param name String containing the faction's name
factions.can_create_faction = function(name) factions.can_create_faction = function(name)
if factions.factions[name] then if factions.factions[name] then
return false return false
@ -52,24 +53,53 @@ util = {
factions.Faction.__index = factions.Faction factions.Faction.__index = factions.Faction
-- Faction permissions:
--
-- disband: disband the faction
-- claim: (un)claim chunks
-- playerslist: invite/kick players and open/close the faction
-- build: dig and place nodes
-- description: set the faction's description
-- ranks: create and delete ranks
-- spawn: set the faction's spawn
-- banner: set the faction's banner
-- promote: set a player's rank
function factions.Faction:new(faction) function factions.Faction:new(faction)
faction = { faction = {
--! @brief power of a faction (needed for chunk claiming)
power = 0., power = 0.,
--! @brief maximum power of a faction
maxpower = 0.,
--! @brief list of player names
players = {}, players = {},
--! @brief table of ranks/permissions
ranks = {["leader"] = {"disband", "claim", "playerslist", "build", "description", "ranks", "spawn", "banner", "promote"}, ranks = {["leader"] = {"disband", "claim", "playerslist", "build", "description", "ranks", "spawn", "banner", "promote"},
["moderator"] = {"claim", "playerslist", "build", "spawn"}, ["moderator"] = {"claim", "playerslist", "build", "spawn"},
["member"] = {"build"} ["member"] = {"build"}
}, },
--! @brief name of the leader
leader = nil, leader = nil,
--! @brief default joining rank for new members
default_rank = "member", default_rank = "member",
--! @brief default rank assigned to the leader
default_leader_rank = "leader", default_leader_rank = "leader",
--! @brief faction's description string
description = "Default faction description.", description = "Default faction description.",
--! @brief list of players currently invited (can join with /f join)
invited_players = {}, invited_players = {},
--! @brief table of claimed chunks (keys are chunkpos strings)
land = {}, land = {},
--! @brief table of allies
allies = {}, allies = {},
--! @brief table of enemies
enemies = {}, enemies = {},
--! @brief table of chunks/factions that are under attack
attacked_chunks = {}, attacked_chunks = {},
--! @brief whether faction is closed or open (boolean)
join_free = false, join_free = false,
--! @brief banner texture string
banner = "bg_white.png", banner = "bg_white.png",
} or faction } or faction
setmetatable(faction, self) setmetatable(faction, self)
@ -77,6 +107,7 @@ function factions.Faction:new(faction)
end end
--! @brief create a new empty faction
factions.new_faction = function(name) factions.new_faction = function(name)
local faction = factions.Faction:new(nil) local faction = factions.Faction:new(nil)
faction.name = name faction.name = name
@ -110,6 +141,8 @@ function factions.Faction.remove_player(self, player)
factions.save() factions.save()
end end
--! @param chunkpos position of the wanted chunk
--! @return whether this faction can claim a chunkpos
function factions.Faction.can_claim_chunk(self, chunkpos) function factions.Faction.can_claim_chunk(self, chunkpos)
local fac = factions.chunks[chunkpos] local fac = factions.chunks[chunkpos]
if fac then if fac then
@ -124,6 +157,7 @@ function factions.Faction.can_claim_chunk(self, chunkpos)
return true return true
end end
--! @brief claim a chunk, update power and update global chunks table
function factions.Faction.claim_chunk(self, chunkpos) function factions.Faction.claim_chunk(self, chunkpos)
-- check if claiming over other faction's territory -- check if claiming over other faction's territory
local otherfac = factions.chunks[chunkpos] local otherfac = factions.chunks[chunkpos]
@ -137,6 +171,7 @@ function factions.Faction.claim_chunk(self, chunkpos)
self:on_claim_chunk(chunkpos) self:on_claim_chunk(chunkpos)
factions.save() factions.save()
end end
--! @brief claim a chunk, update power and update global chunks table
function factions.Faction.unclaim_chunk(self, chunkpos) function factions.Faction.unclaim_chunk(self, chunkpos)
factions.chunks[chunkpos] = nil factions.chunks[chunkpos] = nil
self.land[chunkpos] = nil self.land[chunkpos] = nil
@ -144,6 +179,8 @@ function factions.Faction.unclaim_chunk(self, chunkpos)
self:on_unclaim_chunk(chunkpos) self:on_unclaim_chunk(chunkpos)
factions.save() factions.save()
end end
--! @brief disband faction, updates global players and chunks table
function factions.Faction.disband(self) function factions.Faction.disband(self)
for k, _ in pairs(self.players) do -- remove players affiliation for k, _ in pairs(self.players) do -- remove players affiliation
factions.players[k] = nil factions.players[k] = nil
@ -155,12 +192,17 @@ function factions.Faction.disband(self)
factions.factions[self.name] = nil factions.factions[self.name] = nil
factions.save() factions.save()
end end
--! @brief change the faction leader
function factions.Faction.set_leader(self, player) function factions.Faction.set_leader(self, player)
self.leader = player self.leader = player
self.players[player] = self.default_leader_rank self.players[player] = self.default_leader_rank
self:on_new_leader() self:on_new_leader()
factions.save() factions.save()
end end
--! @brief check permissions for a given player
--! @return boolean indicating permissions. Players not in faction always receive false
function factions.Faction.has_permission(self, player, permission) function factions.Faction.has_permission(self, player, permission)
local p = self.players[player] local p = self.players[player]
if not p then if not p then
@ -179,27 +221,32 @@ function factions.Faction.set_description(self, new)
self:on_change_description() self:on_change_description()
factions.save() factions.save()
end end
--! @brief places player in invite list
function factions.Faction.invite_player(self, player) function factions.Faction.invite_player(self, player)
self.invited_players[player] = true self.invited_players[player] = true
self:on_player_invited(player) self:on_player_invited(player)
factions.save() factions.save()
end end
--! @brief removes player from invite list (can no longer join via /f join)
function factions.Faction.revoke_invite(self, player) function factions.Faction.revoke_invite(self, player)
self.invited_players[player] = nil self.invited_players[player] = nil
self:on_revoke_invite(player) self:on_revoke_invite(player)
factions.save() factions.save()
end end
function factions.Faction.is_invited(self, player) --! @brief set faction openness
return table.contains(self.invited_players, player)
end
function factions.Faction.toggle_join_free(self, bool) function factions.Faction.toggle_join_free(self, bool)
self.join_free = bool self.join_free = bool
self:on_toggle_join_free() self:on_toggle_join_free()
factions.save() factions.save()
end end
--! @return true if a player can use /f join, false otherwise
function factions.Faction.can_join(self, player) function factions.Faction.can_join(self, player)
return self.join_free or self.invited_players[player] return self.join_free or self.invited_players[player]
end end
function factions.Faction.new_alliance(self, faction) function factions.Faction.new_alliance(self, faction)
self.allies[faction] = true self.allies[faction] = true
self:on_new_alliance(faction) self:on_new_alliance(faction)
@ -226,16 +273,26 @@ function factions.Faction.end_enemy(self, faction)
self:on_end_enemy(faction) self:on_end_enemy(faction)
factions.save() factions.save()
end end
--! @brief faction's member will now spawn in a new place
function factions.Faction.set_spawn(self, pos) function factions.Faction.set_spawn(self, pos)
self.spawn = {x=pos.x, y=pos.y, z=pos.z} self.spawn = {x=pos.x, y=pos.y, z=pos.z}
self:on_set_spawn(pos) self:on_set_spawn(pos)
factions.save() factions.save()
end end
--! @brief create a new rank with permissions
--! @param rank the name of the new rank
--! @param rank a list with the permissions of the new rank
function factions.Faction.add_rank(self, rank, perms) function factions.Faction.add_rank(self, rank, perms)
self.ranks[rank] = perms self.ranks[rank] = perms
self:on_add_rank(rank) self:on_add_rank(rank)
factions.save() factions.save()
end end
--! @brief delete a rank and replace it
--! @param rank the name of the rank to be deleted
--! @param newrank the rank given to players who were previously "rank"
function factions.Faction.delete_rank(self, rank, newrank) function factions.Faction.delete_rank(self, rank, newrank)
for player, r in pairs(self.players) do for player, r in pairs(self.players) do
if r == rank then if r == rank then
@ -246,14 +303,17 @@ function factions.Faction.delete_rank(self, rank, newrank)
self:on_delete_rank(rank, newrank) self:on_delete_rank(rank, newrank)
factions.save() factions.save()
end end
--! @param newbanner texture string of the new banner
function factions.Faction.set_banner(self, newbanner) function factions.Faction.set_banner(self, newbanner)
self.banner = newbanner self.banner = newbanner
self:on_new_banner() self:on_new_banner()
end end
--! @brief set a player's rank
function factions.Faction.promote(self, member, rank) function factions.Faction.promote(self, member, rank)
self.players[member] = rank self.players[member] = rank
self:on_promote(member) self:on_promote(member)
end end
--! @brief send a message to all members
function factions.Faction.broadcast(self, msg, sender) function factions.Faction.broadcast(self, msg, sender)
local message = self.name.."> "..msg local message = self.name.."> "..msg
if sender then if sender then