| 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 | * Benjamin Knecht |
|---|
| 24 | * Co-authors: |
|---|
| 25 | * ... |
|---|
| 26 | * |
|---|
| 27 | */ |
|---|
| 28 | |
|---|
| 29 | #include "Trigger.h" |
|---|
| 30 | |
|---|
| 31 | #include "core/Debug.h" |
|---|
| 32 | #include <OgreBillboard.h> |
|---|
| 33 | |
|---|
| 34 | #include "core/CoreIncludes.h" |
|---|
| 35 | #include "core/ConsoleCommand.h" |
|---|
| 36 | |
|---|
| 37 | namespace orxonox |
|---|
| 38 | { |
|---|
| 39 | |
|---|
| 40 | ConsoleCommand(Trigger, setVisibility, AccessLevel::Debug, false).setDefaultValues(0); |
|---|
| 41 | |
|---|
| 42 | CreateFactory(Trigger); |
|---|
| 43 | |
|---|
| 44 | Trigger::Trigger() |
|---|
| 45 | { |
|---|
| 46 | RegisterObject(Trigger); |
|---|
| 47 | |
|---|
| 48 | targetMask_.exclude(Class(BaseObject)); |
|---|
| 49 | |
|---|
| 50 | //testing |
|---|
| 51 | mode_ = TM_EventTriggerAND; |
|---|
| 52 | bActive_ = true; |
|---|
| 53 | triggingTime_ = 100; |
|---|
| 54 | |
|---|
| 55 | debugBillboard_.setBillboardSet("Examples/Flare", ColourValue(1.0, 0.0, 0.0), 1); |
|---|
| 56 | this->getNode()->attachObject(debugBillboard_.getBillboardSet()); |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | Trigger::~Trigger() |
|---|
| 60 | { |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | bool Trigger::isTriggered() |
|---|
| 64 | { |
|---|
| 65 | return this->isTriggered(this->mode_); |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | void Trigger::setVisibility(int bVisible) |
|---|
| 69 | { |
|---|
| 70 | if(bVisible) |
|---|
| 71 | this->setScale(2,2,2); |
|---|
| 72 | else |
|---|
| 73 | this->setScale(0,0,0); |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | void Trigger::tick(float dt) |
|---|
| 77 | { |
|---|
| 78 | //COUT(0) << "Scale: " << this->getScale() << std::endl; |
|---|
| 79 | if(bActive_) |
|---|
| 80 | { |
|---|
| 81 | //this->actualTime_ += dt; |
|---|
| 82 | if(this->isTriggered()) |
|---|
| 83 | { |
|---|
| 84 | this->debugBillboard_.getBillboardSet()->getBillboard(0)->setColour(ColourValue(0.0, 1.0, 0.0)); |
|---|
| 85 | } |
|---|
| 86 | } |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | bool Trigger::isTriggered(TriggerMode mode) |
|---|
| 90 | { |
|---|
| 91 | if( children_.size() != 0 ) |
|---|
| 92 | { |
|---|
| 93 | switch(mode) |
|---|
| 94 | { |
|---|
| 95 | case TM_EventTriggerAND: |
|---|
| 96 | return checkAnd(); |
|---|
| 97 | break; |
|---|
| 98 | case TM_EventTriggerOR: |
|---|
| 99 | return checkOr(); |
|---|
| 100 | break; |
|---|
| 101 | case TM_EventTriggerXOR: |
|---|
| 102 | return checkXor(); |
|---|
| 103 | break; |
|---|
| 104 | case TM_EventTriggerNOT: |
|---|
| 105 | return checkNot(); |
|---|
| 106 | break; |
|---|
| 107 | default: |
|---|
| 108 | return false; |
|---|
| 109 | break; |
|---|
| 110 | } |
|---|
| 111 | } |
|---|
| 112 | return true; |
|---|
| 113 | } |
|---|
| 114 | |
|---|
| 115 | void Trigger::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
|---|
| 116 | { |
|---|
| 117 | WorldEntity::XMLPort(xmlelement, mode); |
|---|
| 118 | } |
|---|
| 119 | |
|---|
| 120 | void Trigger::addTrigger(Trigger* trig) |
|---|
| 121 | { |
|---|
| 122 | if (this != trig) |
|---|
| 123 | this->children_.insert(trig); |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | void Trigger::addTargets(std::string targets) |
|---|
| 127 | { |
|---|
| 128 | Identifier* targetId = ID(targets); |
|---|
| 129 | targetMask_.include(targetId); |
|---|
| 130 | // trigger shouldn't react on itself or other triggers |
|---|
| 131 | targetMask_.exclude(Class(Trigger), true); |
|---|
| 132 | } |
|---|
| 133 | |
|---|
| 134 | void Trigger::removeTargets(std::string targets) |
|---|
| 135 | { |
|---|
| 136 | Identifier* targetId = ID(targets); |
|---|
| 137 | targetMask_.exclude(targetId); |
|---|
| 138 | } |
|---|
| 139 | |
|---|
| 140 | bool Trigger::checkAnd() |
|---|
| 141 | { |
|---|
| 142 | std::set<Trigger*>::iterator it; |
|---|
| 143 | for(it = this->children_.begin(); it != this->children_.end(); it++) |
|---|
| 144 | { |
|---|
| 145 | if(!((*it)->isTriggered())) |
|---|
| 146 | return false; |
|---|
| 147 | } |
|---|
| 148 | return true; |
|---|
| 149 | } |
|---|
| 150 | |
|---|
| 151 | bool Trigger::checkOr() |
|---|
| 152 | { |
|---|
| 153 | std::set<Trigger*>::iterator it; |
|---|
| 154 | for(it = this->children_.begin(); it != this->children_.end(); it++) |
|---|
| 155 | { |
|---|
| 156 | if((*it)->isTriggered()) |
|---|
| 157 | return true; |
|---|
| 158 | } |
|---|
| 159 | return false; |
|---|
| 160 | } |
|---|
| 161 | |
|---|
| 162 | bool Trigger::checkNot() |
|---|
| 163 | { |
|---|
| 164 | std::set<Trigger*>::iterator it; |
|---|
| 165 | for(it = this->children_.begin(); it != this->children_.end(); it++) |
|---|
| 166 | { |
|---|
| 167 | if((*it)->isTriggered()) |
|---|
| 168 | return false; |
|---|
| 169 | } |
|---|
| 170 | return true; |
|---|
| 171 | } |
|---|
| 172 | |
|---|
| 173 | bool Trigger::checkXor() |
|---|
| 174 | { |
|---|
| 175 | std::set<Trigger*>::iterator it; |
|---|
| 176 | bool test = false; |
|---|
| 177 | for(it = this->children_.begin(); it != this->children_.end(); it++) |
|---|
| 178 | { |
|---|
| 179 | if(test && (*it)->isTriggered()) |
|---|
| 180 | return false; |
|---|
| 181 | if((*it)->isTriggered()) |
|---|
| 182 | test = true; |
|---|
| 183 | } |
|---|
| 184 | return test; |
|---|
| 185 | } |
|---|
| 186 | |
|---|
| 187 | /*bool Trigger::checkDelay() |
|---|
| 188 | { |
|---|
| 189 | if (triggingTime_ < actualTime_) |
|---|
| 190 | return true; |
|---|
| 191 | else |
|---|
| 192 | return false; |
|---|
| 193 | } |
|---|
| 194 | |
|---|
| 195 | bool Trigger::checkDistance() |
|---|
| 196 | { |
|---|
| 197 | // Iterate through all WorldEntities |
|---|
| 198 | for(Iterator<WorldEntity> it = ObjectList<WorldEntity>::begin(); it; it++) |
|---|
| 199 | { |
|---|
| 200 | Vector3 distanceVec = it->getNode()->getWorldPosition() - this->getNode()->getWorldPosition(); |
|---|
| 201 | if (distanceVec.length() < radius_) |
|---|
| 202 | return true; |
|---|
| 203 | } |
|---|
| 204 | return false; |
|---|
| 205 | |
|---|
| 206 | }*/ |
|---|
| 207 | |
|---|
| 208 | } |
|---|