游戏邦在:
杂志专栏:
gamerboom.com订阅到鲜果订阅到抓虾google reader订阅到有道订阅到QQ邮箱订阅到帮看

分享使用过程生成技术制作无限世界的方法

发布时间:2012-05-08 16:21:37 Tags:,,,,

作者:Alex Norton

过程生成技术无疑是当下流行的做法,我个人相信这是许多年以来电子游戏的发展方向。当然,在游戏中使用过程生成已经不是新鲜的做法,《Elite》或《The Sentinel》等游戏的粉丝都知道,过程生成在游戏中的运用已经有25年的历史了。

因为硬件的内存限制,较老的游戏可以良好地使用这种方法。自动生成使关卡的创作效率要高于手动制作,但是硬件设备的升级不能成为我们无法更好地使用这种方法的借口。

《上古卷轴2:匕首雨》游戏世界(from g4tv.com)

《上古卷轴2:匕首雨》游戏世界(from g4tv.com)

RPG题材游戏粉丝毫无疑问都记得《上古卷轴2:匕首雨》,游戏中有有史以来最大的虚拟世界,其世界的范围甚至超过现代的几乎所有RPG游戏。我回想起自己曾经在某个地方读到过,《匕首雨》的游戏内世界面积约为不列颠群岛的两倍。

对玩家来说,这是个值得探索的广袤世界,但是从游戏设计的角度来看,手工制作如此大的世界简直是噩梦。但是,通过对过程生成技术的精妙利用,这种世界的创造成为可能,而Bethesda Softworks在《匕首雨》中使用的正是这种方法。住宅区和城镇由手工制作而成,野外的场景则交由游戏自动生成。

但是,为何对这种方法的使用止步于此呢?为何无法再继续发展呢?在过去25年里,过程生成代码并没有发生很大的改变。人们仍然坚持使用不规则形状、菱形和球形来塑造所有东西,这种重复性使得内容看上去很像过程生成的内容。任何程序员在观察游戏中的内容时,都会嗅到过程生成的气息。

在此基础上,如果你的执行发生了错误,最终会得到与意向相去甚远的结果。独立开发者似乎在这方面做得比较好,《Dwarf Fortress》等游戏生成了带有辉煌历史的大型世界,其世界的面积原比我们期望探索的要大得多。但是,他们依然没有突破极限。

我的目标就是改变现状,无限游戏世界应当是可以实现的,而且事实确实如此。

想法

两年前,我开始组建团队制作首款真正的无限全3D玄幻RPG游戏,名为《Malevolence: The Sword of Ahkranox》。游戏的风格类似于80年代末和90年代初那些基于格子的经典第一人称RPG游戏,比如《英雄无敌》、《魔眼杀机》和《Dungeon Master》,不同之处在于该游戏的世界是无限的。

我们最初考虑将其制作成星球状的世界,但是最终在故事设计时决定将游戏世界视为一把有感知能力的剑的想象之物,由此来“解释”它充满无限性的原因。

经过多次实验和极为复杂的数学运算后,我们得到了有效的无限世界,但却是原始数据状态的世界,并没有真正的可体验之物。然而,我们确实看到了充满无限地下城的无限世界和布满无限NPC的无限城市。于是,我们开始制作在这个世界背景下运转的游戏。

现在,需要确认的是,这个世界并非随机生成。它必须兼有无限性和一致性。世界中不含有过多的细节,所以可以通过让世界受时间推移动态影响来实现上述目标。世界中的每个部分要么会随时间变化,要么保持永恒不变。带有山脉和洞穴的大地,这些层次都是永恒不变的。

因为这些部分永远不会改变,也不会受玩家行为的影响,所以只需要在玩家进入可视范围中或在生成探索信息需要时加载进内存即可。但是,如果某个对象受时间影响(游戏邦注:比如宝箱中的物品),那么就需要在生成这些内容的过程运算法则中加入时间系数。

这意味着,地下城中的某个宝箱所呈现的道具取决于玩家打开宝箱的时间。如果玩家已经打开了宝箱,那么这个动作就会被存储在玩家改变数据库中,经过特定长度的时间后数据库会被重置。这样就可以确保玩家改变世界的数据库大小不会超过特定容量(游戏邦注:最多估计可支持250MB左右,通常情况下约为50MB)。

这种生成被运用到游戏几乎所有东西中,包括法术制作、道具制作、武器制作、药水制作、NPC对话系统甚至屏幕上呈现的法术效果。

于是,玩家探索的游戏世界将会不断发生改变,成为无限的世界。他们不会不断找到相同的武器或道具,他们能够找到或使用的法术数量也是无限的,他们与NPC间的对话内容也不会完全保持不变。无限性成为保持玩家对游戏世界兴趣的必要方式。

公众接受程度

在游戏《Elite》开发时,原本计划设置282万亿个星系,每个星系中的恒星系统约为256个,但是游戏发行商Firebird担心如此庞大的游戏内置宇宙会让玩家感到无所适从。我必须承认,我也考虑过这个问题,所以对公众会如何看待如此大的游戏内置世界很感兴趣。

最终的结果令我感到震惊。

我们一直都在公开发布游戏的开发进程,在IndieDB等社区也拥有了部分粉丝,但是似乎很少人能够真正理解无限世界,尽管我们对其进行了充分的描述。我们渲染了世界生成数据,向公众展示了世界的一小部分:

一小部分的游戏世界(from gamasutra)

一小部分的游戏世界(from gamasutra)

随后,我们向他们展示了以下这片区域:

内陆海(from gamasutra)

内陆海(from gamasutra)

这块内陆海的面积大约相当于《上古卷轴:天际》中整个游戏内世界的面积。有趣的是,我们收到的大部分是怀疑的回应。许多人认为我们在撒谎,这完全是不可能的事情。有些人则认为《Malevolence》的游戏世界就是以上的整幅图片,并不是无限世界。只有将近20%的人真正能够理解我们所构建的这个世界。

所以,从营销的角度来看,在游戏中设置无限世界并非有效的做法。我们甚至听到有人评价说《Malevolence》只是在剽窃《魔岩山传说》,尽管《Malevolence》的项目启动时间更早。但是,无论公众对这款游戏有何评价,它终究是要发布的。

有趣的是,这还不是我们面临的最困难的事情。最困难的事情是制作此等世界所涉及到的数学问题。

数学

因为游戏世界无限、过程化且延绵不断,所以《Malevolence》采用的多为理论数学,也就是几乎不含有固定或已知值的数学。但是,我们将世界的创作分割成多个层次。

上图便是首个层次。生成大型世界区域,覆盖面积约为400 X 400 km。这是游戏中唯一使用标准化过程生成系统的层次。

随后,它被划分为约3 X 3 km的方块,计算区域内的生物群系信息,如下图所示:

5个步骤(from gamasutra)

5个步骤(from gamasutra)

最后,所有这些步骤都完成后,新世界区域生成,原始数据转变为下图:

世界地图(from gamasutra)

一般关卡(from gamasutra)

但这只是一般关卡的做法。玩家可见的每个世界片段都有个独特代码,通过过程运算法则生成。如果该片段中有个地下城入口,那么地下城便使用这个独特代码生成,确保玩家每次到达相同地点时都能够看到同一个地下城:

地下城(from gamasutra)

地下城(from gamasutra)

城镇、墓地、废墟以及玩家可能到达的每个地方都使用同样的方法。而且,这个过程永远持续下去。如果玩家关闭碰撞,按住“前进”键,那么从世界片段的一端到另一端需要约3周时间,随后他们会无缝地跳转到一个新的世界片段,并如此反复进行下去。

我们遇到的最大问题是如何处理玩家坐标的数据类型限制,但我在这里不能透露解决方案的相关信息。但是,我可以告诉你,《Malevolence》并没有遇到《Minecraft》的世界边界问题,它会不断延续下去。

总结

在游戏中使用过程生成技术确实能够产生丰富的体验,但是不要过于匆忙。这种方法需要精密的计划以及睿智地运用,最重要的是需要让玩家产生地图片段无缝衔接的感觉,否则公众就不会接受这种设计方法。(本文为游戏邦/gamerboom.com编译,拒绝任何不保留版权的转载,如需转载请联系:游戏邦

Opinion: The difficulties of an infinite video game world

Alex Norton

Procedural generation is definitely in vogue, and I personally have believed that it is the way forward in video gaming for many years now. Using procedural generation in games is nothing new of course, as fans of games such as Elite or The Sentinel will know that we’ve been seeing it in games for a good 25 years.

Older titles made good use of it due to the memory constraints of the hardware of the time. It was simply more efficient to have generated levels rather than hand-rafted ones, but that is no excuse for games not to make better use of it now that we have better specced hardware.

Fans of the RPG genre will no doubt remember The Elder Scrolls II: Daggerfall, which had one of the largest in-game worlds ever seen, and still to this day tramples almost every RPG made in terms of world size. I recall reading somewhere that the in-game world of Daggerfall was equal to twice the landmass of the British Isles.

That is a heck of a lot of world to explore, and – from a game design perspective – a nightmare to recreate by hand. Through clever use of procedural generation, however, it is easily possible, which is what Bethesda Softworks did with Daggerfall. The settlements and towns were hand-crafted, with the wilderness in between being generated by the game.

But why stop there? Why have world borders at all? Procedural generation code hasn’t changed much in the last 25 years. People are still stuck using fractals and diamonds and blobs to do everything, which becomes repetitive and quite simply looks like procedurally generated content. To any programmer looking at it, it virtually smells of procedural generation.

On top of all this, if you get it wrong, it will end up VERY wrong. The indie crowd seems to do it best, with titles like Dwarf Fortress generating MASSIVE worlds with lush histories and more world than you could ever hope to explore. But still, they aren’t pushing the envelope.

My aim was to fix that by making it work. An infinite game world should be possible, and indeed it is.

The idea

Just over two years ago I began assembling a team to make the first truly infinite, fully 3D fantasy RPG, entitled Malevolence: The Sword of Ahkranox. It was to be played in a style similar to the classic grid-based, first person RPGs of the late ’80s and early ’90s such as Might & Magic, Eye of the Beholder and Dungeon Master, but set in a literally infinite world.

We had originally thought to make it a planet-sized world, but in the end decided on the story being that the game’s world was being created within the imagination of a sentient sword, which would act as a way to “explain” the infinity of it.

After much experimentation and very complex math, we got it working, but all in raw data. Nothing really playable. But we had in front of us an infinite world filled with infinite dungeons and infinite cities filled with infinite NPCs. We then worked to get a game working in such a world (some of the efforts of which, you may have read about in my last post).

Now, just to confirm, this world wasn’t being randomly generated. It was both infinite AND persistent. Without going into too much detail, this is achieved by making the world dynamically affected by the passing of time. Every part of the world is identified as either affected by time or timeless. The lay of the land with its hills and caverns… That’s all timeless, and never changes.

Because those parts never change and cannot be affected by the player, they only need to be loaded into memory when the player can see them (or if they are needed to generate quest information, etc). However, if an object is affected by time (for example, the contents of a chest), then they have a time coefficient applied to the procedural algorithm that generates them.

This means that a chest in a dungeon, for example, will have different items in it depending on WHEN the player opens the chest. If the player was the clear out that chest, that act is stored in a database of player changes, but then re-set when a certain amount of time has passed. This ensures that the database of player changes to the world never exceeds a certain size (which is estimated to be around 250mb at the very most, but more realistically around 50mb)

This generation accounts for almost everything in the game. Spell creation, item creation, weapon creation, potion creation, NPC dialogue system, even the spell effects that happen on the screen.

Due to this, the world that the player explores will be ever-changing and infinite. They won’t keep finding the same old weapons or items, there will be no end to the number of spells they can find or use, they won’t even keep having the same conversations with NPCs. This is necessary to keep a player interested for long enough in an infinite world.

Public acceptance

Back when the game Elite was first being worked on, it was planned to have around 282 trillion galaxies with around 256 star systems in each one, but their publisher, Firebird, were worried that such a large in-game universe would be intimidating to players and put them off. I have to say I had wondered at that, and was interested to see how the public would react to an even bigger in-game world.

I was surprised at the results.

We’ve been quite public with our development process for the game so far and generated a small cult following on communities such as IndieDB, but very few people seem to quite grasp the scale of an infinite world, despite our thorough descriptions of it. We had put up renders of the world generation data, showing just a tiny fraction of the world:

And then, we showed them this:

That inland sea is around the size of the entire in-game world of Skyrim. Funnily enough, the largest response we got from this information was disbelief. Many called us liars and that it simply wasn’t possible. Others began to believe that the world size of Malevolence was the entire above image, rather than infinite. Only about 20 percent of people really understood.

So, from a marketing perspective, it’s been a bit of a nightmare to have an infinite world. We’ve even had many suggest that Malevolence is just a rip-off of Legend of Grimrock, despite the fact that Malevolence was started about a year before. But that’s always going to happen, no matter what the game. What happens upon release will happen, and that’s just how the cookie crumbles with game development.

Funnily enough, that hasn’t been the hardest bit. The hardest bit has been the math involved in making a world like this one.

The Math

Being infinite, procedural AND persistent, most of the mathematics behind Malevolence is theoretical math – that is, mathematics with few or no fixed/known values acting in a volatile space. But we’ve broken the world creation down into multiple layers.

The first layer is the one you saw above. A large world segment is generated which covers an area of about 400x400km. This is the only layer of the game that uses a standardised procedural generation system (perlin noise)

That is then broken down into chunks that are around 3x3km, calculating the biome information within that area, like so:

In the end, all of these steps need to be completed when each new world segment is generated in order to turn the raw data into this:

That is just for the overworld. Every world segment that is VISIBLE to the player (as in the view above) is given a unique code, generated by the procedural algorithm. If there is a dungeon entrance in that segment, the dungeon is generated using this unique code, ensuring that every time the player returns to that spot, the same dungeon will be there:

This same method is used for town generation, graveyards, ruins or anything else that the player may encounter. And this goes on forever. If a player was to turn off collision and hold down the ‘move forward’ button, it would take them just under three weeks to walk from one end of a world segment to another, and then they would simply move to a new world segment seamlessly, and then another, forever.

The biggest question we have been given is how we have dealt with the data type limitations on player co-ordinates, but unfortunately we can’t give away all our secrets.But I can tell you that Malevolence doesn’t suffer from the Minecraft world-edge issue, it just keeps going on and on.

Conclusion

Using procedural generation in your game can be a rewarding experience, but definitely don’t rush into it. It takes good planning, clever usage and most of all it needs to feel seamless, otherwise the public simply won’t accept it.

If you’d like to read more about Malevolence: The Sword of Ahkranox, you can check out these links. (Source: Gamasutra)


上一篇:

下一篇: