Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Some cleanup.

File size: 3.6 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 *      Sven Stucki
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "DockingController.h"
30
31#include <cmath>
32
33#include "infos/PlayerInfo.h"
34#include "worldentities/ControllableEntity.h"
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    {
53        ControllableEntity* entity = this->getControllableEntity();
54        if (!entity)
55            return;
56
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
83        SUPER(DockingController, tick, dt);
84    }
85
86    void DockingController::takeControl(bool docking)
87    {
88        this->docking = docking;
89
90        entity = player->getControllableEntity();
91        assert(entity);
92
93        if (docking)
94        {
95            COUT(4) << "DockingController::takeControl Taking over control." << std::endl;
96
97            entity->setDestroyWhenPlayerLeft(false);
98            player->pauseControl();
99            entity->setController(this);
100            this->setControllableEntity(entity);
101        }
102    }
103
104    void DockingController::positionReached()
105    {
106        COUT(4) << "DockingController::positionReached() called." << std::endl;
107
108        assert(this->player);
109        assert(this->dock);
110
111        // stop spaceship
112        entity->setPosition(dock->getWorldPosition());
113        entity->setVelocity(0, 0, 0);
114        entity->setOrientation(dock->getWorldOrientation());
115
116        // give control back to player
117        player->startControl(entity);
118        this->setActive(false);
119        this->controllableEntity_ = NULL;
120
121        if (docking)
122            dock->dockingAnimationFinished(player);
123        /*else
124            dock->undockingAnimationFinished(player);*/
125
126        this->destroy();
127    }
128}
129
Note: See TracBrowser for help on using the repository browser.