<?
include_once '../sys/inc/start.php';
include_once '../sys/inc/compress.php';
include_once '../sys/inc/sess.php';
include_once '../sys/inc/home.php';
include_once '../sys/inc/settings.php';
include_once '../sys/inc/db_connect.php';
include_once '../sys/inc/ipua.php';
include_once '../sys/inc/fnc.php';
include_once '../sys/inc/user.php';

$set['title'] = 'Танки -  В бой';
include_once '../sys/inc/thead.php';
title();
err();
aut();
echo '<link rel="stylesheet" href="style.css" type="text/css" />';
include_once 'function.php';


if(isset($_POST['submit'])){
$id=abs(intval($_GET['id_user']));

if(mysql_result(mysql_query("SELECT COUNT(*) FROM `racing_moi` WHERE `id_2`='".$user['id']."' AND `id_1`='".$id."' AND `act`='0'"),0)==0 && mysql_result(mysql_query("SELECT COUNT(*) FROM `racing_moi` WHERE `id_1`='".$user['id']."' AND `id_2`='".$id."' AND `act`='0'"),0)==0){
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `tanks` WHERE `id_u`='".$id."'"),0)!=0){
mysql_query("INSERT `racing_moi`(`id_1`, `id_2`) VALUES('".$user['id']."', '".$id."')");
echo 'Вы отправили вызов сопернику ждите ответа.';
}

}
else
{
echo 'Гонщик ваш вызов еще не подтвердил.';
}

}
if($tanks_code['race_last'] < time()){
    if(isset($_GET['b'])){
        $rand=rand(1,2);
            if($rand == 1){
                mysql_query("UPDATE `tanks` SET `race_kol`=`race_kol`+1,`battle`=`battle`+1,`serebro`=`serebro`+20000 ,`experience` = `experience`+1000 WHERE `id_u`='".$user['id']."'");
echo '<div class="trnt-block mb6">
  <div class="wrap1">
    <div class="wrap2">
      <div class="wrap3">
        <div class="wrap4">
          <div class="wrap5">
            <div class="wrap6">
              <div class="wrap7">
                <div class="wrap8">
                  <div class="wrap-content">
                    <div class="medium bold pb5 cntr green1">
                      <img src="images/icons/victory.png">
                      <span>Враг уничтожен!</span>
                      <img src="images/icons/victory.png">
                    </div>
                    <div class="small white cntr sh_b bold">
                      <span class="nwr">
                        <img class="ico vm" src="images/icons/exp.png" alt="опыт" title="опыт">
                         1000
 опыта
                      </span>
                      <span class="nwr">
                        <img class="ico vm" src="images/icons/silver.png" alt="Серебро" title="Серебро">
                        20000
 серебра
                      </span>
                    </div>
                    <a class="simple-but w50 mXa medium m5" href="index.php">
                      <span>
                        <span>Вернуться в ангар</span>
                      </span>
                    </a>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>';
}
else
{
mysql_query("UPDATE `tanks` SET `race_kol`=`race_kol`+1,`battle`=`battle`+1,`serebro`=`serebro`+7000 ,`experience` = `experience`+100 WHERE `id_u`='".$user['id']."'");
echo '<div class="trnt-block mb6">
  <div class="wrap1">
    <div class="wrap2">
      <div class="wrap3">
        <div class="wrap4">
          <div class="wrap5">
            <div class="wrap6">
              <div class="wrap7">
                <div class="wrap8">
                  <div class="wrap-content">
                    <div class="medium bold pb5 cntr red1">
                      <img src="images/icons/defeat.png">
                      <span>Танк уничтожен</span>
                      <img src="images/icons/defeat.png">
                    </div>
                    <div class="small white cntr sh_b bold">
                      <span class="nwr">
                        <img class="ico vm" src="images/icons/exp.png" alt="опыт" title="опыт">
                         100
 опыта
                      </span>
                      <span class="nwr">
                        <img class="ico vm" src="images/icons/silver.png" alt="Серебро" title="Серебро">
                         7000
 кредитов
                      </span>
                    </div>
					                    <a class="simple-but w50 mXa medium m5" href="index.php">
                      <span>
                        <span>Вернуться в ангар</span>
                      </span>
                    </a>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>';

}


}}
else
{
echo "Вы не можете войти в бою подожди: ".sictime($tanks_code['race_last']-time())."";
$t = 1;
}

