Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

Jet Class Reference

#include <MilitaryUnit.h>

Inheritance diagram for Jet:

Inheritance graph
[legend]
Collaboration diagram for Jet:

Collaboration graph
[legend]
List of all members.

Detailed Description

The Jet.

Jets are not diretly controllable via the overhead view. when created they should fly around the city that created them. They can be called to a battle via the battle mode.

Definition at line 181 of file MilitaryUnit.h.

Public Types

enum  JetState { CIRCLE, LIFTOFF, MOVING, ARRIVE }
enum  State { IDLE, BUSY, WANTS_TO_STOP }

Public Methods

 Jet (const Vec3D &initialPosition, Player *owner, const int armySize, const int cityID)
virtual ~Jet (void)
virtual int getCityID ()
virtual void draw () const
virtual void goal (Vec3D destination)
 What the tank should be moving towards.

virtual void move ()
 Move the tank towards the goal.

virtual bool contains (Vec3D that) const
virtual bool around (Vec3D that)
virtual bool collision (const MilitaryUnit *const that) const
virtual bool fightingCollision (const MilitaryUnit *const that) const
virtual bool nearEachOther (const MilitaryUnit *const that) const
virtual void drawBox () const
 Draw a box around the unit. This is useful for if you want to mark a unit as being selected.

virtual Playerowner () const
virtual Vec3D color () const
virtual void drawColor () const
 Draw's a color box around the unit to indicate team ownership.

virtual Vec3D position () const
virtual Vec3D goalPosition () const
virtual void setShortcutKey (int key)
virtual int shortcutKey () const
UnitType unitType () const
int armySize () const
bool isIdle () const
bool isMoving () const
virtual unsigned int uniqueID (void) const

Protected Attributes

Vec3D m_currPos
Vec3D m_teamColor
Vec3D m_unitSize
Vec3D m_direction
Playerm_pOwner
UnitType m_unitType
int m_armySize
State m_currState
Vec3D m_collisionSize
Vec3D m_goalPos
int m_overheadShortcutKey

Private Attributes

Vec3D m_cityCenter
float m_ang
float m_liftOffAng
int m_cityID
float m_distFromCity
Vec3D m_velocity
JetState m_jetState

Static Private Attributes

const float s_dTheta = 0.5f
const float s_speed = 0.2f
const float s_dZ


Member Enumeration Documentation

enum Jet::JetState
 

Enumeration values:
CIRCLE 
LIFTOFF 
MOVING 
ARRIVE 

Definition at line 185 of file MilitaryUnit.h.

00185 { CIRCLE, LIFTOFF, MOVING, ARRIVE };

enum MilitaryUnit::State [inherited]
 

states a unit can be in

Enumeration values:
IDLE 
BUSY 
WANTS_TO_STOP 

Definition at line 40 of file MilitaryUnit.h.

00040 {IDLE, BUSY, WANTS_TO_STOP};


Constructor & Destructor Documentation

Jet::Jet const Vec3D   initialPosition,
Player   owner,
const int    armySize,
const int    cityID
 

Definition at line 324 of file MilitaryUnit.cpp.

References City::addJetGaurd(), GameState::getCity(), MilitaryUnit::IDLE, UnitTypes::JET, City::jetGaurdSize(), m_cityCenter, MilitaryUnit::m_currPos, MilitaryUnit::m_currState, and m_distFromCity.

00325 : MilitaryUnit(initialPosition, owner, UnitTypes::JET, armySize, BattleUnitData::getObj().jetSize()),
00326  m_cityCenter(GameState::getCity(cityID)->position()),  m_ang(0.0f), m_liftOffAng(0.0f), 
00327  m_cityID(cityID), m_jetState(CIRCLE)
00328 {
00329   m_currState = IDLE;
00330   // every 4 jets that guard city increases the radius at which they draw
00331   m_distFromCity = ((GameState::getCity(m_cityID)->jetGaurdSize() / 4)+1)*15.0f;
00332   m_currPos.x = m_cityCenter.x + (m_distFromCity * (cosf(m_ang*(D3DX_PI/180))));
00333   m_currPos.y = m_cityCenter.y + (m_distFromCity * (sinf(m_ang*(D3DX_PI/180))));
00334   m_currPos.z = 20.0f;
00335   // add one to the city i'm gaurding's list of jets
00336   GameState::getCity(m_cityID)->addJetGaurd();
00337   //sys_console() << "Adding jet gaurd" << GameState::getCity(m_cityID)->jetGaurdSize() << endl;
00338 
00339 }

Jet::~Jet void    [virtual]
 

Definition at line 345 of file MilitaryUnit.cpp.

