Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/formation/src/orxonox/controllers/ArtificialController.cc @ 8985

Last change on this file since 8985 was 8978, checked in by willis, 13 years ago

renamed Masterable to FormationController, some minor changes

  • Property svn:eol-style set to native
File size: 3.0 KB
RevLine 
[2362]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:
[7163]25 *      Dominik Solenicki
[2362]26 *
27 */
28
29#include "ArtificialController.h"
30#include "core/CoreIncludes.h"
[5735]31#include "worldentities/pawns/Pawn.h"
[3049]32
[8939]33
[2362]34namespace orxonox
35{
[7163]36
[8978]37    ArtificialController::ArtificialController(BaseObject* creator) : FormationController(creator)
[2362]38    {
[8939]39         
[2362]40    }
41
42    ArtificialController::~ArtificialController()
43    {
[8939]44       
[2362]45    }
46
[7163]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
[2362]58    void ArtificialController::aimAtTarget()
59    {
60        if (!this->target_ || !this->getControllableEntity())
61            return;
62
[2493]63        static const float hardcoded_projectile_speed = 1250;
[2362]64
[2493]65        this->targetPosition_ = getPredictedPosition(this->getControllableEntity()->getPosition(), hardcoded_projectile_speed, this->target_->getPosition(), this->target_->getVelocity());
[2362]66        this->bHasTargetPosition_ = (this->targetPosition_ != Vector3::ZERO);
[6417]67
[7163]68        Pawn* pawn = orxonox_cast<Pawn*>(this->getControllableEntity());
[6417]69        if (pawn)
70            pawn->setAimPosition(this->targetPosition_);
[2362]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
[5929]92    void ArtificialController::abandonTarget(Pawn* target)
[2362]93    {
[5929]94        if (target == this->target_)
95            this->targetDied();
[2362]96    }
[8939]97 
[2362]98}
Note: See TracBrowser for help on using the repository browser.