Location: PHPKode > projects > Merchant Empires > merchempires/merchantempires/planet_scan.php
<?php
/****************************************************************************
*    Copyright (C) 2000 Bryan Brunton
*
*    This program is free software; you can redistribute it and/or modify
*    it under the terms of the GNU General Public License as published by
*    the Free Software Foundation; either version 2 of the License, or
*    (at your option) any later version.
*
*    This program is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*    GNU General Public License for more details.
*
*    You should have received a copy of the GNU General Public License
*    along with this program; if not, write to the Free Software
*    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
****************************************************************************/

page_open(array("sess" => "ME_Session_Uncached", "auth" => "ME_Auth", "user" => "ME_User"));
$sess->register("player_id");
$sess->register("player_dead");

include("./lib/player.php");
include("./lib/ship.php");
include("./lib/sector.php");
include("./merchantempiresdefines.php");
include("./lib/player_redirect.php");
?>

<html><head><title>Merchant Empires: Planetary Scanner</title>
<link rel=stylesheet href="./merchantempires.css" type=text/css>
</head><body text=white background="./images/createbg.gif"><?php

include("./templates/header.html");
?>

<table width=100%><tr>
<td width=100 vAlign=top><?php

$player = new ME_Player;
$player->get_player($player_id);
$player_dead = $player->f("dead");
$ship = new ME_Ship;
$ship->get_ship($player_id);
$planet_id = $ship->f("planet_id");

$ship->add_parameter("time", date ("Y H:i:s"));
$ship->add_parameter("current_screen", "planet");
echo $ship->get_transform("./xslt/mainmenu.xslt", $ship->get_xml());
	
$db_pl = new ME_DB;
$db_pl->query("select players.rank, players.experience, players.level, players.player_id, ships.planet_id, ships.player_id from players, ships where ships.planet_id = '$planet_id' and players.player_id = ships.player_id order by players.experience desc limit 1");
$db_pl->next_record();

$db_p = new ME_DB_Xml;
$db_p->query("select * from planets where planet_id = '$planet_id'");
$db_p->next_record();

$sector_id = $db_p->f("sector_id");

$db_s = new ME_DB;
$db_s->query("select * from sectors where sector_id = '$sector_id'");
$db_s->next_record();

$sector = new ME_Sector;
$sector->get_offset_sector($db_s->f("map_id"), $db_s->f("xpos"), $db_s->f("ypos"));
	
?>

</td>
<td vAlign=top align=left width=0>&nbsp;</td>
<td vAlign=top width=490><?php

