Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/spaceshipcontrol/src/world_entities/playable.cc @ 6188

Last change on this file since 6188 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
Line 
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:
12   main-programmer: Silvan Nellen
13   co-programmer: Benjamin Knecht
14*/
15
16
17#include "playable.h"
18
19#include "weapons/weapon_manager.h"
20#include "event_handler.h"
21#include "player.h"
22
23
24Playable::Playable()
25{
26  this->init();
27}
28
29Playable::~Playable()
30{
31  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  }
38}
39
40/**
41 * initializes this Playable
42 */
43void Playable::init()
44{
45  this->setClassID(CL_PLAYABLE, "Playable");
46  PRINTF(4)("PLAYABLE INIT\n");
47
48  this->toList(OM_GROUP_01);
49  this->weaponMan = new WeaponManager(this);
50
51  // the reference to the Current Player is NULL, because we dont have one at the beginning.
52  this->currentPlayer = NULL;
53}
54
55/**
56 * subscribe to all events the controllable needs
57 * @param player the player that shall controll this Playable
58 */
59bool Playable::subscribePlayer(Player* player)
60{
61  if (this->currentPlayer != NULL)
62  {
63    PRINTF(1)("Already registered Player:%s to this Playable (%s:%s)\n", this->currentPlayer->getName(), this->getClassName(), this->getName());
64    return false;
65  }
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));
74
75    return true;
76  }
77}
78
79/**
80 * unsubscribe from all events the controllable needs
81 * @param player the Player, that controlled this Ship.
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/**
105 * add an event to the event list of events this Playable can capture
106 * @param eventType the Type of event to add
107 */
108void Playable::registerEvent(int eventType)
109{
110  this->events.push_back(eventType);
111
112  if (this->currentPlayer != NULL)
113    EventHandler::getInstance()->subscribe(this->currentPlayer, ES_GAME, eventType);
114}
115
116/**
117 * remove an event to the event list this Playable can capture.
118 * @param event the event to unregister.
119 */
120void Playable::unregisterEvent(int eventType)
121{
122  this->events.remove(eventType);
123
124  if (this->currentPlayer != NULL)
125    EventHandler::getInstance()->unsubscribe(ES_GAME, eventType);
126}
127
128
Note: See TracBrowser for help on using the repository browser.