Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/presentation/src/orxonox/objects/pickup/Turbo.cc @ 2500

Last change on this file since 2500 was 2500, checked in by landauf, 16 years ago

merged pickups2 to presentation

  • Property svn:eol-style set to native
File size: 2.9 KB
Line 
1#include "Turbo.h"
2
3#include "objects/worldentities/pawns/SpaceShip.h"
4#include "core/Executor.h"
5#include "core/CoreIncludes.h"
6#include "core/XMLPort.h"
7
8namespace orxonox
9{
10
11
12        CreateFactory(Turbo);
13
14        Turbo::Turbo(BaseObject* creator) : BaseItem(creator)
15        {
16                RegisterObject(Turbo);
17
18                this->boost_ = 0;
19                this->duration_ = 0;
20                this->accboost_ = 1;
21                this->rotacc_= 0;
22        }
23
24        Turbo::~Turbo()
25        {
26        }
27
28    void Turbo::XMLPort(Element& xmlelement, XMLPort::Mode mode)
29    {
30        SUPER(Turbo, XMLPort, xmlelement, mode);
31
32        XMLPortParam(Turbo, "boost", setBoost, getBoost, xmlelement, mode);
33        XMLPortParam(Turbo, "duration", setDuration, getDuration, xmlelement, mode);
34        XMLPortParam(Turbo, "accboost", setAccBoost, getAccBoost, xmlelement, mode);
35        XMLPortParam(Turbo, "rotacc", setRotAcc, getRotAcc, xmlelement, mode);
36    }
37
38        bool Turbo::pickedUp(Pawn* player)
39        {
40
41                if(player-> isA(this->getPlayerBaseClass()))
42                        {
43                        SpaceShip* ship = dynamic_cast <SpaceShip*>(player);
44                        if(duration_==0 )
45                        {
46                                if(addTo(player))
47                                {
48                                                COUT(3)<<"ITEM EQUIPPED"<<std::endl;
49                                                this->setSpeedBoost(ship);
50                                                return true;
51                                }
52                                return false;
53                        }
54                        else
55                        {
56                                this->setSpeedBoost(ship);
57                                return true;
58                        }
59                        return false;
60                        }
61                return false;
62
63        }
64
65
66        void Turbo::unsetSpeedBoost(SpaceShip* ship)
67        {
68/*
69        ship->setMaxSpeed( ship->getMaxSpeed() - this->boost_);
70        ship->setTransAcc( ship->getTransAcc()/this->accboost_);
71        ship->setMaxRotation( ship->getMaxRotation()-this->rotacc_);
72        ship->setRotAcc( ship->getRotAcc()-this->rotacc_);
73        COUT(3)<<"BOOST UNSET"<<std::endl;
74        COUT(3)<<"Speed:"<< ship->getMaxSpeed()<<std::endl;
75*/
76        ship->setPermanentBoost(false);
77        }
78
79        void Turbo::setSpeedBoost(SpaceShip* ship)
80        {
81/*
82        COUT(3)<<"Speed:"<< ship->getMaxSpeed()<<std::endl;
83        ship->setMaxSpeed( ship->getMaxSpeed() + this->boost_);
84        ship->setTransAcc( ship->getTransAcc()*this->accboost_);
85        ship->setMaxRotation( ship->getMaxRotation()+this->rotacc_);
86        ship->setRotAcc( ship->getRotAcc()+this->rotacc_);
87*/
88    ship->setPermanentBoost(true);
89    ship->setBoost(true);
90
91        if( this->duration_ != 0)
92        {
93                ExecutorMember<Turbo>* executor = createExecutor(createFunctor(&Turbo::unsetSpeedBoost));
94                executor->setDefaultValues(ship);
95                turbotimer_.setTimer(this->duration_, false, this, executor);
96        }
97//      COUT(3)<<"Speed:"<< ship->getMaxSpeed()<<std::endl;
98        }
99        bool Turbo::dropped(Pawn* player)
100        {
101                if (this->duration_ == 0)
102                {
103                        COUT(0) << "ITEM DROPPED" << std::endl;
104                        if(remove(player)==true);
105                        {
106                        SpaceShip* ship = dynamic_cast <SpaceShip*>(player);
107                        this->unsetSpeedBoost(ship);
108                        }
109                }
110                return true;
111        }
112
113}
114/*<Template baseclass="Turbo" name=turboitem>
115      <Turbo playerclass="SpaceShip" boost=150 duration=10 accboost=10 />
116    </Template>
117
118    <PickupSpawner item=turboitem>
119      <attached>
120        <Billboard material="Examples/Flare" scale=0.2 colour="0.0, 0.0, 1.0, 1.0" />
121      </attached>
122    </PickupSpawner>*/
123
124
125
126
127
Note: See TracBrowser for help on using the repository browser.