Logo
~Sockets~
~Examples~
~Contact~


MobFactory::MOB Struct Reference

Mobile/NPC properties struct. More...

Collaboration diagram for MobFactory::MOB:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 MOB (SmallHandler &handler, int x, int y, const std::string &name)
void Move ()
void Create ()
void SetNewPos (int, int)

Public Attributes

SmallHandlerm_handler
int m_x
int m_y
std::string m_name

Detailed Description

Mobile/NPC properties struct.

Definition at line 33 of file MobFactory.h.


Constructor & Destructor Documentation

MobFactory::MOB::MOB ( SmallHandler handler,
int  x,
int  y,
const std::string &  name 
) [inline]

Definition at line 35 of file MobFactory.h.

00035                                                                              : m_handler(handler),m_x(x),m_y(y),m_name(name) {
00036                 }


Member Function Documentation

void MobFactory::MOB::Move (  ) 

Definition at line 109 of file MobFactory.cpp.

References World::FindAt(), World::GetAt(), SmallHandler::GetWorld(), World::Handler(), m_handler, m_name, m_x, m_y, and SetNewPos().

00110 {
00111         int ny_x = m_x;
00112         int ny_y = m_y;
00113         std::string dir;
00114         std::string rdir;
00115         std::string str;
00116         bool n,s,e,w;
00117         bool open = false;
00118         m_handler.GetWorld().GetAt(m_x,m_y,str,n,s,e,w);
00119         switch(random() % 4)
00120         {
00121         case 0: // n
00122                 ny_y--;
00123                 dir = "north";
00124                 rdir = "south";
00125                 open = n;
00126                 break;
00127         case 1: // s
00128                 ny_y++;
00129                 dir = "south";
00130                 rdir = "north";
00131                 open = s;
00132                 break;
00133         case 2: // e
00134                 ny_x++;
00135                 dir = "east";
00136                 rdir = "west";
00137                 open = e;
00138                 break;
00139         case 3: // w
00140                 ny_x--;
00141                 dir = "west";
00142                 rdir = "east";
00143                 open = w;
00144                 break;
00145         }
00146         if (open && m_handler.GetWorld().FindAt(ny_x,ny_y,str))
00147         {
00148                 static_cast<SmallHandler&>(m_handler.GetWorld().Handler()).Event(m_x,m_y,m_name + " leaves " + dir + "\n");
00149                 SetNewPos(ny_x,ny_y);
00150                 static_cast<SmallHandler&>(m_handler.GetWorld().Handler()).Event(m_x,m_y,m_name + " enters from the " + rdir + "\n");
00151         }
00152 }

void MobFactory::MOB::Create (  ) 

Definition at line 155 of file MobFactory.cpp.

References World::AddAt(), World::FindAt(), SmallHandler::GetWorld(), World::Handler(), m_handler, m_name, m_x, m_y, World::Open(), and SetNewPos().

00156 {
00157         int ny_x = m_x;
00158         int ny_y = m_y;
00159         std::string dir;
00160         std::string rdir;
00161         switch(random() % 4)
00162         {
00163         case 0: // n
00164                 ny_y--;
00165                 dir = "north";
00166                 rdir = "south";
00167                 break;
00168         case 1: // s
00169                 ny_y++;
00170                 dir = "south";
00171                 rdir = "north";
00172                 break;
00173         case 2: // e
00174                 ny_x++;
00175                 dir = "east";
00176                 rdir = "west";
00177                 break;
00178         case 3: // w
00179                 ny_x--;
00180                 dir = "west";
00181                 rdir = "east";
00182                 break;
00183         }
00184         std::string str;
00185         if (!m_handler.GetWorld().FindAt(ny_x,ny_y,str))
00186         {
00187                 str = "A small cell (created by " + m_name + ")";
00188                 m_handler.GetWorld().AddAt(ny_x,ny_y,str);
00189                 m_handler.GetWorld().Open(m_x,m_y,dir);
00190                 m_handler.GetWorld().Open(ny_x,ny_y,rdir);
00191                 static_cast<SmallHandler&>(m_handler.GetWorld().Handler()).Event(m_x,m_y,m_name + " creates a cell to the " + dir + "\n");
00192                 static_cast<SmallHandler&>(m_handler.GetWorld().Handler()).Event(m_x,m_y,m_name + " leaves " + dir + "\n");
00193                 SetNewPos(ny_x,ny_y);
00194         }
00195 }

void MobFactory::MOB::SetNewPos ( int  ,
int   
)

Definition at line 198 of file MobFactory.cpp.

References m_x, and m_y.

Referenced by Create(), and Move().

00199 {
00200         m_x = x;
00201         m_y = y;
00202 }


Member Data Documentation

Definition at line 41 of file MobFactory.h.

Referenced by Create(), and Move().

Definition at line 42 of file MobFactory.h.

Referenced by Create(), Move(), and SetNewPos().

Definition at line 43 of file MobFactory.h.

Referenced by Create(), Move(), and SetNewPos().

Definition at line 44 of file MobFactory.h.

Referenced by Create(), and Move().


The documentation for this struct 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