if(!isset($user)){
echo 'Чтобы гонятся вам нужно пройти регистрацию или авторизацию';
include_once '../sys/inc/tfoot.php';
exit;
}
function sictime($timediff){

$oneMinute=60;
$oneHour=60*60;
$oneDay=60*60*24;
$dayfield=floor($timediff/$oneDay);
$hourfield=floor(($timediff-$dayfield*$oneDay)/$oneHour);
$minutefield=floor(($timediff-$dayfield*$oneDay-$hourfield*$oneHour)/$oneMinute);
$secondfield=floor(($timediff-$dayfield*$oneDay-$hourfield*$oneHour-$minutefield*$oneMinute));
$time_1="$hourfield ч. $minutefield м. $secondfield c";
return $time_1;
}
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `tanks` WHERE `id_u`='".$user['id']."'"),0)==0)
mysql_query("INSERT INTO `tanks`(`id_u`) VALUES('".$user['id']."')");
  $tanks_code = mysql_fetch_array(mysql_query("SELECT * FROM `tanks` WHERE `id_u`='".$user['id']."'"));
   $tank_lin = mysql_fetch_array(mysql_query("SELECT * FROM `tanks_magazin` WHERE `id`='".$tanks_code['tanks']."'"));

if($tanks_code['race_kol']>900000){
$newtime = time()+60*60*12;
mysql_query("UPDATE `tanks` SET `race_kol`='0', `race_last`='".$newtime."' WHERE `id_u`='".$user['id']."'");
echo 'Вы сегодня много сделали боев и вам нужно отдохнуть, в ближайщее 10 часов ';

}
if(isset($_GET['a'])){
echo 'Тут  вы сможете выбирать себе танкиста и танковать с ним';
}

if($t!=1){
$tanks_function = mysql_fetch_array(mysql_query("SELECT * FROM `tanks_maps` ORDER BY RAND() DESC LIMIT 3"));

echo '<div class="trnt-block">
  <div class="wrap1">
    <div class="wrap2">
      <div class="wrap3">
        <div class="wrap4">
          <div class="wrap5">
            <div class="wrap6">
              <div class="wrap7">
                <div class="wrap8">
                  <div class="wrap-content">
				  Карта: <b>'.$tanks_function['maps'].'</b>
                    <div class="small bold green2 cntr sh_b pb5 pt5">'.$tanks_function['battle'].'</div>
					<img src="images/maps/'.$tanks_function['img'].'"/>
   
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>';
?>
<div class="medium bold cntr white mb10">
В бою
</div>
<?}
$cars=mysql_fetch_array(mysql_query("SELECT * FROM `tanks_magazin` ORDER BY RAND() DESC LIMIT 3"));

if($t!=1){

echo '<div class="trnt-block">
  <div class="wrap1">
    <div class="wrap2">
      <div class="wrap3">
        <div class="wrap4">
          <div class="wrap5">
            <div class="wrap6">
              <div class="wrap7">
                <div class="wrap8">
                  <div class="wrap-content">
                    <table>
                      <tbody>
                        <tr>
                          <td>
                            <img class="tank-img" alt="tank" src="images/tanks/'.$cars['screen'].'">
                          </td>
                          <td class="esmall bold green2 pl5 sh_b va_m w60px">
                            <span class="medium bold cntr white mb10">'.$cars['level'].'</span>
                            <br>
                          </td>
                        </tr>
                      </tbody>
                    </table>
                    <div class="small bold green2 cntr sh_b pb5 pt5">'.$cars['name'].'</div>
                    <div class="bot">
                      <a class="simple-but border" href="?b">
                        <span>
                          <span>Атаковать</span>
                        </span>
                      </a>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>';
}
include_once '../sys/inc/tfoot.php';
?>