-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata.go
98 lines (85 loc) · 3.04 KB
/
data.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package data
type Resource struct {
Name string `json:",omitempty"`
Type string `json:",omitempty"`
IsHidden bool `json:",omitempty"`
Count float64 `json:",omitempty"`
Cap float64 `json:",omitempty"`
Producers []Resource `json:",omitempty"`
// Count += Producer.Count * Factor * elapsedTime
Factor float64 `json:",omitempty"`
// Count += floor(Producer.Count) * Factor * elapsedTime
ProductionFloor bool `json:",omitempty"`
// Count += (Producer.Count > 0 ? 1 : 0) * Factor * elapsedTime
ProductionBoolean bool `json:",omitempty"`
// Count = StartCount + Producer.Count * Factor
StartCount float64 `json:",omitempty"`
// Count = Producer.Count * Factor
StartCountFromZero bool `json:",omitempty"`
// Count = StartCount + (Producer.Count * Factor) % ProductionModulus
ProductionModulus int `json:",omitempty"`
// Count = StartCount if (Producer.Count * Factor) % ProductionModulus == ProductionModulusEquals else 0
ProductionModulusEquals int `json:",omitempty"`
// Count = min(Min, Count)
Min float64 `json:",omitempty"`
// Production *= 1 + sum(Bonus)
Bonus []Resource `json:",omitempty"`
// Production *= sum(Bonus)
BonusStartsFromZero bool `json:",omitempty"`
// Production *= 1 + product(Bonus)
BonusIsMultiplicative bool `json:",omitempty"`
// negative production reduces consumers
ProductionOnGone bool `json:",omitempty"`
OnGone []Resource `json:",omitempty"`
// Cap = CapResource.Count
CapResource string `json:",omitempty"`
// Count = ResetResource.Count
ResetResource string `json:",omitempty"`
ProducerAction string `json:",omitempty"`
// generated production formula
Formula string `json:",omitempty"`
}
type Action struct {
Name string `json:",omitempty"`
Type string `json:",omitempty"`
UnlockedBy string `json:",omitempty"`
LockedBy string `json:",omitempty"`
Costs []Resource `json:",omitempty"`
Adds []Resource `json:",omitempty"`
IsHidden bool `json:",omitempty"`
// Cost = Count * pow(CostExponentBase, add.Count)
CostExponentBase float64 `json:",omitempty"`
// Cost = Count * pow(rate(CostExponentBaseResource), add.Count)
CostExponentBaseResource Resource `json:",omitempty"`
// extra fields for convenience
Producers []Resource `json:",omitempty"`
Bonus []Resource `json:",omitempty"`
ResetResource string `json:",omitempty"`
}
var (
ParsedInputTypeSkip = "s"
ParsedInputTypeCreate = "c"
ParsedInputTypeMax = "m"
ParsedInputTypeReset = "r"
ParsedInputTypeHide = "h"
ParsedInputTypeShow = "S"
ParsedInputTypeUndo = "u"
ParsedInputTypes = []string{ParsedInputTypeSkip, ParsedInputTypeCreate, ParsedInputTypeMax, ParsedInputTypeReset, ParsedInputTypeHide, ParsedInputTypeShow, ParsedInputTypeUndo}
)
type ParsedInput struct {
Type string
Arg string
Index int
Count int
Action Action
}
func (r *Resource) Add(add Resource, factor float64) {
r.Cap += add.Cap * factor
r.Count += add.Count * factor
if r.Count > r.Cap && r.Cap >= 0 {
r.Count = r.Cap
}
if r.Count < 0 {
r.Count = 0
}
}