References City::deleteJetGuard(), and GameState::getCity().

00346 {
00347   // delete one from the city i'm guarding
00348   GameState::getCity(m_cityID)->deleteJetGuard();
00349   //sys_console() << "Deleting jet gaurd" << GameState::getCity(m_cityID)->jetGaurdSize() << endl;
00350 }


Member Function Documentation

int MilitaryUnit::armySize   const [inline, inherited]
 

Definition at line 105 of file MilitaryUnit.h.

References MilitaryUnit::m_armySize.

Referenced by NetworkSubsystem::processNetworkData().

00106 {
00107         return m_armySize;
00108 }

bool MilitaryUnit::around Vec3D    that [virtual, inherited]
 

Returns:
true if the unit is close to passed in point.

Definition at line 73 of file MilitaryUnit.cpp.

References Globals::BATTLE_RADIUS, math_dist2D(), and Vec2D.

00074 {
00075         return math_dist2D(Vec2D(this->m_currPos.x, this->m_currPos.y), Vec2D(that.x, that.y)) < BATTLE_RADIUS;
00076 }

bool MilitaryUnit::collision const MilitaryUnit *const    that const [virtual, inherited]
 

Returns:
true if the current unit collides with the passed in unit. false otherwise.

Definition at line 78 of file MilitaryUnit.cpp.

References MilitaryUnit::m_collisionSize, MilitaryUnit::m_currPos, and MilitaryUnit::position().

Referenced by Globals::OverheadCollisonWithIdleUnit().

00079 {
00080         return (
00081                 (m_currPos.z + m_collisionSize.z > that->position().z) &&
00082                 (m_currPos.z - m_collisionSize.z < that->position().z) &&
00083                 (m_currPos.x + m_collisionSize.x > that->position().x) &&
00084                 (m_currPos.x - m_collisionSize.x < that->position().x) &&
00085                 (m_currPos.y + m_collisionSize.y > that->position().y) &&
00086                 (m_currPos.y - m_collisionSize.y < that->position().y) );
00087 }

Vec3D MilitaryUnit::color   const [virtual, inherited]
 

Returns:
the color of the team this unit belongs to.

Definition at line 210 of file MilitaryUnit.cpp.

References MilitaryUnit::m_teamColor, and Vec3D.

Referenced by Overhead::getSurroundingUnits(), goal(), and NetworkSubsystem::processNetworkData().

00211 {
00212         return m_teamColor;
00213 }

bool MilitaryUnit::contains Vec3D    that const [virtual, inherited]
 

Returns:
true if the x, y pair is inside the unit. false otherwise. The z-axis is ignored in this check.

Definition at line 65 of file MilitaryUnit.cpp.

References math_dist2D(), math_translateWorldToScreen(), and Vec2D.

00066 {
00067         // because a unit also has height (instead of just x,y) we'll do screen-space checking
00068         Vec2D pt(math_translateWorldToScreen(that));
00069         Vec2D unitPt(math_translateWorldToScreen(m_currPos));
00070         return math_dist2D(pt,unitPt)<0.03f;
00071 }

void Jet::draw   const [virtual]
 

Draws the object at its current location.

Implements DrawableObject.

Definition at line 358 of file MilitaryUnit.cpp.

References Globals::artWork, and mesh_render().

00359 {
00360         mesh_render( artWork->jet_mesh, this->m_currPos, this->m_unitSize, this->m_direction, artWork->jet_texture, 0,
00361                 this->color());
00362 }

void MilitaryUnit::drawBox   const [virtual, inherited]
 

Draw a box around the unit. This is useful for if you want to mark a unit as being selected.

Definition at line 197 of file MilitaryUnit.cpp.

References Globals::artWork, MilitaryUnit::m_currPos, mesh_render(), and Vec3D.

00198 {
00199         Vec3D pos = m_currPos;
00200         pos.z += 0.3f;
00201         FLOAT angle = (FLOAT)( (Globals::currGameTick*5) % 360 );
00202         mesh_render( artWork->circle, pos, Vec3D(5.0f,5.0f,0.001f), Vec3D(angle,0,0), artWork->colorGreen );
00203 }

void MilitaryUnit::drawColor   const [virtual, inherited]
 

Draw's a color box around the unit to indicate team ownership.

Definition at line 220 of file MilitaryUnit.cpp.

References math_translateWorldToScreen(), overlay_line(), Vec2D, and Vec3D.

