Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/playable.cc @ 6219

Last change on this file since 6219 was 6142, checked in by bensch, 19 years ago

orxonox/trunk: merge the ObjectManager to the trunk
merged with command:
svn merge -r6082:HEAD objectmanager/ ../trunk/

conflicts resolution was easy this time :)
but specially merged the world to network_world

File size: 3.0 KB
RevLine 
[5838]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:
[5841]12   main-programmer: Silvan Nellen
13   co-programmer: Benjamin Knecht
[5838]14*/
15
[5881]16
[5838]17#include "playable.h"
[5895]18
19#include "weapons/weapon_manager.h"
[5875]20#include "event_handler.h"
21#include "player.h"
[5838]22
[5872]23
[5838]24Playable::Playable()
25{
26  this->init();
27}
28
[5875]29Playable::~Playable()
[5838]30{
[5881]31  delete this->weaponMan;
[5895]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  }
[5875]38}
39
[5898]40/**
41 * initializes this Playable
42 */
[5875]43void Playable::init()
44{
[5838]45  this->setClassID(CL_PLAYABLE, "Playable");
46  PRINTF(4)("PLAYABLE INIT\n");
[5898]47
[6142]48  this->toList(OM_GROUP_01);
[5838]49  this->weaponMan = new WeaponManager(this);
[5895]50
[5898]51  // the reference to the Current Player is NULL, because we dont have one at the beginning.
[5895]52  this->currentPlayer = NULL;
[5838]53}
54
[5872]55/**
56 * subscribe to all events the controllable needs
[5898]57 * @param player the player that shall controll this Playable
[5872]58 */
[5895]59bool Playable::subscribePlayer(Player* player)
[5872]60{
[5895]61  if (this->currentPlayer != NULL)
[5872]62  {
[5895]63    PRINTF(1)("Already registered Player:%s to this Playable (%s:%s)\n", this->currentPlayer->getName(), this->getClassName(), this->getName());
64    return false;
[5875]65  }
[5895]66  else
67  {
68    this->currentPlayer = player;
69    /*EventHandler*/
70    EventHandler* evh = EventHandler::getInstance();
71    std::list<int>::iterator ev;
72    for (ev = this->events.begin(); ev != events.end(); ev++)
73      evh->subscribe(player, ES_GAME, (*ev));
[5872]74
[5895]75    return true;
76  }
[5872]77}
[5889]78
79/**
[5898]80 * unsubscribe from all events the controllable needs
81 * @param player the Player, that controlled this Ship.
[5896]82 */
83bool Playable::unsubscribePlayer(Player* player)
84{
85  if (this->currentPlayer != player)
86  {
87    PRINTF(1)("not the right Player to unregister from this Playable (%s:%s)\n", this->currentPlayer->getName(), this->getClassName(), this->getName());
88    return false;
89  }
90
91  else
92  {
93    /*EventHandler*/
94    EventHandler* evh = EventHandler::getInstance();
95    std::list<int>::iterator ev;
96    for (ev = this->events.begin(); ev != events.end(); ev++)
97      evh->unsubscribe( ES_GAME, (*ev));
98
99    this->currentPlayer = NULL;
100    return true;
101  }
102}
103
104/**
[5898]105 * add an event to the event list of events this Playable can capture
106 * @param eventType the Type of event to add
[5889]107 */
[5896]108void Playable::registerEvent(int eventType)
[5889]109{
110  this->events.push_back(eventType);
111
[5896]112  if (this->currentPlayer != NULL)
113    EventHandler::getInstance()->subscribe(this->currentPlayer, ES_GAME, eventType);
[5889]114}
115
[5896]116/**
[5898]117 * remove an event to the event list this Playable can capture.
118 * @param event the event to unregister.
[5896]119 */
120void Playable::unregisterEvent(int eventType)
121{
[5902]122  this->events.remove(eventType);
[5889]123
[5896]124  if (this->currentPlayer != NULL)
125    EventHandler::getInstance()->unsubscribe(ES_GAME, eventType);
126}
[5889]127
[5896]128
Note: See TracBrowser for help on using the repository browser.