Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 9, 2010, 10:56:43 AM (14 years ago)
Author:
dafrick
Message:

Created a new MutliTrigger: EventMultiTrigger, which essentially does the same as EventTrigger but for every object that is a target as specified by teh EventMultiTrigger an Event is fired with information as being triggered by the target object.
This allows, e.g. to use the EventMultiTrigger to trigger QuestEffectBeacons.
I've also added a fireEvent() to Pawn such that an Event is fired when the Pawn is destroyed (forcebly). With EventMultiTrigger (but also with EventTrigger) one can now find out whether a Pawn died.
Here a little piece of example XML code to illustrate the usage:
<EventMutliTrigger name="trigger1">

<events>

<trigger>

<Spaceship />

</trigger>

</events>

</EventMultiTrigger>
To be able to implement this another feature was added to MultiTrigger, which is called broadcast. If enabled the MultiTrigger sends all Events triggered by NULL as to have come by all possible triggerers.

Additionally I've fixed a bug:
In DistanceMultiTrigger, an infinite loop occured under some circumstances. Not any more.

And did some niceifying (aka. documenting, renaming and code restructuring).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/modules/objects/triggers/MultiTrigger.h

    r6859 r6864  
    8282            'simultaniousTriggerers':   The number of simultanious triggerers limits the number of object that are allowed to trigger the MultiTrigger at the same time. Or a little more precisely, the number of distinct objects the MultiTrigger has 'triggered' states for, at each point in time.
    8383            'mode':                     The mode describes how the MultiTrigger acts in relation to all the MultiTriggers, that are appended to it. There are 3 modes: 'and', meaning that the MultiTrigger can only be triggered if all the appended MultiTriggers are active. 'or', meaning that the MultiTrigger can only triggered if at least one of the appendend MultiTriggers is active. And 'xor', meaning that the MultiTrigger can only be triggered if one and only one appended MultiTrigger is active. Notice, that I wrote 'can only be active', that implies, that there is an addtitional condition to the activity of the MultiTrigger and that is the fulfillment of the triggering condition (the MultiTrigger itself doesn't have one, but all derived classes should). Also bear in mind, that the activity of a MultiTrigger is still coupled to the object that triggered it. The default is 'and'.
     84            'broadcast'                 Broadcast is a bool, if true the MutliTrigger is in broadcast-mode, meaining, that all trigger events that are caused by no originator (originator is NULL) are broadcasted as having come from every possible originator, or more precisely as having come from all objects that are specified targets of this MultiTrigger.
    8485            'target':                   The target describes the kind of objects that are allowed to trigger this MultiTrigger. The default is 'Pawn'.
    8586            Also there is the possibility of appending MultiTriggers to the MultiTrigger just by adding them as subobjects in the XML description of your MultiTrigger.
     
    109110            @return The delay.
    110111            */
    111             inline float getDelay() const
     112            inline float getDelay(void) const
    112113                { return this->delay_; }
    113114
     
    122123            @return Returns true if the MultiTriger is in switch-mode.
    123124            */
    124             inline bool getSwitch() const
     125            inline bool getSwitch(void) const
    125126                { return this->bSwitch_; }
    126127
     
    135136            @return Returns true if the MultiTrigger stays active.
    136137            */
    137             inline bool getStayActive() const
     138            inline bool getStayActive(void) const
    138139                { return this->bStayActive_; }
    139140
     
    148149            @return The number of activations. -1 denotes infinity.
    149150            */
    150             inline int getActivations() const
     151            inline int getActivations(void) const
    151152                { return this->remainingActivations_; }
    152153
     
    174175            @return Returns true if the MultiTrigger is set to invert.
    175176            */
    176             inline bool getInvert() const
     177            inline bool getInvert(void) const
    177178                { return this->bInvertMode_; }
    178179
     
    193194
    194195            /**
     196            @brief Set the broadcast-mode of the MultiTrigger.
     197            @param bBroadcast If true the MultiTrigger is set to broadcast;
     198            */
     199            inline void setBroadcast(bool bBroadcast)
     200                { this->bBroadcast_ = bBroadcast; }
     201            /**
     202            @brief Get the broadcast-mode of the MultiTrigger.
     203            @return Returns true if the MultiTrigger is set to broadcast.
     204            */
     205            inline bool getBroadcast(void)
     206                { return this->bBroadcast_; }
     207
     208            /**
    195209            @brief Get whether the input object is a target of the MultiTrigger.
    196210            @param target A pointer to the object.
     
    198212            */
    199213            inline bool isTarget(BaseObject* target)
    200                 { return targetMask_.isIncluded(target->getIdentifier()); }
     214                { if(target == NULL) return true; else return targetMask_.isIncluded(target->getIdentifier()); }
    201215            void addTargets(const std::string& targets); //!< Add some target to the MultiTrigger.
    202216            void removeTargets(const std::string& targets); //!< Remove some target from the MultiTrigger.
     
    208222            virtual std::queue<MultiTriggerState*>* letTrigger(void); //!< This method is called by the MultiTrigger to get information about new trigger events that need to be looked at.
    209223
    210             void activityChanged(BaseObject* originator);
     224            void changeTriggered(BaseObject* originator = NULL); //!< This method can be called by any class inheriting from MultiTrigger to change it's triggered status for a specified originator.
    211225           
    212226            bool isModeTriggered(BaseObject* triggerer = NULL); //!< Checks whetherx the MultiTrigger is triggered concerning it's sub-triggers.
    213227            bool isTriggered(BaseObject* triggerer = NULL); //!< Get whether the MultiTrigger is triggered for a given object.
    214228
    215             void fire(bool status, BaseObject* originator = NULL);  //!< Helper method. Creates an event for the given status and originator and fires it.
     229            void fire(bool status, BaseObject* originator = NULL);  //!< Helper method. Creates an Event for the given status and originator and fires it.
     230            void broadcast(bool status); //!< Helper method. Broadcasts an Event for every object that is a target.
    216231
    217232            /**
     
    240255            static const std::string or_s;
    241256            static const std::string xor_s;
     257
     258            void subTrigggerActivityChanged(BaseObject* originator); //!< This method is called by any sub-trigger to advertise changes in it's state to it's parent-trigger.
    242259           
    243260            bool addState(MultiTriggerState* state); //!< Helper method. Adds a state to the state queue, where the state will wait to become active.
     
    266283            MultiTriggerMode::Value mode_; //!< The mode of the MultiTrigger.
    267284
     285            bool bBroadcast_; //!< Bool for the broadcast-mode, if true all triggers go to all possible targets.
     286
    268287            MultiTrigger* parentTrigger_;
    269288            std::set<MultiTrigger*> subTriggers_; //!< The sub-triggers of this MultiTrigger.
Note: See TracChangeset for help on using the changeset viewer.