/***************************************************************************
 *   Copyright (C) 2004 by Christian Hubinger                              *
 *   e9806056@student.tuwien.ac.at                                         *
 *                                                                         *
 *   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 of the License, 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.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#include "kflevel.h"

#include "kfconfiguration.h"
#include "kfgame.h"
#include "kdebug.h"

KFLevel::KFLevel( int level, int moves, int skill ){
	setLevel( level );
	setMoves( moves );
	setSkill( skill );
	m_maxAllowdMoves = moves *2;
	switch ( Config().m_GameLevel ) {
		case 0:
		m_maxAllowdMoves = moves *4;
		break;
		case 1:
		m_maxAllowdMoves = moves *3;
		break;
		case 2:
		m_maxAllowdMoves = moves *2;
		break;
		case 3:
		m_maxAllowdMoves = moves + moves/2;
		break;
	}
	
	m_finished = false;
	m_points = -1;
	m_bonus = -1;
	m_maxPoints = -1;
	m_maxBonus = -1;

}
KFLevel::~KFLevel(){}

void KFLevel::setLevel( int level) {
	m_level = level;
}

void KFLevel::setMoves( int moves ) {
	m_moves = moves;
}

void KFLevel::setSkill( int skill ) {
	m_skill = skill;
}

void KFLevel::finishedLevel( int moves_needed ) {
	m_finished = true;
	calculatePoints( moves_needed );
}

void KFLevel::calculatePoints( int moves_needed ) {
	m_bonus = 0;
	if ( m_moves > moves_needed ) {
		m_bonus = getMaxBonus() - 500*moves_needed;
	}
	m_points = getMaxPoints() / moves_needed;
}

int KFLevel::getPoints() const {
	return m_points;
};
int KFLevel::getBonus() const {
	return m_bonus;
};
int KFLevel::getScore() const {
	return m_points + m_bonus;
};
int KFLevel::getMaxPoints() const{
	switch ( m_skill ) {
		case KFGame::CHILD:
			return 1000*m_moves + getMaxBonus();
		break;
		case KFGame::BEGINNER:
			return  ( 1000*m_moves + getMaxBonus() ) * 1.3;
		break;
		case KFGame::ADVANCED:
			return ( 1000*m_moves + getMaxBonus() ) * 1.6;
		break;
		case KFGame::EXPERT:
			return ( 1000*m_moves + getMaxBonus() ) * 2;
		break;
		
		default:
			return 1000*m_moves + getMaxBonus();
			kdDebug() << "ERROR: INVALID skill set - ignoring it..." << endl;
		break;
	}
}

int KFLevel::getMaxBonus() const {
	return 500*m_moves;
}

