Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/dockingsystem2/src/modules/docking/DockingController.cc @ 8692

Last change on this file since 8692 was 8560, checked in by dafrick, 13 years ago

Some cleanup.

File size: 3.6 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"
36
37namespace orxonox
38{
39    CreateFactory(DockingController);
40
41    DockingController::DockingController(BaseObject* creator) : ArtificialController(creator)
42    {
43        RegisterObject(DockingController);
44    }
45
46    DockingController::~DockingController()
47    {
48
49    }
50
51    void DockingController::tick(float dt)
52    {
[8544]53        ControllableEntity* entity = this->getControllableEntity();
54        if (!entity)
55            return;
[8493]56
[8544]57        float distance = (dock->getWorldPosition() - entity->getPosition()).length();
58        Vector2 coord = get2DViewdirection(     // I don't understand this too
59            entity->getPosition(),
60            entity->getOrientation() * WorldEntity::FRONT,
61            entity->getOrientation() * WorldEntity::UP,
62            dock->getWorldPosition()
63        );
64
65        // adjust direction of spaceship
66        if (distance > 10)
67        {
68            entity->rotateYaw(-1.0f * 0.8f * sgn(coord.x) * coord.x*coord.x);
69            entity->rotatePitch(0.8f * sgn(coord.y) * coord.y*coord.y);
70        }
71
72        /*// adjust speed
73        if (distance < 200 && entity->getVelocity().squaredLength() > dock->getVelocity().squaredLength())
74            entity->moveFrontBack(0.2f);
75        else
76            entity->moveFrontBack(0.8f);*/
77
78        entity->moveFrontBack(0.5f * log(distance/10.0f));
79
80        if (distance < 20)
81            this->positionReached();
82
[8493]83        SUPER(DockingController, tick, dt);
84    }
85
[8544]86    void DockingController::takeControl(bool docking)
87    {
88        this->docking = docking;
89
90        entity = player->getControllableEntity();
91        assert(entity);
92
93        if (docking)
94        {
[8560]95            COUT(4) << "DockingController::takeControl Taking over control." << std::endl;
[8544]96
97            entity->setDestroyWhenPlayerLeft(false);
98            player->pauseControl();
99            entity->setController(this);
100            this->setControllableEntity(entity);
101        }
102    }
103
[8493]104    void DockingController::positionReached()
105    {
[8560]106        COUT(4) << "DockingController::positionReached() called." << std::endl;
[8493]107
[8544]108        assert(this->player);
109        assert(this->dock);
110
111        // stop spaceship
[8560]112        entity->setPosition(dock->getWorldPosition());
[8544]113        entity->setVelocity(0, 0, 0);
[8560]114        entity->setOrientation(dock->getWorldOrientation());
[8544]115
116        // give control back to player
117        player->startControl(entity);
118        this->setActive(false);
119        this->controllableEntity_ = NULL;
120
[8493]121        if (docking)
122            dock->dockingAnimationFinished(player);
[8544]123        /*else
124            dock->undockingAnimationFinished(player);*/
125
126        this->destroy();
[8493]127    }
128}
[8501]129
Note: See TracBrowser for help on using the repository browser.