[8087] | 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 | * Maurus Kaufmann |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | #include "SpaceBoundaries.h" |
---|
| 30 | |
---|
| 31 | /* Folgender Block ist Copy-Paste und somit teilweise wohl unnoetig */ |
---|
| 32 | #include "core/Template.h" |
---|
| 33 | #include "core/XMLPort.h" |
---|
| 34 | #include "gametypes/Gametype.h" |
---|
| 35 | #include "worldentities/pawns/Pawn.h" |
---|
| 36 | |
---|
| 37 | /* Eigene, spezifische include-Statements*/ |
---|
[8110] | 38 | #include "worldentities/MobileEntity.h" |
---|
[8164] | 39 | #include "worldentities/ControllableEntity.h" |
---|
[8110] | 40 | #include "core/ObjectListIterator.h" |
---|
[8164] | 41 | #include <worldentities/pawns/Pawn.h> |
---|
| 42 | #include <infos/PlayerInfo.h> |
---|
[8087] | 43 | |
---|
[8166] | 44 | //#include <OgreTextAreaOverlayElement.h> |
---|
[8164] | 45 | #include <OgreOverlayManager.h> |
---|
[8166] | 46 | //#include <overlays/OverlayText.h> |
---|
[8164] | 47 | |
---|
[8087] | 48 | namespace orxonox |
---|
| 49 | { |
---|
| 50 | CreateFactory(SpaceBoundaries); |
---|
| 51 | |
---|
| 52 | SpaceBoundaries::SpaceBoundaries(BaseObject* creator) : StaticEntity(creator) |
---|
| 53 | { |
---|
| 54 | RegisterObject(SpaceBoundaries); |
---|
[8164] | 55 | COUT(0) << "Test ob Konstruktor aufgerufen wird." << std::endl; //!< message for debugging |
---|
[8110] | 56 | // Show Boundaries on the radar. |
---|
[8166] | 57 | // m_pColoredTextAreaOverlayElementFactory = new ColoredTextAreaOverlayElementFactory(); |
---|
[8087] | 58 | } |
---|
| 59 | SpaceBoundaries::~SpaceBoundaries() |
---|
| 60 | { |
---|
[8166] | 61 | // delete pColoredTextAreaOverlayElementFactory; |
---|
[8087] | 62 | } |
---|
[8110] | 63 | |
---|
| 64 | void SpaceBoundaries::setCenter(Vector3 r) |
---|
| 65 | { |
---|
[8166] | 66 | this->center_ = r; |
---|
[8110] | 67 | } |
---|
| 68 | Vector3 SpaceBoundaries::getCenter() |
---|
| 69 | { |
---|
[8166] | 70 | return this->center_; |
---|
[8110] | 71 | } |
---|
| 72 | |
---|
| 73 | void SpaceBoundaries::setMaxDistance(float r) |
---|
| 74 | { |
---|
[8166] | 75 | this->maxDistance_ = r; |
---|
[8110] | 76 | } |
---|
| 77 | float SpaceBoundaries::getMaxDistance() |
---|
| 78 | { |
---|
[8166] | 79 | return this->maxDistance_; |
---|
[8110] | 80 | } |
---|
| 81 | |
---|
| 82 | void SpaceBoundaries::setWarnDistance(float r) |
---|
| 83 | { |
---|
[8166] | 84 | this->warnDistance_ = r; |
---|
[8110] | 85 | } |
---|
| 86 | float SpaceBoundaries::getWarnDistance() |
---|
| 87 | { |
---|
[8166] | 88 | return this->warnDistance_; |
---|
[8110] | 89 | } |
---|
[8087] | 90 | |
---|
| 91 | void SpaceBoundaries::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
| 92 | { |
---|
[8110] | 93 | SUPER(SpaceBoundaries, XMLPort, xmlelement, mode); |
---|
[8087] | 94 | |
---|
[8110] | 95 | XMLPortParam(SpaceBoundaries, "center", setCenter, getCenter, xmlelement, mode); |
---|
| 96 | XMLPortParam(SpaceBoundaries, "maxDistance", setMaxDistance, getMaxDistance, xmlelement, mode); |
---|
| 97 | XMLPortParam(SpaceBoundaries, "warnDistance", setWarnDistance, getWarnDistance, xmlelement, mode); |
---|
[8087] | 98 | } |
---|
[8110] | 99 | |
---|
| 100 | void SpaceBoundaries::tick(float dt) |
---|
| 101 | { |
---|
| 102 | for(ObjectListIterator<MobileEntity> item = ObjectList<MobileEntity>::begin(); item != ObjectList<MobileEntity>::end(); ++item) |
---|
| 103 | { |
---|
[8164] | 104 | MobileEntity* myMobileEntity = *item; |
---|
| 105 | Pawn* myItem = dynamic_cast<Pawn*>(myMobileEntity); |
---|
| 106 | //COUT(0) << "Die for-Schleife wird erreicht!!!" << std::endl; //!< message for debugging |
---|
| 107 | if(myItem != NULL) |
---|
[8110] | 108 | { |
---|
[8164] | 109 | float distance = computeDistance((WorldEntity*) myItem); |
---|
| 110 | bool humanItem = this->isHumanPlayer(myItem); |
---|
| 111 | COUT(0) << "Pawn wird erkannt!!!" << std::endl; //!< message for debugging |
---|
| 112 | COUT(0) << "Distanz:" << distance << std::endl; //!< message for debugging |
---|
[8166] | 113 | if(distance > this->warnDistance_ /*&& distance < this->maxDistance*/) |
---|
[8164] | 114 | { |
---|
| 115 | COUT(0) << "You are leaving the area" << std::endl; //!< message for debugging |
---|
| 116 | if(humanItem) |
---|
| 117 | { |
---|
| 118 | COUT(0) << "humanItem ist true" << std::endl; |
---|
| 119 | this->displayWarning("Attention! You are leaving the area!"); |
---|
| 120 | } else { |
---|
| 121 | |
---|
| 122 | } |
---|
[8166] | 123 | } else if(distance > maxDistance_) |
---|
[8164] | 124 | { |
---|
| 125 | // Decrease Health |
---|
| 126 | if(humanItem) |
---|
| 127 | { |
---|
| 128 | |
---|
| 129 | } else { |
---|
| 130 | |
---|
| 131 | } |
---|
| 132 | } |
---|
[8110] | 133 | } |
---|
| 134 | } |
---|
| 135 | } |
---|
| 136 | |
---|
| 137 | float SpaceBoundaries::computeDistance(WorldEntity *item) |
---|
| 138 | { |
---|
| 139 | Vector3 itemPosition = item->getPosition(); |
---|
[8166] | 140 | return (itemPosition.distance(this->center_)); |
---|
[8110] | 141 | } |
---|
| 142 | |
---|
[8164] | 143 | void SpaceBoundaries::displayWarning(const std::string warnText) |
---|
| 144 | { /* |
---|
| 145 | Ogre::TextAreaOverlayElement *pTextArea; |
---|
| 146 | Ogre::OverlayManager manager = Ogre::OverlayManager(); |
---|
| 147 | Ogre::OverlayElement temp = manager.createOverlayElement("TextArea", "MyTextArea"); |
---|
| 148 | //pTextArea = (Ogre::TextAreaOverlayElement *) |
---|
| 149 | // pTextArea->setCaption("Some plain text"); |
---|
[8110] | 150 | |
---|
[8164] | 151 | Ogre::TextAreaOverlayElement warning(warnText); |
---|
| 152 | warning.initialise(); |
---|
| 153 | //warning.setPosition(0.2, 0.2); |
---|
| 154 | |
---|
| 155 | |
---|
| 156 | COUT(0) << "Breite des Warntextes: " << warning.getWidth() << std::endl; |
---|
| 157 | COUT(0) << "Hoehe des Warntextes: " << warning.getHeight() << std::endl; |
---|
| 158 | |
---|
| 159 | warning.show();*/ |
---|
| 160 | // Register the overlay element |
---|
[8166] | 161 | /* OverlayManager::getSingleton().addOverlayElementFactory(pColoredTextAreaOverlayElementFactory); |
---|
[8164] | 162 | |
---|
| 163 | Ogre::TextAreaOverlayElement *pTextArea = |
---|
| 164 | (Ogre::TextAreaOverlayElement*)Ogre::OverlayManager.createOverlayElement("TextArea", "MyTextArea"); |
---|
| 165 | pTextArea->setCaption("Some plain text"); |
---|
[8166] | 166 | */ |
---|
[8164] | 167 | |
---|
| 168 | } |
---|
[8110] | 169 | |
---|
[8164] | 170 | bool SpaceBoundaries::isHumanPlayer(Pawn *item) |
---|
| 171 | { |
---|
| 172 | if(item != NULL) |
---|
| 173 | { |
---|
| 174 | return item->getPlayer()->isHumanPlayer(); |
---|
| 175 | } else { |
---|
| 176 | return false; |
---|
| 177 | } |
---|
| 178 | } |
---|
[8110] | 179 | |
---|
| 180 | |
---|
| 181 | |
---|
| 182 | |
---|
| 183 | |
---|
| 184 | |
---|
| 185 | |
---|
| 186 | |
---|
| 187 | |
---|
| 188 | |
---|
| 189 | |
---|
| 190 | |
---|
| 191 | |
---|
| 192 | |
---|
| 193 | |
---|
| 194 | |
---|
| 195 | |
---|
| 196 | |
---|
| 197 | |
---|
| 198 | |
---|
| 199 | |
---|
| 200 | |
---|
[8164] | 201 | |
---|
[8087] | 202 | } |
---|