Google
Web alhem.net

RobotObject Class Reference

#include <RobotObject.h>

Inheritance diagram for RobotObject:

Inheritance graph
[legend]
Collaboration diagram for RobotObject:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 RobotObject (Robot &)
virtual ~RobotObject ()
virtual void Tick (long usec)
virtual long get_property (int)=0
virtual void set_property (int, long)=0
virtual long call_method (int, stack_v &)=0
int GetMaxLife ()
void SetMaxLife (int x)
int GetLife ()
void SetLife (int x)
int GetDamage ()
bool Ok ()
void SetRepairRate (int x)
int GetRepairRate ()
RobotGetRobot ()

Private Attributes

Robotm_robot
int m_max_life
double m_life
int m_repair_rate

Detailed Description

Definition at line 10 of file RobotObject.h.


Constructor & Destructor Documentation

RobotObject::RobotObject ( Robot  ) 

Definition at line 9 of file RobotObject.cpp.

00009                                  : m_robot(r)
00010 ,m_max_life(100)
00011 ,m_life(100)
00012 ,m_repair_rate(10) // % of max power/sec
00013 {
00014 }

RobotObject::~RobotObject (  )  [virtual]

Definition at line 17 of file RobotObject.cpp.

00018 {
00019 }


Member Function Documentation

void RobotObject::Tick ( long  usec  )  [virtual]

Reimplemented in Gun, Life, Radar, Shields, and Turret.

Definition at line 22 of file RobotObject.cpp.

References Robot::GetMaxPowerLevel(), GetRobot(), m_life, m_max_life, and m_repair_rate.

Referenced by Turret::Tick(), Shields::Tick(), Radar::Tick(), and Gun::Tick().

00023 {
00024         if (m_life < m_max_life)
00025         {
00026                 double repair_units_per_sec = (m_repair_rate * GetRobot().GetMaxPowerLevel()) / 100;
00027                 double power_units = (repair_units_per_sec * usec) / 1000000;
00028                 if (GetRobot().UsePower(power_units))
00029                 {
00030                         m_life += power_units / 100;
00031                         if (m_life > m_max_life)
00032                                 m_life = m_max_life;
00033                 }
00034         }
00035 }

virtual long RobotObject::get_property ( int   )  [pure virtual]

Implemented in Gun, Life, Radar, Shields, and Turret.

virtual void RobotObject::set_property ( int  ,
long   
) [pure virtual]

Implemented in Gun, Life, Radar, Shields, and Turret.

virtual long RobotObject::call_method ( int  ,
stack_v  
) [pure virtual]

Implemented in Gun, Life, Radar, Shields, and Turret.

int RobotObject::GetMaxLife (  )  [inline]

Definition at line 22 of file RobotObject.h.

References m_max_life.

00022 { return m_max_life; }

void RobotObject::SetMaxLife ( int  x  )  [inline]

Definition at line 23 of file RobotObject.h.

References m_max_life.

00023 { m_max_life = x; }

int RobotObject::GetLife (  )  [inline]

Definition at line 24 of file RobotObject.h.

References m_life.

00024 { return (int)m_life; }

void RobotObject::SetLife ( int  x  )  [inline]

Definition at line 25 of file RobotObject.h.

References m_life.

00025 { m_life = (double)x; }

int RobotObject::GetDamage (  )  [inline]

Definition at line 26 of file RobotObject.h.

References m_life, and m_max_life.

Referenced by Turret::get_property(), Shields::get_property(), Robot::get_property(), Radar::get_property(), Gun::get_property(), and Ok().

00026 { return (int)((m_life * 100) / m_max_life); }

bool RobotObject::Ok (  )  [inline]

Definition at line 27 of file RobotObject.h.

References GetDamage().

Referenced by Turret::get_property(), Shields::get_property(), Robot::get_property(), Radar::get_property(), and Gun::get_property().

00027 { return GetDamage() > 0; }

void RobotObject::SetRepairRate ( int  x  )  [inline]

Definition at line 28 of file RobotObject.h.

References m_repair_rate.

Referenced by Turret::set_property(), Shields::set_property(), Robot::set_property(), Radar::set_property(), and Gun::set_property().

00028 { m_repair_rate = x; }

int RobotObject::GetRepairRate (  )  [inline]

Definition at line 29 of file RobotObject.h.

References m_repair_rate.

Referenced by Turret::get_property(), Shields::get_property(), Robot::get_property(), Radar::get_property(), and Gun::get_property().

00029 { return m_repair_rate; }

Robot& RobotObject::GetRobot (  )  [inline]

Definition at line 31 of file RobotObject.h.

References m_robot.

Referenced by Tick().

00031 { return m_robot; }


Member Data Documentation

Robot& RobotObject::m_robot [private]

Definition at line 34 of file RobotObject.h.

Referenced by GetRobot().

int RobotObject::m_max_life [private]

Definition at line 35 of file RobotObject.h.

Referenced by GetDamage(), GetMaxLife(), SetMaxLife(), and Tick().

double RobotObject::m_life [private]

Definition at line 36 of file RobotObject.h.

Referenced by GetDamage(), GetLife(), SetLife(), and Tick().

int RobotObject::m_repair_rate [private]

Definition at line 37 of file RobotObject.h.

Referenced by GetRepairRate(), SetRepairRate(), 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