<?php
require'fun.php';
require'f_conectare.php';
conectare('cladire principala (triburile v2)','triburile2-cladire-principala');
$titlu='Cladire principala - Triburile V2';
$back[1]='<a href="/triburile2">'.img('triburile.gif',1).'Triburi</a>';
require'f_sus.php';
require'triburile2_nicu1.php';
require'f_ramas.php';
if(isset($_GET['pid']))
{
$cl=['','`t2_cladire_principala`','`t2_lemn`','`t2_argila`','`t2_piatra`','`t2_zid`','`t2_ferma`','`t2_ascunzatoare`','`t2_cazermata`','`t2_grajd`','`t2_fierarie`','`t2_magazie`'];
$tir=$conn->query('SELECT COUNT(*)FROM`t2_procese`WHERE`id`="'.$pid.'"')->fetch_row();
if($tir[0])
{
$tiu=$conn->query('SELECT`lvl`,`tip`FROM`t2_procese`WHERE`id`="'.$pid.'"')->fetch_row();
$lol=$conn->query('SELECT COUNT(*),`id`FROM`t2_procese`WHERE`de`="'.$de.'"&&`tip`="'.$tiu[1].'"&&`lvl`>"'.$tiu[0].'"')->fetch_row();
if($lol[0])
{
$lot=$conn->query('SELECT`id`,`lvl`,`tip`FROM`t2_procese`WHERE`id`="'.$lol[1].'"')->fetch_row();
$fa=$conn->query('SELECT`lmn`,`arg`,`ptr`,`pop`FROM'.$cl[$lot[2]].'WHERE`lvl`="'.$lot[1].'"')->fetch_row();
$tot=$conn->query('SELECT`lmn`,`arg`,`ptr`,`pop`,`pct`FROM`t2_membrii`WHERE`de`="'.$de.'"')->fetch_row();
$lmn=$tot[0]+$fa[0];
$arg=$tot[1]+$fa[1];
$ptr=$tot[2]+$fa[2];
$pop=$tot[3]-$fa[3];
$pct=$tot[4]-$fa[3];
$conn->query('UPDATE`t2_membrii`SET`lmn`="'.$lmn.'",`arg`="'.$arg.'",`ptr`="'.$ptr.'",`pop`="'.$pop.'",`pct`="'.$pct.'"WHERE`de`="'.$de.'"');
$conn->query('DELETE FROM`t2_procese`WHERE`id`="'.$lot[0].'"');
}
else
{
$tip=$conn->query('SELECT`tip`,`lvl`FROM`t2_procese`WHERE`id`="'.$pid.'"')->fetch_row();
$fa=$conn->query('SELECT`lmn`,`arg`,`ptr`,`pop`FROM'.$cl[$tip[0]].'WHERE`lvl`="'.$tip[1].'"')->fetch_row();
$tot=$conn->query('SELECT`lmn`,`arg`,`ptr`,`pop`,`pct`FROM`t2_membrii`WHERE`de`="'.$de.'"')->fetch_row();
$lmn=$tot[0]+$fa[0];
$arg=$tot[1]+$fa[1];
$ptr=$tot[2]+$fa[2];
$pop=$tot[3]-$fa[3];
$pct=$tot[4]-$fa[3];
$conn->query('UPDATE`t2_membrii`SET`lmn`="'.$lmn.'",`arg`="'.$arg.'",`ptr`="'.$ptr.'",`pop`="'.$pop.'",`pct`="'.$pct.'"WHERE`de`="'.$de.'"');
$conn->query('DELETE FROM`t2_procese`WHERE`id`="'.$pid.'"');
}
}
}
$msg='';
$proces=$conn->query('SELECT COUNT(*)FROM`t2_procese`WHERE`tip`="1"&&`de`="'.$de.'"')->fetch_row();
if($proces[0]<2)
{
if($go!='')
{
$ggo=$conn->query('SELECT COUNT(*)FROM`t2_cladire_principala`WHERE`lvl`="'.$go.'"')->fetch_row();
$ggoe=$conn->query('SELECT`lvlprin`FROM`t2_membrii`WHERE`de`="'.$de.'"')->fetch_row();
$fot=$ggoe[0]+1;
$fe=$conn->query('SELECT COUNT(*)FROM`t2_procese`WHERE`de`="'.$de.'"&&`tip`="1"')->fetch_row();
if($fe[0])
{
$fe=$conn->query('SELECT`lvl`FROM`t2_procese`WHERE`de`="'.$de.'"&&`tip`="1"')->fetch_row();
$fot=$fe[0]+1;
}
if($ggo[0]&&($go==$fot))
{
$ggo=$conn->query('SELECT`lmn`,`arg`,`ptr`,`timp`,`pop`FROM`t2_cladire_principala`WHERE`lvl`="'.$go.'"')->fetch_row();
$ggo1=$conn->query('SELECT`lmn`,`arg`,`ptr`,`pop`,`pct`,`poptot`,`lvlfrm`FROM`t2_membrii`WHERE`de`="'.$de.'"')->fetch_row();
$poptot=$conn->query('SELECT`cant`FROM`t2_ferma`WHERE`lvl`="'.$ggo1[6].'"')->fetch_row();
$lmn=$ggo1[0]-$ggo[0];
$arg=$ggo1[1]-$ggo[1];
$ptr=$ggo1[2]-$ggo[2];
$pop=$ggo1[3]+$ggo[4];
$pct=$ggo1[4]+$ggo[4];
if($poptot[0]<$pop)
$msg.=$div[7].'Nu poți avea în sat mai mult de <strong>'.$pop.'</strong> persoane!<br />Ridica nivelul fermei!'.$div[0];
elseif($ggo1[0]<$ggo[0])
$msg.=$div[7].'Nu ai destul lemn!'.$div[0];
elseif($ggo1[1]<$ggo[1])
$msg.=$div[7].'Nu ai destula argila!'.$div[0];
elseif($ggo1[2]<$ggo[2])
$msg.=$div[7].'Nu ai destul fier!'.$div[0];
else
{
$no1=$conn->query('UPDATE`t2_membrii`SET`lmn`="'.$lmn.'",`arg`="'.$arg.'",`ptr`="'.$ptr.'",`pop`="'.$pop.'",`pct`="'.$pct.'"WHERE`de`="'.$de.'"');
$toy=$conn->query('SELECT COUNT(*)FROM`t2_procese`WHERE`de`="'.$de.'"')->fetch_row();
if($toy[0])
{
$topt=$conn->query('SELECT`timp`,`data`FROM`t2_procese`WHERE`de`="'.$de.'"ORDER BY`id`DESC LIMIT 1 ')->fetch_row();
$timpe=$topt[0]+$topt[1];
}
else
$timpe=$_SERVER['REQUEST_TIME'];
$no=$conn->query('INSERT INTO`t2_procese`SET`de`="'.$de.'",`tip`="1",`data`="'.$timpe.'",`timp`="'.$ggo[3].'",`lvl`="'.$go.'"');
if($no1&&$no)
$msg=$div[6].'Comanda acceptata!'.$div[0];
else
$msg=$div[7].'Eroare!'.$div[0];
}
}
else
$msg=$div[7].'Eroare!'.$div[0];
}
}
echo$msg;
require'triburile2_nicu2.php';
echo$div[4].'<img src="'.$domenii_statice[2].'triburile2/main.png" alt="" />Cladire Principala (nivel '.$if[20].')'.$div[5].$div[10].'In cladirea principala pot fi construite cladiri noi sau imbunatatite cladirile existente.<br />Cu cat mai inalt nivelul, cu atat mai repede pot fi construite cladiri noi.<br />In momentul în care cladirea principala a atins nivelul 15, ai posibilitatea sa demolezi cladiri.'.$div[0];
$lvlprin=$if[20];
$fe=$conn->query('SELECT COUNT(*)FROM`t2_procese`WHERE`de`="'.$de.'"&&`tip`="1"')->fetch_row();
if($fe[0])
{
$fe=$conn->query('SELECT`lvl`FROM`t2_procese`WHERE`de`="'.$de.'"&&`tip`="1"ORDER BY`id`DESC LIMIT 1')->fetch_row();
$lvlprin=$fe[0];
}
if($lvlprin==$conn->query('SELECT COUNT(*)FROM`t2_cladire_principala`')->fetch_row()[0])
echo$div[6].'Cladire complet terminata!'.$div[0];
else
{
echo$div[7].'Nivelul '.++$lvlprin.' costă: ';
$lvl=$conn->query('SELECT`lmn`,`arg`,`ptr`,`pop`,`timp`FROM`t2_cladire_principala`WHERE`lvl`="'.$lvlprin.'"')->fetch_row();
echo'<img src="'.$domenii_statice[2].'triburile2/lemne.png" alt="lemn" />'.$lvl[0].'<img src="'.$domenii_statice[1].'triburile2/argila.png" alt="argile" />'.$lvl[1].'<img src="'.$domenii_statice[1].'triburile2/piatra.png" alt="piatra" />'.$lvl[2].'<br /><img src="'.$domenii_statice[2].'triburile2/populatie.png" alt="populatie" />'.$lvl[3].'<img src="'.$domenii_statice[2].'triburile2/clock.png" alt="ceas" />'.ramas($lvl[4]).$div[0];
$ggo=$conn->query('SELECT`lmn`,`arg`,`ptr`,`timp`,`pop`FROM`t2_cladire_principala`WHERE`lvl`="'.$lvlprin.'"')->fetch_row();
$ggo1=$conn->query('SELECT`lmn`,`arg`,`ptr`,`pop`,`pct`,`poptot`FROM`t2_membrii`WHERE`de`="'.$de.'"')->fetch_row();
$lmn=$ggo1[0]-$ggo[0];
$arg=$ggo1[1]-$ggo[1];
$ptr=$ggo1[2]-$ggo[2];
$pop=$ggo1[3]+$ggo[4];
$pct=$ggo1[4]+$ggo[4];
$te=$conn->query('SELECT COUNT(*)FROM`t2_procese`WHERE`de`="'.$de.'"')->fetch_row();
$fef=$conn->query('SELECT COUNT(*)FROM`t2_procese`WHERE`de`="'.$de.'"&&`tip`="1"')->fetch_row();
if($ggo1[0]>$ggo[0]&&$ggo1[1]>$ggo[1]&&$ggo1[2]>$ggo[2])
{
if($fef[0]>=2)
echo$div[7].'Nu poți da mai mult de 2 nivele de constructii pe aceeas cladire!'.$div[0];
elseif($te[0]<2||$if[13]==1)
{
if($te[0]<=7)
{
if($lvlprin-1==0)
echo$div[1].'<a href="/triburile2-cladire-principala/tip/'.$lvlprin.'">Construire</a>'.$div[0];
else
echo$div[1].'<a href="/triburile2-cladire-principala/tip/'.$lvlprin.'">Extindere nivel '.$lvlprin.'</a>'.$div[0];
}
else
echo$div[7].'Numarul maxim de constructii pe cont Premium!'.$div[0];
}
elseif($te[0]>=2)
echo$div[7].'Trebuie să ai cont Premium pentru mai mult de 2 nivele de constructie!'.$div[0];
}
else
echo$div[7].'Nu ai suficienta materie!'.$div[0];
}
echo$div[4].'In constructie:'.$div[5];
$items=$conn->query('SELECT`de`,`tip`,`lvl`,`data`,`timp`,`id`FROM`t2_procese`WHERE`de`="'.$de.'"ORDER BY`id`ASC');
$cou=0;
echo'<table columns="5"><tr><th><strong>Cladire</strong></th><th><strong>Nivel</strong></th><th><strong>Timp</strong></th><th><strong>Term</strong></th><th><strong>[X]</strong></th></tr>';
require'f_data.php';
while($item=$items->fetch_row())
{
$cou++;
$term=$item[4]+$item[3];
echo'<tr><td>'.['','Cladire Principala','Taietor lemne','Mina de argila','Mina de fier','Zid','Ferma','Ascunzatoare','Cazarma','Grajd','Fierarie','Magazie'][$item[1]].'</td><td>'.$item[2].'</td><td>'.($cou==1?ramas($term-$_SERVER['REQUEST_TIME']):ramas($item[4])).'</td><td><small>'.data($term).'</small></td><td><a href="/triburile2-cladire-principala/id/'.$item[5].'"><img src="'.$domenii_statice[2].'sterge.png" alt="" width="16" height="16" /></a></td></tr>';
}
echo'</table>';
require'f_jos.php';