Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6986 in orxonox.OLD for trunk/src/world_entities/playable.cc


Ignore:
Timestamp:
Feb 2, 2006, 5:58:33 PM (18 years ago)
Author:
bensch
Message:

trunk: brainfuck: interface to Playable much bea now

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/world_entities/playable.cc

    r6973 r6986  
    7575  delete this->weaponMan;
    7676
    77   if (this->currentPlayer)
    78   {
    79     PRINTF(2)("There is Still a Player subscribed to this Playable (%s::%s)\n", this->getClassName(), this->getName());
    80 
    81   }
     77  // THE DERIVED CLASS MUST UNSUBSCRIBE THE PLAYER THROUGH
     78  // this->setPlayer(NULL);
     79  // IN ITS DESTRUCTOR.
     80  assert(this->currentPlayer == NULL);
    8281}
    8382
     
    158157 * @param player the player that shall controll this Playable
    159158 */
    160 bool Playable::subscribePlayer(Player* player)
    161 {
    162   if (this->currentPlayer != NULL)
    163   {
    164     PRINTF(1)("Already registered Player:%s to this Playable (%s:%s)\n", this->currentPlayer->getName(), this->getClassName(), this->getName());
     159bool Playable::setPlayer(Player* player)
     160{
     161  // if we already have a Player inside do nothing
     162  if (this->currentPlayer != NULL && player != NULL)
     163  {
     164    printf("No Change in Playable\n");
    165165    return false;
    166166  }
    167   else
    168   {
     167
     168  // eject the Player if player == NULL
     169  if (this->currentPlayer != NULL && player == NULL)
     170  {
     171    PRINTF(0)("Player gets ejected\n");
     172
     173    // unsubscibe all events.
     174    EventHandler* evh = EventHandler::getInstance();
     175    std::list<int>::iterator ev;
     176    for (ev = this->events.begin(); ev != events.end(); ev++)
     177      evh->unsubscribe( ES_GAME, (*ev));
     178
     179    // leave the entity
     180    this->leave();
     181
     182    // eject the current Player.
     183    Player* ejectPlayer = this->currentPlayer;
     184    this->currentPlayer = NULL;
     185    // eject the Player.
     186    ejectPlayer->setPlayable(NULL);
     187
     188    return true;
     189  }
     190
     191  // get the new Player inside
     192  if (this->currentPlayer == NULL && player != NULL)
     193  {
     194    PRINTF(0)("New Player gets inside\n");
    169195    this->currentPlayer = player;
     196    if (this->currentPlayer->getPlayable() != this)
     197      this->currentPlayer->setPlayable(this);
     198
    170199    /*EventHandler*/
    171200    EventHandler* evh = EventHandler::getInstance();
     
    173202    for (ev = this->events.begin(); ev != events.end(); ev++)
    174203      evh->subscribe(player, ES_GAME, (*ev));
     204
    175205    this->enter();
    176206    return true;
    177207  }
    178 }
    179 
    180 /**
    181  * unsubscribe from all events the controllable needs
    182  * @param player the Player, that controlled this Ship.
    183  */
    184 bool Playable::unsubscribePlayer(Player* player)
    185 {
    186   if (this->currentPlayer != player)
    187   {
    188     PRINTF(1)("not the right Player to unregister from this Playable (%s:%s)\n", this->currentPlayer->getName(), this->getClassName(), this->getName());
    189     return false;
    190   }
    191 
    192   else
    193   {
    194     /*EventHandler*/
    195     EventHandler* evh = EventHandler::getInstance();
    196     std::list<int>::iterator ev;
    197     for (ev = this->events.begin(); ev != events.end(); ev++)
    198       evh->unsubscribe( ES_GAME, (*ev));
    199 
    200     this->leave();
    201     this->currentPlayer = NULL;
    202     return true;
    203   }
    204 }
     208
     209  printf("none\n");
     210  return false;
     211}
     212
    205213
    206214bool Playable::pickup(PowerUp* powerUp)
Note: See TracChangeset for help on using the changeset viewer.