Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 19, 2008, 11:50:03 AM (15 years ago)
Author:
dafrick
Message:

Some tweaks and solved some bugs…

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/questsystem2/src/orxonox/objects/quest/QuestEffectBeacon.cc

    r2209 r2221  
    2727 */
    2828
     29/**
     30    @file QuestEffectBeacon.cc
     31    @brief
     32        Implementation of the QuestEffectBeacon class.
     33*/
     34
    2935#include "OrxonoxStableHeaders.h"
    3036#include "QuestEffectBeacon.h"
     
    4450    CreateFactory(QuestEffectBeacon);
    4551
     52    /**
     53    @brief
     54        Constructor. Registers the object and initializes defaults.
     55    */
    4656    QuestEffectBeacon::QuestEffectBeacon(BaseObject* creator) : PositionableEntity(creator)
    4757    {
     
    4959       
    5060        this->status_ = QuestEffectBeaconStatus::active;
    51         this->times_ = -1;
    52         this->trigger_ = NULL;
    53     }
    54 
     61        this->times_ = INFINITE;
     62    }
     63
     64    /**
     65        Destructor.
     66    */
    5567    QuestEffectBeacon::~QuestEffectBeacon()
    5668    {
    5769    }
    5870   
     71    /**
     72    @brief
     73        Method for creating a QuestEffectBeacon object through XML.
     74    */
    5975    void QuestEffectBeacon::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    6076    {
     
    6278
    6379        XMLPortParam(QuestEffectBeacon, "times", setTimes, getTimes, xmlelement, mode);
    64         XMLPortObject(QuestEffectBeacon, QuestEffect, "", addEffect, getEffect, xmlelement, mode);
    65         XMLPortObject(QuestEffectBeacon, PlayerTrigger, "", addTrigger, getTrigger, xmlelement, mode);
    66     }
    67    
     80        XMLPortObject(QuestEffectBeacon, QuestEffect, "effects", addEffect, getEffect, xmlelement, mode);
     81    }
     82   
     83    /**
     84    @brief
     85        Processes an event for this QuestEffectBeacon.
     86    */
    6887    void QuestEffectBeacon::processEvent(Event& event)
    6988    {
     89        SUPER(QuestEffectBeacon, processEvent, event);
     90   
    7091        SetSubclassEvent(QuestEffectBeacon, "execute", execute, event, PlayerTrigger);
    7192    }
    7293   
     94    /**
     95    @brief
     96        Executes the QuestEffectBeacon.
     97        This means extracting the ControllableEntity from the PlayerTrigger, provided by the Event causing the execution, and the extracting the PlayerInfo from the received ControllableEntity and invoking the QuestEffectbeacon's QuestEffects on the received PlayerInfo.
     98    @param b
     99        TDO: What is this???
     100    @param trigger
     101        Apointer to the PlayerTrigger that threw the Event.
     102    @return
     103        Returns true if successfully executed, false if not.
     104    */
    73105    bool QuestEffectBeacon::execute(bool b, PlayerTrigger* trigger)
    74106    {
    75107        if(!b)
    76108        {
     109            //TDO: Better message, please.
    77110            COUT(2) << "b is false." << std::endl;
    78111        }
    79         if(!(this->isActive()))
     112        if(!(this->isActive())) //!< If the QuestEffectBeacon is inactive it cannot be executed.
    80113        {
    81114            COUT(3) << "The QuestEffectBeacon is inactive." << std::endl;
    82115            return false;
    83116        }
    84 
     117       
     118        if(!trigger->isForPlayer()) //!< The PlayerTrigger is not exclusively for ControllableEntities which means we cannot extract one.
     119        {
     120            return false;
     121        }
     122
     123        //! Extracting the ControllableEntity form the PlayerTrigger.
    85124        ControllableEntity* entity = trigger->getTriggeringPlayer();
    86125
     
    91130        }
    92131       
     132        //! Extract the PlayerInfo from the ControllableEntity.
    93133        PlayerInfo* player = entity->getPlayer();
    94134       
     
    99139        }
    100140
    101         COUT(3) << "QuestEffectBeacon executed on player: " << player << " ." << std::endl;       
    102 
    103         bool check = QuestEffect::invokeEffects(player, this->effects_);
     141        COUT(3) << "QuestEffectBeacon executed on player: " << player << " ." << std::endl;
     142
     143        bool check = QuestEffect::invokeEffects(player, this->effects_); //!< Invoke the QuestEffects on the PlayerInfo.
    104144        if(check)
    105145        {
    106             this->decrementTimes();
     146            this->decrementTimes(); //!< Decrement the number of times the beacon can be used.
    107147            return true;
    108148        }
    109        
     149
    110150        return false;
    111151    }
    112152   
    113     bool QuestEffectBeacon::isActive(void)
    114     {
    115         return this->status_ == QuestEffectBeaconStatus::active;
    116     }
    117    
     153    /**
     154    @brief
     155        Set the status of the QuestEffectBeacon.
     156    @param activate
     157        If true the QuestEffectBeacon is activated, if false it is deactivated.
     158    @return
     159        Returns whether the activation/deactivation was successful.
     160    */
     161    bool QuestEffectBeacon::setActive(bool activate)
     162    {
     163        if(this->getTimes() == 0 && activate) //!< A QuestEffectBeacon that can be executed only 0 times is always inactive.
     164        {
     165            return false;
     166        }
     167       
     168        if(activate)
     169        {
     170            this->status_ = QuestEffectBeaconStatus::active;
     171            return true;
     172        }
     173       
     174        this->status_ = QuestEffectBeaconStatus::inactive;
     175        return true;
     176    }
     177   
     178    /**
     179    @brief
     180        Decrement the number of times the QuestEffectBeacon can be executed.
     181    @return
     182        Returns true if successful.
     183    */
    118184    bool QuestEffectBeacon::decrementTimes(void)
    119185    {
    120         if(!(this->isActive()))
    121         {
    122             return false;
    123         }
    124         if(this->getTimes() == -1)
     186        if(!(this->isActive())) //!< The QuestEffectBeacon mus be active to decrement the number of times it can be executed.
     187        {
     188            return false;
     189        }
     190        if(this->getTimes() == INFINITE) //!< If times is infinity the QuestEffectBeacon can be executed an infinite number fo times.
    125191        {
    126192            return true;
    127193        }
    128194       
    129         this->times_ = this->times_ - 1;
    130         if(this->getTimes() == 0)
     195        this->times_ = this->times_ - 1; //!< Decrement number of times the QuestEffectBeacon can be executed.
     196        if(this->getTimes() == 0) //!< Set the QuestEffectBeacon to inactive when the number of times it can be executed is reduced to 0.
    131197        {
    132198            this->status_ = QuestEffectBeaconStatus::inactive;
     
    136202    }
    137203   
    138    
     204    /**
     205    @brief
     206        Set the number of times the QuestEffectBeacon can be executed.
     207        The number must be eighter <= 0, or INFINITY which is '-1'.
     208    @param n
     209        The number of times the QuestEffectBeacon can be executed.
     210        The number must be eighter <= 0, or INFINITY which is '-1'.
     211    @return
     212        Returns true if successful.
     213    */
    139214    bool QuestEffectBeacon::setTimes(const int & n)
    140215    {
    141         if(n < -1)
     216        if(n < 0 && n != INFINITE)
    142217        {
    143218            return false;
     
    148223    }
    149224   
    150    
    151     /**
    152     @brief
    153 
     225    /**
     226    @brief
     227        Adds a QuestEffect to the QuestEffectBeacon.
     228    @param effect
     229        A pointer to the QuestEffect to be added.
     230    @return
     231        Returns true if successful.
    154232    */
    155233    bool QuestEffectBeacon::addEffect(QuestEffect* effect)
    156234    {
    157         if(effect == NULL)
     235        if(effect == NULL) //!< NULL-pointers are not well liked here...
    158236        {
    159237            COUT(2) << "A NULL-QuestEffect was trying to be added" << std::endl;
     
    167245    }
    168246   
    169     bool QuestEffectBeacon::addTrigger(PlayerTrigger* trigger)
    170     {
    171         if(this->trigger_ != NULL)
    172         {
    173            COUT(2) << "A Trigger was trying to be added, where one was already set." << std::endl;
    174            return false;
    175         }
    176         if(trigger == NULL)
    177         {
    178             COUT(2) << "A NULL-Trigger was trying to be added." << std::endl;
    179             return false;
    180         }
    181        
    182         COUT(3) << "A Trigger was added to a QuestEffectBeacon." << std::endl;
    183         this->trigger_ = trigger;
    184         return true;
    185     }
    186    
    187      /**
    188     @brief
    189 
     247    /**
     248    @brief
     249        Returns the QuestEffect at the given index.
     250    @param index
     251        The index.
     252    @return
     253        Returns a pointer to the QuestEffect at the given index.
    190254    */
    191255    const QuestEffect* QuestEffectBeacon::getEffect(unsigned int index) const
     
    203267    }
    204268
    205     const PlayerTrigger* QuestEffectBeacon::getTrigger(unsigned int index) const
    206     {
    207         if(index == 0)
    208         {
    209             return this->trigger_;
    210         }
    211        
    212         return NULL;
    213     }
    214 
    215269}
Note: See TracChangeset for help on using the changeset viewer.