Quests/Persistent data?

What do you guys do for quest systems? I was just thinking about what a good expandable way (i.e. adding new quests) would be. You’d have to account for the quest giver/returner, what type (fetch, kill, talk to), the target objective, and that’s not event accounting for multi-step quests…

Hmm…the only thing I could think of is an XML file and build your class hierarchy off of that. Do you have any suggestions? Maybe scripting? I’ve never done scripting before though, so I could use a nudge in the right direction.

XML is used to load/save the actual data, scripting is used to manipulate that data. Use them depending on what you need.

Just doing a little research on XML. So 1 simple quest in an XML file could like like this:


<quest id="5">
           <name>
                   Hippo Hijynx II
           </name>
           <desc>
                   // Quest description
           </desc>
           <quest_flow>
                   <npc_start_id>54<npc_start_id />
                   <requirements>
                             <min_level>5</min_level>
                             <quest_completed_id>4</quest_completed_id>
                   </requirements>
                   <step id="1">
                              <fetch>
                                        <item_id>67</item_id>
                                        <quantity>3</quantity>
                              </fetch>
                              <npc_finish_id>54</npc_finish_id>
                   </step>
           </quest_flow>
</quest>

Do I have the general idea, and how can I keep track of all this in-game?

Looks good. If it contains the data you need then it’s fine. If you come to a point where you need a way to dynamically add code to manipulate data, then you need scripting :slight_smile:

I see…

Do I need to write a custom parser since I’m using custom tags?

Yes, and no.

You can use an XML parser that’s already available to read the XML and parse it into its node set. XML has very fewpredefined tags. It’s meant to be customizable (Hence, eXtensible Markup Language). So most of the available parsers will be able to deal correctly with it, so long as it’s well defined/well structured.

To actually use the set, you’ll have custom code that knows the structure of your XML document, and how to traverse it/retrieve information. For the most part, you’ll be able to just use the regular DOMDocument system available to process your nodes into your data-structures. However, if you need to do searches like “Find the quest which rewards ‘this’”, then you might want to look into one of the XML-Search languages like xQuery, and there are a few others that I can’t remember off the top of my head.

No, parsers don’t do anything special with custom tags. I recommed you use XPP3 (this link downloads a zip, containing the JAR, JavaDoc, and sources).

EDIT:
@UprightPath
It is best not to search through an XML for certain data, but store it in memory in your data structures.

Thank you very much, gentlemen. This a good starting point. :slight_smile:

XML: The solution in search of a problem.

=p

it is pretty amazing…

@ra4king
I suppose so. I’ll admit that I’m not used to actually storing data persistently in memory. The most XML fun I’ve had was loading it from a web site, converting it into a middle-format, then placing that data into a SQL database. Or, taking it from that database and putting it into a second XML format and sending it elsewhere.

But, for persistent quest data, it does make more sense to just cram it into your own data structures and keep it available. And it’s a much better plan than attempting to save through the fun that is serialize functions.

Personally I never ever use XML for anything EXCEPT as an importer/exporter to some interchange format.

@UprightPath
For single player RPGs anyway. Once you add a server then it might be best to store the data in a database.

I just need to figure out how I should put together the actual data structure. If I’m doing quests in XML, it would make sense to use it for items and npcs as well.

Well, XML can be edited by hand, where as most other formats you tend to require a program to add stuff. And if you’re serializing anything, you need to have some form of converter, if you make any change to the storage class.

And, even if you’re storing stuff in a DB, you wouldn’t need to get stuff out of it in an XML format, so the searching through XML is doubly bleh in those cases.

Yeah, that puts a lot of overhead on the server.

I’m not attempting to convince anyone not to use XML, but can you think of a more verbose and less readable text format? I can’t. Plenty of games used text prior to XML and you could (usually) read the data in the file. Compare the above to, say JSON if non-custom formats are they way you want to go.

I think that XML is one the most readable ways to store and read data if the tags are descriptive. Why, do you have another suggestion?

Use whatever works for you. Personally I don’t like any begin/end tag system when the data is generally short when compared the tags. Too much noise compare to signal. The example above has very little data, but quite a bit of text. Even properly colorified I find it hard to see the data.

Well, it depends on the complexity of the text file you’re going to use. As for XML’s readability? I can read it fine, and if you know what the intent of the tags are, a lot of it becomes clear. It’s a very context based thing.

If you’re at all planning on allowing anyone else to edit the files without the use of a program (Like a quest/content creator), then using another format probably isn’t going to work so well. Since you will have to define your own rules about how the file will be read into your system (What the use of \n, \r, \t, and other characters mean), you’ll have to make these rules available to others. And, if you decide that you need to add in another piece of data, your whole format is probably going to change. XML is fairly easy to change (Add tags to), and reading it doesn’t change too much when you do so.

So, a lot ends up depending on how set your data format will be. If you think you have everything you need to store your quest/other data and that you don’t want other people poking around inside of the text files, then using some sort of plain text parser could be easier than attempting to define a whole XML document. If you think that you might need to add/remove/change things later in the development process or that you want to allow people to add/remove quests by editing the text document directly, then XML is probably better for you.

@Roquen
I guess I get that. There probably should be more data than tags, but I just threw that example out to see if I was understanding right.

Would it make more sense to come up with the XML, then a data structure, or the other way around? I’m just trying to think how I can read in all this quest data and be able to organize the Java classes/code to be able to have it function in the game.