Anyone know PHP (or be willing to learn?)

It's what you think it is.
Post Reply
User avatar
The Mindset
Posts: 3079
Joined: Sat Apr 24, 2004 10:35 pm
Prefix: Den interstellera republik av
Name: The Mindset

Anyone know PHP (or be willing to learn?)

Post by The Mindset »

I know a few of you do/did computer science degrees here. PHP is a very simple language, with probably the best documentation other than MS's .NET stuff. If you know C/C++ you can probably pick up PHP in about an hour. The syntax is very standard, php.net has excellent primers on using code and I can help you with any queries you may have.

I'm not asking for advanced programming skills. Anything you cannot do (either because you don't understand my code or because you're not familiar with the methods I'm using - this especially applies to session security and database maintainence) - I can do.

So I'm making an appeal to any coders out there with some free time. I've included some code below that's part of the mapping code. If you can explain what it means in plain terms you might be able to help me!

Code: Select all

// Set this to false if the public can view this page.
$private_page = false;
include ('common/config.php');
include ('common/sessions.php');

// BEGIN MAIN CODE

	$map = new Map_Management();
	$gd = new GD_Management();
	
	// Get random system
	if ($_SESSION['logged_in'] == true) {
		if ($_GET['x'] || $_GET['y']) {
			$x = $_GET['x'];
			$y = $_GET['y'];
			$smarty->assign('x', $x);
			$smarty->assign('y', $y);
		}
		else {
			$system = $map->random_system($nation_id);
			$x = $system['x'];
			$y = $system['y'];	
			$smarty->assign('x', $x);
			$smarty->assign('y', $y);
		}
	}
	else {
		if ($_GET['x'] || $_GET['y']) {
			$x = $_GET['x'];
			$y = $_GET['y'];
			$smarty->assign('x', $x);
			$smarty->assign('y', $y);
		}
		else {
			$x = 500;
			$y = 500;
			$smarty->assign('x', $x);
			$smarty->assign('y', $y);
		}
	}
	if ($_GET['s']) {
		$x = $_GET['x'];
		$y = $_GET['y'];
		$system_id = $_GET['s'];
		$smarty->assign('system', 'true');
		$smarty->assign('y', $y);
		$smarty->assign('s', $s);
		$smarty->assign('x', $x);
	}
	// Variables
	
	switch ($_GET['mode']) {
		case 'img':
			$tiledimensions = 40;
			$mapdimension = 16;
			$src_img = "templates/map/blank.png";
			$image = imagecreatefrompng($src_img);
			
			// Colours
			$white = imagecolorallocate($image, 255, 255, 255);
			$influence = imagecreatefrompng("templates/map/influence.png");
						
			// Get map data
			$x = $_GET['x'];
			$y = $_GET['y'];
			$tile_array = $map->tile_array($x - 8, $y - 8, (16 + $x), (16 + $y));
			if (empty($tile_array)) {
				$tile_array[0] = 0;
			}
			
			foreach($tile_array as $coord_data) {
				$coords = $gd->convert_coords($x - 8, $y - 8, $coord_data['x'], $coord_data['y']);
				
				$sx = $coords['x'];
				$sy = $coords['y'];
				imagecolortransparent($influence,imagecolorat($influence,0,0));
				imagecopymerge($image, $influence, $sx - 20, $sy - 20, 0, 0, 80, 80, 35);
			}
			
			foreach($tile_array as $coord_data) {
				$coords = $gd->convert_coords($x - 8, $y - 8, $coord_data['x'], $coord_data['y']);
				
				$sx = $coords['x'];
				$sy = $coords['y'];
				
				if (substr($coord_data['type'], 0, 3) == "sun") {
					$type = $gd->sun_type($coord_data['type']);
					imagecolortransparent($type,imagecolorat($type,0,0));
				}
				else {
					$type = imagecreatefrompng("templates/map/".$coord_data['type'].".png");
					imagecolortransparent($type,imagecolorat($type,0,0));
				}
				imagecopymerge($image, $type, $sx, $sy, 0, 0, 40, 40, 100);
			} 

			
			header('Content-type: image/png');
			imagejpeg($image);
		break;
		
		case 'system':
			$tiledimensions = 40;
			$mapdimension = 16;
			$src_img = "templates/map/blank.png";
			$image = imagecreatefrompng($src_img);
			imagealphablending($image,true);
			imageantialias($image,true);
			$system_id = $_GET['s'];
			
			// Colours
			$white = imagecolorallocate($image, 64, 64, 64);
						
			// Get map data
			if (!$_GET['x'] || !$_GET['y']) {
				$x = 500;
				$y = 500;
			}
			else {
				$x = $_GET['x'];
				$y = $_GET['y'];
			}
			$tile_array = $map->tile_array_system($x - 8, $y - 8, (16 + $x), (16 + $y), $system_id);
			if (empty($tile_array)) {
				$tile_array[0] = 0;
			}
			
			
			$sun_x = 300;
			$sun_y = 300;
			
			
			foreach($tile_array as $coord_data) {
				$coords = $gd->convert_coords($x - 8, $y - 8, $coord_data['x'], $coord_data['y']);
				
				$sx = $coords['x'];
				$sy = $coords['y'];
				
				if (substr($coord_data['type'], 0, 3) != "sun") {
					// Find distance between planet and center of map
					$distance = ($gd->distance($sun_x, $sun_y, $sx + 20.0, $sy + 20.0))*2;
					$direction = $gd->direction($sun_x, $sun_y, $sx + 20.0, $sy + 20.0, $distance);
					
					if ($distance <= 250) {
						$ellipse = 2;
					}
					else {
						$ellipse = $sx/8;
					}
					
					rotatedellipse($image, $sun_x, $sun_y, $distance, $distance - $ellipse, $direction['dir'], $white);
				}
			}
			
			foreach($tile_array as $coord_data) {
				$coords = $gd->convert_coords($x - 8, $x - 8, $coord_data['x'], $coord_data['y']);
				
				$sx = $coords['x'];
				$sy = $coords['y'];
				
				if (substr($coord_data['type'], 0, 3) == "sun") {
					$type = $gd->sun_type($coord_data['type']);
					imagecolortransparent($type,imagecolorat($type,0,0));
				}
				else {
					$type = imagecreatefrompng("templates/map/".$coord_data['type'].".png");
					imagecolortransparent($type,imagecolorat($type,0,0));
				}
				
				imagecopymerge($image, $type, $sx, $sy, 0, 0, 40, 40, 100);
				
			} 
			
			header('Content-type: image/png');
			imagejpeg($image);
		break;
	}
	
	if (!$_GET['s']) {
		$tile_array = $map->tile_array($x - 8, $y - 8, (16 + $x), (16 + $y));
	} 
	else {
		if (!$_GET['x'] || !$_GET['y']) {
			$x = 500;
			$y = 500;
		}
		else {
			$x = $_GET['x'];
			$y = $_GET['y'];
		}
		$tile_array = $map->tile_array_system($x - 8, $y - 8, (16 + $x), (16 + $y), $_GET['s']);
	}
	foreach($tile_array as $coord_data) {
				$coords = $gd->convert_coords($x - 8, $y - 8, $coord_data['x'], $coord_data['y']);
				
				$tx = $coords['x'];
				$ty = $coords['y'];
				
				$bx = $tx + 40;
				$by = $ty + 40;
				
				if (!$_GET['s']) {
					$system_name = $map->name($coord_data['coord_id']);
					$owner = $nation->full_name($coord_data['owner']);
					$system_id = $coord_data['coord_id'];
					
					$areamap = $areamap . "<AREA
   HREF='map.php?s=$system_id' SHAPE=RECT COORDS='$tx,$ty,$bx,$by' onmouseover=\"Tip('<b>$system_name</b><br/>$owner<br/>Population: population', ABOVE, true, OFFSETY, 20, WIDTH, 200, TEXTALIGN, 'left', FADEIN, 100, FADEOUT, 100, PADDING, 8)\">";
   				}
				else {
					$system_name = $map->name($_GET['s']);
					$owner = $nation->full_name($coord_data['owner']);
					$population = number_format($coord_data['population']);

					$areamap = $areamap . "<AREA
   HREF='#' SHAPE=RECT COORDS='$tx,$ty,$bx,$by' onmouseover=\"Tip('<strong>$owner</strong><br/>$system_name<br/>Population: $population', ABOVE, true, OFFSETY, 20, WIDTH, 200, TEXTALIGN, 'left', FADEIN, 100, FADEOUT, 100, PADDING, 8)\">";
				}
	}
	$smarty->assign('areamap', $areamap);
	$smarty->display('game_map.tpl');
	
