Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 29, 2010, 1:16:16 PM (14 years ago)
Author:
dafrick
Message:

Created a new class of triggers called Multitriggers.
MultiTriggers are triggers which (as opposed to normal triggers) have a state for each object triggering the MultiTrigger, that means, that a MultiTrigger can be triggered for two different Players, while not being triggered for a third.
To go with this MultiTrigger I created a data structure (MultitriggerContainer), which helps relaying important information to the objects, that receive the Events of the trigger.
Also there is a MultiDistanceTrigger, which is just the DistanceTrigger as a MultiTrigger.

To make this work I had to make some adjustements to the eventsystem, namely an EventState can now be either an EventState (as it was before) or an EventSink, which means that every efent arriving at the EventState is processed as opposed to just the ones which change the state.
There is a new makro (XMLPortEventSink) to create an EventState with sink behaviour. It can be used exacly as the XMLPortEventState makro.

Location:
code/trunk/src/modules/questsystem
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/modules/questsystem/CMakeLists.txt

    r5781 r6800  
    3434  LINK_LIBRARIES
    3535    orxonox
     36    objects
    3637    overlays
    3738  SOURCE_FILES ${QUESTSYSTEM_SRC_FILES}
  • code/trunk/src/modules/questsystem/QuestEffectBeacon.cc

    r5938 r6800  
    3939#include "worldentities/pawns/Pawn.h"
    4040#include "interfaces/PlayerTrigger.h"
     41#include "objects/triggers/MultiTriggerContainer.h"
    4142#include "QuestEffect.h"
    4243
     
    7576        XMLPortObject(QuestEffectBeacon, QuestEffect, "effects", addEffect, getEffect, xmlelement, mode);
    7677
    77         XMLPortEventState(QuestEffectBeacon, PlayerTrigger, "execute", execute, xmlelement, mode);
     78        XMLPortEventState(QuestEffectBeacon, BaseObject, "execute", execute, xmlelement, mode); //TODO: Change BaseObject to MultiTrigger as soon as MultiTrigger is the base of all triggers.
    7879
    7980        COUT(3) << "New QuestEffectBeacon created." << std::endl;
     
    8485        SUPER(QuestEffectBeacon, XMLEventPort, xmlelement, mode);
    8586
    86         XMLPortEventState(QuestEffectBeacon, PlayerTrigger, "execute", execute, xmlelement, mode);
     87        XMLPortEventSink(QuestEffectBeacon, BaseObject, "execute", execute, xmlelement, mode);
    8788    }
    8889
     
    9293        This means extracting the Pawn from the PlayerTrigger, provided by the Event causing the execution, and the extracting the PlayerInfo from the received Pawn and invoking the QuestEffectbeacon's QuestEffects on the received PlayerInfo.
    9394    @param trigger
    94         Apointer to the PlayerTrigger that threw the Event.
     95        A pointer to the PlayerTrigger that threw the Event.
    9596    @return
    9697        Returns true if successfully executed, false if not.
    9798    */
    98     bool QuestEffectBeacon::execute(bool b, PlayerTrigger* trigger)
    99     {
     99    bool QuestEffectBeacon::execute(bool b, BaseObject* trigger)
     100    {
     101        //TODO: Remove debug output.
     102        COUT(1) << "Debug: Calling execute on QuestEffectBeacon." << std::endl;
     103       
    100104        if(!b)
    101105        {
     
    108112        }
    109113
    110         if(!trigger->isForPlayer()) //!< The PlayerTrigger is not exclusively for Pawns which means we cannot extract one.
    111         {
    112             return false;
    113         }
    114 
    115         //! Extracting the Pawn from the PlayerTrigger.
    116         Pawn* pawn = trigger->getTriggeringPlayer();
     114        PlayerTrigger* pTrigger = orxonox_cast<PlayerTrigger*>(trigger);
     115        MultiTriggerContainer* mTrigger = orxonox_cast<MultiTriggerContainer*>(trigger);
     116        Pawn* pawn = NULL;
     117       
     118        //! If the trigger is neither a Playertrigger nor a MultiTrigger (i.e. a MultitriggerContainer) we can do anything with it.
     119        if(pTrigger == NULL && mTrigger == NULL)
     120            return false;
     121       
     122        // If the trigger is a PlayerTrigger.       
     123        if(pTrigger != NULL)
     124        {
     125            if(!pTrigger->isForPlayer())  //!< The PlayerTrigger is not exclusively for Pawns which means we cannot extract one.
     126                return false;
     127            else
     128                pawn = pTrigger->getTriggeringPlayer();
     129        }
     130       
     131        // If the trigger is a MultiTrigger (i.e. a MultiTriggerContainer)
     132        if(mTrigger != NULL)
     133        {
     134            pawn = orxonox_cast<Pawn*>(mTrigger->getData());
     135        }
    117136
    118137        if(pawn == NULL)
  • code/trunk/src/modules/questsystem/QuestEffectBeacon.h

    r5938 r6800  
    8888            virtual void XMLEventPort(Element& xmlelement, XMLPort::Mode mode);
    8989
    90             bool execute(bool b, PlayerTrigger* trigger); //!< Executes the QuestEffects of the QuestEffectBeacon.
     90            bool execute(bool b, BaseObject* trigger); //!< Executes the QuestEffects of the QuestEffectBeacon.
    9191
    9292            /**
Note: See TracChangeset for help on using the changeset viewer.