if($config['ag_style'] == '2'){
$coins_wood = 28000;
$coins_stone = 30000;
$coins_iron = 25000;
$vill = $_GET['village'];
$tpl->assign("coins_wood", $coins_wood);
$tpl->assign("coins_stone", $coins_stone);
$tpl->assign("coins_iron", $coins_iron);
$all_coins = mysql_fetch_array(mysql_query("SELECT * FROM users WHERE id = '".$user['id']."'")) or die (mysql_error());
$tpl->assign("allcoins", $all_coins['coins']);
$tpl->assign("nextsnob", $all_coins['nextsnob']);
$tpl->assign("coins_n", $all_coins['coins_n']);
$villages = mysql_query("SELECT * FROM villages WHERE userid = '".$user['id']."'");
while($a = mysql_fetch_array($villages)){
$snob_recruit = mysql_num_rows(mysql_query("SELECT * FROM recruit WHERE villageid = '".$a['id']."' AND `unit` = 'unit_snob'"));
$num_recruit = mysql_fetch_array(mysql_query("SELECT snob_recruit FROM villages WHERE id = '".$a['id']."'"));
if($num_recruit['0'] != $snob_recruit){
mysql_query("UPDATE villages SET snob_recruit = '".$snob_recruit."' WHERE id = '".$a['id']."'");
}
$num_recruits += $num_recruit['0'];
$units = mysql_query("SELECT unit_snob FROM unit_place WHERE villages_from_id = '".$a['id']."'");
while($b = mysql_fetch_array($units)){
$all_snob += $b['unit_snob'];
}
}
$tpl->assign("snob_recruit", $num_recruits);
$tpl->assign("all_snob", $all_snob);
$village_control = mysql_fetch_array(mysql_query("SELECT control_villages FROM villages WHERE id = '".$vill."'")) or die (mysql_error());
$tpl->assign("village_control", $village_control['0']);
$resource = mysql_fetch_array(mysql_query("SELECT * FROM villages WHERE id = '".$_GET['village']."'"));
$wood_r = number_format($resource['r_wood'],0,'','');
$stone_r = number_format($resource['r_stone'],0,'','');
$iron_r = number_format($resource['r_iron'],0,'','');
if($_GET['recruit'] == 'snob'){
if($all_coins['nextsnob'] - $all_snob - $num_recruits - $village_control['0'] < 1){
$error = 'Insuficienti taleri!'; $tpl->assign("error", $error);
}else{
$unit = "unit_snob";
$count = "1";
$building = "snob";
$building_stage = "1";
$vid = $_GET['village'];
$wood = $cl_units->get_woodprice($unit) * $count;
$stone = $cl_units->get_stoneprice($unit) * $count;
$iron = $cl_units->get_ironprice($unit) * $count;
$bh = $cl_units->get_bhprice($unit) * $count;
if($wood_r < $wood OR $stone_r < $stone OR $iron_r < $iron){
$error = 'Insuficiente materiale prime'; $tpl->assign("error", $error);
}else{
mysql_query("UPDATE villages SET r_wood = r_wood - '".$wood."' WHERE id = '".$_GET['village']."'") or die (mysql_error());
mysql_query("UPDATE villages SET r_stone = r_stone - '".$stone."' WHERE id = '".$_GET['village']."'");
mysql_query("UPDATE villages SET r_iron = r_iron - '".$iron."' WHERE id = '".$_GET['village']."'");
mysql_query("UPDATE villages SET r_bh = r_bh + '".$bh."' WHERE id = '".$_GET['village']."'");
mysql_query("UPDATE villages SET snob_recruit = snob_recruit + '1' WHERE id = '".$_GET['village']."'");
$recruit = $cl_units->recruit_units($unit, $count, $building, $building_stage, $vid);
header("Location: game.php?village=$vid&screen=snob");
}
}
}
if($_GET['create'] == 'coins'){
if($wood_r < $coins_wood OR $stone_r < $coins_stone OR $iron_r < $coins_iron){
$error = 'Insuficiente materiale prime';
$tpl->assign("error", $error);
}else{
mysql_query("UPDATE users SET coins = coins + 1 WHERE id = '".$user['id']."'") or die (mysql_error());
mysql_query("UPDATE users SET coins_n = coins_n + 1 WHERE id = '".$user['id']."'") or die (mysql_error());
$nextcoins_1 = mysql_fetch_array(mysql_query("SELECT nextsnob FROM users WHERE id = '".$user['id']."'")) or die (mysql_error());
$nextcoins_2 = mysql_fetch_array(mysql_query("SELECT coins_n FROM users WHERE id = '".$user['id']."'")) or die (mysql_error());
if($nextcoins_2['coins_n'] >= $nextcoins_1['nextsnob']){
mysql_query("UPDATE users SET nextsnob = nextsnob + 1 WHERE id = '".$user['id']."'") or die (mysql_error());
mysql_query("UPDATE users SET coins_n = '0' WHERE id = '".$user['id']."'") or die (mysql_error());
}
mysql_query("UPDATE villages SET r_wood = r_wood - '".$coins_wood."' WHERE id = '".$_GET['village']."'") or die (mysql_error());
mysql_query("UPDATE villages SET r_stone = r_stone - '".$coins_stone."' WHERE id = '".$_GET['village']."'");
mysql_query("UPDATE villages SET r_iron = r_iron - '".$coins_iron."' WHERE id = '".$_GET['village']."'");
header("Location: game.php?village=$vill&screen=snob");
}
}
}