-
Notifications
You must be signed in to change notification settings - Fork 6
/
Cult.hx
1618 lines (1373 loc) · 40.6 KB
/
Cult.hx
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
// cult (game player)
import Static;
import sects.Sect;
import _SaveGame;
class Cult
{
var game: Game;
var ui: UI;
public var id: Int;
public var infoID: Int;
public var name: String;
public var fullName(get, null): String;
public var info: CultInfo;
public var difficulty: DifficultyInfo; // difficulty info link
public var isInfoKnown: Array<Bool>; // info known to players?
public var isDiscovered: Array<Bool>; // is met by players?
public var isAI: Bool; // player or AI?
public var isDead: Bool; // cult is dead
public var isParalyzed: Bool; // cult is paralyzed
var paralyzedTurns: Int; // paralyzed state count
public var isDebugInvisible: Bool; // debug: cult nodes are invisible
// ritual stuff
public var isRitual: Bool; // cult is performing ritual?
public var ritual: RitualInfo; // which ritual is in progress
public var ritualPoints: Int; // amount of ritual points left
public var awarenessMod: Int; // awareness static mod from expansions
public var awarenessBase: Int; // base awareness
public var awareness(get, null): Int; // public awareness (combined)
// power reserves
public var power: Array<Int>; // intimidation, persuasion, bribe, virgins
public var virgins(get, set): Int;
public var wars: Array<Bool>; // wars
public var powerMod: Array<Int>; // power that will be generated next turn (cache)
public var origin: Node; // origin
// followers number cache
public var neophytes(get, null): Int;
public var adepts(get, null): Int;
public var priests(get, null): Int;
public var nodes: List<Node>; // cache of owned nodes
public var adeptsUsed: Int; // how many adepts were used this turn
public var sects: List<Sect>; // list of controlled sects
public var hasInvestigator: Bool; // does this cult has investigator on its back?
public var investigator: Investigator; // investigator
public var investigatorTimeout: Int; // timeout before next investigator may appear
public var logMessages: String; // log string
public var logMessagesTurn: String; // log string for this turn
public var logPanelMessages: List<LogPanelMessage>; // log panel messages list
public var highlightedNodes: List<Node>; // highlighted nodes list
// expansion stuff
public var artifacts: artifacts.CultArtifacts;
public var fluffShown: Map<String, Bool>;
public function new(gvar: Game, uivar: UI, id: Int, infoID: Int)
{
game = gvar;
ui = uivar;
this.id = id;
this.infoID = infoID;
this.info = Static.cults[infoID];
this.name = this.info.name;
this.isAI = false;
this.isDead = false;
this.isParalyzed = false;
this.highlightedNodes = new List<Node>();
this.artifacts = new artifacts.CultArtifacts(game, ui, this);
this.fluffShown = new Map();
this.isDiscovered = [];
this.isInfoKnown = [];
this.paralyzedTurns = 0;
for (i in 0...game.difficulty.numCults)
this.isInfoKnown[i] = game.difficulty.isInfoKnown;
for (i in 0...game.difficulty.numCults)
this.isDiscovered[i] = game.difficulty.isDiscovered;
// self discovered and info known
this.isDiscovered[id] = true;
this.isInfoKnown[id] = true;
this.power = [0, 0, 0, 0];
this.powerMod = [0, 0, 0, 0];
wars = [];
for (i in 0...game.difficulty.numCults)
wars.push(false);
this.adeptsUsed = 0;
this.awarenessBase = 0;
this.awarenessMod = 0;
this.awareness = 0;
this.nodes = new List<Node>();
this.sects = new List<Sect>();
this.investigatorTimeout = 0;
this.difficulty = game.difficulty;
this.logMessages = '';
this.logMessagesTurn = '';
this.logPanelMessages = new List();
}
// max number of sects
public inline function getMaxSects(): Int
{
return Std.int(nodes.length / 4);
}
// get generated ritual points
public function getRitualPoints(): Int
{
if (game.flags.artifacts)
return artifacts.getRitualPoints();
return priests;
}
// get max ritual points
public function getMaxRitualPoints(): Int
{
var pts = ritual.points;
if (game.flags.longRituals)
return Std.int(Const.longRitualsRitualPoints * pts);
return pts;
}
// create a new sect
public function createSect(node: Node)
{
if (sects.length >= getMaxSects())
return;
var sect = new Sect(game, ui, node, this);
sects.add(sect);
node.sect = sect;
node.update();
if (game.flags.devoted) // DEVOTED: pick a resource to buff with
sect.powerID = Std.random(Game.numPowers);
if (!isAI)
ui.log2(this, node.name +
" becomes the puppeteer of a sect called " + sect.name + ".",
{ type: 'sect', symbol: 's' });
// tutorial
if (!isAI)
game.tutorial.play('gainSect');
}
// remove a sect
public function removeSect(node: Node, src: String)
{
var text = node.sect.name;
if (src == 'investigator')
text += ' has dispersed without proper inspiration.';
else if (src == 'sacrifice')
text += ' was sacrificed to discourage the investigator.';
else if (src == 'attack')
text += ' was disbanded when its puppeteer has left the cult.';
else if (src == 'harvest')
text += ' was harvested for resources.';
if (src != null)
ui.log2(this, text, { type: 'sect', symbol: 's' });
sects.remove(node.sect);
node.sect.leader = null;
node.sect = null;
node.update();
}
// get sect by id
public function getSect(id: Int): Sect
{
for (s in sects)
if (s.id == id)
return s;
return null;
}
// setup random starting node
public function setOrigin()
{
// change method on the difficulty setting
if (game.difficulty.numCults <= 4)
setupOriginFair();
else setupOriginRandom();
origin.owner = this;
if (!isAI || game.difficulty.isOriginKnown)
origin.isKnown[this.id] = true;
nodes.add(origin);
origin.update();
// origin.setOwner(this);
// make starting node generator
for (i in 0...Game.numPowers)
if (origin.power[i] > 0)
{
origin.powerGenerated[i] = 1;
powerMod[i] += 1;
}
origin.setGenerator(true);
origin.setVisible(this, true);
origin.showLinks();
highlightedNodes.clear(); // hack: clear highlighted
// give initial power from starting node
for (i in 0...Game.numPowers)
{
power[i] += Math.round(origin.powerGenerated[i]);
// 50% chance of raising the conquer difficulty
if (Math.random() < 0.5)
origin.power[i]++;
}
origin.update();
// remove close generators on hard for player
if (!isAI && game.difficultyLevel == 2)
removeCloseGenerators();
}
// pick an origin fairly
function setupOriginFair()
{
// pick unused quadrant and set origin there
// pick unused quadrant
var quad = game.freeQuadrants[Std.random(game.freeQuadrants.length)];
game.freeQuadrants.remove(quad);
// get all nodes in this quadrant
var tmp = [];
var outer: Node = null;
var outerd = 10000.0;
for (n in game.nodes)
if (quad.x1 <= n.x && quad.y1 <= n.y &&
n.x <= quad.x2 && n.y <= quad.y2)
{
tmp.push(n);
// also pick outermost node for tutorial
if (outer != null && !isAI && game.isTutorial)
{
var d = 0.0;
if (quad.id == 0)
d = n.distanceXY(quad.x1, quad.y1);
else if (quad.id == 1)
d = n.distanceXY(quad.x2, quad.y1);
else if (quad.id == 2)
d = n.distanceXY(quad.x1, quad.y2);
else if (quad.id == 3)
d = n.distanceXY(quad.x2, quad.y2);
if (d < outerd)
{
outer = n;
outerd = d;
}
}
else outer = n;
}
var node = tmp[Std.random(tmp.length)];
if (game.isTutorial && !isAI)
node = outer;
origin = node;
}
// pick a random node as an origin
function setupOriginRandom()
{
// find appropriate node
var index = -1;
while (true)
{
index = Math.round((game.nodes.length - 1) * Math.random());
var node = game.nodes[index];
if (node.owner != null)
continue;
// check for close nodes
var ok = 1;
for (p in game.cults)
if (p.origin != null &&
node.distance(p.origin) < difficulty.nodeActivationRadius + 50)
{
ok = 0;
break;
}
if (ok == 0)
continue;
origin = game.nodes[index];
return;
}
}
// remove close node generators
function removeCloseGenerators()
{
for (n in origin.links)
{
/*
for (n2 in n.links)
if (n2.owner == null && n2.isGenerator)
n2.setGenerator(false);
*/
if (n.owner == null && n.isGenerator)
n.setGenerator(false);
}
}
// get resource chance
public function getResourceChance()
{
var ch = 99 - Std.int(difficulty.awarenessResource * awareness);
if (ch < 1)
ch = 1;
return ch;
}
// get upgrade chance
public function getUpgradeChance(level)
{
var ch = 0;
if (level == 0)
ch = Std.int(99 * difficulty.upgradeChance -
awareness * difficulty.awarenessUpgrade);
else if (level == 1)
ch = Std.int(80 * difficulty.upgradeChance -
awareness * 1.5 * difficulty.awarenessUpgrade);
else if (level == 2)
ch = Std.int(75 * difficulty.upgradeChance -
awareness * 2 * difficulty.awarenessUpgrade);
if (ch < 1)
ch = 1;
if (ch > 99)
ch = 99;
return ch;
}
// get gain chance (pl)
public function getGainChance(node: Node)
{
var ch = 0;
if (!node.isGenerator) // generators are harder to gain
ch = 99 - Std.int(awareness * difficulty.awarenessGain);
else ch = 99 - Std.int(awareness * 2 * difficulty.awarenessGain);
// player penalty if cult info is not known
if (!isAI && node.owner != null && !node.owner.isInfoKnown[game.player.id])
ch -= 20;
// player penalty if node info is not known
if (!isAI && node.owner != null && !node.isKnown[game.player.id])
ch -= 10;
if (ch < 1)
ch = 1;
return ch;
}
// lower awareness
public function lowerAwareness(pwr)
{
if (awarenessBase == 0 || adeptsUsed >= adepts || pwr == 3 ||
power[pwr] < 1)
return;
awarenessBase -= 2;
if (awarenessBase < 0)
awarenessBase = 0;
power[pwr]--;
adeptsUsed++;
if (!isAI)
{
ui.updateStatus();
ui.map.paint();
}
}
// lower investigator willpower chance
public function getLowerWillChance(): Int
{
var failChance = 30 * difficulty.investigatorWillpower;
if (investigator.name == "Randolph Carter") // wink-wink
failChance += 10;
return Std.int(100 - failChance);
}
// lower investigator willpower
public function lowerWillpower(pwr)
{
if (!hasInvestigator || adeptsUsed >= adepts || pwr == 3 ||
power[pwr] < Game.willPowerCost || investigator.isHidden)
return;
power[pwr] -= Game.willPowerCost;
adeptsUsed++;
// chance of failure
if (Std.random(100) > getLowerWillChance())
{
if (!isAI)
{
ui.msg('You have failed to shatter the will of the investigator.');
ui.updateStatus();
}
return;
}
investigator.lowerWillpower(1);
if (!isAI)
{
if (hasInvestigator)
ui.msg('Investigator willpower lowered.');
else
{
ui.msg('The investigator disappeared.');
ui.sound.play('inv-disappear');
}
ui.updateStatus();
}
}
// remove investigator for this cult
public function killInvestigator()
{
investigator = null;
hasInvestigator = false;
investigatorTimeout = 3;
game.failSectTasks(); // fail all tasks for that investigator
if (!isAI)
game.tutorial.play('investigatorDead');
}
// convert resources
public function convert(from: Int, to: Int)
{
if (from == to)
return;
if (power[from] < Game.powerConversionCost[from])
{
// if (!isAI)
// ui.msg("Not enough " + Game.powerNames[from]);
return;
}
power[from] -= Game.powerConversionCost[from];
power[to] += 1;
if (!isAI)
ui.updateStatus();
}
// cult can upgrade?
public function canUpgrade(level: Int): Bool
{
if (game.isFinished)
return false;
if (level < 2)
{
// base
var ok = (getNumFollowers(level) >= Game.upgradeCost &&
virgins >= level + 1);
if (!ok)
return false;
// flags
if (game.flags.artifacts)
return artifacts.canUpgrade(level);
return true;
}
// final ritual
else return
(priests >= Static.rituals['summoning'].priests &&
virgins >= game.difficulty.numSummonVirgins &&
!isRitual);
}
// cult can start this ritual?
public function canStartRitual(id: String): Bool
{
if (game.isFinished)
return false;
var info = Static.rituals[id];
if (isRitual || priests < info.priests || virgins < info.virgins)
return false;
// all origins are known
if (id == 'unveiling')
{
for (c in game.cults)
if (c.origin != null && !c.origin.isKnown[this.id])
return true;
return false;
}
return true;
}
// start ritual by id
public function startRitual(id: String)
{
if (!canStartRitual(id))
return;
// player is already in ritual
if (isRitual)
{
ui.alert("You must first finish the current ritual before starting another.");
return;
}
var info = Static.rituals[id];
virgins -= info.virgins;
ritual = info;
ritualPoints = getMaxRitualPoints();
isRitual = true;
ui.log2(this, fullName + " has started the " + ritual.name + ".",
{ symbol: 'R' });
if (!isAI)
ui.updateStatus();
}
// upgrade nodes (fupgr)
public function upgrade(level): Bool
{
// cannot upgrade
if (!canUpgrade(level))
return false;
// summon
if (level == 2)
{
summonStart();
return true;
}
virgins -= (level + 1);
// check for failure
if (100 * Math.random() > getUpgradeChance(level))
{
if (!isAI)
{
ui.msg('You have failed the ritual to gain ' +
(level == 0 ? 'an adept.' : 'a priest.'));
ui.updateStatus();
}
return false;
}
awareness += level;
// starting node upgrades first
var ok = false;
var upNode = null;
if (origin != null && origin.level == level)
{
origin.upgrade();
upNode = origin;
ok = true;
}
// find a node with maximum amount of links
if (!ok)
{
upNode = findMostLinkedNode(level);
if (upNode != null)
{
upNode.upgrade();
ok = true;
}
}
if (!ok)
{
trace('BUG: Cannot upgrade. No nodes found.');
return false;
}
// expansions
if (game.flags.artifacts && level == 1)
artifacts.onUpgrade(upNode);
if (!isAI)
ui.updateStatus();
// notify player
if (this != game.player && priests >= 2)
ui.log2(this, fullName + " has " + priests + " priests. Be careful.");
// cult un-paralyzed with priests
if (isParalyzed && priests >= 1)
{
unParalyze();
ui.log2(this, fullName + " has gained a priest and is no longer paralyzed.");
}
ui.map.paint();
// tutorial hooks
if (!isAI)
{
if (adepts >= 1)
game.tutorial.play('gainAdept');
if (adepts >= 3)
game.tutorial.play('gain3Adepts');
if (priests >= 1)
game.tutorial.play('gainPriest');
}
return true;
}
// find most linked node for this cult
function findMostLinkedNode(?level: Int, ?noSects: Bool): Node
{
var node = null;
var nlinks = -1;
if (level != null)
{
for (n in nodes)
{
// no sects
if (noSects && n.sect != null)
continue;
// count links owned by that cult
var cnt = 0;
for (l in n.links)
if (l.owner == this)
cnt++;
if (n.level == level && cnt > nlinks)
{
node = n;
nlinks = cnt;
}
}
}
else
for (n in nodes)
{
// no sects
if (noSects && n.sect != null)
continue;
// count links owned by that cult
var cnt = 0;
for (l in n.links)
if (l.owner == this)
cnt++;
if (cnt > nlinks)
{
node = n;
nlinks = cnt;
}
}
return node;
}
// unparalyze cult
function unParalyze()
{
// get most protected with links node
var node = findMostLinkedNode();
// make it a temp generator
node.makeGenerator();
node.isTempGenerator = true;
// unparalyze cult
isParalyzed = false;
paralyzedTurns = 0;
origin = node;
}
// chance of gaining investigator
public function getInvestigatorChance(): Int
{
// chance depends on size
var x = (20 * priests + 5 * adepts + 0.5 * neophytes) *
difficulty.investigatorChance * // difficulty mod
(100.0 + awareness) / 100.0; // awareness mod
// on very low awareness we halve it
if (awareness <= 5)
x /= 2.0;
return Std.int(x);
}
// summon elder god
public function summonStart()
{
// player is already in ritual
if (isRitual)
{
ui.alert("You must first finish the current ritual before starting another.");
return;
}
virgins -= game.difficulty.numSummonVirgins;
isRitual = true;
for (c in game.cults)
isInfoKnown[c.id] = true;
ritual = Static.rituals['summoning'];
ritualPoints = getMaxRitualPoints();
// every cult starts war with this one
for (p in game.cults)
if (p != this && !p.isDead)
{
p.wars[id] = true;
wars[p.id] = true;
}
ui.sound.play('final-ritual-start');
ui.alert('<h2>FINAL RITUAL STARTED</h2><div class=fluff>' +
info.summonStart + '</div><br>' +
fullName + ' has started the ' + ritual.name + '.', {
w: 700,
h: 400,
});
ui.log2(this, fullName + " has started the " + ritual.name + ".",
{ symbol: 'R' });
if (!isAI)
ui.updateStatus();
if (isAI)
game.tutorial.play('enemyFinalRitual');
}
// finish a ritual
function ritualFinish()
{
if (ritual.id == "summoning")
summonFinish();
else if (ritual.id == "unveiling")
{
ui.log2(this, fullName + ' has finished the ' + ritual.name + '.',
{ symbol: 'R' });
unveilingFinish();
}
isRitual = false;
}
// finish unveiling
function unveilingFinish()
{
if (!isAI)
{
ui.sound.play('unveiling-ritual-finish');
ui.alert('<h2>RITUAL COMPLETED</h2><div class=fluff>' +
Static.templates['ritualUnveiling'] + '</div><br>' +
fullName + ' has finished the ' + ritual.name +
'. All cult origins are revealed.', {
w: 600,
h: 345,
});
}
for (c in game.cults)
if (c.origin != null)
{
c.origin.setVisible(this, true);
c.origin.isKnown[this.id] = true;
}
ui.map.paint();
}
// finish summoning
public function summonFinish()
{
// chance of failure
if (100 * Math.random() > getUpgradeChance(2))
{
// 1 priest goes totally insane and has to be replaced with neophyte
var tmp = [];
for (n in nodes)
if (n.level == 2)
tmp.push(n);
var n = tmp[Std.random(tmp.length)];
n.generateLite();
var msg =
'<h2>FINAL RITUAL FAILED</h2><div class=fluff>' +
info.summonFail + '</div><br>' +
fullName + " has failed to perform the " +
Static.rituals['summoning'].name +
'. The stars were not properly aligned. One of the high priests goes insane.';
ui.alert(msg, {
w: 700,
h: 400,
sound: 'final-ritual-fail',
});
if (!isAI)
{
ui.log2(this, fullName + " has failed to perform the " +
Static.rituals['summoning'].name + ".",
{ symbol: 'R' });
ui.updateStatus();
}
else
{
ui.log2(this, fullName + " has failed to perform the " +
Static.rituals['summoning'].name + ".",
{ symbol: 'R' });
}
return;
}
ui.finish(this, "summon");
ui.log2(this, fullName + " has completed the " +
Static.rituals['summoning'].name + ". Game over.");
}
// start new turn for this cult (fturn) - gain resources, finish rituals, etc
public function turn()
{
// un-paralyzed after 3 turns even if no priests available
if (isParalyzed && paralyzedTurns > 3)
{
unParalyze();
var text = fullName + " has gained an origin and is no longer paralyzed.";
ui.log2(this, text);
if (!isAI)
ui.alert(text, {
h: UI.getVarInt('--alert-window-height-2lines'),
sound: 'window-open',
});
}
// if a cult has any adepts, each turn it has a
// chance of an investigator finding out about it
if ((priests > 0 || adepts > 0) &&
!hasInvestigator &&
100 * Math.random() < getInvestigatorChance() &&
investigatorTimeout == 0)
{
hasInvestigator = true;
ui.log2(this, "An investigator has found out about " + fullName + ".", {
important: !this.isAI,
symbol: 'I'
});
if (!isAI)
ui.alert("An investigator has found out about your cult.", {
h: UI.getVarInt('--alert-window-min-height'),
sound: 'inv-appear',
});
investigator = new Investigator(this, ui, game);
if (!isAI)
ui.updateStatus();
// tutorial
if (!isAI)
game.tutorial.play('investigator');
}
if (investigatorTimeout > 0)
investigatorTimeout--;
// finish a ritual if there is one
if (isRitual)
{
ritualPoints -= getRitualPoints();
if (ritualPoints <= 0)
ritualFinish();
// summon finished
if (game.isFinished)
return;
}
// give power and recalculate power mod cache
powerMod = [0, 0, 0, 0];
for (node in nodes)
if (node.isGenerator)
for (i in 0...Game.numFullPowers)
{
// failure chance
if (100 * Math.random() < getResourceChance())
power[i] += node.powerGenerated[i];
powerMod[i] += node.powerGenerated[i];
}
// neophytes bring in some virgins
var value = Std.random(maxVirgins() + 1);
virgins += value;
adeptsUsed = 0;
// investigator acts
if (hasInvestigator)
investigator.turn();
for (s in sects) // sect tasks
s.turn();
if (isParalyzed) // count paralyzed state time
paralyzedTurns++;
createSects(); // create new sects
// run sect advisor
if (game.options.getBool('sectAdvisor'))
game.sectAdvisor.run(this);
// expansions
if (game.flags.artifacts && !isAI)
artifacts.turn();
// recalculate base awareness
calcBaseAwareness();
}
// recalculate base awareness
function calcBaseAwareness()
{
// DEVOTED: bonus to mod
awarenessMod = 0;
for (s in sects)
if (s.isDevoted)
awarenessMod += Const.devotedAwarenessBonus[s.level];
}
// create new sects
function createSects()
{
if (isAI) return;
while (sects.length < getMaxSects())
{
var node = findMostLinkedNode(null, true);
createSect(node);
}
// ui.map.paint();
}
public function maxVirgins(): Int
{
var x = Std.int(neophytes / 4 - 0.5);
if (x < 0)
return 0;
return x;
}
// can this player activate this node?
public function canActivate(node: Node): Bool
{
if (game.isFinished)
return false;
// tutorial: do not allow clicking nodes on first turn
if (!isAI && game.isTutorial && game.turns == 0)
return false;
if (isParalyzed)
return false;
// check for power
for (i in 0...Game.numFullPowers)
if (power[i] < node.power[i])
return false;