Logo
~Sockets~
~Examples~
~Contact~

Player Class Reference
[Database]

Database table Player. More...

#include <Player.h>

Inheritance diagram for Player:

Inheritance graph
[legend]
Collaboration diagram for Player:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 Player (Database &, const std::string &name)
 ~Player ()
std::string GetName ()
bool IsWizard ()
std::string GetPasswd ()
std::string GetDisplayName ()
void SetName (const std::string &)
void SetPasswd (const std::string &)
void SetWizard (bool)
void SetDisplayName (const std::string &)
void SetEmail (const std::string &)
long GetArea ()
long GetChunk ()
long GetChunkX ()
long GetChunkY ()
void SetChunkX (int)
void SetChunkY (int)
void SetArea (long)
void SetChunk (long)
long GetNum ()
 Get integer primary key from object.
int GetFacing ()
 1-north, 2-south, 3-east, 4-west
void SetFacing (int)
 1-north, 2-south, 3-east, 4-west
void SetRace (long)
long GetRace ()
void VerifyPos ()
void Save ()
 Save the object in database.
bool Exists ()
 Check if the object already exists in database.
void SetWizView (bool=true)
bool IsWizView ()
long GetCoordX (Area &, Chunk &)
long GetCoordY (Area &, Chunk &)
bool Seen (Area &, long xcoord, long ycoord, int ch_z)
double SightRange ()
void LoadSteps ()

Static Public Member Functions

static db::AccountGetAccount (Database &db, const std::string &name)

Private Attributes

db::Accountm_account

Static Private Attributes

static accounts_t m_accounts

Detailed Description

Database table Player.

Definition at line 37 of file Player.h.


Constructor & Destructor Documentation

Player::Player ( Database &  ,
const std::string &  name 
)

Definition at line 36 of file Player.cpp.

00036                                                  : Object(db)
00037 , m_account(Player::GetAccount(db, name))
00038 {
00039 }

Player::~Player (  ) 

Definition at line 42 of file Player.cpp.

00043 {
00044 }


Member Function Documentation

std::string Player::GetName (  ) 

Definition at line 80 of file Player.cpp.

References m_account.

Referenced by Setcmd::Execute(), and Login::OnLine().

00081 {
00082         return m_account ? m_account -> name: "";
00083 }

bool Player::IsWizard (  ) 

std::string Player::GetPasswd (  ) 

Definition at line 92 of file Player.cpp.

References m_account.

Referenced by Login::OnLine().

00093 {
00094         return m_account -> passwd;
00095 }

std::string Player::GetDisplayName (  ) 

Definition at line 98 of file Player.cpp.

References m_account.

Referenced by Who::Execute(), Quit::Execute(), InSocket::OnDelete(), Login::OnLine(), and FutureHandler::Talk().

00099 {
00100         return m_account -> display_name + "&n";
00101 }

void Player::SetName ( const std::string &   ) 

Definition at line 124 of file Player.cpp.

References m_account.

Referenced by Login::OnLine().

00125 {
00126         m_account -> name = x;
00127 }

void Player::SetPasswd ( const std::string &   ) 

Definition at line 130 of file Player.cpp.

References m_account.

Referenced by Login::OnLine().

00131 {
00132         m_account -> passwd = x;
00133 }

void Player::SetWizard ( bool   ) 

Definition at line 136 of file Player.cpp.

References m_account.

00137 {
00138         m_account -> wizard = x ? 1 : 0;
00139 }

void Player::SetDisplayName ( const std::string &   ) 

Definition at line 142 of file Player.cpp.

References m_account.

Referenced by Setcmd::Execute(), and Login::OnLine().

00143 {
00144         m_account -> display_name = x;
00145 }

void Player::SetEmail ( const std::string &   ) 

Definition at line 148 of file Player.cpp.

References m_account.

00149 {
00150         m_account -> email = x;
00151 }

long Player::GetChunkX (  ) 

long Player::GetChunkY (  ) 

void Player::SetChunkX ( int   ) 

Definition at line 178 of file Player.cpp.

References m_account.

Referenced by Enter::Execute(), Move::move_to(), and Move::try_create().

00179 {
00180         m_account -> chunkx = x;
00181 }

void Player::SetChunkY ( int   ) 

Definition at line 184 of file Player.cpp.

References m_account.

Referenced by Enter::Execute(), Move::move_to(), and Move::try_create().

00185 {
00186         m_account -> chunky = y;
00187 }

void Player::SetArea ( long   ) 

