#ifndef POWERSTRUGGLE_H
#define POWERSTRUGGLE_H
#include "delayeddamage.h"
#define FRONTPS 0
#define SIDEPS 1

class CExplodingAttack;
struct psAttack
{
	psAttack *next;
	CExplodingAttack *attack;
	int side;
};

/**
* Powerstruggle entity
* @version 29-11-2002
* @author Herwin 'harSens' van Welbergen
*/
class CPowerStruggle:public CMagicAttack
{	
public:
	/**
	 * Creates a powerstruggle
	 * @param CExplodingAttack *a1:
	 * @param CExplodingAttack *a2: The 2 exploding attacks that started the ps
	 * @param type: the type, FRONTPS or SIDEPS
	 */
	static CPowerStruggle *CreatePowerStruggle(CExplodingAttack *a1, CExplodingAttack *a2, int type);

	/**
	 * PS think, sets velocity of struggling attacks
	 */
	void EXPORT PSFrontThink();

	/**
	 * PS think, sets velocity of struggling attacks
	 */
	void EXPORT PSSideThink();

	/**
	 * Adds an attack to the powerstruggle
	 * precondition: ps is not full
	 * @param CExplodingAttack *attack: the attack to add
	 * @param side, side to join, 0 for none
	 */
	void AddAttack(CExplodingAttack *attack,int side);

	/**
	 * Removes the powerstruggle entity 
	 */
	virtual void Remove();

	/**
	 * Checks if the attack is in this ps
	 * @param CBaseEntity *attack: the attack to check for
	 * @return BOOL: true if it's in, false otherwise
	 */
	BOOL InStruggle(entvars_t *attack);

	/**
	 * Get the strongest attack, based on struggle ration
	 * @return the strongest exploding attack
	 */
	CExplodingAttack* GetStrongestAttack();

	/**
	 * Checks if the powerstruggle is full, or we can add more
	 * @return BOOL: true if the ps is full
	 */
	BOOL IsFull();
	
	/**
	 * Gets the ps type
	 * @return int: FRONTPS or SIDEPS
	 */
	int GetType(){return m_iType;};

	/**
	 * Get the distance between the owners of the first 2 beams. Meaningfull for frontal ps only.
	 */
	double GetDistance();

	/**
	 * @param iDmg damage to add
	 * @param attack attack that adds damage
	 */
    void AddPSDamage(DelayedDamage *dDamage);

	psAttack *m_pAttack;
	int m_fExploding;
protected:
	void ApplyDelayedDamage();

	int m_iAttacks;
	float m_flIdleTime;
	int m_iType;
	DelayedDamage *m_pDelayedDamage;	
};
#endif
