Planeshift
psGuildAlliance Class Reference

A guild alliance between 2+ guilds. More...

#include <psguildinfo.h>

Public Member Functions

bool AddNewMember (psGuildInfo *member)
 Adds a new guild to the alliance. More...
 
bool CheckMembership (psGuildInfo *member) const
 Checks if a guild is in this alliance. More...
 
int GetID () const
 Gets the ID. More...
 
psGuildInfoGetLeader () const
 Gets the leader. More...
 
psGuildInfoGetMember (int memberNum)
 Gets a guild based off its index. More...
 
size_t GetMemberCount () const
 Gets the number of members in this alliance. More...
 
const csString & GetName () const
 Gets the name. More...
 
bool InsertNew ()
 INSERTs alliance data in database. More...
 
bool Load (int id)
 Loads alliance data from database. More...
 
 psGuildAlliance ()
 Basic constructor. More...
 
 psGuildAlliance (const csString &n_name)
 Basic constructor with name parameter. More...
 
bool RemoveAlliance ()
 Removes alliance. More...
 
bool RemoveMember (psGuildInfo *member)
 Removes a guild from the alliance. More...
 
bool SetLeader (psGuildInfo *newLeader)
 Sets a new alliance leader. More...
 

Static Public Attributes

static csString lastError
 When a psGuildAlliance method fails (returns false), this contains a description of the problem. More...
 

Protected Attributes

int id
 The ID of the alliance, used for storing in the DB. More...
 
psGuildInfoleader
 Leader of the alliance, must also be a member. More...
 
csArray< psGuildInfo * > members
 Array of the members of this alliance. More...
 
csString name
 Viewable name of the alliance. More...
 

Detailed Description

A guild alliance between 2+ guilds.

Primary database table : alliances
Secondary database tables: guilds

Definition at line 731 of file psguildinfo.h.

Constructor & Destructor Documentation

psGuildAlliance::psGuildAlliance ( )

Basic constructor.

psGuildAlliance::psGuildAlliance ( const csString &  n_name)

Basic constructor with name parameter.

Used when inserting a new alliance.

Parameters
n_nameSets name

Member Function Documentation

bool psGuildAlliance::AddNewMember ( psGuildInfo member)

Adds a new guild to the alliance.

Returns false if the guild to add is already in the alliance. Also returns false if the DB update fails. Otherwise, the DB is updated and the new guild is added to members.

Parameters
memberThe new guild to add
Returns
True if everything was successful, false if either the update failed or the guild is already part of the alliance.
bool psGuildAlliance::CheckMembership ( psGuildInfo member) const

Checks if a guild is in this alliance.

Checks if the guild is in members.

Parameters
memberThe guild to check
Returns
True if the guild is in the alliance, false if it is not.
int psGuildAlliance::GetID ( ) const
inline

Gets the ID.

Returns
id

Definition at line 845 of file psguildinfo.h.

psGuildInfo* psGuildAlliance::GetLeader ( ) const
inline

Gets the leader.

Returns
leader

Definition at line 865 of file psguildinfo.h.

psGuildInfo* psGuildAlliance::GetMember ( int  memberNum)

Gets a guild based off its index.

Asserts that the index is > 0 and < GetMemberCount().

Parameters
memberNumIndex of the guild to look up
Returns
The member in members with the given index
size_t psGuildAlliance::GetMemberCount ( ) const
inline

Gets the number of members in this alliance.

Returns
The size of members

Definition at line 825 of file psguildinfo.h.

const csString& psGuildAlliance::GetName ( ) const
inline

Gets the name.

Returns
name

Definition at line 855 of file psguildinfo.h.

bool psGuildAlliance::InsertNew ( )

INSERTs alliance data in database.

Uses name to insert alliance into database. No leader will be set.

Todo:
Why not include leader at same time?
Returns
True if successful, false if DB insert failed.
bool psGuildAlliance::Load ( int  id)

Loads alliance data from database.

Uses parameter to overwrite id. Uses id select from the DB the name and leading guild's ID. If select fails, false is returned. The leader guild is then pulled from the cache manager. If it fails, false is returned. All of the members are then selected from the DB based on this alliance's ID sorted by name. Each member is then actually pulled from the cache manager. If any of the members fail, false is returned.

Parameters
idThe ID to pull from the DB
Returns
True if everything was successful, false if an error occurred.
bool psGuildAlliance::RemoveAlliance ( )

Removes alliance.

Deletes alliance data from database and updates psGuildInfo::alliance of members to 0

Returns
True if successful, false if either the update or the delete failed.
bool psGuildAlliance::RemoveMember ( psGuildInfo member)

Removes a guild from the alliance.

Checks to make sure the guild is actually a member of this alliance and that it is not the leader, if both are true then the guild is removed from members.

Parameters
memberThe guild to remove
Returns
True if successful, false if the guild is not a member or is the leader or if the DB update fails.
bool psGuildAlliance::SetLeader ( psGuildInfo newLeader)

Sets a new alliance leader.

Calls CheckMembership with the new leader, then updates the DB and sets leader to the new leader.

Parameters
newLeaderThe guild that will be the new leader
Returns
True if successful, false if CheckMembership fails or the DB update fails.

Member Data Documentation

int psGuildAlliance::id
protected

The ID of the alliance, used for storing in the DB.

Definition at line 885 of file psguildinfo.h.

csString psGuildAlliance::lastError
static

When a psGuildAlliance method fails (returns false), this contains a description of the problem.

Definition at line 882 of file psguildinfo.h.

psGuildInfo* psGuildAlliance::leader
protected

Leader of the alliance, must also be a member.

Definition at line 887 of file psguildinfo.h.

csArray<psGuildInfo*> psGuildAlliance::members
protected

Array of the members of this alliance.

Definition at line 888 of file psguildinfo.h.

csString psGuildAlliance::name
protected

Viewable name of the alliance.

Definition at line 886 of file psguildinfo.h.


The documentation for this class was generated from the following file: