-
Notifications
You must be signed in to change notification settings - Fork 34
/
Blizzard.eai
1984 lines (1796 loc) · 66.1 KB
/
Blizzard.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
#INCLUDE <$VER$\tmp\Blizzard1.j>
//-----------------------------------------------------------------------
// Commander globals
//-----------------------------------------------------------------------
// default values
string language = "" // Possible values: "" (dialog), "English", "Deutsch", "Swedish", "French", "Spanish", "Romanian", "Russian", "Portuguese", "Norwegian", "Chinese"
string game_mode = "" // Possible values: "" (dialog), "commander", "no_human", "ai_only", "shared"
integer array command_number
integer array command_par1
integer array command_par2
integer array command_par3
string array command_key1
string array command_key2
string array command_key3
string array command_text1
string array command_text2
string array command_text3
string array command_text4
string array command_dlg1
integer array command_hotkey1
string array command_dlg2
integer array command_hotkey2
string array command_dlg3
integer array command_hotkey3
string array command_msg
integer command_length = 0
string array parsed_command
string command_prefix = "-cmd"
button array cdlg_button
integer array cdlg_number
dialog array cdlg_dialog
integer cdlg_length = 0
dialog number_dialog = null
dialog last_number_dialog = null
dialog player_dialog = null
dialog last_player_dialog = null
dialog start_dialog = null
dialog root_dialog = null
dialog clanguage_dialog = null
dialog tribute_type_dlg = null
integer array current_command
integer array current_player_par
integer array current_number_par
player array commanded_player
#INCLUDETABLE <$VER$\Races.txt>
string array %1_StrategyName
integer %1_strategyNum = 0
#ENDINCLUDE
button strategyBtn = null
boolean strategyDialog = false
string array tribute_type
button tribute_g = null
button tribute_l = null
button tribute_give_g = null
button tribute_give_l = null
dialog tribute_dlg = null
button array tribute_dlg_button
integer tribute_dlg_length = 0
button array sdbn_button
integer array sdbn_number
integer sdbn_length = 0
integer sdbn_paged_length = 0
button array pcbn_button
integer array pcbn_number
integer pcbn_length = 0
integer pcbn_paged_length = 0
button array ndbn_button
button next_button = null
button previous_button = null
button all_button = null
button clanguage_button = null
integer ndbn_length = 0
integer ndbn_paged_length = 0
dialog array dlg_dialog
string array dlg_string
integer dlg_length = 0
trigger ZoomSetx = null
trigger AdjustZoomUp = null
trigger AdjustZoomDown = null
boolean array ZoomKey
real array current_zoom
dialog game_start_dialog = null
trigger game_start_trigger = null
button commander_mode = null
button no_human_mode = null
button shared_mode = null
button ai_only_mode = null
dialog language_dialog = null
trigger language_trigger = null
#INCLUDETABLE <Languages.txt> #EFR
button %1_button = null
#ENDINCLUDE
string chat_no_ally = ""
string you_no_gold = ""
string i_no_gold = ""
string tribute_of_gold = ""
string gold_received_thanks = ""
string you_no_lumber = ""
string i_no_lumber = ""
string tribute_of_lumber = ""
string lumber_received_thanks = ""
string you_mistyped_tribute = ""
string specified_player_not_valid = ""
string command_not_valid = ""
string all_not_allowed = ""
string player_id_mistyped = ""
string color_word_mistyped = ""
string not_specified_computer = ""
string dlgbutton_next_page = ""
string dlgbutton_previous_page = ""
string dlghdr_choose_ally = ""
string dlghdr_choose_number = ""
string dlghdr_choose_player = ""
string dlghdr_game_type = ""
string dlghdr_root = ""
string dlghdr_tribute_type = ""
string dlghdr_tribute_amount = ""
string dlgbutton_cancel = ""
string dlgbutton_all = ""
string dlgbutton_gold = ""
string dlgbutton_lumber = ""
string dlgbutton_give_gold = "Give Gold"
string dlgbutton_give_lumber = "Give Lumber"
string dlgbutton_tribute = ""
string dlgbutton_commander = ""
string dlgbutton_commander_language = ""
string dlgbutton_player_ally = ""
string dlgbutton_no_human = ""
string dlgbutton_shared = ""
string dlgbutton_ai_only = ""
boolean debugging = false
string dglchoose_language = "Choose Language"
leaderboard color_board = null
//gamecache translation = InitGameCache("Commander.w3v")
hashtable translation = InitHashtable()
timer last_timer = null
trigger last_player_trigger = null
triggeraction last_player_trigger_action = null
trigger last_number_trigger = null
triggeraction last_number_trigger_action = null
trigger last_dialog_trigger = null
triggeraction last_dialog_trigger_action = null
trigger last_main_trigger = null
trigger array dlg_trigger
trigger array last_tribute_trigger
#DEFINE GLOBAL
#INCLUDESCRIPT <$VER$\custom_common.eai>
#UNDEF GLOBAL
#INCLUDE <$VER$\tmp\Blizzard2.j>
#INCLUDESCRIPT <$VER$\custom_common.eai>
#INCLUDE <$VER$\tmp\Blizzard3Gen.j>
#INCLUDE <$VER$\tmp\Blizzard4.j>
function DestroyLastTrigger takes trigger t, triggeraction ta returns nothing
if (ta != null and t != null) then
call TriggerRemoveAction(t, ta)
endif
if (t != null) then
call TriggerClearActions(t)
call DestroyTrigger(t)
endif
endfunction
//***************************************************************************
//*
//* Commander
//*
//***************************************************************************
function DisplayToTP takes string msg returns nothing
call DisplayTimedTextToPlayer(GetTriggerPlayer(), 0, 0, 5, msg )
endfunction
function TraceToTP takes string msg returns nothing
if debugging then
call DisplayToTP(msg)
endif
endfunction
function DisplayToPlayer takes player p, string msg returns nothing
call DisplayTimedTextToPlayer(p, 0, 0, 5, msg )
endfunction
function DisplayToAll takes string msg returns nothing
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 7, msg )
endfunction
function TraceToAll takes string msg returns nothing
if debugging then
call DisplayToAll(msg)
endif
endfunction
//===========================================================================
// The Parser (Takes a String, Seperates words, puts in string array)
//===========================================================================
function Parser takes string ChatMsg returns nothing
//Required Variables
local integer Last = 0
local integer A = 1
local integer I = 0
local integer Length = StringLength(ChatMsg)
call TraceToAll("Parser run:" + ChatMsg)
//Pulls Words and places them each in their own Variable
loop
if (SubStringBJ(ChatMsg,A,A) == " ") then
set parsed_command[I] = StringCase(SubStringBJ(ChatMsg, (Last + 1), (A - 1)), true)
set Last = A
set I = I + 1
elseif (SubStringBJ(ChatMsg,A,A) == ":") then
if (SubStringBJ(ChatMsg,A+1,A+1) == " ") then
set A = A + 1 // space after the : so include in separator
endif
set parsed_command[I] = StringCase(SubStringBJ(ChatMsg, (Last + 1), (A - 1)), true)
set Last = A
set I = I + 1
elseif (A == Length) then
set parsed_command[I] = StringCase(SubStringBJ(ChatMsg, (Last + 1), A), true)
set I = I + 1
endif
set A = A + 1
exitwhen(A>Length)
endloop
loop
exitwhen I > 6
set parsed_command[I] = ""
set I = I + 1
endloop
endfunction
//===========================================================================
// ColorPlayer (Converts from text version of a color to a playercolor)
//===========================================================================
function ColorPlayer takes string CompC returns playercolor
//Finds player color of the text color
if (CompC == "Red") then
return PLAYER_COLOR_RED
elseif (CompC == "Blue") then
return PLAYER_COLOR_BLUE
elseif (CompC == "Cyan") then
return PLAYER_COLOR_CYAN
elseif (CompC == "Purple") then
return PLAYER_COLOR_PURPLE
elseif (CompC == "Yellow") then
return PLAYER_COLOR_YELLOW
elseif (CompC == "Orange") then
return PLAYER_COLOR_ORANGE
elseif (CompC == "Green") then
return PLAYER_COLOR_GREEN
elseif (CompC == "Pink") then
return PLAYER_COLOR_PINK
elseif (CompC == "Light Gray") then
return PLAYER_COLOR_LIGHT_GRAY
elseif (CompC == "Light Blue") then
return PLAYER_COLOR_LIGHT_BLUE
elseif (CompC == "Aqua") then
return PLAYER_COLOR_AQUA
elseif (CompC == "Brown") then
return PLAYER_COLOR_BROWN
elseif (CompC == "MAROON") then
return PLAYER_COLOR_MAROON
elseif (CompC == "Navy") then
return PLAYER_COLOR_NAVY
elseif (CompC == "Turquoise") then
return PLAYER_COLOR_TURQUOISE
elseif (CompC == "Violet") then
return PLAYER_COLOR_VIOLET
elseif (CompC == "Wheat") then
return PLAYER_COLOR_WHEAT
elseif (CompC == "Peach") then
return PLAYER_COLOR_PEACH
elseif (CompC == "Mint") then
return PLAYER_COLOR_MINT
elseif (CompC == "Lavender") then
return PLAYER_COLOR_LAVENDER
elseif (CompC == "Coal") then
return PLAYER_COLOR_COAL
elseif (CompC == "Snow") then
return PLAYER_COLOR_SNOW
elseif (CompC == "Emerald") then
return PLAYER_COLOR_EMERALD
elseif (CompC == "Peanut") then
return PLAYER_COLOR_PEANUT
else
return null
endif
endfunction
#INCLUDE <playercolors.j>
function c2s takes player p returns string
return cs2s(GetPlayerName(p), GetPlayerColor(p)) + ": "
endfunction
function DisplayFromPlayer takes player p, string msg returns nothing
call DisplayToTP(c2s(p) + msg)
endfunction
function DisplayFromToPlayer takes player sp, player rp, string msg returns nothing
call DisplayToPlayer(rp, c2s(sp) + msg)
endfunction
function DisplayFromDlg takes string msg returns nothing
if msg == "" or commanded_player[GetPlayerId(GetTriggerPlayer())] == Player(PLAYER_NEUTRAL_AGGRESSIVE) then
return
endif
if GetTriggerPlayer() != null then
if commanded_player[GetPlayerId(GetTriggerPlayer())] != null then
call DisplayFromToPlayer(commanded_player[GetPlayerId(GetTriggerPlayer())], GetTriggerPlayer(), msg)
else
call DisplayToPlayer(commanded_player[GetPlayerId(GetTriggerPlayer())], msg)
endif
else
call DisplayToAll(msg)
endif
endfunction
//===========================================================================
// Sync integer
//===========================================================================
function SyncInteger takes player sync_p, integer unsynced returns integer
local integer array source_int // the bits of the unsynced integer are stored in there
local integer array target_int // the bits of the synced integer are stored in there
local unit array sel_unit // the units used for the selection
local integer i = 1
local integer j = 0
local integer sum = unsynced
local group old_selection = null
local unit u = null
local integer bits_per_selection = 8 // that many bits are sent per selection
local integer selection_num = 2 // that many times a selection is done
local integer bits_number = selection_num * bits_per_selection // number of bits of integer used
local timer t = null
local location l = null
// call DisplayToPlayer(sync_p, I2S(sum))
if bj_isSinglePlayer then
return unsynced
endif
set old_selection = CreateGroup()
set t = CreateTimer()
// separate integer in bits
if sum < 0 then
set source_int[0] = 1
set sum = -sum
else
set source_int[0] = 0
endif
loop
exitwhen i >= bits_number
set source_int[i] = ModuloInteger(sum, 2)
set sum = sum / 2
set i = i + 1
endloop
// create units to select
set i = 0
set l = GetPlayerStartLocationLoc(sync_p)
loop
exitwhen i >= bits_per_selection
set sel_unit[i] = CreateUnitAtLoc( sync_p, 'nshf', l, bj_UNIT_FACING )
set i = i + 1
endloop
call RemoveLocation(l)
set l = null
// save old selection
call SyncSelections()
call GroupEnumUnitsSelected(old_selection, sync_p, null)
// send the bits by selection
set i = 0
loop
exitwhen i >= selection_num
// write information
if GetLocalPlayer() == sync_p then
set j = 0
call ClearSelection()
loop
exitwhen j >= bits_per_selection
if source_int[i*bits_per_selection + j] == 0 then
call SelectUnit(sel_unit[j], false)
else
call SelectUnit(sel_unit[j], true)
endif
set j = j + 1
endloop
endif
// read information
call TimerStart(t, 1, false, null) // prevent wait bug
loop
exitwhen TimerGetRemaining(t) <= 0
call TriggerSleepAction(0.5)
endloop
call DestroyTimer(t)
set t = null
call SyncSelections()
set j = 0
loop
exitwhen j >= bits_per_selection
if IsUnitSelected(sel_unit[j], sync_p) then
set target_int[i*bits_per_selection + j] = 1
else
set target_int[i*bits_per_selection + j] = 0
endif
set j = j + 1
endloop
set i = i + 1
endloop
// restore selection
if GetLocalPlayer() == sync_p then
call ClearSelection()
loop
set u = FirstOfGroup(old_selection)
exitwhen u == null
call SelectUnit(u, true)
call GroupRemoveUnit(old_selection, u)
endloop
endif
call SyncSelections()
// remove units to select
set i = 0
loop
exitwhen i >= bits_per_selection
call RemoveUnit(sel_unit[i])
set sel_unit[i] = null
set i = i + 1
endloop
// rebuild integer
set i = bits_number - 1
set sum = 0
loop
exitwhen i < 1
set sum = 2 * sum + target_int[i]
set i = i - 1
endloop
if target_int[0] != 0 then
set sum = -sum
endif
call DestroyGroup(old_selection)
set old_selection = null
set u = null
// call DisplayToPlayer(sync_p, I2S(sum))
return sum
endfunction
//===========================================================================
// Convert2Player (Converts either text color or id to player)
//===========================================================================
function Convert2Player takes string Comp, boolean all_allowed returns player
//Required Variables
local integer j = 0
local playercolor CColor = ColorPlayer(Comp) //Gets the player color
local player theplayer = null
if Comp == "All" then
if all_allowed then
set theplayer = Player(PLAYER_NEUTRAL_AGGRESSIVE)
else
call DisplayToTP(all_not_allowed)
endif
elseif (CColor == null) then
//Makes Sure color was typed Correctly
//Makes sure number is 0 - max number of players
if (S2I(Comp) >= 0) and (S2I(Comp) < GetBJMaxPlayers()) then
set theplayer = Player(S2I(Comp))
else
call DisplayToTP(player_id_mistyped)
endif
else
//Compares the color until we get a match then stores that player
loop
exitwhen((CColor == GetPlayerColor(Player(j))) or (j > GetBJMaxPlayers()))
set j = j + 1
if (j > GetBJMaxPlayers()) then
call DisplayToTP(color_word_mistyped)
endif
endloop
if j <= GetBJMaxPlayers() then
set theplayer = Player(j)
endif
endif
set CColor = null
//Returns player
return theplayer
endfunction
//===========================================================================
// Colorboard Function (Displays all the Colors on screen)
//===========================================================================
//Required by GetPlayersMatching to select a players playing
function GetPlayersMatchingCode takes nothing returns boolean
return ( GetPlayerSlotState(GetFilterPlayer()) == PLAYER_SLOT_STATE_PLAYING )
endfunction
//Required by ForForce to add a player name for each player
function ForForceCode takes nothing returns nothing
call LeaderboardAddItemBJ(GetEnumPlayer(), color_board, GetPlayerName(GetEnumPlayer()), 0 )
call LeaderboardSetPlayerItemLabelBJ(GetEnumPlayer(), color_board, ColorText(GetPlayerColor(GetEnumPlayer())))
call LeaderboardSetPlayerItemValueBJ(GetEnumPlayer(), color_board, GetPlayerId(GetEnumPlayer()))
endfunction
//The Main function for Showing the Colorboard
function CreateBoard takes nothing returns nothing
//Required Variables
local integer j = 0
//Creates Colorboard
set color_board =CreateLeaderboardBJ( GetPlayersAll(), "Colorboard" ) //Creates board
//Adds all player to Colorboard
call ForForce( GetPlayersMatching(Condition(function GetPlayersMatchingCode)), function ForForceCode )
//Displays the Colorboard
call LeaderboardDisplay(color_board, false)
endfunction
function ShowBoard takes nothing returns nothing
call LeaderboardDisplay(color_board, not IsLeaderboardDisplayed(color_board))
endfunction
//===========================================================================
// Zoom
//===========================================================================
function ZoomSet takes nothing returns nothing
local real Zoom = 0
local integer i = GetPlayerId(GetTriggerPlayer())
call TraceToAll("ZOOM SET Triggered")
if SubStringBJ(GetEventPlayerChatString(), 6, 6) != "k" then
if SubStringBJ(GetEventPlayerChatString(), 6, 6) != " " then
set Zoom = S2R(SubStringBJ(GetEventPlayerChatString(), 6, 10))
else
set Zoom = S2R(SubStringBJ(GetEventPlayerChatString(), 7, 11))
endif
if (GetTriggerPlayer() == GetLocalPlayer()) then
if Zoom < 1650 then
call SetCameraFieldForPlayer( GetTriggerPlayer(), CAMERA_FIELD_TARGET_DISTANCE, 1650, 0 )
call DisplayTimedTextToPlayer(GetTriggerPlayer(), 0, 0, 7, "zoom min:|cff00ff001650|r" )
elseif Zoom > 3000 then
call SetCameraFieldForPlayer( GetTriggerPlayer(), CAMERA_FIELD_TARGET_DISTANCE, 3000, 0 )
call DisplayTimedTextToPlayer(GetTriggerPlayer(), 0, 0, 7, "zoom max:|cff00ff003000|r" )
else
call SetCameraFieldForPlayer( GetTriggerPlayer(), CAMERA_FIELD_TARGET_DISTANCE, Zoom, 0 )
endif
endif
// Fix desync, variables must be same across players
if Zoom < 1650 then
set current_zoom[i] = 1650
elseif Zoom > 3000 then
set current_zoom[i] = 3000
else
set current_zoom[i] = Zoom
endif
elseif legacyCamera then
if ZoomKey[i] == true then
set ZoomKey[i] = false
call DisplayTimedTextToPlayer(GetTriggerPlayer(), 0, 0, 7, "Zoom Hot Key: |cfffd0000[off]|r" )
else
set ZoomKey[i] = true
call DisplayTimedTextToPlayer(GetTriggerPlayer(), 0, 0, 7, "Zoom Hot Key: |cff00ff00[on]|r" )
endif
endif
endfunction
function ZoomDown takes nothing returns nothing
local integer i = GetPlayerId(GetTriggerPlayer())
if ZoomKey[i] and current_zoom[i] > 1650 then
if GetTriggerPlayer() == GetLocalPlayer() then
call SetCameraFieldForPlayer(GetTriggerPlayer(), CAMERA_FIELD_TARGET_DISTANCE, ( current_zoom[i] - 50 ), 0 )
set current_zoom[i] = current_zoom[i] - 50
endif
endif
endfunction
function ZoomUp takes nothing returns nothing
local integer i = GetPlayerId(GetTriggerPlayer())
if ZoomKey[i] and current_zoom[i] < 3000 then
if GetTriggerPlayer() == GetLocalPlayer() then
call SetCameraFieldForPlayer(GetTriggerPlayer(), CAMERA_FIELD_TARGET_DISTANCE, ( current_zoom[i] + 50 ), 0 )
set current_zoom[i] = current_zoom[i] + 50
endif
endif
endfunction
function InitZoom takes nothing returns nothing
local integer i = 0
set ZoomSetx = CreateTrigger()
set AdjustZoomUp = CreateTrigger()
set AdjustZoomDown = CreateTrigger()
call TriggerAddAction(ZoomSetx, function ZoomSet)
call TriggerAddAction(AdjustZoomUp , function ZoomUp)
call TriggerAddAction(AdjustZoomDown , function ZoomDown)
loop
exitwhen i >= GetBJMaxPlayers()
if (GetPlayerController(Player(i)) != MAP_CONTROL_COMPUTER) then
call DisplayTimedTextToPlayer(Player(i),0,0,7,"Set Zoom type: |c00d5f038-zoom1850|r")
call TriggerRegisterPlayerChatEvent( ZoomSetx, Player(i), "-zoom", false )
if (legacyCamera) then // Only required for legacy versions as no camera support built into the game
call TriggerRegisterPlayerKeyEventBJ( AdjustZoomUp, Player(i), bj_KEYEVENTTYPE_DEPRESS, bj_KEYEVENTKEY_UP )
call TriggerRegisterPlayerKeyEventBJ( AdjustZoomDown, Player(i), bj_KEYEVENTTYPE_DEPRESS, bj_KEYEVENTKEY_DOWN )
set current_zoom[i] = 1650 // Default expected in legacy systems
set ZoomKey[i] = true
call DisplayTimedTextToPlayer(Player(i),0,0,7,"Enable/Disable Zoom Hot Keys: |c00d5f038-zoomkey|r")
if IsPlayerObserver(Player(i)) then
call SetCameraFieldForPlayer(Player(i), CAMERA_FIELD_TARGET_DISTANCE, 1950, 0)
set current_zoom[i] = 1950
endif
endif
endif
set i = i + 1
endloop
endfunction
//===========================================================================
// Help Function (Displays help on screen)
//===========================================================================
function DisplayHelpToPlayer takes player p, string msg returns nothing
if msg == "PAUSE" then
call TriggerSleepAction( 15.00 )
else
call DisplayTimedTextToPlayer(p, 0, 0, 15, msg)
endif
endfunction
function Helpin takes nothing returns nothing
local player p = GetTriggerPlayer()
#INCLUDETABLE <Languages\CommanderHelp.txt>
call DisplayHelpToPlayer(p, "%1")
#ENDINCLUDE
set p = null
endfunction
//===========================================================================
// Map Initialization (Runs all stuff needed to be run after map is loaded)
//===========================================================================
function MapInit takes nothing returns nothing
call DestroyTimer(last_timer)
//Displays the Leaderboard
call CreateBoard()
//Display Commander Message
if false then
#INCLUDETABLE <Languages.txt> #EFR
elseif language == "%1" then
#INCLUDETABLE <Languages\%1\CommanderStart.txt> #ENC:%4
call DisplayToAll("|c0000ffff%1|r")
#ENDINCLUDE
#ENDINCLUDE
endif
endfunction
//===========================================================================
// Tribute Function (Allows computer allies to give you resources)
//===========================================================================
function TributeGold takes player Commander, player Comp, integer res_amount returns nothing
if res_amount < 0 then
set res_amount = -res_amount
if GetPlayerState(Commander, PLAYER_STATE_RESOURCE_GOLD) >= res_amount then
call SetPlayerState(Comp, PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(Comp, PLAYER_STATE_RESOURCE_GOLD) + res_amount)
call SetPlayerState(Commander, PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(Commander, PLAYER_STATE_RESOURCE_GOLD) - res_amount)
call DisplayFromToPlayer(Comp, Commander, I2S(res_amount) + gold_received_thanks)
//You don't have enough Gold to share
else
call DisplayFromToPlayer(Comp, Commander, you_no_gold)
endif
elseif GetPlayerState(Comp, PLAYER_STATE_RESOURCE_GOLD) >= res_amount then
call SetPlayerState(Comp, PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(Comp, PLAYER_STATE_RESOURCE_GOLD) - res_amount)
call SetPlayerState(Commander, PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(Commander, PLAYER_STATE_RESOURCE_GOLD) + res_amount)
call DisplayFromToPlayer(Comp, Commander, I2S(res_amount) + tribute_of_gold)
//I don't have enough Gold to share
else
call DisplayFromToPlayer(Comp, Commander, i_no_gold)
endif
endfunction
function TributeWood takes player Commander, player Comp, integer res_amount returns nothing
if res_amount < 0 then
set res_amount = -res_amount
if GetPlayerState(Commander, PLAYER_STATE_RESOURCE_LUMBER) >= res_amount then
call SetPlayerState(Comp, PLAYER_STATE_RESOURCE_LUMBER, GetPlayerState(Comp, PLAYER_STATE_RESOURCE_LUMBER) + res_amount)
call SetPlayerState(Commander, PLAYER_STATE_RESOURCE_LUMBER, GetPlayerState(Commander, PLAYER_STATE_RESOURCE_LUMBER) - res_amount)
call DisplayFromToPlayer(Comp, Commander, I2S(res_amount) + lumber_received_thanks)
//You don't have enough Lumber to share
else
call DisplayFromToPlayer(Comp, Commander, you_no_lumber)
endif
elseif GetPlayerState(Comp, PLAYER_STATE_RESOURCE_LUMBER) >= res_amount then
call SetPlayerState(Comp, PLAYER_STATE_RESOURCE_LUMBER, GetPlayerState(Comp, PLAYER_STATE_RESOURCE_LUMBER) - res_amount)
call SetPlayerState(Commander, PLAYER_STATE_RESOURCE_LUMBER, GetPlayerState(Commander, PLAYER_STATE_RESOURCE_LUMBER) + res_amount)
call DisplayFromToPlayer(Comp, Commander, I2S(res_amount) + tribute_of_lumber)
//I don't have enough Lumber to share
else
call DisplayFromToPlayer(Comp, Commander, i_no_lumber)
endif
endfunction
function TributeGoldFromAll takes player Commander, integer res_amount returns nothing
local integer i = 0
loop
exitwhen i >= GetBJMaxPlayers()
if IsPlayerAlly(Commander, Player(i)) and GetPlayerController(Player(i)) == MAP_CONTROL_COMPUTER then
call TributeGold(Commander, Player(i),res_amount)
endif
set i = i + 1
endloop
endfunction
function TributeWoodFromAll takes player Commander, integer res_amount returns nothing
local integer i = 0
loop
exitwhen i >= GetBJMaxPlayers()
if IsPlayerAlly(Commander,Player(i)) and GetPlayerController(Player(i)) == MAP_CONTROL_COMPUTER then
call TributeWood(Commander, Player(i),res_amount)
endif
set i = i + 1
endloop
endfunction
function Tribute takes player Commander, player Comp, string LorG, string ResAmount returns nothing
//Player wants Gold
if (LorG == "G") or (LorG == "GiveG") or (LorG == "Gold") then
if LorG == "GiveG" then
set ResAmount = "-" + ResAmount
endif
if Comp == Player(PLAYER_NEUTRAL_AGGRESSIVE) then
call TributeGoldFromAll(Commander, S2I(ResAmount))
else
call TributeGold(Commander, Comp, S2I(ResAmount))
endif
//Player wants Lumber
elseif (LorG == "L") or (LorG == "GiveL") or (LorG == "Lumber") then
if LorG == "GiveL" then
set ResAmount = "-" + ResAmount
endif
if Comp == Player(PLAYER_NEUTRAL_AGGRESSIVE) then
call TributeWoodFromAll(Commander, S2I(ResAmount))
else
call TributeWood(Commander, Comp, S2I(ResAmount))
endif
//Didn't type L or G
else
call DisplayToPlayer(Commander, you_mistyped_tribute)
endif
endfunction
//===========================================================================
// Execute Command
//===========================================================================
function GetParValue takes integer par returns integer
local player p = null
local integer pid = -1
if par == -1 then
return 0
elseif par == -30 then
return SyncInteger(GetTriggerPlayer(), R2I(GetCameraTargetPositionX()))
elseif par == -31 then
return SyncInteger(GetTriggerPlayer(), R2I(GetCameraTargetPositionY()))
elseif par == -40 then
return GetPlayerId(GetTriggerPlayer())
elseif par < -100 then
set p = Convert2Player(parsed_command[-(par + 100)], false)
if p == null then
return -1000000
else
set pid = GetPlayerId(p)
set p = null
return pid
endif
elseif par < 0 then
return S2I(parsed_command[-par])
else
return par
endif
endfunction
function ExecuteCommand takes player Comp, integer number returns nothing
local integer cn = GetParValue(command_number[number])
local integer par1 = GetParValue(command_par1[number])
local integer par2 = GetParValue(command_par2[number])
local integer par3 = GetParValue(command_par3[number])
if cn == -1000000 or par1 == -1000000 or par2 == -1000000 or par3 == -1000000 then
return
endif
if command_par2[number] != -1 then
call CommandAI(Comp, par2, par3)
endif
if command_number[number] != -1 then
call CommandAI(Comp, cn, par1)
endif
call DisplayFromPlayer(Comp, command_msg[number])
endfunction
function ExecuteCommandForAll takes integer number returns nothing
local integer i = 0
loop
exitwhen i >= GetBJMaxPlayers()
if (IsPlayerAlly(GetTriggerPlayer(),Player(i))) and GetPlayerController(Player(i)) == MAP_CONTROL_COMPUTER then
call ExecuteCommand(Player(i), number)
endif
set i = i + 1
endloop
endfunction
function GetDlgParValue takes integer par returns integer
if par == -1 then
return 0
elseif par == -30 then
return SyncInteger(GetTriggerPlayer(), R2I(GetCameraTargetPositionX()))
elseif par == -31 then
return SyncInteger(GetTriggerPlayer(), R2I(GetCameraTargetPositionY()))
elseif par == -40 then
return GetPlayerId(GetTriggerPlayer())
elseif par < -100 then
return current_player_par[GetPlayerId(GetTriggerPlayer())]
elseif par < 0 then
return current_number_par[GetPlayerId(GetTriggerPlayer())]
else
return par
endif
endfunction
function ExecuteDlgCommand takes player Comp, integer number returns nothing
local integer cn = GetDlgParValue(command_number[number])
local integer par1 = GetDlgParValue(command_par1[number])
local integer par2 = GetDlgParValue(command_par2[number])
local integer par3 = GetDlgParValue(command_par3[number])
if command_par2[number] != -1 then
call CommandAI(Comp, par2, par3)
endif
if command_number[number] != -1 then
call CommandAI(Comp, cn, par1)
endif
call DisplayFromDlg(command_msg[number])
endfunction
function ExecuteDlgCommandForAll takes integer number returns nothing
local integer i = 0
loop
exitwhen i >= GetBJMaxPlayers()
if IsPlayerAlly(GetTriggerPlayer(),Player(i)) and GetPlayerController(Player(i)) == MAP_CONTROL_COMPUTER then
set commanded_player[GetPlayerId(GetTriggerPlayer())] = Player(i)
call ExecuteDlgCommand(Player(i), number)
endif
set i = i + 1
endloop
endfunction
function ExecuteDialogCommand takes player Comp, integer number returns nothing
if commanded_player[GetPlayerId(GetTriggerPlayer())] == Player(PLAYER_NEUTRAL_AGGRESSIVE) then
call ExecuteDlgCommandForAll(number)
else
call ExecuteDlgCommand(Comp, number)
endif
endfunction
//===========================================================================
// Find Command
//===========================================================================
function FindCommand takes nothing returns integer
local integer i = 0
loop
exitwhen i >= command_length
if command_key1[i] == "" or command_key1[i] == parsed_command[2] then
if command_key2[i] == "" or command_key2[i] == parsed_command[3] then
exitwhen command_key3[i] == "" or command_key3[i] == parsed_command[4]
endif
endif
set i = i + 1
endloop
if i >= command_length then
return -1
else
return i
endif
endfunction
#INCLUDETABLE <Languages.txt> #EFR
function initLanguage%1 takes nothing returns nothing
#INCLUDETABLE <Languages\%1\Commander.txt> #ENC:%4 #EFR
set %1 = "%2"
#ENDINCLUDE
// English backup if translation missing
#INCLUDETABLE <Languages\English\Commander.txt> #ENC:%4 #EFR
if %1 == null or %1 == "" then
set %1 = "%2"
endif
#ENDINCLUDE
#INCLUDETABLE <Languages\%1\CommandsTrans.txt> #ENC:%4 #EFR
call SaveStr(translation, StringHash(language), StringHash("%1"), "%2")
#ENDINCLUDE
#INCLUDETABLE <Languages\%1\Strategy.txt> #ENC:%4 #EFR
call SaveStr(translation, StringHash(language), StringHash("%1"), "%2")
#ENDINCLUDE
#INCLUDETABLE <Languages\English\Strategy.txt> #ENC:%4 #EFR
call SaveStr(translation, StringHash("English"), StringHash("%1"), "%2")
#ENDINCLUDE
endfunction
#ENDINCLUDE
//===========================================================================
// The Commander
//===========================================================================
function AddCancelButton takes dialog d returns nothing
call DialogAddButton(d, dlgbutton_cancel, 8) // backspace
endfunction
function AddNextButton takes dialog d returns nothing
set next_button = DialogAddButton(d, dlgbutton_next_page, 78) // n
endfunction
function AddPreviousButton takes dialog d returns nothing
set previous_button = DialogAddButton(d, dlgbutton_previous_page, 80) // p
endfunction
function AddCDCancelButtons takes nothing returns nothing
local integer i = 0
loop
exitwhen i >= dlg_length
call AddCancelButton(dlg_dialog[i])
set i = i + 1
endloop
endfunction
function RegisterCDialogButton takes button b, integer cn, dialog d returns nothing
set cdlg_button[cdlg_length] = b
set cdlg_number[cdlg_length] = cn
set cdlg_dialog[cdlg_length] = d
set cdlg_length = cdlg_length + 1
//call DisplayToAll("RegsiterButton:" + I2S(cn) + " length:" + I2S(cdlg_length))
endfunction
function FindDialog takes string s returns dialog
local integer i = 0
loop
exitwhen i >= dlg_length
if dlg_string[i] == s then
return dlg_dialog[i]
endif
set i = i + 1
endloop
return null
endfunction
function TributeDialogResponse takes nothing returns nothing
local button b = GetClickedButton()