/*************************************************************************** * Copyright (C) 2003-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 GENERGYH #define GENERGYH #include namespace GCS { /** \class GEnergy GEnergy.h \brief Everything consists of energy, it thus classifies the element @author Raphael Langerhorst Everything consists of energy. So, naturally, the "content" of objects are certain energies. Only with energy can anything be done, thus, agents should be programmed with heavy usage of energy to determine their actions. Also, to actually perform an action an agent normally uses energy to determine the strength and character of the action. Energy consists of: - level - amount - sigma See the description of the attributes for details about how energy is represented. Togehter with the element's form the energy characterises the element. agents make the element "alive". @note The great idea behind the whole G System is that everything actually influences each other AND that the only attribute ever needed (if we don't specialise anything) is energy. This results in the fact that elements influence each other depending on their energies. Influencing behaviour is defined by the agents of an element. @see GAgent, GForm */ class GEnergy : public QMutex { protected: /** * The energy level is just like a frequency - * put on a very large scale it can either represent sound * (low frequency) or light (high frequency). * Even different light colours are just represented by * different energy levels. Thus every object gets its * individual characteristic by its energy. */ double Level; /** * Since it is not possible (hardware limitations) to represent every * atom as a seperate element the amount attribute is used to tell * how much of this energy is in the element. */ double Amount; /** * Sigma tells the range of the energy "level" ( in frequency, not space ); * the smaller sigma is the more "distinct" and less changeable the energy * is; it should thus be only influencable by a narrow band of frequency * (with low sigma). This is needed because we don't work on (sub-)atomic * levels where there is really only one energy level. So we get a * collection of energies with a general average level (this is where the * attribute "level" is set to) and a divergence around this average value. * The result is a certain amount of energy with a energy level of a * "normal distribution". */ double Sigma; public: /** * Construct an empty energy object. * All values are initialised to 0. */ GEnergy(); /** * This constructor initalises with given attributes. */ GEnergy(double level, double amount, double sigma); /** * Copy constructor */ GEnergy(const GEnergy& original); /** * if GEnergy is subclassed then a virtual destructor * ensures proper deletion of an GEnergy object * * @note There should be no reason for subclassing. * Please contact the author if you think there is. */ virtual ~GEnergy(); /** * @return energy level. */ double level() const; /** * @return energy amount. */ double amount() const; /** * @return energy sigma. */ double sigma() const; /** * Sets the energy to given values. */ void set(double level, double amount, double sigma); /** * Copies values from given energy. */ void set(const GEnergy original); /** * Copies values from given energy. */ void operator = (const GEnergy& original); /** * Removes given fraction of this energy and returns it. * This can be useful for sending out influences with some * fraction of the elements own energy. * @return fraction of own energy */ GEnergy take(double fraction); /** * Adds given energy. * @note The attributes are not just summed up, it's more * like mixing two kinds of liquids together. */ void put(const GEnergy& energy); }; } #endif