Skip to content

Instantly share code, notes, and snippets.

@michaeltchapman
Last active November 15, 2019 09:49
Show Gist options
  • Save michaeltchapman/866bc11c9ff3a44469921cb756c002e8 to your computer and use it in GitHub Desktop.
Save michaeltchapman/866bc11c9ff3a44469921cb756c002e8 to your computer and use it in GitHub Desktop.
[
{
"Name": "Build00",
"ProcedureTag": "World.Procedure.Build.Minor00",
"Executions": [
"Select 0 near SpatialGG.Region.Centre above 0 below 3",
"Sort 0 by Random",
"Register from 0 to World.Claimed.Faction.0.1.Capital",
"Truncate 0 max 1 min 1",
"Add Tag 0 World.Passable.City",
"Grow 0 to 0 count 8 minimum 4 deny World.Claimed.Faction",
"Grow 0 to 0 count 2 minimum 2 uniform deny World.Claimed.Faction",
"Grow 0 to 0 count 24 minimum 18 deny World.Claimed.Faction",
"Select 1 near World.Claimed.Faction.0.1.Capital above 0 below 8",
"Filter 1 using Empty",
"Set Intersection from 1 to 0",
"Duplicate 0 to 2",
"Set Difference from 1 to 2",
"Add Tag 0 World.Claimed.Faction.0.1",
"Add Tag 1 World.Claimed.Faction",
"Add Tag 2 World.Buffer",
"Filter 2 World.Claimed.Faction using HasOnly",
"Execute World.Procedure.Build.Minor00.Resources with {0,1,2}"
]
},
{
"Name": "BuildMajorFactionFirstSubFaction",
"ProcedureTag": "World.Procedure.Build.Minor10",
"Executions": [
"Select 0 near World.Tmp1 above 12 below 16",
"Filter 0 World.Claimed.Faction using HasNoneExact",
"Sort 0 by Random",
"Register from 0 to World.Tmp2",
"Truncate 0 max 1 min 1",
"Add Tag 0 World.Passable.City",
"Execute World.Procedure.Build.Major.Grow with {0,1,2}",
"Filter 1 using Empty",
"Set Intersection from 1 to 0",
"Duplicate 0 to 2",
"Set Difference from 1 to 2",
"Add Tag 1 World.Claimed.Faction",
"Add Tag 2 World.Buffer",
"Filter 1 World.Claimed.Faction using HasOnly",
"Execute World.Procedure.Build.MajorSub.Resources with {0,1,2}",
"Execute World.Procedure.Connect with {2,3}"
]
},
{
"Name": "Major1",
"ProcedureTag": "World.Procedure.Build.Major1",
"Executions": [
"Execute World.Procedure.GetImpassable with {3,0}",
"Register copy World.Claimed.Faction.0.1.Capital to World.Tmp1",
"Execute World.Procedure.Build.Minor10 with {0,1,2,3}",
"Register copy World.Tmp2 to World.Claimed.Faction.1.0.Capital",
"Add Tag 0 World.Claimed.Faction.1.0",
"Register copy World.Claimed.Faction.1.0.Capital to World.Tmp1",
"Execute World.Procedure.Build.MajorSub with {0,1,2,3}",
"Register copy World.Tmp2 to World.Claimed.Faction.1.1.Capital",
"Add Tag 0 World.Claimed.Faction.1.1",
"Register copy World.Claimed.Faction.1.0.Capital to World.Tmp1",
"Execute World.Procedure.Build.MajorSub with {0,1,2,3}",
"Register copy World.Tmp2 to World.Claimed.Faction.1.2.Capital",
"Add Tag 0 World.Claimed.Faction.1.2"
]
},
{
"Name": "Major2",
"ProcedureTag": "World.Procedure.Build.Major2",
"Executions": [
"Register copy World.Claimed.Faction.0.1.Capital to World.Tmp1",
"Execute World.Procedure.Build.Minor10 with {0,1,2,3}",
"Register copy World.Tmp2 to World.Claimed.Faction.2.0.Capital",
"Add Tag 0 World.Claimed.Faction.2.0",
"Register copy World.Claimed.Faction.2.0.Capital to World.Tmp1",
"Execute World.Procedure.Build.MajorSub with {0,1,2,3}",
"Register copy World.Tmp2 to World.Claimed.Faction.2.1.Capital",
"Add Tag 0 World.Claimed.Faction.2.1",
"Register copy World.Claimed.Faction.2.0.Capital to World.Tmp1",
"Execute World.Procedure.Build.MajorSub with {0,1,2,3}",
"Register copy World.Tmp2 to World.Claimed.Faction.2.2.Capital",
"Add Tag 0 World.Claimed.Faction.2.2"
]
},
{
"Name": "Major3",
"ProcedureTag": "World.Procedure.Build.Major3",
"Executions": [
"Register copy World.Claimed.Faction.0.1.Capital to World.Tmp1",
"Execute World.Procedure.Build.Minor10 with {0,1,2,3}",
"Register copy World.Tmp2 to World.Claimed.Faction.3.0.Capital",
"Add Tag 0 World.Claimed.Faction.3.0",
"Register copy World.Claimed.Faction.3.0.Capital to World.Tmp1",
"Execute World.Procedure.Build.MajorSub with {0,1,2,3}",
"Register copy World.Tmp2 to World.Claimed.Faction.3.1.Capital",
"Add Tag 0 World.Claimed.Faction.3.1",
"Register copy World.Claimed.Faction.3.0.Capital to World.Tmp1",
"Execute World.Procedure.Build.MajorSub with {0,1,2,3}",
"Register copy World.Tmp2 to World.Claimed.Faction.3.2.Capital",
"Add Tag 0 World.Claimed.Faction.3.2"
]
},
{
"Name": "BuildMajorSub",
"ProcedureTag": "World.Procedure.Build.MajorSub",
"Executions": [
"Select 0 near World.Tmp1 above 8 below 12",
"Filter 0 using Empty",
"Sort 0 by Random",
"Register from 0 to World.Tmp2",
"Truncate 0 max 1 min 1",
"Add Tag 0 World.Passable.City",
"Execute World.Procedure.Build.Major.Grow with {0,1,2}",
"Filter 1 using Empty",
"Set Intersection from 1 to 0",
"Duplicate 0 to 2",
"Set Difference from 1 to 2",
"Add Tag 2 World.Buffer",
"Add Tag 1 World.Claimed.Faction",
"Filter 1 World.Claimed.Faction using HasOnly",
"Execute World.Procedure.Build.MajorSub.Resources with {0,1,2}",
"Execute World.Procedure.Connect with {2,3}"
]
},
{
"Name": "BuildMajorSubResources",
"ProcedureTag": "World.Procedure.Build.MajorSub.Resources",
"Executions": [
"Duplicate 0 to 1",
"Filter 1 World.Passable.City using HasNoneExact",
"Sort 1 by Random",
"Duplicate 1 to 2",
"Truncate 1 max 3 min 2",
"Add Tag 1 World.Passable.Essence",
"Set Difference from 2 to 1",
"Duplicate 1 to 2",
"Sort 1 by Random",
"Truncate 1 max 3 min 2",
"Add Tag 1 World.Passable.Metal",
"Set Difference from 2 to 1",
"Sort 1 by Random",
"Duplicate 1 to 2",
"Truncate 1 max 3 min 2",
"Add Tag 1 World.Passable.Wood",
"Set Difference from 2 to 1",
"Sort 1 by Random",
"Duplicate 1 to 2",
"Truncate 1 max 2 min 1",
"Add Tag 1 World.Passable.Gold"
]
},
{
"Name": "BuildMinorRuinedResources",
"ProcedureTag": "World.Procedure.Build.Minor00.Resources",
"Executions": [
"Sort 0 by Random",
"Duplicate 0 to 1",
"Filter 1 World.Passable.City using HasNoneExact",
"Duplicate 1 to 2",
"Truncate 1 max 5 min 4",
"Add Tag 1 World.Passable.Metal",
"Set Difference from 2 to 1",
"Duplicate 1 to 2",
"Sort 1 by Random",
"Truncate 1 max 5 min 4",
"Add Tag 1 World.Passable.Wood",
"Set Difference from 2 to 1",
"Duplicate 1 to 2",
"Sort 1 by Random",
"Truncate 1 max 4 min 3",
"Add Tag 1 World.Passable.Gold",
"Set Difference from 2 to 1",
"Duplicate 1 to 2",
"Sort 1 by Random",
"Truncate 1 max 4 min 3",
"Add Tag 1 World.Passable.Ruins"
]
},
{
"Name": "GrowMajorSubFaction",
"ProcedureTag": "World.Procedure.Build.Major.Grow",
"Executions": [
"Grow 0 to 0 count 8 minimum 4 deny World.Claimed.Faction",
"Grow 0 to 0 count 1 minimum 1 uniform deny World.Claimed.Faction",
"Grow 0 to 0 count 18 minimum 14 deny World.Claimed.Faction",
"Select 1 near World.Tmp2 above 0 below 6"
]
},
{
"Name": "BuildBuildBufferResources",
"ProcedureTag": "World.Procedure.Build.Resources.Contested",
"Executions": [
"Select 0 near SpatialGG.Region.All",
"Filter 0 World.Buffer using HasAnyExact",
"Grow 0 to 0 count 1 minimum 1 uniform deny World.Claimed.Faction",
"Grow 0 to 0 count 64 minimum 32 deny World.Claimed.Faction",
"Add Tag 0 World.Buffer",
"Select 0 near SpatialGG.Region.All",
"Filter 0 World.Buffer using HasAnyExact",
"Sort 0 by Random",
"Duplicate 0 to 1",
"Truncate 0 max 15 min 10",
"Add Tag 0 World.Passable.Gold",
"Set Difference from 1 to 0",
"Duplicate 0 to 1",
"Sort 0 by Random",
"Truncate 0 max 20 min 15",
"Add Tag 0 World.Passable.Wood",
"Set Difference from 1 to 0",
"Duplicate 0 to 1",
"Sort 0 by Random",
"Truncate 0 max 20 min 15",
"Add Tag 0 World.Passable.Metal",
"Set Difference from 1 to 0",
"Duplicate 0 to 1",
"Sort 0 by Random",
"Truncate 0 max 20 min 15",
"Add Tag 0 World.Passable.Essence",
"Set Difference from 1 to 0",
"Duplicate 0 to 1",
"Sort 0 by Random",
"Truncate 0 max 20 min 15",
"Add Tag 0 World.Passable.Ruins"
]
},
{
"Name": "GetImpassable",
"ProcedureTag": "World.Procedure.GetImpassable",
"Executions": [
"Select 0 near SpatialGG.Region.All",
"Filter 0 World.Impassable.Mountain,World.Impassable.Water using HasAnyExact"
]
},
{
"Name": "Connect",
"ProcedureTag": "World.Procedure.Connect",
"Executions": [
"Path 0 src World.Tmp1 dest World.Tmp2 disallow 1",
"Filter 0 using Empty",
"Add Tag 0 World.Buffer"
]
},
{
"Name": "Biomes",
"ProcedureTag": "World.Procedure.Biomes",
"Executions": [
"Select 0 near SpatialGG.Region.All"
]
},
{
"Name": "BuildAll",
"ProcedureTag": "World.Procedure.Build",
"Executions": [
"Execute World.Procedure.Build.Minor00 with {0,1,2,3}",
"Execute World.Procedure.Build.Major1 with {0,1,2,3}",
"Execute World.Procedure.Build.Major2 with {0,1,2,3}",
"Execute World.Procedure.Build.Major3 with {0,1,2,3}",
"Execute World.Procedure.Build.Resources.Contested with {0,1,2,3}"
]
}
]

