Google
Web alhem.net

Robot Class Reference

#include <Robot.h>

Inheritance diagram for Robot:

Inheritance graph
[legend]
Collaboration diagram for Robot:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 Robot (Map &, const std::string &xmlfile)
 ~Robot ()
bool IsOk ()
mapobject_t GetType ()
long get_property (const std::string &)
void Tick (long usec)
LifePartLife ()
RadarPartRadar ()
TurretPartTurret ()
GunPartGun ()
ShieldsPartShields ()
long get_property (int)
void set_property (int, long)
long call_method (int, stack_v &)
void Call (const std::string &method)
void AddObject (MapObject *)
mapobject_vGetInventory ()
int GetPower ()
int GetPowerLevel ()
int GetMaxPowerLevel ()
void SetMaxPowerLevel (int x)
bool Charging ()
int GetChargeRate ()
void SetChargeRate (int x)
bool UsePower (double units)
int GetCurrentHeading ()
void SetHeading (double x)
double GetTurnRate ()
void SetTurnRate (double x)

Private Attributes

RobotXMLFile m_config
CodeToolm_code
Life m_life
Radar m_radar
Turret m_turret
Gun m_gun
Shields m_shields
mapobject_v m_inventory
double m_power_level
int m_max_power_level
int m_charge_rate
double m_current_heading
double m_set_heading
double m_turn_rate

Detailed Description

Definition at line 17 of file Robot.h.


Constructor & Destructor Documentation

Robot::Robot ( Map ,
const std::string &  xmlfile 
)

Definition at line 7 of file Robot.cpp.

References m_code, and m_config.

00007                                             : MapObject(m)
00008 ,m_config(xmlfile)
00009 ,m_code(NULL)
00010 ,m_life(*this)
00011 ,m_radar(*this)
00012 ,m_turret(*this)
00013 ,m_gun(*this)
00014 ,m_shields(*this)
00015 ,m_power_level(0)
00016 ,m_max_power_level(10000)
00017 ,m_charge_rate(1000)
00018 ,m_current_heading(0)
00019 ,m_set_heading(m_current_heading)
00020 ,m_turn_rate(12)
00021 {
00022         m_code = new CodeTool(m_config);
00023         m_code -> SetRobot( this );
00024 }

Robot::~Robot (  ) 

Definition at line 27 of file Robot.cpp.

References m_code.

00028 {
00029         delete m_code;
00030 }


Member Function Documentation

bool Robot::IsOk (  )  [inline]

XML parsed ok

Definition at line 24 of file Robot.h.

References BaseXMLFile::IsOk(), and m_config.

00024 { return m_config.IsOk(); }

mapobject_t Robot::GetType (  )  [inline, virtual]

Implements MapObject.

Definition at line 26 of file Robot.h.

References MAPOBJECT_ROBOT.

00026 { return MAPOBJECT_ROBOT; }

long Robot::get_property ( const std::string &   )  [virtual]

Implements MapObject.

Definition at line 169 of file Robot.cpp.

Referenced by CodeTool::get_property().

00170 {
00171 }

void Robot::Tick ( long  usec  ) 

Definition at line 33 of file Robot.cpp.

References Call(), m_charge_rate, m_current_heading, m_gun, m_life, m_max_power_level, m_power_level, m_radar, m_set_heading, m_shields, m_turn_rate, m_turret, Life::Tick(), Gun::Tick(), Turret::Tick(), Radar::Tick(), Shields::Tick(), and UsePower().

