ComsPlayedMoveMessage.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 <coms/ComsPlayedMoveMessage.h>
00022 
00023 ComsPlayedMoveMessage::ComsPlayedMoveMessage(unsigned int playerId, MoveType type) :
00024         ComsMessage("ComsPlayedMoveMessage"),
00025         moveType_(type),
00026         weaponId_(0),
00027         rotationXY_(0), rotationYZ_(0), power_(0), playerId_(playerId),
00028         selectPositionX_(0), selectPositionY_(0)
00029 {
00030 }
00031 
00032 ComsPlayedMoveMessage::~ComsPlayedMoveMessage()
00033 {
00034 }
00035 
00036 void ComsPlayedMoveMessage::setShot(unsigned int weaponId,
00037         fixed rotationXY,
00038         fixed rotationYZ,
00039         fixed power,
00040         int selectPositionX, 
00041         int selectPositionY)
00042 {
00043         weaponId_ = weaponId;
00044         rotationXY_ = rotationXY;
00045         rotationYZ_ = rotationYZ;
00046         power_ = power;
00047         selectPositionX_ = selectPositionX;
00048         selectPositionY_ = selectPositionY;
00049 }
00050 
00051 bool ComsPlayedMoveMessage::writeMessage(NetBuffer &buffer)
00052 {
00053         buffer.addToBuffer(playerId_);
00054         buffer.addToBuffer((int) moveType_);
00055         if (moveType_ == eShot)
00056         {
00057                 buffer.addToBuffer(weaponId_);
00058                 buffer.addToBuffer(rotationXY_);
00059                 buffer.addToBuffer(rotationYZ_);
00060                 buffer.addToBuffer(power_);
00061                 buffer.addToBuffer(selectPositionX_);
00062                 buffer.addToBuffer(selectPositionY_);
00063         }
00064         return true;
00065 }
00066 
00067 bool ComsPlayedMoveMessage::readMessage(NetBufferReader &reader)
00068 {
00069         if (!reader.getFromBuffer(playerId_)) return false;
00070         int mt;
00071         if (!reader.getFromBuffer(mt)) return false;
00072         moveType_ = (MoveType) mt;
00073         if (moveType_ == eShot)
00074         {
00075                 if (!reader.getFromBuffer(weaponId_)) return false;
00076                 if (!reader.getFromBuffer(rotationXY_)) return false;
00077                 if (!reader.getFromBuffer(rotationYZ_)) return false;
00078                 if (!reader.getFromBuffer(power_)) return false;
00079                 if (!reader.getFromBuffer(selectPositionX_)) return false;
00080                 if (!reader.getFromBuffer(selectPositionY_)) return false;
00081         }
00082         return true;
00083 }
00084 

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