Logo
~Sockets~
~Examples~
~Contact~

Look Class Reference
[Commands]

Command: look around. More...

#include <Look.h>

Inheritance diagram for Look:

Inheritance graph
[legend]
Collaboration diagram for Look:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 Look ()
void Execute (InSocket *, const std::string &params, Parse &)
 Execute command.
std::string Category ()
 Get command category.

Static Public Member Functions

static void LookMap (InSocket *)
static void Show (InSocket *)

Static Private Member Functions

static void WizMap (InSocket *)
static void NormalMap (InSocket *)
static void getmap (Database &db, Area &area, Chunk &chunk, int x, int y, std::string &mapstr, std::string &colorstr, bool color)
static bool check_facing (int x, int y, int facing)

Detailed Description

Command: look around.

Definition at line 32 of file Look.h.


Constructor & Destructor Documentation

Look::Look (  )  [inline]

Definition at line 35 of file Look.h.

00035 : Command("look", 'l') {}


Member Function Documentation

void Look::Execute ( InSocket ,
const std::string &  arg,
Parse &   
) [virtual]

Execute command.

Implements Command.

Definition at line 31 of file Look.cpp.

References LookMap(), and Show().

00032 {
00033         LookMap(from);
00034         Show(from);
00035         from -> SetPrompt();
00036 }

void Look::LookMap ( InSocket  )  [static]

Definition at line 39 of file Look.cpp.

References Player::IsWizard(), Player::IsWizView(), NormalMap(), and WizMap().

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

00040 {
00041         Player pl(from -> GetDatabase(),from -> GetAccountName());
00042         if (pl.IsWizView() && pl.IsWizard())
00043         {
00044                 WizMap(from);
00045         }
00046         else
00047         {
00048                 NormalMap(from);
00049         }
00050 }

void Look::Show ( InSocket  )  [static]

Definition at line 239 of file Look.cpp.

References Player::GetArea(), Player::GetChunk(), Player::GetChunkX(), and Player::GetChunkY().

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

00240 {
00241         Database& db = from -> GetDatabase();
00242         Player pl(db, from -> GetAccountName());
00243         Area area(db, pl.GetArea());
00244         Chunk chunk(db, area, pl.GetChunk());
00245         Terrain t(db, area, chunk.Get(pl.GetChunkX(), pl.GetChunkY()));
00246         if (t.Exists())
00247                 from -> Send(t.GetColor() + t.GetName() + "&n\n");
00248         chunk.Show(from);
00249 }

std::string Look::Category (  )  [inline, virtual]

Get command category.

Implements Command.

Definition at line 42 of file Look.h.

00042 { return "Navigation"; }

void Look::WizMap ( InSocket  )  [static, private]

Definition at line 53 of file Look.cpp.

References Player::GetArea(), Player::GetChunk(), Player::GetChunkX(), and Player::GetChunkY().

Referenced by LookMap().

00054 {
00055         Database& db = from -> GetDatabase();
00056         Player pl(db, from -> GetAccountName());
00057         Area area(db, pl.GetArea());
00058         Chunk chunk(db, area, pl.GetChunk());
00059 
00060         std::string mapstr;
00061         std::string colorstr;
00062         for (int y = 0; y < area.GetHeight(); y++)
00063         {
00064                 for (int x = 0; x < area.GetWidth(); x++)
00065                 {
00066                         if (x == pl.GetChunkX() && y == pl.GetChunkY())
00067                         {
00068                                 mapstr += "&nA";
00069                                 colorstr = "&n";
00070                         }
00071                         else
00072                         {
00073                                 Terrain t(db, area, chunk.Get(x, y));
00074                                 if (t.Exists())
00075                                 {
00076                                         if (t.GetColor() != colorstr)
00077                                         {
00078                                                 mapstr += t.GetColor();
00079                                                 colorstr = t.GetColor();
00080                                         }
00081                                         mapstr += t.GetChar();
00082                                 }
00083                                 else
00084                                 {
00085                                         mapstr += ' ';
00086                                 }
00087                         }
00088                 }
00089                 mapstr += "&n\n";
00090                 colorstr = "&n";
00091         }
00092         from -> Send(mapstr);
00093         //Show(from);
00094 }

void Look::NormalMap ( InSocket  )  [static, private]

Definition at line 97 of file Look.cpp.

References check_facing(), Player::GetArea(), Player::GetChunk(), Player::GetChunkX(), Player::GetChunkY(), Player::GetCoordX(), Player::GetCoordY(), Player::GetFacing(), getmap(), and Player::SightRange().

Referenced by LookMap().

