forked from factoriotools/factorio-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate-settings.sh
301 lines (272 loc) · 14.9 KB
/
create-settings.sh
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
#!/bin/bash
# updateTemplate
#
# replaces the template string with either the default, or
# the value in the passed in environment variable.
#
# $1 Template String: The value that is replaced in the template.
# $2 Environment Variable String: the environment variable that is checked for a value.
# $3 Default Value: The default value used if the environment variable is empty or invalid.
updateTemplate () {
#get the value from the environment varaible and put it in val
val=${!2}
#Test if there was a value that was set.
if [[ -z "$val" ]]
then
#replace the value in the template file with the default value
sed -i "s/$1/$3/g" "$TEMPLATE_FILE"
else
#Replace the value in the template file with the value in the environment Variable
if [[ $GENERATE_SETTINGS_FILES_DEBUG ]]; then
echo Setting $1 to $val in $TEMPLATE_FILE
fi
sed -i "s/$1/$val/g" "$TEMPLATE_FILE"
fi
}
# updateTemplateBool
#
# replaces the template string with either the default, or
# the value in the passed in environment variable.
# if the value in the variable is not 'true' or 'false', the default is used.
#
# $1 Template String: The value that is replaced in the template.
# $2 Environment Variable String: the environment variable that is checked for a value.
# $3 Default Value: The default value used if the environment variable is empty or invalid.
updateTemplateBool (){
#get the value from the environment varaible and put it in val
val=${!2}
#Test if there was a value that was set to true or false
if [[ ${val} =~ ^(true)|(false)$ ]]
then
#replace the value in the template file with the argument
sed -i "s/$1/$val/g" "$TEMPLATE_FILE"
if [[ $GENERATE_SETTINGS_FILES_DEBUG ]]; then
echo Setting $1 to $val in $TEMPLATE_FILE
fi
else
#Replace the value in the template file with the default
sed -i "s/$1/$3/g" "$TEMPLATE_FILE"
fi
}
# updateTemplateNumber
#
# replaces the template string with either the default, or
# the value in the passed in environment variable.
# if the value in the variable is not anumber, the default is used.
#
# $1 Template String: The value that is replaced in the template.
# $2 Environment Variable String: the environment variable that is checked for a value.
# $3 Default Value: The default value used if the environment variable is empty or invalid.
updateTemplateNumber (){
#get the value from the environment varaible and put it in val
val=${!2}
#Test if there was a value that was set to true or false
if [[ ${val} =~ ^[0-9]+\.?[0-9]*$ ]]
then
#replace the value in the template file with the argument
sed -i "s/$1/$val/g" "$TEMPLATE_FILE"
if [[ $GENERATE_SETTINGS_FILES_DEBUG ]]; then
echo Setting $1 to $val in $TEMPLATE_FILE
fi
else
#Replace the value in the template file with the default
sed -i "s/$1/$3/g" "$TEMPLATE_FILE"
fi
}
# updateTemplateEmpty
#
# replaces the template string with either an empty string, or
# the value in the passed in environment variable.
#
# $1 Template String: The value that is replaced in the template.
# $2 Environment Variable String: the environment variable that is checked for a value
updateTemplateEmpty(){
#get the value from the environment varaible and put it in val
val=${!2}
#Test if there was a value that was set.
if [[ -z "$val" ]]
then
#replace the value in the template file with the default value
sed -i "s/$1//g" "$TEMPLATE_FILE"
else
#Replace the value in the template file with the value in the environment Variable
sed -i "s/$1/$val/g" "$TEMPLATE_FILE"
if [[ $GENERATE_SETTINGS_FILES_DEBUG ]]; then
echo Setting $1 to $val in $TEMPLATE_FILE
fi
fi
}
#Using the template, generate a map-settings.json file
mapSettings () {
echo Creating map generation settings file
TEMPLATE_FILE=map-settings-template.json
updateTemplateNumber templateMapDifficultyRecipe TEMPLATE_MAP_DIFFICULTY_RECIPE 0
updateTemplateNumber templateMapDifficultyTechnology TEMPLATE_MAP_DIFFICULTY_TECHNOLOGY 0
updateTemplateNumber templateMapDifficultyTechPrice TEMPLATE_MAP_DIFFICULTY_TECH_PRICE 1
updateTemplate templateMapDifficultyResearchQueue TEMPLATE_MAP_DIFFICULTY_RESEARCH_QUEUE "after-victory"
updateTemplateBool templateMapPollutionEnabled TEMPLATE_MAP_POLLUTION_ENABLED true
updateTemplateNumber templateMapPollutionDiffusionRatio TEMPLATE_MAP_POLLUTION_DIFFUSION_RATIO 0.02
updateTemplateNumber templateMapPollutionMinToDefuse TEMPLATE_MAP_POLLUTION_MIN_TO_DEFUSE 15
updateTemplateNumber templateMapPollutionAgeing TEMPLATE_MAP_POLLUTION_AGEING 1
updateTemplateNumber templateMapPollutionExpectedMaxPerChunk TEMPLATE_MAP_POLLUTION_EXPECTED_MAX_PER_CHUNK 150
updateTemplateNumber templateMapPollutionMinToShowPerChunk TEMPLATE_MAP_POLLUTION_MIN_TO_SHOW_PER_CHUNK 50
updateTemplateNumber templateMapPollutionMinToDamageTrees TEMPLATE_MAP_POLLUTION_MIN_TO_DAMAGE_TREES 60
updateTemplateNumber templateMapPollutionMaxForestDamage TEMPLATE_MAP_POLLUTION_MAX_FOREST_DAMMAGE 150
updateTemplateNumber templateMapPollutionPerTreeDamage TEMPLATE_MAP_POLLUTION_PER_TREE_DAMAGE 50
updateTemplateNumber templateMapPollutionRestoredPerTreeDamage TEMPLATE_MAP_POLLUTION_RESTORED_PER_TREE_DAMAGE 10
updateTemplateNumber templateMapPollutionMaxToRestoreTrees TEMPLATE_MAP_POLLUTION_MAX_TO_RESTORE_TREES 20
updateTemplateNumber templateMapPollutionBiterAttackModifier TEMPLATE_MAP_POLLUTION_BITER_ATTACK_MODIFIER 1
updateTemplateBool templateMapEvolutionEnabled TEMPLATE_MAP_EVOLUTION_ENABLED true
updateTemplateNumber templateMapEvolutionTimeFactor TEMPLATE_MAP_EVOLUTION_TIME_FACTOR 0.000004
updateTemplateNumber templateMapEvolutionDestroyFactor TEMPLATE_MAP_EVOLUTION_DESTROY_FACTOR 0.002
updateTemplateNumber templateMapEvolutionPollutionFactor TEMPLATE_MAP_EVOLUTION_POLLUTION_FACTOR 0.0000009
updateTemplateBool templateMapExpansionEnabled TEMPLATE_MAP_EXPANSION_ENABLED true
updateTemplateNumber templateMapExpansionMinBaseSpacing TEMPLATE_MAP_EXPANSION_MIN_BASE_SPACING 3
updateTemplateNumber templateMapExpansionMaxExpansionDistance TEMPLATE_MAP_EXPANSION_MAX_EXPANSION_DISTANCE 7
updateTemplateNumber templateMapExpansionFriendlyBaseRadius TEMPLATE_MAP_EXPANSION_FRIENDLY_BASE_RADIUS 2
updateTemplateNumber templateMapExpansionBiterBaseRadius TEMPLATE_MAP_EXPANSION_BITER_BASE_RADIUS 2
updateTemplateNumber templateMapExpansionBuildingCff TEMPLATE_MAP_EXPANSION_BUILDING_CFF 0.1
updateTemplateNumber templateMapExpansionOtherBaseCff TEMPLATE_MAP_EXPANSION_OTHER_BASE_CFF 2.0
updateTemplateNumber templateMapExpansionNeighbourChunkCff TEMPLATE_MAP_EXPANSION_NEIGHBOUR_CHUNK_CFF 0.5
updateTemplateNumber templateMapExpansionNeighbourBaseChunkCff TEMPLATE_MAP_EXPANSION_NEIGHBOUR_BASE_CHUNK_CFF 0.4
updateTemplateNumber templateMapExpansionMaxCollidingTilesCff TEMPLATE_MAP_EXPANSION_MAX_COLLIDING_TILES_CFF 0.9
updateTemplateNumber templateMapExpansionSettlerGroupMin TEMPLATE_MAP_EXPANSION_SETTLER_GROUP_MIN 5
updateTemplateNumber templateMapExpansionSettlerGroupMax TEMPLATE_MAP_EXPANSION_SETTLER_GROUP_MAX 20
updateTemplateNumber templateMapExpansionMinCooldown TEMPLATE_MAP_EXPANSION_MIN_COOLDOWN 14400
updateTemplateNumber templateMapExpansionMaxCooldown TEMPLATE_MAP_EXPANSION_MAX_COOLDOWN 216000
#unit_group, Steering, Path_finder, and max_failed_behavior_count settings not included at this time
#as they are likely very optimized by the developers;
}
#Using the template, generate a map-gen-settings.json file
mapGenSettings () {
echo Creating map settings file
TEMPLATE_FILE=map-gen-settings-template.json
updateTemplateNumber templateGenTerrainSegmentation TEMPLATE_GEN_TERRAIN_SEGMENTATION 1
updateTemplateNumber templateGenTerrainWater TEMPLATE_GEN_TERRAIN_WATER 1
updateTemplateNumber templateGenMapWidth TEMPLATE_GEN_MAP_WIDTH 0
updateTemplateNumber templateGenMapHeight TEMPLATE_GEN_MAP_HEIGHT 0
updateTemplateNumber templateGenMapStartingArea TEMPLATE_GEN_MAP_STARTING_AREA 1
updateTemplateBool templateGenPeacefullMode TEMPLATE_GEN_PEACEFULL_MODE false
#coal
updateTemplateNumber templateGenCoalRichness TEMPLATE_GEN_COAL_RICHNESS 1
updateTemplateNumber templateGenCoalSize TEMPLATE_GEN_COAL_SIZE 1
updateTemplateNumber templateGenCoalFrequency TEMPLATE_GEN_COAL_FREQUENCY 1
#stone
updateTemplateNumber templateGenStoneRichness TEMPLATE_GEN_STONE_RICHNESS 1
updateTemplateNumber templateGenStoneSize TEMPLATE_GEN_STONE_SIZE 1
updateTemplateNumber templateGenStoneFrequency TEMPLATE_GEN_STONE_FREQUENCY 1
#Copper
updateTemplateNumber templateGenCopperRichness TEMPLATE_GEN_COPPER_RICHNESS 1
updateTemplateNumber templateGenCopperSize TEMPLATE_GEN_COPPER_SIZE 1
updateTemplateNumber templateGenCopperFrequency TEMPLATE_GEN_COPPER_FREQUENCY 1
#Iron
updateTemplateNumber templateGenIronRichness TEMPLATE_GEN_IRON_RICHNESS 1
updateTemplateNumber templateGenIronSize TEMPLATE_GEN_IRON_SIZE 1
updateTemplateNumber templateGenIronFrequency TEMPLATE_GEN_IRON_FREQUENCY 1
#Uranium
updateTemplateNumber templateGenUraniumRichness TEMPLATE_GEN_URANIUM_RICHNESS 1
updateTemplateNumber templateGenUraniumSize TEMPLATE_GEN_URANIUM_SIZE 1
updateTemplateNumber templateGenUraniumFrequency TEMPLATE_GEN_URANIUM_FREQUENCY 1
#Crude
updateTemplateNumber templateGenCrudeRichness TEMPLATE_GEN_CRUDE_RICHNESS 1
updateTemplateNumber templateGenCrudeSize TEMPLATE_GEN_CRUDE_SIZE 1
updateTemplateNumber templateGenCrudeFrequency TEMPLATE_GEN_CRUDE_FREQUENCY 1
#Trees
updateTemplateNumber templateGenTreesRichness TEMPLATE_GEN_TREES_RICHNESS 1
updateTemplateNumber templateGenTreesSize TEMPLATE_GEN_TREES_SIZE 1
updateTemplateNumber templateGenTreesFrequency TEMPLATE_GEN_TREES_FREQUENCY 1
#Biters
updateTemplateNumber templateGenBiterRichness TEMPLATE_GEN_BITER_RICHNESS 1
updateTemplateNumber templateGenBiterSize TEMPLATE_GEN_BITER_SIZE 1
updateTemplateNumber templateGenBiterFrequency TEMPLATE_GEN_BITER_FREQUENCY 1
#cliffs
updateTemplate templateGenCliffName TEMPLATE_GEN_CLIFF_NAME "cliff"
updateTemplateNumber templateGenCliffElevationZero TEMPLATE_GEN_CLIFF_ELEVATION_ZERO 10
updateTemplateNumber templateGenCliffElevationInterval TEMPLATE_GEN_CLIFF_ELEVATION_INTERVAL 10
updateTemplateNumber templateGenCliffRichness TEMPLATE_GEN_CLIFF_RICHNESS 1
#expression Names
updateTemplateEmpty templateGenExpressionElevation TEMPLATE_GEN_EXPRESSION_ELEVATION
updateTemplateNumber templateGenAuxBias TEMPLATE_GEN_AUX_BIAS "0.300000"
updateTemplateNumber templateGenAuxMultiplier TEMPLATE_GEN_AUX_MULTIPLIER "1.333333"
updateTemplateNumber templateGenMoistureBias TEMPLATE_GEN_MOISTURE_BIAS "0.100000"
updateTemplateNumber templateGenMoistureMultiplier TEMPLATE_GEN_MOISTURE_MULTIPLIER "0.500000"
#Starting Point
updateTemplateNumber templateGenStartingPointX TEMPLATE_GEN_STARTING_POINT_X 1000
updateTemplateNumber templateGenStartingPointY TEMPLATE_GEN_STARTING_POINT_Y 2000
#seed
updateTemplateNumber templateGenMapSeed TEMPLATE_GEN_MAP_SEED null
}
#Using the template, generate a server-settings.json file.
serverSettings(){
echo Creating server settings file
TEMPLATE_FILE=server-settings-template.json
updateTemplate templateServerName TEMPLATE_SERVER_NAME "my-server"
updateTemplate templateServerDescription TEMPLATE_SERVER_DESCRIPTION "my-server"
updateTemplate templateServerTags TEMPLATE_SERVER_TAGS '"factorio","docker"'
updateTemplateNumber templateServerMaxPlayers TEMPLATE_SERVER_MAX_PLAYERS 0
updateTemplateBool templateServerPulicVisibility TEMPLATE_SERVER_PUBLIC_VISIBILITY true
updateTemplateBool templateServerLanVisibility TEMPLATE_SERVER_LAN_VISIBILITY true
updateTemplateEmpty templateServerUsername TEMPLATE_SERVER_USERNAME
updateTemplateEmpty templateServerPassword TEMPLATE_SERVER_PASSWORD
updateTemplateEmpty templateServerGameToken TEMPLATE_SERVER_TOKEN
updateTemplateEmpty templateServerGamePassword TEMPLATE_SERVER_GAME_PASSWORD
updateTemplateBool templateServerRequireUserVerification TEMPLATE_SERVER_REQUIRE_USER_VERIFICATION true
updateTemplateNumber templateServerMaxUploadCount TEMPLATE_SERVER_MAX_UPLOAD 0
updateTemplateNumber templateServerMaxUploadSlots TEMPLATE_SERVER_MAX_UPLOAD_SLOTS 5
updateTemplateNumber templateServerMinimumLatenctInTicks TEMPLATE_SERVER_MIN_LATENCY_TICKS 0
updateTemplateBool templateServerIgnoreLimitForReturning TEMPLATE_SERVER_IGNORE_LIMIT_FOR_RETURNING false
updateTemplate templateServerAllowCommands TEMPLATE_SERVER_ALLOW_COMMANDS "admins-only"
updateTemplateNumber templateServerAutosaveInterval TEMPLATE_SERVER_AUTOSAVE_INTERVAL 5
updateTemplateNumber templateServerAutosaveSlots TEMPLATE_SERVER_AUTOSAVE_SLOTS 3
updateTemplateNumber templateServerAFKAutokickInterval TEMPLATE_SERVER_AFK_KICK_INTERVAL 0
updateTemplateBool templateServerAutoPause TEMPLATE_SERVER_AUTOPAUSE true
updateTemplateBool templateServerOnlyAdminsPause TEMPLATE_SERVER_ADMIN_ONLY_PAUSE true
updateTemplateBool templateServerAutosaveOnlyOnServer TEMPLATE_SERVER_SERVER_ONLY_AUTOSAVE true
updateTemplateBool templateServerNonblockingSaving TEMPLATE_SERVER_NONBLOCKING_SAVE false
updateTemplateNumber templateServerMinSegmentSizeCount TEMPLATE_SERVER_MIN_SEGMENT_SIZE 25
updateTemplateNumber templateServerMinSegmentSizePeer TEMPLATE_SERVER_MIN_SEGMENT_SIZE_PEER 20
updateTemplateNumber templateServerMaxSegmentSizeCount TEMPLATE_SERVER_MAX_SEGMENT_SIZE 100
updateTemplateNumber templateServerMaxSegmentSizePeer TEMPLATE_SERVER_MAX_SEGMENT_SIZE_PEER 10
}
if [[ $FORCE_GENERATE_SETTINGS_FILES ]]
then
#backup old files using timestamp.
if [[ ! -f $CONFIG/server-settings.json ]]
then
mv "$CONFIG/server-settings.json" "$CONFIG/server-settings.json".`date +%Y.%m.%d.%H.%M.%S`
fi
if [[ ! -f $CONFIG/map-gen-settings.json ]]
then
mv "$CONFIG/map-gen-settings.json" "$CONFIG/map-gen-settings.json".`date +%Y.%m.%d.%H.%M.%S`
fi
if [[ ! -f $CONFIG/map-settings.json ]]
then
mv "$CONFIG/map-settings.json" "$CONFIG/map-settings.json".`date +%Y.%m.%d.%H.%M.%S`
fi
#generate new files.
serverSettings
mapSettings
mapGenSettings
#move new files into place
cp ./server-settings-template.json "$CONFIG/server-settings.json"
cp ./map-gen-settings-template.json "$CONFIG/map-gen-settings.json"
cp ./map-settings-template.json "$CONFIG/map-settings.json"
else
#call the functions to generate and copy the files from the templates.
if [[ ! -f $CONFIG/server-settings.json ]]
then
# generate settings if server-settings.json doesn't exist
serverSettings
cp ./server-settings-template.json "$CONFIG/server-settings.json"
fi
if [[ ! -f $CONFIG/map-gen-settings.json ]]
then
mapGenSettings
cp ./map-gen-settings-template.json "$CONFIG/map-gen-settings.json"
fi
if [[ ! -f $CONFIG/map-settings.json ]]
then
mapSettings
cp ./map-settings-template.json "$CONFIG/map-settings.json"
fi
fi