Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5895 in orxonox.OLD for branches/spaceshipcontrol


Ignore:
Timestamp:
Dec 3, 2005, 5:18:37 PM (19 years ago)
Author:
bensch
Message:

controll: playable interface work

Location:
branches/spaceshipcontrol/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/spaceshipcontrol/src/story_entities/world.cc

    r5894 r5895  
    363363  {
    364364    playable = dynamic_cast<Playable*>(playableList->front());
    365     if (playable != NULL)
    366       this->localPlayer->setControllable(playable);
     365    this->localPlayer->setControllable(playable);
    367366  }
    368367
  • branches/spaceshipcontrol/src/world_entities/playable.cc

    r5889 r5895  
    1414*/
    1515
    16 #include "weapons/weapon_manager.h"
    1716
    1817#include "playable.h"
     18
     19#include "weapons/weapon_manager.h"
    1920#include "event_handler.h"
    2021#include "player.h"
     
    2930{
    3031  delete this->weaponMan;
     32
     33  if (this->currentPlayer)
     34  {
     35    PRINTF(2)("There is Still a Player subscribed to this Playable (%s::%s)\n", this->getClassName(), this->getName());
     36
     37  }
    3138}
    3239
     
    3643  PRINTF(4)("PLAYABLE INIT\n");
    3744  this->weaponMan = new WeaponManager(this);
     45
     46  this->currentPlayer = NULL;
    3847}
    3948
     
    4150 * subscribe to all events the controllable needs
    4251 */
    43 void Playable::subscribeEvents(Player* player)
     52bool Playable::subscribePlayer(Player* player)
    4453{
    45   /*EventHandler*/
    46   EventHandler* evh = EventHandler::getInstance();
    47   std::list<int>::iterator ev;
    48   for (ev = this->events.begin(); ev != events.end(); ev++)
     54  if (this->currentPlayer != NULL)
    4955  {
    50     evh->subscribe(player, ES_GAME, (*ev));
     56    PRINTF(1)("Already registered Player:%s to this Playable (%s:%s)\n", this->currentPlayer->getName(), this->getClassName(), this->getName());
     57    return false;
    5158  }
     59  else
     60  {
     61    this->currentPlayer = player;
     62    /*EventHandler*/
     63    EventHandler* evh = EventHandler::getInstance();
     64    std::list<int>::iterator ev;
     65    for (ev = this->events.begin(); ev != events.end(); ev++)
     66      evh->subscribe(player, ES_GAME, (*ev));
    5267
     68    return true;
     69  }
    5370}
    5471
  • branches/spaceshipcontrol/src/world_entities/playable.h

    r5888 r5895  
    3131    inline WeaponManager* getWeaponManager() const { return this->weaponMan; };
    3232
    33     void subscribeEvents(Player* player);
     33    bool subscribePlayer(Player* player);
     34
    3435    virtual void process(const Event &event) {} //= 0;
    3536    inline const std::list<int>& getEventList() { return this->events; };
     
    3738  protected:
    3839    void registerEvent(int eventType);
     40    void unregisterEvent(int eventType);
    3941
    4042  private:
  • branches/spaceshipcontrol/src/world_entities/player.cc

    r5883 r5895  
    6161
    6262
    63 void Player::setControllable(Playable* controllalble)
     63bool Player::setControllable(Playable* controllable)
    6464{
    65 
    66   this->controllable = controllalble;
    67   this->controllable->subscribeEvents(this);
    68 
     65  if(controllable != NULL && controllable->subscribePlayer(this))
     66  {
     67      this->controllable = controllable;
     68      return true;
     69  }
     70  else
     71    return false;
    6972}
    7073
    7174
    72 
    73 Playable* Player::getControllable()
    74 {
    75   return controllable;
    76 }
    77 
  • branches/spaceshipcontrol/src/world_entities/player.h

    r5872 r5895  
    3131    virtual void  process(const Event &event);
    3232
    33     void          setControllable(Playable* controllalble);
     33    bool          setControllable(Playable* controllalble);
    3434    void          disconnectControllable();
    35     Playable*     getControllable();
     35    Playable*     getControllable() { return this->controllable; };
    3636
    3737
    3838  private:
    39     Playable* controllable;
     39    Playable*          controllable;
    4040
    4141
Note: See TracChangeset for help on using the changeset viewer.