Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/gui/src/lib/network/player_stats.cc @ 8240

Last change on this file since 8240 was 8147, checked in by bensch, 19 years ago

orxonox/trunk: merged the network branche back here
merged with command:
svn merge -r8070:HEAD https://svn.orxonox.net/orxonox/branches/network .
no conflicts

File size: 3.8 KB
Line 
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
21#include "player.h"
22#include "state.h"
23
24
25CREATE_FACTORY(PlayerStats, CL_PLAYER_STATS);
26
27/**
28 * constructor
29 */
30PlayerStats::PlayerStats( int userId )
31{
32  init();
33 
34  this->userId = userId;
35}
36
37/**
38 * constructor
39 */
40PlayerStats::PlayerStats( const TiXmlElement* root )
41{
42  init();
43}
44
45void PlayerStats::init( )
46{
47  this->setClassID( CL_PLAYER_STATS, "PlayerStats" );
48
49  this->userId = 0;
50  this->teamId = TEAM_NOTEAM;
51  this->preferedTeamId = TEAM_NOTEAM;
52  this->score = 0;
53  this->playableClassId = 0;
54  this->modelFileName = "";
55 
56  userId_handle = registerVarId( new SynchronizeableInt( &userId, &userId, "userId" ) );
57  teamId_handle = registerVarId( new SynchronizeableInt( &teamId, &teamId, "teamId" ) );
58  preferedTeamId_handle = registerVarId( new SynchronizeableInt( &preferedTeamId, &preferedTeamId, "preferedUserId" ) );
59  score_handle = registerVarId( new SynchronizeableInt( &score, &score, "score" ) );
60  playableClassId_handle = registerVarId( new SynchronizeableInt( &playableClassId, &playableClassId, "playableClassId") );
61  playableUniqueId_handle = registerVarId( new SynchronizeableInt( &playableUniqueId, &playableUniqueId, "playableUniqueId" ) );
62  modelFileName_handle = registerVarId( new SynchronizeableString( &modelFileName, &modelFileName, "modelFileName" ) );
63 
64  PRINTF(0)("PlayerStats created\n");
65}
66
67
68/**
69 * standard deconstructor
70 */
71PlayerStats::~PlayerStats()
72{
73}
74
75
76 /**
77 * override this function to be notified on change
78 * of your registred variables.
79 * @param id id's which have changed
80  */
81void PlayerStats::varChangeHandler( std::list< int > & id )
82{
83  if ( std::find( id.begin(), id.end(), playableUniqueId_handle ) != id.end() )
84  {
85    this->setPlayableUniqueId( this->playableUniqueId );
86   
87    PRINTF(0)("uniqueID changed %d %d\n", userId, getHostID());
88  }
89}
90
91/**
92 * get stats for user userId
93 * @param userId user's id
94 * @return stats assigned to user
95 */
96PlayerStats * PlayerStats::getStats( int userId )
97{
98  const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYER_STATS );
99 
100  if ( !list )
101    return NULL;
102 
103  for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ )
104  {
105    if ( dynamic_cast<PlayerStats*>(*it)->getUserId() == userId )
106    {
107      return dynamic_cast<PlayerStats*>(*it);
108    }
109  }
110 
111  //TODO maybe we should create an object here
112 
113  return NULL;
114}
115
116/**
117 * set playable class id and set playable
118 */
119void PlayerStats::setPlayableUniqueId( int uniqueId )
120{
121  const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYABLE );
122 
123  if ( !list )
124  {
125    this->playableUniqueId = uniqueId;
126    return;
127  }
128 
129  this->playable = NULL;
130  for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ )
131  {
132    if ( dynamic_cast<Playable*>(*it)->getUniqueID() == uniqueId )
133    {
134      this->playable = dynamic_cast<Playable*>(*it);
135      break;
136    }
137  }
138 
139  if ( this->playable && userId == getHostID() )
140    State::getPlayer()->setPlayable( this->playable );
141 
142  this->playableUniqueId = uniqueId;
143}
144
145/**
146 * get playable associated to player
147 * @return playable associated to player
148 */
149Playable * PlayerStats::getPlayable()
150{
151  if ( playable )
152    return playable;
153 
154  assert( playableUniqueId > 0 );
155 
156  setPlayableUniqueId( playableUniqueId );
157 
158  assert( playable );
159 
160  return playable;
161}
162
163
Note: See TracBrowser for help on using the repository browser.