Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 18, 2011, 4:35:01 PM (14 years ago)
Author:
sven
Message:

First working dock example..

Location:
code/branches/dockingsystem2/src/modules/docking
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • code/branches/dockingsystem2/src/modules/docking/CMakeLists.txt

    r8196 r8257  
    11SET_SOURCE_FILES(DOCKING_SRC_FILES
     2  DockingTarget.cc
    23  DockingEffect.cc
    34  DockToShip.cc
  • code/branches/dockingsystem2/src/modules/docking/Dock.cc

    r8197 r8257  
    7373    bool Dock::execute(bool bTriggered, BaseObject* trigger)
    7474    {
    75         //TODO: Handle DistanceMultiTrigger
    76 
    7775        PlayerTrigger* pTrigger = orxonox_cast<PlayerTrigger*>(trigger);
    7876        Pawn* pawn = NULL;
     
    104102        }
    105103
    106         // Try to get HumanPlayer
    107         if(!player->isHumanPlayer()) {
    108             COUT(0) << "Docking::execute Not triggered by a human." << std::endl;
    109             return false;
    110         }
    111         HumanPlayer* human = orxonox_cast<HumanPlayer*>(player);
    112         if(human == NULL) {
    113             COUT(0) << "Docking::execute Player was not as human as expected.." << std::endl;
    114         }
    115         COUT(0) << "Dock triggered by player: " << human->getName() << ".." << std::endl;
     104        COUT(0) << "Dock triggered by player: " << player->getName() << ".." << std::endl;
    116105
    117         //TODO: This is waaay too oversimplified
    118106        if(bTriggered) {
    119107            DockingEffect::invokeEffect(docking::DOCKING, player, effects_);
    120             //DockingEffect::invokeEffect(docking::ATTACH, player, effects_);
     108            DockingEffect::invokeEffect(docking::ATTACH, player, effects_);
    121109        } else {
    122110            DockingEffect::invokeEffect(docking::RELEASE, player, effects_);
  • code/branches/dockingsystem2/src/modules/docking/DockToShip.cc

    r8196 r8257  
    5151    }
    5252
     53
     54    void DockToShip::XMLPort(Element& xmlelement, XMLPort::Mode mode) {
     55        SUPER(DockToShip, XMLPort, xmlelement, mode);
     56
     57        XMLPortParam(DockToShip, "target", setTargetId, getTargetId, xmlelement, mode);
     58    }
     59
     60    void DockToShip::setTargetId(std::string str) {
     61        this->target = str;
     62    }
     63
     64    std::string DockToShip::getTargetId() {
     65        return this->target;
     66    }
     67
     68
    5369    bool DockToShip::docking(PlayerInfo* player)
    5470    {
     
    6076    {
    6177        COUT(0) << "DockToShip::attach" << endl;
     78
     79        DockingTarget *target = DockingEffect::findTarget(this->target);
     80        if (target == NULL) {
     81            COUT(0) << "Can't retrieve target for '" << this->target << "'.." << std::endl;
     82            return false;
     83        }
     84
     85        ControllableEntity *dockTo = (ControllableEntity*) target->getParent();
     86        if (dockTo == NULL) {
     87            COUT(0) << "Parent is not a ControllableEntity.." << std::endl;
     88            return false;
     89        }
     90
     91        player->startTemporaryControl(dockTo);
     92
    6293        return true;
    6394    }
  • code/branches/dockingsystem2/src/modules/docking/DockToShip.h

    r8196 r8257  
    3939#include "DockToShip.h"
    4040
     41#include "worldentities/ControllableEntity.h"
     42
    4143
    4244namespace orxonox
     
    5860            virtual ~DockToShip();
    5961
     62            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
     63            virtual void setTargetId(std::string str);
     64            virtual std::string getTargetId();
     65
    6066            virtual bool docking(PlayerInfo* player); //!< Called when docking starts
    6167            virtual bool attach(PlayerInfo* player); //!< Called after docking animation
    6268            virtual bool release(PlayerInfo* player); //!< Called when player wants undock
     69
     70        private:
     71            std::string target;
    6372    };
    6473
  • code/branches/dockingsystem2/src/modules/docking/DockingEffect.cc

    r8196 r8257  
    3333
    3434#include "DockingEffect.h"
    35 #include "core/CoreIncludes.h"
    3635
    3736namespace orxonox
     
    7170        return check;
    7271    }
     72
     73    DockingTarget *DockingEffect::findTarget(std::string name) {
     74        for (ObjectList<DockingTarget>::iterator it = ObjectList<DockingTarget>::begin();
     75                                 it != ObjectList<DockingTarget>::end(); ++it)
     76        {
     77            if ((*it)->getName().compare(name) == 0)
     78                return (*it);
     79        }
     80        return NULL;
     81    }
    7382}
  • code/branches/dockingsystem2/src/modules/docking/DockingEffect.h

    r8196 r8257  
    3636#define _DockingEffect_H__
    3737
     38#include "core/CoreIncludes.h"
     39#include "core/XMLPort.h"
     40
     41#include "infos/PlayerInfo.h"
     42
    3843#include "DockingPrereqs.h"
     44#include "DockingTarget.h"
    3945
    4046#include <list>
     
    6874            virtual bool docking(PlayerInfo* player) = 0; //!< Called when docking starts
    6975            virtual bool attach(PlayerInfo* player) = 0; //!< Called after docking animation
    70             virtual bool release(PlayerInfo* player) = 0; //!< Called when player wants undock
     76            virtual bool release(PlayerInfo* player) = 0; //!< Called when player wants to undock
    7177
    7278            static bool invokeEffect(docking::event event, PlayerInfo* player, std::list<DockingEffect*> & effects); //!< Invokes the event specific method of all DockingEffects in the list
     79            static DockingTarget *findTarget(std::string name); //!< Iterates through all DockingTarget objects to find the one with name=target
    7380    };
    7481
  • code/branches/dockingsystem2/src/modules/docking/DockingPrereqs.h

    r8196 r8257  
    6666{
    6767    class Dock;
     68    class DockingTarget;
    6869    class DockingEffect;
    6970    class DockToShip;
Note: See TracChangeset for help on using the changeset viewer.