Source

Selador / welt.php

Full commit
<?php

/* welt.php - Front-end code for the map view page
 *
 * Copyright (C) 2006, 2007, 2008 Kevin Read, Simone Schaefer
 *
 * This file is part of Selador, a browser-based fantasy strategy game
 *
 * This program is distributed under the terms of the GNU Affero General Public License.
 *
 *
 *   Selador is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU Affero General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   any later version.
 *
 *   Selador 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 Affero General Public License for more details.
 *
 *   You should have received a copy of the GNU Affero General Public License
 *   along with Selador.  If not, see <http://www.gnu.org/licenses/>.
 **/

// We also cache here, beware.

require_once("php/base/world.inc.php");
require_once("php/base.php");
require_once("php/event.php");
require_once("headers.php");

$highlight = false;

if (isset($_GET['h']))
{
	$highlight=true;
	$x_orig = $_GET['x'];
	$y_orig = $_GET['y'];
}
$coords = array();
if (isset($_POST['search']))
{
	if (strlen($_POST['playername']) > 0)
	{
		$player = mysql_real_escape_string(trim($_POST['playername']));
		$query = 'select x,y from village,user where village.uid=user.uid and user.user="'.$player.'"';//" limit 1';
	}
	if (strlen ($_POST['allytag']) > 0)
	{
		$tag = mysql_real_escape_string(trim($_POST['allytag']));
		$query = 'select x,y from village,user,allies where village.uid=user.uid and user.aid=allies.aid and allies.tag="'.$tag.'"';//" limit 1';
	}
	$highlight=true;
	
	$x_orig = array();
	$y_orig = array();
	//echo $query;
	if ($res = mysql_query($query))
	{
		while ($row = mysql_fetch_array($res))
		{
			$coords[$row['x']] = $row['y'];
			$x = $row['x'] % $world->sizex;
			$y = $row['y'] % $world->sizey;
			
			$x = (int)($x/MAP_NUMFIELDS);
			$y = (int)($y/MAP_NUMFIELDS);

			$x = max (0, min ($x, (int)($world->sizex/MAP_NUMFIELDS)-1));
			$y = max (0, min ($y, (int)($world->sizey/MAP_NUMFIELDS)-1));
			//$y_orig['villageid'] = $row['y'];
		}
		
		$_SESSION['coords'] = $coords;

		//echo '<h1>x: '.$x.', y: '.$y.'</h1>';
	}
	else
	{
		$me->log_err('Could not read player/ally villages in welt.php: '.$query);
	}
}
else
{
	
	//else
	{
		if (isset($_SESSION['coords']))
		{
			$coords = $_SESSION['coords'];
			$highlight=true;
		}
		// Did we get a position to display (or enhance) from the user?
		if ((isset ($_GET['x'])) && (isset ($_GET['y'])))
		{
			$x = $_GET['x'] % $world->sizex;
			$y = $_GET['y'] % $world->sizey;

			$x = (int)($x/MAP_NUMFIELDS);
			$y = (int)($y/MAP_NUMFIELDS);

			$x = max (0, min ($x, (int)($world->sizex/MAP_NUMFIELDS)-1));
			$y = max (0, min ($y, (int)($world->sizey/MAP_NUMFIELDS)-1));
		}
		else
		{
			// If there is an active outpost
			if ($me->activeoutpostid)
			{
				// We set this as the displayed location
				$x = $me->activeoutpost->x;
				$y = $me->activeoutpost->y;
			}
			else
			{
				// No, so we set as starting position the location of the active village
				$x = $me->activevillage->x;
				$y = $me->activevillage->y;
			}
		  // No, so we set as starting position the location of the active village
		  $x = (int)($x/MAP_NUMFIELDS);
		  $y = (int)($y/MAP_NUMFIELDS);
		  $z = $y * (int)($world->sizex/20) + $x;
		  
		unset ($_SESSION['coords']);
		unset($coords);//world view is freshly opened. we don't want to see that old crap anymore. 
		}
	}
}


// Handle past events
// $me->event_handler (true, $me->activevillageid, $gui);

// Then calculate ressources through checking income - this takes into account
// past events, because event_handler might have updated $secspassed
// $me->activevillage->do_income ();

