[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; |
---|
| 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())) |
---|
[2202] | 39 | { |
---|
[2227] | 40 | SpaceShip* ship = dynamic_cast <SpaceShip*>(player); |
---|
| 41 | this->setSpeedBoost(ship); |
---|
| 42 | if(duration_==0) |
---|
| 43 | addTo(player); |
---|
[2202] | 44 | return true; |
---|
| 45 | } |
---|
| 46 | return false; |
---|
| 47 | |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | |
---|
[2227] | 51 | void Turbo::unsetSpeedBoost(SpaceShip* ship) |
---|
[2202] | 52 | { |
---|
[2227] | 53 | ship->setMaxSpeed( ship->getMaxSpeed() - this->boost_); |
---|
| 54 | ship->setTransAcc( ship->getTransAcc()/this->accboost_); |
---|
| 55 | COUT(3)<<"PickUp Timer expired"<<std::endl; |
---|
[2202] | 56 | } |
---|
| 57 | |
---|
[2227] | 58 | void Turbo::setSpeedBoost(SpaceShip* ship) |
---|
[2202] | 59 | { |
---|
[2227] | 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 | } |
---|
[2202] | 68 | |
---|
| 69 | } |
---|
[2227] | 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 | } |
---|
[2202] | 80 | |
---|
| 81 | } |
---|
[2227] | 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 | |
---|
[2202] | 92 | |
---|
| 93 | |
---|
| 94 | |
---|
| 95 | |
---|