| 1 | #include "OrxonoxStableHeaders.h" |
|---|
| 2 | #include "Turbo.h" |
|---|
| 3 | |
|---|
| 4 | #include "objects/worldentities/pawns/SpaceShip.h" |
|---|
| 5 | #include "core/Executor.h" |
|---|
| 6 | #include "core/CoreIncludes.h" |
|---|
| 7 | #include "core/XMLPort.h" |
|---|
| 8 | |
|---|
| 9 | namespace orxonox |
|---|
| 10 | { |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | CreateFactory(Turbo); |
|---|
| 14 | |
|---|
| 15 | Turbo::Turbo(BaseObject* creator) : BaseItem(creator) |
|---|
| 16 | { |
|---|
| 17 | RegisterObject(Turbo); |
|---|
| 18 | |
|---|
| 19 | this->boost_ = 0; |
|---|
| 20 | this->duration_ = 0; |
|---|
| 21 | this->accboost_ = 1; |
|---|
| 22 | this->rotacc_= 0; |
|---|
| 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); |
|---|
| 36 | XMLPortParam(Turbo, "rotacc", setRotAcc, getRotAcc, xmlelement, mode); |
|---|
| 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 | /* |
|---|
| 70 | ship->setMaxSpeed( ship->getMaxSpeed() - this->boost_); |
|---|
| 71 | ship->setTransAcc( ship->getTransAcc()/this->accboost_); |
|---|
| 72 | ship->setMaxRotation( ship->getMaxRotation()-this->rotacc_); |
|---|
| 73 | ship->setRotAcc( ship->getRotAcc()-this->rotacc_); |
|---|
| 74 | COUT(3)<<"BOOST UNSET"<<std::endl; |
|---|
| 75 | COUT(3)<<"Speed:"<< ship->getMaxSpeed()<<std::endl; |
|---|
| 76 | */ |
|---|
| 77 | ship->setPermanentBoost(false); |
|---|
| 78 | } |
|---|
| 79 | |
|---|
| 80 | void Turbo::setSpeedBoost(SpaceShip* ship) |
|---|
| 81 | { |
|---|
| 82 | /* |
|---|
| 83 | COUT(3)<<"Speed:"<< ship->getMaxSpeed()<<std::endl; |
|---|
| 84 | ship->setMaxSpeed( ship->getMaxSpeed() + this->boost_); |
|---|
| 85 | ship->setTransAcc( ship->getTransAcc()*this->accboost_); |
|---|
| 86 | ship->setMaxRotation( ship->getMaxRotation()+this->rotacc_); |
|---|
| 87 | ship->setRotAcc( ship->getRotAcc()+this->rotacc_); |
|---|
| 88 | */ |
|---|
| 89 | ship->setPermanentBoost(true); |
|---|
| 90 | ship->setBoost(true); |
|---|
| 91 | |
|---|
| 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 | } |
|---|
| 98 | // COUT(3)<<"Speed:"<< ship->getMaxSpeed()<<std::endl; |
|---|
| 99 | } |
|---|
| 100 | bool Turbo::dropped(Pawn* player) |
|---|
| 101 | { |
|---|
| 102 | if (this->duration_ == 0) |
|---|
| 103 | { |
|---|
| 104 | COUT(0) << "ITEM DROPPED" << std::endl; |
|---|
| 105 | if(remove(player)==true) |
|---|
| 106 | { |
|---|
| 107 | SpaceShip* ship = dynamic_cast <SpaceShip*>(player); |
|---|
| 108 | this->unsetSpeedBoost(ship); |
|---|
| 109 | } |
|---|
| 110 | } |
|---|
| 111 | return true; |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | } |
|---|
| 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 | |
|---|
| 125 | |
|---|
| 126 | |
|---|
| 127 | |
|---|
| 128 | |
|---|