wall building for rts games patrick schmid. age of empires

36
Wall Building for RTS Games Patrick Schmid

Upload: kyler-pollen

Post on 29-Mar-2015

220 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Wall Building for RTS Games Patrick Schmid. Age of Empires

Wall Building for RTS Games

Patrick Schmid

Page 2: Wall Building for RTS Games Patrick Schmid. Age of Empires

Age of Empires

Page 3: Wall Building for RTS Games Patrick Schmid. Age of Empires

Age of Empires

Page 4: Wall Building for RTS Games Patrick Schmid. Age of Empires

Stronghold

Page 5: Wall Building for RTS Games Patrick Schmid. Age of Empires

Walls

• Walls

• Barbed wire

• Fences

• Sandbags

• Force fields

Page 6: Wall Building for RTS Games Patrick Schmid. Age of Empires

Intelligent Wall Placement

• Locations to protect

• Use natural barriers

• Wall cost

• Distance from a given location

• Size of protected area

Page 7: Wall Building for RTS Games Patrick Schmid. Age of Empires

Possible Solutions

• Build rectangular wall

• Add walls to level via map editor

• Wall-building algorithm

Page 8: Wall Building for RTS Games Patrick Schmid. Age of Empires

Problem Definition

• Protect a given location by blocking the movement of enemy units

• Implies:– Block all access routes– No breaks

Page 9: Wall Building for RTS Games Patrick Schmid. Age of Empires

Preliminaries

• Restricted to tile-based maps• Obstruction footprints confined to tiles• Wall segment

– Passive defensive structure– Blocks unit movement over a single tile

• Two wall segments are adjacent when they touch along the edges (not diagonals)

• Four adjacent wall segments (neighbors) for each free standing wall segment

• Each wall segment of a wall has two neighbors

Page 10: Wall Building for RTS Games Patrick Schmid. Age of Empires

Definitions

A wall is a set of wall segments connected together in such a way that

– Every wall segments has exactly two unique neighbors ( wall segments linked in circular fashion)

– At least one interior tile (tile inside the walled-off area)

– All interior tiles (interior area) are connected through edges (not diagonally).

Page 11: Wall Building for RTS Games Patrick Schmid. Age of Empires

Examples

Page 12: Wall Building for RTS Games Patrick Schmid. Age of Empires

Acceptance Criteria

• Minimum / maximum distance from location to protect

• Minimum / maximum number of interior tiles

• Maximum number of wall segments (cost of building wall)

Page 13: Wall Building for RTS Games Patrick Schmid. Age of Empires

Definition of Problem

On a given tile map, build a wall that fits the definition, protects the given location, and meets the given acceptance criteria.

Page 14: Wall Building for RTS Games Patrick Schmid. Age of Empires

Wall-building algorithm

• Starting location (given) that needs to be protected

• Apply an initial wall around this location• Move wall outwards greedily: remove an existing

wall segment and place it in a different location, so that– Net gain of exactly one interior tile– Resulting wall still meets the wall definition

• Some moves might require addition of extra wall segments

• Stop when acceptance criteria are met

Page 15: Wall Building for RTS Games Patrick Schmid. Age of Empires

Possible wall segments

Page 16: Wall Building for RTS Games Patrick Schmid. Age of Empires

Possible moves

Page 17: Wall Building for RTS Games Patrick Schmid. Age of Empires

Does this work?

• Every group allows 17 possible moves= 68 possible moves

• Common patterns can be used to reduce number of cases

• Natural barriers act similarly to wall segments

• Natural barriers will greatly increase the number of possible moves

Large number of moves

Page 18: Wall Building for RTS Games Patrick Schmid. Age of Empires

Is there a better way?

• Instead of expanding wall, expand interior area

• Once expansion is done, generate wall around interior area

Page 19: Wall Building for RTS Games Patrick Schmid. Age of Empires

Definitions

• Node = representation of the smallest area, e.g. a tile or a waypoint, that can be obstructed by the placement of game objects

• Graph with every edge connecting two nodes

• Edge defines path units can take

• Nodes sharing same edge are called adjacent

Page 20: Wall Building for RTS Games Patrick Schmid. Age of Empires

Definitions (cont.)

• A node can have any number of adjacent nodes

• A wall segment that is part of a wall still only has two neighbors

• Interior tile interior node• Interior area set of interior nodes• Starting location starting node• Move process of adding new nodes to

the interior area

Page 21: Wall Building for RTS Games Patrick Schmid. Age of Empires

New wall-building algorithm

• Start with starting node

• Expand interior area by adding one node per step

• Select the node to add using a greedy methodology ( heuristic function)

• Stop when acceptance criteria are met

