Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/player.cc @ 10765

Last change on this file since 10765 was 10698, checked in by snellen, 18 years ago

merged adm, hud, vs-enhancements : beni's responsible for this commit. blame him!

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