$news_text_extra = sprintf($st[47], $user_ship[colon], $user[login_name]); } elseif ($temp == 3) { $extra_text = "<br />" . $st[48]; $news_text_extra = sprintf($st[49], $user[login_name], $user_ship[colon]); } elseif ($temp == 4) { $extra_text = "<br />" . $st[50]; $news_text_extra = sprintf($st[51], $user[login_name], $user_ship[colon]); } post_news($news_text_extra, "other, player_status"); } dbn("update {$db_name}_ships set metal=0, fuel=0, elect=0, colon=0 where ship_id = '{$user_ship['ship_id']}'"); $user_ship['metal'] = 0; $user_ship['fuel'] = 0; $user_ship['elect'] = 0; $user_ship['colon'] = 0; empty_bays($user_ship); $user_loc_message .= $cw['cargo_jettisoned'] . ". \n{$extra_text}<p />"; } } if ($_GET['tempo']) { if (!$user['gdt']) { $user_loc_message .= "<p>" . $st[1801] . "</p>"; } else { $cyclesenp = mt_rand(50, 150); $cycles = $user['turns'] + $cyclesenp; if ($cycles > $GAME_VARS['max_turns']) { $cycles = $GAME_VARS['max_turns']; } dbn("update {$db_name}_users set gdt=gdt-1, turns={$cycles} where login_id=" . $user['login_id']); $user['gdt']--; $user_loc_message .= "<p>" . sprintf($st[1802], $cyclesenp) . "</p>";
function load_unload_planet($selected_ships, $load_or_unload, $do_ship = 0) { global $user, $user_ship, $db_name, $tech_mat, $text_mat, $planet, $sure, $type, $dump_all, $cw, $st; discern_type($type); $extra_where = ""; $captaining = 0; if ($selected_ships == 1) { foreach ($do_ship as $ship_id) { $extra_where .= "ship_id = '{$ship_id}' || "; if ($ship_id == $user['ship_id']) { $captaining = 1; } } $extra_where = preg_replace("/\\|\\| \$/", "", $extra_where); $extra_where = "&& ({$extra_where})"; } if ($load_or_unload == 2) { //unloading the ship //select all ships that are valid db("select sum({$tech_mat}) as goods, count(ship_id) as ship_count from {$db_name}_ships where login_id = '{$user['login_id']}' && location = '{$user['location']}' && {$tech_mat} > 0 " . $extra_where); $results = dbr(1); $turn_cost = ceil($results['ship_count'] * 0.75); $max_reached = ""; if (!isset($results['goods'])) { //no goods on any ships return sprintf($st[1535], $text_mat); } elseif ($user['turns'] < $turn_cost && !isset($dump_all)) { //insufficient turns return sprintf($st[1536], $turn_cost); unset($results); } elseif ($results['goods'] + $planet['colon'] > $planet['max_population'] && $type == 1) { $max_reached = "<b class='b1'>" . $cw['warning'] . "</b>: " . $st[1537]; } elseif (!isset($sure) && $selected_ships == 0 && !isset($dump_all)) { //confirmation get_var($st[1538] . " {$text_mat}", 'planet.php', sprintf($st[1539], $text_mat, $results[goods], $results[ship_count], $turn_cost) . $max_reached, 'sure', 'yes'); } else { //finish unloading the planets. $t_cost_str = ""; dbn("update {$db_name}_planets set {$tech_mat} = {$tech_mat} + '{$results['goods']}' where planet_id = '{$user['on_planet']}'"); dbn("update {$db_name}_ships set {$tech_mat} = 0 where login_id = '{$user['login_id']}' && location = '{$user['location']}' && {$tech_mat} > 0 " . $extra_where); if (!isset($dump_all)) { charge_turns($turn_cost); $t_cost_str = " pour un coût total de <b>{$turn_cost}</b> cycles."; } if ($captaining == 1 || $selected_ships == 0 && $user_ship[$tech_mat] > 0) { $user_ship[$tech_mat] = 0; empty_bays($user_ship); } $planet[$tech_mat] += $results['goods']; return "<b>{$results['goods']}</b> " . sprintf($st[1540], $text_mat, $results[ship_count]) . $t_cost_str; } } else { //loading the ship $taken = 0; //goods taken from planet so far. $ship_counter = 0; if ($planet[$tech_mat] < 1) { //can't take stuff if there isn't any to take return sprintf($st[1541], $text_mat); } elseif ($type == 0) { //fighters db2("select ship_id,(max_fighters - fighters) as free,ship_name, {$tech_mat} from {$db_name}_ships where login_id = '{$user['login_id']}' && location = '{$user['location']}' && (max_fighters - fighters) > 0 {$extra_where} order by free desc"); } elseif ($type != 0) { db2("select ship_id, (cargo_bays - metal - fuel - elect - colon) as free, ship_name, {$tech_mat} from {$db_name}_ships where login_id = '{$user['login_id']}' && location = '{$user['location']}' && (cargo_bays - metal - fuel - elect - colon) > 0 {$extra_where} order by free desc"); } $ships = dbr2(1); $first_mess = ""; $sec_mess = ""; $turns_txt = ""; $out = ""; if ($type == 0 && $planet['allocated_to_fleet'] > 0) { //warning about fighter allocation $first_mess = $cw['warning'] . ".<br /> " . $st[1542]; $sec_mess = $cw['warning'] . ":<br />" . $st[1543]; } if (!isset($ships['ship_id']) && $selected_ships == 0) { //check to see if there are any ships return $st[1544] . " <b class='b1'>{$text_mat}</b>."; } elseif (!isset($ships['ship_id']) && $selected_ships == 1) { //check to see if there are any ships return $st[1545] . " <b class='b1'>{$text_mat}</b>."; } else { while ($ships) { $ship_counter++; //planet can load ship w/ spare fighters. if ($ships['free'] < $planet[$tech_mat] - $taken) { if (isset($sure) || $selected_ships == 1) { //only run during the real thing. dbn("update {$db_name}_ships set {$tech_mat} = {$tech_mat} + '{$ships['free']}' where ship_id = '{$ships['ship_id']}'"); $out .= "<br /><b class='b1'>{$ships['ship_name']}</b> : " . sprintf($st[1546], $ships[free], $text_mat); if ($ships['ship_id'] == $user_ship['ship_id'] && $type == 0) { #update user ship $user_ship['fighters'] = $user_ship['max_fighters']; } elseif ($ships['ship_id'] == $user_ship['ship_id'] && $type > 0) { #update user ship $user_ship[$tech_mat] += $ships['free']; $user_ship['empty_bays'] -= $ships['free']; } } $taken += $ships['free']; //ensure user has enough turns, or stop the loop where the user is. if ($user['turns'] <= ceil($ship_counter * 0.75)) { $turns_txt = $st[1547]; $out .= $st[1548]; unset($ships); break; } //planet will run out of fighters. } elseif ($ships['free'] >= $planet[$tech_mat] - $taken) { $t868 = $ships[$tech_mat] + ($planet[$tech_mat] - $taken); if (isset($sure) || $selected_ships == 1) { #only run during the real thing. dbn("update {$db_name}_ships set {$tech_mat} = '{$t868}' where ship_id = '{$ships['ship_id']}'"); $out .= "<br /><b class='b1'>{$ships['ship_name']}</b>s " . $st[1549] . " <b>{$t868}</b> <b class='b1'>{$text_mat}</b>"; if ($ships['ship_id'] == $user_ship['ship_id'] && $type == 0) { #update user ship $user_ship['fighters'] = $t868; } elseif ($ships['ship_id'] == $user_ship['ship_id'] && $type > 0) { #update user ship $user_ship[$tech_mat] = $t868; empty_bays($user_ship); } } $taken += $t868 - $ships[$tech_mat]; unset($ships); break; } $ships = dbr2(1); } #end loop of ships $turn_cost = ceil($ship_counter * 0.75); if (!isset($sure) && $selected_ships == 0) { get_var($st[1550], 'planet.php', $turns_txt . sprintf($st[1551], $ship_counter, $taken, $text_mat, $turn_cost) . "<p />" . $first_mess, 'sure', 'yes'); } else { dbn("update {$db_name}_planets set {$tech_mat} = {$tech_mat} - '{$taken}' where planet_id = '{$user['on_planet']}'"); $planet[$tech_mat] -= $taken; if ($planet['allocated_to_fleet'] > 0 && $type == 0) { dbn("update {$db_name}_planets set allocated_to_fleet = 0 where planet_id = '{$user['on_planet']}'"); } charge_turns($turn_cost); if ($type == 1) { #colonists $planet['alloc_fight'] = 0; $planet['alloc_elect'] = 0; dbn("update {$db_name}_planets set alloc_fight = 0, alloc_elect=0 where planet_id = '{$user['on_planet']}'"); $out .= $st[1552]; } return "<b>{$ship_counter}</b>" . sprintf($st[1553], $taken, $text_mat) . " <b class='b1'>{$planet['planet_name']}</b>:<br />" . $out . "<p />" . $st[1554] . " <b>{$turn_cost}</b>.<p />" . $sec_mess; } } } }
function bay_storage_little($ship) { if (empty($ship['cargo_bays'])) { return "\n <b>" . $cw['none'] . "</b>"; } $ret_str = ""; $colour = ''; empty_bays($ship); if ($ship['cargo_bays'] * 0.1 > $ship['empty_bays']) { $colour = '#c00000'; } elseif ($ship['cargo_bays'] * 0.25 > $ship['empty_bays']) { $colour = '#d6750e'; } if ($colour) { $ret_str .= "<font color={$colour}><b>"; } $bay_storage = str_replace("'", "\\'", bay_storage($ship)); if ($ship['cargo_bays'] - $ship['empty_bays']) { $ret_str .= "<span onmouseover=\"montre('{$bay_storage}');\" onmouseout=\"cache();\">"; } $ret_str .= "<b>" . ($ship['cargo_bays'] - $ship['empty_bays']) . '/' . $ship['cargo_bays'] . "</b>"; if ($ship['cargo_bays'] - $ship['empty_bays']) { $ret_str .= "</span>"; } if ($colour) { $ret_str .= '</b></font>'; } return $ret_str; }
function process_mining() { global $db_name, $final_str, $GAME_VARS, $st, $cw; if ($GAME_VARS['alternate_play_1'] == 1) { //alternate db2("select s.ship_id, s.location, s.mine_rate_metal, s.mine_rate_fuel, s.cargo_bays, s.metal, s.fuel, s.elect, s.colon, star.metal AS star_metal, star.fuel AS star_fuel, star.star_id, s.mine_mode\t\t\tfrom {$db_name}_stars star, {$db_name}_ships s\t\twhere star.star_id = s.location && s.location != 1 && (s.cargo_bays - s.metal - s.fuel - s.elect - s.colon) > 0 && ((s.mine_mode = 1 && s.mine_rate_metal > 0 && star.metal > 0) || (s.mine_mode = 2 && s.mine_rate_fuel > 0 && star.fuel > 0)) && s.login_id not in ( (select login_id from users_holiday_mode where mode = 1) )"); } else { //normal db2("select s.ship_id, s.location, (s.mine_rate_metal + s.mine_rate_fuel) as mine_rate_metal, (s.mine_rate_metal + s.mine_rate_fuel) as mine_rate_fuel, s.cargo_bays, s.metal, s.fuel, s.elect, s.colon, star.metal AS star_metal, star.fuel AS star_fuel, star.star_id, s.mine_mode\t\tfrom {$db_name}_stars star, {$db_name}_ships s\t\twhere star.star_id = s.location && s.location != 1 && (s.cargo_bays - s.metal - s.fuel - s.elect - s.colon) > 0 && mine_rate_metal > 0 && ((s.mine_mode = 1 && star.metal > 0) || (s.mine_mode = 2 && star.fuel > 0)) && s.login_id not in ( (select login_id from users_holiday_mode where mode = 1) )"); } $metal_fuel = array(); while ($ships = dbr2(1)) { //new star system. get metal content if (!isset($metal_fuel[$ships['star_id']]['metal'])) { $metal_fuel[$ships['star_id']]['metal'] = $ships['star_metal']; } //new star system. get fuel content if (!isset($metal_fuel[$ships['star_id']]['fuel'])) { $metal_fuel[$ships['star_id']]['fuel'] = $ships['star_fuel']; } if ($ships['mine_mode'] == 1) { $str_txt = 'metal'; } else { $str_txt = 'fuel'; } //run out of that resource in this system. if ($metal_fuel[$ships['star_id']][$str_txt] <= 0) { continue 1; } //make up an amount of metal/fuel to mine. $temp_amount = $ships['mine_rate_' . $str_txt] + mt_rand(-1, 1); empty_bays($ships); //if this takes to cargo capacity, lower temp_amount if ($ships['empty_bays'] <= $temp_amount) { $temp_amount = $ships['empty_bays']; } //update the dbn("update {$db_name}_ships set {$str_txt} = {$str_txt} + '{$temp_amount}' where ship_id = '{$ships['ship_id']}'"); //update ship and star resources. $metal_fuel[$ships['star_id']][$str_txt] -= $temp_amount; } $final_str .= "<br />\n" . count($metal_fuel) . $st[1859]; print_time(); //************************planetary mining ***************************** $planet_count = 0; db2("select p.planet_id, p.location, p.drones_alloc_fuel, p.drones_alloc_metal, star.fuel AS star_fuel, star.metal AS star_metal, star.star_id\t\t\t from {$db_name}_stars star, {$db_name}_planets p where ((star.fuel > 0 && p.drones_alloc_fuel > 0) || (star.metal > 0 && p.drones_alloc_metal > 0)) && star.star_id = p.location && p.login_id not in ( (select login_id from users_holiday_mode where mode = 1) )"); #planetary mining loop while ($planet = dbr2(1)) { //new star system. get metal content if (!isset($metal_fuel[$planet['star_id']]['metal'])) { $metal_fuel[$planet['star_id']]['metal'] = $planet['star_metal']; } //new star system. get fuel content if (!isset($metal_fuel[$planet['star_id']]['fuel'])) { $metal_fuel[$planet['star_id']]['fuel'] = $planet['star_fuel']; } $fuel_to_mine = 0; $metal_to_mine = 0; if ($planet['drones_alloc_fuel'] > 0) { $fuel_to_mine = $planet['drones_alloc_fuel']; //don't overmine the system. if ($fuel_to_mine > $metal_fuel[$planet['star_id']]['fuel']) { $fuel_to_mine = $metal_fuel[$planet['star_id']]['fuel']; } if ($fuel_to_mine < 1) { //no negative by accident. $fuel_to_mine = 0; } } if ($planet['drones_alloc_metal'] > 0) { $metal_to_mine = $planet['drones_alloc_metal']; //don't overmine the system. if ($metal_to_mine > $metal_fuel[$planet['star_id']]['metal']) { $metal_to_mine = $metal_fuel[$planet['star_id']]['metal']; } if ($metal_to_mine < 1) { //no negative by accident. $metal_to_mine = 0; } } $metal_fuel[$planet['star_id']]['fuel'] -= $fuel_to_mine; $metal_fuel[$planet['star_id']]['metal'] -= $metal_to_mine; //update the planet dbn("update {$db_name}_planets set fuel = fuel + '{$fuel_to_mine}', metal = metal + '{$metal_to_mine}' where planet_id = '{$planet['planet_id']}'"); $planet_count++; } //end planetary mining loop. //loop through all mined star systems and update them with new values foreach ($metal_fuel as $id => $arr) { dbn("update {$db_name}_stars set metal = '{$arr['metal']}', fuel='{$arr['fuel']}' where star_id = '{$id}'"); } //ensure no negative amounts of metal/fuel in star systems. dbn("update {$db_name}_stars set metal = 0 where metal < 0"); dbn("update {$db_name}_stars set fuel = 0 where fuel < 0"); $final_str .= sprintf($st[1860], $planet_count); $final_str .= print_time() . $st[1861] . count($metal_fuel); }