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