00221 {
00222         // team color box
00223         Vec3D p1(m_currPos), p2(m_currPos), p3(m_currPos), p4(m_currPos);
00224         const int delta = 4;    
00225         p1.x -= delta;
00226         p2.y += delta;
00227         p3.x += delta;
00228         p4.y -= delta;
00229         Vec2D s1( math_translateWorldToScreen(p1) );
00230         Vec2D s2( math_translateWorldToScreen(p2) );
00231         Vec2D s3( math_translateWorldToScreen(p3) );
00232         Vec2D s4( math_translateWorldToScreen(p4) );
00233         overlay_line( s1,s2, m_teamColor );
00234         overlay_line( s2,s3, m_teamColor );
00235         overlay_line( s3,s4, m_teamColor );
00236         overlay_line( s4,s1, m_teamColor );
00237 }

bool MilitaryUnit::fightingCollision const MilitaryUnit *const    that const [virtual, inherited]
 

Definition at line 89 of file MilitaryUnit.cpp.

References MilitaryUnit::m_currPos, and math_distPlanar3D().

00090 {
00091         const FLOAT distanceForAFight(25.0f);
00092         return distanceForAFight > math_distPlanar3D(this->m_currPos, that->m_currPos);
00093 }

int Jet::getCityID   [virtual]
 

Definition at line 353 of file MilitaryUnit.cpp.

References m_cityID.

00354 {
00355         return m_cityID;
00356 }

void Jet::goal Vec3D    destination [virtual]
 

What the tank should be moving towards.

Reimplemented from MilitaryUnit.

Definition at line 364 of file MilitaryUnit.cpp.

References MilitaryUnit::BUSY, GameState::cities(), Overhead::cities, MilitaryUnit::color(), City::deleteJetGuard(), GameState::getCity(), LIFTOFF, m_ang, m_cityCenter, m_cityID, MilitaryUnit::m_currPos, MilitaryUnit::m_currState, m_distFromCity, MilitaryUnit::m_goalPos, m_jetState, m_liftOffAng, m_velocity, math_distPlanar3D(), math_getDir(), and s_speed.

00365 {
00366   vector<City*>& cities = GameState::cities();
00367   for(CityIter iter=cities.begin(); iter != cities.end(); ++iter)
00368   {
00369     // if destination is a city
00370     if( (*iter)->color() == this->color() && math_distPlanar3D((*iter)->position(),dest) < 40.0f )
00371     {
00372       //   move there
00373       // remove myself from the current cities gaurd
00374       GameState::getCity(m_cityID)->deleteJetGuard();
00375       m_currState = BUSY;
00376       m_jetState = LIFTOFF;
00377       m_cityID = (*iter)->uniqueID();
00378       m_cityCenter = (*iter)->position();
00379       (*iter)->addJetGaurd();
00380       // radius the plane should fly at when it reaches city
00381       m_distFromCity = (((*iter)->jetGaurdSize() / 4)+1)*15.0f;
00382       m_ang = 0.0f;
00383       m_liftOffAng = math_getDir(m_currPos, (*iter)->position());
00384       m_goalPos.x = m_cityCenter.x + (m_distFromCity * (cosf(m_ang*(D3DX_PI/180))));
00385       m_goalPos.y = m_cityCenter.y + (m_distFromCity * (sinf(m_ang*(D3DX_PI/180))));
00386       m_velocity = m_goalPos - m_currPos;
00387       m_velocity *= (1/(sqrtf( m_velocity.x*m_velocity.x + m_velocity.y*m_velocity.y )))*s_speed  ;
00388       
00389       break;
00390     }
00391     // else
00392     //   do nothing
00393   }
00394 }

Vec3D MilitaryUnit::goalPosition   const [virtual, inherited]
 

Returns:
the location of where the unit is moving towards.

Definition at line 60 of file MilitaryUnit.cpp.

References MilitaryUnit::m_goalPos, and Vec3D.

00061 {
00062         return this->m_goalPos;
00063 }

bool MilitaryUnit::isIdle   const [inline, inherited]
 

Definition at line 110 of file MilitaryUnit.h.

References MilitaryUnit::IDLE, and MilitaryUnit::m_currState.

00111 {
00112         return m_currState == IDLE;
00113 }

bool MilitaryUnit::isMoving   const [inline, inherited]
 

Definition at line 115 of file MilitaryUnit.h.

References MilitaryUnit::BUSY, and MilitaryUnit::m_currState.

00116 {
00117         return m_currState == BUSY;
00118 }

void Jet::move   [virtual]
 

Move the tank towards the goal.

Reimplemented from MilitaryUnit.

Definition at line 398 of file MilitaryUnit.cpp.

