-
Notifications
You must be signed in to change notification settings - Fork 0
/
formations_scripts.py
3189 lines (2932 loc) · 127 KB
/
formations_scripts.py
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
# Formations for Warband by Motomataru
# rel. 05/02/11
#EDITED FOR MANY DIVISIONS BY CABA'DRIN 02/23/11
from header_common import *
from header_operations import *
from module_constants import *
from header_parties import *
from header_skills import *
from header_mission_templates import *
from header_items import *
from header_triggers import *
from header_terrain_types import *
from header_music import *
from ID_animations import *
####################################################################################################################
# scripts is a list of script records.
# Each script record contns the following two fields:
# 1) Script id: The prefix "script_" will be inserted when referencing scripts.
# 2) Operation block: This must be a valid operation block. See header_operations.py for reference.
####################################################################################################################
scripts = [
# #Formations Scripts
# script_division_reset_places by motomataru
# Input: none
# Output: none
# Resets globals for placing divisions around player for script_battlegroup_place_around_leader
("division_reset_places", [
(assign, "$next_cavalry_place", formation_minimum_spacing_horse_width), #first spot RIGHT of the player
(assign, "$next_archer_place", 1000), #first spot 10m FRONT of the player
(assign, "$next_infantry_place", -1 * formation_minimum_spacing_horse_width), #first spot LEFT of the player
]),
# script_battlegroup_place_around_leader by motomataru
# Input: team, division
# Output: pos61 division position
("battlegroup_place_around_leader", [
(store_script_param, ":fteam", 1),
(store_script_param, ":fdivision", 2),
(team_get_leader, ":fleader", ":fteam"),
(try_begin),
(gt, ":fleader", -1), #any team members left?
(agent_get_position, pos1, ":fleader"),
(try_begin),
(eq, "$autorotate_at_player", 1),
(call_script, "script_team_get_position_of_enemies", Enemy_Team_Pos, ":fteam", grc_everyone),
(neq, reg0, 0), #more than 0 enemies still alive?
(call_script, "script_point_y_toward_position", pos1, Enemy_Team_Pos),
(try_end),
(store_add, ":slot", slot_team_d0_type, ":fdivision"),
(team_get_slot, ":sd_type", ":fteam", ":slot"),
(store_add, ":slot", slot_team_d0_size, ":fdivision"),
(team_get_slot, ":num_troops", ":fteam", ":slot"),
(store_add, ":slot", slot_team_d0_formation, ":fdivision"),
(team_get_slot, ":fformation", ":fteam", ":slot"),
(store_add, ":slot", slot_team_d0_formation_space, ":fdivision"),
(team_get_slot, ":formation_extra_spacing", ":fteam", ":slot"),
(try_begin),
(this_or_next|eq, ":sd_type", sdt_cavalry),
(eq, ":sd_type", sdt_harcher),
(position_move_x, pos1, "$next_cavalry_place", 0),
(try_begin), #handle Native's way of doing things
(eq, ":fformation", formation_none),
(try_begin),
(ge, ":formation_extra_spacing", 0),
(store_mul, ":troop_space", ":formation_extra_spacing", 133),
(val_add, ":troop_space", 150),
(else_try), #handle Native multi-ranks
(assign, ":troop_space", 200),
(val_mul, ":formation_extra_spacing", -1),
(val_add, ":formation_extra_spacing", 1),
(val_div, ":num_troops", ":formation_extra_spacing"),
(try_end),
(store_mul, ":formation_width", ":num_troops", ":troop_space"),
(store_div, reg0, ":formation_width", 2),
(position_move_x, pos1, reg0, 0), #cavalry set up RIGHT of leader
(copy_position, pos61, pos1),
(else_try),
(store_mul, ":troop_space", ":formation_extra_spacing", 50),
(val_add, ":troop_space", formation_minimum_spacing_horse_width),
(convert_to_fixed_point, ":num_troops"),
(store_sqrt, ":formation_width", ":num_troops"),
(val_mul, ":formation_width", ":troop_space"),
(convert_from_fixed_point, ":formation_width"),
(val_sub, ":formation_width", ":troop_space"),
(store_div, reg0, ":formation_width", 2),
(position_move_x, pos1, reg0, 0), #cavalry set up RIGHT of leader
(copy_position, pos61, pos1),
(call_script, "script_form_cavalry", ":fteam", ":fdivision", ":fleader", ":formation_extra_spacing"),
(try_end),
(val_add, "$next_cavalry_place", ":formation_width"),
(val_add, "$next_cavalry_place", formation_minimum_spacing_horse_width),
(else_try),
(eq, ":sd_type", sdt_archer),
(position_move_y, pos1, "$next_archer_place"), #archers set up FRONT of leader
(copy_position, pos61, pos1),
(try_begin),
(neq, ":fformation", formation_none),
(call_script, "script_get_centering_amount", formation_default, ":num_troops", ":formation_extra_spacing"),
(val_mul, reg0, -1),
(position_move_x, pos1, reg0, 0),
(call_script, "script_form_archers", ":fteam", ":fdivision", ":fleader", ":formation_extra_spacing", ":fformation"),
(try_end),
(val_add, "$next_archer_place", 500), #next archers 5m FRONT of these
(else_try),
(eq, ":sd_type", sdt_skirmisher),
(position_move_y, pos1, "$next_archer_place"), #skirmishers set up FRONT of leader
(copy_position, pos61, pos1),
(try_begin),
(neq, ":fformation", formation_none),
(call_script, "script_get_centering_amount", ":fformation", ":num_troops", ":formation_extra_spacing"),
(position_move_x, pos1, reg0, 0),
(call_script, "script_form_infantry", ":fteam", ":fdivision", ":fleader", ":formation_extra_spacing", ":fformation"),
(try_end),
(val_add, "$next_archer_place", 500), #next archers 5m FRONT of these
(else_try),
(position_move_x, pos1, "$next_infantry_place", 0),
(copy_position, pos61, pos1),
(try_begin), #handle Native's way of doing things
(eq, ":fformation", formation_none),
(try_begin),
(ge, ":formation_extra_spacing", 0),
(store_mul, ":troop_space", ":formation_extra_spacing", 75), #Native minimum spacing not consistent but less than this
(val_add, ":troop_space", 100),
(else_try), #handle Native multi-ranks
(assign, ":troop_space", 150),
(val_mul, ":formation_extra_spacing", -1),
(val_add, ":formation_extra_spacing", 1),
(val_div, ":num_troops", ":formation_extra_spacing"),
(try_end),
(store_mul, ":formation_width", ":num_troops", ":troop_space"),
(store_div, reg0, ":formation_width", 2),
(val_mul, reg0, -1), #infantry set up LEFT of leader
(position_move_x, pos61, reg0, 0),
(else_try),
(call_script, "script_form_infantry", ":fteam", ":fdivision", ":fleader", ":formation_extra_spacing", ":fformation"),
(call_script, "script_get_centering_amount", ":fformation", ":num_troops", ":formation_extra_spacing"),
(store_mul, ":formation_width", 2, reg0),
(store_mul, ":troop_space", ":formation_extra_spacing", 50),
(val_add, ":troop_space", formation_minimum_spacing),
(val_add, ":formation_width", ":troop_space"),
(val_mul, reg0, -1), #infantry set up LEFT of leader
(position_move_x, pos61, reg0, 0),
(try_end),
(val_sub, "$next_infantry_place", ":formation_width"), #next infantry 1m LEFT of these
(val_sub, "$next_infantry_place", 100),
(try_end),
(store_add, ":slot", slot_team_d0_move_order, ":fdivision"),
(team_set_slot, ":fteam", ":slot", mordr_hold),
(set_show_messages, 0),
(team_get_movement_order, reg0, ":fteam", ":fdivision"),
(try_begin),
(neq, reg0, mordr_hold),
(team_give_order, ":fteam", ":fdivision", mordr_hold),
(try_end),
(call_script, "script_set_formation_destination", ":fteam", ":fdivision", pos61),
(set_show_messages, 1),
(try_end),
]),
# script_battlegroup_place_at_leader by Caba'drin
# Input: team, division
# Output: pos61 division position
("battlegroup_place_at_leader", [
(store_script_param, ":fteam", 1),
(store_script_param, ":fdivision", 2),
(team_get_leader, ":fleader", ":fteam"),
(try_begin),
(gt, ":fleader", -1), #any team members left?
(agent_get_position, pos1, ":fleader"),
(try_begin),
(eq, "$autorotate_at_player", 1),
(call_script, "script_team_get_position_of_enemies", pos60, ":fteam", grc_everyone),
(neq, reg0, 0), #more than 0 enemies still alive?
(call_script, "script_point_y_toward_position", pos1, pos60),
(try_end),
(store_add, ":slot", slot_team_d0_type, ":fdivision"),
(team_get_slot, ":sd_type", ":fteam", ":slot"),
(store_add, ":slot", slot_team_d0_size, ":fdivision"),
(team_get_slot, ":num_troops", ":fteam", ":slot"),
(store_add, ":slot", slot_team_d0_formation, ":fdivision"),
(team_get_slot, ":fformation", ":fteam", ":slot"),
(store_add, ":slot", slot_team_d0_formation_space, ":fdivision"),
(team_get_slot, ":formation_extra_spacing", ":fteam", ":slot"),
(copy_position, pos61, pos1),
(neq, ":fformation", formation_none),
(try_begin),
(this_or_next|eq, ":sd_type", sdt_cavalry),
(eq, ":sd_type", sdt_harcher),
(call_script, "script_form_cavalry", ":fteam", ":fdivision", ":fleader", ":formation_extra_spacing"),
(else_try),
(eq, ":sd_type", sdt_archer),
(call_script, "script_get_centering_amount", formation_default, ":num_troops", ":formation_extra_spacing"),
(val_mul, reg0, -1),
(position_move_x, pos1, reg0, 0),
(call_script, "script_form_archers", ":fteam", ":fdivision", ":fleader", ":formation_extra_spacing", ":fformation"),
(else_try),
(eq, ":sd_type", sdt_skirmisher),
(call_script, "script_get_centering_amount", ":fformation", ":num_troops", ":formation_extra_spacing"),
(position_move_x, pos1, reg0, 0),
(call_script, "script_form_infantry", ":fteam", ":fdivision", ":fleader", ":formation_extra_spacing", ":fformation"),
(else_try),
(call_script, "script_form_infantry", ":fteam", ":fdivision", ":fleader", ":formation_extra_spacing", ":fformation"),
(try_end),
(store_add, ":slot", slot_team_d0_move_order, ":fdivision"),
(team_set_slot, ":fteam", ":slot", mordr_hold),
(set_show_messages, 0),
(team_get_movement_order, reg0, ":fteam", ":fdivision"),
(try_begin),
(neq, reg0, mordr_hold),
(team_give_order, ":fteam", ":fdivision", mordr_hold),
(try_end),
(call_script, "script_set_formation_destination", ":fteam", ":fdivision", pos61),
(set_show_messages, 1),
(try_end),
]),
# script_form_cavalry by motomataru
# Input: (pos1), team, division, agent number of team leader, spacing
# Output: none
# Form in wedge, (now not) excluding horse archers
# Creates formation starting at pos1
("form_cavalry", [
(store_script_param, ":fteam", 1),
(store_script_param, ":fdivision", 2),
(store_script_param, ":fleader", 3),
(store_script_param, ":formation_extra_spacing", 4),
(store_mul, ":extra_space", ":formation_extra_spacing", 50),
(store_add, ":x_distance", formation_minimum_spacing_horse_width, ":extra_space"),
(store_add, ":y_distance", formation_minimum_spacing_horse_length, ":extra_space"),
(store_add, ":slot", slot_team_d0_first_member, ":fdivision"),
(team_set_slot, ":fteam", ":slot", -1),
(assign, ":max_level", 0),
(try_for_agents, ":agent"),
(call_script, "script_cf_valid_formation_member", ":fteam", ":fdivision", ":fleader", ":agent"),
(agent_get_troop_id, ":troop_id", ":agent"),
(store_character_level, ":troop_level", ":troop_id"),
(gt, ":troop_level", ":max_level"),
(assign, ":max_level", ":troop_level"),
(end_try),
(assign, ":column", 1),
(assign, ":rank_dimension", 1),
(store_mul, ":neg_y_distance", ":y_distance", -1),
(store_mul, ":neg_x_distance", ":x_distance", -1),
(store_div, ":wedge_adj", ":x_distance", 2),
(store_div, ":neg_wedge_adj", ":neg_x_distance", 2),
(val_add, ":max_level", 1),
(assign, ":form_left", 1),
(try_for_range_backwards, ":rank_level", 0, ":max_level"), #put troops with highest exp in front
(try_for_agents, ":agent"),
(agent_get_troop_id, ":troop_id", ":agent"),
(store_character_level, ":troop_level", ":troop_id"),
(eq, ":troop_level", ":rank_level"),
(call_script, "script_cf_valid_formation_member", ":fteam", ":fdivision", ":fleader", ":agent"),
(agent_set_scripted_destination, ":agent", pos1, 1),
(try_begin), #First Agent
(store_add, ":slot", slot_team_d0_first_member, ":fdivision"),
(neg|team_slot_ge, ":fteam", ":slot", 0),
(team_set_slot, ":fteam", ":slot", ":agent"),
(try_end),
(try_begin),
(eq, ":form_left", 1),
(position_move_x, pos1, ":neg_x_distance", 0),
(else_try),
(position_move_x, pos1, ":x_distance", 0),
(try_end),
(val_add, ":column", 1),
(gt, ":column", ":rank_dimension"),
(position_move_y, pos1, ":neg_y_distance", 0),
(try_begin),
(neq, ":form_left", 1),
(assign, ":form_left", 1),
(position_move_x, pos1, ":neg_wedge_adj", 0),
(else_try),
(assign, ":form_left", 0),
(position_move_x, pos1, ":wedge_adj", 0),
(try_end),
(assign, ":column", 1),
(val_add, ":rank_dimension", 1),
(end_try),
(end_try),
]),
# script_form_archers by motomataru
# Input: (pos1), team, division, agent number of team leader, spacing, formation
# Output: none
# Form in line, staggered if formation = formation_ranks
# Creates formation starting at pos1
("form_archers", [
(store_script_param, ":fteam", 1),
(store_script_param, ":fdivision", 2),
(store_script_param, ":fleader", 3),
(store_script_param, ":formation_extra_spacing", 4),
(store_script_param, ":archers_formation", 5),
(store_mul, ":extra_space", ":formation_extra_spacing", 50),
(store_add, ":distance", formation_minimum_spacing, ":extra_space"), #minimum distance between troops
(store_add, ":slot", slot_team_d0_first_member, ":fdivision"),
(team_set_slot, ":fteam", ":slot", -1),
(assign, ":total_move_y", 0), #staggering variable
(try_for_agents, ":agent"),
(call_script, "script_cf_valid_formation_member", ":fteam", ":fdivision", ":fleader", ":agent"),
(agent_set_scripted_destination, ":agent", pos1, 1),
(try_begin), #First Agent
(store_add, ":slot", slot_team_d0_first_member, ":fdivision"),
(neg|team_slot_ge, ":fteam", ":slot", 0),
(team_set_slot, ":fteam", ":slot", ":agent"),
(try_end),
(position_move_x, pos1, ":distance", 0),
(try_begin),
(eq, ":archers_formation", formation_ranks),
(val_add, ":total_move_y", 75),
(try_begin),
(le, ":total_move_y", 150),
(position_move_y, pos1, 75, 0),
(else_try),
(position_move_y, pos1, -150, 0),
(assign, ":total_move_y", 0),
(try_end),
(try_end),
(try_end),
]),
# script_form_infantry by motomataru
# Input: (pos1), team, division, agent number of team leader, spacing, formation
# Output: none
# If input "formation" is formation_default, will select a formation based on faction
# Creates formation starting at pos1
("form_infantry", [
(store_script_param, ":fteam", 1),
(store_script_param, ":fdivision", 2),
(store_script_param, ":fleader", 3),
(store_script_param, ":formation_extra_spacing", 4),
(store_script_param, ":infantry_formation", 5),
(store_mul, ":extra_space", ":formation_extra_spacing", 50),
(store_add, ":distance", formation_minimum_spacing, ":extra_space"), #minimum distance between troops
(store_mul, ":neg_distance", ":distance", -1),
(store_add, ":slot", slot_team_d0_first_member, ":fdivision"),
(team_set_slot, ":fteam", ":slot", -1),
(store_add, ":slot", slot_team_d0_size, ":fdivision"),
(team_get_slot, ":num_troops", ":fteam", ":slot"),
(try_begin),
(eq, ":infantry_formation", formation_default),
(call_script, "script_get_default_formation", ":fteam"),
(assign, ":infantry_formation", reg0),
(try_end),
(team_get_weapon_usage_order, ":weapon_order", ":fteam", ":fdivision"),
(team_get_hold_fire_order, ":fire_order", ":fteam", ":fdivision"),
(assign, ":form_left", 1),
(assign, ":column", 1),
(assign, ":rank", 1),
(try_begin),
(eq, ":infantry_formation", formation_square),
(convert_to_fixed_point, ":num_troops"),
(store_sqrt, ":square_dimension", ":num_troops"),
(convert_from_fixed_point, ":square_dimension"),
(val_add, ":square_dimension", 1),
(try_for_agents, ":agent"),
(call_script, "script_cf_valid_formation_member", ":fteam", ":fdivision", ":fleader", ":agent"),
(try_begin), ##CABA - Deployment
(eq, "$battle_phase", BP_Spawn), ##CABA - Deployment
(agent_set_scripted_destination, ":agent", pos1), ##CABA - Deployment
(else_try), ##CABA - Deployment
(call_script, "script_formation_process_agent_move", ":fteam", ":fdivision", ":agent", ":rank"),
(try_end), ##CABA - Deployment
(try_begin),
(eq, formation_reequip, 1),
(eq, ":weapon_order", wordr_use_any_weapon),
(try_begin),
(this_or_next|eq, ":rank", 1),
(this_or_next|ge, ":rank", ":square_dimension"),
(this_or_next|eq, ":column", 1),
(ge, ":column", ":square_dimension"),
(call_script, "script_equip_best_melee_weapon", ":agent", 0, 0, ":fire_order"),
(agent_set_slot, ":agent", slot_agent_inside_formation, 0),
(else_try),
(call_script, "script_equip_best_melee_weapon", ":agent", 0, 1, ":fire_order"),
(agent_set_slot, ":agent", slot_agent_inside_formation, 1),
(try_end),
(try_end),
(try_begin),
(eq, ":form_left", 1),
(position_move_x, pos1, ":neg_distance", 0),
(else_try),
(position_move_x, pos1, ":distance", 0),
(try_end),
(val_add, ":column", 1),
(gt, ":column", ":square_dimension"),
(position_move_y, pos1, ":neg_distance", 0),
(try_begin),
(neq, ":form_left", 1),
(assign, ":form_left", 1),
(position_move_x, pos1, ":neg_distance", 0),
(else_try),
(assign, ":form_left", 0),
(position_move_x, pos1, ":distance", 0),
(try_end),
(assign, ":column", 1),
(val_add, ":rank", 1),
(end_try),
(else_try),
(eq, ":infantry_formation", formation_wedge),
(assign, ":max_level", 0),
(try_for_agents, ":agent"),
(call_script, "script_cf_valid_formation_member", ":fteam", ":fdivision", ":fleader", ":agent"),
(agent_get_troop_id, ":troop_id", ":agent"),
(store_character_level, ":troop_level", ":troop_id"),
(gt, ":troop_level", ":max_level"),
(assign, ":max_level", ":troop_level"),
(end_try),
(assign, ":rank_dimension", 1),
(store_div, ":wedge_adj", ":distance", 2),
(store_div, ":neg_wedge_adj", ":neg_distance", 2),
(val_add, ":max_level", 1),
(try_for_range_backwards, ":rank_level", 0, ":max_level"), #put troops with highest exp in front
(try_for_agents, ":agent"),
(agent_get_troop_id, ":troop_id", ":agent"),
(store_character_level, ":troop_level", ":troop_id"),
(eq, ":troop_level", ":rank_level"),
(call_script, "script_cf_valid_formation_member", ":fteam", ":fdivision", ":fleader", ":agent"),
(try_begin), ##CABA - Deployment
(eq, "$battle_phase", BP_Spawn), ##CABA - Deployment
(agent_set_scripted_destination, ":agent", pos1), ##CABA - Deployment
(else_try), ##CABA - Deployment
(call_script, "script_formation_process_agent_move", ":fteam", ":fdivision", ":agent", ":rank_dimension"),
(try_end), ##CABA - Deployment
(try_begin),
(eq, formation_reequip, 1),
(eq, ":weapon_order", wordr_use_any_weapon),
(try_begin),
(this_or_next|eq, ":column", 1),
(ge, ":column", ":rank_dimension"),
(call_script, "script_equip_best_melee_weapon", ":agent", 0, 0, ":fire_order"),
(agent_set_slot, ":agent", slot_agent_inside_formation, 0),
(else_try),
(call_script, "script_equip_best_melee_weapon", ":agent", 0, 1, ":fire_order"),
(agent_set_slot, ":agent", slot_agent_inside_formation, 1),
(try_end),
(try_end),
(try_begin),
(eq, ":form_left", 1),
(position_move_x, pos1, ":neg_distance", 0),
(else_try),
(position_move_x, pos1, ":distance", 0),
(try_end),
(val_add, ":column", 1),
(gt, ":column", ":rank_dimension"),
(position_move_y, pos1, ":neg_distance", 0),
(try_begin),
(neq, ":form_left", 1),
(assign, ":form_left", 1),
(position_move_x, pos1, ":neg_wedge_adj", 0),
(else_try),
(assign, ":form_left", 0),
(position_move_x, pos1, ":wedge_adj", 0),
(try_end),
(assign, ":column", 1),
(val_add, ":rank_dimension", 1),
(end_try),
(end_try),
(else_try),
(eq, ":infantry_formation", formation_ranks),
(store_div, ":rank_dimension", ":num_troops", 3), #basic three ranks
(val_add, ":rank_dimension", 1),
(assign, ":max_level", 0),
(try_for_agents, ":agent"),
(call_script, "script_cf_valid_formation_member", ":fteam", ":fdivision", ":fleader", ":agent"),
(agent_get_troop_id, ":troop_id", ":agent"),
(store_character_level, ":troop_level", ":troop_id"),
(gt, ":troop_level", ":max_level"),
(assign, ":max_level", ":troop_level"),
(end_try),
(val_add, ":max_level", 1),
(try_for_range_backwards, ":rank_level", 0, ":max_level"), #put troops with highest exp in front
(try_for_agents, ":agent"),
(agent_get_troop_id, ":troop_id", ":agent"),
(store_character_level, ":troop_level", ":troop_id"),
(eq, ":troop_level", ":rank_level"),
(call_script, "script_cf_valid_formation_member", ":fteam", ":fdivision", ":fleader", ":agent"),
(try_begin), ##CABA - Deployment
(eq, "$battle_phase", BP_Spawn), ##CABA - Deployment
(agent_set_scripted_destination, ":agent", pos1), ##CABA - Deployment
(else_try), ##CABA - Deployment
(call_script, "script_formation_process_agent_move", ":fteam", ":fdivision", ":agent", ":rank"),
(try_end), ##CABA - Deployment
(try_begin),
(eq, formation_reequip, 1),
(eq, ":weapon_order", wordr_use_any_weapon),
(try_begin),
(eq, ":rank", 1),
(call_script, "script_equip_best_melee_weapon", ":agent", 0, 0, ":fire_order"),
(agent_set_slot, ":agent", slot_agent_inside_formation, 0),
(else_try),
(call_script, "script_equip_best_melee_weapon", ":agent", 0, 1, ":fire_order"),
(agent_set_slot, ":agent", slot_agent_inside_formation, 1),
(try_end),
(try_end),
(try_begin),
(eq, ":form_left", 1),
(position_move_x, pos1, ":neg_distance", 0),
(else_try),
(position_move_x, pos1, ":distance", 0),
(try_end),
(val_add, ":column", 1),
(gt, ":column", ":rank_dimension"), #next rank?
(position_move_y, pos1, ":neg_distance", 0),
(try_begin),
(neq, ":form_left", 1),
(assign, ":form_left", 1),
(position_move_x, pos1, ":neg_distance", 0),
(else_try),
(assign, ":form_left", 0),
(position_move_x, pos1, ":distance", 0),
(try_end),
(assign, ":column", 1),
(val_add, ":rank", 1),
(end_try),
(end_try),
(else_try),
(eq, ":infantry_formation", formation_shield),
(store_div, ":rank_dimension", ":num_troops", 3), #basic three ranks
(val_add, ":rank_dimension", 1),
(assign, ":first_second_rank_agent", -1),
(assign, ":min_len_non_shielded", -1),
(try_for_range, ":weap_group", 0, 4),
(store_mul, ":min_len", ":weap_group", Third_Max_Weapon_Length),
(store_add, ":max_len", ":min_len", Third_Max_Weapon_Length),
(try_begin),
(gt, ":min_len_non_shielded", -1), #looped through agents at least once since rank 2
(assign, ":min_len_non_shielded", ":min_len"),
(try_end),
(try_for_agents, ":agent"),
(call_script, "script_cf_valid_formation_member", ":fteam", ":fdivision", ":fleader", ":agent"),
(agent_get_wielded_item, ":agent_weapon", ":agent", 0),
(try_begin),
(gt, ":agent_weapon", itm_no_item),
#(item_get_slot, ":weapon_length", ":agent_weapon", slot_item_length),
(item_get_weapon_length, ":weapon_length", ":agent_weapon"), #WSE
(else_try),
(assign, ":weapon_length", 0),
(try_end),
(try_begin),
(gt, ":rank", 1),
(try_begin),
(eq, ":first_second_rank_agent", ":agent"), #looped through agents at least once since rank 2
(assign, ":min_len_non_shielded", ":min_len"),
(else_try),
(eq, ":first_second_rank_agent", -1),
(assign, ":first_second_rank_agent", ":agent"),
(try_end),
(eq, formation_reequip, 1),
(eq, ":weapon_order", wordr_use_any_weapon),
(ge, ":weapon_length", ":min_len"), #avoid reequipping agents that are already in formation
(eq, ":min_len_non_shielded", -1), #haven't looped through agents at least once since rank 2
(call_script, "script_equip_best_melee_weapon", ":agent", 0, 1, ":fire_order"), #longest weapon, including two-handed
(agent_set_slot, ":agent", slot_agent_inside_formation, 1),
(agent_get_wielded_item, ":agent_weapon", ":agent", 0),
(try_begin),
(gt, ":agent_weapon", itm_no_item),
#(item_get_slot, ":weapon_length", ":agent_weapon", slot_item_length),
(item_get_weapon_length, ":weapon_length", ":agent_weapon"), #WSE
(else_try),
(assign, ":weapon_length", 0),
(try_end),
(try_end),
(assign, ":form_up", 0),
(agent_get_wielded_item, ":agent_shield", ":agent", 1),
(try_begin),
(gt, ":agent_shield", itm_no_item),
(item_get_type, reg0, ":agent_shield"),
(eq, reg0, itp_type_shield),
(try_begin),
(is_between, ":weapon_length", ":min_len", ":max_len"),
(assign, ":form_up", 1),
(try_end),
(else_try),
(this_or_next|gt, ":rank", 1),
(gt, ":weap_group", 2),
(is_between, ":weapon_length", ":min_len_non_shielded", ":max_len"),
(assign, ":form_up", 1),
(try_end),
(eq, ":form_up", 1),
(try_begin), ##CABA - Deployment
(eq, "$battle_phase", BP_Spawn), ##CABA - Deployment
(agent_set_scripted_destination, ":agent", pos1), ##CABA - Deployment
(else_try), ##CABA - Deployment
(call_script, "script_formation_process_agent_move", ":fteam", ":fdivision", ":agent", ":rank"),
(try_end), ##CABA - Deployment
(try_begin),
(eq, formation_reequip, 1),
(eq, ":weapon_order", wordr_use_any_weapon),
(eq, ":rank", 1),
(call_script, "script_equip_best_melee_weapon", ":agent", 1, 0, ":fire_order"), #best weapon, force shield
(agent_set_slot, ":agent", slot_agent_inside_formation, 0),
(try_end),
(try_begin),
(eq, ":form_left", 1),
(position_move_x, pos1, ":neg_distance", 0),
(else_try),
(position_move_x, pos1, ":distance", 0),
(try_end),
(val_add, ":column", 1),
(gt, ":column", ":rank_dimension"), #next rank?
(position_move_y, pos1, ":neg_distance", 0),
(try_begin),
(neq, ":form_left", 1),
(assign, ":form_left", 1),
(position_move_x, pos1, ":neg_distance", 0),
(else_try),
(assign, ":form_left", 0),
(position_move_x, pos1, ":distance", 0),
(try_end),
(assign, ":column", 1),
(val_add, ":rank", 1),
(try_end),
(try_end),
(try_end),
#calculate percent in place from counts from section above (see script_formation_process_agent_move)
(store_add, ":slot", slot_team_d0_size, ":fdivision"),
(team_get_slot, ":num_troops", ":fteam", ":slot"),
(store_add, ":slot", slot_team_d0_percent_in_place, ":fdivision"),
(team_get_slot, reg0, ":fteam", ":slot"),
(val_mul, reg0, 100),
(val_div, reg0, ":num_troops"),
(team_set_slot, ":fteam", ":slot", reg0),
]),
# script_get_default_formation by motomataru
# Input: team id
# Output: reg0 default formation
("get_default_formation", [
(store_script_param, ":fteam", 1),
(team_get_slot, ":ffaction", ":fteam", slot_team_faction),
(try_begin),
(this_or_next|eq, ":ffaction", fac_player_supporters_faction),
(eq, ":ffaction", fac_player_faction),
(is_between, "$players_kingdom", npc_kingdoms_begin, npc_kingdoms_end),
(assign, ":ffaction", "$players_kingdom"),
(try_end),
#assign default formation
(try_begin),
(eq, ":ffaction", fac_kingdom_1), #Swadians
(assign, reg0, formation_shield),
(else_try),
(eq, ":ffaction", fac_kingdom_2), #Vaegirs
(assign, reg0, formation_ranks),
(else_try),
(eq, ":ffaction", fac_kingdom_3), #Khergit
(assign, reg0, formation_none), #Khergit have underdeveloped infantry
(else_try),
(eq, ":ffaction", fac_kingdom_4), #Nords
(assign, reg0, formation_shield),
(else_try),
(eq, ":ffaction", fac_kingdom_5), #Rhodoks
(assign, reg0, formation_shield),
(else_try),
(eq, ":ffaction", fac_kingdom_6), #Sarranid
(assign, reg0, formation_ranks),
(else_try),
(this_or_next|eq, ":ffaction", fac_player_supporters_faction),
(eq, ":ffaction", fac_player_faction), #independent player
(assign, reg0, formation_ranks),
(else_try),
(assign, reg0, formation_none), #riffraff don't use formations
(try_end),
]),
# script_formation_process_agent_move by motomataru
# Input: (pos1), team, division, agent, which rank of formation agent is in
# Output: (pos1) may change to reference first agent's anticipated position
# This function sets scripted destination and performs other tasks related to making the formation look nice on the move (and more)
("formation_process_agent_move", [
(store_script_param, ":fteam", 1),
(store_script_param, ":fdivision", 2),
(store_script_param, ":agent", 3),
(store_script_param, ":rank", 4),
(agent_set_scripted_destination, ":agent", pos1, 1),
(agent_get_position, Current_Pos, ":agent"),
(get_distance_between_positions, ":distance_to_go", Current_Pos, pos1),
(store_add, ":slot", slot_team_d0_speed_limit, ":fdivision"),
(team_get_slot, ":speed_limit", ":fteam", ":slot"),
(agent_get_speed, Speed_Pos, ":agent"),
(position_transform_position_to_parent, Temp_Pos, Current_Pos, Speed_Pos),
(call_script, "script_point_y_toward_position", Current_Pos, Temp_Pos), #get direction of travel
(store_mul, ":expected_travel", reg0, formation_reform_interval),
(store_div, ":speed", ":expected_travel", Km_Per_Hour_To_Cm),
#First Agent
(try_begin),
(store_add, ":slot", slot_team_d0_first_member, ":fdivision"),
(neg|team_slot_ge, ":fteam", ":slot", 0),
(team_set_slot, ":fteam", ":slot", ":agent"),
(try_begin), #reset speed when first member stopped
(le, ":speed", 5), #minimum observed speed
(store_add, ":slot", slot_team_d0_speed_limit, ":fdivision"),
(team_set_slot, ":fteam", ":slot", Top_Speed),
(agent_set_speed_limit, ":agent", Top_Speed),
(else_try), #first member in motion
(val_mul, ":speed", 2), #after terrain & encumbrance, agents tend to move about half their speed limit
(try_begin), #speed up if everyone caught up
(store_add, ":slot", slot_team_d0_percent_in_place, ":fdivision"),
(team_slot_ge, ":fteam", ":slot", 100),
(try_begin),
(ge, ":speed", ":speed_limit"),
(val_add, ":speed_limit", 1),
(try_end),
(else_try), #else slow down
(val_min, ":speed_limit", ":speed"),
(val_sub, ":speed_limit", 1),
(val_max, ":speed_limit", 5), #minimum observed speed
(try_end),
#build formation from first agent
(store_add, ":slot", slot_team_d0_prev_first_member, ":fdivision"),
(team_slot_eq, ":fteam", ":slot", ":agent"), #looking at same first member as last call?
(store_mul, ":expected_travel", ":speed_limit", Km_Per_Hour_To_Cm),
(lt, ":expected_travel", ":distance_to_go"), #more than one call from destination?
(store_add, ":slot", slot_team_d0_speed_limit, ":fdivision"),
(team_set_slot, ":fteam", ":slot", ":speed_limit"),
(agent_set_speed_limit, ":agent", ":speed_limit"),
(copy_position, Temp_Pos, Current_Pos),
(call_script, "script_point_y_toward_position", Temp_Pos, pos1),
(position_move_y, Temp_Pos, ":expected_travel", 0), #anticipate where first member will be next
(position_copy_rotation, Temp_Pos, pos1), #conserve destination facing of formation
(copy_position, pos1, Temp_Pos), #reference the rest of the formation to first member's anticipated position
(try_end),
(store_add, ":slot", slot_team_d0_percent_in_place, ":fdivision"),
(team_set_slot, ":fteam", ":slot", 1), #reinit: always count first member as having arrived
(store_add, ":slot", slot_team_d0_prev_first_member, ":fdivision"),
(team_set_slot, ":fteam", ":slot", ":agent"),
#Not First Agent
(else_try),
(try_begin),
(le, ":speed", 0),
(assign, ":speed_limit", Top_Speed),
(else_try),
(neg|position_is_behind_position, pos1, Current_Pos),
(store_div, ":speed_limit", ":distance_to_go", Km_Per_Hour_To_Cm),
(val_max, ":speed_limit", 1),
(else_try),
(store_add, ":slot", slot_team_d0_in_melee, ":fdivision"),
(team_slot_eq, ":fteam", ":slot", 0),
(assign, ":speed_limit", 1),
(else_try),
(assign, ":speed_limit", Top_Speed),
(try_end),
(agent_set_speed_limit, ":agent", ":speed_limit"),
(try_begin),
(this_or_next|le, ":speed", 0), #reached previous destination or blocked OR
(this_or_next|lt, ":speed_limit", Top_Speed), #destination within reach OR
(position_is_behind_position, pos1, Current_Pos), #agent ahead of formation
(store_add, ":slot", slot_team_d0_percent_in_place, ":fdivision"),
(team_get_slot, reg0, ":fteam", ":slot"),
(val_add, reg0, 1),
(team_set_slot, ":fteam", ":slot", reg0),
(try_end),
(try_end),
#Housekeeping
(try_begin),
(eq, ":rank", 1),
(agent_set_slot, ":agent", slot_agent_in_first_rank, 1),
(else_try),
(agent_set_slot, ":agent", slot_agent_in_first_rank, 0),
(try_end),
]),
# script_equip_best_melee_weapon by motomataru
# Input: agent id, flag to force shield, flag to force for length ALONE, current fire order
# Output: none
# Caba - edit to comply with weapon/shield-type orders
("equip_best_melee_weapon", [
(store_script_param, ":agent", 1),
(store_script_param, ":force_shield", 2),
(store_script_param, ":force_length", 3),
(store_script_param, ":fire_order", 4),
(try_begin), #CABA additions
(agent_get_division, ":division", ":agent"),
(agent_get_team, ":team", ":agent"),
(store_add, ":slot", slot_team_d0_order_weapon, ":division"),
(team_slot_eq, ":team", ":slot", clear),
(try_begin),
(store_add, ":slot", slot_team_d0_order_shield, ":division"),
(team_slot_eq, ":team", ":slot", shield),
(assign, ":force_shield", 1),
(try_end), #CABA additions end
#priority items
(assign, ":shield", itm_no_item),
(assign, ":weapon", itm_no_item),
(try_for_range, ":item_slot", ek_item_0, ek_head),
(agent_get_item_slot, ":item", ":agent", ":item_slot"),
(gt, ":item", itm_no_item),
(item_get_type, ":weapon_type", ":item"),
(try_begin),
(eq, ":weapon_type", itp_type_shield),
(assign, ":shield", ":item"),
(else_try),
(eq, ":weapon_type", itp_type_thrown),
(eq, ":fire_order", aordr_fire_at_will),
# (agent_get_ammo, ":ammo", ":agent", 0), #assume infantry would have no other kind of ranged weapon
# (gt, ":ammo", 0),
(assign, ":weapon", ":item"), #use thrown weapons first
(try_end),
(try_end),
#select weapon
(try_begin),
(eq, ":weapon", itm_no_item),
(assign, ":cur_score", 0),
(try_for_range, ":item_slot", ek_item_0, ek_head),
(agent_get_item_slot, ":item", ":agent", ":item_slot"),
(gt, ":item", itm_no_item),
(item_get_type, ":weapon_type", ":item"),
(neq, ":weapon_type", itp_type_shield),
#(item_get_slot, reg0, ":item", slot_item_needs_two_hands),
#(this_or_next|eq, reg0, 0),
(this_or_next|neg|item_has_property, ":item", itp_two_handed), #WSE
(this_or_next|eq, ":force_shield", 0),
(eq, ":shield", itm_no_item),
(try_begin),
(neq, ":force_length", 0),
#(item_get_slot, ":item_length", ":item", slot_item_length),
(item_get_weapon_length, ":item_length", ":item"), #WSE
(try_begin),
(lt, ":cur_score", ":item_length"),
(assign, ":cur_score", ":item_length"),
(assign, ":weapon", ":item"),
(try_end),
(else_try),
(assign, ":imod", imodbit_plain),
(agent_get_troop_id, ":troop_id", ":agent"),
(try_begin), #only heroes have item modifications
(troop_is_hero, ":troop_id"),
(try_for_range, ":troop_item_slot", ek_item_0, ek_head), # heroes have only 4 possible weapons (equipped)
(troop_get_inventory_slot, reg0, ":troop_id", ":troop_item_slot"), #Find Item Slot with same item ID as Equipped Weapon
(eq, reg0, ":item"),
(troop_get_inventory_slot_modifier, ":imod", ":troop_id", ":troop_item_slot"),
(try_end),
(try_end),
(call_script, "script_get_item_score_with_imod", ":item", ":imod"),
(lt, ":cur_score", reg0),
(assign, ":cur_score", reg0),
(assign, ":weapon", ":item"),
(try_end),
(try_end),
(try_end),
#equip selected items if needed
(agent_get_wielded_item, reg0, ":agent", 0),
(try_begin),
(neq, reg0, ":weapon"),
(try_begin),
(gt, ":shield", itm_no_item),
(agent_get_wielded_item, reg0, ":agent", 1),
(neq, reg0, ":shield"), #reequipping secondary will UNequip (from experience)
(agent_set_wielded_item, ":agent", ":shield"),
(try_end),
(gt, ":weapon", itm_no_item),
(agent_set_wielded_item, ":agent", ":weapon"),
(try_end),
(try_end),
]),
# script_formation_current_position by motomataru
# Input: destination position (not pos0), team, division
# Output: in destination position
# As opposed to script_battlegroup_get_position, this obtains target rotation
("formation_current_position", [
(store_script_param, ":fposition", 1),
(store_script_param, ":fteam", 2),
(store_script_param, ":fdivision", 3),
(call_script, "script_battlegroup_get_position", ":fposition", ":fteam", ":fdivision"),
(call_script, "script_get_formation_destination", pos0, ":fteam", ":fdivision"),
(position_copy_rotation, ":fposition", pos0),
(call_script, "script_battlegroup_get_depth", ":fteam", ":fdivision"),
(val_div, reg0, 2), #position from script_battlegroup_get_position is in middle of bg
(position_move_y, ":fposition", reg0, 0),
]),
# script_get_centering_amount by motomataru
# Input: formation type, number of troops, extra spacing
# Use formation type formation_default to use script for archer line
# Output: reg0 number of centimeters to adjust x-position to center formation
("get_centering_amount", [
(store_script_param, ":troop_formation", 1),
(store_script_param, ":num_troops", 2),
(store_script_param, ":extra_spacing", 3),
(store_mul, ":troop_space", ":extra_spacing", 50),
(val_add, ":troop_space", formation_minimum_spacing),
(assign, reg0, 0),
(try_begin),
(eq, ":troop_formation", formation_square),
(convert_to_fixed_point, ":num_troops"),
(store_sqrt, reg0, ":num_troops"),
(val_mul, reg0, ":troop_space"),
(convert_from_fixed_point, reg0),
(val_sub, reg0, ":troop_space"),
(else_try),
(this_or_next|eq, ":troop_formation", formation_ranks),
(eq, ":troop_formation", formation_shield),
(store_div, reg0, ":num_troops", 3),
(try_begin),
(store_mod, reg1, ":num_troops", 3),
(eq, reg1, 0),
(val_sub, reg0, 1),
(try_end),
(val_mul, reg0, ":troop_space"),
(else_try),
(this_or_next|eq, ":troop_formation", formation_none), #CABA - also a line
(eq, ":troop_formation", formation_default), #assume these are archers in a line
(store_mul, reg0, ":num_troops", ":troop_space"),
(try_end),
(val_div, reg0, 2),
]),
# script_formation_end
# Input: team, division
# Output: none
("formation_end", [
(store_script_param, ":fteam", 1),
(store_script_param, ":fdivision", 2),
(try_begin),
(store_add, ":slot", slot_team_d0_formation, ":fdivision"),
(neg|team_slot_eq, ":fteam", ":slot", formation_none),
(team_set_slot, ":fteam", ":slot", formation_none),
(team_get_leader, ":leader", ":fteam"),
(try_for_agents, ":agent"),
(agent_is_alive, ":agent"),
(agent_is_human, ":agent"),
(agent_get_team, ":team", ":agent"),
(eq, ":team", ":fteam"),
(neq, ":leader", ":agent"),
(agent_get_division, ":bgdivision", ":agent"),
(eq, ":bgdivision", ":fdivision"),
(agent_clear_scripted_mode, ":agent"),
(agent_set_speed_limit, ":agent", 100),
(agent_set_slot, ":agent", slot_agent_in_first_rank, 0),
(agent_set_slot, ":agent", slot_agent_inside_formation, 0),
(try_end),
(try_begin),
(eq, ":fteam", "$fplayer_team_no"),
(store_add, ":slot", slot_team_d0_formation_space, ":fdivision"),
(team_get_slot, ":div_spacing", "$fplayer_team_no", ":slot"),
#adjust for differences between the two systems of spreading out
(set_show_messages, 0),
(try_begin),
(gt, ":div_spacing", 3),
(assign, ":div_spacing", 2), #Native maximum spread out
(else_try),
(gt, ":div_spacing", 0),
(team_give_order, "$fplayer_team_no", ":fdivision", mordr_stand_closer),
(try_begin),