TankAICurrent.cpp

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////////////
00002 //    Scorched3D (c) 2000-2009
00003 //
00004 //    This file is part of Scorched3D.
00005 //
00006 //    Scorched3D is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    Scorched3D is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with Scorched3D; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 ////////////////////////////////////////////////////////////////////////////////
00020 
00021 #include <tankai/TankAICurrent.h>
00022 #include <tank/TankContainer.h>
00023 #include <server/ScorchedServer.h>
00024 #include <common/OptionsTransient.h>
00025 #include <XML/XMLNode.h>
00026 
00027 TankAICurrent::TankAICurrent() : tank_(0)
00028 {
00029 }
00030 
00031 TankAICurrent::~TankAICurrent()
00032 {
00033 }
00034 
00035 TankAI *TankAICurrent::createCopy(Tank *tank)
00036 {
00037         TankAICurrent *result = new TankAICurrent(*this);
00038         result->setTank(tank);
00039         return result;
00040 }
00041 
00042 void TankAICurrent::setTank(Tank *tank)
00043 {
00044         tank_ = tank;
00045 }
00046 
00047 bool TankAICurrent::parseConfig(XMLNode *node)
00048 {
00049         if (!TankAI::parseConfig(node)) return false;
00050 
00051         {
00052                 XMLNode *weapons = 0;
00053                 if (!node->getNamedChild("weapons", weapons)) return false;
00054                 if (!wantedWeapons_.parseConfig(weapons)) return false;
00055         }
00056         {
00057                 XMLNode *defense = 0;
00058                 if (!node->getNamedChild("defense", defense)) return false;
00059                 if (!defenses_.parseConfig(defense)) return false;
00060         }
00061         {
00062                 XMLNode *attack = 0;
00063                 if (!node->getNamedChild("attack", attack)) return false;
00064                 if (!move_.parseConfig(attack)) return false;
00065         }
00066 
00067         return node->failChildren();    
00068 }
00069 
00070 void TankAICurrent::newMatch()
00071 {
00072         newGame();
00073 }
00074 
00075 void TankAICurrent::newGame()
00076 {
00077         move_.getTargets().clear();
00078         move_.clear();
00079 }
00080 
00081 void TankAICurrent::playMove()
00082 {
00083         // Raise any defenses
00084         defenses_.raiseDefenses(tank_);
00085 
00086         // Make the move
00087         move_.playMove(tank_, 
00088                 wantedWeapons_.getCurrentWeaponSet(),
00089                 defenses_.getUseBatteries());
00090 }
00091 
00092 void TankAICurrent::autoDefense()
00093 {
00094         defenses_.raiseDefenses(tank_);
00095 }
00096 
00097 void TankAICurrent::buyAccessories()
00098 {
00099         bool lastRound = 
00100                 (ScorchedServer::instance()->getOptionsTransient().getCurrentRoundNo() >=
00101                 ScorchedServer::instance()->getOptionsGame().getNoRounds());
00102 
00103         wantedWeapons_.buyWeapons(tank_, lastRound);
00104 }
00105 
00106 void TankAICurrent::tankHurt(Weapon *weapon, float damage, 
00107         unsigned int damaged, unsigned int fired)
00108 {
00109         if (damaged == tank_->getPlayerId())
00110         {
00111                 Tank *firedTank = ScorchedServer::instance()->
00112                         getTankContainer().getTankById(fired);
00113                 if (firedTank)
00114                 {
00115                         move_.getTargets().tookDamage(firedTank, damage);               
00116                 }
00117         }
00118         else if (fired == tank_->getPlayerId())
00119         {
00120                 Tank *damagedTank = ScorchedServer::instance()->
00121                         getTankContainer().getTankById(damaged);
00122                 if (damagedTank)
00123                 {
00124                         move_.getTargets().gaveDamage(damagedTank, damage);             
00125                 }
00126         }
00127 }
00128 
00129 void TankAICurrent::shotLanded(ScorchedCollisionId collision,
00130                 Weapon *weapon, unsigned int firer, 
00131                 Vector &position)
00132 {
00133 }

Generated on Mon Feb 16 15:14:53 2009 for Scorched3D by  doxygen 1.5.3