References Helper::abs(), ARRIVE, MilitaryUnit::BUSY, CIRCLE, MilitaryUnit::IDLE, LIFTOFF, m_ang, m_cityCenter, MilitaryUnit::m_currPos, MilitaryUnit::m_currState, MilitaryUnit::m_direction, m_distFromCity, MilitaryUnit::m_goalPos, m_jetState, m_velocity, math_clipAngle(), MOVING, Globals::OverheadCollisonWithIdleUnit(), s_dTheta, s_dZ, and sys_randInt().

00399 {
00400   if(m_currState == IDLE)
00401   {
00402     // jet should circle the cities center
00403     // dont want to draw jets on top of each other, move if they collide
00404     m_ang += (OverheadCollisonWithIdleUnit(this) ? (sys_randInt()*s_dTheta) : s_dTheta);
00405     m_direction.x = math_clipAngle(m_ang + 90.0f);
00406     m_currPos.x = m_cityCenter.x + (m_distFromCity * (cosf(m_ang*(D3DX_PI/180))));
00407     m_currPos.y = m_cityCenter.y + (m_distFromCity * (sinf(m_ang*(D3DX_PI/180))));
00408   }
00409   else if (m_currState == BUSY)
00410   {
00411     // if we have just been order to move increase z and rotate to face new city
00412     if(m_jetState == LIFTOFF) 
00413     {
00414       if(Helper::abs(m_direction.x - m_liftOffAng) < 1.0f)
00415       {
00416         m_jetState = MOVING;
00417         return;
00418       }
00419       else
00420       {
00421         m_direction.x = math_clipAngle(m_direction.x+1.0f);
00422         m_currPos.z += s_dZ;
00423       }
00424     }
00425     else if(m_jetState == MOVING)
00426     {
00427       if( Helper::abs(m_currPos.x - m_goalPos.x) < 0.1f && Helper::abs(m_currPos.y - m_goalPos.y) < 0.1f )
00428       {
00429         m_jetState = ARRIVE;
00430       }
00431       else
00432       {
00433         // jet is moving to a new city
00434         m_currPos.x += m_velocity.x;
00435         m_currPos.y += m_velocity.y;
00436       }
00437     }
00438     else if(m_jetState == ARRIVE)
00439     {
00440       // jet should face 90.0 and descend
00441 
00442       bool atHeight = !((m_currPos.z - s_dZ) > 20.0f);
00443       if( !atHeight )
00444         m_currPos.z -= s_dZ;
00445 
00446       //if( math_clipAngle(m_direction.x + 1.0f) != 90.0f)
00447       bool atAng = !(Helper::abs(m_direction.x - 90.0f) > 1.0f); 
00448       if( !atAng )
00449         m_direction.x = math_clipAngle(m_direction.x + 1.0f);
00450 
00451       if( atHeight && atAng )
00452       {
00453         m_jetState = CIRCLE;
00454         m_currState = IDLE;
00455       }
00456     }
00457 
00458   }
00459 }

bool MilitaryUnit::nearEachOther const MilitaryUnit *const    that const [virtual, inherited]
 

Definition at line 95 of file MilitaryUnit.cpp.

References MilitaryUnit::m_currPos, and math_distPlanar3D().

00096 {
00097         const FLOAT distance(50.0f);
00098         return distance > math_distPlanar3D(this->m_currPos, that->m_currPos);
00099 }

Player * MilitaryUnit::owner   const [virtual, inherited]
 

Returns:
the player this MilitaryUnit belongs to.

Definition at line 205 of file MilitaryUnit.cpp.

References MilitaryUnit::m_pOwner.

00206 {
00207         return this->m_pOwner;
00208 }

Vec3D MilitaryUnit::position   const [virtual, inherited]
 

Returns:
the location of the unit on the overhead map.

Definition at line 215 of file MilitaryUnit.cpp.

References MilitaryUnit::m_currPos, and Vec3D.

Referenced by MilitaryUnit::collision(), City::collision(), Overhead::deleteMilitaryUnit(), and Overhead::getSurroundingUnits().

00216 {
00217         return this->m_currPos;
00218 }

void MilitaryUnit::setShortcutKey int    key [virtual, inherited]
 

This number is different for each tank produced

Definition at line 239 of file MilitaryUnit.cpp.

References MilitaryUnit::m_overheadShortcutKey.

00240 {
00241         m_overheadShortcutKey = key;
00242 }

int MilitaryUnit::shortcutKey   const [virtual, inherited]
 

Definition at line 244 of file MilitaryUnit.cpp.

References MilitaryUnit::m_overheadShortcutKey.

Referenced by NetworkSubsystem::processNetworkData().

00245 {
00246         return m_overheadShortcutKey;
00247 }

unsigned int UniqueID::uniqueID void    const [virtual, inherited]
 

