Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 12, 2011, 7:50:43 PM (13 years ago)
Author:
jo
Message:

Ai and tutorial improvements merged back to the trunk. AI features: all weapons are used, the ai-firestrength is configurable, bots are able to collect pickups . I've set the tutorial level as default level.

Location:
code/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

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

    r8858 r8891  
    5050    CreateUnloadableFactory(NotificationDispatcher);
    5151
     52    registerMemberNetworkFunction(NotificationDispatcher, broadcastHelper);
    5253    registerMemberNetworkFunction(NotificationDispatcher, dispatch);
    5354
     
    6162
    6263        this->sender_ = NotificationListener::NONE;
     64        this->bBroadcast_ = false;
    6365        this->registerVariables();
    6466    }
     
    8183        SUPER(NotificationDispatcher, XMLPort, xmlelement, mode);
    8284
    83         XMLPortParam(NotificationDispatcher, "sender", getSender, setSender, xmlelement, mode);
    84        
    85         XMLPortEventSink(NotificationDispatcher, BaseObject, "trigger", trigger, xmlelement, mode); //TODO: Change BaseObject to MultiTrigger as soon as MultiTrigger is the base of all triggers.
     85        XMLPortParam(NotificationDispatcher, "sender", setSender, getSender, xmlelement, mode);
     86        XMLPortParam(NotificationDispatcher, "broadcast", setBroadcasting, isBroadcasting, xmlelement, mode);
     87
     88        XMLPortEventSink(NotificationDispatcher, BaseObject, "trigger", trigger, xmlelement, mode);
    8689    }
    8790
     
    100103    {
    101104        registerVariable(this->sender_, VariableDirection::ToClient);
     105    }
     106
     107    /**
     108    @brief
     109        Broadcasts a specific Notification.
     110    */
     111    void NotificationDispatcher::broadcast(void)
     112    {
     113        // TODO: Needed?
     114        const std::string message = this->createNotificationMessage();
     115        NotificationListener::sendNotification(message, this->getSender(), notificationMessageType::info, notificationSendMode::local);
     116
     117        // Broadcast
     118        if(!GameMode::isStandalone())
     119        {
     120            callMemberNetworkFunction(NotificationDispatcher, broadcastHelper, this->getObjectID(), NETWORK_PEER_ID_BROADCAST);
     121        }
     122    }
     123
     124    /**
     125    @brief
     126        Helper function for broadcast.
     127    */
     128    void NotificationDispatcher::broadcastHelper(void)
     129    {
     130        this->dispatch(Host::getPlayerID());
    102131    }
    103132
     
    110139    void NotificationDispatcher::dispatch(unsigned int clientId)
    111140    {
    112         if(GameMode::isStandalone() || Host::getPlayerID() == clientId || this->getSyncMode() == 0x0)
     141        // We don't call sendNotification() directly on the server, because if might be necessary that createNotificationMessage() is executed on the client as the message may be client-specific.
     142        if(GameMode::isStandalone() || Host::getPlayerID() == clientId || this->getSyncMode() == ObjectDirection::None)
    113143        {
    114144            const std::string message = this->createNotificationMessage();
     
    139169        orxout(verbose, context::notifications) << "NotificationDispatcher (&" << this << ") triggered." << endl;
    140170
     171        // If the NotificationDispatcher is set to broadcast.
     172        if(this->isBroadcasting())
     173        {
     174            this->broadcast();
     175            return true;
     176        }
     177
    141178        PlayerTrigger* pTrigger = orxonox_cast<PlayerTrigger*>(trigger);
    142179        PlayerInfo* player = NULL;
  • code/trunk/src/modules/notifications/NotificationDispatcher.h

    r7552 r8891  
    5050        A NotificationDispatcher is an entity that, upon being triggered, dispatches (or sends) a specified @ref orxonox::Notification "Notification".
    5151
    52         There is one parameter to be set, the @b sender . The sender specifies the part of Orxonox the sent @ref orxonox::Notification "Notification" comes from. The default value is set by the classes implementing NotificationDispatcher.
     52        There are two parameter to be set:
     53        - The @b sender . The sender specifies the part of Orxonox the sent @ref orxonox::Notification "Notification" comes from. The default value is set by the classes implementing NotificationDispatcher.
     54        - The @b broadcast . Specifies whether messages are broadcast (i.e. sent to all clients) or just sent to a specific player.
    5355
    5456        Its standard usage is:
     
    6264        </NotificationDispatcher>
    6365        @endcode
    64         But keep in mind, that NotificationDispatcher is an abstract class and in this example @ref orxonox::PlayerTrigger "PlayerTrigger" stands for any event that is caused by a @ref orxonox::PlayerTrigger "PlayerTrigger", so instead of @ref orxonox::PlayerTrigger "PlayerTrigger", there could be a @ref orxonox::DistanceTrigger "DistanceTrigger", or a @ref orxonox::DistanceMultiTrigger "DistanceMutliTrigger", or even an @ref orxonox::EventListener "EventListener" that waits for an event coming from any kind of @ref orxonox::PlayerTrigger "PlayerTrigger".
     66        But keep in mind, that NotificationDispatcher is an abstract class.
     67        Also in this example @ref orxonox::PlayerTrigger "PlayerTrigger" stands for any event that is caused by a @ref orxonox::PlayerTrigger "PlayerTrigger", so instead of @ref orxonox::PlayerTrigger "PlayerTrigger", there could be a @ref orxonox::DistanceTrigger "DistanceTrigger", or a @ref orxonox::DistanceMultiTrigger "DistanceMutliTrigger", or even an @ref orxonox::EventListener "EventListener" that waits for an event coming from any kind of @ref orxonox::PlayerTrigger "PlayerTrigger".
     68        If the NotificationDispatcher is not set to broadcast only events caused by @ref orxonox::PlayerTrigger "PlayerTriggers" trigger a message since the information obtained by the @ref orxonox::PlayerTrigger "PlayerTrigger" is used to identify the client to which the message should be sent.
    6569
    6670    @author
     
    8488            const std::string& getSender(void) const
    8589                { return this->sender_; }
    86                         /**
     90            /**
    8791            @brief Set the sender of the Notification dispatched by this NotificationDispatcher.
    8892            @param sender The name of the sender.
     
    9195                { this->sender_ = sender; }
    9296
    93             void dispatch(unsigned int clientId); //!< Dispatches a specific Notification.
     97            /**
     98            @brief Check whether the NotificationDispatcher is set to broadcast.
     99            @return Returns true if the NotificationDispatcher is set to broadcast.
     100            */
     101            bool isBroadcasting(void) const
     102                { return this->bBroadcast_; }
     103            /**
     104            @brief Set the NotificationDispatcher to broadcast.
     105            @param broadcast Whether the NotificationDispatcher is set to broadcast or singlecast.
     106            */
     107            void setBroadcasting(bool v)
     108                { this->bBroadcast_ = v; }
     109
     110            void broadcast(void); //!< Broadcasts a specific Notification.
     111            void broadcastHelper(void); //!< Helper function for broadcast.
     112            void dispatch(unsigned int clientId); //!< Dispatches a specific Notification to a given client.
    94113            bool trigger(bool triggered, BaseObject* trigger); //!< Is called when the NotificationDispatcher is triggered.
    95114
    96115        protected:
    97116            std::string sender_; //!< The name of the sender of the Notification dispatched by this NotificationDispatcher.
     117            bool bBroadcast_; //!< Whether the NotificationDispatcher is broadcasting.
    98118
    99119            void registerVariables(void); //!< Register some variables for synchronisation.
     
    105125            */
    106126            virtual const std::string& createNotificationMessage(void)
    107                 { return *(new std::string("")); }
     127                { return BLANKSTRING; }
    108128
    109129    };
Note: See TracChangeset for help on using the changeset viewer.