TankPosition.h

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 #if !defined(__INCLUDE_TankPositionh_INCLUDE__)
00022 #define __INCLUDE_TankPositionh_INCLUDE__
00023 
00024 #include <net/NetBuffer.h>
00025 #include <vector>
00026 
00027 class Tank;
00028 class ScorchedContext;
00029 class TankPosition
00030 {
00031 public:
00032 
00033         struct ShotEntry
00034         {
00035                 ShotEntry(fixed p = 0, fixed r = 0, fixed e = 0) : 
00036                         power(p), rot(r), ele(e) { }
00037         
00038                 fixed power;
00039                 fixed rot;
00040                 fixed ele;
00041                 bool current;
00042         };
00043 
00044         TankPosition(ScorchedContext &context);
00045         virtual ~TankPosition();
00046 
00047         void setTank(Tank *tank) { tank_ = tank; }
00048 
00049         // State change
00050         void clientNewGame();
00051         void madeShot();
00052         void newGame();
00053         
00054         // Saved settings
00055         fixed getRotationXYDiff();
00056         fixed getRotationYZDiff();
00057         fixed getPowerDiff();
00058         void revertSettings(unsigned int index = 0);
00059         void undo();
00060         std::vector<ShotEntry> &getOldShots();
00061 
00062         // Gun/Turret Rotation
00063         fixed rotateGunXY(fixed angle, bool diff=true);
00064         fixed rotateGunYZ(fixed angle, bool diff=true);
00065         fixed getRotationGunXY() { return turretRotXY_; }
00066         fixed getRotationGunYZ() { return turretRotYZ_; }
00067 
00068         // Select position
00069         int getSelectPositionX() { return selectPositionX_; }
00070         int getSelectPositionY() { return selectPositionY_; }
00071         void setSelectPosition(int x, int y) { 
00072                 selectPositionX_ = x; selectPositionY_ = y; }
00073 
00074         // Power of gun
00075         fixed getPower() { return power_; }
00076         fixed changePower(fixed power, bool diff=true);
00077 
00078         fixed getMaxPower() { return maxPower_; }
00079         void setMaxPower(fixed power) { maxPower_ = power; }
00080 
00081         // Position
00082         FixedVector &getVelocityVector();
00083         FixedVector &getTankPosition(); // Position of center bottom of tank
00084         FixedVector &getTankTurretPosition(); // Position of center of turret
00085         FixedVector &getTankGunPosition(); // Position of end of gun
00086 
00087         const char *getRotationString();
00088         const char *getElevationString();
00089         const char *getPowerString();
00090 
00091         // Serialize the tank
00092         bool writeMessage(NetBuffer &buffer);
00093         bool readMessage(NetBufferReader &reader);
00094 
00095 protected:
00096         ScorchedContext &context_;
00097         Tank *tank_;
00098 
00099         // Turret angles
00100         std::vector<ShotEntry> oldShots_;
00101         fixed turretRotXY_, turretRotYZ_, power_;
00102         fixed oldTurretRotXY_, oldTurretRotYZ_, oldPower_;
00103         fixed maxPower_;
00104         int selectPositionX_, selectPositionY_;
00105 };
00106 
00107 #endif
00108 

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