1 / 52

Map / Wall Generation

Automatic generation and maintenance of maps and walls. Map / Wall Generation. Content Overview. Generating maps What do we want in a map? Warcraft 3 map editor RTS maps for Empire Earth Wall Building Generating intelligent barriers Populating large worlds using limited resources

nuala
Download Presentation

Map / Wall Generation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Automatic generation and maintenance of maps and walls Map / Wall Generation

  2. Content Overview • Generating maps • What do we want in a map? Warcraft 3 map editor • RTS maps for Empire Earth • Wall Building • Generating intelligent barriers • Populating large worlds using limited resources • The Waterfall Algorithm

  3. Generating an RTS map

  4. RTS Map Generation: Overview • Place players on the map first • Grow land for each player • Land that has not been allocated is considered water • Analyze terrain and add features • Place resources around players fairly

  5. Scripting for variety • Scripts are used to specify map parameters such that they can be modified quickly without programmer intervention • For example: • number of resources per player • maximum height of land • player land allocation • climate

  6. Player placement - Step 1 • Inscribe a large disk on the map • Inner and outer radii can be set in a script

  7. Player placement - Step 2 • 1 random point for each player is chosen within the disk; closest points are pushed apart • Closest points are pushed apart iteratively until distribution is satisfactory

  8. Player placement – Step 3 • If the game has teams, they are assigned to adjacent player locations

  9. Back it up - dummy players • Player locations will have allotted flat land and resources • We may want other areas of the map to also have these properties for player expansion

  10. Where to put land? • This process is centered around the positions of the players which have just been determined • Why? Land is a very important resource in RTS games: Exhibit A • Each player must receive an equal amount of buildable land

  11. Growing land: Clumps • Land is grown in around players in “Clumps” • Attributes of clumps can be set, such as: clump size, number of clumps per player, chaos level • Clumps grow (consume tiles) until they reach the predetermined size • When a clump is completed, a new clump is created a random distance and angle away until the number of clumps required are generated

  12. Two methods for growing clumps • Completion Method: One clump is grown to completion before another is started • Step Method: Grows clumps one tile per iteration. This method is used to lay out each players’ land.

  13. Keeping track of clumps • A 2-D array of all the tiles on the map is initialized such that all tiles are water • When a land clump is grown, it changes the value for its tile in the array to indicate that the tile is part of a land clump • When a land clump is grown for a player, the player’s enumerated value is placed into the land-water array

  14. Different Map Types • Island Map: Require a new land tile for a player is not within some tile distance from another player’s land • Land Map: Allow players’ land to be adjacent to an enemy player’s land

  15. Flat Clumps • While each player has been allocated an equal amount of land, nothing has been set about the conditions on the land • To ensure that each player has the same amount of buildable land, a subset of their land clumps are “Flat Elevation Clumps” • Flat Clumps are grown using the completion method and can only grow in a player’s existing land

  16. Adding interesting terrain • Terrain can be generated using Fractals – “The Diamond-Square Algorithm”

  17. Resource Allocation • Resources are placed on the map on a per-player basis • Placed within rings centered on a player’s starting location (number of resources and size of ring are attributes which can be changed with scripts) • For a particular resource, random locations in the ring are tried until an acceptable location is found • Why might a location be unacceptable? • Cannot be placed on a certain terrain • Must have a minimum distance to other resources • Cannot be too close to the player’s start location

  18. What about the trees? • Trees are placed last because they are plentiful and restrict path finding. • Forest size, number of forests per player can be specified as attributes • Forest growth is not restricted by the players’ land boundaries (unlike most other resources) • Another type of clumps, “treeClumps” are used to grow forests • Forests cannot grow near other forests, and some areas are marked as forest-free

  19. Flaws with this algorithm • High processing times • No ability to add specific terrain features • Often resulted in maps in which players had vastly different choke points, or even no access to other players • Resource placement system often created a resource advantage for certain players • Example of what these maps look like

  20. Building Walls • Many RTS games allow the player to build walls to impede enemy mobility, so AI players must be able to as well • A good wall building algorithm can make NPC opponents much more formidable • In games with a map editor, an automated wall building feature would make a level designer’s job easier

  21. Defining a Wall • A wall segment is a passive defensive structure which blocks movement over a single tile which it occupies • Wall segments are adjacent if they touch along the edges (not diagonals) • A wall is a set of wall segments which • Every wall segment has two adjacent wall segments • There is at least one interior tile • All interior tiles are connected through edges

  22. To be crystal clear…

  23. Greedy Algorithm • A greedy algorithm is one that always takes the best solution at the time • Must define a heuristic to determine how favorable a given action is • Always choose the solution with the lowest / highest value from the heuristic (depending on how your heuristic is defined) • Disadvantage: There is no guarantee that the overall solution will be optimal even if each step was optimal

  24. Approach #1- Build Wall • Given a starting location which you would like to protect with the wall • Create a simple small rectangular wall directly surrounding the starting point • Using a series of moves, expand the wall until it meets the desired properties • Each “move” moves the interior space outward such that exactly one more tile is walled off and the new wall still meets our wall definition

  25. Analyzing Permutations • In order to decide which move is best, we must consider all permutations • Each 3x3 square generates 68 permutations. • Once all permutations have been determined, calculate their heuristic value (in this case, how many wall segments must be added to accommodate including the interior node) • Option with the lowest cost is chosen

  26. What about natural barriers? • Excellent question! • Natural barriers would create many more permutations, to the point where we are forced to ask the question, “Isn’t there a more efficient way to do this?” • The solution lies in realizing that there is a one-to-one relationship between a wall and the interior space protected by the wall

  27. Paradigm shift • Instead of building the wall, we concentrate on building the space within the wall • We still start with the starting node from before (the location we’d like to defend) • The “move” described before simply becomes adding another tile to the interior space (using the same greedy algorithm)

  28. Managing the nodes (tiles) • Closed list – the list of nodes that have been selected to be in the interior space • Open list – the list of nodes that are candidates for inclusion in the closed list (on the border) • On each iteration, the nodes on the open list are inspected, and the best candidate is moved to the closed list • This process is repeated until the desired size is achieved • Upon completion, the open list becomes the list of tiles on which to build the wall

  29. Pseudocode

  30. Keys to this algorithm • Traversal Function: for a given node, determine successor nodes (that become members of the open list) • Acceptance Function: determines whether or not the current wall is acceptable (# of nodes on the closed list, etc) • Heuristic Function: ranks open nodes, and thusly controls the shape of expansion. Must attempt to maximize area walled off while minimizing cost to do so

  31. More on the Heuristic • Simply using the cost to include a node tends to result in asymmetric walls which stretch in one direction. • To correct this behavior, we add a term to the heuristic equation which increases the cost of nodes proportionally to their distance from the start node. • However, we must ensure that the distance does not out-weigh the cost of building • This results in a formula of this form f(n) = c * w(n) + d(n)

  32. What about natural barriers? • This algorithm allows us to easily incorporate the possibility of natural barriers with some modifications • Traversal Function: must be changed to ignore natural barriers when looking for nodes to include • Heuristic Function: must consider natural barrier nodes to have no cost when considering including the bordering nodes in the open set • With these modifications, the algorithm takes advantage of natural barriers and tries to use them as free walls

  33. Min/Max Distance Requirements • Minimum Distance: We may want to ensure that no wall segments are within a certain distance from the starting node. To accommodate for this, set the heuristic value (cost) of all nodes within the minimum distance to 0. • Maximum Distance: This can be done by monitoring the inclusion of nodes on the open list. If the node is at the maximum distance, add the node to a maximum distance list instead of the open list. Upon completion, we must merge the open list with the maximum distance list to get the full wall

  34. Doors and Gates • We may want to have the ability to move friendly units in and out of the walled area • Brute force method: place openings randomly or at fixed intervals • More sophisticated: create paths (using A*) from starting node to all locations of interest outside the walls. Intersections between these paths and the wall are logical locations for doors

  35. Diagonal Walls • With a few modifications, this algorithm can be adapted to games which do not allow diagonal movement • Heuristic: Cost function must ignore cost of walling off diagonally • Traversal: Ensure diagonal successor nodes are not added to the open list

  36. Populating Large Worlds • Many actors in a large world map can consume an inordinate amount of resources • “Waterfall concept” helps to alleviate pressure on system resources • General idea is to devote the most system resources to units closest to the player, and limit actions of those far away.

  37. Five Functional Components • The Context • The Character • The Personality • The Director • The Manager • Each of these is represented as a class in the architecture’s implementation

  38. The Context • The “soul” of the AI • Set of all essential variables and data required to represent the state of an agent • Is the agent currently active? • Visual representation being used • State of thought process • Information is used by the Character class to affect agent behavior

  39. The Character • Takes an instance of Context and uses the data contained therein to generate input for the agent- causes it to behave in a certain manner • Can be thought of as a script for the role the agent is playing • Will be sub-classed to generate a range of behaviors

  40. The Personality • Allows multiple agents with the same Character to act in slightly different ways • Example: if an agent drives a vehicle • Character: Agent drives fast • Personality: provides a range from which the Character provides a range of minimum speed values • Ensures that agents are unique

  41. The Director • Responsible for determining when agents fall in and out of the waterfall based on a complex set of rules • This helps maintain the illusion of a world teeming with active agents • Also chooses which Character an agent should use when it falls back into the “waterfall”

  42. The Manager • Holds, instantiates, updates, renders, and destroys all AI agents • These functions could be absorbed into the Director if desired, but separating them eases management and encapsulates functionality • Deals with the physical aspect of AI: instantiates visual and functional piece of the game the user sees

  43. Mechanics • Director determines if the Context needs to exit the waterfall • If yes, a new location is chosen for the Context, and agent is placed there • If not, a Character is chosen for the Context and the Context is assigned to a Character

  44. Mechanics cont… • Next, the Character is allowed to operate on the Context • Path information • Collision information • Friend / foe information • Character never directly moves the agent; it leaves ‘suggestions’ the agent can use to affect its physical representation • The Director then determines if the agent has left the waterfall

  45. Flow of the Waterfall • Purpose is to focus on the most interesting AI activity close to the player • Agents that have “exited” the waterfall may be recycled into a visible position or replaced with other agents • Most effective in a game where the player moves at a steady predictable rate • There must be a well-defined set of rules for when agents will enter and exit the waterfall

  46. Exit Rules • Dependant on the type of game and visibility / line-of-sight distances (the shorter these distances, the better the system will work) • Examples of exit rules • The agent is farther than a certain distance away • The agent is behind the camera for a certain amount of time • The agent is outside the view cone for a certain amount of time

  47. Entry Rules • Where to spawn the agent? • Very specific to the player’s location, movement, viewing direction • Some example rules • Enter agents behind the player, speed them up so they pass the player • Enter agents just out of player’s view distance • Enter agents into predetermined locations in anticipation of player’s arrival • What type of Character to spawn? • Are there too few agents with this Character in the Waterfall? • Are agents of this Character relevant to the game in the player’s current situation? E.g. more cops if the player is doing something illegal

  48. Optimization • Just don’t do it • If an agent too far away or occluded, turn off unnecessary functions (animation, collision checks) • Do it, but only so often • Some things can be done just once in a while (update pathfinding, searching for downhill direction, other long searches)

More Related