Graph Queries

SpatialGG Objects have the ability to execute queries against their graph, storing the results to a set of PCGGraphQueryBuffer arrays. These queries can either be a read or an update, and will execute against the regions stored within a provided buffer.

Initialisation

Use InitialiseBuffersAndRegisters to create a given number of buffers with a provided Random seed. The buffer length will be the size of the graph in the SpatialGG zone, so do this after Initialising the zone within its hull.

Available Commands

General usage

Int params

Whenever a non-buffer integer is used, it can be substituted for a tag with a preceding $. For example:

Select 0 near SpatialGG.Region.Centre above $World.Separation.Min below $World.Separation.Max

Will use the register to find the values for World.Separation.Min. This can be used to set up global parameter sets within procedures before starting to control sizes easily.

Tag Params

Whenever a tag parameter is used, it can be substituted for an int with a preceding $. This will use the tag map of the corresponding index for the currently executing procedure. For example:

Execute World.Build.All tags A.B,C.D,E.F

...
inside World.Build.All
...

Select 0 near $1 above 0 below 3

Will execute the World.Build.All procedure with three tags in its TagMap, which we can then reference within the procedure using $0 $1 and $2. In this case, it will select all regions within range 3 of C.D.

Sort

Sort {BufferIdx} by Index

Sort the given buffer by region index using standard quicksort

