示例#1
0
 function create_sector_map($sector_id)
 {
     include_once 'include/libs/moves.php';
     global $db, $game;
     if ($sector_id < 1 || $sector_id > $this->max_sectors) {
         message(GENERAL, 'Invalid sector id ' . $sector_id);
     }
     //$g_coords = $game->get_sector_global_coords($game->get_sector_name($sector_id));
     $im = imagecreate($this->sector_map_size, $this->sector_map_size);
     //$im = imagecreatefrompng('maps/templates/sector_'.$g_coords[0].'_'.$g_coords[1].'.jpg');
     imagecolorallocate($im, 0, 0, 0);
     $this->draw_stars($im, $this->sector_map_size, 600);
     $this->draw_outer_border($im, $this->sector_map_size, 10);
     $sql = 'SELECT *
             FROM starsystems
             WHERE sector_id = ' . $sector_id;
     if (!($q_systems = $db->query($sql))) {
         message(DATABASE_ERROR, 'Could not query starsystems data');
     }
     $n_systems = $db->num_rows($q_systems);
     if ($n_systems > $this->max_systems_per_sector) {
         message(GENERAL, 'Too many starsystems found in sector ' . $sector_id);
     }
     $map_html = '<map name="sector_map">' . NL;
     $used_fields = array();
     while ($system = $db->fetchrow($q_systems)) {
         $coord_id = $system['system_x'] . $system['system_y'];
         if (isset($used_fields[$coord_id])) {
             message(GENERAL, 'Sector field ' . $system['system_x'] . '|' . $system['system_y'] . ' is used twice [by system ' . $used_fields[$coord_id] . ' and ' . $system['system_id'] . ' in sector ' . $sector_id . ']');
         }
         if ($system['system_x'] > $this->sector_map_split || $system['system_y'] > $this->sector_map_split) {
             message(GENERAL, 'Invalid starsystem coordinates ' . $system['system_x'] . ' | ' . $system['system_y'] . ' by system <i>' . $system['system_id'] . '</i> in sector <i>' . $sector_id . '</i>');
         }
         $star_color = imagecolorallocate($im, $system['system_starcolor_red'], $system['system_starcolor_green'], $system['system_starcolor_blue']);
         $star_size = (double) $system['system_starsize'];
         if ($star_size < $this->starsize_range[0] || $star_size > $this->starsize_range[1]) {
             message(GENERAL, 'Invalid starsize ' . $star_size . ' by system ' . $system['system_id'] . ' in sector ' . $sector_id);
         }
         $star_size *= 0.45;
         imagefilledellipse($im, $system['system_map_x'], $system['system_map_y'], $star_size, $star_size, $star_color);
         ////////////////// Calculate the distance in A.U. between the capital system and the target one
         if ($game->capital_system_id != $system['system_id']) {
             $distance = get_distance(array($game->capital_global_x, $game->capital_global_y), array($system['system_global_x'], $system['system_global_y']));
             $distance = round($distance, 2);
         } else {
             $distance = 0;
         }
         if ($distance > MAX_BOUND_RANGE) {
             $distance_str = ' ' . $this->str_range . $distance . ' A.U.<br>' . $this->str_outrange;
         } else {
             $distance_str = ' ' . $this->str_range . $distance . ' A.U.';
         }
         // DC Try to give more information, just for fun
         $explored_str = '';
         $sql = 'SELECT count(*) as explored FROM starsystems_details
                 WHERE system_id = ' . $system['system_id'] . '
                 AND user_id = ' . $game->player['user_id'];
         if ($res = $db->queryrow($sql)) {
             if ($res['explored'] == 0) {
                 $explored_str = '<br><i>' . $this->str_unch . '</i>';
             }
         }
         // DC Stringa Pianeti
         $planets_str = '';
         if ($res['explored'] == 0) {
             $planets_str = '<br>' . $this->str_planets . ' ' . $system['system_n_planets'];
         } else {
             $sql = 'SELECT p.planet_id, p.planet_distance_id, p.planet_name, p.planet_type, p.planet_owner, u.user_name, p.planet_points, pd.survey_1, pd.survey_2, pd.survey_3
                     FROM (planets p)
                     LEFT JOIN (user u) ON (u.user_id = p.planet_owner AND p.planet_owner > 0)
                     LEFT JOIN (planet_details pd) ON (pd.planet_id = p.planet_id AND pd.log_code = 100 AND pd.user_id = ' . $game->player['user_id'] . ')
                     WHERE p.system_id = ' . $system['system_id'] . '
                     ORDER BY p.planet_distance_id ASC';
             if ($plist = $db->queryrowset($sql)) {
                 $planets_str .= '<br>' . $this->str_planets;
                 foreach ($plist as $pitem) {
                     $planets_str .= '<br>' . ($pitem['planet_distance_id'] + 1) . ': ' . strtoupper($pitem['planet_type']);
                     if (isset($pitem['survey_1'])) {
                         $planets_str .= ' (';
                         switch ($pitem['survey_1']) {
                             case 0:
                                 $planets_str .= '<font color=red>-</font>|';
                                 break;
                             case 1:
                                 $planets_str .= '<font color=grey>=</font>|';
                                 break;
                             case 2:
                                 $planets_str .= '<font color=green>+</font>|';
                                 break;
                         }
                         switch ($pitem['survey_2']) {
                             case 0:
                                 $planets_str .= '<font color=red>-</font>|';
                                 break;
                             case 1:
                                 $planets_str .= '<font color=grey>=</font>|';
                                 break;
                             case 2:
                                 $planets_str .= '<font color=green>+</font>|';
                                 break;
                         }
                         switch ($pitem['survey_3']) {
                             case 0:
                                 $planets_str .= '<font color=red>-</font>';
                                 break;
                             case 1:
                                 $planets_str .= '<font color=grey>=</font>';
                                 break;
                             case 2:
                                 $planets_str .= '<font color=green>+</font>';
                                 break;
                         }
                         $planets_str .= ')';
                     }
                     $planets_str .= !empty($pitem['planet_owner']) ? ' &#34;' . htmlentities($pitem['planet_name']) . '&#34;' : ' <i>' . htmlentities($pitem['planet_name']) . '</i>';
                     if (!empty($pitem['planet_owner'])) {
                         $planets_str .= ' ' . htmlentities($pitem['user_name']) . ' (' . $pitem['planet_points'] . ' pt.)';
                     }
                     $fleet_sensor = false;
                     //Any fleet here?
                     $sql = 'SELECT sf.fleet_name, sf.n_ships FROM ship_fleets sf 
                             WHERE planet_id = ' . $pitem['planet_id'] . ' AND sf.user_id = ' . $game->player['user_id'];
                     if ($fleet_details = $db->queryrowset($sql)) {
                         $fleet_sensor = true;
                         foreach ($fleet_details as $f_i) {
                             $planets_str .= '<br>&nbsp;&nbsp;&nbsp;&nbsp;&#187;&nbsp;' . $this->str_fleet_player . ' <b>' . htmlentities($f_i['fleet_name']) . '</b>, ' . $f_i['n_ships'] . ' ' . $this->str_ships;
                         }
                     }
                     //Anu OTHER fleets here?
                     if (!empty($pitem['planet_owner']) && $pitem['planet_owner'] == $game->player['user_id'] || $fleet_sensor) {
                         $sql = 'SELECT user_name, SUM(n_ships) AS n_ships FROM ship_fleets INNER JOIN user USING (user_id) WHERE planet_id = ' . $pitem['planet_id'] . ' AND user_id <> ' . $game->player['user_id'] . ' GROUP BY user_id';
                         if ($flist = $db->queryrowset($sql)) {
                             foreach ($flist as $fitem) {
                                 $planets_str .= '<br>&nbsp;&nbsp;&nbsp;&#183;&#183;&#183;<b>' . $fitem['user_name'] . '</b>, ' . $fitem['n_ships'] . ' ' . $this->str_ships;
                             }
                         }
                     }
                 }
             }
         }
         $private_str = '';
         if (!empty($system['system_owner']) && $system['system_owner'] != $game->player['user_id']) {
             $private_str = '<br><i>' . $this->str_priv . '</i>';
         }
         // ----
         /////////////////
         $map_html .= '<area href="' . parse_link('a=tactical_cartography&system_id=' . encode_system_id($system['system_id'])) . '" shape="circle" coords="' . $system['system_map_x'] . ', ' . $system['system_map_y'] . ', ' . $star_size . '" onmouseover="return overlib(\'' . $system['system_name'] . $distance_str . $planets_str . $explored_str . $private_str . '\', CAPTION, \'' . $this->str_details . '\', WIDTH, 300, ' . OVERLIB_STANDARD . ');" onmouseout="return nd();">';
         $used_fields[$coord_id] = $system['system_id'];
     }
     imagepng($im, 'maps/images/cache/' . md5($game->player['user_id']) . '.png');
     imagedestroy($im);
     $map_html .= '</map>';
     return $map_html;
 }
