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
Line 
1#include "PortalEndPoint.h"
2#include "core/XMLPort.h"
3#include "objects/triggers/MultiTriggerContainer.h"
4#include "portals/PortalLink.h"
5#include "worldentities/MobileEntity.h"
6
7
8namespace orxonox
9{
10    CreateFactory(PortalEndPoint);
11
12    std::map<unsigned int, PortalEndPoint *> PortalEndPoint::idMap_s;
13
14    PortalEndPoint::PortalEndPoint(BaseObject* creator) : StaticEntity(creator), id_(0), trigger_(new DistanceMultiTrigger(this))
15    {
16        RegisterObject(PortalEndPoint);
17        this->trigger_->setName("portal");
18        this->attach(trigger_);
19    }
20   
21    PortalEndPoint::~PortalEndPoint()
22    {
23   
24    }
25
26    void PortalEndPoint::XMLPort(Element& xmlelement, XMLPort::Mode mode)
27    {
28        SUPER(PortalEndPoint, XMLPort, xmlelement, mode);
29       
30        XMLPortParam(PortalEndPoint, "id", setID, getID, xmlelement, mode);
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");
35       
36        if(mode == XMLPort::LoadObject)
37        {
38            PortalEndPoint::idMap_s[this->id_] = this;
39        }
40    }
41
42    void PortalEndPoint::XMLEventPort(Element& xmlelement, XMLPort::Mode mode)
43    {
44        SUPER(PortalEndPoint, XMLEventPort, xmlelement, mode);
45       
46        XMLPortEventSink(PortalEndPoint, BaseObject, "execute", execute, xmlelement, mode);
47    }
48
49    bool PortalEndPoint::execute(bool bTriggered, BaseObject* trigger)
50    {
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)
57        {
58            COUT(1) << "originator no DistanceMultiTrigger\n" << std::endl;
59            return true;
60        }
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        }
76        else
77        {
78            this->recentlyJumpedOut_.erase(entity);
79        }
80       
81        return true;
82    }
83
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
92}
Note: See TracBrowser for help on using the repository browser.