Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/network/player_stats.cc @ 8454

Last change on this file since 8454 was 8362, checked in by bensch, 18 years ago

orxonox/trunk: removed stupid included in base_object.h
this should lead to faster compile-times

File size: 3.9 KB
RevLine 
[7974]1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
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.
10
11### File Specific:
12   main-programmer: Christoph Renner
13   co-programmer: ...
14*/
15
16#include "player_stats.h"
17
18#include "class_list.h"
19#include "src/lib/util/loading/factory.h"
20
[7984]21#include "player.h"
22#include "state.h"
[8228]23#include "shared_network_data.h"
[7974]24
[8362]25#include "debug.h"
[7984]26
[8362]27
[7974]28CREATE_FACTORY(PlayerStats, CL_PLAYER_STATS);
29
30/**
31 * constructor
32 */
33PlayerStats::PlayerStats( int userId )
34{
35  init();
[8362]36
[7974]37  this->userId = userId;
38}
39
40/**
41 * constructor
42 */
43PlayerStats::PlayerStats( const TiXmlElement* root )
44{
45  init();
46}
47
48void PlayerStats::init( )
49{
50  this->setClassID( CL_PLAYER_STATS, "PlayerStats" );
51
52  this->userId = 0;
[8067]53  this->teamId = TEAM_NOTEAM;
54  this->preferedTeamId = TEAM_NOTEAM;
[7974]55  this->score = 0;
56  this->playableClassId = 0;
57  this->modelFileName = "";
[8362]58
[7974]59  userId_handle = registerVarId( new SynchronizeableInt( &userId, &userId, "userId" ) );
[8067]60  teamId_handle = registerVarId( new SynchronizeableInt( &teamId, &teamId, "teamId" ) );
61  preferedTeamId_handle = registerVarId( new SynchronizeableInt( &preferedTeamId, &preferedTeamId, "preferedUserId" ) );
[7974]62  score_handle = registerVarId( new SynchronizeableInt( &score, &score, "score" ) );
63  playableClassId_handle = registerVarId( new SynchronizeableInt( &playableClassId, &playableClassId, "playableClassId") );
64  playableUniqueId_handle = registerVarId( new SynchronizeableInt( &playableUniqueId, &playableUniqueId, "playableUniqueId" ) );
65  modelFileName_handle = registerVarId( new SynchronizeableString( &modelFileName, &modelFileName, "modelFileName" ) );
[8362]66
[8014]67  PRINTF(0)("PlayerStats created\n");
[7974]68}
69
70
71/**
72 * standard deconstructor
73 */
74PlayerStats::~PlayerStats()
75{
76}
77
78
79 /**
80 * override this function to be notified on change
81 * of your registred variables.
82 * @param id id's which have changed
83  */
84void PlayerStats::varChangeHandler( std::list< int > & id )
85{
86  if ( std::find( id.begin(), id.end(), playableUniqueId_handle ) != id.end() )
87  {
88    this->setPlayableUniqueId( this->playableUniqueId );
[8362]89
[8228]90    PRINTF(0)("uniqueID changed %d %d %d\n", userId, getHostID(), getUniqueID());
[7974]91  }
92}
93
94/**
95 * get stats for user userId
96 * @param userId user's id
97 * @return stats assigned to user
98 */
99PlayerStats * PlayerStats::getStats( int userId )
100{
101  const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYER_STATS );
[8362]102
[8147]103  if ( !list )
[8228]104  {
[8147]105    return NULL;
[8228]106  }
[8362]107
[7974]108  for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ )
109  {
110    if ( dynamic_cast<PlayerStats*>(*it)->getUserId() == userId )
111    {
112      return dynamic_cast<PlayerStats*>(*it);
113    }
114  }
[8362]115
[7974]116  return NULL;
117}
118
119/**
120 * set playable class id and set playable
121 */
122void PlayerStats::setPlayableUniqueId( int uniqueId )
123{
124  const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYABLE );
[8362]125
[8147]126  if ( !list )
127  {
128    this->playableUniqueId = uniqueId;
129    return;
130  }
[8362]131
[7974]132  this->playable = NULL;
133  for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ )
134  {
135    if ( dynamic_cast<Playable*>(*it)->getUniqueID() == uniqueId )
136    {
137      this->playable = dynamic_cast<Playable*>(*it);
[8228]138      //TODO when OM_PLAYERS is ticked add line:
139      //this->playable->toList( OM_PLAYERS );
[7974]140      break;
141    }
142  }
[8362]143
[8147]144  if ( this->playable && userId == getHostID() )
[8228]145  {
[8147]146    State::getPlayer()->setPlayable( this->playable );
[8228]147  }
[8362]148
[7974]149  this->playableUniqueId = uniqueId;
150}
151
152/**
153 * get playable associated to player
154 * @return playable associated to player
155 */
156Playable * PlayerStats::getPlayable()
157{
158  if ( playable )
159    return playable;
[8362]160
[7974]161  assert( playableUniqueId > 0 );
[8362]162
[7974]163  setPlayableUniqueId( playableUniqueId );
[8362]164
[7974]165  assert( playable );
[8362]166
[7974]167  return playable;
168}
169
170
Note: See TracBrowser for help on using the repository browser.