TargetShield.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 <target/TargetShield.h>
00022 #include <target/TargetSpace.h>
00023 #include <weapons/AccessoryStore.h>
00024 #include <weapons/ShieldRound.h>
00025 #include <weapons/ShieldSquare.h>
00026 #include <engine/ScorchedContext.h>
00027 #include <engine/ActionController.h>
00028 
00029 TargetShield::TargetShield(ScorchedContext &context,
00030         unsigned int playerId) :
00031         context_(context),
00032         currentShield_(0),
00033         power_(0), 
00034         target_(0),
00035         boundingSize_(0)
00036 {
00037 }
00038 
00039 TargetShield::~TargetShield()
00040 {
00041 }
00042 
00043 void TargetShield::newGame()
00044 {
00045         setCurrentShield(0);
00046 }
00047 
00048 void TargetShield::setCurrentShield(Accessory *sh)
00049 {
00050         if (sh)
00051         {
00052                 Shield *shield = (Shield *) sh->getAction();
00053                 power_ = shield->getPower();
00054                 currentShield_ = sh;    
00055                 boundingSize_ = shield->getBoundingSize();
00056         }
00057         else
00058         {
00059                 power_ = 0;
00060                 currentShield_ = 0;
00061                 boundingSize_ = 0;
00062         }
00063 
00064         // Update the target space with this new shield information
00065         context_.getTargetSpace().updateTarget(target_);
00066 }
00067 
00068 void TargetShield::setShieldPower(fixed power)
00069 {
00070         power_ = power;
00071         if (power_ <= 0)
00072         {
00073                 power_ = 0;
00074                 setCurrentShield(0);
00075         }
00076 }
00077 
00078 bool TargetShield::writeMessage(NetBuffer &buffer)
00079 {
00080         unsigned int shieldId = (currentShield_?currentShield_->getAccessoryId():0);
00081         buffer.addToBuffer(shieldId);
00082         if (shieldId != 0) buffer.addToBuffer(power_);
00083         return true;
00084 }
00085 
00086 bool TargetShield::readMessage(NetBufferReader &reader)
00087 {
00088         unsigned int shieldId;
00089         if (!reader.getFromBuffer(shieldId)) return false;
00090         if (shieldId == 0) setCurrentShield(0);
00091         else setCurrentShield(context_.getAccessoryStore().findByAccessoryId(shieldId));
00092         if (shieldId != 0) if (!reader.getFromBuffer(power_)) return false;
00093         return true;
00094 }

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