Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8201 for code/branches


Ignore:
Timestamp:
Apr 7, 2011, 4:11:20 PM (14 years ago)
Author:
kmaurus
Message:

healthDecreasing added, position of SpaceBoundaries added to the radar

Location:
code/branches/spaceboundaries
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.cc

    r8166 r8201  
    2929#include "SpaceBoundaries.h"
    3030
    31 /* Folgender Block ist Copy-Paste und somit teilweise wohl unnoetig */
    32 #include "core/Template.h"
    33 #include "core/XMLPort.h"
    34 #include "gametypes/Gametype.h"
    35 #include "worldentities/pawns/Pawn.h"
    36 
    37 /* Eigene, spezifische include-Statements*/
    3831#include "worldentities/MobileEntity.h"
    3932#include "worldentities/ControllableEntity.h"
    4033#include "core/ObjectListIterator.h"
    41 #include <worldentities/pawns/Pawn.h>
    42 #include <infos/PlayerInfo.h>
     34#include "core/XMLPort.h"
     35#include "worldentities/pawns/Pawn.h"
     36#include "infos/PlayerInfo.h"
     37#include "interfaces/RadarViewable.h"
     38
    4339
    4440//#include <OgreTextAreaOverlayElement.h>
     
    5248    SpaceBoundaries::SpaceBoundaries(BaseObject* creator) : StaticEntity(creator)
    5349    {
     50        /* Standardwerte, die zum Tragen kommen,
     51         * falls im XML-File keine Werte spezifiziert wurden. */
     52        this->setMaxDistance(3000);
     53        this->setWarnDistance(2000);
     54        this->setHealthDecrease(1);
     55       
    5456        RegisterObject(SpaceBoundaries);
    55         COUT(0) << "Test ob Konstruktor aufgerufen wird." << std::endl; //!< message for debugging
     57       
    5658        // Show Boundaries on the radar.
     59        this->centerRadar_ = new RadarViewable(this, this);
     60        this->centerRadar_->setRadarObjectShape(RadarViewable::Dot);
     61        this->centerRadar_->setRadarVisibility(false);
     62       
    5763//         m_pColoredTextAreaOverlayElementFactory = new ColoredTextAreaOverlayElementFactory();
    5864    }
    5965    SpaceBoundaries::~SpaceBoundaries()
    6066    {
     67        delete this->centerRadar_;
    6168//        delete pColoredTextAreaOverlayElementFactory;
    62     }
    63    
    64     void SpaceBoundaries::setCenter(Vector3 r)
    65     {
    66         this->center_ = r;
    67     }
    68     Vector3 SpaceBoundaries::getCenter()
    69     {
    70         return this->center_;
    7169    }
    7270   
     
    8886        return this->warnDistance_;
    8987    }
     88   
     89    void SpaceBoundaries::setHealthDecrease(float amount)
     90    {
     91        this->healthDecrease_ = amount/1000;
     92    }
     93    float SpaceBoundaries::getHealthDecrease()
     94    {
     95        return this->healthDecrease_;
     96    }
    9097
    9198    void SpaceBoundaries::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     
    93100        SUPER(SpaceBoundaries, XMLPort, xmlelement, mode);
    94101
    95         XMLPortParam(SpaceBoundaries, "center", setCenter, getCenter, xmlelement, mode);
    96102        XMLPortParam(SpaceBoundaries, "maxDistance", setMaxDistance, getMaxDistance, xmlelement, mode);
    97103        XMLPortParam(SpaceBoundaries, "warnDistance", setWarnDistance, getWarnDistance, xmlelement, mode);
     104        XMLPortParam(SpaceBoundaries, "healthDecrease", setHealthDecrease, getHealthDecrease, xmlelement, mode);
    98105    }
    99106   
     
    104111            MobileEntity* myMobileEntity = *item;
    105112            Pawn* myItem = dynamic_cast<Pawn*>(myMobileEntity);
    106             //COUT(0) << "Die for-Schleife wird erreicht!!!" << std::endl; //!< message for debugging
    107113            if(myItem != NULL)
    108114            {
    109115                float distance = computeDistance((WorldEntity*) myItem);
    110116                bool humanItem = this->isHumanPlayer(myItem);
    111                 COUT(0) << "Pawn wird erkannt!!!" << std::endl; //!< message for debugging
    112117                COUT(0) << "Distanz:" << distance << std::endl; //!< message for debugging
    113                 if(distance > this->warnDistance_ /*&& distance < this->maxDistance*/)
     118                if(distance > this->warnDistance_ && distance < this->maxDistance_)
    114119                {
    115120                    COUT(0) << "You are leaving the area" << std::endl; //!< message for debugging
     
    119124                        this->displayWarning("Attention! You are leaving the area!");
    120125                    } else {
    121                    
     126                       
    122127                    }
    123                 } else if(distance > maxDistance_)
     128                }
     129                if(distance > maxDistance_)
    124130                {
    125                     // Decrease Health
    126131                    if(humanItem)
    127132                    {
     133                        COUT(0) << "Health should be decreasing!" << std::endl;
     134                        this->displayWarning("You are out of the area now!");
     135                        myItem->removeHealth( (distance - maxDistance_) * this->healthDecrease_);
     136                    } else {
    128137                       
    129                     } else {
    130                    
    131138                    }
    132139                }
     
    138145    {
    139146        Vector3 itemPosition = item->getPosition();
    140         return (itemPosition.distance(this->center_));
     147        return (itemPosition.distance(this->getPosition()));
    141148    }
    142149   
     
    172179        if(item != NULL)
    173180        {
    174             return item->getPlayer()->isHumanPlayer();
    175         } else {
    176             return false;
     181            if(item->getPlayer())
     182            {
     183                return item->getPlayer()->isHumanPlayer();
     184            }
    177185        }
     186        return false;
    178187    }
    179188   
    180    
    181    
    182    
    183    
    184    
    185    
    186    
    187    
    188    
    189    
    190    
    191    
    192    
    193    
    194    
    195    
    196    
    197    
    198    
    199    
    200    
    201    
    202189}
  • code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.h

    r8166 r8201  
    2626 *
    2727 */
     28 
     29 /* TODO: - Markiere SpaceBoundaries-Position mit einem schoenen Objekt
     30          - Kugel-Model mal hinzufuegen, das nur sichtbar ist, wenn man genuegend nah an maxDistance dran ist
     31          - Reflexion an obiger Kugel beim Versuch durchzudringen
     32 */
    2833
    2934#ifndef _SpaceBoundaries_H__
    3035#define _SpaceBoundaries_H__
    3136
    32 /* Folgender Block ist Copy-Paste und somit teilweise wohl unnoetig */
    33 #include "OrxonoxPrereqs.h"
    34 #include "core/SubclassIdentifier.h"
    35 
    3637/* Einige, spezifische include-Statements */
    3738#include "core/CoreIncludes.h"
    3839#include "tools/interfaces/Tickable.h"
     40#include "interfaces/RadarViewable.h"
    3941#include "worldentities/StaticEntity.h"
    4042#include "worldentities/WorldEntity.h"
     
    4446#include <string>
    4547
     48/**
     49@brief SpaceBoundaries gives level creators the possibility to bar Pawns from leaving a defined area.
     50
     51       Four attributes can/should be defined in the XML-File:
     52       'position', 'warnDistance', 'maxDistance', 'healthDecrease'.
     53*/
    4654
    4755namespace orxonox
     
    5361            ~SpaceBoundaries();
    5462           
    55             void setCenter(Vector3 r);
    56             Vector3 getCenter();
    57            
    5863            void setMaxDistance(float r);
    5964            float getMaxDistance();
     
    6166            void setWarnDistance(float r);
    6267            float getWarnDistance();
     68           
     69            void setHealthDecrease(float amount);
     70            float getHealthDecrease();
    6371
    6472            void XMLPort(Element& xmlelement, XMLPort::Mode mode);
     
    6775
    6876        private:
    69             Vector3 center_;
    70             float maxDistance_;
    71             float warnDistance_;
     77            float maxDistance_; //!< maximal zulaessige Entfernung von 'this->getPosition()'.
     78            float warnDistance_; //!< Entfernung von 'this->getPosition()', ab der eine Warnung angezeigt wird, dass man bald das zulaessige Areal verlaesst.
     79           
     80            float healthDecrease_; //!< Mass fuer die Anzahl Health-Points, die nach ueberschreiten der Entfernung 'maxDistance_' von 'this->getPosition()' abgezogen werden.
     81                                   //!< Empfohlene Werte: 0.1 (langsame Health-Verminderung) bis 5 (sehr schnelle Health-Verminderung)
     82           
     83            RadarViewable* centerRadar_; //!< Repraesentation von 'this->getPosition()' auf dem Radar.
    7284       
    73             float computeDistance(WorldEntity *item); //!< Auf den Mittelpunkt 'center' bezogen.
     85            float computeDistance(WorldEntity *item); //!< Auf den Mittelpunkt 'this->getPosition()' bezogen.
    7486            void displayWarning(const std::string warnText);
    7587            bool isHumanPlayer(Pawn *item);
     88           
    7689 //           ColoredTextAreaOverlayElementFactory* pColoredTextAreaOverlayElementFactory;
    7790    };
Note: See TracChangeset for help on using the changeset viewer.