This repository has been archived by the owner on Oct 2, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathheraldry.go
218 lines (180 loc) · 4.69 KB
/
heraldry.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
package heraldry
import (
"math/rand"
"github.com/ironarachne/random"
)
// Tincture is a tincture
type Tincture struct {
Type string
Name string
Hexcode string
}
// Charge is a charge
type Charge struct {
Identifier string
Name string
Noun string
NounPlural string
Descriptor string
Article string
SingleOnly bool
Tags []string
}
// ChargeGroup is a group of charges with a common tincture
type ChargeGroup struct {
Charges []Charge
Tincture
}
// Division is a division of the field
type Division struct {
Name string
Blazon string
Tincture
}
// Variation is a variation of the field
type Variation struct {
Name string
Tincture1 Tincture
Tincture2 Tincture
}
// Field is the field of a coat of arms
type Field struct {
Division
Tincture
HasVariation bool
Variation
}
// Device is the entire coat of arms
type Device struct {
Field
ChargeGroups []ChargeGroup
AllTinctures []Tincture
}
func randomCharge() Charge {
return AvailableCharges[rand.Intn(len(AvailableCharges))]
}
func randomDivision() Division {
return AvailableDivisions[rand.Intn(len(AvailableDivisions))]
}
func randomTincture() Tincture {
typeOfTincture := random.ItemFromThresholdMap(tinctureChances)
if typeOfTincture == "metal" {
return randomTinctureMetal()
} else if typeOfTincture == "color" {
return randomTinctureColor()
} else if typeOfTincture == "stain" {
return randomTinctureStain()
}
return randomTinctureFur()
}
func randomTinctureColor() Tincture {
t := Colors[rand.Intn(len(Colors))]
return t
}
func randomTinctureFur() Tincture {
t := Furs[rand.Intn(len(Furs))]
return t
}
func randomTinctureMetal() Tincture {
t := Metals[rand.Intn(len(Metals))]
return t
}
func randomTinctureStain() Tincture {
t := Stains[rand.Intn(len(Stains))]
return t
}
func randomComplementaryTincture(t Tincture) Tincture {
var availableTinctures []Tincture
if t.Type == "color" || t.Type == "stain" {
typeOfTincture := random.ItemFromThresholdMap(colorOrStainChances)
if typeOfTincture == "color" {
for _, color := range Colors {
if color.Name != t.Name {
availableTinctures = append(availableTinctures, color)
}
}
} else {
for _, stain := range Stains {
if stain.Name != t.Name {
availableTinctures = append(availableTinctures, stain)
}
}
}
} else {
for _, metal := range Metals {
if metal.Name != t.Name {
availableTinctures = append(availableTinctures, metal)
}
}
}
t2 := availableTinctures[rand.Intn(len(availableTinctures))]
return t2
}
func randomContrastingTincture(t Tincture) Tincture {
t2 := Tincture{}
if t.Type == "metal" {
typeOfTincture := random.ItemFromThresholdMap(colorOrStainChances)
if typeOfTincture == "color" {
t2 = randomTinctureColor()
} else {
t2 = randomTinctureStain()
}
} else {
t2 = randomTinctureMetal()
}
return t2
}
func shallWeIncludeCharges() bool {
someRandomValue := rand.Intn(10)
if someRandomValue > 2 {
return true
}
return false
}
// Generate procedurally generates a random heraldic device and returns it.
func Generate() Device {
fieldTincture1 := randomTincture()
fieldTincture2 := randomComplementaryTincture(fieldTincture1)
chargeTincture := randomContrastingTincture(fieldTincture1)
var tinctures []Tincture
fieldHasContrastingTinctures := false
if rand.Intn(10) > 1 {
fieldHasContrastingTinctures = true
}
if fieldHasContrastingTinctures {
fieldTincture2 = randomContrastingTincture(fieldTincture1)
}
division := randomDivision()
division.Tincture = fieldTincture2
field := Field{Division: division, Tincture: fieldTincture1, HasVariation: false, Variation: Variation{}}
if shallWeHaveAVariation() {
variation := randomVariation()
variation.Tincture1 = randomTincture()
variation.Tincture2 = randomContrastingTincture(variation.Tincture1)
tinctures = append(tinctures, variation.Tincture1, variation.Tincture2)
field.HasVariation = true
field.Variation = variation
}
tinctures = append(tinctures, fieldTincture1)
tinctures = append(tinctures, fieldTincture2)
var charges []Charge
var chargeGroups []ChargeGroup
if shallWeIncludeCharges() {
charge := randomCharge()
chargeCountRanking := rand.Intn(10)
countOfCharges := 1
if chargeCountRanking >= 9 && !charge.SingleOnly {
countOfCharges = 3
} else if chargeCountRanking >= 7 && chargeCountRanking < 9 && !charge.SingleOnly {
countOfCharges = 2
}
for i := 0; i < countOfCharges; i++ {
charges = append(charges, charge)
}
chargeGroup := ChargeGroup{charges, chargeTincture}
tinctures = append(tinctures, chargeTincture)
chargeGroups = append(chargeGroups, chargeGroup)
}
d := Device{Field: field, ChargeGroups: chargeGroups, AllTinctures: tinctures}
return d
}