- Main Page
- Classes
- Files

- File List
- File Members

# E:/uas2/Server/Allegiance.h

Go to the documentation of this file.

    00001 /*
    00002 * This file is part of UAS2.
    00003 *
    00004 * UAS2 is free software; you can redistribute it and/or modify
    00005 * it under the terms of the GNU General Public License as published by
    00006 * the Free Software Foundation; either version 2 of the License, or
    00007 * (at your option) any later version.
    00008 *
    00009 * UAS2 is distributed in the hope that it will be useful,
    00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
    00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00012 * GNU General Public License for more details.
    00013
    00014 * You should have received a copy of the GNU General Public License
    00015 * along with UASv1; if not, write to the Free Software
    00016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    00017 */
    00018
    00023 #ifndef __ALLEGIANCES_H
    00024 #define __ALLEGIANCES_H
    00025
    00026 #pragma warning(disable:4786)   //warning: identifier was truncated to '255' characters in the browser information
    00027 #include <map>
    00028 //#include <vector>
    00029
    00030 #include "Avatar.h"
    00031 #include "Shared.h"
    00032
    00033 struct Member
    00034 {
    00035         // allegiance table
    00036     DWORD               m_dwGUID;
    00037     std::string m_szName;
    00038         bool            m_online;
    00039     BYTE                m_bGender;
    00040         BYTE            m_bRace;
    00041         BYTE            m_bRank;
    00042         WORD            m_wLeadership;
    00043         WORD            m_wLoyalty;
    00044         DWORD           m_dwPatron;
    00045         DWORD           m_dwVassals[MAX_VASSALS];       // vassals determined at run-time
    00046         DWORD           m_dwFollowers;  // number of personal followers
    00047         float           m_avgIGSworn;   // average in-game sworn time of vassals
    00048         float           m_avgRTSworn;   // average real-time sworn time of vassals
    00049         DWORD           m_passupXP;             // experience generated
    00050         DWORD           m_pendingXP;    // experience pending since previous login
    00051
    00052         // avatar table
    00053         DWORD           m_dwLevel;
    00054         ULONG           m_timeBirth;
    00055         ULONG           m_timeRLSwear;  // sworn time, real-life
    00056         ULONG           m_timeIGTotal;  // total time in-game (character age)
    00057         ULONG           m_timeIGSwear;  // sworn time, in-game (character age)
    00058 };
    00059
    00060 class cAllegiance
    00061 {
    00062         friend class cMasterServer;
    00063
    00064     public:
    00065         cAllegiance();
    00066         ~cAllegiance();
    00067
    00068                 void            LoadAllegiance          (DWORD ID, DWORD leaderGUID, char name[40], char MOTD[255]);
    00069         void            CreateAllegiance        ( DWORD leaderGUID );
    00070         void            Disband                         ( );
    00071
    00072                 typedef         std::map<DWORD, Member> MemberList;
    00073
    00074                 Member*         FindMember      ( DWORD memberGUID ) { return &this->members.find(memberGUID)->second; }
    00075
    00076                 static cAllegiance*     GetAllegianceByID               ( DWORD AllegianceID );
    00077         DWORD           GetID()                         { return m_ID; }
    00078         DWORD           GetLeader()                     { return m_LeaderGUID; }
    00079                 DWORD           GetSize()                       { return m_Size; }
    00080                 std::string GetName()                   { return m_Name.c_str(); }
    00081         std::string GetMOTD()                   { return m_MOTD.c_str(); }
    00082
    00083         static void             SetLeader                                       ( DWORD allegianceID, DWORD leaderGUID );
    00084                 static bool             AddNewMember                            ( DWORD dwAvatarGUID, DWORD dwPatronGUID, DWORD oldAllegianceID, DWORD newAllegianceID );
    00085                 static bool             AddRemMember                            ( Member* member, DWORD oldAllegianceID, DWORD newAllegianceID );
    00086                 static bool             RemMember                                       ( DWORD dwRemMemberGUID, DWORD oldAllegianceID, bool isDisbanding=false );
    00087                 static bool             SwitchMonarchAndVassals         ( Member* member, DWORD oldAllegianceID, DWORD newAllegianceID );
    00088                 static bool             SwitchNonMonarchVassals         ( Member* member, DWORD oldAllegianceID, DWORD newAllegianceID );
    00089
    00090                 void            InsertMember            ( Member member, DWORD dwPatronGUID );
    00091                 void            EraseMember                     ( Member* member );
    00092                 void            EraseMember                     ( DWORD dwMemberGUID );
    00093
    00094                 bool            AddDirectVassal         ( Member* memPatron, Member* memVassal );
    00095                 bool            AddDirectVassal         ( DWORD dwPatronGUID, DWORD dwVassalGUID );
    00096                 bool            RemDirectVassal         ( Member* memVassal );
    00097                 bool            RemDirectVassal         ( DWORD dwVassalGUID );
    00098
    00099                 void            SetMOTD                         ( std::string motd );
    00100
    00101                 std::string GetMemberName               ( Member* member )              { return member->m_szName.c_str(); }
    00102                 std::string GetMemberName               ( DWORD dwMemberGUID )  { Member* member = FindMember(dwMemberGUID); return member->m_szName.c_str(); }
    00103
    00104                 int                     GetVassalCount          ( Member* member );
    00105                 int                     GetVassalCount          ( DWORD dwMemberGUID );
    00106                 int                     GetFollowerCount        ( Member* member );
    00107                 int                     GetFollowerCount        ( DWORD dwMemberGUID );
    00108
    00109                 static void     UpdatePlayerAllegID                     ( Member* member, DWORD newAllegianceID );
    00110                 static void     UpdatePlayerAllegID                     ( DWORD dwPlayerGUID, DWORD newAllegianceID );
    00111                 void            UpdateFollowers                         ( Member* member, int numFollowers );
    00112                 void            UpdateFollowers                         ( DWORD dwMemberGUID, int numFollowers );
    00113                 void            UpdateRank                                      ( Member* member );
    00114                 void            UpdateRank                                      ( DWORD dwMemberGUID );
    00115
    00116                 void            VassalPassupXP                                          ( Member* memVassal, UINT64 experience, bool isGrandVassal=false );
    00117                 void            UpdateGeneratedXP                                       ( Member* member, UINT64 experience );
    00118                 void            UpdateEarnedXP                                          ( Member* member, UINT64 experience );
    00119                 UINT64          CalcVassalGeneratedXP                           ( Member* memVassal, UINT64 experience, bool isGrandPatron=false );
    00120                 UINT64          CalcPatronReceivedXP                            ( Member* memPatron, UINT64 experience, bool isGrandPatron=false );
    00121                 void            UpdateAverageSwornTimeOfVassals         ( Member* memPatron );
    00122                 float           CalcVassalFactor                                        ( int numVassals );
    00123
    00124                 cMessage        GetAllegianceInfo       ( DWORD avatarGUID );
    00125
    00126                 static void     LoadMembersFromDB       ( cAllegiance* aAllegiance );
    00127
    00128                 static void             UpdateAvatarAllegIDDB           ( DWORD dwGUID, DWORD allegianceID );
    00129                 static void             UpdateMemberAllegIDDB           ( DWORD dwGUID, DWORD allegianceID );
    00130                 static void             UpdateAvatarRecordDB            ( DWORD dwAvatarGUID );
    00131                 static void             AddMemberRecordDB                       ( DWORD allegianceID, DWORD dwAvatarGUID, DWORD dwPatronGUID );
    00132                 static void             DeleteMemberRecordDB            ( DWORD allegianceID, DWORD dwMemberGUID );
    00133                 static void             UpdateMemberRecordDB            ( Member* member );
    00134                 static void             UpdateMemberXPPassupDB          ( DWORD memberGUID, UINT64 passedXP );
    00135                 static void             UpdateMemberXPPendingDB         ( DWORD memberGUID, UINT64 pendingXP );
    00136                 static void             UpdateMemberFollowersDB         ( DWORD memberGUID, int numFollowers );
    00137                 static void             UpdateMemberRankDB                      ( DWORD memberGUID, int rank );
    00138                 static void             UpdateMemberPatronDB            ( DWORD memberGUID, DWORD patronGUID );
    00139
    00140                 MemberList      members;
    00141
    00142     protected:
    00143         DWORD           m_ID;
    00144         std::string     m_Name;
    00145         DWORD           m_LeaderGUID;
    00146         std::string     m_MOTD;
    00147                 int                     m_Size;                 // calculated at run-time
    00148                 ULONG           m_CreationTime;
    00149 };
    00150
    00151 #endif  // #ifndef __ALLEGIANCES_H