Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/objects/controllers/AIController.cc @ 3172

Last change on this file since 3172 was 3110, checked in by rgrieder, 16 years ago

Removed old msvc specific support for precompiled header files.

  • Property svn:eol-style set to native
File size: 3.3 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:
25 *      ...
26 *
27 */
28
29#include "AIController.h"
30
31#include "core/CoreIncludes.h"
32#include "core/Executor.h"
33#include "objects/worldentities/ControllableEntity.h"
34
35namespace orxonox
36{
37    static const float ACTION_INTERVAL = 1.0f;
38
39    CreateFactory(AIController);
40
41    AIController::AIController(BaseObject* creator) : ArtificialController(creator)
42    {
43        RegisterObject(AIController);
44
[3084]45        this->actionTimer_.setTimer(ACTION_INTERVAL, true, this, createExecutor(createFunctor(&AIController::action)));
[2362]46    }
47
48    AIController::~AIController()
49    {
50    }
51
52    void AIController::action()
53    {
54        float random;
55        float maxrand = 100.0f / ACTION_INTERVAL;
[2493]56
[2362]57        // search enemy
58        random = rnd(maxrand);
59        if (random < 15 && (!this->target_))
60            this->searchNewTarget();
61
62        // forget enemy
63        random = rnd(maxrand);
64        if (random < 5 && (this->target_))
65            this->forgetTarget();
66
67        // next enemy
68        random = rnd(maxrand);
69        if (random < 10 && (this->target_))
70            this->searchNewTarget();
[2493]71
[2362]72        // fly somewhere
73        random = rnd(maxrand);
74        if (random < 50 && (!this->bHasTargetPosition_ && !this->target_))
75            this->searchRandomTargetPosition();
76
77        // stop flying
78        random = rnd(maxrand);
79        if (random < 10 && (this->bHasTargetPosition_ && !this->target_))
80            this->bHasTargetPosition_ = false;
81
82        // fly somewhere else
83        random = rnd(maxrand);
84        if (random < 30 && (this->bHasTargetPosition_ && !this->target_))
85            this->searchRandomTargetPosition();
[2493]86
[2362]87        // shoot
88        random = rnd(maxrand);
89        if (random < 75 && (this->target_ && !this->bShooting_))
90            this->bShooting_ = true;
91
92        // stop shooting
93        random = rnd(maxrand);
94        if (random < 25 && (this->bShooting_))
95            this->bShooting_ = false;
96    }
97
98    void AIController::tick(float dt)
99    {
100        if (!this->isActive())
101            return;
102
103        if (this->target_)
104            this->aimAtTarget();
105
106        if (this->bHasTargetPosition_)
[3049]107            this->moveToTargetPosition();
[2362]108
[3049]109        if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(Ogre::Math::PI / 20.0))
[3053]110            this->getControllableEntity()->fire(0);
[2362]111
112        SUPER(AIController, tick, dt);
113    }
114
115}
Note: See TracBrowser for help on using the repository browser.