SPYSpheres
ZREnergy.cpp
Go to the documentation of this file.
00001 #include <string.h>
00002 #include <math.h>
00003 #include "ZRGame.h"
00004 #include "ZRGameInternal.h"
00005 
00006 /*#ifdef ZRSIMULATION
00007 #include "mex.h"
00008 #define GAME_TRACE(arg) DEBUG(arg)
00009 #else
00010 #define GAME_TRACE(arg)
00011 #endif*/
00012 
00013 /*
00014 * Tries to use a given amount of energy. If the sphere has enough energy,
00015 * the function subtracts the amount and returns true. Otherwise returns false.
00016 */
00017 bool ZeroRoboticsGameImpl::tryToUseEnergy(float amount)
00018 {
00019   if (amount < 0) {
00020     GAME_TRACE(("DEV: trying to use negative energy. Check for bugs. | "));
00021     return false;
00022   }
00023 
00024   if (amount > challInfo.me.energy) {
00025     // GAME_TRACE(("Not enough energy to perform the action. | "));
00026     return false;
00027   }
00028 
00029   challInfo.me.energy -= amount;
00030   return true;
00031 }
00032 
00033 void ZeroRoboticsGameImpl::initEnergy() {
00034   challInfo.me.energy = STARTING_ENERGY;
00035 }
00036 
00037 void ZeroRoboticsGameImpl::updateEnergy() {
00038   if (!sphereInLight(challInfo.me.zrState)) return;
00039 
00040   challInfo.me.energy += ENERGY_GAIN_RATE;
00041   if (challInfo.me.energy > MAX_ENERGY) {
00042     challInfo.me.energy = MAX_ENERGY;
00043   }
00044 }
00045 
00046 float ZeroRoboticsGame::getEnergy() {
00047   return pimpl.challInfo.me.energy;
00048 }
00049 float ZeroRoboticsGame::getOtherEnergy(){
00050   bool energyUsed = pimpl.tryToUseEnergy(ENERGY_COST_GET_OTHER_ENERGY);
00051   if(energyUsed)
00052     return pimpl.challInfo.other.energy;
00053   return 0;
00054 }