Topic: New Map File Creator

I've written a PHP script that generates an IC Map Gen mapfile without needing to be given the system data/family data. If someone wants to host it, that would be great (I don't have a domain for hosting random scripts I write). I've tried my best to keep the script short and simple. Anyway, enjoy!

<?php

if (isset($_POST['submit']))
{
    // Get the input and sanitize
    $galaxy_id = isset($_POST['g_id']) ? intval($_POST['g_id']) : 0;
    $systems_x = isset($_POST['x_coord']) ? intval($_POST['x_coord']) : 0;
    $systems_y = isset($_POST['y_coord']) ? intval($_POST['y_coord']) : 0;
    $sectors_x = isset($_POST['x_sectors']) ? intval($_POST['x_sectors']) : 0;
    $sectors_y = isset($_POST['y_sectors']) ? intval($_POST['y_sectors']) : 0;
    $description = isset($_POST['filename']) ? substr($_POST['filename'], 0, 32) : 'No information';

    // Validation is key!
    if ($galaxy_id <= 0)
        die('Invalid galaxy ID');

    if ($systems_x <= 0)
        die('Invalid horizontal coordinate count');

    if ($systems_y <= 0)
        die('Invalid vertical coordinate count');

    if ($sectors_x <= 0)
        die('Invalid horizontal sector count');

    if ($sectors_y <= 0)
        die('Invalid vertical sector count');

    // First, we fill the systems array with 0s
    $systems = array_fill(0, $systems_x * $systems_y, 0);

    // Next, we mark all the systems that exist
    for ($i = 1; $i <= $sectors_x; ++$i)
    {
        for ($j = 1; $j <= $sectors_y; ++$j)
        {
            $map_data = file_get_contents('http://www.imperialconflict.com/maps/'.$galaxy_id.'.'.$i.'.'.$j.'.html');

            $systems_found = array();
            preg_match_all('/onmousedown\=w\(([0-9]+)\,([0-9]+)\)/', $map_data, $systems_found);

            for ($k = 0; $k < count($systems_found[1]); ++$k)
            {
                $system_index = (($systems_found[2][$k] - 1) * $systems_x) + ($systems_found[1][$k] - 1);
                $systems[$system_index] = 1;
            }
        }
    }

    // Finally, we grab family data and mark all the homesystems
    $families = array();
    $family_data = strip_tags(file_get_contents('http://www.imperialconflict.com/rankings.php?type=topfamilies_size&g='.$galaxy_id));

    $families_found = array();
    preg_match_all('/[0-9]+.*?\(([0-9]+)\).*?\[([0-9]+),([0-9]+)\]/s', $family_data, $families_found);

    for ($i = 0; $i < count($families_found[1]); ++$i)
    {
        $system_index = (($families_found[3][$i] - 1) * $systems_x) + ($families_found[2][$i] - 1);

        $families[$families_found[1][$i]] = $system_index;
        $systems[$system_index] = 129;
    }


    // Yay for binary file formats
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename="'.str_replace('"', '\'', $description).'.dat";');

    echo "ICg3"; # Header!
    echo pack('V', $systems_x); # The map size in the x direction
    echo pack('V', $systems_y); # The map size in the y direction
    echo pack('V', $sectors_x); # The number of sectors in the x direction
    echo pack('a32', $description); # The description
    echo pack('a64', 'http://www.imperialconflict.com/system.php?x=%d&y=%d'); # url to system page

    // Pack in the system data
    foreach ($systems as $system_info)
        echo pack('C', $system_info);

    // The number of families
    echo pack('V', count($families));

    // The family homesystems and corresponding family numbers
    foreach ($families as $homesystem_info)
        echo pack('V', $homesystem_info);
    foreach ($families as $family_number => $homesystem_info)
        echo pack('V', $family_number);

    // The number of sectors in the y direction
    echo pack('V', $sectors_y);
    exit;
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <title>Semi-Automatic Map File Creator</title>
        <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    </head>
    <body>
        <form action="<?php echo htmlspecialchars($_SERVER['REQUEST_URI']) ?>" method="post" enctype="multipart/form-data">
            Horizontal coordinate count: <input type="text" name="x_coord" /><br />
            Vertical coordinate count: <input type="text" name="y_coord" /><br />
            Horizontal sector count: <input type="text" name="x_sectors" /><br />
            Vertical sector count: <input type="text" name="y_sectors" /><br />
            Galaxy Description: <input type="text" name="filename" /><br />
            Galaxy ID: <input type="text" name="g_id" /><br />
            <input type="submit" name="submit" value="Create!" />
        </form>
    </body>
</html>
CLEAR YOUR CACHE!
http://www.microsoft.com/windows/ie/usi … cache.mspx

Do not read this fortune under penalty of law.
Violators will be prosecuted.
(Penal Code sec. 2.3.2 (II.a.))

Re: New Map File Creator

Whoa, I had no idea /maps/ existed and was accessible without logging in!


Nice script

Rehabilitated IC developer

Re: New Map File Creator

is there a reason stefan can't host it on the IC server?

Never attribute to malice that which is adequately explained by stupidity.

Re: New Map File Creator

thirdrock: Physically? No. It's fairly standard PHP (although it relies on allow_url_fopen being enabled). He's welcome to do so, in fact: he could even use this script as the basis for a script that automatically generates a mapfile when a galaxy is created. My guess is it'll happen when pigs fly though. tongue

