Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

merged playability back to trunk

File size: 3.0 KB
Line 
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:
12   main-programmer: Silvan Nellen
13   co-programmer: Benjamin Knecht
14*/
15
16#include "player.h"
17#include "playable.h"
18#include "space_ships/space_ship.h"
19
20#include "event_handler.h"
21
22#include "state.h"
23#include "util/hud.h"
24
25#include "debug.h"
26
27ObjectListDefinition(Player);
28/**
29 * creates a new Player
30*/
31Player::Player()
32{
33  //  this->setRelDir(Quaternion(M_PI, Vector(1,0,0)));
34  this->registerObject(this, Player::_objectList);
35
36  PRINTF(4)("PLAYER INIT\n");
37
38  this->playable = NULL;
39  this->_hud.setVisibility(true);
40
41  this->subscribeEvent(ES_GAME, KeyMapper::PEV_CHANGE_SHIP);
42}
43
44
45/**
46 *  destructs the player, deletes alocated memory
47 */
48Player::~Player ()
49{
50  this->setPlayable(NULL);
51}
52
53
54bool Player::setPlayable(Playable* playable)
55{
56  if (this->playable == playable)
57    return false;
58
59  // get out of the current Playable
60  if (this->playable != NULL)
61  {
62    PRINTF(4)("Player gets ejected from Playable\n");
63    this->_hud.setEnergyWidget(NULL);
64    this->_hud.setWeaponManager(NULL);
65
66    Playable* ejectedPlayable = this->playable;
67
68    this->playable = NULL;
69    ejectedPlayable->setPlayer(NULL);
70  }
71
72  if (playable != NULL)
73  {
74    PRINTF(4)("Enter new Playable\n");
75    this->playable = playable;
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());
81
82    this->playable->setPlayer(this);
83    return true;
84  }
85
86  if ( playable == NULL )
87    this->playable = NULL;
88
89  return true;
90}
91
92bool Player::eject()
93{
94  return this->setPlayable(NULL);
95}
96
97
98void Player::weaponConfigChanged()
99{
100  //this->_hud.updateWeaponManager();
101
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());
106}
107
108
109void Player::enterNewPlayable()
110{
111  /// FIXME this should be in the ObjectManager
112  for (ObjectList<Playable>::const_iterator node = Playable::objectList().begin();
113       node != Playable::objectList().end();
114       ++node)
115  {
116    if (this->playable != (*node) &&
117        ((*node)->getAbsCoor() - this->playable->getAbsCoor()).len() < ((*node)->getEnterRadius()))
118    {
119
120      this->setPlayable(*(node));
121
122      break;
123    }
124  }
125}
126
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
139
Note: See TracBrowser for help on using the repository browser.