<?
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 domik4='2'"));
if($sp[id]>0){
echo'</div><div class="knews">';
if(!empty($_GET['make'])){$make = $_GET['make'];} else {$make= '';}
switch($make){
default:
echo'<a href="ncentr.php?make=oxp&der='.$key.'">{охрана}</a>';
$ox=mysql_fetch_array(qw("SELECT * FROM oxp_4 WHERE strana ='$re1[strana]'"));
$ox=$ox[peh]+$ox[kon]+$ox[str]+$ox[puh]+$ox[tan]+$ox[sam];
echo"[($ox)]<br/>";
echo'<a href="ncentr.php?make=3&der='.$key.'">Технологии</a><br/>';
echo'<a href="ncentr.php?make=5&der='.$key.'">Открытия</a><br/>';
echo'<a href="ncentr.php?make=2&der='.$key.'">Управление учёными</a><br/>';
break;
case 5:
if($re2[otk1]==1){echo'открытие-переплавка железа<br/>';}
if($re2[otk2]==1){echo'открытие-распиловка древесины<br/>';}
if($re2[otk3]==1){echo'открытие-удобрение зерновых<br/>';}
if($re2[otk4]==1){echo'открытие-обработка камней<br/>';}
if($re2[otk5]==1){echo'открытие-синтез нефти<br/>';}
if($re2[otk6]==1){echo'открытие-берсерк<br/>';}
if($re2[otk7]==1){echo'открытие-бомба<br/>';}
break;
case 4:
$i=$_GET[m];
$ox=mysql_fetch_array(qw("SELECT * FROM nauka WHERE id ='$i' and strana='$re1[strana]'"));
if($i==$ox[id] and $ox[strana]==$re1[strana]){
if(empty($_GET[d])){
$tg1=time();$tg2=$ox[time]-$tg1;
$sec = $tg2;
$min = floor($sec/60);$sec-=$min*60;
echo"До конца исследования <b>$min</b>минут! <b>$sec</b> cek!<br/>";
echo "<a href=ncentr.php?make=4&d=2&m=$i&der=$key>Отменить</a>"; 
/////////////////////////
echo'<FORM ACTION="ncentr.php?make=4&d=1&m='.$i.'&der='.$key.'" METHOD="POST">';?>
Учёные:<?echo"$ox[bot]";?><br/>
Свободные учёные:<?echo"$re2[bot]";?><br/>
<input format='*N' name='bot'/><br/>
<input name="plus" type="submit" value="+"/>/
<input name="minus" type="submit" value="-"/></FORM>
<?
}
if($_GET[d]==2){
echo"Исследование отменено!<br/>";
qw("UPDATE gos2 SET bot=bot+'$ox[bot]' WHERE strana='$re1[strana]'");
qw("DELETE FROM nauka WHERE id='$i' and strana='$re1[strana]'");
}
if($_GET[d]==1){

if (isset($_POST['plus'])) {$time=time();
$bot=zif($_POST[bot]);$ox[data]=$ox[time]-$time;
if($bot>$re2[bot]){echo"нет столько учёных<br/>";}else{
$dat=($ox[data]*$ox[bot])/($ox[bot]+zif($_POST[bot]));$tim=time();$tad=$tim+$dat;
qw("UPDATE nauka SET bot=bot+'$bot',data='$dat',time='$tad' WHERE id='$ox[id]'");
qw("UPDATE gos2 SET bot=bot-'$bot' WHERE strana='$re1[strana]'");
header("Location: ncentr.php?make=3&der=$key");
}}else{}
if (isset($_POST['minus'])) {$time=time();
$bot=zif($_POST[bot]);$ox[data]=$ox[time]-$time;
if($bot>=$ox[bot]){echo"нет столько учёных<br/>";}else{
$dat=($ox[data]*$ox[bot])/($ox[bot]-zif($_POST[bot]));;$tim=time();$tad=$tim+$dat;
qw("UPDATE nauka SET bot=bot-'$bot',data='$dat',time='$tad' WHERE id='$ox[id]'");
qw("UPDATE gos2 SET bot=bot+'$bot' WHERE strana='$re1[strana]'");
header("Location: ncentr.php?make=3&der=$key");

}}else{}
}
}else{header("Location: ncentr.php?make=3&der=$key");}
break;
case 3:
if(empty($_GET[f])){
$nk = qw("SELECT id,nauka,time FROM nauka  WHERE strana='$re1[strana]'");
while($as = mysql_fetch_array($nk)){
switch($as[nauka]){
case 1:
$tg1=time();$tg2=$as[time]-$tg1;
$sec = $tg2;
$min = floor($sec/60);$sec-=$min*60;
echo"{<a href='ncentr.php?m=$as[id]&make=4&der=$key'>Научный уровень</a>}(<b>$min м. $sec с.</b>)<br/>";
break;
case 2:
$tg1=time();$tg2=$as[time]-$tg1;
$sec = $tg2;
$min = floor($sec/60);$sec-=$min*60;
echo"{<a href='ncentr.php?m=$as[id]&make=4&der=$key'>Выплавка железа</a>}(<b>$min м. $sec с.</b>)<br/>";
break;
case 3:
$tg1=time();$tg2=$as[time]-$tg1;
$sec = $tg2;
$min = floor($sec/60);$sec-=$min*60;
echo"{<a href='ncentr.php?m=$as[id]&make=4&der=$key'>Добыча камня</a>}(<b>$min м. $sec с.</b>)<br/>";
break;
case 4:
$tg1=time();$tg2=$as[time]-$tg1;
$sec = $tg2;
$min = floor($sec/60);$sec-=$min*60;
echo"{<a href='ncentr.php?m=$as[id]&make=4&der=$key'>Переработка древесины</a>}(<b>$min м. $sec с.</b>)<br/>";
break;
case 5:
$tg1=time();$tg2=$as[time]-$tg1;
$sec = $tg2;
$min = floor($sec/60);$sec-=$min*60;
echo"{<a href='ncentr.php?m=$as[id]&make=4&der=$key'>Выращивание зерна</a>}(<b>$min м. $sec с.</b>)<br/>";
break;
case 6:
$tg1=time();$tg2=$as[time]-$tg1;
$sec = $tg2;
$min = floor($sec/60);$sec-=$min*60;
echo"{<a href='ncentr.php?m=$as[id]&make=4&der=$key'>Нефтедобыча</a>}(<b>$min м. $sec с.</b>)<br/>";
break;
case 7:
$tg1=time();$tg2=$as[time]-$tg1;
$sec = $tg2;
$min = floor($sec/60);$sec-=$min*60;
echo"{<a href='ncentr.php?m=$as[id]&make=4&der=$key'>Прирост населения</a>}(<b>$min м. $sec с.</b>)<br/>";
break;
case 8:
$tg1=time();$tg2=$as[time]-$tg1;
$sec = $tg2;
$min = floor($sec/60);$sec-=$min*60;
echo"{<a href='ncentr.php?m=$as[id]&make=4&der=$key'>Демонтаж зданий</a>}(<b>$min м. $sec с.</b>)<br/>";
break;
}}
$nik=$re1[strana];
$nka1=mysql_fetch_array(qw("SELECT id FROM nauka WHERE strana='$nik' and nauka='1'"));
if(!empty($nka1[id])){}else{echo'<a href="ncentr.php?make=3&f=1&n=1&der='.$key.'">Научный уровень</a>';echo"[<b>$re1[naukur]%</b>]<br/>";}
$nka1=mysql_fetch_array(qw("SELECT id FROM nauka WHERE strana='$nik' and nauka='2'"));
if(!empty($nka1[id])){}else{if($re1[naukur]>29){echo'<a href="ncentr.php?make=3&f=1&n=2&der='.$key.'">Выплавка железа</a>';echo"[<b>$re1[naukmet]%</b>]<br/>";}}
$nka1=mysql_fetch_array(qw("SELECT id FROM nauka WHERE strana='$nik' and nauka='3'"));
if(!empty($nka1[id])){}else{if($re1[naukur]>29){echo'<a href="ncentr.php?make=3&f=1&n=3&der='.$key.'">Добыча камня</a>';echo"[<b>$re1[naukkam]%</b>]<br/>";}}
$nka1=mysql_fetch_array(qw("SELECT id FROM nauka WHERE strana='$nik' and nauka='4'"));
if(!empty($nka1[id])){}else{if($re1[naukur]>29){echo'<a href="ncentr.php?make=3&f=1&n=4&der='.$key.'">Переработка древесины</a>';echo"[<b>$re1[naukder]%</b>]<br/>";}}
$nka1=mysql_fetch_array(qw("SELECT id FROM nauka WHERE strana='$nik' and nauka='5'"));
if(!empty($nka1[id])){}else{if($re1[naukur]>29){echo'<a href="ncentr.php?make=3&f=1&n=5&der='.$key.'">Выращивание зерна</a>';echo"[<b>$re1[naukzer]%</b>]<br/>";}}
$nka1=mysql_fetch_array(qw("SELECT id FROM nauka WHERE strana='$nik' and nauka='6'"));
if(!empty($nka1[id])){}else{if($re1[naukur]>29){echo'<a href="ncentr.php?make=3&f=1&n=6&der='.$key.'">Нефтедобыча</a>';echo"[<b>$re1[nauknef]%</b>]<br/>";}}
$nka1=mysql_fetch_array(qw("SELECT id FROM nauka WHERE strana='$nik' and nauka='7'"));
if(!empty($nka1[id])){}else{if($re1[naukur]>49 and $re2[land]>7999){echo'<a href="ncentr.php?make=3&f=1&n=7&der='.$key.'">Прирост населения</a>';echo"[<b>$re1[naukpri]%</b>]<br/>";}}
$nka1=mysql_fetch_array(qw("SELECT id FROM nauka WHERE strana='$nik' and nauka='8'"));
if(!empty($nka1[id])){}else{if($re1[naukur]>49 and $re2[land]>7999){echo'<a href="ncentr.php?make=3&f=1&n=8&der='.$key.'">Демонтаж зданий</a>';echo"[<b>$re1[naukdem]%</b>]<br/>";}}

//////////////////////////////////////////////////////////////////////
}
if($_GET[f]==1){
$n=zif($_GET[n]);
$sp=mysql_fetch_array(qw("SELECT id FROM nauka WHERE strana ='$re1[strana]' and nauka='$n'"));
if($sp[id]>0){header("Location: ncentr.php?make=3&der=$key");}else{
echo"<FORM ACTION='ncentr.php?make=3&f=2&n=$n&der=$key' METHOD='POST'>";?>
Учёные :<br/><input type="text" name="bot" maxlength="10" value="<?=$re2[bot];?>" size="10"/><br/>
Деньги:<br/><input type="text" name="den" maxlength="10" value="" size="10"/><br/>
<INPUT TYPE='submit'VALUE='Исследовать'></FORM><br/>
100 ден. = 1% <br/><?

}}
if($_GET[f]==2){
$n=zif($_GET[n]);$bot=zif($_POST[bot]);$den=zif($_POST[den]);
switch($n){
case 1:
$q1='naukur';$vr=3250500;
break;
case 2:
$q1='naukmet';$vr=1280500;
if($re1[naukur]>29){}else{header("Location: ncentr.php?make=3&der=$key");}
break;
case 3:
$q1='naukkam';$vr=1320500;
if($re1[naukur]>29){}else{header("Location: ncentr.php?make=3&der=$key");}
break;
case 4:
$q1='naukder';$vr=1220500;
if($re1[naukur]>29){}else{header("Location: ncentr.php?make=3&der=$key");}
break;
case 5:
$q1='naukzer';$vr=1170500;
if($re1[naukur]>29){}else{header("Location: ncentr.php?make=3&der=$key");}
break;
case 6:
$q1='nauknef';$vr=2500000;
if($re1[naukur]>49 and $re2[land]>7999){}else{header("Location: ncentr.php?make=3&der=$key");}
break;
case 7:
$q1='naukpri';$vr=3200000;
if($re1[naukur]>99 and $re2[land]>11999){}else{header("Location: ncentr.php?make=3&der=$key");}
break;
case 8:
$q1='naukdem';$vr=3150000;
if($re1[naukur]>99 and $re2[land]>11999){}else{header("Location: ncentr.php?make=3&der=$key");}
break;
}
$sp=mysql_fetch_array(qw("SELECT id FROM nauka WHERE strana ='$re1[strana]' and nauka='$n'"));
if($sp[id]>0){header("Location: ncentr.php?make=3&der=$key");}else{
if($re2[bot]>=$bot and $re2[dengi]>=$den){
if($re1[$q1]==100){echo"Достигнуто максимальное значение";}else{
if($bot==0 or $den==0){header("Location: ncentr.php?make=3&der=$key");}else{
$z=round((($vr/$bot)/$re1['naukur'])*($den/100));$x=($den/100);$x1=$re1[$q1]+$x;if($x1>100){$x=100;}else{$x=$x1;}$dat=time();
$nik=$re1[strana];$b=$n;$date=$z;$z=$dat+$z;$c=$bot;
qw("INSERT INTO nauka (strana,nauka,data,time,bot,pr) VALUES('$nik','$b','$date','$z','$c','$x')");
qw("UPDATE gos2 SET dengi=dengi-'$den',bot=bot-'$bot' WHERE strana='$nik'");
header("Location:ncentr.php?make=3&f=3&dat=$date&der=$key");
}
}
}else{echo"Нет столько денег или учёных!<br/>";}
}
}
if($_GET[f]==3){
$f=$_GET['dat'];
$sec = $f;
$min = floor($sec/60);$sec-=$min*60;
echo"Исследование займёт $min мин. $sec сек.<br/>";
}
break;
case 2:
echo"Учёных(<b>$re2[bot]</b>)<br/>";
echo'<a href="ncentr.php?make=1&k=1&der='.$key.'">Обучить</a><br/>';
echo'<a href="ncentr.php?make=1&k=3&der='.$key.'">Уволить</a><br/>';
break;
case 1:
$sp=mysql_fetch_array(qw("SELECT * FROM botan WHERE strana ='$re1[strana]'"));
$u1=time();$u2=$sp[time]-$u1;
if($sp[data]>$u2){
$sec = $u2;
$min = floor($sec/60);$sec-=$min*60;
echo"{Идёт обучение}(<b>$min м. $sec c.</b>)<br/>";
}else{

if($_GET[k]==1){
echo"<FORM ACTION='ncentr.php?make=1&k=2&der=$key' METHOD='POST'>";?>
Рабочие :<br/><input type="text" name="rab" maxlength="10" value="<?=$re2[rab];?>" size="10"/><br/>
Учёные:<br/><input type="text" name="bot" maxlength="10" value="<?=$re2[bot];?>" size="10"/><br/>
<INPUT TYPE='submit'VALUE='Обучить'></FORM><br/><?
}
if($_GET[k]==2){
$e1=zif($_POST[rab]);$e2=zif($_POST[bot]);
if($re2[rab]>=$e1 and $re2[bot]>=$e2){
$den=50*$e1;$kam=50*$e1;
if($re2[dengi]>=$den and $re2[kamen]>=$kam){
$ty=round(($e1*1000)/$e2);$yt=round($ty/60);$tim1=time();$tim2=$tim1+$ty;
echo"Обучение займёт $yt минут,<br/>Стоимость :Деньги ($den),Камень ($kam)<br/>";
$dt1=date("d");$dt2=date("m");$dt3=date("H");$dt4=date("i");
mysql_query("INSERT INTO logistik (vid,data,strana,text) VALUES('21','[$dt1:$dt2]($dt3:$dt4)','$re1[strana]',
'Обучение займёт $yt минут(учёные)($e1)')");
qw("INSERT INTO botan (strana,rab,bot,data,time) VALUES('$re1[strana]','$e1','$e2','$ty','$tim2')");
qw("UPDATE gos2 SET rab=rab-'$e1',bot=bot-'$e2',dengi=dengi-'$kam',kamen=kamen-'$kam' WHERE strana='$re1[strana]'");
}else{
echo"Не хватает ресурсов,нужно :<br/>Деньги ($den),Камень ($kam)<br/>";
}
}else{
echo"Нет столько рабочих или учёных!<br/>";
}
}
if($_GET[k]==3){
if($re2[bot]>0){
echo"<FORM ACTION='ncentr.php?make=1&k=4&der=$key' METHOD='POST'>";?>
<?if($re2[bot]>0){?>Учёные:<br/><input type="text" name="bot" maxlength="10" value="<?=$re2[bot];?>" size="10"/><br/><?}?>
<INPUT TYPE='submit'VALUE='Уволить'></FORM><br/><?
}else{echo"Нет свободных учёных<br/>";}
}
if($_GET[k]==4){
if($re2[bot]>0){
$bot=zif($_POST[bot]);
if($re2[bot]>$bot){
$den=2*$bot;$kam=2*$bot;
/////////////////////////////////////////////////
$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]);
////////////////////////////////////////////////
if($x>$kam){$x=$x-$kam;}else{$kam=$x;$x=0;}if($kam<0){$kam=0;}
qw("UPDATE gos2 SET rab=rab+'$bot',bot=bot-'$bot',dengi=dengi+'$den',kamen=kamen+'$kam' WHERE strana='$re1[strana]'");
echo"Учёные уволены,вы получили :<br/>деньги($den),камень($kam)<br/>";
$dt1=date("d");$dt2=date("m");$dt3=date("H");$dt4=date("i");
mysql_query("INSERT INTO logistik (vid,data,strana,text) VALUES('21','[$dt1:$dt2]($dt3:$dt4)','$re1[strana]',
'Учёные уволены,вы получили :<br/>деньги($den),камень($kam)')");
}else{echo"Нет столько учёных<br/>";}
}else{echo"Нет свободных учёных<br/>";}
}

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