Logo
~Sockets~
~Examples~
~Contact~


MobFactory Class Reference

Contains/spawns mobiles/npcs. More...

#include <MobFactory.h>

Collaboration diagram for MobFactory:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 MobFactory (SmallHandler &w)
 ~MobFactory ()
void Spawn ()
void RandomAction ()
void ShowNamesAt (SmallSocket *, int x, int y, const std::string &="")
SmallHandlerHandler ()
size_t NumberOfMobs ()

Private Types

typedef std::vector< MOB * > mob_v

Private Attributes

SmallHandlerm_handler
mob_v m_mobs
string_v m_name_beg
string_v m_name_end

Classes

struct  MOB
 Mobile/NPC properties struct. More...

Detailed Description

Contains/spawns mobiles/npcs.

Definition at line 30 of file MobFactory.h.


Member Typedef Documentation

typedef std::vector<MOB *> MobFactory::mob_v [private]

Definition at line 46 of file MobFactory.h.


Constructor & Destructor Documentation

MobFactory::MobFactory ( SmallHandler w  ) 

Definition at line 29 of file MobFactory.cpp.

References m_name_beg, m_name_end, and Spawn().

00030 :m_handler(w)
00031 {
00032         m_name_beg.push_back( "naz" );
00033         m_name_beg.push_back( "mor" );
00034         m_name_beg.push_back( "gnar" );
00035         m_name_beg.push_back( "aahr" );
00036         m_name_beg.push_back( "more" );
00037         m_name_beg.push_back( "dark" );
00038         m_name_beg.push_back( "bam" );
00039         m_name_beg.push_back( "raab" );
00040         m_name_beg.push_back( "rake" );
00041         m_name_beg.push_back( "lor" );
00042         m_name_beg.push_back( "smur" );
00043 
00044         m_name_end.push_back( "guz" );
00045         m_name_end.push_back( "kill" );
00046         m_name_end.push_back( "gul" );
00047         m_name_end.push_back( "gok" );
00048         m_name_end.push_back( "tan" );
00049         m_name_end.push_back( "tok" );
00050         m_name_end.push_back( "bul" );
00051         m_name_end.push_back( "zod" );
00052         m_name_end.push_back( "zed" );
00053         m_name_end.push_back( "dor" );
00054         m_name_end.push_back( "grim" );
00055         m_name_end.push_back( "yohn" );
00056         m_name_end.push_back( "fan" );
00057 
00058         Spawn();
00059 }

MobFactory::~MobFactory (  ) 

Definition at line 62 of file MobFactory.cpp.

References m_mobs.

00063 {
00064         for (mob_v::iterator it = m_mobs.begin(); it != m_mobs.end(); it++)
00065         {
00066                 MOB *p = *it;
00067                 delete p;
00068         }
00069 }


Member Function Documentation

void MobFactory::Spawn (  ) 

Definition at line 72 of file MobFactory.cpp.

References World::GetRandomLocation(), SmallHandler::GetWorld(), Handler(), m_handler, m_mobs, m_name_beg, and m_name_end.

Referenced by MobFactory(), and SmallHandler::SecTick().

00073 {
00074         int x;
00075         int y;
00076         std::string loc;
00077         std::string name;
00078 
00079         m_handler.GetWorld().GetRandomLocation(x,y,loc);
00080 
00081         name = m_name_beg[random() % m_name_beg.size()] +
00082                m_name_end[random() % m_name_end.size()];
00083         name[0] = name[0] - 32;
00084         {
00085                 std::string str;
00086                 str = name + " enters the world\n";
00087                 static_cast<SmallHandler&>(Handler()).Event(x,y,str);
00088         }
00089         MOB *p = new MOB(m_handler,x,y,name);
00090         m_mobs.push_back(p);
00091 }

void MobFactory::RandomAction (  ) 

Definition at line 94 of file MobFactory.cpp.

References m_mobs.

Referenced by SmallHandler::SecTick().

00095 {
00096         MOB *p = m_mobs[random() % m_mobs.size()];
00097         switch(random() % 10)
00098         {
00099         case 0:
00100                 p -> Create();
00101                 break;
00102         default:
00103                 p -> Move();
00104                 break;
00105         }
00106 }

void MobFactory::ShowNamesAt ( SmallSocket ,
int  x,
int  y,
const std::string &  = "" 
)

Definition at line 205 of file MobFactory.cpp.

References m_mobs.

Referenced by SmallHandler::ShowCell().

00206 {
00207         for (mob_v::iterator it = m_mobs.begin(); it != m_mobs.end(); it++)
00208         {
00209                 MOB *m = *it;
00210                 if (m -> m_x == x && m -> m_y == y)
00211                 {
00212                         p -> Send("  " + prefix + m -> m_name + "\n");
00213                 }
00214         }
00215 }

SmallHandler& MobFactory::Handler (  )  [inline]

Definition at line 54 of file MobFactory.h.

References m_handler.

Referenced by Spawn().

00054 { return m_handler; }

size_t MobFactory::NumberOfMobs (  )  [inline]

Definition at line 55 of file MobFactory.h.

References m_mobs.

Referenced by SmallHandler::ShowStatus().

00055 { return m_mobs.size(); }


Member Data Documentation

Definition at line 58 of file MobFactory.h.

Referenced by Handler(), and Spawn().

Definition at line 59 of file MobFactory.h.

Referenced by NumberOfMobs(), RandomAction(), ShowNamesAt(), Spawn(), and ~MobFactory().

Definition at line 60 of file MobFactory.h.

Referenced by MobFactory(), and Spawn().

Definition at line 61 of file MobFactory.h.

Referenced by MobFactory(), and Spawn().


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