[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 | { |
---|
[2389] | 41 | |
---|
[2227] | 42 | if(player-> isA(this->getPlayerBaseClass())) |
---|
[2202] | 43 | { |
---|
[2227] | 44 | SpaceShip* ship = dynamic_cast <SpaceShip*>(player); |
---|
[2324] | 45 | if(duration_==0 ) |
---|
[2397] | 46 | { |
---|
| 47 | if(addTo(player)) |
---|
| 48 | { |
---|
[2389] | 49 | COUT(3)<<"ITEM EQUIPPED"<<std::endl; |
---|
[2324] | 50 | this->setSpeedBoost(ship); |
---|
| 51 | return true; |
---|
[2397] | 52 | } |
---|
| 53 | return false; |
---|
[2202] | 54 | } |
---|
[2324] | 55 | else |
---|
| 56 | { |
---|
| 57 | this->setSpeedBoost(ship); |
---|
| 58 | return true; |
---|
| 59 | } |
---|
| 60 | return false; |
---|
| 61 | } |
---|
[2202] | 62 | return false; |
---|
| 63 | |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | |
---|
[2227] | 67 | void Turbo::unsetSpeedBoost(SpaceShip* ship) |
---|
[2202] | 68 | { |
---|
[2227] | 69 | ship->setMaxSpeed( ship->getMaxSpeed() - this->boost_); |
---|
| 70 | ship->setTransAcc( ship->getTransAcc()/this->accboost_); |
---|
[2289] | 71 | ship->setMaxRotation( ship->getMaxRotation()-this->rotacc_); |
---|
| 72 | ship->setRotAcc( ship->getRotAcc()-this->rotacc_); |
---|
[2389] | 73 | COUT(3)<<"BOOST UNSET"<<std::endl; |
---|
[2397] | 74 | COUT(3)<<"Speed:"<< ship->getMaxSpeed()<<std::endl; |
---|
[2202] | 75 | } |
---|
| 76 | |
---|
[2227] | 77 | void Turbo::setSpeedBoost(SpaceShip* ship) |
---|
[2202] | 78 | { |
---|
[2397] | 79 | COUT(3)<<"Speed:"<< ship->getMaxSpeed()<<std::endl; |
---|
[2227] | 80 | ship->setMaxSpeed( ship->getMaxSpeed() + this->boost_); |
---|
| 81 | ship->setTransAcc( ship->getTransAcc()*this->accboost_); |
---|
[2289] | 82 | ship->setMaxRotation( ship->getMaxRotation()+this->rotacc_); |
---|
| 83 | ship->setRotAcc( ship->getRotAcc()+this->rotacc_); |
---|
[2227] | 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 | } |
---|
[2397] | 90 | COUT(3)<<"Speed:"<< ship->getMaxSpeed()<<std::endl; |
---|
[2202] | 91 | } |
---|
[2227] | 92 | bool Turbo::dropped(Pawn* player) |
---|
| 93 | { |
---|
| 94 | if (this->duration_ == 0) |
---|
| 95 | { |
---|
[2389] | 96 | COUT(0) << "ITEM DROPPED" << std::endl; |
---|
[2289] | 97 | if(remove(player)==true); |
---|
| 98 | { |
---|
[2227] | 99 | SpaceShip* ship = dynamic_cast <SpaceShip*>(player); |
---|
| 100 | this->unsetSpeedBoost(ship); |
---|
[2289] | 101 | } |
---|
[2227] | 102 | } |
---|
| 103 | return true; |
---|
| 104 | } |
---|
[2202] | 105 | |
---|
| 106 | } |
---|
[2227] | 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 | |
---|
[2202] | 117 | |
---|
| 118 | |
---|
| 119 | |
---|
| 120 | |
---|