<?
require'../sys/conf.php';
$ng = mysql_query("SELECT strana,gora,lesa,land,zerno,rab,bot,peh,kon,str,genn,genm,geno,genv FROM gos2 ");
while($n = mysql_fetch_array($ng)){
$lg=mysql_fetch_array(qw("SELECT login FROM gos WHERE strana='$n[strana]'"));
////////////////////////////////////////dengi
$dengi=$n[gora]*5;$tm=time();
$n1="С гор пришло $dengi лавэ!<br/>";
////////////////////////////////////////gory_lesa
$land=$n[land]+$n[gora]+$n[lesa];
$gor1=20000;$les1=15000;
if($n[gora]>$gor1){$gor=$n[gora]-$gor1;$n2="Разрушено $gor гор!<br/>";}else{$gor=0;$n2='';}
if($n[lesa]>$les1){$les=$n[lesa]-$les1;$n3="Сгорело $les леса!<br/>";}else{$les=0;$n3='';}
//////////////////////////////////////////gena
if($n[genn]!=0){if($n[genv]>79){$gn=0;$gm=0;$go=1;$gv=0;$n4="Помянем Вашего Генерала! Он Склеил Ласты!Умер!<br/>";
}else{
$gn=$n[genn];$gm=$n[genm];$go=$n[geno];$gv=$n[genv]+1;$n4="Генерал постарел на 1 год!<br/>";
}}else{$gn=$n[genn];$gm=$n[genm];$go=$n[geno];$gv=$n[genv];$n4='';}
////////////////////////////////////////gory_prirost
if($n[gora]!=0){$gg=round($n[gora]*0.1);$n5="Разведано $gg гор<br/>";}else{$gg=rand(100,500);$n5="Разведано $gg гор<br/>";}
///////////////////////////////////////////
////////////////////////////////////////lesa_prirost
if($n[lesa]!=0){$ll=round($n[lesa]*0.15);$n6="Выращено $ll леса<br/>";}else{$ll=rand(100,400);$n6="Выращено $ll леса<br/>";}
///////////////////////////////////////////rab_derevn
$sp=mysql_fetch_array(qw("SELECT id,der FROM domik WHERE strana ='$n[strana]' and domik5='1'"));
$sd=$sp[der]*10;
if($sp[id]>0){if($n[rab]>$sd){$rb=$n[rab]-$sd;$n7="Перенаселение!!! Дали Деру $rb рабочих!<br/>";}else{$rb=0;$n7='';}}else{$rb=0;$n7='';}
/////////////////////////////////////////////zhrat

$wr=mysql_fetch_array(qw("SELECT sum(peh)as a,sum(kon) as b,sum(str) as c FROM voyna WHERE strana='$n[strana]'"));
$re=mysql_fetch_array(qw("SELECT sum(rab) as rab FROM res WHERE strana='$n[strana]'"));
$s1=mysql_fetch_array(qw("SELECT sum(rab) as rab FROM stroyka WHERE strana='$n[strana]'"));
$s2=mysql_fetch_array(qw("SELECT sum(rab) as rab FROM stroyka2 WHERE strana='$n[strana]'"));
$bn=mysql_fetch_array(qw("SELECT login,naukpri,peh3,kon3,str3 FROM gos WHERE strana='$n[strana]'"));
$b1=mysql_fetch_array(qw("SELECT sum(bot) as bot FROM botan WHERE strana='$n[strana]'"));
$b2=mysql_fetch_array(qw("SELECT sum(bot) as bot FROM kmb WHERE strana='$n[strana]'"));
$b3=mysql_fetch_array(qw("SELECT sum(bot) as bot FROM nauka WHERE strana='$n[strana]'"));
$b4=mysql_fetch_array(qw("SELECT rab FROM nef WHERE strana='$n[strana]'"));
$arr1 = mysql_fetch_row(mysql_query("SELECT count(*) as a from voyna where vrag='$n[strana]'"));
$rec1= $arr1[0];

$rabz=($n[rab]+$re[rab]+$s1[rab]+$s2[rab]+$b4[rab])*2;$botz=($n[bot]+$b1[bot]+$b2[bot]+$b3[bot])*2;
$pehz=4*($n[peh]+$wr[a]+$bn[peh3]);$konz=6*($n[kon]+$wr[b]+$bn[kon3]);$strz=8*($n[str]+$wr[c]+$bn[str3]);
$zerno=$rabz+$botz+$pehz+$konz+$strz;
echo"($zerno)($n[zerno])<br/>";echo"wars [$rec1]<br/>";

if($n[zerno]>$zerno){$zer=$n[zerno]-$zerno;$n8="Население сьело $zerno зерна<br/>";$terra=1;$zrr=0;$pz=1;}else{
$zer=0;
$zr=$zerno-$n[zerno];$zrr=round(($zr*100)/$zerno);echo"($zr)($zrr)<br/>";
if($zrr==0){$n8="Население сьело всё зерно<br/>";$pz=1;
}else{
$n8="Не хватило зерна случился голодомор!Умерло $zrr % населения!";$pz=1;

$zr=$zerno-$n[zerno];$zrr=round(($zr*100)/$zerno);
if($zrr<80){
///////////vyzhivet
$pz=(100-$zrr)/100;$terra=1;

}else{
/////pizdyamba
if($rec1>0 or $lg[login]=='K'){$pz=(100-$zrr)/100;$terra=1;}else{
$terra=2;}
}}
}
///////////////////////prirost
$rabb=round((($n[rab]/100)*$bn[naukpri])/2);$n9="Прирост $rabb рабочих";
if($terra==1){
$gork=$n[gora]-$gor;$gork=$gork+$gg;$lesk=$n[lesa]-$les+$ll;
if($lg[login]=='K'){
$rab=$n[rab]+$rabb;$bot=$n[bot];
}else{
$rab=(($n[rab]-$rb)*$pz)+$rabb;$bot=$n[bot]*$pz;
}
mysql_query("UPDATE gos2 SET dengi=dengi+'$dengi',gora='$gork',lesa='$lesk',zerno='$zer',rab='$rab',bot='$bot',peh=peh*'$pz',
kon=kon*'$pz',str=str*'$pz',genn='$gn',genm='$gm',geno='$go',genv='$gv' WHERE strana='$n[strana]'");
mysql_query("UPDATE voyna SET peh=peh*'$pz',kon=kon*'$pz',str=str*'$pz' WHERE strana='$n[strana]'");
mysql_query("UPDATE res SET rab=rab*'$pz' WHERE strana='$n[strana]'");
mysql_query("UPDATE stroyka SET rab=rab*'$pz' WHERE strana='$n[strana]'");
mysql_query("UPDATE stroyka2 SET rab=rab*'$pz' WHERE strana='$n[strana]'");
mysql_query("UPDATE gos SET peh3=peh3*'$pz',kon3=kon3*'$pz',str3=str3*'$pz' WHERE strana='$n[strana]'");
mysql_query("UPDATE botan SET bot=bot*'$pz' WHERE strana='$n[strana]'");
mysql_query("UPDATE kmb SET bot=bot*'$pz' WHERE strana='$n[strana]'");
mysql_query("UPDATE nauka SET bot=bot*'$pz' WHERE strana='$n[strana]'");
mysql_query("UPDATE nef SET rab=rab*'$pz' WHERE strana='$n[strana]'");
$ng1="Новогодние вести.<br/>$n1$n2$n3$n4$n5$n6$n7$n8$n9";$tm=time();
$dt1=date("d");$dt2=date("m");$dt3=date("H");$dt4=date("i");
mysql_query("INSERT INTO logistik (vid,data,strana,text) VALUES('5','[$dt1:$dt2]($dt3:$dt4)','$n[strana]',
'$n1$n2$n3$n4$n5$n6$n7$n8$n9')");
mysql_query("INSERT INTO mess (komu,kto,data,st,tip,text) VALUES('$n[strana]','@','$tm','0','0','$ng1')");
echo"[$pz][$n[strana]]($ng1)<br/>";
}else{
///////////////////////////
$wr[vrag]=$n[strana];
qw("DELETE FROM gos WHERE strana='$wr[vrag]'");
qw("DELETE FROM gos2 WHERE strana='$wr[vrag]'");
qw("DELETE FROM botan WHERE strana='$wr[vrag]'");
qw("DELETE FROM domik WHERE strana='$wr[vrag]'");
qw("DELETE FROM voyna WHERE strana='$wr[vrag]'");
qw("DELETE FROM rynok WHERE strana='$wr[vrag]'");
qw("DELETE FROM kmb WHERE strana='$wr[vrag]'");
qw("DELETE FROM nauka WHERE strana='$wr[vrag]'");
qw("DELETE FROM sosed WHERE strana1='$wr[vrag]' or strana2='$wr[vrag]'");
qw("DELETE FROM soyuz WHERE strana1='$wr[vrag]' or strana2='$wr[vrag]'");
qw("DELETE FROM nef WHERE strana='$wr[vrag]'");
qw("DELETE FROM mess WHERE komu='$wr[vrag]'");
qw("DELETE FROM res WHERE strana='$wr[vrag]'");
qw("DELETE FROM stroyka WHERE strana='$wr[vrag]'");
qw("DELETE FROM stroyka2 WHERE strana='$wr[vrag]'");
qw("UPDATE users SET kill='Страна умерла от нехватки зерна' WHERE login='$lg[login]'");

}
}
?>