1 /*****************************************************************************
2  * $LastChangedDate: 2011-04-09 21:58:06 -0400 (Sat, 09 Apr 2011) $
3  * @file
4  * @author  Jim E. Brooks  http://www.palomino3d.org
5  * @brief   Base class for projectiles (missiles, bullets, etc).
6  *//*
7  * LEGAL:   COPYRIGHT (C) 2008 JIM E. BROOKS
8  *          THIS SOURCE CODE IS RELEASED UNDER THE TERMS
9  *          OF THE GNU GENERAL PUBLIC LICENSE VERSION 2 (GPL 2).
10  *****************************************************************************/
11 
12 #ifndef GAME_PROJECTILE_HH
13 #define GAME_PROJECTILE_HH 1
14 
15 #include "object/module.hh"
16 #include "object/dyna.hh"
17 using namespace object;
18 #include "physics/module.hh"
19 using namespace physics;
20 
21 namespace game {
22 
23 ////////////////////////////////////////////////////////////////////////////////
24 /// @brief Base class for projectiles (missiles, bullets, etc).
25 ///
26 /// Lua:
27 /// ----
28 /// Lua determines which Actor is the target.
29 /// Lua interfaces with this C++ class in terms of the Dyna class.
30 ///
31 /// C++:
32 /// ----
33 /// Projectile inherits its matrix and speed from its launcher.
34 /// Every tick, a guidance method defined by the derivative
35 /// rotates the Dyna's matrix to guide the projectile.
36 /// Some derivatives such as Missile may define a target Object
37 /// and guide its projectile towards, while other derivatives
38 /// such as Bullet/Bomb are unguided.
39 ///
40 class Projectile : public Dyna
41 {
42 PREVENT_COPYING(Projectile)
43 typedef Dyna Parent;
44 public:
45                             Projectile( shptr<Graph> graph,
46                                         Object&      launcher,
47                                         const Speed  speed,
48                                         const Meter  maxDistanceGeo,
49                                         const Meter  safeDistanceGeo,
50                                         const bool   malfunction = false );
51     virtual                 ~Projectile();
GetName(void)52     virtual const string    GetName( void ) { return string("Projectile"); }
53 
54 protected:
55     virtual WorldVertex     Guide( const fp step1 ) = 0;
56     virtual void            Explode( void ) = 0;
57     virtual void            HandleCollision( shptr<Object> collider );  // Template Method
58 
59 private:
60     virtual void            Tick( const Milliseconds millisecElapsed );
61 
62 protected:
63     bool                mHit;               ///< if projectile has hit anything
64 private:
65     SpeedKPH            mSpeedKPH;          ///< scalar speed
66     const fp            mMaxDistance;       ///< prevent projectile moving infinitely
67     const fp            mSafeDistance;      ///< distance when collision-detection will be enabled
68     const WorldVertex   mInitialPosition;   ///< initial position of projectile
69     Milliseconds        mPrevTick;          ///< previous tick
70     bool                mCollidable;        ///< temporarily indestructible while launching
71     const bool          mMalfunction;       ///< simulate malfunction
72 public:
73     DECLARE_TYPESIG(TYPESIG_PROJECTILE)
74 };
75 
76 } // namespace game
77 
78 #endif // GAME_PROJECTILE_HH
79