rendered paste body<?
INCLUDE "db_connect.php";
$time1=time();
$ol_y = mysql_query("select * from overlords where place = 'yuaktz'");
$y_t=mysql_result($ol_y,0,"tax");
$ol_s = mysql_query("select * from overlords where place = 'shleincyrodil'");
$s_t=mysql_result($ol_s,0,"tax");
$ol_gp = mysql_query("select * from overlords where place = 'great_plains'");
$gp_t=mysql_result($ol_gp,0,"tax");
$ol_wp = mysql_query("select * from overlords where place = 'western_province'");
$wp_t=mysql_result($ol_wp,0,"tax");
$select_weather = mysql_query("select * from `weather`");
while($weather=mysql_fetch_array($select_weather))
{
$y_w=$weather['yuaktz'];
if($y_w== "rain"){$y_c= 1.1;}
if($y_w== "sunny"){$y_c= 1.15;}
if($y_w== "over cast"){$y_c= 1;}
$s_w=$weather['shleincyrodil'];
if($s_w== "rain"){$s_c= 1.1;}
if($s_w== "sunny"){$s_c= 1.15;}
if($s_w== "over cast"){$s_c= 1;}
if($s_w== "frosty"){$s_c= 0.75;}
$gp_w=$weather['great_plains'];
if($gp_w== "sunny"){$gp_c= 1.15;}
if($gp_w== "over cast"){$gp_c= 1;}
$wp_w=$weather['western_province'];
if($wp_w== "rain"){$wp_c= 1.1;}
if($wp_w== "frosty"){$wp_c= 0.75;}
}
###################### SELECTING USERS #######################################
$select_users=mysql_query("SELECT * FROM data WHERE bann='0' AND active > '0' ");
while($sel_users=mysql_fetch_array($select_users))
{
$username=$sel_users['username'];
$user_hashed=$sel_users['username_hashed'];
$user_net=$sel_users['netscore'];
$user_pop=$sel_users['pop'];
$user_xp=$sel_users['xp'];
$user_money=$sel_users['money'];
$user_pop=$sel_users['pop'];
$user_place=$sel_users['place'];
$user_turns=$sel_users['turns'];
$user_food=$sel_users['food'];
if($user_place=='yuaktz'){$tax=$y_t/100;}
if($user_place=='shleincyrodil'){$tax=$s_t/100;}
if($user_place=='great_plains'){$tax=$gp_t/100;}
if($user_place=='western_province'){$tax=$wp_t/100;}
############ CIV UNREST ##################################################################
$select_user_units=mysql_query("SELECT * FROM units WHERE username_hashed='$user_hashed' ");
while($sel_units = mysql_fetch_array($select_user_units))
{
$user_hi = $sel_units['heavy_infantry'];
$user_mi = $sel_units['medium_infantry'];
$user_li = $sel_units['light_infantry'];
$user_ww = $sel_units['war_weariness'];
$user_as = $sel_units['army_str'];
}
$army_req = ((sqrt($user_net) + $user_pop) - ($user_as + sqrt($user_xp)));
if($army_req<0){$army_req=1;}
if($user_as<$army_req){$civil_unrest =number_format(($user_as/$army_req),'2');}else{$civil_unrest=1;}
if($user_as==0 || $user_as<0){$civil_unrest=0;}
###############################################################################################
$select_user_labs=mysql_query("SELECT * FROM buildings WHERE username_hashed='$user_hashed' ");
while($sel_lab = mysql_fetch_array($select_user_labs))
{
$user_lab = $sel_lab['lab'];
$user_farms = $sel_lab['farms'];
$user_homes = $sel_lab['home'];
}
$profit=$user_pop*100*(1-$user_ww);
$costs=$user_hi*100+$user_mi*50+$user_li*10;
$gain=($profit-$costs)*$civil_unrest;
$gain_taxed=$gain*(1-$tax);
$gain_over=$gain*$tax;
//////////// OVERLORD CASH AND WEATHER BONUSES
if($user_place=='yuaktz'){$oy_money=$oy_money+$gain_over;$food_bonus=$y_c;}
if($user_place=='shleincyrodil'){$os_money=$os_money+$gain_over;$food_bonus=$s_c;}
if($user_place=='great_plains'){$ogp_money=$ogp_money+$gain_over;$food_bonus=$gp_c;}
if($user_place=='western_province'){$owp_money=$owp_money+$gain_over;$food_bonus=$wp_c;}
///////////////////////////////////////////////
###################### FAILSAFE CHECK ##########################
$second_select=mysql_query("SELECT money,turns,food FROM data WHERE username_hashed='$user_hashed'");
while($sel_sec = mysql_fetch_array($second_select))
{
$user_money=$sel_sec['money'];
$user_turns=$sel_sec['turns'];
$user_food=$sel_sec['food'];
}
################################################################
if($user_food<$user_pop){$dead=$user_pop-$user_food;}else{$dead=0;}
$new_pop=$user_homes*10-$dead;
$food_production=(($user_farms*100)*$food_bonus)*$civil_unrest;
$new_user_money=$gain_taxed+$user_money;
$new_turns = (($user_turns+$user_lab)+10);
$new_user_food=$user_food+$food_production-$new_pop;
if($new_user_food<0){$new_user_food=0;}
mysql_query("UPDATE data SET money='$new_user_money',turns='$new_turns',food='$new_user_food',pop='$new_pop' WHERE username_hashed='$user_hashed'");
if($user_ww>0)
{
$new_user_ww=$user_ww-0.05;
if($new_user_ww<=0){$new_user_ww=0;}
mysql_query("UPDATE units SET war_weariness='$new_user_ww' WHERE username_hashed='$user_hashed'");
}
}
##############################################################################################
###################################### EXPLORATIONS #########################
$select_voyage=mysql_query("SELECT * FROM voyages");
while($voyage=mysql_fetch_array($select_voyage))
{
$explorer=$voyage['username_hashed'];
$timer=$voyage['time'];
$timer2=$timer-1;
$l_gain=$voyage['land_expected'];
$force=$voyage['away'];
$id=$voyage['id'];
if($timer==0)
{
$select_explorer=mysql_query("SELECT * FROM data WHERE username_hashed='$explorer'");
while($explo=mysql_fetch_array($select_explorer))
{
$user_land=$explo['land'];
}
$select_unite=mysql_query("SELECT * FROM units WHERE username_hashed='$explorer'");
while($unite=mysql_fetch_array($select_unite))
{
$user_lip=$unite['light_infantry'];
}
$new_land=$user_land+$l_gain;
$new_lis=$user_lip+$force;
mysql_query("UPDATE data SET land='$new_land' WHERE username_hashed='$explorer'");
mysql_query("UPDATE units SET light_infantry='$new_lis' WHERE username_hashed='$explorer'");
mysql_query("delete from `voyages` where `id` = '$id'");
//MSG
$t=time();
$message = "<i>Your <b>".$force."</b> soldiers have arrived back from their voyage. They have discovered <b>".$l_gain."</b> Acres of new land for your empire! - from <b>Your Chief Messenger</b> on <b>".date("d/m/y",$t)."</b> at <b>".date("H:i:s",$t)."</b></i>";
mysql_query("INSERT INTO `news` (`username_hashed`,`latest`)VALUES('$explorer','$message')");
///////
}
else
{
mysql_query("UPDATE voyages SET time='$timer2' WHERE id='$id'");
}
}
##################################################################################################
################################### WEATHER ###########################################
$weather1 = RAND(1,2);
$weather2 = RAND(1,2);
$weather3 = RAND(1,3);
$weather4 = RAND(1,4);
IF($weather1 == 1){$weath1 = "sunny";}
IF($weather1 == 2){$weath1 = "over cast";}
IF($weather2 == 1){$weath2 = "frosty";}
IF($weather2 == 2){$weath2 = "rain";}
IF($weather3 == 1){$weath3 = "rain";}
IF($weather3 == 2){$weath3 = "sunny";}
IF($weather3 == 3){$weath3 = "over cast";}
IF($weather4 == 1){$weath4 = "rain";}
IF($weather4 == 2){$weath4 = "sunny";}
IF($weather4 == 3){$weath4 = "over cast";}
IF($weather4 == 4){$weath4 = "frosty";}
mysql_query("update `weather` set `great_plains` = '$weath1',`western_province` = '$weath2',`yuaktz` = '$weath3',`shleincyrodil` = '$weath4'");
##################################################################################################
$war_sel=mysql_query("select * from war_timer ");
while($war=mysql_fetch_array($war_sel))
{
$username_has = $war['username_hashed'];
$target = $war['target'];
$time1s=$war['time'];
$time2s=$time1s-1;
mysql_query("update `war_timer` set `time` = '$time2s' WHERE username_hashed='$username_has' AND target='$target'");
}
mysql_query("delete from `war_timer` where `time` = '0'");
mysql_query("delete from `war_timer` where `time` < '0'");
####################################### OVERLORD PAY #############################################
$o_y = mysql_query("select * from overlords where place = 'yuaktz'");
$y_o=mysql_result($o_y,0,"username");
if($y_o!='-')
{
$sel_o=mysql_query("SELECT * FROM data WHERE username='$y_o'");
$y_m=mysql_result($sel_o,0,"money");
$new_money=number_format(($oy_money+$y_m),'0','','');
mysql_query("update `data` set `money` = '$new_money' WHERE username='$y_o' ");
//MSG
$receiver=md5($y_o);
$message = "Sire You have received £ <b>".number_format($oy_money,'0')."</b> as your overlord pay.";
mysql_query("INSERT INTO `news` (`username_hashed`,`latest`)VALUES('$receiver','$message')");
///////
}
$o_s = mysql_query("select * from overlords where place = 'shleincyrodil'");
$s_o=mysql_result($o_s,0,"username");
if($s_o!='-')
{
$sel_o=mysql_query("SELECT * FROM data WHERE username='$s_o'");
$s_m=mysql_result($sel_o,0,"money");
$new_money=number_format(($os_money+$s_m),'0','','');
mysql_query("update `data` set `money` = '$new_money' WHERE username='$s_o' ");
//MSG
$receiver=md5($s_o);
$message = "Sire You have received £ <b>".number_format($os_money,'0')."</b> as your overlord pay.";
mysql_query("INSERT INTO `news` (`username_hashed`,`latest`)VALUES('$receiver','$message')");
///////
}
$o_gp = mysql_query("select * from overlords where place = 'great_plains'");
$gp_o=mysql_result($o_gp,0,"username");
if($gp_o!='-')
{
$sel_o=mysql_query("SELECT * FROM data WHERE username='$gp_o'");
$gp_m=mysql_result($sel_o,0,"money");
$new_money=number_format(($ogp_money+$gp_m),'0','','');
mysql_query("update `data` set `money` = '$new_money' WHERE username='$gp_o' ");
//MSG
$receiver=md5($gp_o);
$message = "Sire You have received £ <b>".number_format($ogp_money,'0')."</b> as your overlord pay.";
mysql_query("INSERT INTO `news` (`username_hashed`,`latest`)VALUES('$receiver','$message')");
///////
}
$o_wp = mysql_query("select * from overlords where place = 'western_province'");
$wp_o=mysql_result($o_wp,0,"username");
if($wp_o!='-')
{
$sel_o=mysql_query("SELECT * FROM data WHERE username='$wp_o'");
$wp_m=mysql_result($sel_o,0,"money");
$new_money=number_format(($owp_money+$wp_m),'0','','');
mysql_query("update `data` set `money` = '$new_money' WHERE username='$wp_o' ");
//MSG
$receiver=md5($wp_o);
$message = "Sire You have received £ <b>".number_format($owp_money,'0')."</b> as your overlord pay.";
$timeris=time();
mysql_query("INSERT INTO `news` (`username_hashed`,`latest`,`time`)VALUES('$receiver','$message','$timeris')");
///////
}
############################ RESETING ELECTION TABLE
$check_votes_num2=mysql_query("SELECT * FROM `voting`");
$num_checkings=mysql_num_rows($check_votes_num2);
$t=time();
$date=date("D",$t);
#echo"$date";
if($date=='Sun' && $num_checkings>=0)
{
mysql_query("TRUNCATE TABLE `voting`");
mysql_query("UPDATE `election_nominees` SET `votes`='0'");
}
########################################################################################################
$time2=time();
$time3=$time2-$time1;
#echo"Execution time : $time3 seconds";
#echo"<br>Taxes : y=$y_t , s=$s_t , gp=$gp_t , wp=$wp_t";
#echo"<br>Overlord money: y=$oy_money , s=$os_money , gp=$ogp_money , wp=$owp_money";
mysql_query("INSERT INTO `execution` (`time`,`exec`)VALUES('$time2','$time3')");
echo"$num_checkings";
?>