Newlines in FBI files

Newlines in FBI files

Discuss game development here, from a distinct game project to an accessible third-party mutator, down to the interaction and design of individual units if you like.

Moderator: Moderators

Post Reply
User avatar
Maelstrom
Posts: 1950
Joined: 23 Jul 2005, 14:52

Newlines in FBI files

Post by Maelstrom »

Are tags in FBI/TDF/SMD files allowed to be on the same line like

Code: Select all

name=Commander;unitname=ARMCOM;
or do they have to be on seperate lines? If they HAVE to be on seperate lines it makes writing file parsing things alot easier to write.
User avatar
Maelstrom
Posts: 1950
Joined: 23 Jul 2005, 14:52

Post by Maelstrom »

Tested it out myself, and you can leave out the newlines. Whitespace and Newlines are completly optional. The following it a valid line:

Code: Select all

[CANBUILD]{[ARMCOM]{canbuild1=ARMSOLAR;canbuild2=ARMWIN;}}
Damn, that makes my life just that little bit harder...
User avatar
BvDorp
Posts: 439
Joined: 14 Oct 2005, 12:09

Post by BvDorp »

you can do it.. ;)
User avatar
Maelstrom
Posts: 1950
Joined: 23 Jul 2005, 14:52

Post by Maelstrom »

Ive done it in VB, but I have no idea how to do it in php so that it can parse ~500 files in under 30 seconds. It has to be under 30 seconds cause thats the default timeout for scripts in PHP, and not everyone can change that setting. Ive got it working alright currently, but its not perfect. It can parse unit files, but it cant parse files with sub-sections. Im trying to make one, and I am slowly getting there, but it isnt easy.
User avatar
PauloMorfeo
Posts: 2004
Joined: 15 Dec 2004, 20:53

Post by PauloMorfeo »

Maelstrom wrote:Tested it out myself, and you can leave out the newlines. Whitespace and Newlines are completly optional. The following it a valid line:

Code: Select all

[CANBUILD]{[ARMCOM]{canbuild1=ARMSOLAR;canbuild2=ARMWIN;}}
Damn, that makes my life just that little bit harder...
Indeed those are workfull news...
Maelstrom wrote:... I have no idea how to do it in php so that it can parse ~500 files in under 30 seconds. ...
You don't. You parse the files with some program, like vb, taking as long as you want, and fill a database. Then the php accesses the database.

But, i supose it's regarding this:
Maelstrom wrote:For those interested in unit pages like AA's [http://www.planetannihilation.com/aa/guide60/index.htm]Unit Guide[/url] I am working on a little php script to do something similar. You can see it here:
http://210.11.113.96/modweb/unit.php?unit=armcom

Its no where near finished yet, but is getting there slowly. It loads all the fbi files in a folder into a database, ...
Where you're saying you're filling a database. If you have the databse filled, why would you want to be accessing the mod's structure directly from the files with php?

Anyway, that's interesting. How is the structure of that database you're using?
I can upload the one i'm using for my program (the most recent version).
User avatar
Maelstrom
Posts: 1950
Joined: 23 Jul 2005, 14:52

Post by Maelstrom »

This is for http://210.11.113.96/modweb/unit.php?unit=armcom, yes.
PauloMorfeo wrote:
Maelstrom wrote:... I have no idea how to do it in php so that it can parse ~500 files in under 30 seconds. ...
You don't. You parse the files with some program, like vb, taking as long as you want, and fill a database. Then the php accesses the database.
Not everyone has the ability to run programs on their webserver, as most people rent space from a web host. So im making this all in PHP so everyone can use it. Plus you can run it on linux, unlike VB programs.
PauloMorfeo wrote:Where you're saying you're filling a database. If you have the databse filled, why would you want to be accessing the mod's structure directly from the files with php?
The way this thing will work is like this:
Dump all the FBI files into a FBI folder.
Run the LoadUnits.php script, which opens up the FBI files and dumps them in the database.
Grab the data from the database as needed, which you can see happening in that link i posted at the top.
PauloMorfeo wrote:Anyway, that's interesting. How is the structure of that database you're using?
I can upload the one i'm using for my program (the most recent version).
The way im doing it is in no way the most efficient way of doing it. But, with my somewhat limited PHP/MySQL skills (im still learning half the stuff as I go), the only way I could conceviably do it. The structure is like this:

Code: Select all

Unit Table:
  id - Not used for anyhting, just the key
  unitname - The unitname of the unit. ARMCOM for the commander, ect. Read from the FBI files
  stat - the name of the property. 'description' for 'description=Commander'
  value - the value of the property. 'Commander' for 'description=Commander'
When filled out, the unit table will look a little like this:

Code: Select all

| id | unitname | stat       | value     |
+------+----------+------------+---------+
| 1  | ARMCOM   | name       | Commander |
| 2  | ARMCOM   | unitname   | ARMCOM    |
| 3  | ARMCOM   | metalcost  | 12345     |
| 4  | ARMCOM   | energycost | 234567    |
| 5  | CORCOM   | name       | Commander |
| 6  | CORCOM   | untiname   | CORCOM    |


Again, this would not be the most efficient way to do things. But short of altering the table's layout by adding a new column for every new tag, this is the only way I could think of doing it. And I dont really want to alter the table, as that could just get confusing.

If your database is better than this, please send it over, as I would be happy to improve my design.



Also, ive been thinking of a way of loading in alot of files, and I think ive come up with a good way of doing it.

Code: Select all

function ParseFile($fileString)
  {
  
  $file = array();
  
    //Loop through each character in the file
  for ($i++ while $i < strlen($fileString))
    {
    $chr = character $i in $fileString;
    switch ($chr)
      {
        //Begining of a [section]
      case "[": 
        $sectionName = string between $i and the next "]";
        $newFileString = string between $i and the closing '}';
        $file[$sectionName] = ParseFile($newFileString);
        $i = position of the closing "}"
        
        //Its a setting.
      default:
        $setting = string betweem $i and the next ";";
        $file[bit before the "="] = bit after the "=";
        $i = position of the ";"l
      }
    }
  }
The above code, when its working, would output something like this:

Code: Select all

$file = Array
  (
  Setting1 = Value;
  Setting2 = Value;
  Section = Array
    (
    Setting3 = Value;
    Setting4 = Value;
    )
  )
With as many nested arrays as the file has. You would access the values like so:
$file['SectionName']['SubSection']['Setting'] = 'Value';

Again, this probably isnt the best way of doing things, but its all I can come up with. Any input is welcome.
User avatar
PauloMorfeo
Posts: 2004
Joined: 15 Dec 2004, 20:53

Post by PauloMorfeo »

Maelstrom wrote:...

Code: Select all

| id | unitname | stat       | value     |
+------+----------+------------+---------+
| 1  | ARMCOM   | name       | Commander |
| 2  | ARMCOM   | unitname   | ARMCOM    |
| 3  | ARMCOM   | metalcost  | 12345     |
| 4  | ARMCOM   | energycost | 234567    |
| 5  | CORCOM   | name       | Commander |
| 6  | CORCOM   | untiname   | CORCOM    |


Again, this would not be the most efficient way to do things. But short of altering the table's layout by adding a new column for every new tag, this is the only way I could think of doing it. ...
Not the most efficient way but it's close (at least to what i understand as the most efficient way). It's working very similarly to my own database.

Adding all fields to the table would be, indeed, not very well done. With the adition of new tags to units, the database would become outdated. But your method keeps the database generic enough which is nice, which is similar to what i'm doing.

What's wrong with your's?

Code: Select all

... ARMCOM ...
... ARMCOM ...
... ARMCOM ...
...
It repeats data which should not occur, although a very common error in databases. For that, the best method, as far as databases is concerned, is to create 2 tables:
Table 1:

Code: Select all

| id | unitname
+------+----------+
| 1  | ARMCOM
| 2  | CORCOM
Table 2:

Code: Select all

| id | idOfUnitToWhichRefers | stat       | value     |
+--+----+------------+---------+
| 1  | 1   | name       | Commander |
| 2  | 1   | unitname   | ARMCOM    |
| 3  | 1   | metalcost  | 12345     |
| 4  | 1   | energycost | 234567    |
| 5  | 1   | name       | Commander |
| 6  | 1   | untiname   | CORCOM    |
Which is how i'm using my DB.
Keep in mind that, to be able to do advanced selects with joins:

Code: Select all

