Back to index

extremetuxracer  0.5beta
player.h
Go to the documentation of this file.
00001 /* 
00002  * PPRacer 
00003  * Copyright (C) 2004-2005 Volker Stroebel <volker@planetpenguin.de>
00004  *  
00005  * Copyright (C) 1999-2001 Jasmin F. Patry
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  * 
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  * 
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00020  */
00021 
00022 
00023 #ifndef _PLAYER_H_
00024 #define _PLAYER_H_
00025 
00026 #include "course_mgr.h"
00027 
00028 #include <list>
00029 #include <map>
00030 #include <string>
00031 #include <fstream>
00032 
00033 
00034 class PlayerCourseData
00035 {
00036 public:
00037        PlayerCourseData();  
00038 
00039        bool update(double time,int herring,int score, bool won=true);
00040 
00041        bool won;
00042     double time;
00043     int herring;
00044     int score;
00045 };
00046 
00047 
00048 class PlayerCupData
00049 {
00050        std::map<std::string,PlayerCourseData> courses;
00051 public:
00052        PlayerCupData();
00053 
00054        bool won;
00055 
00056        bool getCupCourseData(std::string course,
00057                                    PlayerCourseData& data);
00058        bool updateCupCourseData(std::string course, 
00059                                    double time, 
00060                                    int herring,
00061                                    int score,
00062                                    bool won);
00063        
00064        bool loaded;
00065 
00066        void saveData(std::ofstream& sfile);
00067        void loadData(std::ifstream& sfile);
00068 };
00069 
00070 class PlayerEventData
00071 {
00072        std::map<std::string,PlayerCupData> cups; 
00073 public:
00074        PlayerEventData();
00075 
00076        bool won;     
00077 
00078        bool isCupWon(std::string cup);
00079        bool getCupCourseData(std::string cup,
00080                                    std::string course,
00081                                    PlayerCourseData& data);
00082        bool updateCupCourseData(std::string cup,
00083                                    std::string course, 
00084                                    double time, 
00085                                    int herring,
00086                                    int score,
00087                                    bool won);
00088        void setCupComplete(std::string cup);
00089 
00090        void clearCupData(std::string cup);
00091 
00092        bool loaded;
00093 
00094        void saveData(std::ofstream& sfile);
00095        void loadData(std::ifstream& sfile);
00096 };
00097 
00098 
00099 class Player
00100 {
00101        std::map<std::string,PlayerEventData> events;
00102        
00103        std::map<std::string,PlayerCourseData> courses;
00104        
00105        int m_lives;
00106        
00107 public:
00108        Player();
00109        ~Player();
00110 
00111        static const int FILE_VERSION=2;
00112 
00113        bool isCupComplete(std::string event,
00114                                           std::string cup);
00115        bool isFirstIncompleteCup( std::list<EventData>::iterator event,
00116                                           std::list<CupData>::iterator cup);
00117        
00118        bool getCupCourseData(std::string event,
00119                                    std::string cup,
00120                                    std::string course,
00121                                    PlayerCourseData& data);
00122 
00123        bool updateCupCourseData(std::string event,
00124                                    std::string cup,
00125                                    std::string course, 
00126                                    double time, 
00127                                    int herring,
00128                                    int score,
00129                                    bool won);
00130 
00131        void setCupComplete(std::string event, std::string cup);
00132        void setEventComplete(std::string event);
00133        
00134        void clearCupData(std::string event, std::string cup);
00135        
00136 
00137        bool getOpenCourseData(std::string course,
00138                                                         PlayerCourseData& data);
00139 
00140        bool updateOpenCourseData(std::string course, 
00141                                                         double time, 
00142                                                         int herring,
00143                                                         int score);
00144 
00145        void resetLives();
00146        int getLives();
00147        void decLives();
00148        void incLives();
00149        
00150        
00151        bool saveData();
00152        bool loadData();     
00153        
00155        std::string name;
00156        
00157        // for future use
00158        int health;
00159        
00160        int herring;
00161        
00162        int score;
00163        
00164        int max_speed;
00165 
00166        // to check if loadData was executed
00167        bool loaded;
00168 
00170        pp::Vec3d pos;   
00171        
00173        pp::Vec3d vel;
00174        
00176        pp::Quat orientation; 
00177        
00179        bool orientation_initialized;
00180        
00182        pp::Vec3d plane_nml;
00183        
00185        pp::Vec3d direction; 
00186        
00188        pp::Vec3d net_force;
00189        
00191        pp::Vec3d normal_force;  
00192        
00194        bool airborne;
00195        
00197        bool collision;
00198        
00200        control_t control;
00201 
00203        view_t view;
00204        
00205        float getCoursePercentage();           
00206 };
00207 
00209 extern Player players[1];
00210 
00211 #endif // _PLAYER_H_