-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLand_Grab_source.js
5730 lines (5605 loc) · 723 KB
/
Land_Grab_source.js
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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//Land Grab is a resource management game about saving people from a natural disaster.
/** Note to player: paste your save string right here (if you have one). **/
var g_LoadString = "";
/*Thank you to:
https://www.khanacademy.org/computer-programming/image-tutorial-hope/6740408654856192
*/
/** Normally, I'm a huge believer in putting lots of comments in my code. **/
/** Due to file size restrictions, I removed comments to make room for more code. **/
{
frameRate(30);
var tilesClaimed=0;
var goldenClaimTilesLeft=0;
var shiftPressed=false;
var TT_PAVED_OVER=0,TT_DESERT=1,TT_LAKE=2,TT_PLAINS=3,TT_SWAMP=4,TT_SLIMED=5,TT_MAP_EDGE=6,TT_LAVA=7,TT_WASTELAND=8,TT_MITHRIL=9,TT_CYBERMIND=10,TT_DDESERT=11,TT_DLAKE=12,TT_DPLAINS=13,TT_DSWAMP=14,TT_DCYBERMIND=15,TT_DWASTELAND=16,BT_HOUSE=0,BT_FARM=1,BT_COLLECTOR=2,BT_MINE=3,BT_MER_MALL=4,BT_ENCHANTING_TABLE=5,BT_FURNACE=6,BT_TERRAFORMER=7,BT_REEF=8,BT_SHELTER=9,BT_IRS=10,BT_MITHRIL_MINE=11,BT_LAVA_FREEZER=12,BT_BACKSIDE_TERRAFORMER=13,BT_UNDERWATER_RUINS=14,CT_SWARM=0,CT_DRAGON=1,CT_BURNING=2,CT_FISH=3,CT_CAMEL=4,CT_SLIME=5,CT_DEC_EYE=6,CT_SPARK=7,CT_TRAIN_HEAD=8,CT_TRAIN_BODY=9,CT_TRAIN_TAIL=10,CT_TURTLE=11,CT_TILE_GEN_FORCER=12,CT_FIRE_GIANT=13,CT_COSMIC=14,CT_EDGE_FINDER=15;
//Each is the amount generated or consumed per day:
var foodProduction=0;
var foodProductionFromHouse=0;
var foodProductionFromFarms=0;
var foodInternalFromRibbon=0;
var foodProjectedProductionFromTerraformers=0;
var foodProductionMulti=1;
var foodProductionMultiFromUCC=1;
var foodProductionMultiFromAqueductsOriginal=1;
var foodProductionMultiFromAqueducts=1;
var foodProductionMultiFromIronTools=1;
var foodProductionMultiFromInstaGrow=1;
var foodAppleProductionMultiFromFrosthour=1;
var foodConsumption=0;
var foodConsumptionFromHouse=0;
var foodConsumptionFromDragons=0;
var foodConsumptionFromBank=0;
var foodConsumptionMulti=1;
var foodConsumptionMultiFromSpice=1;
var foodNetIncome=0;
var foodResource=20;
var foodBonusFromFishingOnReef=0;
var foodGainedAtEachSpellCast=0;
var foodGivenToBank=0;
var manaProduction=0;
var manaProductionFromCollectors=0;
var manaProductionFromCollectionPower=0;
var manaProductionFromHouse=0;
var manaConsumption=0;
var manaConsumptionFromMines=0;
var manaConsumptionFromLifeSupport=0;
var manaConsumptionFromFarms=0;
var manaConsumptionFromAutocasting=0;
var manaProductionMulti=1;
var manaProductionMultiFromFrosthour=1;
var manaProductionMultiFromMagicOre=1;
var manaProductionMultiFromCyber=1;
var manaProductionMultiFromChallengeRules=1;
var manaProductionMultiFromRuneStoneOriginal=1;
var manaProductionMultiFromRuneStoneFinal=1;
var manaProductionMultiFrom8YC=1;
var runeStoneEffectExponent=1;
var manaProductionMultiFromH2O=1;
var manaConsumptionMulti=1;
var manaConsumptionMultiFromFans=1;
var manaNetIncome=0;
var manaResource=0;
var manaFromSlimeMulti=1;
var manaAndGdFromSlimeMultiFrom8YC=1;
var manaFromSlimeMultiFromTech=1;
var pearlProduction=0;
var pearlProductionFromReef=0;
var pearlProductionFromH2O=0;
var pearlConsumption=0;
var pearlConsumptionFromLavaFreezers=0;
var pearlProductionMulti=1;
//Note: Ultimate Upgrades also affect pearl from fishing
var pearlProductionMultiFromUltimate=1;
var pearlProductionMultiFromMultiShift=1;
var pearlProductionMultiFromFrosthour=1;
var pearlConsumptionMulti=1;
var pearlConsumptionMultiFromFans=1;
var pearlTradeMultiFromCyber=1;
var pearlNetIncome=0;
var pearlResource=0;
var pearlFromFishMulti=1;
var enchantingPearlCostMulti=1;
var stoneProductionFromMines=0;
var stoneProjectedIncomeFromLavaFreezers=0;
var stoneProductionMulti=1;
var stoneProductionMultiFromStonemover=1;
var stoneProductionMultiFromMineralEnrichment=1;
var stoneProductionMultiFromReefMagic=1;
var stoneProductionMultiFromChallengeRules=1;
var stoneProductionMultiFromCoolRock=1; //Also affects manual mining
var stoneProductionMultiFromFrosthour=1;
var stoneGuaranteedProduction=0;
var stoneProjectedProduction=0;
var stoneConsumption=0;
var stoneConsumptionFromRuneStone=0;
var stoneConsumptionFromFurnaces=0;
var stoneConsumptionMulti=1;
var stoneConsumptionMultiFromGiants=1;
var stoneNetIncome=0;
var stoneResource=10;
var stoneLastConsumedByRuneStone=0;
var generalManualMiningMulti=1;
var spiceProjectedProduction=0;
var spiceConsumption=0;
var spiceConsumptionFromHouse=0;
var spiceConsumptionFromDragons=0;
var spiceConsumptionFromMines=0;
var spiceConsumptionFromInnovation=0;
var spiceConsumptionMulti=1;
var spiceTradeMultiFromCyber=1;
var spiceNetIncome=0;
var spiceResource=0;
var gadoliniumProduction=0;
var gadoliniumProductionFromMines=0;
var gadoliniumProductionFromLavaFreezers=0;
var gadoliniumProductionMulti=1;
var gadoliniumProductionMultiFromUltimate=1;
var gadoliniumNetIncome=0;
var gadoliniumResource=0;
var gadoliniumFromSlimeMulti=1;
var gadoliniumFromSlimeMultiFromHouse=1;
var gadoliniumFromSlimeMultiFromFrost=1;
var gadoliniumFromSlimeMultiFromCyber=1;
var flameOrbProduction=0;
var flameOrbProductionFromLavaFreezers=0;
var flameOrbProductionFromFireplace=0;
var flameOrbConsumption=0;
var flameOrbConsumptionFromFrosthour=0;
var flameOrbConsumptionFromAutocasting=0;
var flameOrbConsumptionFromFurnaces=0;
var flameOrbConsumptionFromTerraformers=0;
var flameOrbConsumptionFromEtD=0;
var flameOrbConsumptionFromSeed=0;
var flameOrbProductionMulti=1;
var flameOrbProductionMultiFromH2O=1;
var flameOrbConsumptionMulti=1;
var flameOrbConsumptionMultiFromReef=1;
var flameOrbConsumptionMultiFromSCB=1;
var flameOrbNetIncome=0;
var flameOrbResource=0;
var ironProjectedProduction=0;
var ironProjectedIncomeFromFurnaces=0;
var ironProjectedIncomeFromLavaFreezers=0;
var ironProductionMulti=1;
var ironProductionMultiFromUltimate=1;
var ironProductionMultiFromHouse=1;
var ironProductionMultiFromMineralEnrichment=1;
var ironProductionMultiFromSynergy=1;
var ironProductionMultiFromSpecialCircuitBox=1;
var ironProductionMultiFromGiants=1;
var ironMithrilProductionMultiFromFrosthour=1;
var ironConsumption=0;
var ironConsumptionFromMithrilMines=0;
var ironConsumptionFromUpkeep=0;
var ironUpkeepFromHouses=0;
var ironUpkeepFromFarms=0;
var ironUpkeepFromCollectors=0;
var ironUpkeepFromShelters=0;
var ironUpkeepFromMines=0;
var ironUpkeepFromMithrilMines=0;
var ironUpkeepFromTables=0;
var ironUpkeepFromIRSs=0;
var ironUpkeepFromLavaFreezers=0;
var ironUpkeepFromCoolingFans=0;
var ironProjectedNetIncome=0;
var ironResource=0;
var upkeepLastSatisfiedRatio=1;
var goldenAppleProjectedProduction=0;
var goldenAppleProjectedIncomeFromFarms=0;
var goldenAppleProjectedIncomeDueToTables=0;
var goldenAppleProductionMulti=1;
var goldenAppleProductionMultiFromHouse=1;
var goldenAppleProductionMultiFromTF=1;
var goldenAppleProductionMultiFromUltimate=1;
var goldenAppleNetIncome=0;
var goldenAppleResource=0;
var darkEnergyProjectedBaseIncome=0;
var darkEnergyProjectedIncomeFromMines=0;
var darkEnergyProjectedIncomeFromMithrilMines=0;
var darkEnergyProjectedIncomeFromDarkDesert=0;
var darkEnergyProductionFromTF=0;
var darkEnergyProductionMulti=1;
var darkEnergyProductionMultiFromFrosthour=1;
var darkEnergyProductionMultiFromDEC=1;
var darkEnergyProductionMultiFromCyber=1;
var darkEnergyProductionMultiFromMultiShift=1;
var darkEnergyProductionMultiFromFurnacesOriginal=1;
var darkEnergyProductionMultiFromFurnaces=1;
var darkEnergyProductionMultiFromTurtles=1;
var darkEnergyProductionMultiFromAttunement=1;
var darkEnergyProductionMultiFromChallengeRules=1;
var darkEnergyProjectedNetIncome=0;
var darkEnergyResource=0;
//For scoring DECs:
var totalDarkEnergyGained=0;
var darkEnergyFuelMultiFromFancyGlove=1;
var bioOrbProjectedProduction=0;
var bioOrbProductionFromInstaGrow=0;
var bioOrbProjectedProductionFromSeed=0;
var bioOrbConsumption=0;
var bioOrbConsumptionFromFrosthour=0;
var bioOrbConsumptionFromRibbon=0;
var bioOrbProductionMulti=1;
var bioOrbNetIncome=0;
var bioOrbResource=0;
var totalBioOrbGainedFromEnchanting=0;
var enchantingUltimBioOrbPercent=0;
var mithrilProductionFrom4PS=0;
var mithrilGuaranteedProduction=0;
var mithrilProjectedBaseIncome=0;
var mithrilProjectedIncomeFromMithrilMines=0;
var mithrilProjectedIncomeFromFurnaces=0;
var mithrilProductionMulti=1;
var mithrilProductionMultiFromReef=1;
var mithrilProductionMultiFromDrillBit=1;
var mithrilProjectedFinalIncome=0;
var mithrilResource=0;
var evacuees=0;
var evacueesEnRoute=0;
var maxEvacuees=0;
var maxEvacueesBase=0;
var maxEvacueesFromSRCs=0;
var maxEvacueesFromShelters=0;
var maxEvacueesFromWifi=0;
var maxEvacueesFromReef=0;
var maxEvacueesMulti=1;
var maxEvacueesMultiFromHouse=1;
var maxEvacueesMultiFromHeatingSystem=1;
var maxEvacueesMultiFromZoning=1;
var maxEvacueesMultiFromFoodBank=1;
var maxEvacueesMultiFromMultiShift=1;
var maxEvacueesRaw=0;
var innovationMulti=1;
var innovationPower=1;
var innovationLastConsumed=0;
var lotsOfThingsMultiFromTerraformers=1;
var tier3MultiFromUpkeep=1;
var tier3MultiFrom3B=1;
var fastererness=1;//Only affects furnaces
var textbookTier1Multi=1;
var textbookTier3Multi=1;
var foodColoringMulti=1;
//Bonuses to ench. tables:
var flameHeartMulti=1;
var enchantingTableSynergyMulti=1;
var mithrilEnchantingMultiFromSwamp=1;
var mithrilEnchantingMultiFromMines=1;
var enchantingProductMultiFromCyber=1;
var enchantingProductMultiFromTurtles=1;
var enchantingProductMultiFromFrosthour=1;
var shelterCostMultiFromPizza=1;
var resourcesOnSpellCast=0;
var greetedCosmic=!1;
var enchantingPriceMulti=1;
//See old file versions for more info:
var globalCyclicAnimation=0,gcaS=0,gcaC=1,worldgenOption=4,PerlinNoiseRandomFactor=random(-500,500),mapEdgeRandomFactor=2*sq(sin(PerlinNoiseRandomFactor))+cos(PerlinNoiseRandomFactor+7)-1,trainPowerLineX=0,canCastSpells=!0,tilesTerraformed=0,cameraX=0,cameraY=0,terraform_cost_multi=function(l){return 1.22-0.02*l;},selectedTile=-1,currentlyInBackside=!1,g_ReefData,g_Diplomacy,g_ConstructionManager,g_ToggleButtonManager,g_ResourcePane,g_Factors,g_FlyingText,g_EnchTableFlyingText,g_Dragon,g_TrainHead,g_TrainBody,g_TrainTail,g_TechnologyManager,g_TutorialProgress,g_ArtifactManager,allTiles,allEnchTableAnimations,allGoldClaimAnimations,allRWCLimiterAnimations,recalculate_building_effects,check_day_end,building_on_tile,find_closest_creature,tile_at_position,allSpells=[],allIRSDatas=[],allBuildings=[],allCreatures=[],spellHints=[],smgfxx=[0,0,0,0,0,0,0,0,0,0,0,0],smgfxy=[0,0,0,0,0,0,0,0,0,0,0,0];
//Was the cutscene shown in this run?
var backsideCutsceneShown = false;
var deCutscene2Shown = false;
var photosensitivityShown = false;
var breakdownTab=1;
var currentScreen = "frontend";
var nextScreen = "main";
var is_in_cutscene=function(){return currentScreen.includes("cutscene");};
var enchantingScreenSelection = 0;
var reefScreenShowBonuses = false;
var DECEyeGazingText = "";
//Unclaimed space & void space (NOT dark energy) is this color:
var FRONTSIDE_VOID_COLOR=color(0),BACKSIDE_VOID_COLOR=color(64,12,0);
var WM_SPELL_DESC=["Fish spawn instantly, gain pearl when fishing","Cannot be cast in Frosthour"];
var IG_SPELL_DESC=["Repairs all farms within its radius","Cannot be cast in Frosthour"];
var SM_SPELL_DESC=["Quadruples passive stone production","Autocast; triples passive stone production"];
var SM_SPELL_LORE=["An ancient spell that cleaves rock. Must be cast while standing at a lvl. 2+ mine. Named after a magic dragon who lived thousands of years ago.","A spell that cuts rock. Is autocast every 5th day, & its mana cost is amortized. Named after a magic dragon who lives thousands of years ago."];
var DA_SPELL_LORE=["Listen to the mysterious power. Allows you to detect dark energy & equip mines with the ability to mine dark energy! (Upgrade a mine to lvl. 4 while this is active.)","Listen to the force you're beginning to understand. Allows you to detect dark energy & equip mines with the ability to mine dark energy!","Listen to an energy you know rather well. Makes dark energy visible to the naked eye, allowing certain buildings to be upgraded.","Attune to the cosmic voice of a good friend. You can now cast the spell while it's still active to restore it to full duration."];
var IG_SPELL_LORE=["This spell rejuvenates crops, boosting their yield. Also spends your food to repair farms. Must be cast while standing in the midst of a destroyed farm.","This spell rejuvenates crops, boosting their yield. Also spends your food to repair farms. Can be cast on any farm."];
var FOOD_TO_KILL_SLIME=3;
var g_Credits={positions:["Design","Graphics","Writing","Programming"],playtesters:["Nathan","Ananya","JC","Batuhan","Daniel","Zeke","Ethan","Natalie","John","Pxide","Bradley","Cutler","Evan","Bruce","Billy Bob Jones","Thu","Quinn","Story"]};g_Credits.playtesters.sort();
var movesLeft = 2;
var movesPerDay = 2;
var dayCount = 1;
//If true, a tile was slimed at the beginning of today:
var tileSlimed = false;
var daysUntilSwarmArrival = 79;
var dayToUnlockDarkEnergy = 400;
var dayToRunEnd = 1000;
//The current day number is shown for a brief moment.
var ticksToShowDayNumber = 0;
//Used to animate cutscenes:
var cutsceneTickCounter = 0;
//0=spring,1=summer,2=autumn,3=winter,4=frosthour
var season=1;
var season_to_string=function(){
switch(season){case 0:return"spring";case 1:return"summer";case 2:return"autumn";case 3:return"winter";case 4:return"frosthour";default:return"undefined";}};
var rwcLimiter=createImage(32,32,RGB);noStroke();fill(128,128,128);rect(0,0,32,32);fill(192,0,0);for(var i=4;i<32;i+=8){quad(i,0,4+i,0,0,4+i,0,i);quad(32,i,32,4+i,4+i,32,i,32);}rwcLimiter=get(0,0,32,32);
var round32=function(x){
if(x<0){return-round32(-x);}var y=x-x%32;if(x%32>=16&&x>0){y+=32;}if(x&32>=-16&&x<0){y+=32;}return y;};
var true_func=function(){return!0;};
var false_func=function(){return!1;};
var null_func=function(){};
var base_flame_orb_from_enchanting;
var mana_multi_8YC=function(x){return 1+0.1*pow(x,0.65);};
var dissipation=function(){if(flameOrbResource<10000){return 1;}if(flameOrbResource<100000){return 1.1-flameOrbResource/100000;}return 0.1;};
var draw_smiley_face=function(X,Y,g){
g=g||0;var a=mouseIsPressed&&dist(mouseX,mouseY,X,Y)<20;stroke(0);fill(192*(1-g),192+63*g,0);ellipse(X,Y,40,40);if(g>0){arc(X-2,Y+3,22,20,70,170);}else if(a){line(X-8,Y+12,X+8,Y+12);}else{arc(X,Y+4,30,20,30,150);}line(X-1,Y+1,X-5,Y+6);line(X-5,Y+6,X-1,Y+6);if(g>0){line(X+9,Y-6,X+4,Y-5);fill(0);noStroke();ellipse(X-6,Y-5,4,6);}else if(a){line(X-8,Y-7,X-4,Y-5);line(X-8,Y-3,X-4,Y-5);line(X+8,Y-7,X+4,Y-5);line(X+8,Y-3,X+4,Y-5);}else{fill(0);noStroke();ellipse(X-6,Y-5,4,6);ellipse(X+6,Y-5,4,6);}};
} //General global stuff
{
//For more info, see past file versions:
var Persistent_Data=function(){
this.saveNeeded=!1;this.statTotalPeopleSaved=0;this.statLastPeopleSaved=0;this.statTotalUPGained=0;this.statCurrentUP=0;this.statLastUPFromPeople=0;this.statLastUPFromChallenges=0;this.statLastChallengeWon=!1;this.statTotalLevel5=0;this.statLastLevel5=0;this.statHighestReefHealthRecord=0;this.statLastReefHealthRecord=0;this.statWifi=0;this.statCosmic=0;this.statLastFrosthours=0;this.statTotalFrosthours=0;this.techOptionsShowPurchased=!0;this.techOptionsShowAvailable=!0;this.techOptionsShowUnavailable=!0;this.techOptionsShowPurchasedFromCamels=!0;this.currentChallenge="SRC";this.upgradeShopPageCount=1;this.upgradeShopCurrentPage=1;this.loadErrorMessage="";this.lastAPs=0;this.totalAPs=0;this.discoveredArtifactList=[];this.upgradesList=[];this.challengesList=[];this.statLastWaterCast=this.statHighestWaterCast=0;this.statLast500=this.statTotal500=0;this.uuOptions=0;};
Persistent_Data.prototype.add_upgrade=function(a,d1,d2,eF,dF,cF,m,uF,l,h){
this.upgradesList.push({abbreviation:a,desc1:d1,desc2:"("+d2+")",effectFunc:eF,dispFunc:dF,costFunc:cF,timesPurchased:0,maxLevel:m,unlockFunc:uF,hiddenFunc:h||false_func,lockedStr:l});};
Persistent_Data.prototype.add_challenge=function(a,n,d1,d2,sF,cF,r,uF){
this.challengesList.push({abbreviation:a,name:n,descFunc1:d1,descFunc2:d2,unlockFunc:uF,startRunFunc:sF,conditionFunc:cF,reward:r,timesCompleted:0,hideName:false_func});};
Persistent_Data.prototype.get_total_upgrades_purchased=function(){
var c=0;this.upgradesList.forEach(function(u){c+=u.timesPurchased;});return c;};
Persistent_Data.prototype.get_total_challenges_completed=function(){
var c=0;this.challengesList.forEach(function(C){c+=C.timesCompleted;});return c;};
Persistent_Data.prototype.get_has_completed_1_challenge=function(){
for(var i=0;i<this.challengesList.length;i+=1){if(this.challengesList[i].timesCompleted>0){return!0;}}return!1;};
Persistent_Data.prototype.get_current_challenge_unlocked=function(){
if(this.currentChallenge.substring(2,3)!=="C"){throw"Unknown Challenge";}var f=!1,i=0;for(;i<this.challengesList.length;i+=1){if(this.challengesList[i].abbreviation===this.currentChallenge.substring(0,2)){f=!0;return this.challengesList[i].unlockFunc();}}if(!f){throw"Unknown Challenge abbreviation";}return!1;};
Persistent_Data.prototype.get_cn_number=function(){
if(this.get_has_completed_1_challenge()){var c=0;this.challengesList.forEach(function(C){c+=C.timesCompleted===0&&C.unlockFunc();});return c;}return 1;};
Persistent_Data.prototype.unlock_wifi=function(){
this.statWifi+=1;if(this.statWifi>9){this.statWifi=4;}};
Persistent_Data.prototype.get_has_wifi=function(){return this.statWifi>0;};
Persistent_Data.prototype.on_greet_cosmic=function(){this.statCosmic+=1;};
Persistent_Data.prototype.on_run_end=function(){
this.statLast500=(tilesClaimed>499?1:0);this.statTotal500+=this.statLast500;
this.statLastWaterCast=allSpells.by_name("Water Music").castStat;this.statHighestWaterCast=max(this.statHighestWaterCast,this.statLastWaterCast);
this.saveNeeded=!0;g_TutorialProgress.disable_tutorial();while(allEnchTableAnimations.length>0){allEnchTableAnimations.pop();}while(allGoldClaimAnimations.length>0){allGoldClaimAnimations.pop();}while(allRWCLimiterAnimations.length>0){allRWCLimiterAnimations.pop();}if(this.currentChallenge.substring(2,3)!=="C"){throw"Unknown abbreviation";}var challengeFound=!1;for(var i=0;i<this.challengesList.length;i+=1){if(this.challengesList[i].abbreviation===this.currentChallenge.substring(0,2)){challengeFound=!0;if(this.challengesList[i].conditionFunc(this.challengesList[i].timesCompleted)){this.statLastChallengeWon=!0;this.statLastUPFromChallenges=this.challengesList[i].reward;this.challengesList[i].timesCompleted+=1;}else{this.statLastChallengeWon=!1;this.statLastUPFromChallenges=0;}}}if(!challengeFound){throw"Unknown Challenge abbreviation";}this.statLastPeopleSaved=evacuees;this.statLastUPFromPeople=floor(0.1*this.statLastPeopleSaved);this.statTotalPeopleSaved+=this.statLastPeopleSaved;this.statCurrentUP+=this.statLastUPFromPeople+this.statLastUPFromChallenges;this.statTotalUPGained+=this.statLastUPFromPeople+this.statLastUPFromChallenges;this.statLastLevel5=allBuildings.count_level_5();this.statTotalLevel5+=this.statLastLevel5;this.statLastReefHealthRecord=constrain(g_ReefData.healthRecord,0,500);this.statHighestReefHealthRecord=max(this.statHighestReefHealthRecord,this.statLastReefHealthRecord);this.lastAPs=0;for(var i=0;i<g_ArtifactManager.get_length();i+=1){this.lastAPs+=g_ArtifactManager.artifactList[i].level>0;g_ArtifactManager.artifactList[i].level=0;}this.totalAPs+=this.lastAPs;};
Persistent_Data.prototype.on_enter_frosthour=function(){
this.statLastFrosthours+=1;this.statTotalFrosthours+=1;};
Persistent_Data.prototype.draw_4_page_buttons=function(){
var c=this.get_is_certificate_unlocked();stroke(0);if(mouseX>=4&&mouseX<width/4-4&&mouseY>=4&&mouseY<36){fill(192,208,208);}else{fill(128,160,160);}rect(4,4,width/4-8,32);if(currentScreen==="challenges"){rect(6,6,width/4-12,28);}if(mouseX>=width/4+4&&mouseX<width/2-4&&mouseY>=4&&mouseY<36){fill(224,128,255);}else{fill(192,128,255);}rect(width/4+4,4,width/4-8,32);if(currentScreen==="ultimate-shop"){rect(width/4+6,6,width/4-12,28);}if(mouseX>=width/2+4&&mouseX<3*width/4-4&&mouseY>=4&&mouseY<36){if(c){fill(255,255,192);}else{fill(128,255,255);}}else{if(c){fill(255,255,128);}else{fill(0,255,255);}}rect(width/2+4,4,width/4-8,32);noFill();if(c){arc(width/2+6.5,6.5,9,9,0,90);arc(3*width/4-5.5,6.5,9,9,90,180);arc(3*width/4-5.5,34.5,9,9,180,270);arc(width/2+6.5,34.5,9,9,270,360);line(width/2+11,8,3*width/4-11,8);line(width/2+11,32,3*width/4-11,32);line(width/2+8,11,width/2+8,29);line(3*width/4-8,11,3*width/4-8,29);}if(currentScreen==="persistent-statistics"||currentScreen==="artifact-persistent-statistics"){rect(width/2+6,6,width/4-12,28);}if(mouseX>=3*width/4+4&&mouseX<width-4&&mouseY>=4&&mouseY<36){fill(255,160,160);}else{fill(255,64,64);}rect(3*width/4+4,4,width/4-8,32);if(currentScreen==="savegame"){rect(3*width/4+6,6,width/4-12,28);}fill(0,0,0);textAlign(CENTER,CENTER);textSize(16);text("Challenges",width/8,20);text("Upgrades",3*width/8,20);text("Statistics",5*width/8,20);text("Savegame",7*width/8,20);var m=this.get_cn_number(),n=this.get_count_affordable_upgrades();if(m>0&&!this.saveNeeded){noStroke();fill(224,64,64);ellipse(8,8,16,16);fill(255,255,255);textSize(12);text(m,8,8);}if(n>0){noStroke();fill(224,64,64);ellipse(width/4+8,8,16,16);fill(255,255,255);textSize(12);text(n,width/4+8,8);}if(this.saveNeeded&&(n<1||this.get_total_challenges_completed()>1)){noStroke();fill(224,64,64);ellipse(3*width/4+8,8,16,16);fill(255,255,255);textSize(12);text("!!",3*width/4+8,8);}textAlign(LEFT,BASELINE);fill(0,0,0);};
Persistent_Data.prototype.on_4_page_buttons_pressed=function(){
if(mouseY<4||mouseY>=36){return!1;}if(mouseX>=4&&mouseX<width/4-4){currentScreen="challenges";this.loadErrorMessage="";return!0;}if(mouseX>=width/4+4&&mouseX<width/2-4){currentScreen="ultimate-shop";this.update_us_page_count();this.loadErrorMessage="";return!0;}if(mouseX>=width/2+4&&mouseX<3*width/4-4){currentScreen="persistent-statistics";this.loadErrorMessage="";return!0;}if(mouseX>=3*width/4+4&&mouseX<width-4){currentScreen="savegame";this.loadErrorMessage="";return!0;}return!1;};
Persistent_Data.prototype.on_4_page_key_pressed=function(){
switch(key.code){case 49:currentScreen="challenges";this.loadErrorMessage="";return!0;case 50:currentScreen="ultimate-shop";this.update_us_page_count();this.loadErrorMessage="";return!0;case 51:currentScreen="persistent-statistics";this.loadErrorMessage="";return!0;case 52:currentScreen="savegame";this.loadErrorMessage="";return!0;}return!1;
};
Persistent_Data.prototype.render_end_of_run_screen=function(){
var s=24,t="Evacuees saved: "+g_ResourcePane.evacuee_to_string(this.statLastPeopleSaved)+" ("+g_ResourcePane.evacuee_to_string(this.statLastUPFromPeople)+" Points)";background(255,255,0);fill(0);textSize(24);textAlign(CENTER,CENTER);if(this.statLastChallengeWon){text(">>> "+this.currentChallenge+" Completed! <<<",width/2,75);}text("End of run!",200,125);for(;textWidth(t)>398;s-=1){textSize(s);}text(t,200,175);textSize(24);text("Challenge bonus: "+this.statLastUPFromChallenges+" Points",200,225);text("Your score: "+g_ResourcePane.evacuee_to_string(this.statLastUPFromPeople+this.statLastUPFromChallenges)+" Points",200,275);if(this.lastAPs>0){textSize(18);text("Artifact Points gained: "+this.lastAPs,200,315);}if(mouseX>=140&&mouseY>=335&&mouseX<260&&mouseY<375){fill(128,255,128);}else{fill(0,255,0);}stroke(0,0,0);rect(140,335,120,40);fill(0,0,0);textSize(24);text("Continue",200,355);textSize(12);stroke(0,0,0);if(this.statLastChallengeWon&&mouseY>=63&&mouseY<89){fill(255,255,255);rect(min(mouseX,202),90,198,32);fill(0,0,0);text("Completing Challenges grants some\npermanent boosts to your power.",min(mouseX,202)+99,106);}if(mouseY>=163&&mouseY<189){fill(255,255,255);rect(min(mouseX,248),190,152,32);fill(0,0,0);text("You get 1 Ultimate Point for\neach 10 people you saved.",min(mouseX,248)+76,206);}if(mouseY>=213&&mouseY<239){fill(255,255,255);rect(min(mouseX,210),240,190,32);fill(0,0,0);text(this.statLastChallengeWon?"Each Challenge awards you some\nUltimate Points upon completion.":"You didn't complete the Challenge,\nso you don't get a bonus this time.",min(mouseX,210)+95,256);}if(mouseY>=263&&mouseY<289){fill(255,255,255);rect(min(mouseX,236),290,164,32);fill(0,0,0);text("Ultimate Points can be spent\non permanent upgrades.",min(mouseX,236)+82,306);}if(this.lastAPs>0&&mouseY>=306&&mouseY<324){fill(255,255,255);rect(min(mouseX,206),325,194,32);fill(0,0,0);text("Artifact Points can be used in future\nruns to upgrade your Artifacts.",min(mouseX,206)+97,341);}textAlign(LEFT,BASELINE);};
Persistent_Data.prototype.render_challenges_screen=function(){
background(128,160,160);this.draw_4_page_buttons();fill(64,80,80);noStroke();rect(4,40,64,min(height-44,this.challengesList.length*28+4));var h2=mouseX>=112&&mouseX<width-40&&mouseY>=height-48&&mouseY<height-16,h=!1,i=0,u=!0,t=0,tot=this.get_total_challenges_completed();for(i=0;i<this.challengesList.length;i+=1){var cha=this.challengesList[i];t=cha.timesCompleted;u=cha.unlockFunc();h=cha.abbreviation===this.currentChallenge.substring(0,2);textAlign(CENTER,CENTER);textSize(16);noStroke();if(mouseX>=8&&mouseX<64&&mouseY>=44+28*i&&mouseY<68+28*i){if(u){fill(192,208,208);}else{fill(203,203,203);}}else{if(u){fill(128,160,160);}else{fill(149,149,149);}}rect(8,44+28*i,56,24);if(h){stroke(0,0,0);noFill();rect(10,46+28*i,52,20);}fill(0,0,0);text(cha.hideName()?"???":cha.abbreviation+"C",36,56+28*i);if(u&&t===0&&(cha.abbreviation==="SR"||tot)&&!this.saveNeeded){noStroke();fill(224,64,64);ellipse(12,46+28*i,8,8);fill(255,255,255);textSize(8);text("!",12,46+28*i);fill(0,0,0);}if(h){textSize(16);text(cha.hideName()?"???":cha.name,(72+width)/2,56);textAlign(LEFT,BASELINE);textSize(12);text(cha.descFunc1(t),72,72,width-76,height);text(cha.descFunc2(t),72,232,width-76,height);if(u){textAlign(CENTER,CENTER);stroke(0,0,0);if(h2){fill(128,255,128);}else{fill(0,255,0);}if(g_TutorialProgress.get_challenges_disabled()){if(h2){fill(255);rect(min(mouseX,158),334,242,16);fill(0);text("Progress a bit more through the tutorial first.",min(mouseX,158)+121,342);}fill(85);}rect(112,height-48,width-152,32);fill(0);textSize(24);text("START CHALLENGE",(72+width)/2,height-32);textAlign(LEFT,BASELINE);}}}};
Persistent_Data.prototype.choose_challenge=function(){
if(mouseX<8||mouseX>=64){return;}for(var i=0;i<this.challengesList.length;i+=1){if(mouseY>=44+28*i&&mouseY<68+28*i){this.currentChallenge=this.challengesList[i].abbreviation+"C";return;}}};
Persistent_Data.prototype.choose_previous_challenge=function(){
var i=0,j=0;for(;j<this.challengesList.length;j+=1){if(this.challengesList[j].abbreviation+"C"===this.currentChallenge){i=j;break;}}i-=1;if(i<0){i=this.challengesList.length-1;}this.currentChallenge=this.challengesList[i].abbreviation+"C";};
Persistent_Data.prototype.choose_next_challenge=function(){
var i=0,j=0;for(;j<this.challengesList.length;j+=1){if(this.challengesList[j].abbreviation+"C"===this.currentChallenge){i=j;break;}}i+=1;if(i>=this.challengesList.length){i=0;}this.currentChallenge=this.challengesList[i].abbreviation+"C";};
Persistent_Data.prototype.update_us_page_count=function(){
var c=0,showLocked=this.uuOptions&1,showMaxed=this.uuOptions&2,hid,un,x,maxX,i=0;for(;i<this.upgradesList.length;i+=1){hid=this.upgradesList[i].hiddenFunc();un=!hid&&this.upgradesList[i].unlockFunc();x=this.upgradesList[i].timesPurchased;maxX=this.upgradesList[i].maxLevel;if(!un&&!showLocked){continue;}if(x===maxX&&!showMaxed){continue;}c+=1;}this.upgradeShopPageCount=max(1,ceil(c/6));this.upgradeShopCurrentPage=min(this.upgradeShopPageCount,this.upgradeShopCurrentPage);};
Persistent_Data.prototype.render_ultimate_shop_screen=function(){
var showLocked=this.uuOptions&1,showMaxed=this.uuOptions&2,yDraw=80,hov,un,x,maxX,nR=0,nS=0,i=0,hid;background(255);this.draw_4_page_buttons();textAlign(CENTER,CENTER);textSize(18);text("~ULTIMATE SHOP~",width/2,56);textAlign(LEFT,BASELINE);textSize(12);for(;i<this.upgradesList.length&&nR<6;i+=1){hov=mouseX>=width-100&&mouseX<width-4&&mouseY>=yDraw-8&&mouseY<yDraw+16;hid=this.upgradesList[i].hiddenFunc();un=!hid&&this.upgradesList[i].unlockFunc();x=this.upgradesList[i].timesPurchased;maxX=this.upgradesList[i].maxLevel;if(!un&&!showLocked){continue;}if(x===maxX&&!showMaxed){continue;}if(nS<6*this.upgradeShopCurrentPage-6){nS+=1;continue;}text(hid?"???":this.upgradesList[i].desc1,16,yDraw);if(hid){text("(???)",32,yDraw+16);text("???",250,yDraw+8);}else if(hov&&un){if(maxX>0){text("(Current level: "+x+" of "+maxX+")",32,yDraw+16);}else{text("(Current level: "+x+")",32,yDraw+16);}if(x<maxX||maxX<0){text(this.upgradesList[i].dispFunc(x),250,yDraw);text(this.upgradesList[i].dispFunc(x+1),250,yDraw+16);}else{text(this.upgradesList[i].dispFunc(x),250,yDraw+8);}}else{text(this.upgradesList[i].desc2,32,yDraw+16);text(this.upgradesList[i].dispFunc(x),250,yDraw+8);}stroke(0);if(x>=maxX&&maxX>0){noFill();}else if(!un){fill(128);}else if(this.statCurrentUP>=this.upgradesList[i].costFunc(x)){if(hov){fill(128,224,128);}else{fill(0,192,0);}}else{fill(255,0,0);}rect(width-100,yDraw-8,96,24);fill(0);if(hid){text("???",width-96,yDraw+8);}else if(!un){text(this.upgradesList[i].lockedStr,width-96,yDraw+8);}else if(x<maxX||maxX<0){text("Cost: "+g_ResourcePane.evacuee_to_string(this.upgradesList[i].costFunc(x)),width-96,yDraw+8);}else{text("Maxed out!",width-96,yDraw+8);}yDraw+=48;nR+=1;}
stroke(0);fill(192,128,255);rect(-2,height-30,width+4,32);fill(0);textSize(16);text("Page "+this.upgradeShopCurrentPage+" of "+this.upgradeShopPageCount,50,height-36);textSize(12);text("Ultimate Points: "+this.statCurrentUP,50,height-8);if(this.upgradeShopCurrentPage>1){if(mouseX<16&&mouseY>=height-48&&mouseY<height-32){fill(255,255,0);}else{fill(192,192,0);}triangle(0,height-40,16,height-48,16,height-32);}if(this.upgradeShopCurrentPage<this.upgradeShopPageCount){if(mouseX>=width-16&&mouseY>=height-48&&mouseY<height-32){fill(255,255,0);}else{fill(192,192,0);}triangle(width,height-40,width-16,height-48,width-16,height-32);}textAlign(CENTER,CENTER);stroke(0);fill(255);rect(276,377,16,16);if(showMaxed){noFill();ellipse(284.5,385,6,6);ellipse(284.5,385,16,8);}if(mouseX>=276&&mouseX<292&&mouseY>=377&&mouseY<393){noFill();rect(274,375,20,20);fill(0,255,255);rect(214,344,140,24);fill(0);text((showMaxed?"Hide":"Show")+" maxed Upgrades",284,356);}fill(128);rect(308,377,16,16);if(showLocked){noFill();ellipse(316.5,385,6,6);ellipse(316.5,385,16,8);}if(mouseX>=308&&mouseX<324&&mouseY>=377&&mouseY<393){noFill();rect(306,375,20,20);fill(0,255,255);rect(246,344,140,24);fill(0);text((showLocked?"Hide":"Show")+" locked Upgrades",316,356);}textAlign(LEFT,BASELINE);if(mouseY>=height-30&&mouseX<200){fill(0,255,255);rect(floor(25+mouseX/4),296,191,72);fill(0);text("Ultimate Points are spent to",floor(29+mouseX/4),312);text("purchase Ultimate Upgrades.",floor(29+mouseX/4),328);text("Ultimate Points have no other use,",floor(29+mouseX/4),344);text("so don't hesitate to spend them!",floor(29+mouseX/4),360);}};
Persistent_Data.prototype.purchase_ultimate_upgrade=function(){
if(mouseX>=276&&mouseX<292&&mouseY>=377&&mouseY<393){if(this.uuOptions&2){this.uuOptions-=2;}else{this.uuOptions+=2;}this.update_us_page_count();return;}if(mouseX>=308&&mouseX<324&&mouseY>=377&&mouseY<393){if(this.uuOptions&1){this.uuOptions-=1;}else{this.uuOptions+=1;}this.update_us_page_count();return;}if(mouseX<16&&mouseY>=height-48&&mouseY<height-32){this.upgradeShopCurrentPage=max(this.upgradeShopCurrentPage-1,1);return;}if(mouseX>=width-16&&mouseY>=height-48&&mouseY<height-32){this.upgradeShopCurrentPage=min(this.upgradeShopCurrentPage+1,this.upgradeShopPageCount);return;}var yDraw=80,nR=0,nS=0,i=0,showLocked=this.uuOptions&1,showMaxed=this.uuOptions&2,hid,un,x,maxX;for(;i<this.upgradesList.length&&nR<6;i+=1){hid=this.upgradesList[i].hiddenFunc();un=!hid&&this.upgradesList[i].unlockFunc();x=this.upgradesList[i].timesPurchased;maxX=this.upgradesList[i].maxLevel;if(!un&&!showLocked){continue;}if(x===maxX&&!showMaxed){continue;}if(nS<6*this.upgradeShopCurrentPage-6){nS+=1;continue;}if(mouseX>=width-100&&mouseX<width-4&&mouseY>=yDraw-8&&mouseY<yDraw+16){if(x>=maxX&&maxX>0){g_FlyingText.set_text("Maxed out!",width-96,yDraw+8);g_FlyingText.fontColor=color(0);return!1;}if(!un){g_FlyingText.set_text("Locked.",width-96,yDraw+8);g_FlyingText.fontColor=color(0);return!1;}if(this.statCurrentUP>=this.upgradesList[i].costFunc(x)){this.statCurrentUP-=this.upgradesList[i].costFunc(x);this.upgradesList[i].timesPurchased+=1;g_FlyingText.set_text("Purchased!",width-96,yDraw+8);g_FlyingText.fontColor=color(0);this.update_us_page_count();this.saveNeeded=!0;return!0;}g_FlyingText.set_text("Can't afford!",width-96,yDraw+8);g_FlyingText.fontColor=color(0);return!1;}yDraw+=48;nR+=1;}return!1;};
Persistent_Data.prototype.ultimate_shop_on_key_pressed=function(){
if(keyCode===LEFT){this.upgradeShopCurrentPage=max(this.upgradeShopCurrentPage-1,1);return;}if(keyCode===RIGHT){this.upgradeShopCurrentPage=min(this.upgradeShopCurrentPage+1,this.upgradeShopPageCount);return;}};
Persistent_Data.prototype.render_persistent_statistics_screen = function()
{
background(0,255,255);this.draw_4_page_buttons();stroke(0);if(currentScreen==="artifact-persistent-statistics"){fill(255,0,255);rect(4,40,width-8,height-44);textSize(18);fill(0);textAlign(CENTER,CENTER);text("Artifacts discovered:",width/2,64);textSize(16);text("Progress: "+this.discoveredArtifactList.length+"/"+g_ArtifactManager.get_length(),width/2,300);textAlign(LEFT,BASELINE);g_ArtifactManager.draw_artifacts_unlock();return;}line(width/2-2,40,width/2-2,height-4);line(width/2+1,40,width/2+1,height-4);textSize(18);textAlign(CENTER,CENTER);text("LAST RUN",width/4,52);text("ALL-TIME",3*width/4,52);textAlign(LEFT,BASELINE);textSize(12);
text("People saved: "+this.statLastPeopleSaved,4,80);text("People saved: "+this.statTotalPeopleSaved,width/2+4,80);text("Ultimate Points (people): "+this.statLastUPFromPeople,4,112);text("Ultimate Points (Challenges): "+this.statLastUPFromChallenges,4,128);text("Ultimate Points (total): "+this.statTotalUPGained,width/2+4,112);text("Ultimate Points (current): "+this.statCurrentUP,width/2+4,128);text("Challenge completed? "+(this.statLastChallengeWon?"YES":"NO"),4,160);text("Challenges completed: "+this.get_total_challenges_completed(),width/2+4,160);text("Ultimate Upgrades: "+this.get_total_upgrades_purchased(),width/2+4,176);if(this.statTotalLevel5){text("Lvl. 5 buildings: "+this.statLastLevel5,4,208);text("Lvl. 5 buildings: "+this.statTotalLevel5,width/2+4,208);}if(this.statLastFrosthours||this.statTotalFrosthours){text("Frosthours: "+this.statLastFrosthours,4,240);text("Frosthours: "+this.statTotalFrosthours,width/2+4,240);}if(this.lastAPs>0||this.totalAPs>0){text("Artifact Points: "+this.lastAPs,4,272);text("Artifact Points: "+this.totalAPs,width/2+4,272);text("Progress: "+this.discoveredArtifactList.length+"/"+g_ArtifactManager.get_length(),width/2+90,300);}if(this.get_is_certificate_unlocked()){fill(0,255,255);rect(64,323,272,54);if(mouseX>=66&&mouseY>=325&&mouseX<334&&mouseY<375){fill(128,255,128);}else{fill(0,255,0);}rect(66,325,268,50);fill(0);textAlign(CENTER,CENTER);textSize(24);text("Certificate of Completion",width/2,350);textAlign(LEFT,BASELINE);}
};
Persistent_Data.prototype.render_savegame_screen=function(){
background(255,64,64);this.draw_4_page_buttons();textSize(16);if(this.loadErrorMessage.length>0){text(this.loadErrorMessage,20,50,width-40,height);}text("To save your game, click the button below to get your save string. Copy it & paste it into a document elsewhere. When you want to load the game again (from the main menu), click the Load Game button & follow the instructions.",20,100,width-40,height);};
Persistent_Data.prototype.get_upgrade_effect=function(a){
for(var i=0;i<this.upgradesList.length;i+=1){if(this.upgradesList[i].abbreviation===a){return this.upgradesList[i].effectFunc(this.upgradesList[i].timesPurchased);}}return undefined;};
Persistent_Data.prototype.get_upgrade_times_purchased=function(a){
for(var i=0;i<this.upgradesList.length;i+=1){if(this.upgradesList[i].abbreviation===a){return this.upgradesList[i].timesPurchased;}}return undefined;};
Persistent_Data.prototype.get_is_reef_unlocked=function(){
return this.get_upgrade_times_purchased("RF")>0;};
Persistent_Data.prototype.get_count_affordable_upgrades=function(){
var c=0,s=this.statCurrentUP;this.upgradesList.forEach(function(u){c+=(u.maxLevel<0||u.timesPurchased<u.maxLevel)&&!u.hiddenFunc()&&u.unlockFunc()&&s>=u.costFunc(u.timesPurchased);});return c;};
Persistent_Data.prototype.on_artifact_found=function(a){
var l=!1,i=0;for(;i<this.discoveredArtifactList.length;i+=1){if(this.discoveredArtifactList[i]===a){l=!0;break;}}if(!l){this.discoveredArtifactList.push(a);}};
Persistent_Data.prototype.get_was_artifact_found=function(a){
for(var i=0;i<this.discoveredArtifactList.length;i+=1){if(this.discoveredArtifactList[i]===a){return!0;}}return!1;};
Persistent_Data.prototype.get_is_certificate_unlocked=function(){
var i=0;for(;i<this.challengesList.length;i+=1){if(this.challengesList[i].timesCompleted<3){return!1;}}for(i=0;i<this.upgradesList.length;i+=1){if(this.upgradesList[i].maxLevel>0){if(this.upgradesList[i].timesPurchased<this.upgradesList[i].maxLevel){return!1;}}else{if(this.upgradesList[i].timesPurchased<3){return!1;}}}if(this.statWifi<3){return!1;}if(this.statCosmic<3){return!1;}if(this.statTotal500<3){return!1;}return!0;};
Persistent_Data.prototype.erase_all_data = function()
{
this.saveNeeded=!1;
this.challengesList.forEach(function(C){C.timesCompleted=0;});
this.upgradesList.forEach(function(U){U.timesPurchased=0;});
this.currentChallenge="SRC";
this.statTotalPeopleSaved=0;
this.statLastPeopleSaved=0;
this.statTotalUPGained=0;
this.statCurrentUP=0;
this.statLastUPFromPeople=0;
this.statLastUPFromChallenges=0;
this.statLastChallengeWon=false;
this.statTotalLevel5=0;
this.statLastLevel5=0;
this.statLastReefHealthRecord=0;
this.statHighestReefHealthRecord=0;
this.statWifi=0;
this.statCosmic=0;
this.statLastFrosthours=0;
this.statTotalFrosthours=0;
this.techOptionsShowPurchased=!0;
this.techOptionsShowAvailable=!0;
this.techOptionsShowUnavailable=!0;
this.techOptionsShowPurchasedFromCamels=!0;
this.lastAPs=0;
this.totalAPs=0;
this.discoveredArtifactList=[];this.statLastWaterCast=this.statHighestWaterCast=0;this.statLast500=this.statTotal500=0;this.uuOptions=0;
};
Persistent_Data.prototype.get_challenge_times_completed=function(a){
for(var i=0;i<this.challengesList.length;i+=1){if(this.challengesList[i].abbreviation===a){return this.challengesList[i].timesCompleted;}}return 0;};
Persistent_Data.prototype.make_save_string=function(){
var cS="",uS="",sS="",aS="",ck=0,i=0,tos=8*this.techOptionsShowPurchased+4*this.techOptionsShowAvailable+2*this.techOptionsShowUnavailable+this.techOptionsShowPurchasedFromCamels;for(;i<this.challengesList.length;i+=1){var v=this.challengesList[i].timesCompleted;if(v>0){cS+=this.challengesList[i].abbreviation+"C:"+v+";";ck+=sq(v);}}ck%=59;cS+="CCK:"+ck+";";ck=0;for(i=0;i<this.upgradesList.length;i+=1){var v=this.upgradesList[i].timesPurchased;if(v>0){uS+=this.upgradesList[i].abbreviation+"U:"+v+";";ck+=sq(v);}}ck%=59;uS+="UCK:"+ck+";";ck=0;sS+="TPS:"+this.statTotalPeopleSaved+";";ck+=sq(this.statTotalPeopleSaved);sS+="LPS:"+this.statLastPeopleSaved+";";ck+=sq(this.statLastPeopleSaved);sS+="TUS:"+this.statTotalUPGained+";";ck+=sq(this.statTotalUPGained);sS+="CUS:"+this.statCurrentUP+";";ck+=sq(this.statCurrentUP);sS+="UPS:"+this.statLastUPFromPeople+";";ck+=sq(this.statLastUPFromPeople);sS+="UCS:"+this.statLastUPFromChallenges+";";ck+=sq(this.statLastUPFromChallenges);if(this.statLastChallengeWon){sS+="LCS:1;";ck+=1;}else{sS+="LCS:0;";}sS+="T5S:"+this.statTotalLevel5+";";ck+=sq(this.statTotalLevel5);sS+="L5S:"+this.statLastLevel5+";";ck+=sq(this.statLastLevel5);sS+="RHS:"+this.statLastReefHealthRecord+";";ck+=sq(this.statLastReefHealthRecord);sS+="RRS:"+this.statHighestReefHealthRecord+";";ck+=sq(this.statHighestReefHealthRecord);sS+="UUS:"+this.uuOptions+";";ck+=sq(this.uuOptions);if(this.statWifi>0){sS+="WFS:"+this.statWifi+";";ck+=sq(this.statWifi);}if(this.statCosmic>0){sS+="CGS:"+this.statCosmic+";";ck+=sq(this.statCosmic);}if(this.statLastWaterCast){sS+="LWS:"+this.statLastWaterCast+";";ck+=sq(this.statLastWaterCast);}if(this.statHighestWaterCast){sS+="HWS:"+this.statHighestWaterCast+";";ck+=sq(this.statHighestWaterCast);}if(this.statLastFrosthours){sS+="LFS:"+this.statLastFrosthours+";";ck+=sq(this.statLastFrosthours);}if(this.statTotalFrosthours){sS+="TFS:"+this.statTotalFrosthours+";";ck+=sq(this.statTotalFrosthours);}if(this.statTotal500){sS+="5HS:"+this.statTotal500+";";ck+=sq(this.statTotal500);}if(this.statLast500){sS+="5LS:"+this.statLast500+";";ck+=sq(this.statLast500);}sS+="CCS:"+this.currentChallenge+";";sS+="TOS:"+tos+";";ck+=sq(tos);ck%=59;sS+="SCK:"+ck+";";ck=0;if(this.lastAPs+this.totalAPs+this.discoveredArtifactList.length>0){aS+="LPA:"+this.lastAPs+";";ck+=sq(this.lastAPs);aS+="TPA:"+this.totalAPs+";";ck+=sq(this.totalAPs);aS+="ADA:"+this.discoveredArtifactList.join(",")+";";ck+=sq(this.discoveredArtifactList.length);ck%=59;aS+="ACK:"+ck+";";}this.saveNeeded=!1;return"\""+cS+uS+aS+sS+"\"";};
Persistent_Data.prototype.load_from_save_string=function(){
var tempC=[],tempU=[],tempS=[],tempA=[],tempADL=[],tempKV=[],ccs="",ccck=0,cuck=0,csck=0,cack=0,tcck=-1,tuck=-1,tsck=-1,tack=-1,b=!1,tos=0,sections=g_LoadString.replace(/"/g,"").split(";"),i=0,j=0,a="";while(i<sections.length){if(sections[i].length===0||sections[i]==="ADA:"){sections.splice(i,1);}else{if(sections[i].length<=4||sections[i][3]!==":"){this.loadErrorMessage="Invalid format: \""+sections[i]+"\"";return!1;}i+=1;}}for(i=0;i<sections.length;i+=1){switch(sections[i][2]){case"C":tempKV=sections[i].split(":");if(tempKV.length!==2){this.loadErrorMessage="Invalid format: \""+sections[i]+"\"";return!1;}tempKV[1]=parseInt(tempKV[1],10)||0;tempC.push(tempKV);ccck+=sq(tempKV[1]);break;case"U":tempKV=sections[i].split(":");if(tempKV.length!==2){this.loadErrorMessage="Invalid format: \""+sections[i]+"\"";return!1;}tempKV[1]=parseInt(tempKV[1],10)||0;tempU.push(tempKV);cuck+=sq(tempKV[1]);break;case"S":tempKV=sections[i].split(":");if(tempKV.length!==2){this.loadErrorMessage="Invalid format: \""+sections[i]+"\"";return!1;}if(tempKV[0]==="CCS"){ccs=tempKV[1];break;}tempKV[1]=parseInt(tempKV[1],10)||0;if(tempKV[0]==="RHS"||tempKV[0]==="RRS"){if(tempKV[1]>500){this.loadErrorMessage="Invalid reef health parameter.";return!1;}}tempS.push(tempKV);csck+=sq(tempKV[1]);break;case"A":b=!0;tempKV=sections[i].split(":");if(tempKV.length!==2){this.loadErrorMessage="Invalid format: \""+sections[i]+"\"";return!1;}if(tempKV[0]==="ADA"){tempADL=tempKV[1].split(",");cack+=sq(tempADL.length);}tempKV[1]=parseInt(tempKV[1],10)||0;tempA.push(tempKV);cack+=sq(tempKV[1]);break;case"K":tempKV=sections[i].split(":");if(tempKV.length!==2){this.loadErrorMessage="Invalid format: \""+sections[i]+"\"";return!1;}tempKV[1]=parseInt(tempKV[1],10)||0;switch(tempKV[0]){case"CCK":tcck=tempKV[1];break;case"UCK":tuck=tempKV[1];break;case"SCK":tsck=tempKV[1];break;case"ACK":tack=tempKV[1];break;}break;}}ccck%=59;cuck%=59;csck%=59;cack%=59;if(tcck<0||tuck<0||tsck<0||(tack<0&&b)){this.loadErrorMessage="One or more checksums are missing!";return!1;}if(ccck!==tcck||cuck!==tuck||csck!==tsck||(cack!==tack&&b)){this.loadErrorMessage="One or more checksums mismatch the calculated value!";return!1;}
for(i=0;i<this.challengesList.length;i+=1){this.challengesList[i].timesCompleted=0;for(j=0;j<tempC.length;j+=1){if(this.challengesList[i].abbreviation+"C"===tempC[j][0]){this.challengesList[i].timesCompleted=tempC[j][1];}}}for(i=0;i<this.upgradesList.length;i+=1){this.upgradesList[i].timesPurchased=0;for(j=0;j<tempU.length;j+=1){if(this.upgradesList[i].abbreviation+"U"===tempU[j][0]){this.upgradesList[i].timesPurchased=tempU[j][1];}}if(this.upgradesList[i].maxLevel>0&&this.upgradesList[i].timesPurchased>this.upgradesList[i].maxLevel){this.upgradesList[i].timesPurchased=this.upgradesList[i].maxLevel;}}this.lastAPs=0;for(i=0;i<tempA.length;i+=1){if(tempA[i][0]==="LPA"){this.lastAPs=tempA[i][1];}}this.totalAPs=0;for(i=0;i<tempA.length;i+=1){if(tempA[i][0]==="TPA"){this.totalAPs=tempA[i][1];}}this.discoveredArtifactList=[];for(i=0;i<tempADL.length;i+=1){a=tempADL[i];if(typeof(g_ArtifactManager.by_abbreviation(a))!=="undefined"){this.discoveredArtifactList.push(a);}}this.currentChallenge="";for(i=0;i<this.challengesList.length;i+=1){if(this.challengesList[i].abbreviation+"C"===ccs){this.currentChallenge=ccs;break;}}if(this.currentChallenge===""){this.currentChallenge="SRC";}this.statTotalPeopleSaved=0;for(i=0;i<tempS.length;i+=1){if(tempS[i][0]==="TPS"){this.statTotalPeopleSaved=tempS[i][1];break;}}this.statLastPeopleSaved=0;for(i=0;i<tempS.length;i+=1){if(tempS[i][0]==="LPS"){this.statLastPeopleSaved=tempS[i][1];break;}}this.statTotalUPGained=0;for(i=0;i<tempS.length;i+=1){if(tempS[i][0]==="TUS"){this.statTotalUPGained=tempS[i][1];break;}}this.statCurrentUP=0;for(i=0;i<tempS.length;i+=1){if(tempS[i][0]==="CUS"){this.statCurrentUP=tempS[i][1];break;}}this.statLastUPFromPeople=0;for(i=0;i<tempS.length;i+=1){if(tempS[i][0]==="UPS"){this.statLastUPFromPeople=tempS[i][1];break;}}this.statLastUPFromChallenges=0;for(i=0;i<tempS.length;i+=1){if(tempS[i][0]==="UCS"){this.statLastUPFromChallenges=tempS[i][1];break;}}this.statLastChallengeWon=!1;for(i=0;i<tempS.length;i+=1){if(tempS[i][0]==="LCS"){if(tempS[i][1]===1){this.statLastChallengeWon=!0;}break;}}this.statTotalLevel5=0;for(i=0;i<tempS.length;i+=1){if(tempS[i][0]==="T5S"){this.statTotalLevel5=tempS[i][1];break;}}this.statLastLevel5=0;
for(i=0;i<tempS.length;i+=1){if(tempS[i][0]==="L5S"){this.statLastLevel5=tempS[i][1];break;}}this.statLastReefHealthRecord=0;for(i=0;i<tempS.length;i+=1){if(tempS[i][0]==="RHS"){this.statLastReefHealthRecord=tempS[i][1];break;}}this.statHighestReefHealthRecord=0;for(i=0;i<tempS.length;i+=1){if(tempS[i][0]==="RRS"){this.statHighestReefHealthRecord=tempS[i][1];break;}}this.statWifi=0;for(i=0;i<tempS.length;i+=1){if(tempS[i][0]==="WFS"){this.statWifi=tempS[i][1];break;}}this.statCosmic=0;for(i=0;i<tempS.length;i+=1){if(tempS[i][0]==="CGS"){this.statCosmic=tempS[i][1];break;}}this.statLastWaterCast=0;for(i=0;i<tempS.length;i+=1){if(tempS[i][0]==="LWS"){this.statLastWaterCast=tempS[i][1];break;}}this.statHighestWaterCast=0;for(i=0;i<tempS.length;i+=1){if(tempS[i][0]==="HWS"){this.statHighestWaterCast=tempS[i][1];break;}}this.statLastFrosthours=0;for(i=0;i<tempS.length;i+=1){if(tempS[i][0]==="LFS"){this.statLastFrosthours=tempS[i][1];break;}}this.statTotalFrosthours=0;for(i=0;i<tempS.length;i+=1){if(tempS[i][0]==="TFS"){this.statTotalFrosthours=tempS[i][1];break;}}this.statTotal500=0;for(i=0;i<tempS.length;i+=1){if(tempS[i][0]==="5HS"){this.statTotal500=tempS[i][1];break;}}this.statLast500=0;for(i=0;i<tempS.length;i+=1){if(tempS[i][0]==="5LS"){this.statLast500=tempS[i][1];break;}}this.uuOptions=0;for(i=0;i<tempS.length;i+=1){if(tempS[i][0]==="UUS"){this.uuOptions=tempS[i][1];break;}}tos=15;for(i=0;i<tempS.length;i+=1){if(tempS[i][0]==="TOS"){tos=tempS[i][1];break;}}this.update_us_page_count();this.techOptionsShowPurchased=(tos/8)%2>=1;this.techOptionsShowAvailable=(tos/4)%2>=1;this.techOptionsShowUnavailable=(tos/2)%2>=1;this.techOptionsShowPurchasedFromCamels=tos%2>=1;this.loadErrorMessage="Everything successfully loaded!";this.saveNeeded=!1;return!0;};
Persistent_Data.prototype.start_new_run = function()
{
this.statLastPeopleSaved=0;this.statLastUPFromPeople=0;this.statLastUPFromChallenges=0;this.statLastFrosthours=0;this.lastAPs=0;greetedCosmic=!1;g_TutorialProgress.showGoal=!1;
movesLeft=2;movesPerDay=2;dayCount=1;daysUntilSwarmArrival=79;season=1;dayToUnlockDarkEnergy=400;dayToRunEnd=1000;enchantingScreenSelection=0;
g_TutorialProgress.foodFromFish=0;g_Factors.on_new_run_start();g_ArtifactManager.on_new_run_start();g_ToggleButtonManager.on_new_run_start();g_ReefData.on_new_run_start();goldenClaimTilesLeft=0;foodResource=20+3*this.get_challenge_times_completed("UC");manaResource=0;pearlResource=0;stoneResource=10+4*this.get_challenge_times_completed("UR");spiceResource=0;gadoliniumResource=0;flameOrbResource=0;ironResource=0;goldenAppleResource=0;darkEnergyResource=0;bioOrbResource=0;mithrilResource=0;
foodGivenToBank=0;totalDarkEnergyGained=0;totalBioOrbGainedFromEnchanting=0;upkeepLastSatisfiedRatio=1;enchantingPearlCostMulti=1;
evacuees=0;evacueesEnRoute=0;maxEvacuees=0;canCastSpells=!0;backsideCutsceneShown=!1;deCutscene2Shown=!1;
foodAppleProductionMultiFromFrosthour=1;manaProductionMultiFromFrosthour=1;pearlProductionMultiFromFrosthour=1;stoneProductionMultiFromFrosthour=1;ironMithrilProductionMultiFromFrosthour=1;darkEnergyProductionMultiFromFrosthour=1;enchantingProductMultiFromFrosthour=1;enchantingPriceMulti=1;
worldgenOption=4;PerlinNoiseRandomFactor=random(-500,500);mapEdgeRandomFactor=2*sq(sin(PerlinNoiseRandomFactor))+cos(PerlinNoiseRandomFactor+7)-1;trainPowerLineX=round32(random(500,550)+random(0,50)-64);tilesTerraformed=0;cameraX=0;cameraY=0;selectedTile=-1;currentlyInBackside=!1;manaProductionMultiFromCyber=1;pearlTradeMultiFromCyber=1;spiceTradeMultiFromCyber=1;gadoliniumFromSlimeMultiFromCyber=1;darkEnergyProductionMultiFromCyber=1;enchantingProductMultiFromCyber=1;
g_Diplomacy.on_new_run_start(this.currentChallenge);g_ResourcePane.on_new_run_start();g_TechnologyManager.setup_techs();g_TechnologyManager.check_count_techs();while(allTiles.length>0){allTiles.pop();}while(allSpells.length>0){allSpells.pop();}while(spellHints.length>0){spellHints.pop();}spellHints.currentlyShowing=0;allSpells.setup_spells();allSpells.scrollOffset=0;allSpells.scrollVelocity=0;allSpells.goldenAppleEaten=!1;allSpells.subscreen=0;while(allIRSDatas.length>0){allIRSDatas.pop();}while(allBuildings.length>0){allBuildings.pop();}while(allCreatures.length>0){allCreatures.pop();}
allCreatures.fedSeaTurtle=0;allCreatures.fedAirTurtle=0;g_Dragon.on_new_run_start();allCreatures.update_train();if(this.currentChallenge.substring(2,3)!=="C"){throw"Unknown abbreviation";}var challengeFound=!1;for(var i=0;i<this.challengesList.length;i+=1){if(this.challengesList[i].abbreviation===this.currentChallenge.substring(0,2)){challengeFound=!0;this.challengesList[i].startRunFunc(this.challengesList[i].timesCompleted);}}if(!challengeFound){throw"Unknown Challenge abbreviation";}allSpells.by_name("Empower the Dragon").extendedDescription+=dayToRunEnd+".";
};
var g_PersistentData = new Persistent_Data();
{
//abbrev,desc1,desc2,effectFunc,dispFunc,costFunc,maxLevel,unlockFunc,lockedStr,hiddenFunc(optional)
g_PersistentData.add_upgrade("F1","Decrease Farm Lvl. 1 Food Cost","Also lowers cost to repair.",function(x){return-0.5*x;},function(x){var n=this.effectFunc(x);return Number.isInteger(n)?n:n.toFixed(1);},function(x){return floor(0.2*x)+1;},7,true_func,"");
g_PersistentData.add_upgrade("F2","Decrease Farm Lvl. 2 Pearl Cost","That's all this one does.",function(x){return-1.5*x;},function(x){var n=this.effectFunc(x);return Number.isInteger(n)?n:n.toFixed(1);},function(x){return(x===3)?5:3;},4,function(){return g_PersistentData.get_total_challenges_completed()>=2;},"2 Challenges");
g_PersistentData.add_upgrade("C3","Collector Lvl. 3 Tech","Spice cost of the tech.",function(x){return x<1?800:(x<2?80:8);},function(x){return this.effectFunc(x);},function(x){return x<1?2:3;},2,function(){return g_PersistentData.get_total_challenges_completed()>4;},"???",function(){return!this.unlockFunc();});
g_PersistentData.add_upgrade("Ef","Free Enchanting Tables on Plains","Chance to instantly get a lvl. 1 table.",function(x){return x*x;},function(x){return this.effectFunc(x)+"%";},function(x){return x+1;},10,function(){return g_PersistentData.get_challenge_times_completed("DE")>1;},"Need 2 DECs");
g_PersistentData.add_upgrade("ES","Ench. Tables on Swamps","Can build directly on swamps.",function(x){return x>0;},function(x){if(x>0){return"Yes";}return"No";},function(x){return 4;},1,function(){return g_PersistentData.statTotalLevel5>=20;},"20 lvl. 5 buildings",function(){return g_PersistentData.statTotalLevel5<3;});
g_PersistentData.add_upgrade("E3","Enchanting Table Lvl. 3","Reduce the dark energy cost.",function(x){return pow(0.2,x/5);},function(x){return"*"+this.effectFunc(x).toFixed(3);},function(x){return 50;},5,function(){return g_PersistentData.get_challenge_times_completed("8Y")>2;},"Need 3 8YCs",function(){return!g_PersistentData.get_challenge_times_completed("8Y");});
g_PersistentData.add_upgrade("FC","Decrease Furnace Costs by 2%","Cost to build/upgrade.",function(x){return pow(0.98,x);},function(x){return"*"+this.effectFunc(x).toFixed(3);},function(x){return 10+10*x;},-1,function(){return g_PersistentData.get_challenge_times_completed("UR")>0;},"Need 1 URC",function(){return g_PersistentData.get_total_challenges_completed()<3;});
g_PersistentData.add_upgrade("S1","Decrease Shelter Lvl. 1 Mithril Cost","Other costs unaffected.",function(x){return max(-2*x,-20-x);},function(x){return this.effectFunc(x);},function(x){return floor(sqrt(x+1));},25,function(){return g_PersistentData.get_challenge_times_completed("SR")>0;},"Need 1 SRC");
g_PersistentData.add_upgrade("RF","Enable the Reef","New building connected to merfolk.",function(x){return x;},function(x){return x?"Yes":"No";},function(x){return 1;},1,function(){return g_PersistentData.get_challenge_times_completed("DA")>1;},"Need 2 DACs",function(){return g_PersistentData.get_challenge_times_completed("DA")<1;});
g_PersistentData.add_upgrade("H2","House Lvl. 2 Spice Cost","Iron cost unaffected.",function(x){return 600*pow(0.25,x);},function(x){var n=this.effectFunc(x);return Number.isInteger(n)?n:n.toFixed(1);},function(x){return pow(5,x+1);},2,function(){return g_PersistentData.get_challenge_times_completed("DA")>0;},"Need 1 DAC");
g_PersistentData.add_upgrade("H3","House Lvl. 3 Spice Cost","Other cost unaffected.",function(x){return round(1000*pow(0.3,x));},function(x){return this.effectFunc(x);},function(x){return 10*x+10;},3,function(){return g_PersistentData.statTotalPeopleSaved>=2500;},"2500 people");
g_PersistentData.add_upgrade("H4","House Lvl. 4 Bio-Orb Cost","Other cost unaffected.",function(x){return 250-100*x;},function(x){return this.effectFunc(x);},function(x){return 18;},2,function(){return g_PersistentData.totalAPs>=3;},"3 ???s",function(){return!this.unlockFunc();});
g_PersistentData.add_upgrade("H5","House Lvl. 5 Cost","Golden apple/bio-orb costs.",function(x){var bArr=[5000,2000,1000,800,650,500],gArr=[10000,1000,200,190,180,170];return{"ga":gArr[x],"bo":bArr[x]};},function(x){var t=this.effectFunc(x);return(t.ga>999?round(t.ga/1000)+"k":t.ga)+"/"+(t.bo>999?round(t.bo/1000)+"k":t.bo);},function(x){return x<3?40:30;},5,function(){return g_PersistentData.get_challenge_times_completed("RW")>0;},"Need 1 RWC",function(){return g_PersistentData.totalAPs<1;});
g_PersistentData.add_upgrade("AP","Aqueducts Technology Power","Raises exponent of effect.",function(x){return 1+0.2*x;},function(x){return"^"+this.effectFunc(x).toFixed(1);},function(x){return floor(pow(x+2,1.5));},20,function(){return g_PersistentData.statTotalPeopleSaved>=1000;},"1000 people");
g_PersistentData.add_upgrade("CP","Collection Power","Mana production from collectors.",function(x){return 0.01*x;},function(x){return"+"+this.effectFunc(x).toFixed(2);},function(x){return 6+3*floor(pow(x,1.2));},-1,function(){return g_PersistentData.statTotalPeopleSaved>=7500;},"7500 people",function(){return g_PersistentData.statTotalPeopleSaved<2500;});
g_PersistentData.add_upgrade("PM","6% Higher Pearl Production Multiplier","Also multiplies pearl from fishing.",function(x){return pow(1.06,x);},function(x){return"*"+g_ResourcePane.formatSI(this.effectFunc(x));},function(x){return sq(x)+1;},-1,function(){return g_PersistentData.statHighestReefHealthRecord===500;},"500% Health",function(){return g_PersistentData.statHighestReefHealthRecord<200;});
g_PersistentData.add_upgrade("SM","Faraway Mines Produce More Stone","Based on distance from your house.",function(x){return 0.1*x;},function(x){return this.effectFunc(x).toFixed(1);},function(x){return 15+x;},5,function(){return g_PersistentData.get_total_upgrades_purchased()>124;},"125 Upgrades",function(){return g_PersistentData.get_total_upgrades_purchased()<50;});
g_PersistentData.add_upgrade("ST","3% More Spice From Trading","Stacks multiplicatively.",function(x){return pow(1.03,x);},function(x){return"*"+g_ResourcePane.formatSI(this.effectFunc(x));},function(x){return max(floor(0.5*x)+1,pow(x-106,3));},-1,true_func,"");
g_PersistentData.add_upgrade("GM","Slime Multi → Gadolinium Production","Part of the multi affects production.",function(x){return 0.1*x;},function(x){return"^"+this.effectFunc(x).toFixed(1);},function(x){return 2*floor(10*pow(1.3,x));},5,function(){return g_PersistentData.statTotalLevel5>=1000;},"1000 lvl. 5",function(){return g_PersistentData.statTotalLevel5<750;});
g_PersistentData.add_upgrade("FP","Fireplace: Gain Flame Orb in Summer","Only for house lvl. 2+.",function(x){if(allBuildings.length<1||currentScreen==="ultimate-shop"){return 0.5*x;}if(allBuildings[0].upgradeLevel>1){return allBuildings[0].upgradeLevel*0.5*x;}return 0;},function(x){var n=this.effectFunc(x);return Number.isInteger(n)?n:n.toFixed(1);},function(x){return floor(40*pow(1.15,x))-20;},-1,function(){return g_PersistentData.statTotalLevel5>=100;},"100 lvl. 5 bldgs.",function(){return g_PersistentData.statTotalLevel5<20;});
g_PersistentData.add_upgrade("IS","7.5% More Iron in Spring","Stacks multiplicatively.",function(x){return pow(1.075,x);},function(x){return"*"+g_ResourcePane.formatSI(this.effectFunc(x));},function(x){if(x>52){return floor(exp(x-48));}return 4*x+1;},-1,true_func,"");
g_PersistentData.add_upgrade("GA","5% More Golden Apple","Stacks multiplicatively.",function(x){return pow(1.05,x);},function(x){return"*"+g_ResourcePane.formatSI(this.effectFunc(x));},function(x){return max(40+6*x,floor(exp(x-45)));},-1,function(){return g_PersistentData.totalAPs>=60;},"60 Artifact Points",function(){return g_PersistentData.totalAPs<3;});
g_PersistentData.add_upgrade("BF","Bio-Orb From Enchanting","Percentage boost per farm built.",function(x){return 0.01*x;},function(x){return this.effectFunc(x).toFixed(2)+"%";},function(x){if(x<40){return 50+2*x;}return 129+sq(x-39);},-1,function(){return g_PersistentData.totalAPs>=40;},"40 Artifact Points",function(){return g_PersistentData.totalAPs<3;});
g_PersistentData.add_upgrade("EP","Expanded Furnaces Power","Raises exponent of effect.",function(x){return 1+0.1*x;},function(x){return"^"+this.effectFunc(x).toFixed(1);},function(x){return floor(10*pow(1.5,x));},-1,function(){return g_PersistentData.statTotalLevel5>=750;},"750 lvl. 5 bldgs.",function(){return g_PersistentData.statTotalLevel5<500;});
g_PersistentData.add_upgrade("MS","More Mithril Based on Swamp Factor","Affects enchanting & production.",function(x){if(x>0){return 0.1*sqrt(max(g_Factors.get_swamp_factor()+x,0))+1;}return 1;},function(x){if(x>0){return"Yes +"+x;}return"No";},function(x){if(x===0){return 4;}if(x<3){return 1;}return 20;},4,true_func,"");
g_PersistentData.add_upgrade("3B","Tier 3 Resource Boost","Resource production multiplier.",function(x){return x?1.5:1;},function(x){return "*"+this.effectFunc(x).toFixed(1);},function(x){return 100;},1,function(){return g_PersistentData.statTotalFrosthours>=3;},"???",function(){return!this.unlockFunc();});
g_PersistentData.add_upgrade("HA","Hilbert Architecture","Increases effect of Zoning tech.",function(x){return 1.3+0.05*x;},function(x){return(100*this.effectFunc(x)-100).toFixed(0)+"%";},function(x){return floor(100*pow(1.15,x));},-1,function(){return g_PersistentData.get_was_artifact_found("GFC");},"???",function(){return!this.unlockFunc();});
g_PersistentData.add_upgrade("DA","De-Slime Adjacent Claimed Tiles","Upgrade the spell De-Slimification.",function(x){return x>0;},function(x){return x>0?"Yes":"No";},function(x){return 3;},1,function(){return g_PersistentData.statTotalLevel5>0;},"1 lvl. 5 building");
g_PersistentData.add_upgrade("GC","Golden Magic Counting","Increase cast stat with golden apple.",function(x){return 10+x;},function(x){return this.effectFunc(x);},function(x){if(x>10){return floor(exp(x-6));}return floor(pow(x,1.1)+10*x+5);},-1,function(){return g_PersistentData.totalAPs>=100;},"100 Artifact Pts",function(){return g_PersistentData.totalAPs<60;});
g_PersistentData.add_upgrade("FR","Dragonfire Range Increase","Also boosts a certain spell.",function(x){return{"base":50+15*x,"EtD":25+5*x};},function(x){var r=this.effectFunc(x).base/32;if(r<100){return r.toFixed(1)+" tiles";}return(r<1000?r.toFixed(1):(r/1000).toFixed(2)+"k");},function(x){return 10*pow(5,x);},-1,function(){return g_PersistentData.statTotalPeopleSaved>=15000;},"15k people",function(){return g_PersistentData.statTotalPeopleSaved<7500;});
g_PersistentData.add_upgrade("SB","Spice Cost of Bio-Orb","Amount needed for enchanting.",function(x){return 50-5*x;},function(x){return this.effectFunc(x);},function(x){return 2+2*x;},10,function(){return g_PersistentData.discoveredArtifactList.length>0;},"Find ???",function(){return!this.unlockFunc();});
g_PersistentData.add_upgrade("FB","Food Bank Tech Cost","Affects the bio-orb cost.",function(x){return 70-10*x;},function(x){return this.effectFunc(x);},function(x){return 15;},6,function(){return g_PersistentData.get_was_artifact_found("P");},"???",function(){return!this.unlockFunc();});
g_PersistentData.add_upgrade("Ms","Multiplier Shift Discount","Decreases cost to buy the tech.",function(x){return 70-10*x;},function(x){return "-"+(10*x);},function(x){return 15+2*x;},6,function(){return g_PersistentData.get_was_artifact_found("H2O");},"Find ???",function(){return g_PersistentData.totalAPs<25;});
g_PersistentData.add_upgrade("PA","Rescue Pod Armor","Make engines take less damage.",function(x){return x>0;},function(x){return x>0?"Armored":"Normal";},function(x){return 100;},1,function(){return g_PersistentData.totalAPs>=300;},"300 Artifact Pts",function(){return g_PersistentData.totalAPs<100;});
g_PersistentData.add_upgrade("TF","Telephone Footwear Boost","Affects its seasonal extra effect.",function(x){return x>0?0.99:0.86;},function(x){return this.effectFunc(x).toFixed(2);},function(x){return 13;},1,function(){return g_PersistentData.get_was_artifact_found("TF");},"???",function(){return!this.unlockFunc();});
g_PersistentData.add_upgrade("4P","More Purple Squares","Increases mithril scaling with level.",function(x){return 0.8+0.045*sqrt(x);},function(x){return g_ResourcePane.formatSI(this.effectFunc(x));},function(x){return ceil(10*pow(1.1,x));},-1,function(){return g_PersistentData.get_was_artifact_found("4PS");},"???",function(){return!this.unlockFunc();});
g_PersistentData.update_us_page_count();
}
{
//abbrev, name, descFunc[1,2], startRunFunc, conditionFunc, reward, unlockFunc
g_PersistentData.add_challenge("SR","Standard Run Challenge",function(x){return"Standard run; regular rules. Lasts 10 years (1000 days).\nGoal to meet: rescue "+g_ResourcePane.evacuee_to_string(100*(x+1))+" people\nReward: 2 Ultimate Points, +5 max evacuees, more base flame orb from enchanting";},function(x){return"Unlock requirement: none (always unlocked)\nTimes completed: "+x+"\nCurrent cumulative reward: +"+g_ResourcePane.evacuee_to_string(5*x)+" max evacuees, "+g_ResourcePane.formatSI(base_flame_orb_from_enchanting())+" base flame orb from enchanting";},function(x){return;},function(x){return evacuees>=100*(x+1);},2,true_func);
g_PersistentData.add_challenge("DA","Diplomatic Alliance Challenge",function(x){if(this.unlockFunc()){return "Mana production is reduced by 30% in this Challenge. Purchasing tech from camels has no effect on standing."+(x>2?" Trading is more expensive.":"")+"\nGoal to meet: reach allied standing with the merfolk & the camels, rescue "+g_ResourcePane.evacuee_to_string(50*sq(x+1))+" people\nReward: 1 Ultimate Point, increase merfolk trade rewards";}return"Locked!";},function(x){if(this.unlockFunc()){return"Unlock requirement: purchase any 5 Ultimate Upgrades\nTimes completed: "+x+"\nCurrent cumulative reward: stone *"+g_ResourcePane.formatSI(pow(1.05,x))+", pearl +"+g_ResourcePane.formatSI(0.5*x)+", food +"+g_ResourcePane.formatSI(0.8*x)+(x>2?", dark energy *"+g_ResourcePane.formatSI(0.7*sqrt(x)):"");}return"Unlock requirement: purchase any 5 Ultimate Upgrades";},function(x){return;},function(x){return g_Diplomacy.merfolkStanding>7&&g_Diplomacy.camelsStanding>7&&evacuees>=50*sq(x+1);},1,function(){return g_PersistentData.get_total_upgrades_purchased()>=5;});
g_PersistentData.add_challenge("DE","Dark Energy Challenge",function(x){if(this.unlockFunc()){return"Dark energy is unlocked early. Gaze into the eye for a bonus.\nGoal to meet: gain a total of "+g_ResourcePane.formatSI(100*pow(4,x))+" dark energy\nReward: 5 Ultimate Points, *1.04 dark energy production, mine lvls. 3 & 4 cost 10% less iron";}return"Locked!";},function(x){if(this.unlockFunc()){return"Unlock requirement: complete any 3 Challenges\nTimes completed: "+x+"\nCurrent cumulative reward: *"+g_ResourcePane.formatSI(pow(1.04,x))+" dark energy production, mine lvls. 3 & 4 iron cost *"+pow(0.9,x).toFixed(3);}return"Unlock requirement: complete any 3 Challenges";},function(x){dayToUnlockDarkEnergy=10;},function(x){return totalDarkEnergyGained>=100*pow(4,x);},5,function(){return g_PersistentData.get_total_challenges_completed()>=3;});
g_PersistentData.add_challenge("5F","5 Farm Challenge",function(x){if(this.unlockFunc()){return"In this Challenge, you are limited to 5 farms & therefore 5 shelters. Some techs are changed."+(x>=2?" Stone production is also reduced by 10%.":"")+(x>=3?" Manual mining costs more food.":"")+"\nGoal to meet: rescue "+g_ResourcePane.evacuee_to_string(120+40*x)+" people\nReward: 3 Ultimate Points, various boosts to the spell Insta-Grow";}return"Locked!";},function(x){var n=g_TechnologyManager.get_farms_required_for_insta_grow_tech();if(this.unlockFunc()){return"Unlock requirement: purchase any 30 Ultimate Upgrades\nTimes completed: "+x+"\nCurrent cumulative reward: Insta-Grow spell cost reduced by "+min(1300,10*x)+" mana, Insta-Grow spell radius of effect: "+(256+20*x)/32+" tiles, Insta-Grow technology requires "+n+" farm"+(n===1?"":"s");}return"Unlock requirement: purchase any 30 Ultimate Upgrades";},function(x){return;},function(x){return evacuees>=120+40*x;},3,function(){return g_PersistentData.get_total_upgrades_purchased()>=30;});
g_PersistentData.add_challenge("UR","Underwater Ruins Challenge",function(x){if(this.unlockFunc()){return"The merfolk have mysteriously disappeared. Explore the ruins of their civilization to find resources."+(x>=2?" Camels & enchanting require more pearl.":"")+"\nGoal to meet: rescue "+g_ResourcePane.evacuee_to_string(1000+200*x)+" people\nReward: 4 Ultimate Points, +4 stone at the start of a run, +1 stone from manual mining"+(x<5?", -3 pearl to Chronometer tech cost":"");}return"Locked!";},function(x){if(this.unlockFunc()){return"Unlock requirement: complete any 10 Challenges\nTimes completed: "+x+"\nCurrent cumulative reward: start each run with "+g_ResourcePane.evacuee_to_string(10+4*x)+" stone, +"+g_ResourcePane.evacuee_to_string(x)+" stone from manual mining, Chronometer tech costs "+g_TechnologyManager.get_pearl_cost_for_chronometer_tech()+" pearl";}return"Unlock requirement: complete any 10 Challenges";},function(x){if(x>=2){enchantingPearlCostMulti=2.5;}return;},function(x){return evacuees>=1000+200*x;},4,function(){return g_PersistentData.get_total_challenges_completed()>=10;});
g_PersistentData.add_challenge("8Y","8 Year Challenge",function(x){if(this.unlockFunc()){return"The run ends in only 8 years instead of 10. Swarms spawn more often, some tiles are pre-slimed.\nGoal to meet: rescue "+g_ResourcePane.evacuee_to_string(5*pow(x+4,3))+" people & reach house lvl. 3 or higher\nReward: 3 Ultimate Points, gain 20% more mana & gadolinium from slime, increase mana production during the 1st year"+(x<56?", -50 to house lvl. 3 mithril cost":"");}return"Locked!";},function(x){if(this.unlockFunc()){return"Unlock requirement: rescue a total of 8000 people\nTimes completed: "+x+"\nCurrent cumulative reward: *"+g_ResourcePane.formatSI(pow(1.2,x))+" mana & gadolinium from slime, *"+g_ResourcePane.formatSI(mana_multi_8YC(x))+" mana production in the 1st year, house lvl. 3 costs "+g_TechnologyManager.get_mithril_cost_for_house_lvl_3()+" mithril";}return"Unlock requirement: rescue a total of 8000 people";},function(x){dayToRunEnd=800;},function(x){return allBuildings[0].upgradeLevel>=3&&evacuees>=5*pow(x+4,3);},3,function(){return g_PersistentData.statTotalPeopleSaved>=8000;});
g_PersistentData.add_challenge("RW","Ribbon World Challenge",function(x){if(this.unlockFunc()){return"The map is only 8 tiles tall"+(x>0?", faraway tiles cost more food to claim":"")+(x>=2?", dark energy production reduced by 20%":"")+".\nGoal to meet: rescue "+g_ResourcePane.evacuee_to_string(100*(x+1))+" people, claim "+min(500,300+50*x)+" tiles\nReward: 5 Ultimate Points, all terraformers cost 2% less to build & upgrade"+(x<17?", Land Grabbing tech requires 10 tiles fewer to unlock":"");}return"Locked!";},function(x){if(this.unlockFunc()){return"Unlock requirement: find the Ribbon Artifact\nTimes completed: "+x+"\nCurrent cumulative reward: all terraformer costs: *"+pow(0.98,x).toFixed(3)+", Land Grabbing technology requires "+g_TechnologyManager.get_tiles_for_land_grabbing_tech()+" tiles claimed";}if(g_PersistentData.discoveredArtifactList.length){return"Unlock requirement: find the ???";}return"Unlock requirement: ???";},function(x){worldgenOption=5;trainPowerLineX=round32(random(500,650)+random(0,350));},function(x){return evacuees>=100*(x+1)&&tilesClaimed>=min(500,300+50*x);},5,function(){return g_PersistentData.get_was_artifact_found("R");});
g_PersistentData.add_challenge("UC","Upkeep Cost Challenge",function(x){if(this.unlockFunc()){return"Furnaces are limited to 1 but are buffed. Some technologies are changed. Many buildings require iron for passive upkeep. Trade with the fire giants is enabled."+(x>0?" Camel technologies are "+g_ResourcePane.evacuee_to_string(50*x)+"% more expensive.":"")+"\nGoal to meet: purchase every camel technology\nReward: 12 Ultimate Points, +3 food at the start of a run, increased food production, more food from fishing";}return"Locked!";},function(x){if(this.unlockFunc()){return"Unlock requirement: 500 level 5 buildings, \"7.5% More Iron in Spring\" Ultimate Upgrade purchased to level 7\nTimes completed: "+x+"\nCurrent cumulative reward: start each run with "+g_ResourcePane.evacuee_to_string(20+3*x)+" food, *"+g_ResourcePane.formatSI(1+0.1*x)+" food production, *"+g_ResourcePane.formatSI(x<3?1+0.3*x:1.6+0.1*x)+" food from fishing";}return"Unlock requirement: 500 level 5 buildings, \"7.5% More Iron in Spring\" Ultimate Upgrade purchased to level 7";},function(x){throw"Error this will be overwritten";},function(x){return g_TechnologyManager.camelTechs.every(function(t){return t.researched;});},12,function(){return g_PersistentData.statTotalLevel5>=500&&g_PersistentData.get_upgrade_times_purchased("IS")>=7;});
g_PersistentData.add_challenge("AA","All Artifacts Challenge",function(x){if(this.hideName()){return"Progress in the game to see what this Challenge's name is!";}if(this.unlockFunc()){return"Artifacts get harder to find, spell mana costs increase by "+g_ResourcePane.evacuee_to_string(10*(x+1))+" when manually cast, all enchanting costs "+g_ResourcePane.evacuee_to_string(100+60*x)+"% more, early techs are harder to get.\nGoal to meet: find all 20 Artifacts\nReward: 8 Ultimate Points, +1 free lava freezer"+(x<16?", camel & merfolk standings increase faster":"");}return"Locked!";},function(x){if(this.unlockFunc()){return"Unlock requirement: find 20 unique Artifacts (not necessarily all in the same run)\nTimes completed: "+x+"\nCurrent cumulative reward: free lava freezers: "+x+", merfolk & camel standings increase "+min(800,50*x)+"% faster";}var l=g_PersistentData.discoveredArtifactList.length;if(l>=3){return"Unlock requirement: find 20 unique Artifacts (not necessarily all in the same run)";}return"Unlock requirement: ???";},function(x){enchantingPriceMulti=2+0.6*x;},function(x){return g_ArtifactManager.count_undiscovered()===0;},8,function(){return g_PersistentData.discoveredArtifactList.length===20;});
g_PersistentData.challengesList[g_PersistentData.challengesList.length-1].hideName=function(){return g_PersistentData.totalAPs<1;};
}
} //Persistent_Data
{
//More info can be found in previous file versions
var Resource_Pane=function(){
this.spiceVisible=!1;this.gadoliniumVisible=!1;this.flameOrbVisible=!1;this.ironVisible=!1;this.goldenAppleVisible=!1;this.darkEnergyVisible=!1;this.bioOrbVisible=!1;this.mithrilVisible=!1;this.evacueesVisible=!1;this.tierShowing=1;this.bProd=!0;this.bProdY=0;this.bCons=!0;this.bConsY=0;this.uCons=!0;this.uConsY=0;this.pMult=!0;this.pMultY=0;this.cMult=!0;this.cMultY=0;};
Resource_Pane.prototype.on_new_run_start=function(){
this.spiceVisible=!1;this.gadoliniumVisible=!1;this.flameOrbVisible=!1;this.ironVisible=!1;this.goldenAppleVisible=!1;this.darkEnergyVisible=!1;this.bioOrbVisible=!1;this.mithrilVisible=!1;this.evacueesVisible=!1;this.tierShowing=1;this.bProd=!0;this.bProdY=0;this.bCons=!0;this.bConsY=0;this.uCons=!0;this.uConsY=0;this.pMult=!0;this.pMultY=0;this.cMult=!0;this.cMultY=0;};
Resource_Pane.prototype.left_arrow_visible=function(){
if(g_TutorialProgress.get_rview_disabled()){return!1;}return this.tierShowing>1;};
Resource_Pane.prototype.right_arrow_visible=function(){
if(g_TutorialProgress.get_rview_disabled()){return!1;}if(this.evacueesVisible){return this.tierShowing<4;}if(this.goldenAppleVisible||this.darkEnergyVisible||this.bioOrbVisible||this.mithrilVisible){return this.tierShowing<3;}if(this.spiceVisible||this.gadoliniumVisible||this.flameOrbVisible||this.ironVisible){return this.tierShowing<2;}return!1;};
Resource_Pane.prototype.get_back_color=function(){
switch(this.tierShowing){case 1:return color(255,255,128);case 2:return color(128,255,128);case 3:return color(192,192,255);default:return color(255,128,128);}};
Resource_Pane.prototype.render_factors=function(){
stroke(0);fill(this.get_back_color());rect(-1,height-86,118,88);fill(0);textSize(12);text("Plains factor: "+g_Factors.get_plains_factor_string(),4,height-64);text("Swamp factor: "+g_Factors.get_swamp_factor_string(),4,height-48);text("Lake factor: "+g_Factors.get_lake_factor_string(),4,height-32);text("Desert factor: "+g_Factors.get_desert_factor_string(),4,height-16);};
Resource_Pane.prototype.render = function()
{
this.render_factors();fill(this.get_back_color());rect(117.2,height-86,width,88);if(g_TutorialProgress.get_rview_disabled()){return!1;}fill(0);
var xT=176,yT=[height-64,height-48,height-32,height-16];
switch(this.tierShowing)
{
case 1:text("Food: "+this.formatSI(foodResource)+" "+this.income_to_string(foodNetIncome),xT,yT[0]);text("Mana: "+this.formatSI(manaResource)+" "+this.income_to_string(manaNetIncome),xT,yT[1]);text("Pearl: "+this.formatSI(pearlResource)+" "+this.income_to_string(pearlNetIncome),xT,yT[2]);text("Stone: "+this.formatSI(stoneResource)+" "+this.income_to_string(stoneNetIncome),xT,yT[3]);break;
case 2:if(this.spiceVisible){text("Spice: "+this.formatSI(spiceResource)+" "+this.income_to_string(spiceNetIncome),xT,yT[0]);}if(this.gadoliniumVisible){text("Gadolinium: "+this.formatSI(gadoliniumResource)+" "+this.income_to_string(gadoliniumNetIncome),xT,yT[1]);}if(this.flameOrbVisible){text("Flame Orb: "+this.formatSI(flameOrbResource)+" "+this.income_to_string(flameOrbNetIncome),xT,yT[2]);}if(this.ironVisible){text("Iron: "+this.formatSI(ironResource)+" "+this.income_to_string(ironProjectedNetIncome),xT,yT[3]);}break;
case 3:if(this.goldenAppleVisible){text("Golden Apple: "+this.formatSI(goldenAppleResource)+" "+this.income_to_string(goldenAppleNetIncome),xT,yT[0]);}if(this.darkEnergyVisible){text("Dark Energy: "+this.formatSI(darkEnergyResource)+" "+this.income_to_string(darkEnergyProjectedNetIncome),xT,yT[1]);}if(this.bioOrbVisible){text("Bio-Orb: "+this.formatSI(bioOrbResource)+" "+this.income_to_string(bioOrbNetIncome),xT,yT[2]);}if(this.mithrilVisible){text("Mithril: "+this.formatSI(mithrilResource)+" "+this.income_to_string(mithrilProjectedFinalIncome),xT,yT[3]);}break;
case 4:if(this.evacueesVisible){var zzz="Evacuees: "+this.evacuee_to_string(evacuees)+"/"+this.evacuee_to_string(evacueesEnRoute)+"/"+this.evacuee_to_string(maxEvacuees),sz=18;textSize(sz);while(textWidth(zzz)>396-xT){sz-=1;textSize(sz);}
text(zzz,xT,height-46);textSize(12);text("(rescued/en route/maximum)",xT,height-28);}
}
if(this.left_arrow_visible()){if(mouseX>=120&&mouseX<152&&mouseY>=height-58&&mouseY<height-26){fill(255,255,0);}else{fill(192,192,0);}triangle(120,height-42,152,height-58,152,height-26);}if(this.right_arrow_visible()){if(mouseX>=width-32&&mouseX<width&&mouseY>=height-58&&mouseY<height-26){fill(255,255,0);}else{fill(192,192,0);}triangle(width,height-42,width-32,height-58,width-32,height-26);}
};
Resource_Pane.prototype.on_mouse_pressed=function(){if(mouseY<height-58||mouseY>=height-26){return;}if(mouseX>=120&&mouseX<152){this.move_left();}if(mouseX>=width-32&&mouseX<width){this.move_right();}};
Resource_Pane.prototype.move_left=function(){if(this.left_arrow_visible()){this.tierShowing-=1;}return;};
Resource_Pane.prototype.move_right=function(){if(this.right_arrow_visible()){this.tierShowing+=1;}return;};
Resource_Pane.prototype.format_multi=function(n,v){return n+": *"+v.toFixed(3)+" or "+(100*v-100).toFixed(3)+"%";};
Resource_Pane.prototype.formatSI=function(n){if(typeof n!=="number"){throw"Type Error";}if(Number.isNaN(n)){return"NaN";}if(!Number.isFinite(n)){return n<0?"-Infinity":"Infinity";}if(abs(n)<100000){return this.to_decimal_places(n);}if(abs(n)<1000000){return this.to_decimal_places(n/1000)+"k";}if(abs(n)<pow(10,9)){return this.to_decimal_places(n/1000000)+"M";}if(abs(n)<pow(10,12)){return this.to_decimal_places(n/pow(10,9))+"G";}if(abs(n)<pow(10,15)){return this.to_decimal_places(n/pow(10,12))+"T";}if(abs(n)<pow(10,18)){return this.to_decimal_places(n/pow(10,15))+"P";}if(abs(n)<pow(10,21)){return this.to_decimal_places(n/pow(10,18))+"E";}if(abs(n)<pow(10,24)){return this.to_decimal_places(n/pow(10,21))+"Z";}if(abs(n)<pow(10,27)){return this.to_decimal_places(n/pow(10,24))+"Y";}if(abs(n)<pow(10,30)){return this.to_decimal_places(n/pow(10,27))+"R";}if(abs(n)<pow(10,33)){return this.to_decimal_places(n/pow(10,30))+"Q";}if(abs(n)<pow(10,36)){return this.to_decimal_places(n/pow(10,33))+" big";}if(abs(n)<pow(10,39)){return this.to_decimal_places(n/pow(10,36))+" huge";}return n<0?"Almost Negative Infinity":"Almost Infinity";};
Resource_Pane.prototype.to_decimal_places=function(n){if(abs(n)<100){return n.toFixed(3);}if(abs(n)<1000){return n.toFixed(2);}if(abs(n)<10000){return n.toFixed(1);}return n.toFixed(0);};
Resource_Pane.prototype.evacuee_to_string=function(n){if(n<100000){return n.toFixed(0);}return this.formatSI(n);};
Resource_Pane.prototype.income_to_string=function(n){return"("+(n>0?"+":"")+this.formatSI(n)+"/day)";};
Resource_Pane.prototype.display_expander_buttons=function(){
stroke(0);if(this.bCons&&this.bConsY<this.uConsY){line(8,this.bConsY+1,8,this.uConsY-5);line(8,this.uConsY-5,18,this.uConsY-5);}var y=this.bProdY,b=this.bProd;fill(0,192,192);if(mouseX>=2&&mouseX<14&&mouseY>=y-11&&mouseY<y+1){fill(0,255,255);}rect(2,y-11,12,12);fill(0);text(b?"-":"+",5+2*b,y-b);y=this.bConsY;b=this.bCons;fill(0,192,192);if(mouseX>=2&&mouseX<14&&mouseY>=y-11&&mouseY<y+1){fill(0,255,255);}rect(2,y-11,12,12);fill(0);text(b?"-":"+",5+2*b,y-b);y=this.uConsY;b=this.uCons;fill(0,144,192);if(mouseX>=18&&mouseX<30&&mouseY>=y-11&&mouseY<y+1){fill(0,192,255);}rect(18,y-11,12,12);fill(0);text(b?"-":"+",21+2*b,y-b);y=this.pMultY;b=this.pMult;fill(0,192,192);if(mouseX>=2&&mouseX<14&&mouseY>=y-11&&mouseY<y+1){fill(0,255,255);}rect(2,y-11,12,12);fill(0);text(b?"-":"+",5+2*b,y-b);y=this.cMultY;b=this.cMult;fill(0,192,192);if(mouseX>=2&&mouseX<14&&mouseY>=y-11&&mouseY<y+1){fill(0,255,255);}rect(2,y-11,12,12);fill(0);text(b?"-":"+",5+2*b,y-b);};
Resource_Pane.prototype.click_expander_button=function(){
var y=this.uConsY;if(mouseX>=18&&mouseX<30&&mouseY>=y-11&&mouseY<y+1){this.uCons=!this.uCons;return!0;}if(mouseX<2||mouseX>=14){return!1;}y=this.bProdY;if(mouseY>=y-11&&mouseY<y+1){this.bProd=!this.bProd;return!0;}y=this.bConsY;if(mouseY>=y-11&&mouseY<y+1){this.bCons=!this.bCons;return!0;}y=this.pMultY;if(mouseY>=y-11&&mouseY<y+1){this.pMult=!this.pMult;return!0;}y=this.cMultY;if(mouseY>=y-11&&mouseY<y+1){this.cMult=!this.cMult;return!0;}return!1;};
g_ResourcePane=new Resource_Pane();
} //Resource_Pane
{
//This class keeps track of the 4 factors; designed to eliminate rounding errors.
var Factor_Manager=function(){this.plainsFactor=0;this.swampFactor=0;this.desertFactor=0;this.lakeFactor=0;};
Factor_Manager.prototype.on_new_run_start=function(){this.plainsFactor=0;this.swampFactor=0;this.desertFactor=0;this.lakeFactor=0;};
Factor_Manager.prototype.get_plains_factor=function(){return 0.1*this.plainsFactor;};
Factor_Manager.prototype.get_swamp_factor=function(){return 0.1*this.swampFactor;};
Factor_Manager.prototype.get_desert_factor=function(){return 0.1*this.desertFactor;};
Factor_Manager.prototype.get_lake_factor=function(){return 0.1*this.lakeFactor;};
Factor_Manager.prototype.get_plains_factor_string=function(){return(0.1*this.plainsFactor).toFixed(1);};
Factor_Manager.prototype.get_swamp_factor_string=function(){return(0.1*this.swampFactor).toFixed(1);};
Factor_Manager.prototype.get_desert_factor_string=function(){return(0.1*this.desertFactor).toFixed(1);};
Factor_Manager.prototype.get_lake_factor_string=function(){return(0.1*this.lakeFactor).toFixed(1);};
Factor_Manager.prototype.add_plains_tile=function(){this.plainsFactor+=3;this.swampFactor-=1;this.desertFactor-=1;this.lakeFactor-=1;};
Factor_Manager.prototype.add_swamp_tile=function(){this.plainsFactor-=1;this.swampFactor+=3;this.desertFactor-=1;this.lakeFactor-=1;};
Factor_Manager.prototype.add_desert_tile=function(){this.plainsFactor-=1;this.swampFactor-=1;this.desertFactor+=3;this.lakeFactor-=1;};
Factor_Manager.prototype.add_lake_tile=function(){this.plainsFactor-=1;this.swampFactor-=1;this.desertFactor-=1;this.lakeFactor+=3;};
Factor_Manager.prototype.remove_plains_tile=function(){this.plainsFactor-=3;this.swampFactor+=1;this.desertFactor+=1;this.lakeFactor+=1;};
Factor_Manager.prototype.remove_swamp_tile=function(){this.plainsFactor+=1;this.swampFactor-=3;this.desertFactor+=1;this.lakeFactor+=1;};
Factor_Manager.prototype.remove_desert_tile=function(){this.plainsFactor+=1;this.swampFactor+=1;this.desertFactor-=3;this.lakeFactor+=1;};
Factor_Manager.prototype.remove_lake_tile=function(){this.plainsFactor+=1;this.swampFactor+=1;this.desertFactor+=1;this.lakeFactor-=3;};
Factor_Manager.prototype.start_lake_music=function(){this.plainsFactor-=20;this.swampFactor-=20;this.desertFactor-=20;this.lakeFactor+=60;};
Factor_Manager.prototype.end_lake_music=function(){this.plainsFactor+=20;this.swampFactor+=20;this.desertFactor+=20;this.lakeFactor-=60;};
Factor_Manager.prototype.start_plains_grow=function(){this.plainsFactor+=60;this.swampFactor-=20;this.desertFactor-=20;this.lakeFactor-=20;};
Factor_Manager.prototype.end_plains_grow=function(){this.plainsFactor-=60;this.swampFactor+=20;this.desertFactor+=20;this.lakeFactor+=20;};
g_Factors = new Factor_Manager();
} //Factor_Manager
{
//For more info, see old file versions:
var Toggle_Button_Manager=function(){
this.furnaceToggle=!0;this.furnaceToggleVisible=!1;this.darkMineToggle=!0;this.darkMineToggleVisible=!1;this.mithrilMineToggle=!0;this.mithrilMineToggleVisible=!1;this.terraformerLvl4Toggle=!0;this.terraformerLvl4ToggleVisible=!1;this.lavaFreezerToggle=!0;this.lavaFreezerToggleVisible=!1;this.goldenFarmToggle=!0;this.goldenFarmToggleVisible=!1;this.mithrilMineDarkToggle=!0;this.mithrilMineDarkToggleVisible=!1;};
Toggle_Button_Manager.prototype.on_new_run_start=function(){
this.furnaceToggle=!0;this.furnaceToggleVisible=!1;this.darkMineToggle=!0;this.darkMineToggleVisible=!1;this.mithrilMineToggle=!0;this.mithrilMineToggleVisible=!1;this.terraformerLvl4Toggle=!0;this.terraformerLvl4ToggleVisible=!1;this.lavaFreezerToggle=!0;this.lavaFreezerToggleVisible=!1;this.goldenFarmToggle=!0;this.goldenFarmToggleVisible=!1;this.mithrilMineDarkToggle=!0;this.mithrilMineDarkToggleVisible=!1;};
Toggle_Button_Manager.prototype.draw=function(){
noStroke();var textX=width-2,textY=[199,215,231];if(this.furnaceToggleVisible&&!currentlyInBackside){fill(255,255,255,128);rect(width-25,121,26,14);fill(0,0,0);ellipse(width-18,128,12,12);ellipse(width-6,128,12,12);rect(width-18,122,12,12);if(this.furnaceToggle){fill(0,255,0);ellipse(width-18,128,10,10);}else{fill(255,0,0);ellipse(width-6,128,10,10);}if(ticksToShowDayNumber===0&&mouseX>=width-24&&mouseY>=122&&mouseY<134){fill(255,255,255,128);rect(width-90,textY[0]-14,90,34);fill(0,0,0);textSize(12);textAlign(RIGHT,BASELINE);text("Toggle furnaces",textX,textY[0]);if(this.furnaceToggle){text("Currently ON",textX,textY[1]);}else{text("Currently OFF",textX,textY[1]);}textAlign(LEFT,BASELINE);}}if(this.darkMineToggleVisible&&!currentlyInBackside){fill(255,255,255,128);rect(width-25,137,26,14);fill(0,0,0);ellipse(width-18,144,12,12);ellipse(width-6,144,12,12);rect(width-18,138,12,12);if(this.darkMineToggle){fill(0,255,0);ellipse(width-18,144,10,10);}else{fill(255,0,0);ellipse(width-6,144,10,10);}if(ticksToShowDayNumber===0&&mouseX>=width-24&&mouseY>=138&&mouseY<150){fill(255,255,255,128);rect(width-80,textY[0]-14,80,34);fill(0,0,0);textSize(12);textAlign(RIGHT,BASELINE);text("Dark mines",textX,textY[0]);if(this.darkMineToggle){text("Currently ON",textX,textY[1]);}else{text("Currently OFF",textX,textY[1]);}textAlign(LEFT,BASELINE);}}if(this.goldenFarmToggleVisible&&!currentlyInBackside){fill(255,255,255,128);rect(width-25,153,26,14);fill(0,0,0);ellipse(width-18,160,12,12);ellipse(width-6,160,12,12);rect(width-18,154,12,12);if(this.goldenFarmToggle){fill(0,255,0);if(season===4){fill(85,85,85);}ellipse(width-18,160,10,10);}else{fill(255,0,0);if(season===4){fill(85,85,85);}ellipse(width-6,160,10,10);}if(ticksToShowDayNumber===0&&mouseX>=width-24&&mouseY>=154&&mouseY<166){fill(255,255,255,128);rect(width-80,textY[0]-14,80,34);if(season===4){fill(255,255,255,128);rect(width-116,textY[2]-12,142,16);}fill(0,0,0);textSize(12);textAlign(RIGHT,BASELINE);text("Golden farms",textX,textY[0]);if(this.goldenFarmToggle){text("Currently ON",textX,textY[1]);}else{text("Currently OFF",textX,textY[1]);}if(season===4){text("No effect in frosthour",textX,textY[2]);}textAlign(LEFT,BASELINE);}}if(this.terraformerLvl4ToggleVisible){fill(255,255,255,128);rect(width-25,169,26,14);fill(0,0,0);ellipse(width-18,176,12,12);ellipse(width-6,176,12,12);rect(width-18,170,12,12);
if(this.terraformerLvl4Toggle){fill(0,255,0);ellipse(width-18,176,10,10);}else{fill(255,0,0);ellipse(width-6,176,10,10);}if(ticksToShowDayNumber===0&&mouseX>=width-24&&mouseY>=170&&mouseY<182){fill(255,255,255,128);rect(width-107,textY[0]-14,107,34);fill(0,0,0);textSize(12);textAlign(RIGHT,BASELINE);text("Terraformers lvl. 4+",textX,textY[0]);if(this.terraformerLvl4Toggle){text("Currently ON",textX,textY[1]);}else{text("Currently OFF",textX,textY[1]);}textAlign(LEFT,BASELINE);}}if(this.mithrilMineToggleVisible&¤tlyInBackside){fill(255,255,255,128);rect(width-25,137,26,14);fill(0,0,0);ellipse(width-18,144,12,12);ellipse(width-6,144,12,12);rect(width-18,138,12,12);if(this.mithrilMineToggle){fill(0,255,0);ellipse(width-18,144,10,10);}else{fill(255,0,0);ellipse(width-6,144,10,10);}if(ticksToShowDayNumber===0&&mouseX>=width-24&&mouseY>=138&&mouseY<150){fill(255,255,255,128);rect(width-116,textY[0]-14,116,34);fill(0,0,0);textSize(12);textAlign(RIGHT,BASELINE);text("Toggle mithril mining",textX,textY[0]);if(this.mithrilMineToggle){text("Currently ON",textX,textY[1]);}else{text("Currently OFF",textX,textY[1]);}textAlign(LEFT,BASELINE);}}if(this.lavaFreezerToggleVisible&¤tlyInBackside){fill(255,255,255,128);rect(width-25,121,26,14);fill(0,0,0);ellipse(width-18,128,12,12);ellipse(width-6,128,12,12);rect(width-18,122,12,12);fill(0,128,255);if(this.lavaFreezerToggle){ellipse(width-18,128,10,10);}else{ellipse(width-6,128,10,10);}if(ticksToShowDayNumber===0&&mouseX>=width-24&&mouseY>=122&&mouseY<134){var minEnr=allSpells.by_name("Mineral Enrichment").durationLeft>0;fill(255,255,255,128);rect(width-(126+6*minEnr),textY[0]-14,126+6*minEnr,50);fill(0,0,0);textSize(12);textAlign(RIGHT,BASELINE);text("Lava freezers",textX,textY[0]);text(minEnr?"Iron or gadolinium":"Stone or flame orb",textX,textY[1]);if(this.lavaFreezerToggle){text(minEnr?"Currently IRON":"Currently STONE",textX,textY[2]);}else{text(minEnr?"Currently GADOLINIUM":"Currently FLAME ORB",textX,textY[2]);}textAlign(LEFT,BASELINE);}}if(this.mithrilMineDarkToggleVisible&¤tlyInBackside){fill(255,255,255,128);rect(width-25,153,26,14);fill(0,0,0);ellipse(width-18,160,12,12);ellipse(width-6,160,12,12);rect(width-18,154,12,12);
if(this.mithrilMineDarkToggle){fill(0,255,0);if(!this.mithrilMineToggle){fill(85,85,85);}ellipse(width-18,160,10,10);}else{fill(255,0,0);if(!this.mithrilMineToggle){fill(85,85,85);}ellipse(width-6,160,10,10);}if(ticksToShowDayNumber===0&&mouseX>=width-24&&mouseY>=154&&mouseY<166){fill(255,255,255,128);rect(width-80,textY[0]-14,80,34);if(!this.mithrilMineToggle){fill(255,255,255,128);rect(width-110,textY[2]-12,136,16);}fill(0,0,0);textSize(12);textAlign(RIGHT,BASELINE);text("Dark mines",textX,textY[0]);if(this.mithrilMineDarkToggle){text("Currently ON",textX,textY[1]);}else{text("Currently OFF",textX,textY[1]);}if(!this.mithrilMineToggle){text("Mines are turned off",textX,textY[2]);}textAlign(LEFT,BASELINE);}}};
Toggle_Button_Manager.prototype.on_mouse_pressed=function(){
if(mouseX<width-24){return!1;}if(mouseY>=122&& mouseY<134){if(this.furnaceToggleVisible&&!currentlyInBackside){this.furnaceToggle=!this.furnaceToggle;recalculate_building_effects();movesLeft-=1;return!0;}if(this.lavaFreezerToggleVisible&¤tlyInBackside){this.lavaFreezerToggle=!this.lavaFreezerToggle;recalculate_building_effects();movesLeft-=1;return!0;}}if(mouseY>=138&&mouseY<150){if(this.darkMineToggleVisible&&!currentlyInBackside){this.darkMineToggle=!this.darkMineToggle;recalculate_building_effects();movesLeft-=1;return!0;}if(this.mithrilMineToggleVisible&¤tlyInBackside){this.mithrilMineToggle=!this.mithrilMineToggle;recalculate_building_effects();movesLeft-=1;return!0;}}if(mouseY>=154&&mouseY<166) {if(this.goldenFarmToggleVisible&&!currentlyInBackside){this.goldenFarmToggle=!this.goldenFarmToggle;recalculate_building_effects();movesLeft-=1;return!0;}if(this.mithrilMineDarkToggleVisible&¤tlyInBackside){this.mithrilMineDarkToggle=!this.mithrilMineDarkToggle;recalculate_building_effects();movesLeft-=1;return!0;}}if(mouseY>=170&&mouseY<182){if(this.terraformerLvl4ToggleVisible){this.terraformerLvl4Toggle=!this.terraformerLvl4Toggle;recalculate_building_effects();movesLeft-=1;return!0;}}return!1;};
g_ToggleButtonManager=new Toggle_Button_Manager();
} //Toggle_Button_Manager
{
//For more info, see older file versions:
var tile_type_as_string=function(t){
switch(t){case TT_PLAINS:return"plains";case TT_DESERT:return"desert";case TT_SWAMP:return"swamp";case TT_LAKE:return"lake";case TT_PAVED_OVER:return"paved over";case TT_SLIMED:return"slimed";case TT_MAP_EDGE:return"map edge";case TT_LAVA:return"lava";case TT_WASTELAND:return"wasteland";case TT_MITHRIL:return"mithril";case TT_CYBERMIND:return"cybermind";default:return"unknown";}};
var Tile=function(X,Y,t){
this.x=X;this.y=Y;this.claimed=!1;this.revealed=!1;this.nextToEdge=!1;this.tileType=t;this.backsideTileType=t===TT_MAP_EDGE?t:t+6;this.hasDarkEnergy=random(10)<2;this.hasTrainPowerLine=trainPowerLineX>=this.x-16&&trainPowerLineX<this.x+16;this.tier=dist(this.x,this.y,192,160)/200;this.buildings=[];if(t===TT_SWAMP&&g_PersistentData.currentChallenge==="8YC"&&random(10)<1){this.tileType=TT_SLIMED;}};
Tile.prototype.draw_at=function(xDraw,yDraw){
if(xDraw<-16||xDraw>width+16||yDraw<-16||yDraw>height+16){return;}var voidColor=currentlyInBackside?BACKSIDE_VOID_COLOR:FRONTSIDE_VOID_COLOR;if(!this.revealed){return;}switch(currentlyInBackside?this.backsideTileType:this.tileType){case TT_PLAINS:image(allTiles.images[season===4?TT_DPLAINS:TT_PLAINS],xDraw,yDraw);if(this.nextToEdge){noStroke();fill(voidColor);rect(xDraw-16,yDraw-16,8,8);rect(xDraw-16,yDraw,8,8);rect(xDraw-8,yDraw-8,8,8);}break;case TT_DESERT:image(allTiles.images[season===4?TT_DDESERT:TT_DESERT],xDraw,yDraw);if(this.nextToEdge){noStroke();fill(voidColor);rect(xDraw-16,yDraw-8,8,8);rect(xDraw-8,yDraw+8,8,8);}break;case TT_SWAMP:image(allTiles.images[season===4?TT_DSWAMP:TT_SWAMP],xDraw,yDraw);if(this.nextToEdge){noStroke();fill(voidColor);rect(xDraw-16,yDraw-8,8,16);rect(xDraw,yDraw-16,8,8);}break;case TT_LAKE:image(allTiles.images[season===4?TT_DLAKE:TT_LAKE],xDraw,yDraw);if(this.nextToEdge){noStroke();fill(voidColor);rect(xDraw-16,yDraw-8,16,8);rect(xDraw,yDraw,8,8);}break;case TT_PAVED_OVER:image(allTiles.images[TT_PAVED_OVER],xDraw,yDraw);if(season===4){noFill();stroke(255,128,0,130-80*(gcaS+sin(2*globalCyclicAnimation)/2+sin(3*globalCyclicAnimation)/3+sin(4*globalCyclicAnimation)/4));for(var i=7;i<=13;i+=2){rect(xDraw-i,yDraw-i,2*i,2*i);}}break;case TT_SLIMED:image(allTiles.images[TT_SLIMED],xDraw,yDraw);if(season===4){noStroke();fill(255,255,255,64);rect(xDraw-14,yDraw-14,28,28);rect(xDraw-16,yDraw-16,32,32);}if(this.nextToEdge){noStroke();fill(voidColor);rect(xDraw-16,yDraw-8,8,16);rect(xDraw,yDraw-16,8,8);}break;case TT_MAP_EDGE:var offset=floor(map(4*globalCyclicAnimation%360,0,360,0,32)),starColor=currentlyInBackside?color(0,255,0):color(255,255,255);noStroke();fill(voidColor);if(currentScreen==="main"||currentScreen==="main-info"){rect(0,yDraw-16,xDraw+16,32);stroke(starColor);for(var i=xDraw+offset-16;i>-1;i-=32){point(i,yDraw-offset+15);}}else{rect(xDraw-16,yDraw-16,32,32);stroke(starColor);point(xDraw+offset-16,yDraw-offset+15);}break;case TT_MITHRIL:image(allTiles.images[TT_MITHRIL],xDraw,yDraw);if(season===4){noStroke();fill(0,255,255,32);rect(xDraw-16,yDraw-16,32,32);}if(this.nextToEdge){noStroke();fill(voidColor);rect(xDraw-16,yDraw-16,8,8);rect(xDraw-16,yDraw,8,8);rect(xDraw-8,yDraw-8,8,8);}break;case TT_LAVA:image(allTiles.images[TT_LAVA],xDraw,yDraw);noStroke();if(season!==4){for(var i=-16;i<16;i+=8){for(var j=-16;j<16;j+=8){fill(255,0,0,128+64*sin(globalCyclicAnimation+2*(i+j)));rect(xDraw+i,yDraw+j,8,8);}}}else{var xL=xDraw+(180-(globalCyclicAnimation+abs(2*this.x+this.y))%360)/18;fill(128,128,128,64);rect(xDraw-16,yDraw-16,32,32);fill(96,96,96,196*sin((globalCyclicAnimation+abs(2*this.x+this.y))%360/2));
quad(xL,yDraw-5,xL+6,yDraw-3,xL+4,yDraw+5,xL-3,yDraw+4);triangle(xL-2,yDraw+8,xL+2,yDraw+6,xL-1,yDraw+12);fill(96,96,96,96+128*sq(cos(globalCyclicAnimation-this.x+this.y/3)));triangle(xDraw-4,yDraw-16,xDraw+6,yDraw-16,xDraw-1,yDraw-13);fill(96,96,96,96+128*sq(cos(globalCyclicAnimation-this.x+(this.y+32)/3)));triangle(xDraw-4,yDraw+16,xDraw+6,yDraw+16,xDraw+3,yDraw+13);}if(this.nextToEdge){fill(voidColor);rect(xDraw-16,yDraw-8,8,8);rect(xDraw-8,yDraw+8,8,8);}break;case TT_CYBERMIND:image(allTiles.images[TT_CYBERMIND],xDraw,yDraw);if(season===4){tint(255,255,255,128);image(allTiles.images[TT_DCYBERMIND],xDraw,yDraw);tint(255,255,255,255);}if(this.nextToEdge){noStroke();fill(voidColor);rect(xDraw-16,yDraw-8,8,16);rect(xDraw,yDraw-16,8,8);}break;case TT_WASTELAND:image(allTiles.images[season===4?TT_DWASTELAND:TT_WASTELAND],xDraw,yDraw);if(this.nextToEdge){noStroke();fill(voidColor);rect(xDraw-16,yDraw-8,16,8);rect(xDraw,yDraw,8,8);}break;default:image(allTiles.images[TT_MAP_EDGE],xDraw,yDraw);}if(allBuildings[0].upgradeLevel>=3&&this.hasTrainPowerLine){noStroke();if(currentlyInBackside){fill(0,255,255);}else{fill(128,64,0);}rect(xDraw+10,yDraw-16,3,32);}if(!this.claimed){noStroke();fill(voidColor,128);if(this.tileType===TT_MAP_EDGE&&(currentScreen==="main"||currentScreen==="main-info")){rect(0,yDraw-16,xDraw+16,32);}else{rect(xDraw-16,yDraw-16,32,32);}}};
Tile.prototype.draw=function(){this.draw_at(this.x-cameraX,this.y-cameraY);};
Tile.prototype.draw_dark_energy_at=function(x,y){
if(!this.hasDarkEnergy||x<-16||x>width+16||y<-16||y>height+16||!this.revealed){return;}noStroke();fill(0,0,0,64*gcaS+128);ellipse(x,y,8,8);ellipse(x+10*gcaC,y+10*gcaS,8,8);ellipse(x-10*gcaS,y+10*gcaC,8,8);ellipse(x-10*gcaC,y-10*gcaS,8,8);ellipse(x+10*gcaS,y-10*gcaC,8,8);};
Tile.prototype.draw_dark_energy=function(){this.draw_dark_energy_at(this.x-cameraX,this.y-cameraY);};
Tile.prototype.type_as_string=function(){return tile_type_as_string(this.tileType);};
Tile.prototype.backside_type_as_string=function(){return tile_type_as_string(this.backsideTileType);};
Tile.prototype.claim=function(){
this.claimed=!0;this.revealed=!0;switch(this.tileType){case TT_PLAINS:g_Factors.add_plains_tile();break;case TT_DESERT:g_Factors.add_desert_tile();break;case TT_SWAMP:g_Factors.add_swamp_tile();break;case TT_LAKE:g_Factors.add_lake_tile();break;}};
Tile.prototype.food_cost_to_claim=function(){
var C=10;if(g_PersistentData.currentChallenge==="RWC"){C+=5*g_PersistentData.get_challenge_times_completed("RW");}return C*floor(this.tier)+(this.tileType===TT_DESERT);};
allTiles = [];
allTiles.has_claimed=function(t){
for(var i=0;i<allTiles.length;i+=1){if(allTiles[i].claimed){if(allTiles[i].tileType===t||allTiles[i].backsideTileType===t){return!0;}}}return!1;};
allTiles.count_unclaimed_lakes=function(){var c=0;allTiles.forEach(function(T){c+=!T.claimed&&T.tileType===TT_LAKE;});return c;};
var slime_tile=function(){
var s=!1,r=-1,y=0;for(;y<50;y+=1){r=floor(random(allTiles.length));var t=allTiles[r];if(t.tileType===TT_SWAMP){t.tileType=TT_SLIMED;if(t.claimed){g_Factors.remove_swamp_tile();}if(selectedTile===r){if(currentScreen==="build"){currentScreen="main";}g_ConstructionManager.on_tile_selected();}s=!0;break;}}recalculate_building_effects();return s;};
var deslime_selected_tile=function(){
if(selectedTile===-1){return;}if(allTiles[selectedTile].tileType===TT_SLIMED){allTiles[selectedTile].tileType=TT_SWAMP;g_Factors.add_swamp_tile();var manaGained=10*manaFromSlimeMulti,gadoliniumGained=1*gadoliniumFromSlimeMulti;g_ConstructionManager.on_tile_selected();if(g_PersistentData.get_upgrade_effect("DA")){var temp=-1;temp=tile_at_position(allTiles[selectedTile].x-32,allTiles[selectedTile].y);if(temp>-1&&allTiles[temp].claimed&&allTiles[temp].tileType===TT_SLIMED){allTiles[temp].tileType=TT_SWAMP;g_Factors.add_swamp_tile();manaGained+=10*manaFromSlimeMulti;gadoliniumGained+=1*gadoliniumFromSlimeMulti;}temp=tile_at_position(allTiles[selectedTile].x+32,allTiles[selectedTile].y);if(temp>-1&&allTiles[temp].claimed&&allTiles[temp].tileType===TT_SLIMED){allTiles[temp].tileType=TT_SWAMP;g_Factors.add_swamp_tile();manaGained+=10*manaFromSlimeMulti;gadoliniumGained+=1*gadoliniumFromSlimeMulti;}temp=tile_at_position(allTiles[selectedTile].x,allTiles[selectedTile].y-32);if(temp>-1&&allTiles[temp].claimed&&allTiles[temp].tileType===TT_SLIMED){allTiles[temp].tileType=TT_SWAMP;g_Factors.add_swamp_tile();manaGained+=10*manaFromSlimeMulti;gadoliniumGained+=1*gadoliniumFromSlimeMulti;}temp=tile_at_position(allTiles[selectedTile].x,allTiles[selectedTile].y+32);if(temp>-1&&allTiles[temp].claimed&&allTiles[temp].tileType===TT_SLIMED){allTiles[temp].tileType=TT_SWAMP;g_Factors.add_swamp_tile();manaGained+=10*manaFromSlimeMulti;gadoliniumGained+=1*gadoliniumFromSlimeMulti;}}manaResource+=manaGained;gadoliniumResource+=gadoliniumGained;g_ResourcePane.gadoliniumVisible=!0;g_FlyingText.set_text("+"+(Number.isInteger(manaGained)?manaGained:g_ResourcePane.formatSI(manaGained))+" mana, +"+(Number.isInteger(gadoliniumGained)?gadoliniumGained:g_ResourcePane.formatSI(gadoliniumGained))+" gadolinium",mouseX,mouseY);g_FlyingText.fontColor=color(255,0,0);recalculate_building_effects();}};
var claim_tile=function(){
if(selectedTile===-1){return;}var s=allTiles[selectedTile];if(!s.claimed){s.claim();tilesClaimed+=1;var t=-1;t=tile_at_position(s.x-32,s.y);if(t>-1){allTiles[t].revealed=!0;}t=tile_at_position(s.x+32,s.y);if(t>-1){allTiles[t].revealed=!0;}t=tile_at_position(s.x,s.y-32);if(t>-1){allTiles[t].revealed=!0;}t=tile_at_position(s.x,s.y+32);if(t>-1){allTiles[t].revealed=!0;}if(s.tileType===TT_PLAINS){var c=g_PersistentData.get_upgrade_effect("Ef");if(c===100||(c>0&&random(0,100)<c)){allBuildings.build(selectedTile,BT_ENCHANTING_TABLE);g_EnchTableFlyingText.set_text("Free enchanting table!!!",s.x-cameraX,s.y+16-cameraY);g_EnchTableFlyingText.fontColor=color(255,0,255);allEnchTableAnimations.add();}}if(allCreatures.get_on_tile(selectedTile,CT_EDGE_FINDER)){if(g_EnchTableFlyingText.ticksToDisplay<60){g_EnchTableFlyingText.set_text("\n+10 mithril",s.x-cameraX,s.y-cameraY);g_EnchTableFlyingText.fontColor=color(255,0,255);}else{g_EnchTableFlyingText.text+="\n+10 mithril";}mithrilResource+=10;g_ResourcePane.mithrilVisible=!0;}if(g_PersistentData.currentChallenge==="URC"&&s.tileType===TT_LAKE&&!allBuildings.get_tile_has(selectedTile,BT_MER_MALL)&&!allBuildings.get_tile_has(selectedTile,BT_REEF)){var f=allBuildings.count_of_type(BT_UNDERWATER_RUINS,5)<1&&allTiles.count_unclaimed_lakes()<1;if(f||random(5)<1){allBuildings.build(selectedTile,BT_UNDERWATER_RUINS);if(f){allBuildings[allBuildings.length-1].upgradeLevel=5;}}}
recalculate_building_effects();}};
//I found a tutorial here:
//https://www.khanacademy.org/computer-programming/image-tutorial-hope/6740408654856192
//The image feature reduces lag in my game.
//Thank you, Iron Programming (@ncochran2) for this tutorial!
imageMode(CENTER);
var make_images=function(){
allTiles.images=[];for(var i=TT_PAVED_OVER;i<TT_DWASTELAND+1;i+=1){allTiles.images[i]=createImage(32,32,RGB);}noStroke();fill(128,128,128);rect(0,0,32,32);stroke(192,192,192);line(0,0,30,0);line(0,0,0,31);stroke(64,64,64);line(31,0,31,31);line(1,31,31,31);allTiles.images[TT_PAVED_OVER]=get(0,0,32,32);noStroke();fill(224,224,64);rect(0,0,32,32);stroke(112,112,32);fill(112,112,32);ellipse(12,18,2,2);ellipse(25,6,6,2);allTiles.images[TT_DESERT]=get(0,0,32,32);noStroke();fill(0,128,255);rect(0,0,32,32);allTiles.images[TT_LAKE]=get(0,0,32,32);noStroke();fill(0,192,0);rect(0,0,32,32);stroke(0,255,0);line(12,5,14,8);line(12,4,14,8);line(16,5,14,8);allTiles.images[TT_PLAINS]=get(0,0,32,32);noStroke();fill(0,96,192);rect(0,0,32,32);fill(0,128,0);rect(0,0,8,8);rect(8,0,8,16);rect(0,16,8,8);rect(8,24,16,8);rect(16,16,16,8);rect(24,0,8,8);allTiles.images[TT_SWAMP]=get(0,0,32,32);noStroke();fill(32,255,32);rect(0,0,32,32);fill(48,224,32);rect(10,10,12,12);stroke(144,255,144);line(0,0,30,0);line(0,0,0,31);stroke(24,128,72);line(31,0,31,31);line(1,31,31,31);allTiles.images[TT_SLIMED]=get(0,0,32,32);noStroke();fill(0,0,0);rect(0,0,32,32);allTiles.images[TT_MAP_EDGE]=get(0,0,32,32);noStroke();fill(255,64,0);rect(0,0,32,32);allTiles.images[TT_LAVA]=get(0,0,32,32);noStroke();fill(96,96,96);rect(0,0,32,32);stroke(0,64,0);point(4,5);point(5,6);point(6,5);point(4,7);point(6,7);point(8,24);point(8,25);point(9,26);noStroke();fill(128,64,0);ellipse(27,11,3,3);stroke(80,80,0);point(29,18);allTiles.images[TT_WASTELAND]=get(0,0,32,32);noStroke();fill(208,208,208);rect(0,0,32,32);stroke(0,0,0,64);line(6,8,11,14);line(21,11,17,16);line(4,17,8,25);line(18,27,19,31);allTiles.images[TT_MITHRIL]=get(0,0,32,32);
noStroke();fill(128,128,128);rect(0,0,32,32);noFill();stroke(255,0,0);line(8,0,8,10);line(8,10,22,24);line(22,24,31,24);line(0,24,4,24);line(4,24,8,28);line(8,28,8,31);stroke(0,255,0);line(24,0,24,8);line(0,8,24,8);line(28,8,31,8);line(28,8,28,28);line(24,28,28,28);line(24,28,24,31);stroke(0,0,255);line(16,0,16,31);line(0,16,6,16);line(26,16,31,16);ellipse(8.5,16.5,4,4);ellipse(24.5,16.5,4,4);allTiles.images[TT_CYBERMIND]=get(0,0,32,32);
noStroke();fill(240,240,160);rect(0,0,32,32);stroke(120,120,80);fill(112,112,32);ellipse(12,18,2,2);ellipse(25,6,6,2);allTiles.images[TT_DDESERT]=get(0,0,32,32);noStroke();fill(96,180,255);rect(0,0,32,32);allTiles.images[TT_DLAKE]=get(0,0,32,32);noStroke();fill(240,240,240);rect(0,0,32,32);stroke(255,255,255);line(6,8,11,14);line(21,11,17,16);line(4,17,8,25);line(18,27,19,31);allTiles.images[TT_DPLAINS]=get(0,0,32,32);noStroke();fill(96,164,224);rect(0,0,32,32);fill(240,240,240);rect(0,0,8,8);rect(8,0,8,16);rect(0,16,8,8);rect(8,24,16,8);rect(16,16,16,8);rect(24,0,8,8);allTiles.images[TT_DSWAMP]=get(0,0,32,32);background(0,0,0,0);noFill();stroke(255,255,255);line(8,0,8,10);line(8,10,22,24);line(22,24,31,24);line(0,24,4,24);line(4,24,8,28);line(8,28,8,31);line(24,0,24,8);line(0,8,24,8);line(28,8,31,8);line(28,8,28,28);line(24,28,28,28);line(24,28,24,31);line(16,0,16,31);line(0,16,6,16);line(26,16,31,16);stroke(0,0,0);ellipse(8.5,16.5,4,4);ellipse(24.5,16.5,4,4);allTiles.images[TT_DCYBERMIND]=get(0,0,32,32);image(allTiles.images[TT_WASTELAND],16,16);stroke(0,224,255,64);line(0,0,5,32);line(5,0,18,32);line(5,0,32,17);line(18,0,0,17);line(0,12,20,22);line(0,23,32,12);line(20,22,32,32);line(20,22,18,32);line(20,22,32,23);noStroke();fill(128,16,152);ellipse(20,22,4,4);ellipse(23,22,4,4);ellipse(20+3*cos(72),22+3*sin(72),4,4);ellipse(20+3*cos(72),22-3*sin(72),4,4);ellipse(20-3*cos(36),22+3*sin(144),4,4);ellipse(20-3*cos(36),22-3*sin(144),4,4);allTiles.images[TT_DWASTELAND]=get(0,0,32,32);};
make_images();
} //Tile
{
var Reef_Data=function(){
this.health=0;this.healthRecord=0;this.maxHealth=100;this.images=[];};
Reef_Data.prototype.on_new_run_start=function(){
this.health=0;this.healthRecord=0;this.maxHealth=100;};
Reef_Data.prototype.on_recalculate_effects=function(){
var h=this.health;foodBonusFromFishingOnReef+=1*(h>=20)+4*(h>=120)+5*(h>=220)+5*(h>=420);pearlProductionFromReef+=0.1*(h>=40)+0.9*(h>=140)+6*(h>=240)+8*(h>=320)+10*(h>=380)+11*(h>=480);stoneProductionMultiFromReefMagic*=(1+0.1*(h>=60))*(1+0.2*(h>=160))*(1+0.25*(h>=260));maxEvacueesFromReef+=30*(h>=280)+50*(h>=340);mithrilProductionMultiFromReef*=1+0.1*(h>=360);flameOrbConsumptionMultiFromReef*=1-0.2*(h>=460);};
Reef_Data.prototype.on_day_end=function(){
if(this.health>0&&this.health<160&&(this.health<80||random(0,10)<5)){this.health-=1;}this.health=constrain(this.health,0,this.maxHealth);};
Reef_Data.prototype.on_reef_upgraded=function(){
this.maxHealth=100*allBuildings.get_reef_level();};
Reef_Data.prototype.increase_health=function(a){
this.health=min(this.health+a,this.maxHealth);this.healthRecord=max(this.healthRecord,this.health);if(this.healthRecord>=280){g_ResourcePane.evacueesVisible=true;}};
Reef_Data.prototype.make_images=function(){
for(var i=0;i<5;i+=1){this.images[i]=createImage(32,32,RGB);}background(0,0,0,0);noStroke();fill(255,0,0);rect(0,24,8,8);fill(255,0,255);rect(0,20,4,4);rect(8,28,4,4);fill(0,255,128);rect(4,20,4,4);rect(8,24,4,4);stroke(255,0,255);line(1,6,1,20);line(12,30,25,30);line(1,18,6,18);line(13,25,13,30);line(1,15,6,15);line(16,25,16,30);line(1,12,5,12);line(19,26,19,30);line(1,9,3,9);line(22,28,22,30);this.images[0]=get(0,0,32,32);background(0,0,0,0);noStroke();fill(255,0,0);rect(0,24,8,8);fill(255,0,255);rect(0,20,4,4);rect(8,28,4,4);fill(0,255,128);rect(4,20,4,4);rect(8,24,4,4);stroke(255,0,255);line(1,2,1,20);line(12,30,29,30);line(0,18,7,18);line(13,24,13,31);line(1,16,8,16);line(15,23,15,30);line(1,14,7,14);line(17,24,17,30);line(1,12,6,12);line(19,25,19,30);line(1,10,5,10);line(21,26,21,30);line(1,8,4,8);line(23,27,23,30);line(1,6,3,6);line(25,28,25,30);line(1,4,2,4);line(27,29,27,30);stroke(0,255,128);line(5,16,5,20);line(12,26,15,26);line(9,18,9,24);line(8,22,13,22);this.images[1]=get(0,0,32,32);background(0,0,0,0);noStroke();fill(255,0,0);rect(0,24,8,8);fill(255,0,255);rect(0,20,4,4);rect(8,28,4,4);rect(0,0,5,5);rect(27,27,5,5);fill(0,255,128);rect(4,20,4,4);rect(8,24,4,4);stroke(255,0,255);line(2,2,2,20);line(12,29,29,29);line(0,18,7,18);line(13,24,13,31);line(0,16,8,16);line(15,23,15,31);line(0,14,7,14);line(17,24,17,31);line(0,12,6,12);line(19,25,19,31);line(0,10,5,10);line(21,26,21,31);line(0,8,4,8);line(23,27,23,31);line(0,6,4,6);line(25,27,25,31);line(2,2,10,2);line(29,21,29,29);line(6,0,6,4);line(27,25,31,25);line(8,1,8,3);line(28,23,30,23);stroke(0,255,128);line(5,12,5,20);line(12,26,19,26);line(7,14,7,20);line(12,24,17,24);line(9,16,9,24);line(8,22,15,22);line(11,18,11,24);line(8,20,13,20);this.images[2]=get(0,0,32,32);background(0,0,0,0);noStroke();fill(255,0,0);rect(0,24,8,8);rect(28,0,4,4);fill(255,0,255);rect(0,20,4,4);rect(8,28,4,4);rect(0,0,5,5);rect(27,27,5,5);fill(0,255,128);rect(4,20,4,4);rect(8,24,4,4);rect(1,1,3,3);rect(28,28,3,3);stroke(255,0,255);line(2,4,2,20);line(12,29,27,29);line(0,18,7,18);line(13,24,13,31);line(0,16,8,16);line(15,23,15,31);line(0,14,7,14);line(17,24,17,31);line(0,12,6,12);line(19,25,19,31);line(0,10,6,10);line(21,25,21,31);line(0,8,6,8);line(23,25,23,31);line(0,6,4,6);line(25,27,25,31);line(4,2,14,2);line(29,17,29,27);line(6,0,6,6);line(25,25,31,25);line(8,0,8,5);line(26,23,31,23);line(10,0,10,4);line(27,21,31,21);line(12,1,12,3);line(28,19,30,19);stroke(0,255,128);line(5,8,5,26);line(5,26,23,26);line(7,11,7,20);line(12,24,20,24);line(9,14,9,24);line(8,22,17,22);line(11,17,11,24);line(8,20,14,20);point(2,4);point(4,2);point(29,27);point(27,29);stroke(255,0,0);line(21,1,27,1);line(30,4,30,10);line(26,1,26,3);line(28,5,30,5);line(23,3,26,3);line(28,5,28,8);point(24,4);point(27,7);this.images[3]=get(0,0,32,32);background(0,0,0,0);noStroke();fill(255,0,0);rect(0,24,8,8);rect(28,0,4,4);fill(255,0,255);rect(0,20,4,4);rect(8,28,4,4);rect(0,0,5,5);rect(27,27,5,5);fill(0,255,128);rect(4,20,4,4);rect(8,24,4,4);rect(1,1,3,3);rect(28,28,3,3);stroke(255,0,255);line(2,4,2,20);line(12,29,27,29);line(0,18,10,18);line(13,21,13,31);line(0,16,11,16);line(15,20,15,31);line(0,14,9,14);line(17,22,17,31);line(0,12,8,12);line(19,23,19,31);line(0,10,8,10);line(21,23,21,31);line(0,8,8,8);line(23,23,23,31);line(0,6,4,6);line(25,27,25,31);line(4,2,25,2);line(29,6,29,27);line(6,0,6,6);line(25,25,31,25);line(8,0,8,6);line(25,23,31,23);line(10,0,10,8);line(23,21,31,21);line(12,0,12,7);line(24,19,31,19);line(14,0,14,6);line(25,17,31,17);line(16,0,16,5);line(26,15,31,15);line(18,1,18,5);line(26,13,30,13);line(20,1,20,3);line(28,11,30,11);stroke(0,255,128);line(5,8,5,26);line(5,26,23,26);line(7,11,7,20);line(12,24,20,24);line(9,14,9,24);line(8,22,17,22);line(11,17,11,24);line(8,20,14,20);line(2,4,2,7);line(4,2,10,2);line(29,21,29,27);line(24,29,27,29);line(2,7,5,7);line(24,26,24,29);stroke(255,0,0);line(19,1,27,1);line(30,4,30,12);line(26,1,26,3);line(28,5,30,5);line(21,3,26,3);line(28,5,28,10);line(24,4,24,5);line(26,7,27,7);line(20,5,25,5);line(26,6,26,11);point(25,6);this.images[4]=get(0,0,32,32);
};
g_ReefData=new Reef_Data();
g_ReefData.make_images();
} //Reef_Data
{
//BT_IRS buildings need extra data, which is associated with one of these objects
var IRS_Data = function()
{
//0=not built,1=standard(speed 1.0),2=fast(speed 1.5, variable capacity bonus)
this.engineType = 0;
//int in range [0,100] that reperesents the condition as a percentage
this.engineCondition = 100;
//Type of rescue pod built here
//0=not built,1=small (15 people),2=large (32 people),3=lightweight (38 people, fuel discount)
this.rescuePodType = 0;
//If true, the pod already has resources put in it (food, fuel)
this.stocked = false;
//Total number of days the last round trip took:
this.totalRoundTripTime = -1;
//Number of days until the rescue pod returns; -1 = not launched yet
this.timeUntilReturn = -1;
this.capacityAtLaunch=0;
this.launchedThisTurn=false;
this.openTab=1;
this.returnReport=false;
this.returnReportDamageSustained=0;
this.returnReportPeopleSaved=0;
this.resourceCapacityAtLaunch=0;
//0=mana,1=stone,2=gadolinium,3=dark energy
this.resourceType=0;
this.level=1;
};
IRS_Data.prototype.get_engine_type_as_string=function(){
switch(this.engineType){case 0:return"not built";case 1:return"standard";case 2:return"fast";default:return"unknown";}};
//Hyperspeed affects travel time. Engine condition must be >= 30% to work.
IRS_Data.prototype.get_engine_hyperspeed=function(){
if(this.engineCondition<30){return 0;}switch(this.engineType){case 1:return 1*sqrt(0.01*this.engineCondition)*(this.level>4?1.5:1);case 2:return 1.5*pow((this.engineCondition-29)/71,1.5)*(this.level>4?1.5:1);default:return 0;}};
IRS_Data.prototype.get_rescue_pod_type_as_string=function(){
switch(this.rescuePodType){case 0:return"not built";case 1:return"small";case 2:return"large";case 3:return"lightweight";default:return"unknown";}};
//Having Wi-Fi increases this by 1:
IRS_Data.prototype.get_rescue_pod_base_capacity=function(){
var b=g_Diplomacy.get_is_wifi_active()+10*(this.level>4);switch(this.rescuePodType){case 1:return 15+b;case 2:return 32+b;case 3:return 38+b;default:return 0;}};
IRS_Data.prototype.get_rescue_pod_fuel_multi=function(){
if(this.rescuePodType===3){return 0.6+0.4/(1+exp(0.3*(g_Factors.get_swamp_factor()-4)));}return 1;};
IRS_Data.prototype.get_fuel_discount_explanation=function(){
if(this.rescuePodType===3){return"Based on swamp factor";}return"No discount";};
//Different engine types can multiply rescue pod capacity without affecting the
//amount of food or spice needed as supplies:
IRS_Data.prototype.get_engine_capacity_multi=function(){
if(this.engineType===2){return 2*(1-exp(-max(0.2*g_Factors.get_desert_factor(),0)))+1;}return 1;};
IRS_Data.prototype.get_engine_capacity_explanation=function(){
if(this.engineType===2){return"Based on desert factor";}return"No bonus";};
//Amount of iron needed to repair the engine by 10%:
IRS_Data.prototype.get_repair_iron_cost=function(){
switch(this.engineType){case 1:return 10;case 2:return 50;default:return 0;}};
//Amount of mithril needed to repair the engine by 10%:
IRS_Data.prototype.get_repair_mithril_cost=function(){
switch(this.engineType){case 1:return 10;case 2:return 100;default:return 0;}};
IRS_Data.prototype.get_rescue_pod_final_capacity=function(){
return floor(this.get_rescue_pod_base_capacity()*this.get_engine_capacity_multi()*foodColoringMulti*(1+g_TechnologyManager.by_name("Double-Capacity Pods").researched));};
IRS_Data.prototype.get_is_ready_for_launch=function(){
return this.engineType>0&&this.engineCondition>=30&&this.rescuePodType>0&&this.stocked&&!this.returnReport&&this.timeUntilReturn===-1;};
IRS_Data.prototype.get_status_as_string=function(){
if(this.returnReport){return"rescue pod has returned";}if(this.timeUntilReturn>-1){return"waiting for rescue pod to return";}if(this.engineType===0){return"ready to assemble engine";}if(this.engineCondition<30){return"engine is nonfunctional";}if(this.rescuePodType===0){return"ready to construct rescue pod";}if(this.stocked){return"ready for launch";}return"ready to stock with resources";};
IRS_Data.prototype.on_day_end=function(){
this.launchedThisTurn=!1;if(this.timeUntilReturn<0){if((this.level>4)&&this.engineCondition<100){this.engineCondition+=1;}}else{var a=g_PersistentData.get_upgrade_times_purchased("PA");this.timeUntilReturn-=1;if(random(0,10)<5-2*a&&this.engineCondition>1){this.engineCondition-=1;this.returnReportDamageSustained+=1;if(this.engineType===2&&random(0,10)<2-a&&this.engineCondition>5){this.engineCondition-=(a?1:5);this.returnReportDamageSustained+=(a?1:5);}}}if(this.timeUntilReturn===0){if(this.resourceCapacityAtLaunch>0){this.resourceType=floor(random(3.9));if(this.resourceType<2){this.resourceCapacityAtLaunch*=5;}var r=this.resourceCapacityAtLaunch;switch(this.resourceType){case 0:manaResource+=r;break;case 1:stoneResource+=r;break;case 2:gadoliniumResource+=r;break;default:darkEnergyResource+=r;totalDarkEnergyGained+=r;}}this.timeUntilReturn=-1;this.stocked=!1;this.returnReport=!0;this.returnReportPeopleSaved=this.capacityAtLaunch;evacuees+=this.returnReportPeopleSaved;}};
//Returns the number of days a round trip will take or 0 if infinite time:
//Travel takes 10 days if hyperspeed is 1.000.
IRS_Data.prototype.get_estimated_round_trip_time=function(){
var h=this.get_engine_hyperspeed();if(h>0){return round(10/h);}return 0;};
//Returns the amount of supplies needed to stock the pod:
IRS_Data.prototype.get_supplies_dark_energy_cost=function(){
var m=this.get_rescue_pod_fuel_multi()*darkEnergyFuelMultiFromFancyGlove*darkEnergyProductionMultiFromFrosthour*foodColoringMulti;switch(this.engineType){case 1:return 100*m;case 2:return 600*m;default:return 0;}};
IRS_Data.prototype.get_supplies_dark_energy_cost_string=function(){
var c=this.get_supplies_dark_energy_cost();if(Number.isInteger(c)){return c;}return c.toFixed( 3 );};
IRS_Data.prototype.get_supplies_food_cost=function(){
return 5*this.get_rescue_pod_base_capacity();};
IRS_Data.prototype.get_supplies_spice_cost=function(){
return 2*this.get_rescue_pod_base_capacity();};
IRS_Data.prototype.get_indicator_light_color=function(){
if(this.engineType===0||this.rescuePodType===0){return color(0,0,0);}if(this.timeUntilReturn>-1){return color(0,255,0);}if(this.engineCondition<30){if(globalCyclicAnimation%30<15){return color(255,0,0);}return color(128,0,0);}if(!this.stocked){if(globalCyclicAnimation%30<15){return color(0,128,255);}return color(0,64,128);}if(globalCyclicAnimation%60<30){return color(0,128,255);}return color(0,64,128);};
} //IRS_Data
{
//For more info, see old file versions:
var draw_lava_freezer_circle=function(x,y,c,s,f){
if(f){noFill();stroke(c);var X=s*4*sin(8*globalCyclicAnimation),Y=s*4*cos(8*globalCyclicAnimation);line(x+X,y+Y,x-X,y-Y);line(x+Y,y-X,x-Y,y+X);}else{noStroke();fill(c);ellipse(x,y,8*s,8*s);}};
var Building=function(tI,t){
this.tileIndex=tI;this.buildingType=t;this.resourceProduction=0;this.upgradeLevel=1;this.destroyed=!1;if(this.buildingType===BT_IRS){allIRSDatas.push(new IRS_Data());this.resourceProduction=allIRSDatas.length-1;}if(this.buildingType===BT_MER_MALL&&g_PersistentData.currentChallenge==="URC"){this.upgradeLevel=3;this.destroyed=!0;}if(this.buildingType===BT_UNDERWATER_RUINS){var T=allTiles[this.tileIndex].tier;this.destroyed=!0;this.upgradeLevel=constrain(floor(random(T>=2?1.8+0.1*T:1,1+2*T)),1,5);}};
Building.prototype.draw=function(){
this.draw_at(allTiles[this.tileIndex].x-cameraX,allTiles[this.tileIndex].y-cameraY);};
Building.prototype.draw_at = function(x,y)
{
if(x<-16||(x>width+16&&this.buildingType!==BT_IRS)||y<-16||y>height+16||!this.visible_in_current_side()||!allTiles[this.tileIndex].claimed){return;}
switch(this.buildingType)
{
case BT_HOUSE:switch(this.upgradeLevel){case 1:noStroke();fill(128,64,0);rect(x-8,y-8,8,8);stroke(192,160,128);line(x-8,y-8,x-2,y-8);line(x-8,y-8,x-8,y-1);stroke(64,32,0);line(x-1,y-8,x-1,y-1);line(x-7,y-1,x-1,y-1);break;case 2:noStroke();fill(128,64,0);rect(x-8,y-8,8,16);stroke(192,160,128);line(x-8,y-8,x-2,y-8);line(x-8,y-8,x-8,y+7);stroke(64,32,0);line(x-1,y-8,x-1,y+7);line(x-7,y+7,x-1,y+7);break;case 3:noStroke();fill(128,64,0);rect(x-8,y-8,16,16);stroke(192,160,128);line(x-8,y-8,x+6,y-8);line(x-8,y-8,x-8,y+7);stroke(64,32,0);line(x+7,y-8,x+7,y+7);line(x-7,y+7,x+7,y+7);break;case 4:noStroke();fill(0,64,128);rect(x-8,y-8,16,16);stroke(128,160,192);line(x-8,y-8,x+6,y-8);line(x-8,y-8,x-8,y+7);stroke(0,32,64);line(x+7,y-8,x+7,y+7);line(x-7,y+7,x+7,y+7);break;default:noStroke();fill(128,64,0);rect(x+8,y-4,5,8);rect(x-12,y-12,8,14);stroke(192,160,128);line(x+8,y-4,x+11,y-4);line(x-12,y-12,x-6,y-12);line(x-12,y-12,x-12,y+1);stroke(64,32,0);line(x+12,y-4,x+12,y+3);line(x+8,y+3,x+12,y+3);line(x-5,y-12,x-5,y+1);line(x-11,y+1,x-5,y+1);noStroke();fill(0,64,128);rect(x-8,y-8,16,16);stroke(128,160,192);line(x-8,y-8,x+6,y-8);line(x-8,y-8,x-8,y+7);stroke(0,32,64);line(x+7,y-8,x+7,y+7);line(x-7,y+7,x+7,y+7);stroke(0,0,0);fill(160,160,160);rect(x-2,y-2,4,4);if(season===4){noStroke();fill(255,255,0,32);for(var i=3;i<16;i+=1){rect(x-3,y-i,6,2*i);rect(x-i,y-3,2*i,6);}}}if(allSpells.by_name("Insta-Grow").durationLeft>0&¤tScreen!=="max-house-cutscene"){noStroke();fill(allSpells.insta_grow_color());ellipse(x-12,y-12,4,4);}break;
case BT_FARM:noStroke();if(this.destroyed){fill(255,192,0);triangle(x-8,y-8,x+4,y-8,x-8,y+8);triangle(x+8,y-8,x+4,y+8,x+8,y+8);if(this.upgradeLevel>2){fill(128,40,40);rect(x-3,y-5,2,6);if(this.upgradeLevel>4){rect(x+5,y-7,2,6);}}}else{fill(128,255,0);rect(x-8,y-8,16,16);if(this.upgradeLevel>2){fill(255,0,0);rect(x-4,y-8,4,12);if(this.upgradeLevel>4){rect(x+4,y-8,4,12);}}}if(this.upgradeLevel>1){fill(255,255,0);rect(x-8,y-8,4,16);if(this.upgradeLevel>3){rect(x,y-8,4,16);}}if(season===4){fill(240,240,240,192);rect(x-8,y-8,16,16);}if(!this.destroyed&&allSpells.by_name("Insta-Grow").durationLeft>0){fill(allSpells.insta_grow_color());rect(x-8,y-8,16,16);}break;
case BT_COLLECTOR:stroke(32);fill(allBuildings.collector_color(this.upgradeLevel));ellipse(x+8,y-8,8,8);if(g_TechnologyManager.camel_technology_by_name("Swarm Interference").researched&&daysUntilSwarmArrival<=10){noFill();stroke(0);ellipse(x+8,y-8,8*abs(sin(globalCyclicAnimation*8)),8*abs(sin(globalCyclicAnimation*8)));}break;
case BT_MINE:noStroke();if(this.upgradeLevel<4){fill(128,96,64);ellipse(x,y,16-2*(this.upgradeLevel===1),16-2*(this.upgradeLevel===1));if(this.upgradeLevel>1){fill(red(FRONTSIDE_VOID_COLOR),green(FRONTSIDE_VOID_COLOR),blue(FRONTSIDE_VOID_COLOR),32);ellipse(x,y,12,12);if(this.upgradeLevel>2){ellipse(x,y,10,10);}}}else{fill(FRONTSIDE_VOID_COLOR);ellipse(x,y,16,16);if(this.upgradeLevel>4){noFill();stroke(255,0,0);ellipse(x,y,12,12);noStroke();}}if(allTiles[this.tileIndex].tileType===TT_LAKE){if(season===4){fill(96,180,255,180);}else{fill(0,128,255,180);}ellipse(x,y,16,16);}if(this.upgradeLevel>1&&allSpells.by_name("Stonemover").durationLeft>0){fill(255,0,255);for(var i=0;i<12;i+=1){ellipse(x+smgfxx[i],y+smgfxy[i],2,2);}}break;
case BT_MER_MALL:noStroke();fill(224,224,64);var d=4*this.upgradeLevel;if(this.destroyed){arc(x,y,d,d,12,90);arc(x,y+2,d,d,90,148);arc(x,y,d,d,177,352);}else{ellipse(x,y,d,d);if(this.upgradeLevel>3){if(season===4){fill(255,255,255);}else{fill(0,192,0);}ellipse(x-1,y+1,d-12,d-12);ellipse(x+1,y-1,d-12,d-12);}}break;
case BT_ENCHANTING_TABLE:noStroke();fill(64,0,64,season===4?128:255);rect(x-16,y-16,8,8);switch(this.upgradeLevel){case 1:fill(255,0,255);break;case 2:fill(255,192,255);break;case 3:fill(0,255,255);break;case 4:fill(0,255,96);break;default:fill(255,255,255);}if(this.upgradeLevel<4){ellipse(x-12,y-12,4,4);}else{quad(x-16,y-12,x-12,y-16,x-8,y-12,x-12,y-8);}break;
case BT_FURNACE:stroke(0);if(this.upgradeLevel>4){fill(0);}else{fill(255,224,0);}rect(x-16,y,4,4);if(this.upgradeLevel>1){rect(x-16,y-6,4,4);}if(this.upgradeLevel>2){rect(x-10,y,4,4);}if(this.upgradeLevel>3){rect(x-10,y-6,4,4);}break;
case BT_TERRAFORMER:case BT_BACKSIDE_TERRAFORMER:var c=allBuildings.terraformer_color(this.upgradeLevel);if(g_ArtifactManager.by_abbreviation("R").active&&allSpells.by_name("Insta-Grow").durationLeft>0){c=blendColor(c,allSpells.insta_grow_color(),BLEND);}noStroke();fill(c);triangle(x+16,y+5,x+16,y+16,x+5,y+16);stroke(c);line(x,y,x+12,y+12);line(x+2,y-2,x+14,y+10);line(x-2,y+2,x+10,y+14);break;
case BT_REEF:tint(255,255,255,season===4?96:255);image(g_ReefData.images[this.upgradeLevel-1],x,y);tint(255,255,255,255);break;
case BT_SHELTER:noStroke();if(this.upgradeLevel>=3){stroke(255*(this.upgradeLevel>4),255*(this.upgradeLevel===4),255*(this.upgradeLevel<5));}fill(160,160,160);rect(x-16,y+4,24,12,3);if(this.upgradeLevel>=2){fill(192,192,192);rect(x-12,y+6,12,8,4);}if(season===4){noStroke();fill(224,224,224);rect(x-14,y+6,20,8,3);}break;
case BT_IRS:
if((currentScreen==="main"||currentScreen==="main-info")&&(allIRSDatas[this.resourceProduction].launchedThisTurn||allIRSDatas[this.resourceProduction].timeUntilReturn===1)){for(var i=y-6;i<y+6;i+=1){stroke(random(0,255),random(0,255),random(0,255));line(0,i,x-32,i);}}noStroke();var col1,col2,chCol;
switch(this.upgradeLevel){case 1:col1=color(255,0,0);col2=color(192,0,0);chCol=color(230+25*gcaS,0,80+80*gcaC);break;case 2:col1=color(255,255,0);col2=color(192,192,0);chCol=color(230+25*gcaS,200+55*gcaS,50+50*gcaC);break;case 3:col1=color(0,255,96);col2=color(0,192,72);chCol=color(25+25*gcaS,230+25*gcaS,90+90*gcaC);break;case 4:col1=color(224,0,255);col2=color(160,0,128);chCol=color(150+70*gcaS,60+60*gcaC,170+60*gcaS);break;default:col1=color(208,208,208);col2=color(224,224,224);chCol=color(223+32*gcaS,223+32*gcaC,223-32*gcaS);}if(currentScreen==="main"||currentScreen==="main-info"||currentScreen==="IRS"){fill(col1);rect(x-24,y-16,40,8);ellipse(x-24,y-12,8,8);arc(x+6,y+8,24,16,90,180);fill(chCol);quad(x-8,y,x-8,y+8,x-24,y+4,x-24,y-4);fill(col2);rect(x-8,y-16,16,24);arc(x-32,y,24,24,-90,90);rect(x-36,y-1,4,2);}else{fill(col1);rect(x-16,y-16,32,8);arc(x+6,y+8,24,16,90,180);fill(chCol);quad(x-8,y,x-8,y+8,x-16,y+6,x-16,y-2);fill(col2);rect(x-8,y-16,16,24);}stroke(64,64,64);fill(allIRSDatas[this.resourceProduction].get_indicator_light_color());ellipse(x,y,6,6);break;
case BT_MITHRIL_MINE:noStroke();if(this.upgradeLevel<4){fill(128,96,64);ellipse(x,y,16-2*(this.upgradeLevel===1),16-2*(this.upgradeLevel===1));if(this.upgradeLevel>1){fill(red(BACKSIDE_VOID_COLOR),green(BACKSIDE_VOID_COLOR),blue(BACKSIDE_VOID_COLOR),32);ellipse(x,y,12,12);if(this.upgradeLevel>2){ellipse(x,y,10,10);}}}else{fill(BACKSIDE_VOID_COLOR);ellipse(x,y,16,16);if(this.upgradeLevel>4){noFill();stroke(255,0,0);ellipse(x,y,12,12);noStroke();}}if(allTiles[this.tileIndex].backsideTileType===TT_CYBERMIND){noFill();stroke(255,0,0);arc(x+0.5,y+0.5,3,3,0,120);stroke(0,255,0);arc(x+0.5,y+0.5,9,9,120,240);stroke(0,0,255);arc(x+0.5,y+0.5,6,6,240,360);}break;
case BT_LAVA_FREEZER:{var l=(allTiles[this.tileIndex].backsideTileType===TT_LAVA),col=allBuildings.collector_color(this.upgradeLevel);noStroke();fill(128,96,80);if(l){rect(x-8,y-8,16,16);draw_lava_freezer_circle(x-4,y-4,col,1,this.destroyed);draw_lava_freezer_circle(x+4,y+4,col,1,this.destroyed);draw_lava_freezer_circle(x+4,y-4,col,1,this.destroyed);draw_lava_freezer_circle(x-4,y+4,col,1,this.destroyed);}else{rect(x-16,y-16,24,8);rect(x-16,y-16,8,16);draw_lava_freezer_circle(x-12,y-12,col,1,this.destroyed);draw_lava_freezer_circle(x+4,y-12,col,1,this.destroyed);draw_lava_freezer_circle(x-4,y-12,col,1,this.destroyed);draw_lava_freezer_circle(x-12,y-4,col,1,this.destroyed);}if(this.destroyed||!l){break;}if(allSpells.by_name("Mineral Enrichment").durationLeft>0){fill(0,128,255);var dg=globalCyclicAnimation*3;for(var th=0;th<360;th+=40){var cx=x+12*cos(th+dg),cy=y+12*sin(th+dg);triangle(cx-2,cy-sqrt(3),cx+2,cy-sqrt(3),cx,cy+sqrt(3));}}else if(g_ToggleButtonManager.lavaFreezerToggle&&allSpells.by_name("Stonemover" ).durationLeft>0){fill(0,128,255);for(var i=0;i<12;i+=1){ellipse(x+smgfxx[i],y+smgfxy[i],2,2);}}}break;
case BT_UNDERWATER_RUINS:noStroke();if(season===4){fill(115,176,233);}else{fill(134,172,210);}switch(this.upgradeLevel){case 1:quad(x-4,y-5,x+3,y-5,x+5,y+4,x-3,y+6);break;case 2:ellipse(x-4,y-4,7,9);ellipse(x+6,y+2,10,8);rect(x-4,y-4,4,4);break;case 3:rect(x-6,y-6,12,8,2);triangle(x-9,y+4,x+6,y+2,x+1,y+6);triangle(x-3,y-6,x+2,y-15,x+3,y-8);break;case 4:arc(x,y,8,8,-74,234);quad(x-16,y-12,x+2,y-15,x+1,y-10,x-14,y-9);quad(x-4,y+4,x+4,y+7,x+3,y+14,x-6,y+15);break;case 5:quad(x-16,y-16,x-8,y-16,x-6,y-4,x-14,y-8);quad(x-2,y+1,x+8,y,x+9,y+7,x,y+9);stroke(134,172,210);line(x-6,y-4,x,y-1);line(x-14,y+15,x-2,y+9);break;}break;}
};
Building.prototype.type_as_string=function(){
var s="";switch(this.buildingType){case BT_HOUSE:s="your house";break;case BT_FARM:s="farm";break;case BT_COLLECTOR:s="collector";break;case BT_MINE:case BT_MITHRIL_MINE:s="mine";break;case BT_MER_MALL:s="mer mall";break;case BT_ENCHANTING_TABLE:s="ench. table";break;case BT_FURNACE:s="furnace";break;case BT_TERRAFORMER:case BT_BACKSIDE_TERRAFORMER:s="terraformer";break;case BT_REEF:s=g_Diplomacy.merfolkStanding>3?"reef":"???";break;case BT_SHELTER:s="shelter";break;case BT_IRS:s="IRS";break;case BT_LAVA_FREEZER:s=this.destroyed?"cooling fan":"lava freezer";break;case BT_UNDERWATER_RUINS:s="ruins";break;default:s="unknown";}if(this.upgradeLevel>1){s+=" lvl. "+this.upgradeLevel;}return s;};
Building.prototype.get_description = function()
{
var t=allTiles[this.tileIndex].tileType,T=allTiles[this.tileIndex].backsideTileType;
switch(this.buildingType)
{case BT_HOUSE:return season===4?"manipulates seasons":(g_TechnologyManager.get_completion_ratio()<1?"do research here":"where you live");
case BT_FARM:if(this.destroyed){return"crops were all eaten";}return"+"+g_ResourcePane.formatSI(this.resourceProduction)+" food per day";
case BT_COLLECTOR:if(g_TechnologyManager.camel_technology_by_name("Swarm Interference").researched&&daysUntilSwarmArrival<=10){return"-70% swarm chance";}return"+"+g_ResourcePane.formatSI(this.resourceProduction)+" mana per day";
case BT_MINE:if(this.upgradeLevel<2){return t===TT_LAKE?"can't do anything":"manually mine stone";}return"+"+g_ResourcePane.formatSI(this.resourceProduction)+" stone per day";
case BT_MER_MALL:if(this.destroyed){return"has fallen to ruin";}return"unlocks diplomacy";
case BT_REEF:return g_Diplomacy.merfolkStanding>3?"various bonuses":"";
case BT_ENCHANTING_TABLE:return t===TT_SLIMED?"too slimy to use":"unlocks enchanting";
case BT_FURNACE:if(!g_ToggleButtonManager.furnaceToggle){return"turned off";}if(t===TT_SLIMED){return"too slimy to work";}if(!g_ResourcePane.flameOrbVisible){return"no fuel";}return"smelts stone → iron";
case BT_TERRAFORMER:if(t===TT_SLIMED){return"too slimy to use";}return"can change tile types";case BT_BACKSIDE_TERRAFORMER:return "can change tile types";
case BT_SHELTER:return "+"+(25*pow(2,this.upgradeLevel)+g_Diplomacy.get_is_wifi_active())+" max evacuees";
case BT_IRS:return"rescues evacuees";
case BT_MITHRIL_MINE:if(g_ToggleButtonManager.mithrilMineToggle){return"+"+g_ResourcePane.formatSI(this.resourceProduction)+" mithril per day";}return"turned off";
case BT_LAVA_FREEZER:if(this.destroyed){return"- pearl consumption";}if(T!==TT_LAVA){return"no lava to freeze";}if(g_ToggleButtonManager.lavaFreezerToggle){return"+"+this.resourceProduction+" "+(allSpells.by_name("Mineral Enrichment").durationLeft>0?"iron":"stone")+"/day";}return "+"+this.resourceProduction+" "+(allSpells.by_name("Mineral Enrichment").durationLeft>0?"gadolinium":"flame orb")+"/day";
case BT_UNDERWATER_RUINS:return"explore to find stuff";
default:return"this is a bug";
}
};
Building.prototype.visible_in_current_side=function(){
switch(this.buildingType){case BT_HOUSE:return!0;case BT_FARM:case BT_COLLECTOR:case BT_MINE:case BT_MER_MALL:case BT_ENCHANTING_TABLE:case BT_FURNACE:case BT_TERRAFORMER:case BT_SHELTER:case BT_IRS:return !currentlyInBackside;case BT_REEF:if(!g_PersistentData.get_is_reef_unlocked()){return!1;}return g_Diplomacy.merfolkStanding>3&&!currentlyInBackside;case BT_UNDERWATER_RUINS:return g_Diplomacy.merfolkStanding>3&&!currentlyInBackside;case BT_MITHRIL_MINE:case BT_LAVA_FREEZER:case BT_BACKSIDE_TERRAFORMER:return currentlyInBackside;default:return!1;}};
allBuildings.terraformer_color=function(l){
switch(l){case 1:return color(0,80,128);case 2:return color(96,0,128);case 3:return color(224,182,0);case 4:return color(240,128,224);default:return color(255,255,255);}};
allBuildings.collector_color=function(l){
switch(l){case 1:return color(255,128,255);case 2:return color(255,255,255);case 3:return color(0,255,0);case 4:return color(0,255,255);default:return color(128,32,255);}};
allBuildings.get_mer_mall_level=function(){
if(allBuildings.length>=2&&allBuildings[1].buildingType===BT_MER_MALL){return allBuildings[1].upgradeLevel;}return 0;};
allBuildings.get_reef_level=function(){
if(allBuildings.length>=3&&allBuildings[2].buildingType===BT_REEF){return allBuildings[2].upgradeLevel;}return 0;};
allBuildings.count_cooling_fans=function(){
var c=0;allBuildings.forEach(function(b){c+=(b.buildingType===BT_LAVA_FREEZER&&b.destroyed);});return c;};
allBuildings.count_level_5=function(){
var c=0;allBuildings.forEach(function(b){c+=b.upgradeLevel===5;});return c;};
allBuildings.count_of_type=function(T,l){
l=l||0;var c=0;allBuildings.forEach(function(b){c+=(b.buildingType===T&&b.upgradeLevel>=l);});return c;};
var can_build_mine_lvl_4=function(){
return selectedTile>-1&&allSpells.by_name("Dark Attunement").durationLeft>0&&allTiles[selectedTile].hasDarkEnergy;};
var can_build_furnace_lvl_4=function(){return allBuildings.count_of_type(BT_IRS,3)>0;};
var can_build_furnace_lvl_5=function(){return selectedTile>-1&&allSpells.by_name("Dark Attunement").durationLeft>0&&allTiles[selectedTile].hasDarkEnergy;};
var can_build_IRS_lvl_4=function(){
var c=g_ArtifactManager.count_discovered();if(c>1){return!0;}if(c<1){return!1;}return g_ArtifactManager.by_abbreviation("CPU").level===0;};
allBuildings.get_tile_has=function(I,t){
for(var i=0;i<allTiles[I].buildings.length;i+=1){if(allBuildings[allTiles[I].buildings[i]].buildingType===t){return!0;}}return!1;};
building_on_tile=function(I,t){
for(var i=0;i<allTiles[I].buildings.length;i+=1){if(allBuildings[allTiles[I].buildings[i]].buildingType===t){return allTiles[I].buildings[i];}}return-1;};
var building_level_on_tile=function(I,t){
for(var i=0;i<allTiles[I].buildings.length;i+=1){if(allBuildings[allTiles[I].buildings[i]].buildingType===t){return allBuildings[allTiles[I].buildings[i]].upgradeLevel;}}return 0;};
allBuildings.build=function(i,t){
allBuildings.push(new Building(i,t));allTiles[i].buildings.push(allBuildings.length-1);recalculate_building_effects();};
var mithril_mine_on_tile=function(tI){
for(var i=0;i<allTiles[tI].buildings.length;i+=1){if(allBuildings[allTiles[tI].buildings[i]].buildingType===BT_MITHRIL_MINE){return allTiles[tI].buildings[i];}}return-1;};
var cooling_fan_on_tile=function(tI){
for(var i=0;i<allTiles[tI].buildings.length;i+=1){if(allBuildings[allTiles[tI].buildings[i]].buildingType===BT_LAVA_FREEZER&&allBuildings[allTiles[tI].buildings[i]].destroyed){return allTiles[tI].buildings[i];}}return-1;};
var farm_production_winter=function(l){
switch(l){case 1:return 0.01;case 2:return 0.03;case 3:return 0.07;case 4:return 0.12;default:return 0.14;}};
var farm_production_nonwinter=function(l){
switch(l){case 1:return 0.1;case 2:return 0.15;case 3:return 0.25;case 4:return 0.40;default:return 0.44;}};
var furnace_stone_consumption=function(l){return l<3?2:1.8;};
var furnace_flame_orb_consumption_summer=function(l){
switch(l){case 1:return 1;case 2:return 1.1;case 3:return 1.3;case 4:return 1.6;default:return 0;}};
var furnace_flame_orb_consumption_nonsummer=function(l){
switch(l){case 1:return 1;case 2:return 1.2;case 3:return 1.5;case 4:return 1.9;default:return 0;}};
var furnace_flame_orb_consumption=function(l){
return(season===1)?furnace_flame_orb_consumption_summer(l):furnace_flame_orb_consumption_nonsummer(l);};
var furnace_iron_production=function(l){return 0.3+min(0.7*l,3.2)+0.2*(l>=3)+0.4*(g_PersistentData.currentChallenge==="UCC");};
var mithril_mine_iron_consumption=function(l){
switch(l){case 1:return 0.8;case 2:return 1;case 5:return 1.2;default:return 1.4;}};
var manual_mining_min_stone=function(l){
return 1+g_PersistentData.get_challenge_times_completed("UR")+(l>=3);};
var manual_mining_max_stone=function(l){
return 5+g_PersistentData.get_challenge_times_completed("UR")+10*(l===5)+(l>=3);};
var mithril_mine_TT_multi=function(t){
if(t===TT_MITHRIL){return 1;}if(t===TT_WASTELAND){return 0.5;}return 0.1;};
var mithril_mine_deTT_multi=function(t){
if(t===TT_WASTELAND){return 1.2;}return 1;};
var lava_freezer_pearl_consumption=function(l){return max(2,3.5-0.5*l);};
var lava_freezer_flame_orb_production=function(l){
switch(l){case 1:return 10;case 2:return 15;case 3:return 21;case 4:return 25;default:return 29;}};
var lava_freezer_stone_production=function(l){
return 2*lava_freezer_flame_orb_production(l);};
//Has no cost to the player:
var upgrade_all_terraformers_to_level=function(l){
for(var i=0;i<allBuildings.length;i+=1){if(allBuildings[i].buildingType===BT_TERRAFORMER||allBuildings[i].buildingType===BT_BACKSIDE_TERRAFORMER){allBuildings[i].upgradeLevel=max(allBuildings[i].upgradeLevel,l);}}};
var can_afford_collector_upgrade=function(l)
{
switch(l)
{
case 1:return pearlResource>=5&&stoneResource>=5;
case 2:return gadoliniumResource>=1.25&&stoneResource>=6.5;
case 3:return stoneResource>=500&&mithrilResource>=20;
case 4:return darkEnergyResource>=30;
default:return!1;
}
};
var pay_collector_upgrade_cost=function(l)
{
switch(l)
{
case 1:pearlResource-=5;stoneResource-=5;break;
case 2:gadoliniumResource-=1.25;stoneResource-=6.5;break;
case 3:stoneResource-=500;mithrilResource-=20;break;
case 4:darkEnergyResource-=30;break;
}
};
var food_cost_to_manual_mine=function(){
return(g_PersistentData.currentChallenge==="5FC")?max(3,g_PersistentData.get_challenge_times_completed("5F")+1):3;};
var farm_bio_orb_cost_multi=function(){
if(g_TechnologyManager.by_name("Spontaneous Growth").researched){var f=g_Factors.get_plains_factor();return f<=0?1:pow(0.7,0.35*f+1)+0.3;}return 1;};
var setup_start_funcs=function(){
var UCCStartFunc=function(x){var fs=g_TechnologyManager.by_name("Furnace Synergy");fs.description="Does nothing in a UCC";fs.conditionString="free";fs.unlockCondition=function(){return allBuildings.count_of_type(BT_FURNACE)>0;};fs.purchaseCondition=true_func;fs.callback=null_func;g_Diplomacy.cameltechCostMulti=1+0.5*x;};
var StartFunc5FC=function(x){var t=g_TechnologyManager.by_name("Genetic Engineering"),s=g_TechnologyManager.by_name("Spontaneous Growth");t.description="Does nothing in a 5FC";t.conditionString="free";t.unlockCondition=function(){return g_ResourcePane.goldenAppleVisible&&allBuildings.count_of_type(BT_FARM,3);};t.purchaseCondition=true_func;t.callback=null_func;s.conditionString="costs 5 spice, 10 stone";s.purchaseCondition=function(){return spiceResource>=5&&stoneResource>=10;};s.callback=function(){spiceResource-=5;stoneResource-=10;};};
for(var i=0;i<g_PersistentData.challengesList.length;i+=1){switch(g_PersistentData.challengesList[i].abbreviation){case"UC":g_PersistentData.challengesList[i].startRunFunc=UCCStartFunc;break;case"5F":g_PersistentData.challengesList[i].startRunFunc=StartFunc5FC;break;}}};
setup_start_funcs();
} //Building
{
//See past versions of this file for notes on everything here.
var draw_camel=function(x,y,a){stroke(224,224,64);fill(140,96,0);ellipse(x+8*sin(a),y+10,8,4);ellipse(x+8*sin(a)+(a>=90&&a<270?-6:6),y+10,4,4);};
var Creature=function(s,t,l){
this.tileAt=s;this.creatureType=t;this.animation=0;this.markedForDestruction=!1;this.daysToLive=l;if(this.creatureType===CT_FISH||this.creatureType===CT_SLIME||this.creatureType===CT_SPARK){this.animation=floor(random(360));}};
Creature.prototype.visible_in_current_side=function(){
switch(this.creatureType){case CT_TURTLE:case CT_COSMIC:return!0;case CT_DRAGON:return!currentlyInBackside||currentScreen==="end-of-run-cutscene";case CT_SWARM:case CT_BURNING:case CT_FISH:case CT_CAMEL:case CT_SLIME:case CT_TRAIN_HEAD:case CT_TRAIN_BODY:case CT_TRAIN_TAIL:return!currentlyInBackside;case CT_EDGE_FINDER:return!allTiles[this.tileAt].claimed;case CT_SPARK:case CT_FIRE_GIANT:return currentlyInBackside;case CT_DEC_EYE:return allSpells.by_name("Dark Attunement").durationLeft>0;default:return!1;}};
Creature.prototype.draw=function(){
var t=allTiles[this.tileAt];if(this.creatureType!==CT_COSMIC&&!t.revealed){return;}this.draw_at(t.x-cameraX,t.y-cameraY);};
Creature.prototype.draw_at=function(x,y){
var r=(this.creatureType===CT_COSMIC?80:16);if(!this.visible_in_current_side()||x<-r||x>width+r||y<-r||y>height+r){return;}switch(this.creatureType){case CT_SWARM:stroke(0);fill(0);for(var i=0;i<20;i+=1){ellipse(x+random(-14,14),y+random(-14,14),2,2);}break;case CT_DRAGON:stroke(192,0,0);fill(255,0,0);ellipse(x,y,12,6);ellipse(x-7,y,4,4);triangle(x-2,y-1,x-3,y-6,x+1,y-12);triangle(x-2,y,x-3,y+5,x+1,y+11);triangle(x+6,y-1,x+10,y,x+6,y);break;case CT_BURNING:stroke(255,128,0);fill(255,128,0);var mpd=movesPerDay+(g_ArtifactManager.by_abbreviation("GFC").active&&season===1),i=0;for(;i<20*movesLeft/mpd;i+=1){ellipse(x+random(-14,14),y+random(-14,14),2,2);}break;case CT_FISH:noStroke();fill(255,0,0);ellipse(x+8*cos(this.animation),y+8*sin(2*this.animation),4,4);fill(255,64,0);ellipse(x+8*cos(3*this.animation+135),y+8*sin(2*this.animation+90),4,4);this.animation+=1;this.animation%=360;break;case CT_CAMEL:draw_camel(x,y,is_in_cutscene()?0:this.animation);this.animation+=1;this.animation%=360;break;case CT_SLIME:noStroke();var cenX=x+8*cos(this.animation),cenY=y+8*sin(this.animation);fill(32,255,32);quad(cenX-5,cenY,cenX,cenY-5,cenX+5,cenY,cenX,cenY+5);stroke(144,255,144);line(cenX-5,cenY,cenX,cenY-5);stroke(24,128,72);line(cenX,cenY+5,cenX+5,cenY);break;case CT_DEC_EYE:{var dirToC=atan2(mouseY-y,mouseX-x),distToC=min(8,0.1*dist(x,y,mouseX,mouseY));noStroke();fill(0,0,0,64*gcaS+128);ellipse(x,y,30,30);stroke(0);fill(255);ellipse(x+distToC*cos(dirToC),y+distToC*sin(dirToC),4,4);}break;case CT_SPARK:{r=(season===4?1.5:8);var t=this.animation*(season===4?12:1);noStroke();fill(255,255,0);ellipse(x+r*cos(3*t)*cos(t),y+r*cos(3*t)*sin(t),4,4);this.animation+=3;this.animation%=360;}break;
case CT_TRAIN_HEAD:noStroke();fill(255,0,0);rect(x+9,y,5,16);break;case CT_TRAIN_BODY:noStroke();fill(255,0,0);rect(x+9,y-16,5,4);rect(x+9,y-10,5,20);rect(x+9,y+12,5,4);break;case CT_TRAIN_TAIL:noStroke();fill(255,0,0);rect(x+9,y-16,5,16);break;case CT_TURTLE:noStroke();if(currentlyInBackside){fill(224);}else{fill(64,128,64);}ellipse(x,y,20,10);bezier(x+7,y-3,x+17,y-3,x+17,y+3,x+7,y+3);bezier(x+5,y-4,x+5,y-10,x+9,y-12,x+7,y-3);bezier(x+5,y+4,x+5,y+10,x+9,y+12,x+7,y+3);bezier(x-6,y-3,x-6,y-8,x-10,y-7,x-9,y-3);bezier(x-6,y+3,x-6,y+8,x-10,y+7,x-9,y+3);break;case CT_FIRE_GIANT:stroke(128);line(x+2,y-5,x+12,y-5);stroke(80);line(x+3,y-4,x+7,y-4);stroke(205+45*sin(globalCyclicAnimation*3),128,96);fill(192+48*gcaS,0,0);ellipse(x+10,y,6,10);ellipse(x+9,y,4,4);break;case CT_COSMIC:stroke(255);var t=0,l=40+20*gcaC,m=80-l;for(;t<360;t+=36){line(x+10*cos(globalCyclicAnimation+t),y-10*sin(globalCyclicAnimation+t),x+l*cos(globalCyclicAnimation+t),y-l*sin(globalCyclicAnimation+t));line(x+10*cos(globalCyclicAnimation+t),y-10*sin(globalCyclicAnimation+t),x-m*cos(2*globalCyclicAnimation+t),y+m*sin(2*globalCyclicAnimation+t));}noStroke();fill(255,125,0);ellipse(x,y,16,16);break;case CT_EDGE_FINDER:{var dirToC=atan2(mouseY-y,mouseX-x),distToC=min(6,0.1*dist(x,y,mouseX,mouseY)),col=currentlyInBackside?BACKSIDE_VOID_COLOR:FRONTSIDE_VOID_COLOR;noStroke();fill(col,192);bezier(x-14,y,x-6,y-9,x+6,y-9,x+14,y);bezier(x-14,y,x-6,y+9,x+6,y+9,x+14,y);stroke(col);fill(255,125,0);ellipse(x+distToC*cos(dirToC),y+distToC*sin(dirToC)/4,8,8);}break;}};
var tile_random_adjacent=function(o){var d=floor(random(0,4))*90;return tile_at_position(allTiles[o].x+32*cos(d),allTiles[o].y+32*sin(d));};
Creature.prototype.on_day_end=function(){
var nT=-1;if(!g_TechnologyManager.by_name("Dark Chronomancy").researched||allSpells.by_name("Dark Attunement").durationLeft<=0||this.creatureType!==CT_DRAGON){this.daysToLive-=1;}switch(this.creatureType){case CT_SWARM:if(allTiles[this.tileAt].tileType===TT_MAP_EDGE){this.markedForDestruction=!0;break;}if(random(0,10)<8||allTiles[this.tileAt].tileType===TT_LAKE){nT=tile_random_adjacent(this.tileAt);if(nT>-1){this.tileAt=nT;}}var index=building_on_tile(this.tileAt,BT_FARM);if(index>-1){allBuildings[index].destroyed=!0;}if(this.tileAt===selectedTile&&!currentlyInBackside){selectedTile=-1;g_ConstructionManager.on_tile_selected();currentScreen="main";g_Diplomacy.currentlyMeetingWith="noone";}break;
case CT_DRAGON:var duc=g_TechnologyManager.by_name("Dragon-Upgraded Collectors").researched,i=0,L=9;g_Dragon.lastCollectorUpgraded=-1;if(duc){var b=building_on_tile(this.tileAt,BT_COLLECTOR);if(b>-1){L=allBuildings[b].upgradeLevel;if(L<5&&can_afford_collector_upgrade(L)){pay_collector_upgrade_cost(L);allBuildings[b].upgradeLevel+=1;g_Dragon.lastCollectorUpgraded=b;}}}var cet=find_closest_creature(28,CT_SWARM);if(cet===-1){cet=find_closest_creature(28,CT_SLIME);}if(cet===this.tileAt){break;}if(cet>-1){this.tileAt=cet;break;}if(duc){for(;i<allBuildings.length;i+=1){if(allBuildings[i].buildingType===BT_COLLECTOR&&allBuildings[i].upgradeLevel<5){nT=allBuildings[i].tileIndex;break;}}}if(nT<0){nT=tile_random_adjacent(this.tileAt);}if(nT>-1){this.tileAt=nT;}break;
case CT_BURNING:this.markedForDestruction=!0;break;case CT_FISH:if(season===4){this.markedForDestruction=!0;break;}if(g_ReefData.health>=180&&allBuildings.get_tile_has(this.tileAt,BT_REEF)){break;}if(random(0,10)<5){nT=tile_random_adjacent(this.tileAt);if(nT>-1&&allTiles[nT].tileType===TT_LAKE){this.tileAt=nT;}}break;case CT_CAMEL:if(random(0,10)<2){nT=tile_random_adjacent(this.tileAt);if(nT>-1&&allTiles[nT].tileType===TT_DESERT){this.tileAt=nT;}}break;case CT_SLIME:this.animation=floor(random(0,360));if(allTiles[this.tileAt].tileType!==TT_SLIMED||season!==4){nT=tile_random_adjacent(this.tileAt);if(nT>-1){this.tileAt=nT;} }this.daysToLive-=2*(allTiles[this.tileAt].tileType===TT_LAKE);if(allTiles[this.tileAt].tileType===TT_MAP_EDGE){this.markedForDestruction=!0;}break;case CT_SPARK:nT=tile_random_adjacent(this.tileAt);if(nT>-1){this.tileAt=nT;}break;case CT_TURTLE:if(season===4){this.markedForDestruction=!0;break;}nT=tile_random_adjacent(this.tileAt);if(nT>-1&&allTiles[nT].tileType===TT_LAKE&&allTiles[nT].backsideTileType===TT_WASTELAND){this.tileAt=nT;}break;case CT_TILE_GEN_FORCER:if(allTiles[this.tileAt].tileType!==TT_MAP_EDGE){nT=tile_at_position(allTiles[this.tileAt].x-32,allTiles[this.tileAt].y);if(nT>-1){this.tileAt=nT;}}if(allTiles[this.tileAt].tileType===TT_MAP_EDGE){this.markedForDestruction=!0;}break;
case CT_EDGE_FINDER:if(allTiles[this.tileAt].tileType===TT_MAP_EDGE){this.daysToLive+=!allTiles[this.tileAt].claimed;}else{this.daysToLive+=1;nT=tile_at_position(allTiles[this.tileAt].x-32,allTiles[this.tileAt].y);if(nT>-1&&allTiles[nT].revealed){this.tileAt=nT;}}break;
}if(this.daysToLive<1){this.markedForDestruction=!0;}};
Creature.prototype.on_enter_frosthour=function(){
switch(this.creatureType){case CT_SWARM:this.daysToLive=floor(this.daysToLive/2)-10;if(this.daysToLive<1){this.markedForDestruction=!0;}break;case CT_FISH:this.markedForDestruction=!0;break;case CT_TURTLE:this.markedForDestruction=!0;break;}};
Creature.prototype.type_as_string=function(){
var s="";switch(this.creatureType){case CT_SWARM:s="swarm";break;case CT_DRAGON:s="dragon";break;case CT_BURNING:s="burning";break;case CT_FISH:s="fish";break;case CT_CAMEL:s="camel";break;case CT_SLIME:s="slime";break;case CT_DEC_EYE:s="the eye";break;case CT_SPARK:s="spark";break;case CT_TRAIN_HEAD:case CT_TRAIN_BODY:case CT_TRAIN_TAIL:s="train";break;case CT_TURTLE:s=currentlyInBackside?"air turtle":"sea turtle";break;case CT_FIRE_GIANT:s="fire giant";break;case CT_COSMIC:case CT_EDGE_FINDER:while(s.length<6){s+=floor(26*random()+10).toString(36);}break;default:s="unknown";}return s;};
Creature.prototype.get_description=function(){
var s="";switch(this.creatureType){case CT_SWARM:s="enemy";break;case CT_DRAGON:s="your friend";break;case CT_BURNING:s="dead swarm";break;case CT_FISH:s="seafood";break;case CT_CAMEL:case CT_FIRE_GIANT:s="unlocks diplomacy";break;case CT_SLIME:s="it's harmless";break;case CT_DEC_EYE:s="it hears your thoughts";break;case CT_SPARK:s="helps you cast spells";break;case CT_TRAIN_HEAD:case CT_TRAIN_BODY:case CT_TRAIN_TAIL:s="delivers freight";break;case CT_TURTLE:s="can get you bonuses";break;case CT_COSMIC:case CT_EDGE_FINDER:s="cosmic being";var i=0,x;for(;i<3;i+=1){x=floor(random(s.length));s=s.substr(0,x)+"?"+s.substr(x+1);}break;default:s="unknown";}return s;};
g_Dragon=new Creature(-1,CT_DRAGON,0);
g_Dragon.attackRange=50;
g_Dragon.lastCollectorUpgraded=-1;
g_Dragon.on_new_run_start=function(){
g_Dragon.attackRange=g_PersistentData.get_upgrade_effect("FR").base;g_Dragon.tileAt=-1;g_Dragon.markedForDestruction=!1;g_Dragon.daysToLive=0;g_Dragon.lastCollectorUpgraded=-1;};
g_Dragon.fight_enemies=function(){
var iTile,dragonTile=allTiles[g_Dragon.tileAt],i=0,b=0,f=0;for(;i<allCreatures.length;i+=1){iTile=allTiles[allCreatures[i].tileAt];if(allCreatures[i].creatureType===CT_SWARM){if(dist(iTile.x,iTile.y,dragonTile.x,dragonTile.y)<g_Dragon.attackRange){allCreatures[i].creatureType=CT_BURNING;}}if(allCreatures[i].creatureType===CT_SLIME){if(dist(iTile.x,iTile.y,dragonTile.x,dragonTile.y)<g_Dragon.attackRange){allCreatures[i].markedForDestruction=!0;b=random(0.5,2.35);f=b*manaFromSlimeMulti;manaResource+=f;gadoliniumResource+=b*0.1*gadoliniumFromSlimeMulti;g_ResourcePane.gadoliniumVisible=!0;}}}};
g_Dragon.draw_attack_range_visualization=function(){
if(!g_Dragon.visible_in_current_side()||!allTiles[g_Dragon.tileAt].revealed){return;}var iTile,dTile=allTiles[g_Dragon.tileAt],i=0;if(mouseX>=dTile.x-cameraX-16&&mouseX<dTile.x-cameraX+15&&mouseY>=dTile.y-cameraY-16&&mouseY<dTile.y-cameraY+15){noStroke();fill(255,128,0,128);for(;i<allTiles.length;i+=1){iTile=allTiles[i];if(!allTiles[i].revealed){continue;}if(dist(iTile.x,iTile.y,dTile.x,dTile.y)<g_Dragon.attackRange){if(iTile.tileType===TT_MAP_EDGE){rect(0,iTile.y-cameraY-16,iTile.x-cameraX+16,32);}else{rect(iTile.x-cameraX-16,iTile.y-cameraY-16,32,32);}}}}};
g_TrainHead=new Creature(-1,CT_TRAIN_HEAD,0);
g_TrainBody=new Creature(-1,CT_TRAIN_BODY,0);
g_TrainTail=new Creature(-1,CT_TRAIN_TAIL,0);
g_TrainBody.freight=[0,0,0,0,0,0,0,0,0,0,0,0];
g_TrainBody.pastDeliveries=0;
allCreatures.remove_marked_for_destruction=function(){
var i=0;while(i<allCreatures.length){if(allCreatures[i].markedForDestruction){allCreatures.splice(i,1);i=0;}else{i+=1;}}if(g_Dragon.markedForDestruction){g_Dragon.tileAt=-1;g_Dragon.timeToLive=0;g_Dragon.lastCollectorUpgraded=-1;}};
allCreatures.on_enter_frosthour=function(){
allCreatures.forEach(function(c){c.on_enter_frosthour();});allCreatures.remove_marked_for_destruction();};
allCreatures.choose_train_action=function(){
var TT=g_ArtifactManager.by_abbreviation("TT"),cM=TT.active?TT.level+1:1,m=[65536*cM,8192*cM,1024*cM];if(TT.active){if(g_TrainBody.freight[0]===m[0]&&g_TrainBody.freight[1]===m[0]&&g_TrainBody.freight[2]===m[0]&&g_TrainBody.freight[3]===m[0]&&g_TrainBody.freight[4]===m[1]&&g_TrainBody.freight[5]===m[1]&&g_TrainBody.freight[6]===m[1]&&g_TrainBody.freight[7]===m[1]&&g_TrainBody.freight[8]===m[2]&&g_TrainBody.freight[9]===m[2]&&g_TrainBody.freight[10]===m[2]&&g_TrainBody.freight[11]===m[2]){return!1;}if(g_TrainBody.freight.every(function(f){return f>0;})){return random(10)<2;}if(g_TrainBody.freight.every(function(f){return f===0;})){return!0;}}return random(10)<4;};
allCreatures.update_train=function()
{
var TT=g_ArtifactManager.by_abbreviation("TT"),cM=TT.active?TT.level+1:1;
if(allBuildings.length<1||allBuildings[0].upgradeLevel<3)
{g_TrainHead.tileAt=-1;g_TrainHead.timeToLive=0;g_TrainBody.tileAt=-1;g_TrainBody.timeToLive=0;g_TrainTail.tileAt=-1;g_TrainTail.timeToLive=0;g_TrainBody.freight=[0,0,0,0,0,0,0,0,0,0,0,0];g_TrainBody.pastDeliveries=0;return;}
if(allCreatures.choose_train_action())
{
g_TrainHead.tileAt=-1;g_TrainHead.timeToLive=0;
g_TrainBody.tileAt=-1;g_TrainBody.timeToLive=0;
g_TrainTail.tileAt=-1;g_TrainTail.timeToLive=0;
var rR=floor(random(28)),rTTA=-1,rATA=1;
switch(rR)
{
case 0:case 1:case 2:case 3://Food
rTTA=0;rATA=floor(random(0.05,0.1)*foodResource)+1;break;
case 4:case 5:case 6:case 7://Mana
rTTA=1;rATA=floor(random(0.05,0.1)*manaResource)+1;break;
case 8:case 9:case 10:case 11://Pearl
if(g_PersistentData.currentChallenge==="URC"){rTTA=-1;break;}
rTTA=2;rATA=floor(random(0.05,0.1)*pearlResource)+1;break;
case 12:case 13:case 14:case 15://Stone
rTTA=3;rATA=floor(random(0.05,0.1)*stoneResource)+1;break;
case 16:case 17://Spice
if(!g_ResourcePane.spiceVisible||spiceResource<10){rTTA=-1;break;}
rTTA=4;rATA=floor(random(0.05,0.1)*spiceResource*0.75);break;
case 18:case 19://Gadolinium
if(!g_ResourcePane.gadoliniumVisible||gadoliniumResource<10){rTTA=-1;break;}
rTTA=5;rATA=floor(random(0.05,0.1)*gadoliniumResource*0.75);break;
case 20:case 21://Flame orb
if(!g_ResourcePane.flameOrbVisible||flameOrbResource<10){rTTA=-1;break;}
rTTA=6;rATA=floor(random(0.05,0.1)*flameOrbResource*0.75);break;
case 22:case 23://Iron
if(g_PersistentData.currentChallenge==="UCC"||!g_ResourcePane.ironVisible||ironResource<10){rTTA=-1;break;}
rTTA=7;rATA=floor(random(0.05,0.1)*ironResource*0.75);break;
case 24://Golden Apple
if(!g_ResourcePane.goldenAppleVisible||goldenAppleResource<10){rTTA=-1;break;}
rTTA=8;rATA=floor(random(0.05,0.1)*goldenAppleResource*0.75);break;
case 25://Dark energy
if(g_PersistentData.currentChallenge==="DEC"||!g_ResourcePane.darkEnergyVisible||darkEnergyResource<10){rTTA=-1;break;}
rTTA=9;rATA=floor(random(0.05,0.1)*darkEnergyResource*0.5);break;
case 26://Bio-orb
if(!g_ResourcePane.bioOrbVisible||bioOrbResource<10){rTTA=-1;break;}
rTTA=10;rATA=floor(random(0.05,0.1)*bioOrbResource*0.5);break;
case 27://Mithril
if(!g_ResourcePane.mithrilVisible||mithrilResource<10){rTTA=-1;break;}
rTTA=11;rATA=floor(random(0.05,0.1)*mithrilResource*0.5);break;
}
if(rTTA>-1){g_TrainBody.freight[rTTA]+=rATA;}
//Train limited cargo space:
g_TrainBody.freight[0]=min(g_TrainBody.freight[0],65536*cM);//2^16
g_TrainBody.freight[1]=min(g_TrainBody.freight[1],65536*cM);
g_TrainBody.freight[2]=min(g_TrainBody.freight[2],65536*cM);
g_TrainBody.freight[3]=min(g_TrainBody.freight[3],65536*cM);
g_TrainBody.freight[4]=min(g_TrainBody.freight[4],8192*cM);//2^13
g_TrainBody.freight[5]=min(g_TrainBody.freight[5],8192*cM);
g_TrainBody.freight[6]=min(g_TrainBody.freight[6],8192*cM);
g_TrainBody.freight[7]=min(g_TrainBody.freight[7],8192*cM);
g_TrainBody.freight[8]=min(g_TrainBody.freight[8],1024*cM);//2^10
g_TrainBody.freight[9]=min(g_TrainBody.freight[9],1024*cM);
g_TrainBody.freight[10]=min(g_TrainBody.freight[10],1024*cM);
g_TrainBody.freight[11]=min(g_TrainBody.freight[11],1024*cM);
return;
}
//Else, pick a random tile along the Train Line:
if(TT.active&&selectedTile>-1&&allTiles[selectedTile].hasTrainPowerLine)
{
g_TrainHead.tileAt=tile_at_position(allTiles[selectedTile].x,allTiles[selectedTile].y-32);