[2227] | 1 | #include "Turbo.h" |
---|
| 2 | |
---|
| 3 | #include "objects/worldentities/pawns/SpaceShip.h" |
---|
[2202] | 4 | #include "core/Executor.h" |
---|
[2227] | 5 | #include "core/CoreIncludes.h" |
---|
| 6 | #include "core/XMLPort.h" |
---|
[2202] | 7 | |
---|
| 8 | namespace orxonox |
---|
| 9 | { |
---|
[2227] | 10 | |
---|
[2202] | 11 | |
---|
[2227] | 12 | CreateFactory(Turbo); |
---|
| 13 | |
---|
| 14 | Turbo::Turbo(BaseObject* creator) : Item(creator) |
---|
[2202] | 15 | { |
---|
[2227] | 16 | RegisterObject(Turbo); |
---|
| 17 | |
---|
| 18 | this->boost_ = 0; |
---|
| 19 | this->duration_ = 0; |
---|
| 20 | this->accboost_ = 1; |
---|
[2289] | 21 | this->rotacc_= 0; |
---|
[2227] | 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); |
---|
[2289] | 35 | XMLPortParam(Turbo, "rotacc", setRotAcc, getRotAcc, xmlelement, mode); |
---|
| 36 | |
---|
[2227] | 37 | } |
---|
| 38 | |
---|
| 39 | bool Turbo::pickedUp(Pawn* player) |
---|
| 40 | { |
---|
| 41 | if(player-> isA(this->getPlayerBaseClass())) |
---|
[2202] | 42 | { |
---|
[2227] | 43 | SpaceShip* ship = dynamic_cast <SpaceShip*>(player); |
---|
[2324] | 44 | if(duration_==0 ) |
---|
| 45 | { if(addTo(player)) |
---|
| 46 | { |
---|
| 47 | this->setSpeedBoost(ship); |
---|
| 48 | return true; |
---|
| 49 | } |
---|
[2202] | 50 | } |
---|
[2324] | 51 | else |
---|
| 52 | { |
---|
| 53 | this->setSpeedBoost(ship); |
---|
| 54 | return true; |
---|
| 55 | } |
---|
| 56 | return false; |
---|
| 57 | } |
---|
[2202] | 58 | return false; |
---|
| 59 | |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | |
---|
[2227] | 63 | void Turbo::unsetSpeedBoost(SpaceShip* ship) |
---|
[2202] | 64 | { |
---|
[2227] | 65 | ship->setMaxSpeed( ship->getMaxSpeed() - this->boost_); |
---|
| 66 | ship->setTransAcc( ship->getTransAcc()/this->accboost_); |
---|
[2289] | 67 | ship->setMaxRotation( ship->getMaxRotation()-this->rotacc_); |
---|
| 68 | ship->setRotAcc( ship->getRotAcc()-this->rotacc_); |
---|
[2227] | 69 | COUT(3)<<"PickUp Timer expired"<<std::endl; |
---|
[2202] | 70 | } |
---|
| 71 | |
---|
[2227] | 72 | void Turbo::setSpeedBoost(SpaceShip* ship) |
---|
[2202] | 73 | { |
---|
[2227] | 74 | ship->setMaxSpeed( ship->getMaxSpeed() + this->boost_); |
---|
| 75 | ship->setTransAcc( ship->getTransAcc()*this->accboost_); |
---|
[2289] | 76 | ship->setMaxRotation( ship->getMaxRotation()+this->rotacc_); |
---|
| 77 | ship->setRotAcc( ship->getRotAcc()+this->rotacc_); |
---|
[2227] | 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 | } |
---|
[2202] | 84 | |
---|
| 85 | } |
---|
[2227] | 86 | bool Turbo::dropped(Pawn* player) |
---|
| 87 | { |
---|
| 88 | if (this->duration_ == 0) |
---|
| 89 | { |
---|
[2324] | 90 | COUT(0) << "dropped" << std::endl; |
---|
[2289] | 91 | if(remove(player)==true); |
---|
| 92 | { |
---|
[2227] | 93 | SpaceShip* ship = dynamic_cast <SpaceShip*>(player); |
---|
| 94 | this->unsetSpeedBoost(ship); |
---|
[2289] | 95 | } |
---|
[2227] | 96 | } |
---|
| 97 | return true; |
---|
| 98 | } |
---|
[2202] | 99 | |
---|
| 100 | } |
---|
[2227] | 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 | |
---|
[2202] | 111 | |
---|
| 112 | |
---|
| 113 | |
---|
| 114 | |
---|