示例#2
0
    while ($system = $db->fetchrow($q_systems)) {
        $glob_systems[$system['system_id']] = $system;
    }
    $q_planets = $db->query('SELECT system_id FROM planets WHERE planet_owner=0 GROUP BY system_id');
    while ($planet = $db->fetchrow($q_planets)) {
        $system = $glob_systems[$planet['system_id']];
        $px = getSystemCoords($system, $size);
        $px_x = $px[0];
        $px_y = $px[1];
        if ($size > 2) {
            imagefilledrectangle($im, $px_x, $px_y, $px_x + $size - 2, $px_y + $size - 2, $color[5]);
            $map_data .= '<area href="index.php?a=tactical_cartography&system_id=' . encode_system_id($system['system_id']) . '" target=_mapshow shape="rect" coords="' . $px_x . ',' . $px_y . ', ' . ($px_x + $size - 2) . ', ' . ($px_y + $size - 2) . '" title="' . $system['system_name'] . '">
';
        } else {
            imagefilledrectangle($im, $px_x - 1, $px_y - 1, $px_x + $size - 2, $px_y + $size - 2, $color[5]);
            $map_data .= '<area href="index.php?a=tactical_cartography&system_id=' . encode_system_id($system['system_id']) . '" target=_mapshow shape="rect" coords="' . ($px_x - 1) . ',' . ($px_y - 1) . ', ' . ($px_x + $size - 2) . ', ' . ($px_y + $size - 2) . '" title="' . $system['system_name'] . '">
';
        }
    }
    if ($size < 3) {
        $size2 = 1;
    }
    if ($size == 3) {
        $size2 = 2;
    } else {
        $size2 = $size - 2;
    }
    if ($size > 1) {
        imagestring($im, $size2, 15, 162 * $size - 12 - $size, $created . date('d.m.y H:i', time()), $color[4]);
    } else {
        imagestring($im, $size2, 5, 162 * $size - 15, $created, $color[4]);
          <td width="20">&nbsp;</td>
          <td width="360">' . $legend_html . $map_html . constant($game->sprache("TEXT91")) . '</font></td>
          <td width="20">&nbsp;</td>
        </tr>
      </table>
    </td>
  </tr>
</table>
<br>
    ');
    display_cartography_jump();
} else {
    if (empty($tc_views_map[$game->player['last_tcartography_view']])) {
        $sql = 'UPDATE user
                SET last_tcartography_view = 0,
                    last_tcartography_id = 0
                WHERE user_id = ' . $game->player['user_id'];
        if (!$db->query($sql)) {
            message(DATABASE_ERROR, 'Could not update user last tcartography data');
        }
        redirect('a=tactical_cartography&galaxy');
    }
    // workaround
    if ($game->player['last_tcartography_view'] == 3) {
        $game->player['last_tcartography_id'] = encode_system_id((int) $game->player['last_tcartography_id']);
    }
    if ($game->player['last_tcartography_view'] == 4) {
        $game->player['last_tcartography_id'] = encode_planet_id((int) $game->player['last_tcartography_id']);
    }
    redirect('a=tactical_cartography&' . sprintf($tc_views_map[$game->player['last_tcartography_view']], $game->player['last_tcartography_id']));
}