select Table2.* from ComplexJoinSyntax where Table1.Name = 'CORCOM';
Table 2 will need to have an index created and the linked field in Table 1 (inside the "ComplexJoinSyntax" part, not Table1.Name) needs to be primary key (.. i think).

You can check my DB here:
http://fileuniverse.com/?p=showitem&ID=2394
The xml file is the project, case you want to mess around with it to adapt to something else.
The script to create it is in plain text inside ScriptCreateVR.
Also, you can see the structure of the DB in a .png image.
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Post by zwzsg »

Maelstrom wrote:The following it a valid line:

Code: Select all

[CANBUILD]{[ARMCOM]{canbuild1=ARMSOLAR;canbuild2=ARMWIN;}}
Don't forget that

Code: Select all

[CANBUILD]{[ARMCOM]{canbuild1=ARMSOLAR; /*comments in the middle!*/ canbuild2=ARMWIN;}}
is valid too!
User avatar
Maelstrom
Posts: 1950
Joined: 23 Jul 2005, 14:52

Post by Maelstrom »

Ah yes, forgot about those comments. I already filter out the other type (//), as that is much more common, but I shall add in that type as well.

I wrote that file importing function now. Works quite nicley. Ill upload the source somewhere if anyones interested.

I will try to modify my database to fit your structure, as it makes alot more sense. Ill have a look at what you uploaded later.
User avatar
Maelstrom
Posts: 1950
Joined: 23 Jul 2005, 14:52

Post by Maelstrom »

Eeek. That database your posted is way to complex for me to follow. Ill still try and add that little fix you posted, but im not doing anything like yours, as it is WAY to complex.
User avatar
PauloMorfeo
Posts: 2004
Joined: 15 Dec 2004, 20:53

Post by PauloMorfeo »

zwzsg wrote:...
Don't forget that

Code: Select all

[CANBUILD]{[ARMCOM]{canbuild1=ARMSOLAR; /*comments in the middle!*/ canbuild2=ARMWIN;}}
is valid too!
Arghh :evil:!
Maelstrom wrote:Eeek. That database your posted is way to complex for me to follow. Ill still try and add that little fix you posted, but im not doing anything like yours, as it is WAY to complex.
:lol:
Indeed! You may be better off using something more simple.
In fact, even the error i pointed in your database may prove worth not fixing as it will make it simpler working with it (that is, if your database is to hold unit's data only, not connected to all other things).
It replicates data, which brings the dangers of having things like "ARMCOM", "armcom" and "armcomm", and some extra space usage, but it is easier to use.

Doing it «the right way», you'll end up with 2 tables connected and, if you want to do something like:

Code: Select all

SELECT * FROM Table1 WHERE name= 'armcom';
You'll end up having to do something like this:

Code: Select all

SELECT name
FROM first_table
INNER JOIN second_table
ON first_table.keyfield = second_table.foreign_keyfield;
Although a minor failure in design, it is not very serious if you take care of handling the potencial problems it may bring.
User avatar
Maelstrom
Posts: 1950
Joined: 23 Jul 2005, 14:52

Post by Maelstrom »

Point taken. Ill just keep with my simple version now. Also, as the unit names are case insensitive in Spring (I think), Im just storing all the unit names as lowercase. Which will also make it simpler again, as I can just interprate the Build Tree as unit names, instead of numbers. And on that note, Build Trees have been implemented! Go check out that link again.
http://210.11.113.96/modweb/unit.php?unit=armcom

I just need to add a few more pages, clean up where everything works, and then I can release it! Yay for me.

Also, if your interested, this works off a template, and you can view the template here:
http://210.11.113.96/modweb/unittemplate.html
User avatar
PauloMorfeo
Posts: 2004
Joined: 15 Dec 2004, 20:53

Post by PauloMorfeo »

Maelstrom wrote:...
http://210.11.113.96/...
Haa, crap... That's your computer, no? I never seem to be able to catch it online. Or else, he doesn't likes me.
User avatar
Maelstrom
Posts: 1950
Joined: 23 Jul 2005, 14:52

Post by Maelstrom »

I uploaded it to a propper web server now.
http://maelstrom.wik3d.com/modweb/

Thread about it is here:
http://taspring.clan-sy.com/phpbb/viewtopic.php?t=3842
Post Reply

Return to “Game Development”