INI parsing isn't that hard if you have decrypted inis (all mods I've seen where, but standard installs start encrypted), not sure how hard it is to decrypt them (just get "bini" if your inis aren't legible). Here's a sample ini parser written in PHP:
Code:
$names = file("universe.ini"); //Loads each line of input file into a node in an array
foreach($names as $line){ //Loop through all nodes of array, current node will be assigned to $line
if(preg_match('/^\[(.*)\]/',$line,$matches)){ //This REGEX searches for text within [ and ]. if found, it saves the text as node 1 of $matches
if($matches[1] == "Base"){ //If the contents are "Base", set a flag to true
$adding = true;
}else{ //All other possible entries in universe.ini I want to ignore for this script, so turn off my flag
$adding = false;
}
}
if($adding){ //So, if we're adding, that means we're looking somewhere after "[Base]", but before some other [ ] text
if(preg_match('/^nickname = (.*)$/',$line,$matches)){ //REGEX to check for a line that reads "nickname = ". Capture any text after the "=" if found
echo $matches[1]."<BR>"; //Prints, for debugging
$name = tr($matches[1]); //Save the name, used later because I'm making an array of bases
}
if(preg_match('/^strid_name = (.*)$/',$line,$matches)){ //REGEX for the DLL's string table id (a number that points to a string, the number will be something like 1003, and the text could be something like "Planet New York")
//echo $matches[1]."<BR>"; //Commented out, but would print the string id
$names[$name] = tr($matches[1]); //$names is my array of bases, and $name is the base name I saved up above. the function tr (by the way) just cuts off any newline characters on the end of my string. I'm setting up an array off base names and the string ids for use later
}
if(preg_match('/^system = (.*)$/',$line,$matches)){ //The system field, will be something like "BR01"
$system = tr($matches[1]); //Hold on to the system name, we will reference this much like "$name" from earlier
if(!array_key_exists($system,$files)){ //array_key_exists will be true if I've already entered this system, I only want to load each file once (efficiency and preference, not mandatory)
$f = file("systems/".$system."/".$system.".ini"); //Load the given system ini file
foreach($f as $lines){ //We're searching out "Objects" this time, but the process is the same
if(preg_match('/^\[(.*)\]/',$lines,$match)){
if($match[1]=="Object"){
$adding2 = true;
}else{
$adding2 = false;
}
}
if($adding2){ //As a note, if we came across a [Asteroids] entry (for example), the above code would turn $adding2 to false, so no processing, just loop to the next line and check for [Object]
if(preg_match('/^pos = (.*),(.*),(.*)$/',$lines,$match)){ //The pos field is stored in the ini as X,Y,Z and I want all three of them
$pos[0] = tr($match[1]);
$pos[1] = tr($match[2]);
$pos[2] = tr($match[3]);
$pos[3] = $system; //Save the system name as well
}
if(preg_match('/^base = (.*)$/',$lines,$match)){ //This line will reference which base is at the above location
$name = tr($match[1]); //grab the base name
$base[$name] = $pos; //Assign the position array (along with parent system) to our $base array
}
}
}
$files[$system] = true; //Set our $files array for this system name to true, so we don't parse it again
}
}
}
}
Now I left out the part just after all this where I actually use the data I've parsed, but you only asked for a parser
If you need more info on how I'm doing this, or help converting the code over to something C/VB compatable, let me know.
Distance measurement isn't hard:
A = starting X position
B = starting Y position
C = starting Z position
X = ending X position
Y = ending Y position
Z = ending Z position
Distance = sqrt(sqrt((max(A,X)-min(A,X))^2+(max(B,Y)-min(B,Y))^2)^2+(max(C,Z)-min(C,Z))^2)
Or in mathematical-esque speak: use the pythagorean theorem with the change in X and change in Y, then take that distance as a variable for a second pathagorian theorum with your change in Z.
The tricky part is using that information
I have three related questions, how do you (Wizou) determine the best path? Did you use the systems_shortest_path.ini, or do you try all possibilities and discard all but the fastest for each destination? Also, when compantion wants you to abandon trade lanes midway down one, is it at a gate only, or did you calculate the perpendicular and abandon the trade lane at the closest possible point? Lastly, from point to point (I'll say from a base to a jump hole) do you calculate the travel time as a straight path, then calculate again using possible trade lanes, and take the best, or do you have a better method to decide when to use lanes and when to use cruise engines?