Sort {BufferIdx} by distance from {ReferenceRegion}

Sort the given buffer by distance from a registered region. This uses spatial distance, not graph distance

Sort {BufferIdx} by Random

Shuffle the given buffer

Select

Select {BufferIdx} near {RegionTag} [above {MinRange}] [below {MaxRange}]

Find regions within a given graph distance of a registered region and put them into the given buffer. Use SpatiallGG.Region.All to get the entire graph.

Find Path

Path {OutBuffer} src {StartRegion} dest {EndRegion} [disallow {InBuffer}]

Find a path through the graph from StartRegion to EndRegion without going through any region in InBuffer and place it in OutBuffer

Register

Register from {SourceBuffer} to {RegisterTag} [index {Index}] Register copy {SourceTag} to {DestTag} Register buffer {SourceBuffer} from {SrcTag} Register value {Integer} to {DestTag}

Add a single region from SourceBuffer to the QueryRegister using RegisterTag. Will add the first region by default but can use others using Index. Can also copy a register to a new tag, or add a registered region to a buffer.

Filter by Tag

Filter {Bufferindex} {A.B,X.Y} using HasAll

Filter {Bufferindex} {A.B,X.Y} using HasAllExact

Filter {Bufferindex} {A.B,X.Y} using HasAny

Filter {Bufferindex} {A.B,X.Y} using HasAnyExact

