[2503] | 1 | #include "OrxonoxStableHeaders.h" |
---|
[2227] | 2 | #include "Turbo.h" |
---|
| 3 | |
---|
| 4 | #include "objects/worldentities/pawns/SpaceShip.h" |
---|
[2202] | 5 | #include "core/Executor.h" |
---|
[2227] | 6 | #include "core/CoreIncludes.h" |
---|
| 7 | #include "core/XMLPort.h" |
---|
[2202] | 8 | |
---|
| 9 | namespace orxonox |
---|
| 10 | { |
---|
| 11 | |
---|
[2500] | 12 | |
---|
[2227] | 13 | CreateFactory(Turbo); |
---|
| 14 | |
---|
[2500] | 15 | Turbo::Turbo(BaseObject* creator) : BaseItem(creator) |
---|
[2202] | 16 | { |
---|
[2227] | 17 | RegisterObject(Turbo); |
---|
| 18 | |
---|
| 19 | this->boost_ = 0; |
---|
| 20 | this->duration_ = 0; |
---|
| 21 | this->accboost_ = 1; |
---|
[2289] | 22 | this->rotacc_= 0; |
---|
[2227] | 23 | } |
---|
| 24 | |
---|
| 25 | Turbo::~Turbo() |
---|
| 26 | { |
---|
| 27 | } |
---|
| 28 | |
---|
| 29 | void Turbo::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
| 30 | { |
---|
| 31 | SUPER(Turbo, XMLPort, xmlelement, mode); |
---|
| 32 | |
---|
| 33 | XMLPortParam(Turbo, "boost", setBoost, getBoost, xmlelement, mode); |
---|
| 34 | XMLPortParam(Turbo, "duration", setDuration, getDuration, xmlelement, mode); |
---|
| 35 | XMLPortParam(Turbo, "accboost", setAccBoost, getAccBoost, xmlelement, mode); |
---|
[2500] | 36 | XMLPortParam(Turbo, "rotacc", setRotAcc, getRotAcc, xmlelement, mode); |
---|
[2227] | 37 | } |
---|
| 38 | |
---|
| 39 | bool Turbo::pickedUp(Pawn* player) |
---|
| 40 | { |
---|
[2500] | 41 | |
---|
[2227] | 42 | if(player-> isA(this->getPlayerBaseClass())) |
---|
[2202] | 43 | { |
---|
[2227] | 44 | SpaceShip* ship = dynamic_cast <SpaceShip*>(player); |
---|
[2324] | 45 | if(duration_==0 ) |
---|
[2500] | 46 | { |
---|
[2397] | 47 | if(addTo(player)) |
---|
[2500] | 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 | } |
---|
[2500] | 65 | |
---|
| 66 | |
---|
[2227] | 67 | void Turbo::unsetSpeedBoost(SpaceShip* ship) |
---|
[2202] | 68 | { |
---|
[2500] | 69 | /* |
---|
[2227] | 70 | ship->setMaxSpeed( ship->getMaxSpeed() - this->boost_); |
---|
| 71 | ship->setTransAcc( ship->getTransAcc()/this->accboost_); |
---|
[2289] | 72 | ship->setMaxRotation( ship->getMaxRotation()-this->rotacc_); |
---|
| 73 | ship->setRotAcc( ship->getRotAcc()-this->rotacc_); |
---|
[2389] | 74 | COUT(3)<<"BOOST UNSET"<<std::endl; |
---|
[2397] | 75 | COUT(3)<<"Speed:"<< ship->getMaxSpeed()<<std::endl; |
---|
[2500] | 76 | */ |
---|
| 77 | ship->setPermanentBoost(false); |
---|
[2202] | 78 | } |
---|
| 79 | |
---|
[2227] | 80 | void Turbo::setSpeedBoost(SpaceShip* ship) |
---|
[2202] | 81 | { |
---|
[2500] | 82 | /* |
---|
[2397] | 83 | COUT(3)<<"Speed:"<< ship->getMaxSpeed()<<std::endl; |
---|
[2227] | 84 | ship->setMaxSpeed( ship->getMaxSpeed() + this->boost_); |
---|
| 85 | ship->setTransAcc( ship->getTransAcc()*this->accboost_); |
---|
[2289] | 86 | ship->setMaxRotation( ship->getMaxRotation()+this->rotacc_); |
---|
| 87 | ship->setRotAcc( ship->getRotAcc()+this->rotacc_); |
---|
[2500] | 88 | */ |
---|
| 89 | ship->setPermanentBoost(true); |
---|
| 90 | ship->setBoost(true); |
---|
| 91 | |
---|
[2227] | 92 | if( this->duration_ != 0) |
---|
| 93 | { |
---|
| 94 | ExecutorMember<Turbo>* executor = createExecutor(createFunctor(&Turbo::unsetSpeedBoost)); |
---|
| 95 | executor->setDefaultValues(ship); |
---|
| 96 | turbotimer_.setTimer(this->duration_, false, this, executor); |
---|
| 97 | } |
---|
[2500] | 98 | // COUT(3)<<"Speed:"<< ship->getMaxSpeed()<<std::endl; |
---|
[2202] | 99 | } |
---|
[2227] | 100 | bool Turbo::dropped(Pawn* player) |
---|
| 101 | { |
---|
| 102 | if (this->duration_ == 0) |
---|
| 103 | { |
---|
[2389] | 104 | COUT(0) << "ITEM DROPPED" << std::endl; |
---|
[2504] | 105 | if(remove(player)==true) |
---|
[2289] | 106 | { |
---|
[2504] | 107 | SpaceShip* ship = dynamic_cast <SpaceShip*>(player); |
---|
| 108 | this->unsetSpeedBoost(ship); |
---|
[2500] | 109 | } |
---|
[2227] | 110 | } |
---|
| 111 | return true; |
---|
| 112 | } |
---|
[2500] | 113 | |
---|
[2202] | 114 | } |
---|
[2227] | 115 | /*<Template baseclass="Turbo" name=turboitem> |
---|
| 116 | <Turbo playerclass="SpaceShip" boost=150 duration=10 accboost=10 /> |
---|
| 117 | </Template> |
---|
| 118 | |
---|
| 119 | <PickupSpawner item=turboitem> |
---|
| 120 | <attached> |
---|
| 121 | <Billboard material="Examples/Flare" scale=0.2 colour="0.0, 0.0, 1.0, 1.0" /> |
---|
| 122 | </attached> |
---|
| 123 | </PickupSpawner>*/ |
---|
| 124 | |
---|
[2500] | 125 | |
---|
| 126 | |
---|
| 127 | |
---|
| 128 | |
---|