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 | |
---|
8 | namespace 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 | if(duration_==0 ) |
---|
45 | { if(addTo(player)) |
---|
46 | { |
---|
47 | this->setSpeedBoost(ship); |
---|
48 | return true; |
---|
49 | } |
---|
50 | } |
---|
51 | else |
---|
52 | { |
---|
53 | this->setSpeedBoost(ship); |
---|
54 | return true; |
---|
55 | } |
---|
56 | return false; |
---|
57 | } |
---|
58 | return false; |
---|
59 | |
---|
60 | } |
---|
61 | |
---|
62 | |
---|
63 | void Turbo::unsetSpeedBoost(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 | COUT(3)<<"PickUp Timer expired"<<std::endl; |
---|
70 | } |
---|
71 | |
---|
72 | void Turbo::setSpeedBoost(SpaceShip* ship) |
---|
73 | { |
---|
74 | ship->setMaxSpeed( ship->getMaxSpeed() + this->boost_); |
---|
75 | ship->setTransAcc( ship->getTransAcc()*this->accboost_); |
---|
76 | ship->setMaxRotation( ship->getMaxRotation()+this->rotacc_); |
---|
77 | ship->setRotAcc( ship->getRotAcc()+this->rotacc_); |
---|
78 | if( this->duration_ != 0) |
---|
79 | { |
---|
80 | ExecutorMember<Turbo>* executor = createExecutor(createFunctor(&Turbo::unsetSpeedBoost)); |
---|
81 | executor->setDefaultValues(ship); |
---|
82 | turbotimer_.setTimer(this->duration_, false, this, executor); |
---|
83 | } |
---|
84 | |
---|
85 | } |
---|
86 | bool Turbo::dropped(Pawn* player) |
---|
87 | { |
---|
88 | if (this->duration_ == 0) |
---|
89 | { |
---|
90 | COUT(0) << "dropped" << std::endl; |
---|
91 | if(remove(player)==true); |
---|
92 | { |
---|
93 | SpaceShip* ship = dynamic_cast <SpaceShip*>(player); |
---|
94 | this->unsetSpeedBoost(ship); |
---|
95 | } |
---|
96 | } |
---|
97 | return true; |
---|
98 | } |
---|
99 | |
---|
100 | } |
---|
101 | /*<Template baseclass="Turbo" name=turboitem> |
---|
102 | <Turbo playerclass="SpaceShip" boost=150 duration=10 accboost=10 /> |
---|
103 | </Template> |
---|
104 | |
---|
105 | <PickupSpawner item=turboitem> |
---|
106 | <attached> |
---|
107 | <Billboard material="Examples/Flare" scale=0.2 colour="0.0, 0.0, 1.0, 1.0" /> |
---|
108 | </attached> |
---|
109 | </PickupSpawner>*/ |
---|
110 | |
---|
111 | |
---|
112 | |
---|
113 | |
---|
114 | |
---|