Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

huge pipeline

File size: 3.8 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
49void Playable::addWeapon(Weapon* weapon, int configID, int slotID)
50{
51  this->weaponMan->addWeapon(weapon, configID, slotID);
52
53  if (this->currentPlayer != NULL)
54      this->currentPlayer->weaponConfigChanged();
55}
56
57void Playable::removeWeapon(Weapon* weapon)
58{
59  this->weaponMan->removeWeapon(weapon);
60
61  if (this->currentPlayer != NULL)
62    this->currentPlayer->weaponConfigChanged();
63}
64
65
66/**
67 * @brief helps us colliding Playables
68 */
69void Playable::collidesWith(WorldEntity* entity, const Vector& location)
70{
71  if (entity->isA(CL_PROJECTILE))
72    this->removeEnergy(entity->getEnergy());
73
74  // EXTREME HACK
75  if (this->getEnergy() == 0.0f)
76    this->deactivateNode();
77}
78
79/**
80 * subscribe to all events the controllable needs
81 * @param player the player that shall controll this Playable
82 */
83bool Playable::subscribePlayer(Player* player)
84{
85  if (this->currentPlayer != NULL)
86  {
87    PRINTF(1)("Already registered Player:%s to this Playable (%s:%s)\n", this->currentPlayer->getName(), this->getClassName(), this->getName());
88    return false;
89  }
90  else
91  {
92    this->currentPlayer = player;
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->subscribe(player, ES_GAME, (*ev));
98    this->enter();
99    return true;
100  }
101}
102
103/**
104 * unsubscribe from all events the controllable needs
105 * @param player the Player, that controlled this Ship.
106 */
107bool Playable::unsubscribePlayer(Player* player)
108{
109  if (this->currentPlayer != player)
110  {
111    PRINTF(1)("not the right Player to unregister from this Playable (%s:%s)\n", this->currentPlayer->getName(), this->getClassName(), this->getName());
112    return false;
113  }
114
115  else
116  {
117    /*EventHandler*/
118    EventHandler* evh = EventHandler::getInstance();
119    std::list<int>::iterator ev;
120    for (ev = this->events.begin(); ev != events.end(); ev++)
121      evh->unsubscribe( ES_GAME, (*ev));
122
123    this->leave();
124    this->currentPlayer = NULL;
125    return true;
126  }
127}
128
129/**
130 * add an event to the event list of events this Playable can capture
131 * @param eventType the Type of event to add
132 */
133void Playable::registerEvent(int eventType)
134{
135  this->events.push_back(eventType);
136
137  if (this->currentPlayer != NULL)
138    EventHandler::getInstance()->subscribe(this->currentPlayer, ES_GAME, eventType);
139}
140
141/**
142 * remove an event to the event list this Playable can capture.
143 * @param event the event to unregister.
144 */
145void Playable::unregisterEvent(int eventType)
146{
147  this->events.remove(eventType);
148
149  if (this->currentPlayer != NULL)
150    EventHandler::getInstance()->unsubscribe(ES_GAME, eventType);
151}
152
153
154void  Playable::attachCamera()
155{
156       State::getCamera()->setParentSoft(this);
157       State::getCameraTarget()->setParentSoft(this);
158
159}
160
161
162void  Playable::detachCamera()
163{
164
165
166}
Note: See TracBrowser for help on using the repository browser.