Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: collides with function now takes away the Energy of our beloved Entity

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