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 "core/ObjectListIterator.h" |
---|
40 | |
---|
41 | namespace orxonox |
---|
42 | { |
---|
43 | CreateFactory(SpaceBoundaries); |
---|
44 | |
---|
45 | SpaceBoundaries::SpaceBoundaries(BaseObject* creator) : StaticEntity(creator) |
---|
46 | { |
---|
47 | RegisterObject(SpaceBoundaries); |
---|
48 | |
---|
49 | // Show Boundaries on the radar. |
---|
50 | } |
---|
51 | SpaceBoundaries::~SpaceBoundaries() |
---|
52 | { |
---|
53 | |
---|
54 | } |
---|
55 | |
---|
56 | void SpaceBoundaries::setCenter(Vector3 r) |
---|
57 | { |
---|
58 | this->center = r; |
---|
59 | } |
---|
60 | Vector3 SpaceBoundaries::getCenter() |
---|
61 | { |
---|
62 | return this->center; |
---|
63 | } |
---|
64 | |
---|
65 | void SpaceBoundaries::setMaxDistance(float r) |
---|
66 | { |
---|
67 | this->maxDistance = r; |
---|
68 | } |
---|
69 | float SpaceBoundaries::getMaxDistance() |
---|
70 | { |
---|
71 | return this->maxDistance; |
---|
72 | } |
---|
73 | |
---|
74 | void SpaceBoundaries::setWarnDistance(float r) |
---|
75 | { |
---|
76 | this->warnDistance = r; |
---|
77 | } |
---|
78 | float SpaceBoundaries::getWarnDistance() |
---|
79 | { |
---|
80 | return this->warnDistance; |
---|
81 | } |
---|
82 | |
---|
83 | void SpaceBoundaries::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
84 | { |
---|
85 | SUPER(SpaceBoundaries, XMLPort, xmlelement, mode); |
---|
86 | |
---|
87 | XMLPortParam(SpaceBoundaries, "center", setCenter, getCenter, xmlelement, mode); |
---|
88 | XMLPortParam(SpaceBoundaries, "maxDistance", setMaxDistance, getMaxDistance, xmlelement, mode); |
---|
89 | XMLPortParam(SpaceBoundaries, "warnDistance", setWarnDistance, getWarnDistance, xmlelement, mode); |
---|
90 | } |
---|
91 | |
---|
92 | void SpaceBoundaries::tick(float dt) |
---|
93 | { |
---|
94 | for(ObjectListIterator<MobileEntity> item = ObjectList<MobileEntity>::begin(); item != ObjectList<MobileEntity>::end(); ++item) |
---|
95 | { |
---|
96 | float distance = computeDistance((WorldEntity *)&item); // fuer casts gibt's scheinbar andere, neuere Variante --> vgl. Coding-Guide und andere Files |
---|
97 | if(distance > this->warnDistance && distance < this->maxDistance) |
---|
98 | { |
---|
99 | COUT(0) << "You are leaving the area" << std::endl; //!< message for debugging |
---|
100 | // Display Warning on Screen if the humanPlayer (infos/PlayerInfo.h) is leaving the area |
---|
101 | } else if(distance > maxDistance) |
---|
102 | { |
---|
103 | // Decrease Health |
---|
104 | } |
---|
105 | } |
---|
106 | } |
---|
107 | |
---|
108 | float SpaceBoundaries::computeDistance(WorldEntity *item) |
---|
109 | { |
---|
110 | Vector3 itemPosition = item->getPosition(); |
---|
111 | return (itemPosition.distance(center)); |
---|
112 | } |
---|
113 | |
---|
114 | |
---|
115 | |
---|
116 | |
---|
117 | |
---|
118 | |
---|
119 | |
---|
120 | |
---|
121 | |
---|
122 | |
---|
123 | |
---|
124 | |
---|
125 | |
---|
126 | |
---|
127 | |
---|
128 | |
---|
129 | |
---|
130 | |
---|
131 | |
---|
132 | |
---|
133 | |
---|
134 | |
---|
135 | |
---|
136 | |
---|
137 | |
---|
138 | } |
---|