Repository navigation
Expand file tree
/
Copy pathdata.js
More file actions
4175 lines (4006 loc) · 153 KB
/
Copy pathdata.js
File metadata and controls
4175 lines (4006 loc) · 153 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
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
G.AddData({
name:'Default dataset',
author:'Orteil',
desc:'The default dataset for NEL. Does not require internet to use with the NEL Toolkit.',
engineVersion:1,
manifest:0,
func:function()
{
/*
Note : unlike some other strategy games, this dataset does not attempt to replicate Earth human history. In fact, care has been taken not to mention any existing civilizations; other topics consciously avoided are the player's species (no "mankind" or "humans") and gender ("they" is used when referring to any single individual).
Similarly, technologies do not necessarily follow the order in which they were invented in real life, if it makes sense for them to do so.
Mods should feel free to follow along these guidelines or to implement real-world civilizations, species, and genders into the game if they wish to.
-Playable species may be added as a game concept at some point in the future.
*/
/*=====================================================================================
PROPS & FUNCTIONS
=======================================================================================*/
G.props['fastTicksOnResearch']=150;
G.funcs['new game blurb']=function()
{
var str=
'<b>Your tribe:</b><div class="thingBox">'+
G.textWithTooltip('<div class="icon freestanding" style="'+G.getIconUsedBy(G.getRes('adult'))+'"></div><div class="freelabel">x5</div>','5 Adults')+
G.textWithTooltip('<div class="icon freestanding" style="'+G.getIconUsedBy(G.getRes('elder'))+'"></div><div class="freelabel">x1</div>','1 Elder')+
G.textWithTooltip('<div class="icon freestanding" style="'+G.getIconUsedBy(G.getRes('child'))+'"></div><div class="freelabel">x2</div>','2 Children')+
G.textWithTooltip('<div class="icon freestanding" style="'+G.getIconUsedBy(G.getRes('herb'))+'"></div><div class="freelabel">x250</div>','250 Herbs')+
G.textWithTooltip('<div class="icon freestanding" style="'+G.getIconUsedBy(G.getRes('water'))+'"></div><div class="freelabel">x250</div>','250 Water')+
'</div>'+
'<div class="par fancyText bitBiggerText">Your tribe finds a place to settle in the wilderness.<br>Resources are scarce, and everyone starts foraging.</div>'+
'<div class="par fancyText bitBiggerText">You emerge as the tribe\'s leader. They call you:</div>';
return str;
}
G.funcs['new game']=function()
{
var str='Your name is '+G.getName('ruler')+''+(G.getName('ruler').toLowerCase()=='orteil'?' <i>(but that\'s not you, is it?)</i>':'')+', ruler of '+G.getName('civ')+'. Your tribe is primitive, but full of hope.<br>The first year of your legacy has begun. May it stand the test of time.';
G.Message({type:'important tall',text:str,icon:[0,3]});
}
G.funcs['game over']=function()
{
var str=G.getName('civ')+' is no more, and your legacy is but a long-lost memory, merely a sidenote in a history book.<br>Everyone is dead.';
G.Message({type:'bad',text:str,icon:[5,4]});
}
G.funcs['game loaded']=function()
{
G.Message({type:'important tall',text:'Welcome back, '+G.getName('ruler')+', ruler of '+G.getName('civ')+'.',icon:[0,3]});
}
G.funcs['new year']=function()
{
if (G.on)
{
var str='';
str+='It is now the year '+(G.year+1)+'.<br>';
str+='Report for last year:<br>';
str+='• Births : '+B(G.getRes('born this year').amount)+'<br>';
str+='• Deaths : '+B(G.getRes('died this year').amount)+'<br>';
G.getRes('born this year').amount=0;
G.getRes('died this year').amount=0;
G.Message({type:'important',text:str,icon:[0,3]});
//influence trickle
if (G.getRes('influence').amount<=G.getRes('authority').amount-1)G.gain('influence',1);
}
}
G.props['new day lines']=[
'Creatures are lurking.',
'Danger abounds.',
'Wild beasts are on the prowl.',
'Large monsters roam, unseen.',
'This is a cold night.',
'No sound but the low hum of a gray sky.',
'The darkness is terrifying.',
'Clouds twist in complicated shapes.',
'It is raining.',
'Dark birds caw ominously in the distance.',
'There is a storm on the horizon.',
'The night is unforgiving.',
'Creatures crawl in the shadows.',
'A stream burbles quietly nearby.',
'In the distance, a prey falls to a pack of beasts.',
'An unexplained sound echoes on the horizon.',
'Everything stands still in the morning air.',
'A droning sound fills the sky.',
'The night sky sparkles, its mysteries unbroken.',
'Dry bones crack and burst underfoot.',
'Wild thorns scratch the ankles.',
'Something howls in the distance.',
'Strange ashes snow down slowly from far away.',
'A blood-curdling wail is heard.',
'Unknown creatures roll and scurry in the dirt.',
'The air carries a peculiar smell today.',
'Wild scents flow in from elsewhere.',
'The dust is oppressive.',
'An eerie glow from above illuminates the night.',
'Distant lands lay undisturbed.'
];
shuffle(G.props['new day lines']);
G.funcs['new day']=function()
{
if (G.on)
{
if (G.getSetting('atmosphere') && Math.random()<0.01)
{
//show a random atmospheric message occasionally on new days
//we pick one of the first 5 lines in the array, then push that line back at the end; this means we get a semi-random stream of lines with no frequent repetitions
var i=Math.floor(Math.random()*5);
var msg=G.props['new day lines'].splice(i,1)[0];
G.props['new day lines'].push(msg);
G.Message({text:msg});
}
//possibility to gain random traits everyday
for (var i in G.trait)
{
var me=G.trait[i];
if (!G.has(me.name))
{
if (Math.random()<1/(me.chance*300))
{
if (G.checkReq(me.req) && G.testCost(me.cost,1))
{
G.doCost(me.cost,1);
G.gainTrait(me);
G.Message({type:'important tall',text:'Your people have adopted the trait <b>'+me.displayName+'</b>.',icon:me.icon});
}
}
}
}
G.trackedStat=Math.max(G.trackedStat,G.getRes('population').amount);
}
}
G.funcs['tracked stat str']=function()
{
return 'Most population ruled';
}
G.funcs['civ blurb']=function()
{
var str='';
str+='<div class="fancyText shadowed">'+
'<div class="barred infoTitle">The land of '+G.getName('civ')+'</div>'+
'<div class="barred">ruler : '+G.getName('ruler')+'</div>';
var toParse='';
var pop=G.getRes('population').amount;
if (pop>0)
{
toParse+='Population: <b>'+B(pop)+' [population,'+G.getName((pop==1?'inhab':'inhabs'))+']</b>//';
var stat=G.getRes('happiness').amount/pop;
var text='unknown';if (stat<=-200) text='miserable'; else if (stat<=-100) text='mediocre'; else if (stat<=-50) text='low'; else if (stat<50) text='average'; else if (stat<100) text='pleasant'; else if (stat<=200) text='high'; else if (stat>=200) text='euphoric';
toParse+='Happiness: <b>'+text+'</b>//';
var stat=G.getRes('health').amount/pop;
var text='unknown';if (stat<=-200) text='dreadful'; else if (stat<=-100) text='sickly'; else if (stat<=-50) text='low'; else if (stat<50) text='average'; else if (stat<100) text='good'; else if (stat<=200) text='gleaming'; else if (stat>=200) text='examplary';
toParse+='Health: <b>'+text+'</b>//';
}
else toParse+='All '+G.getName('inhabs')+' have died out.';
str+=G.parse(toParse);
str+='</div>';
return str;
}
G.funcs['found tile']=function(tile)
{
G.Message({type:'good',mergeId:'foundTile',textFunc:function(args){
if (args.count==1) return 'Our explorers have found a new tile: <b>'+args.tile.land.displayName+'</b>.';
else return 'Our explorers have found '+B(args.count)+' new tiles; the latest is <b>'+args.tile.land.displayName+'</b>.';
},args:{tile:tile,count:1},icon:[14,4]});
}
G.funcs['production multiplier']=function()
{
var mult=1;
if (G.getRes('population').amount>0)
{
var happiness=(G.getRes('happiness').amount/G.getRes('population').amount)/100;
happiness=Math.max(-2,Math.min(2,happiness));
if (happiness>=0) mult=(Math.pow(2,happiness+1)/2);
else mult=1/(Math.pow(2,-happiness+1)/2);
}
return mult;
}
/*=====================================================================================
RESOURCES
=======================================================================================*/
G.resCategories={
'main':{
name:'Essentials',
base:[],
side:['population','worker','happiness','health','land','coin'],
},
'demog':{
name:'Demographics',
base:['baby','child','adult','elder','worker','sick','wounded'],
side:['population','housing','corpse','burial spot'],
},
'food':{
name:'Food & Water',
base:[],
side:['food','spoiled food','water','muddy water','food storage'],
},
'build':{
name:'Crafting & Construction',
base:[],
side:['archaic building materials','basic building materials','advanced building materials','precious building materials','material storage'],
},
'gear':{
name:'Gear',
base:[],
side:[],
},
'misc':{
name:'Miscellaneous',
base:[],
},
};
new G.Res({name:'died this year',hidden:true});
new G.Res({name:'born this year',hidden:true});
var numbersInfo='//The number on the left is how many are in use, while the number on the right is how many you have in total.';
new G.Res({
name:'coin',
displayName:'Coins',
desc:'[#coin,Currency] has a multitude of uses, from paying the upkeep on units to purchasing various things.//Before the invention of currency, [food] is used instead.',
icon:[13,1],
replacement:'food',
tick:function(me,tick)
{
if (me.replacement) me.hidden=true; else me.hidden=false;
}
});
new G.Res({
name:'population',
desc:'Your [population] represents everyone living under your rule. These are the people that look to you for protection, survival, and glory.',
meta:true,
visible:true,
icon:[0,3],
tick:function(me,tick)
{
//this.displayName=G.getName('inhabs');
if (me.amount>0)
{
//note : we also sneak in some stuff unrelated to population here
//policy ticks
//ORTEIL WHY WAS THIS VALUE FIFTY!!?
if (tick%20==0)
{
var rituals=['fertility rituals','harvest rituals','flower rituals','wisdom rituals'];
for (var i in rituals)
{
if (G.checkPolicy(rituals[i])=='on')
{
if (G.getRes('faith').amount<=0) G.setPolicyModeByName(rituals[i],'off');
else G.lose('faith',1,'rituals');
}
}
}
var productionMult=G.doFunc('production multiplier',1);
var deathUnhappinessMult=1;
if (G.has('fear of death')) deathUnhappinessMult*=2;
if (G.has('belief in the afterlife')) deathUnhappinessMult/=2;
if (tick%3==0 && G.checkPolicy('disable eating')=='off')
{
//drink water
var toConsume=0;
var weights={'baby':0.1,'child':0.3,'adult':0.5,'elder':0.5,'sick':0.4,'wounded':0.4};
for (var i in weights)
{toConsume+=G.getRes(i).amount*weights[i];}
var rations=G.checkPolicy('water rations');
if (rations=='none') {toConsume=0;G.gain('happiness',-me.amount*3,'water rations');G.gain('health',-me.amount*2,'water rations');}
else if (rations=='meager') {toConsume*=0.5;G.gain('happiness',-me.amount*1,'water rations');G.gain('health',-me.amount*0.5,'water rations')}
else if (rations=='plentiful') {toConsume*=1.5;G.gain('happiness',me.amount*1,'water rations');}
toConsume=randomFloor(toConsume);
var lacking=toConsume-G.lose('water',toConsume,'drinking');
if (rations=='none') lacking=me.amount*0.5;
if (lacking>0)//are we out of water?
{
//resort to muddy water
if (rations!='none' && G.checkPolicy('drink muddy water')=='on') lacking=lacking-G.lose('muddy water',lacking,'drinking');
if (lacking>0 && G.checkPolicy('disable aging')=='off')//are we also out of muddy water?
{
G.gain('happiness',-lacking*5,'no water');
//die off
var toDie=(lacking/5)*0.05;
if (G.year<1) toDie/=5;//less deaths in the first year
var died=0;
var weights={'baby':0.1,'child':0.2,'adult':0.5,'elder':1,'sick':0.3,'wounded':0.3};//the elderly are the first to starve off
var sum=0;for (var i in weights){sum+=weights[i];}for (var i in weights){weights[i]/=sum;}//normalize
for (var i in weights){var ratio=(G.getRes(i).amount/me.amount);weights[i]=ratio+(1-ratio)*weights[i];}
for (var i in weights)
{var n=G.lose(i,randomFloor((Math.random()*0.8+0.2)*toDie*weights[i]),'dehydration');died+=n;}
G.gain('corpse',died,'dehydration');
G.gain('happiness',-died*20*deathUnhappinessMult,'dehydration');
G.getRes('died this year').amount+=died;
if (died>0) G.Message({type:'bad',mergeId:'diedDehydration',textFunc:function(args){return B(args.died)+' '+(args.died==1?'person':'people')+' died from dehydration.';},args:{died:died},icon:[5,4]});
}
}
//eat food
var toConsume=0;
var consumeMult=1;
var happinessAdd=0;
if (G.has('culture of moderation')) {consumeMult*=0.85;happinessAdd-=0.1;}
else if (G.has('joy of eating')) {consumeMult*=1.15;happinessAdd+=0.1;}
var weights={'baby':0.2,'child':0.5,'adult':1,'elder':1,'sick':0.75,'wounded':0.75};
for (var i in weights)
{toConsume+=G.getRes(i).amount*weights[i];}
var rations=G.checkPolicy('food rations');
if (rations=='none') {toConsume=0;G.gain('happiness',-me.amount*3,'food rations');G.gain('health',-me.amount*2,'food rations');}
else if (rations=='meager') {toConsume*=0.5;G.gain('happiness',-me.amount*1,'food rations');G.gain('health',-me.amount*0.5,'food rations');}
else if (rations=='plentiful') {toConsume*=1.5;G.gain('happiness',me.amount*1,'food rations');}
toConsume=randomFloor(toConsume*consumeMult);
var consumed=G.lose('food',toConsume,'eating');
G.gain('happiness',G.lose('salt',randomFloor(consumed*0.1),'eating')*5,'salting food');//use salt
G.gain('happiness',consumed*happinessAdd,'food culture');
var lacking=toConsume-consumed;
if (rations=='none') lacking=me.amount*1;
if (lacking>0)//are we out of food?
{
//resort to spoiled food
if (rations!='none' && G.checkPolicy('eat spoiled food')=='on') lacking=lacking-G.lose('spoiled food',lacking,'eating');
if (lacking>0 && G.checkPolicy('disable aging')=='off')//are we also out of spoiled food?
{
G.gain('happiness',-lacking*5,'no food');
//die off
var toDie=(lacking/5)*0.05;
if (G.year<1) toDie/=5;//less deaths in the first year
var died=0;
var weights={'baby':0.1,'child':0.2,'adult':0.5,'elder':1,'sick':0.3,'wounded':0.3};//the elderly are the first to starve off
var sum=0;for (var i in weights){sum+=weights[i];}for (var i in weights){weights[i]/=sum;}//normalize
for (var i in weights){var ratio=(G.getRes(i).amount/me.amount);weights[i]=ratio+(1-ratio)*weights[i];}
for (var i in weights)
{var n=G.lose(i,randomFloor((Math.random()*0.8+0.2)*toDie*weights[i]),'starvation');died+=n;}
G.gain('corpse',died,'starvation');
G.gain('happiness',-died*20*deathUnhappinessMult,'starvation');
G.getRes('died this year').amount+=died;
if (died>0) G.Message({type:'bad',mergeId:'diedStarvation',textFunc:function(args){return B(args.died)+' '+(args.died==1?'person':'people')+' died from starvation.';},args:{died:died},icon:[5,4]});
}
}
}
//clothing
var objects={'basic clothes':[0.1,0.1],'primitive clothes':[0,0]};
var leftout=me.amount;
var prev=leftout;
var fulfilled=0;
for (var i in objects)
{
fulfilled=Math.min(me.amount,Math.min(G.getRes(i).amount,leftout));
G.gain('happiness',fulfilled*objects[i][0],'clothing');
G.gain('health',fulfilled*objects[i][1],'clothing');
leftout-=fulfilled;
}
G.gain('happiness',-leftout*0.15,'no clothing');
G.gain('health',-leftout*0.15,'no clothing');
//fire
var objects={'fire pit':[10,0.1,0.1]};
var leftout=me.amount;
var prev=leftout;
var fulfilled=0;
for (var i in objects)
{
fulfilled=Math.min(me.amount,Math.min(G.getRes(i).amount*objects[i][0],leftout));
G.gain('happiness',fulfilled*objects[i][1],'warmth & light');
G.gain('health',fulfilled*objects[i][2],'warmth & light');
leftout-=fulfilled;
}
G.gain('happiness',-leftout*0.1,'cold & darkness');
G.gain('health',-leftout*0.1,'cold & darkness');
//homelessness
var homeless=Math.max(0,(me.amount)-G.getRes('housing').amount);
if (G.has('sedentism') && me.amount>15 && homeless>0)
{
if (tick%10==0) G.Message({type:'bad',mergeId:'homeless',textFunc:function(args){return B(args.n)+' '+(args.n==1?'person is':'people are')+' homeless.<br>Homelessness with more than 15 population leads to lower birth rates.';},args:{n:homeless},replaceOnly:true,icon:[12,4]});
}
//age
if (G.checkPolicy('disable aging')=='off')
{
if (G.year>=10)//no deaths of old age the first 10 years
{
var n=randomFloor(G.getRes('elder').amount*0.00035);
G.gain('corpse',n,'old age');
G.lose('elder',n,'old age');
G.gain('happiness',-n*5*deathUnhappinessMult,'death');
if (n>0) G.Message({type:'bad',mergeId:'diedAge',textFunc:function(args){return B(args.n)+' '+(args.n==1?'person':'people')+' died of old age.';},args:{n:n},icon:[13,4]});
G.getRes('died this year').amount+=n;
}
if (G.year>=5)//no aging adults the first 5 years
{
var n=randomFloor(G.getRes('adult').amount*0.0002);
G.gain('elder',n,'-');G.lose('adult',n,'aging up');
}
var n=randomFloor(G.getRes('child').amount*0.002);G.gain('adult',n,'aging up');G.lose('child',n,'aging up');
var n=randomFloor(G.getRes('baby').amount*0.005);G.gain('child',n,'aging up');G.lose('baby',n,'aging up');
//births
var parents=G.getRes('adult').amount+G.getRes('elder').amount;
if (parents>=2)//can't make babies by yourself
{
var born=0;
var birthRate=1;
if (me.amount<100) birthRate*=3;//more births if low pop
if (me.amount<10) birthRate*=3;//even more births if very low pop
if (G.checkPolicy('fertility rituals')=='on') birthRate*=1.2;
if (G.checkPolicy('population control')=='forbidden') birthRate*=0;
else if (G.checkPolicy('population control')=='limited') birthRate*=0.5;
birthRate*=productionMult;
if (homeless>0 && me.amount>15) birthRate*=0.05;//harder to make babies if you have more than 15 people and some of them are homeless
var n=randomFloor(G.getRes('adult').amount*0.0003*birthRate);G.gain('baby',n,'birth');G.gain('happiness',n*10,'birth');born+=n;
var n=randomFloor(G.getRes('elder').amount*0.00003*birthRate);G.gain('baby',n,'birth');G.gain('happiness',n*10,'birth');born+=n;
G.getRes('born this year').amount+=born;
if (born>0) G.Message({type:'good',mergeId:'born',textFunc:function(args){return B(args.born)+' '+(args.born==1?'baby has':'babies have')+' been born.';},args:{born:born},icon:[2,3]});
}
//health (diseases and wounds)
//note : when a sick or wounded person recovers, they turn into adults; this means you could get a community of old people fall sick, then miraculously age back. life is a mystery
//sickness
var toChange=0.00003;
if (G.getRes('health').amount<0)
{
toChange*=(1+Math.abs(G.getRes('health').amount/me.amount));
}
if (toChange>0)
{
if (G.year<5) toChange*=0.5;//less disease the first 5 years
if (me.amount<=15) toChange*=0.5;
if (G.checkPolicy('flower rituals')=='on') toChange*=0.8;
var changed=0;
var weights={'baby':2,'child':1.5,'adult':1,'elder':2};
if (G.checkPolicy('child workforce')=='on') weights['child']*=2;
if (G.checkPolicy('elder workforce')=='on') weights['elder']*=2;
if (G.year<5) weights['adult']=0;//adults don't fall sick the first 5 years
for (var i in weights)
{var n=G.lose(i,randomFloor(Math.random()*G.getRes(i).amount*toChange*weights[i]),'-');changed+=n;}
G.gain('sick',changed,'disease');
if (changed>0) G.Message({type:'bad',mergeId:'fellSick',textFunc:function(args){return B(args.n)+' '+(args.n==1?'person':'people')+' fell sick.';},args:{n:changed},icon:[6,3]});
}
//sickness : death and recovery
var sickMortality=0.005;
var changed=0;
var n=G.lose('sick',randomFloor(Math.random()*G.getRes('sick').amount*sickMortality),'disease');G.gain('corpse',n,'disease');changed+=n;
G.gain('happiness',-changed*15*deathUnhappinessMult,'death');
G.getRes('died this year').amount+=changed;
if (changed>0) G.Message({type:'bad',mergeId:'diedSick',textFunc:function(args){return B(args.n)+' '+(args.n==1?'person':'people')+' died from disease.';},args:{n:changed},icon:[5,4]});
var sickHealing=0.01;
if (G.checkPolicy('flower rituals')=='on') sickHealing*=1.2;
var changed=0;
var n=G.lose('sick',randomFloor(Math.random()*G.getRes('sick').amount*sickHealing),'healing');G.gain('adult',n,'-');changed+=n;
G.gain('happiness',changed*10,'recovery');
if (changed>0) G.Message({type:'good',mergeId:'sickRecovered',textFunc:function(args){return B(args.n)+' sick '+(args.n==1?'person':'people')+' got better.';},args:{n:changed},icon:[4,3]});
//wounds
var toChange=0.00003;
if (toChange>0)
{
if (G.year<5) toChange*=0.5;//less wounds the first 5 years
if (me.amount<=15) toChange*=0.5;
var changed=0;
var weights={'baby':2,'child':1.5,'adult':1,'elder':2};
if (G.checkPolicy('child workforce')=='on') weights['child']*=3;
if (G.checkPolicy('elder workforce')=='on') weights['elder']*=3;
if (G.year<5) weights['adult']=0;//adults don't get wounded the first 5 years
for (var i in weights)
{var n=G.lose(i,randomFloor(Math.random()*G.getRes(i).amount*toChange*weights[i]),'-');changed+=n;}
G.gain('wounded',changed,'accident');
if (changed>0) G.Message({type:'bad',mergeId:'gotWounded',textFunc:function(args){return B(args.n)+' '+(args.n==1?'person':'people')+' got wounded.';},args:{n:changed},icon:[7,3]});
}
//wounds : death and recovery
var woundMortality=0.005;
var changed=0;
var n=G.lose('wounded',randomFloor(Math.random()*G.getRes('wounded').amount*woundMortality),'wounds');G.gain('corpse',n,'wounds');changed+=n;
G.gain('happiness',-changed*15*deathUnhappinessMult,'death');
G.getRes('died this year').amount+=changed;
if (changed>0) G.Message({type:'bad',mergeId:'diedWounded',textFunc:function(args){return B(args.n)+' '+(args.n==1?'person':'people')+' died from their wounds.';},args:{n:changed},icon:[5,4]});
var sickHealing=0.005;
var changed=0;
var n=G.lose('wounded',randomFloor(Math.random()*G.getRes('wounded').amount*sickHealing),'healing');G.gain('adult',n,'-');changed+=n;
G.gain('happiness',changed*10,'recovery');
if (changed>0) G.Message({type:'good',mergeId:'woundedRecovered',textFunc:function(args){return B(args.n)+' '+(args.n==1?'person':'people')+' recovered from their wounds.';},args:{n:changed},icon:[4,3]});
}
}
else if (G.T>0) {G.GameOver();}
},
});
new G.Res({
name:'baby',
desc:'[baby,Babies] are what happens when you have 2 or more [adult,Adults] left to their own devices.//Any 2 adults can have babies, even if they are working. [elder]s can also have babies, though much slower.//[happiness] affects how many babies your people make.//Over time, babies will grow into [child,Children].//Babies drink and eat half as much as children.',
startWith:0,
visible:true,
partOf:'population',
icon:[2,3],
});
new G.Res({
name:'child',
desc:'[child,Children] grow from [baby,Babies] over time.//After a while, they will grow up into [adult,Adults].//Children drink and eat half as much as adults.//Children do not count as [worker,Workers], unless special measures are in place.',
startWith:2,
visible:true,
partOf:'population',
icon:[3,3],
});
new G.Res({
name:'adult',
desc:'[adult,Adults] grow from [child,Children] over time.//They eventually age into [elder,Elders].//Generally, adults make up most of your [worker,workforce].',
startWith:5,
visible:true,
partOf:'population',
icon:[4,3],
});
new G.Res({
name:'elder',
desc:'[adult,Adults] that grow old are [elder,Elders].//Elders may end up [corpse,dying] of old age.//Elders do not count as [worker,Workers], unless special measures are in place.',
startWith:1,
visible:true,
partOf:'population',
icon:[5,3],
});
new G.Res({
name:'sick',
desc:'[adult,People] can fall [sick,sick] when your [health] levels are too low. They do not [worker,work], but may be healed over time.',
partOf:'population',
icon:[6,3],
});
new G.Res({
name:'wounded',
desc:'[adult,People] may get [wounded,wounded] due to work injuries, or from war. They do not [worker,work], but may slowly get better over time.',
partOf:'population',
icon:[7,3],
});
new G.Res({
name:'corpse',
desc:'[corpse,Corpses] are the remains of [population,People] that died, whether from old age, accident, disease, starvation or war.//Corpses left in the open air tend to spread diseases and make people unhappy, which gets even worse as superstitions develop. To mitigate this, you need a [burial spot] for each corpse.',
startWith:0,
icon:[8,3],
tick:function(me,tick)
{
var graves=G.getRes('burial spot');
if (G.getRes('population').amount>0)
{
if (G.has('ritual necrophagy'))//butcher 3% of corpses every day, you weirdo
{
var changed=0;
var n=G.lose('corpse',randomFloor(G.getRes('corpse').amount*0.03),'necrophagy');G.gain('meat',n*30,'necrophagy');G.gain('bone',n*5,'necrophagy');changed+=n;
if (n>0)
{
G.pseudoGather(G.getRes('faith'),changed);
G.gain('health',-changed*0.1,'necrophagy');
}
}
if (me.amount>0)
{
//bury slowly
if (graves.amount>graves.used)
{
var amount=Math.min(graves.amount-graves.used,Math.max(1,randomFloor(me.amount*0.1)));
graves.used+=amount;G.lose('corpse',amount,'burial');
G.gain('happiness',amount*2,'burial');
}
}
}
if (graves.amount<graves.used)
{
//more occupied burial spots than total burial spots? this means we've been deleting burial spot that was already containing corpses; exhume those suckers
var toExhume=randomFloor((graves.used-graves.amount)*0.1);
graves.used-=toExhume;
G.gain('corpse',toExhume,'not enough burial spots');
}
var toSpoil=me.amount*0.001;
var spent=G.lose('corpse',randomFloor(toSpoil),'decay');
var unhappiness=0.01;
if (G.has('burial')) unhappiness*=2;
if (G.has('belief in revenants')) unhappiness*=2;
G.gain('happiness',-me.amount*unhappiness,'corpses');
G.gain('health',-me.amount*0.02,'corpses');
},
});
new G.Res({
name:'burial spot',
desc:'Each [burial spot] has enough room for one [corpse], letting you prevent the spread of disease and unhappiness.//By default, corpses are buried at the rate of 1 per day.//The number on the left is how many burial spots are occupied, while the number on the right is how many you have in total.',
icon:[13,4],
displayUsed:true,
});
new G.Res({
name:'housing',
desc:'Each [housing,Housing spot] accommodates one [population,Person].//Beyond the 15 people a nomad tribe can support, your population will only grow if you have empty housing.//Homelessness (having less housing than population) will lead to unhappiness and disease.//The number on the left is how much housing is occupied, while the number on the right is how much housing room you have in total.',
icon:[12,4],
getDisplayAmount:function()
{
return B(Math.min(this.displayedAmount,G.getRes('population').displayedAmount))+'<wbr>/'+B(this.displayedAmount);
},
});
new G.Res({
name:'land',
desc:'Each tile of territory you own grants you some [land] (100 per fully-explored non-ocean tile, by default) upon which you can construct buildings. If for some reason you find yourself with less land than your buildings are using, some of them will start to slowly crumble away.//The number on the left is how much land is occupied, while the number on the right is how much land you have in total.',
icon:[14,4],
displayUsed:true,
tick:function(me)
{
me.amount=Math.ceil(G.currentMap.territoryByOwner[1]*100);
//me.amount=G.tiles;
//TODO : this stuff
/*
concept :
-each tile owned can be explored to 100%
-you get one land per explored percent per tile
-some techs also add a +10 etc bonus to the max of 100 land per full tile
-we need to setup a system to recalculate this when appropriate
*/
},
getDisplayAmount:function()
{
return B(this.displayedUsedAmount)+'<wbr>/'+B(this.displayedAmount);
},
});
new G.Res({
name:'worker',
desc:'Your [worker,Workforce] is the part of your [population] that is ready to work.//The number on the left is how many are currently being employed, while the number on the right is your total amount of workers.',
startWith:0,
visible:true,
icon:[1,3],
displayUsed:true,
tick:function(me,tick)
{
me.amount=G.getRes('adult').amount;
if (G.checkPolicy('elder workforce')=='on') me.amount+=G.getRes('elder').amount;
if (G.checkPolicy('child workforce')=='on') me.amount+=G.getRes('child').amount;
if (me.used>me.amount)
{
//TODO maybe ?
//select all units that require workers
//pick some at random until we have enough people to reach the difference between workers and workers needed
//kill them if the unit has no gizmos, otherwise reduce the unit's percent by 1 rank
//maybe this could be generalized to work will all requirements
//or not ? some requirements have unique conditions, such as : 10 factories running at 50% only use half the workers and tools, but still need 10 land
//maybe this could just be a flag on land, reqIgnoresPercent=true
//but then how do we deal with the situation where we have less land available than land used (like after a war where we lost tiles) ? the desired behavior would be that buildings slowly die off until we're under the threshold
//maybe just implement a "onReqFail" function that overrides the default behavior
}
},
});
new G.Res({
name:'happiness',
desc:'[happiness] describes the global level of well-being of your [population].//Happy people work even harder, while unhappy people tend to slack off; at +100% happiness, most of your workers will work twice as fast, while at -100% happiness, they will work twice as slow. This goes on up to +200% and -200%.//Several things improve happiness, such as good [food,food], entertainment, or luxury items; things that bring down happiness are spoiled food, starvation, disease, death and harsh policies.//Happiness and unhappiness both tend to level off over time.',
startWith:0,
visible:true,
icon:[3,4],
fractional:true,
tick:function(me,tick)
{
if (G.getRes('population').amount>0 && tick%2==0)
{
me.amount*=0.99;
}
},
getDisplayAmount:function()
{
if (G.getRes('population').amount<=0) return '-';
var amount=(this.displayedAmount/G.getRes('population').displayedAmount);
if (amount>200) amount=200;
if (amount<-200) amount=-200;
return B(amount)+'%';
},
getIcon:function(me)
{
if (G.getRes('population').amount<=0) return [5,4];
else
{
var amount=me.amount/G.getRes('population').amount;
if (amount>=100) return [4,4];
else if (amount>=50) return [3,4];
else if (amount>=-50) return [2,4];
else if (amount>=-100) return [1,4];
else return [0,4];
}
},
});
new G.Res({
name:'health',
desc:'[health] represents the average physical condition of your [population].//Lower health tends to make people [sick] and unhappy, while higher health will make people happier.//Health can be affected by a number of things : eating raw or spoiled [spoiled food,Food], drinking [muddy water], poor living conditions, and ongoing plagues.',
startWith:0,
visible:true,
icon:[3,5],
fractional:true,
tick:function(me,tick)
{
if (G.getRes('population').amount>0 && tick%2==0)
{
//note : this is "soft" sickness; it affects the chance of people falling sick
//G.getRes('happiness').amount+=(me.amount-G.getRes('happiness').amount)*0.01;
G.gain('happiness',me.amount*0.001,'health');
var sickness=0.1;
sickness+=Math.pow(Math.max(0,G.getRes('population').amount-50),0.1)*0.1;//more people means more contagion
G.gain('health',-G.getRes('population').amount*(Math.random()*sickness),'disease');//people randomly get sick
var recovery=0.98;
me.amount*=recovery;//people recover over time
}
},
getDisplayAmount:function()
{
if (G.getRes('population').amount<=0) return '-';
return B(this.displayedAmount/G.getRes('population').displayedAmount)+'%';
},
getIcon:function(me)
{
if (G.getRes('population').amount<=0) return [5,5];
else
{
var amount=me.amount/G.getRes('population').amount;
if (amount>=100) return [4,5];
else if (amount>=50) return [3,5];
else if (amount>=-50) return [2,5];
else if (amount>=-100) return [1,5];
else return [0,5];
}
},
});
new G.Res({
name:'food storage',
desc:'Each [food storage] unit slows down decay for one [food] unit.//The number on the left is how much food storage is occupied, while the number on the right is how much you have in total.',
icon:[12,5],
tick:function(me,tick)
{
var amount=0;
amount+=G.getRes('basket').amount*10;
amount+=G.getRes('pot').amount*25;
amount+=G.getRes('ice').amount;
amount+=G.getRes('added food storage').amount;
me.amount=amount;
},
getDisplayAmount:function()
{
return B(Math.min(this.displayedAmount,G.getRes('food').displayedAmount))+'<wbr>/'+B(this.displayedAmount);
},
});
new G.Res({
name:'added food storage',
//food storage added by buildings
desc:'',
icon:[12,5],
hidden:true,
});
new G.Res({
name:'material storage',
desc:'Each [material storage] unit lowers the rate of decay or theft for one unit of your materials.//The number on the left is how much material storage is occupied, while the number on the right is how much you have in total.',
icon:[14,5],
tick:function(me,tick)
{
var amount=0;
amount+=G.getRes('added material storage').amount;
me.amount=amount;
var materials=0;
for (var i in G.props['perishable materials list'])
{
var mat=G.props['perishable materials list'][i];
materials+=mat.amount;
}
me.used=materials;
if (materials>0)
{
var stored=Math.min(materials,amount)/materials;
var notStored=1-stored;
for (var i in G.props['perishable materials list'])
{
var mat=G.props['perishable materials list'][i];
var toSpoil=mat.amount*0.002*notStored+mat.amount*0.0001*stored;
var spent=G.lose(mat.name,randomFloor(toSpoil),'decay');
}
}
G.props['perishable materials list']=[];
},
getDisplayAmount:function()
{
return B(Math.min(this.displayedAmount,this.displayedUsedAmount))+'<wbr>/'+B(this.displayedAmount);
},
displayUsed:true,
});
new G.Res({
name:'added material storage',
//material storage added by buildings
desc:'',
icon:[14,5],
hidden:true,
});
new G.Res({
name:'water',
desc:'[water] is required to keep your [population,people] hydrated, at the rate of half a unit per person every 3 ticks (although babies and children drink less).//Without water, people will resort to drinking [muddy water], which is unhealthy; if that runs out too, your people will simply die off.//Most terrains have some fresh water up for gathering - from ponds, streams and rain; drier locations will have to rely on well digging.//Water turns into [muddy water] over time, if your water storage is insufficient.',
icon:[7,6],
startWith:250,
visible:true,
turnToByContext:{'drinking':{'health':0.01,'happiness':0}},
tick:function(me,tick)
{
if (G.checkPolicy('disable spoiling')=='off')
{
var toSpoil=me.amount*0.02;
var spent=G.lose('water',randomFloor(toSpoil),'decay');
G.gain('muddy water',randomFloor(spent),'decay');
}
},
});
new G.Res({
name:'muddy water',
desc:'[muddy water] tastes awful and is unhealthy, but is better than dying of thirst. Your people will default to drinking it in the absence of fresh [water].//Muddy water can be collected while gathering, from stagnant pools or old rainwater; [water] also turns into muddy water over time, if not stored properly. Additionally, muddy water itself will slowly dry out.',
icon:[8,6],
visible:true,
turnToByContext:{'drinking':{'health':-0.03,'happiness':-0.05}},
tick:function(me,tick)
{
if (G.checkPolicy('disable spoiling')=='off')
{
var toSpoil=me.amount*0.01;
var spent=G.lose('muddy water',randomFloor(toSpoil),'decay');
}
},
});
new G.Res({
name:'food',
desc:'[food] is consumed by your [population,people] when they get hungry, at the rate of 1 unit per person every 3 ticks (although babies and children eat less).//Some types of food are tastier or healthier than others.//Note that some food types may or may not be eaten depending on policies in place.//Food will slowly decay into [spoiled food] if you lack proper food storage.',
meta:true,
visible:true,
icon:[3,6],
tick:function(me,tick)
{
if (me.amount>0 && G.checkPolicy('disable spoiling')=='off')
{
var stored=Math.min(me.amount,G.getRes('food storage').amount)/me.amount;
var notStored=1-stored;
var toSpoil=me.amount*0.01*notStored+me.amount*0.0005*stored;
var spent=G.lose('food',randomFloor(toSpoil),'decay');
//G.gain('spoiled food',randomFloor(spent));
}
},
});
new G.Res({
name:'spoiled food',
desc:'[spoiled food] is eaten when no other [food] is available, in a last-ditch effort to fend off starvation.//Spoiled food is terribly unhealthy and tastes just as bad. Over time, it will decay even further into inedibility.',
icon:[3,7],
visible:true,
turnToByContext:{'eating':{'health':-0.3,'happiness':-0.5}},
tick:function(me,tick)
{
if (G.checkPolicy('disable spoiling')=='off')
{
var toSpoil=me.amount*0.001;
var spent=G.lose('spoiled food',randomFloor(toSpoil),'decay');
}
},
});
//a trick to make different food types spoil at different speeds : turnToByContext:{'decay':{'fruit':0.2}} would make fruit last 20% longer (note : the food may still produce spoiled food)
new G.Res({
name:'herb',
desc:'[herb,Herbs] are various plants, roots and mushrooms that can be collected by simply foraging around. While relatively healthy to eat, they tend to taste fairly unpleasant.',
icon:[4,6],
startWith:250,
turnToByContext:{'eating':{'health':0.005,'happiness':-0.03},'decay':{'herb':0.2,'spoiled food':0.8}},
partOf:'food',
category:'food',
});
new G.Res({
name:'fruit',
desc:'[fruit,Fruits], whether gathered from berry bushes or fruit trees, are both sweet-tasting and good for you.',
icon:[4,7],
turnToByContext:{'eating':{'health':0.02,'happiness':0.01},'decay':{'spoiled food':1}},
partOf:'food',
category:'food',
});
new G.Res({
name:'meat',
desc:'[meat,Raw meat] is gathered from dead animals and, while fairly tasty, can harbor a variety of diseases.',
icon:[5,7],
turnToByContext:{'eating':{'health':-0.03,'happiness':0.02,'bone':0.1},'decay':{'spoiled food':1}},
partOf:'food',
category:'food',
});
new G.Res({
name:'cooked meat',
desc:'Eating [cooked meat] is deeply satisfying and may even produce a [bone].',
icon:[6,7],
turnToByContext:{'eating':{'health':0.02,'happiness':0.04,'bone':0.1},'decay':{'cooked meat':0.2,'spoiled food':0.8}},
partOf:'food',
category:'food',
});
new G.Res({
name:'cured meat',
desc:'[cured meat] is interestingly tough and can keep for months without spoiling.',
icon:[11,6],
turnToByContext:{'eating':{'health':0.02,'happiness':0.05,'bone':0.1},'decay':{'cured meat':0.95,'spoiled food':0.05}},
partOf:'food',
category:'food',
});
new G.Res({
name:'seafood',
desc:'[seafood,Raw seafood] such as fish, clams, or shrimps, is both bland-tasting and several kinds of nasty.',
icon:[5,6],
turnToByContext:{'eating':{'health':-0.02,'happiness':0.01,'bone':0.02},'decay':{'spoiled food':1}},
partOf:'food',
category:'food',
});
new G.Res({
name:'cooked seafood',
desc:'[cooked seafood] tastes pretty good and has various health benefits.',
icon:[6,6],
turnToByContext:{'eating':{'health':0.03,'happiness':0.03,'bone':0.02},'decay':{'cooked seafood':0.2,'spoiled food':0.8}},
partOf:'food',
category:'food',
});
new G.Res({
name:'cured seafood',
desc:'[cured seafood] has a nice smoky flavor and lasts terribly long.',
icon:[12,6],
turnToByContext:{'eating':{'health':0.02,'happiness':0.04,'bone':0.02},'decay':{'cured seafood':0.95,'spoiled food':0.05}},
partOf:'food',
category:'food',
});
new G.Res({
name:'bread',
desc:'[bread] is filling, nutritious, and usually not unpleasant to eat; for these reasons, it is often adopted as staple food by those who can produce it.',
icon:[7,7],
turnToByContext:{'eating':{'health':0.02,'happiness':0.02},'decay':{'spoiled food':1}},
partOf:'food',
category:'food',
});
new G.Res({
name:'bugs',
desc:'Worms, insects, spiders - [bugs] are easily caught, but are usually not considered [food].',
icon:[8,11],
turnToByContext:{'eating':{'health':0,'happiness':-0.05},'decay':{'spoiled food':0.5}},
//partOf:'food',
category:'food',
tick:function(me,tick)
{
var toLose=me.amount*0.003;//bugs don't like to stick around
var spent=G.lose(me.name,randomFloor(toLose),'decay');
}
});
G.props['perishable materials list']=[];
var loseMaterialsTick=function(me,tick)
{
if (G.checkPolicy('disable spoiling')=='off')
{
G.props['perishable materials list'].push(me);
}
};
new G.Res({
//hidden, used for every material that can be stored in a warehouse that isn't part of any other material
name:'misc materials',
meta:true,
tick:loseMaterialsTick,
hidden:true,
});
new G.Res({
name:'archaic building materials',
desc:'Materials such as [stick]s and [stone]s, used to build rudimentary structures.',
icon:[2,7],
meta:true,
tick:loseMaterialsTick,