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*/ |
---|
38 | #include "worldentities/MobileEntity.h" |
---|
39 | #include "worldentities/ControllableEntity.h" |
---|
40 | #include "core/ObjectListIterator.h" |
---|
41 | #include <worldentities/pawns/Pawn.h> |
---|
42 | #include <infos/PlayerInfo.h> |
---|
43 | |
---|
44 | //#include <OgreTextAreaOverlayElement.h> |
---|
45 | #include <OgreOverlayManager.h> |
---|
46 | //#include <overlays/OverlayText.h> |
---|
47 | |
---|
48 | namespace orxonox |
---|
49 | { |
---|
50 | CreateFactory(SpaceBoundaries); |
---|
51 | |
---|
52 | SpaceBoundaries::SpaceBoundaries(BaseObject* creator) : StaticEntity(creator) |
---|
53 | { |
---|
54 | RegisterObject(SpaceBoundaries); |
---|
55 | COUT(0) << "Test ob Konstruktor aufgerufen wird." << std::endl; //!< message for debugging |
---|
56 | // Show Boundaries on the radar. |
---|
57 | // m_pColoredTextAreaOverlayElementFactory = new ColoredTextAreaOverlayElementFactory(); |
---|
58 | } |
---|
59 | SpaceBoundaries::~SpaceBoundaries() |
---|
60 | { |
---|
61 | // delete pColoredTextAreaOverlayElementFactory; |
---|
62 | } |
---|
63 | |
---|
64 | void SpaceBoundaries::setCenter(Vector3 r) |
---|
65 | { |
---|
66 | this->center_ = r; |
---|
67 | } |
---|
68 | Vector3 SpaceBoundaries::getCenter() |
---|
69 | { |
---|
70 | return this->center_; |
---|
71 | } |
---|
72 | |
---|
73 | void SpaceBoundaries::setMaxDistance(float r) |
---|
74 | { |
---|
75 | this->maxDistance_ = r; |
---|
76 | } |
---|
77 | float SpaceBoundaries::getMaxDistance() |
---|
78 | { |
---|
79 | return this->maxDistance_; |
---|
80 | } |
---|
81 | |
---|
82 | void SpaceBoundaries::setWarnDistance(float r) |
---|
83 | { |
---|
84 | this->warnDistance_ = r; |
---|
85 | } |
---|
86 | float SpaceBoundaries::getWarnDistance() |
---|
87 | { |
---|
88 | return this->warnDistance_; |
---|
89 | } |
---|
90 | |
---|
91 | void SpaceBoundaries::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
92 | { |
---|
93 | SUPER(SpaceBoundaries, XMLPort, xmlelement, mode); |
---|
94 | |
---|
95 | XMLPortParam(SpaceBoundaries, "center", setCenter, getCenter, xmlelement, mode); |
---|
96 | XMLPortParam(SpaceBoundaries, "maxDistance", setMaxDistance, getMaxDistance, xmlelement, mode); |
---|
97 | XMLPortParam(SpaceBoundaries, "warnDistance", setWarnDistance, getWarnDistance, xmlelement, mode); |
---|
98 | } |
---|
99 | |
---|
100 | void SpaceBoundaries::tick(float dt) |
---|
101 | { |
---|
102 | for(ObjectListIterator<MobileEntity> item = ObjectList<MobileEntity>::begin(); item != ObjectList<MobileEntity>::end(); ++item) |
---|
103 | { |
---|
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) |
---|
108 | { |
---|
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 |
---|
113 | if(distance > this->warnDistance_ /*&& distance < this->maxDistance*/) |
---|
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 | } |
---|
123 | } else if(distance > maxDistance_) |
---|
124 | { |
---|
125 | // Decrease Health |
---|
126 | if(humanItem) |
---|
127 | { |
---|
128 | |
---|
129 | } else { |
---|
130 | |
---|
131 | } |
---|
132 | } |
---|
133 | } |
---|
134 | } |
---|
135 | } |
---|
136 | |
---|
137 | float SpaceBoundaries::computeDistance(WorldEntity *item) |
---|
138 | { |
---|
139 | Vector3 itemPosition = item->getPosition(); |
---|
140 | return (itemPosition.distance(this->center_)); |
---|
141 | } |
---|
142 | |
---|
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"); |
---|
150 | |
---|
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 |
---|
161 | /* OverlayManager::getSingleton().addOverlayElementFactory(pColoredTextAreaOverlayElementFactory); |
---|
162 | |
---|
163 | Ogre::TextAreaOverlayElement *pTextArea = |
---|
164 | (Ogre::TextAreaOverlayElement*)Ogre::OverlayManager.createOverlayElement("TextArea", "MyTextArea"); |
---|
165 | pTextArea->setCaption("Some plain text"); |
---|
166 | */ |
---|
167 | |
---|
168 | } |
---|
169 | |
---|
170 | bool SpaceBoundaries::isHumanPlayer(Pawn *item) |
---|
171 | { |
---|
172 | if(item != NULL) |
---|
173 | { |
---|
174 | return item->getPlayer()->isHumanPlayer(); |
---|
175 | } else { |
---|
176 | return false; |
---|
177 | } |
---|
178 | } |
---|
179 | |
---|
180 | |
---|
181 | |
---|
182 | |
---|
183 | |
---|
184 | |
---|
185 | |
---|
186 | |
---|
187 | |
---|
188 | |
---|
189 | |
---|
190 | |
---|
191 | |
---|
192 | |
---|
193 | |
---|
194 | |
---|
195 | |
---|
196 | |
---|
197 | |
---|
198 | |
---|
199 | |
---|
200 | |
---|
201 | |
---|
202 | } |
---|