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