// END MAIN CODE
The Cerberus Alliance
ESUS Nipple-o-rama
Posts: 671
Joined: Tue May 01, 2007 1:45 am
Prefix: The Reclusive Protectorate of
Name: The Cerberus Alliance

Re: Anyone know PHP (or be willing to learn?)

Post by The Cerberus Alliance »

Well, for starters, it looks like the map decides on a nation's location only when the owner of that nation decides to look at the map.

The map view is centered on the user's nation, or on the location (500,500) if the user isn't logged in.

That's just what I think I could figure out from the first 30 or so lines of code.

I'll try and look at more of it later. I just have a bit of work to do right now.
This won't end well.
Siesatia
ESUS Testicle Monster
Posts: 1155
Joined: Fri Sep 17, 2004 3:33 am
Prefix: The Unified Worlds of
Name: Siesatia

Re: Anyone know PHP (or be willing to learn?)

Post by Siesatia »

I'll be willing to take up some PHP if it'll help.
Dear god... No more 5 year old Signature...

Proud ESUS Member since '04
User avatar
The Mindset
Posts: 3079
Joined: Sat Apr 24, 2004 10:35 pm
Prefix: Den interstellera republik av
Name: The Mindset

Re: Anyone know PHP (or be willing to learn?)

Post by The Mindset »

Can you demonstrate usage of PHP, particularly relating to database access and data processing? Do you know how to use SVN?
Post Reply