简体   繁体   English

在C语言中,XML是在内部用于RPG引擎的好格式吗?

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

I am a novice C coder who would like to write a role playing game resolution library. 我是一位C语言新手,想编写一个角色扮演游戏分辨率库。 What I mean by this is that this program would only deal with resolving those conflicts which is piped into 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. 例如,当得知Amazing队长使用d8射击技能(花费3点能量)并以中等距离使用他的Blasto眼光,并击败了Medium Cover背后的指挥官Nefarious时,他的Wild Die决定了结果。 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. 这样,同一核心引擎可用于Savage Worlds虚拟桌面游戏,基于回合的流氓类游戏或实时D&D第三版3d游戏。 Different sets of rules for different types of CRPGs all using the same RPG library. 不同类型的CRPG的不同规则集都使用相同的RPG库。 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. 在过去的几天中,我一直在考虑使用XML作为存储游戏数据的一种可能方法。 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. 另一方面,由于它将在运行时加载规则,因此我无法进行XML数据绑定,因为那样会将其转换为C代码,这当然需要进行编译。 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? XML可以吗,还是应该以其他方式处理呢?

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. 使用XML存储数据并在游戏中托管脚本引擎可能会更好,并且可以将规则编程为程序外部的脚本。 Lua is a good option for C programs, Python is also another choice. Lua是C程序的不错选择,Python也是另一选择。

Civilization IV uses XML and Python for everything except the graphics engine and the AI. Civilization IV使用XML和Python来处理图形引擎和AI以外的所有内容。 All the rules are Python scripts, all the units characteristics are XML files. 所有规则都是Python脚本,所有单位特征都是XML文件。

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. 使用XML进行通信和存储的一个优点是,如果您决定使用C语言对其进行编码过于繁琐,则您会退回到一种对XML几乎“内置”支持的语言。

I would not particularly associate C with XML. 我不会特别将C与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. 有许多用C或C ++编写的可以处理XML的库,但是使用的接口意味着C在很大程度上是巧合的-您正在使用库代码和库调用,而不仅仅是使用C。如果您遵循这种方法,您应该旨在使用许多已建立的XML库之一,而不是发明自己的XML库-在其他任何语言中也是如此。

Note that XML is a fairly heavy-weight language to process. 请注意,XML是一种相当繁重的语言,需要处理。 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. 我建议XML是一种好的规则文件语言。 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. 我个人认为,除非需要进行模式验证,否则它实在太大了,JSON是一个更好的选择。 Neither JSON or XML really are a good map into C's execution model, but them's the breaks. JSON或XML都不是C的执行模型的良好映射,但它们是断点。 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. 对于动作数据管道,我建议使用操作系统管道并编写适合直接读入C结构的二进制数据。

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. Lua是语言选择大谈特谈游戏脚本。 I don't know any reason off-hand not to choose Lua for this purpose. 我不知道没有任何理由不为此选择Lua。

BTW you have chosen a good starting project area I think. 顺便说一句,我认为您选择了一个很好的启动项目区域。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM