$rec_itemdata = mysql_fetch_array(mysql_query($sql_itemdata));
			$item_resource += $rec_itemdata['cost_steel'] + $rec_itemdata['cost_crystal'] + $rec_itemdata['cost_erbium'] + $rec_itemdata['cost_titanium'];
		}
		$sql_resunits = "SELECT * FROM $table[playerunit] WHERE `player_id` = '$id'";
		$res_resunits = mysql_query($sql_resunits);
		while ($rec_resunits = mysql_fetch_array($res_resunits)) {
			$sql_unitdata = "SELECT `cost_steel`, `cost_crystal`, `cost_erbium`, `cost_titanium` FROM $table[ships] WHERE `id` = '$rec_resunits[unit_id]'";
			$rec_unitdata = mysql_fetch_array(mysql_query($sql_unitdata));
			$unit_resource += ($rec_unitdata['cost_steel'] + $rec_unitdata['cost_crystal'] + $rec_unitdata['cost_erbium'] + $rec_unitdata['cost_titanium']) * $rec_resunits['amount'];
		}
		$total_asteroids = $p['roid_steel'] + $p['roid_crystal'] + $p['roid_erbium'] + $p['roid_unused'];
		$new['score'] = ($stock_resource / 150) + ($item_resource / 30) + ($unit_resource / 15) + ($total_asteroids * 1000);

		include('ticker.battle-engine.php');

		updatePlayerData($id, $new);
	}
	include('ticker.fleetcheck.php');
	putCurrentTick($current);
	include('ticker.universe.php');
} else {
	//putCurrentTick(0);
}

$time_end = getmicrotime();
$time = $time_end - $time_start;
$num = rand();

//echo 'The ticker ran for '.$time.' seconds.';
?>
					$table[items].cost_steel, $table[items].cost_crystal, $table[items].cost_erbium, $table[items].cost_titanium
				FROM $table[productions] 
				INNER JOIN $table[items] ON $table[productions].item_id = $table[items].id
				WHERE $table[productions].id = '$prod_id' AND $table[productions].player_id = $playerdata[id]";
	$res_findcprod = mysql_query($sql_findcprod);
	$num_findcprod = mysql_num_rows($res_findcprod);
	if ($num_findcprod > 0) {
		$rec_findcprod = mysql_fetch_assoc($res_findcprod);
		$sql_cancelprod = "DELETE FROM $table[productions] WHERE `id` = '$rec_findcprod[id]'";
		mysql_query($sql_cancelprod);
		if (mysql_affected_rows() > 0) {
			$playerdata['res_steel'] += ($rec_findcprod['cost_steel'] * 0.80);
			$playerdata['res_crystal'] += ($rec_findcprod['cost_crystal'] * 0.80);
			$playerdata['res_erbium'] += ($rec_findcprod['cost_erbium'] * 0.80);
			$playerdata['res_titanium'] += ($rec_findcprod['cost_titanium'] * 0.80);
			updatePlayerData(IB_PLAYER_ID, $playerdata);
			$error = 2;
		} else {
			$error = 106;
		}
	} else {
		$error = 107;
	}
}

switch($error) {
	case 1:
	$msg = "Succesfully added production.";
	break;
	case 2:
	$msg = 'Succesfully canceled production.<br />You got 80% of the spent resources back.';
		updatePlayerData($playerdata['id'], $playerdata);
		$error = 2;
	} else {
		$error = 104;
	}
}
if ($do == 'joinalliance') { 
	$password = secureData($_POST['password']);
	$sql_checkalliance = "SELECT `id` FROM $table[alliance] WHERE `password` = '$password'";
	$res_checkalliance = mysql_query($sql_checkalliance);
	$num_checkalliance = mysql_num_rows($res_checkalliance);
	$rec_checkalliance = mysql_fetch_array($res_checkalliance);
	if ($num_checkalliance > 0) {
		if ($rec_checkalliance['id'] != $playerdata['alliance_id']) {
			$playerdata['alliance_id'] = $rec_checkalliance['id'];
			updatePlayerData($playerdata['id'], $playerdata);
			$error = 3;
		} else {
			$error = 105;
		}
	} else {
		$error = 106;
	}
}
if ($do == 'changerulerplanet') {
	$rulername = secureData($_POST['rulername']);
	$planetname = secureData($_POST['planetname']);
	if (!$rulername || !$planetname) { $error = 108; }
	if (getCurrentTick() > 1500) { $error = 109; }
	if ((getIdByRulername($rulername)) && ($rulername != $playerdata['rulername'])) { $error = 110; }
	if ((getIdByPlanetname($planetname)) && ($planetname != $playerdata['planetname'])) { $error = 111; }
function decreaseCurrentResources($player_id, $steel, $crystal, $erbium, $titanium) {
	global $table, $playerdata;
	$new = $playerdata;
	$new['res_steel'] = $playerdata['res_steel'] - $steel;
	$new['res_crystal'] = $playerdata['res_crystal'] - $crystal;
	$new['res_erbium'] = $playerdata['res_erbium'] - $erbium;
	$new['res_titanium'] = $playerdata['res_titanium'] - $titanium;
	updatePlayerData($player_id, $new);
}