-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbattle_of_sabis.nlogox
More file actions
2811 lines (2494 loc) · 105 KB
/
battle_of_sabis.nlogox
File metadata and controls
2811 lines (2494 loc) · 105 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="utf-8"?>
<model version="NetLogo 7.0.2" snapToGrid="false">
<code><![CDATA[;;;;; DECLARATIONS ;;;;;
breed [legionaries legionary]
breed [leaders leader]
breed [nervii nervii-warrior]
breed [baggage-trains baggage-train]
globals [
river-amplitude river-halfwidth river-wavelength ; making river visuals
river-phase river-offset-y bank-width ; making river visuals
dispersion-factor ; dispersion of legions based on compression chosen by user (IV)
marching? ; track if romans are marching
nervii-attack-started? ; track if nervii have begun their attack
nervii-attack-start-tick ; tick when nervii attack began
first-roman-aware? ; track if first Roman has become aware
first-aware-roman ; the first Roman who spotted a Nervii
first-aware-tick ; save the tick when the first roman became aware
ambush-bonus ; damage multiplier when attacking romans with statuses != ready
baggage-awareness-penalty ; ticks per baggage ahead of the legion (awareness)
roman-awareness-radius ; LOS in patches for romans becoming aware of nervii
agent-size ; global agent size (combatant) variable
baggage-size ; global baggage size variable
marching-speed ; initial marching speed of romans + baggage
charge-speed ; initial charge/running speed
short-attack-range ; shortsword/slashing sword attack range
long-attack-range ; javelin/pilum attack range
readiness-times ; store total readiness times
total-legionaries-at-start ; total num legionaries at start to % number of romans who became ready
legionaries-reached-ready ; count of legionaries who reached ready status
unaware-to-aware-times ; store unaware > awareness times
aware-to-orders-times ; store aware > orders received times
orders-to-ready-times ; store times from orders-received > ready
victory-state ; victory or loss status
victory-tick ; store tick for win/loss from simulation start
]
patches-own [
water?
bank?
forest?
]
legionaries-own [
legion-id ; to link a unit to its legion and legion leader to receive orders
is-veteran? ; track if veteran or rookie - veterans are more likely to have higher combat-skill and armor quality
health ; track health - start 90-100 stochastic
opponent-defense ; determines amount of damage to mitigate
combat-skill ; determines amount of damage to deal per tick when in combat. Formula: DPS = ((Accuracy of attacker * Lethality of weapon) / attack time avg in seconds ) ; later multiplied by (1 - Opponent's opponent-defense)
weapon-type ; determines range of weapon (80% of units will be shorswords, 20% pilums (javelins))
speed ; starts at usual march speed with a baggage train (~1.27m/s), run at 3m/s after aware, slow for melee, and slow regular speed over time
formation-position ; position in the marching column, IV
status ; unaware, aware, orders-received, ready
; Time between unaware -> aware dependent on Roman's first contact and awareness-latency
; Time between aware -> orders received dependent on order-latency
; Time between orders-received -> ready for battle dependent on readiness-speed
readiness-speed ; speed at which unit becomes ready for battle after being given orders; (probability; veterans are faster)
order-latency ; time from awareness to given orders, represents confusion described by caesar with compact columns; increases with higher compactness
awareness-latency ; time from first Roman awareness to that unit's awareness of battle; increases with distance from first roman's awareness of battle, simulating a messenger going back to warn the legions or visual/audible awareness
time-to-readiness ; counted to measure number of ticks from first roman aware to status "ready", determined at runtime
aware-tick ; store tick when roman becomes aware
orders-tick ; store tick when roman becomes orders-received
ready-tick ; store tick when roman becomes ready
nervii-targeting-me ; track the nervii targeting this roman
target-nervii ; the nervii this roman is attacking
blocked-by-baggage? ; can't move forward due to baggage
]
leaders-own [
legion-id ; link leader to its subordinates to give orders
is-veteran?
health
opponent-defense
combat-skill
weapon-type
speed
formation-position
status ; unaware, aware, orders-issued, ready
order-consideration-time ; time from aware -> giving orders, probability of faster if veteran
awareness-latency ; time from first Roman awareness to this leader's awareness
readiness-speed ; speed at which unit becomes ready for battle after being given orders; random between 5 and 10 seconds for leaders after issuing orders
nervii-targeting-me ; track the nervii are targeting this roman
target-nervii ; the nervii this leader is attacking
blocked-by-baggage? ; can't move forward due to baggage
legion-isolation-penalty ; isolation penalty for legion's performance if no other legions in LOS
]
baggage-trains-own [
legion-id ; associated legion; determines direction to march
speed
formation-position ; where to place baggage based on formation order IV chosen
status ; unaware -> aware of battle. unaware == marching behind legion, aware == moving to side
awareness-latency ; time until baggage becomes aware
side-movement-target ; x-coordinate to move to when getting out of way
down-movement-target ; y coord to move when getting out of way
has-cleared-path? ; track if baggage has moved far enough and may stop
]
nervii-own [
is-attacking? ; tracks if nervii are attacking, set to false initially then true once roman within a certain distance of sight line
health
combat-skill ; increases depending on ambush bonus, if the roman attacked isn't "Ready"
opponent-defense ; lower than Romans, very little armor historically, probability between 0 and 0.1
speed ; run/sprint when charging, slows over time
target-roman ; the specific roman our nervii agent is currently pursuing
romans-targeting-me ; track romans that are targeting this nervii
blocked-by-baggage?
]
;;;;; SETUP & GO main loop ;;;;;
to setup
clear-all
resize-world -125 125 -175 100 ; 10m x 10m patches
set agent-size 1.5 ; gives each soldier in the 80 soldiers in an agent about 3 sqmeters of space
set baggage-size 12 ; approx size of a legion 1:1 ratio, 14,336 sqmeters
set marching-speed 0.127 ; est. 1.27 meters per second while marching with baggage train
set charge-speed 0.3 ; est 3 m/s once aware of battle
set-default-river-params
color-terrain
create-forest
setup-agents
set marching? false
set nervii-attack-started? false
set nervii-attack-start-tick -1
set first-roman-aware? false
set first-aware-roman nobody
set first-aware-tick -1
set ambush-bonus 2 ; 2x damage from ambush - devastating initial blow according to Caesar
set roman-awareness-radius 10 ; LOS in dust/debris/chaos: ~100 meters
set short-attack-range 0.1 ; 1 meter for shortswords/slashing swords
set long-attack-range 1.5 ; 15 meters for pilums
set baggage-awareness-penalty 180 ; ~3 min per baggage in between legion and battle
set readiness-times [] ; init readiness times to mean later
set unaware-to-aware-times []
set aware-to-orders-times []
set orders-to-ready-times []
set total-legionaries-at-start count legionaries
set legionaries-reached-ready 0
set victory-state "In progress"
set victory-tick -1
reset-ticks
end
to go
if not marching? [
set marching? true ; start by marching romans towards river
]
; check if any roman has reached the trigger point for ambush (pycor >= 30) (within 300 meters of forest start)
check-ambush-trigger
;; roman state transitions
; unaware -> aware
check-first-roman-awareness
update-roman-awareness
update-baggage-awareness
; aware -> orders-received
process-leader-orders
process-legionary-orders
; orders-received -> ready
process-legionary-readiness
; Nervii behavior
ask nervii [
ifelse is-attacking? [
; Nervii are attacking - move toward closest available Roman
nervii-attack-movement
] [
; Stay hidden in forest - no movement yet
]
]
; romans march toward river
march-romans
; COMBAT
nervii-combat
roman-combat
; Remove dead agents
remove-dead-agents
; update victory status if battle is won
update-victory
if victory-state != "In progress" [
plot-readiness-histogram
stop
]
tick
end
;;;;; TERRAIN SETUP ;;;;;
;; patch represents: 10 meters x 10 meters
;; tick represents: 1 second
to set-default-river-params
if river-amplitude = 0 [ set river-amplitude 2 ]
if river-halfwidth = 0 [ set river-halfwidth 2.5 ]
if river-wavelength = 0 [ set river-wavelength 10 ]
if river-phase = 0 [ set river-phase 0 ]
if river-offset-y = 0 [ set river-offset-y 29 ] ; center of river ~290m away (edge was ~300 paces from forest line)
if bank-width = 0 [ set bank-width 1 ]
end
to color-terrain
ask patches [
set forest? false
set water? in-river? self
set bank? (not water?) and any? neighbors with [ in-river? self ]
set pcolor
ifelse-value water? [ blue + 1 ]
[ ifelse-value bank? [ brown + 2 ] [ green ] ]
]
end
to create-forest
ask n-of 200 patches with [ not water? and not bank? and pycor > 60 ] [
set pcolor 53
set forest? true
ask patches in-radius 5 with [ not water? and not bank? ] [
set pcolor 53
set forest? true
]
]
end
to-report river-center-y [x]
report river-offset-y + river-amplitude * sin (x * river-wavelength + river-phase)
end
to-report in-river? [p]
let cx river-center-y ([pxcor] of p)
report abs(([pycor] of p) - cx) <= river-halfwidth
end
to-report river-patches
report patches with [ water? ]
end
to-report bank-patches
report patches with [ bank? ]
end
;;;;; AGENT SETUP ;;;;;
to setup-agents
; compactness-of-legions: 0.0 = highly dispersed, 1.0 = highly compact
set dispersion-factor (1 - compactness-of-legions) * 32 + 13 ; Range from 13 patches horizontally and across to 45
; legion is approx 13 patches x 11 patches in total W/H, and so dispersion from center effectively means that 13 patches legions are literally right next to each other horizontally and only a few meters away vertically.
; most compact = legion CENTERS are 130 meters away from each other horizontally/vertically. (Legion EDGES 0 meters away from each other(minus the size of baggage between))
; most disperse = legion centers are 450 meters away horizontally/vertically.
; setup romans based on IVs: formation order and dispersion
setup-roman-formation
; setup nervii in the forest
setup-nervii
end
to setup-roman-formation
let formation-order get-formation-order
; starting positions
let current-y 0
let formation-index 0
let left-y current-y
let right-y current-y
; baggage starting positions
let in-baggage-section false
let baggage-y 0
let baggage-count 0
; create agents according to formation order and dispersion-factor IVs
foreach formation-order [ unit-spec ->
let unit-type item 0 unit-spec
let legion-num item 1 unit-spec
if unit-type = "legion" [
if in-baggage-section [
set in-baggage-section false
]
; column positions: dispersion-factor apart
let column-x 0
let legion-y 0
; handling for Caesar's order - veteran legions in single row
ifelse roman-order = "Caesar's order" and legion-num <= 6 [
; legions 1-6 in a single horizontal row
; legion spacing: dispersion-factor betwn centers
let legion-position (legion-num - 3.5)
set column-x legion-position * dispersion-factor
set legion-y 0
; set positions for baggage/rookie legions
if legion-num = 6 [
set left-y legion-y - dispersion-factor
set right-y left-y
]
] [
; expected order: standard Roman two column placement
ifelse legion-num mod 2 = 1 [
; left column
set column-x (- dispersion-factor / 2)
set legion-y left-y
] [
; right column
set column-x (dispersion-factor / 2)
set legion-y right-y
]
]
; create legion leader
create-leaders 1 [
set legion-id legion-num
set is-veteran? (legion-num <= 6)
set shape "triangle"
set color 45
set size agent-size + 0.5
setxy column-x legion-y
set heading 0
set formation-position formation-index
set blocked-by-baggage? false
initialize-leader-params
]
; create legionaries and chunk them with their legion
let legionaries-per-side 7
let agent-spacing agent-size + 0.1
let current-legionary 0
create-legionaries 55 [
set legion-id legion-num
set is-veteran? (legion-num <= 6)
set shape "square"
set color red
set size agent-size
let row floor (current-legionary / 8)
let col current-legionary mod 8
let offset-x (col - 7 / 2.0) * agent-spacing
let offset-y (row - 6 / 2.0) * agent-spacing
let jitter-x (random-float 0.3) - 0.15
let jitter-y (random-float 0.3) - 0.15
setxy (column-x + offset-x + jitter-x) (legion-y + offset-y + jitter-y)
set heading 0
set formation-position formation-index
set blocked-by-baggage? false
initialize-legionary-params
set current-legionary current-legionary + 1
]
; use dispersion factor to determine spacing - only for standard two-column
if roman-order = "Caesar's order" and legion-num > 6 [
if legion-num mod 2 = 0 [
set left-y left-y - dispersion-factor
set right-y right-y - dispersion-factor
]
]
if roman-order = "Expected order" [
; have to place baggage between, continue
]
set formation-index formation-index + 1
]
; set baggage order and distance based on each order
if unit-type = "baggage" [
if not in-baggage-section and roman-order = "Caesar's order" [
set in-baggage-section true
set baggage-y left-y
set baggage-count 0
]
if roman-order = "Caesar's order" [
let row floor (baggage-count / 4)
let col baggage-count mod 4
let baggage-spacing baggage-size
let baggage-x (col - 1.5) * baggage-spacing
let min-spacing baggage-size
; calc spacing above baggage section
let spacing-above (dispersion-factor * 0.5)
if spacing-above < min-spacing [
set spacing-above min-spacing
]
let first-row-y baggage-y + (dispersion-factor - spacing-above)
let baggage-y-pos first-row-y - (row * baggage-spacing)
create-baggage-trains 1 [
set legion-id legion-num
set shape "circle"
set color 17
set size baggage-size
setxy baggage-x baggage-y-pos
set heading 0
set formation-position formation-index
set speed marching-speed
set status "unaware"
set awareness-latency -1
set side-movement-target 0
set has-cleared-path? false
]
set baggage-count baggage-count + 1
if baggage-count = 8 [
; calculate spacing below baggage section
let spacing-below (dispersion-factor * 0.5)
if spacing-below < min-spacing [
set spacing-below min-spacing
]
; second row is at: first-row-y - baggage-spacing
set left-y first-row-y - baggage-spacing - spacing-below
set right-y left-y
]
]
if roman-order = "Expected order" [
let column-x 0
let baggage-y-pos 0
let min-spacing baggage-size
let spacing-around-baggage (dispersion-factor * 0.5)
if spacing-around-baggage < min-spacing [
set spacing-around-baggage min-spacing
]
ifelse legion-num mod 2 = 1 [
set column-x (- dispersion-factor / 2)
set baggage-y-pos left-y - spacing-around-baggage
] [
set column-x (dispersion-factor / 2)
set baggage-y-pos right-y - spacing-around-baggage
]
create-baggage-trains 1 [
set legion-id legion-num
set shape "circle"
set color 17
set size baggage-size
setxy column-x baggage-y-pos
set heading 0
set formation-position formation-index
set speed marching-speed
set status "unaware"
set awareness-latency -1
set side-movement-target 0
set down-movement-target 0
set has-cleared-path? false
]
ifelse legion-num mod 2 = 1 [
set left-y baggage-y-pos - spacing-around-baggage
] [
set right-y baggage-y-pos - spacing-around-baggage
]
]
set formation-index formation-index + 1
]
]
end
to-report get-formation-order
; returns list to represent orders
if roman-order = "Caesar's order" [
; legions 1-6, all baggage, legions 7-8
report (list
["legion" 1] ["legion" 2] ["legion" 3]
["legion" 4] ["legion" 5] ["legion" 6]
["baggage" 1] ["baggage" 2] ["baggage" 3]
["baggage" 4] ["baggage" 5] ["baggage" 6]
["baggage" 7] ["baggage" 8]
["legion" 7] ["legion" 8]
)
]
if roman-order = "Expected order" [
; baggage behind its legion in expected
report (list
["legion" 1] ["baggage" 1]
["legion" 2] ["baggage" 2]
["legion" 3] ["baggage" 3]
["legion" 4] ["baggage" 4]
["legion" 5] ["baggage" 5]
["legion" 6] ["baggage" 6]
["legion" 7] ["baggage" 7]
["legion" 8] ["baggage" 8]
)
]
; default to Caesar's order
report (list
["legion" 1] ["legion" 2] ["legion" 3]
["legion" 4] ["legion" 5] ["legion" 6]
["baggage" 1] ["baggage" 2] ["baggage" 3]
["baggage" 4] ["baggage" 5] ["baggage" 6]
["baggage" 7] ["baggage" 8]
["legion" 7] ["legion" 8]
)
end
to initialize-legionary-params
; init roman combatants
set health 90 + random-float 10 ; 90-100
; 80% shortswords, 20% long-range pilums
ifelse random-float 1.0 < 0.8 [
set weapon-type "short-range" ; 0.1 patch distance range (1 meter)
] [
set weapon-type "long-range" ; 1.5 patch distance range (15 meter)
]
; vet stats
if is-veteran? [
ifelse weapon-type = "short-range" [
; Vet with Shortsword
set opponent-defense 0.45 + random-float 0.1 ; avg vet with shortsword opponent-defense = 50% (+- 5%)
; DPS = ((Accuracy of attacker * Lethality of weapon) / attack time avg in seconds) effect of opponent's armor determined during attack
set combat-skill 18.5 + random-float 5 ; (0.7 * 0.6) / 2 seconds = 0.21. = 21 (+- 2.5)
] [
; Vet with Javelin
set opponent-defense 0.25 + random-float 0.1 ; half armor quality - no shield when using pilum (30% +-5)
set combat-skill 8.75 + random-float 5 ; (0.5 * 0.9) / 4 seconds = 0.1125 == 11.25 (+-2.5)
]
]
; rookie stats
if not is-veteran? [
ifelse weapon-type = "short-range" [
; Rookie with Shortsword
set opponent-defense 0.35 + random-float 0.1 ; avg rookie with shortsword opponent-defense = 40% (+- 5%)
set combat-skill 8 + random-float 5 ; (0.35 * 0.6) / 2 seconds = 0.105 => 10.5 (+-2.5) (rookies accuracy approx half of vet's)
] [
; Rookie with Javelin
set opponent-defense 0.15 + random-float 0.1 ; avg rookie with jav armor quality = 20% (half. no shield)
set combat-skill 3.125 + random-float 5 ; (0.25 * 0.9) / 4 seconds = 0.05625 ==> 5.625 (+- 2.5 points)
]
]
set nervii-targeting-me 0 ; no nervii targeting him at beginning
set target-nervii nobody ; not targeting anyone yet
set order-latency -1 ; not yet init
set readiness-speed -1 ; not yet init
set time-to-readiness -1 ;not yet init
set aware-tick -1
set orders-tick -1
set ready-tick -1
set speed marching-speed
set status "unaware"
end
; init roman leaders
to initialize-leader-params
set health 90 + random-float 10 ; 90-100
set weapon-type "short-range" ; typically, leaders did not throw javelins
if is-veteran? [
set opponent-defense 0.45 + random-float 0.1 ; avg vet with shortsword opponent-defense = 50% (+- 5%)
set combat-skill 18.5 + random-float 5 ; (0.7 * 0.6) / 2 seconds = 0.21. = 21 (+- 2.5)
]
if not is-veteran? [
set opponent-defense 0.35 + random-float 0.1 ; avg rookie with shortsword opponent-defense = 40% (+- 5%)
set combat-skill 8 + random-float 5 ; (0.35 * 0.6) / 2 seconds = 0.105 => 10.5 (+-2.5) (rookies accuracy approx half of vet's)
]
set nervii-targeting-me 0
set target-nervii nobody
set readiness-speed 5 + random 10
set legion-isolation-penalty 1.0 ; default - no penalty
set weapon-type "short-range"
set speed marching-speed
; turns to 0.3 when fighting/aware
set status "unaware"
end
;;;; SETUP NERVII ;;;;;
to setup-nervii
; 313 nervii agents (~25,040 warriors historically / 80) organized in tribal clusters in forest patches
let forest-patches-list patches with [
forest? = true and
pxcor >= -30 and pxcor <= 30 and ; nervii were close together according to hisotrical sources, despite being in different tribes
pycor >= 65 and pycor <= 75
]
if any? forest-patches-list [
; ~6 tribal clusters
let num-tribes 6
let nervii-per-tribe floor (313 / num-tribes)
repeat num-tribes [
; pick a central location for this tribe
let tribe-center one-of forest-patches-list
; create warriors
create-nervii nervii-per-tribe [
set shape "square"
set color violet
set size agent-size
; position= loosely near tribe center
move-to tribe-center
let offset-distance random-float 10
let offset-angle random-float 360
let new-x [pxcor] of tribe-center + offset-distance * sin offset-angle
let new-y [pycor] of tribe-center + offset-distance * cos offset-angle
; forest bounds
if new-x < -35 [ set new-x -35 ]
if new-x > 35 [ set new-x 35 ]
if new-y < 60 [ set new-y 60 ]
if new-y > 80 [ set new-y 80 ]
let target-patch patch new-x new-y
ifelse [forest?] of target-patch = true [
setxy new-x new-y
] [
setxy [pxcor] of tribe-center [pycor] of tribe-center
]
set is-attacking? false
set health 90 + random-float 10 ; 90-100
set opponent-defense 0.05 + random-float 0.1 ; only a shield used if any. typically very minimal armor 10% +- 5%
set combat-skill 10 + random-float 5 ; (0.5 * 0.5)/2 seconds = 0.125 -> 12.5 pts (+- 2.5), ends up being a little higher than rookie roman
set speed charge-speed;
set heading 180 ; facing south toward romans
set target-roman nobody
set romans-targeting-me 0
set blocked-by-baggage? false
]
]
]
end
;;;;; AGENT MOVEMENT ;;;;;
to march-romans
; romans begin marching northward
; speed determined by terrain
; movement depends on status
ask legionaries with [status = "unaware"] [
let terrain-speed get-terrain-speed
move-avoiding-baggage (speed * terrain-speed)
set heading 0
]
ask leaders with [status = "unaware"] [
let terrain-speed get-terrain-speed
move-avoiding-baggage (speed * terrain-speed)
set heading 0
]
; aware and orders-received legionaries slow down to organize
ask legionaries with [status = "aware" or status = "orders-received"] [
let terrain-speed get-terrain-speed
move-avoiding-baggage (speed * 0.5 * terrain-speed)
set heading 0 ; Keep marching north
]
ask leaders with [status = "aware" or status = "orders-issued"] [
let terrain-speed get-terrain-speed
move-avoiding-baggage (speed * 0.5 * terrain-speed)
set heading 0
]
; ready legionaries move toward attackers or find enemies
ask legionaries with [status = "ready"] [
let attackers nervii with [target-roman = myself and is-attacking?]
ifelse any? attackers [
; move toward attacker
let nearest-attacker min-one-of attackers [distance myself]
face nearest-attacker
let terrain-speed get-terrain-speed
let dist-to-target distance nearest-attacker
; slow down when close ...avoid overshooting
ifelse dist-to-target <= 0.5 [
; if theyre close to attacker, slow down to fight
move-avoiding-baggage (speed * 0.3 * terrain-speed)
] [
; forward speed * terrain-speed
move-avoiding-baggage (speed * terrain-speed)
]
] [
; if i already have a target, move toward it
ifelse target-nervii != nobody and is-turtle? target-nervii [
face target-nervii
let terrain-speed get-terrain-speed
let dist-to-target distance target-nervii
ifelse dist-to-target <= 0.5 [
; if theyre close to target, slow down to fight
move-avoiding-baggage (speed * 0.3 * terrain-speed)
] [
move-avoiding-baggage (speed * terrain-speed)
]
] [
; otherwise search nearby for new enemies
let nearby-nervii nervii with [is-attacking?] in-radius 15
if not any? nearby-nervii [
set nearby-nervii nervii with [is-attacking?] in-radius 25
]
if not any? nearby-nervii [
set nearby-nervii nervii with [is-attacking?] in-radius 40
]
if any? nearby-nervii [
let nearest-nervii min-one-of nearby-nervii [distance myself]
face nearest-nervii
let terrain-speed get-terrain-speed
let dist-to-target distance nearest-nervii
ifelse dist-to-target <= 0.5 [
move-avoiding-baggage (speed * 0.3 * terrain-speed)
] [
move-avoiding-baggage (speed * terrain-speed)
]
]
]
]
]
; same movement as legionaries for combat
ask leaders with [status = "ready"] [
let attackers nervii with [target-roman = myself and is-attacking?]
ifelse any? attackers [
let nearest-attacker min-one-of attackers [distance myself]
face nearest-attacker
let terrain-speed get-terrain-speed
let dist-to-target distance nearest-attacker
ifelse dist-to-target <= 0.5 [
move-avoiding-baggage (speed * 0.3 * terrain-speed)
] [
move-avoiding-baggage (speed * terrain-speed)
]
] [
ifelse target-nervii != nobody and is-turtle? target-nervii [
face target-nervii
let terrain-speed get-terrain-speed
let dist-to-target distance target-nervii
ifelse dist-to-target <= 0.5 [
move-avoiding-baggage (speed * 0.3 * terrain-speed)
] [
move-avoiding-baggage (speed * terrain-speed)
]
] [
let nearby-nervii nervii with [is-attacking?] in-radius 15
if not any? nearby-nervii [
set nearby-nervii nervii with [is-attacking?] in-radius 25
]
if not any? nearby-nervii [
set nearby-nervii nervii with [is-attacking?] in-radius 40
]
if any? nearby-nervii [
let nearest-nervii min-one-of nearby-nervii [distance myself]
face nearest-nervii
let terrain-speed get-terrain-speed
let dist-to-target distance nearest-nervii
ifelse dist-to-target <= 0.5 [
move-avoiding-baggage (speed * 0.3 * terrain-speed)
] [
move-avoiding-baggage (speed * terrain-speed)
]
]
]
]
]
; move to the side and down, baggage is massive and slow
ask baggage-trains [
ifelse status = "aware" [
if not has-cleared-path? [
let target-dist distancexy side-movement-target down-movement-target
if target-dist > 0.5 [
; move towards target
set heading towardsxy side-movement-target down-movement-target
forward (speed * 0.5)
]
; check if arrived
if target-dist <= 0.5 [
set has-cleared-path? true
set color yellow ; indicate that path is clear
]
]
] [
; normal marching when unaware
let terrain-speed get-terrain-speed
forward speed * terrain-speed
set heading 0
]
]
end
to-report get-terrain-speed
; get speed mult based on terrain type
let current-patch patch-here
if [water?] of current-patch [
report 0.6 ; 60% speed in water
]
if [bank?] of current-patch [
report 0.8 ; 80% of speed in bank
]
if [forest?] of current-patch [
report 0.7 ; 70% speed in forest
]
report 1.0 ; normal terrain
end
;;;;; ROMAN STATUS CHANGES ;;;;;
;;; UNAWARE -> AWARE ;;;
to check-first-roman-awareness
; check if first roman has been made aware of attack
if not first-roman-aware? [
; visible == not in forest and within 10 patches (~100 meters)
let all-romans (turtle-set legionaries leaders)
ask all-romans with [status = "unaware"] [
let visible-nervii nervii in-radius roman-awareness-radius with [
is-attacking? and
not [forest?] of patch-here
]
if any? visible-nervii [
; first roman to spot nervii
set status "aware"
set speed charge-speed ; increase speed to running once aware
set color orange ; indicates awareness
set first-roman-aware? true
set first-aware-roman self
set first-aware-tick ticks ; save tick number first roman became aware to track awareness times
; once first roman aware, calculate awareness-latency for all other romans based on distance from first aware Roman
; represents approx rider travel time or audible/visual latency if within shouting/discernable distance
calculate-awareness-latency
calculate-baggage-awareness-latency
stop
]
]
]
end
to calculate-awareness-latency
; once first roman becomes aware, this calculates how long until each agent becomes aware
ask (turtle-set legionaries leaders) with [status = "unaware"] [
let dist distance first-aware-roman
; count baggage trains between this Roman and the battle
let f baggage-in-front-factor legion-id
; base awareness - on foot or mule -> legion behind, no cavalry as they were wiped at beginning
; run speed: 3 m/s avg
; time = distance / speed
; time = (dist * 10 meters) / 3 patches p tick
; to do: diminish run speed over time
; anywhere from 10-30 seconds added, getting through column
let base (dist * 10 / 3) + 10 + random-float 20
; awareness latency accounts for distance and baggage between
set awareness-latency base + (f * baggage-awareness-penalty)
]
end
to calculate-baggage-awareness-latency
; slow reacts due to equipment load and size
ask baggage-trains with [status = "unaware"] [
let dist distance first-aware-roman
set awareness-latency (dist * 10 / 3) + 20 + random-float 20
]
end
to update-baggage-awareness
; baggage trains become aware, attempt to hang back or get out of way
if first-roman-aware? [
ask baggage-trains with [status = "unaware"] [
let should-become-aware false
let visible-nervii nervii in-radius roman-awareness-radius with [
is-attacking? and
not [forest?] of patch-here
]
if any? visible-nervii [
set should-become-aware true
]
if not should-become-aware [
if awareness-latency > 0 [
set awareness-latency awareness-latency - 1
]
if awareness-latency <= 0 [
set should-become-aware true
]
]
if should-become-aware [
set status "aware"
set color white ; aware baggage
let side-distance 20 ; aim to move away to the side and down
let down-distance 20
ifelse xcor < 0 [
set side-movement-target xcor - side-distance
] [
set side-movement-target xcor + side-distance
]
set down-movement-target ycor - down-distance
]
]
]
end
to update-roman-awareness
; romans become aware when:
; 1. they see nervii nearby (after battle start, caesar implies dust/debris/chaos greatly impacted LOS, so if battle has already started, visibility lowers by 0.25)
; 2. awareness-latency expires
if first-roman-aware? [
ask (turtle-set legionaries leaders) with [status = "unaware"] [
let should-become-aware false
; can they see battle/nervii?
; account for baggage visibility and LOS
let candidate-nervii nervii in-radius roman-awareness-radius with [
is-attacking? and
not [forest?] of patch-here
]
; filter out nervii blocked by baggage
let me-roman self ; save ref to this roman
let visible-nervii candidate-nervii with [
[has-clear-line-of-sight-to? myself] of me-roman
]
if any? visible-nervii [
set should-become-aware true
]
; check if awareness latency has expired
if not should-become-aware [
if awareness-latency > 0 [
set awareness-latency awareness-latency - 1
]
if awareness-latency <= 0 [
set should-become-aware true
]
]
; if any condition met, become aware
if should-become-aware [
set status "aware"