00034 {
00035         // Robot: charge
00036         {
00037                 double x = (usec * m_charge_rate) / 1000000;
00038                 m_power_level += x;
00039                 if (m_power_level > m_max_power_level)
00040                         m_power_level = m_max_power_level;
00041         }
00042         // Robot: turn
00043         {
00044                 double diff_cw = m_set_heading - m_current_heading;
00045                 if (diff_cw < 0)
00046                         diff_cw += 360;
00047                 if (diff_cw >= 0.1 && diff_cw <= 180)
00048                 {
00049                         // cw turn
00050                         double angl = (usec * m_turn_rate) / 1000000; // 12 degrees/sec
00051                         angl = (angl < diff_cw) ? angl : diff_cw;
00052                         double powr = (angl * 550) / m_turn_rate; // 550 power units / 12 degrees
00053                         // ...
00054                         if (UsePower(powr))
00055                         {
00056                                 m_current_heading += angl;
00057                                 if (m_current_heading >= 360)
00058                                         m_current_heading -= 360;
00059                                 double diff = m_current_heading - m_set_heading;
00060                                 if (diff < 0)
00061                                         diff *= -1;
00062                                 if (diff < 0.1)
00063                                 {
00064                                         Call( "OnTurnComplete" );
00065                                 }
00066                         }
00067                 }
00068                 else
00069                 if (diff_cw >= 0.1)
00070                 {
00071                         // ccw turn
00072                         double diff_ccw = m_current_heading - m_set_heading;
00073                         if (diff_ccw < 0)
00074                                 diff_ccw += 360;
00075                         double angl = (usec * m_turn_rate) / 1000000; // 12 degrees/sec
00076                         angl = (angl < diff_ccw) ? angl : diff_ccw;
00077                         double powr = (angl * 550) / m_turn_rate; // 550 power units / 12 degrees
00078                         // ...
00079                         if (UsePower(powr))
00080                         {
00081                                 m_current_heading -= angl;
00082                                 if (m_current_heading < 0)
00083                                         m_current_heading += 360;
00084                                 double diff = m_current_heading - m_set_heading;
00085                                 if (diff < 0)
00086                                         diff *= -1;
00087                                 if (diff < 0.1)
00088                                 {
00089                                         Call( "OnTurnComplete" );
00090                                 }
00091                         }
00092                 }
00093         }
00094 
00095         // Robot parts Tick
00096         m_shields.Tick( usec );
00097         m_radar.Tick( usec );
00098         m_turret.Tick( usec );
00099         m_gun.Tick( usec );
00100         m_life.Tick( usec );
00101 }

Life& Robot::PartLife (  )  [inline]

Definition at line 31 of file Robot.h.

References m_life.

00031 { return m_life; }

Radar& Robot::PartRadar (  )  [inline]

Definition at line 32 of file Robot.h.

References m_radar.

00032 { return m_radar; }

Turret& Robot::PartTurret (  )  [inline]

Definition at line 33 of file Robot.h.

References m_turret.

00033 { return m_turret; }

Gun& Robot::PartGun (  )  [inline]

Definition at line 34 of file Robot.h.

References m_gun.

00034 { return m_gun; }

Shields& Robot::PartShields (  )  [inline]

Definition at line 35 of file Robot.h.

References m_shields.

00035 { return m_shields; }

long Robot::get_property ( int   ) 

Definition at line 128 of file Robot.cpp.

References RobotObject::GetDamage(), RobotObject::GetRepairRate(), m_life, m_max_power_level, m_power_level, and RobotObject::Ok().

00129 {
00130         switch (prop)
00131         {
00132         case 1: // ok
00133                 return m_life.Ok();
00134         case 2: // damage
00135                 return m_life.GetDamage();
00136         case 3: // repair_rate
00137                 return m_life.GetRepairRate();
00138         case 4: // inventory
00139                 break;
00140         case 5: // power 0 .. 100 %
00141                 return (int)((100 * m_power_level) / m_max_power_level);
00142         case 6: // charging
00143                 return (m_power_level < m_max_power_level) ? true : false;
00144         }
00145         return 0;
00146 }

void Robot::set_property ( int  ,
long   
)

Definition at line 149 of file Robot.cpp.

References m_life, and RobotObject::SetRepairRate().

Referenced by CodeTool::set_property().

00150 {
00151         switch (prop)
00152         {
00153         case 1: // ok
00154                 break;
00155         case 2: // damage
00156                 break;
00157         case 3: // repair_rate
00158                 m_life.SetRepairRate(value);
00159                 break;
00160         }
00161 }

long Robot::call_method ( int  ,
stack_v  
)

Definition at line 164 of file Robot.cpp.

Referenced by CodeTool::call_method().

00165 {
00166 }

void Robot::Call ( const std::string &  method  ) 

Definition at line 122 of file Robot.cpp.

References m_code.

Referenced by Tick(), and UsePower().

00123 {
00124         m_code -> Call( method );
00125 }

void Robot::AddObject ( MapObject  ) 

Definition at line 104 of file Robot.cpp.

References m_inventory.

00105 {
00106         m_inventory.push_back(p);
00107 }

mapobject_v& Robot::GetInventory (  )  [inline]

Definition at line 46 of file Robot.h.

References m_inventory.

00046 { return m_inventory; } // robot.inventory

int Robot::GetPower (  )  [inline]

