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