| 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 | #ifndef _SpaceBoundaries_H__ | 
|---|
| 30 | #define _SpaceBoundaries_H__ | 
|---|
| 31 |  | 
|---|
| 32 | #include "objects/ObjectsPrereqs.h" | 
|---|
| 33 |  | 
|---|
| 34 | #include <string> | 
|---|
| 35 | #include <list> | 
|---|
| 36 | #include <vector> | 
|---|
| 37 |  | 
|---|
| 38 | #include "core/object/WeakPtr.h" | 
|---|
| 39 |  | 
|---|
| 40 | #include "tools/interfaces/Tickable.h" | 
|---|
| 41 | #include "worldentities/StaticEntity.h" | 
|---|
| 42 |  | 
|---|
| 43 | namespace orxonox | 
|---|
| 44 | { | 
|---|
| 45 |  | 
|---|
| 46 | /** | 
|---|
| 47 | @brief SpaceBoundaries gives level creators the possibility to bar Pawns from leaving a defined area (until now this area is a ball). | 
|---|
| 48 |  | 
|---|
| 49 | Some attributes can/should be defined in the XML-File: | 
|---|
| 50 | - 'position' : absolute position of the object of SpaceBoundaries in the level (usually 0,0,0) | 
|---|
| 51 | - 'maxDistance' : defines the area, where a pawn is allowed to be (radius of a ball). | 
|---|
| 52 | - 'warnDistance' : If the distance between the pawn of the human player and 'position' is bigger than 'warnDistance', a message is displayed to | 
|---|
| 53 | inform the player that he'll soon be leaving the allowed area. (not implemented yet!) | 
|---|
| 54 | - 'showDistance' : If the distance between the pawn and the boundary of the allowed area is smaller than 'showDistance', the boundary is shown. | 
|---|
| 55 | - 'reactionMode' : Integer-Value. Defines what effect appears if a space ship has crossed the boundaries. | 
|---|
| 56 | 0: Reflect the space ship (default). | 
|---|
| 57 | 1: Decrease Health of the space ship after having left the allowed area. | 
|---|
| 58 | 2: Inverted Version of 0. Prohibit to fly INTO a defined area. | 
|---|
| 59 | - 'healthDecrease' : a measure to define how fast the health of a pawn should decrease after leaving the allowed area (unnecessary if 'reactionMode' == 0). | 
|---|
| 60 | Recommended values: 0.1 (slow health decrease) to 5 (very fast health decrease) | 
|---|
| 61 |  | 
|---|
| 62 | Follow http://www.orxonox.net/wiki/SpaceBoundaries to get some further information. | 
|---|
| 63 |  | 
|---|
| 64 | Examples: | 
|---|
| 65 | Two examples how one could include SpaceBoundaries in the XML-File. The first one uses reflection, the second one health decrease. | 
|---|
| 66 | @code | 
|---|
| 67 | <SpaceBoundaries position="0,0,0" maxDistance="1000" warnDistance="800" showDistance="100" reactionMode="0" /> | 
|---|
| 68 | @endcode | 
|---|
| 69 |  | 
|---|
| 70 | @code | 
|---|
| 71 | <SpaceBoundaries position="0,0,0" maxDistance="1000" warnDistance="800" showDistance="100" reactionMode="1" healthDecrease="0.2" /> | 
|---|
| 72 | @endcode | 
|---|
| 73 | */ | 
|---|
| 74 | class _ObjectsExport SpaceBoundaries : public StaticEntity, public Tickable | 
|---|
| 75 | { | 
|---|
| 76 | public: | 
|---|
| 77 | SpaceBoundaries(Context* context); | 
|---|
| 78 | ~SpaceBoundaries(); | 
|---|
| 79 |  | 
|---|
| 80 | void setMaxDistance(float r); | 
|---|
| 81 | float getMaxDistance(); | 
|---|
| 82 |  | 
|---|
| 83 | void setWarnDistance(float r); | 
|---|
| 84 | float getWarnDistance(); | 
|---|
| 85 |  | 
|---|
| 86 | void setShowDistance(float r); | 
|---|
| 87 | float getShowDistance(); | 
|---|
| 88 |  | 
|---|
| 89 | void setHealthDecrease(float amount); | 
|---|
| 90 | float getHealthDecrease(); | 
|---|
| 91 |  | 
|---|
| 92 | void setReaction(int mode); | 
|---|
| 93 | int getReaction(); | 
|---|
| 94 |  | 
|---|
| 95 | virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override; | 
|---|
| 96 |  | 
|---|
| 97 | virtual void tick(float dt) override; | 
|---|
| 98 |  | 
|---|
| 99 | private: | 
|---|
| 100 | struct BillboardAdministration{ bool usedYet; Billboard* billy; }; | 
|---|
| 101 |  | 
|---|
| 102 | // Variabeln:: | 
|---|
| 103 | std::list<WeakPtr<Pawn>> pawnsIn_; //!< List of the pawns that this instance of SpaceBoundaries has to handle. | 
|---|
| 104 |  | 
|---|
| 105 | std::vector<BillboardAdministration> billboards_; | 
|---|
| 106 |  | 
|---|
| 107 | int reaction_; //!< Values: 0, 1, 2. | 
|---|
| 108 | //!< 0: Reflection on boundary (Standard). | 
|---|
| 109 | //!< 1: Decrease-Health-Mode. | 
|---|
| 110 | //!< 2: Inverted Version of 0. Prohibit to fly INTO a defined area. | 
|---|
| 111 | float maxDistance_; //!<  Maximum allowed distance. | 
|---|
| 112 | float warnDistance_; //!< Distance in which a warning is displayed. | 
|---|
| 113 | float showDistance_; //!< Distance at which the boundaries are displayed. | 
|---|
| 114 |  | 
|---|
| 115 | float healthDecrease_; //!< Rate of health loss. | 
|---|
| 116 |  | 
|---|
| 117 | //RadarViewable* centerRadar_; //!< Representation of the space boundary in the radar. | 
|---|
| 118 |  | 
|---|
| 119 | // Funktionen:: | 
|---|
| 120 | float computeDistance(WorldEntity *item); //!< Compute distance to center point. | 
|---|
| 121 | void displayWarning(const std::string warnText); //!< TODO: Implement. | 
|---|
| 122 | void displayBoundaries(Pawn *item, float alpha); | 
|---|
| 123 | void conditionalBounceBack(Pawn *item, float currentDistance, float dt); | 
|---|
| 124 | void bounceBack(Pawn *item, Vector3 *normal, Vector3 *velocity); | 
|---|
| 125 | bool isHumanPlayer(Pawn *item); | 
|---|
| 126 |  | 
|---|
| 127 | void checkWhoIsIn(); //!< Update the list 'pawnsIn_'. | 
|---|
| 128 |  | 
|---|
| 129 | void positionBillboard(const Vector3& position, float alpha); //!< Display a Billboard at the position 'position'. | 
|---|
| 130 | void setBillboardOptions(Billboard *billy); | 
|---|
| 131 | void removeAllBillboards(); //!< Hide all elements of '*billboard_' and set their attribute 'usedYet' to 0. | 
|---|
| 132 | }; | 
|---|
| 133 | } | 
|---|
| 134 |  | 
|---|
| 135 | #endif /* _SpaceBoundaries_H__ */ | 
|---|