Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/preferences/src/world_entities/playable.cc @ 6999

Last change on this file since 6999 was 6241, checked in by bensch, 19 years ago

trunk: merged the spaceshipcontrol back to the trunk

File size: 3.2 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#include "state.h"
23
24
25Playable::Playable()
26{
27  this->init();
28}
29
30Playable::~Playable()
31{
32  delete this->weaponMan;
33
34  if (this->currentPlayer)
35  {
36    PRINTF(2)("There is Still a Player subscribed to this Playable (%s::%s)\n", this->getClassName(), this->getName());
37
38  }
39}
40
41/**
42 * initializes this Playable
43 */
44void Playable::init()
45{
46  this->setClassID(CL_PLAYABLE, "Playable");
47  PRINTF(4)("PLAYABLE INIT\n");
48
49  this->toList(OM_GROUP_01);
50  this->weaponMan = new WeaponManager(this);
51
52  // the reference to the Current Player is NULL, because we dont have one at the beginning.
53  this->currentPlayer = NULL;
54}
55
56/**
57 * subscribe to all events the controllable needs
58 * @param player the player that shall controll this Playable
59 */
60bool Playable::subscribePlayer(Player* player)
61{
62  if (this->currentPlayer != NULL)
63  {
64    PRINTF(1)("Already registered Player:%s to this Playable (%s:%s)\n", this->currentPlayer->getName(), this->getClassName(), this->getName());
65    return false;
66  }
67  else
68  {
69    this->currentPlayer = player;
70    /*EventHandler*/
71    EventHandler* evh = EventHandler::getInstance();
72    std::list<int>::iterator ev;
73    for (ev = this->events.begin(); ev != events.end(); ev++)
74      evh->subscribe(player, ES_GAME, (*ev));
75    this->enter();
76    return true;
77  }
78}
79
80/**
81 * unsubscribe from all events the controllable needs
82 * @param player the Player, that controlled this Ship.
83 */
84bool Playable::unsubscribePlayer(Player* player)
85{
86  if (this->currentPlayer != player)
87  {
88    PRINTF(1)("not the right Player to unregister from this Playable (%s:%s)\n", this->currentPlayer->getName(), this->getClassName(), this->getName());
89    return false;
90  }
91
92  else
93  {
94    /*EventHandler*/
95    EventHandler* evh = EventHandler::getInstance();
96    std::list<int>::iterator ev;
97    for (ev = this->events.begin(); ev != events.end(); ev++)
98      evh->unsubscribe( ES_GAME, (*ev));
99
100    this->leave();
101    this->currentPlayer = NULL;
102    return true;
103  }
104}
105
106/**
107 * add an event to the event list of events this Playable can capture
108 * @param eventType the Type of event to add
109 */
110void Playable::registerEvent(int eventType)
111{
112  this->events.push_back(eventType);
113
114  if (this->currentPlayer != NULL)
115    EventHandler::getInstance()->subscribe(this->currentPlayer, ES_GAME, eventType);
116}
117
118/**
119 * remove an event to the event list this Playable can capture.
120 * @param event the event to unregister.
121 */
122void Playable::unregisterEvent(int eventType)
123{
124  this->events.remove(eventType);
125
126  if (this->currentPlayer != NULL)
127    EventHandler::getInstance()->unsubscribe(ES_GAME, eventType);
128}
129
130
131void  Playable::attachCamera()
132{
133       State::getCamera()->setParentSoft(this);
134       State::getCameraTarget()->setParentSoft(this);
135
136}
137
138
139void  Playable::detachCamera()
140{
141
142
143}
Note: See TracBrowser for help on using the repository browser.