<?php
/*
 *
 * @copyright (c) 2010 animegame.eu
 * @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public Licence
 *
 */
include "db.php";
include_once('path.inc.php'); // get the path ;)
include_once ('inclu/messagefunctions.inc.php');
include_once ('inclu/halloffame.inc.php');
include_once ('inclu/fruitdistribution.inc.php');
include_once ('inclu/exp.inc.php');
include_once (ROOT_PATH.'/include/usergroup.inc.php');
include_once ('inclu/turnier.inc.php');
include_once ('inclu/char.inc.php');

$turnier_kurz = 'grossst';
$turnier_name = 'Weltturnier Non-Fusion';


// calculate the avg level of the chars participating
$sql = '(Select distinct(char1) as x from turnier_kampf where art = \''.$turnier_kurz.'\' ) union (Select distinct(char2) as x from turnier_kampf where art = \''.$turnier_kurz.'\' )';

$charids = array();
$qry1 = mysql_query($sql);
while($row = mysql_fetch_assoc($qry1)){
	$charids[] = $row['x'];
}

$sql2 = 'Select avg(level) as dlevel from chars where id in ('.join(',', $charids).')';
$row = mysql_fetch_assoc(mysql_query($sql2));

$dlevel = ceil($row['dlevel']);

// do the stuff for the whole exp and money distribution there ;)
//$results = generateTournamentResults($turnier_kurz, 250000, 2000000);

// Franky && Sinnes request no more money for rounds
$results = generateTournamentResults($turnier_kurz, 250000, 0);
$rang1 = getChar($results[0][0]);

insertIntoHallOfFame($turnier_name, $rang1['id'], $rang1['besitzer']);

//$natur_frucht = mysql_num_rows(mysql_query("SELECT id FROM wochen_markt WHERE art='natur'"));		///wieviel TF gibt es?.

////////////////FRUCHT ARRAY
//include "array.php";
distributeParamecia($rang1['besitzer']);

//Schutz vor automatischem löschen hinzufügen für den sieger :)
$usergroups = getUserGroups($rang1['besitzer']);
if(!isUserInGroup($usergroups, INAKTIV_LOESCHSCHUTZ) && !isUserInGroup($usergroups, AKTIV_LOESCHSCHUTZ)) {
	addUserToGroup($rang1['besitzer'], INAKTIV_LOESCHSCHUTZ);
}

// Durchschnittslevel


$summe = 20000000/(1+exp(5-$dlevel/14));

// Now distribute the shop points ;)

$prices[] = 4000000; // 1.
$prices[] = 3000000;  // 2.
$prices[] = 2000000;  // 3. + 4.

$cprices[] = ceil($summe/2);
$cprices[] = ceil($summe/4);
$cprices[] = ceil($summe/8);

distributeUserPrices($prices, $results, $turnier_name);

#distributeShopPoints($prices, $results, $turnier_name);
// clan prices are not distributed anymore!!
//distributeClanPrices($cprices, $results, $turnier_name);

?>