Logo
~Sockets~
~Examples~
~Contact~


SmallHandler Class Reference

Small mud socket handler controller class. More...

#include <SmallHandler.h>

Collaboration diagram for SmallHandler:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 SmallHandler ()
 ~SmallHandler ()
void Who (SmallSocket *)
void ShowCell (SmallSocket *)
void SecTick (time_t)
WorldGetWorld ()
PlayerFactoryGetPlayerF ()
item_vGetItems (int x, int y)
void ShowStatus (SmallSocket *)
void MergeItem (item_v &x, ITEM *y)
void Event (int x, int y, const std::string &, SmallSocket *=NULL, bool=false)
void Load ()

Private Attributes

World m_world
MobFactory m_mob
PlayerFactory m_pf
ipersist_v m_persist
ItemFactory m_itemf

Detailed Description

Small mud socket handler controller class.

Definition at line 34 of file SmallHandler.h.


Constructor & Destructor Documentation

SmallHandler::SmallHandler (  ) 

Definition at line 27 of file SmallHandler.cpp.

References m_persist, and m_pf.

00028 :SocketHandler()
00029 ,m_world(*this)
00030 ,m_mob(*this)
00031 ,m_itemf(*this)
00032 {
00033         m_persist.push_back(&m_pf);
00034 }

SmallHandler::~SmallHandler (  ) 

Definition at line 37 of file SmallHandler.cpp.

00038 {
00039 }


Member Function Documentation

void SmallHandler::Who ( SmallSocket  ) 

Definition at line 42 of file SmallHandler.cpp.

00043 {
00044         for (socket_m::iterator it = m_sockets.begin(); it != m_sockets.end(); it++)
00045         {
00046                 Socket *p0 = (*it).second;
00047                 SmallSocket *p = dynamic_cast<SmallSocket *>(p0);
00048                 if (p)
00049                 {
00050                         p2 -> Send(p -> GetName() + "\n");
00051                 }
00052         }
00053 }

void SmallHandler::ShowCell ( SmallSocket  ) 

Definition at line 75 of file SmallHandler.cpp.

References World::GetAt(), m_itemf, m_mob, m_world, ItemFactory::ShowNamesAt(), and MobFactory::ShowNamesAt().

00076 {
00077         int x = p -> GetX();
00078         int y = p -> GetY();
00079         std::string name;
00080         bool n,s,e,w;
00081         m_world.GetAt(x,y,name,n,s,e,w);
00082         p -> Send(name + "\n");
00083         m_mob.ShowNamesAt(p,x,y,"Here is ");
00084         m_itemf.ShowNamesAt(p,x,y,"You see ");
00085 /*
00086         if (n && m_world.FindAt(x,y - 1,name))
00087         {
00088                 p -> Send("To the north you see... " + name + "\n");
00089                 m_mob.ShowNamesAt(p,x,y - 1);
00090                 m_itemf.ShowNamesAt(p,x,y - 1);
00091         }
00092         if (s && m_world.FindAt(x,y + 1,name))
00093         {
00094                 p -> Send("To the south you see... " + name + "\n");
00095                 m_mob.ShowNamesAt(p,x,y + 1);
00096                 m_itemf.ShowNamesAt(p,x,y + 1);
00097         }
00098         if (e && m_world.FindAt(x + 1,y,name))
00099         {
00100                 p -> Send("To the east you see... " + name + "\n");
00101                 m_mob.ShowNamesAt(p,x + 1,y);
00102                 m_itemf.ShowNamesAt(p,x + 1,y);
00103         }
00104         if (w && m_world.FindAt(x - 1,y,name))
00105         {
00106                 p -> Send("To the west you see... " + name + "\n");
00107                 m_mob.ShowNamesAt(p,x - 1,y);
00108                 m_itemf.ShowNamesAt(p,x - 1,y);
00109         }
00110 */
00111         std::string str = "Exits:&W";
00112         str += n ? " N" : "";
00113         str += s ? " S" : "";
00114         str += e ? " E" : "";
00115         str += w ? " W" : "";
00116         p -> Send( str + "&n\n");
00117 }

