Author Topic: Spells data format  (Read 9286 times)

RogueMaster

  • Rogueliker
  • ***
  • Posts: 65
  • Karma: +0/-0
    • View Profile
Spells data format
« on: December 08, 2011, 04:35:19 PM »
Hi.

I'm trying to implement a spell system where the spells' data is stored into a human-readable text file following a format like this:

Spell_Name:Spell_Type:Arg1:Arg2:Arg3:Arg4

Then I read each line and call the different functions with the defined arguments.

So far, it seems to work well but I guess if there is a better way to store the spells data so other players can create or modify existing spells.
I also tried using an Excel database, but that doesn't allow easy editing for players or modders.

The same happens when storing the spell data as binary data: impossible to edit by players.

Another problem is for those spells that does not follow that exact same format, for example spells that produce more than one effect, for example damage + slow.

The file format i wrote before doesn't allow to set different spell types at the same spell.

Thanks so much.

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: Spells data format
« Reply #1 on: December 08, 2011, 04:47:39 PM »
Write more flexible data parser that allows creating spells supported by the engine. Like for example:

{
name: fireball
type: attack
effect: burn (5)
effect: explosion (3)
}

george

  • Rogueliker
  • ***
  • Posts: 201
  • Karma: +1/-1
    • View Profile
    • Email
Re: Spells data format
« Reply #2 on: December 08, 2011, 05:02:09 PM »
Along those same lines you could use json, yaml, etc., and there's probably a parser for it in your language already written.

XLambda

  • Rogueliker
  • ***
  • Posts: 208
  • Karma: +0/-0
    • MSN Messenger - tau_iota@live.de
    • View Profile
    • The Weird Rogue
Re: Spells data format
« Reply #3 on: December 08, 2011, 10:24:12 PM »
libtcod has one, too. Also, like Krice stated, YAML parsers are available for pretty much every language in use (I hear JSON is even a subset of YAML nowadays :o), so finding one for your project won't be hard.

RogueMaster

  • Rogueliker
  • ***
  • Posts: 65
  • Karma: +0/-0
    • View Profile
Re: Spells data format
« Reply #4 on: December 09, 2011, 01:04:33 PM »
Thanks for your answers.

I want to avoid the use of 3rd party libs, that's why I didn't implemented any other markup language. I thought about XML instead of YAML, but still, some external libs required.

Finally I implemented a more advanced parser as Krice suggested. I did the next file format, that is pretty good for what I want to achieve:

Code: [Select]
!/<spell>
    <name>
    <description>
    ?/<effect1>
          <type>
          <arg1>
          <arg2>
          <argN>
     ?\<effect>
     ?/<effectN>
          <type>
          <arg1>
          <arg2>
          <argN>
     ?\<effect>
!\<spell>


The game will search for sections, and from each section, will read the spell name and description, and finally will read each of the effects into that section.
For each effect, it's provided the effect type and the list of arguments. Those arguments will be saved into an array that will be passed to the appropriate function.
Each effect "enclosure" will have the effect type and the list of arguments. Those contents will be read until the "?\" characters are found, so it's not necessary to specify the number of arguments within the spell section.
The same happens for each effect: they will be read until the end of spell mark ( "!\" ) is found, which is the same as Krice probably had in mind.

The only difference with the Krice, that I think is better, is that with this method, it's not necessary to implement any string format procedure or even split strings or similar problems. Each line is exactly the data required, without other chars or strings, which, for programming, is most easy to implement.

Also, the parser as i did it, only searches for "!/", "!\", "?/" and "?\" strings. It don't even read the text after them, so it's possible to add whatever text is needed, from a simple word to a whole phrase.

So, you can write something like this
Code: [Select]
!/
    Fireball
    A fiery fireball to burn your enemy
    ?/
        DirectDamage
        10
        2
    ?\
!\

or like this

Code: [Select]
!/FIREBALL : This will be the Fireball Spell, that only deals direct damage to target monster
    Fireball
    A fiery fireball to burn your enemy
    ?/EFFECT : The effect is direct damage of 10, and costs 2 mana
        DirectDamage
        10
        2
    ?\EFFECT
!\FIREBALL

Right now, I don't know is set the spell damage as a spell property, or set the damage as a effect property, so each effect has it's own mana cost and mana increase per spell level.

If someone is interested in the code, I can write it here.
Only needs some polish and code enhancement.

st33d

  • Rogueliker
  • ***
  • Posts: 112
  • Karma: +2/-0
    • View Profile
    • Email
Re: Spells data format
« Reply #5 on: December 09, 2011, 11:40:00 PM »
Dungeon Master seemed to solve this whole issue by separating the effects out into power words.

Rather than expecting players to program in json or the equivalent, wouldn't it be more fun for them to create spells from a basic word recipe book?

Then you could simply have: damage, area, slow

And then you'd be free to balance the engine without having to support legacy spell files full of magic numbers.

RogueMaster

  • Rogueliker
  • ***
  • Posts: 65
  • Karma: +0/-0
    • View Profile
Re: Spells data format
« Reply #6 on: December 11, 2011, 10:30:52 AM »
Dungeon Master seemed to solve this whole issue by separating the effects out into power words.

Rather than expecting players to program in json or the equivalent, wouldn't it be more fun for them to create spells from a basic word recipe book?

Then you could simply have: damage, area, slow

And then you'd be free to balance the engine without having to support legacy spell files full of magic numbers.

I thought about that system at first, but still, i need to define each spell in a file or some data structure so finally I will end up with the same issue.

Brigand

  • Rogueliker
  • ***
  • Posts: 93
  • Karma: +0/-0
    • View Profile
Re: Spells data format
« Reply #7 on: January 02, 2012, 06:52:54 PM »
Just save the data in a csv file. Excel is totally fine with it - it's human readable and editable. No reason a person can't edit a csv with text pad either. It's what I use, though I am debating using some kind of encryption to avoid players making their characters super powerful.

Just save your file as:

spell name, damage type, spell shape, low damage, high damage, description, range
fireball spell, DAMAGE_TYPE_FIRE, SPELL_TYPE_BOLT, 5, 15, "A ball of fire flies from your fingertips.", 6


Or something similar. Have your program discard the header line. Excel is totally kosher with this. Write your parser to simply convert words into whatever constants youve defined. No third party stuff needed if the user wants to edit a text file.