$me->activevillage->update_stamp ();
// We include basic design parts here
require_once ("styles/php/base_design-".$_SESSION['theme'].".php");
require_once("blocked.php");
$xsize=MAP_NUMFIELDS*3*16;
$xorig=(int)($xsize-764)/2;
$ysize=MAP_NUMFIELDS*3*8;

// We should pass this on to the tutorial, if it is still going strong
if (is_object ($tutorial))
{
	if ($tutorial->active)
		$tutorial->is_in_world ();
}

echo "<div id=\"mapbox\"><div id=\"mapkarte\">\n";
echo "<img src=\"map/pergament6.jpg\">";
// echo "<div id=\"karte\">\n";
for ($ywalk=($y-1); $ywalk <= ($y+1); $ywalk++)
{
  for ($xwalk=($x-1); $xwalk <= ($x+1); $xwalk++)
  {
    $karteid++;

    /* $xwm = max ((int)($world->sizex/MAP_NUMFIELDS), min (0, $xwalk % (int)($world->sizex/MAP_NUMFIELDS)));
    $ywm = max ((int)($world->sizex/MAP_NUMFIELDS), min (0, $ywalk % (int)($world->sizey/MAP_NUMFIELDS);

    if ($xwm >= 0)
      $xwm += (int)($world->sizex/MAP_NUMFIELDS);
    if ($ywm < 0)
      $ywm += (int)($world->sizey/MAP_NUMFIELDS); */

    $xwm = $xwalk;
    $ywm = $ywalk;
//    echo "xwalk ".$xwalk.", ywalk ".$ywalk." xwm ".$xwm." ywm ".$ywm."<br>\n";

    $precalcpath = MAP_PATH.$xwm.".".$ywm.".gif";
    if (!file_exists ($precalcpath))
    {
      require_once ("php/draw_map2.php");
      draw_map ($xwm*MAP_NUMFIELDS, $ywm*MAP_NUMFIELDS, $precalcpath, 3);
    }
    echo "<img id=\"map".$karteid."\" src=\"var/premap/".$xwm.".".$ywm.".gif\">\n";
  }
}

$todostr = "a";

// print_r ($me->allydipl);

require_once ("php/draw_map2.php");
draw_specials ($x*MAP_NUMFIELDS, $y*MAP_NUMFIELDS, $precalcpath, 3, $me->uid, MAP_NUMFIELDS * 3, $highlight, $x_orig, $y_orig);


echo '
	<!--</div>-->
	<div id="bottom">
		<div id="infos-welt">
			<table>
				<tr>
					<td>Koordinaten: </td>
					<td><span id="X">'.$x.'</span><span id="Y">'.$y.'</span></td>
				</tr>
				<tr>
					<td>Stadt: </td>
					<td><b><span id="VNAME">&nbsp;</span></b><span id="VSCORE">&nbsp;</span></td>
				</tr>
				<tr>
					<td>Spieler: </td>
					<td><b><span id="PLAYER">&nbsp;</span></b><span id="SCORE">&nbsp;</span></td>
					</tr>
				<tr>
					<td>Allianz: </td>
					<td><span id="TAG">&nbsp;</span></td>
				</tr>
			</table>
		</div>
		<div id="world-legend" >
			<table>
				<tr>
					<td><img width="9" src="map/overland/d.gif"></td>
					<td>Eigene St&auml;dte</td>
					<td><img width="9" src="map/overland/d4.gif"></td>
					<td>Fremde</td>
				</tr>
				<tr>
					<td><img width="9" src="map/overland/da.gif"></td>
					<td>Ally-Kollegen</td>
					<td><img width="9" src="map/overland/da1.gif"></td>
					<td>Verb&uuml;ndet</td>
				</tr>
				<tr>
					<td><img width="9" src="map/overland/da2.gif"></td>
					<td>NAP</td><td><img width="9" src="map/overland/da3.gif"></td>
					<td>HAB</td>
				</tr>
				<tr>
					<td><img width="9" src="map/overland/da4.gif"></td>
					<td>Meta</td>
					<td><img width="9" src="map/overland/da5.gif"></td>
					<td>Krieg</td>
				</tr>
			</table>
		</div>
	</div>
	<div id="worldsearch">
		<form name="world" action="welt.php" method="POST">
			Spieler <input type="text" name="playername" value="" size="12"><br>
			Allianz <input type="text" name="allytag" value="" size="12"><br>
			<input type="submit" name="search" value="suchen">
		</form>
	</div>
</div>';

require_once("footer.php");
?>