wtorek, 17 listopada 2015

Let them speak!

This is actually old subject, but I spent some time to do it so, maybe somebody finds this useful. Like always if you do games there are several ways to achieve your goal. For example making tree of dialogues can be done manually (greetings Zuber ;p) so every possible path of speech has it own condition. But this approach takes massive amount of work. It's even worse if you decide to change some talks. So I didn't like it. Besides I'm lazy old fat guy who don't like to write too much. So I thought about some engine which allows me to do the hard work. After digging internet I found nothing useful or free. Damn! So I analysed what I need in game:

  • dialogues in form of graph.
  • some answers (choices) for player are available if some condition is meet
    • If you done something in past
    • If you have some spells
    • If your stats are at least at some level 
  • Some answers will open/close passages
  • Some answers will change state of your player (for example you might be liked more or less by other NPC)
Ok how to achieve this? Since there is no Hashmap/fancy structures in UDK blueprint I designed something which work for linear container like list. It's not super efficient but it doesn't matter, since about of data is so small that algorithm might be very non optimal. SO my structure describing dialogue is as follow:
  • NPCName: String - engine friendly name used when you press some NPC to discover dialogues for him
  • SequenceIndex: int - used to create tree of dialogues. If some option is visible on screen (NPC said something) then I use this field to discover options for player. It's connected with next field...
  • moveToSequenceIndex: int - Informs which dialogues are available in next step. This points to SequenceIndex.
  • Text: String - actual text to be shown on screen
  • NPCDialog: bool - if true this is something what NPC will say, false otherwise.
  • condition: string[] - boolean condition in human readable form which need to be meet to have this dialogue available.
  • execSequence:string[] - encoded sequence of things which will happen if this dialogue is selected.
I decided to use list of pairs Key-Value (String-int) to store state of player. So my player have list named state and in this list can be stored pairs which holds current state of game. What this give me? Well I can encode execSequence with just 4 operations. For simplicity of blueprints I used prefixes to encode operation. And we have:
  • >doorName - it's tell engine to open some passage/door for example ">DoorToKitchen"
  • !DoorName - it's tell engine to close some passage/door for example "!DoorToKitchen"
  • +variable - adds one to Key-Value with name 'variable'. If pair with given key doesn't exists then it's created, for example "+goldenKey"
  • -variable -  subtracts one from Key-Value with name 'variable'. If pair with given key doesn't exists then it's created, for example "-goldenKey"
Similar easy approach was used for condition array. This is what I plan to do (since I don't have this part done yet). 
  • each string will start with & or | operator which tells how to apply those condition to previous value.
  • then will be variable from list of Key-Value, if variable doesn't exists then this part of condition is false.
  • then operator in form of >, <, <=, >=, =
  • then value
example of condition: 
[0] |key>1
[1] &marryLikeMe > 10
which mean I need key and mary need to like me for at least 10 points. Ok. This is all for today, hope somebody understands me :)

Brak komentarzy:

Prześlij komentarz