1 | /* |
---|
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 | * Fabian 'x3n' Landau |
---|
24 | * Co-authors: |
---|
25 | * Dominik Solenicki |
---|
26 | * |
---|
27 | */ |
---|
28 | |
---|
29 | #include "ArtificialController.h" |
---|
30 | #include "core/CoreIncludes.h" |
---|
31 | #include "worldentities/pawns/Pawn.h" |
---|
32 | |
---|
33 | |
---|
34 | namespace orxonox |
---|
35 | { |
---|
36 | |
---|
37 | ArtificialController::ArtificialController(BaseObject* creator) : FormationController(creator) |
---|
38 | { |
---|
39 | |
---|
40 | } |
---|
41 | |
---|
42 | ArtificialController::~ArtificialController() |
---|
43 | { |
---|
44 | |
---|
45 | } |
---|
46 | |
---|
47 | |
---|
48 | /** |
---|
49 | @brief Gets called when ControllableEntity is being changed. Resets the bot when it dies. |
---|
50 | */ |
---|
51 | void ArtificialController::changedControllableEntity() |
---|
52 | { |
---|
53 | if (!this->getControllableEntity()) |
---|
54 | this->removeFromFormation(); |
---|
55 | } |
---|
56 | |
---|
57 | |
---|
58 | void ArtificialController::aimAtTarget() |
---|
59 | { |
---|
60 | if (!this->target_ || !this->getControllableEntity()) |
---|
61 | return; |
---|
62 | |
---|
63 | static const float hardcoded_projectile_speed = 1250; |
---|
64 | |
---|
65 | this->targetPosition_ = getPredictedPosition(this->getControllableEntity()->getPosition(), hardcoded_projectile_speed, this->target_->getPosition(), this->target_->getVelocity()); |
---|
66 | this->bHasTargetPosition_ = (this->targetPosition_ != Vector3::ZERO); |
---|
67 | |
---|
68 | Pawn* pawn = orxonox_cast<Pawn*>(this->getControllableEntity()); |
---|
69 | if (pawn) |
---|
70 | pawn->setAimPosition(this->targetPosition_); |
---|
71 | } |
---|
72 | |
---|
73 | bool ArtificialController::isCloseAtTarget(float distance) const |
---|
74 | { |
---|
75 | if (!this->getControllableEntity()) |
---|
76 | return false; |
---|
77 | |
---|
78 | if (!this->target_) |
---|
79 | return (this->getControllableEntity()->getPosition().squaredDistance(this->targetPosition_) < distance*distance); |
---|
80 | else |
---|
81 | return (this->getControllableEntity()->getPosition().squaredDistance(this->target_->getPosition()) < distance*distance); |
---|
82 | } |
---|
83 | |
---|
84 | bool ArtificialController::isLookingAtTarget(float angle) const |
---|
85 | { |
---|
86 | if (!this->getControllableEntity()) |
---|
87 | return false; |
---|
88 | |
---|
89 | return (getAngle(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->targetPosition_) < angle); |
---|
90 | } |
---|
91 | |
---|
92 | void ArtificialController::abandonTarget(Pawn* target) |
---|
93 | { |
---|
94 | if (target == this->target_) |
---|
95 | this->targetDied(); |
---|
96 | } |
---|
97 | |
---|
98 | } |
---|