Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc @ 10682

Last change on this file since 10682 was 10682, checked in by gania, 9 years ago

Set a layout for WingmanController and LeaderController

File size: 4.7 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 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 "WingmanController.h"
30
31
32namespace orxonox
33{
34    const float WingmanController::ACTION_INTERVAL = 1.0f;
35
36    RegisterClass(WingmanController);
37
38    WingmanController::WingmanController(Context* context) : SectionController(context)
39    {
40        RegisterObject(WingmanController);
41        this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&WingmanController::action, this)));
42    }
43
44    WingmanController::~WingmanController()
45    {
46    }
47
48   /* void WingmanController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
49    {
50        SUPER(WingmanController, XMLPort, xmlelement, mode);
51
52        XMLPortParam(WingmanController, "accuracy", setAccuracy, getAccuracy, xmlelement, mode).defaultValues(100.0f);
53        XMLPortObject(WingmanController, WorldEntity, "waypoints", addWaypoint, getWaypoint,  xmlelement, mode);
54    }*/
55    void WingmanController::action()
56    {
57        //--------------------------Cover Leader's rear--------------------------
58        //check for enemies in Leader's rear that can attack him and if they are visible, meaning there are no other Leader's between Leader and enemies.
59        //if there are enemies, set target_ to the nearest one and set bFollowLeader_ to false,
60        //otherwise set bFollowLeader_ to true and target_ to sectionTarget_
61        this->coverAllyRear(this->sectionLeader_);
62    }
63
64    void WingmanController::tick(float dt)
65    {
66        if (!this->isActive())
67            return;
68        //--------------------------Stay in formation--------------------------
69        if (bFollowLeader_)
70        {
71            this->keepSectionTick();
72            /*keepSectionTick(){
73                if (this->sectionLeader_ && this->sectionLeader_->getControllableEntity() && desiredRelativePosition_){
74                    Vector3 desiredAbsolutePosition = ((this->sectionLeader_->getControllableEntity()->getWorldPosition()) +
75                        (this->sectionLeader_->getControllableEntity()->getWorldOrientation()* (*desiredRelativePosition_)));
76                    this->moveToPosition (desiredAbsolutePosition);
77                }
78            }
79            */
80           
81            //--------------------------Attack same target as the Leader--------------------------
82           
83            if (this->target_)
84            {
85                this->aimAtTarget();
86                this->doFire();
87            }
88        }
89        //--------------------------Protect Leader by killing target_--------------------------
90
91        else
92        {
93            if (this->target_)
94            {
95                //--------------------------Don't attack if not visible--------------------------               
96                if (!this->target_->getRadarVisibility()) /* So AI won't shoot invisible Spaceships */
97                {
98                    this->forgetTarget();
99                    //this->bFollowLeader_ = true;
100                }
101                //--------------------------Otherwise destroy it--------------------------
102                else
103                {
104                    this->aimAtTarget();
105                    this->follow();  //If a bot is shooting a player, it shouldn't let him go away easily.
106                }
107                if (this->bHasTargetPosition_)
108                {
109                    this->moveToTargetPosition();
110                }
111                this->doFire();
112            }
113            //--------------------------no target? do nothing until next action() -> either new target appears or bFollowLeader_ set to true--------------------------
114            else
115            {
116
117            }           
118
119        }
120        SUPER(WingmanController, tick, dt);
121    }
122//**********************************************NEW
123    /*void WingmanController::defaultBehaviour(float maxrand)
124    { 
125       
126    }*/
127
128}
Note: See TracBrowser for help on using the repository browser.