Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Sep 11, 2010, 10:20:44 AM (14 years ago)
Author:
dafrick
Message:

Merged notifications branch back to trunk.

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/modules/notifications/NotificationDispatcher.cc

    r7285 r7403  
    3939#include "Notification.h"
    4040#include "NotificationManager.h"
     41#include "interfaces/PlayerTrigger.h"
     42#include "infos/PlayerInfo.h"
     43#include "worldentities/pawns/Pawn.h"
    4144
    4245namespace orxonox
     
    8689    @brief
    8790        Dispatches a Notification with a message supplied by the createNotificationMessage() method, which can be overloaded.
     91    @param clientId
     92        The id of the client the notification should be dispatched to.
    8893    */
    89     void NotificationDispatcher::dispatch(void)
     94    void NotificationDispatcher::dispatch(unsigned int clientId)
    9095    {
    9196        const std::string message = this->createNotificationMessage();
    9297        Notification* notification = new Notification(this, message);
    9398
    94         notification->send(this->getSender());
     99        notification->send(clientId, this->getSender());
    95100    }
    96101
     
    103108        Returns true if the NotificationDispatcher was successfully triggered.
    104109    */
    105     bool NotificationDispatcher::trigger(bool triggered)
     110    bool NotificationDispatcher::trigger(bool triggered, BaseObject* trigger)
    106111    {
    107112        if(!triggered || !this->isActive()) // If the NotificationDispatcher is inactive it cannot be executed.
     
    110115        COUT(4) << "NotificationDispatcher (&" << this << ") triggered." << std::endl;
    111116
    112         this->dispatch();
     117        PlayerTrigger* pTrigger = orxonox_cast<PlayerTrigger*>(trigger);
     118        Pawn* pawn = NULL;
     119
     120        // If the trigger is a PlayerTrigger.
     121        if(pTrigger != NULL)
     122        {
     123            if(!pTrigger->isForPlayer())  //!< The PlayerTrigger is not exclusively for Pawns which means we cannot extract one.
     124                return false;
     125            else
     126                pawn = pTrigger->getTriggeringPlayer();
     127        }
     128        else
     129            return false;
     130
     131        if(pawn == NULL)
     132        {
     133            COUT(4) << "The QuestEffectBeacon was triggered by an entity other than a Pawn. (" << trigger->getIdentifier()->getName() << ")" << std::endl;
     134            return false;
     135        }
     136
     137        //! Extract the PlayerInfo from the Pawn.
     138        PlayerInfo* player = pawn->getPlayer();
     139
     140        if(player == NULL)
     141        {
     142            COUT(3) << "The PlayerInfo* is NULL." << std::endl;
     143            return false;
     144        }
     145
     146        this->dispatch(player->getClientID());
    113147
    114148        return true;
Note: See TracChangeset for help on using the changeset viewer.