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 | #include "worldentities/MobileEntity.h" |
---|
32 | #include "worldentities/ControllableEntity.h" |
---|
33 | #include "core/ObjectListIterator.h" |
---|
34 | #include "core/XMLPort.h" |
---|
35 | #include "worldentities/pawns/Pawn.h" |
---|
36 | #include "infos/PlayerInfo.h" |
---|
37 | #include "interfaces/RadarViewable.h" |
---|
38 | |
---|
39 | |
---|
40 | //#include <OgreTextAreaOverlayElement.h> |
---|
41 | #include <OgreOverlayManager.h> |
---|
42 | //#include <overlays/OverlayText.h> |
---|
43 | |
---|
44 | namespace orxonox |
---|
45 | { |
---|
46 | CreateFactory(SpaceBoundaries); |
---|
47 | |
---|
48 | SpaceBoundaries::SpaceBoundaries(BaseObject* creator) : StaticEntity(creator) |
---|
49 | { |
---|
50 | /* Standardwerte, die zum Tragen kommen, |
---|
51 | * falls im XML-File keine Werte spezifiziert wurden. */ |
---|
52 | this->setMaxDistance(3000); |
---|
53 | this->setWarnDistance(2000); |
---|
54 | this->setHealthDecrease(1); |
---|
55 | |
---|
56 | RegisterObject(SpaceBoundaries); |
---|
57 | |
---|
58 | // Show Boundaries on the radar. |
---|
59 | this->centerRadar_ = new RadarViewable(this, this); |
---|
60 | this->centerRadar_->setRadarObjectShape(RadarViewable::Dot); |
---|
61 | this->centerRadar_->setRadarVisibility(false); |
---|
62 | |
---|
63 | // m_pColoredTextAreaOverlayElementFactory = new ColoredTextAreaOverlayElementFactory(); |
---|
64 | } |
---|
65 | SpaceBoundaries::~SpaceBoundaries() |
---|
66 | { |
---|
67 | delete this->centerRadar_; |
---|
68 | // delete pColoredTextAreaOverlayElementFactory; |
---|
69 | } |
---|
70 | |
---|
71 | void SpaceBoundaries::setMaxDistance(float r) |
---|
72 | { |
---|
73 | this->maxDistance_ = r; |
---|
74 | } |
---|
75 | float SpaceBoundaries::getMaxDistance() |
---|
76 | { |
---|
77 | return this->maxDistance_; |
---|
78 | } |
---|
79 | |
---|
80 | void SpaceBoundaries::setWarnDistance(float r) |
---|
81 | { |
---|
82 | this->warnDistance_ = r; |
---|
83 | } |
---|
84 | float SpaceBoundaries::getWarnDistance() |
---|
85 | { |
---|
86 | return this->warnDistance_; |
---|
87 | } |
---|
88 | |
---|
89 | void SpaceBoundaries::setHealthDecrease(float amount) |
---|
90 | { |
---|
91 | this->healthDecrease_ = amount/1000; |
---|
92 | } |
---|
93 | float SpaceBoundaries::getHealthDecrease() |
---|
94 | { |
---|
95 | return this->healthDecrease_; |
---|
96 | } |
---|
97 | |
---|
98 | void SpaceBoundaries::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
99 | { |
---|
100 | SUPER(SpaceBoundaries, XMLPort, xmlelement, mode); |
---|
101 | |
---|
102 | XMLPortParam(SpaceBoundaries, "maxDistance", setMaxDistance, getMaxDistance, xmlelement, mode); |
---|
103 | XMLPortParam(SpaceBoundaries, "warnDistance", setWarnDistance, getWarnDistance, xmlelement, mode); |
---|
104 | XMLPortParam(SpaceBoundaries, "healthDecrease", setHealthDecrease, getHealthDecrease, xmlelement, mode); |
---|
105 | } |
---|
106 | |
---|
107 | void SpaceBoundaries::tick(float dt) |
---|
108 | { |
---|
109 | for(ObjectListIterator<MobileEntity> item = ObjectList<MobileEntity>::begin(); item != ObjectList<MobileEntity>::end(); ++item) |
---|
110 | { |
---|
111 | MobileEntity* myMobileEntity = *item; |
---|
112 | Pawn* myItem = dynamic_cast<Pawn*>(myMobileEntity); |
---|
113 | if(myItem != NULL) |
---|
114 | { |
---|
115 | float distance = computeDistance((WorldEntity*) myItem); |
---|
116 | bool humanItem = this->isHumanPlayer(myItem); |
---|
117 | COUT(0) << "Distanz:" << distance << std::endl; //!< message for debugging |
---|
118 | if(distance > this->warnDistance_ && distance < this->maxDistance_) |
---|
119 | { |
---|
120 | COUT(0) << "You are leaving the area" << std::endl; //!< message for debugging |
---|
121 | if(humanItem) |
---|
122 | { |
---|
123 | COUT(0) << "humanItem ist true" << std::endl; |
---|
124 | this->displayWarning("Attention! You are leaving the area!"); |
---|
125 | } else { |
---|
126 | |
---|
127 | } |
---|
128 | } |
---|
129 | if(distance > maxDistance_) |
---|
130 | { |
---|
131 | if(humanItem) |
---|
132 | { |
---|
133 | COUT(0) << "Health should be decreasing!" << std::endl; |
---|
134 | this->displayWarning("You are out of the area now!"); |
---|
135 | myItem->removeHealth( (distance - maxDistance_) * this->healthDecrease_); |
---|
136 | } else { |
---|
137 | |
---|
138 | } |
---|
139 | } |
---|
140 | } |
---|
141 | } |
---|
142 | } |
---|
143 | |
---|
144 | float SpaceBoundaries::computeDistance(WorldEntity *item) |
---|
145 | { |
---|
146 | Vector3 itemPosition = item->getPosition(); |
---|
147 | return (itemPosition.distance(this->getPosition())); |
---|
148 | } |
---|
149 | |
---|
150 | void SpaceBoundaries::displayWarning(const std::string warnText) |
---|
151 | { /* |
---|
152 | Ogre::TextAreaOverlayElement *pTextArea; |
---|
153 | Ogre::OverlayManager manager = Ogre::OverlayManager(); |
---|
154 | Ogre::OverlayElement temp = manager.createOverlayElement("TextArea", "MyTextArea"); |
---|
155 | //pTextArea = (Ogre::TextAreaOverlayElement *) |
---|
156 | // pTextArea->setCaption("Some plain text"); |
---|
157 | |
---|
158 | Ogre::TextAreaOverlayElement warning(warnText); |
---|
159 | warning.initialise(); |
---|
160 | //warning.setPosition(0.2, 0.2); |
---|
161 | |
---|
162 | |
---|
163 | COUT(0) << "Breite des Warntextes: " << warning.getWidth() << std::endl; |
---|
164 | COUT(0) << "Hoehe des Warntextes: " << warning.getHeight() << std::endl; |
---|
165 | |
---|
166 | warning.show();*/ |
---|
167 | // Register the overlay element |
---|
168 | /* OverlayManager::getSingleton().addOverlayElementFactory(pColoredTextAreaOverlayElementFactory); |
---|
169 | |
---|
170 | Ogre::TextAreaOverlayElement *pTextArea = |
---|
171 | (Ogre::TextAreaOverlayElement*)Ogre::OverlayManager.createOverlayElement("TextArea", "MyTextArea"); |
---|
172 | pTextArea->setCaption("Some plain text"); |
---|
173 | */ |
---|
174 | |
---|
175 | } |
---|
176 | |
---|
177 | bool SpaceBoundaries::isHumanPlayer(Pawn *item) |
---|
178 | { |
---|
179 | if(item != NULL) |
---|
180 | { |
---|
181 | if(item->getPlayer()) |
---|
182 | { |
---|
183 | return item->getPlayer()->isHumanPlayer(); |
---|
184 | } |
---|
185 | } |
---|
186 | return false; |
---|
187 | } |
---|
188 | |
---|
189 | } |
---|