Definition at line 31 of file UniqueID.cpp.

References UniqueID::m_uniqueID.

Referenced by City::changeOwner(), BattleEntry::inputIssueGroupCommand(), BattleEntry::inputIssueJetsCommand(), Overhead::processOverheadInput(), HUD::processOverheadInput(), sendReinforcement(), and City::update().

00032 {
00033         return m_uniqueID;
00034 }

UnitType MilitaryUnit::unitType   const [inline, inherited]
 

Definition at line 100 of file MilitaryUnit.h.

References MilitaryUnit::m_unitType, and UnitType.

Referenced by NetworkSubsystem::processNetworkData(), and HUD::render().

00101 {
00102         return m_unitType;
00103 }


Member Data Documentation

float Jet::m_ang [private]
 

Definition at line 195 of file MilitaryUnit.h.

Referenced by goal(), and move().

int MilitaryUnit::m_armySize [protected, inherited]
 

Definition at line 86 of file MilitaryUnit.h.

Referenced by MilitaryUnit::armySize().

Vec3D Jet::m_cityCenter [private]
 

Definition at line 194 of file MilitaryUnit.h.

Referenced by goal(), Jet(), and move().

int Jet::m_cityID [private]
 

Definition at line 197 of file MilitaryUnit.h.

Referenced by getCityID(), and goal().

Vec3D MilitaryUnit::m_collisionSize [protected, inherited]
 

Definition at line 88 of file MilitaryUnit.h.

Referenced by MilitaryUnit::collision().

Vec3D MilitaryUnit::m_currPos [protected, inherited]
 

Definition at line 80 of file MilitaryUnit.h.

Referenced by MilitaryUnit::collision(), MilitaryUnit::drawBox(), MilitaryUnit::fightingCollision(), goal(), Jet(), move(), MilitaryUnit::move(), MilitaryUnit::nearEachOther(), and MilitaryUnit::position().

State MilitaryUnit::m_currState [protected, inherited]
 

Definition at line 87 of file MilitaryUnit.h.

Referenced by goal(), MilitaryUnit::goal(), MilitaryUnit::isIdle(), MilitaryUnit::isMoving(), Jet(), move(), and MilitaryUnit::move().

Vec3D MilitaryUnit::m_direction [protected, inherited]
 

Definition at line 83 of file MilitaryUnit.h.

Referenced by move(), and MilitaryUnit::move().

float Jet::m_distFromCity [private]
 

Definition at line 199 of file MilitaryUnit.h.

Referenced by goal(), Jet(), and move().

Vec3D MilitaryUnit::m_goalPos [protected, inherited]
 

Definition at line 89 of file MilitaryUnit.h.

Referenced by goal(), MilitaryUnit::goal(), MilitaryUnit::goalPosition(), move(), and MilitaryUnit::move().

JetState Jet::m_jetState [private]
 

Definition at line 201 of file MilitaryUnit.h.

Referenced by goal(), and move().

float Jet::m_liftOffAng [private]
 

Definition at line 196 of file MilitaryUnit.h.

Referenced by goal().

int MilitaryUnit::m_overheadShortcutKey [protected, inherited]
 

Definition at line 90 of file MilitaryUnit.h.

Referenced by MilitaryUnit::setShortcutKey(), and MilitaryUnit::shortcutKey().

Player* MilitaryUnit::m_pOwner [protected, inherited]
 

Definition at line 84 of file MilitaryUnit.h.

Referenced by MilitaryUnit::owner().

Vec3D MilitaryUnit::m_teamColor [protected, inherited]
 

Definition at line 81 of file MilitaryUnit.h.

Referenced by MilitaryUnit::color().

Vec3D MilitaryUnit::m_unitSize [protected, inherited]
 

Definition at line 82 of file MilitaryUnit.h.

UnitType MilitaryUnit::m_unitType [protected, inherited]
 

Definition at line 85 of file MilitaryUnit.h.

Referenced by MilitaryUnit::unitType().

Vec3D Jet::m_velocity [private]
 

Definition at line 200 of file MilitaryUnit.h.

Referenced by goal(), and move().

const float Jet::s_dTheta = 0.5f [static, private]
 

Definition at line 342 of file MilitaryUnit.cpp.

Referenced by move().

const float Jet::s_dZ [static, private]
 

Referenced by move().

const float Jet::s_speed = 0.2f [static, private]
 

Definition at line 343 of file MilitaryUnit.cpp.

Referenced by goal().


The documentation for this class was generated from the following files:
Generated on Wed Apr 23 05:52:10 2003 for Modern Warfare by doxygen1.3-rc2