if ( $planet_id <> 0 ) {
	$db_p->add_parameter("current_screen", "planet_scan");	
	echo $db_p->get_transform("./xslt/menu_top_planet.xslt", $db_p->get_xml());
?>
<table border=0 cellPadding=0 cellSpacing=0 width=490>
	<tr>
  	<td bgColor=#003399>
    	<table border=0 cellPadding=5 cellSpacing=1 width=490>
        <tr>
        	<td bgColor=#000000>
						<font color=#3333FF face=arial,helvetica,swiss size=3><b>Planetary Scanner</font></b><br>
						<font  color=#cccccc face=arial,helvetica,swiss size=3>&nbsp;Range: 0</font><br>
						<font  color=#cccccc face=arial,helvetica,swiss size=3>&nbsp;Level: <?php

	$db = new ME_DB;
	$rank = $db_pl->f("rank");
	$db->query("select * from levels where rank = '$rank'");	
	$db->next_record();
	echo $db->f("level");	
?>
						<br><br>
						<img border=0 src='./images/map<?php

	echo $sector->f("map_id") . "/scanmenu" . $sector_id	. ".png' usemap='#scanmenu'>";
	echo "<map name='scanmenu'>";
	
	#middle
	$s2 = new ME_Sector;
	$s2->get_offset_sector($sector->f("map_id"), $sector->f("xpos"), $sector->f("ypos"));

	if ( $s2->f("sector_id") != 0 )  {
		echo "<area alt='Scan Sector' coords=40,30,68,57 href=" . URL . "planet_scan.php?id=" . $s2->f("sector_id") . ">";
	}

	#bottom
#	$s2->get_offset_sector($sector->f("map_id"), $sector->f("xpos"), $sector->f("ypos") - 1);

#	if ($s2->f("sector_id") != 0)  {
#		echo "<area alt='Scan Sector' coords=40,58,68,85 href=" . URL . "planet_scan.php?id=" . $s2->f("sector_id") . ">";
#	}

	#top
#	$s2->get_offset_sector($sector->f("map_id"), $sector->f("xpos"), $sector->f("ypos") + 1);

#	if ($s2->f("sector_id") != 0)  {
#		echo "<area alt='Scan Sector' coords=40,2,68,29 href=" . URL . "planet_scan.php?id=" . $s2->f("sector_id") . ">";
#	}

	#right
#	$s2->get_offset_sector($sector->f("map_id"), $sector->f("xpos") + 1, $sector->f("ypos"));

#	if ($s2->f("sector_id") != 0)  {
#		echo "<area alt='Scan Sector' coords=69,30,97,57 href=" . URL . "planet_scan.php?id=" . $s2->f("sector_id") . ">";
#	}

	#left
#	$s2->get_offset_sector($sector->f("map_id"), $sector->f("xpos") - 1, $sector->f("ypos"));

#	if ($s2->f("sector_id") != 0)  {
#		echo "<area alt='Scan Sector' coords=11,30,39,57 href=" . URL . "planet_scan.php?id=" . $s2->f("sector_id") . ">";
#	}

	echo "</map>";	

?>										
	       	</td>
		  	</tr>
			</table>
		</td>
	</tr>
</table><br><?php
	
	$id = (int) $id;			

	if ( $id > 0 and $id == $db_p->f("sector_id") ) {		

?>
<table border=0 cellPadding=0 cellSpacing=0>
	<tr>
		<td bgColor=#003399>
			<table border=0 cellPadding=5 cellSpacing=1 width=500>
				<tr>
					<td width=170 bgColor=#000000>
						<font color=#3333FF face=arial,helvetica,swiss size=3>
							Scanners detect:</font><br><?php

		if ( $db_p->f("scanner") == 't' ) {
			$db = new ME_DB;
			$query = sprintf("SELECT ships.player_id, ships.sector_id, ship_technology.player_id, ship_technology.cloak, ship_technology.cloak_active from ships, ship_technology where ships.sector_id = '%s' and ships.player_id = ship_technology.player_id", $id);
			$db->query($query);

			$nonallied = 0;
			$allied = 0;
			$db_2 = new ME_DB;

			while ( $db->next_record() ) {
				$query = sprintf("SELECT player_id, name, public_player_id, experience, level, alliance_id from players where player_id = '%s'", $db->f("player_id"));
				$db_2->query($query);
				$db_2->next_record();

				if ( ($db->f("cloak") and $db->f("cloak_active") == 't' and $db_2->f("level") < $db_pl->f("level")) or ( $db->f("cloak_active") == 'f' ) ) {	
			
					srand((double)microtime()*1000000);
	
					if ( $db_2->f("alliance_id") <> $player->f("alliance_id") or $player->f("alliance_id") == 0 ) {
						$nonallied = $nonallied + 1;

						if ( rand(1,11) <= 3 ) {
			 	   		$nonallied = $nonallied + 1;
						}
					} else {
						$allied = $allied + 1;

						if ( rand(1,11) <= 2 ) {
							$allied = $allied + 1;
						}
					}
				}
			}
	
			echo "<table><tr>";
			echo "<td><font color=#cccccc  face=arial,helvetica,swiss size=2>Estimated non-allied ships: </font></td><td><font color=#cccccc  face=arial,helvetica,swiss size=2>" . $nonallied . "</font></td>";
			echo "<tr></tr>";
			echo "<td><font color=#cccccc  face=arial,helvetica,swiss size=2>Estimated allied ships: </font></td><td><font color=#cccccc  face=arial,helvetica,swiss size=2>" . $allied . "</font></td>";
			echo "</tr></table>";

			$query = sprintf("SELECT * from forces where sector_id = '%s'", $id);
			$db->query($query);

			$nonallied_drones = 0;
			$allied_drones = 0;
			$nonallied_mines = 0;
			$allied_mines = 0;

			while ( $db->next_record() ) {
				$query = sprintf("SELECT player_id, alliance_id from players where player_id = '%s'", $db->f("player_id"));
				$db_2->query($query);
			  $db_2->next_record();
			  srand((double)microtime()*1000000);
	
				if ( $db_2->f("alliance_id") <> $player->f("alliance_id") or ($player->f("alliance_id") == 0 and $db->f("player_id") == $player->f("player_id")) ) {
					$nonallied_drones = $nonallied_drones + $db->f("combat") + $db->f("scout");
					$nonallied_mines = $nonallied_mines + $db->f("mine");

					if ( rand(1,11) <= 3 ) {
						$nonallied_drones = $nonallied_drones + 1;
						$nonallied_mines = $nonallied_mines + 1;
					}
				} elseif ( $db_2->f("alliance_id") == $player->f("alliance_id") or $db->f("player_id") == $player->f("player_id") ) {				
					$allied_drones = $allied_drones + $db->f("combat") + $db->f("scout");
					$allied_mines = $allied_mines + $db->f("mine");

					if ( rand(1,11) <= 2 ) {
						$allied_drones = $allied_drones + 1;
						$allied_mines = $allied_mines + 1;
					}
				}
			}

			echo "<table><tr>";
			echo "<td><font color=#cccccc  face=arial,helvetica,swiss size=2>Estimated non-allied drones: </font></td><td><font color=#cccccc  face=arial,helvetica,swiss size=2>" . $nonallied_drones . "</font></td>";
			echo "<tr></tr>";
			echo "<td><font color=#cccccc  face=arial,helvetica,swiss size=2>Estimated allied drones: </font></td><td><font color=#cccccc  face=arial,helvetica,swiss size=2>" . $allied_drones . "</font></td>";
			echo "</tr></table>";
			echo "<table><tr>";
			echo "<td><font color=#cccccc  face=arial,helvetica,swiss size=2>Estimated non-allied mines: </font></td><td><font color=#cccccc  face=arial,helvetica,swiss size=2>" . $nonallied_mines . "</font></td>";
			echo "<tr></tr>";
			echo "<td><font color=#cccccc  face=arial,helvetica,swiss size=2>Estimated allied mines: </font></td><td><font color=#cccccc  face=arial,helvetica,swiss size=2>" . $allied_mines . "</font></td>";
			echo "</tr></table>";
		} else {
			echo "<br><font color=#cccccc  face=arial,helvetica,swiss size=2>&nbsp;Your ship's scanner cannot scan beyond the current sector.</font>";
		}
?>
						<br>
					</td>					
				</tr>
			</table>
		</td>
	</tr>
</table><br><?php

	}
} else {
	$error = 4;
}

if ( $error ) {
	$db = new ME_DB_Xml;	
	$db->add_parameter("title", "Error");
	
	if ($error == 1) {
		$db->add_parameter("message", "Password not entered.");		
	} elseif ($error == 2) {
		$db->add_parameter("message", "Incorrect password.");			
	} elseif ($error == 3) {
		$db->add_parameter("message", "Each player is allowed to own only one planet.");			
	} elseif ($error == 4) {
		$db->add_parameter("message", "Your merchant is currently not landed on a planet.");			
	}
	
	echo $db->get_transform("./xslt/message_box.xslt", "");
}
?>
</td>
<td valign=top align=right width=100%><?php

include("./messages_display.php");
echo $player->get_transform("./xslt/player.xslt", $player->get_xml());
include("./ship_display.php");
?>

</td></tr></table>
</body></html><?php

page_close();
?>
Return current item: Merchant Empires