Example #1
0
 function _action_main()
 {
     // #############################################################################
     // Data of the scouts or the target planet
     // (resembles get_fleet_details())
     $sql = 'SELECT COUNT(s.ship_id) AS n_ships,
                    MAX(st.ship_torso) AS highest_torso,
                    SUM(st.value_11) AS sum_sensors,
                    SUM(st.value_12) AS sum_cloak,
             AVG(st.value_9) AS scoutxp
             FROM (ship_fleets f)
             INNER JOIN ships s ON s.fleet_id = f.fleet_id
             INNER JOIN ship_templates st ON st.id = s.template_id
             WHERE f.fleet_id IN (' . $this->fleet_ids_str . ')';
     if (($spy_fleet = $this->db->queryrow($sql)) === false) {
         return $this->log(MV_M_DATABASE, 'Could not query main spy fleets data! SKIP');
     }
     if ($spy_fleet['highest_torso'] != SHIP_TYPE_SCOUT) {
         $this->deactivate(35);
         $this->report('Spy fleet has no-scout torso withflying');
         return MV_EXEC_ERROR;
     }
     $dest_planet = get_friendly_orbit_fleets($this->move['dest'], $this->dest['user_id'], $this->dest['user_alliance']);
     // #############################################################################
     // Spy()
     $spy_result = Spy($spy_fleet['sum_sensors'], $spy_fleet['sum_cloak'], $spy_fleet['n_ships'], $dest_planet['sum_sensors'], $this->dest['building_7'], $spy_fleet['scoutxp']);
     $log2_data = array();
     if ($spy_result[0]) {
         // unsuccessful
         $sql = 'DELETE FROM ship_fleets
                 WHERE fleet_id IN (' . $this->fleet_ids_str . ')';
         if (!$this->db->query($sql)) {
             return $this->log(MV_M_DATABASE, 'Could not delete fleets data! SKIP');
         }
         $sql = 'DELETE FROM ships
                 WHERE fleet_id IN (' . $this->fleet_ids_str . ')';
         if (!$this->db->query($sql)) {
             $this->log(MV_M_DATABASE, 'Could not delete ships data! CONTINUE');
             $this->report('Could not delete ships data due spy mission');
         }
         $log1_data = $log2_data = array(22, $this->move['user_id'], $this->move['start'], $this->start['planet_name'], $this->start['user_id'], $this->move['dest'], $this->dest['planet_name'], $this->dest['user_id'], $spy_fleet['n_ships']);
     } else {
         // Calculate gained experience
         $difficult_rate = $dest_planet['sum_sensors'] + ($this->dest['building_7'] + 1) * 200;
         $exp = (double) $difficult_rate / 266 + 5.0;
         $sql = 'UPDATE ships SET experience = experience+' . $exp . '
                 WHERE fleet_id IN (' . $this->fleet_ids_str . ')';
         if (!$this->db->query($sql)) {
             $this->log(MV_M_DATABASE, 'Could not update fleet EXP! CONTINUE');
         }
         // Scouts returns
         $sql = 'INSERT INTO scheduler_shipmovement (user_id, move_status,
                     move_exec_started, start, dest, total_distance,
                     remaining_distance, tick_speed, move_begin, move_finish, n_ships,
                     action_code, action_data)
                 VALUES (' . $this->move['user_id'] . ', 0, 0,
                     ' . $this->move['dest'] . ', ' . $this->move['start'] . ',
                     ' . $this->move['total_distance'] . ', ' . $this->move['total_distance'] . ',
                     ' . $this->move['tick_speed'] . ', ' . $this->CURRENT_TICK . ',
                     ' . ($this->CURRENT_TICK + ($this->move['move_finish'] - $this->move['move_begin'])) . ',
                     ' . $this->move['n_ships'] . ', 12, "' . serialize(22) . '")';
         if (!$this->db->query($sql)) {
             return $this->log(MV_M_DATABASE, 'Could not create new movement for return! SKIP');
         }
         $new_move_id = $this->db->insert_id();
         if (!$new_move_id) {
             return $this->log(MV_M_ERROR, 'Could not get new move id! SKIP');
         }
         $sql = 'UPDATE ship_fleets
                 SET move_id = ' . $new_move_id . '
                 WHERE fleet_id IN (' . $this->fleet_ids_str . ')';
         if (!$this->db->query($sql)) {
             return $this->log(MV_M_DATABASE, 'Could not update fleets movement data! SKIP');
         }
         $log1_data = array(22, $this->move['user_id'], $this->move['start'], $this->start['planet_name'], $this->start['user_id'], $this->move['dest'], $this->dest['planet_name'], $this->dest['user_id'], $spy_fleet['n_ships'], $spy_result, $this->dest['user_race']);
     }
     $log1_data[9] = array($spy_result[0], array(), array(), array(), array(), array());
     for ($i = 0; $i < count($spy_result[1]); ++$i) {
         $log1_data[9][1][$spy_result[1][$i]] = $this->dest['resource_' . ($spy_result[1][$i] + 1)];
     }
     for ($i = 0; $i < count($spy_result[2]); ++$i) {
         if ($spy_result[2][$i] == 1) {
             $log1_data[9][2][$i] = $this->dest['unit_' . ($i + 1)];
         }
     }
     for ($i = 0; $i < count($spy_result[3]); ++$i) {
         $log1_data[9][3][$spy_result[3][$i]] = $this->dest['building_' . ($spy_result[3][$i] + 1)];
     }
     for ($i = 0; $i < count($spy_result[4]); ++$i) {
         $log1_data[9][4][$spy_result[4][$i]] = $this->dest['research_' . ($spy_result[4][$i] + 1)];
     }
     for ($i = 0; $i < count($spy_result[5]); ++$i) {
         $log1_data[9][5][$spy_result[5][$i]] = $this->dest['catresearch_' . ($spy_result[5][$i] + 1)];
     }
     $log1_data[10] = $this->dest['user_race'];
     // #############################################################################
     // 31/03/08 - AC: Retrieve player language
     switch ($this->move['language']) {
         case 'GER':
             $log_title = 'Spionagebericht von ';
             $log_success = ' ausspioniert';
             break;
         case 'ITA':
             $log_title = 'Report spionaggio di ';
             $log_success = ' spiato';
             break;
         default:
             $log_title = 'Spy report of ';
             $log_success = ' spied';
             break;
     }
     add_logbook_entry($this->move['user_id'], LOGBOOK_TACTICAL, $log_title . $this->dest['planet_name'], $log1_data);
     if (!empty($log2_data)) {
         add_logbook_entry($this->dest['user_id'], LOGBOOK_TACTICAL, $this->dest['planet_name'] . $log_success, $log2_data);
     }
     return MV_EXEC_OK;
 }
        INNER JOIN (user u2) ON u2.user_id = ss.user_id
        LEFT JOIN (alliance a) ON a.alliance_id = u2.user_alliance
        
        WHERE u1.user_id = p1.planet_owner AND
              u1.user_alliance = ' . $game->player['user_alliance'] . ' AND
              ss.move_status = 0 AND
              ss.dest = p1.planet_id AND
              ss.action_code IN  (24,25,40,41,42,43,44,45,46,50,51,52,53,54,55)
        GROUP BY ss.move_id
        ORDER BY p1.planet_next_attack ASC';
if (!($q_moves = $db->query($sql))) {
    message(DATABASE_ERROR, 'Could not query moves data');
}
$commands = array(41 => constant($game->sprache("TEXT16")), 42 => constant($game->sprache("TEXT16")), 46 => constant($game->sprache("TEXT27")), 51 => constant($game->sprache("TEXT16")), 52 => '(error)', 53 => constant($game->sprache("TEXT25")), 54 => constant($game->sprache("TEXT26")), 55 => constant($game->sprache("TEXT28")));
while ($move = $db->fetchrow($q_moves)) {
    $dest_fleets = get_friendly_orbit_fleets($move['dest'], $move['dest_user_id']);
    $flight_duration = $move['move_finish'] - $move['move_begin'];
    // Move 46 shall be always visible
    if ($move['action_code'] != 46) {
        $visibility = GetVisibility($move['sum_atk_sensors'], $move['sum_atk_cloak'], $move['n_ships'], $dest_fleets['sum_sensors'], $dest_fleets['sum_cloak'], ($move['dest_spacedock'] + 1) * PLANETARY_SENSOR_VALUE, $flight_duration);
    } else {
        $visibility = 0;
    }
    $travelled = 100 / $flight_duration * ($ACTUAL_TICK - $move['move_begin']);
    if ($travelled >= $visibility) {
        $n_ships = $travelled >= $visibility + (100 - $visibility) / 4 ? $move['n_ships'] : '-';
        $command = $travelled >= $visibility + 2 * ((100 - $visibility) / 4) ? $commands[$move['action_code']] : '-';
        $game->out('
        <tr>
          <td><a href="' . parse_link('a=stats&a2=viewplayer&id=' . $move['dest_user_id']) . '">' . $move['dest_user_name'] . '</a></td>
          <td><a href="' . parse_link('a=tactical_cartography&planet_id=' . encode_planet_id($move['dest'])) . '">' . $move['dest_name'] . '</a></td>