Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 5896 was 5896, checked in by bensch, 18 years ago

controll: more elaborate playable

File size: 2.6 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
40void Playable::init()
41{
42  this->setClassID(CL_PLAYABLE, "Playable");
43  PRINTF(4)("PLAYABLE INIT\n");
44  this->weaponMan = new WeaponManager(this);
45
46  this->currentPlayer = NULL;
47}
48
49/**
50 * subscribe to all events the controllable needs
51 */
52bool Playable::subscribePlayer(Player* player)
53{
54  if (this->currentPlayer != NULL)
55  {
56    PRINTF(1)("Already registered Player:%s to this Playable (%s:%s)\n", this->currentPlayer->getName(), this->getClassName(), this->getName());
57    return false;
58  }
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));
67
68    return true;
69  }
70}
71
72/**
73 * subscribe to all events the controllable needs
74 */
75bool Playable::unsubscribePlayer(Player* player)
76{
77  if (this->currentPlayer != player)
78  {
79    PRINTF(1)("not the right Player to unregister from this Playable (%s:%s)\n", this->currentPlayer->getName(), this->getClassName(), this->getName());
80    return false;
81  }
82
83  else
84  {
85    /*EventHandler*/
86    EventHandler* evh = EventHandler::getInstance();
87    std::list<int>::iterator ev;
88    for (ev = this->events.begin(); ev != events.end(); ev++)
89      evh->unsubscribe( ES_GAME, (*ev));
90
91    this->currentPlayer = NULL;
92    return true;
93  }
94}
95
96/**
97 * add an event to the event list
98 */
99void Playable::registerEvent(int eventType)
100{
101  this->events.push_back(eventType);
102
103  if (this->currentPlayer != NULL)
104    EventHandler::getInstance()->subscribe(this->currentPlayer, ES_GAME, eventType);
105}
106
107/**
108 * add an event to the event list
109 */
110void Playable::unregisterEvent(int eventType)
111{
112  this->events.push_back(eventType);
113
114  if (this->currentPlayer != NULL)
115    EventHandler::getInstance()->unsubscribe(ES_GAME, eventType);
116}
117
118
Note: See TracBrowser for help on using the repository browser.