#include <MilitaryUnit.h>
Inheritance diagram for MilitaryUnit:


Definition at line 35 of file MilitaryUnit.h.
Public Types | |
| enum | State { IDLE, BUSY, WANTS_TO_STOP } |
Public Methods | |
| MilitaryUnit (Vec3D initalPosition, Player *owner, UnitType unitType, const int armySize, Vec3D unitSize) | |
| virtual | ~MilitaryUnit (void) |
| 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 Player * | owner () 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 void | draw () const=0 |
| virtual unsigned int | uniqueID (void) const |
Protected Attributes | |
| Vec3D | m_currPos |
| Vec3D | m_teamColor |
| Vec3D | m_unitSize |
| Vec3D | m_direction |
| Player * | m_pOwner |
| UnitType | m_unitType |
| int | m_armySize |
| State | m_currState |
| Vec3D | m_collisionSize |
| Vec3D | m_goalPos |
| int | m_overheadShortcutKey |
Private Methods | |
| MilitaryUnit & | operator= (MilitaryUnit &rhs) |
| Not defined. Should never be used. | |
| MilitaryUnit (MilitaryUnit &rhs) | |
| Not defined. Should never be used. | |
|
|
states a unit can be in Definition at line 40 of file MilitaryUnit.h.
00040 {IDLE, BUSY, WANTS_TO_STOP};
|
|
||||||||||||||||||||||||
|
Definition at line 35 of file MilitaryUnit.cpp. References Vec3D.
00035 : 00036 m_currPos(initalPosition), 00037 m_teamColor(owner->color()), 00038 m_unitSize(unitSize), 00039 m_direction(Vec3D(0,90.0f,0)), 00040 m_goalPos(initalPosition), 00041 m_unitType(unitType), 00042 m_armySize(armySize), 00043 m_currState(BUSY), 00044 m_collisionSize(unitSize*2), 00045 m_pOwner(owner), 00046 m_overheadShortcutKey(-1) 00047 { 00048 } |
|
|
Definition at line 50 of file MilitaryUnit.cpp.
00051 {
00052 }
|
|
|
Not defined. Should never be used.
|
|
|
Definition at line 105 of file MilitaryUnit.h. References m_armySize. Referenced by NetworkSubsystem::processNetworkData().
00106 {
00107 return m_armySize;
00108 }
|
|
|
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 }
|
|
|
Definition at line 78 of file MilitaryUnit.cpp. References m_collisionSize, m_currPos, and 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 }
|
|
|
Definition at line 210 of file MilitaryUnit.cpp. References m_teamColor, and Vec3D. Referenced by Overhead::getSurroundingUnits(), Jet::goal(), and NetworkSubsystem::processNetworkData().
00211 {
00212 return m_teamColor;
00213 }
|
|
|
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 }
|
|
|
Draws the object at its current location. Implemented in City, LightTank, HeavyTank, RocketLauncher, Artillery, and Jet. |
|
|
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, m_currPos, mesh_render(), and Vec3D.
|
|
|
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 }
|
|
|
Definition at line 89 of file MilitaryUnit.cpp. References m_currPos, and math_distPlanar3D().
00090 {
00091 const FLOAT distanceForAFight(25.0f);
00092 return distanceForAFight > math_distPlanar3D(this->m_currPos, that->m_currPos);
00093 }
|
|
|
What the tank should be moving towards.
Reimplemented in Jet. Definition at line 54 of file MilitaryUnit.cpp. References BUSY, m_currState, and m_goalPos. Referenced by NetworkSubsystem::processNetworkData(), and City::update().
00055 {
00056 this->m_goalPos = dest;
00057 m_currState = BUSY;
00058 }
|
|
|
Definition at line 60 of file MilitaryUnit.cpp. References m_goalPos, and Vec3D.
00061 {
00062 return this->m_goalPos;
00063 }
|
|
|
Definition at line 110 of file MilitaryUnit.h. References IDLE, and m_currState.
00111 {
00112 return m_currState == IDLE;
00113 }
|
|
|
Definition at line 115 of file MilitaryUnit.h. References BUSY, and m_currState.
00116 {
00117 return m_currState == BUSY;
00118 }
|
|
|
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(), IDLE, m_currPos, m_currState, m_direction, m_goalPos, Globals::OverheadCollisionWithCity(), Globals::OverheadCollisonWithIdleUnit(), sys_randFloat(), terrain_getHeight(), Vec2D, Vec3D, 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 }
|
|
|
Definition at line 95 of file MilitaryUnit.cpp. References m_currPos, and math_distPlanar3D().
00096 {
00097 const FLOAT distance(50.0f);
00098 return distance > math_distPlanar3D(this->m_currPos, that->m_currPos);
00099 }
|
|
|
Not defined. Should never be used.
|
|
|
Definition at line 205 of file MilitaryUnit.cpp. References m_pOwner.
00206 {
00207 return this->m_pOwner;
00208 }
|
|
|
Definition at line 215 of file MilitaryUnit.cpp. References m_currPos, and Vec3D. Referenced by collision(), City::collision(), Overhead::deleteMilitaryUnit(), and Overhead::getSurroundingUnits().
00216 {
00217 return this->m_currPos;
00218 }
|
|
|
This number is different for each tank produced Definition at line 239 of file MilitaryUnit.cpp. References m_overheadShortcutKey.
00240 {
00241 m_overheadShortcutKey = key;
00242 }
|
|
|
Definition at line 244 of file MilitaryUnit.cpp. References m_overheadShortcutKey. Referenced by NetworkSubsystem::processNetworkData().
00245 {
00246 return m_overheadShortcutKey;
00247 }
|
|
|
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 }
|
|
|
Definition at line 100 of file MilitaryUnit.h. References m_unitType, and UnitType. Referenced by NetworkSubsystem::processNetworkData(), and HUD::render().
00101 {
00102 return m_unitType;
00103 }
|
|
|
Definition at line 86 of file MilitaryUnit.h. Referenced by armySize(). |
|
|
Definition at line 88 of file MilitaryUnit.h. Referenced by collision(). |
|
|
Definition at line 80 of file MilitaryUnit.h. Referenced by collision(), drawBox(), fightingCollision(), Jet::goal(), Jet::Jet(), Jet::move(), move(), nearEachOther(), and position(). |
|
|
Definition at line 87 of file MilitaryUnit.h. Referenced by Jet::goal(), goal(), isIdle(), isMoving(), Jet::Jet(), Jet::move(), and move(). |
|
|
Definition at line 83 of file MilitaryUnit.h. Referenced by Jet::move(), and move(). |
|
|
Definition at line 89 of file MilitaryUnit.h. Referenced by Jet::goal(), goal(), goalPosition(), Jet::move(), and move(). |
|
|
Definition at line 90 of file MilitaryUnit.h. Referenced by setShortcutKey(), and shortcutKey(). |
|
|
Definition at line 84 of file MilitaryUnit.h. Referenced by owner(). |
|
|
Definition at line 81 of file MilitaryUnit.h. Referenced by color(). |
|
|
Definition at line 82 of file MilitaryUnit.h. |
|
|
Definition at line 85 of file MilitaryUnit.h. Referenced by unitType(). |
1.3-rc2