<?
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 domik8='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="neftevyshka.php?make=oxp&der='.$key.'">{охрана}</a>';
$ox=mysql_fetch_array(qw("SELECT * FROM oxp_8 WHERE strana ='$re1[strana]'"));
$ox=$ox[peh]+$ox[kon]+$ox[str]+$ox[puh]+$ox[tan]+$ox[sam];
echo"[($ox)]<br/>";
$sp=mysql_fetch_array(qw("SELECT * FROM nef WHERE strana ='$re1[strana]'"));
$u1=time();$u2=$sp[time]-$u1;
if($u2>0){
$sec = $u2;
$min = floor($sec/60);$sec-=$min*60;
echo"{Идёт разработка}(<b>$min м. $sec c.</b>)<br/>";
}else{
if($re2[emnef]==0){
echo"<a href='neftevyshka.php?make=1&der=$key'>Разработать месторождение</a><br/>";
}else{
$tims=time();$limit=round($re2[emnef]*1.5);
$neft=round(($tims-$re2[datanef])/10);$neft1=round($neft*1.5);if($limit>=$neft1){}else{$neft1=$limit;}
$neft1=round(($neft1/100)*$re1[nauknef]);
if($re2[otk5]==1){$neft1=round($neft1*1.25);}
echo"Ёмкость <b>$re2[emnef] ед.</b><br/>вы можете собрать <b>$neft1</b> нефти<br/>";
echo"<a href='neftevyshka.php?make=3&der=$key'>Собрать нефть</a><br/>";
echo"Формула нефти - ( (ёмкость*1.5)/100)*наука<br/>";
}}
break;
case 3:
/////////////////////////////////////////////////
$w1=mysql_fetch_array(qw("SELECT sum(kolvo)as a FROM rynok WHERE strana='$re1[strana]'"));
$sp=mysql_fetch_array(qw("SELECT res,ryn FROM domik WHERE strana ='$re1[strana]'"));
$x=$sp[res]-($re2[metal]+$re2[kamen]+$re2[derevo]+$re2[neft]+$re2[zerno]+$w1[a]);
////////////////////////////////////////////////
$tims=time();$limit=round($re2[emnef]*1.5);
$neft=round(($tims-$re2[datanef])/10);$neft1=round($neft*1.5);if($limit>=$neft1){}else{$neft1=$limit;}
$neft1=round(($neft1/100)*$re1[nauknef]);
if($re2[otk5]==1){$neft1=round($neft1*1.25);}
if($x>$neft1){}else{$neft1=$x;$x=0;}if($neft1<0){$neft1=0;}
echo"Вы собрали <b>$neft1</b> нефти<br/>";if($neft>$re2[emnef]){$neft=$re2[emnef];}
qw("UPDATE gos2 SET neft=neft+'$neft1',emnef=emnef-'$neft',datanef='$tims' WHERE strana='$re1[strana]'");
$dt1=date("d");$dt2=date("m");$dt3=date("H");$dt4=date("i");
mysql_query("INSERT INTO logistik (vid,data,strana,text) VALUES('8','[$dt1:$dt2]($dt3:$dt4)','$re1[strana]','Вы собрали $neft1 нефти')");

break;
case 1:
$sp=mysql_fetch_array(qw("SELECT * FROM nef WHERE strana ='$re1[strana]'"));
$u1=time();$u2=$sp[time]-$u1;
if($u2>0){
$sec = $u2;
$min = floor($sec/60);$sec-=$min*60;
echo"{Идёт разработка}(<b>$min м. $sec c.</b>)<br/>";
}else{
if($re2[emnef]==0){
echo"<FORM ACTION='neftevyshka.php?make=2&der=$key' METHOD='POST'>";
echo'Рабочие ('.$re2[rab].'):<br/><input type="text" name="rab" maxlength="10" value="" size="10"/><br/>
Деньги ('.$re2[dengi].')<br/><input type="text" name="den" maxlength="10" value="" size="10"/><br/>';?>
<INPUT TYPE='submit'VALUE='Добавить'></FORM><br/><?
}else{
header("Location: neftevyshka.php?der=$key");
}}
break;
case 2:
$sp=mysql_fetch_array(qw("SELECT * FROM nef WHERE strana ='$re1[strana]'"));
$u1=time();$u2=$sp[time]-$u1;
if($u2>0){
$sec = $u2;
$min = floor($sec/60);$sec-=$min*60;
echo"{Идёт разработка}(<b>$min м. $sec c.</b>)<br/>";
}else{
if($re2[emnef]==0){
$rab=zif($_POST[rab]);$den=zif($_POST[den]);
if($re2[rab]>=$rab and $re2[dengi]>=$den and $rab>0 and $den>0){
$tim=round(900000/$rab);$emk=round(0.1*$den);$time=time();$tim2=$time+$tim;$min=round($tim/60);
qw("INSERT INTO nef (strana,rab,emk,data,time) VALUES('$re1[strana]','$rab','$emk','$tim','$tim2')");
qw("UPDATE gos2 SET rab=rab-'$rab',dengi=dengi-'$den' WHERE strana='$re1[strana]'");
echo"Через $min минут будет разработано месторождение ёмкостью $emk ед. нефти<br/>";
$dt1=date("d");$dt2=date("m");$dt3=date("H");$dt4=date("i");
mysql_query("INSERT INTO logistik (vid,data,strana,text) VALUES('8','[$dt1:$dt2]($dt3:$dt4)','$re1[strana]','Через $min минут будет разработано месторождение ёмкостью $emk ед. нефти')");

}else{
header("Location: neftevyshka.php?make=1&der=$key");
}}else{
header("Location: neftevyshka.php?der=$key");
}}
break;
case oxp:
$ox=mysql_fetch_array(qw("SELECT * FROM oxp_8 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='neftevyshka.php?make=oxp&k=1&der=$key'>Добавить</a><br/><a href='neftevyshka.php?make=oxp&k=3&der=$key'>Забрать</a><br/>";
}
if($_GET[k]==1){
echo"<FORM ACTION='neftevyshka.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: neftevyshka.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_8 SET peh=peh+'$a1',str=str+'$a2',puh=puh+'$a3',tan=tan+'$a4' WHERE strana='$re1[strana]'");
header("Location: neftevyshka.php?make=oxp&der=$key");
}else{header("Location: neftevyshka.php?make=oxp&der=$key");}
}else{echo"В охране может находиться не более $ox[max] юнитов!<br/>";}
}
}
if($_GET[k]==3){
echo"<FORM ACTION='neftevyshka.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: neftevyshka.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_8 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: neftevyshka.php?make=oxp&der=$key");
}else{header("Location: neftevyshka.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");}
?>