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

RocketLauncher Class Reference

#include <MilitaryUnit.h>

Inheritance diagram for RocketLauncher:

Inheritance graph
[legend]
Collaboration diagram for RocketLauncher:

Collaboration graph
[legend]
List of all members.

Detailed Description

The RocketLauncher.

Definition at line 150 of file MilitaryUnit.h.

Public Types

enum  State { IDLE, BUSY, WANTS_TO_STOP }

Public Methods

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

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 move ()
 Move the tank towards the goal.

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


Member Enumeration Documentation

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

RocketLauncher::RocketLauncher const Vec3D   initialPosition,
Player   owner,
const int    armySize
 

Definition at line 289 of file MilitaryUnit.cpp.

References UnitTypes::LAUNCHER.

00290 : MilitaryUnit(initialPosition, owner, UnitTypes::LAUNCHER, armySize, BattleUnitData::getObj().launcherSize())
00291 {
00292 }

RocketLauncher::~RocketLauncher void    [virtual]
 

Definition at line 294 of file MilitaryUnit.cpp.

00295 {
00296 }


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(), Jet::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 RocketLauncher::draw   const [virtual]
 

Draws the object at its current location.

Implements DrawableObject.

Definition at line 298 of file MilitaryUnit.cpp.

References Globals::artWork, and mesh_render().

00299 {
00300         mesh_render( artWork->launcher_mesh, this->m_currPos, this->m_unitSize, this->m_direction, artWork->launcher_texture, 0,
00301                 this->color());
00302 }

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 }

void MilitaryUnit::goal Vec3D    destination [virtual, inherited]
 

What the tank should be moving towards.

Reimplemented in Jet.

Definition at line 54 of file MilitaryUnit.cpp.

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

Referenced by NetworkSubsystem::processNetworkData(), and City::update().

00055 {
00056         this->m_goalPos = dest;
00057         m_currState = BUSY;
00058 }

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 MilitaryUnit::move   [virtual, inherited]
 

Move the tank towards the goal.

Reimplemented in Jet.

Definition at line 101 of file MilitaryUnit.cpp.

References absf, Globals::artWork, Map::WorldMap::bounds, clipAngle(), Rect::contains(), MilitaryUnit::IDLE, MilitaryUnit::m_currPos, MilitaryUnit::m_currState, MilitaryUnit::m_direction, MilitaryUnit::m_goalPos, Globals::OverheadCollisionWithCity(), Globals::OverheadCollisonWithIdleUnit(), sys_randFloat(), terrain_getHeight(), Vec2D, Vec3D, MilitaryUnit::WANTS_TO_STOP, and GameState::worldMap().

