Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/docking/DockingController.cc @ 12274

Last change on this file since 12274 was 11071, checked in by landauf, 9 years ago

merged branch cpp11_v3 back to trunk

  • Property svn:eol-style set to native
File size: 3.9 KB
RevLine 
[8493]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 *      Sven Stucki
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "DockingController.h"
30
[8544]31#include <cmath>
32
[8501]33#include "infos/PlayerInfo.h"
34#include "worldentities/ControllableEntity.h"
[8493]35#include "Dock.h"
[9667]36#include "core/CoreIncludes.h"
[8493]37
38namespace orxonox
39{
[9667]40    RegisterClass(DockingController);
[8493]41
[9667]42    DockingController::DockingController(Context* context) : ArtificialController(context)
[8493]43    {
44        RegisterObject(DockingController);
[8568]45
[11071]46        this->dock_ = nullptr;
47        this->player_ = nullptr;
48        this->entity_ = nullptr;
[8493]49    }
50
51    DockingController::~DockingController()
52    {
53
54    }
55
56    void DockingController::tick(float dt)
57    {
[8544]58        ControllableEntity* entity = this->getControllableEntity();
59        if (!entity)
60            return;
[8493]61
[8568]62        float distance = (this->dock_->getWorldPosition() - entity->getPosition()).length();
[11052]63        Vector2 coord = get2DViewCoordinates(     // I don't understand this too
[8544]64            entity->getPosition(),
65            entity->getOrientation() * WorldEntity::FRONT,
66            entity->getOrientation() * WorldEntity::UP,
[8568]67            dock_->getWorldPosition()
[8544]68        );
69
70        // adjust direction of spaceship
71        if (distance > 10)
72        {
[9348]73            entity->rotateYaw(-1.0f * 0.8f * clamp(coord.x * 10, -1.0f, 1.0f));
74            entity->rotatePitch(0.8f * clamp(coord.y * 10, -1.0f, 1.0f));
[8544]75        }
76
77        /*// adjust speed
78        if (distance < 200 && entity->getVelocity().squaredLength() > dock->getVelocity().squaredLength())
79            entity->moveFrontBack(0.2f);
80        else
81            entity->moveFrontBack(0.8f);*/
82
83        entity->moveFrontBack(0.5f * log(distance/10.0f));
84
85        if (distance < 20)
86            this->positionReached();
87
[8493]88        SUPER(DockingController, tick, dt);
89    }
90
[8544]91    void DockingController::takeControl(bool docking)
92    {
[8568]93        this->docking_ = docking;
[8544]94
[8568]95        this->entity_ = this->player_->getControllableEntity();
96        assert(this->entity_);
[8544]97
98        if (docking)
99        {
[8858]100            orxout(verbose, context::docking) << "DockingController::takeControl Taking over control." << endl;
[8544]101
[8568]102            this->entity_->setDestroyWhenPlayerLeft(false);
103            this->player_->pauseControl();
104            this->entity_->setController(this);
105            this->setControllableEntity(this->entity_);
[8544]106        }
107    }
108
[8493]109    void DockingController::positionReached()
110    {
[8858]111        orxout(verbose, context::docking) << "DockingController::positionReached() called." << endl;
[8493]112
[8568]113        assert(this->player_);
114        assert(this->dock_);
[8544]115
116        // stop spaceship
[8568]117        this->entity_->setPosition(this->dock_->getWorldPosition());
118        this->entity_->setVelocity(0, 0, 0);
119        this->entity_->setOrientation(this->dock_->getWorldOrientation());
[8544]120
121        // give control back to player
[8568]122        this->player_->startControl(this->entity_);
[8544]123        this->setActive(false);
[11071]124        this->controllableEntity_ = nullptr;
[8544]125
[8568]126        if (this->docking_)
127            this->dock_->dockingAnimationFinished(this->player_);
[8544]128        /*else
129            dock->undockingAnimationFinished(player);*/
130
131        this->destroy();
[8493]132    }
133}
[8501]134
Note: See TracBrowser for help on using the repository browser.