Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/inputdevice/src/world_entities/player.cc @ 10632

Last change on this file since 10632 was 10632, checked in by snellen, 17 years ago

finished… testing needed

File size: 3.4 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"
[10632]19#include "script_triggers/action_trigger.h"
[3596]20
[4404]21#include "event_handler.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);
[10632]43  this->subscribeEvent(ES_GAME, KeyMapper::PEV_ACTION);
[3471]44}
45
[4975]46
[4010]47/**
[4975]48 *  destructs the player, deletes alocated memory
49 */
50Player::~Player ()
51{
[6986]52  this->setPlayable(NULL);
[4780]53}
54
55
[6985]56bool Player::setPlayable(Playable* playable)
[4780]57{
[6986]58  if (this->playable == playable)
59    return false;
60
61  // get out of the current Playable
62  if (this->playable != NULL)
[5435]63  {
[6987]64    PRINTF(4)("Player gets ejected from Playable\n");
[9019]65    this->_hud.setEnergyWidget(NULL);
66    this->_hud.setWeaponManager(NULL);
[6986]67
68    Playable* ejectedPlayable = this->playable;
69
70    this->playable = NULL;
71    ejectedPlayable->setPlayer(NULL);
72  }
73
74  if (playable != NULL)
75  {
[6987]76    PRINTF(4)("Enter new Playable\n");
[9061]77    this->playable = playable;
[10368]78    this->_hud.setArmorWidget(this->playable->getHealthWidget());
79    if (dynamic_cast<SpaceShip*>(this->playable) != 0)
80      this->_hud.setWeaponManager(&this->playable->getWeaponManager(), &dynamic_cast<SpaceShip*>(this->playable)->getWeaponManagerSecondary());
81    else
82      this->_hud.setWeaponManager(&this->playable->getWeaponManager());
[6986]83
[9061]84    this->playable->setPlayer(this);
85    return true;
[5751]86  }
[8316]87
[8147]88  if ( playable == NULL )
89    this->playable = NULL;
[6986]90
91  return true;
[3471]92}
[3584]93
[6986]94bool Player::eject()
[9061]95{
96  return this->setPlayable(NULL);
97}
[3584]98
[6986]99
[9869]100void Player::weaponConfigChanged()
101{
[10368]102  //this->_hud.updateWeaponManager();
103
[10516]104  if (dynamic_cast<SpaceShip*>(this->playable) != NULL)
105    this->_hud.setWeaponManager(&this->playable->getWeaponManager(), &dynamic_cast<SpaceShip*>(this->playable)->getWeaponManagerSecondary());
106  else
107    this->_hud.setWeaponManager(&this->playable->getWeaponManager());
[9869]108}
[6443]109
[6438]110
[9061]111void Player::enterNewPlayable()
112{
113  /// FIXME this should be in the ObjectManager
[9869]114  for (ObjectList<Playable>::const_iterator node = Playable::objectList().begin();
115       node != Playable::objectList().end();
116       ++node)
[9061]117  {
[9869]118    if (this->playable != (*node) &&
119        ((*node)->getAbsCoor() - this->playable->getAbsCoor()).len() < ((*node)->getEnterRadius()))
120    {
[6222]121
[9869]122      this->setPlayable(*(node));
[6222]123
[9869]124      break;
125    }
[9061]126  }
127}
[5751]128
[9061]129
130void Player::process(const Event &event)
131{
132  if (event.type == KeyMapper::PEV_CHANGE_SHIP && event.bPressed)
133  {
134    this->enterNewPlayable();
135  }
[10632]136  else if(event.type == KeyMapper::PEV_ACTION && event.bPressed)
137  {
138   for (ObjectList<ActionTrigger>::const_iterator it = ActionTrigger::objectList().begin();
139       it != ActionTrigger::objectList().end();
140       ++it)
141      (*it)->executeAction();
142  }
[9061]143
144  if (likely(this->playable != NULL))
145    this->playable->process(event);
146}
147
[10368]148
Note: See TracBrowser for help on using the repository browser.