-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathshipsystem.go
More file actions
215 lines (190 loc) · 5.43 KB
/
shipsystem.go
File metadata and controls
215 lines (190 loc) · 5.43 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
package main
var statInformation map[StatType]StatInfo
type SystemType int
const (
SYS_PROPULSION SystemType = iota
SYS_POWER
SYS_COMPUTER
SYS_COMMS
SYS_NAVIGATION
SYS_SCANNER
SYS_LIFESUPPORT
SYS_STORAGE
SYS_WEAPON
SYS_SHIELD
SYS_MAXSYSTEMS
)
type ShipSystem interface {
GetStat(StatType) int
GetAllStats() map[StatType]RoomStat
AddStat(RoomStat)
RemoveStat(RoomStat)
InitStats()
Update(int)
OnStatUpdate()
}
type SystemStats struct {
Stats map[StatType]RoomStat
}
func (ss SystemStats) GetStat(s StatType) int {
if _, ok := ss.Stats[s]; ok {
return ss.Stats[s].Modifier
} else {
return 0
}
}
func (ss SystemStats) GetAllStats() map[StatType]RoomStat {
return ss.Stats
}
func (ss *SystemStats) AddStat(s RoomStat) {
if _, ok := ss.Stats[s.Stat]; ok {
ss.Stats[s.Stat] = RoomStat{s.Stat, ss.Stats[s.Stat].Modifier + s.Modifier}
} else {
ss.Stats[s.Stat] = s
}
}
func (ss *SystemStats) RemoveStat(s RoomStat) {
if _, ok := ss.Stats[s.Stat]; ok {
ss.Stats[s.Stat] = RoomStat{s.Stat, ss.Stats[s.Stat].Modifier - s.Modifier}
if ss.Stats[s.Stat].Modifier <= 0 {
delete(ss.Stats, s.Stat)
}
}
}
func (ss *SystemStats) InitStats() {
ss.Stats = make(map[StatType]RoomStat)
}
func (ss *SystemStats) OnStatUpdate() {
//no op for now.
}
type StatType int
const (
//SYS_PROPULSION stats
STAT_SUBLIGHT_THRUST StatType = iota
STAT_SUBLIGHT_FUELUSE
STAT_SUBLIGHT_POWER
STAT_FTL_THRUST
STAT_FTL_FUELUSE
STAT_FTL_POWER
//SYS_POWER stats
STAT_POWER_GEN
STAT_POWER_DRAW
//SYS_NAVIGATION stats
STAT_NAV_POWER
STAT_NAV_COMPUTER
//SYS_LIFESUPPORT
STAT_PRESSURIZATION_RATE
STAT_LS_MODULE_CAP
STAT_CO2_SCRUBRATE
//SYS_STORAGE
STAT_GENERAL_STORAGE //total volume for general item storage (L)
STAT_LIQUID_STORAGE //total volume for liquid storage (L)
STAT_GAS_STORAGE //total volume for gas storage (L)
STAT_MAXSTATS
)
type StatInfo struct {
Name string
Description string
System SystemType
Stat StatType
}
type RoomStat struct {
Stat StatType
Modifier int
}
func (rs RoomStat) GetName() string {
return statInformation[rs.Stat].Name
}
func (rs RoomStat) GetDesc() string {
return statInformation[rs.Stat].Description
}
func (rs RoomStat) GetSystem() SystemType {
return statInformation[rs.Stat].System
}
func init() {
statInformation = make(map[StatType]StatInfo)
statInformation[STAT_SUBLIGHT_THRUST] = StatInfo{
Name: "Sublight Thrust Factor",
Description: "The thrust provided by the engine for sublight-travel",
System: SYS_PROPULSION,
Stat: STAT_SUBLIGHT_THRUST,
}
statInformation[STAT_SUBLIGHT_FUELUSE] = StatInfo{
Name: "Sublight Fuel Use",
Description: "The fuel used by the engine for sublight-travel",
System: SYS_PROPULSION,
Stat: STAT_SUBLIGHT_FUELUSE,
}
statInformation[STAT_SUBLIGHT_POWER] = StatInfo{
Name: "Sublight Power Draw",
Description: "The power used by the engine for sublight-travel",
System: SYS_PROPULSION,
Stat: STAT_SUBLIGHT_POWER,
}
statInformation[STAT_FTL_THRUST] = StatInfo{
Name: "FTL Thrust Factor",
Description: "The thrust provided by the engine for FTL-travel",
System: SYS_PROPULSION,
Stat: STAT_FTL_THRUST,
}
statInformation[STAT_FTL_FUELUSE] = StatInfo{
Name: "FTL Fuel Use",
Description: "The fuel used by the engine for FTL-travel",
System: SYS_PROPULSION,
Stat: STAT_FTL_FUELUSE,
}
statInformation[STAT_FTL_POWER] = StatInfo{
Name: "FTL Power Draw",
Description: "The power used by the engine for FTL-travel",
System: SYS_PROPULSION,
Stat: STAT_FTL_POWER,
}
statInformation[STAT_POWER_GEN] = StatInfo{
Name: "Power Generation",
Description: "Ship power generated by the module.",
System: SYS_POWER,
Stat: STAT_POWER_GEN,
}
statInformation[STAT_POWER_DRAW] = StatInfo{
Name: "Power Draw",
Description: "Ship power drawn by the module on a regular basis.",
System: SYS_POWER,
Stat: STAT_POWER_DRAW,
}
statInformation[STAT_LS_MODULE_CAP] = StatInfo{
Name: "Life Support Module Limit",
Description: "Number of modules life support system can safely support. Trying to support mode modules than this cap will affect efficiency and performance of all life support systems.",
System: SYS_LIFESUPPORT,
Stat: STAT_LS_MODULE_CAP,
}
statInformation[STAT_PRESSURIZATION_RATE] = StatInfo{
Name: "Pressurization Rate",
Description: "Rate at which life support can repressurize a room.",
System: SYS_LIFESUPPORT,
Stat: STAT_PRESSURIZATION_RATE,
}
statInformation[STAT_CO2_SCRUBRATE] = StatInfo{
Name: "CO2 Scrub Rate",
Description: "Rate at which life support can scrub CO2 from atmosphere and replace with life giving O2.",
System: SYS_LIFESUPPORT,
Stat: STAT_CO2_SCRUBRATE,
}
statInformation[STAT_GENERAL_STORAGE] = StatInfo{
Name: "General Storage",
Description: "Store all the things you love, in Litres.",
System: SYS_STORAGE,
Stat: STAT_GENERAL_STORAGE,
}
statInformation[STAT_LIQUID_STORAGE] = StatInfo{
Name: "Liquid Storage",
Description: "Storage for liquids (water, fuel, etc.), in Litres ",
System: SYS_STORAGE,
Stat: STAT_LIQUID_STORAGE,
}
statInformation[STAT_GAS_STORAGE] = StatInfo{
Name: "Gas Storage",
Description: "Storage for gasses, in Litres.",
System: SYS_STORAGE,
Stat: STAT_GAS_STORAGE,
}
}