开发者

In C, would XML be a good format to use internally for a RPG engine?

开发者 https://www.devze.com 2023-01-14 12:48 出处:网络
I am a novice C coder who would like to write a role playing game resolution library.What I mean by this is that this program would only deal with resolving those conflicts which is piped i开发者_运维

I am a novice C coder who would like to write a role playing game resolution library. What I mean by this is that this program would only deal with resolving those conflicts which is piped i开发者_运维技巧nto it. For example, when informed that Captain Amazing uses his Blasto eye beams at medium distance with his d8 Shooting Skill costing 3 Power Points, and his Wild Die, against Commandant Nefarious who is behind Medium Cover, it determines the result. It will not deal with either character, per se, only their relevant statistics, who the attacker and defender are and any modifiers relevant to this particular action of which it is informed.

The thing is that it will not have a built-in set of rules. Instead, it will be fed the rule set from a configuration file. This way, the same core engine could be used for a Savage Worlds virtual tabletop game, a turn based rogue-like or a real time D&D 3rd Edition 3d game. Different sets of rules for different types of CRPGs all using the same RPG library. My question is with regards to how best to do this.

For the last couple of days, I've been looking at using XML as a possible way to store the game data which would be needed. At first appearance, it looks like a good way to go since does not appear to be terribly difficult. On the other hand, since it would load the rules at run time, I cannot do XML data binding as that would convert it to C code, which would of course need to be compiled. That is how I understand it, at least.

To build on the example in the first paragraph, this is what the library would and would not need after the rules have been read in:

Library knows through the read in rules: How to resolve a Ranged Attack. What Skill is needed for a Ranged Attack (Shooting). What the base Target Number is. What the penalty to hit at Medium distance is. What the penalty to hit for the Defender being behind Medium Cover. How to deal with the Wild Die (if it is higher than another rolled die, it is used instead.) Aceing. (On most, but not all rolls, if the die hits its maximum score, it is rolled again, adding to the total. This continues until the die does not hit the maximum score.) What the values for the dice are.

What the library will need to be informed of: What the Attacker's Shooting Skill is. Distance. What the relevant situational modifiers are (Medium Distance, behind Medium Cover) Any character modifiers relevant to resolving the Shooting attack.

What the library does not care about in performing its task: Character names. Character skill levels in subjects not pertaining to resolving the current question. Which character is the player and which the non-player character.

Would XML be fine or should I approach this in a different way?


The thing is that it will not have a built-in set of rules.

You might be better off using XML to store data and hosting a scripting engine in your game and have the rules programmed as scripts external to your program. Lua is a good option for C programs, Python is also another choice.


Civilization IV uses XML and Python for everything except the graphics engine and the AI. All the rules are Python scripts, all the units characteristics are XML files.

So the answer is I guess yes, it can be a good format.


One advantage of using XML for the communications and storage is that if you decide it gets too hairy coding it in C, you drop back to a language with more nearly 'built-in' support for XML.

I would not particularly associate C with XML. There are (many) libraries written in C or C++ that can manipulate XML, but the interfaces used mean that C is largely coincidental - you are working with the library code and library calls more than with just C. If you go down this route, you should aim to use one of the many established XML libraries rather than inventing your own - the same would be true in any other language.

Note that XML is a fairly heavy-weight language to process. I suspect that many gaming systems would find it too slow to process the relevant data.


In essence, I envision this sort of flow:

                                rule file
                                   |
UI --| pipe with action data |-- Resolution Engine --| pipe back to UI |--

I would suggest that XML is an ok rule-file language. Personally I think it's too much big iron unless one needs schema validation, and that JSON is a better choice to start off with. Neither JSON or XML really are a good map into C's execution model, but them's the breaks. You won't be parsing the rule file much anyway, so you can afford to take the time to do that with a parsing library.

For the action data pipe, I'd suggest using operating system pipes and writing binary data suitable for directly reading into a C structure.

Edit - If you're going to be using the rule file as a full-on scripting language instead of a configuration language, you want to embed another language eventually. Lua is the language choice du jour for game scripting. I don't know any reason off-hand not to choose Lua for this purpose.

BTW you have chosen a good starting project area I think.

0

精彩评论

暂无评论...
验证码 换一张
取 消