Filter {Bufferindex} {A.B,X.Y} using HasOnly

Filter {Bufferindex} {A.B,X.Y} using HasOnlyExact

Filter {Bufferindex} {A.B,X.Y} using HasNone

Filter {Bufferindex} {A.B,X.Y} using HasNoneExact

Filter {Bufferindex} using Empty

Filter {Bufferindex} using NotEmpty

Remove regions from the given buffer that do not match the specified Tag Container Query.

Set Operations

Set SymDifference from {InBuffer} to {OutBuffer}

Set Difference from {InBuffer} to {OutBuffer}

Set Union from {InBuffer} to {OutBuffer}

Set Intersection from {InBuffer} to {OutBuffer}

Perform the given set operation: OutBuffer = InBuffer [operation] OutBuffer

Truncate

Truncate {BufferIdx} max {MaxCount} [min {MinCount}]

Reduce the size of given buffer to be between minimum and maximum. Will use randomstream if minimum != maximum.

Filter By Border

BorderFilter {BufferIdx} {Border}

Remove regions from the buffer that match the given border index.

  • -1 Remove all regions that sit on a border of the parent convex hull
  • >=0 Remove all regions that sit on the specified border

Modify

Add Tag {BufferIdx} {Tag}

Add a single tag to all regions in the buffer

Remove Tag {BufferIdx} {Tag}

Remove a single tag from all regions in the buffer

Add Tags {BufferIdx} {A.B,X.Y}

Add a set of tags to all regions in the buffer

Remove Tags {BufferIdx} {A.B,X.Y}

Remove a set of tags from all regions in the buffer

Remove AllTags {BufferIdx}

Remove all tags from all regions in the buffer

Execute

Execute {ProcedureTag} with {2,5}

Execute a stored procedure with the given tag, with the procedure's buffer 0 set to the current buffer 2, and the procedure's buffer 1 set to the current buffer 5. So if we have a top level procedure that has placed things we need in buffers 2 and 5, the procedure will reference them with 0 and 1.

Duplicate

Duplicate {InBufferIdx} to {OutBufferIdx}

Copy the contents of InBuffer to OutBuffer

Grow

Grow {InBufferIdx} to {OutBufferIdx} count {MaxCount} [minimum {MinCount}] [static || uniform] [require {A.B,X.Y}] [deny {A.B,X.Y}]

Add a neighbour of InBuffer to OutBuffer and repeat between MaxCount and MinCount times.

  • If static is not set, neighbours of the regions added will be included in the set of neighbours to choose from.
  • If require or deny are provided, only neighbours that HaveAllExact or HaveNoneExact will be selected.
  • If Uniform is set, the entire neighbour set will be added for each count.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment