<?php
// Copyright by SlimShady95 < manuel_mannhardt@web.de >
// reload_ress() by milos
// Geklaut vom milos Bot :D
function reload_ress($vid)
{
global $arr_maxstorage, $arr_production, $config, $db;
$sql = 'SELECT * FROM `villages` WHERE `id` = ' . $vid;
$res = $db->query($sql);
$village = $db->fetch($res);
$time = time();
$wood = $village['r_wood'] + $arr_production[$village['wood']] * $config['speed'] / 60 / 60 * ($time - $village['last_prod_aktu']);
$stone = $village['r_stone'] + $arr_production[$village['stone']] * $config['speed'] / 60 / 60 * ($time - $village['last_prod_aktu']);
$iron = $village['r_iron'] + $arr_production[$village['iron']] * $config['speed'] / 60 / 60 * ($time - $village['last_prod_aktu']);
if($arr_maxstorage[$village['storage']] < $wood)
{
$wood = $arr_maxstorage[$village['storage']];
}
if ($arr_maxstorage[$village['storage']] < $stone)
{
$stone = $arr_maxstorage[$village['storage']];
}
if ($arr_maxstorage[$village['storage']] < $iron)
{
$iron = $arr_maxstorage[$village['storage']];
}
$sql = 'UPDATE `villages` SET `r_wood` = \'' . $wood . '\', `r_stone` = \'' . $stone . '\', `r_iron` = \'' . $iron . '\', last_prod_aktu = \'' . $time . '\' WHERE `id` = \'' . $vid . '\'';
$db->query($sql);
}
// Improvisation pur -.-'
$query = $db->query('SELECT * FROM `build` WHERE `end_time` < ' . time());
while($row = $db->fetch($query))
{
$db->query('UPDATE `villages` SET `' . $row['building'] . '` = `' . $row['building'] . '` + 1 WHERE `id` = ' . $row['villageid']);
$db->query('DELETE FROM `build` WHERE `id` = ' . $row['id']);
}
// Alle Dörfer holen, die weniger als die maximalen Punkte haben
$query = $db->query('SELECT * FROM `villages` WHERE `userid` = \'-1\' AND `points` < ' . $config['bb_max_points']);
while($row = $db->fetch($query))
{
// Baut da schon was?
$query2 = $db->query('SELECT * FROM `build` WHERE `villageid` = ' . $row['id']);
if($db->numrows($query2) == 0)
{
// Nein? Dann Gebäude auswählen
$builds = $cl_builds->get_array('dbname');
$build_village = array();
$id_array = array_flip($cl_builds->get_array('dbname'));
foreach($builds as $key => $value)
{
$build_village[$value] = $row[$value];
}
// Zufälliges Gebäude
$rand = rand(0, count($builds)-1);
$build = $builds[$rand];
// Bauen
$cl_builds->build($row, $id_array[$build], $build_village, 1);
#print $cl_builds->get_build_error2() . '<br />';
// Kein Fehler -> Rohstoffe abziehen und son Zeug halt
if($cl_builds->get_build_error2() == 'no_error')
{
// Rohstoffe abziehen
$wood = $cl_builds->get_wood($build, $row[$build] + 1);
$stone = $cl_builds->get_stone($build, $row[$build] + 1);
$iron = $cl_builds->get_iron($build, $row[$build] + 1);
$bh = $cl_builds->get_bh($build, $row[$build] + 1);
$time = $cl_builds->get_time($row['main'], $build, $row[$build] + 1) + time();
$onlytime = $cl_builds->get_time($row['main'], $build, $row[$build] + 1);
$db->query('UPDATE `villages` SET `r_wood` = `r_wood` - ' . round($wood) . ', `r_stone` = `r_stone` - ' . round($stone) . ', `r_iron` = `r_iron` - ' . round($iron) . ', `r_bh` = `r_bh` + ' . $bh . ' WHERE `id` = ' . $row['id']);
$db->query('INSERT INTO `build` (`building`, `villageid`, `end_time`, `build_time`) VALUES (\'' . $build . '\',' . $row['id'] . ',' . $time . ', ' . $onlytime . ')');
}
}
reload_ress($row['id']);
}