quazbut: Thanks for hosting it. smile

CLEAR YOUR CACHE!
http://www.microsoft.com/windows/ie/usi … cache.mspx

Do not read this fortune under penalty of law.
Violators will be prosecuted.
(Penal Code sec. 2.3.2 (II.a.))

Re: New Map File Creator

Fantastic smile

I'll look at this in more detail tomorrow big_smile

Re: New Map File Creator

Legend!

Your = possessive. As in, "your grammar sucks."
You're = you are. As in, "you're an idiot for not knowing the difference."

Re: New Map File Creator

so how to use this? what do i put as galaxy ID to get it to work etc?

LORD HELP OREGON

Re: New Map File Creator

i wanna use it if it works!!!

LORD HELP OREGON

Re: New Map File Creator

It aint working yikes

Re: New Map File Creator

Mw=1
Sd=4
Pw=6

CLEAR YOUR CACHE!
http://www.microsoft.com/windows/ie/usi … cache.mspx

Do not read this fortune under penalty of law.
Violators will be prosecuted.
(Penal Code sec. 2.3.2 (II.a.))

Re: New Map File Creator

I just tried it with SD and it does generate a file. If there's something wrong with the file, let me know.

CLEAR YOUR CACHE!
http://www.microsoft.com/windows/ie/usi … cache.mspx

Do not read this fortune under penalty of law.
Violators will be prosecuted.
(Penal Code sec. 2.3.2 (II.a.))

Re: New Map File Creator

something is$

u get a file but no systems in it xd

Re: New Map File Creator

well i did 4 but got an empty map

LORD HELP OREGON

Re: New Map File Creator

Horizontal coordinate count: 100
Vertical coordinate count: 100
Horizontal sector count: 2
Vertical sector count: 2
Galaxy Description: SD
Galaxy ID: 4

I tried that and got a blank map. I also tried 101 for the horizontal and vertical counts and got a blank one with those also. I'm using firefox

2011 IC League Fantasy Football Champion
2012 IC League Fantasy Football Runner Up
2013 IC League Fantasy Football Champion

http://www.ic-wiki.com/index.php?title=Gondor

Re: New Map File Creator

it works guys.. you just need to put the full galaxy name in the "Galaxy Description" part, ie: Sagittarius Dwarf for this one..

<@Nick> it always scares me when KT gets all dominatrixy
* I_like_pie is now known as pie|bbl
<@KT|afk> Look at him run!
<@Nick> if you tell him to slap you and call you mommy
<@Nick> i'm leaving and never coming back

Re: New Map File Creator

Smartys don't be lazy X( make drop down lists for galaxy names and galaxy IDs X(

2011 IC League Fantasy Football Champion
2012 IC League Fantasy Football Runner Up
2013 IC League Fantasy Football Champion

http://www.ic-wiki.com/index.php?title=Gondor

Re: New Map File Creator

haha I still get no systems.

Re: New Map File Creator

then you suck. mind you, I was using Chrome. maybe it's a firefox issue?

<@Nick> it always scares me when KT gets all dominatrixy
* I_like_pie is now known as pie|bbl
<@KT|afk> Look at him run!
<@Nick> if you tell him to slap you and call you mommy
<@Nick> i'm leaving and never coming back

Re: New Map File Creator

doesn't work with IE either yikes

Re: New Map File Creator

i refer to my earlier post.. use chrome..

<@Nick> it always scares me when KT gets all dominatrixy
* I_like_pie is now known as pie|bbl
<@KT|afk> Look at him run!
<@Nick> if you tell him to slap you and call you mommy
<@Nick> i'm leaving and never coming back

21

Re: New Map File Creator

Gina can download map files automatically. If you're willing to give http://www.petrolstone.com/gina.php a try there is no need to mess with this. It is a very good script though Smartys.

Rehabilitated IC developer

Re: New Map File Creator

it misses something when it saves the file (well apart from not appearing to not save in hex like mapgen uses)  in the link to the map it's not adding the &g= part.

<@Nick> it always scares me when KT gets all dominatrixy
* I_like_pie is now known as pie|bbl
<@KT|afk> Look at him run!
<@Nick> if you tell him to slap you and call you mommy
<@Nick> i'm leaving and never coming back

23 (edited by AntBriWes 27-Apr-2010 00:21:26)

Re: New Map File Creator

Even putting in the full galaxy name I'm still having issues. Anyone know what round this is for SD?

[EDIT] I tried it with the other galaxies and get the same result. An empty map file. :s

< Naturally curious >

Re: New Map File Creator

Gondor: No. I deliberately didn't do that so it wouldn't have to be updated when galaxies were added/removed. Anyone is free to improve the script, of course, but I'm not hosting it anywhere: the website it's running on isn't mine.
Petrolstone: I wrote this almost a year ago when the original map generator temporarily broke wink

I'll download IC Map Gen again and test it out.

CLEAR YOUR CACHE!
http://www.microsoft.com/windows/ie/usi … cache.mspx

Do not read this fortune under penalty of law.
Violators will be prosecuted.
(Penal Code sec. 2.3.2 (II.a.))

Re: New Map File Creator

Smartys, if you figure out what needs to be done to the code would you mind posting it? I have it semi-hosted locally while still pulling some of the info from quazbuts site. If I get the changes I'll atleast be able to make the mapfile and upload it for everyone.

< Naturally curious >