Logo
~Sockets~
~Examples~
~Contact~

Move Class Reference
[Commands]

Movement command base class. More...

#include <Move.h>

Inheritance diagram for Move:

Inheritance graph
[legend]
Collaboration diagram for Move:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 Move (const std::string &x, char y, int loc_x, int loc_y, bool wiz=false)
void move_to (InSocket *from, Chunk &north, int ny_x, int ny_y, bool hide_map)
void try_move (InSocket *from, int ch_x, int ch_y, int ch_z, bool hide_map)
void try_create (InSocket *from, const std::string &line, int ch_x, int ch_y, int ch_z)

Private Attributes

int m_loc_x
int m_loc_y

Detailed Description

Movement command base class.

Definition at line 31 of file Move.h.


Constructor & Destructor Documentation

Move::Move ( const std::string &  x,
char  y,
int  loc_x,
int  loc_y,
bool  wiz = false 
) [inline]

Definition at line 34 of file Move.h.

00034                                                                              : Command(x, y, wiz)
00035         , m_loc_x(loc_x), m_loc_y(loc_y) {}


Member Function Documentation

void Move::move_to ( InSocket from,
Chunk north,
int  ny_x,
int  ny_y,
bool  hide_map 
)

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

Definition at line 29 of file Move.cpp.

References Chunk::Get(), Player::GetArea(), Chunk::GetNum(), Player::IsWizard(), Look::LookMap(), m_loc_x, m_loc_y, Player::SetChunk(), Player::SetChunkX(), Player::SetChunkY(), Player::SetFacing(), and Look::Show().

Referenced by try_move().

00030 {
00031         Database& db = from -> GetDatabase();
00032         Player pl(db, from -> GetAccountName());
00033         Area area(db, pl.GetArea());
00034         Terrain t(db, area, north.Get(ny_x, ny_y));
00035         if ((t.Exists() && !t.IsImpassable()) || pl.IsWizard())
00036         {
00037                 pl.SetChunk(north.GetNum());
00038                 pl.SetChunkX(ny_x);
00039                 pl.SetChunkY(ny_y);
00041                 if (m_loc_y < 0)
00042                         pl.SetFacing(1);
00043                 if (m_loc_y > 0)
00044                         pl.SetFacing(2);
00045                 if (m_loc_x > 0)
00046                         pl.SetFacing(3);
00047                 if (m_loc_x < 0)
00048                         pl.SetFacing(4);
00049                 if (!hide_map)
00050                         Look::LookMap(from);
00051                 Look::Show(from);
00052                 from -> SetMoveEvent(0, 1000);
00053         }
00054         else
00055         {
00056                 from -> Send("Impassable terrain ahead.\n");
00057                 from -> CancelMoves();
00058         }
00059         from -> SetPrompt();
00060 }

void Move::try_move ( InSocket from,
int  ch_x,
int  ch_y,
int  ch_z,
bool  hide_map 
)

Definition at line 63 of file Move.cpp.

References Player::GetArea(), Player::GetChunk(), Player::GetChunkX(), Player::GetChunkY(), Player::IsWizard(), m_loc_x, m_loc_y, and move_to().

Referenced by West::Execute(), Up::Execute(), South::Execute(), North::Execute(), East::Execute(), and Down::Execute().

