Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10030 was 10030, checked in by marcscha, 17 years ago

Second Weapon Ammo Widget Support

File size: 2.8 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"
[10023]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;
[9062]76    this->_hud.setEnergyWidget(this->playable->getHealthWidget());
[10030]77    if (dynamic_cast<SpaceShip*>(this->playable) != 0)
[10023]78      this->_hud.setWeaponManager(&this->playable->getWeaponManager(), &dynamic_cast<SpaceShip*>(this->playable)->getWeaponManagerSecondary());
[10030]79    else
[10023]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{
100  this->_hud.updateWeaponManager();
101}
[6443]102
[6438]103
[9061]104void Player::enterNewPlayable()
105{
106  /// FIXME this should be in the ObjectManager
[9869]107  for (ObjectList<Playable>::const_iterator node = Playable::objectList().begin();
108       node != Playable::objectList().end();
109       ++node)
[9061]110  {
[9869]111    if (this->playable != (*node) &&
112        ((*node)->getAbsCoor() - this->playable->getAbsCoor()).len() < ((*node)->getEnterRadius()))
113    {
[6222]114
[9869]115      this->setPlayable(*(node));
[6222]116
[9869]117      break;
118    }
[9061]119  }
120}
[5751]121
[9061]122
123void Player::process(const Event &event)
124{
125  if (event.type == KeyMapper::PEV_CHANGE_SHIP && event.bPressed)
126  {
127    this->enterNewPlayable();
128  }
129
130  if (likely(this->playable != NULL))
131    this->playable->process(event);
132}
133
[9971]134
Note: See TracBrowser for help on using the repository browser.