xonecas.ioDon't click! Sean Caetano Martin Sign in
space-browser / server / stats.go 22 lines677 bytes Raw
1package main
2
3// Every piece carries two numbers: hit points and fuel. A square is twice as
4// tough as anything else and a star carries five times the fuel; each tier adds
5// half again on top, so a fully upgraded piece is worth two base pieces of it.
6func stats(kind string, tier int) (hp, fuel float64) {
7	hp, fuel = 10, 1
8	switch kind {
9	case "square":
10		hp = 20
11	case "star":
12		fuel = 5
13	}
14	m := 1 + 0.5*float64(tier)
15	return hp * m, fuel * m
16}
17
18// A new piece arrives intact: full hit points for its kind and tier.
19func (h *hub) fitted(kind string, tier int) piece {
20	hp, _ := stats(kind, tier)
21	return piece{ID: h.pieceID(), Kind: kind, HP: hp, MaxHP: hp, Tier: tier}
22}