Planeshift

psguildinfo.h

Go to the documentation of this file.
00001 /*
00002  * psguildinfo.h
00003  *
00004  * Copyright (C) 2003 Atomic Blue ([email protected], http://www.atomicblue.org)
00005  *
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation (version 2 of the License)
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017  *
00018  */
00019 
00020 
00021 
00022 #ifndef __PSGUILDINFO_H__
00023 #define __PSGUILDINFO_H__
00024 //=============================================================================
00025 // Crystal Space Includes
00026 //=============================================================================
00027 #include <csutil/ref.h>
00028 #include <csutil/refarr.h>
00029 #include <csutil/refcount.h>
00030 #include <csutil/weakreferenced.h>
00031 
00032 //=============================================================================
00033 // Project Includes
00034 //=============================================================================
00035 #include "util/psconst.h"
00036 
00037 #include "rpgrules/psmoney.h"
00038 
00039 //=============================================================================
00040 // Local Includes
00041 //=============================================================================
00042 
00043 
00044 class psCharacter;
00045 class iResultRow;
00046 
00061 enum GUILD_PRIVILEGE
00062 {
00063     RIGHTS_VIEW_CHAT         = 1,      
00064 
00065     RIGHTS_CHAT              = 2,      
00066 
00067     RIGHTS_INVITE            = 4,      
00068 
00069     RIGHTS_REMOVE            = 8,      
00070 
00071     RIGHTS_PROMOTE           = 16,     
00072 
00073     RIGHTS_EDIT_LEVEL         = 32,    
00074 
00075     RIGHTS_EDIT_POINTS        = 64,    
00076 
00077     RIGHTS_EDIT_GUILD         = 128,   
00078 
00079 
00080     RIGHTS_EDIT_PUBLIC        = 256,   
00081 
00082 
00083     RIGHTS_EDIT_PRIVATE       = 512,   
00084 
00085 
00086     RIGHTS_VIEW_CHAT_ALLIANCE = 1024,  
00087 
00088     RIGHTS_CHAT_ALLIANCE      = 2048,  
00089 
00090     RIGHTS_USE_BANK           = 4096   
00091 };
00092 
00099 struct psGuildLevel
00100 {
00101     csString title;      
00102     int      level;      
00103     int      privileges; 
00104 
00111     inline bool HasRights(GUILD_PRIVILEGE rights) const
00112     {
00113         return (level == MAX_GUILD_LEVEL) || (privileges & rights);
00114     }
00115 };
00116 
00117 //------------------------------------------------------------------------------
00118 
00124 class psGuildMember
00125 {
00126 public:
00127     PID char_id;                
00128     csString name;              
00129     psCharacter*  character;    
00130     psGuildLevel* guildlevel;   
00131     int guild_points;           
00132     csString public_notes;      
00133     csString private_notes;     
00134     csString last_login;        
00135     int privileges;             
00136     int removedPrivileges;      
00137 
00145     bool HasRights(GUILD_PRIVILEGE rights)
00146     {
00147         return (guildlevel->HasRights(rights) && !(removedPrivileges & rights)) || (privileges & rights);
00148     }
00149 };
00150 
00151 //------------------------------------------------------------------------------
00152 
00159 class psGuildInfo
00160 {
00161 protected:
00162     int id;                          
00163     csString name;                   
00164     PID founder;                     
00165     int karma_points;                
00166     csString web_page;               
00167     csString motd;                   
00168     bool secret;                     
00169     psMoney bankMoney;               
00170     int max_guild_points;            
00171     csTicks lastNameChange;          
00172     int alliance;                    
00173     csArray<psGuildMember*> members; 
00174     csArray<psGuildLevel*>  levels;  
00175     csArray<int> guild_war_with_id;  
00176     friend class psGuildAlliance;
00177 
00178 public:
00185     psGuildInfo();
00186 
00196     psGuildInfo(csString name, PID founder);
00197 
00201     ~psGuildInfo();
00202 
00212     bool Load(unsigned int id);
00213 
00223     bool Load(const csString &name);
00224 
00234     bool Load(iResultRow &row);
00235 
00244     bool InsertNew();
00245 
00256     bool RemoveGuild();
00257 
00266     void Connect(psCharacter* player);
00267 
00277     void Disconnect(psCharacter* player);
00278 
00288     void UpdateLastLogin(psCharacter* player);
00289 
00298     psGuildMember* FindMember(const char* name) const;
00299 
00308     psGuildMember* FindMember(PID char_id) const;
00309 
00319     psGuildMember* FindLeader() const;
00320 
00329     psGuildLevel* FindLevel(int level) const;
00330 
00339     bool MeetsMinimumRequirements() const;
00340 
00354     bool AddNewMember(psCharacter* player, int level=1);
00355 
00366     bool RemoveMember(psGuildMember* target);
00367 
00379     bool RenameLevel(int level, const char* levelname);
00380 
00393     bool SetPrivilege(int level, GUILD_PRIVILEGE privilege, bool on);
00394 
00410     bool SetMemberPrivilege(psGuildMember* member, GUILD_PRIVILEGE privilege, bool on);
00411 
00422     bool UpdateMemberLevel(psGuildMember* target, int level);
00423 
00430     inline void AdjustMoney(const psMoney &money, bool unused)
00431     {
00432         unused = unused;
00433         AdjustMoney(money);
00434     }
00435 
00442     void AdjustMoney(const psMoney &money);
00443 
00449     inline psMoney &GetBankMoney()
00450     {
00451         return bankMoney;
00452     }
00453 
00459     void SaveBankMoney();
00460 
00471     unsigned int MinutesUntilUserChangeName() const;
00472 
00478     inline const csString &GetName() const
00479     {
00480         return name;
00481     }
00482 
00490     bool SetMaxMemberPoints(int points);
00491 
00497     inline int GetMaxMemberPoints() const
00498     {
00499         return max_guild_points;
00500     }
00501 
00514     bool SetMemberPoints(psGuildMember* member, int points);
00515 
00528     bool SetMemberNotes(psGuildMember* member, const csString &notes, bool isPublic);
00529 
00539     bool SetName(csString guildName);
00540 
00546     inline const csString &GetWebPage() const
00547     {
00548         return web_page;
00549     }
00550 
00560     bool SetWebPage(const csString &web_page);
00561 
00571     bool SetSecret(bool secretGuild);
00572 
00578     inline bool IsSecret() const
00579     {
00580         return secret;
00581     }
00582 
00588     inline const csString &GetMOTD() const
00589     {
00590         return motd;
00591     }
00592 
00601     bool SetMOTD(const csString &str);
00602 
00608     inline int GetKarmaPoints() const
00609     {
00610         return karma_points;
00611     }
00612 
00621     bool SetKarmaPoints(int n_karma_points);
00622 
00631     void AddGuildWar(psGuildInfo* other);
00632 
00642     bool IsGuildWarActive(psGuildInfo* other);
00643 
00650     void RemoveGuildWar(psGuildInfo* other);
00651 
00657     inline int GetAllianceID() const
00658     {
00659         return alliance;
00660     }
00661 
00667     inline int GetID() const
00668     {
00669         return id;
00670     }
00671 
00677     inline csArray<psGuildLevel*>::ConstIterator GetLevelIterator() const
00678     {
00679         return levels.GetIterator();
00680     }
00681 
00687     inline csArray<psGuildLevel*>::Iterator GetLevelIterator()
00688     {
00689         return levels.GetIterator();
00690     }
00691 
00697     inline csArray<psGuildMember*>::ConstIterator GetMemberIterator() const
00698     {
00699         return members.GetIterator();
00700     }
00701 
00707     inline csArray<psGuildMember*>::Iterator GetMemberIterator()
00708     {
00709         return members.GetIterator();
00710     }
00711 
00717     inline size_t GetMemberCount() const
00718     {
00719         return members.GetSize();
00720     }
00721 };
00722 
00723 //-----------------------------------------------------------------------------
00724 
00731 class psGuildAlliance : public csRefCount
00732 {
00733 public:
00734 
00738     psGuildAlliance();
00739 
00747     psGuildAlliance(const csString &n_name);
00748 
00758     bool InsertNew();
00759 
00768     bool RemoveAlliance();
00769 
00783     bool Load(int id);
00784 
00796     bool AddNewMember(psGuildInfo* member);
00797 
00806     bool CheckMembership(psGuildInfo* member) const;
00807 
00818     bool RemoveMember(psGuildInfo* member);
00819 
00825     inline size_t GetMemberCount() const
00826     {
00827         return members.GetSize();
00828     }
00829 
00838     psGuildInfo* GetMember(int memberNum);
00839 
00845     inline int GetID() const
00846     {
00847         return id;
00848     }
00849 
00855     inline const csString &GetName() const
00856     {
00857         return name;
00858     }
00859 
00865     inline psGuildInfo* GetLeader() const
00866     {
00867         return leader;
00868     }
00869 
00880     bool SetLeader(psGuildInfo* newLeader);
00881 
00882     static csString lastError;       
00883 
00884 protected:
00885     int id;                          
00886     csString name;                   
00887     psGuildInfo* leader;             
00888     csArray<psGuildInfo*> members;   
00889 };
00890 
00893 #endif
00894