Page 22: Wall Building for RTS Games Patrick Schmid. Age of Empires

Data structures

• Closed list– Nodes in the interior area

• Open list– Nodes bordering the interior area– Ranked by heuristic function– After node was moved to closed list, add new

neighboring nodes

Page 23: Wall Building for RTS Games Patrick Schmid. Age of Empires
Page 24: Wall Building for RTS Games Patrick Schmid. Age of Empires

Traversal Function

• Get all successor nodes for a particular node

• Power to block individual node to prevent the interior area from spreading into undesirable areas

• Frequently used by heuristic function to get list of successor nodes for cost calculation

Page 25: Wall Building for RTS Games Patrick Schmid. Age of Empires

Heuristic Function

f(n) is cost function representing the cost of adding node n to interior area

c is a constant larger than the maximum possible distance from the starting node

w(n) is the cost of walling off node nd(n) is the distance from node n to the starting

node

distance minimum)(

distance minimum)(

)()(*

0)(

nd

nd

ndnwcnf

Page 26: Wall Building for RTS Games Patrick Schmid. Age of Empires

w(n)

• Number of wall segments needed to keep the new node walled off from the outside area

• Only w(n) generates asymmetric walls stretching in only one direction– Why?– List of successor nodes tends to be arranged in a certain order.– Beginning of list gets preference over nodes with same cost

further down the list– Leads to expansion in general direction of successor node at the

top of the list

distance minimum)(

distance minimum)(

)()(*

0)(

nd

nd

ndnwcnf

Page 27: Wall Building for RTS Games Patrick Schmid. Age of Empires

d(n)

• Add distance from starting node• Maximize the minimum wall distance from the

starting node for same wall cost good for defensive purposes

• Distance-related part has to be less significant than portion related to walling-off

• Achieve this by multiplying cost of walling off with the maximum distance (c)

distance minimum)(

distance minimum)(

)()(*

0)(

nd

nd

ndnwcnf

Page 28: Wall Building for RTS Games Patrick Schmid. Age of Empires

Minimum distance

• Gives priority (0) to the nodes closer than the required minimum distance

• Need to adjust acceptance function to require that all nodes have reached minimum distance

• Used to protected important location, e.g. building, from enemy fire

distance minimum)(

distance minimum)(

)()(*

0)(

nd

nd

ndnwcnf

Page 29: Wall Building for RTS Games Patrick Schmid. Age of Empires

What about natural barriers?

• Traversal has to ignore natural barriers

• Heuristic function needs to treat barriers as free wall segments and ignore them in the calculation of w(n)

• Efficient implementation: Change node traversal to ignore barriers

Page 30: Wall Building for RTS Games Patrick Schmid. Age of Empires

Map Edges?

• Inaccessible, maybe even permanent fog of war– Requires impassable terrain around them– Treated as natural barriers

• Embraced as part of game play– Traversal cannot find nodes past the map

edges– Heuristic function has no cost for those nodes– Area past the edges treated as invisible

natural barrier

Page 31: Wall Building for RTS Games Patrick Schmid. Age of Empires

Maximum Distance?

• Do not let open nodes at maximum distance become interior nodes

• Undermines functionality of open list!• Introduce maximum distance list

– Holds nodes located at max distance– Before adding a node to open list, check its distance– If equal to max distance, add it to max distance list– Upon completion, merge open and max distance list

to get final solution

• Used to place wall within manageable distance, or ensure protective cover of tower fire

Page 32: Wall Building for RTS Games Patrick Schmid. Age of Empires

Doors and Gates?

• A wall without doors and gates is not that useful!• Simply place gates at evenly spaced locations in

the wall– Dumb solution– Might place a gate right in front of a natural barrier– Might not get us to all interesting locations

• Smart solution: Create paths from starting location to interesting outside locations. Where path and wall intersect, place a gate.

Page 33: Wall Building for RTS Games Patrick Schmid. Age of Empires

Diagonal Walls?

• Walls might be connectable diagonally

• Cost function needs to ignore cost of walling off a diagonal direction

• Diagonal successor nodes may not be added to open list

Page 34: Wall Building for RTS Games Patrick Schmid. Age of Empires

Demonstration

Page 35: Wall Building for RTS Games Patrick Schmid. Age of Empires

Actual Games

Author of chapter (Mario Grimani) worked on– Age of Empires II: The Age of Kings– Age of Empires II: The Conquerors– Age of Mythology– Sovereign– Everquest II

Page 36: Wall Building for RTS Games Patrick Schmid. Age of Empires

Reference

• Mario Grimani – “Wall Building for RTS Games”. AI Game Programming Wisdom 2