Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/pickups2/src/orxonox/objects/pickup/Turbo.cc @ 2294

Last change on this file since 2294 was 2289, checked in by dsommer, 16 years ago

Added ShipEquipment to Pawn and various funtions for it -not compiling, because private…

File size: 2.4 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) : Item(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
39        bool Turbo::pickedUp(Pawn* player)
40        {
41                if(player-> isA(this->getPlayerBaseClass()))
42                        {
43                        SpaceShip* ship = dynamic_cast <SpaceShip*>(player);
44                        this->setSpeedBoost(ship);
45                        if(duration_==0)
46                        addTo(player);
47                        return true;
48                        }
49                return false;
50
51        }
52       
53       
54        void Turbo::unsetSpeedBoost(SpaceShip* ship)
55        {
56        ship->setMaxSpeed( ship->getMaxSpeed() - this->boost_);
57        ship->setTransAcc( ship->getTransAcc()/this->accboost_);
58        ship->setMaxRotation( ship->getMaxRotation()-this->rotacc_);
59        ship->setRotAcc( ship->getRotAcc()-this->rotacc_);
60        COUT(3)<<"PickUp Timer expired"<<std::endl;
61        }
62
63        void Turbo::setSpeedBoost(SpaceShip* ship)
64        {
65        ship->setMaxSpeed( ship->getMaxSpeed() + this->boost_);
66        ship->setTransAcc( ship->getTransAcc()*this->accboost_);
67        ship->setMaxRotation( ship->getMaxRotation()+this->rotacc_);
68        ship->setRotAcc( ship->getRotAcc()+this->rotacc_);
69        if( this->duration_ != 0)
70        {
71                ExecutorMember<Turbo>* executor = createExecutor(createFunctor(&Turbo::unsetSpeedBoost));
72                executor->setDefaultValues(ship);
73                turbotimer_.setTimer(this->duration_, false, this, executor);
74        }
75       
76        }
77        bool Turbo::dropped(Pawn* player)
78        {
79                if (this->duration_ == 0)
80                {
81                        if(remove(player)==true);
82                        {
83                        SpaceShip* ship = dynamic_cast <SpaceShip*>(player);
84                        this->unsetSpeedBoost(ship);
85                        }       
86                }
87                return true;
88        }
89       
90}
91/*<Template baseclass="Turbo" name=turboitem>
92      <Turbo playerclass="SpaceShip" boost=150 duration=10 accboost=10 />
93    </Template>
94
95    <PickupSpawner item=turboitem>
96      <attached>
97        <Billboard material="Examples/Flare" scale=0.2 colour="0.0, 0.0, 1.0, 1.0" />
98      </attached>
99    </PickupSpawner>*/
100
101       
102       
103       
104       
Note: See TracBrowser for help on using the repository browser.