function _action_main()
 {
     // #############################################################################
     // Data from the attacker
     $sql = 'SELECT ' . $this->get_combat_query_fleet_columns() . ', f.resource_4, f.unit_1, f.unit_2, f.unit_3, f.unit_4
     FROM (ship_fleets f)
     INNER JOIN user u ON u.user_id = f.user_id
     WHERE f.fleet_id IN (' . $this->fleet_ids_str . ')';
     if (($atk_fleets = $this->db->queryrowset($sql)) === false) {
         return $this->log(MV_M_DATABASE, 'Could not query attackers fleets data! SKIP');
     }
     /* 01/07/08 -AC: I need to move this query here, in order to correctly report attacker
      *               losses in case he lost the battle.
      */
     $sql = 'SELECT ss.fleet_id,
            SUM(ss.unit_1 - st.min_unit_1) AS troop_1,
            SUM(ss.unit_2 - st.min_unit_2) AS troop_2,
            SUM(ss.unit_3 - st.min_unit_3) AS troop_3,
            SUM(ss.unit_4 - st.min_unit_4) AS troop_4
     FROM ships ss, ship_templates st
     WHERE ss.template_id = st.id
     AND ss.fleet_id IN (' . $this->fleet_ids_str . ')
     GROUP BY ss.fleet_id';
     if (($atk_crews = $this->db->queryrowset($sql)) === false) {
         return $this->log(MV_M_DATABASE, 'Could not query attacking fleet data! SKIP');
     }
     // #############################################################################
     // Data from the defender
     $user_id = $this->dest['user_id'];
     $planetary_attack = true;
     // The course could be optimized, but it should be possible
     // compatibility to provide much action_51.php maintained
     $cur_user = array('user_id' => $user_id, 'user_name' => $this->dest['user_name'], 'user_race' => $this->dest['user_race'], 'user_planets' => $this->dest['user_planets'], 'user_alliance' => $this->dest['user_alliance']);
     $sql = 'SELECT DISTINCT f.user_id,
            u.user_alliance,
            ud.ud_id, ud.accepted,
            ad.ad_id, ad.type, ad.status
     FROM (ship_fleets f)
     INNER JOIN user u ON u.user_id = f.user_id
     LEFT JOIN user_diplomacy ud ON ( ( ud.user1_id = ' . $user_id . ' AND ud.user2_id = f.user_id ) OR ( ud.user1_id = f.user_id AND ud.user2_id = ' . $user_id . ' ) )
     LEFT JOIN alliance_diplomacy ad ON ( ( ad.alliance1_id = ' . $cur_user['user_alliance'] . ' AND ad.alliance2_id = u.user_alliance) OR ( ad.alliance1_id = u.user_alliance AND ad.alliance2_id = ' . $cur_user['user_alliance'] . ' ) )
     WHERE f.planet_id = ' . $this->move['dest'] . ' AND
           f.user_id <> ' . $user_id . ' AND
           f.user_id <> ' . $this->move['user_id'] . ' AND
           f.alert_phase >= ' . ALERT_PHASE_YELLOW;
     if (!($q_st_uid = $this->db->query($sql))) {
         return $this->log(MV_M_DATABASE, 'Could not query stationated fleets user data! SKIP');
     }
     $st_user = array();
     while ($st_uid = $this->db->fetchrow($q_st_uid)) {
         $allied = false;
         if ($st_uid['user_alliance'] == $this->dest['user_alliance']) {
             $allied = true;
         }
         if (!empty($st_uid['ud_id'])) {
             if ($st_uid['accepted'] == 1) {
                 $allied = true;
             }
         }
         if (!empty($st_uid['ad_id'])) {
             if ($st_uid['type'] == ALLIANCE_DIPLOMACY_PACT && $st_uid['status'] == 0) {
                 $allied = true;
             }
         }
         if ($allied) {
             $st_user[] = $st_uid['user_id'];
         }
     }
     $n_st_user = count($st_user);
     if ($n_st_user > 0) {
         $sql = 'SELECT ' . $this->get_combat_query_fleet_columns() . '
          FROM (ship_fleets f)
          INNER JOIN user u ON u.user_id = f.user_id
          WHERE f.planet_id = ' . $this->move['dest'] . ' AND
                (
                  (
                    f.user_id = ' . $user_id . '
                  )
                  OR
                  (
                    f.user_id IN (' . implode(',', $st_user) . ') AND
                    f.alert_phase >= ' . ALERT_PHASE_YELLOW . '
                  )
                )';
     } else {
         $sql = 'SELECT ' . $this->get_combat_query_fleet_columns() . '
          FROM (ship_fleets f)
          INNER JOIN user u ON u.user_id = f.user_id
          WHERE f.planet_id = ' . $this->move['dest'] . ' AND
                f.user_id = ' . $user_id;
     }
     if (($dfd_fleets = $this->db->queryrowset($sql)) === false) {
         return $this->log(MV_M_DATABASE, 'Could not query defenders fleets data! SKIP');
     }
     $dfd_fleet_ids = array();
     foreach ($dfd_fleets as $i => $cur_fleet) {
         $dfd_fleet_ids[] = $cur_fleet['fleet_id'];
     }
     $dfd_fleet_ids_str = implode(',', $dfd_fleet_ids);
     if ($this->do_ship_combat($this->fleet_ids_str, $dfd_fleet_ids_str, MV_COMBAT_LEVEL_PLANETARY) == MV_EXEC_ERROR) {
         $this->log(MV_M_DATABASE, 'Move Action 55: Something went wrong with this fight!');
         return MV_EXEC_ERROR;
     }
     // #############################################################################
     // If the attacker has won attempt to start takeover
     // #############################################################################
     // 03/04/08 - AC: Retrieve player language
     switch ($this->dest['language']) {
         case 'GER':
             $dfd_title = 'Angriff auf ' . $this->dest['planet_name'];
             break;
         case 'ITA':
             $dfd_title = 'Attacco su ' . $this->dest['planet_name'];
             break;
         default:
             $dfd_title = 'Attack on ' . $this->dest['planet_name'];
             break;
     }
     $action_status = 0;
     /* 11/07/08 - AC: Initialize here arrays atk/dfd_losses */
     $atk_losses = array(0, 0, 0, 0, 0);
     $dfd_losses = array(0, 0, 0, 0, 0);
     if ($this->cmb[MV_CMB_WINNER] == MV_CMB_ATTACKER) {
         if (empty($this->action_data[0])) {
             return $this->log('Moves', 'action_55: Could not find required action_data entry [0]! SKIP');
         }
         $ship_id = (int) $this->action_data[0];
         // We make it quite safe here, to see whether the
         // ship is
         $sql = 'SELECT s.ship_id, s.user_id, s.unit_1, s.unit_2, s.unit_3, s.unit_4,
                st.ship_torso, st.race, st.min_unit_1, st.min_unit_2, st.min_unit_3, st.min_unit_4,
                f.fleet_id, f.move_id, f.n_ships
         FROM (ships s)
         INNER JOIN ship_templates st ON st.id = s.template_id
         INNER JOIN ship_fleets f ON f.fleet_id = s.fleet_id
         WHERE s.ship_id = ' . $ship_id;
         if (($cship = $this->db->queryrow($sql)) === false) {
             return $this->log(MV_M_DATABASE, 'Could not query cship data! SKIP');
         }
         $cship_exists = true;
         if (empty($cship['ship_id'])) {
             $cship_exists = false;
         } elseif ($cship['user_id'] != $this->move['user_id']) {
             $cship_exists = false;
         } elseif ($cship['ship_torso'] != SHIP_TYPE_COLO) {
             $cship_exists = false;
         } elseif ($cship['move_id'] != $this->mid) {
             $cship_exists = false;
         }
         if ($cship_exists) {
             $atk_units = array($cship['unit_1'] - $cship['min_unit_1'], $cship['unit_2'] - $cship['min_unit_2'], $cship['unit_3'] - $cship['min_unit_3'], $cship['unit_4'] - $cship['min_unit_4'], 0);
             // 20/06/08 - AC: Keep out workers from battle!
             for ($i = 0; $i < count($atk_fleets); ++$i) {
                 $atk_units[0] += $atk_fleets[$i]['unit_1'];
                 $atk_units[1] += $atk_fleets[$i]['unit_2'];
                 $atk_units[2] += $atk_fleets[$i]['unit_3'];
                 $atk_units[3] += $atk_fleets[$i]['unit_4'];
                 //$atk_units[4] += $atk_fleets[$i]['resource_4']; <-- What the hell is this field?? No workers in the battle!
                 // 23/06/08 - AC: Store the space occupied by workers
                 $worker_per_fleets[$atk_fleets[$i]['fleet_id']] = $atk_fleets[$i]['resource_4'];
             }
             // 090408 DC:  ------ Let those f*****g soldiers on ships do their job!!!!
             for ($i = 0; $i < count($atk_crews); ++$i) {
                 $atk_units[0] += $atk_crews[$i]['troop_1'];
                 $atk_units[1] += $atk_crews[$i]['troop_2'];
                 $atk_units[2] += $atk_crews[$i]['troop_3'];
                 $atk_units[3] += $atk_crews[$i]['troop_4'];
             }
             // 090409 DC:  ------
             $dfd_units = array($this->dest['unit_1'], $this->dest['unit_2'], $this->dest['unit_3'], $this->dest['unit_4'], $this->dest['resource_4']);
             // Are there some defenders?
             if (array_sum($dfd_units) > 0) {
                 $ucmb = UnitFight($atk_units, $this->move['user_race'], $dfd_units, $this->dest['user_race'], $this->mid);
                 $n_atk_alive = array_sum($ucmb[0]);
                 $atk_alive = $ucmb[0];
                 $dfd_alive = $ucmb[1];
             } else {
                 $n_atk_alive = 1;
                 $atk_alive = $atk_units;
                 $dfd_alive = array(0, 0, 0, 0, 0);
             }
             // 01/07/08 - AC: Count losses for each part
             for ($i = 0; $i < 5; ++$i) {
                 $atk_losses[$i] = $atk_units[$i] - $atk_alive[$i];
                 $dfd_losses[$i] = $dfd_units[$i] - $dfd_alive[$i];
             }
             // If there are no more attackers, the defender
             // always won even if the defending had no units
             if ($n_atk_alive == 0) {
                 // In order to eliminate the troops of the aggressor, simply reset all transporters
                 // 21/06/08 - AC: Keep out workers from battle!
                 $sql = 'UPDATE ship_fleets
                 SET unit_1 = 0,
                     unit_2 = 0,
                     unit_3 = 0,
                     unit_4 = 0
                 WHERE fleet_id IN (' . $this->fleet_ids_str . ')';
                 if (!$this->db->query($sql)) {
                     return $this->log(MV_M_DATABASE, 'Could not update ship fleets unit transport data! SKIP');
                 }
                 // Simply update the defender troops
                 $sql = 'UPDATE planets
                 SET unit_1 = ' . $ucmb[1][0] . ',
                     unit_2 = ' . $ucmb[1][1] . ',
                     unit_3 = ' . $ucmb[1][2] . ',
                     unit_4 = ' . $ucmb[1][3] . ',
                     resource_4 = ' . $ucmb[1][4] . '
                 WHERE planet_id = ' . $this->move['dest'];
                 if (!$this->db->query($sql)) {
                     return $this->log(MV_M_DATABASE, 'Could not update dest planet units data! SKIP');
                 }
                 // 090408 DC:  ------ Finally the f*****g soldiers have done their job!!!!
                 $this->log(MV_M_NOTICE, 'Update ships with the minimum troops value');
                 $sql = 'UPDATE ships ss, ship_templates st
                 SET ss.unit_1 = st.min_unit_1,
                     ss.unit_2 = st.min_unit_2,
                     ss.unit_3 = st.min_unit_3,
                     ss.unit_4 = st.min_unit_4
                 WHERE ss.template_id = st.id
             AND ss.fleet_id IN (' . $this->fleet_ids_str . ')';
                 if (!$this->db->query($sql)) {
                     return $this->log(MV_M_DATABASE, 'Could not update attacking ships! SKIP');
                 }
                 // 090408 DC:  ------
                 $action_status = -1;
                 // #############################################################################
                 // 03/04/08 - AC: Retrieve player language
                 switch ($this->move['language']) {
                     case 'GER':
                         $atk_title = 'Angriff auf ' . $this->dest['planet_name'] . ' teilweise erfolgreich';
                         break;
                     case 'ITA':
                         $atk_title = 'Attacco su ' . $this->dest['planet_name'] . ' parzialmente riuscito';
                         break;
                     default:
                         $atk_title = 'Attack on ' . $this->dest['planet_name'] . ' partially successful';
                         break;
                 }
             } else {
                 account_log($this->move['user_id'], $this->dest['user_id'], 4);
                 // Export a ruler switch
                 // We need the number of planets, which owns the colonizing
                 // (we want planet_owner_enum degree of certainty)
                 $sql = 'SELECT COUNT(planet_id) AS n_planets
                 FROM planets
                 WHERE planet_owner = ' . $this->move['user_id'];
                 if (($pcount = $this->db->queryrow($sql)) === false) {
                     $this->log(MV_M_DATABASE, 'Could not query planets count data! CONTINUE AND USE INSTABLE VALUE');
                     $n_planets = $this->move['user_planets'];
                 } else {
                     $n_planets = $pcount['n_planets'];
                 }
                 // We accommodate as much troops, as on the colony ship were, on the planet
                 $planet_units = array(0, 0, 0, 0);
                 // 21/06/08 - AC: Check available space on target planet
                 $sql = 'SELECT max_units FROM planets WHERE planet_id = ' . $this->move['dest'];
                 if (($plspace = $this->db->queryrow($sql)) === false) {
                     $this->log(MV_M_DATABASE, 'Could not query planet max units data! CONTINUE AND USE INSTABLE VALUE');
                     $plspace['max_units'] = 1300;
                     // Minimum size available
                 }
                 if ($atk_alive[0] * 2 + $atk_alive[1] * 3 + $atk_alive[2] * 4 + $atk_alive[3] * 4 > $plspace['max_units']) {
                     $this->log(MV_M_NOTICE, 'Alive units exceed planet maximum units, we need to recall aboard the surplus');
                     // AC: Recall aboard the surplus troops
                     $i = 0;
                     while ($n_atk_alive) {
                         if ($planet_units[0] * 2 + $planet_units[1] * 3 + $planet_units[2] * 4 + $planet_units[3] * 4 >= $plspace['max_units']) {
                             break;
                         }
                         if ($atk_alive[$i] > 0) {
                             $planet_units[$i]++;
                             $atk_alive[$i]--;
                             $n_atk_alive--;
                         } else {
                             $i++;
                         }
                     }
                     $this->log(MV_M_NOTICE, 'Troops that will return aboard: Lev1 ' . $atk_alive[0] . ' Lev2 ' . $atk_alive[1] . ' Lev3 ' . $atk_alive[2] . ' Lev4 ' . $atk_alive[3]);
                     // We pick ALL transporter of the fleets and then distribute
                     $sql = 'SELECT s.ship_id, s.fleet_id
                     FROM (ships s)
                     INNER JOIN (ship_templates st) ON s.template_id = st.id
                     WHERE s.fleet_id IN (' . $this->fleet_ids_str . ') AND
                           st.ship_torso = ' . SHIP_TYPE_TRANSPORTER;
                     if (!($q_ftrans = $this->db->query($sql))) {
                         $this->log(MV_M_DATABASE, 'Could not query fleets transporter data! CONTINUE');
                     }
                     // 27/10/08 - AC: First of all, loads all available transports
                     $space_per_fleets = array();
                     while ($_ship = $this->db->fetchrow($q_ftrans)) {
                         if (!isset($space_per_fleets[$_ship['fleet_id']])) {
                             $space_per_fleets[$_ship['fleet_id']] = $worker_per_fleets[$_ship['fleet_id']] * -1;
                         }
                         $space_per_fleets[$_ship['fleet_id']] += MAX_TRANSPORT_UNITS;
                     }
                     foreach ($space_per_fleets as $fleet_id => $free_space) {
                         if ($free_space == 0) {
                             continue;
                         }
                         $still_free = $free_space;
                         $new_load = array(0, 0, 0, 0);
                         for ($i = 0; $i < 4; ++$i) {
                             if ($atk_alive[$i] > 0) {
                                 $new_load[$i] = $atk_alive[$i] > $still_free ? $still_free : $atk_alive[$i];
                                 $atk_alive[$i] -= $new_load[$i];
                                 $still_free -= $new_load[$i];
                             }
                             if ($still_free == 0) {
                                 break;
                             }
                         }
                         $sql = 'UPDATE ship_fleets
                         SET unit_1 = ' . $new_load[0] . ',
                             unit_2 = ' . $new_load[1] . ',
                             unit_3 = ' . $new_load[2] . ',
                             unit_4 = ' . $new_load[3] . '
                         WHERE fleet_id = ' . $fleet_id;
                         if (!$this->db->query($sql)) {
                             $this->log(MV_M_DATABASE, 'Could not update fleets units data! CONTINUE');
                         }
                     }
                     // 27/10/08- AC: If there are still some extra troops on ground
                     $n_atk_still_to_board = array_sum($atk_alive);
                     if ($n_atk_still_to_board > 0) {
                         $this->log(MV_M_NOTICE, 'There are still: Lev1 ' . $atk_alive[0] . ' Lev2 ' . $atk_alive[1] . ' Lev3 ' . $atk_alive[2] . ' Lev4 ' . $atk_alive[3] . ' troops to embark!');
                         // Extra troops didn't really leave the ships so we have to remove the losses
                         $sql = 'SELECT ss.ship_id,
                                st.min_unit_1, st.max_unit_1,
                                st.min_unit_2, st.max_unit_2,
                                st.min_unit_3, st.max_unit_3,
                                st.min_unit_4, st.max_unit_4
                          FROM ships ss, ship_templates st
                          WHERE ss.template_id = st.id AND
                                ss.fleet_id IN (' . $this->fleet_ids_str . ')';
                         if (!($q_ships = $this->db->query($sql))) {
                             $this->log(MV_M_DATABASE, 'Could not query fleets ships data! CONTINUE');
                         }
                         // Distribute troops on available ships
                         while ($ship = $this->db->fetchrow($q_ships)) {
                             $new_crew = array(0, 0, 0, 0);
                             // For each type of troops
                             for ($i = 0; $i < 4; ++$i) {
                                 $j = $i + 1;
                                 // Are there still some troops?
                                 if ($atk_alive[$i] > 0) {
                                     $new_crew[$i] = $atk_alive[$i] > $ship['max_unit_' . $j] ? $ship['max_unit_' . $j] : $atk_alive[$i];
                                     $atk_alive[$i] -= $new_crew[$i];
                                 } else {
                                     $new_crew[$i] = $ship['min_unit_' . $j];
                                 }
                                 $n_atk_still_to_board -= $new_crew[$i];
                             }
                             // Update ship's crew
                             $sql = 'UPDATE ships
                             SET unit_1 = ' . $new_crew[0] . ',
                                 unit_2 = ' . $new_crew[1] . ',
                                 unit_3 = ' . $new_crew[2] . ',
                                 unit_4 = ' . $new_crew[3] . '
                             WHERE ship_id =' . $ship['ship_id'];
                             if (!$this->db->query($sql)) {
                                 $this->log(MV_M_DATABASE, 'Could not update ship crew data! CONTINUE');
                             }
                             // If we have finished boarding phase, we are ready to takeoff ;)
                             if ($n_atk_still_to_board == 0) {
                                 break;
                             }
                         }
                     }
                 } else {
                     for ($i = 0; $i <= 3; ++$i) {
                         $planet_units[$i] += $atk_alive[$i];
                     }
                     // 28/06/08 - AC: Snort! Delete landed troops!
                     $sql = 'UPDATE ship_fleets
                     SET unit_1 = 0,
                         unit_2 = 0,
                         unit_3 = 0,
                         unit_4 = 0
                     WHERE fleet_id IN (' . $this->fleet_ids_str . ')';
                     if (!$this->db->query($sql)) {
                         return $this->log(MV_M_DATABASE, 'Could not update ship fleets unit transport data! SKIP');
                     }
                     // 27/10/08 - AC: Delete also extra troops on ships...
                     $sql = 'UPDATE ships ss, ship_templates st
                     SET ss.unit_1 = st.min_unit_1,
                         ss.unit_2 = st.min_unit_2,
                         ss.unit_3 = st.min_unit_3,
                         ss.unit_4 = st.min_unit_4
                     WHERE ss.template_id = st.id AND
                           ss.fleet_id IN (' . $this->fleet_ids_str . ')';
                     if (!$this->db->query($sql)) {
                         return $this->log(MV_M_DATABASE, 'Could not update attacking ships to minimum crew! SKIP');
                     }
                 }
                 $this->log(MV_M_NOTICE, 'Troops that will remain on the planet: Lev1 ' . $planet_units[0] . ' Lev2 ' . $planet_units[1] . ' Lev3 ' . $planet_units[2] . ' Lev4 ' . $planet_units[3]);
                 $sql = 'DELETE FROM scheduler_instbuild
                 WHERE planet_id = ' . $this->move['dest'];
                 if (!$this->db->query($sql)) {
                     $this->log(MV_M_DATABASE, 'Could not delete scheduler instbuild data! CONTINUE');
                 }
                 $sql = 'DELETE FROM scheduler_research
                 WHERE planet_id = ' . $this->move['dest'];
                 if (!$this->db->query($sql)) {
                     $this->log(MV_M_DATABASE, 'Could not delete scheduler research data! CONTINUE');
                 }
                 $sql = 'DELETE FROM scheduler_resourcetrade
                 WHERE planet = ' . $this->move['dest'];
                 if (!$this->db->query($sql)) {
                     $this->log(MV_M_DATABASE, 'Could not delete resource data! CONTINUE');
                 }
                 $sql = 'DELETE FROM scheduler_shipbuild
                 WHERE planet_id = ' . $this->move['dest'];
                 if (!$this->db->query($sql)) {
                     $this->log(MV_M_DATABASE, 'Could not delete shipbuild data! CONTINUE');
                 }
                 global $NUM_BUILDING, $MAX_BUILDING_LVL;
                 // As someone yes number == max_index sets
                 $n_buildings = $NUM_BUILDING + 1;
                 $building_levels = array();
                 $building_damage = 0.01 * mt_rand(40, 60);
                 // Set new home world
                 if ($this->move['dest'] == $this->dest['user_capital']) {
                     for ($i = 0; $i < $n_buildings; ++$i) {
                         $j = $i + 1;
                         $building_levels[$i] = (int) ($this->dest['building_' . $j] > $MAX_BUILDING_LVL[0][$i]) ? $MAX_BUILDING_LVL[0][$i] : round($this->dest['building_' . $j] * $building_damage, 0);
                     }
                     if ($this->dest['user_planets'] == 1) {
                         // #############################################################################
                         // 03/04/08 - AC: Retrieve player language
                         switch ($this->dest['language']) {
                             case 'GER':
                                 $msg_title = 'Verlust aller deiner Planeten';
                                 $msg_body = 'Da du alle deine Planeten verloren hast, wurde f&uuml;r dich ein neuer Planet an einer zuf&uuml;ligen Stelle der Galaxie erstellt.';
                                 break;
                             case 'ITA':
                                 $msg_title = 'Perdita di tutti i pianeti';
                                 $msg_body = 'Dato che hai perduto tutti i pianeti ne &egrave; stato creato uno nuovo nella galassia.';
                                 break;
                             default:
                                 $msg_title = 'Loss of all your planets';
                                 $msg_body = 'Since you lost all your planets a new one have been created in the body of the galaxy.';
                                 break;
                         }
                         SystemMessage($this->dest['user_id'], $msg_title, $msg_body);
                     } else {
                         if (!$this->db->query('SET @i=0')) {
                             return $this->log(MV_M_DATABASE, 'Could not set sql iterator variable for planet owner enum! SKIP');
                         }
                         $sql = 'UPDATE planets
                         SET planet_owner_enum = (@i := (@i + 1))-1
                         WHERE planet_owner = ' . $this->dest['user_id'] . '
                         ORDER BY planet_owned_date ASC, planet_id ASC';
                         if (!$this->db->query($sql)) {
                             return $this->log(MV_M_DATABASE, 'Could not update planet owner enum data! SKIP');
                         }
                         $sql = 'SELECT planet_id
                         FROM planets
                         WHERE planet_owner = ' . $this->dest['user_id'] . '
                         ORDER BY planet_owner_enum ASC
                         LIMIT 1';
                         if (($first_planet = $this->db->queryrow($sql)) === false) {
                             return $this->log(MV_M_DATABASE, 'Could not query first planet data! SKIP');
                         }
                         $sql = 'UPDATE user
                         SET last_active = ' . time() . ',
                             last_ip = "0.0.0.0",
                             user_capital = ' . $first_planet['planet_id'] . ',
                             pending_capital_choice = 1
                         WHERE user_id = ' . $this->dest['user_id'];
                         if (!$this->db->query($sql)) {
                             return $this->log(MV_M_DATABASE, 'Could not update user capital data! SKIP');
                         }
                     }
                 } else {
                     for ($i = 0; $i < $n_buildings; ++$i) {
                         $building_levels[$i] = round($this->dest['building_' . ($i + 1)] * $building_damage, 0);
                     }
                 }
                 $sql = 'DELETE FROM resource_trade
                 WHERE planet = ' . $this->move['dest'];
                 if (!$this->db->query($sql)) {
                     $this->log(MV_M_DATABASE, 'Could not delete resource trade data! CONTINUE');
                 }
                 $sql = 'SELECT ship_id
                 FROM ship_trade
                 WHERE scheduler_processed = 0 AND
                       planet = ' . $this->move['dest'];
                 if (!($q_shipt = $this->db->query($sql))) {
                     $this->log(MV_M_DATABASE, 'Could not query ship trade data! CONTINUE');
                 } else {
                     $ship_ids = array();
                     while ($_ship = $this->db->fetchrow($q_shipt)) {
                         $ship_ids[] = $_ship['ship_id'];
                     }
                     if (count($ship_ids) > 0) {
                         $sql = 'UPDATE ships
                         SET ship_untouchable = 0
                         WHERE ship_id IN (' . implode(',', $ship_ids) . ')';
                         if (!$this->db->query($sql)) {
                             $this->log(MV_M_DATABASE, 'Could not update ships untouchable data! CONTINUE');
                         }
                     }
                 }
                 $sql = 'DELETE FROM ship_trade
                 WHERE scheduler_processed = 0 AND
                       planet = ' . $this->move['dest'];
                 if (!$this->db->query($sql)) {
                     $this->log(MV_M_DATABASE, 'Could not delete ship trade data! CONTINUE');
                 }
                 $sql = 'UPDATE planets
                 SET planet_owner = ' . $this->move['user_id'] . ',
                     planet_owned_date = ' . time() . ',
                     planet_owner_enum = ' . ($n_planets - 1) . ',
                     best_mood = 0,
                     best_mood_user = 0,
                     planet_available_points = ' . $this->get_structure_points($this->move['user_id'], $this->move['dest']) . ',
                     resource_4 = 0,
                     recompute_static = 1,
                     building_1 = ' . $building_levels[0] . ',
                     building_2 = ' . $building_levels[1] . ',
                     building_3 = ' . $building_levels[2] . ',
                     building_4 = ' . $building_levels[3] . ',
                     building_5 = ' . $building_levels[4] . ',
                     building_6 = ' . $building_levels[5] . ',
                     building_7 = ' . $building_levels[6] . ',
                     building_8 = ' . $building_levels[7] . ',
                     building_9 = ' . $building_levels[8] . ',
                     building_10 = ' . $building_levels[9] . ',
                     building_11 = ' . $building_levels[10] . ',
                     building_12 = ' . $building_levels[11] . ',
                     building_13 = ' . $building_levels[12] . ',
                     unit_1 = ' . $planet_units[0] . ',
                     unit_2 = ' . $planet_units[1] . ',
                     unit_3 = ' . $planet_units[2] . ',
                     unit_4 = ' . $planet_units[3] . ',
                     unit_5 = 0,
                     unit_6 = 0,
                     workermine_1 = 100,
                     workermine_2 = 100,
                     workermine_3 = 100,
                     catresearch_1 = 0,
                     catresearch_2 = 0,
                     catresearch_3 = 0,
                     catresearch_4 = 0,
                     catresearch_5 = 0,
                     catresearch_6 = 0,
                     catresearch_7 = 0,
                     catresearch_8 = 0,
                     catresearch_9 = 0,
                     catresearch_10 = 0,
                     unittrainid_1 = 0,
                     unittrainid_2 = 0,
                     unittrainid_3 = 0,
                     unittrainid_4 = 0,
                     unittrainid_5 = 0,
                     unittrainid_6 = 0,
                     unittrainid_7 = 0,
                     unittrainid_8 = 0,
                     unittrainid_9 = 0,
                     unittrainid_10 = 0,
                     unittrainnumber_1 = 0,
                     unittrainnumber_2 = 0,
                     unittrainnumber_3 = 0,
                     unittrainnumber_4 = 0,
                     unittrainnumber_5 = 0,
                     unittrainnumber_6 = 0,
                     unittrainnumber_7 = 0,
                     unittrainnumber_8 = 0,
                     unittrainnumber_9 = 0,
                     unittrainnumber_10 = 0,
                     unittrainnumberleft_1 = 0,
                     unittrainnumberleft_2 = 0,
                     unittrainnumberleft_3 = 0,
                     unittrainnumberleft_4 = 0,
                     unittrainnumberleft_5 = 0,
                     unittrainnumberleft_6 = 0,
                     unittrainnumberleft_7 = 0,
                     unittrainnumberleft_8 = 0,
                     unittrainnumberleft_9 = 0,
                     unittrainnumberleft_10 = 0,
                     unittrain_actual = 0,
                     unittrainid_nexttime=0,
                     planet_insurrection_time=0,
                     planet_surrender=0
                 WHERE planet_id = ' . $this->move['dest'];
                 //$this->log('SQL Debug', ''.$sql.'');
                 if (!$this->db->query($sql)) {
                     return $this->log(MV_M_DATABASE, 'Could not update planets data! SKIP');
                 }
                 // DC ---- History record in planet_details, with label '26'
                 $sql = 'INSERT INTO planet_details (planet_id, user_id, alliance_id, source_uid, source_aid, timestamp, log_code, defeat_uid, defeat_aid)
                 VALUES (' . $this->move['dest'] . ', ' . $this->move['user_id'] . ', ' . $this->move['user_alliance'] . ', ' . $this->move['user_id'] . ', ' . $this->move['user_alliance'] . ', ' . time() . ', 26,' . $this->dest['user_id'] . ', ' . $this->dest['user_alliance'] . ')';
                 if (!$this->db->query($sql)) {
                     $this->log(MV_M_DATABASE, 'Could not update planet details data! CONTINUE');
                 }
                 // If the attack was on a settlers planet, we get rid of the moods data!
                 if ($this->dest['user_id'] == INDEPENDENT_USERID) {
                     $this->log(MV_M_NOTICE, 'Colony: Settlers taken over!!! They gonna be no more...');
                     $sql = 'SELECT user_id, user_name, language FROM settlers_relations
                                                         INNER JOIN user USING user_id
                     WHERE planet_id = ' . $this->move['dest'] . ' AND user_id NOT = ' . $this->move['user_id'] . '
                     GROUP BY user_id';
                     if ($res = $this->db->queryrowset($sql)) {
                         foreach ($res as $res_item) {
                             $log_data = array($this->move['dest'], $this->dest['planet_name'], 0, '', 105, $res_item['user_name']);
                             switch ($res_item['language']) {
                                 case 'GER':
                                     $log_title = 'Automatic distress message from ';
                                     break;
                                 case 'ITA':
                                     $log_title = 'Richiesta automatica di soccorso dalla colonia ';
                                     break;
                                 default:
                                     $log_title = 'Automatic distress message from ';
                                     break;
                             }
                             add_logbook_entry($res_item['user_id'], LOGBOOK_SETTLERS, $log_title . $this->dest['planet_name'], $log_data);
                         }
                     }
                     $sql = 'DELETE FROM settlers_relations WHERE planet_id = ' . $this->dest['planet_id'];
                     if (!$this->db->query($sql)) {
                         $this->log(MV_M_DATABASE, 'Could not delete settlers moods! CONTINUE!');
                     }
                     $sql = 'SELECT planet_id FROM settlers_relations WHERE user_id = ' . $this->move['user_id'] . ' GROUP BY planet_id';
                     if ($res = $this->db->queryrowset($sql)) {
                         foreach ($res as $res_item) {
                             // Clear all + logs on the planet
                             $sql = 'DELETE FROM settlers_relations
                             WHERE user_id = ' . $this->move['user_id'] . '
                             AND planet_id = ' . $res_item['planet_id'] . '
                             AND log_code IN ("2", "3", "4")';
                             if (!$this->db->query($sql)) {
                                 $this->log(MV_M_DATABASE, 'Could not delete settlers relations data! ' . $sql . ' CONTINUE');
                             }
                             $sql = 'INSERT INTO settlers_relations SET planet_id = ' . $res_item['planet_id'] . ',
                                                                user_id = ' . $this->move['user_id'] . ',
                                                                timestamp = ' . time() . ', log_code = 12,
                                                                mood_modifier = -50';
                             $this->db->query($sql);
                             $this->check_best_mood($res_item['planet_id'], false);
                         }
                     }
                 }
                 // DC ----
                 $this->log('Update Planetdata', 'Limited resources');
                 //Concept of vessels destroyed by hostile takeover.
                 //Version 0.2b by Mojo1987 - Calculation adjusted
                 $this->log('Ship destruction', 'Begin ships deletion');
                 $sql = 'SELECT s.ship_id FROM (ships s) WHERE s.fleet_id = -' . $this->move['dest'] . '';
                 if (!($del_ship = $this->db->query($sql))) {
                     $this->log('Errors with ships get', 'Could not query planets ships! CONTINUE - ' . $sql . '');
                 }
                 while ($ship_wahl = $this->db->fetchrow($del_ship)) {
                     $zufall = mt_rand(6, 18);
                     if ($zufall >= 8) {
                         $sql = 'DELETE FROM ships WHERE ship_id = ' . $ship_wahl['ship_id'] . '';
                         if (!$this->db->query($sql)) {
                             $this->log('Error with ship deletion', 'Could not query deleted ship! CONTINUE');
                         } else {
                             $this->log('Ships removed', 'Ship_ID: ' . $ship_wahl['ship_id'] . ' Random number: ' . $zufall . ' <b>SUCCESS!</b>');
                         }
                     }
                 }
                 $this->log('Ship destruction', 'Deletion ended');
                 if (!$this->db->query('SET @i=0')) {
                     return $this->log(MV_M_DATABASE, 'Could not set sql iterator variable for planet owner enum (the invading player)! SKIP');
                 }
                 $sql = 'UPDATE planets
                 SET planet_owner_enum = (@i := (@i + 1))-1
                 WHERE planet_owner = ' . $this->move['user_id'] . '
                 ORDER BY planet_owned_date ASC, planet_id ASC';
                 if (!$this->db->query($sql)) {
                     return $this->log(MV_M_DATABASE, 'Could not update planet owner enum data (the invading player)! SKIP');
                 }
                 $sql = 'UPDATE ships
                 SET user_id = ' . $this->move['user_id'] . '
                 WHERE fleet_id = -' . $this->move['dest'];
                 if (!$this->db->query($sql)) {
                     return $this->log(MV_M_DATABASE, 'Could not update ships location data! SKIP');
                 }
                 if ($this->dest['user_id'] == BORG_USERID) {
                     if ((int) $this->move['user_alliance'] != 0) {
                         $sql = 'UPDATE alliance
                         SET borg_invade = borg_invade + 1
                         WHERE alliance_id = ' . $this->move['user_alliance'];
                         if (!$this->db->query($sql)) {
                             $this->log(MV_M_DATABASE, 'Could not update user alliance Borg honor data! CONTINUE');
                         }
                     }
                     $num_item = $this->dest['planet_type'] == "m" || $this->dest['planet_type'] == "o" || $this->dest['planet_type'] == "y" || $this->dest['planet_type'] == "x" || $this->dest['planet_type'] == "f" || $this->dest['planet_type'] == "g" ? 2 : 1;
                     send_premonition_to_user($this->move['user_id'], $num_item);
                     $sql = 'SELECT threat_level FROM borg_target WHERE user_id = ' . $this->move['user_id'];
                     $bot_target_data = $this->db->query($sql);
                     $already_acquired = $this->db->num_rows($bot_target_data);
                     if ($already_acquired < 1) {
                         $honor_prize = $this->dest['planet_type'] == "m" || $this->dest['planet_type'] == "o" || $this->dest['planet_type'] == "y" || $this->dest['planet_type'] == "x" || $this->dest['planet_type'] == "f" || $this->dest['planet_type'] == "g" ? 40 : 15;
                         $sql = 'INSERT INTO borg_target (user_id, planets_taken, battle_win) VALUES (' . $this->move['user_id'] . ', 1, 1)';
                         $this->db->query($sql);
                     } else {
                         $honor_bonus_data = $this->db->fetchrow($bot_target_data);
                         // Keep values align with those present in in borg.php
                         if ($honor_bonus_data['threat_level'] > 1400.0) {
                             $honor_bonus = 5.0;
                         } elseif ($honor_bonus_data['threat_level'] > 950.0) {
                             $honor_bonus = 3.0;
                         } elseif ($honor_bonus_data['threat_level'] > 450.0) {
                             $honor_bonus = 2.0;
                         } elseif ($honor_bonus_data['threat_level'] > 200.0) {
                             $honor_bonus = 1.5;
                         } else {
                             $honor_bonus = 1.0;
                         }
                         $honor_prize = ($this->dest['planet_type'] == "m" || $this->dest['planet_type'] == "n" || $this->dest['planet_type'] == "y" || $this->dest['planet_type'] == "e" || $this->dest['planet_type'] == "f" || $this->dest['planet_type'] == "g" ? 40 : 15) * $honor_bonus;
                         $sql = 'UPDATE borg_target SET planets_taken = planets_taken + 1, battle_win = battle_win +1 WHERE user_id = ' . $this->move['user_id'];
                         $this->db->query($sql);
                     }
                     $sql = 'UPDATE user SET user_honor = user_honor + ' . $honor_prize . ' WHERE user_id = ' . $this->move['user_id'];
                     if (!$this->db->query($sql)) {
                         $this->log(MV_M_DATABASE, 'Could not update user honor data! CONTINUE');
                     }
                     if (isset($this->move['user_alliance']) && !empty($this->move['user_alliance'])) {
                         $sql = 'UPDATE alliance SET alliance_honor = alliance_honor + ' . $honor_prize . ' WHERE alliance_id = ' . $this->move['user_alliance'];
                         if (!$this->db->query($sql)) {
                             $this->log(MV_M_DATABASE, 'Could not update alliance honor data! CONTINUE');
                         }
                     }
                     // #############################################################################
                     // 03/04/08 - AC: Retrieve player language
                     switch ($this->move['language']) {
                         case 'GER':
                             $msg_title = 'Verdienst im Kampf gegen die Borg';
                             $msg_text = 'F&uuml;e gerade erbrachten Verdienst gegen die neue Invasion des Borg-Kollektives befinden sich im Anflug auf euren Heimatplaneten ein speziell f&ouml;sen Kampf entwickeltes Schiff. Versucht nicht die enthaltene Technologie zu verstehen, sie wurde wirkungsvoll gegen euch abgeschirmt - nutzt sie stattdessen in eurem weiteren Kampf!';
                             break;
                         case 'ITA':
                             $msg_title = 'Merito in battaglia contro i Borg';
                             $msg_text = 'Proprio per rendere merito contro la nuova invasione del collettivo Borg si trova in approccio al tuo pianeta madre una nave appositamente progettata per combatterli. Non provare a capire la tecnologia inclusa, &egrave; stata efficacemente schermata contro di te - utilizzala invece ulteriormente nella tua lotta!';
                             break;
                         default:
                             $msg_title = 'Merit in the battle against the Borg';
                             $msg_text = 'For precisely rendered merit against the new invasion of the Borg Collective are located in the approach to your home planet fuse fight a specially designed ship. Do not try to understand the included technology, it was effectively shielded against you - instead uses it further in your fight!';
                             break;
                     }
                     $sql = 'INSERT INTO message (sender, receiver, subject, text, time)
                     VALUES (' . FUTURE_HUMANS_UID . ', ' . $this->move['user_id'] . ', "' . $msg_title . '", "' . $msg_text . '", ' . time() . ')';
                     if (!$this->db->query($sql)) {
                         $this->log(MV_M_DATABASE, 'Could not send message');
                     }
                 }
                 $action_status = 1;
                 // #############################################################################
                 // 03/04/08 - AC: Retrieve player language
                 switch ($this->move['language']) {
                     case 'GER':
                         $atk_title = 'Angriff auf ' . $this->dest['planet_name'] . ' erfolgreich';
                         break;
                     case 'ITA':
                         $atk_title = 'Attacco su ' . $this->dest['planet_name'] . ' riuscito';
                         break;
                     default:
                         $atk_title = 'Attack on ' . $this->dest['planet_name'] . ' successful';
                         break;
                 }
             }
             $sql = 'DELETE FROM ships
             WHERE ship_id = ' . $ship_id;
             if (!$this->db->query($sql)) {
                 return $this->log(MV_M_DATABASE, 'Could not delete ships data! SKIP');
             }
             if ($cship['n_ships'] == 1) {
                 $sql = 'DELETE FROM ship_fleets
                 WHERE fleet_id = ' . $cship['fleet_id'];
             } else {
                 $sql = 'UPDATE ship_fleets
                 SET n_ships = n_ships - 1
                 WHERE fleet_id = ' . $cship['fleet_id'];
             }
             if (!$this->db->query($sql)) {
                 $this->log(MV_M_DATABASE, 'Could not update/delete cships fleet data! CONTINUE');
             }
         } else {
             $action_status = -2;
             // #############################################################################
             // 03/04/08 - AC: Retrieve player language
             switch ($this->move['language']) {
                 case 'GER':
                     $atk_title = 'Angriff auf ' . $this->dest['planet_name'] . ' teilweise erfolgreich';
                     break;
                 case 'ITA':
                     $atk_title = 'Attacco su ' . $this->dest['planet_name'] . ' parzialmente riuscito';
                     break;
                 default:
                     $atk_title = 'Attack on ' . $this->dest['planet_name'] . ' partially successful';
                     break;
             }
         }
         $sql = 'UPDATE ship_fleets
         SET planet_id = ' . $this->move['dest'] . ',
             move_id = 0
         WHERE fleet_id IN (' . $this->fleet_ids_str . ')';
         if (!$this->db->query($sql)) {
             // Here one could also report and then go on
             return $this->log(MV_M_DATABASE, 'Could not update fleets location data! SKIP');
         }
     } else {
         // #############################################################################
         // 03/04/08 - AC: Retrieve player language
         switch ($this->move['language']) {
             case 'GER':
                 $atk_title = 'Angriff auf ' . $this->dest['planet_name'] . ' fehlgeschlagen';
                 break;
             case 'ITA':
                 $atk_title = 'Attacco su ' . $this->dest['planet_name'] . ' fallito';
                 break;
             default:
                 $atk_title = 'Attack on ' . $this->dest['planet_name'] . ' failed';
                 break;
         }
         // 01/07/08 - The attacker has lost the fleets
         for ($i = 0; $i < count($atk_fleets); ++$i) {
             $atk_losses[0] += $atk_fleets[$i]['unit_1'];
             $atk_losses[1] += $atk_fleets[$i]['unit_2'];
             $atk_losses[2] += $atk_fleets[$i]['unit_3'];
             $atk_losses[3] += $atk_fleets[$i]['unit_4'];
             $atk_losses[4] += $atk_fleets[$i]['resource_4'];
         }
         for ($i = 0; $i < count($atk_crews); ++$i) {
             $atk_losses[0] += $atk_crews[$i]['troop_1'];
             $atk_losses[1] += $atk_crews[$i]['troop_2'];
             $atk_losses[2] += $atk_crews[$i]['troop_3'];
             $atk_losses[3] += $atk_crews[$i]['troop_4'];
         }
     }
     // #############################################################################
     // Write logbook
     $log1_data = array(55, $this->move['user_id'], $this->move['dest'], $this->dest['planet_name'], $this->dest['user_id'], 0, 0, 0, MV_CMB_ATTACKER, $this->cmb[MV_CMB_WINNER] == MV_CMB_ATTACKER ? 1 : 0, 0, 0, $atk_fleets, $dfd_fleets);
     $log2_data = array(55, $this->move['user_id'], $this->move['dest'], $this->dest['planet_name'], $this->dest['user_id'], 0, 0, 0, MV_CMB_DEFENDER, $this->cmb[MV_CMB_WINNER] == MV_CMB_DEFENDER ? 1 : 0, 0, 0, $atk_fleets, $dfd_fleets);
     $log1_data[17] = $log2_data[17] = $action_status;
     $log1_data[20] = $this->dest['user_race'];
     $log2_data[20] = $this->move['user_race'];
     for ($i = 0; $i < 5; ++$i) {
         $log1_data[18][$i] = $log2_data[19][$i] = $atk_losses[$i];
         $log1_data[19][$i] = $log2_data[18][$i] = $dfd_losses[$i];
     }
     //$log1_data[19][4] = $log2_data[18][4] = (int)$dfd_losses[4]; already done by for above...
     $log2_data[14] = $this->cmb[MV_CMB_KILLS_PLANETARY];
     $log1_data[10] = $this->cmb[MV_CMB_KILLS_EXT];
     $log2_data[10] = $this->cmb[MV_CMB_KILLS_EXT];
     add_logbook_entry($this->move['user_id'], LOGBOOK_TACTICAL, $atk_title, $log1_data);
     add_logbook_entry($this->dest['user_id'], LOGBOOK_TACTICAL, $dfd_title, $log2_data);
     if ($n_st_user > 0) {
         $log2_data[2] = $this->move['start'];
         $log2_data[3] = $this->dest['planet_name'];
         $log2_data[4] = $user_id;
         $log2_data[5] = 0;
         $log2_data[6] = 0;
         $log2_data[7] = 0;
         $log2_data[16] = 1;
         for ($i = 0; $i < $n_st_user; ++$i) {
             // #############################################################################
             // 24/06/08 - AC: Retrieve player language
             $log_title = 'One of your allies defended ' . $this->dest['planet_name'];
             $sql = 'SELECT language FROM user WHERE user_id = ' . $st_user[$i];
             if (!($lang = $this->db->queryrow($sql))) {
                 $this->log(MV_M_DATABASE, 'Could not retrieve player language');
             } else {
                 switch ($lang['language']) {
                     case 'GER':
                         $log_title = 'Verb&uuml;ndeten bei ' . $this->dest['planet_name'] . ' verteidigt';
                         break;
                     case 'ITA':
                         $log_title = 'Difesa alleata presso ' . $this->dest['planet_name'];
                         break;
                 }
             }
             add_logbook_entry($st_user[$i], LOGBOOK_TACTICAL, $log_title, $log2_data);
         }
     }
     return MV_EXEC_OK;
 }
