Skip to content

Commit

Permalink
Improve relationships for pantheons
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Overmyer committed May 28, 2019
1 parent f8930b1 commit 6d48d21
Show file tree
Hide file tree
Showing 6 changed files with 218 additions and 58 deletions.
14 changes: 9 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ require (
github.com/Joker/hpp v1.0.0 // indirect
github.com/ajstarks/svgo v0.0.0-20181006003313-6ce6a3bcf6cd
github.com/divan/num2words v0.0.0-20170904212200-57dba452f942
github.com/flosch/pongo2 v0.0.0-20190505152737-8914e1cf9164 // indirect
github.com/go-chi/chi v4.0.2+incompatible
github.com/ironarachne/heraldry v0.0.0-20190325172346-07bf7eeae990
github.com/juju/testing v0.0.0-20190415054131-a282c42ba059 // indirect
golang.org/x/crypto v0.0.0-20190411191339-88737f569e3a // indirect
golang.org/x/net v0.0.0-20190415214537-1da14a5a36f2 // indirect
golang.org/x/sys v0.0.0-20190416124237-ebb4019f01c9 // indirect
golang.org/x/tools v0.0.0-20190415205951-2e9de471ebd3 // indirect
github.com/juju/testing v0.0.0-20190429233213-dfc56b8c09fc // indirect
github.com/klauspost/compress v1.5.0 // indirect
github.com/klauspost/cpuid v1.2.1 // indirect
golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f // indirect
golang.org/x/net v0.0.0-20190522155817-f3200d17e092 // indirect
golang.org/x/sys v0.0.0-20190524152521-dbbf3f1254d4 // indirect
golang.org/x/text v0.3.2 // indirect
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135 // indirect
)
13 changes: 13 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ github.com/divan/num2words v0.0.0-20170904212200-57dba452f942/go.mod h1:K88GQWK1
github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385/go.mod h1:0vRUJqYpeSZifjYj7uP3BG/gKcuzL9xWVV/Y+cK33KM=
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
github.com/flosch/pongo2 v0.0.0-20181225140029-79872a7b2769/go.mod h1:tbAXHifHQWNSpWbiJHpJTZH5fi3XHhDMdP//vuz9WS4=
github.com/flosch/pongo2 v0.0.0-20190505152737-8914e1cf9164/go.mod h1:tbAXHifHQWNSpWbiJHpJTZH5fi3XHhDMdP//vuz9WS4=
github.com/go-check/check v1.0.0-20180628173108-788fd7840127/go.mod h1:9ES+weclKsC9YodN5RgxqK/VD9HM9JsCSh7rNhMZE98=
github.com/go-chi/chi v4.0.2+incompatible h1:maB6vn6FqCxrpz4FqWdh4+lwpyZIQS7YEAUcHlgXVRs=
github.com/go-chi/chi v4.0.2+incompatible/go.mod h1:eB3wogJHnLi3x/kFX2A+IbTBlXxmMeXJVKy9tTv1XzQ=
Expand All @@ -29,11 +30,14 @@ github.com/juju/loggo v0.0.0-20180524022052-584905176618/go.mod h1:vgyd7OREkbtVE
github.com/juju/loggo v0.0.0-20190212223446-d976af380377/go.mod h1:vgyd7OREkbtVEN/8IXZe5Ooef3LQePvuBm9UWj6ZL8U=
github.com/juju/testing v0.0.0-20180920084828-472a3e8b2073/go.mod h1:63prj8cnj0tU0S9OHjGJn+b1h0ZghCndfnbQolrYTwA=
github.com/juju/testing v0.0.0-20190415054131-a282c42ba059/go.mod h1:63prj8cnj0tU0S9OHjGJn+b1h0ZghCndfnbQolrYTwA=
github.com/juju/testing v0.0.0-20190429233213-dfc56b8c09fc/go.mod h1:63prj8cnj0tU0S9OHjGJn+b1h0ZghCndfnbQolrYTwA=
github.com/kataras/golog v0.0.0-20180321173939-03be10146386/go.mod h1:PcaEvfvhGsqwXZ6S3CgCbmjcp+4UDUh2MIfF2ZEul8M=
github.com/kataras/iris v11.1.1+incompatible/go.mod h1:ki9XPua5SyAJbIxDdsssxevgGrbpBmmvoQmo/A0IodY=
github.com/kataras/pio v0.0.0-20190103105442-ea782b38602d/go.mod h1:NV88laa9UiiDuX9AhMbDPkGYSPugBOV6yTZB1l2K9Z0=
github.com/klauspost/compress v1.4.1/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
github.com/klauspost/compress v1.5.0/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
github.com/klauspost/cpuid v1.2.1/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/pty v1.1.4/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
Expand All @@ -48,22 +52,31 @@ github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeV
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190411191339-88737f569e3a/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE=
golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190324223953-e3b2ff56ed87/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190327091125-710a502c58a2/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190415100556-4a65cf94b679/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190415214537-1da14a5a36f2/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190322080309-f49334f85ddc/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190415145633-3fd5a3612ccd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190416124237-ebb4019f01c9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190524152521-dbbf3f1254d4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20181221001348-537d06c36207/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190325161752-5a8dccf5b48a/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190415205951-2e9de471ebd3/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA=
Expand Down
7 changes: 4 additions & 3 deletions pkg/culture/religion.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ type ReligionClass struct {

func (culture Culture) generateReligion() Religion {
religion := Religion{}
var deities []pantheon.Deity

deities := make(map[string]pantheon.Deity)

religion.Class = randomReligionClass()
religion.GatheringPlaceName = religion.randomGatheringPlaceName()
Expand All @@ -37,11 +38,11 @@ func (culture Culture) generateReligion() Religion {
} else {
deity.Name = culture.Language.RandomGenderedName("female")
}
deities = append(deities, deity)
deities[deity.Name] = deity
}

religion.Pantheon.Deities = deities
religion.Pantheon.Relationships = religion.Pantheon.GenerateRelationships()
religion.Pantheon.Deities = religion.Pantheon.GenerateRelationships()

return religion
}
Expand Down
15 changes: 13 additions & 2 deletions pkg/pantheon/deities.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package pantheon
import (
"math/rand"

"github.com/ironarachne/world/pkg/language"
"github.com/ironarachne/world/pkg/random"
)

Expand All @@ -13,10 +14,11 @@ type Deity struct {
Appearance string
Gender string
PersonalityTraits []string
Relationships []Relationship
}

// GenerateDeity generates a random deity
func (pantheon Pantheon) GenerateDeity() Deity {
func (pantheon Pantheon) GenerateDeity(lang language.Language) Deity {
var deity Deity
var domain Domain
var allDomains []Domain
Expand Down Expand Up @@ -49,7 +51,7 @@ func (pantheon Pantheon) GenerateDeity() Deity {

deity.PersonalityTraits = deity.getRandomTraits()

deity.Name = pantheon.Language.RandomName()
deity.Name = lang.RandomName()

return deity
}
Expand All @@ -63,3 +65,12 @@ func getRandomGender() string {

return random.StringFromThresholdMap(genders)
}

func randomDeityNameFromMap(deities map[string]Deity) string {
names := []string{}
for _, d := range deities {
names = append(names, d.Name)
}

return names[rand.Intn(len(names)-1)]
}
54 changes: 6 additions & 48 deletions pkg/pantheon/pantheon.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,70 +4,28 @@ import (
"math/rand"

"github.com/ironarachne/world/pkg/language"
"github.com/ironarachne/world/pkg/random"
)

// Pantheon is a nonhierarchical group of deities
type Pantheon struct {
Language language.Language
Deities []Deity
Relationships []Relationship
}

// Relationship is a unidirectional relationship between deities
type Relationship struct {
Origin Deity
Target Deity
Descriptor string
Deities map[string]Deity
}

// Generate creates a random pantheon of deities
func Generate(maxSize int, lang language.Language) Pantheon {
var deity Deity
var pantheon Pantheon

numberOfDeities := rand.Intn(maxSize) + 1
pantheon.Deities = make(map[string]Deity)

pantheon.Language = lang
numberOfDeities := rand.Intn(maxSize) + 1

for i := 0; i < numberOfDeities; i++ {
deity = pantheon.GenerateDeity()
pantheon.Deities = append(pantheon.Deities, deity)
deity = pantheon.GenerateDeity(lang)
pantheon.Deities[deity.Name] = deity
}

pantheon.Relationships = pantheon.GenerateRelationships()
pantheon.Deities = pantheon.GenerateRelationships()

return pantheon
}

// GenerateRelationships generates relationships between deities
func (pantheon Pantheon) GenerateRelationships() []Relationship {
var descriptor string
var relationship Relationship
var relationships []Relationship
var target Deity

descriptors := []string{
"is parent to",
"hates",
"loves",
"fears",
"respects",
"is amused by",
"is chagrined by",
"worries about",
"is suspicious of",
}

for _, deity := range pantheon.Deities {
target = pantheon.Deities[rand.Intn(len(pantheon.Deities))]
descriptor = random.String(descriptors)
relationship = Relationship{Origin: deity, Target: target, Descriptor: descriptor}

if deity.Name != target.Name {
relationships = append(relationships, relationship)
}
}

return relationships
}
173 changes: 173 additions & 0 deletions pkg/pantheon/relationships.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
package pantheon

import (
"math/rand"

"github.com/ironarachne/world/pkg/random"
)

// Relationship is a unidirectional relationship between deities
type Relationship struct {
Target string
Descriptor string
Type string
}

// RelationshipType is a type of relationship
type RelationshipType struct {
Name string
Descriptors []string
}

// GenerateRelationships generates relationships between deities
func (pantheon Pantheon) GenerateRelationships() map[string]Deity {
var descriptor string
var relationship Relationship
var inverse Relationship
var inverseDeity Deity
var relationshipType RelationshipType
var target string

modifiedDeities := make(map[string]Deity)

relationshipTypes := getAllRelationshipTypes()

for _, deity := range pantheon.Deities {
for i := 0; i < 3; i++ {
target = randomDeityNameFromMap(pantheon.Deities)
relationshipType = relationshipTypes[rand.Intn(len(relationshipTypes)-1)]
descriptor = random.String(relationshipType.Descriptors)

if deity.Name != target {
if relationshipType.Name == "parent" {
if deity.Gender == "male" {
descriptor = "is the father of"
} else if deity.Gender == "female" {
descriptor = "is the mother of"
}
} else if relationshipType.Name == "child" {
if deity.Gender == "male" {
descriptor = "is the son of"
} else if deity.Gender == "female" {
descriptor = "is the daughter of"
}
}
relationship = Relationship{Target: target, Descriptor: descriptor, Type: relationshipType.Name}
if !isRelationshipADuplicate(relationship, deity.Relationships) {
deity.Relationships = append(deity.Relationships, relationship)
}

modifiedDeities[deity.Name] = deity
}
}
}

for _, deity := range modifiedDeities {
for _, r := range deity.Relationships {
inverse = deity.getInverseRelationship(r)
if !isRelationshipADuplicate(inverse, modifiedDeities[r.Target].Relationships) {
inverseDeity = modifiedDeities[r.Target]
inverseDeity.Relationships = append(inverseDeity.Relationships, inverse)
modifiedDeities[r.Target] = inverseDeity
}
}
}

return modifiedDeities
}

func getAllRelationshipTypes() []RelationshipType {
types := []RelationshipType{
RelationshipType{
Name: "parent",
Descriptors: []string{
"created",
"gave birth to",
"is parent of",
},
},
RelationshipType{
Name: "child",
Descriptors: []string{
"was created by",
"is child of",
},
},
RelationshipType{
Name: "friend",
Descriptors: []string{
"is a confidant of",
"is a friend of",
"is an ally of",
},
},
RelationshipType{
Name: "enemy",
Descriptors: []string{
"despises",
"fears",
"hates",
"is the enemy of",
"is the eternal rival of",
"is the hated foe of",
},
},
RelationshipType{
Name: "lover",
Descriptors: []string{
"loves",
"adores",
},
},
RelationshipType{
Name: "opinion",
Descriptors: []string{
"is amused by",
"is bored by",
"is chagrined by",
"is suspicious of",
"respects",
"tends to avoid",
"worries about",
},
},
}

return types
}

func getRelationshipType(name string) RelationshipType {
allTypes := getAllRelationshipTypes()

for _, t := range allTypes {
if t.Name == name {
return t
}
}

return RelationshipType{}
}

func (deity Deity) getInverseRelationship(relationship Relationship) Relationship {
inverseType := relationship.Type

if relationship.Type == "parent" {
inverseType = "child"
} else if relationship.Type == "child" {
inverseType = "parent"
}

inverse := getRelationshipType(inverseType)
inverseDescriptor := random.String(inverse.Descriptors)

return Relationship{Target: deity.Name, Descriptor: inverseDescriptor, Type: inverseType}
}

func isRelationshipADuplicate(relationship Relationship, relationships []Relationship) bool {
for _, r := range relationships {
if relationship.Type == r.Type && relationship.Target == r.Target {
return true
}
}
return false
}

0 comments on commit 6d48d21

Please sign in to comment.