<?php
echo "<div class='aut'>Топ Империи</div>\n";

$kup=abs(intval($_GET['kup']));
if($kup=='0'){
$all_p=mysql_result(mysql_query("SELECT COUNT(*) FROM `empire`"),0);
$k_page=k_page($all_p,$set['p_str']);
$page=page($k_page);
$start=$set['p_str']*$page-$set['p_str'];
$my_p=mysql_query("SELECT * FROM `empire` ORDER BY `win` DESC LIMIT $start,$set[p_str]");
while($arr=mysql_fetch_array($my_p)){
if($num==1){ 
echo "<div class='f1'>"; 
$num=0;}
else{ 
echo "<div class='f2'>"; 
$num=1;}
echo "<img src='empire.PNG'>\n";
echo "<a href='?do=9&amp;kup=$arr[id]'>".output_text($arr[name])."</a> ";
echo "(<font color='green'>$arr[win]</font>/<font color='red'>$arr[lose]</font>)<br/>\n";
echo "Владелец: ".mysql_result(mysql_query("SELECT `nick` FROM `user` WHERE `id`='".$arr['id_u']."'"),0)."";
echo "</div>";
}
if($k_page>'1')str('?do=9&amp;',$k_page,$page);
}
else
{
$all_p=mysql_result(mysql_query("SELECT COUNT(*) FROM `empire` WHERE `id`='$kup'"),0);
if($all_p!='0'){
$all_v=mysql_fetch_array(mysql_query("SELECT * FROM `empire` WHERE `id`='$kup'"));
$vek=$all_v['vek'];
$name=$all_v['name'];
$zoloto=$all_v['zoloto'];
$eda=$all_v['eda'];
$derevo=$all_v['derevo'];
$gelezo=$all_v['gelezo'];
$voin=$all_v['voin'];
$push=$all_v['push'];
echo "<div class='f1'><img src='empire.PNG'> ".output_text($name)."</div>\n
<div class='aut'>Информация</div>\n";
echo "<div class='f2'>Дерево: ".intval($derevo)."</div>\n";
echo "<div class='f1'>Золото: ".intval($zoloto)."</div>\n";
echo "<div class='f2'>Железо: ".intval($gelezo)."</div>\n";
echo "<div class='f1'>Еда: ".intval($eda)."</div>\n";
echo "<div class='f2'>Воины: ".intval($voin)."</div>\n";
echo "<div class='f1'>Пушки: ".intval($push)."</div>\n";
echo "<div class='f2'>Век: ".intval($vek)."</div>\n";

if(isset($_GET['ololo']) && $kup!=$q['id'] && $q['time_nap']<=time() && $vek!='1' && $q['vek']!='1' && $voin>='10' && $q['voin']>='10' && $push>='3' && $q['push']>='3'){
$ololo=round($push*3)+$voin;
$ololom=round($q['push']*3)+$q['voin'];
if($ololo>$ololom){
$timenap=time()+60*60*3;
$mvoin=round($q['voin']/2);
$mpush=round($q['push']/2);
msg('Вы потерпели поражение! У вас убито '.$mvoin.' воинов и потеряно '.$mpush.' пушек!');
mysql_query("UPDATE `empire` SET `win`=`win`+1, `voin`=`voin`+$mvoin, `push`=`push`+$mpush WHERE `id`='".$kup."' LIMIT 1");
mysql_query("UPDATE `empire` SET `lose`=`lose`+1, `time_nap`='$timenap', `voin`=`voin`-$mvoin, `push`=`push`-$mpush WHERE `id_u`='".$user['id']."' LIMIT 1");
}else{
$timenap=time()+60*60*3;
$mvoin=round($voin/2);
$mpush=round($push/2);
msg('Вы выиграли! К вам присоединилось '.$mvoin.' воинов и '.$mpush.' пушек!');
mysql_query("UPDATE `empire` SET `lose`=`lose`+1, `voin`=`voin`-$mvoin, `push`=`push`-$mpush WHERE `id`='".$kup."' LIMIT 1");
mysql_query("UPDATE `empire` SET `win`=`win`+1, `time_nap`='$timenap', `voin`=`voin`+$mvoin, `push`=`push`+$mpush WHERE `id_u`='".$user['id']."' LIMIT 1");
}}
else{
echo "<div class='aut'>Действия</div>";
echo "<div class='f1'><a href='?do=9&amp;kup=$kup&amp;ololo'>Напасть</a></div>\n";
}}}
echo "<div class='aut'><a href='?do=0'>Назад</a></div>";
?>