Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/playability/src/world_entities/player.cc @ 10621

Last change on this file since 10621 was 10516, checked in by patrick, 18 years ago

merged playability back to trunk

File size: 3.0 KB
RevLine 
[4592]1/*
[3471]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:
[5915]12   main-programmer: Silvan Nellen
13   co-programmer: Benjamin Knecht
[3471]14*/
15
16#include "player.h"
[5915]17#include "playable.h"
[10368]18#include "space_ships/space_ship.h"
[3596]19
[4404]20#include "event_handler.h"
[4389]21
[6222]22#include "state.h"
[6438]23#include "util/hud.h"
[6222]24
[8362]25#include "debug.h"
[3471]26
[9869]27ObjectListDefinition(Player);
[3471]28/**
[4885]29 * creates a new Player
[3471]30*/
[4762]31Player::Player()
[3471]32{
[9061]33  //  this->setRelDir(Quaternion(M_PI, Vector(1,0,0)));
[9869]34  this->registerObject(this, Player::_objectList);
[6222]35
[6440]36  PRINTF(4)("PLAYER INIT\n");
37
[6985]38  this->playable = NULL;
[9019]39  this->_hud.setVisibility(true);
[6440]40
[7868]41  this->subscribeEvent(ES_GAME, KeyMapper::PEV_CHANGE_SHIP);
[3471]42}
43
[4975]44
[4010]45/**
[4975]46 *  destructs the player, deletes alocated memory
47 */
48Player::~Player ()
49{
[6986]50  this->setPlayable(NULL);
[4780]51}
52
53
[6985]54bool Player::setPlayable(Playable* playable)
[4780]55{
[6986]56  if (this->playable == playable)
57    return false;
58
59  // get out of the current Playable
60  if (this->playable != NULL)
[5435]61  {
[6987]62    PRINTF(4)("Player gets ejected from Playable\n");
[9019]63    this->_hud.setEnergyWidget(NULL);
64    this->_hud.setWeaponManager(NULL);
[6986]65
66    Playable* ejectedPlayable = this->playable;
67
68    this->playable = NULL;
69    ejectedPlayable->setPlayer(NULL);
70  }
71
72  if (playable != NULL)
73  {
[6987]74    PRINTF(4)("Enter new Playable\n");
[9061]75    this->playable = playable;
[10368]76    this->_hud.setArmorWidget(this->playable->getHealthWidget());
77    if (dynamic_cast<SpaceShip*>(this->playable) != 0)
78      this->_hud.setWeaponManager(&this->playable->getWeaponManager(), &dynamic_cast<SpaceShip*>(this->playable)->getWeaponManagerSecondary());
79    else
80      this->_hud.setWeaponManager(&this->playable->getWeaponManager());
[6986]81
[9061]82    this->playable->setPlayer(this);
83    return true;
[5751]84  }
[8316]85
[8147]86  if ( playable == NULL )
87    this->playable = NULL;
[6986]88
89  return true;
[3471]90}
[3584]91
[6986]92bool Player::eject()
[9061]93{
94  return this->setPlayable(NULL);
95}
[3584]96
[6986]97
[9869]98void Player::weaponConfigChanged()
99{
[10368]100  //this->_hud.updateWeaponManager();
101
[10516]102  if (dynamic_cast<SpaceShip*>(this->playable) != NULL)
103    this->_hud.setWeaponManager(&this->playable->getWeaponManager(), &dynamic_cast<SpaceShip*>(this->playable)->getWeaponManagerSecondary());
104  else
105    this->_hud.setWeaponManager(&this->playable->getWeaponManager());
[9869]106}
[6443]107
[6438]108
[9061]109void Player::enterNewPlayable()
110{
111  /// FIXME this should be in the ObjectManager
[9869]112  for (ObjectList<Playable>::const_iterator node = Playable::objectList().begin();
113       node != Playable::objectList().end();
114       ++node)
[9061]115  {
[9869]116    if (this->playable != (*node) &&
117        ((*node)->getAbsCoor() - this->playable->getAbsCoor()).len() < ((*node)->getEnterRadius()))
118    {
[6222]119
[9869]120      this->setPlayable(*(node));
[6222]121
[9869]122      break;
123    }
[9061]124  }
125}
[5751]126
[9061]127
128void Player::process(const Event &event)
129{
130  if (event.type == KeyMapper::PEV_CHANGE_SHIP && event.bPressed)
131  {
132    this->enterNewPlayable();
133  }
134
135  if (likely(this->playable != NULL))
136    this->playable->process(event);
137}
138
[10368]139
Note: See TracBrowser for help on using the repository browser.