Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9348 for code/trunk/src


Ignore:
Timestamp:
Aug 30, 2012, 11:08:17 PM (12 years ago)
Author:
landauf
Message:

merged branch presentation2012merge back to trunk

Location:
code/trunk
Files:
7 deleted
109 edited
7 copied

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/BuildUnitsConfigGCC.cmake

    • Property svn:eol-style set to native
  • code/trunk/src/BuildUnitsConfigMSVC.cmake

    • Property svn:eol-style set to native
  • code/trunk/src/external/enet/VERSION

    • Property svn:eol-style set to native
  • code/trunk/src/external/tolua/README_ORXONOX

    • Property svn:eol-style set to native
  • code/trunk/src/libraries/core/Super.h

    r8866 r9348  
    280280        SUPER_NOARGS(classname, functionname)
    281281
    282     #define SUPER_clone(classname, functionname, ...) \
    283         SUPER_ARGS(classname, functionname, __VA_ARGS__)
    284 
    285282    #define SUPER_changedCarrier(classname, functionname, ...) \
    286283        SUPER_NOARGS(classname, functionname)
     
    398395                    inline void operator()( SUPER_CALL_ARGUMENTS##hasarguments(__VA_ARGS__) ) \
    399396                    { \
    400                         (dynamic_cast<T*>(object))->T:: functionname
     397                        (orxonox_cast<T*>(object))->T:: functionname
    401398
    402399        /*
     
    508505                inline void operator()( SUPER_CALL_ARGUMENTS##hasarguments(__VA_ARGS__) )
    509506                {
    510                     (dynamic_cast<T*>(object))->T:: functionname ( Call the function with it's arguments );
     507                    (orxonox_cast<T*>(object))->T:: functionname ( Call the function with it's arguments );
    511508                }
    512509
     
    566563        SUPER_FUNCTION_GLOBAL_DECLARATION_PART2;
    567564
    568         SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(11, clone, true, OrxonoxClass*& item)
    569             (item)
    570         SUPER_FUNCTION_GLOBAL_DECLARATION_PART2;
    571 
    572         SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(12, changedCarrier, false)
    573             ()
    574         SUPER_FUNCTION_GLOBAL_DECLARATION_PART2;
    575 
    576         SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(13, changedPickedUp, false)
     565        SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(11, changedCarrier, false)
     566            ()
     567        SUPER_FUNCTION_GLOBAL_DECLARATION_PART2;
     568
     569        SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(12, changedPickedUp, false)
    577570            ()
    578571        SUPER_FUNCTION_GLOBAL_DECLARATION_PART2;
     
    632625    SUPER_INTRUSIVE_DECLARATION(changedGametype);
    633626    SUPER_INTRUSIVE_DECLARATION(changedUsed);
    634     SUPER_INTRUSIVE_DECLARATION(clone);
    635627    SUPER_INTRUSIVE_DECLARATION(changedCarrier);
    636628    SUPER_INTRUSIVE_DECLARATION(changedPickedUp);
  • code/trunk/src/libraries/core/Template.cc

    r8858 r9348  
    149149        orxout(verbose, context::templates) << object->getLoaderIndentation() << " aplying Template \"" << this->getName() << "\"..." << endl;
    150150
     151        // check if the template is applied on an object of the right type
     152        Identifier* identifier = Identifier::getIdentifierByString(this->getXMLElement().Value());
     153        if (!object->getIdentifier()->isA(identifier))
     154            orxout(internal_warning, context::templates) << "Template was defined for " << identifier->getName() << " but the object is of type " << object->getIdentifier()->getName() << endl;
     155
    151156        Element temp = &const_cast<TiXmlElement&>(this->getXMLElement());
    152157
  • code/trunk/src/libraries/core/XMLPort.h

    r8858 r9348  
    197197        ClassIdentifier<classname>::getIdentifier()->addXMLPortParamContainer(paramname, containername); \
    198198    } \
    199     containername->port(dynamic_cast<BaseObject*>(this), object, xmlelement, mode)
     199    containername->port(orxonox_cast<BaseObject*>(this), object, xmlelement, mode)
    200200
    201201// --------------------
  • code/trunk/src/libraries/core/command/ConsoleCommand.cc

    r8858 r9348  
    594594        @param bPrintError If true, an error is printed if the command doesn't exist
    595595    */
    596     /* static */ const ConsoleCommand* ConsoleCommand::getCommand(const std::string& group, const std::string& name, bool bPrintError)
     596    /* static */ ConsoleCommand* ConsoleCommand::getCommand(const std::string& group, const std::string& name, bool bPrintError)
    597597    {
    598598        // find the group
     
    624624        @param bPrintError If true, an error is printed if the command doesn't exist
    625625    */
    626     /* static */ const ConsoleCommand* ConsoleCommand::getCommandLC(const std::string& group, const std::string& name, bool bPrintError)
     626    /* static */ ConsoleCommand* ConsoleCommand::getCommandLC(const std::string& group, const std::string& name, bool bPrintError)
    627627    {
    628628        std::string groupLC = getLowercase(group);
  • code/trunk/src/libraries/core/command/ConsoleCommand.h

    r8858 r9348  
    382382                public:
    383383                    /// Constructor: Creates a manipulator for a given ConsoleCommand.
    384                     ConsoleCommandManipulator(const ConsoleCommand* command) : command_(const_cast<ConsoleCommand*>(command)) {}
     384                    ConsoleCommandManipulator(ConsoleCommand* command) : command_(command) {}
    385385
    386386                    /// Changes the current function of the command. @param function The new function-pointer @param bForce If true, the new function-pointer is always assigned, even if the headers don't match
     
    619619
    620620            /// Returns a manipulator for this command.
    621             inline ConsoleCommandManipulator getManipulator() const
     621            inline ConsoleCommandManipulator getManipulator()
    622622                { return this; }
    623623
     
    667667
    668668            /// Returns a command (shortcut) with given name. @param name The name of the command shortcut @param bPrintError If true, an error is printed if the command doesn't exist
    669             static inline const ConsoleCommand* getCommand(const std::string& name, bool bPrintError = false)
     669            static inline ConsoleCommand* getCommand(const std::string& name, bool bPrintError = false)
    670670                { return ConsoleCommand::getCommand("", name, bPrintError); }
    671671            /// Returns a command (shortcut) with given name in lowercase. @param name The lowercase name of the command shortcut @param bPrintError If true, an error is printed if the command doesn't exist
    672             static inline const ConsoleCommand* getCommandLC(const std::string& name, bool bPrintError = false)
     672            static inline ConsoleCommand* getCommandLC(const std::string& name, bool bPrintError = false)
    673673                { return ConsoleCommand::getCommandLC("", name, bPrintError); }
    674674
    675             static const ConsoleCommand* getCommand(const std::string& group, const std::string& name, bool bPrintError = false);
    676             static const ConsoleCommand* getCommandLC(const std::string& group, const std::string& name, bool bPrintError = false);
     675            static ConsoleCommand* getCommand(const std::string& group, const std::string& name, bool bPrintError = false);
     676            static ConsoleCommand* getCommandLC(const std::string& group, const std::string& name, bool bPrintError = false);
    677677
    678678            static void destroyAll();
  • code/trunk/src/libraries/util/output/ConsoleWriter.cc

    • Property svn:eol-style set to native
  • code/trunk/src/modules/CMakeLists.txt

    r8706 r9348  
    3838ADD_SUBDIRECTORY(weapons)
    3939ADD_SUBDIRECTORY(docking)
     40ADD_SUBDIRECTORY(towerdefense)
  • code/trunk/src/modules/docking/DockingController.cc

    r8858 r9348  
    6060
    6161        float distance = (this->dock_->getWorldPosition() - entity->getPosition()).length();
    62         Vector2 coord = get2DViewdirection(     // I don't understand this too
     62        Vector2 coord = get2DViewcoordinates(     // I don't understand this too
    6363            entity->getPosition(),
    6464            entity->getOrientation() * WorldEntity::FRONT,
     
    7070        if (distance > 10)
    7171        {
    72             entity->rotateYaw(-1.0f * 0.8f * sgn(coord.x) * coord.x*coord.x);
    73             entity->rotatePitch(0.8f * sgn(coord.y) * coord.y*coord.y);
     72            entity->rotateYaw(-1.0f * 0.8f * clamp(coord.x * 10, -1.0f, 1.0f));
     73            entity->rotatePitch(0.8f * clamp(coord.y * 10, -1.0f, 1.0f));
    7474        }
    7575
  • code/trunk/src/modules/gametypes/OldRaceCheckPoint.cc

    • Property svn:eol-style set to native
    r9016 r9348  
    112112                const std::string& message =  "You have " + multi_cast<std::string>(this->bTimeLimit_)
    113113                            + " seconds to reach the check point " + multi_cast<std::string>(this->bCheckpointIndex_+1);
    114                 const_cast<GametypeInfo*>(gametype->getGametypeInfo())->sendAnnounceMessage(message);
     114                gametype->getGametypeInfo()->sendAnnounceMessage(message);
    115115                ChatManager::message(message);
    116116            }
  • code/trunk/src/modules/gametypes/OldRaceCheckPoint.h

    • Property svn:eol-style set to native
  • code/trunk/src/modules/gametypes/OldSpaceRace.cc

    • Property svn:eol-style set to native
    r9016 r9348  
    5858                        + "You didn't reach the check point " + multi_cast<std::string>(this->checkpointsReached_+1)
    5959                        + " before the time limit. You lose!";
    60             const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
     60            this->getGametypeInfo()->sendAnnounceMessage(message);
    6161            ChatManager::message(message);
    6262        }
     
    6868            const std::string& message = "You win!! You have reached the last check point after "+ multi_cast<std::string>(s)
    6969                        + "." + multi_cast<std::string>(ms) + " seconds.";
    70             const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
     70            this->getGametypeInfo()->sendAnnounceMessage(message);
    7171            ChatManager::message(message);
    7272/*
     
    8585
    8686        std::string message("The match has started! Reach the check points as quickly as possible!");
    87         const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
     87        this->getGametypeInfo()->sendAnnounceMessage(message);
    8888        ChatManager::message(message);
    8989    }
     
    9898                        + " reached after " + multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms)
    9999                        + " seconds.";
    100         const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
     100        this->getGametypeInfo()->sendAnnounceMessage(message);
    101101        ChatManager::message(message);
    102102    }
  • code/trunk/src/modules/gametypes/OldSpaceRace.h

    • Property svn:eol-style set to native
    r9016 r9348  
    5959
    6060            virtual void newCheckpointReached();
     61            virtual void addBots(unsigned int amount){} //<! overwrite function in order to bypass the addbots command.
     62                                                        //<! This is only a temporary solution. Better: create racingBots.
    6163
    6264            inline void setCheckpointsReached(int n)
  • code/trunk/src/modules/gametypes/RaceCheckPoint.cc

    r9263 r9348  
    9797            std::string message =  "You have " + multi_cast<std::string>(this->timeLimit_)
    9898                        + " seconds to reach the check point " + multi_cast<std::string>(this->checkpointIndex_ + 1);
    99             const_cast<GametypeInfo*>(this->getGametype()->getGametypeInfo())->sendAnnounceMessage(message);
     99            this->getGametype()->getGametypeInfo()->sendAnnounceMessage(message);
    100100            ChatManager::message(message);
    101101        }
  • code/trunk/src/modules/gametypes/SpaceRace.cc

    r9263 r9348  
    2323 *     Mauro Salomon
    2424 *   Co-authors:
    25  *      ...
     25 *      Celine Egger
    2626 *
    2727 */
     
    4848        this->cantMove_ = false;
    4949        this->bTimeIsUp_ = false;
     50        this->numberOfBots_ = 0; // quick fix: don't allow default-bots to enter the race
     51                                 // remove this line, if a raceBot has been created.
    5052    }
    5153
     
    7072        }
    7173
    72         const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
     74        this->getGametypeInfo()->sendAnnounceMessage(message);
    7375        ChatManager::message(message);
    7476    }
     
    9799
    98100            std::string message = "The match has started! Reach the check points as quickly as possible!";
    99             const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
     101            this->getGametypeInfo()->sendAnnounceMessage(message);
    100102            ChatManager::message(message);
    101103        }
     
    112114        const std::string& message = "Checkpoint " + multi_cast<std::string>(checkpoint->getCheckpointIndex() + 1)
    113115            + " reached after " + multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) + " seconds.";
    114         const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
     116        this->getGametypeInfo()->sendAnnounceMessage(message);
    115117        ChatManager::message(message);
    116118    }
  • code/trunk/src/modules/gametypes/SpaceRaceManager.cc

    • Property svn:eol-style set to native
    r9263 r9348  
    149149            }
    150150            else
    151                         {
     151            {
    152152                // adjust the radarvisibility
    153153                gametype->newCheckpointReached(newCheckpoint, player);
  • code/trunk/src/modules/gametypes/SpaceRaceManager.h

    • Property svn:eol-style set to native
  • code/trunk/src/modules/objects/triggers/CheckPoint.cc

    r7601 r9348  
    109109                if (bIsDestination_)
    110110                {
    111                     const_cast<GametypeInfo*>(gametype->getGametypeInfo())->sendAnnounceMessage("Congratulations - you have won the match!");
     111                    gametype->getGametypeInfo()->sendAnnounceMessage("Congratulations - you have won the match!");
    112112                    gametype->end();
    113113                }
     
    115115                if (!bIsFirst_ && !bIsDestination_)
    116116                {
    117                     const_cast<GametypeInfo*>(gametype->getGametypeInfo())->sendAnnounceMessage("Checkpoint reached");
     117                    gametype->getGametypeInfo()->sendAnnounceMessage("Checkpoint reached");
    118118                }
    119119            }
  • code/trunk/src/modules/overlays/OverlaysPrereqs.h

    r8706 r9348  
    9595    class PauseNotice;
    9696    class TeamBaseMatchScore;
    97     class UnderAttackHealthBar;
    9897
    9998    // stats
  • code/trunk/src/modules/overlays/hud/CMakeLists.txt

    r9016 r9348  
    1212  KillMessage.cc
    1313  DeathMessage.cc
    14   UnderAttackHealthBar.cc
    1514  TeamBaseMatchScore.cc
    1615  GametypeStaticMessage.cc
  • code/trunk/src/modules/overlays/hud/HUDBoostBar.cc

    • Property svn:eol-style set to native
  • code/trunk/src/modules/overlays/hud/HUDBoostBar.h

    • Property svn:eol-style set to native
  • code/trunk/src/modules/overlays/hud/HUDEnemyHealthBar.cc

    • Property svn:eol-style set to native
  • code/trunk/src/modules/overlays/hud/HUDEnemyHealthBar.h

    • Property svn:eol-style set to native
  • code/trunk/src/modules/overlays/hud/HUDNavigation.cc

    r9257 r9348  
    5555namespace orxonox
    5656{
    57 bool compareDistance ( std::pair<RadarViewable*, unsigned int > a, std::pair<RadarViewable*, unsigned int > b )
    58 {
    59     return a.second<b.second;
    60 
    61 }
    62 
    63 void HUDNavigation::setConfigValues()
    64 {
    65   SetConfigValue(markerLimit_, 3);
    66   SetConfigValue(showDistance, false);
    67 }
    68 
    69 CreateFactory ( HUDNavigation );
    70 
    71 HUDNavigation::HUDNavigation ( BaseObject* creator )
    72         : OrxonoxOverlay ( creator )
    73 {
    74     RegisterObject ( HUDNavigation );
    75     this->setConfigValues();
    76 
    77     // Set default values
    78     this->setFont ( "Monofur" );
    79     this->setTextSize ( 0.05f );
    80     this->setNavMarkerSize ( 0.05f );
    81     this->setDetectionLimit( 10000.0f );
    82 }
    83 
    84 HUDNavigation::~HUDNavigation()
    85 {
    86     if ( this->isInitialized() )
    87     {
    88         for ( ObjectMap::iterator it = activeObjectList_.begin(); it != activeObjectList_.end(); )
    89             removeObject ( ( it++ )->first );
    90 
    91     }
    92 
    93     sortedObjectList_.clear();
    94 }
    95 
    96 void HUDNavigation::XMLPort ( Element& xmlelement, XMLPort::Mode mode )
    97 {
    98     SUPER ( HUDNavigation, XMLPort, xmlelement, mode );
    99 
    100     XMLPortParam ( HUDNavigation, "font",          setFont,          getFont,          xmlelement, mode );
    101     XMLPortParam ( HUDNavigation, "textSize",      setTextSize,      getTextSize,      xmlelement, mode );
    102     XMLPortParam ( HUDNavigation, "navMarkerSize", setNavMarkerSize, getNavMarkerSize, xmlelement, mode );
    103     XMLPortParam ( HUDNavigation, "detectionLimit", setDetectionLimit, getDetectionLimit, xmlelement, mode );
    104 }
    105 
    106 void HUDNavigation::setFont ( const std::string& font )
    107 {
    108     const Ogre::ResourcePtr& fontPtr = Ogre::FontManager::getSingleton().getByName ( font );
    109     if ( fontPtr.isNull() )
    110     {
    111         orxout(internal_warning) << "HUDNavigation: Font '" << font << "' not found" << endl;
    112         return;
    113     }
    114     fontName_ = font;
    115     for ( ObjectMap::iterator it = activeObjectList_.begin(); it != activeObjectList_.end(); ++it )
    116     {
    117         if ( it->second.text_ != NULL )
    118             it->second.text_->setFontName ( fontName_ );
    119     }
    120 }
    121 
    122 const std::string& HUDNavigation::getFont() const
    123 {
    124     return fontName_;
    125 }
    126 
    127 void HUDNavigation::setTextSize ( float size )
    128 {
    129     if ( size <= 0.0f )
    130     {
    131         orxout(internal_warning) << "HUDNavigation: Negative font size not allowed" << endl;
    132         return;
    133     }
    134     textSize_ = size;
    135     for ( ObjectMap::iterator it = activeObjectList_.begin(); it!=activeObjectList_.end(); ++it )
    136     {
    137         if ( it->second.text_ )
    138             it->second.text_->setCharHeight ( size );
    139     }
    140 }
    141 
    142 float HUDNavigation::getTextSize() const
    143 {
    144     return textSize_;
    145 }
    146 
    147 float HUDNavigation::getArrowSizeX(int dist)
    148 {
    149     if (dist < 600)
    150         dist = 600;
    151     return this->getActualSize().x * 900 * navMarkerSize_ / dist;
    152 }
    153 
    154 float HUDNavigation::getArrowSizeY(int dist)
    155 {
    156     if (dist < 600)
    157         dist = 600;
    158     return this->getActualSize().y * 900 * navMarkerSize_ / dist;
    159 }
    160 
    161 void HUDNavigation::tick ( float dt )
    162 {
    163     SUPER ( HUDNavigation, tick, dt );
    164 
    165     Camera* cam = CameraManager::getInstance().getActiveCamera();
    166     if ( cam == NULL )
    167         return;
    168     const Matrix4& camTransform = cam->getOgreCamera()->getProjectionMatrix() * cam->getOgreCamera()->getViewMatrix();
    169 
    170 
    171     for ( sortedList::iterator listIt = sortedObjectList_.begin(); listIt != sortedObjectList_.end(); ++listIt )
    172     {
    173         listIt->second = ( int ) ( ( listIt->first->getRVWorldPosition() - HumanController::getLocalControllerSingleton()->getControllableEntity()->getWorldPosition() ).length() + 0.5f );
    174     }
    175 
    176     sortedObjectList_.sort ( compareDistance );
    177 
    178     unsigned int markerCount_ = 0;
    179     bool closeEnough_ = false; //only display objects that are close enough to be relevant for the player
    180 
    181 //         for (ObjectMap::iterator it = activeObjectList_.begin(); it != activeObjectList_.end(); ++it)
    182     for ( sortedList::iterator listIt = sortedObjectList_.begin(); listIt != sortedObjectList_.end(); ++markerCount_, ++listIt )
    183     {
    184         ObjectMap::iterator it = activeObjectList_.find ( listIt->first );
    185         closeEnough_ = listIt->second < detectionLimit_ ;
    186         // display radarviewables on HUD if the marker limit and max-distance is not exceeded
    187         if ( markerCount_ < markerLimit_ && (closeEnough_ ||  detectionLimit_ < 0) )
    188         {
    189 
    190 
    191             // Get Distance to HumanController and save it in the TextAreaOverlayElement.
    192             int dist = listIt->second;
    193             float textLength = 0.0f;
    194 
    195             //display distance next to cursor
    196             if (showDistance){
    197             it->second.text_->setCaption ( multi_cast<std::string> ( dist ) );
    198             textLength = multi_cast<std::string> ( dist ).size() * it->second.text_->getCharHeight() * 0.3f;
    199             }
    200 
    201             //display name next to cursor
    202             else{
    203             it->second.text_->setCaption(it->first->getRadarName());
    204             textLength = it->first->getRadarName().size() * it->second.text_->getCharHeight() * 0.3f;
    205             }
    206 
    207             // Transform to screen coordinates
    208             Vector3 pos = camTransform * it->first->getRVWorldPosition();
    209 
    210             bool outOfView = true;
    211             if ( pos.z > 1.0 )
     57    bool compareDistance(std::pair<RadarViewable*, unsigned int> a, std::pair<RadarViewable*, unsigned int> b)
     58    {
     59        return a.second < b.second;
     60    }
     61
     62    CreateFactory ( HUDNavigation );
     63
     64    HUDNavigation::HUDNavigation(BaseObject* creator) : OrxonoxOverlay(creator)
     65    {
     66        RegisterObject(HUDNavigation);
     67        this->setConfigValues();
     68
     69        // Set default values
     70        this->setFont("Monofur");
     71        this->setTextSize(0.05f);
     72        this->setNavMarkerSize(0.05f);
     73        this->setDetectionLimit(10000.0f);
     74    }
     75
     76    HUDNavigation::~HUDNavigation()
     77    {
     78        if (this->isInitialized())
     79        {
     80            for (std::map<RadarViewable*, ObjectInfo>::iterator it = this->activeObjectList_.begin(); it != this->activeObjectList_.end();)
     81                removeObject((it++)->first);
     82        }
     83        this->sortedObjectList_.clear();
     84    }
     85
     86    void HUDNavigation::setConfigValues()
     87    {
     88        SetConfigValue(markerLimit_, 3);
     89        SetConfigValue(showDistance_, false);
     90    }
     91
     92    void HUDNavigation::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     93    {
     94        SUPER(HUDNavigation, XMLPort, xmlelement, mode);
     95
     96        XMLPortParam(HUDNavigation, "font",           setFont,           getFont,           xmlelement, mode);
     97        XMLPortParam(HUDNavigation, "textSize",       setTextSize,       getTextSize,       xmlelement, mode);
     98        XMLPortParam(HUDNavigation, "navMarkerSize",  setNavMarkerSize,  getNavMarkerSize,  xmlelement, mode);
     99        XMLPortParam(HUDNavigation, "detectionLimit", setDetectionLimit, getDetectionLimit, xmlelement, mode);
     100    }
     101
     102    void HUDNavigation::setFont(const std::string& font)
     103    {
     104        const Ogre::ResourcePtr& fontPtr = Ogre::FontManager::getSingleton().getByName(font);
     105        if (fontPtr.isNull())
     106        {
     107            orxout(internal_warning) << "HUDNavigation: Font '" << font << "' not found" << endl;
     108            return;
     109        }
     110        this->fontName_ = font;
     111        for (std::map<RadarViewable*, ObjectInfo>::iterator it = this->activeObjectList_.begin(); it != this->activeObjectList_.end(); ++it)
     112        {
     113            if (it->second.text_ != NULL)
     114                it->second.text_->setFontName(this->fontName_);
     115        }
     116    }
     117
     118    const std::string& HUDNavigation::getFont() const
     119    {
     120        return this->fontName_;
     121    }
     122
     123    void HUDNavigation::setTextSize(float size)
     124    {
     125        if (size <= 0.0f)
     126        {
     127            orxout(internal_warning) << "HUDNavigation: Negative font size not allowed" << endl;
     128            return;
     129        }
     130        this->textSize_ = size;
     131        for (std::map<RadarViewable*, ObjectInfo>::iterator it = this->activeObjectList_.begin(); it!=this->activeObjectList_.end(); ++it)
     132        {
     133            if (it->second.text_)
     134                it->second.text_->setCharHeight(size);
     135        }
     136    }
     137
     138    float HUDNavigation::getTextSize() const
     139    {
     140        return this->textSize_;
     141    }
     142
     143    float HUDNavigation::getArrowSizeX(int dist) const
     144    {
     145        if (dist < 600)
     146            dist = 600;
     147        return this->getActualSize().x * 900 * this->navMarkerSize_ / dist;
     148    }
     149
     150    float HUDNavigation::getArrowSizeY(int dist) const
     151    {
     152        if (dist < 600)
     153            dist = 600;
     154        return this->getActualSize().y * 900 * this->navMarkerSize_ / dist;
     155    }
     156
     157    void HUDNavigation::tick(float dt)
     158    {
     159        SUPER(HUDNavigation, tick, dt);
     160
     161        Camera* cam = CameraManager::getInstance().getActiveCamera();
     162        if (cam == NULL)
     163            return;
     164        const Matrix4& camTransform = cam->getOgreCamera()->getProjectionMatrix() * cam->getOgreCamera()->getViewMatrix();
     165
     166
     167        for (std::list<std::pair<RadarViewable*, unsigned int> >::iterator listIt = this->sortedObjectList_.begin(); listIt != this->sortedObjectList_.end(); ++listIt)
     168            listIt->second = (int)((listIt->first->getRVWorldPosition() - HumanController::getLocalControllerSingleton()->getControllableEntity()->getWorldPosition()).length() + 0.5f);
     169
     170        this->sortedObjectList_.sort(compareDistance);
     171
     172        unsigned int markerCount = 0;
     173        bool closeEnough = false; // only display objects that are close enough to be relevant for the player
     174
     175        for (std::list<std::pair<RadarViewable*, unsigned int> >::iterator listIt = this->sortedObjectList_.begin(); listIt != this->sortedObjectList_.end(); ++markerCount, ++listIt)
     176        {
     177            std::map<RadarViewable*, ObjectInfo>::iterator it = this->activeObjectList_.find(listIt->first);
     178            closeEnough = listIt->second < this->detectionLimit_;
     179            // display radarviewables on HUD if the marker limit and max-distance is not exceeded
     180            if (markerCount < this->markerLimit_ && (closeEnough ||  this->detectionLimit_ < 0))
    212181            {
    213                 // z > 1.0 means that the object is behind the camera
    214                 outOfView = true;
    215                 // we have to switch all coordinates (if you don't know why,
    216                 // try linear algebra lectures, because I can't explain..)
    217                 pos.x = -pos.x;
    218                 pos.y = -pos.y;
    219             }
    220             else
    221                 outOfView = pos.x < -1.0 || pos.x > 1.0 || pos.y < -1.0 || pos.y > 1.0;
    222 
    223             if ( outOfView )
    224             {
    225                 // Object is not in view
    226 
    227                 // Change material only if outOfView changed
    228                 if ( !it->second.wasOutOfView_ )
     182                // Get Distance to HumanController and save it in the TextAreaOverlayElement.
     183                int dist = listIt->second;
     184                float textLength = 0.0f;
     185
     186                if (this->showDistance_)
    229187                {
    230                     it->second.panel_->setMaterialName( TextureGenerator::getMaterialName( "arrows.png", it->first->getRadarObjectColour()) );
    231                     it->second.wasOutOfView_ = true;
     188                    //display distance next to cursor
     189                    it->second.text_->setCaption(multi_cast<std::string>(dist));
     190                    textLength = multi_cast<std::string>(dist).size() * it->second.text_->getCharHeight() * 0.3f;
    232191                }
    233 
    234                 //float xDistScale = this->getActualSize().x * 1000.0f * navMarkerSize_ / dist;
    235                 //float yDistScale = this->getActualSize().y * 1000.0f * navMarkerSize_ / dist;
    236 
    237                 // Adjust Arrowsize according to distance
    238                 it->second.panel_->setDimensions(getArrowSizeX(dist),getArrowSizeY(dist));
    239 
    240                 // Switch between top, bottom, left and right position of the arrow at the screen border
    241                 if ( pos.x < pos.y )
     192                else
    242193                {
    243                     if ( pos.y > -pos.x )
     194                    //display name next to cursor
     195                    it->second.text_->setCaption(it->first->getRadarName());
     196                    textLength = it->first->getRadarName().size() * it->second.text_->getCharHeight() * 0.3f;
     197                }
     198
     199                // Transform to screen coordinates
     200                Vector3 pos = camTransform * it->first->getRVWorldPosition();
     201
     202                bool outOfView = true;
     203                if (pos.z > 1.0)
     204                {
     205                    // z > 1.0 means that the object is behind the camera
     206                    outOfView = true;
     207                    // we have to switch all coordinates (if you don't know why,
     208                    // try linear algebra lectures, because I can't explain..)
     209                    pos.x = -pos.x;
     210                    pos.y = -pos.y;
     211                }
     212                else
     213                    outOfView = pos.x < -1.0 || pos.x > 1.0 || pos.y < -1.0 || pos.y > 1.0;
     214
     215                if (outOfView)
     216                {
     217                    // Object is not in view
     218
     219                    // Change material only if outOfView changed
     220                    if (!it->second.wasOutOfView_)
    244221                    {
    245                         // Top
    246                         float position = pos.x / pos.y + 1.0f;
    247                         it->second.panel_->setPosition ( ( position - it->second.panel_->getWidth() ) * 0.5f, 0.0f );
    248                         it->second.panel_->setUV ( 0.5f, 0.0f, 1.0f, 0.5f );
    249                         it->second.text_->setLeft ( ( position - textLength ) * 0.5f );
    250                         it->second.text_->setTop ( it->second.panel_->getHeight() );
     222                        it->second.panel_->setMaterialName(TextureGenerator::getMaterialName("arrows.png", it->first->getRadarObjectColour()));
     223                        it->second.wasOutOfView_ = true;
     224                    }
     225
     226                    //float xDistScale = this->getActualSize().x * 1000.0f * this->navMarkerSize_ / dist;
     227                    //float yDistScale = this->getActualSize().y * 1000.0f * this->navMarkerSize_ / dist;
     228
     229                    // Adjust Arrowsize according to distance
     230                    it->second.panel_->setDimensions(getArrowSizeX(dist), getArrowSizeY(dist));
     231
     232                    // Switch between top, bottom, left and right position of the arrow at the screen border
     233                    if (pos.x < pos.y)
     234                    {
     235                        if (pos.y > -pos.x)
     236                        {
     237                            // Top
     238                            float position = pos.x / pos.y + 1.0f;
     239                            it->second.panel_->setPosition((position - it->second.panel_->getWidth()) * 0.5f, 0.0f);
     240                            it->second.panel_->setUV(0.5f, 0.0f, 1.0f, 0.5f);
     241                            it->second.text_->setLeft((position - textLength) * 0.5f);
     242                            it->second.text_->setTop(it->second.panel_->getHeight());
     243                        }
     244                        else
     245                        {
     246                            // Left
     247                            float position = pos.y / pos.x + 1.0f;
     248                            it->second.panel_->setPosition(0.0f, (position - it->second.panel_->getWidth()) * 0.5f);
     249                            it->second.panel_->setUV(0.0f, 0.0f, 0.5f, 0.5f);
     250                            it->second.text_->setLeft(it->second.panel_->getWidth() + 0.01f);
     251                            it->second.text_->setTop((position - it->second.text_->getCharHeight()) * 0.5f);
     252                        }
    251253                    }
    252254                    else
    253255                    {
    254                         // Left
    255                         float position = pos.y / pos.x + 1.0f;
    256                         it->second.panel_->setPosition ( 0.0f, ( position - it->second.panel_->getWidth() ) * 0.5f );
    257                         it->second.panel_->setUV ( 0.0f, 0.0f, 0.5f, 0.5f );
    258                         it->second.text_->setLeft ( it->second.panel_->getWidth() + 0.01f );
    259                         it->second.text_->setTop ( ( position - it->second.text_->getCharHeight() ) * 0.5f );
     256                        if (pos.y < -pos.x)
     257                        {
     258                            // Bottom
     259                            float position = -pos.x / pos.y + 1.0f;
     260                            it->second.panel_->setPosition((position - it->second.panel_->getWidth()) * 0.5f, 1.0f - it->second.panel_->getHeight());
     261                            it->second.panel_->setUV(0.0f, 0.5f, 0.5f, 1.0f );
     262                            it->second.text_->setLeft((position - textLength) * 0.5f);
     263                            it->second.text_->setTop(1.0f - it->second.panel_->getHeight() - it->second.text_->getCharHeight());
     264                        }
     265                        else
     266                        {
     267                            // Right
     268                            float position = -pos.y / pos.x + 1.0f;
     269                            it->second.panel_->setPosition(1.0f - it->second.panel_->getWidth(), (position - it->second.panel_->getHeight()) * 0.5f);
     270                            it->second.panel_->setUV(0.5f, 0.5f, 1.0f, 1.0f);
     271                            it->second.text_->setLeft(1.0f - it->second.panel_->getWidth() - textLength - 0.01f);
     272                            it->second.text_->setTop((position - it->second.text_->getCharHeight()) * 0.5f);
     273                        }
    260274                    }
    261275                }
    262 
    263276                else
    264277                {
    265 
    266                     if ( pos.y < -pos.x )
     278                    // Object is in view
     279
     280                    // Change material only if outOfView changed
     281                    if (it->second.wasOutOfView_)
    267282                    {
    268                         // Bottom
    269                         float position = -pos.x / pos.y + 1.0f;
    270                         it->second.panel_->setPosition ( ( position - it->second.panel_->getWidth() ) * 0.5f, 1.0f - it->second.panel_->getHeight() );
    271                         it->second.panel_->setUV ( 0.0f, 0.5f, 0.5f, 1.0f );
    272                         it->second.text_->setLeft ( ( position - textLength ) * 0.5f );
    273                         it->second.text_->setTop ( 1.0f - it->second.panel_->getHeight() - it->second.text_->getCharHeight() );
     283                        //it->second.panel_->setMaterialName("Orxonox/NavTDC");
     284                        it->second.panel_->setMaterialName(TextureGenerator::getMaterialName("tdc.png", it->first->getRadarObjectColour()));
     285                        it->second.panel_->setDimensions(this->navMarkerSize_ * this->getActualSize().x, this->navMarkerSize_ * this->getActualSize().y);
     286                        it->second.wasOutOfView_ = false;
    274287                    }
    275                     else
    276                     {
    277                         // Right
    278                         float position = -pos.y / pos.x + 1.0f;
    279                         it->second.panel_->setPosition ( 1.0f - it->second.panel_->getWidth(), ( position - it->second.panel_->getHeight() ) * 0.5f );
    280                         it->second.panel_->setUV ( 0.5f, 0.5f, 1.0f, 1.0f );
    281                         it->second.text_->setLeft ( 1.0f - it->second.panel_->getWidth() - textLength - 0.01f );
    282                         it->second.text_->setTop ( ( position - it->second.text_->getCharHeight() ) * 0.5f );
    283                     }
     288
     289                    // Position marker
     290                    it->second.panel_->setUV(0.0f, 0.0f, 1.0f, 1.0f);
     291                    it->second.panel_->setLeft((pos.x + 1.0f - it->second.panel_->getWidth()) * 0.5f);
     292                    it->second.panel_->setTop((-pos.y + 1.0f - it->second.panel_->getHeight()) * 0.5f);
     293
     294                    // Position text
     295                    it->second.text_->setLeft((pos.x + 1.0f + it->second.panel_->getWidth()) * 0.5f);
     296                    it->second.text_->setTop((-pos.y + 1.0f + it->second.panel_->getHeight()) * 0.5f);
    284297                }
     298
     299                // Make sure the overlays are shown
     300                it->second.panel_->show();
     301                it->second.text_->show();
    285302            }
    286             else
     303            else // do not display on HUD
    287304            {
    288                 // Object is in view
    289 
    290                 // Change material only if outOfView changed
    291                 if ( it->second.wasOutOfView_ )
    292                 {
    293                   //it->second.panel_->setMaterialName ( "Orxonox/NavTDC" );
    294                     it->second.panel_->setMaterialName( TextureGenerator::getMaterialName( "tdc.png", it->first->getRadarObjectColour()) );
    295                     it->second.panel_->setDimensions ( navMarkerSize_ * this->getActualSize().x, navMarkerSize_ * this->getActualSize().y );
    296                     it->second.wasOutOfView_ = false;
    297                 }
    298 
    299                 // Position marker
    300                 it->second.panel_->setUV ( 0.0f, 0.0f, 1.0f, 1.0f );
    301                 it->second.panel_->setLeft ( ( pos.x + 1.0f - it->second.panel_->getWidth() ) * 0.5f );
    302                 it->second.panel_->setTop ( ( -pos.y + 1.0f - it->second.panel_->getHeight() ) * 0.5f );
    303 
    304                 // Position text
    305                 it->second.text_->setLeft ( ( pos.x + 1.0f + it->second.panel_->getWidth() ) * 0.5f );
    306                 it->second.text_->setTop ( ( -pos.y + 1.0f + it->second.panel_->getHeight() ) * 0.5f );
     305                it->second.panel_->hide();
     306                it->second.text_->hide();
    307307            }
    308 
    309             // Make sure the overlays are shown
    310             it->second.panel_->show();
    311             it->second.text_->show();
    312         }
    313         else // do not display on HUD
    314         {
    315             it->second.panel_->hide();
    316             it->second.text_->hide();
    317         }
    318 
     308        }
     309    }
     310
     311    /** Overridden method of OrxonoxOverlay.
     312    @details
     313        Usually the entire overlay scales with scale().
     314        Here we obviously have to adjust this.
     315    */
     316    void HUDNavigation::sizeChanged()
     317    {
     318        // Use size to compensate for aspect ratio if enabled.
     319        float xScale = this->getActualSize().x;
     320        float yScale = this->getActualSize().y;
     321
     322        for (std::map<RadarViewable*, ObjectInfo>::iterator it = this->activeObjectList_.begin(); it != this->activeObjectList_.end(); ++it)
     323        {
     324            if (it->second.panel_ != NULL)
     325                it->second.panel_->setDimensions(this->navMarkerSize_ * xScale, this->navMarkerSize_ * yScale);
     326            if (it->second.text_ != NULL)
     327                it->second.text_->setCharHeight(it->second.text_->getCharHeight() * yScale);
     328        }
     329    }
     330
     331    void HUDNavigation::addObject(RadarViewable* object)
     332    {
     333        if (showObject(object) == false)
     334            return;
     335
     336        if (this->activeObjectList_.size() >= this->markerLimit_)
     337            if (object == NULL)
     338                return;
     339
     340        // Object hasn't been added yet (we know that)
     341        assert(this->activeObjectList_.find(object) == this->activeObjectList_.end());
     342
     343        // Scales used for dimensions and text size
     344        float xScale = this->getActualSize().x;
     345        float yScale = this->getActualSize().y;
     346
     347        // Create everything needed to display the object on the radar and add it to the map
     348
     349        // Create arrow/marker
     350        Ogre::PanelOverlayElement* panel = static_cast<Ogre::PanelOverlayElement*>( Ogre::OverlayManager::getSingleton()
     351                                           .createOverlayElement("Panel", "HUDNavigation_navMarker_" + getUniqueNumberString()));
     352        //panel->setMaterialName("Orxonox/NavTDC");
     353        panel->setMaterialName(TextureGenerator::getMaterialName("tdc.png", object->getRadarObjectColour()));
     354        panel->setDimensions(this->navMarkerSize_ * xScale, this->navMarkerSize_ * yScale);
     355        //panel->setColour(object->getRadarObjectColour());
     356
     357        Ogre::TextAreaOverlayElement* text = static_cast<Ogre::TextAreaOverlayElement*>( Ogre::OverlayManager::getSingleton()
     358                                             .createOverlayElement("TextArea", "HUDNavigation_navText_" + getUniqueNumberString()));
     359        text->setFontName(this->fontName_);
     360        text->setCharHeight(text->getCharHeight() * yScale);
     361        text->setColour(object->getRadarObjectColour());
     362
     363        panel->hide();
     364        text->hide();
     365
     366        ObjectInfo tempStruct = {panel, text, false /*, TODO: initialize wasOutOfView_ */};
     367        this->activeObjectList_[object] = tempStruct;
     368
     369        this->background_->addChild(panel);
     370        this->background_->addChild(text);
     371
     372        this->sortedObjectList_.push_front(std::make_pair(object, (unsigned int)0));
     373    }
     374
     375    void HUDNavigation::removeObject(RadarViewable* viewable)
     376    {
     377        std::map<RadarViewable*, ObjectInfo>::iterator it = this->activeObjectList_.find(viewable);
     378
     379        if (this->activeObjectList_.find(viewable) != this->activeObjectList_.end())
     380        {
     381            // Detach overlays
     382            this->background_->removeChild(it->second.panel_->getName());
     383            this->background_->removeChild(it->second.text_->getName());
     384            // Properly destroy the overlay elements (do not use delete!)
     385            Ogre::OverlayManager::getSingleton().destroyOverlayElement(it->second.panel_);
     386            Ogre::OverlayManager::getSingleton().destroyOverlayElement(it->second.text_);
     387            // Remove from the list
     388            this->activeObjectList_.erase(viewable);
     389        }
     390
     391        for (std::list<std::pair<RadarViewable*, unsigned int> >::iterator listIt = this->sortedObjectList_.begin(); listIt != this->sortedObjectList_.end(); ++listIt)
     392        {
     393            if ((listIt->first) == viewable)
     394            {
     395                this->sortedObjectList_.erase(listIt);
     396                break;
     397            }
     398        }
     399    }
     400
     401    void HUDNavigation::objectChanged(RadarViewable* viewable)
     402    {
     403        // TODO: niceification neccessary ;)
     404        removeObject(viewable);
     405        addObject(viewable);
     406    }
     407
     408    bool HUDNavigation::showObject(RadarViewable* rv)
     409    {
     410        if (rv == orxonox_cast<RadarViewable*>(this->getOwner()))
     411            return false;
     412        assert(rv->getWorldEntity());
     413        if (rv->getWorldEntity()->isVisible() == false || rv->getRadarVisibility() == false)
     414            return false;
     415        return true;
     416    }
     417
     418    void HUDNavigation::changedOwner()
     419    {
     420        const std::set<RadarViewable*>& respawnObjects = this->getOwner()->getScene()->getRadar()->getRadarObjects();
     421        for (std::set<RadarViewable*>::const_iterator it = respawnObjects.begin(); it != respawnObjects.end(); ++it)
     422        {
     423            if (!(*it)->isHumanShip_)
     424                this->addObject(*it);
     425        }
    319426    }
    320427}
    321 
    322 
    323 /** Overridden method of OrxonoxOverlay.
    324 @details
    325     Usually the entire overlay scales with scale().
    326     Here we obviously have to adjust this.
    327 */
    328 void HUDNavigation::sizeChanged()
    329 {
    330     // Use size to compensate for aspect ratio if enabled.
    331     float xScale = this->getActualSize().x;
    332     float yScale = this->getActualSize().y;
    333 
    334     for ( ObjectMap::iterator it = activeObjectList_.begin(); it!=activeObjectList_.end(); ++it )
    335     {
    336         if ( it->second.panel_ != NULL )
    337             it->second.panel_->setDimensions ( navMarkerSize_ * xScale, navMarkerSize_ * yScale );
    338         if ( it->second.text_ != NULL )
    339             it->second.text_->setCharHeight ( it->second.text_->getCharHeight() * yScale );
    340     }
    341 }
    342 
    343 void HUDNavigation::addObject ( RadarViewable* object )
    344 {
    345     if( showObject(object)==false )
    346         return;
    347 
    348     if ( activeObjectList_.size() >= markerLimit_ )
    349         if ( object == NULL )
    350             return;
    351 
    352     // Object hasn't been added yet (we know that)
    353     assert ( this->activeObjectList_.find ( object ) == this->activeObjectList_.end() );
    354 
    355     // Scales used for dimensions and text size
    356     float xScale = this->getActualSize().x;
    357     float yScale = this->getActualSize().y;
    358 
    359     // Create everything needed to display the object on the radar and add it to the map
    360 
    361     // Create arrow/marker
    362     Ogre::PanelOverlayElement* panel = static_cast<Ogre::PanelOverlayElement*> ( Ogre::OverlayManager::getSingleton()
    363                                        .createOverlayElement ( "Panel", "HUDNavigation_navMarker_" + getUniqueNumberString() ) );
    364 //     panel->setMaterialName ( "Orxonox/NavTDC" );
    365     panel->setMaterialName( TextureGenerator::getMaterialName( "tdc.png", object->getRadarObjectColour()) );
    366     panel->setDimensions ( navMarkerSize_ * xScale, navMarkerSize_ * yScale );
    367 //     panel->setColour( object->getRadarObjectColour() );
    368 
    369     Ogre::TextAreaOverlayElement* text = static_cast<Ogre::TextAreaOverlayElement*> ( Ogre::OverlayManager::getSingleton()
    370                                          .createOverlayElement ( "TextArea", "HUDNavigation_navText_" + getUniqueNumberString() ) );
    371     text->setFontName ( this->fontName_ );
    372     text->setCharHeight ( text->getCharHeight() * yScale );
    373     text->setColour( object->getRadarObjectColour() );
    374 
    375     panel->hide();
    376     text->hide();
    377 
    378     ObjectInfo tempStruct = {panel, text, false /*, TODO: initialize wasOutOfView_ */};
    379     activeObjectList_[object] = tempStruct;
    380 
    381     this->background_->addChild ( panel );
    382     this->background_->addChild ( text );
    383 
    384     sortedObjectList_.push_front ( std::make_pair ( object, ( unsigned int ) 0 ) );
    385 
    386 
    387 }
    388 
    389 void HUDNavigation::removeObject ( RadarViewable* viewable )
    390 {
    391     ObjectMap::iterator it = activeObjectList_.find ( viewable );
    392 
    393     if ( activeObjectList_.find ( viewable ) != activeObjectList_.end() )
    394     {
    395         // Detach overlays
    396         this->background_->removeChild ( it->second.panel_->getName() );
    397         this->background_->removeChild ( it->second.text_->getName() );
    398         // Properly destroy the overlay elements (do not use delete!)
    399         Ogre::OverlayManager::getSingleton().destroyOverlayElement ( it->second.panel_ );
    400         Ogre::OverlayManager::getSingleton().destroyOverlayElement ( it->second.text_ );
    401         // Remove from the list
    402         activeObjectList_.erase ( viewable );
    403 
    404 
    405     }
    406 
    407     for ( sortedList::iterator listIt = sortedObjectList_.begin(); listIt != sortedObjectList_.end(); ++listIt )
    408     {
    409         if ( (listIt->first) == viewable )
    410         {
    411             sortedObjectList_.erase ( listIt );
    412             break;
    413         }
    414 
    415     }
    416 
    417 }
    418 
    419 void HUDNavigation::objectChanged(RadarViewable* viewable)
    420 {
    421     // TODO: niceification neccessary ;)
    422     removeObject(viewable);
    423     addObject(viewable);
    424 }
    425 
    426 
    427 bool HUDNavigation::showObject(RadarViewable* rv)
    428 {
    429     if ( rv == dynamic_cast<RadarViewable*> ( this->getOwner() ) )
    430         return false;
    431     assert( rv->getWorldEntity() );
    432     if ( rv->getWorldEntity()->isVisible()==false || rv->getRadarVisibility()==false )
    433         return false;
    434     return true;
    435 }
    436 
    437 void HUDNavigation::changedOwner()
    438 {
    439 
    440     const std::set<RadarViewable*>& respawnObjects = this->getOwner()->getScene()->getRadar()->getRadarObjects();
    441     for ( std::set<RadarViewable*>::const_iterator it = respawnObjects.begin(); it != respawnObjects.end(); ++it )
    442     {
    443         if ( ! ( *it )->isHumanShip_ )
    444             this->addObject ( *it );
    445     }
    446 }
    447 
    448 }
  • code/trunk/src/modules/overlays/hud/HUDNavigation.h

    r9016 r9348  
    3636#include <string>
    3737
    38 
    3938#include "util/OgreForwardRefs.h"
    4039#include "tools/interfaces/Tickable.h"
     
    4443namespace orxonox
    4544{
    46 class _OverlaysExport HUDNavigation : public OrxonoxOverlay, public Tickable, public RadarListener
    47 {
    48 public:
    49     HUDNavigation ( BaseObject* creator );
    50     virtual ~HUDNavigation();
     45    class _OverlaysExport HUDNavigation : public OrxonoxOverlay, public Tickable, public RadarListener
     46    {
     47        public:
     48            HUDNavigation(BaseObject* creator);
     49            virtual ~HUDNavigation();
    5150
    52     void setConfigValues();
     51            void setConfigValues();
    5352
    54     virtual void XMLPort ( Element& xmlelement, XMLPort::Mode mode );
    55     virtual void tick ( float dt );
     53            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
     54            virtual void tick(float dt);
    5655
    57     // RadarListener interface
    58     virtual void addObject ( RadarViewable* object );
    59     virtual void removeObject ( RadarViewable* viewable );
    60     virtual void objectChanged ( RadarViewable* viewable );
     56            // RadarListener interface
     57            virtual void addObject(RadarViewable* object);
     58            virtual void removeObject(RadarViewable* viewable);
     59            virtual void objectChanged(RadarViewable* viewable);
    6160
    62     virtual void changedOwner();
    63     virtual void sizeChanged();
    64     virtual void angleChanged() { }
    65     virtual void positionChanged() { }
    66     virtual void radarTick ( float dt ) {}
     61            virtual void changedOwner();
     62            virtual void sizeChanged();
     63            virtual void angleChanged() { }
     64            virtual void positionChanged() { }
     65            virtual void radarTick(float dt) {}
    6766
    68     inline float getRadarSensitivity() const
    69     { return 1.0f; }
     67            inline float getRadarSensitivity() const
     68                { return 1.0f; }
    7069
    71     unsigned int getMarkerLimit() { return this->markerLimit_; }
     70            inline unsigned int getMarkerLimit() const
     71                { return this->markerLimit_; }
    7272
    73 private:
    74     struct ObjectInfo
    75     {
    76         Ogre::PanelOverlayElement* panel_;
    77         Ogre::TextAreaOverlayElement* text_;
    78         bool outOfView_;
    79         bool wasOutOfView_;
     73        private:
     74            struct ObjectInfo
     75            {
     76                Ogre::PanelOverlayElement* panel_;
     77                Ogre::TextAreaOverlayElement* text_;
     78                bool outOfView_;
     79                bool wasOutOfView_;
     80            };
    8081
     82            bool showObject(RadarViewable* rv);
     83
     84            // XMLPort accessors
     85            inline void setNavMarkerSize(float size)
     86            {
     87                navMarkerSize_ = size;
     88                this->sizeChanged();
     89            }
     90            inline float getNavMarkerSize() const
     91                { return navMarkerSize_; }
     92            inline void setDetectionLimit(float limit)
     93                { this->detectionLimit_ = limit; }
     94            inline float getDetectionLimit() const
     95                { return this->detectionLimit_; }
     96
     97            void setTextSize(float size);
     98            float getTextSize() const;
     99
     100            void setFont(const std::string& font);
     101            const std::string& getFont() const;
     102
     103            float getArrowSizeX(int dist) const;
     104            float getArrowSizeY(int dist) const;
     105
     106            std::map<RadarViewable*, ObjectInfo> activeObjectList_;
     107            std::list<std::pair<RadarViewable*, unsigned int> > sortedObjectList_;
     108
     109            float navMarkerSize_;
     110            std::string fontName_;
     111            float textSize_;
     112            bool showDistance_;
     113
     114            unsigned int markerLimit_;
     115            float detectionLimit_; //!< Objects that are more far away than detectionLimit_ are not displayed on the HUD. 10000.0f is the default value.
    81116    };
    82 
    83     bool showObject( RadarViewable* rv );
    84 
    85     // XMLPort accessors
    86     void setNavMarkerSize ( float size )
    87         { navMarkerSize_ = size; this->sizeChanged(); }
    88     float getNavMarkerSize() const
    89         { return navMarkerSize_; }
    90     void setDetectionLimit( float limit )
    91         { this->detectionLimit_ = limit; }
    92     float getDetectionLimit() const
    93         { return this->detectionLimit_; }
    94 
    95     void setTextSize ( float size );
    96     float getTextSize() const;
    97 
    98     void setFont ( const std::string& font );
    99     const std::string& getFont() const;
    100 
    101     typedef std::map<RadarViewable*, ObjectInfo > ObjectMap;
    102     ObjectMap activeObjectList_;
    103 
    104     typedef std::list < std::pair<RadarViewable*, unsigned int > > sortedList;
    105     sortedList sortedObjectList_;
    106 
    107     float getArrowSizeX(int dist);   
    108     float getArrowSizeY(int dist);
    109 
    110     float navMarkerSize_;
    111     std::string fontName_;
    112     float textSize_;
    113     bool showDistance;
    114 
    115     unsigned int markerLimit_;
    116     float detectionLimit_; //!< Objects that are more far away than detectionLimit_ are not displayed on the HUD. 10000.0f is the default value.
    117 
    118 };
    119117}
    120118
  • code/trunk/src/modules/overlays/hud/HUDRadar.cc

    r8891 r9348  
    9292    void HUDRadar::addObject(RadarViewable* object)
    9393    {
    94         if (object == dynamic_cast<RadarViewable*>(this->owner_))
     94        if (object == orxonox_cast<RadarViewable*>(this->owner_))
    9595            return;
    9696        if( showObject(object) == false ) //do not show objects that are "invisible" or "radar invisible"
     
    189189    bool HUDRadar::showObject(RadarViewable* rv)
    190190    {
    191         if ( rv == dynamic_cast<RadarViewable*> ( this->getOwner() ) )
     191        if ( rv == orxonox_cast<RadarViewable*> ( this->getOwner() ) )
    192192            return false;
    193193        assert( rv->getWorldEntity() );
  • code/trunk/src/modules/pickup/CMakeLists.txt

    r7163 r9348  
    11SET_SOURCE_FILES(PICKUP_SRC_FILES
    22  CollectiblePickup.cc
    3   DroppedPickup.cc
    43  Pickup.cc
    54  PickupCollection.cc
    6   PickupCollectionIdentifier.cc
    75  PickupManager.cc
    86  PickupRepresentation.cc
  • code/trunk/src/modules/pickup/CollectiblePickup.cc

    r7494 r9348  
    4545        Registers the object and initializes variables.
    4646    */
    47     CollectiblePickup::CollectiblePickup() : isInCollection_(false)
     47    CollectiblePickup::CollectiblePickup() : collection_(NULL)
    4848    {
    4949        RegisterObject(CollectiblePickup);
    50 
    51         this->collection_ = NULL;
    5250    }
    5351
     
    5856    CollectiblePickup::~CollectiblePickup()
    5957    {
    60 
    61     }
    62 
    63     /**
    64     @brief
    65         Is called by OrxonoxClass::destroy() before the object is actually destroyed.
    66     */
    67     void CollectiblePickup::preDestroy(void)
    68     {
    69         this->Pickupable::preDestroy();
    70 
    71         // The PickupCollection has to be destroyed as well.
    72         if(this->isInCollection())
    73             this->collection_->Pickupable::destroy();
    74     }
    75 
    76     /**
    77     @brief
    78         Destroys a Pickupable.
    79     */
    80     void CollectiblePickup::destroyPickup(void)
    81     {
    82         if(!this->isInCollection()) // If the CollectiblePickup is not in a PickupCollection the destroyPickup method of Pickupable is called.
    83             this->Pickupable::destroyPickup();
    84         else // Else the ColectiblePickup is dropped and disabled,
    85         {
    86             this->drop(false);
    87             if(this->isInCollection() && this->isEnabled()) // It is only disabled if it is enabled and still ina PickupCollection after having been dropped.
    88             {
    89                 this->setDisabled();
    90                 this->collection_->pickupDisabled();
    91             }
    92         }
    93     }
    94 
    95     /**
    96     @brief
    97         Is called by the PickupCarrier when it is being destroyed.
    98     */
    99     void CollectiblePickup::carrierDestroyed(void)
    100     {
    101         if(!this->isInCollection())
    102             this->Pickupable::destroy();
    103         else // If the CollectiblePickup is part of a PickupCollection it is just dropped instead of destroyed.
    104             this->drop(false);
     58        if (this->isInCollection())
     59            this->collection_->removePickupable(this);
    10560    }
    10661
     
    13186    /**
    13287    @brief
    133         Adds this CollectiblePickup to the input PickupCollection.
     88        Notifies this CollectiblePickup that it was added to a PickupCollection.
    13489    @param collection
    13590        A pointer to the PickupCollection to which the CollectiblePickup should be added.
    136     @return
    137         Returns true if the CollectiblePickup was successfully added to the PickupCollection.
    13891    */
    139     bool CollectiblePickup::addToCollection(PickupCollection* collection)
     92    void CollectiblePickup::wasAddedToCollection(PickupCollection* collection)
    14093    {
    141         if(this->isInCollection() || collection == NULL) //If the CollectiblePickup already is in a PickupCollection or if the input pointer is NULL.
    142             return false;
    143 
    144         this->isInCollection_ = true;
    14594        this->collection_ = collection;
    146         return true;
    14795    }
    14896
    14997    /**
    15098    @brief
    151         Removes this CollectiblePickup from its PickupCollection.
    152     @return
    153         Returns true if the CollectiblePickup was succcessfully removed.
     99        Notifies this CollectiblePickup that it was removed from its PickupCollection.
    154100    */
    155     bool CollectiblePickup::removeFromCollection(void)
     101    void CollectiblePickup::wasRemovedFromCollection(void)
    156102    {
    157         if(!this->isInCollection()) //If the CollectiblePickup is not in a PickupCollection.
    158             return false;
    159 
    160         this->isInCollection_ = false;
    161103        this->collection_ = NULL;
    162         return true;
    163104    }
    164 
    165105}
  • code/trunk/src/modules/pickup/CollectiblePickup.h

    r7547 r9348  
    5555    class _PickupExport CollectiblePickup : public Pickupable
    5656    {
     57        friend class PickupCollection;
    5758
    5859        public:
     
    6869            */
    6970            bool isInCollection(void) const
    70                 { return this->isInCollection_; }
    71 
    72             bool addToCollection(PickupCollection* collection); //!< Adds this CollectiblePickup to the input PickupCollection.
    73             bool removeFromCollection(void); //!< Removes this CollectiblePickup from its PickupCollection.
    74 
    75             void carrierDestroyed(void); //!< Is called by the PickupCarrier when it is being destroyed.
    76 
    77         protected:
    78             virtual void preDestroy(void); //!< Is called by OrxonoxClass::destroy() before the object is actually destroyed.
    79             virtual void destroyPickup(void); //!< Destroys a Pickupable.
     71                { return this->collection_ != NULL; }
    8072
    8173        private:
    82             bool isInCollection_; //!< True if the CollectiblePickup is in a PickupCollection.
     74            void wasAddedToCollection(PickupCollection* collection);
     75            void wasRemovedFromCollection(void);
     76
    8377            PickupCollection* collection_; //!< A pointer to the PickupCollection this CollectiblePickup is in.
    84 
    8578    };
    8679}
  • code/trunk/src/modules/pickup/Pickup.cc

    r8864 r9348  
    3737#include "util/StringUtils.h"
    3838
    39 #include "pickup/PickupIdentifier.h"
    40 
    41 #include "DroppedPickup.h"
     39#include "PickupSpawner.h"
    4240
    4341namespace orxonox
     
    8684    /**
    8785    @brief
    88         Initializes the PickupIdentififer of this Pickup.
    89     */
    90     void Pickup::initializeIdentifier(void)
    91     {
    92         std::string val1 = this->getActivationType();
    93         std::string type1 = "activationType";
    94         this->pickupIdentifier_->addParameter(type1, val1);
    95 
    96         std::string val2 = this->getDurationType();
    97         std::string type2 = "durationType";
    98         this->pickupIdentifier_->addParameter(type2, val2);
    99     }
    100 
    101     /**
    102     @brief
    10386        Method for creating a Pickup object through XML.
    10487    */
     
    10790        SUPER(Pickup, XMLPort, xmlelement, mode);
    10891
    109         XMLPortParam(Pickup, "activationType", setActivationType, getActivationType, xmlelement, mode);
    110         XMLPortParam(Pickup, "durationType", setDurationType, getDurationType, xmlelement, mode);
    111 
    112         this->initializeIdentifier();
     92        XMLPortParam(Pickup, "representation", setRepresentationName, getRepresentationName, xmlelement, mode);
     93        XMLPortParam(Pickup, "activationType", setActivationTypeAsString, getActivationTypeAsString, xmlelement, mode);
     94        XMLPortParam(Pickup, "durationType", setDurationTypeAsString, getDurationTypeAsString, xmlelement, mode);
    11395    }
    11496
     
    119101        Returns a string containing the activation type.
    120102    */
    121     const std::string& Pickup::getActivationType(void) const
     103    const std::string& Pickup::getActivationTypeAsString(void) const
    122104    {
    123         switch(this->activationType_)
     105        switch(this->getActivationType())
    124106        {
    125107            case pickupActivationType::immediate:
     
    138120        Returns a string containing the duration type.
    139121    */
    140     const std::string& Pickup::getDurationType(void) const
     122    const std::string& Pickup::getDurationTypeAsString(void) const
    141123    {
    142         switch(this->durationType_)
     124        switch(this->getDurationType())
    143125        {
    144126            case pickupDurationType::once:
     
    157139        The activation type of the Pickup as a string.
    158140    */
    159     void Pickup::setActivationType(const std::string& type)
     141    void Pickup::setActivationTypeAsString(const std::string& type)
    160142    {
    161143        if(type == Pickup::activationTypeImmediate_s)
    162             this->activationType_ = pickupActivationType::immediate;
     144            this->setActivationType(pickupActivationType::immediate);
    163145        else if(type == Pickup::activationTypeOnUse_s)
    164             this->activationType_ = pickupActivationType::onUse;
     146            this->setActivationType(pickupActivationType::onUse);
    165147        else
    166148            orxout(internal_error, context::pickups) << "Invalid activationType '" << type << "' in " << this->getIdentifier()->getName() << "." << endl;
     
    173155        The duration type of the Pickup as a string.
    174156    */
    175     void Pickup::setDurationType(const std::string& type)
     157    void Pickup::setDurationTypeAsString(const std::string& type)
    176158    {
    177159        if(type == Pickup::durationTypeOnce_s)
    178             this->durationType_ = pickupDurationType::once;
     160            this->setDurationType(pickupDurationType::once);
    179161        else if(type == Pickup::durationTypeContinuous_s)
    180             this->durationType_ = pickupDurationType::continuous;
     162            this->setDurationType(pickupDurationType::continuous);
    181163        else
    182164            orxout(internal_error, context::pickups) << "Invalid durationType '" << type << "' in " << this->getIdentifier()->getName() << "." << endl;
     
    199181    /**
    200182    @brief
    201         Creates a duplicate of the OrxonoxClass.
    202     @param item
    203         A reference to the pointer of the item that we're duplicating.
    204     */
    205     void Pickup::clone(OrxonoxClass*& item)
    206     {
    207         if(item == NULL)
    208             item = new Pickup(this);
    209 
    210         SUPER(Pickup, clone, item);
    211 
    212         Pickup* pickup = dynamic_cast<Pickup*>(item);
    213         pickup->setActivationTypeDirect(this->getActivationTypeDirect());
    214         pickup->setDurationTypeDirect(this->getDurationTypeDirect());
    215 
    216         pickup->initializeIdentifier();
    217     }
    218 
    219     /**
    220     @brief
    221183        Facilitates the creation of a PickupSpawner upon dropping of the Pickupable.
    222         This method must be implemented by any class directly inheriting from Pickupable. It is most easily done by just creating a new DroppedPickup, e.g.:
    223         DroppedPickup(BaseObject* creator, Pickupable* pickup, const Vector3& position);
    224184    @return
    225185        Returns true if a spawner was created, false if not.
     
    227187    bool Pickup::createSpawner(void)
    228188    {
    229         new DroppedPickup(this, this, this->getCarrier());
     189        PickupSpawner::createDroppedPickup(this, this, this->getCarrier());
    230190        return true;
    231191    }
  • code/trunk/src/modules/pickup/Pickup.h

    r8108 r9348  
    105105            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    106106
     107            virtual const std::string& getRepresentationName() const
     108                { return this->representationName_; }
     109
    107110            /**
    108111            @brief Get the activation type of the Pickup.
    109112            @return Returns the activation type of the Pickup.
    110113            */
    111             inline pickupActivationType::Value getActivationTypeDirect(void) const
     114            inline pickupActivationType::Value getActivationType(void) const
    112115                { return this->activationType_; }
    113116            /**
     
    115118            @return Returns the duration type of the Pickup.
    116119            */
    117             inline pickupDurationType::Value getDurationTypeDirect(void) const
     120            inline pickupDurationType::Value getDurationType(void) const
    118121                { return this->durationType_; }
    119122
    120             const std::string& getActivationType(void) const; //!< Get the activation type of the Pickup.
    121             const std::string& getDurationType(void) const; //!< Get the duration type of the Pickup.
     123            const std::string& getActivationTypeAsString(void) const; //!< Get the activation type of the Pickup.
     124            const std::string& getDurationTypeAsString(void) const; //!< Get the duration type of the Pickup.
    122125
    123126            /**
     
    126129            */
    127130            inline bool isImmediate(void) const
    128                 { return this->getActivationTypeDirect() == pickupActivationType::immediate; }
     131                { return this->getActivationType() == pickupActivationType::immediate; }
    129132            /**
    130133            @brief Get whether the activation type is 'onUse'.
     
    132135            */
    133136            inline bool isOnUse(void) const
    134                 { return this->getActivationTypeDirect() == pickupActivationType::onUse; }
     137                { return this->getActivationType() == pickupActivationType::onUse; }
    135138            /**
    136139            @brief Get whether the duration type is 'once'.
     
    138141            */
    139142            inline bool isOnce(void) const
    140                 { return this->getDurationTypeDirect() == pickupDurationType::once; }
     143                { return this->getDurationType() == pickupDurationType::once; }
    141144            /**
    142145            @brief Get whether the duration type is 'continuous'.
     
    144147            */
    145148            inline bool isContinuous(void) const
    146                 { return this->getDurationTypeDirect() == pickupDurationType::continuous; }
     149                { return this->getDurationType() == pickupDurationType::continuous; }
    147150
    148151            virtual void changedPickedUp(void); //!< Should be called when the pickup has transited from picked up to dropped or the other way around.
    149             virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the OrxonoxClass.
    150152
    151153        protected:
    152             void initializeIdentifier(void);
     154            virtual bool createSpawner(void); //!< Facilitates the creation of a PickupSpawner upon dropping of the Pickupable.
    153155
    154             virtual bool createSpawner(void); //!< Facilitates the creation of a PickupSpawner upon dropping of the Pickupable.
     156            /**
     157            @brief Sets the representation name which refers to the name of the PickupRepresentation that is used to represent this pickup.
     158            */
     159            inline void setRepresentationName(const std::string& name)
     160                { this->representationName_ = name; }
    155161
    156162            /**
     
    158164            @param type The activation type of the Pickup.
    159165            */
    160             inline void setActivationTypeDirect(pickupActivationType::Value type)
     166            inline void setActivationType(pickupActivationType::Value type)
    161167                { this->activationType_ = type; }
    162168            /**
     
    164170            @param type The duration type of the Pickup.
    165171            */
    166             inline void setDurationTypeDirect(pickupDurationType::Value type)
     172            inline void setDurationType(pickupDurationType::Value type)
    167173                { this->durationType_ = type; }
    168174
    169             void setActivationType(const std::string& type); //!< Set the activation type of the Pickup.
    170             void setDurationType(const std::string& type); //!< Set the duration type of the Pickup.
     175            void setActivationTypeAsString(const std::string& type); //!< Set the activation type of the Pickup.
     176            void setDurationTypeAsString(const std::string& type); //!< Set the duration type of the Pickup.
    171177
    172178        private:
    173179            void initialize(void); //!< Initializes the member variables.
    174180
     181            std::string representationName_; //!< The name of the associated PickupRepresentation.
    175182            pickupActivationType::Value activationType_; //!< The activation type of the Pickup.
    176183            pickupDurationType::Value durationType_; //!< The duration type of the Pickup.
  • code/trunk/src/modules/pickup/PickupCollection.cc

    r8305 r9348  
    3838
    3939#include "CollectiblePickup.h"
    40 #include "DroppedPickup.h"
    41 #include "PickupCollectionIdentifier.h"
     40#include "PickupSpawner.h"
    4241
    4342#include "PickupCollection.h"
     
    5453        The creator of the object.
    5554    */
    56     PickupCollection::PickupCollection(BaseObject* creator) : BaseObject(creator), pickupCollectionIdentifier_(NULL)
     55    PickupCollection::PickupCollection(BaseObject* creator) : BaseObject(creator)
    5756    {
    5857        RegisterObject(PickupCollection);
    5958
    60         this->pickupCollectionIdentifier_ = new PickupCollectionIdentifier(this);
    61         this->usedCounter_ = 0;
    62         this->pickedUpCounter_ = 0;
    63         this->disabledCounter_ = 0;
    6459        this->processingUsed_ = false;
    6560        this->processingPickedUp_ = false;
     
    7065        Destructor. Iterates through all Pickupables this PickupCollection consists of and destroys them if they haven't been already.
    7166    */
    72     PickupCollection::~ PickupCollection()
     67    PickupCollection::~PickupCollection()
    7368    {
    7469        // Destroy all Pickupables constructing this PickupCollection.
    75         for(std::vector<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
    76         {
    77             (*it)->removeFromCollection();
     70        for(std::list<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); ++it)
     71        {
     72            (*it)->wasRemovedFromCollection();
    7873            (*it)->destroy();
    7974        }
    8075        this->pickups_.clear();
    81        
    82         if(this->pickupCollectionIdentifier_ != NULL)
    83             delete this->pickupCollectionIdentifier_;
    8476    }
    8577
     
    9284        SUPER(PickupCollection, XMLPort, xmlelement, mode);
    9385
     86        XMLPortParam(PickupCollection, "representation", setRepresentationName, getRepresentationName, xmlelement, mode);
    9487        XMLPortObject(PickupCollection, CollectiblePickup, "pickupables", addPickupable, getPickupable, xmlelement, mode);
    95 
    96         this->initializeIdentifier();
    97     }
    98 
    99     /**
    100     @brief
    101         Initializes the PickupIdentifier for this pickup.
    102     */
    103     void PickupCollection::initializeIdentifier(void)
    104     {
    105         for(std::vector<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
    106         {
    107             this->pickupCollectionIdentifier_->addPickup((*it)->getPickupIdentifier());
    108         }
    10988    }
    11089
     
    12099        this->processingUsed_ = true;
    121100        // Change used for all Pickupables this PickupCollection consists of.
    122         for(std::vector<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
     101        for(std::list<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); ++it)
    123102            (*it)->setUsed(this->isUsed());
    124103
     
    138117            return;
    139118
     119        size_t numPickupsEnabled = 0;
     120        size_t numPickupsInUse = 0;
     121        for(std::list<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); ++it)
     122        {
     123            if ((*it)->isEnabled())
     124                ++numPickupsEnabled;
     125            if ((*it)->isUsed())
     126                ++numPickupsInUse;
     127        }
     128
    140129        // If all the pickups are not in use but the PickupCollection is.
    141         if(this->usedCounter_ == 0 && this->isUsed())
     130        if(numPickupsInUse == 0 && this->isUsed())
    142131            this->setUsed(false);
    143132
    144133        // If all the enabled pickups are in use but the PickupCollection is not.
    145         if(this->usedCounter_ != 0 && this->usedCounter_ == this->pickups_.size()-this->disabledCounter_ && !this->isUsed())
     134        if(numPickupsInUse > 0 && numPickupsInUse == numPickupsEnabled && !this->isUsed())
    146135            this->setUsed(true);
    147136    }
     
    157146
    158147        // Change the PickupCarrier for all Pickupables this PickupCollection consists of.
    159         for(std::vector<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
     148        for(std::list<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); ++it)
    160149        {
    161150            if(this->getCarrier() == NULL)
     
    177166        this->processingPickedUp_ = true;
    178167        // Change the pickedUp status for all Pickupables this PickupCollection consists of.
    179         for(std::vector<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
    180             (*it)->setPickedUp(this->isPickedUp());
     168        for(std::list<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); )
     169            (*(it++))->setPickedUp(this->isPickedUp());
    181170
    182171        this->processingPickedUp_ = false;
     
    195184            return;
    196185
    197         // If at least all the enabled pickups of this PickupCollection are no longer picked up.
    198         if(this->pickedUpCounter_ <= this->disabledCounter_ && this->isPickedUp())
     186        // If at least all the enabled pickups of this PickupCollection are no longer picked up.
     187        bool isOnePickupEnabledAndPickedUp = false;
     188        for(std::list<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); ++it)
     189        {
     190            if ((*it)->isEnabled() && (*it)->isPickedUp())
     191            {
     192                isOnePickupEnabledAndPickedUp = true;
     193                break;
     194            }
     195        }
     196        if(!isOnePickupEnabledAndPickedUp && this->isPickedUp())
    199197            this->Pickupable::destroy();
    200 
    201         // If the PickupCollection is no longer picked up.
    202         if(!this->isPickedUp())
    203             this->pickedUpCounter_ = 0;
    204     }
    205 
    206     /**
    207     @brief
    208         Creates a duplicate of the input Pickupable.
    209         This method needs to be implemented by any Class inheriting from Pickupable.
    210     @param item
    211         A reference to a pointer to the OrxonoxClass that is to be duplicated.
    212     */
    213     void PickupCollection::clone(OrxonoxClass*& item)
    214     {
    215         if(item == NULL)
    216             item = new PickupCollection(this);
    217 
    218         SUPER(PickupCollection, clone, item);
    219 
    220         PickupCollection* pickup = dynamic_cast<PickupCollection*>(item);
    221         // Clone all Pickupables this PickupCollection consist of.
    222         for(std::vector<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
    223         {
    224             Pickupable* newPickup = (*it)->clone();
    225             CollectiblePickup* collectible = static_cast<CollectiblePickup*>(newPickup);
    226             pickup->addPickupable(collectible);
    227         }
    228 
    229         pickup->initializeIdentifier();
    230198    }
    231199
     
    240208    bool PickupCollection::isTarget(const PickupCarrier* carrier) const
    241209    {
    242         for(std::vector<CollectiblePickup*>::const_iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
     210        for(std::list<CollectiblePickup*>::const_iterator it = this->pickups_.begin(); it != this->pickups_.end(); ++it)
    243211        {
    244212            if(!carrier->isTarget(*it))
     
    247215
    248216        return true;
    249     }
    250 
    251     /**
    252     @brief
    253         Get the PickupIdentifier of this PickupCollection.
    254         This is in fact the PickupCollectionIdentifier.
    255     @return
    256         Returns a pointer to the PickupIdentifier of this PickupCollection.
    257     */
    258     const PickupIdentifier* PickupCollection::getPickupIdentifier(void) const
    259     {
    260         return this->pickupCollectionIdentifier_;
    261217    }
    262218
     
    274230            return false;
    275231
    276         pickup->addToCollection(this);
    277232        this->pickups_.push_back(pickup);
     233        pickup->wasAddedToCollection(this);
     234        this->pickupsChanged();
    278235        return true;
    279236    }
     
    289246    const Pickupable* PickupCollection::getPickupable(unsigned int index) const
    290247    {
    291         return this->pickups_[index];
     248        if(this->pickups_.size() >= index)
     249            return NULL;
     250
     251        std::list<CollectiblePickup*>::const_iterator it = this->pickups_.begin();
     252        std::advance(it, index);
     253        return *it;
     254    }
     255
     256    /**
     257    @brief
     258        Removes the Pickup from the Collection.
     259    @param pickup
     260        The Pickup to be removed.
     261    @return
     262        Returns true if the pickup was in the collection.
     263    */
     264    bool PickupCollection::removePickupable(CollectiblePickup* pickup)
     265    {
     266        for(std::list<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); ++it)
     267        {
     268            if (*it == pickup)
     269            {
     270                this->pickups_.erase(it);
     271                pickup->wasRemovedFromCollection();
     272                this->pickupsChanged();
     273                return true;
     274            }
     275        }
     276        return false;
    292277    }
    293278
     
    297282        This is used internally by the CollectiblePickup class.
    298283    @param changed
    299         The value the used status has changed to. 
     284        The value the used status has changed to.
    300285    */
    301286    void PickupCollection::pickupChangedUsed(bool changed)
    302287    {
    303         if(changed)
    304             this->usedCounter_++;
    305         else
    306             this->usedCounter_--;
    307 
    308288        this->changedUsedAction();
    309289    }
     
    318298    void PickupCollection::pickupChangedPickedUp(bool changed)
    319299    {
    320         if(changed)
    321             this->pickedUpCounter_++;
    322         else
    323             this->pickedUpCounter_--;
    324 
    325300        this->changedPickedUpAction();
    326301    }
     
    333308    void PickupCollection::pickupDisabled(void)
    334309    {
    335         this->disabledCounter_++;
     310    }
     311
     312    /**
     313    @brief
     314        Helpfer function if the number of pickups in this collection has changed.
     315    */
     316    void PickupCollection::pickupsChanged(void)
     317    {
     318        this->changedUsedAction();
     319        this->changedPickedUpAction();
    336320    }
    337321
     
    339323    @brief
    340324        Facilitates the creation of a PickupSpawner upon dropping of the Pickupable.
    341         This method must be implemented by any class directly inheriting from Pickupable. It is most easily done by just creating a new DroppedPickup, e.g.:
    342         DroppedPickup(BaseObject* creator, Pickupable* pickup, const Vector3& position);
    343325    @return
    344326        Returns true if a spawner was created, false if not.
     
    346328    bool PickupCollection::createSpawner(void)
    347329    {
    348         new DroppedPickup(this, this, this->getCarrier());
     330        PickupSpawner::createDroppedPickup(this, this, this->getCarrier());
    349331        return true;
    350332    }
  • code/trunk/src/modules/pickup/PickupCollection.h

    r8351 r9348  
    5050        The PickupCollection combines different @ref orxonox::Pickupable "Pickupables" (more precisely @ref orxonox::CollectiblePickup "CollectiblePickups") to a coherent, single pickup and makes them seem (from the outside looking in) just as if they were just one @ref orxonox::Pickupable "Pickupable".
    5151
    52         To differentiate between different types of @ref orxonox::PickupCollection "PickupCollections" (just as we differentiate between different types of @ref orxonox::Pickupable "Pickupables") we define a new identifyer called the @ref orxonox::PickupCollectionIdentifier "PickupCollectionIdentifier" which has pretty much the same properties as the @ref orxonox::PickupIdentifier "PickupIdentifier" but extende to @ref orxonox::PickupCollection "PickupCollections".
    53 
    5452        A PickupCollection can be created in XML as follows:
    5553        @code
     
    8179            virtual void changedPickedUp(void); //!< Is called when the pickup has transited from picked up to dropped or the other way around.
    8280
    83             virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the input pickup.
    84 
    8581            virtual bool isTarget(const PickupCarrier* carrier) const; //!< Get whether a given class, represented by the input Identifier, is a target of this PickupCollection.
    8682
    87             virtual const PickupIdentifier* getPickupIdentifier(void) const; //!< Get the PickupIdentifier of this PickupCollection.
     83            inline void setRepresentationName(const std::string& name)
     84                { this->representationName_ = name; }
     85            virtual const std::string& getRepresentationName() const
     86                { return this->representationName_; }
    8887
    8988            bool addPickupable(CollectiblePickup* pickup); //!< Add the input Pickupable to list of Pickupables combined by this PickupCollection.
    9089            const Pickupable* getPickupable(unsigned int index) const; //!< Get the Pickupable at the given index.
     90            bool removePickupable(CollectiblePickup* pickup); //!< Removes the input Pickupable from the list of Pickupables in this PickupCollection.
     91
     92            inline const std::list<CollectiblePickup*>& getPickups() const
     93                { return this->pickups_; }
    9194
    9295            void pickupChangedUsed(bool changed); //!< Informs the PickupCollection, that one of its pickups has changed its used status to the input value.
     
    9598
    9699        protected:
    97             void initializeIdentifier(void); //!< Initializes the PickupIdentifier for this pickup.
    98 
    99100            virtual bool createSpawner(void); //!< Facilitates the creation of a PickupSpawner upon dropping of the Pickupable.
    100 
    101             PickupCollectionIdentifier* pickupCollectionIdentifier_; //!< The PickupCollectionIdentifier of this PickupCollection. Is used to distinguish different PickupCollections amongst themselves.
    102101
    103102        private:
    104103            void changedUsedAction(void); //!< Helper method.
    105104            void changedPickedUpAction(void); //!< Helper method.
     105            void pickupsChanged(void); //!< Helper method.
    106106
    107             std::vector<CollectiblePickup*> pickups_; //!< The list of the pointers of all the Pickupables this PickupCollection consists of. They are weak pointers to facilitate testing, whether the pointers are still valid.
    108 
    109             unsigned int usedCounter_; //!< Keeps track of the number of pickups of this PickupCollection, that are in use.
    110             unsigned int pickedUpCounter_; //!< Keeps track of the number of pickups of this PickupCollection, that are picked up.
    111             unsigned int disabledCounter_; //!< Keeps track of the number of pickups of this PickupCollection, that are disabled.
     107            std::string representationName_; //!< The name of the associated PickupRepresentation.
     108            std::list<CollectiblePickup*> pickups_; //!< The list of the pointers of all the Pickupables this PickupCollection consists of. They are weak pointers to facilitate testing, whether the pointers are still valid.
    112109
    113110            bool processingUsed_; //!< Boolean to ensure, that the PickupCollection doesn't update its used status while its internal state is inconsistent.
  • code/trunk/src/modules/pickup/PickupManager.cc

    r8858 r9348  
    8787
    8888        this->representations_.clear();
    89         this->representationsNetworked_.clear();
    9089
    9190        // Destroying all the PickupInventoryContainers that are still there.
     
    106105    /**
    107106    @brief
    108         Registers a PickupRepresentation together with the PickupIdentifier of the Pickupable the PickupRepresentation represents, on the server (or in standalone mode).
    109         For every type of Pickupable (uniquely identified by a PickupIdentifier) there can be one (and just one) PickupRepresentation registered.
    110     @param identifier
    111         The PickupIdentifier identifying the Pickupable.
     107        Registers a PickupRepresentation.
     108    @param name
     109        The representation's name.
    112110    @param representation
    113111        A pointer to the PickupRepresentation.
     
    115113        Returns true if successful and false if not.
    116114    */
    117     bool PickupManager::registerRepresentation(const PickupIdentifier* identifier, PickupRepresentation* representation)
    118     {
    119         assert(identifier);
     115    bool PickupManager::registerRepresentation(const std::string& name, PickupRepresentation* representation)
     116    {
    120117        assert(representation);
    121118
    122119        // If the list is not empty and Pickupable already has a Representation registered.
    123         if(!this->representations_.empty() && this->representations_.find(identifier) != this->representations_.end())
     120        if(!this->representations_.empty() && this->representations_.find(name) != this->representations_.end())
    124121            return false;
    125122
    126         this->representations_[identifier] = representation;
     123        this->representations_[name] = representation;
    127124
    128125        orxout(verbose, context::pickups) << "PickupRepresentation &" << representation << " registered with the PickupManager." << endl;
     
    132129    /**
    133130    @brief
    134         Unegisters a PickupRepresentation together with the PickupIdentifier of the Pickupable the PickupRepresentation represents, on the server (or in standalone mode).
    135     @param identifier
    136         The PickupIdentifier identifying the Pickupable.
    137     @param representation
    138         A pointer to the PickupRepresentation.
     131        Unegisters a PickupRepresentation.
     132    @param name
     133        The representation's name.
    139134    @return
    140135        Returns true if successful and false if not.
    141136    */
    142     bool PickupManager::unregisterRepresentation(const PickupIdentifier* identifier, PickupRepresentation* representation)
    143     {
    144         assert(identifier);
    145         assert(representation);
    146 
    147         std::map<const PickupIdentifier*, PickupRepresentation*, PickupIdentifierCompare>::iterator it = this->representations_.find(identifier);
     137    bool PickupManager::unregisterRepresentation(const std::string& name)
     138    {
     139        std::map<std::string, PickupRepresentation*>::iterator it = this->representations_.find(name);
    148140        if(it == this->representations_.end()) // If the Pickupable is not registered in the first place.
    149141            return false;
     
    151143        this->representations_.erase(it);
    152144
    153         orxout(verbose, context::pickups) << "PickupRepresentation &" << representation << " unregistered with the PickupManager." << endl;
     145        orxout(verbose, context::pickups) << "PickupRepresentation &" << name << " unregistered with the PickupManager." << endl;
    154146        return true;
    155147    }
     
    157149    /**
    158150    @brief
    159         Registers a PickupRepresentation on the host it was created.
    160     @param representation
    161         A pointer to the PickupRepresentation.
    162     @return
    163         Returns true if successful, false if not.
    164     */
    165     bool PickupManager::registerRepresentation(PickupRepresentation* representation)
    166     {
    167         assert(representation);
    168 
    169         // If the list is not empty and PickupRepresentation is already registered.
    170         if(!this->representationsNetworked_.empty() && this->representationsNetworked_.find(representation->getObjectID()) != this->representationsNetworked_.end())
    171             return false;
    172 
    173         this->representationsNetworked_[representation->getObjectID()] = representation;
    174         return true;
    175     }
    176 
    177     /**
    178     @brief
    179         Unregisters a PickupRepresentation on the host it is being destroyed (which is the same host on which it was created).
    180     @param representation
    181         A pointer to the Pickuprepresentation.
    182     @return
    183         Returns true if successful, false if not.
    184     */
    185     bool PickupManager::unregisterRepresentation(PickupRepresentation* representation)
    186     {
    187         assert(representation);
    188 
    189         std::map<uint32_t, PickupRepresentation*>::iterator it = this->representationsNetworked_.find(representation->getObjectID());
    190         if(it == this->representationsNetworked_.end()) // If the Pickupable is not registered in the first place.
    191             return false;
    192 
    193         this->representationsNetworked_.erase(it);
    194         return true;
    195     }
    196 
    197     /**
    198     @brief
    199         Get the PickupRepresentation representing the Pickupable with the input PickupIdentifier.
    200     @param identifier
    201         The PickupIdentifier.
     151        Get the PickupRepresentation with the given name.
     152    @param name
     153        The name of the PickupRepresentation.
    202154    @return
    203155        Returns a pointer to the PickupRepresentation.
    204156    */
    205     PickupRepresentation* PickupManager::getRepresentation(const PickupIdentifier* identifier)
    206     {
    207         std::map<const PickupIdentifier*, PickupRepresentation*, PickupIdentifierCompare>::iterator it = this->representations_.find(identifier);
    208         if(it == this->representations_.end()) // If there is no PickupRepresentation associated with the input PickupIdentifier.
     157    PickupRepresentation* PickupManager::getRepresentation(const std::string& name)
     158    {
     159        std::map<std::string, PickupRepresentation*>::iterator it = this->representations_.find(name);
     160        if(it == this->representations_.end()) // If there is no PickupRepresentation associated with the input name.
    209161        {
    210162            orxout(verbose, context::pickups) << "PickupManager::getRepresentation() returned default representation." << endl;
     
    353305        {
    354306            // If there is no PickupRepresentation registered the default representation is used.
    355             if(this->representations_.find(pickup->getPickupIdentifier()) == this->representations_.end())
    356                 PickupManager::pickupChangedPickedUpNetwork(index, pickup->isUsable(), this->defaultRepresentation_->getObjectID(), pickedUp);
     307            if(this->representations_.find(pickup->getRepresentationName()) == this->representations_.end())
     308                PickupManager::pickupChangedPickedUpNetwork(index, pickup->isUsable(), this->defaultRepresentation_->getObjectID(), pickup->getRepresentationName(), pickedUp);
    357309            else
    358                 PickupManager::pickupChangedPickedUpNetwork(index, pickup->isUsable(), this->representations_[pickup->getPickupIdentifier()]->getObjectID(), pickedUp);
     310                PickupManager::pickupChangedPickedUpNetwork(index, pickup->isUsable(), this->representations_[pickup->getRepresentationName()]->getObjectID(), pickup->getRepresentationName(), pickedUp);
    359311        }
    360312        // If the concerned host is somewhere in the network, we call pickupChangedPickedUpNetwork() on its PickupManager.
     
    362314        {
    363315            // If there is no PickupRepresentation registered the default representation is used.
    364             if(this->representations_.find(pickup->getPickupIdentifier()) == this->representations_.end())
     316            if(this->representations_.find(pickup->getRepresentationName()) == this->representations_.end())
    365317            {
    366318                callStaticNetworkFunction(PickupManager::pickupChangedPickedUpNetwork, clientId, index, pickup->isUsable(), this->defaultRepresentation_->getObjectID(), pickedUp);
     
    368320            else
    369321            {
    370                 callStaticNetworkFunction(PickupManager::pickupChangedPickedUpNetwork, clientId, index, pickup->isUsable(), this->representations_[pickup->getPickupIdentifier()]->getObjectID(), pickedUp);
     322                callStaticNetworkFunction(PickupManager::pickupChangedPickedUpNetwork, clientId, index, pickup->isUsable(), this->representations_[pickup->getRepresentationName()]->getObjectID(), pickedUp);
    371323            }
    372324        }
     
    388340        The pickedUp status the Pickupable changed to.
    389341    */
    390     /*static*/ void PickupManager::pickupChangedPickedUpNetwork(uint32_t pickup, bool usable, uint32_t representationObjectId, bool pickedUp)
     342    /*static*/ void PickupManager::pickupChangedPickedUpNetwork(uint32_t pickup, bool usable, uint32_t representationObjectId, const std::string& representationName, bool pickedUp)
    391343    {
    392344        PickupManager& manager = PickupManager::getInstance(); // Get the PickupManager singleton on this host.
     
    402354            container->unusable = false;
    403355            container->representationObjectId = representationObjectId;
     356            container->representationName = representationName;
    404357            // Insert the container into the pickupInventoryContainers_ list.
    405358            manager.pickupInventoryContainers_.insert(std::pair<uint32_t, PickupInventoryContainer*>(pickup, container));
     
    417370            manager.updateGUI(); // Tell the PickupInventory that something has changed.
    418371        }
    419     }
    420 
    421     /**
    422     @brief
    423         Get the PickupRepresentation of an input Pickupable.
    424         This method spares us the hassle to export the PickupIdentifier class to lua.
    425     @param pickup
    426         The number identifying the Pickupable whose PickupRepresentation should be returned.
    427     @return
    428         Returns the PickupRepresentation of the input Pickupable or NULL if an error occurred.
    429     */
    430     orxonox::PickupRepresentation* PickupManager::getPickupRepresentation(uint32_t pickup)
    431     {
    432         // Clear and rebuild the representationsNetworked_ list.
    433         //TODO: Better solution?
    434         this->representationsNetworked_.clear();
    435         for(ObjectList<PickupRepresentation>::iterator it = ObjectList<PickupRepresentation>::begin(); it != ObjectList<PickupRepresentation>::end(); ++it)
    436             this->representationsNetworked_[it->getObjectID()] = *it;
    437 
    438         // Get the container belonging to the input pickup, if not found return the default representation.
    439         std::map<uint32_t, PickupInventoryContainer*>::iterator it = this->pickupInventoryContainers_.find(pickup);
    440         if(it == this->pickupInventoryContainers_.end())
    441             return this->defaultRepresentation_;
    442 
    443         // Get the PickupRepresentation of the input pickup (through the objecId of the representation stored in the PickupInventoryContainer belonging to the pickup), if not found return the default representation.
    444         std::map<uint32_t, PickupRepresentation*>::iterator it2 = this->representationsNetworked_.find(it->second->representationObjectId);
    445         if(it2 == this->representationsNetworked_.end())
    446             return this->defaultRepresentation_;
    447 
    448         return it2->second;
    449372    }
    450373
  • code/trunk/src/modules/pickup/PickupManager.h

    r8706 r9348  
    4141#include "core/WeakPtr.h"
    4242
    43 #include "pickup/PickupIdentifier.h"
    44 
    4543#include "PickupRepresentation.h"
    4644
     
    6765        bool unusable; //!< Whether the @ref orxonox::Pickupable "Pickupable" is droppable.
    6866        uint32_t representationObjectId; //!< The objectId of the @ref orxonox::PickupRepresentation "PickupRepresentation" that represents the @ref orxonox::Pickupable "Pickupable".
     67        std::string representationName; //!< The name of the associated PickupRepresentation
    6968    };
    7069    // tolua_end
     
    7473        The PickupManager class manages @ref orxonox::Pickupable "Pickupables".
    7574
    76         It has in essence two tasks to fulfill. Firstly it must link @ref orxonox::Pickupable "Pickupables" (through their @ref orxonox::PickupIdentifier "PickupIdentifiers") to their respective @ref orxonox::PickupRepresentation "PickupRepresentations". Secondly it manages the PickupInventory. (The PickupInventory is the GUI that displays @ref orxonox::Pickupable "Pickupables" for the covenience of the user.)
     75        It has in essence two tasks to fulfill. Firstly it must link @ref orxonox::Pickupable "Pickupables" (through their representation-name attribute) to the respective @ref orxonox::PickupRepresentation "PickupRepresentations". Secondly it manages the PickupInventory. (The PickupInventory is the GUI that displays @ref orxonox::Pickupable "Pickupables" for the covenience of the user.)
    7776
    7877        @section PickupManagerTechnicalDetails Technical details
     
    8685
    8786        Firstly there are a number of lists (where by list I really mean any kind of ordered data structure) kept.
    88         - The @ref orxonox::PickupManager::representations_ "representations_" list links @ref orxonox::PickupRepresentation "PickupRepresentations" with @ref orxonox::PickupIdentifier "PickupIdentifiers" and can be used to get the @ref orxonox::PickupRepresentation "PickupRepresentation" for a given @ref orxonox::Pickupable "Pickupable". It is only populated on the server (or in standalone mode). Each @ref orxonox::PickupRepresentation "PickupRepresentation" that is generated through XML registers itself with the PickupManager and is thereby added to the list.
    89         - The @ref orxonox::PickupManager::representationsNetworked_ "representationsNetworked_" list is the networked (hence the name) equivalent to the @ref orxonox::PickupManager::representations_ "representations_" list. It links an objectId of a @ref orxonox::PickupRepresentation "PickupRepresentation" to a @ref orxonox::PickupRepresentation "PickupRepresentation". This list is maintained on all hosts, each representation registers itself (in its constructor) with the PickupManager. Since the representations are synchronised they are created on each host. The "same" instance on each host is identified by the same objectId and that is why we store the representations with the objectId as key. We can then use this list to get a @ref orxonox::PickupRepresentation "PickupRepresentation" for a specific @ref orxonox::Pickupable "Pickupable" (or more precisely a number identifiying that particular pickup, but we'll see that, when we look at the next list) on a client to be used in the PickupInventory.
     87        - The @ref orxonox::PickupManager::representations_ "representations_" list links @ref orxonox::PickupRepresentation "PickupRepresentations" with its name and can be used to get the @ref orxonox::PickupRepresentation "PickupRepresentation" for a given @ref orxonox::Pickupable "Pickupable". It is only populated on the server (or in standalone mode). Each @ref orxonox::PickupRepresentation "PickupRepresentation" that is generated through XML registers itself with the PickupManager and is thereby added to the list.
    9088        - The @ref orxonox::PickupManager::pickupInventoryContainers_ "pickupInventoryContainers_" list links a number identifying a @ref orxonox::Pickupable "Pickupable" to a data structure (the @ref orxonox::PickupInventoryContainer "PickupInventoryContainer"), which contains all necessary information about that @ref orxonox::Pickupable "Pickupable". This list is maintained on all hosts, a new container is inserted when a @ref orxonox::Pickupable "Pickupable" is picked up, but only if it has been picked up by the repsective host. This list is then used by the PickupInventory to access the required information and to get the correct @ref orxonox::PickupRepresentation "PickupRepresentation".
    9189        - The @ref orxonox::PickupManager::pickups_ "pickups_" list links a number identifiying a @ref orxonox::Pickupable "Pickupable" to a (weak pointer to a) @ref orxonox::Pickupable "Pickupable". It is only maintained by the server (or in standalone mode), to be able to use, unuse and drop @ref orxonox::Pickupable "Pickupables" through the PickupInventory. Since @ref orxonox::Pickupable "Pickupables" only exist on the server a client that wants to change a pickups status has so send a request over the network (with the number identifying the pickup) to the server and then the server facilitates the change, using this list to map from the identifyer to the actual @ref orxonox::Pickupable "Pickupable".
     
    114112            static PickupManager& getInstance() { return Singleton<PickupManager>::getInstance(); } // tolua_export
    115113
    116             bool registerRepresentation(const PickupIdentifier* identifier, PickupRepresentation* representation); //!< Registers a PickupRepresentation together with the PickupIdentifier of the Pickupable the PickupRepresentation represents.
    117             bool unregisterRepresentation(const PickupIdentifier* identifier, PickupRepresentation* representation); //!< Unegisters a PickupRepresentation together with the PickupIdentifier of the Pickupable the PickupRepresentation represents.
     114            bool registerRepresentation(const std::string& name, PickupRepresentation* representation);
     115            bool unregisterRepresentation(const std::string& name);
    118116
    119             bool registerRepresentation(PickupRepresentation* representation); //!< Registers a PickupRepresentation on the host it was created.
    120             bool unregisterRepresentation(PickupRepresentation* representation); //!< Unregisters a PickupRepresentation on the host it is being destroyed.
    121 
    122             PickupRepresentation* getRepresentation(const PickupIdentifier* identifier); //!< Get the PickupRepresentation representing the Pickupable with the input PickupIdentifier.
     117            PickupRepresentation* getRepresentation(const std::string& name); // tolua_export
    123118
    124119            virtual void pickupChangedUsed(Pickupable* pickup, bool used); //!< Is called by the PickupListener to notify the PickupManager, that the input Pickupable has transited to the input used state.
    125120            static void pickupChangedUsedNetwork(uint32_t pickup, bool inUse, bool usable, bool unusable); //!< Helper method to react to the change in the used status of a Pickupable.
    126121            virtual void pickupChangedPickedUp(Pickupable* pickup, bool pickedUp); //!< Is called by the PickupListener to notify the PickupManager, that the input Pickupable has transited to the input pickedUp state.
    127             static void pickupChangedPickedUpNetwork(uint32_t pickup, bool usable, uint32_t representationObjectId, bool pickedUp); //!< Helper method to react to the change in the pickedUp status of a Pickupable.
     122            static void pickupChangedPickedUpNetwork(uint32_t pickup, bool usable, uint32_t representationObjectId, const std::string& representationName, bool pickedUp); //!< Helper method to react to the change in the pickedUp status of a Pickupable.
    128123
    129124        // Methods to be used by the PickupInventory.
    130125        public:
    131126            // tolua_begin
    132             orxonox::PickupRepresentation* getPickupRepresentation(uint32_t pickup); //!< Get the PickupRepresentation of an input indentifier for Pickupable.
    133 
    134127            int getNumPickups(void); //!< Get the number of pickups currently picked up by the player.
    135128            /**
     
    163156            PickupRepresentation* defaultRepresentation_; //!< The default PickupRepresentation.
    164157
    165             std::map<const PickupIdentifier*, PickupRepresentation*, PickupIdentifierCompare> representations_; //!< Map linking PickupIdentifiers (representing types of Pickupables) and PickupRepresentations.
    166             std::map<uint32_t, PickupRepresentation*> representationsNetworked_; //!< Map linking the PickupRepresentation's objectId to the PickupRepresentation itself. It is used for networking purposes.
     158            std::map<std::string, PickupRepresentation*> representations_; //!< Map linking PickupRepresentations and their names.
    167159
    168160            std::map<uint32_t, PickupInventoryContainer*> pickupInventoryContainers_; //!< Map linking a number identifying a Pickupable to a PickupInventoryContainer, which contains all necessary information about that Pickupable.
  • code/trunk/src/modules/pickup/PickupPrereqs.h

    r8706 r9348  
    7070
    7171    class CollectiblePickup;
    72     class DroppedPickup;
    7372    class Pickup;
    7473    class PickupCollection;
    75     class PickupCollectionIdentifier;
    7674    class PickupManager;
    7775    class PickupRepresentation;
     
    8684    class ShieldPickup;
    8785    class ShrinkPickup;
    88 
     86    class DamageBoostPickup;
    8987}
    9088
  • code/trunk/src/modules/pickup/PickupRepresentation.cc

    r8858 r9348  
    5252        This is primarily for use of the PickupManager in creating a default PickupRepresentation.
    5353    */
    54     PickupRepresentation::PickupRepresentation() : BaseObject(NULL), Synchronisable(NULL), spawnerRepresentation_(NULL), pickup_(NULL)
     54    PickupRepresentation::PickupRepresentation() : BaseObject(NULL), Synchronisable(NULL), spawnerRepresentation_(NULL)
    5555    {
    5656        RegisterObject(PickupRepresentation);
     
    6464        Default Constructor. Registers the object and initializes its member variables.
    6565    */
    66     PickupRepresentation::PickupRepresentation(BaseObject* creator) : BaseObject(creator), Synchronisable(creator), spawnerRepresentation_(NULL), pickup_(NULL)
     66    PickupRepresentation::PickupRepresentation(BaseObject* creator) : BaseObject(creator), Synchronisable(creator), spawnerRepresentation_(NULL)
    6767    {
    6868        RegisterObject(PickupRepresentation);
     
    7070        this->initialize();
    7171        this->registerVariables();
    72 
    73         PickupManager::getInstance().registerRepresentation(this); // Registers the PickupRepresentation with the PickupManager.
    7472    }
    7573
     
    8482
    8583        if(this->isInitialized())
    86         {
    87             if(GameMode::isMaster() && this->pickup_ != NULL)
    88             {
    89                 PickupManager::getInstance().unregisterRepresentation(this->pickup_->getPickupIdentifier(), this);
    90             }
    91             PickupManager::getInstance().unregisterRepresentation(this);
    92         }
     84            PickupManager::getInstance().unregisterRepresentation(this->getName());
    9385    }
    9486
     
    128120        XMLPortParam(PickupRepresentation, "spawnerTemplate", setSpawnerTemplate, getSpawnerTemplate, xmlelement, mode);
    129121        XMLPortParam(PickupRepresentation, "inventoryRepresentation", setInventoryRepresentation, getInventoryRepresentation, xmlelement, mode);
    130         XMLPortObject(PickupRepresentation, Pickupable, "pickup", setPickup, getPickup, xmlelement, mode);
    131122        XMLPortObject(PickupRepresentation, StaticEntity, "spawner-representation", setSpawnerRepresentation, getSpawnerRepresentationIndex, xmlelement, mode);
    132 
    133         if(GameMode::isMaster())
    134         {
    135             // Registers the PickupRepresentation with the PickupManager through the PickupIdentifier of the Pickupable it represents.
    136             PickupManager::getInstance().registerRepresentation(this->pickup_->getPickupIdentifier(), this);
    137         }
    138 
    139         if(this->spawnerRepresentation_ != NULL)
    140             this->spawnerRepresentation_->setVisible(false);
    141123
    142124        orxout(verbose, context::pickups) << "PickupRepresentation created: name: '" << this->name_ << "', description: '" << this->description_ << "', spawnerTemplate: '" << this->spawnerTemplate_ << "'." << endl;
     
    151133        Returns a pointer to the StaticEntity.
    152134    */
    153     StaticEntity* PickupRepresentation::getSpawnerRepresentation(PickupSpawner* spawner)
     135    StaticEntity* PickupRepresentation::createSpawnerRepresentation(PickupSpawner* spawner)
    154136    {
    155137        if(this->spawnerRepresentation_ == NULL)
     
    158140            if(this->spawnerTemplate_ == "")
    159141            {
    160                 orxout(verbose, context::pickups) << "PickupRepresentation: Spawner template is empty." << endl;
     142                orxout(internal_warning, context::pickups) << "PickupRepresentation: Spawner template is empty." << endl;
    161143                // If neither spawnerRepresentation nor spawnerTemplate was specified
    162144                return this->getDefaultSpawnerRepresentation(spawner);
     
    165147        }
    166148
    167         StaticEntity* representation = this->spawnerRepresentation_;
    168         representation->setVisible(true);
     149        this->spawnerRepresentation_->setVisible(true);
     150        StaticEntity* temp = this->spawnerRepresentation_;
     151        this->spawnerRepresentation_ = NULL;
    169152
    170         this->addTemplate(this->spawnerTemplate_);
    171         this->spawnerRepresentation_->setVisible(false);
     153        return temp;
     154    }
    172155
    173         return representation;
     156    void PickupRepresentation::changedName()
     157    {
     158        // Registers the PickupRepresentation with the PickupManager.
     159        PickupManager::getInstance().unregisterRepresentation(this->getOldName());
     160        PickupManager::getInstance().registerRepresentation(this->getName(), this);
     161    }
     162
     163    void PickupRepresentation::setSpawnerRepresentation(StaticEntity* representation)
     164    {
     165        this->spawnerRepresentation_ = representation;
     166        if(this->spawnerRepresentation_ != NULL)
     167            this->spawnerRepresentation_->setVisible(false);
    174168    }
    175169
  • code/trunk/src/modules/pickup/PickupRepresentation.h

    r7547 r9348  
    4141
    4242#include "interfaces/Pickupable.h"
    43 #include "pickup/PickupIdentifier.h"
    4443#include "worldentities/StaticEntity.h"
    4544
     
    5453    /**
    5554    @brief
    56         The PickupRepresentation class represents a specific pickup type (identified by its @ref orxonox::PickupIdentifier "PickupIdentifier"). It defines the information displayed in the GUI (PickupInventory) and how @ref orxonox::PickupSpawner "PickupSpawners" that spawn the pickup type look like.
     55        The PickupRepresentation class represents a specific pickup type. It defines the information displayed in the GUI (PickupInventory) and how @ref orxonox::PickupSpawner "PickupSpawners" that spawn the pickup type look like.
    5756        They are created through XML and are registered with the @ref orxonox::PickupManager "PickupManager".
    5857
     
    6463            spawnerTemplate = "awesomePickupRepresentation"
    6564            inventoryRepresentation = "AwesomePickup"
    66         >
    67             <pickup>
    68                 <SomePickup />
    69             </pickup>
    70         </PickupRepresentation>
     65        />
    7166        @endcode
    7267        As you might have noticed, there is a parameter called <em>spawnerTemplate</em> and also another parameter called <em>inventoryRepresentation</em>. Let's first explain the second one, <em>inventoryRepresentation</em>.
     
    133128            */
    134129            inline const std::string& getInventoryRepresentation(void) const { return this->inventoryRepresentation_; } // tolua_export
    135             /**
    136             @brief Get the Pickupable represented by this PickupRepresentation.
    137             @param index The index.
    138             @return Returns (for index = 0) a pointer to the Pickupable. For index > 0 it returns NULL.
    139             */
    140             inline const Pickupable* getPickup(unsigned int index) const
    141                 { if(index == 0) return this->pickup_; return NULL; }
    142130
    143             StaticEntity* getSpawnerRepresentation(PickupSpawner* spawner); //!< Get a spawnerRepresentation for a specific PickupSpawner.
     131            virtual void changedName();
     132
     133            StaticEntity* createSpawnerRepresentation(PickupSpawner* spawner); //!< Create a spawnerRepresentation for a specific PickupSpawner.
    144134
    145135        protected:
     
    168158            @param representation A pointer to the StaticEntity that is the spawnerRepresentation of this PickupRepresentation.
    169159            */
    170             inline void setSpawnerRepresentation(StaticEntity* representation)
    171                 { this->spawnerRepresentation_ = representation; }
     160            void setSpawnerRepresentation(StaticEntity* representation);
     161
    172162            /**
    173163            @brief Set the image representing the pickup in the PickupInventory.
     
    176166            inline void setInventoryRepresentation(const std::string& image)
    177167                { this->inventoryRepresentation_ = image; }
    178             /**
    179             @brief Set the Pickupable that is represented by this PickupRepresentation.
    180             @param pickup A pointer to the Pickupable.
    181             */
    182             inline void setPickup(Pickupable* pickup)
    183                 { this->pickup_ = pickup; }
    184168
    185169        private:
     
    195179            std::string inventoryRepresentation_; //!< The name of an image representing the pickup in the PickupInventory.
    196180
    197             Pickupable* pickup_; //!< The Pickupable that is represented by this PickupRepresentation.
    198 
    199181    }; // tolua_export
    200182
  • code/trunk/src/modules/pickup/PickupSpawner.cc

    r8891 r9348  
    5555        Pointer to the object which created this item.
    5656    */
    57     PickupSpawner::PickupSpawner(BaseObject* creator) : StaticEntity(creator), pickup_(NULL)
     57    PickupSpawner::PickupSpawner(BaseObject* creator) : StaticEntity(creator), pickup_(NULL), representation_(NULL), pickupTemplate_(NULL)
    5858    {
    5959        RegisterObject(PickupSpawner);
    6060
    6161        this->initialize();
    62     }
    63 
    64     /**
    65     @brief
    66         Constructor, Creates a fully functional PickupSpawner.
    67     @param creator
    68         The creator of this PickupSpawner.
    69     @param pickup
    70         The Pickupable to be spawned by this PickupSpawner.
    71     @param triggerDistance
    72         The distance at which the PickupSpawner will trigger.
    73     @param respawnTime
    74         The minimum time between two spawns.
    75     @param maxSpawnedItems
    76         The maximum number of items spawned by this PickupSpawner.
    77     */
    78     PickupSpawner::PickupSpawner(BaseObject* creator, Pickupable* pickup, float triggerDistance, float respawnTime, int maxSpawnedItems) : StaticEntity(creator), pickup_(NULL)
    79     {
    80         RegisterObject(PickupSpawner);
    81 
    82         this->initialize();
    83 
    84         this->pickup_ = pickup;
    85 
    86         this->triggerDistance_ = triggerDistance;
    87         this->respawnTime_ = respawnTime;
    88         this->setMaxSpawnedItems(maxSpawnedItems);
    89 
    90         if(this->pickup_ == NULL)
    91         {
    92             orxout(internal_warning, context::pickups) << "A PickupSpawner was created without a valid Pickupable. This won't work." << endl;
    93             this->setActive(false);
    94         }
    95         else
    96         {
    97             PickupRepresentation* representation = PickupManager::getInstance().getRepresentation(this->pickup_->getPickupIdentifier());
    98             this->attach(representation->getSpawnerRepresentation(this));
    99             this->setActive(true);
    100         }
    10162    }
    10263
     
    11273        this->spawnsRemaining_ = INF;
    11374        this->selfDestruct_ = false;
     75
     76        this->setPickupable(NULL);
    11477    }
    11578
     
    12285        if(this->isInitialized() && this->selfDestruct_ && this->pickup_ != NULL)
    12386            this->pickup_->destroy();
     87    }
     88
     89    /**
     90    @brief
     91        Factory method, Creates a fully functional PickupSpawner.
     92    @param creator
     93        The creator of this PickupSpawner.
     94    @param pickup
     95        The Pickupable to be spawned by this PickupSpawner.
     96    @param carrier
     97        The PickupCarrier that carried the input pickup before it was dropped.
     98    @param triggerDistance
     99        The distance at which the PickupSpawner will trigger.
     100    */
     101    /*static*/ PickupSpawner* PickupSpawner::createDroppedPickup(BaseObject* creator, Pickupable* pickup, PickupCarrier* carrier, float triggerDistance)
     102    {
     103        PickupSpawner* spawner = new PickupSpawner(creator);
     104
     105        spawner->setPickupable(pickup);
     106        spawner->setTriggerDistance(triggerDistance);
     107        spawner->setMaxSpawnedItems(1);
     108
     109        spawner->setPosition(carrier->getCarrierPosition());
     110        spawner->block(carrier);
     111
     112        return spawner;
    124113    }
    125114
     
    136125        SUPER(PickupSpawner, XMLPort, xmlelement, mode);
    137126
    138         XMLPortObject(PickupSpawner, Pickupable, "pickup", setPickupable, getPickupable, xmlelement, mode);
    139 
     127        XMLPortParam(PickupSpawner, "pickup", setPickupTemplateName, getPickupTemplateName, xmlelement, mode);
    140128        XMLPortParam(PickupSpawner, "triggerDistance", setTriggerDistance, getTriggerDistance, xmlelement, mode);
    141129        XMLPortParam(PickupSpawner, "respawnTime", setRespawnTime, getRespawnTime, xmlelement, mode);
    142130        XMLPortParam(PickupSpawner, "maxSpawnedItems", setMaxSpawnedItems, getMaxSpawnedItems, xmlelement, mode);
    143 
    144         if(this->pickup_ == NULL)
    145         {
    146             orxout(internal_warning, context::pickups) << "A PickupSpawner was created without a valid Pickupable. This won't work." << endl;
    147             this->setActive(false);
    148         }
    149         else
    150         {
    151             PickupRepresentation* representation = PickupManager::getInstance().getRepresentation(this->pickup_->getPickupIdentifier());
    152             this->attach(representation->getSpawnerRepresentation(this));
    153             this->setActive(true);
    154         }
    155     }
    156 
    157     /**
    158     @brief
    159         Invoked when the activity has changed. Sets visibility of attached objects.
    160     */
    161     void PickupSpawner::changedActivity()
    162     {
    163         SUPER(PickupSpawner, changedActivity);
    164 
    165         if(GameMode::isMaster())
    166             this->setVisible(this->isActive());
    167131    }
    168132
     
    199163
    200164                Vector3 distance = it->getWorldPosition() - this->getWorldPosition();
    201                 PickupCarrier* carrier = dynamic_cast<PickupCarrier*>(*it);
     165                PickupCarrier* carrier = static_cast<PickupCarrier*>(*it);
    202166                // If a PickupCarrier, that fits the target-range of the Pickupable spawned by this PickupSpawner, is in trigger-distance and the carrier is not blocked.
    203167                if(distance.length() < this->triggerDistance_ && carrier != NULL && this->blocked_.find(carrier) == this->blocked_.end())
     
    212176    /**
    213177    @brief
     178        Trigger the PickupSpawner.
     179        Adds the pickup to the Pawn that triggered, sets the timer to re-activate and deactives the PickupSpawner.
     180    @param carrier
     181        Carrier which triggered the PickupSpawner.
     182    */
     183    void PickupSpawner::trigger(PickupCarrier* carrier)
     184    {
     185        orxout(verbose, context::pickups) << "PickupSpawner (&" << this << ") triggered and active." << endl;
     186
     187        PickupCarrier* target = carrier->getTarget(this->pickup_);
     188
     189        this->block(carrier);
     190
     191        assert(target);
     192        bool pickedUp = this->pickup_->pickup(target);
     193        assert(pickedUp);
     194        pickedUp = false; // To avoid compiler warning.
     195
     196        this->setPickupable(NULL);
     197        this->decrementSpawnsRemaining();
     198    }
     199
     200    void PickupSpawner::setPickupTemplateName(const std::string& name)
     201    {
     202        Template* temp = Template::getTemplate(name);
     203        if (temp)
     204            this->setPickupTemplate(temp);
     205    }
     206
     207    void PickupSpawner::setPickupTemplate(Template* temp)
     208    {
     209        this->pickupTemplate_ = temp;
     210        this->pickupTemplateName_ = temp->getName();
     211
     212        this->setPickupable(this->createPickup());
     213    }
     214
     215    /**
     216    @brief
    214217        Sets the maximum number of spawned items.
    215218    @param items
     
    233236            this->spawnsRemaining_--;
    234237
     238        this->setActive(false);
     239
    235240        if(this->spawnsRemaining_ != 0 && this->respawnTime_ > 0)
    236241        {
    237242            this->startRespawnTimer();
    238 
    239             this->setActive(false);
    240243            this->fireEvent();
    241244        }
     
    243246        {
    244247            orxout(verbose, context::pickups) << "PickupSpawner (&" << this << ") empty, selfdestruct initialized." << endl;
    245             this->setActive(false);
    246248            this->destroy();
    247249        }
     
    255257    {
    256258        this->respawnTimer_.setTimer(this->respawnTime_, false, createExecutor(createFunctor(&PickupSpawner::respawnTimerCallback, this)));
     259    }
     260
     261    /**
     262    @brief
     263        Invoked by the timer, re-activates the PickupSpawner.
     264    */
     265    void PickupSpawner::respawnTimerCallback()
     266    {
     267        orxout(verbose, context::pickups) << "PickupSpawner (&" << this << ") reactivated." << endl;
     268
     269        this->setPickupable(this->createPickup());
     270    }
     271
     272    /**
     273    @brief
     274        Creates a new Pickupable.
     275    @return
     276        The Pickupable created.
     277    */
     278    Pickupable* PickupSpawner::createPickup(void)
     279    {
     280        if(this->spawnsRemaining_ == 0)
     281        {
     282            orxout(internal_error, context::pickups) << "Massive Error: PickupSpawner still alive until having spawned last item." << endl;
     283            return NULL;
     284        }
     285
     286        if (this->pickupTemplate_ != NULL)
     287        {
     288            Identifier* identifier = this->pickupTemplate_->getBaseclassIdentifier();
     289            if (identifier != NULL)
     290            {
     291                Pickupable* pickup = orxonox_cast<Pickupable*>(identifier->fabricate(this));
     292                orxonox_cast<BaseObject*>(pickup)->addTemplate(this->pickupTemplate_);
     293                return pickup;
     294            }
     295            else
     296                orxout(internal_error, context::pickups) << "No base class defined in pickup-template " << this->pickupTemplateName_ << endl;
     297        }
     298
     299        return NULL;
    257300    }
    258301
     
    265308    void PickupSpawner::setPickupable(Pickupable* pickup)
    266309    {
    267         if(this->pickup_ != NULL)
    268         {
    269             orxout(internal_error, context::pickups) << "In PickupSpawner (&" << this << "): setPickupable called, with this->pickup_ already set." << endl;
    270             return;
    271         }
    272         if(pickup == NULL)
    273         {
    274             orxout(internal_error, context::pickups) << "In PickupSpawner (&" << this << "): Argument of setPickupable is NULL." << endl;
    275             return;
     310        if (this->representation_ != NULL)
     311        {
     312            this->representation_->destroy();
     313            this->representation_ = NULL;
     314        }
     315
     316        if (pickup != NULL)
     317        {
     318            if (this->pickup_ != NULL)
     319                this->pickup_->destroy();
     320
     321            PickupRepresentation* representation = PickupManager::getInstance().getRepresentation(pickup->getRepresentationName());
     322            this->representation_ = representation->createSpawnerRepresentation(this);
     323            this->attach(this->representation_);
     324            this->setActive(true);
     325        }
     326        else
     327        {
     328            this->setActive(false);
    276329        }
    277330
    278331        this->pickup_ = pickup;
    279332    }
    280 
    281     /**
    282     @brief
    283         Get the Pickupable that is spawned by this PickupSpawner.
    284     @return
    285         Returns the Pickupable that is spawned by this PickupSpawner.
    286     */
    287     const Pickupable* PickupSpawner::getPickupable(void) const
    288     {
    289         return this->pickup_;
    290     }
    291 
    292     /**
    293     @brief
    294         Trigger the PickupSpawner.
    295         Adds the pickup to the Pawn that triggered, sets the timer to re-activate and deactives the PickupSpawner.
    296     @param pawn
    297         Pawn which triggered the PickupSpawner.
    298     */
    299     void PickupSpawner::trigger(Pawn* pawn)
    300     {
    301         if(this->isActive()) // Checks whether PickupSpawner is active.
    302         {
    303             orxout(verbose, context::pickups) << "PickupSpawner (&" << this << ") triggered and active." << endl;
    304 
    305             PickupCarrier* carrier = dynamic_cast<PickupCarrier*>(pawn);
    306             assert(carrier);
    307 
    308             // If the Pawn isn't a target of the Pickupable.
    309             if(!carrier->isTarget(this->pickup_))
    310             {
    311                 orxout(verbose, context::pickups) << "PickupSpawner (&" << this << ") triggered but Pawn wasn't a target of the Pickupable." << endl;
    312                 return;
    313             }
    314 
    315             PickupCarrier* target = carrier->getTarget(this->pickup_);
    316             Pickupable* pickup = this->getPickup();
    317 
    318             this->block(carrier);
    319 
    320             assert(pickup);
    321             assert(target);
    322             bool pickedUp = pickup->pickup(target);
    323             assert(pickedUp);
    324             pickedUp = false; // To avoid compiler warning.
    325 
    326             this->decrementSpawnsRemaining();
    327         }
    328     }
    329 
    330     /**
    331     @brief
    332         Creates a new Pickupable.
    333     @return
    334         The Pickupable created.
    335     */
    336     Pickupable* PickupSpawner::getPickup(void)
    337     {
    338         if(this->spawnsRemaining_ == 0)
    339         {
    340             orxout(internal_error, context::pickups) << "Massive Error: PickupSpawner still alive until having spawned last item." << endl;
    341             return NULL;
    342         }
    343 
    344         Pickupable* pickup = this->pickup_->clone();
    345         return pickup;
    346     }
    347 
    348     /**
    349     @brief
    350         Invoked by the timer, re-activates the PickupSpawner.
    351     */
    352     void PickupSpawner::respawnTimerCallback()
    353     {
    354         orxout(verbose, context::pickups) << "PickupSpawner (&" << this << ") reactivated." << endl;
    355 
    356         this->setActive(true);
    357     }
    358333}
  • code/trunk/src/modules/pickup/PickupSpawner.h

    r7549 r9348  
    7878        public:
    7979            PickupSpawner(BaseObject* creator); //!< Default Constructor.
    80             PickupSpawner(BaseObject* creator, Pickupable* pickup, float triggerDistance, float respawnTime, int maxSpawnedItems); //!< Constructor.
    8180            virtual ~PickupSpawner(); //!< Destructor.
    8281
     82            static PickupSpawner* createDroppedPickup(BaseObject* creator, Pickupable* pickup, PickupCarrier* carrier, float triggerDistance = 10.0);
     83
    8384            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);  //!< Method for creating a PickupSpawner through XML.
    84             virtual void changedActivity(); //!< Invoked when activity has changed (set visibilty).
    8585            virtual void tick(float dt); //!< Tick, checks if any Pawn is close enough to trigger.
    8686
     
    103103            inline int getMaxSpawnedItems(void) const
    104104                { return this->maxSpawnedItems_; }
     105            /**
     106            @brief Returns the name of the template which is used to create a pickup for this spawner.
     107            */
     108            inline const std::string& getPickupTemplateName() const
     109                { return this->pickupTemplateName_; }
     110            /**
     111            @brief Returns the template which is used to create a pickup for this spawner.
     112            */
     113            inline Template* getPickupTemplate() const
     114                {return this->pickupTemplate_; }
    105115
    106         protected:
     116        private:
     117            void initialize(void);
     118
     119            void trigger(PickupCarrier* carrier); //!< Method called when a carrier is close enough.
     120            void respawnTimerCallback(); //!< Method called when the timer runs out.
     121
    107122            void decrementSpawnsRemaining(void); //!< Decrements the number of remaining spawns.
    108123            void startRespawnTimer(void); //!< Invoked by the timer, re-activates the PickupSpawner.
     
    128143            inline void setRespawnTime(float time)
    129144                { this->respawnTime_ = time; }
     145
    130146            void setMaxSpawnedItems(int items); //!< Sets the maximum number of spawned items.
    131147
    132             virtual Pickupable* getPickup(void); //!< Creates a new Pickupable.
     148            void setPickupTemplateName(const std::string& name);
     149            void setPickupTemplate(Template* temp);
    133150
     151            Pickupable* createPickup(void); //!< Creates a new Pickupable.
    134152            void setPickupable(Pickupable* pickup); //!< Sets a Pickupable for the PickupSpawner to spawn.
    135             const Pickupable* getPickupable(void) const; //!< Get the Pickupable that is spawned by this PickupSpawner.
    136153
    137154            Pickupable* pickup_; //!< The pickup to be spawned.
    138 
    139         private:
    140             void initialize(void);
    141 
    142             void trigger(Pawn* pawn); //!< Method called when a Pawn is close enough.
    143             void respawnTimerCallback(); //!< Method called when the timer runs out.
     155            StaticEntity* representation_; //!< The active representation of the spawner.
     156            std::string pickupTemplateName_; //!< The name of the pickup template.
     157            Template* pickupTemplate_; //!< The template to be used to create a pickupable.
    144158
    145159            int maxSpawnedItems_; //!< Maximum number of items spawned by this PickupSpawner.
  • code/trunk/src/modules/pickup/items/CMakeLists.txt

    r8706 r9348  
    77  ShieldPickup.cc
    88  ShrinkPickup.cc
     9  DamageBoostPickup.cc
    910)
  • code/trunk/src/modules/pickup/items/DronePickup.cc

    r8858 r9348  
    3939
    4040#include "controllers/DroneController.h"
    41 #include "pickup/PickupIdentifier.h"
    4241#include "worldentities/Drone.h"
    4342#include "worldentities/pawns/Pawn.h"
     
    7574    {
    7675        this->addTarget(ClassIdentifier<Pawn>::getIdentifier());
    77         this->setDurationTypeDirect(pickupDurationType::once);
     76        this->setDurationType(pickupDurationType::once);
    7877        this->droneTemplate_ = "";
    79     }
    80 
    81     /**
    82     @brief
    83         Initializes the PickupIdentifier of this pickup.
    84     */
    85     void DronePickup::initializeIdentifier(void)
    86     {
    87         std::string val = this->getDroneTemplate();
    88         std::string type = "droneTemplate";
    89         this->pickupIdentifier_->addParameter(type, val);
    9078    }
    9179
     
    9886        SUPER(DronePickup, XMLPort, xmlelement, mode);
    9987        XMLPortParam(DronePickup, "droneTemplate", setDroneTemplate, getDroneTemplate, xmlelement, mode);
    100 
    101         this->initializeIdentifier();
    10288    }
    10389
     
    10894        The name of the Template to e set.
    10995    */
    110     void DronePickup::setDroneTemplate(std::string templatename){
     96    void DronePickup::setDroneTemplate(const std::string& templatename){
    11197        droneTemplate_ = templatename;
    11298    }
     
    144130
    145131                Controller* controller = drone->getController();
    146                 DroneController* droneController = dynamic_cast<DroneController*>(controller);
     132                DroneController* droneController = orxonox_cast<DroneController*>(controller);
    147133                if(droneController != NULL)
    148134                {
     
    175161    {
    176162        PickupCarrier* carrier = this->getCarrier();
    177         Pawn* pawn = dynamic_cast<Pawn*>(carrier);
     163        Pawn* pawn = orxonox_cast<Pawn*>(carrier);
    178164
    179165        if(pawn == NULL)
     
    184170        return pawn;
    185171    }
    186 
    187     /**
    188     @brief
    189         Creates a duplicate of the input OrxonoxClass.
    190     @param item
    191         A pointer to the Orxonox class.
    192     */
    193     void DronePickup::clone(OrxonoxClass*& item)
    194     {
    195         if(item == NULL)
    196             item = new DronePickup(this);
    197 
    198         SUPER(DronePickup, clone, item);
    199 
    200         DronePickup* pickup = dynamic_cast<DronePickup*>(item);
    201         pickup->setDroneTemplate(this->getDroneTemplate());
    202 
    203         pickup->initializeIdentifier();
    204     }
    205172}
  • code/trunk/src/modules/pickup/items/DronePickup.h

    r7547 r9348  
    7070
    7171            virtual void changedUsed(void); //!< Is called when the pickup has transited from used to unused or the other way around.
    72             virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the input OrxonoxClass.
    7372
    7473            const std::string& getDroneTemplate() const; //!< Get the name of the droneTemplate.
    7574
    7675        protected:
    77             void initializeIdentifier(void); //!< Initializes the PickupIdentifier of this pickup.
    78 
    79             void setDroneTemplate(std::string templatename); //!< Set the droneTemplate.
     76            void setDroneTemplate(const std::string& templatename); //!< Set the droneTemplate.
    8077
    8178        private:
  • code/trunk/src/modules/pickup/items/HealthPickup.cc

    r8864 r9348  
    3838#include "core/XMLPort.h"
    3939
    40 #include "pickup/PickupIdentifier.h"
    4140#include "worldentities/pawns/Pawn.h"
    4241
     
    8786    /**
    8887    @brief
    89         Initializes the PickupIdentifier of this pickup.
    90     */
    91     void HealthPickup::initializeIdentifier(void)
    92     {
    93         std::stringstream stream;
    94         stream << this->getHealth();
    95         std::string type1 = "health";
    96         std::string val1 = stream.str();
    97         this->pickupIdentifier_->addParameter(type1, val1);
    98 
    99         std::string val2 = this->getHealthType();
    100         std::string type2 = "healthType";
    101         this->pickupIdentifier_->addParameter(type2, val2);
    102 
    103         stream.clear();
    104         stream << this->getHealthRate();
    105         std::string val3 = stream.str();
    106         std::string type3 = "healthRate";
    107         this->pickupIdentifier_->addParameter(type3, val3);
    108     }
    109 
    110     /**
    111     @brief
    11288        Method for creating a HealthPickup object through XML.
    11389    */
     
    11894        XMLPortParam(HealthPickup, "health", setHealth, getHealth, xmlelement, mode);
    11995        XMLPortParam(HealthPickup, "healthRate", setHealthRate, getHealthRate, xmlelement, mode);
    120         XMLPortParam(HealthPickup, "healthType", setHealthType, getHealthType, xmlelement, mode);
     96        XMLPortParam(HealthPickup, "healthType", setHealthTypeAsString, getHealthTypeAsString, xmlelement, mode);
    12197
    12298        if(!this->isContinuous())
    123             this->healthRate_ = 0.0f;
    124 
    125         this->initializeIdentifier();
     99            this->setHealthRate(0.0f); // TODO: this logic should be inside tick(), not in XMLPort
    126100    }
    127101
     
    151125            this->setHealth(this->getHealth()-health);
    152126
    153             switch(this->getHealthTypeDirect())
     127            switch(this->getHealthType())
    154128            {
    155129                case pickupHealthType::permanent:
     
    198172
    199173                float health = 0.0f;
    200                 switch(this->getHealthTypeDirect())
     174                switch(this->getHealthType())
    201175                {
    202176                    case pickupHealthType::permanent:
     
    227201        else
    228202        {
    229             if(this->getHealthTypeDirect() == pickupHealthType::temporary)
     203            if(this->getHealthType() == pickupHealthType::temporary)
    230204            {
    231205                PickupCarrier* carrier = this->getCarrier();
    232                 Pawn* pawn = dynamic_cast<Pawn*>(carrier);
     206                Pawn* pawn = orxonox_cast<Pawn*>(carrier);
    233207
    234208                if(pawn == NULL)
     
    264238    {
    265239        PickupCarrier* carrier = this->getCarrier();
    266         Pawn* pawn = dynamic_cast<Pawn*>(carrier);
     240        Pawn* pawn = orxonox_cast<Pawn*>(carrier);
    267241
    268242        if(pawn == NULL)
     
    270244
    271245        return pawn;
    272     }
    273 
    274     /**
    275     @brief
    276         Creates a duplicate of the input OrxonoxClass.
    277     @param item
    278         A pointer to the Orxonox class.
    279     */
    280     void HealthPickup::clone(OrxonoxClass*& item)
    281     {
    282         if(item == NULL)
    283             item = new HealthPickup(this);
    284 
    285         SUPER(HealthPickup, clone, item);
    286 
    287         HealthPickup* pickup = dynamic_cast<HealthPickup*>(item);
    288         pickup->setHealth(this->getHealth());
    289         pickup->setHealthRate(this->getHealthRate());
    290         pickup->setHealthTypeDirect(this->getHealthTypeDirect());
    291 
    292         pickup->initializeIdentifier();
    293246    }
    294247
     
    299252        Returns the health type as a string.
    300253    */
    301     const std::string& HealthPickup::getHealthType(void) const
    302     {
    303         switch(this->getHealthTypeDirect())
     254    const std::string& HealthPickup::getHealthTypeAsString(void) const
     255    {
     256        switch(this->getHealthType())
    304257        {
    305258            case pickupHealthType::limited:
     
    352305        The type as a string.
    353306    */
    354     void HealthPickup::setHealthType(std::string type)
     307    void HealthPickup::setHealthTypeAsString(const std::string& type)
    355308    {
    356309        if(type == HealthPickup::healthTypeLimited_s)
    357             this->setHealthTypeDirect(pickupHealthType::limited);
     310            this->setHealthType(pickupHealthType::limited);
    358311        else if(type == HealthPickup::healthTypeTemporary_s)
    359             this->setHealthTypeDirect(pickupHealthType::temporary);
     312            this->setHealthType(pickupHealthType::temporary);
    360313        else if(type == HealthPickup::healthTypePermanent_s)
    361             this->setHealthTypeDirect(pickupHealthType::permanent);
     314            this->setHealthType(pickupHealthType::permanent);
    362315        else
    363316            orxout(internal_error, context::pickups) << "Invalid healthType '" << type << "' in HealthPickup." << endl;
  • code/trunk/src/modules/pickup/items/HealthPickup.h

    r7551 r9348  
    9797
    9898            virtual void changedUsed(void); //!< Is called when the pickup has transited from used to unused or the other way around.
    99             virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the input OrxonoxClass.
    10099
    101100            /**
     
    116115            @return Returns the health type as an enum.
    117116            */
    118             inline pickupHealthType::Value getHealthTypeDirect(void) const
     117            inline pickupHealthType::Value getHealthType(void) const
    119118                { return this->healthType_; }
    120             const std::string& getHealthType(void) const; //!< Get the health type of this pickup.
     119            const std::string& getHealthTypeAsString(void) const; //!< Get the health type of this pickup.
    121120
    122121        protected:
    123             void initializeIdentifier(void); //!< Initializes the PickupIdentifier of this pickup.
    124 
    125122            void setHealth(float health); //!< Sets the health.
    126123            void setHealthRate(float speed); //!< Set the rate at which health is transferred if the pickup is continuous.
     
    130127            @param type The type of this pickup as an enum.
    131128            */
    132             inline void setHealthTypeDirect(pickupHealthType::Value type)
     129            inline void setHealthType(pickupHealthType::Value type)
    133130                { this->healthType_ = type; }
    134             void setHealthType(std::string type); //!< Set the type of the HealthPickup.
     131            void setHealthTypeAsString(const std::string& type); //!< Set the type of the HealthPickup.
    135132
    136133        private:
  • code/trunk/src/modules/pickup/items/InvisiblePickup.cc

    r8858 r9348  
    4040#include "core/XMLPort.h"
    4141
    42 #include "pickup/PickupIdentifier.h"
    4342#include "worldentities/pawns/Pawn.h"
    4443
     
    7978    /**
    8079    @brief
    81         Initializes the PickupIdentifier of this pickup.
    82     */
    83     void InvisiblePickup::initializeIdentifier(void)
    84     {
    85         std::stringstream stream;
    86         stream << this->getDuration();
    87         std::string type1 = "duration";
    88         std::string val1 = stream.str();
    89         this->pickupIdentifier_->addParameter(type1, val1);
    90     }
    91 
    92     /**
    93     @brief
    9480        Method for creating a HealthPickup object through XML.
    9581    */
     
    9884        SUPER(InvisiblePickup, XMLPort, xmlelement, mode);
    9985        XMLPortParam(InvisiblePickup, "duration", setDuration, getDuration, xmlelement, mode);
    100 
    101         this->initializeIdentifier();
    10286    }
    10387
     
    148132    /**
    149133    @brief
    150         Creates a duplicate of the input OrxonoxClass.
    151     @param item
    152         A pointer to the Orxonox class.
    153     */
    154     void InvisiblePickup::clone(OrxonoxClass*& item)
    155     {
    156         if(item == NULL)
    157             item = new InvisiblePickup(this);
    158 
    159         SUPER(InvisiblePickup, clone, item);
    160 
    161         InvisiblePickup* pickup = dynamic_cast<InvisiblePickup*>(item);
    162         pickup->setDuration(this->getDuration());
    163         pickup->initializeIdentifier();
    164     }
    165 
    166     /**
    167     @brief
    168134        Sets the invisibility.
    169135    @param invisibility
     
    202168    {
    203169        PickupCarrier* carrier = this->getCarrier();
    204         Pawn* pawn = dynamic_cast<Pawn*>(carrier);
     170        Pawn* pawn = orxonox_cast<Pawn*>(carrier);
    205171
    206172        if(pawn == NULL)
  • code/trunk/src/modules/pickup/items/InvisiblePickup.h

    r7547 r9348  
    7272            InvisiblePickup(BaseObject* creator); //!< Constructor.
    7373            virtual ~InvisiblePickup(); //!< Destructor.
    74            
     74
    7575            virtual void XMLPort(Element& xmlelement, orxonox::XMLPort::Mode mode); //!< Method for creating a HealthPickup object through XML.
    7676            virtual void changedUsed(void); //!< Is called when the pickup has transited from used to unused or the other way around.
    77             virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the input OrxonoxClass.
    7877
    7978            /**
     
    9190
    9291        protected:
    93             void initializeIdentifier(void); //!< Initializes the PickupIdentifier of this pickup.
    94 
    9592            bool setInvisible(bool invisibility); //!< Set the Pawn to be invisible or visible again.
    9693            void setDuration(float duration); //!< Sets the time the InvisibilityPickup will last.
  • code/trunk/src/modules/pickup/items/MetaPickup.cc

    r8858 r9348  
    3636
    3737#include "interfaces/PickupCarrier.h"
    38 #include "pickup/PickupIdentifier.h"
    3938#include "worldentities/pawns/Pawn.h"
    4039
     
    8079        this->addTarget(ClassIdentifier<PickupCarrier>::getIdentifier());
    8180
    82         this->setDurationTypeDirect(pickupDurationType::once);
     81        this->setDurationType(pickupDurationType::once);
    8382        this->metaType_ = pickupMetaType::none;
    8483    }
     
    8685    /**
    8786    @brief
    88         Helper method to initialize the PickupIdentifier.
    89     */
    90     void MetaPickup::initializeIdentifier(void)
    91     {
    92         std::string val = this->getMetaType();
    93         std::string type = "metaType";
    94         this->pickupIdentifier_->addParameter(type, val);
    95     }
    96 
    97     /**
    98     @brief
    9987        Method for creating a MetaPickup object through XML.
    10088    */
     
    10391        SUPER(MetaPickup, XMLPort, xmlelement, mode);
    10492
    105         XMLPortParam(MetaPickup, "metaType", setMetaType, getMetaType, xmlelement, mode);
    106 
    107         this->initializeIdentifier();
     93        XMLPortParam(MetaPickup, "metaType", setMetaTypeAsString, getMetaTypeAsString, xmlelement, mode);
    10894    }
    10995
     
    121107        {
    122108            PickupCarrier* carrier = this->getCarrier();
    123             if(this->getMetaTypeDirect() != pickupMetaType::none && carrier != NULL)
     109            if(this->getMetaType() != pickupMetaType::none && carrier != NULL)
    124110            {
    125111                // If the metaType is destroyCarrier, then the PickupCarrier is destroyed.
    126                 if(this->getMetaTypeDirect() == pickupMetaType::destroyCarrier)
     112                if(this->getMetaType() == pickupMetaType::destroyCarrier)
    127113                {
    128114                    Pawn* pawn = orxonox_cast<Pawn*>(carrier);
     
    139125
    140126                    // If the metaType is use, then the Pickupable is set to used.
    141                     if(this->getMetaTypeDirect() == pickupMetaType::use && !pickup->isUsed())
     127                    if(this->getMetaType() == pickupMetaType::use && !pickup->isUsed())
    142128                    {
    143129                        pickup->setUsed(true);
    144130                    }
    145131                    // If the metaType is drop, then the Pickupable is dropped.
    146                     else if(this->getMetaTypeDirect() == pickupMetaType::drop)
     132                    else if(this->getMetaType() == pickupMetaType::drop)
    147133                    {
    148134                        pickup->drop();
    149135                    }
    150136                    // If the metaType is destroy, then the Pickupable is destroyed.
    151                     else if(this->getMetaTypeDirect() == pickupMetaType::destroy)
     137                    else if(this->getMetaType() == pickupMetaType::destroy)
    152138                    {
    153139                        pickup->Pickupable::destroy();
     
    161147    /**
    162148    @brief
    163         Creates a duplicate of the input OrxonoxClass.
    164     @param item
    165         A pointer to the Orxonox class.
    166     */
    167     void MetaPickup::clone(OrxonoxClass*& item)
    168     {
    169         if(item == NULL)
    170             item = new MetaPickup(this);
    171 
    172         SUPER(MetaPickup, clone, item);
    173 
    174         MetaPickup* pickup = dynamic_cast<MetaPickup*>(item);
    175         pickup->setMetaTypeDirect(this->getMetaTypeDirect());
    176 
    177         pickup->initializeIdentifier();
    178     }
    179 
    180     /**
    181     @brief
    182149        Get the meta type of this MetaPickup.
    183150    @return
    184151        Returns a string with the meta type of the MetaPickup.
    185152    */
    186     const std::string& MetaPickup::getMetaType(void) const
    187     {
    188         switch(this->getMetaTypeDirect())
     153    const std::string& MetaPickup::getMetaTypeAsString(void) const
     154    {
     155        switch(this->getMetaType())
    189156        {
    190157            case pickupMetaType::none:
     
    209176        A string with the type to be set.
    210177    */
    211     void MetaPickup::setMetaType(const std::string& type)
     178    void MetaPickup::setMetaTypeAsString(const std::string& type)
    212179    {
    213180        if(type == MetaPickup::metaTypeNone_s)
    214181        {
    215             this->setMetaTypeDirect(pickupMetaType::none);
     182            this->setMetaType(pickupMetaType::none);
    216183        }
    217184        else if(type == MetaPickup::metaTypeUse_s)
    218185        {
    219             this->setMetaTypeDirect(pickupMetaType::use);
     186            this->setMetaType(pickupMetaType::use);
    220187        }
    221188        else if(type == MetaPickup::metaTypeDrop_s)
    222189        {
    223             this->setMetaTypeDirect(pickupMetaType::drop);
     190            this->setMetaType(pickupMetaType::drop);
    224191        }
    225192        else if(type == MetaPickup::metaTypeDestroy_s)
    226193        {
    227             this->setMetaTypeDirect(pickupMetaType::destroy);
     194            this->setMetaType(pickupMetaType::destroy);
    228195        }
    229196        else if(type == MetaPickup::metaTypeDestroyCarrier_s)
    230197        {
    231             this->setMetaTypeDirect(pickupMetaType::destroyCarrier);
     198            this->setMetaType(pickupMetaType::destroyCarrier);
    232199        }
    233200        else
  • code/trunk/src/modules/pickup/items/MetaPickup.h

    r7547 r9348  
    6969
    7070        The default value is <em>none</em>, which basically does nothing.
    71        
     71
    7272        The parameter <b>activation type</b> can be used to specify, whether the MetaPickup is used upon pickup (<em>immediate</em>) or not (<em>onUse</em>). With <em>immediate</em> being the default.
    7373
     
    9595
    9696            virtual void changedUsed(void); //!< Is called when the pickup has transited from used to unused or the other way around.
    97             virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the input OrxonoxClass.
    9897
    9998            /**
     
    101100            @return Returns an enum with the meta type of the MetaPickup.
    102101            */
    103             inline pickupMetaType::Value getMetaTypeDirect(void) const
     102            inline pickupMetaType::Value getMetaType(void) const
    104103                { return this->metaType_; }
    105             const std::string& getMetaType(void) const; //!< Get the meta type of this MetaPickup.
     104            const std::string& getMetaTypeAsString(void) const; //!< Get the meta type of this MetaPickup.
    106105
    107106        protected:
    108             void initializeIdentifier(void); //!< Initializes the PickupIdentifier of this pickup.
    109 
    110107            /**
    111108            @brief Set the meta type of the MetaPickup.
    112109            @param type The meta type as an enum.
    113110            */
    114             inline void setMetaTypeDirect(pickupMetaType::Value type)
     111            inline void setMetaType(pickupMetaType::Value type)
    115112                { this->metaType_ =  type; }
    116             void setMetaType(const std::string& type); //!< Set the meta type of this MetaPickup.
     113            void setMetaTypeAsString(const std::string& type); //!< Set the meta type of this MetaPickup.
    117114
    118115        private:
  • code/trunk/src/modules/pickup/items/ShieldPickup.cc

    r8858 r9348  
    3838#include "core/XMLPort.h"
    3939
    40 #include "pickup/PickupIdentifier.h"
    4140#include "worldentities/pawns/Pawn.h"
    4241
     
    8079    /**
    8180    @brief
    82         Initializes the PickupIdentifier of this pickup.
    83     */
    84     void ShieldPickup::initializeIdentifier(void)
    85     {
    86         std::stringstream stream;
    87         stream << this->getDuration();
    88         std::string type1 = "duration";
    89         std::string val1 = stream.str();
    90         this->pickupIdentifier_->addParameter(type1, val1);
    91 
    92         stream.clear();
    93         stream << this->getShieldHealth();
    94         std::string type2 = "ShieldHealth";
    95         std::string val2 = stream.str();
    96         this->pickupIdentifier_->addParameter(type2, val2);
    97 
    98         stream.clear();
    99         stream << this->getShieldAbsorption();
    100         std::string type3 = "ShieldAbsorption";
    101         std::string val3 = stream.str();
    102         this->pickupIdentifier_->addParameter(type3, val3);
    103 
    104     }
    105 
    106     /**
    107     @brief
    10881        Method for creating a ShieldPickup object through XML.
    10982    */
     
    11588        XMLPortParam(ShieldPickup, "shieldabsorption", setShieldAbsorption, getShieldAbsorption, xmlelement, mode);
    11689        XMLPortParam(ShieldPickup, "duration", setDuration, getDuration, xmlelement, mode);
    117 
    118         this->initializeIdentifier();
    11990    }
    12091
     
    177148    {
    178149        PickupCarrier* carrier = this->getCarrier();
    179         Pawn* pawn = dynamic_cast<Pawn*>(carrier);
     150        Pawn* pawn = orxonox_cast<Pawn*>(carrier);
    180151
    181152        if(pawn == NULL)
     
    184155        }
    185156        return pawn;
    186     }
    187 
    188     /**
    189     @brief
    190         Creates a duplicate of the input OrxonoxClass.
    191     @param item
    192         A pointer to the Orxonox class.
    193     */
    194     void ShieldPickup::clone(OrxonoxClass*& item)
    195     {
    196         if(item == NULL)
    197             item = new ShieldPickup(this);
    198 
    199         SUPER(ShieldPickup, clone, item);
    200 
    201         ShieldPickup* pickup = dynamic_cast<ShieldPickup*>(item);
    202         pickup->setDuration(this->getDuration());
    203         pickup->setShieldAbsorption(this->getShieldAbsorption());
    204         pickup->setShieldHealth(this->getShieldHealth());
    205         pickup->initializeIdentifier();
    206157    }
    207158
  • code/trunk/src/modules/pickup/items/ShieldPickup.h

    r7547 r9348  
    8282
    8383            virtual void changedUsed(void); //!< Is called when the pickup has transited from used to unused or the other way around.
    84             virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the input OrxonoxClass.
    8584
    8685            /**
     
    104103
    105104        protected:
    106             void initializeIdentifier(void); //!< Initializes the PickupIdentifier of this pickup.
    107105            void pickupTimerCallback(void); //!< Helper method. Is called by the Timer as soon as it expires.
    108106
  • code/trunk/src/modules/pickup/items/ShrinkPickup.cc

    r8713 r9348  
    4040#include "core/XMLPort.h"
    4141
    42 #include "pickup/PickupIdentifier.h"
    4342#include "worldentities/pawns/Pawn.h"
    4443
     
    8180    }
    8281
    83     void ShrinkPickup::initializeIdentifier(void)
    84     {
    85         std::stringstream stream;
    86         stream << this->getShrinkFactor();
    87         std::string type1 = "shrinkFactor";
    88         std::string val1 = stream.str();
    89         this->pickupIdentifier_->addParameter(type1, val1);
    90 
    91         stream.clear();
    92         stream << this->getDuration();
    93         std::string val2 = stream.str();
    94         std::string type2 = "duration";
    95         this->pickupIdentifier_->addParameter(type2, val2);
    96 
    97         stream.clear();
    98         stream << this->getShrinkDuration();
    99         std::string val3 = stream.str();
    100         std::string type3 = "shrinkDuration";
    101         this->pickupIdentifier_->addParameter(type3, val3);
    102     }
    103 
    10482   /**
    10583    @brief
     
    11391        XMLPortParam(ShrinkPickup, "duration", setDuration, getDuration, xmlelement, mode);
    11492        XMLPortParam(ShrinkPickup, "shrinkDuration", setShrinkDuration, getShrinkDuration, xmlelement, mode);
    115 
    116         this->initializeIdentifier();
     93    }
     94
     95    /**
     96    @brief Sets the shrinking factor.
     97    @param factor The factor, needs to greater than 1.
     98    */
     99    void ShrinkPickup::setShrinkFactor(float factor)
     100    {
     101        if(factor <= 1.0f)
     102        {
     103            orxout(internal_warning, context::pickups) << "Invalid shrinking factor in ShrinkPickup. Ignoring.." << endl;
     104            return;
     105        }
     106        this->shrinkFactor_ = factor;
     107    }
     108
     109    /**
     110    @brief Set the duration for which the ship remains shrunken.
     111    @param duration The duration, needs to be non-negative.
     112    */
     113    void ShrinkPickup::setDuration(float duration)
     114    {
     115        if(duration < 0.0f)
     116        {
     117            orxout(internal_warning, context::pickups) << "Invalid duration in ShrinkPickup. Ignoring.." << endl;
     118            return;
     119        }
     120        this->duration_ = duration;
     121    }
     122
     123    /**
     124    @brief Set the shrink duration.
     125    @param speed The shrink duration, needs to be positive.
     126    */
     127    void ShrinkPickup::setShrinkDuration(float speed)
     128    {
     129        if(speed <= 0.0f)
     130        {
     131            orxout(internal_warning, context::pickups) << "Invalid shrink duration in ShrinkPickup. Ignoring.." << endl;
     132            return;
     133        }
     134        this->shrinkDuration_ = speed;
    117135    }
    118136
     
    148166    {
    149167        SUPER(ShrinkPickup, changedPickedUp);
    150        
     168
    151169        if(!this->isPickedUp() && this->isActive_)
    152170        {
     
    271289
    272290                bool destroy = false;
    273                
     291
    274292                // Stop shrinking if the desired size is reached.
    275293                if(this->timeRemainig_ <= 0.0f)
     
    314332    {
    315333        PickupCarrier* carrier = this->getCarrier();
    316         Pawn* pawn = dynamic_cast<Pawn*>(carrier);
     334        Pawn* pawn = orxonox_cast<Pawn*>(carrier);
    317335
    318336        return pawn;
    319337    }
    320 
    321     /**
    322     @brief
    323         Creates a duplicate of the input OrxonoxClass.
    324     @param item
    325         A pointer to the Orxonox class.
    326     */
    327     void ShrinkPickup::clone(OrxonoxClass*& item)
    328     {
    329         if(item == NULL)
    330             item = new ShrinkPickup(this);
    331 
    332         SUPER(ShrinkPickup, clone, item);
    333         ShrinkPickup* pickup = dynamic_cast<ShrinkPickup*>(item);
    334         pickup->setShrinkFactor(this->getShrinkFactor());
    335         pickup->setDuration(this->getDuration());
    336         pickup->setShrinkDuration(this->getShrinkDuration());
    337 
    338         pickup->initializeIdentifier();
    339     }
    340338}
  • code/trunk/src/modules/pickup/items/ShrinkPickup.h

    r8858 r9348  
    8080            virtual void changedUsed(void); // Is called when the pickup has transited from used to unused or the other way around.
    8181            virtual void changedPickedUp(void);
    82             virtual void clone(OrxonoxClass*& item); // Creates a duplicate of the input OrxonoxClass.
    8382
    8483            /**
     
    8887            inline float getShrinkFactor(void) const
    8988                { return this->shrinkFactor_; }
    90             /**
    91             @brief Sets the shrinking factor.
    92             @param factor The factor, needs to greater than 1.
    93             */
    94             inline void setShrinkFactor(float factor)
    95                 { if(factor <= 1.0f) { orxout(internal_warning, context::pickups) << "Invalid shrinking factor in ShrinkPickup. Ignoring.." << endl; return; } this->shrinkFactor_ = factor; }
     89            void setShrinkFactor(float factor);
     90
    9691            /**
    9792            @brief Get the duration for which the ship remains shrunken.
     
    10095            inline float getDuration(void) const
    10196                { return this->duration_; }
    102             /**
    103             @brief Set the duration for which the ship remains shrunken.
    104             @param duration The duration, needs to be non-negative.
    105             */
    106             inline void setDuration(float duration)
    107                 { if(duration < 0.0f) { orxout(internal_warning, context::pickups) << "Invalid duration in ShrinkPickup. Ignoring.." << endl; return; } this->duration_ = duration; }
     97            void setDuration(float duration);
     98
    10899            /**
    109100            @brief Get the shrink speed.
     
    112103            inline float getShrinkDuration(void) const
    113104                { return this->shrinkDuration_; }
    114             /**
    115             @brief Set the shrink duration.
    116             @param speed The shrink duration, needs to be positive.
    117             */
    118             inline void setShrinkDuration(float speed)
    119                 { if(speed <= 0.0f) { orxout(internal_warning, context::pickups) << "Invalid shrink duration in ShrinkPickup. Ignoring.." << endl; return; } this->shrinkDuration_ = speed; }
    120 
    121         protected:
    122             void initializeIdentifier(void);
     105            void setShrinkDuration(float speed);
    123106
    124107        private:
     
    135118            float currentFactor_;       //!< The shrink factor that is currently applied.
    136119            float timeRemainig_;        //!< The remaining shrink time.
    137            
     120
    138121            Pawn* carrierToPawnHelper(void);
    139122            Timer durationTimer_;
  • code/trunk/src/modules/pickup/items/SpeedPickup.cc

    r8858 r9348  
    3838#include "core/XMLPort.h"
    3939
    40 #include "pickup/PickupIdentifier.h"
    4140#include "worldentities/pawns/SpaceShip.h"
    4241
     
    8079    /**
    8180    @brief
    82         Initializes the PickupIdentifier of this pickup.
    83     */
    84     void SpeedPickup::initializeIdentifier(void)
    85     {
    86         std::stringstream stream;
    87         stream << this->getDuration();
    88         std::string type1 = "duration";
    89         std::string val1 = stream.str();
    90         this->pickupIdentifier_->addParameter(type1, val1);
    91 
    92         stream.clear();
    93         stream << this->getSpeedAdd();
    94         std::string type2 = "speedAdd";
    95         std::string val2 = stream.str();
    96         this->pickupIdentifier_->addParameter(type2, val2);
    97 
    98         stream.clear();
    99         stream << this->getSpeedMultiply();
    100         std::string type3 = "speedMultiply";
    101         std::string val3 = stream.str();
    102         this->pickupIdentifier_->addParameter(type3, val3);
    103     }
    104 
    105     /**
    106     @brief
    10781        Method for creating a SpeedPickup object through XML.
    10882    */
     
    11488        XMLPortParam(SpeedPickup, "speedAdd", setSpeedAdd, getSpeedAdd, xmlelement, mode);
    11589        XMLPortParam(SpeedPickup, "speedMultiply", setSpeedMultiply, getSpeedMultiply, xmlelement, mode);
    116 
    117         this->initializeIdentifier();
    11890    }
    11991
     
    176148    {
    177149        PickupCarrier* carrier = this->getCarrier();
    178         SpaceShip* ship = dynamic_cast<SpaceShip*>(carrier);
     150        SpaceShip* ship = orxonox_cast<SpaceShip*>(carrier);
    179151
    180152        if(ship == NULL)
     
    184156
    185157        return ship;
    186     }
    187 
    188     /**
    189     @brief
    190         Creates a duplicate of the input OrxonoxClass.
    191     @param item
    192         A pointer to the Orxonox class.
    193     */
    194     void SpeedPickup::clone(OrxonoxClass*& item)
    195     {
    196         if(item == NULL)
    197             item = new SpeedPickup(this);
    198 
    199         SUPER(SpeedPickup, clone, item);
    200 
    201         SpeedPickup* pickup = dynamic_cast<SpeedPickup*>(item);
    202         pickup->setDuration(this->getDuration());
    203         pickup->setSpeedAdd(this->getSpeedAdd());
    204         pickup->setSpeedMultiply(this->getSpeedMultiply());
    205 
    206         pickup->initializeIdentifier();
    207158    }
    208159
  • code/trunk/src/modules/pickup/items/SpeedPickup.h

    r8727 r9348  
    8181
    8282            virtual void changedUsed(void); //!< Is called when the pickup has transited from used to unused or the other way around.
    83             virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the input OrxonoxClass.
    8483
    8584            /**
     
    103102
    104103        protected:
    105             void initializeIdentifier(void); //!< Initializes the PickupIdentifier of this pickup.
    106104            void pickupTimerCallback(void); //!< Function that gets called when timer ends.
    107105
     
    112110        private:
    113111            void initialize(void); //!< Initializes the member variables.
    114             SpaceShip* carrierToSpaceShipHelper(void); //!< Helper to transform the PickupCarrier to a SpaceSHip, and throw an error message if the conversion fails.
     112            SpaceShip* carrierToSpaceShipHelper(void); //!< Helper to transform the PickupCarrier to a SpaceShip, and throw an error message if the conversion fails.
    115113
    116114            Timer durationTimer_; //!< Timer.
  • code/trunk/src/modules/pong/Pong.cc

    r9258 r9348  
    256256        Is called when the player scored.
    257257    */
    258     void Pong::playerScored(PlayerInfo* player)
    259     {
    260         Deathmatch::playerScored(player);
     258    void Pong::playerScored(PlayerInfo* player, int score)
     259    {
     260        Deathmatch::playerScored(player, score);
    261261
    262262        if (this->center_ != NULL) // If there is a centerpoint.
  • code/trunk/src/modules/pong/Pong.h

    r9258 r9348  
    7373            virtual void spawnPlayer(PlayerInfo* player); //!< Spawns the input player.
    7474
    75             virtual void playerScored(PlayerInfo* player); //!< Is called when the player scored.
     75            virtual void playerScored(PlayerInfo* player, int score = 1); //!< Is called when the player scored.
    7676
    7777            /**
  • code/trunk/src/modules/tetris/CMakeLists.txt

    r8706 r9348  
    33  TetrisCenterpoint.cc
    44  TetrisStone.cc
     5  TetrisBrick.cc
     6  TetrisScore.cc
    57)
    68
     
    1012  LINK_LIBRARIES
    1113    orxonox
     14    overlays
    1215  SOURCE_FILES ${TETRIS_SRC_FILES}
    1316)
  • code/trunk/src/modules/tetris/Tetris.cc

    r8858 r9348  
    2323 *      ...
    2424 *   Co-authors:
    25  *      ...
    26  *
     25 *      Johannes Ritz
     26 *
     27 *
     28 *
     29 *
     30 *TASK c) end the game in a nicer way
     31 *TASK d) save the highscore
     32 *TASK e) eye candy
    2733 */
    2834
     
    4248#include "TetrisCenterpoint.h"
    4349#include "TetrisStone.h"
     50#include "TetrisBrick.h"
    4451#include "infos/PlayerInfo.h"
    4552
     
    5259    @brief
    5360        Constructor. Registers and initializes the object.
     61    @ingroup Tetris
    5462    */
    5563    Tetris::Tetris(BaseObject* creator) : Deathmatch(creator)
     
    5765        RegisterObject(Tetris);
    5866
    59         this->activeStone_ = NULL;
     67        this->activeBrick_ = 0;
    6068
    6169        // Pre-set the timer, but don't start it yet.
    62         this->starttimer_.setTimer(1.0, false, createExecutor(createFunctor(&Tetris::startStone, this)));
     70        this->starttimer_.setTimer(1.0, false, createExecutor(createFunctor(&Tetris::startBrick, this)));
    6371        this->starttimer_.stopTimer();
    6472
    6573        this->player_ = NULL;
     74        this->setHUDTemplate("TetrisHUD");
     75        this->futureBrick_ = 0;
    6676    }
    6777
     
    8292    void Tetris::cleanup()
    8393    {
    84 
     94        if (this->activeBrick_)
     95        {
     96            this->activeBrick_->destroy();
     97            this->activeBrick_ = 0;
     98        }
     99        if (this->futureBrick_)
     100        {
     101            this->futureBrick_->destroy();
     102            this->futureBrick_ = 0;
     103        }
     104
     105        for (std::list<SmartPtr<TetrisStone> >::iterator it = this->stones_.begin(); it != this->stones_.end(); ++it)
     106            (*it)->destroy();
     107        this->stones_.clear();
    85108    }
    86109
     
    89112        SUPER(Tetris, tick, dt);
    90113
    91         if(this->activeStone_ != NULL)
    92         {
    93             if(!this->isValidStonePosition(this->activeStone_, this->activeStone_->getPosition()))
    94             {
    95                 this->activeStone_->setVelocity(Vector3::ZERO);
    96                 this->createStone();
    97                 this->startStone();
     114        if((this->activeBrick_ != NULL)&&(!this->hasEnded()))
     115        {
     116            if(!this->isValidBrickPosition(this->activeBrick_))
     117            {
     118                for (unsigned int i = 0; i < this->activeBrick_->getNumberOfStones(); i++)
     119                    this->stones_.push_back(this->activeBrick_->getStone(i));
     120                this->activeBrick_->setVelocity(Vector3::ZERO);
     121                this->activeBrick_->releaseStones(this->center_);
     122                this->findFullRows();
     123                this->startBrick();
    98124            }
    99125        }
     
    109135            return false;
    110136
    111         for(std::vector<TetrisStone*>::const_iterator it = this->stones_.begin(); it != this->stones_.end(); ++it)
    112         {
    113             if(stone == *it)
    114                 continue;
    115 
     137        for(std::list<SmartPtr<TetrisStone> >::const_iterator it = this->stones_.begin(); it != this->stones_.end(); ++it)
     138        {
    116139            const Vector3& currentStonePosition = (*it)->getPosition(); //!< Saves the position of the currentStone
    117140
     
    123146    }
    124147
     148    /**
     149    @brief
     150        Check for each stone in a brick if it is moved the right way.
     151    */
     152    bool Tetris::isValidMove(TetrisBrick* brick, const Vector3& position, bool isRotation = false)
     153    {
     154        assert(brick);
     155
     156        for (unsigned int i = 0; i < brick->getNumberOfStones(); i++ )
     157        {
     158            TetrisStone* stone = brick->getStone(i);
     159            Vector3 stonePosition; //the current stone's offset to position
     160            if(isRotation)
     161                stonePosition = rotateVector(stone->getPosition(), brick->getRotationCount()+1);
     162            else
     163                stonePosition = rotateVector(stone->getPosition(), brick->getRotationCount());
     164
     165            if(! this->isValidMove(stone, position + stonePosition ))
     166            {
     167                return false;
     168            }
     169
     170            //catch illegal rotation (such that collisions with ground are not permitted)
     171            if(isRotation)
     172            {
     173                if((position + stonePosition).y < this->center_->getStoneSize()/2.0f) //!< If the stone has reached the bottom of the level
     174                {
     175                    return false;
     176                }
     177            }
     178        }
     179        return true;
     180
     181    }
     182
     183
     184
    125185    bool Tetris::isValidStonePosition(TetrisStone* stone, const Vector3& position)
    126186    {
    127187        assert(stone);
    128188
    129         // we use a reverse iterator because we have to check for collisions with the topmost stones first
    130         for(std::vector<TetrisStone*>::const_reverse_iterator it = this->stones_.rbegin(); it != this->stones_.rend(); ++it)
    131         {
    132             if(stone == *it)
     189        // check for collisions with all stones
     190        for(std::list<SmartPtr<TetrisStone> >::const_iterator it = this->stones_.begin(); it != this->stones_.end(); ++it)
     191        {
     192            //Vector3 currentStonePosition = rotateVector((*it)->getPosition(), this->activeBrick_->getRotationCount());
     193            const Vector3& currentStonePosition = (*it)->getPosition(); //!< Saves the position of the currentStone
     194            //!< Saves the position of the currentStone
     195
     196            //filter out cases where the falling stone is already below a steady stone
     197            if(position.y < currentStonePosition.y - this->center_->getStoneSize()/2.0f)
    133198                continue;
    134 
    135             const Vector3& currentStonePosition = (*it)->getPosition(); //!< Saves the position of the currentStone
    136 
    137199            if((position.x == currentStonePosition.x) && (position.y < currentStonePosition.y + this->center_->getStoneSize()))
    138200            {
    139                 this->activeStone_->setPosition(Vector3(this->activeStone_->getPosition().x, currentStonePosition.y+this->center_->getStoneSize(), this->activeStone_->getPosition().z));
     201                float y_offset = static_cast<int>((this->activeBrick_->getPosition().y-currentStonePosition.y+10)/10)*10 + currentStonePosition.y;
     202                if(y_offset < 0) //filter out extreme cases (very rare bug)
     203                    y_offset = 0;
     204                this->activeBrick_->setPosition(Vector3(this->activeBrick_->getPosition().x, y_offset, this->activeBrick_->getPosition().z));
    140205                return false;
    141206            }// This case applies if the stones overlap partially vertically
     
    145210        if(position.y < this->center_->getStoneSize()/2.0f) //!< If the stone has reached the bottom of the level
    146211        {
    147             stone->setPosition(Vector3(stone->getPosition().x, this->center_->getStoneSize()/2.0f, stone->getPosition().z));
     212            float yOffset = stone->getPosition().y + this->center_->getStoneSize()/2.0f;//calculate offset
     213            if(yOffset < 0) //catch brake-throughs
     214                yOffset = 0;
     215            this->activeBrick_->setPosition(Vector3(this->activeBrick_->getPosition().x, yOffset, this->activeBrick_->getPosition().z));
    148216            return false;
    149217        }
     
    151219        return true;
    152220    }
     221    /**
     222     * @brief This function determines wether a brick touches another brick or the ground.
     223     *
     224     */
     225    bool Tetris::isValidBrickPosition(TetrisBrick* brick)
     226    {
     227        assert(brick);
     228
     229        const Vector3& brickPosition = this->activeBrick_->getPosition();
     230
     231        // check all stones in the brick
     232        for (unsigned int i = 0; i < brick->getNumberOfStones(); i++ )
     233        {
     234            TetrisStone* stone = brick->getStone(i);
     235            const Vector3& stonePosition = rotateVector(stone->getPosition(), brick->getRotationCount());
     236            if(! this->isValidStonePosition(stone, brickPosition + stonePosition) )
     237            {
     238                // recurse because all stones have to checked again after the brick was re-positioned
     239                this->isValidBrickPosition(brick);
     240                return false;
     241            }
     242        }
     243        return true;
     244    }
     245
     246    /**
     247    @brief
     248        A Vector3 is rolled 90 * degrees * amount (anticlockwise rotation)
     249    */
     250    Vector3 Tetris::rotateVector(Vector3 position, unsigned int amount)
     251    {
     252        float temp = 0;
     253        for(unsigned int i = 0; i < amount; i++)
     254        {
     255            temp = position.x;
     256            position.x = -position.y;
     257            position.y = temp;
     258        }
     259        return position;
     260    }
    153261
    154262    /**
     
    160268        if (this->center_ != NULL) // There needs to be a TetrisCenterpoint, i.e. the area the game takes place.
    161269        {
    162             // Create the first stone.
    163             this->createStone();
     270            // Create the first brick.
     271            this->createBrick();
    164272        }
    165273        else // If no centerpoint was specified, an error is thrown and the level is exited.
     
    190298    void Tetris::end()
    191299    {
     300        this->activeBrick_->setVelocity(Vector3::ZERO);
     301        if(this->activeBrick_ != NULL)
     302        {
     303            this->player_->stopControl();
     304        }
     305
    192306        this->cleanup();
    193307
     
    225339    }
    226340
    227     /**
    228     @brief
    229         Starts the first stone.
    230     */
    231     void Tetris::startStone(void)
     341
     342
     343    void Tetris::startBrick(void)
    232344    {
    233345        if(this->player_ == NULL)
     
    235347
    236348        unsigned int cameraIndex = 0;
    237         if(this->activeStone_ != NULL)
     349        if(this->activeBrick_ != NULL)
    238350        {
    239351            // Get camera settings
    240             cameraIndex = this->activeStone_->getCurrentCameraIndex();
     352            cameraIndex = this->activeBrick_->getCurrentCameraIndex();
    241353            this->player_->stopControl();
    242         }
    243        
    244         // Make the last stone to be created the active stone.
    245         this->activeStone_ = this->stones_.back();
    246        
    247         this->player_->startControl(this->activeStone_);
    248         this->activeStone_->setVelocity(0.0f, -this->center_->getStoneSpeed(), 0.0f);
    249         this->activeStone_->setCameraPosition(cameraIndex);
    250     }
    251 
    252     /**
    253     @brief
    254         Creates a new stone.
    255     */
    256     void Tetris::createStone(void)
    257     {
    258         // Create a new stone and add it to the list of stones.
    259         TetrisStone* stone = new TetrisStone(this->center_);
    260         this->stones_.push_back(stone);
    261        
    262         // Apply the stone template to the stone.
    263         stone->addTemplate(this->center_->getStoneTemplate());
    264        
    265         // Attach the stone to the Centerpoint and set the position of the stone to be at the top middle.
    266         this->center_->attach(stone);
     354            // destroy old active brick
     355            this->activeBrick_->destroy();
     356        }
     357
     358        // Make the last brick to be created the active brick.
     359        this->activeBrick_ = this->futureBrick_;
     360        this->futureBrick_ = 0;
     361
     362        // set its position
     363        this->player_->startControl(this->activeBrick_);
    267364        float xPos = (this->center_->getWidth()/2 + ((this->center_->getWidth() % 2)*2-1)/2.0f)*this->center_->getStoneSize();
    268365        float yPos = (this->center_->getHeight()-0.5f)*this->center_->getStoneSize();
    269         stone->setPosition(xPos, yPos, 0.0f);
    270         stone->setGame(this);
    271     }
     366        this->activeBrick_->setPosition(xPos, yPos, 0.0f);
     367        this->activeBrick_->setVelocity(0.0f, -this->center_->getStoneSpeed(), 0.0f);
     368        this->activeBrick_->setCameraPosition(cameraIndex);
     369
     370        // create a new future brick
     371        this->createBrick();
     372
     373        // check if the new brick is in a valid position, otherwise end the game
     374        if (!this->isValidBrickPosition(this->activeBrick_))
     375            this->end();
     376    }
     377
     378    void Tetris::createBrick(void)             //TODO: random rotation offset between 0 and 3 (times 90°)
     379    {
     380        // create new futureBrick_
     381        this->futureBrick_ = new TetrisBrick(this->center_);
     382
     383
     384        // Apply the stone template to the stone.
     385        this->futureBrick_->addTemplate(this->center_->getBrickTemplate());
     386
     387        // Attach the brick to the Centerpoint and set the position of the brick to be at the left side.
     388        this->center_->attach(this->futureBrick_);
     389        float xPos = (this->center_->getWidth()*1.6f + ((this->center_->getWidth() % 2)*2-1)/2.0f)*this->center_->getStoneSize();
     390        float yPos = (this->center_->getHeight()-5.1f)*this->center_->getStoneSize();
     391        this->futureBrick_->setPosition(xPos, yPos, 0.0f);
     392        this->futureBrick_->setGame(this);
     393    }
     394
    272395
    273396    /**
     
    282405    }
    283406
     407    /*TetrisCenterpoint* Tetris::getCenterpoint(void) const
     408    {
     409        return this->center_;
     410    }*/
     411
    284412    /**
    285413    @brief Set the TetrisCenterpoint (the playing field).
     
    291419    }
    292420
     421    /**
     422    @brief Check each row if it is full. Removes all full rows. Update
     423    @brief Manages score.
     424    */
     425    void Tetris::findFullRows()
     426    {
     427        unsigned int correctPosition = 0;
     428        unsigned int stonesPerRow = 0;
     429        for (unsigned int row = 0; row < this->center_->getHeight(); row++)
     430        {
     431            stonesPerRow = 0;
     432            for(std::list<SmartPtr<TetrisStone> >::iterator it = this->stones_.begin(); it != this->stones_.end(); )
     433            {
     434                std::list<SmartPtr<TetrisStone> >::iterator it_temp = it++;
     435                correctPosition = static_cast<unsigned int>(((*it_temp)->getPosition().y - 5)/this->center_->getStoneSize());
     436                if(correctPosition == row)
     437                {
     438                    stonesPerRow++;
     439                    if(stonesPerRow == this->center_->getWidth())
     440                    {
     441                        clearRow(row);
     442                        row--; //the row counter has to be decreased in order to detect multiple rows!
     443                        this->playerScored(this->player_);// add points
     444                        //increase the stone's speed
     445                        this->center_->setStoneSpeed(this->center_->getStoneSpeed()+1.0f);
     446                    }
     447                }
     448            }
     449        }
     450    }
     451
     452    void Tetris::clearRow(unsigned int row)
     453    {// clear the full row
     454        for(std::list<SmartPtr<TetrisStone> >::iterator it = this->stones_.begin(); it != this->stones_.end(); )
     455        {
     456            if(static_cast<unsigned int>(((*it)->getPosition().y - 5)/this->center_->getStoneSize()) == row)
     457            {
     458                (*it)->destroy();
     459                this->stones_.erase(it++);
     460            }
     461            else
     462                ++it;
     463        }
     464      // adjust height of stones above the deleted row //TODO: check if this could be a source of a bug.
     465        for(std::list<SmartPtr<TetrisStone> >::iterator it = this->stones_.begin(); it != this->stones_.end(); ++it)
     466        {
     467            if(static_cast<unsigned int>(((*it)->getPosition().y - 5)/this->center_->getStoneSize()) > row)
     468                (*it)->setPosition((*it)->getPosition()-Vector3(0,10,0));
     469        }
     470
     471    }
     472
     473
    293474}
  • code/trunk/src/modules/tetris/Tetris.h

    r8706 r9348  
    5656        public:
    5757            Tetris(BaseObject* creator); //!< Constructor. Registers and initializes the object.
    58             virtual ~Tetris(); //!< Destructor. Cleans up, if initialized.           
     58            virtual ~Tetris(); //!< Destructor. Cleans up, if initialized.
    5959
    6060            virtual void start(void); //!< Starts the Tetris minigame.
     
    6868
    6969            PlayerInfo* getPlayer(void) const; //!< Get the player.
     70            WeakPtr<TetrisCenterpoint> getCenterpoint(void)
     71                { return this->center_; }
    7072
    7173            bool isValidMove(TetrisStone* stone, const Vector3& position);
     74            bool isValidMove(TetrisBrick* brick, const Vector3& position, bool isRotation);
     75            Vector3 rotateVector(Vector3 position, unsigned int amount);
    7276
    7377        protected:
    7478            virtual void spawnPlayersIfRequested(); //!< Spawns player.
    7579
     80
    7681        private:
    77             void startStone(void); //!< Starts with the first stone.
    78             void createStone(void);
     82            void startBrick(void);
     83            void createBrick(void);
    7984            void cleanup(void); //!< Cleans up the Gametype by destroying the ball and the bats.
    8085            bool isValidStonePosition(TetrisStone* stone, const Vector3& position);
    81            
     86            bool isValidBrickPosition(TetrisBrick* brick);
     87            void findFullRows(void);
     88            void clearRow(unsigned int row);
     89
     90
    8291            PlayerInfo* player_;
    8392
    8493            WeakPtr<TetrisCenterpoint> center_; //!< The playing field.
    85             std::vector<TetrisStone*> stones_; //!< A list of all stones in play.
    86             std::vector< std::vector<bool> > grid_;
    87             TetrisStone* activeStone_;
    88            
     94            std::list<SmartPtr<TetrisStone> > stones_; //!< A list of all stones in play.
     95            WeakPtr<TetrisBrick> activeBrick_;
     96            WeakPtr<TetrisBrick> futureBrick_;
     97
    8998            Timer starttimer_; //!< A timer to delay the start of the game.
    9099    };
  • code/trunk/src/modules/tetris/TetrisCenterpoint.cc

    r8706 r9348  
    3030    @file TetrisCenterpoint.cc
    3131    @brief Implementation of the TetrisCenterpoint class.
     32    @ingroup Tetris
    3233*/
    3334
     
    5556        this->stoneSize_ = 10.0f;
    5657        this->stoneTemplate_ = "";
     58        this->brickTemplate_ = "";
    5759        this->stoneSpeed_ = 20.0f;
    5860       
     
    6971
    7072        XMLPortParam(TetrisCenterpoint, "width", setWidth, getWidth, xmlelement, mode); // die Breite
    71         XMLPortParam(TetrisCenterpoint, "height", setHeight, setWidth, xmlelement, mode); // die Grösse
     73        XMLPortParam(TetrisCenterpoint, "height", setHeight, getHeight, xmlelement, mode); // die Grösse //was sollte das mit setWidth??
    7274        XMLPortParam(TetrisCenterpoint, "stoneSize", setStoneSize, getStoneSize, xmlelement, mode);
    7375        XMLPortParam(TetrisCenterpoint, "stoneTemplate", setStoneTemplate, getStoneTemplate, xmlelement, mode);
     76        XMLPortParam(TetrisCenterpoint, "brickTemplate", setBrickTemplate, getBrickTemplate, xmlelement, mode);
    7477        XMLPortParam(TetrisCenterpoint, "stoneSpeed", setStoneSpeed, getStoneSpeed, xmlelement, mode);
    7578    }
  • code/trunk/src/modules/tetris/TetrisCenterpoint.h

    r8706 r9348  
    4545
    4646namespace orxonox
    47 {
     47{//idea: add 2 triggers to the centerpoint (one to determine when a box would go above the centerpoint;
     48//the other to find out when the lowest row is filled totally)
    4849   
    4950    /**
     
    118119           
    119120            /**
     121            @brief Set the template for the bricks.
     122            @param template The template name to be applied to each brick.
     123            */
     124            void setBrickTemplate(const std::string& templateName)
     125                { this->brickTemplate_ = templateName; }
     126            /**
     127            @brief Get the template for the bricks.
     128            @return Returns the template name to be applied to each brick.
     129            */
     130            const std::string& getBrickTemplate(void) const
     131                { return this->brickTemplate_; }
     132
     133            /**
    120134            @brief Set the speed of the stones.
    121135            @param speed The speed to be set.
     
    137151            float stoneSize_;
    138152            std::string stoneTemplate_;
     153            std::string brickTemplate_;
    139154            float stoneSpeed_;
    140155
  • code/trunk/src/modules/tetris/TetrisPrereqs.h

    r8706 r9348  
    6868    class TetrisCenterpoint;
    6969    class TetrisStone;
     70    class TetrisBrick;
     71    class TetrisScore;
    7072}
    7173
  • code/trunk/src/modules/tetris/TetrisStone.cc

    r8706 r9348  
    3030    @file TetrisStone.cc
    3131    @brief Implementation of the TetrisStone class.
     32    @ingroup Tetris
    3233*/
    3334
     
    4748        Constructor. Registers and initializes the object.
    4849    */
    49     TetrisStone::TetrisStone(BaseObject* creator) : ControllableEntity(creator)
     50    TetrisStone::TetrisStone(BaseObject* creator) : MovableEntity(creator)
    5051    {
    5152        RegisterObject(TetrisStone);
    52        
     53
    5354        this->size_ = 10.0f;
    5455        this->delay_ = false;
    5556        this->delayTimer_.setTimer(0.2f, false, createExecutor(createFunctor(&TetrisStone::enableMovement, this)));
     57        this->lockRotation_ = false;
     58
    5659    }
    5760
     
    6467    void TetrisStone::moveFrontBack(const Vector2& value)
    6568    {
    66         if(value.x < 0)
     69        if(value.x < 0) //speedup on key down
    6770        {
    6871            this->setVelocity(this->getVelocity()*1.1);
     72        }
     73        else if(!this->lockRotation_) //rotate when key up is pressed
     74        {
     75            this->lockRotation_ = true; // multiple calls of this function have to be filtered out.
     76            this->rotationTimer_.setTimer(0.1f, false, createExecutor(createFunctor(&TetrisStone::unlockRotation, this)));
     77            Quaternion q(Degree(90), Vector3::UNIT_Z);
     78            this->setOrientation(this->getOrientation()*q); //rotation: roll 90°
     79
    6980        }
    7081    }
  • code/trunk/src/modules/tetris/TetrisStone.h

    r8706 r9348  
    3838#include "tetris/TetrisPrereqs.h"
    3939
    40 #include "worldentities/ControllableEntity.h"
     40#include "worldentities/MovableEntity.h"
    4141#include "tools/Timer.h"
    4242
     
    5151    @ingroup Tetris
    5252    */
    53     class _TetrisExport TetrisStone : public ControllableEntity
     53    class _TetrisExport TetrisStone : public MovableEntity
    5454    {
    5555        public:
     
    8181            void enableMovement(void)
    8282                { this->delay_ = false; }
    83            
     83            void unlockRotation(void)
     84                { this->lockRotation_ = false; }
     85
    8486            float size_; //!< The dimensions a stone has in the game world.
    8587            bool delay_;
     88            bool lockRotation_;
    8689            Timer delayTimer_;
     90            Timer rotationTimer_; ///!< This timer is used to filter out multiple rotation inputs.
    8791
    8892            Tetris* tetris_;
  • code/trunk/src/modules/weapons/RocketController.cc

    r8858 r9348  
    5353        this->rocket_ = new SimpleRocket(this);
    5454        this->rocket_->setController(this);
    55         this->setControllableEntity(dynamic_cast<ControllableEntity*> (this->rocket_));
     55        this->setControllableEntity(orxonox_cast<ControllableEntity*>(this->rocket_));
    5656    }
    5757
  • code/trunk/src/orxonox/CMakeLists.txt

    r8858 r9348  
    5050ADD_SUBDIRECTORY(items)
    5151ADD_SUBDIRECTORY(overlays)
    52 ADD_SUBDIRECTORY(pickup)
    5352ADD_SUBDIRECTORY(sound)
    5453ADD_SUBDIRECTORY(weaponsystem)
  • code/trunk/src/orxonox/CameraManager.cc

    r8079 r9348  
    4848    CameraManager::CameraManager()
    4949    {
     50        RegisterRootObject(CameraManager);
     51
    5052        assert(GameMode::showsGraphics());
    5153    }
  • code/trunk/src/orxonox/LevelInfo.cc

    r9016 r9348  
    4242
    4343    // LevelInfoItem
    44    
     44
    4545    //! The list of allowed tags.
    4646    /*static*/ std::set<std::string> LevelInfoItem::possibleTags_s = std::set<std::string>();
     
    9393            LevelInfoItem::possibleTags_s.insert("gametype");
    9494            LevelInfoItem::possibleTags_s.insert("minigame");
     95            LevelInfoItem::possibleTags_s.insert("shipselection");
    9596        }
    9697    }
     
    106107        SubString substr = SubString(tags, ",", " "); // Split the string into tags.
    107108        const std::vector<std::string>& strings = substr.getAllStrings();
     109        for (std::vector<std::string>::const_iterator it = strings.begin(); it != strings.end(); it++)
     110            this->addTag(*it, false);
     111
     112        this->tagsUpdated();
     113    }
     114    /**
     115    @brief
     116        Set the starting ship models of the level
     117    @param tags
     118        A comma-seperated string of all the allowed ship models for the shipselection.
     119    */
     120    void LevelInfoItem::setStartingShips(const std::string& ships)
     121    {
     122        SubString substr = SubString(ships, ",", " "); // Split the string into tags.
     123        const std::vector<std::string>& strings = substr.getAllStrings();
    108124        for(std::vector<std::string>::const_iterator it = strings.begin(); it != strings.end(); it++)
    109             this->addTag(*it, false);
    110 
    111         this->tagsUpdated();
     125            this->addStartingShip(*it, false);
     126
     127        this->startingshipsUpdated();
    112128    }
    113129
     
    137153    /**
    138154    @brief
     155        Add a ship model to allowed models for the shipselection
     156    @param ship
     157        The ship model to be added.
     158    @param update
     159        Whether the comma-seperated string of all ship models should be updated. Default is true.
     160    @return
     161        Returns true if the ship was successfully added, if the ship was already present it returns false.
     162    */
     163    bool LevelInfoItem::addStartingShip(const std::string& ship, bool update)
     164    {
     165        bool success = this->startingShips_.insert(ship).second;
     166        if(update && success)
     167            this->startingshipsUpdated();
     168
     169        return success;
     170    }
     171
     172
     173    /**
     174    @brief
    139175        Updates the comma-seperated string of all tags, if the set of tags has changed.
    140176    */
     
    155191    }
    156192
     193    /**
     194    @brief
     195        Updates the comma-seperated string of all ships, if the set of tags has changed.
     196    */
     197    void LevelInfoItem::startingshipsUpdated(void)
     198    {
     199        std::stringstream stream;
     200        std::set<std::string>::iterator temp;
     201        for(std::set<std::string>::iterator it = this->startingShips_.begin(); it != this->startingShips_.end(); )
     202        {
     203            temp = it;
     204            if(++it == this->startingShips_.end()) // If this is the last ship we don't add a comma.
     205                stream << *temp;
     206            else
     207                stream << *temp << ", ";
     208        }
     209
     210        this->startingShipsString_ = std::string(stream.str());
     211    }
     212
     213    void LevelInfoItem::changeStartingShip(const std::string& model)
     214    {
     215        static std::string shipSelectionTag = "shipselection";
     216        //HACK: Read Level XML File, find "shipselection", replace with ship model
     217        std::string levelPath = "../levels/";
     218        levelPath.append(this->getXMLFilename());
     219        std::string tempPath = "../levels/";
     220        tempPath.append("_temp.oxw");
     221        orxout(user_status) << levelPath << endl;
     222        orxout(user_status) << tempPath << endl;
     223        std::ifstream myLevel (levelPath.c_str());
     224        std::ofstream tempLevel (tempPath.c_str());
     225        while(!myLevel.eof())
     226        {
     227            std::string buff;
     228            std::getline(myLevel, buff);
     229            std::string pawndesignString = "pawndesign=";
     230            size_t found = buff.find(pawndesignString.append(shipSelectionTag));
     231            if (found!= std::string::npos)
     232                buff = buff.substr(0, found + 11) + model + buff.substr(found+11+shipSelectionTag.length(), std::string::npos);
     233            tempLevel.write(buff.c_str(), buff.length());
     234            tempLevel << std::endl;
     235        }
     236        myLevel.close();
     237        tempLevel.close();
     238        orxout(user_status) << "done" << endl;
     239    }
     240
     241
    157242    // LevelInfo
    158243
     
    192277        XMLPortParam(LevelInfo, "screenshot", setScreenshot, getScreenshot, xmlelement, mode);
    193278        XMLPortParam(LevelInfo, "tags", setTags, getTags, xmlelement, mode);
     279        XMLPortParam(LevelInfo, "startingships", setStartingShips, getStartingShips, xmlelement, mode);
    194280    }
    195281
     
    207293        info->setScreenshot(this->getScreenshot());
    208294        info->setTags(this->getTags());
     295        info->setStartingShips(this->getStartingShips());
    209296        return info;
    210297    }
  • code/trunk/src/orxonox/LevelInfo.h

    r9016 r9348  
    4343
    4444#include "core/BaseObject.h"
     45#include <iostream>
     46#include <fstream>
    4547#include "core/OrxonoxClass.h"
    4648
     
    7779            */
    7880            inline const std::string& getName(void) const { return this->name_; } // tolua_export
    79        
     81
    8082            /**
    8183            @brief Set the screenshot of the Level.
     
    116118            inline bool hasTag(const std::string& tag) const { return this->tags_.find(tag) != this->tags_.end(); } // tolua_export
    117119
     120            void setStartingShips(const std::string& ships); //!< Set the starting ship models of the level
     121            bool addStartingShip(const std::string& ship, bool update = true); //!< Add a model to shipselection
     122            /**
     123            @brief Get the set of starting ship models the Level allows
     124            @return Returns a comma-seperated string of all the allowed ship models for the shipselection.
     125            */
     126            inline const std::string& getStartingShips(void) const
     127                { return this->startingShipsString_; }
     128            /**
     129            @brief Get whether the Level allows a specific starting ship model
     130            @param ship The ship model for which is checked.
     131            @return Returns true if the Level allows the input ship model
     132            */
     133            inline bool hasStartingShip(const std::string& ship) const { return this->startingShips_.find(ship) != this->startingShips_.end(); } // tolua_export
     134            inline void selectStartingShip(const std::string& ship) { this->changeStartingShip(ship); } // tolua_export
    118135            /**
    119136            @brief Get the XML-filename of the Level.
     
    122139            inline const std::string& getXMLFilename(void) const { return this->xmlfilename_; } // tolua_export
    123140
     141
    124142        protected:
    125143            /**
     
    133151
    134152        private:
     153            void changeStartingShip (const std::string& model);
     154            void startingshipsUpdated(void); //!< Updates the comma-seperated string of all possible starting ships.
    135155            void tagsUpdated(void); //!< Updates the comma-seperated string of all tags, if the set of tags has changed.
    136 
    137156            static void initializeTags(void); //!< Initialize the set of allowed tags.
    138157            /**
     
    152171            std::set<std::string> tags_; //!< The set of tags the Level is tagged with.
    153172            std::string tagsString_; //!< The comma-seperated string of all the tags the Level is tagged with.
     173            std::set<std::string> startingShips_; //!< The set of starting ship models the Level allows.
     174            std::string startingShipsString_; //!< The comma-seperated string of all the allowed ship models for the shipselection.
    154175    }; // tolua_export
    155176
     
    161182        - @b description The description of the level.
    162183        - @b screenshot The screenshot of the level.
    163         - @b tags A comma-seperated string of tags. Allowed tags are: <em>test</em>, <em>singleplayer</em>, <em>multiplayer</em>, <em>showcase</em>, <em>tutorial</em>, <em>presentation</em>.
    164 
     184        - @b tags A comma-seperated string of tags. Allowed tags are: <em>test</em>, <em>singleplayer</em>, <em>multiplayer</em>, <em>showcase</em>, <em>tutorial</em>, <em>presentation</em>, <em>shipselection</em>.
     185        - @b (optional) startingships The comma-seperated string of starting ship models
    165186        An example would be:
    166187        @code
     
    176197    @author
    177198        Damian 'Mozork' Frick
    178 
     199    @edit
     200        Matthias Hutter
    179201    @ingroup Orxonox
    180202    */
     
    186208
    187209            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Creates a LevelInfo object through XML.
    188        
     210
    189211            /**
    190212            @brief Set the screenshot of the Level.
     
    223245            inline const std::string& getTags(void) const
    224246                { return this->LevelInfoItem::getTags(); }
     247            /**
     248            @brief Set the starting ship models of the level
     249            @param A comma-seperated string of all the allowed ship models for the shipselection.
     250            */
     251            inline void setStartingShips(const std::string& ships)
     252                { this->LevelInfoItem::setStartingShips(ships); }
     253            /**
     254            @brief Get the starting ship models of the level
     255            @return Returns a comma-seperated string of all the allowed ship models for the shipselection.
     256            */
     257            inline const std::string& getStartingShips(void) const
     258                { return this->LevelInfoItem::getStartingShips(); }
    225259
    226260            LevelInfoItem* copy(void); //!< Copies the contents of this LevelInfo object to a new LevelInfoItem object.
    227 
    228261    };
    229262
     
    243276            }
    244277    };
    245    
     278
    246279} // tolua_export
    247280
  • code/trunk/src/orxonox/OrxonoxPrereqs.h

    r8858 r9348  
    109109    class TeamDeathmatch;
    110110    class UnderAttack;
     111    class TeamGametype;
    111112
    112113    // graphics
     
    150151    class OrxonoxOverlay;
    151152    class OverlayGroup;
    152 
    153     // pickup
    154     class PickupIdentifier;
    155153
    156154    //sound
  • code/trunk/src/orxonox/Scene.cc

    r8858 r9348  
    258258    void Scene::setSkybox(const std::string& skybox)
    259259    {
    260         if (GameMode::showsGraphics() && this->sceneManager_)
    261             this->sceneManager_->setSkyBox(true, skybox);
     260        try
     261        {
     262            if (GameMode::showsGraphics() && this->sceneManager_)
     263                this->sceneManager_->setSkyBox(true, skybox);
     264        }
     265        catch (const Ogre::Exception&)
     266        {
     267            orxout(internal_error) << "Could not load skybox '" << skybox << "':" << endl;
     268            orxout(internal_error) << Exception::handleMessage() << endl;
     269        }
    262270
    263271        this->skybox_ = skybox;
  • code/trunk/src/orxonox/controllers/FormationController.cc

    • Property svn:eol-style set to native
    r9265 r9348  
    5050{
    5151
    52   SetConsoleCommand("FormationController", "formationflight",  &FormationController::formationflight);
    53   SetConsoleCommand("FormationController", "masteraction",     &FormationController::masteraction);
    54   SetConsoleCommand("FormationController", "followme",         &FormationController::followme);
    55   SetConsoleCommand("FormationController", "passivebehaviour", &FormationController::passivebehaviour);
    56   SetConsoleCommand("FormationController", "formationsize",    &FormationController::formationsize);
    57 
    58 
    59 
    60 
    61   static const unsigned int STANDARD_MAX_FORMATION_SIZE = 9;
    62   static const int RADIUS_TO_SEARCH_FOR_MASTERS = 5000;
    63   static const float FORMATION_LENGTH =  110;
    64   static const float FORMATION_WIDTH =  110;
    65   static const int FREEDOM_COUNT = 4; //seconds the slaves in a formation will be set free when master attacks an enemy
    66   static const float SPEED_MASTER = 0.6f;
    67   static const float ROTATEFACTOR_MASTER = 0.2f;
    68   static const float SPEED_FREE = 0.8f;
    69   static const float ROTATEFACTOR_FREE = 0.8f;
    70 
    71   FormationController::FormationController(BaseObject* creator) : Controller(creator)
    72   {
     52    SetConsoleCommand("FormationController", "formationflight",  &FormationController::formationflight);
     53    SetConsoleCommand("FormationController", "masteraction",     &FormationController::masteraction);
     54    SetConsoleCommand("FormationController", "followme",         &FormationController::followme);
     55    SetConsoleCommand("FormationController", "passivebehaviour", &FormationController::passivebehaviour);
     56    SetConsoleCommand("FormationController", "formationsize",    &FormationController::formationsize);
     57
     58
     59
     60
     61    static const unsigned int STANDARD_MAX_FORMATION_SIZE = 9;
     62    static const int RADIUS_TO_SEARCH_FOR_MASTERS = 5000;
     63    static const float FORMATION_LENGTH =  110;
     64    static const float FORMATION_WIDTH =  110;
     65    static const int FREEDOM_COUNT = 4; //seconds the slaves in a formation will be set free when master attacks an enemy
     66    static const float SPEED_MASTER = 0.6f;
     67    static const float ROTATEFACTOR_MASTER = 0.2f;
     68    static const float SPEED_FREE = 0.8f;
     69    static const float ROTATEFACTOR_FREE = 0.8f;
     70
     71    FormationController::FormationController(BaseObject* creator) : Controller(creator)
     72    {
    7373        RegisterObject(FormationController);
    7474
     
    9191        this->team_=-1;
    9292        this->target_.setCallback(createFunctor(&FormationController::targetDied, this));
    93   }
    94 
    95   FormationController::~FormationController()
    96   {
    97     if (this->isInitialized())
     93    }
     94
     95    FormationController::~FormationController()
     96    {
     97        if (this->isInitialized())
    9898        {
    9999            this->removeFromFormation();
     
    123123            }
    124124        }
    125   }
    126 
    127   void FormationController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     125    }
     126
     127    void FormationController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    128128    {
    129129        SUPER(FormationController, XMLPort, xmlelement, mode);
     
    137137
    138138
    139   /**
     139    /**
    140140        @brief Activates / deactivates formationflight behaviour
    141141        @param form activate formflight if form is true
    142142    */
    143   void FormationController::formationflight(const bool form)
     143    void FormationController::formationflight(const bool form)
    144144    {
    145145        for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
     
    168168    }
    169169
    170   /**
     170    /**
    171171        @brief Get all masters to do a "specific master action"
    172172        @param action which action to perform (integer, so it can be called with a console command (tmp solution))
     
    198198    }
    199199
    200   /**
     200    /**
    201201        @brief Sets shooting behaviour of pawns.
    202202        @param passive if true, bots won't shoot.
     
    225225    }
    226226
    227   /**
     227    /**
    228228        @brief Sets maximal formation size
    229229        @param size maximal formation size.
     
    280280        }
    281281
    282         Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
     282        Vector2 coord = get2DViewcoordinates(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
    283283        float distance = (target - this->getControllableEntity()->getPosition()).length();
    284 
     284        float rotateX = clamp(coord.x * 10, -1.0f, 1.0f);
     285        float rotateY = clamp(coord.y * 10, -1.0f, 1.0f);
    285286
    286287        if(this->state_ == FREE)
     
    289290            {
    290291                // Multiply with ROTATEFACTOR_FREE to make them a bit slower
    291                 this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_FREE * sgn(coord.x) * coord.x*coord.x);
    292                 this->getControllableEntity()->rotatePitch(ROTATEFACTOR_FREE * sgn(coord.y) * coord.y*coord.y);
    293             }
    294 
    295             if (this->target_ && distance < 200 && this->getControllableEntity()->getVelocity().squaredLength() > this->target_->getVelocity().squaredLength())
     292                this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_FREE * rotateX);
     293                this->getControllableEntity()->rotatePitch(ROTATEFACTOR_FREE * rotateY);
     294            }
     295
     296            if (this->target_ && distance <  200 && this->getControllableEntity()->getVelocity().squaredLength() > this->target_->getVelocity().squaredLength())
    296297            {
    297298              this->getControllableEntity()->moveFrontBack(-0.05f); // They don't brake with full power to give the player a chance
     
    305306            if (this->target_ || distance > 10)
    306307            {
    307                 this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_MASTER * sgn(coord.x) * coord.x*coord.x);
    308                 this->getControllableEntity()->rotatePitch(ROTATEFACTOR_MASTER * sgn(coord.y) * coord.y*coord.y);
     308                this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_MASTER * rotateX);
     309                this->getControllableEntity()->rotatePitch(ROTATEFACTOR_MASTER * rotateY);
    309310            }
    310311
     
    320321        {
    321322
    322            this->getControllableEntity()->rotateYaw(-2.0f * ROTATEFACTOR_MASTER * sgn(coord.x) * coord.x*coord.x);
    323            this->getControllableEntity()->rotatePitch(2.0f * ROTATEFACTOR_MASTER * sgn(coord.y) * coord.y*coord.y);
     323            this->getControllableEntity()->rotateYaw(-2.0f * ROTATEFACTOR_MASTER * rotateX);
     324            this->getControllableEntity()->rotatePitch(2.0f * ROTATEFACTOR_MASTER * rotateY);
    324325
    325326            if (distance < 300)
    326327            {
    327                 if (bHasTargetOrientation_)
    328                     {
    329                         copyTargetOrientation();
    330                     }
     328                if (bHasTargetOrientation_)
     329                {
     330                    copyTargetOrientation();
     331                }
    331332                if (distance < 100)
    332                 {   //linear speed reduction
     333                { //linear speed reduction
    333334                    this->getControllableEntity()->moveFrontBack(distance/100.0f*0.4f*SPEED_MASTER);
    334 
    335                 } else this->getControllableEntity()->moveFrontBack(1.2f*SPEED_MASTER);
    336 
    337             } else {
     335                }
     336                else
     337                    this->getControllableEntity()->moveFrontBack(1.2f*SPEED_MASTER);
     338            }
     339            else
    338340                this->getControllableEntity()->moveFrontBack(1.2f*SPEED_MASTER + distance/300.0f);
    339             }
    340341        }
    341342
     
    343344        {
    344345            this->positionReached();
    345             bHasTargetOrientation_=false;
    346         }
    347     }
    348 
    349 
    350 
    351   void FormationController::moveToTargetPosition()
     346            bHasTargetOrientation_=false;
     347        }
     348    }
     349
     350
     351
     352    void FormationController::moveToTargetPosition()
    352353    {
    353354        this->moveToPosition(this->targetPosition_);
    354355    }
    355356
    356   //copy the Roll orientation of given Quaternion.
    357   void FormationController::copyOrientation(const Quaternion& orient)
     357    //copy the Roll orientation of given Quaternion.
     358    void FormationController::copyOrientation(const Quaternion& orient)
    358359    {
    359360        //roll angle difference in radian
     
    373374
    374375
    375    /**
     376    /**
    376377        @brief Unregisters a slave from its master. Initiated by a slave.
    377378    */
     
    463464        }
    464465    }
    465  /**
     466
     467    /**
    466468        @brief Commands the slaves of a master into a formation. Sufficiently fast not to be called within tick. Initiated by a master.
    467469    */
    468 
    469 void FormationController::commandSlaves()
     470    void FormationController::commandSlaves()
    470471    {
    471472        if(this->state_ != MASTER) return;
     
    481482        }
    482483        else
    483         // formation:
     484        // formation:
    484485        {
    485486            dest += 1.0f*orient*WorldEntity::BACK;
    486487            Vector3 pos = Vector3::ZERO;
    487                  bool left=true;
     488            bool left=true;
    488489            int i = 1;
    489490
     
    683684
    684685        if (specificMasterActionHoldCount_ == 0)
    685          {
     686        {
    686687            this->specificMasterAction_ = NONE;
    687688            this->searchNewTarget();
    688          }
    689         else specificMasterActionHoldCount_--;
     689        }
     690        else
     691            specificMasterActionHoldCount_--;
    690692    }
    691693
     
    711713    void FormationController::turn180()
    712714    {
    713             Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, this->targetPosition_);
    714 
    715             this->getControllableEntity()->rotateYaw(-2.0f * sgn(coord.x) * coord.x*coord.x);
    716             this->getControllableEntity()->rotatePitch(2.0f * sgn(coord.y) * coord.y*coord.y);
    717 
    718             this->getControllableEntity()->moveFrontBack(SPEED_MASTER);
     715        Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, this->targetPosition_);
     716
     717        this->getControllableEntity()->rotateYaw(-2.0f * sgn(coord.x) * coord.x*coord.x);
     718        this->getControllableEntity()->rotatePitch(2.0f * sgn(coord.y) * coord.y*coord.y);
     719
     720        this->getControllableEntity()->moveFrontBack(SPEED_MASTER);
    719721    }
    720722
     
    734736    void FormationController::spin()
    735737    {
    736             this->moveToTargetPosition();
    737             this->getControllableEntity()->rotateRoll(0.8f);
     738        this->moveToTargetPosition();
     739        this->getControllableEntity()->rotateRoll(0.8f);
    738740    }
    739741
     
    773775        if((humanPawn != NULL) && (allMasters.size() != 0))
    774776        {
    775                 float posHuman = humanPawn->getPosition().length();
    776                 float distance = 0.0f;
    777                 float minDistance = FLT_MAX;
    778                 int index = 0;
    779                 int i = 0;
    780 
    781                 for(std::vector<FormationController*>::iterator it = allMasters.begin(); it != allMasters.end(); it++, i++)
    782                     {
    783                         if (!FormationController::sameTeam((*it)->getControllableEntity(), humanPawn, (*it)->getGametype())) continue;
    784                         distance = posHuman - (*it)->getControllableEntity()->getPosition().length();
    785                         if(distance < minDistance) index = i;
    786                     }
    787                 allMasters[index]->followInit(humanPawn);
    788             }
    789 
    790     }
    791 
    792 
    793 
    794 
     777            float posHuman = humanPawn->getPosition().length();
     778            float distance = 0.0f;
     779            float minDistance = FLT_MAX;
     780            int index = 0;
     781            int i = 0;
     782
     783            for(std::vector<FormationController*>::iterator it = allMasters.begin(); it != allMasters.end(); it++, i++)
     784            {
     785                if (!FormationController::sameTeam((*it)->getControllableEntity(), humanPawn, (*it)->getGametype())) continue;
     786                distance = posHuman - (*it)->getControllableEntity()->getPosition().length();
     787                if(distance < minDistance) index = i;
     788            }
     789            allMasters[index]->followInit(humanPawn);
     790        }
     791    }
    795792
    796793    /**
     
    814811    }
    815812
    816    /**
     813    /**
    817814        @brief Master begins to follow a randomly chosen human player of the same team. Is a "specific master action".
    818815    */
     
    842839
    843840
    844   /**
     841    /**
    845842        @brief Master follows target with adjusted speed. Called within tick.
    846843    */
     
    854851
    855852
    856   void FormationController::setTargetPosition(const Vector3& target)
     853    void FormationController::setTargetPosition(const Vector3& target)
    857854    {
    858855        this->targetPosition_ = target;
     
    918915    }
    919916
    920   void FormationController::forgetTarget()
     917    void FormationController::forgetTarget()
    921918    {
    922919        this->target_ = 0;
     
    924921    }
    925922
    926    void FormationController::targetDied()
     923    void FormationController::targetDied()
    927924    {
    928925        this->forgetTarget();
     
    930927    }
    931928
    932   bool FormationController::sameTeam(ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype)
     929    bool FormationController::sameTeam(ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype)
    933930    {
    934931        if (entity1 == entity2)
     
    10541051            return;
    10551052
    1056         Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
     1053        Vector2 coord = get2DViewcoordinates(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
    10571054        float distance = (target - this->getControllableEntity()->getPosition()).length();
    10581055
     
    10601057            {
    10611058                // Multiply with ROTATEFACTOR_FREE to make them a bit slower
    1062                 this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_FREE * sgn(coord.x) * coord.x*coord.x);
    1063                 this->getControllableEntity()->rotatePitch(ROTATEFACTOR_FREE * sgn(coord.y) * coord.y*coord.y);
     1059                this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_FREE * clamp(coord.x * 10, -1.0f, 1.0f));
     1060                this->getControllableEntity()->rotatePitch(ROTATEFACTOR_FREE * clamp(coord.y * 10, -1.0f, 1.0f));
    10641061                this->getControllableEntity()->moveFrontBack(SPEED_FREE);
    10651062            }
  • code/trunk/src/orxonox/controllers/FormationController.h

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

    r9016 r9348  
    298298        //Used in HumanController for formationFlight
    299299        HumanController::hit(originator,contactpoint,damage);
    300        
     300
    301301        if (this->showDamageOverlay_ && !this->controlPaused_ && this->controllableEntity_ && !this->controllableEntity_->isInMouseLook())
    302302        {
     
    397397                try
    398398                {
    399                     wePtr = dynamic_cast<WorldEntity*>(Ogre::any_cast<OrxonoxClass*>(itr->movable->getUserAny()));
     399                    wePtr = orxonox_cast<WorldEntity*>(Ogre::any_cast<OrxonoxClass*>(itr->movable->getUserAny()));
    400400                }
    401401                catch (...)
  • code/trunk/src/orxonox/gamestates/GSRoot.cc

    r8858 r9348  
    7676        for (ObjectList<BaseObject>::iterator it = ObjectList<BaseObject>::begin(); it; ++it)
    7777        {
    78             if (dynamic_cast<Synchronisable*>(*it))
    79                 orxout(debug_output) << "object: " << it->getIdentifier()->getName() << " id: " << dynamic_cast<Synchronisable*>(*it)->getObjectID() << endl;
     78            Synchronisable* synchronisable = orxonox_cast<Synchronisable*>(*it);
     79            if (synchronisable)
     80                orxout(debug_output) << "object: " << it->getIdentifier()->getName() << " id: " << synchronisable->getObjectID() << endl;
    8081            else
    8182                orxout(debug_output) << "object: " << it->getIdentifier()->getName() << endl;
  • code/trunk/src/orxonox/gametypes/Deathmatch.cc

    r8858 r9348  
    114114    }
    115115
    116     void Deathmatch::playerScored(PlayerInfo* player)
     116    void Deathmatch::playerScored(PlayerInfo* player, int score)
    117117    {
    118         Gametype::playerScored(player);
     118        Gametype::playerScored(player, score);
    119119
    120120        if (player)
  • code/trunk/src/orxonox/gametypes/Deathmatch.h

    r5781 r9348  
    4848
    4949            virtual void pawnKilled(Pawn* victim, Pawn* killer = 0);
    50             virtual void playerScored(PlayerInfo* player);
     50            virtual void playerScored(PlayerInfo* player, int score = 1);
    5151    };
    5252}
  • code/trunk/src/orxonox/gametypes/Dynamicmatch.cc

    r8858 r9348  
    3131//Low; Codeoptimierung und Dokumentation
    3232
    33 /*
    34 short gaming manual:
    35 There are three different parties a player can belong to: victim, chaser or killer
    36 Every player starts as chaser. As long as there are not enough victims and killers, you can change your and other player's parties by shooting them.
    37 In order to win you have to earn as much points as possible:
    38 - as victim by escaping the chasers
    39 - as chaser by shooting the victim
    40 - as killer by killing the chasers
    41 
    42 
    43 What you shouldn't do is shooting at players of your own party. By doing so your score will decrease.
    44 P.S: If you don't want to be a victim: Get rid of your part by shooting a chaser.
     33/**
     34@brief
     35    Short Gaming Manual:
     36    There are three different parties a player can belong to: victim, chaser or killer
     37    Every player starts as chaser. As long as there are not enough victims and killers, you can change your and other player's parties by shooting them.
     38    In order to win you have to earn as much points as possible:
     39    - as victim by escaping the chasers
     40    - as chaser by shooting the victim
     41    - as killer by killing the chasers
     42
     43
     44    What you shouldn't do is shooting at players of your own party. By doing so your score will decrease.
     45    P.S: If you don't want to be a victim: Get rid of your part by shooting a chaser.
    4546*/
    4647#include "Dynamicmatch.h"
     
    8182        this->numberOf[killer]=0;
    8283        this->tutorial=true;
    83         this->pointsPerTime=0.0f;
     84        this->pointsPerTime=1.0f;
    8485        this->setHUDTemplate("DynamicmatchHUD");
    8586    }
     
    9596            ColourValue(0.3f, 0.3f, 1.0f),  //piggycolour
    9697            ColourValue(0.3f, 1.0f, 0.3f)   //killercolour  what about black: 0.0f, 0.0f, 0.0f
    97 
    9898        };
    9999        static std::vector<ColourValue> defaultcolours(colours, colours + sizeof(colours) / sizeof(ColourValue));
     
    111111        if (victim && victim->getPlayer()) //&& originator && originator->getPlayer() ??
    112112        {
    113         int target= playerParty_[victim->getPlayer()];
    114         int source= playerParty_[originator->getPlayer()];
     113            int target = playerParty_[victim->getPlayer()];
     114            int source = playerParty_[originator->getPlayer()];
    115115
    116116            //Case: Not Enough Pigs: party change (= party management)
     
    151151
    152152                //Give new pig boost
    153                 SpaceShip* spaceship = dynamic_cast<SpaceShip*>(victim);
     153                SpaceShip* spaceship = orxonox_cast<SpaceShip*>(victim);
    154154                this->grantPigBoost(spaceship);
    155155            }
     
    245245                }
    246246                //Give new pig boost
    247                 SpaceShip* spaceship = dynamic_cast<SpaceShip*>(victim);
     247                SpaceShip* spaceship = orxonox_cast<SpaceShip*>(victim);
    248248                this->grantPigBoost(spaceship);
    249249            }
     
    276276            else if (friendlyfire && (source == target))
    277277            {
    278                 std::map<PlayerInfo*, Player>::iterator it = this->players_.find(originator->getPlayer());
    279                 if (it != this->players_.end())
    280                     {
    281                         it->second.frags_--;
    282                     }
    283             }
    284         }// from far far away not to be removed!
     278                    this->playerScored(originator->getPlayer(), -1);
     279            }
     280        }
    285281        return false; //default: no damage
    286282    }
     
    296292            if (playerParty_[originator->getPlayer()] == killer) //reward the killer
    297293            {
    298                 std::map<PlayerInfo*, Player>::iterator it = this->players_.find(originator->getPlayer());
    299                 if (it != this->players_.end())
    300                 {
    301                     it->second.frags_+=20; //value must be tested
    302                 }
    303             }
    304         return true;
     294                    this->playerScored(originator->getPlayer(), 25);
     295            }
     296            return true;
    305297        }
    306298        else return false;
     
    309301    /**
    310302    @brief
    311         Grant the piggy a boost.
     303        Grant the victim a boost.
    312304    @param spaceship
    313305        The SpaceShip to give the boost.
     
    315307    void Dynamicmatch::grantPigBoost(SpaceShip* spaceship)
    316308    {
    317         // Give pig boost
     309        // Give victim boost
    318310        if (spaceship)
    319311        {
     312            WeakPtr<SpaceShip>* ptr = new WeakPtr<SpaceShip>(spaceship);
     313            if(ptr == NULL)
     314                return;
    320315            spaceship->addSpeedFactor(5);
    321             WeakPtr<SpaceShip>* ptr = new WeakPtr<SpaceShip>(spaceship);
    322316            ExecutorPtr executor = createExecutor(createFunctor(&Dynamicmatch::resetSpeedFactor, this));
    323317            executor->setDefaultValue(0, ptr);
     
    374368
    375369        if (this->hasStarted() && !gameEnded_)
    376         {   pointsPerTime =pointsPerTime + dt;
    377             gameTime_ = gameTime_ - dt;
    378             if (pointsPerTime > 2.0f)//hard coded!! should be changed
    379             {
    380                 pointsPerTime=0.0f;
     370        {
     371            pointsPerTime = pointsPerTime + dt; //increase points
     372            gameTime_ = gameTime_ - dt; // decrease game time
     373            if (pointsPerTime > 2.0f) //hard coded points for victim! should be changed
     374            {
     375                pointsPerTime = 0.0f;
    381376                rewardPig();
    382377            }
     
    408403    }
    409404
     405/**
     406    @brief The reward function is called every 2 seconds via the tick function and makes the victim score points.
     407*/
    410408    void Dynamicmatch::rewardPig()
    411409    {
    412410        for (std::map< PlayerInfo*, int >::iterator it = this->playerParty_.begin(); it != this->playerParty_.end(); ++it) //durch alle Spieler iterieren und alle piggys finden
    413411        {
    414             if (it->second==piggy)
    415             {
    416                  //Spieler mit der Pig-party frags++
    417                  std::map<PlayerInfo*, Player>::iterator it2 = this->players_.find(it->first);// still not sure if right syntax
    418                  if (it2 != this->players_.end())
    419                  {
    420                      it2->second.frags_++;
    421                  }
     412            if (it->second==piggy)//Spieler mit der Pig-party frags++
     413            {
     414                 this->playerScored(it->first);
    422415            }
    423416        }
     
    426419    {
    427420        std::map<PlayerInfo*, int>::const_iterator it_player = this->playerParty_.find(player);
    428         Pawn* pawn = dynamic_cast<Pawn*>(player->getControllableEntity());
     421        Pawn* pawn = orxonox_cast<Pawn*>(player->getControllableEntity());
    429422            if (pawn)
    430423            {
     
    446439    {
    447440        //pigs: 1 + every 6th player is a pig
    448         if ( (1+this->getNumberOfPlayers()/6) > numberOf[piggy])
     441        if ( (1 + getPlayerCount()/6) > numberOf[piggy])
    449442        {
    450443            notEnoughPigs=true;
     
    495488        }
    496489        //killers: every 4th player is a killer
    497         if (getNumberOfPlayers()/4 > numberOf[killer])
     490        if ( static_cast<unsigned int>(getPlayerCount()/4) > numberOf[killer])
    498491        {
    499492            notEnoughKillers=true;
  • code/trunk/src/orxonox/gametypes/Dynamicmatch.h

    r8727 r9348  
    8181            SpawnPoint* getBestSpawnPoint(PlayerInfo* player) const;
    8282
     83
    8384        protected:
     85            inline int getPlayerCount() const
     86                 { return this->numberOf[chaser] + numberOf[piggy] + this->numberOf[killer]; }
    8487
    8588            std::map< PlayerInfo*, int > playerParty_; //player's parties are recorded here
  • code/trunk/src/orxonox/gametypes/Gametype.cc

    r9261 r9348  
    301301    }
    302302
    303     void Gametype::playerScored(PlayerInfo* player)
     303    void Gametype::playerScored(PlayerInfo* player, int score)
    304304    {
    305305        std::map<PlayerInfo*, Player>::iterator it = this->players_.find(player);
    306306        if (it != this->players_.end())
    307             it->second.frags_++;
     307            it->second.frags_ += score;
    308308    }
    309309
  • code/trunk/src/orxonox/gametypes/Gametype.h

    r9260 r9348  
    9090            virtual bool playerChangedName(PlayerInfo* player);
    9191
    92             virtual void playerScored(PlayerInfo* player);
     92            virtual void playerScored(PlayerInfo* player, int score = 1);
    9393
    9494            virtual bool allowPawnHit(Pawn* victim, Pawn* originator = 0);
     
    153153            virtual void resetTimer(float t);
    154154
     155            /**
     156            @brief Get number of Players in game.
     157            */
    155158            inline unsigned int getNumberOfPlayers() const
    156                 { return this->gtinfo_->getNumberOfPlayers(); }
     159                { return this->players_.size(); }
     160
     161
    157162
    158163        protected:
  • code/trunk/src/orxonox/gametypes/LastManStanding.cc

    r8858 r9348  
    211211            if(!player->getControllableEntity())
    212212                return;
    213             Pawn* pawn = dynamic_cast<Pawn*>(player->getControllableEntity());
     213            Pawn* pawn = orxonox_cast<Pawn*>(player->getControllableEntity());
    214214            if(!pawn)
    215215                return;
  • code/trunk/src/orxonox/gametypes/LastTeamStanding.cc

    r8858 r9348  
    283283            if(!player->getControllableEntity())
    284284                return;
    285             Pawn* pawn = dynamic_cast<Pawn*>(player->getControllableEntity());
     285            Pawn* pawn = orxonox_cast<Pawn*>(player->getControllableEntity());
    286286            if(!pawn)
    287287                return;
  • code/trunk/src/orxonox/gametypes/Mission.cc

    • Property svn:eol-style set to native
    r9016 r9348  
    6363        {
    6464            this->missionAccomplished_ = false;
    65             this->end();
     65            this->end();
    6666        }
    6767    }
     
    7878    {
    7979        Gametype::end();
    80         /*if (this->missionAccomplished_)
     80        /*if (this->missionAccomplished_)
    8181            this->gtinfo_->sendAnnounceMessage("Mission accomplished!");
    82         else
     82        else
    8383            this->gtinfo_->sendAnnounceMessage("Mission failed!");
    84          * */
     84        */
    8585    }
    8686
  • code/trunk/src/orxonox/gametypes/Mission.h

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

    r8952 r9348  
    128128
    129129    // collect Points for killing oppenents
    130     void TeamBaseMatch::playerScored(PlayerInfo* player)
     130    void TeamBaseMatch::playerScored(PlayerInfo* player, int score)
    131131    {
    132132        int teamnr = this->getTeam(player);
  • code/trunk/src/orxonox/gametypes/TeamBaseMatch.h

    r5929 r9348  
    4747            virtual bool allowPawnDamage(Pawn* victim, Pawn* originator);
    4848
    49             virtual void playerScored(PlayerInfo* player);
     49            virtual void playerScored(PlayerInfo* player, int score = 1);
    5050            virtual void showPoints();
    5151            virtual void endGame();
  • code/trunk/src/orxonox/gametypes/TeamDeathmatch.cc

    r7182 r9348  
    3030
    3131#include "core/CoreIncludes.h"
    32 #include "core/ConfigValueIncludes.h"
    33 #include "interfaces/TeamColourable.h"
    34 #include "worldentities/TeamSpawnPoint.h"
     32#include "chat/ChatManager.h"
     33#include "infos/PlayerInfo.h"
    3534#include "worldentities/pawns/Pawn.h"
    3635
     
    3938    CreateUnloadableFactory(TeamDeathmatch);
    4039
    41     TeamDeathmatch::TeamDeathmatch(BaseObject* creator) : Deathmatch(creator)
     40    TeamDeathmatch::TeamDeathmatch(BaseObject* creator) : TeamGametype(creator)
    4241    {
    4342        RegisterObject(TeamDeathmatch);
    44 
    45         this->teams_ = 2;
    46 
    47         this->setConfigValues();
    4843    }
    4944
    50     void TeamDeathmatch::setConfigValues()
     45    void TeamDeathmatch::start()
    5146    {
    52         SetConfigValue(teams_, 2);
     47        TeamGametype::start();
    5348
    54         static ColourValue colours[] =
    55         {
    56             ColourValue(1.0f, 0.3f, 0.3f),
    57             ColourValue(0.3f, 0.3f, 1.0f),
    58             ColourValue(0.3f, 1.0f, 0.3f),
    59             ColourValue(1.0f, 1.0f, 0.0f)
    60         };
    61         static std::vector<ColourValue> defaultcolours(colours, colours + sizeof(colours) / sizeof(ColourValue));
     49        std::string message("The match has started!");
     50        ChatManager::message(message);
     51    }
    6252
    63         SetConfigValue(teamcolours_, defaultcolours);
     53    void TeamDeathmatch::end()
     54    {
     55        TeamGametype::end();
     56
     57        std::string message("The match has ended.");
     58        ChatManager::message(message);
    6459    }
    6560
    6661    void TeamDeathmatch::playerEntered(PlayerInfo* player)
    6762    {
    68         Deathmatch::playerEntered(player);
     63        TeamGametype::playerEntered(player);
    6964
    70         std::vector<unsigned int> playersperteam(this->teams_, 0);
    71 
    72         for (std::map<PlayerInfo*, int>::iterator it = this->teamnumbers_.begin(); it != this->teamnumbers_.end(); ++it)
    73             if (it->second < static_cast<int>(this->teams_) && it->second >= 0)
    74                 playersperteam[it->second]++;
    75 
    76         unsigned int minplayers = static_cast<unsigned int>(-1);
    77         size_t minplayersteam = 0;
    78         for (size_t i = 0; i < this->teams_; ++i)
    79         {
    80             if (playersperteam[i] < minplayers)
    81             {
    82                 minplayers = playersperteam[i];
    83                 minplayersteam = i;
    84             }
    85         }
    86 
    87         this->teamnumbers_[player] = minplayersteam;
     65        const std::string& message = player->getName() + " entered the game";
     66        ChatManager::message(message);
    8867    }
    8968
    9069    bool TeamDeathmatch::playerLeft(PlayerInfo* player)
    9170    {
    92         bool valid_player = Deathmatch::playerLeft(player);
     71        bool valid_player = TeamGametype::playerLeft(player);
    9372
    9473        if (valid_player)
    95             this->teamnumbers_.erase(player);
     74        {
     75            const std::string& message = player->getName() + " left the game";
     76            ChatManager::message(message);
     77        }
     78
     79        return valid_player;
     80    }
     81    bool TeamDeathmatch::playerChangedName(PlayerInfo* player)
     82    {
     83        bool valid_player = TeamGametype::playerChangedName(player);
     84
     85        if (valid_player)
     86        {
     87            const std::string& message = player->getOldName() + " changed name to " + player->getName();
     88            ChatManager::message(message);
     89        }
    9690
    9791        return valid_player;
    9892    }
    9993
    100     bool TeamDeathmatch::allowPawnHit(Pawn* victim, Pawn* originator)
     94    void TeamDeathmatch::pawnKilled(Pawn* victim, Pawn* killer)
    10195    {
    102         return (!this->pawnsAreInTheSameTeam(victim, originator) || !originator);
     96        if (victim && victim->getPlayer())
     97        {
     98            std::string message;
     99            if (killer)
     100            {
     101                if (killer->getPlayer())
     102                    message = victim->getPlayer()->getName() + " was killed by " + killer->getPlayer()->getName();
     103                else
     104                    message = victim->getPlayer()->getName() + " was killed";
     105            }
     106            else
     107                message = victim->getPlayer()->getName() + " died";
     108
     109            ChatManager::message(message);
     110        }
     111
     112        Gametype::pawnKilled(victim, killer);
    103113    }
    104114
    105     bool TeamDeathmatch::allowPawnDamage(Pawn* victim, Pawn* originator)
     115    void TeamDeathmatch::playerScored(PlayerInfo* player, int score)
    106116    {
    107         return (!this->pawnsAreInTheSameTeam(victim, originator) || !originator);
    108     }
     117        TeamGametype::playerScored(player, score);
    109118
    110     bool TeamDeathmatch::allowPawnDeath(Pawn* victim, Pawn* originator)
    111     {
    112         return (!this->pawnsAreInTheSameTeam(victim, originator) || !originator);
    113     }
    114 
    115     SpawnPoint* TeamDeathmatch::getBestSpawnPoint(PlayerInfo* player) const
    116     {
    117         int desiredTeamNr = -1;
    118         std::map<PlayerInfo*, int>::const_iterator it_player = this->teamnumbers_.find(player);
    119         if (it_player != this->teamnumbers_.end())
    120             desiredTeamNr = it_player->second;
    121 
    122         // Only use spawnpoints of the own team (or non-team-spawnpoints)
    123         std::set<SpawnPoint*> teamSpawnPoints = this->spawnpoints_;
    124         for (std::set<SpawnPoint*>::iterator it = teamSpawnPoints.begin(); it != teamSpawnPoints.end(); )
     119        if (player)
    125120        {
    126             if ((*it)->isA(Class(TeamSpawnPoint)))
    127             {
    128                 TeamSpawnPoint* tsp = orxonox_cast<TeamSpawnPoint*>(*it);
    129                 if (tsp && static_cast<int>(tsp->getTeamNumber()) != desiredTeamNr)
    130                 {
    131                     teamSpawnPoints.erase(it++);
    132                     continue;
    133                 }
    134             }
    135 
    136             ++it;
    137         }
    138 
    139         SpawnPoint* fallbackSpawnPoint = NULL;
    140         if (teamSpawnPoints.size() > 0)
    141         {
    142             unsigned int randomspawn = static_cast<unsigned int>(rnd(static_cast<float>(teamSpawnPoints.size())));
    143             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*>::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;
    170             for (std::set<SpawnPoint*>::const_iterator it = teamSpawnPoints.begin(); it != teamSpawnPoints.end(); ++it)
    171             {
    172                 if (index == randomspawn)
    173                     return (*it);
    174 
    175                 ++index;
    176             }
    177 
    178             return fallbackSpawnPoint;
    179         }
    180 
    181         return 0;
    182     }
    183 
    184     void TeamDeathmatch::playerStartsControllingPawn(PlayerInfo* player, Pawn* pawn)
    185     {
    186         if (!player)
    187             return;
    188 
    189         // Set the team colour
    190         std::map<PlayerInfo*, int>::const_iterator it_player = this->teamnumbers_.find(player);
    191         if (it_player != this->teamnumbers_.end() && it_player->second >= 0 && it_player->second < static_cast<int>(this->teamcolours_.size()))
    192         {
    193             if (pawn)
    194             {
    195                 pawn->setRadarObjectColour(this->teamcolours_[it_player->second]);
    196 
    197                 std::set<WorldEntity*> pawnAttachments = pawn->getAttachedObjects();
    198                 for (std::set<WorldEntity*>::iterator it = pawnAttachments.begin(); it != pawnAttachments.end(); ++it)
    199                 {
    200                     if ((*it)->isA(Class(TeamColourable)))
    201                     {
    202                         TeamColourable* tc = orxonox_cast<TeamColourable*>(*it);
    203                         tc->setTeamColour(this->teamcolours_[it_player->second]);
    204                     }
    205                 }
    206             }
     121            const std::string& message = player->getName() + " scores!";
     122            ChatManager::message(message);
    207123        }
    208124    }
    209125
    210     bool TeamDeathmatch::pawnsAreInTheSameTeam(Pawn* pawn1, Pawn* pawn2)
    211     {
    212         if (pawn1 && pawn2)
    213         {
    214             std::map<PlayerInfo*, int>::const_iterator it1 = this->teamnumbers_.find(pawn1->getPlayer());
    215             std::map<PlayerInfo*, int>::const_iterator it2 = this->teamnumbers_.find(pawn2->getPlayer());
    216 
    217             if (it1 != this->teamnumbers_.end() && it2 != this->teamnumbers_.end())
    218                 return (it1->second == it2->second);
    219         }
    220         return false;
    221     }
    222 
    223     int TeamDeathmatch::getTeam(PlayerInfo* player)
    224     {
    225         std::map<PlayerInfo*, int>::const_iterator it_player = this->teamnumbers_.find(player);
    226         if (it_player != this->teamnumbers_.end())
    227             return it_player->second;
    228         else
    229             return -1;
    230     }
    231126}
  • code/trunk/src/orxonox/gametypes/TeamDeathmatch.h

    r9016 r9348  
    3131
    3232#include "OrxonoxPrereqs.h"
    33 
    34 #include <map>
    35 #include <vector>
    36 #include "Deathmatch.h"
     33#include "TeamGametype.h"
    3734
    3835namespace orxonox
    3936{
    40     class _OrxonoxExport TeamDeathmatch : public Deathmatch
     37    class _OrxonoxExport TeamDeathmatch : public TeamGametype
    4138    {
    4239        public:
     
    4441            virtual ~TeamDeathmatch() {}
    4542
    46             void setConfigValues();
    47 
     43            virtual void start();
     44            virtual void end();
    4845            virtual void playerEntered(PlayerInfo* player);
    4946            virtual bool playerLeft(PlayerInfo* player);
     47            virtual bool playerChangedName(PlayerInfo* player);
    5048
    51             virtual bool allowPawnHit(Pawn* victim, Pawn* originator = 0);
    52             virtual bool allowPawnDamage(Pawn* victim, Pawn* originator = 0);
    53             virtual bool allowPawnDeath(Pawn* victim, Pawn* originator = 0);
    54 
    55             virtual void playerStartsControllingPawn(PlayerInfo* player, Pawn* pawn);
    56 
    57             int getTeam(PlayerInfo* player);
    58             inline const ColourValue& getTeamColour(int teamnr) const
    59                 { return this->teamcolours_[teamnr]; }
    60 
    61         protected:
    62             virtual SpawnPoint* getBestSpawnPoint(PlayerInfo* player) const;
    63             bool pawnsAreInTheSameTeam(Pawn* pawn1, Pawn* pawn2);
    64 
    65             std::map<PlayerInfo*, int> teamnumbers_;
    66             std::vector<ColourValue> teamcolours_;
    67             unsigned int teams_;
     49            virtual void pawnKilled(Pawn* victim, Pawn* killer = 0);
     50            virtual void playerScored(PlayerInfo* player, int score = 1);
    6851    };
    6952}
  • code/trunk/src/orxonox/gametypes/TeamGametype.cc

    • Property svn:eol-style set to native
    r9048 r9348  
    8989    }
    9090
     91    /**
     92    @brief
     93        Function that determines the player's team number when entering the game for the first time.
     94        Override this function for other team structures.
     95    */
    9196    void TeamGametype::findAndSetTeam(PlayerInfo* player)
    9297    {
     
    130135            this->allowedInGame_.erase(player);
    131136        }
    132 
    133137
    134138        return valid_player;
  • code/trunk/src/orxonox/gametypes/TeamGametype.h

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

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

    r9016 r9348  
    6868    {
    6969        RegisterObject(GametypeInfo);
    70        
     70
    7171        this->bStarted_ = false;
    7272        this->bEnded_ = false;
     
    165165        if(this->bStarted_)
    166166           { return;}
    167        
     167
    168168        this->bStarted_ = true;
    169169        this->changedStarted();
    170        
    171        
     170
     171
    172172    }
    173173
     
    195195        if(this->startCountdown_ == countdown || countdown < 0.0f)
    196196            return;
    197        
     197
    198198        this->startCountdown_ = countdown;
    199199        // Set the counter to the ceiling of the current countdown.
     
    225225        if(this->counter_ == 0)
    226226            return;
    227        
     227
    228228        this->counter_--;
    229229        this->changedCountdownCounter();
     
    325325        if(this->spawned_ == spawned)
    326326            return;
    327        
     327
    328328        this->spawned_ = spawned;
    329329        // Clear the notifications if the Player has spawned.
     
    395395    // TODO: Replace with notifications.
    396396
    397     void GametypeInfo::sendAnnounceMessage(const std::string& message)
     397    void GametypeInfo::sendAnnounceMessage(const std::string& message) const
    398398    {
    399399        if (GameMode::isMaster())
     
    404404    }
    405405
    406     void GametypeInfo::sendAnnounceMessage(const std::string& message, unsigned int clientID)
     406    void GametypeInfo::sendAnnounceMessage(const std::string& message, unsigned int clientID) const
    407407    {
    408408        if (GameMode::isMaster())
     
    415415    }
    416416
    417     void GametypeInfo::sendKillMessage(const std::string& message, unsigned int clientID)
     417    void GametypeInfo::sendKillMessage(const std::string& message, unsigned int clientID) const
    418418    {
    419419        if (GameMode::isMaster())
     
    426426    }
    427427
    428     void GametypeInfo::sendDeathMessage(const std::string& message, unsigned int clientID)
     428    void GametypeInfo::sendDeathMessage(const std::string& message, unsigned int clientID) const
    429429    {
    430430        if (GameMode::isMaster())
     
    437437    }
    438438
    439     void GametypeInfo::sendStaticMessage(const std::string& message, unsigned int clientID, const ColourValue& colour)
     439    void GametypeInfo::sendStaticMessage(const std::string& message, unsigned int clientID, const ColourValue& colour) const
    440440    {
    441441        if (GameMode::isMaster())
     
    448448    }
    449449
    450     void GametypeInfo::sendFadingMessage(const std::string& message, unsigned int clientID)
     450    void GametypeInfo::sendFadingMessage(const std::string& message, unsigned int clientID) const
    451451    {
    452452        if (GameMode::isMaster())
     
    459459    }
    460460
    461     void GametypeInfo::dispatchAnnounceMessage(const std::string& message)
     461    void GametypeInfo::dispatchAnnounceMessage(const std::string& message) const
    462462    {
    463463        for (ObjectList<GametypeMessageListener>::iterator it = ObjectList<GametypeMessageListener>::begin(); it != ObjectList<GametypeMessageListener>::end(); ++it)
     
    465465    }
    466466
    467     void GametypeInfo::dispatchKillMessage(const std::string& message)
     467    void GametypeInfo::dispatchKillMessage(const std::string& message) const
    468468    {
    469469        for (ObjectList<GametypeMessageListener>::iterator it = ObjectList<GametypeMessageListener>::begin(); it != ObjectList<GametypeMessageListener>::end(); ++it)
     
    471471    }
    472472
    473     void GametypeInfo::dispatchDeathMessage(const std::string& message)
     473    void GametypeInfo::dispatchDeathMessage(const std::string& message) const
    474474    {
    475475        for (ObjectList<GametypeMessageListener>::iterator it = ObjectList<GametypeMessageListener>::begin(); it != ObjectList<GametypeMessageListener>::end(); ++it)
     
    477477    }
    478478
    479      void GametypeInfo::dispatchStaticMessage(const std::string& message, const ColourValue& colour)
     479     void GametypeInfo::dispatchStaticMessage(const std::string& message, const ColourValue& colour) const
    480480    {
    481481        for (ObjectList<GametypeMessageListener>::iterator it = ObjectList<GametypeMessageListener>::begin(); it != ObjectList<GametypeMessageListener>::end(); ++it)
     
    483483    }
    484484
    485      void GametypeInfo::dispatchFadingMessage(const std::string& message)
     485     void GametypeInfo::dispatchFadingMessage(const std::string& message) const
    486486    {
    487487        for (ObjectList<GametypeMessageListener>::iterator it = ObjectList<GametypeMessageListener>::begin(); it != ObjectList<GametypeMessageListener>::end(); ++it)
  • code/trunk/src/orxonox/infos/GametypeInfo.h

    r9016 r9348  
    6868                { return this->bStarted_; }
    6969            void changedStarted(void); // Is called when the game has changed to started.
    70            
     70
    7171            /**
    7272            @brief Get whether the game has ended yet.
     
    108108                { return this->readyToSpawn_; }
    109109            void changedReadyToSpawn(bool ready); // Inform the GametypeInfo that the local player has changed its spawned status.
    110            
     110
    111111            /**
    112112            @brief Get whether the local player is spawned.
     
    119119            inline const std::string& getHUDTemplate() const
    120120                { return this->hudtemplate_; }
    121            
    122             inline unsigned int getNumberOfPlayers() const
    123                 {  return this->spawnedPlayers_.size(); }
    124121
    125             void sendAnnounceMessage(const std::string& message);
    126             void sendAnnounceMessage(const std::string& message, unsigned int clientID);
    127             void sendKillMessage(const std::string& message, unsigned int clientID);
    128             void sendDeathMessage(const std::string& message, unsigned int clientID);
    129             void sendStaticMessage(const std::string& message, unsigned int clientID, const ColourValue& colour);
    130             void sendFadingMessage(const std::string& message, unsigned int clientID);
     122            void sendAnnounceMessage(const std::string& message) const;
     123            void sendAnnounceMessage(const std::string& message, unsigned int clientID) const;
     124            void sendKillMessage(const std::string& message, unsigned int clientID) const;
     125            void sendDeathMessage(const std::string& message, unsigned int clientID) const;
     126            void sendStaticMessage(const std::string& message, unsigned int clientID, const ColourValue& colour) const;
     127            void sendFadingMessage(const std::string& message, unsigned int clientID) const;
    131128
    132             void dispatchAnnounceMessage(const std::string& message);
    133             void dispatchKillMessage(const std::string& message);
    134             void dispatchDeathMessage(const std::string& message);
    135             void dispatchStaticMessage(const std::string& message,const ColourValue& colour);
    136             void dispatchFadingMessage(const std::string& message);
    137            
     129            void dispatchAnnounceMessage(const std::string& message) const;
     130            void dispatchKillMessage(const std::string& message) const;
     131            void dispatchDeathMessage(const std::string& message) const;
     132            void dispatchStaticMessage(const std::string& message,const ColourValue& colour) const;
     133            void dispatchFadingMessage(const std::string& message) const;
     134
    138135        protected:
    139136            void start(void); // Inform the GametypeInfo that the game has started.
     
    165162            unsigned int counter_; //!< The current integer value of the start countdown, the start countdown counter.
    166163            std::string hudtemplate_;
    167            
     164
    168165            std::set<PlayerInfo*> spawnedPlayers_; //!< A set of players that are currently spawned.
    169166            bool spawned_; //!< Whether the local Player is currently spawned.
  • code/trunk/src/orxonox/infos/PlayerInfo.cc

    r9257 r9348  
    173173        this->changedControllableEntity();
    174174
    175                 RadarViewable* radarviewable = orxonox_cast<RadarViewable*>(entity);
     175        RadarViewable* radarviewable = orxonox_cast<RadarViewable*>(entity);
    176176        if (radarviewable != NULL)
    177177            radarviewable->setRadarName(this->getName());
  • code/trunk/src/orxonox/interfaces/Pickupable.cc

    r8866 r9348  
    3939
    4040#include "infos/PlayerInfo.h"
    41 #include "pickup/PickupIdentifier.h"
    4241#include "worldentities/pawns/Pawn.h"
    4342
     
    5251        Constructor. Registers the objects and initializes its member variables.
    5352    */
    54     Pickupable::Pickupable() : pickupIdentifier_(NULL), used_(false), pickedUp_(false)
     53    Pickupable::Pickupable() : used_(false), pickedUp_(false)
    5554    {
    5655        RegisterRootObject(Pickupable);
     
    5857        this->carrier_ = NULL;
    5958
    60         this->pickupIdentifier_ = new PickupIdentifier(this);
    6159        this->beingDestroyed_ = false;
    6260        this->enabled_ = true;
     
    6967    Pickupable::~Pickupable()
    7068    {
    71         if(this->pickupIdentifier_ != NULL)
    72         {
    73             orxout(verbose, context::pickups) << "Pickupable (&" << this << ") destroyed." << endl;
    74             this->pickupIdentifier_->destroy();
    75         }
    7669    }
    7770
     
    10497    void Pickupable::destroyPickup(void)
    10598    {
    106         if(!this->beingDestroyed_)
     99        if(!this->isBeingDestroyed())
    107100            this->OrxonoxClass::destroy();
    108101        else
     
    329322    /**
    330323    @brief
    331         Creates a duplicate of the Pickupable.
    332     @return
    333         Returns the clone of this pickup as a pointer to a Pickupable.
    334     */
    335     Pickupable* Pickupable::clone(void)
    336     {
    337         OrxonoxClass* item = NULL;
    338         this->clone(item);
    339 
    340         Pickupable* pickup = dynamic_cast<Pickupable*>(item);
    341 
    342         orxout(verbose, context::pickups) << "Pickupable (&" << this << ") cloned. Clone is new Pickupable (&" << pickup << ")." << endl;
    343         return pickup;
    344     }
    345 
    346     /**
    347     @brief
    348324        Method to transcribe a Pickupable as a Rewardable to the player.
    349325    @param player
  • code/trunk/src/orxonox/interfaces/Pickupable.h

    r8866 r9348  
    5353        Pickups (@ref orxonox::Pickupable "Pickupables") are objects that (quite unsurprisingly) can be picked up. Additionally they can be used and unused (transition from used to not used), and also dropped.
    5454
    55         A class of Pickups can incorporate many different types of pickups (see @ref orxonox::PickupIdentifier "PickupIdentifier"), each type is uniquely defined by a @ref orxonox::PickupIdentifier "PickupIdentifier". Each pickup has such an identifier identiying its type. This means that two pickups of the same type have identifiers which are equal.
    56 
    5755    @author
    5856        Damian 'Mozork' Frick
     
    6967        public:
    7068            virtual ~Pickupable(); //!< Default destructor.
     69
     70            //! @brief Returns the representation name which refers to the name of the PickupRepresentation that is used to represent this pickup.
     71            virtual const std::string& getRepresentationName() const = 0;
    7172
    7273            /**
     
    136137            bool addTarget(Identifier* identifier); //!< Add a class, representetd by the input Identifier, as target of this Pickupable.
    137138
    138             Pickupable* clone(void); //!< Creates a duplicate of the Pickupable.
    139             /**
    140             @brief Creates a duplicate of the input OrxonoxClass.
    141                    This method needs to be implemented by any Class inheriting from Pickupable.
    142             @param item A reference to a pointer to the OrxonoxClass that is to be duplicated.
    143             */
    144             virtual void clone(OrxonoxClass*& item) {}
    145 
    146             /**
    147             @brief Get the PickupIdentifier of this Pickupable.
    148             @return Returns a pointer to the PickupIdentifier of this Pickupable.
    149             */
    150             virtual const PickupIdentifier* getPickupIdentifier(void) const
    151                 { return this->pickupIdentifier_; }
    152 
    153139            bool setUsed(bool used); //!< Sets the Pickupable to used or unused, depending on the input.
    154140            bool setPickedUp(bool pickedUp); //!< Helper method to set the Pickupable to either picked up or not picked up.
     
    158144
    159145        protected:
    160             /**
    161             @brief Helper method to initialize the PickupIdentifier.
    162             */
    163             void initializeIdentifier(void) {}
    164 
    165146            virtual void preDestroy(void); //!< A method that is called by OrxonoxClass::destroy() before the object is actually destroyed.
    166147            virtual void destroyPickup(void); //!< Destroys a Pickupable.
     
    174155
    175156            /**
     157            @brief Check whether the Pickupable is in the process of being destroyed.
     158            @return Returns true if so.
     159            */
     160            inline bool isBeingDestroyed(void)
     161                { return this->beingDestroyed_; }
     162
     163            /**
    176164            @brief Facilitates the creation of a PickupSpawner upon dropping of the Pickupable.
    177                    This method must be implemented by any class directly inheriting from Pickupable. It is most easily done by just creating a new DroppedPickup, e.g.:
    178                    DroppedPickup(BaseObject* creator, Pickupable* pickup, PickupCarrier* carrier, float triggerDistance);
     165                   This method must be implemented by any class directly inheriting from Pickupable.
    179166            @return Returns true if a spawner was created, false if not.
    180167            */
    181168            virtual bool createSpawner(void) = 0;
    182 
    183             PickupIdentifier* pickupIdentifier_; //!< The PickupIdentifier of this Pickupable.
    184169
    185170        private:
     
    203188    //! SUPER functions.
    204189    SUPER_FUNCTION(10, Pickupable, changedUsed, false);
    205     SUPER_FUNCTION(12, Pickupable, changedCarrier, false);
    206     SUPER_FUNCTION(13, Pickupable, changedPickedUp, false);
    207     SUPER_FUNCTION(11, Pickupable, clone, false);
     190    SUPER_FUNCTION(11, Pickupable, changedCarrier, false);
     191    SUPER_FUNCTION(12, Pickupable, changedPickedUp, false);
    208192}
    209193
  • code/trunk/src/orxonox/interfaces/RadarViewable.h

    r9257 r9348  
    6161        virtual ~RadarViewable();
    6262
    63                 virtual void setRadarName(const std::string& name)
    64                         {
    65                                 if (this->radarName_ != name)
    66                                 {
    67                                         this->radarName_ = name;
    68                                         this->settingsChanged();
    69                                 }
    70                         }
    71                 const std::string& getRadarName() const
    72                         { return this->radarName_; }
     63        virtual void setRadarName(const std::string& name)
     64            {
     65                if (this->radarName_ != name)
     66                {
     67                    this->radarName_ = name;
     68                    this->settingsChanged();
     69                }
     70            }
     71        const std::string& getRadarName() const
     72            { return this->radarName_; }
    7373
    7474        inline void setRadarObjectCamouflage(float camouflage)
     
    163163        ColourValue radarObjectColour_;
    164164        float scale_;
    165                 std::string radarName_;
     165        std::string radarName_;
    166166    };
    167167}
  • code/trunk/src/orxonox/worldentities/ControllableEntity.cc

    r9016 r9348  
    8787        this->setPriority( Priority::VeryHigh );
    8888        this->registerVariables();
    89         this->team_ = -1;
     89        this->team_ = -1;
    9090    }
    9191
     
    266266                this->cameraPositionRootNode_->_update(true, false); // update the camera node because otherwise the camera will drag back in position which looks strange
    267267
    268                 NewHumanController* controller = dynamic_cast<NewHumanController*>(this->getController());
     268                NewHumanController* controller = orxonox_cast<NewHumanController*>(this->getController());
    269269                if (controller)
    270270                    controller->centerCursor();
  • code/trunk/src/orxonox/worldentities/ControllableEntity.h

    r9255 r9348  
    164164            void setTargetInternal( uint32_t targetID );
    165165
    166             inline void setTeam(int team)
    167                 { this->team_ = team; }
    168             inline int getTeam() const
    169                 { return this->team_; }
     166            inline void setTeam(int team)
     167                { this->team_ = team; }
     168            inline int getTeam() const
     169                { return this->team_; }
    170170
    171171        protected:
     
    243243            WeakPtr<WorldEntity> target_;
    244244
    245             int team_ ; //<! teamnumber
     245            int team_ ; //<! teamnumber
    246246    };
    247247}
  • code/trunk/src/orxonox/worldentities/pawns/Pawn.cc

    r9257 r9348  
    7575        this->lastHitOriginator_ = 0;
    7676
     77        // set damage multiplier to default value 1, meaning nominal damage
     78        this->damageMultiplier_ = 1;
     79
    7780        this->spawnparticleduration_ = 3.0f;
    7881
     
    228231    void Pawn::damage(float damage, float healthdamage, float shielddamage, Pawn* originator)
    229232    {
     233        // Applies multiplier given by the DamageBoost Pickup.
     234        if (originator)
     235            damage *= originator->getDamageMultiplier();
     236
    230237        if (this->getGametype() && this->getGametype()->allowPawnDamage(this, originator))
    231238        {
  • code/trunk/src/orxonox/worldentities/pawns/Pawn.h

    r9254 r9348  
    144144            virtual void addedWeaponPack(WeaponPack* wPack) {}
    145145
    146             inline const WorldEntity* getWorldEntity() const
    147                 { return const_cast<Pawn*>(this); }
    148 
    149146            inline void setSpawnParticleSource(const std::string& source)
    150147                { this->spawnparticlesource_ = source; }
     
    162159                { return this->numexplosionchunks_; }
    163160
     161            // These are used with the Damage Boost Pickup to use the damage multiplier.
     162            inline void setDamageMultiplier(float multiplier)
     163                { this->damageMultiplier_ = multiplier; }
     164            inline float getDamageMultiplier() const
     165                { return this->damageMultiplier_; }
     166
     167
    164168            virtual void startLocalHumanControl();
    165169
     
    203207            float maxShieldHealth_;
    204208            float initialShieldHealth_;
    205             float shieldAbsorption_; // Has to be between 0 and 1
     209            float shieldAbsorption_; ///< Has to be between 0 and 1
    206210            float reloadRate_;
    207211            float reloadWaitTime_;
    208212            float reloadWaitCountdown_;
     213
     214            float damageMultiplier_; ///< Used by the Damage Boost Pickup.
    209215
    210216            WeakPtr<Pawn> lastHitOriginator_;
  • code/trunk/src/orxonox/worldentities/pawns/SpaceShip.cc

    r8892 r9348  
    133133    {
    134134        SetConfigValue(bInvertYAxis_, false).description("Set this to true for joystick-like mouse behaviour (mouse up = ship down).");
    135        
     135
    136136        SetConfigValueExternal(bEnableMotionBlur_, "GraphicsSettings", "enableMotionBlur", true)
    137137            .description("Enable or disable the motion blur effect when moving very fast")
     
    503503    void SpaceShip::resetCamera()
    504504    {
    505         if(this->hasLocalController() && this->hasHumanController())
    506         {
     505        if(this->hasLocalController() && this->hasHumanController())
     506        {
    507507            Camera *camera = this->getCamera();
    508508            if (camera == 0)
     
    514514            camera->setPosition(this->cameraOriginalPosition_);
    515515            camera->setOrientation(this->cameraOriginalOrientation_);
    516         }
     516        }
    517517    }
    518518
Note: See TracChangeset for help on using the changeset viewer.