algorithm – Splitting areas throughout mountain ranges in 2D tile map partitioning, for a Civ5 mod

algorithm – Splitting areas throughout mountain ranges in 2D tile map partitioning, for a Civ5 mod

[ad_1]

I am attempting to do a rewrite of Civ5’s AssignStartingPlots.lua (Lua is the scripting language utilized by Civ5), and I am comfy writing it, however conceptually, simply determining what algorithm to make use of, I am working up in opposition to a wall.

By the purpose that this script is known as, the terrain (plains/grassland/desert/snow/jungle/hills, and many others.) has already been generated, however the sources haven’t been positioned on it. This script is meant to 1) place the sources, and a couple of) assign beginning positions to gamers.

This begins – within the default script in addition to in my rewrite – by dividing the map up into “areas” (both Tundra, Jungle, Forest, Desert, Hills, Plains, Grassland or Hybrid), which have an effect on each the place sure sources may be positioned, and the place gamers are preferentially positioned. My basic technique for that is principally flood-fill: choose e.g. a random jungle plot, iterate via its neighbors, and in the event that they 1) are additionally jungle and a couple of) should not already in a area, then add them to the area being generated, then undergo their neighbors and repeat, till each plot has been assigned a area.

One factor I wish to add although is having areas be bisected by mountain ranges – that’s, e.g. the grassland on the north facet of a mountain vary shouldn’t be positioned in the identical area because the grassland on the south facet of the mountain vary, even when they’re in any other case merely linked. However this presupposes that 1) I can inform which mountains even compose a mountain vary within the first place, and a couple of) learn how to inform which facet of the vary a plot falls on.

All of the map information is contained in international Map object and utilizing Map.GetPlot(x,y) I can get a Plot object at any (x, y, z = -(x+y) ) on the map. With nested for all x/ all y loops I can interate via each plot on the map, use Plot.IsMountain() to examine if it is a mountain, and whether it is, I can cache it in a desk. That provides me an inventory of all of the mountains on the map. After which… what do I do with it to determine which gadgets collectively compose a variety?

And for which facet of the vary a check plot is on – if the vary is completely linear then it is so simple as developing the system for a secant line from the 2 most excessive factors, after which checking the check plot’s y coordinate to see if it is greater/decrease of the y-coordinate predicted by the secant y(x). However any curvature within the mountain vary (which is sort of assured) means the secant line strategy goes to finish up assigning plots to the unsuitable facet.

[ad_2]

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply