- Timestamp:
- May 26, 2011, 4:35:46 PM (13 years ago)
- Location:
- code/branches/presentation
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation
- Property svn:mergeinfo changed
/code/branches/portals2 (added) merged: 8460,8466,8483,8511,8599-8600
- Property svn:mergeinfo changed
-
code/branches/presentation/src/modules/portals/PortalEndPoint.cc
r8471 r8605 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 22 * Author: 23 * Andreas Büchel 24 * Co-authors: 25 * ... 26 * 27 */ 28 1 29 #include "PortalEndPoint.h" 2 30 #include "core/XMLPort.h" … … 4 32 #include "portals/PortalLink.h" 5 33 #include "worldentities/MobileEntity.h" 6 34 #include <ctime> 7 35 8 36 namespace orxonox … … 14 42 std::map<unsigned int, PortalEndPoint *> PortalEndPoint::idMap_s; 15 43 16 PortalEndPoint::PortalEndPoint(BaseObject* creator) : StaticEntity(creator), id_(0), trigger_(NULL) 44 PortalEndPoint::PortalEndPoint(BaseObject* creator) : StaticEntity(creator), id_(0), trigger_(NULL), reenterDelay_(0) 17 45 { 18 46 RegisterObject(PortalEndPoint); 47 19 48 this->trigger_ = new DistanceMultiTrigger(this); 20 49 this->trigger_->setName("portal"); … … 24 53 PortalEndPoint::~PortalEndPoint() 25 54 { 26 delete this->trigger_; 55 if(this->isInitialized() && this->trigger_ != NULL) 56 delete this->trigger_; 27 57 } 28 58 … … 33 63 XMLPortParam(PortalEndPoint, "id", setID, getID, xmlelement, mode); 34 64 XMLPortParam(PortalEndPoint, "design", setTemplate, getTemplate, xmlelement, mode); 65 XMLPortParam(PortalEndPoint, "reenterDelay", setReenterDelay, getReenterDelay, xmlelement, mode); 35 66 XMLPortParamExtern(PortalEndPoint, DistanceMultiTrigger, this->trigger_, "distance", setDistance, getDistance, xmlelement, mode); 36 67 XMLPortParamLoadOnly(PortalEndPoint, "target", setTarget, xmlelement, mode).defaultValues("Pawn"); … … 64 95 if(originatingTrigger == 0) 65 96 { 66 COUT(1) << "originator no DistanceMultiTrigger\n" << std::endl;67 97 return true; 68 98 } … … 74 104 if(bTriggered) 75 105 { 76 if(this-> recentlyJumpedOut_.find(entity) == this->recentlyJumpedOut_.end()) // only enter the portal if not just jumped out of it106 if(this->letsEnter(entity)) // only enter the portal if not just (this very moment) jumped out of it, or if the reenterDelay expired 77 107 { 78 108 PortalLink::use(entity, this); … … 87 117 } 88 118 119 bool PortalEndPoint::letsEnter(MobileEntity* entity) 120 { 121 // not allowed to enter if reenterDelay hasn't expired yet 122 std::map<MobileEntity *, time_t>::const_iterator time = this->jumpOutTimes_.find(entity); 123 if(time != this->jumpOutTimes_.end() && std::difftime(std::time(0),time->second) < this->reenterDelay_) 124 return false; 125 126 // not allowed to enter if jumped out of this portal and not left its activation radius yet 127 std::set<MobileEntity *>::const_iterator recent = this->recentlyJumpedOut_.find(entity); 128 if(recent != this->recentlyJumpedOut_.end()) 129 return false; 130 131 return true; 132 } 133 89 134 void PortalEndPoint::jumpOut(MobileEntity* entity) 90 135 { 136 this->jumpOutTimes_[entity] = std::time(0); 91 137 this->recentlyJumpedOut_.insert(entity); 92 138 139 // adjust 93 140 entity->setPosition(this->getWorldPosition()); 94 141 entity->rotate(this->getWorldOrientation()); 95 142 entity->setVelocity(this->getWorldOrientation() * entity->getVelocity()); 96 entity->setVelocity(entity->getVelocity() * 1.5);97 143 } 98 144
Note: See TracChangeset
for help on using the changeset viewer.