Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 23, 2011, 4:12:27 PM (14 years ago)
Author:
sven
Message:

Spaceships attach now to the dock, fixed DockingController.

Location:
code/branches/dockingsystem2/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • code/branches/dockingsystem2/src/modules/docking/DockingController.cc

    r8501 r8544  
    2929#include "DockingController.h"
    3030
     31#include <cmath>
     32
    3133#include "infos/PlayerInfo.h"
    3234#include "worldentities/ControllableEntity.h"
     
    4951    void DockingController::tick(float dt)
    5052    {
    51         this->moveToTargetPosition();
     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();
    5282
    5383        SUPER(DockingController, tick, dt);
    5484    }
    5585
     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(0) << "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
    56104    void DockingController::positionReached()
    57105    {
    58         // TODO; Give control back to player
    59         PlayerInfo* player = this->entity->getPlayer();
    60         assert(player);
     106        COUT(0) << "DockingController::positionReached() called." << std::endl;
     107
     108        assert(this->player);
     109        assert(this->dock);
     110
     111        // stop spaceship
     112        dock->attach(entity);
     113        entity->setVelocity(0, 0, 0);
     114        entity->setOrientation(dock->getOrientation());
     115
     116        // give control back to player
     117        player->startControl(entity);
     118        this->setActive(false);
     119        this->controllableEntity_ = NULL;
    61120
    62121        if (docking)
    63122            dock->dockingAnimationFinished(player);
    64         else
    65             dock->undockingAnimationFinished(player);
     123        /*else
     124            dock->undockingAnimationFinished(player);*/
     125
     126        this->destroy();
    66127    }
    67128}
  • code/branches/dockingsystem2/src/modules/docking/DockingController.h

    r8493 r8544  
    5050
    5151            void setDock(Dock* dock) { this->dock = dock; }
    52             void setEntity(ControllableEntity* entity) { this->entity = entity; }
     52            void setPlayer(PlayerInfo* player) { this->player = player; }
    5353
    5454        protected:
     
    5656
    5757        private:
     58            bool docking;
     59
    5860            Dock* dock;
    59             bool docking;
     61            PlayerInfo* player;
     62
    6063            ControllableEntity* entity;
    6164    };
  • code/branches/dockingsystem2/src/modules/docking/MoveToDockingTarget.cc

    r8501 r8544  
    5353    {
    5454        assert(parent);
    55         parent->dockingAnimationFinished(player);
     55
     56        DockingController *dockingController = new DockingController(this);
     57        dockingController->setDock(parent);
     58        dockingController->setPlayer(player);
     59        dockingController->takeControl(true);
     60
    5661        return true;
    5762    }
     
    5964    bool MoveToDockingTarget::release(PlayerInfo *player)
    6065    {
    61         assert(parent);
     66        //TODO: Investigate strange things...
     67        parent->detach((WorldEntity*)player->getControllableEntity());
     68
    6269        parent->undockingAnimationFinished(player);
    6370        return true;
  • code/branches/dockingsystem2/src/modules/docking/MoveToDockingTarget.h

    r8493 r8544  
    3838#include "DockingPrereqs.h"
    3939#include "DockingAnimation.h"
     40#include "DockingController.h"
    4041#include "Dock.h"
    4142
  • code/branches/dockingsystem2/src/orxonox/infos/PlayerInfo.cc

    r8382 r8544  
    213213    }
    214214
     215    void PlayerInfo::pauseControl()
     216    {
     217        ControllableEntity* entity = this->controllableEntity_;
     218
     219        if (!entity)
     220            return;
     221
     222        this->controllableEntity_->getController()->setActive(false);
     223        //this->controllableEntity_->getController()->setControllableEntity(NULL);
     224        this->controllableEntity_->setController(0);
     225    }
     226
    215227    void PlayerInfo::stopTemporaryControl()
    216228    {
  • code/branches/dockingsystem2/src/orxonox/infos/PlayerInfo.h

    r8289 r8544  
    6868            void startControl(ControllableEntity* entity);
    6969            void stopControl();
     70            void pauseControl();
    7071            void startTemporaryControl(ControllableEntity* entity);
    7172            void stopTemporaryControl();
Note: See TracChangeset for help on using the changeset viewer.