<?
ob_start();
require'../sys/head.php';
require'../sys/conf.php';
require'../sys/sess.php';
require'../otsev.php';
echo"<b>Сторожевая башня</b><br/>";
$sp=mysql_fetch_array(qw("SELECT id FROM domik WHERE strana ='$re1[strana]' and domik10='1'"));
if($sp[id]>0){
echo'</div><div class="knews">';
if(!empty($_GET['make'])){$make = $_GET['make'];} else {$make= '';}
switch($make){
default:
echo'<a href="storbashnya.php?make=oxp&der='.$key.'">{охрана}</a>';
$ox=mysql_fetch_array(qw("SELECT * FROM oxp_10 WHERE strana ='$re1[strana]'"));
$ox=$ox[peh]+$ox[kon]+$ox[str]+$ox[puh]+$ox[tan]+$ox[sam];
echo"[($ox)]<br/>";
////////////////////////////////////////////////////////////////////////////////////////////////////
$mon = qw("SELECT id,strana1 FROM sosed WHERE strana2='$re1[strana]'");
while($arr = mysql_fetch_array($mon)){
echo'<a href="storbashnya.php?make=1&x=1&f='.$arr[id].'&der='.$key.'">'.$arr[strana1].'</a><br/>';
}
$mon = qw("SELECT id,strana2 FROM sosed WHERE strana1='$re1[strana]'");
while($arr = mysql_fetch_array($mon)){
echo'<a href="storbashnya.php?make=1&x=2&f='.$arr[id].'&der='.$key.'">'.$arr[strana2].'</a><br/>';
}
break;
case 1:
if($_GET[x]==1){$r='strana2';$t='strana1';}else{$r='strana1';$t='strana2';}
$ox=mysql_fetch_array(qw("SELECT id,$t FROM sosed WHERE id='$_GET[f]' and $r='$re1[strana]'"));
echo"$ox[1]<br/>";
$ox1=mysql_fetch_array(qw("SELECT id FROM gos WHERE strana='$ox[$t]'"));
if($ox[id]>0){
$query="SELECT * FROM voyna WHERE vrag='$ox[1]'";
$result=mysql_query($query);
$num=mysql_numrows($result);
$i=0;
while ($i < $num) {
$zh1=mysql_result($result,$i,"strana");
$zh2=mysql_result($result,$i,"peh");
$zh3=mysql_result($result,$i,"kon");
$zh4=mysql_result($result,$i,"str");
$zh8=mysql_result($result,$i,"puh");
$zh66=mysql_result($result,$i,"tan");
$zh7=mysql_result($result,$i,"sam");
$zh5=mysql_result($result,$i,"datanap");
$array[id]=mysql_result($result,$i,"id");
$tim=time();
$zh6=$tim-$zh5;
$sec1=$zh6;
$hou1=floor($sec1/3600);
$sec1-=$hou1*3600;
$min1=floor($sec1/60);
$sec1-=$min1*60;
echo"<b>$zh1</b>(<b>$zh2</b> пех.)(<b>$zh3</b> кав.)(<b>$zh4</b> стр.)(<b>$zh8</b> пух.)(<b>$zh66</b> тан.)(<b>$zh7</b> сам.)[<b>$hou1</b> час.<b>$min1</b> мин.]<br/>";
$i++;
}
$ox1[0]=(($ox1[0]*500)/2);
$sx=mysql_fetch_array(qw("SELECT id,strana2 FROM soyuz WHERE strana1='$re1[strana]' and strana2='$ox[1]'"));
	if($sx[id]>0){
	if($array[id]>0){echo"<a href=citadel.php?make=v55&der=$key&y=$array[id]>Атаковать</a><br/>";}
	}else{
echo"<a href='citadel.php?make=5&a=$ox1[0]&f=$_GET[f]&x=$_GET[x]&m=7&der=$key'>Напасть</a><br/>";
}
}else{echo"Нет такого соседнего гос-ва!<br/>";}
break;
case oxp:
$ox=mysql_fetch_array(qw("SELECT * FROM oxp_10 WHERE strana ='$re1[strana]'"));
if(empty($_GET[k])){
echo"<u>В охране </u>:<br/>Пехота ($ox[peh])<br/>Стрелки ($ox[str])<br/>Пушки ($ox[puh])<br/>Танки ($ox[tan])<br/>";
echo"<a href='storbashnya.php?make=oxp&k=1&der=$key'>Добавить</a><br/><a href='storbashnya.php?make=oxp&k=3&der=$key'>Забрать</a><br/>";
}
if($_GET[k]==1){
echo"<FORM ACTION='storbashnya.php?make=oxp&k=2&der=$key' METHOD='POST'>";?>
Пехота:<br/><input type="text" name="peh" maxlength="4" value="<?=$re2[peh];?>" size="5"/><br/>
Стрелки:<br/><input type="text" name="str" maxlength="4" value="<?=$re2[str];?>" size="5"/><br/>
Пушки:<br/><input type="text" name="puh" maxlength="4" value="<?=$re2[puh];?>" size="5"/><br/>
Танки:<br/><input type="text" name="tan" maxlength="4" value="<?=$re2[tan];?>" size="5"/><br/>
<INPUT TYPE='submit'VALUE='Добавить'></FORM><br/><?
}
if($_GET[k]==2){
$a1=zif($_POST[peh]);$a2=zif($_POST[str]);$a3=zif($_POST[puh]);$a4=zif($_POST[tan]);$a5=$a1+$a2+$a3+$a4;
if($a5==0){header("Location: storbashnya.php?make=oxp&der=$key");}else{
$lim=$a5+$ox[peh]+$ox[str]+$ox[puh]+$ox[tan];
if($ox[max]>=$lim){
if($re2[peh]>=$a1 and $re2[str]>=$a2 and $re2[puh]>=$a3 and $re2[tan]>=$a4){
qw("UPDATE gos2 SET peh=peh-'$a1',str=str-'$a2',puh=puh-'$a3',tan=tan-'$a4' WHERE strana='$re1[strana]'");
qw("UPDATE oxp_10 SET peh=peh+'$a1',str=str+'$a2',puh=puh+'$a3',tan=tan+'$a4' WHERE strana='$re1[strana]'");
header("Location: storbashnya.php?make=oxp&der=$key");
}else{header("Location: storbashnya.php?make=oxp&der=$key");}
}else{echo"В охране может находиться не более $ox[max] юнитов!<br/>";}
}
}
if($_GET[k]==3){
echo"<FORM ACTION='storbashnya.php?make=oxp&k=4&der=$key' METHOD='POST'>";?>
Пехота:<br/><input type="text" name="peh" maxlength="4" value="<?=$ox[peh];?>" size="5"/><br/>
Стрелки:<br/><input type="text" name="str" maxlength="4" value="<?=$ox[str];?>" size="5"/><br/>
Пушки:<br/><input type="text" name="puh" maxlength="4" value="<?=$ox[puh];?>" size="5"/><br/>
Танки:<br/><input type="text" name="tan" maxlength="4" value="<?=$ox[tan];?>" size="5"/><br/>
<INPUT TYPE='submit'VALUE='Забрать'></FORM><br/><?
}
if($_GET[k]==4){
$a1=zif($_POST[peh]);$a2=zif($_POST[str]);$a3=zif($_POST[puh]);$a4=zif($_POST[tan]);$a5=$a1+$a2+$a3+$a4;
if($a5==0){header("Location: storbashnya.php?make=oxp&der=$key");}else{
if($ox[peh]>=$a1 and $ox[str]>=$a2 and $ox[puh]>=$a3 and $ox[tan]>=$a4){
qw("UPDATE oxp_10 SET peh=peh-'$a1',str=str-'$a2',puh=puh-'$a3',tan=tan-'$a4' WHERE strana='$re1[strana]'");
qw("UPDATE gos2 SET peh=peh+'$a1',str=str+'$a2',puh=puh+'$a3',tan=tan+'$a4' WHERE strana='$re1[strana]'");
header("Location: storbashnya.php?make=oxp&der=$key");
}else{header("Location: storbashnya.php?make=oxp&der=$key");}
}
}
break;
}
echo'</div><div class="knews">';
?>|<a href='javascript:history.go(-1)'>Назад</a><br/><?
echo'<a href="../game.php?der='.$key.'">В страну</a><br/>';
echo'</div><div class="knews"><a href="../out.php?der='.$key.'">Выход</a><br/>';
require'../sys/foot.php';
}else{header("Location:../../game.php?der=$key");}
?>