[6803] | 1 | /* |
---|
[7018] | 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * > www.orxonox.net < |
---|
| 4 | * |
---|
| 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
| 22 | * Author: |
---|
| 23 | * Gabriel Nadler, Originalfile: Oli Scheuss |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
[6803] | 28 | |
---|
| 29 | #include "RocketController.h" |
---|
| 30 | #include "projectiles/SimpleRocket.h" |
---|
| 31 | #include "util/Math.h" |
---|
[6810] | 32 | #include "weapons/projectiles/SimpleRocket.h" |
---|
[6815] | 33 | #include "util/Debug.h" |
---|
[6834] | 34 | #include "weapons/weaponmodes/SimpleRocketFire.h" |
---|
[6904] | 35 | #include "worldentities/pawns/Pawn.h" |
---|
[6803] | 36 | |
---|
| 37 | namespace orxonox |
---|
| 38 | { |
---|
| 39 | /** |
---|
| 40 | @brief |
---|
[7018] | 41 | Constructor. |
---|
[6803] | 42 | */ |
---|
| 43 | RocketController::RocketController(BaseObject* creator) : Controller(creator) |
---|
| 44 | { |
---|
[6951] | 45 | RegisterObject(RocketController); |
---|
| 46 | COUT(5)<< "RocketController constructed\n"; |
---|
[6811] | 47 | |
---|
[7018] | 48 | |
---|
| 49 | this->rocket_ = new SimpleRocket(this); |
---|
| 50 | this->rocket_->setController(this); |
---|
| 51 | this->setControllableEntity(dynamic_cast<ControllableEntity*> (this->rocket_)); |
---|
[6803] | 52 | } |
---|
| 53 | |
---|
| 54 | |
---|
| 55 | /** |
---|
| 56 | @brief |
---|
[7018] | 57 | The controlling happens here. This method defines what the controller has to do each tick. |
---|
[6803] | 58 | @param dt |
---|
[7018] | 59 | The duration of the tick. |
---|
[6803] | 60 | */ |
---|
| 61 | void RocketController::tick(float dt) |
---|
| 62 | { |
---|
[6811] | 63 | |
---|
[7018] | 64 | if (this->target_ && this->rocket_->hasFuel()) { |
---|
[6951] | 65 | this->setTargetPosition(); |
---|
| 66 | this->moveToTargetPosition(); |
---|
| 67 | } |
---|
[7018] | 68 | |
---|
| 69 | |
---|
[6951] | 70 | } |
---|
[6803] | 71 | |
---|
| 72 | |
---|
[6951] | 73 | RocketController::~RocketController() |
---|
| 74 | { |
---|
| 75 | COUT(5)<< "RocketController destroyed\n"; |
---|
| 76 | } |
---|
[6814] | 77 | |
---|
[6951] | 78 | void RocketController::setTargetPosition() |
---|
| 79 | { |
---|
[7018] | 80 | this->targetPosition_=this->target_->getWorldPosition(); //don't really note a difference in the rocket behaviour xD |
---|
| 81 | //this->targetPosition_ = getPredictedPosition(this->getControllableEntity()->getWorldPosition(),this->getControllableEntity()->getVelocity().length() , this->target_->getWorldPosition(), this->target_->getVelocity()); |
---|
[6951] | 82 | } |
---|
| 83 | void RocketController::moveToTargetPosition() |
---|
| 84 | { |
---|
| 85 | this->moveToPosition(this->targetPosition_); |
---|
| 86 | } |
---|
[6814] | 87 | |
---|
[6905] | 88 | |
---|
| 89 | |
---|
[6951] | 90 | void RocketController::setTarget(WorldEntity* target) |
---|
| 91 | { |
---|
| 92 | this->target_ = target; |
---|
| 93 | } |
---|
[6814] | 94 | |
---|
[6951] | 95 | void RocketController::moveToPosition(const Vector3& target) |
---|
[6905] | 96 | { |
---|
[6951] | 97 | if (!this->getControllableEntity()) |
---|
[6905] | 98 | return; |
---|
[7018] | 99 | |
---|
[7021] | 100 | Vector2 coord = get2DViewdirection(this->rocket_->getPosition(), this->rocket_->getOrientation() * WorldEntity::FRONT, this->rocket_->getOrientation() * WorldEntity::UP, target); |
---|
| 101 | float distance = (target - this->rocket_->getWorldPosition()).length(); |
---|
[7018] | 102 | |
---|
[7021] | 103 | |
---|
| 104 | if (distance > 1000 && this->rocket_->getVelocity().squaredLength()<160000) |
---|
| 105 | this->rocket_->setAcceleration(this->rocket_->getOrientation()*Vector3(-20,-20,-20)); |
---|
[7018] | 106 | if (distance <1000) this->rocket_->setAcceleration(0,0,0); |
---|
[7021] | 107 | |
---|
| 108 | this->rocket_->rotateYaw(-sgn(coord.x)*coord.x*coord.x); |
---|
| 109 | this->rocket_->rotatePitch(sgn(coord.y)*coord.y*coord.y); |
---|
[6905] | 110 | } |
---|
| 111 | |
---|
| 112 | |
---|
| 113 | |
---|
| 114 | |
---|
[6803] | 115 | } |
---|