Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 11, 2010, 8:55:13 AM (14 years ago)
Author:
dafrick
Message:

Merged presentation3 branch into trunk.

Location:
code/trunk
Files:
2 deleted
87 edited
18 copied

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/orxonox/CMakeLists.txt

    r6711 r7163  
    3232  PlayerManager.cc
    3333  Radar.cc
     34  ChatHistory.cc
     35  ChatInputHandler.cc
     36#  Test.cc
    3437COMPILATION_BEGIN SceneCompilation.cc
    3538  CameraManager.cc
     
    5558  FIND_HEADER_FILES
    5659  TOLUA_FILES
     60    ChatInputHandler.h
    5761    LevelManager.h
    5862    MoodManager.h
    5963    controllers/HumanController.h
    60     interfaces/PickupCarrier.h
     64    interfaces/Pickupable.h
     65    infos/PlayerInfo.h
    6166    sound/SoundManager.h
    62   DEFINE_SYMBOL
    63     "ORXONOX_SHARED_BUILD"
    6467  PCH_FILE
    6568    OrxonoxPrecompiledHeaders.h
     
    7578    ${VORBIS_LIBRARY}
    7679    ${OGG_LIBRARY}
    77     tinyxml++_orxonox
    78     tolua++_orxonox
     80    tinyxml_orxonox
     81    tolua_orxonox
    7982    bullet_orxonox
    8083    util
  • code/trunk/src/orxonox/Level.cc

    r6746 r7163  
    4949        RegisterObject(Level);
    5050
     51
    5152        this->registerVariables();
    5253        this->xmlfilename_ = this->getFilename();
     
    7374        XMLPortParam(Level, "gametype", setGametypeString, getGametypeString, xmlelement, mode).defaultValues("Gametype");
    7475
     76        XMLPortObject(Level, MeshLodInformation, "lodinformation", addLodInfo, getLodInfo, xmlelement, mode);
    7577        XMLPortObjectExtended(Level, BaseObject, "", addObject, getObject, xmlelement, mode, true, false);
    76     }
     78}
    7779
    7880    void Level::registerVariables()
    7981    {
    80         registerVariable(this->xmlfilename_, VariableDirection::ToClient, new NetworkCallback<Level>(this, &Level::networkcallback_applyXMLFile));
    81         registerVariable(this->name_,        VariableDirection::ToClient, new NetworkCallback<Level>(this, &Level::changedName));
    82         registerVariable(this->description_, VariableDirection::ToClient);
     82        registerVariable(this->xmlfilename_,            VariableDirection::ToClient, new NetworkCallback<Level>(this, &Level::networkcallback_applyXMLFile));
     83        registerVariable(this->name_,                   VariableDirection::ToClient, new NetworkCallback<Level>(this, &Level::changedName));
     84        registerVariable(this->description_,            VariableDirection::ToClient);
     85        registerVariable(this->networkTemplateNames_,   VariableDirection::ToClient, new NetworkCallback<Level>(this, &Level::networkCallbackTemplatesChanged));
    8386    }
    8487
     
    9598
    9699        Loader::open(this->xmlfile_);
     100    }
     101
     102    void Level::networkCallbackTemplatesChanged()
     103    {
     104        for( std::set<std::string>::iterator it = this->networkTemplateNames_.begin(); it!=this->networkTemplateNames_.end(); ++it )
     105        {
     106            assert(Template::getTemplate(*it));
     107            Template::getTemplate(*it)->applyOn(this);
     108        }
    97109    }
    98110
     
    125137        this->objects_.push_back(object);
    126138        object->setGametype(this->getGametype());
     139        object->setLevel(this);
    127140    }
    128141
     
    136149            ++i;
    137150        }
     151        return 0;
     152    }
     153
     154    void Level::addLodInfo(MeshLodInformation* lodInformation)
     155    {
     156        std::string meshName = lodInformation->getMeshName();
     157//         this->lodInformation_.insert(std::make_pair(meshName,lodInformation));
     158        if( this->lodInformation_.find(meshName) != this->lodInformation_.end())
     159          CCOUT(4) << "replacing lod information for " << meshName << endl;
     160        this->lodInformation_[meshName] = lodInformation;
     161    }
     162
     163    MeshLodInformation* Level::getLodInfo(std::string meshName) const
     164    {
     165        if(this->lodInformation_.find(meshName)!=this->lodInformation_.end())
     166            return this->lodInformation_.find(meshName)->second;
     167
    138168        return 0;
    139169    }
  • code/trunk/src/orxonox/Level.h

    r5929 r7163  
    3434#include <list>
    3535#include <string>
     36#include <map>
    3637#include "core/BaseObject.h"
    3738#include "network/synchronisable/Synchronisable.h"
     39#include "graphics/MeshLodInformation.h"
    3840
    3941namespace orxonox
     
    4648
    4749            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    48             void registerVariables();
    4950
    5051            inline void setDescription(const std::string& description)
     
    5657            void playerLeft(PlayerInfo* player);
    5758
     59            MeshLodInformation* getLodInfo(std::string meshName) const;
     60
     61
    5862        private:
     63            void registerVariables();
    5964            void addObject(BaseObject* object);
    6065            BaseObject* getObject(unsigned int index) const;
     66
     67            void addLodInfo(MeshLodInformation* object);
     68            void networkCallbackTemplatesChanged();
     69//            const MeshLodInformation* getLodInfo(std::string meshName) const;
     70//            MeshLodInformation* getLodInfo(unsigned int index) const;
    6171
    6272            void setGametypeString(const std::string& gametype);
     
    6676            void networkcallback_applyXMLFile();
    6777
    68             std::string            description_;
    69             std::string            gametype_;
    70             std::string            xmlfilename_;
    71             XMLFile*               xmlfile_;
    72             std::list<BaseObject*> objects_;
     78            std::string                    description_;
     79            std::string                    gametype_;
     80            std::string                    xmlfilename_;
     81            XMLFile*                       xmlfile_;
     82            std::list<BaseObject*>         objects_;
     83            std::map<std::string,MeshLodInformation*>  lodInformation_;
    7384    };
    7485}
  • code/trunk/src/orxonox/LevelManager.cc

    r6501 r7163  
    7070    void LevelManager::requestActivity(Level* level)
    7171    {
     72        assert( std::find(this->levels_s.begin(), this->levels_s.end(), level)==this->levels_s.end() );
     73        if( std::find(this->levels_s.begin(), this->levels_s.end(), level)!=this->levels_s.end() )
     74            return; // level is already in list
    7275        this->levels_s.push_back(level);
    7376        if (this->levels_s.size() == 1)
  • code/trunk/src/orxonox/Main.cc

    r6105 r7163  
    4040#include "core/LuaState.h"
    4141#include "ToluaBindOrxonox.h"
     42#include "ToluaBindNetwork.h"
    4243#include "Main.h"
    4344
     
    5152
    5253DeclareToluaInterface(Orxonox);
     54DeclareToluaInterface(Network);
    5355
    5456namespace orxonox
  • code/trunk/src/orxonox/MoodManager.cc

    r6417 r7163  
    3232#include "core/CoreIncludes.h"
    3333#include "core/ScopedSingletonManager.h"
     34#include "core/Resource.h"
    3435
    3536namespace orxonox
     
    3738    ManageScopedSingleton(MoodManager, ScopeID::Root, false);
    3839
     40    // Note: I'm (Kevin Young) not entirely sure whether that's good code style:
     41    const std::string MoodManager::defaultMood_ = "default";
     42
    3943    MoodManager::MoodManager()
    4044    {
    4145        RegisterRootObject(MoodManager);
    4246        this->setConfigValues();
     47
     48        // Need to use a variable to store old data because ResetConfigValues() doesn't seem to work.
     49        oldMood_ = MoodManager::defaultMood_;
     50       
     51        // Checking for the existence of the folder for the default mood
     52        const std::string& path = "ambient/" + MoodManager::defaultMood_ + "/.";
     53        if (!Resource::exists(path))
     54        {
     55            // TODO: Non-fatal error handling (non-critical resource missing)
     56            COUT(2) << "Mood Warning: Folder for default mood (" << MoodManager::defaultMood_ << ") does not exist!" << std::endl;
     57        }
    4358    }
    4459
    4560    void MoodManager::setConfigValues()
    4661    {
    47         SetConfigValue(mood_, "default")
     62        SetConfigValue(mood_, MoodManager::defaultMood_)
    4863            .description("Sets the mood for the current level.")
    4964            .callback(this, &MoodManager::checkMoodValidity);
    5065    }
    5166
    52     /** Sets the mood
    53     @note
    54         TODO: Inform dependent classes of mood change
    55     */
     67    /** Set a new mood
     68     */
    5669    void MoodManager::setMood(const std::string& mood)
    5770    {
     71        oldMood_ = mood_;
    5872        ModifyConfigValue(mood_, set, mood);
    5973    }
     
    6175    void MoodManager::checkMoodValidity()
    6276    {
    63         // TODO: Insert new moods here & make this generic
    64         if (mood_ != "default" && mood_ != "dnb")
     77        //  Generic mood validation
     78        const std::string& path = "ambient/" + mood_ + "/.";
     79        if (!Resource::exists(path))
    6580        {
    66             ResetConfigValue(mood_);
     81            COUT(3) << "Mood " << mood_ << " does not exist. Will not change." << std::endl;
     82            this->setMood(oldMood_);
    6783        }
    6884        else
  • code/trunk/src/orxonox/MoodManager.h

    r6417 r7163  
    3838namespace orxonox
    3939{
     40    /*
     41    @brief
     42        The MoodListener class is aware of a change in themes and directs that info to dependent classes.
     43    */
    4044    class _OrxonoxExport MoodListener : virtual public OrxonoxClass
    4145    {
     
    5559    };
    5660
     61    /*
     62    @brief
     63        The MoodManager class serves to allow for different musical themes in the game.
     64    */
    5765    class _OrxonoxExport MoodManager : public Singleton<MoodManager>, public OrxonoxClass
    5866    {
     
    7482            // config values
    7583            std::string mood_;
     84            std::string oldMood_;
     85            static const std::string defaultMood_;
    7686
    7787            static MoodManager* singletonPtr_s;
  • code/trunk/src/orxonox/OrxonoxPrereqs.h

    r6524 r7163  
    8282    class ArtificialController;
    8383    class Controller;
     84    class DroneController;
    8485    class HumanController;
    8586    class ScriptController;
     
    9091    class Asteroids;
    9192    class Deathmatch;
     93    class Dynamicmatch;
    9294    class Gametype;
    9395    class TeamBaseMatch;
     
    135137    class OrxonoxOverlay;
    136138    class OverlayGroup;
    137    
     139
    138140    // pickup
    139141    class PickupIdentifier;
     
    161163    class CameraPosition;
    162164    class ControllableEntity;
     165    class Drone;
    163166    class EffectContainer;
    164167    class ExplosionChunk;
  • code/trunk/src/orxonox/Radar.cc

    r6417 r7163  
    7777    }
    7878
     79    void Radar::addRadarObject(RadarViewable* rv)
     80    {
     81        assert( this->radarObjects_.find(rv) == this->radarObjects_.end() );
     82        this->radarObjects_.insert(rv);
     83        // iterate through all radarlisteners and notify them
     84        for (ObjectList<RadarListener>::iterator itListener = ObjectList<RadarListener>::begin(); itListener; ++itListener)
     85        {
     86            (*itListener)->addObject(rv);
     87        }
     88    }
     89
     90    void Radar::removeRadarObject(RadarViewable* rv)
     91    {
     92        assert( this->radarObjects_.find(rv) != this->radarObjects_.end() );
     93        this->radarObjects_.erase(rv);
     94        // iterate through all radarlisteners and notify them
     95        for (ObjectList<RadarListener>::iterator itListener = ObjectList<RadarListener>::begin(); itListener; ++itListener)
     96        {
     97            (*itListener)->removeObject(rv);
     98        }
     99    }
     100
    79101    const RadarViewable* Radar::getFocus()
    80102    {
     
    109131        {
    110132            (*itListener)->radarTick(dt);
    111 
    112             for (ObjectList<RadarViewable>::iterator itElement = ObjectList<RadarViewable>::begin(); itElement; ++itElement)
    113             {
    114                 if ((*itElement)->getRadarVisibility())
    115                     if ((*itListener)->getRadarSensitivity() > (*itElement)->getRadarObjectCamouflage())
    116                         (*itListener)->displayObject(*itElement, *itElement == this->focus_);
    117             }
    118133        }
    119134    }
     
    188203        }
    189204    }
     205
     206    void Radar::radarObjectChanged(RadarViewable* rv)
     207    {
     208        for (ObjectList<RadarListener>::iterator itListener = ObjectList<RadarListener>::begin(); itListener; ++itListener)
     209        {
     210          (*itListener)->objectChanged(rv);
     211        }
     212    }
    190213}
  • code/trunk/src/orxonox/Radar.h

    r6417 r7163  
    3838
    3939#include <map>
     40#include <set>
    4041#include <string>
    4142
     
    4849    class _OrxonoxExport Radar : public Tickable
    4950    {
     51        friend class RadarViewable;
    5052    public:
    5153        Radar();
     
    5860
    5961        void listObjects() const;
     62        const std::set<RadarViewable*>& getRadarObjects() const
     63            { return this->radarObjects_; }
    6064
    6165        void releaseFocus();
     
    6670
    6771        void updateFocus();
     72        void addRadarObject(RadarViewable* rv);
     73        void removeRadarObject(RadarViewable* rv);
     74        void radarObjectChanged(RadarViewable* rv);
    6875
    6976        ObjectListIterator<RadarViewable> itFocus_;
    7077        RadarViewable* focus_;
    7178        std::map<std::string, RadarViewable::Shape> objectTypes_;
     79        std::set<RadarViewable*> radarObjects_;
    7280        int objectTypeCounter_;
    7381    };
  • code/trunk/src/orxonox/Scene.cc

    r6417 r7163  
    4747#include "Radar.h"
    4848#include "worldentities/WorldEntity.h"
     49#include "Level.h"
    4950
    5051namespace orxonox
     
    133134        registerVariable(this->bHasPhysics_,        VariableDirection::ToClient, new NetworkCallback<Scene>(this, &Scene::networkcallback_hasPhysics));
    134135        registerVariable(this->bShadows_,           VariableDirection::ToClient, new NetworkCallback<Scene>(this, &Scene::networkcallback_applyShadows));
     136        registerVariable(this->getLevel(),          VariableDirection::ToClient, new NetworkCallback<Scene>(this, &Scene::changedLevel));
    135137    }
    136138
  • code/trunk/src/orxonox/Test.cc

    r6417 r7163  
    8888    void Test::registerVariables()
    8989    {
    90         registerVariable ( u1, VariableDirection::ToClient, new NetworkCallback<Test> ( this, &Test::checkU1 ));
    91         registerVariable ( u2, VariableDirection::ToServer, new NetworkCallback<Test> ( this, &Test::checkU2 ));
    92         registerVariable ( u3, Bidirectionality::ServerMaster, new NetworkCallback<Test> ( this, &Test::checkU3 ), true );
    93         registerVariable ( u4, Bidirectionality::ClientMaster, new NetworkCallback<Test> ( this, &Test::checkU4 ), true );
     90        registerVariable ( this->mySet_, VariableDirection::ToClient );
     91     
     92//         registerVariable ( u1, VariableDirection::ToClient, new NetworkCallback<Test> ( this, &Test::checkU1 ));
     93//         registerVariable ( u2, VariableDirection::ToServer, new NetworkCallback<Test> ( this, &Test::checkU2 ));
     94//         registerVariable ( u3, Bidirectionality::ServerMaster, new NetworkCallback<Test> ( this, &Test::checkU3 ), true );
     95//         registerVariable ( u4, Bidirectionality::ClientMaster, new NetworkCallback<Test> ( this, &Test::checkU4 ), true );
    9496   
    95         registerVariable ( s1, VariableDirection::ToClient, new NetworkCallback<Test> ( this, &Test::checkS1 ));
    96         registerVariable ( s2, VariableDirection::ToServer, new NetworkCallback<Test> ( this, &Test::checkS2 ));
    97         registerVariable ( s3, Bidirectionality::ServerMaster, new NetworkCallback<Test> ( this, &Test::checkS3 ), true );
    98         registerVariable ( s4, Bidirectionality::ClientMaster, new NetworkCallback<Test> ( this, &Test::checkS4 ), true );
     97//         registerVariable ( s1, VariableDirection::ToClient, new NetworkCallback<Test> ( this, &Test::checkS1 ));
     98//         registerVariable ( s2, VariableDirection::ToServer, new NetworkCallback<Test> ( this, &Test::checkS2 ));
     99//         registerVariable ( s3, Bidirectionality::ServerMaster, new NetworkCallback<Test> ( this, &Test::checkS3 ), true );
     100//         registerVariable ( s4, Bidirectionality::ClientMaster, new NetworkCallback<Test> ( this, &Test::checkS4 ), true );
    99101   
    100         registerVariable ( pointer_, VariableDirection::ToClient, new NetworkCallback<Test> ( this, &Test::printPointer ) );
     102//         registerVariable ( pointer_, VariableDirection::ToClient, new NetworkCallback<Test> ( this, &Test::printPointer ) );
    101103    }
    102104 
  • code/trunk/src/orxonox/Test.h

    r6417 r7163  
    3535#include "tools/interfaces/Tickable.h"
    3636
     37#include <set>
    3738
    3839typedef int TYPE;
     
    4950
    5051      void setConfigValues();
    51       void registerVariables();
    5252
    5353      static void call(unsigned int clientID);
     
    7878      void printPointer();
    7979
    80       static void printV1(){ instance_->checkU1(); }
    81       static void printV2(){ instance_->checkU2(); }
     80      static void printV1(){ instance_->blub(); }
     81      static void printV2(){ instance_->blub2(); }
    8282      static void printV3(){ instance_->checkU3(); }
    8383      static void printV4(){ instance_->checkU4(); }
     
    8686
    8787    private:
     88      void registerVariables();
     89
    8890      UTYPE u1;
    8991      UTYPE u2;
     
    9799
    98100      Test* pointer_;
     101     
     102      std::set<uint32_t> mySet_;
    99103
    100104      static Test* instance_;
     105     
     106      void blub()
     107      { mySet_.insert(2); }
     108     
     109      void blub2()
     110      { for( std::set<uint32_t>::iterator it=mySet_.begin(); it!=mySet_.end(); ++it ) COUT(0) << *it << endl; }
    101111  };
    102112}
  • code/trunk/src/orxonox/collisionshapes/CollisionShape.h

    r5781 r7163  
    4545
    4646            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    47             void registerVariables();
    4847
    4948            inline void setPosition(const Vector3& position)
     
    8887
    8988        private:
     89            void registerVariables();
     90
    9091            Vector3                 position_;
    9192            Quaternion              orientation_;
  • code/trunk/src/orxonox/controllers/AIController.cc

    r5929 r7163  
    2323 *      Fabian 'x3n' Landau
    2424 *   Co-authors:
    25  *      ...
     25 *      Dominik Solenicki
    2626 *
    2727 */
     
    3333#include "core/Executor.h"
    3434#include "worldentities/ControllableEntity.h"
     35#include "worldentities/pawns/Pawn.h"
    3536
    3637namespace orxonox
     
    5657        float maxrand = 100.0f / ACTION_INTERVAL;
    5758
    58         // search enemy
    59         random = rnd(maxrand);
    60         if (random < 15 && (!this->target_))
    61             this->searchNewTarget();
    62 
    63         // forget enemy
    64         random = rnd(maxrand);
    65         if (random < 5 && (this->target_))
    66             this->forgetTarget();
    67 
    68         // next enemy
    69         random = rnd(maxrand);
    70         if (random < 10 && (this->target_))
    71             this->searchNewTarget();
    72 
    73         // fly somewhere
    74         random = rnd(maxrand);
    75         if (random < 50 && (!this->bHasTargetPosition_ && !this->target_))
    76             this->searchRandomTargetPosition();
    77 
    78         // stop flying
    79         random = rnd(maxrand);
    80         if (random < 10 && (this->bHasTargetPosition_ && !this->target_))
    81             this->bHasTargetPosition_ = false;
    82 
    83         // fly somewhere else
    84         random = rnd(maxrand);
    85         if (random < 30 && (this->bHasTargetPosition_ && !this->target_))
    86             this->searchRandomTargetPosition();
    87 
    88         // shoot
    89         random = rnd(maxrand);
    90         if (random < 75 && (this->target_ && !this->bShooting_))
    91             this->bShooting_ = true;
    92 
    93         // stop shooting
    94         random = rnd(maxrand);
    95         if (random < 25 && (this->bShooting_))
    96             this->bShooting_ = false;
     59        if (this->state_ == FREE)
     60        {
     61
     62            if (this->formationFlight_)
     63            {
     64                // return to Master after being forced free
     65                if (this->freedomCount_ == 1)
     66                {
     67                this->state_ = SLAVE;
     68                this->freedomCount_ = 0;
     69                }
     70
     71                random = rnd(maxrand);
     72                if (random < 90 && (((!this->target_) || (random < 50 && this->target_)) && !this->forcedFree()))
     73                    this->searchNewMaster();
     74            }
     75
     76            // search enemy
     77            random = rnd(maxrand);
     78            if (random < 15 && (!this->target_))
     79                this->searchNewTarget();
     80
     81            // forget enemy
     82            random = rnd(maxrand);
     83            if (random < 5 && (this->target_))
     84                this->forgetTarget();
     85
     86            // next enemy
     87            random = rnd(maxrand);
     88            if (random < 10 && (this->target_))
     89                this->searchNewTarget();
     90
     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
     106            // shoot
     107            random = rnd(maxrand);
     108            if (!(this->passive_) && random < 75 && (this->target_ && !this->bShooting_))
     109                this->bShooting_ = true;
     110
     111            // stop shooting
     112            random = rnd(maxrand);
     113            if (random < 25 && (this->bShooting_))
     114                this->bShooting_ = false;
     115
     116        }
     117
     118        if (this->state_ == SLAVE)
     119        {
     120
     121        }
     122
     123        if (this->state_ == MASTER)
     124        {
     125
     126
     127            this->commandSlaves();
     128
     129            if  (this->specificMasterAction_ != NONE)
     130                    this->specificMasterActionHold();
     131
     132            else {
     133
     134                 // make 180 degree turn - a specific Master Action
     135                random = rnd(1000.0f);
     136                if (random < 5)
     137                   this->turn180Init();
     138
     139                // spin around - a specific Master Action
     140                random = rnd(1000.0f);
     141                if (random < 5)
     142                   this->spinInit();
     143
     144                // follow a randomly chosen human - a specific Master Action
     145                random = rnd(1000.0f);
     146                if (random < 1)
     147                   this->followRandomHumanInit();
     148
     149                 // lose master status (only if less than 4 slaves in formation)
     150                random = rnd(maxrand);
     151                if(random < 15/(this->slaves_.size()+1) && this->slaves_.size() < 4 )
     152                   this->loseMasterState();
     153
     154                // look out for outher masters if formation is small
     155                random = rnd(maxrand);
     156                if(this->slaves_.size() < 3 && random < 20)
     157                    this->searchNewMaster();
     158
     159                // search enemy
     160                random = rnd(maxrand);
     161                if (random < 15 && (!this->target_))
     162                    this->searchNewTarget();
     163
     164                // forget enemy
     165                random = rnd(maxrand);
     166                if (random < 5 && (this->target_))
     167                    this->forgetTarget();
     168
     169                // next enemy
     170                random = rnd(maxrand);
     171                if (random < 10 && (this->target_))
     172                    this->searchNewTarget();
     173
     174                // fly somewhere
     175                random = rnd(maxrand);
     176                if (random < 50 && (!this->bHasTargetPosition_ && !this->target_))
     177                    this->searchRandomTargetPosition();
     178
     179
     180                // fly somewhere else
     181                random = rnd(maxrand);
     182                if (random < 30 && (this->bHasTargetPosition_ && !this->target_))
     183                    this->searchRandomTargetPosition();
     184
     185                // shoot
     186                random = rnd(maxrand);
     187                if (!(this->passive_) && random < 9 && (this->target_ && !this->bShooting_))
     188                {
     189                this->bShooting_ = true;
     190                this->forceFreeSlaves();
     191                }
     192
     193                // stop shooting
     194                random = rnd(maxrand);
     195                if (random < 25 && (this->bShooting_))
     196                    this->bShooting_ = false;
     197
     198            }
     199        }
     200
    97201    }
    98202
     
    102206            return;
    103207
    104         if (this->target_)
    105             this->aimAtTarget();
    106 
    107         if (this->bHasTargetPosition_)
    108             this->moveToTargetPosition();
    109 
    110         if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(Ogre::Math::PI / 20.0f))
    111             this->getControllableEntity()->fire(0);
     208        if (this->state_ == MASTER)
     209        {
     210            if (this->specificMasterAction_ ==  NONE)
     211            {
     212                if (this->target_)
     213                {
     214                                if (!this->target_->getRadarVisibility()) /* So AI won't shoot invisible Spaceships */
     215                        this->forgetTarget();
     216                else this->aimAtTarget();
     217            }
     218
     219                if (this->bHasTargetPosition_)
     220                    this->moveToTargetPosition();
     221
     222                if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(Ogre::Math::PI / 20.0f))
     223                    this->getControllableEntity()->fire(0);
     224            }
     225
     226            if (this->specificMasterAction_  == TURN180)
     227                    this->turn180();
     228
     229            if (this->specificMasterAction_ == SPIN)
     230                    this->spin();
     231            if (this->specificMasterAction_ == FOLLOW)
     232                    this->follow();
     233        }
     234
     235        if (this->state_ == SLAVE)
     236        {
     237
     238            if (this->bHasTargetPosition_)
     239                this->moveToTargetPosition();
     240
     241        }
     242
     243         if (this->state_ == FREE)
     244        {
     245            if (this->target_)
     246            {
     247                                if (!this->target_->getRadarVisibility()) /* So AI won't shoot invisible Spaceships */
     248                        this->forgetTarget();
     249                else this->aimAtTarget();
     250            }
     251
     252            if (this->bHasTargetPosition_)
     253                this->moveToTargetPosition();
     254
     255            if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(Ogre::Math::PI / 20.0f))
     256                this->getControllableEntity()->fire(0);
     257        }
    112258
    113259        SUPER(AIController, tick, dt);
  • code/trunk/src/orxonox/controllers/ArtificialController.cc

    r6502 r7163  
    2323 *      Fabian 'x3n' Landau
    2424 *   Co-authors:
    25  *      ...
     25 *      Dominik Solenicki
    2626 *
    2727 */
     
    2929#include "ArtificialController.h"
    3030
     31#include <vector>
     32#include <climits>
     33
     34#include "util/Math.h"
     35#include "core/ConsoleCommand.h"
    3136#include "core/CoreIncludes.h"
     37#include "core/XMLPort.h"
    3238#include "worldentities/ControllableEntity.h"
    3339#include "worldentities/pawns/Pawn.h"
    3440#include "worldentities/pawns/TeamBaseMatchBase.h"
    3541#include "gametypes/TeamDeathmatch.h"
     42#include "gametypes/Dynamicmatch.h"
    3643#include "controllers/WaypointPatrolController.h"
     44#include "controllers/NewHumanController.h"
     45#include "controllers/DroneController.h"
    3746
    3847namespace orxonox
    3948{
     49    SetConsoleCommand(ArtificialController, formationflight, true);
     50    SetConsoleCommand(ArtificialController, masteraction, true);
     51    SetConsoleCommand(ArtificialController, followme, true);
     52    SetConsoleCommand(ArtificialController, passivebehaviour, true);
     53    SetConsoleCommand(ArtificialController, formationsize, true);
     54
     55    static const unsigned int STANDARD_MAX_FORMATION_SIZE = 7;
     56    static const int RADIUS_TO_SEARCH_FOR_MASTERS = 5000;
     57    static const int FORMATION_LENGTH =  130;
     58    static const int FORMATION_WIDTH =  110;
     59    static const int FREEDOM_COUNT = 4; //seconds the slaves in a formation will be set free when master attacks an enemy
     60    static const float SPEED_MASTER = 0.6f;
     61    static const float ROTATEFACTOR_MASTER = 0.2f;
     62    static const float SPEED_FREE = 0.8f;
     63    static const float ROTATEFACTOR_FREE = 0.8f;
     64
     65
    4066    ArtificialController::ArtificialController(BaseObject* creator) : Controller(creator)
    4167    {
     
    4369
    4470        this->target_ = 0;
     71        this->formationFlight_ = true;
     72        this->passive_ = false;
     73        this->maxFormationSize_ = STANDARD_MAX_FORMATION_SIZE;
     74        this->myMaster_ = 0;
     75        this->freedomCount_ = 0;
     76        this->team_ = -1;
     77        this->state_ = FREE;
     78        this->specificMasterAction_ = NONE;
     79        this->specificMasterActionHoldCount_  = 0;
    4580        this->bShooting_ = false;
    4681        this->bHasTargetPosition_ = false;
     82        this->speedCounter_ = 0.2f;
    4783        this->targetPosition_ = Vector3::ZERO;
    4884
     
    5288    ArtificialController::~ArtificialController()
    5389    {
     90        if (this->isInitialized())
     91        {
     92            this->removeFromFormation();
     93
     94            for (ObjectList<ArtificialController>::iterator it = ObjectList<ArtificialController>::begin(); it; ++it)
     95            {
     96                if (*it != this)
     97                {
     98                    if (it->myMaster_ == this)
     99                    {
     100                        COUT(1) << "error: " << this << " is still master in " << (*it) << std::endl;
     101                        it->myMaster_ = 0;
     102                    }
     103
     104                    while (true)
     105                    {
     106                        std::vector<ArtificialController*>::iterator it2 = std::find(it->slaves_.begin(), it->slaves_.end(), this);
     107                        if (it2 != it->slaves_.end())
     108                        {
     109                            COUT(1) << "error: " << this << " is still slave in " << (*it) << std::endl;
     110                            it->slaves_.erase(it2);
     111                        }
     112                        else
     113                            break;
     114                    }
     115                }
     116            }
     117        }
     118    }
     119
     120    void ArtificialController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     121    {
     122        SUPER(ArtificialController, XMLPort, xmlelement, mode);
     123
     124        XMLPortParam(ArtificialController, "team", setTeam, getTeam, xmlelement, mode).defaultValues(-1);
     125        XMLPortParam(ArtificialController, "formationFlight", setFormationFlight, getFormationFlight, xmlelement, mode).defaultValues(false);
     126        XMLPortParam(ArtificialController, "formationSize", setFormationSize, getFormationSize, xmlelement, mode).defaultValues(STANDARD_MAX_FORMATION_SIZE);
     127        XMLPortParam(ArtificialController, "passive", setPassive, getPassive, xmlelement, mode).defaultValues(false);
     128    }
     129
     130// Documentation only here to get a faster overview for creating a useful documentation...
     131
     132    /**
     133        @brief Activates / deactivates formationflight behaviour
     134        @param form activate formflight if form is true
     135    */
     136    void ArtificialController::formationflight(const bool form)
     137    {
     138        for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
     139        {
     140            Controller* controller = 0;
     141
     142            if (it->getController())
     143                controller = it->getController();
     144            else if (it->getXMLController())
     145                controller = it->getXMLController();
     146
     147            if (!controller)
     148                continue;
     149
     150            ArtificialController *aiController = orxonox_cast<ArtificialController*>(controller);
     151
     152            if (aiController)
     153            {
     154                aiController->formationFlight_ = form;
     155                if (!form)
     156                {
     157                    aiController->removeFromFormation();
     158                }
     159            }
     160        }
     161    }
     162
     163    /**
     164        @brief Get all masters to do a "specific master action"
     165        @param action which action to perform (integer, so it can be called with a console command (tmp solution))
     166    */
     167    void ArtificialController::masteraction(const int action)
     168    {
     169        for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
     170        {
     171            Controller* controller = 0;
     172
     173            if (it->getController())
     174                controller = it->getController();
     175            else if (it->getXMLController())
     176                controller = it->getXMLController();
     177
     178            if (!controller)
     179                continue;
     180
     181            ArtificialController *aiController = orxonox_cast<ArtificialController*>(controller);
     182
     183            if(aiController && aiController->state_ == MASTER)
     184            {
     185                if (action == 1)
     186                    aiController->spinInit();
     187                if (action == 2)
     188                    aiController->turn180Init();
     189            }
     190        }
     191    }
     192
     193    /**
     194        @brief A human player gets followed by its nearest master. Initiated by console command, so far intended for demonstration puproses (possible future pickup).
     195    */
     196    void ArtificialController::followme()
     197    {
     198
     199        Pawn *humanPawn = NULL;
     200        NewHumanController *currentHumanController = NULL;
     201        std::vector<ArtificialController*> allMasters;
     202
     203        for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
     204        {
     205            Controller* controller = 0;
     206
     207            if (it->getController())
     208                controller = it->getController();
     209            else if (it->getXMLController())
     210                controller = it->getXMLController();
     211
     212            if (!controller)
     213                continue;
     214
     215            currentHumanController = orxonox_cast<NewHumanController*>(controller);
     216
     217            if(currentHumanController) humanPawn = *it;
     218
     219            ArtificialController *aiController = orxonox_cast<ArtificialController*>(controller);
     220
     221            if(aiController && aiController->state_ == MASTER)
     222                allMasters.push_back(aiController);
     223
     224        }
     225
     226        if((humanPawn != NULL) && (allMasters.size() != 0))
     227        {
     228                float posHuman = humanPawn->getPosition().length();
     229                float distance = 0.0f;
     230                float minDistance = FLT_MAX;
     231                int index = 0;
     232                int i = 0;
     233
     234                for(std::vector<ArtificialController*>::iterator it = allMasters.begin(); it != allMasters.end(); it++, i++)
     235                    {
     236                        if (!ArtificialController::sameTeam((*it)->getControllableEntity(), humanPawn, (*it)->getGametype())) continue;
     237                        distance = posHuman - (*it)->getControllableEntity()->getPosition().length();
     238                        if(distance < minDistance) index = i;
     239                    }
     240                allMasters[index]->followInit(humanPawn);
     241            }
     242
     243    }
     244
     245    /**
     246        @brief Sets shooting behaviour of pawns.
     247        @param passive if true, bots won't shoot.
     248    */
     249    void ArtificialController::passivebehaviour(const bool passive)
     250    {
     251        for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
     252        {
     253            Controller* controller = 0;
     254
     255            if (it->getController())
     256                controller = it->getController();
     257            else if (it->getXMLController())
     258                controller = it->getXMLController();
     259
     260            if (!controller)
     261                continue;
     262
     263            ArtificialController *aiController = orxonox_cast<ArtificialController*>(controller);
     264
     265            if(aiController)
     266            {
     267                aiController->passive_ = passive;
     268            }
     269        }
     270    }
     271
     272
     273    /**
     274        @brief Sets maximal formation size
     275        @param size maximal formation size.
     276    */
     277    void ArtificialController::formationsize(const int size)
     278    {
     279        for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
     280        {
     281            Controller* controller = 0;
     282
     283            if (it->getController())
     284                controller = it->getController();
     285            else if (it->getXMLController())
     286                controller = it->getXMLController();
     287
     288            if (!controller)
     289                continue;
     290
     291            ArtificialController *aiController = orxonox_cast<ArtificialController*>(controller);
     292
     293            if(aiController)
     294            {
     295                aiController->maxFormationSize_ = size;
     296            }
     297        }
     298    }
     299
     300    /**
     301        @brief Gets called when ControllableEntity is being changed. Resets the bot when it dies.
     302    */
     303    void ArtificialController::changedControllableEntity()
     304    {
     305        if (!this->getControllableEntity())
     306            this->removeFromFormation();
     307    }
     308
     309    void ArtificialController::removeFromFormation()
     310    {
     311        if (this->state_ == SLAVE || this->myMaster_) // slaves can also be temporary free, so check if myMaster_ is set
     312            this->unregisterSlave();
     313        else if (this->state_ == MASTER)
     314            this->setNewMasterWithinFormation();
    54315    }
    55316
     
    59320            return;
    60321
     322        // Slave uses special movement if its master is in FOLLOW mode
     323        if(this->state_ == SLAVE && this->myMaster_ && this->myMaster_->specificMasterAction_ == FOLLOW)
     324        {
     325//             this->followForSlaves(target);
     326//             return;
     327        }
     328
    61329        Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
    62330        float distance = (target - this->getControllableEntity()->getPosition()).length();
    63331
    64         if (this->target_ || distance > 10)
    65         {
    66             // Multiply with 0.8 to make them a bit slower
    67             this->getControllableEntity()->rotateYaw(-0.8f * sgn(coord.x) * coord.x*coord.x);
    68             this->getControllableEntity()->rotatePitch(0.8f * sgn(coord.y) * coord.y*coord.y);
    69         }
    70 
    71         if (this->target_ && distance < 200 && this->getControllableEntity()->getVelocity().squaredLength() > this->target_->getVelocity().squaredLength())
    72             this->getControllableEntity()->moveFrontBack(-0.5f); // They don't brake with full power to give the player a chance
     332
     333        if(this->state_ == FREE)
     334        {
     335            if (this->target_ || distance > 10)
     336            {
     337                // Multiply with ROTATEFACTOR_FREE to make them a bit slower
     338                this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_FREE * sgn(coord.x) * coord.x*coord.x);
     339                this->getControllableEntity()->rotatePitch(ROTATEFACTOR_FREE * sgn(coord.y) * coord.y*coord.y);
     340            }
     341
     342            if (this->target_ && distance < 200 && this->getControllableEntity()->getVelocity().squaredLength() > this->target_->getVelocity().squaredLength())
     343            {
     344              this->getControllableEntity()->moveFrontBack(-0.05f); // They don't brake with full power to give the player a chance
     345            } else this->getControllableEntity()->moveFrontBack(SPEED_FREE);
     346        }
     347
     348
     349
     350        if(this->state_ == MASTER)
     351        {
     352            if (this->target_ || distance > 10)
     353            {
     354                this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_MASTER * sgn(coord.x) * coord.x*coord.x);
     355                this->getControllableEntity()->rotatePitch(ROTATEFACTOR_MASTER * sgn(coord.y) * coord.y*coord.y);
     356            }
     357
     358            if (this->target_ && distance < 200 && this->getControllableEntity()->getVelocity().squaredLength() > this->target_->getVelocity().squaredLength())
     359            {
     360                this->getControllableEntity()->moveFrontBack(-0.05f);
     361            } else this->getControllableEntity()->moveFrontBack(SPEED_MASTER);
     362        }
     363
     364
     365
     366        if(this->state_ == SLAVE)
     367        {
     368
     369           this->getControllableEntity()->rotateYaw(-2.0f * ROTATEFACTOR_MASTER * sgn(coord.x) * coord.x*coord.x);
     370           this->getControllableEntity()->rotatePitch(2.0f * ROTATEFACTOR_MASTER * sgn(coord.y) * coord.y*coord.y);
     371
     372            if (distance < 300)
     373            {
     374                if (distance < 40)
     375                {
     376                    this->getControllableEntity()->moveFrontBack(0.8f*SPEED_MASTER);
     377                } else this->getControllableEntity()->moveFrontBack(1.2f*SPEED_MASTER);
     378
     379            } else {
     380                this->getControllableEntity()->moveFrontBack(1.2f*SPEED_MASTER + distance/300.0f);
     381            }
     382        }
     383    }
     384
     385    void ArtificialController::moveToTargetPosition()
     386    {
     387        this->moveToPosition(this->targetPosition_);
     388    }
     389
     390
     391    /**
     392        @brief Unregisters a slave from its master. Initiated by a slave.
     393    */
     394    void ArtificialController::unregisterSlave()
     395    {
     396        if (this->myMaster_)
     397        {
     398            std::vector<ArtificialController*>::iterator it = std::find(this->myMaster_->slaves_.begin(), this->myMaster_->slaves_.end(), this);
     399            if (it != this->myMaster_->slaves_.end())
     400                this->myMaster_->slaves_.erase(it);
     401        }
     402
     403        this->myMaster_ = 0;
     404        this->state_ = FREE;
     405    }
     406
     407    void ArtificialController::searchNewMaster()
     408    {
     409
     410        if (!this->getControllableEntity())
     411            return;
     412
     413        this->targetPosition_ = this->getControllableEntity()->getPosition();
     414        this->forgetTarget();
     415        int teamSize = 0;
     416        //go through all pawns
     417        for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
     418        {
     419            //same team?
     420            if (!ArtificialController::sameTeam(this->getControllableEntity(), static_cast<ControllableEntity*>(*it), this->getGametype()))
     421                continue;
     422
     423            //has it an ArtificialController?
     424            Controller* controller = 0;
     425
     426            if (it->getController())
     427                controller = it->getController();
     428            else if (it->getXMLController())
     429                controller = it->getXMLController();
     430
     431            if (!controller)
     432                continue;
     433
     434            //is pawn oneself?
     435            if (orxonox_cast<ControllableEntity*>(*it) == this->getControllableEntity())
     436                continue;
     437
     438            teamSize++;
     439
     440            ArtificialController *newMaster = orxonox_cast<ArtificialController*>(controller);
     441
     442            //is it a master?
     443            if (!newMaster || newMaster->state_ != MASTER)
     444                continue;
     445
     446            float distance = (it->getPosition() - this->getControllableEntity()->getPosition()).length();
     447
     448            // is pawn in range?
     449            if (distance < RADIUS_TO_SEARCH_FOR_MASTERS)
     450            {
     451                if(newMaster->slaves_.size() > this->maxFormationSize_) continue;
     452
     453                for(std::vector<ArtificialController*>::iterator itSlave = this->slaves_.begin(); itSlave != this->slaves_.end(); itSlave++)
     454                {
     455                    (*itSlave)->myMaster_ = newMaster;
     456                    newMaster->slaves_.push_back(*itSlave);
     457                }
     458                this->slaves_.clear();
     459                this->state_ = SLAVE;
     460
     461                this->myMaster_ = newMaster;
     462                newMaster->slaves_.push_back(this);
     463
     464                break;
     465            }
     466        }
     467
     468        if (this->state_ != SLAVE  && teamSize != 0)
     469        {
     470            this->state_ = MASTER;
     471            this->myMaster_ = 0;
     472        }
     473    }
     474
     475    /**
     476        @brief Commands the slaves of a master into a formation. Sufficiently fast not to be called within tick. Initiated by a master.
     477    */
     478    void ArtificialController::commandSlaves()
     479    {
     480        if(this->state_ != MASTER) return;
     481
     482        Quaternion orient = this->getControllableEntity()->getOrientation();
     483        Vector3 dest = this->getControllableEntity()->getPosition();
     484
     485        // 1 slave: follow
     486        if (this->slaves_.size() == 1)
     487        {
     488            dest += 4*orient*WorldEntity::BACK;
     489            this->slaves_.front()->setTargetPosition(dest);
     490        }
    73491        else
    74             this->getControllableEntity()->moveFrontBack(0.8f);
    75     }
    76 
    77     void ArtificialController::moveToTargetPosition()
    78     {
    79         this->moveToPosition(this->targetPosition_);
    80     }
     492        {
     493            dest += 1.0f*orient*WorldEntity::BACK;
     494            Vector3 pos = Vector3::ZERO;
     495            int i = 1;
     496
     497            for(std::vector<ArtificialController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++)
     498            {
     499                pos = Vector3::ZERO;
     500                if (i <= 1) pos += dest  + FORMATION_WIDTH*(orient*WorldEntity::LEFT);
     501                if (i == 2) pos += dest  + FORMATION_WIDTH*(orient*WorldEntity::RIGHT);
     502                if (i == 3) pos += dest  + FORMATION_WIDTH*(orient*WorldEntity::UP);
     503                if (i >= 4)
     504                {
     505                    pos += dest  + FORMATION_WIDTH*(orient*WorldEntity::DOWN);
     506                    i = 1;
     507                    dest += FORMATION_LENGTH*(orient*WorldEntity::BACK);
     508                    (*it)->setTargetPosition(pos);
     509                    continue;
     510                }
     511                i++;
     512                (*it)->setTargetPosition(pos);
     513            }
     514        }
     515    }
     516
     517    /**
     518        @brief Sets a new master within the formation. Called by a master.
     519    */
     520    void ArtificialController::setNewMasterWithinFormation()
     521    {
     522        if(this->state_ != MASTER) return;
     523
     524        if (!this->slaves_.empty())
     525        {
     526            ArtificialController *newMaster = this->slaves_.back();
     527            this->slaves_.pop_back();
     528
     529            newMaster->state_ = MASTER;
     530            newMaster->slaves_ = this->slaves_;
     531            newMaster->myMaster_ = 0;
     532
     533            for(std::vector<ArtificialController*>::iterator it = newMaster->slaves_.begin(); it != newMaster->slaves_.end(); it++)
     534            {
     535                (*it)->myMaster_ = newMaster;
     536            }
     537        }
     538
     539        this->slaves_.clear();
     540        this->specificMasterAction_ = NONE;
     541        this->state_ = FREE;
     542    }
     543
     544    /**
     545        @brief Frees all slaves form a master. Initiated by a master.
     546    */
     547    void ArtificialController::freeSlaves()
     548    {
     549        if(this->state_ != MASTER) return;
     550
     551        for(std::vector<ArtificialController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++)
     552        {
     553            (*it)->state_ = FREE;
     554            (*it)->myMaster_ = 0;
     555        }
     556        this->slaves_.clear();
     557    }
     558
     559    /**
     560        @brief Master sets its slaves free for @var FREEDOM_COUNT seconds.
     561    */
     562    void ArtificialController::forceFreeSlaves()
     563    {
     564        if(this->state_ != MASTER) return;
     565
     566        for(std::vector<ArtificialController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++)
     567        {
     568            (*it)->state_ = FREE;
     569            (*it)->forceFreedom();
     570            (*it)->targetPosition_ = this->targetPosition_;
     571            (*it)->bShooting_ = true;
     572//             (*it)->getControllableEntity()->fire(0);// fire once for fun
     573        }
     574    }
     575
     576    void ArtificialController::loseMasterState()
     577    {
     578        this->freeSlaves();
     579        this->state_ = FREE;
     580    }
     581
     582
     583    void ArtificialController::forceFreedom()
     584    {
     585        this->freedomCount_ = FREEDOM_COUNT;
     586    }
     587
     588    /**
     589        @brief Checks wether caller has been forced free, decrements time to stay forced free.
     590        @return true if forced free.
     591    */
     592    bool ArtificialController::forcedFree()
     593    {
     594        if(this->freedomCount_ > 0)
     595        {
     596            this->freedomCount_--;
     597            return true;
     598        } else return false;
     599    }
     600
     601    /**
     602        @brief Used to continue a "specific master action" for a certain time and resuming normal behaviour after.
     603    */
     604    void ArtificialController::specificMasterActionHold()
     605    {
     606        if(this->state_ != MASTER) return;
     607
     608        if (specificMasterActionHoldCount_ == 0)
     609         {
     610            this->specificMasterAction_ = NONE;
     611            this->searchNewTarget();
     612         }
     613        else specificMasterActionHoldCount_--;
     614    }
     615
     616    /**
     617        @brief Master initializes a 180 degree turn. Leads to a "specific master action".
     618    */
     619    void ArtificialController::turn180Init()
     620    {
     621        if(this->state_ != MASTER) return;
     622
     623        Quaternion orient = this->getControllableEntity()->getOrientation();
     624
     625        this->setTargetPosition(this->getControllableEntity()->getPosition() + 1000.0f*orient*WorldEntity::BACK);
     626
     627        this->specificMasterActionHoldCount_ = 4;
     628
     629        this->specificMasterAction_ = TURN180;
     630    }
     631
     632    /**
     633        @brief Execute the 180 degree turn. Called within tick.
     634    */
     635    void ArtificialController::turn180()
     636    {
     637            Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, this->targetPosition_);
     638
     639            this->getControllableEntity()->rotateYaw(-2.0f * sgn(coord.x) * coord.x*coord.x);
     640            this->getControllableEntity()->rotatePitch(2.0f * sgn(coord.y) * coord.y*coord.y);
     641
     642            this->getControllableEntity()->moveFrontBack(SPEED_MASTER);
     643    }
     644
     645    /**
     646        @brief Master initializes a spin around its looking direction axis. Leads to a "specific master action".
     647    */
     648    void ArtificialController::spinInit()
     649    {
     650        if(this->state_ != MASTER) return;
     651        this->specificMasterAction_ = SPIN;
     652        this->specificMasterActionHoldCount_ = 10;
     653    }
     654
     655    /**
     656        @brief Execute the spin. Called within tick.
     657    */
     658    void ArtificialController::spin()
     659    {
     660            this->moveToTargetPosition();
     661            this->getControllableEntity()->rotateRoll(0.8f);
     662    }
     663
     664    /**
     665        @brief Master begins to follow a pawn. Is a "specific master action".
     666        @param pawn pawn to follow.
     667        @param alaways follows pawn forever if true (false if omitted).
     668        @param secondsToFollow seconds to follow the pawn if always is false. Will follow pawn 100 seconds if omitted (set in header).
     669    */
     670    void ArtificialController::followInit(Pawn* pawn, const bool always, const int secondsToFollow)
     671    {
     672        if (pawn == NULL || this->state_ != MASTER)
     673            return;
     674        this->specificMasterAction_  =  FOLLOW;
     675
     676        this->setTarget(pawn);
     677        if (!always)
     678            this->specificMasterActionHoldCount_ = secondsToFollow;
     679        else
     680            this->specificMasterActionHoldCount_ = INT_MAX; //for now...
     681
     682    }
     683
     684
     685    /**
     686        @brief Master begins to follow a randomly chosen human player of the same team. Is a "specific master action".
     687    */
     688    void ArtificialController::followRandomHumanInit()
     689    {
     690
     691        Pawn *humanPawn = NULL;
     692        NewHumanController *currentHumanController = NULL;
     693
     694        for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
     695        {
     696            if (!it->getController())
     697                continue;
     698
     699            currentHumanController = orxonox_cast<NewHumanController*>(it->getController());
     700            if(currentHumanController)
     701            {
     702                if (!ArtificialController::sameTeam(this->getControllableEntity(), *it, this->getGametype())) continue;
     703                humanPawn = *it;
     704                break;
     705            }
     706        }
     707
     708        if((humanPawn != NULL))
     709                this->followInit(humanPawn);
     710    }
     711
     712    /**
     713        @brief Master follows target with adjusted speed. Called within tick.
     714    */
     715    void ArtificialController::follow()
     716    {
     717        if (this->target_)
     718            this->moveToPosition(this->target_->getPosition());
     719        else
     720            this->specificMasterActionHoldCount_ = 0;
     721/*
     722        if (!this->getControllableEntity())
     723            return;
     724
     725        float distance = (this->target_->getPosition() - this->getControllableEntity()->getPosition()).length();
     726
     727        Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, this->target_->getPosition());
     728
     729
     730        this->getControllableEntity()->rotateYaw(-0.8f * sgn(coord.x) * coord.x*coord.x);
     731        this->getControllableEntity()->rotatePitch(0.8f * sgn(coord.y) * coord.y*coord.y);
     732
     733        float speedDiv = this->getControllableEntity()->getVelocity().squaredLength() - this->target_->getVelocity().squaredLength();
     734
     735COUT(0) << "~follow distance: " << distance << "SpeedCounter: " << this->speedCounter_ << "~speedDiv: " << speedDiv << std::endl;
     736        if (distance < 800)
     737        {
     738            if (distance < 200)
     739            {
     740                this->speedCounter_ -= 0.5f;
     741                if(this->speedCounter_ < 0) this->speedCounter_ = 0.0f;
     742                this->getControllableEntity()->moveFrontBack(speedCounter_);
     743            } else {
     744                if(speedDiv < 0)
     745                    this->speedCounter_ +=  0.01f;
     746                else
     747                    this->speedCounter_ -= 0.05f;
     748                this->getControllableEntity()->moveFrontBack(speedCounter_);
     749            }
     750
     751        } else {
     752            this->speedCounter_ += 0.05f;
     753            this->getControllableEntity()->moveFrontBack(speedCounter_ + distance/300.0f);
     754        }
     755//         if (this->getControllableEntity()->getVelocity().squaredLength() > 50.0f) this->speedCounter_ = 0;
     756
     757*/
     758    }
     759
     760
     761    /**
     762        @brief Slave moving behaviour when master is following a pawn, gets redirected from moveToPosition(const Vector3& target)). Called within tick.
     763    */
     764    void ArtificialController::followForSlaves(const Vector3& target)
     765    {
     766
     767/*
     768        if (!this->getControllableEntity() && !this->myMaster_ && this->myMaster_->state_ != FOLLOW && !this->myMaster_->target_)
     769            return;
     770
     771        float distance = (target - this->getControllableEntity()->getPosition()).length();
     772
     773        Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
     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
     780        float speedDiv = this->getControllableEntity()->getVelocity().squaredLength() - this->myMaster_->target_->getVelocity().squaredLength();
     781
     782
     783         if (distance < 800)
     784        {
     785            if (distance < 200)
     786            {
     787                this->speedCounter_ -= 5.0f;
     788                if(this->speedCounter_ < 0) this->speedCounter_ = 0.0f;
     789                this->getControllableEntity()->moveFrontBack(speedCounter_);
     790            } else {
     791                if(speedDiv < 0)
     792                    this->speedCounter_ +=  0.01f;
     793                else
     794                    this->speedCounter_ -= 0.05f;
     795                this->getControllableEntity()->moveFrontBack(speedCounter_);
     796            }
     797
     798        } else {
     799            this->speedCounter_ += 0.05f;
     800            this->getControllableEntity()->moveFrontBack(speedCounter_ + distance/300.0f);
     801        }
     802//         if (this->getControllableEntity()->getVelocity().squaredLength() > 50.0f) this->speedCounter_ = 0;
     803*/
     804    }
     805
    81806
    82807    void ArtificialController::setTargetPosition(const Vector3& target)
     
    111836        {
    112837            if (ArtificialController::sameTeam(this->getControllableEntity(), static_cast<ControllableEntity*>(*it), this->getGametype()))
     838                continue;
     839
     840            /* So AI won't choose invisible Spaceships as target */
     841            if (!it->getRadarVisibility())
    113842                continue;
    114843
     
    144873        this->bHasTargetPosition_ = (this->targetPosition_ != Vector3::ZERO);
    145874
    146         Pawn* pawn = dynamic_cast<Pawn*>(this->getControllableEntity());
     875        Pawn* pawn = orxonox_cast<Pawn*>(this->getControllableEntity());
    147876        if (pawn)
    148877            pawn->setAimPosition(this->targetPosition_);
     
    188917        int team2 = -1;
    189918
    190         if (entity1->getXMLController())
    191         {
    192             WaypointPatrolController* wpc = orxonox_cast<WaypointPatrolController*>(entity1->getXMLController());
    193             if (wpc)
    194                 team1 = wpc->getTeam();
    195         }
    196         if (entity2->getXMLController())
    197         {
    198             WaypointPatrolController* wpc = orxonox_cast<WaypointPatrolController*>(entity2->getXMLController());
    199             if (wpc)
    200                 team2 = wpc->getTeam();
     919        Controller* controller = 0;
     920        if (entity1->getController())
     921            controller = entity1->getController();
     922        else
     923            controller = entity1->getXMLController();
     924        if (controller)
     925        {
     926            ArtificialController* ac = orxonox_cast<ArtificialController*>(controller);
     927            if (ac)
     928                team1 = ac->getTeam();
     929        }
     930
     931        if (entity2->getController())
     932            controller = entity2->getController();
     933        else
     934            controller = entity2->getXMLController();
     935        if (controller)
     936        {
     937            ArtificialController* ac = orxonox_cast<ArtificialController*>(controller);
     938            if (ac)
     939                team2 = ac->getTeam();
    201940        }
    202941
     
    245984        }
    246985
     986        DroneController* droneController = 0;
     987        droneController = orxonox_cast<DroneController*>(entity1->getController());
     988        if (droneController && static_cast<ControllableEntity*>(droneController->getOwner()) == entity2)
     989            return true;
     990        droneController = orxonox_cast<DroneController*>(entity2->getController());
     991        if (droneController && static_cast<ControllableEntity*>(droneController->getOwner()) == entity1)
     992            return true;
     993        DroneController* droneController1 = orxonox_cast<DroneController*>(entity1->getController());
     994        DroneController* droneController2 = orxonox_cast<DroneController*>(entity2->getController());
     995        if (droneController1 && droneController2 && droneController1->getOwner() == droneController2->getOwner())
     996            return true;
     997
     998        Dynamicmatch* dynamic = orxonox_cast<Dynamicmatch*>(gametype);
     999        if (dynamic)
     1000        {
     1001            if (dynamic->notEnoughPigs||dynamic->notEnoughKillers||dynamic->notEnoughChasers) {return false;}
     1002
     1003            if (entity1->getPlayer())
     1004                team1 = dynamic->getParty(entity1->getPlayer());
     1005
     1006            if (entity2->getPlayer())
     1007                team2 = dynamic->getParty(entity2->getPlayer());
     1008
     1009            if (team1 ==-1 ||team2 ==-1 ) {return false;}
     1010            else if (team1 == dynamic->chaser && team2 != dynamic->chaser) {return false;}
     1011            else if (team1 == dynamic->piggy && team2 == dynamic->chaser) {return false;}
     1012            else if (team1 == dynamic->killer && team2 == dynamic->chaser) {return false;}
     1013            else return true;
     1014        }
     1015
    2471016        return (team1 == team2 && team1 != -1);
    2481017    }
  • code/trunk/src/orxonox/controllers/ArtificialController.h

    r6417 r7163  
    2323 *      Fabian 'x3n' Landau
    2424 *   Co-authors:
    25  *      ...
     25 *      Dominik Solenicki
    2626 *
    2727 */
     
    3232#include "OrxonoxPrereqs.h"
    3333
     34#include <vector>
     35
    3436#include "util/Math.h"
    3537#include "Controller.h"
     38#include "controllers/NewHumanController.h"
    3639
    3740namespace orxonox
     
    4346            virtual ~ArtificialController();
    4447
     48            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
     49
    4550            void abandonTarget(Pawn* target);
    4651
     52            inline void setTeam(int team)
     53                { this->team_ = team; }
     54            inline int getTeam() const
     55                { return this->team_; }
     56
     57            inline void setFormationFlight(bool formation)
     58                { this->formationFlight_ = formation; }
     59            inline bool getFormationFlight() const
     60                { return this->formationFlight_; }
     61
     62            inline void setFormationSize(int size)
     63                { this->maxFormationSize_ = size; }
     64            inline int getFormationSize() const
     65                { return this->maxFormationSize_; }
     66
     67            inline void setPassive(bool passive)
     68                { this->passive_ = passive; }
     69            inline bool getPassive() const
     70                { return this->passive_; }
     71
     72            virtual void changedControllableEntity();
     73
     74            static void formationflight(const bool form);
     75            static void masteraction(const int action);
     76            static void followme();
     77            static void passivebehaviour(const bool passive);
     78            static void formationsize(const int size);
     79
    4780        protected:
    48             void targetDied();
     81
     82            int team_;
     83            bool formationFlight_;
     84            bool passive_;
     85            unsigned int maxFormationSize_;
     86            int freedomCount_;
     87            enum State {SLAVE, MASTER, FREE};
     88            State state_;
     89            std::vector<ArtificialController*> slaves_;
     90            ArtificialController *myMaster_;
     91            enum SpecificMasterAction {NONE, HOLD, SPIN, TURN180, FOLLOW};
     92            SpecificMasterAction specificMasterAction_;
     93            int specificMasterActionHoldCount_;
     94            float speedCounter_; //for speed adjustment when following
    4995
    5096            void moveToPosition(const Vector3& target);
    5197            void moveToTargetPosition();
     98
     99            void removeFromFormation();
     100            void unregisterSlave();
     101            void searchNewMaster();
     102            void commandSlaves();
     103            void setNewMasterWithinFormation();
     104
     105            void freeSlaves();
     106            void forceFreeSlaves();
     107            void loseMasterState();
     108            void forceFreedom();
     109            bool forcedFree();
     110
     111            void specificMasterActionHold();
     112            void turn180Init();
     113            void turn180();
     114            void spinInit();
     115            void spin();
     116            void followInit(Pawn* pawn, const bool always = false, const int secondsToFollow = 100);
     117            void followRandomHumanInit();
     118            void follow();
     119            void followForSlaves(const Vector3& target);
    52120
    53121            void setTargetPosition(const Vector3& target);
     
    61129            bool isCloseAtTarget(float distance) const;
    62130            bool isLookingAtTarget(float angle) const;
     131
     132            void targetDied();
    63133
    64134            static bool sameTeam(ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype); // hack
  • code/trunk/src/orxonox/controllers/CMakeLists.txt

    r6417 r7163  
    88  WaypointController.cc
    99  WaypointPatrolController.cc
     10  DroneController.cc
    1011)
  • code/trunk/src/orxonox/controllers/HumanController.cc

    r6417 r7163  
    3535#include "gametypes/Gametype.h"
    3636#include "infos/PlayerInfo.h"
    37 #include "overlays/Map.h"
    3837#include "Radar.h"
    3938#include "Scene.h"
     
    116115    void HumanController::yaw(const Vector2& value)
    117116    {
    118         //Hack to enable mouselook in map
    119         if ( Map::getSingletonPtr() && Map::getSingletonPtr()->getVisibility() && HumanController::localController_s->controllableEntity_->isInMouseLook() )
    120         {
    121             Map::getSingletonPtr()->rotateYaw(value);
    122             return;
    123         }
    124117        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
    125118            HumanController::localController_s->controllableEntity_->rotateYaw(value);
     
    128121    void HumanController::pitch(const Vector2& value)
    129122    {
    130         //Hack to enable mouselook in map
    131         if ( Map::getSingletonPtr() && Map::getSingletonPtr()->getVisibility() && HumanController::localController_s->controllableEntity_->isInMouseLook() )
    132         {
    133             Map::getSingletonPtr()->rotatePitch(value);
    134             return;
    135         }
    136123        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
    137124            HumanController::localController_s->controllableEntity_->rotatePitch(value);
  • code/trunk/src/orxonox/controllers/NewHumanController.cc

    r6598 r7163  
    217217                    if (this->getControllableEntity() && (this->getControllableEntity()->isExactlyA(ClassByString("SpaceShip")) || this->getControllableEntity()->isExactlyA(ClassByString("Rocket"))))
    218218                        this->showOverlays();
     219                    else if (this->getControllableEntity() &&  this->getControllableEntity()->isExactlyA(ClassByString("FpsPlayer")))
     220                    {
     221                        this->showOverlays();
     222                        this->hideArrows();
     223                    }
    219224
    220225                    this->crossHairOverlay_->setPosition(Vector2(static_cast<float>(this->currentYaw_)/2*-1+.5f-overlaySize_/2, static_cast<float>(this->currentPitch_)/2*-1+.5f-overlaySize_/2));
     
    364369        Ogre::RaySceneQueryResult& result = rsq->execute();
    365370        Pawn* pawn = orxonox_cast<Pawn*>(this->getControllableEntity());
     371        WorldEntity* myWe = static_cast<WorldEntity*>(this->getControllableEntity());
    366372
    367373        Ogre::RaySceneQueryResult::iterator itr;
    368374        for (itr = result.begin(); itr != result.end(); ++itr)
    369375        {
    370             if (itr->movable->isInScene() && itr->movable->getMovableType() == "Entity" && itr->distance > 500)
     376//             CCOUT(0) << "testing object as target" << endl;
     377            if (itr->movable->isInScene() && itr->movable->getMovableType() == "Entity" /*&& itr->distance > 500*/)
    371378            {
    372379                // Try to cast the user pointer
    373                 WorldEntity* wePtr = dynamic_cast<WorldEntity*>(Ogre::any_cast<OrxonoxClass*>(itr->movable->getUserAny()));
     380                WorldEntity* wePtr;
     381                try
     382                {
     383                    wePtr = dynamic_cast<WorldEntity*>(Ogre::any_cast<OrxonoxClass*>(itr->movable->getUserAny()));
     384                }
     385                catch (...)
     386                {
     387                    continue;
     388                }
     389
     390                // make sure we don't shoot ourselves
     391                if( wePtr==myWe )
     392                    continue;
     393
    374394                if (wePtr)
    375395                {
     
    379399                    while (parent)
    380400                    {
    381                         if (this->targetMask_.isExcluded(parent->getIdentifier()))
     401                        if (this->targetMask_.isExcluded(parent->getIdentifier()) || parent==myWe)
    382402                        {
    383403                            parent = parent->getParent();
     
    430450            HumanController::yaw(value);
    431451
    432         this->currentYaw_ = value.x;
     452        if (this->getControllableEntity() && !this->getControllableEntity()->isExactlyA(ClassByString("FpsPlayer")))
     453            this->currentYaw_ = value.x;
    433454    }
    434455
     
    439460            HumanController::pitch(value);
    440461
    441         this->currentPitch_ = value.x;
     462        if (this->getControllableEntity() && !this->getControllableEntity()->isExactlyA(ClassByString("FpsPlayer")))
     463            this->currentPitch_ = value.x;
    442464    }
    443465
     
    579601        }
    580602    }
     603
     604
     605
     606
     607
    581608}
  • code/trunk/src/orxonox/controllers/NewHumanController.h

    r6417 r7163  
    6767            virtual void doResumeControl();
    6868
     69
    6970        protected:
    7071            void updateTarget();
  • code/trunk/src/orxonox/controllers/WaypointPatrolController.cc

    r6502 r7163  
    4242        RegisterObject(WaypointPatrolController);
    4343
    44         this->team_ = 0;
     44        //this->team_ = 0;
    4545        this->alertnessradius_ = 500;
    4646
     
    5353
    5454        XMLPortParam(WaypointPatrolController, "alertnessradius", setAlertnessRadius, getAlertnessRadius, xmlelement, mode).defaultValues(500.0f);
    55         XMLPortParam(WaypointPatrolController, "team", setTeam, getTeam, xmlelement, mode).defaultValues(0);
     55//        XMLPortParam(WaypointPatrolController, "team", setTeam, getTeam, xmlelement, mode).defaultValues(0);
    5656    }
    5757
  • code/trunk/src/orxonox/controllers/WaypointPatrolController.h

    r5929 r7163  
    4646            virtual void tick(float dt);
    4747
    48             inline void setTeam(int team)
     48           /* inline void setTeam(int team)
    4949                { this->team_ = team; }
    5050            inline int getTeam() const
    51                 { return this->team_; }
     51                { return this->team_; } */
    5252
    5353            inline void setAlertnessRadius(float radius)
     
    5959            void searchEnemy();
    6060
    61             int team_;
     61            //int team_;
    6262            float alertnessradius_;
    6363            Timer patrolTimer_;
  • code/trunk/src/orxonox/gamestates/GSClient.cc

    r6426 r7163  
    4040    DeclareGameState(GSClient, "client", false, false);
    4141
    42     SetCommandLineArgument(ip, "127.0.0.1").information("Sever IP as string in the form #.#.#.#");
     42    SetCommandLineArgument(dest, "127.0.0.1").information("Server hostname/IP (IP in the form of #.#.#.#)");
    4343
    4444    GSClient::GSClient(const GameStateInfo& info)
    4545        : GameState(info)
    46         , client_(0)
    4746    {
    4847    }
     
    5655        GameMode::setIsClient(true);
    5756
    58         this->client_ = new Client(CommandLineParser::getValue("ip").getString(), CommandLineParser::getValue("port"));
     57//         this->client_ = new Client();
     58//         this->client_->setDestination(CommandLineParser::getValue("dest").getString(), CommandLineParser::getValue("port") );
    5959
    60         if(!client_->establishConnection())
     60        if( !Client::getInstance()->establishConnection() )
    6161        {
    62             delete this->client_;
    6362            ThrowException(InitialisationFailed, "Could not establish connection with server.");
    6463        }
    6564
    66         client_->update(Game::getInstance().getGameClock());
     65        Client::getInstance()->update(Game::getInstance().getGameClock());
    6766    }
    6867
    6968    void GSClient::deactivate()
    7069    {
    71         client_->closeConnection();
     70        Client::getInstance()->closeConnection();
    7271
    7372        // destroy client
    74         delete this->client_;
     73//         delete this->client_;
    7574
    7675        GameMode::setIsClient(false);
     
    7978    void GSClient::update(const Clock& time)
    8079    {
    81         client_->update(time);
     80        Client::getInstance()->update(time);
    8281    }
    8382}
  • code/trunk/src/orxonox/gamestates/GSClient.h

    r5929 r7163  
    4646        void deactivate();
    4747        void update(const Clock& time);
    48 
    49     private:
    50         Client* client_;
    5148    };
    5249}
  • code/trunk/src/orxonox/gamestates/GSGraphics.cc

    r6417 r7163  
    3939#include "core/Game.h"
    4040#include "core/GUIManager.h"
    41 // HACK:
    42 #include "overlays/Map.h"
    4341
    4442namespace orxonox
     
    7371    void GSGraphics::deactivate()
    7472    {
    75         // HACK: (destroys a resource smart pointer)
    76         Map::hackDestroyMap();
     73
    7774    }
    7875
  • code/trunk/src/orxonox/gametypes/CMakeLists.txt

    r5781 r7163  
    66  UnderAttack.cc
    77  Asteroids.cc
     8  Dynamicmatch.cc
    89)
  • code/trunk/src/orxonox/gametypes/Gametype.cc

    r6417 r7163  
    309309        if (this->spawnpoints_.size() > 0)
    310310        {
     311            SpawnPoint* fallbackSpawnPoint = NULL;
    311312            unsigned int randomspawn = static_cast<unsigned int>(rnd(static_cast<float>(this->spawnpoints_.size())));
    312313            unsigned int index = 0;
     314            std::set<SpawnPoint*> activeSpawnPoints = this->spawnpoints_;
    313315            for (std::set<SpawnPoint*>::const_iterator it = this->spawnpoints_.begin(); it != this->spawnpoints_.end(); ++it)
     316            {
     317                if (index == randomspawn)
     318                    fallbackSpawnPoint = (*it);
     319
     320                if (!(*it)->isActive())
     321                    activeSpawnPoints.erase(*it);
     322
     323                ++index;
     324            }
     325
     326            randomspawn = static_cast<unsigned int>(rnd(static_cast<float>(this->spawnpoints_.size())));
     327            index = 0;
     328            for (std::set<SpawnPoint*>::const_iterator it = activeSpawnPoints.begin(); it != activeSpawnPoints.end(); ++it)
    314329            {
    315330                if (index == randomspawn)
     
    318333                ++index;
    319334            }
     335
     336            return fallbackSpawnPoint;
    320337        }
    321338        return 0;
  • code/trunk/src/orxonox/gametypes/TeamDeathmatch.cc

    r6417 r7163  
    137137        }
    138138
     139        SpawnPoint* fallbackSpawnPoint = NULL;
    139140        if (teamSpawnPoints.size() > 0)
    140141        {
    141142            unsigned int randomspawn = static_cast<unsigned int>(rnd(static_cast<float>(teamSpawnPoints.size())));
    142143            unsigned int index = 0;
     144            // Get random fallback spawnpoint in case there is no active SpawnPoint.
     145            for (std::set<SpawnPoint*>::const_iterator it = teamSpawnPoints.begin(); it != teamSpawnPoints.end(); ++it)
     146            {
     147                if (index == randomspawn)
     148                {
     149                    fallbackSpawnPoint = (*it);
     150                    break;
     151                }
     152
     153                ++index;
     154            }
     155
     156            // Remove all inactive SpawnPoints from the list.
     157            for (std::set<SpawnPoint*>::const_iterator it = teamSpawnPoints.begin(); it != teamSpawnPoints.end(); )
     158            {
     159                if(!(*it)->isActive())
     160                {
     161                    teamSpawnPoints.erase(it++);
     162                    continue;
     163                }
     164
     165                ++it;
     166            }
     167
     168            randomspawn = static_cast<unsigned int>(rnd(static_cast<float>(teamSpawnPoints.size())));
     169            index = 0;
    143170            for (std::set<SpawnPoint*>::const_iterator it = teamSpawnPoints.begin(); it != teamSpawnPoints.end(); ++it)
    144171            {
     
    148175                ++index;
    149176            }
     177
     178            return fallbackSpawnPoint;
    150179        }
    151180
  • code/trunk/src/orxonox/graphics/Backlight.h

    r5781 r7163  
    4545
    4646            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    47             void registerVariables();
    4847
    4948            virtual void tick(float dt);
     
    8180
    8281        private:
     82            void registerVariables();
    8383            virtual void startturnonoff();
    8484            virtual void stopturnonoff();
  • code/trunk/src/orxonox/graphics/Billboard.h

    r5781 r7163  
    4646
    4747            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    48             void registerVariables();
    4948
    5049            virtual void changedVisibility();
     
    7877
    7978        private:
     79            void registerVariables();
    8080            void changedMaterial();
    8181//            void changedRotation();
  • code/trunk/src/orxonox/graphics/BlinkingBillboard.cc

    r6417 r7163  
    6666    void BlinkingBillboard::registerVariables()
    6767    {
    68 //        registerVariable(this->amplitude_, VariableDirection::ToClient);
    69 //        registerVariable(this->frequency_, VariableDirection::ToClient);
    70 //        registerVariable(this->phase_,     VariableDirection::ToClient);
     68        unregisterVariable(this->getScale3D());
     69        registerVariable(this->amplitude_,  VariableDirection::ToClient);
     70        registerVariable(this->frequency_,  VariableDirection::ToClient);
     71        registerVariable(this->phase_,      VariableDirection::ToClient);
     72        registerVariable(this->bQuadratic_, VariableDirection::ToClient);
    7173    }
    7274
     
    7577        SUPER(BlinkingBillboard, tick, dt);
    7678
    77         if (GameMode::isMaster() && this->isActive())
     79        if (this->isActive())
    7880        {
    7981            this->time_ += dt;
  • code/trunk/src/orxonox/graphics/BlinkingBillboard.h

    r5781 r7163  
    4545
    4646            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    47             void registerVariables();
    4847
    4948            virtual void tick(float dt);
     
    7069
    7170        private:
     71            void registerVariables();
     72           
    7273            float amplitude_;
    7374            float frequency_;
  • code/trunk/src/orxonox/graphics/CMakeLists.txt

    r5929 r7163  
    44  FadingBillboard.cc
    55  GlobalShader.cc
     6  MeshLodInformation.cc
    67  Model.cc
     8  AnimatedModel.cc
    79  ParticleEmitter.cc
    810  ParticleSpawner.cc
  • code/trunk/src/orxonox/graphics/Camera.cc

    r6501 r7163  
    111111        SUPER(Camera, tick, dt);
    112112
    113         if (this->bDrag_)
     113        if (this->bDrag_ && this->getTimeFactor() != 0)
    114114        {
    115115            // this stuff here may need some adjustments
  • code/trunk/src/orxonox/graphics/FadingBillboard.h

    r5929 r7163  
    4646
    4747            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    48             void registerVariables();
    4948
    5049            virtual void tick(float dt);
     
    6665
    6766        protected:
     67            void registerVariables();
    6868            virtual void startturnonoff();
    6969            virtual void stopturnonoff();
  • code/trunk/src/orxonox/graphics/GlobalShader.h

    r5781 r7163  
    4545
    4646            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    47             void registerVariables();
    4847
    4948            virtual void changedVisibility();
     
    5352
    5453        private:
     54            void registerVariables();
    5555            void changedCompositor();
    5656
  • code/trunk/src/orxonox/graphics/Light.h

    r5781 r7163  
    5757
    5858            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    59             void registerVariables();
    6059
    6160            virtual void changedVisibility();
     
    132131
    133132        private:
     133            void registerVariables();
    134134            void setTypeString(const std::string& type);
    135135            std::string getTypeString() const;
  • code/trunk/src/orxonox/graphics/Model.cc

    r5781 r7163  
    3535#include "core/XMLPort.h"
    3636#include "Scene.h"
     37#include "graphics/MeshLodInformation.h"
     38#include "Level.h"
    3739
    3840namespace orxonox
     
    4042    CreateFactory(Model);
    4143
    42     Model::Model(BaseObject* creator) : StaticEntity(creator)
     44    Model::Model(BaseObject* creator) :
     45        StaticEntity(creator), bCastShadows_(true), lodLevel_(5), bLodEnabled_(true), numLodLevels_(10), lodReductionRate_(.15)
    4346    {
    4447        RegisterObject(Model);
    45 
    46         this->bCastShadows_ = true;
    4748
    4849        this->registerVariables();
     
    5960        SUPER(Model, XMLPort, xmlelement, mode);
    6061
     62        XMLPortParam(Model, "lodLevel", setLodLevel, getLodLevel, xmlelement, mode);
     63
    6164        XMLPortParam(Model, "mesh", setMeshSource, getMeshSource, xmlelement, mode);
    6265        XMLPortParam(Model, "shadow", setCastShadows, getCastShadows, xmlelement, mode).defaultValues(true);
     
    6770        registerVariable(this->meshSrc_,    VariableDirection::ToClient, new NetworkCallback<Model>(this, &Model::changedMesh));
    6871        registerVariable(this->bCastShadows_, VariableDirection::ToClient, new NetworkCallback<Model>(this, &Model::changedShadows));
     72    }
     73
     74    float Model::getBiggestScale(Vector3 scale3d)
     75    {
     76        float scaleFactor = scale3d.x;
     77        if(scale3d.y>scaleFactor)
     78            scaleFactor = scale3d.y;
     79        if(scale3d.z>scaleFactor)
     80            scaleFactor = scale3d.z;
     81        return scaleFactor;
    6982    }
    7083
     
    8396                this->mesh_.getEntity()->setCastShadows(this->bCastShadows_);
    8497                this->mesh_.setVisible(this->isVisible());
     98
     99
     100                //LOD
     101                if( this->mesh_.getEntity()->getMesh()->getNumLodLevels()==1 )
     102                {
     103                    Level* level = this->getLevel();
     104
     105                    assert( level != 0 );
     106
     107                    MeshLodInformation* lodInfo = level->getLodInfo(this->meshSrc_);
     108                    if( lodInfo )
     109                    {
     110                        setLodLevel(lodInfo->getLodLevel());
     111                        this->bLodEnabled_ = lodInfo->getEnabled();
     112                        this->numLodLevels_ = lodInfo->getNumLevels();
     113                        this->lodReductionRate_ = lodInfo->getReductionRate();
     114                    }
     115                    if( this->numLodLevels_>10 )
     116                    {
     117                        CCOUT(2) << "More than 10 LoD levels requested. Creating only 10." << endl;
     118                        this->numLodLevels_ = 10;
     119                    }
     120                    if( this->bLodEnabled_ )
     121                    {
     122                        float volume = this->mesh_.getEntity()->getBoundingBox().volume();
     123    //                     float scaleFactor = 1;
     124
     125    //                     BaseObject* creatorPtr = this;
     126    //
     127    //                     while(creatorPtr!=NULL&&orxonox_cast<WorldEntity*>(creatorPtr))
     128    //                     {
     129    //                         scaleFactor *= getBiggestScale(((WorldEntity*) creatorPtr)->getScale3D());
     130    //                         creatorPtr = creatorPtr->getCreator();
     131    //                     }
     132    //                     COUT(0) << "name: " << this->meshSrc_ << "scaleFactor: " << scaleFactor << ", volume: " << volume << endl;
     133
     134                        COUT(4) << "Setting lodLevel for " << this->meshSrc_<< " with lodLevel_: " << this->lodLevel_ <<" and volume: "<< volume << ":" << std::endl;
     135
     136#if OGRE_VERSION >= 0x010700
     137                        Ogre::Mesh::LodValueList distList;
     138#else
     139                        Ogre::Mesh::LodDistanceList distList;
     140#endif
     141
     142                        if( lodLevel_>0 )
     143                        {
     144    //                         float factor = scaleFactor*5/lodLevel_;
     145                            float factor = pow(volume, 2.0f / 3.0f) * 15.0f / lodLevel_;
     146
     147                            COUT(4) << "LodLevel set with factor: " << factor << endl;
     148
     149                            distList.push_back(70.0f*factor);
     150                            distList.push_back(140.0f*factor);
     151                            distList.push_back(170.0f*factor);
     152                            distList.push_back(200.0f*factor);
     153                            distList.push_back(230.0f*factor);
     154                            distList.push_back(250.0f*factor);
     155                            distList.push_back(270.0f*factor);
     156                            distList.push_back(290.0f*factor);
     157                            distList.push_back(310.0f*factor);
     158                            distList.push_back(330.0f*factor);
     159                            while(distList.size()>this->numLodLevels_)
     160                                distList.pop_back();
     161
     162
     163                            //Generiert LOD-Levels
     164                            this->mesh_.getEntity()->getMesh()->generateLodLevels(distList, Ogre::ProgressiveMesh::VRQ_PROPORTIONAL, this->lodReductionRate_);
     165                        }
     166                        else
     167                        {
     168                            std::string what;
     169                            if(lodLevel_>5)
     170                                what = ">5";
     171                            else
     172                                what = "<0";
     173
     174                            COUT(4)<<"LodLevel not set because lodLevel("<<lodLevel_<<") was "<<what<<"." << endl;
     175                        }
     176                    }
     177                    else
     178                        COUT(4) << "LodLevel for " << this->meshSrc_ << " not set because is disabled." << endl;
     179                }
    85180            }
    86181        }
  • code/trunk/src/orxonox/graphics/Model.h

    r5781 r7163  
    4545
    4646            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    47             void registerVariables();
    4847
    4948            virtual void changedVisibility();
     
    6261                { return this->bCastShadows_; }
    6362
    64         private:
     63        protected:
     64            void registerVariables();
    6565            void changedMesh();
    6666            void changedShadows();
     67
     68            //LoD
     69            inline void setLodLevel(float lodLevel)
     70                { this->lodLevel_ =  lodLevel; }
     71            inline float getLodLevel() const
     72                { return this->lodLevel_; }
     73            float getBiggestScale(Vector3 scale3d);
    6774
    6875            std::string meshSrc_;
    6976            Mesh mesh_;
    7077            bool bCastShadows_;
     78
     79            //LoD
     80            float lodLevel_;
     81            bool bLodEnabled_;
     82            unsigned int numLodLevels_;
     83            float lodReductionRate_;
     84
    7185    };
    7286}
  • code/trunk/src/orxonox/graphics/ParticleEmitter.h

    r5781 r7163  
    4444
    4545            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    46             void registerVariables();
    4746
    4847            virtual void changedVisibility();
     
    7473            std::string        source_;
    7574            LODParticle::Value   LOD_;
     75
     76        private:
     77            void registerVariables();
    7678    };
    7779}
  • code/trunk/src/orxonox/infos/GametypeInfo.cc

    r5781 r7163  
    4242    registerMemberNetworkFunction(GametypeInfo, dispatchKillMessage);
    4343    registerMemberNetworkFunction(GametypeInfo, dispatchDeathMessage);
     44    registerMemberNetworkFunction(GametypeInfo, dispatchStaticMessage);
     45    registerMemberNetworkFunction(GametypeInfo, dispatchFadingMessage);
    4446
    4547    GametypeInfo::GametypeInfo(BaseObject* creator) : Info(creator)
     
    110112    }
    111113
     114    void GametypeInfo::sendStaticMessage(const std::string& message, unsigned int clientID, const ColourValue& colour)
     115    {
     116        if (GameMode::isMaster())
     117        {
     118            if (clientID == CLIENTID_SERVER)
     119                this->dispatchStaticMessage(message, colour);
     120            else
     121                callMemberNetworkFunction(GametypeInfo, dispatchStaticMessage, this->getObjectID(), clientID, message, colour);
     122        }
     123    }
     124
     125    void GametypeInfo::sendFadingMessage(const std::string& message, unsigned int clientID)
     126    {
     127        if (GameMode::isMaster())
     128        {
     129            if (clientID == CLIENTID_SERVER)
     130                this->dispatchFadingMessage(message);
     131            else
     132                callMemberNetworkFunction(GametypeInfo, dispatchFadingMessage, this->getObjectID(), clientID, message);
     133        }
     134    }
     135
    112136    void GametypeInfo::dispatchAnnounceMessage(const std::string& message)
    113137    {
     
    127151            it->deathmessage(this, message);
    128152    }
     153
     154     void GametypeInfo::dispatchStaticMessage(const std::string& message, const ColourValue& colour)
     155    {
     156        for (ObjectList<GametypeMessageListener>::iterator it = ObjectList<GametypeMessageListener>::begin(); it != ObjectList<GametypeMessageListener>::end(); ++it)
     157            it->staticmessage(this, message, colour);
     158    }
     159
     160     void GametypeInfo::dispatchFadingMessage(const std::string& message)
     161    {
     162        for (ObjectList<GametypeMessageListener>::iterator it = ObjectList<GametypeMessageListener>::begin(); it != ObjectList<GametypeMessageListener>::end(); ++it)
     163            it->fadingmessage(this, message);
     164    }
    129165}
  • code/trunk/src/orxonox/infos/GametypeInfo.h

    r5781 r7163  
    4545            virtual ~GametypeInfo();
    4646
    47             void registerVariables();
    48 
    4947            inline bool hasStarted() const
    5048                { return this->bStarted_; }
     
    6462            void sendKillMessage(const std::string& message, unsigned int clientID);
    6563            void sendDeathMessage(const std::string& message, unsigned int clientID);
     64            void sendStaticMessage(const std::string& message, unsigned int clientID, const ColourValue& colour);
     65            void sendFadingMessage(const std::string& message, unsigned int clientID);
    6666
    6767            void dispatchAnnounceMessage(const std::string& message);
    6868            void dispatchKillMessage(const std::string& message);
    6969            void dispatchDeathMessage(const std::string& message);
     70            void dispatchStaticMessage(const std::string& message,const ColourValue& colour);
     71            void dispatchFadingMessage(const std::string& message);
    7072
    7173        private:
     74            void registerVariables();
     75
    7276            bool bStarted_;
    7377            bool bEnded_;
  • code/trunk/src/orxonox/infos/HumanPlayer.h

    r5781 r7163  
    4343            virtual ~HumanPlayer();
    4444
    45             void registerVariables();
    4645            void setConfigValues();
    4746
     
    101100            std::string gametypeHudTemplate_;
    102101            OverlayGroup* gametypeHud_;
     102        private:
     103            void registerVariables();
    103104    };
    104105}
  • code/trunk/src/orxonox/infos/PlayerInfo.cc

    r6417 r7163  
    177177            return;
    178178
    179 //         assert( this->temporaryControllableEntity_==0 );
     179        assert( this->oldControllableEntity_==0 );
    180180
    181181        this->oldControllableEntity_ = this->controllableEntity_;
     
    184184
    185185        entity->setPlayer(this);
     186        entity->setController(this->controller_);
    186187
    187188        if (this->controller_)
     
    222223            return;
    223224
     225        this->controllableEntity_->setController(0);
     226       
    224227        this->controllableEntity_ = this->oldControllableEntity_;
    225228        this->controllableEntityID_ = this->controllableEntity_->getObjectID();
  • code/trunk/src/orxonox/infos/PlayerInfo.h

    r6417 r7163  
    3535#include "core/SubclassIdentifier.h"
    3636
    37 namespace orxonox
    38 {
    39     class _OrxonoxExport PlayerInfo : public Info
    40     {
     37namespace orxonox // tolua_export
     38{ // tolua_export
     39    class _OrxonoxExport PlayerInfo // tolua_export
     40        : public Info
     41    { // tolua_export
    4142        public:
    4243            PlayerInfo(BaseObject* creator);
    4344            virtual ~PlayerInfo();
    44 
    45             void registerVariables();
    4645
    4746            virtual void changedName();
     
    9190
    9291        private:
     92            void registerVariables();
    9393            void networkcallback_changedcontrollableentityID();
    9494            void networkcallback_changedgtinfoID();
     
    103103            const GametypeInfo* gtinfo_;
    104104            unsigned int gtinfoID_;
    105     };
    106 }
     105    }; // tolua_export
     106} // tolua_export
    107107
    108108#endif /* _PlayerInfo_H__ */
  • code/trunk/src/orxonox/interfaces/GametypeMessageListener.h

    r5781 r7163  
    4444            virtual void killmessage(const GametypeInfo* gtinfo, const std::string& message) {}
    4545            virtual void deathmessage(const GametypeInfo* gtinfo, const std::string& message) {}
     46            virtual void staticmessage(const GametypeInfo* gtinfo, const std::string& message, const ColourValue& colour) {}
     47            virtual void fadingmessage(const GametypeInfo* gtinfo, const std::string& message) {}
    4648    };
    4749}
  • code/trunk/src/orxonox/interfaces/InterfaceCompilation.cc

    r6711 r7163  
    5252        RegisterRootObject(GametypeMessageListener);
    5353    }
    54    
     54
    5555    //----------------------------
    5656    // PickupCarrier
     
    5959    {
    6060        RegisterRootObject(PickupCarrier);
    61        
    62         this->setCarrierName("PickupCarrier");
    6361    }
    64    
     62
    6563    PickupCarrier::~PickupCarrier()
    6664    {
     65
     66    }
     67
     68    void PickupCarrier::preDestroy(void)
     69    {
    6770        std::set<Pickupable*>::iterator it = this->pickups_.begin();
     71        std::set<Pickupable*>::iterator temp;
    6872        while(it != this->pickups_.end())
    6973        {
    70             (*(it++))->destroy();
     74            (*it)->carrierDestroyed();
     75            temp = it;
     76            it = this->pickups_.begin();
     77            if(it == temp) // Infinite loop avoidance, in case the pickup wasn't removed from the carrier somewhere in the carrierDestroy() procedure.
     78            {
     79                COUT(2) << "Oops. In a PickupCarrier, while cleaning up, a Pickupable (&" << (*temp) << ") didn't unregister itself as it should have." << std::endl;;
     80                it++;
     81            }
    7182        }
    7283
     
    8495        this->isForPlayer_ = true;
    8596    }
    86    
     97
    8798    //----------------------------
    8899    // RadarListener
  • code/trunk/src/orxonox/interfaces/NotificationListener.h

    r5929 r7163  
    4747    class Notification;
    4848
     49    /**
     50    @brief
     51        NotificationListener interface.
     52    @author
     53        Fabian 'x3n' Landau
     54    */
    4955    class _OrxonoxExport NotificationListener : virtual public OrxonoxClass
    5056    {
  • code/trunk/src/orxonox/interfaces/PickupCarrier.h

    • Property svn:eol-style set to native
    r6711 r7163  
    4545#include "core/OrxonoxClass.h"
    4646
    47 namespace orxonox // tolua_export
    48 { // tolua_export
     47namespace orxonox
     48{
    4949
    5050    //! Forward-declarations.
     
    5454    class InvisiblePickup;
    5555    class MetaPickup;
     56    class DronePickup;
    5657    class SpeedPickup;
    5758
     
    6263        Damian 'Mozork' Frick
    6364    */
    64     class _OrxonoxExport PickupCarrier  // tolua_export
    65         : virtual public OrxonoxClass
    66     { // tolua_export
     65    class _OrxonoxExport PickupCarrier : virtual public OrxonoxClass
     66    {
    6767        //! So that the different Pickupables have full access to their PickupCarrier.
    6868        friend class Pickupable;
    6969        friend class PickupManager;
    70         //! Friends. 
     70        //! Friends.
    7171        friend class Pickup;
    7272        friend class HealthPickup;
    7373        friend class InvisiblePickup;
    7474        friend class MetaPickup;
     75        friend class DronePickup;
    7576        friend class SpeedPickup;
    7677
     
    7879            PickupCarrier(); //!< Constructor.
    7980            virtual ~PickupCarrier(); //!< Destructor.
    80 
    81             /**
    82             @brief Can be called to pick up a Pickupable.
    83             @param pickup A pointer to the Pickupable.
    84             @return Returns true if the Pickupable was picked up, false if not.
    85             */
    86             bool pickup(Pickupable* pickup)
    87                 {
    88                     bool pickedUp = this->pickups_.insert(pickup).second;
    89                     if(pickedUp)
    90                     {
    91                         COUT(4) << "Picked up Pickupable " << pickup->getIdentifier()->getName() << "(&" << pickup << ")." << std::endl;
    92                         pickup->pickedUp(this);
    93                     }
    94                     return pickedUp;
    95                 }
    96 
    97             /**
    98             @brief Can be called to drop a Pickupable.
    99             @param pickup A pointer to the Pickupable.
    100             @param drop If the Pickupable should just be removed from the PickupCarrier without further action, this can be set to false. true is default.
    101             @return Returns true if the Pickupable has been dropped, false if not.
    102             */
    103             bool drop(Pickupable* pickup, bool drop = true)
    104                 {
    105                     bool dropped = this->pickups_.erase(pickup) == 1;
    106                     if(dropped && drop)
    107                     {
    108                         COUT(4) << "Dropping Pickupable " << pickup->getIdentifier()->getName() << "(&" << pickup << ")." << std::endl;
    109                         pickup->dropped();
    110                     }
    111                     return dropped;
    112                 }
     81            void preDestroy(void);
    11382
    11483            /**
     
    169138            */
    170139            virtual const Vector3& getCarrierPosition(void) = 0;
    171            
    172             /**
    173             @brief Get the name of this PickupCarrier.
    174             @return Returns the name as a string.
    175             */
    176             const std::string& getCarrierName(void) { return this->carrierName_; } // tolua_export
    177            
    178         protected:       
     140
     141        protected:
    179142            /**
    180143            @brief Get all direct children of this PickupSpawner.
     
    197160            std::set<Pickupable*>& getPickups(void)
    198161                { return this->pickups_; }
    199                
    200             /**
    201             @brief Set the name of this PickupCarrier.
    202                    The name needs to be set in the constructor of every class inheriting from PickupCarrier, by calling setCarrierName().
    203             @param name The name to be set.
    204             */
    205             void setCarrierName(const std::string& name)
    206                 { this->carrierName_ = name; }
    207        
     162
    208163        private:
    209164            std::set<Pickupable*> pickups_; //!< The list of Pickupables carried by this PickupCarrier.
    210             std::string carrierName_; //!< The name of the PickupCarrier, as displayed in the PickupInventory.
    211            
     165
    212166            /**
    213             @brief Get the number of carrier children this PickupCarrier has.
    214             @return Returns the number of carrier children.
     167            @brief Adds a Pickupable to the list of pickups that are carried by this PickupCarrier.
     168            @param pickup A pointer to the pickup to be added.
     169            @return Returns true if successfull, false if the Pickupable was already present.
    215170            */
    216             unsigned int getNumCarrierChildren(void)
     171            bool addPickup(Pickupable* pickup)
    217172                {
    218                     std::vector<PickupCarrier*>* list = this->getCarrierChildren();
    219                     unsigned int size = list->size();
    220                     delete list;
    221                     return size;
     173                    COUT(4) << "Adding Pickupable (&" << pickup << ") to PickupCarrier (&" << this << ")" << std::endl;
     174                    return this->pickups_.insert(pickup).second;
    222175                }
    223            
     176
    224177            /**
    225             @brief Get the index-th child of this PickupCarrier.
    226             @param index The index of the child to return.
    227             @return Returns the index-th child.
     178            @brief Removes a Pickupable from the list of pickups that are carried by thsi PickupCarrier.
     179            @param pickup A pointer to the pickup to be removed.
     180            @return Returns true if successfull, false if the Pickupable was not present in the list.
    228181            */
    229             PickupCarrier* getCarrierChild(unsigned int index)
     182            bool removePickup(Pickupable* pickup)
    230183                {
    231                     std::vector<PickupCarrier*>* list = this->getCarrierChildren();
    232                     if(list->size() < index)
    233                         return NULL;
    234                     PickupCarrier* carrier = (*list)[index];
    235                     delete list;
    236                     return carrier;
     184                    COUT(4) << "Removing Pickupable (&" << pickup << ") from PickupCarrier (&" << this << ")" << std::endl;
     185                    return this->pickups_.erase(pickup) == 1;
    237186                }
    238            
    239             /**
    240             @brief Get the number of Pickupables this PickupCarrier carries.
    241             @return returns the number of pickups.
    242             */
    243             unsigned int getNumPickups(void)
    244                 { return this->pickups_.size(); }
    245            
    246             /**
    247             @brief Get the index-th Pickupable of this PickupCarrier.
    248             @param index The index of the Pickupable to return.
    249             @return Returns the index-th pickup.
    250             */
    251             Pickupable* getPickup(unsigned int index)
    252                 {
    253                     std::set<Pickupable*>::iterator it;
    254                     for(it = this->pickups_.begin(); index != 0 && it != this->pickups_.end(); it++)
    255                         index--;
    256                     if(it == this->pickups_.end())
    257                         return NULL;
    258                     return *it;
    259                 }
    260            
    261     }; // tolua_export
    262 } // tolua_export
     187
     188    };
     189}
    263190
    264191#endif /* _PickupCarrier_H__ */
  • code/trunk/src/orxonox/interfaces/Pickupable.cc

    • Property svn:eol-style set to native
    r6901 r7163  
    3434#include "Pickupable.h"
    3535
     36#include "core/LuaState.h"
     37#include "core/GUIManager.h"
    3638#include "core/Identifier.h"
    3739#include "core/CoreIncludes.h"
     40#include "util/Convert.h"
     41#include "infos/PlayerInfo.h"
    3842#include "pickup/PickupIdentifier.h"
     43#include "worldentities/pawns/Pawn.h"
    3944#include "PickupCarrier.h"
    4045
    4146namespace orxonox
    4247{
    43    
     48
    4449    /**
    4550    @brief
     
    4752    */
    4853    Pickupable::Pickupable() : pickupIdentifier_(NULL), used_(false), pickedUp_(false)
    49     {       
     54    {
    5055        RegisterRootObject(Pickupable);
    51        
     56
    5257        this->carrier_ = NULL;
    53        
     58
    5459        this->pickupIdentifier_ = new PickupIdentifier(this);
    55     }
    56    
    57     /**
    58     @brief
    59         Destructor.
     60        this->beingDestroyed_ = false;
     61        this->enabled_ = true;
     62    }
     63
     64    /**
     65    @brief
     66        Destructor.
    6067    */
    6168    Pickupable::~Pickupable()
    6269    {
    63         if(this->isUsed())
    64             this->setUsed(false);
    65        
    66         if(this->isPickedUp() && this->getCarrier() != NULL)
    67         {
    68             this->getCarrier()->drop(this, false);
    69             this->setCarrier(NULL);
    70         }
    71        
     70        COUT(4) << "Pickupable (" << this->getIdentifier()->getName() << ") (&" << this << ") destroyed." << std::endl;
    7271        if(this->pickupIdentifier_ != NULL)
    7372            this->pickupIdentifier_->destroy();
    7473    }
    75    
     74
     75    /**
     76    @brief
     77        A method that is called by OrxonoxClass::destroy() before the object is actually destroyed.
     78    */
     79    void Pickupable::preDestroy(void)
     80    {
     81        this->beingDestroyed_ = true;
     82
     83        if(this->isPickedUp())
     84            this->drop(false); // Drops the pickup without creating a PickupSpawner.
     85    }
     86
     87    /**
     88    @brief
     89        Is called internally within the pickup module to destroy pickups.
     90    */
     91    void Pickupable::destroy(void)
     92    {
     93        this->destroyPickup();
     94    }
     95
     96    /**
     97    @brief
     98        Destroys a Pickupable.
     99        If the Pickupable is already in the process of being destroyed a warning is displayed and this method is skipped.
     100    */
     101    void Pickupable::destroyPickup(void)
     102    {
     103        if(!this->beingDestroyed_)
     104            this->OrxonoxClass::destroy();
     105        else
     106            COUT(2) << this->getIdentifier()->getName() << " may be unsafe. " << std::endl;
     107    }
     108
    76109    /**
    77110    @brief
     
    84117    bool Pickupable::setUsed(bool used)
    85118    {
    86         if(this->used_ == used)
    87             return false;
    88        
     119        if(this->used_ == used || !this->isPickedUp()) // If either the used status of the Pickupable doesn't change or it isn't picked up.
     120            return false;
     121
     122        if((!this->isUsable() && used) || (!this->isUnusable() && !used)) // If either the Pickupable is requested to be used but it is not usable or the Pickupable is requested to be unused, while it is not unusable.
     123            return false;
     124
    89125        COUT(4) << "Pickupable (&" << this << ") set to used " << used << "." << std::endl;
    90        
     126
    91127        this->used_ = used;
    92128        this->changedUsed();
    93         return true;
    94     }
    95    
     129
     130        GUIManager::getInstance().getLuaState()->doString("PickupInventory.update()");
     131        return true;
     132    }
     133
    96134    /**
    97135    @brief
     
    106144        if(carrier == NULL)
    107145            return false;
     146
    108147        return this->isTarget(carrier->getIdentifier());
    109148    }
    110    
     149
    111150    /**
    112151    @brief
     
    125164                return true;
    126165        }
     166
    127167        return false;
    128168    }
    129        
     169
    130170    /**
    131171    @brief
     
    140180        return this->addTarget(target->getIdentifier());
    141181    }
    142    
     182
    143183    /**
    144184    @brief
     
    153193        if(this->isTarget(target)) //!< If the input target is already present in the list of targets.
    154194            return false;
    155        
     195
    156196        COUT(4) << "Target " << target->getName() << " added to Pickupable (&" << this << ")." << std::endl;
    157197        this->targets_.push_back(target);
    158198        return true;
    159199    }
    160    
    161     /**
    162     @brief 
    163         Sets the Pickupable to picked up.
    164         This method will be called by the PickupCarrier picking the Pickupable up.
     200
     201    /**
     202    @brief
     203        Can be called to pick up a Pickupable.
    165204    @param carrier
    166         The PickupCarrier that picked the Pickupable up.
    167     @return
    168         Returns false if, for some reason, the pickup could not be picked up, e.g. it was picked up already.
    169     */
    170     bool Pickupable::pickedUp(PickupCarrier* carrier)
    171     {
    172         if(this->isPickedUp()) //!< If the Pickupable is already picked up.
    173             return false;
     205        A pointer to the PickupCarrier that picks up the Pickupable.
     206    @return
     207        Returns true if the Pickupable was picked up, false if not.
     208    */
     209    bool Pickupable::pickup(PickupCarrier* carrier)
     210    {
     211        if(carrier == NULL || this->isPickedUp()) //!< If carrier is NULL or the Pickupable is already picked up.
     212            return false;
     213
     214        if(!this->setCarrier(carrier))
     215        {
     216            COUT(3) << "A Pickupable (&" << this << ") was trying to be added to a PickupCarrier, but was already present." << std::endl;
     217            return false;
     218        }
    174219       
     220        this->setPickedUp(true);
    175221        COUT(4) << "Pickupable (&" << this << ") got picked up by a PickupCarrier (&" << carrier << ")." << std::endl;
    176         this->setCarrier(carrier);
    177         this->setPickedUp(true);
    178         return true;
    179     }
    180    
     222        return true;
     223    }
     224
     225    /**
     226    @brief
     227        Can be called to drop a Pickupable.
     228    @param createSpawner
     229        If true a spawner is to be created for the dropped Pickupable. True is default.
     230    @return
     231        Returns true if the Pickupable has been dropped, false if not.
     232    */
     233    bool Pickupable::drop(bool createSpawner)
     234    {
     235        if(!this->isPickedUp()) // If the Pickupable is not picked up.
     236            return false;
     237
     238        assert(this->getCarrier()); // The Carrier cannot be NULL at this point.
     239        if(!this->getCarrier()->removePickup(this)) //TODO Shouldn't this be a little later?
     240            COUT(2) << "Pickupable (&" << this << ", " << this->getIdentifier()->getName() << ") is being dropped, but it was not present in the PickupCarriers list of pickups." << std::endl;
     241
     242        COUT(4) << "Pickupable (&" << this << ") got dropped up by a PickupCarrier (&" << this->getCarrier() << ")." << std::endl;
     243        this->setUsed(false);
     244        this->setPickedUp(false);
     245
     246        bool created = false;
     247        if(createSpawner)
     248            created = this->createSpawner();
     249
     250        this->setCarrier(NULL);
     251
     252        if(!created && createSpawner) // If a PickupSpawner should have been created but wasn't.
     253            this->destroy();
     254
     255        return true;
     256    }
     257
    181258    /**
    182259    @brief
     
    189266    bool Pickupable::setPickedUp(bool pickedUp)
    190267    {
    191         if(this->pickedUp_ == pickedUp)
    192             return false;
    193        
     268        if(this->pickedUp_ == pickedUp) // If the picked up status has not changed.
     269            return false;
     270
    194271        COUT(4) << "Pickupable (&" << this << ") set to pickedUp " << pickedUp << "." << std::endl;
    195        
     272
    196273        this->pickedUp_ = pickedUp;
     274        if(!pickedUp) // if the Pickupable has been dropped it unregisters itself with its PickupCarrier.
     275            this->getCarrier()->removePickup(this);
    197276        this->changedPickedUp();
    198         return true;
    199     }
    200        
     277        GUIManager::getInstance().getLuaState()->doString("PickupInventory.update()");
     278        return true;
     279    }
     280
    201281    /**
    202282    @brief
     
    204284    @param carrier
    205285        Sets the input PickupCarrier as the carrier of the pickup.
    206     */
    207     inline bool Pickupable::setCarrier(PickupCarrier* carrier)
    208     {
    209         if(this->carrier_ == carrier)
    210             return false;
    211        
     286    @param tell
     287        If true (default) the pickup is added to the list of pickups in the PickupCarrier.
     288    @return
     289        Returns true if successful, false if not.
     290    */
     291    bool Pickupable::setCarrier(orxonox::PickupCarrier* carrier, bool tell)
     292    {
     293        if(this->carrier_ == carrier) // If the PickupCarrier doesn't change.
     294            return false;
     295
    212296        COUT(4) << "Pickupable (&" << this << ") changed Carrier (& " << carrier << ")." << std::endl;
     297
     298        if(carrier != NULL && tell)
     299        {
     300            if(!carrier->addPickup(this))
     301                return false;
     302        }
    213303       
    214304        this->carrier_ = carrier;
     
    216306        return true;
    217307    }
    218    
    219     /**
    220     @brief
    221         Sets the Pickupable to not picked up or dropped.
    222         This method will be called by the PickupCarrier dropping the Pickupable.
    223     @return
    224         Returns false if the pickup could not be dropped.
    225     */
    226     bool Pickupable::dropped(void)
    227     {
    228         if(!this->isPickedUp()) //!< If the Pickupable is not picked up.
    229             return false;
    230        
    231         COUT(4) << "Pickupable (&" << this << ") got dropped up by a PickupCarrier (&" << this->getCarrier() << ")." << std::endl;
    232         this->setUsed(false);
    233         this->setPickedUp(false);
    234        
    235         bool created = this->createSpawner();
    236        
    237         this->setCarrier(NULL);
    238        
    239         if(!created)
    240         {
    241             this->destroy();
    242         }
    243        
    244         return true;
    245     }
    246    
     308
     309    /**
     310    @brief
     311        Is called by the PickupCarrier when it is being destroyed.
     312    */
     313    void Pickupable::carrierDestroyed(void)
     314    {
     315        this->destroy();
     316    }
     317
    247318    /**
    248319    @brief
     
    255326        OrxonoxClass* item = NULL;
    256327        this->clone(item);
    257        
     328
    258329        Pickupable* pickup = dynamic_cast<Pickupable*>(item);
    259        
     330
    260331        COUT(4) << "Pickupable (&" << this << ") cloned. Clone is new Pickupable (&" << pickup << ")." << std::endl;
    261332        return pickup;
    262333    }
    263    
     334
    264335    /**
    265336    @brief
     
    273344        SUPER(Pickupable, clone, item);
    274345    }
    275    
     346
     347    /**
     348    @brief
     349        Method to transcribe a Pickupable as a Rewardable to the player.
     350    @param player
     351        A pointer to the PlayerInfo, do whatever you want with it.
     352    @return
     353        Return true if successful.
     354    */
     355    bool Pickupable::reward(PlayerInfo* player)
     356    {
     357        ControllableEntity* entity = player->getControllableEntity();
     358        Pawn* pawn = static_cast<Pawn*>(entity);
     359        PickupCarrier* carrier = static_cast<PickupCarrier*>(pawn);
     360        return this->pickup(carrier);
     361    }
     362
    276363}
  • code/trunk/src/orxonox/interfaces/Pickupable.h

    • Property svn:eol-style set to native
    r6901 r7163  
    4141
    4242#include "core/OrxonoxClass.h"
     43#include "Rewardable.h"
    4344
    44 namespace orxonox
    45 {
    46    
     45namespace orxonox // tolua_export
     46{ // tolua_export
     47
    4748    /**
    4849    @brief
     
    5152        Damian 'Mozork' Frick
    5253    */
    53     class _OrxonoxExport Pickupable : virtual public OrxonoxClass
    54     {
     54    class _OrxonoxExport Pickupable  // tolua_export
     55        : virtual public OrxonoxClass, public Rewardable
     56    {  // tolua_export
    5557        protected:
    5658            Pickupable(); //!< Default constructor.
    57        
     59
    5860        public:
    5961            virtual ~Pickupable(); //!< Default destructor.
    60            
     62
    6163            /**
    6264            @brief Get whether the pickup is currently in use or not.
    6365            @return Returns true if the pickup is currently in use.
    6466            */
    65             inline bool isUsed(void)
    66                 { return this->used_; }
     67            inline bool isUsed(void) { return this->used_; }  // tolua_export
    6768            /**
    6869            @brief  Should be called when the pickup has transited from used to unused or the other way around.
     
    7071            */
    7172            virtual void changedUsed(void) {}
    72            
     73
    7374            /**
    7475            @brief Get the carrier of the pickup.
     
    8283            */
    8384            virtual void changedCarrier(void) {}
    84            
     85
    8586            /**
    8687            @brief Returns whether the Pickupable is currently picked up.
    8788            @return Returns true if the Pickupable is currently picked up, false if not.
    8889            */
    89             inline bool isPickedUp(void)
    90                 { return this->pickedUp_; }
     90            inline bool isPickedUp(void) { return this->pickedUp_; }  // tolua_export
    9191            /**
    9292            @brief  Should be called when the pickup has transited from picked up to dropped or the other way around.
     
    9494            */
    9595            virtual void changedPickedUp(void) {}
     96
     97            /**
     98            @brief Returns whether the Pickupable can be used.
     99            @return Returns true if it can be used.
     100            */
     101            inline bool isUsable(void) { return this->enabled_; } // tolua_export
    96102           
    97             bool pickedUp(PickupCarrier* carrier); //!< Sets the Pickupable to picked up.
    98             bool dropped(void); //!< Sets the Pickupable to not picked up or dropped.
    99            
     103            /**
     104            @brief Returns whether the Pickupable can be unused.
     105            @return Returns true if it can be unused.
     106            */
     107            inline bool isUnusable(void) { return this->enabled_; } // tolua_export
     108
     109            /**
     110            @brief Returns whether the Pickupable is enabled.
     111                   Once a Pickupable is disabled it cannot be enabled again. A Pickupable that is disabled can neither be used nor unused.
     112            @return Returns true if the Pickupable is enabled.
     113            */
     114            inline bool isEnabled(void)
     115                { return this->enabled_; }
     116
     117            bool pickup(PickupCarrier* carrier); //!< Can be called to pick up a Pickupable.
     118            bool drop(bool createSpawner = true); //!< Can be called to drop a Pickupable.
     119
    100120            virtual bool isTarget(PickupCarrier* carrier) const; //!< Get whether the given PickupCarrier is a target of this pickup.
    101121            bool isTarget(const Identifier* identifier) const; //!< Get whether a given class, represented by the input Identifier, is a target of this Pickupable.
    102122            bool addTarget(PickupCarrier* target); //!< Add a PickupCarrier as target of this pickup.
    103123            bool addTarget(Identifier* identifier); //!< Add a class, representetd by the input Identifier, as target of this pickup.
    104            
     124
    105125            Pickupable* clone(void); //!< Creates a duplicate of the Pickupable.
    106126            virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the input OrxonoxClass.
    107            
     127
    108128            /**
    109129            @brief Get the PickupIdentifier of this Pickupable.
     
    112132            virtual const PickupIdentifier* getPickupIdentifier(void)
    113133                { return this->pickupIdentifier_; }
    114                
     134
    115135            bool setUsed(bool used); //!< Sets the Pickupable to used or unused, depending on the input.
    116136            bool setPickedUp(bool pickedUp); //!< Helper method to set the Pickupable to either picked up or not picked up.
    117             bool setCarrier(PickupCarrier* carrier); //!< Sets the carrier of the pickup.
    118            
     137            //TODO: private?
     138            bool setCarrier(PickupCarrier* carrier, bool tell = true); //!< Sets the carrier of the pickup.
     139
     140            //TODO: private?
     141            virtual void carrierDestroyed(void); //!< Is called by the PickupCarrier when it is being destroyed.
     142
     143            void destroy(void); //!< Is called internally within the pickup module to destroy pickups.
     144
    119145        protected:
    120146            /**
     
    122148            */
    123149            void initializeIdentifier(void) {}
    124            
     150
     151            virtual void preDestroy(void); //!< A method that is called by OrxonoxClass::destroy() before the object is actually destroyed.
     152            virtual void destroyPickup(void); //!< Destroys a Pickupable.
     153
     154            /**
     155            @brief Sets the Pickuapble to disabled.
     156            */
     157            inline void setDisabled(void)
     158                { this->enabled_ = false; }
     159
    125160            /**
    126161            @brief Facilitates the creation of a PickupSpawner upon dropping of the Pickupable.
     
    131166            */
    132167            virtual bool createSpawner(void) = 0;
    133            
     168
    134169            PickupIdentifier* pickupIdentifier_; //!< The PickupIdentifier of this Pickupable.
    135            
     170
    136171        private:
    137            
    138             bool used_; //!< Whether the pickup is currently in use or not.
    139             bool pickedUp_; //!< Whether the pickup is currently picked up or not.
    140            
    141             PickupCarrier* carrier_; //!< The carrier of the pickup.
    142             std::list<Identifier*> targets_; //!< The possible targets of this pickup.
    143172
    144     };
    145    
     173            bool used_; //!< Whether the Pickupable is currently in use or not.
     174            bool pickedUp_; //!< Whether the Pickupable is currently picked up or not.
     175
     176            bool enabled_; //!< Whether the Pickupable is enabled or not.
     177
     178            PickupCarrier* carrier_; //!< The PickupCarrier of the Pickupable.
     179            std::list<Identifier*> targets_; //!< The possible targets of this Pickupable.
     180
     181            bool beingDestroyed_; //!< Is true if the Pickupable is in the process of being destroyed.
     182
     183        // For implementing the Rewardable interface:
     184        public:
     185            virtual bool reward(PlayerInfo* player); //!< Method to transcribe a Pickupable as a Rewardable to the player.
     186
     187    };  // tolua_export
     188
    146189    SUPER_FUNCTION(10, Pickupable, changedUsed, false);
    147190    SUPER_FUNCTION(12, Pickupable, changedCarrier, false);
    148191    SUPER_FUNCTION(13, Pickupable, changedPickedUp, false);
    149 }
     192}  // tolua_export
    150193
    151194#endif /* _Pickupable_H__ */
  • code/trunk/src/orxonox/interfaces/RadarListener.h

    r5781 r7163  
    4141        virtual ~RadarListener() { }
    4242
    43         virtual void displayObject(RadarViewable* viewable, bool bIsMarked) = 0;
     43        virtual void addObject(RadarViewable* viewable) = 0;
     44        virtual void removeObject(RadarViewable* viewable) = 0;
     45        virtual void objectChanged(RadarViewable* viewable) = 0;
    4446        virtual float getRadarSensitivity() const = 0;
    4547        virtual void radarTick(float dt) = 0;
  • code/trunk/src/orxonox/interfaces/RadarViewable.cc

    r6417 r7163  
    2929#include "RadarViewable.h"
    3030
    31 #include <OgreSceneManager.h>
    32 #include <OgreSceneNode.h>
    33 #include <OgreEntity.h>
    34 
    3531#include "util/StringUtils.h"
    3632#include "core/CoreIncludes.h"
    37 #include "tools/DynamicLines.h"
     33#include "core/GameMode.h"
    3834#include "worldentities/WorldEntity.h"
    3935#include "Radar.h"
    4036#include "Scene.h"
    41 #include "overlays/Map.h"
    4237
    4338namespace orxonox
     
    4641        @brief Constructor.
    4742    */
    48     RadarViewable::RadarViewable()
    49         : MapNode_(NULL)
    50         , MapEntity_(NULL)
    51         , line_(NULL)
    52         , LineNode_(NULL)
    53         , isHumanShip_(false)
     43    RadarViewable::RadarViewable(BaseObject* creator, const WorldEntity* wePtr)
     44        : isHumanShip_(false)
    5445        , bVisibility_(true)
     46        , bInitialized_(false)
     47        , creator_(creator)
     48        , wePtr_(wePtr)
    5549        , radarObjectCamouflage_(0.0f)
    5650        , radarObjectShape_(Dot)
     
    6054
    6155        this->uniqueId_=getUniqueNumberString();
    62 /*
    63         if(Map::getSingletonPtr() && Map::getSingletonPtr()->getMapSceneManagerPtr())
     56        if( GameMode::showsGraphics() )
    6457        {
    65             this->addEntity();
     58            this->radar_ = this->creator_->getScene()->getRadar();
     59            this->radar_->addRadarObject(this);
    6660        }
    67 
    68         */
     61        this->bInitialized_ = true;
    6962    }
    7063
     
    7265    RadarViewable::~RadarViewable()
    7366    {
    74         if (this->isHumanShip_ && MapNode_)
    75             MapNode_->removeAllChildren();
    7667
    77         if (MapNode_)
    78             delete MapNode_;
    79 
    80         if (MapEntity_)
    81             delete MapEntity_;
    82 
    83         if (line_)
    84             delete line_;
    85 
    86         if (LineNode_)
    87             delete LineNode_;
    88     }
    89 
    90     void RadarViewable::addMapEntity()
    91     { //TODO Check shape and add accordantly
    92         if( this->MapNode_ && !this->MapEntity_ && Map::getSingletonPtr() && Map::getSingletonPtr()->getMapSceneManagerPtr() )
     68        if( this->bInitialized_ )
    9369        {
    94             COUT(0) << "Adding " << this->uniqueId_ << " to Map.\n";
    95             this->MapEntity_ = Map::getSingletonPtr()->getMapSceneManagerPtr()->createEntity( this->uniqueId_, "drone.mesh");
    96             /*this->line_ =  Map::getSingletonPtr()->getMapSceneManagerPtr()->createManualObject(this->uniqueId_ + "_l");
    97             this->line_->begin("Map/line_", Ogre::RenderOperation::OT_LINE_STRIP);
    98             //line_->position(0, -it->getRVWorldPosition().y, 0);
    99             //this->line_->position(0, -20, 0);
    100             this->line_->position(0, 0, -10); //Front Arrow
    101             this->line_->position(0, 0, 0);
    102 
    103             this->line_->end(); */
    104             this->line_ = new Ogre::DynamicLines(Ogre::RenderOperation::OT_LINE_LIST);
    105             this->line_->addPoint( Vector3(0,0,0) );
    106             this->line_->addPoint( Vector3(0,0,0) );
    107 
    108             this->MapNode_->attachObject( this->MapEntity_ );
    109 
    110             this->LineNode_ = this->MapNode_->createChildSceneNode();
    111             this->LineNode_->attachObject( this->line_ );
    112         }
    113         else
    114         {
    115             COUT(0) << "Unable to load " << this->uniqueId_ << " to Map.\n";
     70            if( GameMode::showsGraphics() )
     71            {
     72                this->radar_->removeRadarObject(this);
     73            }
    11674        }
    11775    }
    11876
    119     void RadarViewable::updateMapPosition()
    120     {
    121         if( this->MapNode_ )
    122         {
    123             this->MapNode_->setPosition( this->getRVWorldPosition() );
    124             this->MapNode_->translate( this->getRVOrientedVelocity(), static_cast<Ogre::Node::TransformSpace>(3) );
    125             this->MapNode_->setOrientation( this->getWorldEntity()->getOrientation() );
    126 //Vector3 v = this->getRVWorldPosition();
    127             //this->line_->setPoint(1, Vector3(0,v.y,0) );
    128             this->line_->setPoint(1, Vector3( 0, static_cast<float>(static_cast<int>( -Map::getSingletonPtr()->movablePlane_->getDistance( this->getRVWorldPosition() ) ) ) ,0 ));
    129             this->line_->update();
    130             if( Map::getSingletonPtr()->playerShipNode_ )
    131                 this->LineNode_->setDirection( Map::getSingletonPtr()->playerShipNode_->getLocalAxes().GetColumn(1) ,Ogre::Node::TS_WORLD,Vector3::UNIT_Y);
    132         }
    133     }
    134 
    135     void RadarViewable::setRadarObjectDescription(const std::string& str)
    136     {
    137         Radar* radar = this->getWorldEntity()->getScene()->getRadar();
    138         if (radar)
    139             this->radarObjectShape_ = radar->addObjectDescription(str);
    140         else
    141         {
    142             CCOUT(2) << "Attempting to access the radar, but the radar is non existent." << std::endl;
    143         }
    144         this->radarObjectDescription_ = str;
    145     }
     77//     void RadarViewable::setRadarObjectDescription(const std::string& str)
     78//     {
     79//         Radar* radar = this->getWorldEntity()->getScene()->getRadar();
     80//         if (radar)
     81//             this->radarObjectShape_ = radar->addObjectDescription(str);
     82//         else
     83//         {
     84//             CCOUT(2) << "Attempting to access the radar, but the radar is non existent." << std::endl;
     85//         }
     86//         this->radarObjectDescription_ = str;
     87//     }
    14688
    14789    const Vector3& RadarViewable::getRVWorldPosition() const
     
    167109        }
    168110    }
     111
     112    void RadarViewable::settingsChanged()
     113    {
     114        if( GameMode::showsGraphics() )
     115        {
     116            this->radar_->radarObjectChanged(this);
     117        }
     118    }
    169119}
  • code/trunk/src/orxonox/interfaces/RadarViewable.h

    r5781 r7163  
    3636
    3737#include "util/Math.h"
    38 #include "util/OgreForwardRefs.h"
    3938#include "core/OrxonoxClass.h"
     39#include "core/SmartPtr.h"
    4040
    4141namespace orxonox
    4242{
     43    class BaseObject;
     44
    4345    /**
    4446    @brief Interface for receiving window events.
     
    5658
    5759    public:
    58         RadarViewable();
     60        RadarViewable(BaseObject* creator, const WorldEntity* wePtr);
    5961        virtual ~RadarViewable();
    6062
    6163        inline void setRadarObjectCamouflage(float camouflage)
    62             { this->radarObjectCamouflage_ = camouflage; }
     64            {
     65                if( this->radarObjectCamouflage_ != camouflage )
     66                {
     67                    this->radarObjectCamouflage_ = camouflage;
     68                    this->settingsChanged();
     69                }
     70            }
    6371        inline float getRadarObjectCamouflage() const
    6472            { return this->radarObjectCamouflage_; }
    6573
    6674        inline void setRadarObjectColour(const ColourValue& colour)
    67             { this->radarObjectColour_ = colour; }
     75            {
     76                if(this->radarObjectColour_ != colour)
     77                {
     78                    this->radarObjectColour_ = colour;
     79                    this->settingsChanged();
     80                }
     81            }
    6882        inline const ColourValue& getRadarObjectColour() const
    6983            { return this->radarObjectColour_; }
    7084
    71         void setRadarObjectDescription(const std::string& str);
    72         inline const std::string& getRadarObjectDescription() const
    73             { return this->radarObjectDescription_; }
     85//         void setRadarObjectDescription(const std::string& str);
     86//         inline const std::string& getRadarObjectDescription() const
     87//             { return this->radarObjectDescription_; }
    7488
    7589        inline void setRadarVisibility(bool b)
    76             { this->bVisibility_ = b; }
     90            {
     91                if(b!=this->bVisibility_)
     92                {
     93                    this->bVisibility_ = b;
     94                    this->settingsChanged();
     95                }
     96            }
    7797        inline bool getRadarVisibility() const
    7898            { return this->bVisibility_; }
    7999
    80         virtual const WorldEntity* getWorldEntity() const = 0;
     100        virtual const WorldEntity* getWorldEntity() const{ return this->wePtr_; }
    81101
    82102        const Vector3& getRVWorldPosition() const;
     
    84104
    85105        inline void setRadarObjectShape(Shape shape)
    86             { this->radarObjectShape_ = shape; }
     106            {
     107                if( this->radarObjectShape_ != shape )
     108                {
     109                    this->radarObjectShape_ = shape;
     110                    this->settingsChanged();
     111                }
     112            }
    87113        inline Shape getRadarObjectShape() const
    88114            { return this->radarObjectShape_; }
     115        void settingsChanged();
    89116
    90 /*
    91         inline void setMapNode(Ogre::SceneNode * node)
    92             { this->MapNode_ = node; }
    93         inline Ogre::SceneNode * getMapNode() const
    94             { return this->MapNode_; }
    95         inline void setMapEntity(Ogre::Entity * ent)
    96             { this->MapEntity_ = ent; }
    97         inline Ogre::Entity * getMapEntity() const
    98             { return this->MapEntity_; }
    99 */
    100         //Used for Map
    101         Ogre::SceneNode * MapNode_;
    102         Ogre::Entity * MapEntity_;
    103         Ogre::DynamicLines* line_;
    104         Ogre::SceneNode * LineNode_;
    105         void addMapEntity();
    106         void updateMapPosition();
     117
    107118        bool isHumanShip_;
    108119        inline const std::string& getUniqueId()
     
    115126        void validate(const WorldEntity* object) const;
    116127        bool bVisibility_;
     128        bool bInitialized_;
    117129        //Map
    118130        std::string uniqueId_;
     131        BaseObject* creator_;
    119132
    120133
    121134        //Radar
     135        const WorldEntity* wePtr_;
     136        SmartPtr<Radar> radar_;
    122137        float radarObjectCamouflage_;
    123138        Shape radarObjectShape_;
  • code/trunk/src/orxonox/interfaces/Rewardable.h

    r6417 r7163  
    4848        Damian 'Mozork' Frick
    4949    */
    50     class _OrxonoxExport Rewardable : public OrxonoxClass
     50    class _OrxonoxExport Rewardable : virtual public OrxonoxClass
    5151    {
    5252        public:
     
    5959                Must be implemented by every class inheriting from Rewardable.
    6060            @param player
    61                 A pointer to the ControllableEntity, do whatever you want with it.
     61                A pointer to the PlayerInfo, do whatever you want with it.
    6262            @return
    6363                Return true if successful.
  • code/trunk/src/orxonox/items/Engine.cc

    r6711 r7163  
    6464        this->boostBlur_ = 0;
    6565
    66         this->setCarrierName("Engine");
    6766        this->speedAdd_ = 0.0;
    6867        this->speedMultiply_ = 1.0;
  • code/trunk/src/orxonox/items/Engine.h

    r6711 r7163  
    4646
    4747            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    48             void registerVariables();
    4948            void setConfigValues();
    5049
     
    127126
    128127        private:
     128            void registerVariables();
    129129            void networkcallback_shipID();
    130130
  • code/trunk/src/orxonox/items/MultiStateEngine.h

    r6417 r7163  
    5353
    5454            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    55             void registerVariables();
    5655
    5756            virtual void tick(float dt);
     
    6867
    6968        private:
     69            void registerVariables();
     70
    7071            int state_;
    7172            int oldState_;
  • code/trunk/src/orxonox/overlays/CMakeLists.txt

    r6746 r7163  
    44  OverlayGroup.cc
    55
    6 COMPILATION_BEGIN OverlayCompilation.cc
     6#COMPILATION_BEGIN OverlayCompilation.cc
    77  InGameConsole.cc
    8   Map.cc
    9 COMPILATION_END
     8#COMPILATION_END
    109)
  • code/trunk/src/orxonox/overlays/GUISheet.cc

    r6746 r7163  
    3232#include "core/GUIManager.h"
    3333#include "core/XMLPort.h"
     34#include "core/GameMode.h"
    3435
    3536namespace orxonox
  • code/trunk/src/orxonox/pickup/PickupIdentifier.cc

    • Property svn:eol-style set to native
    r6725 r7163  
    3939namespace orxonox
    4040{
    41    
     41
    4242    /**
    4343    @brief
     
    4747    {
    4848        RegisterRootObject(PickupIdentifier);
    49        
     49
    5050        if(pickup == NULL)
    5151            COUT(1) << "Error, PickupIdentifier was created without a valid Pickupable." << std::endl;
    52        
     52
    5353        this->pickup_ = pickup;
    5454    }
    55    
     55
    5656    PickupIdentifier::~PickupIdentifier()
    5757    {
    5858
    5959    }
    60    
     60
    6161    /**
    6262    @brief
     
    7474            COUT(1) << "Error in PickupIdentifier::compare: Input Identifier is NULL." << std::endl;
    7575        }
    76        
     76
    7777        if(identifier->pickup_ == NULL && this->pickup_ == NULL)
    7878        {
     
    8080            COUT(1) << "Error in PickupIdentifier::compare: Pickup stored by Identifier is NULL." << std::endl;
    8181        }
    82        
     82
    8383        if(identifier->pickup_ == NULL)
    8484        {
     
    8686            COUT(1) << "Error in PickupIdentifier::compare: Pickup stored by Identifier is NULL." << std::endl;
    8787        }
    88        
     88
    8989        if(this->pickup_ == NULL)
    9090        {
     
    9292            COUT(1) << "Error in PickupIdentifier::compare: Pickup stored by Identifier is NULL." << std::endl;
    9393        }
    94        
     94
    9595        //! If the classIdentifiers are not the same (meaning the PickupIdentifiers identify different classes), the obviously the two Pickupables identified by the PickupIdentifiers cannot be the same. An ordering is established through the alphabetical ordering of the respective classnames.
    9696        if(!identifier->pickup_->getIdentifier()->isExactlyA(this->pickup_->getIdentifier()))
    9797            return this->pickup_->getIdentifier()->getName().compare(identifier->pickup_->getIdentifier()->getName());
    98        
     98
    9999        //! If the class is the same for both PickupIdentifiers we go on to check the parameters of the class.
    100100        //! If the two have a different number of parameters then obviusly something is very wrong.
     
    104104            return this->parameters_.size()-identifier->parameters_.size();
    105105        }
    106        
    107         //! We iterate through all parameters and compar their values (which are strings). The first parameter is the most significant. The ordering is once again established by the alphabetical comparison of the two value strings.
     106
     107        //! We iterate through all parameters and compare their values (which are strings). The first parameter is the most significant. The ordering is once again established by the alphabetical comparison of the two value strings.
    108108        for(std::map<std::string, std::string>::const_iterator it = this->parameters_.begin(); it != this->parameters_.end(); it++)
    109109        {
     
    117117                return it->second.compare(identifier->parameters_.find(it->first)->second);
    118118        }
    119            
     119
    120120        return 0;
    121121    }
    122    
     122
    123123    /**
    124124    @brief
     
    134134    {
    135135        COUT(4) << "PickupIdentifier " << name << ", " << value << std::endl;
    136        
     136
    137137        if(!(this->parameters_.find(name) == this->parameters_.end()))
    138138        {
     
    140140            return false;
    141141        }
    142        
     142
    143143        this->parameters_[name] = value;
    144        
     144
    145145        return true;
    146146    }
    147    
     147
    148148}
  • code/trunk/src/orxonox/pickup/PickupIdentifier.h

    • Property svn:eol-style set to native
    r6540 r7163  
    4141#include "core/Identifier.h"
    4242
    43 #include "core/OrxonoxClass.h" 
     43#include "core/OrxonoxClass.h"
    4444
    4545namespace orxonox
    4646{
    47    
     47
    4848    /**
    4949    @brief
     
    5757    class _OrxonoxExport PickupIdentifier : virtual public OrxonoxClass
    5858    {
    59        
     59
    6060        public:
    6161            PickupIdentifier(Pickupable* pickup); //!< Constructor.
    6262            ~PickupIdentifier(); //!< Destructor.
    63            
     63
    6464            virtual int compare(const PickupIdentifier* identifier) const; //!< Compares two PickupIdentifiers and returns 0 if a == b, <0 if a < b and >0 if a > b for a.compare(b).
    65            
     65
    6666            bool addParameter(std::string & name, std::string & value); //!< Add a parameter to the PickupIdentifier.
    67            
     67
    6868        private:
    6969            Pickupable* pickup_; //!< The Pickupable the PickupIdentififer is for.
    7070            std::map<std::string, std::string> parameters_; //!< The parameters identifying the type of the pickup beyond the class.
    71            
     71
    7272    };
    73    
     73
    7474    /**
    7575    @brief
     
    8181            { return lhs->compare(rhs) < 0; }
    8282    };
    83    
     83
    8484}
    8585
  • code/trunk/src/orxonox/sound/BaseSound.cc

    r6502 r7163  
    3333#include <al.h>
    3434
     35#include "util/Math.h"
    3536#include "core/CoreIncludes.h"
    3637#include "core/GameMode.h"
     
    248249        else // No source acquired so far, but might be set to playing or paused
    249250        {
    250             State state = this->state_; // save
     251            State state = static_cast<State>(this->state_); // save
    251252            if (this->isPlaying() || this->isPaused())
    252253                doPlay();
  • code/trunk/src/orxonox/sound/BaseSound.h

    r6417 r7163  
    112112        float           volume_;
    113113        bool            bLooping_;
    114         State           state_;
     114        uint8_t         state_;       // This Variable is actually of type State
    115115        float           pitch_;
    116116
  • code/trunk/src/orxonox/sound/SoundStreamer.cc

    • Property svn:eol-style set to native
  • code/trunk/src/orxonox/sound/SoundStreamer.h

    • Property svn:eol-style set to native
  • code/trunk/src/orxonox/sound/WorldSound.cc

    r6417 r7163  
    5858        registerVariable(bLooping_, ObjectDirection::ToClient, new NetworkCallback<WorldSound>(this, &WorldSound::loopingChanged));
    5959        registerVariable(pitch_,    ObjectDirection::ToClient, new NetworkCallback<WorldSound>(this, &WorldSound::pitchChanged));
    60         registerVariable((int&)(BaseSound::state_), ObjectDirection::ToClient, new NetworkCallback<WorldSound>(this, &WorldSound::stateChanged));
     60        registerVariable((uint8_t&)(BaseSound::state_), ObjectDirection::ToClient, new NetworkCallback<WorldSound>(this, &WorldSound::stateChanged));
    6161    }
    6262
  • code/trunk/src/orxonox/weaponsystem/WeaponMode.cc

    r6417 r7163  
    274274            return BLANKSTRING;
    275275    }
     276
     277    void WeaponMode::setDefaultSoundWithVolume(const std::string& soundPath, const float soundVolume){
     278        if (this->defSndWpnFire_) {
     279            this->defSndWpnFire_->setSource(soundPath);
     280            this->defSndWpnFire_->setVolume(soundVolume);
     281        }
     282    }
     283
    276284}
  • code/trunk/src/orxonox/weaponsystem/WeaponMode.h

    r6417 r7163  
    5555            void setDefaultSound(const std::string& soundPath);
    5656            const std::string& getDefaultSound();
    57 
     57            void setDefaultSoundWithVolume(const std::string& soundPath, const float soundVolume);
    5858
    5959            // Munition
  • code/trunk/src/orxonox/weaponsystem/WeaponSystem.cc

    r6417 r7163  
    214214        Weapon* weapon = 0;
    215215        while ((weapon = wPack->getWeapon(i++)))
    216             weapon->getWeaponSlot()->removeWeapon();
     216            if (weapon->getWeaponSlot())
     217                weapon->getWeaponSlot()->removeWeapon();
    217218
    218219        // Remove all added links from the WeaponSets
  • code/trunk/src/orxonox/worldentities/BigExplosion.cc

    r5929 r7163  
    101101        this->debrisEntity3_ = new MovableEntity(this);
    102102        this->debrisEntity4_ = new MovableEntity(this);
     103       
     104        this->debrisEntity1_->setSyncMode(0);
     105        this->debrisEntity2_->setSyncMode(0);
     106        this->debrisEntity3_->setSyncMode(0);
     107        this->debrisEntity4_->setSyncMode(0);
    103108
    104109        this->debris1_ = new Model(this);
     
    106111        this->debris3_ = new Model(this);
    107112        this->debris4_ = new Model(this);
     113       
     114        this->debris1_->setSyncMode(0);
     115        this->debris2_->setSyncMode(0);
     116        this->debris3_->setSyncMode(0);
     117        this->debris4_->setSyncMode(0);
    108118
    109119        this->explosion_ = new StaticEntity(this);
     120        this->explosion_->setSyncMode(0);
    110121
    111122        this->debrisSmoke1_ = new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/smoke7", this->LOD_);
     
    158169        effect->setSource("Orxonox/explosion2b");
    159170        effect->setLifetime(4.0f);
     171        effect->setSyncMode(0);
    160172
    161173        ParticleSpawner* effect2 = new ParticleSpawner(this->getCreator());
     
    163175        effect2->setSource("Orxonox/smoke6");
    164176        effect2->setLifetime(4.0f);
     177        effect2->setSyncMode(0);
    165178
    166179        this->explosion_->attach(effect);
     
    181194            MovableEntity* partEntity1 = new MovableEntity(this);
    182195            MovableEntity* partEntity2 = new MovableEntity(this);
     196           
     197            part1->setSyncMode(0);
     198            part2->setSyncMode(0);
     199            partEntity1->setSyncMode(0);
     200            partEntity2->setSyncMode(0);
    183201
    184202            partEntity1->setVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1))*rnd(10,100));
  • code/trunk/src/orxonox/worldentities/BigExplosion.h

    r5929 r7163  
    4545
    4646            virtual void tick(float dt);
    47             void registerVariables();
    4847
    4948            inline void setLOD(LODParticle::Value level)
     
    5352
    5453        private:
     54            void registerVariables();
    5555
    5656            void LODchanged();
  • code/trunk/src/orxonox/worldentities/CMakeLists.txt

    r6417 r7163  
    55  MobileEntity.cc
    66  ControllableEntity.cc
    7 
     7  Drone.cc
    88  BigExplosion.cc
    99  EffectContainer.cc
  • code/trunk/src/orxonox/worldentities/ControllableEntity.h

    r6417 r7163  
    4949            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    5050            virtual void tick(float dt);
    51             void registerVariables();
    5251            void setConfigValues();
    5352
     
    137136            inline float getMouseLookSpeed() const
    138137                { return this->mouseLookSpeed_; }
     138            inline CameraPosition* getCurrentCameraPosition()
     139                { return this->currentCameraPosition_; }
    139140
    140141            inline Controller* getXMLController() const
     
    162163                { this->hudtemplate_ = name; }
    163164
     165            Ogre::SceneNode* cameraPositionRootNode_;
     166
    164167        private:
     168            void registerVariables();
    165169            void setXMLController(Controller* controller);
    166170
     
    208212            bool bMouseLook_;
    209213            float mouseLookSpeed_;
    210             Ogre::SceneNode* cameraPositionRootNode_;
    211214            std::list<SmartPtr<CameraPosition> > cameraPositions_;
    212215            CameraPosition* currentCameraPosition_;
  • code/trunk/src/orxonox/worldentities/ExplosionChunk.h

    r5929 r7163  
    4444
    4545            virtual void tick(float dt);
    46             void registerVariables();
    4746
    4847            inline void setLOD(LODParticle::Value level)
     
    5251
    5352        private:
     53            void registerVariables();
    5454            void LODchanged();
    5555            void checkStop();
  • code/trunk/src/orxonox/worldentities/MobileEntity.cc

    r5781 r7163  
    4646        this->angularAcceleration_ = Vector3::ZERO;
    4747        this->angularVelocity_     = Vector3::ZERO;
    48 
    49         this->registerVariables();
    5048    }
    5149
  • code/trunk/src/orxonox/worldentities/MovableEntity.h

    r6417 r7163  
    4848            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    4949            virtual bool collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint);
    50             void registerVariables();
    5150
    5251            using WorldEntity::setPosition;
     
    7978
    8079        private:
     80            void registerVariables();
    8181            void clientConnected(unsigned int clientID);
    8282            void clientDisconnected(unsigned int clientID);
  • code/trunk/src/orxonox/worldentities/StaticEntity.h

    r5781 r7163  
    4242            virtual ~StaticEntity();
    4343
    44             void registerVariables();
    45 
    4644            using WorldEntity::setPosition;
    4745            using WorldEntity::setOrientation;
     
    5149
    5250        private:
     51            void registerVariables();
    5352            bool isCollisionTypeLegal(CollisionType type) const;
    5453
  • code/trunk/src/orxonox/worldentities/WorldEntity.cc

    r6524 r7163  
    8181        this->node_->setPosition(Vector3::ZERO);
    8282        this->node_->setOrientation(Quaternion::IDENTITY);
    83        
     83
    8484        // Activity and visibility memory.
    8585        this->bActiveMem_ = true;
     
    205205        registerVariable(this->parentID_,       VariableDirection::ToClient, new NetworkCallback<WorldEntity>(this, &WorldEntity::networkcallback_parentChanged));
    206206    }
    207    
     207
    208208    /**
    209209    @brief
     
    213213    {
    214214        SUPER(WorldEntity, changedActivity);
    215        
     215
    216216        for (std::set<WorldEntity*>::const_iterator it = this->getAttachedObjects().begin(); it != this->getAttachedObjects().end(); it++)
    217217        {
     
    227227        }
    228228    }
    229    
     229
    230230    /**
    231231    @brief
     
    235235    {
    236236        SUPER(WorldEntity, changedVisibility);
    237        
     237
    238238        for (std::set<WorldEntity*>::const_iterator it = this->getAttachedObjects().begin(); it != this->getAttachedObjects().end(); it++)
    239239        {
  • code/trunk/src/orxonox/worldentities/WorldEntity.h

    r6524 r7163  
    9494
    9595            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    96             void registerVariables();
    9796
    9897            inline const Ogre::SceneNode* getNode() const
     
    105104            static const Vector3 DOWN;
    106105            static const Vector3 UP;
    107            
     106
    108107            virtual void changedActivity(void);
    109108            virtual void changedVisibility(void);
     
    214213
    215214        private:
     215            void registerVariables();
     216           
    216217            inline void lookAt_xmlport(const Vector3& target)
    217218                { this->lookAt(target); }
     
    234235            std::set<WorldEntity*> children_;
    235236            bool bDeleteWithParent_;
    236            
     237
    237238            bool bActiveMem_;
    238239            bool bVisibleMem_;
  • code/trunk/src/orxonox/worldentities/pawns/CMakeLists.txt

    r5781 r7163  
    11ADD_SOURCE_FILES(ORXONOX_SRC_FILES
     2  FpsPlayer.cc
    23  Spectator.cc
    34  Pawn.cc
  • code/trunk/src/orxonox/worldentities/pawns/Pawn.cc

    r6864 r7163  
    5353    CreateFactory(Pawn);
    5454
    55     Pawn::Pawn(BaseObject* creator) : ControllableEntity(creator)
     55    Pawn::Pawn(BaseObject* creator)
     56        : ControllableEntity(creator)
     57        , RadarViewable(creator, static_cast<WorldEntity*>(this))
    5658    {
    5759        RegisterObject(Pawn);
     
    6466        this->maxHealth_ = 0;
    6567        this->initialHealth_ = 0;
     68        this->shieldHealth_ = 0;
     69        this->shieldAbsorption_ = 0.5;
    6670
    6771        this->lastHitOriginator_ = 0;
     
    7882        else
    7983            this->weaponSystem_ = 0;
    80        
    81         this->setCarrierName("Pawn");
    8284
    8385        this->setRadarObjectColour(ColourValue::Red);
     
    105107        XMLPortParam(Pawn, "maxhealth", setMaxHealth, getMaxHealth, xmlelement, mode).defaultValues(200);
    106108        XMLPortParam(Pawn, "initialhealth", setInitialHealth, getInitialHealth, xmlelement, mode).defaultValues(100);
     109
     110        XMLPortParam(Pawn, "shieldhealth", setShieldHealth, getShieldHealth, xmlelement, mode).defaultValues(0);
     111        XMLPortParam(Pawn, "shieldabsorption", setShieldAbsorption, getShieldAbsorption, xmlelement, mode).defaultValues(0);
     112
    107113        XMLPortParam(Pawn, "spawnparticlesource", setSpawnParticleSource, getSpawnParticleSource, xmlelement, mode);
    108114        XMLPortParam(Pawn, "spawnparticleduration", setSpawnParticleDuration, getSpawnParticleDuration, xmlelement, mode).defaultValues(3.0f);
     
    116122    void Pawn::registerVariables()
    117123    {
    118         registerVariable(this->bAlive_,        VariableDirection::ToClient);
    119         registerVariable(this->health_,        VariableDirection::ToClient);
    120         registerVariable(this->initialHealth_, VariableDirection::ToClient);
    121         registerVariable(this->bReload_,       VariableDirection::ToServer);
    122         registerVariable(this->aimPosition_,   Bidirectionality::ServerMaster, 0, true);
     124        registerVariable(this->bAlive_,           VariableDirection::ToClient);
     125        registerVariable(this->health_,           VariableDirection::ToClient);
     126        registerVariable(this->initialHealth_,    VariableDirection::ToClient);
     127        registerVariable(this->shieldHealth_,     VariableDirection::ToClient);
     128        registerVariable(this->shieldAbsorption_, VariableDirection::ToClient);
     129        registerVariable(this->bReload_,          VariableDirection::ToServer);
     130        registerVariable(this->aimPosition_,      VariableDirection::ToServer);  // For the moment this variable gets only transfered to the server
    123131    }
    124132
     
    162170        if (this->getGametype() && this->getGametype()->allowPawnDamage(this, originator))
    163171        {
    164             this->setHealth(this->health_ - damage);
     172            //share the dealt damage to the shield and the Pawn.
     173            float shielddamage = damage*this->shieldAbsorption_;
     174            float healthdamage = damage*(1-this->shieldAbsorption_);
     175
     176            // In case the shield can not take all the shield damage.
     177            if (shielddamage > this->getShieldHealth())
     178            {
     179                healthdamage += shielddamage-this->getShieldHealth();
     180                this->setShieldHealth(0);
     181            }
     182
     183            this->setHealth(this->health_ - healthdamage);
     184
     185            if (this->getShieldHealth() > 0)
     186            {
     187                this->setShieldHealth(this->shieldHealth_ - shielddamage);
     188            }
     189
    165190            this->lastHitOriginator_ = originator;
    166191
     
    336361    {
    337362        if (this->weaponSystem_)
     363        {
    338364            this->weaponSystem_->addWeaponPack(wPack);
     365            this->addedWeaponPack(wPack);
     366        }
    339367    }
    340368
     
    342370    {
    343371        if (this->weaponSystem_)
     372        {
    344373            if (!this->weaponSystem_->addWeaponPack(wPack))
    345374                wPack->destroy();
     375            else
     376                this->addedWeaponPack(wPack);
     377        }
    346378    }
    347379
  • code/trunk/src/orxonox/worldentities/pawns/Pawn.h

    r6711 r7163  
    5050            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    5151            virtual void tick(float dt);
    52             void registerVariables();
    5352
    5453            inline bool isAlive() const
     
    7372                { return this->initialHealth_; }
    7473
     74            inline void setShieldHealth(float shieldHealth)
     75            { this->shieldHealth_ = shieldHealth; }
     76            inline float getShieldHealth()
     77            { return this->shieldHealth_; }
     78
     79            inline void setShieldAbsorption(float shieldAbsorption)
     80            { this->shieldAbsorption_ = shieldAbsorption; }
     81            inline float getShieldAbsorption()
     82            { return this->shieldAbsorption_; }
     83
    7584            inline ControllableEntity* getLastHitOriginator() const
    7685                { return this->lastHitOriginator_; }
     
    91100            void addWeaponPackXML(WeaponPack * wPack);
    92101            WeaponPack * getWeaponPack(unsigned int index) const;
     102
     103            virtual void addedWeaponPack(WeaponPack* wPack) {}
    93104
    94105            inline const WorldEntity* getWorldEntity() const
     
    116127            Vector3 getAimPosition()
    117128                { return this->aimPosition_; }
    118                
     129
    119130            virtual const Vector3& getCarrierPosition(void)
    120131                { return this->getWorldPosition(); };
     
    141152            float maxHealth_;
    142153            float initialHealth_;
     154            float shieldHealth_;
     155            float shieldAbsorption_; // Has to be between 0 and 1
    143156
    144157            Pawn* lastHitOriginator_;
     
    152165
    153166        private:
     167            void registerVariables();
    154168            inline void setWeaponSystem(WeaponSystem* weaponsystem)
    155169                { this->weaponSystem_ = weaponsystem; }
  • code/trunk/src/orxonox/worldentities/pawns/SpaceShip.h

    r6711 r7163  
    4747            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    4848            virtual void tick(float dt);
    49             void registerVariables();
    5049            void setConfigValues();
    5150
     
    9998
    10099        private:
     100            void registerVariables();
    101101            virtual bool isCollisionTypeLegal(WorldEntity::CollisionType type) const;
    102102
    103         private:
    104103            void loadEngineTemplate();
    105104
  • code/trunk/src/orxonox/worldentities/pawns/Spectator.h

    r6417 r7163  
    4444
    4545            void setConfigValues();
    46             void registerVariables();
    4746            virtual void tick(float dt);
    4847
     
    6362
    6463        private:
     64            void registerVariables();
    6565            void changedGreeting();
    6666            void changedFlareVisibility();
Note: See TracChangeset for help on using the changeset viewer.