/***************************************************************************
 *   Copyright (C) 2004 by Raphael Langerhorst                             *
 *   raphael-langerhorst@gmx.at                                            *
 *                                                                         *
 *   Permission is hereby granted, free of charge, to any person obtaining *
 *   a copy of this software and associated documentation files (the       *
 *   "Software"), to deal in the Software without restriction, including   *
 *   without limitation the rights to use, copy, modify, merge, publish,   *
 *   distribute, sublicense, and/or sell copies of the Software, and to    *
 *   permit persons to whom the Software is furnished to do so, subject to *
 *   the following conditions:                                             *
 *                                                                         *
 *   The above copyright notice and this permission notice shall be        *
 *   included in all copies or substantial portions of the Software.       *
 *                                                                         *
 *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       *
 *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    *
 *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*
 *   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR     *
 *   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
 *   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
 *   OTHER DEALINGS IN THE SOFTWARE.                                       *
 ***************************************************************************/

#ifndef GBEGRADIATINGAGENTH
#define GBEGRADIATINGAGENTH

#include <GAgent.h>

namespace GBE
{

/**
  \class GRadiatingAgent GRadiatingAgent.h
  \brief Periodically radiates an influence.

  Radiates a fraction (Fraction) of the own energy as influence every
  few milliseconds (according to the Msleep attribute). If the element
  has a form then a GPositionalInfluence is used, otherwise a
  GElementInfluence.
  
  A range can be specified in which the agent should keep the element's
  energy amount. If the energy amount is below the minimum then no
  influence is emitted. If the energy amount is above the maximum then
  more energy is emitted to get down to the maximum amount.
  
  Adds the following xml data to the element data:
  <radiation>
    <fraction>double value</fraction>
    <minenergy>double value</minenergy>
    <maxenergy>double value</maxenergy>
    <interval>unsigned long integer</interval> <!-- milliseconds -->
  </radiation>
  
  @see GPositionalInfluence.
*/
class GRadiatingAgent : public GCS::GAgent
{
  Q_OBJECT
  
  public:
    /**
     * Constructor. Allows for paramter initialisation.
     */
    GRadiatingAgent();

    /**
     * Destructor.
     */
    virtual ~GRadiatingAgent();
    
    /**
     * Periodically radiates an influence.
     * @see Msleep.
     */
    virtual void run();
    
    /**
     * Initializes radiation fraction in the element data.
     * @param radiation_fraction If current energy amount is between
     *                           MinEnergyAmount and MaxEnergyAmount
     *                           then this fraction of own energy
     *                           amount is emitted.
     */
    virtual void initFraction(double radiation_fraction);
    
    /**
     * Initializes minimum energy amount in the element data.
     * @param min_energy_amount The agent won't radiate any influence
     *                          if current energy amount is less
     *                          than min_energy_amount.
     */
    virtual void initMinEnergy(double min_energy_amount);
    
    /**
     * Initializes maximum energy amount in the element data.
     * @param max_energy_amount If current energy amount is greater
     *                          than MaxEnergyAmount the agent will
     *                          emit just as much to reach max_energy_amount.
     */
    virtual void initMaxEnergy(double max_energy_amount);

    /**
     * Initializes radiation interval in the element data.
     * @param radiate_interval Determines the time between which
     *                         influences are radiated. value must
     *                         be in milliseconds.
     */
    virtual void initInterval(unsigned long radiate_interval);
};

}

#endif
