function shipping_distance($start, $dest)
{
  global $playerinfo;
  global $shipinfo;
  global $level_factor;
  global $db, $dbtables;

  $retvalue[triptime] = 0;
  $query = $db->Execute("SELECT * FROM $dbtables[universe] WHERE sector_id=$start");
  $start = $query->fields;
  $query = $db->Execute("SELECT * FROM $dbtables[universe] WHERE sector_id=$dest");
  $dest = $query->fields;

  if($start[sector_id] == $dest[sector_id])
  {
    return 1;
  }

  $distance=calc_dist($start,$dest);
  if($distance<1) {
    $distance = 1;
    // TODO: The query failed. What now?
  }

  $shipspeed = mypw($level_factor, $shipinfo[engines]);
  $triptime = round($distance / $shipspeed);

  if(!$triptime && $destination != $playerinfo[sector])
    $triptime = 1;

  $triptime+=1;
  return $triptime;
}
function postcode_dist($mysqli, $postcode1, $postcode2)
{
    //Get lat and lon for postcode 1
    $query = "SELECT * FROM Post_Codes WHERE Latitude <> 0 and Longtitude <> 0 and Post_Code = '{$postcode1}' Limit 1";
    $result = $mysqli->query($query);
    $num = mysqli_num_rows($result);
    $query1 = "SELECT * FROM Post_Codes WHERE Latitude <> 0 and Longtitude <> 0 and Post_Code = '{$postcode2}' Limit 1";
    $result1 = $mysqli->query($query1);
    $num1 = mysqli_num_rows($result1);
    if ($num != 0 && $num1 != 0) {
        $row = mysqli_fetch_array($result, MYSQLI_ASSOC);
        $row1 = mysqli_fetch_array($result1, MYSQLI_ASSOC);
        //proceed
        $lat1 = $row["Latitude"];
        $lon1 = $row["Longtitude"];
        $lat2 = $row1["Latitude"];
        $lon2 = $row1["Longtitude"];
        $dist = calc_dist($lat1, $lon1, $lat2, $lon2);
        if (is_numeric($dist)) {
            return $dist;
        } else {
            return "Unknown";
        }
    } else {
        return "Unknown";
    }
}
Exemple #3
0
	  echo "$l_rs_movetime $l_rs_energy<BR><BR>";
	  if($triptime > $playerinfo[turns])
	  {
		echo "$l_rs_noturns";
	  }
	  else
	  {
		$l_rs_engage_link= "<A HREF=rsmove.php?engage=1&destination=$destination>" . $l_rs_engage_link . "</A>";
		$l_rs_engage=str_replace("[turns]",NUMBER($playerinfo[turns]),$l_rs_engage);
		$l_rs_engage=str_replace("[engage]",$l_rs_engage_link,$l_rs_engage);
		echo "$l_rs_engage<BR><BR>";
	  }
	}
	elseif($destination <= $sector_max && $engage == 1)
	{
	   $distance=calc_dist($playerinfo['sector'],$destination);
	
	  if($distance<1) {
		// TODO: The query failed. What now?
		$distance = 1;
	  }
	  $shipspeed = mypw($level_factor, $shipinfo[engines]);
	  $triptime = round($distance / $shipspeed);
	  if($triptime == 0 && $destination != $playerinfo[sector])
	  {
		$triptime = 1;
	  }
	  if($shipinfo[dev_fuelscoop] == "Y")
	  {
		$energyscooped = $distance * 100;
	  }
function Real_Space_Move($destination)
{
  global $db;
  global $dbtables;
  global $level_factor;
  global $username;
  global $lang;

  $res = $db->Execute("SELECT * FROM $dbtables[players] WHERE email='$username'");
  $playerinfo = $res->fields;
  // Check if player is on a planet or not
  if ($playerinfo[on_planet] == 'Y') {
	  echo "You cannot realspace when on a planet!<br><br>";
	  return("ON_PLANET");
  }	
  $res = $db->Execute("SELECT * FROM $dbtables[ships] WHERE player_id=$playerinfo[player_id] AND ship_id=$playerinfo[currentship]");
  $shipinfo = $res->fields;
  
  $distance=calc_dist($playerinfo['sector'],$destination);

  if($distance<1) {
    // TODO: The query failed. What now?
	$distance = 1;
  }

  $shipspeed = mypw($level_factor, $shipinfo[engines]);
  $triptime = round($distance / $shipspeed);






  if($triptime == 0 && $destination != $playerinfo[sector])
  {
    $triptime = 1;
  }


  if($playerinfo[dev_fuelscoop] == "Y")
  {
    $energyscooped = $distance * 100;
  }
  else
  {
    $energyscooped = 0;
  }

 
  if($shipinfo[dev_fuelscoop] == "Y" && $energyscooped == 0 && $triptime == 1)
  {
    $energyscooped = 100;
  }
  $free_power = NUM_ENERGY($shipinfo[power]) - $shipinfo[ship_energy];

  // amount of energy that can be stored is less than amount scooped amount scooped is set to what can be stored
  if($free_power < $energyscooped)
  {
    $energyscooped = $free_power;
  }

  // make sure energyscooped is not null
  if(!isset($energyscooped))
  {
    $energyscooped = "0";
  }

  // make sure energyscooped not negative, or decimal
  if($energyscooped < 1)
  {
    $energyscooped = 0;
  }

  // check to see if already in that sector
  if($destination == $playerinfo[sector])
  {
    $triptime = 0;
    $energyscooped = 0;
  }

  if($triptime > $playerinfo[turns])
  {
    $l_rs_movetime=str_replace("[triptime]",NUMBER($triptime),$l_rs_movetime);
    echo "$l_rs_movetime<BR><BR>";
    echo "$l_rs_noturns";
    $db->Execute("UPDATE $dbtables[players] SET cleared_defences=' ' where player_id=$playerinfo[player_id]");

    $retval = "BREAK-TURNS";
  }
  else
  {

// ********************************
// ***** Sector Defense Check *****
// ********************************

  $result99 = $db->Execute("SELECT * FROM $dbtables[players] LEFT JOIN $dbtables[sector_defence] ON ( $dbtables[players].player_id = $dbtables[sector_defence].player_id ) WHERE sector_id = $destination AND ( team = 0 OR team != $playerinfo[team] ) AND $dbtables[sector_defence].player_id != $playerinfo[player_id]");
  if(!$result99->EOF)
  {
	$retval = "HOSTILE";
	// need to add a language value for this
	echo "YOU CANNOT MOVE TO SECTOR $destination: THERE ARE HOSTILE SECTOR DEFENSES THERE!<br>";
  } else
  {
       $stamp = date("Y-m-d H-i-s");
       $update = $db->Execute("UPDATE $dbtables[players] SET last_login='******',sector=$destination,turns=turns-$triptime,turns_used=turns_used+$triptime WHERE player_id=$playerinfo[player_id]");
	   $update = $db->Execute("UPDATE $dbtables[ships] SET ship_energy=ship_energy+$energyscooped WHERE player_id=$playerinfo[player_id] AND ship_id=$playerinfo[currentship]");
       $l_rs_ready=str_replace("[sector]",$destination,$l_rs_ready);
   
       $l_rs_ready= str_replace("[triptime]",NUMBER($triptime),$l_rs_ready);
       $l_rs_ready=str_replace("[energy]",NUMBER($energyscooped),$l_rs_ready);
       echo "$l_rs_ready<BR>";
       $retval = "GO";	
  }
 }
  return($retval);
}