Definition at line 49 of file Robot.h.

References m_max_power_level, and m_power_level.

00049 { return (int)((m_power_level * 100) / m_max_power_level); } // robot.power

int Robot::GetPowerLevel (  )  [inline]

Definition at line 50 of file Robot.h.

References m_power_level.

Referenced by Charging().

00050 { return (int)m_power_level; }

int Robot::GetMaxPowerLevel (  )  [inline]

Definition at line 51 of file Robot.h.

References m_max_power_level.

Referenced by Charging(), and RobotObject::Tick().

00051 { return m_max_power_level; }

void Robot::SetMaxPowerLevel ( int  x  )  [inline]

Definition at line 52 of file Robot.h.

References m_max_power_level.

00052 { m_max_power_level = x; }

bool Robot::Charging (  )  [inline]

Definition at line 53 of file Robot.h.

References GetMaxPowerLevel(), and GetPowerLevel().

00053 { return GetPowerLevel() < GetMaxPowerLevel(); } // robot.charging

int Robot::GetChargeRate (  )  [inline]

Definition at line 54 of file Robot.h.

References m_charge_rate.

00054 { return m_charge_rate; }

void Robot::SetChargeRate ( int  x  )  [inline]

Definition at line 55 of file Robot.h.

References m_charge_rate.

00055 { m_charge_rate = x; }

bool Robot::UsePower ( double  units  ) 

Definition at line 110 of file Robot.cpp.

References Call(), and m_power_level.

Referenced by Tick().

00111 {
00112         if (m_power_level < units)
00113         {
00114                 Call( "OnOutOfPower" );
00115                 return false;
00116         }
00117         m_power_level -= units;
00118         return true;
00119 }

int Robot::GetCurrentHeading (  )  [inline]

Definition at line 59 of file Robot.h.

References m_current_heading.

00059 { return (int)m_current_heading; }

void Robot::SetHeading ( double  x  )  [inline]

Definition at line 60 of file Robot.h.

References m_set_heading.

00060 { m_set_heading = x; }

double Robot::GetTurnRate (  )  [inline]

Definition at line 61 of file Robot.h.

References m_turn_rate.

00061 { return m_turn_rate; }

void Robot::SetTurnRate ( double  x  )  [inline]

Definition at line 62 of file Robot.h.

References m_turn_rate.

00062 { m_turn_rate = x; }


Member Data Documentation

RobotXMLFile Robot::m_config [private]

Definition at line 65 of file Robot.h.

Referenced by IsOk(), and Robot().

CodeTool* Robot::m_code [private]

Definition at line 66 of file Robot.h.

Referenced by Call(), Robot(), and ~Robot().

Life Robot::m_life [private]

Definition at line 68 of file Robot.h.

Referenced by get_property(), PartLife(), set_property(), and Tick().

Radar Robot::m_radar [private]

Definition at line 69 of file Robot.h.

Referenced by PartRadar(), and Tick().

Turret Robot::m_turret [private]

Definition at line 70 of file Robot.h.

Referenced by PartTurret(), and Tick().

Gun Robot::m_gun [private]

Definition at line 71 of file Robot.h.

Referenced by PartGun(), and Tick().

Shields Robot::m_shields [private]

Definition at line 72 of file Robot.h.

Referenced by PartShields(), and Tick().

mapobject_v Robot::m_inventory [private]

Definition at line 74 of file Robot.h.

Referenced by AddObject(), and GetInventory().

double Robot::m_power_level [private]

Definition at line 76 of file Robot.h.

Referenced by get_property(), GetPower(), GetPowerLevel(), Tick(), and UsePower().

int Robot::m_max_power_level [private]

Definition at line 77 of file Robot.h.

Referenced by get_property(), GetMaxPowerLevel(), GetPower(), SetMaxPowerLevel(), and Tick().

int Robot::m_charge_rate [private]

Definition at line 78 of file Robot.h.

Referenced by GetChargeRate(), SetChargeRate(), and Tick().

double Robot::m_current_heading [private]

Definition at line 80 of file Robot.h.

Referenced by GetCurrentHeading(), and Tick().

double Robot::m_set_heading [private]

Definition at line 81 of file Robot.h.

Referenced by SetHeading(), and Tick().

double Robot::m_turn_rate [private]

Definition at line 82 of file Robot.h.

Referenced by GetTurnRate(), SetTurnRate(), and Tick().


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