00064 {
00065         Database& db = from -> GetDatabase();
00066         Player pl(db, from -> GetAccountName());
00067         Area area(db, pl.GetArea());
00068         Chunk chunk(db, area, pl.GetChunk());
00069 
00070         int ny_x = pl.GetChunkX() + m_loc_x;
00071         int ny_y = pl.GetChunkY() + m_loc_y;
00072         if (!ch_z && ny_x >= 0 && ny_x < area.GetWidth() && ny_y >= 0 && ny_y < area.GetHeight())
00073         {
00074                 move_to(from, chunk, ny_x, ny_y, hide_map);
00075         }
00076         else
00077         {
00078                 if (ch_z && !pl.IsWizard()) // up/down check
00079                 {
00080                         Terrain t(db, area, chunk.Get(ny_x, ny_y));
00081                         if ((ch_z == 1 && t.GetChar() != 'U') || (ch_z == -1 && t.GetChar() != 'D'))
00082                         {
00083                                 from -> Send("No exit that way.\n");
00084                                 from -> CancelMoves();
00085                                 from -> SetPrompt();
00086                                 return;
00087                         }
00088                 }
00089                 Chunk north(db, area, chunk.GetX() + ch_x, chunk.GetY() + ch_y, chunk.GetZ() + ch_z);
00090                 if (north.Exists())
00091                 {
00092                         while (ny_x < 0)
00093                                 ny_x += area.GetWidth();
00094                         while (ny_y < 0)
00095                                 ny_y += area.GetHeight();
00096                         while (ny_x >= area.GetWidth())
00097                                 ny_x -= area.GetWidth();
00098                         while (ny_y >= area.GetHeight())
00099                                 ny_y -= area.GetHeight();
00100                         move_to(from, north, ny_x, ny_y, hide_map);
00101                 }
00102                 else
00103                 if (pl.IsWizard())
00104                 {
00105                         from -> SetPrompt(this, 0, "Create a new chunk of land (y/N)? ");
00106                         from -> CancelMoves();
00107                 }
00108                 else
00109                 {
00110                         from -> Send("End of the world.\n");
00111                         from -> CancelMoves();
00112                         from -> SetPrompt();
00113                 }
00114         }
00115 }

void Move::try_create ( InSocket from,
const std::string &  line,
int  ch_x,
int  ch_y,
int  ch_z 
)

Definition at line 118 of file Move.cpp.

References Player::GetArea(), Player::GetChunk(), Player::GetChunkX(), Player::GetChunkY(), Look::LookMap(), m_loc_x, m_loc_y, Player::SetChunk(), Player::SetChunkX(), Player::SetChunkY(), and Look::Show().

Referenced by West::OnLine(), Up::OnLine(), South::OnLine(), North::OnLine(), East::OnLine(), and Down::OnLine().

00119 {
00120         Database& db = from -> GetDatabase();
00121         Player pl(from -> GetDatabase(), from -> GetAccountName());
00122         Area area(db, pl.GetArea());
00123         Chunk chunk(db, area, pl.GetChunk());
00124 
00125         int ny_x = pl.GetChunkX() + m_loc_x;
00126         int ny_y = pl.GetChunkY() + m_loc_y;
00127         while (ny_x < 0)
00128                 ny_x += area.GetWidth();
00129         while (ny_y < 0)
00130                 ny_y += area.GetHeight();
00131         while (ny_x >= area.GetWidth())
00132                 ny_x -= area.GetWidth();
00133         while (ny_y >= area.GetHeight())
00134                 ny_y -= area.GetHeight();
00135         if (line.size() && (line[0] == 'y' || line[0] == 'Y'))
00136         {
00137                 Chunk north(db, area, chunk.GetX() + ch_x, chunk.GetY() + ch_y, chunk.GetZ() + ch_z);
00138                 if (!north.Exists())
00139                 {
00140                         north.Init(from, chunk.GetX() + ch_x, chunk.GetY() + ch_y, chunk.GetZ() + ch_z, ' ');
00141                         north.Save();
00142                 }
00143                 if (ch_z == 1) // create up
00144                 {
00145                         chunk.Set(ny_x, ny_y, 'U');
00146                         north.Set(ny_x, ny_y, 'D');
00147                         chunk.Save();
00148                         north.Save();
00149                 }
00150                 else
00151                 if (ch_z == -1) // create down
00152                 {
00153                         chunk.Set(ny_x, ny_y, 'D');
00154                         north.Set(ny_x, ny_y, 'U');
00155                         chunk.Save();
00156                         north.Save();
00157                 }
00158                 pl.SetChunk(north.GetNum());
00159                 pl.SetChunkX(ny_x);
00160                 pl.SetChunkY(ny_y);
00161                 Look::LookMap(from);
00162                 Look::Show(from);
00163         }
00164         from -> SetPrompt();
00165 }


Member Data Documentation

int Move::m_loc_x [private]

Definition at line 42 of file Move.h.

Referenced by move_to(), try_create(), and try_move().

int Move::m_loc_y [private]

Definition at line 43 of file Move.h.

Referenced by move_to(), try_create(), and try_move().


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