00098 {
00099         Database& db = from -> GetDatabase();
00100         Player pl(db, from -> GetAccountName());
00101         Area area(db, pl.GetArea());
00102         Chunk chunk(db, area, pl.GetChunk());
00103         int cx = pl.GetChunkX();
00104         int cy = pl.GetChunkY();
00105         double sightrange = pl.SightRange();
00106         int xr = (int)(3 * sightrange / 2) + 1;
00107         int yr = (int)sightrange + 1;
00108 
00109         long xcoord = pl.GetCoordX(area, chunk);
00110         long ycoord = pl.GetCoordY(area, chunk);
00111         Steps st(db, pl, area, chunk.GetZ(), ycoord);
00112         st.AddCoord(xcoord);
00113 
00114         std::string mapstr;
00115         std::string colorstr;
00116 
00117         for (int y = -yr; y <= yr; y++)
00118         {
00119                 for (int x = -xr; x <= xr; x++)
00120                 {
00121                         int xtmp = 2 * x / 3;
00122                         if (sqrt(xtmp * xtmp + y * y) >= sightrange)
00123                         {
00124                                 mapstr += "&n ";
00125                                 colorstr = "&n";
00126                         }
00127                         else
00128                         if (cx + x == pl.GetChunkX() && cy + y == pl.GetChunkY())
00129                         {
00130                                 mapstr += "&nA";
00131                                 colorstr = "&n";
00132                         }
00133                         else
00134                         {
00135                                 bool can_see = check_facing(x, y, pl.GetFacing());
00136                                 getmap(db, area, chunk, cx + x, cy + y, mapstr, colorstr, can_see);
00137                         }
00138                 }
00139                 mapstr += "&n\n";
00140                 colorstr = "&n";
00141         }
00142 
00143         from -> Send(mapstr);
00144         //Show(from);
00145 }

void Look::getmap ( Database &  db,
Area area,
Chunk chunk,
int  x,
int  y,
std::string &  mapstr,
std::string &  colorstr,
bool  color 
) [static, private]

Definition at line 148 of file Look.cpp.

References Chunk::Exists(), Chunk::Get(), Area::GetHeight(), Area::GetWidth(), Chunk::GetX(), Chunk::GetY(), and Chunk::GetZ().

Referenced by NormalMap().

00149 {
00150         if (x >= 0 && x < area.GetWidth() && y >= 0 && y < area.GetHeight())
00151         {
00152                 Terrain t(db, area, chunk.Get(x, y));
00153                 if (t.Exists())
00154                 {
00155                         if (!color)
00156                         {
00157                                 if (colorstr != "&n")
00158                                 {
00159                                         mapstr += "&n";
00160                                         colorstr = "&n";
00161                                 }
00162                         }
00163                         else
00164                         if (t.GetColor() != colorstr)
00165                         {
00166                                 mapstr += t.GetColor();
00167                                 colorstr = t.GetColor();
00168                         }
00169                         mapstr += t.GetChar();
00170                 }
00171                 else
00172                 {
00173                         if (colorstr != "&n")
00174                         {
00175                                 mapstr += "&n";
00176                                 colorstr = "&n";
00177                         }
00178                         mapstr += ' ';
00179                 }
00180         }
00181         else
00182         {
00183                 int chunk_x = chunk.GetX();
00184                 int chunk_y = chunk.GetY();
00185                 int chunk_z = chunk.GetZ();
00186                 while (x < 0)
00187                 {
00188                         chunk_x -= 1; // west
00189                         x += area.GetWidth();
00190                 }
00191                 while (x >= area.GetWidth())
00192                 {
00193                         chunk_x += 1; // east
00194                         x -= area.GetWidth();
00195                 }
00196                 while (y < 0)
00197                 {
00198                         chunk_y += 1; // north
00199                         y += area.GetHeight();
00200                 }
00201                 while (y >= area.GetHeight())
00202                 {
00203                         chunk_y -= 1; // south
00204                         y -= area.GetHeight();
00205                 }
00206                 Chunk cc(db, area, chunk_x, chunk_y, chunk_z);
00207                 Terrain t(db, area, cc.Get(x, y));
00208                 if (cc.Exists() && t.Exists())
00209                 {
00210                         if (!color)
00211                         {
00212                                 if (colorstr != "&n")
00213                                 {
00214                                         mapstr += "&n";
00215                                         colorstr = "&n";
00216                                 }
00217                         }
00218                         else
00219                         if (t.GetColor() != colorstr)
00220                         {
00221                                 mapstr += t.GetColor();
00222                                 colorstr = t.GetColor();
00223                         }
00224                         mapstr += t.GetChar();
00225                 }
00226                 else
00227                 {
00228                         if (colorstr != "&n")
00229                         {
00230                                 mapstr += "&n";
00231                                 colorstr = "&n";
00232                         }
00233                         mapstr += ' ';
00234                 }
00235         }
00236 }

bool Look::check_facing ( int  x,
int  y,
int  facing 
) [static, private]

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

Definition at line 252 of file Look.cpp.

Referenced by NormalMap().

00253 {
00254         if (x > -2 && x < 2 && y > -2 && y < 2)
00255                 return true;
00257         switch (facing)
00258         {
00259         case 1:
00260                 if (y <= 0)
00261                         return true;
00262                 break;
00263         case 2:
00264                 if (y >= 0)
00265                         return true;
00266                 break;
00267         case 3:
00268                 if (x >= 0)
00269                         return true;
00270                 break;
00271         case 4:
00272                 if (x <= 0)
00273                         return true;
00274                 break;
00275         }
00276         return false;
00277 }


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