Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Gui Shows weapons (simple)

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