Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/objecthierarchy/src/orxonox/objects/infos/PlayerInfo.cc @ 2019

Last change on this file since 2019 was 2019, checked in by landauf, 17 years ago

many changes, most important: BaseObject takes now a pointer to it's creator which is needed to build a level hierarchy (with different scenes)

File size: 4.9 KB
RevLine 
[1940]1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Fabian 'x3n' Landau
24 *   Co-authors:
25 *      ...
26 *
27 */
28
[2019]29#include <cassert>
30
[1947]31#include "OrxonoxStableHeaders.h"
[1940]32#include "PlayerInfo.h"
33
34#include "core/CoreIncludes.h"
[2006]35#include "network/ClientInformation.h"
[1940]36#include "objects/gametypes/Gametype.h"
37
38namespace orxonox
39{
[2019]40    PlayerInfo::PlayerInfo(BaseObject* creator) : Info(creator)
[1940]41    {
42        RegisterObject(PlayerInfo);
43
[1953]44        this->clientID_ = network::CLIENTID_UNKNOWN;
[2019]45        this->bHumanPlayer_ = false;
[1940]46        this->bLocalPlayer_ = false;
[2019]47        this->bReadyToSpawn_ = false;
[1993]48        this->controller_ = 0;
[2019]49        this->controllableEntity_ = 0;
50        this->controllableEntityID_ = network::CLIENTID_UNKNOWN;
[1989]51
[1940]52        this->registerVariables();
53    }
54
55    PlayerInfo::~PlayerInfo()
56    {
[1993]57        if (this->isInitialized())
58        {
[2019]59            this->stopControl(this->controllableEntity_);
[1993]60
61            if (this->controller_)
[2019]62            {
[1993]63                delete this->controller_;
[2019]64                this->controller_ = 0;
65            }
[1993]66        }
[1940]67    }
68
[2019]69    void PlayerInfo::registerVariables()
[1940]70    {
[2019]71        REGISTERSTRING(this->name_,                 network::direction::toclient, new network::NetworkCallback<PlayerInfo>(this, &PlayerInfo::changedName));
72        REGISTERDATA  (this->controllableEntityID_, network::direction::toclient, new network::NetworkCallback<PlayerInfo>(this, &PlayerInfo::networkcallback_changedcontrollableentityID));
[1940]73    }
74
[2019]75    void PlayerInfo::changedName()
[1945]76    {
[2019]77        if (this->isReady() && this->getGametype())
78            this->getGametype()->playerChangedName(this);
79    }
80
81    void PlayerInfo::changedGametype()
82    {
83        if (this->isReady())
[1953]84        {
[2019]85            if (this->getOldGametype())
86            {
87                if (this->getGametype())
88                    this->getOldGametype()->playerSwitched(this, this->getGametype());
89                else
90                    this->getOldGametype()->playerLeft(this);
91            }
[1953]92
[2019]93            if (this->getGametype())
94            {
95                if (this->getOldGametype())
96                    this->getGametype()->playerSwitchedBack(this, this->getOldGametype());
97                else
98                    this->getGametype()->playerEntered(this);
99            }
[1953]100        }
[1945]101    }
102
[2019]103    void PlayerInfo::createController()
[1946]104    {
[2019]105        this->controller_ = this->defaultController_.fabricate(this);
106        assert(this->controller_);
107        this->controller_->setPlayer(this);
108        if (this->controllableEntity_)
109            this->controller_->setControllableEntity(this->controllableEntity_);
[1946]110    }
111
[2019]112    void PlayerInfo::startControl(ControllableEntity* entity)
[1940]113    {
[2019]114        if (this->controllableEntity_)
115            this->stopControl(this->controllableEntity_);
[1940]116
[2019]117        this->controllableEntity_ = entity;
[1940]118
[2019]119        if (entity)
[1940]120        {
[2019]121            this->controllableEntityID_ = entity->getObjectID();
122            entity->setPlayer(this);
[1940]123        }
[2019]124        else
[1940]125        {
[2019]126            this->controllableEntityID_ = network::OBJECTID_UNKNOWN;
[1940]127        }
[1989]128
[1993]129        if (this->controller_)
[2019]130            this->controller_->setControllableEntity(entity);
[1989]131    }
132
[2019]133    void PlayerInfo::stopControl(ControllableEntity* entity)
[1989]134    {
[2019]135        if (entity && this->controllableEntity_ == entity)
136        {
137            this->controllableEntity_ = 0;
138            this->controllableEntityID_ = network::OBJECTID_UNKNOWN;
[1989]139
[2019]140            if (this->controller_)
141                this->controller_->setControllableEntity(0);
142
143            entity->removePlayer();
144        }
[1993]145    }
146
[2019]147    void PlayerInfo::networkcallback_changedcontrollableentityID()
[1993]148    {
[2019]149        if (this->controllableEntityID_ != network::OBJECTID_UNKNOWN)
150        {
151            Synchronisable* temp = Synchronisable::getSynchronisable(this->controllableEntityID_);
152            ControllableEntity* entity = dynamic_cast<ControllableEntity*>(temp);
[1993]153
[2019]154            this->startControl(entity);
155        }
156        else
157        {
158            this->stopControl(this->controllableEntity_);
159        }
[1989]160    }
[1940]161}
Note: See TracBrowser for help on using the repository browser.