Google
Web alhem.net

Map Class Reference

#include <Map.h>

List of all members.

Public Member Functions

 Map ()
 ~Map ()
void SetMax (int, int)
int GetMaxX ()
int GetMaxY ()
double GetNearest (double x, double y)
void SetWraps (bool x=true)
bool GetWraps ()
void AddObject (MapObject *p, bool delete_by_map=true)
void IncreaseTime (long usec)
void SpawnRandom ()
size_t objects_in_map ()

Private Attributes

int m_max_x
int m_max_y
bool m_wraps
mapobject_v m_objects


Detailed Description

Definition at line 7 of file Map.h.


Constructor & Destructor Documentation

Map::Map (  ) 

Definition at line 9 of file Map.cpp.

00010 :m_max_x(0)
00011 ,m_max_y(0)
00012 ,m_wraps(false)
00013 {
00014 }

Map::~Map (  ) 

Definition at line 17 of file Map.cpp.

References m_objects.

00018 {
00019         for (mapobject_v::iterator it = m_objects.begin(); it != m_objects.end(); it++)
00020         {
00021                 MapObject *p = *it;
00022                 if (p -> DeleteByMap())
00023                 {
00024                         delete p;
00025                 }
00026         }
00027 }


Member Function Documentation

void Map::SetMax ( int  ,
int   
)

Definition at line 30 of file Map.cpp.

References m_max_x, and m_max_y.

Referenced by main().

00031 {
00032         m_max_x = x;
00033         m_max_y = y;
00034 }

int Map::GetMaxX (  )  [inline]

Definition at line 14 of file Map.h.

References m_max_x.

00014 { return m_max_x; }

int Map::GetMaxY (  )  [inline]

Definition at line 15 of file Map.h.

References m_max_y.

00015 { return m_max_y; }

double Map::GetNearest ( double  x,
double  y 
)

Definition at line 85 of file Map.cpp.

References m_max_x, m_max_y, and m_objects.

Referenced by SpawnRandom().

00086 {
00087         double dist = m_max_x * m_max_y;
00088         for (mapobject_v::iterator it = m_objects.begin(); it != m_objects.end(); it++)
00089         {
00090                 MapObject *p = *it;
00091                 double x1 = p -> GetX() - x;
00092                 double x2 = x - p -> GetX();
00093                 if (x1 < m_max_x)
00094                         x1 += m_max_x;
00095                 if (x2 < m_max_x)
00096                         x2 += m_max_x;
00097                 double y1 = p -> GetY() - y;
00098                 double y2 = y - p -> GetY();
00099                 if (y1 < m_max_y)
00100                         y1 += m_max_y;
00101                 if (y2 < m_max_y)
00102                         y2 += m_max_y;
00103                 double xx = (x1 < x2) ? x1 : x2;
00104                 double yy = (y1 < y2) ? y1 : y2;
00105                 double d = sqrt(xx * xx + yy * yy);
00106                 if (d < dist)
00107                         dist = d;
00108         }
00109         return dist;
00110 }

void Map::SetWraps ( bool  x = true  )  [inline]

Definition at line 17 of file Map.h.

References m_wraps.

00017 { m_wraps = x; }

bool Map::GetWraps (  )  [inline]

Definition at line 18 of file Map.h.

References m_wraps.

00018 { return m_wraps; }

void Map::AddObject ( MapObject p,
bool  delete_by_map = true 
)

Definition at line 37 of file Map.cpp.

References m_objects.

Referenced by RowoHandler::InjectRobot(), and main().

00038 {
00039         m_objects.push_back(p);
00040         p -> SetDeleteByMap(delete_by_map);
00041         printf("New object added - new map size is %d object%s\n",m_objects.size(),(m_objects.size() == 1) ? "" : "s");
00042 }

void Map::IncreaseTime ( long  usec  ) 

Definition at line 45 of file Map.cpp.

References m_objects.

Referenced by main().

00046 {
00047         for (mapobject_v::iterator it = m_objects.begin(); it != m_objects.end(); it++)
00048         {
00049                 MapObject *p0 = *it;
00050                 Robot *p = dynamic_cast<Robot *>(p0);
00051                 if (p)
00052                 {
00053                         p -> Tick( usec );
00054                         p -> Call("Main");
00055                 }
00056         }
00057 }

void Map::SpawnRandom (  ) 

Definition at line 60 of file Map.cpp.

References GetNearest(), m_max_x, m_max_y, and m_objects.

Referenced by main().

00061 {
00062         MapObject *p = NULL;
00063         switch (random() % 2)
00064         {
00065         case 0: // powerup
00066                 p = new Powerup( *this );
00067                 break;
00068         case 1: // item
00069                 p = new Item( *this );
00070                 break;
00071         }
00072         p -> SetPos(random() % m_max_x,random() % m_max_y);
00073         double dist = GetNearest(p -> GetX(),p -> GetY());
00074         if (dist > 20)
00075         {
00076                 m_objects.push_back( p );
00077         }
00078         else
00079         {
00080                 delete p;
00081         }
00082 }

size_t Map::objects_in_map (  )  [inline]

Definition at line 24 of file Map.h.

References m_objects.

Referenced by main().

00024 { return m_objects.size(); }


Member Data Documentation

int Map::m_max_x [private]

Definition at line 27 of file Map.h.

Referenced by GetMaxX(), GetNearest(), SetMax(), and SpawnRandom().

int Map::m_max_y [private]

Definition at line 28 of file Map.h.

Referenced by GetMaxY(), GetNearest(), SetMax(), and SpawnRandom().

bool Map::m_wraps [private]

Definition at line 29 of file Map.h.

Referenced by GetWraps(), and SetWraps().

mapobject_v Map::m_objects [private]

Definition at line 30 of file Map.h.

Referenced by AddObject(), GetNearest(), IncreaseTime(), objects_in_map(), SpawnRandom(), and ~Map().


The documentation for this class was generated from the following files:
Generated for Robot World by doxygen 1.3.6

Page, code, and content Copyright (C) 2004 by Anders Hedström