void SmallHandler::SecTick ( time_t   ) 

Definition at line 56 of file SmallHandler.cpp.

References m_itemf, m_mob, MobFactory::RandomAction(), MobFactory::Spawn(), and ItemFactory::Spawn().

Referenced by main().

00057 {
00058         if (random() % 5 == 0)
00059         {
00060                 m_itemf.Spawn();
00061         }
00062         else
00063         if (random() % 120 == 0)
00064         {
00065                 m_mob.Spawn();
00066         }
00067         else
00068         if (random() % 5 == 0)
00069         {
00070                 m_mob.RandomAction();
00071         }
00072 }

World& SmallHandler::GetWorld (  )  [inline]

Definition at line 44 of file SmallHandler.h.

References m_world.

Referenced by MobFactory::MOB::Create(), MobFactory::MOB::Move(), MobFactory::Spawn(), and ItemFactory::Spawn().

00044 { return m_world; }

PlayerFactory& SmallHandler::GetPlayerF (  )  [inline]

Definition at line 45 of file SmallHandler.h.

References m_pf.

00045 { return m_pf; }

item_v& SmallHandler::GetItems ( int  x,
int  y 
) [inline]

Definition at line 46 of file SmallHandler.h.

References ItemFactory::GetItems(), and m_itemf.

00046 { return m_itemf.GetItems(x,y); }

void SmallHandler::ShowStatus ( SmallSocket  ) 

Definition at line 148 of file SmallHandler.cpp.

References m_itemf, m_mob, m_world, World::NumberOfCells(), ItemFactory::NumberOfItems(), and MobFactory::NumberOfMobs().

00149 {
00150         sendto -> Send("Number of rooms : &R" + Utility::l2string(m_world.NumberOfCells()) + "&n\n");
00151         sendto -> Send("Number of mobs  : &G" + Utility::l2string(m_mob.NumberOfMobs()) + "&n\n");
00152         sendto -> Send("Number of items : &B" + Utility::l2string(m_itemf.NumberOfItems()) + "&n\n");
00153 }

void SmallHandler::MergeItem ( item_v x,
ITEM y 
) [inline]

Definition at line 48 of file SmallHandler.h.

References m_itemf, and ItemFactory::Merge().

00048 { m_itemf.Merge(x,y); }

void SmallHandler::Event ( int  x,
int  y,
const std::string &  ,
SmallSocket = NULL,
bool  = false 
)

Definition at line 120 of file SmallHandler.cpp.

Referenced by ItemFactory::Spawn().

00121 {
00122         for (socket_m::iterator it = m_sockets.begin(); it != m_sockets.end(); it++)
00123         {
00124                 Socket *p0 = (*it).second;
00125                 SmallSocket *p = dynamic_cast<SmallSocket *>(p0);
00126                 if (p && p != from)
00127                 {
00128                         if (bAll || p -> IsAt(x,y))
00129                         {
00130                                 p -> Send("\n" + line);
00131                                 p -> SendPrompt();
00132                         }
00133                 }
00134         }
00135 }

void SmallHandler::Load (  ) 

Definition at line 138 of file SmallHandler.cpp.

References m_persist.

Referenced by main().

00139 {
00140         for (ipersist_v::iterator it = m_persist.begin(); it != m_persist.end(); it++)
00141         {
00142                 IPersist *p = *it;
00143                 p -> Load();
00144         }
00145 }


Member Data Documentation

Definition at line 55 of file SmallHandler.h.

Referenced by GetWorld(), ShowCell(), and ShowStatus().

Definition at line 56 of file SmallHandler.h.

Referenced by SecTick(), ShowCell(), and ShowStatus().

Definition at line 57 of file SmallHandler.h.

Referenced by GetPlayerF(), and SmallHandler().

Definition at line 58 of file SmallHandler.h.

Referenced by Load(), and SmallHandler().

Definition at line 59 of file SmallHandler.h.

Referenced by GetItems(), MergeItem(), SecTick(), ShowCell(), and ShowStatus().


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