求生之路2关卡设计/多游戏模式支持

来自Valve Developer Community
跳转至: 导航搜索
English (en)Русский (ru)中文 (zh)
编辑

本简体中文页面由大康翻译于2021年9月11日。部分翻译摘自『定时子弹』的翻译版本(在此有改动)。


info_gamemode 实体

在求生之路2中,你能用新的实体 info_gamemode 根据不同游戏模式来触发不同事件。包括多样地图的外观,路径安排,项目的布置,或者别的什么。

最直接的好处就是不需要把同一关卡弄出多个版本。单独一个 .BSP 就能支持所有游戏模式,从而很显著的减小了地图文件的体积。

如果硬要说缺点,那就是提高了地图文件的复杂度。然而,正如我们将看到的,实现简单管理只需要使用“可见组”功能和新的“实例”功能。

从案例学习

让我们看看如何使用 info_gamemode 在现有地图中添加清道夫模式,在本例中是来自死亡班车(Deadline)附加战役的地图。

首先,打开死亡班车 2 第二张地图的源文件:

Steam\steamapps\common\left 4 dead 2\sdk_content\DeadLine2\mapsrc\deadline02.vmf

整体结构

特定于清道夫的实体位于它们自己的实例中,该实例也位于它的可见组中。

此地图的特点是中间的电梯必定会被触发。扯淡,这“噪音”会引来一大群尸潮啊。这用于划分地图为两半并限定游戏性到各个区域。当线性地图部分在合作模式下是不错的,清道夫的游戏性是更多偏向竞技。那么我们要让地图以清道夫模式启动会表现得与众不同。

让我们看看这是如何做的:

在可见组面板中,单击“+SCAVENGE”可视组旁边的复选框以显示和隐藏它。你会看到所有特定于清道夫的内容被激活和停用。这个 visgroup 中只有一个 func_instance,它引用了以下文件:

"instance/l4d_deadline02_scavenge.vmf"

这里的原理是在主地图源文件中引用所有游戏模式通用的所有元素:“deadline02.vmf”,并使特定于游戏模式的元素分别存在于各自独立的 .VMF 文件,并将它们作为实例引用到主地图中。求生之路2的关卡设计师发现以这种方式管理所有内容更容易,并且根据地图的复杂性,你可能会发现它会让管理更容易。

[这段大概是这样的:这里的原理是将其他游戏模式的内容引用到当前地图,引用的是"deadline02.vmf" 即实例。用这个方法比较容易管理。(此处省略不少字啊,但意思表达清晰完整)]

检查实例

编辑清道夫地图元素实例。

使用选择工具点击包含清道夫地图元素的实例并打开其属性对话框。在左下角,单击 Edit Instance (编辑实例)按钮。

Hammer 将打开实例引用的清道夫地图元素的 VMF 文件进行编辑。现在我们只能看到与清道夫地图元素相关的物品:起始区域、发电机、武器和一些改变地图和导航的障碍物。

不过,有点复杂。一些元素只需要在清道夫模式下生成,如果地图运行任何非清道夫模式,则必须移除其他元素。请记住,在 Hammer 中,可视组和实例是唯一的意义所在。一旦你编译你的地图,VBSP 进程会读取所有的实例并编译到地图中,就意味着所有模式的元素都集中到了一块,并且被隐藏的可见组将被 VBSP 忽略。所以我们需要一种在游戏中控制地图中的游戏元素的机制。这就是 info_gamemode 实体的用武之地。

info_gamemode 的设置

info_gamemode 及其逻辑实体。

该图标看起来像一副扑克牌。

Tip.png提示:你也可以使用 Map > Entity Report (地图 > 实体列表)来找到 info_gamemode。启用 filter by class (通过实体类别过滤),然后输入“info_gamemode”。
根据地图的游戏模式触发的输出。

选择它并单击 Properties (属性)按钮(译者注:或者双击实体)。键值非常少,但让我们看看 Outputs 选项卡。这就是操作所有的地方。

在这里你可以看到,如果地图在任何游戏模式下加载,而不是清道夫模式,它会触发一个名为“relay_kill_scavenge”的 logic_relay,移除该地图中所有特定于清道夫模式的物品。

通过这个简单的输出,它将负责删除所有内容。但是,添加内容需要分阶段完成,因此我们将内容分组为它们各自的logic_relay实体。

当地图刚刚以清道夫模式加载时,它会触发“OnScavenge”事件。此时,导演仍在初始化中,重要的是在完成初始化之前不要生成或杀死实体。

地图加载好并初始化导演后,它会触发“OnScavengePostIO”。我们在此刻进行一些操作:

  1. 首先,我们根据需要做一些 point_template。案例中包含用于清道夫的特定武器、物品和带有填充点的发电机的模板(point_template)
  2. 它还可以自动启动电梯,从而升起梯子并解除呼叫按钮。
  3. 我们在 post IO 中做的最后一件事是调整导航。我们已经封锁了一些路径来平衡地图,并且通过导航拦截器来封锁导航网格。

