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, 20 years ago

Gui Shows weapons (simple)

File size: 3.4 KB
RevLine 
[5838]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:
[5841]12   main-programmer: Silvan Nellen
13   co-programmer: Benjamin Knecht
[5838]14*/
15
[5881]16
[5838]17#include "playable.h"
[5895]18
19#include "weapons/weapon_manager.h"
[5875]20#include "event_handler.h"
21#include "player.h"
[6241]22#include "state.h"
[5838]23
[5872]24
[5838]25Playable::Playable()
26{
[6442]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;
[5838]35}
36
[5875]37Playable::~Playable()
[5838]38{
[5881]39  delete this->weaponMan;
[5895]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  }
[5875]46}
47
[5898]48
[5872]49/**
[6436]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/**
[5872]63 * subscribe to all events the controllable needs
[5898]64 * @param player the player that shall controll this Playable
[5872]65 */
[5895]66bool Playable::subscribePlayer(Player* player)
[5872]67{
[5895]68  if (this->currentPlayer != NULL)
[5872]69  {
[5895]70    PRINTF(1)("Already registered Player:%s to this Playable (%s:%s)\n", this->currentPlayer->getName(), this->getClassName(), this->getName());
71    return false;
[5875]72  }
[5895]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));
[6241]81    this->enter();
[5895]82    return true;
83  }
[5872]84}
[5889]85
86/**
[5898]87 * unsubscribe from all events the controllable needs
88 * @param player the Player, that controlled this Ship.
[5896]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
[6241]106    this->leave();
[5896]107    this->currentPlayer = NULL;
108    return true;
109  }
110}
111
112/**
[5898]113 * add an event to the event list of events this Playable can capture
114 * @param eventType the Type of event to add
[5889]115 */
[5896]116void Playable::registerEvent(int eventType)
[5889]117{
118  this->events.push_back(eventType);
119
[5896]120  if (this->currentPlayer != NULL)
121    EventHandler::getInstance()->subscribe(this->currentPlayer, ES_GAME, eventType);
[5889]122}
123
[5896]124/**
[5898]125 * remove an event to the event list this Playable can capture.
126 * @param event the event to unregister.
[5896]127 */
128void Playable::unregisterEvent(int eventType)
129{
[5902]130  this->events.remove(eventType);
[5889]131
[5896]132  if (this->currentPlayer != NULL)
133    EventHandler::getInstance()->unsubscribe(ES_GAME, eventType);
134}
[5889]135
[5896]136
[6241]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.