mod_sim_game.hh

Go to the documentation of this file.
00001 /*
00008  * LEGAL:   COPYRIGHT (C) 2007 JIM E. BROOKS
00009  *          THIS SOURCE CODE IS RELEASED UNDER THE TERMS
00010  *          OF THE GNU GENERAL PUBLIC LICENSE VERSION 2 (GPL 2).
00011  *****************************************************************************/
00012 
00013 #if COMPILING_MODULE//_SIM
00014 #ifndef MOD_SIM_GAME_HH
00015 #define MOD_SIM_GAME_HH 1
00016 
00017 #include "mod_sim_sound.hh"
00018 
00019 namespace mod_sim {
00020 namespace game {
00021 
00022 #define gGame (gModule.GetGame())
00023 
00024 class Actor;
00025 class CraftActor;
00026 
00034 class Game : public Shared
00035 {
00036 
00037 
00038 public:
00039     typedef int TeamNum;
00040     enum { TEAM_NONE, TEAM1, TEAM2 };
00041 
00042 private:
00046     class TimerFunctor : public Timer::Functor
00047     {
00048     public:
00049         TimerFunctor( Game& game ) : mGame(game) { }
00050         void operator()( const Milliseconds millisecElapsed );
00051     private:
00052         Game&   mGame;
00053     };
00054 
00055 private:
00059     class IdleFunctor : public Event<>::ListenerFunctor
00060     {
00061     public:
00062         IdleFunctor( Game& game ) : mGame(game) { }
00063         void operator()( Void nothing );
00064     private:
00065         Game&   mGame;
00066     };
00067     friend class IdleFunctor;
00068 
00069 private:
00076     class MultiView : public eng::View
00077     {
00078     public:
00079         enum eMode { eMode_DISABLED,
00080                      eMode_REAR_VIEW,
00081                      eMode_MISSILE_VIEW };
00082 
00083                     MultiView( const Rect<int>& rect );
00084         void        Reshape( const Rect<int>& mainViewRect );
00085         void        SetMode( eMode mode );
00086         eMode       GetMode( void );
00087         void        Tick( void );
00088         CLASS_VAR Rect<int> ComputeRect( const Rect<int>& mainViewRect );
00089 
00090     private:
00091         eMode       mMode;
00092     };
00093 
00094 private:
00095     // Listener for the post-draw event of one View.
00096     struct ListenerPostDrawOneView : public Event<SharedPtr<View> >::ListenerFunctor
00097     {
00098         void operator()( SharedPtr<View> view );
00099     };
00100     friend struct ListenerPostDrawOneView;
00101 
00102 //..............................................................................
00103 
00104 // Types:
00105 private:    typedef uint ActorId;
00106 public:     typedef map<ActorId,SharedPtr<Actor> >      Actors;
00107 public:     typedef map<ActorId,SharedPtr<CraftActor> > CraftActors;
00108 public:     enum eTargets { eTargets_ALL, eTargets_MISSILE_LOCK };
00109 
00110 // Methods:
00111 public:                         Game( void );
00112 public:     void                Init( void );
00113 public:                         ~Game();
00114 public:     mod_sim::Sound&     GetSound( void ) { return mSound; }
00115 public:     int                 GetScore( void );
00116 public:     void                AddScore( int points );
00117 public:     void                AddActor( SharedPtr<Actor> actor );
00118 public:     void                AddCraftActor( SharedPtr<CraftActor> craftActor );
00119 public:     void                ZombifyActor( SharedPtr<Actor> actor );
00120 public:     SharedPtr<CraftActor>   GetPlayerActor( void ) { return mPlayerActor; }
00121 public:     CraftActors         GetPlayerTargets( const eTargets whichTargets );
00122 public:     void                SetPlayerHasMissileLock( const bool hasLock );
00123 public:     bool                IfPlayerHasMissileLock( void );
00124 public:     void                UpdateMissileView( const Matrix& m );
00125 public:     void                ReleaseMissileView( void );
00126 public:     void                SpawnEnemyCraft( const uint num );
00127 private:    void                Tick( const Milliseconds millisecElapsed );
00128 private:    void                Idle( void );
00129 
00130 // Data:
00131 private:    CLASS_CONST uint    MAX_TARGETS = 500;
00132 private:    CLASS_VAR set<ActorId> msZombieActors;      
00133 private:    shptr<TimerFunctor> mTimerFunctor;          
00134 private:    shptr<IdleFunctor>  mIdleFunctor;           
00135 private:    shptr<MultiView>    mMultiView;             
00136 public:     GFX::Light          mLightMissile;          
00137 private:    mod_sim::Sound      mSound;                 
00138 private:    shptr<CraftActor>   mPlayerActor;           
00139 private:    Actors              mActors;                
00140 private:    CraftActors         mCraftActors;           
00141 private:    int                 mScore;
00142 private:    bool                mPlayerHasMissileLock;  
00143 private:    uint                mEnemyCraftSpawned;
00144 };
00145 
00151 class Actor : public Shared
00152 {
00153 
00154 friend class Game;
00155 public:
00156                         Actor( const string& name = "", Game::TeamNum teamNum = Game::TEAM_NONE, SharedPtr0<Object> = NULL );
00157     virtual             ~Actor();
00158     virtual void        Action( const Milliseconds millisecElapsed ) { }
00159     SharedPtr0<Object>      GetObject( void ) { return mObject; }
00160     const string        GetName( void ) const { return mName; }
00161     virtual WorldVertex GetPosition( void ) const { return WorldVertex(0.0,0.0,0.0); }
00162     bool                IfFriendly( SharedPtr<Actor> other ) const { return mTeamNum == other->mTeamNum; }
00163     bool                IfDummy( void ) const { return mTeamNum == Game::TEAM_NONE; }  // dummy actor
00164     virtual bool        IfUnderMissileLock( void ) { return false; }
00165     virtual void        SetFollowedByMissile( bool followed ) { }  // NOP
00166     virtual bool        IfFollowedByMissile( void ) { return false; }  // NOP
00167 
00168 private:
00169     typedef uint Id;  // for key of STL map
00170     Id              GetId( void ) { return mId; }
00171 
00172 private:
00173     CLASS_VAR Id            msId;
00174     const string            mName;
00175     const Game::TeamNum     mTeamNum;
00176     SharedPtr0<Object>          mObject;
00177     const Id                mId;
00178 public:
00179     
00180 };
00181 
00187 class CraftActor : public Actor
00188 {
00189 
00190 public:
00191                             CraftActor( const string& name, Game::TeamNum teamNum, SharedPtr0<Craft> craft );
00192     virtual                 ~CraftActor();
00193     virtual WorldVertex     GetPosition( void ) const { return GetCraft()->GetPosition(); }
00194     virtual SharedPtr<Craft>    GetCraft( void ) const { return mCraft.PTR(); }
00195     void                    SetUnderMissileLock( const bool lock ) { mUnderMissileLock = lock; }
00196     virtual bool            IfUnderMissileLock( void ) { return mUnderMissileLock; }
00197     virtual void            SetFollowedByMissile( bool followed ) { mFollowedByMissile = followed; }
00198     virtual bool            IfFollowedByMissile( void ) { return mFollowedByMissile; }
00199 
00200 private:
00201     SharedPtr0<Craft>   mCraft;
00202     bool            mUnderMissileLock;      
00203     bool            mFollowedByMissile;     
00204 };
00205 
00211 class PlayerCraftActor : public CraftActor
00212 {
00213 
00214 public:
00215                             PlayerCraftActor( const string& name, Game::TeamNum teamNum );
00216     virtual                 ~PlayerCraftActor();
00217     virtual SharedPtr<Craft>    GetCraft( void ) const;
00218 };
00219 
00220 } // namespace game
00221 } // namespace mod_sim
00222 
00223 #endif // MOD_SIM_GAME_HH
00224 #endif // COMPILING_MODULE//_SIM
Palomino 3D Engine documents generated by doxygen 1.5.3 on Fri Nov 23 11:26:12 2007