/***************************************************************************
 *   Copyright (C) 2004 by ian reinhart geiser                             *
 *   ian@geiseri.com                                                       *
 *                                                                         *
 *   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.             *
 ***************************************************************************/
#ifndef UTIL_H
#define UTIL_H
#include <Qt>
#include <stdlib.h>
#include <time.h>

static void seed()
{
	unsigned int seed = time(NULL);
	::srand(seed);
}

static int random( int min, int max )
{
	int end = max - min;
	return min + 1 + (::rand()%end);
}

static int roll( int number, int sides )
{
	int count = 0;
	for( int idx = 0; idx < number; ++idx)
		count += (int) random(1,sides);
	return count;
}

template <class T>
static T max( T value1, T value2 )
{
	if ( value1 > value2 )
		return value1;
	if ( value2 > value1 )
		return value2;
	return value1; // equal
}

template <class T>
static T range( T start, T end, T value)
{
	if( value < start )
		value = start;
	if( value > end )
		value = end;
	return value;
}

enum Attack { CUT, BASH, THRUST };
#endif

