/****************************************************************
**
** Attal : Lords of Doom
**
** genericEvent.cpp
** this is a template for all .cpp files
**
** Version : $Id: genericEvent.cpp,v 1.2 2003/08/27 13:09:25 audoux Exp $
**
** Author(s) : Pascal Audoux
**
** Date : 17/12/2002
**
** Licence :
**	This program is free software; you can redistribute it and/or modify
**   	it under the terms of the GNU General Public License as published by
**     	the Free Software Foundation; either version 2, or (at your option)
**      any later version.
**
**	This program is distributed in the hope that it will be useful,
** 	but WITHOUT ANY WARRANTY; without even the implied warranty of
**	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
**	GNU General Public License for more details.
**
****************************************************************/

#include "genericEvent.h"

// generic include files
// include files for QT
#include <qtextstream.h>
// application specific include files
#include "libCommon/artefact.h"
#include "libCommon/condition.h"
#include "libCommon/dataTheme.h"
#include "libCommon/genericBonus.h"
#include "libCommon/genericChest.h"
#include "libCommon/log.h"

//
// ----- GenericEvent -----
//

GenericEvent::GenericEvent()
{
	_type = EventNone;
	_cell = 0;
	_condition = 0;
	_artefact = 0;
	_bonus = 0;
	_chest = 0;
}

GenericEvent::~GenericEvent()
{
	if( _artefact ) {
		delete _artefact;
	}
	if( _bonus ) {
		delete _bonus;
	}
	if( _chest ) {
		delete _chest;
	}
}

void GenericEvent::setCell( GenericCell * cell )
{
	_cell = cell;
}

void GenericEvent::save( QTextStream * ts, int indent )
{
	indentation( ts, indent );
	*ts << "<event type=\"" << (uint)_type << "\">" << endl;

	indentation( ts, indent+1 );
	*ts << "<col>" << _cell->getCol() << "</col>" << endl;

	indentation( ts, indent+1 );
	*ts << "<row>" << _cell->getRow() << "</row>" << endl;

	if( _artefact ) {
		_artefact->save( ts, indent+1 );
	}
	if( _bonus ) {
		_bonus->save( ts, indent+1 );
	}
	if( _chest ) {
		_chest->save( ts, indent+1 );
	}

	indentation( ts, indent );
	*ts << "</event>" << endl;
	*ts << flush;
}

void GenericEvent::setArtefact( GenericArtefact * artefact )
{
	_type = EventArtefact;
	_artefact = artefact;
	if( _bonus ) {
		delete _bonus;
		_bonus = 0;
	}
	if( _chest ) {
		delete _chest;
		_chest = 0;
	}
}

void GenericEvent::setBonus( GenericBonus * bonus )
{
	_type = EventBonus;
	_bonus = bonus;
	if( _artefact ) {
		delete _artefact;
		_artefact = 0;
	}
	if( _chest ) {
		delete _chest;
		_chest = 0;
	}
}

void GenericEvent::setChest( GenericChest * chest )
{
	_type = EventChest;
	_chest = chest;
	if( _artefact ) {
		delete _artefact;
		_artefact = 0;
	}
	if( _bonus ) {
		delete _bonus;
		_bonus = 0;
	}
}

