function getFleet(&$players, &$weapons) { if (DEBUG) { print "Get Fleet<br>"; } global $db, $session, $player; $player_ids = array_keys($players); $fleet = array(); // Is there a fed beacon in the sector? $db->query('SELECT location_type_id FROM location WHERE location_type_id=201 AND sector_id=' . $player->sector_id . ' AND game_id=' . SmrSession::$game_id . ' LIMIT 1'); if ($db->next_record()) { $have_beacon = TRUE; $db->query('SELECT account_id FROM ship_has_cargo WHERE good_id IN (5,9,12) AND game_id=' . SmrSession::$game_id . ' AND account_id IN (' . implode(',', $player_ids) . ')'); while ($db->next_record()) { $illegal_goods[$db->f('account_id')] = TRUE; } } else { $have_beacon = FALSE; } foreach ($player_ids as $account_id) { // Remove players that are fed protected from the fighting if ($have_beacon && !isset($illegal_goods[$account_id]) && protected_rating($account_id, $players, $weapons)) { // Player and their target must not have dropped into fed protection if ($account_id == $player->account_id) { create_error("You are under federal protection"); } unset($players[$account_id]); } else { if ($account_id != $player->account_id) { // We add the player and target to the fleet after capping if ($players[$account_id][ALLIANCE_ID] == $player->alliance_id) { $fleet[] = $account_id; } else { $fleet[] = $account_id; } } } } // Cap fleet to the required size $fleet_size = count($fleet); if ($fleet_size > MAXIMUM_FLEET_SIZE - 1) { // We shuffle to stop the same people being capped all the time shuffle($fleet); $temp = array(); $count = 0; for ($j = 0; $j < $fleet_size; ++$j) { if ($count < MAXIMUM_FLEET_SIZE - 1) { $temp[] = $fleet[$j]; } else { unset($players[$fleet[$j]]); } ++$count; } $fleet = $temp; } // Add the inital combatants to their respective fleets $fleet[] = (int) SmrSession::$old_account_id; // Shuffle for random firing order shuffle($fleet); return $fleet; }
function build_fleets(&$players, &$weapons, $attackers, $defenders) { global $db, $session, $player, $var; $player_ids = array_keys($players); $fleets = array(); // Is there a fed beacon in the sector? $db->query('SELECT location_type_id FROM location WHERE location_type_id=201 AND sector_id=' . $player->sector_id . ' AND game_id=' . SmrSession::$game_id . ' LIMIT 1'); if ($db->next_record()) { $have_beacon = TRUE; $db->query('SELECT account_id FROM ship_has_cargo WHERE good_id IN (5,9,12) AND game_id=' . SmrSession::$game_id . ' AND account_id IN (' . implode(',', $player_ids) . ')'); while ($db->next_record()) { $illegal_goods[$db->f('account_id')] = TRUE; } } else { $have_beacon = FALSE; } foreach ($player_ids as $account_id) { // Remove players that are fed protected from the fighting if ($have_beacon && !isset($illegal_goods[$account_id]) && protected_rating($account_id, $players, $weapons)) { // Player and their target must not have dropped into fed protection if ($account_id == $player->account_id) { $container = array(); $container['url'] = 'skeleton.php'; $container['body'] = 'current_sector.php'; $container['msg'] = '<span class="red bold">ERROR:</span> You are under federal protection.'; forward($container); exit; } else { if ($account_id == $var['target']) { $container = array(); $container['url'] = 'skeleton.php'; $container['body'] = 'current_sector.php'; $container['msg'] = '<span class="red bold">ERROR:</span> Target is under federal protection.'; forward($container); exit; } } unset($players[$account_id]); } else { if ($account_id != $player->account_id && $account_id != $var['target']) { // We add the player and target to the fleets after capping if (in_array($players[$account_id][ALLIANCE_ID], $attackers)) { $fleets[0][] = $account_id; } else { $fleets[1][] = $account_id; } } } } // Cap fleets to the required size for ($i = 0; $i < 2; ++$i) { $fleet_size = count($fleets[$i]); if ($fleet_size > MAXIMUM_FLEET_SIZE - 1) { // We shuffle to stop the same people being capped all the time shuffle($fleets[$i]); $temp = array(); $count = 0; for ($j = 0; $j < $fleet_size; ++$j) { if ($count < MAXIMUM_FLEET_SIZE - 1) { $temp[] = $fleets[$i][$j]; } else { unset($players[$fleets[$i][$j]]); } ++$count; } $fleets[$i] = $temp; } } // Add the inital combatants to their respective fleets $fleets[0][] = (int) SmrSession::$old_account_id; $fleets[1][] = (int) $var['target']; // Shuffle for random firing order shuffle($fleets[0]); shuffle($fleets[1]); return $fleets; }