[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] | 8 | namespace orxonox |
---|
| 9 | { |
---|
| 10 | CreateFactory(PortalEndPoint); |
---|
[8290] | 11 | |
---|
| 12 | /*static*/ const std::string PortalEndPoint::EVENTFUNCTIONNAME = "execute"; |
---|
[8177] | 13 | |
---|
| 14 | std::map<unsigned int, PortalEndPoint *> PortalEndPoint::idMap_s; |
---|
| 15 | |
---|
[8243] | 16 | PortalEndPoint::PortalEndPoint(BaseObject* creator) : StaticEntity(creator), id_(0), trigger_(new DistanceMultiTrigger(this)) |
---|
[8177] | 17 | { |
---|
| 18 | RegisterObject(PortalEndPoint); |
---|
[8243] | 19 | this->trigger_->setName("portal"); |
---|
| 20 | this->attach(trigger_); |
---|
[8177] | 21 | } |
---|
| 22 | |
---|
| 23 | PortalEndPoint::~PortalEndPoint() |
---|
| 24 | { |
---|
[8243] | 25 | |
---|
[8177] | 26 | } |
---|
| 27 | |
---|
| 28 | void PortalEndPoint::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
| 29 | { |
---|
| 30 | SUPER(PortalEndPoint, XMLPort, xmlelement, mode); |
---|
[8243] | 31 | |
---|
[8177] | 32 | XMLPortParam(PortalEndPoint, "id", setID, getID, xmlelement, mode); |
---|
[8243] | 33 | XMLPortParam(PortalEndPoint, "design", setTemplate, getTemplate, xmlelement, mode); |
---|
| 34 | XMLPortParamExtern(PortalEndPoint, DistanceMultiTrigger, this->trigger_, "distance", setDistance, getDistance, xmlelement, mode); |
---|
[8457] | 35 | XMLPortParamLoadOnly(PortalEndPoint, "target", setTarget, xmlelement, mode).defaultValues("Pawn"); |
---|
[8177] | 36 | |
---|
[8290] | 37 | // Add the DistanceMultiTrigger as event source. |
---|
| 38 | this->addEventSource(this->trigger_, EVENTFUNCTIONNAME); |
---|
| 39 | |
---|
[8177] | 40 | if(mode == XMLPort::LoadObject) |
---|
| 41 | { |
---|
[8198] | 42 | PortalEndPoint::idMap_s[this->id_] = this; |
---|
[8177] | 43 | } |
---|
| 44 | } |
---|
[8198] | 45 | |
---|
[8243] | 46 | void PortalEndPoint::XMLEventPort(Element& xmlelement, XMLPort::Mode mode) |
---|
[8198] | 47 | { |
---|
[8243] | 48 | SUPER(PortalEndPoint, XMLEventPort, xmlelement, mode); |
---|
| 49 | |
---|
[8290] | 50 | XMLPortEventSink(PortalEndPoint, BaseObject, EVENTFUNCTIONNAME, execute, xmlelement, mode); |
---|
[8198] | 51 | } |
---|
| 52 | |
---|
[8243] | 53 | bool PortalEndPoint::execute(bool bTriggered, BaseObject* trigger) |
---|
[8198] | 54 | { |
---|
[8454] | 55 | if(!this->isActive()) |
---|
| 56 | return true; |
---|
| 57 | |
---|
[8243] | 58 | MultiTriggerContainer * cont = orxonox_cast<MultiTriggerContainer *>(trigger); |
---|
| 59 | if(cont == 0) |
---|
| 60 | return true; |
---|
| 61 | |
---|
| 62 | DistanceMultiTrigger * originatingTrigger = orxonox_cast<DistanceMultiTrigger *>(cont->getOriginator()); |
---|
| 63 | if(originatingTrigger == 0) |
---|
[8198] | 64 | { |
---|
[8243] | 65 | COUT(1) << "originator no DistanceMultiTrigger\n" << std::endl; |
---|
| 66 | return true; |
---|
[8198] | 67 | } |
---|
[8243] | 68 | |
---|
| 69 | MobileEntity * entity = orxonox_cast<MobileEntity *>(cont->getData()); |
---|
| 70 | if(entity == 0) |
---|
| 71 | return true; |
---|
| 72 | |
---|
| 73 | if(bTriggered) |
---|
| 74 | { |
---|
[8454] | 75 | if(this->recentlyJumpedOut_.find(entity) == this->recentlyJumpedOut_.end()) // only enter the portal if not just jumped out of it |
---|
[8243] | 76 | { |
---|
| 77 | PortalLink::use(entity, this); |
---|
| 78 | } |
---|
| 79 | } |
---|
[8198] | 80 | else |
---|
[8243] | 81 | { |
---|
| 82 | this->recentlyJumpedOut_.erase(entity); |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | return true; |
---|
[8198] | 86 | } |
---|
| 87 | |
---|
[8243] | 88 | void PortalEndPoint::jumpOut(MobileEntity* entity) |
---|
| 89 | { |
---|
| 90 | this->recentlyJumpedOut_.insert(entity); |
---|
[8454] | 91 | |
---|
[8243] | 92 | entity->setPosition(this->getWorldPosition()); |
---|
| 93 | entity->rotate(this->getWorldOrientation()); |
---|
| 94 | entity->setVelocity(this->getWorldOrientation() * entity->getVelocity()); |
---|
[8454] | 95 | entity->setVelocity(entity->getVelocity() * 1.5); |
---|
[8243] | 96 | } |
---|
| 97 | |
---|
[8177] | 98 | } |
---|