Definition at line 190 of file Player.cpp.

References m_account.

Referenced by Enter::Execute().

00191 {
00192         m_account -> area = x;
00193 }

void Player::SetChunk ( long   ) 

Definition at line 196 of file Player.cpp.

References m_account.

Referenced by Enter::Execute(), Move::move_to(), and Move::try_create().

00197 {
00198         m_account -> chunk = x;
00199 }

long Player::GetNum (  )  [virtual]

Get integer primary key from object.

Implements Object.

Definition at line 202 of file Player.cpp.

References m_account.

Referenced by Steps::GetStep(), Steps::GetSteps(), Chunk::Init(), and LoadSteps().

00203 {
00204         return m_account -> num;
00205 }

int Player::GetFacing (  ) 

1-north, 2-south, 3-east, 4-west

Definition at line 208 of file Player.cpp.

References m_account.

Referenced by Right::Execute(), Left::Execute(), Forward::Execute(), and Look::NormalMap().

00209 {
00210         return m_account -> facing;
00211 }

void Player::SetFacing ( int   ) 

1-north, 2-south, 3-east, 4-west

Definition at line 214 of file Player.cpp.

References m_account.

Referenced by Right::Execute(), Left::Execute(), Forward::Execute(), and Move::move_to().

00215 {
00216         m_account -> facing = x;
00217 }

void Player::SetRace ( long   ) 

Definition at line 340 of file Player.cpp.

References m_account.

Referenced by Login::OnLine().

00341 {
00342         m_account -> race = x;
00343 }

long Player::GetRace (  ) 

Definition at line 346 of file Player.cpp.

References m_account.

Referenced by Login::OnLine().

00347 {
00348         return m_account -> race;
00349 }

void Player::VerifyPos (  ) 

Definition at line 104 of file Player.cpp.

References Area::GetHeight(), Chunk::GetNum(), Area::GetNum(), Area::GetWidth(), m_account, Object::m_db, and Save().

Referenced by Login::OnLine().

00105 {
00106         if (!m_account -> area)
00107         {
00108                 Area area(m_db, "World");
00109                 Chunk chunk(m_db, area, 1000, 1000, 0); // default starting point
00110                 m_account -> area = area.GetNum();
00111                 m_account -> chunk = chunk.GetNum();
00112                 m_account -> chunkx = area.GetWidth() / 2;
00113                 m_account -> chunky = area.GetHeight() / 2;
00114                 m_account -> save();
00115         }
00116         if (!m_account -> facing)
00117         {
00118                 m_account -> facing = 1;
00119                 Save();
00120         }
00121 }

void Player::Save (  )  [virtual]

Save the object in database.

Implements Object.

Definition at line 65 of file Player.cpp.

References m_account.

Referenced by Save::Execute(), Login::OnLine(), and VerifyPos().

00066 {
00067         if (m_account)
00068                 m_account -> save();
00069 }

bool Player::Exists (  )  [virtual]

Check if the object already exists in database.

Returns:
true if the object exists

Implements Object.

Definition at line 72 of file Player.cpp.

References m_account.

Referenced by InSocket::OnDelete().

00073 {
00074         if (m_account && m_account -> num)
00075                 return true;
00076         return false;
00077 }

db::Account * Player::GetAccount ( Database &  db,
const std::string &  name 
) [static]

Definition at line 47 of file Player.cpp.

References m_accounts.

00048 {
00049         db::Account *p = m_accounts[name];
00050         if (p != NULL)
00051                 return p;
00052         p = new db::Account(db, name);
00053         p -> name = name;
00054         if (!p -> num)
00055         {
00056                 Query q(db);
00057                 long nr = q.get_count("select count(*) from account");
00058                 p -> wizard = !nr;
00059         }
00060         m_accounts[name] = p;
00061         return p;
00062 }

void Player::SetWizView ( bool  = true  ) 

Definition at line 220 of file Player.cpp.

References m_account.

Referenced by Setcmd::Execute().

00221 {
00222         m_account -> wizview = x ? 1 : 0;
00223 }

bool Player::IsWizView (  ) 

Definition at line 226 of file Player.cpp.

References m_account.

Referenced by Look::LookMap().

00227 {
00228         return (m_account -> wizview && m_account -> wizard) ? true : false;
00229 }

long Player::GetCoordX ( Area ,
Chunk  
)

Definition at line 232 of file Player.cpp.

References GetChunkX(), Area::GetWidth(), and Chunk::GetX().

