Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 14, 2011, 8:53:28 PM (14 years ago)
Author:
dafrick
Message:

Merging presentation branch back into trunk.
There are many new features and also a lot of other changes and bugfixes, if you want to know, digg through the svn log.
Not everything is yet working as it should, but it should be fairly stable. If you habe any bug reports, just send me an email.

Location:
code/trunk
Files:
2 deleted
54 edited
1 copied

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/orxonox/LevelManager.cc

    r8079 r8706  
    222222                this->nextLevel_ = this->availableLevels_.begin();
    223223            }
     224
    224225            while(this->nextIndex_ != index)
    225226            {
  • code/trunk/src/orxonox/MoodManager.cc

    r8351 r8706  
    9393
    9494
    95     std::string MoodListener::mood_s;
    96 
    9795    MoodListener::MoodListener()
    9896    {
     
    102100    /*static*/ void MoodListener::changedMood(const std::string& mood)
    103101    {
    104         mood_s = mood;
    105102        for (ObjectList<MoodListener>::iterator it = ObjectList<MoodListener>::begin(); it; ++it)
    106             it->moodChanged(mood_s);
     103            it->moodChanged(mood);
    107104    }
    108105}
  • code/trunk/src/orxonox/MoodManager.h

    r7163 r8706  
    5050            virtual ~MoodListener() {}
    5151
    52             const std::string& getMood() const { return mood_s; }
    53 
    5452        private:
    5553            virtual void moodChanged(const std::string& mood) = 0;
    5654
    5755            static void changedMood(const std::string& mood);
    58             static std::string mood_s;
    5956    };
    6057
  • code/trunk/src/orxonox/collisionshapes/CollisionShape.cc

    r7401 r8706  
    2626 *
    2727 */
     28
     29/**
     30    @file CollisionShape.cc
     31    @brief Implementation of the CollisionShape class.
     32*/
    2833
    2934#include "CollisionShape.h"
     
    3944namespace orxonox
    4045{
     46
     47    /**
     48    @brief
     49        Constructor. Registers and initializes the object.
     50    */
    4151    CollisionShape::CollisionShape(BaseObject* creator)
    4252        : BaseObject(creator)
     
    5161        this->orientation_ = Quaternion::IDENTITY;
    5262        this->scale_ = Vector3::UNIT_SCALE;
     63        this->uniformScale_ = true;
    5364
    5465        this->registerVariables();
    5566    }
    5667
     68    /**
     69    @brief
     70        Destructor. Detaches the CollisionShape from its parent.
     71    */
    5772    CollisionShape::~CollisionShape()
    5873    {
    59         // Detach from parent
     74        // Detach from parent CompoundCollisionShape.
    6075        if (this->isInitialized() && this->parent_)
    6176            this->parent_->detach(this);
     
    7590    }
    7691
     92    /**
     93    @brief
     94        Register variables that need synchronizing over the network.
     95    */
    7796    void CollisionShape::registerVariables()
    7897    {
     98        // Keep the shape's parent (can be either a CompoundCollisionShape or a WorldEntity) consistent over the network.
    7999        registerVariable(this->parentID_, VariableDirection::ToClient, new NetworkCallback<CollisionShape>(this, &CollisionShape::parentChanged));
    80100    }
    81101
     102    /**
     103    @brief
     104        Notifies the CollisionShape of being attached to a CompoundCollisionShape.
     105    @param newParent
     106        A pointer to the CompoundCollisionShape the CollisionShape was attached to.
     107    @return
     108        Returns
     109    */
     110    bool CollisionShape::notifyBeingAttached(CompoundCollisionShape* newParent)
     111    {
     112        // If the CollisionShape is attached to a CompoundCollisionShapes, detach it.
     113        if (this->parent_)
     114            this->parent_->detach(this);
     115
     116        this->parent_ = newParent;
     117
     118        // If the new parent is a WorldEntityCollisionShape, the parentID is set to the objectID of the WorldEntity that is its owner.
     119        // TODO: Why?
     120        WorldEntityCollisionShape* parentWECCS = orxonox_cast<WorldEntityCollisionShape*>(newParent);
     121        if (parentWECCS)
     122            this->parentID_ = parentWECCS->getWorldEntityOwner()->getObjectID();
     123        // Else it is set to the objectID of the CompoundCollisionShape.
     124        else
     125            this->parentID_ = newParent->getObjectID();
     126
     127        return true;
     128    }
     129
     130    /**
     131    @brief
     132        Notifies the CollisionShape of being detached from a CompoundCollisionShape.
     133    */
     134    void CollisionShape::notifyDetached()
     135    {
     136        this->parent_ = 0;
     137        this->parentID_ = OBJECTID_UNKNOWN;
     138    }
     139
     140    /**
     141    @brief
     142        Updates the CompoundCollisionShape the CollisionShape belongs to (if it belongs to one), after the CollisionShape has changed.
     143    */
     144    void CollisionShape::updateParent()
     145    {
     146        if (this->parent_)
     147            this->parent_->updateAttachedShape(this);
     148    }
     149
     150    /**
     151    @brief
     152        Is called when the parentID of the CollisionShape has changed.
     153        Attaches it to the object with the changed parentID, which can either be a CompoundCollisionShape or a WorldEntity.
     154    */
    82155    void CollisionShape::parentChanged()
    83156    {
     157        // Get the parent object from the network.
    84158        Synchronisable* parent = Synchronisable::getSynchronisable(this->parentID_);
     159
    85160        // Parent can either be a WorldEntity or a CompoundCollisionShape. The reason is that the
    86161        // internal collision shape (which is compound) of a WE doesn't get synchronised.
    87162        CompoundCollisionShape* parentCCS = orxonox_cast<CompoundCollisionShape*>(parent);
     163
     164        // If the parent is a CompoundCollisionShape, attach the CollisionShape to it.
    88165        if (parentCCS)
    89166            parentCCS->attach(this);
    90167        else
    91168        {
     169            // If the parent is a WorldEntity, attach the CollisionShape to its collision shapes.
    92170            WorldEntity* parentWE = orxonox_cast<WorldEntity*>(parent);
    93171            if (parentWE)
     
    96174    }
    97175
    98     bool CollisionShape::notifyBeingAttached(CompoundCollisionShape* newParent)
    99     {
    100         if (this->parent_)
    101             this->parent_->detach(this);
    102 
    103         this->parent_ = newParent;
    104 
    105         WorldEntityCollisionShape* parentWECCS = orxonox_cast<WorldEntityCollisionShape*>(newParent);
    106         if (parentWECCS)
    107             this->parentID_ = parentWECCS->getWorldEntityOwner()->getObjectID();
    108         else
    109             this->parentID_ = newParent->getObjectID();
    110 
    111         return true;
    112     }
    113 
    114     void CollisionShape::notifyDetached()
    115     {
    116         this->parent_ = 0;
    117         this->parentID_ = OBJECTID_UNKNOWN;
    118     }
    119 
    120     void CollisionShape::updateParent()
    121     {
    122         if (this->parent_)
    123             this->parent_->updateAttachedShape(this);
    124     }
    125 
     176    /**
     177    @brief
     178        Check whether the CollisionShape has been either moved or rotated or both. (i.e. it doesn't have position zero and identity orientation any more)
     179    @return
     180        Returns true if it has been moved.
     181    */
    126182    bool CollisionShape::hasTransform() const
    127183    {
     
    130186    }
    131187
     188    /**
     189    @brief
     190        Set the scale of the CollisionShape.
     191        Since the scale is a vector the CollisionShape can be scaled independently in each direction, allowing for linear distortions.
     192        If the scale changes, this causes the parent CompoundCollisionShape (if there is one) to be updated.
     193        Beware, non-uniform scaling (i.e. distortions) might not be supported by all CollisionShapes.
     194    @param scale
     195        The new scale to be set. Vector3::UNIT_SCALE is the initial scale.
     196    */
    132197    void CollisionShape::setScale3D(const Vector3& scale)
    133198    {
    134         CCOUT(2) << "Warning: Cannot set the scale of a collision shape: Not yet implemented." << std::endl;
    135     }
    136 
     199        if(this->scale_ == scale)
     200            return;
     201
     202        // If the vectors are not in the same direction, then this is no longer a uniform scaling.
     203        if(scale_.crossProduct(scale).squaredLength() != 0.0f)
     204        {
     205            CCOUT(2) << "Warning: Non-uniform scaling is not yet supported." << endl;
     206            return;
     207        }
     208
     209        this->scale_ = scale;
     210
     211        this->changedScale();
     212        this->updateParent();
     213    }
     214
     215    /**
     216    @brief
     217        Set the (uniform) scale of the CollisionShape.
     218        If the scale changes, this causes the parent CompoundCollisionShape (if there is one) to be updated.
     219    @param scale
     220        The scale to scale the CollisionShape with. 1.0f is the initial scale.
     221    */
    137222    void CollisionShape::setScale(float scale)
    138223    {
    139         CCOUT(2) << "Warning: Cannot set the scale of a collision shape: Not yet implemented." << std::endl;
    140     }
    141 
     224        if(this->scale_.length() == scale)
     225            return;
     226
     227        this->scale_ = Vector3::UNIT_SCALE*scale;
     228
     229        this->changedScale();
     230        this->updateParent();
     231    }
     232
     233    /**
     234    @brief
     235        Is called when the scale of the CollisionShape has changed.
     236    */
     237    void CollisionShape::changedScale()
     238    {
     239        // Adjust the position of the CollisionShape.
     240        this->position_ *= this->getScale3D();
     241    }
     242
     243    /**
     244    @brief
     245        Updates the shape.
     246        Is called when the internal parameters of the shape have changed such that a new shape needs to be created.
     247    */
    142248    void CollisionShape::updateShape()
    143249    {
    144250        btCollisionShape* oldShape = this->collisionShape_;
    145251        this->collisionShape_ = this->createNewShape();
     252        // If the CollisionShape has been rescaled, scale the shape to fit the current scale.
     253        if(this->scale_ != Vector3::UNIT_SCALE)
     254            this->changedScale();
    146255        // When we recreate the shape, we have to inform the parent about this to update the shape
    147256        this->updateParent();
     
    150259    }
    151260
     261    /**
     262    @brief
     263        Calculates the local inertia of the collision shape.
     264    @todo
     265        Document.
     266    */
    152267    void CollisionShape::calculateLocalInertia(float mass, btVector3& inertia) const
    153268    {
  • code/trunk/src/orxonox/collisionshapes/CollisionShape.h

    r7163 r8706  
    2727 */
    2828
     29/**
     30    @file CollisionShape.h
     31    @brief Definition of the CollisionShape class.
     32    @ingroup Collisionshapes
     33*/
     34
    2935#ifndef _CollisionShape_H__
    3036#define _CollisionShape_H__
     
    3844namespace orxonox
    3945{
     46
     47    /**
     48    @brief
     49        Wrapper for bullet collision shape class btCollisionShape.
     50
     51    @author
     52        Reto Grieder
     53
     54    @see btCollisionShape
     55    @ingroup Collisionshapes
     56    */
    4057    class _OrxonoxExport CollisionShape : public BaseObject, public Synchronisable
    4158    {
     
    4663            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    4764
     65            /**
     66            @brief Set the position of the CollisionShape.
     67                   If the position changes, this causes the parent CompoundCollisionShape (if there is one) to be updated.
     68            @param position A vector indicating the new position.
     69            */
    4870            inline void setPosition(const Vector3& position)
    49                 { this->position_ = position; this->updateParent(); }
     71                { if(this->position_ == position) return; this->position_ = position; this->updateParent(); }
     72            /**
     73            @brief Get the position of the CollisionShape.
     74            @return Returns the position of the CollisionShape as a vector.
     75            */
    5076            inline const Vector3& getPosition() const
    5177                { return this->position_; }
    5278
     79            /**
     80            @brief Set the orientation of the CollisionShape.
     81                   If the orientation changes, this causes the parent CompoundCollisionShape (if there is one) to be updated.
     82            @param orientation A quaternion indicating the new orientation.
     83            */
    5384            inline void setOrientation(const Quaternion& orientation)
    54                 { this->orientation_ = orientation; this->updateParent(); }
     85                { if(this->orientation_ == orientation) return; this->orientation_ = orientation; this->updateParent(); }
     86            /**
     87            @brief Get the orientation of the CollisionShape.
     88            @return Returns the orientation of the CollisionShape as a quaternion.
     89            */
    5590            inline const Quaternion& getOrientation() const
    5691                { return this->orientation_; }
    5792
    58             void yaw(const Degree& angle)   { this->setOrientation(this->orientation_ * Quaternion(angle, Vector3::UNIT_Y)); }
    59             void pitch(const Degree& angle) { this->setOrientation(this->orientation_ * Quaternion(angle, Vector3::UNIT_X)); }
    60             void roll(const Degree& angle)  { this->setOrientation(this->orientation_ * Quaternion(angle, Vector3::UNIT_Z)); }
     93            /**
     94            @brief Rotate the CollisionShape around the y-axis by the specified angle.
     95                   If the orientation changes, this causes the parent CompoundCollisionShape (if there is one) to be updated.
     96            @param angle The angle by which the CollisionShape is rotated.
     97            */
     98            void yaw(const Degree& angle)
     99                { this->setOrientation(this->orientation_ * Quaternion(angle, Vector3::UNIT_Y)); }
     100            /**
     101            @brief Rotate the CollisionShape around the x-axis by the specified angle.
     102                   If the orientation changes, this causes the parent CompoundCollisionShape (if there is one) to be updated.
     103            @param angle The angle by which the CollisionShape is rotated.
     104            */
     105            void pitch(const Degree& angle)
     106                { this->setOrientation(this->orientation_ * Quaternion(angle, Vector3::UNIT_X)); }
     107            /**
     108            @brief Rotate the CollisionShape around the z-axis by the specified angle.
     109                   If the orientation changes, this causes the parent CompoundCollisionShape (if there is one) to be updated.
     110            @param angle The angle by which the CollisionShape is rotated.
     111            */
     112            void roll(const Degree& angle)
     113                { this->setOrientation(this->orientation_ * Quaternion(angle, Vector3::UNIT_Z)); }
    61114
    62             virtual void setScale3D(const Vector3& scale);
    63             virtual void setScale(float scale);
     115            /**
     116            @brief Scale the CollisionShape by the input vector.
     117                   Since the scale is a vector the CollisionShape can be scaled independently in each direction, allowing for linear distortions.
     118                   If the scale changes, this causes the parent CompoundCollisionShape (if there is one) to be updated.
     119                   Beware, non-uniform scaling (i.e. distortions) might not be supported by all CollisionShapes.
     120            @param scale The scaling vector by which the CollisionShape is scaled.
     121            */
     122            inline void scale3D(const Vector3& scale)
     123                { this->setScale3D(this->getScale3D()*scale); }
     124            void setScale3D(const Vector3& scale); // Set the scale of the CollisionShape.
     125            /**
     126            @brief Get the scale of the CollisionShape.
     127            @return Returns a vector indicating the scale of the CollisionShape.
     128            */
    64129            inline const Vector3& getScale3D() const
    65130                { return this->scale_; }
    66131
    67             void updateShape();
     132            /**
     133            @brief (Uniformly) scale the CollisionShape by the input scale.
     134                   If the scale changes, this causes the parent CompoundCollisionShape (if there is one) to be updated.
     135            @param scale The value by which the CollisionShape is scaled.
     136            */
     137            inline void scale(float scale)
     138                { this->setScale3D(this->getScale3D()*scale); }
     139            void setScale(float scale); // Set the (uniform) scale of the CollisionShape.
     140            /**
     141            @brief Get the (uniform) scale of the CollisionShape.
     142                   This is only meaningful if the CollisionShape has uniform scaling.
     143            @return Returns the (uniform) scale of the CollisionShape. Returns 0.0f if the scaling is non-uniform.
     144            */
     145            inline float getScale()
     146                { if(this->hasUniformScaling()) return this->scale_.x; return 0.0f; }
    68147
    69             void calculateLocalInertia(float mass, btVector3& inertia) const;
     148            /**
     149            @brief Check whether the CollisionShape is uniformly scaled.
     150            @return Returns true if the CollisionShape is uniformly scaled, false if not.
     151            */
     152            inline bool hasUniformScaling()
     153                { return this->uniformScale_; }
     154            virtual void changedScale(); // Is called when the scale of the CollisionShape has changed.
    70155
     156            void updateShape(); // Updates the shape.
     157
     158            void calculateLocalInertia(float mass, btVector3& inertia) const; // Calculates the local inertia of the collision shape.
     159
     160            /**
     161            @brief Get the bullet collision shape of this CollisionShape.
     162            @return Returns a pointer to the bullet collision shape of this CollisionShape.
     163            */
    71164            inline btCollisionShape* getCollisionShape() const
    72165                { return this->collisionShape_; }
    73166
    74             bool hasTransform() const;
     167            bool hasTransform() const; // Check whether the CollisionShape has been either moved or rotated or both.
    75168
    76             bool notifyBeingAttached(CompoundCollisionShape* newParent);
    77             void notifyDetached();
     169            bool notifyBeingAttached(CompoundCollisionShape* newParent); // Notifies the CollisionShape of being attached to a CompoundCollisionShape.
     170            void notifyDetached(); // Notifies the CollisionShape of being detached from a CompoundCollisionShape.
    78171
    79172        protected:
    80             virtual void updateParent();
    81             virtual void parentChanged();
     173            virtual void updateParent(); // Updates the CompoundCollisionShape the CollisionShape belongs to, after the CollisionShape has changed.
     174            virtual void parentChanged(); // Is called when the parentID of the CollisionShape has changed.
     175
     176            /**
     177            @brief Create a new bullet collision shape depending on the internal parameters of the specific CollisionShape.
     178            @return Returns a pointer to the new bullet collision shape.
     179            */
    82180            virtual btCollisionShape* createNewShape() const = 0;
    83181
    84             btCollisionShape*       collisionShape_;
    85             CompoundCollisionShape* parent_;
    86             unsigned int            parentID_;
     182            btCollisionShape*       collisionShape_; //!< The bullet collision shape of this CollisionShape.
     183            CompoundCollisionShape* parent_; //!< The CompoundCollisionShape this CollisionShape belongs to, NULL if it doesn't belong to one.
     184            unsigned int            parentID_; //!< The objectID of the parent of this CollisionShape, which can either be a CompoundCollisionShape or a WorldEntity.
    87185
    88186        private:
    89187            void registerVariables();
    90188
    91             Vector3                 position_;
    92             Quaternion              orientation_;
    93             Vector3                 scale_;
     189            Vector3                 position_; //!< The position of the CollisionShape.
     190            Quaternion              orientation_; //!< The orientation of the CollisionShape.
     191            Vector3                 scale_; //!< The scale of the CollisionShape.
     192            bool                    uniformScale_; //!< Whether the scale is uniform.
    94193    };
    95194}
  • code/trunk/src/orxonox/collisionshapes/CompoundCollisionShape.cc

    r5929 r8706  
    2727 */
    2828
     29/**
     30    @file CompoundCollisionShape.cc
     31    @brief Implementation of the CompoundCollisionShape class.
     32*/
     33
    2934#include "CompoundCollisionShape.h"
    3035
     
    3944    CreateFactory(CompoundCollisionShape);
    4045
     46    /**
     47    @brief
     48        Constructor. Registers and initializes the object.
     49    */
    4150    CompoundCollisionShape::CompoundCollisionShape(BaseObject* creator) : CollisionShape(creator)
    4251    {
     
    4655    }
    4756
     57    /**
     58    @brief
     59        Destructor.
     60        Deletes all its children.
     61    */
    4862    CompoundCollisionShape::~CompoundCollisionShape()
    4963    {
     
    7084    }
    7185
     86    /**
     87    @brief
     88        Attach the input CollisionShape to the CompoundCollisionShape.
     89    @param shape
     90        A pointer to the CollisionShape that is to be attached.
     91    */
    7292    void CompoundCollisionShape::attach(CollisionShape* shape)
    7393    {
     94        // If either the input shape is NULL or we try to attach the CollisionShape to itself.
    7495        if (!shape || static_cast<CollisionShape*>(this) == shape)
    7596            return;
     97
    7698        if (this->attachedShapes_.find(shape) != this->attachedShapes_.end())
    7799        {
     
    80102        }
    81103
     104        // Notify the CollisionShape that it is being attached to the CompoundCollisionShape.
    82105        if (!shape->notifyBeingAttached(this))
    83106            return;
    84107
     108        // Attach it.
    85109        this->attachedShapes_[shape] = shape->getCollisionShape();
    86110
     111        // Only actually attach if we didn't pick a CompoundCollisionShape with no content.
    87112        if (shape->getCollisionShape())
    88113        {
    89             // Only actually attach if we didn't pick a CompoundCollisionShape with no content
    90114            btTransform transf(multi_cast<btQuaternion>(shape->getOrientation()), multi_cast<btVector3>(shape->getPosition()));
     115            // Add the btCollisionShape of the CollisionShape as a child shape to the btCompoundShape of the CompoundCollisionShape.
    91116            this->compoundShape_->addChildShape(transf, shape->getCollisionShape());
    92117
     
    95120    }
    96121
     122    /**
     123    @brief
     124        Detach the input CollisionShape form the CompoundCollisionShape.
     125    @param shape
     126        A pointer to the CollisionShape to be detached.
     127    */
    97128    void CompoundCollisionShape::detach(CollisionShape* shape)
    98129    {
     130        // If the input CollisionShape is actually attached.
    99131        if (this->attachedShapes_.find(shape) != this->attachedShapes_.end())
    100132        {
    101133            this->attachedShapes_.erase(shape);
    102134            if (shape->getCollisionShape())
    103                 this->compoundShape_->removeChildShape(shape->getCollisionShape());
     135                this->compoundShape_->removeChildShape(shape->getCollisionShape()); // TODO: Apparently this is broken?
    104136            shape->notifyDetached();
    105137
     
    110142    }
    111143
     144    /**
     145    @brief
     146        Detach all attached CollisionShapes.
     147    */
    112148    void CompoundCollisionShape::detachAll()
    113149    {
     
    116152    }
    117153
     154    /**
     155    @brief
     156        Update the input CollisionShape that is attached to the CompoundCollisionShape.
     157        This is called when the input shape's internal collision shape (a btCollisionShape) has changed.
     158    @param shape
     159        A pointer to the CollisionShape to be updated.
     160    */
    118161    void CompoundCollisionShape::updateAttachedShape(CollisionShape* shape)
    119162    {
    120163        if (!shape)
    121164            return;
     165
    122166        std::map<CollisionShape*, btCollisionShape*>::iterator it = this->attachedShapes_.find(shape);
     167        // Check whether the input shape belongs to this CompoundCollisionShape.
    123168        if (it == this->attachedShapes_.end())
    124169        {
     
    129174        // Remove old btCollisionShape, stored in the children map
    130175        if (it->second)
    131             this->compoundShape_->removeChildShape(it->second);
     176            this->compoundShape_->removeChildShape(it->second); // TODO: Apparently this is broken?
     177
     178        // Only actually attach if we didn't pick a CompoundCollisionShape with no content
    132179        if (shape->getCollisionShape())
    133180        {
    134             // Only actually attach if we didn't pick a CompoundCollisionShape with no content
    135181            btTransform transf(multi_cast<btQuaternion>(shape->getOrientation()), multi_cast<btVector3>(shape->getPosition()));
    136182            this->compoundShape_->addChildShape(transf, shape->getCollisionShape());
     
    141187    }
    142188
     189    /**
     190    @brief
     191        Updates the public shape, the collision shape this CompoundCollisionShape has to the outside.
     192    */
    143193    void CompoundCollisionShape::updatePublicShape()
    144194    {
    145         btCollisionShape* primitive = 0;
    146         bool bPrimitive = true;
    147         bool bEmpty = true;
     195        btCollisionShape* primitive = 0; // The primitive shape, if there is one.
     196        bool bPrimitive = true; // Whether the CompoundCollisionShape has just one non-empty CollisionShape. And that shape also has no transformation.
     197        bool bEmpty = true; // Whether the CompoundCollisionShape is empty.
     198        // Iterate over all CollisionShapes that belong to this CompoundCollisionShape.
    148199        for (std::map<CollisionShape*, btCollisionShape*>::const_iterator it = this->attachedShapes_.begin(); it != this->attachedShapes_.end(); ++it)
    149200        {
     201            // TODO: Make sure this is correct.
    150202            if (it->second)
    151203            {
    152204                bEmpty = false;
    153                 if (!it->first->hasTransform() && !bPrimitive)
     205                if (!it->first->hasTransform() && bPrimitive)
    154206                    primitive = it->second;
    155207                else
     208                {
    156209                    bPrimitive = false;
     210                    break;
     211                }
    157212            }
    158213        }
     214
     215        // If there is no non-empty CollisionShape.
    159216        if (bEmpty)
    160217        {
     218            // If there was none all along, nothing needs to be changed.
    161219            if (this->collisionShape_ == 0)
    162             {
    163                 this->collisionShape_ = 0;
    164220                return;
    165             }
    166221            this->collisionShape_ = 0;
    167222        }
     223        // If the CompoundCollisionShape is just a primitive.
     224        // Only one shape to be added, no transform; return it directly.
    168225        else if (bPrimitive)
    169         {
    170             // --> Only one shape to be added, no transform; return it directly
    171226            this->collisionShape_ = primitive;
    172         }
     227        // Make sure we use the compound shape when returning a btCollisionShape.
    173228        else
    174         {
    175             // Make sure we use the compound shape when returning a btCollisionShape
    176229            this->collisionShape_ = this->compoundShape_;
    177         }
     230
    178231        this->updateParent();
    179232    }
    180233
     234    /**
     235    @brief
     236        Get the attached CollisionShape at the given index.
     237    @param index
     238        The index of the desired CollisionShape.
     239    @return
     240        Returns a pointer to the attached CollisionShape at the given index.
     241    */
    181242    CollisionShape* CompoundCollisionShape::getAttachedShape(unsigned int index) const
    182243    {
     
    190251        return 0;
    191252    }
     253
     254    /**
     255    @brief
     256        Is called when the scale of the CompoundCollisionShape has changed.
     257        Iterates over all attached CollisionShapes and scales them, then recomputes their compound shape.
     258    */
     259    void CompoundCollisionShape::changedScale()
     260    {
     261        CollisionShape::changedScale();
     262
     263        std::vector<CollisionShape*> shapes;
     264        // Iterate through all attached CollisionShapes and add them to the list of shapes.
     265        for(std::map<CollisionShape*, btCollisionShape*>::iterator it = this->attachedShapes_.begin(); it != this->attachedShapes_.end(); it++)
     266            shapes.push_back(it->first);
     267
     268        // Delete the compound shape and create a new one.
     269        delete this->compoundShape_;
     270        this->compoundShape_ = new btCompoundShape();
     271
     272        // Re-attach all CollisionShapes.
     273        for(std::vector<CollisionShape*>::iterator it = shapes.begin(); it != shapes.end(); it++)
     274        {
     275            CollisionShape* shape = *it;
     276            shape->setScale3D(this->getScale3D());
     277            // Only actually attach if we didn't pick a CompoundCollisionShape with no content.
     278            if (shape->getCollisionShape())
     279            {
     280                btTransform transf(multi_cast<btQuaternion>(shape->getOrientation()), multi_cast<btVector3>(shape->getPosition()));
     281                // Add the btCollisionShape of the CollisionShape as a child shape to the btCompoundShape of the CompoundCollisionShape.
     282                this->compoundShape_->addChildShape(transf, shape->getCollisionShape());
     283            }
     284        }
     285
     286        this->updatePublicShape();
     287
     288        /*
     289        // Iterate through all attached CollisionShapes
     290        for(std::map<CollisionShape*, btCollisionShape*>::const_iterator it = this->attachedShapes_.begin(); it != this->attachedShapes_.end(); it++)
     291        {
     292            // Rescale the CollisionShape.
     293            it->first->setScale3D(this->getScale3D());
     294            this->updateAttachedShape(it->first);
     295        }
     296
     297        this->updatePublicShape();*/
     298    }
    192299}
  • code/trunk/src/orxonox/collisionshapes/CompoundCollisionShape.h

    r5781 r8706  
    2727 */
    2828
     29/**
     30    @file CompoundCollisionShape.h
     31    @brief Definition of the CompoundCollisionShape class.
     32    @ingroup Collisionshapes
     33*/
     34
    2935#ifndef _CompoundCollisionShape_H__
    3036#define _CompoundCollisionShape_H__
     
    3844namespace orxonox
    3945{
     46
     47    /**
     48    @brief
     49        Wrapper for the bullet compound collision shape class btCompoundShape.
     50
     51    @author
     52        Reto Grieder
     53
     54    @see btCompoundShape
     55    @ingroup Collisionshapes
     56    */
    4057    class _OrxonoxExport CompoundCollisionShape : public CollisionShape
    4158    {
     
    5370            void updateAttachedShape(CollisionShape* shape);
    5471
     72            virtual void changedScale();
     73
    5574        private:
    5675            void updatePublicShape();
  • code/trunk/src/orxonox/collisionshapes/WorldEntityCollisionShape.cc

    r5929 r8706  
    4343        this->worldEntityOwner_ = creator;
    4444        // suppress synchronisation
    45         this->setSyncMode(0x0);
     45        this->setSyncMode(ObjectDirection::None);
    4646    }
    4747
  • code/trunk/src/orxonox/controllers/ArtificialController.cc

    r8351 r8706  
    381381            }
    382382        }
     383
     384        if (distance < 10)
     385        {
     386            this->positionReached();
     387        }
    383388    }
    384389
     
    387392        this->moveToPosition(this->targetPosition_);
    388393    }
    389 
    390394
    391395    /**
  • code/trunk/src/orxonox/controllers/ArtificialController.h

    r7163 r8706  
    9797            void moveToTargetPosition();
    9898
     99            virtual void positionReached() {}
     100
    99101            void removeFromFormation();
    100102            void unregisterSlave();
  • code/trunk/src/orxonox/controllers/Controller.h

    r6417 r8706  
    5050                { return this->player_; }
    5151
    52             virtual inline void hit(Pawn* originator, btManifoldPoint& contactpoint, float damage) {};
     52            virtual void hit(Pawn* originator, btManifoldPoint& contactpoint, float damage) {};
     53
     54/* Override needed for different visual effects (e.g. in "NewHumanController.cc") depending on
     55   the DIFFERENT AMOUNT OF DAMAGE done to the shield and to the health of "victim" (see Projectile.cc, Pawn.cc)
     56
     57//            virtual inline void hit(Pawn* originator, btManifoldPoint& contactpoint, float damage, float healthdamage, float shielddamage) {};
     58*/
    5359
    5460            void setGodMode( bool mode ){ this->bGodMode_ = mode; }
  • code/trunk/src/orxonox/controllers/HumanController.cc

    r8079 r8706  
    4242    extern const std::string __CC_fire_name = "fire";
    4343    extern const std::string __CC_suicide_name = "suicide";
     44    const std::string __CC_boost_name = "boost";
    4445
    4546    SetConsoleCommand("HumanController", "moveFrontBack",          &HumanController::moveFrontBack ).addShortcut().setAsInputCommand();
     
    5152    SetConsoleCommand("HumanController", __CC_fire_name,           &HumanController::fire          ).addShortcut().keybindMode(KeybindMode::OnHold);
    5253    SetConsoleCommand("HumanController", "reload",                 &HumanController::reload        ).addShortcut();
    53     SetConsoleCommand("HumanController", "boost",                  &HumanController::boost         ).addShortcut().keybindMode(KeybindMode::OnHold);
     54    SetConsoleCommand("HumanController", __CC_boost_name,          &HumanController::keepBoost     ).addShortcut().keybindMode(KeybindMode::OnHold);
    5455    SetConsoleCommand("HumanController", "greet",                  &HumanController::greet         ).addShortcut();
    5556    SetConsoleCommand("HumanController", "switchCamera",           &HumanController::switchCamera  ).addShortcut();
     
    6667
    6768    HumanController* HumanController::localController_s = 0;
     69    /*static*/ const float HumanController::BOOSTING_TIME = 0.1f;
    6870
    6971    HumanController::HumanController(BaseObject* creator) : Controller(creator)
     
    7173        RegisterObject(HumanController);
    7274
    73         controlPaused_ = false;
     75        this->controlPaused_ = false;
     76        this->boosting_ = false;
     77        this->boosting_ = false;
    7478
    7579        HumanController::localController_s = this;
     80        this->boostingTimeout_.setTimer(HumanController::BOOSTING_TIME, false, createExecutor(createFunctor(&HumanController::terminateBoosting, this)));
     81        this->boostingTimeout_.stopTimer();
    7682    }
    7783
     
    163169    }
    164170
    165     void HumanController::boost()
    166     {
    167         if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
    168             HumanController::localController_s->controllableEntity_->boost();
     171    /**
     172    @brief
     173        Static method,keeps boosting.
     174    */
     175    /*static*/ void HumanController::keepBoost()
     176    {
     177        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
     178            HumanController::localController_s->keepBoosting();
     179    }
     180   
     181    /**
     182    @brief
     183        Starts, or keeps the boosting mode.
     184        Resets the boosting timeout and ells the ControllableEntity to boost (or not boost anymore).
     185    */
     186    void HumanController::keepBoosting(void)
     187    {
     188        if(this->boostingTimeout_.isActive())
     189        {
     190            this->boostingTimeout_.stopTimer();
     191            this->boostingTimeout_.startTimer();
     192        }
     193        else
     194        {
     195            this->boosting_ = true;
     196            this->boostingTimeout_.startTimer();
     197           
     198            this->controllableEntity_->boost(this->boosting_);
     199            COUT(4) << "Start boosting" << endl;
     200        }
     201    }
     202
     203    /**
     204    @brief
     205        Terminates the boosting mode.
     206    */
     207    void HumanController::terminateBoosting(void)
     208    {
     209        this->boosting_ = false;
     210        this->boostingTimeout_.stopTimer();
     211
     212        this->controllableEntity_->boost(this->boosting_);
     213        COUT(4) << "Stop boosting" << endl;
    169214    }
    170215
  • code/trunk/src/orxonox/controllers/HumanController.h

    r8079 r8706  
    3232#include "OrxonoxPrereqs.h"
    3333
     34#include "tools/Timer.h"
    3435#include "tools/interfaces/Tickable.h"
    3536#include "Controller.h"
     
    6465            static void reload();
    6566
    66             static void boost();
     67            static void keepBoost(); // Static method, keeps boosting.
     68            /**
     69            @brief Check whether the HumanController is in boosting mode.
     70            @return Returns true if it is, false if not.
     71            */
     72            inline bool isBoosting(void)
     73                { return this->boosting_; }
     74            void keepBoosting(void);
     75            void terminateBoosting(void);
     76           
    6777            static void greet();
    6878            static void switchCamera();
     
    92102            static HumanController* localController_s;
    93103            bool controlPaused_;
     104       
     105        private:
     106            bool boosting_; // Whether the HumanController is in boosting mode or not.
     107            Timer boostingTimeout_; // A timer to check whether the player is no longer boosting.
     108            static const float BOOSTING_TIME; // The time after it is checked, whether the player is no longer boosting.
     109
    94110    }; // tolua_export
    95111} // tolua_export
  • code/trunk/src/orxonox/gamestates/GSRoot.cc

    r8327 r8706  
    4545
    4646    static const std::string __CC_setTimeFactor_name = "setTimeFactor";
     47    static const std::string __CC_getTimeFactor_name = "getTimeFactor";
    4748    static const std::string __CC_setPause_name = "setPause";
    4849    static const std::string __CC_pause_name = "pause";
     
    5253    SetConsoleCommand("printObjects", &GSRoot::printObjects).hide();
    5354    SetConsoleCommand(__CC_setTimeFactor_name, &GSRoot::setTimeFactor).accessLevel(AccessLevel::Master).defaultValues(1.0);
     55    SetConsoleCommand(__CC_getTimeFactor_name, &GSRoot::getTimeFactor).accessLevel(AccessLevel::Master);
    5456    SetConsoleCommand(__CC_setPause_name,      &GSRoot::setPause     ).accessLevel(AccessLevel::Master).hide();
    5557    SetConsoleCommand(__CC_pause_name,         &GSRoot::pause        ).accessLevel(AccessLevel::Master);
     
    8991
    9092        ModifyConsoleCommand(__CC_setTimeFactor_name).setObject(this);
     93        ModifyConsoleCommand(__CC_getTimeFactor_name).setObject(this);
    9194        ModifyConsoleCommand(__CC_setPause_name).setObject(this);
    9295        ModifyConsoleCommand(__CC_pause_name).setObject(this);
     
    9699    {
    97100        ModifyConsoleCommand(__CC_setTimeFactor_name).setObject(0);
     101        ModifyConsoleCommand(__CC_getTimeFactor_name).setObject(0);
    98102        ModifyConsoleCommand(__CC_setPause_name).setObject(0);
    99103        ModifyConsoleCommand(__CC_pause_name).setObject(0);
     
    151155                this->timeFactorPauseBackup_ = factor;
    152156        }
     157    }
     158
     159    float GSRoot::getTimeFactor()
     160    {
     161        return TimeFactorListener::getTimeFactor();
    153162    }
    154163
  • code/trunk/src/orxonox/gamestates/GSRoot.h

    r8079 r8706  
    5454        void pause();
    5555
     56        float getTimeFactor();
     57
    5658        static void delayedStartMainMenu(void);
    5759
  • code/trunk/src/orxonox/gametypes/Dynamicmatch.cc

    r8327 r8706  
    151151                //Give new pig boost
    152152                SpaceShip* spaceship = dynamic_cast<SpaceShip*>(victim);
    153                 if (spaceship && spaceship->getEngine())
    154                 {
    155                     spaceship->getEngine()->setSpeedFactor(5);
    156                     WeakPtr<Engine>* ptr = new WeakPtr<Engine>(spaceship->getEngine());
    157                     ExecutorPtr executor = createExecutor(createFunctor(&Dynamicmatch::resetSpeedFactor, this));
    158                     executor->setDefaultValue(0, ptr);
    159                     new Timer(10, false, executor, true);
    160                 }
     153                grantPigBoost(spaceship);
    161154            }
    162155
     
    252245                //Give new pig boost
    253246                SpaceShip* spaceship = dynamic_cast<SpaceShip*>(victim);
    254                 if (spaceship && spaceship->getEngine())
    255                 {
    256                     spaceship->getEngine()->setSpeedFactor(5);
    257                     WeakPtr<Engine>* ptr = new WeakPtr<Engine>(spaceship->getEngine());
    258                     ExecutorPtr executor = createExecutor(createFunctor(&Dynamicmatch::resetSpeedFactor, this));
    259                     executor->setDefaultValue(0, ptr);
    260                     new Timer(10, false, executor, true);
    261                 }
    262 
     247                grantPigBoost(spaceship);
    263248            }
    264249            // killer vs piggy
     
    321306    }
    322307
     308    void Dynamicmatch::grantPigBoost(orxonox::SpaceShip* spaceship)
     309    {
     310        // Give pig boost
     311        if (spaceship)
     312        {
     313            spaceship->setSpeedFactor(5);
     314            WeakPtr<SpaceShip>* ptr = new WeakPtr<SpaceShip>(spaceship);
     315            ExecutorPtr executor = createExecutor(createFunctor(&Dynamicmatch::resetSpeedFactor, this));
     316            executor->setDefaultValue(0, ptr);
     317            new Timer(10, false, executor, true);
     318        }
     319    }
     320
    323321    void Dynamicmatch::playerStartsControllingPawn(PlayerInfo* player, Pawn* pawn) //set party + colouring
    324322    {
     
    597595    }
    598596
    599     void Dynamicmatch::resetSpeedFactor(WeakPtr<Engine>* ptr)// helper function
     597    void Dynamicmatch::resetSpeedFactor(WeakPtr<SpaceShip>* ptr)// helper function
    600598    {
    601599        if (*ptr)
  • code/trunk/src/orxonox/gametypes/Dynamicmatch.h

    r7163 r8706  
    7373            virtual void furtherInstructions();*/
    7474            virtual void rewardPig();
    75             void resetSpeedFactor(WeakPtr<Engine>* ptr);
     75            void grantPigBoost(SpaceShip* spaceship); // Added this, since it's used twice on different occasions.
     76            void resetSpeedFactor(WeakPtr<SpaceShip>* ptr);
    7677            void tick (float dt);// used to end the game
    7778            SpawnPoint* getBestSpawnPoint(PlayerInfo* player) const;
  • code/trunk/src/orxonox/gametypes/Gametype.cc

    r8327 r8706  
    121121        }
    122122
    123         if (this->gtinfo_->bStartCountdownRunning_ && !this->gtinfo_->bStarted_)
    124             this->gtinfo_->startCountdown_ -= dt;
    125 
    126         if (!this->gtinfo_->bStarted_)
     123        if (this->gtinfo_->isStartCountdownRunning() && !this->gtinfo_->hasStarted())
     124            this->gtinfo_->countdownStartCountdown(dt);
     125
     126        if (!this->gtinfo_->hasStarted())
     127        {
     128            for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
     129            {
     130                // Inform the GametypeInfo that the player is ready to spawn.
     131                if(it->first->isHumanPlayer() && it->first->isReadyToSpawn())
     132                    this->gtinfo_->playerReadyToSpawn(it->first);
     133            }
     134                   
    127135            this->checkStart();
    128         else if (!this->gtinfo_->bEnded_)
     136        }
     137        else if (!this->gtinfo_->hasEnded())
    129138            this->spawnDeadPlayersIfRequested();
    130139
     
    136145        this->addBots(this->numberOfBots_);
    137146
    138         this->gtinfo_->bStarted_ = true;
     147        this->gtinfo_->start();
    139148
    140149        this->spawnPlayersIfRequested();
     
    143152    void Gametype::end()
    144153    {
    145         this->gtinfo_->bEnded_ = true;
     154        this->gtinfo_->end();
    146155
    147156        for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
     
    173182    {
    174183        this->players_[player].state_ = PlayerState::Joined;
     184        this->gtinfo_->playerEntered(player);
    175185    }
    176186
     
    270280                }
    271281
     282                if(victim->getPlayer()->isHumanPlayer())
     283                    this->gtinfo_->pawnKilled(victim->getPlayer());
     284
    272285                ControllableEntity* entity = this->defaultControllableEntity_.fabricate(victim->getCreator());
    273286                if (victim->getCamera())
     
    306319    SpawnPoint* Gametype::getBestSpawnPoint(PlayerInfo* player) const
    307320    {
     321        // If there is at least one SpawnPoint.
    308322        if (this->spawnpoints_.size() > 0)
    309323        {
     324            // Fallback spawn point if there is no active one, choose a random one.
    310325            SpawnPoint* fallbackSpawnPoint = NULL;
    311326            unsigned int randomspawn = static_cast<unsigned int>(rnd(static_cast<float>(this->spawnpoints_.size())));
    312327            unsigned int index = 0;
    313             std::set<SpawnPoint*> activeSpawnPoints = this->spawnpoints_;
     328            std::vector<SpawnPoint*> activeSpawnPoints;
    314329            for (std::set<SpawnPoint*>::const_iterator it = this->spawnpoints_.begin(); it != this->spawnpoints_.end(); ++it)
    315330            {
     
    317332                    fallbackSpawnPoint = (*it);
    318333
    319                 if (!(*it)->isActive())
    320                     activeSpawnPoints.erase(*it);
     334                if (*it != NULL && (*it)->isActive())
     335                    activeSpawnPoints.push_back(*it);
    321336
    322337                ++index;
    323338            }
    324339
    325             randomspawn = static_cast<unsigned int>(rnd(static_cast<float>(this->spawnpoints_.size())));
    326             index = 0;
    327             for (std::set<SpawnPoint*>::const_iterator it = activeSpawnPoints.begin(); it != activeSpawnPoints.end(); ++it)
    328             {
    329                 if (index == randomspawn)
    330                     return (*it);
    331 
    332                 ++index;
    333             }
    334 
     340            if(activeSpawnPoints.size() > 0)
     341            {
     342                randomspawn = static_cast<unsigned int>(rnd(static_cast<float>(activeSpawnPoints.size())));
     343                return activeSpawnPoints[randomspawn];
     344            }
     345
     346            COUT(2) << "Warning: Fallback SpawnPoint was used, because there were no active SpawnPoints." << endl;
    335347            return fallbackSpawnPoint;
    336348        }
     
    346358                it->second.state_ = PlayerState::Dead;
    347359
    348                 if (!it->first->isReadyToSpawn() || !this->gtinfo_->bStarted_)
     360                if (!it->first->isReadyToSpawn() || !this->gtinfo_->hasStarted())
    349361                {
    350362                    this->spawnPlayerAsDefaultPawn(it->first);
     
    357369    void Gametype::checkStart()
    358370    {
    359         if (!this->gtinfo_->bStarted_)
    360         {
    361             if (this->gtinfo_->bStartCountdownRunning_)
    362             {
    363                 if (this->gtinfo_->startCountdown_ <= 0)
    364                 {
    365                     this->gtinfo_->bStartCountdownRunning_ = false;
    366                     this->gtinfo_->startCountdown_ = 0;
     371        if (!this->gtinfo_->hasStarted())
     372        {
     373            if (this->gtinfo_->isStartCountdownRunning())
     374            {
     375                if (this->gtinfo_->getStartCountdown() <= 0.0f)
     376                {
     377                    this->gtinfo_->stopStartCountdown();
     378                    this->gtinfo_->setStartCountdown(0.0f);;
    367379                    this->start();
    368380                }
     
    389401                        // If in developer's mode, there is no start countdown.
    390402                        if(Core::getInstance().inDevMode())
    391                             this->gtinfo_->startCountdown_ = 0;
     403                            this->start();
    392404                        else
    393                             this->gtinfo_->startCountdown_ = this->initialStartCountdown_;
    394                         this->gtinfo_->bStartCountdownRunning_ = true;
     405                            this->gtinfo_->setStartCountdown(this->initialStartCountdown_);
     406                        this->gtinfo_->startStartCountdown();
    395407                    }
    396408                }
     
    402414    {
    403415        for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
     416        {
    404417            if (it->first->isReadyToSpawn() || this->bForceSpawn_)
    405418                this->spawnPlayer(it->first);
     419        }
    406420    }
    407421
     
    422436            player->startControl(spawnpoint->spawn());
    423437            this->players_[player].state_ = PlayerState::Alive;
     438
     439            if(player->isHumanPlayer())
     440                this->gtinfo_->playerSpawned(player);
     441           
    424442            this->playerPostSpawn(player);
    425443        }
  • code/trunk/src/orxonox/gametypes/Gametype.h

    r8178 r8706  
    7878
    7979            inline bool hasStarted() const
    80                 { return this->gtinfo_->bStarted_; }
     80                { return this->gtinfo_->hasStarted(); }
    8181            inline bool hasEnded() const
    82                 { return this->gtinfo_->bEnded_; }
     82                { return this->gtinfo_->hasEnded(); }
    8383
    8484            virtual void start();
     
    114114
    115115            inline bool isStartCountdownRunning() const
    116                 { return this->gtinfo_->bStartCountdownRunning_; }
     116                { return this->gtinfo_->isStartCountdownRunning(); }
    117117            inline float getStartCountdown() const
    118                 { return this->gtinfo_->startCountdown_; }
     118                { return this->gtinfo_->getStartCountdown(); }
    119119
    120120            inline void setHUDTemplate(const std::string& name)
    121                 { this->gtinfo_->hudtemplate_ = name; }
     121                { this->gtinfo_->setHUDTemplate(name); }
    122122            inline const std::string& getHUDTemplate() const
    123                 { return this->gtinfo_->hudtemplate_; }
     123                { return this->gtinfo_->getHUDTemplate(); }
    124124
    125125            void addBots(unsigned int amount);
  • code/trunk/src/orxonox/gametypes/LastTeamStanding.cc

    r8351 r8706  
    5555        this->setHUDTemplate("lastTeamStandingHUD");
    5656    }
    57    
     57
    5858    LastTeamStanding::~LastTeamStanding()
    5959    {
    60     }   
     60    }
    6161
    6262    void LastTeamStanding::playerEntered(PlayerInfo* player)
     
    6969        else
    7070            playerLives_[player]=getMinLives();//new players only get minimum of lives */
    71        
     71
    7272        this->timeToAct_[player] = timeRemaining;
    7373        this->playerDelayTime_[player] = respawnDelay;
    7474        this->inGame_[player] = true;
    7575        unsigned int team = getTeam(player);
    76         if( team < 0|| team > teams_) // make sure getTeam returns a regular value
     76        if(team >= eachTeamsPlayers.size()) // make sure getTeam returns a regular value
    7777            return;
    7878        if(this->eachTeamsPlayers[team]==0) //if a player is the first in his group, a new team is alive
     
    9191            this->inGame_.erase(player);
    9292            unsigned int team = getTeam(player);
    93             if( team < 0|| team > teams_) // make sure getTeam returns a regular value
     93            if(team >= eachTeamsPlayers.size()) // make sure getTeam returns a regular value
    9494                return valid_player;
    9595            this->eachTeamsPlayers[team]--;       // a player left the team
     
    107107        bool allow = TeamDeathmatch::allowPawnDeath(victim, originator);
    108108        if(!allow) {return allow;}
    109        
     109
    110110        playerLives_[victim->getPlayer()] = playerLives_[victim->getPlayer()] - 1; //player lost a live
    111111        this->inGame_[victim->getPlayer()] = false; //if player dies, he isn't allowed to respawn immediately
     
    113113        {
    114114            unsigned int team = getTeam(victim->getPlayer());
    115             if(team < 0|| team > teams_) // make sure getTeam returns a regular value
     115            if(team >= eachTeamsPlayers.size()) // make sure getTeam returns a regular value
    116116                return allow;
    117117            this->eachTeamsPlayers[team]--;
     
    140140                const std::string& message = ""; // resets Camper-Warning-message
    141141                this->gtinfo_->sendFadingMessage(message,it->first->getClientID());
    142             }   
     142            }
    143143        }
    144144        return allow;
     
    163163            return;
    164164        TeamDeathmatch::playerStartsControllingPawn(player,pawn);
    165        
     165
    166166        this->timeToAct_[player] = timeRemaining + 3.0f + respawnDelay;//reset timer
    167167        this->playerDelayTime_[player] = respawnDelay;
    168        
     168
    169169        std::map<PlayerInfo*, Player>::iterator it = this->players_.find(player);
    170170        if (it != this->players_.end())
     
    174174            const std::string& message = ""; // resets Camper-Warning-message
    175175            this->gtinfo_->sendFadingMessage(message,it->first->getClientID());
    176         } 
     176        }
    177177    }
    178178
     
    187187            }
    188188            for (std::map<PlayerInfo*, float>::iterator it = this->timeToAct_.begin(); it != this->timeToAct_.end(); ++it)
    189             {   
     189            {
    190190                if (playerGetLives(it->first) <= 0)//Players without lives shouldn't be affected by time.
    191                     continue;     
     191                    continue;
    192192                it->second -= dt;//Decreases punishment time.
    193                 if (!inGame_[it->first])//Manages respawn delay - player is forced to respawn after the delaytime is used up. 
     193                if (!inGame_[it->first])//Manages respawn delay - player is forced to respawn after the delaytime is used up.
    194194                {
    195195                    playerDelayTime_[it->first] -= dt;
     
    309309            return 0;
    310310    }
    311    
     311
    312312    void LastTeamStanding::setConfigValues()
    313313    {
  • code/trunk/src/orxonox/graphics/Billboard.cc

    r7492 r8706  
    2323 *      Fabian 'x3n' Landau
    2424 *   Co-authors:
    25  *      ...
     25 *      Maurus Kaufmann
    2626 *
    2727 */
     
    3030
    3131#include "OgreBillboard.h"
    32 #include "OgreBillboardSet.h"
    3332
    3433#include "core/CoreIncludes.h"
     
    4645
    4746        this->colour_ = ColourValue::White;
    48         //this->rotation_ = 0;
     47        this->rotation_ = 0;
    4948
    5049        this->registerVariables();
     
    6665        XMLPortParam(Billboard, "material", setMaterial, getMaterial, xmlelement, mode);
    6766        XMLPortParam(Billboard, "colour",   setColour,   getColour,   xmlelement, mode).defaultValues(ColourValue::White);
    68         //XMLPortParam(Billboard, "rotation", setRotation, getRotation, xmlelement, mode).defaultValues(0);
     67        XMLPortParam(Billboard, "rotation", setRotation, getRotation, xmlelement, mode).defaultValues(0);
    6968    }
    7069
     
    7372        registerVariable(this->material_, VariableDirection::ToClient, new NetworkCallback<Billboard>(this, &Billboard::changedMaterial));
    7473        registerVariable(this->colour_,   VariableDirection::ToClient, new NetworkCallback<Billboard>(this, &Billboard::changedColour));
    75         //registerVariable(this->rotation_, VariableDirection::ToClient, new NetworkCallback<Billboard>(this, &Billboard::changedRotation));
     74        registerVariable(this->rotation_, VariableDirection::ToClient, new NetworkCallback<Billboard>(this, &Billboard::changedRotation));
    7675    }
    7776
     
    8988                     this->attachOgreObject(this->billboard_.getBillboardSet());
    9089                this->billboard_.setVisible(this->isVisible());
    91                 //this->changedRotation();
     90                this->changedRotation();
    9291            }
    9392        }
     
    114113    }
    115114
    116 /*
     115
    117116    void Billboard::changedRotation()
    118117    {
     
    128127        }
    129128    }
    130 */
     129
    131130
    132131    void Billboard::changedVisibility()
     
    136135        this->billboard_.setVisible(this->isVisible());
    137136    }
     137   
     138    void Billboard::setBillboardType(Ogre::BillboardType bbt)
     139    {
     140        Ogre::BillboardSet* bSet = this->billboard_.getBillboardSet();
     141        if( bSet != NULL )
     142        {
     143            bSet->setBillboardType(bbt);
     144        }
     145    }
     146   
     147    void Billboard::setCommonDirection(Vector3 vec)
     148    {
     149        Ogre::BillboardSet* bSet = this->billboard_.getBillboardSet();
     150        if( bSet != NULL )
     151        {
     152            bSet->setCommonDirection( vec );
     153        }
     154    }
     155           
     156    void Billboard::setCommonUpVector(Vector3 vec)
     157    {
     158        Ogre::BillboardSet* bSet = this->billboard_.getBillboardSet();
     159        if( bSet != NULL )
     160        {
     161            bSet->setCommonUpVector( vec );
     162        }
     163    }
     164   
     165    void Billboard::setDefaultDimensions(float width, float height)
     166    {
     167        Ogre::BillboardSet* bSet = this->billboard_.getBillboardSet();
     168        if( bSet != NULL )
     169        {
     170            bSet->setDefaultDimensions(width, height);
     171        }
     172    }
    138173}
  • code/trunk/src/orxonox/graphics/Billboard.h

    r7492 r8706  
    2323 *      Fabian 'x3n' Landau
    2424 *   Co-authors:
    25  *      ...
     25 *      Maurus Kaufmann
    2626 *
    2727 */
     
    3131
    3232#include "OrxonoxPrereqs.h"
     33
     34#include "OgreBillboardSet.h"
    3335
    3436#include "util/Math.h"
     
    6264                { return this->colour_; }
    6365
    64 /*
     66
    6567            inline void setRotation(const Radian& rotation)
    6668                { this->rotation_ = rotation; this->changedRotation(); }
    6769            inline const Radian& getRotation() const
    6870                { return this->rotation_; }
    69 */
     71
    7072
    7173            virtual void setTeamColour(const ColourValue& colour)
    7274                { this->setColour(colour); }
     75               
     76            void setBillboardType(Ogre::BillboardType bbt);
     77           
     78            void setCommonDirection(Vector3 vec); //!< normalised Vector vec as argument
     79           
     80            void setCommonUpVector(Vector3 vec); //!< normalised Vector vec as argument
     81           
     82            void setDefaultDimensions(float width, float height);
     83
    7384
    7485        protected:
     
    8192            void registerVariables();
    8293            void changedMaterial();
    83             //void changedRotation();
     94            void changedRotation();
    8495
    8596            BillboardSet billboard_;
    8697            std::string material_;
    8798            ColourValue colour_;
    88             //Radian rotation_;
     99            Radian rotation_;
    89100    };
    90101}
  • code/trunk/src/orxonox/graphics/Camera.cc

    r8079 r8706  
    7171        this->lastDtLagged_ = false;
    7272
    73         this->setSyncMode(0x0);
     73        this->setSyncMode(ObjectDirection::None);
    7474
    7575        this->setConfigValues();
  • code/trunk/src/orxonox/graphics/Camera.h

    r8079 r8706  
    4040namespace orxonox
    4141{
    42     class _OrxonoxExport Camera : public StaticEntity, public Tickable, public TimeFactorListener, public WindowEventListener
     42
     43    class _OrxonoxExport Camera : public StaticEntity, public Tickable,  public TimeFactorListener, public WindowEventListener
    4344    {
    4445        friend class CameraManager;
  • code/trunk/src/orxonox/infos/GametypeInfo.cc

    r8327 r8706  
    2323 *      Fabian 'x3n' Landau
    2424 *   Co-authors:
    25  *      ...
     25 *      Damian 'Mozork' Frick
    2626 *
    2727 */
     28
     29/**
     30    @file GametypeInfo.cc
     31    @brief Implementation of the GametypeInfo class
     32*/
    2833
    2934#include "GametypeInfo.h"
     
    3136#include "core/CoreIncludes.h"
    3237#include "core/GameMode.h"
     38#include "network/Host.h"
    3339#include "network/NetworkFunction.h"
    34 #include "network/Host.h"
     40#include "util/Convert.h"
     41
     42#include "controllers/HumanController.h"
    3543#include "interfaces/GametypeMessageListener.h"
     44#include "interfaces/NotificationListener.h"
     45
     46#include "PlayerInfo.h"
    3647
    3748namespace orxonox
     
    4556    registerMemberNetworkFunction(GametypeInfo, dispatchFadingMessage);
    4657
     58    registerMemberNetworkFunction(GametypeInfo, changedReadyToSpawn);
     59    registerMemberNetworkFunction(GametypeInfo, changedSpawned);
     60
     61    /*static*/ const std::string GametypeInfo::NOTIFICATION_SENDER("gameinfo");
     62
     63    /**
     64    @brief
     65        Registers and initializes the object.
     66    */
    4767    GametypeInfo::GametypeInfo(BaseObject* creator) : Info(creator)
    4868    {
    4969        RegisterObject(GametypeInfo);
    50 
     70       
    5171        this->bStarted_ = false;
    5272        this->bEnded_ = false;
    53         this->startCountdown_ = 0;
     73        this->startCountdown_ = 0.0f;
    5474        this->bStartCountdownRunning_ = false;
     75        this->counter_ = 0;
     76        this->spawned_ = false;
     77        this->readyToSpawn_ = false;
    5578
    5679        this->registerVariables();
     
    6386    void GametypeInfo::registerVariables()
    6487    {
    65         registerVariable(this->bStarted_,               VariableDirection::ToClient);
    66         registerVariable(this->bEnded_,                 VariableDirection::ToClient);
     88        registerVariable(this->bStarted_,               VariableDirection::ToClient, new NetworkCallback<GametypeInfo>(this, &GametypeInfo::changedStarted));
     89        registerVariable(this->bEnded_,                 VariableDirection::ToClient, new NetworkCallback<GametypeInfo>(this, &GametypeInfo::changedEnded));
     90        registerVariable(this->bStartCountdownRunning_, VariableDirection::ToClient, new NetworkCallback<GametypeInfo>(this, &GametypeInfo::changedStartCountdownRunning));
    6791        registerVariable(this->startCountdown_,         VariableDirection::ToClient);
    68         registerVariable(this->bStartCountdownRunning_, VariableDirection::ToClient);
     92        registerVariable(this->counter_,                VariableDirection::ToClient, new NetworkCallback<GametypeInfo>(this, &GametypeInfo::changedCountdownCounter));
    6993        registerVariable(this->hudtemplate_,            VariableDirection::ToClient);
    7094    }
     95
     96    /**
     97    @brief
     98        Is called when the game has changed to started.
     99    */
     100    void GametypeInfo::changedStarted(void)
     101    {
     102        NotificationListener::sendCommand("clear", GametypeInfo::NOTIFICATION_SENDER);
     103    }
     104
     105    /**
     106    @brief
     107        Is called when the game has changed to ended.
     108    */
     109    void GametypeInfo::changedEnded(void)
     110    {
     111        // If the game has ended, a "Game has ended" notification is displayed.
     112        if(this->hasEnded())
     113            NotificationListener::sendNotification("Game has ended", GametypeInfo::NOTIFICATION_SENDER);
     114    }
     115
     116    /**
     117    @brief
     118        Is called when the start countdown has been either started or stopped.
     119    */
     120    void GametypeInfo::changedStartCountdownRunning(void)
     121    {
     122        // Send first countdown notification if the countdown has started.
     123        if(this->isReadyToSpawn() && !this->hasStarted() && this->isStartCountdownRunning() && !this->hasEnded())
     124            NotificationListener::sendNotification(multi_cast<std::string>(this->counter_), GametypeInfo::NOTIFICATION_SENDER);
     125    }
     126
     127    /**
     128    @brief
     129        Is called when the start countdown counter has changed.
     130    */
     131    void GametypeInfo::changedCountdownCounter(void)
     132    {
     133        // Send countdown notification if the counter has gone down.
     134        if(this->isReadyToSpawn() &&  !this->hasStarted() && this->isStartCountdownRunning() && !this->hasEnded())
     135            NotificationListener::sendNotification(multi_cast<std::string>(this->counter_), GametypeInfo::NOTIFICATION_SENDER);
     136    }
     137
     138    /**
     139    @brief
     140        Inform the GametypeInfo that the local player has changed its ready to spawn status.
     141    @param ready
     142        Whether the player has become ready to spawn or not.
     143    */
     144    void GametypeInfo::changedReadyToSpawn(bool ready)
     145    {
     146        if(this->readyToSpawn_ == ready)
     147            return;
     148
     149        this->readyToSpawn_ = ready;
     150
     151        // Send "Waiting for other players" if the player is ready to spawn but the game has not yet started nor is the countdown running.
     152        if(this->readyToSpawn_ && !this->hasStarted() && !this->isStartCountdownRunning() && !this->hasEnded())
     153            NotificationListener::sendNotification("Waiting for other players", GametypeInfo::NOTIFICATION_SENDER);
     154        // Send current countdown if the player is ready to spawn and the countdown has already started.
     155        else if(this->readyToSpawn_ && !this->hasStarted() && this->isStartCountdownRunning() && !this->hasEnded())
     156            NotificationListener::sendNotification(multi_cast<std::string>(this->counter_), GametypeInfo::NOTIFICATION_SENDER);
     157    }
     158
     159    /**
     160    @brief
     161        Inform the GametypeInfo that the game has started.
     162    */
     163    void GametypeInfo::start(void)
     164    {
     165        if(this->bStarted_)
     166            return;
     167       
     168        this->bStarted_ = true;
     169        this->changedStarted();
     170    }
     171
     172    /**
     173    @brief
     174        Inform the GametypeInfo that the game has ended.
     175    */
     176    void GametypeInfo::end(void)
     177    {
     178        if(this->bEnded_)
     179            return;
     180
     181        this->bEnded_ = true;
     182        this->changedEnded();
     183    }
     184
     185    /**
     186    @brief
     187        Set the start countdown to the input value.
     188    @param countdown
     189        The countdown to be set.
     190    */
     191    void GametypeInfo::setStartCountdown(float countdown)
     192    {
     193        if(this->startCountdown_ == countdown || countdown < 0.0f)
     194            return;
     195       
     196        this->startCountdown_ = countdown;
     197        // Set the counter to the ceiling of the current countdown.
     198        this->counter_ = std::ceil(countdown);
     199        this->changedCountdownCounter();
     200    }
     201
     202    /**
     203    @brief
     204        Count down the start countdown by the specified value.
     205    @param countDown
     206        The amount by which we count down.
     207    */
     208    void GametypeInfo::countdownStartCountdown(float countDown)
     209    {
     210        float newCountdown = this->startCountdown_ - countDown;
     211        // If we have switched integers or arrived at zero, we also count down the start countdown counter.
     212        if(ceil(newCountdown) != ceil(this->startCountdown_) || newCountdown <= 0.0f)
     213            this->countDown();
     214        this->startCountdown_ = newCountdown;
     215    }
     216
     217    /**
     218    @brief
     219        Count down the start countdown counter.
     220    */
     221    void GametypeInfo::countDown()
     222    {
     223        if(this->counter_ == 0)
     224            return;
     225       
     226        this->counter_--;
     227        this->changedCountdownCounter();
     228    }
     229
     230    /**
     231    @brief
     232        Inform the GametypeInfo about the start of the start countdown.
     233    */
     234    void GametypeInfo::startStartCountdown(void)
     235    {
     236        if(GameMode::isMaster())
     237        {
     238            if(this->bStartCountdownRunning_)
     239                return;
     240
     241            this->bStartCountdownRunning_ = true;
     242            this->changedStartCountdownRunning();
     243        }
     244    }
     245
     246    /**
     247    @brief
     248        Inform the GametypeInfo about the stop of the start countdown.
     249    */
     250    void GametypeInfo::stopStartCountdown(void)
     251    {
     252        if(GameMode::isMaster())
     253        {
     254            if(!this->bStartCountdownRunning_)
     255                return;
     256
     257            this->bStartCountdownRunning_ = false;
     258            this->changedStartCountdownRunning();
     259        }
     260    }
     261
     262    /**
     263    @brief
     264        Inform the GametypeInfo about a player that is ready to spawn.
     265    @param player
     266        The player that is ready to spawn.
     267    */
     268    void GametypeInfo::playerReadyToSpawn(PlayerInfo* player)
     269    {
     270        if(GameMode::isMaster())
     271        {
     272            // If the player has spawned already.
     273            if(this->spawnedPlayers_.find(player) != this->spawnedPlayers_.end())
     274                return;
     275
     276            this->spawnedPlayers_.insert(player);
     277            this->setReadyToSpawnHelper(player, true);
     278        }
     279    }
     280
     281    /**
     282    @brief
     283        Inform the GametypeInfo about a player whose Pawn has been killed.
     284    @param player
     285        The player whose Pawn has been killed.
     286    */
     287    void GametypeInfo::pawnKilled(PlayerInfo* player)
     288    {
     289        if(GameMode::isMaster())
     290        {
     291            NotificationListener::sendNotification("Press [Fire] to respawn", GametypeInfo::NOTIFICATION_SENDER, notificationMessageType::info, notificationSendMode::network, player->getClientID());
     292            // Remove the player from the list of players that have spawned, since it currently is not.
     293            this->spawnedPlayers_.erase(player);
     294            this->setReadyToSpawnHelper(player, false);
     295            this->setSpawnedHelper(player, false);
     296        }
     297    }
     298
     299    /**
     300    @brief
     301        Inform the GametypeInfo about a player that has spawned.
     302    @param player
     303        The player that has spawned.
     304    */
     305    void GametypeInfo::playerSpawned(PlayerInfo* player)
     306    {
     307        if(GameMode::isMaster())
     308        {
     309            if(this->hasStarted() && !this->hasEnded())
     310
     311                this->setSpawnedHelper(player, true);
     312        }
     313    }
     314
     315    /**
     316    @brief
     317        Inform the GametypeInfo that the local player has changed its spawned status.
     318    @param spawned
     319        Whether the local player has changed to spawned or to not spawned.
     320    */
     321    void GametypeInfo::changedSpawned(bool spawned)
     322    {
     323        if(this->spawned_ == spawned)
     324            return;
     325       
     326        this->spawned_ = spawned;
     327        // Clear the notifications if the Player has spawned.
     328        if(this->spawned_ && !this->hasEnded())
     329            NotificationListener::sendCommand("clear", GametypeInfo::NOTIFICATION_SENDER);
     330    }
     331
     332    /**
     333    @brief
     334        Inform the GametypeInfo about a player that has entered,
     335    @param player
     336        The player that has entered.
     337    */
     338    void GametypeInfo::playerEntered(PlayerInfo* player)
     339    {
     340        if(GameMode::isMaster())
     341        {
     342            if( player->isHumanPlayer() )
     343            {
     344                // Display "Press [Fire] to start the match" if the game has not yet ended.
     345                if(!this->hasEnded())
     346                    NotificationListener::sendNotification("Press [Fire] to start the match", GametypeInfo::NOTIFICATION_SENDER, notificationMessageType::info, notificationSendMode::network, player->getClientID());
     347                // Else display "Game has ended".
     348                else
     349                    NotificationListener::sendNotification("Game has ended", GametypeInfo::NOTIFICATION_SENDER, notificationMessageType::info, notificationSendMode::network, player->getClientID());
     350            }
     351        }
     352    }
     353
     354    /**
     355    @brief
     356        Helper method. Sends changedReadyToSpawn notifiers over the network.
     357    @param player
     358        The player that has changed its ready to spawn status.
     359    @param ready
     360        The new ready to spawn status.
     361    */
     362    void GametypeInfo::setReadyToSpawnHelper(PlayerInfo* player, bool ready)
     363    {
     364        if(GameMode::isMaster())
     365        {
     366            if(player->getClientID() == CLIENTID_SERVER)
     367                this->changedReadyToSpawn(ready);
     368            else
     369                callMemberNetworkFunction(GametypeInfo, changedReadyToSpawn, this->getObjectID(), player->getClientID(), ready);
     370        }
     371    }
     372
     373    /**
     374    @brief
     375        Helper method. Sends changedSpawned notifiers over the network.
     376    @param player
     377        The player that has changed its spawned status.
     378    @param ready
     379        The new spawned status.
     380    */
     381    void GametypeInfo::setSpawnedHelper(PlayerInfo* player, bool spawned)
     382    {
     383        if(GameMode::isMaster())
     384        {
     385            if(player->getClientID() == CLIENTID_SERVER)
     386                    this->changedSpawned(spawned);
     387            else
     388                callMemberNetworkFunction(GametypeInfo, changedSpawned, this->getObjectID(), player->getClientID(), spawned);
     389        }
     390    }
     391
     392    // Announce messages.
     393    // TODO: Replace with notifications.
    71394
    72395    void GametypeInfo::sendAnnounceMessage(const std::string& message)
  • code/trunk/src/orxonox/infos/GametypeInfo.h

    r7163 r8706  
    2323 *      Fabian 'x3n' Landau
    2424 *   Co-authors:
    25  *      ...
     25 *      Damian 'Mozork' Frick
    2626 *
    2727 */
     28
     29/**
     30    @file GametypeInfo.h
     31    @brief Definition of the GametypeInfo class
     32*/
    2833
    2934#ifndef _GametypeInfo_H__
     
    3338
    3439#include <string>
     40
    3541#include "Info.h"
    3642
    3743namespace orxonox
    3844{
     45
     46    /**
     47    @brief
     48        The GametypeInfo class keeps track of the state of the game and provides facilities to inform the player about it.
     49
     50    @author
     51        Fabian 'x3n' Landau
     52    @author
     53        Damian 'Mozork' Frick
     54    */
    3955    class _OrxonoxExport GametypeInfo : public Info
    4056    {
     
    4561            virtual ~GametypeInfo();
    4662
     63            /**
     64            @brief Get whether the game has started yet.
     65            @return Returns true if the game has started, false if not.
     66            */
    4767            inline bool hasStarted() const
    4868                { return this->bStarted_; }
     69            void changedStarted(void); // Is called when the game has changed to started.
     70           
     71            /**
     72            @brief Get whether the game has ended yet.
     73            @return Returns true if the game has ended, false if not.
     74            */
    4975            inline bool hasEnded() const
    5076                { return this->bEnded_; }
     77            void changedEnded(void); // Is called when the game has changed to ended.
    5178
     79            /**
     80            @brief Get whether the start countdown is currently running.
     81            @return Returns true if the countdown is running, false if not.
     82            */
    5283            inline bool isStartCountdownRunning() const
    5384                { return this->bStartCountdownRunning_; }
     85            void changedStartCountdownRunning(void); // Is called when the start countdown has been either started or stopped.
     86
     87            /**
     88            @brief Get the current value of the start countdown.
     89            @return Returns the current value of the start countdown.
     90            */
    5491            inline float getStartCountdown() const
    5592                { return this->startCountdown_; }
     93
     94            /**
     95            @brief Get the current start countdown counter.
     96                   The start countdown counter only has integer values that correspond to the actually displayed countdown.
     97            @return Returns the current integer countdown counter.
     98            */
     99            inline unsigned int getStartCountdownCounter() const
     100                { return this->counter_; }
     101            void changedCountdownCounter(void); // Is called when the start countdown counter has changed.
     102
     103            /**
     104            @brief Get whether the local player is ready to spawn.
     105            @return Returns true if the player is ready to spawn, false if not.
     106            */
     107            inline bool isReadyToSpawn() const
     108                { return this->readyToSpawn_; }
     109            void changedReadyToSpawn(bool ready); // Inform the GametypeInfo that the local player has changed its spawned status.
     110           
     111            /**
     112            @brief Get whether the local player is spawned.
     113            @return Returns true if the local player is currently spawned, false if not.
     114            */
     115            inline bool isSpawned() const
     116                { return this->spawned_; }
     117            void changedSpawned(bool spawned); // Inform the GametypeInfo that the local player has changed its spawned status.
    56118
    57119            inline const std::string& getHUDTemplate() const
     
    70132            void dispatchStaticMessage(const std::string& message,const ColourValue& colour);
    71133            void dispatchFadingMessage(const std::string& message);
     134           
     135        protected:
     136            void start(void); // Inform the GametypeInfo that the game has started.
     137            void end(void); // Inform the GametypeInfo that the game has ended.
     138            void setStartCountdown(float countdown); // Set the start countdown to the input value.
     139            void countdownStartCountdown(float countDown); // Count down the start countdown by the specified value.
     140            void countDown(); // Count down the start countdown counter.
     141            void startStartCountdown(void); // Inform the GametypeInfo about the start of the start countdown.
     142            void stopStartCountdown(void); // Inform the GametypeInfo about the stop of the start countdown.
     143            void playerReadyToSpawn(PlayerInfo* player); // Inform the GametypeInfo about a player that is ready to spawn.
     144            void pawnKilled(PlayerInfo* player); // Inform the GametypeInfo about a player whose Pawn has been killed.
     145            void playerSpawned(PlayerInfo* player); // Inform the GametypeInfo about a player that has spawned.
     146            void playerEntered(PlayerInfo* player); // Inform the GametypeInfo about a player that has entered,
     147
     148            inline void setHUDTemplate(const std::string& templateName)
     149                { this->hudtemplate_ = templateName; };
    72150
    73151        private:
    74152            void registerVariables();
     153            void setSpawnedHelper(PlayerInfo* player, bool spawned); // Helper method. Sends changedReadyToSpawn notifiers over the network.
     154            void setReadyToSpawnHelper(PlayerInfo* player, bool ready); // Helper method. Sends changedSpawned notifiers over the network.
    75155
    76             bool bStarted_;
    77             bool bEnded_;
    78             bool bStartCountdownRunning_;
    79             float startCountdown_;
     156            static const std::string NOTIFICATION_SENDER; //!< The name of the sender for the sending of notifications.
     157
     158            bool bStarted_; //!< Whether the game has started,
     159            bool bEnded_; //!< Whether the game has ended.
     160            bool bStartCountdownRunning_; //!< Whether the start countdown is running.
     161            float startCountdown_; //!< The current value of the start countdown.
     162            unsigned int counter_; //!< The current integer value of the start countdown, the start countdown counter.
    80163            std::string hudtemplate_;
     164           
     165            std::set<PlayerInfo*> spawnedPlayers_; //!< A set of players that are currently spawned.
     166            bool spawned_; //!< Whether the local Player is currently spawned.
     167            bool readyToSpawn_; //!< Whether the local Player is ready to spawn.
    81168    };
    82169}
  • code/trunk/src/orxonox/infos/PlayerInfo.cc

    r8327 r8706  
    5151        this->controllableEntity_ = 0;
    5252        this->controllableEntityID_ = OBJECTID_UNKNOWN;
    53         this->oldControllableEntity_ = 0;
    5453
    5554        this->gtinfo_ = 0;
     
    151150            return;
    152151
    153         if (this->oldControllableEntity_)
     152        while (this->previousControllableEntity_.size() > 0)
    154153            this->stopTemporaryControl();
     154       
    155155        if (this->controllableEntity_)
    156156            this->stopControl();
     
    177177            return;
    178178
    179         assert( this->oldControllableEntity_==0 );
    180 
    181         this->oldControllableEntity_ = this->controllableEntity_;
     179        this->controllableEntity_->destroyHud(); // HACK-ish
     180        this->previousControllableEntity_.push_back(WeakPtr<ControllableEntity>(this->controllableEntity_));
    182181        this->controllableEntity_ = entity;
    183182        this->controllableEntityID_ = entity->getObjectID();
     
    194193    void PlayerInfo::stopControl()
    195194    {
    196         if ( this->oldControllableEntity_ )
     195        while ( this->previousControllableEntity_.size() > 0)
    197196            this->stopTemporaryControl();
    198197
     
    215214    }
    216215
     216    void PlayerInfo::pauseControl()
     217    {
     218        ControllableEntity* entity = this->controllableEntity_;
     219
     220        if (!entity)
     221            return;
     222
     223        this->controllableEntity_->getController()->setActive(false);
     224        //this->controllableEntity_->getController()->setControllableEntity(NULL);
     225        this->controllableEntity_->setController(0);
     226    }
     227
    217228    void PlayerInfo::stopTemporaryControl()
    218229    {
    219230        ControllableEntity* entity = this->controllableEntity_;
    220231
    221         assert( this->controllableEntity_ && this->oldControllableEntity_ );
    222         if( !entity || !this->oldControllableEntity_ )
     232        assert(this->controllableEntity_ != NULL);
     233        if( !entity || this->previousControllableEntity_.size() == 0 )
    223234            return;
    224235
    225236        this->controllableEntity_->setController(0);
     237        this->controllableEntity_->destroyHud(); // HACK-ish
    226238       
    227         this->controllableEntity_ = this->oldControllableEntity_;
     239//        this->controllableEntity_ = this->previousControllableEntity_.back();
     240        do {
     241            this->controllableEntity_ = this->previousControllableEntity_.back();
     242        } while(this->controllableEntity_ == NULL && this->previousControllableEntity_.size() > 0);
    228243        this->controllableEntityID_ = this->controllableEntity_->getObjectID();
    229         this->oldControllableEntity_ = 0;
    230 
    231         if ( this->controllableEntity_ && this->controller_)
     244        this->previousControllableEntity_.pop_back();
     245
     246        if ( this->controllableEntity_ != NULL && this->controller_ != NULL)
    232247            this->controller_->setControllableEntity(this->controllableEntity_);
     248
     249         // HACK-ish
     250        if(this->controllableEntity_ != NULL)
     251            this->controllableEntity_->createHud();
    233252
    234253        if ( GameMode::isMaster() )
  • code/trunk/src/orxonox/infos/PlayerInfo.h

    r7163 r8706  
    6868            void startControl(ControllableEntity* entity);
    6969            void stopControl();
     70            void pauseControl();
    7071            void startTemporaryControl(ControllableEntity* entity);
    7172            void stopTemporaryControl();
     
    9899            Controller* controller_;
    99100            ControllableEntity* controllableEntity_;
    100             ControllableEntity* oldControllableEntity_;
     101            std::vector< WeakPtr<ControllableEntity> > previousControllableEntity_; //!< List of the previous ControllableEntities if repeatedly startTemporary control was called. The ControllableEntity at the back is the most recent.
    101102            unsigned int controllableEntityID_;
    102103
  • code/trunk/src/orxonox/interfaces/CMakeLists.txt

    r7504 r8706  
    11ADD_SOURCE_FILES(ORXONOX_SRC_FILES
    22  InterfaceCompilation.cc
     3  NotificationListener.cc
    34  Pickupable.cc
    45  PickupCarrier.cc
  • code/trunk/src/orxonox/interfaces/InterfaceCompilation.cc

    r7606 r8706  
    4242#include "core/CoreIncludes.h"
    4343
     44#include "infos/PlayerInfo.h"
     45#include "worldentities/pawns/Pawn.h"
     46
    4447namespace orxonox
    4548{
     
    5962        RegisterRootObject(PlayerTrigger);
    6063
    61         this->player_ = NULL;
    6264        this->isForPlayer_ = false;
     65    }
     66
     67    void PlayerTrigger::setTriggeringPawn(Pawn* pawn)
     68    {
     69        assert(pawn);
     70        this->pawn_ = WeakPtr<Pawn>(pawn);
     71        if (pawn)
     72            this->player_ = WeakPtr<PlayerInfo>(pawn->getPlayer());
    6373    }
    6474
     
    8696        RegisterRootObject(Rewardable);
    8797    }
    88 
    89     //----------------------------
    90     // NotificationListener
    91     //----------------------------
    92     NotificationListener::NotificationListener()
    93     {
    94         RegisterRootObject(NotificationListener);
    95     }
    9698}
  • code/trunk/src/orxonox/interfaces/NotificationListener.h

    r7552 r8706  
    2121 *
    2222 *   Author:
    23  *      Fabian 'x3n' Landau
     23 *      Damian 'Mozork' Frick
    2424 *   Co-authors:
    2525 *      ...
     
    4848namespace orxonox
    4949{
    50     class Notification;
     50    // TODO: Document.
     51    namespace notificationMessageType
     52    {
     53        enum Value {
     54            info,
     55            important
     56        };
     57    }
     58   
     59    namespace notificationSendMode
     60    {
     61        enum Value {
     62            local,
     63            network,
     64            broadcast
     65        };
     66    }
     67   
     68    namespace notificationCommand
     69    {
     70        enum Value {
     71            none,
     72            clear
     73        };
     74    }
    5175
     76    // TODO: Update doc.
    5277    /**
    5378    @brief
    5479        NotificationListener interface.
    5580
    56         The NotificationListener interface presents a means to being informed when @ref orxonox::Notification "Notifications" in the target set of this NotificationListener change. (e.g. @ref orxonox::Notification "Notifications" were added or removed)
    57         When inheriting from a NotificationListener it is important to register (in the constructor) and unregister (in the destructor) it to and from the @ref orxonox::NotificationManager "NotificationManager".
     81        The NotificationListener interface (or more precisely abstract class) presents a means of being informed when a new @ref orxonox::Notification "Notification" is sent.
     82        The NotificationListener can be used to send a new notification message (with NotificationListener::sendNotification() ) or a new notification command (with NotificationListener::sendCommand() ). Each NotificationListener is then informed about the new @ref orxonox::Notification "Notification" and can take appropriate action. Currently the only NotificationListener ist the @ref orxonox::NotificationManager "NotificationManager" singleton.
     83
     84        When inheriting from a NotificationListener it is important to provide an appropriate implementation of registerNotification() and executeCommand().
    5885
    5986    @author
    60         Fabian 'x3n' Landau
    61 
     87        Damian 'Mozork' Frick
     88       
    6289    @ingroup Notifications
     90    @todo Consistent terminology between message, notification and command.
    6391    */
    6492    class _OrxonoxExport NotificationListener : virtual public OrxonoxClass
     
    6997
    7098            /**
    71             @brief Get the senders that are targets of this NotificationListener.
    72             @return Returns the set of senders that are targets of this NotificationListener.
     99            @brief Sends a Notification with the specified message to the specified client from the specified sender.
     100            @param message The message that should be sent.
     101            @param sender The sender that sent the notification. Default is 'none'.
     102            @param messageType The type of the message, can be either 'info' or 'important'. Default is 'info'.
     103            @param sendMode The mode in which the notification is sent, can be 'local' to send the notification to the client where this function is executed, 'network' if the notification is to be sent to the client with the specified clientID, or 'broadcast' if the notification should be sent to all hosts. Default is notificationSendMode::local.
     104            @param clientId The id of the client the notification should be sent to. Default is 0.
    73105            */
    74             virtual const std::set<std::string> & getTargetsSet(void) = 0;
     106            static void sendNotification(const std::string& message, const std::string& sender = NotificationListener::NONE, notificationMessageType::Value messageType = notificationMessageType::info, notificationSendMode::Value sendMode = notificationSendMode::local, unsigned int clientId = 0)
     107                { NotificationListener::sendNetworkHelper(message, sender, sendMode, clientId, false, messageType); }
     108            /**
     109            @brief Sends a specified command to the specified client from the specified sender.
     110            @param command The command that should be sent (and later executed).
     111            @param sender The sender that sent the notification. Default is 'none'.
     112            @param sendMode The mode in which the command is sent, can be 'local' to send the command to the client where this function is executed, 'network' if the command is to be sent to the client with the specified clientID, or 'broadcast' if the command should be sent to all hosts. Default is notificationSendMode::local.
     113            @param clientId The id of the client the command should be sent to. Default is 0.
     114            */
     115            static void sendCommand(const std::string& command, const std::string& sender = NotificationListener::NONE, notificationSendMode::Value sendMode = notificationSendMode::local, unsigned int clientId = 0)
     116                { NotificationListener::sendNetworkHelper(command, sender, sendMode, clientId, true); }
    75117
     118            static void sendHelper(const std::string& message, const std::string& sender, bool isCommand = false, unsigned int messageMode = 0); // Helper method to register a notification/execute a command with all NotificationListeners after it has been sent over the network.
     119
     120            //TODO: Make protected?
     121           
    76122            /**
    77             @brief Updates the whole NotificationListener.
    78                    This is called by the @ref orxonox::NotificationManager "NotificationManager" when the @ref orxonox::Notification "Notifications" have changed so much, that the NotificationListener may have to re-initialize his operations.
     123            @brief Registers a notification with the NotificationListener.
     124                   This needs to be overloaded by each class inheriting from NotificationListener.
     125            @param message The notification's message.
     126            @param sender The sender of the notification.
     127            @param type The type of the notification.
     128            @return Returns true if the notification was successfully registered, false if not.
    79129            */
    80             virtual void update(void) = 0;
     130            virtual bool registerNotification(const std::string& message, const std::string& sender, notificationMessageType::Value type)
     131                { return false; }
    81132            /**
    82             @brief Updates the NotificationListener, when a new Notification has come in at the specified time.
    83             @param notification A pointer to the @ref orxonox::Notification "Notification".
    84             @param time The time the @ref orxonox::Notification "Notification" has come in.
     133            @brief Executes a command with the NotificationListener
     134                   This needs to be overloaded by each class inheriting from NotificationListener.
     135            @param command The command to be executed.
     136            @param sender The sender of the command.
     137            @return Returns true if the command was successfully executed, false if not.
    85138            */
    86             virtual void update(Notification* notification, const std::time_t & time) = 0;
     139            virtual bool executeCommand(notificationCommand::Value command, const std::string& sender) { return false; }
     140
     141        public:
     142           
     143            static const std::string ALL; //!< Static string to indicate a sender that sends to all NotificationQueues.
     144            static const std::string NONE; //!< Static string to indicate a sender that sends to no specific NotificationQueues.
     145           
     146            //! Commands
     147            static const std::string COMMAND_CLEAR;
     148            static const std::string COMMAND_NONE;
     149           
     150        protected:
     151            static void sendNetworkHelper(const std::string& message, const std::string& sender, notificationSendMode::Value sendMode, unsigned int clientId, bool isCommand = false, notificationMessageType::Value messageType = notificationMessageType::info); // Helper method to send both notifications and commands over the network.
     152
     153            static notificationCommand::Value str2Command(const std::string& string); // Helper method. Converts a string into the enum for a command.
     154            static const std::string& command2Str(notificationCommand::Value command); // Helper method. Converts a command enum into its corresponding string.
    87155    };
    88156}
  • code/trunk/src/orxonox/interfaces/PlayerTrigger.h

    r7601 r8706  
    3939
    4040#include "core/OrxonoxClass.h"
     41#include "core/WeakPtr.h"
    4142
    4243namespace orxonox
     
    4445    /**
    4546    @brief
    46         PlayerTrigger is an interface if implemented by a specific trigger can be used to recover the Player (or more precisely the @ref orxonox::Pawn "Pawn") that triggered it.
     47        PlayerTrigger is an interface if implemented by a specific trigger can be used to recover the Player (or the @ref orxonox::Pawn "Pawn") that triggered it.
    4748
    4849    @author
     
    5859
    5960        /**
    60         @brief Returns the player that triggered the PlayerTrigger.
     61        @brief Returns the Pawn that triggered the PlayerTrigger.
    6162        @return Returns a pointer to the Pawn that triggered the PlayerTrigger.
    6263        */
    63         inline Pawn* getTriggeringPlayer(void) const
     64        inline Pawn* getTriggeringPawn(void) const
     65            { return this->pawn_.get(); }
     66
     67        /**
     68        @brief Returns the player that triggered the PlayerTrigger.
     69        @return Returns a pointer to the PlayerInfo that triggered the PlayerTrigger.
     70        */
     71        inline PlayerInfo* getTriggeringPlayer(void) const
    6472            { return this->player_; }
    6573
    6674        /**
    67         @brief Checks whether the PlayerTrigger normally returns a Pawn.
    68         @return Returns true if the PlayerTrigger normally returns a Pawn.
     75        @brief Checks whether the PlayerTrigger normally returns a Pawn/PlayerInfo.
     76        @return Returns true if the PlayerTrigger normally returns a Pawn/PlayerInfo.
    6977        */
    7078        inline bool isForPlayer(void) const
     
    7684        @param player A pointer to the Pawn that triggered the PlayerTrigger.
    7785        */
    78         inline void setTriggeringPlayer(Pawn* player)
    79            { this->player_ = player; }
     86        void setTriggeringPawn(Pawn* pawn);
    8087
    8188        /**
     
    8794
    8895    private:
    89         Pawn* player_; //!< The player that triggered the PlayerTrigger.
     96        WeakPtr<PlayerInfo> player_; //!< The player that triggered the PlayerTrigger.
     97        WeakPtr<Pawn> pawn_; //!< The Pawn that triggered the PlayerTrigger.
    9098        bool isForPlayer_; //!< Is true when the PlayerTrigger should be set to normally be triggered by Pawns.
    9199
  • code/trunk/src/orxonox/items/Engine.cc

    r8079 r8706  
    3535#include "Scene.h"
    3636#include "worldentities/pawns/SpaceShip.h"
    37 #include "tools/Shader.h"
     37#include "core/Template.h"
    3838
    3939namespace orxonox
     
    4747        this->ship_ = 0;
    4848        this->shipID_ = OBJECTID_UNKNOWN;
     49        this->relativePosition_ = Vector3(0,0,0);
    4950
    5051        this->boostFactor_ = 1.5;
     
    6263        this->accelerationUpDown_ = 0.0;
    6364
    64         this->boostBlur_ = 0;
    65 
    6665        this->speedAdd_ = 0.0;
    6766        this->speedMultiply_ = 1.0;
     
    7372    Engine::~Engine()
    7473    {
    75         if (this->isInitialized() && this->ship_)
    76         {
    77             this->ship_->setEngine(0);
    78 
    79             if (this->boostBlur_)
    80                 this->boostBlur_->destroy();
     74        if (this->isInitialized())
     75        {
     76            if (this->ship_ && this->ship_->hasEngine(this))
     77                this->ship_->removeEngine(this);
    8178        }
    8279    }
     
    9895        XMLPortParam(Engine, "accelerationleftright", setAccelerationLeftRight, setAccelerationLeftRight, xmlelement, mode);
    9996        XMLPortParam(Engine, "accelerationupdown",    setAccelerationUpDown,    setAccelerationUpDown,    xmlelement, mode);
     97
     98        XMLPortParam(Engine, "position", setRelativePosition, getRelativePosition, xmlelement, mode);
     99        XMLPortParam(Engine, "template", setEngineTemplate, getEngineTemplate, xmlelement, mode);
    100100    }
    101101
    102102    void Engine::setConfigValues()
    103103    {
    104         SetConfigValueExternal(bEnableMotionBlur_, "GraphicsSettings", "enableMotionBlur", true)
    105             .description("Enable or disable the motion blur effect when moving very fast")
    106             .callback(this, &Engine::changedEnableMotionBlur);
    107         SetConfigValueExternal(blurStrength_, "GraphicsSettings", "blurStrength", 3.0f)
    108             .description("Defines the strength of the motion blur effect");
    109104    }
    110105
     
    163158        SUPER(Engine, tick, dt);
    164159
    165         const Vector3& direction = this->getDirection();
     160        Vector3 direction = this->getDirection();
     161        float directionLength = direction.length();
     162        if (directionLength > 1.0f)
     163            direction /= directionLength; // normalize
     164       
    166165        Vector3 velocity = this->ship_->getLocalVelocity();
    167166        Vector3 acceleration = Vector3::ZERO;
     
    202201        }
    203202
    204         this->ship_->setAcceleration(this->ship_->getOrientation() * (acceleration*this->getSpeedMultiply()+Vector3(0,0,-this->getSpeedAdd())));
    205 
    206         if (!this->ship_->getPermanentBoost())
    207             this->ship_->setBoost(false);
    208         this->ship_->setSteeringDirection(Vector3::ZERO);
    209 
    210         if (this->bEnableMotionBlur_ && !this->boostBlur_ && this->ship_->hasLocalController() && this->ship_->hasHumanController())
    211         {
    212             this->boostBlur_ = new Shader(this->ship_->getScene()->getSceneManager());
    213             this->boostBlur_->setCompositorName("Radial Blur");
    214         }
    215 
    216         if (this->boostBlur_ && this->maxSpeedFront_ != 0 && this->boostFactor_ != 1)
    217         {
    218             float blur = this->blurStrength_ * clamp((-velocity.z - this->maxSpeedFront_) / ((this->boostFactor_ - 1) * this->maxSpeedFront_), 0.0f, 1.0f);
    219 
    220             this->boostBlur_->setVisible(blur > 0);
    221             this->boostBlur_->setParameter(0, 0, "sampleStrength", blur);
     203        // NOTE: Bullet always uses global coordinates.
     204        this->ship_->addAcceleration(this->ship_->getOrientation() * (acceleration*this->getSpeedMultiply()+Vector3(0,0,-this->getSpeedAdd())), this->ship_->getOrientation() * this->relativePosition_);
     205
     206        // Hack to reset a temporary variable "direction"
     207        this->ship_->oneEngineTickDone();
     208        if(!this->ship_->hasEngineTicksRemaining())
     209        {
     210            this->ship_->setSteeringDirection(Vector3::ZERO);
     211            this->ship_->resetEngineTicks();
    222212        }
    223213    }
     
    226216    {
    227217        SUPER(Engine, changedActivity);
    228 
    229         if (this->boostBlur_)
    230             this->boostBlur_->setVisible(this->isVisible());
    231218    }
    232219
     
    238225        {
    239226            this->shipID_ = ship->getObjectID();
    240             if (ship->getEngine() != this)
    241                 ship->setEngine(this);
    242 
    243             if (this->boostBlur_)
    244             {
    245                 this->boostBlur_->destroy();
    246                 this->boostBlur_ = 0;
    247             }
     227            if (!ship->hasEngine(this))
     228                ship->addEngine(this);
    248229        }
    249230    }
     
    267248    }
    268249
    269     void Engine::changedEnableMotionBlur()
    270     {
    271         if (!this->bEnableMotionBlur_)
    272         {
    273             this->boostBlur_->destroy();
    274             this->boostBlur_ = 0;
     250    void Engine::loadEngineTemplate()
     251    {
     252        if(!this->engineTemplate_.empty())
     253        {
     254            COUT(4)<<"Loading an engine template: "<<this->engineTemplate_<<"\n";
     255            Template *temp = Template::getTemplate(this->engineTemplate_);
     256            if(temp)
     257            {
     258                this->addTemplate(temp);
     259            }
    275260        }
    276261    }
  • code/trunk/src/orxonox/items/Engine.h

    r8079 r8706  
    5454            inline SpaceShip* getShip() const
    5555                { return this->ship_; }
     56
     57            inline void setRelativePosition(const Vector3 &position)
     58                { this->relativePosition_ = position; }
     59            inline Vector3& getRelativePosition()
     60                { return this->relativePosition_; }
    5661
    5762            inline void setBoostFactor(float factor)
     
    119124                { this->speedMultiply_=speedMultiply; }
    120125
     126           
     127            inline void setEngineTemplate(const std::string& temp)
     128                { this->engineTemplate_ = temp; this->loadEngineTemplate(); }
     129            inline const std::string& getEngineTemplate() const
     130                { return this->engineTemplate_; }
     131
    121132        protected:
    122133            virtual std::vector<PickupCarrier*>* getCarrierChildren(void) const
    123134                { return new std::vector<PickupCarrier*>(); }
    124135            virtual PickupCarrier* getCarrierParent(void) const;
     136           
     137            void loadEngineTemplate();
    125138
    126139        private:
    127140            void registerVariables();
    128141            void networkcallback_shipID();
    129             void changedEnableMotionBlur();
     142
     143            std::string engineTemplate_;
    130144
    131145            SpaceShip* ship_;
    132146            unsigned int shipID_;
     147            Vector3 relativePosition_;
    133148
    134149            float boostFactor_;
     
    148163            float accelerationLeftRight_;
    149164            float accelerationUpDown_;
    150 
    151             Shader* boostBlur_;
    152             float blurStrength_;
    153             bool bEnableMotionBlur_;
    154165    };
    155166}
  • code/trunk/src/orxonox/overlays/OrxonoxOverlay.cc

    r8351 r8706  
    137137        XMLPortParam(OrxonoxOverlay, "correctaspect", setAspectCorrection,   getAspectCorrection,   xmlelement, mode);
    138138        XMLPortParam(OrxonoxOverlay, "background",    setBackgroundMaterial, getBackgroundMaterial, xmlelement, mode);
     139        XMLPortParam(OrxonoxOverlay, "backgroundtex", setBackgroundTexture,  getBackgroundTexture,  xmlelement, mode);
    139140    }
    140141
     
    163164        if (this->background_)
    164165            return this->background_->getMaterialName();
     166        else
     167            return BLANKSTRING;
     168    }
     169
     170    //! Sets the background texture name and creates a new material if necessary
     171    void OrxonoxOverlay::setBackgroundTexture(const std::string& texture)
     172    {
     173        if (this->background_ && this->background_->getMaterial().isNull() && !texture.empty())
     174        {
     175            // create new material
     176            const std::string& materialname = "generated_material" + getUniqueNumberString();
     177            Ogre::MaterialPtr material = static_cast<Ogre::MaterialPtr>(Ogre::MaterialManager::getSingleton().create(materialname, "General"));
     178            material->getTechnique(0)->getPass(0)->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
     179            Ogre::TextureUnitState* textureUnitState_ = material->getTechnique(0)->getPass(0)->createTextureUnitState();
     180            textureUnitState_->setTextureName(texture);
     181            textureUnitState_->setNumMipmaps(0);
     182            this->background_->setMaterialName(materialname);
     183        }
     184    }
     185
     186    //! Returns the the texture name of the background
     187    const std::string& OrxonoxOverlay::getBackgroundTexture() const
     188    {
     189        if (this->background_)
     190        {
     191            Ogre::TextureUnitState* tempTx = this->background_->getMaterial()->getTechnique(0)->getPass(0)->getTextureUnitState(0);
     192            return tempTx->getTextureName();
     193        }
    165194        else
    166195            return BLANKSTRING;
     
    406435    }
    407436
    408     void OrxonoxOverlay::setBackgroundAlpha(float alpha) {
     437    void OrxonoxOverlay::setBackgroundAlpha(float alpha)
     438    {
    409439        Ogre::MaterialPtr ptr = this->background_->getMaterial();
    410440        Ogre::TextureUnitState* tempTx = ptr->getTechnique(0)->getPass(0)->getTextureUnitState(0);
    411441        tempTx->setAlphaOperation(Ogre::LBX_MODULATE, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, alpha);
    412442    }
     443
     444    void OrxonoxOverlay::setBackgroundColour(ColourValue colour)
     445    {
     446        Ogre::MaterialPtr ptr = this->background_->getMaterial();
     447        Ogre::TextureUnitState* tempTx = ptr->getTechnique(0)->getPass(0)->getTextureUnitState(0);
     448        tempTx->setColourOperationEx(Ogre::LBX_MODULATE, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, colour);
     449    }
    413450}
  • code/trunk/src/orxonox/overlays/OrxonoxOverlay.h

    r8309 r8706  
    160160        const std::string& getBackgroundMaterial() const;
    161161
     162        void setBackgroundTexture(const std::string& texture);
     163        const std::string& getBackgroundTexture() const;
     164
    162165        void setBackgroundAlpha(float alpha);
     166
     167        void setBackgroundColour(ColourValue colour);
    163168
    164169        virtual void changedVisibility();
  • code/trunk/src/orxonox/sound/AmbientSound.cc

    r8351 r8706  
    8282    {
    8383        this->ambientSource_ = source;
    84         this->moodChanged(this->getMood());
     84        this->moodChanged(MoodManager::getInstance().getMood());
    8585    }
    8686
     
    8989        if (GameMode::playsSound())
    9090        {
    91             const std::string& path = "ambient/" + MoodManager::getInstance().getMood() + '/' + this->ambientSource_;
     91            const std::string& path = "ambient/" + mood + '/' + this->ambientSource_;
    9292            shared_ptr<ResourceInfo> fileInfo = Resource::getInfo(path);
    9393            if (fileInfo != NULL)
  • code/trunk/src/orxonox/weaponsystem/Munition.cc

    r7896 r8706  
    253253    bool Munition::canAddMunition(unsigned int amount) const
    254254    {
     255        // TODO: 'amount' is not used
     256
    255257        if (!this->bAllowMunitionRefilling_)
    256258            return false;
     
    334336    bool Munition::canAddMagazines(unsigned int amount) const
    335337    {
     338        // TODO: 'amount' is not used
     339
    336340        if (this->bStackMunition_)
    337341            // If we stack munition, we can always add new magazines because they contribute directly to the munition
  • code/trunk/src/orxonox/weaponsystem/WeaponMode.cc

    r7847 r8706  
    6666
    6767        this->damage_ = 0;
     68        this->healthdamage_ = 0;
     69        this->shielddamage_ = 0;
    6870
    6971        this->muzzleOffset_ = Vector3::ZERO;
     
    106108
    107109        XMLPortParam(WeaponMode, "damage",           setDamage,           getDamage,           xmlelement, mode);
     110        XMLPortParam(WeaponMode, "healthdamage",     setHealthDamage,     getHealthDamage,     xmlelement, mode);
     111        XMLPortParam(WeaponMode, "shielddamage",     setShieldDamage,     getShieldDamage,     xmlelement, mode);
    108112        XMLPortParam(WeaponMode, "muzzleoffset",     setMuzzleOffset,     getMuzzleOffset,     xmlelement, mode);
    109113    }
  • code/trunk/src/orxonox/weaponsystem/WeaponMode.h

    r7163 r8706  
    104104            // Fire
    105105            inline void setDamage(float damage)
    106                 { this->damage_ = damage; }
     106                { this->damage_ = damage;}
    107107            inline float getDamage() const
    108108                { return this->damage_; }
     109            inline void setHealthDamage(float healthdamage)
     110                { this->healthdamage_ = healthdamage; }
     111            inline float getHealthDamage() const
     112                { return this->healthdamage_; }
     113
     114            inline void setShieldDamage(float shielddamage)
     115                { this->shielddamage_ = shielddamage;}
     116            inline float getShieldDamage() const
     117                { return this->shielddamage_; }
    109118
    110119            inline void setMuzzleOffset(const Vector3& offset)
     
    146155
    147156            float damage_;
     157            float healthdamage_;
     158            float shielddamage_;
    148159            Vector3 muzzleOffset_;
    149160
  • code/trunk/src/orxonox/weaponsystem/WeaponSlot.cc

    r5929 r8706  
    4646        this->weapon_ = 0;
    4747
    48         this->setSyncMode(0x0);
     48        this->setSyncMode(ObjectDirection::None);
    4949    }
    5050
  • code/trunk/src/orxonox/worldentities/CMakeLists.txt

    r8458 r8706  
    1212  SpawnPoint.cc
    1313  TeamSpawnPoint.cc
    14   SpaceBoundaries.cc
    1514)
    1615
  • code/trunk/src/orxonox/worldentities/CameraPosition.cc

    r5929 r8706  
    4646        this->bRenderCamera_ = false;
    4747
    48         this->setSyncMode(0x0);
     48        this->setSyncMode(ObjectDirection::None);
    4949    }
    5050
  • code/trunk/src/orxonox/worldentities/ControllableEntity.cc

    r7892 r8706  
    8484        this->client_angular_velocity_ = Vector3::ZERO;
    8585
    86 
    8786        this->setConfigValues();
    8887        this->setPriority( Priority::VeryHigh );
     
    121120
    122121        XMLPortParam(ControllableEntity, "hudtemplate", setHudTemplate, getHudTemplate, xmlelement, mode);
    123         XMLPortParam(ControllableEntity, "camerapositiontemplate", setCameraPositionTemplate, getCameraPositionTemkplate, xmlelement, mode);
     122        XMLPortParam(ControllableEntity, "camerapositiontemplate", setCameraPositionTemplate, getCameraPositionTemplate, xmlelement, mode);
    124123
    125124        XMLPortObject(ControllableEntity, CameraPosition, "camerapositions", addCameraPosition, getCameraPosition, xmlelement, mode);
     
    171170        }
    172171        return 0;
     172    }
     173
     174    unsigned int ControllableEntity::getCurrentCameraIndex() const
     175    {
     176        if (this->cameraPositions_.size() <= 0)
     177            return 0;
     178
     179        unsigned int counter = 0;
     180        for (std::list<SmartPtr<CameraPosition> >::const_iterator it = this->cameraPositions_.begin(); it != this->cameraPositions_.end(); ++it)
     181        {
     182            if ((*it) == this->currentCameraPosition_)
     183                break;
     184            counter++;
     185        }
     186        if (counter >= this->cameraPositions_.size())
     187            return 0;
     188
     189        return counter;
     190    }
     191   
     192    bool ControllableEntity::setCameraPosition(unsigned int index)
     193    {
     194        if(this->camera_ != NULL && this->cameraPositions_.size() > 0)
     195        {
     196            if(index >= this->cameraPositions_.size())
     197                index = 0;
     198
     199            CameraPosition* position = this->getCameraPosition(index);
     200            position->attachCamera(this->camera_);
     201            this->currentCameraPosition_ = position;
     202            return true;
     203        }
     204
     205        return false;
    173206    }
    174207
     
    373406        }
    374407
     408        this->createHud();
     409    }
     410
     411    // HACK-ish
     412    void ControllableEntity::createHud(void)
     413    {
    375414        if (!this->hud_ && GameMode::showsGraphics())
    376415        {
     
    381420                this->hud_->setOwner(this);
    382421            }
     422        }
     423    }
     424
     425    void ControllableEntity::destroyHud(void)
     426    {
     427        if (this->hud_ != NULL)
     428        {
     429            this->hud_->destroy();
     430            this->hud_ = NULL;
    383431        }
    384432    }
  • code/trunk/src/orxonox/worldentities/ControllableEntity.h

    r7889 r8706  
    9393            virtual void reload() {}
    9494
    95             virtual void boost() {}
     95            /**
     96            @brief Tells the ControllableEntity to either start or stop boosting.
     97                   This doesn't mean, that the ControllableEntity will do so, there might be additional restrictions on boosting, but if it can, then it will.
     98            @param bBoost If true the ControllableEntity is told to start boosting, if false it is told to stop.
     99            */
     100            virtual void boost(bool bBoost) {}
     101           
    96102            virtual void greet() {}
    97103            virtual void switchCamera();
     
    110116            inline const std::list<SmartPtr<CameraPosition> >& getCameraPositions() const
    111117                { return this->cameraPositions_; }
     118            unsigned int getCurrentCameraIndex() const;
     119            bool setCameraPosition(unsigned int index);
    112120
    113121            inline void setCameraPositionTemplate(const std::string& name)
    114122                { this->cameraPositionTemplate_ = name; }
    115             inline const std::string& getCameraPositionTemkplate() const
     123            inline const std::string& getCameraPositionTemplate() const
    116124                { return this->cameraPositionTemplate_; }
    117125
     
    168176            inline void setHudTemplate(const std::string& name)
    169177                { this->hudtemplate_ = name; }
     178            // HACK-ish
     179            void createHud(void);
     180            void destroyHud(void);
    170181
    171182            Ogre::SceneNode* cameraPositionRootNode_;
  • code/trunk/src/orxonox/worldentities/MobileEntity.cc

    r7163 r8706  
    143143    {
    144144        if (this->isDynamic())
     145        {
    145146            this->physicalBody_->applyCentralForce(btVector3(acceleration.x * this->getMass(), acceleration.y * this->getMass(), acceleration.z * this->getMass()));
    146 
     147        }
     148
     149        // If not bullet-managed (deprecated? SpaceShip doesn't use this anymore for movement)
    147150        this->linearAcceleration_ = acceleration;
     151    }
     152
     153    void MobileEntity::addAcceleration(const Vector3 &acceleration, const Vector3 &relativePosition)
     154    {
     155        if(this->isDynamic())
     156        {
     157            this->physicalBody_->applyForce(this->getMass() * btVector3(acceleration.x, acceleration.y, acceleration.z), btVector3(relativePosition.x, relativePosition.y, relativePosition.z));
     158        }
    148159    }
    149160
  • code/trunk/src/orxonox/worldentities/MobileEntity.h

    r5781 r8706  
    7070                { return this->linearAcceleration_; }
    7171
     72            // Added for making N engines work with spaceships
     73            void addAcceleration(const Vector3& acceleration, const Vector3 &relativePosition);
     74            inline void addAcceleration(float x, float y, float z)
     75                { this->addAcceleration(Vector3(x, y, z), Vector3(0,0,0)); }
     76            // Getter function above
     77
    7278            void setAngularAcceleration(const Vector3& acceleration);
    7379            inline void setAngularAcceleration(float x, float y, float z)
     
    8389                { this->setAngularVelocity(this->getAngularVelocity().normalisedCopy() * rate.valueRadians()); }
    8490            inline Degree getRotationRate() const
    85                 { return Degree(this->getAngularVelocity().length()); }
     91                { return Radian(this->getAngularVelocity().length()); }
    8692
    8793            inline void setRotationAxis(const Vector3& axis)
  • code/trunk/src/orxonox/worldentities/SpawnPoint.cc

    r5929 r8706  
    5050            COUT(1) << "Error: SpawnPoint has no Gametype" << std::endl;
    5151
    52         this->setSyncMode(0x0);
     52        this->setSyncMode(ObjectDirection::None);
    5353    }
    5454
  • code/trunk/src/orxonox/worldentities/WorldEntity.cc

    r7937 r8706  
    642642    void WorldEntity::setScale3D(const Vector3& scale)
    643643    {
    644 /*
    645 HACK HACK HACK
    646         if (bScalePhysics && this->hasPhysics() && scale != Vector3::UNIT_SCALE)
    647         {
    648             CCOUT(2) << "Warning: Cannot set the scale of a physical object: Not yet implemented. Ignoring scaling." << std::endl;
    649             return;
    650         }
    651 HACK HACK HACK
    652 */
     644        // If physics is enabled scale the attached CollisionShape.
     645        /*if (this->hasPhysics() && this->collisionShape_ != NULL)
     646        {
     647            this->collisionShape_->setScale3D(scale);
     648        }*/
     649
    653650        this->node_->setScale(scale);
    654651
  • code/trunk/src/orxonox/worldentities/pawns/Pawn.cc

    r8351 r8706  
    2323 *      Fabian 'x3n' Landau
    2424 *   Co-authors:
    25  *      ...
     25 *      Simon Miescher
    2626 *
    2727 */
     
    6464        this->maxHealth_ = 0;
    6565        this->initialHealth_ = 0;
     66
    6667        this->shieldHealth_ = 0;
     68        this->initialShieldHealth_ = 0;
     69        this->maxShieldHealth_ = 100; //otherwise shield might increase to float_max
    6770        this->shieldAbsorption_ = 0.5;
     71
     72        this->reloadRate_ = 0;
     73        this->reloadWaitTime_ = 1.0f;
     74        this->reloadWaitCountdown_ = 0;
    6875
    6976        this->lastHitOriginator_ = 0;
     
    109116
    110117        XMLPortParam(Pawn, "shieldhealth", setShieldHealth, getShieldHealth, xmlelement, mode).defaultValues(0);
     118        XMLPortParam(Pawn, "initialshieldhealth", setInitialShieldHealth, getInitialShieldHealth, xmlelement, mode).defaultValues(0);
     119        XMLPortParam(Pawn, "maxshieldhealth", setMaxShieldHealth, getMaxShieldHealth, xmlelement, mode).defaultValues(100);
    111120        XMLPortParam(Pawn, "shieldabsorption", setShieldAbsorption, getShieldAbsorption, xmlelement, mode).defaultValues(0);
    112121
     
    118127        XMLPortObject(Pawn, WeaponSet, "weaponsets", addWeaponSet, getWeaponSet, xmlelement, mode);
    119128        XMLPortObject(Pawn, WeaponPack, "weapons", addWeaponPackXML, getWeaponPack, xmlelement, mode);
     129
     130        XMLPortParam(Pawn, "reloadrate", setReloadRate, getReloadRate, xmlelement, mode).defaultValues(0);
     131        XMLPortParam(Pawn, "reloadwaittime", setReloadWaitTime, getReloadWaitTime, xmlelement, mode).defaultValues(1.0f);
    120132    }
    121133
     
    124136        registerVariable(this->bAlive_,           VariableDirection::ToClient);
    125137        registerVariable(this->health_,           VariableDirection::ToClient);
    126         registerVariable(this->initialHealth_,    VariableDirection::ToClient);
     138        registerVariable(this->maxHealth_,        VariableDirection::ToClient);
    127139        registerVariable(this->shieldHealth_,     VariableDirection::ToClient);
     140        registerVariable(this->maxShieldHealth_,  VariableDirection::ToClient);
    128141        registerVariable(this->shieldAbsorption_, VariableDirection::ToClient);
    129142        registerVariable(this->bReload_,          VariableDirection::ToServer);
     
    137150        this->bReload_ = false;
    138151
     152        // TODO: use the existing timer functions instead
     153        if(this->reloadWaitCountdown_ > 0)
     154        {
     155            this->decreaseReloadCountdownTime(dt);
     156        }
     157        else
     158        {
     159            this->addShieldHealth(this->getReloadRate() * dt);
     160            this->resetReloadCountdown();
     161        }
     162
    139163        if (GameMode::isMaster())
     164        {
    140165            if (this->health_ <= 0 && bAlive_)
    141166            {
    142                 this->fireEvent(); // Event to notify anyone who want's to know about the death.
     167                this->fireEvent(); // Event to notify anyone who wants to know about the death.
    143168                this->death();
    144169            }
     170        }
    145171    }
    146172
     
    168194    }
    169195
     196
    170197    void Pawn::setHealth(float health)
    171198    {
    172         this->health_ = std::min(health, this->maxHealth_);
    173     }
    174 
    175     void Pawn::damage(float damage, Pawn* originator)
     199        this->health_ = std::min(health, this->maxHealth_); //Health can't be set to a value bigger than maxHealth, otherwise it will be reduced at first hit
     200    }
     201
     202    void Pawn::setShieldHealth(float shieldHealth)
     203    {
     204        this->shieldHealth_ = std::min(shieldHealth, this->maxShieldHealth_);
     205    }
     206
     207    void Pawn::setMaxShieldHealth(float maxshieldhealth)
     208    {
     209        this->maxShieldHealth_ = maxshieldhealth;
     210    }
     211
     212    void Pawn::setReloadRate(float reloadrate)
     213    {
     214        this->reloadRate_ = reloadrate;
     215    }
     216
     217    void Pawn::setReloadWaitTime(float reloadwaittime)
     218    {
     219        this->reloadWaitTime_ = reloadwaittime;
     220    }
     221
     222    void Pawn::decreaseReloadCountdownTime(float dt)
     223    {
     224        this->reloadWaitCountdown_ -= dt;
     225    }
     226
     227    void Pawn::damage(float damage, float healthdamage, float shielddamage, Pawn* originator)
    176228    {
    177229        if (this->getGametype() && this->getGametype()->allowPawnDamage(this, originator))
    178230        {
    179             //share the dealt damage to the shield and the Pawn.
    180             float shielddamage = damage*this->shieldAbsorption_;
    181             float healthdamage = damage*(1-this->shieldAbsorption_);
    182 
    183             // In case the shield can not take all the shield damage.
    184             if (shielddamage > this->getShieldHealth())
     231            if (shielddamage >= this->getShieldHealth())
    185232            {
    186                 healthdamage += shielddamage-this->getShieldHealth();
    187233                this->setShieldHealth(0);
     234                this->setHealth(this->health_ - (healthdamage + damage));
    188235            }
    189 
    190             this->setHealth(this->health_ - healthdamage);
    191 
    192             if (this->getShieldHealth() > 0)
     236            else
    193237            {
    194238                this->setShieldHealth(this->shieldHealth_ - shielddamage);
     239
     240                // remove remaining shieldAbsorpton-Part of damage from shield
     241                shielddamage = damage * this->shieldAbsorption_;
     242                shielddamage = std::min(this->getShieldHealth(),shielddamage);
     243                this->setShieldHealth(this->shieldHealth_ - shielddamage);
     244
     245                // set remaining damage to health
     246                this->setHealth(this->health_ - (damage - shielddamage) - healthdamage);
    195247            }
    196248
    197249            this->lastHitOriginator_ = originator;
    198 
    199             // play damage effect
    200         }
    201     }
    202 
    203     void Pawn::hit(Pawn* originator, const Vector3& force, float damage)
     250        }
     251    }
     252
     253// TODO: Still valid?
     254/* HIT-Funktionen
     255    Die hit-Funktionen muessen auch in src/orxonox/controllers/Controller.h angepasst werden! (Visuelle Effekte)
     256
     257*/
     258
     259    void Pawn::hit(Pawn* originator, const Vector3& force, float damage, float healthdamage, float shielddamage)
    204260    {
    205261        if (this->getGametype() && this->getGametype()->allowPawnHit(this, originator) && (!this->getController() || !this->getController()->getGodMode()) )
    206262        {
    207             this->damage(damage, originator);
     263            this->damage(damage, healthdamage, shielddamage, originator);
    208264            this->setVelocity(this->getVelocity() + force);
    209 
    210             // play hit effect
    211         }
    212     }
    213 
    214     void Pawn::hit(Pawn* originator, btManifoldPoint& contactpoint, float damage)
     265        }
     266    }
     267
     268
     269    void Pawn::hit(Pawn* originator, btManifoldPoint& contactpoint, float damage, float healthdamage, float shielddamage)
    215270    {
    216271        if (this->getGametype() && this->getGametype()->allowPawnHit(this, originator) && (!this->getController() || !this->getController()->getGodMode()) )
    217272        {
    218             this->damage(damage, originator);
     273            this->damage(damage, healthdamage, shielddamage, originator);
    219274
    220275            if ( this->getController() )
    221                 this->getController()->hit(originator, contactpoint, damage);
    222 
    223             // play hit effect
    224         }
    225     }
     276                this->getController()->hit(originator, contactpoint, damage); // changed to damage, why shielddamage?
     277        }
     278    }
     279
    226280
    227281    void Pawn::kill()
  • code/trunk/src/orxonox/worldentities/pawns/Pawn.h

    r7889 r8706  
    7272                { return this->initialHealth_; }
    7373
    74             inline void setShieldHealth(float shieldHealth)
    75             { this->shieldHealth_ = shieldHealth; }
     74            virtual void setShieldHealth(float shieldHealth);
     75
    7676            inline float getShieldHealth()
    7777            { return this->shieldHealth_; }
     78
     79            inline void addShieldHealth(float amount)
     80            { this->setShieldHealth(this->shieldHealth_ + amount); }
     81
     82            inline bool hasShield()
     83            { return (this->getShieldHealth() > 0); }
     84
     85            virtual void setMaxShieldHealth(float maxshieldhealth);
     86            inline float getMaxShieldHealth() const
     87                { return this->maxShieldHealth_; }
     88
     89            inline void setInitialShieldHealth(float initialshieldhealth)
     90                { this->initialShieldHealth_ = initialshieldhealth; this->setShieldHealth(initialshieldhealth); }
     91            inline float getInitialShieldHealth() const
     92                { return this->initialShieldHealth_; }
     93
     94            inline void restoreInitialShieldHealth()
     95                { this->setShieldHealth(this->initialShieldHealth_); }
     96            inline void restoreMaxShieldHealth()
     97                { this->setShieldHealth(this->maxShieldHealth_); }
    7898
    7999            inline void setShieldAbsorption(float shieldAbsorption)
     
    82102            { return this->shieldAbsorption_; }
    83103
     104            // TODO: Rename to shieldRechargeRate
     105            virtual void setReloadRate(float reloadrate);
     106            inline float getReloadRate() const
     107                { return this->reloadRate_; }
     108
     109            virtual void setReloadWaitTime(float reloadwaittime);
     110            inline float getReloadWaitTime() const
     111                { return this->reloadWaitTime_; }
     112
     113            inline void resetReloadCountdown()
     114            { this->reloadWaitCountdown_ = 0; }
     115
     116            inline void startReloadCountdown()
     117            { this->reloadWaitCountdown_ = this->getReloadWaitTime(); } // TODO: Implement in Projectile.cc
     118
     119            virtual void decreaseReloadCountdownTime(float dt);
     120
    84121            inline ControllableEntity* getLastHitOriginator() const
    85122                { return this->lastHitOriginator_; }
    86123
    87             virtual void hit(Pawn* originator, const Vector3& force, float damage);
    88             virtual void hit(Pawn* originator, btManifoldPoint& contactpoint, float damage);
     124            //virtual void hit(Pawn* originator, const Vector3& force, float damage);
     125            //virtual void hit(Pawn* originator, btManifoldPoint& contactpoint, float damage);
     126            virtual void hit(Pawn* originator, const Vector3& force, float damage, float healthdamage = 0.0f, float shielddamage = 0.0f);
     127            virtual void hit(Pawn* originator, btManifoldPoint& contactpoint, float damage, float healthdamage = 0.0f, float shielddamage = 0.0f);
     128
    89129            virtual void kill();
    90130
     
    142182            virtual void spawneffect();
    143183
    144             virtual void damage(float damage, Pawn* originator = 0);
     184            //virtual void damage(float damage, Pawn* originator = 0);
     185            virtual void damage(float damage, float healthdamage = 0.0f, float shielddamage = 0.0f, Pawn* originator = NULL);
    145186
    146187            bool bAlive_;
     
    154195            float maxHealth_;
    155196            float initialHealth_;
     197           
    156198            float shieldHealth_;
     199            float maxShieldHealth_;
     200            float initialShieldHealth_;
    157201            float shieldAbsorption_; // Has to be between 0 and 1
     202            float reloadRate_;
     203            float reloadWaitTime_;
     204            float reloadWaitCountdown_;
    158205
    159206            WeakPtr<Pawn> lastHitOriginator_;
  • code/trunk/src/orxonox/worldentities/pawns/SpaceShip.cc

    r7860 r8706  
    3535#include "core/Template.h"
    3636#include "core/XMLPort.h"
     37#include "tools/Shader.h"
     38#include "util/Debug.h" // TODO: Needed?
     39#include "util/Math.h"
     40
     41#include "graphics/Camera.h"
    3742#include "items/Engine.h"
     43
     44#include "CameraManager.h"
     45#include "Scene.h"
    3846
    3947namespace orxonox
     
    4250    CreateFactory(SpaceShip);
    4351
    44     SpaceShip::SpaceShip(BaseObject* creator) : Pawn(creator)
     52    SpaceShip::SpaceShip(BaseObject* creator) : Pawn(creator), boostBlur_(NULL)
    4553    {
    4654        RegisterObject(SpaceShip);
     
    5361        this->localAngularAcceleration_.setValue(0, 0, 0);
    5462        this->bBoost_ = false;
    55         this->bPermanentBoost_ = false;
    5663        this->steering_ = Vector3::ZERO;
    57         this->engine_ = 0;
    5864
    5965        this->boostPower_ = 10.0f;
     
    6470        this->bBoostCooldown_ = false;
    6571
     72        this->lift_ = 1.0f;                         // factor of the lift, standard is 1
     73        this->stallSpeed_ = 220.0f;                 // max speed where lift is added
     74
    6675        this->bInvertYAxis_ = false;
    6776
     
    7483        this->enableCollisionCallback();
    7584
     85        this->engineTicksNotDone = 0;
    7686        this->setConfigValues();
    7787        this->registerVariables();
     88       
     89        this->cameraOriginalPosition_ = Vector3::UNIT_SCALE;
     90        this->cameraOriginalOrientation_ = Quaternion::IDENTITY;
     91
     92        this->shakeFrequency_ = 15;
     93        this->shakeAmplitude_ = 5;
     94        this->shakeDt_ = 0;
    7895    }
    7996
    8097    SpaceShip::~SpaceShip()
    8198    {
    82         if (this->isInitialized() && this->engine_)
    83             this->engine_->destroy();
     99        if (this->isInitialized())
     100        {
     101            this->removeAllEngines();
     102       
     103            if (this->boostBlur_)
     104                this->boostBlur_->destroy();
     105        }
    84106    }
    85107
     
    88110        SUPER(SpaceShip, XMLPort, xmlelement, mode);
    89111
    90         XMLPortParam(SpaceShip, "engine",            setEngineTemplate,    getEngineTemplate,    xmlelement, mode);
     112        //XMLPortParam(SpaceShip, "engine",            setEngineTemplate,    getEngineTemplate,    xmlelement, mode);
    91113        XMLPortParamVariable(SpaceShip, "primaryThrust",  primaryThrust_,  xmlelement, mode);
    92114        XMLPortParamVariable(SpaceShip, "auxilaryThrust", auxilaryThrust_, xmlelement, mode);
     
    96118        XMLPortParamVariable(SpaceShip, "boostRate", boostRate_, xmlelement, mode);
    97119        XMLPortParamVariable(SpaceShip, "boostCooldownDuration", boostCooldownDuration_, xmlelement, mode);
     120        XMLPortParamVariable(SpaceShip, "shakeFrequency", shakeFrequency_, xmlelement, mode);
     121        XMLPortParamVariable(SpaceShip, "shakeAmplitude", shakeAmplitude_, xmlelement, mode);
     122        XMLPortParamVariable(SpaceShip, "lift", lift_, xmlelement, mode);
     123        XMLPortParamVariable(SpaceShip, "stallSpeed", stallSpeed_, xmlelement, mode);
     124
     125        XMLPortObject(SpaceShip, Engine, "engines", addEngine, getEngine, xmlelement, mode);
    98126    }
    99127
     
    103131        registerVariable(this->auxilaryThrust_, VariableDirection::ToClient);
    104132        registerVariable(this->rotationThrust_, VariableDirection::ToClient);
     133        // TODO: Synchronization of boost needed?
     134        registerVariable(this->boostPower_, VariableDirection::ToClient);
     135        registerVariable(this->boostPowerRate_, VariableDirection::ToClient);
     136        registerVariable(this->boostRate_, VariableDirection::ToClient);
     137        registerVariable(this->boostCooldownDuration_, VariableDirection::ToClient);
     138        registerVariable(this->shakeFrequency_, VariableDirection::ToClient);
     139        registerVariable(this->shakeAmplitude_, VariableDirection::ToClient);
     140        registerVariable(this->lift_, VariableDirection::ToClient);
     141        registerVariable(this->stallSpeed_, VariableDirection::ToClient);
    105142    }
    106143
     
    108145    {
    109146        SetConfigValue(bInvertYAxis_, false).description("Set this to true for joystick-like mouse behaviour (mouse up = ship down).");
     147       
     148        SetConfigValueExternal(bEnableMotionBlur_, "GraphicsSettings", "enableMotionBlur", true)
     149            .description("Enable or disable the motion blur effect when moving very fast")
     150            .callback(this, &SpaceShip::changedEnableMotionBlur);
     151        SetConfigValueExternal(blurStrength_, "GraphicsSettings", "blurStrength", 3.0f)
     152            .description("Defines the strength of the motion blur effect");
    110153    }
    111154
     
    128171        if (this->hasLocalController())
    129172        {
    130 /*
    131             this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() * getMass() * this->auxilaryThrust_);
    132             this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() * getMass() * this->auxilaryThrust_);
    133             if (this->localLinearAcceleration_.z() > 0)
    134                 this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->auxilaryThrust_);
    135             else
    136                 this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->primaryThrust_);
    137             this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * this->localLinearAcceleration_);
    138             this->localLinearAcceleration_.setValue(0, 0, 0);
    139 */
     173            // Handle mouse look
    140174            if (!this->isInMouseLook())
    141175            {
     
    143177                this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_);
    144178            }
    145 
    146179            this->localAngularAcceleration_.setValue(0, 0, 0);
    147180
     181            // Charge boostPower
    148182            if(!this->bBoostCooldown_ && this->boostPower_ < this->initialBoostPower_)
    149183            {
    150184                this->boostPower_ += this->boostPowerRate_*dt;
    151185            }
     186            // Use boostPower
    152187            if(this->bBoost_)
    153188            {
     
    155190                if(this->boostPower_ <= 0.0f)
    156191                {
    157                     this->bBoost_ = false;
     192                    this->boost(false);
    158193                    this->bBoostCooldown_ = true;
    159194                    this->timer_.setTimer(this->boostCooldownDuration_, false, createExecutor(createFunctor(&SpaceShip::boostCooledDown, this)));
    160195                }
    161             }
     196
     197                this->shakeCamera(dt);
     198            }
     199
     200            // Enable Blur depending on settings
     201            if (this->bEnableMotionBlur_ && !this->boostBlur_ && this->hasLocalController() && this->hasHumanController())
     202            {
     203                this->boostBlur_ = new Shader(this->getScene()->getSceneManager());
     204                this->boostBlur_->setCompositorName("Radial Blur");
     205            }
     206
     207            if (this->boostBlur_) // && this->maxSpeedFront_ != 0 && this->boostFactor_ != 1)
     208            {
     209                // TODO: this->maxSpeedFront_ gets fastest engine
     210                float blur = this->blurStrength_ * clamp((-this->getLocalVelocity().z - 0.0f /*this->maxSpeedFront_*/) / ((150.0f /*boostFactor_*/ - 1) * 1.5f /*this->maxSpeedFront_*/), 0.0f, 1.0f);
     211
     212                // Show and hide blur effect depending on state of booster
     213                if(this->bBoost_)
     214                    this->boostBlur_->setVisible(blur > 0);
     215                else
     216                    this->boostBlur_->setVisible(false);
     217
     218                this->boostBlur_->setParameter(0, 0, "sampleStrength", blur);
     219            }
     220        }
     221    }
     222
     223    void SpaceShip::moveFrontBack(const Vector2& value)
     224    {
     225        this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() - value.x);
     226        this->steering_.z -= value.x;
     227    }
     228
     229    void SpaceShip::moveRightLeft(const Vector2& value)
     230    {
     231        this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() + value.x);
     232        this->steering_.x += value.x;
     233    }
     234
     235    void SpaceShip::moveUpDown(const Vector2& value)
     236    {
     237        this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() + value.x);
     238        this->steering_.y += value.x;
     239    }
     240
     241    void SpaceShip::rotateYaw(const Vector2& value)
     242    {
     243        this->localAngularAcceleration_.setY(this->localAngularAcceleration_.y() + value.x);
     244
     245        Pawn::rotateYaw(value);
     246
     247        //This function call adds a lift to the ship when it is rotating to make it's movement more "realistic" and enhance the feeling.
     248        if (abs(this-> getLocalVelocity().z) < stallSpeed_)  {this->moveRightLeft(-lift_ / 5 * value * sqrt(abs(this-> getLocalVelocity().z)));}
     249    }
     250
     251    void SpaceShip::rotatePitch(const Vector2& value)
     252    {
     253        this->localAngularAcceleration_.setX(this->localAngularAcceleration_.x() + value.x*0.8f);
     254
     255        Pawn::rotatePitch(value);
     256
     257        //This function call adds a lift to the ship when it is pitching to make it's movement more "realistic" and enhance the feeling.
     258        if (abs(this-> getLocalVelocity().z) < stallSpeed_)  {this->moveUpDown(lift_ / 5 * value * sqrt(abs(this-> getLocalVelocity().z)));}
     259    }
     260
     261    void SpaceShip::rotateRoll(const Vector2& value)
     262    {
     263        this->localAngularAcceleration_.setZ(this->localAngularAcceleration_.z() + value.x);
     264
     265        Pawn::rotateRoll(value);
     266    }
     267
     268    void SpaceShip::fire()
     269    {
     270    }
     271
     272    /**
     273    @brief
     274        Starts or stops boosting.
     275    @param bBoost
     276        Whether to start or stop boosting.
     277    */
     278    void SpaceShip::boost(bool bBoost)
     279    {
     280        if(bBoost && !this->bBoostCooldown_)
     281        {
     282            this->bBoost_ = true;
     283            Camera* camera = CameraManager::getInstance().getActiveCamera();
     284            this->cameraOriginalPosition_ = camera->getPosition();
     285            this->cameraOriginalOrientation_ = camera->getOrientation();
     286        }
     287        if(!bBoost)
     288        {
     289            this->bBoost_ = false;
     290            this->resetCamera();
    162291        }
    163292    }
     
    167296        this->bBoostCooldown_ = false;
    168297    }
    169 
    170     void SpaceShip::moveFrontBack(const Vector2& value)
    171     {
    172         this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() - value.x);
    173         this->steering_.z = -value.x;
    174     }
    175 
    176     void SpaceShip::moveRightLeft(const Vector2& value)
    177     {
    178         this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() + value.x);
    179         this->steering_.x = value.x;
    180     }
    181 
    182     void SpaceShip::moveUpDown(const Vector2& value)
    183     {
    184         this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() + value.x);
    185         this->steering_.y = value.x;
    186     }
    187 
    188     void SpaceShip::rotateYaw(const Vector2& value)
    189     {
    190         this->localAngularAcceleration_.setY(this->localAngularAcceleration_.y() + value.x);
    191 
    192         Pawn::rotateYaw(value);
    193     }
    194 
    195     void SpaceShip::rotatePitch(const Vector2& value)
    196     {
    197         this->localAngularAcceleration_.setX(this->localAngularAcceleration_.x() + value.x);
    198 
    199         Pawn::rotatePitch(value);
    200     }
    201 
    202     void SpaceShip::rotateRoll(const Vector2& value)
    203     {
    204         this->localAngularAcceleration_.setZ(this->localAngularAcceleration_.z() + value.x);
    205 
    206         Pawn::rotateRoll(value);
    207     }
    208 
    209     // TODO: something seems to call this function every tick, could probably handled a little more efficiently!
    210     void SpaceShip::setBoost(bool bBoost)
    211     {
    212         if(bBoost == this->bBoost_)
     298   
     299    void SpaceShip::shakeCamera(float dt)
     300    {
     301        //make sure the ship is only shaking if it's moving
     302        if (this->getVelocity().squaredLength() > 80.0f)
     303        {
     304            this->shakeDt_ += dt;
     305   
     306            float frequency = this->shakeFrequency_ * (this->getVelocity().squaredLength());
     307   
     308            if (this->shakeDt_ >= 1.0f/frequency)
     309            {
     310                this->shakeDt_ -= 1.0f/frequency;
     311            }
     312   
     313            Degree angle = Degree(sin(this->shakeDt_ *2.0f* math::pi * frequency) * this->shakeAmplitude_);
     314   
     315            //COUT(0) << "Angle: " << angle << std::endl;
     316            Camera* camera = this->getCamera();
     317
     318            //Shaking Camera effect
     319            if (camera != 0)
     320            {
     321                camera->setOrientation(Vector3::UNIT_X, angle);
     322            }
     323        }
     324    }
     325
     326    void SpaceShip::resetCamera()
     327    {
     328        Camera *camera = this->getCamera();
     329
     330        if (camera == 0)
     331        {
     332            COUT(2) << "Failed to reset camera!";
    213333            return;
    214 
    215         if(bBoost)
    216             this->boost();
     334        }
     335   
     336        this->shakeDt_ = 0;
     337        camera->setPosition(this->cameraOriginalPosition_);
     338        camera->setOrientation(this->cameraOriginalOrientation_);
     339    }
     340
     341    void SpaceShip::backupCamera()
     342    {
     343        Camera* camera = CameraManager::getInstance().getActiveCamera();
     344        if(camera != NULL)
     345        {
     346            this->cameraOriginalPosition_ = camera->getPosition();
     347            this->cameraOriginalOrientation_ = camera->getOrientation();
     348        }
     349    }
     350
     351    void SpaceShip::addEngine(orxonox::Engine* engine)
     352    {
     353        //COUT(0)<<"Adding an Engine: " << engine << endl;
     354        this->engineList_.push_back(engine);
     355        engine->addToSpaceShip(this);
     356        this->resetEngineTicks();
     357    }
     358
     359    bool SpaceShip::hasEngine(Engine* engine)
     360    {
     361        for(unsigned int i=0; i<this->engineList_.size(); i++)
     362        {
     363            if(this->engineList_[i]==engine)
     364                return true;
     365        }
     366        return false;
     367    }
     368
     369    Engine* SpaceShip::getEngine(unsigned int i)
     370    {
     371        if(this->engineList_.size()>=i)
     372            return 0;
    217373        else
    218         {
    219             this->bBoost_ = false;
    220         }
    221     }
    222 
    223     void SpaceShip::fire()
    224     {
    225     }
    226 
    227     void SpaceShip::boost()
    228     {
    229         if(!this->bBoostCooldown_)
    230             this->bBoost_ = true;
    231     }
    232 
    233     void SpaceShip::loadEngineTemplate()
    234     {
    235         if (!this->enginetemplate_.empty())
    236         {
    237             Template* temp = Template::getTemplate(this->enginetemplate_);
    238 
    239             if (temp)
    240             {
    241                 Identifier* identifier = temp->getBaseclassIdentifier();
    242 
    243                 if (identifier)
    244                 {
    245                     BaseObject* object = identifier->fabricate(this);
    246                     this->engine_ = orxonox_cast<Engine*>(object);
    247 
    248                     if (this->engine_)
    249                     {
    250                         this->engine_->addTemplate(temp);
    251                         this->engine_->addToSpaceShip(this);
    252                     }
    253                     else
    254                     {
    255                         object->destroy();
    256                     }
    257                 }
    258             }
    259         }
    260     }
    261 
    262     void SpaceShip::setEngine(Engine* engine)
    263     {
    264         this->engine_ = engine;
    265         if (engine && engine->getShip() != this)
    266             engine->addToSpaceShip(this);
     374            return this->engineList_[i];
     375    }
     376
     377    void SpaceShip::removeAllEngines()
     378    {
     379        while(this->engineList_.size())
     380            this->engineList_.back()->destroy();
     381    }
     382   
     383    void SpaceShip::removeEngine(Engine* engine)
     384    {
     385        for(std::vector<Engine*>::iterator it=this->engineList_.begin(); it!=this->engineList_.end(); ++it)
     386        {
     387            if(*it==engine)
     388            {
     389                this->engineList_.erase(it);
     390                return;
     391            }
     392        }
     393    }
     394
     395    void SpaceShip::setSpeedFactor(float factor)
     396    {
     397        for(unsigned int i=0; i<this->engineList_.size(); i++)
     398            this->engineList_[i]->setSpeedFactor(factor);
     399    }
     400    float SpaceShip::getSpeedFactor() // Calculate mean SpeedFactor.
     401    {
     402        float ret = 0; unsigned int i = 0;
     403        for(; i<this->engineList_.size(); i++)
     404            ret += this->engineList_[i]->getSpeedFactor();
     405        ret /= (float)i;
     406        return ret;
     407    }
     408    float SpaceShip::getMaxSpeedFront()
     409    {
     410        float ret=0;
     411        for(unsigned int i=0; i<this->engineList_.size(); i++)
     412        {
     413            if(this->engineList_[i]->getMaxSpeedFront() > ret)
     414                ret = this->engineList_[i]->getMaxSpeedFront();
     415        }
     416        return ret;
     417    }
     418
     419    float SpaceShip::getBoostFactor()
     420    {
     421        float ret = 0; unsigned int i=0;
     422        for(; i<this->engineList_.size(); i++)
     423            ret += this->engineList_[i]->getBoostFactor();
     424        ret /= (float)i;
     425        return ret;
    267426    }
    268427
     
    270429    {
    271430        std::vector<PickupCarrier*>* list = new std::vector<PickupCarrier*>();
    272         list->push_back(this->engine_);
     431        for(unsigned int i=0; i<this->engineList_.size(); i++)
     432            list->push_back(this->engineList_[i]);
    273433        return list;
    274434    }
     435   
     436    void SpaceShip::changedEnableMotionBlur()
     437    {
     438        if (!this->bEnableMotionBlur_)
     439        {
     440            this->boostBlur_->destroy();
     441            this->boostBlur_ = 0;
     442        }
     443    }
     444
    275445}
  • code/trunk/src/orxonox/worldentities/pawns/SpaceShip.h

    r7801 r8706  
    5959
    6060            virtual void fire();
    61             virtual void boost();
     61            virtual void boost(bool bBoost); // Starts or stops boosting.
    6262
    63             void setEngine(Engine* engine);
    64             inline Engine* getEngine() const
    65                 { return this->engine_; }
     63            void addEngine(Engine* engine);
     64            bool hasEngine(Engine* engine);
     65            Engine* getEngine(unsigned int i); // This one's for XMLPort
     66            inline const std::vector<Engine*>& getEngineList()
     67                { return this->engineList_; }
     68            void removeEngine(Engine* engine);
     69            void removeAllEngines();
     70
     71            void setSpeedFactor(float factor);
     72            float getSpeedFactor(); // Gets mean speed factor
     73            float getMaxSpeedFront(); // gets largest speed forward
     74            float getBoostFactor(); // gets mean boost factor
    6675
    6776            inline void setSteeringDirection(const Vector3& direction)
     
    6978            inline const Vector3& getSteeringDirection() const
    7079                { return this->steering_; }
     80            inline void resetEngineTicks()
     81                { this->engineTicksNotDone = this->engineList_.size(); }
     82            inline void oneEngineTickDone()
     83                { this->engineTicksNotDone--; }
     84            inline bool hasEngineTicksRemaining()
     85                { return (this->engineTicksNotDone>0); }
    7186
    72             void setBoost(bool bBoost);
    7387            inline bool getBoost() const
    7488                { return this->bBoost_; }
    7589
    76             inline void setEngineTemplate(const std::string& temp)
    77                 { this->enginetemplate_ = temp; this->loadEngineTemplate(); }
    78             inline const std::string& getEngineTemplate() const
    79                 { return this->enginetemplate_; }
     90            inline float getBoostPower() const
     91                { return this->boostPower_; }
     92            inline float getInitialBoostPower() const
     93                { return this->initialBoostPower_; }
    8094
    81             inline void setPermanentBoost(bool bPermanent)
    82                 { this->bPermanentBoost_ = bPermanent; }
    83             inline bool getPermanentBoost() const
    84                 { return this->bPermanentBoost_; }
     95            inline bool isBoostCoolingDown() const
     96                { return bBoostCooldown_; }
    8597
    8698        protected:
     
    90102            bool bBoost_;
    91103            bool bBoostCooldown_;
    92             bool bPermanentBoost_;
    93104            float boostPower_;
    94105            float initialBoostPower_;
     
    96107            float boostPowerRate_;
    97108            float boostCooldownDuration_;
     109            float lift_;
     110            float stallSpeed_;
    98111            Vector3 steering_;
    99112            float primaryThrust_;
     
    103116            btVector3 localAngularAcceleration_;
    104117
     118            float shakeFrequency_;
     119            float shakeAmplitude_;
     120
    105121        private:
    106122            void registerVariables();
    107123            virtual bool isCollisionTypeLegal(WorldEntity::CollisionType type) const;
     124           
     125            //All things booster
     126            void changedEnableMotionBlur();
     127            void boostCooledDown(void);
     128       
     129            void resetCamera();
     130            void backupCamera();
     131            void shakeCamera(float dt);
    108132
    109             void loadEngineTemplate();
    110            
    111             void boostCooledDown(void);
     133            Shader* boostBlur_;
     134            float blurStrength_;
     135            bool bEnableMotionBlur_;
    112136
    113             std::string enginetemplate_;
    114             Engine* engine_;
     137            std::vector<Engine*> engineList_;
     138            int engineTicksNotDone; // Used for knowing when to reset temporary variables.
    115139            Timer timer_;
     140            Vector3 cameraOriginalPosition_;
     141            Quaternion cameraOriginalOrientation_;
     142       
     143            float shakeDt_;
    116144    };
    117145}
Note: See TracChangeset for help on using the changeset viewer.