Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/ai/src/orxonox/controllers/Detector.cc @ 8143

Last change on this file since 8143 was 7827, checked in by jo, 14 years ago

First draft. The detector tries to detect events that are critical for ai-bots. Furthermore the detected events have to be further analyzed.

File size: 2.9 KB
Line 
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 detls.
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 *      Johannes Ritz
24 *   Co-authors:
25 *     
26 *
27 */
28
29#include "Detector.h"
30
31#include "util/Math.h"
32#include "core/CoreIncludes.h"
33#include "worldentities/pawns/Pawn.h"
34
35namespace orxonox
36{
37    const float NOT_UNDER_ATTACK_LIMIT=2.0f;
38
39    CreateFactory(Detector);
40
41    Detector::Detector(BaseObject* creator) : ArtificialController(creator)
42    {
43        RegisterObject(Detector);
44        this->healthLost = 0;
45        this->notUnderAttackTime = 2.0f;
46        this->bUnderAttack = false;
47        this->bot_ = orxonox_cast<Pawn*>(this->getControllableEntity());
48        if(bot_)
49            this->previousHealth = bot_->getHealth();
50        else
51            this->previousHealth = 0;
52        this->botLevel = 10.0f;
53        this->attacker_=0;
54    }
55
56    Detector::~Detector()
57    {
58    }
59   
60    void Detector::tick(float dt) //TODO: set a checking interval depending on ai-level
61    {
62        SUPER(Detector, tick, dt);
63       
64        notUnderAttackTime += dt;
65        if(bot_)
66        {
67            this->checkHealth();
68        }
69        else
70        {
71            bot_ = orxonox_cast<Pawn*>(this->getControllableEntity());
72        }
73        bUnderAttack = this->checkUnderAttack();
74    }
75   
76    void Detector::checkHealth() //finds out if bot lost life
77    {
78        float actualHealth = this->bot_->getHealth();
79        healthLost = previousHealth - actualHealth;
80        if (healthLost>0)
81        {
82            notUnderAttackTime=0;
83            this->analyseAttack();
84        }
85        previousHealth = actualHealth;
86    }
87   
88    bool Detector::checkUnderAttack()
89    {
90        return (NOT_UNDER_ATTACK_LIMIT > notUnderAttackTime);
91    }
92   
93    void Detector::analyseAttack()
94    {
95        if (attacker_)//attacker is already known
96            return;
97        else
98        {
99        ;
100        }       
101        ;//?? from where came the attack;
102        //Kombination aus isLooking at und object list und ???
103        //idea: if the attacker is viewable he is known. Else the attacking direction is know.
104        //callForHelp-Function to friendly pawns
105    }
106}
Note: See TracBrowser for help on using the repository browser.