season.gno
1.21 Kb · 48 lines
1package hall
2
3import (
4 "chain"
5 "chain/runtime"
6 "strconv"
7)
8
9// podiumSize is how many players a closing season decorates.
10const podiumSize = 3
11
12// season is a stretch of play with its own standings. New challenges
13// usually open with a new season.
14type season struct {
15 Number int
16 Name string
17 OpenedAt int64
18 ClosedAt int64 // 0 while open
19 Claims int
20 Podium []address
21}
22
23func newSeason(n int, name string) *season {
24 return &season{Number: n, Name: name, OpenedAt: runtime.ChainHeight()}
25}
26
27func currentSeason() *season { return seasons[len(seasons)-1] }
28
29// OpenSeason closes the current season, decorates its podium with season
30// badges, and opens the next one under name.
31func OpenSeason(cur realm, name string) {
32 assertCurator(cur)
33 if len(name) == 0 || len(name) > 40 {
34 panic(ErrBadSeasonName)
35 }
36 closing := currentSeason()
37 closing.ClosedAt = runtime.ChainHeight()
38 for i, row := range standings(closing.Number) {
39 if i == podiumSize {
40 break
41 }
42 closing.Podium = append(closing.Podium, row.Player)
43 awardSeason(row.Player, closing.Number, i+1)
44 }
45 next := newSeason(closing.Number+1, name)
46 seasons = append(seasons, next)
47 chain.Emit("SeasonOpened", "number", strconv.Itoa(next.Number), "name", name)
48}