95 lines
3.4 KiB
Plaintext
95 lines
3.4 KiB
Plaintext
{{ define "koka-character" -}}
|
|
module horse/{{ $.Region }}/character
|
|
|
|
// Automatically generated with horsegen; DO NOT EDIT
|
|
|
|
import std/core/delayed
|
|
import std/core/vector
|
|
import std/core-extras
|
|
import std/data/rb-map
|
|
import horse/game-id
|
|
pub import horse/character
|
|
|
|
extern create-id-table(): vector<int>
|
|
c inline "int32_t arr[] = { {{- range $chara := $.Characters }}{{ $chara.ID }},{{ end -}} };\nkk_vector_from_cint32array(arr, (kk_ssize_t){{ $.CharaCount }}, kk_context())"
|
|
js inline "[{{ range $chara := $.Characters }}{{ $chara.ID }},{{ end }}]"
|
|
// Vector of all character ID values in order for easy iterating.
|
|
pub val all = once(create-id-table)
|
|
|
|
val name2id = once()
|
|
var m: rbmap<string, int> := empty()
|
|
all().foreach() fn(id) m := m.set(Character-id(id).show, id)
|
|
m
|
|
|
|
// Get the character ID that has the given exact name.
|
|
// If no character matches the name, the result is an invalid ID.
|
|
pub fun from-name(name: string): character-id
|
|
Character-id(name2id().rb-map/lookup(name).default(0))
|
|
|
|
// Get the name for a character.
|
|
// If no character matches the ID, the result is the numeric ID.
|
|
pub fun show(c: character-id): string
|
|
match c.game-id
|
|
{{- range $chara := $.Characters }}
|
|
{{ $chara.ID }} -> {{ printf "%q" $chara.Name }}
|
|
{{- end }}
|
|
x -> "character " ++ x.show
|
|
|
|
fun character/index(c: character-id): int
|
|
match c.game-id
|
|
{{- range $chara := $.Characters }}
|
|
{{ $chara.ID }} -> {{ $chara.Index }}
|
|
{{- end }}
|
|
_ -> -99999999
|
|
|
|
// 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 "int32_t arr[] = {
|
|
{{- range $a := $.Characters }}
|
|
{{- range $b := $.Characters }}
|
|
{{- index $.PairMaps $a.ID $b.ID }},
|
|
{{- end }}
|
|
{{- end -}}
|
|
};\nkk_vector_from_cint32array(arr, (kk_ssize_t){{ $.CharaCount }} * (kk_ssize_t){{ $.CharaCount }}, 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-id, b: character-id): int
|
|
global/pair-table.at(a.index * {{ $.CharaCount }} + 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 "int32_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_cint32array(arr, (kk_ssize_t){{ $.CharaCount }} * (kk_ssize_t){{ $.CharaCount }} * (kk_ssize_t){{ $.CharaCount }}, 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-id, b: character-id, c: character-id): int
|
|
global/trio-table.at(a.index * {{ $.CharaCount }} * {{ $.CharaCount }} + b.index * {{ $.CharaCount }} + c.index).default(0)
|
|
{{ end }}
|