Beispiel #2
0
            default:
                $text = 'almost exclusively sitted';
                if ($val < 0.8) {
                    $text = 'very excessively sitted';
                }
                if ($val < 0.6) {
                    $text = 'excessively sitted';
                }
                if ($val < 0.45) {
                    $text = 'a little too sitted';
                }
                $message = 'Hello ' . $user['user_name'] . ',<br>your account <b>now</b> for <b>one day</b> can not be sitted, because within the last 24 hours it was <b>' . $text . '</ b>.<br>This message was automatically generated, complaints to the STFC2 team bring nothing.<br>~Automatic Abuse Sitting';
                $title = 'Sitting locked';
                break;
        }
        SystemMessage($user['user_id'], $title, $message);
        $sql = 'UPDATE user SET num_sitting=-1 WHERE user_id=' . $user['user_id'];
        if (!$db->query($sql)) {
            $sdl->log('<b>Error:</b> cannot lock sitting for user ID ' . $user['user_id'] . '!');
        }
        $sdl->log('User sitting locked: ID ' . $user['user_id'] . ' Name: ' . $user['user_name'] . ' Abuse: ' . $val);
    }
}
$sdl->finish_job('Sitting abuse check');
// #######################################################################################
// #######################################################################################
// Create or update galaxy map image
$sdl->start_job('Create galaxy map');
$maps = new maps();
$maps->create_galaxy_detail_map();
if (($destimg = ImageCreateTrueColor(150, 150)) === false) {
    function _action_main()
    {
        // #############################################################################
        // Data from the attacker
        /*        
        $sql = 'SELECT '.$this->get_combat_query_fleet_columns().', f.resource_4, f.unit_1, f.unit_2, f.unit_3, f.unit_4
               FROM (ship_fleets f)
               INNER JOIN user u ON u.user_id = f.user_id
               INNER JOIN ships ON ships
               WHERE f.fleet_id IN ('.$this->fleet_ids_str.')';
        */
        $sql = 'SELECT ' . $this->get_combat_query_fleet_columns() . ',
		SUM(s.unit_1 - st.min_unit_1) AS unit_1,
                SUM(s.unit_2 - st.min_unit_2) AS unit_2,
                SUM(s.unit_3 - st.min_unit_3) AS unit_3,
                SUM(s.unit_4 - st.min_unit_4) AS unit_4
        FROM (ship_fleets f)
        INNER JOIN user u ON u.user_id = f.user_id
        INNER JOIN ships s USING (fleet_id)
        INNER JOIN ship_templates st ON s.template_id = st.id
        WHERE f.fleet_id IN (' . $this->fleet_ids_str . ')';
        if (($atk_fleets = $this->db->queryrowset($sql)) === false) {
            return $this->log(MV_M_DATABASE, 'Could not query attackers fleets data! SKIP');
        }
        // #############################################################################
        // Data from the defender
        $sql = 'SELECT DISTINCT f.user_id,
               u.user_alliance,
               ud.ud_id, ud.accepted,
               ad.ad_id, ad.type, ad.status
        FROM (ship_fleets f)
        INNER JOIN user u ON u.user_id = f.user_id
        LEFT JOIN user_diplomacy ud ON ( ( ud.user1_id = ' . $this->dest['user_id'] . ' AND ud.user2_id = f.user_id ) OR ( ud.user1_id = f.user_id AND ud.user2_id = ' . $this->dest['user_id'] . ' ) )
        LEFT JOIN alliance_diplomacy ad ON ( ( ad.alliance1_id = ' . $this->dest['user_alliance'] . ' AND ad.alliance2_id = u.user_alliance) OR ( ad.alliance1_id = u.user_alliance AND ad.alliance2_id = ' . $this->dest['user_alliance'] . ' ) )
        WHERE f.planet_id = ' . $this->move['dest'] . ' AND
              f.user_id <> ' . $this->dest['user_id'] . ' AND
              f.user_id <> ' . $this->move['user_id'] . ' AND
              f.alert_phase >= ' . ALERT_PHASE_YELLOW;
        if (!($q_st_uid = $this->db->query($sql))) {
            return $this->log(MV_M_DATABASE, 'Could not query stationated fleets user data! SKIP');
        }
        $st_user = array();
        while ($st_uid = $this->db->fetchrow($q_st_uid)) {
            $allied = false;
            if ($st_uid['user_alliance'] == $this->dest['user_alliance']) {
                $allied = true;
            }
            if (!empty($st_uid['ud_id'])) {
                if ($st_uid['accepted'] == 1) {
                    $allied = true;
                }
            }
            if (!empty($st_uid['ad_id'])) {
                if ($st_uid['type'] == ALLIANCE_DIPLOMACY_PACT && $st_uid['status'] == 0) {
                    $allied = true;
                }
            }
            if ($allied) {
                $st_user[] = $st_uid['user_id'];
            }
        }
        $n_st_user = count($st_user);
        if ($n_st_user > 0) {
            $sql = 'SELECT ' . $this->get_combat_query_fleet_columns() . '
             FROM (ship_fleets f)
             INNER JOIN user u ON u.user_id = f.user_id
             WHERE f.planet_id = ' . $this->move['dest'] . ' AND
                   (
                     (
                       f.user_id = ' . $this->dest['user_id'] . '
                     )
                     OR
                     (
                       f.user_id IN (' . implode(',', $st_user) . ') AND
                       f.alert_phase >= ' . ALERT_PHASE_YELLOW . '
                     )
                   )';
        } else {
            $sql = 'SELECT ' . $this->get_combat_query_fleet_columns() . '
             FROM (ship_fleets f)
             INNER JOIN user u ON u.user_id = f.user_id
             WHERE f.planet_id = ' . $this->move['dest'] . ' AND
                   f.user_id = ' . $this->dest['user_id'];
        }
        if (($dfd_fleets = $this->db->queryrowset($sql)) === false) {
            return $this->log(MV_M_DATABASE, 'Could not query defenders fleets data! SKIP');
        }
        $dfd_fleet_ids = array();
        foreach ($dfd_fleets as $i => $cur_fleet) {
            $dfd_fleet_ids[] = $cur_fleet['fleet_id'];
        }
        $dfd_fleet_ids_str = implode(',', $dfd_fleet_ids);
        if ($this->do_ship_combat($this->fleet_ids_str, $dfd_fleet_ids_str, MV_COMBAT_LEVEL_PLANETARY) == MV_EXEC_ERROR) {
            $this->log(MV_M_DATABASE, 'Move Action 46: Something went wrong with this fight!');
            return MV_EXEC_ERROR;
        }
        // #############################################################################
        // If the attacker has won attempt to start takeover
        // #############################################################################
        // 03/04/08 - AC: Retrieve player language
        switch ($this->dest['language']) {
            case 'GER':
                $dfd_title = 'Angriff der Borg auf ' . $this->dest['planet_name'];
                break;
            case 'ITA':
                $dfd_title = 'Attacco Borg su ' . $this->dest['planet_name'];
                break;
            default:
                $dfd_title = 'Borg attack on ' . $this->dest['planet_name'];
                break;
        }
        $action_status = 0;
        /* 11/07/08 - AC: Initialize here arrays atk/dfd_losses */
        $atk_losses = array(0, 0, 0, 0, 0);
        $dfd_losses = array(0, 0, 0, 0, 0);
        if ($this->cmb[MV_CMB_WINNER] == MV_CMB_ATTACKER) {
            $atk_units = array(0, 0, 0, 0, 0);
            // 20/06/08 - AC: Borg as no "workers"
            for ($i = 0; $i < count($atk_fleets); ++$i) {
                $atk_units[0] += $atk_fleets[$i]['unit_1'];
                $atk_units[1] += $atk_fleets[$i]['unit_2'];
                $atk_units[2] += $atk_fleets[$i]['unit_3'];
                $atk_units[3] += $atk_fleets[$i]['unit_4'];
            }
            $dfd_units = array($this->dest['unit_1'], $this->dest['unit_2'], $this->dest['unit_3'], $this->dest['unit_4'], $this->dest['resource_4']);
            // Are there some defenders?
            if (array_sum($dfd_units) > 0) {
                $ucmb = UnitFight($atk_units, $this->move['user_race'], $dfd_units, $this->dest['user_race'], $this->mid);
                $n_atk_alive = array_sum($ucmb[0]);
                $atk_alive = $ucmb[0];
                $dfd_alive = $ucmb[1];
            } else {
                $n_atk_alive = 1;
                $atk_alive = $atk_units;
                $dfd_alive = array(0, 0, 0, 0, 0);
            }
            // 01/07/08 - AC: Count losses for each part
            for ($i = 0; $i < 5; ++$i) {
                $atk_losses[$i] = $atk_units[$i] - $atk_alive[$i];
                $dfd_losses[$i] = $dfd_units[$i] - $dfd_alive[$i];
            }
            // If there are no more attackers, the defender
            // always won even if the defending had no units
            if ($n_atk_alive == 0) {
                // In order to eliminate the troops of the aggressor, simply reset all transporters
                // 21/06/08 - AC: Keep out workers from battle!
                $sql = 'UPDATE ships
                INNER JOIN ship_templates ON ships.template_id = ship_templates.id
                        SET unit_1 = ship_templates.min_unit_1,
                        unit_2 = ship_templates.min_unit_2,
                        unit_3 = ship_templates.min_unit_3,
                        unit_4 = ship_templates.min_unit_4
                WHERE fleet_id IN (' . $this->fleet_ids_str . ')';
                if (!$this->db->query($sql)) {
                    return $this->log(MV_M_DATABASE, 'Could not update ship fleets unit transport data! SKIP');
                }
                // Simply update the defender troops
                $sql = 'UPDATE planets
                SET unit_1 = ' . $ucmb[1][0] . ',
                    unit_2 = ' . $ucmb[1][1] . ',
                    unit_3 = ' . $ucmb[1][2] . ',
                    unit_4 = ' . $ucmb[1][3] . ',
                    resource_4 = ' . $ucmb[1][4] . '
                WHERE planet_id = ' . $this->move['dest'];
                if (!$this->db->query($sql)) {
                    return $this->log(MV_M_DATABASE, 'Could not update dest planet units data! SKIP');
                }
                $action_status = -1;
                // #############################################################################
                // 03/04/08 - AC: Retrieve player language
                switch ($this->move['language']) {
                    case 'GER':
                        $atk_title = 'Angriff auf ' . $this->dest['planet_name'] . ' teilweise erfolgreich';
                        break;
                    case 'ITA':
                        $atk_title = 'Attacco su ' . $this->dest['planet_name'] . ' parzialmente riuscito';
                        break;
                    default:
                        $atk_title = 'Attack on ' . $this->dest['planet_name'] . ' partially successful';
                        break;
                }
            } else {
                account_log($this->move['user_id'], $this->dest['user_id'], 4);
                // Export a ruler switch
                // We need the number of planets, which owns the colonizing
                // (we want planet_owner_enum degree of certainty)
                $sql = 'SELECT COUNT(planet_id) AS n_planets
                FROM planets
                WHERE planet_owner = ' . $this->move['user_id'];
                if (($pcount = $this->db->queryrow($sql)) === false) {
                    $this->log(MV_M_DATABASE, 'Could not query planets count data! CONTINUE AND USE INSTABLE VALUE');
                    $n_planets = $this->move['user_planets'];
                } else {
                    $n_planets = $pcount['n_planets'];
                }
                // We accommodate as much troops, as on the colony ship were, on the planet
                $planet_units = array(0, 0, 0, 0);
                // 25/06/08 - AC: Check available space on target planet
                $sql = 'SELECT max_units FROM planets WHERE planet_id = ' . $this->move['dest'];
                if (($plspace = $this->db->queryrow($sql)) === false) {
                    $this->log(MV_M_DATABASE, 'Could not query planet max units data! CONTINUE AND USE INSTABLE VALUE');
                    $plspace['max_units'] = 1300;
                    // Minimum size available
                }
                if ($atk_alive[0] * 2 + $atk_alive[1] * 3 + $atk_alive[2] * 4 + $atk_alive[3] * 4 > $plspace['max_units']) {
                    $this->log(MV_M_NOTICE, 'Alive units exceed planet maximum units, we need to recall aboard the surplus');
                    // AC: Recall aboard the surplus troops
                    $i = 0;
                    while ($n_atk_alive) {
                        if ($planet_units[0] * 2 + $planet_units[1] * 3 + $planet_units[2] * 4 + $planet_units[3] * 4 >= $plspace['max_units']) {
                            break;
                        }
                        if ($atk_alive[$i] > 0) {
                            $planet_units[$i]++;
                            $atk_alive[$i]--;
                            $n_atk_alive--;
                        } else {
                            $i++;
                        }
                    }
                    // Borg doesn't have cargo, simply use the Cube
                    /*
                                $sql = 'UPDATE ship_fleets
                           SET unit_1 = '.$atk_alive[0].',
                               unit_2 = '.$atk_alive[1].',
                               unit_3 = '.$atk_alive[2].',
                               unit_4 = '.$atk_alive[3].'
                           WHERE fleet_id = '.$this->fleet_ids_str;
                    
                                if(!$this->db->query($sql)) {
                       $this->log(MV_M_DATABASE, 'Could not update fleets units data! CONTINUE');
                                }
                    * 
                    */
                } else {
                    for ($i = 0; $i <= 3; ++$i) {
                        $planet_units[$i] += $atk_alive[$i];
                    }
                    /*
                                $sql = 'UPDATE ship_fleets
                           SET unit_1 = 0,
                               unit_2 = 0,
                               unit_3 = 0,
                               unit_4 = 0
                           WHERE fleet_id IN ('.$this->fleet_ids_str.')';
                    
                                if(!$this->db->query($sql)) {
                       return $this->log(MV_M_DATABASE, 'Could not update ship fleets unit transport data! SKIP');
                                }
                    * 
                    */
                }
                $sql = 'DELETE FROM scheduler_instbuild
                WHERE planet_id = ' . $this->move['dest'];
                if (!$this->db->query($sql)) {
                    $this->log(MV_M_DATABASE, 'Could not delete scheduler instbuild data! CONTINUE');
                }
                $sql = 'DELETE FROM scheduler_research
                WHERE planet_id = ' . $this->move['dest'];
                if (!$this->db->query($sql)) {
                    $this->log(MV_M_DATABASE, 'Could not delete scheduler research data! CONTINUE');
                }
                global $NUM_BUILDING, $MAX_BUILDING_LVL;
                // As someone yes number == max_index sets
                $n_buildings = $NUM_BUILDING + 1;
                $building_levels = array();
                $building_damage = 0.01 * mt_rand(40, 60);
                // Set new home world
                if ($this->move['dest'] == $this->dest['user_capital']) {
                    for ($i = 0; $i < $n_buildings; ++$i) {
                        $j = $i + 1;
                        $building_levels[$i] = (int) ($this->dest['building_' . $j] > $MAX_BUILDING_LVL[0][$i]) ? $MAX_BUILDING_LVL[0][$i] : round($this->dest['building_' . $j] * $building_damage, 0);
                    }
                    if ($this->dest['user_planets'] == 1) {
                        // #############################################################################
                        // 03/04/08 - AC: Retrieve player language
                        switch ($this->dest['language']) {
                            case 'GER':
                                $msg_title = 'Verlust aller deiner Planeten';
                                $msg_body = 'Da du alle deine Planeten verloren hast, wurde f&uuml;r dich ein neuer Planet an einer zuf&uuml;ligen Stelle der Galaxie erstellt.';
                                break;
                            case 'ITA':
                                $msg_title = 'Perdita di tutti i pianeti';
                                $msg_body = 'Dato che hai perduto tutti i pianeti ne &egrave; stato creato uno nuovo nella galassia.';
                                break;
                            default:
                                $msg_title = 'Loss of all your planets';
                                $msg_body = 'Since you lost all your planets a new one have been created in the body of the galaxy.';
                                break;
                        }
                        SystemMessage($this->dest['user_id'], $msg_title, $msg_body);
                    } else {
                        if (!$this->db->query('SET @i=0')) {
                            return $this->log(MV_M_DATABASE, 'Could not set sql iterator variable for planet owner enum! SKIP');
                        }
                        $sql = 'UPDATE planets
                        SET planet_owner_enum = (@i := (@i + 1))-1
                        WHERE planet_owner = ' . $this->dest['user_id'] . '
                        ORDER BY planet_owned_date ASC, planet_id ASC';
                        if (!$this->db->query($sql)) {
                            return $this->log(MV_M_DATABASE, 'Could not update planet owner enum data! SKIP');
                        }
                        $sql = 'SELECT planet_id
                        FROM planets
                        WHERE planet_owner = ' . $this->dest['user_id'] . '
                        ORDER BY planet_owner_enum ASC
                        LIMIT 1';
                        if (($first_planet = $this->db->queryrow($sql)) === false) {
                            return $this->log(MV_M_DATABASE, 'Could not query first planet data! SKIP');
                        }
                        $sql = 'UPDATE user
                        SET last_active = ' . time() . ',
                            last_ip = "0.0.0.0",
                            user_capital = ' . $first_planet['planet_id'] . ',
                            pending_capital_choice = 1
                        WHERE user_id = ' . $this->dest['user_id'];
                        if (!$this->db->query($sql)) {
                            return $this->log(MV_M_DATABASE, 'Could not update user capital data! SKIP');
                        }
                    }
                } else {
                    for ($i = 0; $i < $n_buildings; ++$i) {
                        $building_levels[$i] = round($this->dest['building_' . ($i + 1)] * $building_damage, 0);
                    }
                }
                $sql = 'DELETE FROM resource_trade
                WHERE planet = ' . $this->move['dest'];
                if (!$this->db->query($sql)) {
                    $this->log(MV_M_DATABASE, 'Could not delete resource trade data! CONTINUE');
                }
                $sql = 'SELECT ship_id
                FROM ship_trade
                WHERE scheduler_processed = 0 AND
                      planet = ' . $this->move['dest'];
                if (!($q_shipt = $this->db->query($sql))) {
                    $this->log(MV_M_DATABASE, 'Could not query ship trade data! CONTINUE');
                } else {
                    $ship_ids = array();
                    while ($_ship = $this->db->fetchrow($q_shipt)) {
                        $ship_ids[] = $_ship['ship_id'];
                    }
                    if (count($ship_ids) > 0) {
                        $sql = 'UPDATE ships
                        SET ship_untouchable = 0
                        WHERE ship_id IN (' . implode(',', $ship_ids) . ')';
                        if (!$this->db->query($sql)) {
                            $this->log(MV_M_DATABASE, 'Could not update ships untouchable data! CONTINUE');
                        }
                    }
                }
                $sql = 'DELETE FROM ship_trade
                WHERE scheduler_processed = 0 AND
                      planet = ' . $this->move['dest'];
                if (!$this->db->query($sql)) {
                    $this->log(MV_M_DATABASE, 'Could not delete ship trade data! CONTINUE');
                }
                $sql = 'DELETE FROM scheduler_shipbuild WHERE planet_id = ' . $this->move['dest'];
                if (!$this->db->query($sql)) {
                    $this->log(MV_M_DATABASE, 'Could not delete ship building queue! CONTINUE');
                }
                if ($this->dest['planet_type'] == "m" || $this->dest['planet_type'] == "o" || $this->dest['planet_type'] == "p" || $this->dest['planet_type'] == "x" || $this->dest['planet_type'] == "y" || $this->dest['planet_type'] == "f" || $this->dest['planet_type'] == "g") {
                    $def_tech_lev = 9;
                } else {
                    $def_tech_lev = 6;
                }
                $sql = 'UPDATE planets
                SET planet_owner = ' . $this->move['user_id'] . ',
                    planet_name = "Unimatrix #' . $this->move['dest'] . '",
                    best_mood = 0,
                    best_mood_user = 0,
                    planet_owned_date = ' . time() . ',
                    planet_owner_enum = ' . ($n_planets - 1) . ',
                    resource_4 = ' . $ucmb[1][4] . ',
                    planet_next_attack = 0,
                    planet_attack_ships = 0,
                    planet_attack_type = 0,
                    research_3 = ' . $def_tech_lev . ',
                    research_4 = ' . $def_tech_lev . ',
                    research_5 = ' . $def_tech_lev . ',
                    recompute_static = 1,
                    building_1 = 9,
                    building_2 = ' . $building_levels[1] . ',
                    building_3 = ' . $building_levels[2] . ',
                    building_4 = ' . $building_levels[3] . ',
                    building_5 = 9,
                    building_6 = 9,
                    building_7 = ' . $building_levels[6] . ',
                    building_8 = ' . $building_levels[7] . ',
                    building_9 = ' . $building_levels[8] . ',
                    building_10 = ' . $building_levels[9] . ',
                    building_11 = ' . $building_levels[10] . ',
                    building_12 = ' . $building_levels[11] . ',
                    building_13 = ' . $building_levels[12] . ',
                    unit_1 = ' . $planet_units[0] . ',
                    unit_2 = ' . $planet_units[1] . ',
                    unit_3 = ' . $planet_units[2] . ',
                    unit_4 = ' . $planet_units[3] . ',
                    unit_5 = 0,
                    unit_6 = 0,
                    workermine_1 = 100,
                    workermine_2 = 100,
                    workermine_3 = 100,
                    catresearch_1 = 0,
                    catresearch_2 = 0,
                    catresearch_3 = 0,
                    catresearch_4 = 0,
                    catresearch_5 = 0,
                    catresearch_6 = 0,
                    catresearch_7 = 0,
                    catresearch_8 = 0,
                    catresearch_9 = 0,
                    catresearch_10 = 0,
                    unittrainid_1 = 0, unittrainid_2 = 0, unittrainid_3 = 0, unittrainid_4 = 0, unittrainid_5 = 0, unittrainid_6 = 0, unittrainid_7 = 0, unittrainid_8 = 0, unittrainid_9 = 0, unittrainid_10 = 0, 
                    unittrainnumber_1 = 0, unittrainnumber_2 = 0, unittrainnumber_3 = 0, unittrainnumber_4 = 0, unittrainnumber_5 = 0, unittrainnumber_6 = 0, unittrainnumber_7 = 0, unittrainnumber_8 = 0, unittrainnumber_9 = 0, unittrainnumber_10 = 0, 
                    unittrainnumberleft_1 = 0, unittrainnumberleft_2 = 0, unittrainnumberleft_3 = 0, unittrainnumberleft_4 = 0, unittrainnumberleft_5 = 0, unittrainnumberleft_6 = 0, unittrainnumberleft_7 = 0, unittrainnumberleft_8 = 0, unittrainnumberleft_9 = 0, unittrainnumberleft_10 = 0, 
                    unittrainendless_1 = 0, unittrainendless_2 = 0, unittrainendless_3 = 0, unittrainendless_4 = 0, unittrainendless_5 = 0, unittrainendless_6 = 0, unittrainendless_7 = 0, unittrainendless_8 = 0, unittrainendless_9 = 0, unittrainendless_10 = 0, 
                    unittrain_actual = 0,
                    unittrainid_nexttime=0,
                    planet_insurrection_time=0
                WHERE planet_id = ' . $this->move['dest'];
                if (!$this->db->query($sql)) {
                    return $this->log(MV_M_DATABASE, 'Could not update planets data! SKIP');
                }
                // DC >>>> Historycal record in planet_details, with label '29'
                $sql = 'INSERT INTO planet_details (planet_id, user_id, alliance_id, source_uid, source_aid, timestamp, log_code, defeat_uid, defeat_aid)
                VALUES (' . $this->move['dest'] . ', 0, 0, 0, 0, ' . time() . ', 29,' . $this->dest['user_id'] . ', ' . $this->dest['user_alliance'] . ')';
                if (!$this->db->query($sql)) {
                    $this->log(MV_M_DATABASE, 'Could not update planet details data! CONTINUE');
                }
                // DC <<<<
                // DC >>>> Update borg_target table; the $this->dest['user_id'] entry may not exists, so do not check error
                $sql = 'UPDATE borg_target SET battle_lost = battle_lost + 1,
                                       planets_back = planets_back + 1,
                                       under_attack = under_attack - 1
                WHERE user_id = ' . $this->dest['user_id'];
                $this->db->query($sql);
                // DC <<<<
                // DC >>>>
                $sql = 'DELETE FROM borg_npc_target WHERE planet_id = ' . $this->move['dest'];
                $this->db->query($sql);
                $sql = 'UPDATE scheduler_shipmovement SET action_code = 11
                WHERE action_code = 46 AND move_id <> ' . $this->mid . '
                AND move_status = 0 AND user_id = ' . BORG_USERID . ' AND dest = ' . $this->move['dest'];
                $this->db->query($sql);
                // DC <<<<
                // DC >>>> Settlers management
                if ($this->dest['user_id'] == INDEPENDENT_USERID) {
                    $sql = 'SELECT sr.user_id, u.language FROM settlers_relations sr
                    LEFT JOIN user u ON u.user_id = sr.user_id
                    WHERE planet_id = ' . $this->move['dest'] . ' GROUP BY sr.user_id';
                    if ($m_u_q = $this->db->queryrowset($sql)) {
                        foreach ($m_u_q as $m_u) {
                            $log_data = array($this->move['dest'], $this->dest['planet_name'], 0, '', 103);
                            switch ($m_u['language']) {
                                case 'GER':
                                    $log_title = 'Automatic distress message from ';
                                    break;
                                case 'ITA':
                                    $log_title = 'Richiesta automatica di soccorso dalla colonia ';
                                    break;
                                default:
                                    $log_title = 'Automatic distress message from ';
                                    break;
                            }
                            add_logbook_entry($m_u['user_id'], LOGBOOK_SETTLERS, $log_title . $this->dest['planet_name'], $log_data);
                        }
                        $sql = 'DELETE FROM settlers_relations WHERE planet_id = ' . $this->move['dest'];
                        $this->db->query($sql);
                    }
                }
                // DC <<<< Settlers management
                if (!$this->db->query('SET @i=0')) {
                    return $this->log(MV_M_DATABASE, 'Could not set sql iterator variable for planet owner enum (the invading player)! SKIP');
                }
                $sql = 'UPDATE planets
                SET planet_owner_enum = (@i := (@i + 1))-1
                WHERE planet_owner = ' . $this->move['user_id'] . '
                ORDER BY planet_owned_date ASC, planet_id ASC';
                if (!$this->db->query($sql)) {
                    return $this->log(MV_M_DATABASE, 'Could not update planet owner enum data (the invading player)! SKIP');
                }
                $sql = 'UPDATE ships
                SET user_id = ' . $this->move['user_id'] . '
                WHERE fleet_id = -' . $this->move['dest'];
                if (!$this->db->query($sql)) {
                    return $this->log(MV_M_DATABASE, 'Could not update ships location data! SKIP');
                }
                $action_status = 1;
                // #############################################################################
                // 03/04/08 - AC: Retrieve player language
                switch ($this->move['language']) {
                    case 'GER':
                        $atk_title = 'Angriff auf ' . $this->dest['planet_name'] . ' erfolgreich';
                        break;
                    case 'ITA':
                        $atk_title = 'Attacco su ' . $this->dest['planet_name'] . ' riuscito';
                        break;
                    default:
                        $atk_title = 'Attack on ' . $this->dest['planet_name'] . ' successful';
                        break;
                }
            }
            // DC >>>>
            if ($this->dest['user_id'] == INDEPENDENT_USERID) {
                $sql = 'SELECT sr.user_id, u.language FROM settlers_relations sr
                LEFT JOIN user u ON u.user_id = sr.user_id
                WHERE planet_id = ' . $this->move['dest'] . ' GROUP BY sr.user_id';
                if ($m_u_q = $this->db->queryrowset($sql)) {
                    foreach ($m_u_q as $m_u) {
                        $log_data = array($this->move['dest'], $this->dest['planet_name'], 0, '', 104);
                        switch ($m_u['language']) {
                            case 'GER':
                                $log_title = 'Distress call from ';
                                break;
                            case 'ITA':
                                $log_title = 'Richiesta di soccorso dalla colonia ';
                                break;
                            default:
                                $log_title = 'Distress call from ';
                                break;
                        }
                        add_logbook_entry($m_u['user_id'], LOGBOOK_SETTLERS, $log_title . $this->dest['planet_name'], $log_data);
                    }
                }
            }
            // DC <<<<
            $sql = 'UPDATE ship_fleets
            SET planet_id = ' . $this->move['dest'] . ',
                move_id = 0
            WHERE fleet_id IN (' . $this->fleet_ids_str . ')';
            if (!$this->db->query($sql)) {
                // Here one could also report and then go on
                return $this->log(MV_M_DATABASE, 'Could not update fleets location data! SKIP');
            }
        } else {
            // #############################################################################
            // 03/04/08 - AC: Retrieve player language
            switch ($this->move['language']) {
                case 'GER':
                    $atk_title = 'Angriff auf ' . $this->dest['planet_name'] . ' fehlgeschlagen';
                    break;
                case 'ITA':
                    $atk_title = 'Attacco su ' . $this->dest['planet_name'] . ' fallito';
                    break;
                default:
                    $atk_title = 'Attack on ' . $this->dest['planet_name'] . ' failed';
                    break;
            }
            // DC >>>> Begin Borg Adaption Phase!!!
            $adaption_chance_array = array('no_event' => 90, 'adapt_PRI' => 13, 'adapt_SEC' => 12, 'adapt_SHI' => 7, 'adapt_ARM' => 9, 'adapt_REA' => 4, 'adapt_RED' => 5, 'adapt_AGI' => 3, 'adapt_ROF' => 4, 'adapt_ROF2' => 2);
            $adaption_array = array();
            foreach ($adaption_chance_array as $event => $probability) {
                for ($i = 0; $i < $probability; ++$i) {
                    $adaption_array[] = $event;
                }
            }
            $adaption_event = $adaption_array[array_rand($adaption_array)];
            if ($adaption_event == 'no_event') {
                $this->log(MV_M_NOTICE, 'Borg Adaption Phase not occured this time.');
            } else {
                $this->log(MV_M_NOTICE, 'Borg Adaption Phase begin NOW.');
                $borg_bot = $this->db->queryrow('SELECT ship_template2 FROM borg_bot WHERE id = 1');
                $borgcube_tp = $this->db->queryrow('SELECT * FROM ship_templates WHERE owner = ' . BORG_USERID . ' AND id = ' . $borg_bot['ship_template2']);
                $newvalue1 = $borgcube_tp['value_1'];
                $newvalue2 = $borgcube_tp['value_2'];
                $newvalue4 = $borgcube_tp['value_4'];
                $newvalue5 = $borgcube_tp['value_5'];
                $newvalue6 = $borgcube_tp['value_6'];
                $newvalue7 = $borgcube_tp['value_7'];
                $newvalue8 = $borgcube_tp['value_8'];
                $newrof = $borgcube_tp['rof'];
                $newrof2 = $borgcube_tp['rof2'];
                switch ($adaption_event) {
                    case 'adapt_PRI':
                        $newvalue1 = $newvalue1 * 1.015;
                        $this->log(MV_M_NOTICE, 'Borg Primary Attack Value ++.');
                        break;
                    case 'adapt_SEC':
                        $newvalue2 = $newvalue2 * 1.015;
                        $this->log(MV_M_NOTICE, 'Borg Secondary Attack Value ++.');
                        break;
                    case 'adapt_SHI':
                        $newvalue4 = $newvalue4 * 1.025;
                        $this->log(MV_M_NOTICE, 'Borg Armor Value ++.');
                        break;
                    case 'adapt_ARM':
                        $newvalue5 = $newvalue5 * 1.02;
                        $this->log(MV_M_NOTICE, 'Borg Shield Value ++.');
                        break;
                    case 'adapt_REA':
                        $newvalue6 = $newvalue6 + 1;
                        $this->log(MV_M_NOTICE, 'Borg Reaction Value ++.');
                        break;
                    case 'adapt_RED':
                        $newvalue7 = $newvalue7 + 1;
                        $this->log(MV_M_NOTICE, 'Borg Readiness Value ++.');
                        break;
                    case 'adapt_AGI':
                        $newvalue8 = $newvalue8 + 1;
                        $this->log(MV_M_NOTICE, 'Borg Agility Value ++.');
                        break;
                    case 'adapt_ROF':
                        $newrof = $newrof + 1;
                        $this->log(MV_M_NOTICE, '+++ Borg ROF Value +++.');
                        break;
                    case 'adapt_ROF2':
                        $newrof2 = $newrof2 + 1;
                        $this->log(MV_M_NOTICE, '+++ Borg ROF2 Value +++.');
                        break;
                }
                $oldversion = 0;
                sscanf($borgcube_tp['name'], "Adapted Cube#%u", $oldversion);
                $sql = 'INSERT INTO ship_templates (owner, timestamp, name, description, race, ship_torso, ship_class,
                                                component_1, component_2, component_3, component_4, component_5,
                                                component_6, component_7, component_8, component_9, component_10,
                                                value_1, value_2, value_3, value_4, value_5,
                                                value_6, value_7, value_8, value_9, value_10,
                                                value_11, value_12, value_13, value_14, value_15,
                                                resource_1, resource_2, resource_3, resource_4, unit_5, unit_6,
                                                min_unit_1, min_unit_2, min_unit_3, min_unit_4,
                                                max_unit_1, max_unit_2, max_unit_3, max_unit_4,
                                                buildtime, rof, rof2, max_torp)
                VALUES ("' . $borgcube_tp['owner'] . '","' . time() . '","Adapted Cube#' . ($oldversion + 1) . '","Assimilation ship","' . $borgcube_tp['race'] . '",9,3,
                            -1,-1,-1,-1,-1,
                            -1,-1,-1,-1,-1,
                            "' . $newvalue1 . '","' . $newvalue2 . '","140","' . $newvalue4 . '","' . $newvalue5 . '",
                            "' . $newvalue6 . '","' . $newvalue7 . '","' . $newvalue8 . '","50","10",
                            "42","0","300","300","0",
                            "500000","500000","500000","50000","39","16",
                            "294","0","0","6",
                            "9294","6000","3000","6",
                            0, ' . $newrof . ', ' . $newrof2 . ', 1000)';
                $this->db->query($sql);
                $newtpid = $this->db->insert_id();
                $this->db->query('UPDATE borg_bot SET ship_template2 = ' . $newtpid . ' WHERE id = 1 ');
                $this->log(MV_M_NOTICE, 'Borg Adaption Phase ends NOW.');
            }
            // DC <<<< End Borg Adaption Phase
            // DC >>>> Settlers management
            if ($this->dest['user_id'] == INDEPENDENT_USERID) {
                // Check for defenders
                if ($n_st_user > 0) {
                    $sql = 'SELECT user_id from borg_target WHERE user_id IN (' . implode(",", $st_user) . ')';
                    if (!($def_q = $this->db->query($sql))) {
                        $this->log(MV_M_DATABASE, 'Could not query borg_target data! ' . $sql);
                    }
                    $num_row = $this->db->num_rows($def_q);
                    if ($num_row > 0) {
                        // Update priority of this planet!!!
                        $sql = 'UPDATE borg_npc_target SET priority = priority + ' . 10 * $num_row . ' WHERE planet_id = ' . $this->move['dest'];
                        if (!$this->db->query($sql)) {
                            $this->log(MV_M_DATABASE, 'Could not update borg_npc_target data! ' . $sql);
                        }
                        $def_i_q = $this->db->fetchrowset($def_q);
                        foreach ($def_i_q as $item_def_q) {
                            $sql = 'UPDATE borg_target SET battle_win = battle_win + 1 WHERE user_id = ' . $item_def_q['user_id'];
                            if (!$this->db->query($sql)) {
                                $this->log(MV_M_DATABASE, 'Could not update borg_target data! ' . $sql);
                            }
                        }
                    }
                }
                $sql = 'UPDATE borg_npc_target SET tries = tries + 1,
                                           live_attack = live_attack - 1 
                WHERE planet_id = ' . $this->move['dest'];
                $this->db->query($sql);
                $sql = 'SELECT sr.user_id, u.language FROM settlers_relations sr
                LEFT JOIN user u ON u.user_id = sr.user_id
                WHERE planet_id = ' . $this->move['dest'] . ' GROUP BY sr.user_id';
                if ($m_u_q = $this->db->queryrowset($sql)) {
                    foreach ($m_u_q as $m_u) {
                        $log_data = array($this->move['dest'], $this->dest['planet_name'], 0, '', 104);
                        switch ($m_u['language']) {
                            case 'GER':
                                $log_title = 'Distress call from ';
                                break;
                            case 'ITA':
                                $log_title = 'Richiesta di soccorso dalla colonia ';
                                break;
                            default:
                                $log_title = 'Distress call from ';
                                break;
                        }
                        add_logbook_entry($m_u['user_id'], LOGBOOK_SETTLERS, $log_title . $this->dest['planet_name'], $log_data);
                    }
                }
            }
            // DC <<<< Settlers management
            // 01/07/08 - The attacker has lost the fleets
            for ($i = 0; $i < count($atk_fleets); ++$i) {
                $atk_losses[0] += $atk_fleets[$i]['unit_1'];
                $atk_losses[1] += $atk_fleets[$i]['unit_2'];
                $atk_losses[2] += $atk_fleets[$i]['unit_3'];
                $atk_losses[3] += $atk_fleets[$i]['unit_4'];
                $atk_losses[4] += $atk_fleets[$i]['resource_4'];
            }
        }
        // #############################################################################
        // Write logbook
        $log1_data = array(46, $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'], MV_CMB_ATTACKER, $this->cmb[MV_CMB_WINNER] == MV_CMB_ATTACKER ? 1 : 0, 0, 0, $atk_fleets, $dfd_fleets);
        $log2_data = array(46, $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'], MV_CMB_DEFENDER, $this->cmb[MV_CMB_WINNER] == MV_CMB_DEFENDER ? 1 : 0, 0, 0, $atk_fleets, $dfd_fleets);
        $log1_data[17] = $log2_data[17] = $action_status;
        $log1_data[20] = $this->dest['user_race'];
        $log2_data[20] = $this->move['user_race'];
        for ($i = 0; $i < 5; ++$i) {
            $log1_data[18][$i] = $log2_data[19][$i] = $atk_losses[$i];
            $log1_data[19][$i] = $log2_data[18][$i] = $dfd_losses[$i];
        }
        //$log1_data[19][4] = $log2_data[18][4] = (int)$dfd_losses[4]; already done by for above...
        $log2_data[14] = $this->cmb[MV_CMB_KILLS_PLANETARY];
        $log1_data[10] = $this->cmb[MV_CMB_KILLS_EXT];
        $log2_data[10] = $this->cmb[MV_CMB_KILLS_EXT];
        add_logbook_entry($this->move['user_id'], LOGBOOK_TACTICAL, $atk_title, $log1_data);
        add_logbook_entry($this->dest['user_id'], LOGBOOK_TACTICAL, $dfd_title, $log2_data);
        if ($n_st_user > 0) {
            $log2_data[2] = $this->move['dest'];
            $log2_data[3] = $this->dest['planet_name'];
            $log2_data[4] = $this->dest['user_id'];
            $log2_data[5] = 0;
            $log2_data[6] = 0;
            $log2_data[7] = 0;
            $log2_data[16] = 1;
            for ($i = 0; $i < $n_st_user; ++$i) {
                // #############################################################################
                // 03/04/08 - AC: Retrieve player language
                $log_title = 'One of your allies defended ' . $this->dest['planet_name'];
                $sql = 'SELECT language FROM user WHERE user_id = ' . $st_user[$i];
                if (!($lang = $this->db->queryrow($sql))) {
                    $this->log(MV_M_DATABASE, 'Could not retrieve player language');
                } else {
                    switch ($lang['language']) {
                        case 'GER':
                            $log_title = 'Verb&uuml;ndeten bei ' . $this->dest['planet_name'] . ' verteidigt';
                            break;
                        case 'ENG':
                            $log_title = 'Joined the defenders of the ' . $this->dest['planet_name'] . ' planet';
                            break;
                        case 'ITA':
                            $log_title = 'Difesa alleata presso ' . $this->dest['planet_name'];
                            break;
                    }
                }
                add_logbook_entry($st_user[$i], LOGBOOK_TACTICAL, $log_title, $log2_data);
            }
        }
        return MV_EXEC_OK;
    }
        message(DATABASE_ERROR, 'Could not update user alliance data');
    }
    alliance_log('<font color=green>' . $user_data['user_name'] . '</font> ' . constant($game->sprache("TEXT11")) . ' <font color=green>' . $game->player['user_name'] . '</font>' . constant($game->sprache("TEXT12")));
    $sql = 'UPDATE userally_history SET leave_date = ' . time() . ' WHERE user_id = ' . $user_id . ' AND alliance_id = ' . $game->player['user_alliance'];
    if (!$db->query($sql)) {
        message(DATABASE_ERROR, 'Could not record userally history');
    }
    $sql = 'UPDATE alliance
            SET alliance_points = alliance_points - ' . $user_data['user_points'] . ',
                alliance_planets = alliance_planets - ' . $user_data['user_planets'] . ',
                alliance_honor = alliance_honor - ' . $user_data['user_honor'] . '
            WHERE alliance_id = ' . $game->player['user_alliance'];
    if (!$db->query($sql)) {
        message(DATABASE_ERROR, 'Could not update alliance data');
    }
    SystemMessage($user_id, constant($game->sprache("TEXT13")), constant($game->sprache("TEXT14")) . ' <b>' . $game->player['alliance_name'] . '</b>' . constant($game->sprache("TEXT15")));
    redirect('a=alliance_rights');
} elseif (!empty($_POST['kick'])) {
    if (empty($_POST['user_id'])) {
        message(GENERAL, 'Invalid request', '$_POST[\'user_id\'] was empty');
    }
    $user_id = (int) $_POST['user_id'];
    $sql = 'SELECT user_id, user_name
            FROM user
            WHERE user_id = ' . $user_id;
    if (($user_data = $db->queryrow($sql)) === false) {
        message(DATABASE_ERROR, 'Could not query user alliance data');
    }
    if (empty($user_data['user_id'])) {
        message(NOTICE, constant($game->sprache("TEXT7")));
    }
    }
    redirect('a=alliance_application&application=admin');
}
if ($_GET['application'] == 'deny') {
    check_membership(true);
    if ($game->player['user_alliance_rights6'] != 1) {
        message(NOTICE, constant($game->sprache("TEXT10")));
    }
    $sql = 'SELECT * FROM alliance_application, user, alliance WHERE application_id = ' . $_GET['app_id'] . ' AND user_id = application_user AND alliance_id = application_alliance';
    if (($application_data = $db->queryrow($sql)) === false) {
        message(DATABASE_ERROR, 'Could not query app data');
    }
    if ($application_data['application_alliance'] != $game->player['user_alliance']) {
        message(NOTICE, constant($game->sprache("TEXT22")));
    }
    SystemMessage($application_data['application_user'], constant($game->sprache("TEXT34")), constant($game->sprache("TEXT23")) . $application_data['alliance_name'] . constant($game->sprache("TEXT27")));
    /* // If only if not already set to read, otherwise negative values can arise.
    
        if($application_data['application_read']!=1) {
      
          $sql = 'UPDATE alliance SET alliance_application_new = (alliance_application_new - 1) WHERE alliance_id = '.$game->player['user_alliance'];
    
        if(!$db->query($sql)) {
          message(DATABASE_ERROR, 'Could not Update alliance application READ');
        }
      } */
    $sql = 'DELETE FROM alliance_application WHERE application_id = ' . $_GET['app_id'];
    if (!$db->query($sql)) {
        message(DATABASE_ERROR, 'Could not delete application Data');
    }
    redirect('a=alliance_application&application=admin');
Beispiel #6
0
 function report($reason)
 {
     $message = addslashes($reason . NL . NL . 'move_id: <b>' . $this->mid . '</b>' . NL . 'user_id: <b>' . $this->move['user_id'] . '</b>' . NL . 'action_code: <b>' . $this->move['action_code'] . '</b>' . NL . 'start: <b>' . $this->move['start'] . '</b>' . NL . 'dest: <b>' . $this->move['dest'] . '</b>' . NL . 'move_begin: <b>' . $this->move['move_begin'] . '</b>' . NL . 'move_finish: <b>' . $this->move['move_finish'] . '</b>' . NL . 'processing tick: <b>' . $this->CURRENT_TICK . '</b>');
     SystemMessage(DATA_UID, 'Move (' . $reason . ')', $message);
 }
 function _action_main()
 {
     if ($this->flags['combat_happened']) {
         $sql = 'UPDATE ship_fleets
                 SET planet_id = ' . $this->move['dest'] . ',
                     move_id = 0
                 WHERE fleet_id = ' . $this->fleet_ids[0];
         if (!$this->db->query($sql)) {
             return $this->log(MV_M_DATABASE, 'Could not update ships position data');
         }
         return MV_EXEC_OK;
     }
     if ($this->flags['free_dest_planet']) {
         $sql = 'UPDATE ship_fleets
                 SET planet_id = ' . $this->move['dest'] . ',
                     move_id = 0
                 WHERE fleet_id = ' . $this->fleet_ids[0];
         if (!$this->db->query($sql)) {
             return $this->log(MV_M_DATABASE, 'Could not update ships position data');
         }
         return MV_EXEC_OK;
     }
     $this->tr_data = $this->action_data;
     $this->tr_data[5] *= 2;
     if ($this->tr_data[5] < 0) {
         $this->tr_data[5] = -1;
     }
     // On which planet we are arrived?
     if ($this->move['dest'] == $this->tr_data[2]) {
         $this->actions =& $this->tr_data[4];
     } else {
         $this->actions =& $this->tr_data[3];
     }
     $this->log(MV_M_NOTICE, 'Buondi! Sono quello della flotta <b>' . $this->fleet_ids[0] . '</b> del Boss <b>' . $this->move['user_id'] . '</b>, in arrivo sul pianeta <b>' . $this->dest['planet_id'] . '</b> che appartiene a <b>' . $this->dest['user_id'] . '</b> per un trasporto.');
     $sql = 'SELECT resource_1, resource_2, resource_3, resource_4, unit_1, unit_2, unit_3, unit_4, unit_5, unit_6
             FROM ship_fleets
             WHERE fleet_id = ' . $this->fleet_ids[0];
     if (($this->fleet = $this->db->queryrow($sql)) === false) {
         return $this->log(MV_M_DATABASE, 'Could not query fleet data');
     }
     $sql = 'SELECT COUNT(s.ship_id) AS n_transporter
             FROM (ships s, ship_templates st)
             WHERE s.fleet_id = ' . $this->fleet_ids[0] . ' AND
                   st.id = s.template_id AND
                   st.ship_torso = ' . SHIP_TYPE_TRANSPORTER;
     if (($n_transporter = $this->db->queryrow($sql)) === false) {
         return $this->log(MV_M_DATABASE, 'Could not query n_transporter data');
     }
     $this->fleet['max_resources'] = $n_transporter['n_transporter'] * MAX_TRANSPORT_RESOURCES;
     $this->fleet['max_units'] = $n_transporter['n_transporter'] * MAX_TRANSPORT_UNITS;
     /* START OF RULE TO AVOID ROUTES BETWEEN SITTER AND SITTED */
     $route_blocked = false;
     $sql = 'SELECT user_sitting_id1, user_sitting_id2, user_sitting_id3,
                    user_sitting_id4, user_sitting_id5
             FROM user
             WHERE user_id = ' . $this->move['user_id'];
     if (($move_sitters = $this->db->queryrow($sql)) === false) {
         return $this->log(MV_M_DATABASE, 'Could not query sitters data of the move owner');
     }
     $sql = 'SELECT user_sitting_id1, user_sitting_id2, user_sitting_id3,
                    user_sitting_id4, user_sitting_id5
             FROM user
             WHERE user_id = ' . $this->dest['user_id'];
     if (($dest_sitters = $this->db->queryrow($sql)) === false) {
         return $this->log(MV_M_DATABASE, 'Could not query sitters data of the dest owner');
     }
     if ($move_sitters['user_sitting_id1'] == $this->dest['user_id'] || $move_sitters['user_sitting_id2'] == $this->dest['user_id'] || $move_sitters['user_sitting_id3'] == $this->dest['user_id'] || $move_sitters['user_sitting_id4'] == $this->dest['user_id'] || $move_sitters['user_sitting_id5'] == $this->dest['user_id']) {
         $route_blocked = true;
         $log_message = 'Trade route between sitter <b>' . $this->dest['user_id'] . '</b> and sitted <b>' . $this->move['user_id'] . '</b> are forbidden!!!';
     }
     if ($dest_sitters['user_sitting_id1'] == $this->move['user_id'] || $dest_sitters['user_sitting_id2'] == $this->move['user_id'] || $dest_sitters['user_sitting_id3'] == $this->move['user_id'] || $dest_sitters['user_sitting_id4'] == $this->move['user_id'] || $dest_sitters['user_sitting_id5'] == $this->move['user_id']) {
         $route_blocked = true;
         $log_message = 'Trade route between sitter <b>' . $this->move['user_id'] . '</b> and sitted <b>' . $this->dest['user_id'] . '</b> are forbidden!!!';
     }
     if ($route_blocked) {
         switch ($this->move['language']) {
             case 'GER':
                 $message = 'Hallo ' . $this->move['user_name'] . ',<br>Handelswege zwischen Sitter und sitted Konto sind verboten.<br>Diese Nachricht wurde automatisch generiert, Beschwerden beim STFC2-Team bringen nichts.<br>~ Sitting-Abuse-Automatik';
                 $title = 'Routesperre';
                 break;
             case 'ITA':
                 $message = 'Ciao ' . $this->move['user_name'] . ',<br>le rotte commerciali tra account sitter e sittato non sono ammesse.<br>Questo messaggio &egrave; stato generato automaticamente, lamentele al team di STFC2 sono inutili.<br>~ Sistema anti abuso sitting';
                 $title = 'Rotta bloccata';
                 break;
             default:
                 $message = 'Hello ' . $this->move['user_name'] . ',<br>trade routes between sitter and sitted account are forbidden.<br>This message is automatically generated complaints to the team STFC2 are useless.<br>~Sitting Abuse Prevention System';
                 $title = 'Route blocked';
                 break;
         }
     }
     /* END OF RULE TO AVOID ROUTES BETWEEN SITTER AND SITTED */
     /* START OF RULE TO AVOID ROUTES WITH SETTLERS */
     if ($this->dest['user_id'] == INDEPENDENT_USERID) {
         $route_blocked = true;
         switch ($this->move['language']) {
             case 'GER':
                 $message = 'Hallo ' . $this->move['user_name'] . ',<br>Handelswege mit Siedler sind verboten.<br>Diese Nachricht wurde automatisch generiert, Beschwerden beim STFC2-Team bringen nichts.<br>~ Siedler-Abuse-Automatik';
                 $title = 'Routesperre';
                 break;
             case 'ITA':
                 $message = 'Ciao ' . $this->move['user_name'] . ',<br>le rotte commerciali con i Coloni non sono ammesse.<br>Questo messaggio &egrave; stato generato automaticamente, lamentele al team di STFC2 sono inutili.<br>~ Sistema anti abuso Coloni';
                 $title = 'Rotta bloccata';
                 break;
             default:
                 $message = 'Hello ' . $this->move['user_name'] . ',<br>trade routes with Settlers are forbidden.<br>This message is automatically generated complaints to the team STFC2 are useless.<br>~Settlers Abuse Prevention System';
                 $title = 'Route blocked';
                 break;
         }
         $log_message = 'Trade route between user <b>' . $this->move['user_id'] . '</b> and Settlers are forbidden!!!';
     }
     /* END OF RULE TO AVOID ROUTES WITH SETTLERS */
     // Route not allowed: log it, inform the admin and deactivate
     if ($route_blocked) {
         $this->log(MV_M_NOTICE, $log_message);
         SystemMessage($this->move['user_id'], $title, $message);
         //Send a copy to the admin
         SystemMessage(10, $title, $message);
         // Deactivate the move
         $sql = 'UPDATE ship_fleets
             SET planet_id = ' . $this->move['dest'] . ',
             move_id = 0
             WHERE fleet_id IN (' . $this->fleet_ids_str . ')';
         if (!$this->db->query($sql)) {
             return $this->log(MV_M_DATABASE, 'Could not update fleets data! SKIP');
         }
         return MV_EXEC_OK;
     }
     $this->do_unloading();
     if ($this->move['user_id'] != $this->dest['user_id']) {
         $sql = 'SELECT ud.ud_id, a.alliance_id, ad.ad_id, ad.type, ad.status 
                 FROM (user u)
                 LEFT JOIN user_diplomacy ud ON ( ( ud.user1_id = ' . $this->move['user_id'] . ' AND ud.user2_id = ' . $this->dest['user_id'] . ' ) OR (ud.user1_id = ' . $this->dest['user_id'] . ' AND ud.user2_id = ' . $this->move['user_id'] . ' ) )
                 LEFT JOIN alliance a ON a.alliance_id = u.user_alliance
                 LEFT JOIN alliance_diplomacy ad ON ( ( ad.alliance1_id = ' . $this->move['user_alliance'] . ' AND ad.alliance2_id = a.alliance_id ) OR ( ad.alliance1_id = a.alliance_id AND ad.alliance2_id = ' . $this->move['user_alliance'] . ' ) )
                 WHERE u.user_id = ' . $this->dest['user_id'];
         if (($diplomacy = $this->db->queryrow($sql)) === false) {
             return $this->log(MV_M_DATABASE, 'Could not query diplomacy data');
         }
         $allied = false;
         // Players has a private pact?
         if (!empty($diplomacy['ud_id'])) {
             $allied = true;
         }
         // Players are in the same alliance?
         if ($diplomacy['alliance_id'] != 0 && $diplomacy['alliance_id'] == $this->move['user_alliance']) {
             $allied = true;
         }
         // Player's alliances are sharing a Cooperation pact?
         if (!empty($diplomacy['ad_id'])) {
             if ($diplomacy['type'] == 3) {
                 if ($diplomacy['status'] == 0) {
                     $allied = true;
                 }
             }
         }
     } else {
         $allied = true;
     }
     if ($allied && ($this->tr_data[5] < 0 || $this->tr_data[5] == 4)) {
         $this->do_loading();
     }
     $sql = 'UPDATE ship_fleets
             SET resource_1 = ' . $this->fleet['resource_1'] . ',
                 resource_2 = ' . $this->fleet['resource_2'] . ',
                 resource_3 = ' . $this->fleet['resource_3'] . ',
                 resource_4 = ' . $this->fleet['resource_4'] . ',
                 unit_1 = ' . $this->fleet['unit_1'] . ',
                 unit_2 = ' . $this->fleet['unit_2'] . ',
                 unit_3 = ' . $this->fleet['unit_3'] . ',
                 unit_4 = ' . $this->fleet['unit_4'] . ',
                 unit_5 = ' . $this->fleet['unit_5'] . ',
                 unit_6 = ' . $this->fleet['unit_6'] . '
             WHERE fleet_id = ' . $this->fleet_ids[0];
     if (!$this->db->query($sql)) {
         return $this->log(MV_M_DATABASE, 'Could not update ship fleets resource data');
     }
     $sql = 'UPDATE planets
             SET resource_1 = ' . $this->dest['resource_1'] . ',
                 resource_2 = ' . $this->dest['resource_2'] . ',
                 resource_3 = ' . $this->dest['resource_3'] . ',
                 resource_4 = ' . $this->dest['resource_4'] . ',
                 unit_1 = ' . $this->dest['unit_1'] . ',
                 unit_2 = ' . $this->dest['unit_2'] . ',
                 unit_3 = ' . $this->dest['unit_3'] . ',
                 unit_4 = ' . $this->dest['unit_4'] . ',
                 unit_5 = ' . $this->dest['unit_5'] . ',
                 unit_6 = ' . $this->dest['unit_6'] . '
             WHERE planet_id = ' . $this->dest['planet_id'];
     if (!$this->db->query($sql)) {
         return $this->log(MV_M_DATABASE, 'Could not update planets resource data');
     }
     // #############################################################################
     // Returns ships if requested
     if ($this->tr_data[5] < 0 || $this->tr_data[5] == 4) {
         $new_move_begin = $this->CURRENT_TICK;
         $new_move_finish = $this->move['move_finish'] - $this->move['move_begin'] + $this->CURRENT_TICK;
         $sql = 'UPDATE scheduler_shipmovement
                 SET start = ' . $this->move['dest'] . ',
                     dest = ' . $this->move['start'] . ',
                     move_begin = ' . $new_move_begin . ',
                     move_finish = ' . $new_move_finish . ',
                     remaining_distance = total_distance,
                     action_data = "' . serialize($this->tr_data) . '"
                 WHERE move_id = ' . $this->mid;
         if (!$this->db->query($sql)) {
             return $this->log(MV_M_DATABASE, 'Could not update move data! SKIP');
         }
         $this->flags['keep_move_alive'] = true;
     } else {
         $sql = 'UPDATE ship_fleets
             SET planet_id = ' . $this->move['dest'] . ',
             move_id = 0
             WHERE fleet_id IN (' . $this->fleet_ids_str . ')';
         if (!$this->db->query($sql)) {
             return $this->log(MV_M_DATABASE, 'Could not update fleets data! SKIP');
         }
     }
     // #############################################################################
     // Logbook entry
     $sql = 'SELECT st.name, st.ship_torso, st.race,
                    COUNT(s.ship_id) AS n_ships
             FROM ship_templates st, ship_fleets f, ships s
             WHERE f.fleet_id IN (' . $this->fleet_ids_str . ') AND
                   s.template_id = st.id AND
                   s.fleet_id = f.fleet_id
             GROUP BY st.id
             ORDER BY st.ship_torso ASC, st.race ASC';
     if (!($q_stpls = $this->db->query($sql))) {
         return $this->log(MV_M_DATABASE, 'Could not query ships templates data! SKIP');
     }
     $log_data = array(34, $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'], array(), $this->unlwares, $this->lwares, $this->planet_overloaded);
     while ($stpl = $this->db->fetchrow($q_stpls)) {
         $log_data[8][] = array($stpl['name'], $stpl['ship_torso'], $stpl['race'], $stpl['n_ships']);
     }
     // #############################################################################
     // Retrieve player language
     switch ($this->move['language']) {
         case 'GER':
             $log_title1 = 'Transport bei ' . $this->dest['planet_name'] . ' durchgef&uuml;hrt';
             $log_title2 = 'Transport bei ' . $this->dest['planet_name'] . ' erhalten';
             break;
         case 'ITA':
             $log_title1 = 'Trasporto per ' . $this->dest['planet_name'] . ' compiuto';
             $log_title2 = 'Trasporto per ' . $this->dest['planet_name'] . ' ricevuto';
             break;
         default:
             $log_title1 = 'Transport for ' . $this->dest['planet_name'] . ' accomplished';
             $log_title2 = 'Transport for ' . $this->dest['planet_name'] . ' received';
             break;
     }
     // Add logbook entries only if players had activated them
     if ($this->action_data[6]) {
         add_logbook_entry($this->move['user_id'], LOGBOOK_TACTICAL, $log_title1, $log_data);
     }
     // Only one logbook if the owner of the planet is also the owner of the fleets
     if ($this->move['user_id'] != $this->dest['user_id']) {
         add_logbook_entry($this->dest['user_id'], LOGBOOK_TACTICAL, $log_title2, $log_data);
     }
     return MV_EXEC_OK;
 }
    if ($user2['user_id'] == $game->player['user_id']) {
        message(NOTICE, constant($game->sprache("TEXT15")));
    }
    $sql = 'SELECT ud_id
            FROM user_diplomacy
            WHERE (user1_id = ' . $game->player['user_id'] . ' AND user2_id = ' . $user2['user_id'] . ') OR
                  (user1_id = ' . $user2['user_id'] . ' AND user2_id = ' . $game->player['user_id'] . ')';
    if (($ud_exists = $db->queryrow($sql)) === false) {
        message(DATABASE_ERROR, 'Could not query user diplomacy data');
    }
    if (!empty($ud_exists['ud_id'])) {
        message(NOTICE, constant($game->sprache("TEXT16")));
    }
    $sql = 'INSERT INTO user_diplomacy (user1_id, user2_id, accepted)
            VALUES (' . $game->player['user_id'] . ', ' . $user2['user_id'] . ', 0)';
    SystemMessage($user2['user_id'], constant($game->sprache("TEXT17")), constant($game->sprache("TEXT18")));
    if (!$db->query($sql)) {
        message(DATABASE_ERROR, 'Could not insert new diplomacy private data');
    }
    redirect('a=user_diplomacy');
} elseif (isset($_GET['new'])) {
    $game->out('
<table class="style_outer" width="400" align="center" border="0" cellpadding="2" cellspacing="2"><tr><td>	
<table class="style_inner" width="400" align="center" border="0" cellpadding="2" cellspacing="2">
  <form method="post" action="' . parse_link('a=user_diplomacy') . '">
  <tr>
    <td align="left">
      <b>' . constant($game->sprache("TEXT19")) . '</b><br><br>
      ' . constant($game->sprache("TEXT3")) . '&nbsp;&nbsp;<input class="field" type="text" name="user2_name" value="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input class="button" type="submit" name="searcher" value="' . constant($game->sprache("TEXT4")) . '">
    </td>
  </tr>