00102 {
00103         if (this->m_currState == WANTS_TO_STOP && !OverheadCollisonWithIdleUnit(this) && !OverheadCollisionWithCity(this))
00104         {
00105                 m_currState = IDLE;
00106         }       
00107         if (this->m_currState != IDLE) {
00108 
00109                 Vec3D savePos( m_currPos );
00110                 Vec3D targetVec = m_goalPos - m_currPos;
00111                 FLOAT targetDir = clipAngle( 90-D3DXToDegree( atan2f( targetVec.x, targetVec.y ) ) );
00112                 FLOAT currentDir = m_direction.x;
00113                 FLOAT delta;                            // signed (+CW,-CCW) smallest-magnitude difference in angle
00114                 if(targetDir>currentDir)
00115                 {
00116                         delta = targetDir - currentDir;
00117                         if(delta>180.0f) delta = delta - 360.0f;
00118                 }
00119                 else
00120                 {
00121                         delta = targetDir - currentDir;
00122                         if(delta<-180.0f) delta = 360.0f - delta;
00123                 }               
00124 
00125                 const FLOAT turnRate = 0.4f;
00126                 FLOAT turnAngle = delta;
00127                 if (delta > turnRate ) turnAngle = turnRate;
00128                 else if (delta < -turnRate ) turnAngle = -turnRate;
00129                 else turnAngle = delta;
00130                 m_direction.x = clipAngle( currentDir + turnAngle );                            // turn
00131 
00132                 // move if we're heading roughly the right way
00133                 FLOAT speed = 0.0f;
00134                 if (absf(delta)<10.0f ) speed = 0.1f;
00135                 else if( absf(delta)<90.0f ) speed = 0.06f;
00136                 if (D3DXVec3Length(&targetVec) < 3.0f )                                 // if we're close to target, help stop accurately
00137                 {
00138                         m_currPos += (m_goalPos-m_currPos) * 0.06f;
00139                         speed = 0.0f;
00140                 }
00141                 if (speed>0.0f)                                                                                 // otherwise, move normally
00142                 {
00143                         FLOAT rad = D3DXToRadian( m_direction.x );
00144                         m_currPos += speed * Vec3D( cosf(rad), sinf(rad), 0.0f );
00145                 }               
00146 
00147                 /*
00148                 FLOAT x_delta = this->m_goalPos.x - this->m_currPos.x;
00149                 FLOAT y_delta = this->m_goalPos.y - this->m_currPos.y;
00150                 FLOAT abs_x_delta = Helper::abs(x_delta);
00151                 FLOAT abs_y_delta = Helper::abs(y_delta);
00152                 if (abs_x_delta + abs_y_delta > 0.0f) { 
00153                 FLOAT x_percent = abs_x_delta / (abs_x_delta + abs_y_delta);
00154                 if (x_delta < 0.0f) x_percent *= -1;
00155                 FLOAT y_percent = abs_y_delta / (abs_x_delta + abs_y_delta);
00156                 if (y_delta < 0.0f) y_percent *= -1;
00157                 FLOAT x_amount = x_percent * overheadMovementRate;
00158                 FLOAT y_amount = y_percent * overheadMovementRate;
00159                 if (Helper::abs(x_amount) > abs_x_delta) this->m_currPos.x = this->m_goalPos.x;
00160                 else this->m_currPos.x += x_amount;
00161                 if (Helper::abs(y_amount) > abs_y_delta) this->m_currPos.y = this->m_goalPos.y;
00162                 else this->m_currPos.y += y_amount;
00163                 */
00164                 // make sure unit is within map bounds
00165                 if (!GameState::worldMap().bounds.contains(Vec2D(this->m_currPos.x, this->m_currPos.y)) )
00166                         m_currPos = savePos;
00167 
00168                 // is the unit at the goal position?
00169                 FLOAT thresh = 0.1f;
00170                 if (this->m_currPos.x <= m_goalPos.x + thresh  &&  this->m_currPos.x >= m_goalPos.x - thresh &&
00171                         this->m_currPos.y <= m_goalPos.y + thresh  &&  this->m_currPos.y >= m_goalPos.y - thresh )
00172                 {
00173                         if (OverheadCollisonWithIdleUnit(this) || OverheadCollisionWithCity(this)) 
00174                         {
00175                                 this->m_currState = WANTS_TO_STOP;
00176                                 FLOAT newGoal = sys_randFloat() * 40.0F;
00177                                 this->m_goalPos = Vec3D(m_currPos.x + newGoal, m_currPos.y + newGoal, 0);
00178                         } else 
00179                         {
00180                                 m_currState = IDLE;
00181                         }
00182                 }
00183         } else if (OverheadCollisonWithIdleUnit(this) || OverheadCollisionWithCity(this)) 
00184         {
00185                 this->m_currState = WANTS_TO_STOP;
00186                 FLOAT newGoal = sys_randFloat() * 40.0F;
00187                 this->m_goalPos = Vec3D(m_currPos.x + newGoal, m_currPos.y + newGoal, 0);
00188         } else 
00189         {
00190                 this->m_currState = IDLE;
00191         }
00192 
00193         // stay on terrain
00194         m_currPos.z = terrain_getHeight( artWork->worldMap, m_currPos.x, m_currPos.y ) + 0.33f;  // 0.33f to offset unit size
00195 }

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

int MilitaryUnit::m_armySize [protected, inherited]
 

Definition at line 86 of file MilitaryUnit.h.

Referenced by MilitaryUnit::armySize().

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(), Jet::goal(), Jet::Jet(), 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 Jet::goal(), MilitaryUnit::goal(), MilitaryUnit::isIdle(), MilitaryUnit::isMoving(), Jet::Jet(), Jet::move(), and MilitaryUnit::move().

Vec3D MilitaryUnit::m_direction [protected, inherited]
 

Definition at line 83 of file MilitaryUnit.h.

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

Vec3D MilitaryUnit::m_goalPos [protected, inherited]
 

Definition at line 89 of file MilitaryUnit.h.

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

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().


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