Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 8014 was 8014, checked in by rennerc, 19 years ago

new NetworkGameManager works now

File size: 3.5 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 = 0;
51  this->score = 0;
52  this->playableClassId = 0;
53  this->modelFileName = "";
54 
55  userId_handle = registerVarId( new SynchronizeableInt( &userId, &userId, "userId" ) );
56  groupId_handle = registerVarId( new SynchronizeableInt( &teamId, &teamId, "teamId" ) );
57  score_handle = registerVarId( new SynchronizeableInt( &score, &score, "score" ) );
58  playableClassId_handle = registerVarId( new SynchronizeableInt( &playableClassId, &playableClassId, "playableClassId") );
59  playableUniqueId_handle = registerVarId( new SynchronizeableInt( &playableUniqueId, &playableUniqueId, "playableUniqueId" ) );
60  modelFileName_handle = registerVarId( new SynchronizeableString( &modelFileName, &modelFileName, "modelFileName" ) );
61 
62  PRINTF(0)("PlayerStats created\n");
63}
64
65
66/**
67 * standard deconstructor
68 */
69PlayerStats::~PlayerStats()
70{
71}
72
73
74 /**
75 * override this function to be notified on change
76 * of your registred variables.
77 * @param id id's which have changed
78  */
79void PlayerStats::varChangeHandler( std::list< int > & id )
80{
81  if ( std::find( id.begin(), id.end(), playableUniqueId_handle ) != id.end() )
82  {
83    this->setPlayableUniqueId( this->playableUniqueId );
84   
85    PRINTF(0)("uniqueID changed %d %d\n", userId, getHostID());
86   
87    if ( userId == getHostID() )
88      State::getPlayer()->setPlayable( getPlayable() );
89  }
90}
91
92/**
93 * get stats for user userId
94 * @param userId user's id
95 * @return stats assigned to user
96 */
97PlayerStats * PlayerStats::getStats( int userId )
98{
99  const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYER_STATS );
100 
101  for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ )
102  {
103    if ( dynamic_cast<PlayerStats*>(*it)->getUserId() == userId )
104    {
105      return dynamic_cast<PlayerStats*>(*it);
106    }
107  }
108 
109  //TODO maybe we should create an object here
110 
111  return NULL;
112}
113
114/**
115 * set playable class id and set playable
116 */
117void PlayerStats::setPlayableUniqueId( int uniqueId )
118{
119  const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYABLE );
120 
121  this->playable = NULL;
122  for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ )
123  {
124    if ( dynamic_cast<Playable*>(*it)->getUniqueID() == uniqueId )
125    {
126      this->playable = dynamic_cast<Playable*>(*it);
127      break;
128    }
129  }
130 
131  this->playableUniqueId = uniqueId;
132}
133
134/**
135 * get playable associated to player
136 * @return playable associated to player
137 */
138Playable * PlayerStats::getPlayable()
139{
140  if ( playable )
141    return playable;
142 
143  assert( playableUniqueId > 0 );
144 
145  setPlayableUniqueId( playableUniqueId );
146 
147  assert( playable );
148 
149  return playable;
150}
151
152
Note: See TracBrowser for help on using the repository browser.