Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 22, 2008, 5:25:01 AM (16 years ago)
Author:
landauf
Message:

added several new classes

Location:
code/branches/objecthierarchy/src/orxonox/objects/infos
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/objecthierarchy/src/orxonox/objects/infos/PlayerInfo.cc

    r1989 r1993  
    4242#include "objects/gametypes/Gametype.h"
    4343#include "objects/worldentities/ControllableEntity.h"
     44#include "objects/controllers/HumanController.h"
    4445
    4546namespace orxonox
     
    5354        this->ping_ = -1;
    5455        this->clientID_ = network::CLIENTID_UNKNOWN;
    55         this->bLocalPlayer_ = Core::isStandalone();
    5656        this->bLocalPlayer_ = false;
    5757        this->bHumanPlayer_ = false;
     
    6060        this->pawn_ = 0;
    6161        this->pawnID_ = network::OBJECTID_UNKNOWN;
     62        this->controller_ = 0;
     63        this->setDefaultController(Class(HumanController));
    6264
    6365        this->setConfigValues();
    6466        this->registerVariables();
    65 
    66 //COUT(0) << "created PlayerInfo (" << this->getObjectID() << ")" << std::endl;
    6767    }
    6868
    6969    PlayerInfo::~PlayerInfo()
    7070    {
    71         Gametype* gametype = Gametype::getCurrentGametype();
    72         if (gametype)
    73             gametype->removePlayer(this);
    74 //COUT(0) << "destroyed PlayerInfo (" << this->getObjectID() << ")" << std::endl;
     71        if (this->isInitialized())
     72        {
     73            Gametype* gametype = Gametype::getCurrentGametype();
     74            if (gametype)
     75                gametype->removePlayer(this);
     76
     77            if (this->controller_)
     78                delete this->controller_;
     79
     80            if (this->pawn_)
     81                this->pawn_->removePlayer();
     82        }
    7583    }
    7684
     
    8290    void PlayerInfo::checkNick()
    8391    {
    84 //std::cout << "# PI(" << this->getObjectID() << "): checkName: " << this->bLocalPlayer_ << std::endl;
    8592        if (this->bLocalPlayer_)
    8693        {
     
    94101    void PlayerInfo::changedName()
    95102    {
    96 //std::cout << "# PI(" << this->getObjectID() << "): changedName to " << this->getName() << std::endl;
    97103        Gametype* gametype = Gametype::getCurrentGametype();
    98104        if (gametype)
     
    113119    void PlayerInfo::clientChangedName()
    114120    {
    115 //std::cout << "# PI(" << this->getObjectID() << "): clientChangedName() from " << this->getName() << " to " << this->playerName_ << std::endl;
    116121        this->setName(this->playerName_);
    117122    }
     
    119124    void PlayerInfo::checkClientID()
    120125    {
    121 //std::cout << "# PI(" << this->getObjectID() << "): checkClientID()" << std::endl;
    122126        this->bHumanPlayer_ = true;
    123127
    124128        if (this->clientID_ == network::Host::getPlayerID())
    125129        {
    126 //std::cout << "# PI(" << this->getObjectID() << "): checkClientID(): it's the client's ID" << std::endl;
    127             this->bLocalPlayer_ = true;
    128             this->playerName_ = this->nick_;
    129 //std::cout << "# PI(" << this->getObjectID() << "): checkClientID(): name: " << this->getName() << std::endl;
     130            this->takeLocalControl();
    130131
    131132            if (Core::isClient())
    132             {
    133 //std::cout << "# PI(" << this->getObjectID() << "): checkClientID(): we're on a client: set object mode to bidirectional" << std::endl;
    134133                this->setObjectMode(network::direction::bidirectional);
    135 //std::cout << "# PI(" << this->getObjectID() << "): checkClientID(): proposed name: " << this->playerName_ << std::endl;
    136             }
    137134            else
    138135            {
    139 //std::cout << "# PI(" << this->getObjectID() << "): checkClientID(): we're not on a client: finish setup" << std::endl;
    140136                this->clientChangedName();
    141137                this->bFinishedSetup_ = true;
     
    147143    void PlayerInfo::finishedSetup()
    148144    {
    149 //std::cout << "# PI(" << this->getObjectID() << "): finishedSetup(): " << this->bFinishedSetup_ << std::endl;
    150145        if (Core::isClient())
    151         {
    152 //std::cout << "# PI(" << this->getObjectID() << "): finishedSetup(): we're a client: finish setup" << std::endl;
    153146            this->bFinishedSetup_ = true;
    154         }
    155147        else if (this->bFinishedSetup_)
    156148        {
    157 //std::cout << "# PI(" << this->getObjectID() << "): finishedSetup(): we're a server: add player" << std::endl;
    158149            Gametype* gametype = Gametype::getCurrentGametype();
    159150            if (gametype)
    160151                gametype->addPlayer(this);
    161         }
    162         else
    163         {
    164 //std::cout << "# PI(" << this->getObjectID() << "): finishedSetup(): we're a server: client not yet finished" << std::endl;
    165152        }
    166153    }
     
    171158        this->pawn_ = pawn;
    172159        this->pawnID_ = pawn->getObjectID();
     160
     161        if (this->controller_)
     162            this->controller_->setPawn(this->pawn_);
    173163    }
    174164
     
    180170    }
    181171
     172    void PlayerInfo::takeLocalControl()
     173    {
     174        this->bLocalPlayer_ = true;
     175        this->playerName_ = this->nick_;
     176        this->createController();
     177    }
     178
     179    void PlayerInfo::createController()
     180    {
     181        this->controller_ = this->defaultController_.fabricate();
     182        this->controller_->setPawn(this->pawn_);
     183    }
     184
    182185    void PlayerInfo::updatePawn()
    183186    {
  • code/branches/objecthierarchy/src/orxonox/objects/infos/PlayerInfo.h

    r1989 r1993  
    3333
    3434#include "Info.h"
     35#include "core/Identifier.h"
     36#include "objects/controllers/Controller.h"
    3537
    3638namespace orxonox
     
    5860                { return this->bLocalPlayer_; }
    5961
    60             void startControl(ControllableEntity* pawn);
    61             void stopControl();
     62            virtual void startControl(ControllableEntity* pawn);
     63            virtual void stopControl();
    6264
    6365            inline ControllableEntity* getPawn() const
    6466                { return this->pawn_; }
     67/*
     68            inline void setController(Controller* controller)
     69                { this->controller_ = controller; }
     70            inline Controller* getController() const
     71                { return this->controller_; }
     72*/
     73        protected:
     74            inline void setDefaultController(Identifier* identifier)
     75                { this->defaultController_ = identifier; }
    6576
    6677        private:
     78            virtual void createController();
     79            virtual void takeLocalControl();
     80
    6781            void checkClientID();
    6882            void finishedSetup();
     
    8296            ControllableEntity* pawn_;
    8397            unsigned int pawnID_;
     98            Controller* controller_;
     99            SubclassIdentifier<Controller> defaultController_;
    84100    };
    85101}
Note: See TracChangeset for help on using the changeset viewer.