Referenced by Look::NormalMap().

00233 {
00234         return chunk.GetX() * area.GetWidth() + GetChunkX();
00235 }

long Player::GetCoordY ( Area ,
Chunk  
)

Definition at line 238 of file Player.cpp.

References GetChunkY(), Area::GetHeight(), and Chunk::GetY().

Referenced by Look::NormalMap().

00239 {
00240         return chunk.GetY() * area.GetHeight() + area.GetHeight() - GetChunkY() - 1;
00241 }

bool Player::Seen ( Area ,
long  xcoord,
long  ycoord,
int  ch_z 
)

Definition at line 244 of file Player.cpp.

References Steps::GetStep(), and SightRange().

Referenced by Map::Execute().

00245 {
00246         for (int y = 0; y < SightRange() + 1; y++)
00247         {
00248                 db::Steps *st;
00249                 if (y)
00250                 {
00251                         st = Steps::GetStep(*this, area, ch_z, ycoord - y);
00252                         if (st)
00253                         {
00254                                 Parse pa(st -> xcoords, ":");
00255                                 std::string tmp = pa.getword();
00256                                 while (tmp.size())
00257                                 {
00258                                         long x = atol(tmp.c_str());
00259                                         long x0 = x - xcoord;
00260                                         long y0 = st -> ycoord - ycoord;
00261                                         long xtmp = 2 * x0 / 3;
00262                                         if (sqrt(xtmp * xtmp + y0 * y0) < SightRange())
00263                                         {
00264                                                 return true;
00265                                         }
00266                                         //
00267                                         tmp = pa.getword();
00268                                 }
00269                         }
00270                         st = Steps::GetStep(*this, area, ch_z, ycoord + y);
00271                         if (st)
00272                         {
00273                                 Parse pa(st -> xcoords, ":");
00274                                 std::string tmp = pa.getword();
00275                                 while (tmp.size())
00276                                 {
00277                                         long x = atol(tmp.c_str());
00278                                         long x0 = x - xcoord;
00279                                         long y0 = st -> ycoord - ycoord;
00280                                         long xtmp = 2 * x0 / 3;
00281                                         if (sqrt(xtmp * xtmp + y0 * y0) < SightRange())
00282                                         {
00283                                                 return true;
00284                                         }
00285                                         //
00286                                         tmp = pa.getword();
00287                                 }
00288                         }
00289                 }
00290                 else
00291                 {
00292                         st = Steps::GetStep(*this, area, ch_z, ycoord);
00293                         if (st)
00294                         {
00295                                 Parse pa(st -> xcoords, ":");
00296                                 std::string tmp = pa.getword();
00297                                 while (tmp.size())
00298                                 {
00299                                         long x = atol(tmp.c_str());
00300                                         long x0 = x - xcoord;
00301                                         long y0 = st -> ycoord - ycoord;
00302                                         long xtmp = 2 * x0 / 3;
00303                                         if (sqrt(xtmp * xtmp + y0 * y0) < SightRange())
00304                                         {
00305                                                 return true;
00306                                         }
00307                                         //
00308                                         tmp = pa.getword();
00309                                 }
00310                         }
00311                 }
00312         }
00313         return false;
00314 }

double Player::SightRange (  ) 

Definition at line 317 of file Player.cpp.

References Race::Exists(), Race::GetSightRange(), m_account, and Object::m_db.

Referenced by Look::NormalMap(), and Seen().

00318 {
00319         Race r(m_db, m_account -> race);
00320         if (r.Exists())
00321                 return r.GetSightRange();
00322         return 3.5;
00323 }

void Player::LoadSteps (  ) 

Definition at line 326 of file Player.cpp.

References GetNum(), and Object::m_db.

Referenced by Login::OnLine().

00327 {
00328         Query q(m_db);
00329         q.get_result("select * from steps where player=" + Utility::l2string(GetNum()));
00330         while (q.fetch_row())
00331         {
00332                 db::Steps st(&m_db, &q);
00333                 Area area(m_db, st.area);
00334                 Steps s(m_db, *this, area, st.zcoord, st.ycoord);
00335         }
00336         q.free_result();
00337 }


Member Data Documentation

accounts_t Player::m_accounts [static, private]

Definition at line 86 of file Player.h.

Referenced by GetAccount().


The documentation for this class was generated from the following files:
Page, code, and content Copyright (C) 2006 by Anders Hedström
Generated on Mon Aug 29 20:21:47 2005 for C++ Sockets by  doxygen 1.4.4