Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 14, 2011, 4:33:33 PM (13 years ago)
Author:
anbueche
Message:

portals work pretty good

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/portals/src/modules/portals/PortalEndPoint.cc

    r8200 r8243  
    11#include "PortalEndPoint.h"
    22#include "core/XMLPort.h"
     3#include "objects/triggers/MultiTriggerContainer.h"
     4#include "portals/PortalLink.h"
     5#include "worldentities/MobileEntity.h"
     6
    37
    48namespace orxonox
     
    812    std::map<unsigned int, PortalEndPoint *> PortalEndPoint::idMap_s;
    913
    10     PortalEndPoint::PortalEndPoint(BaseObject* creator) : DistanceMultiTrigger(creator), id_(0)
     14    PortalEndPoint::PortalEndPoint(BaseObject* creator) : StaticEntity(creator), id_(0), trigger_(new DistanceMultiTrigger(this))
    1115    {
    1216        RegisterObject(PortalEndPoint);
     17        this->trigger_->setName("portal");
     18        this->attach(trigger_);
    1319    }
    1420   
    1521    PortalEndPoint::~PortalEndPoint()
    1622    {
    17      
     23   
    1824    }
    1925
     
    2127    {
    2228        SUPER(PortalEndPoint, XMLPort, xmlelement, mode);
     29       
    2330        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");
    2435       
    2536        if(mode == XMLPort::LoadObject)
     
    2940    }
    3041
    31     void PortalEndPoint::tick(float dt)
     42    void PortalEndPoint::XMLEventPort(Element& xmlelement, XMLPort::Mode mode)
    3243    {
    33         SUPER(PortalEndPoint, tick, dt);
     44        SUPER(PortalEndPoint, XMLEventPort, xmlelement, mode);
     45       
     46        XMLPortEventSink(PortalEndPoint, BaseObject, "execute", execute, xmlelement, mode);
    3447    }
    3548
    36     void PortalEndPoint::jumpOut(WorldEntity* entity)
     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)
    3785    {
    3886        this->recentlyJumpedOut_.insert(entity);
    39         entity->setPosition(this->getPosition());
     87        entity->setPosition(this->getWorldPosition());
     88        entity->rotate(this->getWorldOrientation());
     89        entity->setVelocity(this->getWorldOrientation() * entity->getVelocity());
    4090    }
    4191
    42     bool PortalEndPoint::hasRecentlyJumpedOut(WorldEntity* entity)
    43     {
    44         if(this->recentlyJumpedOut_.find(entity) == this->recentlyJumpedOut_.end())
    45         {
    46             return false;
    47         }
    48         else
    49             return true;
    50     }
    5192
    5293}
Note: See TracChangeset for help on using the changeset viewer.