Back to index

extremetuxracer  0.5beta
Public Member Functions | Public Attributes | Static Public Attributes | Private Attributes
Player Class Reference

#include <player.h>

Collaboration diagram for Player:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Player ()
 ~Player ()
bool isCupComplete (std::string event, std::string cup)
bool isFirstIncompleteCup (std::list< EventData >::iterator event, std::list< CupData >::iterator cup)
bool getCupCourseData (std::string event, std::string cup, std::string course, PlayerCourseData &data)
bool updateCupCourseData (std::string event, std::string cup, std::string course, double time, int herring, int score, bool won)
void setCupComplete (std::string event, std::string cup)
void setEventComplete (std::string event)
void clearCupData (std::string event, std::string cup)
bool getOpenCourseData (std::string course, PlayerCourseData &data)
bool updateOpenCourseData (std::string course, double time, int herring, int score)
void resetLives ()
int getLives ()
void decLives ()
void incLives ()
bool saveData ()
bool loadData ()
float getCoursePercentage ()
 returns the the percentage of the course completion related to the player position in the heightmap

Public Attributes

std::string name
 name of player
int health
int herring
int score
int max_speed
bool loaded
pp::Vec3d pos
 current position
pp::Vec3d vel
 current velocity
pp::Quat orientation
 current orientation
bool orientation_initialized
 is orientation initialized?
pp::Vec3d plane_nml
 vector sticking out of bellybutton (assuming on back)
pp::Vec3d direction
 vector sticking out of feet
pp::Vec3d net_force
 net force on player
pp::Vec3d normal_force
 terrain force on player
bool airborne
 is plyr in the air?
bool collision
 has plyr collided with obstacle?
control_t control
 player control data
view_t view
 player's view point

Static Public Attributes

static const int FILE_VERSION = 2

Private Attributes

std::map< std::string,
PlayerEventData
events
std::map< std::string,
PlayerCourseData
courses
int m_lives

Detailed Description

Definition at line 99 of file player.h.


Constructor & Destructor Documentation

Definition at line 196 of file player.cpp.

 : health(100), loaded(false)
{
}

Definition at line 201 of file player.cpp.

{      
}

Member Function Documentation

void Player::clearCupData ( std::string  event,
std::string  cup 
)

Definition at line 269 of file player.cpp.

{
       std::map<std::string,PlayerEventData>::iterator it;
       if( (it=events.find( event ))!=events.end() ){
              (*it).second.clearCupData(cup);
       }
}

Here is the caller graph for this function:

void Player::decLives ( )

Definition at line 290 of file player.cpp.

{
       m_lives--;
}

Here is the caller graph for this function:

returns the the percentage of the course completion related to the player position in the heightmap

Definition at line 447 of file player.cpp.

{
       if(pos.y<0){
              float x,y;    
              get_course_dimensions( &x,&y );
              float correction = 100/tan((get_course_angle())*M_PI/180.0);
              return (((-1)*pos.y)/y)*correction;
       }else{
              return 0;
       }
}

Here is the call graph for this function:

bool Player::getCupCourseData ( std::string  event,
std::string  cup,
std::string  course,
PlayerCourseData data 
)

Definition at line 232 of file player.cpp.

{
       std::map<std::string,PlayerEventData>::iterator it;
       if( (it=events.find( event ))!=events.end() ){
              return (*it).second.getCupCourseData(cup,course,data);
       }
       return false; 
}

Here is the caller graph for this function:

Definition at line 284 of file player.cpp.

{
       return m_lives;
}
bool Player::getOpenCourseData ( std::string  course,
PlayerCourseData data 
)

Definition at line 308 of file player.cpp.

{
       std::map<std::string,PlayerCourseData>::iterator it;
       
       if( (it=courses.find( course ))!=courses.end() ){
              data = (*it).second;
              return true;
       }
       return false;
}
void Player::incLives ( )

Definition at line 296 of file player.cpp.

{
       // todo:
       // in practicing mode incrementing lives should increase score
       if(m_lives < PLAYER_MAX_LIVES){
              m_lives++;
       }
}

Here is the caller graph for this function:

bool Player::isCupComplete ( std::string  event,
std::string  cup 
)

Definition at line 206 of file player.cpp.

{
       std::map<std::string,PlayerEventData>::iterator it;     
       if( (it=events.find( event ))!=events.end() ){
              return (*it).second.isCupWon( cup );
       }else{
              return false; 
       }
}

Here is the caller graph for this function:

bool Player::isFirstIncompleteCup ( std::list< EventData >::iterator  event,
std::list< CupData >::iterator  cup 
)

Definition at line 218 of file player.cpp.

{
       if (cup==(*event).cupList.begin()){
              //first cup in event always playable
              return true;
       } else {
              //check if previous cup was completed
              cup--;
              return isCupComplete((*event).name,(*cup).name);
       }
}

Here is the call graph for this function:

bool Player::loadData ( )

Definition at line 381 of file player.cpp.

