Changeset 1541 for code/branches/script_trigger/src/orxonox
- Timestamp:
- Jun 5, 2008, 10:59:49 AM (17 years ago)
- Location:
- code/branches/script_trigger/src/orxonox/objects
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/script_trigger/src/orxonox/objects/Trigger.cc
r1383 r1541 39 39 RegisterObject(Trigger); 40 40 41 targetMask_.exclude(Class(BaseObject)); 41 42 } 42 43 … … 47 48 bool Trigger::isTriggered() 48 49 { 49 return true; 50 return this->isTriggered(this->mode_); 51 } 52 53 bool Trigger::isTriggered(TriggerMode mode) 54 { 55 switch(mode) 56 { 57 case TM_EventTriggerAnd: 58 return checkAnd(); 59 break; 60 case TM_EventTriggerOr: 61 return checkOr(); 62 break; 63 case TM_DelayTrigger: 64 return checkDelay(); 65 break; 66 case TM_DistanceTrigger: 67 return checkDistance(); 68 break; 69 case TM_DistanceEventTriggerAnd: 70 if (checkDistance() && checkAnd()) 71 return true; 72 else 73 return false; 74 break; 75 case TM_DistanceEventTriggerOr: 76 if (checkDistance() && checkOr()) 77 return true; 78 else 79 return false; 80 break; 81 default: 82 return false; 83 break; 84 } 50 85 } 51 86 … … 56 91 } 57 92 93 void Trigger::addTargets(std::string targets) 94 { 95 Identifier* targetId = ID(targets); 96 targetMask_.include(targetId); 97 // trigger shouldn't react on itself or other triggers 98 targetMask_.exclude(Class(Trigger), true); 99 } 100 101 bool Trigger::checkAnd() 102 { 103 std::set<Trigger*>::iterator it; 104 for(it = this->triggers_.begin(); it != this->triggers_.end(); it++) 105 { 106 if(!((*it)->isTriggered())) 107 return false; 108 } 109 return true; 110 } 111 112 bool Trigger::checkOr() 113 { 114 std::set<Trigger*>::iterator it; 115 for(it = this->triggers_.begin(); it != this->triggers_.end(); it++) 116 { 117 if((*it)->isTriggered()) 118 return true; 119 } 120 return false; 121 } 122 123 bool Trigger::checkDelay() 124 { 125 if (triggingTime_ < actualTime_) 126 return true; 127 else 128 return false; 129 } 130 131 bool Trigger::checkDistance() 132 { 133 // Iterate through all WorldEntities 134 for(Iterator<WorldEntity> it = ObjectList<WorldEntity>::begin(); it; it++) 135 { 136 Vector3 distanceVec = it->getNode()->getWorldPosition() - this->getNode()->getWorldPosition(); 137 if (distanceVec.length() < radius_) 138 return true; 139 } 140 return false; 141 142 } 143 58 144 } -
code/branches/script_trigger/src/orxonox/objects/Trigger.h
r1383 r1541 30 30 #define _Trigger_H__ 31 31 32 #include < list>32 #include <set> 33 33 34 34 #include "OrxonoxPrereqs.h" … … 36 36 #include "WorldEntity.h" 37 37 #include "core/BaseObject.h" 38 #include "core/ClassTreeMask.h" 38 39 39 40 namespace orxonox { … … 56 57 57 58 bool isTriggered(); 59 bool isTriggered(TriggerMode mode); 58 60 void addTrigger(Trigger* trig); 61 void addTargets(std::string targets); 59 62 inline TriggerMode getMode() { return mode_; } 60 63 inline void setMode(TriggerMode mode) { this->mode_ = mode; } 64 inline void tick(float dt) { this->actualTime_ += dt; } 65 66 private: 67 bool checkAnd(); 68 bool checkOr(); 69 bool checkDelay(); 70 bool checkDistance(); 61 71 62 72 private: 63 73 std::set<Trigger*> triggers_; 64 74 TriggerMode mode_; 65 75 float triggingTime_; 76 float actualTime_; 77 float radius_; 78 ClassTreeMask targetMask_; 66 79 }; 67 80
Note: See TracChangeset
for help on using the changeset viewer.