Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6803 was 6710, checked in by bensch, 19 years ago

merged the powerups back to the trunk

File size: 4.8 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
[6700]24#include "world_entities/projectiles/projectile.h"
25
[6547]26#include "power_ups/weapon_power_up.h"
27#include "power_ups/param_power_up.h"
[5872]28
[6547]29
[5838]30Playable::Playable()
31{
[6442]32  this->setClassID(CL_PLAYABLE, "Playable");
33  PRINTF(4)("PLAYABLE INIT\n");
34
35  this->toList(OM_GROUP_01);
36  this->weaponMan = new WeaponManager(this);
37
38  // the reference to the Current Player is NULL, because we dont have one at the beginning.
39  this->currentPlayer = NULL;
[6695]40
41  this->setSynchronized(true);
[5838]42}
43
[6695]44
45
[5875]46Playable::~Playable()
[5838]47{
[5881]48  delete this->weaponMan;
[5895]49
50  if (this->currentPlayer)
51  {
52    PRINTF(2)("There is Still a Player subscribed to this Playable (%s::%s)\n", this->getClassName(), this->getName());
53
54  }
[5875]55}
56
[5898]57
[6443]58void Playable::addWeapon(Weapon* weapon, int configID, int slotID)
59{
[6676]60  this->weaponMan->addWeapon(weapon, configID, slotID);
[6443]61
[6578]62  this->weaponConfigChanged();
[6443]63}
64
[6695]65
[6443]66void Playable::removeWeapon(Weapon* weapon)
67{
68  this->weaponMan->removeWeapon(weapon);
69
[6568]70    this->weaponConfigChanged();
[6443]71}
72
[6695]73
[6444]74void Playable::nextWeaponConfig()
75{
76  this->weaponMan->nextWeaponConfig();
[6568]77    this->weaponConfigChanged();
[6444]78}
[6443]79
[6695]80
[6444]81void Playable::previousWeaponConfig()
82{
83  this->weaponMan->previousWeaponConfig();
[6568]84    this->weaponConfigChanged();
[6444]85}
86
[6695]87
[6568]88void Playable::weaponConfigChanged()
89{
[6578]90  if (this->currentPlayer != NULL)
91    this->currentPlayer->weaponConfigChanged();
[6568]92}
[6444]93
[6695]94
[5872]95/**
[6436]96 * @brief helps us colliding Playables
97 */
98void Playable::collidesWith(WorldEntity* entity, const Vector& location)
99{
100  if (entity->isA(CL_PROJECTILE))
[6700]101    this->decreaseHealth(entity->getHealth());
[6436]102
103  // EXTREME HACK
[6700]104  if (this->getHealth() == 0.0f)
[6436]105    this->deactivateNode();
106}
107
108/**
[5872]109 * subscribe to all events the controllable needs
[5898]110 * @param player the player that shall controll this Playable
[5872]111 */
[5895]112bool Playable::subscribePlayer(Player* player)
[5872]113{
[5895]114  if (this->currentPlayer != NULL)
[5872]115  {
[5895]116    PRINTF(1)("Already registered Player:%s to this Playable (%s:%s)\n", this->currentPlayer->getName(), this->getClassName(), this->getName());
117    return false;
[5875]118  }
[5895]119  else
120  {
121    this->currentPlayer = player;
122    /*EventHandler*/
123    EventHandler* evh = EventHandler::getInstance();
124    std::list<int>::iterator ev;
125    for (ev = this->events.begin(); ev != events.end(); ev++)
126      evh->subscribe(player, ES_GAME, (*ev));
[6241]127    this->enter();
[5895]128    return true;
129  }
[5872]130}
[5889]131
132/**
[5898]133 * unsubscribe from all events the controllable needs
134 * @param player the Player, that controlled this Ship.
[5896]135 */
136bool Playable::unsubscribePlayer(Player* player)
137{
138  if (this->currentPlayer != player)
139  {
140    PRINTF(1)("not the right Player to unregister from this Playable (%s:%s)\n", this->currentPlayer->getName(), this->getClassName(), this->getName());
141    return false;
142  }
143
144  else
145  {
146    /*EventHandler*/
147    EventHandler* evh = EventHandler::getInstance();
148    std::list<int>::iterator ev;
149    for (ev = this->events.begin(); ev != events.end(); ev++)
150      evh->unsubscribe( ES_GAME, (*ev));
151
[6241]152    this->leave();
[5896]153    this->currentPlayer = NULL;
154    return true;
155  }
156}
157
[6547]158bool Playable::pickup(PowerUp* powerUp)
159{
160  if(powerUp->isA(CL_WEAPON_POWER_UP)) {
161    Weapon* weapon = dynamic_cast<WeaponPowerUp*>(powerUp)->getWeapon();
162    WeaponManager* manager = this->getWeaponManager();
[6710]163    return manager->addWeapon(weapon);
[6547]164  }
165  else if(powerUp->isA(CL_PARAM_POWER_UP)) {
166    ParamPowerUp* ppu = dynamic_cast<ParamPowerUp*>(powerUp);
167    switch(ppu->getType()) {
168      case POWERUP_PARAM_HEALTH:
[6700]169        this->increaseHealth(ppu->getValue());
[6547]170        return true;
171      case POWERUP_PARAM_MAX_HEALTH:
[6700]172        this->increaseHealthMax(ppu->getValue());
[6547]173        return true;
174    }
175  }
176  return false;
177}
178
[5896]179/**
[5898]180 * add an event to the event list of events this Playable can capture
181 * @param eventType the Type of event to add
[5889]182 */
[5896]183void Playable::registerEvent(int eventType)
[5889]184{
185  this->events.push_back(eventType);
186
[5896]187  if (this->currentPlayer != NULL)
188    EventHandler::getInstance()->subscribe(this->currentPlayer, ES_GAME, eventType);
[5889]189}
190
[5896]191/**
[5898]192 * remove an event to the event list this Playable can capture.
193 * @param event the event to unregister.
[5896]194 */
195void Playable::unregisterEvent(int eventType)
196{
[5902]197  this->events.remove(eventType);
[5889]198
[5896]199  if (this->currentPlayer != NULL)
200    EventHandler::getInstance()->unsubscribe(ES_GAME, eventType);
201}
[5889]202
[5896]203
[6241]204void  Playable::attachCamera()
205{
[6444]206  State::getCamera()->setParentSoft(this);
207  State::getCameraTarget()->setParentSoft(this);
[6241]208
209}
210
211
212void  Playable::detachCamera()
213{
214}
Note: See TracBrowser for help on using the repository browser.