/
guardians.cfg
671 lines (613 loc) · 20.7 KB
/
guardians.cfg
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
#textdomain wesnoth-ai
#define HOME_GUARDIAN X Y
# Meant to be used as a suffix to a unit-generating macro call.
# The previously-generated unit will treat (X,Y) as its home.
[+unit]
[ai]
[vars]
home_loc="loc({X},{Y})"
[/vars]
[/ai]
[/unit]
#enddef
[test]
id=guardians
name= _ "Guardians"
next_scenario=micro_ai_test
map_file=/multiplayer/maps/4p_Paths_of_Daggers.map
{DEFAULT_SCHEDULE}
turns=unlimited
victory_when_enemies_defeated=no
[side]
side=1
controller=human
suppress_end_turn_confirmation=yes
id=Kraa
name= _ "Kraa"
unrenamable=yes
type=Gryphon
x,y=3,5
team_name=gryphons
user_team_name=_"Gryphons"
recruit=Gryphon
persistent=no
gold=200
[/side]
# Guardians
[side]
side=2
controller=ai
type=Orcish Leader
id=Another Bad Orc
name= _ "Another Bad Orc"
x,y=33,24
canrecruit=yes
recruit=Orcish Archer,Orcish Grunt
persistent=no
gold=30
[ai]
[modify_ai]
side=1
action=add
# wmllint: unbalanced-on
path=stage[main_loop].candidate_action[]
# wmllint: unbalanced-off
[candidate_action]
engine=fai
name=go_home
id=go_home
type=movement
# wmlindent: start ignoring
evaluation="if( (null != me.vars.home_loc), {AI_CA_MOVE_TO_TARGETS_SCORE}+10, 0)"
action="if( (me.loc != me.vars.home_loc), move(me.loc, next_hop(me.loc, me.vars.home_loc)), move(me.loc, me.loc)#do not move this turn#)"
# wmlindent: stop ignoring
[/candidate_action]
[/modify_ai]
[/ai]
[/side]
# Put all the units and markers out there
[event]
name=prestart
{VARIABLE scenario_name guardians}
{PLACE_IMAGE "scenery/signpost.png" 1 6}
{SET_LABEL 1 6 _"End Scenario"}
# A couple gryphons
{GENERIC_UNIT 1 Gryphon 4 6}
{GENERIC_UNIT 1 Gryphon 5 4}
# The normal guardians
[unit]
type=Dwarvish Guardsman
side=2
id=guardian1
name= _ "Guardian 1"
x,y=12,1
ai_special=guardian
[variables]
label="ai_special=guardian"
[/variables]
[/unit]
[unit]
type=Dwarvish Guardsman
side=2
id=guardian2
name= _ "Guardian 2"
x,y=15,1
ai_special=guardian
[variables]
label="ai_special=guardian"
[/variables]
[/unit]
# The cowards
[unit]
type=Giant Rat
side=2
id=coward1
name= _ "Coward 1"
x,y=14,21
[modifications]
{TRAIT_QUICK}
[/modifications]
[variables]
label="coward r=5"
[/variables]
[/unit]
[micro_ai]
side=2
ai_type=coward
action=add
[filter]
id=coward1
[/filter]
distance=5
[/micro_ai]
[unit]
type=Giant Rat
side=2
id=coward2
name= _ "Coward 2"
x,y=16,21
[modifications]
{TRAIT_QUICK}
[/modifications]
[variables]
label="coward r=5
s=24 5"
[/variables]
[/unit]
[micro_ai]
side=2
ai_type=coward
action=add
[filter]
id=coward2
[/filter]
distance=5
seek_x,seek_y=24,5
[/micro_ai]
[unit]
type=Giant Rat
side=2
id=coward3
name= _ "Coward 3"
x,y=18,21
[modifications]
{TRAIT_QUICK}
[/modifications]
[variables]
label=" coward r=5
s=24,5 a=24,15"
[/variables]
[/unit]
[micro_ai]
side=2
ai_type=coward
action=add
[filter]
id=coward3
[/filter]
distance=5
seek_x,seek_y=24,5
avoid_x,avoid_y=24,15
[/micro_ai]
[unit]
type=Giant Rat
side=2
id=coward4
name= _ "Coward 4"
x,y=12,21
[modifications]
{TRAIT_QUICK}
[/modifications]
[variables]
label="coward r=5
s=32,--"
[/variables]
[/unit]
[micro_ai]
side=2
ai_type=coward
action=add
[filter]
id=coward4
[/filter]
distance=4
seek_x=32
[/micro_ai]
{SET_LABEL 15 19 _"Move gryphons here to see different coward reactions"}
{PLACE_IMAGE "items/gohere.png" 13 20}
{PLACE_IMAGE "items/gohere.png" 17 20}
# The return guardians
[unit]
type=Troll
side=2
id=return1
name= _ "Return Guardian 1"
x,y=20,2
[variables]
label="return 20,2"
[/variables]
[/unit]
[micro_ai]
side=2
ai_type=return_guardian
action=add
[filter]
id=return1
[/filter]
return_x,return_y=20,2
[/micro_ai]
[unit]
type=Troll Whelp
side=2
id=return2
name= _ "Return Guardian 2"
x,y=21,9
[variables]
label="return 21,9"
[/variables]
[/unit]
[micro_ai]
side=2
ai_type=return_guardian
action=add
[filter]
id=return2
[/filter]
return_x,return_y=21,9
[/micro_ai]
# The home guards
[unit]
type=Troll Whelp
side=2
id=home1
name= _ "Home Guard 1"
x,y=19,2
[variables]
label="home 19,2"
[/variables]
[/unit]
{HOME_GUARDIAN 19 2}
[unit]
type=Troll
side=2
id=home 2
name= _ "Home Guard 2"
x,y=21,10
[variables]
label="home 21,10"
[/variables]
[/unit]
{HOME_GUARDIAN 21 10}
# The stationed guardians
[unit]
type=Skeleton Archer
side=2
id=stationed1
name= _ "Stationed Guardian 1"
x,y=1,12
[variables]
label=" stationed r=4
s=2,14 g=3,13"
[/variables]
[/unit]
[micro_ai]
side=2
ai_type=stationed_guardian
action=add
[filter]
id=stationed1
[/filter]
distance=4
station_x,station_y=2,14
guard_x,guard_y=3,13
[/micro_ai]
[unit]
type=Skeleton
side=2
id=stationed2
name= _ "Stationed Guardian 2"
x,y=6,14
[variables]
label=" stationed r=4
s=4,14 g=7,13"
[/variables]
[/unit]
[micro_ai]
side=2
ai_type=stationed_guardian
action=add
[filter]
id=stationed2
[/filter]
distance=4
station_x,station_y=4,14
guard_x,guard_y=3,13
[/micro_ai]
# Zone guardians
[unit]
type=Troll
side=2
id=zone1
name= _ "Gate Keeper"
x,y=5,25
[modifications]
{TRAIT_STRONG}
[/modifications]
[variables]
label="Zone Guard"
[/variables]
[/unit]
[micro_ai]
side=2
ai_type=zone_guardian
action=add
[filter]
id=zone1
[/filter]
[filter_location]
x=4,5,6,7,5
y=24,24,24,24,25
[/filter_location]
[/micro_ai]
[unit]
type=Dwarvish Guardsman
side=2
id=zone2
name= _ "Home Keeper"
x,y=2,27
[modifications]
{TRAIT_STRONG}
[/modifications]
[variables]
label="Zone Guard with
separate attack Zone"
[/variables]
[/unit]
[micro_ai]
side=2
ai_type=zone_guardian
action=add
[filter]
id=zone2
[/filter]
[filter_location]
x=1,2,3,2
y=27,27,27,26
[/filter_location]
[filter_location_enemy]
x,y=1-4,24-27
[/filter_location_enemy]
[/micro_ai]
[unit]
type=Naga Fighter
side=2
id=zone3
name= _ "Water Guardian"
x,y=29,8
[variables]
label="Zone Guard"
[/variables]
[/unit]
[micro_ai]
side=2
ai_type=zone_guardian
action=add
[filter]
id=zone3
[/filter]
[filter_location]
x,y=22-31,4-11 # This is intentionally chosen to extend past the lake
terrain=W*
[/filter_location]
station_x,station_y=32,8
[/micro_ai]
{SET_LABEL 3 13 _"Guarded Location"}
{SET_LABEL 2 14 _"Station 1"}
{SET_LABEL 4 14 _"Station 2"}
# Set initial label for each units
[store_unit]
[filter]
side=2
[/filter]
variable=tmp_units
kill=no
[/store_unit]
[foreach]
array=tmp_units
[do]
{SET_LABEL $this_item.x $this_item.y $this_item.variables.label}
[/do]
[/foreach]
{CLEAR_VARIABLE tmp_units}
# The right-click menu items
[set_menu_item]
id=m01_guardian
description= _ "Standard WML Guardian"
image=units/dwarves/guard.png~CROP(28,24,24,24)
[show_if]
{VARIABLE_CONDITIONAL scenario_name equals guardians}
[/show_if]
[command]
[message]
speaker=narrator
image=portraits/dwarves/guard.png
caption= _ "Standard WML Guardian"
message= _ "This is the built-in WML guardian coded using 'ai_special=guardian'. These guardians attack if there is an enemy within their movement range, otherwise they do nothing (except maybe retreating to a village for healing)."
[/message]
[/command]
[/set_menu_item]
[set_menu_item]
id=m02_return
description= _ "Return Guardian"
image=units/trolls/grunt.png~CROP(31,7,24,24)
[show_if]
{VARIABLE_CONDITIONAL scenario_name equals guardians}
[/show_if]
[command]
[message]
speaker=narrator
image=portraits/trolls/troll.png
caption= _ "Return Guardian"
message= _ "A 'return guardian' is a variation of the standard Wesnoth guardian. It has an assigned guard position (GP) to which it returns after attacks on approaching enemies:
- If at GP with no enemy in reach, do nothing.
- If at GP with enemy in reach, leave attack to default AI (note that this may include not attacking if the enemy is deemed too strong).
- If not at GP, return there, no matter whether an enemy is in reach or not.
- If enemies are blocking your way back, do your best to get there anyway.
- If you end up next to an enemy on the way back, attack after the move."
[/message]
[/command]
[/set_menu_item]
[set_menu_item]
id=m03_home
description= _ "Home Guard"
image=units/trolls/grunt.png~CROP(31,7,24,24)
[show_if]
{VARIABLE_CONDITIONAL scenario_name equals guardians}
[/show_if]
[command]
[message]
speaker=narrator
image=portraits/trolls/troll.png
caption= _ "Home Guard"
message= _ "A 'home guard' is a variant on the 'guardian' AI special. With this variant, the unit has an assigned 'home' location, and will return there if not involved in combat and if not going to a village, whether for healing or to capture it this turn. (By contrast, the standard guardian AI will cause the unit to stay where it last attacked.) This differs from 'return guardian' in that a home guard will press the attack, possibly getting drawn quite far from 'home', rather than returning after each attack. (It can also be lured away by a string of closely-placed villages, but that is something a map builder can control.)
This also demonstrates how to combine candidate actions from Formula AI and Lua AI in one side. The home guard is written in Formula AI, while the return and stationed guardians and the cowards are written in Lua AI. In addition the non-guardian units of the side follow the default AI behavior."
[/message]
[/command]
[/set_menu_item]
[set_menu_item]
id=m04_stationed
description= _ "Stationed Guardian"
image=units/undead-skeletal/archer/archer.png~CROP(24,16,24,24)
[show_if]
{VARIABLE_CONDITIONAL scenario_name equals guardians}
[/show_if]
[command]
[message]
speaker=narrator
image=portraits/undead/archer.png
caption= _ "Stationed Guardian"
message= _ "A 'stationed guardian' is another variation of the standard Wesnoth guardian with a somewhat more complex behavior than that of the 'return guardian'. Two positions are defined for it, a 'station' and a 'guarded location', as well as a 'distance'. The behavior is as follows:
- If no enemy is within 'distance' of the guard's current position, do nothing.
- Otherwise: If an enemy is within 'distance' of the guard, but not also within the same distance of the guarded location and the station (all of this simultaneously), move the guard in the direction of the station.
- Otherwise:
- Pick the enemy unit that is closest to the guarded location.
- If we can reach it, pick the adjacent hex with the highest defense rating and attack from there.
- If not in reach, move toward this unit."
[/message]
[/command]
[/set_menu_item]
[set_menu_item]
id=m05_coward
description= _ "Coward"
image=units/monsters/giant-rat.png~CROP(30,30,24,24)
[show_if]
{VARIABLE_CONDITIONAL scenario_name equals guardians}
[/show_if]
[command]
[message]
speaker=narrator
image=units/monsters/giant-rat.png
caption= _ "Coward"
message= _ "Cowards are units that, like guardians, sit around doing nothing until an enemy comes into range. Unlike guardians, however, they run away once enemies approach. Applications might be wild animals, unarmed civilians getting in the way of a battle, etc. The coward macro can be called with two optional locations, 'seek' and 'avoid':
- If neither is given, the coward retreats to the position farthest away from the approaching enemies.
- If 'seek' is given, it preferentially goes toward that location (but getting away from enemies takes priority).
- If 'avoid' is given, it in addition tries to avoid that location (with both maximizing distance from enemies and going toward 'seek' taking priority).
- Both 'seek' and 'avoid' may consist of only one coordinate ('x' or 'y'), in which case not a single hex, but a line of hexes is sought or avoided."
[/message]
[/command]
[/set_menu_item]
[set_menu_item]
id=m06_zone
description= _ "Zone Guardian"
image=units/nagas/fighter.png~CROP(25,19,24,24)
[show_if]
{VARIABLE_CONDITIONAL scenario_name equals guardians}
[/show_if]
[command]
[message]
speaker=narrator
image=portraits/nagas/fighter.png
caption= _ "Zone Guardian"
message= _ "A zone guardian is a unit that, as the name says, guards a zone. It moves randomly inside this zone until an enemy enters it (or a separately defined enemy zone, see below). Applications might be the defense of a castle or a nesting area. The zone macro can be called with an optional enemy zone:
- If not specified, the zone guard attacks any enemy coming inside its guard zone.
- Otherwise, it attacks any enemy entering the enemy zone and once there are no more enemies, it goes back to patrol in its basic zone."
[/message]
[/command]
[/set_menu_item]
[/event]
[event]
name=start
{STORE_UNIT_VAR id=Kraa profile profile}
[message]
speaker=Kraa
image=$profile~FL()~RIGHT()
message= _ "Kraahhh!!!!"
[/message]
[message]
speaker=Another Bad Orc
message= _ "They there! We them get!"
[/message]
# wmllint: unbalanced-on
[message]
speaker=Kraa
image=$profile~FL()~RIGHT()
message= _ "Gryphons of the High Plains, look at all these enemies. They don't behave normally. Most of them don't move at all unless we get close. Let's check out how they react to us.
Note to the player: the right-click context menu provides information about each of the units' behavior.
Another note: Most of the Guardian AIs are coded as Micro AIs. A Micro AI can be added and adapted to the need of a scenario easily using only WML and the [micro_ai] tag. Check out the <span color='#00A000'>Micro AI wiki page</span> at https://wiki.wesnoth.org/Micro_AIs for more information."
[/message]
# wmllint: unbalanced-off
{CLEAR_VARIABLE profile}
[objectives]
summary= _ "Move the Gryphons around to explore how the guardians react"
[objective]
description= _ "Defeat all enemy units"
condition=win
[/objective]
[objective]
description= _ "Move Kraa to the signpost"
condition=win
[/objective]
[objective]
description= _ "Death of Kraa"
condition=lose
[/objective]
[note]
description= _ "Check out the right-click menu options for information on each guardian type"
[/note]
[/objectives]
[/event]
# Reset the label for moving units
[event]
name=moveto
first_time_only=no
[filter]
side=2
[/filter]
{REMOVE_LABEL $x2 $y2}
{SET_LABEL $x1 $y1 $unit.variables.label}
[/event]
# The events finishing the scenario
[event]
name=die
first_time_only=no
[if]
[not]
[have_unit]
side=2
[/have_unit]
[/not]
[then]
[kill]
id=$unit.id
[/kill]
[fire_event]
name=end_scenario
[/fire_event]
[/then]
[/if]
[/event]
[event]
name=moveto
[filter]
id=Kraa
x,y=1,6
[/filter]
[fire_event]
name=end_scenario
[/fire_event]
[/event]
[event]
name=end_scenario
[message]
speaker=Kraa
message= _ "Gryphons of the High Plains, it is time to return to said plains. Follow me."
[/message]
[endlevel]
result=victory
bonus=no
carryover_percentage=0
carryover_report=no
linger_mode=no
[/endlevel]
[/event]
[/test]