[1383] | 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 | |
---|
[1550] | 31 | #include "core/Debug.h" |
---|
[1671] | 32 | #include <OgreBillboard.h> |
---|
[1550] | 33 | |
---|
[1383] | 34 | #include "core/CoreIncludes.h" |
---|
[1671] | 35 | #include "core/ConsoleCommand.h" |
---|
[1383] | 36 | |
---|
| 37 | namespace orxonox |
---|
| 38 | { |
---|
[1671] | 39 | |
---|
| 40 | ConsoleCommand(Trigger, setVisibility, AccessLevel::Debug, false).setDefaultValues(0); |
---|
| 41 | |
---|
[1383] | 42 | CreateFactory(Trigger); |
---|
| 43 | |
---|
| 44 | Trigger::Trigger() |
---|
| 45 | { |
---|
| 46 | RegisterObject(Trigger); |
---|
| 47 | |
---|
[1541] | 48 | targetMask_.exclude(Class(BaseObject)); |
---|
[1550] | 49 | |
---|
[1671] | 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()); |
---|
[1383] | 57 | } |
---|
| 58 | |
---|
| 59 | Trigger::~Trigger() |
---|
| 60 | { |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | bool Trigger::isTriggered() |
---|
| 64 | { |
---|
[1541] | 65 | return this->isTriggered(this->mode_); |
---|
[1383] | 66 | } |
---|
| 67 | |
---|
[1671] | 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 | |
---|
[1541] | 89 | bool Trigger::isTriggered(TriggerMode mode) |
---|
| 90 | { |
---|
[1671] | 91 | if( children_.size() != 0 ) |
---|
[1541] | 92 | { |
---|
[1671] | 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: |
---|
[1541] | 108 | return false; |
---|
[1671] | 109 | break; |
---|
| 110 | } |
---|
[1541] | 111 | } |
---|
[1671] | 112 | return true; |
---|
[1541] | 113 | } |
---|
| 114 | |
---|
[1550] | 115 | void Trigger::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
| 116 | { |
---|
| 117 | WorldEntity::XMLPort(xmlelement, mode); |
---|
| 118 | } |
---|
| 119 | |
---|
[1383] | 120 | void Trigger::addTrigger(Trigger* trig) |
---|
| 121 | { |
---|
| 122 | if (this != trig) |
---|
[1671] | 123 | this->children_.insert(trig); |
---|
[1383] | 124 | } |
---|
| 125 | |
---|
[1541] | 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 | |
---|
[1550] | 134 | void Trigger::removeTargets(std::string targets) |
---|
| 135 | { |
---|
| 136 | Identifier* targetId = ID(targets); |
---|
| 137 | targetMask_.exclude(targetId); |
---|
| 138 | } |
---|
| 139 | |
---|
[1541] | 140 | bool Trigger::checkAnd() |
---|
| 141 | { |
---|
| 142 | std::set<Trigger*>::iterator it; |
---|
[1671] | 143 | for(it = this->children_.begin(); it != this->children_.end(); it++) |
---|
[1541] | 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; |
---|
[1671] | 154 | for(it = this->children_.begin(); it != this->children_.end(); it++) |
---|
[1541] | 155 | { |
---|
| 156 | if((*it)->isTriggered()) |
---|
| 157 | return true; |
---|
| 158 | } |
---|
| 159 | return false; |
---|
| 160 | } |
---|
| 161 | |
---|
[1671] | 162 | bool Trigger::checkNot() |
---|
[1541] | 163 | { |
---|
[1671] | 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 | { |
---|
[1541] | 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 | |
---|
[1671] | 206 | }*/ |
---|
[1541] | 207 | |
---|
[1383] | 208 | } |
---|