19
19
import mindustry .graphics .*;
20
20
import mindustry .graphics .g3d .*;
21
21
import mindustry .graphics .g3d .PlanetGrid .*;
22
+ import mindustry .io .*;
22
23
import mindustry .maps .generators .*;
23
24
import mindustry .world .*;
24
25
import mindustry .world .blocks .*;
@@ -127,15 +128,21 @@ public class Planet extends UnlockableContent{
127
128
public boolean allowWaves = false ;
128
129
/** If false, players are unable to land on this planet's numbered sectors. */
129
130
public boolean allowLaunchToNumbered = true ;
131
+ /** If true, the player is allowed to change the difficulty/rules in the planet UI. */
132
+ public boolean allowCampaignRules = false ;
130
133
/** Icon as displayed in the planet selection dialog. This is a string, as drawables are null at load time. */
131
134
public String icon = "planet" ;
132
135
/** Plays in the planet dialog when this planet is selected. */
133
136
public Music launchMusic = Musics .launch ;
134
137
/** Default core block for launching. */
135
138
public Block defaultCore = Blocks .coreShard ;
139
+ /** Global difficulty/modifier settings for this planet's campaign. */
140
+ public CampaignRules campaignRules = new CampaignRules ();
141
+ /** Defaults applied to the rules. */
142
+ public CampaignRules campaignRuleDefaults = new CampaignRules ();
136
143
/** Sets up rules on game load for any sector on this planet. */
137
144
public Cons <Rules > ruleSetter = r -> {};
138
- /** Parent body that this planet orbits around. If null, this planet is considered to be in the middle of the solar system.*/
145
+ /** Parent body that this planet orbits around. If null, this planet is considered to be in the middle of the solar system. */
139
146
public @ Nullable Planet parent ;
140
147
/** The root parent of the whole solar system this planet is in. */
141
148
public Planet solarSystem ;
@@ -183,6 +190,7 @@ public Planet(String name, Planet parent, float radius){
183
190
184
191
//calculate solar system
185
192
for (solarSystem = this ; solarSystem .parent != null ; solarSystem = solarSystem .parent );
193
+ allowCampaignRules = isVanilla ();
186
194
}
187
195
188
196
public Planet (String name , Planet parent , float radius , int sectorSize ){
@@ -200,17 +208,38 @@ public Planet(String name, Planet parent, float radius, int sectorSize){
200
208
}
201
209
}
202
210
211
+ public void saveRules (){
212
+ Core .settings .putJson (name + "-campaign-rules" , campaignRules );
213
+ }
214
+
215
+ public void loadRules (){
216
+ campaignRules = Core .settings .getJson (name + "-campaign-rules" , CampaignRules .class , () -> campaignRules );
217
+ }
218
+
203
219
public @ Nullable Sector getStartSector (){
204
220
return sectors .size == 0 ? null : sectors .get (startSector );
205
221
}
206
222
207
223
public void applyRules (Rules rules ){
224
+ applyRules (rules , false );
225
+ }
226
+
227
+ public void applyRules (Rules rules , boolean customGame ){
208
228
ruleSetter .get (rules );
209
229
210
230
rules .attributes .clear ();
211
231
rules .attributes .add (defaultAttributes );
212
232
rules .env = defaultEnv ;
213
233
rules .planet = this ;
234
+
235
+ if (!customGame ){
236
+ campaignRules .apply (rules );
237
+ }
238
+ }
239
+
240
+ public void applyDefaultRules (CampaignRules rules ){
241
+ JsonIO .copy (campaignRuleDefaults , rules );
242
+ rules .sectorInvasion = allowSectorInvasion ;
214
243
}
215
244
216
245
public @ Nullable Sector getLastSector (){
@@ -327,6 +356,9 @@ public void load(){
327
356
328
357
@ Override
329
358
public void init (){
359
+ applyDefaultRules (campaignRules );
360
+ loadRules ();
361
+
330
362
if (techTree == null ){
331
363
techTree = TechTree .roots .find (n -> n .planet == this );
332
364
}
0 commit comments