function processResults(&$players, &$port, $fleet, $weapons)
{
    if (DEBUG) {
        print "Processing Results<br>";
    }
    global $db, $player;
    $results = array('', '', 0, 0, array());
    //port is updated in downgrade function, all we need to do is format text
    $portDisplay = "<h2>Port Results</h2>";
    $totalPortDamage = 0;
    foreach ($port[PORT_RESULTS] as $resultArray) {
        $totalPortDamage += $resultArray[SHIELD_DMG_DONE] + $resultArray[DRONE_DMG_DONE] + $resultArray[ARMOR_DMG_DONE];
        $portDisplay .= "<span style=\"color:yellow;font-variant:small-caps\">Port " . $player->sector_id . "</span>";
        if ($resultArray[DRONES_FIRED]) {
            $portDisplay .= " launches " . $resultArray[DRONES_FIRED] . " drones at ";
        } else {
            $portDisplay .= " fires a turret at ";
        }
        if ($resultArray[RESULT_OF_WEAPON] == ALREADY_DEAD) {
            $portDisplay .= "the debris that used to be ";
        }
        $portDisplay .= $players[$resultArray[TARGET]][PLAYER_NAME];
        if ($resultArray[RESULT_OF_WEAPON] == NORMAL_HIT || $resultArray[RESULT_OF_WEAPON] == FINAL_HIT) {
            $portDisplay .= " destroying ";
        } elseif ($resultArray[RESULT_OF_WEAPON] == WEAPON_MISS) {
            $portDisplay .= " and misses";
        } elseif ($resultArray[RESULT_OF_WEAPON] == ALREADY_DEAD) {
            $portDisplay .= "";
        } else {
            $portDisplay .= " and I have no idea what the hell happens!  Please save this screen and notify Azool.";
        }
        if ($resultArray[SHIELD_DMG_DONE]) {
            $portDisplay .= "<span class=\"cyan\">" . $resultArray[SHIELD_DMG_DONE] . "</span> shields";
        }
        if ($resultArray[DRONE_DMG_DONE]) {
            if ($resultArray[SHIELD_DMG_DONE]) {
                if ($resultArray[ARMOR_DMG_DONE]) {
                    $portDisplay .= ", ";
                } else {
                    $portDisplay .= " and ";
                }
            }
            $portDisplay .= "<span class=\"yellow\">";
            $portDisplay .= floor($resultArray[DRONE_DMG_DONE] / 3);
            $portDisplay .= "</span> drones";
        }
        if ($resultArray[ARMOR_DMG_DONE]) {
            if ($resultArray[DRONE_DMG_DONE] || $resultArray[SHIELD_DMG_DONE]) {
                $portDisplay .= " and ";
            }
            $portDisplay .= "<span class=\"red\">" . $resultArray[ARMOR_DMG_DONE] . "</span> armor";
        }
        $portDisplay .= ".<br />";
        if ($resultArray[RESULT_OF_WEAPON] == FINAL_HIT) {
            $portDisplay .= "<span style=\"color:yellow;\">" . $players[$resultArray[TARGET]][PLAYER_NAME] . "</span>";
            $portDisplay .= " is <span style=\"color:red;\">DESTROYED.</span><br />";
        }
        $results[DMG_TO_PLAYER][$resultArray[TARGET]] += $resultArray[SHIELD_DMG_DONE] + $resultArray[DRONE_DMG_DONE] + $resultArray[ARMOR_DMG_DONE];
    }
    $portDisplay .= "<br /><span style=\"color:yellow;font-variant:small-caps\">Port " . $player->sector_id . "</span>";
    $portDisplay .= " does a total of <span class=\"red\">{$totalPortDamage}</span> damage.<br />";
    $results[PORT_DISPLAY] = $portDisplay;
    $results[TOTAL_PORT_DMG] = $totalPortDamage;
    $playerDisplay = "<h2>Attacker Results</h2>";
    $totalPlayerDamage = 0;
    foreach ($fleet as $accId) {
        $traderDisplay = "";
        $weapon = 0;
        $totalTraderDamage = 0;
        //make sure this element exists to prevent blank messages
        $results[DMG_TO_PLAYER][$accId] += 0;
        foreach ($players[$accId][RESULTS] as $resultArray) {
            $totalTraderDamage += $resultArray[SHIELD_DMG_DONE] + $resultArray[DRONE_DMG_DONE] + $resultArray[ARMOR_DMG_DONE] + floor($resultArray[DRONES_HIT_BEHIND_SHIELDS] / 60) * 60;
            $traderDisplay .= $players[$accId][PLAYER_NAME];
            if (!$players[$accId][WEAPONS][$weapon]) {
                if ($resultArray[DRONES_FIRED]) {
                    $traderDisplay .= " launches <span class=\"yellow\">" . $resultArray[DRONES_FIRED] . "</span> drones";
                } else {
                    $traderDisplay .= " fails to launch their drones";
                }
            } else {
                $traderDisplay .= " fires their ";
                $traderDisplay .= $weapons[$players[$accId][WEAPONS][$weapon]][WEAPON_NAME];
            }
            $traderDisplay .= " at ";
            if ($resultArray[RESULT_OF_WEAPON] == PORT_DEAD) {
                $traderDisplay .= " the remnants of ";
            }
            $traderDisplay .= "<span style=\"color:yellow;font-variant:small-caps\">Port " . $player->sector_id . "</span>";
            if ($resultArray[RESULT_OF_WEAPON] == ARMOR_ON_SHIELD) {
                $traderDisplay .= " which is deflected by its shields.";
            } else {
                if ($resultArray[RESULT_OF_WEAPON] == SHIELD_ON_ARMOR) {
                    $traderDisplay .= " which proves ineffective against its armor.";
                } else {
                    if ($resultArray[RESULT_OF_WEAPON] == SHIELD_ON_DRONES) {
                        $traderDisplay .= " which proves ineffective against its combat drones.";
                    } else {
                        if ($resultArray[RESULT_OF_WEAPON] == WEAPON_MISS && $players[$accId][WEAPONS][$weapon]) {
                            $traderDisplay .= " and misses every critical system.";
                        } else {
                            if ($resultArray[RESULT_OF_WEAPON] == PORT_DEAD) {
                                $traderDisplay .= ".";
                            } else {
                                $traderDisplay .= " destroying ";
                                if ($resultArray[SHIELD_DMG_DONE]) {
                                    $traderDisplay .= "<span class=\"cyan\">" . $resultArray[SHIELD_DMG_DONE] . "</span> shields";
                                }
                                if ($resultArray[DRONE_DMG_DONE] || $resultArray[DRONES_HIT_BEHIND_SHIELDS]) {
                                    if ($resultArray[SHIELD_DMG_DONE] && $resultArray[ARMOR_DMG_DONE]) {
                                        $traderDisplay .= ", ";
                                    } elseif ($resultArray[SHIELD_DMG_DONE]) {
                                        $traderDisplay .= " and ";
                                    }
                                    $traderDisplay .= "<span class=\"yellow\">";
                                    if ($resultArray[DRONE_DMG_DONE]) {
                                        $traderDisplay .= floor($resultArray[DRONE_DMG_DONE] / 3);
                                    } else {
                                        $traderDisplay .= floor($resultArray[DRONES_HIT_BEHIND_SHIELDS] / 60);
                                    }
                                    $traderDisplay .= "</span> drones";
                                }
                                if ($resultArray[ARMOR_DMG_DONE]) {
                                    if ($resultArray[SHIELD_DMG_DONE] || $resultArray[DRONE_DMG_DONE] || $resultArray[DRONES_HIT_BEHIND_SHIELDS]) {
                                        $traderDisplay .= " and ";
                                    }
                                    $traderDisplay .= "<span class=\"red\">" . $resultArray[ARMOR_DMG_DONE] . "</span> armor";
                                }
                                $traderDisplay .= ".";
                            }
                        }
                    }
                }
            }
            $traderDisplay .= "<br />";
            if ($resultArray[RESULT_OF_WEAPON] == FINAL_HIT) {
                $traderDisplay .= "<span style=\"color:yellow;font-variant:small-caps\">Port " . $player->sector_id . "'s</span> defenses are ";
                $traderDisplay .= "<span style=\"color:red;\">DESTROYED.</span><br />";
                $traderDisplay .= $players[$accId][PLAYER_NAME] . " claims <span class=\"yellow\">" . number_format($port[PORT_CREDITS]) . "</span> credits from the port.<br />";
                $players[$accId][CREDITS] += $port[PORT_CREDITS];
                $port[PORT_CREDITS] = 0;
                //get all players involved for HoF
                $allowed = TIME - 60 * 60 * 3;
                $db->query("SELECT * FROM player_attacks_port WHERE game_id = {$player->game_id} AND sector_id = {$player->sector_id} AND time > {$allowed}");
                $temp = array();
                while ($db->next_record()) {
                    $temp[$db->f("account_id")] = $db->f("level");
                }
                foreach ($temp as $tempAcc => $level) {
                    $db->query("UPDATE player_has_stats SET port_raids = port_raids + 1, port_raid_levels = port_raid_levels + {$level} " . "WHERE account_id = {$tempAcc} AND game_id = {$player->game_id} LIMIT 1");
                    $db->query("UPDATE account_has_stats SET port_raids = port_raids + 1, port_raid_levels = port_raid_levels + {$level} " . "WHERE account_id = {$tempAcc} LIMIT 1");
                }
                $db->query("DELETE FROM player_attacks_port WHERE sector_id = {$player->sector_id} AND game_id = {$player->game_id}");
                unset($temp);
                // News Entry
                $news = '<span class="yellow smallCaps">Port ' . $player->sector_id . '</span> has been successfully raided by ';
                if ($player->alliance_id) {
                    $news .= 'the members of <span class="yellow">' . $player->alliance_name . '</span>';
                } else {
                    $news .= '<span class="yellow">' . $player->player_name . '</span>';
                }
                $news = mysql_real_escape_string($news);
                $db->query("INSERT INTO news (game_id, time, news_message, type) VALUES ({$player->game_id}, " . TIME . ", '{$news}', 'regular')");
                // Trigger gets an alignment change and a bounty if port is taken
                $db->query("SELECT * FROM bounty WHERE game_id = {$player->game_id} AND account_id = {$player->account_id} " . "AND claimer_id = 0 AND type = 'HQ'");
                $amount = $player->experience * $port[PORT_LEVEL];
                if ($db->next_record() && $amount > 0) {
                    $bounty_id = $db->f("bounty_id");
                    $curr_amount = $db->f("amount");
                    $new_amount = $curr_amount + $amount;
                    $db->query("UPDATE bounty SET amount = {$new_amount}, time = " . TIME . " WHERE game_id = {$player->game_id} AND bounty_id = {$bounty_id}");
                } elseif ($amount > 0) {
                    $db->query("INSERT INTO bounty (account_id, game_id, type, amount, claimer_id, time) VALUES " . "({$player->account_id}, {$player->game_id}, 'HQ', {$amount}, 0, " . TIME . ")");
                }
                $player->get_relations();
                if ($port[PORT_RACE_ID] > 1) {
                    $new_relations = $player->relations[$port[PORT_RACE_ID]] - 45;
                    if ($new_relations < -500) {
                        $new_relations = -500;
                    }
                    $db->query("REPLACE INTO player_has_relation (account_id, game_id, race_id, relation) VALUES({$player->account_id}, {$player->game_id}, " . $port[PORT_RACE_ID] . ", {$new_relations})");
                }
                // also we change alignment
                if ($player->relations_global_rev[$port[PORT_RACE_ID]] < -299) {
                    $new_alignment = $player->alignment + $port[PORT_LEVEL] * 2;
                } else {
                    $new_alignment = $player->alignment - $port[PORT_LEVEL] * 2;
                }
                $db->query("UPDATE player SET alignment={$new_alignment} WHERE account_id={$player->account_id} AND game_id={$player->game_id} LIMIT 1");
            }
            $weapon++;
        }
        $totalPlayerDamage += $totalTraderDamage;
        $db->query("UPDATE account_has_stats SET port_damage = port_damage + {$totalTraderDamage} WHERE account_id = {$accId} LIMIT 1");
        $db->query("UPDATE player_has_stats SET port_damage = port_damage + {$totalTraderDamage} WHERE account_id = {$accId} AND game_id = {$player->game_id} LIMIT 1");
        $players[$accId][EXPERIENCE_GAINED] = round($totalTraderDamage * 0.05);
        $traderDisplay .= "<br />" . $players[$accId][PLAYER_NAME] . " does a total of <span class=\"red\">{$totalTraderDamage}</span> damage.<br />";
        //append this display to the overal display.
        $playerDisplay .= $traderDisplay . "<br />";
        $traderDisplay = "<span style=\"color:yellow;font-variant:small-caps\">Port " . $player->sector_id . "</span>'s defenses " . "do a total of <span class=\"red\">{$totalPortDamage}</span> damage. <span class=\"red\">" . $results[DMG_TO_PLAYER][$accId] . "</span> of which hit you.<br /><br />" . $traderDisplay . "You have gained <span class=\"blue\">" . round($totalTraderDamage * 0.05) . "</span> experience.";
        if ($accId != $player->account_id) {
            $db->query("REPLACE INTO sector_message (account_id, game_id, message) VALUES ({$accId}, {$player->game_id}, '" . addslashes($traderDisplay) . "')");
        }
    }
    $playerDisplay .= "This team does a total of <span class=\"red\">{$totalPlayerDamage}</span> damage.<br />";
    $results[PLAYER_DISPLAY] = $playerDisplay;
    $results[TOTAL_PLAYER_DMG] = $totalPlayerDamage;
    //we need to update the database for the players
    $temp = array();
    $ships = array();
    $hqs = array();
    foreach ($players as $accId => $playerArray) {
        if ($playerArray[SHIELDS] == 0 && $playerArray[ARMOR] == 0) {
            $temp[] = $accId;
            $ships[] = $players[$accId][SHIP_ID];
            $hqs[] = $players[$accId][RACE_ID];
        } else {
            $db->query('UPDATE ship_has_hardware SET amount=' . $players[$accId][SHIELDS] . ' WHERE hardware_type_id=1 AND account_id=' . $accId . ' AND game_id=' . $player->game_id . ' LIMIT 1');
            $db->query('UPDATE ship_has_hardware SET amount=' . $players[$accId][ARMOR] . ' WHERE hardware_type_id=2 AND account_id=' . $accId . ' AND game_id=' . $player->game_id . ' LIMIT 1');
            $db->query('UPDATE ship_has_hardware SET amount=' . $players[$accId][DRONES] . ' WHERE hardware_type_id=4 AND account_id=' . $accId . ' AND game_id=' . $player->game_id . ' LIMIT 1');
            $db->query("UPDATE player SET experience = experience + " . $players[$accId][EXPERIENCE_GAINED] . ", credits = " . $players[$accId][CREDITS] . " WHERE account_id = {$accId} AND game_id = {$player->game_id}");
        }
    }
    podPlayers($temp, $ships, $hqs, $port, $players);
    unset($temp);
    return $results;
}
function processResults(&$players, &$port, $fleet, $weapons)
{
    if (DEBUG) {
        $PHP_OUTPUT .= 'Processing Results<br>';
    }
    global $db, $player;
    $results = array('', '', 0, 0, array());
    //port is updated in downgrade function, all we need to do is format text
    $portDisplay = '<h2>Port Results</h2>';
    $totalPortDamage = 0;
    foreach ($port[PORT_RESULTS] as $resultArray) {
        $totalPortDamage += $resultArray[SHIELD_DMG_DONE] + $resultArray[DRONE_DMG_DONE] + $resultArray[ARMOUR_DMG_DONE];
        $portDisplay .= '<span style="color:yellow;font-variant:small-caps">Port ' . $player->getSectorID() . '</span>';
        if ($resultArray[DRONES_FIRED]) {
            $portDisplay .= ' launches ' . $resultArray[DRONES_FIRED] . ' drones at ';
        } else {
            $portDisplay .= ' fires a turret at ';
        }
        if ($resultArray[RESULT_OF_WEAPON] == ALREADY_DEAD) {
            $portDisplay .= 'the debris that used to be ';
        }
        $portDisplay .= $players[$resultArray[TARGET]][PLAYER_NAME];
        if ($resultArray[RESULT_OF_WEAPON] == NORMAL_HIT || $resultArray[RESULT_OF_WEAPON] == FINAL_HIT) {
            $portDisplay .= ' destroying ';
        } elseif ($resultArray[RESULT_OF_WEAPON] == WEAPON_MISS) {
            $portDisplay .= ' and misses';
        } elseif ($resultArray[RESULT_OF_WEAPON] == ALREADY_DEAD) {
            $portDisplay .= '';
        } else {
            $portDisplay .= ' and I have no idea what the hell happens!  Please save this screen and notify Azool.';
        }
        if ($resultArray[SHIELD_DMG_DONE]) {
            $portDisplay .= '<span class="cyan">' . $resultArray[SHIELD_DMG_DONE] . '</span> shields';
        }
        if ($resultArray[DRONE_DMG_DONE]) {
            if ($resultArray[SHIELD_DMG_DONE]) {
                if ($resultArray[ARMOUR_DMG_DONE]) {
                    $portDisplay .= ', ';
                } else {
                    $portDisplay .= ' and ';
                }
            }
            $portDisplay .= '<span class="yellow">';
            $portDisplay .= floor($resultArray[DRONE_DMG_DONE] / 3);
            $portDisplay .= '</span> drones';
        }
        if ($resultArray[ARMOUR_DMG_DONE]) {
            if ($resultArray[DRONE_DMG_DONE] || $resultArray[SHIELD_DMG_DONE]) {
                $portDisplay .= ' and ';
            }
            $portDisplay .= '<span class="red">' . $resultArray[ARMOUR_DMG_DONE] . '</span> armour';
        }
        $portDisplay .= '.<br />';
        if ($resultArray[RESULT_OF_WEAPON] == FINAL_HIT) {
            $portDisplay .= '<span style="color:yellow;">' . $players[$resultArray[TARGET]][PLAYER_NAME] . '</span>';
            $portDisplay .= ' is <span style="color:red;">DESTROYED.</span><br />';
        }
        $results[DMG_TO_PLAYER][$resultArray[TARGET]] += $resultArray[SHIELD_DMG_DONE] + $resultArray[DRONE_DMG_DONE] + $resultArray[ARMOUR_DMG_DONE];
    }
    $portDisplay .= '<br /><span style="color:yellow;font-variant:small-caps">Port ' . $player->getSectorID() . '</span>';
    $portDisplay .= ' does a total of <span class="red">' . $totalPortDamage . '</span> damage.<br />';
    $results[PORT_DISPLAY] = $portDisplay;
    $results[TOTAL_PORT_DMG] = $totalPortDamage;
    $playerDisplay = '<h2>Attacker Results</h2>';
    $totalPlayerDamage = 0;
    foreach ($fleet as $accId) {
        $traderDisplay = '';
        $weapon = 0;
        $totalTraderDamage = 0;
        //make sure this element exists to prevent blank messages
        $results[DMG_TO_PLAYER][$accId] += 0;
        foreach ($players[$accId][RESULTS] as $resultArray) {
            $totalTraderDamage += $resultArray[SHIELD_DMG_DONE] + $resultArray[DRONE_DMG_DONE] + $resultArray[ARMOUR_DMG_DONE] + floor($resultArray[DRONES_HIT_BEHIND_SHIELDS] / 60) * 60;
            $traderDisplay .= $players[$accId][PLAYER_NAME];
            if (!$players[$accId][WEAPONS][$weapon]) {
                if ($resultArray[DRONES_FIRED]) {
                    $traderDisplay .= ' launches <span class="yellow">' . $resultArray[DRONES_FIRED] . '</span> drones';
                } else {
                    $traderDisplay .= ' fails to launch their drones';
                }
            } else {
                $traderDisplay .= ' fires their ';
                $traderDisplay .= $weapons[$players[$accId][WEAPONS][$weapon]][WEAPON_NAME];
            }
            $traderDisplay .= ' at ';
            if ($resultArray[RESULT_OF_WEAPON] == PORT_DEAD) {
                $traderDisplay .= ' the remnants of ';
            }
            $traderDisplay .= '<span style="color:yellow;font-variant:small-caps">Port ' . $player->getSectorID() . '</span>';
            if ($resultArray[RESULT_OF_WEAPON] == ARMOUR_ON_SHIELD) {
                $traderDisplay .= ' which is deflected by its shields.';
            } else {
                if ($resultArray[RESULT_OF_WEAPON] == SHIELD_ON_ARMOUR) {
                    $traderDisplay .= ' which proves ineffective against its armour.';
                } else {
                    if ($resultArray[RESULT_OF_WEAPON] == SHIELD_ON_DRONES) {
                        $traderDisplay .= ' which proves ineffective against its combat drones.';
                    } else {
                        if ($resultArray[RESULT_OF_WEAPON] == WEAPON_MISS && $players[$accId][WEAPONS][$weapon]) {
                            $traderDisplay .= ' and misses every critical system.';
                        } else {
                            if ($resultArray[RESULT_OF_WEAPON] == PORT_DEAD) {
                                $traderDisplay .= '.';
                            } else {
                                $traderDisplay .= ' destroying ';
                                if ($resultArray[SHIELD_DMG_DONE]) {
                                    $traderDisplay .= '<span class="cyan">' . $resultArray[SHIELD_DMG_DONE] . '</span> shields';
                                }
                                if ($resultArray[DRONE_DMG_DONE] || $resultArray[DRONES_HIT_BEHIND_SHIELDS]) {
                                    if ($resultArray[SHIELD_DMG_DONE] && $resultArray[ARMOUR_DMG_DONE]) {
                                        $traderDisplay .= ', ';
                                    } elseif ($resultArray[SHIELD_DMG_DONE]) {
                                        $traderDisplay .= ' and ';
                                    }
                                    $traderDisplay .= '<span class="yellow">';
                                    if ($resultArray[DRONE_DMG_DONE]) {
                                        $traderDisplay .= floor($resultArray[DRONE_DMG_DONE] / 3);
                                    } else {
                                        $traderDisplay .= floor($resultArray[DRONES_HIT_BEHIND_SHIELDS] / 60);
                                    }
                                    $traderDisplay .= '</span> drones';
                                }
                                if ($resultArray[ARMOUR_DMG_DONE]) {
                                    if ($resultArray[SHIELD_DMG_DONE] || $resultArray[DRONE_DMG_DONE] || $resultArray[DRONES_HIT_BEHIND_SHIELDS]) {
                                        $traderDisplay .= ' and ';
                                    }
                                    $traderDisplay .= '<span class="red">' . $resultArray[ARMOUR_DMG_DONE] . '</span> armour';
                                }
                                $traderDisplay .= '.';
                            }
                        }
                    }
                }
            }
            $traderDisplay .= '<br />';
            if ($resultArray[RESULT_OF_WEAPON] == FINAL_HIT) {
                $traderDisplay .= '<span style="color:yellow;font-variant:small-caps">Port ' . $player->getSectorID() . '\'s</span> defenses are ';
                $traderDisplay .= '<span style="color:red;">DESTROYED.</span><br />';
                $traderDisplay .= $players[$accId][PLAYER_NAME] . ' claims <span class="yellow">' . number_format($port[PORT_CREDITS]) . '</span> credits from the port.<br />';
                $players[$accId][CREDITS] += $port[PORT_CREDITS];
                $port[PORT_CREDITS] = 0;
                //get all players involved for HoF
                $allowed = TIME - 60 * 60 * 3;
                $db->query('SELECT * FROM player_attacks_port WHERE game_id = ' . $player->getGameID() . ' AND sector_id = ' . $player->getSectorID() . ' AND time > ' . $allowed);
                $temp = array();
                while ($db->next_record()) {
                    $currPlayer =& SmrPlayer::getPlayer($db->f('account_id'), SmrSession::$game_id, true);
                    $currPlayer->increaseHOF($db->getField('level'), array('Combat', 'Port', 'Levels Raided'));
                    $currPlayer->increaseHOF(1, array('Combat', 'Port', 'Total Raided'));
                    $currPlayer->update();
                }
                $db->query('DELETE FROM player_attacks_port WHERE sector_id = ' . $player->getSectorID() . ' AND game_id = ' . $player->getGameID());
                // News Entry
                $news = '<span class="yellow smallCaps">Port ' . $player->getSectorID() . '</span> has been successfully raided by ';
                if ($player->getAllianceID()) {
                    $news .= 'the members of <span class="yellow">' . $player->getAllianceName() . '</span>';
                } else {
                    $news .= '<span class="yellow">' . $player->getPlayerName() . '</span>';
                }
                $news = mysql_real_escape_string($news);
                $db->query('INSERT INTO news (game_id, time, news_message, type,killer_id,killer_alliance,dead_id) VALUES (' . $player->getGameID() . ', ' . TIME . ', ' . $db->escapeString($news) . ', \'regular\',' . $player->getAccountID() . ',' . $player->getAllianceID() . ',' . ACCOUNT_ID_PORT . ')');
                // Trigger gets an alignment change and a bounty if port is taken
                $db->query('SELECT * FROM bounty WHERE game_id = ' . $player->getGameID() . ' AND account_id = ' . $player->getAccountID() . ' ' . 'AND claimer_id = 0 AND type = \'HQ\'');
                $amount = $player->getExperience() * $port[PORT_LEVEL];
                if ($db->next_record() && $amount > 0) {
                    $bounty_id = $db->f('bounty_id');
                    $curr_amount = $db->f('amount');
                    $new_amount = $curr_amount + $amount;
                    $db->query('UPDATE bounty SET amount = ' . $new_amount . ', time = ' . TIME . ' WHERE game_id = ' . $player->getGameID() . ' AND bounty_id = ' . $bounty_id);
                } elseif ($amount > 0) {
                    $db->query('INSERT INTO bounty (account_id, game_id, type, amount, claimer_id, time) VALUES ' . '(' . $player->getAccountID() . ', ' . $player->getGameID() . ', \'HQ\', ' . $amount . ', 0, ' . TIME . ')');
                }
                if ($port[PORT_RACE_ID] > 1) {
                    $new_relations = $player->getRelation($port[PORT_RACE_ID]) - 45;
                    if ($new_relations < -500) {
                        $new_relations = -500;
                    }
                    $db->query('REPLACE INTO player_has_relation (account_id, game_id, race_id, relation) VALUES(' . $player->getAccountID() . ', ' . $player->getGameID() . ', ' . $port[PORT_RACE_ID] . ', ' . $new_relations . ')');
                }
                // also we change alignment
                if ($player->relations_global_rev[$port[PORT_RACE_ID]] < -299) {
                    $new_alignment = $player->getAlignment() + $port[PORT_LEVEL] * 2;
                } else {
                    $new_alignment = $player->getAlignment() - $port[PORT_LEVEL] * 2;
                }
                $db->query('UPDATE player SET alignment=' . $new_alignment . ' WHERE account_id=' . $player->getAccountID() . ' AND game_id=' . $player->getGameID() . ' LIMIT 1');
            }
            $weapon++;
        }
        $totalPlayerDamage += $totalTraderDamage;
        $currPlayer =& SmrPlayer::getPlayer($accId, SmrSession::$game_id, true);
        $currPlayer->increaseHOF($totalTraderDamage, array('Combat', 'Port', 'Damage Done'));
        $currPlayer->update();
        $players[$accId][EXPERIENCE_GAINED] = round($totalTraderDamage * 0.05);
        $traderDisplay .= '<br />' . $players[$accId][PLAYER_NAME] . ' does a total of <span class="red">' . $totalTraderDamage . '</span> damage.<br />';
        //append this display to the overal display.
        $playerDisplay .= $traderDisplay . '<br />';
        $traderDisplay = '<span style="color:yellow;font-variant:small-caps">Port ' . $player->getSectorID() . '</span>\'s defenses ' . 'do a total of <span class="red">' . $totalPortDamage . '</span> damage. <span class="red">' . $results[DMG_TO_PLAYER][$accId] . '</span> of which hit you.<br /><br />' . $traderDisplay . 'You have gained <span class="blue">' . round($totalTraderDamage * 0.05) . '</span> experience.';
        if ($accId != $player->getAccountID()) {
            $db->query('REPLACE INTO sector_message (account_id, game_id, message) VALUES (' . $accId . ', ' . $player->getGameID() . ', ' . $db->escape_string($traderDisplay) . ')');
        }
    }
    $playerDisplay .= 'This team does a total of <span class="red">' . $totalPlayerDamage . '</span> damage.<br />';
    $results[PLAYER_DISPLAY] = $playerDisplay;
    $results[TOTAL_PLAYER_DMG] = $totalPlayerDamage;
    //we need to update the database for the players
    $temp = array();
    $ships = array();
    $hqs = array();
    foreach ($players as $accId => $playerArray) {
        if ($playerArray[SHIELDS] == 0 && $playerArray[ARMOUR] == 0) {
            $temp[] = $accId;
            $ships[] = $players[$accId][SHIP_ID];
            $hqs[] = $players[$accId][RACE_ID];
        } else {
            $db->query('UPDATE ship_has_hardware SET amount=' . $players[$accId][SHIELDS] . ' WHERE hardware_type_id=1 AND account_id=' . $accId . ' AND game_id=' . $player->getGameID() . ' LIMIT 1');
            $db->query('UPDATE ship_has_hardware SET amount=' . $players[$accId][ARMOUR] . ' WHERE hardware_type_id=2 AND account_id=' . $accId . ' AND game_id=' . $player->getGameID() . ' LIMIT 1');
            $db->query('UPDATE ship_has_hardware SET amount=' . $players[$accId][DRONES] . ' WHERE hardware_type_id=4 AND account_id=' . $accId . ' AND game_id=' . $player->getGameID() . ' LIMIT 1');
            $db->query('UPDATE player SET experience = experience + ' . $players[$accId][EXPERIENCE_GAINED] . ', credits = ' . $players[$accId][CREDITS] . ' WHERE account_id = ' . $accId . ' AND game_id = ' . $player->getGameID());
        }
    }
    podPlayers($temp, $ships, $hqs, $port, $players);
    unset($temp);
    return $results;
}
function processResults($players, $planet, $fleet, $weapons)
{
    if (DEBUG) {
        print "Processing Results<br>";
    }
    global $db, $player;
    $results = array('', '', 0, 0, array());
    //planet is updated in downgrade function, all we need to do is format text
    $planetDisplay = "<h2>Planet Results</h2>";
    $totalPlanetDamage = 0;
    foreach ($planet[PLANET_RESULTS] as $resultArray) {
        $totalPlanetDamage += $resultArray[SHIELD_DMG_DONE] + $resultArray[DRONE_DMG_DONE] + $resultArray[ARMOR_DMG_DONE];
        $planetDisplay .= "<span style=\"color:yellow;font-variant:small-caps\">" . $planet[PLANET_NAME] . "</span>";
        if ($resultArray[DRONES_FIRED]) {
            $planetDisplay .= " launches " . $resultArray[DRONES_FIRED] . " drones at ";
        } else {
            $planetDisplay .= " fires a turret at ";
        }
        if ($resultArray[RESULT_OF_WEAPON] == ALREADY_DEAD) {
            $planetDisplay .= "the debris that used to be ";
        }
        $planetDisplay .= $players[$resultArray[TARGET]][PLAYER_NAME];
        if ($resultArray[RESULT_OF_WEAPON] == NORMAL_HIT || $resultArray[RESULT_OF_WEAPON] == FINAL_HIT) {
            $planetDisplay .= " destroying ";
        } elseif ($resultArray[RESULT_OF_WEAPON] == WEAPON_MISS) {
            $planetDisplay .= " and misses";
        } elseif ($resultArray[RESULT_OF_WEAPON] == ALREADY_DEAD) {
            $planetDisplay .= "";
        } else {
            $planetDisplay .= " and I have no idea what the hell happens!  Please save this screen and notify Azool.";
        }
        if ($resultArray[SHIELD_DMG_DONE]) {
            $planetDisplay .= "<span class=\"cyan\">" . $resultArray[SHIELD_DMG_DONE] . "</span> shields";
        }
        if ($resultArray[DRONE_DMG_DONE]) {
            if ($resultArray[SHIELD_DMG_DONE]) {
                if ($resultArray[ARMOR_DMG_DONE]) {
                    $planetDisplay .= ", ";
                } else {
                    $planetDisplay .= " and ";
                }
            }
            $planetDisplay .= "<span class=\"yellow\">";
            $planetDisplay .= floor($resultArray[DRONE_DMG_DONE] / 3);
            $planetDisplay .= "</span> drones";
        }
        if ($resultArray[ARMOR_DMG_DONE]) {
            if ($resultArray[DRONE_DMG_DONE] || $resultArray[SHIELD_DMG_DONE]) {
                $planetDisplay .= " and ";
            }
            $planetDisplay .= "<span class=\"red\">" . $resultArray[ARMOR_DMG_DONE] . "</span> armor";
        }
        $planetDisplay .= ".<br />";
        if ($resultArray[RESULT_OF_WEAPON] == FINAL_HIT) {
            $planetDisplay .= "<span style=\"color:yellow;\">" . $players[$resultArray[TARGET]][PLAYER_NAME] . "</span>";
            $planetDisplay .= " is <span style=\"color:red;\">DESTROYED.</span><br />";
        }
        $results[DMG_TO_PLAYER][$resultArray[TARGET]] += $resultArray[SHIELD_DMG_DONE] + $resultArray[DRONE_DMG_DONE] + $resultArray[ARMOR_DMG_DONE];
    }
    $planetDisplay .= "<br /><span style=\"color:yellow;font-variant:small-caps\">" . $planet[PLANET_NAME] . "</span>";
    $planetDisplay .= " does a total of <span class=\"red\">{$totalPlanetDamage}</span> damage.<br />";
    $results[PLANET_DISPLAY] = $planetDisplay;
    $results[TOTAL_PLANET_DMG] = $totalPlanetDamage;
    $playerDisplay = "<h2>Attacker Results</h2>";
    $totalPlayerDamage = 0;
    foreach ($fleet as $accId) {
        $traderDisplay = "";
        $weapon = 0;
        $totalTraderDamage = 0;
        //make sure this element exists to prevent blank messages
        $results[DMG_TO_PLAYER][$accId] += 0;
        foreach ($players[$accId][RESULTS] as $resultArray) {
            $totalTraderDamage += $resultArray[SHIELD_DMG_DONE] + $resultArray[DRONE_DMG_DONE] + $resultArray[ARMOR_DMG_DONE] + 3 * floor($resultArray[DRONES_HIT_BEHIND_SHIELDS] / 12);
            $traderDisplay .= $players[$accId][PLAYER_NAME];
            if (!$players[$accId][WEAPONS][$weapon]) {
                if ($resultArray[DRONES_FIRED]) {
                    $traderDisplay .= " launches <span class=\"yellow\">" . $resultArray[DRONES_FIRED] . "</span> drones";
                } else {
                    $traderDisplay .= " fails to launch their drones";
                }
            } else {
                $traderDisplay .= " fires their ";
                $traderDisplay .= $weapons[$players[$accId][WEAPONS][$weapon]][WEAPON_NAME];
            }
            $traderDisplay .= " at ";
            if ($resultArray[RESULT_OF_WEAPON] == PLANET_DEAD) {
                $traderDisplay .= " the surface of ";
            }
            $traderDisplay .= "<span style=\"color:yellow;font-variant:small-caps\">" . $planet[PLANET_NAME] . "</span>";
            if ($resultArray[RESULT_OF_WEAPON] == ARMOR_ON_SHIELD) {
                $traderDisplay .= " which is deflected by its shields.";
            } else {
                if ($resultArray[RESULT_OF_WEAPON] == SHIELD_ON_DRONES) {
                    $traderDisplay .= " which proves ineffective against its combat drones.";
                } else {
                    if ($resultArray[RESULT_OF_WEAPON] == WEAPON_MISS && $players[$accId][WEAPONS][$weapon]) {
                        $traderDisplay .= " and misses every critical system.";
                    } else {
                        if ($resultArray[RESULT_OF_WEAPON] == PLANET_DEAD) {
                            $traderDisplay .= ".";
                        } else {
                            $traderDisplay .= " destroying ";
                            if ($resultArray[SHIELD_DMG_DONE]) {
                                $traderDisplay .= "<span class=\"cyan\">" . $resultArray[SHIELD_DMG_DONE] . "</span> shields";
                            }
                            if ($resultArray[DRONE_DMG_DONE] || $resultArray[DRONES_HIT_BEHIND_SHIELDS]) {
                                if ($resultArray[SHIELD_DMG_DONE]) {
                                    $traderDisplay .= " and ";
                                }
                                $traderDisplay .= "<span class=\"yellow\">";
                                if ($resultArray[DRONE_DMG_DONE]) {
                                    $traderDisplay .= floor($resultArray[DRONE_DMG_DONE] / 3);
                                } else {
                                    $traderDisplay .= floor($resultArray[DRONES_HIT_BEHIND_SHIELDS] / 12);
                                }
                                $traderDisplay .= "</span> drones";
                            }
                            $traderDisplay .= ".";
                        }
                    }
                }
            }
            $traderDisplay .= "<br />";
            if ($resultArray[RESULT_OF_WEAPON] == PLANET_DEAD) {
                $traderDisplay .= "<span style=\"color:yellow;font-variant:small-caps\">" . $planet[PLANET_NAME] . "'s</span> defenses are ";
                $traderDisplay .= "<span style=\"color:red;\">DESTROYED.</span><br />";
                //get all players involved for HoF
                $allowed = TIME - 60 * 60 * 3;
                $db->query("SELECT * FROM player_attacks_planet WHERE game_id = {$player->game_id} AND sector_id = {$player->sector_id} AND time > {$allowed}");
                $temp = array();
                while ($db->next_record()) {
                    $temp[$db->f("account_id")] = $db->f("level");
                }
                foreach ($temp as $tempAcc => $level) {
                    $db->query("UPDATE player_has_stats SET planet_busts = planet_busts + 1, planet_bust_levels = planet_bust_levels + {$level} " . "WHERE account_id = {$tempAcc} AND game_id = {$player->game_id}");
                    $db->query("UPDATE account_has_stats SET planet_busts = planet_busts + 1, planet_bust_levels = planet_bust_levels + {$level} " . "WHERE account_id = {$tempAcc}");
                }
                $db->query("DELETE FROM player_attacks_planet WHERE sector_id = {$player->sector_id} AND game_id = {$player->game_id}");
                unset($temp);
                $db->query("UPDATE planet SET owner_id = 0, password = '' WHERE sector_id = {$player->sector_id} AND game_id = {$player->game_id}");
            }
            $weapon++;
        }
        $totalPlayerDamage += $totalTraderDamage;
        $db->query("UPDATE account_has_stats SET planet_damage = planet_damage + {$totalTraderDamage} WHERE account_id = {$accId}");
        $db->query("UPDATE player_has_stats SET planet_damage = planet_damage + {$totalTraderDamage} WHERE account_id = {$accId} AND game_id = {$player->game_id}");
        $players[$accId][EXPERIENCE_GAINED] = round($totalTraderDamage * 0.25);
        $traderDisplay .= "<br />" . $players[$accId][PLAYER_NAME] . " does a total of <span class=\"red\">{$totalTraderDamage}</span> damage.<br />";
        //append this display to the overal display.
        $playerDisplay .= $traderDisplay . "<br />";
        $traderDisplay = "<span style=\"color:yellow;font-variant:small-caps\">" . $planet[PLANET_NAME] . "</span>'s defenses " . "do a total of <span class=\"red\">{$totalPlanetDamage}</span> damage. <span class=\"red\">" . $results[DMG_TO_PLAYER][$accId] . "</span> of which hit you.<br /><br />" . $traderDisplay . "You have gained <span class=\"blue\">" . round($totalTraderDamage * 0.25) . "</span> experience.";
        if ($accId != $player->account_id) {
            $db->query("REPLACE INTO sector_message (account_id, game_id, message) VALUES ({$accId}, {$player->game_id}, '" . addslashes($traderDisplay) . "')");
        }
    }
    $playerDisplay .= "This team does a total of <span class=\"red\">{$totalPlayerDamage}</span> damage.<br />";
    $results[PLAYER_DISPLAY] = $playerDisplay;
    $results[TOTAL_PLAYER_DMG] = $totalPlayerDamage;
    //we need to update the database for the players
    $temp = array();
    $ships = array();
    $hqs = array();
    foreach ($players as $accId => $playerArray) {
        if ($playerArray[SHIELDS] == 0 && $playerArray[ARMOR] == 0) {
            $temp[] = $accId;
            $ships[] = $players[$accId][SHIP_ID];
            $hqs[] = $players[$accId][RACE_ID];
        } else {
            $db->query('UPDATE ship_has_hardware SET amount=' . $players[$accId][SHIELDS] . ' WHERE hardware_type_id=1 AND account_id=' . $accId . ' AND game_id=' . $player->game_id . ' LIMIT 1');
            $db->query('UPDATE ship_has_hardware SET amount=' . $players[$accId][ARMOR] . ' WHERE hardware_type_id=2 AND account_id=' . $accId . ' AND game_id=' . $player->game_id . ' LIMIT 1');
            $db->query('UPDATE ship_has_hardware SET amount=' . $players[$accId][DRONES] . ' WHERE hardware_type_id=4 AND account_id=' . $accId . ' AND game_id=' . $player->game_id . ' LIMIT 1');
            $db->query("UPDATE player SET experience = experience + " . $players[$accId][EXPERIENCE_GAINED] . " WHERE account_id = {$accId} AND game_id = {$player->game_id}");
        }
    }
    podPlayers($temp, $ships, $hqs, $planet, $players);
    unset($temp);
    return $results;
}
function processResults($players, $planet, $fleet, $weapons)
{
    if (DEBUG) {
        $PHP_OUTPUT .= 'Processing Results<br>';
    }
    global $db, $player;
    $results = array('', '', 0, 0, array());
    //planet is updated in downgrade function, all we need to do is format text
    $planetDisplay = '<h2>Planet Results</h2>';
    $totalPlanetDamage = 0;
    foreach ($planet[PLANET_RESULTS] as $resultArray) {
        $totalPlanetDamage += $resultArray[SHIELD_DMG_DONE] + $resultArray[DRONE_DMG_DONE] + $resultArray[ARMOUR_DMG_DONE];
        $planetDisplay .= '<span style="color:yellow;font-variant:small-caps">' . $planet[PLANET_NAME] . '</span>';
        if ($resultArray[DRONES_FIRED]) {
            $planetDisplay .= ' launches ' . $resultArray[DRONES_FIRED] . ' drones at ';
        } else {
            $planetDisplay .= ' fires a turret at ';
        }
        if ($resultArray[RESULT_OF_WEAPON] == ALREADY_DEAD) {
            $planetDisplay .= 'the debris that used to be ';
        }
        $planetDisplay .= $players[$resultArray[TARGET]][PLAYER_NAME];
        if ($resultArray[RESULT_OF_WEAPON] == NORMAL_HIT || $resultArray[RESULT_OF_WEAPON] == FINAL_HIT) {
            $planetDisplay .= ' destroying ';
        } elseif ($resultArray[RESULT_OF_WEAPON] == WEAPON_MISS) {
            $planetDisplay .= ' and misses';
        } elseif ($resultArray[RESULT_OF_WEAPON] == ALREADY_DEAD) {
            $planetDisplay .= '';
        } else {
            $planetDisplay .= ' and I have no idea what the hell happens!  Please save this screen and notify Azool.';
        }
        if ($resultArray[SHIELD_DMG_DONE]) {
            $planetDisplay .= '<span class="cyan">' . $resultArray[SHIELD_DMG_DONE] . '</span> shields';
        }
        if ($resultArray[DRONE_DMG_DONE]) {
            if ($resultArray[SHIELD_DMG_DONE]) {
                if ($resultArray[ARMOUR_DMG_DONE]) {
                    $planetDisplay .= ', ';
                } else {
                    $planetDisplay .= ' and ';
                }
            }
            $planetDisplay .= '<span class="yellow">';
            $planetDisplay .= floor($resultArray[DRONE_DMG_DONE] / 3);
            $planetDisplay .= '</span> drones';
        }
        if ($resultArray[ARMOUR_DMG_DONE]) {
            if ($resultArray[DRONE_DMG_DONE] || $resultArray[SHIELD_DMG_DONE]) {
                $planetDisplay .= ' and ';
            }
            $planetDisplay .= '<span class="red">' . $resultArray[ARMOUR_DMG_DONE] . '</span> armour';
        }
        $planetDisplay .= '.<br />';
        if ($resultArray[RESULT_OF_WEAPON] == FINAL_HIT) {
            $planetDisplay .= '<span style="color:yellow;">' . $players[$resultArray[TARGET]][PLAYER_NAME] . '</span>';
            $planetDisplay .= ' is <span style="color:red;">DESTROYED.</span><br />';
        }
        $results[DMG_TO_PLAYER][$resultArray[TARGET]] += $resultArray[SHIELD_DMG_DONE] + $resultArray[DRONE_DMG_DONE] + $resultArray[ARMOUR_DMG_DONE];
    }
    $planetDisplay .= '<br /><span style="color:yellow;font-variant:small-caps">' . $planet[PLANET_NAME] . '</span>';
    $planetDisplay .= ' does a total of <span class="red">$totalPlanetDamage</span> damage.<br />';
    $results[PLANET_DISPLAY] = $planetDisplay;
    $results[TOTAL_PLANET_DMG] = $totalPlanetDamage;
    $playerDisplay = '<h2>Attacker Results</h2>';
    $totalPlayerDamage = 0;
    foreach ($fleet as $accId) {
        $traderDisplay = '';
        $weapon = 0;
        $totalTraderDamage = 0;
        //make sure this element exists to prevent blank messages
        $results[DMG_TO_PLAYER][$accId] += 0;
        foreach ($players[$accId][RESULTS] as $resultArray) {
            $totalTraderDamage += $resultArray[SHIELD_DMG_DONE] + $resultArray[DRONE_DMG_DONE] + $resultArray[ARMOUR_DMG_DONE] + 3 * floor($resultArray[DRONES_HIT_BEHIND_SHIELDS] / 12);
            $traderDisplay .= $players[$accId][PLAYER_NAME];
            if (!$players[$accId][WEAPONS][$weapon]) {
                if ($resultArray[DRONES_FIRED]) {
                    $traderDisplay .= ' launches <span class="yellow">' . $resultArray[DRONES_FIRED] . '</span> drones';
                } else {
                    $traderDisplay .= ' fails to launch their drones';
                }
            } else {
                $traderDisplay .= ' fires their ';
                $traderDisplay .= $weapons[$players[$accId][WEAPONS][$weapon]][WEAPON_NAME];
            }
            $traderDisplay .= ' at ';
            if ($resultArray[RESULT_OF_WEAPON] == PLANET_DEAD) {
                $traderDisplay .= ' the surface of ';
            }
            $traderDisplay .= '<span style="color:yellow;font-variant:small-caps">' . $planet[PLANET_NAME] . '</span>';
            if ($resultArray[RESULT_OF_WEAPON] == ARMOUR_ON_SHIELD) {
                $traderDisplay .= ' which is deflected by its shields.';
            } else {
                if ($resultArray[RESULT_OF_WEAPON] == SHIELD_ON_DRONES) {
                    $traderDisplay .= ' which proves ineffective against its combat drones.';
                } else {
                    if ($resultArray[RESULT_OF_WEAPON] == WEAPON_MISS && $players[$accId][WEAPONS][$weapon]) {
                        $traderDisplay .= ' and misses every critical system.';
                    } else {
                        if ($resultArray[RESULT_OF_WEAPON] == PLANET_DEAD) {
                            $traderDisplay .= '.';
                        } else {
                            $traderDisplay .= ' destroying ';
                            if ($resultArray[SHIELD_DMG_DONE]) {
                                $traderDisplay .= '<span class="cyan">' . $resultArray[SHIELD_DMG_DONE] . '</span> shields';
                            }
                            if ($resultArray[DRONE_DMG_DONE] || $resultArray[DRONES_HIT_BEHIND_SHIELDS]) {
                                if ($resultArray[SHIELD_DMG_DONE]) {
                                    $traderDisplay .= ' and ';
                                }
                                $traderDisplay .= '<span class="yellow">';
                                if ($resultArray[DRONE_DMG_DONE]) {
                                    $traderDisplay .= floor($resultArray[DRONE_DMG_DONE] / 3);
                                } else {
                                    $traderDisplay .= floor($resultArray[DRONES_HIT_BEHIND_SHIELDS] / 12);
                                }
                                $traderDisplay .= '</span> drones';
                            }
                            $traderDisplay .= '.';
                        }
                    }
                }
            }
            $traderDisplay .= '<br />';
            if ($resultArray[RESULT_OF_WEAPON] == PLANET_DEAD) {
                $traderDisplay .= '<span style="color:yellow;font-variant:small-caps">' . $planet[PLANET_NAME] . '\'s</span> defenses are ';
                $traderDisplay .= '<span style="color:red;">DESTROYED.</span><br />';
                //get all players involved for HoF
                $allowed = TIME - 60 * 60 * 3;
                $db->query('SELECT * FROM player_attacks_planet WHERE game_id = ' . $player->getGameID() . ' AND sector_id = ' . $player->getSectorID() . ' AND time > ' . $allowed);
                $temp = array();
                while ($db->next_record()) {
                    $currPlayer =& SmrPlayer::getPlayer($db->f('account_id'), SmrSession::$game_id, true);
                    $currPlayer->increaseHOF($db->f('level'), array('Combat', 'Planet', 'Levels'));
                    $currPlayer->increaseHOF(1, array('Combat', 'Planet', 'Completed'));
                    $currPlayer->update();
                }
                $db->query('DELETE FROM player_attacks_planet WHERE sector_id = ' . $player->getSectorID() . ' AND game_id = ' . $player->getGameID());
                $db->query('UPDATE planet SET owner_id = 0, password = \'\' WHERE sector_id = ' . $player->getSectorID() . ' AND game_id = ' . $player->getGameID());
            }
            $weapon++;
        }
        $totalPlayerDamage += $totalTraderDamage;
        $currPlayer =& SmrPlayer::getPlayer($accId, SmrSession::$game_id, true);
        $currPlayer->increaseHOF($totalTraderDamage, array('Combat', 'Planet', 'Damage Done'));
        $currPlayer->update();
        $players[$accId][EXPERIENCE_GAINED] = round($totalTraderDamage * 0.25);
        $traderDisplay .= '<br />' . $players[$accId][PLAYER_NAME] . ' does a total of <span class="red">' . $totalTraderDamage . '</span> damage.<br />';
        //append this display to the overal display.
        $playerDisplay .= $traderDisplay . '<br />';
        $traderDisplay = '<span style="color:yellow;font-variant:small-caps">' . $planet[PLANET_NAME] . '</span>\'s defenses ' . 'do a total of <span class="red">' . $totalPlanetDamage . '</span> damage. <span class="red">' . $results[DMG_TO_PLAYER][$accId] . '</span> of which hit you.<br /><br />' . $traderDisplay . 'You have gained <span class="blue">' . round($totalTraderDamage * 0.25) . '</span> experience.';
        if ($accId != $player->getAccountID()) {
            $db->query('REPLACE INTO sector_message (account_id, game_id, message) VALUES (' . $accId . ', ' . $player->getGameID() . ', ' . $db->escape_string($traderDisplay) . ')');
        }
    }
    $playerDisplay .= 'This team does a total of <span class="red">' . $totalPlayerDamage . '</span> damage.<br />';
    $results[PLAYER_DISPLAY] = $playerDisplay;
    $results[TOTAL_PLAYER_DMG] = $totalPlayerDamage;
    //we need to update the database for the players
    $temp = array();
    $ships = array();
    $hqs = array();
    foreach ($players as $accId => $playerArray) {
        if ($playerArray[SHIELDS] == 0 && $playerArray[ARMOUR] == 0) {
            $temp[] = $accId;
            $ships[] = $players[$accId][SHIP_ID];
            $hqs[] = $players[$accId][RACE_ID];
        } else {
            $db->query('UPDATE ship_has_hardware SET amount=' . $players[$accId][SHIELDS] . ' WHERE hardware_type_id=1 AND account_id=' . $accId . ' AND game_id=' . $player->getGameID() . ' LIMIT 1');
            $db->query('UPDATE ship_has_hardware SET amount=' . $players[$accId][ARMOUR] . ' WHERE hardware_type_id=2 AND account_id=' . $accId . ' AND game_id=' . $player->getGameID() . ' LIMIT 1');
            $db->query('UPDATE ship_has_hardware SET amount=' . $players[$accId][DRONES] . ' WHERE hardware_type_id=4 AND account_id=' . $accId . ' AND game_id=' . $player->getGameID() . ' LIMIT 1');
            $db->query('UPDATE player SET experience = experience + ' . $players[$accId][EXPERIENCE_GAINED] . ' WHERE account_id = ' . $accId . ' AND game_id = ' . $player->getGameID());
        }
    }
    podPlayers($temp, $ships, $hqs, $planet, $players);
    unset($temp);
    return $results;
}