-
Notifications
You must be signed in to change notification settings - Fork 34
/
common_original.eai
1718 lines (1457 loc) · 53.7 KB
/
common_original.eai
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
//============================================================================
// Standard common.ai V1.18 by Blizzard Entertainment (Implementation by Strategy Master)
//============================================================================
//============================================================================
function InitAI takes nothing returns nothing
set ai_player = Player(GetAiPlayer())
set sleep_seconds = 0
call InitAiUnits() // This function makes all unit ids go back to there originals
call VersionCheck()
call InitGlobalSettings()
if debugging and IsPlayerObserver(GetLocalPlayer()) then
call SetPlayerAlliance(ai_player, GetLocalPlayer(), ALLIANCE_HELP_REQUEST, true)
call SetPlayerAlliance(ai_player, GetLocalPlayer(), ALLIANCE_HELP_RESPONSE, true)
call SetPlayerAlliance(ai_player, GetLocalPlayer(), ALLIANCE_SHARED_XP, true)
call SetPlayerAlliance(ai_player, GetLocalPlayer(), ALLIANCE_SHARED_SPELLS, true)
call SetPlayerAlliance(ai_player, GetLocalPlayer(), ALLIANCE_SHARED_VISION, true)
call SetPlayerAlliance(ai_player, GetLocalPlayer(), ALLIANCE_SHARED_CONTROL, true)
call SetPlayerAlliance(ai_player, GetLocalPlayer(), ALLIANCE_SHARED_ADVANCED_CONTROL, true)
endif
call InitArrays()
call StopGathering()
endfunction
//============================================================================
function StandardAI takes code heroes, code peons, code attacks returns nothing
local boolean isNewbie = (MeleeDifficulty() == MELEE_NEWBIE)
call InitAI()
call SetMeleeAI()
call SetDefendPlayer(true)
call SetGroupsFlee(not isNewbie)
call SetHeroesBuyItems(not isNewbie)
call SetHeroesFlee(true)
call SetHeroesTakeItems(true)
call SetIgnoreInjured(true)
call SetPeonsRepair(true)
call SetSmartArtillery(not isNewbie)
call SetTargetHeroes(not isNewbie)
call SetUnitsFlee(not isNewbie)
call SetWatchMegaTargets(true)
call CreateCaptains()
call SetHeroLevels(heroes)
call Sleep(0.1)
call StartThread(peons)
call StartThread(attacks)
endfunction
//============================================================================
// Utility Functions
//============================================================================
function SetZepNextWave takes nothing returns nothing
set zep_next_wave = true
endfunction
function SuicideSleep takes integer seconds returns nothing
set sleep_seconds = sleep_seconds - seconds
loop
exitwhen seconds <= 0
exitwhen allow_signal_abort and CommandsWaiting() != 0
if seconds >= 5 then
call Sleep(5)
set seconds = seconds - 5
else
call Sleep(seconds)
set seconds = 0
endif
endloop
endfunction
//============================================================================
function WaitForSignal takes nothing returns integer
local integer cmd
local boolean display = false //xxx
loop
exitwhen CommandsWaiting() != 0
//xxx
call Trace("waiting for a signal to begin AI script...\n")
set display = true
call Sleep(2)
exitwhen CommandsWaiting() != 0
call Sleep(2)
exitwhen CommandsWaiting() != 0
call Sleep(2)
exitwhen CommandsWaiting() != 0
call Sleep(2)
exitwhen CommandsWaiting() != 0
call Sleep(2)
//xxx
endloop
//xxx
if display then
call Trace("signal received, beginning AI script\n")
endif
//xxx
set cmd = GetLastCommand()
call PopLastCommand()
return cmd
endfunction
//============================================================================
function SetWoodPeons takes integer count returns nothing
set campaign_wood_peons = count
endfunction
//============================================================================
function SetGoldPeons takes integer count returns nothing
set campaign_gold_peons = count
endfunction
//============================================================================
function SetHarvestLumber takes boolean harvest returns nothing
if harvest then
set campaign_wood_peons = 3
else
set campaign_wood_peons = 0
endif
endfunction
//============================================================================
function SetFormGroupTimeouts takes boolean state returns nothing
set form_group_timeouts = state
endfunction
//============================================================================
function DoCampaignFarms takes boolean state returns nothing
set do_campaign_farms = state
endfunction
//============================================================================
function GetMinorCreep takes nothing returns unit
return GetCreepCamp(0,9,false)
endfunction
//============================================================================
function GetMajorCreep takes nothing returns unit
return GetCreepCamp(10,100,allow_air_creeps)
endfunction
//============================================================================
function InitBuildArray takes nothing returns nothing
set build_length = 0
endfunction
//============================================================================
function InitMeleeGroup takes nothing returns nothing
call InitAssaultGroup()
call RemoveInjuries()
call RemoveSiege()
endfunction
//============================================================================
function PrepFullSuicide takes nothing returns nothing
call InitAssaultGroup()
call InitDefenseGroup()
set campaign_gold_peons = 0
set campaign_wood_peons = 0
endfunction
//============================================================================
function SetReplacements takes integer easy, integer med, integer hard returns nothing
if difficulty == EASY then
call SetReplacementCount(easy)
elseif difficulty == NORMAL then
call SetReplacementCount(med)
else
call SetReplacementCount(hard)
endif
endfunction
//============================================================================
function StartTownBuilder takes code func returns nothing
call StartThread(func)
endfunction
//============================================================================
function SetBuildAll takes integer t, integer qty, integer unitid, integer town returns nothing
if qty > 0 then
set build_qty[build_length] = qty
set build_type[build_length] = t
set build_item[build_length] = unitid
set build_town[build_length] = town
set build_length = build_length + 1
endif
endfunction
//============================================================================
function SetBuildUnit takes integer qty, integer unitid returns nothing
call SetBuildAll(BUILD_UNIT,qty,unitid,-1)
endfunction
//============================================================================
function SetBuildNext takes integer qty, integer unitid returns nothing
local integer has = GetUnitCount(unitid)
if has >= qty then
return
endif
call SetBuildAll(BUILD_UNIT,GetUnitCountDone(unitid)+1,unitid,-1)
endfunction
//============================================================================
function SetBuildUnitEx takes integer easy, integer med, integer hard, integer unitid returns nothing
if difficulty == EASY then
call SetBuildAll(BUILD_UNIT,easy,unitid,-1)
elseif difficulty == NORMAL then
call SetBuildAll(BUILD_UNIT,med,unitid,-1)
else
call SetBuildAll(BUILD_UNIT,hard,unitid,-1)
endif
endfunction
//============================================================================
function SecondaryTown takes integer town, integer qty, integer unitid returns nothing
call SetBuildAll(BUILD_UNIT,qty,unitid,town)
endfunction
//============================================================================
function SecTown takes integer town, integer qty, integer unitid returns nothing
call SetBuildAll(BUILD_UNIT,qty,unitid,town)
endfunction
//============================================================================
function SetBuildUpgr takes integer qty, integer unitid returns nothing
if MeleeDifficulty() != MELEE_NEWBIE or qty == 1 then
call SetBuildAll(BUILD_UPGRADE,qty,unitid,-1)
endif
endfunction
//============================================================================
function SetBuildUpgrEx takes integer easy, integer med, integer hard, integer unitid returns nothing
if difficulty == EASY then
call SetBuildAll(BUILD_UPGRADE,easy,unitid,-1)
elseif difficulty == NORMAL then
call SetBuildAll(BUILD_UPGRADE,med,unitid,-1)
else
call SetBuildAll(BUILD_UPGRADE,hard,unitid,-1)
endif
endfunction
//============================================================================
function SetBuildExpa takes integer qty, integer unitid returns nothing
call SetBuildAll(BUILD_EXPAND,qty,unitid,-1)
endfunction
//============================================================================
function StartUpgrade takes integer level, integer upgid returns boolean
local integer gold_cost
local integer wood_cost
if GetUpgradeLevel(upgid) >= level then
return true
endif
set gold_cost = GetUpgradeGoldCost(upgid)
if total_gold < gold_cost then
return false
endif
set wood_cost = GetUpgradeWoodCost(upgid)
if total_wood < wood_cost then
return false
endif
return SetUpgrade(upgid)
endfunction
//============================================================================
function BuildFactory takes integer unitid returns nothing
if GetGold() > 1000 and GetWood() > 500 then
call SetBuildUnit( 2, unitid )
else
call SetBuildUnit( 1, unitid )
endif
endfunction
//============================================================================
function GuardSecondary takes integer townid, integer qty, integer unitid returns nothing
if TownHasHall(townid) and TownHasMine(townid) then
call SecondaryTown( townid, qty, unitid )
endif
endfunction
//============================================================================
function BasicExpansion takes boolean build_it, integer unitid returns nothing
if build_it and HallsCompleted(unitid) then
call SetBuildExpa( TownCount(unitid)+1, unitid )
endif
endfunction
//============================================================================
function UpgradeAll takes integer baseid, integer newid returns nothing
call SetBuildUnit( TownCountDone(baseid), newid )
endfunction
//============================================================================
// FoodPool
//============================================================================
function FoodPool takes integer food, boolean weak, integer id1, integer use1, boolean strong, integer id2, integer use2 returns nothing
if strong then
call SetBuildUnit( (food - use1 * TownCount(id1)) / Max(1, use2), id2 )
elseif weak then
call SetBuildUnit( (food - use2 * TownCount(id2)) / Max(1, use1), id1 )
endif
endfunction
//============================================================================
// MeleeTownHall
//============================================================================
function MeleeTownHall takes integer townid, integer unitid returns nothing
if TownHasMine(townid) and not TownHasHall(townid) then
call SecondaryTown ( townid, 1, unitid )
endif
endfunction
//============================================================================
function WaitForUnits takes integer unitid, integer qty returns nothing
loop
exitwhen TownCountDone(unitid) == qty
call Sleep(2)
endloop
endfunction
//============================================================================
function StartUnit takes integer ask_qty, integer unitid, integer town returns boolean
local integer have_qty
local integer need_qty
local integer afford_gold
local integer afford_wood
local integer afford_qty
local integer gold_cost
local integer wood_cost
//------------------------------------------------------------------------
// if we have all we're asking for then make nothing
//
if town == -1 then
set have_qty = TownCount(unitid)
else
set have_qty = TownCountTown(unitid,town)
endif
if have_qty >= ask_qty then
return true
endif
set need_qty = ask_qty - have_qty
//------------------------------------------------------------------------
// limit the qty we're requesting to the amount of resources available
//
set gold_cost = GetUnitGoldCost(unitid)
set wood_cost = GetUnitWoodCost(unitid)
if gold_cost == 0 then
set afford_gold = need_qty
else
set afford_gold = total_gold / gold_cost
endif
if afford_gold < need_qty then
set afford_qty = afford_gold
else
set afford_qty = need_qty
endif
if wood_cost == 0 then
set afford_wood = need_qty
else
set afford_wood = total_wood / wood_cost
endif
if afford_wood < afford_qty then
set afford_qty = afford_wood
endif
// if we're waiting on gold/wood; pause build orders
if afford_qty < 1 then
return false
endif
//------------------------------------------------------------------------
// whether we make right now what we're requesting or not, assume we will
// and deduct the cost of the units from our fake gold total right away
//
set total_gold = total_gold - gold_cost * need_qty
set total_wood = total_wood - wood_cost * need_qty
if total_gold < 0 then
set total_gold = 0
endif
if total_wood < 0 then
set total_wood = 0
endif
//------------------------------------------------------------------------
// give the AI a chance to make the units (it may not be able to right now
// but that doesn't stop us from trying other units after this as long
// as we have enough money to make this AND the needed, unbuilt ones)
//
return SetProduce(afford_qty,unitid,town)
endfunction
//============================================================================
function WaitForTown takes integer towns, integer townid returns nothing
local integer i = 0
loop
call Sleep(10)
exitwhen TownCount(townid) >= towns
set i = i + 1
exitwhen i >= GetBJMaxPlayers()
endloop
endfunction
//============================================================================
function StartExpansion takes integer qty, integer hall returns boolean
local integer count
local integer town
local unit peon = null
local integer gold_cost
local boolean b = true
set count = TownCount(hall)
if count >= qty then
return true
endif
set town = GetNextExpansion()
if town == -1 then
return true
endif
set take_exp = true
set gold_cost = GetUnitGoldCost(hall)
if gold_cost > total_gold then
return false
endif
set total_gold = total_gold - gold_cost
if GetExpansionFoe() != null then
return true
endif
set peon = GetExpansionPeon()
if peon != null then
set b = SetExpansion(peon,hall)
set peon = null
return b
endif
return true
endfunction
//============================================================================
function OneBuildLoop takes nothing returns nothing
local integer index = 0
local integer qty
local integer id
local integer tp
set total_gold = GetGold() - gold_buffer
set total_wood = GetWood()
loop
exitwhen index == build_length
set qty = build_qty [index]
set id = build_item[index]
set tp = build_type[index]
//--------------------------------------------------------------------
if tp == BUILD_UNIT then
if not StartUnit(qty,id,build_town[index]) then
return
endif
//--------------------------------------------------------------------
elseif tp == BUILD_UPGRADE then
call StartUpgrade(qty,id)
//--------------------------------------------------------------------
else // tp == BUILD_EXPAND
if not StartExpansion(qty,id) then
return
endif
endif
set index = index + 1
endloop
endfunction
//============================================================================
function BuildLoop takes nothing returns nothing
call OneBuildLoop()
call StaggerSleep(1,2)
loop
call OneBuildLoop()
call Sleep(2)
endloop
endfunction
//============================================================================
function StartBuildLoop takes nothing returns nothing
call StartThread(function BuildLoop)
endfunction
//============================================================================
function SetInitialWave takes integer seconds returns nothing
set sleep_seconds = seconds
endfunction
//============================================================================
function AddSleepSeconds takes integer seconds returns nothing
set sleep_seconds = sleep_seconds + seconds
endfunction
//============================================================================
function SleepForever takes nothing returns nothing
call Trace("going to sleep forever\n") //xxx
loop
call Sleep(100)
endloop
endfunction
//============================================================================
function PlayGame takes nothing returns nothing
call StartBuildLoop()
call SleepForever()
endfunction
//============================================================================
function ConvertNeeds takes integer unitid returns nothing
if GetUnitCount(unitid) < 1 then
call StartUnit(1,unitid,-1)
endif
endfunction
//============================================================================
function Conversions takes integer desire, integer unitid returns nothing
if GetUnitCount(unitid) >= desire then
return
endif
#INCLUDETABLE <$VER$\UnitConversions.txt> #EFR
if unitid == %1 then
call ConvertNeeds(%2)
call ConvertNeeds(%3)
call MergeUnits(desire,%2,%3,%1)
endif
#ENDINCLUDE
#INCLUDETABLE <$VER$\UnitEquivalence.txt> #EFR #COND "%2" eq "BUILT_FROM"
if unitid == %1 then
call ConvertNeeds(%3)
call ConvertUnits(desire, %3)
endif
#ENDINCLUDE
endfunction
//============================================================================
function SetAssaultGroup takes integer qty, integer max, integer unitid returns nothing
call Conversions(max,unitid)
if qty <= 0 and TownCountDone(unitid) == 0 then
return
endif
set harass_qty[harass_length] = qty
set harass_max[harass_length] = max
set harass_units[harass_length] = unitid
set harass_length = harass_length + 1
endfunction
//============================================================================
function Interleave3 takes integer e1, integer m1, integer h1, integer u1, integer e2, integer m2, integer h2, integer u2, integer e3, integer m3, integer h3, integer u3 returns nothing
local integer i1 = 1
local integer i2 = 1
local integer i3 = 1
local integer q1
local integer q2
local integer q3
if difficulty == EASY then
set q1 = e1
set q2 = e2
set q3 = e3
elseif difficulty == NORMAL then
set q1 = m1
set q2 = m2
set q3 = m3
else // difficulty == HARD
set q1 = h1
set q2 = h2
set q3 = h3
endif
loop
exitwhen q1<=0 and q2<=0 and q3<=0
if q1 > 0 then
call SetAssaultGroup(i1,i1,u1)
set q1 = q1 - 1
set i1 = i1 + 1
endif
if q2 > 0 then
call SetAssaultGroup(i2,i2,u2)
set q2 = q2 - 1
set i2 = i2 + 1
endif
if q3 > 0 then
call SetAssaultGroup(i3,i3,u3)
set q3 = q3 - 1
set i3 = i3 + 1
endif
endloop
endfunction
//============================================================================
function SetMeleeGroup takes integer unitid returns nothing
if unitid == hero_id then
call SetAssaultGroup(1,9,unitid)
else
call SetAssaultGroup((TownCountDone(unitid)*3)/4,20,unitid)
endif
endfunction
//============================================================================
function CampaignDefender takes integer level, integer qty, integer unitid returns nothing
if qty > 0 and difficulty >= level then
set defense_qty[defense_length] = qty
set defense_units[defense_length] = unitid
set defense_length = defense_length + 1
call Conversions(qty,unitid)
call SetBuildUnit(qty,unitid)
endif
endfunction
//============================================================================
function CampaignDefenderEx takes integer easy, integer med, integer hard, integer unitid returns nothing
if difficulty == EASY then
call CampaignDefender(EASY,easy,unitid)
elseif difficulty == NORMAL then
call CampaignDefender(NORMAL,med,unitid)
else
call CampaignDefender(HARD,hard,unitid)
endif
endfunction
//============================================================================
function CampaignAttacker takes integer level, integer qty, integer unitid returns nothing
if qty > 0 and difficulty >= level then
call SetAssaultGroup(qty,qty,unitid)
endif
endfunction
//============================================================================
function CampaignAttackerEx takes integer easy, integer med, integer hard, integer unitid returns nothing
if difficulty == EASY then
call CampaignAttacker(EASY,easy,unitid)
elseif difficulty == NORMAL then
call CampaignAttacker(NORMAL,med,unitid)
else
call CampaignAttacker(HARD,hard,unitid)
endif
endfunction
//============================================================================
function FormGroup takes integer seconds, boolean testReady returns nothing
local integer index
local integer count
local integer unitid
local integer desire
local integer readyPercent
// normally test for CaptainReadiness() of 50%
if testReady == true then
set readyPercent = 50
call Trace("forming group, requiring healthy guys\n") //xxx
else
set readyPercent = 0
call Trace("forming group, unit health not important\n") //xxx
endif
call Trace("trying to gather forces\n") //xxx
loop
call SuicideSleep(seconds)
call InitAssault()
set index = 0
loop
exitwhen index == harass_length
set unitid = harass_units[index]
set desire = harass_max[index]
set count = TownCountDone(unitid)
call Conversions(desire,unitid)
if count >= desire then
call AddAssault(desire,unitid)
else
set desire = harass_qty[index]
if count < desire then
call AddAssault(desire,unitid)
else
call AddAssault(count,unitid)
endif
endif
set index = index + 1
endloop
//xxx
if form_group_timeouts and (sleep_seconds < -60) then
call Trace("exit form group -- timeout\n")
elseif CaptainInCombat(true) then
call Trace("exit form group -- can't form while already in combat\n")
elseif CaptainIsFull() and CaptainReadiness() >= readyPercent then
call Trace("exit form group -- ready\n")
endif
//xxx
// time out and send group anyway if time has already expired
exitwhen form_group_timeouts and (sleep_seconds < -60)
exitwhen CaptainInCombat(true)
exitwhen CaptainIsFull() and CaptainReadiness() >= readyPercent
endloop
endfunction
//============================================================================
function WavePrepare takes integer unitid returns integer
return GetUnitBuildTime(unitid)
endfunction
//============================================================================
function PrepTime takes nothing returns integer
local integer unitid
local integer missing
local integer prep
local integer count
local integer largest = 30
local integer index = 0
loop
exitwhen index == harass_length
set unitid = harass_units[index]
set missing = harass_qty[index] + IgnoredUnits(unitid) - TownCount(unitid)
set prep = WavePrepare(unitid) * missing
if prep > largest then
set largest = prep
endif
set index = index + 1
endloop
call TraceI("next wave will require around %d seconds to build and gather\n",largest) //xxx
return largest
endfunction
//============================================================================
function PrepSuicideOnPlayer takes integer seconds returns boolean
local integer wave_prep = PrepTime()
local integer save_length
set save_length = harass_length
set harass_length = 0
call AddSleepSeconds(seconds)
if sleep_seconds-wave_prep > 0 then
call TraceI("going to sleep for %d seconds before gathering next attack wave\n",sleep_seconds-wave_prep) //xxx
call SuicideSleep(sleep_seconds-wave_prep)
endif
call Trace("preparing suicide attack wave\n") //xxx
set harass_length = save_length
if harass_length < 1 then
call Trace("ERROR - no units specificed, exiting early\n") //xxx
return false
endif
return true
endfunction
//============================================================================
function SleepUntilAtGoal takes nothing returns nothing
loop
exitwhen CaptainRetreating()
exitwhen CaptainAtGoal() // reached goal
exitwhen CaptainIsHome() // failed to path and returned home
exitwhen CaptainIsEmpty() // all units died
call SuicideSleep(3)
endloop
endfunction
//============================================================================
function SleepInCombat takes nothing returns nothing
local integer count = 0
debug call Trace("SleepInCombat\n")
loop
loop
exitwhen not CaptainInCombat(true) // goal is cleared
exitwhen CaptainIsEmpty() // duh
call SuicideSleep(1)
endloop
set count = count + 1
exitwhen count >= 8
//xxx this is what it should have been; do this for next patch?
//call SuicideSleep(1)
endloop
debug call Trace("exit SleepInCombat\n")
endfunction
//============================================================================
function AttackMoveXYA takes integer x, integer y returns nothing
if zep_next_wave then
call LoadZepWave(x,y)
set zep_next_wave = false
endif
call AttackMoveXY(x,y)
call SleepUntilAtGoal()
call SleepInCombat()
endfunction
//============================================================================
function SuicideOnPlayerWave takes nothing returns nothing
call Trace("waiting for attack wave to enter combat\n") //xxx
loop
//xxx
if allow_signal_abort and CommandsWaiting() != 0 then
call Trace("ABORT -- attack wave override\n")
endif
if CaptainInCombat(true) then
call Trace("done - captain has entered combat\n")
endif
if CaptainIsEmpty() then
call Trace("done - all units are dead\n")
endif
if sleep_seconds < -300 then
call Trace("done - timeout, took too long to reach engage the enemy\n")
endif
//xxx
exitwhen allow_signal_abort and CommandsWaiting() != 0
exitwhen CaptainInCombat(true)
exitwhen CaptainIsEmpty()
call SuicideSleep(10)
exitwhen sleep_seconds < -300
endloop
call Trace("waiting for attack wave to die\n") //xxx
loop
//xxx
if allow_signal_abort and CommandsWaiting() != 0 then
call Trace("ABORT - attack wave override\n")
endif
if CaptainIsEmpty() then
call Trace("done - all units are dead\n")
endif
if sleep_seconds < -300 then
call Trace("done - timeout, took too long to reach engage the enemy\n")
endif
//xxx
exitwhen allow_signal_abort and CommandsWaiting() != 0
exitwhen CaptainIsEmpty()
call SuicideSleep(10)
exitwhen sleep_seconds < -300
endloop
endfunction
//--------------------------------------------------------------------------------------------------
function CommonSuicideOnPlayer takes boolean standard, boolean bldgs, integer seconds, player p, integer x, integer y returns nothing
local integer save_peons
if not PrepSuicideOnPlayer(seconds) then
return
endif
set save_peons = campaign_wood_peons
set campaign_wood_peons = 0
loop
//xxx
if allow_signal_abort and CommandsWaiting() != 0 then
call Trace("ABORT -- attack wave override\n")
endif
//xxx
exitwhen allow_signal_abort and CommandsWaiting() != 0
loop
exitwhen allow_signal_abort and CommandsWaiting() != 0
call FormGroup(5,true)
exitwhen sleep_seconds <= 0
call TraceI("waiting %d seconds before suicide\n",sleep_seconds) //xxx
endloop
if standard then
if bldgs then
exitwhen SuicidePlayer(p,sleep_seconds >= -60)
else
exitwhen SuicidePlayerUnits(p,sleep_seconds >= -60)
endif
else
call AttackMoveXYA(x,y)
endif
call TraceI("waiting %d seconds before timeout\n",60+sleep_seconds) //xxx
call SuicideSleep(5)
endloop
set campaign_wood_peons = save_peons
set harass_length = 0
call SuicideOnPlayerWave()
endfunction
//--------------------------------------------------------------------------------------------------
function SuicideOnPlayer takes integer seconds, player p returns nothing
call CommonSuicideOnPlayer(true,true,seconds,p,0,0)
endfunction
//--------------------------------------------------------------------------------------------------
function SuicideOnUnits takes integer seconds, player p returns nothing
call CommonSuicideOnPlayer(true,false,seconds,p,0,0)
endfunction
//--------------------------------------------------------------------------------------------------
function SuicideOnPoint takes integer seconds, player p, integer x, integer y returns nothing
call CommonSuicideOnPlayer(false,false,seconds,p,x,y)
endfunction
//============================================================================
function SuicideUntilSignal takes integer seconds, player p returns nothing
local integer save
local integer wave_prep = PrepTime()
loop
call AddSleepSeconds(seconds)
if sleep_seconds-wave_prep > 0 then
call SuicideSleep(sleep_seconds-wave_prep)
endif
set save = campaign_wood_peons
set campaign_wood_peons = 0
loop
loop
call FormGroup(5, true)
exitwhen sleep_seconds <= 0
exitwhen CommandsWaiting() != 0
endloop
exitwhen SuicidePlayer(p,sleep_seconds >= -60)
exitwhen CommandsWaiting() != 0
call SuicideSleep(3)
endloop
set campaign_wood_peons = save
loop
exitwhen CaptainIsEmpty()
exitwhen CommandsWaiting() != 0
call SuicideSleep(5)
endloop
exitwhen CommandsWaiting() != 0
endloop
endfunction
//--------------------------------------------------------------------------------------------------
function SuicideOnce takes integer easy, integer med, integer hard, integer unitid returns nothing
if difficulty == EASY then
call SuicideUnit(easy,unitid)
elseif difficulty == NORMAL then