OnScavengeMatchStart”,是……我确定你已经猜到了,在清道夫模式的第一次地图加载时触发。不会在回合重新开始时触发。(译者注:原句为“fired off for each match”,由于含糊,此处的翻译是摘自对于该输出的描述的翻译

info_gamemode的优点之一是你可以在一张地图中放置几个 info_gamemode。死亡班车 2 地图不是依靠一个 info_gamemode 来执行所有操作,而是在每个游戏模式的实例文件中使用 info_gamemode。每个人都负责单独生成和杀死与特定游戏模式相关的物件。这需要努力来完成,但它有助于在你制作时使制作变得更简单。当你继续编辑你有一段时间没有接触过的地图时,让事物都有规划的呆在自己的地盘真的能帮我们不少忙。

使用 info_director

info_director 的输出。

在某些情况下,你将无法完全划分游戏模式。例如,清道夫地图要求 info_director 位于主地图中,因为它被所有游戏模式使用,并且具有如右图所示地图的某些输出。

你会注意到生存模式也有它自己的实例,合作模式和对抗模式是被组合在一起的2种模式。当然,你可以根据需要组织地图并添加支持的游戏模式,无论是否有实例。


info_gamemode entity

In L4D2, You can use the new info_gamemode entity to trigger different events depending on the game mode in which a map is played. This includes variant map appearance, path arrangement, item placement, or any other logic.

The most direct benefit is that you no longer have to ship multiple versions of the same level. A single .BSP can support all gamemodes, thus dramatically reducing the size of your add-on.

If there is a drawback, it is certainly in the increased complexity of your VMF file. However, as we shall see, this can be easily managed using visgroups and the new .VMF instance functionality described previously.

Learning by example

Let's look at how gamemode logic can be used to add scavenge in an existing map, in this case one from the Deadline add-on campaign.

First, open the source file for the second map of Deadline 2:

Steam\steamapps\common\left 4 dead 2\sdk_content\DeadLine2\mapsrc\deadline02.vmf

Overall structure

The scavenge-specific entities are in their own instance, which also lives in its own visgroup.

One of the features of this map is a lift in the center that must be triggered. Fictionally, the "noise" also creates a horde panic event. This is used to create two halves of the map and limit gameplay to each area. While this is desirable in co-op, where maps are very linear, scavenge gameplay is much more arena-oriented. So we'll need to have the map behave differently when launched in scavenge mode.

Let's look at how this is set up:

In the visgroup panel, click on the checkbox next to the "+SCAVENGE" visgroup to turn it on and off. You'll see all the scavenge-specific content activate and deactivate. There is just one func_instance in this visgroup, and it references the following file:

"instance/l4d_deadline02_scavenge.vmf"
The idea here is to have all the elements that are common to all gamemodes in the main map source file: "deadline02.vmf" and to have elements that are gamemode-specific each live in their own separate .VMF files, and have them be referenced into the main map as instances. The L4D2 level designers find it easier to manage everything this way, and depending on the complexity of your map, you may find it easier as well.

Examining the instance

Editing the Scavenge instance.

Click on the Scavenge instance with the selection tool and open up its properties dialog. At the bottom left, click the Edit Instance button.

Hammer opens up the scavenge .VMF for editing. Now we can see just the scavenge-related items: The starting areas, the generator, weapons, and some obstacles that alter the map and navigation.

It's a little more complicated, though. Some elements need to be spawned only in scavenge mode, and others must be killed if the map is run anything but scavenge mode. Remember that visgroups and instances are only meaningful in Hammer. Once you run your map, the VBSP process collapses all the instances, which means everything gets lumped together, and disabled visgroups are ignored. So we need a mechanism for controlling these in game. This is where the info_gamemode entity comes in.

info_gamemode settings

The gamemode logic entities.

The icon looks like a set of playing cards.

Tip.png提示:You can also use Map > Entity Report to find it. Enable filter by class, and type in "info_gamemode".
Outputs that fire depending on gamemode.

Select it and click on the Properties button. The class info is pretty sparse, but let's look at the Outputs tab. That's where all the action is.

Here you can see that if the map loads in any gamemode other than scavenge, it fires off a logic_relay named "relay_kill_scavenge" that kills all of the scavenge-specific items in this map.

That takes care of removing everything, which is the easy scenario. Adding things, however, needs to be done in stages, so we have broken things out into their own logic_relay entities.

When the map is first loaded in scavenge mode, it fires off the "OnScavenge" event. At this point, the Director is still getting ready, and it's important not to spawn or kill entities until it is finished initializing.

After the map has been set up and the Director has been initialized, it fires off "OnScavengePostIO". We do several things here:

  1. First, we do any point_template spawning that we need to do. This example map has templates for scavenge-specific weapons, items, and the generator with the fill point.
  2. It also actuates the lift automatically, thus raising the ladder and disarming the call button.
  3. The last thing we do in post IO is adjust navigation. We've blocked some paths to balance the map, and the nav blockers are set to block.

"OnScavengeMatchStart" is, as I'm sure you've guessed, fired off for each match.

One of the nice things about the info_gamemode is that you can have several of them in a map. Instead of relying on a single one to do everything, the Deadline 2 map uses one in each game mode instance file. Each one is responsible for spawning and killing stuff related to that particular gamemode alone. This takes a bit more effort to set up, but it helps keep things a little simpler when you're editing. And keeping things in their own "buckets" really helps when you resume editing a map that you haven't touched for a while.

Using info_director

info_director outputs.

In some cases, you will not be able to fully compartmentalize a gamemode. For example, scavenge maps require that the info_director, which is in the main map because it is used by all game modes, have certain outputs mapped as shown to the right.

You'll notice that survival has its own instance as well, with coop and versus modes are combined together into their own. Of course, you may organize your map and support gamemodes as you see fit, with or without instances.