Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/turretFS14/src/modules/objects/controllers/TurretController.cc @ 10031

Last change on this file since 10031 was 10031, checked in by muemart, 11 years ago

Limit turret's rotation (another method…), work a bit on the controller, and make a (ugly?) hack to allow attaching dynamic objects

File size: 2.8 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 *      Martin Mueller
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "TurretController.h"
30#include "worldentities/pawns/Pawn.h"
31#include "Turret.h"
32
33 namespace orxonox
34 {
35        RegisterClass(TurretController);
36
37        TurretController::TurretController(Context* context) : ArtificialController(context)
38        {
39                RegisterObject(TurretController);
40        }
41
42        TurretController::~TurretController()
43        {
44
45        }
46
47        void TurretController::searchTarget()
48        {
49        Turret* turret = orxonox_cast<Turret*>(this->getControllableEntity());
50        if(target_ && turret->isInRange(target_->getPosition()))
51        {
52                return;
53        }
54        else
55        {
56                this->forgetTarget();
57        }
58
59
60        ControllableEntity* parent = orxonox_cast<ControllableEntity*>(turret->getParent());
61        if(parent)
62        {
63                Pawn* parenttarget = orxonox_cast<Pawn*>(parent->getTarget());
64                if(parenttarget && turret->isInRange(parenttarget->getPosition()))
65                {
66                        this->setTarget(parenttarget);
67                        turret->setTarget(parenttarget);
68                        return;
69                }
70        }
71
72                for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it != ObjectList<Pawn>::end(); ++it)
73        {
74                Pawn* entity = orxonox_cast<Pawn*>(*it);
75            if (ArtificialController::sameTeam(this->getControllableEntity(), entity, this->getGametype()))
76                continue;
77
78            if(turret->isInRange(entity->getPosition()))
79            {
80                this->setTarget(entity);
81                turret->setTarget(entity);
82                break;
83            }
84        }               
85        }
86
87        void TurretController::tick(float dt)
88        {
89        if (!this->isActive() || !this->getControllableEntity())
90            return;
91                this->searchTarget();
92                this->getControllableEntity()->rotatePitch(0.2);
93                /*if(target_)
94                {
95                        this->aimAtTarget();
96                        //It says move, but really it only turns
97                        this->moveToTargetPosition();
98                        if(this->isLookingAtTarget(Degree(5).valueRadians()))
99                        {
100                                orxout() << 42 << endl;
101                        }
102                }*/
103        }
104 }
Note: See TracBrowser for help on using the repository browser.