Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/avi_play/src/world_entities/playable.cc @ 6585

Last change on this file since 6585 was 6444, checked in by bensch, 19 years ago

trunk: sliders get updated, as they should be

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