Home » PLAYER'S HQ 1.13 » JA2 Complete Mods & Sequels » Stracciatella Project (Platform Independent JA2) » Data externalisation
Data externalisation[message #189797] Sun, 29 June 2008 19:44 Go to next message
Tron

 
Messages:225
Registered:August 2007
Location: Germany
I'm working a bit on data externalisation for JA2-Stracciatella. I plan to use simple key/value pairs. It will look about like this:
weapon GLOCK_17 {
  weapon_class  = HANDGUNCLASS,
  weapon_type   = GUN_PISTOL,
  calibre       = AMMO9,
  ready_time    =   0,
  rate_of_fire  =  14,
  bullet_speed  =  24,
  impact        =  21,
  deadliness    =   8,
  clip_size     =  15,
  range         = 120,
  attack_volume =  60,
  impact_volume =   5,
  fire_sound    = S_GLOCK17
}


I'll probably start with merge combinations, because this has the least dependencies in the source:
merge { result = FIRSTAIDKIT,   action = COMBINE_POINTS }
merge { result = MEDICKIT,      action = COMBINE_POINTS }
merge { result = LOCKSMITHKIT,  action = COMBINE_POINTS }

merge { item1 = COMPOUND18, item2 = FLAK_JACKET,  result = FLAK_JACKET_18, action = TREAT_ARMOUR }

merge { item1 = COMPOUND18, item2 = FLAK_JACKET_Y, action = DESTRUCTION }

merge { item1 = RDX, item2 = TNT, result = HMX, action = EXPLOSIVE }

merge {
  item1  = STRING,
  item2  = TIN_CAN,
  result = STRING_TIED_TO_TIN_CAN,
  action = EASY_MERGE
}

merge {
  item1  = FLASH_DEVICE,
  item2  = DISPLAY_UNIT,
  result = XRAY_DEVICE,
  action = ELECTRONIC_MERGE
}


Parsing this only needs a very simple recursive descent parser. Of course the order of the key/value pairs and placement of whitespace does not matter. Consistency (typo in key, a missing mandatory key, etc.) is checked when the input is parsed and an appropriate error message will be generated:
merge { item1 = RDX, item2 = TNT, resul = HMX, action = EXPLOSIVE }
merge.cfg:1:35: error: got unknown key "resul"

merge { item1 = RDX, item2 = TNT, action = EXPLOSIVE }
merge.cfg:1:1: error: merge has no valid result


I think, this approach leads to configuration files, which are easy to read and edit.

Report message to a moderator

Sergeant 1st Class
Re: Data externalisation[message #189811] Sun, 29 June 2008 22:03 Go to previous messageGo to next message
Marlboro Man

 
Messages:1156
Registered:October 2005
Location: USA
Sounds great. Smile

Report message to a moderator

Sergeant Major

Re: Data externalisation[message #189906] Mon, 30 June 2008 22:47 Go to previous messageGo to next message
Mythrell is currently offline Mythrell

 
Messages:78
Registered:May 2008
Location: Mikkeli, Finland
That looks like a very nice addition, very good idea. Smile

Report message to a moderator

Corporal
Re: Data externalisation[message #196264] Fri, 12 September 2008 00:15 Go to previous messageGo to next message
LCJr.

 
Messages:83
Registered:November 2001
Looks good. Straightforward and easy to understand.

Report message to a moderator

Corporal 1st Class
Re: Data externalisation[message #199273] Thu, 16 October 2008 10:38 Go to previous messageGo to next message
Khor1255 is currently offline Khor1255

 
Messages:1817
Registered:August 2003
Location: Pleasantville, NJ
Any progress on this?

Report message to a moderator

Sergeant Major
Re: Data externalisation[message #225017] Fri, 03 July 2009 00:32 Go to previous messageGo to next message
Tron

 
Messages:225
Registered:August 2007
Location: Germany
I haven't worked on this in a long time. You can have a look at a rough prototype:
http://tron.homeunix.org/merge.cfg
http://tron.homeunix.org/merge.diff
Put merge.cfg in JA2/Data/. Apply the diff to a clean version of the source code at r6167 (patch -p0 < merge.diff)
It's not much, it only reads the merge recipes from merge.cfg, but it shows the general idea. The implementation is really scruffy.

Report message to a moderator

Sergeant 1st Class
Re: Data externalisation[message #225025] Fri, 03 July 2009 00:57 Go to previous messageGo to next message
Shanga is currently offline Shanga

 
Messages:3480
Registered:January 2000
Location: Danubia
So if you for example in the line below I decide to change COMPOUND18 with something else, dunno, GAS_CAN (first thing it came to mind), it would throw an error or the result would still be FLAK_JACKET_18?

merge { item1 = COMPOUND18, item2 = FLAK_JACKET,             result = FLAK_JACKET_18,             action = TREAT_ARMOUR }


I answered my own question - i made a wierd combo to test: gas + flak jacket = treated spectra. Worked flawlessly. So basically this is neither XML nor LUA. What is it then?

Nice work Smile

[Updated on: Fri, 03 July 2009 02:08] by Moderator

Report message to a moderator

Captain
Re: Data externalisation[message #225093] Fri, 03 July 2009 08:05 Go to previous messageGo to next message
gmonk

 
Messages:670
Registered:April 2002
Location: Newfoundland, Canada
It's a configuration file like an ini. The game data is read from the cfg by the game and acted on by the functions in the exe.

Did you write your own parser for this Tron?

Report message to a moderator

First Sergeant
Re: Data externalisation[message #225097] Fri, 03 July 2009 08:35 Go to previous messageGo to next message
Tron

 
Messages:225
Registered:August 2007
Location: Germany
It's just a simple lexer (Tokenizer.cc) and a cheap parser for the merge recipes (ReadMerge.cc).

Report message to a moderator

Sergeant 1st Class
Re: Data externalisation[message #229500] Tue, 28 July 2009 10:58 Go to previous message
1Samildanach

 
Messages:56
Registered:February 2009
Location: Southern hemisphere
Might be worth looking at YAML as a potential data format (it has some advantages when compared with XML).

Report message to a moderator

Corporal
Previous Topic: Using Eclipse: Any advice?
Next Topic: Minor Visual Bug
Goto Forum:
  


Current Time: Mon Jan 20 07:00:18 GMT+2 2025

Total time taken to generate the page: 0.01699 seconds