Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/portals/src/modules/portals/PortalEndPoint.cc @ 8278

Last change on this file since 8278 was 8278, checked in by anbueche, 13 years ago

flares as billboard

  • Property svn:executable set to *
File size: 3.1 KB
RevLine 
[8177]1#include "PortalEndPoint.h"
2#include "core/XMLPort.h"
[8243]3#include "objects/triggers/MultiTriggerContainer.h"
4#include "portals/PortalLink.h"
5#include "worldentities/MobileEntity.h"
[8177]6
[8243]7
[8177]8namespace orxonox
9{
10    CreateFactory(PortalEndPoint);
11
12    std::map<unsigned int, PortalEndPoint *> PortalEndPoint::idMap_s;
13
[8243]14    PortalEndPoint::PortalEndPoint(BaseObject* creator) : StaticEntity(creator), id_(0), trigger_(new DistanceMultiTrigger(this))
[8177]15    {
16        RegisterObject(PortalEndPoint);
[8243]17        this->trigger_->setName("portal");
18        this->attach(trigger_);
[8177]19    }
20   
21    PortalEndPoint::~PortalEndPoint()
22    {
[8243]23   
[8177]24    }
25
26    void PortalEndPoint::XMLPort(Element& xmlelement, XMLPort::Mode mode)
27    {
28        SUPER(PortalEndPoint, XMLPort, xmlelement, mode);
[8243]29       
[8177]30        XMLPortParam(PortalEndPoint, "id", setID, getID, xmlelement, mode);
[8243]31        XMLPortParam(PortalEndPoint, "design", setTemplate, getTemplate, xmlelement, mode);
32        XMLPortParamExtern(PortalEndPoint, DistanceMultiTrigger, this->trigger_, "distance", setDistance, getDistance, xmlelement, mode);
33        XMLPortParamLoadOnly(PortalEndPoint, "eventTemplate", setEventTemplate, xmlelement, mode);
34        XMLPortParamLoadOnly(PortalEndPoint, "target", setTargets, xmlelement, mode).defaultValues("Pawn");
[8177]35       
36        if(mode == XMLPort::LoadObject)
37        {
[8198]38            PortalEndPoint::idMap_s[this->id_] = this;
[8177]39        }
40    }
[8198]41
[8243]42    void PortalEndPoint::XMLEventPort(Element& xmlelement, XMLPort::Mode mode)
[8198]43    {
[8243]44        SUPER(PortalEndPoint, XMLEventPort, xmlelement, mode);
45       
46        XMLPortEventSink(PortalEndPoint, BaseObject, "execute", execute, xmlelement, mode);
[8198]47    }
48
[8243]49    bool PortalEndPoint::execute(bool bTriggered, BaseObject* trigger)
[8198]50    {
[8243]51        MultiTriggerContainer * cont = orxonox_cast<MultiTriggerContainer *>(trigger);
52        if(cont == 0)
53            return true;
54       
55        DistanceMultiTrigger * originatingTrigger = orxonox_cast<DistanceMultiTrigger *>(cont->getOriginator());
56        if(originatingTrigger == 0)
[8198]57        {
[8243]58            COUT(1) << "originator no DistanceMultiTrigger\n" << std::endl;
59            return true;
[8198]60        }
[8243]61       
62        if(this->getAttachedObjects().find(orxonox_cast<WorldEntity *>(originatingTrigger)) == this->getAttachedObjects().end())  // only necessary if events have the same name
63            return true;
64       
65        MobileEntity * entity = orxonox_cast<MobileEntity *>(cont->getData());
66        if(entity == 0)
67            return true;
68       
69        if(bTriggered)
70        {
71            if(this->recentlyJumpedOut_.find(entity) == this->recentlyJumpedOut_.end())  // only enter the portal if not recently jumped out of it
72            {
73                PortalLink::use(entity, this);
74            }
75        }
[8198]76        else
[8243]77        {
78            this->recentlyJumpedOut_.erase(entity);
79        }
80       
81        return true;
[8198]82    }
83
[8243]84    void PortalEndPoint::jumpOut(MobileEntity* entity)
85    {
86        this->recentlyJumpedOut_.insert(entity);
87        entity->setPosition(this->getWorldPosition());
88        entity->rotate(this->getWorldOrientation());
89        entity->setVelocity(this->getWorldOrientation() * entity->getVelocity());
90    }
91
[8177]92}
Note: See TracBrowser for help on using the repository browser.