Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8188 in orxonox.OLD for branches/network/src/lib


Ignore:
Timestamp:
Jun 7, 2006, 2:47:11 PM (19 years ago)
Author:
rennerc
Message:

no comment :D

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/network/src/lib/network/player_stats.h

    r8187 r8188  
    1 /*
    2    orxonox - the future of 3D-vertical-scrollers
     1/*!
     2 * @file player_stats.h
     3 * @brief Definition of PlayerStats
     4 */
    35
    4    Copyright (C) 2004 orx
     6#ifndef _PLAYER_STATS_H
     7#define _PLAYER_STATS_H
    58
    6    This program is free software; you can redistribute it and/or modify
    7    it under the terms of the GNU General Public License as published by
    8    the Free Software Foundation; either version 2, or (at your option)
    9    any later version.
     9#include "synchronizeable.h"
     10#include "playable.h"
    1011
    11 ### File Specific:
    12    main-programmer: Christoph Renner
    13    co-programmer: ...
    14 */
     12#include <string>
     13#include <list>
    1514
    16 #include "player_stats.h"
     15enum
     16{
     17  TEAM_NOTEAM = -3,
     18  TEAM_RANDOM = -2,
     19  TEAM_SPECTATOR = -1
     20};
    1721
    18 #include "class_list.h"
    19 #include "src/lib/util/loading/factory.h"
     22//! A class for storing player information
     23class PlayerStats : public Synchronizeable
     24{
    2025
    21 #include "player.h"
    22 #include "state.h"
    23 #include "shared_network_data.h"
     26  public:
     27    PlayerStats( const TiXmlElement* root = NULL );
     28    PlayerStats( int userId );
     29    virtual ~PlayerStats();
     30   
     31    virtual void varChangeHandler( std::list<int> & id );
     32   
     33    static PlayerStats * getStats( int userId );
     34   
     35    inline int getUserId(){ return userId; }
     36   
     37    inline int getTeamId(){ return teamId; }
     38    inline void setTeamId( int teamId ){ this->teamId = teamId; }
     39   
     40    inline int getPreferedTeamId(){ return preferedTeamId; }
     41    inline void setPreferedTeamId( int preferedTeamId ){ this->preferedTeamId = preferedTeamId; }
     42   
     43    inline int getScore(){ return score; }
     44    inline void setScore( int score ){ this->score = score; }
     45   
     46    inline int getPlayableClassId(){ return playableClassId; }
     47    void setPlayableClassId( int classId ){ this->playableClassId = classId; };
     48   
     49    inline int getPlayableUniqueId(){ return playableUniqueId; }
     50    void setPlayableUniqueId( int uniqueId );
     51   
     52    inline std::string getModelFileName(){ return modelFileName; }
     53    inline void setModelFileName( std::string filename ){ modelFileName = filename; }
     54   
     55    Playable * getPlayable();
    2456
     57  private:
     58    int userId;                //!< userId
     59    int teamId;                //!< teamId
     60    int preferedTeamId;        //!< preferedTeamId
    2561
    26 CREATE_FACTORY(PlayerStats, CL_PLAYER_STATS);
     62    int score;                 //!< users score points
     63    int playableClassId;       //!< players playable class id
     64    int playableUniqueId;      //!< playable's uniqueId
     65    std::string modelFileName; //!< model filename
    2766
    28 /**
    29  * constructor
    30  */
    31 PlayerStats::PlayerStats( int userId )
    32 {
    33   init();
    34  
    35   this->userId = userId;
    36 }
     67    Playable * playable;       //!< pointer to players playable
    3768
    38 /**
    39  * constructor
    40  */
    41 PlayerStats::PlayerStats( const TiXmlElement* root )
    42 {
    43   init();
    44 }
     69    // handles for SynchronizeableVars
     70    int userId_handle;
     71    int teamId_handle;
     72    int preferedTeamId_handle;
     73    int score_handle;
     74    int playableClassId_handle;
     75    int playableUniqueId_handle;
     76    int modelFileName_handle;
     77   
     78    void init();
     79};
    4580
    46 void PlayerStats::init( )
    47 {
    48   this->setClassID( CL_PLAYER_STATS, "PlayerStats" );
    49 
    50   this->userId = 0;
    51   this->teamId = TEAM_NOTEAM;
    52   this->preferedTeamId = TEAM_NOTEAM;
    53   this->score = 0;
    54   this->playableClassId = 0;
    55   this->modelFileName = "";
    56  
    57   userId_handle = registerVarId( new SynchronizeableInt( &userId, &userId, "userId" ) );
    58   teamId_handle = registerVarId( new SynchronizeableInt( &teamId, &teamId, "teamId" ) );
    59   preferedTeamId_handle = registerVarId( new SynchronizeableInt( &preferedTeamId, &preferedTeamId, "preferedUserId" ) );
    60   score_handle = registerVarId( new SynchronizeableInt( &score, &score, "score" ) );
    61   playableClassId_handle = registerVarId( new SynchronizeableInt( &playableClassId, &playableClassId, "playableClassId") );
    62   playableUniqueId_handle = registerVarId( new SynchronizeableInt( &playableUniqueId, &playableUniqueId, "playableUniqueId" ) );
    63   modelFileName_handle = registerVarId( new SynchronizeableString( &modelFileName, &modelFileName, "modelFileName" ) );
    64  
    65   PRINTF(0)("PlayerStats created\n");
    66 }
    67 
    68 
    69 /**
    70  * standard deconstructor
    71  */
    72 PlayerStats::~PlayerStats()
    73 {
    74 }
    75 
    76 
    77  /**
    78  * override this function to be notified on change
    79  * of your registred variables.
    80  * @param id id's which have changed
    81   */
    82 void PlayerStats::varChangeHandler( std::list< int > & id )
    83 {
    84   if ( std::find( id.begin(), id.end(), playableUniqueId_handle ) != id.end() )
    85   {
    86     this->setPlayableUniqueId( this->playableUniqueId );
    87    
    88     PRINTF(0)("uniqueID changed %d %d %d\n", userId, getHostID(), getUniqueID());
    89   }
    90 }
    91 
    92 /**
    93  * get stats for user userId
    94  * @param userId user's id
    95  * @return stats assigned to user
    96  */
    97 PlayerStats * PlayerStats::getStats( int userId )
    98 {
    99   const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYER_STATS );
    100  
    101   if ( !list )
    102   {
    103     return NULL;
    104   }
    105  
    106   for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ )
    107   {
    108     if ( dynamic_cast<PlayerStats*>(*it)->getUserId() == userId )
    109     {
    110       return dynamic_cast<PlayerStats*>(*it);
    111     }
    112   }
    113  
    114   return NULL;
    115 }
    116 
    117 /**
    118  * set playable class id and set playable
    119  */
    120 void PlayerStats::setPlayableUniqueId( int uniqueId )
    121 {
    122   const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYABLE );
    123  
    124   if ( !list )
    125   {
    126     this->playableUniqueId = uniqueId;
    127     return;
    128   }
    129  
    130   this->playable = NULL;
    131   for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ )
    132   {
    133     if ( dynamic_cast<Playable*>(*it)->getUniqueID() == uniqueId )
    134     {
    135       this->playable = dynamic_cast<Playable*>(*it);
    136       break;
    137     }
    138   }
    139  
    140   if ( this->playable && userId == getHostID() )
    141   {
    142     State::getPlayer()->setPlayable( this->playable );
    143   }
    144  
    145   this->playableUniqueId = uniqueId;
    146 }
    147 
    148 /**
    149  * get playable associated to player
    150  * @return playable associated to player
    151  */
    152 Playable * PlayerStats::getPlayable()
    153 {
    154   if ( playable )
    155     return playable;
    156  
    157   assert( playableUniqueId > 0 );
    158  
    159   setPlayableUniqueId( playableUniqueId );
    160  
    161   assert( playable );
    162  
    163   return playable;
    164 }
    165 
    166 
     81#endif /* _PLAYER_STATS_H */
Note: See TracChangeset for help on using the changeset viewer.