121 lines
3.8 KiB
Plaintext
121 lines
3.8 KiB
Plaintext
{{ define "koka-character" -}}
|
|
module horse/{{ $.Region }}/character
|
|
|
|
// Automatically generated with horsegen; DO NOT EDIT
|
|
|
|
import std/core/vector
|
|
import std/core-extras
|
|
|
|
// Character identity.
|
|
pub type character
|
|
{{- range $uma := $.Characters }}
|
|
{{ kkenum $uma.Name }}
|
|
{{- end }}
|
|
|
|
// The list of all characters in order by ID, for easy iterating.
|
|
pub val character/all = [
|
|
{{- range $uma := $.Characters }}
|
|
{{ kkenum $uma.Name }},
|
|
{{- end }}
|
|
]
|
|
|
|
// Get the character for a character ID.
|
|
// Generally, these are four digit numbers in the range 1000-1999.
|
|
pub fun character/from-id(id: int): maybe<character>
|
|
match id
|
|
{{- range $uma := $.Characters }}
|
|
{{ $uma.ID }} -> Just( {{- kkenum $uma.Name -}} )
|
|
{{- end }}
|
|
_ -> Nothing
|
|
|
|
// Get the ID for a character.
|
|
pub fun character/character-id(c: character): int
|
|
match c
|
|
{{- range $uma := $.Characters }}
|
|
{{ kkenum $uma.Name }} -> {{ $uma.ID }}
|
|
{{- end }}
|
|
|
|
// Get the name of a character.
|
|
pub fun character/show(c: character): string
|
|
match c
|
|
{{- range $uma := $.Characters }}
|
|
{{ kkenum $uma.Name }} -> {{ printf "%q" $uma.Name }}
|
|
{{- end }}
|
|
|
|
// Compare two characters.
|
|
pub fip fun character/order2(a: character, b: character): order2<character>
|
|
match (a, b)
|
|
{{- range $uma := $.Characters }}{{ $e := kkenum $uma.Name }}
|
|
( {{- $e }}, {{ $e -}} ) -> Eq2( {{- $e -}} )
|
|
{{- if ne $uma.ID $.MaxID }}
|
|
( {{- $e }}, b') -> Lt2( {{- $e }}, b')
|
|
(a', {{ $e -}} ) -> Gt2( {{- $e }}, a')
|
|
{{- end }}
|
|
{{- end }}
|
|
|
|
// Character equality.
|
|
pub fun character/(==)(a: character, b: character): bool
|
|
match (a, b)
|
|
{{- range $uma := $.Characters }}{{ $e := kkenum $uma.Name }}
|
|
( {{- $e }}, {{ $e -}} ) -> True
|
|
{{- end }}
|
|
_ -> False
|
|
|
|
fip fun character/index(^c: character): int
|
|
match c
|
|
{{- range $uma := $.Characters }}
|
|
{{ kkenum $uma.Name }} -> {{ $uma.Index }}
|
|
{{- end }}
|
|
|
|
// Create the table of all pair affinities.
|
|
// The affinity is the value at a.index*count + b.index.
|
|
extern global/create-pair-table(): vector<int>
|
|
c inline "kk_intx_t arr[] = {
|
|
{{- range $a := $.Characters }}
|
|
{{- range $b := $.Characters }}
|
|
{{- index $.PairMaps $a.ID $b.ID }},
|
|
{{- end }}
|
|
{{- end -}}
|
|
};\nkk_vector_from_cintarray(arr, (kk_ssize_t){{ $.Count }} * (kk_ssize_t){{ $.Count }}, kk_context())"
|
|
js inline "[
|
|
{{- range $a := $.Characters }}
|
|
{{- range $b := $.Characters }}
|
|
{{- index $.PairMaps $a.ID $b.ID }},
|
|
{{- end }}
|
|
{{- end -}}
|
|
]"
|
|
val global/pair-table = global/create-pair-table()
|
|
|
|
// Base affinity between a pair using the global ruleset.
|
|
pub fun global/pair-affinity(a: character, b: character): int
|
|
global/pair-table.at(a.index * {{ $.Count }} + b.index).default(0)
|
|
|
|
// Create the table of all trio affinities.
|
|
// The affinity is the value at a.index*count*count + b.index*count + c.index.
|
|
extern global/create-trio-table(): vector<int>
|
|
c inline "kk_intx_t arr[] = {
|
|
{{- range $a := $.Characters }}
|
|
{{- range $b := $.Characters }}
|
|
{{- range $c := $.Characters }}
|
|
{{- index $.TrioMaps $a.ID $b.ID $c.ID }},
|
|
{{- end }}
|
|
{{- end }}
|
|
{{- end -}}
|
|
};\nkk_vector_from_cintarray(arr, (kk_ssize_t){{ $.Count }} * (kk_ssize_t){{ $.Count }} * (kk_ssize_t){{ $.Count }}, kk_context())"
|
|
js inline "[
|
|
{{- range $a := $.Characters }}
|
|
{{- range $b := $.Characters }}
|
|
{{- range $c := $.Characters }}
|
|
{{- index $.TrioMaps $a.ID $b.ID $c.ID }},
|
|
{{- end }}
|
|
{{- end }}
|
|
{{- end -}}
|
|
]"
|
|
val global/trio-table = global/create-trio-table()
|
|
|
|
// Base affinity for a trio using the global ruleset.
|
|
pub fun global/trio-affinity(a: character, b: character, c: character): int
|
|
global/trio-table.at(a.index * {{ $.Count }} * {{ $.Count }} + b.index * {{ $.Count }} + c.index).default(0)
|
|
|
|
{{- end }}
|