Tuesday, 16 September 2008

Designing a Magic System - Part Nine (Shapes and Behaviours)

(You'll probably want to read parts one, two, three, four, five, six, seven and eight before starting this).

If we are limited in the number of status effects and elements based on user interface considerations, how many different ways are there of defining damage shapes and behaviours? (By shape, I mean the volume damaged by an attack, and by behaviour I mean how this volume changes over time).

It turns out part of the answer depends on your point of view.

In a first person game, you are limited to shapes that are unique from your point of view: and damage effects that are closer to you obscure the shape of damage further away from you. In particular, a line projected from your perspective can appear the same as a number of conic shapes - which is why it is hard to judge the area covered by the flame from a Pyro's flamethrower. So for FPS games, the behaviour of a damaging attack is much more import than its shape, because attack shapes are difficult to convey.

In first person shooters, there are 4 different types of common weapon behaviours: hitscan weapons, projectiles, physics weapons and placements.

Hitscan weapons are weapons that when fired, immediately hit whatever the weapon is aimed at. They are called hitscan, because they trace, or scan, a line from the weapon to determine what is hit, and immediately apply the damage (latency considerations in multi-player games aside).

Projectiles instead model the movement of one or more projectiles leaving the gun and travelling ballistically in the direction aimed. The projectile has a defined velocity, so that it takes game time to travel to the target. Bullet drop may or may not be modelled with a projectile. Physics weapons extend the projectile concept to include more variables modelled, such as grenade bounce, penetration, particle effects and ricochets - usually using the in game physics engine. Physics weapons may have defined conditions under which they explode.

Placements are thrown or placed weapons which are detonated later: either using a remote control, trigger or proximity sensor of some kind. Finally, all of the above weapon types may model splash damage, where damage has an area effect that drops off with range from the impact point.

This is not an exhaustive list: remote control drones, target seeking weapons, and combinations of the above are all possible - but it is important to notes that the weapon behaviour is the primary determinate of how most first person weapons work, and that the shape of the projectile, hitscan and so on usually limited to a single point, perhaps including a random or predictable deviation from the intended target to mimic weapon recoil, or splash damage.

However, when you have a perspective removed from the players point of view, such as an overhead or side on perspective, you can vary the attack shape to a much greater degree. In fact, you can generate attacks which have pretty much any shape that is sufficiently memorable for the player, from a single point, to lines, cones, lines radiating out from a point, circles - affecting either the edge or the whole enclosed area, all targets in line of sight, or more complex shapes: in roguelike games even ASCII art can be used to define an attack shape. There are fighting games and shoot em ups that have attacks which fill the whole scene with a wonderful palette of unusual shapes and projectiles - there is little limit but your imagination when it comes to designing interesting attack shapes.

And the behaviour of these attacks can be complicated as well: vortexes of energy which chase after nearby targets, blasting rays that rotate around a single point, attacks which swell up to enclose much larger spaces than they initially occupied or mimic natural phenomena such as thunderstorms, volcanoes, waves or lightning bolts. You could have attacks which require you touch the target, then manipulate a voodoo doll from a safe distance, stand still while you control a illusory monster, move around to push out waves of damage on a much larger scale in the direction you step.

There are still important considerations when designing shapes for non-first person games however. The first of which is the interaction between the attack and parts of the map which normally block line of fire. For large and unusual shapes, you may either choose to allow the attack to pass through blocking grids in order to maintain the integrity of the shape, or to project the attack from a central point or points, not drawing parts of the shape which would fall outside of the line of fire of these points.

The second is the interaction between line of sight and line of fire. Depending on the algorithms you use for each, you may end up in a position where line of sight and line of fire do not coincide. This might be because you apply looser constraints to determine whether a grid is visible or not, to the constraints required to pass the projectile through intervening grids to reach the final target. You need to intuitively convey the differences, either through the targetting user interface, or by clearly showing the projectile failing to reach the target when fired. What is worse, that some times a grid may appear to be untargettable when aiming directly at it, but by aiming at a nearby or further away grid, the projectile algorithm may determine that it moves through the targetted grid as a part of the projection.

The final consideration is symmetry between player and enemy attacks. With complex attacks which do not necessarily require line of fire over the lifetime of the attack behaviour, it is possible for the player to repeatedly hit an opponent without exposing themselves for retaliation in return. This can also occur when opponents are unable to return fire at the range the player is at, or if line of fire itself is not symmetrical (possible in some grid-based line of fire implementations). In this case, the enemy AI needs to be programmed to avoid indirect attack by the player, which is a lot more difficult than simply avoiding direct attack, as all possible types of indirect fire need to be considered. Otherwise the player will be able to trap opponents using indirect attacks so that they can be killed without exposing the player themselves.

It is possible with shapes to come up with a hierarchy of less to more effective shapes. The most effective shapes are those that don't expose the player to counter-attack - as a result, these should be encumbered with drawbacks such as a limit on the number of placements, or forcing the player to stay in relative proximity to the attack, or within a proscribed area.

The least to most useful shapes affect:

1. The player
2. One target adjacent to the player
3. Multiple targets adjacent to the player
4. One target in a limited range, in line of fire
5. One target, at unlimited range, in line of fire
6. One target, ignoring some or all line of fire restrictions
7. Multiple targets in a limited range, in line of fire
8. Multiple targets, at unlimited range in line of fire
9. Multiple targets, ignoring some or all line of fire restrictions

The above hierachy is not absolute in any sense, and as pointed out in the comments and by Craig Perko in landscapes and level design, the layout of the level strongly interacts with the shapes of attacks. But thinking about a hierachy will allow you to judge whether to increase or decrease the relative power and effectiveness of attacks against the shape they damage.

For shapes where multiple grids are affected, shapes which which are closer to the player, such as a cone with the player at one terminus, are lower in the hierarchy, than shapes that are unbound; shapes which can inadvertently affect useful targets, such as the player, allies or collectible items less than shapes which can be controlled or have no drawbacks. Finally, as noted, shapes which affect grids out of line of fire of the player are the most effective.

Behaviours are simply shapes which persist for multiple game ticks - potentially transforming shape, damage and/or element over the course of the behaviour lifetime. Note that behaviours are different to timed damage: timed damage once applied can be removed as a status effect, the behaviour instead must be avoided by the target. This suggests that behaviours are preferrable to timed damage where possible.

Shapes are where your imagination can run wild, and where balancing game play is the most critical. It is possible to create interesting, vivid games with only using damage per second and damage shapes to control the game space: Team Fortress 2 and to a lesser extent the Half-Life 2 mod Dystopia are excellent examples of how the shape of the damage defines the characters in the game. Shape design interacts with map design, forcing you to think holistically about how your magic system interacts with the game spaces you build for players in your game - are corridors short or long, wide or twisty, rooms clear or filled with obstacles? These factors will determine the utility of shapes in the game, and often only extensive play testing and statistical analysis of game play will reveal the relative strengths of each shape. One of the greatest games ever made, Chess, depends entirely on the library of attack shapes of the pieces in the game, and your game should as well.

In part ten, I start to bring all the design concerns I've raised in parts one to nine together, using Angband and variants as specific examples of magic implementation, and start to consider what changes I need to make to the UnAngband magic system, and my way of thinking about game-design in general.


Mikolaj said...

> What is worse, that some times a grid may appear to be untargettable when aiming directly at it,
> but by aiming at a nearby or further away grid, the projectile algorithm may determine that it moves through the targetted grid as a part of the projection.

That's what happens in NPP, where they enchanced the LOS and targetting code from Vanilla. I'm not sure about other Angband variants.

James said...

It is possible with shapes to come up with a hierarchy of less to more effective shapes.

I think this is more dependent on the situation than you are allowing for. (Or, you are simplifying further than is a good idea, to look at it another way.)

For example, in fairly open terrain where speed and rate of attack are high compared to movement, simply out-ranging the opponent can be more effective than any tricky ability to shoot around corners. Even in the simplified terrain of a roguelike, if a map generator tends to generate straight sections of hallway comparable to or greater than effective attack range, outranging becomes effective.

In a 3-D, third-person environment, being confined to the corridors and rooms of a building, or the passages of a cave, can effectively reduce the perspective to not much better than first person as far as perception and targeting of effect areas go. This may actually be a desired effect under some circumstances, if you want a logical reason to have a different feel for "indoor" and "outdoor" combat.

In chaotic battle conditions, attacks that simply emit from the player with a keypress may be more effective in practice than attacks that require complicated targeting of an arbitrary point at range. This can be seen in City of Heroes, where there are some high-end attacks (e.g. Archery's Rain of Arrows) which require selecting the center point of the effect area in (limited) 3-space with the mouse. Most other comparable attacks either emit from the player with a single keystroke, or launch toward the currently designated target with a single keystroke. In situations where the player has time and attention, the ability to fire around corners, conduct time-on-target attacks, etc. with RoA is quite useful, increasing the effectiveness compared to the numerical stats. In pitched combat where even being able to find the pointer and direct the effect is tricky amongst all the other effects going off, the extra time and attention require reduce the effectiveness considerably compared to the numerical stats.

Turn-based games reduce this somewhat, but player ease remains a balancing factor of sorts. Consider an attack that allows specifying any three adjacent squares at range, but which requires the player to manually scroll a targeting cursor to and select each of the three squares every time. The tactical advantages are considerable, but it may not be used as often or be considered as useful as one would expect from a numerical perspective.

As for asymmetric view and fire, ideally this either doesn't happen (line of view and line of fire coincide, and are symmetrical in each direction), or it is deliberately handled to allow interesting tactical complexity.

One approach I've been musing about is to take established maneuver and terrain concepts such as "defilade", "military crest", "hull down", and "reverse slope defense"; and rotate them from the vertical to the horizontal plane. This formalizes such fuzzy concepts as "I want to be near enough to the corner that I can see around it, but not really be shot at" (turret down); "I want to be leaning around the corner to shoot / swing / etc., but still keep most of my body shielded by the corner" (hull down); "I need to advance just far enough into the cave to be able to fire on anything trying to close in by sneaking along the walls" (military crest); "I want to be far enough back in the passageway leading to this cave to significantly reduce my exposure to cross-fire from multiple potential occupants, but still be able to fire into the room somewhat" (reverse slope defense).

Andrew Doull said...

James: You are, of course, correct - I was simplifying - mostly to encourage people to develop a hierachy. The reasoning for this comes later - perhaps I should have left the hierachy concept until then.

I referenced dungeon layout in a later paragraph, and Craig Perko's article on layout and level design interacting with damage sumarises the field (I linked to this in part six - here it is again: http://projectperko.blogspot.com/2008/07/landscapes-and-level-designs-boring.html ).

I should really emphasise it more here, as it really is key, as you point out.

Antoine said...

I'd love to see a roguelike where you have a variety of shaped attack spells, so


or so


or so


and so on and so on.


Antoine said...

(Ice spells could have snowflake shaped target areas, necro spells could have skull shaped target areas, and so on and so forth...)

Mikolaj said...

> rotate them from the vertical to the horizontal plane

Wow. That would be wonderful. OTOH, I'm afraid some of these would encourage camping, which in roguelikes is even more boring than in FPS. I was so bored in Vanilla Angband just standing around a corner and tapping a strong ranged attack macro turn after turn. AI would need to help make it interesting, e.g. monsters wouldn't be lured ahead seeing their comrades killed in one or two shot without a chance to strike back.