horsegen: redesign character template
This commit is contained in:
@@ -5,67 +5,35 @@ module horse/{{ $.Region }}/character
|
||||
|
||||
import std/core/vector
|
||||
import std/core-extras
|
||||
import std/data/rb-map
|
||||
import horse/game-id
|
||||
pub import horse/character
|
||||
|
||||
// Character identity.
|
||||
pub type character
|
||||
val name2id: rbmap<string, character-id> = rb-map/empty()
|
||||
{{- range $uma := $.Characters }}
|
||||
{{ kkenum $uma.Name }}
|
||||
.set({{ printf "%q" $uma.Name }}, Character-id({{ $uma.ID}}))
|
||||
{{- 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 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
|
||||
name2id.lookup(name).default(Character-id(0))
|
||||
|
||||
// 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
|
||||
// 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 $uma := $.Characters }}
|
||||
{{ $uma.ID }} -> Just( {{- kkenum $uma.Name -}} )
|
||||
{{ $uma.ID }} -> {{ printf "%q" $uma.Name }}
|
||||
{{- end }}
|
||||
_ -> Nothing
|
||||
x -> "character " ++ x.show
|
||||
|
||||
// Get the ID for a character.
|
||||
pub fun character/character-id(c: character): int
|
||||
match c
|
||||
fun character/index(c: character-id): int
|
||||
match c.game-id
|
||||
{{- 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 }}
|
||||
{{ $uma.ID }} -> {{ $uma.Index }}
|
||||
{{- end }}
|
||||
_ -> -99999999
|
||||
|
||||
// Create the table of all pair affinities.
|
||||
// The affinity is the value at a.index*count + b.index.
|
||||
@@ -87,7 +55,7 @@ extern global/create-pair-table(): vector<int>
|
||||
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
|
||||
pub fun global/pair-affinity(a: character-id, b: character-id): int
|
||||
global/pair-table.at(a.index * {{ $.Count }} + b.index).default(0)
|
||||
|
||||
// Create the table of all trio affinities.
|
||||
@@ -114,7 +82,7 @@ extern global/create-trio-table(): vector<int>
|
||||
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
|
||||
pub fun global/trio-affinity(a: character-id, b: character-id, c: character-id): int
|
||||
global/trio-table.at(a.index * {{ $.Count }} * {{ $.Count }} + b.index * {{ $.Count }} + c.index).default(0)
|
||||
|
||||
{{- end }}
|
||||
|
||||
Reference in New Issue
Block a user