<?php

require_once '../includes/start.php';
require_once '../includes/function.php';
require_once '../includes/header1.php';

if($game==0 OR $level==0 OR $ban!=0){
		echo "<title>Доступ закрыт!!!</title>";
	 	echo "<script type=\"text/javascript\">createPopup().show( 0, 0, 0, 0, 0 );</script>";
	 	echo "<body oncontextmenu=\"return false;\"><body onselectstart='return false' oncopy='return false'><body onselectstart=\"return false\" oncopy=\"return false\"><body onload=\"digitalWatch()\">";
		echo '<div class="blok3"><img src="/images/errors.png" width="200px"/></div><div class="blok3"><b>Вы не авторизованный или заблокированный пользователь или вы не достигли условий для доступа на страницу!!!</b><br/><a href="/?sign_in=1"><font color="#4EEE94"><b>Авторизуйтесь</font></a></b> или <a href="/reg.php"><font color="#4EEE94"><b>Зарегистрируйтесь</b></font></a></div>';
}else{
	$w=$_GET['w'];
	$q = mysql_query("SELECT * FROM `war` WHERE `id`='".check(mysql_real_escape_string($w))."'");
	$f = mysql_fetch_array($q);
	$s = mysql_query("SELECT * FROM `planet` WHERE `id`='".$f['planet']."'");
	$p = mysql_fetch_array($s);
	$g = mysql_query("SELECT * FROM `users` WHERE `id`='".$f['uid2']."'");
	$u = mysql_fetch_array($g);
	$count = mysql_result(mysql_query("SELECT COUNT(*) FROM `planet_loc` WHERE `uid`='".$use_id."' AND `occupy`=1 AND `planet_id`='".$p['id']."' AND `x`=4 AND `y`=4;"), 0);
	if($f['uid1']==$use_id AND $count!=0){
	if($f['ztime']>$realtime){
	echo '<div class="top">Планета '.rasa($f['rasa2']).' <span class="'.crasa($f['rasa2']).'">'.$p['name'].'</span></div>';
	echo '<div class="cont">Захват или уничтожение планеты возможны не раньше <img src="../images/time.gif" alt="image" /> '.dates($f['ztime']).'</div>';
	echo '<div class="conts"><a href="index.php?act=info&amp;w='.$f['id'].'"><<Назад</a></div>';
	}else{
	switch ($act) {
	default:
	echo '<div class="top">Захват планеты '.rasa($f['rasa2']).' <span class="'.crasa($f['rasa2']).'">'.$p['name'].'</span></div>';
	if(($lvl_hero/10)>=$maxplanet){
	if($rasa==1)$npeople=1000;
	if($rasa==2)$npeople=750;
	if($rasa==3)$npeople=1250;
	echo '<div class="conts">Вы захватили планету <span class="'.crasa($f['rasa2']).'">'.$p['name'].'</span> игрока <a href="../p/anketa.php?id='.$f['uid2'].'"><span class="'.crasa($f['rasa2']).'">'.$f['login2'].'</span></a> с координатами x:'.$p['x'].' y:'.$p['y'].'. 
	<span class="'.crasa($f['rasa2']).'">'.b(1, $f['rasa2']).'</a></span> и остальные постройки противника уничтожены! 
	Для колонизации и развития вашей новой планеты прибыло '.$npeople.' <img src="../images/peo.gif" alt="" /> населения и 1000 '.rab($rasa).'!</div>';
	if($u['planet']==1){
	mysql_query("DELETE FROM `doklad` WHERE `uid`='".$u['id']."';");
	mysql_query("DELETE FROM `sosed` WHERE `uid1`='".$u['id']."';");
	mysql_query("DELETE FROM `war` WHERE `uid1`='".$u['id']."';");
	mysql_query("DELETE FROM `units` WHERE `uid`='".$u['id']."';");
	mysql_query("UPDATE `users` SET `game`=0 WHERE `id`='".$u['id']."';");
	mysql_query("DELETE FROM `log_battle` WHERE `uid`='".$u['id']."';");
	mysql_query("DELETE FROM `torg` WHERE `uid`='".$u['id']."';");
	mysql_query("DELETE FROM `rabota` WHERE `uid`='".$p['uid']."';");
	}
	mysql_query("UPDATE `users` SET `planet`=planet-1 WHERE `id`='".$u['id']."';");
	
			$PAGINGS = mysql_query("SELECT * FROM `war` WHERE `uid1`='".$u['id']."' ORDER BY `id` DESC");
	if($PAGINGS > 0)
	{
		while($row = mysql_fetch_array($PAGINGS))
		{
			$onpl = mysql_result(mysql_query("SELECT COUNT(*) FROM `army` WHERE `planet`!='".$p['id']."' AND `uid`='".$u['id']."' AND `onpl`='".$row['planet']."';"), 0);
			if($onpl==0){
			mysql_query("UPDATE `sosed` SET `war`=0 WHERE `uid1`='".$row['uid1']."' AND `uid2`='".$row['uid2']."' AND `planet`='".$row['planet']."';");
			mysql_query("UPDATE `planet_loc` SET `uid`='".$row['uid2']."', `occupy`=0 WHERE `planet_id`='".$row['planet']."' AND `uid`='".$row['uid1']."';");
			mysql_query("INSERT INTO `doklad` SET `uid`='".$row['uid2']."', `time`='" . time() . "', `type`=4, `text`='Игрок <b>".$u['login']."</b> обьявил перемирие вашей планете <b>".$row['name']."</b>';");
			mysql_query("DELETE FROM `war` WHERE `uid1`='".$row['uid1']."' AND `uid2`='".$row['uid2']."' AND `planet`='".$row['planet']."';");
			}
	}}
	
	mysql_query("DELETE FROM `army` WHERE `planet`='".$p['id']."';");
	mysql_query("DELETE FROM `sector_loc` WHERE `planet`='".$p['id']."' AND `loc`=1;");
	mysql_query("DELETE FROM `rabota` WHERE `planet`='".$p['id']."';");
	mysql_query("UPDATE `building` SET `uid`='".$use_id."', `b1`=1, `b2`=0, `b3`=0, `b4`=0, `b5`=0, `b6`=0, `b7`=0, `b8`=0, `b9`=0, `b10`=0, `b11`=0, `b12`=0, `b12time`=0 WHERE `planet_id`='".$p['id']."';");
	mysql_query("UPDATE `moon` SET `uid`='".$use_id."', `rasa`='".$rasa."' WHERE `planet`='".$p['id']."';");
	mysql_query("UPDATE `planet` SET `uid`='".$use_id."', `rasa`='".$rasa."', `fr_id`='".$fr_id."', `rab`=1000, `peo`='".$npeople."', `razv`=25, `raket`=1 WHERE `id`='".$p['id']."';");
	mysql_query("UPDATE `planet_loc` SET `uid`='".$use_id."', `occupy`=0 WHERE `planet_id`='".$p['id']."' AND (`uid`='".$use_id."' OR `uid`='".$f['uid2']."');");
	mysql_query("UPDATE `planet_loc` SET `rab`=0 WHERE `planet_id`='".$p['id']."';");
	mysql_query("UPDATE `planet_units` SET `uid`='".$use_id."', `u1`=0, `u2`=0, `u3`=0, `u4`=0, `u5`=0, `u6`=0, `u7`=0, `u8`=0, `u9`=0, `u10`=0, `u11`=0, `u12`=0 WHERE `planet`='".$p['id']."';");
	mysql_query("UPDATE `science` SET `uid`='".$use_id."', `s1`=1, `s2`=1, `s3`=1, `s4`=1, `s5`=1, `s6`=1, `s7`=1 WHERE `planet_id`='".$p['id']."';");
	mysql_query("UPDATE `sector_loc` SET `uid`='".$use_id."', `fr_id`='".$fr_id."' WHERE `planet`='".$p['id']."';");
	mysql_query("UPDATE `war` SET `uid2`='".$use_id."', `rasa2`='".$rasa."', `login2`='".$login."' WHERE `planet`='".$p['id']."';");
	mysql_query("DELETE FROM `war` WHERE `uid1`='".$use_id."' AND `planet`='".$p['id']."';");
	mysql_query("UPDATE `users` SET `planet`=planet+1 WHERE `id`='".$use_id."';");
	mysql_query("DELETE FROM `sosed` WHERE `uid1`='".$use_id."' AND `planet`='".$p['id']."';");
	mysql_query("DELETE FROM `art` WHERE `planet`='".$p['id']."';");
	mysql_query("UPDATE `sosed` SET `uid2`='".$use_id."' WHERE `planet`='".$p['id']."';");

	mysql_query("INSERT INTO `doklad` SET `uid`='".$u['id']."', `time`='" . time() . "', `type`=4, `text`='Вашу планету <b>".$p['name']."</b> захватил игрок <b>".$login."</b>';");
	mysql_query("INSERT INTO `log_zahvat` SET `who`='".$use_id."', `uid`='".$u['id']."', `rasa`='".$u['rasa']."', `login`='".$u['login']."', `time`='" . time() . "', `type`=1, `name`='".$p['name']."';");
	}else{
	echo '<div class="conts">Для захвата планеты <span class="'.crasa($f['rasa2']).'">'.$p['name'].'</span> игрока <a href="../p/anketa.php?id='.$f['uid2'].'"><span class="'.crasa($f['rasa2']).'">'.$f['login2'].'</span></a> нужно повысить вашего героя до '.($maxplanet*10).' уровня!</div>';
	echo '<div class="conts"><a href="index.php?act=info&amp;w='.$f['id'].'"><<Назад</a></div>';}
	break;
	case 'destroy':
	echo '<div class="top">Уничтожение планеты '.rasa($f['rasa2']).' <span class="'.crasa($f['rasa2']).'">'.$p['name'].'</span></div>';
	echo '<div class="conts">Вы уничтожили планету <span class="'.crasa($f['rasa2']).'">'.$p['name'].'</span> игрока <a href="../p/anketa.php?id='.$f['uid2'].'"><span class="'.crasa($f['rasa2']).'">'.$f['login2'].'</span></a> с координатами x:'.$p['x'].' y:'.$p['y'].'. 
	На месте бывшей планеты образовался <img src="../images/space/teleport.jpg" alt="" /> портал под вашим управлением! Трофеи:</br>';
	
	$mmin=$lvl_hero*1000;
	$mgas=$lvl_hero*1000;
	$mmetall=$lvl_hero*1000;
	$mkred=$lvl_hero*250;
	$mprov=$lvl_hero*250;
	$mwater=$lvl_hero*750;

	if($u['planet']==1){
	mysql_query("DELETE FROM `doklad` WHERE `uid`='".$u['id']."';");
	mysql_query("DELETE FROM `sosed` WHERE `uid1`='".$u['id']."';");
	mysql_query("DELETE FROM `war` WHERE `uid1`='".$u['id']."';");
	mysql_query("UPDATE `users` SET `game`=0 WHERE `id`='".$u['id']."';");
	mysql_query("DELETE FROM `log_battle` WHERE `uid`='".$u['id']."';");
	mysql_query("DELETE FROM `units` WHERE `uid`='".$u['id']."';");
	mysql_query("DELETE FROM `torg` WHERE `uid`='".$u['id']."';");
	mysql_query("DELETE FROM `rabota` WHERE `uid`='".$p['uid']."';");
	}
	
	mysql_query("INSERT INTO `doklad` SET `uid`='".$u['id']."', `time`='" . time() . "', `type`=4, `text`='Игрок <b>".$login."</b> получил часть ваших ресурсов';");
	mysql_query("UPDATE `users` SET `planet`=planet-1, `min`=min-$zmin, `gas`=gas-$zgas, `metall`=metall-$zmetall, `prov`=prov-$zprov, `water`=water-$zwater, `kred`=kred-$zkred WHERE `id`='".$u['id']."';");

	$zmin=(($u['min']/$u['planet'])/100)*rand(40,60);
	if($zmin<$mmin)$zmin=$mmin;
	$zgas=(($u['gas']/$u['planet'])/100)*rand(40,60);
	if($zgas<$mgas)$zgas=$mgas;
	$zmetall=(($u['metall']/$u['planet'])/100)*rand(40,60);
	if($zmetall<$mmetall)$zmetall=$mmetall;
	$zprov=(($u['prov']/$u['planet'])/100)*rand(40,60);
	if($zprov<$mprov)$zprov=$mprov;
	$zwater=(($u['water']/$u['planet'])/100)*rand(40,60);
	if($zwater<$mwater)$zwater=$mwater;
	$zkred=(($u['kred']/$u['planet'])/100)*rand(40,60);
	if($zkred<$mkred)$zkred=$mkred;
	echo '<img src="../images/min.gif" alt="" /> Минералы: '.$zmin.'<br/>
	<img src="../images/metall.gif" alt="" /> Металлы: '.$zmetall.'<br/>
	<img src="../images/gas.gif" alt="" /> Газ Веспен: '.$zgas.'<br/>
	<img src="../images/prov.png" alt="" /> Провизия: '.$zprov.'<br/>
	<img src="../images/water.png" alt="" /> Вода: '.$zwater.'<br/>
	<img src="../images/kred.png" alt="" /> Кредиты: '.$zkred.'</div>';
	
			$PAGINGS = mysql_query("SELECT * FROM `war` WHERE `uid1`='".$u['id']."' ORDER BY `id` DESC");
	if($PAGINGS > 0)
	{
		while($row = mysql_fetch_array($PAGINGS))
		{
			$onpl = mysql_result(mysql_query("SELECT COUNT(*) FROM `army` WHERE `planet`!='".$p['id']."' AND `uid`='".$u['id']."' AND `onpl`='".$row['planet']."';"), 0);
			if($onpl==0){
			mysql_query("UPDATE `sosed` SET `war`=0 WHERE `uid1`='".$row['uid1']."' AND `uid2`='".$row['uid2']."' AND `planet`='".$row['planet']."';");
			mysql_query("UPDATE `planet_loc` SET `uid`='".$row['uid2']."', `occupy`=0 WHERE `planet_id`='".$row['planet']."' AND `uid`='".$row['uid1']."';");
			mysql_query("INSERT INTO `doklad` SET `uid`='".$row['uid2']."', `time`='" . time() . "', `type`=4, `text`='Игрок <b>".$u['login']."</b> обьявил перемирие вашей планете <b>".$row['name']."</b>';");
			mysql_query("DELETE FROM `war` WHERE `uid1`='".$row['uid1']."' AND `uid2`='".$row['uid2']."' AND `planet`='".$row['planet']."';");
			}
	}}
	
	mysql_query("DELETE FROM `army` WHERE `planet`='".$p['id']."';");
	mysql_query("UPDATE `army` SET `onpl`=0, `time`=$realtime+300 WHERE `x`='".$p['x']."' AND `y`='".$p['y']."';");
	mysql_query("DELETE FROM `army` WHERE `planet`='".$p['id']."';");
	mysql_query("DELETE FROM `rabota` WHERE `planet`='".$p['id']."';");
	mysql_query("DELETE FROM `building` WHERE `planet_id`='".$p['id']."';");
	mysql_query("DELETE FROM `moon` WHERE `planet`='".$p['id']."';");
	mysql_query("DELETE FROM `planet` WHERE `id`='".$p['id']."';");
	mysql_query("DELETE FROM `planet_loc` WHERE `planet_id`='".$p['id']."';");
	mysql_query("DELETE FROM `planet_units` WHERE `planet`='".$p['id']."';");
	mysql_query("DELETE FROM `science` WHERE `planet_id`='".$p['id']."';");
	mysql_query("DELETE FROM `war` WHERE `planet`='".$p['id']."';");
	mysql_query("DELETE FROM `sosed` WHERE `planet`='".$p['id']."';");
	mysql_query("DELETE FROM `sosed` WHERE `uid1`='".$use_id."' AND `planet`='".$p['id']."';");
	mysql_query("DELETE FROM `sosed` WHERE `uid2`='".$u['id']."' AND `planet`='".$p['id']."';");
	mysql_query("DELETE FROM `rabota` WHERE `planet`='".$p['id']."';");
	mysql_query("DELETE FROM `sector_loc` WHERE `planet`='".$p['id']."';");
	mysql_query("INSERT INTO `sector_loc` SET `uid`='".$use_id."', `loc`=5, `x`='".$p['x']."', `y`='".$p['y']."';");
	mysql_query("DELETE FROM `art` WHERE `planet`='".$p['id']."';");
	mysql_query("UPDATE `users` SET `min`=min+$zmin, `gas`=gas+$zgas, `metall`=metall+$zmetall, `prov`=prov+$zprov, `water`=water+$zwater, `kred`=kred+$zkred WHERE `id`='".$use_id."';");
	mysql_query("INSERT INTO `doklad` SET `uid`='".$u['id']."', `time`='" . time() . "', `type`=4, `text`='Вашу планету <b>".$p['name']."</b> уничтожил игрок <b>".$login."</b>';");

	mysql_query("INSERT INTO `log_zahvat` SET `who`='".$use_id."', `uid`='".$u['id']."', `rasa`='".$u['rasa']."', `login`='".$u['login']."', `time`='" . time() . "', `type`=2, `name`='".$p['name']."', `min`=$zmin, `gas`=$zgas, `metall`=$zmetall, `prov`=$zprov, `water`=$zwater, `kred`=$zkred;");

	break;
	}}}}
echo '<div class="razd"></div>';
echo '<center><div class="blok2"><a href="../"><b>На Главную</b></a></div></center>';
echo '<div class="razd"></div>';
require_once '../includes/footer1.php';
?>