{
       char buff[256];

    if (get_config_dir_name( buff, 255 ) != 0) {
              return false;
    }
       
       std::string filename(buff);
              
       filename+="/";
       //filename+=name;
       /*Load from same config for all different nicks, but save last used nick in file*/
       filename+="player";
       filename+=".sav";
       
       std::ifstream sfile(filename.c_str());
       
       if(!sfile) return false;
       
       int version;
       int numcourses;
       int model;
       
       std::string notused;
                     
       sfile >> buff >> buff >> version;
       if(version==FILE_VERSION) {
              sfile >> notused; //character
              sfile >> notused; //difficulty
              sfile >> notused; //num difficulties
              sfile >> name;
              sfile >> model;
              sfile >> numcourses;
              
              for (int i=0; i<numcourses ;i++){
                     double time;
                     int herring;
                     int score;
                     sfile.get();  
                     sfile.getline(buff,256);
                     sfile >> time >> herring >> score;
                     PlayerCourseData& data = courses[buff];
                     data.time=time;
                     data.herring=herring;
                     data.score=score;           
              }
              
              int numevents;
              
              sfile >> numevents;
              for(int i=0; i<numevents; i++){    
                     sfile.get();
                     sfile.getline(buff,256);
                     events[buff].loadData(sfile);
              }
       } else {
              std::cout<<"File versions mismatch, sorry, saved data deleted"<<std::endl;
       }
       ModelHndl->load_model(model);
       loaded=true;
       return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 278 of file player.cpp.

Here is the caller graph for this function:

bool Player::saveData ( )

Definition at line 327 of file player.cpp.

{
       char buff[256];

    if (get_config_dir_name( buff, 255 ) != 0) {
              return false;
    }
       
       std::string filename(buff);
       
       filename+="/";
       //filename+=name;
       /*Load from same config for all different nicks, but save last used nick in file*/
       filename+="player";
       filename+=".sav";
       
       std::ofstream sfile(filename.c_str());
       
       if(name.compare("") == 0) {
              name="tux"; //Make sure the name isn't empty, since it causes errors in the loading.
       }
       
       sfile << "ETRacer SAVE " << FILE_VERSION << std::endl;
       sfile << "tux" << std::endl;
       sfile << "easy" << std::endl;
       sfile << 1 << std::endl;
       sfile << name << std::endl;
       sfile << ModelHndl->cur_model <<std::endl;
       sfile << courses.size() << std::endl;
       
       std::map<std::string,PlayerCourseData>::iterator it;
       
       for(it=courses.begin(); it!=courses.end(); it++){
              sfile << (*it).first << std::endl;
              sfile << (*it).second.time << std::endl;
              sfile << (*it).second.herring << std::endl;
              sfile << (*it).second.score << std::endl;
       }
       
       
       sfile << events.size() << std::endl;
       
       if(events.size()>0){
              std::map<std::string,PlayerEventData>::iterator it;
              for (it=events.begin(); it!=events.end(); it++){
                     sfile << (*it).first << std::endl; 
                     (*it).second.saveData(sfile);             
              }
       }
       
       return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void Player::setCupComplete ( std::string  event,
std::string  cup 
)

Definition at line 257 of file player.cpp.

{
       events[event].setCupComplete(cup); 
}

Here is the caller graph for this function:

void Player::setEventComplete ( std::string  event)

Definition at line 263 of file player.cpp.

{
       events[event].won=true;     
}

Here is the caller graph for this function:

bool Player::updateCupCourseData ( std::string  event,
std::string  cup,
std::string  course,
double  time,
int  herring,
int  score,
bool  won 
)

Definition at line 245 of file player.cpp.

{
       return events[event].updateCupCourseData(cup,course,time,herring,score,won);
}

Here is the caller graph for this function:

bool Player::updateOpenCourseData ( std::string  course,
double  time,
int  herring,
int  score 
)

Definition at line 320 of file player.cpp.

{
       return courses[course].update(time,herring,score);
}

Here is the caller graph for this function:


Member Data Documentation

is plyr in the air?

Definition at line 194 of file player.h.

has plyr collided with obstacle?

Definition at line 197 of file player.h.

player control data

Definition at line 200 of file player.h.

std::map<std::string,PlayerCourseData> Player::courses [private]

Definition at line 103 of file player.h.

vector sticking out of feet

Definition at line 185 of file player.h.

std::map<std::string,PlayerEventData> Player::events [private]

Definition at line 101 of file player.h.

const int Player::FILE_VERSION = 2 [static]

Definition at line 111 of file player.h.

Definition at line 158 of file player.h.

Definition at line 160 of file player.h.

Definition at line 167 of file player.h.

int Player::m_lives [private]

Definition at line 105 of file player.h.

Definition at line 164 of file player.h.

std::string Player::name

name of player

Definition at line 155 of file player.h.

net force on player

Definition at line 188 of file player.h.

terrain force on player

Definition at line 191 of file player.h.

current orientation

Definition at line 176 of file player.h.

is orientation initialized?

Definition at line 179 of file player.h.

vector sticking out of bellybutton (assuming on back)

Definition at line 182 of file player.h.

current position

Definition at line 170 of file player.h.

Definition at line 162 of file player.h.

current velocity

Definition at line 173 of file player.h.

player's view point

Definition at line 203 of file player.h.


The documentation for this class was generated from the following files: