Google
Web alhem.net

RobotObject.cpp

Go to the documentation of this file.
00001 //#include <stdio.h>
00002 
00003 #include "Robot.h"
00004 #include "RobotObject.h"
00005 
00006 
00007 
00008 
00009 RobotObject::RobotObject(Robot& r) : m_robot(r)
00010 ,m_max_life(100)
00011 ,m_life(100)
00012 ,m_repair_rate(10) // % of max power/sec
00013 {
00014 }
00015 
00016 
00017 RobotObject::~RobotObject()
00018 {
00019 }
00020 
00021 
00022 void RobotObject::Tick(long usec)
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 }
00036 
00037 

Generated for Robot World by doxygen 1.3.6

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