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 | } |
---|
22 | |
---|
23 | Turbo::~Turbo() |
---|
24 | { |
---|
25 | } |
---|
26 | |
---|
27 | void Turbo::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
28 | { |
---|
29 | SUPER(Turbo, XMLPort, xmlelement, mode); |
---|
30 | |
---|
31 | XMLPortParam(Turbo, "boost", setBoost, getBoost, xmlelement, mode); |
---|
32 | XMLPortParam(Turbo, "duration", setDuration, getDuration, xmlelement, mode); |
---|
33 | XMLPortParam(Turbo, "accboost", setAccBoost, getAccBoost, xmlelement, mode); |
---|
34 | } |
---|
35 | |
---|
36 | bool Turbo::pickedUp(Pawn* player) |
---|
37 | { |
---|
38 | if(player-> isA(this->getPlayerBaseClass())) |
---|
39 | { |
---|
40 | SpaceShip* ship = dynamic_cast <SpaceShip*>(player); |
---|
41 | this->setSpeedBoost(ship); |
---|
42 | if(duration_==0) |
---|
43 | addTo(player); |
---|
44 | return true; |
---|
45 | } |
---|
46 | return false; |
---|
47 | |
---|
48 | } |
---|
49 | |
---|
50 | |
---|
51 | void Turbo::unsetSpeedBoost(SpaceShip* ship) |
---|
52 | { |
---|
53 | ship->setMaxSpeed( ship->getMaxSpeed() - this->boost_); |
---|
54 | ship->setTransAcc( ship->getTransAcc()/this->accboost_); |
---|
55 | COUT(3)<<"PickUp Timer expired"<<std::endl; |
---|
56 | } |
---|
57 | |
---|
58 | void Turbo::setSpeedBoost(SpaceShip* ship) |
---|
59 | { |
---|
60 | ship->setMaxSpeed( ship->getMaxSpeed() + this->boost_); |
---|
61 | ship->setTransAcc( ship->getTransAcc()*this->accboost_); |
---|
62 | if( this->duration_ != 0) |
---|
63 | { |
---|
64 | ExecutorMember<Turbo>* executor = createExecutor(createFunctor(&Turbo::unsetSpeedBoost)); |
---|
65 | executor->setDefaultValues(ship); |
---|
66 | turbotimer_.setTimer(this->duration_, false, this, executor); |
---|
67 | } |
---|
68 | |
---|
69 | } |
---|
70 | bool Turbo::dropped(Pawn* player) |
---|
71 | { |
---|
72 | if (this->duration_ == 0) |
---|
73 | { |
---|
74 | //player->Equipment.erase ( std::pair<std::string, Item*>(this->itemname,this) ); |
---|
75 | SpaceShip* ship = dynamic_cast <SpaceShip*>(player); |
---|
76 | this->unsetSpeedBoost(ship); |
---|
77 | } |
---|
78 | return true; |
---|
79 | } |
---|
80 | |
---|
81 | } |
---|
82 | /*<Template baseclass="Turbo" name=turboitem> |
---|
83 | <Turbo playerclass="SpaceShip" boost=150 duration=10 accboost=10 /> |
---|
84 | </Template> |
---|
85 | |
---|
86 | <PickupSpawner item=turboitem> |
---|
87 | <attached> |
---|
88 | <Billboard material="Examples/Flare" scale=0.2 colour="0.0, 0.0, 1.0, 1.0" /> |
---|
89 | </attached> |
---|
90 | </PickupSpawner>*/ |
---|
91 | |
---|
92 | |
---|
93 | |
---|
94 | |
---|
95 | |
---|