Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9016 for code/trunk/src


Ignore:
Timestamp:
Feb 15, 2012, 11:51:58 PM (13 years ago)
Author:
jo
Message:

Merging presentation2011 branch to trunk. Please check for possible bugs.

Location:
code/trunk
Files:
54 edited
14 copied

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/libraries/core/GUIManager.cc

    r8862 r9016  
    223223
    224224    GUIManager* GUIManager::singletonPtr_s = 0;
    225     /*static*/ const std::string GUIManager::defaultScheme_ = "TaharezGreen";
     225    /*static*/ const std::string GUIManager::defaultScheme_ = "TaharezGreen"; //Alternative: Orxonox (not fully complete yet, see the graphics menu)
    226226
    227227    SetConsoleCommand("showGUI", &GUIManager::showGUI).defaultValue(1, false).defaultValue(2, false);
  • code/trunk/src/libraries/util/SignalHandler.cc

    r8858 r9016  
    7070
    7171      catchSignal( SIGSEGV );
    72       catchSignal( SIGABRT );
     72      catchSignal( SIGABRT ); 
    7373      catchSignal( SIGILL );
    7474    }
     
    675675
    676676    /// Returns a description of the given exception.
    677     // Based on code from Dr. Mingw by José Fonseca
     677    // Based on code from Dr. Mingw by Jos\E9 Fonseca
    678678    /* static */ std::string SignalHandler::getExceptionType(PEXCEPTION_POINTERS pExceptionInfo)
    679679    {
     
    745745
    746746    /// Retrieves the base address of the module that contains the specified address.
    747     // Code from Dr. Mingw by José Fonseca
     747    // Code from Dr. Mingw by Jos\E9 Fonseca
    748748    /* static */ DWORD SignalHandler::getModuleBase(DWORD dwAddress)
    749749    {
  • code/trunk/src/modules/gametypes/CMakeLists.txt

    r8706 r9016  
    22  SpaceRace.cc
    33  RaceCheckPoint.cc
     4  SpaceRaceManager.cc
     5  OldSpaceRace.cc
     6  OldRaceCheckPoint.cc
    47)
    58
  • code/trunk/src/modules/gametypes/GametypesPrereqs.h

    r8706 r9016  
    6666{
    6767    class SpaceRace;
     68    class OldSpaceRace;
    6869}
    6970
  • code/trunk/src/modules/gametypes/RaceCheckPoint.cc

    r8858 r9016  
    3434#include "chat/ChatManager.h"
    3535
     36#include <infos/PlayerInfo.h>
     37#include <worldentities/ControllableEntity.h>
     38
    3639#include "SpaceRace.h"
    3740
     
    3942{
    4043    CreateFactory(RaceCheckPoint);
     44   
     45     
    4146
    42     RaceCheckPoint::RaceCheckPoint(BaseObject* creator): DistanceTrigger(creator), RadarViewable(creator, static_cast<WorldEntity*>(this))
     47    RaceCheckPoint::RaceCheckPoint(BaseObject* creator): DistanceMultiTrigger(creator), RadarViewable(creator, static_cast<WorldEntity*>(this))
    4348    {
    4449        RegisterObject(RaceCheckPoint);
    45 
    46         this->bCheckpointIndex_ = 0;
    47         this->bIsLast_ = false;
     50        this->setDistance(100);
     51        this->setBeaconMode("off");
     52        this->setBroadcast(false);
     53        this->setSimultaneousTriggerers(100);
    4854        this->bTimeLimit_ = 0;
    4955
     
    5157        this->setRadarObjectShape(RadarViewable::Triangle);
    5258        this->setRadarVisibility(false);
     59        this->settingsChanged();
     60        this->reached_=NULL;
     61     
    5362    }
     63   
    5464
    55     RaceCheckPoint::~RaceCheckPoint()
    56     {
    57     }
     65   RaceCheckPoint::~RaceCheckPoint()
     66   {
     67   
     68   }
    5869
    5970    void RaceCheckPoint::tick(float dt)
     
    6374        SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get());
    6475        assert(gametype);
    65         if (this->getCheckpointIndex() == gametype->getCheckpointsReached())
    66             this->setRadarVisibility(true);
    67         else
    68             this->setRadarVisibility(false);
    6976    }
    7077
     
    7279    {
    7380        SUPER(RaceCheckPoint, XMLPort, xmlelement, mode);
    74 
     81        Vector3 v= Vector3(0,0,0);
    7582        XMLPortParam(RaceCheckPoint, "checkpointindex", setCheckpointIndex, getCheckpointIndex, xmlelement, mode).defaultValues(0);
    7683        XMLPortParam(RaceCheckPoint, "islast", setLast, getLast, xmlelement, mode).defaultValues(false);
    7784        XMLPortParam(RaceCheckPoint, "timelimit", setTimelimit, getTimeLimit, xmlelement, mode).defaultValues(0);
     85    XMLPortParamTemplate(RaceCheckPoint, "nextcheckpoints", setNextcheckpoint, getNextcheckpoint, xmlelement, mode,const Vector3&).defaultValues(v);
    7886    }
    7987
    80     void RaceCheckPoint::triggered(bool bIsTriggered)
     88    void RaceCheckPoint::fire(bool bIsTriggered,BaseObject* player)
    8189    {
    82         DistanceTrigger::triggered(bIsTriggered);
    83 
     90        DistanceMultiTrigger::fire((bool)bIsTriggered,player);
     91       
    8492        SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get());
    85         if (gametype && this->getCheckpointIndex() == gametype->getCheckpointsReached() && bIsTriggered)
    86         {
    87             gametype->clock_.capture();
    88             float time = gametype->clock_.getSecondsPrecise();
    89             if (this->bTimeLimit_!=0 && time > this->bTimeLimit_)
    90             {
    91                 gametype->timeIsUp();
    92                 gametype->end();
    93             }
    94             else if (this->getLast())
    95                 gametype->end();
    96             else
    97             {
    98                 gametype->newCheckpointReached();
    99                 this->setRadarObjectColour(ColourValue::Green); //sets the radar colour of the checkpoint to green if it is reached, else it is red.
    100             }
    101         }
     93        assert(gametype);
     94        ControllableEntity* entity = (ControllableEntity*) player;
     95     
     96        PlayerInfo* player2 = entity->getPlayer();
     97     
     98        if(bIsTriggered)
     99            this->reached_=player2;
    102100    }
    103101
     
    108106        {
    109107            SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get());
     108            assert(gametype);
    110109            if (gametype)
    111110            {
  • code/trunk/src/modules/gametypes/RaceCheckPoint.h

    r8767 r9016  
    3232#include "gametypes/GametypesPrereqs.h"
    3333
    34 #include "objects/triggers/DistanceTrigger.h"
     34
     35
     36#include "objects/triggers/DistanceMultiTrigger.h"
    3537#include "interfaces/RadarViewable.h"
    3638
     
    4042    @brief
    4143        The RaceCheckPoint class enables the creation of a check point to use in a SpaceRace level.
    42         !!! Don't forget to control the indexes of your check points and to set one last check point!!!
     44         Don't forget to control the indexes of your check points and to set one last check point
    4345    */
    44     class _GametypesExport RaceCheckPoint : public DistanceTrigger, public RadarViewable
     46    class _GametypesExport RaceCheckPoint : public DistanceMultiTrigger, public RadarViewable
    4547    {
    4648        public:
     
    5052            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    5153            virtual void tick(float dt);
     54            inline void setCheckpointIndex(int checkpointIndex)
     55                { this->bCheckpointIndex_ = checkpointIndex; }
     56            inline int getCheckpointIndex()
     57                { return this->bCheckpointIndex_; }
    5258
    53             protected:
    54             virtual void triggered(bool bIsTriggered);
     59            inline void setNextcheckpoint(const Vector3& checkpoints)
     60                { this->nextcheckpoints_=checkpoints; }
     61            inline void setNextcheckpoint(float x, float y, float z)
     62                { this->setNextcheckpoint(Vector3(x, y, z)); }
     63            inline const Vector3& getNextcheckpoint() const
     64                { return this->nextcheckpoints_; }
    5565            inline void setLast(bool isLast)
    5666                { this->bIsLast_ = isLast; }
    5767            inline bool getLast()
    5868                { return this->bIsLast_; }
    59             inline void setCheckpointIndex(int checkpointIndex)
    60                 { this->bCheckpointIndex_ = checkpointIndex; }
    61             inline int getCheckpointIndex()
    62                 { return this->bCheckpointIndex_; }
     69
     70            bool bIsLast_; //True if this check point is the last of the level. There can be only one last check point for each level and there must be a last check point in the level.
     71            float bTimeLimit_; //The time limit (from the start of the level) to reach this check point. If the check point is reached after this time, the game ends and the player looses.
     72            PlayerInfo* reached_;
     73               
     74            inline float getTimeLimit()
     75                { return this->bTimeLimit_; }
     76   
     77        protected:
     78            virtual void fire(bool bIsTriggered,BaseObject* player);
    6379            virtual void setTimelimit(float timeLimit);
    64             inline float getTimeLimit()
    65                 { return this->bTimeLimit_;}
     80           
    6681            inline const WorldEntity* getWorldEntity() const
    6782                { return this; }
    6883
    6984        private:
    70             int bCheckpointIndex_; //The index of this check point. This value will be compared with the number of check points reached in the level. The check points must be indexed in ascending order beginning from zero and without any jumps between the indexes.
    71             bool bIsLast_; //True if this check point is the last of the level. There can be only one last check point for each level and there must be a last check point in the level.
    72             float bTimeLimit_; //The time limit (from the start of the level) to reach this check point. If the check point is reached after this time, the game ends and the player looses.
    73      
     85            int bCheckpointIndex_; //The index of this check point. The race starts with the check point with the index 0
     86            Vector3 nextcheckpoints_; //the indexes of the next check points
     87           
    7488    };
    7589}
  • code/trunk/src/modules/gametypes/SpaceRace.cc

    r8858 r9016  
    2929#include "SpaceRace.h"
    3030
     31
     32#include "items/Engine.h"
     33
    3134#include "core/CoreIncludes.h"
    3235#include "chat/ChatManager.h"
    3336#include "util/Convert.h"
    3437#include "util/Math.h"
     38
     39#include "items/Engine.h"
    3540
    3641namespace orxonox
     
    4146    {
    4247        RegisterObject(SpaceRace);
    43         this->checkpointsReached_ = 0;
     48       
    4449        this->bTimeIsUp_ = false;
    4550        this->numberOfBots_ = 0;
     51        this->cantMove_=false;
     52       
    4653    }
     54       
     55   
     56  // void SpaceRace::SetConfigValues(){
     57    //SUPER(Gametype,setConfigValues);
     58    //this->Gametype::SetConfigValue(initialStartCountdown_, 3.0f);}
    4759
    4860    void SpaceRace::end()
     
    5668            int ms = static_cast<int>(this->clock_.getMilliseconds()-1000*s);
    5769            const std::string& message = multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) + " seconds !!\n"
    58                         + "You didn't reach the check point " + multi_cast<std::string>(this->checkpointsReached_+1)
    59                         + " before the time limit. You lose!";
     70                        + "You didn't reach the check point  before the time limit. You lose!";
    6071            const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
    6172            ChatManager::message(message);
     
    7081            const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
    7182            ChatManager::message(message);
    72 /*
     83
    7384            float time = this->clock_.getSecondsPrecise();
    7485            this->scores_.insert(time);
    7586            std::set<float>::iterator it;
    76             for (it=this->scores_.begin(); it!=this->scores_.end(); it++)
    77                 orxout(level::message) << multi_cast<std::string>(*it) << endl;
    78 */
     87           
     88
    7989        }
    8090    }
     
    8292    void SpaceRace::start()
    8393    {
    84         Gametype::start();
    8594
    86         std::string message("The match has started! Reach the check points as quickly as possible!");
     95        this->spawnPlayersIfRequested();
     96        Gametype::checkStart();
     97        this->cantMove_=true;
     98       
     99        for(ObjectList<Engine>::iterator it = ObjectList<Engine>::begin(); it; ++it)
     100        {
     101            it->setActive(false);
     102           
     103        }
     104        this->addBots(this->numberOfBots_);
     105    }
     106   
     107    void SpaceRace::tick(float dt)
     108    {
     109        SUPER(SpaceRace,tick,dt);
     110   
     111        if(!this->isStartCountdownRunning() && this->cantMove_)
     112        {
     113            for(ObjectList<Engine>::iterator it = ObjectList<Engine>::begin(); it; ++it)
     114            {
     115                it->setActive(true);
     116               
     117            }
     118            this->cantMove_= false;
     119           
     120            std::string message("The match has started! Reach the check points as quickly as possible!");
     121            const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
     122            ChatManager::message(message);           
     123        }
     124   
     125    }
     126
     127   
     128   
     129    void SpaceRace::newCheckpointReached(SpaceRaceManager* p, int index,PlayerInfo* pl)
     130    {
     131        this->checkpointReached_[pl]=index;
     132        this->clock_.capture();
     133        int s = this->clock_.getSeconds();
     134        int ms = static_cast<int>(this->clock_.getMilliseconds()-1000*s);
     135        const std::string& message = "Checkpoint " + multi_cast<std::string>(index)
     136            + " reached after " + multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms)
     137            + " seconds.";// Message is too long for a normal screen.
    87138        const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
    88139        ChatManager::message(message);
    89140    }
    90 
    91     void SpaceRace::newCheckpointReached()
    92     {
    93         this->checkpointsReached_++;
     141   
     142    void SpaceRace::newCheckpointReached(RaceCheckPoint* p, PlayerInfo* pl)
     143    {   
     144        int index = p->getCheckpointIndex();
     145        this->checkpointReached_[pl]=index;
    94146        this->clock_.capture();
    95147        int s = this->clock_.getSeconds();
    96148        int ms = static_cast<int>(this->clock_.getMilliseconds()-1000*s);
    97         const std::string& message = "Checkpoint " + multi_cast<std::string>(this->getCheckpointsReached())
    98                         + " reached after " + multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms)
    99                         + " seconds.";
     149        const std::string& message = "Checkpoint " + multi_cast<std::string>(index)
     150            + " reached after " + multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms)
     151            + " seconds.";
    100152        const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
    101153        ChatManager::message(message);
    102154    }
     155       
     156   
     157    void SpaceRace::playerEntered(PlayerInfo* player)
     158    {
     159        Gametype::playerEntered(player);
     160   
     161        this->checkpointReached_[player]=-1;
     162        //this->playersAlive_++;
     163    }
     164   
     165    bool SpaceRace::playerLeft(PlayerInfo* player)
     166    {
     167        return Gametype::playerLeft(player);
     168        // bool valid_player = true;
     169        //if (valid_player)
     170       // {
     171        //    this->playersAlive_--;
     172        //}
    103173
     174       // return valid_player;
     175    }
     176   
     177    bool SpaceRace::allowPawnHit(Pawn* victim, Pawn* originator)
     178    {
     179        return false;
     180    }
     181
     182    bool SpaceRace::allowPawnDamage(Pawn* victim, Pawn* originator)
     183    {
     184        return false;
     185    }
     186
     187    bool SpaceRace::allowPawnDeath(Pawn* victim, Pawn* originator)
     188    {
     189        return false;
     190    }
    104191}
  • code/trunk/src/modules/gametypes/SpaceRace.h

    r8767 r9016  
    3434#include <set>
    3535#include <string>
     36# include <vector>
    3637
    3738#include <util/Clock.h>
     
    3940#include "gametypes/Gametype.h"
    4041
    41 #include "RaceCheckPoint.h"
     42#include "SpaceRaceManager.h"
    4243
    4344namespace orxonox
     
    5051    {
    5152        friend class RaceCheckPoint;
     53       
    5254
    5355        public:
     
    5860            virtual void end();
    5961
    60             virtual void newCheckpointReached();
     62            virtual void newCheckpointReached(SpaceRaceManager* p, int index,PlayerInfo* pl);
     63            virtual void newCheckpointReached(RaceCheckPoint* p, PlayerInfo* pl);
    6164
    62             inline void setCheckpointsReached(int n)
    63                 { this->checkpointsReached_ = n;}
    64             inline int getCheckpointsReached()
    65                 { return this->checkpointsReached_; }
     65            inline void setCheckpointReached(int n, PlayerInfo* p)
     66                { this->checkpointReached_[p] = n;}
     67            inline int getCheckpointReached(PlayerInfo* p)
     68                { return this->checkpointReached_[p]; }
     69
    6670            inline void timeIsUp()
    6771                { this->bTimeIsUp_ = true;}
     72            void tick(float dt);
     73            Clock clock_; //The clock starts running at the beginning of the game. It is used to give the time at each check point, the give the time at the end of the game, and to stop the game if a check point is reached too late.
    6874
     75
     76            bool allowPawnHit(Pawn* victim, Pawn* originator);
     77
     78            bool allowPawnDamage(Pawn* victim, Pawn* originator);
     79
     80            bool allowPawnDeath(Pawn* victim, Pawn* originator);
    6981        protected:
    70 
     82            virtual void playerEntered(PlayerInfo* player); //!< Initializes values.
     83            virtual bool playerLeft(PlayerInfo* player); //!< Manages all local variables.
    7184        private:
    72             int checkpointsReached_; //The current number of check points reached by the player.
     85            bool cantMove_;
     86            std::map<PlayerInfo*, int>checkpointReached_; //The number of the last check point reached by each player.
    7387            std::set<float> scores_; //The times of the players are saved in a set.
    7488            bool bTimeIsUp_; //True if one of the check points is reached too late.
    75             Clock clock_; //The clock starts running at the beginning of the game. It is used to give the time at each check point, the give the time at the end of the game, and to stop the game if a check point is reached too late.
     89           
     90            int playersAlive_;
    7691    };
    7792}
  • code/trunk/src/modules/objects/triggers/DistanceMultiTrigger.h

    r8706 r9016  
    9191    @ingroup MultiTrigger
    9292    */
    93     class _ObjectsExport DistanceMultiTrigger : public MultiTrigger
     93    class _ObjectsExport DistanceMultiTrigger : public MultiTrigger 
    9494    {
    9595
  • code/trunk/src/modules/objects/triggers/MultiTrigger.h

    r8457 r9016  
    157157            bool isTriggered(BaseObject* triggerer = NULL); //!< Get whether the MultiTrigger is triggered for a given object.
    158158
    159             void fire(bool status, BaseObject* originator = NULL);  //!< Helper method. Creates an Event for the given status and originator and fires it.
     159            virtual void fire(bool status, BaseObject* originator = NULL);  //!< Helper method. Creates an Event for the given status and originator and fires it.
    160160            void broadcast(bool status); //!< Helper method. Broadcasts an Event for every object that is a target.
    161161
  • code/trunk/src/modules/overlays/hud/CMakeLists.txt

    r8706 r9016  
    77  HUDHealthBar.cc
    88  HUDTimer.cc
     9  HUDEnemyHealthBar.cc
    910  ChatOverlay.cc
    1011  AnnounceMessage.cc
  • code/trunk/src/modules/overlays/hud/HUDHealthBar.h

    r7401 r9016  
    110110                { return this->textoverlay_->getSpaceWidth(); }
    111111
     112            inline void setOverlayText(SmartPtr<OverlayText> textoverlay)
     113                { this->textoverlay_ = textoverlay; }
     114            inline SmartPtr<OverlayText> getOverlayText() const
     115                {return this->textoverlay_; }
     116
    112117        private:
    113118            WeakPtr<Pawn> owner_;
  • code/trunk/src/modules/overlays/hud/HUDNavigation.cc

    r8891 r9016  
    2525 *      Reto Grieder
    2626 *      Oliver Scheuss
     27 *      Matthias Spalinger
    2728 *
    2829 */
     
    6364{
    6465  SetConfigValue(markerLimit_, 3);
    65 
     66  SetConfigValue(showDistance, false);
    6667}
    6768
     
    7576
    7677    // Set default values
    77     setFont ( "Monofur" );
    78     setTextSize ( 0.05f );
    79     setNavMarkerSize ( 0.05f );
    80     setDetectionLimit( 10000.0f );
     78    this->setFont ( "Monofur" );
     79    this->setTextSize ( 0.05f );
     80    this->setNavMarkerSize ( 0.05f );
     81    this->setDetectionLimit( 10000.0f );
    8182}
    8283
     
    9798    SUPER ( HUDNavigation, XMLPort, xmlelement, mode );
    9899
    99     XMLPortParam ( HUDNavigation, "font",           setFont,           getFont,           xmlelement, mode );
    100     XMLPortParam ( HUDNavigation, "textSize",       setTextSize,       getTextSize,       xmlelement, mode );
    101     XMLPortParam ( HUDNavigation, "navMarkerSize",  setNavMarkerSize,  getNavMarkerSize, xmlelement, mode );
    102     XMLPortParam ( HUDNavigation, "detectionLimit", setDetectionLimit, getDetectionLimit, xmlelement, mode );
     100    XMLPortParam ( HUDNavigation, "font",          setFont,          getFont,          xmlelement, mode );
     101    XMLPortParam ( HUDNavigation, "textSize",      setTextSize,      getTextSize,      xmlelement, mode );
     102    XMLPortParam ( HUDNavigation, "navMarkerSize", setNavMarkerSize, getNavMarkerSize, xmlelement, mode );
     103    XMLPortParam ( HUDNavigation, "detectionLimit", setDetectionLimit, getDetectionLimit, xmlelement, mode ); 
    103104}
    104105
     
    144145}
    145146
    146 
     147float HUDNavigation::getArrowSizeX(int dist)
     148{   
     149    if (dist < 600)
     150        dist = 600;
     151    return this->getActualSize().x * 900 * navMarkerSize_ / dist;
     152}
     153
     154float HUDNavigation::getArrowSizeY(int dist)
     155{   
     156    if (dist < 600)
     157        dist = 600;   
     158    return this->getActualSize().y * 900 * navMarkerSize_ / dist;
     159}
    147160
    148161void HUDNavigation::tick ( float dt )
     
    165178    unsigned int markerCount_ = 0;
    166179    bool closeEnough_ = false; //only display objects that are close enough to be relevant for the player
     180
    167181//         for (ObjectMap::iterator it = activeObjectList_.begin(); it != activeObjectList_.end(); ++it)
    168182    for ( sortedList::iterator listIt = sortedObjectList_.begin(); listIt != sortedObjectList_.end(); ++markerCount_, ++listIt )
     
    170184        ObjectMap::iterator it = activeObjectList_.find ( listIt->first );
    171185        closeEnough_ = listIt->second < detectionLimit_ ;
    172         if ( markerCount_ < markerLimit_ && (closeEnough_ ||  detectionLimit_ < 0) ) // display on HUD if the statement is true
     186        // display radarviewables on HUD if the marker limit and max-distance is not exceeded
     187        if ( markerCount_ < markerLimit_ && (closeEnough_ ||  detectionLimit_ < 0) )
    173188        {
    174189
     
    176191            // Get Distance to HumanController and save it in the TextAreaOverlayElement.
    177192            int dist = listIt->second;
     193            float textLength = 0.0f;
     194
     195            //display distance next to cursor
     196            if (showDistance){
    178197            it->second.text_->setCaption ( multi_cast<std::string> ( dist ) );
    179             float textLength = multi_cast<std::string> ( dist ).size() * it->second.text_->getCharHeight() * 0.3f;
     198            textLength = multi_cast<std::string> ( dist ).size() * it->second.text_->getCharHeight() * 0.3f;
     199            }
     200
     201            //display name next to cursor
     202            else{
     203            it->second.text_->setCaption(it->first->getRVName());
     204            textLength = it->first->getRVName().size() * it->second.text_->getCharHeight() * 0.3f;
     205            }
    180206
    181207            // Transform to screen coordinates
     
    194220            else
    195221                outOfView = pos.x < -1.0 || pos.x > 1.0 || pos.y < -1.0 || pos.y > 1.0;
    196             // Get Distance to HumanController and save it in the TextAreaOverlayElement.
    197             it->second.text_->setCaption ( multi_cast<std::string> ( dist ) );
    198222
    199223            if ( outOfView )
     
    207231                    it->second.wasOutOfView_ = true;
    208232                }
     233
     234                //float xDistScale = this->getActualSize().x * 1000.0f * navMarkerSize_ / dist;
     235                //float yDistScale = this->getActualSize().y * 1000.0f * navMarkerSize_ / dist;
     236
     237                // Adjust Arrowsize according to distance
     238                it->second.panel_->setDimensions(getArrowSizeX(dist),getArrowSizeY(dist));
    209239
    210240                // Switch between top, bottom, left and right position of the arrow at the screen border
     
    263293                  //it->second.panel_->setMaterialName ( "Orxonox/NavTDC" );
    264294                    it->second.panel_->setMaterialName( TextureGenerator::getMaterialName( "tdc.png", it->first->getRadarObjectColour()) );
     295                    it->second.panel_->setDimensions ( navMarkerSize_ * this->getActualSize().x, navMarkerSize_ * this->getActualSize().y );
    265296                    it->second.wasOutOfView_ = false;
    266297                }
     
    280311            it->second.text_->show();
    281312        }
    282         else // do not display on HUD
     313        else // do not display on HUD 
    283314        {
    284315            it->second.panel_->hide();
     
    312343void HUDNavigation::addObject ( RadarViewable* object )
    313344{
    314     if( showObject(object) == false )
     345    if( showObject(object)==false )
    315346        return;
    316347
     
    399430        return false;
    400431    assert( rv->getWorldEntity() );
    401     if ( rv->getWorldEntity()->isVisible() == false || rv->getRadarVisibility() == false )
     432    if ( rv->getWorldEntity()->isVisible()==false || rv->getRadarVisibility()==false )
    402433        return false;
    403434    return true;
  • code/trunk/src/modules/overlays/hud/HUDNavigation.h

    r8891 r9016  
    2424 *   Co-authors:
    2525 *      Reto Grieder
     26 *      Matthias Spalinger
    2627 *
    2728 */
     
    5455    virtual void tick ( float dt );
    5556
     57    // RadarListener interface
    5658    virtual void addObject ( RadarViewable* object );
    5759    virtual void removeObject ( RadarViewable* viewable );
     
    6668    inline float getRadarSensitivity() const
    6769    { return 1.0f; }
     70
     71    unsigned int getMarkerLimit() { return this->markerLimit_; }
    6872
    6973private:
     
    8185    // XMLPort accessors
    8286    void setNavMarkerSize ( float size )
    83     { navMarkerSize_ = size; this->sizeChanged(); }
     87        { navMarkerSize_ = size; this->sizeChanged(); }
    8488    float getNavMarkerSize() const
    85     { return navMarkerSize_; }
    86 
    87     void setDetectionLimit( float limit )
    88     { this->detectionLimit_ = limit; }
    89     float getDetectionLimit() const
    90     { return this->detectionLimit_; }
     89        { return navMarkerSize_; }
     90    void setDetectionLimit( float limit )
     91        { this->detectionLimit_ = limit; }
     92    float getDetectionLimit() const
     93        { return this->detectionLimit_; }
    9194
    9295    void setTextSize ( float size );
     
    102105    sortedList sortedObjectList_;
    103106
     107    float getArrowSizeX(int dist);   
     108    float getArrowSizeY(int dist);
    104109
    105110    float navMarkerSize_;
    106111    std::string fontName_;
    107112    float textSize_;
     113    bool showDistance;
    108114
    109     unsigned int markerLimit_; //TODO: is it possible to set this over the console and/or the IG-Setting
    110     float detectionLimit_; //!< Objects that are more far away than detectionLimit_ are not displayed on the HUD. 10000.0f is the default value.
    111                            //!< In order to bypass this behaviour, set a negative detectionLimit_. Then the detection range is "infinite".
     115    unsigned int markerLimit_;
     116    float detectionLimit_; //!< Objects that are more far away than detectionLimit_ are not displayed on the HUD. 10000.0f is the default value. 
     117
    112118};
    113119}
  • code/trunk/src/modules/pong/Pong.cc

    r8858 r9016  
    3737#include "core/EventIncludes.h"
    3838#include "core/command/Executor.h"
     39#include "core/ConfigValueIncludes.h"
    3940
    4041#include "gamestates/GSLevel.h"
     42#include "chat/ChatManager.h"
    4143
    4244#include "PongCenterpoint.h"
     
    4547#include "PongBot.h"
    4648#include "PongAI.h"
    47 
    4849namespace orxonox
    4950{
     
    7576        // Set the type of Bots for this particular Gametype.
    7677        this->botclass_ = Class(PongBot);
     78        this->scoreLimit_ = 10;
     79        this->setConfigValues();
    7780    }
    7881
     
    280283        }
    281284
     285        // If a palyer gets 21 points, he won the game -> end of game
     286       
     287        PlayerInfo* player1 = this->getLeftPlayer();
     288        PlayerInfo* player2 = this->getRightPlayer();
     289        if(player1==NULL||player2==NULL) return; //safety
     290        if(this->getScore(player1) >= scoreLimit_)
     291        {
     292            std::string name1=player1->getName();
     293            std::string message(name1 + " has won!");
     294            ChatManager::message(message);
     295            this->end();
     296        }
     297        else if(this->getScore(player2) >= scoreLimit_)
     298        {
     299             std::string name2=player2->getName();
     300             std::string message2(name2 + " has won!");
     301             ChatManager::message(message2);
     302             this->end();
     303        }
    282304        // Restart the timer to start the ball.
    283305        this->starttimer_.startTimer();
     306
    284307    }
    285308
     
    321344            return 0;
    322345    }
     346
     347    /**
     348     @brief
     349         Make scoreLimit_ configurable e.g. in the menu.
     350     */
     351    void Pong::setConfigValues()
     352    {
     353        SetConfigValue(scoreLimit_, 10).description("The player first reaching those points wins.");
     354    }
    323355}
  • code/trunk/src/modules/pong/Pong.h

    r8351 r9016  
    8181            void setCenterpoint(PongCenterpoint* center)
    8282                { this->center_ = center; }
    83 
    84             PlayerInfo* getLeftPlayer() const; //!< Get the left player.
     83            void setConfigValues(); //!< Makes scoreLimit configurable.
     84           
     85            PlayerInfo* getLeftPlayer() const; //!< Get the left player.
    8586            PlayerInfo* getRightPlayer() const; //!< Get the right player.
    8687
     
    9495            WeakPtr<PongBall> ball_; //!< The Pong ball.
    9596            WeakPtr<PongBat> bat_[2]; //!< The two bats.
    96             Timer starttimer_; //!< A timer to delay the start of the game.
     97            Timer starttimer_; //!< A timer to delay the start of the game.
     98            int scoreLimit_; //!< If a player scored that much points, the game is ended.
    9799    };
    98100}
  • code/trunk/src/modules/pong/PongAI.h

    r8108 r9016  
    8080            void delayedMove(); //!< Is called, when a delayed move takes effect.
    8181
    82             PongBall* ball_; //!< A pointer to the ball.
     82            WeakPtr<PongBall> ball_; //!< A weak pointer to the ball.
    8383            Vector2 ballDirection_; //!< Vector to store the (x,z) direction in which the ball is flying.
    8484            float ballEndPosition_; //!< The calculated end position of the ball.
  • code/trunk/src/modules/pong/PongScore.cc

    r8108 r9016  
    6060        this->bShowLeftPlayer_ = false;
    6161        this->bShowRightPlayer_ = false;
     62        this->player1_ = NULL;
     63        this->player2_ = NULL;
    6264    }
    6365
     
    98100        if (this->owner_ != NULL)
    99101        {
    100             // Get the two players.
    101             PlayerInfo* player1 = this->owner_->getLeftPlayer();
    102             PlayerInfo* player2 = this->owner_->getRightPlayer();
    103 
    104             std::string name1;
    105             std::string name2;
    106 
    107             std::string score1("0");
    108             std::string score2("0");
    109 
    110             // Save the name and score of each player as a string.
    111             if (player1 != NULL)
     102            if(!this->owner_->hasEnded())
    112103            {
    113                 name1 = player1->getName();
    114                 score1 = multi_cast<std::string>(this->owner_->getScore(player1));
    115             }
    116             if (player2 != NULL)
    117             {
    118                 name2 = player2->getName();
    119                 score2 = multi_cast<std::string>(this->owner_->getScore(player2));
     104                //get the two players
     105                player1_ = this->owner_->getLeftPlayer();
     106                player2_ = this->owner_->getRightPlayer();
    120107            }
    121108
    122             // Assemble the strings, depending on what should all be displayed.
    123             std::string output1;
    124             if (this->bShowLeftPlayer_)
     109            if(this->owner_->hasStarted())
    125110            {
    126                 if (this->bShowName_ && this->bShowScore_ && player1 != NULL)
    127                     output1 = name1 + " - " + score1;
    128                 else if (this->bShowScore_)
    129                     output1 = score1;
    130                 else if (this->bShowName_)
    131                     output1 = name1;
    132             }
     111                // Get the two players.
    133112
    134             std::string output2;
    135             if (this->bShowRightPlayer_)
    136             {
    137                 if (this->bShowName_ && this->bShowScore_ && player2 != NULL)
     113                std::string name1;
     114                std::string name2;
     115
     116                std::string score1("0");
     117                std::string score2("0");
     118
     119                // Save the name and score of each player as a string.
     120                if (player1_ != NULL)
     121                {
     122                    name1 = player1_->getName();
     123                    score1 = multi_cast<std::string>(this->owner_->getScore(player1_));
     124                }
     125                if (player2_ != NULL)
     126                {
     127                    name2 = player2_->getName();
     128                    score2 = multi_cast<std::string>(this->owner_->getScore(player2_));
     129                }
     130
     131                // Assemble the strings, depending on what should all be displayed.
     132                std::string output1;
     133                if (this->bShowLeftPlayer_)
     134                {
     135                    if (this->bShowName_ && this->bShowScore_ && player1_ != NULL)
     136                         output1 = name1 + " - " + score1;
     137                    else if (this->bShowScore_)
     138                         output1 = score1;
     139                    else if (this->bShowName_)
     140                         output1 = name1;
     141                }
     142
     143                std::string output2;
     144                if (this->bShowRightPlayer_)
     145                {
     146                if (this->bShowName_ && this->bShowScore_ && player2_ != NULL)
    138147                    output2 = score2 + " - " + name2;
    139148                else if (this->bShowScore_)
     
    143152            }
    144153
    145             std::string output("PONG");
    146             if (this->bShowName_ || this->bShowScore_)
    147             {
    148                 if (this->bShowLeftPlayer_ && this->bShowRightPlayer_)
    149                     output = output1 + ':' + output2;
    150                 else if (this->bShowLeftPlayer_ || this->bShowRightPlayer_)
    151                     output = output1 + output2;
     154                std::string output("PONG");
     155                if (this->bShowName_ || this->bShowScore_)
     156                {
     157                    if (this->bShowLeftPlayer_ && this->bShowRightPlayer_)
     158                        output = output1 + ':' + output2;
     159                    else if (this->bShowLeftPlayer_ || this->bShowRightPlayer_)
     160                        output = output1 + output2;
     161                }
     162                this->setCaption(output);
    152163            }
    153 
    154             this->setCaption(output);
    155164        }
    156165    }
  • code/trunk/src/modules/pong/PongScore.h

    r8108 r9016  
    122122            bool bShowLeftPlayer_; //!< Whether the left player is shown.
    123123            bool bShowRightPlayer_; //!< Whether the right player is shown.
     124            PlayerInfo* player1_; //!< Store information about left player permanently.
     125            PlayerInfo* player2_; //!< Same for the right player. To end the game properly.
    124126    };
    125127}
  • code/trunk/src/modules/weapons/projectiles/Rocket.cc

    r8891 r9016  
    6666        this->localAngularVelocity_ = 0;
    6767        this->lifetime_ = 100.0f;
    68         this->bIsRocket_= true;
    6968
    7069        if (GameMode::isMaster())
     
    135134        if(this->isInitialized())
    136135        {
    137             this->bIsRocket_= false;
    138136            if (GameMode::isMaster())
    139137            {
     
    163161       
    164162        this->player_ = this->getShooter()->getPlayer();
    165         this->getShooter()->getPlayer()->startTemporaryControl(this);
     163        if(this->player_)
     164            this->player_->startTemporaryControl(this);
    166165
    167166        if( GameMode::isMaster() )
  • code/trunk/src/modules/weapons/projectiles/Rocket.h

    r8855 r9016  
    122122
    123123            WeakPtr<PlayerInfo> player_; //!< The player that controls the Rocket.
     124            //WeakPtr<Pawn> pawn_; //!< The pawn that controls the Rocket. TODO
    124125            Timer destroyTimer_; //!< Timer to destroy the projectile after its lifetime has run out.
    125126            float lifetime_; //!< The time the projectile exists.
  • code/trunk/src/modules/weapons/weaponmodes/LightningGun.cc

    r8855 r9016  
    5252        this->reloadTime_ = 1.0f;
    5353        this->damage_ = 0.0f;
    54         this->speed_ = 250.0f;
     54        this->speed_ = 700.0f;
    5555
    5656        this->setMunitionName("LaserMunition");
  • code/trunk/src/orxonox/Level.cc

    r8858 r9016  
    7171        SUPER(Level, XMLPort, xmlelement, mode);
    7272
    73         XMLPortParam(Level, "description", setDescription, getDescription, xmlelement, mode);
    7473        XMLPortParam(Level, "gametype", setGametypeString, getGametypeString, xmlelement, mode).defaultValues("Gametype");
    7574
     
    8281        registerVariable(this->xmlfilename_,            VariableDirection::ToClient, new NetworkCallback<Level>(this, &Level::networkcallback_applyXMLFile));
    8382        registerVariable(this->name_,                   VariableDirection::ToClient, new NetworkCallback<Level>(this, &Level::changedName));
    84         registerVariable(this->description_,            VariableDirection::ToClient);
    8583        registerVariable(this->networkTemplateNames_,   VariableDirection::ToClient, new NetworkCallback<Level>(this, &Level::networkCallbackTemplatesChanged));
    8684    }
  • code/trunk/src/orxonox/Level.h

    r7163 r9016  
    4949            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    5050
    51             inline void setDescription(const std::string& description)
    52                 { this->description_ = description; }
    53             inline const std::string& getDescription() const
    54                 { return this->description_; }
    55 
    5651            void playerEntered(PlayerInfo* player);
    5752            void playerLeft(PlayerInfo* player);
     
    7671            void networkcallback_applyXMLFile();
    7772
    78             std::string                    description_;
    7973            std::string                    gametype_;
    8074            std::string                    xmlfilename_;
  • code/trunk/src/orxonox/LevelInfo.cc

    r8858 r9016  
    8787        {
    8888            LevelInfoItem::possibleTags_s.insert("test");
    89             LevelInfoItem::possibleTags_s.insert("singleplayer");
    90             LevelInfoItem::possibleTags_s.insert("multiplayer");
    9189            LevelInfoItem::possibleTags_s.insert("showcase");
    9290            LevelInfoItem::possibleTags_s.insert("tutorial");
    9391            LevelInfoItem::possibleTags_s.insert("presentation");
     92            LevelInfoItem::possibleTags_s.insert("mission");
     93            LevelInfoItem::possibleTags_s.insert("gametype");
     94            LevelInfoItem::possibleTags_s.insert("minigame");
    9495        }
    9596    }
     
    189190
    190191        XMLPortParam(LevelInfo, "description", setDescription, getDescription, xmlelement, mode);
     192        XMLPortParam(LevelInfo, "screenshot", setScreenshot, getScreenshot, xmlelement, mode);
    191193        XMLPortParam(LevelInfo, "tags", setTags, getTags, xmlelement, mode);
    192194    }
     
    203205        LevelInfoItem* info = new LevelInfoItem(this->BaseObject::getName(), this->getXMLFilename());
    204206        info->setDescription(this->getDescription());
     207        info->setScreenshot(this->getScreenshot());
    205208        info->setTags(this->getTags());
    206209        return info;
  • code/trunk/src/orxonox/LevelInfo.h

    r8079 r9016  
    7777            */
    7878            inline const std::string& getName(void) const { return this->name_; } // tolua_export
     79       
     80            /**
     81            @brief Set the screenshot of the Level.
     82            @param screenshot The screenshot to be set.
     83            */
     84            inline void setScreenshot(const std::string& screenshot) { this->screenshot_ = std::string(screenshot); }
     85            /**
     86            @brief Get the screenshot of the Level.
     87            @return Returns the screenshot of the Level.
     88            */
     89            inline const std::string& getScreenshot() const { return this->screenshot_; } // tolua_export
    7990
    8091            /**
     
    138149            std::string name_; //!< The name of the Level.
    139150            std::string description_; //!< The description of the Level.
     151            std::string screenshot_; //!< The screenshot of the Level.
    140152            std::set<std::string> tags_; //!< The set of tags the Level is tagged with.
    141153            std::string tagsString_; //!< The comma-seperated string of all the tags the Level is tagged with.
     
    148160        - @b name The name of the level.
    149161        - @b description The description of the level.
     162        - @b screenshot The screenshot of the level.
    150163        - @b tags A comma-seperated string of tags. Allowed tags are: <em>test</em>, <em>singleplayer</em>, <em>multiplayer</em>, <em>showcase</em>, <em>tutorial</em>, <em>presentation</em>.
    151164
     
    155168            name = "Levelname"lhs->compare(rhs) < 0
    156169            description = "This is just some awesome level."
     170            screenshot = "Screenshot.png"
    157171            tags = "test, awesome"
    158172        />
     
    172186
    173187            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Creates a LevelInfo object through XML.
     188       
     189            /**
     190            @brief Set the screenshot of the Level.
     191            @param screenshot The screenshot to be set.
     192            */
     193            inline void setScreenshot(const std::string& screenshot) { this->LevelInfoItem::setScreenshot(screenshot); }
     194            /**
     195            @brief Get the screenshot of the Level.
     196            @return Returns the screenshot of the Level.
     197            */
     198            inline const std::string& getScreenshot() const { return this->LevelInfoItem::getScreenshot(); }
    174199
    175200            /**
  • code/trunk/src/orxonox/controllers/AIController.cc

    r8891 r9016  
    5959        if (this->state_ == FREE)
    6060        {
    61 
     61           
    6262            if (this->formationFlight_)
    6363            {
     64
     65                //changed order -> searchNewMaster MUSTN'T be called in SLAVE-state (bugfix for internal-error messages at quit)
     66                random = rnd(maxrand);
     67                if (random < 90 && (((!this->target_) || (random < 50 && this->target_)) && !this->forcedFree()))
     68                       this->searchNewMaster();
     69
    6470                // return to Master after being forced free
    6571                if (this->freedomCount_ == 1)
     
    6874                    this->freedomCount_ = 0;
    6975                }
    70 
    71                 random = rnd(maxrand);
    72                 if (random < 90 && (((!this->target_) || (random < 50 && this->target_)) && !this->forcedFree()))
    73                     this->searchNewMaster();
    74             }
    75 
     76            }
     77
     78            this->defaultBehaviour(maxrand);
     79
     80        }
     81
     82        if (this->state_ == SLAVE && this->formationMode_ == ATTACK)
     83        {
    7684            // search enemy
    7785            random = rnd(maxrand);
    78             if (random < (15 + botlevel_* 20) && (!this->target_))
     86            if (random < (botlevel_*100) && (!this->target_))
    7987                this->searchNewTarget();
    8088
    81             // forget enemy
    82             random = rnd(maxrand);
    83             if (random < ((1-botlevel_)*6) && (this->target_))
    84                 this->forgetTarget();
    85 
    8689            // next enemy
    8790            random = rnd(maxrand);
    88             if (random < (botlevel_*20) && (this->target_))
     91            if (random < (botlevel_*30) && (this->target_))
    8992                this->searchNewTarget();
    9093
    91             // fly somewhere
    92             random = rnd(maxrand);
    93             if (random < 50 && (!this->bHasTargetPosition_ && !this->target_))
    94                 this->searchRandomTargetPosition();
    95 
    96             // stop flying
    97             random = rnd(maxrand);
    98             if (random < 10 && (this->bHasTargetPosition_ && !this->target_))
    99                 this->bHasTargetPosition_ = false;
    100 
    101             // fly somewhere else
    102             random = rnd(maxrand);
    103             if (random < 30 && (this->bHasTargetPosition_ && !this->target_))
    104                 this->searchRandomTargetPosition();
    105 
    10694            // shoot
    10795            random = rnd(maxrand);
    108             if (!(this->passive_) && random < (75 + botlevel_*25) && (this->target_ && !this->bShooting_))
     96            if (!(this->passive_) && random < (botlevel_*100) && (this->target_ && !this->bShooting_))
    10997                this->bShooting_ = true;
    11098
    11199            // stop shooting
    112100            random = rnd(maxrand);
    113             if (random < ((1 - botlevel_)*25) && (this->bShooting_))
     101            if (random < (1-botlevel_)*50 && (this->bShooting_))
    114102                this->bShooting_ = false;
    115103
    116             // boost
    117             random = rnd(maxrand);
    118             if (random < botlevel_*100 )
    119                 this->boostControl();
    120 
    121             // update Checkpoints
    122             /*random = rnd(maxrand);
    123             if (this->defaultWaypoint_ && random > (maxrand-10))
    124                 this->manageWaypoints();
    125             else //if(random > maxrand-10) //CHECK USABILITY!!*/
    126             if (this->waypoints_.size() == 0 )
    127                 this->manageWaypoints();
    128 
    129         }
    130 
    131         if (this->state_ == SLAVE)
    132         {
    133 
    134104        }
    135105
    136106        if (this->state_ == MASTER)
    137107        {
    138 
    139 
    140108            this->commandSlaves();
    141109
     
    155123                   this->spinInit();
    156124
    157                 // follow a randomly chosen human - a specific Master Action
     125                /*// follow a randomly chosen human - a specific Master Action
    158126                random = rnd(1000.0f);
    159127                if (random < 1)
    160128                   this->followRandomHumanInit();
    161 
     129*/
    162130                 // lose master status (only if less than 4 slaves in formation)
    163131                random = rnd(maxrand);
     
    170138                    this->searchNewMaster();
    171139
    172                 // search enemy
    173                 random = rnd(maxrand);
    174                 if (random < (botlevel_)*25 && (!this->target_))
    175                     this->searchNewTarget();
    176 
    177                 // forget enemy
    178                 random = rnd(maxrand);
    179                 if (random < (1-botlevel_)*6 && (this->target_))
    180                     this->forgetTarget();
    181 
    182                 // next enemy
    183                 random = rnd(maxrand);
    184                 if (random < 10 && (this->target_))
    185                     this->searchNewTarget();
    186 
    187                 // fly somewhere
    188                 random = rnd(maxrand);
    189                 if (random < 50 && (!this->bHasTargetPosition_ && !this->target_))
    190                     this->searchRandomTargetPosition();
    191 
    192 
    193                 // fly somewhere else
    194                 random = rnd(maxrand);
    195                 if (random < 30 && (this->bHasTargetPosition_ && !this->target_))
    196                     this->searchRandomTargetPosition();
    197 
    198                 // shoot
    199                 random = rnd(maxrand);
    200                 if (!(this->passive_) && random < 25*(botlevel_)+1 && (this->target_ && !this->bShooting_))
    201                 {
    202                     this->bShooting_ = true;
    203                     this->forceFreeSlaves();
    204                 }
    205 
    206                 // stop shooting
    207                 random = rnd(maxrand);
    208                 if (random < ( (1- botlevel_)*25 ) && (this->bShooting_))
    209                     this->bShooting_ = false;
    210 
    211                 // boost
    212                 random = rnd(maxrand);
    213                 if (random < botlevel_*100 )
    214                     this->boostControl();
    215 
    216                 // update Checkpoints
    217                 /*random = rnd(maxrand);
    218                 if (this->defaultWaypoint_ && random > (maxrand-10))
    219                     this->manageWaypoints();
    220                 else //if(random > maxrand-10) //CHECK USABILITY!!*/
    221                 if (this->waypoints_.size() == 0 )
    222                     this->manageWaypoints();
     140                this->defaultBehaviour(maxrand);
     141
    223142            }
    224143        }
     
    234153        float maxrand = 100.0f / ACTION_INTERVAL;
    235154        ControllableEntity* controllable = this->getControllableEntity();
    236 
     155        //DOES: Either move to the waypoint or search for a Point of interest
    237156        if (controllable && this->mode_ == DEFAULT)// bot is ready to move to a target
    238157        {
     
    256175            }
    257176        }
    258         if(this->mode_ == DEFAULT)
    259             {
     177
     178        if (this->mode_ == DEFAULT)
     179        {
    260180            if (this->state_ == MASTER)
    261181            {
     
    270190                            this->aimAtTarget();
    271191                            random = rnd(maxrand);
    272                             if(this->botlevel_*100 > random && !this->isCloseAtTarget(20))
     192                            if(this->botlevel_*70 > random && !this->isCloseAtTarget(100))
    273193                                this->follow();  //If a bot is shooting a player, it shouldn't let him go away easily.
    274194                        }
     
    277197                    if (this->bHasTargetPosition_)
    278198                        this->moveToTargetPosition();
    279 
    280199                    this->doFire();
    281200                }
     
    290209            }
    291210
    292             if (this->state_ == SLAVE)
     211            if (this->state_ == SLAVE && this->formationMode_ != ATTACK)
    293212            {
    294213                if (this->bHasTargetPosition_)
     
    296215            }
    297216
    298             if (this->state_ == FREE)
     217            if (this->state_ == FREE || (this->state_==SLAVE && this->formationMode_ == ATTACK) )
    299218            {
    300219                if (this->target_)
     
    302221                    if (!this->target_->getRadarVisibility()) /* So AI won't shoot invisible Spaceships */
    303222                        this->forgetTarget();
    304                     else
    305                     {
    306                         this->aimAtTarget();
    307                         random = rnd(maxrand);
    308 
    309                         if(this->botlevel_*100 > random && !this->isCloseAtTarget(20))
    310                             this->follow();//If a bot is shooting a player, it shouldn't let him go away easily.
    311                      }
     223                    else this->aimAtTarget();
    312224                }
    313225
     
    315227                    this->moveToTargetPosition();
    316228
    317                 this->doFire();
    318             }
    319         }//END_OF DEFAULT MODE
     229                    this->doFire();
     230            }
     231        }
    320232        else if (this->mode_ == ROCKET)//Rockets do not belong to a group of bots -> bot states are not relevant.
    321233        {   //Vector-implementation: mode_.back() == ROCKET;
    322234            if(controllable)
    323             {
    324                 if(controllable->getRocket())//Check wether the bot is controlling the rocket and if the timeout is over.
     235            {//Check wether the bot is controlling the rocket and if the timeout is over.
     236                if(controllable->getIdentifier() == ClassByString("Rocket"))
     237
    325238                {
    326239                    this->follow();
     
    341254        SUPER(AIController, tick, dt);
    342255    }
     256//**********************************************NEW
     257    void AIController::defaultBehaviour(float maxrand)
     258    {       float random;
     259            // search enemy
     260            random = rnd(maxrand);
     261            if (random < (botlevel_* 100) && (!this->target_))
     262                this->searchNewTarget();
     263
     264            // forget enemy
     265            random = rnd(maxrand);
     266            if (random < ((1-botlevel_)*20) && (this->target_))
     267                this->forgetTarget();
     268
     269            // next enemy
     270            random = rnd(maxrand);
     271            if (random < (botlevel_*30) && (this->target_))
     272                this->searchNewTarget();
     273
     274            // fly somewhere
     275            random = rnd(maxrand);
     276            if (random < 50 && (!this->bHasTargetPosition_ && !this->target_))
     277                this->searchRandomTargetPosition();
     278
     279            // stop flying
     280            random = rnd(maxrand);
     281            if (random < 10 && (this->bHasTargetPosition_ && !this->target_))
     282                this->bHasTargetPosition_ = false;
     283
     284            // fly somewhere else
     285            random = rnd(maxrand);
     286            if (random < 30 && (this->bHasTargetPosition_ && !this->target_))
     287                this->searchRandomTargetPosition();
     288
     289            if (this->state_ == MASTER) // master: shoot
     290            {
     291                random = rnd(maxrand);
     292                if (!(this->passive_) && random < (100*botlevel_) && (this->target_ && !this->bShooting_))
     293                {
     294                    this->bShooting_ = true;
     295                    this->forceFreeSlaves();
     296                }
     297            }
     298            else
     299            {
     300                // shoot
     301                random = rnd(maxrand);
     302                if (!(this->passive_) && random < (botlevel_*100) && (this->target_ && !this->bShooting_))
     303                    this->bShooting_ = true;
     304            }
     305
     306            // stop shooting
     307            random = rnd(maxrand);
     308            if (random < ((1 - botlevel_)*50) && (this->bShooting_))
     309                this->bShooting_ = false;
     310
     311            // boost
     312            random = rnd(maxrand);
     313            if (random < botlevel_*50 )
     314                this->boostControl();
     315
     316            // update Checkpoints
     317            /*random = rnd(maxrand);
     318            if (this->defaultWaypoint_ && random > (maxrand-10))
     319                this->manageWaypoints();
     320            else //if(random > maxrand-10) //CHECK USABILITY!!*/
     321            if (this->waypoints_.size() == 0 )
     322                this->manageWaypoints();
     323    }
    343324
    344325}
  • code/trunk/src/orxonox/controllers/AIController.h

    r8729 r9016  
    4444            virtual ~AIController();
    4545
    46             virtual void tick(float dt);
     46            virtual void tick(float dt); //<! Carrying out the targets set in action().
    4747
    4848        protected:
    49             virtual void action();
     49            virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour ~ setting targets.
     50            void defaultBehaviour(float maxrand); //<! Helper function for code reusage. Some concrete commands for a bot.
    5051
    5152        private:
    5253            static const float ACTION_INTERVAL;
    5354
    54             Timer actionTimer_;
     55            Timer actionTimer_; //<! Regularly calls action().
    5556    };
    5657}
  • code/trunk/src/orxonox/controllers/ArtificialController.cc

    r8892 r9016  
    2424 *   Co-authors:
    2525 *      Dominik Solenicki
    26  *
     26 *     
    2727 */
    2828
    2929#include "ArtificialController.h"
    30 
    31 #include <vector>
    32 #include <climits>
    33 
    34 #include "util/Math.h"
    3530#include "core/CoreIncludes.h"
    36 #include "core/XMLPort.h"
    3731#include "core/command/ConsoleCommand.h"
    38 #include "worldentities/ControllableEntity.h"
    3932#include "worldentities/pawns/Pawn.h"
    40 #include "worldentities/pawns/TeamBaseMatchBase.h"
    4133#include "worldentities/pawns/SpaceShip.h"
    42 #include "gametypes/TeamDeathmatch.h"
    43 #include "gametypes/Dynamicmatch.h"
    44 #include "controllers/WaypointPatrolController.h"
    45 #include "controllers/NewHumanController.h"
    46 #include "controllers/DroneController.h"
     34
    4735#include "weaponsystem/WeaponMode.h"
    4836#include "weaponsystem/WeaponPack.h"
     
    5139#include "weaponsystem/WeaponSlot.h"
    5240
     41
    5342namespace orxonox
    5443{
    55     SetConsoleCommand("ArtificialController", "formationflight",  &ArtificialController::formationflight);
    56     SetConsoleCommand("ArtificialController", "masteraction",     &ArtificialController::masteraction);
    57     SetConsoleCommand("ArtificialController", "followme",         &ArtificialController::followme);
    58     SetConsoleCommand("ArtificialController", "passivebehaviour", &ArtificialController::passivebehaviour);
    59     SetConsoleCommand("ArtificialController", "formationsize",    &ArtificialController::formationsize);
    6044    SetConsoleCommand("ArtificialController", "setbotlevel",      &ArtificialController::setAllBotLevel);
    6145
    62     static const unsigned int STANDARD_MAX_FORMATION_SIZE = 7;
    63     static const int RADIUS_TO_SEARCH_FOR_MASTERS = 5000;
    64     static const int FORMATION_LENGTH =  130;
    65     static const int FORMATION_WIDTH =  110;
    66     static const int FREEDOM_COUNT = 4; //seconds the slaves in a formation will be set free when master attacks an enemy
    67     static const float SPEED_MASTER = 0.6f;
    68     static const float ROTATEFACTOR_MASTER = 0.2f;
    69     static const float SPEED_FREE = 0.8f;
    70     static const float ROTATEFACTOR_FREE = 0.8f;
    71 
    72 
    73     ArtificialController::ArtificialController(BaseObject* creator) : Controller(creator)
    74     {
    75         RegisterObject(ArtificialController);
    76 
    77         this->target_ = 0;
    78         this->formationFlight_ = false;
    79         this->passive_ = false;
    80         this->maxFormationSize_ = STANDARD_MAX_FORMATION_SIZE;
    81         this->myMaster_ = 0;
    82         this->freedomCount_ = 0;
    83         this->team_ = -1;
    84         this->state_ = FREE;
    85         this->specificMasterAction_ = NONE;
    86         this->specificMasterActionHoldCount_  = 0;
    87         this->bShooting_ = false;
    88         this->bHasTargetPosition_ = false;
    89         this->speedCounter_ = 0.2f;
    90         this->targetPosition_ = Vector3::ZERO;
    91 
    92         this->target_.setCallback(createFunctor(&ArtificialController::targetDied, this));
     46    ArtificialController::ArtificialController(BaseObject* creator) : FormationController(creator)
     47    {
    9348        this->bSetupWorked = false;
    94         this->botlevel_ = 0.2f;
    95         this->mode_ = DEFAULT;////Vector-implementation: mode_.push_back(DEFAULT);
     49        this->botlevel_ = 0.5f;
    9650        this->timeout_ = 0;
    9751        this->currentWaypoint_ = 0;
    9852        this->setAccuracy(5);
    9953        this->defaultWaypoint_ = NULL;
     54        this->mode_ = DEFAULT;//Vector-implementation: mode_.push_back(DEFAULT);
    10055    }
    10156
     
    10560        {//Vector-implementation: mode_.erase(mode_.begin(),mode_.end());
    10661            this->waypoints_.clear();
    107             this->removeFromFormation();
    10862            this->weaponModes_.clear();
    109             for (ObjectList<ArtificialController>::iterator it = ObjectList<ArtificialController>::begin(); it; ++it)
    110             {
    111                 if (*it != this)
    112                 {
    113                     if (it->myMaster_ == this)
    114                     {
    115                         orxout(internal_error) << this << " is still master in " << (*it) << endl;
    116                         it->myMaster_ = 0;
    117                     }
    118 
    119                     while (true)
    120                     {
    121                         std::vector<ArtificialController*>::iterator it2 = std::find(it->slaves_.begin(), it->slaves_.end(), this);
    122                         if (it2 != it->slaves_.end())
    123                         {
    124                             orxout(internal_error) << this << " is still slave in " << (*it) << endl;
    125                             it->slaves_.erase(it2);
    126                         }
    127                         else
    128                             break;
    129                     }
    130                 }
    131             }
    132         }
    133     }
    134 
    135     void ArtificialController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    136     {
    137         SUPER(ArtificialController, XMLPort, xmlelement, mode);
    138 
    139         XMLPortParam(ArtificialController, "team", setTeam, getTeam, xmlelement, mode).defaultValues(-1);
    140         XMLPortParam(ArtificialController, "formationFlight", setFormationFlight, getFormationFlight, xmlelement, mode).defaultValues(false);
    141         XMLPortParam(ArtificialController, "formationSize", setFormationSize, getFormationSize, xmlelement, mode).defaultValues(STANDARD_MAX_FORMATION_SIZE);
    142         XMLPortParam(ArtificialController, "passive", setPassive, getPassive, xmlelement, mode).defaultValues(false);
    143     }
    144 
    145 // Documentation only here to get a faster overview for creating a useful documentation...
    146 
    147     /**
    148         @brief Activates / deactivates formationflight behaviour
    149         @param form activate formflight if form is true
    150     */
    151     void ArtificialController::formationflight(const bool form)
    152     {
    153         for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
    154         {
    155             Controller* controller = 0;
    156 
    157             if (it->getController())
    158                 controller = it->getController();
    159             else if (it->getXMLController())
    160                 controller = it->getXMLController();
    161 
    162             if (!controller)
    163                 continue;
    164 
    165             ArtificialController *aiController = orxonox_cast<ArtificialController*>(controller);
    166 
    167             if (aiController)
    168             {
    169                 aiController->formationFlight_ = form;
    170                 if (!form)
    171                 {
    172                     aiController->removeFromFormation();
    173                 }
    174             }
    175         }
    176     }
    177 
    178     /**
    179         @brief Get all masters to do a "specific master action"
    180         @param action which action to perform (integer, so it can be called with a console command (tmp solution))
    181     */
    182     void ArtificialController::masteraction(const int action)
    183     {
    184         for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
    185         {
    186             Controller* controller = 0;
    187 
    188             if (it->getController())
    189                 controller = it->getController();
    190             else if (it->getXMLController())
    191                 controller = it->getXMLController();
    192 
    193             if (!controller)
    194                 continue;
    195 
    196             ArtificialController *aiController = orxonox_cast<ArtificialController*>(controller);
    197 
    198             if(aiController && aiController->state_ == MASTER)
    199             {
    200                 if (action == 1)
    201                     aiController->spinInit();
    202                 if (action == 2)
    203                     aiController->turn180Init();
    204             }
    205         }
    206     }
    207 
    208     /**
    209         @brief A human player gets followed by its nearest master. Initiated by console command, so far intended for demonstration puproses (possible future pickup).
    210     */
    211     void ArtificialController::followme()
    212     {
    213 
    214         Pawn *humanPawn = NULL;
    215         NewHumanController *currentHumanController = NULL;
    216         std::vector<ArtificialController*> allMasters;
    217 
    218         for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
    219         {
    220             Controller* controller = 0;
    221 
    222             if (it->getController())
    223                 controller = it->getController();
    224             else if (it->getXMLController())
    225                 controller = it->getXMLController();
    226 
    227             if (!controller)
    228                 continue;
    229 
    230             currentHumanController = orxonox_cast<NewHumanController*>(controller);
    231 
    232             if(currentHumanController) humanPawn = *it;
    233 
    234             ArtificialController *aiController = orxonox_cast<ArtificialController*>(controller);
    235 
    236             if(aiController && aiController->state_ == MASTER)
    237                 allMasters.push_back(aiController);
    238 
    239         }
    240 
    241         if((humanPawn != NULL) && (allMasters.size() != 0))
    242         {
    243                 float posHuman = humanPawn->getPosition().length();
    244                 float distance = 0.0f;
    245                 float minDistance = FLT_MAX;
    246                 int index = 0;
    247                 int i = 0;
    248 
    249                 for(std::vector<ArtificialController*>::iterator it = allMasters.begin(); it != allMasters.end(); it++, i++)
    250                     {
    251                         if (!ArtificialController::sameTeam((*it)->getControllableEntity(), humanPawn, (*it)->getGametype())) continue;
    252                         distance = posHuman - (*it)->getControllableEntity()->getPosition().length();
    253                         if(distance < minDistance) index = i;
    254                     }
    255                 allMasters[index]->followInit(humanPawn);
    256             }
    257 
    258     }
    259 
    260     /**
    261         @brief Sets shooting behaviour of pawns.
    262         @param passive if true, bots won't shoot.
    263     */
    264     void ArtificialController::passivebehaviour(const bool passive)
    265     {
    266         for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
    267         {
    268             Controller* controller = 0;
    269 
    270             if (it->getController())
    271                 controller = it->getController();
    272             else if (it->getXMLController())
    273                 controller = it->getXMLController();
    274 
    275             if (!controller)
    276                 continue;
    277 
    278             ArtificialController *aiController = orxonox_cast<ArtificialController*>(controller);
    279 
    280             if(aiController)
    281             {
    282                 aiController->passive_ = passive;
    283             }
    284         }
    285     }
    286 
    287 
    288     /**
    289         @brief Sets maximal formation size
    290         @param size maximal formation size.
    291     */
    292     void ArtificialController::formationsize(const int size)
    293     {
    294         for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
    295         {
    296             Controller* controller = 0;
    297 
    298             if (it->getController())
    299                 controller = it->getController();
    300             else if (it->getXMLController())
    301                 controller = it->getXMLController();
    302 
    303             if (!controller)
    304                 continue;
    305 
    306             ArtificialController *aiController = orxonox_cast<ArtificialController*>(controller);
    307 
    308             if(aiController)
    309             {
    310                 aiController->maxFormationSize_ = size;
    311             }
    312         }
    313     }
     63        }
     64    }
     65
    31466
    31567    /**
     
    32072        if (!this->getControllableEntity())
    32173            this->removeFromFormation();
    322         this->bSetupWorked = false;        // reset weapon information
    323         this->setupWeapons();
    324     }
    325 
    326     void ArtificialController::removeFromFormation()
    327     {
    328         if (this->state_ == SLAVE || this->myMaster_) // slaves can also be temporary free, so check if myMaster_ is set
    329             this->unregisterSlave();
    330         else if (this->state_ == MASTER)
    331             this->setNewMasterWithinFormation();
    332     }
    333 
    334     void ArtificialController::moveToPosition(const Vector3& target)
    335     {
    336         if (!this->getControllableEntity())
    337             return;
    338 
    339         // Slave uses special movement if its master is in FOLLOW mode
    340         if(this->state_ == SLAVE && this->myMaster_ && this->myMaster_->specificMasterAction_ == FOLLOW)
    341         {
    342 //             this->followForSlaves(target);
    343 //             return;
    344         }
    345 
    346         Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
    347         float distance = (target - this->getControllableEntity()->getPosition()).length();
    348 
    349 
    350         if(this->state_ == FREE)
    351         {
    352             if (this->target_ || distance > 10)
    353             {
    354                 // Multiply with ROTATEFACTOR_FREE to make them a bit slower
    355                 this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_FREE * sgn(coord.x) * coord.x*coord.x);
    356                 this->getControllableEntity()->rotatePitch(ROTATEFACTOR_FREE * sgn(coord.y) * coord.y*coord.y);
    357             }
    358 
    359             if (this->target_ && distance < 200 && this->getControllableEntity()->getVelocity().squaredLength() > this->target_->getVelocity().squaredLength())
    360             {
    361               this->getControllableEntity()->moveFrontBack(-0.05f); // They don't brake with full power to give the player a chance
    362             } else this->getControllableEntity()->moveFrontBack(SPEED_FREE);
    363         }
    364 
    365 
    366 
    367         if(this->state_ == MASTER)
    368         {
    369             if (this->target_ || distance > 10)
    370             {
    371                 this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_MASTER * sgn(coord.x) * coord.x*coord.x);
    372                 this->getControllableEntity()->rotatePitch(ROTATEFACTOR_MASTER * sgn(coord.y) * coord.y*coord.y);
    373             }
    374 
    375             if (this->target_ && distance < 200 && this->getControllableEntity()->getVelocity().squaredLength() > this->target_->getVelocity().squaredLength())
    376             {
    377                 this->getControllableEntity()->moveFrontBack(-0.05f);
    378             } else this->getControllableEntity()->moveFrontBack(SPEED_MASTER);
    379         }
    380 
    381 
    382 
    383         if(this->state_ == SLAVE)
    384         {
    385 
    386            this->getControllableEntity()->rotateYaw(-2.0f * ROTATEFACTOR_MASTER * sgn(coord.x) * coord.x*coord.x);
    387            this->getControllableEntity()->rotatePitch(2.0f * ROTATEFACTOR_MASTER * sgn(coord.y) * coord.y*coord.y);
    388 
    389             if (distance < 300)
    390             {
    391                 if (distance < 40)
    392                 {
    393                     this->getControllableEntity()->moveFrontBack(0.8f*SPEED_MASTER);
    394                 } else this->getControllableEntity()->moveFrontBack(1.2f*SPEED_MASTER);
    395 
    396             } else {
    397                 this->getControllableEntity()->moveFrontBack(1.2f*SPEED_MASTER + distance/300.0f);
    398             }
    399         }
    400 
    401         if (distance < 10)
    402         {
    403             this->positionReached();
    404         }
    405     }
    406 
    407     void ArtificialController::absoluteMoveToPosition(const Vector3& target)
    408     {
    409         float minDistance = 40.0f;
    410         if (!this->getControllableEntity())
    411             return;
    412 
    413         Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
    414         float distance = (target - this->getControllableEntity()->getPosition()).length();
    415 
    416             if (this->target_ || distance > minDistance)
    417             {
    418                 // Multiply with ROTATEFACTOR_FREE to make them a bit slower
    419                 this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_FREE * sgn(coord.x) * coord.x*coord.x);
    420                 this->getControllableEntity()->rotatePitch(ROTATEFACTOR_FREE * sgn(coord.y) * coord.y*coord.y);
    421                 this->getControllableEntity()->moveFrontBack(SPEED_FREE);
    422             }
    423 
    424 
    425         if (distance < minDistance)
    426         {
    427             this->positionReached();
    428         }
    429     }
    430 
    431 
    432     void ArtificialController::moveToTargetPosition()
    433     {
    434         this->moveToPosition(this->targetPosition_);
    435     }
    436 
    437     /**
    438         @brief Unregisters a slave from its master. Initiated by a slave.
    439     */
    440     void ArtificialController::unregisterSlave()
    441     {
    442         if (this->myMaster_)
    443         {
    444             std::vector<ArtificialController*>::iterator it = std::find(this->myMaster_->slaves_.begin(), this->myMaster_->slaves_.end(), this);
    445             if (it != this->myMaster_->slaves_.end())
    446                 this->myMaster_->slaves_.erase(it);
    447         }
    448 
    449         this->myMaster_ = 0;
    450         this->state_ = FREE;
    451     }
    452 
    453     void ArtificialController::searchNewMaster()
    454     {
    455 
    456         if (!this->getControllableEntity())
    457             return;
    458 
    459         this->targetPosition_ = this->getControllableEntity()->getPosition();
    460         this->forgetTarget();
    461         int teamSize = 0;
    462         //go through all pawns
    463         for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
    464         {
    465             //same team?
    466             if (!ArtificialController::sameTeam(this->getControllableEntity(), static_cast<ControllableEntity*>(*it), this->getGametype()))
    467                 continue;
    468 
    469             //has it an ArtificialController?
    470             Controller* controller = 0;
    471 
    472             if (it->getController())
    473                 controller = it->getController();
    474             else if (it->getXMLController())
    475                 controller = it->getXMLController();
    476 
    477             if (!controller)
    478                 continue;
    479 
    480             //is pawn oneself?
    481             if (orxonox_cast<ControllableEntity*>(*it) == this->getControllableEntity())
    482                 continue;
    483 
    484             teamSize++;
    485 
    486             ArtificialController *newMaster = orxonox_cast<ArtificialController*>(controller);
    487 
    488             //is it a master?
    489             if (!newMaster || newMaster->state_ != MASTER)
    490                 continue;
    491 
    492             float distance = (it->getPosition() - this->getControllableEntity()->getPosition()).length();
    493 
    494             // is pawn in range?
    495             if (distance < RADIUS_TO_SEARCH_FOR_MASTERS)
    496             {
    497                 if(newMaster->slaves_.size() > this->maxFormationSize_) continue;
    498 
    499                 for(std::vector<ArtificialController*>::iterator itSlave = this->slaves_.begin(); itSlave != this->slaves_.end(); itSlave++)
    500                 {
    501                     (*itSlave)->myMaster_ = newMaster;
    502                     newMaster->slaves_.push_back(*itSlave);
    503                 }
    504                 this->slaves_.clear();
    505                 this->state_ = SLAVE;
    506 
    507                 this->myMaster_ = newMaster;
    508                 newMaster->slaves_.push_back(this);
    509 
    510                 break;
    511             }
    512         }
    513 
    514         if (this->state_ != SLAVE  && teamSize != 0)
    515         {
    516             this->state_ = MASTER;
    517             this->myMaster_ = 0;
    518         }
    519     }
    520 
    521     /**
    522         @brief Commands the slaves of a master into a formation. Sufficiently fast not to be called within tick. Initiated by a master.
    523     */
    524     void ArtificialController::commandSlaves()
    525     {
    526         if(this->state_ != MASTER) return;
    527 
    528         Quaternion orient = this->getControllableEntity()->getOrientation();
    529         Vector3 dest = this->getControllableEntity()->getPosition();
    530 
    531         // 1 slave: follow
    532         if (this->slaves_.size() == 1)
    533         {
    534             dest += 4*orient*WorldEntity::BACK;
    535             this->slaves_.front()->setTargetPosition(dest);
    536         }
    537         else
    538         {
    539             dest += 1.0f*orient*WorldEntity::BACK;
    540             Vector3 pos = Vector3::ZERO;
    541             int i = 1;
    542 
    543             for(std::vector<ArtificialController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++)
    544             {
    545                 pos = Vector3::ZERO;
    546                 if (i <= 1) pos += dest  + (float)FORMATION_WIDTH*(orient*WorldEntity::LEFT);
    547                 if (i == 2) pos += dest  + (float)FORMATION_WIDTH*(orient*WorldEntity::RIGHT);
    548                 if (i == 3) pos += dest  + (float)FORMATION_WIDTH*(orient*WorldEntity::UP);
    549                 if (i >= 4)
    550                 {
    551                     pos += dest  + (float)FORMATION_WIDTH*(orient*WorldEntity::DOWN);
    552                     i = 1;
    553                     dest += (float)FORMATION_LENGTH*(orient*WorldEntity::BACK);
    554                     (*it)->setTargetPosition(pos);
    555                     continue;
    556                 }
    557                 i++;
    558                 (*it)->setTargetPosition(pos);
    559             }
    560         }
    561     }
    562 
    563     /**
    564         @brief Sets a new master within the formation. Called by a master.
    565     */
    566     void ArtificialController::setNewMasterWithinFormation()
    567     {
    568         if(this->state_ != MASTER) return;
    569 
    570         if (!this->slaves_.empty())
    571         {
    572             ArtificialController *newMaster = this->slaves_.back();
    573             this->slaves_.pop_back();
    574 
    575             newMaster->state_ = MASTER;
    576             newMaster->slaves_ = this->slaves_;
    577             newMaster->myMaster_ = 0;
    578 
    579             for(std::vector<ArtificialController*>::iterator it = newMaster->slaves_.begin(); it != newMaster->slaves_.end(); it++)
    580             {
    581                 (*it)->myMaster_ = newMaster;
    582             }
    583         }
    584 
    585         this->slaves_.clear();
    586         this->specificMasterAction_ = NONE;
    587         this->state_ = FREE;
    588     }
    589 
    590     /**
    591         @brief Frees all slaves form a master. Initiated by a master.
    592     */
    593     void ArtificialController::freeSlaves()
    594     {
    595         if(this->state_ != MASTER) return;
    596 
    597         for(std::vector<ArtificialController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++)
    598         {
    599             (*it)->state_ = FREE;
    600             (*it)->myMaster_ = 0;
    601         }
    602         this->slaves_.clear();
    603     }
    604 
    605     /**
    606         @brief Master sets its slaves free for @ref FREEDOM_COUNT seconds.
    607     */
    608     void ArtificialController::forceFreeSlaves()
    609     {
    610         if(this->state_ != MASTER) return;
    611 
    612         for(std::vector<ArtificialController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++)
    613         {
    614             (*it)->state_ = FREE;
    615             (*it)->forceFreedom();
    616             (*it)->targetPosition_ = this->targetPosition_;
    617             (*it)->bShooting_ = true;
    618 //             (*it)->getControllableEntity()->fire(0);// fire once for fun
    619         }
    620     }
    621 
    622     void ArtificialController::loseMasterState()
    623     {
    624         this->freeSlaves();
    625         this->state_ = FREE;
    626     }
    627 
    628 
    629     void ArtificialController::forceFreedom()
    630     {
    631         this->freedomCount_ = FREEDOM_COUNT;
    632     }
    633 
    634     /**
    635         @brief Checks wether caller has been forced free, decrements time to stay forced free.
    636         @return true if forced free.
    637     */
    638     bool ArtificialController::forcedFree()
    639     {
    640         if(this->freedomCount_ > 0)
    641         {
    642             this->freedomCount_--;
    643             return true;
    644         } else return false;
    645     }
    646 
    647     /**
    648         @brief Used to continue a "specific master action" for a certain time and resuming normal behaviour after.
    649     */
    650     void ArtificialController::specificMasterActionHold()
    651     {
    652         if(this->state_ != MASTER) return;
    653 
    654         if (specificMasterActionHoldCount_ == 0)
    655          {
    656             this->specificMasterAction_ = NONE;
    657             this->searchNewTarget();
    658          }
    659         else specificMasterActionHoldCount_--;
    660     }
    661 
    662     /**
    663         @brief Master initializes a 180 degree turn. Leads to a "specific master action".
    664     */
    665     void ArtificialController::turn180Init()
    666     {
    667         if(this->state_ != MASTER) return;
    668 
    669         Quaternion orient = this->getControllableEntity()->getOrientation();
    670 
    671         this->setTargetPosition(this->getControllableEntity()->getPosition() + 1000.0f*orient*WorldEntity::BACK);
    672 
    673         this->specificMasterActionHoldCount_ = 4;
    674 
    675         this->specificMasterAction_ = TURN180;
    676     }
    677 
    678     /**
    679         @brief Execute the 180 degree turn. Called within tick.
    680     */
    681     void ArtificialController::turn180()
    682     {
    683             Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, this->targetPosition_);
    684 
    685             this->getControllableEntity()->rotateYaw(-2.0f * sgn(coord.x) * coord.x*coord.x);
    686             this->getControllableEntity()->rotatePitch(2.0f * sgn(coord.y) * coord.y*coord.y);
    687 
    688             this->getControllableEntity()->moveFrontBack(SPEED_MASTER);
    689     }
    690 
    691     /**
    692         @brief Master initializes a spin around its looking direction axis. Leads to a "specific master action".
    693     */
    694     void ArtificialController::spinInit()
    695     {
    696         if(this->state_ != MASTER) return;
    697         this->specificMasterAction_ = SPIN;
    698         this->specificMasterActionHoldCount_ = 10;
    699     }
    700 
    701     /**
    702         @brief Execute the spin. Called within tick.
    703     */
    704     void ArtificialController::spin()
    705     {
    706             this->moveToTargetPosition();
    707             this->getControllableEntity()->rotateRoll(0.8f);
    708     }
    709 
    710     /**
    711         @brief Master begins to follow a pawn. Is a "specific master action".
    712         @param pawn pawn to follow.
    713         @param always follows pawn forever if true (false if omitted).
    714         @param secondsToFollow seconds to follow the pawn if always is false. Will follow pawn 100 seconds if omitted (set in header).
    715     */
    716     void ArtificialController::followInit(Pawn* pawn, const bool always, const int secondsToFollow)
    717     {
    718         if (pawn == NULL || this->state_ != MASTER)
    719             return;
    720         this->specificMasterAction_  =  FOLLOW;
    721 
    722         this->setTarget(pawn);
    723         if (!always)
    724             this->specificMasterActionHoldCount_ = secondsToFollow;
    725         else
    726             this->specificMasterActionHoldCount_ = INT_MAX; //for now...
    727 
    728     }
    729 
    730 
    731     /**
    732         @brief Master begins to follow a randomly chosen human player of the same team. Is a "specific master action".
    733     */
    734     void ArtificialController::followRandomHumanInit()
    735     {
    736 
    737         Pawn *humanPawn = NULL;
    738         NewHumanController *currentHumanController = NULL;
    739 
    740         for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
    741         {
    742             if (!it->getController())
    743                 continue;
    744 
    745             currentHumanController = orxonox_cast<NewHumanController*>(it->getController());
    746             if(currentHumanController)
    747             {
    748                 if (!ArtificialController::sameTeam(this->getControllableEntity(), *it, this->getGametype())) continue;
    749                 humanPawn = *it;
    750                 break;
    751             }
    752         }
    753 
    754         if((humanPawn != NULL))
    755                 this->followInit(humanPawn);
    756     }
    757 
    758     /**
    759         @brief Master follows target with adjusted speed. Called within tick.
    760     */
    761     void ArtificialController::follow()
    762     {
    763         if (this->target_)
    764             this->moveToPosition(this->target_->getPosition());
    765         else
    766             this->specificMasterActionHoldCount_ = 0;
    767 /*
    768         if (!this->getControllableEntity())
    769             return;
    770 
    771         float distance = (this->target_->getPosition() - this->getControllableEntity()->getPosition()).length();
    772 
    773         Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, this->target_->getPosition());
    774 
    775 
    776         this->getControllableEntity()->rotateYaw(-0.8f * sgn(coord.x) * coord.x*coord.x);
    777         this->getControllableEntity()->rotatePitch(0.8f * sgn(coord.y) * coord.y*coord.y);
    778 
    779         float speedDiv = this->getControllableEntity()->getVelocity().squaredLength() - this->target_->getVelocity().squaredLength();
    780 
    781 orxout() << "~follow distance: " << distance << "SpeedCounter: " << this->speedCounter_ << "~speedDiv: " << speedDiv << endl;
    782         if (distance < 800)
    783         {
    784             if (distance < 200)
    785             {
    786                 this->speedCounter_ -= 0.5f;
    787                 if(this->speedCounter_ < 0) this->speedCounter_ = 0.0f;
    788                 this->getControllableEntity()->moveFrontBack(speedCounter_);
    789             } else {
    790                 if(speedDiv < 0)
    791                     this->speedCounter_ +=  0.01f;
    792                 else
    793                     this->speedCounter_ -= 0.05f;
    794                 this->getControllableEntity()->moveFrontBack(speedCounter_);
    795             }
    796 
    797         } else {
    798             this->speedCounter_ += 0.05f;
    799             this->getControllableEntity()->moveFrontBack(speedCounter_ + distance/300.0f);
    800         }
    801 //         if (this->getControllableEntity()->getVelocity().squaredLength() > 50.0f) this->speedCounter_ = 0;
    802 
    803 */
    804     }
    805 
    806 
    807     /**
    808         @brief Slave moving behaviour when master is following a pawn, gets redirected from moveToPosition(const Vector3& target)). Called within tick.
    809     */
    810     void ArtificialController::followForSlaves(const Vector3& target)
    811     {
    812 
    813 /*
    814         if (!this->getControllableEntity() && !this->myMaster_ && this->myMaster_->state_ != FOLLOW && !this->myMaster_->target_)
    815             return;
    816 
    817         float distance = (target - this->getControllableEntity()->getPosition()).length();
    818 
    819         Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
    820 
    821 
    822         this->getControllableEntity()->rotateYaw(-0.8f * sgn(coord.x) * coord.x*coord.x);
    823         this->getControllableEntity()->rotatePitch(0.8f * sgn(coord.y) * coord.y*coord.y);
    824 
    825 
    826         float speedDiv = this->getControllableEntity()->getVelocity().squaredLength() - this->myMaster_->target_->getVelocity().squaredLength();
    827 
    828 
    829          if (distance < 800)
    830         {
    831             if (distance < 200)
    832             {
    833                 this->speedCounter_ -= 5.0f;
    834                 if(this->speedCounter_ < 0) this->speedCounter_ = 0.0f;
    835                 this->getControllableEntity()->moveFrontBack(speedCounter_);
    836             } else {
    837                 if(speedDiv < 0)
    838                     this->speedCounter_ +=  0.01f;
    839                 else
    840                     this->speedCounter_ -= 0.05f;
    841                 this->getControllableEntity()->moveFrontBack(speedCounter_);
    842             }
    843 
    844         } else {
    845             this->speedCounter_ += 0.05f;
    846             this->getControllableEntity()->moveFrontBack(speedCounter_ + distance/300.0f);
    847         }
    848 //         if (this->getControllableEntity()->getVelocity().squaredLength() > 50.0f) this->speedCounter_ = 0;
    849 */
    850     }
    851 
    852 
    853     void ArtificialController::setTargetPosition(const Vector3& target)
    854     {
    855         this->targetPosition_ = target;
    856         this->bHasTargetPosition_ = true;
    857     }
    858 
    859     void ArtificialController::searchRandomTargetPosition()
    860     {
    861         this->targetPosition_ = Vector3(rnd(-2000,2000), rnd(-2000,2000), rnd(-2000,2000));
    862         this->bHasTargetPosition_ = true;
    863     }
    864 
    865     void ArtificialController::setTarget(Pawn* target)
    866     {
    867         this->target_ = target;
    868 
    869         if (target)
    870             this->targetPosition_ = target->getPosition();
    871     }
    872 
    873     void ArtificialController::searchNewTarget()
    874     {
    875         if (!this->getControllableEntity())
    876             return;
    877 
    878         this->targetPosition_ = this->getControllableEntity()->getPosition();
    879         this->forgetTarget();
    880 
    881         for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
    882         {
    883             if (ArtificialController::sameTeam(this->getControllableEntity(), static_cast<ControllableEntity*>(*it), this->getGametype()))
    884                 continue;
    885 
    886             /* So AI won't choose invisible Spaceships as target */
    887             if (!it->getRadarVisibility())
    888                 continue;
    889 
    890             if (static_cast<ControllableEntity*>(*it) != this->getControllableEntity())
    891             {
    892                 float speed = this->getControllableEntity()->getVelocity().length();
    893                 Vector3 distanceCurrent = this->targetPosition_ - this->getControllableEntity()->getPosition();
    894                 Vector3 distanceNew = it->getPosition() - this->getControllableEntity()->getPosition();
    895                 if (!this->target_ || it->getPosition().squaredDistance(this->getControllableEntity()->getPosition()) * (1.5f + acos((this->getControllableEntity()->getOrientation() * WorldEntity::FRONT).dotProduct(distanceNew) / speed / distanceNew.length()) / math::twoPi)
    896                         < this->targetPosition_.squaredDistance(this->getControllableEntity()->getPosition()) * (1.5f + acos((this->getControllableEntity()->getOrientation() * WorldEntity::FRONT).dotProduct(distanceCurrent) / speed / distanceCurrent.length()) / math::twoPi) + rnd(-250, 250))
    897                 {
    898                     this->target_ = (*it);
    899                     this->targetPosition_ = it->getPosition();
    900                 }
    901             }
    902         }
    903     }
    904 
    905     void ArtificialController::forgetTarget()
    906     {
    907         this->target_ = 0;
    908         this->bShooting_ = false;
    909     }
     74    }
     75
    91076
    91177    void ArtificialController::aimAtTarget()
     
    947113        if (target == this->target_)
    948114            this->targetDied();
    949     }
    950 
    951     void ArtificialController::targetDied()
    952     {
    953         this->forgetTarget();
    954         this->searchRandomTargetPosition();
    955     }
    956 
    957     bool ArtificialController::sameTeam(ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype)
    958     {
    959         if(!entity1 || !entity2)
    960             return true;
    961         if (entity1 == entity2)
    962             return true;
    963 
    964         int team1 = -1;
    965         int team2 = -1;
    966 
    967         Controller* controller = 0;
    968         if (entity1->getController())
    969             controller = entity1->getController();
    970         else
    971             controller = entity1->getXMLController();
    972         if (controller)
    973         {
    974             ArtificialController* ac = orxonox_cast<ArtificialController*>(controller);
    975             if (ac)
    976                 team1 = ac->getTeam();
    977         }
    978 
    979         if (entity2->getController())
    980             controller = entity2->getController();
    981         else
    982             controller = entity2->getXMLController();
    983         if (controller)
    984         {
    985             ArtificialController* ac = orxonox_cast<ArtificialController*>(controller);
    986             if (ac)
    987                 team2 = ac->getTeam();
    988         }
    989 
    990         TeamDeathmatch* tdm = orxonox_cast<TeamDeathmatch*>(gametype);
    991         if (tdm)
    992         {
    993             if (entity1->getPlayer())
    994                 team1 = tdm->getTeam(entity1->getPlayer());
    995 
    996             if (entity2->getPlayer())
    997                 team2 = tdm->getTeam(entity2->getPlayer());
    998         }
    999 
    1000         TeamBaseMatchBase* base = 0;
    1001         base = orxonox_cast<TeamBaseMatchBase*>(entity1);
    1002         if (base)
    1003         {
    1004             switch (base->getState())
    1005             {
    1006                 case BaseState::ControlTeam1:
    1007                     team1 = 0;
    1008                     break;
    1009                 case BaseState::ControlTeam2:
    1010                     team1 = 1;
    1011                     break;
    1012                 case BaseState::Uncontrolled:
    1013                 default:
    1014                     team1 = -1;
    1015             }
    1016         }
    1017         base = orxonox_cast<TeamBaseMatchBase*>(entity2);
    1018         if (base)
    1019         {
    1020             switch (base->getState())
    1021             {
    1022                 case BaseState::ControlTeam1:
    1023                     team2 = 0;
    1024                     break;
    1025                 case BaseState::ControlTeam2:
    1026                     team2 = 1;
    1027                     break;
    1028                 case BaseState::Uncontrolled:
    1029                 default:
    1030                     team2 = -1;
    1031             }
    1032         }
    1033 
    1034         DroneController* droneController = 0;
    1035         droneController = orxonox_cast<DroneController*>(entity1->getController());
    1036         if (droneController && static_cast<ControllableEntity*>(droneController->getOwner()) == entity2)
    1037             return true;
    1038         droneController = orxonox_cast<DroneController*>(entity2->getController());
    1039         if (droneController && static_cast<ControllableEntity*>(droneController->getOwner()) == entity1)
    1040             return true;
    1041         DroneController* droneController1 = orxonox_cast<DroneController*>(entity1->getController());
    1042         DroneController* droneController2 = orxonox_cast<DroneController*>(entity2->getController());
    1043         if (droneController1 && droneController2 && droneController1->getOwner() == droneController2->getOwner())
    1044             return true;
    1045 
    1046         Dynamicmatch* dynamic = orxonox_cast<Dynamicmatch*>(gametype);
    1047         if (dynamic)
    1048         {
    1049             if (dynamic->notEnoughPigs||dynamic->notEnoughKillers||dynamic->notEnoughChasers) {return false;}
    1050 
    1051             if (entity1->getPlayer())
    1052                 team1 = dynamic->getParty(entity1->getPlayer());
    1053 
    1054             if (entity2->getPlayer())
    1055                 team2 = dynamic->getParty(entity2->getPlayer());
    1056 
    1057             if (team1 ==-1 ||team2 ==-1 ) {return false;}
    1058             else if (team1 == dynamic->chaser && team2 != dynamic->chaser) {return false;}
    1059             else if (team1 == dynamic->piggy && team2 == dynamic->chaser) {return false;}
    1060             else if (team1 == dynamic->killer && team2 == dynamic->chaser) {return false;}
    1061             else return true;
    1062         }
    1063 
    1064         return (team1 == team2 && team1 != -1);
    1065115    }
    1066116
     
    1110160        {
    1111161            Pawn* pawn = orxonox_cast<Pawn*>(this->getControllableEntity());
    1112             if(pawn)
     162            if(pawn && pawn->isA(Class(SpaceShip))) //fix for First Person Mode: check for SpaceShip
    1113163            {
    1114164                this->weaponModes_.clear(); // reset previous weapon information
     
    1217267
    1218268    /**
    1219         @brief Adds point of interest depending on context. Further Possibilites: "ForceField", "PortalEndPoint", "MovableEntity", "Dock"
     269        @brief Adds point of interest depending on context.  TODO: Further Possibilites: "ForceField", "PortalEndPoint", "MovableEntity", "Dock"
    1220270    */
    1221271    void ArtificialController::manageWaypoints()
     
    1226276            this->updatePointsOfInterest("PickupSpawner", 20.0f); // take pickup en passant if there is a default waypoint
    1227277    }
    1228 
     278 
    1229279}
  • code/trunk/src/orxonox/controllers/ArtificialController.h

    r8891 r9016  
    3131
    3232#include "OrxonoxPrereqs.h"
     33#include "controllers/FormationController.h"
    3334
    34 #include <map>
    35 
    36 #include "util/Math.h"
    37 #include "Controller.h"
    38 #include "controllers/NewHumanController.h"
    39 #include "weaponsystem/WeaponSystem.h"
    4035
    4136namespace orxonox
    4237{
    43     class _OrxonoxExport ArtificialController : public Controller
     38    class _OrxonoxExport ArtificialController : public FormationController
    4439    {
    4540        public:
     
    4742            virtual ~ArtificialController();
    4843
    49             virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    50 
    5144            void abandonTarget(Pawn* target);
    5245
    53             inline void setTeam(int team)
    54                 { this->team_ = team; }
    55             inline int getTeam() const
    56                 { return this->team_; }
    57 
    58             inline void setFormationFlight(bool formation)
    59                 { this->formationFlight_ = formation; }
    60             inline bool getFormationFlight() const
    61                 { return this->formationFlight_; }
    62 
    63             inline void setFormationSize(int size)
    64                 { this->maxFormationSize_ = size; }
    65             inline int getFormationSize() const
    66                 { return this->maxFormationSize_; }
    67 
    68             inline void setPassive(bool passive)
    69                 { this->passive_ = passive; }
    70             inline bool getPassive() const
    71                 { return this->passive_; }
    72 
    7346            virtual void changedControllableEntity();
    74 
    75             static void formationflight(const bool form);
    76             static void masteraction(const int action);
    77             static void followme();
    78             static void passivebehaviour(const bool passive);
    79             static void formationsize(const int size);
    8047
    8148            virtual void doFire();
     
    9562            void manageWaypoints();
    9663
     64           
     65
    9766        protected:
    98 
    99             int team_;
    100             bool formationFlight_;
    101             bool passive_;
    102             unsigned int maxFormationSize_;
    103             int freedomCount_;
    104             enum State {SLAVE, MASTER, FREE};
    105             State state_;
    106             std::vector<ArtificialController*> slaves_;
    107             ArtificialController *myMaster_;
    108             enum SpecificMasterAction {NONE, HOLD, SPIN, TURN180, FOLLOW};
    109             SpecificMasterAction specificMasterAction_;
    110             int specificMasterActionHoldCount_;
    111             float speedCounter_; //for speed adjustment when following
    112 
    113             void moveToPosition(const Vector3& target);
    114             void moveToTargetPosition();
    115             void absoluteMoveToPosition(const Vector3& target);
    116 
    117             virtual void positionReached() {}
    118 
    119             void removeFromFormation();
    120             void unregisterSlave();
    121             void searchNewMaster();
    122             void commandSlaves();
    123             void setNewMasterWithinFormation();
    124 
    125             void freeSlaves();
    126             void forceFreeSlaves();
    127             void loseMasterState();
    128             void forceFreedom();
    129             bool forcedFree();
    130 
    131             void specificMasterActionHold();
    132             void turn180Init();
    133             void turn180();
    134             void spinInit();
    135             void spin();
    136             void followInit(Pawn* pawn, const bool always = false, const int secondsToFollow = 100);
    137             void followRandomHumanInit();
    138             void follow();
    139             void followForSlaves(const Vector3& target);
    140 
    141             void setTargetPosition(const Vector3& target);
    142             void searchRandomTargetPosition();
    143 
    144             void setTarget(Pawn* target);
    145             void searchNewTarget();
    146             void forgetTarget();
     67           
    14768            void aimAtTarget();
    14869
    14970            bool isCloseAtTarget(float distance) const;
    15071            bool isLookingAtTarget(float angle) const;
    151 
    152             void targetDied();
    153 
    154             static bool sameTeam(ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype); // hack
    155             void boostControl(); //<! Sets and resets the boost parameter of the spaceship. Bots alternate between boosting and saving boost.
    156 
    157             bool bHasTargetPosition_;
    158             Vector3 targetPosition_;
    159             WeakPtr<Pawn> target_;
    160             bool bShooting_;
    16172
    16273            float botlevel_; //<! Makes the level of a bot configurable.
     
    16576            void setPreviousMode();
    16677
     78
    16779            //WEAPONSYSTEM DATA
    168             std::map<std::string, int> weaponModes_; //<! Links each "weapon" to it's weaponmode- managed by setupWeapons()
     80            std::map<std::string, int> weaponModes_; //<! Links each "weapon" to it's weaponmode - managed by setupWeapons()
    16981            //std::vector<int> projectiles_; //<! Displays amount of projectiles of each weapon. - managed by setupWeapons()
    17082            float timeout_; //<! Timeout for rocket usage. (If a rocket misses, a bot should stop using it.)
     
    17385            int getFiremode(std::string name);
    17486
     87
    17588            //WAYPOINT DATA
    17689            std::vector<WeakPtr<WorldEntity> > waypoints_;
     
    17891            float squaredaccuracy_;
    17992            WorldEntity* defaultWaypoint_;
     93
     94            void boostControl(); //<! Sets and resets the boost parameter of the spaceship. Bots alternate between boosting and saving boost.
     95
     96        private:
    18097    };
    18198}
  • code/trunk/src/orxonox/controllers/CMakeLists.txt

    r7163 r9016  
    99  WaypointPatrolController.cc
    1010  DroneController.cc
     11  FormationController.cc
    1112)
  • code/trunk/src/orxonox/controllers/HumanController.cc

    r8858 r9016  
    5050    SetConsoleCommand("HumanController", "rotatePitch",            &HumanController::rotatePitch   ).addShortcut().setAsInputCommand();
    5151    SetConsoleCommand("HumanController", "rotateRoll",             &HumanController::rotateRoll    ).addShortcut().setAsInputCommand();
     52    SetConsoleCommand("HumanController", "toggleFormationFlight",  &HumanController::toggleFormationFlight).addShortcut().keybindMode(KeybindMode::OnPress);
     53    SetConsoleCommand("HumanController", "FFChangeMode",  &HumanController::FFChangeMode).addShortcut().keybindMode(KeybindMode::OnPress);
    5254    SetConsoleCommand("HumanController", __CC_fire_name,           &HumanController::fire          ).addShortcut().keybindMode(KeybindMode::OnHold);
    5355    SetConsoleCommand("HumanController", "reload",                 &HumanController::reload        ).addShortcut();
     
    6971    /*static*/ const float HumanController::BOOSTING_TIME = 0.1f;
    7072
    71     HumanController::HumanController(BaseObject* creator) : Controller(creator)
     73    HumanController::HumanController(BaseObject* creator) : FormationController(creator)
    7274    {
    7375        RegisterObject(HumanController);
     
    7678        this->boosting_ = false;
    7779        this->boosting_ = false;
    78 
    7980        HumanController::localController_s = this;
    8081        this->boostingTimeout_.setTimer(HumanController::BOOSTING_TIME, false, createExecutor(createFunctor(&HumanController::terminateBoosting, this)));
     
    8485    HumanController::~HumanController()
    8586    {
     87        if (HumanController::localController_s)
     88        {
     89            HumanController::localController_s->removeFromFormation();
     90        }
    8691        HumanController::localController_s = 0;
    8792    }
     
    95100                orxout(internal_warning) << "HumanController, Warning: Using a ControllableEntity without Camera" << endl;
    96101        }
     102
     103        // commandslaves when Master of a formation
     104        if (HumanController::localController_s && HumanController::localController_s->state_==MASTER)
     105        {
     106            if (HumanController::localController_s->formationMode_ != ATTACK)
     107                HumanController::localController_s->commandSlaves();
     108        }
    97109    }
    98110
     
    160172    {
    161173        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
     174        {
    162175            HumanController::localController_s->controllableEntity_->fire(firemode);
     176            //if human fires, set slaves free. See FormationController::forceFreeSlaves()
     177            if (HumanController::localController_s->state_==MASTER && HumanController::localController_s->formationMode_ == NORMAL)
     178            {
     179                HumanController::localController_s->forceFreeSlaves();
     180            }
     181        }
    163182    }
    164183
     
    195214            this->boosting_ = true;
    196215            this->boostingTimeout_.startTimer();
    197            
    198             this->controllableEntity_->boost(this->boosting_);
     216            if(this->controllableEntity_)
     217                this->controllableEntity_->boost(this->boosting_);
    199218//            orxout() << "Start boosting" << endl;
    200219        }
     
    209228        this->boosting_ = false;
    210229        this->boostingTimeout_.stopTimer();
    211 
    212         this->controllableEntity_->boost(this->boosting_);
     230        if(this->controllableEntity_)
     231            this->controllableEntity_->boost(this->boosting_);
    213232//        orxout() << "Stop boosting" << endl;
    214233    }
     
    262281    }
    263282
     283    /**
     284    @brief
     285       toggle the formation. Not usable, if formationflight is disabled generally (formationFlight_)
     286    */
     287    void HumanController::toggleFormationFlight()
     288    {
     289        if (HumanController::localController_s)
     290        {
     291            if (!HumanController::localController_s->formationFlight_)
     292            {
     293                return; //dont use when formationFlight is disabled
     294            }
     295            if (HumanController::localController_s->state_==MASTER)
     296            {
     297                HumanController::localController_s->loseMasterState();
     298                orxout(message) <<"FormationFlight disabled "<< endl;
     299            } else //SLAVE or FREE
     300            {
     301                HumanController::localController_s->takeLeadOfFormation();
     302                orxout(message) <<"FormationFlight enabled "<< endl;
     303            }
     304           
     305        }
     306
     307    }
     308
     309    /**
     310    @brief
     311       Switch through the different Modes of formationflight. You must be a master of a formation to use.
     312    */
     313    void HumanController::FFChangeMode()
     314    {
     315        if (HumanController::localController_s && HumanController::localController_s->state_==MASTER)
     316        {
     317            switch (HumanController::localController_s->getFormationMode()) {
     318                case NORMAL:
     319                    HumanController::localController_s->setFormationMode(DEFEND);
     320                    orxout(message) <<"Mode: DEFEND "<< endl;
     321                    break;
     322                case DEFEND:
     323                    HumanController::localController_s->setFormationMode(ATTACK);
     324                    orxout(message) <<"Mode: ATTACK "<< endl;
     325                    break;
     326                case ATTACK:
     327                    HumanController::localController_s->setFormationMode(NORMAL);
     328                    orxout(message) <<"Mode: NORMAL "<< endl;
     329                    break;
     330            }
     331        }
     332    }
     333
     334
     335    //used, when slaves are in DEFEND mode.
     336    void HumanController::hit(Pawn* originator, btManifoldPoint& contactpoint, float damage)
     337    {
     338        if (!this->formationFlight_ || this->state_!=MASTER || this->formationMode_!=DEFEND) return;
     339            this->masterAttacked(originator);
     340    }
     341
    264342    void HumanController::addBots(unsigned int amount)
    265343    {
  • code/trunk/src/orxonox/controllers/HumanController.h

    r8706 r9016  
    3434#include "tools/Timer.h"
    3535#include "tools/interfaces/Tickable.h"
    36 #include "Controller.h"
     36#include "FormationController.h"
    3737
    3838// tolua_begin
     
    4141    class _OrxonoxExport HumanController
    4242// tolua_end
    43         : public Controller, public Tickable
     43        : public FormationController, public Tickable
    4444    { // tolua_export
    4545        public:
     
    7474            void keepBoosting(void);
    7575            void terminateBoosting(void);
    76            
     76                 
     77
    7778            static void greet();
    7879            static void switchCamera();
     
    8485            static void toggleGodMode();
    8586            static void myposition();
     87
     88            static void toggleFormationFlight();
     89            static void FFChangeMode();
     90            virtual void hit(Pawn* originator, btManifoldPoint& contactpoint, float damage);
     91
    8692
    8793            static void addBots(unsigned int amount);
  • code/trunk/src/orxonox/controllers/NewHumanController.cc

    r8858 r9016  
    291291        }
    292292        else
    293             HumanController::localController_s->getControllableEntity()->fire(firemode);
    294 
     293            HumanController::doFire(firemode); //call for formationflight
    295294    }
    296295
    297296    void NewHumanController::hit(Pawn* originator, btManifoldPoint& contactpoint, float damage)
    298297    {
     298        //Used in HumanController for formationFlight
     299        HumanController::hit(originator,contactpoint,damage);
     300       
    299301        if (this->showDamageOverlay_ && !this->controlPaused_ && this->controllableEntity_ && !this->controllableEntity_->isInMouseLook())
    300302        {
  • code/trunk/src/orxonox/controllers/NewHumanController.h

    r7859 r9016  
    6969            virtual void doResumeControl();
    7070
     71            float getCurrentYaw(){ return this->currentYaw_; }
     72            float getCurrentPitch(){ return this->currentPitch_; }
     73
    7174
    7275        protected:
  • code/trunk/src/orxonox/controllers/WaypointPatrolController.cc

    r7184 r9016  
    4242        RegisterObject(WaypointPatrolController);
    4343
    44         //this->team_ = 0;
    4544        this->alertnessradius_ = 500;
    4645
     
    5352
    5453        XMLPortParam(WaypointPatrolController, "alertnessradius", setAlertnessRadius, getAlertnessRadius, xmlelement, mode).defaultValues(500.0f);
    55 //        XMLPortParam(WaypointPatrolController, "team", setTeam, getTeam, xmlelement, mode).defaultValues(0);
    5654    }
    5755
  • code/trunk/src/orxonox/controllers/WaypointPatrolController.h

    r7163 r9016  
    4646            virtual void tick(float dt);
    4747
    48            /* inline void setTeam(int team)
    49                 { this->team_ = team; }
    50             inline int getTeam() const
    51                 { return this->team_; } */
    52 
    5348            inline void setAlertnessRadius(float radius)
    5449                { this->alertnessradius_ = radius; }
     
    5954            void searchEnemy();
    6055
    61             //int team_;
    6256            float alertnessradius_;
    6357            Timer patrolTimer_;
  • code/trunk/src/orxonox/gametypes/CMakeLists.txt

    r8178 r9016  
    99  LastManStanding.cc
    1010  LastTeamStanding.cc
     11  TeamGametype.cc
     12  Mission.cc
    1113)
  • code/trunk/src/orxonox/gametypes/Gametype.cc

    r8858 r9016  
    123123        if (this->gtinfo_->isStartCountdownRunning() && !this->gtinfo_->hasStarted())
    124124            this->gtinfo_->countdownStartCountdown(dt);
    125 
     125                       
    126126        if (!this->gtinfo_->hasStarted())
    127127        {
     
    131131                if(it->first->isHumanPlayer() && it->first->isReadyToSpawn())
    132132                    this->gtinfo_->playerReadyToSpawn(it->first);
    133             }
    134                    
     133                   
     134               
     135            }
    135136            this->checkStart();
    136137        }
     
    143144    void Gametype::start()
    144145    {
     146         
    145147        this->addBots(this->numberOfBots_);
    146148
     
    148150
    149151        this->spawnPlayersIfRequested();
     152       
     153       
    150154    }
    151155
     
    376380                {
    377381                    this->gtinfo_->stopStartCountdown();
    378                     this->gtinfo_->setStartCountdown(0.0f);;
     382                    this->gtinfo_->setStartCountdown(0.0f);
    379383                    this->start();
    380384                }
     
    397401                            hashumanplayers = true;
    398402                    }
     403                         
    399404                    if (allplayersready && hashumanplayers)
    400405                    {
     
    408413                }
    409414            }
     415           
    410416        }
    411417    }
     
    439445            if(player->isHumanPlayer())
    440446                this->gtinfo_->playerSpawned(player);
    441            
     447
    442448            this->playerPostSpawn(player);
    443449        }
  • code/trunk/src/orxonox/gametypes/Gametype.h

    r8706 r9016  
    123123                { return this->gtinfo_->getHUDTemplate(); }
    124124
    125             void addBots(unsigned int amount);
     125            virtual void addBots(unsigned int amount);
    126126            void killBots(unsigned int amount = 0);
    127 
    128             inline unsigned int getNumberOfPlayers() const
    129                 { return this->players_.size(); }
    130127
    131128            virtual void addTime(float t);
     
    151148
    152149            //inline bool getForceSpawn()
    153             //  { return this->bForceSpawn_; }       
     150            //  { return this->bForceSpawn_; }
    154151
    155152            virtual void resetTimer();
    156153            virtual void resetTimer(float t);
     154            inline unsigned int getNumberOfPlayers()
     155              { return this->gtinfo_->getNumberOfPlayers(); }
     156
     157       
    157158
    158159        protected:
     
    192193            ConsoleCommand* dedicatedKillBots_;
    193194            /* HACK HACK HACK */
     195
    194196    };
    195197}
  • code/trunk/src/orxonox/gametypes/TeamDeathmatch.h

    r5781 r9016  
    5656
    5757            int getTeam(PlayerInfo* player);
    58 
    5958            inline const ColourValue& getTeamColour(int teamnr) const
    6059                { return this->teamcolours_[teamnr]; }
  • code/trunk/src/orxonox/gametypes/UnderAttack.cc

    r8858 r9016  
    4949        this->gameEnded_ = false;
    5050
    51         this->setHUDTemplate("UnderAttackHUD");
    52 
     51        //this->setHUDTemplate("UnderAttackHUD");
     52        //This HUD is in conflict with the HUDEnemyHealthBar
    5353        this->setConfigValues();
    5454        this->timesequence_ = static_cast<int>(this->gameTime_);
  • code/trunk/src/orxonox/infos/GametypeInfo.cc

    r8858 r9016  
    7171        this->bStarted_ = false;
    7272        this->bEnded_ = false;
    73         this->startCountdown_ = 0.0f;
     73        this->startCountdown_ = 10.0f;
    7474        this->bStartCountdownRunning_ = false;
    75         this->counter_ = 0;
     75        this->counter_ = 10;
    7676        this->spawned_ = false;
    7777        this->readyToSpawn_ = false;
     
    164164    {
    165165        if(this->bStarted_)
    166             return;
     166           { return;}
    167167       
    168168        this->bStarted_ = true;
    169169        this->changedStarted();
     170       
     171       
    170172    }
    171173
  • code/trunk/src/orxonox/infos/GametypeInfo.h

    r8706 r9016  
    119119            inline const std::string& getHUDTemplate() const
    120120                { return this->hudtemplate_; }
     121           
     122            inline unsigned int getNumberOfPlayers() const
     123                {  return this->spawnedPlayers_.size(); }
    121124
    122125            void sendAnnounceMessage(const std::string& message);
  • code/trunk/src/orxonox/infos/PlayerInfo.cc

    r8891 r9016  
    3636#include "worldentities/ControllableEntity.h"
    3737#include "controllers/Controller.h"
     38#include "worldentities/pawns/SpaceShip.h"
    3839
    3940namespace orxonox
     
    5758
    5859        this->registerVariables();
     60       
    5961    }
    6062
     
    170172
    171173        this->changedControllableEntity();
     174                SpaceShip* spaceship = dynamic_cast<SpaceShip*>(entity);
     175        if (spaceship != NULL)
     176        {
     177            spaceship->setRVName(this->getName());
     178        }
    172179    }
    173180
  • code/trunk/src/orxonox/interfaces/RadarViewable.cc

    r8858 r9016  
    5151        , radarObjectDescription_("staticObject")
    5252        , scale_(1.0f)
     53                , RVName("")
    5354    {
    5455        RegisterRootObject(RadarViewable);
  • code/trunk/src/orxonox/interfaces/RadarViewable.h

    r8738 r9016  
    6060        RadarViewable(BaseObject* creator, const WorldEntity* wePtr);
    6161        virtual ~RadarViewable();
     62
     63                virtual void setRVName(std::string name)
     64                        {
     65                                if (this->RVName != name)
     66                                {
     67                                        this->RVName = name;
     68                                        this->settingsChanged();
     69                                }
     70                        }
     71                std::string getRVName() const
     72                        { return this->RVName; }
    6273
    6374        inline void setRadarObjectCamouflage(float camouflage)
     
    152163        ColourValue radarObjectColour_;
    153164        float scale_;
     165                std::string RVName;
    154166    };
    155167}
  • code/trunk/src/orxonox/worldentities/ControllableEntity.cc

    r8891 r9016  
    7474        this->bMouseLook_ = false;
    7575        this->mouseLookSpeed_ = 200;
    76         this->bIsRocket_ = false;
    7776
    7877        this->server_position_         = Vector3::ZERO;
     
    8887        this->setPriority( Priority::VeryHigh );
    8988        this->registerVariables();
     89        this->team_ = -1;
    9090    }
    9191
     
    120120        SUPER(ControllableEntity, XMLPort, xmlelement, mode);
    121121
     122        XMLPortParam(ControllableEntity, "team", setTeam, getTeam, xmlelement, mode).defaultValues(-1);
    122123        XMLPortParam(ControllableEntity, "hudtemplate", setHudTemplate, getHudTemplate, xmlelement, mode);
    123124        XMLPortParam(ControllableEntity, "camerapositiontemplate", setCameraPositionTemplate, getCameraPositionTemplate, xmlelement, mode);
  • code/trunk/src/orxonox/worldentities/ControllableEntity.h

    r8891 r9016  
    163163                { return this->target_.get(); }
    164164            void setTargetInternal( uint32_t targetID );
    165             inline bool getRocket() const
    166                 { return this-> bIsRocket_; }
     165
     166            inline void setTeam(int team)
     167                { this->team_ = team; }
     168            inline float getTeam() const
     169                { return this->team_; }
    167170
    168171        protected:
     
    183186
    184187            Ogre::SceneNode* cameraPositionRootNode_;
    185             bool bIsRocket_; //Workaround to see, if the controllable entity is a Rocket.
    186188
    187189        private:
     
    240242            CameraPosition* reverseCamera_;
    241243            WeakPtr<WorldEntity> target_;
     244
     245            int team_ ; //<! teamnumber
    242246    };
    243247}
  • code/trunk/src/orxonox/worldentities/pawns/FpsPlayer.cc

    r8858 r9016  
    270270    }
    271271
    272     void FpsPlayer::boost() //acctually jump
     272    void FpsPlayer::boost(bool bBoost) //acctually jump
    273273    {
    274274        if (this->isFloor_)
  • code/trunk/src/orxonox/worldentities/pawns/FpsPlayer.h

    r7163 r9016  
    6565                { return this->meshSrc_; }
    6666
    67             void boost(); //acctually jump
     67            void boost(bool bBoost); //acctually jump
    6868
    6969            virtual void fire();
  • code/trunk/src/orxonox/worldentities/pawns/Pawn.cc

    r8891 r9016  
    129129        XMLPortParam(Pawn, "reloadrate", setReloadRate, getReloadRate, xmlelement, mode).defaultValues(0);
    130130        XMLPortParam(Pawn, "reloadwaittime", setReloadWaitTime, getReloadWaitTime, xmlelement, mode).defaultValues(1.0f);
     131   
     132        XMLPortParam ( RadarViewable, "RVName", setRVName, getRVName, xmlelement, mode );
    131133    }
    132134
     
    455457        SUPER(Pawn, changedActivity);
    456458
    457         this->setRadarVisibility(this->isActive());
     459        this->setRadarVisibility(this->isVisible());
    458460    }
    459461
  • code/trunk/src/orxonox/worldentities/pawns/Pawn.h

    r8891 r9016  
    5353            inline bool isAlive() const
    5454                { return this->bAlive_; }
     55
    5556
    5657            virtual void setHealth(float health);
     
    194195                { return NULL; }
    195196
     197
    196198            float health_;
    197199            float maxHealth_;
Note: See TracChangeset for help on using the changeset viewer.