Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/spaceboundaries2/src/orxonox/worldentities/SpaceBoundaries.h @ 8513

Last change on this file since 8513 was 8513, checked in by kmaurus, 13 years ago

third reactionMode added

File size: 6.9 KB
Line 
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 /* TODO:   - Bei Reaction_ == 2 ist die Reflexion noch nicht ganz so top!! Vielleicht auch so belassen, ist ja nicht unbedingt schlecht.
30 
31            - Textmessages und Billboards sollen teils nur bei einem humanPlayer angezeigt werden, nicht bei allen (vgl. Netzwerk-Spiel mit mehreren humanPlayers)
32                beachte hierzu folgende statische Funktion: 'static unsigned int  Host::getPlayerID()'
33                (file:///home/kmaurus/orxonox/spaceBoundaries/build/doc/api/html/classorxonox_1_1_host.html#9c1e3b39e3b42e467dfbf42902911ce2)
34               
35                Mich finde ich unter humanPlayer ...
36               
37            - Kommentieren (Betrachte als Beispiel/Vorbild 'libraries/core/WeakPtr.h')
38                oder brauche groups-file.
39 */
40
41#ifndef _SpaceBoundaries_H__
42#define _SpaceBoundaries_H__
43
44
45#include "core/CoreIncludes.h"
46#include "core/WeakPtr.h"
47#include "tools/interfaces/Tickable.h"
48#include "interfaces/RadarViewable.h"
49#include "worldentities/StaticEntity.h"
50#include "worldentities/WorldEntity.h"
51
52#include <string>
53#include <list>
54#include <vector>
55
56namespace orxonox
57{
58
59/**
60@brief SpaceBoundaries gives level creators the possibility to bar Pawns from leaving a defined area (until now this area is a ball).
61
62       Some attributes can/should be defined in the XML-File:
63       - 'position' : absolute position of the object of SpaceBoundaries in the level (usually 0,0,0)
64       - 'maxDistance' : defines the area, where a pawn is allowed to be (radius of a ball).
65       - 'warnDistance' : If the distance between the pawn of the human player and 'position' is bigger than 'warnDistance', a message is displayed to
66                          inform the player that he'll soon be leaving the allowed area.
67       - 'showDistance' : If the distance between the pawn and the boundary of the allowed area is smaller than 'showDistance', the boundary is shown.
68       - 'reactionMode' : Integer-Value. Defines what effect appears if a space ship has crossed the boundaries.
69                            0: Reflect the space ship (default).
70                            1: Decrease Health of the space ship after having left the allowed area.
71                            2: Inverted Version of 0. Prohibit to fly INTO a defined area.
72       - 'healthDecrease' : a measure to define how fast the health of a pawn should decrease after leaving the allowed area (unnecessary if 'reactionMode' == 0).
73                            Recommended values: 0.1 (slow health decrease) to 5 (very fast health decrease)
74
75Follow http://www.orxonox.net/wiki/SpaceBoundaries to get some further information.
76
77Examples:
78Two examples how one could include SpaceBoundaries in the XML-File. The first one uses reflection, the second one health decrease.
79@code
80<SpaceBoundaries position="0,0,0" maxDistance="1000" warnDistance="800" showDistance="100" reactionMode="0" />
81@endcode
82
83@code
84<SpaceBoundaries position="0,0,0" maxDistance="1000" warnDistance="800" showDistance="100" reactionMode="1" healthDecrease="0.2" />
85@endcode
86*/
87
88    class _OrxonoxExport SpaceBoundaries : public StaticEntity, public Tickable
89    {
90        public:
91            SpaceBoundaries(BaseObject* creator);
92            ~SpaceBoundaries();
93           
94            void setMaxDistance(float r);
95            float getMaxDistance();
96           
97            void setWarnDistance(float r);
98            float getWarnDistance();
99           
100            void setShowDistance(float r);
101            float getShowDistance();
102           
103            void setHealthDecrease(float amount);
104            float getHealthDecrease();
105           
106            void setReaction(int mode);
107            int getReaction();
108
109            void XMLPort(Element& xmlelement, XMLPort::Mode mode);
110           
111            void tick(float dt);
112
113        private:
114            struct billboardAdministration{ bool usedYet; Billboard* billy; };
115           
116            // Variabeln::
117            std::list<WeakPtr<Pawn> > pawnsIn_; //!< List of the pawns that this instance of SpaceBoundaries has to handle.
118           
119            std::vector<billboardAdministration> billboards_;
120       
121            int reaction_; //!< Werte: 0, 1, 2.
122                           //!< 0: Reflektion an Boundaries (Standard).
123                           //!< 1: Health-Abzug-Modus.
124                           //!< 2: Invertierte Version von 0. Verbiete es, in ein Gebiet hinein zu fliegen.
125            float maxDistance_; //!< maximal zulaessige Entfernung von 'this->getPosition()'.
126            float warnDistance_; //!< Entfernung von 'this->getPosition()', ab der eine Warnung angezeigt wird, dass man bald das zulaessige Areal verlaesst.
127            float showDistance_; //!< Definiert, wann die Grenzen visualisiert werden sollen.
128           
129            float healthDecrease_; //!< Mass fuer die Anzahl Health-Points, die nach ueberschreiten der Entfernung 'maxDistance_' von 'this->getPosition()' abgezogen werden.
130                                   //!< Empfohlene Werte: 0.1 (langsame Health-Verminderung) bis 5 (sehr schnelle Health-Verminderung)
131           
132           
133            RadarViewable* centerRadar_; //!< Repraesentation von SpaceBoundaries auf dem Radar.
134       
135       
136            // Funktionen::
137            float computeDistance(WorldEntity *item); //!< Auf den Mittelpunkt 'this->getPosition()' bezogen.
138            void displayWarning(const std::string warnText);
139            void displayBoundaries(Pawn *item);
140            void conditionalBounceBack(Pawn *item, float currentDistance, float dt);
141            void bounceBack(Pawn *item, Vector3 *normal, Vector3 *velocity);
142            bool isHumanPlayer(Pawn *item);
143           
144            void checkWhoIsIn(); //!< Update the list 'pawnsIn_'.
145           
146            void positionBillboard(const Vector3 position); //!< Display a Billboard at the position 'position'.
147            void setBillboardOptions(Billboard *billy);
148            void removeAllBillboards(); //!< Hide all elements of '*billboard_' and set their attribute 'usedYet' to 0.
149           
150    };
151}
152
153#endif /* _SpaceBoundaries_H__ */
Note: See TracBrowser for help on using the repository browser.