<?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"));
include("./merchantempiresdefines.php");
$sess->register("player_id");
include("./lib/ship.php");
include("./lib/ship_miscellaneous.php");
include("./lib/player.php");
include("./lib/player_map.php");
include("./lib/player_alliance.php");
include("./lib/sector.php");
include("./lib/player_redirect.php");
if ( $player_id > 0 ) {
# update player turns
$player = new ME_Player;
$player->get_player($player_id);
$turns = $player->f("turns");
$newturns = $player->f("newturnsleft");
# only move if the player has a turn
if ( ($player->f("turns") - 10) >= 0 ) {
if ( $newturns > 0 ) {
$player->set_new_turns_left($newturns - 10);
}
#determine if its possible to move to the target sector
$s1 = new ME_Sector;
$s1->get_sector($player_id);
$db = new ME_DB;
$db_2 = new ME_DB;
$query = sprintf("select * from warps where sector_id = '%s'", $s1->f("sector_id"));
$db->query($query);
$db->next_record();
if ( $db->nf() > 0 ) {
$db_2 = new ME_DB;
$query = sprintf("select * from sectors where sector_id = '%s'", $db->f("destination_sector_id"));
$db_2->query($query);
$db_2->next_record();
$ship = new ME_Ship;
$ship->get_ship($player_id);
$ship->set_sector_id($db_2->f("sector_id"));
$ship->set_last_move_sector_id($ship->f("sector_id"));
$ship->set_public_sector_id($db_2->f("public_sector_id"));
$ship->save();
save_player_map($db_2->f("map_id"), $player, $db_2->f("sector_id"));
$db_m = new ME_DB;
$query = sprintf("select * from forces where sector_id = '%s' and player_id <> '%s'", $db_2->f("sector_id"), $player->f("player_id"));
$db->query($query);
if ( $db->nf() > 0 ) {
$date = date("H:i m/d/y");
$date_integer = time();
$treaties = get_treaties($player->f("alliance_id"), 'Free Movement');
$tactical_defense = get_tactical_defense($ship, $player->f("level"));
while ( $db->next_record() ) {
if ( $db->f("alliance_id") <> $player->f("alliance_id") or $db->f("alliance_id") == 0 ) {
if ( $ship->f("cloak_active") == 't' and $ship->f("cloak") ) {
# nothing
} elseif ( $db->f("focused_alliance_id") <> 0 and $db->f("focused_alliance_id") <> $player->f("alliance_id") ) {
# nothing
} elseif ( $db->f("focused_player_id") <> 0 and $db->f("focused_player_id") <> $player->f("player_id") ) {
# nothing
} elseif ( $db->f("scout") > 0 ) {
$scout_player_id = $db->f("player_id");
$query = "select player_id, message_id from messages where player_id = '$scout_player_id' and scout = 't' order by message_id";
$db_m->query($query);
$db_m->next_record();
if ( $db_m->nf() > 50 ) {
$message_id = $db_m->f("message_id");
$query = "delete from messages where message_id = '$message_id'";
$db_m->query($query);
}
$message = "Movement detected in sector " . $db_2->f("public_sector_id");
$message = $message . "<br>Merchant: " . addslashes($player->f("name"));
$message = $message . "<br>Alliance: " . addslashes($player->f("alliance_name"));
$message = $message . "<br>Ship type: " . $ship->f("type");
$message = $message . "<br>Entered via: worm hole";
$query = "insert into messages (player_id, message, date, toplayer, scout, date_integer)
values ('$scout_player_id', '$message', '$date', 'Drone Comm Link', 't', '$date_integer')";
$db_m->query($query);
}
}
if ( $player->f("newturnsleft") == 0 and $db->f("mine") > 0 ) {
if ( $db->f("alliance_id") <> $player->f("alliance_id") or $db->f("alliance_id") == 0 ) {
if ( $db->f("focused_alliance_id") <> 0 and $db->f("focused_alliance_id") <> $player->f("alliance_id") ) {
# nothing
} elseif ( $db->f("focused_player_id") <> 0 and $db->f("focused_player_id") <> $player->f("player_id") ) {
# nothing
} elseif ( in_array($db->f("alliance_id"), $treaties) ) {
# nothing
} else {
if ( $db->f("mine") <= 5 ) {
$percent_escape = 35;
} elseif ( $db->f("mine") > 5 and $db->f("mine") <= 10 ) {
$percent_escape = 25;
} elseif ( $db->f("mine") > 10 and $db->f("mine") <= 20 ) {
$percent_escape = 20;
} elseif ( $db->f("mine") > 20 and $db->f("mine") <= 30 ) {
$percent_escape = 15;
} elseif ( $db->f("mine") > 30 and $db->f("mine") <= 40 ) {
$percent_escape = 10;
} elseif ( $db->f("mine") > 40 ) {
$percent_escape = 5;
}
if ( $ship->f("cloak") and $ship->f("cloak_active") == 't' ) {
$percent_escape = $percent_escape + 10;
}
$num = rand(1,100);
if ( $num > $percent_escape + $tactical_defense ) {
$returnto = "attack";
$id = $db->f("forces_id");
$type = "m";
$refer = "moveto";
}
}
}
}
}
}
$player->set_turns($turns - 10);
$player->save();
} else {
// nothing
}
}
if ($returnto == "currentsector") {
$newurl = $sess->url(URL . "current_sector.php");
header("Location: $newurl");
} elseif ($returnto == "attack") {
$newurl = $sess->url(URL . "attack.php" . "?refer=" . $refer . "&id=" . $id . "&type=" . $type );
header("Location: $newurl");
} else {
$newurl = $sess->url(URL . "local_map.php");
header("Location: $newurl");
}
}
page_close();
?>