示例#1
0
/**
 * MissionCaseTransport.php
 *
 * @version 1
 * @copyright 2008 By Chlorel for XNova
 */
function MissionCaseTransport($FleetRow)
{
    global $lang;
    $from = doquery("SELECT * FROM {{table}} WHERE `id` = '" . $FleetRow['owner_userid'] . "' LIMIT 1 ;", 'planets', true);
    $to = doquery("SELECT * FROM {{table}} WHERE `id` = '" . $FleetRow['target_userid'] . "' LIMIT 1 ;", 'planets', true);
    RestoreRes($FleetRow, false);
    $Message = sprintf($lang['sys_tran_mess_owner'], $TargetPlanet['name'], "[" . $TargetPlanet['galaxy'] . ":" . $TargetPlanet['system'] . ":" . $TargetPlanet['planet'] . "]", $FleetRow['metal'], $lang['Metal'], $FleetRow['crystal'], $lang['Crystal'], $FleetRow['deuterium'], $lang['Deuterium']);
    SendSimpleMessage($StartPlanet['id_owner'], '', $FleetRow['arrival'], 5, $lang['sys_mess_tower'], $lang['sys_mess_transport'], $Message);
    if ($TargetPlanet['id_owner'] != $StartPlanet['id_owner']) {
        $Message = sprintf($lang['sys_tran_mess_user'], $StartPlanet['name'], "[" . $StartPlanet['galaxy'] . ":" . $StartPlanet['system'] . ":" . $StartPlanet['planet'] . "]", $TargetPlanet['name'], "[" . $TargetPlanet['galaxy'] . ":" . $TargetPlanet['system'] . ":" . $TargetPlanet['planet'] . "]", $FleetRow['metal'], $lang['Metal'], $FleetRow['crystal'], $lang['Crystal'], $FleetRow['deuterium'], $lang['Deuterium']);
        SendSimpleMessage($TargetPlanet['id_owner'], '', $FleetRow['arrival'], 5, $lang['sys_mess_tower'], $lang['sys_mess_transport'], $Message);
    }
}
示例#2
0
function ManageFleets($limit = 5)
{
    global $lang;
    getLang('fleet_management');
    //Lock the tables
    $tables = array('aks', 'cr', 'errors', 'messages', 'fleets', 'planets', 'users');
    foreach ($tables as $k => $v) {
        $tables[$k] = "``{{prefix}}" . $v . "`` WRITE";
    }
    doquery("LOCK TABLE " . implode(", ", $tables), "");
    //Get the fleets - ordered by their returning time
    $fleets = doquery("SELECT * FROM {{table}} WHERE (`arrival` + `hold_time`) < " . time() . " ORDER BY (`arrival` + `hold_time`) ASC LIMIT " . idstring($limit) . " ;", 'fleets');
    //If there are any fleets.
    if (mysql_num_rows($fleets) > 0) {
        include_once ROOT_PATH . 'includes/functions/MissionCaseStay.php';
        include_once ROOT_PATH . 'includes/functions/MissionCaseStayAlly.php';
        include_once ROOT_PATH . 'includes/functions/MissionCaseSpy.php';
        include_once ROOT_PATH . 'includes/functions/MissionCaseRecycling.php';
        include_once ROOT_PATH . 'includes/functions/MissionCaseDestroy.php';
        include_once ROOT_PATH . 'includes/functions/MissionCaseExpedition.php';
        include_once ROOT_PATH . 'includes/functions/MissionCaseColonisation.php';
        //Now loop through the fleets.
        while ($row = mysql_fetch_array($fleets)) {
            //Update the users menus if he is online:
            doquery("UPDATE {{table}} SET `menus_update` = '" . time() . "' WHERE `id` = '" . $row['owner_userid'] . "' LIMIT 1 ;", 'users', false);
            doquery("UPDATE {{table}} SET `menus_update` = '" . time() . "' WHERE `id` = '" . $row['target_userid'] . "' LIMIT 1 ;", 'users', false);
            //Now deal with the fleet
            if ($row["mission"] == 0 || $row["mission"] == 4) {
                //Fleet is returning home, just restore the fleet to the planet and delete it.
                DeleteFleet($row['fleet_id']);
                RestoreFleet($row);
                $StartPlanet = doquery("SELECT * FROM {{table}} WHERE `id` = '" . $row['owner_id'] . "' LIMIT 1 ;", 'planets', true);
                $TargetPlanet = doquery("SELECT * FROM {{table}} WHERE `id` = '" . $row['target_id'] . "' LIMIT 1 ;", 'planets', true);
                //Send the user a message
                $Message = sprintf($lang['fleet_return_m'], $StartPlanet['name'], "[" . $StartPlanet['galaxy'] . ":" . $StartPlanet['system'] . ":" . $StartPlanet['planet'] . "]", pretty_number($row['metal']), $lang['Metal'], pretty_number($row['crystal']), $lang['Crystal'], pretty_number($row['deuterium']), $lang['Deuterium']);
                PM($row['target_userid'], 0, $Message, $lang['fleet_return'], $lang['fleet_control'], 2);
            } else {
                switch ($row["mission"]) {
                    case 1:
                        if ($row["fleet_mess"] == 0) {
                            // Attack
                            doquery("UPDATE {{table}} SET `fleet_mess` = '3' WHERE `fleet_id` = '" . $row["fleet_id"] . "' LIMIT 1 ;", 'fleets', false);
                            require_once ROOT_PATH . 'includes/battle_engines/MissionCaseAttack_' . BATTLE_ENGINE . '.php';
                            include_once ROOT_PATH . 'includes/battle_engines/ManageCR.php';
                            $results = MissionCaseAttack($row);
                            $CurrentPlanet = doquery("SELECT * FROM {{table}} WHERE `id` = '" . $row['target_id'] . "' LIMIT 1 ;", 'planets', true);
                            ManageCR($results, $CurrentPlanet);
                        }
                        break;
                    case 2:
                        // ACS Attack
                        // Wait, this fleet will be dealt with when the attack fleet arrives.
                        // Note that the return fleet won't exist until after the attack.
                        break;
                    case 3:
                        // Transport
                        DeleteFleet($row['fleet_id']);
                        //Send the res
                        RestoreRes($row);
                        //Now send messages to the players
                        $StartPlanet = doquery("SELECT * FROM {{table}} WHERE `id` = '" . $row['owner_id'] . "' LIMIT 1 ;", 'planets', true);
                        $TargetPlanet = doquery("SELECT * FROM {{table}} WHERE `id` = '" . $row['target_id'] . "' LIMIT 1 ;", 'planets', true);
                        $Message = sprintf($lang['fleet_3_yours'], $TargetPlanet['name'], "[" . $TargetPlanet['galaxy'] . ":" . $TargetPlanet['system'] . ":" . $TargetPlanet['planet'] . "]", pretty_number($row['metal']), $lang['Metal'], pretty_number($row['crystal']), $lang['Crystal'], pretty_number($row['deuterium']), $lang['Deuterium']);
                        PM($StartPlanet['id_owner'], 0, $Message, $lang['sys_mess_transport'], $lang['fleet_control'], 2);
                        if ($TargetPlanet['id_owner'] != $StartPlanet['id_owner']) {
                            $Message = sprintf($lang['fleet_3_allied'], $StartPlanet['name'], "[" . $StartPlanet['galaxy'] . ":" . $StartPlanet['system'] . ":" . $StartPlanet['planet'] . "]", $TargetPlanet['name'], "[" . $TargetPlanet['galaxy'] . ":" . $TargetPlanet['system'] . ":" . $TargetPlanet['planet'] . "]", pretty_number($row['metal']), $lang['Metal'], pretty_number($row['crystal']), $lang['Crystal'], pretty_number($row['deuterium']), $lang['Deuterium']);
                            PM($TargetPlanet['id_owner'], 0, $Message, $lang['sys_mess_transport'], $lang['fleet_control'], 2);
                        }
                        break;
                    case 4:
                        // Deploy (note that this is imposible so is really only here to avoid confusion)
                        DeleteFleet($row['fleet_id']);
                        break;
                    case 5:
                        // ACS Defend
                        // Wait, this fleet will be dealt with when the attack fleet arrives.
                        // Note that the return fleet won't exist until after the attack.
                        //DeleteFleet($row['fleet_id']);
                        break;
                    case 6:
                        // Espionage
                        DeleteFleet($row['fleet_id']);
                        MissionCaseSpy($row);
                        break;
                    case 7:
                        // Colonise
                        DeleteFleet($row['fleet_id']);
                        MissionCaseColonisation($row);
                        break;
                    case 8:
                        // Recycle
                        DeleteFleet($row['fleet_id']);
                        MissionCaseRecycling($row);
                        break;
                    case 9:
                        // Moon Destroy
                        $CurrentPlanet = doquery("SELECT * FROM {{table}} WHERE `id` = '" . $row['target_id'] . "' LIMIT 1 ;", 'planets', true);
                        if ($row["fleet_mess"] == 0 && $CurrentPlanet['planet_type'] == 3) {
                            // Attack
                            doquery("UPDATE {{table}} SET `fleet_mess` = '3' WHERE `fleet_id` = '" . $row["fleet_id"] . "' LIMIT 1 ;", 'fleets', false);
                            require_once ROOT_PATH . 'includes/battle_engines/MissionCaseAttack_' . BATTLE_ENGINE . '.php';
                            include_once ROOT_PATH . 'includes/battle_engines/ManageCR.php';
                            $results = MissionCaseAttack($row);
                            ManageCR($results, $CurrentPlanet);
                            //And then destroy, if the fleet survived
                            if ($results['won'] == 'a') {
                                $nowfleet = doquery("SELECT * FROM {{table}} WHERE `partner_fleet` = '" . $row['fleet_id'] . "' LIMIT 1 ;", 'fleets', true);
                                MissionCaseDestruction($nowfleet, $CurrentPlanet);
                            }
                        }
                        DeleteFleet($row['fleet_id']);
                        break;
                    case 10:
                        // Missiles !!
                        DeleteFleet($row['fleet_id']);
                        MissileAttack($row);
                        break;
                    case 15:
                        // Expedition
                        DeleteFleet($row['fleet_id']);
                        MissionCaseExpedition($row);
                        break;
                    default:
                        DeleteFleet($row['fleet_id']);
                }
            }
        }
    }
    //Unlock tables
    doquery("UNLOCK TABLES", "");
}